5 // Michael Hutchinson <mhutchinson@novell.com>
7 // Copyright (C) 2008 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System
.Collections
;
30 using System
.Runtime
.Remoting
.Messaging
;
32 namespace System
.Runtime
.Remoting
.Channels
.Http
35 public class HttpChannel
: BaseChannelWithProperties
,
36 IChannel
, IChannelReceiver
, IChannelReceiverHook
, IChannelSender
41 HttpClientChannel client
;
42 HttpServerChannel server
;
49 client
= new HttpClientChannel ();
50 server
= new HttpServerChannel ();
53 public HttpChannel (int port
)
55 client
= new HttpClientChannel ();
56 server
= new HttpServerChannel (port
);
59 public HttpChannel (IDictionary properties
,
60 IClientChannelSinkProvider clientSinkProvider
,
61 IServerChannelSinkProvider serverSinkProvider
)
63 if (properties
!= null && properties
.Contains ("name")) {
64 this.name
= (string)properties
["name"];
67 client
= new HttpClientChannel (properties
, clientSinkProvider
);
68 server
= new HttpServerChannel (properties
, serverSinkProvider
);
73 #region BaseChannelWithProperties overrides
75 public override object this[object key
]
77 get { return Properties[key]; }
78 set { Properties[key] = value; }
81 public override ICollection Keys
83 get { return Properties.Keys; }
86 public override IDictionary Properties
90 return new AggregateDictionary (new IDictionary
[] {
101 public string ChannelName
106 public int ChannelPriority
108 get { return server.ChannelPriority; }
111 public string Parse (string url
, out string objectURI
)
113 return ParseInternal (url
, out objectURI
);
116 internal static string ParseInternal (string url
, out string objectURI
)
119 throw new ArgumentNullException ("url");
121 // format: "http://host:port/path/to/object"
124 // url needs to be at least "http:" or "https:"
125 if (url
.Length
< 5 ||
126 (url
[0] != 'H' && url
[0] != 'h') ||
127 (url
[1] != 'T' && url
[1] != 't') ||
128 (url
[2] != 'T' && url
[2] != 't') ||
129 (url
[3] != 'P' && url
[3] != 'p'))
133 if (url
[4] == 'S' || url
[4] == 's') {
142 if (url
[protolen
] != ':')
145 // "http:" and "https:" are acceptable inputs
146 if (url
.Length
== protolen
+ 1)
149 // protocol must be followed by "//"
150 if (url
.Length
< protolen
+ 3 || url
[protolen
+ 1] != '/' || url
[protolen
+ 2] != '/')
153 // "http://" and "https://" are acceptable inputs
154 if (url
.Length
== protolen
+ 3)
157 int slash
= url
.IndexOf ('/', protolen
+ 3);
161 objectURI
= url
.Substring (slash
);
163 return url
.Substring (0, slash
);
168 #region IChannelReceiver (: IChannel)
170 public object ChannelData
172 get { return server.ChannelData; }
175 public string[] GetUrlsForUri (string objectURI
)
177 return server
.GetUrlsForUri (objectURI
);
180 public void StartListening (object data
)
182 server
.StartListening (data
);
185 public void StopListening (object data
)
187 server
.StopListening (data
);
192 #region IChannelReceiverHook
194 public void AddHookChannelUri (string channelUri
)
196 server
.AddHookChannelUri (channelUri
);
199 public string ChannelScheme
201 get { return server.ChannelScheme; }
204 public IServerChannelSink ChannelSinkChain
206 get { return server.ChannelSinkChain; }
209 public bool WantsToListen
211 get { return server.WantsToListen; }
212 set { server.WantsToListen = value; }
217 #region IChannelSender (: IChannel)
219 public IMessageSink
CreateMessageSink (string url
, object remoteChannelData
, out string objectURI
)
221 return client
.CreateMessageSink (url
, remoteChannelData
, out objectURI
);
227 #region ISecurableChannel
229 public bool IsSecured
231 get { return client.IsSecured; }
232 set { client.IsSecured = value; }