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

jabberoo-packet.cpp

00001 /* jabberoo-packet.cc
00002  * Jabber base packet
00003  *
00004  * Original Code Copyright (C) 1999-2001 Dave Smith (dave@jabber.org)
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  * 
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  * Contributor(s): Julian Missig
00021  *
00022  * This Original Code has been modified by IBM Corporation. Modifications 
00023  * made by IBM described herein are Copyright (c) International Business 
00024  * Machines Corporation, 2002.
00025  *
00026  * Date             Modified by     Description of modification
00027  * 01/20/2002       IBM Corp.       Updated to libjudo 1.1.1
00028  * 2002-03-05       IBM Corp.       Updated to libjudo 1.1.5
00029  */
00030 
00031 #include <packet.hh>
00032 
00033 using namespace judo; 
00034 
00035 namespace jabberoo {
00036 
00037 Packet::Packet(const std::string& name)
00038      : _base(name)
00039 {}
00040 
00041 Packet::Packet(const Element& t)
00042      : _base(t)
00043 {}
00044 
00045 const std::string Packet::getFrom() const
00046 {
00047      return _base.getAttrib("from");
00048 }
00049 
00050 const std::string Packet::getTo() const
00051 {
00052      return _base.getAttrib("to");
00053 }
00054 
00055 const std::string Packet::getID() const
00056 {
00057      return _base.getAttrib("id");
00058 }
00059 
00060 const std::string Packet::getError() const
00061 {
00062      return std::string(_base.getChildCData("error"));
00063 }
00064 
00065 const int Packet::getErrorCode() const
00066 {
00067      const Element* error = _base.findElement("error");
00068      if (error)
00069           return atoi(error->getAttrib("code").c_str());
00070      else
00071           return 0;
00072 }
00073 
00074 const std::string Packet::toString() const
00075 {
00076      return _base.toString();
00077 }
00078 
00079 const Element& Packet::getBaseElement() const
00080 {
00081      return _base;
00082 }
00083 
00084 void Packet::setFrom(const std::string& from)
00085 {
00086      _base.putAttrib("from", from);
00087 }
00088 
00089 void Packet::setTo(const std::string& to)
00090 {
00091      _base.putAttrib("to", to);
00092 }
00093 
00094 void Packet::setID(const std::string& id)
00095 {
00096      _base.putAttrib("id", id);
00097 }
00098 
00099 Element* Packet::addX()
00100 {
00101      return _base.addElement("x");
00102 }
00103 
00104 Element* Packet::addX(const std::string& tnamespace)
00105 {
00106      Element* x = _base.addElement("x");
00107      x->putAttrib("xmlns", tnamespace);
00108      return x;
00109 }
00110 
00111 Element* Packet::findX(const std::string& tnamespace) const
00112 {
00113      Element::const_iterator it = _base.begin();
00114      for (; it != _base.end(); it++)
00115      {
00116           if (((*it)->getType() == Node::ntElement) && 
00117               ((static_cast<Element*>(*it))->cmpAttrib("xmlns", tnamespace)))
00118                break;
00119      }
00120      if (it != _base.end())
00121           return static_cast<Element*>(*it);
00122      else
00123           return NULL;
00124 }
00125 
00126 void Packet::eraseX(const std::string& tnamespace)
00127 {
00128      Element::iterator it = _base.begin();
00129      for (; it != _base.end(); it++)
00130      {
00131           if (((*it)->getType() == Node::ntElement) && 
00132               ((static_cast<Element*>(*it))->cmpAttrib("xmlns", tnamespace)))
00133                break;
00134      }
00135      if (it != _base.end())
00136           static_cast<Element*>(*it)->erase(it);
00137 }
00138 
00139 Element& Packet::getBaseElement()
00140 {
00141      return _base;
00142 }
00143 
00144 } // namespace jabberoo

Generated on Thu Jul 24 13:31:50 2003 for jabberoo by doxygen1.3-rc3