1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
/*
* UserRequestHandlerGroup.cpp
*
* Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UserRequestHandlerGroup.h"
#include "../Application.h"
#include <Common/UserManager.h>
namespace Mad {
namespace Server {
namespace RequestHandlers {
void UserRequestHandlerGroup::handleUserListRequest(boost::shared_ptr<const Common::XmlPacket> packet _UNUSED_PARAMETER_, Common::XmlPacket *ret,
Common::Connection *connection _UNUSED_PARAMETER_) {
boost::shared_ptr<const std::map<unsigned long, Common::UserInfo> > info = application->getUserManager()->getUserList();
ret->setType("OK");
Common::XmlPacket::List *list = ret->createList("users");
for(std::map<unsigned long, Common::UserInfo>::const_iterator user = info->begin(); user != info->end(); ++user) {
Common::XmlPacket::List::iterator entry = list->addEntry();
entry->set("uid", user->second.getUid());
entry->set("gid", user->second.getGid());
entry->set("username", user->second.getUsername());
entry->set("fullName", user->second.getFullName());
}
}
void UserRequestHandlerGroup::handleUserInfoRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret,
Common::Connection *connection _UNUSED_PARAMETER_) {
boost::shared_ptr<const Common::UserInfo> info;
unsigned long uid = packet->get<unsigned long>("uid");
if(uid)
info = application->getUserManager()->getUserInfo(uid);
else
info = application->getUserManager()->getUserInfoByName(packet->get<const std::string&>("name"));
ret->setType("OK");
ret->set("uid", info->getUid());
ret->set("gid", info->getGid());
ret->set("username", info->getUsername());
ret->set("fullName", info->getFullName());
}
void UserRequestHandlerGroup::handleUserGroupListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret,
Common::Connection *connection _UNUSED_PARAMETER_) {
boost::shared_ptr<const std::set<unsigned long> > groups = application->getUserManager()->getUserGroupList(packet->get<unsigned long>("uid"));
ret->setType("OK");
Common::XmlPacket::List *list = ret->createList("groups");
for(std::set<unsigned long>::const_iterator group = groups->begin(); group != groups->end(); ++group) {
Common::XmlPacket::List::iterator entry = list->addEntry();
entry->set("gid", *group);
}
}
void UserRequestHandlerGroup::handleGroupListRequest(boost::shared_ptr<const Common::XmlPacket> packet _UNUSED_PARAMETER_, Common::XmlPacket *ret,
Common::Connection *connection _UNUSED_PARAMETER_) {
boost::shared_ptr<const std::map<unsigned long, Common::GroupInfo> > info = application->getUserManager()->getGroupList();
ret->setType("OK");
Common::XmlPacket::List *list = ret->createList("groups");
for(std::map<unsigned long, Common::GroupInfo>::const_iterator group = info->begin(); group != info->end(); ++group) {
Common::XmlPacket::List::iterator entry = list->addEntry();
entry->set("gid", group->second.getGid());
entry->set("name", group->second.getName());
}
}
void UserRequestHandlerGroup::handleGroupInfoRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret,
Common::Connection *connection _UNUSED_PARAMETER_) {
boost::shared_ptr<const Common::GroupInfo> info;
unsigned long gid = packet->get<unsigned long>("gid");
if(gid)
info = application->getUserManager()->getGroupInfo(gid);
else
info = application->getUserManager()->getGroupInfoByName(packet->get<const std::string&>("name"));
ret->setType("OK");
ret->set("gid", info->getGid());
ret->set("name", info->getName());
}
void UserRequestHandlerGroup::handleGroupUserListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret,
Common::Connection *connection _UNUSED_PARAMETER_) {
boost::shared_ptr<const std::set<unsigned long> > users = application->getUserManager()->getGroupUserList(packet->get<unsigned long>("gid"));
ret->setType("OK");
Common::XmlPacket::List *list = ret->createList("users");
for(std::set<unsigned long>::const_iterator user = users->begin(); user != users->end(); ++user) {
Common::XmlPacket::List::iterator entry = list->addEntry();
entry->set("uid", *user);
}
}
void UserRequestHandlerGroup::handleFullUserGroupListRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret, Common::Connection *connection) {
boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > userGroups = application->getUserManager()->getFullUserGroupList();
ret->setType("OK");
Common::XmlPacket::List *list = ret->createList("userGroupList");
for(std::map<unsigned long, unsigned long>::const_iterator userGroup = userGroups->begin(); userGroup != userGroups->end(); ++userGroup) {
Common::XmlPacket::List::iterator entry = list->addEntry();
entry->set("uid", userGroup->first);
entry->set("gid", userGroup->second);
}
}
UserRequestHandlerGroup::UserRequestHandlerGroup(Application *application0) : application(application0) {
registerHandler("ListUsers", boost::bind(&UserRequestHandlerGroup::handleUserListRequest, this, _1, _2, _3));
registerHandler("GetUserInfo", boost::bind(&UserRequestHandlerGroup::handleUserInfoRequest, this, _1, _2, _3));
registerHandler("ListUserGroups", boost::bind(&UserRequestHandlerGroup::handleUserGroupListRequest, this, _1, _2, _3));
registerHandler("ListGroups", boost::bind(&UserRequestHandlerGroup::handleGroupListRequest, this, _1, _2, _3));
registerHandler("GetGroupInfo", boost::bind(&UserRequestHandlerGroup::handleGroupInfoRequest, this, _1, _2, _3));
registerHandler("ListGroupUsers", boost::bind(&UserRequestHandlerGroup::handleGroupUserListRequest, this, _1, _2, _3));
registerHandler("GetFullUserGroupList", boost::bind(&UserRequestHandlerGroup::handleFullUserGroupListRequest, this, _1, _2, _3));
}
}
}
}
|