BUG#: 7712
authorkavita.gupta <kavita.gupta>
Fri, 27 Jun 2008 09:18:30 +0000 (09:18 +0000)
committerkavita.gupta <kavita.gupta>
Fri, 27 Jun 2008 09:18:30 +0000 (09:18 +0000)
TITLE: CMPI providers can have unexpected exceptions thrown at them in upcalls

src/Pegasus/ProviderManager2/CMPI/CMPI_Broker.cpp

index a3e5e69ff95456aeb9cdc469f9c419b97329d549..a6030820eb2f35f737618c8f00a9a4f92c11d2fb 100644 (file)
@@ -64,6 +64,82 @@ static const CMPIUint32 MB_CAPABILITIES =
 #   endif
     ;
 
+#define HandlerCatchSetStatus(rc, returnvalue) \
+    catch (const CIMException &e) \
+    { \
+        PEG_TRACE_STRING( \
+            TRC_CMPIPROVIDERINTERFACE, \
+            Tracer::LEVEL2, \
+            "CIMException: " + e.getMessage()); \
+        CMSetStatusWithString( \
+            rc, \
+            (CMPIrc)e.getCode(), \
+            (CMPIString*)string2CMPIString(e.getMessage())); \
+        PEG_METHOD_EXIT(); \
+        return returnvalue; \
+    } \
+    catch (const Exception &e) \
+    { \
+        PEG_TRACE(( \
+            TRC_CMPIPROVIDERINTERFACE, \
+            Tracer::LEVEL2, \
+            "Exception: %s", (const char *)e.getMessage().getCString())); \
+        CMSetStatusWithString( \
+            rc, \
+            (CMPIrc)CMPI_RC_ERROR_SYSTEM, \
+            (CMPIString*)string2CMPIString(e.getMessage())); \
+        PEG_METHOD_EXIT(); \
+        return returnvalue; \
+    } \
+    catch (...) \
+    { \
+        PEG_TRACE(( \
+            TRC_CMPIPROVIDERINTERFACE, \
+            Tracer::LEVEL2, \
+            "Unknown exception")); \
+        CMSetStatusWithString( \
+            rc, \
+            (CMPIrc)CMPI_RC_ERROR_SYSTEM, \
+            (CMPIString*)string2CMPIString("Unknown exception")); \
+        PEG_METHOD_EXIT(); \
+        return returnvalue; \
+    }
+
+#define HandlerCatchReturnStatus() \
+    catch (const CIMException &e) \
+    { \
+        PEG_TRACE_STRING( \
+            TRC_CMPIPROVIDERINTERFACE, \
+            Tracer::LEVEL2, \
+            "CIMException: " + e.getMessage()); \
+        PEG_METHOD_EXIT(); \
+        CMReturnWithString( \
+            (CMPIrc)e.getCode(), \
+            (CMPIString*)string2CMPIString(e.getMessage())); \
+    } \
+    catch (const Exception &e) \
+    { \
+        PEG_TRACE(( \
+            TRC_CMPIPROVIDERINTERFACE, \
+            Tracer::LEVEL2, \
+            "Exception: %s", (const char *)e.getMessage().getCString())); \
+        PEG_METHOD_EXIT(); \
+        CMReturnWithString( \
+            (CMPIrc)CMPI_RC_ERROR_SYSTEM, \
+            (CMPIString*)string2CMPIString(e.getMessage())); \
+    } \
+    catch (...) \
+    { \
+        PEG_TRACE(( \
+            TRC_CMPIPROVIDERINTERFACE, \
+            Tracer::LEVEL2, \
+            "Unknown exception")); \
+        PEG_METHOD_EXIT(); \
+        CMReturnWithString( \
+            (CMPIrc)CMPI_RC_ERROR_SYSTEM, \
+            (CMPIString*)string2CMPIString("Unknown exception")); \
+    }
+
 static CIMPropertyList getList(const char** l)
 {
     CIMPropertyList pl;
@@ -176,22 +252,8 @@ extern "C"
             PEG_METHOD_EXIT();
             return cmpiInst;
         }
-        catch (const CIMException &e)
-        {
-            PEG_TRACE_STRING(
-                TRC_CMPIPROVIDERINTERFACE,
-                Tracer::LEVEL2,
-                "Exception: " + e.getMessage());
-            if (rc)
-            {
-                CMSetStatusWithString(
-                    rc,
-                    (CMPIrc)e.getCode(),
-                    (CMPIString*)string2CMPIString(e.getMessage()));
-            }
-            PEG_METHOD_EXIT();
-            return NULL;
-        }
+        HandlerCatchSetStatus(rc, NULL);
+
         // Code flow should never get here.
     }
 
@@ -220,21 +282,8 @@ extern "C"
             PEG_METHOD_EXIT();
             return cmpiObjPath;
         }
-        catch (const CIMException &e)
-        {
-            PEG_TRACE_STRING(
-                TRC_CMPIPROVIDERINTERFACE,
-                Tracer::LEVEL2,
-                "Exception: " + e.getMessage());
-            if (rc)
-            {
-                CMSetStatusWithString(
-                    rc,(CMPIrc)e.getCode(),
-                    (CMPIString*)string2CMPIString(e.getMessage()));
-            }
-            PEG_METHOD_EXIT();
-            return NULL;
-        }
+        HandlerCatchSetStatus(rc, NULL);
+
         // Code flow should never get here.
     }
 
@@ -264,17 +313,8 @@ extern "C"
                 CM_IncludeQualifiers(flgs),
                 props);
         }
-        catch (const CIMException &e)
-        {
-            PEG_TRACE_STRING(
-                TRC_CMPIPROVIDERINTERFACE,
-                Tracer::LEVEL2,
-                "Exception: " + e.getMessage());
-            PEG_METHOD_EXIT();
-            CMReturnWithString(
-                (CMPIrc)e.getCode(),
-                (CMPIString*)string2CMPIString(e.getMessage()));
-        }
+        HandlerCatchReturnStatus();
+
         PEG_METHOD_EXIT();
         CMReturn(CMPI_RC_OK);
     }
@@ -300,17 +340,8 @@ extern "C"
                 CM_ObjectPath(cop)->getNameSpace(),
                 qop); //*CM_ObjectPath(cop));
         }
-        catch (const CIMException &e)
-        {
-            PEG_TRACE_STRING(
-                TRC_CMPIPROVIDERINTERFACE,
-                Tracer::LEVEL2,
-                "Exception: " + e.getMessage());
-            PEG_METHOD_EXIT();
-            CMReturnWithString(
-                (CMPIrc)e.getCode(),
-                (CMPIString*)string2CMPIString(e.getMessage()));
-        }
+        HandlerCatchReturnStatus();
+
         PEG_METHOD_EXIT();
         CMReturn(CMPI_RC_OK);
     }
@@ -341,22 +372,8 @@ extern "C"
             PEG_METHOD_EXIT();
             return cmpiEnum;
         }
-        catch (const CIMException &e)
-        {
-            PEG_TRACE_STRING(
-                TRC_CMPIPROVIDERINTERFACE,
-                Tracer::LEVEL2,
-                "Exception: " + e.getMessage());
-            if (rc)
-            {
-                CMSetStatusWithString(
-                    rc,
-                    (CMPIrc)e.getCode(),
-                    (CMPIString*)string2CMPIString(e.getMessage()));
-            }
-            PEG_METHOD_EXIT();
-            return NULL;
-        }
+        HandlerCatchSetStatus(rc, NULL);
+
         // Code flow should never get here.
     }
 
@@ -410,22 +427,8 @@ extern "C"
             PEG_METHOD_EXIT();
             return cmpiEnum;
         }
-        catch (const CIMException &e)
-        {
-            PEG_TRACE_STRING(
-                TRC_CMPIPROVIDERINTERFACE,
-                Tracer::LEVEL2,
-                "Exception: " + e.getMessage());
-            if (rc)
-            {
-                CMSetStatusWithString(
-                    rc,
-                    (CMPIrc)e.getCode(),
-                    (CMPIString*)string2CMPIString(e.getMessage()));
-            }
-            PEG_METHOD_EXIT();
-            return NULL;
-        }
+        HandlerCatchSetStatus(rc, NULL);
+
         // Code flow should never get here.
     }
 
@@ -463,22 +466,8 @@ extern "C"
             PEG_METHOD_EXIT();
             return cmpiEnum;
         }
-        catch (const CIMException &e)
-        {
-            PEG_TRACE_STRING(
-                TRC_CMPIPROVIDERINTERFACE,
-                Tracer::LEVEL2,
-                "Exception: " + e.getMessage());
-            if (rc)
-            {
-                CMSetStatusWithString(
-                    rc,
-                    (CMPIrc)e.getCode(),
-                    (CMPIString*)string2CMPIString(e.getMessage()));
-            }
-            PEG_METHOD_EXIT();
-            return NULL;
-        }
+        HandlerCatchSetStatus(rc, NULL);
+
         // Code flow should never get here.
     }
 
@@ -549,22 +538,8 @@ extern "C"
             PEG_METHOD_EXIT();
             return cmpiEnum;
         }
-        catch (const CIMException &e)
-        {
-            PEG_TRACE_STRING(
-                TRC_CMPIPROVIDERINTERFACE,
-                Tracer::LEVEL2,
-                "Exception: " + e.getMessage());
-            if (rc)
-            {
-                CMSetStatusWithString(
-                    rc,
-                    (CMPIrc)e.getCode(),
-                    (CMPIString*)string2CMPIString(e.getMessage()));
-            }
-            PEG_METHOD_EXIT();
-            return NULL;
-        }
+        HandlerCatchSetStatus(rc, NULL);
+
         // Code flow should never get here.
     }
 
@@ -624,22 +599,8 @@ extern "C"
             PEG_METHOD_EXIT();
             return cmpiEnum;
         }
-        catch (const CIMException &e)
-        {
-            PEG_TRACE_STRING(
-                TRC_CMPIPROVIDERINTERFACE,
-                Tracer::LEVEL2,
-                "Exception: " + e.getMessage());
-            if (rc)
-            {
-                CMSetStatusWithString(
-                    rc,
-                    (CMPIrc)e.getCode(),
-                    (CMPIString*)string2CMPIString(e.getMessage()));
-            }
-            PEG_METHOD_EXIT();
-            return NULL;
-        }
+        HandlerCatchSetStatus(rc, NULL);
+
         // Code flow should never get here.
     }
 
@@ -706,22 +667,8 @@ extern "C"
             PEG_METHOD_EXIT();
             return cmpiEnum;
         }
-        catch (const CIMException &e)
-        {
-            PEG_TRACE_STRING(
-                TRC_CMPIPROVIDERINTERFACE,
-                Tracer::LEVEL2,
-                "Exception: " + e.getMessage());
-            if (rc)
-            {
-                CMSetStatusWithString(
-                    rc,
-                    (CMPIrc)e.getCode(),
-                    (CMPIString*)string2CMPIString(e.getMessage()));
-            }
-            PEG_METHOD_EXIT();
-            return NULL;
-        }
+        HandlerCatchSetStatus(rc, NULL);
+
         // Code flow should never get here.
     }
 
@@ -778,22 +725,8 @@ extern "C"
             PEG_METHOD_EXIT();
             return cmpiEnum;
         }
-        catch (const CIMException &e)
-        {
-            PEG_TRACE_STRING(
-                TRC_CMPIPROVIDERINTERFACE,
-                Tracer::LEVEL2,
-                "Exception: " + e.getMessage());
-            if (rc)
-            {
-                CMSetStatusWithString(
-                    rc,
-                    (CMPIrc)e.getCode(),
-                    (CMPIString*)string2CMPIString(e.getMessage()));
-            }
-            PEG_METHOD_EXIT();
-            return NULL;
-        }
+        HandlerCatchSetStatus(rc, NULL);
+
         // Code flow should never get here.
     }
 
@@ -835,20 +768,8 @@ extern "C"
                 CMSetStatus(rc,CMPI_RC_OK);
             }
         }
-        catch (const CIMException &e)
-        {
-            PEG_TRACE_STRING(
-                TRC_CMPIPROVIDERINTERFACE,
-                Tracer::LEVEL2,
-                "Exception: " + e.getMessage());
-            if (rc)
-            {
-                CMSetStatusWithString(
-                    rc,
-                    (CMPIrc)e.getCode(),
-                    (CMPIString*)string2CMPIString(e.getMessage()));
-            }
-        }
+        HandlerCatchSetStatus(rc, data);
+
         PEG_METHOD_EXIT();
         return data; // "data" will be valid data or nullValue (in error case)
     }
@@ -877,17 +798,8 @@ extern "C"
                 String(name),
                 v);
         }
-        catch (const CIMException &e)
-        {
-            PEG_TRACE_STRING(
-                TRC_CMPIPROVIDERINTERFACE,
-                Tracer::LEVEL2,
-                "Exception: " + e.getMessage());
-            PEG_METHOD_EXIT();
-            CMReturnWithString(
-                (CMPIrc)e.getCode(),
-                (CMPIString*)string2CMPIString(e.getMessage()));
-        }
+        HandlerCatchReturnStatus();
+
         PEG_METHOD_EXIT();
         CMReturn(CMPI_RC_OK);
     }
@@ -917,14 +829,8 @@ extern "C"
             value2CMPIData(v,t,&data);
             CMSetStatus(rc,CMPI_RC_OK);
         }
-        catch (const CIMException &e)
-        {
-            PEG_TRACE_STRING(
-                TRC_CMPIPROVIDERINTERFACE,
-                Tracer::LEVEL2,
-                "Exception: " + e.getMessage());
-            CMSetStatus(rc,(CMPIrc)e.getCode());
-        }
+        HandlerCatchSetStatus(rc, data);
+
         PEG_METHOD_EXIT();
         return data; // "data" will be valid data or nullValue (in error case)
     }
@@ -1032,15 +938,7 @@ extern "C"
                     PEG_METHOD_EXIT();
                     CMReturn(CMPI_RC_OK);
                 }
-                catch (const CIMException &e)
-                {
-                    PEG_TRACE_STRING(
-                        TRC_CMPIPROVIDERINTERFACE,
-                        Tracer::LEVEL2,
-                        "Exception: " + e.getMessage());
-                    PEG_METHOD_EXIT();
-                    CMReturn((CMPIrc)e.getCode());
-                }
+                HandlerCatchReturnStatus();
             }
         }
         PEG_METHOD_EXIT();
@@ -1076,5 +974,3 @@ static CMPIBrokerFT broker_FT =
 CMPIBrokerFT *CMPI_Broker_Ftab = & broker_FT;
 
 PEGASUS_NAMESPACE_END
-
-