Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members  

jabberoo::Packet Class Reference

A Jabber Packet with standard attributes. More...

#include <jabberoo.hh>

Inheritance diagram for jabberoo::Packet::

jabberoo::Message jabberoo::Presence List of all members.

Public Methods

 Packet (const string &name)
 Jabber Packet constructor with a base element of name. More...

 Packet (const Element &t)
 Jabber Packet constructor based upon a judo::Element Create a Jabber Packet based off of a judo::Element. More...

const string getFrom () const
 from attribute on the base element. More...

const string getTo () const
 to attribute on the base element. More...

const string getID () const
 id attribute on the base element. More...

const string getError () const
 error subelement of the base element. More...

const int getErrorCode () const
 code attribute on the error subelement. More...

const string toString () const
 XML string form of the Jabber Packet. More...

const Element& getBaseElement () const
 XML judo::Element form of the Jabber Packet. More...

void setFrom (const string &from)
 from attribute on the base element. More...

void setTo (const string &to)
 to attribute on the base element. More...

void setID (const string &id)
 id attribute on the base element. More...

Element* addX ()
 Add x element to the packet. More...

Element* addX (const string &tnamespace)
 Add x element to the packet. More...

Element* findX (const string &tnamespace) const
 Get the x (extension) element which has an xmlns of tnamespace. More...

Element& getBaseElement ()
 Access to the base element. More...


Protected Attributes

Element _base

Detailed Description

A Jabber Packet with standard attributes.

This class has accessors and modifiers for several common Jabber attributes and elements.

Definition at line 96 of file jabberoo.hh.


Constructor & Destructor Documentation

Packet::Packet ( const string & name )
 

Jabber Packet constructor with a base element of name.

Create a Jabber Packet with a base element of name.

Parameters:
name   A string base element name.

Definition at line 34 of file jabberoo-packet.cc.

00035      : _base(name)
00036 {}

Packet::Packet ( const Element & t )
 

Jabber Packet constructor based upon a judo::Element Create a Jabber Packet based off of a judo::Element.

Parameters:
t   A judo::Element

Definition at line 38 of file jabberoo-packet.cc.

00039      : _base(t)
00040 {}


Member Function Documentation

Element * Packet::addX ( const string & tnamespace )
 

Add x element to the packet.

Adds an x (extension) element to the Jabber Packet with the given namespace.

See also:
judo::Element , judo::Element::putAttrib()
Returns:
A pointer to the newly created judo::Element.

Definition at line 101 of file jabberoo-packet.cc.

00102 {
00103      Element* x = _base.addElement("x");
00104      x->putAttrib("xmlns", tnamespace);
00105      return x;
00106 }

Element * Packet::addX ( )
 

Add x element to the packet.

Adds an x (extension) element to the Jabber Packet. x elements should have an xmlns attribute.

See also:
judo::Element , judo::Element::putAttrib()
Returns:
A pointer to the newly created judo::Element.

Definition at line 96 of file jabberoo-packet.cc.

Referenced by jabberoo::Message::Message(), jabberoo::Message::requestComposing(), jabberoo::Message::requestDelivered(), and jabberoo::Message::requestDisplayed().

00097 {
00098      return _base.addElement("x");
00099 }

Element * Packet::findX ( const string & tnamespace ) const
 

Get the x (extension) element which has an xmlns of tnamespace.

See also:
judo::Element
Parameters:
tnamespace   The namespace of the x element to return.
Returns:
A pointer to the x element.

Definition at line 108 of file jabberoo-packet.cc.

Referenced by jabberoo::Message::Message(), jabberoo::Message::requestComposing(), jabberoo::Message::requestDelivered(), and jabberoo::Message::requestDisplayed().

00109 {
00110      Element::const_iterator it = _base.begin();
00111      for (; it != _base.end(); it++)
00112      {
00113           if (((*it)->getType() == Node::ntElement) && 
00114               ((static_cast<Element*>(*it))->cmpAttrib("xmlns", tnamespace)))
00115                break;
00116      }
00117      if (it != _base.end())
00118           return static_cast<Element*>(*it);
00119      else
00120           return NULL;
00121 }

Element & Packet::getBaseElement ( )
 

Access to the base element.

See also:
judo::Element
Returns:
A reference to the base element of the Jabber Packet as a judo::Element

Definition at line 123 of file jabberoo-packet.cc.

00124 {
00125      return _base;
00126 }

const Element & Packet::getBaseElement ( ) const
 

XML judo::Element form of the Jabber Packet.

Returns:
The XML forming the Jabber Packet as a judo::Element.
See also:
judo::Element

Definition at line 76 of file jabberoo-packet.cc.

00077 {
00078      return _base;
00079 }

const string Packet::getError ( ) const
 

error subelement of the base element.

Returns:
The string in the error subelement of the base element, NULL if the error subelement is nonexistent.

Definition at line 57 of file jabberoo-packet.cc.

00058 {
00059      return string(_base.getChildCData("error"));
00060 }

const int Packet::getErrorCode ( ) const
 

code attribute on the error subelement.

Returns:
The int in the code attribute on the error subelement, 0 if the code attribute or the error subelement is nonexistent.

Definition at line 62 of file jabberoo-packet.cc.

00063 {
00064      const Element* error = _base.findElement("error");
00065      if (error)
00066           return atoi(error->getAttrib("code").c_str());
00067      else
00068           return 0;
00069 }

const string Packet::getFrom ( ) const
 

from attribute on the base element.

Returns:
The string in the from attribute on the base element, NULL if the from attribute is nonexistent.

Definition at line 42 of file jabberoo-packet.cc.

Referenced by jabberoo::Message::Message(), jabberoo::Message::composing(), jabberoo::Message::delivered(), and jabberoo::Message::displayed().

00043 {
00044      return _base.getAttrib("from");
00045 }

const string Packet::getID ( ) const
 

id attribute on the base element.

Returns:
The string in the id attribute on the base element, NULL if the id attribute is nonexistent.

Definition at line 52 of file jabberoo-packet.cc.

Referenced by jabberoo::Message::composing(), jabberoo::Message::delivered(), and jabberoo::Message::displayed().

00053 {
00054      return _base.getAttrib("id");
00055 }

const string Packet::getTo ( ) const
 

to attribute on the base element.

Returns:
The string in the to attribute on the base element, NULL if the to attribute is nonexistent.

Definition at line 47 of file jabberoo-packet.cc.

00048 {
00049      return _base.getAttrib("to");
00050 }

void Packet::setFrom ( const string & from )
 

from attribute on the base element.

Parameters:
from   The JabberID to go in the from attribute on the base element, normally set by the server.

Definition at line 81 of file jabberoo-packet.cc.

00082 {
00083      _base.putAttrib("from", from);
00084 }

void Packet::setID ( const string & id )
 

id attribute on the base element.

Parameters:
id   The string id attribute on the base element.

Definition at line 91 of file jabberoo-packet.cc.

00092 {
00093      _base.putAttrib("id", id);
00094 }

void Packet::setTo ( const string & to )
 

to attribute on the base element.

Parameters:
to   The JabberID to send this packet to.

Definition at line 86 of file jabberoo-packet.cc.

Referenced by jabberoo::Message::Message(), and jabberoo::Presence::Presence().

00087 {
00088      _base.putAttrib("to", to);
00089 }

const string Packet::toString ( ) const
 

XML string form of the Jabber Packet.

Returns:
The XML forming the Jabber Packet as a string.

Definition at line 71 of file jabberoo-packet.cc.

00072 {
00073      return _base.toString();
00074 }


The documentation for this class was generated from the following files:
Generated at Tue Apr 16 17:09:06 2002 for jabberoo by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001