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

📄 pserver.cxx

📁 SIP(Session Initiation Protocol)是由IETF定义
💻 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 pserver_cxx_Version =    "$Id: pserver.cxx,v 1.34 2002/11/09 02:03:38 derekm Exp $";#include <cstdio>#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#include "Daemon.hxx"#include "ProvisionServer.hxx"#include "VEnvVar.hxx"#include "VException.hxx"#include "cpLog.h"#include "NetworkAddress.h"#include "ConfFile.hxx"#include "Data.hxx"#include <set>#include "vocalconfig.h"using Vocal::ConfFile;void convertHostPort(string& hostname, int& port, string pair, const char* c){    string::size_type start;    string::size_type len;    start = pair.find(":");    len = pair.length();    hostname = (pair.substr(0, start));    if (start != string::npos)    {        string Port = (pair.substr(start + 1, len));        port = atoi(Port.c_str());    }    else    {        cerr << "argument -" << c << " requires host AND port" << endl;        exit( -1);    }    NetworkAddress tempAddr(hostname, port);    hostname = tempAddr.getIpName().convertString();}int main(int argc, char** argv){    char c;    extern char *optarg;    int rFlg = 0, vFlg = 0, pFlg = 0, nFlg = 0;    int lFlg = 0, sFlg= 0;    bool daemonMode = true;    string psRoot, logLevel;    string logFile;    string hostname = "";    int port = 6005;    int lPort = 6005;    int nbins = 6;    int nthreads = 25;    string mhost = "";    int mport = -1;    Data configFile = VOCAL_INSTALL_PATH;    configFile += "/etc/vocal.conf";    bool useConfigFile = true;    bool requireTls = false;    bool useTls = true;    string confFileBase = VOCAL_INSTALL_PATH;    confFileBase += "/etc";    set <char> hasOpt;        try    {        // parse the command line options        while (1)        {            c = getopt(argc, argv, "c:sr:v:f:b:p:u:t:M:N:d");            if (c == -1) break;            hasOpt.insert(c);            switch (c)            {            case 'c':                configFile = optarg;            case 'd':                daemonMode = false;                break;            case 'r':                psRoot = optarg;                rFlg++;                break;            case 'v':                logLevel = optarg;                vFlg++;                break;            case 'u':                if (!nFlg)                {                    nbins = atoi(optarg);                    nbins = 1 + (nbins / 200);                }                break;            case 'n':                useConfigFile = false;                break;            case 'N':                nFlg = 1;                nbins = atoi(optarg);                break;            case 't':                nthreads = atoi(optarg);                break;            case 'M':                convertHostPort(mhost, mport, optarg, "M");                break;            case 'f':                lFlg++;                logFile = optarg;                break;            case 's':                sFlg++;                break;            case 'b':                convertHostPort(hostname, port, optarg, "b");                break;            case 'p':                pFlg++;                lPort = atoi(optarg);                break;            case '?':                cerr << "Unknown arg" << endl;                cerr << "Usage:  " << argv[0] << " [OPTION]..." << endl;                cerr << endl;                cerr << "  Where [OPTION] is one of: " << endl;                cerr << "    -c <conf_file>                      " <<                    "    specify config file" << endl;                cerr << "    -n                                  " <<                    "    do not read from config file" << endl;                cerr << "    -v <log_level>                      " <<                    "    set verbosity" << endl;                cerr << "    -r <psRootFileSystem>               " <<                    "    set file system root" << endl;                cerr << "    -f <logfile>                        " <<                    "    set log file" << endl;                cerr << "    -b <redundant server host:port>     " <<                    "    set redundant (\"backup\") server\n" <<                    "                                        " <<                    "      hostname and port" << endl;                cerr << "    -p <local port>                     " <<                    "    set port to listen for incoming\n" <<                    "                                        " <<                    "      requests" << endl;                cerr << "    -d                                  " <<                    "    disable daemon mode (run in \n" <<                    "                                        " <<                    "      foreground)" << endl;                cerr << "    -u <number of users (1000)>         " <<                    "    number of users." << endl;                cerr << "    -N <number of bins>                 " <<                    "    number of hash bins " <<                    "                                               " <<                    "               (overrides number users)."                     << endl;                cerr << "    -t <number of threads (25)>         " <<                    "    number of request proccess threads." << endl;                cerr << "    -M <multicast host (224.0.0.100):port(9000)>" <<                    "    multicast host and port." << endl;                cerr << "    -s                                  " <<                    "    log via syslog." << endl;                cerr << endl;                exit( -1);                break;            }        }        ConfFile configFileMap;        if(useConfigFile)        {            configFileMap.parse( configFile );            if(configFileMap.find("NO_DAEMON") != configFileMap.end())            {                if(configFileMap.find("NO_DAEMON")->second == "1")                {                    daemonMode = false;                }            }            if(configFileMap.find("LOGFILE") != configFileMap.end() &&               hasOpt.find('f') == hasOpt.end() )            {                LocalScopeAllocator lo;                cpLogOpen(configFileMap["LOGFILE"].getData(lo));            }            if(configFileMap.find("LOGLEVEL") != configFileMap.end() &&               hasOpt.find('v') == hasOpt.end() )            {                logLevel = configFileMap["LOGLEVEL"].convertString();            }            if(configFileMap.find("USE_SYSLOG") != configFileMap.end() &&               hasOpt.find('s') == hasOpt.end() )            {                if(configFileMap.find("USE_SYSLOG")->second == "1")                {                    cpLogOpenSyslog();                }            }            if(configFileMap.find("PSERVERBACKUP") != configFileMap.end() &&               configFileMap.find("PSERVER") != configFileMap.end() &&               hasOpt.find('b') == hasOpt.end() )            {                if (configFileMap.find("PSERVERBACKUP")->second !=                     configFileMap.find("PSERVER")->second)                {                    string pair = configFileMap.find("PSERVERBACKUP")->                        second.convertString();                    convertHostPort(hostname, port, pair, "PSERVERBACKUP");                }            }            if(configFileMap.find("PSERVERMCAST") != configFileMap.end())            {                string pair = configFileMap.find("PSERVERMCAST")->                    second.convertString();                convertHostPort(mhost, mport, pair, "PSERVERMCAST");            }            if(configFileMap.find("REQUIRE_TLS") != configFileMap.end())            {                if(configFileMap.find("REQUIRE_TLS")->second == "1")                {                    if(TlsConnection::hasTls())                    {                        // require TLS                        requireTls = true;                    }                    else                    {                        // cannot require TLS and not have it!                        cpLog(LOG_ALERT, "REQUIRE_TLS specified, but TLS not available");                        cerr << "REQUIRE_TLS specified, but TLS not availble" << endl;                        exit(1);                    }                }            }            if(configFileMap.find("USE_TLS") != configFileMap.end())            {                if(configFileMap.find("USE_TLS")->second == "0")                {                    cpLog(LOG_DEBUG, "USE_TLS set to 0");                    useTls = false;                }                else if(TlsConnection::hasTls())                {                    cpLog(LOG_DEBUG, "USE_TLS set to 1");                    // require TLS                    useTls = true;                }                else                {                    // cannot require TLS and not have it!                    cpLog(LOG_ALERT, "USE_TLS specified, but TLS not available");                    cerr << "USE_TLS specified, but TLS not availble" << endl;                    exit(1);                }            }            if(configFileMap.find("CONFFILE_BASE") != configFileMap.end())            {                confFileBase = configFileMap.find("CONFFILE_BASE")->second.convertString();            }        }                    if (daemonMode)        {            Daemon();        }        if(lFlg)        {            cpLogOpen(logFile.c_str());        }        if(sFlg)        {             cpLogOpenSyslog();        }        // Set the umask so that others only have read permission        umask(S_IWOTH);        // Set the Provision server root file-system if given by the        // user else default to "/usr/local/provisioning_data/"        if (rFlg)        {            VEnvVar vVar("VPS_FILESYSTEM", psRoot.c_str());            VEnvVar::VPS_FILESYSTEM = vVar;            cerr << "Setting root " << VEnvVar::VPS_FILESYSTEM.value()            << endl;        }        else        {            VEnvVar vVar("VPS_FILESYSTEM",                          VOCAL_INSTALL_PATH "/provisioning_data");            VEnvVar::VPS_FILESYSTEM = vVar;            cerr << "Setting root " << VEnvVar::VPS_FILESYSTEM.value()            << endl;        }        if (pFlg)        {            char buf[256];            sprintf(buf, "%d", lPort);            string daPort = buf;            VEnvVar vVar("VPS_PORT", daPort);            VEnvVar::VPS_PORT = vVar;            cerr << "Setting port " << VEnvVar::VPS_PORT.value()            << endl;        }        else        {            VEnvVar vVar("VPS_PORT",                         "6005");            VEnvVar::VPS_PORT = vVar;            cerr << "Setting port " << VEnvVar::VPS_PORT.value()            << endl;        }        if (vFlg)        {            char buf[56];            sprintf(buf, "%d", cpLogStrToPriority(logLevel.c_str()));            VEnvVar vVar("VLOG_LEVEL", buf );            VEnvVar::VLOG_LEVEL = vVar;        }        // if they specify a host to user redundant mode, we need to        // ensure they specify a host and port for broadcast.        if (hostname != "")        {            if (mhost == "" || mport == -1)            {                cerr << "\n\n\nFailed to start PS!" << endl;                cerr << "You must specify a multicast address and port "                     << "with the -M " << endl                     << "option to use redundancy.\n\n\n" << endl;                exit(1);            }                                                    ProvisionServer::instance(nbins,                                       nthreads,                                       requireTls,                                      useTls,                                      confFileBase,                                      mhost,                                       mport,                                       hostname,                                       port).run();        }        else        {            ProvisionServer::instance(nbins,                                       nthreads,                                      requireTls,                                      useTls,                                      confFileBase).run();        }    }    catch (VException& e)    {        cerr << "Appplication exiting, reason:" << e.getDescription() << endl;    }    catch (...)    {        cerr << "Appplication exiting, reason:Unknown" << endl;    }}/* Local Variables: *//* c-file-style: "stroustrup" *//* indent-tabs-mode: nil *//* c-file-offsets: ((access-label . -) (inclass . ++)) *//* c-basic-offset: 4 *//* End: */

⌨️ 快捷键说明

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