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

📄 aaad_user_db.h

📁 AAA服务器功能实现
💻 H
字号:
/* 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                                                          */#ifndef __AAAD_USER_DB_H__#define __AAAD_USER_DB_H__#include "aaad_config.h"class AAAD_UserEapArchieMethod{   public:      std::string &SharedSecretFile() {	 return m_SharedSecretFile;      }      void Dump() {         AAAD_LOG(LM_INFO,                   "(%P|%t)  Shared secret: %s\n",                   m_SharedSecretFile.data());      }   private:      std::string m_SharedSecretFile;};class AAAD_UserEapMd5Method{   public:      typedef enum {	 SYSTEM,         FLAT,         NONE      } PASSWD_TYPE;   public:      std::string &Secret() {	 return m_Secret;      }      PASSWD_TYPE &PasswordType() {	 return m_PasswdType;      }      static PASSWD_TYPE PasswordType(std::string &t) {         static char *strType[] = {	   "system", "flat", "none" // same order as enum         };         for (int i = 0;               i < sizeof(strType)/sizeof(char*);              i ++) {	    if (t == strType[i]) {	       return PASSWD_TYPE(i);	    }	 }         return NONE;      }      void Dump() {         AAAD_LOG(LM_INFO,                   "(%P|%t) MD5 Passwd Typ: %d\n",                   (int)m_PasswdType);      }   private:      std::string m_Secret;      PASSWD_TYPE m_PasswdType;};class AAAD_UserEntry :   public AAAD_MapElement{   public:      std::string &Method() {	 return m_Method;      }      AAAD_UserEapMd5Method &Md5() {	 return m_Md5;      }      AAAD_UserEapArchieMethod &Archie() {	 return m_Archie;      }      void Dump() {         AAAD_LOG(LM_INFO,                   "(%P|%t) *** Match User: %s\n",                   m_Name.data());         AAAD_LOG(LM_INFO,                   "(%P|%t)         Method: %s\n",                   m_Method.data());         m_Md5.Dump();         m_Archie.Dump();      }   private:      std::string m_Method;      AAAD_UserEapMd5Method m_Md5;      AAAD_UserEapArchieMethod m_Archie;};typedef AAAD_Map AAAD_UserDb;typedef ACE_Singleton<AAAD_UserDb,                       ACE_Recursive_Thread_Mutex>                       AAAD_UserDb_S;#define AAAD_USER_DB()   (*(AAAD_UserDb_S::instance()))class AAAD_ParserArchieMethod :    public OD_Utl_XMLElementParserWithData<AAAD_UserEapArchieMethod>{   public:      AAAD_ParserArchieMethod(const char *name,                              AAAD_UserEapArchieMethod &p) :          OD_Utl_XMLElementParserWithData<AAAD_UserEapArchieMethod>                              (name, p) {      }      virtual int svc(DOMNode *n) {         OD_Utl_XMLDataString sfile("shared_secret_file",                                     m_Payload.SharedSecretFile());         sfile.populate(n->getFirstChild());         return 0;      }};class AAAD_ParserMd5Method :    public OD_Utl_XMLElementParserWithData<AAAD_UserEapMd5Method>{   public:      AAAD_ParserMd5Method(const char *name,                           AAAD_UserEapMd5Method &p) :          OD_Utl_XMLElementParserWithData<AAAD_UserEapMd5Method>                              (name, p) {      }      virtual int svc(DOMNode *n) {         OD_Utl_XMLDataString sfile("secret",                                     m_Payload.Secret());         sfile.populate(n->getFirstChild());	 std::string type;         OD_Utl_XMLDataString ptype("password_type", type);         ptype.populate(n->getFirstChild());         m_Payload.PasswordType() =               AAAD_UserEapMd5Method::PasswordType(type);         return 0;      }};class AAAD_ParserUserEntry :    public OD_Utl_XMLElementParser{   public:      AAAD_ParserUserEntry(const char *name) :          OD_Utl_XMLElementParser(name) {      }      virtual int svc(DOMNode *n) {         std::auto_ptr<AAAD_MapElement>             u(new AAAD_UserEntry);         AAAD_UserEntry &uRef = (AAAD_UserEntry&)(*u);         OD_Utl_XMLDataString name("name_match", uRef.Name());         name.populate(n->getFirstChild());         OD_Utl_XMLDataString method("eap_method", uRef.Method());         method.populate(n->getFirstChild());         AAAD_ParserArchieMethod archie("archie", uRef.Archie());         archie.populate(n->getFirstChild());         AAAD_ParserMd5Method md5("md5", uRef.Md5());         md5.populate(n->getFirstChild());         AAAD_USER_DB().Register(u);         return 0;      }};class AAAD_ParserDefaultUserEntry :    public OD_Utl_XMLElementParserWithData<AAAD_UserEntry>{   public:      AAAD_ParserDefaultUserEntry(const char *name,                                  AAAD_UserEntry &u) :          OD_Utl_XMLElementParserWithData<AAAD_UserEntry>(name, u) {      }      virtual int svc(DOMNode *n) {         OD_Utl_XMLDataString method("eap_method",                                      m_Payload.Method());         method.populate(n->getFirstChild());         AAAD_ParserArchieMethod archie("archie",                                      m_Payload.Archie());         archie.populate(n->getFirstChild());         AAAD_ParserMd5Method md5("md5", m_Payload.Md5());         md5.populate(n->getFirstChild());         m_Payload.Name() = "default";         return 0;      }};class AAAD_ParserUserDb :    public OD_Utl_XMLElementParser{   public:      AAAD_ParserUserDb(const char *name) :         OD_Utl_XMLElementParser(name) {      }      virtual int svc(DOMNode *n) {         AAAD_ParserMultiElement<AAAD_ParserUserEntry>              users("user_entry");         users.populate(n);         std::auto_ptr<AAAD_MapElement>             u(new AAAD_UserEntry);         AAAD_ParserDefaultUserEntry defEntry             ("default_entry", (AAAD_UserEntry&)*u);         defEntry.populate(n->getFirstChild());         AAAD_USER_DB().Register(u);         return (0);      }};class AAAD_UserDbLoader{   public:      AAAD_UserDbLoader(const char *name) {         Open(name);      }   protected:      int Open(const char *name) {         OD_Utl_XMLTreeParser parser;         AAAD_ParserUserDb root("user_db");         return parser.open(name, root);      }};#endif // __AAAD_USER_DB_H__

⌨️ 快捷键说明

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