aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorOren Hurvitz2014-01-05 18:04:55 +0200
committerOren Hurvitz2014-03-25 09:37:18 +0100
commit368b29a68006d5e4cda2e0a7663c3978725f4276 (patch)
tree9cee0b8c76cf1548734030ebec24f2e617ccf83c /OpenSim
parentAlways throw an exception if MakeRequest (used for HTTP POST) fails. (Previou... (diff)
downloadopensim-SC-368b29a68006d5e4cda2e0a7663c3978725f4276.zip
opensim-SC-368b29a68006d5e4cda2e0a7663c3978725f4276.tar.gz
opensim-SC-368b29a68006d5e4cda2e0a7663c3978725f4276.tar.bz2
opensim-SC-368b29a68006d5e4cda2e0a7663c3978725f4276.tar.xz
In Core Profiles: as a fallback, try to get profiles from foreign grids using the OpenProfile protocol
Resolves http://opensimulator.org/mantis/view.php?id=6954
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/UserProfiles/OpenProfileClient.cs193
-rw-r--r--OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs28
2 files changed, 219 insertions, 2 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/UserProfiles/OpenProfileClient.cs b/OpenSim/Region/CoreModules/Avatar/UserProfiles/OpenProfileClient.cs
new file mode 100644
index 0000000..23de3f5
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Avatar/UserProfiles/OpenProfileClient.cs
@@ -0,0 +1,193 @@
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.Collections;
30using System.Collections.Generic;
31using System.Linq;
32using System.Net;
33using System.Net.Sockets;
34using System.Reflection;
35using System.Text;
36using System.Xml;
37using log4net;
38using Nwc.XmlRpc;
39using OpenMetaverse;
40using OpenSim.Framework;
41
42namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
43{
44 /// <summary>
45 /// A client for accessing a profile server using the OpenProfile protocol.
46 /// </summary>
47 /// <remarks>
48 /// This class was adapted from the full OpenProfile class. Since it's only a client, and not a server,
49 /// it's much simpler.
50 /// </remarks>
51 public class OpenProfileClient
52 {
53 static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54
55 private string m_serverURI;
56
57 /// <summary>
58 /// Creates a client for accessing a foreign grid's profile server using the OpenProfile protocol.
59 /// </summary>
60 /// <param name="serverURI">The grid's profile server URL</param>
61 public OpenProfileClient(string serverURI)
62 {
63 m_serverURI = serverURI;
64 }
65
66
67 /// <summary>
68 /// Gets an avatar's profile using the OpenProfile protocol.
69 /// </summary>
70 /// <param name="props">On success, this will contain the avatar's profile</param>
71 /// <returns>Success/failure</returns>
72 /// <remarks>
73 /// There are two profile modules currently in use in OpenSim: the older one is OpenProfile, and the newer
74 /// one is UserProfileModule (this file). This method attempts to read an avatar's profile from a foreign
75 /// grid using the OpenProfile protocol.
76 /// </remarks>
77 public bool RequestAvatarPropertiesUsingOpenProfile(ref UserProfileProperties props)
78 {
79 Hashtable ReqHash = new Hashtable();
80 ReqHash["avatar_id"] = props.UserId.ToString();
81
82 Hashtable profileData = GenericXMLRPCRequest(ReqHash, "avatar_properties_request", m_serverURI);
83
84 ArrayList dataArray = (ArrayList)profileData["data"];
85
86 if (dataArray == null || dataArray[0] == null)
87 return false;
88 profileData = (Hashtable)dataArray[0];
89
90 props.WebUrl = string.Empty;
91 props.AboutText = String.Empty;
92 props.FirstLifeText = String.Empty;
93 props.ImageId = UUID.Zero;
94 props.FirstLifeImageId = UUID.Zero;
95 props.PartnerId = UUID.Zero;
96
97 if (profileData["ProfileUrl"] != null)
98 props.WebUrl = profileData["ProfileUrl"].ToString();
99 if (profileData["AboutText"] != null)
100 props.AboutText = profileData["AboutText"].ToString();
101 if (profileData["FirstLifeAboutText"] != null)
102 props.FirstLifeText = profileData["FirstLifeAboutText"].ToString();
103 if (profileData["Image"] != null)
104 props.ImageId = new UUID(profileData["Image"].ToString());
105 if (profileData["FirstLifeImage"] != null)
106 props.FirstLifeImageId = new UUID(profileData["FirstLifeImage"].ToString());
107 if (profileData["Partner"] != null)
108 props.PartnerId = new UUID(profileData["Partner"].ToString());
109
110 props.WantToMask = 0;
111 props.WantToText = String.Empty;
112 props.SkillsMask = 0;
113 props.SkillsText = String.Empty;
114 props.Language = String.Empty;
115
116 if (profileData["wantmask"] != null)
117 props.WantToMask = Convert.ToInt32(profileData["wantmask"].ToString());
118 if (profileData["wanttext"] != null)
119 props.WantToText = profileData["wanttext"].ToString();
120
121 if (profileData["skillsmask"] != null)
122 props.SkillsMask = Convert.ToInt32(profileData["skillsmask"].ToString());
123 if (profileData["skillstext"] != null)
124 props.SkillsText = profileData["skillstext"].ToString();
125
126 if (profileData["languages"] != null)
127 props.Language = profileData["languages"].ToString();
128
129 return true;
130 }
131
132 private Hashtable GenericXMLRPCRequest(Hashtable ReqParams, string method, string server)
133 {
134 ArrayList SendParams = new ArrayList();
135 SendParams.Add(ReqParams);
136
137 XmlRpcResponse Resp;
138 try
139 {
140 XmlRpcRequest Req = new XmlRpcRequest(method, SendParams);
141 Resp = Req.Send(server, 30000);
142 }
143 catch (WebException ex)
144 {
145 m_log.ErrorFormat("[PROFILE]: Unable to connect to Profile " +
146 "Server {0}. Exception {1}", server, ex);
147
148 Hashtable ErrorHash = new Hashtable();
149 ErrorHash["success"] = false;
150 ErrorHash["errorMessage"] = "Unable to fetch profile data at this time. ";
151 ErrorHash["errorURI"] = "";
152
153 return ErrorHash;
154 }
155 catch (SocketException ex)
156 {
157 m_log.ErrorFormat(
158 "[PROFILE]: Unable to connect to Profile Server {0}. Method {1}, params {2}. " +
159 "Exception {3}", server, method, ReqParams, ex);
160
161 Hashtable ErrorHash = new Hashtable();
162 ErrorHash["success"] = false;
163 ErrorHash["errorMessage"] = "Unable to fetch profile data at this time. ";
164 ErrorHash["errorURI"] = "";
165
166 return ErrorHash;
167 }
168 catch (XmlException ex)
169 {
170 m_log.ErrorFormat(
171 "[PROFILE]: Unable to connect to Profile Server {0}. Method {1}, params {2}. " +
172 "Exception {3}", server, method, ReqParams.ToString(), ex);
173 Hashtable ErrorHash = new Hashtable();
174 ErrorHash["success"] = false;
175 ErrorHash["errorMessage"] = "Unable to fetch profile data at this time. ";
176 ErrorHash["errorURI"] = "";
177
178 return ErrorHash;
179 }
180 if (Resp.IsFault)
181 {
182 Hashtable ErrorHash = new Hashtable();
183 ErrorHash["success"] = false;
184 ErrorHash["errorMessage"] = "Unable to fetch profile data at this time. ";
185 ErrorHash["errorURI"] = "";
186 return ErrorHash;
187 }
188 Hashtable RespData = (Hashtable)Resp.Value;
189
190 return RespData;
191 }
192 }
193}
diff --git a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs
index bb2a258..d949d70 100644
--- a/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/UserProfiles/UserProfileModule.cs
@@ -47,7 +47,7 @@ using OpenSim.Services.Interfaces;
47using Mono.Addins; 47using Mono.Addins;
48using OpenSim.Services.Connectors.Hypergrid; 48using OpenSim.Services.Connectors.Hypergrid;
49 49
50namespace OpenSim.Region.OptionalModules.Avatar.UserProfiles 50namespace OpenSim.Region.CoreModules.Avatar.UserProfiles
51{ 51{
52 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "UserProfilesModule")] 52 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "UserProfilesModule")]
53 public class UserProfileModule : IProfileModule, INonSharedRegionModule 53 public class UserProfileModule : IProfileModule, INonSharedRegionModule
@@ -999,7 +999,31 @@ namespace OpenSim.Region.OptionalModules.Avatar.UserProfiles
999 string result = string.Empty; 999 string result = string.Empty;
1000 1000
1001 props.UserId = avatarID; 1001 props.UserId = avatarID;
1002 GetProfileData(ref props, out result); 1002
1003 try
1004 {
1005 GetProfileData(ref props, out result);
1006 }
1007 catch (Exception e)
1008 {
1009 if (foreign)
1010 {
1011 // Check if the foreign grid is using OpenProfile.
1012 // If any error occurs then discard it, and report the original error.
1013 try
1014 {
1015 OpenProfileClient client = new OpenProfileClient(serverURI);
1016 if (!client.RequestAvatarPropertiesUsingOpenProfile(ref props))
1017 throw e;
1018 }
1019 catch (Exception)
1020 {
1021 throw e;
1022 }
1023 }
1024 else
1025 throw;
1026 }
1003 1027
1004 remoteClient.SendAvatarProperties(props.UserId, props.AboutText, born, charterMember , props.FirstLifeText, flags, 1028 remoteClient.SendAvatarProperties(props.UserId, props.AboutText, born, charterMember , props.FirstLifeText, flags,
1005 props.FirstLifeImageId, props.ImageId, props.WebUrl, props.PartnerId); 1029 props.FirstLifeImageId, props.ImageId, props.WebUrl, props.PartnerId);