📄 stafproc.cpp
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF) *//* (C) Copyright IBM Corp. 2001, 2004 *//* *//* This software is licensed under the Common Public License (CPL) V1.0. *//*****************************************************************************/#include "STAF.h"#include "STAF_iostream.h"#include "STAF_fstream.h"#include "STAF_exception.h"#include "STAFString.h"#include "STAFProc.h"#include "STAFConfig.h"#include "STAFRefPtr.h"#include "STAFSocket.h"#include "STAFConnectionProvider.h"#include "STAFSimpleServices.h"#include "STAFProcessService.h"#include "STAFHandleService.h"#include "STAFVariableService.h"#include "STAFFSService.h"#include "STAFServiceService.h"#include "STAFTrustService.h"#include "STAFDiagService.h"#include "STAFQueueService.h"#include "STAFShutdownService.h"#include "STAFMiscService.h"#include "STAFTraceService.h"#include "STAFSemService.h"#include "STAFHelpService.h"#include "STAFEventSem.h"#include "STAFHandleManager.h"#include "STAFRequestManager.h"#include "STAFFSCopyManager.h"#include "STAFTrustManager.h"#include "STAFDiagManager.h"#include "STAFConnectionManager.h"#include "STAFServiceManager.h"#include "STAFNotificationList.h"#include "STAFException.h"#include "STAFUtil.h"#include "STAFProcUtil.h"#include "STAFProcOSUtil.h"#include "STAFTrace.h"#include "STAFThreadManager.h"#include "STAFFileSystem.h"#include "STAFConverter.h"//// Prototypes//STAFRC_t HandleRequest(const STAFConnectionProvider *provider, STAFConnectionPtr &connection);STAFServiceResult submitRemoteRequest(STAFConnectionPtr &connection, STAFServiceRequest &serviceRequest);void handleLocalServiceRequestAPI(unsigned int level, const STAFConnectionProvider *provider, STAFConnectionPtr &connection, unsigned int &doShutdown);void handleRemoteServiceRequestAPI(unsigned int level, const STAFConnectionProvider *provider, STAFConnectionPtr &connection, unsigned int &doShutdown);void handleRemoteServiceRequestAPI2(unsigned int level, const STAFConnectionProvider *provider, STAFConnectionPtr &connection, unsigned int &doShutdown);STAFServiceResult submitLocalRequest(STAFConnectionPtr &connection, STAFServiceRequest &serviceRequest);void handleProcessRegistrationAPI(unsigned int level, const STAFConnectionProvider *provider, STAFConnectionPtr &connection, unsigned int &);void handleProcessUnRegistrationAPI(unsigned int level, const STAFConnectionProvider *provider, STAFConnectionPtr &connection, unsigned int &);void handleFileTransferAPI(unsigned int level, const STAFConnectionProvider *provider, STAFConnectionPtr &connection, unsigned int &);void handleFileTransferAPI2(unsigned int level, const STAFConnectionProvider *provider, STAFConnectionPtr &connection, unsigned int &);void handleFileTransfer(unsigned int apiType, unsigned int level, const STAFConnectionProvider *provider, STAFConnectionPtr &connection);void handleDirectoryCopyAPI(unsigned int level, const STAFConnectionProvider *provider, STAFConnectionPtr &connection, unsigned int &);void handleHandleTerminationRegistrationAPI( unsigned int level, const STAFConnectionProvider *provider, STAFConnectionPtr &connection, unsigned int &);void handleRemoteHandleTerminatedAPI(unsigned int level, const STAFConnectionProvider *provider, STAFConnectionPtr &connection, unsigned int &);STAFRC_t writeFile(fstream &outFile, const char *fileBuffer, unsigned int writeLength, const STAFString toFile, const STAFString fromMachine, unsigned int fileLength, unsigned int currentPos);STAFServiceResult checkTrustForFSCopy(unsigned int apiType, unsigned int level, const STAFConnectionProvider *provider, STAFConnectionPtr &connection, const STAFString &orgMachine, const STAFString &fromMachine, unsigned int copyType);void stafProcTerminate();void replaceStringInBuffer (char* current, const char* searchStr, const char* replaceStr, int currentLen, int searchStrLen, int replaceStrLen, int* newLen, int* lastReplace, char* newBuffer);void rollBuffer(char * buffer, int bufferLen, int rollLen);void updateRemoveDirResultString(STAFString &result, STAFFSEntryPtr &entry, STAFRC_t rc, unsigned int osRC);STAFRC_t removeDirChildren(STAFFSEntryPtr entry, const STAFString &namePattern, const STAFString &extPattern, unsigned int entryTypesUInt, STAFFSCaseSensitive_t caseSensitive, STAFString &result);STAFRC_t removeDir(STAFFSEntryPtr entry, const STAFString &namePattern, const STAFString &extPattern, unsigned int entryTypesUInt, STAFFSCaseSensitive_t caseSensitive, STAFString &result);// type definitionstypedef void (*STAFAPIHandler)(unsigned int level, const STAFConnectionProvider *provider, STAFConnectionPtr &connection, unsigned int &doShutdown);const unsigned int kOldAPI = 0;const unsigned int kNewAPI = 1;struct STAFAPIDescriptor{ unsigned int apiType; // 0 = old API type, 1 = new API type unsigned int minLevel; unsigned int maxLevel; bool availLocal; // Can this API be called locally? bool availRemote; // Can this API be called from a remote system? STAFAPIHandler handler;};//// Global variables//// Note: New APIs must have a minimum/maximum level >= 1// Note: Whenever an entry is added to the gAPITable, add a corresponding entry// in enum STAFAPINumber in STAFProc.h so that the API number can be referencedSTAFAPIDescriptor gAPITable[] ={ // APINum 0 { kOldAPI, 2, 2, true, false, handleLocalServiceRequestAPI }, // APINum 1 { kOldAPI, 0, 0, false, true, handleRemoteServiceRequestAPI }, // APINum 2 { kOldAPI, 0, 0, true, false, handleProcessRegistrationAPI }, // APINum 3 { kOldAPI, 0, 0, true, false, handleProcessUnRegistrationAPI }, // APINum 4 { kOldAPI, 0, 0, true, true, handleFileTransferAPI }, // APINum 5 { kNewAPI, 1, 3, true, true, handleFileTransferAPI2 }, // APINum 6 { kNewAPI, 1, 4, true, true, handleDirectoryCopyAPI }, // APINum 7 { kNewAPI, 2, 2, false, true, handleRemoteServiceRequestAPI2 }, // APINum 8 { kNewAPI, 1, 1, false, true, handleHandleTerminationRegistrationAPI }, // APINum 9 { kNewAPI, 1, 1, false, true, handleRemoteHandleTerminatedAPI }};unsigned int gMaxAPINumber = (sizeof(gAPITable) / sizeof(STAFAPIDescriptor)) - 1;STAFString gVersion("3.2.1");STAFThreadManager gThreadManager(0, 1);STAFThreadManager *gThreadManagerPtr = &gThreadManager;STAFHandleManager gHandleManager;STAFHandleManager *gHandleManagerPtr = &gHandleManager;STAFRequestManager gRequestManager;STAFRequestManager *gRequestManagerPtr = &gRequestManager;STAFFSCopyManager gFSCopyManager;STAFFSCopyManager *gFSCopyManagerPtr = &gFSCopyManager;STAFTrustManager gTrustManager(5);STAFTrustManager *gTrustManagerPtr = &gTrustManager;STAFConnectionProviderPtr gLocalConnProv;STAFConnectionProviderPtr *gLocalConnProvPtr = &gLocalConnProv;STAFConnectionProviderPtr gTCPConnProv;STAFConnectionProviderPtr *gTCPConnProvPtr = &gTCPConnProv;STAFConnectionManager gConnectionManager;STAFConnectionManager *gConnectionManagerPtr = &gConnectionManager;STAFServiceManager gServiceManager;STAFServiceManager *gServiceManagerPtr = &gServiceManager;STAFDiagManager gDiagManager(0);STAFDiagManager *gDiagManagerPtr = &gDiagManager;STAFEventSemPtr gShutdownSemaphore;STAFEventSemPtr *gShutdownSemaphorePtr = &gShutdownSemaphore;STAFEventSemPtr gGCPollingSem = STAFEventSemPtr(new STAFEventSem(), STAFEventSemPtr::INIT);STAFEventSemPtr *gGCPollingSemPtr = &gGCPollingSem;unsigned int gContinueGCPolling = 1;STAFProcessID_t gSTAFProcPID = 0;STAFHandle_t gSTAFProcHandle = 0;STAFHandlePtr gSTAFProcHandlePtr;STAFEnvMap gEnvMap;STAFEnvMap *gEnvMapPtr = &gEnvMap;unsigned char *gEnvBuffer = 0;int gEnvSize = 0;STAFMutexSem gDirectorySem;STAFMutexSem *gDirectorySemPtr = &gDirectorySem;STAFString gSTAFInstanceUUID;STAFString *gSTAFInstanceUUIDPtr = &gSTAFInstanceUUID;STAFString gMachineNickname;STAFString *gMachineNicknamePtr = &gMachineNickname;STAFString gMachine;STAFString *gMachinePtr = &gMachine;STAFString gDefaultAuthenticator;STAFString gSTAFWriteLocation;STAFString *gSTAFWriteLocationPtr = &gSTAFWriteLocation;STAFString gSTAFInstanceName;STAFString *gSTAFInstanceNamePtr = &gSTAFInstanceName;STAFVariablePoolPtr gGlobalVariablePool(new STAFVariablePool, STAFVariablePoolPtr::INIT);STAFVariablePoolPtr *gGlobalVariablePoolPtr = &gGlobalVariablePool;STAFVariablePoolPtr gSharedVariablePool(new STAFVariablePool, STAFVariablePoolPtr::INIT);STAFVariablePoolPtr *gSharedVariablePoolPtr = &gSharedVariablePool;unsigned short gTCPIPPort = 6500;unsigned int gMaxQueueSize = 100;unsigned int gNumInitialThreads = 10;STAFProcessConsoleMode_t gDefaultConsoleMode = kSTAFProcessNewConsole;unsigned int gResultCompatibilityMode = kSTAFResultCompatibilityVerbose;unsigned int gStrictFSCopyTrust = 0; // 0 = Disable strict FS Copy trustlong gMaxFiles = 500;unsigned int gConnectionAttempts = 2;unsigned int gConnectionRetryDelay = 1000;STAFNotificationList gNotifyOnStart;STAFNotificationList *gNotifyOnStartPtr = &gNotifyOnStart;STAFNotificationList gNotifyOnShutdown;STAFNotificationList *gNotifyOnShutdownPtr = &gNotifyOnShutdown;STAFEventSem gInterfaceSem;STAFString gLineSeparator;STAFString *gLineSeparatorPtr = &gLineSeparator;STAFString gFileSeparator;STAFString *gFileSeparatorPtr = &gFileSeparator;STAFString gPathSeparator;STAFString *gPathSeparatorPtr = &gPathSeparator;STAFString gCommandSeparator;STAFString *gCommandSeparatorPtr = &gCommandSeparator;// Separator for interface and system identifier and for authenticator and// user identifier specifications:// [<Interface>://]<System Identifier>// [<Authenticator>://]<User Identifier>const STAFString gSpecSeparator(STAFString(kUTF8_COLON) + STAFString(kUTF8_SLASH) + STAFString(kUTF8_SLASH));// Handles which are un-authenticated are assigned authenticator "none"// and user identifier "anonymous".const STAFString gNoneString("none");const STAFString gAnonymousString("anonymous");const STAFString gUnauthenticatedUser(gNoneString + gSpecSeparator + gAnonymousString);const STAFString sQueueHandle("QUEUE HANDLE ");const STAFString sMessage(" MESSAGE ");const STAFString sType(" TYPE ");const STAFString sRequestComplete("STAF/RequestComplete ");const STAFString sSemiColon(";");const STAFString sColon(":");const STAFString sLocal("LOCAL");const STAFString sLowerLocal("local");const STAFString sLocalLong("local://local");const STAFString sQueue("QUEUE");int main(int argc, char **argv, char **envp){#ifdef STAF_OS_NAME_ZOS extern char **environ; envp = environ;#endif // Register our termination handler. It will simply tell us if we have // ended abruptly due to an uncaught or unexpected exception. STAF_set_terminate(stafProcTerminate); gSTAFProcPID = STAFUtilGetPID(); // Set STAF instance name gSTAFInstanceName = "STAF"; if (getenv("STAF_INSTANCE_NAME") != NULL) { gSTAFInstanceName = getenv("STAF_INSTANCE_NAME"); } // Initialize Platform specific code STAFString errorBuffer = ""; unsigned int osRC = 0; int stafOSInitRC = STAFProcOSInit(errorBuffer, osRC); if (stafOSInitRC != 0) { cout << "Error during platform-specific initialization" << endl; cout << errorBuffer << ", RC: " << osRC << endl; return 1; } // Default tracing to standard output STAFTrace::setTraceDestination(kSTAFTraceToStdout); // Initialize the global variable pool // // Note: The variable "Machine" is set after the config is read STAFString configHead("STAF/Config/"); STAFConfigInfo configInfo; STAFString_t errorBufferT; STAFRC_t rc = STAFUtilGetConfigInfo(&configInfo, &errorBufferT, &osRC); if (rc != kSTAFOk) { cout << STAFString(errorBufferT, STAFString::kShallow); cout << ", STAF rc: " << rc << ", OS rc: " << osRC << endl; return 1; } gGlobalVariablePool->set("STAF/Version", gVersion); gGlobalVariablePool->set(configHead + "InstanceName", gSTAFInstanceName); gGlobalVariablePool->set(configHead + "BootDrive", configInfo.bootDrive); gGlobalVariablePool->set(configHead + "OS/Name", configInfo.osName); gGlobalVariablePool->set(configHead + "OS/MajorVersion", configInfo.osMajorVersion);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -