aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Avatar/Voice/AsterixVoice/AsteriskVoiceModule.cs
diff options
context:
space:
mode:
authorAdam Frisby2008-04-30 21:43:47 +0000
committerAdam Frisby2008-04-30 21:43:47 +0000
commitbe20f41637b6c06ce3ab16bc25851b6e43468e12 (patch)
treec41081329891f4c24de704fc760fb9012954ac9d /OpenSim/Region/Environment/Modules/Avatar/Voice/AsterixVoice/AsteriskVoiceModule.cs
parent* Sometimes you know, you do something really stupid. (diff)
downloadopensim-SC-be20f41637b6c06ce3ab16bc25851b6e43468e12.zip
opensim-SC-be20f41637b6c06ce3ab16bc25851b6e43468e12.tar.gz
opensim-SC-be20f41637b6c06ce3ab16bc25851b6e43468e12.tar.bz2
opensim-SC-be20f41637b6c06ce3ab16bc25851b6e43468e12.tar.xz
* Cruft removal step #1. Cleaning Modules directory.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Avatar/Voice/AsterixVoice/AsteriskVoiceModule.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Voice/AsterixVoice/AsteriskVoiceModule.cs81
1 files changed, 43 insertions, 38 deletions
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Voice/AsterixVoice/AsteriskVoiceModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Voice/AsterixVoice/AsteriskVoiceModule.cs
index 0d7de78..44d67e6 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Voice/AsterixVoice/AsteriskVoiceModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Voice/AsterixVoice/AsteriskVoiceModule.cs
@@ -44,40 +44,43 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.AsterixVoice
44{ 44{
45 public class AsteriskVoiceModule : IRegionModule 45 public class AsteriskVoiceModule : IRegionModule
46 { 46 {
47 private static readonly ILog m_log = 47 private static readonly ILog m_log =
48 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 48 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49 49
50 private Scene m_scene; 50 private static readonly string m_parcelVoiceInfoRequestPath = "0007/";
51 private IConfig m_config; 51 private static readonly string m_provisionVoiceAccountRequestPath = "0008/";
52
52 private string m_asterisk; 53 private string m_asterisk;
53 private string m_asterisk_password; 54 private string m_asterisk_password;
54 private string m_asterisk_salt; 55 private string m_asterisk_salt;
55 private int m_asterisk_timeout; 56 private int m_asterisk_timeout;
56 private string m_sipDomain;
57 private string m_confDomain; 57 private string m_confDomain;
58 private IConfig m_config;
59 private Scene m_scene;
60 private string m_sipDomain;
58 61
59 private static readonly string m_parcelVoiceInfoRequestPath = "0007/"; 62 #region IRegionModule Members
60 private static readonly string m_provisionVoiceAccountRequestPath = "0008/";
61 63
62 public void Initialise(Scene scene, IConfigSource config) 64 public void Initialise(Scene scene, IConfigSource config)
63 { 65 {
64 m_scene = scene; 66 m_scene = scene;
65 m_config = config.Configs["AsteriskVoice"]; 67 m_config = config.Configs["AsteriskVoice"];
66 68
67 if (null == m_config) 69 if (null == m_config)
68 { 70 {
69 m_log.Info("[ASTERISKVOICE] no config found, plugin disabled"); 71 m_log.Info("[ASTERISKVOICE] no config found, plugin disabled");
70 return; 72 return;
71 } 73 }
72 74
73 if (!m_config.GetBoolean("enabled", false)) 75 if (!m_config.GetBoolean("enabled", false))
74 { 76 {
75 m_log.Info("[ASTERISKVOICE] plugin disabled by configuration"); 77 m_log.Info("[ASTERISKVOICE] plugin disabled by configuration");
76 return; 78 return;
77 } 79 }
78 m_log.Info("[ASTERISKVOICE] plugin enabled"); 80 m_log.Info("[ASTERISKVOICE] plugin enabled");
79 81
80 try { 82 try
83 {
81 m_sipDomain = m_config.GetString("sip_domain", String.Empty); 84 m_sipDomain = m_config.GetString("sip_domain", String.Empty);
82 m_log.InfoFormat("[ASTERISKVOICE] using SIP domain {0}", m_sipDomain); 85 m_log.InfoFormat("[ASTERISKVOICE] using SIP domain {0}", m_sipDomain);
83 86
@@ -91,17 +94,17 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.AsterixVoice
91 if (String.IsNullOrEmpty(m_asterisk)) throw new Exception("missing asterisk_frontend config parameter"); 94 if (String.IsNullOrEmpty(m_asterisk)) throw new Exception("missing asterisk_frontend config parameter");
92 if (String.IsNullOrEmpty(m_asterisk_password)) throw new Exception("missing asterisk_password config parameter"); 95 if (String.IsNullOrEmpty(m_asterisk_password)) throw new Exception("missing asterisk_password config parameter");
93 m_log.InfoFormat("[ASTERISKVOICE] using asterisk front end {0}", m_asterisk); 96 m_log.InfoFormat("[ASTERISKVOICE] using asterisk front end {0}", m_asterisk);
94 97
95 scene.EventManager.OnRegisterCaps += OnRegisterCaps; 98 scene.EventManager.OnRegisterCaps += OnRegisterCaps;
96 } 99 }
97 catch (Exception e) 100 catch (Exception e)
98 { 101 {
99 m_log.ErrorFormat("[ASTERISKVOICE] plugin initialization failed: {0}", e.Message); 102 m_log.ErrorFormat("[ASTERISKVOICE] plugin initialization failed: {0}", e.Message);
100 m_log.DebugFormat("[ASTERISKVOICE] plugin initialization failed: {0}", e.ToString()); 103 m_log.DebugFormat("[ASTERISKVOICE] plugin initialization failed: {0}", e.ToString());
101 return; 104 return;
102 } 105 }
103 } 106 }
104 107
105 public void PostInitialise() 108 public void PostInitialise()
106 { 109 {
107 } 110 }
@@ -120,15 +123,17 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.AsterixVoice
120 get { return false; } 123 get { return false; }
121 } 124 }
122 125
123 public void OnRegisterCaps(LLUUID agentID, Caps caps) 126 #endregion
127
128 public void OnRegisterCaps(LLUUID agentID, Caps caps)
124 { 129 {
125 m_log.DebugFormat("[ASTERISKVOICE] OnRegisterCaps: agentID {0} caps {1}", agentID, caps); 130 m_log.DebugFormat("[ASTERISKVOICE] OnRegisterCaps: agentID {0} caps {1}", agentID, caps);
126 string capsBase = "/CAPS/" + caps.CapsObjectPath; 131 string capsBase = "/CAPS/" + caps.CapsObjectPath;
127 caps.RegisterHandler("ParcelVoiceInfoRequest", 132 caps.RegisterHandler("ParcelVoiceInfoRequest",
128 new RestStreamHandler("POST", capsBase + m_parcelVoiceInfoRequestPath, 133 new RestStreamHandler("POST", capsBase + m_parcelVoiceInfoRequestPath,
129 delegate(string request, string path, string param) 134 delegate(string request, string path, string param)
130 { 135 {
131 return ParcelVoiceInfoRequest(request, path, param, 136 return ParcelVoiceInfoRequest(request, path, param,
132 agentID, caps); 137 agentID, caps);
133 })); 138 }));
134 caps.RegisterHandler("ProvisionVoiceAccountRequest", 139 caps.RegisterHandler("ProvisionVoiceAccountRequest",
@@ -139,7 +144,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.AsterixVoice
139 agentID, caps); 144 agentID, caps);
140 })); 145 }));
141 } 146 }
142 147
143 /// <summary> 148 /// <summary>
144 /// Callback for a client request for ParcelVoiceInfo 149 /// Callback for a client request for ParcelVoiceInfo
145 /// </summary> 150 /// </summary>
@@ -149,30 +154,30 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.AsterixVoice
149 /// <param name="agentID"></param> 154 /// <param name="agentID"></param>
150 /// <param name="caps"></param> 155 /// <param name="caps"></param>
151 /// <returns></returns> 156 /// <returns></returns>
152 public string ParcelVoiceInfoRequest(string request, string path, string param, 157 public string ParcelVoiceInfoRequest(string request, string path, string param,
153 LLUUID agentID, Caps caps) 158 LLUUID agentID, Caps caps)
154 { 159 {
155 // we need to do: 160 // we need to do:
156 // - send channel_uri: as "sip:regionID@m_sipDomain" 161 // - send channel_uri: as "sip:regionID@m_sipDomain"
157 try 162 try
158 { 163 {
159 m_log.DebugFormat("[ASTERISKVOICE][PARCELVOICE]: request: {0}, path: {1}, param: {2}", 164 m_log.DebugFormat("[ASTERISKVOICE][PARCELVOICE]: request: {0}, path: {1}, param: {2}",
160 request, path, param); 165 request, path, param);
161 166
162 167
163 // setup response to client 168 // setup response to client
164 Hashtable creds = new Hashtable(); 169 Hashtable creds = new Hashtable();
165 creds["channel_uri"] = String.Format("sip:{0}@{1}", 170 creds["channel_uri"] = String.Format("sip:{0}@{1}",
166 m_scene.RegionInfo.RegionID, m_sipDomain); 171 m_scene.RegionInfo.RegionID, m_sipDomain);
167 172
168 string regionName = m_scene.RegionInfo.RegionName; 173 string regionName = m_scene.RegionInfo.RegionName;
169 ScenePresence avatar = m_scene.GetScenePresence(agentID); 174 ScenePresence avatar = m_scene.GetScenePresence(agentID);
170 if (null == m_scene.LandChannel) throw new Exception("land data not yet available"); 175 if (null == m_scene.LandChannel) throw new Exception("land data not yet available");
171 LandData land = m_scene.GetLandData(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); 176 LandData land = m_scene.GetLandData(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
172 177
173 LLSDParcelVoiceInfoResponse parcelVoiceInfo = 178 LLSDParcelVoiceInfoResponse parcelVoiceInfo =
174 new LLSDParcelVoiceInfoResponse(regionName, land.localID, creds); 179 new LLSDParcelVoiceInfoResponse(regionName, land.localID, creds);
175 180
176 string r = LLSDHelpers.SerialiseLLSDReply(parcelVoiceInfo); 181 string r = LLSDHelpers.SerialiseLLSDReply(parcelVoiceInfo);
177 182
178 183
@@ -183,17 +188,17 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.AsterixVoice
183 if (!String.IsNullOrEmpty(m_confDomain)) 188 if (!String.IsNullOrEmpty(m_confDomain))
184 { 189 {
185 requestData["region"] += String.Format("@{0}", m_confDomain); 190 requestData["region"] += String.Format("@{0}", m_confDomain);
186 } 191 }
187 192
188 ArrayList SendParams = new ArrayList(); 193 ArrayList SendParams = new ArrayList();
189 SendParams.Add(requestData); 194 SendParams.Add(requestData);
190 XmlRpcRequest updateAccountRequest = new XmlRpcRequest("region_update", SendParams); 195 XmlRpcRequest updateAccountRequest = new XmlRpcRequest("region_update", SendParams);
191 XmlRpcResponse updateAccountResponse = updateAccountRequest.Send(m_asterisk, m_asterisk_timeout); 196 XmlRpcResponse updateAccountResponse = updateAccountRequest.Send(m_asterisk, m_asterisk_timeout);
192 Hashtable responseData = (Hashtable)updateAccountResponse.Value; 197 Hashtable responseData = (Hashtable) updateAccountResponse.Value;
193 198
194 if (!responseData.ContainsKey("success")) throw new Exception("region_update call failed"); 199 if (!responseData.ContainsKey("success")) throw new Exception("region_update call failed");
195 200
196 bool success = Convert.ToBoolean((string)responseData["success"]); 201 bool success = Convert.ToBoolean((string) responseData["success"]);
197 if (!success) throw new Exception("region_update failed"); 202 if (!success) throw new Exception("region_update failed");
198 203
199 204
@@ -218,8 +223,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.AsterixVoice
218 /// <param name="agentID"></param> 223 /// <param name="agentID"></param>
219 /// <param name="caps"></param> 224 /// <param name="caps"></param>
220 /// <returns></returns> 225 /// <returns></returns>
221 public string ProvisionVoiceAccountRequest(string request, string path, string param, 226 public string ProvisionVoiceAccountRequest(string request, string path, string param,
222 LLUUID agentID, Caps caps) 227 LLUUID agentID, Caps caps)
223 { 228 {
224 // we need to 229 // we need to
225 // - get user data from UserProfileCacheService 230 // - get user data from UserProfileCacheService
@@ -232,7 +237,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.AsterixVoice
232 // send account details back to client 237 // send account details back to client
233 try 238 try
234 { 239 {
235 m_log.DebugFormat("[ASTERISKVOICE][PROVISIONVOICE]: request: {0}, path: {1}, param: {2}", 240 m_log.DebugFormat("[ASTERISKVOICE][PROVISIONVOICE]: request: {0}, path: {1}, param: {2}",
236 request, path, param); 241 request, path, param);
237 242
238 // get user data & prepare voice account response 243 // get user data & prepare voice account response
@@ -244,7 +249,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.AsterixVoice
244 249
245 // we generate a nonce everytime 250 // we generate a nonce everytime
246 string voicePassword = "$1$" + Util.Md5Hash(DateTime.UtcNow.ToLongTimeString() + m_asterisk_salt); 251 string voicePassword = "$1$" + Util.Md5Hash(DateTime.UtcNow.ToLongTimeString() + m_asterisk_salt);
247 LLSDVoiceAccountResponse voiceAccountResponse = 252 LLSDVoiceAccountResponse voiceAccountResponse =
248 new LLSDVoiceAccountResponse(voiceUser, voicePassword); 253 new LLSDVoiceAccountResponse(voiceUser, voicePassword);
249 string r = LLSDHelpers.SerialiseLLSDReply(voiceAccountResponse); 254 string r = LLSDHelpers.SerialiseLLSDReply(voiceAccountResponse);
250 m_log.DebugFormat("[CAPS][PROVISIONVOICE]: {0}", r); 255 m_log.DebugFormat("[CAPS][PROVISIONVOICE]: {0}", r);
@@ -257,18 +262,18 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Voice.AsterixVoice
257 if (!String.IsNullOrEmpty(m_sipDomain)) 262 if (!String.IsNullOrEmpty(m_sipDomain))
258 { 263 {
259 requestData["username"] += String.Format("@{0}", m_sipDomain); 264 requestData["username"] += String.Format("@{0}", m_sipDomain);
260 } 265 }
261 requestData["password"] = voicePassword; 266 requestData["password"] = voicePassword;
262 267
263 ArrayList SendParams = new ArrayList(); 268 ArrayList SendParams = new ArrayList();
264 SendParams.Add(requestData); 269 SendParams.Add(requestData);
265 XmlRpcRequest updateAccountRequest = new XmlRpcRequest("account_update", SendParams); 270 XmlRpcRequest updateAccountRequest = new XmlRpcRequest("account_update", SendParams);
266 XmlRpcResponse updateAccountResponse = updateAccountRequest.Send(m_asterisk, m_asterisk_timeout); 271 XmlRpcResponse updateAccountResponse = updateAccountRequest.Send(m_asterisk, m_asterisk_timeout);
267 Hashtable responseData = (Hashtable)updateAccountResponse.Value; 272 Hashtable responseData = (Hashtable) updateAccountResponse.Value;
268 273
269 if (!responseData.ContainsKey("success")) throw new Exception("account_update call failed"); 274 if (!responseData.ContainsKey("success")) throw new Exception("account_update call failed");
270 275
271 bool success = Convert.ToBoolean((string)responseData["success"]); 276 bool success = Convert.ToBoolean((string) responseData["success"]);
272 if (!success) throw new Exception("account_update failed"); 277 if (!success) throw new Exception("account_update failed");
273 278
274 return r; 279 return r;