| 1 |
elmex |
1.1 |
package Net::XMPP2; |
| 2 |
|
|
use warnings; |
| 3 |
|
|
use strict; |
| 4 |
|
|
|
| 5 |
|
|
=head1 NAME |
| 6 |
|
|
|
| 7 |
|
|
Net::XMPP2 - An implementation of the XMPP Protocol |
| 8 |
|
|
|
| 9 |
|
|
=head1 VERSION |
| 10 |
|
|
|
| 11 |
elmex |
1.20 |
Version 0.02 |
| 12 |
elmex |
1.1 |
|
| 13 |
|
|
=cut |
| 14 |
|
|
|
| 15 |
elmex |
1.20 |
our $VERSION = '0.02'; |
| 16 |
elmex |
1.1 |
|
| 17 |
|
|
=head1 SYNOPSIS |
| 18 |
|
|
|
| 19 |
elmex |
1.2 |
use Net::XMPP2::Connection; |
| 20 |
elmex |
1.1 |
|
| 21 |
elmex |
1.2 |
or: |
| 22 |
elmex |
1.1 |
|
| 23 |
elmex |
1.2 |
use Net::XMPP2::IM::Connection; |
| 24 |
elmex |
1.1 |
|
| 25 |
elmex |
1.11 |
or: |
| 26 |
|
|
|
| 27 |
|
|
use Net::XMPP2::Client; |
| 28 |
|
|
|
| 29 |
elmex |
1.2 |
=head1 DESCRIPTION |
| 30 |
|
|
|
| 31 |
|
|
This is the head module of the L<Net::XMPP2> XMPP client protocol (as described in |
| 32 |
elmex |
1.4 |
RFC 3920 and RFC 3921) framework. |
| 33 |
elmex |
1.2 |
|
| 34 |
elmex |
1.4 |
L<Net::XMPP2::Connection> is a RFC 3920 conformant "XML" stream implementation |
| 35 |
elmex |
1.18 |
for clients, which handles TCP connect up to the resource binding. And provides |
| 36 |
|
|
low level access to the XML nodes on the XML stream along with some high |
| 37 |
elmex |
1.5 |
level methods to send the predefined XML stanzas. |
| 38 |
elmex |
1.2 |
|
| 39 |
elmex |
1.18 |
L<Net::XMPP2::IM::Connection> is a more high level module, which is derived |
| 40 |
elmex |
1.4 |
from L<Net::XMPP2::Connection>. It handles all the instant messaging client |
| 41 |
elmex |
1.5 |
functionality described in RFC 3921. |
| 42 |
|
|
|
| 43 |
elmex |
1.11 |
L<Net::XMPP2::Client> is a multi account client class. It manages connections |
| 44 |
elmex |
1.18 |
to multiple XMPP accounts and tries to offer a nice high level interface |
| 45 |
elmex |
1.11 |
to XMPP communication. |
| 46 |
|
|
|
| 47 |
elmex |
1.17 |
For a list of L</Supported extensions> see below. |
| 48 |
elmex |
1.2 |
|
| 49 |
|
|
There are also other modules in this distribution, for example: |
| 50 |
elmex |
1.11 |
L<Net::XMPP2::Util>, L<Net::XMPP2::Writer>, L<Net::XMPP2::Parser> and those I |
| 51 |
elmex |
1.2 |
forgot :-) Those modules might be helpful and/or required if you want to use |
| 52 |
|
|
this framework for XMPP. |
| 53 |
|
|
|
| 54 |
|
|
See also L<Net::XMPP2::Writer> for a discussion about the brokeness of XML in the XMPP |
| 55 |
|
|
specification. |
| 56 |
|
|
|
| 57 |
elmex |
1.15 |
If you have any questions or seek for help look below under L</SUPPORT>. |
| 58 |
|
|
|
| 59 |
elmex |
1.12 |
=head1 REQUIREMENTS |
| 60 |
|
|
|
| 61 |
|
|
One of the major drawbacks I see for Net::XMPP2 is the long list of required |
| 62 |
|
|
modules to make it work. |
| 63 |
|
|
|
| 64 |
|
|
=over 4 |
| 65 |
|
|
|
| 66 |
elmex |
1.15 |
=item L<AnyEvent> |
| 67 |
elmex |
1.12 |
|
| 68 |
|
|
For the I/O events and timers. |
| 69 |
|
|
|
| 70 |
elmex |
1.15 |
=item L<XML::Writer> |
| 71 |
elmex |
1.12 |
|
| 72 |
|
|
For writing "XML". |
| 73 |
|
|
|
| 74 |
elmex |
1.15 |
=item L<XML::Parser::Expat> |
| 75 |
elmex |
1.12 |
|
| 76 |
|
|
For parsing partial "XML" stuff. |
| 77 |
|
|
|
| 78 |
elmex |
1.15 |
=item L<MIME::Base64> |
| 79 |
elmex |
1.12 |
|
| 80 |
|
|
For SASL authentication |
| 81 |
|
|
|
| 82 |
elmex |
1.15 |
=item L<Authen::SASL> |
| 83 |
elmex |
1.12 |
|
| 84 |
|
|
For SASL authentication |
| 85 |
|
|
|
| 86 |
elmex |
1.15 |
=item L<Net::LibIDN> |
| 87 |
elmex |
1.12 |
|
| 88 |
|
|
For stringprep profiles to handle JIDs. |
| 89 |
|
|
|
| 90 |
elmex |
1.15 |
=item L<Net::SSLeay> |
| 91 |
elmex |
1.12 |
|
| 92 |
|
|
For SSL connections. |
| 93 |
|
|
|
| 94 |
elmex |
1.15 |
=item L<Net::DNS> |
| 95 |
elmex |
1.12 |
|
| 96 |
|
|
For SRV RR lookups. |
| 97 |
|
|
|
| 98 |
|
|
=back |
| 99 |
|
|
|
| 100 |
elmex |
1.18 |
And yes, all these are essential for XMPP communication. Even though 'instant |
| 101 |
elmex |
1.12 |
messaging' and 'presence' is a quite simple problem XMPP somehow was successful |
| 102 |
elmex |
1.18 |
at making the task complicated enough to keep me busy for a long time. But all |
| 103 |
|
|
of that time wasn't only for the technology required to get it started, mostly |
| 104 |
|
|
it was for all the quirks, hacks and badly applied "XML" in the protocol which |
| 105 |
elmex |
1.12 |
complicated the matter. |
| 106 |
|
|
|
| 107 |
elmex |
1.11 |
=head1 RELEASE NOTES |
| 108 |
|
|
|
| 109 |
|
|
Here are some notes to the releases (release of this version is at top): |
| 110 |
|
|
|
| 111 |
|
|
=head2 Version |
| 112 |
|
|
|
| 113 |
|
|
=over 4 |
| 114 |
|
|
|
| 115 |
elmex |
1.20 |
=item * 0.02 |
| 116 |
|
|
|
| 117 |
elmex |
1.21 |
This release adds lots of small improvements to the API (mostly new events), |
| 118 |
elmex |
1.20 |
and also some bugfixes here and there. The release also comes with some |
| 119 |
|
|
new examples, you might want to take a look at the L</EXAMPLES> section. |
| 120 |
|
|
|
| 121 |
|
|
As a highlight I also present the implementation of XEP-0004 (Data Forms), see also |
| 122 |
|
|
L<Net::XMPP2::Ext> for a description. |
| 123 |
|
|
|
| 124 |
|
|
I also added some convenience functions to L<Net::XMPP2::Util>, for example |
| 125 |
|
|
C<simxml> which simplifies the generation of XMPP-like "XML". |
| 126 |
|
|
|
| 127 |
elmex |
1.15 |
=item * 0.01 |
| 128 |
elmex |
1.11 |
|
| 129 |
|
|
This release has beta status. The code is already used daily in my client |
| 130 |
|
|
and I keep looking out for bugs. If you find undocumented, missing or faulty |
| 131 |
elmex |
1.15 |
code/methods please drop me a mail! See also L</BUGS> below. |
| 132 |
elmex |
1.11 |
|
| 133 |
elmex |
1.14 |
Potential edges when using this module: sparely documented methods, missing |
| 134 |
elmex |
1.18 |
functionality and generally bugs bugs and bugs. Even though this module is in |
| 135 |
elmex |
1.11 |
daily usage there are still lots of cases I might have missed. |
| 136 |
|
|
|
| 137 |
|
|
For the next release I'm planning to provide more examples in the documentation |
| 138 |
elmex |
1.14 |
and/or samples/ directory, along with bugfixes and enhancements along with some |
| 139 |
elmex |
1.11 |
todo items killed from the TODO file. |
| 140 |
|
|
|
| 141 |
|
|
=back |
| 142 |
|
|
|
| 143 |
|
|
=head2 TODO |
| 144 |
|
|
|
| 145 |
|
|
There are still lots of items on the TODO list (see also the TODO file |
| 146 |
elmex |
1.14 |
in the distribution of Net::XMPP2). |
| 147 |
elmex |
1.11 |
|
| 148 |
elmex |
1.20 |
Sadly this module still misses some decent DOM implementation. Do you know some |
| 149 |
|
|
decent DOM Level 2 implementation for Perl? (I considered switchting to |
| 150 |
|
|
L<XML::LibXML> but I somehow have more trust in the C<expat> XML parser, maybe |
| 151 |
|
|
someone wants to implement L<XML::LibXML> based parsing for me (and of course a |
| 152 |
|
|
DOM interface for L<Net::XMPP2::Node>?) |
| 153 |
|
|
|
| 154 |
elmex |
1.2 |
=head1 Why (yet) another XMPP module? |
| 155 |
|
|
|
| 156 |
elmex |
1.17 |
The main outstanding feature of this module in comparison to the other XMPP |
| 157 |
elmex |
1.2 |
(aka Jabber) modules out there is the support for L<AnyEvent>. L<AnyEvent> |
| 158 |
|
|
permits you to use this module together with other I/O event based programs and |
| 159 |
|
|
libraries (ie. L<Gtk2> or L<Event>). |
| 160 |
|
|
|
| 161 |
elmex |
1.18 |
The other modules could often only be integrated in those applications or |
| 162 |
|
|
libraries by using threads. I decided to write this module because I think CPAN |
| 163 |
|
|
lacks an event based XMPP module. Threads are unfortunately not an alternative |
| 164 |
|
|
in Perl at the moment due the limited threading functionality they provide and |
| 165 |
|
|
the global speed hit. I also think that a simple event based I/O framework |
| 166 |
|
|
might be a bit easier to handle than threads. |
| 167 |
elmex |
1.2 |
|
| 168 |
|
|
Another thing was that I didn't like the APIs of the other modules. In L<Net::XMPP2> |
| 169 |
elmex |
1.9 |
I try to provide low level modules for speaking XMPP as defined in RFC 3920 and RFC 3921 |
| 170 |
|
|
(see also L<Net::XMPP2::Connection> and L<Net::XMPP2::IM::Connection>). But I also |
| 171 |
elmex |
1.11 |
try to provide a high level API for easier usage for instant messaging tasks |
| 172 |
elmex |
1.15 |
and clients (eg. L<Net::XMPP2::Client>). |
| 173 |
elmex |
1.2 |
|
| 174 |
|
|
=head1 A note about TLS |
| 175 |
|
|
|
| 176 |
|
|
This module also supports TLS, as the specification of XMPP requires an |
| 177 |
elmex |
1.7 |
implementation to support TLS. |
| 178 |
elmex |
1.2 |
|
| 179 |
elmex |
1.18 |
Maybe there are still some bugs in the handling of TLS in L<Net::XMPP2::Connection>. |
| 180 |
elmex |
1.7 |
So keep an eye on TLS with this module. If you encounter any problems it would be |
| 181 |
|
|
very helpful if you could debug them or at least send me a detailed report on how |
| 182 |
|
|
to reproduce the problem. |
| 183 |
|
|
|
| 184 |
|
|
(As I use this module myself I don't expect TLS to be completly broken, but it |
| 185 |
|
|
might break under different circumstances than I have here. Those |
| 186 |
|
|
circumstances might be a different load of data pumped through the TLS |
| 187 |
|
|
connection.) |
| 188 |
elmex |
1.1 |
|
| 189 |
elmex |
1.18 |
I mainly expect problems where available data isn't properly read from the socket |
| 190 |
elmex |
1.2 |
or written to it. You might want to take a look at the C<debug_send> and C<debug_recv> |
| 191 |
|
|
events in L<Net::XMPP2::Connection>. |
| 192 |
elmex |
1.1 |
|
| 193 |
elmex |
1.17 |
=head1 Supported extensions |
| 194 |
elmex |
1.3 |
|
| 195 |
elmex |
1.10 |
See L<Net::XMPP2::Ext> for a list. |
| 196 |
elmex |
1.3 |
|
| 197 |
elmex |
1.16 |
=head1 EXAMPLES |
| 198 |
|
|
|
| 199 |
elmex |
1.19 |
Following examples are included in this distribution: |
| 200 |
|
|
|
| 201 |
|
|
=over 4 |
| 202 |
|
|
|
| 203 |
|
|
=item B<samples/simple_example_1> |
| 204 |
|
|
|
| 205 |
|
|
This example script just connects to a server and sends a message and |
| 206 |
|
|
also displays incoming messages on stdout. |
| 207 |
|
|
|
| 208 |
|
|
=item B<samples/devcl/devcl> |
| 209 |
|
|
|
| 210 |
|
|
This is a more advanced 'example'. It requires you to have L<Gtk2> |
| 211 |
|
|
installed. It's mostly used by the author to implement proof-of-concepts. |
| 212 |
|
|
Currently you start the client like this: |
| 213 |
|
|
|
| 214 |
|
|
../Net-XMPP2/samples/devcl/# perl ./devcl <jid> <password> |
| 215 |
|
|
|
| 216 |
|
|
The client's main window displays a protocol dump and there is currently |
| 217 |
|
|
a service discovery browser implemented. |
| 218 |
|
|
|
| 219 |
|
|
This might be a valuable source if you look for more real-world |
| 220 |
|
|
applications of L<Net::XMPP2>. |
| 221 |
|
|
|
| 222 |
|
|
=item B<samples/conference_lister> |
| 223 |
|
|
|
| 224 |
|
|
See below. |
| 225 |
|
|
|
| 226 |
|
|
=item B<samples/room_lister> |
| 227 |
|
|
|
| 228 |
|
|
See below. |
| 229 |
|
|
|
| 230 |
|
|
=item B<samples/room_lister_stat> |
| 231 |
|
|
|
| 232 |
|
|
These three scripts implements a global room scan. C<conference_lister> takes |
| 233 |
|
|
a list of servers (the file is called C<servers.xml> which has the same format as |
| 234 |
|
|
the xml file at L<http://www.jabber.org/servers.xml>). It then scans all |
| 235 |
|
|
servers for chat room services and lists them into a file C<conferences.stor>, |
| 236 |
|
|
which is a L<Storable> dump. |
| 237 |
|
|
|
| 238 |
|
|
C<room_lister> then reads that file and queries all services for rooms, and then |
| 239 |
|
|
all rooms for their occupants. The output file is C<room_data.stor>, also a L<Storable> |
| 240 |
|
|
dump, which in turn can be read with C<room_lister_stat>, which transform |
| 241 |
|
|
the data structures into something human readable. |
| 242 |
|
|
|
| 243 |
|
|
These scripts are a bit hacky and quite complicated, but maybe it's of any |
| 244 |
|
|
value for someone. You might note L<samples/EVQ.pm> which is a module that |
| 245 |
|
|
handles request-throttling (You don't want to flood the server and risk |
| 246 |
|
|
getting the admins attention :). |
| 247 |
|
|
|
| 248 |
|
|
=back |
| 249 |
|
|
|
| 250 |
|
|
For others, which the author might forgot or didn't want to |
| 251 |
|
|
list here see the C<samples/> directory. |
| 252 |
|
|
|
| 253 |
|
|
More examples will be included in later releases, please feel free to ask the |
| 254 |
|
|
L</AUTHOR> if you have any questions about the API. There is also an IRC |
| 255 |
|
|
channel, see L</SUPPORT>. |
| 256 |
elmex |
1.16 |
|
| 257 |
elmex |
1.1 |
=head1 AUTHOR |
| 258 |
|
|
|
| 259 |
elmex |
1.11 |
Robin Redeker, C<< <elmex at ta-sa.org> >>, JID: C<< <elmex at jabber.org> >> |
| 260 |
elmex |
1.1 |
|
| 261 |
|
|
=head1 BUGS |
| 262 |
|
|
|
| 263 |
elmex |
1.12 |
Please note that I'm currently (July 2007) the only developer on this project |
| 264 |
|
|
and I'm very busy with my studies in Computer Science in Summer 2007. If you |
| 265 |
elmex |
1.18 |
want to ease my workload or want timely releases, please send me patches instead |
| 266 |
|
|
of bug reports or feature requests. I won't forget the reports or requests if |
| 267 |
|
|
you can't or didn't send patches, but it can take a long time until I get enough |
| 268 |
elmex |
1.12 |
time to fix/implement them. |
| 269 |
|
|
|
| 270 |
elmex |
1.18 |
Also try to be as precise as possible with bug reports, if you can't send a |
| 271 |
|
|
patch, it would be best if you find out which code doesn't work and tell me |
| 272 |
|
|
why. |
| 273 |
elmex |
1.12 |
|
| 274 |
elmex |
1.1 |
Please report any bugs or feature requests to |
| 275 |
|
|
C<bug-net-xmpp2 at rt.cpan.org>, or through the web interface at |
| 276 |
|
|
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-XMPP2>. |
| 277 |
elmex |
1.18 |
I will be notified and then you'll automatically be notified of progress on |
| 278 |
elmex |
1.1 |
your bug as I make changes. |
| 279 |
|
|
|
| 280 |
|
|
=head1 SUPPORT |
| 281 |
|
|
|
| 282 |
|
|
You can find documentation for this module with the perldoc command. |
| 283 |
|
|
|
| 284 |
|
|
perldoc Net::XMPP2 |
| 285 |
|
|
|
| 286 |
|
|
You can also look for information at: |
| 287 |
|
|
|
| 288 |
|
|
=over 4 |
| 289 |
|
|
|
| 290 |
elmex |
1.15 |
=item * IRC: Net::XMPP2 IRC Channel |
| 291 |
|
|
|
| 292 |
|
|
IRC Network: http://freenode.net/ |
| 293 |
|
|
Server : chat.freenode.net |
| 294 |
|
|
Channel : #net_xmpp2 |
| 295 |
|
|
|
| 296 |
elmex |
1.16 |
Feel free to join and ask questions! |
| 297 |
|
|
|
| 298 |
elmex |
1.15 |
=item * Net::XMPP2 Project Site |
| 299 |
|
|
|
| 300 |
|
|
L<http://www.ta-sa.org/> |
| 301 |
|
|
|
| 302 |
elmex |
1.1 |
=item * AnnoCPAN: Annotated CPAN documentation |
| 303 |
|
|
|
| 304 |
|
|
L<http://annocpan.org/dist/Net-XMPP2> |
| 305 |
|
|
|
| 306 |
|
|
=item * CPAN Ratings |
| 307 |
|
|
|
| 308 |
|
|
L<http://cpanratings.perl.org/d/Net-XMPP2> |
| 309 |
|
|
|
| 310 |
|
|
=item * RT: CPAN's request tracker |
| 311 |
|
|
|
| 312 |
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-XMPP2> |
| 313 |
|
|
|
| 314 |
|
|
=item * Search CPAN |
| 315 |
|
|
|
| 316 |
|
|
L<http://search.cpan.org/dist/Net-XMPP2> |
| 317 |
|
|
|
| 318 |
|
|
=back |
| 319 |
|
|
|
| 320 |
|
|
=head1 ACKNOWLEDGEMENTS |
| 321 |
|
|
|
| 322 |
elmex |
1.18 |
Thanks to the XSF for the development of an open instant messaging protocol (even though it uses "XML"). |
| 323 |
elmex |
1.13 |
|
| 324 |
|
|
And thanks to all people who had to listen to my desperate curses about the |
| 325 |
elmex |
1.18 |
brokenness/braindeadness of XMPP. Without you I would've never brought this |
| 326 |
elmex |
1.13 |
module to a usable state. |
| 327 |
elmex |
1.12 |
|
| 328 |
elmex |
1.17 |
Thanks to: |
| 329 |
|
|
|
| 330 |
|
|
=over 4 |
| 331 |
|
|
|
| 332 |
elmex |
1.18 |
=item * Carlo von Loesch (aka lynX) L<http://www.psyced.org/> |
| 333 |
elmex |
1.17 |
|
| 334 |
|
|
For pointing out some typos. |
| 335 |
|
|
|
| 336 |
|
|
=back |
| 337 |
|
|
|
| 338 |
elmex |
1.1 |
=head1 COPYRIGHT & LICENSE |
| 339 |
|
|
|
| 340 |
|
|
Copyright 2007 Robin Redeker, all rights reserved. |
| 341 |
|
|
|
| 342 |
|
|
This program is free software; you can redistribute it and/or modify it |
| 343 |
|
|
under the same terms as Perl itself. |
| 344 |
|
|
|
| 345 |
|
|
=cut |
| 346 |
|
|
|
| 347 |
|
|
1; # End of Net::XMPP2 |