aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchDirectory.cs
diff options
context:
space:
mode:
authorSean Dague2009-04-17 20:00:30 +0000
committerSean Dague2009-04-17 20:00:30 +0000
commit7f30be17d0ee841961262ee9e9b8fab27ccf6d83 (patch)
tree77a48e8135b5086ba4fd9225f72ce77f702011ce /OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchDirectory.cs
parentCorrect detected rotation to return the same value as llGetRot in the object ... (diff)
downloadopensim-SC_OLD-7f30be17d0ee841961262ee9e9b8fab27ccf6d83.zip
opensim-SC_OLD-7f30be17d0ee841961262ee9e9b8fab27ccf6d83.tar.gz
opensim-SC_OLD-7f30be17d0ee841961262ee9e9b8fab27ccf6d83.tar.bz2
opensim-SC_OLD-7f30be17d0ee841961262ee9e9b8fab27ccf6d83.tar.xz
experimental freeswitch code, imported from Rob Smart's tree
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchDirectory.cs335
1 files changed, 335 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchDirectory.cs b/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchDirectory.cs
new file mode 100644
index 0000000..9959d11
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchDirectory.cs
@@ -0,0 +1,335 @@
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 OpenSim 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
28using log4net;
29using System;
30using System.Reflection;
31using System.Text;
32using System.Collections;
33
34namespace 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(Hashtable request)
42 {
43 m_log.DebugFormat("[FreeSwitchDirectory] HandleDirectoryRequest called with {0}",request.ToString());
44
45 Hashtable response = new Hashtable();
46
47 // information in the request we might be interested in
48
49 // Request 1 sip_auth for users account
50
51 //Event-Calling-Function=sofia_reg_parse_auth
52 //Event-Calling-Line-Number=1494
53 //action=sip_auth
54 //sip_user_agent=Vivox-SDK-2.1.3010.6151-Mac%20(Feb-11-2009/16%3A42%3A41)
55 //sip_auth_username=xhZuXKmRpECyr2AARJYyGgg%3D%3D (==)
56 //sip_auth_realm=9.20.151.43
57 //sip_contact_user=xhZuXKmRpECyr2AARJYyGgg%3D%3D (==)
58 //sip_contact_host=192.168.0.3 // this shouldnt really be a local IP, investigate STUN servers
59 //sip_to_user=xhZuXKmRpECyr2AARJYyGgg%3D%3D
60 //sip_to_host=9.20.151.43
61 //sip_auth_method=REGISTER
62 //user=xhZuXKmRpECyr2AARJYyGgg%3D%3D
63 //domain=9.20.151.43
64 //ip=9.167.220.137 // this is the correct IP rather than sip_contact_host above when through a vpn or NAT setup
65
66 foreach(DictionaryEntry item in request)
67 {
68 m_log.InfoFormat("[FreeSwitchDirectory] requestBody item {0} {1}",item.Key, item.Value);
69 }
70
71 string eventCallingFunction = (string) request["Event-Calling-Function"];
72
73
74 if(eventCallingFunction=="sofia_reg_parse_auth")
75 {
76 string sipAuthMethod = (string)request["sip_auth_method"];
77
78 if(sipAuthMethod=="REGISTER")
79 {
80 response = HandleRegister(request);
81 }
82 else if(sipAuthMethod=="INVITE")
83 {
84 response = HandleInvite(request);
85 }
86 else
87 {
88 m_log.ErrorFormat("[FreeSwitchVoice] HandleDirectoryRequest unknown sip_auth_method {0}",sipAuthMethod);
89 response["int_response_code"]=404;
90 }
91 }
92 else if(eventCallingFunction=="switch_xml_locate_user")
93 {
94 response = HandleLocateUser(request);
95 }
96 else if(eventCallingFunction=="user_data_function") // gets called when an avatar to avatar call is made
97 {
98 response = HandleLocateUser(request);
99 }
100 else if(eventCallingFunction=="user_outgoing_channel")
101 {
102 response = HandleRegister(request);
103 }
104 else if(eventCallingFunction=="config_sofia") // happens once on freeswitch startup
105 {
106 response = HandleConfigSofia(request);
107 }
108 else if(eventCallingFunction=="switch_load_network_lists")
109 {
110 //response = HandleLoadNetworkLists(request);
111 response["int_response_code"]=404;
112 response["keepalive"] = false;
113 }
114 else
115 {
116 m_log.ErrorFormat("[FreeSwitchVoice] HandleDirectoryRequest unknown Event-Calling-Function {0}",eventCallingFunction);
117 response["int_response_code"]=404;
118 response["keepalive"] = false;
119 }
120
121
122
123 return response;
124 }
125
126 private Hashtable HandleRegister(Hashtable request)
127 {
128 m_log.Info("[FreeSwitchDirectory] HandleRegister called");
129
130 // TODO the password we return needs to match that sent in the request, this is hard coded for now
131 string password = "1234";
132 string domain = (string) request["domain"];
133 string user = (string) request["user"];
134
135 Hashtable response = new Hashtable();
136 response["content_type"] = "text/xml";
137 response["keepalive"] = false;
138 response["int_response_code"]=200;
139 response["str_response_string"] = String.Format(
140 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
141 "<document type=\"freeswitch/xml\">\r\n" +
142 "<section name=\"directory\" description=\"User Directory\">\r\n" +
143 "<domain name=\"{0}\">\r\n" +
144 "<user id=\"{1}\">\r\n" +
145 "<params>\r\n" +
146 "<param name=\"password\" value=\"{2}\" />\r\n" +
147 "<param name=\"dial-string\" value=\"{{presence_id=${{dialed_user}}@${{dialed_domain}}}}${{sofia_contact(${{dialed_user}}@${{dialed_domain}})}}\"/>\r\n" +
148 "</params>\r\n" +
149 "<variables>\r\n" +
150 "<variable name=\"user_context\" value=\"default\" />\r\n" +
151 "<variable name=\"presence_id\" value=\"{1}@{0}\"/>"+
152 "</variables>\r\n" +
153 "</user>\r\n" +
154 "</domain>\r\n" +
155 "</section>\r\n" +
156 "</document>\r\n"
157 , domain , user, password);
158
159 return response;
160
161 }
162
163 private Hashtable HandleInvite(Hashtable request)
164 {
165 m_log.Info("[FreeSwitchDirectory] HandleInvite called");
166
167 // TODO the password we return needs to match that sent in the request, this is hard coded for now
168 string password = "1234";
169 string domain = (string) request["domain"];
170 string user = (string) request["user"];
171 string sipRequestUser = (string) request["sip_request_user"];
172
173 Hashtable response = new Hashtable();
174 response["content_type"] = "text/xml";
175 response["keepalive"] = false;
176 response["int_response_code"]=200;
177 response["str_response_string"] = String.Format(
178 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
179 "<document type=\"freeswitch/xml\">\r\n" +
180 "<section name=\"directory\" description=\"User Directory\">\r\n" +
181 "<domain name=\"{0}\">\r\n" +
182 "<user id=\"{1}\">\r\n" +
183 "<params>\r\n" +
184 "<param name=\"password\" value=\"{2}\" />\r\n" +
185 "<param name=\"dial-string\" value=\"{{presence_id=${1}@${{dialed_domain}}}}${{sofia_contact(${1}@${{dialed_domain}})}}\"/>\r\n" +
186 "</params>\r\n" +
187 "<variables>\r\n" +
188 "<variable name=\"user_context\" value=\"default\" />\r\n" +
189 "<variable name=\"presence_id\" value=\"{1}@$${{domain}}\"/>"+
190 "</variables>\r\n" +
191 "</user>\r\n" +
192 "<user id=\"{3}\">\r\n" +
193 "<params>\r\n" +
194 "<param name=\"password\" value=\"{2}\" />\r\n" +
195 "<param name=\"dial-string\" value=\"{{presence_id=${3}@${{dialed_domain}}}}${{sofia_contact(${3}@${{dialed_domain}})}}\"/>\r\n" +
196 "</params>\r\n" +
197 "<variables>\r\n" +
198 "<variable name=\"user_context\" value=\"default\" />\r\n" +
199 "<variable name=\"presence_id\" value=\"{3}@$${{domain}}\"/>"+
200 "</variables>\r\n" +
201 "</user>\r\n" +
202 "</domain>\r\n" +
203 "</section>\r\n" +
204 "</document>\r\n"
205 , domain , user, password,sipRequestUser);
206
207 return response;
208 }
209
210
211 private Hashtable HandleLocateUser(Hashtable request)
212 {
213 m_log.Info("[FreeSwitchDirectory] HandleLocateUser called");
214
215 // TODO the password we return needs to match that sent in the request, this is hard coded for now
216 string domain = (string) request["domain"];
217 string user = (string) request["user"];
218
219 Hashtable response = new Hashtable();
220 response["content_type"] = "text/xml";
221 response["keepalive"] = false;
222 response["int_response_code"]=200;
223 response["str_response_string"] = String.Format(
224 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
225 "<document type=\"freeswitch/xml\">\r\n" +
226 "<section name=\"directory\" description=\"User Directory\">\r\n" +
227 "<domain name=\"{0}\">\r\n" +
228 "<params>\r\n" +
229 "<param name=\"dial-string\" value=\"{{presence_id=${{dialed_user}}@${{dialed_domain}}}}${{sofia_contact(${{dialed_user}}@${{dialed_domain}})}}\"/>\r\n" +
230 "</params>\r\n" +
231 "<user id=\"{1}\">\r\n" +
232 "<variables>\r\n"+
233 "<variable name=\"default_gateway\" value=\"$${{default_provider}}\"/>\r\n"+
234 "<variable name=\"presence_id\" value=\"{1}@$${{domain}}\"/>"+
235 "</variables>\r\n"+
236 "</user>\r\n" +
237 "</domain>\r\n" +
238 "</section>\r\n" +
239 "</document>\r\n"
240 , domain , user);
241
242
243
244 return response;
245 }
246
247 private Hashtable HandleConfigSofia(Hashtable request)
248 {
249 m_log.Info("[FreeSwitchDirectory] HandleConfigSofia called");
250
251 // TODO the password we return needs to match that sent in the request, this is hard coded for now
252 string domain = (string) request["domain"];
253
254 Hashtable response = new Hashtable();
255 response["content_type"] = "text/xml";
256 response["keepalive"] = false;
257 response["int_response_code"]=200;
258 response["str_response_string"] = String.Format(
259 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
260 "<document type=\"freeswitch/xml\">\r\n" +
261 "<section name=\"directory\" description=\"User Directory\">\r\n" +
262 "<domain name=\"{0}\">\r\n" +
263 "<params>\r\n" +
264 "<param name=\"dial-string\" value=\"{{presence_id=${{dialed_user}}@${{dialed_domain}}}}${{sofia_contact(${{dialed_user}}@${{dialed_domain}})}}\"/>\r\n" +
265 "</params>\r\n" +
266 "<groups name=\"default\">\r\n"+
267 "<users>\r\n"+
268 "<user id=\"$${{default_provider}}\">\r\n"+
269 "<gateways>\r\n"+
270 "<gateway name=\"$${{default_provider}}\">\r\n"+
271 "<param name=\"username\" value=\"$${{default_provider_username}}\"/>\r\n"+
272 "<param name=\"password\" value=\"$${{default_provider_password}}\"/>\r\n"+
273 "<param name=\"from-user\" value=\"$${{default_provider_username}}\"/>\r\n"+
274 "<param name=\"from-domain\" value=\"$${{default_provider_from_domain}}\"/>\r\n"+
275 "<param name=\"expire-seconds\" value=\"600\"/>\r\n"+
276 "<param name=\"register\" value=\"$${{default_provider_register}}\"/>\r\n"+
277 "<param name=\"retry-seconds\" value=\"30\"/>\r\n"+
278 "<param name=\"extension\" value=\"$${{default_provider_contact}}\"/>\r\n"+
279 "<param name=\"contact-params\" value=\"domain_name=$${{domain}}\"/>\r\n"+
280 "<param name=\"context\" value=\"public\"/>\r\n"+
281 "</gateway>\r\n"+
282 "</gateways>\r\n"+
283 "<params>\r\n"+
284 "<param name=\"password\" value=\"$${{default_provider_password}}\"/>\r\n"+
285 "</params>\r\n"+
286 "</user>\r\n"+
287 "</users>"+
288 "</groups>\r\n" +
289 "<variables>\r\n"+
290 "<variable name=\"default_gateway\" value=\"$${{default_provider}}\"/>\r\n"+
291 "</variables>\r\n"+
292 "</domain>\r\n" +
293 "</section>\r\n" +
294 "</document>\r\n"
295 , domain);
296
297
298 return response;
299 }
300
301 private Hashtable HandleLoadNetworkLists(Hashtable request)
302 {
303 m_log.Info("[FreeSwitchDirectory] HandleLoadNetworkLists 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
308 Hashtable response = new Hashtable();
309 response["content_type"] = "text/xml";
310 response["keepalive"] = false;
311 response["int_response_code"]=200;
312 response["str_response_string"] = String.Format(
313 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
314 "<document type=\"freeswitch/xml\">\r\n" +
315 "<section name=\"directory\" description=\"User Directory\">\r\n" +
316 "<domain name=\"{0}\">\r\n" +
317 "<params>\r\n" +
318 "<param name=\"dial-string\" value=\"{{presence_id=${{dialed_user}}@${{dialed_domain}}}}${{sofia_contact(${{dialed_user}}@${{dialed_domain}})}}\"/>\r\n" +
319 "</params>\r\n" +
320 "<groups name=\"default\"><users/></groups>\r\n" +
321 "<variables>\r\n"+
322 "<variable name=\"default_gateway\" value=\"$${{default_provider}}\"/>\r\n"+
323 "</variables>\r\n"+
324 "</domain>\r\n" +
325 "</section>\r\n" +
326 "</document>\r\n"
327 , domain);
328
329
330 return response;
331 }
332
333 }
334
335} \ No newline at end of file