./ct_report/coverage/service_admin_extra_private.COVER.html

1 %%%-------------------------------------------------------------------
2 %%% File : service_admin_extra_private.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_private).
27 -author('badlop@process-one.net').
28
29 -export([
30 commands/0,
31 private_get/4,
32 private_set/3
33 ]).
34
35 -ignore_xref([
36 commands/0, private_get/4, private_set/3
37 ]).
38
39 -include("mongoose.hrl").
40 -include("ejabberd_commands.hrl").
41 -include("jlib.hrl").
42 -include_lib("exml/include/exml.hrl").
43
44 %%%
45 %%% Register commands
46 %%%
47
48 -spec commands() -> [ejabberd_commands:cmd(), ...].
49 commands() ->
50 166 [
51 #ejabberd_commands{name = private_get, tags = [private],
52 desc = "Get some information from a user private storage",
53 module = ?MODULE, function = private_get,
54 args = [{user, binary}, {host, binary}, {element, binary}, {ns, binary}],
55 result = {content, string}},
56 #ejabberd_commands{name = private_set, tags = [private],
57 desc = "Set to the user private storage",
58 module = ?MODULE, function = private_set,
59 args = [{user, binary}, {host, binary}, {element, binary}],
60 result = {res, restuple}}
61 ].
62
63 %%%
64 %%% Private Storage
65 %%%
66
67 %% Example usage:
68 %% $ mongooseimctl private_set badlop localhost "\<aa\ xmlns=\'bb\'\>Cluth\</aa\>"
69 %% $ mongooseimctl private_get badlop localhost aa bb
70 %% <aa xmlns='bb'>Cluth</aa>
71
72 -spec private_get(jid:user(), jid:server(), binary(), binary()) ->
73 {not_found, string()} | string().
74 private_get(Username, Host, Element, Ns) ->
75 1 JID = jid:make(Username, Host, <<>>),
76 1 case mod_private_api:private_get(JID, Element, Ns) of
77 1 {ok, String} -> String;
78
:-(
Error -> Error
79 end.
80
81 -spec private_set(jid:user(), jid:server(),
82 ElementString :: binary()) -> {Res, string()} when
83 Res :: ok | not_found | not_loaded | parse_error.
84 private_set(Username, Host, ElementString) ->
85 2 JID = jid:make(Username, Host, <<>>),
86 2 mod_private_api:private_set(JID, ElementString).
Line Hits Source