AnyEvent-XMPP

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

         - also fixed a small bug in stream initiation, Net::XMPP2 now
           sends a xml declaration again.
         - implemented a very old authentication method which makes Net::XMPP2
           now also work with jabberd 1.4.2. See also the
           'disable_old_jabber_authentication' option in Net::XMPP2::Connection
         - fixed cpan bug #29724 (unpacking the tarball on os x works now
           after renaming devcl -> dev_client).
         - fixed a bug with handling the is_room query in MUC

0.09 Sun Sep 16 09:25:25 CEST 2007
         - fixed a small bug important bug in namespace setting when binding
           a resource. this was a showstopper for eg. jabber.org.

0.08 Sat Sep 15 10:50:00 CEST 2007
         - fixed glitches in tests
         - added disco_info example
         - updated disco_info example, added data form retrieval in disco_info
         - fixed bug in whitespace ping
         - added character filter functions for filtering out not-allowed XML
           chars before sending them to the server. Even though this might be
           a programmer error and shouldn't probably be handled by Net::XMPP2

Changes  view on Meta::CPAN

           to outgoing stanzas

0.02 Wed Jul 11 22:55:56 CEST 2007
         - added iq_xml event
         - added development client example in samples/devcl/
         - added some debugging events: debug_recv, debug_send, send_stanza_data,
           and recv_stanza_xml.
         - the error event now also provides error reporting
           about exceptions (eq. in IQ callbacks, which is certainly
           useful for development!)
         - fixed error in binding-handling in case the bind iq gets a timeout
         - added samples/room_lister* and samples/conference_lister
         - redesigned disco mechanism a bit
         - added error collection event for nicer error reporting capabilities
         - added samples/disco_test
         - implemented XEP-0004
         - added samples/limit_searcher
         - added simxml()
         - splitting up large packets when writing
         - fixed bad link in documentation of Net::XMPP2::IM::Connection
         - added samples/simple_example_1

README  view on Meta::CPAN

    or:

       use AnyEvent::XMPP::Client;

DESCRIPTION
    This is the head module of the AnyEvent::XMPP XMPP client protocol (as
    described in RFC 3920 and RFC 3921) framework.

    AnyEvent::XMPP::Connection is a RFC 3920 conforming "XML" stream
    implementation for clients, which handles TCP connect up to the resource
    binding. And provides low level access to the XML nodes on the XML
    stream along with some high level methods to send the predefined XML
    stanzas.

    AnyEvent::XMPP::IM::Connection is a more high level module, which is
    derived from AnyEvent::XMPP::Connection. It handles all the instant
    messaging client functionality described in RFC 3921.

    AnyEvent::XMPP::Client is a multi account client class. It manages
    connections to multiple XMPP accounts and tries to offer a nice high
    level interface to XMPP communication.

TODO  view on Meta::CPAN

- fix the inaviodable memoryleaks with the callbacks
  the circular object structs.
- put some serious stuff in the synopsises
- look at attribute namespace preservation! (if they got
  prefixes, how to parse this with expat?
  see also http://www.w3.org/TR/REC-xml-names/#scoping-defaulting )
- fix problem that xml::writer writes after <stream/> ahs been written
  - reproduce by conflicting resources!
- test the xml parse error object somehow!
- add context field to IQ error for all the places origin from IQ errors
  (bind_error, session_error, ...)
- AnyEvent::XMPP::Client
  - find a way to distinguish presences from JIDs that
    are in multiple account's roster.
- AnyEvent::XMPP missing functionality to be RFC 3920 conform:
   - improve error handling for SASL to
     support retries as specified in RFC 3920.
     (eg. by supporting a method sasl_retry() which takes
      the changed credentials)
   x SRV record lookup
      - weight handling!

lib/AnyEvent/XMPP.pm  view on Meta::CPAN

or:

   use AnyEvent::XMPP::Client;

=head1 DESCRIPTION

This is the head module of the L<AnyEvent::XMPP> XMPP client protocol (as described in
RFC 3920 and RFC 3921) framework.

L<AnyEvent::XMPP::Connection> is a RFC 3920 conforming "XML" stream implementation
for clients, which handles TCP connect up to the resource binding. And provides
low level access to the XML nodes on the XML stream along with some high
level methods to send the predefined XML stanzas.

L<AnyEvent::XMPP::IM::Connection> is a more high level module, which is derived
from L<AnyEvent::XMPP::Connection>. It handles all the instant messaging client
functionality described in RFC 3921.

L<AnyEvent::XMPP::Client> is a multi account client class. It manages connections
to multiple XMPP accounts and tries to offer a nice high level interface
to XMPP communication.

lib/AnyEvent/XMPP/Connection.pm  view on Meta::CPAN


If you didn't provide a C<jid> (see above) you have to set the
C<username> which you want to connect as (see above) and the
C<$domain> to connect to.

B<NOTE:> This field has no effect if C<jid> is given!

=item resource => $resource

If this argument is given C<$resource> will be passed as desired
resource on resource binding.

Note: You have to take care that the stringprep profile for
resources can be applied at: C<$resource>. Otherwise the server
might signal an error. See L<AnyEvent::XMPP::Util> for utility functions
to check this.

=item host => $host

This parameter specifies the hostname where we are going
to connect to. The default for this is the C<domain> of the C<jid>.

lib/AnyEvent/XMPP/Connection.pm  view on Meta::CPAN


   my $proxy_cb = sub {
      my ($self, $er) = @_;
      $self->event (error => $er);
   };

   $self->reg_cb (
      xml_parser_error => $proxy_cb,
      sasl_error       => $proxy_cb,
      stream_error     => $proxy_cb,
      bind_error       => $proxy_cb,
      iq_auth_error    => $proxy_cb,
      iq_result_cb_exception => sub {
         my ($self, $ex) = @_;
         $self->event (error =>
            AnyEvent::XMPP::Error::Exception->new (
               exception => $ex, context => 'iq result callback execution'
            )
         );
      },
      tls_error => sub {

lib/AnyEvent/XMPP/Connection.pm  view on Meta::CPAN

      $self->{username},
      ($self->{use_host_as_sasl_hostname}
         ? $self->{host}
         : $self->{domain}),
      $self->{password}
   );
}

sub handle_stream_features {
   my ($self, $node) = @_;
   my @bind  = $node->find_all ([qw/bind bind/]);
   my @tls   = $node->find_all ([qw/tls starttls/]);

   # and yet another weird thingie: in XEP-0077 it's said that
   # the register feature MAY be advertised by the server. That means:
   # it MAY not be advertised even if it is available... so we don't
   # care about it...
   # my @reg   = $node->find_all ([qw/register register/]);

   if (not ($self->{disable_ssl}) && not ($self->{ssl_enabled}) && @tls) {
      $self->{writer}->send_starttls;

   } elsif (not $self->{authenticated}) {
      my $continue = 1;
      $self->event (stream_pre_authentication => \$continue);
      if ($continue) {
         $self->authenticate;
      }

   } elsif (@bind) {
      $self->do_rebind ($self->{resource});
   }
}

=item B<authenticate>

This method should be called after the C<stream_pre_authentication> event
was emitted to continue authentication of the stream.

Usually this method only has to be called when you want to register before
you authenticate. See also the documentation of the C<stream_pre_authentication>

lib/AnyEvent/XMPP/Connection.pm  view on Meta::CPAN


=cut

sub send_message {
   my ($self, $to, $type, $create_cb, %attrs) = @_;
   my $id = delete $attrs{id} || $self->{iq_id}++;
   $self->{writer}->send_message ($id, $to, $type, $create_cb, %attrs);
   $id
}

=item B<do_rebind ($resource)>

In case you got a C<bind_error> event and want to retry
binding you can call this function to set a new C<$resource>
and retry binding.

If it fails again you can call this again. Becareful not to
end up in a loop!

If binding was successful the C<stream_ready> event will be generated.

=cut

sub do_rebind {
   my ($self, $resource) = @_;
   $self->{resource} = $resource;
   $self->send_iq (
      set =>
         sub {
            my ($w) = @_;
            if ($self->{resource}) {
               simxml ($w,
                  defns => 'bind',
                  node => {
                     name => 'bind',
                     childs => [ { name => 'resource', childs => [ $self->{resource} ] } ]
                  }
               )
            } else {
               simxml ($w, defns => 'bind', node => { name => 'bind' })
            }
         },
         sub {
            my ($ret_iq, $error) = @_;

            if ($error) {
               # TODO: make bind error into a seperate error class?
               if ($error->xml_node ()) {
                  my ($res) = $error->xml_node ()->find_all ([qw/bind bind/], [qw/bind resource/]);
                  $self->event (bind_error => $error, ($res ? $res : $self->{resource}));
               } else {
                  $self->event (bind_error => $error);
               }

            } else {
               my @jid = $ret_iq->find_all ([qw/bind bind/], [qw/bind jid/]);
               my $jid = $jid[0]->text;
               unless ($jid) { die "Got empty JID tag from server!\n" }
               $self->{jid} = $jid;

               $self->event (stream_ready => $jid);
            }
         }
   );
}

lib/AnyEvent/XMPP/Connection.pm  view on Meta::CPAN

After this the connection will be disconnected.

=item sasl_error => $error

This event is emitted on SASL authentication error.

=item iq_auth_error => $error

This event is emitted when IQ authentication (XEP-0078) failed.

=item bind_error => $error, $resource

This event is generated when the stream was unable to bind to
any or the in C<new> specified resource. C<$error> is a L<AnyEvent::XMPP::Error::IQ>
object. C<$resource> is the errornous resource string or undef if none
was received.

The C<condition> of the C<$error> might be one of: 'bad-request',
'not-allowed' or 'conflict'.

Node: this is untested, I couldn't get the server to send a bind error
to test this.

=item connect => $host, $port

This event is generated when a successful TCP connect was performed to
the domain passed to C<new>.

Note: C<$host> and C<$port> might be different from the domain you passed to
C<new> if C<connect> performed a SRV RR lookup.

lib/AnyEvent/XMPP/Namespaces.pm  view on Meta::CPAN

our @EXPORT_OK = qw/xmpp_ns set_xmpp_ns_alias xmpp_ns_maybe/;
our @ISA = qw/Exporter/;

our %NAMESPACES = (
   client      => 'jabber:client',
   component   => 'jabber:component:accept',
   stream      => 'http://etherx.jabber.org/streams',
   streams     => 'urn:ietf:params:xml:ns:xmpp-streams',
   stanzas     => 'urn:ietf:params:xml:ns:xmpp-stanzas',
   sasl        => 'urn:ietf:params:xml:ns:xmpp-sasl',
   bind        => 'urn:ietf:params:xml:ns:xmpp-bind',
   tls         => 'urn:ietf:params:xml:ns:xmpp-tls',
   roster      => 'jabber:iq:roster',
   register    => 'jabber:iq:register',
   version     => 'jabber:iq:version',
   auth        => 'jabber:iq:auth',
   session     => 'urn:ietf:params:xml:ns:xmpp-session',
   xml         => 'http://www.w3.org/XML/1998/namespace',
   disco_info  => 'http://jabber.org/protocol/disco#info',
   disco_items => 'http://jabber.org/protocol/disco#items',
   register_f  => 'http://jabber.org/features/iq-register',

lib/AnyEvent/XMPP/Namespaces.pm  view on Meta::CPAN

There are already some aliases defined for the XMPP XML namespaces
which make handling of namepsaces a bit easier:

   stream  => http://etherx.jabber.org/streams
   xml     => http://www.w3.org/XML/1998/namespace

   streams => urn:ietf:params:xml:ns:xmpp-streams
   session => urn:ietf:params:xml:ns:xmpp-session
   stanzas => urn:ietf:params:xml:ns:xmpp-stanzas
   sasl    => urn:ietf:params:xml:ns:xmpp-sasl
   bind    => urn:ietf:params:xml:ns:xmpp-bind
   tls     => urn:ietf:params:xml:ns:xmpp-tls

   client  => jabber:client
   roster  => jabber:iq:roster
   version => jabber:iq:version
   auth    => jabber:iq:auth

   iq_oob  => jabber:iq:oob
   x_oob   => jabber:x:oob



( run in 0.970 second using v1.01-cache-2.11-cpan-2398b32b56e )