aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorSean Dague2008-04-15 14:24:15 +0000
committerSean Dague2008-04-15 14:24:15 +0000
commit6f8ff326307ae1522e2f3163596b0bf1cdd2157f (patch)
tree4517fcd0560e9cf05ad170c0032fc9a60e7a01e4 /OpenSim
parentFrom: dirk husemann <hud@zurich.ibm.com> (diff)
downloadopensim-SC-6f8ff326307ae1522e2f3163596b0bf1cdd2157f.zip
opensim-SC-6f8ff326307ae1522e2f3163596b0bf1cdd2157f.tar.gz
opensim-SC-6f8ff326307ae1522e2f3163596b0bf1cdd2157f.tar.bz2
opensim-SC-6f8ff326307ae1522e2f3163596b0bf1cdd2157f.tar.xz
From: Dr Scofield <hud@zurich.ibm.com>
ansgar and i have been working on an asterisk voice module that will allow us to couple opensim with an asterisk VoIP gateway. the patch below consists of * AsteriskVoiceModule region module: alternative to the plain-vanilla VoiceModule, will make XmlRpc calls out to an asterisk-opensim frontend * asterisk-opensim.py frontend, living in share/python/asterisk, takes XmlRpc calls from the AsteriskVoiceModule * account_update: to update/create a new SIP account (on ProvisionVoiceAccountRequest) * region_update: to update/create a new "region" conference call (on ParcelVoiceInfo) * a asterisk-opensim test client, living in share/python/asterisk, to exercise astersik-opensim.py this still does not give us voice in OpenSim, but it's another step on this path...
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Communications/Capabilities/Caps.cs1
-rw-r--r--OpenSim/Region/Environment/Modules/AsteriskVoiceModule.cs288
2 files changed, 289 insertions, 0 deletions
diff --git a/OpenSim/Framework/Communications/Capabilities/Caps.cs b/OpenSim/Framework/Communications/Capabilities/Caps.cs
index 46f50ad..a65a3f1 100644
--- a/OpenSim/Framework/Communications/Capabilities/Caps.cs
+++ b/OpenSim/Framework/Communications/Capabilities/Caps.cs
@@ -201,6 +201,7 @@ namespace OpenSim.Region.Capabilities
201 { 201 {
202 //Console.WriteLine("caps request " + request); 202 //Console.WriteLine("caps request " + request);
203 string result = LLSDHelpers.SerialiseLLSDReply(m_capsHandlers.CapsDetails); 203 string result = LLSDHelpers.SerialiseLLSDReply(m_capsHandlers.CapsDetails);
204 //m_log.DebugFormat("[CAPS] CapsRequest {0}", result);
204 return result; 205 return result;
205 } 206 }
206 207
diff --git a/OpenSim/Region/Environment/Modules/AsteriskVoiceModule.cs b/OpenSim/Region/Environment/Modules/AsteriskVoiceModule.cs
new file mode 100644
index 0000000..52b9c3e
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/AsteriskVoiceModule.cs
@@ -0,0 +1,288 @@
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 System;
29using System.Collections;
30using System.Collections.Generic;
31using libsecondlife;
32using Nini.Config;
33using Nwc.XmlRpc;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications.Cache;
36using OpenSim.Framework.Servers;
37using OpenSim.Region.Capabilities;
38using Caps = OpenSim.Region.Capabilities.Caps;
39using OpenSim.Region.Environment.Interfaces;
40using OpenSim.Region.Environment.Scenes;
41
42namespace OpenSim.Region.Environment.Modules
43{
44 public class AsteriskVoiceModule : IRegionModule
45 {
46 private static readonly log4net.ILog m_log =
47 log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
48
49 private Scene m_scene;
50 private IConfig m_config;
51 private string m_asterisk;
52 private string m_asterisk_password;
53 private string m_asterisk_salt;
54 private int m_asterisk_timeout;
55 private string m_sipDomain;
56 private string m_confDomain;
57
58 private static readonly string m_parcelVoiceInfoRequestPath = "0007/";
59 private static readonly string m_provisionVoiceAccountRequestPath = "0008/";
60
61 public void Initialise(Scene scene, IConfigSource config)
62 {
63 m_scene = scene;
64 m_config = config.Configs["AsteriskVoice"];
65
66 if (null == m_config)
67 {
68 m_log.Info("[ASTERISKVOICE] no config found, plugin disabled");
69 return;
70 }
71
72 if (!m_config.GetBoolean("enabled", false))
73 {
74 m_log.Info("[ASTERISKVOICE] plugin disabled by configuration");
75 return;
76 }
77 m_log.Info("[ASTERISKVOICE] plugin enabled");
78
79 try {
80 m_sipDomain = m_config.GetString("sip_domain", String.Empty);
81 m_log.InfoFormat("[ASTERISKVOICE] using SIP domain {0}", m_sipDomain);
82
83 m_confDomain = m_config.GetString("conf_domain", String.Empty);
84 m_log.InfoFormat("[ASTERISKVOICE] using conf domain {0}", m_confDomain);
85
86 m_asterisk = m_config.GetString("asterisk_frontend", String.Empty);
87 m_asterisk_password = m_config.GetString("asterisk_password", String.Empty);
88 m_asterisk_timeout = m_config.GetInt("asterisk_timeout", 3000);
89 m_asterisk_salt = m_config.GetString("asterisk_salt", "Wuffwuff");
90 if (String.IsNullOrEmpty(m_asterisk)) throw new Exception("missing asterisk_frontend config parameter");
91 if (String.IsNullOrEmpty(m_asterisk_password)) throw new Exception("missing asterisk_password config parameter");
92 m_log.InfoFormat("[ASTERISKVOICE] using asterisk front end {0}", m_asterisk);
93
94 scene.EventManager.OnRegisterCaps += OnRegisterCaps;
95 }
96 catch (Exception e)
97 {
98 m_log.ErrorFormat("[ASTERISKVOICE] plugin initialization failed: {0}", e.Message);
99 m_log.DebugFormat("[ASTERISKVOICE] plugin initialization failed: {0}", e.ToString());
100 return;
101 }
102 }
103
104 public void PostInitialise()
105 {
106 }
107
108 public void Close()
109 {
110 }
111
112 public string Name
113 {
114 get { return "AsteriskVoiceModule"; }
115 }
116
117 public bool IsSharedModule
118 {
119 get { return false; }
120 }
121
122 public void OnRegisterCaps(LLUUID agentID, Caps caps)
123 {
124 m_log.DebugFormat("[ASTERISKVOICE] OnRegisterCaps: agentID {0} caps {1}", agentID, caps);
125 string capsBase = "/CAPS/" + caps.CapsObjectPath;
126 caps.RegisterHandler("ParcelVoiceInfoRequest",
127 new RestStreamHandler("POST", capsBase + m_parcelVoiceInfoRequestPath,
128 delegate(string request, string path, string param)
129 {
130 return ParcelVoiceInfoRequest(request, path, param,
131 agentID, caps);
132 }));
133 caps.RegisterHandler("ProvisionVoiceAccountRequest",
134 new RestStreamHandler("POST", capsBase + m_provisionVoiceAccountRequestPath,
135 delegate(string request, string path, string param)
136 {
137 return ProvisionVoiceAccountRequest(request, path, param,
138 agentID, caps);
139 }));
140 }
141
142 /// <summary>
143 /// Callback for a client request for ParcelVoiceInfo
144 /// </summary>
145 /// <param name="request"></param>
146 /// <param name="path"></param>
147 /// <param name="param"></param>
148 /// <param name="agentID"></param>
149 /// <param name="caps"></param>
150 /// <returns></returns>
151 public string ParcelVoiceInfoRequest(string request, string path, string param,
152 LLUUID agentID, Caps caps)
153 {
154 // we need to do:
155 // - send channel_uri: as "sip:regionID@m_sipDomain"
156 try
157 {
158 m_log.DebugFormat("[ASTERISKVOICE][PARCELVOICE]: request: {0}, path: {1}, param: {2}",
159 request, path, param);
160
161
162 // setup response to client
163 Hashtable creds = new Hashtable();
164 creds["channel_uri"] = String.Format("sip:{0}@{1}",
165 m_scene.RegionInfo.RegionID.ToString(), m_sipDomain);
166
167 string regionName = m_scene.RegionInfo.RegionName;
168 ScenePresence avatar = m_scene.GetScenePresence(agentID);
169 if (null == m_scene.LandChannel) throw new Exception("land data not yet available");
170 LandData land = m_scene.GetLandData(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
171
172 LLSDParcelVoiceInfoResponse parcelVoiceInfo =
173 new LLSDParcelVoiceInfoResponse(regionName, land.localID, creds);
174
175 string r = LLSDHelpers.SerialiseLLSDReply(parcelVoiceInfo);
176
177
178 // update region on asterisk-opensim frontend
179 Hashtable requestData = new Hashtable();
180 requestData["admin_password"] = m_asterisk_password;
181 requestData["region"] = m_scene.RegionInfo.RegionID.ToString();
182 if (!String.IsNullOrEmpty(m_confDomain))
183 {
184 requestData["region"] += String.Format("@{0}", m_confDomain);
185 }
186
187 ArrayList SendParams = new ArrayList();
188 SendParams.Add(requestData);
189 XmlRpcRequest updateAccountRequest = new XmlRpcRequest("region_update", SendParams);
190 XmlRpcResponse updateAccountResponse = updateAccountRequest.Send(m_asterisk, m_asterisk_timeout);
191 Hashtable responseData = (Hashtable)updateAccountResponse.Value;
192
193 if (!responseData.ContainsKey("success")) throw new Exception("region_update call failed");
194
195 bool success = Convert.ToBoolean((string)responseData["success"]);
196 if (!success) throw new Exception("region_update failed");
197
198
199 m_log.DebugFormat("[ASTERISKVOICE][PARCELVOICE]: {0}", r);
200 return r;
201 }
202 catch (Exception e)
203 {
204 m_log.ErrorFormat("[ASTERISKVOICE][CAPS][PARCELVOICE]: {0}, retry later", e.Message);
205 m_log.DebugFormat("[ASTERISKVOICE][CAPS][PARCELVOICE]: {0} failed", e.ToString());
206
207 return "<llsd>undef</llsd>";
208 }
209
210 return null;
211 }
212
213 /// <summary>
214 /// Callback for a client request for Voice Account Details
215 /// </summary>
216 /// <param name="request"></param>
217 /// <param name="path"></param>
218 /// <param name="param"></param>
219 /// <param name="agentID"></param>
220 /// <param name="caps"></param>
221 /// <returns></returns>
222 public string ProvisionVoiceAccountRequest(string request, string path, string param,
223 LLUUID agentID, Caps caps)
224 {
225 // we need to
226 // - get user data from UserProfileCacheService
227 // - generate nonce for user voice account password
228 // - issue XmlRpc request to asterisk opensim front end:
229 // + user: base 64 encoded user name (otherwise SL
230 // client is unhappy)
231 // + password: nonce
232 // - the XmlRpc call to asteris-opensim was successful:
233 // send account details back to client
234 try
235 {
236 m_log.DebugFormat("[ASTERISKVOICE][PROVISIONVOICE]: request: {0}, path: {1}, param: {2}",
237 request, path, param);
238
239 // get user data & prepare voice account response
240 string voiceUser = "x" + Convert.ToBase64String(agentID.GetBytes());
241 voiceUser = voiceUser.Replace('+', '-').Replace('/', '_');
242
243 CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(agentID);
244 if (null == userInfo) throw new Exception("cannot get user details");
245
246 // we generate a nonce everytime
247 string voicePassword = "$1$" + Util.Md5Hash(DateTime.UtcNow.ToLongTimeString() + m_asterisk_salt);
248 LLSDVoiceAccountResponse voiceAccountResponse =
249 new LLSDVoiceAccountResponse(voiceUser, voicePassword);
250 string r = LLSDHelpers.SerialiseLLSDReply(voiceAccountResponse);
251 m_log.DebugFormat("[CAPS][PROVISIONVOICE]: {0}", r);
252
253
254 // update user account on asterisk frontend
255 Hashtable requestData = new Hashtable();
256 requestData["admin_password"] = m_asterisk_password;
257 requestData["username"] = voiceUser;
258 if (!String.IsNullOrEmpty(m_sipDomain))
259 {
260 requestData["username"] += String.Format("@{0}", m_sipDomain);
261 }
262 requestData["password"] = voicePassword;
263
264 ArrayList SendParams = new ArrayList();
265 SendParams.Add(requestData);
266 XmlRpcRequest updateAccountRequest = new XmlRpcRequest("account_update", SendParams);
267 XmlRpcResponse updateAccountResponse = updateAccountRequest.Send(m_asterisk, m_asterisk_timeout);
268 Hashtable responseData = (Hashtable)updateAccountResponse.Value;
269
270 if (!responseData.ContainsKey("success")) throw new Exception("account_update call failed");
271
272 bool success = Convert.ToBoolean((string)responseData["success"]);
273 if (!success) throw new Exception("account_update failed");
274
275 return r;
276 }
277 catch (Exception e)
278 {
279 m_log.ErrorFormat("[ASTERISKVOICE][CAPS][PROVISIONVOICE]: {0}, retry later", e.Message);
280 m_log.DebugFormat("[ASTERISKVOICE][CAPS][PROVISIONVOICE]: {0} failed", e.ToString());
281
282 return "<llsd>undef</llsd>";
283 }
284
285 return null;
286 }
287 }
288}