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