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
39 HttpClientChannel client
;
40 HttpServerChannel server
;
47 client
= new HttpClientChannel ();
48 server
= new HttpServerChannel ();
51 public HttpChannel (int port
)
53 client
= new HttpClientChannel ();
54 server
= new HttpServerChannel (port
);
57 public HttpChannel (IDictionary properties
,
58 IClientChannelSinkProvider clientSinkProvider
,
59 IServerChannelSinkProvider serverSinkProvider
)
61 if (properties
!= null && properties
.Contains ("name")) {
62 this.name
= (string)properties
["name"];
65 client
= new HttpClientChannel (properties
, clientSinkProvider
);
66 server
= new HttpServerChannel (properties
, serverSinkProvider
);
71 #region BaseChannelWithProperties overrides
73 public override object this[object key
]
75 get { return Properties[key]; }
76 set { Properties[key] = value; }
79 public override ICollection Keys
81 get { return Properties.Keys; }
84 public override IDictionary Properties
88 return new AggregateDictionary (new IDictionary
[] {
99 public string ChannelName
104 public int ChannelPriority
106 get { return server.ChannelPriority; }
109 public string Parse (string url
, out string objectURI
)
111 return ParseInternal (url
, out objectURI
);
114 internal static string ParseInternal (string url
, out string objectURI
)
117 throw new ArgumentNullException ("url");
119 // format: "http://host:port/path/to/object"
122 // url needs to be at least "http:" or "https:"
123 if (url
.Length
< 5 ||
124 (url
[0] != 'H' && url
[0] != 'h') ||
125 (url
[1] != 'T' && url
[1] != 't') ||
126 (url
[2] != 'T' && url
[2] != 't') ||
127 (url
[3] != 'P' && url
[3] != 'p'))
131 if (url
[4] == 'S' || url
[4] == 's') {
140 if (url
[protolen
] != ':')
143 // "http:" and "https:" are acceptable inputs
144 if (url
.Length
== protolen
+ 1)
147 // protocol must be followed by "//"
148 if (url
.Length
< protolen
+ 3 || url
[protolen
+ 1] != '/' || url
[protolen
+ 2] != '/')
151 // "http://" and "https://" are acceptable inputs
152 if (url
.Length
== protolen
+ 3)
155 int slash
= url
.IndexOf ('/', protolen
+ 3);
159 objectURI
= url
.Substring (slash
);
161 return url
.Substring (0, slash
);
166 #region IChannelReceiver (: IChannel)
168 public object ChannelData
170 get { return server.ChannelData; }
173 public string[] GetUrlsForUri (string objectURI
)
175 return server
.GetUrlsForUri (objectURI
);
178 public void StartListening (object data
)
180 server
.StartListening (data
);
183 public void StopListening (object data
)
185 server
.StopListening (data
);
190 #region IChannelReceiverHook
192 public void AddHookChannelUri (string channelUri
)
194 server
.AddHookChannelUri (channelUri
);
197 public string ChannelScheme
199 get { return server.ChannelScheme; }
202 public IServerChannelSink ChannelSinkChain
204 get { return server.ChannelSinkChain; }
207 public bool WantsToListen
209 get { return server.WantsToListen; }
210 set { server.WantsToListen = value; }
215 #region IChannelSender (: IChannel)
217 public IMessageSink
CreateMessageSink (string url
, object remoteChannelData
, out string objectURI
)
219 return client
.CreateMessageSink (url
, remoteChannelData
, out objectURI
);
224 #region ISecurableChannel
226 public bool IsSecured
228 get { return client.IsSecured; }
229 set { client.IsSecured = value; }