1AnyEvent::XMPP::Util(3)User Contributed Perl DocumentatioAnnyEvent::XMPP::Util(3)
2
3
4
6 AnyEvent::XMPP::Util - Utility functions for AnyEvent::XMPP
7
9 use AnyEvent::XMPP::Util qw/split_jid/;
10 ...
11
13 These functions can be exported if you want:
14
15 resourceprep ($string)
16 This function applies the stringprep profile for resources to
17 $string and returns the result.
18
19 nodeprep ($string)
20 This function applies the stringprep profile for nodes to $string
21 and returns the result.
22
23 prep_join_jid ($node, $domain, $resource)
24 This function joins the parts $node, $domain and $resource to a
25 full jid and applies stringprep profiles. If the profiles couldn't
26 be applied undef will be returned.
27
28 join_jid ($user, $domain, $resource)
29 This is a plain concatenation of $user, $domain and $resource
30 without stringprep.
31
32 See also prep_join_jid
33
34 split_uri ($uri)
35 This function splits up the $uri into service and node part and
36 will return them as list.
37
38 my ($service, $node) = split_uri ($uri);
39
40 split_jid ($jid)
41 This function splits up the $jid into user/node, domain and
42 resource part and will return them as list.
43
44 my ($user, $host, $res) = split_jid ($jid);
45
46 node_jid ($jid)
47 See "prep_res_jid" below.
48
49 domain_jid ($jid)
50 See "prep_res_jid" below.
51
52 res_jid ($jid)
53 See "prep_res_jid" below.
54
55 prep_node_jid ($jid)
56 See "prep_res_jid" below.
57
58 prep_domain_jid ($jid)
59 See "prep_res_jid" below.
60
61 prep_res_jid ($jid)
62 These functions return the corresponding parts of a JID. The
63 "prep_" prefixed JIDs return the stringprep'ed versions.
64
65 stringprep_jid ($jid)
66 This applies stringprep to all parts of the jid according to the
67 RFC 3920. Use this if you want to compare two jids like this:
68
69 stringprep_jid ($jid_a) eq stringprep_jid ($jid_b)
70
71 This function returns undef if the $jid couldn't successfully be
72 parsed and the preparations done.
73
74 cmp_jid ($jid1, $jid2)
75 This function compares two jids $jid1 and $jid2 whether they are
76 equal.
77
78 cmp_bare_jid ($jid1, $jid2)
79 This function compares two jids $jid1 and $jid2 whether their bare
80 part is equal.
81
82 prep_bare_jid ($jid)
83 This function makes the jid $jid a bare jid, meaning: it will strip
84 off the resource part. With stringprep.
85
86 bare_jid ($jid)
87 This function makes the jid $jid a bare jid, meaning: it will strip
88 off the resource part. But without stringprep.
89
90 is_bare_jid ($jid)
91 This method returns a boolean which indicates whether $jid is a
92 bare JID.
93
94 filter_xml_chars ($string)
95 This function removes all characters from $string which are not
96 allowed in XML and returns the new string.
97
98 filter_xml_attr_hash_chars ($hashref)
99 This runs all values of the $hashref through "filter_xml_chars"
100 (see above) and changes them in-place!
101
102 simxml ($w, %xmlstruct)
103 This function takes a XML::Writer as first argument ($w) and the
104 rest key value pairs:
105
106 simxml ($w,
107 defns => '<xmlnamespace>',
108 node => <node>,
109 prefixes => { prefix => namespace, ... },
110 );
111
112 Where node is:
113
114 <node> := {
115 ns => '<xmlnamespace>',
116 name => 'tagname',
117 attrs => [ 'name', 'value', 'name2', 'value2', ... ],
118 childs => [ <node>, ... ]
119 }
120 | {
121 dns => '<xmlnamespace>', # this will set that namespace to
122 # the default namespace before using it.
123 name => 'tagname',
124 attrs => [ 'name', 'value', 'name2', 'value2', ... ],
125 childs => [ <node>, ... ]
126 }
127 | sub { my ($w) = @_; ... } # with $w being a XML::Writer object
128 | "textnode"
129
130 Please note: "childs" stands for "child sequence" :-)
131
132 Also note that if you omit the "ns" key for nodes there is a fall
133 back to the namespace of the parent element or the last default
134 namespace. This makes it easier to write things like this:
135
136 {
137 defns => 'muc_owner',
138 node => { name => 'query' }
139 }
140
141 (Without having to include "ns" in the node.)
142
143 Please note that all attribute values and character data will be
144 filtered by "filter_xml_chars".
145
146 This is a bigger example:
147
148 ...
149
150 $msg->append_creation( sub {
151 my($w) = @_;
152 simxml($w,
153 defns => 'muc_user', # sets the default namepsace for all following elements
154 node => {
155 name => 'x', # element 'x' in namespace 'muc_user'
156 childs => [
157 {
158 'name' => 'invite', # element 'invite' in namespace 'muc_user'
159 'attrs' => [ 'to', $to_jid ], # to="$to_jid" attribute for 'invite'
160 'childs' => [
161 { # the <reason>$reason</reason> element in the invite element
162 'name' => 'reason',
163 childs => [ $reason ]
164 }
165 ],
166 }
167 ]
168 }
169 );
170 });
171
172 to_xmpp_time ($sec, $min, $hour, $tz, $secfrac)
173 This function transforms a time to the XMPP date time format. The
174 meanings and value ranges of $sec, ..., $hour are explained in the
175 perldoc of Perl's builtin "localtime".
176
177 $tz has to be either "UTC" or of the form "[+-]hh:mm", it can be
178 undefined and wont occur in the time string then.
179
180 $secfrac are optional and can be the fractions of the second.
181
182 See also XEP-0082.
183
184 to_xmpp_datetime ($sec,$min,$hour,$mday,$mon,$year,$tz, $secfrac)
185 This function transforms a time to the XMPP date time format. The
186 meanings of $sec, ..., $year are explained in the perldoc of Perl's
187 "localtime" builtin and have the same value ranges.
188
189 $tz has to be either "Z" (for UTC) or of the form "[+-]hh:mm"
190 (offset from UTC), if it is undefined "Z" will be used.
191
192 $secfrac are optional and can be the fractions of the second.
193
194 See also XEP-0082.
195
196 from_xmpp_datetime ($string)
197 This function transforms the $string which is either a time or
198 datetime in XMPP format. If the string was not in the right format
199 an empty list is returned. Otherwise this is returned:
200
201 my ($sec, $min, $hour, $mday, $mon, $year, $tz, $secfrac)
202 = from_xmpp_datetime ($string);
203
204 For the value ranges and semantics of $sec, ..., $srcfrac please
205 look at the documentation for "to_xmpp_datetime".
206
207 $tz and $secfrac might be undefined.
208
209 If $tz is undefined the timezone is to be assumed to be UTC.
210
211 If $string contained just a time $mday, $mon and $year will be
212 undefined.
213
214 See also XEP-0082.
215
216 xmpp_datetime_as_timestamp ($string)
217 This function takes the same arguments as "from_xmpp_datetime", but
218 returns a unix timestamp, like "time ()" would.
219
220 This function requires the POSIX module.
221
223 Robin Redeker, "<elmex at ta-sa.org>", JID: "<elmex at jabber.org>"
224
226 Copyright 2007, 2008 Robin Redeker, all rights reserved.
227
228 This program is free software; you can redistribute it and/or modify it
229 under the same terms as Perl itself.
230
231
232
233perl v5.32.0 2020-07-28 AnyEvent::XMPP::Util(3)