Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

pana_config_manager.cxx

00001 /* BEGIN_COPYRIGHT                                                        */
00002 /*                                                                        */
00003 /* Open Diameter: Open-source software for the Diameter and               */
00004 /*                Diameter related protocols                              */
00005 /*                                                                        */
00006 /* Copyright (C) 2002-2004 Open Diameter Project                          */
00007 /*                                                                        */
00008 /* This library is free software; you can redistribute it and/or modify   */
00009 /* it under the terms of the GNU Lesser General Public License as         */
00010 /* published by the Free Software Foundation; either version 2.1 of the   */
00011 /* License, or (at your option) any later version.                        */
00012 /*                                                                        */
00013 /* This library is distributed in the hope that it will be useful,        */
00014 /* but WITHOUT ANY WARRANTY; without even the implied warranty of         */
00015 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      */
00016 /* Lesser General Public License for more details.                        */
00017 /*                                                                        */
00018 /* You should have received a copy of the GNU Lesser General Public       */
00019 /* License along with this library; if not, write to the Free Software    */
00020 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307    */
00021 /* USA.                                                                   */
00022 /*                                                                        */
00023 /* In addition, when you copy and redistribute some or the entire part of */
00024 /* the source code of this software with or without modification, you     */
00025 /* MUST include this copyright notice in each copy.                       */
00026 /*                                                                        */
00027 /* If you make any changes that are appeared to be useful, please send    */
00028 /* sources that include the changed part to                               */
00029 /* diameter-developers@lists.sourceforge.net so that we can reflect your  */
00030 /* changes to one unified version of this software.                       */
00031 /*                                                                        */
00032 /* END_COPYRIGHT                                                          */
00033 
00034 
00035 #include "ace/Log_Msg.h"
00036 #include "ace/INET_Addr.h"
00037 #include "pana_config_manager.h"
00038 #include "pana_defs.h"
00039 #include "pana_exceptions.h"
00040 #include "pana_xml_parser.h"
00041 
00045 class PANA_XMLData : public PANA_XMLElementParser {
00046    public:
00053       PANA_XMLData(std::string &name, PANA_Cfg &data) :
00054                    PANA_XMLElementParser(name),
00055                        payload(data) { }
00056 
00062       int svc(DOMNode *n);
00063 
00064    protected:
00065 
00066       PANA_Cfg &payload; 
00067 };
00068 
00069 class PANA_XMLDataGeneral : public PANA_XMLElementParser {
00070    public:
00077       PANA_XMLDataGeneral(std::string &name, PANA_CfgGeneral &data) :
00078                           PANA_XMLElementParser(name),
00079                               payload(data) { }
00080 
00084       void print();
00085 
00091       int svc(DOMNode *n);
00092 
00093    protected:
00094 
00095       PANA_CfgGeneral &payload; 
00096 };
00097 
00098 class PANA_XMLRetransmissionParam : public PANA_XMLElementParser {
00099    public:
00106       PANA_XMLRetransmissionParam(std::string &name,
00107                                   PANA_CfgRetransmissionParam &data) :
00108                            PANA_XMLElementParser(name),
00109                            payload(data) { }
00110 
00114       void print();
00115 
00121       int svc(DOMNode *n);
00122 
00123    protected:
00124 
00125       PANA_CfgRetransmissionParam &payload; 
00126 };
00127 
00128 class PANA_XMLProviderInfo : public PANA_XMLElementParser {
00129    public:
00136       PANA_XMLProviderInfo(std::string &name, PANA_CfgProviderInfo &data) :
00137                            PANA_XMLElementParser(name),
00138                            payload(data) { }
00139 
00143       void print();
00144 
00150       int svc(DOMNode *n);
00151 
00155       std::string &banner() { return banner_; }
00156 
00157    protected:
00158 
00159       std::string banner_; 
00161       PANA_CfgProviderInfo &payload; 
00162 };
00163 
00164 class PANA_XMLDeviceId : public PANA_XMLElementParser {
00165    public:
00172       PANA_XMLDeviceId(std::string &name, PANA_DeviceId &data) :
00173                        PANA_XMLElementParser(name),
00174                        payload(data) { }
00175 
00179       void print();
00180 
00186       int svc(DOMNode *n);
00187 
00191       std::string &banner() { return banner_; }
00192 
00193    protected:
00194 
00195       std::string banner_; 
00197       PANA_DeviceId &payload; 
00198 };
00199 
00200 class PANA_XMLDataClient : public PANA_XMLElementParser {
00201    public:
00208       PANA_XMLDataClient(std::string &name, PANA_CfgClient &data) :
00209                            PANA_XMLElementParser(name),
00210                            payload(data) { }
00211 
00217       int svc(DOMNode *n);
00218 
00222       void print();
00223 
00224    protected:
00225 
00226       PANA_CfgClient &payload; 
00227 };
00228 
00229 class PANA_XMLDataAuthAgent : public PANA_XMLElementParser {
00230    public:
00237       PANA_XMLDataAuthAgent(std::string &name, PANA_CfgAuthAgent &data) :
00238                            PANA_XMLElementParser(name),
00239                            payload(data) { }
00240 
00246       int svc(DOMNode *n);
00247 
00251       void print();
00252 
00253    protected:
00254 
00255       PANA_CfgAuthAgent &payload; 
00256 };
00257 
00258 void PANA_XMLDataGeneral::print()
00259 {
00260     ACE_DEBUG((LM_INFO, "     General configuration\n"));
00261     ACE_DEBUG((LM_INFO, "          Listen Port     : %d\n", payload.listen_port_));
00262     ACE_DEBUG((LM_INFO, "          Interface name  : %s\n", payload.iface_name_.data()));
00263     ACE_DEBUG((LM_INFO, "          Protection Cap  : %d\n", payload.protection_capability_));
00264     ACE_DEBUG((LM_INFO, "          Dictionary      : %s\n", payload.dictionary_fname_.data()));
00265     ACE_DEBUG((LM_INFO, "          Mobility        : %d\n", payload.mobility_));
00266 }
00267 
00268 int PANA_XMLDataGeneral::svc(DOMNode *n)
00269 {
00270    std::string tagName;
00271 
00272    tagName = "listen_port";
00273    PANA_XMLDataUInt32 listen_port(tagName, payload.listen_port_);
00274    listen_port.populate(n->getFirstChild());
00275 
00276    tagName = "interface_name";
00277    PANA_XMLDataString iface_name(tagName, payload.iface_name_);
00278    iface_name.populate(n->getFirstChild());
00279 
00280    tagName = "protection_capability";
00281    PANA_XMLDataUInt32 pcap(tagName, payload.protection_capability_);
00282    pcap.populate(n->getFirstChild());
00283 
00284    tagName = "dictionary_filename";
00285    PANA_XMLDataString dict(tagName, payload.dictionary_fname_);
00286    dict.populate(n->getFirstChild());
00287 
00288    tagName = "mobility";
00289    PANA_XMLDataUInt32 mob(tagName, payload.mobility_);
00290    mob.populate(n->getFirstChild());
00291 
00292    print();
00293    
00294    tagName = "retransmission_param";
00295    PANA_XMLRetransmissionParam rt(tagName, payload.rt_);
00296    rt.populate(n->getFirstChild());
00297 
00298    return (0);
00299 }
00300 
00301 void PANA_XMLRetransmissionParam::print()
00302 {
00303     ACE_DEBUG((LM_INFO, "          Re-Transmission\n"));
00304     ACE_DEBUG((LM_INFO, "                     IRT  : %d\n", payload.irt_));
00305     ACE_DEBUG((LM_INFO, "                     MRC  : %d\n", payload.mrc_));
00306     ACE_DEBUG((LM_INFO, "                     MRT  : %d\n", payload.mrt_));
00307     ACE_DEBUG((LM_INFO, "                     MRD  : %d\n", payload.mrd_));
00308 }
00309 
00310 int PANA_XMLRetransmissionParam ::svc(DOMNode *n)
00311 {
00312    std::string tagName;
00313 
00314    tagName = "initial_rt_timeout";
00315    PANA_XMLDataUInt32 irt(tagName, payload.irt_);
00316    irt.populate(n->getFirstChild());
00317 
00318    tagName = "max_rt_count";
00319    PANA_XMLDataUInt32 mrc(tagName, payload.mrc_);
00320    mrc.populate(n->getFirstChild());
00321 
00322    tagName = "max_rt_timeout";
00323    PANA_XMLDataUInt32 mrt(tagName, payload.mrt_);
00324    mrt.populate(n->getFirstChild());
00325 
00326    tagName = "max_rt_duration";
00327    PANA_XMLDataUInt32 mrd(tagName, payload.mrd_);
00328    mrd.populate(n->getFirstChild());
00329 
00330    print();
00331 
00332    return (0);
00333 }
00334 
00335 void PANA_XMLProviderInfo::print()
00336 {
00337     ACE_DEBUG((LM_INFO, "          Provider Info [%s]:\n", banner_.data()));
00338     ACE_DEBUG((LM_INFO, "              Name : %s\n", payload.name_.data()));
00339     ACE_DEBUG((LM_INFO, "              ID   : %d\n", payload.id_));
00340 }
00341 
00342 int PANA_XMLProviderInfo ::svc(DOMNode *n)
00343 {
00344    std::string tagName;
00345 
00346    tagName = "id";
00347    PANA_XMLDataUInt32 id(tagName, payload.id_);
00348    id.populate(n->getFirstChild());
00349 
00350    tagName = "name";
00351    PANA_XMLDataString name(tagName, payload.name_);
00352    name.populate(n->getFirstChild());
00353 
00354    print();
00355 
00356    return (0);
00357 }
00358 
00359 void PANA_XMLDeviceId::print()
00360 {
00361     ACE_DEBUG((LM_INFO, "          EP Device Id      : %d, ",
00362                payload.type()));
00363 }
00364 
00365 int PANA_XMLDeviceId::svc(DOMNode *n)
00366 {
00367    std::string tagName;
00368    
00369    tagName = "type";
00370    ACE_UINT32 type;
00371    PANA_XMLDataUInt32 ptype(tagName, type);
00372    ptype.populate(n->getFirstChild());
00373    payload.type(PANA_DeviceId::TYPE(type));
00374 
00375    tagName = "id";
00376    std::string id;
00377    PANA_XMLDataString pid(tagName, id);
00378    pid.populate(n->getFirstChild());
00379 
00380    print();
00381 
00382    std::string &c_id = const_cast<std::string&>(payload.id());
00383    if (type == PANA_DeviceId::IPV4_ADDRESS) {
00384        char buf[128]; 
00385        ACE_OS::sprintf(buf, "%s:0", id.data());
00386        ACE_INET_Addr inet(buf);
00387        ACE_UINT32 ipAddr = ACE_HTONL(inet.get_ip_address());
00388 
00389        c_id.assign((char*)&ipAddr, sizeof(ACE_UINT32));
00390        
00391        ACE_DEBUG((LM_INFO, "[%s]\n", inet.get_host_addr()));
00392    }
00393    else {
00394        c_id.assign(id.data(), id.size());
00395    }
00396 
00397    return (0);
00398 }
00399 
00400 void PANA_XMLDataClient::print()
00401 {
00402     ACE_DEBUG((LM_INFO, "     Client configuration\n"));
00403     ACE_DEBUG((LM_INFO, "          PAA IP Adress   : %s\n", payload.paa_ip_address_.data()));
00404     ACE_DEBUG((LM_INFO, "          PAA Port Number : %d\n", payload.paa_port_number_));
00405     ACE_DEBUG((LM_INFO, "          PAA Mcast Addr  : %s\n", payload.paa_mcast_address_.data()));
00406     ACE_DEBUG((LM_INFO, "          PAA Mcast Port  : %d\n", payload.paa_mcast_port_number_));
00407     ACE_DEBUG((LM_INFO, "          Separate NAP/ISP: %d\n", payload.s_flag_));
00408 }
00409 
00410 int PANA_XMLDataClient::svc(DOMNode *n)
00411 {
00412    std::string tagName;
00413 
00414    tagName = "paa_ip_address";
00415    PANA_XMLDataString paa_ip(tagName, payload.paa_ip_address_);
00416    paa_ip.populate(n->getFirstChild());
00417 
00418    tagName = "paa_port_number";
00419    PANA_XMLDataUInt32 paa_port(tagName, payload.paa_port_number_);
00420    paa_port.populate(n->getFirstChild());
00421 
00422    tagName = "paa_mcast_address";
00423    PANA_XMLDataString paa_mcast(tagName, payload.paa_mcast_address_);
00424    paa_mcast.populate(n->getFirstChild());
00425 
00426    tagName = "paa_mcast_port_number";
00427    PANA_XMLDataUInt32 paa_mcast_port(tagName, payload.paa_mcast_port_number_);
00428    paa_mcast_port.populate(n->getFirstChild());
00429 
00430    tagName = "separate";
00431    PANA_XMLDataUInt32 separate(tagName, payload.s_flag_);
00432    separate.populate(n->getFirstChild());
00433 
00434    print();
00435 
00436    tagName = "isp_info";
00437    PANA_XMLProviderInfo isp(tagName, payload.isp_info_);
00438    isp.banner() = "ISP Info";
00439    isp.populate(n->getFirstChild());
00440 
00441    return (0);
00442 }
00443 
00444 void PANA_XMLDataAuthAgent::print()
00445 {
00446     ACE_DEBUG((LM_INFO, "     Auth Agent configuration\n"));
00447     ACE_DEBUG((LM_INFO, "          Separate NAP/ISP: %d\n", payload.s_flag_));
00448     ACE_DEBUG((LM_INFO, "          Use Cookie      : %d\n", payload.use_cookie_));
00449     ACE_DEBUG((LM_INFO, "          EAP Piggyback   : %d\n", payload.eap_piggyback_));
00450     ACE_DEBUG((LM_INFO, "          Session-Lifetime: %d\n", payload.sessionLifetime_));
00451     ACE_DEBUG((LM_INFO, "          Grace Period    : %d\n", payload.gracePeriod_));
00452     ACE_DEBUG((LM_INFO, "          Multicast Addr  : %s\n", payload.mcast_address_.data()));
00453     ACE_DEBUG((LM_INFO, "          Multicast Port  : %d\n", payload.mcast_port_number_));
00454     ACE_DEBUG((LM_INFO, "          Requested Dev Id: %d\n", payload.request_dev_id_));
00455 }
00456 
00457 int PANA_XMLDataAuthAgent::svc(DOMNode *n)
00458 {
00459    std::string tagName;
00460 
00461    tagName = "separate";
00462    PANA_XMLDataUInt32 separate(tagName, payload.s_flag_);
00463    separate.populate(n->getFirstChild());
00464 
00465    tagName = "use_cookie";
00466    PANA_XMLDataUInt32 ck(tagName, payload.use_cookie_);
00467    ck.populate(n->getFirstChild());
00468 
00469    tagName = "eap_piggyback";
00470    PANA_XMLDataUInt32 ep(tagName, payload.eap_piggyback_);
00471    ep.populate(n->getFirstChild());
00472 
00473    tagName = "session_lifetime";
00474    PANA_XMLDataUInt32 sessLifetime(tagName, payload.sessionLifetime_);
00475    sessLifetime.populate(n->getFirstChild());
00476 
00477    tagName = "grace_period";
00478    PANA_XMLDataUInt32 gracePeriod(tagName, payload.gracePeriod_);
00479    gracePeriod.populate(n->getFirstChild());
00480 
00481    tagName = "mcast_address";
00482    PANA_XMLDataString mcast(tagName, payload.mcast_address_);
00483    mcast.populate(n->getFirstChild());
00484 
00485    tagName = "mcast_port_number";
00486    PANA_XMLDataUInt32 mcast_port(tagName, payload.mcast_port_number_);
00487    mcast_port.populate(n->getFirstChild());
00488 
00489    tagName = "request_device_id_type";
00490    PANA_XMLDataUInt32 reqDevId(tagName, payload.request_dev_id_);
00491    reqDevId.populate(n->getFirstChild());
00492 
00493    print();
00494 
00495    tagName = "nap_info";
00496    PANA_XMLProviderInfo nap(tagName, payload.nap_info_);
00497    nap.banner() = "NAP Info";
00498    nap.populate(n->getFirstChild());
00499 
00500    ACE_UINT32 ndx = 0;
00501    char buf[32];
00502 
00503    tagName = "isp_info";
00504    DOMNode *sibling = n->getFirstChild();
00505    while (sibling != NULL) {
00506 
00507      if (sibling->getNodeType() == DOMNode::ELEMENT_NODE) {
00508 
00509          char *c_str = XMLString::transcode(sibling->getNodeName());
00510 
00511          if (XMLString::compareString(c_str, tagName.c_str()) == 0) {
00512 
00513              PANA_CfgProviderInfo *pInfo;
00514              ACE_NEW_NORETURN(pInfo, PANA_CfgProviderInfo);
00515 
00516              PANA_XMLProviderInfo isp(tagName, *pInfo);
00517              ACE_OS::sprintf(buf, "%s #%d", "ISP Info", ++ ndx);
00518              isp.banner() = buf;
00519              if (isp.populate(sibling) == 0) {
00520                  payload.isp_info_.push_back(pInfo);
00521              }
00522              else {
00523                  delete pInfo;
00524              }
00525          }
00526 
00527          XMLString::release(&c_str);
00528       }
00529       sibling = sibling->getNextSibling();
00530    }
00531 
00532    tagName = "ep_id";
00533    sibling = n->getFirstChild();
00534    while (sibling != NULL) {
00535 
00536      if (sibling->getNodeType() == DOMNode::ELEMENT_NODE) {
00537 
00538          char *c_str = XMLString::transcode(sibling->getNodeName());
00539 
00540          if (XMLString::compareString(c_str, tagName.c_str()) == 0) {
00541 
00542              PANA_DeviceId *devId;
00543              ACE_NEW_NORETURN(devId, PANA_DeviceId);
00544              
00545              PANA_XMLDeviceId pId(tagName, *devId);
00546              if (pId.populate(sibling) == 0) {
00547                  payload.ep_id_.push_back(devId);                 
00548              }
00549              else {
00550                  delete devId;
00551              }
00552          }
00553 
00554          XMLString::release(&c_str);
00555       }
00556       sibling = sibling->getNextSibling();
00557    }
00558 
00559    return (0);
00560 }
00561 
00562 int PANA_XMLData::svc(DOMNode *n)
00563 {
00564    std::string tagName;
00565 
00566    tagName = "general";
00567    PANA_XMLDataGeneral general(tagName, payload.general_);
00568    general.populate(n->getFirstChild());
00569 
00570    tagName = "client";
00571    PANA_XMLDataClient client(tagName, payload.client_);
00572    client.populate(n->getFirstChild());
00573 
00574    tagName = "auth_agent";
00575    PANA_XMLDataAuthAgent aa(tagName, payload.auth_agent_);
00576    aa.populate(n->getFirstChild());
00577 
00578    return (0);
00579 }
00580 
00581 PANA_CfgManager::PANA_CfgManager()
00582 {
00583 }
00584 
00585 PANA_CfgManager::~PANA_CfgManager()
00586 {
00587     // do nothing
00588 }
00589 
00590 void PANA_CfgManager::open(std::string &cfg_file)
00591 {
00592     std::string cfgRoot = "pana_configuration";
00593 
00594     PANA_XMLTreeParser parser;
00595     PANA_XMLData configData(cfgRoot, data_);
00596 
00597     if (parser.open(cfg_file, configData) != 0) {
00598         throw (PANA_Exception(PANA_Exception::CONFIG_ERROR, 
00599                               "Fatal: Unable to parse XML config file"));
00600     }
00601 }
00602 
00603 void PANA_CfgManager::close()
00604 {
00605    // free up allocated provider list
00606    PANA_CfgProviderInfo *i;
00607    PANA_CfgProviderList &ispList = data_.auth_agent_.isp_info_;
00608 
00609    while (! ispList.empty()) {
00610       i = ispList.front();
00611       if (i) {
00612          delete i;
00613       }
00614       ispList.pop_front();
00615    }
00616 }

Generated on Fri Jun 25 19:18:29 2004 for PANA by doxygen 1.3.5