diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/ApplicationPlugins/Rest/Inventory/RestAppearanceServices.cs | 373 |
1 files changed, 190 insertions, 183 deletions
diff --git a/OpenSim/ApplicationPlugins/Rest/Inventory/RestAppearanceServices.cs b/OpenSim/ApplicationPlugins/Rest/Inventory/RestAppearanceServices.cs index b2b4aa7..b70a511 100644 --- a/OpenSim/ApplicationPlugins/Rest/Inventory/RestAppearanceServices.cs +++ b/OpenSim/ApplicationPlugins/Rest/Inventory/RestAppearanceServices.cs | |||
@@ -32,6 +32,7 @@ using OpenMetaverse; | |||
32 | using OpenSim.Framework; | 32 | using OpenSim.Framework; |
33 | using OpenSim.Framework.Servers; | 33 | using OpenSim.Framework.Servers; |
34 | using OpenSim.Framework.Servers.HttpServer; | 34 | using OpenSim.Framework.Servers.HttpServer; |
35 | using OpenSim.Services.Interfaces; | ||
35 | 36 | ||
36 | namespace OpenSim.ApplicationPlugins.Rest.Inventory | 37 | namespace OpenSim.ApplicationPlugins.Rest.Inventory |
37 | { | 38 | { |
@@ -135,152 +136,153 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
135 | 136 | ||
136 | private void DoAppearance(RequestData hdata) | 137 | private void DoAppearance(RequestData hdata) |
137 | { | 138 | { |
138 | 139 | // !!! REFACTORIMG PROBLEM. This needs rewriting for 0.7 | |
139 | AppearanceRequestData rdata = (AppearanceRequestData) hdata; | 140 | |
140 | 141 | //AppearanceRequestData rdata = (AppearanceRequestData) hdata; | |
141 | Rest.Log.DebugFormat("{0} DoAppearance ENTRY", MsgId); | 142 | |
142 | 143 | //Rest.Log.DebugFormat("{0} DoAppearance ENTRY", MsgId); | |
143 | // If we're disabled, do nothing. | 144 | |
144 | 145 | //// If we're disabled, do nothing. | |
145 | if (!enabled) | 146 | |
146 | { | 147 | //if (!enabled) |
147 | return; | 148 | //{ |
148 | } | 149 | // return; |
149 | 150 | //} | |
150 | // Now that we know this is a serious attempt to | 151 | |
151 | // access inventory data, we should find out who | 152 | //// Now that we know this is a serious attempt to |
152 | // is asking, and make sure they are authorized | 153 | //// access inventory data, we should find out who |
153 | // to do so. We need to validate the caller's | 154 | //// is asking, and make sure they are authorized |
154 | // identity before revealing anything about the | 155 | //// to do so. We need to validate the caller's |
155 | // status quo. Authenticate throws an exception | 156 | //// identity before revealing anything about the |
156 | // via Fail if no identity information is present. | 157 | //// status quo. Authenticate throws an exception |
157 | // | 158 | //// via Fail if no identity information is present. |
158 | // With the present HTTP server we can't use the | 159 | //// |
159 | // builtin authentication mechanisms because they | 160 | //// With the present HTTP server we can't use the |
160 | // would be enforced for all in-bound requests. | 161 | //// builtin authentication mechanisms because they |
161 | // Instead we look at the headers ourselves and | 162 | //// would be enforced for all in-bound requests. |
162 | // handle authentication directly. | 163 | //// Instead we look at the headers ourselves and |
163 | 164 | //// handle authentication directly. | |
164 | try | 165 | |
165 | { | 166 | //try |
166 | if (!rdata.IsAuthenticated) | 167 | //{ |
167 | { | 168 | // if (!rdata.IsAuthenticated) |
168 | rdata.Fail(Rest.HttpStatusCodeNotAuthorized,String.Format("user \"{0}\" could not be authenticated", rdata.userName)); | 169 | // { |
169 | } | 170 | // rdata.Fail(Rest.HttpStatusCodeNotAuthorized,String.Format("user \"{0}\" could not be authenticated", rdata.userName)); |
170 | } | 171 | // } |
171 | catch (RestException e) | 172 | //} |
172 | { | 173 | //catch (RestException e) |
173 | if (e.statusCode == Rest.HttpStatusCodeNotAuthorized) | 174 | //{ |
174 | { | 175 | // if (e.statusCode == Rest.HttpStatusCodeNotAuthorized) |
175 | Rest.Log.WarnFormat("{0} User not authenticated", MsgId); | 176 | // { |
176 | Rest.Log.DebugFormat("{0} Authorization header: {1}", MsgId, rdata.request.Headers.Get("Authorization")); | 177 | // Rest.Log.WarnFormat("{0} User not authenticated", MsgId); |
177 | } | 178 | // Rest.Log.DebugFormat("{0} Authorization header: {1}", MsgId, rdata.request.Headers.Get("Authorization")); |
178 | else | 179 | // } |
179 | { | 180 | // else |
180 | Rest.Log.ErrorFormat("{0} User authentication failed", MsgId); | 181 | // { |
181 | Rest.Log.DebugFormat("{0} Authorization header: {1}", MsgId, rdata.request.Headers.Get("Authorization")); | 182 | // Rest.Log.ErrorFormat("{0} User authentication failed", MsgId); |
182 | } | 183 | // Rest.Log.DebugFormat("{0} Authorization header: {1}", MsgId, rdata.request.Headers.Get("Authorization")); |
183 | throw (e); | 184 | // } |
184 | } | 185 | // throw (e); |
185 | 186 | //} | |
186 | Rest.Log.DebugFormat("{0} Authenticated {1}", MsgId, rdata.userName); | 187 | |
187 | 188 | //Rest.Log.DebugFormat("{0} Authenticated {1}", MsgId, rdata.userName); | |
188 | // We can only get here if we are authorized | 189 | |
189 | // | 190 | //// We can only get here if we are authorized |
190 | // The requestor may have specified an UUID or | 191 | //// |
191 | // a conjoined FirstName LastName string. We'll | 192 | //// The requestor may have specified an UUID or |
192 | // try both. If we fail with the first, UUID, | 193 | //// a conjoined FirstName LastName string. We'll |
193 | // attempt, we try the other. As an example, the | 194 | //// try both. If we fail with the first, UUID, |
194 | // URI for a valid inventory request might be: | 195 | //// attempt, we try the other. As an example, the |
195 | // | 196 | //// URI for a valid inventory request might be: |
196 | // http://<host>:<port>/admin/inventory/Arthur Dent | 197 | //// |
197 | // | 198 | //// http://<host>:<port>/admin/inventory/Arthur Dent |
198 | // Indicating that this is an inventory request for | 199 | //// |
199 | // an avatar named Arthur Dent. This is ALL that is | 200 | //// Indicating that this is an inventory request for |
200 | // required to designate a GET for an entire | 201 | //// an avatar named Arthur Dent. This is ALL that is |
201 | // inventory. | 202 | //// required to designate a GET for an entire |
202 | // | 203 | //// inventory. |
203 | 204 | //// | |
204 | // Do we have at least a user agent name? | 205 | |
205 | 206 | //// Do we have at least a user agent name? | |
206 | if (rdata.Parameters.Length < 1) | 207 | |
207 | { | 208 | //if (rdata.Parameters.Length < 1) |
208 | Rest.Log.WarnFormat("{0} Appearance: No user agent identifier specified", MsgId); | 209 | //{ |
209 | rdata.Fail(Rest.HttpStatusCodeBadRequest, "no user identity specified"); | 210 | // Rest.Log.WarnFormat("{0} Appearance: No user agent identifier specified", MsgId); |
210 | } | 211 | // rdata.Fail(Rest.HttpStatusCodeBadRequest, "no user identity specified"); |
211 | 212 | //} | |
212 | // The first parameter MUST be the agent identification, either an UUID | 213 | |
213 | // or a space-separated First-name Last-Name specification. We check for | 214 | //// The first parameter MUST be the agent identification, either an UUID |
214 | // an UUID first, if anyone names their character using a valid UUID | 215 | //// or a space-separated First-name Last-Name specification. We check for |
215 | // that identifies another existing avatar will cause this a problem... | 216 | //// an UUID first, if anyone names their character using a valid UUID |
216 | 217 | //// that identifies another existing avatar will cause this a problem... | |
217 | try | 218 | |
218 | { | 219 | //try |
219 | rdata.uuid = new UUID(rdata.Parameters[PARM_USERID]); | 220 | //{ |
220 | Rest.Log.DebugFormat("{0} UUID supplied", MsgId); | 221 | // rdata.uuid = new UUID(rdata.Parameters[PARM_USERID]); |
221 | rdata.userProfile = Rest.UserServices.GetUserProfile(rdata.uuid); | 222 | // Rest.Log.DebugFormat("{0} UUID supplied", MsgId); |
222 | } | 223 | // rdata.userProfile = Rest.UserServices.GetUserProfile(rdata.uuid); |
223 | catch | 224 | //} |
224 | { | 225 | //catch |
225 | string[] names = rdata.Parameters[PARM_USERID].Split(Rest.CA_SPACE); | 226 | //{ |
226 | if (names.Length == 2) | 227 | // string[] names = rdata.Parameters[PARM_USERID].Split(Rest.CA_SPACE); |
227 | { | 228 | // if (names.Length == 2) |
228 | Rest.Log.DebugFormat("{0} Agent Name supplied [2]", MsgId); | 229 | // { |
229 | rdata.userProfile = Rest.UserServices.GetUserProfile(names[0],names[1]); | 230 | // Rest.Log.DebugFormat("{0} Agent Name supplied [2]", MsgId); |
230 | } | 231 | // rdata.userProfile = Rest.UserServices.GetUserProfile(names[0],names[1]); |
231 | else | 232 | // } |
232 | { | 233 | // else |
233 | Rest.Log.WarnFormat("{0} A Valid UUID or both first and last names must be specified", MsgId); | 234 | // { |
234 | rdata.Fail(Rest.HttpStatusCodeBadRequest, "invalid user identity"); | 235 | // Rest.Log.WarnFormat("{0} A Valid UUID or both first and last names must be specified", MsgId); |
235 | } | 236 | // rdata.Fail(Rest.HttpStatusCodeBadRequest, "invalid user identity"); |
236 | } | 237 | // } |
237 | 238 | //} | |
238 | // If the user profile is null then either the server is broken, or the | 239 | |
239 | // user is not known. We always assume the latter case. | 240 | //// If the user profile is null then either the server is broken, or the |
240 | 241 | //// user is not known. We always assume the latter case. | |
241 | if (rdata.userProfile != null) | 242 | |
242 | { | 243 | //if (rdata.userProfile != null) |
243 | Rest.Log.DebugFormat("{0} User profile obtained for agent {1} {2}", | 244 | //{ |
244 | MsgId, rdata.userProfile.FirstName, rdata.userProfile.SurName); | 245 | // Rest.Log.DebugFormat("{0} User profile obtained for agent {1} {2}", |
245 | } | 246 | // MsgId, rdata.userProfile.FirstName, rdata.userProfile.SurName); |
246 | else | 247 | //} |
247 | { | 248 | //else |
248 | Rest.Log.WarnFormat("{0} No user profile for {1}", MsgId, rdata.path); | 249 | //{ |
249 | rdata.Fail(Rest.HttpStatusCodeNotFound, "unrecognized user identity"); | 250 | // Rest.Log.WarnFormat("{0} No user profile for {1}", MsgId, rdata.path); |
250 | } | 251 | // rdata.Fail(Rest.HttpStatusCodeNotFound, "unrecognized user identity"); |
251 | 252 | //} | |
252 | // If we get to here, then we have effectively validated the user's | 253 | |
253 | 254 | //// If we get to here, then we have effectively validated the user's | |
254 | switch (rdata.method) | 255 | |
255 | { | 256 | //switch (rdata.method) |
256 | case Rest.HEAD : // Do the processing, set the status code, suppress entity | 257 | //{ |
257 | DoGet(rdata); | 258 | // case Rest.HEAD : // Do the processing, set the status code, suppress entity |
258 | rdata.buffer = null; | 259 | // DoGet(rdata); |
259 | break; | 260 | // rdata.buffer = null; |
260 | 261 | // break; | |
261 | case Rest.GET : // Do the processing, set the status code, return entity | 262 | |
262 | DoGet(rdata); | 263 | // case Rest.GET : // Do the processing, set the status code, return entity |
263 | break; | 264 | // DoGet(rdata); |
264 | 265 | // break; | |
265 | case Rest.PUT : // Update named element | 266 | |
266 | DoUpdate(rdata); | 267 | // case Rest.PUT : // Update named element |
267 | break; | 268 | // DoUpdate(rdata); |
268 | 269 | // break; | |
269 | case Rest.POST : // Add new information to identified context. | 270 | |
270 | DoExtend(rdata); | 271 | // case Rest.POST : // Add new information to identified context. |
271 | break; | 272 | // DoExtend(rdata); |
272 | 273 | // break; | |
273 | case Rest.DELETE : // Delete information | 274 | |
274 | DoDelete(rdata); | 275 | // case Rest.DELETE : // Delete information |
275 | break; | 276 | // DoDelete(rdata); |
276 | 277 | // break; | |
277 | default : | 278 | |
278 | Rest.Log.WarnFormat("{0} Method {1} not supported for {2}", | 279 | // default : |
279 | MsgId, rdata.method, rdata.path); | 280 | // Rest.Log.WarnFormat("{0} Method {1} not supported for {2}", |
280 | rdata.Fail(Rest.HttpStatusCodeMethodNotAllowed, | 281 | // MsgId, rdata.method, rdata.path); |
281 | String.Format("{0} not supported", rdata.method)); | 282 | // rdata.Fail(Rest.HttpStatusCodeMethodNotAllowed, |
282 | break; | 283 | // String.Format("{0} not supported", rdata.method)); |
283 | } | 284 | // break; |
285 | //} | ||
284 | } | 286 | } |
285 | 287 | ||
286 | #endregion Interface | 288 | #endregion Interface |
@@ -294,15 +296,15 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
294 | 296 | ||
295 | private void DoGet(AppearanceRequestData rdata) | 297 | private void DoGet(AppearanceRequestData rdata) |
296 | { | 298 | { |
299 | AvatarData adata = Rest.AvatarServices.GetAvatar(rdata.userProfile.ID); | ||
297 | 300 | ||
298 | rdata.userAppearance = Rest.AvatarServices.GetUserAppearance(rdata.userProfile.ID); | 301 | if (adata == null) |
299 | |||
300 | if (rdata.userAppearance == null) | ||
301 | { | 302 | { |
302 | rdata.Fail(Rest.HttpStatusCodeNoContent, | 303 | rdata.Fail(Rest.HttpStatusCodeNoContent, |
303 | String.Format("appearance data not found for user {0} {1}", | 304 | String.Format("appearance data not found for user {0} {1}", |
304 | rdata.userProfile.FirstName, rdata.userProfile.SurName)); | 305 | rdata.userProfile.FirstName, rdata.userProfile.SurName)); |
305 | } | 306 | } |
307 | rdata.userAppearance = adata.ToAvatarAppearance(rdata.userProfile.ID); | ||
306 | 308 | ||
307 | rdata.initXmlWriter(); | 309 | rdata.initXmlWriter(); |
308 | 310 | ||
@@ -341,18 +343,20 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
341 | // increasingly doubtful that it is appropriate for REST. If I attempt to | 343 | // increasingly doubtful that it is appropriate for REST. If I attempt to |
342 | // add a new record, and it already exists, then it seems to me that the | 344 | // add a new record, and it already exists, then it seems to me that the |
343 | // attempt should fail, rather than update the existing record. | 345 | // attempt should fail, rather than update the existing record. |
344 | 346 | AvatarData adata = null; | |
345 | if (GetUserAppearance(rdata)) | 347 | if (GetUserAppearance(rdata)) |
346 | { | 348 | { |
347 | modified = rdata.userAppearance != null; | 349 | modified = rdata.userAppearance != null; |
348 | created = !modified; | 350 | created = !modified; |
349 | Rest.AvatarServices.UpdateUserAppearance(rdata.userProfile.ID, rdata.userAppearance); | 351 | adata = new AvatarData(rdata.userAppearance); |
352 | Rest.AvatarServices.SetAvatar(rdata.userProfile.ID, adata); | ||
350 | // Rest.UserServices.UpdateUserProfile(rdata.userProfile); | 353 | // Rest.UserServices.UpdateUserProfile(rdata.userProfile); |
351 | } | 354 | } |
352 | else | 355 | else |
353 | { | 356 | { |
354 | created = true; | 357 | created = true; |
355 | Rest.AvatarServices.UpdateUserAppearance(rdata.userProfile.ID, rdata.userAppearance); | 358 | adata = new AvatarData(rdata.userAppearance); |
359 | Rest.AvatarServices.SetAvatar(rdata.userProfile.ID, adata); | ||
356 | // Rest.UserServices.UpdateUserProfile(rdata.userProfile); | 360 | // Rest.UserServices.UpdateUserProfile(rdata.userProfile); |
357 | } | 361 | } |
358 | 362 | ||
@@ -391,37 +395,39 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
391 | private void DoUpdate(AppearanceRequestData rdata) | 395 | private void DoUpdate(AppearanceRequestData rdata) |
392 | { | 396 | { |
393 | 397 | ||
394 | bool created = false; | 398 | // REFACTORING PROBLEM This was commented out. It doesn't work for 0.7 |
395 | bool modified = false; | ||
396 | 399 | ||
400 | //bool created = false; | ||
401 | //bool modified = false; | ||
397 | 402 | ||
398 | rdata.userAppearance = Rest.AvatarServices.GetUserAppearance(rdata.userProfile.ID); | ||
399 | 403 | ||
400 | // If the user exists then this is considered a modification regardless | 404 | //rdata.userAppearance = Rest.AvatarServices.GetUserAppearance(rdata.userProfile.ID); |
401 | // of what may, or may not be, specified in the payload. | ||
402 | 405 | ||
403 | if (rdata.userAppearance != null) | 406 | //// If the user exists then this is considered a modification regardless |
404 | { | 407 | //// of what may, or may not be, specified in the payload. |
405 | modified = true; | ||
406 | Rest.AvatarServices.UpdateUserAppearance(rdata.userProfile.ID, rdata.userAppearance); | ||
407 | Rest.UserServices.UpdateUserProfile(rdata.userProfile); | ||
408 | } | ||
409 | 408 | ||
410 | if (created) | 409 | //if (rdata.userAppearance != null) |
411 | { | 410 | //{ |
412 | rdata.Complete(Rest.HttpStatusCodeCreated); | 411 | // modified = true; |
413 | } | 412 | // Rest.AvatarServices.UpdateUserAppearance(rdata.userProfile.ID, rdata.userAppearance); |
414 | else | 413 | // Rest.UserServices.UpdateUserProfile(rdata.userProfile); |
415 | { | 414 | //} |
416 | if (modified) | 415 | |
417 | { | 416 | //if (created) |
418 | rdata.Complete(Rest.HttpStatusCodeOK); | 417 | //{ |
419 | } | 418 | // rdata.Complete(Rest.HttpStatusCodeCreated); |
420 | else | 419 | //} |
421 | { | 420 | //else |
422 | rdata.Complete(Rest.HttpStatusCodeNoContent); | 421 | //{ |
423 | } | 422 | // if (modified) |
424 | } | 423 | // { |
424 | // rdata.Complete(Rest.HttpStatusCodeOK); | ||
425 | // } | ||
426 | // else | ||
427 | // { | ||
428 | // rdata.Complete(Rest.HttpStatusCodeNoContent); | ||
429 | // } | ||
430 | //} | ||
425 | 431 | ||
426 | rdata.Respond(String.Format("Appearance {0} : Normal completion", rdata.method)); | 432 | rdata.Respond(String.Format("Appearance {0} : Normal completion", rdata.method)); |
427 | 433 | ||
@@ -436,21 +442,22 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory | |||
436 | 442 | ||
437 | private void DoDelete(AppearanceRequestData rdata) | 443 | private void DoDelete(AppearanceRequestData rdata) |
438 | { | 444 | { |
445 | AvatarData adata = Rest.AvatarServices.GetAvatar(rdata.userProfile.ID); | ||
439 | 446 | ||
440 | AvatarAppearance old = Rest.AvatarServices.GetUserAppearance(rdata.userProfile.ID); | 447 | if (adata != null) |
441 | |||
442 | if (old != null) | ||
443 | { | 448 | { |
449 | AvatarAppearance old = adata.ToAvatarAppearance(rdata.userProfile.ID); | ||
444 | rdata.userAppearance = new AvatarAppearance(); | 450 | rdata.userAppearance = new AvatarAppearance(); |
445 | |||
446 | rdata.userAppearance.Owner = old.Owner; | 451 | rdata.userAppearance.Owner = old.Owner; |
452 | adata = new AvatarData(rdata.userAppearance); | ||
447 | 453 | ||
448 | Rest.AvatarServices.UpdateUserAppearance(rdata.userProfile.ID, rdata.userAppearance); | 454 | Rest.AvatarServices.SetAvatar(rdata.userProfile.ID, adata); |
449 | 455 | ||
450 | rdata.Complete(); | 456 | rdata.Complete(); |
451 | } | 457 | } |
452 | else | 458 | else |
453 | { | 459 | { |
460 | |||
454 | rdata.Complete(Rest.HttpStatusCodeNoContent); | 461 | rdata.Complete(Rest.HttpStatusCodeNoContent); |
455 | } | 462 | } |
456 | 463 | ||