void close_xmlrpc() { assert(xmlrpc_initialized); /* Shutdown our XML-RPC client library. */ xmlrpc_client_cleanup(); }
void close_xmlrpc() { assert(xmlrpc_initialized); /* Clean up our error-handling environment. */ xmlrpc_env_clean(&env); /* Shutdown our XML-RPC client library. */ xmlrpc_client_cleanup(); }
int main(int const argc, const char ** const argv) { const char* const methodName = "sample.add"; xmlrpc_env env; xmlrpc_env_init(&env); //create a global client xmlrpc_client_init2(&env, XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION, NULL, 0); // create a multi_server_info struct multi_server_info_t multiServerInfo; multiServerInfo.numberOfServer = 3; // 3 servers, 8080, 8081, 8082 multiServerInfo.serverUrlArray = malloc(sizeof(char *) * multiServerInfo.numberOfServer); multiServerInfo.serverUrlArray[0] = "http://localhost:8080/RPC2"; multiServerInfo.serverUrlArray[1] = "http://localhost:8081/RPC2"; multiServerInfo.serverUrlArray[2] = "http://localhost:8082/RPC2"; // how many times we need to run our multirpc_globalclient_asynch() //int * requestsForMultiRpc = malloc(sizeof(int)); int requestsForMultiRpc = atoi(argv[1]); // in one single multi rpc call, how many requests we need to send // each server will get one request, so it is equal to number of server //int * requestsRequired = malloc(sizeof(int)); int requestsRequired = multiServerInfo.numberOfServer; int counter; for (counter = 0; counter < (requestsForMultiRpc); ++counter) { // requestsRequired shows how many threads need to be created in // the belowing function multirpc_globalclient_asynch(&multiServerInfo, methodName, handle_sample_add_response, requestsRequired); printf("Multi RPC has been done %d time. Waiting..\n", counter+1); // xmlrpc_client_event_loop_finish_asynch(); } // sleep(10); xmlrpc_env_clean(&env); xmlrpc_client_cleanup(); return 0; }
static void getRecentPosts( const char *host, const char *username, const char *password ) { xmlrpc_env env; xmlrpc_value * resultP = NULL; // array item xmlrpc_value * firstElementP = NULL; // first element in array xmlrpc_value * varP = NULL; const char * postResult = NULL; int arrsize; xmlrpc_client_init( XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION ); xmlrpc_env_init( &env ); resultP = xmlrpc_client_call( &env, host, "blogger.getRecentPosts", "(ssssi)", "", /* key, not used */ username, /* journal unique name */ username, /* journal username */ password, /* journal password */ RECENT_POST_COUNT ); /* post count */ die_if_fault_occurred( &env ); arrsize = xmlrpc_array_size( &env, resultP ); die_if_fault_occurred( &env ); //fprintf( stderr, "Array size %d\n", arrsize ); for (int i = 0; i < arrsize; i++ ) { xmlrpc_array_read_item( &env, resultP, i, &firstElementP); xmlrpc_struct_find_value( &env, firstElementP, "title", &varP); if (varP) { xmlrpc_read_string( &env, varP, &postResult); printf( "%d %s\n\n", i, postResult ); free((char *)postResult); xmlrpc_DECREF( varP ); } die_if_fault_occurred( &env ); xmlrpc_struct_find_value( &env, firstElementP, "content", &varP); if (varP) { xmlrpc_read_string( &env, varP, &postResult); printf( "%s\n\n", postResult ); free((char *)postResult); xmlrpc_DECREF( varP ); } die_if_fault_occurred( &env ); xmlrpc_DECREF( firstElementP ); } xmlrpc_DECREF( resultP ); xmlrpc_env_clean( &env ); xmlrpc_client_cleanup(); }
void LogEvent_clean() { #ifdef DEFINE_XMLRPC /* Dispose of our result value. */ xmlrpc_DECREF(_xmlrpc_result); /* Clean up our error-handling environment. */ xmlrpc_env_clean(&_xmlrpc_env); /* Shutdown our XML-RPC client library. */ xmlrpc_client_cleanup(); #endif /* DEFINE_XMLRPC */ }
int main(int const argc, const char ** const argv) { xmlrpc_env env; xmlrpc_server_info * serverP; xmlrpc_value * resultP; xmlrpc_int sum; if (argc-1 > 0) { fprintf(stderr, "There are no arguments. You specified %d", argc-1); exit(1); } /* Start up our XML-RPC client library. */ xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION); xmlrpc_env_init(&env); /* Make a new object to represent our XML-RPC server. */ serverP = xmlrpc_server_info_new(&env, SERVER_URL); die_if_fault_occurred(&env); /* Set up our authentication information. */ xmlrpc_server_info_set_basic_auth(&env, serverP, "jrandom", "secret"); die_if_fault_occurred(&env); resultP = xmlrpc_client_call_server( &env, serverP, "sample.add", "(ii)", (xmlrpc_int32) 5, (xmlrpc_int32) 7); die_if_fault_occurred(&env); /* Dispose of our server object. */ xmlrpc_server_info_free(serverP); /* Get the result of the RPC and print it out. */ xmlrpc_read_int(&env, resultP, &sum); die_if_fault_occurred(&env); printf("The sum is %d\n", sum); /* Dispose of our result value. */ xmlrpc_DECREF(resultP); /* Shut down our XML-RPC client library. */ xmlrpc_env_clean(&env); xmlrpc_client_cleanup(); return 0; }
int main(int const argc, const char ** const argv) { xmlrpc_env env; xmlrpc_value * resultP; xmlrpc_int32 sum; const char * const serverUrl = "http://localhost:8080/RPC2"; const char * const serverUrl2 = "http://localhost:8081/RPC2"; const char * const serverUrl3 = "http://localhost:8082/RPC2"; const char * const methodName = "sample.add"; if (argc-1 > 0) { fprintf(stderr, "This program has no arguments\n"); exit(1); } /* Initialize our error-handling environment. */ xmlrpc_env_init(&env); /* Start up our XML-RPC client library. */ xmlrpc_client_init2(&env, XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION, NULL, 0); dieIfFaultOccurred(&env); printf("Making XMLRPC call to server url '%s' method '%s' " "to request the sum " "of 5 and 7...\n", serverUrl, methodName); /* Make the remote procedure call */ resultP = xmlrpc_client_call(&env, methodName, "(sssii)", 1, 3, serverUrl, serverUrl2, serverUrl3, (xmlrpc_int32) 5, (xmlrpc_int32) 7); dieIfFaultOccurred(&env); /* Get our sum and print it out. */ xmlrpc_read_int(&env, resultP, &sum); dieIfFaultOccurred(&env); printf("The sum is %d\n", sum); /* Dispose of our result value. */ xmlrpc_DECREF(resultP); /* Clean up our error-handling environment. */ xmlrpc_env_clean(&env); /* Shutdown our XML-RPC client library. */ xmlrpc_client_cleanup(); return 0; }
int main (int argc, char** argv) { int i; xmlrpc_env env; xmlrpc_value *result; unsigned char* data; size_t* datasize; /* Start up our XML-RPC client library. */ xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION); xmlrpc_env_init(&env); printf("xmlrpc_client_call:\n"); /* Call our XML-RPC server. */ result = xmlrpc_client_call(&env, SERVER_URL, "poll.DCFTime", "(ii)", (xmlrpc_int32) 5, (xmlrpc_int32) 3); printf("done\n"); exit_on_fault(&env); /* Parse our result value. */ printf("xmlrpc_parse_value\n"); xmlrpc_parse_value(&env, result, "{s:6,*}", "data", &data, &datasize); printf("done\n"); exit_on_fault(&env); /* echo communication result */ printf("ndata: %d, datasize: %u\n", strlen(data), (int) datasize); for ( i = 0; i < (int) datasize ; i++ ) { printf("%x:", data[i]); } printf("\n"); /* Dispose of our result value. */ xmlrpc_DECREF(result); /* Shutdown our XML-RPC client library. */ xmlrpc_env_clean(&env); xmlrpc_client_cleanup(); return 0; }
static void doCall(xmlrpc_env * const envP, const char * const transport, const xmlrpc_server_info * const serverInfoP, xmlrpc_mem_block * const callXmlP, xmlrpc_mem_block ** const respXmlPP) { struct xmlrpc_clientparms clientparms; clientparms.transport = transport; clientparms.transportparmsP = NULL; clientparms.transportparm_size = 0; xmlrpc_client_init2(envP, XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION, &clientparms, XMLRPC_CPSIZE(transportparm_size)); if (!envP->fault_occurred) { xmlrpc_client_transport_call(envP, NULL, serverInfoP, callXmlP, respXmlPP); xmlrpc_client_cleanup(); } }
ArchiveDataClient::~ArchiveDataClient() { xmlrpc_env_clean(&env); xmlrpc_client_cleanup(); }
int main( int argc, char *argv[] ) { xmlrpc_env env; xmlrpc_value * resultP; xmlrpc_value * keyP; xmlrpc_value * valueP; int struct_size; int i, j; size_t length; const char * str_key_value; xmlrpc_int int_key_value; unsigned int max_hits = 0; unsigned int rows = 0; int rv; char *uri; int options; /* what kind of nodes should be processed */ int uri_pos; /* position of first non option argument */ char stropts[16]; int pos = 0; int mask_length = 32; /* 32 means NO aggregate */ if (argc-1 < 1) { print_help(); exit(0); } uri_pos = process_options(argc, argv, &options, &mask_length); switch (options) { case OPT_HOT: sprintf(stropts, "HOT"); break; case OPT_ALL: sprintf(stropts, "ALL"); break; case OPT_WARM: sprintf(stropts, "WARM"); break; } printf("Nodes = %s\n", stropts); printf("Mask = /%d\n", mask_length); /* Start up our XML-RPC client library. */ xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION); /* Initialize our error-handling environment. */ xmlrpc_env_init(&env); /* prototype: xmlrpc_value * xmlrpc_client_call(xmlrpc_env * const envP, const char * const server_url, const char * const method_name, const char * const format, ...); */ asprintf(&uri, "http://%s/RPC2", argv[uri_pos]); resultP = xmlrpc_client_call(&env, uri, "pike.top", "(s)", stropts); free(uri); die_if_fault_occurred_line(&env, __LINE__); /* parse returned structure */ if ( xmlrpc_value_type(resultP) != XMLRPC_TYPE_STRUCT ) { printf("unexpected result - should be structure\n"); xmlrpc_env_clean(&env); xmlrpc_client_cleanup(); exit(1); } struct_size = xmlrpc_struct_size(&env, resultP); die_if_fault_occurred_line(&env, __LINE__); // printf("Struct size: %d\n", struct_size); if ( ! get_int_from_struct_by_name(resultP, MAX_HITS, &max_hits) ) { fprintf(stderr, "ERROR: %s not foung in result\n", MAX_HITS); exit (1); } printf("max_hits = %d\n", max_hits); if ( ! get_int_from_struct_by_name(resultP, NUMBER_OF_ROWS, &rows) ) { fprintf(stderr, "ERROR: %s not foung in result\n", NUMBER_OF_ROWS); exit (1); } printf("rows = %d\n", rows); TopItem top_items[rows]; TopItem *item; /* tmp item ptr */ TopItem *result_items = top_items; /* if no aggregation use this */ memset(top_items, 0, sizeof(top_items)); /* aggregated values */ if ( rows == 0 ) return 0; for ( i = 0, item = top_items; i < rows; ++i, ++item ) { if ( ! read_row(resultP, i, item) ) { fprintf(stderr, "ERROR: while reading row number %d\n", i); } /* fill in ipv4 addr */ // printf("item[%d].ip_addr = %s, len = %d\n", i, item->ip_addr, strlen(item->ip_addr)); rv = inet_pton(AF_INET, item->ip_addr, &item->ipv4_addr); if ( rv > 0 ) { // printf("IPv4 addr: %x\n", item->ipv4_addr); } else { fprintf(stderr, "IP conversion failed - not an IPv4 address: '%s'\n", item->ip_addr); /* conversion failed from any reason */ printf("item[%d].ipv4_addr = %x\n", i, item->ipv4_addr); } } assert( rows > 0 ); /* if IP mask length is shorter than 32 then aggregate list according to the mask */ if ( mask_length < 32 ) { uint32_t ip_mask = htonl(mask(mask_length)); qsort(top_items, rows, sizeof(TopItem), compare_TopItem_ipv4_addr); /* sort by IPv4 */ /* skip items without ipv4 address */ i = 0; /* index of non aggregated items */ while (!top_items[i].ipv4_addr && i < rows ) { printf("Skip item[%d] - do not has IPv4 address: %s\n", i, top_items[i].ip_addr); memset(&top_items[i], 0, sizeof(TopItem)); ++i; } j = 0; /* index of aggregated items */ if ( i == 0 ) ++i; top_items[0].ipv4_addr &= ip_mask; top_items[0].num_of_ips = 1; inet_ntop(AF_INET, &top_items[0].ipv4_addr, top_items[0].ip_addr, sizeof(top_items[0].ip_addr)); while ( i < rows ) { top_items[i].ipv4_addr &= ip_mask; if ( top_items[j].ipv4_addr == top_items[i].ipv4_addr ) { top_items[j].leaf_hits[0] += top_items[i].leaf_hits[0]; top_items[j].leaf_hits[1] += top_items[i].leaf_hits[1]; ++(top_items[j].num_of_ips); ++i; } else { ++j; top_items[j] = top_items[i]; top_items[j].num_of_ips = 1; inet_ntop(AF_INET, &top_items[j].ipv4_addr, top_items[j].ip_addr, sizeof(top_items[j].ip_addr)); ++i; } } rows = j + 1; } qsort(top_items, rows, sizeof(TopItem), compare_TopItem_hits_reverse); print_rows( top_items, rows, mask_length ); /* Dispose of our result value. */ xmlrpc_DECREF(resultP); /* Clean up our error-handling environment. */ xmlrpc_env_clean(&env); /* Shutdown our XML-RPC client library. */ xmlrpc_client_cleanup(); return 0; }
int main(int const argc, const char ** const argv) { if(argc < 2 ) { fprintf(stderr,"Usage : ./client <Semantics> <No of Servers>\n"); exit(EXIT_FAILURE); } const char const **serverUrl; int i = 0, port = 8080 ; xmlrpc_env env; xmlrpc_value * resultP; int nUrl = atoi(argv[2]); struct timeval start,end,diff; if(nUrl == 0) { fprintf(stderr,"Please enter non-zero number of servers\n"); exit(EXIT_FAILURE); } #if 0 serverUrl = (char **) malloc (nUrl * sizeof(char*)); for(i = 0 ; i < nUrl ; i++){ serverUrl[i] = (char *) malloc(50 * sizeof(char)); sprintf(serverUrl[i],"http://localhost:%d/RPC2",port++); } #endif #if 1 serverUrl = malloc(sizeof(char*) * 5); serverUrl[0] = "http://localhost:8080/RPC2"; serverUrl[1] = "http://localhost:8081/RPC2"; serverUrl[2] = "http://localhost:8082/RPC2"; serverUrl[3] = "http://localhost:8083/RPC2"; serverUrl[4] = "http://localhost:8084/RPC2"; #endif const char * const methodName = "calculate_modexp"; //const char * const serverUrl = "http://localhost:8080/RPC2"; /* Initialize our error-handling environment. */ xmlrpc_env_init(&env); /* Start up our XML-RPC client library. */ xmlrpc_client_init2(&env, XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION, NULL, 0); dieIfFaultOccurred(&env); // printf("Making XMLRPC call to server url '%s' method '%s' " "to request the sum " "of 5 and 7...\n", serverUrl, methodName); /* Make the remote procedure call */ // printf("Result is : %d\n",xmlrpc_validate_utf8("Hello World")); xmlrpc_value *arr = xmlrpc_array_new(&env); //resultP = xmlrpc_client_call(&env, serverUrl, methodName,"(A)", generate_request_array(&env , arr) ); gettimeofday(&start,NULL); /*Call the server*/ resultP = xmlrpc_client_call_multi_sync(atoi(argv[1]),nUrl, &env, serverUrl, methodName,"(A)", generate_request_array(&env , arr)); gettimeofday(&end,NULL); difference(&diff,end,start); printf("Time Taken With %d Server = %ld:%ld\n",nUrl,diff.tv_usec/1000000,diff.tv_usec%1000000); // printf("Check to see if killed\n"); dieIfFaultOccurred(&env); /* Get our sum and print it out. */ //xmlrpc_read_int(&env, resultP, &primeResult); // xmlrpc_env * const dummy; // printf("Extracting Results\n"); const char* result = extract_result ( &env , resultP); dieIfFaultOccurred(&env); // printf("2^p/m = %s\n", result); /*Dispose of our result value. */ xmlrpc_DECREF(resultP); /* Clean up our error-handling environment. */ xmlrpc_env_clean(&env); /* Shutdown our XML-RPC client library. */ xmlrpc_client_cleanup(); return 0; }
int main( int argc, char *argv[] ) { xmlrpc_env env; xmlrpc_value * resultP = NULL; const char * postResult = NULL; char username[USERLEN]; char password[PASSLEN]; char entry[ENTRY_MAX]; char host[HOSTLEN]; char * title = NULL; size_t titlelen; int c; size_t i; bool debug = false; bool hflag = false; bool uflag = false; bool pflag = false; bool rflag = false; if ( argc < 3 ) usage( argv[0] ); while ((c = getopt( argc, argv, "h:u:p:s:dr" )) != -1) { switch( c ) { case 'h': /* host */ if ( strlen(optarg) > HOSTLEN - 16) { fprintf( stderr, "host name is too long" ); exit(EXIT_FAILURE); } (void) snprintf(host, HOSTLEN, "http://%s/xml-rpc", optarg); hflag = true; break; case 'u': /* username */ strncpy( username, optarg, USERLEN - 1 ); username[USERLEN -1] = '\0'; uflag = true; break; case 'p': /* password */ strncpy( password, optarg, PASSLEN - 1 ); password[PASSLEN -1] = '\0'; pflag = true; break; case 's': /* subject */ titlelen = strlen(optarg); if ( (title = malloc((titlelen * sizeof(char)) + 1)) == NULL ) { fprintf( stderr, "Unable to allocate memory." ); exit(EXIT_FAILURE); } strncpy( title, optarg, titlelen ); title[titlelen] = '\0'; break; case 'r': /* recent entries */ rflag = true; break; case 'd': /* debug */ debug = true; fprintf( stderr, "Debug enabled.\n"); break; case '?': /* fall through */ default: usage( argv[0] ); } } argc -= optind; if ( !uflag || !pflag ) { fprintf( stderr, "Username and password are required.\n" ); usage( argv[0] ); } /* set host if it's not defined */ if ( !hflag ) (void) snprintf(host, HOSTLEN, "http://%s/xml-rpc", HOST); if ( debug && hflag ) fprintf( stderr, "host is set to: %s\n", host ); if ( rflag ) { getRecentPosts( host, username, password ); exit(0); } /* Copy the title into the top of entry if it's requested */ entry[0] = '\0'; if ( title != NULL ) (void) snprintf( entry, ENTRY_MAX, "<title>%s</title>", title ); /* Start from title or the beginning and copy the entry from stdin */ for ( i = strlen(entry); i < ENTRY_MAX -1; i++ ) { c = getchar(); if ( c == EOF ) break; entry[i] = (char) c; } entry[i] = '\0'; if ( i == 0 ) { fprintf( stderr, "No entry specified." ); exit(EXIT_FAILURE); } xmlrpc_client_init( XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION ); xmlrpc_env_init( &env ); resultP = xmlrpc_client_call( &env, host, "blogger.newPost", "(sssssb)", "", /* key, not used */ username, /* journal unique name */ username, /* journal username */ password, /* journal password */ entry, /* blog content */ true ); /* post now */ die_if_fault_occurred( &env ); xmlrpc_read_string( &env, resultP, &postResult ); if ( debug && postResult != NULL ) fprintf( stderr, "Debug: post result is: %s\n", postResult ); die_if_fault_occurred( &env ); free((char *)postResult); xmlrpc_DECREF( resultP ); xmlrpc_env_clean( &env ); xmlrpc_client_cleanup(); return 0; }
static int join_krb5(const char *ipaserver, char *hostname, char **hostdn, const char **princ, const char **subject, int force, int quiet) { xmlrpc_env env; xmlrpc_value * argArrayP = NULL; xmlrpc_value * paramArrayP = NULL; xmlrpc_value * paramP = NULL; xmlrpc_value * optionsP = NULL; xmlrpc_value * resultP = NULL; xmlrpc_value * structP = NULL; xmlrpc_server_info * serverInfoP = NULL; struct utsname uinfo; xmlrpc_value *princP = NULL; xmlrpc_value *krblastpwdchangeP = NULL; xmlrpc_value *subjectP = NULL; xmlrpc_value *hostdnP = NULL; const char *krblastpwdchange = NULL; char * url = NULL; char * user_agent = NULL; int rval = 0; int ret; *hostdn = NULL; *subject = NULL; *princ = NULL; /* Start up our XML-RPC client library. */ xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION); uname(&uinfo); xmlrpc_env_init(&env); xmlrpc_client_setup_global_const(&env); #if 1 ret = asprintf(&url, "https://%s:443/ipa/xml", ipaserver); #else ret = asprintf(&url, "http://%s:8888/", ipaserver); #endif if (ret == -1) { if (!quiet) fprintf(stderr, _("Out of memory!\n")); rval = 3; goto cleanup; } serverInfoP = xmlrpc_server_info_new(&env, url); argArrayP = xmlrpc_array_new(&env); paramArrayP = xmlrpc_array_new(&env); if (hostname == NULL) paramP = xmlrpc_string_new(&env, uinfo.nodename); else paramP = xmlrpc_string_new(&env, hostname); xmlrpc_array_append_item(&env, argArrayP, paramP); #ifdef REALM if (!quiet) printf("Joining %s to IPA realm %s\n", uinfo.nodename, iparealm); #endif xmlrpc_array_append_item(&env, paramArrayP, argArrayP); xmlrpc_DECREF(paramP); optionsP = xmlrpc_build_value(&env, "{s:s,s:s}", "nsosversion", uinfo.release, "nshardwareplatform", uinfo.machine); xmlrpc_array_append_item(&env, paramArrayP, optionsP); xmlrpc_DECREF(optionsP); if ((user_agent = set_user_agent(ipaserver)) == NULL) { rval = 3; goto cleanup; } callRPC(user_agent, &env, serverInfoP, "join", paramArrayP, &resultP); if (handle_fault(&env)) { rval = 17; goto cleanup_xmlrpc; } /* Return value is the form of an array. The first value is the * DN, the second a struct of attribute values */ xmlrpc_array_read_item(&env, resultP, 0, &hostdnP); xmlrpc_read_string(&env, hostdnP, (const char **)hostdn); xmlrpc_DECREF(hostdnP); xmlrpc_array_read_item(&env, resultP, 1, &structP); xmlrpc_struct_find_value(&env, structP, "krbprincipalname", &princP); if (princP) { xmlrpc_value * singleprincP = NULL; /* FIXME: all values are returned as lists currently. Once this is * fixed we can read the string directly. */ xmlrpc_array_read_item(&env, princP, 0, &singleprincP); xmlrpc_read_string(&env, singleprincP, &*princ); xmlrpc_DECREF(princP); xmlrpc_DECREF(singleprincP); } else { if (!quiet) fprintf(stderr, _("principal not found in XML-RPC response\n")); rval = 12; goto cleanup; } xmlrpc_struct_find_value(&env, structP, "krblastpwdchange", &krblastpwdchangeP); if (krblastpwdchangeP && !force) { xmlrpc_value * singleprincP = NULL; /* FIXME: all values are returned as lists currently. Once this is * fixed we can read the string directly. */ xmlrpc_array_read_item(&env, krblastpwdchangeP, 0, &singleprincP); xmlrpc_read_string(&env, singleprincP, &krblastpwdchange); xmlrpc_DECREF(krblastpwdchangeP); if (!quiet) fprintf(stderr, _("Host is already joined.\n")); rval = 13; goto cleanup; } xmlrpc_struct_find_value(&env, structP, "ipacertificatesubjectbase", &subjectP); if (subjectP) { xmlrpc_value * singleprincP = NULL; /* FIXME: all values are returned as lists currently. Once this is * fixed we can read the string directly. */ xmlrpc_array_read_item(&env, subjectP, 0, &singleprincP); xmlrpc_read_string(&env, singleprincP, *&subject); xmlrpc_DECREF(subjectP); } cleanup: if (argArrayP) xmlrpc_DECREF(argArrayP); if (paramArrayP) xmlrpc_DECREF(paramArrayP); if (resultP) xmlrpc_DECREF(resultP); cleanup_xmlrpc: free(user_agent); free(url); free((char *)krblastpwdchange); xmlrpc_env_clean(&env); xmlrpc_client_cleanup(); return rval; }
void c_oneFree() { xmlrpc_env_clean(&one_client.env); xmlrpc_client_cleanup(); }
inline void XmlRpcClient::Terminate (void) { xmlrpc_client_cleanup(); }
node_t * xmlrpc_client_callmethod(const char * serverUrl, const char * methodName, unsigned int argVersion){ xmlrpc_env env; xmlrpc_env_init(&env); xmlrpc_client_init2(&env, XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION, NULL, 0); dieIfFailed("Client initialization", &env); xmlrpc_value * ID, * PORT, * DATA, * DATAP, * IP; ID = xmlrpc_int_new(&env, 23121); IP = xmlrpc_string_new(&env, "127.0.0.1"); PORT = xmlrpc_int_new(&env, 8085); DATA = xmlrpc_int_new(&env, 123); DATAP = xmlrpc_struct_new(&env); xmlrpc_struct_set_value(&env, DATAP, "ID", ID); xmlrpc_struct_set_value(&env, DATAP, "IP", IP); xmlrpc_struct_set_value(&env, DATAP, "PORT", PORT); xmlrpc_struct_set_value(&env, DATAP, "DATA", DATA); xmlrpc_DECREF(ID); xmlrpc_DECREF(IP); xmlrpc_DECREF(PORT); xmlrpc_DECREF(DATA); /* Make the call */ xmlrpc_value * resultArray = xmlrpc_client_call(&env, serverUrl, methodName, "(iS)", (xmlrpc_int32) argVersion, DATAP); xmlrpc_value * OutID_t, *OutPORT_t, *OutDATA_t, *OutIP_t; xmlrpc_int OutID, OutPORT, OutDATA; char * OutIP; unsigned int const resultCt = xmlrpc_array_size(&env, resultArray); unsigned int i; node_t * resultnode = (node_t *) malloc(3*sizeof(node_t)); for(i = 0; i < resultCt; ++i){ xmlrpc_value * resultP; xmlrpc_array_read_item(&env, resultArray, i, &resultP); xmlrpc_struct_find_value(&env, resultP, "ID", &OutID_t); xmlrpc_struct_find_value(&env, resultP, "IP", &OutIP_t); xmlrpc_struct_find_value(&env, resultP, "PORT", &OutPORT_t); xmlrpc_struct_find_value(&env, resultP, "DATA", &OutDATA_t); xmlrpc_read_int(&env, OutID_t, &OutID); xmlrpc_read_string(&env, OutIP_t, &OutIP); xmlrpc_read_int(&env, OutPORT_t, &OutPORT); xmlrpc_read_int(&env, OutDATA_t, &OutDATA); resultnode[i].ID = OutID; strcpy(resultnode[i].IP, OutIP); resultnode[i].PORT = OutPORT; resultnode[i].DATA = OutDATA; } xmlrpc_env_clean(&env); xmlrpc_client_cleanup(); return resultnode; }
static void testInitCleanup(void) { xmlrpc_env env; struct xmlrpc_clientparms clientParms1; struct xmlrpc_curl_xportparms curlTransportParms1; xmlrpc_env_init(&env); xmlrpc_client_init2(&env, 0, "testprog", "1.0", NULL, 0); TEST_NO_FAULT(&env); xmlrpc_client_cleanup(); xmlrpc_client_init2(&env, 0, "testprog", "1.0", &clientParms1, 0); TEST_NO_FAULT(&env); xmlrpc_client_cleanup(); clientParms1.transport = "curl"; xmlrpc_client_init2(&env, 0, "testprog", "1.0", &clientParms1, XMLRPC_CPSIZE(transport)); TEST_NO_FAULT(&env); xmlrpc_client_cleanup(); clientParms1.transportparmsP = NULL; xmlrpc_client_init2(&env, 0, "testprog", "1.0", &clientParms1, XMLRPC_CPSIZE(transportparmsP)); TEST_NO_FAULT(&env); xmlrpc_client_cleanup(); clientParms1.transportparmsP = &curlTransportParms1; /* Fails because we didn't include transportparm_size: */ xmlrpc_client_init2(&env, 0, "testprog", "1.0", &clientParms1, XMLRPC_CPSIZE(transportparmsP)); TEST_FAULT(&env, XMLRPC_INTERNAL_ERROR); clientParms1.transportparm_size = 0; xmlrpc_client_init2(&env, 0, "testprog", "1.0", &clientParms1, XMLRPC_CPSIZE(transportparm_size)); TEST_NO_FAULT(&env); xmlrpc_client_cleanup(); curlTransportParms1.network_interface = "eth0"; clientParms1.transportparm_size = XMLRPC_CXPSIZE(network_interface); xmlrpc_client_init2(&env, 0, "testprog", "1.0", &clientParms1, XMLRPC_CPSIZE(transportparm_size)); TEST_NO_FAULT(&env); xmlrpc_client_cleanup(); curlTransportParms1.no_ssl_verifypeer = 1; curlTransportParms1.no_ssl_verifyhost = 1; clientParms1.transportparm_size = XMLRPC_CXPSIZE(no_ssl_verifyhost); xmlrpc_client_init2(&env, 0, "testprog", "1.0", &clientParms1, XMLRPC_CPSIZE(transportparm_size)); TEST_NO_FAULT(&env); xmlrpc_client_cleanup(); curlTransportParms1.user_agent = "testprog/1.0"; clientParms1.transportparm_size = XMLRPC_CXPSIZE(user_agent); xmlrpc_client_init2(&env, 0, "testprog", "1.0", &clientParms1, XMLRPC_CPSIZE(transportparm_size)); TEST_NO_FAULT(&env); xmlrpc_client_cleanup(); xmlrpc_client_init(0, "testprog", "1.0"); TEST_NO_FAULT(&env); xmlrpc_client_cleanup(); xmlrpc_env_clean(&env); }
int main(int const argc, const char ** const argv) { xmlrpc_env env; xmlrpc_value * resultP; xmlrpc_int32 number_of_links; const char * const serverUrl = "http://localhost:4567/RPC2"; const char * const methodName = "get_number_of_links"; if (argc-1 > 0) { fprintf(stderr, "This program has no arguments\n"); exit(1); } /* Initialize our error-handling environment. */ xmlrpc_env_init(&env); /* Start up our XML-RPC client library. */ xmlrpc_client_init2(&env, XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION, NULL, 0); dieIfFaultOccurred(&env); printf("Making XMLRPC call to server url '%s' method '%s'\n", serverUrl, "get_number_of_links"); /* Make the remote procedure call */ resultP = xmlrpc_client_call(&env, serverUrl, "get_number_of_links", "(i)", (xmlrpc_int32) 1); dieIfFaultOccurred(&env); /* Get our sum and print it out. */ xmlrpc_read_int(&env, resultP, &number_of_links); dieIfFaultOccurred(&env); printf("Number of links defined: %d\n", number_of_links); /* Dispose of our result value. */ xmlrpc_DECREF(resultP); /* Make the remote procedure call */ resultP = xmlrpc_client_call(&env, serverUrl, "get_links", "(i)", (xmlrpc_int32) 1); dieIfFaultOccurred(&env); int array_size =xmlrpc_array_size(&env, resultP); while(array_size>0) { --array_size; xmlrpc_value *value; const char *link; xmlrpc_array_read_item(&env, resultP, 0, &value); xmlrpc_read_string(&env, value, &link); printf("Link %u: %s\n", array_size, link); xmlrpc_DECREF(value); } xmlrpc_DECREF(resultP); /* Make the remote procedure call */ resultP = xmlrpc_client_call(&env, serverUrl, "add_target", "(i)", (xmlrpc_int32) 1); xmlrpc_int64 targetID = 0; xmlrpc_read_i8(&env, resultP, &targetID); if(targetID) { printf("New target added with ID: %"PRIx64"\n", targetID); } else { printf("Failed to add new target!\n"); goto done; } xmlrpc_DECREF(resultP); /* Make the remote procedure call */ resultP = xmlrpc_client_call(&env, serverUrl, "remove_target", "(i)", (xmlrpc_int64) targetID); xmlrpc_int32 res; xmlrpc_read_int(&env, resultP, &res); printf("Target %"PRIx64" remove: %"PRIx32"\n", targetID, res); done: xmlrpc_DECREF(resultP); /* Clean up our error-handling environment. */ xmlrpc_env_clean(&env); /* Shutdown our XML-RPC client library. */ xmlrpc_client_cleanup(); return 0; }
static int unenroll_host(const char *server, const char *hostname, const char *ktname, int quiet) { int rval = 0; int ret; char *ipaserver = NULL; char *host = NULL; struct utsname uinfo; char *principal = NULL; char *realm = NULL; krb5_context krbctx = NULL; krb5_keytab keytab = NULL; krb5_ccache ccache = NULL; krb5_principal princ = NULL; krb5_error_code krberr; krb5_creds creds; krb5_get_init_creds_opt gicopts; char tgs[LINE_MAX]; xmlrpc_env env; xmlrpc_value * argArrayP = NULL; xmlrpc_value * paramArrayP = NULL; xmlrpc_value * paramP = NULL; xmlrpc_value * resultP = NULL; xmlrpc_server_info * serverInfoP = NULL; xmlrpc_value *princP = NULL; char * url = NULL; char * user_agent = NULL; if (server) { ipaserver = strdup(server); } else { char * conf_data = read_config_file(IPA_CONFIG); if ((ipaserver = getIPAserver(conf_data)) == NULL) { if (!quiet) fprintf(stderr, _("Unable to determine IPA server from %s\n"), IPA_CONFIG); exit(1); } free(conf_data); } if (NULL == hostname) { uname(&uinfo); host = strdup(uinfo.nodename); } else { host = strdup(hostname); } if (NULL == strstr(host, ".")) { if (!quiet) fprintf(stderr, _("The hostname must be fully-qualified: %s\n"), host); rval = 16; goto cleanup; } krberr = krb5_init_context(&krbctx); if (krberr) { if (!quiet) fprintf(stderr, _("Unable to join host: " "Kerberos context initialization failed\n")); rval = 1; goto cleanup; } krberr = krb5_kt_resolve(krbctx, ktname, &keytab); if (krberr != 0) { if (!quiet) fprintf(stderr, _("Error resolving keytab: %s.\n"), error_message(krberr)); rval = 7; goto cleanup; } krberr = krb5_get_default_realm(krbctx, &realm); if (krberr != 0) { if (!quiet) fprintf(stderr, _("Error getting default Kerberos realm: %s.\n"), error_message(krberr)); rval = 21; goto cleanup; } ret = asprintf(&principal, "host/%s@%s", host, realm); if (ret == -1) { if (!quiet) fprintf(stderr, _("Out of memory!\n")); rval = 3; goto cleanup; } krberr = krb5_parse_name(krbctx, principal, &princ); if (krberr != 0) { if (!quiet) fprintf(stderr, _("Error parsing \"%1$s\": %2$s.\n"), principal, error_message(krberr)); return krberr; } strcpy(tgs, KRB5_TGS_NAME); snprintf(tgs + strlen(tgs), sizeof(tgs) - strlen(tgs), "/%.*s", (krb5_princ_realm(krbctx, princ))->length, (krb5_princ_realm(krbctx, princ))->data); snprintf(tgs + strlen(tgs), sizeof(tgs) - strlen(tgs), "@%.*s", (krb5_princ_realm(krbctx, princ))->length, (krb5_princ_realm(krbctx, princ))->data); memset(&creds, 0, sizeof(creds)); krb5_get_init_creds_opt_init(&gicopts); krb5_get_init_creds_opt_set_forwardable(&gicopts, 1); krberr = krb5_get_init_creds_keytab(krbctx, &creds, princ, keytab, 0, tgs, &gicopts); if (krberr != 0) { if (!quiet) fprintf(stderr, _("Error obtaining initial credentials: %s.\n"), error_message(krberr)); return krberr; } krberr = krb5_cc_resolve(krbctx, "MEMORY:ipa-join", &ccache); if (krberr == 0) { krberr = krb5_cc_initialize(krbctx, ccache, creds.client); } else { if (!quiet) fprintf(stderr, _("Unable to generate Kerberos Credential Cache\n")); rval = 19; goto cleanup; } krberr = krb5_cc_store_cred(krbctx, ccache, &creds); if (krberr != 0) { if (!quiet) fprintf(stderr, _("Error storing creds in credential cache: %s.\n"), error_message(krberr)); return krberr; } krb5_cc_close(krbctx, ccache); ccache = NULL; putenv("KRB5CCNAME=MEMORY:ipa-join"); /* Start up our XML-RPC client library. */ xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION); xmlrpc_env_init(&env); xmlrpc_client_setup_global_const(&env); #if 1 ret = asprintf(&url, "https://%s:443/ipa/xml", ipaserver); #else ret = asprintf(&url, "http://%s:8888/", ipaserver); #endif if (ret == -1) { if (!quiet) fprintf(stderr, _("Out of memory!\n")); rval = 3; goto cleanup; } serverInfoP = xmlrpc_server_info_new(&env, url); argArrayP = xmlrpc_array_new(&env); paramArrayP = xmlrpc_array_new(&env); paramP = xmlrpc_string_new(&env, host); xmlrpc_array_append_item(&env, argArrayP, paramP); xmlrpc_array_append_item(&env, paramArrayP, argArrayP); xmlrpc_DECREF(paramP); if ((user_agent = set_user_agent(ipaserver)) == NULL) { rval = 3; goto cleanup; } callRPC(user_agent, &env, serverInfoP, "host_disable", paramArrayP, &resultP); if (handle_fault(&env)) { rval = 17; goto cleanup; } xmlrpc_struct_find_value(&env, resultP, "result", &princP); if (princP) { xmlrpc_bool result; xmlrpc_read_bool(&env, princP, &result); if (result == 1) { if (!quiet) fprintf(stderr, _("Unenrollment successful.\n")); } else { if (!quiet) fprintf(stderr, _("Unenrollment failed.\n")); } xmlrpc_DECREF(princP); } else { fprintf(stderr, _("result not found in XML-RPC response\n")); rval = 20; goto cleanup; } cleanup: free(user_agent); if (keytab) krb5_kt_close(krbctx, keytab); free((char *)principal); free((char *)ipaserver); if (princ) krb5_free_principal(krbctx, princ); if (ccache) krb5_cc_close(krbctx, ccache); if (krbctx) krb5_free_context(krbctx); free(url); xmlrpc_env_clean(&env); xmlrpc_client_cleanup(); return rval; }