⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aaa_xml_data.cxx

📁 Diameter协议栈
💻 CXX
📖 第 1 页 / 共 2 页
字号:
/* BEGIN_COPYRIGHT                                                        *//*                                                                        *//* Open Diameter: Open-source software for the Diameter and               *//*                Diameter related protocols                              *//*                                                                        *//* Copyright (C) 2002-2004 Open Diameter Project                          *//*                                                                        *//* This library is free software; you can redistribute it and/or modify   *//* it under the terms of the GNU Lesser General Public License as         *//* published by the Free Software Foundation; either version 2.1 of the   *//* License, or (at your option) any later version.                        *//*                                                                        *//* This library is distributed in the hope that it will be useful,        *//* but WITHOUT ANY WARRANTY; without even the implied warranty of         *//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      *//* Lesser General Public License for more details.                        *//*                                                                        *//* You should have received a copy of the GNU Lesser General Public       *//* License along with this library; if not, write to the Free Software    *//* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307    *//* USA.                                                                   *//*                                                                        *//* In addition, when you copy and redistribute some or the entire part of *//* the source code of this software with or without modification, you     *//* MUST include this copyright notice in each copy.                       *//*                                                                        *//* If you make any changes that are appeared to be useful, please send    *//* sources that include the changed part to                               *//* diameter-developers@lists.sourceforge.net so that we can reflect your  *//* changes to one unified version of this software.                       *//*                                                                        *//* END_COPYRIGHT                                                          */#include "aaa_xml_data.h"#include "aaa_log_facility.h"#include "aaa_peer_interface.h"int AAA_XMLDataGeneral::svc(DOMNode *n){   std::string tagName;   tagName = "product";   OD_Utl_XMLDataString product(tagName, payload.product);   product.populate(n->getFirstChild());   tagName = "version";   OD_Utl_XMLDataUInt32 version(tagName, payload.version);   version.populate(n->getFirstChild());   tagName = "vendor_id";   OD_Utl_XMLDataUInt32 vendor_id(tagName, payload.vendor);   vendor_id.populate(n->getFirstChild());   AAA_ApplicationIdLst *idList[] = { &payload.supportedVendorIdLst,                                      &payload.authAppIdLst,                                      &payload.acctAppIdLst };   char *idNames[] = { "supported_vendor_id",                       "auth_application_id",                       "acct_application_id" };   for (int i=0; i<sizeof(idNames)/sizeof(char*); i++) {          tagName = idNames[i];       DOMNode *found, *sibling = n->getFirstChild();       while (sibling) {          diameter_unsigned32_t value;          OD_Utl_XMLDataUInt32 id(tagName, value);          if (id.populate(sibling, &found) == 0) {             idList[i]->push_back(value);              sibling = found->getNextSibling();          }          else {             break;          }       }   }   print(payload);   tagName = "vendor_specific_application_id";   DOMNode *found, *sibling = n->getFirstChild();   while (sibling) {      AAA_DataVendorSpecificApplicationId newId;      AAA_XMLDataVendorSpecificApplicationId id(tagName, newId);      if (id.populate(sibling, &found) == 0) {         payload.vendorSpecificId.push_back(newId);         sibling = found->getNextSibling();      }      else {         break;      }   }      return (0);}void AAA_XMLDataGeneral::print(AAA_DataGeneral &data){   AAA_LOG(LM_INFO, "(%P|%t)             Product : %s\n",                  data.product.data());   AAA_LOG(LM_INFO, "(%P|%t)             Version : %d\n",                  data.version);   AAA_LOG(LM_INFO, "(%P|%t)           Vendor Id : %d\n",                  data.vendor);   AAA_ApplicationIdLst *idList[] = { &data.supportedVendorIdLst,                                      &data.authAppIdLst,                                      &data.acctAppIdLst };   char *label[] = { "Supported Vendor",                     "Auth Application",                     "Acct Application" };   for (int i=0;        i < sizeof(idList)/sizeof(AAA_ApplicationIdLst*);        i++) {       AAA_ApplicationIdLst::iterator x = idList[i]->begin();       for (; x != idList[i]->end(); x++) {           AAA_LOG(LM_INFO, "(%P|%t)    %s : %d\n",                   label[i], *x);       }   }}int AAA_XMLDataParser::svc(DOMNode *n){   std::string tagName = "dictionary";   OD_Utl_XMLDataString dictionary(tagName, payload.dictionary);   dictionary.populate(n->getFirstChild());     AAA_XMLDataParser::print(payload);     return (0);}void AAA_XMLDataParser::print(AAA_DataParser &data){   AAA_LOG(LM_INFO, "(%P|%t)          Dictionary : %s\n",                  data.dictionary.data());  }int AAA_XMLDataVendorSpecificApplicationId::svc(DOMNode *n){   std::string tagName = "auth_application_id";   OD_Utl_XMLDataUInt32 auth(tagName, payload.authAppId);   if (auth.populate(n->getFirstChild()) < 0) {       payload.authAppId = 0;   }      tagName = "acct_application_id";   OD_Utl_XMLDataUInt32 acct(tagName, payload.acctAppId);   if (acct.populate(n->getFirstChild()) < 0) {       payload.acctAppId = 0;   }      tagName = "vendor_id";   DOMNode *found, *sibling = n->getFirstChild();   while (sibling) {      diameter_unsigned32_t vendorId;      OD_Utl_XMLDataUInt32 svid(tagName, vendorId);      if (svid.populate(sibling, &found) == 0) {         payload.vendorIdLst.push_back(vendorId);          sibling = found->getNextSibling();      }      else {         break;      }   }      print(payload);      return (0);}void AAA_XMLDataVendorSpecificApplicationId::print    (AAA_DataVendorSpecificApplicationId &e){   AAA_LOG(LM_INFO, "(%P|%t)  Vendor Specific Id : ");   if (e.authAppId > 0) {       AAA_LOG(LM_INFO, " Auth=%d ", e.authAppId);   }   if (e.acctAppId > 0) {       AAA_LOG(LM_INFO, " Acct=%d ", e.acctAppId);   }   AAA_LOG(LM_INFO, "%s\n", ((e.authAppId == 0) && (e.acctAppId == 0)) ? "---" : "");   AAA_ApplicationIdLst::iterator i = e.vendorIdLst.begin();   for (; i != e.vendorIdLst.end(); i++) {       AAA_LOG(LM_INFO, "(%P|%t)                        Vendor=%d\n",               (*i));   }}int AAA_XMLDataPeer::svc(DOMNode *n){   std::string tagName = "hostname";   OD_Utl_XMLDataString product(tagName, payload.hostname);   product.populate(n->getFirstChild());   tagName = "port";   OD_Utl_XMLDataUInt32 port(tagName, payload.port);   port.populate(n->getFirstChild());     tagName = "tls_enabled";   OD_Utl_XMLDataUInt32 tls(tagName, payload.tls_enabled);   tls.populate(n->getFirstChild());   AAA_PeerManager mngr(task);   if (mngr.Add(payload.hostname,                payload.port,                payload.tls_enabled,                0,                true)) {          AAA_Peer *newPeer = mngr.Lookup(payload.hostname);                                                          AAA_XMLDataPeer::print(*newPeer, true);   }   else {       AAA_LOG(LM_INFO, "(%P|%t) WARING !!! - Unable to add peer: %s\n",                payload.hostname.data());   }   return (0);}void AAA_XMLDataPeer::print(AAA_PeerEntry &e, bool label){   if (label) {      AAA_LOG(LM_INFO, "(%P|%t)                Peer : Host = %s, Port = %d, TLS = %d\n",                     e.Data().m_Identity.data(), e.Data().m_Port, e.Data().m_TLS);   }   else {      AAA_LOG(LM_INFO, "(%P|%t)                       Host = %s, Port = %d, TLS = %d\n",                     e.Data().m_Identity.data(), e.Data().m_Port, e.Data().m_TLS);   }}int AAA_XMLDataRouteAppPeerEntry::svc(DOMNode *n){   unsigned int metric;   std::string sname;   std::string tagName;   tagName = "server";   OD_Utl_XMLDataString server(tagName, sname);   server.populate(n->getFirstChild());   payload.Server() = sname;   tagName = "metric";   OD_Utl_XMLDataUInt32 met(tagName, metric);   met.populate(n->getFirstChild());   payload.Metric() = metric;   AAA_XMLDataRouteAppPeerEntry::print(payload);      return (0);}void AAA_XMLDataRouteAppPeerEntry::print(AAA_RouteServerEntry &server){   AAA_LOG(LM_INFO, "(%P|%t)                          Server = %s, metric = %d\n",                  server.Server().data(), server.Metric());}int AAA_XMLDataRouteApplication::svc(DOMNode *n){   diameter_unsigned32_t value;   std::string tagName, empty = "";   tagName = "application_id";   OD_Utl_XMLDataUInt32 appId(tagName, value);   appId.populate(n->getFirstChild());   payload.ApplicationId() = value;   tagName = "vendor_id";   OD_Utl_XMLDataUInt32 vendorId(tagName, value);   vendorId.populate(n->getFirstChild());   payload.VendorId() = value;   print(payload);      tagName = "peer_entry";   DOMNode *found = NULL, *sibling = n->getFirstChild();   while (sibling) {      AAA_RouteServerEntry *newPeer;      ACE_NEW_RETURN(newPeer, AAA_RouteServerEntry(empty), (-1));      AAA_XMLDataRouteAppPeerEntry peer(tagName, *newPeer);      if (peer.populate(sibling, &found) == 0) {         if (payload.Servers().Lookup(newPeer->Server())) {             AAA_LOG(LM_INFO, "(%P|%t)                              *Duplicate server (replacing previous)\n");         }         payload.Servers().Add(*newPeer);         sibling = found->getNextSibling();      }      else {	 delete newPeer;         break;      }   }      return (0);}void AAA_XMLDataRouteApplication::print(AAA_RouteApplication &a){   AAA_LOG(LM_INFO, "(%P|%t)                       Application Id=%d, Vendor=%d\n",           a.ApplicationId(), a.VendorId());}int AAA_XMLDataRoute::svc(DOMNode *n){   unsigned int role;    unsigned int usage;    std::string realm;   std::string tagName;   tagName = "realm";   OD_Utl_XMLDataString rlm(tagName, realm);   rlm.populate(n->getFirstChild());   payload.Realm() = realm;   tagName = "role";   OD_Utl_XMLDataUInt32 rle(tagName, role);   rle.populate(n->getFirstChild());   payload.Action() = AAA_ROUTE_ACTION(role);   tagName = "redirect_usage";   OD_Utl_XMLDataUInt32 redirectUsage(tagName, usage);   redirectUsage.populate(n->getFirstChild());   payload.RedirectUsage() = (AAA_REDIRECT_USAGE)usage;   tagName = "application";   DOMNode *found = NULL, *sibling = n->getFirstChild();   AAA_XMLDataRoute::print(payload);   while (sibling) {      AAA_RouteApplication *newApp;      ACE_NEW_RETURN(newApp, AAA_RouteApplication, (-1));      AAA_XMLDataRouteApplication app(tagName, *newApp);      if (app.populate(sibling, &found) == 0) {          if (payload.Lookup              (newApp->ApplicationId(),               newApp->VendorId())) {             AAA_LOG(LM_INFO, "(%P|%t)                        *Duplicate app id (replacing previous)\n");          }          payload.Add(*newApp);          sibling = found->getNextSibling();      }      else {	 delete newApp;         break;      }   }      return (0);}void AAA_XMLDataRoute::print(AAA_RouteEntry &e){   AAA_LOG(LM_INFO, "(%P|%t)              Route  : Realm = %s, Action = %d, Redirect-Usage = %d\n",                 e.Realm().data(), e.Action(), e.RedirectUsage());}int AAA_XMLDataPeerTable::svc(DOMNode *n){   unsigned int etime;    std::string tagName = "expiration_time";   OD_Utl_XMLDataUInt32 et(tagName, etime);   et.populate(n->getFirstChild());   AAA_PEER_TABLE()->ExpirationTime() = etime;   tagName = "peer";   DOMNode *found = NULL, *sibling = n->getFirstChild();   AAA_LOG(LM_INFO, "(%P|%t)  Peer Table :\n");   while (sibling) {      AAA_DataPeer newPeer;      AAA_XMLDataPeer peer(tagName, newPeer, task);      if (peer.populate(sibling, &found) == 0) {         sibling = found->getNextSibling();      }      else {         break;      }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -