File Coverage

blib/lib/XML/Stream.pm
Criterion Covered Total %
statement 504 1074 46.9
branch 142 452 31.4
condition 40 155 25.8
subroutine 57 108 52.7
pod 53 69 76.8
total 796 1858 42.8


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   198443 use 5.008;
  12         42  
  12         481  
67 12     12   56 use strict;
  12         22  
  12         461  
68 12     12   53 use warnings;
  12         18  
  12         500  
69              
70 12     12   6970 use Sys::Hostname;
  12         13230  
  12         657  
71 12     12   6823 use IO::Socket;
  12         255617  
  12         56  
72 12     12   12810 use IO::Select;
  12         19335  
  12         706  
73 12     12   6844 use FileHandle;
  12         41607  
  12         71  
74 12     12   4281 use Carp;
  12         20  
  12         686  
75 12     12   6880 use POSIX;
  12         76181  
  12         97  
76 12     12   36684 use Authen::SASL;
  12         15790  
  12         78  
77 12     12   6354 use MIME::Base64;
  12         7712  
  12         806  
78 12     12   7213 use utf8;
  12         117  
  12         52  
79 12     12   6740 use Encode;
  12         103443  
  12         1160  
80 12     12   95 use Scalar::Util qw(weaken);
  12         18  
  12         1031  
81              
82 12     12   5263 use XML::Stream::IO::Select::Win32;
  12         29  
  12         571  
83 12     12   4278 use XML::Stream::Tools;
  12         26  
  12         516  
84              
85             $SIG{PIPE} = "IGNORE";
86              
87 12     12   70 use vars qw($VERSION $PAC $SSL $NONBLOCKING %HANDLERS $NETDNS %XMLNS );
  12         15  
  12         1963  
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_07";
120             $NONBLOCKING = 0;
121              
122             #use XML::Stream::Namespace;
123 12     12   5560 use XML::Stream::Parser;
  12         35  
  12         450  
124 12     12   5524 use XML::Stream::XPath;
  12         41  
  12         163752  
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   158 my $class = shift;
136              
137 12         1723 foreach my $module (@_)
138             {
139 10     10   53 eval "use XML::Stream::$module;";
  10     4   13  
  10         149  
  4         20  
  4         7  
  4         51  
  14         777  
140 14 50       56 die($@) if ($@);
141              
142 14         41 my $lc = lc($module);
143            
144 14         791 eval("\$HANDLERS{\$lc}->{startElement} = \\&XML::Stream::${module}::_handle_element;");
145 14         698 eval("\$HANDLERS{\$lc}->{endElement} = \\&XML::Stream::${module}::_handle_close;");
146 14         656 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