(file) Return to errorutil.c CVS log (file) (dir) Up to [OMI] / omi / omi_error

  1 krisbash 1.1 #include "errorutil.h"
  2              #include "OMI_Error.h"
  3              #include "omierror.h"
  4              #include <base/log.h>
  5              #include <base/packing.h>
  6              #include <wsman/wsbuf.h>
  7              
  8              /*
  9              **==============================================================================
 10              **
 11              ** Helper to create PostResultMsg
 12              **
 13              **==============================================================================
 14              */
 15              _Use_decl_annotations_
 16              PostResultMsg* PostResultMsg_NewAndSerialize(
 17                  Message* req,
 18                  const MI_Instance* err,
 19                  const MI_Char* errmsg,
 20                  const MI_Char *errorType,
 21                  MI_Uint32 r)
 22 krisbash 1.1 {
 23                  PostResultMsg* msg = NULL;
 24                  const MI_Instance* error = err;
 25                  MI_Result result = MI_RESULT_OK;
 26                  DEBUG_ASSERT( req );
 27                  msg = PostResultMsg_New(req->operationId);
 28                  if (!msg)
 29                  {
 30                      return NULL;
 31                  }
 32              
 33                  if (!error)
 34                  {
 35                      OMI_ErrorFromErrorCode(
 36                          msg->base.batch,
 37                          r,
 38                          errorType,
 39                          errmsg,
 40                          (OMI_Error**)&error);
 41                  }
 42                  if (error)
 43 krisbash 1.1     {
 44                      MI_Value value;
 45                      MI_Type type;
 46                      MI_Result result;
 47                  
 48                      result = MI_Instance_GetElement(error, MI_T("CIMStatusCode"), &value, &type, NULL, NULL);
 49                      if ((MI_RESULT_OK == result) && (type == MI_UINT32))
 50                      {
 51                          r = value.uint32;
 52                      }
 53                      else
 54                      {
 55                          /* failed to get real status code so assume failed */
 56                          r = MI_RESULT_FAILED;
 57                      }
 58                  }
 59                  else if (Tcscmp(errorType, MI_RESULT_TYPE_MI) != 0)
 60                  {
 61                      /* convert non-MI result to an MI result */
 62                      r = MI_RESULT_FAILED;
 63                  }
 64 krisbash 1.1 
 65                  /* create final result message */
 66                  do
 67                  {
 68                      if (error && (errmsg == NULL))
 69                      {
 70                          MI_Value messageValue;
 71                          MI_Type messageType;
 72              
 73                          result = MI_Instance_GetElement(error, MI_T("Message"), &messageValue, &messageType, NULL, NULL);
 74                          if ((MI_RESULT_OK == result) && (MI_STRING == messageType))
 75                          {
 76                              errmsg = Batch_Tcsdup(msg->base.batch, messageValue.string);
 77                          }
 78                      }
 79                      msg->result = (MI_Result)r;
 80                      if (errmsg)
 81                      {
 82                          msg->errorMessage = Batch_Tcsdup(msg->base.batch, errmsg);
 83                      }
 84                      else
 85 krisbash 1.1         {
 86                          msg->errorMessage = NULL;
 87                      }
 88                      msg->cimError = error;
 89                      msg->packedInstancePtr = NULL;
 90                      msg->packedInstanceSize = 0;
 91                      msg->cimErrorClassName = NULL;
 92              
 93                      if (error)
 94                      {
 95                          if (req->flags & WSMANFlag)
 96                          {
 97                              /* This puts a pretty bad dependency on a bunch of stuff so we are removing this from 
 98                               * from minimum size build and relying on default WSman IF and ONLY if that is needed.
 99                               * The results will have default values for the error case in that case.
100                               */
101                              result = WSBuf_InstanceToBuf(
102                                  USERAGENT_UNKNOWN,
103                                  error,
104                                  NULL, /* filterProperty */
105                                  NULL, /* filterPropertyData */
106 krisbash 1.1                     error->classDecl,
107                                  msg->base.batch,
108                                  WSMAN_ObjectFlag | WSMAN_IsCimError,
109                                  &msg->packedInstancePtr, 
110                                  &msg->packedInstanceSize);
111                              if (result != MI_RESULT_OK)
112                                  break;
113                              msg->base.flags |= req->flags;
114                          }
115                          else /* Binary protocol */
116                          {
117                              result = InstanceToBatch(
118                                  error,
119                                  NULL,
120                                  NULL,
121                                  msg->base.batch,
122                                  &msg->packedInstancePtr,
123                                  &msg->packedInstanceSize);
124                              if (result != MI_RESULT_OK)
125                                  break;
126                              msg->base.flags |= BinaryProtocolFlag;
127 krisbash 1.1             }
128                          msg->cimErrorClassName = Batch_Tcsdup(msg->base.batch, error->classDecl->name);
129                      }
130                  }
131                  while(0);
132              
133                  if ((result != MI_RESULT_OK) && (NULL != msg))
134                  {
135                      /* TODO: Trace message */
136                      PostResultMsg_Release(msg);
137                      msg = NULL;
138                  }
139              
140                  return msg;
141              }
142              

ViewCVS 0.9.2