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 accept_events_call(WsmanMessage *wsman_msg,char* ip_addr) { char *buf = NULL; char *messageid; int len; WsXmlDocH ackdoc = NULL; WsXmlDocH in_doc = wsman_build_inbound_envelope(wsman_msg); WsXmlNodeH header = ws_xml_get_soap_header(in_doc); WsXmlNodeH acknode = ws_xml_get_child(header, 0, XML_NS_WS_MAN, WSM_ACKREQUESTED); if(acknode) { ackdoc = ws_xml_create_envelope(); messageid = ws_xml_get_node_text(ws_xml_get_child(header, 0, XML_NS_ADDRESSING, WSA_MESSAGE_ID)); header = ws_xml_get_soap_header(ackdoc); ws_xml_add_child(header, XML_NS_ADDRESSING, WSA_TO, WSA_TO_ANONYMOUS); ws_xml_add_child(header, XML_NS_ADDRESSING, WSA_RELATES_TO, messageid); ws_xml_add_child(header, XML_NS_ADDRESSING, WSA_ACTION, WSMAN_ACTION_ACK); ws_xml_dump_memory_enc(ackdoc, &buf, &len, wsman_msg->charset); u_buf_set(wsman_msg->response, buf, len); ws_xml_destroy_doc(ackdoc); u_free(buf); } if(listener->eventf) listener->eventf(in_doc, listener->data,ip_addr); ws_xml_destroy_doc(in_doc); }
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 CIM_Indication_call(cimxml_context *cntx, CimxmlMessage *message, void *opaqueData) { char *response = NULL; int len; WsXmlDocH indicationRequest = NULL; WsXmlDocH indicationResponse = NULL; SoapH soap = cntx->soap; char *uuid = cntx->uuid; WsContextH soapCntx = ws_get_soap_context(soap); debug("**********in CIM_Indication_call:: %s", u_buf_ptr(message->request)); indicationRequest = ws_xml_read_memory(u_buf_ptr(message->request), u_buf_len(message->request), message->charset, 0); if(indicationRequest == NULL) { debug("error, request cannot be parsed !"); message->http_code = WSMAN_STATUS_BAD_REQUEST; cimxml_set_fault(message, CIMXML_STATUS_REQUEST_NOT_VALID); goto DONE; } if(!isvalidCIMIndicationExport(indicationRequest)) { debug("error, invalid cim indication"); message->http_code = WSMAN_STATUS_FORBIDDEN; cimxml_set_fault(message, CIMXML_STATUS_UNSUPPORTED_OPERATION); goto DONE; } //to do here: put indication in event pool WsSubscribeInfo *subsInfo = NULL; list_t *subslist = soapCntx->subscriptionMemList; lnode_t *node = list_first(subslist); while(node) { subsInfo = (WsSubscribeInfo *)node->list_data; if(!strcmp(subsInfo->subsId, uuid)) break; node = list_next(subslist, node); } if(node == NULL) { message->http_code = WSMAN_STATUS_NOT_FOUND; cimxml_set_fault(message, CIMXML_STATUS_REQUEST_NOT_VALID); debug("error. uuid:%s not registered!", uuid); goto DONE; } EventPoolOpSetH opset = soap->eventpoolOpSet; create_indication_event(indicationRequest, subsInfo, opset); cimxml_build_response_msg(indicationRequest, &indicationResponse); ws_xml_dump_memory_enc(indicationResponse, &response, &len, "utf-8"); u_buf_construct(message->response, response, len, len); DONE: u_free(cntx); ws_xml_destroy_doc(indicationRequest); ws_xml_destroy_doc(indicationResponse); }
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 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); }
/** * 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; }
static void identify_test(void) { WsXmlDocH response; static int i = 0; char *xp = NULL; wsmc_reinit_conn(cl); options = wsmc_options_init(); response = wsmc_action_identify(cl, options); CU_ASSERT_TRUE(wsmc_get_response_code(cl) == tests[i].final_status); CU_ASSERT_PTR_NOT_NULL(response); if (response == NULL) { goto RETURN; } if (tests[i].value1 != NULL) { xp = ws_xml_get_xpath_value(response, tests[i].expr1); CU_ASSERT_PTR_NOT_NULL(xp); if (xp) { CU_ASSERT_STRING_EQUAL(xp, tests[i].value1 ); } } RETURN: if (response) { ws_xml_destroy_doc(response); } u_free(xp); wsmc_options_destroy(options); i++; }
int wsman_clean_subsrepository(SoapH soap, SubsRepositoryEntryH entry) { int retVal = 0; WsXmlDocH doc = ws_xml_read_memory( (char *)entry->strdoc, entry->len, "UTF-8", 0); unsigned long expire; WsmanFaultCodeType fault_code; if(doc) { WsXmlNodeH node = ws_xml_get_soap_body(doc); if(node) { node = ws_xml_get_child(node, 0, XML_NS_EVENTING, WSEVENT_SUBSCRIBE); node = ws_xml_get_child(node, 0, XML_NS_EVENTING, WSEVENT_EXPIRES); if(node == NULL) { //No specified expiration, delete it debug("subscription %s deleted from the repository", entry->uuid); soap->subscriptionOpSet->delete_subscription(soap->uri_subsRepository, entry->uuid+5); retVal = 1; } else { wsman_set_expiretime(node, &expire, &fault_code); if(fault_code == WSMAN_RC_OK) { if(time_expired(expire)) { debug("subscription %s deleted from the repository", entry->uuid); soap->subscriptionOpSet->delete_subscription(soap->uri_subsRepository, entry->uuid+5); retVal = 1; } } } } ws_xml_destroy_doc(doc); } return retVal; }
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 wsmc_node_to_buf(WsXmlNodeH node, char **buf) { int len; WsXmlDocH doc = ws_xml_create_doc_by_import( node); ws_xml_dump_memory_enc(doc, buf, &len, "UTF-8"); ws_xml_destroy_doc(doc); return; }
static void enumeration_test(void) { char *enumContext = NULL; static int i = 0; char *selectors = NULL; wsmc_reinit_conn(cl); options = wsmc_options_init(); options->flags = tests[i].flags; if (tests[i].selectors) { selectors = u_strdup_printf(tests[i].selectors, host, host, host); wsmc_add_selectors_from_str(options, selectors); } options->max_elements = tests[i].max_elements; WsXmlDocH enum_response = wsmc_action_enumerate(cl, (char *)tests[i].resource_uri, options, NULL); CU_ASSERT_TRUE(wsmc_get_response_code(cl) == tests[i].final_status); if (wsmc_get_response_code(cl) != tests[i].final_status) { if (verbose) { printf("\nExpected = %d\nReturned = %ld ", tests[i].final_status, wsmc_get_response_code(cl)); } goto RETURN; } CU_ASSERT_PTR_NOT_NULL(enum_response); if (enum_response) { enumContext = wsmc_get_enum_context(enum_response); } else { goto RETURN; } check_response_header(enum_response, wsmc_get_response_code(cl), ENUM_ACTION_ENUMERATERESPONSE); //if (i==11) ws_xml_dump_node_tree(stdout, ws_xml_get_doc_root(enum_response)); handle_filters(enum_response, filters); handle_filters(enum_response, tests[i].common_filters); handle_filters(enum_response, tests[i].filters); RETURN: u_free(selectors); if (enumContext) { wsmc_action_release(cl, (char *)tests[i].resource_uri, options, enumContext); } if (enum_response) { ws_xml_destroy_doc(enum_response); } wsmc_options_destroy(options); i++; // decrease executed test number }
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 test_epr_cmp(void) { WsXmlDocH doc1 = ws_xml_read_file("./epr1.xml", "utf-8", 0); WsXmlDocH doc2 = ws_xml_read_file("./epr2.xml", "utf-8", 0); WsXmlDocH doc3 = ws_xml_read_file("./epr3.xml", "utf-8", 0); if(doc1 == NULL || doc2 == NULL || doc3 == NULL) return; WsXmlNodeH node = ws_xml_get_soap_header(doc1); epr_t *epr1 = epr_deserialize(node, NULL, NULL, 0); if(epr1 == NULL) { printf("epr deserialize failed!\n"); return; } node = ws_xml_get_soap_header(doc2); epr_t *epr2 = epr_deserialize(node, NULL, NULL, 0); if(epr2 == NULL) { printf("epr deserialize failed!\n"); return; } node = ws_xml_get_soap_header(doc3); epr_t *epr3 = epr_deserialize(node, NULL, NULL, 0); if(epr3 == NULL) { printf("epr deserialize failed!\n"); return; } ws_xml_destroy_doc(doc1); ws_xml_destroy_doc(doc2); ws_xml_destroy_doc(doc3); if(epr_cmp(epr1, epr2) == 0) printf("\033[22;32mepr1 == epr2\033[m\n\n"); else printf("\033[22;32mepr1 != epr2\033[m\n\n"); if(epr_cmp(epr1, epr3) == 0) printf("\033[22;32mepr1 == epr3\033[m\n\n"); else printf("\033[22;32mepr1 != epr3\033[m\n\n"); epr_destroy(epr1); epr_destroy(epr2); epr_destroy(epr3); }
static void test_epr_delete_selector(void) { WsXmlDocH doc1 = ws_xml_read_file("./epr3.xml", "utf-8", 0); if(doc1 == NULL) return; WsXmlNodeH node = ws_xml_get_soap_header(doc1); epr_t *epr = epr_deserialize(node, NULL, NULL, 0); epr_delete_selector(epr, "Handler"); WsXmlDocH doc = ws_xml_create_envelope(); WsXmlNodeH header = ws_xml_get_soap_header(doc); epr_serialize(header,NULL,NULL,epr,0); ws_xml_dump_doc(stdout, doc); ws_xml_destroy_doc(doc1); ws_xml_destroy_doc(doc); epr_destroy(epr); printf("\033[22;32mdelete selector \"Handler\" from EPR\033[m\n\n"); }
static void test_deserialize(void) { WsXmlDocH doc = ws_xml_read_file("./sample.xml", "utf-8", 0); if(doc == NULL) return; WsXmlNodeH node = ws_xml_get_soap_header(doc); epr_t *epr = epr_deserialize(node, NULL, NULL, 0); if(epr == NULL) { printf("epr deserialize failed!\n"); return; } ws_xml_destroy_doc(doc); doc = ws_xml_create_envelope(); node = ws_xml_get_soap_header(doc); epr_serialize(node, NULL, NULL,epr, 0); ws_xml_dump_doc(stdout, doc); epr_destroy(epr); ws_xml_destroy_doc(doc); printf("\033[22;32mtest deserialize epr successfully!\033[m\n\n"); }
static void generate_op_fault(op_t * op, WsmanFaultCodeType faultCode, WsmanFaultDetailType faultDetail) { if (op->out_doc) { ws_xml_destroy_doc(op->out_doc); op->out_doc = NULL; } if (op->in_doc == NULL) { return; } op->out_doc = wsman_generate_fault(op->in_doc, faultCode, faultDetail, NULL); return; }
/** * Check Identify Request * @param buf Message buffer * @return 1 if true, 0 if not */ int wsman_check_identify(WsmanMessage * msg) { int ret = 0; WsXmlDocH doc = ws_xml_read_memory( u_buf_ptr(msg->request), u_buf_len(msg->request), msg->charset, 0); if (doc == NULL) { return 0; } if (wsman_is_identify_request(doc)) { ret = 1; } ws_xml_destroy_doc(doc); return ret; }
void wsman_generate_fault_buffer ( WsXmlDocH in_doc, const char *encoding, WsmanFaultCodeType faultCode, WsmanFaultDetailType faultDetail, char * fault_msg, char **buf, int* len) { WsXmlDocH doc = wsman_generate_fault( in_doc, faultCode, faultDetail, fault_msg); debug( "Fault Code: %d", faultCode); ws_xml_dump_memory_enc(doc, buf, len, encoding); ws_xml_destroy_doc(doc); return; }
/** * 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; }
int main(int argc, char** argv) { WsManClient *cl; WsXmlDocH doc; client_opt_t *options = NULL; printf ("Test 1: Testin Identify Request:"); cl = wsmc_create( sd[0].server, sd[0].port, sd[0].path, sd[0].scheme, sd[0].username, sd[0].password); wsmc_transport_init(cl, NULL); options = wsmc_options_init(); doc = wsmc_action_identify(cl, options); if (!doc) { printf("\t\t\033[22;31mUNRESOLVED\033[m\n"); goto CONTINUE; } char *xp = ws_xml_get_xpath_value(doc, "/s:Envelope/s:Body/wsmid:IdentifyResponse/wsmid:ProtocolVersion"); if (xp) { if (strcmp(xp,XML_NS_WS_MAN ) == 0) printf("\t\t\033[22;32mPASSED\033[m\n"); else printf("\t\t\033[22;31mFAILED\033[m\n"); u_free(xp); } else { printf("\t\t\033[22;31mFAILED\033[m\n"); } if (doc) { ws_xml_destroy_doc(doc); } CONTINUE: wsmc_options_destroy(options); wsmc_release(cl); return 0; }
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; }
static void test_serialize2(void) { epr_t *epr = epr_from_string("http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/CIM_IndicationFilter?Name=OperatingSystemFilter0&CreationClassName=CIM_IndicationFilter&SystemName=localhost.localdomain&SystemCreationClassName=CIM_ComputerSystem"); if(epr == NULL) { printf("test serialize from string failed!\n"); return; } epr_add_selector_text(epr, CIM_NAMESPACE_SELECTOR, "root/interop"); //test epr_add_selector_text WsXmlDocH doc = ws_xml_create_envelope(); WsXmlNodeH header = ws_xml_get_soap_header(doc); epr_serialize(header,NULL,NULL,epr,0); ws_xml_dump_doc(stdout, doc); ws_xml_destroy_doc(doc); epr_destroy(epr); printf("\033[22;32mtest create epr from string successfully!\033[m\n\n"); }
void dispatch_inbound_call(SoapH soap, WsmanMessage * msg, void *opaqueData) { op_t *op = NULL; WsXmlDocH in_doc = wsman_build_inbound_envelope( msg); SoapDispatchH dispatch = NULL; debug("Inbound call..."); if (wsman_fault_occured(msg)) { error("document is null"); goto DONE; } dispatch = get_dispatch_entry(soap, in_doc); if (dispatch == NULL) { wsman_set_fault(msg, WSA_DESTINATION_UNREACHABLE, WSMAN_DETAIL_INVALID_RESOURCEURI, NULL); debug("dispatch == NULL"); goto DONE; } op = create_op_entry(soap, dispatch, msg); if (op == NULL) { wsman_set_fault(msg, WSA_DESTINATION_UNREACHABLE, WSMAN_DETAIL_INVALID_RESOURCEURI, NULL); destroy_dispatch_entry(dispatch); debug("dispatch == NULL"); goto DONE; } op->in_doc = in_doc; process_inbound_operation(op, msg, opaqueData); DONE: dispatcher_create_fault(soap, msg, in_doc); destroy_op_entry(op); ws_xml_destroy_doc(in_doc); debug("Inbound call completed"); return; }
/* This function guarantees that query is freed, even on failure */ int hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char *root, XmlSerializerInfo *serializerInfo, const char *resourceUri, const char *className, hypervObject **list) { int result = -1; WsSerializerContextH serializerContext; client_opt_t *options = NULL; char *query_string = NULL; filter_t *filter = NULL; WsXmlDocH response = NULL; char *enumContext = NULL; hypervObject *head = NULL; hypervObject *tail = NULL; WsXmlNodeH node = NULL; XML_TYPE_PTR data = NULL; hypervObject *object; if (virBufferCheckError(query) < 0) { virBufferFreeAndReset(query); return -1; } query_string = virBufferContentAndReset(query); if (list == NULL || *list != NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument")); VIR_FREE(query_string); return -1; } serializerContext = wsmc_get_serialization_context(priv->client); options = wsmc_options_init(); if (options == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not initialize options")); goto cleanup; } filter = filter_create_simple(WSM_WQL_FILTER_DIALECT, query_string); if (filter == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not create filter")); goto cleanup; } response = wsmc_action_enumerate(priv->client, root, options, filter); if (hyperyVerifyResponse(priv->client, response, "enumeration") < 0) goto cleanup; enumContext = wsmc_get_enum_context(response); ws_xml_destroy_doc(response); response = NULL; while (enumContext != NULL && *enumContext != '\0') { response = wsmc_action_pull(priv->client, resourceUri, options, filter, enumContext); if (hyperyVerifyResponse(priv->client, response, "pull") < 0) goto cleanup; node = ws_xml_get_soap_body(response); if (node == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not lookup SOAP body")); goto cleanup; } node = ws_xml_get_child(node, 0, XML_NS_ENUMERATION, WSENUM_PULL_RESP); if (node == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not lookup pull response")); goto cleanup; } node = ws_xml_get_child(node, 0, XML_NS_ENUMERATION, WSENUM_ITEMS); if (node == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not lookup pull response items")); goto cleanup; } if (ws_xml_get_child(node, 0, resourceUri, className) == NULL) break; data = ws_deserialize(serializerContext, node, serializerInfo, className, resourceUri, NULL, 0, 0); if (data == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not deserialize pull response item")); goto cleanup; } if (VIR_ALLOC(object) < 0) goto cleanup; object->serializerInfo = serializerInfo; object->data = data; data = NULL; if (head == NULL) { head = object; } else { tail->next = object; } tail = object; VIR_FREE(enumContext); enumContext = wsmc_get_enum_context(response); ws_xml_destroy_doc(response); response = NULL; } *list = head; head = NULL; result = 0; cleanup: if (options != NULL) wsmc_options_destroy(options); if (filter != NULL) filter_destroy(filter); if (data != NULL) { #if WS_SERIALIZER_FREE_MEM_WORKS /* FIXME: ws_serializer_free_mem is broken in openwsman <= 2.2.6, * see hypervFreeObject for a detailed explanation. */ if (ws_serializer_free_mem(serializerContext, data, serializerInfo) < 0) { VIR_ERROR(_("Could not free deserialized data")); } #endif } VIR_FREE(query_string); ws_xml_destroy_doc(response); VIR_FREE(enumContext); hypervFreeObject(priv, head); return result; }
int Redirect_Enumerate_EP(WsContextH cntx, WsEnumerateInfo* enumInfo, WsmanStatus *status, void *opaqueData) { WsXmlNodeH r_header=NULL, r_node=NULL, r_body=NULL, r_opt=NULL; WsXmlDocH r_response=NULL; char *resource_uri, *remote_enumContext; int op; WsManClient *cl=NULL; //The redirected Enumeration request must have RequestTotalItemsCountEstimate enabled r_header = ws_xml_get_soap_header(cntx->indoc); if ( (r_node = ws_xml_get_child(r_header,0,XML_NS_WS_MAN, WSM_REQUEST_TOTAL )) == NULL ) ws_xml_add_child(r_header, XML_NS_WS_MAN, WSM_REQUEST_TOTAL, NULL); cl = setup_redirect_client(cntx, enumInfo->auth_data.username, enumInfo->auth_data.password); //Set the enumInfo flags based on the indoc. This is required while handling the response in wsenum_eunmerate_stub r_body=ws_xml_get_soap_body(cntx->indoc); if ( ( r_node = ws_xml_get_child(r_body ,0, XML_NS_ENUMERATION, WSENUM_ENUMERATE )) != NULL ) { if ( (r_opt = ws_xml_get_child(r_node,0,XML_NS_WS_MAN,WSM_OPTIMIZE_ENUM )) != NULL ) enumInfo->flags |= WSMAN_ENUMINFO_OPT ; } wsman_send_request(cl,cntx->indoc); if (wsmc_get_last_error(cl) != WS_LASTERR_OK ){ //CURL or HTTP errors enumInfo->pullResultPtr = NULL; status->fault_code = WSMAN_INTERNAL_ERROR; status->fault_detail_code = 0; status->fault_msg = redirect_fault_msg( wsman_transport_get_last_error_string( wsmc_get_last_error(cl) ) ); return 1; } r_response = ws_xml_duplicate_doc(wsmc_build_envelope_from_response(cl)); if ( wsman_is_fault_envelope(r_response)){ enumInfo->pullResultPtr = NULL; wsman_get_fault_status_from_doc(r_response, status); return 1; } //Get the Estimated Total No.of Items from the response. r_header=ws_xml_get_soap_header(r_response); r_node=ws_xml_get_child(r_header,0,XML_NS_WS_MAN, WSM_TOTAL_ESTIMATE ); enumInfo->totalItems=(!r_node) ? 0: atoi(ws_xml_get_node_text(r_node)); //Get the remote context remote_enumContext = wsmc_get_enum_context(r_response); //Set the pullResultPtr only if some Enum Items are returned, in optimized mode. r_body= ws_xml_get_soap_body(r_response); if ( (r_node = ws_xml_get_child(r_body,0,XML_NS_ENUMERATION, WSENUM_ENUMERATE_RESP )) != NULL && ( ws_xml_get_child(r_node,0,XML_NS_WS_MAN,WSENUM_ITEMS) != NULL) ) { enumInfo->pullResultPtr = r_response; if( strlen(remote_enumContext) != 0 ) strncpy(enumInfo->enumId, remote_enumContext, strlen(remote_enumContext)+1); else // If all the instances are returned, the context will be NULL enumInfo->enumId[0]='\0'; } else{ //If not items are returned, set the context and return. strncpy(enumInfo->enumId, remote_enumContext, strlen(remote_enumContext)+1); ws_xml_destroy_doc(r_response); } wsmc_release(cl); return 0; }
static void test_serialize1(void) { hash_t *selectors_filter = hash_create(HASHCOUNT_T_MAX, 0, 0); selector_entry *entry1 = NULL; entry1 = u_malloc(sizeof(selector_entry)*4); entry1[0].type = 0; entry1[0].entry.text = "OperatingSystemFilter0"; entry1[1].type = 0; entry1[1].entry.text = "localhost.localdomain"; entry1[2].type = 0; entry1[2].entry.text = "CIM_IndicationFilter"; entry1[3].type = 0; entry1[3].entry.text = "CIM_ComputerSystem"; hash_alloc_insert(selectors_filter, "Name", &entry1[0]); hash_alloc_insert(selectors_filter, "SystemName", &entry1[1]); hash_alloc_insert(selectors_filter, "CreationClassName", &entry1[2]); hash_alloc_insert(selectors_filter, "SystemCreationClassName", &entry1[3]); epr_t *epr_filter = epr_create("http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/CIM_IndicationFilter", selectors_filter, NULL); if(epr_filter == NULL) { printf("epr_create filter failed!\n"); return; } hash_t *selectors_handler = hash_create(HASHCOUNT_T_MAX, 0, 0); selector_entry *entry2 = u_malloc(sizeof(selector_entry)*4); entry2[0].type = 0; entry2[0].entry.text = "OperatingSystemHandler0"; entry2[1].type = 0; entry2[1].entry.text = "localhost.localdomain"; entry2[2].type = 0; entry2[2].entry.text = "CIM_IndicationHandlerCIMXML"; entry2[3].type = 0; entry2[3].entry.text = "CIM_ComputerSystem"; hash_alloc_insert(selectors_handler, "Name", &entry2[0]); hash_alloc_insert(selectors_handler, "SystemName", &entry2[1]); hash_alloc_insert(selectors_handler, "CreationClassName", &entry2[2]); hash_alloc_insert(selectors_handler, "SystemCreationClassName", &entry2[3]); epr_t *epr_handler = epr_create("http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/CIM_IndicationHandlerCIMXML", selectors_handler, NULL); if(epr_handler == NULL) { printf("epr_create handler failed!\n"); return; } hash_t *selectors_subscription = hash_create(HASHCOUNT_T_MAX, 0, 0); selector_entry *entry3 = NULL; entry3 = u_malloc(sizeof(selector_entry)*2); entry3[0].type = 1; entry3[0].entry.eprp = epr_filter; entry3[1].type = 1; entry3[1].entry.eprp = epr_handler; hash_alloc_insert(selectors_subscription, "Filter", &entry3[1]); hash_alloc_insert(selectors_subscription, "Handler", &entry3[1]); epr_t *epr_subscription = epr_create("http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/CIM_IndicationSubscription", selectors_subscription, NULL); if(epr_subscription == NULL) { printf("epr_create subscription failed!\n"); return; } epr_t *epr_cpy = epr_copy(epr_subscription); //test epr_copy WsXmlDocH doc = ws_xml_create_envelope(); WsXmlNodeH header = ws_xml_get_soap_header(doc); epr_serialize(header,NULL,NULL,epr_cpy,0); ws_xml_dump_doc(stdout, doc); epr_destroy(epr_filter); epr_destroy(epr_handler); epr_destroy(epr_subscription); epr_destroy(epr_cpy); hash_free(selectors_filter); hash_free(selectors_handler); hash_free(selectors_subscription); u_free(entry1); u_free(entry2); u_free(entry3); ws_xml_destroy_doc(doc); printf("\033[22;32mtest serialize epr successfully!\033[m\n\n"); }
int main(int argc, char** argv) { int i; WsManClient *cl; WsXmlDocH docp; client_opt_t *options = NULL; char *enumContext = NULL; //unsigned int id = 0; //wsman_debug_set_level(DEBUG_LEVEL_DEBUG); initialize_logging(); //wsmc_add_handler(wsmc_handler, NULL); for (i = 0; i < ntests; i++) { printf ("Test %d: %s:", i + 1, tests[i].explanation); //printf ("------------------------------------------------\n"); cl = wsmc_create( sd[0].server, sd[0].port, sd[0].path, sd[0].scheme, sd[0].username, sd[0].password); wsmc_transport_init(cl, NULL); options = wsmc_options_init(); options->flags = tests[i].flags; options->max_elements = tests[i].max_elements; if (tests[i].selectors != NULL) wsmc_add_selectors_from_str (options, tests[i].selectors); WsXmlDocH enum_response = wsmc_action_enumerate(cl, (char *)tests[i].resource_uri , options, NULL); if (!enum_response) { printf("\t\t\033[22;31mUNRESOLVED\033[m\n"); goto CONTINUE; } //wsman_output(enum_response); if ((char *)tests[i].expected_value != NULL) { char *xp = ws_xml_get_xpath_value(enum_response, (char *)tests[i].xpath_expression); if (xp) { if (strcmp(xp,(char *)tests[i].expected_value ) == 0) printf("\t\t\033[22;32mPASSED\033[m\n"); else printf("\t\t\033[22;31mFAILED\033[m\n"); u_free(xp); } } wsmc_free_enum_context(enumContext); enumContext = wsmc_get_enum_context(enum_response); ws_xml_destroy_doc(enum_response); while (enumContext != NULL) { docp = wsmc_action_pull(cl, (char *)tests[i].resource_uri, options, NULL, enumContext); if (!docp) { printf("\t\t\033[22;31mUNRESOLVED\033[m\n"); goto CONTINUE; } wsman_output(docp); wsmc_free_enum_context(enumContext); enumContext = wsmc_get_enum_context(docp); ws_xml_destroy_doc(docp); } CONTINUE: wsmc_options_destroy(options); wsmc_release(cl); } return 0; }
int main(int argc, char** argv) { int i; int choice = 0; WsManClient *cl; WsXmlDocH doc; client_opt_t *options = NULL; WsXmlDocH resource = NULL; if (getenv("OPENWSMAN_TEST_HOST")) { host = getenv("OPENWSMAN_TEST_HOST"); } resource = wsmc_read_file("./requests/create.xml", "UTF-8", 0); if(argc > 1) choice = atoi(argv[1]); for (i = 0; i < ntests; i++) { if(choice && i != choice -1) continue; if (tests[i].selectors) { tests[i].selectors = u_strdup_printf(tests[i].selectors, host, host, host); } if (tests[i].expected_value) { tests[i].expected_value = u_strdup_printf(tests[i].expected_value, host, host, host); } printf ("Test %3d: %s ", i + 1, tests[i].explanation); cl = wsmc_create( sd[0].server, sd[0].port, sd[0].path, sd[0].scheme, sd[0].username, sd[0].password); wsmc_transport_init(cl, NULL); options = wsmc_options_init(); if (tests[i].selectors != NULL) wsmc_add_selectors_from_str (options, tests[i].selectors); wsmc_set_action_option(options, FLAG_DUMP_REQUEST); doc = wsmc_action_create(cl, (char *)tests[i].resource_uri, options, resource); if (!doc) { printf("\t\t\033[22;31mUNRESOLVED\033[m\n"); goto CONTINUE; } wsman_output(doc); if (tests[i].final_status != wsmc_get_response_code(cl)) { printf("Status = %ld \t\t\033[22;31mFAILED\033[m\n", wsmc_get_response_code(cl)); goto CONTINUE; } if ((char *)tests[i].expected_value != NULL) { char *xp = ws_xml_get_xpath_value(doc, (char *)tests[i].xpath_expression); if (xp) { if (strcmp(xp,(char *)tests[i].expected_value ) == 0) printf("\t\t\033[22;32mPASSED\033[m\n"); else printf("%s = %s\t\033[22;31mFAILED\033[m\n",(char *)tests[i].xpath_expression, xp); u_free(xp); } else { printf(" No %s\t\033[22;31mFAILED\033[m\n", (char *)tests[i].xpath_expression); ws_xml_dump_node_tree(stdout, ws_xml_get_doc_root(doc)); } } else { printf("\t\t\033[22;32mPASSED\033[m\n"); } ws_xml_destroy_doc(doc); CONTINUE: u_free(tests[i].selectors); u_free(tests[i].expected_value); wsmc_options_destroy(options); wsmc_release(cl); } return 0; }