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); }
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; }
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_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; }
void wsmc_handler( WsManClient *cl, WsXmlDocH rqstDoc, void* user_data) { #define curl_err(str) debug("Error = %d (%s); %s", \ r, curl_easy_strerror(r), str); WsManConnection *con = cl->connection; CURL *curl = NULL; CURLcode r; char *upwd = NULL; char *usag = NULL; struct curl_slist *headers=NULL; char *buf = NULL; int len; char *soapact_header = NULL; long http_code; long auth_avail = 0; char *_user = NULL, *_pass = NULL; u_buf_t *response = NULL; //char *soapaction; char *tmp_str = NULL; if (!cl->initialized && wsmc_transport_init(cl, NULL)) { cl->last_error = WS_LASTERR_FAILED_INIT; return; } if (cl->transport == NULL) { cl->transport = init_curl_transport(cl); if (cl->transport == NULL) { return; } } curl = (CURL *)cl->transport; r = curl_easy_setopt(curl, CURLOPT_URL, cl->data.endpoint); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("Could not curl_easy_setopt(curl, CURLOPT_URL, ...)"); goto DONE; } r = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_handler); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("Could not curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ..)"); goto DONE; } u_buf_create(&response); r = curl_easy_setopt(curl, CURLOPT_WRITEDATA, response); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("Could not curl_easy_setopt(curl, CURLOPT_WRITEDATA, ..)"); goto DONE; } char content_type[64]; snprintf(content_type, 64, "Content-Type: application/soap+xml;charset=%s", cl->content_encoding); headers = curl_slist_append(headers, content_type); tmp_str = wsman_transport_get_agent(cl); usag = malloc(12 + strlen(tmp_str) + 1); if (usag == NULL) { r = CURLE_OUT_OF_MEMORY; cl->fault_string = u_strdup("Could not malloc memory"); curl_err("Could not malloc memory"); goto DONE; } sprintf(usag, "User-Agent: %s", tmp_str); free(tmp_str); headers = curl_slist_append(headers, usag); #if 0 soapaction = ws_xml_get_xpath_value(rqstDoc, "/s:Envelope/s:Header/wsa:Action"); if (soapaction) { soapact_header = malloc(12 + strlen(soapaction) + 1); if (soapact_header) { sprintf(soapact_header, "SOAPAction: %s", soapaction); headers = curl_slist_append(headers, soapact_header); } u_free(soapaction); } #endif r = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("Could not curl_easy_setopt(curl, CURLOPT_HTTPHEADER, ..)"); goto DONE; } ws_xml_dump_memory_enc(rqstDoc, &buf, &len, cl->content_encoding); #if 0 int count = 0; while(count < len) { printf("%c",buf[count++]); } #endif debug("*****set post buf len = %d******",len); r = curl_easy_setopt(curl, CURLOPT_POSTFIELDS, buf); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("Could not curl_easy_setopt(curl, CURLOPT_POSTFIELDS, ..)"); goto DONE; } r = curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, len); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("Could not curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, ..)"); goto DONE; } int iDone = 0; while (1) { u_free(_user); u_free(_pass); _user = wsmc_get_user(cl); _pass = wsmc_get_password(cl); if (_user && _pass && cl->data.auth_set) { r = curl_easy_setopt(curl, CURLOPT_HTTPAUTH, cl->data.auth_set); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("curl_easy_setopt(CURLOPT_HTTPAUTH) failed"); goto DONE; } u_free(upwd); upwd = u_strdup_printf( "%s:%s", _user , _pass); if (!upwd) { r = CURLE_OUT_OF_MEMORY; cl->fault_string = u_strdup("Could not malloc memory"); curl_err("Could not malloc memory"); goto DONE; } r = curl_easy_setopt(curl, CURLOPT_USERPWD, upwd); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("curl_easy_setopt(curl, CURLOPT_USERPWD, ..) failed"); goto DONE; } } if (wsman_debug_level_debugged(DEBUG_LEVEL_MESSAGE)) { curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); } r = curl_easy_perform(curl); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("curl_easy_perform failed"); goto DONE; } r = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("curl_easy_getinfo(CURLINFO_RESPONSE_CODE) failed"); goto DONE; } switch (http_code) { case 200: case 400: case 500: // The resource was successfully retrieved or WSMan server // returned a HTTP status code. You can use WinHttpReadData to // read the contents of the server's response. iDone = 1; break; case 401: // The server requires authentication. break; default: // The status code does not indicate success. r = WS_LASTERR_OTHER_ERROR; iDone = 1; break; } if(iDone == 1) { break; } /* we are here because of authentication required */ r = curl_easy_getinfo(curl, CURLINFO_HTTPAUTH_AVAIL, &auth_avail); if (r != CURLE_OK) { cl->fault_string = u_strdup(curl_easy_strerror(r)); curl_err("curl_easy_getinfo(CURLINFO_HTTPAUTH_AVAIL) failed"); goto DONE; } cl->data.auth_set = reauthenticate(cl, cl->data.auth_set, auth_avail, &cl->data.user, &cl->data.pwd); u_buf_clear(response); if (cl->data.auth_set == 0) { /* FIXME: user wants to cancel authentication */ #if LIBCURL_VERSION_NUM >= 0x70D01 r = CURLE_LOGIN_DENIED; #else /* Map the login failure error to CURLE_LOGIN_DENIED (67) so that we * get the same error code in case of login failure */ r = 67; #endif curl_err("user/password wrong or empty."); break; } } #if 0 unsigned char *mbbuf = NULL; iconv_t cd; if(strcmp(cl->content_encoding, "UTF-8")) { cd = iconv_open("UTF-8", cl->content_encoding); if(cd == -1) { cl->last_error = WS_LASTERR_BAD_CONTENT_ENCODING; goto DONE2; } mbbuf = u_zalloc(u_buf_len(response)); size_t outbuf_len = u_buf_len(response); size_t inbuf_len = outbuf_len; char *inbuf = u_buf_ptr(response); char *outbuf = mbbuf; size_t coverted = iconv(cd, &inbuf, &inbuf_len, &outbuf, &outbuf_len); iconv_close(cd); if( coverted == -1) { cl->last_error = WS_LASTERR_BAD_CONTENT_ENCODING; goto DONE2; } u_buf_append(con->response, mbbuf, u_buf_len(response) - inbuf_len); } u_free(mbbuf); #endif u_buf_append(con->response, u_buf_ptr(response), u_buf_len(response)); DONE: curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); cl->response_code = http_code; cl->last_error = convert_to_last_error(r); debug("curl error code: %d.", r); debug("cl->response_code: %d.", cl->response_code); debug("cl->last_error code: %d.", cl->last_error); curl_slist_free_all(headers); u_buf_free(response); u_free(soapact_header); u_free(usag); u_free(upwd); u_free(_pass); u_free(_user); #ifdef _WIN32 ws_xml_free_memory(buf); #else u_free(buf); #endif return; #undef curl_err }
static int process_inbound_operation(op_t * op, WsmanMessage * msg, void *opaqueData) { int retVal = 1; char *buf = NULL; int len; msg->http_code = WSMAN_STATUS_OK; op->out_doc = NULL; if (op->dispatch->serviceCallback == NULL) { wsman_set_fault(msg, WSA_ACTION_NOT_SUPPORTED, OWSMAN_NO_DETAILS, NULL); debug("op service callback is null"); goto GENERATE_FAULT; } if (process_filters(op, 1, opaqueData)) { if (op->out_doc == NULL) { error("doc is null"); wsman_set_fault(msg, WSMAN_INTERNAL_ERROR, OWSMAN_NO_DETAILS, NULL); goto GENERATE_FAULT; } if (wsman_is_fault_envelope(op->out_doc)) { msg->http_code = wsman_find_httpcode_for_value(op->out_doc); } else { error("not fault envelope"); } ws_xml_dump_memory_enc(op->out_doc, &buf, &len, msg->charset); u_buf_set(msg->response, buf, len); ws_xml_destroy_doc(op->out_doc); op->out_doc = NULL; u_free(buf); return 1; } retVal = op->dispatch->serviceCallback((SoapOpH) op, op->dispatch->serviceData, opaqueData); if (op->out_doc == NULL) { // XXX (correct fault?) wsman_set_fault(msg, WSA_DESTINATION_UNREACHABLE, WSMAN_DETAIL_INVALID_RESOURCEURI, NULL); error("output doc is null"); goto GENERATE_FAULT; } process_filters(op, 0, opaqueData); if (op->out_doc == NULL) { error("doc is null"); wsman_set_fault(msg, WSMAN_INTERNAL_ERROR, OWSMAN_NO_DETAILS, NULL); goto GENERATE_FAULT; } if (wsman_is_fault_envelope(op->out_doc)) { msg->http_code = wsman_find_httpcode_for_value(op->out_doc); } else { wsman_add_fragement_for_header(op->in_doc, op->out_doc); } ws_xml_dump_memory_enc(op->out_doc, &buf, &len, msg->charset); u_buf_set(msg->response, buf, len); ws_xml_destroy_doc(op->out_doc); op->out_doc = NULL; u_free(buf); return 0; GENERATE_FAULT: return retVal; }