(file) Return to wsmanbuffer.h CVS log (file) (dir) Up to [OMI] / omi / protocol

  1 mike  1.1 /*
  2           **==============================================================================
  3           **
  4           ** Open Management Infrastructure (OMI)
  5           **
  6           ** Copyright (c) Microsoft Corporation
  7           ** 
  8           ** Licensed under the Apache License, Version 2.0 (the "License"); you may not 
  9           ** use this file except in compliance with the License. You may obtain a copy 
 10           ** of the License at 
 11           **
 12           **     http://www.apache.org/licenses/LICENSE-2.0 
 13           **
 14           ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15           ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
 16           ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
 17           ** MERCHANTABLITY OR NON-INFRINGEMENT. 
 18           **
 19           ** See the Apache 2 License for the specific language governing permissions 
 20           ** and limitations under the License.
 21           **
 22 mike  1.1 **==============================================================================
 23           */
 24           
 25           #ifndef _omi_wsman_buffer_h
 26           #define _omi_wsman_buffer_h
 27           
 28           #include "config.h"
 29           #include <string.h>
 30           #include <common.h>
 31           //#include <base/messages.h>
 32           #include <base/batch.h>
 33           #include <base/strings.h>
 34           
 35           #if defined(_MSC_VER)
 36           /* warning C4204: nonstandard extension used : non-constant aggregate initializer */
 37           # pragma warning(disable : 4204)
 38           
 39           #endif /* _MSC_VER */
 40           
 41           BEGIN_EXTERNC
 42           
 43 mike  1.1 typedef enum _WSBUF_FAULT_CODE
 44           {
 45               WSBUF_FAULT_INTERNAL_ERROR,
 46               WSBUF_FAULT_NOT_SUPPORTED,
 47               WSBUF_FAULT_NOT_UNDERSTOOD,
 48               WSBUF_FAULT_DESTINATION_UNREACHABLE,
 49               WSBUF_FAULT_ACCESS_DENIED,
 50               WSBUF_FAULT_ENCODING_LIMIT
 51           }
 52           WSBUF_FAULT_CODE;
 53           
 54           typedef struct _WS_Buffer
 55           {
 56               Page*   page;
 57           
 58               MI_Uint32   position;
 59           }
 60           WS_Buffer;
 61           
 62           MI_Result WSBuf_Init(
 63               WS_Buffer* buf,
 64 mike  1.1     MI_Uint32 initialSize);
 65           
 66           MI_Result WSBuf_Destroy(
 67               WS_Buffer* buf);
 68           
 69           MI_Result __WSBuf_AddLit(
 70               WS_Buffer* buf,
 71               const MI_Char* str,
 72               MI_Uint32 size);
 73           
 74           /* add literal string to the buffer; 
 75            * skip encoding of special characters;
 76            * length of the string is provided;
 77            * see LIT() macro
 78            */
 79           INLINE MI_Result WSBuf_AddLit(
 80               WS_Buffer* buf,
 81               const MI_Char* str,
 82               MI_Uint32 size)
 83           {
 84               MI_Uint32 n;
 85 mike  1.1 
 86               /* If enough capacity, add string inline */
 87               n = size * sizeof(MI_Char);
 88           
 89               if (n + buf->position < buf->page->u.s.size)
 90               {
 91                   char* data = (char*)(buf->page + 1) + buf->position;
 92                   memcpy(data, str, n);
 93                   ((MI_Char*)data)[size] = 0;
 94           
 95                   buf->position += n;
 96                   return MI_RESULT_OK;
 97               }
 98           
 99               /* Expand buffer and add string */
100               return __WSBuf_AddLit(buf, str, size);
101           }
102           
103           /* add string to the buffer; skip encoding of special characters 
104               typically used with const strings or already encoded values */
105           INLINE MI_Result WSBuf_AddStringNoEncoding(
106 mike  1.1     WS_Buffer* buf,
107               const MI_Char* str)
108           {
109               return WSBuf_AddLit(buf, str, (MI_Uint32)Zlen(str));
110           }
111           
112           INLINE MI_Result WSBuf_AddLit1(
113               WS_Buffer* buf,
114               MI_Char c1)
115           {
116               const MI_Uint32 SIZE = sizeof(c1);
117           
118               if (SIZE + buf->position < buf->page->u.s.size)
119               {
120                   MI_Char* data = (MI_Char*)(((char*)(buf->page + 1)) + buf->position);
121                   data[0] = c1;
122                   data[1] = '\0';
123                   buf->position += SIZE;
124                   return MI_RESULT_OK;
125               }
126               else
127 mike  1.1     {
128                   return __WSBuf_AddLit(buf, &c1, 1);
129               }
130           }
131           
132           INLINE MI_Result WSBuf_AddLit2(
133               WS_Buffer* buf,
134               MI_Char c1,
135               MI_Char c2)
136           {
137               const MI_Uint32 SIZE = 2 * sizeof(c1);
138           
139               if (SIZE + buf->position < buf->page->u.s.size)
140               {
141                   MI_Char* data = (MI_Char*)(((char*)(buf->page + 1)) + buf->position);
142                   data[0] = c1;
143                   data[1] = c2;
144                   data[2] = '\0';
145                   buf->position += SIZE;
146                   return MI_RESULT_OK;
147               }
148 mike  1.1     else
149               {
150                   MI_Char str[2];
151           	    str[0] = c1;
152           	    str[1] = c2;
153                   return __WSBuf_AddLit(buf, str, 2);
154               }
155           }
156           
157           INLINE MI_Result WSBuf_AddLit3(
158               WS_Buffer* buf,
159               MI_Char c1,
160               MI_Char c2,
161               MI_Char c3)
162           {
163               const MI_Uint32 SIZE = 3 * sizeof(c1);
164           
165               if (SIZE + buf->position < buf->page->u.s.size)
166               {
167                   MI_Char* data = (MI_Char*)(((char*)(buf->page + 1)) + buf->position);
168                   data[0] = c1;
169 mike  1.1         data[1] = c2;
170                   data[2] = c3;
171                   data[3] = '\0';
172                   buf->position += SIZE;
173                   return MI_RESULT_OK;
174               }
175               else
176               {
177                   MI_Char str[3];
178           	    str[0] = c1;
179           	    str[1] = c2;
180           	    str[2] = c3;
181                   return __WSBuf_AddLit(buf, str, 3);
182               }
183           }
184           
185           INLINE MI_Result WSBuf_AddLit4(
186               WS_Buffer* buf,
187               MI_Char c1,
188               MI_Char c2,
189               MI_Char c3,
190 mike  1.1     MI_Char c4)
191           {
192               const MI_Uint32 SIZE = 4 * sizeof(c1);
193           
194               if (SIZE + buf->position < buf->page->u.s.size)
195               {
196                   MI_Char* data = (MI_Char*)(((char*)(buf->page + 1)) + buf->position);
197                   data[0] = c1;
198                   data[1] = c2;
199                   data[2] = c3;
200                   data[3] = c4;
201                   data[4] = '\0';
202                   buf->position += SIZE;
203                   return MI_RESULT_OK;
204               }
205               else
206               {
207                   MI_Char str[4];
208           	    str[0] = c1;
209           	    str[1] = c2;
210           	    str[2] = c3;
211 mike  1.1 	    str[3] = c4;
212                   return __WSBuf_AddLit(buf, str, 4);
213               }
214           }
215           
216           MI_Result WSBuf_AddString(
217               WS_Buffer* buf,
218               const MI_Char* str);
219           
220           #if (MI_CHAR_TYPE == 1)
221           #define WSBuf_AddCharStringNoEncoding  WSBuf_AddStringNoEncoding
222           #define WSBuf_AddCharLit               WSBuf_AddLit
223           #else
224           /* */
225           MI_Result WSBuf_AddCharStringNoEncoding(
226               WS_Buffer* buf,
227               const char* str);
228           MI_Result WSBuf_AddCharLit(
229               WS_Buffer* buf,
230               const char* str,
231               MI_Uint32 size);
232 mike  1.1 
233           #endif
234           
235           MI_Result WSBuf_AddUint32(
236               WS_Buffer* buf,
237               MI_Uint32 n);
238           
239           Page* WSBuf_StealPage(
240               WS_Buffer* buf);
241           
242           /*
243               Converts static/dynamic instance into wsman-xml,
244               suitable for concatenating WS-soap xml-response.
245               If successful, result buffer page is attached to the batch.
246               Parameters:
247               instance - instance to convert
248               castToClassDecl [opt] - class-decl of output. Used only for 
249                   deep enumeration with 'base-property-only' flag set.
250                   If set, this parameter must point to a valid base class.
251               batch - batch to borrow memory from
252               flags - flags to control instance encoding mode (EPR/Object)
253 mike  1.1     ptrOut - pointer to result buffer (single string with xml fragment)
254               sizeOut - size of result buffer
255               Returns:
256               OK, FAILED (out of memory)
257           */
258           MI_Result WSBuf_InstanceToBuf(
259               const MI_Instance* instance,
260               MI_Boolean (*filterProperty)(const MI_Char* name, void* data),
261               void* filterPropertyData,
262               const MI_ClassDecl* castToClassDecl,
263               Batch* batch,
264               MI_Uint32 flags,
265               void** ptrOut,
266               MI_Uint32* sizeOut);
267           
268           /* Utility */
269           #define WS_MSG_ID_SIZE      42
270           
271           void WSBuf_GenerateMessageID(
272               MI_Char msgID[WS_MSG_ID_SIZE]);
273           
274 mike  1.1 /* Maps CIMM error to the most relevant WS fault;
275              Retuns description of CIM error (can be used as fault description) */
276           WSBUF_FAULT_CODE    WSBuf_CIMErrorToWSFault(
277               MI_Uint32       cimErrorCode,
278               const MI_Char** description );
279           
280           /* Helper function to create a fault repsonse */
281           Page* WSBuf_CreateFaultResponsePage(
282               WSBUF_FAULT_CODE faultCode,
283               const char* notUnderstoodTag,
284               const char* requestMessageID,
285               const MI_Char* descriptionText);
286           
287           Page* WSBuf_CreateReleaseResponsePage(
288               const char* requestMessageID);
289           
290           /* Creates soap header with provided action. 
291               Funciotn leaves header open so extra header fields can be added */
292           MI_Result WSBuf_CreateSoapResponseHeader(
293               WS_Buffer   *buf,
294               const MI_Char*  action,
295 mike  1.1     MI_Uint32       actionSize,
296               const char*     relatesTo);
297           
298           #define LIT(str) str,(sizeof(str)/sizeof(str[0])-1)
299           
300           END_EXTERNC
301           
302           #endif /* _omi_wsman_buffer_h */

ViewCVS 0.9.2