aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Addons/Groups/Remote
diff options
context:
space:
mode:
authorDiva Canto2013-02-19 07:26:40 -0800
committerDiva Canto2013-02-19 07:26:40 -0800
commit9380d01976726885bd993573aa649f2cb0992909 (patch)
treee34fd4278fe75f1b01e3f16346bc83f15a16b383 /OpenSim/Addons/Groups/Remote
parentOffline IM: moved the Data and MySQL bits to the corresponding places in core... (diff)
downloadopensim-SC-9380d01976726885bd993573aa649f2cb0992909.zip
opensim-SC-9380d01976726885bd993573aa649f2cb0992909.tar.gz
opensim-SC-9380d01976726885bd993573aa649f2cb0992909.tar.bz2
opensim-SC-9380d01976726885bd993573aa649f2cb0992909.tar.xz
First commit of Diva Groups. The Data bits went to OpenSim.Data core, the rest to Addons.Groups.dll.
Diffstat (limited to '')
-rw-r--r--OpenSim/Addons/Groups/Remote/GroupsServiceRemoteConnector.cs642
-rw-r--r--OpenSim/Addons/Groups/Remote/GroupsServiceRemoteConnectorModule.cs437
-rw-r--r--OpenSim/Addons/Groups/Remote/GroupsServiceRobustConnector.cs760
-rw-r--r--OpenSim/Addons/Groups/RemoteConnectorCacheWrapper.cs824
4 files changed, 2663 insertions, 0 deletions
diff --git a/OpenSim/Addons/Groups/Remote/GroupsServiceRemoteConnector.cs b/OpenSim/Addons/Groups/Remote/GroupsServiceRemoteConnector.cs
new file mode 100644
index 0000000..04328c9
--- /dev/null
+++ b/OpenSim/Addons/Groups/Remote/GroupsServiceRemoteConnector.cs
@@ -0,0 +1,642 @@
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.Generic;
30using System.Linq;
31using System.Reflection;
32using System.Text;
33
34using OpenSim.Framework;
35using OpenSim.Server.Base;
36
37using OpenMetaverse;
38using log4net;
39
40namespace OpenSim.Groups
41{
42 public class GroupsServiceRemoteConnector
43 {
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45
46 private string m_ServerURI;
47 private object m_Lock = new object();
48
49 public GroupsServiceRemoteConnector(string url)
50 {
51 m_ServerURI = url;
52 if (!m_ServerURI.EndsWith("/"))
53 m_ServerURI += "/";
54
55 m_log.DebugFormat("[Groups.RemoteConnector]: Groups server at {0}", m_ServerURI);
56 }
57
58 public ExtendedGroupRecord CreateGroup(string RequestingAgentID, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment,
59 bool allowPublish, bool maturePublish, UUID founderID, out string reason)
60 {
61 reason = string.Empty;
62
63 ExtendedGroupRecord rec = new ExtendedGroupRecord();
64 rec.AllowPublish = allowPublish;
65 rec.Charter = charter;
66 rec.FounderID = founderID;
67 rec.GroupName = name;
68 rec.GroupPicture = insigniaID;
69 rec.MaturePublish = maturePublish;
70 rec.MembershipFee = membershipFee;
71 rec.OpenEnrollment = openEnrollment;
72 rec.ShowInList = showInList;
73
74 Dictionary<string, object> sendData = GroupsDataUtils.GroupRecord(rec);
75 sendData["RequestingAgentID"] = RequestingAgentID;
76 sendData["OP"] = "ADD";
77 Dictionary<string, object> ret = MakeRequest("PUTGROUP", sendData);
78
79 if (ret == null)
80 return null;
81
82 if (ret["RESULT"].ToString() == "NULL")
83 {
84 reason = ret["REASON"].ToString();
85 return null;
86 }
87
88 return GroupsDataUtils.GroupRecord((Dictionary<string, object>)ret["RESULT"]);
89
90 }
91
92 public ExtendedGroupRecord UpdateGroup(string RequestingAgentID, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish)
93 {
94 ExtendedGroupRecord rec = new ExtendedGroupRecord();
95 rec.AllowPublish = allowPublish;
96 rec.Charter = charter;
97 rec.GroupPicture = insigniaID;
98 rec.MaturePublish = maturePublish;
99 rec.GroupID = groupID;
100 rec.MembershipFee = membershipFee;
101 rec.OpenEnrollment = openEnrollment;
102 rec.ShowInList = showInList;
103
104 Dictionary<string, object> sendData = GroupsDataUtils.GroupRecord(rec);
105 sendData["RequestingAgentID"] = RequestingAgentID;
106 sendData["OP"] = "UPDATE";
107 Dictionary<string, object> ret = MakeRequest("PUTGROUP", sendData);
108
109 if (ret == null || (ret != null && ret["RESULT"].ToString() == "NULL"))
110 return null;
111
112 return GroupsDataUtils.GroupRecord((Dictionary<string, object>)ret["RESULT"]);
113 }
114
115 public ExtendedGroupRecord GetGroupRecord(string RequestingAgentID, UUID GroupID, string GroupName)
116 {
117 if (GroupID == UUID.Zero && (GroupName == null || (GroupName != null && GroupName == string.Empty)))
118 return null;
119
120 Dictionary<string, object> sendData = new Dictionary<string, object>();
121 if (GroupID != UUID.Zero)
122 sendData["GroupID"] = GroupID.ToString();
123 if (GroupName != null && GroupName != string.Empty)
124 sendData["Name"] = GroupsDataUtils.Sanitize(GroupName);
125
126 sendData["RequestingAgentID"] = RequestingAgentID;
127
128 Dictionary<string, object> ret = MakeRequest("GETGROUP", sendData);
129
130 if (ret == null || (ret != null && ret["RESULT"].ToString() == "NULL"))
131 return null;
132
133 return GroupsDataUtils.GroupRecord((Dictionary<string, object>)ret["RESULT"]);
134 }
135
136 public GroupMembershipData AddAgentToGroup(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID, string token, out string reason)
137 {
138 reason = string.Empty;
139
140 Dictionary<string, object> sendData = new Dictionary<string,object>();
141 sendData["AgentID"] = AgentID;
142 sendData["GroupID"] = GroupID.ToString();
143 sendData["RoleID"] = RoleID.ToString();
144 sendData["RequestingAgentID"] = RequestingAgentID;
145 sendData["AccessToken"] = token;
146 Dictionary<string, object> ret = MakeRequest("ADDAGENTTOGROUP", sendData);
147
148 if (ret == null)
149 return null;
150
151 if (!ret.ContainsKey("RESULT"))
152 return null;
153
154 if (ret["RESULT"].ToString() == "NULL")
155 {
156 reason = ret["REASON"].ToString();
157 return null;
158 }
159
160 return GroupsDataUtils.GroupMembershipData((Dictionary<string, object>)ret["RESULT"]);
161
162 }
163
164 public void RemoveAgentFromGroup(string RequestingAgentID, string AgentID, UUID GroupID)
165 {
166 Dictionary<string, object> sendData = new Dictionary<string, object>();
167 sendData["AgentID"] = AgentID;
168 sendData["GroupID"] = GroupID.ToString();
169 sendData["RequestingAgentID"] = RequestingAgentID;
170 MakeRequest("REMOVEAGENTFROMGROUP", sendData);
171 }
172
173 public ExtendedGroupMembershipData GetMembership(string RequestingAgentID, string AgentID, UUID GroupID)
174 {
175 Dictionary<string, object> sendData = new Dictionary<string, object>();
176 sendData["AgentID"] = AgentID;
177 if (GroupID != UUID.Zero)
178 sendData["GroupID"] = GroupID.ToString();
179 sendData["RequestingAgentID"] = RequestingAgentID;
180 Dictionary<string, object> ret = MakeRequest("GETMEMBERSHIP", sendData);
181
182 if (ret == null)
183 return null;
184
185 if (!ret.ContainsKey("RESULT"))
186 return null;
187
188 if (ret["RESULT"].ToString() == "NULL")
189 return null;
190
191 return GroupsDataUtils.GroupMembershipData((Dictionary<string, object>)ret["RESULT"]);
192 }
193
194 public List<GroupMembershipData> GetMemberships(string RequestingAgentID, string AgentID)
195 {
196 List<GroupMembershipData> memberships = new List<GroupMembershipData>();
197
198 Dictionary<string, object> sendData = new Dictionary<string, object>();
199 sendData["AgentID"] = AgentID;
200 sendData["ALL"] = "true";
201 sendData["RequestingAgentID"] = RequestingAgentID;
202 Dictionary<string, object> ret = MakeRequest("GETMEMBERSHIP", sendData);
203
204 if (ret == null)
205 return memberships;
206
207 if (!ret.ContainsKey("RESULT"))
208 return memberships;
209
210 if (ret["RESULT"].ToString() == "NULL")
211 return memberships;
212
213 foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values)
214 {
215 GroupMembershipData m = GroupsDataUtils.GroupMembershipData((Dictionary<string, object>)v);
216 memberships.Add(m);
217 }
218
219 return memberships;
220 }
221
222 public List<ExtendedGroupMembersData> GetGroupMembers(string RequestingAgentID, UUID GroupID)
223 {
224 List<ExtendedGroupMembersData> members = new List<ExtendedGroupMembersData>();
225
226 Dictionary<string, object> sendData = new Dictionary<string, object>();
227 sendData["GroupID"] = GroupID.ToString();
228 sendData["RequestingAgentID"] = RequestingAgentID;
229 Dictionary<string, object> ret = MakeRequest("GETGROUPMEMBERS", sendData);
230
231 if (ret == null)
232 return members;
233
234 if (!ret.ContainsKey("RESULT"))
235 return members;
236
237 if (ret["RESULT"].ToString() == "NULL")
238 return members;
239 foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values)
240 {
241 ExtendedGroupMembersData m = GroupsDataUtils.GroupMembersData((Dictionary<string, object>)v);
242 members.Add(m);
243 }
244
245 return members;
246 }
247
248 public bool AddGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers, out string reason)
249 {
250 reason = string.Empty;
251
252 Dictionary<string, object> sendData = new Dictionary<string, object>();
253 sendData["GroupID"] = groupID.ToString();
254 sendData["RoleID"] = roleID.ToString();
255 sendData["Name"] = GroupsDataUtils.Sanitize(name);
256 sendData["Description"] = GroupsDataUtils.Sanitize(description);
257 sendData["Title"] = GroupsDataUtils.Sanitize(title);
258 sendData["Powers"] = powers.ToString();
259 sendData["RequestingAgentID"] = RequestingAgentID;
260 sendData["OP"] = "ADD";
261 Dictionary<string, object> ret = MakeRequest("PUTROLE", sendData);
262
263 if (ret == null)
264 return false;
265
266 if (!ret.ContainsKey("RESULT"))
267 return false;
268
269 if (ret["RESULT"].ToString().ToLower() != "true")
270 {
271 reason = ret["REASON"].ToString();
272 return false;
273 }
274
275 return true;
276 }
277
278 public bool UpdateGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers)
279 {
280 Dictionary<string, object> sendData = new Dictionary<string, object>();
281 sendData["GroupID"] = groupID.ToString();
282 sendData["RoleID"] = roleID.ToString();
283 sendData["Name"] = GroupsDataUtils.Sanitize(name);
284 sendData["Description"] = GroupsDataUtils.Sanitize(description);
285 sendData["Title"] = GroupsDataUtils.Sanitize(title);
286 sendData["Powers"] = powers.ToString();
287 sendData["RequestingAgentID"] = RequestingAgentID;
288 sendData["OP"] = "UPDATE";
289 Dictionary<string, object> ret = MakeRequest("PUTROLE", sendData);
290
291 if (ret == null)
292 return false;
293
294 if (!ret.ContainsKey("RESULT"))
295 return false;
296
297 if (ret["RESULT"].ToString().ToLower() != "true")
298 return false;
299
300 return true;
301 }
302
303 public void RemoveGroupRole(string RequestingAgentID, UUID groupID, UUID roleID)
304 {
305 Dictionary<string, object> sendData = new Dictionary<string, object>();
306 sendData["GroupID"] = groupID.ToString();
307 sendData["RoleID"] = roleID.ToString();
308 sendData["RequestingAgentID"] = RequestingAgentID;
309 MakeRequest("REMOVEROLE", sendData);
310 }
311
312 public List<GroupRolesData> GetGroupRoles(string RequestingAgentID, UUID GroupID)
313 {
314 List<GroupRolesData> roles = new List<GroupRolesData>();
315
316 Dictionary<string, object> sendData = new Dictionary<string, object>();
317 sendData["GroupID"] = GroupID.ToString();
318 sendData["RequestingAgentID"] = RequestingAgentID;
319 Dictionary<string, object> ret = MakeRequest("GETGROUPROLES", sendData);
320
321 if (ret == null)
322 return roles;
323
324 if (!ret.ContainsKey("RESULT"))
325 return roles;
326
327 if (ret["RESULT"].ToString() == "NULL")
328 return roles;
329 foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values)
330 {
331 GroupRolesData m = GroupsDataUtils.GroupRolesData((Dictionary<string, object>)v);
332 roles.Add(m);
333 }
334
335 return roles;
336 }
337
338 public List<ExtendedGroupRoleMembersData> GetGroupRoleMembers(string RequestingAgentID, UUID GroupID)
339 {
340 List<ExtendedGroupRoleMembersData> rmembers = new List<ExtendedGroupRoleMembersData>();
341
342 Dictionary<string, object> sendData = new Dictionary<string, object>();
343 sendData["GroupID"] = GroupID.ToString();
344 sendData["RequestingAgentID"] = RequestingAgentID;
345 Dictionary<string, object> ret = MakeRequest("GETROLEMEMBERS", sendData);
346
347 if (ret == null)
348 return rmembers;
349
350 if (!ret.ContainsKey("RESULT"))
351 return rmembers;
352
353 if (ret["RESULT"].ToString() == "NULL")
354 return rmembers;
355
356 foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values)
357 {
358 ExtendedGroupRoleMembersData m = GroupsDataUtils.GroupRoleMembersData((Dictionary<string, object>)v);
359 rmembers.Add(m);
360 }
361
362 return rmembers;
363 }
364
365 public bool AddAgentToGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
366 {
367 Dictionary<string, object> sendData = new Dictionary<string, object>();
368 sendData["AgentID"] = AgentID.ToString();
369 sendData["GroupID"] = GroupID.ToString();
370 sendData["RoleID"] = RoleID.ToString();
371 sendData["RequestingAgentID"] = RequestingAgentID;
372 sendData["OP"] = "ADD";
373
374 Dictionary<string, object> ret = MakeRequest("AGENTROLE", sendData);
375
376 if (ret == null)
377 return false;
378
379 if (!ret.ContainsKey("RESULT"))
380 return false;
381
382 if (ret["RESULT"].ToString().ToLower() != "true")
383 return false;
384
385 return true;
386 }
387
388 public bool RemoveAgentFromGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
389 {
390 Dictionary<string, object> sendData = new Dictionary<string, object>();
391 sendData["AgentID"] = AgentID.ToString();
392 sendData["GroupID"] = GroupID.ToString();
393 sendData["RoleID"] = RoleID.ToString();
394 sendData["RequestingAgentID"] = RequestingAgentID;
395 sendData["OP"] = "DELETE";
396
397 Dictionary<string, object> ret = MakeRequest("AGENTROLE", sendData);
398
399 if (ret == null)
400 return false;
401
402 if (!ret.ContainsKey("RESULT"))
403 return false;
404
405 if (ret["RESULT"].ToString().ToLower() != "true")
406 return false;
407
408 return true;
409 }
410
411 public List<GroupRolesData> GetAgentGroupRoles(string RequestingAgentID, string AgentID, UUID GroupID)
412 {
413 List<GroupRolesData> roles = new List<GroupRolesData>();
414
415 Dictionary<string, object> sendData = new Dictionary<string, object>();
416 sendData["AgentID"] = AgentID.ToString();
417 sendData["GroupID"] = GroupID.ToString();
418 sendData["RequestingAgentID"] = RequestingAgentID;
419 Dictionary<string, object> ret = MakeRequest("GETAGENTROLES", sendData);
420
421 if (ret == null)
422 return roles;
423
424 if (!ret.ContainsKey("RESULT"))
425 return roles;
426
427 if (ret["RESULT"].ToString() == "NULL")
428 return roles;
429
430 foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values)
431 {
432 GroupRolesData m = GroupsDataUtils.GroupRolesData((Dictionary<string, object>)v);
433 roles.Add(m);
434 }
435
436 return roles;
437 }
438
439 public GroupMembershipData SetAgentActiveGroup(string RequestingAgentID, string AgentID, UUID GroupID)
440 {
441 Dictionary<string, object> sendData = new Dictionary<string, object>();
442 sendData["AgentID"] = AgentID.ToString();
443 sendData["GroupID"] = GroupID.ToString();
444 sendData["RequestingAgentID"] = RequestingAgentID;
445 sendData["OP"] = "GROUP";
446
447 Dictionary<string, object> ret = MakeRequest("SETACTIVE", sendData);
448
449 if (ret == null)
450 return null;
451
452 if (!ret.ContainsKey("RESULT"))
453 return null;
454
455 if (ret["RESULT"].ToString() == "NULL")
456 return null;
457
458 return GroupsDataUtils.GroupMembershipData((Dictionary<string, object>)ret["RESULT"]);
459 }
460
461 public void SetAgentActiveGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
462 {
463 Dictionary<string, object> sendData = new Dictionary<string, object>();
464 sendData["AgentID"] = AgentID.ToString();
465 sendData["GroupID"] = GroupID.ToString();
466 sendData["RoleID"] = RoleID.ToString();
467 sendData["RequestingAgentID"] = RequestingAgentID;
468 sendData["OP"] = "ROLE";
469
470 MakeRequest("SETACTIVE", sendData);
471 }
472
473 public void UpdateMembership(string RequestingAgentID, string AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile)
474 {
475 Dictionary<string, object> sendData = new Dictionary<string, object>();
476 sendData["AgentID"] = AgentID.ToString();
477 sendData["GroupID"] = GroupID.ToString();
478 sendData["AcceptNotices"] = AcceptNotices.ToString();
479 sendData["ListInProfile"] = ListInProfile.ToString();
480 sendData["RequestingAgentID"] = RequestingAgentID;
481 MakeRequest("UPDATEMEMBERSHIP", sendData);
482 }
483
484 public bool AddAgentToGroupInvite(string RequestingAgentID, UUID inviteID, UUID groupID, UUID roleID, string agentID)
485 {
486 Dictionary<string, object> sendData = new Dictionary<string, object>();
487 sendData["InviteID"] = inviteID.ToString();
488 sendData["GroupID"] = groupID.ToString();
489 sendData["RoleID"] = roleID.ToString();
490 sendData["AgentID"] = agentID.ToString();
491 sendData["RequestingAgentID"] = RequestingAgentID;
492 sendData["OP"] = "ADD";
493
494 Dictionary<string, object> ret = MakeRequest("INVITE", sendData);
495
496 if (ret == null)
497 return false;
498
499 if (!ret.ContainsKey("RESULT"))
500 return false;
501
502 if (ret["RESULT"].ToString().ToLower() != "true") // it may return "NULL"
503 return false;
504
505 return true;
506 }
507
508 public GroupInviteInfo GetAgentToGroupInvite(string RequestingAgentID, UUID inviteID)
509 {
510 Dictionary<string, object> sendData = new Dictionary<string, object>();
511 sendData["InviteID"] = inviteID.ToString();
512 sendData["RequestingAgentID"] = RequestingAgentID;
513 sendData["OP"] = "GET";
514
515 Dictionary<string, object> ret = MakeRequest("INVITE", sendData);
516
517 if (ret == null)
518 return null;
519
520 if (!ret.ContainsKey("RESULT"))
521 return null;
522
523 if (ret["RESULT"].ToString() == "NULL")
524 return null;
525
526 return GroupsDataUtils.GroupInviteInfo((Dictionary<string, object>)ret["RESULT"]);
527 }
528
529 public void RemoveAgentToGroupInvite(string RequestingAgentID, UUID inviteID)
530 {
531 Dictionary<string, object> sendData = new Dictionary<string, object>();
532 sendData["InviteID"] = inviteID.ToString();
533 sendData["RequestingAgentID"] = RequestingAgentID;
534 sendData["OP"] = "DELETE";
535
536 MakeRequest("INVITE", sendData);
537 }
538
539 public bool AddGroupNotice(string RequestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message,
540 bool hasAttachment, byte attType, string attName, UUID attItemID, string attOwnerID)
541 {
542 Dictionary<string, object> sendData = new Dictionary<string, object>();
543 sendData["GroupID"] = groupID.ToString();
544 sendData["NoticeID"] = noticeID.ToString();
545 sendData["FromName"] = GroupsDataUtils.Sanitize(fromName);
546 sendData["Subject"] = GroupsDataUtils.Sanitize(subject);
547 sendData["Message"] = GroupsDataUtils.Sanitize(message);
548 sendData["HasAttachment"] = hasAttachment.ToString();
549 if (hasAttachment)
550 {
551 sendData["AttachmentType"] = attType.ToString();
552 sendData["AttachmentName"] = attName.ToString();
553 sendData["AttachmentItemID"] = attItemID.ToString();
554 sendData["AttachmentOwnerID"] = attOwnerID;
555 }
556 sendData["RequestingAgentID"] = RequestingAgentID;
557
558 Dictionary<string, object> ret = MakeRequest("ADDNOTICE", sendData);
559
560 if (ret == null)
561 return false;
562
563 if (!ret.ContainsKey("RESULT"))
564 return false;
565
566 if (ret["RESULT"].ToString().ToLower() != "true")
567 return false;
568
569 return true;
570 }
571
572 public GroupNoticeInfo GetGroupNotice(string RequestingAgentID, UUID noticeID)
573 {
574 Dictionary<string, object> sendData = new Dictionary<string, object>();
575 sendData["NoticeID"] = noticeID.ToString();
576 sendData["RequestingAgentID"] = RequestingAgentID;
577
578 Dictionary<string, object> ret = MakeRequest("GETNOTICES", sendData);
579
580 if (ret == null)
581 return null;
582
583 if (!ret.ContainsKey("RESULT"))
584 return null;
585
586 if (ret["RESULT"].ToString() == "NULL")
587 return null;
588
589 return GroupsDataUtils.GroupNoticeInfo((Dictionary<string, object>)ret["RESULT"]);
590 }
591
592 public List<ExtendedGroupNoticeData> GetGroupNotices(string RequestingAgentID, UUID GroupID)
593 {
594 List<ExtendedGroupNoticeData> notices = new List<ExtendedGroupNoticeData>();
595
596 Dictionary<string, object> sendData = new Dictionary<string, object>();
597 sendData["GroupID"] = GroupID.ToString();
598 sendData["RequestingAgentID"] = RequestingAgentID;
599 Dictionary<string, object> ret = MakeRequest("GETNOTICES", sendData);
600
601 if (ret == null)
602 return notices;
603
604 if (!ret.ContainsKey("RESULT"))
605 return notices;
606
607 if (ret["RESULT"].ToString() == "NULL")
608 return notices;
609
610 foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values)
611 {
612 ExtendedGroupNoticeData m = GroupsDataUtils.GroupNoticeData((Dictionary<string, object>)v);
613 notices.Add(m);
614 }
615
616 return notices;
617 }
618
619 #region Make Request
620
621 private Dictionary<string, object> MakeRequest(string method, Dictionary<string, object> sendData)
622 {
623 sendData["METHOD"] = method;
624
625 string reply = string.Empty;
626 lock (m_Lock)
627 reply = SynchronousRestFormsRequester.MakeRequest("POST",
628 m_ServerURI + "groups",
629 ServerUtils.BuildQueryString(sendData));
630
631 if (reply == string.Empty)
632 return null;
633
634 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(
635 reply);
636
637 return replyData;
638 }
639 #endregion
640
641 }
642}
diff --git a/OpenSim/Addons/Groups/Remote/GroupsServiceRemoteConnectorModule.cs b/OpenSim/Addons/Groups/Remote/GroupsServiceRemoteConnectorModule.cs
new file mode 100644
index 0000000..d1c02db
--- /dev/null
+++ b/OpenSim/Addons/Groups/Remote/GroupsServiceRemoteConnectorModule.cs
@@ -0,0 +1,437 @@
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.Generic;
30using System.Linq;
31using System.Reflection;
32using System.Threading;
33using System.Text;
34
35using OpenSim.Framework;
36using OpenSim.Region.Framework.Scenes;
37using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Server.Base;
39
40using OpenMetaverse;
41using Mono.Addins;
42using log4net;
43using Nini.Config;
44
45namespace OpenSim.Groups
46{
47 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GroupsServiceRemoteConnectorModule")]
48 public class GroupsServiceRemoteConnectorModule : ISharedRegionModule, IGroupsServicesConnector
49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51
52 private bool m_Enabled = false;
53 private GroupsServiceRemoteConnector m_GroupsService;
54 private IUserManagement m_UserManagement;
55 private List<Scene> m_Scenes;
56
57 private RemoteConnectorCacheWrapper m_CacheWrapper;
58
59 #region constructors
60 public GroupsServiceRemoteConnectorModule()
61 {
62 }
63
64 public GroupsServiceRemoteConnectorModule(IConfigSource config, IUserManagement uman)
65 {
66 Init(config);
67 m_UserManagement = uman;
68 m_CacheWrapper = new RemoteConnectorCacheWrapper(m_UserManagement);
69
70 }
71 #endregion
72
73 private void Init(IConfigSource config)
74 {
75 IConfig groupsConfig = config.Configs["Groups"];
76 string url = groupsConfig.GetString("GroupsServerURI", string.Empty);
77 if (url == string.Empty)
78 {
79 m_log.WarnFormat("[Groups.RemoteConnector]: Groups server URL not provided. Groups will not work.");
80 return;
81 }
82
83 m_GroupsService = new GroupsServiceRemoteConnector(url);
84 m_Scenes = new List<Scene>();
85
86 }
87
88 #region ISharedRegionModule
89
90 public void Initialise(IConfigSource config)
91 {
92 IConfig groupsConfig = config.Configs["Groups"];
93 if (groupsConfig == null)
94 return;
95
96 if ((groupsConfig.GetBoolean("Enabled", false) == false)
97 || (groupsConfig.GetString("ServicesConnectorModule", string.Empty) != Name))
98 {
99 return;
100 }
101
102 Init(config);
103
104 m_Enabled = true;
105 m_log.DebugFormat("[Groups.RemoteConnector]: Initializing {0}", this.Name);
106 }
107
108 public string Name
109 {
110 get { return "Groups Remote Service Connector"; }
111 }
112
113 public Type ReplaceableInterface
114 {
115 get { return null; }
116 }
117
118 public void AddRegion(Scene scene)
119 {
120 if (!m_Enabled)
121 return;
122
123 m_log.DebugFormat("[Groups.RemoteConnector]: Registering {0} with {1}", this.Name, scene.RegionInfo.RegionName);
124 scene.RegisterModuleInterface<IGroupsServicesConnector>(this);
125 m_Scenes.Add(scene);
126 }
127
128 public void RemoveRegion(Scene scene)
129 {
130 if (!m_Enabled)
131 return;
132
133 scene.UnregisterModuleInterface<IGroupsServicesConnector>(this);
134 m_Scenes.Remove(scene);
135 }
136
137 public void RegionLoaded(Scene scene)
138 {
139 if (!m_Enabled)
140 return;
141
142 if (m_UserManagement == null)
143 {
144 m_UserManagement = scene.RequestModuleInterface<IUserManagement>();
145 m_CacheWrapper = new RemoteConnectorCacheWrapper(m_UserManagement);
146 }
147 }
148
149 public void PostInitialise()
150 {
151 }
152
153 public void Close()
154 {
155 }
156
157 #endregion
158
159 #region IGroupsServicesConnector
160
161 public UUID CreateGroup(UUID RequestingAgentID, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment,
162 bool allowPublish, bool maturePublish, UUID founderID, out string reason)
163 {
164 m_log.DebugFormat("[Groups.RemoteConnector]: Creating group {0}", name);
165 string r = string.Empty;
166
167 UUID groupID = m_CacheWrapper.CreateGroup(RequestingAgentID, delegate
168 {
169 return m_GroupsService.CreateGroup(RequestingAgentID.ToString(), name, charter, showInList, insigniaID,
170 membershipFee, openEnrollment, allowPublish, maturePublish, founderID, out r);
171 });
172
173 reason = r;
174 return groupID;
175 }
176
177 public bool UpdateGroup(string RequestingAgentID, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee,
178 bool openEnrollment, bool allowPublish, bool maturePublish, out string reason)
179 {
180 string r = string.Empty;
181
182 bool success = m_CacheWrapper.UpdateGroup(groupID, delegate
183 {
184 return m_GroupsService.UpdateGroup(RequestingAgentID, groupID, charter, showInList, insigniaID, membershipFee, openEnrollment, allowPublish, maturePublish);
185 });
186
187 reason = r;
188 return success;
189 }
190
191 public ExtendedGroupRecord GetGroupRecord(string RequestingAgentID, UUID GroupID, string GroupName)
192 {
193 if (GroupID == UUID.Zero && (GroupName == null || GroupName != null && GroupName == string.Empty))
194 return null;
195
196 return m_CacheWrapper.GetGroupRecord(RequestingAgentID,GroupID,GroupName, delegate
197 {
198 return m_GroupsService.GetGroupRecord(RequestingAgentID, GroupID, GroupName);
199 });
200 }
201
202 public List<DirGroupsReplyData> FindGroups(string RequestingAgentID, string search)
203 {
204 // TODO!
205 return new List<DirGroupsReplyData>();
206 }
207
208 public bool AddAgentToGroup(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID, string token, out string reason)
209 {
210 string agentFullID = AgentID;
211 m_log.DebugFormat("[Groups.RemoteConnector]: Add agent {0} to group {1}", agentFullID, GroupID);
212 string r = string.Empty;
213
214 bool success = m_CacheWrapper.AddAgentToGroup(RequestingAgentID, AgentID, GroupID, delegate
215 {
216 return m_GroupsService.AddAgentToGroup(RequestingAgentID, agentFullID, GroupID, RoleID, token, out r);
217 });
218
219 reason = r;
220 return success;
221 }
222
223 public void RemoveAgentFromGroup(string RequestingAgentID, string AgentID, UUID GroupID)
224 {
225 m_CacheWrapper.RemoveAgentFromGroup(RequestingAgentID, AgentID, GroupID, delegate
226 {
227 m_GroupsService.RemoveAgentFromGroup(RequestingAgentID, AgentID, GroupID);
228 });
229
230 }
231
232 public void SetAgentActiveGroup(string RequestingAgentID, string AgentID, UUID GroupID)
233 {
234 m_CacheWrapper.SetAgentActiveGroup(AgentID, delegate
235 {
236 return m_GroupsService.SetAgentActiveGroup(RequestingAgentID, AgentID, GroupID);
237 });
238 }
239
240 public ExtendedGroupMembershipData GetAgentActiveMembership(string RequestingAgentID, string AgentID)
241 {
242 return m_CacheWrapper.GetAgentActiveMembership(AgentID, delegate
243 {
244 return m_GroupsService.GetMembership(RequestingAgentID, AgentID, UUID.Zero);
245 });
246 }
247
248 public ExtendedGroupMembershipData GetAgentGroupMembership(string RequestingAgentID, string AgentID, UUID GroupID)
249 {
250 return m_CacheWrapper.GetAgentGroupMembership(AgentID, GroupID, delegate
251 {
252 return m_GroupsService.GetMembership(RequestingAgentID, AgentID, GroupID);
253 });
254 }
255
256 public List<GroupMembershipData> GetAgentGroupMemberships(string RequestingAgentID, string AgentID)
257 {
258 return m_CacheWrapper.GetAgentGroupMemberships(AgentID, delegate
259 {
260 return m_GroupsService.GetMemberships(RequestingAgentID, AgentID);
261 });
262 }
263
264
265 public List<GroupMembersData> GetGroupMembers(string RequestingAgentID, UUID GroupID)
266 {
267 return m_CacheWrapper.GetGroupMembers(RequestingAgentID, GroupID, delegate
268 {
269 return m_GroupsService.GetGroupMembers(RequestingAgentID, GroupID);
270 });
271 }
272
273 public bool AddGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers, out string reason)
274 {
275 string r = string.Empty;
276 bool success = m_CacheWrapper.AddGroupRole(roleID, description, name, powers, title, delegate
277 {
278 return m_GroupsService.AddGroupRole(RequestingAgentID, groupID, roleID, name, description, title, powers, out r);
279 });
280
281 reason = r;
282 return success;
283 }
284
285 public bool UpdateGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers)
286 {
287 return m_CacheWrapper.UpdateGroupRole(groupID, roleID, name, description, title, powers, delegate
288 {
289 return m_GroupsService.UpdateGroupRole(RequestingAgentID, groupID, roleID, name, description, title, powers);
290 });
291 }
292
293 public void RemoveGroupRole(string RequestingAgentID, UUID groupID, UUID roleID)
294 {
295 m_CacheWrapper.RemoveGroupRole(RequestingAgentID, groupID, roleID, delegate
296 {
297 m_GroupsService.RemoveGroupRole(RequestingAgentID, groupID, roleID);
298 });
299 }
300
301 public List<GroupRolesData> GetGroupRoles(string RequestingAgentID, UUID GroupID)
302 {
303 return m_CacheWrapper.GetGroupRoles(RequestingAgentID, GroupID, delegate
304 {
305 return m_GroupsService.GetGroupRoles(RequestingAgentID, GroupID);
306 });
307 }
308
309 public List<GroupRoleMembersData> GetGroupRoleMembers(string RequestingAgentID, UUID GroupID)
310 {
311 return m_CacheWrapper.GetGroupRoleMembers(RequestingAgentID, GroupID, delegate
312 {
313 return m_GroupsService.GetGroupRoleMembers(RequestingAgentID, GroupID);
314 });
315 }
316
317 public void AddAgentToGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
318 {
319 m_CacheWrapper.AddAgentToGroupRole(RequestingAgentID, AgentID, GroupID, RoleID, delegate
320 {
321 return m_GroupsService.AddAgentToGroupRole(RequestingAgentID, AgentID, GroupID, RoleID);
322 });
323 }
324
325 public void RemoveAgentFromGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
326 {
327 m_CacheWrapper.RemoveAgentFromGroupRole(RequestingAgentID, AgentID, GroupID, RoleID, delegate
328 {
329 return m_GroupsService.RemoveAgentFromGroupRole(RequestingAgentID, AgentID, GroupID, RoleID);
330 });
331 }
332
333 public List<GroupRolesData> GetAgentGroupRoles(string RequestingAgentID, string AgentID, UUID GroupID)
334 {
335 return m_CacheWrapper.GetAgentGroupRoles(RequestingAgentID, AgentID, GroupID, delegate
336 {
337 return m_GroupsService.GetAgentGroupRoles(RequestingAgentID, AgentID, GroupID); ;
338 });
339 }
340
341 public void SetAgentActiveGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
342 {
343 m_CacheWrapper.SetAgentActiveGroupRole(AgentID, GroupID, delegate
344 {
345 m_GroupsService.SetAgentActiveGroupRole(RequestingAgentID, AgentID, GroupID, RoleID);
346 });
347 }
348
349 public void UpdateMembership(string RequestingAgentID, string AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile)
350 {
351 m_CacheWrapper.UpdateMembership(AgentID, GroupID, AcceptNotices, ListInProfile, delegate
352 {
353 m_GroupsService.UpdateMembership(RequestingAgentID, AgentID, GroupID, AcceptNotices, ListInProfile);
354 });
355 }
356
357 public bool AddAgentToGroupInvite(string RequestingAgentID, UUID inviteID, UUID groupID, UUID roleID, string agentID)
358 {
359 return m_GroupsService.AddAgentToGroupInvite(RequestingAgentID, inviteID, groupID, roleID, agentID);
360 }
361
362 public GroupInviteInfo GetAgentToGroupInvite(string RequestingAgentID, UUID inviteID)
363 {
364 return m_GroupsService.GetAgentToGroupInvite(RequestingAgentID, inviteID);
365 }
366
367 public void RemoveAgentToGroupInvite(string RequestingAgentID, UUID inviteID)
368 {
369 m_GroupsService.RemoveAgentToGroupInvite(RequestingAgentID, inviteID);
370 }
371
372 public bool AddGroupNotice(string RequestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message,
373 bool hasAttachment, byte attType, string attName, UUID attItemID, string attOwnerID)
374 {
375 GroupNoticeInfo notice = new GroupNoticeInfo();
376 notice.GroupID = groupID;
377 notice.Message = message;
378 notice.noticeData = new ExtendedGroupNoticeData();
379 notice.noticeData.AttachmentItemID = attItemID;
380 notice.noticeData.AttachmentName = attName;
381 notice.noticeData.AttachmentOwnerID = attOwnerID.ToString();
382 notice.noticeData.AttachmentType = attType;
383 notice.noticeData.FromName = fromName;
384 notice.noticeData.HasAttachment = hasAttachment;
385 notice.noticeData.NoticeID = noticeID;
386 notice.noticeData.Subject = subject;
387 notice.noticeData.Timestamp = (uint)Util.UnixTimeSinceEpoch();
388
389 return m_CacheWrapper.AddGroupNotice(groupID, noticeID, notice, delegate
390 {
391 return m_GroupsService.AddGroupNotice(RequestingAgentID, groupID, noticeID, fromName, subject, message,
392 hasAttachment, attType, attName, attItemID, attOwnerID);
393 });
394 }
395
396 public GroupNoticeInfo GetGroupNotice(string RequestingAgentID, UUID noticeID)
397 {
398 return m_CacheWrapper.GetGroupNotice(noticeID, delegate
399 {
400 return m_GroupsService.GetGroupNotice(RequestingAgentID, noticeID);
401 });
402 }
403
404 public List<ExtendedGroupNoticeData> GetGroupNotices(string RequestingAgentID, UUID GroupID)
405 {
406 return m_CacheWrapper.GetGroupNotices(GroupID, delegate
407 {
408 return m_GroupsService.GetGroupNotices(RequestingAgentID, GroupID);
409 });
410 }
411
412 public void ResetAgentGroupChatSessions(string agentID)
413 {
414 }
415
416 public bool hasAgentBeenInvitedToGroupChatSession(string agentID, UUID groupID)
417 {
418 return false;
419 }
420
421 public bool hasAgentDroppedGroupChatSession(string agentID, UUID groupID)
422 {
423 return false;
424 }
425
426 public void AgentDroppedFromGroupChatSession(string agentID, UUID groupID)
427 {
428 }
429
430 public void AgentInvitedToGroupChatSession(string agentID, UUID groupID)
431 {
432 }
433
434 #endregion
435 }
436
437}
diff --git a/OpenSim/Addons/Groups/Remote/GroupsServiceRobustConnector.cs b/OpenSim/Addons/Groups/Remote/GroupsServiceRobustConnector.cs
new file mode 100644
index 0000000..8c257ed
--- /dev/null
+++ b/OpenSim/Addons/Groups/Remote/GroupsServiceRobustConnector.cs
@@ -0,0 +1,760 @@
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.Reflection;
30using System.Text;
31using System.Xml;
32using System.Collections.Generic;
33using System.IO;
34using Nini.Config;
35using OpenSim.Framework;
36using OpenSim.Server.Base;
37using OpenSim.Services.Interfaces;
38using OpenSim.Framework.Servers.HttpServer;
39using OpenSim.Server.Handlers.Base;
40using log4net;
41using OpenMetaverse;
42
43namespace OpenSim.Groups
44{
45 public class GroupsServiceRobustConnector : ServiceConnector
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 private GroupsService m_GroupsService;
50 private string m_ConfigName = "Groups";
51
52 public GroupsServiceRobustConnector(IConfigSource config, IHttpServer server, string configName) :
53 base(config, server, configName)
54 {
55 if (configName != String.Empty)
56 m_ConfigName = configName;
57
58 m_log.DebugFormat("[Groups.RobustConnector]: Starting with config name {0}", m_ConfigName);
59
60 m_GroupsService = new GroupsService(config);
61
62 server.AddStreamHandler(new GroupsServicePostHandler(m_GroupsService));
63 }
64 }
65
66 public class GroupsServicePostHandler : BaseStreamHandler
67 {
68 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
69
70 private GroupsService m_GroupsService;
71
72 public GroupsServicePostHandler(GroupsService service) :
73 base("POST", "/groups")
74 {
75 m_GroupsService = service;
76 }
77
78 public override byte[] Handle(string path, Stream requestData,
79 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
80 {
81 StreamReader sr = new StreamReader(requestData);
82 string body = sr.ReadToEnd();
83 sr.Close();
84 body = body.Trim();
85
86 //m_log.DebugFormat("[XXX]: query String: {0}", body);
87
88 try
89 {
90 Dictionary<string, object> request =
91 ServerUtils.ParseQueryString(body);
92
93 if (!request.ContainsKey("METHOD"))
94 return FailureResult();
95
96 string method = request["METHOD"].ToString();
97 request.Remove("METHOD");
98
99 m_log.DebugFormat("[Groups.Handler]: {0}", method);
100 switch (method)
101 {
102 case "PUTGROUP":
103 return HandleAddOrUpdateGroup(request);
104 case "GETGROUP":
105 return HandleGetGroup(request);
106 case "ADDAGENTTOGROUP":
107 return HandleAddAgentToGroup(request);
108 case "REMOVEAGENTFROMGROUP":
109 return HandleRemoveAgentFromGroup(request);
110 case "GETMEMBERSHIP":
111 return HandleGetMembership(request);
112 case "GETGROUPMEMBERS":
113 return HandleGetGroupMembers(request);
114 case "PUTROLE":
115 return HandlePutRole(request);
116 case "REMOVEROLE":
117 return HandleRemoveRole(request);
118 case "GETGROUPROLES":
119 return HandleGetGroupRoles(request);
120 case "GETROLEMEMBERS":
121 return HandleGetRoleMembers(request);
122 case "AGENTROLE":
123 return HandleAgentRole(request);
124 case "GETAGENTROLES":
125 return HandleGetAgentRoles(request);
126 case "SETACTIVE":
127 return HandleSetActive(request);
128 case "UPDATEMEMBERSHIP":
129 return HandleUpdateMembership(request);
130 case "INVITE":
131 return HandleInvite(request);
132 case "ADDNOTICE":
133 return HandleAddNotice(request);
134 case "GETNOTICES":
135 return HandleGetNotices(request);
136 }
137 m_log.DebugFormat("[GROUPS HANDLER]: unknown method request: {0}", method);
138 }
139 catch (Exception e)
140 {
141 m_log.DebugFormat("[GROUPS HANDLER]: Exception {0}", e.StackTrace);
142 }
143
144 return FailureResult();
145 }
146
147 byte[] HandleAddOrUpdateGroup(Dictionary<string, object> request)
148 {
149 Dictionary<string, object> result = new Dictionary<string, object>();
150
151 ExtendedGroupRecord grec = GroupsDataUtils.GroupRecord(request);
152 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("OP"))
153 NullResult(result, "Bad network data");
154
155 else
156 {
157 string RequestingAgentID = request["RequestingAgentID"].ToString();
158 string reason = string.Empty;
159 string op = request["OP"].ToString();
160 if (op == "ADD")
161 {
162 grec.GroupID = m_GroupsService.CreateGroup(RequestingAgentID, grec.GroupName, grec.Charter, grec.ShowInList, grec.GroupPicture, grec.MembershipFee,
163 grec.OpenEnrollment, grec.AllowPublish, grec.MaturePublish, grec.FounderID, out reason);
164
165 }
166 else if (op == "UPDATE")
167 {
168 m_GroupsService.UpdateGroup(RequestingAgentID, grec.GroupID, grec.Charter, grec.ShowInList, grec.GroupPicture, grec.MembershipFee,
169 grec.OpenEnrollment, grec.AllowPublish, grec.MaturePublish);
170
171 }
172
173 grec = m_GroupsService.GetGroupRecord(RequestingAgentID, grec.GroupID);
174 if (grec == null)
175 NullResult(result, "Internal Error");
176 else
177 result["RESULT"] = GroupsDataUtils.GroupRecord(grec);
178 }
179
180 string xmlString = ServerUtils.BuildXmlResponse(result);
181
182 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
183 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
184 }
185
186 byte[] HandleGetGroup(Dictionary<string, object> request)
187 {
188 Dictionary<string, object> result = new Dictionary<string, object>();
189
190 if (!request.ContainsKey("RequestingAgentID"))
191 NullResult(result, "Bad network data");
192 else
193 {
194 string RequestingAgentID = request["RequestingAgentID"].ToString();
195 ExtendedGroupRecord grec = null;
196 if (request.ContainsKey("GroupID"))
197 {
198 UUID groupID = new UUID(request["GroupID"].ToString());
199 grec = m_GroupsService.GetGroupRecord(RequestingAgentID, groupID);
200 }
201 else if (request.ContainsKey("Name"))
202 {
203 string name = request["Name"].ToString();
204 grec = m_GroupsService.GetGroupRecord(RequestingAgentID, name);
205 }
206
207 if (grec == null)
208 NullResult(result, "Group not found");
209 else
210 result["RESULT"] = GroupsDataUtils.GroupRecord(grec);
211 }
212
213 string xmlString = ServerUtils.BuildXmlResponse(result);
214
215 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
216 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
217 }
218
219 byte[] HandleAddAgentToGroup(Dictionary<string, object> request)
220 {
221 Dictionary<string, object> result = new Dictionary<string, object>();
222
223 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("AgentID") ||
224 !request.ContainsKey("GroupID") || !request.ContainsKey("RoleID"))
225 NullResult(result, "Bad network data");
226 else
227 {
228 UUID groupID = new UUID(request["GroupID"].ToString());
229 UUID roleID = new UUID(request["RoleID"].ToString());
230 string agentID = request["AgentID"].ToString();
231 string requestingAgentID = request["RequestingAgentID"].ToString();
232 string token = string.Empty;
233 string reason = string.Empty;
234
235 if (request.ContainsKey("AccessToken"))
236 token = request["AccessToken"].ToString();
237
238 if (!m_GroupsService.AddAgentToGroup(requestingAgentID, agentID, groupID, roleID, token, out reason))
239 NullResult(result, reason);
240 else
241 {
242 GroupMembershipData membership = m_GroupsService.GetAgentGroupMembership(requestingAgentID, agentID, groupID);
243 if (membership == null)
244 NullResult(result, "Internal error");
245 else
246 result["RESULT"] = GroupsDataUtils.GroupMembershipData((ExtendedGroupMembershipData)membership);
247 }
248 }
249
250 string xmlString = ServerUtils.BuildXmlResponse(result);
251
252 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
253 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
254 }
255
256 byte[] HandleRemoveAgentFromGroup(Dictionary<string, object> request)
257 {
258 Dictionary<string, object> result = new Dictionary<string, object>();
259
260 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("AgentID") || !request.ContainsKey("GroupID"))
261 NullResult(result, "Bad network data");
262 else
263 {
264 UUID groupID = new UUID(request["GroupID"].ToString());
265 string agentID = request["AgentID"].ToString();
266 string requestingAgentID = request["RequestingAgentID"].ToString();
267 string reason = string.Empty;
268
269 m_GroupsService.RemoveAgentFromGroup(requestingAgentID, agentID, groupID);
270 }
271
272 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
273 result["RESULT"] = "true";
274 return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result));
275 }
276
277 byte[] HandleGetMembership(Dictionary<string, object> request)
278 {
279 Dictionary<string, object> result = new Dictionary<string, object>();
280
281 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("AgentID"))
282 NullResult(result, "Bad network data");
283 else
284 {
285 string agentID = request["AgentID"].ToString();
286 UUID groupID = UUID.Zero;
287 if (request.ContainsKey("GroupID"))
288 groupID = new UUID(request["GroupID"].ToString());
289 string requestingAgentID = request["RequestingAgentID"].ToString();
290 bool all = request.ContainsKey("ALL");
291
292 if (!all)
293 {
294 ExtendedGroupMembershipData membership = null;
295 if (groupID == UUID.Zero)
296 {
297 membership = m_GroupsService.GetAgentActiveMembership(requestingAgentID, agentID);
298 }
299 else
300 {
301 membership = m_GroupsService.GetAgentGroupMembership(requestingAgentID, agentID, groupID);
302 }
303
304 if (membership == null)
305 NullResult(result, "No such membership");
306 else
307 result["RESULT"] = GroupsDataUtils.GroupMembershipData(membership);
308 }
309 else
310 {
311 List<GroupMembershipData> memberships = m_GroupsService.GetAgentGroupMemberships(requestingAgentID, agentID);
312 if (memberships == null || (memberships != null && memberships.Count == 0))
313 {
314 NullResult(result, "No memberships");
315 }
316 else
317 {
318 Dictionary<string, object> dict = new Dictionary<string, object>();
319 int i = 0;
320 foreach (GroupMembershipData m in memberships)
321 dict["m-" + i++] = GroupsDataUtils.GroupMembershipData((ExtendedGroupMembershipData)m);
322
323 result["RESULT"] = dict;
324 }
325 }
326 }
327
328 string xmlString = ServerUtils.BuildXmlResponse(result);
329
330 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
331 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
332 }
333
334 byte[] HandleGetGroupMembers(Dictionary<string, object> request)
335 {
336 Dictionary<string, object> result = new Dictionary<string, object>();
337
338 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID"))
339 NullResult(result, "Bad network data");
340 else
341 {
342 UUID groupID = new UUID(request["GroupID"].ToString());
343 string requestingAgentID = request["RequestingAgentID"].ToString();
344
345 List<ExtendedGroupMembersData> members = m_GroupsService.GetGroupMembers(requestingAgentID, groupID);
346 if (members == null || (members != null && members.Count == 0))
347 {
348 NullResult(result, "No members");
349 }
350 else
351 {
352 Dictionary<string, object> dict = new Dictionary<string, object>();
353 int i = 0;
354 foreach (ExtendedGroupMembersData m in members)
355 {
356 dict["m-" + i++] = GroupsDataUtils.GroupMembersData(m);
357 }
358
359 result["RESULT"] = dict;
360 }
361 }
362
363 string xmlString = ServerUtils.BuildXmlResponse(result);
364
365 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
366 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
367 }
368
369 byte[] HandlePutRole(Dictionary<string, object> request)
370 {
371 Dictionary<string, object> result = new Dictionary<string, object>();
372
373 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("RoleID") ||
374 !request.ContainsKey("Name") || !request.ContainsKey("Descrption") || !request.ContainsKey("Title") ||
375 !request.ContainsKey("Powers") || !request.ContainsKey("OP"))
376 NullResult(result, "Bad network data");
377
378 else
379 {
380 string op = request["OP"].ToString();
381 string reason = string.Empty;
382
383 bool success = false;
384 if (op == "ADD")
385 success = m_GroupsService.AddGroupRole(request["RequestingAgentID"].ToString(), new UUID(request["GroupID"].ToString()),
386 new UUID(request["RoleID"].ToString()), request["Name"].ToString(), request["Description"].ToString(),
387 request["Title"].ToString(), UInt64.Parse(request["Powers"].ToString()), out reason);
388
389 else if (op == "UPDATE")
390 success = m_GroupsService.UpdateGroupRole(request["RequestingAgentID"].ToString(), new UUID(request["GroupID"].ToString()),
391 new UUID(request["RoleID"].ToString()), request["Name"].ToString(), request["Description"].ToString(),
392 request["Title"].ToString(), UInt64.Parse(request["Powers"].ToString()));
393
394 result["RESULT"] = success.ToString();
395 }
396
397 string xmlString = ServerUtils.BuildXmlResponse(result);
398
399 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
400 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
401 }
402
403 byte[] HandleRemoveRole(Dictionary<string, object> request)
404 {
405 Dictionary<string, object> result = new Dictionary<string, object>();
406
407 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("RoleID"))
408 NullResult(result, "Bad network data");
409
410 else
411 {
412 m_GroupsService.RemoveGroupRole(request["RequestingAgentID"].ToString(), new UUID(request["GroupID"].ToString()),
413 new UUID(request["RoleID"].ToString()));
414 result["RESULT"] = "true";
415 }
416
417 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
418 return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result));
419 }
420
421 byte[] HandleGetGroupRoles(Dictionary<string, object> request)
422 {
423 Dictionary<string, object> result = new Dictionary<string, object>();
424
425 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID"))
426 NullResult(result, "Bad network data");
427 else
428 {
429 UUID groupID = new UUID(request["GroupID"].ToString());
430 string requestingAgentID = request["RequestingAgentID"].ToString();
431
432 List<GroupRolesData> roles = m_GroupsService.GetGroupRoles(requestingAgentID, groupID);
433 if (roles == null || (roles != null && roles.Count == 0))
434 {
435 NullResult(result, "No members");
436 }
437 else
438 {
439 Dictionary<string, object> dict = new Dictionary<string, object>();
440 int i = 0;
441 foreach (GroupRolesData r in roles)
442 dict["r-" + i++] = GroupsDataUtils.GroupRolesData(r);
443
444 result["RESULT"] = dict;
445 }
446 }
447
448 string xmlString = ServerUtils.BuildXmlResponse(result);
449
450 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
451 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
452 }
453
454 byte[] HandleGetRoleMembers(Dictionary<string, object> request)
455 {
456 Dictionary<string, object> result = new Dictionary<string, object>();
457
458 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID"))
459 NullResult(result, "Bad network data");
460 else
461 {
462 UUID groupID = new UUID(request["GroupID"].ToString());
463 string requestingAgentID = request["RequestingAgentID"].ToString();
464
465 List<ExtendedGroupRoleMembersData> rmembers = m_GroupsService.GetGroupRoleMembers(requestingAgentID, groupID);
466 if (rmembers == null || (rmembers != null && rmembers.Count == 0))
467 {
468 NullResult(result, "No members");
469 }
470 else
471 {
472 Dictionary<string, object> dict = new Dictionary<string, object>();
473 int i = 0;
474 foreach (ExtendedGroupRoleMembersData rm in rmembers)
475 dict["rm-" + i++] = GroupsDataUtils.GroupRoleMembersData(rm);
476
477 result["RESULT"] = dict;
478 }
479 }
480
481 string xmlString = ServerUtils.BuildXmlResponse(result);
482
483 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
484 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
485 }
486
487 byte[] HandleAgentRole(Dictionary<string, object> request)
488 {
489 Dictionary<string, object> result = new Dictionary<string, object>();
490
491 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("RoleID") ||
492 !request.ContainsKey("AgentID") || !request.ContainsKey("OP"))
493 NullResult(result, "Bad network data");
494
495 else
496 {
497 string op = request["OP"].ToString();
498 string reason = string.Empty;
499
500 bool success = false;
501 if (op == "ADD")
502 success = m_GroupsService.AddAgentToGroupRole(request["RequestingAgentID"].ToString(), request["AgentID"].ToString(),
503 new UUID(request["GroupID"].ToString()), new UUID(request["RoleID"].ToString()));
504
505 else if (op == "DELETE")
506 success = m_GroupsService.RemoveAgentFromGroupRole(request["RequestingAgentID"].ToString(), request["AgentID"].ToString(),
507 new UUID(request["GroupID"].ToString()), new UUID(request["RoleID"].ToString()));
508
509 result["RESULT"] = success.ToString();
510 }
511
512 string xmlString = ServerUtils.BuildXmlResponse(result);
513
514 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
515 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
516 }
517
518 byte[] HandleGetAgentRoles(Dictionary<string, object> request)
519 {
520 Dictionary<string, object> result = new Dictionary<string, object>();
521
522 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("AgentID"))
523 NullResult(result, "Bad network data");
524 else
525 {
526 UUID groupID = new UUID(request["GroupID"].ToString());
527 string agentID = request["AgentID"].ToString();
528 string requestingAgentID = request["RequestingAgentID"].ToString();
529
530 List<GroupRolesData> roles = m_GroupsService.GetAgentGroupRoles(requestingAgentID, agentID, groupID);
531 if (roles == null || (roles != null && roles.Count == 0))
532 {
533 NullResult(result, "No members");
534 }
535 else
536 {
537 Dictionary<string, object> dict = new Dictionary<string, object>();
538 int i = 0;
539 foreach (GroupRolesData r in roles)
540 dict["r-" + i++] = GroupsDataUtils.GroupRolesData(r);
541
542 result["RESULT"] = dict;
543 }
544 }
545
546 string xmlString = ServerUtils.BuildXmlResponse(result);
547
548 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
549 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
550 }
551
552 byte[] HandleSetActive(Dictionary<string, object> request)
553 {
554 Dictionary<string, object> result = new Dictionary<string, object>();
555
556 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") ||
557 !request.ContainsKey("AgentID") || !request.ContainsKey("OP"))
558 {
559 NullResult(result, "Bad network data");
560 string xmlString = ServerUtils.BuildXmlResponse(result);
561 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
562 }
563 else
564 {
565 string op = request["OP"].ToString();
566 string reason = string.Empty;
567
568 if (op == "GROUP")
569 {
570 ExtendedGroupMembershipData group = m_GroupsService.SetAgentActiveGroup(request["RequestingAgentID"].ToString(),
571 request["AgentID"].ToString(), new UUID(request["GroupID"].ToString()));
572
573 if (group == null)
574 NullResult(result, "Internal error");
575 else
576 result["RESULT"] = GroupsDataUtils.GroupMembershipData(group);
577
578 string xmlString = ServerUtils.BuildXmlResponse(result);
579
580 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
581 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
582
583 }
584 else if (op == "ROLE" && request.ContainsKey("RoleID"))
585 {
586 m_GroupsService.SetAgentActiveGroupRole(request["RequestingAgentID"].ToString(), request["AgentID"].ToString(),
587 new UUID(request["GroupID"].ToString()), new UUID(request["RoleID"].ToString()));
588 result["RESULT"] = "true";
589 }
590
591 return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result));
592 }
593
594 }
595
596 byte[] HandleUpdateMembership(Dictionary<string, object> request)
597 {
598 Dictionary<string, object> result = new Dictionary<string, object>();
599
600 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("AgentID") || !request.ContainsKey("GroupID") ||
601 !request.ContainsKey("AcceptNotices") || !request.ContainsKey("ListInProfile"))
602 NullResult(result, "Bad network data");
603
604 else
605 {
606 m_GroupsService.UpdateMembership(request["RequestingAgentID"].ToString(), request["AgentID"].ToString(), new UUID(request["GroupID"].ToString()),
607 bool.Parse(request["AcceptNotices"].ToString()), bool.Parse(request["ListInProfile"].ToString()));
608
609 result["RESULT"] = "true";
610 }
611
612 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
613 return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result));
614 }
615
616 byte[] HandleInvite(Dictionary<string, object> request)
617 {
618 Dictionary<string, object> result = new Dictionary<string, object>();
619
620 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("InviteID"))
621 {
622 NullResult(result, "Bad network data");
623 string xmlString = ServerUtils.BuildXmlResponse(result);
624 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
625 }
626 else
627 {
628 string op = request["OP"].ToString();
629 string reason = string.Empty;
630
631 if (op == "ADD" && request.ContainsKey("GroupID") && request.ContainsKey("RoleID") && request.ContainsKey("AgentID"))
632 {
633 bool success = m_GroupsService.AddAgentToGroupInvite(request["RequestingAgentID"].ToString(),
634 new UUID(request["InviteID"].ToString()), new UUID(request["GroupID"].ToString()),
635 new UUID(request["RoleID"].ToString()), request["AgentID"].ToString());
636
637 result["RESULT"] = success.ToString();
638 return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result));
639
640 }
641 else if (op == "DELETE")
642 {
643 m_GroupsService.RemoveAgentToGroupInvite(request["RequestingAgentID"].ToString(), new UUID(request["InviteID"].ToString()));
644 result["RESULT"] = "true";
645 return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result));
646 }
647 else if (op == "GET")
648 {
649 GroupInviteInfo invite = m_GroupsService.GetAgentToGroupInvite(request["RequestingAgentID"].ToString(),
650 new UUID(request["InviteID"].ToString()));
651
652 result["RESULT"] = GroupsDataUtils.GroupInviteInfo(invite);
653 return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result));
654 }
655
656 NullResult(result, "Bad OP in request");
657 return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result));
658 }
659
660 }
661
662 byte[] HandleAddNotice(Dictionary<string, object> request)
663 {
664 Dictionary<string, object> result = new Dictionary<string, object>();
665
666 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("NoticeID") ||
667 !request.ContainsKey("FromName") || !request.ContainsKey("Subject") || !request.ContainsKey("Message") ||
668 !request.ContainsKey("HasAttachment"))
669 NullResult(result, "Bad network data");
670
671 else
672 {
673
674 bool hasAtt = bool.Parse(request["HasAttachment"].ToString());
675 byte attType = 0;
676 string attName = string.Empty;
677 string attOwner = string.Empty;
678 UUID attItem = UUID.Zero;
679 if (request.ContainsKey("AttachmentType"))
680 attType = byte.Parse(request["AttachmentType"].ToString());
681 if (request.ContainsKey("AttachmentName"))
682 attName = request["AttachmentName"].ToString();
683 if (request.ContainsKey("AttachmentItemID"))
684 attItem = new UUID(request["AttachmentItemID"].ToString());
685 if (request.ContainsKey("AttachmentOwnerID"))
686 attOwner = request["AttachmentOwnerID"].ToString();
687
688 bool success = m_GroupsService.AddGroupNotice(request["RequestingAgentID"].ToString(), new UUID(request["GroupID"].ToString()),
689 new UUID(request["NoticeID"].ToString()), request["FromName"].ToString(), request["Subject"].ToString(),
690 request["Message"].ToString(), hasAtt, attType, attName, attItem, attOwner);
691
692 result["RESULT"] = success.ToString();
693 }
694
695 string xmlString = ServerUtils.BuildXmlResponse(result);
696
697 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
698 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
699 }
700
701 byte[] HandleGetNotices(Dictionary<string, object> request)
702 {
703 Dictionary<string, object> result = new Dictionary<string, object>();
704
705 if (!request.ContainsKey("RequestingAgentID"))
706 NullResult(result, "Bad network data");
707
708 else if (request.ContainsKey("NoticeID")) // just one
709 {
710 GroupNoticeInfo notice = m_GroupsService.GetGroupNotice(request["RequestingAgentID"].ToString(), new UUID(request["NoticeID"].ToString()));
711
712 if (notice == null)
713 NullResult(result, "NO such notice");
714 else
715 result["RESULT"] = GroupsDataUtils.GroupNoticeInfo(notice);
716
717 }
718 else if (request.ContainsKey("GroupID")) // all notices for group
719 {
720 List<ExtendedGroupNoticeData> notices = m_GroupsService.GetGroupNotices(request["RequestingAgentID"].ToString(), new UUID(request["GroupID"].ToString()));
721
722 if (notices == null || (notices != null && notices.Count == 0))
723 NullResult(result, "No notices");
724 else
725 {
726 Dictionary<string, object> dict = new Dictionary<string, object>();
727 int i = 0;
728 foreach (ExtendedGroupNoticeData n in notices)
729 dict["n-" + i++] = GroupsDataUtils.GroupNoticeData(n);
730
731 result["RESULT"] = dict;
732 }
733
734 }
735 else
736 NullResult(result, "Bad OP in request");
737
738 string xmlString = ServerUtils.BuildXmlResponse(result);
739 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
740 }
741
742
743 #region Helpers
744
745 private void NullResult(Dictionary<string, object> result, string reason)
746 {
747 result["RESULT"] = "NULL";
748 result["REASON"] = reason;
749 }
750
751 private byte[] FailureResult()
752 {
753 Dictionary<string, object> result = new Dictionary<string, object>();
754 NullResult(result, "Unknown method");
755 string xmlString = ServerUtils.BuildXmlResponse(result);
756 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
757 }
758 #endregion
759 }
760}
diff --git a/OpenSim/Addons/Groups/RemoteConnectorCacheWrapper.cs b/OpenSim/Addons/Groups/RemoteConnectorCacheWrapper.cs
new file mode 100644
index 0000000..f789626
--- /dev/null
+++ b/OpenSim/Addons/Groups/RemoteConnectorCacheWrapper.cs
@@ -0,0 +1,824 @@
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.Generic;
30using System.Reflection;
31using System.Threading;
32
33using OpenSim.Framework;
34using OpenSim.Region.Framework.Interfaces;
35
36using OpenMetaverse;
37
38namespace OpenSim.Groups
39{
40 public delegate ExtendedGroupRecord GroupRecordDelegate();
41 public delegate GroupMembershipData GroupMembershipDelegate();
42 public delegate List<GroupMembershipData> GroupMembershipListDelegate();
43 public delegate List<ExtendedGroupMembersData> GroupMembersListDelegate();
44 public delegate List<GroupRolesData> GroupRolesListDelegate();
45 public delegate List<ExtendedGroupRoleMembersData> RoleMembersListDelegate();
46 public delegate GroupNoticeInfo NoticeDelegate();
47 public delegate List<ExtendedGroupNoticeData> NoticeListDelegate();
48 public delegate void VoidDelegate();
49 public delegate bool BooleanDelegate();
50
51 public class RemoteConnectorCacheWrapper
52 {
53 private ForeignImporter m_ForeignImporter;
54
55 private Dictionary<string, bool> m_ActiveRequests = new Dictionary<string, bool>();
56 private const int GROUPS_CACHE_TIMEOUT = 5 * 60; // 5 minutes
57
58 // This all important cache cahces objects of different types:
59 // group-<GroupID> or group-<Name> => ExtendedGroupRecord
60 // active-<AgentID> => GroupMembershipData
61 // membership-<AgentID>-<GroupID> => GroupMembershipData
62 // memberships-<AgentID> => List<GroupMembershipData>
63 // members-<RequestingAgentID>-<GroupID> => List<ExtendedGroupMembersData>
64 // role-<RoleID> => GroupRolesData
65 // roles-<GroupID> => List<GroupRolesData> ; all roles in the group
66 // roles-<GroupID>-<AgentID> => List<GroupRolesData> ; roles that the agent has
67 // rolemembers-<RequestingAgentID>-<GroupID> => List<ExtendedGroupRoleMembersData>
68 // notice-<noticeID> => GroupNoticeInfo
69 // notices-<GroupID> => List<ExtendedGroupNoticeData>
70 private ExpiringCache<string, object> m_Cache = new ExpiringCache<string, object>();
71
72 public RemoteConnectorCacheWrapper(IUserManagement uman)
73 {
74 m_ForeignImporter = new ForeignImporter(uman);
75 }
76
77 public UUID CreateGroup(UUID RequestingAgentID, GroupRecordDelegate d)
78 {
79 //m_log.DebugFormat("[Groups.RemoteConnector]: Creating group {0}", name);
80 //reason = string.Empty;
81
82 //ExtendedGroupRecord group = m_GroupsService.CreateGroup(RequestingAgentID.ToString(), name, charter, showInList, insigniaID,
83 // membershipFee, openEnrollment, allowPublish, maturePublish, founderID, out reason);
84 ExtendedGroupRecord group = d();
85
86 if (group == null)
87 return UUID.Zero;
88
89 if (group.GroupID != UUID.Zero)
90 lock (m_Cache)
91 {
92 m_Cache.Add("group-" + group.GroupID.ToString(), group, GROUPS_CACHE_TIMEOUT);
93 if (m_Cache.Contains("memberships-" + RequestingAgentID.ToString()))
94 m_Cache.Remove("memberships-" + RequestingAgentID.ToString());
95 }
96
97 return group.GroupID;
98 }
99
100 public bool UpdateGroup(UUID groupID, GroupRecordDelegate d)
101 {
102 //reason = string.Empty;
103 //ExtendedGroupRecord group = m_GroupsService.UpdateGroup(RequestingAgentID, groupID, charter, showInList, insigniaID, membershipFee, openEnrollment, allowPublish, maturePublish);
104 ExtendedGroupRecord group = d();
105
106 if (group != null && group.GroupID != UUID.Zero)
107 lock (m_Cache)
108 m_Cache.AddOrUpdate("group-" + group.GroupID.ToString(), group, GROUPS_CACHE_TIMEOUT);
109 return true;
110 }
111
112 public ExtendedGroupRecord GetGroupRecord(string RequestingAgentID, UUID GroupID, string GroupName, GroupRecordDelegate d)
113 {
114 //if (GroupID == UUID.Zero && (GroupName == null || GroupName != null && GroupName == string.Empty))
115 // return null;
116
117 object group = null;
118 bool firstCall = false;
119 string cacheKey = "group-";
120 if (GroupID != UUID.Zero)
121 cacheKey += GroupID.ToString();
122 else
123 cacheKey += GroupName;
124
125 //m_log.DebugFormat("[XXX]: GetGroupRecord {0}", cacheKey);
126
127 while (true)
128 {
129 lock (m_Cache)
130 {
131 if (m_Cache.TryGetValue(cacheKey, out group))
132 {
133 //m_log.DebugFormat("[XXX]: GetGroupRecord {0} cached!", cacheKey);
134 return (ExtendedGroupRecord)group;
135 }
136
137 // not cached
138 if (!m_ActiveRequests.ContainsKey(cacheKey))
139 {
140 m_ActiveRequests.Add(cacheKey, true);
141 firstCall = true;
142 }
143 }
144
145 if (firstCall)
146 {
147 //group = m_GroupsService.GetGroupRecord(RequestingAgentID, GroupID, GroupName);
148 group = d();
149
150 lock (m_Cache)
151 {
152 m_Cache.AddOrUpdate(cacheKey, group, GROUPS_CACHE_TIMEOUT);
153 m_ActiveRequests.Remove(cacheKey);
154 return (ExtendedGroupRecord)group;
155 }
156 }
157 else
158 Thread.Sleep(50);
159 }
160 }
161
162 public bool AddAgentToGroup(string RequestingAgentID, string AgentID, UUID GroupID, GroupMembershipDelegate d)
163 {
164 GroupMembershipData membership = d();
165 if (membership == null)
166 return false;
167
168 lock (m_Cache)
169 {
170 // first, remove everything! add a user is a heavy-duty op
171 m_Cache.Clear();
172
173 m_Cache.AddOrUpdate("active-" + AgentID.ToString(), membership, GROUPS_CACHE_TIMEOUT);
174 m_Cache.AddOrUpdate("membership-" + AgentID.ToString() + "-" + GroupID.ToString(), membership, GROUPS_CACHE_TIMEOUT);
175 }
176
177
178 return true;
179 }
180
181 public void RemoveAgentFromGroup(string RequestingAgentID, string AgentID, UUID GroupID, VoidDelegate d)
182 {
183 d();
184
185 lock (m_Cache)
186 {
187 string cacheKey = "active-" + AgentID.ToString();
188 if (m_Cache.Contains(cacheKey))
189 m_Cache.Remove(cacheKey);
190
191 cacheKey = "memberships-" + AgentID.ToString();
192 if (m_Cache.Contains(cacheKey))
193 m_Cache.Remove(cacheKey);
194
195 cacheKey = "membership-" + AgentID.ToString() + "-" + GroupID.ToString();
196 if (m_Cache.Contains(cacheKey))
197 m_Cache.Remove(cacheKey);
198
199 cacheKey = "members-" + RequestingAgentID.ToString() + "-" + GroupID.ToString();
200 if (m_Cache.Contains(cacheKey))
201 m_Cache.Remove(cacheKey);
202
203 cacheKey = "roles-" + "-" + GroupID.ToString() + "-" + AgentID.ToString();
204 if (m_Cache.Contains(cacheKey))
205 m_Cache.Remove(cacheKey);
206 }
207 }
208
209 public void SetAgentActiveGroup(string AgentID, GroupMembershipDelegate d)
210 {
211 GroupMembershipData activeGroup = d();
212 if (activeGroup != null)
213 {
214 string cacheKey = "active-" + AgentID.ToString();
215 lock (m_Cache)
216 if (m_Cache.Contains(cacheKey))
217 m_Cache.AddOrUpdate(cacheKey, activeGroup, GROUPS_CACHE_TIMEOUT);
218 }
219 }
220
221 public ExtendedGroupMembershipData GetAgentActiveMembership(string AgentID, GroupMembershipDelegate d)
222 {
223 object membership = null;
224 bool firstCall = false;
225 string cacheKey = "active-" + AgentID.ToString();
226
227 //m_log.DebugFormat("[XXX]: GetAgentActiveMembership {0}", cacheKey);
228
229 while (true)
230 {
231 lock (m_Cache)
232 {
233 if (m_Cache.TryGetValue(cacheKey, out membership))
234 {
235 //m_log.DebugFormat("[XXX]: GetAgentActiveMembership {0} cached!", cacheKey);
236 return (ExtendedGroupMembershipData)membership;
237 }
238
239 // not cached
240 if (!m_ActiveRequests.ContainsKey(cacheKey))
241 {
242 m_ActiveRequests.Add(cacheKey, true);
243 firstCall = true;
244 }
245 }
246
247 if (firstCall)
248 {
249 membership = d();
250
251 lock (m_Cache)
252 {
253 m_Cache.AddOrUpdate(cacheKey, membership, GROUPS_CACHE_TIMEOUT);
254 m_ActiveRequests.Remove(cacheKey);
255 return (ExtendedGroupMembershipData)membership;
256 }
257 }
258 else
259 Thread.Sleep(50);
260 }
261
262 }
263
264 public ExtendedGroupMembershipData GetAgentGroupMembership(string AgentID, UUID GroupID, GroupMembershipDelegate d)
265 {
266 object membership = null;
267 bool firstCall = false;
268 string cacheKey = "membership-" + AgentID.ToString() + "-" + GroupID.ToString();
269
270 //m_log.DebugFormat("[XXX]: GetAgentGroupMembership {0}", cacheKey);
271
272 while (true)
273 {
274 lock (m_Cache)
275 {
276 if (m_Cache.TryGetValue(cacheKey, out membership))
277 {
278 //m_log.DebugFormat("[XXX]: GetAgentGroupMembership {0}", cacheKey);
279 return (ExtendedGroupMembershipData)membership;
280 }
281
282 // not cached
283 if (!m_ActiveRequests.ContainsKey(cacheKey))
284 {
285 m_ActiveRequests.Add(cacheKey, true);
286 firstCall = true;
287 }
288 }
289
290 if (firstCall)
291 {
292 membership = d();
293 lock (m_Cache)
294 {
295 m_Cache.AddOrUpdate(cacheKey, membership, GROUPS_CACHE_TIMEOUT);
296 m_ActiveRequests.Remove(cacheKey);
297 return (ExtendedGroupMembershipData)membership;
298 }
299 }
300 else
301 Thread.Sleep(50);
302 }
303 }
304
305 public List<GroupMembershipData> GetAgentGroupMemberships(string AgentID, GroupMembershipListDelegate d)
306 {
307 object memberships = null;
308 bool firstCall = false;
309 string cacheKey = "memberships-" + AgentID.ToString();
310
311 //m_log.DebugFormat("[XXX]: GetAgentGroupMemberships {0}", cacheKey);
312
313 while (true)
314 {
315 lock (m_Cache)
316 {
317 if (m_Cache.TryGetValue(cacheKey, out memberships))
318 {
319 //m_log.DebugFormat("[XXX]: GetAgentGroupMemberships {0} cached!", cacheKey);
320 return (List<GroupMembershipData>)memberships;
321 }
322
323 // not cached
324 if (!m_ActiveRequests.ContainsKey(cacheKey))
325 {
326 m_ActiveRequests.Add(cacheKey, true);
327 firstCall = true;
328 }
329 }
330
331 if (firstCall)
332 {
333 memberships = d();
334 lock (m_Cache)
335 {
336 m_Cache.AddOrUpdate(cacheKey, memberships, GROUPS_CACHE_TIMEOUT);
337 m_ActiveRequests.Remove(cacheKey);
338 return (List<GroupMembershipData>)memberships;
339 }
340 }
341 else
342 Thread.Sleep(50);
343 }
344 }
345
346 public List<GroupMembersData> GetGroupMembers(string RequestingAgentID, UUID GroupID, GroupMembersListDelegate d)
347 {
348 object members = null;
349 bool firstCall = false;
350 // we need to key in also on the requester, because different ppl have different view privileges
351 string cacheKey = "members-" + RequestingAgentID.ToString() + "-" + GroupID.ToString();
352
353 //m_log.DebugFormat("[XXX]: GetGroupMembers {0}", cacheKey);
354
355 while (true)
356 {
357 lock (m_Cache)
358 {
359 if (m_Cache.TryGetValue(cacheKey, out members))
360 {
361 List<ExtendedGroupMembersData> xx = (List<ExtendedGroupMembersData>)members;
362 return xx.ConvertAll<GroupMembersData>(new Converter<ExtendedGroupMembersData, GroupMembersData>(m_ForeignImporter.ConvertGroupMembersData));
363 }
364
365 // not cached
366 if (!m_ActiveRequests.ContainsKey(cacheKey))
367 {
368 m_ActiveRequests.Add(cacheKey, true);
369 firstCall = true;
370 }
371 }
372
373 if (firstCall)
374 {
375 List<ExtendedGroupMembersData> _members = d();
376
377 if (_members != null && _members.Count > 0)
378 members = _members.ConvertAll<GroupMembersData>(new Converter<ExtendedGroupMembersData, GroupMembersData>(m_ForeignImporter.ConvertGroupMembersData));
379 else
380 members = new List<GroupMembersData>();
381
382 lock (m_Cache)
383 {
384 //m_Cache.AddOrUpdate(cacheKey, members, GROUPS_CACHE_TIMEOUT);
385 m_Cache.AddOrUpdate(cacheKey, _members, GROUPS_CACHE_TIMEOUT);
386 m_ActiveRequests.Remove(cacheKey);
387
388 return (List<GroupMembersData>)members;
389 }
390 }
391 else
392 Thread.Sleep(50);
393 }
394 }
395
396 public bool AddGroupRole(UUID roleID, string description, string name, ulong powers, string title, BooleanDelegate d)
397 {
398 if (d())
399 {
400 GroupRolesData role = new GroupRolesData();
401 role.Description = description;
402 role.Members = 0;
403 role.Name = name;
404 role.Powers = powers;
405 role.RoleID = roleID;
406 role.Title = title;
407
408 lock (m_Cache)
409 m_Cache.AddOrUpdate("role-" + roleID.ToString(), role, GROUPS_CACHE_TIMEOUT);
410
411 return true;
412 }
413
414 return false;
415 }
416
417 public bool UpdateGroupRole(UUID groupID, UUID roleID, string name, string description, string title, ulong powers, BooleanDelegate d)
418 {
419 if (d())
420 {
421 object role;
422 lock (m_Cache)
423 if (m_Cache.TryGetValue("role-" + roleID.ToString(), out role))
424 {
425 GroupRolesData r = (GroupRolesData)role;
426 r.Description = description;
427 r.Name = name;
428 r.Powers = powers;
429 r.Title = title;
430
431 m_Cache.Update("role-" + roleID.ToString(), r, GROUPS_CACHE_TIMEOUT);
432 }
433 return true;
434 }
435 else
436 {
437 lock (m_Cache)
438 {
439 if (m_Cache.Contains("role-" + roleID.ToString()))
440 m_Cache.Remove("role-" + roleID.ToString());
441
442 // also remove these lists, because they will have an outdated role
443 if (m_Cache.Contains("roles-" + groupID.ToString()))
444 m_Cache.Remove("roles-" + groupID.ToString());
445
446 }
447
448 return false;
449 }
450 }
451
452 public void RemoveGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, VoidDelegate d)
453 {
454 d();
455
456 lock (m_Cache)
457 {
458 if (m_Cache.Contains("role-" + roleID.ToString()))
459 m_Cache.Remove("role-" + roleID.ToString());
460
461 // also remove the list, because it will have an removed role
462 if (m_Cache.Contains("roles-" + groupID.ToString()))
463 m_Cache.Remove("roles-" + groupID.ToString());
464
465 if (m_Cache.Contains("roles-" + groupID.ToString() + "-" + RequestingAgentID.ToString()))
466 m_Cache.Remove("roles-" + groupID.ToString() + "-" + RequestingAgentID.ToString());
467
468 if (m_Cache.Contains("rolemembers-" + RequestingAgentID.ToString() + "-" + groupID.ToString()))
469 m_Cache.Remove("rolemembers-" + RequestingAgentID.ToString() + "-" + groupID.ToString());
470 }
471 }
472
473 public List<GroupRolesData> GetGroupRoles(string RequestingAgentID, UUID GroupID, GroupRolesListDelegate d)
474 {
475 object roles = null;
476 bool firstCall = false;
477 string cacheKey = "roles-" + GroupID.ToString();
478
479 while (true)
480 {
481 lock (m_Cache)
482 {
483 if (m_Cache.TryGetValue(cacheKey, out roles))
484 return (List<GroupRolesData>)roles;
485
486 // not cached
487 if (!m_ActiveRequests.ContainsKey(cacheKey))
488 {
489 m_ActiveRequests.Add(cacheKey, true);
490 firstCall = true;
491 }
492 }
493
494 if (firstCall)
495 {
496 roles = d();
497 if (roles != null)
498 {
499 lock (m_Cache)
500 {
501 m_Cache.AddOrUpdate(cacheKey, roles, GROUPS_CACHE_TIMEOUT);
502 m_ActiveRequests.Remove(cacheKey);
503 return (List<GroupRolesData>)roles;
504 }
505 }
506 }
507 else
508 Thread.Sleep(50);
509 }
510 }
511
512 public List<GroupRoleMembersData> GetGroupRoleMembers(string RequestingAgentID, UUID GroupID, RoleMembersListDelegate d)
513 {
514 object rmembers = null;
515 bool firstCall = false;
516 // we need to key in also on the requester, because different ppl have different view privileges
517 string cacheKey = "rolemembers-" + RequestingAgentID.ToString() + "-" + GroupID.ToString();
518
519 //m_log.DebugFormat("[XXX]: GetGroupRoleMembers {0}", cacheKey);
520 while (true)
521 {
522 lock (m_Cache)
523 {
524 if (m_Cache.TryGetValue(cacheKey, out rmembers))
525 {
526 List<ExtendedGroupRoleMembersData> xx = (List<ExtendedGroupRoleMembersData>)rmembers;
527 return xx.ConvertAll<GroupRoleMembersData>(m_ForeignImporter.ConvertGroupRoleMembersData);
528 }
529
530 // not cached
531 if (!m_ActiveRequests.ContainsKey(cacheKey))
532 {
533 m_ActiveRequests.Add(cacheKey, true);
534 firstCall = true;
535 }
536 }
537
538 if (firstCall)
539 {
540 List<ExtendedGroupRoleMembersData> _rmembers = d();
541
542 if (_rmembers != null && _rmembers.Count > 0)
543 rmembers = _rmembers.ConvertAll<GroupRoleMembersData>(new Converter<ExtendedGroupRoleMembersData, GroupRoleMembersData>(m_ForeignImporter.ConvertGroupRoleMembersData));
544 else
545 rmembers = new List<GroupRoleMembersData>();
546
547 lock (m_Cache)
548 {
549 // For some strange reason, when I cache the list of GroupRoleMembersData,
550 // it gets emptied out. The TryGet gets an empty list...
551 //m_Cache.AddOrUpdate(cacheKey, rmembers, GROUPS_CACHE_TIMEOUT);
552 // Caching the list of ExtendedGroupRoleMembersData doesn't show that issue
553 // I don't get it.
554 m_Cache.AddOrUpdate(cacheKey, _rmembers, GROUPS_CACHE_TIMEOUT);
555 m_ActiveRequests.Remove(cacheKey);
556 return (List<GroupRoleMembersData>)rmembers;
557 }
558 }
559 else
560 Thread.Sleep(50);
561 }
562 }
563
564 public void AddAgentToGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID, BooleanDelegate d)
565 {
566 if (d())
567 {
568 lock (m_Cache)
569 {
570 // update the cached role
571 string cacheKey = "role-" + RoleID.ToString();
572 object obj;
573 if (m_Cache.TryGetValue(cacheKey, out obj))
574 {
575 GroupRolesData r = (GroupRolesData)obj;
576 r.Members++;
577 }
578
579 // add this agent to the list of role members
580 cacheKey = "rolemembers-" + RequestingAgentID.ToString() + "-" + GroupID.ToString();
581 if (m_Cache.TryGetValue(cacheKey, out obj))
582 {
583 try
584 {
585 // This may throw an exception, in which case the agentID is not a UUID but a full ID
586 // In that case, let's just remove the whoe things from the cache
587 UUID id = new UUID(AgentID);
588 List<ExtendedGroupRoleMembersData> xx = (List<ExtendedGroupRoleMembersData>)obj;
589 List<GroupRoleMembersData> rmlist = xx.ConvertAll<GroupRoleMembersData>(m_ForeignImporter.ConvertGroupRoleMembersData);
590 GroupRoleMembersData rm = new GroupRoleMembersData();
591 rm.MemberID = id;
592 rm.RoleID = RoleID;
593 rmlist.Add(rm);
594 }
595 catch
596 {
597 m_Cache.Remove(cacheKey);
598 }
599 }
600
601 // Remove the cached info about this agent's roles
602 // because we don't have enough local info about the new role
603 cacheKey = "roles-" + GroupID.ToString() + "-" + AgentID.ToString();
604 if (m_Cache.Contains(cacheKey))
605 m_Cache.Remove(cacheKey);
606
607 }
608 }
609 }
610
611 public void RemoveAgentFromGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID, BooleanDelegate d)
612 {
613 if (d())
614 {
615 lock (m_Cache)
616 {
617 // update the cached role
618 string cacheKey = "role-" + RoleID.ToString();
619 object obj;
620 if (m_Cache.TryGetValue(cacheKey, out obj))
621 {
622 GroupRolesData r = (GroupRolesData)obj;
623 r.Members--;
624 }
625
626 cacheKey = "roles-" + GroupID.ToString() + "-" + AgentID.ToString();
627 if (m_Cache.Contains(cacheKey))
628 m_Cache.Remove(cacheKey);
629
630 cacheKey = "rolemembers-" + RequestingAgentID.ToString() + "-" + GroupID.ToString();
631 if (m_Cache.Contains(cacheKey))
632 m_Cache.Remove(cacheKey);
633 }
634 }
635 }
636
637 public List<GroupRolesData> GetAgentGroupRoles(string RequestingAgentID, string AgentID, UUID GroupID, GroupRolesListDelegate d)
638 {
639 object roles = null;
640 bool firstCall = false;
641 string cacheKey = "roles-" + GroupID.ToString() + "-" + AgentID.ToString();
642
643 //m_log.DebugFormat("[XXX]: GetAgentGroupRoles {0}", cacheKey);
644
645 while (true)
646 {
647 lock (m_Cache)
648 {
649 if (m_Cache.TryGetValue(cacheKey, out roles))
650 {
651 //m_log.DebugFormat("[XXX]: GetAgentGroupRoles {0} cached!", cacheKey);
652 return (List<GroupRolesData>)roles;
653 }
654
655 // not cached
656 if (!m_ActiveRequests.ContainsKey(cacheKey))
657 {
658 m_ActiveRequests.Add(cacheKey, true);
659 firstCall = true;
660 }
661 }
662
663 if (firstCall)
664 {
665 roles = d();
666 lock (m_Cache)
667 {
668 m_Cache.AddOrUpdate(cacheKey, roles, GROUPS_CACHE_TIMEOUT);
669 m_ActiveRequests.Remove(cacheKey);
670 return (List<GroupRolesData>)roles;
671 }
672 }
673 else
674 Thread.Sleep(50);
675 }
676 }
677
678 public void SetAgentActiveGroupRole(string AgentID, UUID GroupID, VoidDelegate d)
679 {
680 d();
681
682 lock (m_Cache)
683 {
684 // Invalidate cached info, because it has ActiveRoleID and Powers
685 string cacheKey = "membership-" + AgentID.ToString() + "-" + GroupID.ToString();
686 if (m_Cache.Contains(cacheKey))
687 m_Cache.Remove(cacheKey);
688
689 cacheKey = "memberships-" + AgentID.ToString();
690 if (m_Cache.Contains(cacheKey))
691 m_Cache.Remove(cacheKey);
692 }
693 }
694
695 public void UpdateMembership(string AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile, VoidDelegate d)
696 {
697 d();
698
699 lock (m_Cache)
700 {
701 string cacheKey = "membership-" + AgentID.ToString() + "-" + GroupID.ToString();
702 if (m_Cache.Contains(cacheKey))
703 m_Cache.Remove(cacheKey);
704
705 cacheKey = "memberships-" + AgentID.ToString();
706 if (m_Cache.Contains(cacheKey))
707 m_Cache.Remove(cacheKey);
708
709 cacheKey = "active-" + AgentID.ToString();
710 object m = null;
711 if (m_Cache.TryGetValue(cacheKey, out m))
712 {
713 GroupMembershipData membership = (GroupMembershipData)m;
714 membership.ListInProfile = ListInProfile;
715 membership.AcceptNotices = AcceptNotices;
716 }
717 }
718 }
719
720 public bool AddGroupNotice(UUID groupID, UUID noticeID, GroupNoticeInfo notice, BooleanDelegate d)
721 {
722 if (d())
723 {
724 lock (m_Cache)
725 {
726 m_Cache.AddOrUpdate("notice-" + noticeID.ToString(), notice, GROUPS_CACHE_TIMEOUT);
727 string cacheKey = "notices-" + groupID.ToString();
728 if (m_Cache.Contains(cacheKey))
729 m_Cache.Remove(cacheKey);
730
731 }
732
733 return true;
734 }
735
736 return false;
737 }
738
739 public GroupNoticeInfo GetGroupNotice(UUID noticeID, NoticeDelegate d)
740 {
741 object notice = null;
742 bool firstCall = false;
743 string cacheKey = "notice-" + noticeID.ToString();
744
745 //m_log.DebugFormat("[XXX]: GetAgentGroupRoles {0}", cacheKey);
746
747 while (true)
748 {
749 lock (m_Cache)
750 {
751 if (m_Cache.TryGetValue(cacheKey, out notice))
752 {
753 return (GroupNoticeInfo)notice;
754 }
755
756 // not cached
757 if (!m_ActiveRequests.ContainsKey(cacheKey))
758 {
759 m_ActiveRequests.Add(cacheKey, true);
760 firstCall = true;
761 }
762 }
763
764 if (firstCall)
765 {
766 GroupNoticeInfo _notice = d();
767
768 lock (m_Cache)
769 {
770 m_Cache.AddOrUpdate(cacheKey, _notice, GROUPS_CACHE_TIMEOUT);
771 m_ActiveRequests.Remove(cacheKey);
772 return _notice;
773 }
774 }
775 else
776 Thread.Sleep(50);
777 }
778 }
779
780 public List<ExtendedGroupNoticeData> GetGroupNotices(UUID GroupID, NoticeListDelegate d)
781 {
782 object notices = null;
783 bool firstCall = false;
784 string cacheKey = "notices-" + GroupID.ToString();
785
786 //m_log.DebugFormat("[XXX]: GetGroupNotices {0}", cacheKey);
787
788 while (true)
789 {
790 lock (m_Cache)
791 {
792 if (m_Cache.TryGetValue(cacheKey, out notices))
793 {
794 //m_log.DebugFormat("[XXX]: GetGroupNotices {0} cached!", cacheKey);
795 return (List<ExtendedGroupNoticeData>)notices;
796 }
797
798 // not cached
799 if (!m_ActiveRequests.ContainsKey(cacheKey))
800 {
801 m_ActiveRequests.Add(cacheKey, true);
802 firstCall = true;
803 }
804 }
805
806 if (firstCall)
807 {
808 notices = d();
809
810 lock (m_Cache)
811 {
812 m_Cache.AddOrUpdate(cacheKey, notices, GROUPS_CACHE_TIMEOUT);
813 m_ActiveRequests.Remove(cacheKey);
814 return (List<ExtendedGroupNoticeData>)notices;
815 }
816 }
817 else
818 Thread.Sleep(50);
819 }
820 }
821
822
823 }
824}