./ct_report/coverage/service_admin_extra_sessions.COVER.html

1 %%%-------------------------------------------------------------------
2 %%% File : service_admin_extra_sessions.erl
3 %%% Author : Badlop <badlop@process-one.net>, Piotr Nosek <piotr.nosek@erlang-solutions.com>
4 %%% Purpose : Contributed administrative functions and commands
5 %%% Created : 10 Aug 2008 by Badlop <badlop@process-one.net>
6 %%%
7 %%%
8 %%% ejabberd, Copyright (C) 2002-2008 ProcessOne
9 %%%
10 %%% This program is free software; you can redistribute it and/or
11 %%% modify it under the terms of the GNU General Public License as
12 %%% published by the Free Software Foundation; either version 2 of the
13 %%% License, or (at your option) any later version.
14 %%%
15 %%% This program is distributed in the hope that it will be useful,
16 %%% but WITHOUT ANY WARRANTY; without even the implied warranty of
17 %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 %%% General Public License for more details.
19 %%%
20 %%% You should have received a copy of the GNU General Public License
21 %%% along with this program; if not, write to the Free Software
22 %%% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 %%%
24 %%%-------------------------------------------------------------------
25
26 -module(service_admin_extra_sessions).
27 -author('badlop@process-one.net').
28
29 -export([
30 commands/0,
31
32 num_resources/2,
33 resource_num/3,
34 kick_session/2,
35 kick_session/4,
36 status_num/2, status_num/1,
37 status_list/2, status_list/1,
38 connected_users_info/0,
39 connected_users_info/1,
40 set_presence/7,
41 user_sessions_info/2
42 ]).
43
44 -ignore_xref([
45 commands/0, num_resources/2, resource_num/3, kick_session/2, kick_session/4,
46 status_num/2, status_num/1, status_list/2, status_list/1,
47 connected_users_info/0, connected_users_info/1, set_presence/7,
48 user_sessions_info/2
49 ]).
50
51 -include("ejabberd_commands.hrl").
52
53 -type status() :: mongoose_session_api:status().
54
55 %%%
56 %%% Register commands
57 %%%
58
59 -spec commands() -> [ejabberd_commands:cmd(), ...].
60 commands() ->
61 164 SessionDisplay = {list,
62 {sessions, {tuple,
63 [{jid, string},
64 {connection, string},
65 {ip, string},
66 {port, integer},
67 {priority, integer},
68 {node, string},
69 {uptime, integer}
70 ]}}
71 },
72
73 164 [
74 #ejabberd_commands{name = num_resources, tags = [session],
75 desc = "Get the number of resources of a user",
76 module = ?MODULE, function = num_resources,
77 args = [{user, binary}, {host, binary}],
78 result = {resources, integer}},
79 #ejabberd_commands{name = resource_num, tags = [session],
80 desc = "Resource string of a session number",
81 module = ?MODULE, function = resource_num,
82 args = [{user, binary}, {host, binary}, {num, integer}],
83 result = {res, restuple}},
84 #ejabberd_commands{name = kick_session, tags = [session],
85 desc = "Kick a user session",
86 module = ?MODULE, function = kick_session,
87 args = [{user, binary}, {host, binary},
88 {resource, binary}, {reason, binary}],
89 result = {res, restuple}},
90 #ejabberd_commands{name = status_num_host, tags = [session, stats],
91 desc = "Number of logged users with this status in host",
92 module = ?MODULE, function = status_num,
93 args = [{host, binary}, {status, binary}],
94 result = {users, integer}},
95 #ejabberd_commands{name = status_num, tags = [session, stats],
96 desc = "Number of logged users with this status",
97 module = ?MODULE, function = status_num,
98 args = [{status, binary}],
99 result = {users, integer}},
100 #ejabberd_commands{name = status_list_host, tags = [session],
101 desc = "List of users logged in host with their statuses",
102 module = ?MODULE, function = status_list,
103 args = [{host, binary}, {status, binary}],
104 result = {users, {list,
105 {userstatus, {tuple, [
106 {user, string},
107 {host, string},
108 {resource, string},
109 {priority, integer},
110 {status, string}
111 ]}}
112 }}},
113 #ejabberd_commands{name = status_list, tags = [session],
114 desc = "List of logged users with this status",
115 module = ?MODULE, function = status_list,
116 args = [{status, binary}],
117 result = {users, {list,
118 {userstatus, {tuple, [
119 {user, string},
120 {host, string},
121 {resource, string},
122 {priority, integer},
123 {status, string}
124 ]}}
125 }}},
126 #ejabberd_commands{name = connected_users_info,
127 tags = [session],
128 desc = "List all established sessions and their information",
129 module = ?MODULE, function = connected_users_info,
130 args = [],
131 result = {connected_users_info, SessionDisplay}},
132 #ejabberd_commands{name = connected_users_vhost,
133 tags = [session],
134 desc = "Get the list of established sessions in a vhost",
135 module = ?MODULE, function = connected_users_info,
136 args = [{host, binary}],
137 result = {connected_users_vhost, SessionDisplay}},
138 #ejabberd_commands{name = user_sessions_info,
139 tags = [session],
140 desc = "Get information about all sessions of a user",
141 module = ?MODULE, function = user_sessions_info,
142 args = [{user, binary}, {host, binary}],
143 result = {user_sessions_info, SessionDisplay}},
144
145 #ejabberd_commands{name = set_presence,
146 tags = [session],
147 desc = "Set presence of a session",
148 module = ?MODULE, function = set_presence,
149 args = [{user, binary}, {host, binary},
150 {resource, binary}, {type, binary},
151 {show, binary}, {status, binary},
152 {priority, binary}],
153 result = {res, rescode}}
154 ].
155
156 %%%
157 %%% Sessions
158 %%%
159
160 -spec num_resources(jid:user(), jid:server()) -> non_neg_integer().
161 num_resources(User, Host) ->
162 1 mongoose_session_api:num_resources(User, Host).
163
164 -spec resource_num(jid:user(), jid:server(), integer()) -> mongoose_session_api:res_number_result().
165 resource_num(User, Host, Num) ->
166 1 mongoose_session_api:get_user_resource(User, Host, Num).
167
168 -spec kick_session(jid:jid(), binary()) -> mongoose_session_api:kick_session_result().
169 kick_session(JID, ReasonText) ->
170 2 mongoose_session_api:kick_session(JID, ReasonText).
171
172 -spec kick_session(jid:user(), jid:server(), jid:resource(), binary()) ->
173 mongoose_session_api:kick_session_result().
174 kick_session(User, Server, Resource, ReasonText) ->
175 1 mongoose_session_api:kick_session(User, Server, Resource, ReasonText).
176
177 -spec status_num(jid:server(), status()) -> non_neg_integer().
178 status_num(Host, Status) ->
179 2 mongoose_session_api:num_status_users(Host, Status).
180
181 -spec status_num(status()) -> non_neg_integer().
182 status_num(Status) ->
183 1 mongoose_session_api:num_status_users(Status).
184
185 -spec status_list(jid:server(), status()) -> [mongoose_session_api:status_user_info()].
186 status_list(Host, Status) ->
187 2 mongoose_session_api:list_status_users(Host, Status).
188
189 -spec status_list(binary()) -> [mongoose_session_api:status_user_info()].
190 status_list(Status) ->
191 1 mongoose_session_api:list_status_users(Status).
192
193 -spec connected_users_info() -> mongoose_session_api:list_sessions_result().
194 connected_users_info() ->
195 1 mongoose_session_api:list_sessions().
196
197 -spec connected_users_info(jid:server()) -> mongoose_session_api:list_sessions_result().
198 connected_users_info(Host) ->
199 2 mongoose_session_api:list_sessions(Host).
200
201 -spec set_presence(jid:user(), jid:server(), jid:resource(),
202 Type :: binary(), Show :: binary(), Status :: binary(),
203 Prio :: binary()) -> ok.
204 set_presence(User, Host, Resource, Type, Show, Status, Priority) ->
205 1 mongoose_session_api:set_presence(User, Host, Resource, Type, Show, Status, Priority),
206 1 ok.
207
208 -spec user_sessions_info(jid:user(), jid:server()) -> [mongoose_session_api:session_info()].
209 user_sessions_info(User, Host) ->
210 1 mongoose_session_api:list_user_sessions(User, Host).
Line Hits Source