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

📄 hostinterface.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 HostInterface_cxx_Version =    "$Id: HostInterface.cxx,v 1.14 2002/09/26 01:14:02 bko Exp $";#include <stdlib.h>#include <stdio.h>#include <strstream.h>#include <unistd.h>#include "HostInterface.hxx"#include "VNetworkException.hxx"#include "VIoException.hxx"#include "PSListener.hxx"#include "cpLog.h"#include "Tcp_ClientSocket.hxx"#include "VPs_def.h"#include "Vpp_def.h"#include "VMissingDataException.hxx"#include "VBadDataException.hxx"#include <errno.h>#include "PSNetworkClient.hxx"#include "PSSecret.hxx"HostInterface::HostInterface(const char *host, 			     const int port, 			     const char* password)     : _isAlive(true), _inUse(false){    // _isAlive is true -- we assume we are connected till we fail on a connect.    // _inUse is set by PSInterface        string pServer = host;    // construct the network address, and pass it to the reader    _networkAddress = new NetworkAddress(pServer);    _networkAddress->setPort(port);    // instantiate the reader and writer using this address    _reader = new PSReader(*_networkAddress, password);    _writer = new PSWriter(*_networkAddress, password);}stringHostInterface::readItem(const string& group, const string &name)throw (VException &){    // if this fails, an exception gets thrown up to the PSInterface    // class, which will mark this as disconnected and try the other one...    return (getXmlContents(_reader->getItem(group, name)));}voidHostInterface::getList(const string& group, vector < Data > & retList)throw (VNetworkException&){    _reader->getList(group, retList);}voidHostInterface::writeItem(const string &group, const string &name,                         const string &contents)throw (VNetworkException &){    _writer->putItem(group, name, contents);}stringHostInterface::getXmlContents(const string& dRead)throw (VException &){    cpLog(LOG_DEBUG, "Response from PS [%s]", dRead.c_str());    //The return response from ProvisionServer has    //Protocol    // <retCode> <Status>    //   Content-Length: <content_length>    //   <contents>    //    //Get the return code    char stMsg[MAXLINE];    char cStr[CONT_STR_LENGTH];    int retCode;    int cLength;    string dReturn;    char * tok = strtok((char*)dRead.c_str(), "\n");    // no data, esssentially...    if (tok == NULL)    {        cpLog(LOG_DEBUG, "Failed to read data from PS");        throw VNetworkException("Failed to READ data from PS",                                __FILE__, __LINE__, 0);    }    // have data. Will be of the form 200 OK\n Content-Length : size\n body    int lnCount = 1;    while (tok)    {        switch (lnCount)        {            case 1:            sscanf(tok, "%d%s", &retCode, stMsg);            if (retCode != 200)            {                // we should get a return code of 200 for a valid message                cpLog(LOG_DEBUG, "Failed to read data from PS");                throw VMissingDataException("Failed to READ data from PS",                                            __FILE__, __LINE__, 0);            }            tok = strtok(NULL, "\n");            lnCount++;            break;            case 2:            sscanf(tok, "%s%d", cStr, &cLength);            tok = strtok(NULL, "");            lnCount++;            break;            case 3:            dReturn += tok;            tok = strtok(NULL, "");            break;        }    }    return dReturn;}voidHostInterface::deleteSubscriber(const string& subscriberName)throw (VNetworkException &){    PSNetworkClient clientSocket(*_networkAddress, true, false);    Connection& connection = clientSocket.getConn(PSSecret::writeSecret());    char buf[MAXLINE];    sprintf(buf, "%s %s \n", DELETE_USER_REQ, subscriberName.c_str());    string regReq(buf);    connection.writeData(regReq);}voidHostInterface::registerForItem(const string &group, const string &name,                               const string &hostName)throw (VNetworkException &){    PSNetworkClient clientSocket(*_networkAddress, true, false);    Connection& connection = clientSocket.getConn(PSSecret::readSecret());    char buf[MAXLINE];    sprintf(buf, "%s %s %s %s\n", REGISTER_ITEM_REQ,            group.c_str(), name.c_str(), hostName.c_str());    string regReq(buf);    connection.writeData(regReq);}voidHostInterface::registerForGroup(const string &group, const string &hostName)throw (VNetworkException &){    PSNetworkClient clientSocket(*_networkAddress, true, false);    Connection& connection = clientSocket.getConn(PSSecret::readSecret());    char buf[MAXLINE];    sprintf(buf, "%s %s %s\n", REGISTER_GROUP_REQ,            group.c_str(), hostName.c_str());    string regReq(buf);    connection.writeData(regReq);}voidHostInterface::unregisterForItem(const string &group, const string &name,                                 const string &hostName)throw (VNetworkException &){    PSNetworkClient clientSocket(*_networkAddress, true, false);    Connection& connection = clientSocket.getConn(PSSecret::readSecret());    char buf[MAXLINE];    sprintf(buf, "%s %s %s %s\n", UNREGISTER_ITEM_REQ,            group.c_str(), name.c_str(), hostName.c_str());    string regReq(buf);    connection.writeData(regReq);}voidHostInterface::unregisterForGroup(const string &group, const string &hostName)throw (VNetworkException &){    PSNetworkClient clientSocket(*_networkAddress, true, false);    Connection& connection = clientSocket.getConn(PSSecret::readSecret());    char buf[MAXLINE];    sprintf(buf, "%s %s %s\n", UNREGISTER_GROUP_REQ,            group.c_str(), hostName.c_str());    string regReq(buf);    connection.writeData(regReq);}/* 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 + -