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 request->acceptLanguages = requestAcceptLanguages;
1126 request->contentLanguages = requestContentLanguages;
1127
|
1128 se.gupta 1.22 request->operationContext.set(AcceptLanguageListContainer(requestAcceptLanguages));
1129 request->operationContext.set(ContentLanguageListContainer(requestContentLanguages));
1130
1131
|
1132 kumpf 1.1 // Sending a new request, so clear out the response Content-Languages
1133 responseContentLanguages = ContentLanguages::EMPTY;
1134
1135 _requestEncoder->enqueue(request);
1136
1137 Uint64 startMilliseconds = TimeValue::getCurrentTime().toMilliseconds();
1138 Uint64 nowMilliseconds = startMilliseconds;
1139 Uint64 stopMilliseconds = nowMilliseconds + _timeoutMilliseconds;
1140
1141 while (nowMilliseconds < stopMilliseconds)
1142 {
1143 //
1144 // Wait until the timeout expires or an event occurs:
1145 //
|
1146 dj.gorey 1.10 #ifdef PEGASUS_USE_23HTTPMONITOR_CLIENT
|
1147 kumpf 1.1 _monitor->run(Uint32(stopMilliseconds - nowMilliseconds));
|
1148 dj.gorey 1.9 #else
1149 _monitor->run();
1150 #endif
|
1151 kumpf 1.1
1152 //
1153 // Check to see if incoming queue has a message
1154 //
1155
1156 Message* response = dequeue();
1157
1158 if (response)
1159 {
1160 // Shouldn't be any more messages in our queue
1161 PEGASUS_ASSERT(getCount() == 0);
1162
1163 //
|
1164 kumpf 1.4 // Future: If M-POST is used and HTTP response is 501 Not
1165 // Implemented or 510 Not Extended, retry with POST method
|
1166 kumpf 1.1 //
1167
1168 if (response->getType() == CLIENT_EXCEPTION_MESSAGE)
1169 {
1170 Exception* clientException =
1171 ((ClientExceptionMessage*)response)->clientException;
1172 delete response;
|
1173 kumpf 1.4
|
1174 kumpf 1.1 Destroyer<Exception> d(clientException);
|
1175 kumpf 1.4
1176 //
1177 // Determine and throw the specific class of client exception
1178 //
1179
1180 CIMClientMalformedHTTPException* malformedHTTPException =
1181 dynamic_cast<CIMClientMalformedHTTPException*>(
1182 clientException);
1183 if (malformedHTTPException)
1184 {
1185 throw *malformedHTTPException;
1186 }
1187
1188 CIMClientHTTPErrorException* httpErrorException =
1189 dynamic_cast<CIMClientHTTPErrorException*>(
1190 clientException);
1191 if (httpErrorException)
1192 {
1193 throw *httpErrorException;
1194 }
1195
1196 kumpf 1.4 CIMClientXmlException* xmlException =
1197 dynamic_cast<CIMClientXmlException*>(clientException);
1198 if (xmlException)
1199 {
1200 throw *xmlException;
1201 }
1202
1203 CIMClientResponseException* responseException =
1204 dynamic_cast<CIMClientResponseException*>(clientException);
1205 if (responseException)
1206 {
1207 throw *responseException;
1208 }
1209
|
1210 brian.campbell 1.25 CIMException* cimException =
1211 dynamic_cast<CIMException*>(clientException);
1212 if (cimException)
1213 {
1214 throw *cimException;
1215 }
1216
|
1217 kumpf 1.1 throw *clientException;
1218 }
1219 else if (response->getType() == expectedResponseMessageType)
1220 {
1221 CIMResponseMessage* cimResponse = (CIMResponseMessage*)response;
1222
1223 if (cimResponse->messageId != messageId)
1224 {
1225 // l10n
1226
1227 // CIMClientResponseException responseException(
1228 // String("Mismatched response message ID: Got \"") +
1229 // cimResponse->messageId + "\", expected \"" +
1230 // messageId + "\".");
1231
1232 MessageLoaderParms mlParms(
1233 "Client.CIMClient.MISMATCHED_RESPONSE",
1234 "Mismatched response message ID: Got \"$0\", "
1235 "expected \"$1\".",
1236 cimResponse->messageId, messageId);
1237 String mlString(MessageLoader::getMessage(mlParms));
1238 kumpf 1.1
1239 CIMClientResponseException responseException(mlString);
1240
1241 delete response;
1242 throw responseException;
1243 }
1244
1245 // l10n
|
1246 se.gupta 1.24 // Get the Content-Languages from the response's operationContext
1247 responseContentLanguages = ((ContentLanguageListContainer)cimResponse->operationContext.get
1248 (ContentLanguageListContainer::NAME)).getLanguages();
|
1249 kumpf 1.1
1250 if (cimResponse->cimException.getCode() != CIM_ERR_SUCCESS)
1251 {
1252 CIMException cimException(
1253 cimResponse->cimException.getCode(),
1254 cimResponse->cimException.getMessage());
1255 delete response;
1256 throw cimException;
1257 }
1258 return response;
1259 }
1260 else
1261 {
1262 // l10n
1263
1264 // CIMClientResponseException responseException(
1265 // "Mismatched response message type.");
1266
1267 MessageLoaderParms mlParms(
1268 "Client.CIMOperationResponseDecoder.MISMATCHED_RESPONSE_TYPE",
1269 "Mismatched response message type.");
1270 kumpf 1.1 String mlString(MessageLoader::getMessage(mlParms));
1271
1272 CIMClientResponseException responseException(mlString);
1273
1274 delete response;
1275 throw responseException;
1276 }
1277 }
1278
1279 nowMilliseconds = TimeValue::getCurrentTime().toMilliseconds();
1280 pegasus_yield();
1281 }
1282
1283 //
1284 // Reconnect to reset the connection (disregard late response)
1285 //
1286 try
1287 {
1288 _reconnect();
1289 }
1290 catch (...)
1291 kumpf 1.1 {
1292 }
1293
1294 //
1295 // Throw timed out exception:
1296 //
1297 throw ConnectionTimeoutException();
1298 }
1299
1300 String CIMClientRep::_getLocalHostName()
1301 {
1302 static String hostname = "localhost";
1303
1304 return hostname;
|
1305 marek 1.12 }
1306
1307 void CIMClientRep::compareObjectPathtoCurrentConnection(CIMObjectPath obj) throw(TypeMismatchException)
1308 {
1309
1310 String ObjHost = obj.getHost();
1311 // test if a host is given at all, if not everything is fine and we leave it at that
1312 if (ObjHost==String::EMPTY)
1313 {
1314 return;
1315 }
|
1316 marek 1.17
1317 MessageLoaderParms typeMismatchMessage;
|
1318 marek 1.12 // splitting the port from hostname as we have to compare both separate
1319 int i = ObjHost.find(":");
1320 String ObjPort = String::EMPTY;
1321 // only if there is a ":" we should split a port address from hostname string
1322 if (i > 0)
1323 {
1324 ObjPort = ObjHost.subString(i+1);
1325 ObjHost.remove(i);
1326
1327 // lets see who we are really connected to
1328 // should stand in UInt32 _connectPortNumber and String _connectHost;
1329
|
1330 marek 1.17 // comparing the stuff
|
1331 marek 1.12 // first the easy part, comparing the ports
1332 Uint32 objectport = strtoul((const char*) ObjPort.getCString(), NULL, 0);
1333
1334 // if port in object path does not equal port of connection throw a TypeMismatch Exception
1335 if (objectport != _connectPortNumber)
1336 {
1337
1338
1339 typeMismatchMessage = MessageLoaderParms("Client.CIMClientRep.TYPEMISMATCH_PORTMISMATCH",
1340 "Failed validation of CIM object path: port of CIMClient connection($0) and port of object path($1) not equal",
1341 _connectPortNumber, objectport);
1342 throw TypeMismatchException(typeMismatchMessage);
1343 }
1344 }
1345
1346 // lets retrieve ip addresses for both hostnames
1347 Uint32 ipObjectPath, ipConnection = 0xFFFFFFFF;
1348 ipObjectPath = _acquireIP((const char *) ObjHost.getCString());
1349 if (ipObjectPath == 0x7F000001)
1350 {
1351 // localhost or ip address of 127.0.0.1
1352 marek 1.12 // still for compare we need the real ip address
1353 ipObjectPath = _acquireIP((const char *) System::getHostName().getCString());
1354 }
1355 if (ipObjectPath == 0xFFFFFFFF)
1356 {
1357 // bad formatted ip address or not resolveable
1358 typeMismatchMessage = MessageLoaderParms("Client.CIMClientRep.TYPEMISMATCH_OBJECTPATH_IP_UNRESOLVEABLE",
1359 "Failed validation of CIM object path: failed to resolve IP address($0) from object path",
1360 ObjHost);
1361 throw TypeMismatchException(typeMismatchMessage);
1362 }
|
1363 marek 1.17 #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
1364 // a local domain socket connection is represented as empty _connectHost
1365 if (_connectHost == String::EMPTY)
1366 {
1367 // ok, it is the localhost, so lets compare with that given
1368 ipConnection = 0x7F000001;
1369 // return;
1370 } else
1371 {
1372 ipConnection = _acquireIP((const char *) _connectHost.getCString());
1373 }
1374 #else
|
1375 marek 1.12 ipConnection = _acquireIP((const char *) _connectHost.getCString());
|
1376 marek 1.17 #endif
|
1377 marek 1.12 if (ipConnection == 0x7F000001)
1378 {
1379 // localhost or ip address of 127.0.0.1
1380 // still for compare we need the real ip address
1381 ipConnection = _acquireIP((const char *) System::getHostName().getCString());
1382 }
1383 if (ipConnection == 0xFFFFFFFF)
1384 {
1385 // bad formatted ip address or not resolveable
1386 typeMismatchMessage = MessageLoaderParms("Client.CIMClientRep.TYPEMISMATCH_CIMCLIENTCONNECTION_IP_UNRESOLVEABLE",
1387 "Failed validation of CIM object path: failed to resolve IP address($0) of CIMClient connection",
1388 _connectHost);
1389 throw TypeMismatchException(typeMismatchMessage);
1390 }
1391
1392 if (ipObjectPath != ipConnection)
1393 {
1394 typeMismatchMessage = MessageLoaderParms("Client.CIMClientRep.TYPEMISMATCH_OBJECTPATHS_NOTEQUAL",
1395 "Failed validation of CIM object path: host of CIMClient connection($0) and object path($1) not equal",
1396 _connectHost,
1397 ObjHost);
1398 marek 1.12 throw TypeMismatchException(typeMismatchMessage);
1399 }
1400
1401 }
1402
1403 Uint32 CIMClientRep::_acquireIP(const char* hostname)
1404 {
1405 Uint32 ip = 0xFFFFFFFF;
1406 if (!hostname) return 0xFFFFFFFF;
1407
1408 #ifdef PEGASUS_OS_OS400
|
1409 marek 1.16 char ebcdicHost[PEGASUS_MAXHOSTNAMELEN];
1410 if (strlen(hostname) < PEGASUS_MAXHOSTNAMELEN)
|
1411 marek 1.12 strcpy(ebcdicHost, hostname);
1412 else
1413 return 0xFFFFFFFF;
1414 AtoE(ebcdicHost);
1415 #endif
1416
1417 struct hostent *entry;
1418
1419 if (isalpha(hostname[0]))
1420 {
1421 #ifdef PEGASUS_PLATFORM_SOLARIS_SPARC_CC
1422 #define HOSTENT_BUFF_SIZE 8192
1423 char buf[HOSTENT_BUFF_SIZE];
1424 int h_errorp;
1425 struct hostent hp;
1426
1427 entry = gethostbyname_r((char *)hostname, &hp, buf,
1428 HOSTENT_BUFF_SIZE, &h_errorp);
1429 #elif defined(PEGASUS_OS_OS400)
1430 entry = gethostbyname(ebcdicHost);
1431 #elif defined(PEGASUS_OS_ZOS)
|
1432 marek 1.16 char hostName[ PEGASUS_MAXHOSTNAMELEN ];
|
1433 marek 1.12 if (String::equalNoCase("localhost",String(hostname)))
1434 {
|
1435 marek 1.16 gethostname( hostName, PEGASUS_MAXHOSTNAMELEN );
|
1436 marek 1.12 entry = gethostbyname(hostName);
1437 } else
1438 {
1439 entry = gethostbyname((char *)hostname);
1440 }
1441 #else
1442 entry = gethostbyname((char *)hostname);
1443 #endif
1444 if (!entry)
1445 {
1446 return 0xFFFFFFFF;
1447 }
1448 unsigned char ip_part1,ip_part2,ip_part3,ip_part4;
1449
1450 ip_part1 = entry->h_addr[0];
1451 ip_part2 = entry->h_addr[1];
1452 ip_part3 = entry->h_addr[2];
1453 ip_part4 = entry->h_addr[3];
1454 ip = ip_part1;
1455 ip = (ip << 8) + ip_part2;
1456 ip = (ip << 8) + ip_part3;
1457 marek 1.12 ip = (ip << 8) + ip_part4;
1458 } else
1459 {
1460 // given hostname starts with an numeric character
|
1461 marek 1.14 // get address in network byte order
|
1462 marek 1.12 #ifdef PEGASUS_OS_OS400
1463 Uint32 tmp_addr = inet_addr(ebcdicHost);
|
1464 marek 1.13 #elif defined(PEGASUS_OS_ZOS)
|
1465 marek 1.12 Uint32 tmp_addr = inet_addr_ebcdic((char *)hostname);
1466 #else
|
1467 marek 1.13 Uint32 tmp_addr = inet_addr((char *) hostname);
|
1468 marek 1.12 #endif
|
1469 marek 1.13
|
1470 marek 1.12 // 0xFFFFFFF is same as -1 in an unsigned int32
1471 if (tmp_addr == 0xFFFFFFFF)
1472 {
1473 // error, given ip does not follow format requirements
1474 return 0xFFFFFFFF;
|
1475 marek 1.14 }
1476 // resolve hostaddr to a real host entry
|
1477 marek 1.15 // casting to (const char *) as (char *) will work as (void *) too, those it fits all platforms
1478 entry = gethostbyaddr((const char *) &tmp_addr, sizeof(tmp_addr), AF_INET);
|
1479 marek 1.12
1480 if (entry == 0)
1481 {
1482 // error, couldn't resolve the ip
1483 return 0xFFFFFFFF;
1484 } else
1485 {
1486
1487 unsigned char ip_part1,ip_part2,ip_part3,ip_part4;
1488
1489 ip_part1 = entry->h_addr[0];
1490 ip_part2 = entry->h_addr[1];
1491 ip_part3 = entry->h_addr[2];
1492 ip_part4 = entry->h_addr[3];
1493 ip = ip_part1;
1494 ip = (ip << 8) + ip_part2;
1495 ip = (ip << 8) + ip_part3;
1496 ip = (ip << 8) + ip_part4;
1497 }
1498 }
1499
1500 marek 1.12 return ip;
|
1501 kumpf 1.1 }
1502
1503 PEGASUS_NAMESPACE_END
|