📄 wbemexeccommand.cpp
字号:
case _OPTION_PORTNUMBER: { if (getOpts.isSet (_OPTION_PORTNUMBER) > 1) { // // More than one portNumber option was found // throw DuplicateOptionException(_OPTION_PORTNUMBER); } _portNumberStr = getOpts [i].Value (); try { getOpts [i].Value (_portNumber); } catch (const TypeMismatchException&) { throw InvalidOptionArgumentException(_portNumberStr, _OPTION_PORTNUMBER); } _portNumberSet = true; break; } case _OPTION_HTTPVERSION: { if (getOpts.isSet (_OPTION_HTTPVERSION) > 1) { // // More than one httpVersion option was found // throw DuplicateOptionException(_OPTION_HTTPVERSION); } httpVersion = getOpts [i].Value (); break; } case _OPTION_SSL: { _useSSL = true; break; } case _OPTION_HTTPMETHOD: { if (getOpts.isSet (_OPTION_HTTPMETHOD) > 1) { // // More than one httpMethod option was found // throw DuplicateOptionException(_OPTION_HTTPMETHOD); } httpMethod = getOpts [i].Value (); break; } case _OPTION_TIMEOUT: { if (getOpts.isSet (_OPTION_TIMEOUT) > 1) { // // More than one timeout option was found // throw DuplicateOptionException(_OPTION_TIMEOUT); } timeoutStr = getOpts [i].Value (); try { getOpts [i].Value (_timeout); } catch (const TypeMismatchException&) { throw InvalidOptionArgumentException( timeoutStr, _OPTION_TIMEOUT); } break; } case _OPTION_USERNAME: { if (getOpts.isSet (_OPTION_USERNAME) > 1) { // // More than one username option was found // throw DuplicateOptionException(_OPTION_USERNAME); } _userName = getOpts [i].Value (); _userNameSet = true; break; } case _OPTION_PASSWORD: { if (getOpts.isSet (_OPTION_PASSWORD) > 1) { // // More than one password option was found // throw DuplicateOptionException(_OPTION_PASSWORD); } _password = getOpts [i].Value (); _passwordSet = true; break; } case _OPTION_DEBUG: { // // String debugOptionStr; debugOptionStr = getOpts [i].Value (); if (debugOptionStr.size () != 1) { // // Invalid debug option // throw InvalidOptionArgumentException( debugOptionStr, _OPTION_DEBUG); } if (debugOptionStr [0] == _DEBUG_OPTION1) { _debugOutput1 = true; } else if (debugOptionStr [0] == _DEBUG_OPTION2) { _debugOutput2 = true; } else { // // Invalid debug option // throw InvalidOptionArgumentException( debugOptionStr, _OPTION_DEBUG); } break; } default: // // This path should not be hit // break; } } }/* // // Some more validations // if ( _operationType == OPERATION_TYPE_UNINITIALIZED ) { // // No operation type was specified // Show the usage // //l10n //CommandFormatException e (REQUIRED_ARGS_MISSING); throw CommandFormatException(localizeMessage( MSG_PATH, REQUIRED_ARGS_MISSING_KEY, REQUIRED_ARGS_MISSING)); }*/ if (getOpts.isSet (_OPTION_PORTNUMBER) < 1) { // // No portNumber specified // Default to WBEM_DEFAULT_PORT // Already done in constructor // } else { if (_portNumber > _MAX_PORTNUMBER) { // // Portnumber out of valid range // throw InvalidOptionArgumentException( _portNumberStr, _OPTION_PORTNUMBER); } } if (getOpts.isSet (_OPTION_HTTPVERSION) < 1) { // // No httpVersion specified // Default is to use HTTP/1.1 // _useHTTP11 = true; } else { if (httpVersion == HTTP_VERSION_10) { _useHTTP11 = false; } // // If version specified is "1.1", use HTTP/1.1 // else if (httpVersion == HTTP_VERSION_11) { _useHTTP11 = true; } // // Invalid (unsupported) HTTP version specified // else { throw InvalidOptionArgumentException( httpVersion, _OPTION_HTTPVERSION); } } if (getOpts.isSet (_OPTION_HTTPMETHOD) < 1) { // // No httpMethod specified // Default is to use POST // _useMPost = false; } else { // // Use HTTP POST method // if (httpMethod == HTTP_METHOD_POST) { _useMPost = false; } // // Use HTTP M-POST method // else if (httpMethod == HTTP_METHOD_MPOST) { _useMPost = true; } // // Invalid HTTP method specified // else { throw InvalidOptionArgumentException( httpMethod, _OPTION_HTTPMETHOD); } } if (getOpts.isSet (_OPTION_TIMEOUT) < 1) { // // No timeout specified // Default to WbemExecClient::DEFAULT_TIMEOUT_MILLISECONDS // Already done in constructor // } else { if (_timeout <= 0) { // // Timeout out of valid range // throw InvalidOptionArgumentException(timeoutStr, _OPTION_TIMEOUT); } }}/** Executes the command and writes the results to the PrintWriters. @param outPrintWriter the ostream to which output should be written @param errPrintWriter the ostream to which error output should be written @return 0 if the command is successful 1 if an error occurs in executing the command */Uint32 WbemExecCommand::execute (ostream& outPrintWriter, ostream& errPrintWriter){ if ( _operationType == OPERATION_TYPE_HELP ) { cerr << usage << endl; return (RC_SUCCESS); } else if ( _operationType == OPERATION_TYPE_VERSION ) { cerr << "Version " << PEGASUS_PRODUCT_VERSION << endl; return (RC_SUCCESS); } try { _executeHttp (outPrintWriter, errPrintWriter); } catch (const WbemExecException& e) { errPrintWriter << WbemExecCommand::COMMAND_NAME << ": " << e.getMessage () << endl; return (RC_ERROR); } catch (const Exception& e) { errPrintWriter << WbemExecCommand::COMMAND_NAME << ": " << e.getMessage() << endl; return (RC_ERROR); }#if !defined(PEGASUS_OS_LSB) catch (const exception& e) { errPrintWriter << WbemExecCommand::COMMAND_NAME << ": " << e.what() << endl; return (RC_ERROR); }#endif catch (...) { errPrintWriter << WbemExecCommand::COMMAND_NAME << ": " << "Unknown error thrown" << endl; return (RC_ERROR); } return (RC_SUCCESS);}/** Parses the command line, and executes the command. @param argc the number of command line arguments @param argv the string vector of command line arguments @return 0 if the command is successful 1 if an error occurs in executing the command */PEGASUS_NAMESPACE_END// exclude main from the Pegasus NamespacePEGASUS_USING_PEGASUS;PEGASUS_USING_STD;int main (int argc, char* argv []){ WbemExecCommand command = WbemExecCommand (); int rc; MessageLoader::setPegasusMsgHomeRelative(argv[0]); try { command.setCommand (argc, argv); } catch (const CommandFormatException& cfe) { String msg(cfe.getMessage()); cerr << WbemExecCommand::COMMAND_NAME << ": " << msg << endl; if (msg.find(String("Unknown flag")) != PEG_NOT_FOUND) { MessageLoaderParms parms(ERR_OPTION_NOT_SUPPORTED_KEY,ERR_OPTION_NOT_SUPPORTED); parms.msg_src_path = MSG_PATH; cerr << WbemExecCommand::COMMAND_NAME << ": " << MessageLoader::getMessage(parms) << endl; } else { MessageLoaderParms parms(ERR_USAGE_KEY,ERR_USAGE); parms.msg_src_path = MSG_PATH; cerr << WbemExecCommand::COMMAND_NAME << ": " << MessageLoader::getMessage(parms) << endl; } exit (Command::RC_ERROR); } rc = command.execute (cout, cerr); exit (rc); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -