30 using System.Reflection;
33 using OpenSim.Framework;
35 using OpenSim.Services.Interfaces;
37 using OpenMetaverse.StructuredData;
38 using System.Collections;
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53 m_log.DebugFormat(
"[FreeSwitchVoice]: HandleDialplanRequest called with {0}",request.ToString());
55 Hashtable response =
new Hashtable();
62 string requestcontext = (string) request[
"Hunt-Context"];
63 response[
"content_type"] =
"text/xml";
64 response[
"keepalive"] =
false;
65 response[
"int_response_code"] = 200;
67 if (m_freeSwitchContext != String.Empty && m_freeSwitchContext != requestcontext)
69 m_log.Debug(
"[FreeSwitchDirectory]: returning empty as it's for another context");
70 response[
"str_response_string"] =
"";
74 response[
"str_response_string"] = String.Format(
@"<?xml version=""1.0"" encoding=""utf-8""?>
75 <document type=""freeswitch/xml"">
76 <section name=""dialplan"">
77 <context name=""{0}"">" +
87 @"<extension name=""opensim_conferences"">
88 <condition field=""destination_number"" expression=""^confctl-(.*)$"">
89 <action application=""answer""/>
90 <action application=""conference"" data=""$1-{1}@{0}""/>
94 <extension name=""opensim_conf"">
95 <condition field=""destination_number"" expression=""^conf-(.*)$"">
96 <action application=""answer""/>
97 <action application=""conference"" data=""$1-{1}@{0}""/>
101 <extension name=""avatar"">
102 <condition field=""destination_number"" expression=""^(x.*)$"">
103 <action application=""bridge"" data=""user/$1""/>
109 </document>", m_freeSwitchContext, m_freeSwitchRealm);
117 Hashtable response =
new Hashtable();
118 string domain = (string) request[
"domain"];
119 if (domain != m_freeSwitchRealm)
121 response[
"content_type"] =
"text/xml";
122 response[
"keepalive"] =
false;
123 response[
"int_response_code"] = 200;
124 response[
"str_response_string"] =
"";
152 string eventCallingFunction = (string) request[
"Event-Calling-Function"];
153 if (eventCallingFunction == null)
155 eventCallingFunction =
"sofia_reg_parse_auth";
158 if (eventCallingFunction.Length == 0)
160 eventCallingFunction =
"sofia_reg_parse_auth";
163 if (eventCallingFunction ==
"sofia_reg_parse_auth")
165 string sipAuthMethod = (string)request[
"sip_auth_method"];
167 if (sipAuthMethod ==
"REGISTER")
169 response = HandleRegister(m_freeSwitchContext, m_freeSwitchRealm, request);
171 else if (sipAuthMethod ==
"INVITE")
173 response = HandleInvite(m_freeSwitchContext, m_freeSwitchRealm, request);
177 m_log.ErrorFormat(
"[FreeSwitchVoice]: HandleDirectoryRequest unknown sip_auth_method {0}",sipAuthMethod);
178 response[
"int_response_code"] = 404;
179 response[
"content_type"] =
"text/xml";
180 response[
"str_response_string"] =
"";
183 else if (eventCallingFunction ==
"switch_xml_locate_user")
185 response = HandleLocateUser(m_freeSwitchRealm, request);
187 else if (eventCallingFunction ==
"user_data_function")
189 response = HandleLocateUser(m_freeSwitchRealm, request);
191 else if (eventCallingFunction ==
"user_outgoing_channel")
193 response = HandleRegister(m_freeSwitchContext, m_freeSwitchRealm, request);
195 else if (eventCallingFunction ==
"config_sofia")
197 response = HandleConfigSofia(m_freeSwitchContext, m_freeSwitchRealm, request);
199 else if (eventCallingFunction ==
"switch_load_network_lists")
202 response[
"int_response_code"] = 404;
203 response[
"keepalive"] =
false;
204 response[
"content_type"] =
"text/xml";
205 response[
"str_response_string"] =
"";
209 m_log.ErrorFormat(
"[FreeSwitchVoice]: HandleDirectoryRequest unknown Event-Calling-Function {0}",eventCallingFunction);
210 response[
"int_response_code"] = 404;
211 response[
"keepalive"] =
false;
212 response[
"content_type"] =
"text/xml";
213 response[
"str_response_string"] =
"";
219 private Hashtable HandleRegister(
string Context,
string Realm, Hashtable request)
221 m_log.Info(
"[FreeSwitchDirectory]: HandleRegister called");
224 string password =
"1234";
225 string domain = (string) request[
"domain"];
226 string user = (string) request[
"user"];
228 Hashtable response =
new Hashtable();
229 response[
"content_type"] =
"text/xml";
230 response[
"keepalive"] =
false;
231 response[
"int_response_code"] = 200;
233 response[
"str_response_string"] = String.Format(
234 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
235 "<document type=\"freeswitch/xml\">\r\n" +
236 "<section name=\"directory\" description=\"User Directory\">\r\n" +
237 "<domain name=\"{0}\">\r\n" +
238 "<user id=\"{1}\">\r\n" +
240 "<param name=\"password\" value=\"{2}\" />\r\n" +
241 "<param name=\"dial-string\" value=\"{{sip_contact_user={1}}}{{presence_id=${{dialed_user}}@${{dialed_domain}}}}${{sofia_contact(${{dialed_user}}@${{dialed_domain}})}}\"/>\r\n" +
244 "<variable name=\"user_context\" value=\"{3}\" />\r\n" +
245 "<variable name=\"presence_id\" value=\"{1}@{0}\"/>"+
251 domain , user, password, Context);
256 private Hashtable HandleInvite(
string Context,
string Realm, Hashtable request)
258 m_log.Info(
"[FreeSwitchDirectory]: HandleInvite called");
261 string password =
"1234";
262 string domain = (string) request[
"domain"];
263 string user = (string) request[
"user"];
264 string sipRequestUser = (string) request[
"sip_request_user"];
266 Hashtable response =
new Hashtable();
267 response[
"content_type"] =
"text/xml";
268 response[
"keepalive"] =
false;
269 response[
"int_response_code"] = 200;
270 response[
"str_response_string"] = String.Format(
271 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
272 "<document type=\"freeswitch/xml\">\r\n" +
273 "<section name=\"directory\" description=\"User Directory\">\r\n" +
274 "<domain name=\"{0}\">\r\n" +
275 "<user id=\"{1}\">\r\n" +
277 "<param name=\"password\" value=\"{2}\" />\r\n" +
278 "<param name=\"dial-string\" value=\"{{sip_contact_user={1}}}{{presence_id=${1}@${{dialed_domain}}}}${{sofia_contact(${1}@${{dialed_domain}})}}\"/>\r\n" +
281 "<variable name=\"user_context\" value=\"{4}\" />\r\n" +
282 "<variable name=\"presence_id\" value=\"{1}@$${{domain}}\"/>"+
285 "<user id=\"{3}\">\r\n" +
287 "<param name=\"password\" value=\"{2}\" />\r\n" +
288 "<param name=\"dial-string\" value=\"{{sip_contact_user={1}}}{{presence_id=${3}@${{dialed_domain}}}}${{sofia_contact(${3}@${{dialed_domain}})}}\"/>\r\n" +
291 "<variable name=\"user_context\" value=\"{4}\" />\r\n" +
292 "<variable name=\"presence_id\" value=\"{3}@$${{domain}}\"/>"+
298 domain , user, password,sipRequestUser, Context);
303 private Hashtable HandleLocateUser(String Realm, Hashtable request)
305 m_log.Info(
"[FreeSwitchDirectory]: HandleLocateUser called");
308 string domain = (string) request[
"domain"];
309 string user = (string) request[
"user"];
311 Hashtable response =
new Hashtable();
312 response[
"content_type"] =
"text/xml";
313 response[
"keepalive"] =
false;
314 response[
"int_response_code"] = 200;
315 response[
"str_response_string"] = String.Format(
316 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
317 "<document type=\"freeswitch/xml\">\r\n" +
318 "<section name=\"directory\" description=\"User Directory\">\r\n" +
319 "<domain name=\"{0}\">\r\n" +
321 "<param name=\"dial-string\" value=\"{{sip_contact_user=${{dialed_user}}}}{{presence_id=${{dialed_user}}@${{dialed_domain}}}}${{sofia_contact(${{dialed_user}}@${{dialed_domain}})}}\"/>\r\n" +
323 "<user id=\"{1}\">\r\n" +
325 "<variable name=\"default_gateway\" value=\"$${{default_provider}}\"/>\r\n"+
326 "<variable name=\"presence_id\" value=\"{1}@$${{domain}}\"/>"+
337 private Hashtable HandleConfigSofia(
string Context,
string Realm, Hashtable request)
339 m_log.Info(
"[FreeSwitchDirectory]: HandleConfigSofia called.");
342 string domain = (string) request[
"domain"];
344 Hashtable response =
new Hashtable();
345 response[
"content_type"] =
"text/xml";
346 response[
"keepalive"] =
false;
347 response[
"int_response_code"] = 200;
348 response[
"str_response_string"] = String.Format(
349 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
350 "<document type=\"freeswitch/xml\">\r\n" +
351 "<section name=\"directory\" description=\"User Directory\">\r\n" +
352 "<domain name=\"{0}\">\r\n" +
354 "<param name=\"dial-string\" value=\"{{sip_contact_user=${{dialed_user}}}}{{presence_id=${{dialed_user}}@${{dialed_domain}}}}${{sofia_contact(${{dialed_user}}@${{dialed_domain}})}}\"/>\r\n" +
356 "<groups name=\"default\">\r\n"+
358 "<user id=\"$${{default_provider}}\">\r\n"+
360 "<gateway name=\"$${{default_provider}}\">\r\n"+
361 "<param name=\"username\" value=\"$${{default_provider_username}}\"/>\r\n"+
362 "<param name=\"password\" value=\"$${{default_provider_password}}\"/>\r\n"+
363 "<param name=\"from-user\" value=\"$${{default_provider_username}}\"/>\r\n"+
364 "<param name=\"from-domain\" value=\"$${{default_provider_from_domain}}\"/>\r\n"+
365 "<param name=\"expire-seconds\" value=\"600\"/>\r\n"+
366 "<param name=\"register\" value=\"$${{default_provider_register}}\"/>\r\n"+
367 "<param name=\"retry-seconds\" value=\"30\"/>\r\n"+
368 "<param name=\"extension\" value=\"$${{default_provider_contact}}\"/>\r\n"+
369 "<param name=\"contact-params\" value=\"domain_name=$${{domain}}\"/>\r\n"+
370 "<param name=\"context\" value=\"{1}\"/>\r\n"+
374 "<param name=\"password\" value=\"$${{default_provider_password}}\"/>\r\n"+
380 "<variable name=\"default_gateway\" value=\"$${{default_provider}}\"/>\r\n"+
394 map.Add(
"Realm", m_freeSwitchRealm);
395 map.Add(
"SIPProxy", m_freeSwitchSIPProxy);
396 map.Add(
"AttemptUseSTUN", m_freeSwitchAttemptUseSTUN);
397 map.Add(
"EchoServer", m_freeSwitchEchoServer);
398 map.Add(
"EchoPort", m_freeSwitchEchoPort);
399 map.Add(
"DefaultWellKnownIP", m_freeSwitchDefaultWellKnownIP);
400 map.Add(
"DefaultTimeout", m_freeSwitchDefaultTimeout);
401 map.Add(
"Context", m_freeSwitchContext);
402 map.Add(
"APIPrefix", m_freeSwitchAPIPrefix);
404 return OSDParser.SerializeJsonString(map);
Hashtable HandleDirectoryRequest(Hashtable request)
OpenMetaverse.StructuredData.OSDMap OSDMap
FreeswitchService(IConfigSource config)
Interactive OpenSim region server
Hashtable HandleDialplanRequest(Hashtable request)