S11nInetdItem.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 $Header$
00004 
00005 */
00006 
00007 #include "Parser.h"
00008 #include "Config.h"
00009 
00010 #include "S11nInetdItem.h"
00011 
00012 template<>
00013 int S11n<InetdItem>::toString(const InetdItem &value, String &str)
00014 {
00015   str =  value.service + INETD_ITEM_DELIMITER +
00016          String::number(value.port) + INETD_ITEM_DELIMITER +
00017          value.login + INETD_ITEM_DELIMITER +
00018          value.password + INETD_ITEM_DELIMITER +
00019          value.allow + INETD_ITEM_DELIMITER +
00020          value.deny + INETD_ITEM_DELIMITER;
00021   return OK;
00022 }
00023 
00024 template<>
00025 int S11n<InetdItem>::fromString(const String &str, InetdItem &value)
00026 {
00027   StringList list;
00028   unsigned int i, size;
00029   int res;
00030 
00031   if (FAILED(res = Parser::split(str, list, 0, INETD_ITEM_DELIMITER)))
00032     return ERROR_BACKTRACE(res);
00033   if ((size = list.size()) < 2)
00034     return ERROR(MSG_CONFIG_WRONG_FORMAT, CSTRING(str));
00035 
00036   for (i = 0; i < size; ++i)
00037     switch (i) {
00038       case 0:
00039         value.service = list[i];
00040         break;
00041       case 1:
00042         if (FAILED(res = list[i].toUint(value.port)))
00043           return ERROR_BACKTRACE(res);
00044         break;
00045       case 2:
00046         value.login = list[i];
00047         break;
00048       case 3:
00049         value.password = list[i];
00050         break;
00051       case 4:
00052         value.allow = list[i];
00053         break;
00054       case 5:
00055         value.deny = list[i];
00056         break;
00057     }
00058   return OK;
00059 }
00060 
00061 template<>
00062 int S11n<InetdItem>::toXml(const InetdItem &value, XmlElement *element)
00063 {
00064   CHECK_POINTER(element);
00065 
00066   int res;
00067 
00068   if (FAILED(res = element->removeChildren()))
00069     return ERROR_BACKTRACE(res);
00070 
00071   XmlElement *root =
00072     new XmlElement(XML_TAG_SERVICE, new XmlAttribute(XML_ATTR_VALUE, value.service), "",
00073       new XmlElement(XML_TAG_PORT,     NULL, String::number(value.port), NULL,
00074       new XmlElement(XML_TAG_LOGIN,    NULL, value.login, NULL,
00075       new XmlElement(XML_TAG_PASSWORD, NULL, value.password, NULL,
00076       new XmlElement(XML_TAG_ALLOW,    NULL, value.allow, NULL,
00077       new XmlElement(XML_TAG_DENY,     NULL, value.deny)))))
00078     );
00079   if (FAILED(res = element->appendChild(root)))
00080     return ERROR_BACKTRACE(res);
00081 
00082   return OK;
00083 }
00084 
00085 template<>
00086 int S11n<InetdItem>::fromXml(const XmlElement *element, InetdItem &value)
00087 {
00088   CHECK_POINTER(element);
00089 
00090   XmlElementCollection *children = element->children();
00091   unsigned int i, size = children->size();
00092   XmlElement *e;
00093   int res;
00094 
00095   value.clear();
00096 
00097   for (i = 0; i < size; ++i) {
00098     e = children->at(i);
00099     if (e->tag().equals(XML_TAG_SERVICE, true)) {
00100       if (FAILED(res = e->attribute(XML_ATTR_NAME, value.service)))
00101         return ERROR_BACKTRACE(res);
00102 
00103       XmlElementCollection *children = e->children();
00104       unsigned int i, size = children->size();
00105       XmlElement *el;
00106 
00107       for (i = 0; i < size; ++i) {
00108         el = children->at(i);
00109         if (el->tag().equals(XML_TAG_PORT, true)) {
00110           if (FAILED(res = el->innerData().toUint(value.port)))
00111             return ERROR_BACKTRACE(res);
00112         } else
00113             if (el->tag().equals(XML_TAG_LOGIN, true))
00114               value.login = el->innerData();
00115             else
00116               if (el->tag().equals(XML_TAG_PASSWORD, true))
00117                 value.password = el->innerData();
00118               else
00119                 if (el->tag().equals(XML_TAG_ALLOW, true))
00120                   value.allow = el->innerData();
00121                 else
00122                   if (el->tag().equals(XML_TAG_DENY, true))
00123                     value.deny = el->innerData();
00124       }
00125     }
00126   }
00127 
00128   return OK;
00129 }

Generated on Thu Sep 6 20:11:25 2007 for Pylon Application Platform by  doxygen 1.5.1