diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchDirectory.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchDirectory.cs | 348 |
1 files changed, 0 insertions, 348 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchDirectory.cs b/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchDirectory.cs deleted file mode 100644 index 17cdf74..0000000 --- a/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchDirectory.cs +++ /dev/null | |||
@@ -1,348 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using log4net; | ||
29 | using System; | ||
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using System.Collections; | ||
33 | |||
34 | namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice | ||
35 | { | ||
36 | public class FreeSwitchDirectory | ||
37 | { | ||
38 | private static readonly ILog m_log = | ||
39 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
40 | |||
41 | public Hashtable HandleDirectoryRequest(string Context, string Realm, Hashtable request) | ||
42 | { | ||
43 | Hashtable response = new Hashtable(); | ||
44 | string domain = (string) request["domain"]; | ||
45 | if (domain != Realm) { | ||
46 | response["content_type"] = "text/xml"; | ||
47 | response["keepalive"] = false; | ||
48 | response["int_response_code"] = 200; | ||
49 | response["str_response_string"] = ""; | ||
50 | } else { | ||
51 | m_log.DebugFormat("[FreeSwitchDirectory] HandleDirectoryRequest called with {0}",request.ToString()); | ||
52 | |||
53 | // information in the request we might be interested in | ||
54 | |||
55 | // Request 1 sip_auth for users account | ||
56 | |||
57 | //Event-Calling-Function=sofia_reg_parse_auth | ||
58 | //Event-Calling-Line-Number=1494 | ||
59 | //action=sip_auth | ||
60 | //sip_user_agent=Vivox-SDK-2.1.3010.6151-Mac%20(Feb-11-2009/16%3A42%3A41) | ||
61 | //sip_auth_username=xhZuXKmRpECyr2AARJYyGgg%3D%3D (==) | ||
62 | //sip_auth_realm=9.20.151.43 | ||
63 | //sip_contact_user=xhZuXKmRpECyr2AARJYyGgg%3D%3D (==) | ||
64 | //sip_contact_host=192.168.0.3 // this shouldnt really be a local IP, investigate STUN servers | ||
65 | //sip_to_user=xhZuXKmRpECyr2AARJYyGgg%3D%3D | ||
66 | //sip_to_host=9.20.151.43 | ||
67 | //sip_auth_method=REGISTER | ||
68 | //user=xhZuXKmRpECyr2AARJYyGgg%3D%3D | ||
69 | //domain=9.20.151.43 | ||
70 | //ip=9.167.220.137 // this is the correct IP rather than sip_contact_host above when through a vpn or NAT setup | ||
71 | |||
72 | foreach (DictionaryEntry item in request) | ||
73 | { | ||
74 | m_log.InfoFormat("[FreeSwitchDirectory] requestBody item {0} {1}", item.Key, item.Value); | ||
75 | } | ||
76 | |||
77 | string eventCallingFunction = (string) request["Event-Calling-Function"]; | ||
78 | if (eventCallingFunction == null) | ||
79 | { | ||
80 | eventCallingFunction = "sofia_reg_parse_auth"; | ||
81 | } | ||
82 | |||
83 | if (eventCallingFunction.Length == 0) | ||
84 | { | ||
85 | eventCallingFunction = "sofia_reg_parse_auth"; | ||
86 | } | ||
87 | |||
88 | if (eventCallingFunction == "sofia_reg_parse_auth") | ||
89 | { | ||
90 | string sipAuthMethod = (string)request["sip_auth_method"]; | ||
91 | |||
92 | if (sipAuthMethod == "REGISTER") | ||
93 | { | ||
94 | response = HandleRegister(Context, Realm, request); | ||
95 | } | ||
96 | else if (sipAuthMethod == "INVITE") | ||
97 | { | ||
98 | response = HandleInvite(Context, Realm, request); | ||
99 | } | ||
100 | else | ||
101 | { | ||
102 | m_log.ErrorFormat("[FreeSwitchVoice] HandleDirectoryRequest unknown sip_auth_method {0}",sipAuthMethod); | ||
103 | response["int_response_code"] = 404; | ||
104 | response["content_type"] = "text/xml"; | ||
105 | response["str_response_string"] = ""; | ||
106 | } | ||
107 | } | ||
108 | else if (eventCallingFunction == "switch_xml_locate_user") | ||
109 | { | ||
110 | response = HandleLocateUser(Realm, request); | ||
111 | } | ||
112 | else if (eventCallingFunction == "user_data_function") // gets called when an avatar to avatar call is made | ||
113 | { | ||
114 | response = HandleLocateUser(Realm, request); | ||
115 | } | ||
116 | else if (eventCallingFunction == "user_outgoing_channel") | ||
117 | { | ||
118 | response = HandleRegister(Context, Realm, request); | ||
119 | } | ||
120 | else if (eventCallingFunction == "config_sofia") // happens once on freeswitch startup | ||
121 | { | ||
122 | response = HandleConfigSofia(Context, Realm, request); | ||
123 | } | ||
124 | else if (eventCallingFunction == "switch_load_network_lists") | ||
125 | { | ||
126 | //response = HandleLoadNetworkLists(request); | ||
127 | response["int_response_code"] = 404; | ||
128 | response["keepalive"] = false; | ||
129 | response["content_type"] = "text/xml"; | ||
130 | response["str_response_string"] = ""; | ||
131 | } | ||
132 | else | ||
133 | { | ||
134 | m_log.ErrorFormat("[FreeSwitchVoice] HandleDirectoryRequest unknown Event-Calling-Function {0}",eventCallingFunction); | ||
135 | response["int_response_code"] = 404; | ||
136 | response["keepalive"] = false; | ||
137 | response["content_type"] = "text/xml"; | ||
138 | response["str_response_string"] = ""; | ||
139 | } | ||
140 | } | ||
141 | return response; | ||
142 | } | ||
143 | |||
144 | private Hashtable HandleRegister(string Context, string Realm, Hashtable request) | ||
145 | { | ||
146 | m_log.Info("[FreeSwitchDirectory] HandleRegister called"); | ||
147 | |||
148 | // TODO the password we return needs to match that sent in the request, this is hard coded for now | ||
149 | string password = "1234"; | ||
150 | string domain = (string) request["domain"]; | ||
151 | string user = (string) request["user"]; | ||
152 | |||
153 | Hashtable response = new Hashtable(); | ||
154 | response["content_type"] = "text/xml"; | ||
155 | response["keepalive"] = false; | ||
156 | response["int_response_code"] = 200; | ||
157 | |||
158 | response["str_response_string"] = String.Format( | ||
159 | "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + | ||
160 | "<document type=\"freeswitch/xml\">\r\n" + | ||
161 | "<section name=\"directory\" description=\"User Directory\">\r\n" + | ||
162 | "<domain name=\"{0}\">\r\n" + | ||
163 | "<user id=\"{1}\">\r\n" + | ||
164 | "<params>\r\n" + | ||
165 | "<param name=\"password\" value=\"{2}\" />\r\n" + | ||
166 | "<param name=\"dial-string\" value=\"{{sip_contact_user={1}}}{{presence_id=${{dialed_user}}@${{dialed_domain}}}}${{sofia_contact(${{dialed_user}}@${{dialed_domain}})}}\"/>\r\n" + | ||
167 | "</params>\r\n" + | ||
168 | "<variables>\r\n" + | ||
169 | "<variable name=\"user_context\" value=\"{3}\" />\r\n" + | ||
170 | "<variable name=\"presence_id\" value=\"{1}@{0}\"/>"+ | ||
171 | "</variables>\r\n" + | ||
172 | "</user>\r\n" + | ||
173 | "</domain>\r\n" + | ||
174 | "</section>\r\n" + | ||
175 | "</document>\r\n", | ||
176 | domain , user, password, Context); | ||
177 | |||
178 | return response; | ||
179 | } | ||
180 | |||
181 | private Hashtable HandleInvite(string Context, string Realm, Hashtable request) | ||
182 | { | ||
183 | m_log.Info("[FreeSwitchDirectory] HandleInvite called"); | ||
184 | |||
185 | // TODO the password we return needs to match that sent in the request, this is hard coded for now | ||
186 | string password = "1234"; | ||
187 | string domain = (string) request["domain"]; | ||
188 | string user = (string) request["user"]; | ||
189 | string sipRequestUser = (string) request["sip_request_user"]; | ||
190 | |||
191 | Hashtable response = new Hashtable(); | ||
192 | response["content_type"] = "text/xml"; | ||
193 | response["keepalive"] = false; | ||
194 | response["int_response_code"] = 200; | ||
195 | response["str_response_string"] = String.Format( | ||
196 | "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + | ||
197 | "<document type=\"freeswitch/xml\">\r\n" + | ||
198 | "<section name=\"directory\" description=\"User Directory\">\r\n" + | ||
199 | "<domain name=\"{0}\">\r\n" + | ||
200 | "<user id=\"{1}\">\r\n" + | ||
201 | "<params>\r\n" + | ||
202 | "<param name=\"password\" value=\"{2}\" />\r\n" + | ||
203 | "<param name=\"dial-string\" value=\"{{sip_contact_user={1}}}{{presence_id=${1}@${{dialed_domain}}}}${{sofia_contact(${1}@${{dialed_domain}})}}\"/>\r\n" + | ||
204 | "</params>\r\n" + | ||
205 | "<variables>\r\n" + | ||
206 | "<variable name=\"user_context\" value=\"{4}\" />\r\n" + | ||
207 | "<variable name=\"presence_id\" value=\"{1}@$${{domain}}\"/>"+ | ||
208 | "</variables>\r\n" + | ||
209 | "</user>\r\n" + | ||
210 | "<user id=\"{3}\">\r\n" + | ||
211 | "<params>\r\n" + | ||
212 | "<param name=\"password\" value=\"{2}\" />\r\n" + | ||
213 | "<param name=\"dial-string\" value=\"{{sip_contact_user={1}}}{{presence_id=${3}@${{dialed_domain}}}}${{sofia_contact(${3}@${{dialed_domain}})}}\"/>\r\n" + | ||
214 | "</params>\r\n" + | ||
215 | "<variables>\r\n" + | ||
216 | "<variable name=\"user_context\" value=\"{4}\" />\r\n" + | ||
217 | "<variable name=\"presence_id\" value=\"{3}@$${{domain}}\"/>"+ | ||
218 | "</variables>\r\n" + | ||
219 | "</user>\r\n" + | ||
220 | "</domain>\r\n" + | ||
221 | "</section>\r\n" + | ||
222 | "</document>\r\n", | ||
223 | domain , user, password,sipRequestUser, Context); | ||
224 | |||
225 | return response; | ||
226 | } | ||
227 | |||
228 | private Hashtable HandleLocateUser(String Realm, Hashtable request) | ||
229 | { | ||
230 | m_log.Info("[FreeSwitchDirectory] HandleLocateUser called"); | ||
231 | |||
232 | // TODO the password we return needs to match that sent in the request, this is hard coded for now | ||
233 | string domain = (string) request["domain"]; | ||
234 | string user = (string) request["user"]; | ||
235 | |||
236 | Hashtable response = new Hashtable(); | ||
237 | response["content_type"] = "text/xml"; | ||
238 | response["keepalive"] = false; | ||
239 | response["int_response_code"] = 200; | ||
240 | response["str_response_string"] = String.Format( | ||
241 | "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + | ||
242 | "<document type=\"freeswitch/xml\">\r\n" + | ||
243 | "<section name=\"directory\" description=\"User Directory\">\r\n" + | ||
244 | "<domain name=\"{0}\">\r\n" + | ||
245 | "<params>\r\n" + | ||
246 | "<param name=\"dial-string\" value=\"{{sip_contact_user=${{dialed_user}}}}{{presence_id=${{dialed_user}}@${{dialed_domain}}}}${{sofia_contact(${{dialed_user}}@${{dialed_domain}})}}\"/>\r\n" + | ||
247 | "</params>\r\n" + | ||
248 | "<user id=\"{1}\">\r\n" + | ||
249 | "<variables>\r\n"+ | ||
250 | "<variable name=\"default_gateway\" value=\"$${{default_provider}}\"/>\r\n"+ | ||
251 | "<variable name=\"presence_id\" value=\"{1}@$${{domain}}\"/>"+ | ||
252 | "</variables>\r\n"+ | ||
253 | "</user>\r\n" + | ||
254 | "</domain>\r\n" + | ||
255 | "</section>\r\n" + | ||
256 | "</document>\r\n", | ||
257 | domain , user); | ||
258 | |||
259 | return response; | ||
260 | } | ||
261 | |||
262 | private Hashtable HandleConfigSofia(string Context, string Realm, Hashtable request) | ||
263 | { | ||
264 | m_log.Info("[FreeSwitchDirectory] HandleConfigSofia called"); | ||
265 | |||
266 | // TODO the password we return needs to match that sent in the request, this is hard coded for now | ||
267 | string domain = (string) request["domain"]; | ||
268 | |||
269 | Hashtable response = new Hashtable(); | ||
270 | response["content_type"] = "text/xml"; | ||
271 | response["keepalive"] = false; | ||
272 | response["int_response_code"] = 200; | ||
273 | response["str_response_string"] = String.Format( | ||
274 | "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + | ||
275 | "<document type=\"freeswitch/xml\">\r\n" + | ||
276 | "<section name=\"directory\" description=\"User Directory\">\r\n" + | ||
277 | "<domain name=\"{0}\">\r\n" + | ||
278 | "<params>\r\n" + | ||
279 | "<param name=\"dial-string\" value=\"{{sip_contact_user=${{dialed_user}}}}{{presence_id=${{dialed_user}}@${{dialed_domain}}}}${{sofia_contact(${{dialed_user}}@${{dialed_domain}})}}\"/>\r\n" + | ||
280 | "</params>\r\n" + | ||
281 | "<groups name=\"default\">\r\n"+ | ||
282 | "<users>\r\n"+ | ||
283 | "<user id=\"$${{default_provider}}\">\r\n"+ | ||
284 | "<gateways>\r\n"+ | ||
285 | "<gateway name=\"$${{default_provider}}\">\r\n"+ | ||
286 | "<param name=\"username\" value=\"$${{default_provider_username}}\"/>\r\n"+ | ||
287 | "<param name=\"password\" value=\"$${{default_provider_password}}\"/>\r\n"+ | ||
288 | "<param name=\"from-user\" value=\"$${{default_provider_username}}\"/>\r\n"+ | ||
289 | "<param name=\"from-domain\" value=\"$${{default_provider_from_domain}}\"/>\r\n"+ | ||
290 | "<param name=\"expire-seconds\" value=\"600\"/>\r\n"+ | ||
291 | "<param name=\"register\" value=\"$${{default_provider_register}}\"/>\r\n"+ | ||
292 | "<param name=\"retry-seconds\" value=\"30\"/>\r\n"+ | ||
293 | "<param name=\"extension\" value=\"$${{default_provider_contact}}\"/>\r\n"+ | ||
294 | "<param name=\"contact-params\" value=\"domain_name=$${{domain}}\"/>\r\n"+ | ||
295 | "<param name=\"context\" value=\"{1}\"/>\r\n"+ | ||
296 | "</gateway>\r\n"+ | ||
297 | "</gateways>\r\n"+ | ||
298 | "<params>\r\n"+ | ||
299 | "<param name=\"password\" value=\"$${{default_provider_password}}\"/>\r\n"+ | ||
300 | "</params>\r\n"+ | ||
301 | "</user>\r\n"+ | ||
302 | "</users>"+ | ||
303 | "</groups>\r\n" + | ||
304 | "<variables>\r\n"+ | ||
305 | "<variable name=\"default_gateway\" value=\"$${{default_provider}}\"/>\r\n"+ | ||
306 | "</variables>\r\n"+ | ||
307 | "</domain>\r\n" + | ||
308 | "</section>\r\n" + | ||
309 | "</document>\r\n", | ||
310 | domain, Context); | ||
311 | |||
312 | return response; | ||
313 | } | ||
314 | |||
315 | |||
316 | // private Hashtable HandleLoadNetworkLists(Hashtable request) | ||
317 | // { | ||
318 | // m_log.Info("[FreeSwitchDirectory] HandleLoadNetworkLists called"); | ||
319 | // | ||
320 | // // TODO the password we return needs to match that sent in the request, this is hard coded for now | ||
321 | // string domain = (string) request["domain"]; | ||
322 | // | ||
323 | // Hashtable response = new Hashtable(); | ||
324 | // response["content_type"] = "text/xml"; | ||
325 | // response["keepalive"] = false; | ||
326 | // response["int_response_code"] = 200; | ||
327 | // response["str_response_string"] = String.Format( | ||
328 | // "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + | ||
329 | // "<document type=\"freeswitch/xml\">\r\n" + | ||
330 | // "<section name=\"directory\" description=\"User Directory\">\r\n" + | ||
331 | // "<domain name=\"{0}\">\r\n" + | ||
332 | // "<params>\r\n" + | ||
333 | // "<param name=\"dial-string\" value=\"{{presence_id=${{dialed_user}}@${{dialed_domain}}}}${{sofia_contact(${{dialed_user}}@${{dialed_domain}})}}\"/>\r\n" + | ||
334 | // "</params>\r\n" + | ||
335 | // "<groups name=\"default\"><users/></groups>\r\n" + | ||
336 | // "<variables>\r\n"+ | ||
337 | // "<variable name=\"default_gateway\" value=\"$${{default_provider}}\"/>\r\n"+ | ||
338 | // "</variables>\r\n"+ | ||
339 | // "</domain>\r\n" + | ||
340 | // "</section>\r\n" + | ||
341 | // "</document>\r\n", | ||
342 | // domain); | ||
343 | // | ||
344 | // | ||
345 | // return response; | ||
346 | // } | ||
347 | } | ||
348 | } | ||