SYNOPSIS

Inherit from this base class when implementing specifc protocol extentions that may exist when writing to support various other jabber server implementations.

DESCRIPTION

PCJ::Protocol is the base class used when differences between authentication or other connection initialization methods require special processing.

A prime example is \s-1JABBER\s0(tm) vs. \s-1XMPP\s0. The Jabber protocol uses a much different method to authenticate (ie. using the iq:auth namespace) than \s-1XMPP\s0 which uses \s-1SASL\s0. While the rest of the protocol is substantially unchanged, these differences mean they must be accounted. In the 1.x versions of \s-1PCJ\s0, this was solved by having different duplicate classes in the same domain with these differences manifest. It led to lots of headaches if there was a problem because it then needed to be fixed in four places.

The solution is to keep the core aspect of \s-1PCJ\s0 immutable, while loading separate individual Protocol classes that then implement the details for each specific dialect.

As an end developer, if you wish to add support for another dialect (ie. support another jabber server implementation that does service management differently), subclass from this module and then add your entry into the ProtocolFactory.

Also be aware that \s-1PCJ\s0 uses object_states to construct its own session. Protocol subclassees are expected to fit smoothly into that. See the \s-1METHOD\s0 get_states() for more information.

And remember when you are finished handling the protocol specifics and the connection is finished, fire off the \s-1PCJ_INIT_FINISHED\s0 status, and call relinquish_states() from the $_[\s-1HEAP\s0] object to return control back to the \s-1PCJ\s0 Core. (Yes, you read that correctly, $_[\s-1HEAP\s0] is actually the \s-1PCJ\s0 object).

If in doubt, please see the source code for the other Protocol subclasses (ie. \s-1XMPP\s0.pm, J14.pm, etc).

METHODS

At a bare minimum, some methods must be implemented by the end developer. These will be indicated with a \s-1MANDATORY\s0 flag.

new() [\s-1OPTIONAL\s0]

new() provides a default constructor. It returns a hash reference blessed into the provided class

get_version() [\s-1MANDATORY\s0]

get_version() is used by \s-1PCJ\s0 to populate the 'version' attribute in the opening <stream:stream/>. For \s-1XMPP\s0 enabled clients, this must return '1.0'. For legacy Jabber connections, it should return '0.9' but it isn't required. For all other applications, see the appropriate \s-1RFC\s0 for details on what version it expects.

get_xmlns() [\s-1MANDATORY\s0]

get_xmlns() is used by \s-1PCJ\s0 to populate the default \s-1XML\s0 namespace attribute in the opening <stream:stream/>. Please feel free to use the constants in POE::Filter::XML::NS to provide this.

get_states() [\s-1MANDATORY\s0]

get_states is used by \s-1PCJ\s0 to fill its object_states with the Protocol states. An array reference containing event names should be returned that corespond one-to-one with the methods you implement in your subclass. Or if a mapping is required, a hash reference should be returned that includes the mapping. See POE::Session for more detail on object_states.

get_input_event() [\s-1MANDATORY\s0]

get_input_event() returns the main entry point event into the Protocol subclass. This is then used by \s-1PCJ\s0 to assign the event to the Wheel, so that the Protocol's events get fired from Wheel events.

get_error_event() [\s-1OPTIONAL\s0]

get_error_event() returns the event to be called when an error occurs in the Wheel. Typically, this isn't required for Protocol subclasses, but is available if needed.

get_flushed_event() [\s-1OPTIONAL\s0]

get_flushed_event() returns the event to be called when the flushed event occurs in the Wheel. Typically, this isn't required for Protocol subclasses, but is available if needed.

NOTES

Here are some quick tips to keep in mind when subclassing:

Protocol subclassees execute within the same Session space as \s-1PCJ\s0 $_[\s-1HEAP\s0] contains the \s-1PCJ\s0 object. If you need storage space, use $_[\s-1OBJECT\s0] (ie. yourself). Send status events. See PCJ::Status Don't forget to send \s-1PCJ_READY\s0. And don't forget to call $_[\s-1HEAP\s0]->relinquish_states() when finished. When in doubt, use the source!

AUTHOR

Copyright (c) 2007-2009 Nicholas Perez. Distributed under the \s-1GPL\s0.