(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 se.gupta 1.23 //				 Seema Gupta (gseema@in.ibm.com) for PEP135
  32 brian.campbell 1.25 //         Brian G. Campbell, EMC (campbell_brian@emc.com) - PEP140/phase1
  33 kumpf          1.1  //
  34                     //%/////////////////////////////////////////////////////////////////////////////
  35                     
  36                     #include "CIMClientRep.h"
  37                     
  38                     // l10n
  39                     #include <Pegasus/Common/MessageLoader.h>
  40                     
  41                     #include <iostream>
  42                     #include <fstream>
  43                     #ifdef PEGASUS_PLATFORM_WIN32_IX86_MSVC
  44                     # include <windows.h>
  45                     #else
  46                     # include <netinet/in.h>
  47                     # include <arpa/inet.h>
  48                     # include <sys/socket.h>
  49                     #endif
  50                     
  51                     PEGASUS_USING_STD;
  52                     
  53                     PEGASUS_NAMESPACE_BEGIN
  54 kumpf          1.1  
  55                     ///////////////////////////////////////////////////////////////////////////////
  56                     //
  57                     // CIMClientRep
  58                     //
  59                     ///////////////////////////////////////////////////////////////////////////////
  60                     
  61                     CIMClientRep::CIMClientRep(Uint32 timeoutMilliseconds)
  62                         :
  63                         MessageQueue(PEGASUS_QUEUENAME_CLIENT),
  64                         _httpConnection(0),
  65                         _timeoutMilliseconds(timeoutMilliseconds),
  66                         _connected(false),
  67                         _responseDecoder(0),
  68                         _requestEncoder(0),
  69                         _connectSSLContext(0)
  70                     {
  71                         //
  72                         // Create Monitor and HTTPConnector
  73                         //
  74 dj.gorey       1.10     #ifdef PEGASUS_USE_23HTTPMONITOR_CLIENT
  75 kumpf          1.1      _monitor = new Monitor();
  76                         _httpConnector = new HTTPConnector(_monitor);
  77 dj.gorey       1.9      #else
  78                         _monitor = new monitor_2();
  79                         _httpConnector = new HTTPConnector2(_monitor);
  80                         #endif
  81 kumpf          1.1  
  82                     // l10n
  83                         requestAcceptLanguages = AcceptLanguages::EMPTY;
  84                         requestContentLanguages = ContentLanguages::EMPTY;
  85                     }
  86                     
  87                     CIMClientRep::~CIMClientRep()
  88                     {
  89                        disconnect();
  90                        delete _httpConnector;
  91                        delete _monitor;
  92                     }
  93                     
  94                     void CIMClientRep::handleEnqueue()
  95                     {
  96                     
  97                     }
  98                     
  99                     Uint32 _getShowType(String& s)
 100                     {
 101                         String log = "log";
 102 kumpf          1.1      String con = "con";
 103                         String both = "both";
 104                         if (s == log)
 105 tony           1.7          return 2;
 106                         if (s == con)
 107 karl           1.6          return 1;
 108 kumpf          1.1      if (s == both)
 109 karl           1.6          return 3;
 110 kumpf          1.1      return 0;
 111                     }
 112                     
 113                     void CIMClientRep::_connect()
 114                     {
 115                         //
 116                         // Test for Display optons of the form
 117                         // Use Env variable PEGASUS_CLIENT_TRACE= <intrace> : <outtrace
 118                         // intrace = "con" | "log" | "both"
 119                         // outtrace = intrace
 120                         // ex set PEGASUS_CLIENT_TRACE=BOTH:BOTH traces input and output
 121                         // to console and log
 122                         // Keywords are case insensitive.
 123                         // PEP 90
 124                         //
 125                         Uint32 showOutput = 0;
 126                         Uint32 showInput = 0;
 127                     #ifdef PEGASUS_CLIENT_TRACE_ENABLE
 128                         String input;
 129                         if (char * envVar = getenv("PEGASUS_CLIENT_TRACE"))
 130                         {
 131 kumpf          1.1          input = envVar;
 132                             input.toLower();
 133                             String io = String::EMPTY;
 134                             Uint32 pos = input.find(':');
 135                             if (pos == PEG_NOT_FOUND)
 136                                 pos = 0;
 137                             else
 138                                 io = input.subString(0,pos);
 139                     
 140 tony           1.5          // some compilers do not allow temporaries to be passed to a
 141                             // reference argument - so break into 2 lines
 142                             String out = input.subString(pos + 1);
 143                             showOutput = _getShowType(out);
 144 kumpf          1.1  
 145                             showInput = _getShowType(io);
 146                         }
 147                     #endif
 148                     
 149                         //
 150                         // Create response decoder:
 151                         //
 152                         _responseDecoder = new CIMOperationResponseDecoder(
 153                             this, _requestEncoder, &_authenticator, showInput);
 154                     
 155                         //
 156                         // Attempt to establish a connection:
 157                         //
 158                         try
 159                         {
 160 dj.gorey       1.10         #ifdef PEGASUS_USE_23HTTPMONITOR_CLIENT
 161 kumpf          1.1          _httpConnection = _httpConnector->connect(_connectHost,
 162                                                                       _connectPortNumber,
 163                                                                       _connectSSLContext,
 164                                                                       _responseDecoder);
 165 dj.gorey       1.9          #else
 166                             _httpConnection = _httpConnector->connect(_connectHost,
 167                                                                       _connectPortNumber,
 168                                                                       _responseDecoder);
 169 a.arora        1.11         _monitor->set_session_dispatch(_httpConnection->connection_dispatch);
 170 dj.gorey       1.9          #endif
 171                             
 172 kumpf          1.1      }
 173                         catch (CannotCreateSocketException& e)
 174                         {
 175                             delete _responseDecoder;
 176                             throw e;
 177                         }
 178                         catch (CannotConnectException& e)
 179                         {
 180                             delete _responseDecoder;
 181                             throw e;
 182                         }
 183                         catch (InvalidLocatorException& e)
 184                         {
 185                             delete _responseDecoder;
 186                             throw e;
 187                         }
 188                     
 189                         //
 190                         // Create request encoder:
 191                         //
 192                         _requestEncoder = new CIMOperationRequestEncoder(
 193 kumpf          1.1          _httpConnection, &_authenticator, showOutput);
 194                     
 195                         _responseDecoder->setEncoderQueue(_requestEncoder);
 196                     
 197                         _connected = true;
 198                     }
 199                     
 200 kumpf          1.8  void CIMClientRep::_disconnect()
 201                     {
 202                         if (_connected)
 203                         {
 204                             //
 205                             // destroy response decoder
 206                             //
 207                             if (_responseDecoder)
 208                             {
 209                                 delete _responseDecoder;
 210                                 _responseDecoder = 0;
 211                             }
 212                     
 213                             //
 214                             // Close the connection
 215                             //
 216                             if (_httpConnector)
 217                             {
 218                                 _httpConnector->disconnect(_httpConnection);
 219                                 delete _httpConnection;
 220                                 _httpConnection = 0;
 221 kumpf          1.8          }
 222                     
 223                             //
 224                             // destroy request encoder
 225                             //
 226                             if (_requestEncoder)
 227                             {
 228                                 delete _requestEncoder;
 229                                 _requestEncoder = 0;
 230                             }
 231                     
 232                             if (_connectSSLContext)
 233                             {
 234                                 delete _connectSSLContext;
 235                                 _connectSSLContext = 0;
 236                             }
 237                     
 238                             _connected = false;
 239                         }
 240                     }
 241                     
 242 kumpf          1.1  void CIMClientRep::_reconnect()
 243                     {
 244 kumpf          1.8      _disconnect();
 245                         _authenticator.setRequestMessage(0);
 246 kumpf          1.1      _connect();
 247                     }
 248                     
 249                     void CIMClientRep::connect(
 250                         const String& host,
 251                         const Uint32 portNumber,
 252                         const String& userName,
 253                         const String& password
 254                     )
 255                     {
 256                         //
 257                         // If already connected, bail out!
 258                         //
 259                         if (_connected)
 260                             throw AlreadyConnectedException();
 261                     
 262                         //
 263                         // If the host is empty, set hostName to "localhost"
 264                         //
 265                         String hostName = host;
 266                         if (host == String::EMPTY)
 267 kumpf          1.1      {
 268                             hostName = "localhost";
 269                         }
 270                     
 271                         //
 272                         // Set authentication information
 273                         //
 274 kumpf          1.8      _authenticator.clear();
 275 kumpf          1.1  
 276                         if (userName.size())
 277                         {
 278                             _authenticator.setUserName(userName);
 279                         }
 280                     
 281                         if (password.size())
 282                         {
 283                             _authenticator.setPassword(password);
 284                         }
 285                     
 286                         _connectSSLContext = 0;
 287                         _connectHost = hostName;
 288                         _connectPortNumber = portNumber;
 289                     
 290                         _connect();
 291                     }
 292                     
 293                     
 294                     void CIMClientRep::connect(
 295                         const String& host,
 296 kumpf          1.1      const Uint32 portNumber,
 297                         const SSLContext& sslContext,
 298                         const String& userName,
 299                         const String& password
 300                     )
 301                     {
 302                         //
 303                         // If already connected, bail out!
 304                         //
 305                         if (_connected)
 306                             throw AlreadyConnectedException();
 307                     
 308                         //
 309                         // If the host is empty, set hostName to "localhost"
 310                         //
 311                         String hostName = host;
 312                         if (host == String::EMPTY)
 313                         {
 314                             hostName = "localhost";
 315                         }
 316                     
 317 kumpf          1.1      //
 318                         // Set authentication information
 319                         //
 320 kumpf          1.8      _authenticator.clear();
 321 kumpf          1.1  
 322                         if (userName.size())
 323                         {
 324                             _authenticator.setUserName(userName);
 325                         }
 326                     
 327                         if (password.size())
 328                         {
 329                             _authenticator.setPassword(password);
 330                         }
 331                     
 332                         _connectSSLContext = new SSLContext(sslContext);
 333                         _connectHost = hostName;
 334                         _connectPortNumber = portNumber;
 335                     
 336                     
 337                         try
 338                         {
 339                             _connect();
 340                         }
 341                         catch (Exception&)
 342 kumpf          1.1      {
 343                             delete _connectSSLContext;
 344                             _connectSSLContext = 0;
 345                             throw;
 346                         }
 347                     }
 348                     
 349                     
 350                     void CIMClientRep::connectLocal()
 351                     {
 352                         //
 353                         // If already connected, bail out!
 354                         //
 355                         if (_connected)
 356                             throw AlreadyConnectedException();
 357                     
 358                         //
 359                         // Set authentication type
 360                         //
 361 kumpf          1.8      _authenticator.clear();
 362 kumpf          1.1      _authenticator.setAuthType(ClientAuthenticator::LOCAL);
 363                     
 364                     #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
 365                         _connect();
 366                     #else
 367                     
 368                         try
 369                         {
 370                             //
 371                             // Look up the WBEM HTTP port number for the local system
 372                             //
 373                             _connectPortNumber = System::lookupPort (WBEM_HTTP_SERVICE_NAME,
 374                                 WBEM_DEFAULT_HTTP_PORT);
 375                     
 376                             //
 377                             //  Assign host
 378                             //
 379                             _connectHost.assign(_getLocalHostName());
 380                     
 381                             _connectSSLContext = 0;
 382                     
 383 kumpf          1.1          _connect();
 384                         }
 385                         catch(CannotConnectException &e)
 386                         {
 387                             //
 388                             // Look up the WBEM HTTPS port number for the local system
 389                             //
 390                             _connectPortNumber = System::lookupPort (WBEM_HTTPS_SERVICE_NAME,
 391                                 WBEM_DEFAULT_HTTPS_PORT);
 392                     
 393                             //
 394                             //  Assign host
 395                             //
 396                             _connectHost.assign(_getLocalHostName());
 397                     
 398                             //
 399                             // Create SSLContext
 400                             //
 401                     #ifdef PEGASUS_OS_OS400
 402                     #pragma convert(37)
 403                             const char* env = getenv("PEGASUS_HOME");
 404 kumpf          1.1  #pragma convert(0)
 405                             char pegasusHome[256] = {0};
 406                             if (env != NULL && strlen(env) < 256)
 407                             {
 408                                 strcpy(pegasusHome, env);
 409                                 EtoA(pegasusHome);
 410                             }
 411                     #else
 412                             const char* pegasusHome = getenv("PEGASUS_HOME");
 413                     #endif
 414                     
 415                             String randFile = String::EMPTY;
 416                     
 417                     #ifdef PEGASUS_SSL_RANDOMFILE
 418                             randFile = FileSystem::getAbsolutePath(
 419                                 pegasusHome, PEGASUS_SSLCLIENT_RANDOMFILE);
 420                     #endif
 421                     
 422                             try
 423                             {
 424                                 _connectSSLContext =
 425 h.sterling     1.20                 new SSLContext(String::EMPTY, NULL, randFile);
 426 kumpf          1.1          }
 427                             catch (SSLException &se)
 428                             {
 429                                 throw se;
 430                             }
 431                     
 432                             try
 433                             {
 434                                 _connect();
 435                             }
 436                             catch (Exception&)
 437                             {
 438                                 delete _connectSSLContext;
 439                                 _connectSSLContext = 0;
 440                                 throw;
 441                             }
 442                         }
 443                     #endif
 444                     }
 445                     
 446                     
 447 kumpf          1.1  void CIMClientRep::disconnect()
 448                     {
 449 kumpf          1.8      _disconnect();
 450                         _authenticator.clear();
 451                     }
 452 kumpf          1.1  
 453                     
 454 marek          1.21 Boolean CIMClientRep::isConnected()
 455                     {
 456                     	return _connected;
 457                     }
 458                     
 459                     
 460 kumpf          1.1  // 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 chuck          1.18 void CIMClientRep::setRequestAcceptLanguages(const AcceptLanguages& langs)
 477 kumpf          1.1  {
 478                         requestAcceptLanguages = langs;
 479                     }
 480                     
 481 chuck          1.18 void CIMClientRep::setRequestContentLanguages(const ContentLanguages& langs)
 482 kumpf          1.1  {
 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                     )
 501                     {
 502                         CIMRequestMessage* request = new CIMGetClassRequestMessage(
 503 kumpf          1.1          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                     
 522                     CIMInstance CIMClientRep::getInstance(
 523                         const CIMNamespaceName& nameSpace,
 524 kumpf          1.1      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                     
1126 se.gupta       1.22 	request->operationContext.set(AcceptLanguageListContainer(requestAcceptLanguages)); 
1127                         request->operationContext.set(ContentLanguageListContainer(requestContentLanguages)); 
1128                     
1129                     
1130 kumpf          1.1      // Sending a new request, so clear out the response Content-Languages
1131                         responseContentLanguages = ContentLanguages::EMPTY;
1132                     
1133                         _requestEncoder->enqueue(request);
1134                     
1135                         Uint64 startMilliseconds = TimeValue::getCurrentTime().toMilliseconds();
1136                         Uint64 nowMilliseconds = startMilliseconds;
1137                         Uint64 stopMilliseconds = nowMilliseconds + _timeoutMilliseconds;
1138                     
1139                         while (nowMilliseconds < stopMilliseconds)
1140                         {
1141                             //
1142                             // Wait until the timeout expires or an event occurs:
1143                             //
1144 dj.gorey       1.10        #ifdef PEGASUS_USE_23HTTPMONITOR_CLIENT
1145 kumpf          1.1         _monitor->run(Uint32(stopMilliseconds - nowMilliseconds));
1146 dj.gorey       1.9         #else
1147                            _monitor->run();
1148                            #endif
1149 kumpf          1.1  
1150                             //
1151                             // Check to see if incoming queue has a message
1152                             //
1153                     
1154                             Message* response = dequeue();
1155                     
1156                             if (response)
1157                             {
1158                                 // Shouldn't be any more messages in our queue
1159                                 PEGASUS_ASSERT(getCount() == 0);
1160                     
1161                                 //
1162 kumpf          1.4              //  Future:  If M-POST is used and HTTP response is 501 Not
1163                                 //  Implemented or 510 Not Extended, retry with POST method
1164 kumpf          1.1              //
1165                     
1166                                 if (response->getType() == CLIENT_EXCEPTION_MESSAGE)
1167                                 {
1168                                     Exception* clientException =
1169                                         ((ClientExceptionMessage*)response)->clientException;
1170                                     delete response;
1171 kumpf          1.4  
1172 kumpf          1.1                  Destroyer<Exception> d(clientException);
1173 kumpf          1.4  
1174 chuck          1.27 		// Make the ContentLanguage of the exception available through
1175                     		// the CIMClient API (its also available in the exception).
1176                     		responseContentLanguages = clientException->getContentLanguages();
1177                     
1178 kumpf          1.4                  //
1179                                     // Determine and throw the specific class of client exception
1180                                     //
1181                     
1182                                     CIMClientMalformedHTTPException* malformedHTTPException =
1183                                         dynamic_cast<CIMClientMalformedHTTPException*>(
1184                                             clientException);
1185                                     if (malformedHTTPException)
1186                                     {
1187                                         throw *malformedHTTPException;
1188                                     }
1189                     
1190                                     CIMClientHTTPErrorException* httpErrorException =
1191                                         dynamic_cast<CIMClientHTTPErrorException*>(
1192                                             clientException);
1193                                     if (httpErrorException)
1194                                     {
1195                                         throw *httpErrorException;
1196                                     }
1197                     
1198                                     CIMClientXmlException* xmlException =
1199 kumpf          1.4                      dynamic_cast<CIMClientXmlException*>(clientException);
1200                                     if (xmlException)
1201                                     {
1202                                         throw *xmlException;
1203                                     }
1204                     
1205                                     CIMClientResponseException* responseException =
1206                                         dynamic_cast<CIMClientResponseException*>(clientException);
1207                                     if (responseException)
1208                                     {
1209                                         throw *responseException;
1210                                     }
1211                     
1212 brian.campbell 1.25 								CIMException* cimException =
1213                                         dynamic_cast<CIMException*>(clientException);
1214                                     if (cimException)
1215                                     {
1216                                         throw *cimException;
1217                                     }
1218                     
1219 kumpf          1.1                  throw *clientException;
1220                                 }
1221                                 else if (response->getType() == expectedResponseMessageType)
1222                                 {
1223                                     CIMResponseMessage* cimResponse = (CIMResponseMessage*)response;
1224                     
1225                                     if (cimResponse->messageId != messageId)
1226                                     {
1227                                         // l10n
1228                     
1229                                         // CIMClientResponseException responseException(
1230                                         //   String("Mismatched response message ID:  Got \"") +
1231                                         //    cimResponse->messageId + "\", expected \"" +
1232                                         //    messageId + "\".");
1233                     
1234                                         MessageLoaderParms mlParms(
1235                                             "Client.CIMClient.MISMATCHED_RESPONSE",
1236                                             "Mismatched response message ID:  Got \"$0\", "
1237                                                 "expected \"$1\".",
1238                                             cimResponse->messageId, messageId);
1239                                         String mlString(MessageLoader::getMessage(mlParms));
1240 kumpf          1.1  
1241                                         CIMClientResponseException responseException(mlString);
1242                     
1243                                         delete response;
1244                                         throw responseException;
1245                                     }
1246                     
1247 chuck          1.27 		// l10n
1248 se.gupta       1.24                 // Get the Content-Languages from the response's operationContext
1249 chuck          1.27 		// and make available through the CIMClient API
1250                                     responseContentLanguages =
1251                     		  ((ContentLanguageListContainer)cimResponse->operationContext.get
1252                     		   (ContentLanguageListContainer::NAME)).getLanguages();
1253 kumpf          1.1  
1254                                     if (cimResponse->cimException.getCode() != CIM_ERR_SUCCESS)
1255                                     {
1256                                         CIMException cimException(
1257                                             cimResponse->cimException.getCode(),
1258                                             cimResponse->cimException.getMessage());
1259 chuck          1.27 		    cimException.setContentLanguages(responseContentLanguages);
1260 kumpf          1.1                      delete response;
1261                                         throw cimException;
1262                                     }
1263                                     return response;
1264                                 }
1265                                 else
1266                                 {
1267                                     // l10n
1268                     
1269                                     // CIMClientResponseException responseException(
1270                                     //   "Mismatched response message type.");
1271                     
1272                                     MessageLoaderParms mlParms(
1273                                       "Client.CIMOperationResponseDecoder.MISMATCHED_RESPONSE_TYPE",
1274                                       "Mismatched response message type.");
1275                                     String mlString(MessageLoader::getMessage(mlParms));
1276                     
1277                                     CIMClientResponseException responseException(mlString);
1278                     
1279                                     delete response;
1280                                     throw responseException;
1281 kumpf          1.1              }
1282                             }
1283                     
1284                             nowMilliseconds = TimeValue::getCurrentTime().toMilliseconds();
1285                             pegasus_yield();
1286                         }
1287                     
1288                         //
1289                         // Reconnect to reset the connection (disregard late response)
1290                         //
1291                         try
1292                         {
1293                             _reconnect();
1294                         }
1295                         catch (...)
1296                         {
1297                         }
1298                     
1299                         //
1300                         // Throw timed out exception:
1301                         //
1302 kumpf          1.1      throw ConnectionTimeoutException();
1303                     }
1304                     
1305                     String CIMClientRep::_getLocalHostName()
1306                     {
1307                         static String hostname = "localhost";
1308                     
1309                         return hostname;
1310 marek          1.12 }
1311                     
1312                     void CIMClientRep::compareObjectPathtoCurrentConnection(CIMObjectPath obj) throw(TypeMismatchException)
1313                     {
1314                     
1315                     	String ObjHost = obj.getHost();
1316                     	// test if a host is given at all, if not everything is fine and we leave it at that
1317                     	if (ObjHost==String::EMPTY)
1318                     	{
1319                     		return;
1320                     	}
1321 marek          1.17 	
1322                         MessageLoaderParms typeMismatchMessage;
1323 marek          1.12 	// splitting the port from hostname as we have to compare both separate
1324                     	int i = ObjHost.find(":");
1325                     	String ObjPort = String::EMPTY;
1326                     	// only if there is a ":" we should split a port address from hostname string
1327                     	if (i > 0)
1328                     	{
1329                     		ObjPort = ObjHost.subString(i+1);
1330                     		ObjHost.remove(i);
1331                     
1332                     		// lets see who we are really connected to
1333                     		// should stand in UInt32 _connectPortNumber and String _connectHost;
1334                     
1335 marek          1.17 		// comparing the stuff
1336 marek          1.12 		// first the easy part, comparing the ports
1337                     		Uint32 objectport = strtoul((const char*) ObjPort.getCString(), NULL, 0);
1338                     
1339                     		// if port in object path does not equal port of connection throw a TypeMismatch Exception
1340                     		if (objectport != _connectPortNumber)
1341                     		{
1342                     
1343                     
1344                     			typeMismatchMessage = MessageLoaderParms("Client.CIMClientRep.TYPEMISMATCH_PORTMISMATCH",
1345                     													 "Failed validation of CIM object path: port of CIMClient connection($0) and port of object path($1) not equal",
1346                     													 _connectPortNumber, objectport);
1347                     			throw TypeMismatchException(typeMismatchMessage);
1348                     		}
1349                     	}
1350                     
1351                     	// lets retrieve ip addresses for both hostnames
1352                     	Uint32 ipObjectPath, ipConnection = 0xFFFFFFFF;
1353                     	ipObjectPath = _acquireIP((const char *) ObjHost.getCString());
1354                     	if (ipObjectPath == 0x7F000001)
1355                     	{
1356                     		// localhost or ip address of 127.0.0.1
1357 marek          1.12 		// still for compare we need the real ip address
1358                     		ipObjectPath = _acquireIP((const char *) System::getHostName().getCString());
1359                     	}
1360                     	if (ipObjectPath == 0xFFFFFFFF)
1361                     	{
1362                     		// bad formatted ip address or not resolveable
1363                     		typeMismatchMessage = MessageLoaderParms("Client.CIMClientRep.TYPEMISMATCH_OBJECTPATH_IP_UNRESOLVEABLE",
1364                     												 "Failed validation of CIM object path: failed to resolve IP address($0) from object path",
1365                     												 ObjHost);
1366                     		throw TypeMismatchException(typeMismatchMessage);
1367                     	}
1368 marek          1.17 #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
1369                     	// a local domain socket connection is represented as empty _connectHost
1370                     	if (_connectHost == String::EMPTY)
1371                     	{
1372                     		// ok, it is the localhost, so lets compare with that given
1373                     		ipConnection = 0x7F000001;
1374                     		// return;
1375                     	} else
1376                     	{
1377                     		ipConnection = _acquireIP((const char *) _connectHost.getCString());
1378                     	}
1379                     #else	
1380 marek          1.12 	ipConnection = _acquireIP((const char *) _connectHost.getCString());
1381 marek          1.17 #endif
1382 marek          1.12 	if (ipConnection == 0x7F000001)
1383                     	{
1384                     		// localhost or ip address of 127.0.0.1
1385                     		// still for compare we need the real ip address
1386                     		ipConnection = _acquireIP((const char *) System::getHostName().getCString());
1387                     	}
1388                     	if (ipConnection == 0xFFFFFFFF)
1389                     	{
1390                     		// bad formatted ip address or not resolveable
1391                     		typeMismatchMessage = MessageLoaderParms("Client.CIMClientRep.TYPEMISMATCH_CIMCLIENTCONNECTION_IP_UNRESOLVEABLE",
1392                                                                      "Failed validation of CIM object path: failed to resolve IP address($0) of CIMClient connection",
1393                     												 _connectHost);
1394                     		throw TypeMismatchException(typeMismatchMessage);
1395                     	}
1396                     
1397                     	if (ipObjectPath != ipConnection)
1398                     	{
1399                     		typeMismatchMessage = MessageLoaderParms("Client.CIMClientRep.TYPEMISMATCH_OBJECTPATHS_NOTEQUAL",
1400                                                                      "Failed validation of CIM object path: host of CIMClient connection($0) and object path($1) not equal",
1401                     												 _connectHost,
1402                     												 ObjHost);
1403 marek          1.12 		throw TypeMismatchException(typeMismatchMessage);
1404                     	}
1405                     
1406                     }
1407                     
1408                     Uint32 CIMClientRep::_acquireIP(const char* hostname)
1409                     {
1410                     	Uint32 ip = 0xFFFFFFFF;
1411                     	if (!hostname) return 0xFFFFFFFF;
1412                     
1413                     #ifdef PEGASUS_OS_OS400
1414 marek          1.16 	char ebcdicHost[PEGASUS_MAXHOSTNAMELEN];
1415                     	if (strlen(hostname) < PEGASUS_MAXHOSTNAMELEN)
1416 marek          1.12 		strcpy(ebcdicHost, hostname);
1417                     	else
1418                     		return 0xFFFFFFFF;
1419                     	AtoE(ebcdicHost);
1420                     #endif
1421                     
1422                     	struct hostent *entry;
1423                     
1424                     	if (isalpha(hostname[0]))
1425                     	{
1426                     #ifdef PEGASUS_PLATFORM_SOLARIS_SPARC_CC
1427                     #define HOSTENT_BUFF_SIZE        8192
1428                     		char      buf[HOSTENT_BUFF_SIZE];
1429                     		int       h_errorp;
1430                     		struct    hostent hp;
1431                     
1432                     		entry = gethostbyname_r((char *)hostname, &hp, buf,
1433                     								HOSTENT_BUFF_SIZE, &h_errorp);
1434                     #elif defined(PEGASUS_OS_OS400)
1435                     		entry = gethostbyname(ebcdicHost);
1436                     #elif defined(PEGASUS_OS_ZOS)
1437 marek          1.16 		char hostName[ PEGASUS_MAXHOSTNAMELEN ];
1438 marek          1.12 		if (String::equalNoCase("localhost",String(hostname)))
1439                     		{
1440 marek          1.16 			gethostname( hostName, PEGASUS_MAXHOSTNAMELEN );
1441 marek          1.12 			entry = gethostbyname(hostName);
1442                     		} else
1443                     		{
1444                     			entry = gethostbyname((char *)hostname);
1445                     		}
1446                     #else
1447                     		entry = gethostbyname((char *)hostname);
1448                     #endif
1449                     		if (!entry)
1450                     		{
1451                     			return 0xFFFFFFFF;
1452                     		}
1453                     		unsigned char ip_part1,ip_part2,ip_part3,ip_part4;
1454                     
1455                     		ip_part1 = entry->h_addr[0];
1456                     		ip_part2 = entry->h_addr[1];
1457                     		ip_part3 = entry->h_addr[2];
1458                     		ip_part4 = entry->h_addr[3];
1459                     		ip = ip_part1;
1460                     		ip = (ip << 8) + ip_part2;
1461                     		ip = (ip << 8) + ip_part3;
1462 marek          1.12 		ip = (ip << 8) + ip_part4;
1463                     	} else
1464                     	{
1465                     		// given hostname starts with an numeric character
1466 marek          1.14 		// get address in network byte order
1467 marek          1.12 #ifdef PEGASUS_OS_OS400
1468                     		Uint32 tmp_addr = inet_addr(ebcdicHost);
1469 marek          1.13 #elif defined(PEGASUS_OS_ZOS)
1470 marek          1.12 		Uint32 tmp_addr = inet_addr_ebcdic((char *)hostname);
1471                     #else
1472 marek          1.13 		Uint32 tmp_addr = inet_addr((char *) hostname);
1473 marek          1.12 #endif
1474 marek          1.13 		
1475 marek          1.12 		// 0xFFFFFFF is same as -1 in an unsigned int32
1476                     		if (tmp_addr == 0xFFFFFFFF)
1477                     		{
1478                     			// error, given ip does not follow format requirements
1479                     			return 0xFFFFFFFF;
1480 marek          1.14 		}		
1481                     		// resolve hostaddr to a real host entry
1482 marek          1.15 		// casting to (const char *) as (char *) will work as (void *) too, those it fits all platforms
1483                     		entry = gethostbyaddr((const char *) &tmp_addr, sizeof(tmp_addr), AF_INET);
1484 marek          1.12 
1485                     		if (entry == 0)
1486                     		{
1487                     			// error, couldn't resolve the ip
1488                     			return 0xFFFFFFFF;
1489                     		} else
1490                     		{
1491                     
1492                     			unsigned char ip_part1,ip_part2,ip_part3,ip_part4;
1493                     
1494                     			ip_part1 = entry->h_addr[0];
1495                     			ip_part2 = entry->h_addr[1];
1496                     			ip_part3 = entry->h_addr[2];
1497                     			ip_part4 = entry->h_addr[3];
1498                     			ip = ip_part1;
1499                     			ip = (ip << 8) + ip_part2;
1500                     			ip = (ip << 8) + ip_part3;
1501                     			ip = (ip << 8) + ip_part4;
1502                     		}
1503                     	}
1504                     
1505 marek          1.12 	return ip;
1506 kumpf          1.1  }
1507                     
1508                     PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2