| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | ############################################################################## | 
| 2 |  |  |  |  |  |  | # | 
| 3 |  |  |  |  |  |  | #  This library is free software; you can redistribute it and/or | 
| 4 |  |  |  |  |  |  | #  modify it under the terms of the GNU Library General Public | 
| 5 |  |  |  |  |  |  | #  License as published by the Free Software Foundation; either | 
| 6 |  |  |  |  |  |  | #  version 2 of the License, or (at your option) any later version. | 
| 7 |  |  |  |  |  |  | # | 
| 8 |  |  |  |  |  |  | #  This library is distributed in the hope that it will be useful, | 
| 9 |  |  |  |  |  |  | #  but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 10 |  |  |  |  |  |  | #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
| 11 |  |  |  |  |  |  | #  Library General Public License for more details. | 
| 12 |  |  |  |  |  |  | # | 
| 13 |  |  |  |  |  |  | #  You should have received a copy of the GNU Library General Public | 
| 14 |  |  |  |  |  |  | #  License along with this library; if not, write to the | 
| 15 |  |  |  |  |  |  | #  Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 
| 16 |  |  |  |  |  |  | #  Boston, MA  02111-1307, USA. | 
| 17 |  |  |  |  |  |  | # | 
| 18 |  |  |  |  |  |  | #  Jabber | 
| 19 |  |  |  |  |  |  | #  Copyright (C) 1998-2004 Jabber Software Foundation http://jabber.org/ | 
| 20 |  |  |  |  |  |  | # | 
| 21 |  |  |  |  |  |  | ############################################################################## | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | package XML::Stream; | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | =head1 NAME | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | XML::Stream - Creates an XML Stream connection and parses return data | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | XML::Stream is an attempt at solidifying the use of XML via streaming. | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | This module provides the user with methods to connect to a remote | 
| 36 |  |  |  |  |  |  | server, send a stream of XML to the server, and receive/parse an XML | 
| 37 |  |  |  |  |  |  | stream from the server.  It is primarily based work for the Etherx XML | 
| 38 |  |  |  |  |  |  | router developed by the Jabber Development Team.  For more information | 
| 39 |  |  |  |  |  |  | about this project visit http://xmpp.org/protocols/streams/. | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | XML::Stream gives the user the ability to define a central callback | 
| 42 |  |  |  |  |  |  | that will be used to handle the tags received from the server.  These | 
| 43 |  |  |  |  |  |  | tags are passed in the format defined at instantiation time. | 
| 44 |  |  |  |  |  |  | the closing tag of an object is seen, the tree is finished and passed | 
| 45 |  |  |  |  |  |  | to the call back function.  What the user does with it from there is up | 
| 46 |  |  |  |  |  |  | to them. | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | For a detailed description of how this module works, and about the data | 
| 49 |  |  |  |  |  |  | structure that it returns, please view the source of Stream.pm and | 
| 50 |  |  |  |  |  |  | look at the detailed description at the end of the file. | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | NOTE: The parser that XML::Stream::Parser provides, as are most Perl | 
| 54 |  |  |  |  |  |  | parsers, is synchronous.  If you are in the middle of parsing a | 
| 55 |  |  |  |  |  |  | packet and call a user defined callback, the Parser is blocked until | 
| 56 |  |  |  |  |  |  | your callback finishes.  This means you cannot be operating on a | 
| 57 |  |  |  |  |  |  | packet, send out another packet and wait for a response to that packet. | 
| 58 |  |  |  |  |  |  | It will never get to you.  Threading might solve this, but as we all | 
| 59 |  |  |  |  |  |  | know threading in Perl is not quite up to par yet.  This issue will be | 
| 60 |  |  |  |  |  |  | revisted in the future. | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | =head1 METHODS | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | =cut | 
| 65 |  |  |  |  |  |  |  | 
| 66 | 12 |  |  | 12 |  | 214896 | use 5.008; | 
|  | 12 |  |  |  |  | 50 |  | 
|  | 12 |  |  |  |  | 546 |  | 
| 67 | 12 |  |  | 12 |  | 69 | use strict; | 
|  | 12 |  |  |  |  | 21 |  | 
|  | 12 |  |  |  |  | 535 |  | 
| 68 | 12 |  |  | 12 |  | 63 | use warnings; | 
|  | 12 |  |  |  |  | 26 |  | 
|  | 12 |  |  |  |  | 493 |  | 
| 69 |  |  |  |  |  |  |  | 
| 70 | 12 |  |  | 12 |  | 7166 | use Sys::Hostname; | 
|  | 12 |  |  |  |  | 14813 |  | 
|  | 12 |  |  |  |  | 750 |  | 
| 71 | 12 |  |  | 12 |  | 7455 | use IO::Socket; | 
|  | 12 |  |  |  |  | 289644 |  | 
|  | 12 |  |  |  |  | 53 |  | 
| 72 | 12 |  |  | 12 |  | 14317 | use IO::Select; | 
|  | 12 |  |  |  |  | 18674 |  | 
|  | 12 |  |  |  |  | 670 |  | 
| 73 | 12 |  |  | 12 |  | 6787 | use FileHandle; | 
|  | 12 |  |  |  |  | 41636 |  | 
|  | 12 |  |  |  |  | 69 |  | 
| 74 | 12 |  |  | 12 |  | 4258 | use Carp; | 
|  | 12 |  |  |  |  | 25 |  | 
|  | 12 |  |  |  |  | 723 |  | 
| 75 | 12 |  |  | 12 |  | 6977 | use POSIX; | 
|  | 12 |  |  |  |  | 75271 |  | 
|  | 12 |  |  |  |  | 121 |  | 
| 76 | 12 |  |  | 12 |  | 38553 | use Authen::SASL; | 
|  | 12 |  |  |  |  | 17348 |  | 
|  | 12 |  |  |  |  | 79 |  | 
| 77 | 12 |  |  | 12 |  | 6902 | use MIME::Base64; | 
|  | 12 |  |  |  |  | 7795 |  | 
|  | 12 |  |  |  |  | 770 |  | 
| 78 | 12 |  |  | 12 |  | 6858 | use utf8; | 
|  | 12 |  |  |  |  | 114 |  | 
|  | 12 |  |  |  |  | 60 |  | 
| 79 | 12 |  |  | 12 |  | 7373 | use Encode; | 
|  | 12 |  |  |  |  | 113878 |  | 
|  | 12 |  |  |  |  | 1210 |  | 
| 80 | 12 |  |  | 12 |  | 95 | use Scalar::Util qw(weaken); | 
|  | 12 |  |  |  |  | 22 |  | 
|  | 12 |  |  |  |  | 1175 |  | 
| 81 |  |  |  |  |  |  |  | 
| 82 | 12 |  |  | 12 |  | 5530 | use XML::Stream::IO::Select::Win32; | 
|  | 12 |  |  |  |  | 23 |  | 
|  | 12 |  |  |  |  | 569 |  | 
| 83 | 12 |  |  | 12 |  | 5257 | use XML::Stream::Tools; | 
|  | 12 |  |  |  |  | 34 |  | 
|  | 12 |  |  |  |  | 625 |  | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | $SIG{PIPE} = "IGNORE"; | 
| 86 |  |  |  |  |  |  |  | 
| 87 | 12 |  |  | 12 |  | 124 | use vars qw($VERSION $PAC $SSL $NONBLOCKING %HANDLERS $NETDNS %XMLNS ); | 
|  | 12 |  |  |  |  | 21 |  | 
|  | 12 |  |  |  |  | 2172 |  | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | ############################################################################## | 
| 90 |  |  |  |  |  |  | # Define the namespaces in an easy/constant manner. | 
| 91 |  |  |  |  |  |  | #----------------------------------------------------------------------------- | 
| 92 |  |  |  |  |  |  | # 0.9 | 
| 93 |  |  |  |  |  |  | #----------------------------------------------------------------------------- | 
| 94 |  |  |  |  |  |  | $XMLNS{'stream'}        = "http://etherx.jabber.org/streams"; | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | #----------------------------------------------------------------------------- | 
| 97 |  |  |  |  |  |  | # 1.0 | 
| 98 |  |  |  |  |  |  | #----------------------------------------------------------------------------- | 
| 99 |  |  |  |  |  |  | $XMLNS{'xmppstreams'}   = "urn:ietf:params:xml:ns:xmpp-streams"; | 
| 100 |  |  |  |  |  |  | $XMLNS{'xmpp-bind'}     = "urn:ietf:params:xml:ns:xmpp-bind"; | 
| 101 |  |  |  |  |  |  | $XMLNS{'xmpp-sasl'}     = "urn:ietf:params:xml:ns:xmpp-sasl"; | 
| 102 |  |  |  |  |  |  | $XMLNS{'xmpp-session'}  = "urn:ietf:params:xml:ns:xmpp-session"; | 
| 103 |  |  |  |  |  |  | $XMLNS{'xmpp-tls'}      = "urn:ietf:params:xml:ns:xmpp-tls"; | 
| 104 |  |  |  |  |  |  | ############################################################################## | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | if (eval "require Net::DNS;" ) | 
| 108 |  |  |  |  |  |  | { | 
| 109 |  |  |  |  |  |  | require Net::DNS; | 
| 110 |  |  |  |  |  |  | import Net::DNS; | 
| 111 |  |  |  |  |  |  | $NETDNS = 1; | 
| 112 |  |  |  |  |  |  | } | 
| 113 |  |  |  |  |  |  | else | 
| 114 |  |  |  |  |  |  | { | 
| 115 |  |  |  |  |  |  | $NETDNS = 0; | 
| 116 |  |  |  |  |  |  | } | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | $VERSION = "1.24"; | 
| 120 |  |  |  |  |  |  | $NONBLOCKING = 0; | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | #use XML::Stream::Namespace; | 
| 123 | 12 |  |  | 12 |  | 5735 | use XML::Stream::Parser; | 
|  | 12 |  |  |  |  | 39 |  | 
|  | 12 |  |  |  |  | 491 |  | 
| 124 | 12 |  |  | 12 |  | 5855 | use XML::Stream::XPath; | 
|  | 12 |  |  |  |  | 40 |  | 
|  | 12 |  |  |  |  | 184672 |  | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | ############################################################################## | 
| 127 |  |  |  |  |  |  | # | 
| 128 |  |  |  |  |  |  | # Setup the exportable objects | 
| 129 |  |  |  |  |  |  | # | 
| 130 |  |  |  |  |  |  | ############################################################################## | 
| 131 |  |  |  |  |  |  | my @EXPORT_OK = qw(Tree Node); | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | sub import | 
| 134 |  |  |  |  |  |  | { | 
| 135 | 12 |  |  | 12 |  | 156 | my $class = shift; | 
| 136 |  |  |  |  |  |  |  | 
| 137 | 12 |  |  |  |  | 1865 | foreach my $module (@_) | 
| 138 |  |  |  |  |  |  | { | 
| 139 | 10 |  |  | 10 |  | 60 | eval "use XML::Stream::$module;"; | 
|  | 10 |  |  | 4 |  | 20 |  | 
|  | 10 |  |  |  |  | 157 |  | 
|  | 4 |  |  |  |  | 23 |  | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 56 |  | 
|  | 14 |  |  |  |  | 799 |  | 
| 140 | 14 | 50 |  |  |  | 63 | die($@) if ($@); | 
| 141 |  |  |  |  |  |  |  | 
| 142 | 14 |  |  |  |  | 59 | my $lc = lc($module); | 
| 143 |  |  |  |  |  |  |  | 
| 144 | 14 |  |  |  |  | 904 | eval("\$HANDLERS{\$lc}->{startElement} = \\&XML::Stream::${module}::_handle_element;"); | 
| 145 | 14 |  |  |  |  | 851 | eval("\$HANDLERS{\$lc}->{endElement}   = \\&XML::Stream::${module}::_handle_close;"); | 
| 146 | 14 |  |  |  |  | 850 | eval("\$HANDLERS{\$lc}->{characters}   = \\&XML::Stream::${module}::_handle_cdata;"); | 
| 147 |  |  |  |  |  |  | } | 
| 148 |  |  |  |  |  |  | } | 
| 149 |  |  |  |  |  |  |  | 
| 150 |  |  |  |  |  |  | =pod | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | =head2 new | 
| 153 |  |  |  |  |  |  |  | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | new( | 
| 156 |  |  |  |  |  |  | debug      => string, | 
| 157 |  |  |  |  |  |  | debugfh    => FileHandle, | 
| 158 |  |  |  |  |  |  | debuglevel => 0|1|N, | 
| 159 |  |  |  |  |  |  | debugtime  => 0|1, | 
| 160 |  |  |  |  |  |  | style      => string) | 
| 161 |  |  |  |  |  |  |  | 
| 162 |  |  |  |  |  |  | Creates the XML::Stream object. | 
| 163 |  |  |  |  |  |  | B should be set to the path for the debug log | 
| 164 |  |  |  |  |  |  | to be written.  If set to "stdout" then the | 
| 165 |  |  |  |  |  |  | debug will go there. Also, you can specify | 
| 166 |  |  |  |  |  |  | a filehandle that already exists by using | 
| 167 |  |  |  |  |  |  | B. | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | B determines the amount of debug to generate. | 
| 170 |  |  |  |  |  |  | 0 is the least, 1 is a little more, N is the limit you want. | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | B determines wether a timestamp should be preappended | 
| 173 |  |  |  |  |  |  | to the entry. | 
| 174 |  |  |  |  |  |  | B |