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

📄 provisionserver.cxx

📁 SIP(Session Initiation Protocol)是由IETF定义
💻 CXX
📖 第 1 页 / 共 5 页
字号:
            else if (  vppReq == LIST_REQ)            {                handleListRequest(conn, arg, false);                processedCommand = true;            }            else if ( vppReq == NLIST_REQ)            {                handleListRequest(conn, arg, true);                processedCommand = true;            }            else if ( vppReq == REGISTER_ITEM_REQ )            {                handleItemRegisterRequest(arg, arg2, arg3);                processedCommand = true;            }            else if ( vppReq == REGISTER_GROUP_REQ )            {                handleGroupRegisterRequest(arg, arg2);                processedCommand = true;            }            else if ( vppReq == UNREGISTER_ITEM_REQ )            {                handleItemUnregisterRequest(arg, arg2, arg3);                processedCommand = true;            }            else if ( vppReq == UNREGISTER_GROUP_REQ )            {                handleGroupUnregisterRequest(arg, arg2);                processedCommand = true;            }        }        if ( conn.isWriteAuthorized() )        {            if ( vppReq == PUT_REQ)            {                handlePutRequest(conn, arg, arg2);                processedCommand = true;            }            else if ( vppReq == REMOVE_REQ )            {                handleRemoveRequest(conn, arg, arg2);                processedCommand = true;            }            else if ( vppReq == DELETE_USER_REQ )            {                handleDeleteUserRequest(conn, arg);                processedCommand = true;            }            else if ( vppReq == SYNC_DEL_REQ)            {                handleSyncDelRequest(conn, arg, arg2);                processedCommand = true;            }            else if ( vppReq == SYNC_PUT_REQ)            {                handleSyncPutRequest(conn, arg, arg2);                processedCommand = true;            }            else if ( vppReq == SYNC_START_REQ)            {                handleSyncStartRequest(conn);                processedCommand = true;            }            else if ( vppReq == SYNC_GET_REQ)            {                handleSyncGetRequest(conn, arg, arg2);                processedCommand = true;            }            else if ( vppReq == SYNC_STAT_REQ)            {                handleSyncStatRequest(conn);                processedCommand = true;            }            else if ( vppReq == SYNC_GOOD_REQ )            {                handleSyncGoodRequest(conn);                processedCommand = true;            }            else if ( vppReq == SYNC_REGISTER_ITEM_REQ )            {                handleSyncRegisterItemRequest(arg, arg2, arg3);                processedCommand = true;            }            else if ( vppReq == SYNC_REGISTER_GROUP_REQ )            {                handleSyncRegisterGroupRequest(arg, arg2);                processedCommand = true;            }            else if ( vppReq == SYNC_UNREGISTER_ITEM_REQ )            {                handleSyncUnregisterItemRequest(arg, arg2, arg3);                processedCommand = true;            }            else if ( vppReq == SYNC_UNREGISTER_GROUP_REQ )            {                handleSyncUnregisterGroupRequest(arg, arg2);                processedCommand = true;            }            else if ( vppReq == SYNC_GRLIST_REQ )            {                handleSyncGetRListRequest(conn);                processedCommand = true;            }            else if ( vppReq == SYNC_PRLIST_REQ )            {                handleSyncPutRListRequest(conn);                processedCommand = true;            }        }    }    if(!processedCommand)    {        sendVPPFail(conn);    }    buf[0] = '\0';    if (vppReq == PUT_REQ)     {        req[0] = '\0';    }    nread = 0;    conn.doneService();    cpLog(LOG_DEBUG, "done processing request %d", conn.getConnId());}voidProvisionServer::handleAuthRequest(LockedConnection& conn,                                   const string userpass){    // break userpass into user:password    unsigned int i = userpass.find(':');    string username;    string password;    if(i != string::npos)    {        username = userpass.substr(0,i);        password = userpass.substr(i + 1, string::npos);    }    else    {        username = "default";        password = userpass;    }    PasswdFile::PasswdFileLevel authLevel         = myPasswdFile.verify(username, password);     if(authLevel == PasswdFile::PasswdReadOnly)    {        conn.readAuthorize();        sendVPPOk(conn);    }     else if (authLevel == PasswdFile::PasswdReadWrite)    {        conn.writeAuthorize();        sendVPPOk(conn);    }    else if(conn.isReadAuthorized())    {        sendVPPOk(conn);    }    else    {        sendVPPFail(conn);    }}voidProvisionServer::handleGetRequest(LockedConnection& conn,                                  const string &group,                                  const string &name){    string gData;    try    {	gData = _dataStore->getItem(group, name);        // Success        string retData = makeVPPHeader(vppOkGLBL, gData.size());        retData += gData;        cpLog(LOG_DEBUG, "Got file (%s)", retData.c_str());        conn.writeData(retData);    }    catch (VIoException& e)    {        // Failed to read the item        sendVPPFail(conn);        string reason = "Failed to get data: " + e.getDescription();        cpLog(LOG_DEBUG, reason.c_str());    }}voidProvisionServer::handlePutRequest(LockedConnection& conn,                                  const string &group,                                  const string &name){    // Get the content length    char buf[MAXLINE];    int nread = 0;    // Read content length    nread = 0;    if (conn.readLine(buf, sizeof(buf), nread) < 0)    {        // Bad VPP header        string retData = makeVPPHeader(vppFailGLBL, 0);        cpLog(LOG_DEBUG, retData.c_str());        conn.writeData(retData);        return ;    }    int cntLength = 0;    char cntStr[56];    sscanf(buf, "%s%d", cntStr, &cntLength);    cpLog(LOG_DEBUG, "Content-Length: %d", cntLength);    // Read the contents    char *c = new char[cntLength + 1];    nread = 0;    conn.readn(c, cntLength, nread);    if (nread == -1)    {        cpLog (LOG_ALERT, "Read error on socket");        delete c;        return ;    }    else if (nread != cntLength)    {        cpLog(LOG_ALERT, "Content length mismatch, expected %d read %d",              cntLength, nread);        delete c;        return ;    }    c[cntLength] = 0;    cpLog(LOG_DEBUG, "Data for PUT request: (%s)", c);    // Write data to the data store    try    {        // Write to the date store and try to send to redundant server        _dataStore->putItem(group, name, c);        if (_copy.inUse() && _copy.isAlive())        {            int result;            result = _copy.writeItem(group, name, c,                                     _dataStore->getItemTimeStamp(group,                                                                  name));            if (result != RedundancyManager::OK)            {                if (result == RedundancyManager::ERR)                {                    _copy.connFailed();                }                if (result == RedundancyManager::FAIL)                {                    _copy.badReturn();                    setSyncTimer();                }            }        }        // send updates        _registerManager.modifyItem(group, name);        sendVPPOk(conn);    }    catch (VIoException& e)    {        cpLog(LOG_ALERT, "Failed to put (%s,%s) in data store. Reason : %s ",              group.c_str(), name.c_str(), strerror(errno));        sendVPPFail(conn);    }    delete c;}voidProvisionServer::handleListRequest(LockedConnection& conn,                                   const string& group,                                   bool useHeader){    cpLog(LOG_DEBUG, "ProvisionServer::handleListRequest for (%s)",          group.c_str());    string gData;    try    {        StringList items;        string retData, finalData;        bool val = _dataStore->isGroup(group);        if (val)        {            items = _dataStore->listItems(group);        }        // if not there, just send empty list (not fail, since the        // behaviour on a create for a bin that doesn't exist is to create it        if (!val || items.size() == 0)        {            retData = "\n";        }        else        {            StringList::iterator itr;            for (itr = items.begin(); itr != items.end(); itr++)            {                retData += (*itr);                retData += ",";            }            retData += "\n";        }        // use header?        if (useHeader == true)        {            finalData = makeVPPHeader(vppOkGLBL, retData.size());        }        else        {            finalData = "";        }        finalData += retData;        conn.writeData(finalData);    }    catch (VIoException& e)    {        //Failed to get the list of items        cpLog(LOG_ERR, "dataStore listItem() failed for (%s)",              group.c_str());        sendVPPFail(conn);    }}voidProvisionServer::handleRemoveRequest(LockedConnection& conn,                                     const string &group, const string &name){    cpLog(LOG_DEBUG, "ProvisionServer::handleRemoveRequest for (%s,%s)",          group.c_str(), name.c_str());    string gData;    try    {        // if the item doesn't exist, don't bother trying to remove it,        // but do still do all normal processing (and return ok)        bool exists = _dataStore->isItem(group, name);        if (exists)        {            _dataStore->removeItem(group, name);        }                cpLog(LOG_DEBUG, "Removed item (%s,%s)", group.c_str(), name.c_str());        _registerManager.deleteItem(group, name);        if (_copy.inUse() && _copy.isAlive())        {            int result = _copy.sendDeleteItem(group, name);            if (result != RedundancyManager::OK)            {                if (result == RedundancyManager::ERR)                {                    _copy.connFailed();                    sendVPPOk(conn);                    return ;                }                if (result == RedundancyManager::FAIL)                {                    _copy.badReturn();                    setSyncTimer();                    sendVPPOk(conn);                    return ;                }            }        }        sendVPPOk(conn);    }    catch (VIoException& e)    {        // Failed to remove the item for whatever reason (likely permissions)        cpLog(LOG_ERR, "Caught exception when trying to delete, reason %s",              e.getDescription().c_str());        sendVPPFail(conn);    }    return;}voidProvisionServer::handleDeleteUserRequest(LockedConnection& conn,        const string& userName){    // this is a multifile delete -- essentially we delete the called,    // calling, and account items for a user.    try    {        bool wasCalled = false;        bool wasCalling = false;        if (_dataStore->isItem(CALLEDLIST, userName))        {            _dataStore->removeItem(CALLEDLIST, userName);            wasCalled = true;        }        if (_dataStore->isItem(CALLINGLIST, userName))        {            _dataStore->removeItem(CALLINGLIST, userName);            wasCalling = true;        }        _dataStore->removeItem(ACCOUNTS, userName);        cpLog(LOG_DEBUG, "Removed user (%s)", userName.c_str());        if (wasCalled)        {            _registerManager.deleteItem(CALLEDLIST, userName);        }        if (wasCalling)        {            _registerManager.deleteItem(CALLINGLIST, userName);        }        _registerManager.deleteItem(ACCOUNTS, userName);        if (_copy.inUse() && _copy.isAlive())        {            // send all three removes to the redundant, just in case            // the copy has one.            int result = _copy.sendDeleteItem(CALLEDLIST, userName);            if (result != RedundancyManager::OK)            {                if (result == RedundancyManager::ERR)                {                    _copy.connFailed();                    return ;                }                if (result == RedundancyManager::FAIL)                {                    _copy.badReturn();                    setSyncTimer();                    return ;                }            }            result = _copy.sendDeleteItem(CALLINGLIST, userName);            if (result != RedundancyManager::OK)            {                if (result == RedundancyManager::ERR)                {                    _copy.connFailed();                    return ;                }                if (result == RedundancyManager::FAIL)                {                    _copy.badReturn();                    setSyncTimer();                    return ;                }            }

⌨️ 快捷键说明

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