static void example106() { char *data = "<dummy><qq>This is qq body</qq><pp>This is pp</pp></dummy>"; // WsXmlDocH response; WsManClient *cl = wsman_create_client("mstevbakrov.ims.intel.com", 8889, "/wsman", "http", "wsman", "secret"); client_opt_t *options = wsmc_options_init(); WsXmlDocH request = wsmc_create_request(cl, "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", options, WSMAN_ACTION_TRANSFER_CREATE, NULL, NULL); WsXmlDocH d = wsmc_read_memory(cl, data, strlen(data), NULL, 0); ws_xml_dump_node_tree(stdout, ws_xml_get_doc_root(d)); // WsXmlNodeH n = ws_xml_get_doc_root(d); ws_xml_duplicate_tree(ws_xml_get_soap_body(request), ws_xml_get_doc_root(d)); ws_xml_destroy_doc(d); // ws_xml_copy_node(ws_xml_get_doc_root(d), ws_xml_get_soap_body(request)); ws_xml_dump_node_tree(stdout, ws_xml_get_doc_root(request)); wsman_release_client(cl); ws_xml_destroy_doc(request); }
static void example12() { typedef struct { XML_TYPE_REAL32 value; XML_NODE_ATTR *attrs; } item; item org = {1.257,NULL}; SER_TYPEINFO_REAL32_ATTR; WsXmlDocH doc; WsXmlNodeH node = ws_xml_get_doc_root(doc); printf ("\n\n ******** example12. real32/64 deserialize/serialize ********\n"); WsSerializerContextH cntx = ws_serializer_init(); if (cntx == NULL) { printf("Error ws_create_runtime\n"); return; } doc = ws_xml_create_doc( NULL, "example"); node = ws_xml_get_doc_root(doc); int retval = ws_serialize(cntx, node, &org, real32_TypeInfo, "PowerState", NULL, NULL, 0); printf("ws_serialize: %d\n", retval); ws_xml_dump_node_tree(stdout, node); item *con = (item *)ws_deserialize(cntx, node, real32_TypeInfo, "PowerState", NULL, NULL, 0, 0); if(con->value != org.value) { printf("Mismatched! org.value = %f con->value = %f\n", org.value, con->value); } ws_xml_destroy_doc(doc); ws_serializer_cleanup(cntx); }
/** * Duplicate an XML document * @param dstSoap Destination SOAP handle * @param srcDoc the Source document * @return The new XML document */ WsXmlDocH ws_xml_duplicate_doc( WsXmlDocH srcDoc) { WsXmlDocH dst = NULL; WsXmlNodeH srcRoot = NULL; const char *name, *nsUri; if (!srcDoc) return NULL; srcRoot = ws_xml_get_doc_root(srcDoc); if (!srcRoot) return NULL; name = ws_xml_get_node_local_name(srcRoot); nsUri = ws_xml_get_node_name_ns(srcRoot); if ((dst = ws_xml_create_doc(nsUri, name)) != NULL) { int i; WsXmlNodeH node; WsXmlNodeH dstRoot = ws_xml_get_doc_root(dst); for (i = 0; (node = ws_xml_get_child(srcRoot, i, NULL, NULL)) != NULL; i++) { ws_xml_duplicate_tree(dstRoot, node); } } return dst; }
int WsManTest_EventPoll_EP(WsEventThreadContextH threadcntx) { int retval = 0; WsNotificationInfoH notificationinfo = u_malloc(sizeof(*notificationinfo)); if(notificationinfo == NULL) return -1; notificationinfo->headerOpaqueData = ws_xml_create_doc( XML_NS_OPENWSMAN"/test", "EventTopics"); WsXmlNodeH node = ws_xml_get_doc_root(notificationinfo->headerOpaqueData); if(node) { ws_xml_set_node_text(node, "openwsman.event.test"); } notificationinfo->EventAction = u_strdup(XML_NS_OPENWSMAN"/EventReport"); notificationinfo->EventContent = ws_xml_create_doc( XML_NS_OPENWSMAN"/test", "TestReport"); if(notificationinfo->EventContent == NULL) return retval; node = ws_xml_get_doc_root(notificationinfo->EventContent); time_t timest = time(0); struct tm tm; localtime_r(×t, &tm); ws_xml_add_child_format(node, XML_NS_OPENWSMAN"/test", "EventTime","%u-%u%u-%u%uT%u%u:%u%u:%u%u", tm.tm_year + 1900, (tm.tm_mon + 1)/10, (tm.tm_mon + 1)%10, tm.tm_mday/10, tm.tm_mday%10, tm.tm_hour/10, tm.tm_hour%10, tm.tm_min/10, tm.tm_min%10, tm.tm_sec/10, tm.tm_sec%10); EventPoolOpSetH opset = threadcntx->soap->eventpoolOpSet; if(threadcntx->subsInfo->deliveryMode == WS_EVENT_DELIVERY_MODE_PULL) retval = opset->addpull(threadcntx->subsInfo->subsId, notificationinfo); else retval = opset->add(threadcntx->subsInfo->subsId, notificationinfo); if(retval) { u_free(notificationinfo->EventAction); ws_xml_destroy_doc(notificationinfo->EventContent); ws_xml_destroy_doc(notificationinfo->headerOpaqueData); u_free(notificationinfo); } return 0; }
char *epr_to_txt(epr_t *epr, const char *ns, const char*epr_node_name) { char *buf = NULL; int len; WsXmlDocH doc2; WsXmlDocH doc = ws_xml_create_doc(ns, epr_node_name); WsXmlNodeH rootNode = ws_xml_get_doc_root(doc); epr_serialize(rootNode, NULL, NULL, epr, 1); doc2 = ws_xml_create_doc_by_import( rootNode); ws_xml_dump_memory_node_tree(ws_xml_get_doc_root(doc), &buf, &len); ws_xml_destroy_doc(doc);; ws_xml_destroy_doc(doc2); return buf; }
void wsman_add_selector(WsXmlNodeH baseNode, const char *name, const char *val) { WsXmlNodeH selector = NULL; WsXmlDocH epr = NULL; WsXmlNodeH set = ws_xml_get_child(baseNode, 0, XML_NS_WS_MAN, WSM_SELECTOR_SET); if (val && strstr(val, WSA_EPR)) { epr = ws_xml_read_memory(val, strlen(val), NULL, 0); } if (set || (set = ws_xml_add_child(baseNode, XML_NS_WS_MAN, WSM_SELECTOR_SET, NULL))) { if (epr) { if ((selector = ws_xml_add_child(set, XML_NS_WS_MAN, WSM_SELECTOR, NULL))) { ws_xml_duplicate_tree(selector, ws_xml_get_doc_root(epr)); ws_xml_add_node_attr(selector, NULL, WSM_NAME, name); } } else { if ((selector = ws_xml_add_child(set, XML_NS_WS_MAN, WSM_SELECTOR, val))) { ws_xml_add_node_attr(selector, NULL, WSM_NAME, name); } } } return; }
static void example14() { typedef struct{ }empty; SER_START_ITEMS(empty) SER_END_ITEMS(empty); typedef struct { XML_TYPE_INT16 num; empty empty1; }A; SER_TYPEINFO_INT16; SER_START_ITEMS(A) SER_INT16("id",1), SER_NS_STRUCT(NULL, "empty", 1, empty), SER_END_ITEMS(A); A a1 = {-12, {}}; printf ("\n\n ******* example 14. serialize/de-serialze with empty t_TypeItems *******\n"); WsSerializerContextH cntx = ws_serializer_init(); if (cntx == NULL) { printf("Error ws_create_runtime\n"); return; } WsXmlDocH doc = ws_xml_create_doc(NULL, "example"); WsXmlNodeH node = ws_xml_get_doc_root(doc); empty values = {}; int ret = ws_serialize(cntx, node, &values, A_TypeInfo, CLASSNAME, NULL, NULL, 0); printf("serialize %i bytes\n", ret); ws_xml_dump_node_tree(stdout, node); void *ptr = ws_deserialize(cntx, node, A_TypeInfo, CLASSNAME, NULL, NULL, 0, 0); printf("ptr = %p\n", ptr); ws_serializer_cleanup(cntx); }
static void example10() { char xmlstring[] = "<example><PowerState xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/></example>"; // char xmlstring[] = "<example><PowerState state = \"critical\">5</PowerState></example>"; typedef struct { XML_TYPE_STR value; XML_NODE_ATTR *attrs; } item; SER_TYPEINFO_STRING_ATTR; WsXmlDocH doc = ws_xml_read_memory(xmlstring, strlen(xmlstring), "UTF-8", 0); WsXmlNodeH node = ws_xml_get_doc_root(doc); printf ("\n\n ******** example10. xsi:nil attibute test ********\n"); WsSerializerContextH cntx = ws_serializer_init(); if (cntx == NULL) { printf("Error ws_create_runtime\n"); return; } item *value = (item *)ws_deserialize(cntx, node, string_attr_TypeInfo, "PowerState", NULL, NULL, 0, 0); if(value->attrs) printf("*********attrs->ns = %s attrs->name = %s attrs->value = %s*********\n", value->attrs->ns, value->attrs->name, value->attrs->value); if(ws_havenilvalue(value->attrs)) printf("******** the attribute has xsi:nil ********\n"); ws_xml_destroy_doc(doc); ws_serializer_cleanup(cntx); }
static void xml_print( WsXmlDocH doc) { ws_xml_dump_node_tree(stdout, ws_xml_get_doc_root(doc)); return; }
/** * Create XML document * @param soap SOAP handler * @param rootNsUri Root Namespace URI * @param rootName Root node name * @return XML document */ WsXmlDocH ws_xml_create_doc( const char *rootNsUri, const char *rootName) { WsXmlDocH wsDoc = (WsXmlDocH) u_zalloc(sizeof(*wsDoc)); WsXmlNodeH rootNode; WsXmlNsH ns; char prefix[12]; if (wsDoc == NULL) { error("No memory"); return NULL; } if (!xml_parser_create_doc(wsDoc, rootName) ) { error("xml_parser_create_doc failed"); u_free(wsDoc); return NULL; } if (rootNsUri == NULL) { return wsDoc; } rootNode = ws_xml_get_doc_root((WsXmlDocH) wsDoc); ws_xml_make_default_prefix(rootNode, rootNsUri, prefix, sizeof(prefix)); ns = xml_parser_ns_add(rootNode, rootNsUri, prefix); if (ns == NULL) { error("xml_parser_ns_add failed"); ws_xml_destroy_doc(wsDoc); return NULL; } ws_xml_set_node_name(rootNode, rootNsUri, NULL); return wsDoc; }
int wsman_send_request(WsManClient * cl, WsXmlDocH request) { #ifdef BENCHMARK struct timeval tv0, tv1; long long t0, t1; #endif if ((g_dump_wsman_data) && (g_wsman_dumpfile != NULL)) { fprintf (g_wsman_dumpfile, "\n\n--------------------------------------------\n"); ws_xml_dump_node_tree(g_wsman_dumpfile, ws_xml_get_doc_root(request)); fprintf (g_wsman_dumpfile, "\n"); } if (wsmc_lock(cl) != 0 ) { error("Client busy"); return 1; } wsmc_reinit_conn(cl); #ifdef BENCHMARK gettimeofday(&tv0, NULL); #endif wsmc_handler(cl, request, NULL); #ifdef BENCHMARK gettimeofday(&tv1, NULL); t0 = tv0.tv_sec * 10000000 + tv0.tv_usec; t1 = tv1.tv_sec * 10000000 + tv1.tv_usec; transfer_time += t1 - t0; #endif wsmc_unlock(cl); return 0; }
static void wsman_output(WsXmlDocH doc) { if (doc) ws_xml_dump_node_tree(stdout, ws_xml_get_doc_root(doc)); else printf("returned doc is null\n"); return; }
/** * Build SOAP Fault * @param soapNsUri SOAP Namespace URI * @param faultNsUri Fault Namespace URI * @param code Fault code * @param subCode Fault Subcode * @param reason Fault Reson * @param detail Fault Details * @return Fault XML document */ WsXmlDocH wsman_build_soap_fault(const char *soapNsUri, const char *faultNsUri, const char *code, const char *subCode, const char *reason, const char *detail) { WsXmlDocH doc; if (faultNsUri == NULL) faultNsUri = soapNsUri; if ((doc = ws_xml_create_doc( soapNsUri, SOAP_ENVELOPE)) != NULL) { WsXmlNodeH node, root, fault, body; root = ws_xml_get_doc_root(doc); body = ws_xml_add_child(root, soapNsUri, SOAP_BODY, NULL); ws_xml_define_ns(root, soapNsUri, NULL, 0); ws_xml_define_ns(root, XML_NS_ADDRESSING, NULL, 0); ws_xml_define_ns(root, XML_NS_XML_NAMESPACES, NULL, 0); if (strcmp(soapNsUri, faultNsUri) != 0) ws_xml_define_ns(root, faultNsUri, NULL, 0); if (body && (fault = ws_xml_add_child(body, soapNsUri, SOAP_FAULT, NULL))) { if (code != NULL && (node = ws_xml_add_child(fault, soapNsUri, SOAP_CODE, NULL)) != NULL) { ws_xml_add_qname_child(node, soapNsUri, SOAP_VALUE, soapNsUri, code); if (subCode != NULL && (node = ws_xml_add_child(node, soapNsUri, SOAP_SUBCODE, NULL)) != NULL) { ws_xml_add_qname_child(node, soapNsUri, SOAP_VALUE, faultNsUri, subCode); } } if (reason && (node = ws_xml_add_child(fault, soapNsUri, SOAP_REASON, NULL))) { node = ws_xml_add_child(node, soapNsUri, SOAP_TEXT, reason); ws_xml_add_node_attr(node, XML_NS_XML_NAMESPACES, SOAP_LANG, "en"); } if (detail) { ws_xml_add_child(fault, soapNsUri, SOAP_DETAIL, detail); } } } return doc; }
static void cimxml_build_response_msg(WsXmlDocH indoc, WsXmlDocH *outdoc) { WsXmlDocH doc = NULL; WsXmlNodeH outnode = NULL; WsXmlNodeH innode = NULL; WsXmlNodeH temp = NULL; WsXmlNodeH temp2 = NULL; doc = ws_xml_create_doc(NULL, CIMXML_CIM); outnode = ws_xml_get_doc_root(doc); innode = ws_xml_get_doc_root(indoc); // char *value = ws_xml_get_node_attr(WsXmlNodeH node, int index) ws_xml_add_node_attr(outnode, NULL, CIMXML_CIMVERSION, "2.0"); ws_xml_add_node_attr(outnode, NULL, CIMXML_DTDVERSION, "2.0"); outnode = ws_xml_add_child(outnode, NULL, CIMXML_MESSAGE, NULL); innode = ws_xml_get_child(innode, 0, NULL, CIMXML_MESSAGE); int n = ws_xml_get_node_attr_count(innode); int i = 0; while(i < n) { WsXmlAttrH attr = ws_xml_get_node_attr(innode, i); char *name = ws_xml_get_attr_name(attr); char *value = ws_xml_get_attr_value(attr); ws_xml_add_node_attr(outnode, NULL, name, value); i++; } temp = ws_xml_get_child(innode, 0, NULL, CIMXML_SIMPLEEXPREQ); if(temp) { outnode = ws_xml_add_child(outnode, NULL, CIMXML_SIMPLEEXPRSP, NULL); outnode = ws_xml_add_child(outnode, NULL, CIMXML_EXPMETHODRESPONSE, NULL); ws_xml_add_node_attr(outnode, NULL, CIMXML_NAME, "ExportIndication"); ws_xml_add_child(outnode, NULL, CIMXML_IRETURNVALUE, NULL); } else { temp = ws_xml_get_child(innode, 0, NULL, CIMXML_MULTIEXPREQ); outnode = ws_xml_add_child(outnode, NULL, CIMXML_MULTIEXPRSQ, NULL); n = ws_xml_get_child_count(temp); i = 0; while(i < n) { innode = ws_xml_get_child(temp, i, NULL, CIMXML_SIMPLEEXPREQ); temp2 = ws_xml_add_child(outnode, NULL, CIMXML_EXPMETHODRESPONSE, NULL); ws_xml_add_node_attr(temp2, NULL, CIMXML_NAME, "ExportIndication"); ws_xml_add_child(temp2, NULL, CIMXML_IRETURNVALUE, NULL); i++; } } *outdoc = doc; }
char* wsmc_node_to_formatbuf(WsXmlNodeH node) { char *buf; int len; WsXmlDocH doc = ws_xml_create_doc_by_import( node); ws_xml_dump_memory_node_tree(ws_xml_get_doc_root(doc), &buf, &len); ws_xml_destroy_doc(doc); return buf; }
static void add_subscription_context(WsXmlNodeH node, char *context) { WsXmlNodeH subsnode; WsXmlDocH doc = ws_xml_read_memory(context, strlen(context), "UTF-8", 0); if(doc == NULL) return; subsnode = ws_xml_get_doc_root(doc); ws_xml_duplicate_children(node, subsnode); }
/** * Get SOAP envelope * @param doc XML document * @return XML node with envelope */ WsXmlNodeH ws_xml_get_soap_envelope(WsXmlDocH doc) { WsXmlNodeH root = ws_xml_get_doc_root(doc); if (ws_xml_is_node_qname(root, XML_NS_SOAP_1_2, SOAP_ENVELOPE) || ws_xml_is_node_qname(root, XML_NS_SOAP_1_1, SOAP_ENVELOPE)) { return root; } return NULL; }
static int isvalidCIMIndicationExport(WsXmlDocH doc){ if(doc == NULL) return 0; WsXmlNodeH node = ws_xml_get_doc_root(doc); WsXmlNodeH temp = NULL; node = ws_xml_get_child(node, 0, NULL, CIMXML_MESSAGE); temp = ws_xml_get_child(node, 0, NULL, CIMXML_SIMPLEEXPREQ); if(temp == NULL) { temp = ws_xml_get_child(node, 0, NULL, CIMXML_MULTIEXPREQ); if(temp == NULL) return 0; } return 1; }
static void example4(void) { typedef struct { XML_TYPE_BOOL a; XML_TYPE_STR string; XML_TYPE_BOOL b; } Embed; typedef struct { XML_TYPE_UINT32 A; Embed EMBED[2]; XML_TYPE_STR STRING; } Sample; Sample sample = { 10, {{1, "string 1", 0}, {0, "string 2", 1},}, "STRING", }; SER_START_ITEMS(Embed) SER_BOOL("a", 1), SER_STR("string", 1), SER_BOOL("b", 1), SER_END_ITEMS(Embed); SER_START_ITEMS(Sample) SER_UINT32("A", 1), SER_STRUCT("EMBED", 2, Embed), SER_STR("STRING", 1), SER_END_ITEMS(Sample); WsSerializerContextH cntx; WsXmlDocH doc; WsXmlNodeH node; int retval; printf ("\n\n ******** example4. Static structure array ********\n"); cntx = ws_serializer_init(); if (cntx == NULL) { printf("Error ws_create_runtime\n"); return; } doc = ws_xml_create_doc(NULL, "example"); node = ws_xml_get_doc_root(doc); retval = ws_serialize(cntx, node, &sample, Sample_TypeInfo, CLASSNAME, NULL, NULL, 0); printf("ws_serialize: %d\n", retval); ws_xml_dump_node_tree(stdout, node); }
/** * Create an empty envelope with a <b>Header</b> and a <b>Body</b> * @param soap Soap handler * @param soapVersion The SOAP version to be used for creating the envelope * @return An XMl document */ WsXmlDocH ws_xml_create_envelope( void ) { WsXmlDocH doc = NULL; if ((doc = ws_xml_create_doc(XML_NS_SOAP_1_2, SOAP_ENVELOPE)) != NULL) { WsXmlNodeH root = ws_xml_get_doc_root(doc); if (root == NULL || ws_xml_add_child(root, XML_NS_SOAP_1_2, "Header", NULL) == NULL || ws_xml_add_child(root, XML_NS_SOAP_1_2, "Body", NULL) == NULL) { ws_xml_destroy_doc(doc); doc = NULL; } } return doc; }
static void create_indication_event(WsXmlDocH indoc, WsSubscribeInfo *subsInfo, EventPoolOpSetH opset) { int count, i; int retval; WsNotificationInfoH notificationinfo = NULL; WsXmlNodeH node = ws_xml_get_doc_root(indoc); node = ws_xml_get_child(node, 0, NULL, CIMXML_MESSAGE); WsXmlNodeH tmp = ws_xml_get_child(node, 0, NULL, CIMXML_MULTIEXPREQ); if(tmp) { count = ws_xml_get_child_count(tmp); i = 0; while(i < count) { node = ws_xml_get_child(tmp, i, NULL, CIMXML_SIMPLEEXPREQ); notificationinfo = create_notification_entity(subsInfo, node); if(notificationinfo == NULL) { i++; continue; } if(subsInfo->deliveryMode == WS_EVENT_DELIVERY_MODE_PULL) retval = opset->addpull(subsInfo->subsId, notificationinfo); else retval = opset->add(subsInfo->subsId, notificationinfo); if(retval) { u_free(notificationinfo->EventAction); ws_xml_destroy_doc(notificationinfo->EventContent); u_free(notificationinfo); } i++; } } else { tmp = ws_xml_get_child(node, 0, NULL, CIMXML_SIMPLEEXPREQ); notificationinfo = create_notification_entity(subsInfo, tmp); if(subsInfo->deliveryMode == WS_EVENT_DELIVERY_MODE_PULL) retval = opset->addpull(subsInfo->subsId, notificationinfo); else retval = opset->add(subsInfo->subsId, notificationinfo); if(retval) { u_free(notificationinfo->EventAction); ws_xml_destroy_doc(notificationinfo->EventContent); u_free(notificationinfo); } } }
void wsman_add_properties (WsXmlNodeH baseNode, const char* uri, const char *name, void* val) { WsXmlNodeH node = NULL; WsXmlDocH doc = NULL; int i; property_t* properties = (property_t*)val; for (i = 0; i < properties->count; i++) { char* val = properties->p_value [i]; /* try constructing xml node from the value, if success, value is XML object, if not its a string */ doc = ws_xml_read_memory(val, strlen(val), NULL, 0); if (doc != NULL) { int prefixindex; node = ws_xml_get_doc_root(doc); /* since xml doc is constructed from string it does not have the default prefix index, so scan for default prefix index and set it */ for (prefixindex = 1; prefixindex < 256; prefixindex++) { char prefix [12]; WsXmlNodeH pnode; sprintf(prefix, "n%d", prefixindex); pnode = (WsXmlNodeH)ws_xml_find_ns (node, NULL, prefix, 1); if (pnode == NULL) { break; } } doc->prefixIndex = prefixindex - 1; ws_xml_set_node_name (node, uri, name); ws_xml_duplicate_tree(baseNode, node); ws_xml_destroy_doc (doc); } else { ws_xml_add_child(baseNode, uri, name, val); } } free (properties->p_value); free (properties); return; }
/** * Check if Envelope is valid * @param msg Message data * @param doc XML document * @return 1 if envelope is valid, 0 if not */ int wsman_is_valid_xml_envelope(WsXmlDocH doc) { int retval = 1; char *soapNsUri; WsXmlNodeH root = ws_xml_get_doc_root(doc); if (strcmp(SOAP_ENVELOPE, ws_xml_get_node_local_name(root)) != 0) { retval = 0; goto cleanup; } soapNsUri = ws_xml_get_node_name_ns(root); if (strcmp(soapNsUri, XML_NS_SOAP_1_2) != 0) { retval = 0; goto cleanup; } if (ws_xml_get_soap_body(doc) == NULL) { retval = 0; goto cleanup; } cleanup: return retval; }
static void example13() { XML_TYPE_UINT8 myshorts[] = { 5, 11, 14}; typedef struct { XML_TYPE_UINT16 id; XML_TYPE_DYN_ARRAY shorts; }item; XML_TYPE_DYN_ARRAY array_int8; SER_TYPEINFO_UINT8; SER_TYPEINFO_UINT16; SER_START_ITEMS(item) SER_INT16("id", 1), SER_DYN_ARRAY("temp", 0, 100, uint8), SER_END_ITEMS(item); char xmlstring[] = "<example><Sample><id>3</id></Sample></example>"; printf ("\n\n ****** example 13. de-serialize to int8 array (empty array de-serialization test) ******\n"); WsXmlDocH doc = ws_xml_read_memory(xmlstring, strlen(xmlstring), "UTF-8", 0); WsXmlNodeH node = ws_xml_get_doc_root(doc); WsSerializerContextH cntx = ws_serializer_init(); if (cntx == NULL) { printf("Error ws_create_runtime\n"); return; } item *desvalue = (item *)ws_deserialize(cntx, node, item_TypeInfo, CLASSNAME, NULL, NULL, 0, 0); printf("desvlaue = %p\n", desvalue); array_int8 = desvalue->shorts; int i = 0; printf("id = %d, array_int8->count = %d\n",desvalue->id, array_int8.count); while(i < array_int8.count) { printf("%d ", ((char *)array_int8.data)[i]); i++; } printf("\n"); ws_serializer_cleanup(cntx); }
static void example9(void) { typedef struct { }empty; SER_START_ITEMS(empty) SER_END_ITEMS(empty); char xmlstring[] = "<example></example>"; WsXmlDocH doc = ws_xml_read_memory(xmlstring, strlen(xmlstring), "UTF-8", 0); WsXmlNodeH node = ws_xml_get_doc_root(doc); WsSerializerContextH cntx = ws_serializer_init(); if (cntx == NULL) { printf("Error ws_create_runtime\n"); return; } void *ptr = NULL; ptr = ws_deserialize(cntx, node, empty_TypeItems, NULL, NULL, NULL, 0, 0); printf("ptr = %p\n", ptr); ws_serializer_cleanup(cntx); }
static void wsman_output(WsXmlDocH doc) { ws_xml_dump_node_tree(stdout, ws_xml_get_doc_root(doc)); return; }
static void example11() { typedef struct { XML_TYPE_INT8 byte1; XML_TYPE_INT32 int1; XML_TYPE_INT8 byte2; } Foo; typedef struct { XML_TYPE_INT8 byte1; XML_TYPE_INT16 short1; XML_TYPE_INT32 int1; char *string1; Foo foo; } Sample; Sample sample = { -1, -127, 4, "string", {-12, 196, 8} }; SER_START_ITEMS(Foo) SER_INT8("FOOBYTE1", 1), SER_INT32("FOOINT32", 1), SER_INT8("FOOBYTE2", 1), SER_END_ITEMS(Foo); SER_START_ITEMS(Sample) SER_INT8("BYTE", 1), SER_INT16("SHORT", 1), SER_INT32("INT32", 1), SER_STR("STRING", 1), SER_STRUCT("FOO", 1, Foo), SER_END_ITEMS(Sample); WsSerializerContextH cntx; WsXmlDocH doc; WsXmlNodeH node; int retval; printf ("\n\n ******** example11. Structure with pads (signed int test). ********\n"); cntx = ws_serializer_init(); if (cntx == NULL) { printf("Error ws_create_runtime\n"); return; } doc = ws_xml_create_doc( NULL, "example"); node = ws_xml_get_doc_root(doc); retval = ws_serialize(cntx, node, &sample, Sample_TypeInfo, CLASSNAME, NULL, NULL, 0); printf("ws_serialize: %d\n", retval); ws_xml_dump_node_tree(stdout, node); node = ws_xml_get_doc_root(doc); Sample *cs = (Sample *) ws_deserialize(cntx, node, Sample_TypeInfo, CLASSNAME, NULL, NULL, 0, 0); if (cs == NULL) { printf("Errror ws_deserialize\n"); return; } printf("\n initial and deserialized structures\n"); printf(" byte1 = %d : %d\n", sample.byte1, cs->byte1); printf(" short1 = %d : %d\n", sample.short1, cs->short1); printf(" int1 = %d : %d\n", sample.int1, cs->int1); printf(" string1 = <%s> : <%s>\n", sample.string1, cs->string1); printf(" foo :\n"); printf(" byte1 = %d : %d\n", sample.foo.byte1, cs->foo.byte1); printf(" int1 = %d : %d\n", sample.foo.int1, cs->foo.int1); printf(" byte2 = %d : %d\n", sample.foo.byte2, cs->foo.byte2); }
static void example7(void) { typedef struct { XML_TYPE_STR value; XML_NODE_ATTR *attrs; } Selector; SER_TYPEINFO_STRING_ATTR; typedef struct { XML_TYPE_DYN_ARRAY selectors; } SelectorSet; SER_START_ITEMS(SelectorSet) SER_NS_DYN_ARRAY(XML_NS_WS_MAN, WSM_SELECTOR, 0, 1000, string_attr), SER_END_ITEMS(SelectorSet); typedef struct { XML_TYPE_STR uri; SelectorSet selectorset; } ReferenceParameters; SER_START_ITEMS(ReferenceParameters) SER_NS_STR(XML_NS_WS_MAN, WSM_RESOURCE_URI, 1), SER_NS_STRUCT(XML_NS_WS_MAN, WSM_SELECTOR_SET, 1, SelectorSet), SER_END_ITEMS(ReferenceParameters); typedef struct { XML_TYPE_STR address; ReferenceParameters refparams; } EPR; SER_START_ITEMS(EPR) SER_NS_STR(XML_NS_ADDRESSING, WSA_ADDRESS, 1), SER_NS_STRUCT(XML_NS_ADDRESSING, WSA_REFERENCE_PARAMETERS, 1, ReferenceParameters), SER_END_ITEMS(EPR); XML_NODE_ATTR attrs[3] = { {NULL, NULL, "Name", "SelName1"}, {NULL, NULL, "Name", "SelName2"}, {NULL, NULL, "Name", "SelName3"}, }; Selector selectors[] = { {"selector1", &attrs[0]}, {"selector2", &attrs[1]}, {"selector3", &attrs[2]} }; EPR Epr = { "http://localhost:8889/wsman", {"http://acme.org/hardware/2005/02/storage/physDisk", {{3, selectors}} } }; WsSerializerContextH cntx; WsXmlDocH doc; WsXmlNodeH node; int retval; printf ("\n\n ******** example7. Endpoint Reference ********\n"); cntx = ws_serializer_init(); if (cntx == NULL) { printf("Error ws_create_runtime\n"); return; } doc = ws_xml_create_doc( NULL, "example"); node = ws_xml_get_doc_root(doc); retval = ws_serialize(cntx, node, &Epr, EPR_TypeInfo, "EndpointReference", XML_NS_ADDRESSING, NULL, 0); printf("\n\nws_serialize: %d\n", retval); ws_xml_dump_node_tree(stdout, node); EPR *newEPR; node = ws_xml_get_doc_root(doc); printf("\n\nws_deserialize:\n"); newEPR = (EPR *) ws_deserialize(cntx, node, EPR_TypeInfo, "EndpointReference", XML_NS_ADDRESSING, NULL, 0, 0); if (newEPR == NULL) { printf("Errror ws_deserialize\n"); return; } printf("**** Deserialized document *****\n"); printf("address = %s\n", newEPR->address); printf("refparams.uri = %s\n", newEPR->refparams.uri); int i; Selector *ss = (Selector *) newEPR->refparams.selectorset.selectors.data; if (ss == NULL) { printf (" !!!! newEPR->refparams.selectors.data == NULL\n"); return; } for (i = 0; i < newEPR->refparams.selectorset.selectors.count; i++) { Selector *s; s = ss + i; printf(" Selector("); XML_NODE_ATTR *a = s->attrs; while (a) { printf("%s:%s=%s", a->ns ? a->ns : "", a->name, a->value); a = a->next; } printf(") = %s\n", s->value); } }
static void example1(void) { #define EX1_NS "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem" XML_TYPE_UINT16 myshorts[] = { 5, 11, 14, 19, 27, 36 }; SER_TYPEINFO_UINT16; struct __Sample_Servie { XML_TYPE_BOOL AcceptPause; XML_TYPE_BOOL AcceptStop; XML_TYPE_STR Caption; XML_TYPE_UINT32 CheckPoint; XML_TYPE_STR CreationClassName; XML_TYPE_STR Description; XML_TYPE_BOOL DesktopInteract; XML_TYPE_STR DisplayName; XML_TYPE_STR ErrorControl; XML_TYPE_UINT32 ExitCode; XML_TYPE_STR InstallDate; XML_TYPE_STR Name; XML_TYPE_STR PathName; XML_TYPE_UINT32 ProcessId; XML_TYPE_UINT32 ServiceSpecificExitCode; XML_TYPE_STR ServiceType; XML_TYPE_BOOL Started; XML_TYPE_STR StartMode; XML_TYPE_STR StartName; XML_TYPE_STR State; XML_TYPE_STR Status; XML_TYPE_STR SystemCreationClassName; XML_TYPE_STR SystemName; XML_TYPE_UINT32 TagId; XML_TYPE_UINT32 WaitHint; XML_TYPE_UINT64 Uint64; XML_TYPE_DYN_ARRAY shorts; }; typedef struct __Sample_Servie Sample_Servie; Sample_Servie servie = { 0, 1, "Caption", 30, "CreationClassName", "Description", 1, "DisplayName", "ErrorControl", 50, "InstallDate", "Name", "PathName", 60, 70, "ServiceType", 0, "StartMode", "StartName", "State", "Status", "SystemCreationClassName", "SystemName", 90, 100, 1000000, {6, myshorts } }; SER_START_ITEMS(Sample_Servie) SER_BOOL("AcceptPause", 1), SER_BOOL("AcceptStop", 1), SER_STR("Caption", 1), SER_UINT32("CheckPoint", 1), SER_STR("CreationClassName", 1), SER_STR("Description", 1), SER_BOOL("DesktopInteract", 1), SER_NS_STR(EX1_NS, "DisplayName", 1), SER_STR("ErrorControl", 1), SER_UINT32("ExitCode", 1), SER_STR("InstallDate", 1), SER_STR("Name", 1), SER_STR("PathName", 1), SER_UINT32("ProcessId", 1), SER_UINT32("ServiceSpecificExitCode", 1), SER_STR("ServiceType", 1), SER_BOOL("Started", 1), SER_STR("StartMode", 1), SER_STR("StartName", 1), SER_STR("State", 1), SER_STR("Status", 1), SER_STR("SystemCreationClassName", 1), SER_STR("SystemName", 1), SER_UINT32("TagId", 1), SER_UINT32("WaitHint", 1), SER_UINT64("Uint64", 1), SER_DYN_ARRAY("shorts", 0, 1000, uint16), SER_END_ITEMS(Sample_Servie); WsSerializerContextH cntx; WsXmlDocH doc; WsXmlNodeH node; int retval; printf("\n\n ******** example1. Basic types ********\n"); cntx = ws_serializer_init(); if (cntx == NULL) { printf("Error ws_create_runtime\n"); return; } doc = ws_xml_create_doc( NULL, "example"); node = ws_xml_get_doc_root(doc); retval = ws_serialize(cntx, node, &servie, Sample_Servie_TypeInfo, CLASSNAME, NULL, NULL, 0); printf("ws_serialize: %d\n", retval); ws_xml_dump_node_tree(stdout, node); node = ws_xml_get_doc_root(doc); //WsXmlDocH xx = ws_xml_read_file( ws_context_get_runtime(cntx), "./test.xml", "UTF-8", 0 ); //node = ws_xml_get_doc_root(xx); Sample_Servie *cs = (Sample_Servie *) ws_deserialize(cntx, node, Sample_Servie_TypeInfo, CLASSNAME, NULL, NULL, 0, 0); if (cs == NULL) { printf("Error in ws_serialize\n"); return; } retval = memcmp(cs, &servie, sizeof(servie)); if (retval) { printf("Not compared (%d) - FAILED\n", retval); printf("%d : %d\n", servie.AcceptPause, cs->AcceptPause); printf("%d : %d\n", servie.AcceptStop, cs->AcceptStop); printf("%s : %s\n", servie.Caption, cs->Caption); } }
static void example6(void) { typedef struct { struct { XML_TYPE_UINT8 body; XML_NODE_ATTR *attrs; } uint8_with_attrs; struct { XML_TYPE_UINT16 body; XML_NODE_ATTR *attrs; } uint16_with_attrs; struct { XML_TYPE_UINT32 body; XML_NODE_ATTR *attrs; } uint32_with_attrs; struct { XML_TYPE_BOOL body; XML_NODE_ATTR *attrs; } bool_with_attrs; struct { XML_TYPE_STR body; XML_NODE_ATTR *attrs; } str_with_attrs; } Dummy; typedef struct { struct { Dummy body; XML_NODE_ATTR *attrs; } struct_with_attrs; } Sample; XML_NODE_ATTR attrs[] = { {NULL, NULL, "Uint8AttrName1", "Uint8AttrValue1"}, {NULL, NULL, "Uint16AttrName1", "Uint16AttrValue1"}, {NULL, NULL, "Uint32AttrName1", "Uint32AttrValue1"}, {NULL, NULL, "BoolAttrName1", "BoolAttrValue1"}, {NULL, NULL, "StringAttrName1", "StringAttrValue1"}, }; XML_NODE_ATTR str_attrs[3] = { {NULL, NULL, "AttrName1", "AttrValue1"}, {NULL, NULL, "AttrName2", "AttrValue2"}, {NULL, XML_NS_ADDRESSING, "AttrQName", "AttrValue3"}, }; Sample sample = { { { {8, &attrs[0]}, {16, &attrs[1]}, {32, &attrs[2]}, {0, &attrs[3]}, {"string", &attrs[4]}, }, &str_attrs[0] } }; str_attrs[0].next = &str_attrs[1]; str_attrs[1].next = &str_attrs[2]; SER_START_ITEMS(Dummy) SER_ATTR_NS_UINT8_FLAGS(NULL, "UINT8", 1, 0), SER_ATTR_NS_UINT16_FLAGS(NULL, "UINT16", 1, 0), SER_ATTR_NS_UINT32_FLAGS(NULL, "UINT32", 1, 0), SER_ATTR_NS_BOOL_FLAGS(NULL, "BOOL", 1, 0), SER_ATTR_NS_STR_FLAGS(NULL, "STRING", 1, 0), SER_END_ITEMS(Dummy); SER_START_ITEMS(Sample) SER_ATTR_NS_STRUCT_FLAGS(XML_NS_WS_MAN, "STRUCT", 1, 0, Dummy), SER_END_ITEMS(Sample); WsSerializerContextH cntx; WsXmlDocH doc; WsXmlNodeH node; int retval; printf ("\n\n ******** example 6. Nodes with attributes ********\n"); cntx = ws_serializer_init(); if (cntx == NULL) { printf("Error ws_create_runtime\n"); return; } doc = ws_xml_create_doc( NULL, "example"); node = ws_xml_get_doc_root(doc); retval = ws_serialize(cntx, node, &sample, Sample_TypeInfo, CLASSNAME, XML_NS_WS_MAN, NULL, 0); printf("\n\nws_serialize: %d\n", retval); ws_xml_dump_node_tree(stdout, node); Sample *news; printf("\n\nws_deserialize:\n"); news = (Sample *) ws_deserialize(cntx, node, Sample_TypeInfo, CLASSNAME, XML_NS_ADDRESSING, NULL, 0, 0); if (news == NULL) { printf("Errror ws_deserialize\n"); return; } XML_NODE_ATTR *nattrs; Dummy *dm = &(news->struct_with_attrs.body); printf("**** Deserialized document %p *****\n", news); printf("struct_with_attrs.body ("); nattrs = news->struct_with_attrs.attrs; while (nattrs) { printf("%s:%s=\"%s\" ", nattrs->ns, nattrs->name, nattrs->value); nattrs = nattrs->next; } printf(")\n"); printf(" uint8_with_attrs = %d (", dm->uint8_with_attrs.body); nattrs = dm->uint8_with_attrs.attrs; while (nattrs) { printf("%s:%s=\"%s\" ", nattrs->ns, nattrs->name, nattrs->value); nattrs = nattrs->next; } printf(")\n"); printf(" uint16_with_attrs = %d (", dm->uint16_with_attrs.body); nattrs = dm->uint16_with_attrs.attrs; while (nattrs) { printf("%s:%s=\"%s\" ", nattrs->ns, nattrs->name, nattrs->value); nattrs = nattrs->next; } printf(")\n"); printf(" uint32_with_attrs = %d (", dm->uint32_with_attrs.body); nattrs = dm->uint32_with_attrs.attrs; while (nattrs) { printf("%s:%s=\"%s\" ", nattrs->ns, nattrs->name, nattrs->value); nattrs = nattrs->next; } printf(")\n"); printf(" bool_with_attrs = %d (", dm->bool_with_attrs.body); nattrs = dm->bool_with_attrs.attrs; while (nattrs) { printf("%s:%s=\"%s\" ", nattrs->ns, nattrs->name, nattrs->value); nattrs = nattrs->next; } printf(")\n"); printf(" str_with_attrs = %s (", dm->str_with_attrs.body); nattrs = dm->str_with_attrs.attrs; while (nattrs) { printf("%s:%s=\"%s\" ", nattrs->ns, nattrs->name, nattrs->value); nattrs = nattrs->next; } printf(")\n"); }