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

Diff for /omi/wsman/wsbuf.c between version 1.2 and 1.3

version 1.2, 2015/04/20 18:10:36 version 1.3, 2015/04/20 18:20:37
Line 27 
Line 27 
 #include <base/log.h> #include <base/log.h>
 #include <base/result.h> #include <base/result.h>
 #include <base/instance.h> #include <base/instance.h>
 #include <base/strings.h>  #include <pal/strings.h>
 #include <base/field.h> #include <base/field.h>
 #include <base/messages.h> #include <base/messages.h>
 #include <base/helpers.h> #include <base/helpers.h>
 #include <base/time.h>  #include <pal/sleep.h>
 #include <base/io.h>  #include <pal/format.h>
 #include <base/base64.h> #include <base/base64.h>
   #include <xmlserializer/xmlserializer.h>
   #include <omi_error/omierror.h>
   
  
 #if defined(WSBUF_DISABLE_INLINING) #if defined(WSBUF_DISABLE_INLINING)
 # include "wsbufinline.h" # include "wsbufinline.h"
 #endif #endif
  
 #define T MI_T  
   
 #if 0 #if 0
 #define ENABLE_TRACING #define ENABLE_TRACING
 #endif #endif
Line 51 
Line 52 
 #define PRINTF(a) #define PRINTF(a)
 #endif #endif
  
 #define XML_CR MI_T("\n")  #define XML_CR ZT("\n")
  
 /* /*
 **============================================================================== **==============================================================================
Line 62 
Line 63 
 */ */
 typedef struct _BUF_FaultItem typedef struct _BUF_FaultItem
 { {
     const MI_Char* action;      const ZChar* action;
     MI_Uint32 actionSize;     MI_Uint32 actionSize;
     const char* code; /* sender/receiver */     const char* code; /* sender/receiver */
     const char* subCode; /* wsa:XXX */     const char* subCode; /* wsa:XXX */
     const char* defaultTest;      const ZChar* defaultText;
 } }
 BUF_FaultItem; BUF_FaultItem;
  
 typedef struct _BUF_CIMErrorItem typedef struct _BUF_CIMErrorItem
 { {
     WSBUF_FAULT_CODE faultCode;     WSBUF_FAULT_CODE faultCode;
     const MI_Char* description;      const ZChar* description;
 } }
 BUF_CIMErrorItem; BUF_CIMErrorItem;
  
Line 86 
Line 87 
 */ */
 static MI_Result _PackInstance( static MI_Result _PackInstance(
     WSBuf* buf,     WSBuf* buf,
       UserAgent userAgent,
     const MI_Instance* instance,     const MI_Instance* instance,
     MI_Boolean (*filterProperty)(const MI_Char* name, void* data),      MI_Boolean(*filterProperty)(const ZChar* name, void* data),
     void* filterPropertyData,     void* filterPropertyData,
     const MI_ClassDecl* castToClassDecl,     const MI_ClassDecl* castToClassDecl,
     MI_Uint32 flags,     MI_Uint32 flags,
     MI_Boolean embedded);      MI_Boolean embedded,
       const ZChar* propName,
       MI_Uint32 *lastPrefixIndex,
       const ZChar* parentNSPrefix); //optional
  
 static MI_Result _PackEPR( static MI_Result _PackEPR(
     WSBuf* buf,     WSBuf* buf,
     const MI_Instance* instance);      UserAgent userAgent,
       const MI_Instance* instance,
       MI_Uint32 flags);
  
 /* /*
 **============================================================================== **==============================================================================
Line 108 
Line 115 
 static const BUF_FaultItem s_faults[] = { static const BUF_FaultItem s_faults[] = {
     /* WSBUF_FAULT_INTERNAL_ERROR */     /* WSBUF_FAULT_INTERNAL_ERROR */
     {     {
         LIT(MI_T("http://schemas.dmtf.org/wbem/wsman/1/wsman/fault")),          LIT(ZT("http://schemas.dmtf.org/wbem/wsman/1/wsman/fault")),
         "SOAP-ENV:Receiver",         "SOAP-ENV:Receiver",
         "wsman:InternalError",         "wsman:InternalError",
         "The service cannot comply with the request due to internal processing errors."          ZT("The service cannot comply with the request due to internal processing errors.")
     },     },
     /* WSBUF_FAULT_NOT_SUPPORTED */     /* WSBUF_FAULT_NOT_SUPPORTED */
     {     {
         LIT(MI_T("http://schemas.dmtf.org/wbem/wsman/1/wsman/fault")),          LIT(ZT("http://schemas.dmtf.org/wbem/wsman/1/wsman/fault")),
         "SOAP-ENV:Sender",         "SOAP-ENV:Sender",
         "wsman:UnsupportedFeature",         "wsman:UnsupportedFeature",
         "not supported"          ZT("not supported")
     },     },
     /* WSBUF_FAULT_NOT_UNDERSTOOD */     /* WSBUF_FAULT_NOT_UNDERSTOOD */
     {     {
         LIT(MI_T("http://schemas.xmlsoap.org/ws/2004/08/addressing/fault")),          LIT(ZT("http://schemas.xmlsoap.org/ws/2004/08/addressing/fault")),
         "SOAP-ENV:MustUnderstand",         "SOAP-ENV:MustUnderstand",
         0,         0,
         "Header not understood"          ZT("Header not understood")
     },     },
     /* WSBUF_FAULT_DESTINATION_UNREACHABLE */     /* WSBUF_FAULT_DESTINATION_UNREACHABLE */
     {     {
         LIT(MI_T("http://schemas.xmlsoap.org/ws/2004/08/addressing/fault")),          LIT(ZT("http://schemas.xmlsoap.org/ws/2004/08/addressing/fault")),
         "SOAP-ENV:Sender",         "SOAP-ENV:Sender",
         "wsa:DestinationUnreachable",         "wsa:DestinationUnreachable",
         "No route can be determined to reach the destination role defined by the Addressing To header."          ZT("No route can be determined to reach the destination role defined by the Addressing To header.")
     },     },
     /* WSBUF_FAULT_ACCESS_DENIED */     /* WSBUF_FAULT_ACCESS_DENIED */
     {     {
         LIT(MI_T("http://schemas.dmtf.org/wbem/wsman/1/wsman/fault")),          LIT(ZT("http://schemas.dmtf.org/wbem/wsman/1/wsman/fault")),
         "SOAP-ENV:Sender",         "SOAP-ENV:Sender",
         "wsman:AccessDenied",         "wsman:AccessDenied",
         "The sender was not authorized to access the resource."          ZT("The sender was not authorized to access the resource.")
     },     },
     /* WSBUF_FAULT_ENCODING_LIMIT */     /* WSBUF_FAULT_ENCODING_LIMIT */
     {     {
         LIT(MI_T("http://schemas.dmtf.org/wbem/wsman/1/wsman/fault")),          LIT(ZT("http://schemas.dmtf.org/wbem/wsman/1/wsman/fault")),
         "SOAP-ENV:Sender",         "SOAP-ENV:Sender",
         "wsman:EncodingLimit",         "wsman:EncodingLimit",
         "An internal encoding limit was exceeded in a request or would be violated if the message were processed."          ZT("An internal encoding limit was exceeded in a request or would be violated if the message were processed.")
       },
       /* WSBUF_FAULT_INVALID_EXPIRATION_TIME */
       {
           LIT(ZT("http://schemas.dmtf.org/wbem/wsman/1/wsman/fault")),
           "SOAP-ENV:Sender",
           "wsman:InvalidExpirationTime",
           ZT("The request specified an invalid expiration time that cannot be supported (zero or in the past).")
       },
       /* WSBUF_FAULT_UNSUPPORTED_EXPIRATION_TIME */
       {
           LIT(ZT("http://schemas.dmtf.org/wbem/wsman/1/wsman/fault")),
           "SOAP-ENV:Sender",
           "wsman:UnsupportedExpirationTime",
           ZT("Only xs:duration expiration values are supported.")
       },
       /* WSBUF_FAULT_TIMED_OUT */
       {
           LIT(ZT("http://schemas.dmtf.org/wbem/wsman/1/wsman/fault")),
           "SOAP-ENV:Receiver",
           "wsman:TimedOut",
           ZT("The operation has timed out.")
       },
       /* WSBUF_FAULT_INVALID_MESSAGE_INFORMATION_HEADER */
       {
           LIT(ZT("http://schemas.xmlsoap.org/ws/2004/08/addressing/fault")),
           "SOAP-ENV:Sender",
           "wsa:InvalidMessageInformationHeader",
           ZT("The request specified an invalid header property.")
       },
       /* WSBUF_FAULT_INVALID_HEARTBEAT */
       {
           LIT(ZT("http://schemas.dmtf.org/wbem/wsman/1/wsman/faultDetail/Heartbeats")),
           "SOAP-ENV:Sender",
           "wsman:UnsupportedFeature",
           ZT("The request specified an invalid heartbeat.")
       },
       /* WSBUF_FAULT_ACTION_NOT_SUPPORTED */
       {
           LIT(ZT("http://schemas.xmlsoap.org/ws/2004/08/addressing/fault")),
           "SOAP-ENV:Sender",
           "wsa:ActionNotSupported",
           ZT("The request specified an unsupported action.")
       },
       /* WSBUF_FAULT_CONNECTION_RETRY_NOT_SUPPORTED */
       {
           LIT(ZT("http://schemas.dmtf.org/wbem/wsman/1/wsman/faultDetail/DeliveryRetries")),
           "SOAP-ENV:Sender",
           "wsman:UnsupportedFeature",
           ZT("Connection retry is not supported.")
       },
       /* WSBUF_FAULT_BOOKMARK_INVALID_FORMAT */
       {
           LIT(ZT("http://schemas.dmtf.org/wbem/wsman/1/wsman/faultDetail/InvalidFormat")),
           "SOAP-ENV:Sender",
           "wsman:InvalidBookmark",
           ZT("Bookmark must be non-empty if specified.")
     }     }
 }; };
  
Line 159 
Line 222 
     /* MI_RESULT_FAILED = 1, */     /* MI_RESULT_FAILED = 1, */
     {     {
         WSBUF_FAULT_INTERNAL_ERROR,         WSBUF_FAULT_INTERNAL_ERROR,
         MI_T("CIM ERROR:FAILED: A general error occurred, not covered by a more specific error code.")          ZT("CIM ERROR:FAILED: A general error occurred, not covered by a more specific error code.")
     },     },
  
     /* MI_RESULT_ACCESS_DENIED = 2, */     /* MI_RESULT_ACCESS_DENIED = 2, */
     {     {
         WSBUF_FAULT_ACCESS_DENIED,         WSBUF_FAULT_ACCESS_DENIED,
         MI_T("CIM ERROR:ACCESS_DENIED: Access to a CIM resource is not available to the client.")          ZT("CIM ERROR:ACCESS_DENIED: Access to a CIM resource is not available to the client.")
     },     },
  
     /* MI_RESULT_INVALID_NAMESPACE = 3, */     /* MI_RESULT_INVALID_NAMESPACE = 3, */
     {     {
         WSBUF_FAULT_DESTINATION_UNREACHABLE,         WSBUF_FAULT_DESTINATION_UNREACHABLE,
         MI_T("CIM ERROR:INVALID_NAMESPACE: The target namespace does not exist.")          ZT("CIM ERROR:INVALID_NAMESPACE: The target namespace does not exist.")
     },     },
  
     /* MI_RESULT_INVALID_PARAMETER  = 4,*/     /* MI_RESULT_INVALID_PARAMETER  = 4,*/
     {     {
         WSBUF_FAULT_INTERNAL_ERROR,         WSBUF_FAULT_INTERNAL_ERROR,
         MI_T("CIM ERROR:INVALID_PARAMETER: One or more parameter values passed to the method are not valid.")          ZT("CIM ERROR:INVALID_PARAMETER: One or more parameter values passed to the method are not valid.")
     },     },
  
     /* MI_RESULT_INVALID_CLASS = 5, */     /* MI_RESULT_INVALID_CLASS = 5, */
     {     {
         WSBUF_FAULT_DESTINATION_UNREACHABLE,         WSBUF_FAULT_DESTINATION_UNREACHABLE,
         MI_T("CIM ERROR:INVALID_CLASS: The specified class does not exist.")          ZT("CIM ERROR:INVALID_CLASS: The specified class does not exist.")
     },     },
  
     /* MI_RESULT_NOT_FOUND = 6,*/     /* MI_RESULT_NOT_FOUND = 6,*/
     {     {
         WSBUF_FAULT_DESTINATION_UNREACHABLE,         WSBUF_FAULT_DESTINATION_UNREACHABLE,
         MI_T("CIM ERROR:NOT_FOUND: The requested object cannot be found.")          ZT("CIM ERROR:NOT_FOUND: The requested object cannot be found.")
     },     },
  
     /* MI_RESULT_NOT_SUPPORTED = 7, */     /* MI_RESULT_NOT_SUPPORTED = 7, */
     {     {
         WSBUF_FAULT_NOT_SUPPORTED,         WSBUF_FAULT_NOT_SUPPORTED,
         MI_T("CIM ERROR:NOT_SUPPORTED: The requested operation is not supported.")          ZT("CIM ERROR:NOT_SUPPORTED: The requested operation is not supported.")
     }     }
  
 #if 0 #if 0
Line 258 
Line 321 
 #endif #endif
 }; };
  
   #if defined(_MSC_VER)
   #pragma warning( push )
   #pragma warning( disable : 4125 )
   #endif
   
 /* Encodings for special XML characters */ /* Encodings for special XML characters */
 static const char* s_specialCharEncodings[128] =  static const ZChar* s_specialCharEncodings[128] =
 { {
     "\004&#0;",      ZT("\004&#0;"),
     "\004&#1;",      ZT("\004&#1;"),
     "\004&#2;",      ZT("\004&#2;"),
     "\004&#3;",      ZT("\004&#3;"),
     "\004&#4;",      ZT("\004&#4;"),
     "\004&#5;",      ZT("\004&#5;"),
     "\004&#6;",      ZT("\004&#6;"),
     "\004&#7;",      ZT("\004&#7;"),
     "\004&#8;",      ZT("\004&#8;"),
     "\004&#9;",      ZT("\004&#9;"),
     "\005&#10;",      ZT("\005&#10;"),
     "\005&#11;",      ZT("\005&#11;"),
     "\005&#12;",      ZT("\005&#12;"),
     "\005&#13;",      ZT("\005&#13;"),
     "\005&#14;",      ZT("\005&#14;"),
     "\005&#15;",      ZT("\005&#15;"),
     "\005&#16;",      ZT("\005&#16;"),
     "\005&#17;",      ZT("\005&#17;"),
     "\005&#18;",      ZT("\005&#18;"),
     "\005&#19;",      ZT("\005&#19;"),
     "\005&#20;",      ZT("\005&#20;"),
     "\005&#21;",      ZT("\005&#21;"),
     "\005&#22;",      ZT("\005&#22;"),
     "\005&#23;",      ZT("\005&#23;"),
     "\005&#24;",      ZT("\005&#24;"),
     "\005&#25;",      ZT("\005&#25;"),
     "\005&#26;",      ZT("\005&#26;"),
     "\005&#27;",      ZT("\005&#27;"),
     "\005&#28;",      ZT("\005&#28;"),
     "\005&#29;",      ZT("\005&#29;"),
     "\005&#30;",      ZT("\005&#30;"),
     "\005&#31;",      ZT("\005&#31;"),
     "\001 ",      ZT("\001 "),
     "\001!",      ZT("\001!"),
     "\006&quot;",      ZT("\006&quot;"),
     "\001#",      ZT("\001#"),
     "\001$",      ZT("\001$"),
     "\001%",      ZT("\001%"),
     "\005&amp;",      ZT("\005&amp;"),
     "\006&apos;",      ZT("\006&apos;"),
     "\001(",      ZT("\001("),
     "\001)",      ZT("\001)"),
     "\001*",      ZT("\001*"),
     "\001+",      ZT("\001+"),
     "\001,",      ZT("\001,"),
     "\001-",      ZT("\001-"),
     "\001.",      ZT("\001."),
     "\001/",      ZT("\001/"),
     "\0010",      ZT("\0010"),
     "\0011",      ZT("\0011"),
     "\0012",      ZT("\0012"),
     "\0013",      ZT("\0013"),
     "\0014",      ZT("\0014"),
     "\0015",      ZT("\0015"),
     "\0016",      ZT("\0016"),
     "\0017",      ZT("\0017"),
     "\0018",      ZT("\0018"),
     "\0019",      ZT("\0019"),
     "\001:",      ZT("\001:"),
     "\001;",      ZT("\001;"),
     "\004&lt;",      ZT("\004&lt;"),
     "\001=",      ZT("\001="),
     "\004&gt;",      ZT("\004&gt;"),
     "\001?",      ZT("\001?"),
     "\001@",      ZT("\001@"),
     "\001A",      ZT("\001A"),
     "\001B",      ZT("\001B"),
     "\001C",      ZT("\001C"),
     "\001D",      ZT("\001D"),
     "\001E",      ZT("\001E"),
     "\001F",      ZT("\001F"),
     "\001G",      ZT("\001G"),
     "\001H",      ZT("\001H"),
     "\001I",      ZT("\001I"),
     "\001J",      ZT("\001J"),
     "\001K",      ZT("\001K"),
     "\001L",      ZT("\001L"),
     "\001M",      ZT("\001M"),
     "\001N",      ZT("\001N"),
     "\001O",      ZT("\001O"),
     "\001P",      ZT("\001P"),
     "\001Q",      ZT("\001Q"),
     "\001R",      ZT("\001R"),
     "\001S",      ZT("\001S"),
     "\001T",      ZT("\001T"),
     "\001U",      ZT("\001U"),
     "\001V",      ZT("\001V"),
     "\001W",      ZT("\001W"),
     "\001X",      ZT("\001X"),
     "\001Y",      ZT("\001Y"),
     "\001Z",      ZT("\001Z"),
     "\001[",      ZT("\001["),
     "\001\\",      ZT("\001\\"),
     "\001]",      ZT("\001]"),
     "\001^",      ZT("\001^"),
     "\001_",      ZT("\001_"),
     "\001`",      ZT("\001`"),
     "\001a",      ZT("\001a"),
     "\001b",      ZT("\001b"),
     "\001c",      ZT("\001c"),
     "\001d",      ZT("\001d"),
     "\001e",      ZT("\001e"),
     "\001f",      ZT("\001f"),
     "\001g",      ZT("\001g"),
     "\001h",      ZT("\001h"),
     "\001i",      ZT("\001i"),
     "\001j",      ZT("\001j"),
     "\001k",      ZT("\001k"),
     "\001l",      ZT("\001l"),
     "\001m",      ZT("\001m"),
     "\001n",      ZT("\001n"),
     "\001o",      ZT("\001o"),
     "\001p",      ZT("\001p"),
     "\001q",      ZT("\001q"),
     "\001r",      ZT("\001r"),
     "\001s",      ZT("\001s"),
     "\001t",      ZT("\001t"),
     "\001u",      ZT("\001u"),
     "\001v",      ZT("\001v"),
     "\001w",      ZT("\001w"),
     "\001x",      ZT("\001x"),
     "\001y",      ZT("\001y"),
     "\001z",      ZT("\001z"),
     "\001{",      ZT("\001{"),
     "\001|",      ZT("\001|"),
     "\001}",      ZT("\001}"),
     "\001~",      ZT("\001~"),
     "\006&#127;",      ZT("\006&#127;"),
 }; };
  
   #if defined(_MSC_VER)
   #pragma warning( pop )
   #endif
   
 /* This table idnetifies special XML characters. */ /* This table idnetifies special XML characters. */
 static const char s_specialChars[256] = static const char s_specialChars[256] =
 { {
Line 427 
Line 499 
     /* round up to next 1k */     /* round up to next 1k */
 #define WSMAN_BUF_CAPACITY 1024 #define WSMAN_BUF_CAPACITY 1024
     newSize = ((newSize + WSMAN_BUF_CAPACITY) / WSMAN_BUF_CAPACITY)  * WSMAN_BUF_CAPACITY;     newSize = ((newSize + WSMAN_BUF_CAPACITY) / WSMAN_BUF_CAPACITY)  * WSMAN_BUF_CAPACITY;
     new_page = (Page*)realloc(buf->page, sizeof(Page) + newSize);      new_page = (Page*)PAL_Realloc(buf->page, sizeof(Page)+ newSize);
  
     if (!new_page)     if (!new_page)
         return MI_RESULT_FAILED;         return MI_RESULT_FAILED;
Line 496 
Line 568 
 ** **
 **============================================================================== **==============================================================================
 */ */
   
 MI_Result WSBuf_Init( MI_Result WSBuf_Init(
     WSBuf* buf,     WSBuf* buf,
     MI_Uint32 initialSize)     MI_Uint32 initialSize)
 { {
     buf->page = (Page*)malloc(sizeof(Page) + initialSize);      buf->page = (Page*)PAL_Malloc(sizeof(Page)+ initialSize);
     buf->position = 0;     buf->position = 0;
  
     if (!buf->page)     if (!buf->page)
Line 511 
Line 584 
     buf->page->u.s.size = initialSize;     buf->page->u.s.size = initialSize;
     buf->page->u.s.next = 0;     buf->page->u.s.next = 0;
     /* Put empty string inside */     /* Put empty string inside */
     ((MI_Char*)(buf->page +1))[0] = 0;      ((ZChar*)(buf->page +1))[0] = 0;
     return MI_RESULT_OK;     return MI_RESULT_OK;
 } }
  
Line 519 
Line 592 
     WSBuf* buf)     WSBuf* buf)
 { {
     if (buf->page)     if (buf->page)
         free(buf->page);          PAL_Free(buf->page);
  
     return MI_RESULT_OK;     return MI_RESULT_OK;
 } }
  
 #if (MI_CHAR_TYPE == 1)  
 Page* WSBuf_StealPage( Page* WSBuf_StealPage(
     WSBuf* buf)     WSBuf* buf)
 { {
Line 539 
Line 611 
  
     return res;     return res;
 } }
 #else  
 Page* WSBuf_StealPage(  MI_Result WSBuf_AddUint32(
     WSBuf* buf)      WSBuf* buf,
       MI_Uint32 x)
 { {
       ZChar tmp[12];
       size_t size;
       const ZChar* s = Uint32ToZStr(tmp, x, &size);
       return WSBuf_AddLit(buf, s, (MI_Uint32)size);
   }
  
     if (!buf->page)  MI_Result __WSBuf_AddLit(
         return 0;      WSBuf* buf,
       const ZChar* str,
       MI_Uint32 size)
   {
       MI_Uint32 n = (size + 1)* sizeof(ZChar);
  
     /* convert wchar_t to utf-8      /* Extend buffer (WSBuf_AddLit determined it was too small)*/
         unfortunately, Windows does not support wchat -> utf8 conversion in crt */      if (_ReallocPage(buf, n + buf->position)!= MI_RESULT_OK)
           return MI_RESULT_FAILED;
  
       /* Add string */
     {     {
         Page* res;          char* data = ((char*)(buf->page+1))+ buf->position;
         const MI_Char* text = ((MI_Char*)(buf->page +1));          memcpy(data, str, n - sizeof(ZChar));
         int size = WideCharToMultiByte(CP_UTF8, 0, text, -1, NULL, 0, 0, NULL);          ((ZChar*)data)[size] = 0;
   
         if (size == 0)  
             goto failed;  
  
         res = (Page*)malloc(sizeof(Page) + size);          buf->position += n - sizeof(ZChar);
       }
  
         if (!res)      return MI_RESULT_OK;
             goto failed;  }
  
         if (WideCharToMultiByte(CP_UTF8, 0, text, -1, (char*)(res + 1), size, 0, NULL) == 0)  MI_Result WSBuf_AddStartTag(
       WSBuf* buf,
       const ZChar* tag,
       MI_Uint32 size)
         {         {
             free(res);      /* Add 2 bytes for "<" and ">" */
             goto failed;      MI_Uint32 n = (size + 1 + 2)* sizeof(ZChar);
         }  
  
         res->u.s.size = size - 1;      /* Extend buffer (WSBuf_AddLit determined it was too small)*/
         res->u.s.next = 0;      if (_ReallocPage(buf, n + buf->position)!= MI_RESULT_OK)
           return MI_RESULT_FAILED;
  
         free(buf->page);      /* Add string */
         buf->page = 0;      {
         buf->position = 0;          ZChar* data = (ZChar*)(((char*)(buf->page+1))+ buf->position);
         return res;          data[0] = '<';
     }          memcpy(data + 1, tag, n - sizeof(ZChar));
           data[size + 1] = '>';
           data[size + 2] = 0;
  
 failed:          buf->position += n - sizeof(ZChar);
     free(buf->page);  
     buf->page = 0;  
     return 0;  
 } }
 #endif  
  
 MI_Result WSBuf_AddUint32(      return MI_RESULT_OK;
     WSBuf* buf,  
     MI_Uint32 x)  
 {  
     MI_Char tmp[12];  
     size_t size;  
     const MI_Char* s = Uint32ToZStr(tmp, x, &size);  
     return WSBuf_AddLit(buf, s, (MI_Uint32)size);  
 } }
  
 MI_Result __WSBuf_AddLit(  MI_Result WSBuf_AddEndTag(
     WSBuf* buf,     WSBuf* buf,
     const MI_Char* str,      const ZChar* tag,
     MI_Uint32 size)     MI_Uint32 size)
 { {
     MI_Uint32 n = (size + 1) * sizeof(MI_Char);      /* Add 3 bytes for "</" and ">" */
       MI_Uint32 n = (size + 1 + 3)* sizeof(ZChar);
  
     /* Extend buffer (WSBuf_AddLit determined it was too small) */     /* Extend buffer (WSBuf_AddLit determined it was too small) */
     if (_ReallocPage(buf, n + buf->position) != MI_RESULT_OK)     if (_ReallocPage(buf, n + buf->position) != MI_RESULT_OK)
Line 608 
Line 685 
  
     /* Add string */     /* Add string */
     {     {
         char* data = ((char*)(buf->page+1)) + buf->position;          ZChar* data = (ZChar*)(((char*)(buf->page+1))+ buf->position);
         memcpy( data, str, n - sizeof(MI_Char));          data[0] = '<';
         ((MI_Char*)data)[size] = 0;          data[1] = '/';
           memcpy(data + 2, tag, n - sizeof(ZChar));
           data[size + 2] = '>';
           data[size + 3] = 0;
  
         buf->position += n - sizeof(MI_Char);          buf->position += n - sizeof(ZChar);
     }     }
  
     return MI_RESULT_OK;     return MI_RESULT_OK;
Line 621 
Line 701 
 /* Add string with proper xml encoding */ /* Add string with proper xml encoding */
 MI_Result WSBuf_AddString( MI_Result WSBuf_AddString(
     WSBuf* buf,     WSBuf* buf,
     const MI_Char* str)      const ZChar* str)
 { {
 #if (MI_CHAR_TYPE == 1) #if (MI_CHAR_TYPE == 1)
   
     /* Process leading non-special characters in the hope that little will     /* Process leading non-special characters in the hope that little will
      * be left over to be encoded the expensive way below this block.      * be left over to be encoded the expensive way below this block.
      */      */
Line 645 
Line 726 
         if (!*str)         if (!*str)
             return MI_RESULT_OK;             return MI_RESULT_OK;
     }     }
   
 #endif #endif
  
     /* Now encode what remains (starting with first special char hit above) */     /* Now encode what remains (starting with first special char hit above) */
     {     {
         /*MI_Uint32 size = (MI_Uint32)((MI_Strlen(str) + 1)*sizeof(MI_Char));*/          /*MI_Uint32 size = (MI_Uint32)((MI_Strlen(str)+ 1)*sizeof(ZChar));*/
         MI_Char* pos = (MI_Char*)(((char*)(buf->page +1)) + buf->position);          ZChar* start = (ZChar*)(((char*)(buf->page +1))+ buf->position);
         MI_Char* end = (MI_Char*)(((char*)(buf->page +1)) + buf->page->u.s.size);          ZChar* pos = start;
           ZChar* end = (ZChar*)(((char*)(buf->page +1))+ buf->page->u.s.size);
         /* Add reamingin characters (next character is special) */         /* Add reamingin characters (next character is special) */
         while (*str)         while (*str)
         {         {
             const MI_Char* item;              const ZChar* item;
             size_t size_chars;             size_t size_chars;
             MI_Uint32 c = (MI_Uint32)(MI_Sint16)*str;             MI_Uint32 c = (MI_Uint32)(MI_Sint16)*str;
  
Line 677 
Line 759 
             if ( (size_t)(end - pos) <= (size_chars + 1))             if ( (size_t)(end - pos) <= (size_chars + 1))
             {             {
                 size_t current_pos =                 size_t current_pos =
                     (pos - ((MI_Char*)(buf->page +1))) * sizeof(MI_Char);                      (pos - ((ZChar*)(buf->page +1)))* sizeof(ZChar);
  
                 if (_ReallocPage(buf, (MI_Uint32)(buf->page->u.s.size + size_chars * sizeof(MI_Char))) != MI_RESULT_OK)                  if (_ReallocPage(buf, (MI_Uint32)(buf->page->u.s.size + size_chars * sizeof(ZChar)))!= MI_RESULT_OK)
                     return MI_RESULT_FAILED;                     return MI_RESULT_FAILED;
  
                 pos = (MI_Char*)(((char*)(buf->page +1)) + current_pos);                  pos = (ZChar*)(((char*)(buf->page +1))+ current_pos);
                 end = (MI_Char*)(((char*)(buf->page +1)) + buf->page->u.s.size);                  end = (ZChar*)(((char*)(buf->page +1))+ buf->page->u.s.size);
             }             }
  
             if (1 == size_chars)             if (1 == size_chars)
                 *pos = *item;                 *pos = *item;
             else             else
                 memcpy( pos, item, size_chars * sizeof(MI_Char));                  memcpy(pos, item, size_chars * sizeof(ZChar));
  
             pos += size_chars;             pos += size_chars;
             str++;             str++;
         }         }
  
         buf->position = (MI_Uint32)((pos - ((MI_Char*)(buf->page +1))) * sizeof(MI_Char));          buf->position = (MI_Uint32)((pos - ((ZChar*)(buf->page +1)))* sizeof(ZChar));
  
         /* put \0 at the end */         /* put \0 at the end */
         ((MI_Char*)(((char*)(buf->page +1)) + buf->position))[0] = 0;          ((ZChar*)(((char*)(buf->page +1))+ buf->position))[0] = 0;
  
         return MI_RESULT_OK;         return MI_RESULT_OK;
     }     }
 } }
  
 #if (MI_CHAR_TYPE != 1)  #if defined(CONFIG_ENABLE_WCHAR)
 MI_Result WSBuf_AddCharStringNoEncoding(  
     WSBuf* buf,  
     const char* str)  
 {  
     return WSBuf_AddCharLit(buf, str, (MI_Uint32)strlen(str));  
 }  
   
 MI_Result WSBuf_AddCharLit( MI_Result WSBuf_AddCharLit(
     WSBuf* buf,     WSBuf* buf,
     const char* str,     const char* str,
     MI_Uint32 size_)     MI_Uint32 size_)
 { {
     MI_Uint32 size = (MI_Uint32)((size_ + 1)*sizeof(MI_Char));      MI_Uint32 size = (MI_Uint32)((size_ + 1)*sizeof(ZChar));
  
     /* Extend buffer if needed */     /* Extend buffer if needed */
     if (size + buf->position > buf->page->u.s.size &&     if (size + buf->position > buf->page->u.s.size &&
Line 725 
Line 800 
         return MI_RESULT_FAILED;         return MI_RESULT_FAILED;
  
     {     {
         MI_Char* data = (MI_Char*)(((char*)(buf->page +1)) + buf->position);          ZChar* data = (ZChar*)(((char*)(buf->page +1))+ buf->position);
         MI_Uint32 i;         MI_Uint32 i;
  
         for (i = 0; i < size_; i++)         for (i = 0; i < size_; i++)
         {         {
             *data++ = *str++;             *data++ = *str++;
         }         }
         buf->position += size - sizeof(MI_Char);          buf->position += size - sizeof(ZChar);
     }     }
  
     return MI_RESULT_OK;     return MI_RESULT_OK;
 } }
   #endif /* defined(CONFIG_ENABLE_WCHAR)*/
  
 #endif  MI_Result WSBuf_AddVerbatim(
       WSBuf* buf,
       const void* data,
       MI_Uint32 size)
   {
       size_t newSize = buf->position + size;
   
       /* Extend buffer if needed */
       if (newSize > buf->page->u.s.size)
       {
           if (_ReallocPage(buf, newSize)!= MI_RESULT_OK)
               return MI_RESULT_FAILED;
       }
   
       {
           void* pos = ((char*)(buf->page + 1))+ buf->position;
           memcpy(pos, data, size);
           buf->position += size;
       }
   
       return MI_RESULT_OK;
   }
   
   #if defined(CONFIG_ENABLE_WCHAR)
   MI_Result WSBuf_AddCharStringNoEncoding(
       WSBuf* buf,
       const char* str)
   {
       return WSBuf_AddCharLit(buf, str, (MI_Uint32)strlen(str));
   }
   #endif /* defined(CONFIG_ENABLE_WCHAR)*/
  
 /* Callback to tag writer: /* Callback to tag writer:
     allows to write properties for both values/EPRs with the same routine */     allows to write properties for both values/EPRs with the same routine */
 typedef MI_Result (*PropertyTagWriter)( typedef MI_Result (*PropertyTagWriter)(
     WSBuf* buf,     WSBuf* buf,
     const MI_Char* name,      const ZChar* name,
     MI_Boolean start);      MI_Boolean start,
       MI_Uint32 flags,
       const ZChar* nsPrefix);
   
   static MI_Result PackCimErrorXsiType(
       WSBuf* buf,
       MI_Uint32 nameLength,
       const ZChar* name)
   {
       if (((nameLength == 13) && (Tcscmp(name, ZT("CIMStatusCode")) == 0)) ||
               ((nameLength == 12) && (Tcscmp(name, ZT("OMI_Category")) == 0)) ||
               ((nameLength == 8) && (Tcscmp(name, ZT("OMI_Code")) == 0)) ||
               ((nameLength == 17) && (Tcscmp(name, ZT("PerceivedSeverity")) == 0)) ||
               ((nameLength == 13) && (Tcscmp(name, ZT("ProbableCause")) == 0)))
       {
           if (MI_RESULT_OK != WSBuf_AddLit(buf, LIT(ZT(" xsi:type=\"cim:cimUnsignedInt\""))))
           {
               return MI_RESULT_FAILED;
           }
       }
       else
       if (((nameLength == 7) && (Tcscmp(name, ZT("Message")) == 0)) ||
           ((nameLength == 16) && (Tcscmp(name, ZT("MessageArguments")) == 0)) ||
           ((nameLength == 9) && (Tcscmp(name, ZT("MessageID")) == 0)) ||
           ((nameLength == 16) && (Tcscmp(name, ZT("OMI_ErrorMessage")) == 0)) ||
           ((nameLength == 8) && (Tcscmp(name, ZT("OMI_Type")) == 0)) ||
           ((nameLength == 12) && (Tcscmp(name, ZT("OwningEntity")) == 0)) ||
           ((nameLength == 24) && (Tcscmp(name, ZT("ProbableCauseDescription")) == 0)))
       {
           if (MI_RESULT_OK != WSBuf_AddLit(buf, LIT(ZT(" xsi:type=\"cim:cimString\""))))
           {
               return MI_RESULT_FAILED;
           }
       }
       return MI_RESULT_OK;
   }
  
 INLINE MI_Result PropertyTagWriter_PropStart( INLINE MI_Result PropertyTagWriter_PropStart(
     WSBuf* buf,     WSBuf* buf,
     const MI_Char* name)      const ZChar* name,
       MI_Uint32 flags,
       const ZChar* nsPrefix)
 { {
     MI_Uint32 n = (MI_Uint32)Zlen(name);      MI_Uint32 n = (MI_Uint32)Tcslen(name);
  
     if (MI_RESULT_OK != WSBuf_AddLit3(buf, '<', 'p', ':') ||      if (WSBuf_AddLit1(buf, '<') != MI_RESULT_OK ||
         MI_RESULT_OK != WSBuf_AddLit(buf, name, n) ||          WSBuf_AddStringNoEncoding(buf, nsPrefix) != MI_RESULT_OK ||
         MI_RESULT_OK != WSBuf_AddLit1(buf,'>'))          WSBuf_AddLit1(buf, ':') != MI_RESULT_OK ||
           MI_RESULT_OK != WSBuf_AddLit(buf, name, n))
       {
           return MI_RESULT_FAILED;
       }
       if (flags & WSMAN_IsCimError)
       {
           if (MI_RESULT_OK != PackCimErrorXsiType(buf, n, name))
           {
               return MI_RESULT_FAILED;
           }
       }
       if (MI_RESULT_OK != WSBuf_AddLit1(buf,'>'))
     {     {
         return MI_RESULT_FAILED;         return MI_RESULT_FAILED;
     }     }
   
     return MI_RESULT_OK;     return MI_RESULT_OK;
 } }
  
 INLINE MI_Result PropertyTagWriter_PropEnd( INLINE MI_Result PropertyTagWriter_PropEnd(
     WSBuf* buf,     WSBuf* buf,
     const MI_Char* name)      const ZChar* name,
       MI_Uint32 flags,
       const ZChar* nsPrefix)
 { {
     MI_Uint32 n = (MI_Uint32)Zlen(name);      MI_Uint32 n = (MI_Uint32)Tcslen(name);
  
     if (MI_RESULT_OK != WSBuf_AddLit4(buf, '<', '/', 'p', ':') ||      if (WSBuf_AddLit2(buf, '<', '/') != MI_RESULT_OK ||
           WSBuf_AddStringNoEncoding(buf, nsPrefix) != MI_RESULT_OK ||
           WSBuf_AddLit1(buf, ':') != MI_RESULT_OK ||
         MI_RESULT_OK != WSBuf_AddLit(buf, name, n) ||         MI_RESULT_OK != WSBuf_AddLit(buf, name, n) ||
         MI_RESULT_OK != WSBuf_AddLit2(buf, '>', '\n'))         MI_RESULT_OK != WSBuf_AddLit2(buf, '>', '\n'))
     {     {
Line 781 
Line 939 
  
 static MI_Result PropertyTagWriter_Prop( static MI_Result PropertyTagWriter_Prop(
     WSBuf* buf,     WSBuf* buf,
     const MI_Char* name,      const ZChar* name,
     MI_Boolean start)      MI_Boolean start,
       MI_Uint32 flags,
       const ZChar* nsPrefix)
 { {
     if (start)     if (start)
         return PropertyTagWriter_PropStart(buf, name);          return PropertyTagWriter_PropStart(buf, name, flags, nsPrefix);
     else     else
         return PropertyTagWriter_PropEnd(buf, name);          return PropertyTagWriter_PropEnd(buf, name, flags, nsPrefix);
 } }
  
 static MI_Result PropertyTagWriter_EPR( static MI_Result PropertyTagWriter_EPR(
     WSBuf* buf,     WSBuf* buf,
     const MI_Char* name,      const ZChar* name,
     MI_Boolean start)      MI_Boolean start,
       MI_Uint32 flags,
       const ZChar* nsPrefix) //ignored
 { {
     if (start)     if (start)
     {     {
         if ( MI_RESULT_OK != WSBuf_AddLit(buf,LIT(MI_T("<wsman:Selector Name=\""))) ||          if (MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("<wsman:Selector Name=\"")))||
             MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf,name) ||             MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf,name) ||
             MI_RESULT_OK != WSBuf_AddLit2(buf, '"', '>')             MI_RESULT_OK != WSBuf_AddLit2(buf, '"', '>')
             )             )
Line 805 
Line 967 
     }     }
     else     else
     {     {
         if ( MI_RESULT_OK != WSBuf_AddLit(buf,LIT(MI_T("</wsman:Selector>") XML_CR))          if (MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("</wsman:Selector>")XML_CR))
             )             )
             return MI_RESULT_FAILED;             return MI_RESULT_FAILED;
     }     }
Line 815 
Line 977 
  
 static MI_Result _PackFieldNil( static MI_Result _PackFieldNil(
     WSBuf* buf,     WSBuf* buf,
     const MI_Char* name)      const ZChar* name,
       MI_Type type,
       MI_Uint32 flags,
       const ZChar* parentNSPrefix)
   {
       if (WSBuf_AddLit1(buf, '<') != MI_RESULT_OK ||
           WSBuf_AddStringNoEncoding(buf, parentNSPrefix) != MI_RESULT_OK ||
           WSBuf_AddLit1(buf, ':') != MI_RESULT_OK ||
           MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf,name))
           return MI_RESULT_FAILED;
   
       trace_Wsman_PackFieldNil( ((flags & WSMAN_UsePreciseArrays) != 0) );
       // adding msft specific attributes
       if (((flags & WSMAN_UsePreciseArrays) != 0) && (type & MI_ARRAY_BIT))
       {
           if(MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT(" msftwinrm:IsNullArray=\"true\""))))
               return MI_RESULT_FAILED;
       }
   
       if(MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT(" xsi:nil=\"true\""))))
           return MI_RESULT_FAILED;
   
       if (flags & WSMAN_IsCimError)
       {
           MI_Uint32 n = (MI_Uint32)Tcslen(name);
   
           if (MI_RESULT_OK != PackCimErrorXsiType(buf, n, name))
           {
               return MI_RESULT_FAILED;
           }
       }
       if (MI_RESULT_OK != WSBuf_AddLit(buf, LIT(ZT("/>")XML_CR)))
 { {
     if ( MI_RESULT_OK != WSBuf_AddLit3(buf, '<', 'p', ':') ||  
         MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf,name) ||  
         MI_RESULT_OK != WSBuf_AddLit(buf,LIT(MI_T(" xsi:nil=\"true\"/>") XML_CR)) )  
         return MI_RESULT_FAILED;         return MI_RESULT_FAILED;
       }
  
     return MI_RESULT_OK;     return MI_RESULT_OK;
 } }
Line 831 
Line 1022 
     void* callbackData)     void* callbackData)
 { {
     WSBuf* buf = callbackData;     WSBuf* buf = callbackData;
     return WSBuf_AddLit(buf, data, size) == MI_RESULT_OK ? 0 : -1;      return WSBuf_AddCharLit(buf, data, size)== MI_RESULT_OK ? 0 : -1;
 } }
  
 static MI_Result _PackFieldOctetString( static MI_Result _PackFieldOctetString(
     WSBuf* buf,     WSBuf* buf,
     const MI_Char* name,      const ZChar* name,
     const MI_Uint8* data,     const MI_Uint8* data,
     size_t size)      size_t size,
       const ZChar* nsPrefix)
 { {
     /* Validate first 4 bytes which contain the length then remove them */     /* Validate first 4 bytes which contain the length then remove them */
     {     {
Line 847 
Line 1039 
         if (size < 4)         if (size < 4)
             return MI_RESULT_FAILED;             return MI_RESULT_FAILED;
  
         length |= data[0] << 24;          length |= ((size_t)data[0]) << 24;
         length |= data[1] << 16;          length |= ((size_t)data[1]) << 16;
         length |= data[2] << 8;          length |= ((size_t)data[2]) << 8;
         length |= data[3];         length |= data[3];
  
         if (length != size)         if (length != size)
Line 859 
Line 1051 
         size -= 4;         size -= 4;
     }     }
  
     if (WSBuf_AddLit3(buf, '<', 'p', ':') != MI_RESULT_OK)      if (WSBuf_AddLit1(buf, '<') != MI_RESULT_OK ||
           WSBuf_AddStringNoEncoding(buf, nsPrefix) != MI_RESULT_OK ||
           WSBuf_AddLit1(buf, ':') != MI_RESULT_OK)
         return MI_RESULT_FAILED;         return MI_RESULT_FAILED;
  
     if (WSBuf_AddStringNoEncoding(buf, name) != MI_RESULT_OK)     if (WSBuf_AddStringNoEncoding(buf, name) != MI_RESULT_OK)
         return MI_RESULT_FAILED;         return MI_RESULT_FAILED;
  
     if (WSBuf_AddLit(buf,     if (WSBuf_AddLit(buf,
         LIT(MI_T(" xsi:type=\"cim:cimBase64Binary\">"))) != MI_RESULT_OK)          LIT(ZT(" xsi:type=\"cim:cimBase64Binary\">")))!= MI_RESULT_OK)
     {     {
         return MI_RESULT_FAILED;         return MI_RESULT_FAILED;
     }     }
Line 874 
Line 1068 
     if (Base64Enc(data, size, _Base64Callback, buf) != 0)     if (Base64Enc(data, size, _Base64Callback, buf) != 0)
         return MI_RESULT_FAILED;         return MI_RESULT_FAILED;
  
     if (PropertyTagWriter_PropEnd(buf, name) != MI_RESULT_OK)      if (PropertyTagWriter_PropEnd(buf, name, 0, nsPrefix)!= MI_RESULT_OK)
         return MI_RESULT_FAILED;         return MI_RESULT_FAILED;
  
     return MI_RESULT_OK;     return MI_RESULT_OK;
Line 883 
Line 1077 
 static MI_Result _PackFieldString( static MI_Result _PackFieldString(
     WSBuf* buf,     WSBuf* buf,
     PropertyTagWriter writer,     PropertyTagWriter writer,
     const MI_Char* name,      const ZChar* name,
     const MI_Char* value)      const ZChar* value,
       MI_Uint32 flags,
       const ZChar* nsPrefix)
 { {
     if ( MI_RESULT_OK != writer(buf,name,MI_TRUE) ||      if (MI_RESULT_OK != writer(buf,name,MI_TRUE, flags, nsPrefix)||
         MI_RESULT_OK != WSBuf_AddString(buf,value) ||         MI_RESULT_OK != WSBuf_AddString(buf,value) ||
         MI_RESULT_OK != writer(buf,name,MI_FALSE)          MI_RESULT_OK != writer(buf,name,MI_FALSE, flags, nsPrefix)
         )         )
         return MI_RESULT_FAILED;         return MI_RESULT_FAILED;
  
Line 898 
Line 1094 
 static MI_Result _PackFieldStringLit( static MI_Result _PackFieldStringLit(
     WSBuf* buf,     WSBuf* buf,
     PropertyTagWriter writer,     PropertyTagWriter writer,
     const MI_Char* name,      const ZChar* name,
     const MI_Char* value,      const ZChar* value,
     MI_Uint32 valueSize)      MI_Uint32 valueSize,
       MI_Uint32 flags,
       const ZChar* nsPrefix)
 { {
     if ( MI_RESULT_OK != writer(buf,name,MI_TRUE) ||      if (MI_RESULT_OK != writer(buf,name,MI_TRUE, flags, nsPrefix)||
         MI_RESULT_OK != WSBuf_AddLit(buf,value,valueSize) ||         MI_RESULT_OK != WSBuf_AddLit(buf,value,valueSize) ||
         MI_RESULT_OK != writer(buf,name,MI_FALSE)          MI_RESULT_OK != writer(buf,name,MI_FALSE, flags, nsPrefix)
         )         )
         return MI_RESULT_FAILED;         return MI_RESULT_FAILED;
  
Line 912 
Line 1110 
 } }
  
 static MI_Result _PackFieldEmbeddedInstance( static MI_Result _PackFieldEmbeddedInstance(
       UserAgent userAgent,
     WSBuf* buf,     WSBuf* buf,
     const MI_Char* name,      const ZChar* name,
     const MI_Instance* value)      const MI_Instance* value,
       MI_Uint32 flags,
       MI_Uint32 *lastPrefixIndex,
       const ZChar* parentNSPrefix)
   {
       if (MI_RESULT_OK != _PackInstance(
           buf,
           userAgent,
           value,
           NULL,
           NULL,
           0,
           WSMAN_ObjectFlag | flags,
           MI_TRUE,
           name,
           lastPrefixIndex,
           parentNSPrefix))
 { {
     if ( MI_RESULT_OK != PropertyTagWriter_PropStart(buf,name) ||  
         MI_RESULT_OK != _PackInstance(buf,value,NULL,NULL,0,WSMAN_ObjectFlag,MI_TRUE) ||  
         MI_RESULT_OK != PropertyTagWriter_PropEnd(buf,name)  
         )  
         return MI_RESULT_FAILED;         return MI_RESULT_FAILED;
       }
  
     return MI_RESULT_OK;     return MI_RESULT_OK;
 } }
  
 static MI_Result _PackFieldRef( static MI_Result _PackFieldRef(
     WSBuf* buf,     WSBuf* buf,
     const MI_Char* name,      PropertyTagWriter writer,
     const MI_Instance* value)      UserAgent userAgent,
       const ZChar* name,
       const MI_Instance* value,
       MI_Uint32 flags,
       const ZChar* nsPrefix)
 { {
     if ( MI_RESULT_OK != PropertyTagWriter_PropStart(buf,name) ||      if (MI_RESULT_OK != writer(buf,name, MI_TRUE, 0, nsPrefix)||
         MI_RESULT_OK != _PackEPR(buf,value) ||          MI_RESULT_OK != _PackEPR(buf, userAgent, value, flags)||
         MI_RESULT_OK != PropertyTagWriter_PropEnd(buf,name)          MI_RESULT_OK != writer(buf,name, MI_FALSE, 0, nsPrefix)
         )         )
         return MI_RESULT_FAILED;         return MI_RESULT_FAILED;
  
Line 942 
Line 1158 
 static MI_Result _PackFieldUint32( static MI_Result _PackFieldUint32(
     WSBuf* buf,     WSBuf* buf,
     PropertyTagWriter writer,     PropertyTagWriter writer,
     const MI_Char* name,      const ZChar* name,
     MI_Uint32 value)      MI_Uint32 value,
       MI_Uint32 flags,
       const ZChar* nsPrefix)
 { {
     MI_Char tmp[11];      ZChar tmp[11];
     size_t size;     size_t size;
     const MI_Char* str = Uint32ToZStr(tmp, value, &size);      const ZChar* str = Uint32ToZStr(tmp, value, &size);
     return _PackFieldStringLit(buf,writer, name, str, (MI_Uint32)size);      return _PackFieldStringLit(buf,writer, name, str, (MI_Uint32)size, flags, nsPrefix);
 } }
  
 static MI_Result _PackFieldUint64( static MI_Result _PackFieldUint64(
     WSBuf* buf,     WSBuf* buf,
     PropertyTagWriter writer,     PropertyTagWriter writer,
     const MI_Char* name,      const ZChar* name,
     MI_Uint64 value)      MI_Uint64 value,
       MI_Uint32 flags,
       const ZChar* nsPrefix)
 { {
     MI_Char tmp[21];      ZChar tmp[21];
     size_t size;     size_t size;
     const MI_Char* str = Uint64ToZStr(tmp, value, &size);      const ZChar* str = NULL;
     return _PackFieldStringLit(buf, writer, name, str, (MI_Uint32)size);      Uint64ToZStr(tmp, value, &str, &size);
       return _PackFieldStringLit(buf, writer, name, str, (MI_Uint32)size, flags, nsPrefix);
 } }
  
 static MI_Result _PackFieldSint32( static MI_Result _PackFieldSint32(
     WSBuf* buf,     WSBuf* buf,
     PropertyTagWriter writer,     PropertyTagWriter writer,
     const MI_Char* name,      const ZChar* name,
     MI_Sint32 value)      MI_Sint32 value,
       MI_Uint32 flags,
       const ZChar* nsPrefix)
 { {
     MI_Char s[24];      ZChar s[24];
  
     MI_Sint32 size = Szprintf(s, MI_COUNT(s), MI_T("%d"), value);      MI_Sint32 size = Stprintf(s, MI_COUNT(s), ZT("%d"), value);
     return _PackFieldStringLit(buf,writer,name,s,size);      return _PackFieldStringLit(buf,writer,name,s,size, flags, nsPrefix);
 } }
  
 static MI_Result _PackFieldSint64( static MI_Result _PackFieldSint64(
     WSBuf* buf,     WSBuf* buf,
     PropertyTagWriter writer,     PropertyTagWriter writer,
     const MI_Char* name,      const ZChar* name,
     MI_Sint64 value)      MI_Sint64 value,
       MI_Uint32 flags,
       const ZChar* nsPrefix)
 { {
     MI_Char s[24];      ZChar s[24];
  
     MI_Sint32 size = Szprintf(s, MI_COUNT(s), SINT64_FMT_T, value);      MI_Sint32 size = Stprintf(s, MI_COUNT(s), SINT64_FMT_T, value);
     return _PackFieldStringLit(buf,writer,name,s,size);      return _PackFieldStringLit(buf,writer,name,s,size,flags, nsPrefix);
 } }
  
 static MI_Result _PackFieldReal64( static MI_Result _PackFieldReal64(
     WSBuf* buf,     WSBuf* buf,
     PropertyTagWriter writer,     PropertyTagWriter writer,
     const MI_Char* name,      const ZChar* name,
     MI_Real64 value)      MI_Real64 value,
       MI_Uint32 flags,
       const ZChar* nsPrefix)
 { {
     MI_Char s[24];      ZChar s[24];
  
     MI_Sint32 size = Szprintf(s, MI_COUNT(s), MI_T("%g"), value);      /* Use DBL_DIG=15 for precision. Check MSDN DBL_DIG */
     return _PackFieldStringLit(buf,writer,name,s,size);      MI_Sint32 size = Stprintf(s, MI_COUNT(s), ZT("%.15g"), value);
       return _PackFieldStringLit(buf,writer,name,s,size,flags, nsPrefix);
 } }
  
 static MI_Result _PackFieldDatetime( static MI_Result _PackFieldDatetime(
     WSBuf* buf,     WSBuf* buf,
       UserAgent userAgent,
     PropertyTagWriter writer,     PropertyTagWriter writer,
     const MI_Char* name,      const ZChar* name,
     const MI_Datetime* p)      const MI_Datetime* p,
       MI_Uint32 flags,
       const ZChar* nsPrefix)
 { {
     MI_Char tmp[64];      ZChar tmp[64];
       const ZChar* tag = NULL;
     FormatWSManDatetime(p, tmp);     FormatWSManDatetime(p, tmp);
     return _PackFieldStringLit(buf, writer, name, tmp, (MI_Uint32)Zlen(tmp));  
       if (writer(buf,name,MI_TRUE, flags, nsPrefix)!= MI_RESULT_OK)
           return MI_RESULT_FAILED;
   
       if (userAgent == USERAGENT_WINRM)
       {
           tag = p->isTimestamp ? ZT("cim:Datetime"): ZT("cim:Interval");
           WSBuf_AddStartTag(buf, tag, 12);
       }
   
       if (WSBuf_AddLit(buf, tmp, (MI_Uint32)Tcslen(tmp))!= MI_RESULT_OK)
           return MI_RESULT_FAILED;
   
       if (userAgent == USERAGENT_WINRM)
           WSBuf_AddEndTag(buf, tag, 12);
   
       if (writer(buf, name, MI_FALSE, flags, nsPrefix)!= MI_RESULT_OK)
           return MI_RESULT_FAILED;
   
       return MI_RESULT_OK;
 } }
  
 static MI_Result _PackValue( static MI_Result _PackValue(
     WSBuf* buf,     WSBuf* buf,
       UserAgent userAgent,
     PropertyTagWriter writer,     PropertyTagWriter writer,
     const MI_Char* name,      const ZChar* name,
     const void* field,     const void* field,
     MI_Type type)      MI_Type type,
       MI_Uint32 flags,
       MI_Uint32 *lastPrefixIndex,
       const ZChar* parentNSPrefix)
 { {
     switch(type)     switch(type)
     {     {
Line 1024 
Line 1279 
             MI_Boolean* f = (MI_Boolean*)field;             MI_Boolean* f = (MI_Boolean*)field;
  
             if (*f)             if (*f)
                 return _PackFieldStringLit(buf,writer,name,LIT(MI_T("TRUE")));                  return _PackFieldStringLit(buf,writer,name,LIT(ZT("TRUE")),flags, parentNSPrefix);
             else             else
                 return _PackFieldStringLit(buf,writer,name,LIT(MI_T("FALSE")));                  return _PackFieldStringLit(buf, writer, name, LIT(ZT("FALSE")), flags, parentNSPrefix);
         }         }
         case MI_UINT8:         case MI_UINT8:
         {         {
             MI_Uint8* f = (MI_Uint8*)field;             MI_Uint8* f = (MI_Uint8*)field;
  
             return _PackFieldUint32(buf,writer,name,*f);              return _PackFieldUint32(buf, writer, name, *f, flags, parentNSPrefix);
         }         }
         case MI_UINT16:         case MI_UINT16:
         {         {
             MI_Uint16* f = (MI_Uint16*)field;             MI_Uint16* f = (MI_Uint16*)field;
  
             return _PackFieldUint32(buf,writer,name,*f);              return _PackFieldUint32(buf, writer, name, *f, flags, parentNSPrefix);
         }         }
         case MI_UINT32:         case MI_UINT32:
         {         {
             MI_Uint32* f = (MI_Uint32*)field;             MI_Uint32* f = (MI_Uint32*)field;
  
             return _PackFieldUint32(buf,writer,name,*f);              return _PackFieldUint32(buf, writer, name, *f, flags, parentNSPrefix);
         }         }
         case MI_UINT64:         case MI_UINT64:
         {         {
             MI_Uint64* f = (MI_Uint64*)field;             MI_Uint64* f = (MI_Uint64*)field;
  
             return _PackFieldUint64(buf,writer,name,*f);              return _PackFieldUint64(buf, writer, name, *f, flags, parentNSPrefix);
         }         }
         case MI_SINT8:         case MI_SINT8:
         {         {
             MI_Sint8* f = (MI_Sint8*)field;             MI_Sint8* f = (MI_Sint8*)field;
  
             return _PackFieldSint32(buf,writer,name,*f);              return _PackFieldSint32(buf, writer, name, *f, flags, parentNSPrefix);
         }         }
         case MI_SINT16:         case MI_SINT16:
         {         {
             MI_Sint16* f = (MI_Sint16*)field;             MI_Sint16* f = (MI_Sint16*)field;
  
             return _PackFieldSint32(buf,writer,name,*f);              return _PackFieldSint32(buf, writer, name, *f, flags, parentNSPrefix);
         }         }
         case MI_SINT32:         case MI_SINT32:
         {         {
             MI_Sint32* f = (MI_Sint32*)field;             MI_Sint32* f = (MI_Sint32*)field;
  
             return _PackFieldSint32(buf,writer,name,*f);              return _PackFieldSint32(buf,writer,name,*f, flags, parentNSPrefix);
         }         }
         case MI_SINT64:         case MI_SINT64:
         {         {
             MI_Sint64* f = (MI_Sint64*)field;             MI_Sint64* f = (MI_Sint64*)field;
  
             return _PackFieldSint64(buf,writer,name,*f);              return _PackFieldSint64(buf, writer, name, *f, flags, parentNSPrefix);
         }         }
         case MI_REAL32:         case MI_REAL32:
         {         {
             MI_Real32* f = (MI_Real32*)field;             MI_Real32* f = (MI_Real32*)field;
  
             return _PackFieldReal64(buf,writer,name,*f);              return _PackFieldReal64(buf, writer, name, *f, flags, parentNSPrefix);
         }         }
         case MI_REAL64:         case MI_REAL64:
         {         {
             MI_Real64* f = (MI_Real64*)field;             MI_Real64* f = (MI_Real64*)field;
  
             return _PackFieldReal64(buf,writer,name,*f);              return _PackFieldReal64(buf, writer, name, *f, flags, parentNSPrefix);
         }         }
         case MI_DATETIME:         case MI_DATETIME:
         {         {
             MI_Datetime* f = (MI_Datetime*)field;             MI_Datetime* f = (MI_Datetime*)field;
  
             return _PackFieldDatetime(buf,writer,name,&*f);              return _PackFieldDatetime(buf, userAgent, writer, name, &*f, flags, parentNSPrefix);
         }         }
         case MI_CHAR16:         case MI_CHAR16:
         {         {
Line 1112 
Line 1367 
 #endif #endif
  
             /* ATTN: convert it to utf8 and encode as a string */             /* ATTN: convert it to utf8 and encode as a string */
             return _PackFieldString(buf,writer,name,s);              return _PackFieldString(buf,writer,name,s, flags, parentNSPrefix);
 #else #else
             return _PackFieldUint32(buf,writer,name,(MI_Uint32)*f);              return _PackFieldUint32(buf, writer, name, (MI_Uint32)*f, flags, parentNSPrefix);
 #endif #endif
         }         }
         case MI_INSTANCE:         case MI_INSTANCE:
         {         {
             MI_Instance** f = (MI_Instance**)field;             MI_Instance** f = (MI_Instance**)field;
  
             return _PackFieldEmbeddedInstance(buf,name,*f);              return _PackFieldEmbeddedInstance(userAgent, buf, name, *f, flags, lastPrefixIndex, parentNSPrefix);
         }         }
         case MI_REFERENCE:         case MI_REFERENCE:
         {         {
             MI_Instance** f = (MI_Instance**)field;             MI_Instance** f = (MI_Instance**)field;
  
             return _PackFieldRef(buf,name,*f);              return _PackFieldRef(buf, writer, userAgent, name, *f, flags, parentNSPrefix);
         }         }
         case MI_STRING:         case MI_STRING:
         {         {
             MI_String* f = (MI_String*)field;             MI_String* f = (MI_String*)field;
  
             return _PackFieldString(buf,writer,name,*f);              return _PackFieldString(buf, writer, name, *f, flags, parentNSPrefix);
         }         }
         default:         default:
             break;             break;
Line 1144 
Line 1399 
  
 static MI_Result _PackField( static MI_Result _PackField(
     WSBuf* buf,     WSBuf* buf,
       UserAgent userAgent,
     PropertyTagWriter writer,     PropertyTagWriter writer,
     const MI_Char* name,      const ZChar* name,
     const void* field,     const void* field,
     MI_Type type,     MI_Type type,
     MI_Boolean isOctetString)      MI_Boolean isOctetString,
       MI_Uint32 flags,
       MI_Uint32 *lastPrefixIndex,
       const ZChar* parentNSPrefix)
 { {
     /* Check if value is null */     /* Check if value is null */
     if (!_Field_GetExists(field, type))     if (!_Field_GetExists(field, type))
         return _PackFieldNil(buf, name);          return _PackFieldNil(buf, name, type, flags, parentNSPrefix);
  
     /* Check if type is array:     /* Check if type is array:
         Arrays are encoded the same way regular instances are         Arrays are encoded the same way regular instances are
Line 1163 
Line 1422 
         {         {
             MI_Uint8AField* f = (MI_Uint8AField*)field;             MI_Uint8AField* f = (MI_Uint8AField*)field;
             return _PackFieldOctetString(buf, name, f->value.data,             return _PackFieldOctetString(buf, name, f->value.data,
                 f->value.size);                  f->value.size, parentNSPrefix);
         }         }
  
         /* ATTN: STRING OctetString not handled! */         /* ATTN: STRING OctetString not handled! */
Line 1178 
Line 1437 
             {             {
                 if (_PackValue(                 if (_PackValue(
                     buf,                     buf,
                       userAgent,
                     writer,                     writer,
                     name,                     name,
                     currentValue,                     currentValue,
                     stype) != MI_RESULT_OK)                      stype,
                       flags,
                       lastPrefixIndex,
                       parentNSPrefix)!= MI_RESULT_OK)
                 {                 {
                     return MI_RESULT_FAILED;                     return MI_RESULT_FAILED;
                 }                 }
Line 1193 
Line 1456 
         }         }
     }     }
  
     return _PackValue(buf, writer, name, field, type);      return _PackValue(buf, userAgent, writer, name, field, type, flags, lastPrefixIndex, parentNSPrefix);
 } }
  
 static MI_Result _PackEPR( static MI_Result _PackEPR(
     WSBuf* buf,     WSBuf* buf,
     const MI_Instance* instance)      UserAgent userAgent,
       const MI_Instance* instance,
       MI_Uint32 flags)
 { {
     Instance* self = (Instance*)instance;      Instance* self = Instance_GetSelf( instance );
     const MI_ClassDecl* cd = self->classDecl;     const MI_ClassDecl* cd = self->classDecl;
     MI_Uint32 i;     MI_Uint32 i;
  
     /* Put EPR header */     /* Put EPR header */
     if ( MI_RESULT_OK != WSBuf_AddLit(buf,LIT(MI_T("<wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>") XML_CR      if (MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("<wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>")XML_CR
             MI_T("<wsa:ReferenceParameters>") XML_CR              ZT("<wsa:ReferenceParameters>")XML_CR
             MI_T("<wsman:ResourceURI>http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/") )) ||              ZT("<wsman:ResourceURI>http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/")))||
         MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf,cd->name) ||         MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf,cd->name) ||
         MI_RESULT_OK != WSBuf_AddLit(buf,LIT(MI_T("</wsman:ResourceURI>") XML_CR          MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("</wsman:ResourceURI>")XML_CR
             MI_T("<wsman:SelectorSet>") XML_CR )) )              ZT("<wsman:SelectorSet>")XML_CR)))
         return MI_RESULT_FAILED;         return MI_RESULT_FAILED;
  
     /* namespace (if present)*/     /* namespace (if present)*/
     if (self->nameSpace)     if (self->nameSpace)
     {     {
           WSBuf_AddLit(buf, LIT(ZT("<wsman:Selector Name=\"__cimnamespace\">")));
           WSBuf_AddStringNoEncoding(buf, self->nameSpace);
           WSBuf_AddLit(buf, LIT(ZT("</wsman:Selector>")));
     }     }
  
     /* Put properties */     /* Put properties */
Line 1223 
Line 1491 
     {     {
         const MI_PropertyDecl* pd = cd->properties[i];         const MI_PropertyDecl* pd = cd->properties[i];
         const void* value = (char*)self + pd->offset;         const void* value = (char*)self + pd->offset;
           MI_Uint32 tmpLastPrefixIndex = 0;
  
         if ((pd->flags & MI_FLAG_KEY) == 0)         if ((pd->flags & MI_FLAG_KEY) == 0)
             continue;             continue;
Line 1233 
Line 1502 
  
         if (_PackValue(         if (_PackValue(
             buf,             buf,
               userAgent,
             PropertyTagWriter_EPR,             PropertyTagWriter_EPR,
             pd->name, value,             pd->name, value,
             (MI_Type)pd->type) != MI_RESULT_OK)              (MI_Type)pd->type,
               flags,
               &tmpLastPrefixIndex,
               NULL) != MI_RESULT_OK)
         {         {
             return MI_RESULT_FAILED;             return MI_RESULT_FAILED;
         }         }
     }     }
  
     /* close EPR */     /* close EPR */
     if ( MI_RESULT_OK != WSBuf_AddLit(buf,LIT(MI_T("</wsman:SelectorSet>") XML_CR      if (MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("</wsman:SelectorSet>")XML_CR
             MI_T("</wsa:ReferenceParameters>") XML_CR )) )              ZT("</wsa:ReferenceParameters>")XML_CR)))
         return MI_RESULT_FAILED;         return MI_RESULT_FAILED;
  
     return MI_RESULT_OK;     return MI_RESULT_OK;
Line 1258 
Line 1531 
     {     {
         const MI_Qualifier* q = pd->qualifiers[i];         const MI_Qualifier* q = pd->qualifiers[i];
  
         if (Zcasecmp(q->name, T("OctetString")) == 0          if (Tcscasecmp(q->name, ZT("OctetString"))== 0
             && q->type == MI_BOOLEAN             && q->type == MI_BOOLEAN
             && q->value)             && q->value)
         {         {
Line 1269 
Line 1542 
     return MI_FALSE;     return MI_FALSE;
 } }
  
   #define WSMAN_SchemaFlagMask 0xf00
   MI_Result WSBuf_ClassToBuf(_In_ const MI_Class *classObject,
                                   MI_Uint32 flags,
                                   Batch* batch,
                                   void** ptrOut,
                                   MI_Uint32* sizeOut)
   {
       WSBuf buf;
       Page* page;
   
       MI_Result result = MI_RESULT_OK;
       MI_Application mi_application = MI_APPLICATION_NULL;
       MI_Serializer mi_serializer;
       MI_Uint32 bufferLenForSerialization = 0;
   
       // in future flags will be converted to the actual flags needed for serialization; for now just pass 0
       MI_UNREFERENCED_PARAMETER(flags);
   
       result = XmlSerializer_Create(&mi_application, 0, ZT("MI_XML"), &mi_serializer);
       if(result != MI_RESULT_OK)
           return result;
   
       trace_XmlSerializer_SerializeClass(flags & WSMAN_SchemaFlagMask);
   
       // pass 1 to compute the total needed length for serializing the class
       XmlSerializer_SerializeClass(&mi_serializer, flags & WSMAN_SchemaFlagMask, classObject, NULL, 0, &bufferLenForSerialization);
   
       // this was just length computation; we will get MI_RESULT_FAILED from here but the bufferLenForSerialization will have the needed length
       // we will just check whether even length returned was 0; in that case we fail immediately
       // but if we get non-zero length required, we will go ahead and allocate the necessary buffer and then do the serialization again to see if it succeeds.
       if(bufferLenForSerialization == 0)
       {
           result = MI_RESULT_FAILED;
           goto End;
       }
   
       // allocating the needed size buffer before pass 2
       result = WSBuf_Init(&buf, bufferLenForSerialization);
   
       if (MI_RESULT_OK != result)
           goto End;
   
       // pass 2 to serialize the class into allocated buffer
       result = XmlSerializer_SerializeClass(&mi_serializer, flags & WSMAN_SchemaFlagMask, classObject, ((MI_Uint8*)(buf.page +1)), bufferLenForSerialization, &bufferLenForSerialization);
   
       if(result != MI_RESULT_OK)
       {
           WSBuf_Destroy(&buf);
           goto End;
       }
   
       // directly assigning the position since we already know how much we wrote in serialization
       buf.position = bufferLenForSerialization;
       page = WSBuf_StealPage(&buf);
       Batch_AttachPage(batch, page);
   
       *ptrOut = page + 1;
   
       *sizeOut = (MI_Uint32)page->u.s.size;
       result = MI_RESULT_OK;
   
   End:
       XmlSerializer_Close(&mi_serializer);
       return result;
   }
   
 static MI_Result _PackInstance( static MI_Result _PackInstance(
     WSBuf* buf,     WSBuf* buf,
       UserAgent userAgent,
     const MI_Instance* instance,     const MI_Instance* instance,
     MI_Boolean (*filterProperty)(const MI_Char* name, void* data),      MI_Boolean (*filterProperty)(const ZChar* name, void* data),
     void* filterPropertyData,     void* filterPropertyData,
     const MI_ClassDecl* castToClassDecl,     const MI_ClassDecl* castToClassDecl,
     MI_Uint32 flags,     MI_Uint32 flags,
     MI_Boolean embedded)      MI_Boolean embedded,
       const ZChar* propName,
       MI_Uint32 *lastPrefixIndex,
       const ZChar* parentNSPrefix) //optional
 { {
     Instance* self = (Instance*)instance;      Instance* self = Instance_GetSelf( instance );
     const MI_ClassDecl* cd = castToClassDecl ? castToClassDecl : self->classDecl;     const MI_ClassDecl* cd = castToClassDecl ? castToClassDecl : self->classDecl;
     MI_Uint32 i;     MI_Uint32 i;
       const ZChar* name;
  
     /* Check for null arguments */     /* Check for null arguments */
     if (!self || !buf)     if (!self || !buf)
         MI_RETURN(MI_RESULT_INVALID_PARAMETER);         MI_RETURN(MI_RESULT_INVALID_PARAMETER);
  
     /* For Object & EPR, add <Item> tag */     /* For Object & EPR, add <Item> tag */
     if ((flags & WSMAN_ObjectAndEPRFlag) == WSMAN_ObjectAndEPRFlag)      if (!embedded &&
           ((flags & WSMAN_ObjectAndEPRFlag)== WSMAN_ObjectAndEPRFlag))
     {     {
         if ( MI_RESULT_OK != WSBuf_AddLit(buf,LIT(MI_T("<wsman:Item>") XML_CR)))          if (MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("<wsman:Item>")XML_CR)))
             return MI_RESULT_FAILED;             return MI_RESULT_FAILED;
     }     }
  
     /* If object was requested */     /* If object was requested */
     if ((flags & WSMAN_ObjectFlag) == WSMAN_ObjectFlag)     if ((flags & WSMAN_ObjectFlag) == WSMAN_ObjectFlag)
     {     {
         /* Put classname */          const ZChar* cn;
         if ( MI_RESULT_OK != WSBuf_AddLit3(buf, '<', 'p', ':') ||          const ZChar* elementName;
             MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf,cd->name) ||          ZChar nsPrefix[12];  // p followed by index and
             MI_RESULT_OK != WSBuf_AddLit(buf,LIT(MI_T(" xmlns:p=\"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/"))) ||  
             MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf,cd->name) ||          //GeneratePrefix
             MI_RESULT_OK != WSBuf_AddLit2(buf, '"', '\n'))          {
               MI_Uint32 used = 1;
               nsPrefix[0] = ZT('p');
   
               if (*lastPrefixIndex)
               {
                   used += Stprintf(nsPrefix + 1, 11, ZT("%d"), *lastPrefixIndex);
               }
   
               if (used > 11)  // should never happen
             return MI_RESULT_FAILED;             return MI_RESULT_FAILED;
  
               nsPrefix[used] = ZT('\0');
               (*lastPrefixIndex)++;
           }
   
           if ((cd->flags & MI_FLAG_METHOD) && ((MI_MethodDecl*)cd)->propagator)
               cn = ((MI_MethodDecl*)cd)->propagator;
           else
               cn = cd->name;
   
           elementName = propName ? propName : cn;
   
           /* <p:propName ... type='class_Type> */
           if ((flags & WSMAN_IsCimError) == 0)
           {
               if (WSBuf_AddLit1(buf, '<') != MI_RESULT_OK ||
                   WSBuf_AddStringNoEncoding(buf, parentNSPrefix ? parentNSPrefix:nsPrefix) != MI_RESULT_OK ||
                   WSBuf_AddLit1(buf, ':') != MI_RESULT_OK ||
                   WSBuf_AddStringNoEncoding(buf, elementName) != MI_RESULT_OK)
               {
                   return MI_RESULT_FAILED;
               }
   
               /* If parameters, append "_OUTPUT" suffix */
   
               if ((cd->flags & MI_FLAG_METHOD) &&
                   WSBuf_AddStringNoEncoding(buf, ZT("_OUTPUT")) != MI_RESULT_OK)
               {
                   return MI_RESULT_FAILED;
               }
   
               if (WSBuf_AddLit(buf, LIT(ZT(" xmlns:"))) != MI_RESULT_OK ||
                   WSBuf_AddStringNoEncoding(buf, nsPrefix) != MI_RESULT_OK ||
                   WSBuf_AddLit(buf, LIT(ZT("=\"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/"))) != MI_RESULT_OK ||
                   WSBuf_AddStringNoEncoding(buf, cn) != MI_RESULT_OK ||
                   WSBuf_AddLit2(buf, '"', '\n') != MI_RESULT_OK)
               {
                   return MI_RESULT_FAILED;
               }
   
         if (embedded)         if (embedded)
         {         {
             if ( MI_RESULT_OK != WSBuf_AddLit(buf,LIT(MI_T(" xsi:type=\""))) ||                  if (WSBuf_AddLit(buf,LIT(ZT(" xsi:type=\""))) != MI_RESULT_OK ||
                 MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf,cd->name) ||                      WSBuf_AddStringNoEncoding(buf, nsPrefix) != MI_RESULT_OK ||
                 MI_RESULT_OK != WSBuf_AddLit(buf,LIT(MI_T("_Type\"") XML_CR)))                      WSBuf_AddLit1(buf, ':') != MI_RESULT_OK ||
                       WSBuf_AddStringNoEncoding(buf,cn) != MI_RESULT_OK ||
                       MI_RESULT_OK != WSBuf_AddLit(buf,ZT("_Type\""), 6))
                   {
                 return MI_RESULT_FAILED;                 return MI_RESULT_FAILED;
         }         }
         if ( MI_RESULT_OK != WSBuf_AddLit2(buf, '>', '\n'))              }
   
               if (WSBuf_AddLit2(buf, '>', '\n') != MI_RESULT_OK)
             return MI_RESULT_FAILED;             return MI_RESULT_FAILED;
           }
  
         /* Put properties */         /* Put properties */
         for ( i = 0; i < cd->numProperties; i++ )         for ( i = 0; i < cd->numProperties; i++ )
Line 1332 
Line 1731 
             if (pd->type == MI_UINT8A || pd->type == MI_STRINGA)             if (pd->type == MI_UINT8A || pd->type == MI_STRINGA)
                 isOctetString = TestOctetStringQualifier(pd);                 isOctetString = TestOctetStringQualifier(pd);
  
               /* Skip non-out params; rename 'MIReturn' to  'ReturnValue' */
   
               name = pd->name;
   
               if (pd->flags & MI_FLAG_PARAMETER)
               {
                   if (!(pd->flags & MI_FLAG_OUT))
                       continue;
   
                   if (name[0] == 'M' && Tcscmp(name, ZT("MIReturn"))== 0)
                       name = ZT("ReturnValue");
               }
   
             /* Pack the field */             /* Pack the field */
  
             if (_PackField(             if (_PackField(
                 buf,                 buf,
                   userAgent,
                 PropertyTagWriter_Prop,                 PropertyTagWriter_Prop,
                 pd->name,                  name,
                 value,                 value,
                 (MI_Type)pd->type,                 (MI_Type)pd->type,
                 isOctetString) != MI_RESULT_OK)                  isOctetString,
                   flags, lastPrefixIndex, nsPrefix)!= MI_RESULT_OK)
             {             {
                 return MI_RESULT_FAILED;                 return MI_RESULT_FAILED;
             }             }
         }         }
  
         /* close class */          /* </p:elementName> */
         if ( MI_RESULT_OK != WSBuf_AddLit4(buf, '<', '/', 'p', ':') ||          if ((flags & WSMAN_IsCimError) == 0)
             MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf,cd->name) ||          {
             MI_RESULT_OK != WSBuf_AddLit2(buf, '>', '\n'))              if (WSBuf_AddLit2(buf, '<', '/') != MI_RESULT_OK ||
                   WSBuf_AddStringNoEncoding(buf, parentNSPrefix ? parentNSPrefix : nsPrefix) != MI_RESULT_OK ||
                   WSBuf_AddLit1(buf, ':') != MI_RESULT_OK ||
                   WSBuf_AddStringNoEncoding(buf, elementName) != MI_RESULT_OK)
               {
             return MI_RESULT_FAILED;             return MI_RESULT_FAILED;
     }     }
  
               if ((cd->flags & MI_FLAG_METHOD) &&
                   WSBuf_AddStringNoEncoding(buf, ZT("_OUTPUT")) != MI_RESULT_OK)
               {
                   return MI_RESULT_FAILED;
               }
   
               if (WSBuf_AddLit2(buf, '>', '\n') != MI_RESULT_OK)
                   return MI_RESULT_FAILED;
           }
       }
   
     /* If EPR was requested */     /* If EPR was requested */
     if ((flags & WSMAN_EPRFlag) == WSMAN_EPRFlag)      if (!embedded &&
           ((flags & WSMAN_EPRFlag)== WSMAN_EPRFlag))
     {     {
         if ( MI_RESULT_OK != WSBuf_AddLit(buf,LIT(MI_T("<wsa:EndpointReference>") XML_CR)) ||          if (MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("<wsa:EndpointReference>")XML_CR))||
             MI_RESULT_OK != _PackEPR(buf,instance) ||              MI_RESULT_OK != _PackEPR(buf, userAgent, instance, flags)||
             MI_RESULT_OK != WSBuf_AddLit(buf,LIT(MI_T("</wsa:EndpointReference>") XML_CR)))              MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("</wsa:EndpointReference>")XML_CR)))
             return MI_RESULT_FAILED;             return MI_RESULT_FAILED;
     }     }
  
     /* If EPR was requested */     /* If EPR was requested */
     if ((flags & WSMAN_CreatedEPRFlag) == WSMAN_CreatedEPRFlag)     if ((flags & WSMAN_CreatedEPRFlag) == WSMAN_CreatedEPRFlag)
     {     {
         if ( MI_RESULT_OK != WSBuf_AddLit(buf,LIT(MI_T("<wxf:ResourceCreated>") XML_CR)) ||          if (MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("<wxf:ResourceCreated>")XML_CR))||
             MI_RESULT_OK != _PackEPR(buf,instance) ||              MI_RESULT_OK != _PackEPR(buf, userAgent, instance, flags)||
             MI_RESULT_OK != WSBuf_AddLit(buf,LIT(MI_T("</wxf:ResourceCreated>") XML_CR)))              MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("</wxf:ResourceCreated>")XML_CR)))
             return MI_RESULT_FAILED;             return MI_RESULT_FAILED;
     }     }
  
     /* For Object & EPR, add </Item> tag */     /* For Object & EPR, add </Item> tag */
     if ((flags & WSMAN_ObjectAndEPRFlag) == WSMAN_ObjectAndEPRFlag)      if (!embedded &&
           ((flags & WSMAN_ObjectAndEPRFlag)== WSMAN_ObjectAndEPRFlag))
     {     {
         if ( MI_RESULT_OK != WSBuf_AddLit(buf,LIT(MI_T("</wsman:Item>") XML_CR)))          if (MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("</wsman:Item>")XML_CR)))
             return MI_RESULT_FAILED;             return MI_RESULT_FAILED;
     }     }
  
Line 1383 
Line 1814 
 } }
  
 MI_Result WSBuf_InstanceToBuf( MI_Result WSBuf_InstanceToBuf(
       UserAgent userAgent,
     const MI_Instance* instance,     const MI_Instance* instance,
     MI_Boolean (*filterProperty)(const MI_Char* name, void* data),      MI_Boolean (*filterProperty)(const ZChar* name, void* data),
     void* filterPropertyData,     void* filterPropertyData,
     const MI_ClassDecl* castToClassDecl,     const MI_ClassDecl* castToClassDecl,
     Batch* batch,     Batch* batch,
Line 1395 
Line 1827 
     WSBuf buf;     WSBuf buf;
     MI_Result r;     MI_Result r;
     Page* page;     Page* page;
       MI_Uint32 lastPrefixIndex = 0;
  
     r = WSBuf_Init(&buf,1024);     r = WSBuf_Init(&buf,1024);
  
     if (MI_RESULT_OK != r)     if (MI_RESULT_OK != r)
         return r;         return r;
  
     r = _PackInstance(&buf, instance, filterProperty,      // Passing NULL as the PropName as this is not embeddedInstance
         filterPropertyData, castToClassDecl, flags,MI_FALSE);      // As the second last parameter is MI_FALSE
       r = _PackInstance(&buf, userAgent, instance, filterProperty,
           filterPropertyData, castToClassDecl, flags, MI_FALSE, NULL, &lastPrefixIndex, NULL);
  
     if (MI_RESULT_OK != r)     if (MI_RESULT_OK != r)
     {     {
Line 1418 
Line 1853 
     return MI_RESULT_OK;     return MI_RESULT_OK;
 } }
  
   _Use_decl_annotations_
 void WSBuf_GenerateMessageID( void WSBuf_GenerateMessageID(
     MI_Char msgID[WS_MSG_ID_SIZE])      ZChar msgID[WS_MSG_ID_SIZE])
 { {
     //WS-Management qualifies the use of wsa:MessageID and wsa:RelatesTo as follows:     //WS-Management qualifies the use of wsa:MessageID and wsa:RelatesTo as follows:
     //R5.4.6.4-1: The MessageID and RelatesTo URIs may be of any format, as long as they are valid     //R5.4.6.4-1: The MessageID and RelatesTo URIs may be of any format, as long as they are valid
Line 1455 
Line 1891 
     static MI_Uint64  s1, s2;     static MI_Uint64  s1, s2;
  
     if (!s1)     if (!s1)
         Time_Now(&s1);          PAL_Time(&s1);
  
     s2++;     s2++;
  
Line 1463 
Line 1899 
     if (!s2)     if (!s2)
         s1++;         s1++;
  
     Szprintf(msgID, WS_MSG_ID_SIZE,      Stprintf(msgID, WS_MSG_ID_SIZE,
         MI_T("uuid:%08X-%04X-%04X-%04X-%08X%04X"),          ZT("uuid:%08X-%04X-%04X-%04X-%08X%04X"),
         (MI_Uint32)(s1 & 0xFFFFFFFF),         (MI_Uint32)(s1 & 0xFFFFFFFF),
         (MI_Uint32)((s1 >> 32) & 0xFFFF),         (MI_Uint32)((s1 >> 32) & 0xFFFF),
         (MI_Uint32)((s1 >> 48) & 0xFFFF),         (MI_Uint32)((s1 >> 48) & 0xFFFF),
Line 1475 
Line 1911 
  
 MI_Result WSBuf_CreateSoapResponseHeader( MI_Result WSBuf_CreateSoapResponseHeader(
     WSBuf   *buf,     WSBuf   *buf,
     const MI_Char*  action,      const ZChar* action,
     MI_Uint32       actionSize,     MI_Uint32       actionSize,
     const char*     relatesTo)      const ZChar* relatesTo)
 { {
     MI_Char msgID[WS_MSG_ID_SIZE];      ZChar msgID[WS_MSG_ID_SIZE];
  
     /* Response header */     /* Response header */
     if (MI_RESULT_OK != WSBuf_AddLit(buf,     if (MI_RESULT_OK != WSBuf_AddLit(buf,
         LIT(         LIT(
         MI_T("<SOAP-ENV:Envelope ")          ZT("<SOAP-ENV:Envelope ")
         MI_T("xmlns:SOAP-ENV=\"http://www.w3.org/2003/05/soap-envelope\" ")          ZT("xmlns:SOAP-ENV=\"http://www.w3.org/2003/05/soap-envelope\" ")
         MI_T("xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" ")          ZT("xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" ")
         MI_T("xmlns:wsen=\"http://schemas.xmlsoap.org/ws/2004/09/enumeration\" ")          ZT("xmlns:wsen=\"http://schemas.xmlsoap.org/ws/2004/09/enumeration\" ")
         MI_T("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ")          ZT("xmlns:e=\"http://schemas.xmlsoap.org/ws/2004/08/eventing\" ")
         MI_T("xmlns:wsmb=\"http://schemas.dmtf.org/wbem/wsman/1/cimbinding.xsd\" ")          ZT("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ")
         MI_T("xmlns:wsman=\"http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd\" ")          ZT("xmlns:wsmb=\"http://schemas.dmtf.org/wbem/wsman/1/cimbinding.xsd\" ")
         MI_T("xmlns:wxf=\"http://schemas.xmlsoap.org/ws/2004/09/transfer\" ")          ZT("xmlns:wsman=\"http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd\" ")
         MI_T("xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" ")          ZT("xmlns:wxf=\"http://schemas.xmlsoap.org/ws/2004/09/transfer\" ")
         MI_T("xmlns:wsmid=\"http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd\" >")          ZT("xmlns:cim=\"http://schemas.dmtf.org/wbem/wscim/1/common\" ")
           ZT("xmlns:msftwinrm=\"http://schemas.microsoft.com/wbem/wsman/1/wsman.xsd\" ")
           /* ZT("xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" ")*/
           ZT("xmlns:wsmid=\"http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd\">")
         XML_CR         XML_CR
         MI_T("<SOAP-ENV:Header>")                                                       XML_CR          ZT("<SOAP-ENV:Header>")XML_CR
         MI_T("<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>")    XML_CR          ZT("<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>")XML_CR
         MI_T("<wsa:Action>")))  )          ZT("<wsa:Action>"))))
     {     {
         goto failed;         goto failed;
     }     }
Line 1506 
Line 1945 
         goto failed;         goto failed;
  
     if (MI_RESULT_OK != WSBuf_AddLit(buf,     if (MI_RESULT_OK != WSBuf_AddLit(buf,
             LIT(MI_T("</wsa:Action>")           XML_CR              LIT(ZT("</wsa:Action>")XML_CR
             MI_T("<wsa:MessageID>" ))))              ZT("<wsa:MessageID>"))))
         goto failed;         goto failed;
  
     /* Generate new uniqueue msg id */     /* Generate new uniqueue msg id */
Line 1517 
Line 1956 
         goto failed;         goto failed;
  
     if (MI_RESULT_OK != WSBuf_AddLit(buf,     if (MI_RESULT_OK != WSBuf_AddLit(buf,
         LIT(MI_T("</wsa:MessageID>")    XML_CR)))          LIT(ZT("</wsa:MessageID>")XML_CR)))
         goto failed;         goto failed;
  
     if (relatesTo)     if (relatesTo)
     {     {
         if (MI_RESULT_OK != WSBuf_AddLit(buf,         if (MI_RESULT_OK != WSBuf_AddLit(buf,
             LIT(MI_T("<wsa:RelatesTo>"))))              LIT(ZT("<wsa:RelatesTo>"))))
             goto failed;             goto failed;
  
         if (MI_RESULT_OK != WSBuf_AddCharStringNoEncoding(buf, relatesTo))          if (MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf, relatesTo))
             goto failed;             goto failed;
  
         if (MI_RESULT_OK != WSBuf_AddLit(buf,         if (MI_RESULT_OK != WSBuf_AddLit(buf,
             LIT(MI_T("</wsa:RelatesTo>")        XML_CR)))              LIT(ZT("</wsa:RelatesTo>")XML_CR)))
             goto failed;             goto failed;
     }     }
  
Line 1540 
Line 1979 
     return MI_RESULT_FAILED;     return MI_RESULT_FAILED;
 } }
  
   
   
 Page* WSBuf_CreateFaultResponsePage( Page* WSBuf_CreateFaultResponsePage(
     WSBUF_FAULT_CODE faultCode,     WSBUF_FAULT_CODE faultCode,
     const char* notUnderstoodTag,      const ZChar* notUnderstoodTag,
     const char* requestMessageID,      const ZChar* requestMessageID,
     const MI_Char* descriptionText)      const PostResultMsg* message)
 { {
     WSBuf   outBuf;     WSBuf   outBuf;
     const BUF_FaultItem* fault;     const BUF_FaultItem* fault;
       const ZChar* textToSend;
  
     if ( ((MI_Uint32)faultCode) >= MI_COUNT(s_faults))     if ( ((MI_Uint32)faultCode) >= MI_COUNT(s_faults))
     {     {
Line 1560 
Line 1998 
         fault = s_faults + (MI_Uint32)faultCode;         fault = s_faults + (MI_Uint32)faultCode;
     }     }
  
   
     /* prepare soap response with error */     /* prepare soap response with error */
     if (WSBuf_Init(&outBuf, 1024) != MI_RESULT_OK)     if (WSBuf_Init(&outBuf, 1024) != MI_RESULT_OK)
         return 0;         return 0;
Line 1573 
Line 2010 
     if (notUnderstoodTag)     if (notUnderstoodTag)
     {     {
         if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,         if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
                 LIT(MI_T("<SOAP-ENV:NotUnderstood qname=\""))))                  LIT(ZT("<SOAP-ENV:NotUnderstood qname=\""))))
             goto failed;             goto failed;
  
         if (MI_RESULT_OK != WSBuf_AddCharStringNoEncoding(&outBuf, notUnderstoodTag ))          if (MI_RESULT_OK != WSBuf_AddStringNoEncoding(
               &outBuf,
               notUnderstoodTag))
           {
             goto failed;             goto failed;
           }
  
         if (MI_RESULT_OK != WSBuf_AddLit3(&outBuf, '"', '/', '>'))         if (MI_RESULT_OK != WSBuf_AddLit3(&outBuf, '"', '/', '>'))
             goto failed;             goto failed;
Line 1585 
Line 2026 
  
     if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,     if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
         LIT(         LIT(
         MI_T("</SOAP-ENV:Header>")      XML_CR  XML_CR          ZT("</SOAP-ENV:Header>")XML_CR XML_CR
         MI_T("<SOAP-ENV:Body>")         XML_CR          ZT("<SOAP-ENV:Body>")XML_CR
         MI_T("<SOAP-ENV:Fault>")        XML_CR          ZT("<SOAP-ENV:Fault>")XML_CR
         MI_T("<SOAP-ENV:Code>")         XML_CR          ZT("<SOAP-ENV:Code>")XML_CR
         MI_T("<SOAP-ENV:Value>")))  )          ZT("<SOAP-ENV:Value>"))))
         goto failed;         goto failed;
  
     if (MI_RESULT_OK != WSBuf_AddCharStringNoEncoding(&outBuf, fault->code))     if (MI_RESULT_OK != WSBuf_AddCharStringNoEncoding(&outBuf, fault->code))
Line 1597 
Line 2038 
         //SOAP-ENV:Sender         //SOAP-ENV:Sender
  
     if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,     if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
         LIT(MI_T("</SOAP-ENV:Value>")       XML_CR)))          LIT(ZT("</SOAP-ENV:Value>")XML_CR)))
         goto failed;         goto failed;
  
     if (fault->subCode)     if (fault->subCode)
     {     {
         if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,         if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
             LIT(MI_T("<SOAP-ENV:Subcode>")      XML_CR              LIT(ZT("<SOAP-ENV:Subcode>")XML_CR
             MI_T("<SOAP-ENV:Value>"))))              ZT("<SOAP-ENV:Value>"))))
             goto failed;             goto failed;
  
         if (MI_RESULT_OK != WSBuf_AddCharStringNoEncoding(&outBuf, fault->subCode))          if (MI_RESULT_OK != WSBuf_AddCharStringNoEncoding(
               &outBuf,
               fault->subCode))
           {
             goto failed;             goto failed;
           }
  
         if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,         if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
             LIT(MI_T("</SOAP-ENV:Value>")       XML_CR              LIT(ZT("</SOAP-ENV:Value>")XML_CR
             MI_T("</SOAP-ENV:Subcode>")     XML_CR)))              ZT("</SOAP-ENV:Subcode>")XML_CR)))
             goto failed;             goto failed;
     }     }
  
     if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,     if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
         LIT(MI_T("</SOAP-ENV:Code>")        XML_CR          LIT(ZT("</SOAP-ENV:Code>")XML_CR
         MI_T("<SOAP-ENV:Reason>")       XML_CR          ZT("<SOAP-ENV:Reason>")XML_CR
         MI_T("<SOAP-ENV:Text xml:lang=\"en-US\">"))))          ZT("<SOAP-ENV:Text xml:lang=\"en-US\">"))))
           goto failed;
   
       textToSend = fault->defaultText;
   
       if (message->errorMessage)
       {
           textToSend = message->errorMessage;
       }
   
       if (MI_RESULT_OK != WSBuf_AddString(&outBuf, textToSend))
       {
         goto failed;         goto failed;
       }
  
     if ( descriptionText )      if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
           LIT(ZT("</SOAP-ENV:Text>")XML_CR
           ZT("</SOAP-ENV:Reason>")XML_CR)))
     {     {
         if (MI_RESULT_OK != WSBuf_AddString(&outBuf, descriptionText))  
             goto failed;             goto failed;
     }     }
   
       if ((message->result != MI_RESULT_OK) || (NULL != message->packedInstancePtr))
       {
           if ((MI_RESULT_OK != WSBuf_AddLit(&outBuf, LIT(ZT("<SOAP-ENV:Detail>")XML_CR ZT("<p:")))) ||
               (MI_RESULT_OK != WSBuf_AddString(&outBuf, (message->cimErrorClassName?message->cimErrorClassName:ZT("OMI_Error")))) ||
               (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
                                             LIT(ZT(" wsmb:IsCIM_Error=\"true\" ")
                                                 ZT("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ")
                                                 ZT("xmlns:wsmb=\"http://schemas.dmtf.org/wbem/wsman/1/cimbinding.xsd\" ")
                                                 ZT("xmlns:p=\"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/OMI_Error\" ")
                                                 ZT("xmlns:cim=\"http://schemas.dmtf.org/wbem/wscim/1/common\">")))))
           {
               goto failed;
           }
   
           if (message->packedInstancePtr)
           {
               if (MI_RESULT_OK != WSBuf_AddLit(&outBuf, message->packedInstancePtr, message->packedInstanceSize/sizeof(MI_Char)))
               {
                   goto failed;
               }
           }
     else     else
     {     {
         if (MI_RESULT_OK != WSBuf_AddCharStringNoEncoding(&outBuf, fault->defaultTest))              /* Create OMI_Error from the error code and string passed in */
   
               // CIM_Error:CIMStatusCode
               if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
                   LIT(ZT("<p:CIMStatusCode xsi:type=\"cim:cimUnsignedInt\">"))))
               {
                   goto failed;
               }
   
               if (MI_RESULT_OK != WSBuf_AddUint32(&outBuf, message->result))
                   goto failed;
   
               if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
                   LIT(ZT("</p:CIMStatusCode>")XML_CR)))
               {
                   goto failed;
               }
   
               // CIM_Error:Message
               if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
                   LIT(ZT("<p:Message xsi:type=\"cim:cimString\">"))))
               {
                   goto failed;
               }
   
               if (MI_RESULT_OK != WSBuf_AddString(&outBuf, textToSend))
               {
                   goto failed;
               }
   
               if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
                   LIT(ZT("</p:Message>")XML_CR)))
               {
                   goto failed;
               }
   
               // CIM_Error:MessageArguments
               if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
                   LIT(ZT("<p:MessageArguments xsi:type=\"cim:cimString\"></p:MessageArguments>"))))
               {
                   goto failed;
               }
   
               //  CIM_Error:MessageID
               if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
                   LIT(ZT("<p:MessageID xsi:type=\"cim:cimString\">OMI:MI_Result:"))))
               {
                   goto failed;
               }
   
               if (MI_RESULT_OK != WSBuf_AddUint32(&outBuf, message->result))
                   goto failed;
   
               if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
                   LIT(ZT("</p:MessageID>")XML_CR)))
               {
                   goto failed;
               }
   
               //OMI_Category - uint32
               if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
                   LIT(ZT("<p:OMI_Category xsi:type=\"cim:cimUnsignedInt\">"))))
               {
                   goto failed;
               }
   
               if (MI_RESULT_OK != WSBuf_AddUint32(&outBuf, ErrorCategoryFromErrorCode(message->result, PAL_T("MI"))))
                   goto failed;
   
               if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
                   LIT(ZT("</p:OMI_Category>")XML_CR)))
               {
                   goto failed;
               }
   
               //OMI_Code - uint32
               if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
                   LIT(ZT("<p:OMI_Code xsi:type=\"cim:cimUnsignedInt\">"))))
               {
                   goto failed;
               }
   
               if (MI_RESULT_OK != WSBuf_AddUint32(&outBuf, message->result))
                   goto failed;
   
               if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
                   LIT(ZT("</p:OMI_Code>")XML_CR)))
               {
                   goto failed;
               }
   
               //OMI_ErrorMessage - string
               if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
                   LIT(ZT("<p:OMI_ErrorMessage xsi:type=\"cim:cimString\">"))))
               {
                   goto failed;
               }
   
               if (MI_RESULT_OK != WSBuf_AddString(&outBuf, textToSend))
               {
                   goto failed;
               }
   
               if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
                   LIT(ZT("</p:OMI_ErrorMessage>")XML_CR)))
               {
                   goto failed;
               }
   
   
               //OMI_Type - string
               if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
                   LIT(ZT("<p:OMI_Type xsi:type=\"cim:cimString\">MI</p:OMI_Type>"))))
               {
                   goto failed;
               }
   
               // CIM_Error:OwningEntity
               if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
                   LIT(ZT("<p:OwningEntity xsi:type=\"cim:cimString\">OMI:CIMOM</p:OwningEntity>"))))
               {
                   goto failed;
               }
   
               // CIM_Error:PerceivedSeverity
               if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
                   LIT(ZT("<p:PerceivedSeverity xsi:type=\"cim:cimUnsignedInt\">7</p:PerceivedSeverity>"))))
               {
             goto failed;             goto failed;
     }     }
  
               // CIM_Error:ProbableCause
     if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,     if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
         LIT( MI_T("</SOAP-ENV:Text>")      XML_CR                  LIT(ZT("<p:ProbableCause xsi:type=\"cim:cimUnsignedInt\">0</p:ProbableCause>"))))
         MI_T("</SOAP-ENV:Reason>")      XML_CR              {
         MI_T("</SOAP-ENV:Fault>")       XML_CR  
         MI_T("</SOAP-ENV:Body>")        XML_CR  
         MI_T("</SOAP-ENV:Envelope>")    XML_CR)) )  
         goto failed;         goto failed;
               }
  
               // CIM_Error:ProbableCauseDescription
               if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
                   LIT(ZT("<p:ProbableCauseDescription xsi:type=\"cim:cimString\">Unknown</p:ProbableCauseDescription>"))))
               {
                   goto failed;
               }
           }
   
   
           if ((MI_RESULT_OK != WSBuf_AddLit(&outBuf, LIT(ZT("</p:"))) ||
               (MI_RESULT_OK != WSBuf_AddString(&outBuf, (message->cimErrorClassName?message->cimErrorClassName:ZT("OMI_Error")))) ||
               (MI_RESULT_OK != WSBuf_AddLit(&outBuf, LIT(ZT(">") XML_CR ZT("</SOAP-ENV:Detail>")XML_CR)))))
           {
               goto failed;
           }
       }
   
       if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
           LIT(ZT("</SOAP-ENV:Fault>")XML_CR
           ZT("</SOAP-ENV:Body>")XML_CR
           ZT("</SOAP-ENV:Envelope>")XML_CR)))
       {
           goto failed;
       }
  
     return WSBuf_StealPage(&outBuf);     return WSBuf_StealPage(&outBuf);
  
Line 1651 
Line 2281 
 } }
  
 Page* WSBuf_CreateReleaseResponsePage( Page* WSBuf_CreateReleaseResponsePage(
     const char* requestMessageID)      const ZChar* requestMessageID)
 { {
     WSBuf   outBuf;     WSBuf   outBuf;
  
Line 1661 
Line 2291 
  
     /* fault header */     /* fault header */
     if (MI_RESULT_OK != WSBuf_CreateSoapResponseHeader(&outBuf,     if (MI_RESULT_OK != WSBuf_CreateSoapResponseHeader(&outBuf,
         LIT(MI_T("http://schemas.xmlsoap.org/ws/2004/09/enumeration/ReleaseResponse")),          LIT(ZT("http://schemas.xmlsoap.org/ws/2004/09/enumeration/ReleaseResponse")),
         requestMessageID))         requestMessageID))
         goto failed;         goto failed;
  
     if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,     if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
         LIT(         LIT(
         MI_T("</SOAP-ENV:Header>")      XML_CR  XML_CR          ZT("</SOAP-ENV:Header>")XML_CR XML_CR
         MI_T("<SOAP-ENV:Body/>")         XML_CR          ZT("<SOAP-ENV:Body/>")XML_CR
         MI_T("</SOAP-ENV:Envelope>")    XML_CR)) )          ZT("</SOAP-ENV:Envelope>")XML_CR)))
         goto failed;         goto failed;
  
     return WSBuf_StealPage(&outBuf);     return WSBuf_StealPage(&outBuf);
Line 1682 
Line 2312 
  
 WSBUF_FAULT_CODE    WSBuf_CIMErrorToWSFault( WSBUF_FAULT_CODE    WSBuf_CIMErrorToWSFault(
     MI_Uint32       cimErrorCode,     MI_Uint32       cimErrorCode,
     const MI_Char** description )      const ZChar** description)
 { {
     MI_Uint32 index = cimErrorCode < MI_COUNT(s_cimerrors) ? cimErrorCode : MI_RESULT_FAILED;     MI_Uint32 index = cimErrorCode < MI_COUNT(s_cimerrors) ? cimErrorCode : MI_RESULT_FAILED;
  


Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

ViewCVS 0.9.2