static void hypervFreePrivate(hypervPrivate **priv) { if (priv == NULL || *priv == NULL) return; if ((*priv)->client != NULL) { /* FIXME: This leaks memory due to bugs in openwsman <= 2.2.6 */ wsmc_release((*priv)->client); } hypervFreeParsedUri(&(*priv)->parsedUri); VIR_FREE(*priv); }
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; }
int Redirect_Pull_EP(WsContextH cntx, WsEnumerateInfo* enumInfo, WsmanStatus *status, void *opaqueData) { WsXmlDocH doc=NULL,response=NULL; WsManClient *cl=NULL; int retVal=0; cl = setup_redirect_client( cntx, enumInfo->auth_data.username, enumInfo->auth_data.password); 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; } response = ws_xml_duplicate_doc(wsmc_build_envelope_from_response(cl)); if ( ! wsman_is_fault_envelope(response) ) enumInfo->pullResultPtr = response; else{ //If there a fault, return the status code. enumInfo->pullResultPtr = NULL; wsman_get_fault_status_from_doc (response, status); retVal=1; } wsmc_release(cl); return retVal; }
int Redirect_transfer_action ( SoapOpH op, void* appData, void *opaqueData) { //Same function to be called for Get, Put, Create, Delete Actions WsmanMessage *msg = wsman_get_msg_from_op(op); SoapH soap = soap_get_op_soap(op); WsXmlDocH in_doc = soap_get_op_doc(op, 1); WsContextH cntx = ws_create_ep_context(soap, in_doc); WsManClient *cl=NULL; WsXmlDocH response=NULL; debug ("Test Get Endpoint Called"); cl = setup_redirect_client(cntx, msg->auth_data.username, msg->auth_data.password ); wsman_send_request(cl,cntx->indoc); if (wsmc_get_last_error(cl) != WS_LASTERR_OK ){ //CURL/ HTTP errors soap_set_op_doc(op, redirect_generate_fault( cntx->indoc , cl), 0); return 1; } response = wsmc_build_envelope_from_response(cl); soap_set_op_doc(op, ws_xml_duplicate_doc(response), 0); 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; }
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 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; }