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

📄 stafserviceservice.cpp

📁 Software Testing Automation Framework (STAF)的开发代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    return STAFServiceResult(rc, mc->marshall());}STAFServiceResult STAFServiceService::handleFree(    const STAFServiceRequest &requestInfo){    // Verify that the requesting machine/user has at least trust level 5    IVALIDATE_TRUST(5, "FREE");    // Parse the request    STAFCommandParseResultPtr parsedFreeResult = fFreeParser->parse(        requestInfo.fRequest);    if (parsedFreeResult->rc != kSTAFOk)    {        return STAFServiceResult(kSTAFInvalidRequestString,                                 parsedFreeResult->errorBuffer, 0);    }    STAFServiceResult result;    STAFRequestNumber_t requestNumber;    STAFString reqNumString = parsedFreeResult->optionValue(sRequest);    if (!reqNumString.isDigits())        return STAFServiceResult(kSTAFInvalidValue);    else       requestNumber = parsedFreeResult->optionValue(sRequest).asUInt();    STAFServiceRequestPtr serviceRequest;    STAFRC_t rc = gRequestManagerPtr->getRequestData(reqNumString.asUInt(),                                                     serviceRequest);    if (rc != kSTAFOk) return STAFServiceResult(rc);    // check for FORCE if this is not the originating process    if ((requestInfo.fMachine != serviceRequest->fMachine) ||        (requestInfo.fHandle != serviceRequest->fHandle))    {        if (parsedFreeResult->optionTimes(sForce) == 0)            return STAFServiceResult(kSTAFAccessDenied);    }    rc = gRequestManagerPtr->freeRequest(requestNumber, &result);    if (rc != kSTAFOk)        return STAFServiceResult(rc);    // Create a marshalled map containing information for the freed request    STAFObjectPtr mc = STAFObject::createMarshallingContext();    mc->setMapClassDefinition(fFreeRequestInfoClass->reference());    STAFObjectPtr freeRequestMap = fFreeRequestInfoClass->createInstance();    freeRequestMap->put("rc", STAFString(result.fRC));    freeRequestMap->put("result", STAFString(result.fResult));    mc->setRootObject(freeRequestMap);    return STAFServiceResult(kSTAFOk, mc->marshall());}STAFServiceResult STAFServiceService::handleAdd(    const STAFServiceRequest &requestInfo){    // Verify that the requesting machine/user has at least trust level 5    IVALIDATE_TRUST(5, "ADD");    // Parse the request    STAFCommandParseResultPtr parsedResult = fAddParser->parse(        requestInfo.fRequest);    if (parsedResult->rc != kSTAFOk)    {        return STAFServiceResult(kSTAFInvalidRequestString,                                 parsedResult->errorBuffer, 0);    }    DEFINE_VAR_POOL_LIST(varPoolList, varPoolListSize, requestInfo);    STAFServiceResult result;    STAFString errorBuffer;    STAFString serviceName;    STAFString libraryName;    STAFString executable;    STAFString parms;    STAFString option;    STAFExternalService::OptionList options;    // Resolve SERVICE value    STAFRC_t rc = RESOLVE_STRING_OPTION("SERVICE", serviceName);    if (!rc) rc = RESOLVE_STRING_OPTION("LIBRARY", libraryName);    if (!rc) rc = RESOLVE_OPTIONAL_STRING_OPTION("EXECUTE", executable);    if (!rc) rc = RESOLVE_OPTIONAL_STRING_OPTION("PARMS", parms);    if (rc) return STAFServiceResult(rc, errorBuffer);    // Resolve OPTION values (if any are specified)    for (int i = 1; i <= parsedResult->optionTimes("OPTION"); ++i)    {        rc = RESOLVE_INDEXED_STRING_OPTION("OPTION", i, option);        if (rc) return STAFServiceResult(rc, errorBuffer);        options.push_back(option);    }    // Verify that the Service name specified is a valid name    rc = gServiceManagerPtr->verifyServiceName(serviceName);    if (rc != kSTAFOk)    {        return STAFServiceResult(            rc, STAFString("Service name ") + serviceName +            " is not valid.  " INVALID_SERVICE_NAME_ERROR_MESSAGE());    }    // Verify that the Service name specified does not already exist.    STAFServicePtr service;    rc = gServiceManagerPtr->get(serviceName, service, errorBuffer, true);    if (rc == kSTAFOk)        return STAFServiceResult(kSTAFAlreadyExists, serviceName);    // Create the service    try    {        service = STAFServicePtr(new STAFExternalService(                  serviceName, libraryName, executable, options, parms,                  kSTAFServiceTypeService),                  STAFServicePtr::INIT);    }    catch (STAFServiceCreateException &e)    {        return STAFServiceResult(kSTAFServiceConfigurationError,                                 STAFString(e.getErrorCode()) + ":" +                                 e.getText());    }    catch (STAFException &e)    {        return STAFServiceResult(kSTAFServiceConfigurationError,                                 STAFString(e.getErrorCode()) + ":" +                                 e.getText());    }    catch (...)    {        return STAFServiceResult(kSTAFServiceConfigurationError,                                 STAFString(""));    }    // Initialize the service    result = service->initialize();    if (result.fRC) return result;    // Add the service    rc = gServiceManagerPtr->add(service);    if (rc != kSTAFOk)    {        result = service->terminate();        return STAFServiceResult(rc, serviceName);    }    return STAFServiceResult(kSTAFOk, STAFString(""));}STAFServiceResult STAFServiceService::handleReplace(    const STAFServiceRequest &requestInfo){    // Verify that the requesting machine/user has at least trust level 5    IVALIDATE_TRUST(5, "REPLACE");    // Parse the request    STAFCommandParseResultPtr parsedResult = fReplaceParser->parse(        requestInfo.fRequest);    if (parsedResult->rc != kSTAFOk)    {        return STAFServiceResult(kSTAFInvalidRequestString,                                 parsedResult->errorBuffer, 0);    }    DEFINE_VAR_POOL_LIST(varPoolList, varPoolListSize, requestInfo);    STAFServiceResult result;    STAFString errorBuffer;    STAFString serviceName;    STAFString libraryName;    STAFString executable;    STAFString parms;    STAFString option;    STAFString newServiceName;    STAFExternalService::OptionList options;    // Resolve SERVICE value    STAFRC_t rc = RESOLVE_STRING_OPTION("SERVICE", serviceName);    if (!rc) rc = RESOLVE_STRING_OPTION("LIBRARY", libraryName);    if (!rc) rc = RESOLVE_OPTIONAL_STRING_OPTION("EXECUTE", executable);    if (!rc) rc = RESOLVE_OPTIONAL_STRING_OPTION("PARMS", parms);    if (rc) return STAFServiceResult(rc, errorBuffer);    // Resolve OPTION values (if any are specified)    for (int i = 1; i <= parsedResult->optionTimes("OPTION"); ++i)    {        rc = RESOLVE_INDEXED_STRING_OPTION("OPTION", i, option);        if (rc) return STAFServiceResult(rc, errorBuffer);        options.push_back(option);    }    // Resolve RENAME value (if specified)    STAFServicePtr newService;    if (parsedResult->optionTimes("RENAME") != 0)    {        rc = RESOLVE_STRING_OPTION("RENAME", newServiceName);        if (rc) return STAFServiceResult(rc, errorBuffer);        if (newServiceName.toUpperCase() == serviceName.toUpperCase())            return STAFServiceResult(kSTAFAlreadyExists, newServiceName);    }    // Create the new service    try    {        newService = STAFServicePtr(new STAFExternalService(                     serviceName, libraryName, executable, options, parms,                     kSTAFServiceTypeService),                     STAFServicePtr::INIT);    }    catch (STAFServiceCreateException &e)    {        return STAFServiceResult(kSTAFServiceConfigurationError,                                 STAFString(e.getErrorCode()) + ":" +                                 e.getText());    }    catch (STAFException &e)    {        return STAFServiceResult(kSTAFServiceConfigurationError,                                 STAFString(e.getErrorCode()) + ":" +                                 e.getText());    }    catch (...)    {        return STAFServiceResult(kSTAFServiceConfigurationError,                                 STAFString(""));    }    // Initialize the new service    result = newService->initialize();    if (result.fRC) return result;    // Replace with the new service    rc = gServiceManagerPtr->replace(newService, newServiceName, errorBuffer);    if (rc)    {        result = newService->terminate();        return STAFServiceResult(rc, STAFString(""));    }    return STAFServiceResult(kSTAFOk, STAFString(""));}STAFServiceResult STAFServiceService::handleRename(    const STAFServiceRequest &requestInfo){    // Verify that the requesting machine/user has at least trust level 5    IVALIDATE_TRUST(5, "RENAME");    // Parse the request    STAFCommandParseResultPtr parsedResult = fRenameParser->parse(        requestInfo.fRequest);    if (parsedResult->rc != kSTAFOk)    {        return STAFServiceResult(kSTAFInvalidRequestString,                                 parsedResult->errorBuffer, 0);    }    DEFINE_VAR_POOL_LIST(varPoolList, varPoolListSize, requestInfo);    STAFServiceResult result;    STAFString errorBuffer;    STAFString serviceName;    STAFString newServiceName;    STAFRC_t rc = RESOLVE_STRING_OPTION("SERVICE", serviceName);    if (!rc) rc = RESOLVE_STRING_OPTION("TO", newServiceName);    if (rc) return STAFServiceResult(rc, errorBuffer);    if (newServiceName.toUpperCase() == serviceName.toUpperCase())        return STAFServiceResult(kSTAFAlreadyExists, newServiceName);    // Rename with the new service name    rc = gServiceManagerPtr->rename(serviceName, newServiceName, errorBuffer);    if (rc) return STAFServiceResult(rc, errorBuffer);    return kSTAFOk;}STAFServiceResult STAFServiceService::handleRemove(    const STAFServiceRequest &requestInfo){    // Verify that the requesting machine/user has at least trust level 5    IVALIDATE_TRUST(5, "REMOVE");        // Parse the request        STAFCommandParseResultPtr parsedResult = fRemoveParser->parse(        requestInfo.fRequest);    if (parsedResult->rc != kSTAFOk)    {        return STAFServiceResult(kSTAFInvalidRequestString,                                 parsedResult->errorBuffer, 0);    }    DEFINE_VAR_POOL_LIST(varPoolList, varPoolListSize, requestInfo);    STAFServiceResult result;    STAFString errorBuffer;    STAFString serviceName;    STAFRC_t rc = RESOLVE_STRING_OPTION("SERVICE", serviceName);    if (rc) return STAFServiceResult(rc, errorBuffer);    STAFServicePtr service;    rc = gServiceManagerPtr->get(serviceName, service, errorBuffer);    if (rc) return STAFServiceResult(rc, serviceName);    // Remove the service    rc = gServiceManagerPtr->remove(serviceName);    if (rc) return STAFServiceResult(rc, serviceName);    // Terminate the service    result = service->terminate();    if (result.fRC) return result;    return kSTAFOk;}STAFServiceResult STAFServiceService::handleHelp(    const STAFServiceRequest &requestInfo){    // Verify that the requesting machine/user has at least trust level 1    IVALIDATE_TRUST(1, "HELP");    STAFString result = "SERVICE Service Help" + *gLineSeparatorPtr +                        *gLineSeparatorPtr;    result +=        "LIST    [SERVICES | SERVICELOADERS | AUTHENTICATORS |"        + *gLineSeparatorPtr +        "         REQUESTS [PENDING] [COMPLETE] [LONG]]"        + *gLineSeparatorPtr;    result += "QUERY   SERVICE <Service Name> | SERVICELOADER "        "<ServiceLoader Name> |" + *gLineSeparatorPtr;    result += "        AUTHENTICATOR <Authenticator Name> | "        "REQUEST <Request Number>" + *gLineSeparatorPtr;    result += "ADD     SERVICE <Service Name> LIBRARY <Library Name>" +        *gLineSeparatorPtr +        "        [EXECUTE <Executable>] [OPTION <Name[=Value]>]..." +        *gLineSeparatorPtr +        "        [PARMS <Parameters>]" + *gLineSeparatorPtr;    // XXX: Commented out REPLACE and RENAME options    //result += "REPLACE SERVICE <Service Name> LIBRARY <Library Name>" +    //    *gLineSeparatorPtr +    //    "        [EXECUTE <Executable>] [OPTION <Name[=Value]>]..." +    //    *gLineSeparatorPtr +    //    "        [PARMS <Parameters>] [RENAME <Service Name>]" +    //    *gLineSeparatorPtr;    //result += "RENAME  SERVICE <Service Name> TO <New Service Name>" +    //    *gLineSeparatorPtr;    result += "REMOVE  SERVICE <Service Name>" + *gLineSeparatorPtr;    result += "FREE    REQUEST <Request Number> [FORCE]" + *gLineSeparatorPtr;    result += "HELP" + *gLineSeparatorPtr;    return STAFServiceResult(kSTAFOk, result);}

⌨️ 快捷键说明

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