forked from processone/exmpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexmpp_xmpp.hrl
81 lines (69 loc) · 2.49 KB
/
exmpp_xmpp.hrl
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
%% Copyright ProcessOne 2006-2010. All Rights Reserved.
%%
%% 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 online 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.
% --------------------------------------------------------------------
% Records to represent XMPP/Jabber specific structures.
% --------------------------------------------------------------------
% IQ stanza.
-record(iq, {
kind :: request | response,
type :: get | set | result | error,
id :: binary() | undefined,
ns :: xmlname() | undefined,
payload :: #xmlel{} | undefined,
error :: #xmlel{} | undefined,
lang :: binary() | undefined,
iq_ns :: xmlname() | undefined
}).
% --------------------------------------------------------------------
% Macros for common tests.
% --------------------------------------------------------------------
% Guard expression to test a stanza as defined by XMPP-IM.
-define(IS_IM_STANZA(El), (
El#xmlel.ns == ?NS_JABBER_CLIENT orelse
El#xmlel.ns == ?NS_JABBER_SERVER orelse
El#xmlel.ns == ?NS_COMPONENT_ACCEPT orelse
El#xmlel.ns == ?NS_COMPONENT_CONNECT
)).
% Guard expression to test a message.
-define(IS_MESSAGE(El), (
?IS_IM_STANZA(El) andalso El#xmlel.name == 'message'
)).
% Guard expression to test a presence.
-define(IS_PRESENCE(El), (
?IS_IM_STANZA(El) andalso El#xmlel.name == 'presence'
)).
% Guard expression to test an IQ.
-define(IS_IQ(El), (
?IS_IM_STANZA(El) andalso El#xmlel.name == 'iq'
)).
-define(IS_IQ_RECORD(IQ), (
is_record(IQ, iq)
)).
% Guard expression to test a JID.
-define(IS_JID(Jid), (
element(1, Jid) =:= 'jid' andalso tuple_size(Jid) =:= 5
)).
% --------------------------------------------------------------------
% Macros to represent <iq/>
% --------------------------------------------------------------------
-define(IQ(Type, To, Id), (
exmpp_xml:set_attributes(
#xmlel{ns = ?NS_JABBER_CLIENT, name = 'iq'},
[{<<"type">>, Type}, {<<"to">>, To}, {<<"id">>, Id}])
)).
-define(IQ_GET(To, Id), (
?IQ("get", To, Id)
)).
-define(IQ_SET(To, Id), (
?IQ("set", To, Id)
)).