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

📄 redundancymanager.cxx

📁 SIP(Session Initiation Protocol)是由IETF定义
💻 CXX
📖 第 1 页 / 共 2 页
字号:
        return ERR;    }}intRedundancyManager::readItem(const string &group, const string &name,                          string &contents,                          TimeStamp &timestamp){    cpLog (LOG_DEBUG, "Asked twin for (%s,%s)", group.c_str(), name.c_str());    char buf[256], msg[256];    int len, status, nread = 0;    string sendData;    LockHelper lockAid( this->_aMutex );    try    {#if 0        Sptr < TcpClientSocket > clientSocket = 0;        clientSocket = new TcpClientSocket(*_networkAddress);        clientSocket->connect();        Connection &conn = clientSocket->getConn();#endif        PSNetworkClient clientSocket(*_networkAddress, true, block, myUseTls);        Connection& conn = clientSocket.getConn(PSSecret::writeSecret());        // send the SYNCGET message to our opposite        sprintf(buf, "SYNCGET %s %s %s\n", group.c_str(),                name.c_str(), VPP_VERSION);        Data result;        int len;        Data data;        sendCommand(conn, buf, result, len, data, false);        if (result != "200 OK\n")        {            cpLog(LOG_DEBUG, "SYNCGET File returned FAILED");            return FAIL;        }        if(len <= 0)        {            cpLog(LOG_ERR, "Premature EOF on socket -- closing connection");            return ERR;        }        // allocate a buffer for the content        char *bigbuf;        // need to eat the first line        bool matchfail;        Data tsLine = data.parse("\n", &matchfail);        if(!matchfail)        {            Data ts = tsLine.parse(": ", &matchfail);            if(!matchfail)            {                LocalScopeAllocator lo;                // parse out the timestamp                sscanf(tsLine.getData(lo), "%lu", &timestamp);                contents = data.convertString();                return OK;            }        }        cpLog(LOG_ERR, "failed to parse SYNCGET data");        return FAIL;    }    catch (VNetworkException& e)    {        cpLog(LOG_DEBUG,              "Failed to write to redundant server %s:%d, reason %s.",              _host.c_str(), _port, e.getDescription().c_str());        return ERR;    }}intRedundancyManager::sendGood(){    // lock the redundant server    LockHelper lockAid( this->_aMutex );    try    {        char buf[256];        string sendData;        char msg[256];        int status, nread;#if 0        Sptr < TcpClientSocket > clientSocket = 0;        clientSocket = new TcpClientSocket(*_networkAddress);        clientSocket->connect();        Connection &conn = clientSocket->getConn();#endif        PSNetworkClient clientSocket(*_networkAddress, true, block, myUseTls);        Connection& conn = clientSocket.getConn(PSSecret::writeSecret());        // send a sync good message, and check for a valid (200)        // return code from the server        sprintf(buf, "SYNCGOOD %s\n", VPP_VERSION);        Data result;        int len;        Data data;        sendCommand(conn, buf, result, len, data, false);        // read back the result and make sure we get a 200 OK        if (result != "200 OK\n")        {            cpLog(LOG_ERR, "No response sending SYNCGOOD");            return FAIL;        }        else        {            _state = ASYNC;  // if it accepted it, we are all synched!            return OK;        }    }    catch (VNetworkException &e)    {        cpLog(LOG_DEBUG, "Failed to send SYNCSTART to %s:%d.",              _host.c_str(), _port);        return ERR;    }}intRedundancyManager::sendRegisterItem(const string &group, const string &name,                                  const string &host){    // lock the redundant server    LockHelper lockAid( this->_aMutex );    try    {        char buf[256];        string sendData;        sprintf(buf, "%s %s %s %s\n", SYNC_REGISTER_ITEM_REQ, group.c_str(),                name.c_str(), host.c_str());        PSNetworkClient clientSocket(*_networkAddress, true, block, myUseTls);        Connection& conn = clientSocket.getConn(PSSecret::writeSecret());        Data result;        int len;        Data data;        cpLog(LOG_DEBUG, "Sending to remote server : (%s)", sendData.c_str());        sendCommand(conn, buf, result, len, data, false);    }    catch (VNetworkException &e)    {        cpLog(LOG_DEBUG, "Failed to send REGISTER to %s:%d.",              _host.c_str(), _port);        return ERR;    }    return OK;}intRedundancyManager::sendRegisterGroup(const string &group,                                   const string &host){    // lock the redundant server    LockHelper lockAid( this->_aMutex );    try    {        char buf[256];        string sendData;#if 0        Sptr < TcpClientSocket > clientSocket = 0;        clientSocket = new TcpClientSocket(*_networkAddress);        clientSocket->connect();#endif        PSNetworkClient clientSocket(*_networkAddress, true, block, myUseTls);        Connection& conn = clientSocket.getConn(PSSecret::writeSecret());        sprintf(buf, "%s %s %s\n", SYNC_REGISTER_GROUP_REQ, group.c_str(),                host.c_str());        sendData += buf;        cpLog(LOG_DEBUG, "Sending : (%s)", sendData.c_str());        Data result;        int len;        Data data;        sendCommand(conn, buf, result, len, data, false);    }    catch (VNetworkException &e)    {        cpLog(LOG_DEBUG, "Failed to send REGISTER to %s:%d.",              _host.c_str(), _port);        return ERR;    }    return OK;}intRedundancyManager::sendUnregisterItem(const string &group, const string &name,                                    const string &host){    // lock the redundant server    LockHelper lockAid( this->_aMutex );    try    {        char buf[256];        string sendData;#if 0        Sptr < TcpClientSocket > clientSocket = 0;        clientSocket = new TcpClientSocket(*_networkAddress);        clientSocket->connect();#endif        PSNetworkClient clientSocket(*_networkAddress, true, block, myUseTls);        Connection& conn = clientSocket.getConn(PSSecret::writeSecret());        sprintf(buf, "%s %s %s %s\n", SYNC_UNREGISTER_ITEM_REQ, group.c_str(),                name.c_str(), host.c_str());        sendData += buf;        cpLog(LOG_DEBUG, "Sending to remote server : (%s)", sendData.c_str());        Data result;        int len;        Data data;        sendCommand(conn, buf, result, len, data, false);    }    catch (VNetworkException &e)    {        cpLog(LOG_DEBUG, "Failed to send UNREGISTER to %s:%d.",              _host.c_str(), _port);        return ERR;    }    return OK;}intRedundancyManager::sendUnregisterGroup(const string &group,                                     const string &host){    // lock the redundant server    LockHelper lockAid( this->_aMutex );    try    {        char buf[256];        string sendData;#if 0        Sptr < TcpClientSocket > clientSocket = 0;        clientSocket = new TcpClientSocket(*_networkAddress);        clientSocket->connect();#endif        PSNetworkClient clientSocket(*_networkAddress, true, block, myUseTls);        Connection& conn = clientSocket.getConn(PSSecret::writeSecret());        sprintf(buf, "%s %s %s\n", SYNC_UNREGISTER_ITEM_REQ, group.c_str(),                host.c_str());        sendData += buf;        cpLog(LOG_DEBUG, "Sending : (%s)", sendData.c_str());        Data result;        int len;        Data data;        sendCommand(conn, buf, result, len, data, false);    }    catch (VNetworkException &e)    {        cpLog(LOG_DEBUG, "Failed to send UNREGISTER to %s:%d.",              _host.c_str(), _port);        return ERR;    }    return OK;}intRedundancyManager::getRemoteRegistration(RegisterManager &man){    char buf[256], msg[256];    string sendData;    int status, len, nread = 0;    LockHelper lockAid( this->_aMutex );    try    {        // send request for the informaion#if 0        Sptr < TcpClientSocket > clientSocket = 0;        clientSocket = new TcpClientSocket(*_networkAddress);        clientSocket->connect();        Connection &conn = clientSocket->getConn();#endif        PSNetworkClient clientSocket(*_networkAddress, true, block, myUseTls);        Connection& conn = clientSocket.getConn(PSSecret::writeSecret());        sprintf(buf, "%s %s\n", SYNC_GRLIST_REQ, VPP_VERSION);        sendData += buf;        Data result;        int len;        Data data;        sendCommand(conn, buf, result, len, data, false);        //cpLog(LOG_INFO, "Data read for remote registration : (%s)", buf);        if(result == "200 OK\n")        {            if (len == 0)            {                // no data on remote server, so just return OK                return OK;            }            char *bigbuf;            LocalScopeAllocator bufbuf(&bigbuf, data.length() + 2);            LocalScopeAllocator lo;            strncpy(bigbuf, data.getData(lo), data.length() + 2);            char *token;            char file[512], host[256];            int mode = 0;                        cpLog(LOG_DEBUG, "Registration list is: (%s)", bigbuf);                        token = strtok(bigbuf, ",");            if (token == NULL)            {                cpLog(LOG_ERR, "Invalid data sent for list of reg.");                return ERR;            }            sscanf(token, "%s", file);                        if (string(file) != "++ITEM++")            {                cpLog(LOG_ERR, "Parse error on registration data.");                return ERR;            }                                    while ((token = strtok(NULL, ",")) != NULL)            {                sscanf(token, "%s", file);                if (string(file) == "++GROUP++")                {                    mode = 1;                    continue;                }                token = strtok(NULL, ",");                if (token == NULL)                {                    cpLog(LOG_ERR, "Parse error on socket - closing");                    return ERR;                }                sscanf(token, "%s", host);                if (mode == 0)                {                    man.registerItemCat(file, host);                }                else                {                    man.registerGroup(file, host);                }            }                            return OK;        }        else        {            cpLog(LOG_DEBUG, "Failed to get remote reg list");            return FAIL;        }    }    catch (VNetworkException &e)    {        cpLog(LOG_DEBUG, "Failed to send get Remote Reg list",              _host.c_str(), _port);        return ERR;    }}intRedundancyManager::putLocalRegistration(RegisterManager &man){    char buf[256], msg[256];    string sendData;    int status, nread = 0;    LockHelper lockAid( this->_aMutex );    cpLog(LOG_DEBUG, "Sending twin our configuration");    try    {#if 0        Sptr < TcpClientSocket > clientSocket = 0;        clientSocket = new TcpClientSocket(*_networkAddress);        clientSocket->connect();        Connection &conn = clientSocket->getConn();#endif        PSNetworkClient clientSocket(*_networkAddress, true, block, myUseTls);        Connection& conn = clientSocket.getConn(PSSecret::writeSecret());        string contents;        man.getList(contents);        // format and send message        sprintf(buf, "%s %s\n", SYNC_PRLIST_REQ, VPP_VERSION);        sendData += buf;        sprintf(buf, "%s %d\n", CONT_LENGTH, contents.size());        sendData += buf;        sendData += contents;        sendData += "\n";        Data result;        int len;        Data data;        sendCommand(conn, sendData.c_str(), result, len, data, false);        if (result == "200 OK\n")        {            // if ok, just return ok            return OK;        }        else        {            cpLog(LOG_DEBUG, "SYNCPRLIST File returned FAILED");            return FAIL;        }    }    catch (VNetworkException &e)    {        cpLog(LOG_DEBUG, "Failed to write to redundant server %s:%d.",              _host.c_str(), _port);        return ERR;    }}intRedundancyManager::sendDeleteItem (const string &group, const string &name){    char buf[256], msg[256];    string sendData;    int status, nread = 0;    LockHelper lockAid( this->_aMutex );    try    {#if 0        Sptr < TcpClientSocket > clientSocket = 0;        clientSocket = new TcpClientSocket(*_networkAddress);        clientSocket->connect();        Connection &conn = clientSocket->getConn();#endif        PSNetworkClient clientSocket(*_networkAddress, true, block, myUseTls);        Connection& conn = clientSocket.getConn(PSSecret::writeSecret());        // format and send message        sprintf(buf, "%s %s %s %s\n", SYNC_DEL_REQ, group.c_str(),                name.c_str(), VPP_VERSION);        Data result;        int len;        Data data;        sendCommand(conn, buf, result, len, data, false);        if (result == "200 OK\n")        {            // if ok, just return ok            return OK;        }        else        {            cpLog(LOG_DEBUG, "SYNCDEL File returned FAILED");            return FAIL;        }    }    catch (VNetworkException &e)    {        cpLog(LOG_DEBUG, "Failed to write to redundant server %s:%d.",              _host.c_str(), _port);        return ERR;    }}/* 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 + -