aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services
diff options
context:
space:
mode:
authorOren Hurvitz2014-03-02 14:43:43 +0200
committerOren Hurvitz2014-04-24 15:58:42 +0100
commitd62f0bc35d966ca4099e43026b90ab24cd768e4b (patch)
treee5702bd71908f959298db8b23f327b3fc89187da /OpenSim/Services
parentWhen sending JSON-RPC calls (for UserProfile), use WebUtil instead of constru... (diff)
downloadopensim-SC_OLD-d62f0bc35d966ca4099e43026b90ab24cd768e4b.zip
opensim-SC_OLD-d62f0bc35d966ca4099e43026b90ab24cd768e4b.tar.gz
opensim-SC_OLD-d62f0bc35d966ca4099e43026b90ab24cd768e4b.tar.bz2
opensim-SC_OLD-d62f0bc35d966ca4099e43026b90ab24cd768e4b.tar.xz
Refactored: moved OpenProfileClient to a location where it can be used by both the Simulators and Robust
Diffstat (limited to 'OpenSim/Services')
-rw-r--r--OpenSim/Services/Interfaces/OpenProfileClient.cs193
1 files changed, 193 insertions, 0 deletions
diff --git a/OpenSim/Services/Interfaces/OpenProfileClient.cs b/OpenSim/Services/Interfaces/OpenProfileClient.cs
new file mode 100644
index 0000000..099b0c3
--- /dev/null
+++ b/OpenSim/Services/Interfaces/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.Services.UserProfilesService
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}