void stop_flows(char* address) { xmlrpc_env env; xmlrpc_client *client = 0; xmlrpc_value * resultP = 0; char* p; int port = DEFAULT_LISTEN_PORT; char host[1000], url[1000]; if (strlen(address) > sizeof(url) - 50) { fprintf(stderr, "Address too long: %s\n", address); return; } /* Construct canonical address and URL */ strncpy(host, address, 1000); p = strchr(host, ':'); if (p) { if (p == host) { fprintf(stderr, "Error, no address given: %s\n", address); return; } port = atoi(p + 1); if (port < 1 || port > 65535) { fprintf(stderr, "Error, invalid port given: %s\n", address); return; } *p = 0; } sprintf(url, "http://%s:%d/RPC2", host, port); sprintf(host, "%s:%d", host, port); printf("Stopping all flows on %s\n", host); /* Stop the flows */ xmlrpc_env_init(&env); xmlrpc_client_create(&env, XMLRPC_CLIENT_NO_FLAGS, "Flowgrind", FLOWGRIND_VERSION, NULL, 0, &client); if (env.fault_occurred) goto cleanup; xmlrpc_client_call2f(&env, client, url, "stop_flow", &resultP, "({s:i})", "flow_id", -1); /* -1 stops all flows */ if (resultP) xmlrpc_DECREF(resultP); cleanup: if (env.fault_occurred) { fprintf(stderr, "Could not stop flows on %s: %s (%d)\n", host, env.fault_string, env.fault_code); } if (client) xmlrpc_client_destroy(client); xmlrpc_env_clean(&env); }
static void stop_flows(const char* address) { xmlrpc_env env; xmlrpc_client *client = 0; xmlrpc_value * resultP = 0; int port = DEFAULT_LISTEN_PORT; bool is_ipv6 = false; char *arg, *url = 0; int rc; char *rpc_address = arg = strdup(address); struct sockaddr_in6 source_in6; source_in6.sin6_family = AF_INET6; parse_rpc_address(&rpc_address, &port, &is_ipv6); if (is_ipv6 && (inet_pton(AF_INET6, rpc_address, (char*)&source_in6.sin6_addr) <= 0)) errx("invalid IPv6 address '%s' for RPC", rpc_address); if (port < 1 || port > 65535) errx("invalid port for RPC"); if (is_ipv6) rc = asprintf(&url, "http://[%s]:%d/RPC2", rpc_address, port); else rc = asprintf(&url, "http://%s:%d/RPC2", rpc_address, port); if (rc==-1) critx("failed to build RPC URL"); printf("Stopping all flows on %s\n", url); /* Stop the flows */ xmlrpc_env_init(&env); xmlrpc_client_create(&env, XMLRPC_CLIENT_NO_FLAGS, "Flowgrind", FLOWGRIND_VERSION, NULL, 0, &client); if (env.fault_occurred) goto cleanup; xmlrpc_client_call2f(&env, client, url, "stop_flow", &resultP, "({s:i})", "flow_id", -1); /* -1 stops all flows */ if (resultP) xmlrpc_DECREF(resultP); cleanup: if (env.fault_occurred) { warnx("could not stop flows on %s: %s (%d)", url, env.fault_string, env.fault_code); } if (client) xmlrpc_client_destroy(client); xmlrpc_env_clean(&env); free_all(arg, url); }
void bugzilla_logout(BugzillaData *data) { E_ASSERT(data != NULL); xmlrpc_value *result; xmlrpc_client_call2f(&data->xenv, data->xcli, data->url.c_str(), "User.logout", &result, "()"); if(data->xenv.fault_occurred) { E_WARNING(E_STRLOC ": Unable to call xmlrpc function (%s)\n", data->xenv.fault_string); if(data->cb) (data->cb)(data->xenv.fault_string, data->cb_data); return; } xmlrpc_DECREF(result); }
char *bugzilla_get_version(BugzillaData *data) { E_ASSERT(data != NULL); xmlrpc_value *result; xmlrpc_client_call2f(&data->xenv, data->xcli, data->url.c_str(), "Bugzilla.version", &result, "()"); if(data->xenv.fault_occurred) { E_WARNING(E_STRLOC ": Unable to call xmlrpc function (%s)\n", data->xenv.fault_string); if(data->cb) (data->cb)(data->xenv.fault_string, data->cb_data); return (char*)""; } /* this value will be malloc()-ated by xmlrpc_decompose_value() and should be freeed by user */ char *ret; xmlrpc_decompose_value(&data->xenv, result, "{s:s,*}", "version", &ret); xmlrpc_DECREF(result); return ret; }
char * wpGetBlogId(char *username, char *password, char *url) { char *blogid; int i; int noOfBlogs; xmlrpc_env env; xmlrpc_client *clientP; char *methodName = "wp.getUsersBlogs"; xmlrpc_value *result, *result2; wp_env_init(&env, &clientP); /* Make the remote procedure call */ xmlrpc_client_call2f(&env, clientP, url, methodName, &result, "(ss)", username, password); die_if_fault_occurred(&env); noOfBlogs = xmlrpc_array_size(&env, result); if ( noOfBlogs > 1 ) { fprintf(stderr, "Currently only single blog wp accounts are supported\n"); blogid = NULL; goto out; } for(i = 0; i < noOfBlogs; i++) { xmlrpc_value *blog_id_xml; xmlrpc_array_read_item(&env, result, i, &result2); xmlrpc_struct_read_value(&env, result2, "blogid", &blog_id_xml); xmlrpc_read_string(&env, blog_id_xml,(const char **) &blogid); xmlrpc_DECREF(blog_id_xml); } /* Dispose of our result value. */ xmlrpc_DECREF(result2); out: xmlrpc_DECREF(result); /* Clean up our error-handling environment. */ wp_env_clean(&env, &clientP); return blogid; }
static void testSynchCall(void) { xmlrpc_env env; xmlrpc_client * clientP; xmlrpc_value * resultP; xmlrpc_value * emptyArrayP; xmlrpc_server_info * noSuchServerInfoP; xmlrpc_env_init(&env); emptyArrayP = xmlrpc_array_new(&env); TEST_NO_FAULT(&env); xmlrpc_client_setup_global_const(&env); TEST_NO_FAULT(&env); xmlrpc_client_create(&env, 0, "testprog", "1.0", NULL, 0, &clientP); TEST_NO_FAULT(&env); noSuchServerInfoP = xmlrpc_server_info_new(&env, "nosuchserver"); TEST_NO_FAULT(&env); xmlrpc_client_call2(&env, clientP, noSuchServerInfoP, "nosuchmethod", emptyArrayP, &resultP); TEST_FAULT(&env, XMLRPC_NETWORK_ERROR); /* No such server */ xmlrpc_client_call2f(&env, clientP, "nosuchserver", "nosuchmethod", &resultP, "(i)", 7); TEST_FAULT(&env, XMLRPC_NETWORK_ERROR); /* No such server */ xmlrpc_server_info_free(noSuchServerInfoP); xmlrpc_client_destroy(clientP); xmlrpc_DECREF(emptyArrayP); xmlrpc_client_teardown_global_const(); xmlrpc_env_clean(&env); }
static void addInterruptibly(xmlrpc_client * const clientP, const char * const serverUrl, int const addend, int const adder) { const char * const methodName = "sample.add"; xmlrpc_env env; xmlrpc_value * resultP; xmlrpc_int32 sum; xmlrpc_env_init(&env); printf("Making XMLRPC call to server url '%s' method '%s' " "to request the sum " "of %d and %d...\n", serverUrl, methodName, addend, adder); interrupt = 0; /* Global variable */ alarm(2); /* Interrupt the call if it hasn't finished 2 seconds from now */ /* Make the remote procedure call */ xmlrpc_client_call2f(&env, clientP, serverUrl, methodName, &resultP, "(ii)", (xmlrpc_int32) addend, (xmlrpc_int32) adder); die_if_fault_occurred(&env); alarm(0); /* Cancel alarm, if it hasn't happened yet */ /* Get our sum 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); xmlrpc_env_clean(&env); }
int bugzilla_login(BugzillaData *data, const char *user, const char *passwd) { E_ASSERT(data != NULL); xmlrpc_value *result; int remember = 0; /* remember login data */ int id = -1; /* bugzilla user id */ xmlrpc_client_call2f(&data->xenv, data->xcli, data->url.c_str(), "User.login", &result, "({s:s,s:s,s:b})", "login", user, "password", passwd, "remember", remember); if(data->xenv.fault_occurred) { E_WARNING(E_STRLOC ": Unable to perform login function (%s)\n", data->xenv.fault_string); if(data->cb) (data->cb)(data->xenv.fault_string, data->cb_data); return id; } xmlrpc_decompose_value(&data->xenv, result, "{s:i,*}", "id", &id); xmlrpc_DECREF(result); return id; }
int bugzilla_submit_bug(BugzillaData *data, const char *product, const char *component, const char *summary, const char *version, const char *description, const char *op_sys, const char *platform, const char *priority, const char *severity, const char *cc) { E_ASSERT(data != NULL); int bug_id = -1; xmlrpc_value *result; /* if given CC, add it so bugzilla assign that email as notification receiver */ if(cc) { /* as for now we only support single email address */ xmlrpc_value *cc_array, *cc_str; cc_array = xmlrpc_array_new(&data->xenv); cc_str = xmlrpc_string_new(&data->xenv, (const char *const)cc); xmlrpc_array_append_item(&data->xenv, cc_array, cc_str); xmlrpc_DECREF(cc_str); xmlrpc_client_call2f(&data->xenv, data->xcli, data->url.c_str(), "Bug.create", &result, "({s:s,s:s,s:s,s:s,s:s,s:s,s:s,s:s,s:s,s:A})", "product", product, "component", component, "summary", summary, "version", version, "description", description, "op_sys", op_sys, "platform", platform, "priority", priority, "severity", severity, "cc", cc_array); xmlrpc_DECREF(cc_array); } else { xmlrpc_client_call2f(&data->xenv, data->xcli, data->url.c_str(), "Bug.create", &result, "({s:s,s:s,s:s,s:s,s:s,s:s,s:s,s:s,s:s})", "product", product, "component", component, "summary", summary, "version", version, "description", description, "op_sys", op_sys, "platform", platform, "priority", priority, "severity", severity); } if(data->xenv.fault_occurred) { E_WARNING(E_STRLOC ": Unable to perform submit function (%s)\n", data->xenv.fault_string); if(data->cb) (data->cb)(data->xenv.fault_string, data->cb_data); return bug_id; } xmlrpc_decompose_value(&data->xenv, result, "{s:i,*}", "id", &bug_id); xmlrpc_DECREF(result); return bug_id; }