00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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 }