aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/FreeswitchService
diff options
context:
space:
mode:
authorMelanie2010-11-21 21:18:03 +0000
committerMelanie2010-11-21 21:29:17 +0000
commited5f91c638d39938bfca04319434e007fcad90b2 (patch)
tree9accb8cc3e6ef2473b564932b0ddb69ae8f4c83f /OpenSim/Services/FreeswitchService
parentStart implementing Freeswitch in ROBUST (diff)
downloadopensim-SC_OLD-ed5f91c638d39938bfca04319434e007fcad90b2.zip
opensim-SC_OLD-ed5f91c638d39938bfca04319434e007fcad90b2.tar.gz
opensim-SC_OLD-ed5f91c638d39938bfca04319434e007fcad90b2.tar.bz2
opensim-SC_OLD-ed5f91c638d39938bfca04319434e007fcad90b2.tar.xz
Move Dialplan and Directory from the region module to the ROBUST server
Diffstat (limited to 'OpenSim/Services/FreeswitchService')
-rw-r--r--OpenSim/Services/FreeswitchService/FreeswitchService.cs337
1 files changed, 333 insertions, 4 deletions
diff --git a/OpenSim/Services/FreeswitchService/FreeswitchService.cs b/OpenSim/Services/FreeswitchService/FreeswitchService.cs
index 109ef9b..b62a65a 100644
--- a/OpenSim/Services/FreeswitchService/FreeswitchService.cs
+++ b/OpenSim/Services/FreeswitchService/FreeswitchService.cs
@@ -26,6 +26,7 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Text;
29using System.Reflection; 30using System.Reflection;
30using Nini.Config; 31using Nini.Config;
31using log4net; 32using log4net;
@@ -46,14 +47,342 @@ namespace OpenSim.Services.FreeswitchService
46 // Perform initilialization here 47 // Perform initilialization here
47 } 48 }
48 49
49 public Hashtable HandleDirectoryRequest(Hashtable requestBody) 50 public Hashtable HandleDialplanRequest(Hashtable request)
50 { 51 {
51 return new Hashtable(); 52 m_log.DebugFormat("[FreeSwitchVoice] HandleDialplanRequest called with {0}",request.ToString());
53
54 Hashtable response = new Hashtable();
55
56 foreach (DictionaryEntry item in request)
57 {
58 m_log.InfoFormat("[FreeSwitchDirectory] requestBody item {0} {1}",item.Key, item.Value);
59 }
60
61 string requestcontext = (string) request["Hunt-Context"];
62 response["content_type"] = "text/xml";
63 response["keepalive"] = false;
64 response["int_response_code"] = 200;
65
66 if (m_freeSwitchContext != String.Empty && m_freeSwitchContext != requestcontext)
67 {
68 m_log.Debug("[FreeSwitchDirectory] returning empty as it's for another context");
69 response["str_response_string"] = "";
70 }
71 else
72 {
73 response["str_response_string"] = String.Format(@"<?xml version=""1.0"" encoding=""utf-8""?>
74 <document type=""freeswitch/xml"">
75 <section name=""dialplan"">
76 <context name=""{0}"">" +
77
78/* <!-- dial via SIP uri -->
79 <extension name=""sip_uri"">
80 <condition field=""destination_number"" expression=""^sip:(.*)$"">
81 <action application=""bridge"" data=""sofia/${use_profile}/$1""/>
82 <!--<action application=""bridge"" data=""$1""/>-->
83 </condition>
84 </extension>*/
85
86 @"<extension name=""opensim_conferences"">
87 <condition field=""destination_number"" expression=""^confctl-(.*)$"">
88 <action application=""answer""/>
89 <action application=""conference"" data=""$1-{1}@{0}""/>
90 </condition>
91 </extension>
92
93 <extension name=""opensim_conf"">
94 <condition field=""destination_number"" expression=""^conf-(.*)$"">
95 <action application=""answer""/>
96 <action application=""conference"" data=""$1-{1}@{0}""/>
97 </condition>
98 </extension>
99
100 <extension name=""avatar"">
101 <condition field=""destination_number"" expression=""^(x.*)$"">
102 <action application=""bridge"" data=""user/$1""/>
103 </condition>
104 </extension>
105
106 </context>
107 </section>
108 </document>", m_freeSwitchContext, m_freeSwitchRealm);
109 }
110
111 return response;
52 } 112 }
53 113
54 public Hashtable HandleDialplanRequest(Hashtable requestBody) 114 public Hashtable HandleDirectoryRequest(Hashtable request)
115 {
116 Hashtable response = new Hashtable();
117 string domain = (string) request["domain"];
118 if (domain != m_freeSwitchRealm) {
119 response["content_type"] = "text/xml";
120 response["keepalive"] = false;
121 response["int_response_code"] = 200;
122 response["str_response_string"] = "";
123 } else {
124 m_log.DebugFormat("[FreeSwitchDirectory] HandleDirectoryRequest called with {0}",request.ToString());
125
126 // information in the request we might be interested in
127
128 // Request 1 sip_auth for users account
129
130 //Event-Calling-Function=sofia_reg_parse_auth
131 //Event-Calling-Line-Number=1494
132 //action=sip_auth
133 //sip_user_agent=Vivox-SDK-2.1.3010.6151-Mac%20(Feb-11-2009/16%3A42%3A41)
134 //sip_auth_username=xhZuXKmRpECyr2AARJYyGgg%3D%3D (==)
135 //sip_auth_realm=9.20.151.43
136 //sip_contact_user=xhZuXKmRpECyr2AARJYyGgg%3D%3D (==)
137 //sip_contact_host=192.168.0.3 // this shouldnt really be a local IP, investigate STUN servers
138 //sip_to_user=xhZuXKmRpECyr2AARJYyGgg%3D%3D
139 //sip_to_host=9.20.151.43
140 //sip_auth_method=REGISTER
141 //user=xhZuXKmRpECyr2AARJYyGgg%3D%3D
142 //domain=9.20.151.43
143 //ip=9.167.220.137 // this is the correct IP rather than sip_contact_host above when through a vpn or NAT setup
144
145 foreach (DictionaryEntry item in request)
146 {
147 m_log.InfoFormat("[FreeSwitchDirectory] requestBody item {0} {1}", item.Key, item.Value);
148 }
149
150 string eventCallingFunction = (string) request["Event-Calling-Function"];
151 if (eventCallingFunction == null)
152 {
153 eventCallingFunction = "sofia_reg_parse_auth";
154 }
155
156 if (eventCallingFunction.Length == 0)
157 {
158 eventCallingFunction = "sofia_reg_parse_auth";
159 }
160
161 if (eventCallingFunction == "sofia_reg_parse_auth")
162 {
163 string sipAuthMethod = (string)request["sip_auth_method"];
164
165 if (sipAuthMethod == "REGISTER")
166 {
167 response = HandleRegister(m_freeSwitchContext, m_freeSwitchRealm, request);
168 }
169 else if (sipAuthMethod == "INVITE")
170 {
171 response = HandleInvite(m_freeSwitchContext, m_freeSwitchRealm, request);
172 }
173 else
174 {
175 m_log.ErrorFormat("[FreeSwitchVoice] HandleDirectoryRequest unknown sip_auth_method {0}",sipAuthMethod);
176 response["int_response_code"] = 404;
177 response["content_type"] = "text/xml";
178 response["str_response_string"] = "";
179 }
180 }
181 else if (eventCallingFunction == "switch_xml_locate_user")
182 {
183 response = HandleLocateUser(m_freeSwitchRealm, request);
184 }
185 else if (eventCallingFunction == "user_data_function") // gets called when an avatar to avatar call is made
186 {
187 response = HandleLocateUser(m_freeSwitchRealm, request);
188 }
189 else if (eventCallingFunction == "user_outgoing_channel")
190 {
191 response = HandleRegister(m_freeSwitchContext, m_freeSwitchRealm, request);
192 }
193 else if (eventCallingFunction == "config_sofia") // happens once on freeswitch startup
194 {
195 response = HandleConfigSofia(m_freeSwitchContext, m_freeSwitchRealm, request);
196 }
197 else if (eventCallingFunction == "switch_load_network_lists")
198 {
199 //response = HandleLoadNetworkLists(request);
200 response["int_response_code"] = 404;
201 response["keepalive"] = false;
202 response["content_type"] = "text/xml";
203 response["str_response_string"] = "";
204 }
205 else
206 {
207 m_log.ErrorFormat("[FreeSwitchVoice] HandleDirectoryRequest unknown Event-Calling-Function {0}",eventCallingFunction);
208 response["int_response_code"] = 404;
209 response["keepalive"] = false;
210 response["content_type"] = "text/xml";
211 response["str_response_string"] = "";
212 }
213 }
214 return response;
215 }
216
217 private Hashtable HandleRegister(string Context, string Realm, Hashtable request)
218 {
219 m_log.Info("[FreeSwitchDirectory] HandleRegister called");
220
221 // TODO the password we return needs to match that sent in the request, this is hard coded for now
222 string password = "1234";
223 string domain = (string) request["domain"];
224 string user = (string) request["user"];
225
226 Hashtable response = new Hashtable();
227 response["content_type"] = "text/xml";
228 response["keepalive"] = false;
229 response["int_response_code"] = 200;
230
231 response["str_response_string"] = String.Format(
232 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
233 "<document type=\"freeswitch/xml\">\r\n" +
234 "<section name=\"directory\" description=\"User Directory\">\r\n" +
235 "<domain name=\"{0}\">\r\n" +
236 "<user id=\"{1}\">\r\n" +
237 "<params>\r\n" +
238 "<param name=\"password\" value=\"{2}\" />\r\n" +
239 "<param name=\"dial-string\" value=\"{{sip_contact_user={1}}}{{presence_id=${{dialed_user}}@${{dialed_domain}}}}${{sofia_contact(${{dialed_user}}@${{dialed_domain}})}}\"/>\r\n" +
240 "</params>\r\n" +
241 "<variables>\r\n" +
242 "<variable name=\"user_context\" value=\"{3}\" />\r\n" +
243 "<variable name=\"presence_id\" value=\"{1}@{0}\"/>"+
244 "</variables>\r\n" +
245 "</user>\r\n" +
246 "</domain>\r\n" +
247 "</section>\r\n" +
248 "</document>\r\n",
249 domain , user, password, Context);
250
251 return response;
252 }
253
254 private Hashtable HandleInvite(string Context, string Realm, Hashtable request)
255 {
256 m_log.Info("[FreeSwitchDirectory] HandleInvite called");
257
258 // TODO the password we return needs to match that sent in the request, this is hard coded for now
259 string password = "1234";
260 string domain = (string) request["domain"];
261 string user = (string) request["user"];
262 string sipRequestUser = (string) request["sip_request_user"];
263
264 Hashtable response = new Hashtable();
265 response["content_type"] = "text/xml";
266 response["keepalive"] = false;
267 response["int_response_code"] = 200;
268 response["str_response_string"] = String.Format(
269 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
270 "<document type=\"freeswitch/xml\">\r\n" +
271 "<section name=\"directory\" description=\"User Directory\">\r\n" +
272 "<domain name=\"{0}\">\r\n" +
273 "<user id=\"{1}\">\r\n" +
274 "<params>\r\n" +
275 "<param name=\"password\" value=\"{2}\" />\r\n" +
276 "<param name=\"dial-string\" value=\"{{sip_contact_user={1}}}{{presence_id=${1}@${{dialed_domain}}}}${{sofia_contact(${1}@${{dialed_domain}})}}\"/>\r\n" +
277 "</params>\r\n" +
278 "<variables>\r\n" +
279 "<variable name=\"user_context\" value=\"{4}\" />\r\n" +
280 "<variable name=\"presence_id\" value=\"{1}@$${{domain}}\"/>"+
281 "</variables>\r\n" +
282 "</user>\r\n" +
283 "<user id=\"{3}\">\r\n" +
284 "<params>\r\n" +
285 "<param name=\"password\" value=\"{2}\" />\r\n" +
286 "<param name=\"dial-string\" value=\"{{sip_contact_user={1}}}{{presence_id=${3}@${{dialed_domain}}}}${{sofia_contact(${3}@${{dialed_domain}})}}\"/>\r\n" +
287 "</params>\r\n" +
288 "<variables>\r\n" +
289 "<variable name=\"user_context\" value=\"{4}\" />\r\n" +
290 "<variable name=\"presence_id\" value=\"{3}@$${{domain}}\"/>"+
291 "</variables>\r\n" +
292 "</user>\r\n" +
293 "</domain>\r\n" +
294 "</section>\r\n" +
295 "</document>\r\n",
296 domain , user, password,sipRequestUser, Context);
297
298 return response;
299 }
300
301 private Hashtable HandleLocateUser(String Realm, Hashtable request)
302 {
303 m_log.Info("[FreeSwitchDirectory] HandleLocateUser called");
304
305 // TODO the password we return needs to match that sent in the request, this is hard coded for now
306 string domain = (string) request["domain"];
307 string user = (string) request["user"];
308
309 Hashtable response = new Hashtable();
310 response["content_type"] = "text/xml";
311 response["keepalive"] = false;
312 response["int_response_code"] = 200;
313 response["str_response_string"] = String.Format(
314 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
315 "<document type=\"freeswitch/xml\">\r\n" +
316 "<section name=\"directory\" description=\"User Directory\">\r\n" +
317 "<domain name=\"{0}\">\r\n" +
318 "<params>\r\n" +
319 "<param name=\"dial-string\" value=\"{{sip_contact_user=${{dialed_user}}}}{{presence_id=${{dialed_user}}@${{dialed_domain}}}}${{sofia_contact(${{dialed_user}}@${{dialed_domain}})}}\"/>\r\n" +
320 "</params>\r\n" +
321 "<user id=\"{1}\">\r\n" +
322 "<variables>\r\n"+
323 "<variable name=\"default_gateway\" value=\"$${{default_provider}}\"/>\r\n"+
324 "<variable name=\"presence_id\" value=\"{1}@$${{domain}}\"/>"+
325 "</variables>\r\n"+
326 "</user>\r\n" +
327 "</domain>\r\n" +
328 "</section>\r\n" +
329 "</document>\r\n",
330 domain , user);
331
332 return response;
333 }
334
335 private Hashtable HandleConfigSofia(string Context, string Realm, Hashtable request)
55 { 336 {
56 return new Hashtable(); 337 m_log.Info("[FreeSwitchDirectory] HandleConfigSofia called");
338
339 // TODO the password we return needs to match that sent in the request, this is hard coded for now
340 string domain = (string) request["domain"];
341
342 Hashtable response = new Hashtable();
343 response["content_type"] = "text/xml";
344 response["keepalive"] = false;
345 response["int_response_code"] = 200;
346 response["str_response_string"] = String.Format(
347 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
348 "<document type=\"freeswitch/xml\">\r\n" +
349 "<section name=\"directory\" description=\"User Directory\">\r\n" +
350 "<domain name=\"{0}\">\r\n" +
351 "<params>\r\n" +
352 "<param name=\"dial-string\" value=\"{{sip_contact_user=${{dialed_user}}}}{{presence_id=${{dialed_user}}@${{dialed_domain}}}}${{sofia_contact(${{dialed_user}}@${{dialed_domain}})}}\"/>\r\n" +
353 "</params>\r\n" +
354 "<groups name=\"default\">\r\n"+
355 "<users>\r\n"+
356 "<user id=\"$${{default_provider}}\">\r\n"+
357 "<gateways>\r\n"+
358 "<gateway name=\"$${{default_provider}}\">\r\n"+
359 "<param name=\"username\" value=\"$${{default_provider_username}}\"/>\r\n"+
360 "<param name=\"password\" value=\"$${{default_provider_password}}\"/>\r\n"+
361 "<param name=\"from-user\" value=\"$${{default_provider_username}}\"/>\r\n"+
362 "<param name=\"from-domain\" value=\"$${{default_provider_from_domain}}\"/>\r\n"+
363 "<param name=\"expire-seconds\" value=\"600\"/>\r\n"+
364 "<param name=\"register\" value=\"$${{default_provider_register}}\"/>\r\n"+
365 "<param name=\"retry-seconds\" value=\"30\"/>\r\n"+
366 "<param name=\"extension\" value=\"$${{default_provider_contact}}\"/>\r\n"+
367 "<param name=\"contact-params\" value=\"domain_name=$${{domain}}\"/>\r\n"+
368 "<param name=\"context\" value=\"{1}\"/>\r\n"+
369 "</gateway>\r\n"+
370 "</gateways>\r\n"+
371 "<params>\r\n"+
372 "<param name=\"password\" value=\"$${{default_provider_password}}\"/>\r\n"+
373 "</params>\r\n"+
374 "</user>\r\n"+
375 "</users>"+
376 "</groups>\r\n" +
377 "<variables>\r\n"+
378 "<variable name=\"default_gateway\" value=\"$${{default_provider}}\"/>\r\n"+
379 "</variables>\r\n"+
380 "</domain>\r\n" +
381 "</section>\r\n" +
382 "</document>\r\n",
383 domain, Context);
384
385 return response;
57 } 386 }
58 } 387 }
59} 388}