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 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); }
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 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); }
/** * Buid Inbound Envelope * @param buf Message buffer * @return XML document with Envelope */ WsXmlDocH wsman_build_inbound_envelope(WsmanMessage * msg) { WsXmlDocH doc = ws_xml_read_memory( u_buf_ptr(msg->request), u_buf_len(msg->request), msg->charset, 0); if (doc == NULL) { wsman_set_fault(msg, WSA_INVALID_MESSAGE_INFORMATION_HEADER, 0, NULL); return NULL; } if (wsman_is_identify_request(doc)) { wsman_set_message_flags(msg, FLAG_IDENTIFY_REQUEST); } wsman_is_valid_envelope(msg, doc); return doc; }
/** * 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 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); }
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 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_set_subscribe_options(WsManClient * cl, WsXmlDocH request, const char* resource_uri, client_opt_t *options, filter_t *filter) { WsXmlNodeH body = ws_xml_get_soap_body(request); WsXmlNodeH header = ws_xml_get_soap_header(request); WsXmlNodeH node = NULL, temp = NULL, node2 = NULL, node3 = NULL; char buf[32]; if(options->delivery_certificatethumbprint ||options->delivery_password || options->delivery_password) { node = ws_xml_add_child(header, XML_NS_TRUST, WST_ISSUEDTOKENS, NULL); ws_xml_add_node_attr(node, XML_NS_SOAP_1_2, SOAP_MUST_UNDERSTAND, "true"); if(options->delivery_certificatethumbprint) { node2 = ws_xml_add_child(node, XML_NS_TRUST, WST_REQUESTSECURITYTOKENRESPONSE, NULL); ws_xml_add_child(node2, XML_NS_TRUST, WST_TOKENTYPE,WST_CERTIFICATETHUMBPRINT ); node3 = ws_xml_add_child(node2, XML_NS_TRUST, WST_REQUESTEDSECURITYTOKEN, NULL); ws_xml_add_child(node3, XML_NS_WS_MAN, WSM_CERTIFICATETHUMBPRINT, options->delivery_certificatethumbprint); node3 = ws_xml_add_child(node2, XML_NS_POLICY, WSP_APPLIESTO, NULL); node3 = ws_xml_add_child(node3, XML_NS_ADDRESSING, WSA_EPR, NULL); ws_xml_add_child(node3, XML_NS_ADDRESSING, WSA_ADDRESS, options->delivery_uri); } if(options->delivery_username || options->delivery_password) { node2 = ws_xml_add_child(node, XML_NS_TRUST, WST_REQUESTSECURITYTOKENRESPONSE, NULL); ws_xml_add_child(node2, XML_NS_TRUST, WST_TOKENTYPE,WST_USERNAMETOKEN); node3 = ws_xml_add_child(node2, XML_NS_TRUST, WST_REQUESTEDSECURITYTOKEN, NULL); node3 = ws_xml_add_child(node3, XML_NS_SE, WSSE_USERNAMETOKEN, NULL); if(options->delivery_username) ws_xml_add_child(node3, XML_NS_SE, WSSE_USERNAME, options->delivery_username); if(options->delivery_password) ws_xml_add_child(node3, XML_NS_SE, WSSE_PASSWORD, options->delivery_password); node3 = ws_xml_add_child(node2, XML_NS_POLICY, WSP_APPLIESTO, NULL); node3 = ws_xml_add_child(node3, XML_NS_ADDRESSING, WSA_EPR, NULL); ws_xml_add_child(node3, XML_NS_ADDRESSING, WSA_ADDRESS, options->delivery_uri); } } node = ws_xml_add_child(body, XML_NS_EVENTING, WSEVENT_SUBSCRIBE,NULL); temp = ws_xml_add_child(node, XML_NS_EVENTING, WSEVENT_DELIVERY, NULL); if(temp) { ws_xml_add_node_attr(temp, NULL, WSEVENT_DELIVERY_MODE, wsmc_create_delivery_mode_str(options->delivery_mode)); if(options->delivery_uri) { node2 = ws_xml_add_child(temp, XML_NS_EVENTING, WSEVENT_NOTIFY_TO, NULL); ws_xml_add_child(node2, XML_NS_ADDRESSING, WSA_ADDRESS, options->delivery_uri); } if(options->delivery_sec_mode) { temp = ws_xml_add_child(temp, XML_NS_WS_MAN, WSM_AUTH, NULL); ws_xml_add_node_attr(temp, NULL, WSM_PROFILE, wsmc_create_delivery_sec_mode_str(options->delivery_sec_mode)); } if(options->heartbeat_interval) { snprintf(buf, 32, "PT%fS", options->heartbeat_interval); ws_xml_add_child(temp, XML_NS_WS_MAN, WSM_HEARTBEATS, buf); } if(options->reference) { WsXmlDocH doc = ws_xml_read_memory( options->reference, strlen(options->reference), "UTF-8", 0); node3 = ws_xml_get_doc_root(doc); temp = ws_xml_add_child(node2, XML_NS_ADDRESSING, WSA_REFERENCE_PROPERTIES, NULL); if(temp) ws_xml_duplicate_tree(temp, node3); } } if (options->expires) { snprintf(buf, 32, "PT%fS", options->expires); ws_xml_add_child(node, XML_NS_EVENTING, WSEVENT_EXPIRES, buf); } if (filter) { filter_serialize(node, filter, XML_NS_WS_MAN); } if (options->flags & FLAG_EVENT_SENDBOOKMARK) { ws_xml_add_child(node, XML_NS_WS_MAN, WSM_SENDBOOKMARKS, NULL); } }
WsXmlDocH wsmc_read_memory( char *buf, size_t size, const char *encoding, unsigned long options) { return ws_xml_read_memory( buf, size, encoding, options); }
SoapDispatchH wsman_dispatcher(WsContextH cntx, void *data, WsXmlDocH doc) { SoapDispatchH disp = NULL; char *uri = NULL, *action; WsManDispatcherInfo *dispInfo = (WsManDispatcherInfo *) data; WsDispatchEndPointInfo *ep = NULL; WsDispatchEndPointInfo *ep_custom = NULL; WsXmlDocH notdoc = NULL; #ifdef ENABLE_EVENTING_SUPPORT WsXmlNodeH nodedoc = NULL; #endif int i; /*, resUriMatch = 0; */ char *ns = NULL; WsDispatchInterfaceInfo *r = NULL; lnode_t *node = list_first((list_t *) dispInfo->interfaces); if (doc == NULL) { error("doc is null"); u_free(data); goto cleanup; } uri = wsman_get_resource_uri(cntx, doc); action = wsman_get_action(cntx, doc); #ifdef ENABLE_EVENTING_SUPPORT if(wsman_is_event_related_request(doc)) { WsXmlNodeH temp = ws_xml_get_child( ws_xml_get_soap_header(doc), 0, XML_NS_EVENTING, WSEVENT_IDENTIFIER); char *uuid = ws_xml_get_node_text(temp); debug("Request uuid: %s", uuid ? uuid : "NULL"); if(uuid) { lnode_t *t = list_first(cntx->subscriptionMemList); while(t != NULL) { WsSubscribeInfo *subsInfo = (WsSubscribeInfo *)t->list_data; if(!strcmp(uuid+5, subsInfo->subsId)) { uri = subsInfo->uri; break; } else t = list_next(cntx->subscriptionMemList, t); } if(t == NULL) { unsigned char *buf = NULL; int len; if(cntx->soap->subscriptionOpSet->get_subscription(cntx->soap->uri_subsRepository, uuid+5, &buf, &len) == 0) { notdoc = ws_xml_read_memory( (char *)buf, len, "UTF-8", 0); if(notdoc) { nodedoc = ws_xml_get_soap_header(notdoc); if(nodedoc) { nodedoc = ws_xml_get_child(nodedoc, 0, XML_NS_WS_MAN, WSM_RESOURCE_URI); if(nodedoc) { uri = ws_xml_get_node_text(nodedoc); } } } u_free(buf); } } } } #endif debug("uri: %s, action: %s", uri ? uri : "NULL", action ? action : "NULL"); if ((!uri || !action) && !wsman_is_identify_request(doc)) { goto cleanup; } while (node != NULL) { WsDispatchInterfaceInfo *ifc = (WsDispatchInterfaceInfo *) node->list_data; if (wsman_is_identify_request(doc)) { if ((ns = wsman_dispatcher_match_ns(ifc, XML_NS_WSMAN_ID))) { r = ifc; /* resUriMatch = 1; */ break; } debug("ns did not match"); } /* * If Resource URI is null then most likely we are dealing * with a generic plugin supporting a namespace with * multiple Resource URIs (e.g. CIM) **/ else if (ifc->wsmanResourceUri == NULL && (ns = wsman_dispatcher_match_ns(ifc, uri))) { r = ifc; /* resUriMatch = 1; */ break; } else if (ifc->wsmanResourceUri && !strcmp(uri, ifc->wsmanResourceUri)) { r = ifc; /* resUriMatch = 1; */ break; } node = list_next((list_t *) dispInfo->interfaces, node); } if (wsman_is_identify_request(doc) && r != NULL) { ep = &r->endPoints[0]; } else if (r != NULL) { char *ptr = action; /* * See if the action is part of the namespace which means that * we are dealing with a custom action */ if (ns != NULL) { size_t len = strlen(ns); if (!strncmp(action, ns, len) && action[len] == '/') ptr = &action[len + 1]; } for (i = 0; r->endPoints[i].serviceEndPoint != NULL; i++) { if (r->endPoints[i].inAction != NULL && !strcmp(ptr, r->endPoints[i].inAction)) { ep = &r->endPoints[i]; break; } else if (r->endPoints[i].inAction == NULL) { /* * Just store it for later * in case no match is found for above condition */ ep_custom = &r->endPoints[i]; } } } ws_remove_context_val(cntx, WSM_RESOURCE_URI); if (ep != NULL) { for (i = 0; i < dispInfo->mapCount; i++) { if (dispInfo->map[i].ep == ep) { disp = dispInfo->map[i].disp; break; } } } else if (ep_custom != NULL) { for (i = 0; i < dispInfo->mapCount; i++) { if (dispInfo->map[i].ep == ep_custom) { disp = dispInfo->map[i].disp; break; } } } cleanup: if(notdoc) ws_xml_destroy_doc(notdoc); if (ns) u_free(ns); return disp; }