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

  1 mike  1.2 //%/////////////////////////////////////////////////////////////////////////////
  2           //
  3 kumpf 1.8 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
  4           // The Open Group, Tivoli Systems
  5 mike  1.2 //
  6           // Permission is hereby granted, free of charge, to any person obtaining a copy
  7 kumpf 1.8 // of this software and associated documentation files (the "Software"), to
  8           // deal in the Software without restriction, including without limitation the
  9           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 10 mike  1.2 // sell copies of the Software, and to permit persons to whom the Software is
 11           // furnished to do so, subject to the following conditions:
 12           // 
 13 kumpf 1.8 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 14 mike  1.2 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 15           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 16 kumpf 1.8 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 17           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 18           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 19 mike  1.2 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 20           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 21           //
 22           //==============================================================================
 23           //
 24           // Author: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
 25           //
 26 kumpf 1.10 // Modified By: Carol Ann Krug Graves, Hewlett-Packard Company
 27            //                (carolann_graves@hp.com)
 28 mday  1.12.4.1 //              Nag Boranna, Hewlett-Packard Company (nagaraja_boranna@hp.com)
 29 mday  1.12.4.2 //              Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
 30 mike  1.2      //
 31                //%/////////////////////////////////////////////////////////////////////////////
 32                
 33                #include <Pegasus/Common/Config.h>
 34 kumpf 1.5      #include <Pegasus/Common/PegasusVersion.h>
 35                
 36 mike  1.2      #include <iostream>
 37                #include <Pegasus/ExportClient/CIMExportClient.h>
 38                #include <Pegasus/Handler/CIMHandler.h>
 39                #include <Pegasus/Repository/CIMRepository.h>
 40 mday  1.12.4.1 #include <Pegasus/Common/SSLContext.h>
 41 mday  1.12.4.2 #include <Pegasus/Config/ConfigManager.h>
 42                #include <Pegasus/Common/Constants.h>
 43                #include <Pegasus/Common/System.h>
 44 mike  1.2      
 45                PEGASUS_NAMESPACE_BEGIN
 46                
 47                PEGASUS_USING_STD;
 48                
 49                //#define DDD(X) X
 50                #define DDD(X) // X
 51                
 52                DDD(static const char* _CIMXMLINDICATIONHANDLER = "CIMxmlIndicationHandler::";)
 53                
 54 mday  1.12.4.1 static Boolean verifyListenerCertificate(SSLCertificateInfo &certInfo)
 55                {
 56                    // ATTN: Add code to handle listener certificate verification.
 57                    //
 58                    return true;
 59                }
 60                
 61                
 62 mike  1.2      class PEGASUS_HANDLER_LINKAGE CIMxmlIndicationHandler: public CIMHandler
 63                {
 64                public:
 65                
 66                    CIMxmlIndicationHandler()
 67                    {
 68                        DDD(cout << _CIMXMLINDICATIONHANDLER << "CIMxmlIndicationHandler()" << endl;)
 69                    }
 70                
 71                    virtual ~CIMxmlIndicationHandler()
 72                    {
 73                        DDD(cout << _CIMXMLINDICATIONHANDLER << "~CIMxmlIndicationHandler()" << endl;)
 74                    }
 75                
 76                    void initialize(CIMRepository* repository)
 77                    {
 78                        DDD(cout << _CIMXMLINDICATIONHANDLER << "initialize()" << endl;)
 79                    }
 80                
 81                    void terminate()
 82                    {
 83 mike  1.2              DDD(cout << _CIMXMLINDICATIONHANDLER << "terminate()" << endl;)
 84                    }
 85                
 86 mday  1.12.4.1 // l10n
 87 mike  1.2          void handleIndication(
 88                	CIMInstance& indicationHandlerInstance, 
 89                	CIMInstance& indicationInstance, 
 90 mday  1.12.4.1 	String nameSpace,
 91                	ContentLanguages& contentLanguages)
 92 mike  1.2          {
 93                	//get destination for the indication
 94 kumpf 1.10     	Uint32 pos = indicationHandlerInstance.findProperty 
 95                            (CIMName ("destination"));
 96 mike  1.2              if (pos == PEG_NOT_FOUND)
 97                        {
 98                            // ATTN: Deal with a malformed handler instance
 99                        }
100                
101                	CIMProperty prop = indicationHandlerInstance.getProperty(pos);
102                
103                        String dest;
104                        try
105                        {
106                            prop.getValue().get(dest);
107                        }
108 kumpf 1.9              catch (TypeMismatchException& e)
109 mike  1.2              {
110                            // ATTN: Deal with a malformed handler instance
111                        }
112                	
113                	try
114                        {
115 mday  1.12.4.1             static String PROPERTY_NAME__SSLCERT_FILEPATH = "sslCertificateFilePath";
116                            static String PROPERTY_NAME__SSLKEY_FILEPATH  = "sslKeyFilePath";
117                            static String PROPERTY_NAME__SSLTRUST_FILEPATH  = "sslTrustFilePath";
118                
119                            //
120                            // Get the sslCertificateFilePath property from the Config Manager.
121                            //
122 mday  1.12.4.2 	    ConfigManager* configManager = ConfigManager::getInstance();
123                
124 mday  1.12.4.1             String certPath;
125 mday  1.12.4.2             certPath = configManager->getCurrentValue(
126 mday  1.12.4.1                                PROPERTY_NAME__SSLCERT_FILEPATH);
127                
128                            //
129                            // Get the sslKeyFilePath property from the Config Manager.
130                            //
131                            String keyPath;
132 mday  1.12.4.2             keyPath = configManager->getCurrentValue(
133 mday  1.12.4.1                                PROPERTY_NAME__SSLKEY_FILEPATH);
134                
135                            //
136                            // Get the sslKeyFilePath property from the Config Manager.
137                            //
138                            String trustPath = String::EMPTY;
139 mday  1.12.4.2             trustPath = configManager->getCurrentValue(
140 mday  1.12.4.1                                PROPERTY_NAME__SSLTRUST_FILEPATH);
141                
142                            String randFile = String::EMPTY;
143                
144                #ifdef PEGASUS_SSL_RANDOMFILE
145                            // NOTE: It is technically not necessary to set up a random file on
146                            // the server side, but it is easier to use a consistent interface
147                            // on the client and server than to optimize out the random file on
148                            // the server side.
149                            randFile = ConfigManager::getHomedPath(PEGASUS_SSLSERVER_RANDOMFILE);
150                #endif
151                
152                            SSLContext sslcontext(trustPath, certPath, keyPath, verifyListenerCertificate, randFile);
153                
154 mday  1.12.4.2 	    Monitor monitor;
155                	    HTTPConnector httpConnector( &monitor);
156                	    CIMExportClient exportclient( &monitor, &httpConnector);
157                
158 kumpf 1.11                 Uint32 colon = dest.find (":");
159 mday  1.12.4.2 
160 kumpf 1.11                 Uint32 portNumber = 0;
161 mday  1.12.4.1             Boolean useHttps = false;
162                            String destStr = dest;
163 mday  1.12.4.2 	    String hostName;
164 mday  1.12.4.1 
165                            //
166 mday  1.12.4.2             // If the URL has https (https://hostname:port/... or
167                	    // https://hostname/...) then use SSL 
168                            // for Indication delivery. If it has http (http://hostname:port/...
169                	    // or http://hostname/...) then do not use SSL.
170 mday  1.12.4.1             //
171 mday  1.12.4.2             if (colon != PEG_NOT_FOUND) 
172 mday  1.12.4.1             {
173                                String httpStr = dest.subString(0, colon); 
174                                if (String::equalNoCase(httpStr, "https"))
175                                {
176                                    useHttps = true;
177                                }
178 mday  1.12.4.2                 else if (String::equalNoCase(httpStr, "http"))
179                                {
180                                    useHttps = false;
181                                }
182                		else
183                		{
184                		    throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, httpStr);
185                		}
186 mday  1.12.4.1             }
187 mday  1.12.4.2 	    else
188                	    {
189                		throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, dest);
190                	    }
191                
192                	    String doubleSlash = dest.subString(colon + 1, 2); 
193                
194                	    if (String::equalNoCase(doubleSlash, "//"))
195                	    {
196                            	destStr = dest.subString(colon + 3, PEG_NOT_FOUND);
197                	    }
198                	    else
199                	    {
200                		throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, dest);
201                	    }
202                
203 mday  1.12.4.1             colon = destStr.find (":");
204                
205 mday  1.12.4.2 	     //
206                	    // get hostname and port number from destination string
207                	    //
208                	    if (colon != PEG_NOT_FOUND)
209                	    {
210                	        hostName = destStr.subString (0, colon);
211                	        destStr = destStr.subString(colon + 1, PEG_NOT_FOUND);
212                
213                	        Uint32 slash = destStr.find ("/");
214                	        String portStr;
215                
216                	        if (slash != PEG_NOT_FOUND)
217                	        {
218                		    portStr = destStr.subString (0, slash);
219                	        }
220                	        else
221                	        {
222                		    portStr = destStr.subString (0, PEG_NOT_FOUND);
223                	        }
224                
225                	        sscanf (portStr.getCString (), "%u", &portNumber);  
226 mday  1.12.4.2 	    }
227                	    //
228                	    // There is no port number in the destination string,
229                	    // get port number from system
230                	    //
231                	    else
232                	    {
233                	        Uint32 slash = destStr.find ("/");
234                	        if (slash != PEG_NOT_FOUND)
235                	        { 
236                		    hostName = destStr.subString (0, slash);
237                	        }
238                	        else
239                	        {
240                		    hostName = destStr.subString (0, PEG_NOT_FOUND);
241                		}
242                		if (useHttps)
243                		{
244                		     portNumber = System::lookupPort(WBEM_HTTPS_SERVICE_NAME,
245                							WBEM_DEFAULT_HTTPS_PORT); 
246                		}
247 mday  1.12.4.2 		else
248                		{
249                		    portNumber = System::lookupPort(WBEM_HTTP_SERVICE_NAME,
250                							WBEM_DEFAULT_HTTP_PORT);
251                		}
252                	    }	
253 mday  1.12.4.1 
254                            if (useHttps)
255                            {
256                #ifdef PEGASUS_HAS_SSL
257 mday  1.12.4.2                 exportclient.connect (hostName, portNumber, sslcontext);
258 mday  1.12.4.1 #else
259                                PEGASUS_STD(cerr) << "CIMxmlIndicationHandler Error: "
260                                    << "Cannot do https connection." << PEGASUS_STD(endl);
261                #endif
262                            }
263                            else
264                            {
265 mday  1.12.4.2                 exportclient.connect (hostName, portNumber);
266 mday  1.12.4.1             }
267                
268                // l10n
269 kumpf 1.4      	    exportclient.exportIndication(
270 mday  1.12.4.2 		destStr.subString(destStr.find("/")), indicationInstance,
271                		contentLanguages);
272 mike  1.2      	}
273                	catch(Exception& e)
274                        {
275 mday  1.12.4.1             //ATTN: Catch specific exceptions and log the error message 
276                            // as Indication delivery failed.
277                
278 karl  1.7                  PEGASUS_STD(cerr) << "CIMxmlIndicationHandler Error: " << e.getMessage() 
279                	    << PEGASUS_STD(endl);
280 mike  1.2              }
281                    }
282                };
283                
284                // This is the dynamic entry point into this dynamic module. The name of
285                // this handler is "CIMxmlIndicationHandler" which is appened to "PegasusCreateHandler_"
286                // to form a symbol name. This function is called by the HandlerTable
287                // to load this handler.
288                
289                extern "C" PEGASUS_EXPORT CIMHandler* 
290                    PegasusCreateHandler_CIMxmlIndicationHandler() {
291                    DDD(cout << "Called PegasusCreateHandler_CIMxmlIndicationHandler" << endl;)
292                    return new CIMxmlIndicationHandler;
293                }
294                
295                PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2