📄 stafproc.cpp
字号:
void handleRemoteServiceRequestAPI(unsigned int level, const STAFConnectionProvider *provider, STAFConnectionPtr &connection, unsigned int &doShutdown){ STAFServiceRequestPtr serviceRequestPtr = gRequestManager.getNewServiceRequest(); STAFServiceRequest &serviceRequest = *serviceRequestPtr; serviceRequest.fTargetMachine = gMachine; serviceRequest.fMachineNickname = connection->readString(); serviceRequest.fHandle = connection->readUInt(); serviceRequest.fHandleName = connection->readString(); serviceRequest.fTargetService = connection->readString(); serviceRequest.fRequest = connection->readString(); serviceRequest.fDiagEnabled = gDiagManager.getEnabled(); // Note: The request pool and source shared pool here are empty pools. // This is the downlevel protocol in which these pools aren't provided // by the remote end. serviceRequest.fRequestVarPool = STAFVariablePoolPtr(new STAFVariablePool, STAFVariablePoolPtr::INIT); serviceRequest.fSourceSharedVarPool = STAFVariablePoolPtr(new STAFVariablePool, STAFVariablePoolPtr::INIT); serviceRequest.fLocalSharedVarPool = *gSharedVariablePoolPtr; serviceRequest.fLocalSystemVarPool = *gGlobalVariablePoolPtr; // Remote is always synchronous serviceRequest.fSyncMode = kSTAFReqSync; serviceRequest.fInterface = provider->getName(); connection->getPeerNetworkIDs(serviceRequest.fLogicalInterfaceID, serviceRequest.fPhysicalInterfaceID); serviceRequest.fMachine = serviceRequest.fLogicalInterfaceID; serviceRequest.fAuthenticator = gNoneString; serviceRequest.fUserIdentifier = gAnonymousString; serviceRequest.fAuthenticationData = ""; serviceRequest.fUser = gNoneString + gSpecSeparator + gAnonymousString; serviceRequest.fEndpoint = serviceRequest.fInterface + gSpecSeparator + serviceRequest.fLogicalInterfaceID + serviceRequest.fPort; // Since this is a pre-V3 system, we don't have a real UUID, so we // simply assign the fEndpoint. Note, there is no way that this can // be a local request, as a STAF V3+ system would always come through // handleRemoteServiceRequestAPI2. serviceRequest.fSTAFInstanceUUID = serviceRequest.fEndpoint; serviceRequest.fIsLocalRequest = false; DEFINE_VAR_POOL_LIST(varPoolList, varPoolListSize, serviceRequest); STAFString errorBuffer; STAFString serviceName; STAFRC_t rc = RESOLVE_STRING(serviceRequest.fTargetService, serviceName); if (rc) { serviceRequest.fResult.fRC = rc; serviceRequest.fResult.fResult = errorBuffer; } else { // Resolved string, serviceName, is stripped to allow begining and/or // trailing white spaces serviceRequest.fTargetService = serviceName.strip(STAFString::kBoth); // Strip any whitespace from the beginning of a request serviceRequest.fRequest = serviceRequest.fRequest.strip( STAFString::kFront); rc = gRequestManager.add(serviceRequestPtr); try { serviceRequest.fResult = submitLocalRequest(connection, serviceRequest); } catch (...) { if (gRequestManager.requestExists(serviceRequest.fRequestNumber)) gRequestManager.deleteRequest(serviceRequest.fRequestNumber); throw; } } connection->writeUInt(serviceRequest.fResult.fRC); if (gResultCompatibilityMode == kSTAFResultCompatibilityVerbose) { // Unmarshall the result into a verbose pretty print format before // providing to a pre-STAF V3 machine connection->writeString(STAFObject::unmarshall( serviceRequest.fResult.fResult)->asFormattedString()); } else { // Don't change anything in the result connection->writeString(serviceRequest.fResult.fResult); } doShutdown = serviceRequest.fResult.fDoShutdown;}void handleRemoteServiceRequestAPI2(unsigned int level, const STAFConnectionProvider *provider, STAFConnectionPtr &connection, unsigned int &doShutdown){ STAFServiceRequestPtr serviceRequestPtr = gRequestManager.getNewServiceRequest(); STAFServiceRequest &serviceRequest = *serviceRequestPtr; serviceRequest.fTargetMachine = gMachine; serviceRequest.fPort = connection->readString(); serviceRequest.fSTAFInstanceUUID = connection->readString(); serviceRequest.fHandle = connection->readUInt(); serviceRequest.fHandleName = connection->readString(); serviceRequest.fTargetService = connection->readString(); serviceRequest.fRequest = connection->readString(); serviceRequest.fAuthenticator = connection->readString(); serviceRequest.fUserIdentifier = connection->readString(); serviceRequest.fAuthenticationData = connection->readString(); serviceRequest.fMachineNickname = connection->readString(); serviceRequest.fDiagEnabled = gDiagManager.getEnabled(); // Set up the intial/empty variable pools serviceRequest.fRequestVarPool = STAFVariablePoolPtr(new STAFVariablePool, STAFVariablePoolPtr::INIT); serviceRequest.fSourceSharedVarPool = STAFVariablePoolPtr(new STAFVariablePool, STAFVariablePoolPtr::INIT); serviceRequest.fLocalSharedVarPool = *gSharedVariablePoolPtr; serviceRequest.fLocalSystemVarPool = *gGlobalVariablePoolPtr; // Read request var pool unsigned int requestPoolSize = connection->readUInt(); for (unsigned int requestPoolIndex = 0; requestPoolIndex < requestPoolSize; ++requestPoolIndex) { STAFString varName = connection->readString(); STAFString varValue = connection->readString(); serviceRequest.fRequestVarPool->set(varName, varValue); } // Read shared var pool unsigned int sharedPoolSize = connection->readUInt(); for (unsigned int sharedPoolIndex = 0; sharedPoolIndex < sharedPoolSize; ++sharedPoolIndex) { STAFString varName = connection->readString(); STAFString varValue = connection->readString(); serviceRequest.fSourceSharedVarPool->set(varName, varValue); } STAFRC_t rc = kSTAFOk; // Remote Service Request is always synchronous serviceRequest.fSyncMode = kSTAFReqSync; // Get Interface information serviceRequest.fInterface = provider->getName(); connection->getPeerNetworkIDs(serviceRequest.fLogicalInterfaceID, serviceRequest.fPhysicalInterfaceID); serviceRequest.fMachine = serviceRequest.fLogicalInterfaceID; serviceRequest.fEndpoint = serviceRequest.fInterface + gSpecSeparator + serviceRequest.fMachine + serviceRequest.fPort; // Determine if request is really from the local machine STAFString myLogicalInterfaceID = STAFString(); STAFString myPhysicalInterfaceID = STAFString(); provider->getMyNetworkIDs(myLogicalInterfaceID, myPhysicalInterfaceID); if ((myPhysicalInterfaceID == serviceRequest.fPhysicalInterfaceID) && (serviceRequest.fSTAFInstanceUUID == gSTAFInstanceUUID)) serviceRequest.fIsLocalRequest = true; else serviceRequest.fIsLocalRequest = false; if (serviceRequest.fAuthenticator != gNoneString) { // Issue an Authenticate request to the specified Authenticator service // passing in the authentication data. If the authenticator is not // registered, set authenticator to "none" and userIdentifier to // "anonymous". serviceRequest.fResult = gHandleManager.authenticate( serviceRequest.fMachine, serviceRequest.fHandle, serviceRequest.fAuthenticator, serviceRequest.fUserIdentifier, STAFHandleManager::kData, serviceRequest.fAuthenticationData); } serviceRequest.fUser = serviceRequest.fAuthenticator + gSpecSeparator + serviceRequest.fUserIdentifier; if (serviceRequest.fResult.fRC == kSTAFOk) { DEFINE_VAR_POOL_LIST(varPoolList, varPoolListSize, serviceRequest); STAFString serviceName; STAFString errorBuffer; rc = RESOLVE_STRING(serviceRequest.fTargetService, serviceName); if (rc) { serviceRequest.fResult.fRC = rc; serviceRequest.fResult.fResult = errorBuffer; } else { // Resolved string, serviceName, is stripped to allow beginning // and/or trailing white spaces serviceRequest.fTargetService = serviceName.strip(STAFString::kBoth); // Strip any whitespace from the beginning of a request serviceRequest.fRequest = serviceRequest.fRequest.strip( STAFString::kFront); rc = gRequestManager.add(serviceRequestPtr); try { serviceRequest.fResult = submitLocalRequest(connection, serviceRequest); } catch (...) { if (gRequestManager.requestExists(serviceRequest.fRequestNumber)) gRequestManager.deleteRequest(serviceRequest.fRequestNumber); throw; } } } connection->writeUInt(serviceRequest.fResult.fRC); connection->writeString(serviceRequest.fResult.fResult); doShutdown = serviceRequest.fResult.fDoShutdown;}STAFServiceResult submitLocalRequest(STAFConnectionPtr &connection, STAFServiceRequest &serviceRequest){ STAFServicePtr service; STAFServiceResult serviceResult = STAFServiceResult(kSTAFOk); STAFServiceResult requestResult; STAFString errorBuffer; STAFRC_t rc = gServiceManager.get(serviceRequest.fTargetService, service, errorBuffer); if (rc) { if ((serviceRequest.fSyncMode != kSTAFReqRetain) && (serviceRequest.fSyncMode != kSTAFReqQueueRetain)) { gRequestManager.requestCompleted(serviceRequest.fRequestNumber, serviceResult); gRequestManager.freeRequest(serviceRequest.fRequestNumber, &requestResult); } if (rc == kSTAFDoesNotExist) rc = kSTAFUnknownService; if (serviceRequest.fSyncMode != kSTAFReqSync) { // pass back the request number serviceResult = STAFServiceResult(kSTAFOk, serviceRequest.fRequestNumber); connection->writeUInt(serviceResult.fRC); connection->writeString(serviceResult.fResult); // send the rc/result to the requester's queue if ((serviceRequest.fSyncMode == kSTAFReqQueue) || (serviceRequest.fSyncMode == kSTAFReqQueueRetain)) { // Create the message to queue. The message is a marshalled // map containing the request completion information. STAFObjectPtr mc = STAFObject::createMarshallingContext(); STAFObjectPtr messageMap = STAFObject::createMap(); messageMap->put("requestNumber", STAFString(serviceRequest.fRequestNumber)); messageMap->put("rc", STAFString(rc)); messageMap->put("result", serviceRequest.fTargetService + errorBuffer); mc->setRootObject(messageMap); STAFString resultMessage = mc->marshall(); // Submit the QUEUE request to the QUEUE service STAFString queueRequest(sQueueHandle + serviceRequest.fHandle); queueRequest += sType + sRequestComplete; queueRequest += sMessage + sColon + resultMessage.length(STAFString::kChar) + sColon + resultMessage; gSTAFProcHandlePtr->submit(sLocal, sQueue, queueRequest, kSTAFReqFireAndForget); } return STAFServiceResult(kSTAFOk); } return STAFServiceResult(rc, serviceRequest.fTargetService + errorBuffer); } else { // Let the submitter continue by sending back the service result // and then submit the actual request if (serviceRequest.fSyncMode != kSTAFReqSync) { // pass back the request number serviceResult = STAFServiceResult(kSTAFOk, serviceRequest.fRequestNumber); connection->writeUInt(serviceResult.fRC);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -