📄 osinfo.cpp
字号:
randFile = FileSystem::getAbsolutePath( pegasusHome, PEGASUS_SSLCLIENT_RANDOMFILE); SSLContext sslcontext (certpath, verifyCertificate, randFile); client.connect(host, portNumber, sslcontext, _userName, _password ); } else { client.connect(host, portNumber, _userName, _password ); } }}/** Parses the command line, validates the options, and sets instance variables based on the option arguments. @param argc the number of command line arguments @param argv the string vector of command line arguments @exception CommandFormatException if an error is encountered in parsing the command line */void OSInfoCommand::setCommand (Uint32 argc, char* argv []){ Uint32 i = 0; Uint32 c = 0; String httpVersion = String (); String httpMethod = String (); String timeoutStr = String (); String GetOptString = String (); getoopt getOpts; _operationType = OPERATION_TYPE_UNINITIALIZED; // // Construct GetOptString //#ifndef DISABLE_SUPPORT_FOR_REMOTE_CONNECTIONS GetOptString.append (_OPTION_HOSTNAME); GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR); GetOptString.append (_OPTION_PORTNUMBER); GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR); GetOptString.append (_OPTION_SSL); GetOptString.append (_OPTION_TIMEOUT); GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR); GetOptString.append (_OPTION_USERNAME); GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR); GetOptString.append (_OPTION_PASSWORD); GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);#endif GetOptString.append (_OPTION_RAW_DATETIME_FORMAT); // // Initialize and parse getOpts // getOpts = getoopt (); getOpts.addFlagspec (GetOptString); //PEP#167 - adding long flag for options : 'help' and 'version' getOpts.addLongFlagspec(LONG_HELP,getoopt::NOARG); getOpts.addLongFlagspec(LONG_VERSION,getoopt::NOARG); getOpts.parse (argc, argv); if (getOpts.hasErrors ()) { CommandFormatException e (getOpts.getErrorStrings () [0]); throw e; } // // Get options and arguments from the command line // for (i = getOpts.first (); i < getOpts.last (); i++) { if (getOpts[i].getType () == Optarg::LONGFLAG) { if (getOpts[i].getopt () == LONG_HELP) { if (_operationType != OPERATION_TYPE_UNINITIALIZED) { String param = String (LONG_HELP); // // More than one operation option was found // UnexpectedOptionException e (param); throw e; } _operationType = OPERATION_TYPE_HELP; } else if (getOpts[i].getopt () == LONG_VERSION) { if (_operationType != OPERATION_TYPE_UNINITIALIZED) { String param = String (LONG_VERSION); // // More than one operation option was found // UnexpectedOptionException e (param); throw e; } _operationType = OPERATION_TYPE_VERSION; } } else if (getOpts [i].getType () == Optarg::REGULAR) { UnexpectedArgumentException e ( getOpts [i].Value ()); throw e; } else /* getOpts [i].getType () == FLAG */ { c = getOpts [i].getopt () [0]; switch (c) { case _OPTION_HOSTNAME: { if (getOpts.isSet (_OPTION_HOSTNAME) > 1) { // // More than one hostname option was found // DuplicateOptionException e (_OPTION_HOSTNAME); throw e; } _hostName = getOpts [i].Value (); _hostNameSet = true; break; } case _OPTION_PORTNUMBER: { if (getOpts.isSet (_OPTION_PORTNUMBER) > 1) { // // More than one portNumber option was found // DuplicateOptionException e (_OPTION_PORTNUMBER); throw e; } _portNumberStr = getOpts [i].Value (); try { getOpts [i].Value (_portNumber); } catch (const TypeMismatchException&) { InvalidOptionArgumentException e (_portNumberStr, _OPTION_PORTNUMBER); throw e; } _portNumberSet = true; break; } case _OPTION_SSL: { // // Use port 5989 as the default port for SSL // _useSSL = true; if (!_portNumberSet) _portNumber = 5989; break; } case _OPTION_RAW_DATETIME_FORMAT: { // // Display "raw" CIM_DateTime format. // _useRawDateTimeFormat = true; break; } case _OPTION_TIMEOUT: { if (getOpts.isSet (_OPTION_TIMEOUT) > 1) { // // More than one timeout option was found // DuplicateOptionException e (_OPTION_TIMEOUT); throw e; } timeoutStr = getOpts [i].Value (); try { getOpts [i].Value (_timeout); } catch (const TypeMismatchException&) { InvalidOptionArgumentException e (timeoutStr, _OPTION_TIMEOUT); throw e; } break; } case _OPTION_USERNAME: { if (getOpts.isSet (_OPTION_USERNAME) > 1) { // // More than one username option was found // DuplicateOptionException e (_OPTION_USERNAME); throw e; } _userName = getOpts [i].Value (); _userNameSet = true; break; } case _OPTION_PASSWORD: { if (getOpts.isSet (_OPTION_PASSWORD) > 1) { // // More than one password option was found // DuplicateOptionException e (_OPTION_PASSWORD); throw e; } _password = getOpts [i].Value (); _passwordSet = true; break; } default: // // This path should not be hit // PEP#167 unless an empty '-' is specified //_operationType = OPERATION_TYPE_UNINITIALIZED; break; } } } // // Some more validations // /*if ( _operationType == OPERATION_TYPE_UNINITIALIZED ) { // // No operation type was specified // Show the usage // //l10n //CommandFormatException e (REQUIRED_ARGS_MISSING); CommandFormatException e (localizeMessage(MSG_PATH,REQUIRED_ARGS_MISSING_KEY, REQUIRED_ARGS_MISSING)); throw e; }*/ 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 // InvalidOptionArgumentException e (_portNumberStr, _OPTION_PORTNUMBER); throw e; } } if (getOpts.isSet (_OPTION_TIMEOUT) < 1) { // // No timeout specified // Default to DEFAULT_TIMEOUT_MILLISECONDS // Already done in constructor // } else { if (_timeout <= 0) { // // Timeout out of valid range // InvalidOptionArgumentException e (timeoutStr, _OPTION_TIMEOUT); throw e; } }}/** ErrorExit - Print out the error message and exits. @param errPrintWriter The ostream to which error output should be written @param message Text for error message @return - None, Terminates the program @exception - This function terminates the program*/void OSInfoCommand::errorExit( ostream& errPrintWriter, const String& message){ errPrintWriter << "osinfo error: " << message << endl; exit(1);}/** formatCIMDateTime method takes a string with CIM formatted DateTime and returns a user-readable string of the format month day-of-month, year hour:minute:second (value-hrs-GMT-offset) */static void formatCIMDateTime (const char* cimString, char* dateTime){ int year = 0; int month = 0; int day = 0; int hour = 0; int minute = 0; int second = 0; int microsecond = 0; int timezone = 0; sscanf(cimString, "%04d%02d%02d%02d%02d%02d.%06d%04d", &year, &month, &day, &hour, &minute, &second, µsecond, &timezone); char monthString[5]; switch (month) { case 1 : { sprintf(monthString, "Jan"); break; } case 2 : { sprintf(monthString, "Feb"); break; } case 3 : { sprintf(monthString, "Mar"); break; } case 4 : { sprintf(monthString, "Apr"); break; } case 5 : { sprintf(monthString, "May"); break; } case 6 : { sprintf(monthString, "Jun"); break; } case 7 : { sprintf(monthString, "Jul"); break; } case 8 : { sprintf(monthString, "Aug"); break; } case 9 : { sprintf(monthString, "Sep"); break; } case 10 : { sprintf(monthString, "Oct"); break; } case 11 : { sprintf(monthString, "Nov"); break; } case 12 : { sprintf(monthString, "Dec"); break; } // covered all known cases, if get to default, just // return the input string as received. default : { strcpy(dateTime, cimString); return; } } sprintf(dateTime, "%s %d, %d %d:%02d:%02d (%03d%02d)", monthString, day, year, hour, minute, second, timezone/60, timezone%60); return;}/** gatherProperties method of the osinfo Test Client*/void OSInfoCommand::gatherProperties(CIMInstance &inst, Boolean cimFormat){ // don't have a try here - want it to be caught by caller // loop through the properties for (Uint32 j=0; j < inst.getPropertyCount(); j++) { CIMName propertyName = inst.getProperty(j).getName(); // only pull out those properties of interest
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -