(file) Return to CIMClientRep.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Client

   1 karl  1.3 //%2003////////////////////////////////////////////////////////////////////////
   2 kumpf 1.1 //
   3 karl  1.3 // Copyright (c) 2000, 2001, 2002  BMC Software, Hewlett-Packard Development
   4           // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
   5           // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
   6           // IBM Corp.; EMC Corporation, The Open Group.
   7 kumpf 1.1 //
   8           // Permission is hereby granted, free of charge, to any person obtaining a copy
   9           // of this software and associated documentation files (the "Software"), to
  10           // deal in the Software without restriction, including without limitation the
  11           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  12           // sell copies of the Software, and to permit persons to whom the Software is
  13           // furnished to do so, subject to the following conditions:
  14           // 
  15           // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
  16           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
  17           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
  18           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  19           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  20           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  21           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23           //
  24           //==============================================================================
  25           //
  26           // Author: Jair Santos, Hewlett-Packard Company (jair.santos@hp.com)
  27           //
  28 dj.gorey 1.9 // Modified By:  Dan Gorey (djgorey@us.ibm.com)
  29 a.arora  1.11 //               Amit Arora (amita@in.ibm.com) for Bug#1170
  30 marek    1.12 //				 Marek Szermutzky (MSzermutzky@de.ibm.com) for PEP#139 Stage1
  31 kumpf    1.1  //
  32               //%/////////////////////////////////////////////////////////////////////////////
  33               
  34               #include "CIMClientRep.h"
  35               
  36               // l10n
  37               #include <Pegasus/Common/MessageLoader.h>
  38               
  39               #include <iostream>
  40               #include <fstream>
  41               #ifdef PEGASUS_PLATFORM_WIN32_IX86_MSVC
  42               # include <windows.h>
  43               #else
  44               # include <netinet/in.h>
  45               # include <arpa/inet.h>
  46               # include <sys/socket.h>
  47               #endif
  48               
  49               PEGASUS_USING_STD;
  50               
  51               PEGASUS_NAMESPACE_BEGIN
  52 kumpf    1.1  
  53               ///////////////////////////////////////////////////////////////////////////////
  54               //
  55               // CIMClientRep
  56               //
  57               ///////////////////////////////////////////////////////////////////////////////
  58               static Boolean verifyServerCertificate(SSLCertificateInfo &certInfo)
  59               {
  60                   //ATTN-NB-03-05132002: Add code to handle server certificate verification.
  61                   return true;
  62               }
  63               
  64               CIMClientRep::CIMClientRep(Uint32 timeoutMilliseconds)
  65                   :
  66                   MessageQueue(PEGASUS_QUEUENAME_CLIENT),
  67                   _httpConnection(0),
  68                   _timeoutMilliseconds(timeoutMilliseconds),
  69                   _connected(false),
  70                   _responseDecoder(0),
  71                   _requestEncoder(0),
  72                   _connectSSLContext(0)
  73 kumpf    1.1  {
  74                   //
  75                   // Create Monitor and HTTPConnector
  76                   //
  77 dj.gorey 1.10     #ifdef PEGASUS_USE_23HTTPMONITOR_CLIENT
  78 kumpf    1.1      _monitor = new Monitor();
  79                   _httpConnector = new HTTPConnector(_monitor);
  80 dj.gorey 1.9      #else
  81                   _monitor = new monitor_2();
  82                   _httpConnector = new HTTPConnector2(_monitor);
  83                   #endif
  84 kumpf    1.1  
  85               // l10n
  86                   requestAcceptLanguages = AcceptLanguages::EMPTY;
  87                   requestContentLanguages = ContentLanguages::EMPTY;
  88               }
  89               
  90               CIMClientRep::~CIMClientRep()
  91               {
  92                  disconnect();
  93                  delete _httpConnector;
  94                  delete _monitor;
  95               }
  96               
  97               void CIMClientRep::handleEnqueue()
  98               {
  99               
 100               }
 101               
 102               Uint32 _getShowType(String& s)
 103               {
 104                   String log = "log";
 105 kumpf    1.1      String con = "con";
 106                   String both = "both";
 107                   if (s == log)
 108 tony     1.7          return 2;
 109                   if (s == con)
 110 karl     1.6          return 1;
 111 kumpf    1.1      if (s == both)
 112 karl     1.6          return 3;
 113 kumpf    1.1      return 0;
 114               }
 115               
 116               void CIMClientRep::_connect()
 117               {
 118                   //
 119                   // Test for Display optons of the form
 120                   // Use Env variable PEGASUS_CLIENT_TRACE= <intrace> : <outtrace
 121                   // intrace = "con" | "log" | "both"
 122                   // outtrace = intrace
 123                   // ex set PEGASUS_CLIENT_TRACE=BOTH:BOTH traces input and output
 124                   // to console and log
 125                   // Keywords are case insensitive.
 126                   // PEP 90
 127                   //
 128                   Uint32 showOutput = 0;
 129                   Uint32 showInput = 0;
 130               #ifdef PEGASUS_CLIENT_TRACE_ENABLE
 131                   String input;
 132                   if (char * envVar = getenv("PEGASUS_CLIENT_TRACE"))
 133                   {
 134 kumpf    1.1          input = envVar;
 135                       input.toLower();
 136                       String io = String::EMPTY;
 137                       Uint32 pos = input.find(':');
 138                       if (pos == PEG_NOT_FOUND)
 139                           pos = 0;
 140                       else
 141                           io = input.subString(0,pos);
 142               
 143 tony     1.5          // some compilers do not allow temporaries to be passed to a
 144                       // reference argument - so break into 2 lines
 145                       String out = input.subString(pos + 1);
 146                       showOutput = _getShowType(out);
 147 kumpf    1.1  
 148                       showInput = _getShowType(io);
 149                   }
 150               #endif
 151               
 152                   //
 153                   // Create response decoder:
 154                   //
 155                   _responseDecoder = new CIMOperationResponseDecoder(
 156                       this, _requestEncoder, &_authenticator, showInput);
 157               
 158                   //
 159                   // Attempt to establish a connection:
 160                   //
 161                   try
 162                   {
 163 dj.gorey 1.10         #ifdef PEGASUS_USE_23HTTPMONITOR_CLIENT
 164 kumpf    1.1          _httpConnection = _httpConnector->connect(_connectHost,
 165                                                                 _connectPortNumber,
 166                                                                 _connectSSLContext,
 167                                                                 _responseDecoder);
 168 dj.gorey 1.9          #else
 169                       _httpConnection = _httpConnector->connect(_connectHost,
 170                                                                 _connectPortNumber,
 171                                                                 _responseDecoder);
 172 a.arora  1.11         _monitor->set_session_dispatch(_httpConnection->connection_dispatch);
 173 dj.gorey 1.9          #endif
 174                       
 175 kumpf    1.1      }
 176                   catch (CannotCreateSocketException& e)
 177                   {
 178                       delete _responseDecoder;
 179                       throw e;
 180                   }
 181                   catch (CannotConnectException& e)
 182                   {
 183                       delete _responseDecoder;
 184                       throw e;
 185                   }
 186                   catch (InvalidLocatorException& e)
 187                   {
 188                       delete _responseDecoder;
 189                       throw e;
 190                   }
 191               
 192                   //
 193                   // Create request encoder:
 194                   //
 195                   _requestEncoder = new CIMOperationRequestEncoder(
 196 kumpf    1.1          _httpConnection, &_authenticator, showOutput);
 197               
 198                   _responseDecoder->setEncoderQueue(_requestEncoder);
 199               
 200                   _connected = true;
 201               }
 202               
 203 kumpf    1.8  void CIMClientRep::_disconnect()
 204               {
 205                   if (_connected)
 206                   {
 207                       //
 208                       // destroy response decoder
 209                       //
 210                       if (_responseDecoder)
 211                       {
 212                           delete _responseDecoder;
 213                           _responseDecoder = 0;
 214                       }
 215               
 216                       //
 217                       // Close the connection
 218                       //
 219                       if (_httpConnector)
 220                       {
 221                           _httpConnector->disconnect(_httpConnection);
 222                           delete _httpConnection;
 223                           _httpConnection = 0;
 224 kumpf    1.8          }
 225               
 226                       //
 227                       // destroy request encoder
 228                       //
 229                       if (_requestEncoder)
 230                       {
 231                           delete _requestEncoder;
 232                           _requestEncoder = 0;
 233                       }
 234               
 235                       if (_connectSSLContext)
 236                       {
 237                           delete _connectSSLContext;
 238                           _connectSSLContext = 0;
 239                       }
 240               
 241                       _connected = false;
 242                   }
 243               }
 244               
 245 kumpf    1.1  void CIMClientRep::_reconnect()
 246               {
 247 kumpf    1.8      _disconnect();
 248                   _authenticator.setRequestMessage(0);
 249 kumpf    1.1      _connect();
 250               }
 251               
 252               void CIMClientRep::connect(
 253                   const String& host,
 254                   const Uint32 portNumber,
 255                   const String& userName,
 256                   const String& password
 257               )
 258               {
 259                   //
 260                   // If already connected, bail out!
 261                   //
 262                   if (_connected)
 263                       throw AlreadyConnectedException();
 264               
 265                   //
 266                   // If the host is empty, set hostName to "localhost"
 267                   //
 268                   String hostName = host;
 269                   if (host == String::EMPTY)
 270 kumpf    1.1      {
 271                       hostName = "localhost";
 272                   }
 273               
 274                   //
 275                   // Set authentication information
 276                   //
 277 kumpf    1.8      _authenticator.clear();
 278 kumpf    1.1  
 279                   if (userName.size())
 280                   {
 281                       _authenticator.setUserName(userName);
 282                   }
 283               
 284                   if (password.size())
 285                   {
 286                       _authenticator.setPassword(password);
 287                   }
 288               
 289                   _connectSSLContext = 0;
 290                   _connectHost = hostName;
 291                   _connectPortNumber = portNumber;
 292               
 293                   _connect();
 294               }
 295               
 296               
 297               void CIMClientRep::connect(
 298                   const String& host,
 299 kumpf    1.1      const Uint32 portNumber,
 300                   const SSLContext& sslContext,
 301                   const String& userName,
 302                   const String& password
 303               )
 304               {
 305                   //
 306                   // If already connected, bail out!
 307                   //
 308                   if (_connected)
 309                       throw AlreadyConnectedException();
 310               
 311                   //
 312                   // If the host is empty, set hostName to "localhost"
 313                   //
 314                   String hostName = host;
 315                   if (host == String::EMPTY)
 316                   {
 317                       hostName = "localhost";
 318                   }
 319               
 320 kumpf    1.1      //
 321                   // Set authentication information
 322                   //
 323 kumpf    1.8      _authenticator.clear();
 324 kumpf    1.1  
 325                   if (userName.size())
 326                   {
 327                       _authenticator.setUserName(userName);
 328                   }
 329               
 330                   if (password.size())
 331                   {
 332                       _authenticator.setPassword(password);
 333                   }
 334               
 335                   _connectSSLContext = new SSLContext(sslContext);
 336                   _connectHost = hostName;
 337                   _connectPortNumber = portNumber;
 338               
 339               
 340                   try
 341                   {
 342                       _connect();
 343                   }
 344                   catch (Exception&)
 345 kumpf    1.1      {
 346                       delete _connectSSLContext;
 347                       _connectSSLContext = 0;
 348                       throw;
 349                   }
 350               }
 351               
 352               
 353               void CIMClientRep::connectLocal()
 354               {
 355                   //
 356                   // If already connected, bail out!
 357                   //
 358                   if (_connected)
 359                       throw AlreadyConnectedException();
 360               
 361                   //
 362                   // Set authentication type
 363                   //
 364 kumpf    1.8      _authenticator.clear();
 365 kumpf    1.1      _authenticator.setAuthType(ClientAuthenticator::LOCAL);
 366               
 367               #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
 368                   _connect();
 369               #else
 370               
 371                   try
 372                   {
 373                       //
 374                       // Look up the WBEM HTTP port number for the local system
 375                       //
 376                       _connectPortNumber = System::lookupPort (WBEM_HTTP_SERVICE_NAME,
 377                           WBEM_DEFAULT_HTTP_PORT);
 378               
 379                       //
 380                       //  Assign host
 381                       //
 382                       _connectHost.assign(_getLocalHostName());
 383               
 384                       _connectSSLContext = 0;
 385               
 386 kumpf    1.1          _connect();
 387                   }
 388                   catch(CannotConnectException &e)
 389                   {
 390                       //
 391                       // Look up the WBEM HTTPS port number for the local system
 392                       //
 393                       _connectPortNumber = System::lookupPort (WBEM_HTTPS_SERVICE_NAME,
 394                           WBEM_DEFAULT_HTTPS_PORT);
 395               
 396                       //
 397                       //  Assign host
 398                       //
 399                       _connectHost.assign(_getLocalHostName());
 400               
 401                       //
 402                       // Create SSLContext
 403                       //
 404               #ifdef PEGASUS_OS_OS400
 405               #pragma convert(37)
 406                       const char* env = getenv("PEGASUS_HOME");
 407 kumpf    1.1  #pragma convert(0)
 408                       char pegasusHome[256] = {0};
 409                       if (env != NULL && strlen(env) < 256)
 410                       {
 411                           strcpy(pegasusHome, env);
 412                           EtoA(pegasusHome);
 413                       }
 414               #else
 415                       const char* pegasusHome = getenv("PEGASUS_HOME");
 416               #endif
 417               
 418                       String certpath = FileSystem::getAbsolutePath(
 419                           pegasusHome, PEGASUS_SSLCLIENT_CERTIFICATEFILE);
 420               
 421                       String randFile = String::EMPTY;
 422               
 423               #ifdef PEGASUS_SSL_RANDOMFILE
 424                       randFile = FileSystem::getAbsolutePath(
 425                           pegasusHome, PEGASUS_SSLCLIENT_RANDOMFILE);
 426               #endif
 427               
 428 kumpf    1.1          try
 429                       {
 430                           _connectSSLContext =
 431                               new SSLContext(certpath, verifyServerCertificate, randFile);
 432                       }
 433                       catch (SSLException &se)
 434                       {
 435                           throw se;
 436                       }
 437               
 438                       try
 439                       {
 440                           _connect();
 441                       }
 442                       catch (Exception&)
 443                       {
 444                           delete _connectSSLContext;
 445                           _connectSSLContext = 0;
 446                           throw;
 447                       }
 448                   }
 449 kumpf    1.1  #endif
 450               }
 451               
 452               
 453               void CIMClientRep::disconnect()
 454               {
 455 kumpf    1.8      _disconnect();
 456                   _authenticator.clear();
 457               }
 458 kumpf    1.1  
 459               
 460               // l10n start
 461               AcceptLanguages CIMClientRep::getRequestAcceptLanguages() const
 462               {
 463                   return requestAcceptLanguages;
 464               }
 465               
 466               ContentLanguages CIMClientRep::getRequestContentLanguages() const
 467               {
 468                   return requestContentLanguages;
 469               }
 470               
 471               ContentLanguages CIMClientRep::getResponseContentLanguages() const
 472               {
 473                   return responseContentLanguages;
 474               }
 475               
 476               void CIMClientRep::setRequestAcceptLanguages(AcceptLanguages& langs)
 477               {
 478                   requestAcceptLanguages = langs;
 479 kumpf    1.1  }
 480               
 481               void CIMClientRep::setRequestContentLanguages(ContentLanguages& langs)
 482               {
 483                   requestContentLanguages = langs;
 484               }
 485               
 486               void CIMClientRep::setRequestDefaultLanguages()
 487               {
 488                   requestAcceptLanguages = AcceptLanguages::getDefaultAcceptLanguages();
 489               }
 490               
 491               // l10n end
 492               
 493               CIMClass CIMClientRep::getClass(
 494                   const CIMNamespaceName& nameSpace,
 495                   const CIMName& className,
 496                   Boolean localOnly,
 497                   Boolean includeQualifiers,
 498                   Boolean includeClassOrigin,
 499                   const CIMPropertyList& propertyList
 500 kumpf    1.1  )
 501               {
 502                   CIMRequestMessage* request = new CIMGetClassRequestMessage(
 503                       String::EMPTY,
 504                       nameSpace,
 505                       className,
 506                       localOnly,
 507                       includeQualifiers,
 508                       includeClassOrigin,
 509                       propertyList,
 510                       QueueIdStack());
 511               
 512                   Message* message = _doRequest(request, CIM_GET_CLASS_RESPONSE_MESSAGE);
 513               
 514                   CIMGetClassResponseMessage* response =
 515                       (CIMGetClassResponseMessage*)message;
 516               
 517                   Destroyer<CIMGetClassResponseMessage> destroyer(response);
 518               
 519                   return(response->cimClass);
 520               }
 521 kumpf    1.1  
 522               CIMInstance CIMClientRep::getInstance(
 523                   const CIMNamespaceName& nameSpace,
 524                   const CIMObjectPath& instanceName,
 525                   Boolean localOnly,
 526                   Boolean includeQualifiers,
 527                   Boolean includeClassOrigin,
 528                   const CIMPropertyList& propertyList
 529               )
 530               {
 531 marek    1.12 	compareObjectPathtoCurrentConnection(instanceName);
 532               
 533 kumpf    1.1      CIMRequestMessage* request = new CIMGetInstanceRequestMessage(
 534                       String::EMPTY,
 535                       nameSpace,
 536                       instanceName,
 537                       localOnly,
 538                       includeQualifiers,
 539                       includeClassOrigin,
 540                       propertyList,
 541                       QueueIdStack());
 542               
 543                   Message* message = _doRequest(request, CIM_GET_INSTANCE_RESPONSE_MESSAGE);
 544               
 545                   CIMGetInstanceResponseMessage* response =
 546                       (CIMGetInstanceResponseMessage*)message;
 547               
 548                   Destroyer<CIMGetInstanceResponseMessage> destroyer(response);
 549               
 550                   return(response->cimInstance);
 551               }
 552               
 553               void CIMClientRep::deleteClass(
 554 kumpf    1.1      const CIMNamespaceName& nameSpace,
 555                   const CIMName& className
 556               )
 557               {
 558                   CIMRequestMessage* request = new CIMDeleteClassRequestMessage(
 559                       String::EMPTY,
 560                       nameSpace,
 561                       className,
 562                       QueueIdStack());
 563               
 564                   Message* message = _doRequest(request, CIM_DELETE_CLASS_RESPONSE_MESSAGE);
 565               
 566                   CIMDeleteClassResponseMessage* response =
 567                       (CIMDeleteClassResponseMessage*)message;
 568               
 569                   Destroyer<CIMDeleteClassResponseMessage> destroyer(response);
 570               }
 571               
 572               void CIMClientRep::deleteInstance(
 573                   const CIMNamespaceName& nameSpace,
 574                   const CIMObjectPath& instanceName
 575 kumpf    1.1  )
 576               {
 577 marek    1.12 	compareObjectPathtoCurrentConnection(instanceName);
 578 kumpf    1.1      CIMRequestMessage* request = new CIMDeleteInstanceRequestMessage(
 579                       String::EMPTY,
 580                       nameSpace,
 581                       instanceName,
 582                       QueueIdStack());
 583               
 584                   Message* message = _doRequest(request, CIM_DELETE_INSTANCE_RESPONSE_MESSAGE);
 585               
 586                   CIMDeleteInstanceResponseMessage* response =
 587                       (CIMDeleteInstanceResponseMessage*)message;
 588               
 589                   Destroyer<CIMDeleteInstanceResponseMessage> destroyer(response);
 590               }
 591               
 592               void CIMClientRep::createClass(
 593                   const CIMNamespaceName& nameSpace,
 594                   const CIMClass& newClass
 595               )
 596               {
 597                   CIMRequestMessage* request = new CIMCreateClassRequestMessage(
 598                       String::EMPTY,
 599 kumpf    1.1          nameSpace,
 600                       newClass,
 601                       QueueIdStack());
 602               
 603                   Message* message = _doRequest(request, CIM_CREATE_CLASS_RESPONSE_MESSAGE);
 604               
 605                   CIMCreateClassResponseMessage* response =
 606                       (CIMCreateClassResponseMessage*)message;
 607               
 608                   Destroyer<CIMCreateClassResponseMessage> destroyer(response);
 609               }
 610               
 611               CIMObjectPath CIMClientRep::createInstance(
 612                   const CIMNamespaceName& nameSpace,
 613                   const CIMInstance& newInstance
 614               )
 615               {
 616 marek    1.12 	compareObjectPathtoCurrentConnection(newInstance.getPath());
 617 kumpf    1.1      CIMRequestMessage* request = new CIMCreateInstanceRequestMessage(
 618                       String::EMPTY,
 619                       nameSpace,
 620                       newInstance,
 621                       QueueIdStack());
 622               
 623                   Message* message = _doRequest(request, CIM_CREATE_INSTANCE_RESPONSE_MESSAGE);
 624               
 625                   CIMCreateInstanceResponseMessage* response =
 626                       (CIMCreateInstanceResponseMessage*)message;
 627               
 628                   Destroyer<CIMCreateInstanceResponseMessage> destroyer(response);
 629               
 630                   return(response->instanceName);
 631               }
 632               
 633               void CIMClientRep::modifyClass(
 634                   const CIMNamespaceName& nameSpace,
 635                   const CIMClass& modifiedClass
 636               )
 637               {
 638 kumpf    1.1      CIMRequestMessage* request = new CIMModifyClassRequestMessage(
 639                       String::EMPTY,
 640                       nameSpace,
 641                       modifiedClass,
 642                       QueueIdStack());
 643               
 644                   Message* message = _doRequest(request, CIM_MODIFY_CLASS_RESPONSE_MESSAGE);
 645               
 646                   CIMModifyClassResponseMessage* response =
 647                       (CIMModifyClassResponseMessage*)message;
 648               
 649                   Destroyer<CIMModifyClassResponseMessage> destroyer(response);
 650               }
 651               
 652               void CIMClientRep::modifyInstance(
 653                   const CIMNamespaceName& nameSpace,
 654                   const CIMInstance& modifiedInstance,
 655                   Boolean includeQualifiers,
 656                   const CIMPropertyList& propertyList
 657               )
 658               {
 659 marek    1.12 	compareObjectPathtoCurrentConnection(modifiedInstance.getPath());
 660 kumpf    1.1      CIMRequestMessage* request = new CIMModifyInstanceRequestMessage(
 661                       String::EMPTY,
 662                       nameSpace,
 663                       modifiedInstance,
 664                       includeQualifiers,
 665                       propertyList,
 666                       QueueIdStack());
 667               
 668                   Message* message = _doRequest(request, CIM_MODIFY_INSTANCE_RESPONSE_MESSAGE);
 669               
 670                   CIMModifyInstanceResponseMessage* response =
 671                       (CIMModifyInstanceResponseMessage*)message;
 672               
 673                   Destroyer<CIMModifyInstanceResponseMessage> destroyer(response);
 674               }
 675               
 676               Array<CIMClass> CIMClientRep::enumerateClasses(
 677                   const CIMNamespaceName& nameSpace,
 678                   const CIMName& className,
 679                   Boolean deepInheritance,
 680                   Boolean localOnly,
 681 kumpf    1.1      Boolean includeQualifiers,
 682                   Boolean includeClassOrigin
 683               )
 684               {
 685                   CIMRequestMessage* request = new CIMEnumerateClassesRequestMessage(
 686                       String::EMPTY,
 687                       nameSpace,
 688                       className,
 689                       deepInheritance,
 690                       localOnly,
 691                       includeQualifiers,
 692                       includeClassOrigin,
 693                       QueueIdStack());
 694               
 695                   Message* message = _doRequest(request, CIM_ENUMERATE_CLASSES_RESPONSE_MESSAGE);
 696               
 697                   CIMEnumerateClassesResponseMessage* response =
 698                       (CIMEnumerateClassesResponseMessage*)message;
 699               
 700                   Destroyer<CIMEnumerateClassesResponseMessage> destroyer(response);
 701               
 702 kumpf    1.1      return(response->cimClasses);
 703               }
 704               
 705               Array<CIMName> CIMClientRep::enumerateClassNames(
 706                   const CIMNamespaceName& nameSpace,
 707                   const CIMName& className,
 708                   Boolean deepInheritance
 709               )
 710               {
 711                   CIMRequestMessage* request = new CIMEnumerateClassNamesRequestMessage(
 712                       String::EMPTY,
 713                       nameSpace,
 714                       className,
 715                       deepInheritance,
 716                       QueueIdStack());
 717               
 718                   Message* message = _doRequest(request, CIM_ENUMERATE_CLASS_NAMES_RESPONSE_MESSAGE);
 719               
 720                   CIMEnumerateClassNamesResponseMessage* response =
 721                       (CIMEnumerateClassNamesResponseMessage*)message;
 722               
 723 kumpf    1.1      Destroyer<CIMEnumerateClassNamesResponseMessage> destroyer(response);
 724               
 725                   // Temporary code until internal structures use CIMName instead of String
 726                   Array<CIMName> classNameArray;
 727                   classNameArray.reserveCapacity(response->classNames.size());
 728                   for (Uint32 i=0; i<response->classNames.size(); i++)
 729                   {
 730                       classNameArray.append(response->classNames[i]);
 731                   }
 732                   return(classNameArray);
 733               }
 734               
 735               Array<CIMInstance> CIMClientRep::enumerateInstances(
 736                   const CIMNamespaceName& nameSpace,
 737                   const CIMName& className,
 738                   Boolean deepInheritance,
 739                   Boolean localOnly,
 740                   Boolean includeQualifiers,
 741                   Boolean includeClassOrigin,
 742                   const CIMPropertyList& propertyList
 743               )
 744 kumpf    1.1  {
 745                   CIMRequestMessage* request = new CIMEnumerateInstancesRequestMessage(
 746                       String::EMPTY,
 747                       nameSpace,
 748                       className,
 749                       deepInheritance,
 750                       localOnly,
 751                       includeQualifiers,
 752                       includeClassOrigin,
 753                       propertyList,
 754                       QueueIdStack());
 755               
 756                   Message* message = _doRequest(request, CIM_ENUMERATE_INSTANCES_RESPONSE_MESSAGE);
 757               
 758                   CIMEnumerateInstancesResponseMessage* response =
 759                       (CIMEnumerateInstancesResponseMessage*)message;
 760               
 761                   Destroyer<CIMEnumerateInstancesResponseMessage> destroyer(response);
 762               
 763                   return(response->cimNamedInstances);
 764               }
 765 kumpf    1.1  
 766               Array<CIMObjectPath> CIMClientRep::enumerateInstanceNames(
 767                   const CIMNamespaceName& nameSpace,
 768                   const CIMName& className
 769               )
 770               {
 771                   CIMRequestMessage* request = new CIMEnumerateInstanceNamesRequestMessage(
 772                       String::EMPTY,
 773                       nameSpace,
 774                       className,
 775                       QueueIdStack());
 776               
 777                   Message* message = _doRequest(request, CIM_ENUMERATE_INSTANCE_NAMES_RESPONSE_MESSAGE);
 778               
 779                   CIMEnumerateInstanceNamesResponseMessage* response =
 780                       (CIMEnumerateInstanceNamesResponseMessage*)message;
 781               
 782                   Destroyer<CIMEnumerateInstanceNamesResponseMessage> destroyer(response);
 783               
 784                   return(response->instanceNames);
 785               }
 786 kumpf    1.1  
 787               Array<CIMObject> CIMClientRep::execQuery(
 788                   const CIMNamespaceName& nameSpace,
 789                   const String& queryLanguage,
 790                   const String& query
 791               )
 792               {
 793                   CIMRequestMessage* request = new CIMExecQueryRequestMessage(
 794                       String::EMPTY,
 795                       nameSpace,
 796                       queryLanguage,
 797                       query,
 798                       QueueIdStack());
 799               
 800                   Message* message = _doRequest(request, CIM_EXEC_QUERY_RESPONSE_MESSAGE);
 801               
 802                   CIMExecQueryResponseMessage* response =
 803                       (CIMExecQueryResponseMessage*)message;
 804               
 805                   Destroyer<CIMExecQueryResponseMessage> destroyer(response);
 806               
 807 kumpf    1.1      return(response->cimObjects);
 808               }
 809               
 810               Array<CIMObject> CIMClientRep::associators(
 811                   const CIMNamespaceName& nameSpace,
 812                   const CIMObjectPath& objectName,
 813                   const CIMName& assocClass,
 814                   const CIMName& resultClass,
 815                   const String& role,
 816                   const String& resultRole,
 817                   Boolean includeQualifiers,
 818                   Boolean includeClassOrigin,
 819                   const CIMPropertyList& propertyList
 820               )
 821               {
 822 marek    1.12 	compareObjectPathtoCurrentConnection(objectName);	
 823 kumpf    1.1      CIMRequestMessage* request = new CIMAssociatorsRequestMessage(
 824                       String::EMPTY,
 825                       nameSpace,
 826                       objectName,
 827                       assocClass,
 828                       resultClass,
 829                       role,
 830                       resultRole,
 831                       includeQualifiers,
 832                       includeClassOrigin,
 833                       propertyList,
 834                       QueueIdStack());
 835               
 836                   Message* message = _doRequest(request, CIM_ASSOCIATORS_RESPONSE_MESSAGE);
 837               
 838                   CIMAssociatorsResponseMessage* response =
 839                       (CIMAssociatorsResponseMessage*)message;
 840               
 841                   Destroyer<CIMAssociatorsResponseMessage> destroyer(response);
 842               
 843                   return(response->cimObjects);
 844 kumpf    1.1  }
 845               
 846               Array<CIMObjectPath> CIMClientRep::associatorNames(
 847                   const CIMNamespaceName& nameSpace,
 848                   const CIMObjectPath& objectName,
 849                   const CIMName& assocClass,
 850                   const CIMName& resultClass,
 851                   const String& role,
 852                   const String& resultRole
 853               )
 854               {
 855 marek    1.12 	compareObjectPathtoCurrentConnection(objectName);
 856 kumpf    1.1      CIMRequestMessage* request = new CIMAssociatorNamesRequestMessage(
 857                       String::EMPTY,
 858                       nameSpace,
 859                       objectName,
 860                       assocClass,
 861                       resultClass,
 862                       role,
 863                       resultRole,
 864                       QueueIdStack());
 865               
 866                   Message* message = _doRequest(request, CIM_ASSOCIATOR_NAMES_RESPONSE_MESSAGE);
 867               
 868                   CIMAssociatorNamesResponseMessage* response =
 869                       (CIMAssociatorNamesResponseMessage*)message;
 870               
 871                   Destroyer<CIMAssociatorNamesResponseMessage> destroyer(response);
 872               
 873                   return(response->objectNames);
 874               }
 875               
 876               Array<CIMObject> CIMClientRep::references(
 877 kumpf    1.1      const CIMNamespaceName& nameSpace,
 878                   const CIMObjectPath& objectName,
 879                   const CIMName& resultClass,
 880                   const String& role,
 881                   Boolean includeQualifiers,
 882                   Boolean includeClassOrigin,
 883                   const CIMPropertyList& propertyList
 884               )
 885               {
 886 marek    1.12 	compareObjectPathtoCurrentConnection(objectName);	
 887 kumpf    1.1      CIMRequestMessage* request = new CIMReferencesRequestMessage(
 888                       String::EMPTY,
 889                       nameSpace,
 890                       objectName,
 891                       resultClass,
 892                       role,
 893                       includeQualifiers,
 894                       includeClassOrigin,
 895                       propertyList,
 896                       QueueIdStack());
 897               
 898                   Message* message = _doRequest(request, CIM_REFERENCES_RESPONSE_MESSAGE);
 899               
 900                   CIMReferencesResponseMessage* response =
 901                       (CIMReferencesResponseMessage*)message;
 902               
 903                   Destroyer<CIMReferencesResponseMessage> destroyer(response);
 904               
 905                   return(response->cimObjects);
 906               }
 907               
 908 kumpf    1.1  Array<CIMObjectPath> CIMClientRep::referenceNames(
 909                   const CIMNamespaceName& nameSpace,
 910                   const CIMObjectPath& objectName,
 911                   const CIMName& resultClass,
 912                   const String& role
 913               )
 914               {
 915 marek    1.12 	compareObjectPathtoCurrentConnection(objectName);	
 916 kumpf    1.1      CIMRequestMessage* request = new CIMReferenceNamesRequestMessage(
 917                       String::EMPTY,
 918                       nameSpace,
 919                       objectName,
 920                       resultClass,
 921                       role,
 922                       QueueIdStack());
 923               
 924                   Message* message = _doRequest(request, CIM_REFERENCE_NAMES_RESPONSE_MESSAGE);
 925               
 926                   CIMReferenceNamesResponseMessage* response =
 927                       (CIMReferenceNamesResponseMessage*)message;
 928               
 929                   Destroyer<CIMReferenceNamesResponseMessage> destroyer(response);
 930               
 931                   return(response->objectNames);
 932               }
 933               
 934               CIMValue CIMClientRep::getProperty(
 935                   const CIMNamespaceName& nameSpace,
 936                   const CIMObjectPath& instanceName,
 937 kumpf    1.1      const CIMName& propertyName
 938               )
 939               {
 940 marek    1.12 	compareObjectPathtoCurrentConnection(instanceName);
 941 kumpf    1.1      CIMRequestMessage* request = new CIMGetPropertyRequestMessage(
 942                       String::EMPTY,
 943                       nameSpace,
 944                       instanceName,
 945                       propertyName,
 946                       QueueIdStack());
 947               
 948                   Message* message = _doRequest(request, CIM_GET_PROPERTY_RESPONSE_MESSAGE);
 949               
 950                   CIMGetPropertyResponseMessage* response =
 951                       (CIMGetPropertyResponseMessage*)message;
 952               
 953                   Destroyer<CIMGetPropertyResponseMessage> destroyer(response);
 954               
 955                   return(response->value);
 956               }
 957               
 958               void CIMClientRep::setProperty(
 959                   const CIMNamespaceName& nameSpace,
 960                   const CIMObjectPath& instanceName,
 961                   const CIMName& propertyName,
 962 kumpf    1.1      const CIMValue& newValue
 963               )
 964               {
 965 marek    1.12 	compareObjectPathtoCurrentConnection(instanceName);		
 966 kumpf    1.1      CIMRequestMessage* request = new CIMSetPropertyRequestMessage(
 967                       String::EMPTY,
 968                       nameSpace,
 969                       instanceName,
 970                       propertyName,
 971                       newValue,
 972                       QueueIdStack());
 973               
 974                   Message* message = _doRequest(request, CIM_SET_PROPERTY_RESPONSE_MESSAGE);
 975               
 976                   CIMSetPropertyResponseMessage* response =
 977                       (CIMSetPropertyResponseMessage*)message;
 978               
 979                   Destroyer<CIMSetPropertyResponseMessage> destroyer(response);
 980               }
 981               
 982               CIMQualifierDecl CIMClientRep::getQualifier(
 983                   const CIMNamespaceName& nameSpace,
 984                   const CIMName& qualifierName
 985               )
 986               {
 987 kumpf    1.1      CIMRequestMessage* request = new CIMGetQualifierRequestMessage(
 988                       String::EMPTY,
 989                       nameSpace,
 990                       qualifierName,
 991                       QueueIdStack());
 992               
 993                   Message* message = _doRequest(request, CIM_GET_QUALIFIER_RESPONSE_MESSAGE);
 994               
 995                   CIMGetQualifierResponseMessage* response =
 996                       (CIMGetQualifierResponseMessage*)message;
 997               
 998                   Destroyer<CIMGetQualifierResponseMessage> destroyer(response);
 999               
1000                   return(response->cimQualifierDecl);
1001               }
1002               
1003               void CIMClientRep::setQualifier(
1004                   const CIMNamespaceName& nameSpace,
1005                   const CIMQualifierDecl& qualifierDeclaration
1006               )
1007               {
1008 kumpf    1.1      CIMRequestMessage* request = new CIMSetQualifierRequestMessage(
1009                       String::EMPTY,
1010                       nameSpace,
1011                       qualifierDeclaration,
1012                       QueueIdStack());
1013               
1014                   Message* message = _doRequest(request, CIM_SET_QUALIFIER_RESPONSE_MESSAGE);
1015               
1016                   CIMSetQualifierResponseMessage* response =
1017                       (CIMSetQualifierResponseMessage*)message;
1018               
1019                   Destroyer<CIMSetQualifierResponseMessage> destroyer(response);
1020               }
1021               
1022               void CIMClientRep::deleteQualifier(
1023                   const CIMNamespaceName& nameSpace,
1024                   const CIMName& qualifierName
1025               )
1026               {
1027                   CIMRequestMessage* request = new CIMDeleteQualifierRequestMessage(
1028                       String::EMPTY,
1029 kumpf    1.1          nameSpace,
1030                       qualifierName,
1031                       QueueIdStack());
1032               
1033                   Message* message = _doRequest(request, CIM_DELETE_QUALIFIER_RESPONSE_MESSAGE);
1034               
1035                   CIMDeleteQualifierResponseMessage* response =
1036                       (CIMDeleteQualifierResponseMessage*)message;
1037               
1038                   Destroyer<CIMDeleteQualifierResponseMessage> destroyer(response);
1039               }
1040               
1041               Array<CIMQualifierDecl> CIMClientRep::enumerateQualifiers(
1042                   const CIMNamespaceName& nameSpace
1043               )
1044               {
1045                   CIMRequestMessage* request = new CIMEnumerateQualifiersRequestMessage(
1046                       String::EMPTY,
1047                       nameSpace,
1048                       QueueIdStack());
1049               
1050 kumpf    1.1      Message* message = _doRequest(request, CIM_ENUMERATE_QUALIFIERS_RESPONSE_MESSAGE);
1051               
1052                   CIMEnumerateQualifiersResponseMessage* response =
1053                       (CIMEnumerateQualifiersResponseMessage*)message;
1054               
1055                   Destroyer<CIMEnumerateQualifiersResponseMessage> destroyer(response);
1056               
1057                   return(response->qualifierDeclarations);
1058               }
1059               
1060               CIMValue CIMClientRep::invokeMethod(
1061                   const CIMNamespaceName& nameSpace,
1062                   const CIMObjectPath& instanceName,
1063                   const CIMName& methodName,
1064                   const Array<CIMParamValue>& inParameters,
1065                   Array<CIMParamValue>& outParameters
1066               )
1067               {
1068                   // ATTN-RK-P2-20020301: Does it make sense to have a nameSpace parameter
1069                   // when the namespace should already be included in the instanceName?
1070                   // ATTN-RK-P3-20020301: Do we need to make sure the caller didn't specify
1071 kumpf    1.1      // a host name in the instanceName?
1072               
1073 marek    1.12 	// solved with PEP#139 Stage1 as other CIMOMs contained in the object path
1074               	// will cause a TypeMisMatchException
1075               
1076               	compareObjectPathtoCurrentConnection(instanceName);
1077 kumpf    1.1      CIMRequestMessage* request = new CIMInvokeMethodRequestMessage(
1078                       String::EMPTY,
1079                       nameSpace,
1080                       instanceName,
1081                       methodName,
1082                       inParameters,
1083                       QueueIdStack());
1084               
1085                   Message* message = _doRequest(request, CIM_INVOKE_METHOD_RESPONSE_MESSAGE);
1086               
1087                   CIMInvokeMethodResponseMessage* response =
1088                       (CIMInvokeMethodResponseMessage*)message;
1089               
1090                   Destroyer<CIMInvokeMethodResponseMessage> destroyer(response);
1091               
1092                   outParameters = response->outParameters;
1093               
1094                   return(response->retValue);
1095               }
1096               
1097               Message* CIMClientRep::_doRequest(
1098 kumpf    1.1      CIMRequestMessage * request,
1099                   const Uint32 expectedResponseMessageType
1100               )
1101               {
1102                   if (!_connected)
1103                   {
1104                       delete request;
1105                       throw NotConnectedException();
1106                   }
1107               
1108                   String messageId = XmlWriter::getNextMessageId();
1109                   const_cast<String &>(request->messageId) = messageId;
1110               
1111 kumpf    1.8      _authenticator.setRequestMessage(0);
1112 kumpf    1.1  
1113                   // ATTN-RK-P2-20020416: We should probably clear out the queue first.
1114                   PEGASUS_ASSERT(getCount() == 0);  // Shouldn't be any messages in our queue
1115               
1116                   //
1117 karl     1.2      //  Set HTTP method in request to POST
1118 kumpf    1.1      //
1119 karl     1.2  	//Bug 478/418 - Change this to do post call, not mpost
1120                   request->setHttpMethod (HTTP_METHOD__POST);
1121 kumpf    1.1  
1122               // l10n
1123                   // Set the Accept-Languages and Content-Languages into
1124                   // the request message
1125                   request->acceptLanguages = requestAcceptLanguages;
1126                   request->contentLanguages = requestContentLanguages;
1127               
1128                   // Sending a new request, so clear out the response Content-Languages
1129                   responseContentLanguages = ContentLanguages::EMPTY;
1130               
1131                   _requestEncoder->enqueue(request);
1132               
1133                   Uint64 startMilliseconds = TimeValue::getCurrentTime().toMilliseconds();
1134                   Uint64 nowMilliseconds = startMilliseconds;
1135                   Uint64 stopMilliseconds = nowMilliseconds + _timeoutMilliseconds;
1136               
1137                   while (nowMilliseconds < stopMilliseconds)
1138                   {
1139                       //
1140                       // Wait until the timeout expires or an event occurs:
1141                       //
1142 dj.gorey 1.10        #ifdef PEGASUS_USE_23HTTPMONITOR_CLIENT
1143 kumpf    1.1         _monitor->run(Uint32(stopMilliseconds - nowMilliseconds));
1144 dj.gorey 1.9         #else
1145                      _monitor->run();
1146                      #endif
1147 kumpf    1.1  
1148                       //
1149                       // Check to see if incoming queue has a message
1150                       //
1151               
1152                       Message* response = dequeue();
1153               
1154                       if (response)
1155                       {
1156                           // Shouldn't be any more messages in our queue
1157                           PEGASUS_ASSERT(getCount() == 0);
1158               
1159                           //
1160 kumpf    1.4              //  Future:  If M-POST is used and HTTP response is 501 Not
1161                           //  Implemented or 510 Not Extended, retry with POST method
1162 kumpf    1.1              //
1163               
1164                           if (response->getType() == CLIENT_EXCEPTION_MESSAGE)
1165                           {
1166                               Exception* clientException =
1167                                   ((ClientExceptionMessage*)response)->clientException;
1168                               delete response;
1169 kumpf    1.4  
1170 kumpf    1.1                  Destroyer<Exception> d(clientException);
1171 kumpf    1.4  
1172                               //
1173                               // Determine and throw the specific class of client exception
1174                               //
1175               
1176                               CIMClientMalformedHTTPException* malformedHTTPException =
1177                                   dynamic_cast<CIMClientMalformedHTTPException*>(
1178                                       clientException);
1179                               if (malformedHTTPException)
1180                               {
1181                                   throw *malformedHTTPException;
1182                               }
1183               
1184                               CIMClientHTTPErrorException* httpErrorException =
1185                                   dynamic_cast<CIMClientHTTPErrorException*>(
1186                                       clientException);
1187                               if (httpErrorException)
1188                               {
1189                                   throw *httpErrorException;
1190                               }
1191               
1192 kumpf    1.4                  CIMClientXmlException* xmlException =
1193                                   dynamic_cast<CIMClientXmlException*>(clientException);
1194                               if (xmlException)
1195                               {
1196                                   throw *xmlException;
1197                               }
1198               
1199                               CIMClientResponseException* responseException =
1200                                   dynamic_cast<CIMClientResponseException*>(clientException);
1201                               if (responseException)
1202                               {
1203                                   throw *responseException;
1204                               }
1205               
1206 kumpf    1.1                  throw *clientException;
1207                           }
1208                           else if (response->getType() == expectedResponseMessageType)
1209                           {
1210                               CIMResponseMessage* cimResponse = (CIMResponseMessage*)response;
1211               
1212                               if (cimResponse->messageId != messageId)
1213                               {
1214                                   // l10n
1215               
1216                                   // CIMClientResponseException responseException(
1217                                   //   String("Mismatched response message ID:  Got \"") +
1218                                   //    cimResponse->messageId + "\", expected \"" +
1219                                   //    messageId + "\".");
1220               
1221                                   MessageLoaderParms mlParms(
1222                                       "Client.CIMClient.MISMATCHED_RESPONSE",
1223                                       "Mismatched response message ID:  Got \"$0\", "
1224                                           "expected \"$1\".",
1225                                       cimResponse->messageId, messageId);
1226                                   String mlString(MessageLoader::getMessage(mlParms));
1227 kumpf    1.1  
1228                                   CIMClientResponseException responseException(mlString);
1229               
1230                                   delete response;
1231                                   throw responseException;
1232                               }
1233               
1234               // l10n
1235                               // Get the Content-Languages from the response
1236                               responseContentLanguages = cimResponse->contentLanguages;
1237               
1238                               if (cimResponse->cimException.getCode() != CIM_ERR_SUCCESS)
1239                               {
1240                                   CIMException cimException(
1241                                       cimResponse->cimException.getCode(),
1242                                       cimResponse->cimException.getMessage());
1243                                   delete response;
1244                                   throw cimException;
1245                               }
1246                               return response;
1247                           }
1248 kumpf    1.1              else
1249                           {
1250                               // l10n
1251               
1252                               // CIMClientResponseException responseException(
1253                               //   "Mismatched response message type.");
1254               
1255                               MessageLoaderParms mlParms(
1256                                 "Client.CIMOperationResponseDecoder.MISMATCHED_RESPONSE_TYPE",
1257                                 "Mismatched response message type.");
1258                               String mlString(MessageLoader::getMessage(mlParms));
1259               
1260                               CIMClientResponseException responseException(mlString);
1261               
1262                               delete response;
1263                               throw responseException;
1264                           }
1265                       }
1266               
1267                       nowMilliseconds = TimeValue::getCurrentTime().toMilliseconds();
1268                       pegasus_yield();
1269 kumpf    1.1      }
1270               
1271                   //
1272                   // Reconnect to reset the connection (disregard late response)
1273                   //
1274                   try
1275                   {
1276                       _reconnect();
1277                   }
1278                   catch (...)
1279                   {
1280                   }
1281               
1282                   //
1283                   // Throw timed out exception:
1284                   //
1285                   throw ConnectionTimeoutException();
1286               }
1287               
1288               String CIMClientRep::_getLocalHostName()
1289               {
1290 kumpf    1.1      static String hostname = "localhost";
1291               
1292                   return hostname;
1293 marek    1.12 }
1294               
1295               void CIMClientRep::compareObjectPathtoCurrentConnection(CIMObjectPath obj) throw(TypeMismatchException)
1296               {
1297               
1298               	String ObjHost = obj.getHost();
1299               	// test if a host is given at all, if not everything is fine and we leave it at that
1300               	if (ObjHost==String::EMPTY)
1301               	{
1302               		return;
1303               	}
1304               	MessageLoaderParms typeMismatchMessage;
1305               	// splitting the port from hostname as we have to compare both separate
1306               	int i = ObjHost.find(":");
1307               	String ObjPort = String::EMPTY;
1308               	// only if there is a ":" we should split a port address from hostname string
1309               	if (i > 0)
1310               	{
1311               		ObjPort = ObjHost.subString(i+1);
1312               		ObjHost.remove(i);
1313               
1314 marek    1.12 
1315               		// lets see who we are really connected to
1316               		// should stand in UInt32 _connectPortNumber and String _connectHost;
1317               
1318               
1319               		// comparing the evil stuff
1320               
1321               		// first the easy part, comparing the ports
1322               		Uint32 objectport = strtoul((const char*) ObjPort.getCString(), NULL, 0);
1323               
1324               
1325               		// if port in object path does not equal port of connection throw a TypeMismatch Exception
1326               		if (objectport != _connectPortNumber)
1327               		{
1328               
1329               
1330               			typeMismatchMessage = MessageLoaderParms("Client.CIMClientRep.TYPEMISMATCH_PORTMISMATCH",
1331               													 "Failed validation of CIM object path: port of CIMClient connection($0) and port of object path($1) not equal",
1332               													 _connectPortNumber, objectport);
1333               			throw TypeMismatchException(typeMismatchMessage);
1334               		}
1335 marek    1.12 	}
1336               
1337               	// lets retrieve ip addresses for both hostnames
1338               	Uint32 ipObjectPath, ipConnection = 0xFFFFFFFF;
1339               	ipObjectPath = _acquireIP((const char *) ObjHost.getCString());
1340               	if (ipObjectPath == 0x7F000001)
1341               	{
1342               		// localhost or ip address of 127.0.0.1
1343               		// still for compare we need the real ip address
1344               		ipObjectPath = _acquireIP((const char *) System::getHostName().getCString());
1345               	}
1346               	if (ipObjectPath == 0xFFFFFFFF)
1347               	{
1348               		// bad formatted ip address or not resolveable
1349               		typeMismatchMessage = MessageLoaderParms("Client.CIMClientRep.TYPEMISMATCH_OBJECTPATH_IP_UNRESOLVEABLE",
1350               												 "Failed validation of CIM object path: failed to resolve IP address($0) from object path",
1351               												 ObjHost);
1352               		throw TypeMismatchException(typeMismatchMessage);
1353               	}
1354               	
1355               	ipConnection = _acquireIP((const char *) _connectHost.getCString());
1356 marek    1.12 	if (ipConnection == 0x7F000001)
1357               	{
1358               		// localhost or ip address of 127.0.0.1
1359               		// still for compare we need the real ip address
1360               		ipConnection = _acquireIP((const char *) System::getHostName().getCString());
1361               	}
1362               	if (ipConnection == 0xFFFFFFFF)
1363               	{
1364               		// bad formatted ip address or not resolveable
1365               		typeMismatchMessage = MessageLoaderParms("Client.CIMClientRep.TYPEMISMATCH_CIMCLIENTCONNECTION_IP_UNRESOLVEABLE",
1366                                                                "Failed validation of CIM object path: failed to resolve IP address($0) of CIMClient connection",
1367               												 _connectHost);
1368               		throw TypeMismatchException(typeMismatchMessage);
1369               	}
1370               
1371               	if (ipObjectPath != ipConnection)
1372               	{
1373               		typeMismatchMessage = MessageLoaderParms("Client.CIMClientRep.TYPEMISMATCH_OBJECTPATHS_NOTEQUAL",
1374                                                                "Failed validation of CIM object path: host of CIMClient connection($0) and object path($1) not equal",
1375               												 _connectHost,
1376               												 ObjHost);
1377 marek    1.12 		throw TypeMismatchException(typeMismatchMessage);
1378               	}
1379               
1380               }
1381               
1382               Uint32 CIMClientRep::_acquireIP(const char* hostname)
1383               {
1384               	Uint32 ip = 0xFFFFFFFF;
1385               	if (!hostname) return 0xFFFFFFFF;
1386               
1387               #ifdef PEGASUS_OS_OS400
1388               	char ebcdicHost[256];
1389               	if (strlen(hostname) < 256)
1390               		strcpy(ebcdicHost, hostname);
1391               	else
1392               		return 0xFFFFFFFF;
1393               	AtoE(ebcdicHost);
1394               #endif
1395               
1396               	struct hostent *entry;
1397               
1398 marek    1.12 	if (isalpha(hostname[0]))
1399               	{
1400               #ifdef PEGASUS_PLATFORM_SOLARIS_SPARC_CC
1401               #define HOSTENT_BUFF_SIZE        8192
1402               		char      buf[HOSTENT_BUFF_SIZE];
1403               		int       h_errorp;
1404               		struct    hostent hp;
1405               
1406               		entry = gethostbyname_r((char *)hostname, &hp, buf,
1407               								HOSTENT_BUFF_SIZE, &h_errorp);
1408               #elif defined(PEGASUS_OS_OS400)
1409               		entry = gethostbyname(ebcdicHost);
1410               #elif defined(PEGASUS_OS_ZOS)
1411               		char hostName[ MAXHOSTNAMELEN + 1 ];
1412               		if (String::equalNoCase("localhost",String(hostname)))
1413               		{
1414               			gethostname( hostName, sizeof( hostName ) );
1415               			entry = gethostbyname(hostName);
1416               		} else
1417               		{
1418               			entry = gethostbyname((char *)hostname);
1419 marek    1.12 		}
1420               #else
1421               		entry = gethostbyname((char *)hostname);
1422               #endif
1423               		if (!entry)
1424               		{
1425               			return 0xFFFFFFFF;
1426               		}
1427               		unsigned char ip_part1,ip_part2,ip_part3,ip_part4;
1428               
1429               		ip_part1 = entry->h_addr[0];
1430               		ip_part2 = entry->h_addr[1];
1431               		ip_part3 = entry->h_addr[2];
1432               		ip_part4 = entry->h_addr[3];
1433               		ip = ip_part1;
1434               		ip = (ip << 8) + ip_part2;
1435               		ip = (ip << 8) + ip_part3;
1436               		ip = (ip << 8) + ip_part4;
1437               	} else
1438               	{
1439               		// given hostname starts with an numeric character
1440 marek    1.14 		// get address in network byte order
1441 marek    1.12 #ifdef PEGASUS_OS_OS400
1442               		Uint32 tmp_addr = inet_addr(ebcdicHost);
1443 marek    1.13 #elif defined(PEGASUS_OS_ZOS)
1444 marek    1.12 		Uint32 tmp_addr = inet_addr_ebcdic((char *)hostname);
1445               #else
1446 marek    1.13 		Uint32 tmp_addr = inet_addr((char *) hostname);
1447 marek    1.12 #endif
1448 marek    1.13 		
1449 marek    1.12 		// 0xFFFFFFF is same as -1 in an unsigned int32
1450               		if (tmp_addr == 0xFFFFFFFF)
1451               		{
1452               			// error, given ip does not follow format requirements
1453               			return 0xFFFFFFFF;
1454 marek    1.14 		}		
1455               		// resolve hostaddr to a real host entry
1456 marek    1.15 		// casting to (const char *) as (char *) will work as (void *) too, those it fits all platforms
1457               		entry = gethostbyaddr((const char *) &tmp_addr, sizeof(tmp_addr), AF_INET);
1458 marek    1.12 
1459               		if (entry == 0)
1460               		{
1461               			// error, couldn't resolve the ip
1462               			return 0xFFFFFFFF;
1463               		} else
1464               		{
1465               
1466               			unsigned char ip_part1,ip_part2,ip_part3,ip_part4;
1467               
1468               			ip_part1 = entry->h_addr[0];
1469               			ip_part2 = entry->h_addr[1];
1470               			ip_part3 = entry->h_addr[2];
1471               			ip_part4 = entry->h_addr[3];
1472               			ip = ip_part1;
1473               			ip = (ip << 8) + ip_part2;
1474               			ip = (ip << 8) + ip_part3;
1475               			ip = (ip << 8) + ip_part4;
1476               		}
1477               	}
1478               
1479 marek    1.12 	return ip;
1480 kumpf    1.1  }
1481               
1482               PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2