flush forgotten changelog
[mono.git] / mcs / class / System.Runtime.Remoting / System.Runtime.Remoting.Channels.Http / HttpChannel.cs
1 //
2 // System.Runtime.Remoting.Channels.Http.HttpChannel
3 //
4 // Summary:     Implements a wrapper class for HTTP client and server channels.
5 //
6 // Classes:    public HttpChannel
7 //
8 // Authors:
9 //      Martin Willemoes Hansen (mwh@sysrq.dk)
10 //              Ahmad Tantawy (popsito82@hotmail.com)
11 //              Ahmad Kadry (kadrianoz@hotmail.com)
12 //              Hussein Mehanna (hussein_mehanna@hotmail.com)
13 //
14 // (C) 2003 Martin Willemoes Hansen
15 //
16
17 //
18 // Permission is hereby granted, free of charge, to any person obtaining
19 // a copy of this software and associated documentation files (the
20 // "Software"), to deal in the Software without restriction, including
21 // without limitation the rights to use, copy, modify, merge, publish,
22 // distribute, sublicense, and/or sell copies of the Software, and to
23 // permit persons to whom the Software is furnished to do so, subject to
24 // the following conditions:
25 // 
26 // The above copyright notice and this permission notice shall be
27 // included in all copies or substantial portions of the Software.
28 // 
29 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
33 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
34 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
35 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 //
37
38 using System;
39 using System.Collections;
40 using System.Runtime.Remoting.Messaging;
41
42 namespace System.Runtime.Remoting.Channels.Http  
43 {
44         public class HttpChannel: BaseChannelWithProperties, IChannelReceiver, 
45                 IChannelSender, IChannel, IChannelReceiverHook
46         {
47                 private HttpServerChannel serverChannel;
48                 private HttpClientChannel clientChannel;
49                 private string channelName = "http";
50                 private int channelPriority = 1;
51                 private AggregateDictionary properties;
52
53                 public HttpChannel()
54                 {
55                         SetupChannel (new Hashtable(), null, null);
56                 }
57
58                 public HttpChannel (int port)
59                 {
60                         Hashtable prop = new Hashtable();
61                         prop["port"] = port;
62                         SetupChannel(prop,null,null);
63                 }
64
65                 public HttpChannel (IDictionary properties,IClientChannelSinkProvider clientSinkProvider,IServerChannelSinkProvider serverSinkProvider)
66                 {
67                         SetupChannel (properties,clientSinkProvider,serverSinkProvider);
68                 }
69
70                 private void SetupChannel (IDictionary properties, IClientChannelSinkProvider clientSinkProvider, IServerChannelSinkProvider serverSinkProvider)
71                 {
72                         clientChannel = new HttpClientChannel (properties, clientSinkProvider);
73                         serverChannel = new HttpServerChannel (properties, serverSinkProvider);
74                         
75                         object val = properties ["name"];
76                         if (val != null) channelName = val as string;
77                         
78                         val = properties ["priority"];
79                         if (val != null) channelPriority = Convert.ToInt32 (val);
80                         
81                         this.properties = new AggregateDictionary (new IDictionary[] {clientChannel, serverChannel});
82                 }
83
84
85                 //IChannel Members
86                 public String ChannelName
87                 {
88                         get { return channelName; }
89                 }
90
91                 public int ChannelPriority
92                 {
93                         get { return channelPriority; }
94                 }
95
96                 public String Parse(String url, out String objectURI)
97                 {
98                         return HttpHelper.Parse(url, out objectURI);
99                 }
100
101                 //IChannelSender Members
102                 public IMessageSink CreateMessageSink(String url, Object remoteChannelData, out String objectURI)
103                 {
104                         return clientChannel.CreateMessageSink(url, remoteChannelData, out objectURI);
105                 }
106
107                 //IChannelReciever Members
108                 public String[] GetUrlsForUri(String objectURI)
109                 {
110                         return serverChannel.GetUrlsForUri(objectURI);
111                 } 
112
113                 public void StartListening(Object data)
114                 {
115                         serverChannel.StartListening(data);
116                 }
117
118                 public void StopListening(Object data)
119                 {
120                         serverChannel.StopListening(data);
121                 } 
122                 
123                 public Object ChannelData
124                 {
125                         get { return serverChannel.ChannelData; }
126                 }
127                 
128                 public String ChannelScheme 
129                 {
130                         get { return "http"; } 
131                 }
132
133                 public bool WantsToListen 
134                 { 
135                         get { return serverChannel.WantsToListen; } 
136                         set { serverChannel.WantsToListen = value; }
137                 } 
138                 
139                 public IServerChannelSink ChannelSinkChain 
140                 {
141                         get { return serverChannel.ChannelSinkChain; }
142                 }
143
144                 public void AddHookChannelUri (String channelUri)
145                 {
146                         serverChannel.AddHookChannelUri (channelUri);
147                 } 
148                 
149                 public override object this [object key]
150                 {
151                         get { return properties[key]; }
152                         set { properties[key] = value; }
153                 }
154                 
155                 public override ICollection Keys 
156                 {
157                         get { return properties.Keys; }
158                 }
159                 
160                 public override IDictionary Properties 
161                 {
162                         get { return properties; }
163                 }
164         }
165 }