1 krisbash 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 krisbash 1.1 **==============================================================================
23 */
24
25 #include "messages.h"
26 #include "packing.h"
27 #include <assert.h>
28 #include "result.h"
29 #include <pal/format.h>
30 #include "log.h"
31 #include "miextras.h"
32
33 typedef enum _FieldType
34 {
35 FT_BOOLEAN = MI_BOOLEAN,
36 FT_UINT8 = MI_UINT8,
37 FT_SINT8 = MI_SINT8,
38 FT_UINT16 = MI_UINT16,
39 FT_SINT16 = MI_SINT16,
40 FT_UINT32 = MI_UINT32,
41 FT_SINT32 = MI_SINT32,
42 FT_UINT64 = MI_UINT64,
43 krisbash 1.1 FT_SINT64 = MI_SINT64,
44 FT_REAL32 = MI_REAL32,
45 FT_REAL64 = MI_REAL64,
46 FT_CHAR16 = MI_CHAR16,
47 FT_DATETIME = MI_DATETIME,
48 FT_STRING = MI_STRING,
49 FT_REFERENCE = MI_REFERENCE,
50 FT_INSTANCE = MI_INSTANCE,
51 FT_BOOLEANA = MI_BOOLEANA,
52 FT_UINT8A = MI_UINT8A,
53 FT_SINT8A = MI_SINT8A,
54 FT_UINT16A = MI_UINT16A,
55 FT_SINT16A = MI_SINT16A,
56 FT_UINT32A = MI_UINT32A,
57 FT_SINT32A = MI_SINT32A,
58 FT_UINT64A = MI_UINT64A,
59 FT_SINT64A = MI_SINT64A,
60 FT_REAL32A = MI_REAL32A,
61 FT_REAL64A = MI_REAL64A,
62 FT_CHAR16A = MI_CHAR16A,
63 FT_DATETIMEA = MI_DATETIMEA,
64 krisbash 1.1 FT_STRINGA = MI_STRINGA,
65 FT_REFERENCEA = MI_REFERENCEA,
66 FT_INSTANCEA = MI_INSTANCEA,
67 FT_RESULT,
68 FT_ATOMIC
69 }
70 FieldType;
71
72 /* Defines meta data for message field (to support printing) */
73 typedef struct Field
74 {
75 /* Name of field */
76 const char* name;
77
78 /* (ZT=Tag, S=String, B=Boolean, A=StringArray, O=Object) */
79 FieldType type;
80
81 /* Byte off within structure to this field */
82 size_t off;
83 }
84 Field;
85 krisbash 1.1
86 static void _Message_Print(
87 const void* msg,
88 FILE* os,
89 const char* structName,
90 const Field fields[])
91 {
92 size_t i;
93
94 Ftprintf(os, ZT("%s\n"), scs(structName));
95 Ftprintf(os, ZT("{\n"));
96
97 for (i = 0; fields[i].name; i++)
98 {
99 const Field* f = &fields[i];
100
101 /* Print name */
102 Ftprintf(os, ZT(" %s="), scs(f->name));
103
104 /* Print value */
105 switch (f->type)
106 krisbash 1.1 {
107 case FT_UINT32:
108 {
109 MessageTag* p = (MessageTag*)((char*)msg + f->off);
110 Ftprintf(os, ZT("%u"), *p);
111 break;
112 }
113 case FT_RESULT:
114 {
115 MI_Result* p = (MI_Result*)((char*)msg + f->off);
116 Ftprintf(os, PAL_T("%u [%T]"),*p, tcs(Result_ToString(*p)));
117 break;
118 }
119 case FT_ATOMIC:
120 {
121 ptrdiff_t* p = (ptrdiff_t*)((char*)msg + f->off);
122 Ftprintf(os, MI_T("%d"),(int)(*p));
123 break;
124 }
125 case FT_UINT64:
126 {
127 krisbash 1.1 MI_Uint64* p = (MI_Uint64*)((char*)msg + f->off);
128 Ftprintf(os, UINT64_FMT_T, *p);
129 break;
130 }
131 case FT_BOOLEAN:
132 {
133 MI_Boolean* p = (MI_Boolean*)((char*)msg + f->off);
134 Ftprintf(os, ZT("%s"), scs(*p ? "TRUE" : "FALSE"));
135 break;
136 }
137 case FT_STRING:
138 {
139 ZChar** p = (ZChar**)((char*)msg + f->off);
140
141 if (*p)
142 Ftprintf(os, PAL_T("\"%T\""), tcs(*p));
143 else
144 Ftprintf(os, PAL_T("NULL"));
145 break;
146 }
147 case FT_STRINGA:
148 krisbash 1.1 {
149 StringArray** p = (StringArray**)((char*)msg + f->off);
150
151 if (*p)
152 StringArray_Print(*p, os);
153 else
154 Ftprintf(os, ZT("NULL"));
155 break;
156 }
157 case FT_INSTANCE:
158 {
159 MI_Instance** p = (MI_Instance**)((char*)msg + f->off);
160
161 if (*p)
162 {
163 Ftprintf(os, ZT("\n"));
164 MI_Instance_Print(*p, os, 1);
165 }
166 else
167 Ftprintf(os, ZT("NULL\n"));
168 break;
169 krisbash 1.1 }
170 default:
171 break;
172 }
173
174 if (f->type != FT_INSTANCE)
175 Ftprintf(os, ZT("\n"));
176 }
177
178 Ftprintf(os, ZT("}\n"));
179 }
180
181 void MessagePrint(const Message* msg, FILE* os)
182 {
183 switch ( msg->tag )
184 {
185 case GetInstanceReqTag:
186 {
187 const GetInstanceReq* m = (const GetInstanceReq*)msg;
188 GetInstanceReq_Print(m, os);
189 }
190 krisbash 1.1 break;
191
192 case GetClassReqTag:
193 {
194 const GetClassReq* m = (const GetClassReq*)msg;
195 GetClassReq_Print(m, os);
196 }
197 break;
198
199 case PostInstanceMsgTag:
200 {
201 const PostInstanceMsg* m = (const PostInstanceMsg*)msg;
202 PostInstanceMsg_Print(m, os);
203 }
204 break;
205
206 case PostSchemaMsgTag:
207 {
208 const PostSchemaMsg* m = (const PostSchemaMsg*)msg;
209 PostSchemaMsg_Print(m, os);
210 }
211 krisbash 1.1 break;
212
213 case EnumerateInstancesReqTag:
214 {
215 const EnumerateInstancesReq* m = (const EnumerateInstancesReq*)msg;
216 EnumerateInstancesReq_Print(m, os);
217 }
218 break;
219
220 case PostResultMsgTag:
221 {
222 const PostResultMsg* m = (const PostResultMsg*)msg;
223 PostResultMsg_Print(m, os);
224 }
225 break;
226
227 case NoOpReqTag:
228 {
229 const NoOpReq* m = (const NoOpReq*)msg;
230 NoOpReq_Print(m, os);
231 }
232 krisbash 1.1 break;
233
234 case NoOpRspTag:
235 {
236 const NoOpRsp* m = (const NoOpRsp*)msg;
237 NoOpRsp_Print(m, os);
238 }
239 break;
240
241 case InvokeReqTag:
242 {
243 const InvokeReq* m = (const InvokeReq*)msg;
244 InvokeReq_Print(m, os);
245 }
246 break;
247
248 case AssociatorsOfReqTag:
249 {
250 const AssociationsOfReq* m = (const AssociationsOfReq*)msg;
251 AssociatorsOfReq_Print(m, os);
252 }
253 krisbash 1.1 break;
254
255 case ReferencesOfReqTag:
256 {
257 const AssociationsOfReq* m = (const AssociationsOfReq*)msg;
258 ReferencesOfReq_Print(m, os);
259 }
260 break;
261
262 case SubscribeReqTag:
263 {
264 const SubscribeReq* m = (const SubscribeReq*)msg;
265 SubscribeReq_Print(m, os);
266 }
267 break;
268
269 case UnsubscribeReqTag:
270 {
271 const UnsubscribeReq* m = (const UnsubscribeReq*)msg;
272 UnsubscribeReq_Print(m, os);
273 }
274 krisbash 1.1 break;
275
276 case DeleteInstanceReqTag:
277 {
278 const DeleteInstanceReq* m = (const DeleteInstanceReq*)msg;
279 DeleteInstanceReq_Print(m, os);
280 }
281 break;
282
283 case CreateInstanceReqTag:
284 {
285 const CreateInstanceReq* m = (const CreateInstanceReq*)msg;
286 CreateInstanceReq_Print(m, os);
287 }
288 break;
289
290 case ModifyInstanceReqTag:
291 {
292 const ModifyInstanceReq* m = (const ModifyInstanceReq*)msg;
293 ModifyInstanceReq_Print(m, os);
294 }
295 krisbash 1.1 break;
296
297 case BinProtocolNotificationTag:
298 {
299 const BinProtocolNotification* m = (const BinProtocolNotification*)msg;
300 BinProtocolNotification_Print(m, os);
301 }
302 break;
303
304 case PostIndicationMsgTag:
305 {
306 const PostIndicationMsg* m = (const PostIndicationMsg*)msg;
307 PostIndicationMsg_Print(m, os);
308 }
309 break;
310
311 default:
312 Ftprintf(os, ZT("unknown message tag %d\n"), msg->tag);
313 break;
314
315 }
316 krisbash 1.1 }
317
318 void GetClassReq_Print(const GetClassReq* msg, FILE* os)
319 {
320 typedef GetClassReq Self;
321 static const Field fields[] =
322 {
323 {"tag", FT_UINT32, offsetof(Self, base.base.tag)},
324 {"operationId", FT_UINT64, offsetof(Self, base.base.operationId)},
325 {"options", FT_INSTANCE, offsetof(Self, base.options)},
326 {"nameSpace", FT_STRING, offsetof(Self, nameSpace)},
327 {"className", FT_STRING, offsetof(Self, className)},
328 {"userAgent", FT_UINT32, offsetof(Self, base.userAgent)},
329 {NULL, 0, 0},
330 };
331 _Message_Print(msg, os, "GetClassReq", fields);
332 }
333
334 void GetInstanceReq_Print(const GetInstanceReq* msg, FILE* os)
335 {
336 typedef GetInstanceReq Self;
337 krisbash 1.1 static const Field fields[] =
338 {
339 {"tag", FT_UINT32, offsetof(Self, base.base.tag)},
340 {"operationId", FT_UINT64, offsetof(Self, base.base.operationId)},
341 {"options", FT_INSTANCE, offsetof(Self, base.options)},
342 {"instanceName", FT_INSTANCE, offsetof(Self, instanceName)},
343 {"includeClassOrigin", FT_BOOLEAN, offsetof(Self, includeClassOrigin)},
344 {"propertySet", FT_STRINGA, offsetof(Self, propertySet)},
345 {"userAgent", FT_UINT32, offsetof(Self, base.userAgent)},
346 {NULL, 0, 0},
347 };
348 _Message_Print(msg, os, "GetInstanceReq", fields);
349 }
350
351 void CreateInstanceReq_Print(const CreateInstanceReq* msg, FILE* os)
352 {
353 typedef CreateInstanceReq Self;
354 static const Field fields[] =
355 {
356 {"tag", FT_UINT32, offsetof(Self, base.base.tag)},
357 {"operationId", FT_UINT64, offsetof(Self, base.base.operationId)},
358 krisbash 1.1 {"options", FT_INSTANCE, offsetof(Self, base.options)},
359 {"instanceName", FT_INSTANCE, offsetof(Self, instance)},
360 {"propertySet", FT_STRINGA, offsetof(Self, propertySet)},
361 {"userAgent", FT_UINT32, offsetof(Self, base.userAgent)},
362 {NULL, 0, 0},
363 };
364 _Message_Print(msg, os, "CreateInstanceReq", fields);
365 }
366
367 void ModifyInstanceReq_Print(const ModifyInstanceReq* msg, FILE* os)
368 {
369 typedef ModifyInstanceReq Self;
370 static const Field fields[] =
371 {
372 {"tag", FT_UINT32, offsetof(Self, base.base.tag)},
373 {"operationId", FT_UINT64, offsetof(Self, base.base.operationId)},
374 {"options", FT_INSTANCE, offsetof(Self, base.options)},
375 {"instanceName", FT_INSTANCE, offsetof(Self, instance)},
376 {"propertySet", FT_STRINGA, offsetof(Self, propertySet)},
377 {"userAgent", FT_UINT32, offsetof(Self, base.userAgent)},
378 {NULL, 0, 0},
379 krisbash 1.1 };
380 _Message_Print(msg, os, "ModifyInstanceReq", fields);
381 }
382
383 void DeleteInstanceReq_Print(const DeleteInstanceReq* msg, FILE* os)
384 {
385 typedef DeleteInstanceReq Self;
386 static const Field fields[] =
387 {
388 {"tag", FT_UINT32, offsetof(Self, base.base.tag)},
389 {"operationId", FT_UINT64, offsetof(Self, base.base.operationId)},
390 {"options", FT_INSTANCE, offsetof(Self, base.options)},
391 {"instanceName", FT_INSTANCE, offsetof(Self, instanceName)},
392 {"userAgent", FT_UINT32, offsetof(Self, base.userAgent)},
393 {NULL, 0, 0},
394 };
395 _Message_Print(msg, os, "DeleteInstanceReq", fields);
396 }
397
398 void InvokeReq_Print(const InvokeReq* msg, FILE* os)
399 {
400 krisbash 1.1 typedef InvokeReq Self;
401 static const Field fields[] =
402 {
403 {"tag", FT_UINT32, offsetof(Self, base.base.tag)},
404 {"operationId", FT_UINT64, offsetof(Self, base.base.operationId)},
405 {"options", FT_INSTANCE, offsetof(Self, base.options)},
406 {"nameSpace", FT_STRING, offsetof(Self, nameSpace)},
407 {"className", FT_STRING, offsetof(Self, className)},
408 {"function", FT_STRING, offsetof(Self, function)},
409 {"instance", FT_INSTANCE, offsetof(Self, instance)},
410 {"instanceParams", FT_INSTANCE, offsetof(Self, instanceParams)},
411 {"userAgent", FT_UINT32, offsetof(Self, base.userAgent)},
412 {NULL, 0, 0},
413 };
414 _Message_Print(msg, os, "InvokeReq", fields);
415 }
416
417 void AssociatorsOfReq_Print(const AssociationsOfReq* msg, FILE* os)
418 {
419 typedef AssociationsOfReq Self;
420 static const Field fields[] =
421 krisbash 1.1 {
422 {"tag", FT_UINT32, offsetof(Self, base.base.tag)},
423 {"operationId", FT_UINT64, offsetof(Self, base.base.operationId)},
424 {"options", FT_INSTANCE, offsetof(Self, base.options)},
425 {"nameSpace", FT_STRING, offsetof(Self, nameSpace)},
426 {"assocClass", FT_STRING, offsetof(Self, assocClass)},
427 {"resultClass", FT_STRING, offsetof(Self, resultClass)},
428 {"role", FT_STRING, offsetof(Self, role)},
429 {"resultRole", FT_STRING, offsetof(Self, resultRole)},
430 {"instance", FT_INSTANCE, offsetof(Self, instance)},
431 {"userAgent", FT_UINT32, offsetof(Self, base.userAgent)},
432 {NULL, 0, 0},
433 };
434 _Message_Print(msg, os, "AssociationsOfReq", fields);
435 }
436
437 void ReferencesOfReq_Print(const AssociationsOfReq* msg, FILE* os)
438 {
439 typedef AssociationsOfReq Self;
440 static const Field fields[] =
441 {
442 krisbash 1.1 {"tag", FT_UINT32, offsetof(Self, base.base.tag)},
443 {"operationId", FT_UINT64, offsetof(Self, base.base.operationId)},
444 {"options", FT_INSTANCE, offsetof(Self, base.options)},
445 {"nameSpace", FT_STRING, offsetof(Self, nameSpace)},
446 {"assocClass", FT_STRING, offsetof(Self, assocClass)},
447 {"role", FT_STRING, offsetof(Self, role)},
448 {"instance", FT_INSTANCE, offsetof(Self, instance)},
449 {"userAgent", FT_UINT32, offsetof(Self, base.userAgent)},
450 {NULL, 0, 0},
451 };
452 _Message_Print(msg, os, "ReferencesOfReq", fields);
453 }
454
455 void PostInstanceMsg_Print(const PostInstanceMsg* msg, FILE* os)
456 {
457 typedef PostInstanceMsg Self;
458 static const Field fields[] =
459 {
460 {"tag", FT_UINT32, offsetof(Self, base.tag)},
461 {"operationId", FT_UINT64, offsetof(Self, base.operationId)},
462 {"instance", FT_INSTANCE, offsetof(Self, instance)},
463 krisbash 1.1 {NULL, 0, 0},
464 };
465 _Message_Print(msg, os, "PostInstanceMsg", fields);
466 }
467
468 void PostSchemaMsg_Print(const PostSchemaMsg* msg, FILE* os)
469 {
470 typedef PostSchemaMsg Self;
471 static const Field fields[] =
472 {
473 {"tag", FT_UINT32, offsetof(Self, base.tag)},
474 {"operationId", FT_UINT64, offsetof(Self, base.operationId)},
475 {NULL, 0, 0},
476 };
477 _Message_Print(msg, os, "PostSchemaMsg", fields);
478 }
479
480 void PostResultMsg_Print(const PostResultMsg* msg, FILE* os)
481 {
482 typedef PostResultMsg Self;
483 static const Field fields[] =
484 krisbash 1.1 {
485 {"tag", FT_UINT32, offsetof(Self, base.tag)},
486 {"operationId", FT_UINT64, offsetof(Self, base.operationId)},
487 {"result", FT_RESULT, offsetof(Self, result)},
488 {"errorMessage", FT_STRING, offsetof(Self, errorMessage)},
489 {"CIM_Error", FT_INSTANCE, offsetof(Self, cimError)},
490 {"CIM_Error Class Name", FT_STRING, offsetof(Self, cimErrorClassName)},
491 {NULL, 0, 0},
492 };
493 _Message_Print(msg, os, "PostResultMsg", fields);
494 }
495
496 void EnumerateInstancesReq_Print(
497 const EnumerateInstancesReq* msg,
498 FILE* os)
499 {
500 typedef EnumerateInstancesReq Self;
501 static const Field fields[] =
502 {
503 {"tag", FT_UINT32, offsetof(Self, base.base.tag)},
504 {"operationId", FT_UINT64, offsetof(Self, base.base.operationId)},
505 krisbash 1.1 {"options", FT_INSTANCE, offsetof(Self, base.options)},
506 {"nameSpace", FT_STRING, offsetof(Self, nameSpace)},
507 {"className", FT_STRING, offsetof(Self, className)},
508 {"requestClassName", FT_STRING, offsetof(Self, requestClassName)},
509 {"deepInheritance", FT_BOOLEAN, offsetof(Self, deepInheritance)},
510 {"includeClassOrigin", FT_BOOLEAN, offsetof(Self, includeClassOrigin)},
511 {"propertySet", FT_STRINGA, offsetof(Self, propertySet)},
512 {"queryLanguage", FT_STRING, offsetof(Self, queryLanguage)},
513 {"queryExpression", FT_STRING, offsetof(Self, queryExpression)},
514 {"userAgent", FT_UINT32, offsetof(Self, base.userAgent)},
515 {NULL, 0, 0},
516 };
517 _Message_Print(msg, os, "EnumerateInstancesReq", fields);
518 }
519
520 void SubscribeReq_Print(const SubscribeReq* msg, FILE* os)
521 {
522 typedef SubscribeReq Self;
523 static const Field fields[] =
524 {
525 {"tag", FT_UINT32, offsetof(Self, base.base.tag)},
526 krisbash 1.1 {"operationId", FT_UINT64, offsetof(Self, base.base.operationId)},
527 {"options", FT_INSTANCE, offsetof(Self, base.options)},
528 {"nameSpace", FT_STRING, offsetof(Self, nameSpace)},
529 {"className", FT_STRING, offsetof(Self, className)},
530 {"bookmark", FT_STRING, offsetof(Self, bookmark)},
531 {"filter", FT_STRING, offsetof(Self, filter)},
532 {"language", FT_STRING, offsetof(Self, language)},
533 {"userAgent", FT_UINT32, offsetof(Self, base.userAgent)},
534 {NULL, 0, 0},
535 };
536 _Message_Print(msg, os, "SubscribeReq", fields);
537 }
538
539 void UnsubscribeReq_Print(const UnsubscribeReq* msg, FILE* os)
540 {
541 typedef UnsubscribeReq Self;
542 static const Field fields[] =
543 {
544 {"tag", FT_UINT32, offsetof(Self, base.base.tag)},
545 {"operationId", FT_UINT64, offsetof(Self, base.base.operationId)},
546 {"options", FT_INSTANCE, offsetof(Self, base.options)},
547 krisbash 1.1 {NULL, 0, 0},
548 };
549 _Message_Print(msg, os, "UnsubscribeReq", fields);
550 }
551
552 void NoOpReq_Print(const NoOpReq* msg, FILE* os)
553 {
554 typedef NoOpReq Self;
555 static const Field fields[] =
556 {
557 {"tag", FT_UINT32, offsetof(Self, base.base.tag)},
558 {"operationId", FT_UINT64, offsetof(Self, base.base.operationId)},
559 {"options", FT_INSTANCE, offsetof(Self, base.options)},
560 {"userAgent", FT_UINT32, offsetof(Self, base.userAgent)},
561 {NULL, 0, 0},
562 };
563 _Message_Print(msg, os, "NoOpReq", fields);
564 }
565
566 void NoOpRsp_Print(const NoOpRsp* msg, FILE* os)
567 {
568 krisbash 1.1 typedef NoOpRsp Self;
569 static const Field fields[] =
570 {
571 {"tag", FT_UINT32, offsetof(Self, base.tag)},
572 {"operationId", FT_UINT64, offsetof(Self, base.operationId)},
573 {NULL, 0, 0},
574 };
575 _Message_Print(msg, os, "NoOpRsp", fields);
576 }
577
578 void BinProtocolNotification_Print(const BinProtocolNotification* msg, FILE* os)
579 {
580 typedef BinProtocolNotification Self;
581 static const Field fields[] =
582 {
583 {"tag", FT_UINT32, offsetof(Self, base.tag)},
584 {"operationId", FT_UINT64, offsetof(Self, base.operationId)},
585 {NULL, 0, 0},
586 };
587 _Message_Print(msg, os, "BinProtocolNotification", fields);
588 }
589 krisbash 1.1
590 void PostIndicationMsg_Print(const PostIndicationMsg* msg, FILE* os)
591 {
592 typedef PostIndicationMsg Self;
593 typedef PostInstanceMsg SelfBase;
594 static const Field fields[] =
595 {
596 {"tag", FT_UINT32, offsetof(SelfBase, base.tag)},
597 {"operationId", FT_UINT64, offsetof(SelfBase, base.operationId)},
598 {"instance", FT_INSTANCE, offsetof(SelfBase, instance)},
599 {"bookmark", FT_STRING, offsetof(Self, bookmark)},
600 {"machineID", FT_STRING, offsetof(Self, machineID)},
601 {NULL, 0, 0},
602 };
603 _Message_Print(msg, os, "PostIndicationMsg", fields);
604 }
605
|