📄 stafmiscservice.cpp
字号:
fQueryParser.parse(requestInfo.fRequest); if (parsedResult->rc != kSTAFOk) { return STAFServiceResult(kSTAFInvalidRequestString, parsedResult->errorBuffer, 0); } DEFINE_VAR_POOL_LIST(varPoolList, varPoolListSize, requestInfo); STAFString theInterface; STAFString errorBuffer; STAFRC_t rc = RESOLVE_STRING_OPTION("INTERFACE", theInterface); if (rc) return STAFServiceResult(rc, errorBuffer); // Create a marshalled map containing interface information STAFObjectPtr mc = STAFObject::createMarshallingContext(); mc->setMapClassDefinition(fInterfaceClass->reference()); bool interfaceFound = false; STAFConnectionManager::ConnectionProviderList connProvList = gConnectionManagerPtr->getConnectionProviderListCopy(); for (STAFConnectionManager::ConnectionProviderList::iterator iter = connProvList.begin(); iter != connProvList.end(); ++iter) { if (theInterface == (*iter)->getName()) { interfaceFound = true; STAFObjectPtr interfaceMap = fInterfaceClass->createInstance(); interfaceMap->put("name", theInterface); interfaceMap->put("library", (*iter)->getLibrary()); // Get the options from the connection provider STAFObjectPtr options; (*iter)->getOptions(options); interfaceMap->put("optionMap", options->reference()); mc->setRootObject(interfaceMap); // Found the interface so break out of the loop break; } } // Get rid of connection provider references connProvList = STAFConnectionManager::ConnectionProviderList(); if (!interfaceFound) return STAFServiceResult(kSTAFDoesNotExist, theInterface); else return STAFServiceResult(kSTAFOk, mc->marshall());}STAFServiceResult STAFMiscService::handleTest( const STAFServiceRequest &requestInfo){ // Verify that the requesting machine/user has at least trust level 3 IVALIDATE_TRUST(3, "TEST"); // Parse the request STAFCommandParseResultPtr parsedResult = fTestParser.parse(requestInfo.fRequest); if (parsedResult->rc != kSTAFOk) { return STAFServiceResult(kSTAFInvalidRequestString, parsedResult->errorBuffer, 0); } // Set up some constants that are used repeatedly STAFString sTimestamp("timestamp"); STAFString sLevel("level"); STAFString sMachine("machine"); STAFString sSystem("x.y.z.com"); STAFString sMessage("message"); STAFString sSTAFMapClassName("staf-map-class-name"); STAFString sLogRecord("STAF/Service/Misc/SampleLogRecord"); STAFString sInfo("info"); // Create the marshalling context STAFObjectPtr mc = STAFObject::createMarshallingContext(); // Figure out which data set the user asked for unsigned int dataSet = 1; if (parsedResult->optionTimes("DATA") != 0) dataSet = parsedResult->optionValue("DATA").asUInt(); if ((dataSet == 1) || (dataSet == 2)) { mc->setMapClassDefinition(fLogRecordClass->reference()); // Populate the list with regular log records STAFObjectPtr logList = STAFObject::createList(); int i = 0; for (i = 1; i < 6; ++i) { STAFObjectPtr logRecord = STAFObject::createMap(); logRecord->put(sSTAFMapClassName, sLogRecord); logRecord->put(sLevel, sInfo); logRecord->put(sMessage, STAFString("Message #") + i); logRecord->put(sMachine, sSystem); logRecord->put(sTimestamp, STAFTimestamp::now().asString()); logList->append(logRecord); } // If we are in dataSet == 2, then we add some "broken" log records to // the list if (dataSet == 2) { // Now, let's add one record that doesn't use the map class STAFObjectPtr logRecord = STAFObject::createMap(); logRecord->put(sLevel, sInfo); logRecord->put(sMessage, STAFString("Message #") + i++); logRecord->put(sMachine, sSystem); logRecord->put(sTimestamp, STAFTimestamp::now().asString()); logList->append(logRecord); // Now, let's add one record using the map class that doesn't include // all the necessary keys logRecord = STAFObject::createMap(); logRecord->put(sSTAFMapClassName, sLogRecord); logRecord->put(sMessage, STAFString("Message #") + i++); logRecord->put(sMachine, sSystem); logRecord->put(sTimestamp, STAFTimestamp::now().asString()); logList->append(logRecord); } mc->setRootObject(logList); } else if (dataSet == 3) { STAFObjectPtr outerMap = STAFObject::createMap(); outerMap->put("SomeMap", fMapOfLists->reference()); outerMap->put("SomeList", fListOfMaps->reference()); mc->setRootObject(outerMap); } else if (dataSet == 4) { // Dataset 4 is a nice little nested structure like [[{}], {[]}] STAFObjectPtr outerList = STAFObject::createList(); outerList->append(fListOfMaps->reference()); outerList->append(fMapOfLists->reference()); mc->setRootObject(outerList); } else if (dataSet == 5) { // Dataset 5 is a simple list containing a nested marshalling context // containing no map class definition, and another containing a map // class definition // Create the list and add a couple of strings STAFObjectPtr theList = STAFObject::createList(); theList->append("String1"); theList->append("String2"); // Create the nested MC without any map class definitions STAFObjectPtr nestedMC1 = STAFObject::createMarshallingContext(); STAFObjectPtr innerMap1 = STAFObject::createMap(); innerMap1->put("key1", "value1"); innerMap1->put("key2", "value2"); nestedMC1->setRootObject(innerMap1); theList->append(nestedMC1); // Create the nested MC with the map class definition STAFObjectPtr nestedMC2 = STAFObject::createMarshallingContext(); // Create the map class definition STAFMapClassDefinitionPtr mapClass = STAFMapClassDefinition::create("STAF/Service/Misc/TrivialMap"); mapClass->addKey("key1", "Key 1"); mapClass->addKey("key2", "Key 2"); nestedMC2->setMapClassDefinition(mapClass); // Now, create the map using the definition STAFObjectPtr innerMap2 = STAFObject::createMap(); innerMap2->put(sSTAFMapClassName, "STAF/Service/Misc/TrivialMap"); innerMap2->put("key1", "value1"); innerMap2->put("key2", "value2"); nestedMC2->setRootObject(innerMap2); theList->append(nestedMC2); // Finally, add a couple more simple strings theList->append("String3"); theList->append("String4"); mc->setRootObject(theList); } else if (dataSet == 6) { // Dataset 6 is a simple list of strins where one of the strings in the // list is the string from marshalling a simple map. STAFObjectPtr theList = STAFObject::createList(); STAFObjectPtr aMap = STAFObject::createMap(); aMap->put("key1", "value1"); aMap->put("key2", "value2"); theList->append("String1"); theList->append("String2"); theList->append(aMap->marshall()); theList->append("String3"); theList->append("String4"); mc->setRootObject(theList); } else if (dataSet == 7) { // Dataset 6 is a list of map class instances (which should normally // print in table mode). However, some of the entries are structures // instead of strings. // Create a couple dummy structures STAFObjectPtr aList = STAFObject::createList(); STAFObjectPtr aMap = STAFObject::createMap(); aMap->put("key1", "value1"); aMap->put("key2", "value2"); aList->append("String1"); aList->append("String2"); aList->append("String3"); // Now populate the output list with some records mc->setMapClassDefinition(fLogRecordClass->reference()); STAFObjectPtr theList = STAFObject::createList(); STAFObjectPtr logRecord1 = STAFObject::createMap(); logRecord1->put(sSTAFMapClassName, sLogRecord); logRecord1->put(sLevel, sInfo); logRecord1->put(sMessage, aMap); logRecord1->put(sMachine, sSystem); logRecord1->put(sTimestamp, STAFTimestamp::now().asString()); theList->append(logRecord1); STAFObjectPtr logRecord2 = STAFObject::createMap(); logRecord2->put(sSTAFMapClassName, sLogRecord); logRecord2->put(sLevel, sInfo); logRecord2->put(sMessage, aList); logRecord2->put(sMachine, sSystem); logRecord2->put(sTimestamp, STAFTimestamp::now().asString()); theList->append(logRecord2); STAFObjectPtr logRecord3 = STAFObject::createMap(); logRecord3->put(sSTAFMapClassName, sLogRecord); logRecord3->put(sLevel, sInfo); logRecord3->put(sMessage, aMap); logRecord3->put(sMachine, sSystem); logRecord3->put(sTimestamp, STAFTimestamp::now().asString()); STAFObjectPtr logRecord4 = STAFObject::createMap(); logRecord4->put(sSTAFMapClassName, sLogRecord); logRecord4->put(sLevel, sInfo); logRecord4->put(sMessage, logRecord3); logRecord4->put(sMachine, sSystem); logRecord4->put(sTimestamp, STAFTimestamp::now().asString()); theList->append(logRecord4); STAFObjectPtr logRecord5 = STAFObject::createMap(); logRecord5->put(sSTAFMapClassName, sLogRecord); logRecord5->put(sLevel, sInfo); logRecord5->put(sMessage, "A simple string message"); logRecord5->put(sMachine, sSystem); logRecord5->put(sTimestamp, STAFTimestamp::now().asString()); theList->append(logRecord5); mc->setRootObject(theList); } return STAFServiceResult(kSTAFOk, mc->marshall());}STAFServiceResult STAFMiscService::handleDebug( const STAFServiceRequest &requestInfo){ // Verify that the requesting machine/user has at least trust level 5 IVALIDATE_TRUST(5, "DEBUG"); // Parse the request STAFCommandParseResultPtr parsedResult = fDebugParser.parse(requestInfo.fRequest); if (parsedResult->rc != kSTAFOk) { return STAFServiceResult(kSTAFInvalidRequestString, parsedResult->errorBuffer, 0); } #if defined(STAF_OS_TYPE_WIN32) && defined(_DEBUG) if (parsedResult->optionTimes("CHECKPOINT") > 0) { _CrtMemCheckpoint(&fFromMemState); } else if (parsedResult->optionTimes("DUMP") > 0) { if (parsedResult->optionTimes("ALL") > 0) _CrtMemDumpAllObjectsSince(0); else _CrtMemDumpAllObjectsSince(&fFromMemState); } else if (parsedResult->optionTimes("STATS") > 0) { _CrtMemDumpStatistics(&fFromMemState); } else if (parsedResult->optionTimes("STATSDIFF") > 0) { _CrtMemState nowMemState; _CrtMemState deltaMemState; _CrtMemCheckpoint(&nowMemState); _CrtMemDifference(&deltaMemState, &fFromMemState, &nowMemState); _CrtMemDumpStatistics(&deltaMemState); } else if (parsedResult->optionTimes("LEAKS") > 0) { _CrtDumpMemoryLeaks(); } #endif return kSTAFOk;}STAFServiceResult STAFMiscService::handleHelp( const STAFServiceRequest &requestInfo){ // Verify that the requesting machine/user has at least trust level 1 IVALIDATE_TRUST(1, "HELP"); STAFString result("MISC service help" + *gLineSeparatorPtr + *gLineSeparatorPtr); result += "VERSION" + *gLineSeparatorPtr + *gLineSeparatorPtr; result += "WHOAMI" + *gLineSeparatorPtr + *gLineSeparatorPtr; result += "WHOAREYOU" + *gLineSeparatorPtr + *gLineSeparatorPtr; result += "LIST INTERFACES | SETTINGS | ENDPOINTCACHE" + *gLineSeparatorPtr + *gLineSeparatorPtr; result += "QUERY INTERFACE <Name>" + *gLineSeparatorPtr + *gLineSeparatorPtr; result += "SET [CONNECTATTEMPTS <Number>] " "[CONNECTRETRYDELAY <Number>]" + *gLineSeparatorPtr; result += " [MAXQUEUESIZE <Number>] " " [INTERFACECYCLING <Enabled | Disabled>]" + *gLineSeparatorPtr; result += " [DEFAULTINTERFACE <Name>] " " [DEFAULTAUTHENTICATOR <Name>] " + *gLineSeparatorPtr; result += " [RESULTCOMPATIBILITYMODE <Verbose | None>]" + *gLineSeparatorPtr + *gLineSeparatorPtr; result += "PURGE ENDPOINTCACHE <ENDPOINT <Endpoint>... | CONFIRM>" + *gLineSeparatorPtr + *gLineSeparatorPtr; result += "HELP" + *gLineSeparatorPtr; return STAFServiceResult(kSTAFOk, result);}STAFString STAFMiscService::info(unsigned int) const{ return name() + ": Internal";}STAFMiscService::~STAFMiscService(){ /* Do Nothing */}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -