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

📄 stafqueueservice.cpp

📁 Software Testing Automation Framework (STAF)的开发代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    if (rc) return STAFServiceResult(rc);    unsigned int numDeleted = 0;    STAFMutexSemLock queueLock(handleQueue->fQueueSem);    STAFHandleQueue::HandleQueue::iterator iter;    int foundIt = 0;    for (iter = handleQueue->fQueue.begin();         iter != handleQueue->fQueue.end();)    {        foundIt = 1;        if (checkPriority)        {            unsigned int priority = 0;            foundIt = 0;            for (int i = 1; (i <= parsedResult->optionTimes("PRIORITY")) &&                 !foundIt; ++i)            {                rc = RESOLVE_INDEXED_UINT_OPTION("PRIORITY", i, priority);                if (rc) return STAFServiceResult(rc, errorBuffer);                if (priority == iter->second.priority) foundIt = 1;            }        }        if (foundIt && checkMachine)        {            STAFString machine;            foundIt = 0;            for (int i = 1; (i <= parsedResult->optionTimes("MACHINE")) &&                 !foundIt; ++i)            {                rc = RESOLVE_INDEXED_STRING_OPTION("MACHINE", i, machine);                if (rc) return STAFServiceResult(rc, errorBuffer);                machine.lowerCase();                // Do a wildcard match                STAFString lowerMachine = iter->second.machine.toLowerCase();                if (lowerMachine.matchesWildcards(machine))                {                    foundIt = 1;                }            }        }        if (foundIt && checkName)        {            STAFString name;            foundIt = 0;            for (int i = 1; (i <= parsedResult->optionTimes("NAME")) &&                 !foundIt; ++i)            {                rc = RESOLVE_INDEXED_STRING_OPTION("NAME", i, name);                if (rc) return STAFServiceResult(rc, errorBuffer);                name.lowerCase();                if (name == iter->second.process.toLowerCase()) foundIt = 1;            }        }        if (foundIt && checkHandle)        {            unsigned int theHandle = 0;            foundIt = 0;            for (int i = 1; (i <= parsedResult->optionTimes("HANDLE")) &&                 !foundIt; ++i)            {                rc = RESOLVE_INDEXED_UINT_OPTION("HANDLE", i, theHandle);                if (rc) return STAFServiceResult(rc, errorBuffer);                if (theHandle == iter->second.handle) foundIt = 1;            }        }        if (foundIt && checkUser)        {            STAFString user;            foundIt = 0;            for (int i = 1; (i <= parsedResult->optionTimes("USER")) &&                 !foundIt; ++i)            {                rc = RESOLVE_INDEXED_STRING_OPTION("USER", i, user);                if (rc) return STAFServiceResult(rc, errorBuffer);                // Check if authenticator was specified in the user value                unsigned int sepIndex = user.find(gSpecSeparator);                if (sepIndex == STAFString::kNPos)                {                    // No authenticator specified                    // Use lower-case default authenticator                    user = gServiceManagerPtr->getDefaultAuthenticator().                        toLowerCase() + gSpecSeparator + user;                }                else                {                    // User specified in form of Authenticator://UserIdentifier                    // Change authenticator to lower-case.                    user = user.subString(0, sepIndex).toLowerCase() +                           user.subString(sepIndex);                }                // Do a wildcard match                STAFString matchString(                    iter->second.authenticator.toLowerCase() +                    gSpecSeparator + iter->second.userIdentifier);                // if (matchString.matchesWildcards(user)) foundIt = 1;                if (matchString == user) foundIt = 1;            }        }        if (foundIt && checkType)        {            STAFString type;            foundIt = 0;            for (int i = 1; (i <= parsedResult->optionTimes("TYPE")) &&                 !foundIt; ++i)            {                rc = RESOLVE_INDEXED_STRING_OPTION("TYPE", i, type);                if (rc) return STAFServiceResult(rc, errorBuffer);                type.lowerCase();                if (type == iter->second.type.toLowerCase()) foundIt = 1;            }        }        if (foundIt && checkContains)        {            STAFString contains;            foundIt = 0;            for (int i = 1; (i <= parsedResult->optionTimes("CONTAINS")) &&                 !foundIt; ++i)            {                rc = RESOLVE_INDEXED_STRING_OPTION("CONTAINS", i, contains);                if (rc) return STAFServiceResult(rc, errorBuffer);                if (iter->second.message.find(contains) != STAFString::kNPos)                    foundIt = 1;            }        }        if (foundIt && checkIContains)        {            STAFString checkMessage = iter->second.message.toLowerCase();            STAFString icontains;            foundIt = 0;            for (int i = 1; (i <= parsedResult->optionTimes("ICONTAINS")) &&                 !foundIt; ++i)            {                rc = RESOLVE_INDEXED_STRING_OPTION("ICONTAINS", i, icontains);                if (rc) return STAFServiceResult(rc, errorBuffer);                if (checkMessage.find(icontains.toLowerCase()) !=                    STAFString::kNPos)                {                    foundIt = 1;                }            }        }        if (foundIt)        {            ++numDeleted;            handleQueue->fQueue.erase(iter);            iter = handleQueue->fQueue.begin();        }        else        {            ++iter;        }    }    return STAFServiceResult(kSTAFOk, STAFString(numDeleted));}STAFServiceResult STAFQueueService::handleList(    const STAFServiceRequest &requestInfo){    // Verify that the requesting machine/user has at least trust level 2    IVALIDATE_TRUST(2, "LIST");    // Parse the request    STAFCommandParseResultPtr parsedResult = fListParser.parse(        requestInfo.fRequest);    if (parsedResult->rc != kSTAFOk)    {        return STAFServiceResult(kSTAFInvalidRequestString,                                 parsedResult->errorBuffer, 0);    }    STAFString errorBuffer;    // HANDLE may only default if the request came from this machine    if ((parsedResult->optionTimes("HANDLE") == 0) &&        !requestInfo.fIsLocalRequest)    {        return STAFServiceResult(kSTAFInvalidRequestString);    }    DEFINE_VAR_POOL_LIST(varPoolList, varPoolListSize, requestInfo);    unsigned int theHandle = requestInfo.fHandle;    STAFRC_t rc = RESOLVE_OPTIONAL_UINT_OPTION("HANDLE", theHandle);    if (rc) return STAFServiceResult(rc, errorBuffer);    STAFHandleQueuePtr handleQueue;    rc = gHandleManagerPtr->handleQueue(theHandle, handleQueue);    if (rc) return STAFServiceResult(rc);    // Create a marshalled list of maps containing information for entries    // found in the queue    STAFObjectPtr mc = STAFObject::createMarshallingContext();    mc->setMapClassDefinition(fQueueEntryMapClass->reference());    STAFObjectPtr queueList = STAFObject::createList();    // Iterate through the queue    STAFMutexSemLock queueLock(handleQueue->fQueueSem);    STAFHandleQueue::HandleQueue::iterator iter;    for (iter = handleQueue->fQueue.begin();         iter != handleQueue->fQueue.end(); iter++)    {        STAFHandleQueue::Message message = iter->second;        // Create a map for each entry in the queue        STAFObjectPtr queueEntryMap = fQueueEntryMapClass->createInstance();        queueEntryMap->put("priority", STAFString(message.priority));        queueEntryMap->put("timestamp", message.timestamp.asString());        queueEntryMap->put("machine", message.machine);        if (message.process.length() == 0)            queueEntryMap->put("handleName", STAFObject::createNone());        else            queueEntryMap->put("handleName", message.process);        queueEntryMap->put("handle", STAFString(message.handle));        queueEntryMap->put("user", message.authenticator +                           gSpecSeparator + message.userIdentifier);        if (message.type.length() != 0)            queueEntryMap->put("type", message.type);        queueEntryMap->put("message",                           STAFHandle::maskPrivateData(message.message));        queueList->append(queueEntryMap);    }    // Set the marshalling context's root object    mc->setRootObject(queueList);    return STAFServiceResult(rc, mc->marshall());}STAFServiceResult STAFQueueService::handleHelp(    const STAFServiceRequest &requestInfo){    // Verify that the requesting machine/user has at least trust level 1    IVALIDATE_TRUST(1, "HELP");    STAFString result("QUEUE Service Help" + *gLineSeparatorPtr +                      *gLineSeparatorPtr);    result += "QUEUE  [HANDLE <Handle>] | [NAME <Name>] [PRIORITY "              "<Priority>] [TYPE <Type>]" + *gLineSeparatorPtr +              "       MESSAGE <Message>" + *gLineSeparatorPtr +              *gLineSeparatorPtr;    result += "GET    [PRIORITY <Priority>]... [MACHINE <Endpoint>]... "              "[NAME <Name>]..." + *gLineSeparatorPtr +              "       [HANDLE <Handle>]... [USER <User>]... [TYPE <Type>]..." +              *gLineSeparatorPtr +              "       [CONTAINS <String>]... [ICONTAINS <String>]... " +              "[WAIT [Timeout]]" + *gLineSeparatorPtr + *gLineSeparatorPtr;    result += "PEEK   [PRIORITY <Priority>]... [MACHINE <Endpoint>]... "              "[NAME <Name>]..." + *gLineSeparatorPtr +              "       [HANDLE <Handle>]... [USER <User>]... [TYPE <Type>]..." +              *gLineSeparatorPtr +              "       [CONTAINS <String>]... [ICONTAINS <String>]... " +              "[WAIT [Timeout]]" + *gLineSeparatorPtr + *gLineSeparatorPtr;    result += "DELETE [PRIORITY <Priority>]... [MACHINE <Endpoint>]... "              "[NAME <Name>]..." + *gLineSeparatorPtr +              "       [HANDLE <Handle>]... [USER <User>]... [TYPE <Type>]..." +              *gLineSeparatorPtr +              "       [CONTAINS <String>]... [ICONTAINS <String>]... " +              "[WAIT [Timeout]]" + *gLineSeparatorPtr + *gLineSeparatorPtr;    result += "LIST   [HANDLE <Handle>]" + *gLineSeparatorPtr +              *gLineSeparatorPtr;    result += "HELP" + *gLineSeparatorPtr;    return STAFServiceResult(kSTAFOk, result);}

⌨️ 快捷键说明

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