private byte[] HandleRegister(string Context, string Realm, Hashtable request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) { MainConsole.Instance.Info("[FreeSwitchDirectory] HandleRegister called"); // TODO the password we return needs to match that sent in the request, this is hard coded for now string password = "******"; string domain = (string)request["domain"]; string user = (string)request["user"]; httpResponse.ContentType = "text/xml"; httpResponse.StatusCode = 200; return Encoding.UTF8.GetBytes(String.Format( "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<document type=\"freeswitch/xml\">\r\n" + "<section name=\"directory\" description=\"User Directory\">\r\n" + "<domain name=\"{0}\">\r\n" + "<user id=\"{1}\">\r\n" + "<params>\r\n" + "<param name=\"password\" value=\"{2}\" />\r\n" + "<param name=\"dial-string\" value=\"{{sip_contact_user={1}}}{{presence_id=${{dialed_user}}@${{dialed_domain}}}}${{sofia_contact(${{dialed_user}}@${{dialed_domain}})}}\"/>\r\n" + "</params>\r\n" + "<variables>\r\n" + "<variable name=\"user_context\" value=\"{3}\" />\r\n" + "<variable name=\"presence_id\" value=\"{1}@{0}\"/>" + "</variables>\r\n" + "</user>\r\n" + "</domain>\r\n" + "</section>\r\n" + "</document>\r\n", domain, user, password, Context)); }
public byte[] HandleDirectoryRequest(Hashtable request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) { string domain = (string)request["domain"]; if (domain != m_freeSwitchRealm) { httpResponse.ContentType = "text/xml"; httpResponse.StatusCode = 200; return MainServer.BadRequest; } else { MainConsole.Instance.DebugFormat("[FreeSwitchDirectory] HandleDirectoryRequest called with {0}", request.ToString()); // information in the request we might be interested in // Request 1 sip_auth for users account //Event-Calling-Function=sofia_reg_parse_auth //Event-Calling-Line-Number=1494 //action=sip_auth //sip_user_agent=Vivox-SDK-2.1.3010.6151-Mac%20(Feb-11-2009/16%3A42%3A41) //sip_auth_username=xhZuXKmRpECyr2AARJYyGgg%3D%3D (==) //sip_auth_realm=9.20.151.43 //sip_contact_user=xhZuXKmRpECyr2AARJYyGgg%3D%3D (==) //sip_contact_host=192.168.0.3 // this shouldnt really be a local IP, investigate STUN servers //sip_to_user=xhZuXKmRpECyr2AARJYyGgg%3D%3D //sip_to_host=9.20.151.43 //sip_auth_method=REGISTER //user=xhZuXKmRpECyr2AARJYyGgg%3D%3D //domain=9.20.151.43 //ip=9.167.220.137 // this is the correct IP rather than sip_contact_host above when through a vpn or NAT setup foreach (DictionaryEntry item in request) { MainConsole.Instance.InfoFormat("[FreeSwitchDirectory] requestBody item {0} {1}", item.Key, item.Value); } string eventCallingFunction = (string)request["Event-Calling-Function"]; if (eventCallingFunction == null) { eventCallingFunction = "sofia_reg_parse_auth"; } if (eventCallingFunction.Length == 0) { eventCallingFunction = "sofia_reg_parse_auth"; } if (eventCallingFunction == "sofia_reg_parse_auth") { string sipAuthMethod = (string)request["sip_auth_method"]; if (sipAuthMethod == "REGISTER") { return HandleRegister(m_freeSwitchContext, m_freeSwitchRealm, request, httpRequest, httpResponse); } else if (sipAuthMethod == "INVITE") { return HandleInvite(m_freeSwitchContext, m_freeSwitchRealm, request, httpRequest, httpResponse); } else { MainConsole.Instance.ErrorFormat("[FreeSwitchVoice] HandleDirectoryRequest unknown sip_auth_method {0}", sipAuthMethod); httpResponse.ContentType = "text/xml"; httpResponse.StatusCode = 404; return MainServer.BadRequest; } } else if (eventCallingFunction == "switch_xml_locate_user") { return HandleLocateUser(m_freeSwitchRealm, request, httpRequest, httpResponse); } else if (eventCallingFunction == "user_data_function") // gets called when an avatar to avatar call is made { return HandleLocateUser(m_freeSwitchRealm, request, httpRequest, httpResponse); } else if (eventCallingFunction == "user_outgoing_channel") { return HandleRegister(m_freeSwitchContext, m_freeSwitchRealm, request, httpRequest, httpResponse); } else if (eventCallingFunction == "config_sofia") // happens once on freeswitch startup { return HandleConfigSofia(m_freeSwitchContext, m_freeSwitchRealm, request, httpRequest, httpResponse); } else if (eventCallingFunction == "switch_load_network_lists") { //response = HandleLoadNetworkLists(request); httpResponse.ContentType = "text/xml"; httpResponse.StatusCode = 404; return MainServer.BadRequest; } else { MainConsole.Instance.ErrorFormat("[FreeSwitchVoice] HandleDirectoryRequest unknown Event-Calling-Function {0}", eventCallingFunction); httpResponse.ContentType = "text/xml"; httpResponse.StatusCode = 404; return MainServer.BadRequest; } } }
private byte[] HandleConfigSofia(string Context, string Realm, Hashtable request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) { MainConsole.Instance.Info("[FreeSwitchDirectory] HandleConfigSofia called"); // TODO the password we return needs to match that sent in the request, this is hard coded for now string domain = (string)request["domain"]; httpResponse.ContentType = "text/xml"; httpResponse.StatusCode = 200; return Encoding.UTF8.GetBytes(String.Format( "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<document type=\"freeswitch/xml\">\r\n" + "<section name=\"directory\" description=\"User Directory\">\r\n" + "<domain name=\"{0}\">\r\n" + "<params>\r\n" + "<param name=\"dial-string\" value=\"{{sip_contact_user=${{dialed_user}}}}{{presence_id=${{dialed_user}}@${{dialed_domain}}}}${{sofia_contact(${{dialed_user}}@${{dialed_domain}})}}\"/>\r\n" + "</params>\r\n" + "<groups name=\"default\">\r\n" + "<users>\r\n" + "<user id=\"$${{default_provider}}\">\r\n" + "<gateways>\r\n" + "<gateway name=\"$${{default_provider}}\">\r\n" + "<param name=\"username\" value=\"$${{default_provider_username}}\"/>\r\n" + "<param name=\"password\" value=\"$${{default_provider_password}}\"/>\r\n" + "<param name=\"from-user\" value=\"$${{default_provider_username}}\"/>\r\n" + "<param name=\"from-domain\" value=\"$${{default_provider_from_domain}}\"/>\r\n" + "<param name=\"expire-seconds\" value=\"600\"/>\r\n" + "<param name=\"register\" value=\"$${{default_provider_register}}\"/>\r\n" + "<param name=\"retry-seconds\" value=\"30\"/>\r\n" + "<param name=\"extension\" value=\"$${{default_provider_contact}}\"/>\r\n" + "<param name=\"contact-params\" value=\"domain_name=$${{domain}}\"/>\r\n" + "<param name=\"context\" value=\"{1}\"/>\r\n" + "</gateway>\r\n" + "</gateways>\r\n" + "<params>\r\n" + "<param name=\"password\" value=\"$${{default_provider_password}}\"/>\r\n" + "</params>\r\n" + "</user>\r\n" + "</users>" + "</groups>\r\n" + "<variables>\r\n" + "<variable name=\"default_gateway\" value=\"$${{default_provider}}\"/>\r\n" + "</variables>\r\n" + "</domain>\r\n" + "</section>\r\n" + "</document>\r\n", domain, Context)); }
public byte[] HandleDialplanRequest(Hashtable request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) { MainConsole.Instance.DebugFormat("[FreeSwitchVoice] HandleDialplanRequest called with {0}", request.ToString()); string requestcontext = (string)request["Hunt-Context"]; httpResponse.ContentType = "text/xml"; httpResponse.StatusCode = 200; if (m_freeSwitchContext != String.Empty && m_freeSwitchContext != requestcontext) { MainConsole.Instance.Debug("[FreeSwitchDirectory] returning empty as it's for another context"); return MainServer.BadRequest; } else { return Encoding.UTF8.GetBytes(String.Format(@"<?xml version=""1.0"" encoding=""utf-8""?> <document type=""freeswitch/xml""> <section name=""dialplan""> <context name=""{0}"">" + /* <!-- dial via SIP uri --> <extension name=""sip_uri""> <condition field=""destination_number"" expression=""^sip:(.*)$""> <action application=""bridge"" data=""sofia/${use_profile}/$1""/> <!--<action application=""bridge"" data=""$1""/>--> </condition> </extension>*/ @"<extension name=""opensim_conferences""> <condition field=""destination_number"" expression=""^confctl-(.*)$""> <action application=""answer""/> <action application=""conference"" data=""$1-{1}@{0}""/> </condition> </extension> <extension name=""opensim_conf""> <condition field=""destination_number"" expression=""^conf-(.*)$""> <action application=""answer""/> <action application=""conference"" data=""$1-{1}@{0}""/> </condition> </extension> <extension name=""avatar""> <condition field=""destination_number"" expression=""^(x.*)$""> <action application=""bridge"" data=""user/$1""/> </condition> </extension> </context> </section> </document>", m_freeSwitchContext, m_freeSwitchRealm)); } }