aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/Servers/HttpServer/JsonRpcRequestManager.cs211
-rw-r--r--OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs198
2 files changed, 230 insertions, 179 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/JsonRpcRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/JsonRpcRequestManager.cs
new file mode 100644
index 0000000..a44f471
--- /dev/null
+++ b/OpenSim/Framework/Servers/HttpServer/JsonRpcRequestManager.cs
@@ -0,0 +1,211 @@
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 OpenSimulator 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.Net;
30using System.Net.Sockets;
31using System.Reflection;
32using System.Text;
33using System.IO;
34using OpenMetaverse.StructuredData;
35using OpenMetaverse;
36using log4net;
37
38namespace OpenSim.Framework.Servers.HttpServer
39{
40 /// <summary>
41 /// Json rpc request manager.
42 /// </summary>
43 public class JsonRpcRequestManager
44 {
45 static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46
47 public JsonRpcRequestManager()
48 {
49 }
50
51 #region Web Util
52 /// <summary>
53 /// Sends json-rpc request with a serializable type.
54 /// </summary>
55 /// <returns>
56 /// OSD Map.
57 /// </returns>
58 /// <param name='parameters'>
59 /// Serializable type .
60 /// </param>
61 /// <param name='method'>
62 /// Json-rpc method to call.
63 /// </param>
64 /// <param name='uri'>
65 /// URI of json-rpc service.
66 /// </param>
67 /// <param name='jsonId'>
68 /// Id for our call.
69 /// </param>
70 public bool JsonRpcRequest(ref object parameters, string method, string uri, string jsonId)
71 {
72 if (jsonId == null)
73 throw new ArgumentNullException ("jsonId");
74 if (uri == null)
75 throw new ArgumentNullException ("uri");
76 if (method == null)
77 throw new ArgumentNullException ("method");
78 if (parameters == null)
79 throw new ArgumentNullException ("parameters");
80
81 // Prep our payload
82 OSDMap json = new OSDMap();
83
84 json.Add("jsonrpc", OSD.FromString("2.0"));
85 json.Add("id", OSD.FromString(jsonId));
86 json.Add("method", OSD.FromString(method));
87
88 json.Add("params", OSD.SerializeMembers(parameters));
89
90 string jsonRequestData = OSDParser.SerializeJsonString(json);
91 byte[] content = Encoding.UTF8.GetBytes(jsonRequestData);
92
93 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
94
95 webRequest.ContentType = "application/json-rpc";
96 webRequest.Method = "POST";
97
98 //Stream dataStream = webRequest.GetRequestStream();
99 //dataStream.Write(content, 0, content.Length);
100 //dataStream.Close();
101
102 using (Stream dataStream = webRequest.GetRequestStream())
103 dataStream.Write(content, 0, content.Length);
104
105 WebResponse webResponse = null;
106 try
107 {
108 webResponse = webRequest.GetResponse();
109 }
110 catch (WebException e)
111 {
112 Console.WriteLine("Web Error" + e.Message);
113 Console.WriteLine ("Please check input");
114 return false;
115 }
116
117 using (webResponse)
118 using (Stream rstream = webResponse.GetResponseStream())
119 {
120 OSDMap mret = (OSDMap)OSDParser.DeserializeJson(rstream);
121
122 if (mret.ContainsKey("error"))
123 return false;
124
125 // get params...
126 OSD.DeserializeMembers(ref parameters, (OSDMap)mret["result"]);
127 return true;
128 }
129 }
130
131 /// <summary>
132 /// Sends json-rpc request with OSD parameter.
133 /// </summary>
134 /// <returns>
135 /// The rpc request.
136 /// </returns>
137 /// <param name='data'>
138 /// data - incoming as parameters, outgong as result/error
139 /// </param>
140 /// <param name='method'>
141 /// Json-rpc method to call.
142 /// </param>
143 /// <param name='uri'>
144 /// URI of json-rpc service.
145 /// </param>
146 /// <param name='jsonId'>
147 /// If set to <c>true</c> json identifier.
148 /// </param>
149 public bool JsonRpcRequest(ref OSD data, string method, string uri, string jsonId)
150 {
151 OSDMap map = new OSDMap();
152
153 map["jsonrpc"] = "2.0";
154 if(string.IsNullOrEmpty(jsonId))
155 map["id"] = UUID.Random().ToString();
156 else
157 map["id"] = jsonId;
158
159 map["method"] = method;
160 map["params"] = data;
161
162 string jsonRequestData = OSDParser.SerializeJsonString(map);
163 byte[] content = Encoding.UTF8.GetBytes(jsonRequestData);
164
165 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
166 webRequest.ContentType = "application/json-rpc";
167 webRequest.Method = "POST";
168
169 using (Stream dataStream = webRequest.GetRequestStream())
170 dataStream.Write(content, 0, content.Length);
171
172 WebResponse webResponse = null;
173 try
174 {
175 webResponse = webRequest.GetResponse();
176 }
177 catch (WebException e)
178 {
179 Console.WriteLine("Web Error" + e.Message);
180 Console.WriteLine ("Please check input");
181 return false;
182 }
183
184 using (webResponse)
185 using (Stream rstream = webResponse.GetResponseStream())
186 {
187 OSDMap response = new OSDMap();
188 try
189 {
190 response = (OSDMap)OSDParser.DeserializeJson(rstream);
191 }
192 catch (Exception e)
193 {
194 m_log.DebugFormat("[JSONRPC]: JsonRpcRequest Error {0}", e.Message);
195 return false;
196 }
197
198 if (response.ContainsKey("error"))
199 {
200 data = response["error"];
201 return false;
202 }
203
204 data = response;
205
206 return true;
207 }
208 }
209 #endregion Web Util
210 }
211}
diff --git a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs
index d949d70..b15dcf8 100644
--- a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs
@@ -46,6 +46,7 @@ using OpenSim.Region.Framework.Scenes;
46using OpenSim.Services.Interfaces; 46using OpenSim.Services.Interfaces;
47using Mono.Addins; 47using Mono.Addins;
48using OpenSim.Services.Connectors.Hypergrid; 48using OpenSim.Services.Connectors.Hypergrid;
49using OpenSim.Framework.Servers.HttpServer;
49 50
50namespace OpenSim.Region.CoreModules.Avatar.UserProfiles 51namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
51{ 52{
@@ -112,6 +113,8 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
112 set; 113 set;
113 } 114 }
114 115
116 JsonRpcRequestManager rpc = new JsonRpcRequestManager();
117
115 #region IRegionModuleBase implementation 118 #region IRegionModuleBase implementation
116 /// <summary> 119 /// <summary>
117 /// This is called to initialize the region module. For shared modules, this is called exactly once, after 120 /// This is called to initialize the region module. For shared modules, this is called exactly once, after
@@ -319,7 +322,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
319 UUID.TryParse(args[0], out creatorId); 322 UUID.TryParse(args[0], out creatorId);
320 parameters.Add("creatorId", OSD.FromUUID(creatorId)); 323 parameters.Add("creatorId", OSD.FromUUID(creatorId));
321 OSD Params = (OSD)parameters; 324 OSD Params = (OSD)parameters;
322 if(!JsonRpcRequest(ref Params, "avatarclassifiedsrequest", serverURI, UUID.Random().ToString())) 325 if(!rpc.JsonRpcRequest(ref Params, "avatarclassifiedsrequest", serverURI, UUID.Random().ToString()))
323 { 326 {
324 remoteClient.SendAvatarClassifiedReply(new UUID(args[0]), classifieds); 327 remoteClient.SendAvatarClassifiedReply(new UUID(args[0]), classifieds);
325 return; 328 return;
@@ -379,7 +382,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
379 GetUserProfileServerURI(target, out serverURI); 382 GetUserProfileServerURI(target, out serverURI);
380 383
381 object Ad = (object)ad; 384 object Ad = (object)ad;
382 if(!JsonRpcRequest(ref Ad, "classifieds_info_query", serverURI, UUID.Random().ToString())) 385 if(!rpc.JsonRpcRequest(ref Ad, "classifieds_info_query", serverURI, UUID.Random().ToString()))
383 { 386 {
384 remoteClient.SendAgentAlertMessage( 387 remoteClient.SendAgentAlertMessage(
385 "Error getting classified info", false); 388 "Error getting classified info", false);
@@ -475,7 +478,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
475 478
476 OSD.SerializeMembers(Ad); 479 OSD.SerializeMembers(Ad);
477 480
478 if(!JsonRpcRequest(ref Ad, "classified_update", serverURI, UUID.Random().ToString())) 481 if(!rpc.JsonRpcRequest(ref Ad, "classified_update", serverURI, UUID.Random().ToString()))
479 { 482 {
480 remoteClient.SendAgentAlertMessage( 483 remoteClient.SendAgentAlertMessage(
481 "Error updating classified", false); 484 "Error updating classified", false);
@@ -501,7 +504,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
501 UUID.TryParse(queryClassifiedID.ToString(), out classifiedId); 504 UUID.TryParse(queryClassifiedID.ToString(), out classifiedId);
502 parameters.Add("classifiedId", OSD.FromUUID(classifiedId)); 505 parameters.Add("classifiedId", OSD.FromUUID(classifiedId));
503 OSD Params = (OSD)parameters; 506 OSD Params = (OSD)parameters;
504 if(!JsonRpcRequest(ref Params, "classified_delete", serverURI, UUID.Random().ToString())) 507 if(!rpc.JsonRpcRequest(ref Params, "classified_delete", serverURI, UUID.Random().ToString()))
505 { 508 {
506 remoteClient.SendAgentAlertMessage( 509 remoteClient.SendAgentAlertMessage(
507 "Error classified delete", false); 510 "Error classified delete", false);
@@ -551,7 +554,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
551 OSDMap parameters= new OSDMap(); 554 OSDMap parameters= new OSDMap();
552 parameters.Add("creatorId", OSD.FromUUID(targetId)); 555 parameters.Add("creatorId", OSD.FromUUID(targetId));
553 OSD Params = (OSD)parameters; 556 OSD Params = (OSD)parameters;
554 if(!JsonRpcRequest(ref Params, "avatarpicksrequest", serverURI, UUID.Random().ToString())) 557 if(!rpc.JsonRpcRequest(ref Params, "avatarpicksrequest", serverURI, UUID.Random().ToString()))
555 { 558 {
556 remoteClient.SendAvatarPicksReply(new UUID(args[0]), picks); 559 remoteClient.SendAvatarPicksReply(new UUID(args[0]), picks);
557 return; 560 return;
@@ -603,18 +606,12 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
603 606
604 607
605 object Pick = (object)pick; 608 object Pick = (object)pick;
606 if(!JsonRpcRequest(ref Pick, "pickinforequest", serverURI, UUID.Random().ToString())) 609 if(!rpc.JsonRpcRequest(ref Pick, "pickinforequest", serverURI, UUID.Random().ToString()))
607 { 610 {
608 remoteClient.SendAgentAlertMessage( 611 remoteClient.SendAgentAlertMessage(
609 "Error selecting pick", false); 612 "Error selecting pick", false);
610 } 613 }
611 pick = (UserProfilePick) Pick; 614 pick = (UserProfilePick) Pick;
612 if(pick.SnapshotId == UUID.Zero)
613 {
614 // In case of a new UserPick, the data may not be ready and we would send wrong data, skip it...
615 m_log.DebugFormat("[PROFILES]: PickInfoRequest: SnapshotID is {0}", UUID.Zero.ToString());
616 return;
617 }
618 615
619 Vector3 globalPos; 616 Vector3 globalPos;
620 Vector3.TryParse(pick.GlobalPos,out globalPos); 617 Vector3.TryParse(pick.GlobalPos,out globalPos);
@@ -711,7 +708,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
711 pick.Enabled = enabled; 708 pick.Enabled = enabled;
712 709
713 object Pick = (object)pick; 710 object Pick = (object)pick;
714 if(!JsonRpcRequest(ref Pick, "picks_update", serverURI, UUID.Random().ToString())) 711 if(!rpc.JsonRpcRequest(ref Pick, "picks_update", serverURI, UUID.Random().ToString()))
715 { 712 {
716 remoteClient.SendAgentAlertMessage( 713 remoteClient.SendAgentAlertMessage(
717 "Error updating pick", false); 714 "Error updating pick", false);
@@ -737,7 +734,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
737 OSDMap parameters= new OSDMap(); 734 OSDMap parameters= new OSDMap();
738 parameters.Add("pickId", OSD.FromUUID(queryPickID)); 735 parameters.Add("pickId", OSD.FromUUID(queryPickID));
739 OSD Params = (OSD)parameters; 736 OSD Params = (OSD)parameters;
740 if(!JsonRpcRequest(ref Params, "picks_delete", serverURI, UUID.Random().ToString())) 737 if(!rpc.JsonRpcRequest(ref Params, "picks_delete", serverURI, UUID.Random().ToString()))
741 { 738 {
742 remoteClient.SendAgentAlertMessage( 739 remoteClient.SendAgentAlertMessage(
743 "Error picks delete", false); 740 "Error picks delete", false);
@@ -772,7 +769,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
772 UUID.TryParse(args[0], out note.TargetId); 769 UUID.TryParse(args[0], out note.TargetId);
773 770
774 object Note = (object)note; 771 object Note = (object)note;
775 if(!JsonRpcRequest(ref Note, "avatarnotesrequest", serverURI, UUID.Random().ToString())) 772 if(!rpc.JsonRpcRequest(ref Note, "avatarnotesrequest", serverURI, UUID.Random().ToString()))
776 { 773 {
777 remoteClient.SendAvatarNotesReply(note.TargetId, note.Notes); 774 remoteClient.SendAvatarNotesReply(note.TargetId, note.Notes);
778 return; 775 return;
@@ -806,7 +803,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
806 GetUserProfileServerURI(remoteClient.AgentId, out serverURI); 803 GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
807 804
808 object Note = note; 805 object Note = note;
809 if(!JsonRpcRequest(ref Note, "avatar_notes_update", serverURI, UUID.Random().ToString())) 806 if(!rpc.JsonRpcRequest(ref Note, "avatar_notes_update", serverURI, UUID.Random().ToString()))
810 { 807 {
811 return; 808 return;
812 } 809 }
@@ -838,7 +835,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
838 bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI); 835 bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
839 836
840 object Pref = pref; 837 object Pref = pref;
841 if(!JsonRpcRequest(ref Pref, "user_preferences_update", serverURI, UUID.Random().ToString())) 838 if(!rpc.JsonRpcRequest(ref Pref, "user_preferences_update", serverURI, UUID.Random().ToString()))
842 { 839 {
843 m_log.InfoFormat("[PROFILES]: UserPreferences update error"); 840 m_log.InfoFormat("[PROFILES]: UserPreferences update error");
844 remoteClient.SendAgentAlertMessage("Error updating preferences", false); 841 remoteClient.SendAgentAlertMessage("Error updating preferences", false);
@@ -863,7 +860,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
863 860
864 861
865 object Pref = (object)pref; 862 object Pref = (object)pref;
866 if(!JsonRpcRequest(ref Pref, "user_preferences_request", serverURI, UUID.Random().ToString())) 863 if(!rpc.JsonRpcRequest(ref Pref, "user_preferences_request", serverURI, UUID.Random().ToString()))
867 { 864 {
868 m_log.InfoFormat("[PROFILES]: UserPreferences request error"); 865 m_log.InfoFormat("[PROFILES]: UserPreferences request error");
869 remoteClient.SendAgentAlertMessage("Error requesting preferences", false); 866 remoteClient.SendAgentAlertMessage("Error requesting preferences", false);
@@ -913,7 +910,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
913 GetUserProfileServerURI(remoteClient.AgentId, out serverURI); 910 GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
914 911
915 object Param = prop; 912 object Param = prop;
916 if(!JsonRpcRequest(ref Param, "avatar_interests_update", serverURI, UUID.Random().ToString())) 913 if(!rpc.JsonRpcRequest(ref Param, "avatar_interests_update", serverURI, UUID.Random().ToString()))
917 { 914 {
918 remoteClient.SendAgentAlertMessage( 915 remoteClient.SendAgentAlertMessage(
919 "Error updating interests", false); 916 "Error updating interests", false);
@@ -1060,7 +1057,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1060 1057
1061 object Prop = prop; 1058 object Prop = prop;
1062 1059
1063 if(!JsonRpcRequest(ref Prop, "avatar_properties_update", serverURI, UUID.Random().ToString())) 1060 if(!rpc.JsonRpcRequest(ref Prop, "avatar_properties_update", serverURI, UUID.Random().ToString()))
1064 { 1061 {
1065 remoteClient.SendAgentAlertMessage( 1062 remoteClient.SendAgentAlertMessage(
1066 "Error updating properties", false); 1063 "Error updating properties", false);
@@ -1105,7 +1102,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1105 } 1102 }
1106 1103
1107 object Prop = (object)properties; 1104 object Prop = (object)properties;
1108 JsonRpcRequest(ref Prop, "avatar_properties_request", serverURI, UUID.Random().ToString()); 1105 rpc.JsonRpcRequest(ref Prop, "avatar_properties_request", serverURI, UUID.Random().ToString());
1109 properties = (UserProfileProperties)Prop; 1106 properties = (UserProfileProperties)Prop;
1110 1107
1111 message = "Success"; 1108 message = "Success";
@@ -1129,7 +1126,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1129 OSDMap parameters= new OSDMap(); 1126 OSDMap parameters= new OSDMap();
1130 parameters.Add("avatarId", OSD.FromUUID(avatarId)); 1127 parameters.Add("avatarId", OSD.FromUUID(avatarId));
1131 OSD Params = (OSD)parameters; 1128 OSD Params = (OSD)parameters;
1132 if(!JsonRpcRequest(ref Params, "image_assets_request", profileServerURI, UUID.Random().ToString())) 1129 if(!rpc.JsonRpcRequest(ref Params, "image_assets_request", profileServerURI, UUID.Random().ToString()))
1133 { 1130 {
1134 return false; 1131 return false;
1135 } 1132 }
@@ -1285,162 +1282,5 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1285 return null; 1282 return null;
1286 } 1283 }
1287 #endregion Util 1284 #endregion Util
1288
1289 #region Web Util
1290 /// <summary>
1291 /// Sends json-rpc request with a serializable type.
1292 /// </summary>
1293 /// <returns>
1294 /// OSD Map.
1295 /// </returns>
1296 /// <param name='parameters'>
1297 /// Serializable type .
1298 /// </param>
1299 /// <param name='method'>
1300 /// Json-rpc method to call.
1301 /// </param>
1302 /// <param name='uri'>
1303 /// URI of json-rpc service.
1304 /// </param>
1305 /// <param name='jsonId'>
1306 /// Id for our call.
1307 /// </param>
1308 bool JsonRpcRequest(ref object parameters, string method, string uri, string jsonId)
1309 {
1310 if (jsonId == null)
1311 throw new ArgumentNullException ("jsonId");
1312 if (uri == null)
1313 throw new ArgumentNullException ("uri");
1314 if (method == null)
1315 throw new ArgumentNullException ("method");
1316 if (parameters == null)
1317 throw new ArgumentNullException ("parameters");
1318
1319 // Prep our payload
1320 OSDMap json = new OSDMap();
1321
1322 json.Add("jsonrpc", OSD.FromString("2.0"));
1323 json.Add("id", OSD.FromString(jsonId));
1324 json.Add("method", OSD.FromString(method));
1325
1326 json.Add("params", OSD.SerializeMembers(parameters));
1327
1328 string jsonRequestData = OSDParser.SerializeJsonString(json);
1329 byte[] content = Encoding.UTF8.GetBytes(jsonRequestData);
1330
1331 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
1332
1333 webRequest.ContentType = "application/json-rpc";
1334 webRequest.Method = "POST";
1335
1336 using (Stream dataStream = webRequest.GetRequestStream())
1337 dataStream.Write(content, 0, content.Length);
1338
1339 WebResponse webResponse = null;
1340 try
1341 {
1342 webResponse = webRequest.GetResponse();
1343 }
1344 catch (WebException e)
1345 {
1346 Console.WriteLine("Web Error" + e.Message);
1347 Console.WriteLine ("Please check input");
1348 return false;
1349 }
1350
1351 using (webResponse)
1352 using (Stream rstream = webResponse.GetResponseStream())
1353 {
1354 OSDMap mret = (OSDMap)OSDParser.DeserializeJson(rstream);
1355
1356 if (mret.ContainsKey("error"))
1357 return false;
1358
1359 // get params...
1360 OSD.DeserializeMembers(ref parameters, (OSDMap)mret["result"]);
1361 return true;
1362 }
1363 }
1364
1365 /// <summary>
1366 /// Sends json-rpc request with OSD parameter.
1367 /// </summary>
1368 /// <returns>
1369 /// The rpc request.
1370 /// </returns>
1371 /// <param name='data'>
1372 /// data - incoming as parameters, outgong as result/error
1373 /// </param>
1374 /// <param name='method'>
1375 /// Json-rpc method to call.
1376 /// </param>
1377 /// <param name='uri'>
1378 /// URI of json-rpc service.
1379 /// </param>
1380 /// <param name='jsonId'>
1381 /// If set to <c>true</c> json identifier.
1382 /// </param>
1383 bool JsonRpcRequest(ref OSD data, string method, string uri, string jsonId)
1384 {
1385 OSDMap map = new OSDMap();
1386
1387 map["jsonrpc"] = "2.0";
1388 if(string.IsNullOrEmpty(jsonId))
1389 map["id"] = UUID.Random().ToString();
1390 else
1391 map["id"] = jsonId;
1392
1393 map["method"] = method;
1394 map["params"] = data;
1395
1396 string jsonRequestData = OSDParser.SerializeJsonString(map);
1397 byte[] content = Encoding.UTF8.GetBytes(jsonRequestData);
1398
1399 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
1400 webRequest.ContentType = "application/json-rpc";
1401 webRequest.Method = "POST";
1402
1403 using (Stream dataStream = webRequest.GetRequestStream())
1404 dataStream.Write(content, 0, content.Length);
1405
1406 WebResponse webResponse = null;
1407 try
1408 {
1409 webResponse = webRequest.GetResponse();
1410 }
1411 catch (WebException e)
1412 {
1413 Console.WriteLine("Web Error" + e.Message);
1414 Console.WriteLine ("Please check input");
1415 return false;
1416 }
1417
1418 using (webResponse)
1419 using (Stream rstream = webResponse.GetResponseStream())
1420 {
1421 OSDMap response = new OSDMap();
1422 try
1423 {
1424 response = (OSDMap)OSDParser.DeserializeJson(rstream);
1425 }
1426 catch (Exception e)
1427 {
1428 m_log.DebugFormat("[PROFILES]: JsonRpcRequest Error {0} - remote user with legacy profiles?", e.Message);
1429 return false;
1430 }
1431
1432 if (response.ContainsKey("error"))
1433 {
1434 data = response["error"];
1435 return false;
1436 }
1437
1438 data = response;
1439
1440 return true;
1441 }
1442 }
1443
1444 #endregion Web Util
1445 } 1285 }
1446} 1286}