aboutsummaryrefslogtreecommitdiff
path: root/src/gen_pubsub_node.erl
blob: a1252f9f8981c4292a2f3714eead46845d21f248 (plain) (blame)
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
%%% ====================================================================
%%% ``The contents of this file are subject to the Erlang Public License,
%%% Version 1.1, (the "License"); you may not use this file except in
%%% compliance with the License. You should have received a copy of the
%%% Erlang Public License along with this software. If not, it can be
%%% retrieved via the world wide web at http://www.erlang.org/.
%%%
%%% Software distributed under the License is distributed on an "AS IS"
%%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%%% the License for the specific language governing rights and limitations
%%% under the License.
%%%
%%% The Initial Developer of the Original Code is ProcessOne.
%%% Portions created by ProcessOne are Copyright 2006-2014, ProcessOne
%%% All Rights Reserved.''
%%% This software is copyright 2006-2014, ProcessOne.
%%%
%%%
%%% @copyright 2006-2014 ProcessOne
%%% @author Christophe Romain <christophe.romain@process-one.net>
%%%   [http://www.process-one.net/]
%%% @version {@vsn}, {@date} {@time}
%%% @end
%%% ====================================================================

%%% @private
%%% @doc <p>The module <strong>{@module}</strong> defines the PubSub node
%%% plugin behaviour. This behaviour is used to check that a PubSub plugin
%%% respects the current ejabberd PubSub plugin API.</p>

-module(gen_pubsub_node).

-include("jlib.hrl").

-type(host() :: mod_pubsub:host()
              | mod_pubsub_odbc:host()
).

-type(nodeId() :: mod_pubsub:nodeId()
                | mod_pubsub_odbc:nodeId()
).

-type(nodeIdx() :: mod_pubsub:nodeIdx()
                | mod_pubsub_odbc:nodeIdx()
).

-type(itemId() :: mod_pubsub:itemId()
                | mod_pubsub_odbc:itemId()
).

-type(pubsubNode() :: mod_pubsub:pubsubNode()
                    | mod_pubsub_odbc:pubsubNode()
).

-type(pubsubState() :: mod_pubsub:pubsubState()
                     | mod_pubsub_odbc:pubsubState()
).

-type(pubsubItem() :: mod_pubsub:pubsubItem()
                    | mod_pubsub_odbc:pubsubItem()
).

-type(nodeOptions() :: mod_pubsub:nodeOptions()
                     | mod_pubsub_odbc:nodeOptions()
).

-type(subOptions() :: mod_pubsub:subOptions()
                    | mod_pubsub_odbc:subOptions()
).

-type(affiliation() :: mod_pubsub:affiliation()
                     | mod_pubsub_odbc:affiliation()
).

-type(subscription() :: mod_pubsub:subscription()
                      | mod_pubsub_odbc:subscription()
).

-type(subId() :: mod_pubsub:subId()
               | mod_pubsub_odbc:subId()
).

-type(accessModel() :: mod_pubsub:accessModel()
                     | mod_pubsub_odbc:accessModel()
).

-type(publishModel() :: mod_pubsub:publishModel()
                     | mod_pubsub_odbc:publishModel()
).

-type(payload() :: mod_pubsub:payload()
                 | mod_pubsub_odbc:payload()
).

-callback init(Host :: binary(),
               ServerHost :: binary(),
               Opts :: [any()]) -> atom().

-callback terminate(Host :: host(),
                    ServerHost :: binary()) -> atom().

-callback options() -> [{atom(), any()}].

-callback features() -> [binary()].

-callback create_node_permission(Host :: host(),
                                 ServerHost :: binary(),
                                 Node :: nodeId(),
                                 ParentNode :: nodeId(),
                                 Owner :: jid(), Access :: atom()) ->
    {result, boolean()}.

-callback create_node(NodeIdx :: nodeIdx(),
                      Owner   :: jid()) ->
    {result, {default, broadcast}}.

-callback delete_node(Nodes :: [pubsubNode(),...]) ->
    {result,
     {default, broadcast,
      [{pubsubNode(),
        [{ljid(), [{subscription(), subId()}]},...]},...]
     }
    }
    |
    {result,
     {[],
      [{pubsubNode(),
        [{ljid(), [{subscription(), subId()}]},...]},...]
     }
    }.

-callback purge_node(NodeIdx :: nodeIdx(),
                     Owner :: jid()) ->
    {result, {default, broadcast}} |
    {error, xmlel()}.

-callback subscribe_node(NodeIdx :: nodeIdx(),
                         Sender :: jid(),
                         Subscriber :: ljid(),
                         AccessModel :: accessModel(),
                         SendLast :: 'never' | 'on_sub' | 'on_sub_and_presence',
                         PresenceSubscription :: boolean(),
                         RosterGroup :: boolean(),
                         Options :: subOptions()) ->
    {result, {default, subscribed, subId()}} |
    {result, {default, subscribed, subId(), send_last}} |
    {result, {default, pending, subId()}} |
    {error, xmlel()}.

-callback unsubscribe_node(NodeIdx :: nodeIdx(),
                           Sender :: jid(),
                           Subscriber :: ljid(),
                           SubId :: subId()) ->
    {result, default} |
    {error, xmlel()}.

-callback publish_item(NodeId :: nodeIdx(),
                       Publisher :: jid(),
                       PublishModel :: publishModel(),
                       Max_Items :: non_neg_integer(),
                       ItemId :: <<>> | itemId(),
                       Payload :: payload()) ->
    {result, {default, broadcast, [itemId()]}} |
    {error, xmlel()}.

-callback delete_item(NodeIdx :: nodeIdx(),
                      Publisher :: jid(),
                      PublishModel :: publishModel(),
                      ItemId :: <<>> | itemId()) ->
    {result, {default, broadcast}} |
    {error, xmlel()}.

-callback remove_extra_items(NodeIdx :: nodeIdx(),
                             Max_Items :: unlimited | non_neg_integer(),
                             ItemIds :: [itemId()]) ->
    {result, {[itemId()], [itemId()]}
    }.

-callback get_node_affiliations(NodeIdx :: nodeIdx()) ->
    {result, [{ljid(), affiliation()}]}.

-callback get_entity_affiliations(Host :: host(),
                                  Owner :: jid()) ->
    {result, [{pubsubNode(), affiliation()}]}.

-callback get_affiliation(NodeIdx :: nodeIdx(),
                          Owner :: jid()) ->
    {result, affiliation()}.

-callback set_affiliation(NodeIdx :: nodeIdx(),
                          Owner :: ljid(),
                          Affiliation :: affiliation()) ->
    ok |
    {error, xmlel()}.

-callback get_node_subscriptions(NodeIdx :: nodeIdx()) ->
    {result,
     [{ljid(), subscription(), subId()}] |
     [{ljid(), none},...]
    }.

-callback get_entity_subscriptions(Host :: host(),
                                   Owner :: jid()) ->
    {result, [{pubsubNode(), subscription(), subId(), ljid()}]
    }.

-callback get_subscriptions(NodeIdx :: nodeIdx(),
                            Owner :: ljid()) ->
    {result, [{subscription(), subId()}]}.

-callback get_pending_nodes(Host :: host(),
                            Owner :: jid()) ->
    {result, [nodeId()]}.

-callback get_states(NodeIdx::nodeIdx()) ->
    {result, [pubsubState()]}.

-callback get_state(NodeIdx :: nodeIdx(),
                    JID :: ljid()) ->
    pubsubState().

-callback set_state(State::pubsubState()) ->
    ok |
    {error, xmlel()}.

-callback get_items(NodeIdx :: nodeIdx(),
                    JID :: jid(),
                    AccessModel :: accessModel(),
                    Presence_Subscription :: boolean(),
                    RosterGroup :: boolean(),
                    SubId :: subId()) ->
    {result, [pubsubItem()]} |
    {error, xmlel()}.

-callback get_items(NodeIdx :: nodeIdx(),
                    From :: jid()) ->
    {result, [pubsubItem()]}.

-callback get_item(NodeIdx :: nodeIdx(),
                   ItemId :: itemId(),
                   JID :: jid(),
                   AccessModel :: accessModel(),
                   PresenceSubscription :: boolean(),
                   RosterGroup :: boolean(),
                   SubId :: subId()) ->
    {result, pubsubItem()} |
    {error, xmlel()}.

-callback get_item(NodeIdx :: nodeIdx(),
                   ItemId :: itemId()) ->
    {result, pubsubItem()} |
    {error, xmlel()}.

-callback set_item(Item :: pubsubItem()) ->
    ok.
%   | {error, _}.

-callback get_item_name(Host :: host(),
                        ServerHost :: binary(),
                        Node :: nodeId()) ->
    itemId().

-callback node_to_path(Node :: nodeId()) ->
    [nodeId()].

-callback path_to_node(Node :: [nodeId()]) ->
    nodeId().