(file) Return to CIMSubCommand.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Clients / cimsub

   1 martin 1.12 //%LICENSE////////////////////////////////////////////////////////////////
   2 martin 1.13 //
   3 martin 1.12 // Licensed to The Open Group (TOG) under one or more contributor license
   4             // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
   5             // this work for additional information regarding copyright ownership.
   6             // Each contributor licenses this file to you under the OpenPegasus Open
   7             // Source License; you may not use this file except in compliance with the
   8             // License.
   9 martin 1.13 //
  10 martin 1.12 // Permission is hereby granted, free of charge, to any person obtaining a
  11             // copy of this software and associated documentation files (the "Software"),
  12             // to deal in the Software without restriction, including without limitation
  13             // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  14             // and/or sell copies of the Software, and to permit persons to whom the
  15             // Software is furnished to do so, subject to the following conditions:
  16 martin 1.13 //
  17 martin 1.12 // The above copyright notice and this permission notice shall be included
  18             // in all copies or substantial portions of the Software.
  19 martin 1.13 //
  20 martin 1.12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  21 martin 1.13 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22 martin 1.12 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  23             // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  24             // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  25             // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  26             // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27 martin 1.13 //
  28 martin 1.12 //////////////////////////////////////////////////////////////////////////
  29 w.otsuka 1.1  //
  30               //%/////////////////////////////////////////////////////////////////////////////
  31               
  32               #include <iostream>
  33 ajay.rao 1.18 #include <fstream>
  34 w.otsuka 1.1  #include <Pegasus/Common/Config.h>
  35               #include <Pegasus/Common/Constants.h>
  36               #include <Pegasus/Common/System.h>
  37               #include <Pegasus/Client/CIMClient.h>
  38               #include <Pegasus/Common/Exception.h>
  39               #include <Pegasus/Common/PegasusVersion.h>
  40               #include <Pegasus/Common/AutoPtr.h>
  41 ajay.rao 1.16 #include <Pegasus/Common/HostAddress.h>
  42               #include <Pegasus/Common/CIMNameCast.h>
  43               #include <Pegasus/Common/StringConversion.h>
  44 w.otsuka 1.1  
  45 ajay.rao 1.18 
  46 thilo.boehm 1.9  #ifdef PEGASUS_OS_ZOS
  47 thilo.boehm 1.15 #include <Pegasus/General/SetFileDescriptorToEBCDICEncoding.h>
  48 thilo.boehm 1.9  #endif
  49                  
  50 ajay.rao    1.16 #ifdef PEGASUS_OS_PASE
  51                  #include <ILEWrapper/ILEUtilities.h>
  52                  #endif
  53                  
  54 w.otsuka    1.1  #include <Pegasus/getoopt/getoopt.h>
  55                  #include <Clients/cliutils/CommandException.h>
  56 ajay.rao    1.17 #include <Clients/cliutils/CsvStringParse.h>
  57 w.otsuka    1.1  #include "CIMSubCommand.h"
  58                  
  59                  PEGASUS_NAMESPACE_BEGIN
  60                  
  61                  
  62                  /**
  63                   * The CLI message resource name
  64                   */
  65                  
  66                  static const char MSG_PATH [] = "pegasus/pegasusCLI";
  67                  
  68                  /**
  69                      The command name.
  70                   */
  71                  const char COMMAND_NAME[] = "cimsub";
  72                  
  73                  /**
  74                     The default subscription namespace
  75                   */
  76                  static const CIMNamespaceName _DEFAULT_SUBSCRIPTION_NAMESPACE  =
  77                      PEGASUS_NAMESPACENAME_INTEROP;
  78 w.otsuka    1.1  
  79                  /**
  80 ajay.rao    1.18    The Description of the Command.
  81                   */
  82                  
  83                  static const char DESCRIPTION[] = "Cimsub Command Line \
  84                  Interface is used to manage CIM Indication Subscriptions.";
  85                  
  86                  /**
  87 w.otsuka    1.1      The usage string for this command.  This string is displayed
  88                      when an error occurs in parsing or validating the command line.
  89                   */
  90                  static const char USAGE[] = "Usage: ";
  91                  
  92                  /*
  93                      These constants represent the operation modes supported by the CLI.
  94                      Any new operation should be added here.
  95                   */
  96                  
  97                  /**
  98                      This constant signifies that an operation option has not been recorded
  99                   */
 100                  const Uint32 CIMSubCommand::OPERATION_TYPE_UNINITIALIZED = 0;
 101                  
 102                  /**
 103                      This constant represents a disable subscription operation
 104                   */
 105                  const Uint32 CIMSubCommand::OPERATION_TYPE_DISABLE = 1;
 106                  
 107                  /**
 108 w.otsuka    1.1      This constant represents a enable subscription operation
 109                   */
 110                  const Uint32 CIMSubCommand::OPERATION_TYPE_ENABLE = 2;
 111                  
 112                  /**
 113                      This constant represents a list operation
 114                   */
 115                  const Uint32 CIMSubCommand::OPERATION_TYPE_LIST = 3;
 116                  
 117                  /**
 118                      This constant represents a remove operation
 119                   */
 120                  const Uint32 CIMSubCommand::OPERATION_TYPE_REMOVE = 4;
 121                  
 122                  /**
 123                      This constant represents a help operation
 124                   */
 125                  const Uint32 CIMSubCommand::OPERATION_TYPE_HELP = 5;
 126                  
 127                  /**
 128                      This constant represents a verbose list operation
 129 w.otsuka    1.1   */
 130                  const Uint32 CIMSubCommand::OPERATION_TYPE_VERBOSE = 6;
 131                  
 132                  /**
 133                      This constant represents a version display operation
 134                   */
 135                  const Uint32 CIMSubCommand::OPERATION_TYPE_VERSION = 7;
 136                  
 137                  /**
 138 ajay.rao    1.16     This constant represents a create operation
 139                   */
 140                  const Uint32 CIMSubCommand::OPERATION_TYPE_CREATE= 8;
 141                  
 142                  /**
 143 ajay.rao    1.18     This constant represents a Batch file execution operation
 144                   */
 145                  
 146                  const Uint32 CIMSubCommand::OPERATION_TYPE_BATCH = 9;
 147                  
 148                  /**
 149 w.otsuka    1.1      The constants representing the messages.
 150                   */
 151                  
 152                  static const char CIMOM_NOT_RUNNING[] =
 153                      "The CIM server may not be running.";
 154                  
 155                  static const char CIMOM_NOT_RUNNING_KEY[] =
 156                      "Clients.cimsub.CIMSubCommand.CIMOM_NOT_RUNNING";
 157                  
 158                  static const char SUBSCRIPTION_NOT_FOUND_FAILURE[] =
 159                      "The requested subscription could not be found.";
 160                  
 161                  static const char SUBSCRIPTION_NOT_FOUND_KEY[] =
 162                      "Clients.cimsub.CIMSubCommand."
 163                          "SUBSCRIPTION_NOT_FOUND_FAILURE_KEY";
 164                  
 165                  static const char HANDLER_NOT_FOUND_FAILURE[] =
 166                      "The requested handler could not be found.";
 167                  
 168                  static const char HANDLER_NOT_FOUND_KEY[] =
 169                      "Clients.cimsub.CIMSubCommand."
 170 w.otsuka    1.1          "HANDLER_NOT_FOUND_FAILURE_KEY";
 171                  
 172                  static const char FILTER_NOT_FOUND_FAILURE[] =
 173                      "The requested filter could not be found.";
 174                  
 175                  static const char FILTER_NOT_FOUND_KEY[] =
 176                      "Clients.cimsub.CIMSubCommand."
 177                          "FILTER_NOT_FOUND_FAILURE_KEY";
 178                  
 179                  static const char SUBSCRIPTION_ALREADY_DISABLED[] =
 180                      "The subscription is already disabled.";
 181                  
 182                  static const char SUBSCRIPTION_ALREADY_DISABLED_KEY[] =
 183                      "Clients.cimsub.CIMSubCommand.SUBSCRIPTION_ALREADY_DISABLED";
 184                  
 185                  static const char SUBSCRIPTION_ALREADY_ENABLED[] =
 186                      "The subscription is already enabled.";
 187                  
 188                  static const char SUBSCRIPTION_ALREADY_ENABLED_KEY[] =
 189                      "Clients.cimsub.CIMSubCommand.SUBSCRIPTION_ALREADY_ENABLED";
 190                  
 191 w.otsuka    1.1  static const char REQUIRED_OPTION_MISSING[] =
 192                      "Required option missing.";
 193                  
 194                  static const char REQUIRED_OPTION_MISSING_KEY[] =
 195                      "Clients.cimsub.CIMSubCommand.REQUIRED_OPTION_MISSING";
 196                  
 197                  static const char ERR_USAGE_KEY[] =
 198                      "Clients.cimsub.CIMSubCommand.ERR_USAGE";
 199                  
 200                  static const char ERR_USAGE[] =
 201 runfang.zhou 1.8      "Use '--help' to obtain command syntax.";
 202 w.otsuka     1.1  
 203                   static const char LONG_HELP[] = "help";
 204                   
 205                   static const char LONG_VERSION[] = "version";
 206                   
 207                   /**
 208                       The option character used to specify disable a specified subscription
 209                    */
 210                   static const char OPTION_DISABLE = 'd';
 211                   
 212                   /**
 213                       The option character used to specify remove a specified subscription
 214                    */
 215                   static const char OPTION_REMOVE = 'r';
 216                   
 217                   /**
 218                       The option character used to specify the Filter Name of a subscription
 219                    */
 220                   static const char OPTION_FILTER = 'F';
 221                   
 222                   /**
 223 ajay.rao     1.16     The option character used to specify the Query of a Filter
 224                    */
 225                   static const char OPTION_QUERY = 'Q';
 226                   
 227                   /**
 228                       The option character used to specify the Query language of a Filter
 229                    */
 230                   static const char OPTION_QUERYLANGUAGE = 'L';
 231                   
 232                   
 233                   /**
 234                       The option character used to specify the Source Namespace of a Filter
 235                    */
 236                   static const char OPTION_SOURCENAMESPACE = 'N';
 237                   
 238                   
 239                   /**
 240 w.otsuka     1.1      The option character used to specify enable a specified subscription.
 241                    */
 242                   static const char OPTION_ENABLE = 'e';
 243                   
 244                   /**
 245                       The option character used to specify the Handler Name of a subscription
 246                    */
 247                   static const char OPTION_HANDLER = 'H';
 248                   
 249                   /**
 250 ajay.rao     1.16     The option character used to specify the Destination of a
 251                       CIM_IndicationHandlerCIMXML Handler
 252                    */
 253                   static const char OPTION_DESTINATION = 'D';
 254                   
 255                   /**
 256                       The option character used to specify the mailto of a
 257                       PG_ListenerDestinationEmail Handler
 258                    */
 259                   static const char OPTION_MAILTO = 'M';
 260                   
 261                   /**
 262                       The option character used to specify the mailcc of a
 263                       PG_ListenerDestinationEmail Handler
 264                    */
 265                   static const char OPTION_MAILCC = 'C';
 266                   
 267                   /**
 268                       The option character used to specify the mail subject of a
 269                       PG_ListenerDestinationEmail Handler
 270                    */
 271 ajay.rao     1.16 static const char OPTION_MAILSUBJECT = 'S';
 272                   
 273                   /**
 274                       The option character used to specify the snmp target host of a
 275                       PG_IndicationHandlerSNMPMapper Handler
 276                    */
 277                   static const char OPTION_SNMPTARGETHOST = 'T';
 278                   
 279                   /**
 280                       The option character used to specify the snmp port number of a
 281                       PG_IndicationHandlerSNMPMapper Handler
 282                    */
 283                   static const char OPTION_SNMPPORTNUMBER = 'P';
 284                   
 285                   /**
 286                       The option character used to specify the snmp version of a
 287                       PG_IndicationHandlerSNMPMapper Handler
 288                    */
 289                   static const char OPTION_SNMPVERSION = 'V';
 290                   
 291                   /**
 292 ajay.rao     1.16     The option character used to specify the snmp security name host of a
 293                       PG_IndicationHandlerSNMPMapper Handler
 294                    */
 295                   static const char OPTION_SNMPSECURITYNAME = 'U';
 296                   
 297                   /**
 298                       The option character used to specify the snmp engine id of a
 299                       PG_IndicationHandlerSNMPMapper Handler
 300                    */
 301                   static const char OPTION_SNMPENGINEID = 'E';
 302                   
 303                   /**
 304                       The option character used to specify creation
 305                    */
 306                   static const char OPTION_CREATE = 'c';
 307                   
 308                   /**
 309 w.otsuka     1.1      The option character used to specify listing
 310                    */
 311                   static const char OPTION_LIST = 'l';
 312                   
 313                   /**
 314 ajay.rao     1.18     The option charcter used to specify a file for batch file execution
 315                    */
 316                   
 317                   static const char OPTION_BATCH = 'b';
 318                   
 319                   /**
 320 w.otsuka     1.1      The option argument character used to specify subscriptions
 321                    */
 322                   static String ARG_SUBSCRIPTIONS = "s";
 323                   
 324                   /**
 325                       The option argument character used to specify filters
 326                    */
 327                   static String ARG_FILTERS = "f";
 328                   
 329                   /**
 330                       The option argument character used to specify handlers
 331                    */
 332                   static String ARG_HANDLERS = "h";
 333                   
 334                   /**
 335                       The option argument character used to specify handlers, filters,
 336                       and subscriptions
 337                    */
 338                   static String ARG_ALL = "a";
 339                   
 340                   /**
 341 w.otsuka     1.1      The option character used to specify namespace of subscription
 342                    */
 343                   static const char OPTION_NAMESPACE = 'n';
 344                   
 345                   /**
 346                       The option character used to display verbose info.
 347                    */
 348                   static const char OPTION_VERBOSE = 'v';
 349                   
 350                   static const char DELIMITER_NAMESPACE = ':';
 351                   static const char DELIMITER_HANDLER_CLASS = '.';
 352                   
 353                   /**
 354                       List output header values
 355                    */
 356                   
 357                   const Uint32 TITLE_SEPERATOR_LEN = 2;
 358                   
 359                   static const Uint32 RC_CONNECTION_FAILED = 2;
 360                   static const Uint32 RC_CONNECTION_TIMEOUT = 3;
 361                   static const Uint32 RC_ACCESS_DENIED = 4;
 362 w.otsuka     1.1  static const Uint32 RC_NAMESPACE_NONEXISTENT = 5;
 363                   static const Uint32 RC_OBJECT_NOT_FOUND = 6;
 364                   static const Uint32 RC_OPERATION_NOT_SUPPORTED = 7;
 365                   
 366                   //
 367                   // List column header constants
 368                   //
 369                   const Uint32 _HANDLER_LIST_NAME_COLUMN = 0;
 370                   const Uint32 _HANDLER_LIST_DESTINATION_COLUMN = 1;
 371                   const Uint32 _FILTER_LIST_NAME_COLUMN = 0;
 372                   const Uint32 _FILTER_LIST_QUERY_COLUMN = 1;
 373                   const Uint32 _FILTER_LIST_QUERYLANGUAGE_COLUMN = 2;
 374                   const Uint32 _SUBSCRIPTION_LIST_NS_COLUMN = 0;
 375                   const Uint32 _SUBSCRIPTION_LIST_FILTER_COLUMN = 1;
 376                   const Uint32 _SUBSCRIPTION_LIST_HANDLER_COLUMN = 2;
 377                   const Uint32 _SUBSCRIPTION_LIST_STATE_COLUMN = 3;
 378                   //
 379                   // Handler persistence display values
 380                   //
 381                   const String _PERSISTENTENCE_OTHER_STRING = "Other";
 382                   const String _PERSISTENTENCE_PERMANENT_STRING = "Permanent";
 383 w.otsuka     1.1  const String _PERSISTENTENCE_TRANSIENT_STRING = "Transient";
 384                   const String _PERSISTENTENCE_UNKNOWN_STRING = "Unknown";
 385                   
 386                   //
 387                   // Subscription state display values
 388                   //
 389                   const String _SUBSCRIPTION_STATE_UNKNOWN_STRING = "Unknown";
 390                   const String _SUBSCRIPTION_STATE_OTHER_STRING = "Other";
 391                   const String _SUBSCRIPTION_STATE_ENABLED_STRING = "Enabled";
 392                   const String _SUBSCRIPTION_STATE_ENABLED_DEGRADED_STRING = "Enabled Degraded";
 393                   const String _SUBSCRIPTION_STATE_DISABLED_STRING = "Disabled";
 394                   const String _SUBSCRIPTION_STATE_NOT_SUPPORTED_STRING = "Not Supported";
 395                   //
 396                   // SNMP version display values
 397                   //
 398                   const String _SNMP_VERSION_SNMPV1_TRAP_STRING = "SNMPv1 Trap";
 399                   const String _SNMP_VERSION_SNMPV2C_TRAP_STRING = "SNMPv2C Trap";
 400                   const String _SNMP_VERSION_PEGASUS_RESERVED_STRING = "Pegasus Reserved";
 401 ajay.rao     1.16 
 402 w.otsuka     1.1  /**
 403                   
 404                       Constructs a CIMSubCommand and initializes instance variables.
 405                    */
 406                   CIMSubCommand::CIMSubCommand()
 407                   {
 408                       /**
 409                           Initialize the instance variables.
 410                       */
 411                       _operationType = OPERATION_TYPE_UNINITIALIZED;
 412                       _verbose = false;
 413 ajay.rao     1.16     _handlerSNMPPortNumber = 162;
 414                       _filterQueryLanguage = "CIM:CQL";
 415 ajay.rao     1.18     _isBatchNamespace = false;
 416 ajay.rao     1.19     _filterNSFlag =false;
 417 w.otsuka     1.1      /**
 418                           Build the usage string for the config command.
 419                       */
 420                   
 421                       usage.reserveCapacity(200);
 422 ajay.rao     1.18     usage.append(DESCRIPTION);
 423                       usage.append("\n\n");
 424 w.otsuka     1.1      usage.append(USAGE);
 425 ajay.rao     1.16     /*
 426                           cimsub -cf [fnamespace:]filtername  -Q query
 427                                    [-L querylanuage] [-N sourcenamespace]
 428                       */
 429                       usage.append(COMMAND_NAME);
 430                       usage.append(" -").append(OPTION_CREATE);
 431                       usage.append(" ").append(ARG_FILTERS);
 432                       usage.append(" [fnamespace:]filtername");
 433                       usage.append(" -").append(OPTION_QUERY).append(" query");
 434                       usage.append(" [-").append(OPTION_QUERYLANGUAGE);
 435                       usage.append(" querylanguage]\n");
 436                       usage.append("                  [-").append(OPTION_SOURCENAMESPACE);
 437                       usage.append(" sourcenamespace(s)] \n");
 438                       /*
 439                           cimsub -ch [hnamespace:][hclassname.]handlername [-D destination ]|
 440                                     [-T mailto [-C mailcc] -S mailsubject] |
 441                                     [-T snmptargethost [-P snmpportnumber] -V snmpversion
 442                                         [-S snmpsecurityname] [-E snmpengineid]]
 443                       */
 444                       usage.append("       ");
 445                       usage.append(COMMAND_NAME);
 446 ajay.rao     1.16     usage.append(" -").append(OPTION_CREATE);
 447                       usage.append(" ").append(ARG_HANDLERS);
 448                       usage.append(" [hnamespace:][hclassname.]handlername");
 449                       usage.append(" [-").append(OPTION_DESTINATION);
 450                       usage.append(" destination]| \n");
 451                       usage.append("                  [-").append(OPTION_MAILTO);
 452                       usage.append(" mailto");
 453                       usage.append(" [-").append(OPTION_MAILCC).append(" mailcc]");
 454                       usage.append(" -").append(OPTION_MAILSUBJECT).append(" mailsubject]| \n");
 455                       usage.append("                  [-").append(OPTION_SNMPTARGETHOST);
 456                       usage.append(" snmptargethost");
 457                       usage.append(" [-").append(OPTION_SNMPPORTNUMBER);
 458                       usage.append(" snmpportnumber]");
 459                       usage.append(" -").append(OPTION_SNMPVERSION).append(" snmpversion] \n");
 460                       usage.append("                      [-").append(OPTION_SNMPSECURITYNAME);
 461                       usage.append(" snmpsecurityname]");
 462                       usage.append(" [-").append(OPTION_SNMPENGINEID);
 463                       usage.append(" snmpengineid]] \n");
 464                   
 465                       /*
 466                           cimsub -cs [-n namespace] -F [fnamespace:]filtername
 467 ajay.rao     1.16                   -H [hnamespace:][hclassname.]handlername
 468                       */
 469                   
 470                       usage.append("       ");
 471                       usage.append(COMMAND_NAME);
 472                       usage.append(" -").append(OPTION_CREATE);
 473                       usage.append(" ").append(ARG_SUBSCRIPTIONS);
 474                       usage.append(" [-").append(OPTION_NAMESPACE).append(" namespace]");
 475                       usage.append(" -").append(OPTION_FILTER).append
 476                           (" [fnamespace:]filtername \n");
 477                       usage.append("                  -").append(OPTION_HANDLER).append
 478                           (" [hnamespace:][hclassname.]handlername \n");
 479                       usage.append("       ");
 480 w.otsuka     1.1      usage.append(COMMAND_NAME);
 481                       usage.append(" -").append(OPTION_LIST);
 482                       usage.append(" ").append(ARG_SUBSCRIPTIONS).append("|");
 483                       usage.append(ARG_FILTERS).append("|");
 484                       usage.append(ARG_HANDLERS);
 485                       usage.append(" [-").append(OPTION_VERBOSE).append("]");
 486                       usage.append(" [-").append(OPTION_NAMESPACE).append(" namespace]");
 487                       usage.append(" [-").append(OPTION_FILTER).append
 488                           (" [fnamespace:]filtername] \n");
 489                       usage.append("                  [-").append(OPTION_HANDLER).append
 490                           (" [hnamespace:][hclassname.]handlername] \n");
 491                   
 492 ajay.rao     1.16     usage.append("       ");
 493                       usage.append(COMMAND_NAME);
 494                       usage.append(" -").append(OPTION_ENABLE);
 495 w.otsuka     1.1      usage.append(" [-").append(OPTION_NAMESPACE).append(" namespace]");
 496                       usage.append(" -").append(OPTION_FILTER).append
 497                           (" [fnamespace:]filtername \n");
 498                       usage.append("                  -").append(OPTION_HANDLER).append
 499                           (" [hnamespace:][hclassname.]handlername \n");
 500                   
 501 ajay.rao     1.16     usage.append("       ");
 502                       usage.append(COMMAND_NAME);
 503                       usage.append(" -").append(OPTION_DISABLE);
 504 w.otsuka     1.1      usage.append(" [-").append(OPTION_NAMESPACE).append(" namespace]");
 505                       usage.append(" -").append(OPTION_FILTER).append
 506 w.otsuka     1.3          (" [fnamespace:]filtername\n");
 507 w.otsuka     1.1      usage.append("                  -").append(OPTION_HANDLER).append
 508                           (" [hnamespace:][hclassname.]handlername \n");
 509                   
 510 ajay.rao     1.16     usage.append("       ");
 511                       usage.append(COMMAND_NAME);
 512                       usage.append(" -").append(OPTION_REMOVE);
 513 w.otsuka     1.1      usage.append(" ").append (ARG_SUBSCRIPTIONS).append("|");
 514                       usage.append(ARG_FILTERS).append("|");
 515                       usage.append(ARG_HANDLERS).append("|");
 516                       usage.append(ARG_ALL);
 517                       usage.append(" [-").append(OPTION_NAMESPACE).append(" namespace]");
 518                       usage.append(" [-").append(OPTION_FILTER).append
 519 ajay.rao     1.16         (" [fnamespace:]filtername] \n");
 520 w.otsuka     1.3      usage.append("                  [-").append(OPTION_HANDLER).append
 521 w.otsuka     1.1          (" [hnamespace:][hclassname.]handlername]\n");
 522 ajay.rao     1.18     usage.append("       ");
 523                       usage.append(COMMAND_NAME);
 524                       usage.append(" -").append(OPTION_BATCH);
 525                       usage.append(" ").append("batchfile");
 526                       usage.append(" [-").append(OPTION_NAMESPACE).append(" namespace]\n");
 527 ajay.rao     1.16     usage.append("       ");
 528                       usage.append(COMMAND_NAME);
 529                       usage.append(" --").append(LONG_HELP).append("\n");
 530                   
 531                       usage.append("       ");
 532                       usage.append(COMMAND_NAME);
 533                       usage.append(" --").append(LONG_VERSION).append("\n");
 534 w.otsuka     1.1  
 535                       usage.append("Options : \n");
 536 ajay.rao     1.16     usage.append("    -c         - Create specified subscription, filter, \n"
 537                                    "                   handler(CIM_ListenerDestinationCIMXML, \n"
 538 ajay.rao     1.18                  "                       if hclassname is not specified)\n");
 539 w.otsuka     1.1      usage.append("    -l         - List and display information\n");
 540                       usage.append("    -e         - Enable specified subscription\n");
 541                       usage.append("                   (set SubscriptionState to Enabled) \n");
 542                       usage.append("    -d         - Disable specified subscription \n");
 543                       usage.append("                   (set SubscriptionState to Disabled) \n");
 544 karl         1.7      usage.append("    -r         - Remove specified subscription, handler,"
 545                                                   " filter \n");
 546 ajay.rao     1.18     usage.append("    -b filename\n");
 547                       usage.append("               - Execute cimsub batch file. Filename is path"
 548                                                        " to the batch file \n");
 549 w.otsuka     1.1      usage.append("    -v         - Include verbose information \n");
 550 karl         1.7      usage.append("    -F         - Specify Filter Name of subscription for"
 551                                                   " the operation\n");
 552 ajay.rao     1.16     usage.append("    -Q         - Specify Query Expression of a Filter \n");
 553                       usage.append("    -L         - Specify Query Language of a Filter \n");
 554 ajay.rao     1.18     usage.append("    -N         - To Use SourceNamespaces property,Specify");
 555                       usage.append(" multiple SourceNamespaces\n");
 556                       usage.append("                 with coma separated or append comma to");
 557                       usage.append(" the single SourceNamespace.\n");
 558 ajay.rao     1.16     usage.append("                 By default SourceNamespace property is ");
 559 ajay.rao     1.18     usage.append(" populated if the single\n");
 560                       usage.append("                 SourceNamespace is specified.\n");
 561 karl         1.7      usage.append("    -H         - Specify Handler Name of subscription for"
 562                                                   " the operation\n");
 563 ajay.rao     1.16     usage.append("    -D         - Specify Destination of a "
 564                                    "CIM_IndicationHandlerCIMXML Handler.\n"
 565                                    "                   Required option for "
 566                                    "CIM_IndicationHandlerCIMXML or \n"
 567                                    "                   CIM_ListenerDestinationCIMXML Handler\n");
 568                       usage.append("    -M         - Specify Mailto of a "
 569                                    " PG_ListenerDestinationEmail Handler\n");
 570                       usage.append("    -C         - Specify Mailcc of a "
 571                                    "PG_ListenerDestinationEmail Handler\n");
 572                       usage.append("    -S         - Specify Subject of a "
 573                                    "PG_ListenerDestinationEmail Handler\n");
 574                       usage.append("    -T         - Specify Target Host of "
 575 ajay.rao     1.18                  "PG_IndicationHandlerSNMPMapper Handler.\n"
 576                                    "                 Required option for SNMPMapper handler\n");
 577 ajay.rao     1.16     usage.append("    -U         - Specify Security Name of "
 578                                    "PG_IndicationHandlerSNMPMapper Handler\n");
 579                       usage.append("    -P         - Specify Port Number of a "
 580                                    "PG_IndicationHandlerSNMPMapper Handler\n"
 581                                    "                   (default 162) \n");
 582                       usage.append("    -V         - Specify SNMPVersion of a "
 583                                    "PG_IndicationHandlerSNMPMapper Handler\n"
 584                                    "                   2 : SNMPv1 Trap\n"
 585                                    "                   3 : SNMPv2C Trap\n"
 586                                    "                   4 : SNMPv2C Inform\n"
 587                                    "                   5 : SNMPv3 Trap\n"
 588                                    "                   6 : SNMPv3 Inform\n"
 589                                    "                   Required option for SNMPMapper Handler");
 590                       usage.append("\n");
 591                       usage.append("    -E         - Specify Engine ID of a "
 592                                    "PG_IndicationHandlerSNMPMapper Handler\n");
 593 w.otsuka     1.1      usage.append("    -n         - Specify namespace of subscription\n");
 594 ajay.rao     1.18     usage.append("                   (interop namespace, if not specified)\n");
 595 w.otsuka     1.1      usage.append("    --help     - Display this help message\n");
 596                       usage.append("    --version  - Display CIM Server version\n");
 597 thilo.boehm  1.6      usage.append("\n");
 598 karl         1.7      usage.append("Usage note: The cimsub command requires that the CIM Server"
 599                                                   " is running.\n");
 600 thilo.boehm  1.6      usage.append("\n");
 601 ajay.rao     1.18     usage.append("Batch File Format\n");
 602                       usage.append("-----------------\n\n");
 603                       usage.append("A cimsub batch file contains multiple cimsub ");
 604                       usage.append("commands, one per line.");
 605                       usage.append("Lines\nthat start with the '#' character and blank lines");
 606                       usage.append(" are ignored.The Execution\n");
 607                       usage.append("of Batch file will stop when it encounters any syntax error");
 608                       usage.append(" or an exception\nin the command.\n\n");
 609                       usage.append("The namespace option (-n) when used with batch execution");
 610                       usage.append(" (-b) uses the\n");
 611                       usage.append("namespace to populate the namespace values of filter, ");
 612                       usage.append("handler and\nsubscription. Any namespace specified for ");
 613                       usage.append("any or all of these is specified\ninside the batch");
 614                       usage.append("command, they will be overridden.\n");
 615 w.otsuka     1.1  
 616                   #ifdef PEGASUS_HAS_ICU
 617 karl         1.7      MessageLoaderParms menuparms(
 618 ajay.rao     1.16             "Clients.cimsub.CIMSubCommand.MENU.STANDARD",
 619                               usage);
 620 w.otsuka     1.1      menuparms.msg_src_path = MSG_PATH;
 621                       usage = MessageLoader::getMessage(menuparms);
 622                   #endif
 623                   
 624                       setUsage(usage);
 625                   }
 626                   
 627                   
 628                   
 629                   /**
 630                       Parses the command line, validates the options, and sets instance
 631                       variables based on the option arguments.
 632                   */
 633                   void CIMSubCommand::setCommand(
 634                       ostream& outPrintWriter,
 635                       ostream& errPrintWriter,
 636                       Uint32 argc,
 637                       char* argv[])
 638                   {
 639                       Uint32 i = 0;
 640 ajay.rao     1.16     Uint64 c = 0;
 641                       //char c;
 642 w.otsuka     1.1      String badOptionString;
 643                       String optString;
 644                       String filterNameString;
 645                       String handlerNameString;
 646                       Boolean filterSet = false;
 647                       Boolean handlerSet = false;
 648 ajay.rao     1.16     Boolean filterQuerySet = false;
 649                       Boolean filterQueryLanguageSet = false;
 650                       Boolean filterSourceNamespaceSet = false;
 651                       Boolean handlerDestinationSet = false;
 652                       Boolean handlerMailToSet = false;
 653                       Boolean handlerMailCcSet = false;
 654                       Boolean handlerMailSubjectSet = false;
 655                       Boolean handlerSnmpTargetHostSet = false;
 656                       Boolean handlerSnmpPortNumberSet = false;
 657                       Boolean handlerSnmpVersionSet = false;
 658                       Boolean handlerSnmpSecurityNameSet = false;
 659                       Boolean handlerSnmpEngineIdSet = false;
 660 w.otsuka     1.1  
 661                       //
 662                       //  Construct optString
 663                       //
 664 ajay.rao     1.16     optString.append(OPTION_CREATE);
 665                       optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 666 w.otsuka     1.1      optString.append(OPTION_LIST);
 667                       optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 668                       optString.append(OPTION_DISABLE);
 669                       optString.append(OPTION_ENABLE);
 670                       optString.append(OPTION_REMOVE);
 671                       optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 672                       optString.append(OPTION_VERBOSE);
 673                       optString.append(OPTION_FILTER);
 674                       optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 675                       optString.append(OPTION_HANDLER);
 676                       optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 677                       optString.append(OPTION_NAMESPACE);
 678                       optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 679 ajay.rao     1.16     optString.append(OPTION_QUERY);
 680                       optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 681                       optString.append(OPTION_QUERYLANGUAGE);
 682                       optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 683                       optString.append(OPTION_SOURCENAMESPACE);
 684                       optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 685                       optString.append(OPTION_DESTINATION);
 686                       optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 687                       optString.append(OPTION_MAILTO); //OPTION_MAILTO & OPTION_SNMPTARGETHOST
 688                       optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 689                       optString.append(OPTION_MAILCC);
 690                       optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 691                       optString.append(OPTION_MAILSUBJECT);
 692                                 //OPTION_MAILSUBJECT & OPTION_SNMPSECURITYNAME
 693                       optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 694                       optString.append(OPTION_SNMPTARGETHOST);
 695                       optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 696                       optString.append(OPTION_SNMPSECURITYNAME);
 697                       optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 698                       optString.append(OPTION_SNMPPORTNUMBER);
 699                       optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 700 ajay.rao     1.16     optString.append(OPTION_SNMPVERSION);
 701                       optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 702                       optString.append(OPTION_SNMPENGINEID);
 703                       optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 704 ajay.rao     1.18     optString.append(OPTION_BATCH);
 705                       optString.append(getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 706 w.otsuka     1.1      //
 707                       //  Initialize and parse options
 708                       //
 709                       getoopt options("");
 710                       options.addFlagspec(optString);
 711                   
 712                       options.addLongFlagspec(LONG_HELP,getoopt::NOARG);
 713                       options.addLongFlagspec(LONG_VERSION,getoopt::NOARG);
 714                   
 715                       options.parse(argc, argv);
 716                   
 717                       if (options.hasErrors())
 718                       {
 719                           throw CommandFormatException(options.getErrorStrings()[0]);
 720                       }
 721                       _operationType = OPERATION_TYPE_UNINITIALIZED;
 722                   
 723                   
 724                       //
 725                       //  Get options and arguments from the command line
 726                       //
 727 w.otsuka     1.1      for (i = options.first(); i <  options.last(); i++)
 728                       {
 729                           if (options[i].getType () == Optarg::LONGFLAG)
 730                           {
 731                               if (options[i].getopt() == LONG_HELP)
 732                               {
 733                                   if (_operationType != OPERATION_TYPE_UNINITIALIZED)
 734                                   {
 735                                       //
 736                                       // More than one operation option was found
 737                                       //
 738                                       throw UnexpectedOptionException(LONG_HELP);
 739                                   }
 740                   
 741                                  _operationType = OPERATION_TYPE_HELP;
 742                               }
 743                               else if (options[i].getopt() == LONG_VERSION)
 744                               {
 745                                   if (_operationType != OPERATION_TYPE_UNINITIALIZED)
 746                                   {
 747                                       //
 748 w.otsuka     1.1                      // More than one operation option was found
 749                                       //
 750                                       throw UnexpectedOptionException(LONG_VERSION);
 751                                   }
 752                   
 753                                   _operationType = OPERATION_TYPE_VERSION;
 754                               }
 755                           }
 756                           else if (options [i].getType() == Optarg::REGULAR)
 757                           {
 758 ajay.rao     1.16             if (options.isSet(OPTION_CREATE))
 759                               {
 760                                   if(ARG_FILTERS == _operationArg)
 761                                   {
 762                                       if(filterSet)
 763                                       {
 764                                           throw UnexpectedArgumentException(options[i].Value());
 765                                       }
 766                                       filterNameString = options[i].Value();
 767                                       filterSet = true;
 768                                   }
 769                                   else if(ARG_HANDLERS == _operationArg)
 770                                   {
 771                                       if(handlerSet)
 772                                       {
 773                                           throw UnexpectedArgumentException(options[i].Value());
 774                                       }
 775                                       handlerNameString = options[i].Value();
 776                                       handlerSet = true;
 777                                   }
 778                                   else
 779 ajay.rao     1.16                 {
 780                                       //
 781                                       //  The cimsub command has no non-option argument
 782                                       //  options except "c"
 783                                       //
 784                                       throw UnexpectedArgumentException(options[i].Value());
 785                                   }
 786                               }
 787                               else
 788                               {
 789                                   //
 790                                   //  The cimsub command has no non-option argument
 791                                   //  options except "c"
 792                                   //
 793                                   throw UnexpectedArgumentException(options[i].Value());
 794                               }
 795 w.otsuka     1.1          }
 796                           else
 797                           {
 798                   
 799                               c = options[i].getopt()[0];
 800                   
 801                               switch (c)
 802                               {
 803                                   case OPTION_DISABLE:
 804                                   {
 805                                       if (_operationType != OPERATION_TYPE_UNINITIALIZED)
 806                                       {
 807                                           //
 808                                           // More than one operation option was found
 809                                           //
 810                                           throw UnexpectedOptionException(OPTION_DISABLE);
 811                                       }
 812                   
 813                                       if (options.isSet(OPTION_DISABLE) > 1)
 814                                       {
 815                                           //
 816 w.otsuka     1.1                          // More than one disable subscription option was found
 817                                           //
 818                                           throw DuplicateOptionException(OPTION_DISABLE);
 819                                       }
 820                   
 821                                       _operationType = OPERATION_TYPE_DISABLE;
 822                   
 823                                       break;
 824                                   }
 825                   
 826                                   case OPTION_ENABLE:
 827                                   {
 828                                       if (_operationType != OPERATION_TYPE_UNINITIALIZED)
 829                                       {
 830                                           //
 831                                           // More than one operation option was found
 832                                           //
 833                                           throw UnexpectedOptionException (OPTION_ENABLE);
 834                                       }
 835                   
 836                                       if (options.isSet(OPTION_ENABLE) > 1)
 837 w.otsuka     1.1                      {
 838                                           //
 839                                           // More than one enable option was found
 840                                           //
 841                                           throw DuplicateOptionException (OPTION_ENABLE);
 842                                       }
 843                   
 844                                       _operationType = OPERATION_TYPE_ENABLE;
 845                   
 846                                       break;
 847                                   }
 848                   
 849                                   case OPTION_LIST:
 850                                   {
 851                                       if (_operationType != OPERATION_TYPE_UNINITIALIZED)
 852                                       {
 853                                           //
 854                                           // More than one operation option was found
 855                                           //
 856                                           throw UnexpectedOptionException(OPTION_LIST);
 857                                       }
 858 w.otsuka     1.1  
 859                                       if (options.isSet(OPTION_LIST) > 1)
 860                                       {
 861                                           //
 862                                           // More than one list option was found
 863                                           //
 864                                           throw DuplicateOptionException (OPTION_LIST);
 865                                       }
 866                                       _operationType = OPERATION_TYPE_LIST;
 867                                       _operationArg = options[i].Value();
 868                                       break;
 869                                   }
 870                   
 871 ajay.rao     1.16                 case OPTION_CREATE:
 872                                   {
 873                                       if (_operationType != OPERATION_TYPE_UNINITIALIZED)
 874                                       {
 875                                           //
 876                                           // More than one operation option was found
 877                                           //
 878                                           throw UnexpectedOptionException(OPTION_LIST);
 879                                       }
 880                   
 881                                       if (options.isSet(OPTION_CREATE) > 1)
 882                                       {
 883                                           //
 884                                           // More than two create option was found
 885                                           //
 886                                           throw DuplicateOptionException (OPTION_CREATE);
 887                                       }
 888                                       _operationType = OPERATION_TYPE_CREATE;
 889                                       _operationArg = options[i].Value();
 890                                       break;
 891                                   }
 892 ajay.rao     1.16 
 893 w.otsuka     1.1                  case OPTION_REMOVE:
 894                                   {
 895                                       if (_operationType != OPERATION_TYPE_UNINITIALIZED)
 896                                       {
 897                                           //
 898                                           // More than one operation option was found
 899                                           //
 900                                           throw UnexpectedOptionException(OPTION_REMOVE);
 901                                       }
 902                                       if (options.isSet(OPTION_REMOVE) > 1)
 903                                       {
 904                                           //
 905                                           // More than one remove option was found
 906                                           //
 907                                           throw DuplicateOptionException(OPTION_REMOVE);
 908                                       }
 909                                       _operationType = OPERATION_TYPE_REMOVE;
 910                                       _operationArg = options[i].Value();
 911                                       break;
 912                                   }
 913                   
 914 w.otsuka     1.1                  case OPTION_VERBOSE:
 915                                   {
 916 ajay.rao     1.16                    if (_operationType != OPERATION_TYPE_LIST)
 917 w.otsuka     1.1                      {
 918                                           //
 919                                           // Unexpected verbose option was found
 920                                           //
 921                                           throw UnexpectedOptionException(OPTION_VERBOSE);
 922                                       }
 923                                       if (options.isSet(OPTION_VERBOSE) > 1)
 924                                       {
 925                                           //
 926                                           // More than one verbose option was found
 927                                           //
 928                                           throw DuplicateOptionException(OPTION_VERBOSE);
 929                                       }
 930                   
 931                                       _verbose = true;
 932                   
 933                                       break;
 934                                   }
 935                   
 936                                   case OPTION_FILTER:
 937                                   {
 938 w.otsuka     1.1                      if ((_operationType == OPERATION_TYPE_HELP) ||
 939 ajay.rao     1.16                         (_operationType == OPERATION_TYPE_VERSION) ||
 940                                           (_operationType == OPERATION_TYPE_CREATE
 941                                               && ARG_SUBSCRIPTIONS!= _operationArg))
 942 w.otsuka     1.1                      {
 943                                           //
 944                                           // Help and version take no options.
 945                                           //
 946                                           throw UnexpectedOptionException(OPTION_FILTER);
 947                                       }
 948                                       if (options.isSet(OPTION_FILTER) > 1)
 949                                       {
 950                                           //
 951                                           // More than one filter option was found
 952                                           //
 953                                           throw DuplicateOptionException(OPTION_FILTER);
 954                                       }
 955                                       filterNameString = options[i].Value();
 956                                       filterSet = true;
 957                                       break;
 958                                   }
 959                   
 960                                   case OPTION_HANDLER:
 961                                   {
 962                                       if ((_operationType == OPERATION_TYPE_HELP) ||
 963 ajay.rao     1.16                         (_operationType == OPERATION_TYPE_VERSION) ||
 964                                           (_operationType == OPERATION_TYPE_CREATE
 965                                               && ARG_SUBSCRIPTIONS!= _operationArg))
 966 w.otsuka     1.1                      {
 967                                           //
 968                                           // Help and version take no options.
 969                                           //
 970                                           throw UnexpectedOptionException(OPTION_HANDLER);
 971                                       }
 972                                       if (options.isSet(OPTION_HANDLER) > 1)
 973                                       {
 974                                           //
 975                                           // More than one handler option was found
 976                                           //
 977                                           throw DuplicateOptionException(OPTION_HANDLER);
 978                                       }
 979                   
 980                                       handlerNameString = options[i].Value();
 981                                       handlerSet = true;
 982                                       break;
 983                                   }
 984                   
 985                                   case OPTION_NAMESPACE:
 986                                   {
 987 w.otsuka     1.1                      if ((_operationType == OPERATION_TYPE_HELP) ||
 988 ajay.rao     1.16                         (_operationType == OPERATION_TYPE_VERSION) ||
 989                                           (_operationType == OPERATION_TYPE_CREATE
 990                                               && ARG_SUBSCRIPTIONS!= _operationArg))
 991 w.otsuka     1.1                      {
 992                                           //
 993                                           // Help and version take no options.
 994                                           //
 995                                           throw UnexpectedOptionException(OPTION_NAMESPACE);
 996                                       }
 997                                       if (options.isSet(OPTION_NAMESPACE) > 1)
 998                                       {
 999                                           //
1000                                           // More than one namespace option was found
1001                                           //
1002                                           throw DuplicateOptionException(OPTION_NAMESPACE);
1003                                       }
1004                   
1005 ajay.rao     1.18                     if (_operationType == OPERATION_TYPE_BATCH )
1006                                       {
1007                                           _batchNamespace = options[i].Value();
1008                                           _isBatchNamespace = true;
1009                                       }
1010                                       else
1011                                       {
1012                                           String nsNameValue = options[i].Value();
1013                                           _subscriptionNamespace = nsNameValue;
1014                                       }
1015 w.otsuka     1.1                      break;
1016                                   }
1017 ajay.rao     1.18                 case OPTION_BATCH:
1018                                   {
1019                                      if (_operationType != OPERATION_TYPE_UNINITIALIZED)
1020                                       {
1021                                           // More than one operation option was found
1022                                           throw UnexpectedOptionException(OPTION_BATCH);
1023                                       }
1024                                       if (options.isSet(OPTION_BATCH) > 1)
1025                                       {
1026                                           throw DuplicateOptionException(OPTION_BATCH);
1027                                       }
1028                                       _operationType = OPERATION_TYPE_BATCH;
1029                                       _batchFileName = options[i].Value();
1030                                       break;
1031                                    }
1032 ajay.rao     1.16                 case OPTION_QUERY:
1033                                   {
1034                                       if (_operationType != OPERATION_TYPE_CREATE
1035                                           || ARG_FILTERS != _operationArg)
1036                                       {
1037                                           //
1038                                           // Help and version take no options.
1039                                           //
1040                                           throw UnexpectedOptionException(OPTION_QUERY);
1041                                       }
1042                                       if (options.isSet(OPTION_QUERY) > 1)
1043                                       {
1044                                           //
1045                                           // More than one query option was found
1046                                           //
1047                                           throw DuplicateOptionException(OPTION_QUERY);
1048                                       }
1049                   
1050                                       String filterQueryValue = options[i].Value();
1051                                       _filterQuery = filterQueryValue;
1052                   
1053 ajay.rao     1.16                     filterQuerySet = true;
1054                                       break;
1055 w.otsuka     1.1                  }
1056 ajay.rao     1.16                 case OPTION_QUERYLANGUAGE:
1057                                   {
1058                                       if (_operationType != OPERATION_TYPE_CREATE
1059                                           || ARG_FILTERS != _operationArg)
1060                                       {
1061                                           //
1062                                           // Help and version take no options.
1063                                           //
1064                                           throw UnexpectedOptionException(OPTION_QUERYLANGUAGE);
1065                                       }
1066                                       if (options.isSet(OPTION_QUERYLANGUAGE) > 1)
1067                                       {
1068                                           //
1069                                           // More than one query language option was found
1070                                           //
1071                                           throw DuplicateOptionException(OPTION_QUERYLANGUAGE);
1072                                       }
1073 w.otsuka     1.1  
1074 ajay.rao     1.16                     String filterQueryLanguageValue = options[i].Value();
1075                                       _filterQueryLanguage = filterQueryLanguageValue;
1076 w.otsuka     1.1  
1077 ajay.rao     1.16                     filterQueryLanguageSet = true;
1078                                       break;
1079                                   }
1080                                   case OPTION_SOURCENAMESPACE:
1081                                   {
1082                                       if (_operationType != OPERATION_TYPE_CREATE
1083                                           || ARG_FILTERS != _operationArg)
1084                                       {
1085                                           //
1086                                           // Help and version take no options.
1087                                           //
1088                                           throw UnexpectedOptionException(OPTION_SOURCENAMESPACE);
1089                                       }
1090                                       if (options.isSet(OPTION_SOURCENAMESPACE) > 1)
1091                                       {
1092                                           //
1093                                           // More than one query language option was found
1094                                           //
1095                                           throw DuplicateOptionException(OPTION_SOURCENAMESPACE);
1096                                       }
1097 ajay.rao     1.18                     _filterNSFlag = false;
1098 ajay.rao     1.16                     String filterSourceNamespaceValue = options[i].Value();
1099                                       String filterNS = filterSourceNamespaceValue;
1100                                       Boolean sourceNamespacesProperty = false;
1101                                       csvStringParse strSNS (filterNS, ',');
1102                                       while (strSNS.more())
1103                                       {
1104                                           _filterSourceNamespaces.append(strSNS.next());
1105                                       }
1106                                       if ( _filterSourceNamespaces.size() > 1 ||
1107                                             filterNS[filterNS.size()-1] == ',')
1108                                       {
1109                                            sourceNamespacesProperty = true;
1110                                       }
1111                                       _filterNSFlag = sourceNamespacesProperty;
1112                                       filterSourceNamespaceSet = true;
1113                                       break;
1114                                   }
1115                                   case OPTION_DESTINATION:
1116                                   {
1117                                       if (_operationType != OPERATION_TYPE_CREATE
1118                                           || ARG_HANDLERS != _operationArg)
1119 ajay.rao     1.16                     {
1120                                           //
1121                                           // Help and version take no options.
1122                                           //
1123                                           throw UnexpectedOptionException(OPTION_DESTINATION);
1124                                       }
1125                                       if (options.isSet(OPTION_DESTINATION) > 1)
1126                                       {
1127                                           //
1128                                           // More than one query language option was found
1129                                           //
1130                                           throw DuplicateOptionException(OPTION_DESTINATION);
1131                                       }
1132                   
1133                                       String handlerDestinationValue = options[i].Value();
1134                                       _handlerDestination = handlerDestinationValue;
1135                   
1136                                       handlerDestinationSet = true;
1137                                       break;
1138                                   }
1139                                   case OPTION_MAILCC:
1140 ajay.rao     1.16                 {
1141                                       if (_operationType != OPERATION_TYPE_CREATE
1142                                           || ARG_HANDLERS != _operationArg)
1143                                       {
1144                                           //
1145                                           // Help and version take no options.
1146                                           //
1147                                           throw UnexpectedOptionException(OPTION_MAILCC);
1148                                       }
1149                                       if (options.isSet(OPTION_MAILCC) > 1)
1150                                       {
1151                                           //
1152                                           // More than one query language option was found
1153                                           //
1154                                           throw DuplicateOptionException(OPTION_MAILCC);
1155                                       }
1156                   
1157                                       String handlerMailCcValue = options[i].Value();
1158                                       _handlerMailCc = handlerMailCcValue;
1159                   
1160                                       handlerMailCcSet = true;
1161 ajay.rao     1.16                     break;
1162                                   }
1163                                   case OPTION_MAILTO: //OPTION_MAILTO && OPTION_SNMPTARGETHOST
1164                                   {
1165                                       if (_operationType != OPERATION_TYPE_CREATE
1166                                           || ARG_HANDLERS != _operationArg)
1167                                       {
1168                                           //
1169                                           // Help and version take no options.
1170                                           //
1171                                           throw UnexpectedOptionException(OPTION_MAILTO);
1172                                       }
1173                                       if (options.isSet(OPTION_MAILTO) > 1)
1174                                       {
1175                                           //
1176                                           // More than one query language option was found
1177                                           //
1178                                           throw DuplicateOptionException(OPTION_MAILTO);
1179                                       }
1180                   
1181                                       String tmpValue = options[i].Value();
1182 ajay.rao     1.16                     _handlerMailTo= tmpValue;
1183                                       handlerMailToSet = true;
1184                                       _handlerSNMPTartgetHost = tmpValue;
1185                                       handlerSnmpTargetHostSet = true;
1186                                       break;
1187                                   }
1188                                   case OPTION_MAILSUBJECT:
1189                                   {
1190                                     //OPTION_MAILSUBJECT && OPTION_SNMPSECURITYNAME
1191                                       if (_operationType != OPERATION_TYPE_CREATE
1192                                           || ARG_HANDLERS != _operationArg)
1193                                       {
1194                                           //
1195                                           // Help and version take no options.
1196                                           //
1197                                           throw UnexpectedOptionException(OPTION_MAILSUBJECT);
1198                                       }
1199                                       if (options.isSet(OPTION_MAILSUBJECT) > 1)
1200                                       {
1201                                           //
1202                                           // More than one query language option was found
1203 ajay.rao     1.16                         //
1204                                           throw DuplicateOptionException(OPTION_MAILSUBJECT);
1205                                       }
1206                   
1207                                       String tmpValue = options[i].Value();
1208                                       _handlerMailSubject = tmpValue;
1209                                       handlerMailSubjectSet = true;
1210                                       _handlerSNMPSecurityName = tmpValue;
1211                                       handlerSnmpSecurityNameSet = true;
1212                                       break;
1213                                   }
1214                                   case OPTION_SNMPTARGETHOST:
1215                                   {
1216                                       if (_operationType != OPERATION_TYPE_CREATE
1217                                           || ARG_HANDLERS != _operationArg)
1218                                       {
1219                                           //
1220                                           // Help and version take no options.
1221                                           //
1222                                           throw UnexpectedOptionException(OPTION_SNMPTARGETHOST);
1223                                       }
1224 ajay.rao     1.16                     if (options.isSet(OPTION_SNMPTARGETHOST) > 1)
1225                                       {
1226                                           //
1227                                           // More than one query language option was found
1228                                           //
1229                                           throw DuplicateOptionException(OPTION_SNMPTARGETHOST);
1230                                       }
1231                   
1232                                       String tmpValue = options[i].Value();
1233                                       _handlerSNMPTartgetHost = tmpValue;
1234                                       handlerSnmpTargetHostSet = true;
1235                                       break;
1236                                   }
1237                                   case OPTION_SNMPSECURITYNAME:
1238                                   {
1239                                       if (_operationType != OPERATION_TYPE_CREATE
1240                                           || ARG_HANDLERS != _operationArg)
1241                                       {
1242                                           //
1243                                           // Help and version take no options.
1244                                           //
1245 ajay.rao     1.16                         throw UnexpectedOptionException(
1246                                                OPTION_SNMPSECURITYNAME);
1247                                       }
1248                                       if (options.isSet(OPTION_SNMPSECURITYNAME) > 1)
1249                                       {
1250                                           //
1251                                           // More than one query language option was found
1252                                           //
1253                                           throw DuplicateOptionException(OPTION_SNMPSECURITYNAME);
1254                                       }
1255                   
1256                                       String tmpValue = options[i].Value();
1257                   
1258                                       _handlerSNMPSecurityName = tmpValue;
1259                                       handlerSnmpSecurityNameSet = true;
1260                                       break;
1261                                   }
1262                                   case OPTION_SNMPPORTNUMBER:
1263                                   {
1264                                       if (_operationType != OPERATION_TYPE_CREATE
1265                                           || ARG_HANDLERS != _operationArg)
1266 ajay.rao     1.16                     {
1267                                           //
1268                                           // Help and version take no options.
1269                                           //
1270                                           throw UnexpectedOptionException(OPTION_SNMPPORTNUMBER);
1271                                       }
1272                                       if (options.isSet(OPTION_SNMPPORTNUMBER) > 1)
1273                                       {
1274                                           //
1275                                           // More than one query language option was found
1276                                           //
1277                                           throw DuplicateOptionException(OPTION_SNMPPORTNUMBER);
1278                                       }
1279                   
1280                                       String handlerPortNumberValue = options[i].Value();
1281                   
1282                                       for( Uint32 i = 0; i < handlerPortNumberValue.size(); i++)
1283                                       {
1284                                           if(!isdigit(handlerPortNumberValue[i]))
1285                                           {
1286                                               throw InvalidOptionArgumentException(
1287 ajay.rao     1.16                                 handlerPortNumberValue,
1288                                                   OPTION_SNMPPORTNUMBER);
1289                                           }
1290                                       }
1291                                       StringConversion::stringToUnsignedInteger(
1292                                           handlerPortNumberValue.getCString(),
1293                                           _handlerSNMPPortNumber);
1294                                       handlerSnmpPortNumberSet = true;
1295                                       break;
1296                                   }
1297                                   case OPTION_SNMPVERSION:
1298                                   {
1299                                       if (_operationType != OPERATION_TYPE_CREATE
1300                                           || ARG_HANDLERS != _operationArg)
1301                                       {
1302                                           //
1303                                           // Help and version take no options.
1304                                           //
1305                                           throw UnexpectedOptionException(OPTION_SNMPVERSION);
1306                                       }
1307                                       if (options.isSet(OPTION_SNMPVERSION) > 1)
1308 ajay.rao     1.16                     {
1309                                           //
1310                                           // More than one query language option was found
1311                                           //
1312                                           throw DuplicateOptionException(OPTION_SNMPVERSION);
1313                                       }
1314                   
1315                                       String handlerSnmpVersionValue = options[i].Value();
1316                   
1317                                       for( Uint32 i = 0; i < handlerSnmpVersionValue.size(); i++)
1318                                       {
1319                                           if(!isdigit(handlerSnmpVersionValue[i]))
1320                                           {
1321                                               throw InvalidOptionArgumentException(
1322                                                   handlerSnmpVersionValue,
1323                                                   OPTION_SNMPPORTNUMBER);
1324                                           }
1325                                       }
1326                                       StringConversion::stringToUnsignedInteger(
1327                                           handlerSnmpVersionValue.getCString(),
1328                                           _handlerSNMPVersion);
1329 ajay.rao     1.16                     handlerSnmpVersionSet = true;
1330                                       break;
1331                                   }
1332                                   case OPTION_SNMPENGINEID:
1333                                   {
1334                                       if (_operationType != OPERATION_TYPE_CREATE
1335                                           || ARG_HANDLERS != _operationArg)
1336                                       {
1337                                           //
1338                                           // Help and version take no options.
1339                                           //
1340                                           throw UnexpectedOptionException(OPTION_SNMPENGINEID);
1341                                       }
1342                                       if (options.isSet(OPTION_SNMPENGINEID) > 1)
1343                                       {
1344                                           //
1345                                           // More than one query language option was found
1346                                           //
1347                                           throw DuplicateOptionException(OPTION_SNMPENGINEID);
1348                                       }
1349                   
1350 ajay.rao     1.16                     String handlerSnmpEngineIdValue = options[i].Value();
1351                                       _handlerSNMPEngineID = handlerSnmpEngineIdValue;
1352                   
1353                                       handlerSnmpEngineIdSet = true;
1354                                       break;
1355                                   }
1356                                   default:
1357                                   {
1358                                       throw UnexpectedOptionException (c);
1359                                   }
1360                               }
1361                           }
1362                       }
1363                   
1364                       //
1365                       // Some more validations
1366                       //
1367                       if (_operationType == OPERATION_TYPE_UNINITIALIZED)
1368                       {
1369                           //
1370                           // No operation type was specified
1371 ajay.rao     1.16         // Show the usage
1372                           //
1373                           throw CommandFormatException(localizeMessage(
1374                               MSG_PATH, REQUIRED_OPTION_MISSING_KEY, REQUIRED_OPTION_MISSING));
1375                       }
1376                   
1377                       if (_operationType == OPERATION_TYPE_LIST)
1378                       {
1379                           if (_operationArg == ARG_FILTERS)
1380                           {
1381                               if (handlerSet)
1382                               {
1383                                   //
1384                                   // Wrong option for this operation
1385                                   // was found
1386                                   //
1387                                   throw UnexpectedOptionException(OPTION_HANDLER);
1388                               }
1389                           }
1390                           else if (_operationArg == ARG_HANDLERS)
1391                           {
1392 ajay.rao     1.16             if (filterSet)
1393                               {
1394                                   //
1395                                   // Wrong option for this operation was found
1396                                   //
1397                                   throw UnexpectedOptionException
1398                                       (OPTION_FILTER);
1399                               }
1400                           }
1401                           else if (_operationArg != ARG_SUBSCRIPTIONS)
1402                           {
1403                               //
1404                               // A wrong option argument for this
1405                               // operation was found
1406                               //
1407                               throw InvalidOptionArgumentException(
1408                                   _operationArg, OPTION_LIST);
1409                           }
1410                       }
1411 w.otsuka     1.1  
1412                       if (_operationType == OPERATION_TYPE_DISABLE)
1413                       {
1414                           if (!filterSet)
1415                           {
1416                               throw MissingOptionException(OPTION_FILTER);
1417                           }
1418                   
1419                           if (!handlerSet)
1420                           {
1421                               throw MissingOptionException(OPTION_HANDLER);
1422                           }
1423                       }
1424                   
1425                       if (_operationType == OPERATION_TYPE_ENABLE)
1426                       {
1427                           if (!filterSet)
1428                           {
1429                               throw MissingOptionException(OPTION_FILTER);
1430                           }
1431                   
1432 w.otsuka     1.1          if (!handlerSet)
1433                           {
1434                               throw MissingOptionException(OPTION_HANDLER);
1435                           }
1436                       }
1437                   
1438                       if (_operationType == OPERATION_TYPE_REMOVE)
1439                       {
1440                           if (_operationArg == ARG_FILTERS)
1441                           {
1442                               if (handlerSet)
1443                               {
1444                                   //
1445                                   // Wrong option for this
1446                                   // operation was found
1447                                   //
1448                                   throw UnexpectedOptionException(
1449                                       OPTION_HANDLER);
1450                               }
1451                           }
1452                           else
1453 w.otsuka     1.1          {
1454                               if (_operationArg == ARG_HANDLERS)
1455                               {
1456                                   if (filterSet)
1457                                   {
1458                                       //
1459                                       // Wrong option for this operation was found
1460                                       //
1461                                       throw UnexpectedOptionException(OPTION_FILTER);
1462                                   }
1463                               }
1464                               else
1465                               {
1466                                   if ((_operationArg != ARG_SUBSCRIPTIONS) &&
1467                                       (_operationArg != ARG_ALL))
1468                                   {
1469                                       //
1470                                       // A wrong option argument for this operation
1471                                       // was found
1472                                       //
1473                                       throw InvalidOptionArgumentException
1474 w.otsuka     1.1                          (_operationArg, OPTION_REMOVE);
1475                                   }
1476                               }
1477                           }
1478                           if ((_operationArg == ARG_SUBSCRIPTIONS) ||
1479                               (_operationArg == ARG_ALL) ||
1480                               (_operationArg == ARG_FILTERS))
1481                           {
1482                             if (!filterSet)
1483                               {
1484                                   throw MissingOptionException(OPTION_FILTER);
1485                               }
1486                           }
1487                           if ((_operationArg == ARG_SUBSCRIPTIONS) ||
1488                               (_operationArg == ARG_ALL) ||
1489                               (_operationArg == ARG_HANDLERS))
1490                           {
1491                               if (!handlerSet)
1492                               {
1493                                   throw MissingOptionException(OPTION_HANDLER);
1494                               }
1495 w.otsuka     1.1          }
1496                       }
1497 ajay.rao     1.16 
1498                       if (_operationType == OPERATION_TYPE_CREATE)
1499                       {
1500                           if(ARG_FILTERS == _operationArg)
1501                           {
1502                               if (!filterQuerySet)
1503                               {
1504                                   throw MissingOptionException(OPTION_QUERY);
1505                               }
1506                               if (!filterSet)
1507                               {
1508                                   throw CommandFormatException(
1509                                       localizeMessage(
1510                                            MSG_PATH,
1511                                            REQUIRED_OPTION_MISSING_KEY,
1512                                            REQUIRED_OPTION_MISSING)
1513                                       );
1514                               }
1515                           }
1516                           else if(ARG_HANDLERS == _operationArg)
1517                           {
1518 ajay.rao     1.16             if (!handlerSet)
1519                               {
1520                                   throw CommandFormatException(
1521                                       localizeMessage(
1522                                           MSG_PATH,
1523                                           REQUIRED_OPTION_MISSING_KEY,
1524                                           REQUIRED_OPTION_MISSING)
1525                                       );
1526                               }
1527                               String handlerName;
1528                               String handlerNamespace;
1529                               _handlerCreationClass =
1530                                    PEGASUS_CLASSNAME_LSTNRDST_CIMXML.getString();
1531                               _parseHandlerName(handlerNameString, handlerName, handlerNamespace,
1532                                    _handlerCreationClass);
1533                               CIMName handlerCreationClass(_handlerCreationClass);
1534                   
1535                               if(handlerCreationClass != PEGASUS_CLASSNAME_LSTNRDST_CIMXML &&
1536                                   handlerCreationClass != PEGASUS_CLASSNAME_INDHANDLER_CIMXML &&
1537                                   handlerCreationClass != PEGASUS_CLASSNAME_LSTNRDST_SYSTEM_LOG &&
1538                                   handlerCreationClass != PEGASUS_CLASSNAME_LSTNRDST_EMAIL &&
1539 ajay.rao     1.16                 handlerCreationClass != PEGASUS_CLASSNAME_INDHANDLER_SNMP)
1540                               {
1541                                   throw UnexpectedArgumentException(handlerNameString);
1542                               }
1543                   
1544                               if (handlerDestinationSet)
1545                               {
1546                                   if (handlerCreationClass != PEGASUS_CLASSNAME_LSTNRDST_CIMXML &&
1547                                       handlerCreationClass != PEGASUS_CLASSNAME_INDHANDLER_CIMXML)
1548                                   {
1549                                       //
1550                                       // Wrong option for this operation was found
1551                                       //
1552                                       throw UnexpectedOptionException(OPTION_DESTINATION);
1553                                   }
1554                               }
1555                               else if (handlerCreationClass ==
1556                                    PEGASUS_CLASSNAME_LSTNRDST_CIMXML ||
1557                                    handlerCreationClass == PEGASUS_CLASSNAME_INDHANDLER_CIMXML)
1558                               {
1559                                   throw MissingOptionException(OPTION_DESTINATION);
1560 ajay.rao     1.16             }
1561                   
1562                               if (
1563                                   handlerMailToSet ||
1564                                   handlerSnmpTargetHostSet)
1565                               {
1566                                   if (
1567                                       handlerCreationClass != PEGASUS_CLASSNAME_LSTNRDST_EMAIL &&
1568                                       handlerCreationClass != PEGASUS_CLASSNAME_INDHANDLER_SNMP)
1569                                   {
1570                                       //
1571                                       // Wrong option for this operation was found
1572                                       //
1573                                       throw UnexpectedOptionException(OPTION_SNMPTARGETHOST);
1574                                   }
1575                               }
1576                               else if(
1577                                   handlerCreationClass == PEGASUS_CLASSNAME_LSTNRDST_EMAIL ||
1578                                   handlerCreationClass == PEGASUS_CLASSNAME_INDHANDLER_SNMP)
1579                               {
1580                                   throw MissingOptionException(OPTION_SNMPTARGETHOST);
1581 ajay.rao     1.16             }
1582                               if (handlerMailCcSet)
1583                               {
1584                                   if (handlerCreationClass != PEGASUS_CLASSNAME_LSTNRDST_EMAIL)
1585                                   {
1586                                       //
1587                                       // Wrong option for this operation was found
1588                                       //
1589                                       throw UnexpectedOptionException(OPTION_MAILCC);
1590                                   }
1591                               }
1592                               if (
1593                                   handlerMailSubjectSet ||
1594                                   handlerSnmpSecurityNameSet)
1595                               {
1596                                   if (
1597                                       handlerCreationClass != PEGASUS_CLASSNAME_LSTNRDST_EMAIL &&
1598                                       handlerCreationClass != PEGASUS_CLASSNAME_INDHANDLER_SNMP)
1599                                   {
1600                                       //
1601                                       // Wrong option for this operation was found
1602 ajay.rao     1.16                     //
1603                                       throw UnexpectedOptionException(OPTION_SNMPSECURITYNAME);
1604                                  }
1605                               }
1606                             else if(handlerCreationClass == PEGASUS_CLASSNAME_LSTNRDST_EMAIL)
1607                               {
1608                                   throw MissingOptionException(OPTION_MAILSUBJECT);
1609                               }
1610                               if (handlerSnmpPortNumberSet)
1611                               {
1612                                   if (handlerCreationClass != PEGASUS_CLASSNAME_INDHANDLER_SNMP)
1613                                   {
1614                                       //
1615                                       // Wrong option for this operation was found
1616                                       //
1617                                       throw UnexpectedOptionException(OPTION_SNMPPORTNUMBER);
1618                                   }
1619                               }
1620                   
1621                               if (handlerSnmpVersionSet)
1622                               {
1623 ajay.rao     1.16                 if (handlerCreationClass != PEGASUS_CLASSNAME_INDHANDLER_SNMP)
1624                                   {
1625                                       //
1626                                       // Wrong option for this operation was found
1627                                       //
1628                                       throw UnexpectedOptionException(OPTION_SNMPVERSION);
1629                                   }
1630                               }
1631                               else if (handlerCreationClass == PEGASUS_CLASSNAME_INDHANDLER_SNMP)
1632                               {
1633                                   throw MissingOptionException(OPTION_SNMPVERSION);
1634                               }
1635                   
1636                               if (handlerSnmpEngineIdSet)
1637                               {
1638                                   if (handlerCreationClass != PEGASUS_CLASSNAME_INDHANDLER_SNMP)
1639                                   {
1640                                       //
1641                                       // Wrong option for this operation was found
1642                                       //
1643                                       throw UnexpectedOptionException(OPTION_SNMPENGINEID);
1644 ajay.rao     1.16                 }
1645                               }
1646                           }
1647                           else if(ARG_SUBSCRIPTIONS== _operationArg)
1648                           {
1649                               if (!handlerSet)
1650                               {
1651                                   throw MissingOptionException(OPTION_HANDLER);
1652                               }
1653                               if (!filterSet)
1654                               {
1655                                   throw MissingOptionException(OPTION_FILTER);
1656                               }
1657                           }
1658                           else
1659                           {
1660                               //
1661                               // A wrong option argument for this operation
1662                               // was found
1663                               //
1664                               throw InvalidOptionArgumentException
1665 ajay.rao     1.16                 (_operationArg, OPTION_CREATE);
1666                           }
1667                       }
1668                   
1669 w.otsuka     1.1      if (filterSet)
1670                       {
1671                           _parseFilterName(filterNameString, _filterName, _filterNamespace);
1672                       }
1673                       if (handlerSet)
1674                       {
1675                           _parseHandlerName(handlerNameString, _handlerName, _handlerNamespace,
1676                               _handlerCreationClass);
1677                       }
1678                   }
1679                   
1680                   /**
1681                       Executes the command and writes the results to the PrintWriters.
1682                   */
1683                   Uint32 CIMSubCommand::execute(
1684                       ostream& outPrintWriter,
1685                       ostream& errPrintWriter)
1686                   {
1687                       Array<CIMNamespaceName> namespaceNames;
1688                       //
1689                       // The CIM Client reference
1690 w.otsuka     1.1      //
1691                   
1692                       if (_operationType == OPERATION_TYPE_UNINITIALIZED)
1693                       {
1694                           //
1695                           // The command was not initialized
1696                           //
1697                           return 1;
1698                       }
1699                       else if (_operationType == OPERATION_TYPE_HELP)
1700                       {
1701                           errPrintWriter << usage << endl;
1702                           return (RC_SUCCESS);
1703                       }
1704                       else if (_operationType == OPERATION_TYPE_VERSION)
1705                       {
1706                            errPrintWriter << "Version " << PEGASUS_PRODUCT_VERSION << endl;
1707                           return (RC_SUCCESS);
1708                       }
1709                   
1710                       try
1711 w.otsuka     1.1      {
1712                           // Construct the CIMClient and set to request server messages
1713                           // in the default language of this client process.
1714                           _client.reset(new CIMClient);
1715                           _client->setRequestDefaultLanguages();
1716                       }
1717                       catch (Exception & e)
1718                       {
1719                           errPrintWriter << e.getMessage() << endl;
1720                           return (RC_ERROR);
1721                       }
1722                   
1723                       try
1724                       {
1725                           //
1726                           // Open connection with CIMSever
1727                           //
1728                           _client->connectLocal();
1729                   
1730                       }
1731                       catch (const Exception&)
1732 w.otsuka     1.1      {
1733                           errPrintWriter << localizeMessage(MSG_PATH,
1734                               CIMOM_NOT_RUNNING_KEY,
1735                               CIMOM_NOT_RUNNING) << endl;
1736                           return (RC_CONNECTION_FAILED);
1737                       }
1738                       //
1739                       // Perform the requested operation
1740                       //
1741                       try
1742                       {
1743                           CIMNamespaceName subscriptionNS;
1744                           CIMNamespaceName filterNS = CIMNamespaceName();
1745                           CIMNamespaceName handlerNS = CIMNamespaceName();
1746                           if (_subscriptionNamespace != String::EMPTY)
1747                           {
1748                               subscriptionNS = _subscriptionNamespace;
1749 ajay.rao     1.16             if(OPERATION_TYPE_LIST == _operationType &&
1750                                   _operationArg != ARG_SUBSCRIPTIONS)
1751                               {
1752                                   filterNS = subscriptionNS;
1753                                   handlerNS = subscriptionNS;
1754                               }
1755 w.otsuka     1.1          }
1756                   
1757                           if (_filterNamespace != String::EMPTY)
1758                           {
1759                               filterNS = _filterNamespace;
1760                           }
1761                   
1762                           if (_handlerNamespace != String::EMPTY)
1763                           {
1764                               handlerNS = _handlerNamespace;
1765                           }
1766                   
1767                           switch (_operationType)
1768                           {
1769                               case OPERATION_TYPE_ENABLE:
1770 kumpf        1.14                 return(_findAndModifyState(STATE_ENABLED,
1771 w.otsuka     1.1                      subscriptionNS, _filterName, filterNS,
1772                                       _handlerName, handlerNS, _handlerCreationClass,
1773                                       outPrintWriter));
1774                   
1775                               case OPERATION_TYPE_DISABLE:
1776 kumpf        1.14                 return (_findAndModifyState(STATE_DISABLED,
1777 w.otsuka     1.1                      subscriptionNS, _filterName, filterNS,
1778                                       _handlerName, handlerNS, _handlerCreationClass,
1779                                       outPrintWriter));
1780                   
1781                               case OPERATION_TYPE_LIST:
1782                                   if (_operationArg == ARG_SUBSCRIPTIONS)
1783                                   {
1784                                       if (subscriptionNS.isNull())
1785                                       {
1786                                           _getAllNamespaces(namespaceNames);
1787                                       }
1788                                       else
1789                                       {
1790                                           namespaceNames.append(subscriptionNS);
1791                                       }
1792                                       _listSubscriptions(namespaceNames, _filterName,
1793                                           filterNS, _handlerName, handlerNS,
1794                                           _handlerCreationClass, _verbose, outPrintWriter,
1795                                           errPrintWriter);
1796                                   }
1797                                   else if (_operationArg == ARG_FILTERS)
1798 w.otsuka     1.1                  {
1799                                       if (filterNS.isNull())
1800                                       {
1801                                           _getAllNamespaces(namespaceNames);
1802                                       }
1803                                       else
1804                                       {
1805                                           namespaceNames.append(filterNS);
1806                                       }
1807                                       _listFilters(_filterName, _verbose,
1808                                           namespaceNames, outPrintWriter,
1809                                           errPrintWriter);
1810                                   }
1811                                   else if (_operationArg == ARG_HANDLERS)
1812                                   {
1813                                        if (handlerNS.isNull())
1814                                        {
1815                                             _getAllNamespaces(namespaceNames);
1816                                        }
1817                                        else
1818                                        {
1819 w.otsuka     1.1                            namespaceNames.append(handlerNS);
1820                                        }
1821                                             _listHandlers(_handlerName, namespaceNames,
1822 kumpf        1.14                                _handlerCreationClass, _verbose,
1823 w.otsuka     1.1                                 outPrintWriter, errPrintWriter);
1824                                   }
1825                               break;
1826                   
1827                           case OPERATION_TYPE_REMOVE:
1828                               if ((_operationArg == ARG_SUBSCRIPTIONS) || (_operationArg ==
1829                                   ARG_ALL))
1830                               {
1831                                   Boolean removeAll = false;
1832                                   if (_operationArg == ARG_ALL)
1833                                   {
1834                                       removeAll = true;
1835                                   }
1836                                   return _removeSubscription(subscriptionNS,
1837                                       _filterName, filterNS, _handlerName, handlerNS,
1838                                       _handlerCreationClass, removeAll, outPrintWriter,
1839                                       errPrintWriter);
1840                               }
1841                               else if (_operationArg == ARG_FILTERS)
1842                               {
1843                                   return (_removeFilter(_filterName, filterNS,
1844 w.otsuka     1.1                      outPrintWriter, errPrintWriter));
1845                               }
1846                               else
1847                               {
1848                                   PEGASUS_ASSERT (_operationArg == ARG_HANDLERS);
1849                                   return _removeHandler(_handlerName,
1850                                       handlerNS, _handlerCreationClass, outPrintWriter,
1851                                       errPrintWriter);
1852                               }
1853                               break;
1854 ajay.rao     1.16         case OPERATION_TYPE_CREATE:
1855                               if ((_operationArg == ARG_SUBSCRIPTIONS) )
1856                               {
1857                                   return _createSubscription(subscriptionNS,
1858                                       _filterName, filterNS, _handlerName, handlerNS,
1859                                       _handlerCreationClass, outPrintWriter,
1860                                       errPrintWriter);
1861                               }
1862                               else if (_operationArg == ARG_FILTERS)
1863                               {
1864                                   return (_createFilter(_filterName, filterNS,
1865                                       _filterQuery,_filterQueryLanguage,_filterSourceNamespaces,
1866                                       outPrintWriter, errPrintWriter));
1867                               }
1868                               else
1869                               {
1870                                   PEGASUS_ASSERT (_operationArg == ARG_HANDLERS);
1871                                   CIMName handlerClass(_handlerCreationClass);
1872 w.otsuka     1.1  
1873 ajay.rao     1.16                 if (handlerClass == PEGASUS_CLASSNAME_LSTNRDST_CIMXML
1874                                       || handlerClass == PEGASUS_CLASSNAME_INDHANDLER_CIMXML)
1875                                   {
1876                                       return _createCimXmlHandler(_handlerName,
1877                                           handlerNS, _handlerCreationClass, _handlerDestination,
1878                                           outPrintWriter, errPrintWriter);
1879                                   }
1880                                  else if (handlerClass == PEGASUS_CLASSNAME_LSTNRDST_SYSTEM_LOG)
1881                                   {
1882                                       return _createSystemLogHandler(_handlerName,
1883                                           handlerNS, _handlerCreationClass,
1884                                           outPrintWriter, errPrintWriter);
1885                                   }
1886                                   else if (handlerClass == PEGASUS_CLASSNAME_LSTNRDST_EMAIL)
1887                                   {
1888                                       Array<String> mailToList;
1889                                       Array<String> mailCcList;
1890                                       {
1891                                           csvStringParse strl(_handlerMailTo, ',');
1892                                           while(strl.more())
1893                                           {
1894 ajay.rao     1.16                             mailToList.append(strl.next());
1895                                           }
1896                                       }
1897                                       {
1898                                           csvStringParse strl(_handlerMailCc, ',');
1899                                           while(strl.more())
1900                                           {
1901                                               mailCcList.append(strl.next());
1902                                           }
1903                                       }
1904                                       return _createEmailHandler(_handlerName,
1905                                           handlerNS, _handlerCreationClass,
1906                                           mailToList,
1907                                           mailCcList,
1908                                           _handlerMailSubject,
1909                                           outPrintWriter, errPrintWriter);
1910                                   }
1911                                   else if(handlerClass == PEGASUS_CLASSNAME_INDHANDLER_SNMP)
1912                                   {
1913                                       return _createSnmpMapperHandler(_handlerName,
1914                                           handlerNS, _handlerCreationClass,
1915 ajay.rao     1.16                         _handlerSNMPTartgetHost,
1916                                           _handlerSNMPPortNumber,
1917                                           _handlerSNMPVersion,
1918                                           _handlerSNMPSecurityName,
1919                                           _handlerSNMPEngineID,
1920                                           outPrintWriter, errPrintWriter);
1921                                   }
1922                                   else
1923                                   {
1924 dl.meetei    1.21                     PEGASUS_UNREACHABLE(PEGASUS_ASSERT(0);)
1925 ajay.rao     1.16                 }
1926                               }
1927                               break;
1928 ajay.rao     1.18         case OPERATION_TYPE_BATCH:
1929                           {
1930                               ifstream batchFile(_batchFileName.getCString());
1931                               char buffer[1024];
1932                               char* argv[128];
1933                               String tempString;
1934                               Uint32 argc = 0;
1935                               String bLine;
1936                               if (!batchFile)
1937                               {
1938                                   throw CannotOpenFile(_batchFileName);
1939                               }
1940                               // parsing batch file line by line
1941                               while (batchFile.getline(buffer, sizeof(buffer)))
1942                               {
1943                                    bLine = buffer;
1944                                    Uint32 start = 0;
1945                                    // ignore whitespaces
1946                                    while (((bLine[start]) == ' ') &&
1947                                        (start < bLine.size()))
1948                                    {
1949 ajay.rao     1.18                      start++;
1950                                    }
1951                                    // ignore comment and empty line
1952                                    if (bLine[start] != '#' &&  bLine[start] != '\000')
1953                                    {
1954                                           String batchLine = bLine.subString(start,bLine.size());
1955                                           csvStringParse BatchCmd(batchLine,' ');
1956                                           while (BatchCmd.more())
1957                                           {
1958                                              tempString = BatchCmd.next();
1959                                              if( tempString.size() != 0 )
1960                                              {
1961                                                 argv[argc] = strdup(tempString.getCString());
1962                                                 argc++;
1963                                              }
1964                                           }
1965                                           try
1966                                           {
1967                                               // get all options
1968                                               setCommand(outPrintWriter,errPrintWriter,argc,argv);
1969                                           }
1970 ajay.rao     1.18                         catch(CommandFormatException& e)
1971                                           {
1972                                              errPrintWriter << e.getMessage()<<"\n";
1973                                           }
1974                                           catch(CIMException& e)
1975                                           {
1976                                              errPrintWriter << e.getMessage()<<"\n";
1977                                           }
1978                                           catch(...)
1979                                           {
1980                   
1981                                           }
1982                                           try
1983                                           {
1984                                               // execute the command
1985                                               execute(outPrintWriter,errPrintWriter);
1986                                           }
1987                                           catch(CIMException& e)
1988                                           {
1989                                              errPrintWriter << e.getMessage()<<"\n";
1990                                           }
1991 ajay.rao     1.18                         catch(...)
1992                                           {
1993                   
1994                                           }
1995                                           for (Uint32 ac = 0; ac < argc ;ac++ )
1996                                           {
1997                                               free(argv[ac]);
1998                                           }
1999                                           argc = 0;
2000                                           if (_verbose)
2001                                           {
2002                                               _verbose = false;
2003                                           }
2004                                           // reset values before next command
2005                                           _subscriptionNamespace.clear();
2006                                           _filterNamespace.clear();
2007                                           _handlerNamespace.clear();
2008                                           _filterName.clear();
2009                                           _handlerName.clear();
2010                                           outPrintWriter << "\n";
2011                                     }
2012 ajay.rao     1.18              }
2013                                _isBatchNamespace = false;
2014                             break;
2015                           }
2016 w.otsuka     1.1          default:
2017 dl.meetei    1.21             PEGASUS_UNREACHABLE(PEGASUS_ASSERT(0);)
2018 w.otsuka     1.1              break;
2019                           }
2020                       }
2021                   
2022                       catch (CIMException& e)
2023                       {
2024                           CIMStatusCode code = e.getCode();
2025                           if (code == CIM_ERR_NOT_FOUND)
2026                           {
2027                               errPrintWriter << e.getMessage() << endl;
2028                               return RC_OBJECT_NOT_FOUND;
2029                           }
2030                           else if (code == CIM_ERR_INVALID_NAMESPACE)
2031                           {
2032                               errPrintWriter << e.getMessage() << endl;
2033                               return RC_NAMESPACE_NONEXISTENT;
2034                           }
2035                           else if (code == CIM_ERR_NOT_SUPPORTED)
2036                           {
2037                               errPrintWriter << e.getMessage() << endl;
2038                               return RC_OPERATION_NOT_SUPPORTED;
2039 w.otsuka     1.1          }
2040                           else if (code == CIM_ERR_ACCESS_DENIED)
2041                           {
2042                               errPrintWriter << e.getMessage() << endl;
2043                               return RC_ACCESS_DENIED;
2044                           }
2045                           else
2046                           {
2047                               errPrintWriter << e.getMessage() << endl;
2048                           }
2049                           return (RC_ERROR);
2050                       }
2051                       catch (ConnectionTimeoutException& e)
2052                       {
2053                           errPrintWriter << e.getMessage() << endl;
2054                           return (RC_CONNECTION_TIMEOUT);
2055                       }
2056                       catch (Exception& e)
2057                       {
2058                           errPrintWriter << e.getMessage() << endl;
2059                           return (RC_ERROR);
2060 w.otsuka     1.1      }
2061                       return (RC_SUCCESS);
2062                   }
2063                   
2064                   //
2065                   // parse the filter option string
2066                   //
2067                   void CIMSubCommand::_parseFilterName(
2068                       const String& filterNameString,
2069                       String& filterName,
2070                       String& filterNamespace)
2071                   {
2072                       Uint32 nsDelimiterIndex = filterNameString.find(
2073                           DELIMITER_NAMESPACE);
2074                       if (nsDelimiterIndex == PEG_NOT_FOUND)
2075                       {
2076                           filterName = filterNameString;
2077                           filterNamespace.clear();
2078                       }
2079                       else
2080                       {
2081 w.otsuka     1.1          if((nsDelimiterIndex == 0 ) ||
2082                               ((nsDelimiterIndex + 1) ==
2083                               filterNameString.size()))
2084                           {
2085                               // Invalid - either no name or no class
2086                               throw InvalidOptionArgumentException(
2087                                   filterNameString, OPTION_FILTER);
2088                           }
2089                           // Parse the filter namespace and filter name
2090                           filterNamespace = filterNameString.subString(0,
2091                               nsDelimiterIndex);
2092                           filterName = filterNameString.subString(
2093                               nsDelimiterIndex+1);
2094                       }
2095                   }
2096                   
2097                   //
2098                   // parse the handler option string
2099                   //
2100                   void CIMSubCommand::_parseHandlerName(
2101                       const String& handlerString,
2102 w.otsuka     1.1      String& handlerName,
2103                       String& handlerNamespace,
2104                       String& handlerCreationClass)
2105                   {
2106                       Uint32 nsDelimiterIndex = handlerString.find (
2107                           DELIMITER_NAMESPACE);
2108                       if (nsDelimiterIndex == PEG_NOT_FOUND)
2109                       {
2110                           //
2111                           // handler namespace was not found
2112                           //
2113                           handlerNamespace.clear();
2114                           //
2115                           // Check for handler class
2116                           //
2117                           Uint32 classDelimiterIndex = handlerString.find (
2118                           DELIMITER_HANDLER_CLASS);
2119                           if (classDelimiterIndex == PEG_NOT_FOUND)
2120                           {
2121                               handlerName = handlerString;
2122                           }
2123 w.otsuka     1.1          else
2124                           {
2125                               //
2126                               // Parse creation class and handler name
2127                               //
2128                               if ((classDelimiterIndex == 0) ||
2129                                   ((classDelimiterIndex + 1) ==
2130                                   handlerString.size()))
2131                               {
2132                                   // Invalid - either no name or no class
2133                                   throw InvalidOptionArgumentException(
2134                                       handlerString, OPTION_HANDLER);
2135                               }
2136                               handlerCreationClass =
2137                                   handlerString.subString (0,
2138                                   classDelimiterIndex);
2139                               handlerName = handlerString.subString(
2140                                   classDelimiterIndex+1);
2141                           }
2142                       }
2143                       else
2144 w.otsuka     1.1      {
2145                           //
2146                           // handler namespace was found
2147                           //
2148                   
2149                           // Parse the handler namespace and handler name
2150                           handlerNamespace = handlerString.subString(0,
2151                               nsDelimiterIndex);
2152                           if ((nsDelimiterIndex == 0) ||
2153                               ((nsDelimiterIndex + 1) ==
2154                               handlerString.size()))
2155                           {
2156                               // Invalid - either no name or no class
2157                               throw InvalidOptionArgumentException(
2158                                   handlerString, OPTION_HANDLER);
2159                           }
2160                           Uint32 classDelimiterIndex = handlerString.find (
2161                               DELIMITER_HANDLER_CLASS);
2162                           if (classDelimiterIndex == PEG_NOT_FOUND)
2163                           {
2164                   
2165 ajay.rao     1.16             // No creation class specified, just the handler name
2166                   
2167                               handlerName = handlerString.subString(nsDelimiterIndex+1);
2168                           }
2169                           else
2170                           {
2171                               if ((nsDelimiterIndex + 1 ) == classDelimiterIndex)
2172                               {
2173                                   // Invalid - no class
2174                                   throw InvalidOptionArgumentException(
2175                                       handlerString, OPTION_HANDLER);
2176                               }
2177                   
2178                               if ((classDelimiterIndex + 1) ==
2179                                   handlerString.size())
2180                               {
2181                                   // Invalid - no name
2182                                   throw InvalidOptionArgumentException(
2183                                       handlerString, OPTION_HANDLER);
2184                               }
2185                   
2186 ajay.rao     1.16             // Parse the handler class and name
2187                   
2188                               Uint32 slen = classDelimiterIndex - nsDelimiterIndex - 1;
2189                               handlerCreationClass =
2190                                   handlerString.subString(nsDelimiterIndex+1, slen);
2191                               handlerName = handlerString.subString(classDelimiterIndex+1);
2192                           }
2193                       }
2194                   }
2195                   
2196                   
2197                   Uint32 CIMSubCommand::_createSubscription(
2198                       const CIMNamespaceName& subscriptionNamespace,
2199                       const String& filterName,
2200                       const CIMNamespaceName& filterNamespace,
2201                       const String& handlerName,
2202                       const CIMNamespaceName& handlerNamespace,
2203                       const String& handlerCreationClass,
2204                       ostream& outPrintWriter,
2205                       ostream& errPrintWriter)
2206                   {
2207 ajay.rao     1.16     Array<CIMObjectPath> allSubPathFound;
2208                       CIMNamespaceName filterNS = _DEFAULT_SUBSCRIPTION_NAMESPACE;
2209                       CIMNamespaceName handlerNS = _DEFAULT_SUBSCRIPTION_NAMESPACE;
2210                       CIMNamespaceName subscriptionNS = _DEFAULT_SUBSCRIPTION_NAMESPACE;
2211                       CIMObjectPath filterPath;
2212                       CIMObjectPath handlerPath;
2213                       String handlerCreationCls = handlerCreationClass;
2214 ajay.rao     1.18     if (_isBatchNamespace )
2215                       {
2216                           subscriptionNS = _batchNamespace;
2217                       }
2218                       else if (!subscriptionNamespace.isNull())
2219 ajay.rao     1.16     {
2220                           subscriptionNS = subscriptionNamespace;
2221                       }
2222 ajay.rao     1.18     if (_isBatchNamespace )
2223                       {
2224                           filterNS = _batchNamespace;
2225                       }
2226                       else if (!filterNamespace.isNull())
2227 ajay.rao     1.16     {
2228                           filterNS = filterNamespace;
2229                       }
2230 ajay.rao     1.18     if (_isBatchNamespace )
2231                       {
2232                           handlerNS = _batchNamespace;
2233                       }
2234                       else if (!handlerNamespace.isNull())
2235 ajay.rao     1.16     {
2236                           handlerNS = handlerNamespace;
2237                       }
2238                   
2239                       if (handlerCreationCls == String::EMPTY)
2240                       {
2241                           handlerCreationCls = PEGASUS_CLASSNAME_LSTNRDST_CIMXML.getString();
2242                       }
2243 w.otsuka     1.1  
2244 ajay.rao     1.16     if (!_findFilter(filterName, filterNS, errPrintWriter, filterPath))
2245                       {
2246                           outPrintWriter << localizeMessage(MSG_PATH,
2247                               FILTER_NOT_FOUND_KEY,
2248                               FILTER_NOT_FOUND_FAILURE) << endl;
2249                           return (RC_OBJECT_NOT_FOUND);
2250                       }
2251                       filterPath.setNameSpace(filterNS);
2252                       if (!_findHandler(handlerName, handlerNS, handlerCreationCls,
2253                           errPrintWriter, handlerPath))
2254                       {
2255                           outPrintWriter << localizeMessage(MSG_PATH,
2256                               HANDLER_NOT_FOUND_KEY,
2257                               HANDLER_NOT_FOUND_FAILURE) << endl;
2258                           return RC_OBJECT_NOT_FOUND;
2259                       }
2260                       handlerPath.setNameSpace(handlerNS);
2261 w.otsuka     1.1  
2262 ajay.rao     1.16     CIMInstance subscriptionInstance (PEGASUS_CLASSNAME_INDSUBSCRIPTION);
2263                       subscriptionInstance.addProperty (CIMProperty (CIMName ("Filter"),
2264                           filterPath, 0, PEGASUS_CLASSNAME_INDFILTER));
2265                       subscriptionInstance.addProperty (CIMProperty (CIMName ("Handler"),
2266                           handlerPath, 0, PEGASUS_CLASSNAME_INDHANDLER_CIMXML));
2267                       subscriptionInstance.addProperty (CIMProperty
2268                           (CIMName ("SubscriptionState"), CIMValue ((Uint16) 2)));
2269 w.otsuka     1.1  
2270 ajay.rao     1.16     _client->createInstance (subscriptionNS,
2271                           subscriptionInstance);
2272 w.otsuka     1.1  
2273 ajay.rao     1.16     return (RC_SUCCESS);
2274 w.otsuka     1.1  }
2275                   
2276                   //
2277                   // remove an existing subscription instance
2278                   //
2279                   Uint32 CIMSubCommand::_removeSubscription(
2280                       const CIMNamespaceName& subscriptionNamespace,
2281                       const String& filterName,
2282                       const CIMNamespaceName& filterNamespace,
2283                       const String& handlerName,
2284                       const CIMNamespaceName& handlerNamespace,
2285                       const String& handlerCreationClass,
2286                       const Boolean removeAll,
2287                       ostream& outPrintWriter,
2288                       ostream& errPrintWriter)
2289                   {
2290 ajay.rao     1.16     Array<CIMObjectPath> allSubPathFound;
2291 w.otsuka     1.1      CIMNamespaceName filterNS;
2292                       CIMNamespaceName handlerNS;
2293                       CIMNamespaceName subscriptionNS = _DEFAULT_SUBSCRIPTION_NAMESPACE;
2294 ajay.rao     1.18     if (_isBatchNamespace )
2295                       {
2296                           subscriptionNS = _batchNamespace;
2297                       }
2298                       else if (!subscriptionNamespace.isNull())
2299 w.otsuka     1.1      {
2300                           subscriptionNS = subscriptionNamespace;
2301                       }
2302 ajay.rao     1.18     if (_isBatchNamespace )
2303                       {
2304                           filterNS = _batchNamespace;
2305                       }
2306                       else if (!filterNamespace.isNull())
2307 w.otsuka     1.1      {
2308                           filterNS = filterNamespace;
2309                       }
2310 ajay.rao     1.18     if (_isBatchNamespace )
2311                       {
2312                           handlerNS = _batchNamespace;
2313                       }
2314                       else if (!handlerNamespace.isNull())
2315 w.otsuka     1.1      {
2316                           handlerNS = handlerNamespace;
2317                       }
2318                   
2319                       if (_findSubscription(subscriptionNS, filterName, filterNS,
2320 ajay.rao     1.16         handlerName, handlerNS, handlerCreationClass, allSubPathFound))
2321 w.otsuka     1.1      {
2322 ajay.rao     1.16         for(Uint32 i = 0;i<allSubPathFound.size();i++)
2323 w.otsuka     1.1          {
2324 ajay.rao     1.16                 CIMObjectPath subPathFound = allSubPathFound[i];
2325                                   if (!removeAll)
2326 w.otsuka     1.1                  {
2327 ajay.rao     1.16                     try
2328                                       {
2329                                           _client->deleteInstance(subscriptionNS, subPathFound);
2330                                       }
2331                                       catch(const Exception& e)
2332                                       {
2333                                           errPrintWriter << e.getMessage() << endl;
2334                                       }
2335 w.otsuka     1.1                  }
2336 ajay.rao     1.16                 else
2337 w.otsuka     1.1                  {
2338 ajay.rao     1.16                     // Delete subscription, filter and handler
2339                                       CIMObjectPath filterRef, handlerRef;
2340                                       //
2341                                       //  Get the subscription Filter and Handler ObjectPaths
2342                                       //
2343                                       Array<CIMKeyBinding> keys = subPathFound.getKeyBindings();
2344                                       for( Uint32 j=0; j < keys.size(); j++)
2345                                       {
2346                                           if (keys[j].getName().equal(
2347                                               PEGASUS_PROPERTYNAME_FILTER))
2348                                           {
2349                                               filterRef = keys[j].getValue();
2350                                           }
2351                                           if (keys[j].getName().equal(
2352                                               PEGASUS_PROPERTYNAME_HANDLER))
2353                                           {
2354                                               handlerRef = keys[j].getValue();
2355                                           }
2356                                       }
2357                                       try
2358                                       {
2359 ajay.rao     1.16                         _client->deleteInstance(subscriptionNS, subPathFound);
2360                                       }
2361                                       catch(const Exception& e)
2362                                       {
2363                                           errPrintWriter << e.getMessage() << endl;
2364                                       }
2365                                       try
2366                                       {
2367                                           CIMNamespaceName tmpFilterNS = filterNS;
2368                                           if(tmpFilterNS.isNull())
2369                                           {
2370                                               tmpFilterNS = filterRef.getNameSpace();
2371                                           }
2372                                           _client->deleteInstance(tmpFilterNS, filterRef);
2373                                       }
2374                                       catch(const Exception& e)
2375                                       {
2376                                           errPrintWriter << e.getMessage() << endl;
2377                                       }
2378                                       try
2379                                       {
2380 ajay.rao     1.16                         CIMNamespaceName tmpFilterNS = handlerNS;
2381                                           if(tmpFilterNS.isNull())
2382                                           {
2383                                               tmpFilterNS = handlerRef.getNameSpace();
2384                                           }
2385                                           _client->deleteInstance(tmpFilterNS, handlerRef);
2386                                       }
2387                                       catch(const Exception& e)
2388                                       {
2389                                           errPrintWriter << e.getMessage() << endl;
2390                                       }
2391 w.otsuka     1.1                  }
2392                           }
2393                           return (RC_SUCCESS);
2394                       }
2395                       else
2396                       {
2397                           outPrintWriter << localizeMessage(MSG_PATH,
2398                               SUBSCRIPTION_NOT_FOUND_KEY,
2399                               SUBSCRIPTION_NOT_FOUND_FAILURE) << endl;
2400                           return (RC_OBJECT_NOT_FOUND);
2401                       }
2402                   }
2403                   
2404                   //
2405 ajay.rao     1.16 //  create an specify filter instance
2406                   //
2407                   Uint32 CIMSubCommand::_createFilter
2408                   (
2409                       const String& filterName,
2410                       const CIMNamespaceName& filterNamespace,
2411                       const String& filterQuery,
2412                       const String& filterQueryLanguage,
2413                       const Array<String>& filterSourceNamespaces,
2414                       ostream& outPrintWriter,
2415                       ostream& errPrintWriter
2416                   )
2417                   {
2418                       CIMObjectPath filterPath;
2419                       CIMNamespaceName filterNS = _DEFAULT_SUBSCRIPTION_NAMESPACE;
2420                       Array<String> sourceNamespaces;
2421                       sourceNamespaces = filterSourceNamespaces;
2422                       String queryLang = "CIM:CQL";
2423 ajay.rao     1.18     if (_isBatchNamespace )
2424                       {
2425                           filterNS = _batchNamespace;
2426                       }
2427                       else if (!filterNamespace.isNull())
2428 ajay.rao     1.16     {
2429                           filterNS = filterNamespace;
2430                       }
2431                       if (sourceNamespaces.size() == 0)
2432                       {
2433                           sourceNamespaces.append(filterNS.getString());
2434                       }
2435                       if (filterQueryLanguage != String::EMPTY)
2436                       {
2437                           queryLang = filterQueryLanguage;
2438                       }
2439                   
2440                       CIMInstance filterInstance (PEGASUS_CLASSNAME_INDFILTER);
2441                       filterInstance.addProperty (CIMProperty (CIMName ("Name"), filterName));
2442                       filterInstance.addProperty (CIMProperty (CIMName ("Query"), filterQuery));
2443                       filterInstance.addProperty (CIMProperty (CIMName ("QueryLanguage"),
2444                           filterQueryLanguage));
2445                       if (_filterNSFlag == false && sourceNamespaces.size() == 1)
2446                       {
2447                            filterInstance.addProperty (
2448                                CIMProperty (CIMName ("SourceNamespace"),sourceNamespaces[0]));
2449 ajay.rao     1.16     }
2450                       else
2451                       {
2452                            filterInstance.addProperty (
2453                                CIMProperty (CIMName ("SourceNamespaces"),sourceNamespaces));
2454                       }
2455                       _client->createInstance(filterNS, filterInstance);
2456                       return (RC_SUCCESS);
2457                   }
2458                   
2459                   //
2460 w.otsuka     1.1  //  remove an existing filter instance
2461                   //
2462                   Uint32 CIMSubCommand::_removeFilter
2463                   (
2464                       const String& filterName,
2465                       const CIMNamespaceName& filterNamespace,
2466                       ostream& outPrintWriter,
2467                       ostream& errPrintWriter
2468                   )
2469                   {
2470                       CIMObjectPath filterPath;
2471                       CIMNamespaceName filterNS = _DEFAULT_SUBSCRIPTION_NAMESPACE;
2472 ajay.rao     1.18     if (_isBatchNamespace )
2473                       {
2474                           filterNS = _batchNamespace;
2475                       }
2476                       else if (!filterNamespace.isNull())
2477 w.otsuka     1.1      {
2478                           filterNS = filterNamespace;
2479                       }
2480                   
2481                       if (_findFilter(filterName, filterNS, errPrintWriter, filterPath))
2482                       {
2483                           _client->deleteInstance(filterNS, filterPath);
2484                           return (RC_SUCCESS);
2485                       }
2486                       else
2487                       {
2488                           outPrintWriter << localizeMessage(MSG_PATH,
2489                               FILTER_NOT_FOUND_KEY,
2490                               FILTER_NOT_FOUND_FAILURE) << endl;
2491                           return (RC_OBJECT_NOT_FOUND);
2492                       }
2493                   }
2494                   
2495                   //
2496                   //  find a filter
2497                   //
2498 w.otsuka     1.1  Boolean CIMSubCommand::_findFilter(
2499                       const String& filterName,
2500                       const CIMNamespaceName& filterNamespace,
2501                       ostream& errPrintWriter,
2502                       CIMObjectPath& filterPath)
2503                   {
2504                       Array<CIMObjectPath> filterPaths;
2505                       Boolean status = false;
2506                   
2507                       try
2508                       {
2509                           filterPaths = _client->enumerateInstanceNames(
2510                               filterNamespace,
2511                               PEGASUS_CLASSNAME_INDFILTER);
2512                       }
2513                       catch (CIMException& e)
2514                       {
2515                           if (e.getCode() == CIM_ERR_INVALID_CLASS)
2516                           {
2517                               return false;
2518                           }
2519 w.otsuka     1.1          else
2520                           {
2521                               throw;
2522                           }
2523                       }
2524                   
2525                       Uint32 filterCount = filterPaths.size();
2526                       if (filterCount > 0)
2527                       {
2528                   
2529                           // find matching indication filter
2530                           for (Uint32 i = 0; i < filterCount; i++)
2531                           {
2532                               CIMObjectPath fPath = filterPaths[i];
2533                               Array<CIMKeyBinding> keys = fPath.getKeyBindings();
2534                               for(Uint32 j=0; j < keys.size(); j++)
2535                               {
2536                                   String filterNameValue;
2537                                   if(keys[j].getName().equal(PEGASUS_PROPERTYNAME_NAME))
2538                                   {
2539                                       filterNameValue = keys[j].getValue();
2540 w.otsuka     1.1                  }
2541                                   if (filterNameValue == filterName)
2542                                   {
2543                                       status = true;
2544                                       filterPath = fPath;
2545                                       break;
2546                                   }
2547                             }
2548                           }
2549                       }
2550                       return status;
2551                   }
2552                   
2553 ajay.rao     1.16 ////  create a specify CIMXML handler instance
2554                   //
2555                   Uint32 CIMSubCommand::_createCimXmlHandler(
2556                       const String& handlerName,
2557                       const CIMNamespaceName& handlerNamespace,
2558                       const String& handlerCreationClass,
2559                       const String& handlerDestination,
2560                       ostream& outPrintWriter,
2561                       ostream& errPrintWriter)
2562                   {
2563                       CIMObjectPath handlerPath;
2564                       CIMNamespaceName handlerNS = _DEFAULT_SUBSCRIPTION_NAMESPACE;
2565                       CIMName creationClass = PEGASUS_CLASSNAME_LSTNRDST_CIMXML;
2566 ajay.rao     1.18     if (_isBatchNamespace )
2567                       {
2568                           handlerNS = _batchNamespace;
2569                       }
2570                       else if (!handlerNamespace.isNull())
2571 ajay.rao     1.16     {
2572                           handlerNS = handlerNamespace;
2573                       }
2574                   
2575                       if (handlerCreationClass != String::EMPTY)
2576                       {
2577                           creationClass = handlerCreationClass;
2578                       }
2579                   
2580                       CIMInstance handlerInstance(creationClass);
2581                       handlerInstance.addProperty(CIMProperty(CIMName("Name"), handlerName));
2582                       handlerInstance.addProperty(CIMProperty(
2583                           CIMName("Destination"),
2584                           handlerDestination));
2585                   
2586                       _client->createInstance(
2587                           handlerNS,
2588                           handlerInstance);
2589                           return (RC_SUCCESS);
2590                   }
2591                   
2592 ajay.rao     1.16 ////  create a specify Syslog handler instance
2593                   //
2594                   Uint32 CIMSubCommand::_createSystemLogHandler(
2595                       const String& handlerName,
2596                       const CIMNamespaceName& handlerNamespace,
2597                       const String& handlerCreationClass,
2598                       ostream& outPrintWriter,
2599                       ostream& errPrintWriter)
2600                   {
2601                       CIMObjectPath handlerPath;
2602                       CIMNamespaceName handlerNS = _DEFAULT_SUBSCRIPTION_NAMESPACE;
2603                       CIMName creationClass = PEGASUS_CLASSNAME_LSTNRDST_SYSTEM_LOG;
2604 ajay.rao     1.18     if (_isBatchNamespace )
2605                       {
2606                           handlerNS = _batchNamespace;
2607                       }
2608                       else if (!handlerNamespace.isNull())
2609 ajay.rao     1.16     {
2610                           handlerNS = handlerNamespace;
2611                       }
2612                   
2613                       if (handlerCreationClass != String::EMPTY)
2614                       {
2615                           creationClass = handlerCreationClass;
2616                       }
2617                   
2618                       CIMInstance handlerInstance(creationClass);
2619                       handlerInstance.addProperty(CIMProperty(CIMName("Name"), handlerName));
2620                   
2621                       _client->createInstance(
2622                           handlerNS,
2623                           handlerInstance);
2624                           return (RC_SUCCESS);
2625                   }
2626                   
2627                   
2628                   ////  create a specify Email handler instance
2629                   //
2630 ajay.rao     1.16 Uint32 CIMSubCommand::_createEmailHandler(
2631                           const String& handlerName,
2632                           const CIMNamespaceName& handlerNamespace,
2633                           const String& handlerCreationClass,
2634                           const Array<String>& mailTo,
2635                           const Array<String>& mailCc,
2636                           const String& mailSubject,
2637                           ostream& outPrintWriter,
2638                           ostream& errPrintWriter)
2639                   {
2640                       CIMObjectPath handlerPath;
2641                       CIMNamespaceName handlerNS = _DEFAULT_SUBSCRIPTION_NAMESPACE;
2642                       CIMName creationClass = PEGASUS_CLASSNAME_LSTNRDST_EMAIL;
2643 ajay.rao     1.18     if (_isBatchNamespace )
2644                       {
2645                           handlerNS = _batchNamespace;
2646                       }
2647                       else if (!handlerNamespace.isNull())
2648 ajay.rao     1.16     {
2649                           handlerNS = handlerNamespace;
2650                       }
2651                   
2652                       if (handlerCreationClass != String::EMPTY)
2653                       {
2654                           creationClass = handlerCreationClass;
2655                       }
2656                   
2657                       CIMInstance handlerInstance(creationClass);
2658                       handlerInstance.addProperty(CIMProperty(CIMName("Name"), handlerName));
2659                   
2660                       handlerInstance.addProperty(CIMProperty(
2661                           PEGASUS_PROPERTYNAME_LSTNRDST_MAILTO,
2662                           mailTo));
2663                   
2664                       handlerInstance.addProperty(CIMProperty(
2665                           PEGASUS_PROPERTYNAME_LSTNRDST_MAILCC,
2666                           mailCc));
2667                   
2668                       handlerInstance.addProperty(CIMProperty(
2669 ajay.rao     1.16         PEGASUS_PROPERTYNAME_LSTNRDST_MAILSUBJECT,
2670                           mailSubject));
2671                   
2672                       _client->createInstance(
2673                           handlerNS,
2674                           handlerInstance);
2675                           return (RC_SUCCESS);
2676                   }
2677                   
2678                   ////  create a specify Snmp Mapper handler instance
2679                   //
2680                   Uint32 CIMSubCommand::_createSnmpMapperHandler(
2681                           const String& handlerName,
2682                           const CIMNamespaceName& handlerNamespace,
2683                           const String& handlerCreationClass,
2684                           const String& targetHost,
2685                           Uint32 snmpPort,
2686                           Uint32 snmpVersion,
2687                           const String& securityName,
2688                           const String& engineId,
2689                           ostream& outPrintWriter,
2690 ajay.rao     1.16         ostream& errPrintWriter)
2691                   {
2692                       CIMObjectPath handlerPath;
2693                       CIMNamespaceName handlerNS = _DEFAULT_SUBSCRIPTION_NAMESPACE;
2694                       CIMName creationClass = PEGASUS_CLASSNAME_INDHANDLER_SNMP;
2695                       Uint16 targetHostFormat = 2; //Host Name
2696 ajay.rao     1.18     if (_isBatchNamespace )
2697                       {
2698                           handlerNS = _batchNamespace;
2699                       }
2700                       else if (!handlerNamespace.isNull())
2701 ajay.rao     1.16     {
2702                           handlerNS = handlerNamespace;
2703                       }
2704                   
2705                       if (handlerCreationClass != String::EMPTY)
2706                       {
2707                           creationClass = handlerCreationClass;
2708                       }
2709                   
2710                       CIMInstance handlerInstance(creationClass);
2711                       handlerInstance.addProperty(CIMProperty(CIMName("Name"), handlerName));
2712                   
2713                       {
2714 dev.meetei   1.20         HostAddress tgtHost;
2715                           tgtHost.setHostAddress(targetHost);
2716                           if (tgtHost.getAddressType() == HostAddress::AT_IPV4)
2717                           {
2718                                 targetHostFormat = 3; //Ipv4
2719                           }
2720                           else if(tgtHost.getAddressType() == HostAddress::AT_IPV6)
2721                           {
2722                               targetHostFormat = 4; //Ipv6
2723                           }
2724 ajay.rao     1.16     }
2725                       handlerInstance.addProperty(CIMProperty(
2726                           PEGASUS_PROPERTYNAME_LSTNRDST_TARGETHOST,
2727                           targetHost));
2728                   
2729                       handlerInstance.addProperty(CIMProperty(
2730                           "TargetHostFormat",
2731                           (Uint16)targetHostFormat));
2732                   
2733                       handlerInstance.addProperty(CIMProperty(
2734                           "PortNumber",
2735                           snmpPort));
2736                   
2737                       handlerInstance.addProperty(CIMProperty(
2738                           "SNMPVersion",
2739                           (Uint16)snmpVersion));
2740                   
2741                       if (securityName != String::EMPTY)
2742                       {
2743                           handlerInstance.addProperty(CIMProperty(
2744                               "SNMPSecurityName",
2745 ajay.rao     1.16             securityName));
2746                       }
2747                   
2748                       if (engineId != String::EMPTY)
2749                       {
2750                           handlerInstance.addProperty(CIMProperty(
2751                               "SNMPEngineID",
2752                               engineId));
2753                       }
2754                       _client->createInstance(
2755                           handlerNS,
2756                           handlerInstance);
2757                           return (RC_SUCCESS);
2758                   }
2759 w.otsuka     1.1  ////  remove an existing handler instance
2760                   //
2761                   Uint32 CIMSubCommand::_removeHandler(
2762                       const String& handlerName,
2763                       const CIMNamespaceName& handlerNamespace,
2764                       const String& handlerCreationClass,
2765                       ostream& outPrintWriter,
2766                       ostream& errPrintWriter)
2767                   {
2768                       CIMObjectPath handlerPath;
2769                       CIMNamespaceName handlerNS = _DEFAULT_SUBSCRIPTION_NAMESPACE;
2770 ajay.rao     1.18     if (_isBatchNamespace )
2771                       {
2772                           handlerNS = _batchNamespace;
2773                       }
2774                       else if (!handlerNamespace.isNull())
2775 w.otsuka     1.1      {
2776                           handlerNS = handlerNamespace;
2777                       }
2778                   
2779                       if (_findHandler(handlerName, handlerNS, handlerCreationClass,
2780                           errPrintWriter, handlerPath))
2781                       {
2782                           _client->deleteInstance(handlerNS, handlerPath);
2783                           return (RC_SUCCESS);
2784                       }
2785                       else
2786                       {
2787                           outPrintWriter << localizeMessage(MSG_PATH,
2788                               HANDLER_NOT_FOUND_KEY,
2789                               HANDLER_NOT_FOUND_FAILURE) << endl;
2790                           return RC_OBJECT_NOT_FOUND;
2791                       }
2792                   }
2793                   
2794                   //
2795                   //  find a matching handler
2796 w.otsuka     1.1  //
2797                   Boolean CIMSubCommand::_findHandler(
2798                       const String& handlerName,
2799                       const CIMNamespaceName& handlerNamespace,
2800                       const String& handlerCreationClass,
2801                       ostream& errPrintWriter,
2802                       CIMObjectPath& handlerPath)
2803                   {
2804                       Array<CIMObjectPath> handlerPaths;
2805                       String handlerCC = PEGASUS_CLASSNAME_LSTNRDST_CIMXML.getString();
2806                       Boolean status = false;
2807                       if (handlerCreationClass != String::EMPTY)
2808                       {
2809                           handlerCC = handlerCreationClass;
2810                       }
2811                       try
2812                       {
2813                           handlerPaths = _client->enumerateInstanceNames(
2814                               handlerNamespace,
2815                               handlerCC);
2816                       }
2817 w.otsuka     1.1      catch (CIMException& e)
2818                       {
2819                           if (e.getCode() == CIM_ERR_INVALID_CLASS)
2820                           {
2821                               return false;
2822                           }
2823                           else
2824                           {
2825                               throw;
2826                           }
2827                       }
2828                   
2829                       Uint32 handlerCount = handlerPaths.size();
2830                       if (handlerCount > 0)
2831                       {
2832                           // find matching indication handler
2833                           for (Uint32 i = 0; i < handlerCount; i++)
2834                           {
2835                               Boolean nameFound = false;
2836                               CIMObjectPath hPath = handlerPaths[i];
2837                               Array<CIMKeyBinding> keys = hPath.getKeyBindings();
2838 w.otsuka     1.1              for( Uint32 j=0; j < keys.size(); j++)
2839                               {
2840                                   if (keys[j].getName().equal(PEGASUS_PROPERTYNAME_NAME))
2841                                   {
2842                                       String handlerNameValue = keys[j].getValue();
2843                                       if (handlerNameValue == handlerName )
2844                                       {
2845                                           nameFound = true;
2846                                           break;
2847                                       }
2848                                   }
2849                               }
2850                               if (nameFound)
2851                               {
2852                                   status = true;
2853                                   handlerPath = hPath;
2854                                   break;
2855                               }
2856                           }
2857                       }
2858                       return status;
2859 w.otsuka     1.1  }
2860                   
2861                   //
2862                   //  Modify a subscription state
2863                   //
2864                   void CIMSubCommand::_modifySubscriptionState(
2865                       const CIMNamespaceName& subscriptionNS,
2866                       const CIMObjectPath& targetPath,
2867                       const Uint16 newState,
2868                       ostream& outPrintWriter)
2869                   {
2870                       Boolean alreadySet = false;
2871                       CIMInstance targetInstance = _client->getInstance(subscriptionNS,
2872                           targetPath);
2873                       Uint32 pos = targetInstance.findProperty (
2874                           PEGASUS_PROPERTYNAME_SUBSCRIPTION_STATE);
2875                       if (pos != PEG_NOT_FOUND)
2876                       {
2877                           Uint16 subscriptionState;
2878                           if (targetInstance.getProperty(pos).getValue().isNull())
2879                           {
2880 w.otsuka     1.1              subscriptionState = STATE_UNKNOWN;
2881                           }
2882                           else
2883                           {
2884                               targetInstance.getProperty(pos).getValue().get
2885                                   (subscriptionState);
2886                               if (subscriptionState == newState)
2887                               {
2888                                   if (newState == STATE_ENABLED )
2889                                   {
2890                                       outPrintWriter << localizeMessage(MSG_PATH,
2891                                           SUBSCRIPTION_ALREADY_ENABLED_KEY,
2892                                           SUBSCRIPTION_ALREADY_ENABLED) << endl;
2893                                   }
2894                                   else
2895                                   {
2896                                       outPrintWriter << localizeMessage(MSG_PATH,
2897                                           SUBSCRIPTION_ALREADY_DISABLED_KEY,
2898                                           SUBSCRIPTION_ALREADY_DISABLED) << endl;
2899                                   }
2900                                   alreadySet = true;
2901 w.otsuka     1.1              }
2902                           }
2903                           if (!alreadySet)
2904                           {
2905                               targetInstance.getProperty(pos).setValue(newState);
2906                               Array <CIMName> propertyNames;
2907                               propertyNames.append(PEGASUS_PROPERTYNAME_SUBSCRIPTION_STATE);
2908                               CIMPropertyList properties(propertyNames);
2909                               targetInstance.setPath(targetPath);
2910                               _client->modifyInstance(subscriptionNS, targetInstance, false,
2911                                   properties);
2912                           }
2913                       }
2914                   }
2915                   
2916                   //
2917                   //  find a subscription
2918                   //
2919                   Boolean CIMSubCommand::_findSubscription(
2920                       const CIMNamespaceName& subscriptionNamespace,
2921                       const String& filterName,
2922 w.otsuka     1.1      const CIMNamespaceName& filterNamespace,
2923                       const String& handlerName,
2924                       const CIMNamespaceName& handlerNamespace,
2925                       const String& handlerCC,
2926 ajay.rao     1.16     Array<CIMObjectPath>& subscriptionFound)
2927 w.otsuka     1.1  {
2928                       Array<CIMObjectPath> subscriptionPaths;
2929 ouyang.jian  1.11     String handlerCreationClass;
2930 w.otsuka     1.1      if (handlerCC != String::EMPTY)
2931                       {
2932                           handlerCreationClass = handlerCC;
2933                       }
2934                       try
2935                       {
2936                           subscriptionPaths = _client->enumerateInstanceNames(
2937                               subscriptionNamespace, PEGASUS_CLASSNAME_INDSUBSCRIPTION);
2938                       }
2939                       catch (CIMException& e)
2940                       {
2941                           if (e.getCode() == CIM_ERR_INVALID_CLASS)
2942                           {
2943                               return false;
2944                           }
2945                           else
2946                           {
2947                               throw;
2948                           }
2949                       }
2950                   
2951 w.otsuka     1.1      Uint32 subscriptionCount = subscriptionPaths.size();
2952                       if (subscriptionCount > 0)
2953                       {
2954                           String handlerNameString, filterNameString;
2955                           CIMNamespaceName handlerNS, filterNS;
2956                   
2957                           // Search the indication subscriptions instances
2958                           for (Uint32 i = 0; i < subscriptionCount; i++)
2959                           {
2960                               CIMObjectPath subPath = subscriptionPaths[i];
2961                               CIMObjectPath filterRef;
2962                               if (_filterMatches(subPath, subscriptionNamespace,
2963                                   filterName, filterNamespace, filterNS, filterRef))
2964                               {
2965                                   CIMObjectPath handlerRef;
2966                                   if(_handlerMatches(subPath, subscriptionNamespace,
2967 kumpf        1.14                     handlerName, handlerNamespace, handlerCreationClass,
2968 w.otsuka     1.1                      handlerNS, handlerRef))
2969                                   {
2970 ajay.rao     1.16                     subscriptionFound.append(subPath);
2971 w.otsuka     1.1                  }
2972                               }
2973                           }
2974                       }
2975 ajay.rao     1.16     return subscriptionFound.size() > 0;
2976 w.otsuka     1.1  }
2977                   
2978                   //
2979                   // Find a subscription and modify it's state
2980                   //
2981                   Uint32 CIMSubCommand::_findAndModifyState(
2982                       const Uint16 newState,
2983 kumpf        1.14     const CIMNamespaceName& subscriptionNamespace,
2984 w.otsuka     1.1      const String& filterName,
2985                       const CIMNamespaceName& filterNamespace,
2986                       const String& handlerName,
2987                       const CIMNamespaceName& handlerNamespace,
2988                       const String& handlerCreationClass,
2989                       ostream& outPrintWriter)
2990                   {
2991 ajay.rao     1.16     Array<CIMObjectPath> allSubscriptionFound;
2992 w.otsuka     1.1      CIMNamespaceName filterNS;
2993                       CIMNamespaceName handlerNS;
2994                       CIMNamespaceName subscriptionNS = _DEFAULT_SUBSCRIPTION_NAMESPACE;
2995                   
2996 ajay.rao     1.18     if (_isBatchNamespace )
2997                       {
2998                           subscriptionNS = _batchNamespace;
2999                       }
3000                   
3001                       else if (!subscriptionNamespace.isNull())
3002 w.otsuka     1.1      {
3003                           subscriptionNS = subscriptionNamespace;
3004                       }
3005                   
3006 ajay.rao     1.18     if (_isBatchNamespace )
3007                       {
3008                           filterNS = _batchNamespace;
3009                       }
3010                   
3011                       else if (!filterNamespace.isNull())
3012 w.otsuka     1.1      {
3013                           filterNS = filterNamespace;
3014                       }
3015                       else
3016                       {
3017                           filterNS = subscriptionNS;
3018                       }
3019 ajay.rao     1.18     if (_isBatchNamespace )
3020                       {
3021                           handlerNS = _batchNamespace;
3022                       }
3023                   
3024                       else if (!handlerNamespace.isNull())
3025 w.otsuka     1.1      {
3026                           handlerNS = handlerNamespace;
3027                       }
3028                       else
3029                       {
3030                           handlerNS = subscriptionNS;
3031                       }
3032 kumpf        1.14     // Find subscriptions in the namespace specified by the user
3033 w.otsuka     1.1      if (_findSubscription(subscriptionNS, filterName, filterNS,
3034 ajay.rao     1.16         handlerName, handlerNS, handlerCreationClass, allSubscriptionFound))
3035 w.otsuka     1.1      {
3036 ajay.rao     1.16         for(Uint32 i = 0;i<allSubscriptionFound.size();i++)
3037                           {
3038                                   _modifySubscriptionState(
3039                                        subscriptionNS,
3040                                        allSubscriptionFound[i],
3041                                        newState,
3042                                        outPrintWriter);
3043                           }
3044 w.otsuka     1.1          return(RC_SUCCESS);
3045                       }
3046                       else
3047                       {
3048                           outPrintWriter << localizeMessage(MSG_PATH,
3049                               SUBSCRIPTION_NOT_FOUND_KEY,
3050                               SUBSCRIPTION_NOT_FOUND_FAILURE) << endl;
3051                           return(RC_OBJECT_NOT_FOUND);
3052                       }
3053                   }
3054                   
3055                   //
3056                   // Get the name from a CIMObjectPath
3057                   //
3058                   String CIMSubCommand::_getNameInKey(const CIMObjectPath& r)
3059                   {
3060                       String nameValue;
3061                       Array<CIMKeyBinding> keys = r.getKeyBindings();
3062                       for (Uint32 j=0; j < keys.size(); j++)
3063                       {
3064                           if (keys[j].getName().equal(PEGASUS_PROPERTYNAME_NAME))
3065 w.otsuka     1.1          {
3066                               nameValue = keys[j].getValue();
3067                           }
3068                       }
3069                       return (nameValue);
3070                   }
3071                   
3072                   //
3073                   // Get all namespaces
3074                   //
3075                   //
3076                   void CIMSubCommand::_getAllNamespaces(
3077                       Array<CIMNamespaceName>& namespaceNames)
3078                   {
3079                       Array<CIMObjectPath> instanceNames = _client->enumerateInstanceNames(
3080 kumpf        1.4          PEGASUS_VIRTUAL_TOPLEVEL_NAMESPACE,
3081                           PEGASUS_CLASSNAME___NAMESPACE);
3082 w.otsuka     1.1  
3083                       // for all new elements in the output array
3084                       for (Uint32 i = 0; i < instanceNames.size(); i++)
3085                       {
3086                           Array<CIMKeyBinding> keys = instanceNames[i].getKeyBindings();
3087                           for (Uint32 j=0; j < keys.size(); j++)
3088                           {
3089                               if (keys[j].getName().equal(PEGASUS_PROPERTYNAME_NAME))
3090                               {
3091                                   namespaceNames.append(keys[j].getValue());
3092                               }
3093                           }
3094                       }
3095                   }
3096                   
3097                   //
3098                   //  get a list of all Handlers in the specified namespace(s)
3099                   //
3100                   void CIMSubCommand::_listHandlers(
3101                       const String& handlerName,
3102                       const Array<CIMNamespaceName>& namespaceNames,
3103 w.otsuka     1.1      const String& handlerCreationClass,
3104                       const Boolean verbose,
3105                       ostream& outPrintWriter,
3106                       ostream& errPrintWriter)
3107                   {
3108                       Array <Uint32> maxColumnWidth;
3109                       Array <ListColumnEntry> listOutputTable;
3110                       Array<String> handlersFound;
3111                       Array<String> destinationsFound;
3112                       Array<CIMInstance> instancesFound;
3113                       Array<Uint32> handlerTypesFound;
3114                       const String handlerTitle = "HANDLER";
3115                       const String destinationTitle = "DESTINATION";
3116                       if (!verbose)
3117                       {
3118                           handlersFound.append(handlerTitle);
3119                           maxColumnWidth.append(handlerTitle.size());
3120                           destinationsFound.append(destinationTitle);
3121                           maxColumnWidth.append(destinationTitle.size());
3122                       }
3123                       listOutputTable.append(handlersFound);
3124 w.otsuka     1.1      listOutputTable.append(destinationsFound);
3125                       //
3126                       //  Find handlers in namespaces
3127                       //
3128 ajay.rao     1.18     if (_isBatchNamespace )
3129 w.otsuka     1.1      {
3130 ajay.rao     1.18         _getHandlerList(
3131                                   handlerName,
3132                                   _batchNamespace,
3133                                   handlerCreationClass,
3134                                   verbose,
3135                                   instancesFound,
3136                                   handlerTypesFound,
3137                                   maxColumnWidth,
3138                                   listOutputTable,
3139                                   outPrintWriter,
3140                                   errPrintWriter);
3141                       }
3142                       else
3143                       {
3144                          for (Uint32 i = 0 ; i < namespaceNames.size() ; i++)
3145                          {
3146                              _getHandlerList(
3147                                   handlerName,
3148                                   namespaceNames[i],
3149                                   handlerCreationClass,
3150                                   verbose,
3151 ajay.rao     1.18                 instancesFound,
3152                                   handlerTypesFound,
3153                                   maxColumnWidth,
3154                                   listOutputTable,
3155                                   outPrintWriter,
3156                                   errPrintWriter);
3157                          }
3158 w.otsuka     1.1      }
3159                       if (verbose)
3160                       {
3161                           if (listOutputTable[_HANDLER_LIST_NAME_COLUMN].size() > 0 )
3162                           {
3163                               _printHandlersVerbose(instancesFound, handlerTypesFound,
3164                                    listOutputTable, outPrintWriter);
3165                           }
3166                       }
3167                       else
3168                       {
3169                           if (listOutputTable[_HANDLER_LIST_NAME_COLUMN].size() > 1 )
3170                           {
3171                               _printColumns(maxColumnWidth, listOutputTable, outPrintWriter);
3172                           }
3173                       }
3174                   }
3175                   
3176                   //
3177                   //  get a list of all handlers in a specified namespace
3178                   //
3179 w.otsuka     1.1  void CIMSubCommand::_getHandlerList(
3180                       const String& handlerName,
3181                       const CIMNamespaceName& handlerNamespace,
3182                       const String& handlerCreationClass,
3183                       const Boolean verbose,
3184                       Array<CIMInstance>& instancesFound,
3185                       Array<Uint32>& handlerTypesFound,
3186                       Array <Uint32>& maxColumnWidth,
3187                       Array <ListColumnEntry>& listOutputTable,
3188                       ostream& outPrintWriter,
3189                       ostream& errPrintWriter)
3190                   {
3191                       Array<CIMObjectPath> handlerPaths;
3192                       try
3193                       {
3194                           handlerPaths = _client->enumerateInstanceNames(
3195                               handlerNamespace,
3196                               PEGASUS_CLASSNAME_LSTNRDST);
3197                       }
3198                       catch(CIMException& e)
3199                       {
3200 w.otsuka     1.1          if (e.getCode() == CIM_ERR_INVALID_CLASS)
3201                           {
3202                               return;
3203                           }
3204                           else
3205                           {
3206                               throw;
3207                           }
3208                       }
3209                   
3210                       Uint32 handlerCount = handlerPaths.size();
3211                       if (handlerCount > 0)
3212                       {
3213                           String handlerNameValue;
3214                           String destination;
3215                           String creationClassValue;
3216                   
3217                           // List all the indication handlers
3218                           for (Uint32 i = 0; i < handlerCount; i++)
3219                           {
3220                               Boolean isMatch = true;
3221 w.otsuka     1.1              CIMObjectPath handlerPath;
3222                               CIMObjectPath hPath = handlerPaths[i];
3223                               Array<CIMKeyBinding> keys = hPath.getKeyBindings();
3224                               for(Uint32 j=0; j < keys.size(); j++)
3225                               {
3226                                   if(keys[j].getName().equal(PEGASUS_PROPERTYNAME_NAME))
3227                                   {
3228                                       handlerNameValue = keys[j].getValue();
3229                                   }
3230 karl         1.7                  if(keys[j].getName().equal(
3231                                               PEGASUS_PROPERTYNAME_CREATIONCLASSNAME))
3232 w.otsuka     1.1                  {
3233                                       creationClassValue = keys[j].getValue();
3234                                   }
3235                               }
3236                               if (handlerName != String::EMPTY)
3237                               {
3238                                   if (handlerNameValue == handlerName)
3239                                   {
3240                                       if (handlerCreationClass != String::EMPTY)
3241                                       {
3242                                           if (handlerCreationClass !=
3243                                               creationClassValue)
3244                                           {
3245                                               isMatch = false;
3246                                           }
3247                                       }
3248                                   }
3249                                   else
3250                                   {
3251                                       isMatch = false;
3252                                   }
3253 w.otsuka     1.1              }
3254                               if (isMatch)
3255                               {
3256                                   handlerPath = hPath;
3257                                   CIMInstance handlerInstance = _client->getInstance(
3258                                       handlerNamespace, handlerPath);
3259                                   Uint32 handlerType = _HANDLER_CIMXML;
3260                                   _getHandlerDestination(handlerInstance, creationClassValue,
3261                                       handlerType, destination);
3262                                   String handlerString = handlerNamespace.getString();
3263                                   handlerString.append(DELIMITER_NAMESPACE);
3264                                   handlerString.append(creationClassValue);
3265                                   handlerString.append(DELIMITER_HANDLER_CLASS);
3266                                   handlerString.append(handlerNameValue);
3267 karl         1.7                  listOutputTable[_HANDLER_LIST_NAME_COLUMN].append(
3268                                           handlerString);
3269                                   listOutputTable[_HANDLER_LIST_DESTINATION_COLUMN].append(
3270                                           destination);
3271 w.otsuka     1.1                  handlerTypesFound.append(handlerType);
3272                                   if (verbose)
3273                                   {
3274                                       instancesFound.append(handlerInstance);
3275                                   }
3276                                   else
3277                                   {
3278                                       if (handlerString.size() >
3279                                           maxColumnWidth[_HANDLER_LIST_NAME_COLUMN])
3280                                       {
3281                                           maxColumnWidth[_HANDLER_LIST_NAME_COLUMN] =
3282                                               handlerString.size();
3283                                       }
3284                                       if (destination.size() >
3285                                           maxColumnWidth[_HANDLER_LIST_DESTINATION_COLUMN])
3286                                       {
3287                                           maxColumnWidth[_HANDLER_LIST_DESTINATION_COLUMN] =
3288                                               destination.size();
3289                                       }
3290                                   }
3291                               }
3292 w.otsuka     1.1          }
3293                       }
3294                   }
3295                   
3296                   //
3297                   //  print a verbose list of Handlers
3298                   //
3299                   void CIMSubCommand::_printHandlersVerbose(
3300                       const Array<CIMInstance>& instancesFound,
3301                       const Array<Uint32>& handlerTypesFound,
3302                       const Array <ListColumnEntry>& listOutputTable,
3303                       ostream& outPrintWriter)
3304                   {
3305                       Uint32 maxEntries = listOutputTable[_HANDLER_LIST_NAME_COLUMN].size();
3306                       Array <Uint32> indexes;
3307                       for (Uint32 i = 0; i < maxEntries; i++)
3308                       {
3309                          indexes.append (i);
3310                       }
3311                       _bubbleIndexSort (listOutputTable[_HANDLER_LIST_NAME_COLUMN], 0, indexes);
3312                       for (Uint32 i = 0; i < maxEntries; i++)
3313 w.otsuka     1.1      {
3314                           Uint32 pos;
3315                           CIMInstance handlerInstance = instancesFound[indexes[i]];
3316                           outPrintWriter << "Handler:           " <<
3317                              (listOutputTable[_HANDLER_LIST_NAME_COLUMN])[indexes[i]] << endl;
3318                           switch (handlerTypesFound[indexes[i]])
3319                           {
3320                               case _HANDLER_SNMP:
3321                               {
3322 kumpf        1.5                  String targetHost;
3323 w.otsuka     1.1                  pos = handlerInstance.findProperty(
3324                                       PEGASUS_PROPERTYNAME_LSTNRDST_TARGETHOST);
3325                                   if (pos != PEG_NOT_FOUND)
3326                                   {
3327                                       handlerInstance.getProperty(pos).getValue().get
3328                                           (targetHost);
3329                                   }
3330                                   outPrintWriter << "TargetHost:        " << targetHost
3331                                       << endl;
3332                                   outPrintWriter << "SNMPVersion:       " <<
3333                                       _getSnmpVersion(handlerInstance) << endl;
3334                                   break;
3335                               }
3336                   
3337                               case _HANDLER_EMAIL:
3338                               {
3339                                   String mailCc;
3340                                   String mailTo;
3341                                   String mailSubject;
3342                                   _getEmailInfo(handlerInstance, mailCc,
3343                                       mailTo, mailSubject );
3344 w.otsuka     1.1                  outPrintWriter << "MailTo:            " <<
3345                                       mailTo << endl;
3346                                   if (mailCc.size() > 0 )
3347                                   {
3348                                       outPrintWriter << "MailCc:            " <<
3349                                           mailCc << endl;
3350                                   }
3351                                   if (mailSubject.size() > 0 )
3352                                   {
3353                                       outPrintWriter << "MailSubject:       " <<
3354                                           mailSubject << endl;
3355                                   }
3356                                   break;
3357                               }
3358                   
3359                               case _HANDLER_SYSLOG:
3360                               {
3361                                   break;
3362                               }
3363                   
3364                               case _HANDLER_CIMXML:
3365 w.otsuka     1.1              {
3366                                   outPrintWriter << "Destination:       " <<
3367 karl         1.7                      (listOutputTable[_HANDLER_LIST_DESTINATION_COLUMN])
3368                                           [indexes[i]]
3369 w.otsuka     1.1                      << endl;
3370                               }
3371                           }
3372                           outPrintWriter << "PersistenceType:   " <<
3373                               _getPersistenceType(handlerInstance) << endl;
3374                           outPrintWriter << "-----------------------------------------"
3375                               << endl;
3376                       }
3377                   }
3378                   
3379                   //
3380                   //  get a list of all filters in the specified namespace(s)
3381                   //
3382                   void CIMSubCommand::_listFilters(
3383                       const String& filterName,
3384                       const Boolean verbose,
3385                       const Array<CIMNamespaceName>& namespaceNames,
3386                       ostream& outPrintWriter,
3387                       ostream& errPrintWriter)
3388                   {
3389                       Array <Uint32> maxColumnWidth;
3390 w.otsuka     1.1      Array <ListColumnEntry> listOutputTable;
3391                       Array<String> filtersFound;
3392                       Array<String> querysFound;
3393                       Array<String> queryLangsFound;
3394 ajay.rao     1.16     Array<String> filterSourceNamespaces;
3395 w.otsuka     1.1      const String filterTitle = "FILTER";
3396                       const String queryTitle = "QUERY";
3397                       if (!verbose)
3398                       {
3399                           filtersFound.append(filterTitle);
3400                           maxColumnWidth.append(filterTitle.size());
3401                           querysFound.append(queryTitle);
3402                           maxColumnWidth.append(queryTitle.size());
3403                       }
3404                       listOutputTable.append(filtersFound);
3405                       listOutputTable.append(querysFound);
3406                   
3407                       //  Find filters in namespaces
3408 ajay.rao     1.18     if (_isBatchNamespace )
3409                       {
3410                            _getFilterList(
3411                                filterName,
3412                                _batchNamespace,
3413                                verbose,
3414                                maxColumnWidth,
3415                                listOutputTable,
3416                                queryLangsFound,
3417                                filterSourceNamespaces,
3418                                outPrintWriter,
3419                                errPrintWriter);
3420                       }
3421                       else
3422 w.otsuka     1.1      {
3423 ajay.rao     1.18        for (Uint32 i = 0 ; i < namespaceNames.size(); i++)
3424                          {
3425 ajay.rao     1.16         _getFilterList(
3426                                filterName,
3427                                namespaceNames[i],
3428                                verbose,
3429                                maxColumnWidth,
3430                                listOutputTable,
3431                                queryLangsFound,
3432                                filterSourceNamespaces,
3433                                outPrintWriter,
3434                                errPrintWriter);
3435 ajay.rao     1.18        }
3436 w.otsuka     1.1      }
3437                       if (verbose)
3438                       {
3439                           if (listOutputTable[_FILTER_LIST_NAME_COLUMN].size() > 0)
3440                           {
3441 ajay.rao     1.16            _printFiltersVerbose(
3442                                   listOutputTable,
3443                                   queryLangsFound,
3444                                   filterSourceNamespaces,
3445                                   outPrintWriter);
3446 w.otsuka     1.1          }
3447                       }
3448                       else
3449                       {
3450                           if (listOutputTable[_FILTER_LIST_NAME_COLUMN].size() > 1)
3451                           {
3452                               _printColumns(maxColumnWidth, listOutputTable, outPrintWriter);
3453                           }
3454                       }
3455                   }
3456                   
3457                   //
3458                   //  get a list of all filters in the specified namespace(s)
3459                   //
3460                   void CIMSubCommand::_printFiltersVerbose(
3461                       const Array <ListColumnEntry>& listOutputTable,
3462                       const Array <String>& queryLangs,
3463 ajay.rao     1.16     const Array<String>& filterSourceNamespaces,
3464 w.otsuka     1.1      ostream& outPrintWriter)
3465                   {
3466                       Uint32 maxEntries = listOutputTable[_FILTER_LIST_NAME_COLUMN].size();
3467                       Array <Uint32> indexes;
3468                       for (Uint32 i = 0; i < maxEntries; i++)
3469                       {
3470                          indexes.append(i);
3471                       }
3472                       _bubbleIndexSort (listOutputTable[_FILTER_LIST_NAME_COLUMN], 0, indexes);
3473                       for (Uint32 i = 0; i < maxEntries; i++)
3474                       {
3475                           outPrintWriter << "Filter:           " <<
3476                               (listOutputTable[_FILTER_LIST_NAME_COLUMN])[indexes[i]] << endl;
3477                           outPrintWriter << "Query:            " <<
3478                               (listOutputTable[_FILTER_LIST_QUERY_COLUMN])[indexes[i]] << endl;
3479                           outPrintWriter << "Query Language:   " <<
3480                               queryLangs[indexes[i]] << endl;
3481 ajay.rao     1.16         outPrintWriter << "Source Namespace: ";
3482                           for (Uint32 j = 0; j < filterSourceNamespaces.size(); j++)
3483                           {
3484                               if ( j < filterSourceNamespaces.size() - 1)
3485                               {
3486                                   outPrintWriter<< filterSourceNamespaces[j]<<",";
3487                               }
3488                               else
3489                               {
3490                                   outPrintWriter<< filterSourceNamespaces[j]<<endl;
3491                               }
3492                           }
3493 w.otsuka     1.1          outPrintWriter <<
3494                               "-----------------------------------------" << endl;
3495 ajay.rao     1.16    }
3496 w.otsuka     1.1  }
3497                   
3498                   //
3499                   //  get a list of all filters in the specified namespace
3500                   //
3501                   void CIMSubCommand::_getFilterList(
3502                       const String& filterName,
3503                       const CIMNamespaceName& filterNamespace,
3504                       const Boolean verbose,
3505                       Array <Uint32>& maxColumnWidth,
3506                       Array <ListColumnEntry>& listOutputTable,
3507                       Array <String>& queryLangsFound,
3508 ajay.rao     1.16     Array<String>& filterSourceNamespaces,
3509 w.otsuka     1.1      ostream& outPrintWriter,
3510                       ostream& errPrintWriter)
3511                   {
3512                       Array<CIMObjectPath> filterPaths;
3513                       try
3514                       {
3515                           filterPaths = _client->enumerateInstanceNames(
3516                               filterNamespace,
3517                               PEGASUS_CLASSNAME_INDFILTER);
3518                       }
3519                       catch(CIMException& e)
3520                       {
3521                           if (e.getCode() == CIM_ERR_INVALID_CLASS)
3522                           {
3523                               return;
3524                           }
3525                           else
3526                           {
3527                               throw;
3528                           }
3529                       }
3530 w.otsuka     1.1  
3531                       Uint32 filterCount = filterPaths.size();
3532                       if (filterCount > 0)
3533                       {
3534                           CIMObjectPath filterPath;
3535                           String filterNameValue;
3536                   
3537                           // List all the indication filters
3538                           for (Uint32 i = 0; i < filterCount; i++)
3539                           {
3540                               Boolean isMatch = true;
3541                               CIMObjectPath fPath = filterPaths[i];
3542                               Array<CIMKeyBinding> keys = fPath.getKeyBindings();
3543                               for(Uint32 j=0; j < keys.size(); j++)
3544                               {
3545                                   if(keys[j].getName().equal(PEGASUS_PROPERTYNAME_NAME))
3546                                   {
3547                                       filterNameValue = keys[j].getValue();
3548                                       filterPath = fPath;
3549                                       if (filterName != String::EMPTY)
3550                                       {
3551 w.otsuka     1.1                          if (filterNameValue == filterName)
3552                                           {
3553                                               break;
3554                                           }
3555                                           else
3556                                           {
3557                                               isMatch = false;
3558                                               break;
3559                                           }
3560                                       }
3561                                       else
3562                                       {
3563                                           break;
3564                                       }
3565                                   }
3566                               }
3567                               if (isMatch)
3568                               {
3569                                   String queryString,queryLanguageString;
3570                                   String filterString = filterNamespace.getString();
3571 ajay.rao     1.16                 String sourceNamespaceString = filterNamespace.getString();
3572 w.otsuka     1.1                  filterString.append(DELIMITER_NAMESPACE);
3573                                   filterString.append(filterNameValue);
3574 ajay.rao     1.16                 _getFilterInfo(
3575                                        filterNamespace,
3576                                        filterPath,
3577                                        queryString,
3578                                        queryLanguageString,
3579                                        filterSourceNamespaces);
3580 w.otsuka     1.1                  listOutputTable[_FILTER_LIST_NAME_COLUMN].append(filterString);
3581                                   listOutputTable[_FILTER_LIST_QUERY_COLUMN].append(queryString);
3582                                   if (verbose)
3583                                   {
3584                                       queryLangsFound.append(queryLanguageString);
3585                                   }
3586                                   else
3587                                   {
3588                                       if (filterString.size () >
3589                                           maxColumnWidth[_FILTER_LIST_NAME_COLUMN])
3590                                       {
3591                                           maxColumnWidth[_FILTER_LIST_NAME_COLUMN] =
3592                                               filterString.size();
3593                                       }
3594                                       if (queryString.size() >
3595                                           maxColumnWidth[_FILTER_LIST_QUERY_COLUMN])
3596                                       {
3597                                           maxColumnWidth[_FILTER_LIST_QUERY_COLUMN] =
3598                                               queryString.size();
3599                                       }
3600                                   }
3601 w.otsuka     1.1             }
3602                           }
3603                       }
3604                   }
3605                   
3606                   //
3607                   //  get the query string for a filter
3608                   //
3609 ajay.rao     1.16 void CIMSubCommand::_getFilterInfo(
3610 w.otsuka     1.1      const CIMNamespaceName& filterNamespace,
3611                       const CIMObjectPath& filterPath,
3612                       String& queryString,
3613 ajay.rao     1.16     String& queryLangString,
3614                       Array<String>& filterSourceNamespaces)
3615 w.otsuka     1.1  {
3616                       String query;
3617 ajay.rao     1.16     String filterSourceNamespace;
3618 w.otsuka     1.1      queryString = "\"";
3619                       CIMInstance filterInstance = _client->getInstance(
3620                           filterNamespace, filterPath);
3621                       Uint32 pos = filterInstance.findProperty(
3622                           PEGASUS_PROPERTYNAME_QUERY);
3623                       if (pos != PEG_NOT_FOUND)
3624                       {
3625                           filterInstance.getProperty(pos).getValue().get(query);
3626                           queryString.append(query);
3627                       }
3628                       queryString.append("\"");
3629                       pos = filterInstance.findProperty(
3630                           PEGASUS_PROPERTYNAME_QUERYLANGUAGE);
3631                       if (pos != PEG_NOT_FOUND)
3632                       {
3633                           filterInstance.getProperty(pos).getValue().get(queryLangString);
3634                       }
3635 ajay.rao     1.16     pos = filterInstance.findProperty(
3636                           CIMNameCast("SourceNamespace"));
3637                       if (pos != PEG_NOT_FOUND)
3638                       {
3639                           filterInstance.getProperty(pos).getValue().get(filterSourceNamespace);
3640                           filterSourceNamespaces.append(filterSourceNamespace);
3641                       }
3642                       pos = filterInstance.findProperty(
3643                                 CIMNameCast("SourceNamespaces"));
3644                       if (pos != PEG_NOT_FOUND)
3645                       {
3646                           filterSourceNamespaces.clear();
3647                           filterInstance.getProperty(pos).getValue().get(
3648                                 filterSourceNamespaces);
3649                       }
3650                       if (filterSourceNamespaces.size() == 0)
3651                       {
3652                           filterSourceNamespaces.append(filterSourceNamespace);
3653                       }
3654 w.otsuka     1.1  }
3655                   
3656                   //
3657                   //  list  all subscriptions is the specified namespace(s)
3658                   //
3659                   void CIMSubCommand::_listSubscriptions(
3660                       const Array<CIMNamespaceName>& namespaceNames,
3661                       const String& filterName,
3662                       const CIMNamespaceName& filterNamespace,
3663                       const String& handlerName,
3664                       const CIMNamespaceName& handlerNamespace,
3665                       const String& handlerCreationClass,
3666                       const Boolean verbose,
3667                       ostream& outPrintWriter,
3668                       ostream& errPrintWriter)
3669                   {
3670                       Array <Uint32> maxColumnWidth;
3671                       Array <ListColumnEntry> listOutputTable;
3672                       Array<String> namespacesFound;
3673                       Array<String> filtersFound;
3674                       Array<String> handlersFound;
3675 w.otsuka     1.1      Array<String> statesFound;
3676                       Array<CIMInstance> handlerInstancesFound;
3677                       Array<Uint32> handlerTypesFound;
3678                       Array<String> querysFound;
3679                       const String namespaceTitle = "NAMESPACE";
3680                       const String filterTitle = "FILTER";
3681                       const String handlerTitle = "HANDLER";
3682                       const String stateTitle = "STATE";
3683                       if (!verbose)
3684                       {
3685                           namespacesFound.append(namespaceTitle);
3686                           maxColumnWidth.append(namespaceTitle.size());
3687                           filtersFound.append(filterTitle);
3688                           maxColumnWidth.append(filterTitle.size());
3689                           handlersFound.append(handlerTitle);
3690                           maxColumnWidth.append(handlerTitle.size());
3691                           statesFound.append(stateTitle);
3692                           maxColumnWidth.append(stateTitle.size());
3693                       }
3694                   
3695                       listOutputTable.append(namespacesFound);
3696 w.otsuka     1.1      listOutputTable.append(filtersFound);
3697                       listOutputTable.append(handlersFound);
3698                       listOutputTable.append(statesFound);
3699 ajay.rao     1.18     if (_isBatchNamespace)
3700                       {
3701                           _getSubscriptionList(
3702                                _batchNamespace,
3703                                filterName,
3704                                _batchNamespace,
3705                                handlerName,
3706                                _batchNamespace,
3707                                handlerCreationClass,
3708                                verbose,
3709                                handlerInstancesFound,
3710                                handlerTypesFound,
3711                                querysFound,
3712                                maxColumnWidth,
3713                                listOutputTable);
3714                       }
3715                       else
3716 w.otsuka     1.1      {
3717 ajay.rao     1.18         for (Uint32 i = 0 ; i < namespaceNames.size() ; i++)
3718                           {
3719                               _getSubscriptionList(
3720                                   namespaceNames[i],
3721                                   filterName,
3722                                   filterNamespace,
3723                                   handlerName,
3724                                   handlerNamespace,
3725                                   handlerCreationClass,
3726                                   verbose,
3727                                   handlerInstancesFound,
3728                                   handlerTypesFound,
3729                                   querysFound,
3730                                   maxColumnWidth,
3731                                   listOutputTable);
3732                           }
3733 w.otsuka     1.1      }
3734                   
3735                       if (verbose)
3736                       {
3737                           if (listOutputTable[_SUBSCRIPTION_LIST_NS_COLUMN].size() > 0)
3738                           {
3739                               _printSubscriptionsVerbose(handlerInstancesFound,
3740                                  handlerTypesFound, querysFound, listOutputTable,
3741                                  outPrintWriter);
3742                           }
3743                       }
3744                       else
3745                       {
3746                           if (listOutputTable[_SUBSCRIPTION_LIST_NS_COLUMN].size() > 1)
3747                           {
3748                               _printColumns(maxColumnWidth, listOutputTable, outPrintWriter);
3749                           }
3750                       }
3751                   }
3752                   
3753                   //
3754 w.otsuka     1.1  //  get a list of subscriptions in the specifed namespace
3755                   //
3756                   void CIMSubCommand::_getSubscriptionList(
3757                       const CIMNamespaceName& subscriptionNSIn,
3758                       const String& filterName,
3759                       const CIMNamespaceName& filterNSIn,
3760                       const String& handlerName,
3761                       const CIMNamespaceName& handlerNSIn,
3762                       const String& handlerCCIn,
3763                       const Boolean verbose,
3764                       Array<CIMInstance>& handlerInstancesFound,
3765                       Array<Uint32>& handlerTypesFound,
3766                       Array<String>& querysFound,
3767                       Array <Uint32>& maxColumnWidth,
3768                       Array <ListColumnEntry>& listOutputTable
3769                   )
3770                   {
3771                       Array<CIMObjectPath> subscriptionPaths;
3772                       String query;
3773                       String destination;
3774                       CIMNamespaceName filterNamespace;
3775 w.otsuka     1.1      CIMNamespaceName handlerNamespace;
3776                       CIMNamespaceName subscriptionNamespace = _DEFAULT_SUBSCRIPTION_NAMESPACE;
3777 ouyang.jian  1.11     String handlerCreationClass;
3778 w.otsuka     1.1      if (!subscriptionNSIn.isNull())
3779                       {
3780                           subscriptionNamespace = subscriptionNSIn;
3781                       }
3782                       if (!filterNSIn.isNull())
3783                       {
3784                           filterNamespace = filterNSIn;
3785                       }
3786                   
3787                       if (!handlerNSIn.isNull())
3788                       {
3789                           handlerNamespace = handlerNSIn;
3790                       }
3791                   
3792                       if (handlerCCIn != String::EMPTY)
3793                       {
3794                           handlerCreationClass = handlerCCIn;
3795                       }
3796                   
3797                       try
3798                       {
3799 w.otsuka     1.1          subscriptionPaths = _client->enumerateInstanceNames(
3800                               subscriptionNamespace,
3801                               PEGASUS_CLASSNAME_INDSUBSCRIPTION);
3802                       }
3803                       catch(CIMException& e)
3804                       {
3805                           if (e.getCode() == CIM_ERR_INVALID_CLASS)
3806                           {
3807                               return;
3808                           }
3809                           else
3810                           {
3811                               throw;
3812                           }
3813                       }
3814                       Uint32 subscriptionCount = subscriptionPaths.size();
3815                       if (subscriptionCount > 0)
3816                       {
3817                           String handlerNameString, filterNameString;
3818                           CIMObjectPath handlerPath, filterPath;
3819                           CIMNamespaceName handlerNS, filterNS;
3820 w.otsuka     1.1          // List all the indication subscriptions
3821                           for (Uint32 i = 0; i < subscriptionCount; i++)
3822                           {
3823                               CIMObjectPath subPath = subscriptionPaths[i];
3824                               CIMObjectPath filterRef, handlerRef;
3825                               Boolean filterMatch = true;
3826                               Boolean handlerMatch = true;
3827                               String creationClassName;
3828                   
3829                               //
3830                               //  Get the subscription Filter
3831                               //
3832                               filterMatch = _filterMatches(subPath, subscriptionNamespace,
3833                                   filterName, filterNamespace, filterNS, filterRef);
3834                               if (filterMatch)
3835                               {
3836                                   filterNameString = _getNameInKey(filterRef);
3837                                   handlerMatch = _handlerMatches(subPath, subscriptionNamespace,
3838                                       handlerName, handlerNamespace, handlerCreationClass,
3839                                       handlerNS, handlerRef);
3840                                   if (handlerMatch)
3841 w.otsuka     1.1                  {
3842                                       handlerNameString = _getNameInKey(handlerRef);
3843                                   }
3844                               }
3845                               if ((filterMatch) && (handlerMatch))
3846                               {
3847                                   // Get the destination for this handler.
3848                                   CIMInstance handlerInstance = _client->getInstance(
3849                                       handlerNS, handlerRef);
3850                                   Uint32 handlerType;
3851                                   _getHandlerDestination(handlerInstance, creationClassName,
3852                                       handlerType, destination);
3853                                   String handlerString = handlerNS.getString();
3854                                   handlerString.append(DELIMITER_NAMESPACE);
3855                                   handlerString.append(creationClassName);
3856                                   handlerString.append(DELIMITER_HANDLER_CLASS);
3857                                   handlerString.append(handlerNameString);
3858                                   String statusValue = _getSubscriptionState(
3859                                       subscriptionNamespace, subPath);
3860                   
3861                                   // Save for columnar listing
3862 w.otsuka     1.1                  listOutputTable[_SUBSCRIPTION_LIST_NS_COLUMN].append
3863                                       (subscriptionNamespace.getString());
3864                                   String filterString = filterNS.getString();
3865                                   filterString.append(DELIMITER_NAMESPACE);
3866                                   filterString.append(filterNameString);
3867                                   listOutputTable[_SUBSCRIPTION_LIST_FILTER_COLUMN].append
3868                                       (filterString);
3869                                   listOutputTable[_SUBSCRIPTION_LIST_HANDLER_COLUMN].append
3870                                       (handlerString);
3871                                   listOutputTable[_SUBSCRIPTION_LIST_STATE_COLUMN].append
3872                                       (statusValue);
3873                                   if (verbose)
3874                                   {
3875 ajay.rao     1.16                     String queryString, queryLangString, sourceNamespace;
3876                                       Array <String> sourceNamespaces;
3877 w.otsuka     1.1                      handlerInstancesFound.append (handlerInstance);
3878                                       handlerTypesFound.append (handlerType);
3879 ajay.rao     1.16                     _getFilterInfo(filterNS, filterRef, queryString,
3880                                          queryLangString,sourceNamespaces);
3881 w.otsuka     1.1                      querysFound.append(queryString);
3882                                   }
3883                                   else
3884                                   {
3885                                       if (subscriptionNamespace.getString().size() >
3886                                           maxColumnWidth[_SUBSCRIPTION_LIST_NS_COLUMN])
3887                                       {
3888                                           maxColumnWidth[_SUBSCRIPTION_LIST_NS_COLUMN] =
3889                                               subscriptionNamespace.getString().size();
3890                                       }
3891                                       if (filterString.size() >
3892                                           maxColumnWidth[_SUBSCRIPTION_LIST_FILTER_COLUMN])
3893                                       {
3894                                           maxColumnWidth[_SUBSCRIPTION_LIST_FILTER_COLUMN] =
3895                                               filterString.size();
3896                                       }
3897                                       if (handlerString.size() >
3898                                           maxColumnWidth[_SUBSCRIPTION_LIST_HANDLER_COLUMN])
3899                                       {
3900                                           maxColumnWidth[_SUBSCRIPTION_LIST_HANDLER_COLUMN] =
3901                                               handlerString.size();
3902 w.otsuka     1.1                      }
3903                                       if (statusValue.size() >
3904                                           maxColumnWidth[_SUBSCRIPTION_LIST_STATE_COLUMN])
3905                                       {
3906                                           maxColumnWidth[_SUBSCRIPTION_LIST_STATE_COLUMN] =
3907                                               statusValue.size();
3908                                       }
3909                                   }
3910                               }
3911                           }
3912                       }
3913                   }
3914                   
3915                   //
3916                   //  get the handler destination and type
3917                   //
3918                   void CIMSubCommand::_getHandlerDestination(
3919                       const CIMInstance& handlerInstance,
3920                       String& creationClassName,
3921                       Uint32&  handlerTypeFound,
3922                       String& destination)
3923 w.otsuka     1.1  {
3924                       Uint32 pos;
3925                       pos = handlerInstance.findProperty(
3926                           PEGASUS_PROPERTYNAME_CREATIONCLASSNAME);
3927                       if (pos != PEG_NOT_FOUND)
3928                       {
3929                           handlerInstance.getProperty(pos).getValue().get
3930                               (creationClassName);
3931                       }
3932                       handlerTypeFound = _HANDLER_CIMXML;
3933                       destination = String::EMPTY;
3934                       if (handlerInstance.getClassName() ==
3935                           PEGASUS_CLASSNAME_INDHANDLER_SNMP)
3936                       {
3937                           handlerTypeFound = _HANDLER_SNMP;
3938 kumpf        1.5          String targetHost;
3939 w.otsuka     1.1          pos = handlerInstance.findProperty(
3940                               PEGASUS_PROPERTYNAME_LSTNRDST_TARGETHOST);
3941                           if (pos != PEG_NOT_FOUND)
3942                           {
3943                               handlerInstance.getProperty(pos).getValue().get
3944                                   (targetHost);
3945                           }
3946                           destination = targetHost;
3947                       }
3948                       else
3949                       {
3950                           if (handlerInstance.getClassName() ==
3951                               PEGASUS_CLASSNAME_LSTNRDST_EMAIL)
3952                           {
3953                               handlerTypeFound = _HANDLER_EMAIL;
3954                               Array <String> mailTo;
3955                               pos = handlerInstance.findProperty
3956                                   (PEGASUS_PROPERTYNAME_LSTNRDST_MAILTO);
3957                               if (pos != PEG_NOT_FOUND)
3958                               {
3959                                   handlerInstance.getProperty(pos).getValue().get
3960 w.otsuka     1.1                      (mailTo);
3961                               }
3962                               for (Uint32 eIndex=0; eIndex < mailTo.size();
3963                                   eIndex++)
3964                               {
3965                                   destination.append (mailTo[eIndex]);
3966                                   destination.append (" ");
3967                               }
3968                            }
3969                           else
3970                           {
3971                               if (creationClassName ==
3972                                   PEGASUS_CLASSNAME_LSTNRDST_SYSTEM_LOG)
3973                               {
3974                                   handlerTypeFound = _HANDLER_SYSLOG;
3975                               }
3976                               else
3977                               {
3978                                   pos = handlerInstance.findProperty(
3979                                       PEGASUS_PROPERTYNAME_LSTNRDST_DESTINATION);
3980                                   if (pos != PEG_NOT_FOUND)
3981 w.otsuka     1.1                  {
3982                                       handlerInstance.getProperty (pos).getValue ().get
3983                                           (destination);
3984                                    }
3985                               }
3986                           }
3987                       }
3988                   }
3989                   
3990                   //
3991                   //  print a verbose list of subscriptions
3992                   //
3993                   void CIMSubCommand::_printSubscriptionsVerbose(
3994                       const Array<CIMInstance>& handlerInstancesFound,
3995                       const Array<Uint32>& handlerTypesFound,
3996                       const Array<String>& querysFound,
3997                       const Array<ListColumnEntry>& listOutputTable,
3998                       ostream& outPrintWriter)
3999                   {
4000                       Uint32 maxEntries = listOutputTable[_SUBSCRIPTION_LIST_NS_COLUMN].size();
4001                       Array <Uint32> indexes;
4002 w.otsuka     1.1      for (Uint32 i = 0; i < maxEntries; i++)
4003                       {
4004                          indexes.append (i);
4005                       }
4006 kumpf        1.14     _bubbleIndexSort(listOutputTable[_SUBSCRIPTION_LIST_HANDLER_COLUMN], 0,
4007 karl         1.7              indexes);
4008 kumpf        1.14     _bubbleIndexSort(listOutputTable[_SUBSCRIPTION_LIST_FILTER_COLUMN], 0,
4009 karl         1.7              indexes);
4010 w.otsuka     1.1      _bubbleIndexSort(listOutputTable[_SUBSCRIPTION_LIST_NS_COLUMN], 0, indexes);
4011                       for (Uint32 i = 0; i < maxEntries; i++)
4012                       {
4013                           outPrintWriter << "Namespace:         " <<
4014                               (listOutputTable[_SUBSCRIPTION_LIST_NS_COLUMN])[indexes[i]] << endl;
4015                           outPrintWriter << "Filter:            " <<
4016 kumpf        1.14             (listOutputTable[_SUBSCRIPTION_LIST_FILTER_COLUMN])[indexes[i]]
4017 karl         1.7              << endl;
4018 w.otsuka     1.1          outPrintWriter << "Handler:           " <<
4019 kumpf        1.14             (listOutputTable[_SUBSCRIPTION_LIST_HANDLER_COLUMN])[indexes[i]]
4020 karl         1.7              << endl;
4021 w.otsuka     1.1          outPrintWriter << "Query:             " << querysFound[indexes[i]]
4022                                   << endl;
4023                           CIMInstance handlerInstance = handlerInstancesFound[indexes[i]];
4024                           switch (handlerTypesFound[indexes[i]])
4025                           {
4026                               case _HANDLER_SNMP:
4027                               {
4028 kumpf        1.5                  String targetHost;
4029 w.otsuka     1.1                  Uint32 pos = handlerInstance.findProperty(
4030                                       PEGASUS_PROPERTYNAME_LSTNRDST_TARGETHOST);
4031                                   if (pos != PEG_NOT_FOUND)
4032                                   {
4033                                       handlerInstance.getProperty(pos).getValue().get
4034                                           (targetHost);
4035                                   }
4036                                   outPrintWriter << "TargetHost:        " << targetHost
4037                                       << endl;
4038                                   outPrintWriter << "SNMPVersion:       " <<
4039                                       _getSnmpVersion(handlerInstance) << endl;
4040                                   break;
4041                               }
4042                               case _HANDLER_EMAIL:
4043                               {
4044                                   String mailCc;
4045                                   String mailTo;
4046                                   String mailSubject;
4047                                   _getEmailInfo(handlerInstance, mailCc,
4048                                       mailTo, mailSubject );
4049                                   outPrintWriter << "MailTo:            " <<
4050 w.otsuka     1.1                      mailTo << endl;
4051                                   if (mailCc.size() > 0 )
4052                                   {
4053                                       outPrintWriter << "MailCc:            " <<
4054                                           mailCc << endl;
4055                                   }
4056                                   if (mailSubject.size() > 0 )
4057                                   {
4058                                       outPrintWriter << "MailSubject:       " <<
4059                                           mailSubject << endl;
4060                                   }
4061                                   break;
4062                               }
4063                               case _HANDLER_SYSLOG:
4064                               {
4065                                   break;
4066                               }
4067                               case _HANDLER_CIMXML:
4068                               {
4069 kumpf        1.5                  String destination;
4070 w.otsuka     1.1                  Uint32 pos = handlerInstance.findProperty(
4071                                       PEGASUS_PROPERTYNAME_LSTNRDST_DESTINATION);
4072                                   if (pos != PEG_NOT_FOUND)
4073                                   {
4074                                       handlerInstance.getProperty(pos).getValue().get
4075                                           (destination);
4076                                   }
4077                                   outPrintWriter << "Destination:       " << destination << endl;
4078                               }
4079                           }
4080                           outPrintWriter << "SubscriptionState: " <<
4081                               (listOutputTable[_SUBSCRIPTION_LIST_STATE_COLUMN])[indexes[i]] <<
4082                               endl;
4083                           outPrintWriter <<
4084                               "-----------------------------------------" << endl;
4085                       }
4086                   }
4087                   
4088                   //
4089                   //  check a subscription for a filter match
4090                   //
4091 w.otsuka     1.1  Boolean CIMSubCommand::_filterMatches(
4092                       const CIMObjectPath& subPath,
4093                       const CIMNamespaceName& subscriptionNS,
4094                       const String& filterName,
4095                       const CIMNamespaceName& filterNamespace,
4096                       CIMNamespaceName& filterNS,
4097                       CIMObjectPath& filterRef)
4098                   {
4099                       Boolean filterMatch = false;
4100                       String filterNameString;
4101                   
4102                       //
4103                       //  Get the subscription Filter
4104                       //
4105                       Array<CIMKeyBinding> keys = subPath.getKeyBindings();
4106                       for( Uint32 j=0; j < keys.size(); j++)
4107                       {
4108                           if (keys[j].getName().equal(PEGASUS_PROPERTYNAME_FILTER))
4109                           {
4110                               filterRef = keys[j].getValue();
4111                           }
4112 w.otsuka     1.1      }
4113                   
4114                       filterNameString = _getNameInKey(filterRef);
4115                       CIMNamespaceName instanceNS = filterRef.getNameSpace();
4116                       if (filterName != String::EMPTY)
4117                       {
4118                           if (filterNameString == filterName)
4119                           {
4120 ajay.rao     1.16             if (!filterNamespace.isNull())
4121 w.otsuka     1.1              {
4122                                   //
4123                                   //  If the Filter reference property value includes
4124                                   //  namespace, check if it is the namespace of the Filter.
4125                                   //  If the Filter reference property value does not
4126                                   //  include namespace, check if the current subscription
4127                                   //  namespace is the namespace of the Filter.
4128                                   //
4129 ajay.rao     1.16                 if(instanceNS.isNull()
4130                                       || filterNamespace == instanceNS)
4131 w.otsuka     1.1                  {
4132 ajay.rao     1.16                     filterNS = filterNamespace;
4133 w.otsuka     1.1                      filterMatch = true;
4134                                   }
4135                               }
4136                               else
4137                               {
4138                                   // No namespace was specified and the filter name matches
4139                                   filterMatch = true;
4140                                   if (instanceNS.isNull())
4141                                   {
4142                                       filterNS = subscriptionNS;
4143                                   }
4144                                   else
4145                                   {
4146                                       filterNS = instanceNS;
4147                                   }
4148                               }
4149                           }
4150                           else
4151                           {
4152                               // The filter name does not match
4153                               filterMatch = false;
4154 w.otsuka     1.1          }
4155                       }
4156                       else
4157                       {
4158                           filterMatch = true;
4159                           // No filter name was specified.
4160                           // Use the filter namespace if specified in the reference.
4161                           //
4162                           if (instanceNS.isNull())
4163                           {
4164                               filterNS = subscriptionNS;
4165                           }
4166                           else
4167                           {
4168                               filterNS = instanceNS;
4169                           }
4170                       }
4171                       return filterMatch;
4172                   }
4173                   
4174                   //
4175 w.otsuka     1.1  //  check a subscription for a handler match
4176                   //
4177                   Boolean CIMSubCommand::_handlerMatches(
4178                       const CIMObjectPath& subPath,
4179                       const CIMNamespaceName& subscriptionNS,
4180                       const String& handlerName,
4181                       const CIMNamespaceName& handlerNamespace,
4182                       const String& handlerCreationClass,
4183                       CIMNamespaceName& handlerNS,
4184                       CIMObjectPath& handlerRef)
4185                   {
4186                       Boolean handlerMatch = false;
4187                       String handlerNameString;
4188                       String creationClassName;
4189                   
4190                       //
4191                       //  Get the subscription Handler
4192                       //
4193                       Array<CIMKeyBinding> keys = subPath.getKeyBindings();
4194                       for( Uint32 j=0; j < keys.size(); j++)
4195                       {
4196 w.otsuka     1.1          if (keys[j].getName().equal(PEGASUS_PROPERTYNAME_HANDLER))
4197                           {
4198                               handlerRef = keys[j].getValue();
4199                           }
4200                       }
4201                       handlerNameString = _getNameInKey(handlerRef);
4202                       if (handlerName != String::EMPTY)
4203                       {
4204                           CIMNamespaceName instanceNS = handlerRef.getNameSpace();
4205                           if (handlerNameString == handlerName)
4206                           {
4207 ajay.rao     1.16             if (!handlerNamespace.isNull())
4208 w.otsuka     1.1              {
4209                                   //
4210                                   //  If the Handler reference property value includes
4211                                   //  namespace, check if it is the namespace of the Handler.
4212                                   //  If the Handler reference property value does not
4213                                   //  include namespace, check if the current subscription
4214                                   //  namespace is the namespace of the Handler.
4215                                   //
4216 ajay.rao     1.16                 if(instanceNS.isNull()
4217                                       || handlerNamespace == instanceNS)
4218 w.otsuka     1.1                  {
4219 ajay.rao     1.16                     handlerNS = handlerNamespace;
4220 w.otsuka     1.1                      handlerMatch = true;
4221                                   }
4222                               }
4223                               else
4224                               {
4225                                   // Handler namespace is not set and handler name matches
4226                                   handlerMatch = true;
4227                                   if (instanceNS.isNull())
4228                                   {
4229                                       handlerNS = subscriptionNS;
4230                                   }
4231                                   else
4232                                   {
4233                                       handlerNS = instanceNS;
4234                                   }
4235                               }
4236                           }
4237                           else
4238                           {
4239                               // Handler name does not match
4240                               handlerMatch = false;
4241 w.otsuka     1.1          }
4242                           if (handlerMatch)
4243                           {
4244                               if(handlerCreationClass != String::EMPTY)
4245                               {
4246                                   CIMInstance handlerInstance = _client->getInstance(
4247                                       handlerNS, handlerRef);
4248                                   Uint32 pos = handlerInstance.findProperty(
4249                                       PEGASUS_PROPERTYNAME_CREATIONCLASSNAME);
4250                                   if (pos != PEG_NOT_FOUND)
4251                                   {
4252                                       handlerInstance.getProperty(pos).getValue().get
4253                                           (creationClassName);
4254                                   }
4255                                   if (handlerCreationClass != creationClassName)
4256                                   {
4257                                       handlerMatch = false;
4258                                   }
4259                               }
4260                           }
4261                       }
4262 w.otsuka     1.1      else
4263                       {
4264                           handlerMatch = true;
4265                           //
4266                           // The handler was not specified.
4267                           // Use the handler namespace if specified in the reference.
4268                           //
4269                           CIMNamespaceName instanceNS = handlerRef.getNameSpace();
4270                           if (!instanceNS.isNull())
4271                           {
4272                               handlerNS = instanceNS;
4273                           }
4274                           else
4275                           {
4276                               handlerNS = subscriptionNS;
4277                           }
4278                       }
4279                       return handlerMatch;
4280                   }
4281                   
4282                   //
4283 w.otsuka     1.1  //  Get the subscription state string from a subscription instance
4284                   //
4285                   void CIMSubCommand::_getEmailInfo(
4286                       const CIMInstance& handlerInstance,
4287                       String& ccString,
4288                       String& toString,
4289                       String& subjectString)
4290                   {
4291                       Array <String> mailCc, mailTo;
4292                       subjectString = String::EMPTY;
4293                       mailTo.append(String::EMPTY);
4294 kumpf        1.14     Uint32 pos =
4295 karl         1.7          handlerInstance.findProperty(PEGASUS_PROPERTYNAME_LSTNRDST_MAILTO);
4296 w.otsuka     1.1      if( pos != PEG_NOT_FOUND)
4297                       {
4298                           handlerInstance.getProperty(pos).getValue().get(mailTo);
4299                       }
4300                       for (Uint32 eIndex=0; eIndex < mailTo.size();
4301                           eIndex++)
4302                       {
4303                           toString.append(mailTo[eIndex]);
4304                           toString.append(" ");
4305                       }
4306                       pos = handlerInstance.findProperty(PEGASUS_PROPERTYNAME_LSTNRDST_MAILCC);
4307                       if (pos != PEG_NOT_FOUND)
4308                       {
4309                           handlerInstance.getProperty(pos).getValue().get(mailCc);
4310                       }
4311                       if (mailCc.size() > 0)
4312                       {
4313                           for (Uint32 eIndex=0; eIndex < mailCc.size();
4314                               eIndex++)
4315                           {
4316                               ccString.append (mailCc[eIndex]);
4317 w.otsuka     1.1              ccString.append (" ");
4318                           }
4319                       }
4320 karl         1.7      pos = handlerInstance.findProperty(
4321                               PEGASUS_PROPERTYNAME_LSTNRDST_MAILSUBJECT);
4322 w.otsuka     1.1      if (pos != PEG_NOT_FOUND)
4323                       {
4324                           handlerInstance.getProperty(pos).getValue().get(subjectString);
4325                       }
4326                   }
4327                   
4328                   //
4329                   //  Get the persistence value from the handler instance
4330                   //
4331                   String CIMSubCommand::_getPersistenceType(const CIMInstance& handlerInstance)
4332                   {
4333                       Uint16 persistenceType = 1;
4334 kumpf        1.14     Uint32 pos =
4335 karl         1.7          handlerInstance.findProperty(PEGASUS_PROPERTYNAME_PERSISTENCETYPE);
4336 w.otsuka     1.1      if (pos != PEG_NOT_FOUND)
4337                       {
4338                           handlerInstance.getProperty(pos).getValue().get(persistenceType);
4339                       }
4340                       String persistenceString;
4341                       switch (persistenceType)
4342                       {
4343                           case PERSISTENCE_OTHER:
4344                           {
4345                               persistenceString = _PERSISTENTENCE_OTHER_STRING;
4346                               break;
4347                           }
4348                           case PERSISTENCE_PERMANENT:
4349                           {
4350                               persistenceString = _PERSISTENTENCE_PERMANENT_STRING;
4351                               break;
4352                           }
4353                           case PERSISTENCE_TRANSIENT:
4354                           {
4355                               persistenceString = _PERSISTENTENCE_TRANSIENT_STRING;
4356                               break;
4357 w.otsuka     1.1          }
4358                           default:
4359                               persistenceString = _PERSISTENTENCE_UNKNOWN_STRING;
4360                         }
4361                         return persistenceString;
4362                   }
4363                   
4364                   //
4365                   //    Get the subscription state string from a subscription instance
4366                   //
4367                   String CIMSubCommand::_getSubscriptionState(
4368                       const CIMNamespaceName& subscriptionNamespace,
4369                       const CIMObjectPath& subPath)
4370                   {
4371                       CIMInstance subInstance = _client->getInstance(subscriptionNamespace,
4372                           subPath);
4373 karl         1.7      Uint32 pos = subInstance.findProperty(
4374                               PEGASUS_PROPERTYNAME_SUBSCRIPTION_STATE);
4375 w.otsuka     1.1      Uint16 subscriptionState = STATE_UNKNOWN;
4376                       if (pos != PEG_NOT_FOUND)
4377                       {
4378                           if (!subInstance.getProperty(pos).getValue().isNull() )
4379                           {
4380                               subInstance.getProperty(pos).getValue().get(subscriptionState);
4381                           }
4382                       }
4383                       String statusString;
4384                       switch (subscriptionState)
4385                       {
4386                           case STATE_UNKNOWN:
4387                           {
4388                               statusString = _SUBSCRIPTION_STATE_UNKNOWN_STRING;
4389                               break;
4390                           }
4391                           case STATE_OTHER:
4392                           {
4393                               statusString = _SUBSCRIPTION_STATE_UNKNOWN_STRING;
4394                               break;
4395                           }
4396 w.otsuka     1.1          case STATE_ENABLED:
4397                           {
4398                               statusString = _SUBSCRIPTION_STATE_ENABLED_STRING;
4399                               break;
4400                           }
4401                           case STATE_ENABLEDDEGRADED:
4402                           {
4403                               statusString = _SUBSCRIPTION_STATE_ENABLED_DEGRADED_STRING;
4404                               break;
4405                           }
4406                           case STATE_DISABLED:
4407                           {
4408                               statusString = _SUBSCRIPTION_STATE_DISABLED_STRING;
4409                               break;
4410                           }
4411                           default:
4412                               statusString = _SUBSCRIPTION_STATE_NOT_SUPPORTED_STRING;
4413                       }
4414                       return statusString;
4415                   }
4416                   
4417 w.otsuka     1.1  //
4418                   //  Get the SNMP version string from a handler instance
4419                   //
4420                   String CIMSubCommand::_getSnmpVersion (const CIMInstance& handlerInstance)
4421                   {
4422                       Uint16 snmpVersion = 0;
4423                       Uint32 pos = handlerInstance.findProperty(PEGASUS_PROPERTYNAME_SNMPVERSION);
4424                       if (pos != PEG_NOT_FOUND)
4425                       {
4426                           if (!handlerInstance.getProperty(pos).getValue().isNull() )
4427                           {
4428                               handlerInstance.getProperty(pos).getValue().get(snmpVersion);
4429                           }
4430                       }
4431                   
4432                       String snmpVersionString;
4433                       switch (snmpVersion)
4434                       {
4435                           case SNMPV1_TRAP:
4436                               snmpVersionString = _SNMP_VERSION_SNMPV1_TRAP_STRING;
4437                               break;
4438 w.otsuka     1.1          case SNMPV2C_TRAP:
4439                               snmpVersionString = _SNMP_VERSION_SNMPV2C_TRAP_STRING;
4440                               break;
4441                           default:
4442                               snmpVersionString = _SNMP_VERSION_PEGASUS_RESERVED_STRING;
4443                       }
4444                       return snmpVersionString;
4445                   }
4446                   
4447                   //
4448                   //    print data in a columnar form
4449                   //
4450                   void CIMSubCommand::_printColumns(
4451                       const Array <Uint32>& maxColumnWidth,
4452                       const Array <ListColumnEntry>& listOutputTable,
4453                       ostream& outPrintWriter)
4454                   {
4455                       Uint32 maxColumns = maxColumnWidth.size();
4456                       Uint32 maxEntries = listOutputTable[0].size();
4457                       Array <Uint32> indexes;
4458                       for (Uint32 i = 0; i < maxEntries; i++)
4459 w.otsuka     1.1      {
4460                          indexes.append(i);
4461                       }
4462                       for (int column = maxColumns-1; column >= 0; column--)
4463                       {
4464                         _bubbleIndexSort(listOutputTable[column], 1, indexes);
4465                       }
4466                       for (Uint32 i = 0; i < maxEntries; i++)
4467                       {
4468                           for (Uint32 column = 0; column < maxColumns-1; column++)
4469                           {
4470 kumpf        1.14             Uint32 outputItemSize =
4471 karl         1.7                  (listOutputTable[column])[indexes[i]].size();
4472 w.otsuka     1.1              Uint32 fillerLen = maxColumnWidth[column] + TITLE_SEPERATOR_LEN -
4473                                   outputItemSize;
4474                               outPrintWriter << (listOutputTable[column])[indexes[i]];
4475                               for (Uint32 j = 0; j < fillerLen; j++)
4476                               {
4477                                   outPrintWriter << ' ';
4478                               }
4479                           }
4480                           outPrintWriter << (listOutputTable[maxColumns-1])[indexes[i]] << endl;
4481                       }
4482                   }
4483                   
4484                   //
4485                   //    Sort a string array by indexes
4486                   //
4487                   void CIMSubCommand::_bubbleIndexSort(
4488                       const Array<String>& x,
4489                       const Uint32 startIndex,
4490                       Array<Uint32>& index)
4491                   {
4492                       Uint32 n = x.size();
4493 w.otsuka     1.1  
4494                       if (n < 3)
4495                           return;
4496                   
4497                       for (Uint32 i = startIndex; i < (n-1); i++)
4498                       {
4499                           for (Uint32 j = startIndex; j < (n-1); j++)
4500                           {
4501                               if (String::compareNoCase(x[index[j]],
4502                                                         x[index[j+1]]) > 0)
4503                               {
4504                                   Uint32 t = index[j];
4505                                   index[j] = index[j+1];
4506                                   index[j+1] = t;
4507                               }
4508                           }
4509                       }
4510                   }
4511                   
4512                   PEGASUS_NAMESPACE_END
4513                   
4514 w.otsuka     1.1  //
4515                   // exclude main from the Pegasus Namespace
4516                   //
4517                   PEGASUS_USING_PEGASUS;
4518                   
4519                   PEGASUS_USING_STD;
4520                   
4521                   ///////////////////////////////////////////////////////////////////////////////
4522                   /**
4523                       Parses the command line, and execute the command.
4524                   
4525                       @param   args  the string array containing the command line arguments
4526                   */
4527                   ///////////////////////////////////////////////////////////////////////////////
4528                   
4529                   int main (int argc, char* argv[])
4530                   {
4531                       AutoPtr<CIMSubCommand> command;
4532                       Uint32 retCode;
4533                   
4534 ajay.rao     1.16 #ifdef PEGASUS_OS_PASE
4535                       Uint32 ret = 0;
4536                       ret = umeCheckCmdAuthorities(COMMAND_NAME, true);
4537                       if (ret)
4538                       {
4539                           return Command::RC_ERROR;
4540                       }
4541                   #endif
4542 thilo.boehm  1.9  #ifdef PEGASUS_OS_ZOS
4543                       // for z/OS set stdout and stderr to EBCDIC
4544                       setEBCDICEncoding(STDOUT_FILENO);
4545                       setEBCDICEncoding(STDERR_FILENO);
4546                   #endif
4547                   
4548 w.otsuka     1.1      MessageLoader::_useProcessLocale = true;
4549                       MessageLoader::setPegasusMsgHomeRelative(argv[0]);
4550                   
4551                       command.reset(new CIMSubCommand());
4552                       try
4553                       {
4554                           command->setCommand (cout, cerr, argc, argv);
4555                       }
4556                       catch (CommandFormatException& cfe)
4557                       {
4558 runfang.zhou 1.8          cerr << COMMAND_NAME << ": " << cfe.getMessage() << endl;
4559 w.otsuka     1.1  
4560 runfang.zhou 1.8          MessageLoaderParms parms(ERR_USAGE_KEY,ERR_USAGE);
4561                           parms.msg_src_path = MSG_PATH;
4562                           cerr << COMMAND_NAME <<
4563                               ": " << MessageLoader::getMessage(parms) << endl;
4564 kumpf        1.14 
4565 w.otsuka     1.1          exit (Command::RC_ERROR);
4566                       }
4567                       retCode = command->execute(cout, cerr);
4568                       return (retCode);
4569                   }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2