📄 b2bconfig.cxx
字号:
/* ==================================================================== * The Vovida Software License, Version 1.0 * * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The names "VOCAL", "Vovida Open Communication Application Library", * and "Vovida Open Communication Application Library (VOCAL)" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact vocal@vovida.org. * * 4. Products derived from this software may not be called "VOCAL", nor * may "VOCAL" appear in their name, without prior written * permission of Vovida Networks, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * * ==================================================================== * * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc. For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. * */static const char* const B2bConfig_cxx_Version = "$Id: B2bConfig.cxx,v 1.8 2002/04/09 19:27:01 sprajpat Exp $";#include <unistd.h>#include <errno.h>#include "cpLog.h"#include "B2bConfig.hxx"#include "VException.hxx"B2bConfig* B2bConfig::myInstance = 0;string B2bConfig::B2B_PROV_DOMAIN="B2BUA_Config";string B2bConfig::PP_OPTIONAL="optional";string B2bConfig::PP_FREE="free";string B2bConfig::PP_MANDATORY="mandatory";string B2bConfig::SIP_LOCAL_PORT;string B2bConfig::SIP_LOCAL_TRANSPORT;string B2bConfig::SIP_PROXY_ADDR;string B2bConfig::SIP_PROXY_PORT;string B2bConfig::SIP_REG_REGISTER;string B2bConfig::SIP_REG_ADDR;string B2bConfig::SIP_REG_PORT;string B2bConfig::SIP_REG_EXPIRE; //Radius relatedstring B2bConfig::RAD_LOCAL_AUTH_PORT;string B2bConfig::RAD_LOCAL_ACCT_PORT;string B2bConfig::RAD_BILLING_ADDR;string B2bConfig::RAD_BILLING_PASSWD;string B2bConfig::RAD_BILLING_AUTH_PORT;string B2bConfig::RAD_BILLING_ACCT_PORT;//Prepaid relatedstring B2bConfig::PP_OPTIONS;string B2bConfig::PP_REFRESH_TIME;string B2bConfig::PP_GET_USERID_FROM;string B2bConfig::PP_USERID_DECODE_SCHEME;string B2bConfig::PP_USE_SIP_INFO;string B2bConfig::PP_USE_HTTP;//Redundancy to comeCfgSrc B2bConfig::myInitFlag=SRC_NONE; // 1=file, 2=provisioning///B2bConfig::B2bConfig() {}voidB2bConfig::initFromFile(const string& fileName){ assert(myInitFlag == SRC_NONE); //read the config file VFile cFile(fileName);// cpLog(LOG_INFO, "Reading configuration from file (%s)", // cFile.getFullName().c_str()); initKeysForFile(); myInitFlag = SRC_FILE; try { myParser = new VXmlParser(cFile); } catch(VException& e) { cpLog(LOG_WARNING, "Failed to read/parse config data, reason:%s", e.getDescription().c_str()); exit(0); }}voidB2bConfig::initFromProvisioning(const char* psHost, int psPort, const char* altHost, int altPort, int localSipPort){#ifdef MASCARPONE assert(myInitFlag == SRC_NONE); myInitFlag = SRC_PROV; cpLog(LOG_INFO, "Reading configuration from provisioning"); initKeysForProvisioning(); //Interface to provision server try { PSIFCreator psFactory; ProvisioningInterface& pif = psFactory.getPSIFInstance(psHost,psPort, altHost, altPort); //Find out its host char hostName[256]; int err = gethostname(hostName, 255); assert( err == 0 ); char hostPort[256]; sprintf(hostPort, "%s:%d", hostName, localSipPort); string filterRule = "(hostport='"; filterRule += hostPort; filterRule += "')"; myProvHandle = pif.getRecordsInDomain(B2B_PROV_DOMAIN, filterRule, myFieldList); if((myProvHandle->getStatus() != 200) || (myProvHandle->getNumMatches() == 0)) { cpLog(LOG_ALERT, "Failed to get Provisioning data, reason:%s", myProvHandle->getError().c_str()); exit(0); } } catch (VException& e) { cpLog(LOG_ALERT, "Failed to get Provisioning data, reason:%s", e.getDescription().c_str()); exit(0); }#endif}void B2bConfig::destroy( void ){ if (B2bConfig::myInstance != 0 ) { delete B2bConfig::myInstance; B2bConfig::myInstance = 0; }}///ostream& operator<<(ostream& os, const B2bConfig& data){ os << "B2bConfig:" << endl; os << "Local:" << endl; os.width(25); os << "Local port:" << data.getStr(B2bConfig::SIP_LOCAL_PORT) << endl; os.width(25); os << "Local transport:" << data.getStr(B2bConfig::SIP_LOCAL_TRANSPORT) << endl; os.width(25); os << endl; os.width(25); os << "Sip proxy addr:" << data.getStr(B2bConfig::SIP_PROXY_ADDR) << endl; os.width(25); os << "Sip proxy port:" << data.getStr(B2bConfig::SIP_PROXY_PORT) << endl; os << endl; os.width(25); os << "Register:" << data.getStr(B2bConfig::SIP_REG_REGISTER) << endl; os.width(25); os << "Registrar address:" << data.getStr(B2bConfig::SIP_REG_ADDR) << endl; os.width(25); os << "Registrar port:" << data.getStr(B2bConfig::SIP_REG_PORT) << endl; os.width(25); os << "Registration expires:" << data.getStr(B2bConfig::SIP_REG_EXPIRE) << endl; //Radius related os << endl; os.width(25); os << "Radius Auth port:" << data.getStr(B2bConfig::RAD_LOCAL_AUTH_PORT) << endl; os.width(25); os << "Radius Acct port:" << data.getStr(B2bConfig::RAD_LOCAL_ACCT_PORT) << endl; os.width(25); os << "Billing address:" << data.getStr(B2bConfig::RAD_BILLING_ADDR) << endl; os.width(25); os << "Billing passwd:" << data.getStr(B2bConfig::RAD_BILLING_PASSWD) << endl; os.width(25); os << "Billing Auth port:" << data.getStr(B2bConfig::RAD_BILLING_AUTH_PORT) << endl; os.width(25); os << "Billing Acct port:" << data.getStr(B2bConfig::RAD_BILLING_ACCT_PORT) << endl; //Prepaid related os << endl; os.width(25); os << "Billing option:" << data.getStr(B2bConfig::PP_OPTIONS) << endl; os.width(25); os << "Refresh time:" << data.getStr(B2bConfig::PP_REFRESH_TIME) << endl; os.width(25); os << "Get UserID from:" << data.getStr(B2bConfig::PP_GET_USERID_FROM) << endl; os.width(25); os << "UserID decoding scheme:" << data.getStr(B2bConfig::PP_USERID_DECODE_SCHEME) << endl; os.width(25); os << "Use SIP Info:" << data.getStr(B2bConfig::PP_USE_SIP_INFO) << endl; os.width(25); os << "Use Http:" << data.getStr(B2bConfig::PP_USE_HTTP) << endl; return os;}voidB2bConfig::notifyUpdate(const string& data, const string& fileName, bool delFlg){ cpLog(LOG_DEBUG, "Received update notification for file %s", fileName.c_str());}voidB2bConfig::initKeysForProvisioning(){#ifdef MASCARPONE SIP_LOCAL_PORT= "local_port"; myFieldList.push_back(SIP_LOCAL_PORT); SIP_LOCAL_TRANSPORT = "local_transport"; myFieldList.push_back(SIP_LOCAL_TRANSPORT); SIP_PROXY_ADDR = "proxy_server"; myFieldList.push_back(SIP_PROXY_ADDR); SIP_PROXY_PORT = "proxy_port"; myFieldList.push_back(SIP_PROXY_PORT); SIP_REG_REGISTER = "register"; myFieldList.push_back(SIP_REG_REGISTER); SIP_REG_ADDR = "register_address"; myFieldList.push_back(SIP_REG_ADDR); SIP_REG_PORT = "register_port"; myFieldList.push_back(SIP_REG_PORT); SIP_REG_EXPIRE = "register_expires"; myFieldList.push_back(SIP_REG_EXPIRE); //Radius related RAD_LOCAL_AUTH_PORT = "local_authentication_port"; myFieldList.push_back(RAD_LOCAL_AUTH_PORT); RAD_LOCAL_ACCT_PORT = "local_accounting_port"; myFieldList.push_back(RAD_LOCAL_ACCT_PORT); RAD_BILLING_ADDR = "billing_server_address"; myFieldList.push_back(RAD_BILLING_ADDR); RAD_BILLING_PASSWD = "billing_server_password"; myFieldList.push_back(RAD_BILLING_PASSWD); RAD_BILLING_AUTH_PORT = "billing_server_auth_port"; myFieldList.push_back(RAD_BILLING_AUTH_PORT); RAD_BILLING_ACCT_PORT = "billing_server_accounting_port"; myFieldList.push_back(RAD_BILLING_ACCT_PORT); //Prepaid related PP_OPTIONS = "billing_option"; myFieldList.push_back(PP_OPTIONS); PP_REFRESH_TIME = "billing_refresh_time"; myFieldList.push_back(PP_REFRESH_TIME); PP_GET_USERID_FROM = "extract_user_id_from"; myFieldList.push_back(PP_GET_USERID_FROM); PP_USERID_DECODE_SCHEME = "user_id_decode_scheme"; myFieldList.push_back(PP_USERID_DECODE_SCHEME); PP_USE_SIP_INFO = "use_sip_info"; myFieldList.push_back(PP_USE_SIP_INFO); PP_USE_HTTP = "use_http"; myFieldList.push_back(PP_USE_HTTP);#endif}voidB2bConfig::initKeysForFile(){ SIP_LOCAL_PORT= "Local:Port"; SIP_LOCAL_TRANSPORT = "Local:Transport"; SIP_PROXY_ADDR = "Proxy_Server:Address"; SIP_PROXY_PORT = "Proxy_Server:Port"; SIP_REG_REGISTER = "Registration:Register"; SIP_REG_ADDR = "Registration:Address"; SIP_REG_PORT = "Registration:Port"; SIP_REG_EXPIRE = "Registration:Expires"; //Radius related RAD_LOCAL_AUTH_PORT = "RADIUS:Authentication_Port"; RAD_LOCAL_ACCT_PORT = "RADIUS:Accounting_Port"; RAD_BILLING_ADDR = "Billing_Server:Address"; RAD_BILLING_PASSWD = "Billing_Server:Password"; RAD_BILLING_AUTH_PORT = "Billing_Server:Authentication_Port"; RAD_BILLING_ACCT_PORT = "Billing_Server:Accounting_Port"; //Prepaid related PP_OPTIONS = "PrePaid:Option"; PP_REFRESH_TIME = "PrePaid:Refresh_Time"; PP_GET_USERID_FROM = "PrePaid:Extract_User_Id_From"; PP_USERID_DECODE_SCHEME = "PrePaid:User_Id_Decode_Scheme"; PP_USE_SIP_INFO = "PrePaid:Use_SIP_INFO"; PP_USE_HTTP = "PrePaid:Use_HTTP"; //Redundancy to come}voidB2bConfig::breakIt(const string& src, string& left, string& right) const{ string::size_type pos = src.find(":"); assert(pos != string::npos); left = src.substr(0, pos); right = src.substr(pos+1, src.length() - pos);}stringB2bConfig::getStr(const string& key) const{ string retVal; if(myInitFlag == SRC_FILE) { string left, right; breakIt(key, left, right); retVal = myParser->getContent(left, right); } else {#ifdef MASCARPONE //Read from provisioning try { myProvHandle->getFieldValue(key, retVal); } catch(VException& e) { cpLog(LOG_ERR, "Failed to get value for field(%s), in domain (%s)", key.c_str(), B2B_PROV_DOMAIN.c_str()); }#endif } return retVal;}intB2bConfig::getInt(const string& key) const{ return(atoi(getStr(key).c_str()));}intB2bConfig::getLocalSipPort() const{ return (getInt(B2bConfig::SIP_LOCAL_PORT));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -