File Coverage

blib/lib/XML/Stream.pm
Criterion Covered Total %
statement 504 1074 46.9
branch 143 452 31.6
condition 40 155 25.8
subroutine 57 108 52.7
pod 53 69 76.8
total 797 1858 42.9


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 11     11   389420 use 5.008;
  11         50  
  11         542  
67 11     11   64 use strict;
  11         132  
  11         777  
68 11     11   71 use warnings;
  11         21  
  11         1635  
69              
70 11     11   14254 use Sys::Hostname;
  11         25582  
  11         1312  
71 11     11   14168 use IO::Socket;
  11         461337  
  11         137  
72 11     11   28971 use IO::Select;
  11         20878  
  11         638  
73 11     11   16427 use FileHandle;
  11         53885  
  11         73  
74 11     11   12436 use Carp;
  11         30  
  11         644  
75 11     11   17935 use POSIX;
  11         160283  
  11         116  
76 11     11   56866 use Authen::SASL;
  11         29428  
  11         90  
77 11     11   11833 use MIME::Base64;
  11         10235  
  11         795  
78 11     11   12140 use utf8;
  11         124  
  11         66  
79 11     11   16289 use Encode;
  11         164309  
  11         1399  
80 11     11   147 use Scalar::Util qw(weaken);
  11         29  
  11         1647  
81              
82 11     11   9687 use XML::Stream::IO::Select::Win32;
  11         36  
  11         674  
83 11     11   7779 use XML::Stream::Tools;
  11         34  
  11         9309  
84              
85             $SIG{PIPE} = "IGNORE";
86              
87 11     11   90 use vars qw($VERSION $PAC $SSL $NONBLOCKING %HANDLERS $NETDNS %XMLNS );
  11         27  
  11         4081  
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.23_06";
120             $NONBLOCKING = 0;
121              
122             #use XML::Stream::Namespace;
123 11     11   9630 use XML::Stream::Parser;
  11         44  
  11         449  
124 11     11   8290 use XML::Stream::XPath;
  11         47  
  11         287446  
125              
126             ##############################################################################
127             #
128             # Setup the exportable objects
129             #
130             ##############################################################################
131             my @EXPORT_OK = qw(Tree Node);
132              
133             sub import
134             {
135 11     11   173 my $class = shift;
136              
137 11         2146 foreach my $module (@_)
138             {
139 9     9   55 eval "use XML::Stream::$module;";
  9     4   20  
  9         147  
  4         27  
  4         10  
  4         58  
  13         772  
140 13 50       68 die($@) if ($@);
141              
142 13         42 my $lc = lc($module);
143            
144 13         784 eval("\$HANDLERS{\$lc}->{startElement} = \\&XML::Stream::${module}::_handle_element;");
145 13         787 eval("\$HANDLERS{\$lc}->{endElement} = \\&XML::Stream::${module}::_handle_close;");
146 13         866 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