aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs192
1 files changed, 19 insertions, 173 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs
index d949d70..015e2d0 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,7 +606,7 @@ 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);
@@ -711,7 +714,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
711 pick.Enabled = enabled; 714 pick.Enabled = enabled;
712 715
713 object Pick = (object)pick; 716 object Pick = (object)pick;
714 if(!JsonRpcRequest(ref Pick, "picks_update", serverURI, UUID.Random().ToString())) 717 if(!rpc.JsonRpcRequest(ref Pick, "picks_update", serverURI, UUID.Random().ToString()))
715 { 718 {
716 remoteClient.SendAgentAlertMessage( 719 remoteClient.SendAgentAlertMessage(
717 "Error updating pick", false); 720 "Error updating pick", false);
@@ -737,7 +740,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
737 OSDMap parameters= new OSDMap(); 740 OSDMap parameters= new OSDMap();
738 parameters.Add("pickId", OSD.FromUUID(queryPickID)); 741 parameters.Add("pickId", OSD.FromUUID(queryPickID));
739 OSD Params = (OSD)parameters; 742 OSD Params = (OSD)parameters;
740 if(!JsonRpcRequest(ref Params, "picks_delete", serverURI, UUID.Random().ToString())) 743 if(!rpc.JsonRpcRequest(ref Params, "picks_delete", serverURI, UUID.Random().ToString()))
741 { 744 {
742 remoteClient.SendAgentAlertMessage( 745 remoteClient.SendAgentAlertMessage(
743 "Error picks delete", false); 746 "Error picks delete", false);
@@ -772,7 +775,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
772 UUID.TryParse(args[0], out note.TargetId); 775 UUID.TryParse(args[0], out note.TargetId);
773 776
774 object Note = (object)note; 777 object Note = (object)note;
775 if(!JsonRpcRequest(ref Note, "avatarnotesrequest", serverURI, UUID.Random().ToString())) 778 if(!rpc.JsonRpcRequest(ref Note, "avatarnotesrequest", serverURI, UUID.Random().ToString()))
776 { 779 {
777 remoteClient.SendAvatarNotesReply(note.TargetId, note.Notes); 780 remoteClient.SendAvatarNotesReply(note.TargetId, note.Notes);
778 return; 781 return;
@@ -806,7 +809,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
806 GetUserProfileServerURI(remoteClient.AgentId, out serverURI); 809 GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
807 810
808 object Note = note; 811 object Note = note;
809 if(!JsonRpcRequest(ref Note, "avatar_notes_update", serverURI, UUID.Random().ToString())) 812 if(!rpc.JsonRpcRequest(ref Note, "avatar_notes_update", serverURI, UUID.Random().ToString()))
810 { 813 {
811 return; 814 return;
812 } 815 }
@@ -838,7 +841,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
838 bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI); 841 bool foreign = GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
839 842
840 object Pref = pref; 843 object Pref = pref;
841 if(!JsonRpcRequest(ref Pref, "user_preferences_update", serverURI, UUID.Random().ToString())) 844 if(!rpc.JsonRpcRequest(ref Pref, "user_preferences_update", serverURI, UUID.Random().ToString()))
842 { 845 {
843 m_log.InfoFormat("[PROFILES]: UserPreferences update error"); 846 m_log.InfoFormat("[PROFILES]: UserPreferences update error");
844 remoteClient.SendAgentAlertMessage("Error updating preferences", false); 847 remoteClient.SendAgentAlertMessage("Error updating preferences", false);
@@ -863,7 +866,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
863 866
864 867
865 object Pref = (object)pref; 868 object Pref = (object)pref;
866 if(!JsonRpcRequest(ref Pref, "user_preferences_request", serverURI, UUID.Random().ToString())) 869 if(!rpc.JsonRpcRequest(ref Pref, "user_preferences_request", serverURI, UUID.Random().ToString()))
867 { 870 {
868 m_log.InfoFormat("[PROFILES]: UserPreferences request error"); 871 m_log.InfoFormat("[PROFILES]: UserPreferences request error");
869 remoteClient.SendAgentAlertMessage("Error requesting preferences", false); 872 remoteClient.SendAgentAlertMessage("Error requesting preferences", false);
@@ -913,7 +916,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
913 GetUserProfileServerURI(remoteClient.AgentId, out serverURI); 916 GetUserProfileServerURI(remoteClient.AgentId, out serverURI);
914 917
915 object Param = prop; 918 object Param = prop;
916 if(!JsonRpcRequest(ref Param, "avatar_interests_update", serverURI, UUID.Random().ToString())) 919 if(!rpc.JsonRpcRequest(ref Param, "avatar_interests_update", serverURI, UUID.Random().ToString()))
917 { 920 {
918 remoteClient.SendAgentAlertMessage( 921 remoteClient.SendAgentAlertMessage(
919 "Error updating interests", false); 922 "Error updating interests", false);
@@ -1060,7 +1063,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1060 1063
1061 object Prop = prop; 1064 object Prop = prop;
1062 1065
1063 if(!JsonRpcRequest(ref Prop, "avatar_properties_update", serverURI, UUID.Random().ToString())) 1066 if(!rpc.JsonRpcRequest(ref Prop, "avatar_properties_update", serverURI, UUID.Random().ToString()))
1064 { 1067 {
1065 remoteClient.SendAgentAlertMessage( 1068 remoteClient.SendAgentAlertMessage(
1066 "Error updating properties", false); 1069 "Error updating properties", false);
@@ -1105,7 +1108,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1105 } 1108 }
1106 1109
1107 object Prop = (object)properties; 1110 object Prop = (object)properties;
1108 JsonRpcRequest(ref Prop, "avatar_properties_request", serverURI, UUID.Random().ToString()); 1111 rpc.JsonRpcRequest(ref Prop, "avatar_properties_request", serverURI, UUID.Random().ToString());
1109 properties = (UserProfileProperties)Prop; 1112 properties = (UserProfileProperties)Prop;
1110 1113
1111 message = "Success"; 1114 message = "Success";
@@ -1129,7 +1132,7 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1129 OSDMap parameters= new OSDMap(); 1132 OSDMap parameters= new OSDMap();
1130 parameters.Add("avatarId", OSD.FromUUID(avatarId)); 1133 parameters.Add("avatarId", OSD.FromUUID(avatarId));
1131 OSD Params = (OSD)parameters; 1134 OSD Params = (OSD)parameters;
1132 if(!JsonRpcRequest(ref Params, "image_assets_request", profileServerURI, UUID.Random().ToString())) 1135 if(!rpc.JsonRpcRequest(ref Params, "image_assets_request", profileServerURI, UUID.Random().ToString()))
1133 { 1136 {
1134 return false; 1137 return false;
1135 } 1138 }
@@ -1285,162 +1288,5 @@ namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
1285 return null; 1288 return null;
1286 } 1289 }
1287 #endregion Util 1290 #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 } 1291 }
1446} 1292}