int wpNewPost(char *username, char *password, wppost_t *post) { int retval = 0; char *postid = NULL; xmlrpc_env env; xmlrpc_client *clientP; xmlrpc_server_info * serverInfoP; xmlrpc_value *paramArrayP = NULL; char *methodName = "metaWeblog.newPost"; xmlrpc_value *resultP; wp_env_init(&env, &clientP); retval = wpCreatePostStruct(&env, username, password, post, ¶mArrayP, 0); if (retval != 0) { fprintf(stderr, "Error creating post structure, exiting\n"); goto out; } serverInfoP = xmlrpc_server_info_new(&env, post->url); xmlrpc_client_call2(&env, clientP, serverInfoP, methodName, paramArrayP, &resultP); xmlrpc_read_string(&env, resultP,(const char **) &postid); post->postid = postid; xmlrpc_DECREF(resultP); out: xmlrpc_DECREF(paramArrayP); wp_env_clean(&env, &clientP); return retval; }
/* * Make an XML-RPC call to methodName. This uses the curl client to make * a connection over SSL using the CA cert that should have been installed * by ipa-client-install. */ static void callRPC(char * user_agent, xmlrpc_env * const envP, xmlrpc_server_info * const serverInfoP, const char * const methodName, xmlrpc_value * const paramArrayP, xmlrpc_value ** const resultPP) { struct xmlrpc_clientparms clientparms; struct xmlrpc_curl_xportparms * curlXportParmsP = NULL; xmlrpc_client * clientP = NULL; memset(&clientparms, 0, sizeof(clientparms)); XMLRPC_ASSERT(xmlrpc_value_type(paramArrayP) == XMLRPC_TYPE_ARRAY); curlXportParmsP = malloc(sizeof(*curlXportParmsP)); if (curlXportParmsP == NULL) { xmlrpc_env_set_fault(envP, XMLRPC_INTERNAL_ERROR, _("Out of memory!")); return; } memset(curlXportParmsP, 0, sizeof(*curlXportParmsP)); /* Have curl do SSL certificate validation */ curlXportParmsP->no_ssl_verifypeer = 0; curlXportParmsP->no_ssl_verifyhost = 0; curlXportParmsP->cainfo = "/etc/ipa/ca.crt"; curlXportParmsP->user_agent = user_agent; /* Enable GSSAPI credentials delegation */ curlXportParmsP->gssapi_delegation = 1; clientparms.transport = "curl"; clientparms.transportparmsP = (struct xmlrpc_xportparms *) curlXportParmsP; clientparms.transportparm_size = XMLRPC_CXPSIZE(gssapi_delegation); xmlrpc_client_create(envP, XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION, &clientparms, sizeof(clientparms), &clientP); /* Set up kerberos negotiate authentication in curl. */ xmlrpc_server_info_set_user(envP, serverInfoP, ":", ""); xmlrpc_server_info_allow_auth_negotiate(envP, serverInfoP); /* Perform the XML-RPC call */ if (!envP->fault_occurred) { xmlrpc_client_call2(envP, clientP, serverInfoP, methodName, paramArrayP, resultPP); } /* Cleanup */ xmlrpc_server_info_free(serverInfoP); xmlrpc_client_destroy(clientP); free((void*)clientparms.transportparmsP); }
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); }
/* * Write accounting information to this modules database. */ static int xmlrpc_accounting(void *instance, REQUEST * request) { rlm_xmlrpc_t *inst = instance; rlm_xmlrpc_client_t *client; VALUE_PAIR *vps = request->packet->vps; xmlrpc_value *array_param; xmlrpc_value *array_string; xmlrpc_value *resultP; char *const methodName = inst->method; int error; VALUE_PAIR *status_type_pair; if ((status_type_pair = pairfind(request->packet->vps, PW_ACCT_STATUS_TYPE)) == NULL) { radlog(L_ERR, "rlm_xmlrpc: No Accounting-Status-Type record."); return RLM_MODULE_NOOP; } client = get_client(instance); /* * Xmlrpc wants method params in an array, so we build an array * with a pointer in index 0. This pointer contains a sub array * filled whith strings each one for packet attributes. */ array_param = xmlrpc_array_new(&client->env); error = check_error(&client->env); if (error != RLM_MODULE_OK) return error; array_string = xmlrpc_array_new(&client->env); error = check_error(&client->env); if (error != RLM_MODULE_OK) return error; /* * The array of strings is built whit vp_prints */ VALUE_PAIR *vp = vps; for (; vp; vp = vp->next) { char buf[1024]; vp_prints(buf, sizeof(buf), vp); xmlrpc_array_append_item(&client->env, array_string, xmlrpc_string_new(&client->env, buf)); int error = check_error(&client->env); if (error != RLM_MODULE_OK) return error; } xmlrpc_array_append_item(&client->env, array_param, array_string); error = check_error(&client->env); if (error != RLM_MODULE_OK) return error; xmlrpc_client_call2(&client->env, client->clientP, client->serverInfoP, methodName, array_param, &resultP); error = check_error(&client->env); if (error != RLM_MODULE_OK) return error; /* * We don't check for method return value. If an accounting packet is * dispatched without errors, it should be processed by server * without any further notification. */ xmlrpc_DECREF(resultP); xmlrpc_DECREF(array_param); xmlrpc_DECREF(array_string); return RLM_MODULE_OK; }