diff options
Diffstat (limited to 'OpenSim/Capabilities/Handlers/GetDisplayNames/GetDisplayNamesHandler.cs')
-rw-r--r-- | OpenSim/Capabilities/Handlers/GetDisplayNames/GetDisplayNamesHandler.cs | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/OpenSim/Capabilities/Handlers/GetDisplayNames/GetDisplayNamesHandler.cs b/OpenSim/Capabilities/Handlers/GetDisplayNames/GetDisplayNamesHandler.cs new file mode 100644 index 0000000..41cfdb6 --- /dev/null +++ b/OpenSim/Capabilities/Handlers/GetDisplayNames/GetDisplayNamesHandler.cs | |||
@@ -0,0 +1,117 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Collections.Specialized; | ||
32 | using System.Reflection; | ||
33 | using System.IO; | ||
34 | using System.Web; | ||
35 | using log4net; | ||
36 | using Nini.Config; | ||
37 | using OpenMetaverse; | ||
38 | using OpenMetaverse.StructuredData; | ||
39 | using OpenSim.Framework.Servers.HttpServer; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | using Caps = OpenSim.Framework.Capabilities.Caps; | ||
42 | using OSDMap = OpenMetaverse.StructuredData.OSDMap; | ||
43 | using OSDArray = OpenMetaverse.StructuredData.OSDArray; | ||
44 | |||
45 | namespace OpenSim.Capabilities.Handlers | ||
46 | { | ||
47 | public class GetDisplayNamesHandler : BaseStreamHandler | ||
48 | { | ||
49 | private static readonly ILog m_log = | ||
50 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | protected IUserManagement m_UserManagement; | ||
52 | |||
53 | public GetDisplayNamesHandler(string path, IUserManagement umService, string name, string description) | ||
54 | : base("GET", path, name, description) | ||
55 | { | ||
56 | m_UserManagement = umService; | ||
57 | } | ||
58 | |||
59 | protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
60 | { | ||
61 | // m_log.DebugFormat("[GET_DISPLAY_NAMES]: called {0}", httpRequest.Url.Query); | ||
62 | |||
63 | NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); | ||
64 | string[] ids = query.GetValues("ids"); | ||
65 | |||
66 | if (m_UserManagement == null) | ||
67 | { | ||
68 | m_log.Error("[GET_DISPLAY_NAMES]: Cannot fetch display names without a user management component"); | ||
69 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError; | ||
70 | return new byte[0]; | ||
71 | } | ||
72 | |||
73 | Dictionary<UUID,string> names = m_UserManagement.GetUsersNames(ids); | ||
74 | |||
75 | OSDMap osdReply = new OSDMap(); | ||
76 | OSDArray agents = new OSDArray(); | ||
77 | |||
78 | osdReply["agents"] = agents; | ||
79 | foreach (KeyValuePair<UUID,string> kvp in names) | ||
80 | { | ||
81 | if (string.IsNullOrEmpty(kvp.Value)) | ||
82 | continue; | ||
83 | if(kvp.Key == UUID.Zero) | ||
84 | continue; | ||
85 | |||
86 | string[] parts = kvp.Value.Split(new char[] {' '}); | ||
87 | OSDMap osdname = new OSDMap(); | ||
88 | if(parts[0] == "Unknown") | ||
89 | { | ||
90 | osdname["display_name_next_update"] = OSD.FromDate(DateTime.UtcNow.AddHours(1)); | ||
91 | osdname["display_name_expires"] = OSD.FromDate(DateTime.UtcNow.AddHours(2)); | ||
92 | } | ||
93 | else | ||
94 | { | ||
95 | osdname["display_name_next_update"] = OSD.FromDate(DateTime.UtcNow.AddDays(8)); | ||
96 | osdname["display_name_expires"] = OSD.FromDate(DateTime.UtcNow.AddMonths(1)); | ||
97 | } | ||
98 | osdname["display_name"] = OSD.FromString(kvp.Value); | ||
99 | osdname["legacy_first_name"] = parts[0]; | ||
100 | osdname["legacy_last_name"] = parts[1]; | ||
101 | osdname["username"] = OSD.FromString(kvp.Value); | ||
102 | osdname["id"] = OSD.FromUUID(kvp.Key); | ||
103 | osdname["is_display_name_default"] = OSD.FromBoolean(true); | ||
104 | |||
105 | agents.Add(osdname); | ||
106 | } | ||
107 | |||
108 | // Full content request | ||
109 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.OK; | ||
110 | //httpResponse.ContentLength = ??; | ||
111 | httpResponse.ContentType = "application/llsd+xml"; | ||
112 | |||
113 | string reply = OSDParser.SerializeLLSDXmlString(osdReply); | ||
114 | return System.Text.Encoding.UTF8.GetBytes(reply); | ||
115 | } | ||
116 | } | ||
117 | } | ||