diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules/Avatar/Voice/SIPVoice/SIPVoiceModule.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/Avatar/Voice/SIPVoice/SIPVoiceModule.cs | 234 |
1 files changed, 0 insertions, 234 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/Voice/SIPVoice/SIPVoiceModule.cs b/OpenSim/Region/OptionalModules/Avatar/Voice/SIPVoice/SIPVoiceModule.cs deleted file mode 100644 index d00a256..0000000 --- a/OpenSim/Region/OptionalModules/Avatar/Voice/SIPVoice/SIPVoiceModule.cs +++ /dev/null | |||
@@ -1,234 +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 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Reflection; | ||
31 | using OpenMetaverse; | ||
32 | using log4net; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications.Cache; | ||
36 | using OpenSim.Framework.Communications.Capabilities; | ||
37 | using OpenSim.Framework.Servers; | ||
38 | using OpenSim.Region.Framework.Interfaces; | ||
39 | using OpenSim.Region.Framework.Scenes; | ||
40 | using Caps=OpenSim.Framework.Communications.Capabilities.Caps; | ||
41 | |||
42 | namespace OpenSim.Region.OptionalModules.Avatar.Voice.SIPVoice | ||
43 | { | ||
44 | public class SIPVoiceModule : IRegionModule | ||
45 | { | ||
46 | private static readonly ILog m_log = | ||
47 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private static readonly string m_parcelVoiceInfoRequestPath = "0007/"; | ||
50 | private static readonly string m_provisionVoiceAccountRequestPath = "0008/"; | ||
51 | private static readonly string m_chatSessionRequestPath = "0009/"; | ||
52 | private IConfig m_config; | ||
53 | private Scene m_scene; | ||
54 | private string m_sipDomain; | ||
55 | |||
56 | #region IRegionModule Members | ||
57 | |||
58 | public void Initialise(Scene scene, IConfigSource config) | ||
59 | { | ||
60 | m_scene = scene; | ||
61 | m_config = config.Configs["Voice"]; | ||
62 | |||
63 | if (null == m_config || !m_config.GetBoolean("enabled", false)) | ||
64 | { | ||
65 | m_log.Info("[VOICE] plugin disabled"); | ||
66 | return; | ||
67 | } | ||
68 | m_log.Info("[VOICE] plugin enabled"); | ||
69 | |||
70 | m_sipDomain = m_config.GetString("sip_domain", String.Empty); | ||
71 | if (String.IsNullOrEmpty(m_sipDomain)) | ||
72 | { | ||
73 | m_log.Error("[VOICE] plugin mis-configured: missing sip_domain configuration"); | ||
74 | m_log.Info("[VOICE] plugin disabled"); | ||
75 | return; | ||
76 | } | ||
77 | m_log.InfoFormat("[VOICE] using SIP domain {0}", m_sipDomain); | ||
78 | |||
79 | scene.EventManager.OnRegisterCaps += OnRegisterCaps; | ||
80 | } | ||
81 | |||
82 | public void PostInitialise() | ||
83 | { | ||
84 | } | ||
85 | |||
86 | public void Close() | ||
87 | { | ||
88 | } | ||
89 | |||
90 | public string Name | ||
91 | { | ||
92 | get { return "VoiceModule"; } | ||
93 | } | ||
94 | |||
95 | public bool IsSharedModule | ||
96 | { | ||
97 | get { return false; } | ||
98 | } | ||
99 | |||
100 | #endregion | ||
101 | |||
102 | public void OnRegisterCaps(UUID agentID, Caps caps) | ||
103 | { | ||
104 | m_log.DebugFormat("[VOICE] OnRegisterCaps: agentID {0} caps {1}", agentID, caps); | ||
105 | string capsBase = "/CAPS/" + caps.CapsObjectPath; | ||
106 | caps.RegisterHandler("ParcelVoiceInfoRequest", | ||
107 | new RestStreamHandler("POST", capsBase + m_parcelVoiceInfoRequestPath, | ||
108 | delegate(string request, string path, string param, | ||
109 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
110 | { | ||
111 | return ParcelVoiceInfoRequest(request, path, param, | ||
112 | agentID, caps); | ||
113 | })); | ||
114 | caps.RegisterHandler("ProvisionVoiceAccountRequest", | ||
115 | new RestStreamHandler("POST", capsBase + m_provisionVoiceAccountRequestPath, | ||
116 | delegate(string request, string path, string param, | ||
117 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
118 | { | ||
119 | return ProvisionVoiceAccountRequest(request, path, param, | ||
120 | agentID, caps); | ||
121 | })); | ||
122 | caps.RegisterHandler("ChatSessionRequest", | ||
123 | new RestStreamHandler("POST", capsBase + m_chatSessionRequestPath, | ||
124 | delegate(string request, string path, string param, | ||
125 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
126 | { | ||
127 | return ChatSessionRequest(request, path, param, | ||
128 | agentID, caps); | ||
129 | })); | ||
130 | |||
131 | } | ||
132 | |||
133 | /// <summary> | ||
134 | /// Callback for a client request for ParcelVoiceInfo | ||
135 | /// </summary> | ||
136 | /// <param name="request"></param> | ||
137 | /// <param name="path"></param> | ||
138 | /// <param name="param"></param> | ||
139 | /// <param name="agentID"></param> | ||
140 | /// <param name="caps"></param> | ||
141 | /// <returns></returns> | ||
142 | public string ParcelVoiceInfoRequest(string request, string path, string param, | ||
143 | UUID agentID, Caps caps) | ||
144 | { | ||
145 | try | ||
146 | { | ||
147 | m_log.DebugFormat("[VOICE][PARCELVOICE]: request: {0}, path: {1}, param: {2}", request, path, param); | ||
148 | |||
149 | // FIXME: get the creds from region file or from config | ||
150 | Hashtable creds = new Hashtable(); | ||
151 | |||
152 | creds["channel_uri"] = String.Format("sip:{0}@{1}", agentID, m_sipDomain); | ||
153 | |||
154 | string regionName = m_scene.RegionInfo.RegionName; | ||
155 | ScenePresence avatar = m_scene.GetScenePresence(agentID); | ||
156 | if (null == m_scene.LandChannel) throw new Exception("land data not yet available"); | ||
157 | LandData land = m_scene.GetLandData(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); | ||
158 | |||
159 | LLSDParcelVoiceInfoResponse parcelVoiceInfo = | ||
160 | new LLSDParcelVoiceInfoResponse(regionName, land.LocalID, creds); | ||
161 | |||
162 | string r = LLSDHelpers.SerialiseLLSDReply(parcelVoiceInfo); | ||
163 | m_log.DebugFormat("[VOICE][PARCELVOICE]: {0}", r); | ||
164 | |||
165 | return r; | ||
166 | } | ||
167 | catch (Exception e) | ||
168 | { | ||
169 | m_log.ErrorFormat("[CAPS]: {0}, try again later", e.ToString()); | ||
170 | } | ||
171 | |||
172 | return null; | ||
173 | } | ||
174 | |||
175 | /// <summary> | ||
176 | /// Callback for a client request for Voice Account Details | ||
177 | /// </summary> | ||
178 | /// <param name="request"></param> | ||
179 | /// <param name="path"></param> | ||
180 | /// <param name="param"></param> | ||
181 | /// <param name="agentID"></param> | ||
182 | /// <param name="caps"></param> | ||
183 | /// <returns></returns> | ||
184 | public string ProvisionVoiceAccountRequest(string request, string path, string param, | ||
185 | UUID agentID, Caps caps) | ||
186 | { | ||
187 | try | ||
188 | { | ||
189 | m_log.DebugFormat("[VOICE][PROVISIONVOICE]: request: {0}, path: {1}, param: {2}", | ||
190 | request, path, param); | ||
191 | |||
192 | string voiceUser = "x" + Convert.ToBase64String(agentID.GetBytes()); | ||
193 | voiceUser = voiceUser.Replace('+', '-').Replace('/', '_'); | ||
194 | |||
195 | CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(agentID); | ||
196 | if (null == userInfo) throw new Exception("cannot get user details"); | ||
197 | |||
198 | LLSDVoiceAccountResponse voiceAccountResponse = | ||
199 | new LLSDVoiceAccountResponse(voiceUser, "$1$" + userInfo.UserProfile.PasswordHash); | ||
200 | string r = LLSDHelpers.SerialiseLLSDReply(voiceAccountResponse); | ||
201 | m_log.DebugFormat("[CAPS][PROVISIONVOICE]: {0}", r); | ||
202 | return r; | ||
203 | } | ||
204 | catch (Exception e) | ||
205 | { | ||
206 | m_log.ErrorFormat("[CAPS][PROVISIONVOICE]: {0}, retry later", e.Message); | ||
207 | } | ||
208 | |||
209 | return null; | ||
210 | } | ||
211 | |||
212 | /// <summary> | ||
213 | /// Callback for a client request for ParcelVoiceInfo | ||
214 | /// </summary> | ||
215 | /// <param name="scene">current scene object of the client</param> | ||
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 ChatSessionRequest(string request, string path, string param, | ||
223 | UUID agentID, Caps caps) | ||
224 | { | ||
225 | ScenePresence avatar = m_scene.GetScenePresence(agentID); | ||
226 | string avatarName = avatar.Name; | ||
227 | |||
228 | m_log.DebugFormat("[CAPS][CHATSESSION]: avatar \"{0}\": request: {1}, path: {2}, param: {3}", | ||
229 | avatarName, request, path, param); | ||
230 | return "<llsd>true</llsd>"; | ||
231 | } | ||
232 | |||
233 | } | ||
234 | } | ||