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

📄 stafhandleservice.cpp

📁 Software Testing Automation Framework (STAF)的开发代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    {        STAFHandleManager::HandleData handleData = iter->second;        if (handleData.handle == handleNumber)        {            STAFString handleState;            if (handleData.state == STAFHandleManager::kPending)            {                handleState = "Pending";            }            else if ((handleData.state == STAFHandleManager::kRegistered)                 ||  (handleData.state == STAFHandleManager::kPendingRegistered))            {                handleState = "Registered";            }            else if (handleData.state == STAFHandleManager::kInProcess)            {                handleState = "InProcess";            }            else if (handleData.state == STAFHandleManager::kStatic)            {                handleState = "Static";            }            else            {                return STAFServiceResult(kSTAFUnknownError, "Unknown Handle State");            }            handleMap->put("handle", STAFString(handleNumber));            if (handleData.name.length() != 0)                handleMap->put("name", handleData.name);            handleMap->put("state", handleState);            handleMap->put(                "lastUsedTimestamp", handleData.lastUsedTimestamp.asString());            handleMap->put("pid", STAFString(handleData.pid));            handleMap->put(                "user", STAFString(handleData.authenticator) +                gSpecSeparator + STAFString(handleData.userIdentifier));        }    }    mc->setRootObject(handleMap);    return STAFServiceResult(kSTAFOk, mc->marshall());}STAFServiceResult STAFHandleService::handleAuthenticate(    const STAFServiceRequest &requestInfo){    // Verify that this request came from the local machine and that    // the requesting machine/user has at least trust level 5    IVALIDATE_LOCAL_TRUST(5, "AUTHENTICATE");    // Parse the request    STAFCommandParseResultPtr parsedResult =                              fAuthParser.parse(requestInfo.fRequest);    if (parsedResult->rc != kSTAFOk)    {        return STAFServiceResult(kSTAFInvalidRequestString,                                 parsedResult->errorBuffer);    }    // Resolve any variables in USER, CREDENTIALS, and AUTHENTICATOR    DEFINE_VAR_POOL_LIST(varPoolList, varPoolListSize, requestInfo);    STAFString authenticator =  gServiceManagerPtr->getDefaultAuthenticator();    STAFString userIdentifier;    STAFString errorBuffer;    STAFRC_t rc = RESOLVE_STRING_OPTION("USER", userIdentifier);    if (!rc) rc = RESOLVE_OPTIONAL_STRING_OPTION("AUTHENTICATOR",                                                 authenticator);    if (rc) return STAFServiceResult(rc, errorBuffer);    if (authenticator == gNoneString)    {        return STAFServiceResult(kSTAFHandleAuthenticationDenied,                                 "No Authenticators are registered");    }    STAFString credentials = parsedResult->optionValue("CREDENTIALS");    // Issue an Authenticate request to the specified Authenticator service    // passing in the credentials.  If the handle is already authenticated,    // or if the authenticator specified is not registered or if authentication    // fails, an error is returned.  If successful, authentication data is    // returned in the result.    STAFServiceResult serviceResult = gHandleManagerPtr->authenticate(        requestInfo.fMachine, requestInfo.fHandle, authenticator,        userIdentifier, STAFHandleManager::kCredentials, credentials);    if (serviceResult.fRC != kSTAFOk) return serviceResult;    // User was successfully authenticated    STAFString authenticationData = serviceResult.fResult;    // Cache the authentication information for the machine/handle/user/data    // Can ignore any errors returned by cacheAuthenticationInfo() as an    // error can only occur if the handle no longer exists, which should    // never happen, but if it did, we wouldn't need to cache authinfo for it.    gHandleManagerPtr->cacheAuthenticationInfo(requestInfo.fMachine,                                               requestInfo.fHandle,                                               authenticator,                                               userIdentifier,                                               authenticationData);    return STAFServiceResult(kSTAFOk);}STAFServiceResult STAFHandleService::handleUnAuthenticate(    const STAFServiceRequest &requestInfo){    // Verify that this request came from the local machine and that    // the requesting machine/user has at least trust level 5    IVALIDATE_LOCAL_TRUST(5, "UNAUTHENTICATE");    // Parse the request    STAFCommandParseResultPtr parsedResult = fUnAuthParser.parse(        requestInfo.fRequest);    if (parsedResult->rc != kSTAFOk)    {        return STAFServiceResult(kSTAFInvalidRequestString,                                 parsedResult->errorBuffer);    }    // Un-authenticate the handle    return gHandleManagerPtr->unAuthenticate(requestInfo.fHandle);}STAFServiceResult STAFHandleService::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);    }    STAFObjectPtr mc = STAFObject::createMarshallingContext();    if (parsedResult->optionTimes("NOTIFICATIONS") != 0)    {        STAFHandleManager::NotificationList notificationList =            gHandleManagerPtr->getNotificationListCopy();                // Create a marshalled list of maps containing notification information        mc->setMapClassDefinition(fNotificationClass->reference());        STAFObjectPtr outputList = STAFObject::createList();                STAFHandleManager::NotificationList::iterator iter;        for (iter = notificationList.begin();             iter != notificationList.end(); iter++)        {            STAFHandleManager::NotificationData notifiee(*iter);            STAFObjectPtr notifyMap = fNotificationClass->createInstance();            notifyMap->put("handle", STAFString(notifiee.handle));            notifyMap->put("machine", STAFString(notifiee.machine));            notifyMap->put("notifyService",                           STAFString(notifiee.notifyService));            outputList->append(notifyMap);        }                mc->setRootObject(outputList);    }    else //list handles    {        int getPending = 0;        int getRegistered = 0;        int getInProcess = 0;        int getStatic = 0;        if ((parsedResult->optionTimes("PENDING") == 0) &&            (parsedResult->optionTimes("REGISTERED") == 0) &&            (parsedResult->optionTimes("INPROCESS") == 0) &&            (parsedResult->optionTimes("STATIC") == 0))        {            getPending = 0;            getRegistered = 1;            getInProcess = 1;            getStatic = 1;        }        else        {            if (parsedResult->optionTimes("PENDING") != 0)                getPending = 1;            if (parsedResult->optionTimes("REGISTERED") != 0)                getRegistered = 1;            if (parsedResult->optionTimes("INPROCESS") != 0)                getInProcess = 1;            if (parsedResult->optionTimes("STATIC") != 0)                getStatic = 1;        }        unsigned int getAll = parsedResult->optionTimes("NAME") == 0;        unsigned int longFormat = parsedResult->optionTimes("LONG");        // Resolve the NAME option value        DEFINE_VAR_POOL_LIST(varPoolList, varPoolListSize, requestInfo);        STAFString errorBuffer;        STAFString name;        STAFRC_t rc = RESOLVE_OPTIONAL_STRING_OPTION("NAME", name);        if (rc) return STAFServiceResult(rc, errorBuffer);                // Create the marshalled list of maps containing handle information        if (!longFormat)            mc->setMapClassDefinition(fHandleInfoClass->reference());        else            mc->setMapClassDefinition(fHandleInfoLongClass->reference());        STAFObjectPtr outputList = STAFObject::createList();                // Get a copy of the handle list        STAFHandleManager::HandleList handleList =                                      gHandleManagerPtr->getHandleListCopy();        STAFHandleManager::HandleList::iterator iter;        for (iter = handleList.begin(); iter != handleList.end(); iter++)        {            STAFHandleManager::HandleData handleData = iter->second;            if (((getAll != 0) || (handleData.name == name))                && (((getPending == 1) && (handleData.state == STAFHandleManager::kPending))                || ((getRegistered == 1) && ((handleData.state == STAFHandleManager::kRegistered)                                || (handleData.state == STAFHandleManager::kPendingRegistered)))                || ((getInProcess == 1) && (handleData.state == STAFHandleManager::kInProcess))                || ((getStatic == 1) && (handleData.state == STAFHandleManager::kStatic))))            {                STAFObjectPtr handleMap;                if (!longFormat)                {                    handleMap = fHandleInfoClass->createInstance();                }                else                {                    handleMap = fHandleInfoLongClass->createInstance();                    handleMap->put("pid", STAFString(handleData.pid));                }                handleMap->put("handle", STAFString(handleData.handle));                if (handleData.state == STAFHandleManager::kPending)                {                    if (handleData.name.length() != 0)                        handleMap->put("name", STAFString(handleData.name));                    handleMap->put("state", STAFString("Pending"));                }                else if ((handleData.state == STAFHandleManager::kRegistered) ||                         (handleData.state == STAFHandleManager::kPendingRegistered))                {                    handleMap->put("name", STAFString(handleData.name));                    handleMap->put("state", STAFString("Registered"));                }                else if (handleData.state == STAFHandleManager::kInProcess)                {                    handleMap->put("name", STAFString(handleData.name));                    handleMap->put("state", STAFString("InProcess"));                }                else if (handleData.state == STAFHandleManager::kStatic)                {                    handleMap->put("name", STAFString(handleData.name));                    handleMap->put("state", STAFString("Static"));                }                else                {                    if (handleData.name.length() != 0)                        handleMap->put("name", STAFString(handleData.name));                    handleMap->put("state", STAFString("<Unknown>"));                }                handleMap->put("lastUsedTimestamp",                               handleData.lastUsedTimestamp.asString());                outputList->append(handleMap);            }        }                mc->setRootObject(outputList);    }    return STAFServiceResult(kSTAFOk, mc->marshall());}STAFServiceResult STAFHandleService::handleNotify(    const STAFServiceRequest &requestInfo){    STAFCommandParseResultPtr parsedResult = fNotifyParser.parse(        requestInfo.fRequest);    if (parsedResult->rc != kSTAFOk)    {        return STAFServiceResult(kSTAFInvalidRequestString,                                 parsedResult->errorBuffer);    }    DEFINE_VAR_POOL_LIST(varPoolList, varPoolListSize, requestInfo);    STAFString errorBuffer;    STAFHandle_t handle;    STAFRC_t rc = RESOLVE_UINT_OPTION("ONENDOFHANDLE", handle);    if (rc) return STAFServiceResult(rc, errorBuffer);    // Don't need to resolve these variables as STAF_NOTIFY request is not    // documented and STAF doesn't need to pass any variables in these options    STAFString machine = parsedResult->optionValue("MACHINE");    STAFString service = parsedResult->optionValue("SERVICE");    STAFString key     = parsedResult->optionValue("KEY");        STAFString uuid;        // UUID is optional.  If not specified, use MISC WHOAREYOU.        if (parsedResult->optionTimes("UUID") == 0)    {        STAFResultPtr result =             gSTAFProcHandlePtr->submit(machine, "MISC", "WHOAREYOU");        if (result->rc == kSTAFOk)        {            STAFObjectPtr mc = STAFObject::unmarshall(result->result);            STAFObjectPtr poolMap = mc->getRootObject();            uuid = poolMap->get("instanceUUID")->asString();        }        else        {            uuid = "N/A";        }    }    else    {        uuid = parsedResult->optionValue("UUID");    }    return gHandleManagerPtr->addNotification(handle, machine, uuid, service,                                               key);}STAFServiceResult STAFHandleService::handleHelp(    const STAFServiceRequest &requestInfo){    // Verify that the requesting machine/user has at least trust level 1    IVALIDATE_TRUST(1, "HELP");    STAFString result("HANDLE Service Help");    result += *gLineSeparatorPtr + *gLineSeparatorPtr;    result += "CREATE HANDLE NAME <Handle Name>" + *gLineSeparatorPtr +              *gLineSeparatorPtr;    result += "DELETE HANDLE <Number>" + *gLineSeparatorPtr +              *gLineSeparatorPtr;    result += "QUERY HANDLE <Handle>" + *gLineSeparatorPtr +              *gLineSeparatorPtr;    result += "LIST [HANDLES [NAME <Handle Name>] [LONG]" +              *gLineSeparatorPtr +              "              [PENDING] [REGISTERED] [INPROCESS] [STATIC]]" +               *gLineSeparatorPtr + *gLineSeparatorPtr;    result += "LIST NOTIFICATIONS [HANDLE <Handle> | MACHINE <Machine>]" +               *gLineSeparatorPtr + *gLineSeparatorPtr;    result += "AUTHENTICATE USER <User Identifier> CREDENTIALS <Credentials>" +              *gLineSeparatorPtr +              "             [AUTHENTICATOR <Authenticator Name>]" +              *gLineSeparatorPtr + *gLineSeparatorPtr;    result += "UNAUTHENTICATE" + *gLineSeparatorPtr + *gLineSeparatorPtr;    result += "STAF_NOTIFY REGISTER ONENDOFHANDLE <Handle> MACHINE <Machine>" +              *gLineSeparatorPtr;    result += "            KEY <Key> SERVICE <Service>" +              *gLineSeparatorPtr + *gLineSeparatorPtr;    result += "HELP" + *gLineSeparatorPtr;    return STAFServiceResult(kSTAFOk, result);}

⌨️ 快捷键说明

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