static xmlrpc_value * you_patch_to_xmlrpc (xmlrpc_env *env, RCYouPatch *patch) { RCPackageSpec *spec = RC_PACKAGE_SPEC (patch); xmlrpc_value *xpatch = NULL; xpatch = xmlrpc_struct_new (env); XMLRPC_FAIL_IF_FAULT (env); RCD_XMLRPC_STRUCT_SET_STRING (env, xpatch, "name", rc_package_spec_get_name (spec)); XMLRPC_FAIL_IF_FAULT (env); RCD_XMLRPC_STRUCT_SET_STRING (env, xpatch, "version", rc_package_spec_version_to_str_static (spec)); XMLRPC_FAIL_IF_FAULT (env); cleanup: if (env->fault_occurred && xpatch != NULL) { xmlrpc_DECREF (xpatch); xpatch = NULL; } return xpatch; }
int wpCreatePostStruct(xmlrpc_env *env, char *username, char*password, wppost_t *post, xmlrpc_value **paramArray, int mode) { int retval = 0; xmlrpc_value *blogidP, *postidP, *usernameP, *passwordP, *titleP, *descriptionP, *dateP, *publishP, *categoryP, *contentP, *tokenP; char *token; char *categories = NULL, *catPtr; if ( mode == 0 ) { post->blogid = wpGetBlogId(username, password, post->url); if (post->blogid == NULL) { fprintf(stderr, "NULL Blog Id\n"); retval = 1; goto out; } blogidP = xmlrpc_string_new(env, post->blogid); postidP = NULL; } else { blogidP = NULL; postidP = xmlrpc_string_new(env, post->postid); } usernameP = xmlrpc_string_new(env, username); passwordP = xmlrpc_string_new(env, password); titleP = xmlrpc_string_new(env, post->subject); descriptionP = xmlrpc_string_new(env, post->body); if(!strcmp(post->status, "draft")) { publishP = xmlrpc_bool_new(env, FALSE); } else { publishP = xmlrpc_bool_new(env, TRUE); } dateP = xmlrpc_datetime_new_sec(env, time(NULL)); asprintf(&categories, "%s", post->categories); catPtr = categories; categoryP = xmlrpc_array_new(env); token = strtok(categories, ","); tokenP = xmlrpc_string_new(env, token); xmlrpc_array_append_item(env, categoryP, tokenP); while( (token = strtok( (char *) NULL, ",") ) != NULL ) { tokenP = xmlrpc_string_new(env, token); xmlrpc_array_append_item(env, categoryP, tokenP); } free(catPtr); contentP = xmlrpc_struct_new(env); xmlrpc_struct_set_value(env, contentP, "title", titleP); xmlrpc_struct_set_value(env, contentP, "description", descriptionP); xmlrpc_struct_set_value(env, contentP, "dateCreated", dateP); xmlrpc_struct_set_value(env, contentP, "categories", categoryP); /* Populate the Parameter Array */ *paramArray = xmlrpc_array_new(env); if (mode == 0) xmlrpc_array_append_item(env, *paramArray, blogidP); else xmlrpc_array_append_item(env, *paramArray, postidP); xmlrpc_array_append_item(env, *paramArray, usernameP); xmlrpc_array_append_item(env, *paramArray, passwordP); xmlrpc_array_append_item(env, *paramArray, contentP); xmlrpc_array_append_item(env, *paramArray, publishP); out: return retval; }
/* Pack the information from any client method into a generic xmlrpc struct to send to the server */ xmlrpc_value * callinfo_pack(xmlrpc_env *envP, struct call_info *cip) { xmlrpc_value *s = xmlrpc_struct_new(envP); xmlrpc_value *methargs = xmlrpc_array_new(envP); xmlrpc_value *files = xmlrpc_array_new(envP); int i; xmlrpc_struct_set_value(envP, s, "clientIP", xmlrpc_string_new(envP, nonull(cip->clientIP))); xmlrpc_struct_set_value(envP, s, "serverURL", xmlrpc_string_new(envP, nonull(cip->serverURL))); xmlrpc_struct_set_value(envP, s, "session", xmlrpc_string_new(envP, nonull(cip->session))); xmlrpc_struct_set_value(envP, s, "method", xmlrpc_string_new(envP, nonull(cip->method))); xmlrpc_struct_set_value(envP, s, "user", xmlrpc_string_new(envP, nonull(cip->user))); xmlrpc_struct_set_value(envP, s, "password", xmlrpc_string_new(envP, nonull(cip->password))); xmlrpc_struct_set_value(envP, s, "project", xmlrpc_string_new(envP, nonull(cip->project))); xmlrpc_struct_set_value(envP, s, "version", xmlrpc_string_new(envP, nonull(cip->version))); if (cip->methodargs) { for (i = 0; cip->methodargs[i]; ++i) { if (!strncmp(cip->methodargs[i], "file:", 5)) { char *file_what, *file_name; file_what = strdup(&cip->methodargs[i][5]); file_name = strchr(file_what, '='); if (file_name) { xmlrpc_value * fstruct; *file_name++ = '\0'; fstruct = file_pack(envP, file_what, file_name); xmlrpc_array_append_item(envP, files, fstruct); } else { fprintf(stderr, "oracc-client: bad -Mfile arg, expected -Mfile:WHAT=NAME\n"); exit(1); } } else xmlrpc_array_append_item(envP, methargs, xmlrpc_string_new(envP, cip->methodargs[i])); } } xmlrpc_struct_set_value(envP, s, "method-args", methargs); xmlrpc_struct_set_value(envP, s, "method-data", files); return s; }
static void parseStruct(xmlrpc_env * const envP, unsigned int const maxRecursion, xml_element * const elemP, xmlrpc_value ** const structPP) { /*---------------------------------------------------------------------------- Parse the <struct> element 'elemP'. -----------------------------------------------------------------------------*/ xmlrpc_value * structP; XMLRPC_ASSERT_ENV_OK(envP); XMLRPC_ASSERT(elemP != NULL); structP = xmlrpc_struct_new(envP); if (!envP->fault_occurred) { /* Iterate over our children, extracting key/value pairs. */ xml_element ** const members = xml_element_children(elemP); unsigned int const size = xml_element_children_size(elemP); unsigned int i; for (i = 0; i < size && !envP->fault_occurred; ++i) { const char * const elemName = xml_element_name(members[i]); if (!xmlrpc_streq(elemName, "member")) setParseFault(envP, "<%s> element found where only <member> " "makes sense", elemName); else { xmlrpc_value * keyP; xmlrpc_value * valueP; parseMember(envP, members[i], maxRecursion, &keyP, &valueP); if (!envP->fault_occurred) { xmlrpc_struct_set_value_v(envP, structP, keyP, valueP); xmlrpc_DECREF(keyP); xmlrpc_DECREF(valueP); } } } if (envP->fault_occurred) xmlrpc_DECREF(structP); else *structPP = structP; } }
xmlrpc_registry * xmlrpc_registry_new(xmlrpc_env *env) { xmlrpc_value *methods; xmlrpc_registry *registry; int registry_valid; XMLRPC_ASSERT_ENV_OK(env); /* Error-handling preconditions. */ methods = NULL; registry = NULL; registry_valid = 0; /* Allocate our memory. */ methods = xmlrpc_struct_new(env); XMLRPC_FAIL_IF_FAULT(env); registry = (xmlrpc_registry*) malloc(sizeof(xmlrpc_registry)); XMLRPC_FAIL_IF_NULL(registry, env, XMLRPC_INTERNAL_ERROR, "Could not allocate memory for registry"); /* Set everything up. */ registry->_introspection_enabled = 1; registry->_methods = methods; registry->_default_method = NULL; registry->_preinvoke_method = NULL; registry_valid = 1; /* Install our system methods. */ install_system_methods(env, registry); XMLRPC_FAIL_IF_FAULT(env); cleanup: if (env->fault_occurred) { if (registry_valid) { xmlrpc_registry_free(registry); } else { if (methods) xmlrpc_DECREF(methods); if (registry) free(registry); } return NULL; } return registry; }
static xmlrpc_value * rcd_mirror_to_xmlrpc (RCDMirror *mirror, xmlrpc_env *env) { xmlrpc_value *value; g_return_val_if_fail (mirror != NULL, NULL); value = xmlrpc_struct_new (env); XMLRPC_FAIL_IF_FAULT (env); if (mirror->name && *mirror->name) RCD_XMLRPC_STRUCT_SET_STRING (env, value, "name", mirror->name); if (mirror->location && *mirror->location) RCD_XMLRPC_STRUCT_SET_STRING (env, value, "location", mirror->location); if (mirror->url && *mirror->url) RCD_XMLRPC_STRUCT_SET_STRING (env, value, "url", mirror->url); if (mirror->ftp && *mirror->ftp) RCD_XMLRPC_STRUCT_SET_STRING (env, value, "ftp", mirror->ftp); if (mirror->contact && *mirror->contact) RCD_XMLRPC_STRUCT_SET_STRING (env, value, "contact", mirror->contact); cleanup: if (env->fault_occurred) { if (value) xmlrpc_DECREF (value); return NULL; } return value; }
static xmlrpc_value * you_info (xmlrpc_env *env, xmlrpc_value *param_array, void *user_data) { xmlrpc_value *xmlrpc_patch = NULL; RCYouPatch *patch = NULL; xmlrpc_value *result = NULL; xmlrpc_parse_value (env, param_array, "(V)", &xmlrpc_patch); XMLRPC_FAIL_IF_FAULT (env); patch = rc_xmlrpc_to_rc_you_patch (xmlrpc_patch, env, RC_YOU_PATCH_FROM_XMLRPC_PATCH); XMLRPC_FAIL_IF_FAULT (env); g_assert (patch != NULL); result = xmlrpc_struct_new (env); XMLRPC_FAIL_IF_FAULT (env); RCD_XMLRPC_STRUCT_SET_STRING (env, result, "summary", patch->summary); XMLRPC_FAIL_IF_FAULT (env); RCD_XMLRPC_STRUCT_SET_STRING (env, result, "description", patch->description); XMLRPC_FAIL_IF_FAULT (env); cleanup: if (env->fault_occurred) { if (patch) rc_you_patch_unref (patch); if (result) xmlrpc_DECREF (result); return NULL; } return result; }
static void test_struct (void) { xmlrpc_env env; xmlrpc_value * value1P; xmlrpc_value *s, *i, *i1, *i2, *i3, *key, *value; size_t size; int present; xmlrpc_bool bval; char const weirdKey[] = {'f', 'o', 'o', '\0', 'b', 'a', 'r'}; xmlrpc_env_init(&env); /* Create a struct. */ s = xmlrpc_struct_new(&env); TEST_NO_FAULT(&env); TEST(s != NULL); TEST(XMLRPC_TYPE_STRUCT == xmlrpc_value_type(s)); size = xmlrpc_struct_size(&env, s); TEST_NO_FAULT(&env); TEST(size == 0); /* Create some elements to insert into our struct. */ i1 = xmlrpc_build_value(&env, "s", "Item #1"); TEST_NO_FAULT(&env); i2 = xmlrpc_build_value(&env, "s", "Item #2"); TEST_NO_FAULT(&env); i3 = xmlrpc_build_value(&env, "s", "Item #3"); TEST_NO_FAULT(&env); /* Insert a single item. */ xmlrpc_struct_set_value(&env, s, "foo", i1); TEST_NO_FAULT(&env); size = xmlrpc_struct_size(&env, s); TEST_NO_FAULT(&env); TEST(size == 1); /* Insert an item whose key has the same hash value as "foo". */ xmlrpc_struct_set_value(&env, s, "qmdebdw", i2); TEST_NO_FAULT(&env); size = xmlrpc_struct_size(&env, s); TEST_NO_FAULT(&env); TEST(size == 2); i = xmlrpc_struct_get_value(&env, s, "foo"); TEST_NO_FAULT(&env); TEST(i == i1); i = xmlrpc_struct_get_value(&env, s, "qmdebdw"); TEST_NO_FAULT(&env); TEST(i == i2); /* Replace an existing element with a different element. */ xmlrpc_struct_set_value(&env, s, "foo", i3); TEST_NO_FAULT(&env); size = xmlrpc_struct_size(&env, s); TEST_NO_FAULT(&env); TEST(size == 2); i = xmlrpc_struct_get_value(&env, s, "foo"); TEST_NO_FAULT(&env); TEST(i == i3); /* Insert an item with a NUL in the key */ xmlrpc_struct_set_value_n(&env, s, weirdKey, sizeof(weirdKey), i2); TEST_NO_FAULT(&env); size = xmlrpc_struct_size(&env, s); TEST_NO_FAULT(&env); TEST(size == 3); test_struct_get_element(s, i3, i2, weirdKey, sizeof(weirdKey)); /* Replace an existing element with the same element (tricky). */ xmlrpc_struct_set_value(&env, s, "foo", i3); TEST_NO_FAULT(&env); size = xmlrpc_struct_size(&env, s); TEST_NO_FAULT(&env); TEST(size == 3); i = xmlrpc_struct_get_value(&env, s, "foo"); TEST_NO_FAULT(&env); TEST(i == i3); /* Test for the presence and absence of elements. */ present = xmlrpc_struct_has_key(&env, s, "foo"); TEST_NO_FAULT(&env); TEST(present); present = xmlrpc_struct_has_key(&env, s, "qmdebdw"); TEST_NO_FAULT(&env); TEST(present); present = xmlrpc_struct_has_key(&env, s, "bogus"); TEST_NO_FAULT(&env); TEST(!present); /* Make sure our typechecks work correctly. */ xmlrpc_struct_size(&env, i1); TEST_FAULT(&env, XMLRPC_TYPE_ERROR); xmlrpc_struct_has_key(&env, i1, "foo"); TEST_FAULT(&env, XMLRPC_TYPE_ERROR); xmlrpc_struct_set_value(&env, i1, "foo", i2); TEST_FAULT(&env, XMLRPC_TYPE_ERROR); xmlrpc_struct_set_value_v(&env, s, s, i2); TEST_FAULT(&env, XMLRPC_TYPE_ERROR); /* Test cleanup code (w/memprof). */ xmlrpc_DECREF(s); s = xmlrpc_build_value(&env, "{s:s,s:i,s:b}", "foo", "Hello!", "bar", (xmlrpc_int32) 1, "baz", (xmlrpc_bool) 0); TEST_NO_FAULT(&env); TEST(s != NULL); TEST(xmlrpc_value_type(s) == XMLRPC_TYPE_STRUCT); size = xmlrpc_struct_size(&env, s); TEST_NO_FAULT(&env); TEST(size == 3); present = xmlrpc_struct_has_key(&env, s, "foo"); TEST_NO_FAULT(&env); TEST(present); present = xmlrpc_struct_has_key(&env, s, "bar"); TEST_NO_FAULT(&env); TEST(present); present = xmlrpc_struct_has_key(&env, s, "baz"); TEST_NO_FAULT(&env); TEST(present); xmlrpc_struct_read_value(&env, s, "baz", &value1P); TEST_NO_FAULT(&env); xmlrpc_read_bool(&env, value1P, &bval); TEST_NO_FAULT(&env); TEST(!bval); xmlrpc_DECREF(value1P); testStructReadout(s, 3); test_struct_decompose(s); /* Test type check. */ xmlrpc_struct_get_key_and_value(&env, i1, 0, &key, &value); TEST_FAULT(&env, XMLRPC_TYPE_ERROR); TEST(key == NULL && value == NULL); /* Test bounds checks. */ xmlrpc_struct_get_key_and_value(&env, s, -1, &key, &value); TEST_FAULT(&env, XMLRPC_INDEX_ERROR); TEST(key == NULL && value == NULL); xmlrpc_struct_get_key_and_value(&env, s, 3, &key, &value); TEST_FAULT(&env, XMLRPC_INDEX_ERROR); TEST(key == NULL && value == NULL); /* Test cleanup code (w/memprof). */ xmlrpc_DECREF(s); xmlrpc_DECREF(i1); xmlrpc_DECREF(i2); xmlrpc_DECREF(i3); xmlrpc_env_clean(&env); }
static xmlrpc_value * transaction_xml (xmlrpc_env *env, RCDTransaction *transaction, gboolean successful, const char *message) { xmlrpc_value *xtrans; xmlrpc_value *xmanifests; RCPackageSList *iter; /* Common part for all logs */ xtrans = xmlrpc_struct_new (env); XMLRPC_FAIL_IF_FAULT (env); if (transaction->id) { RCD_XMLRPC_STRUCT_SET_STRING (env, xtrans, "trid", transaction->id); XMLRPC_FAIL_IF_FAULT (env); } RCD_XMLRPC_STRUCT_SET_INT (env, xtrans, "endtime", time (NULL)); XMLRPC_FAIL_IF_FAULT (env); RCD_XMLRPC_STRUCT_SET_STRING (env, xtrans, "client", transaction->client_id); XMLRPC_FAIL_IF_FAULT (env); RCD_XMLRPC_STRUCT_SET_STRING (env, xtrans, "version", transaction->client_version); XMLRPC_FAIL_IF_FAULT (env); RCD_XMLRPC_STRUCT_SET_INT (env, xtrans, "status", successful ? 1 : 0); XMLRPC_FAIL_IF_FAULT (env); if (message) { RCD_XMLRPC_STRUCT_SET_STRING (env, xtrans, "message", message); XMLRPC_FAIL_IF_FAULT (env); } /* Transaction part */ RCD_XMLRPC_STRUCT_SET_STRING (env, xtrans, "log_type", "package"); XMLRPC_FAIL_IF_FAULT (env); if (transaction->rollback) { RCD_XMLRPC_STRUCT_SET_INT (env, xtrans, "rollback", 1); XMLRPC_FAIL_IF_FAULT (env); } if (transaction->flags & RCD_TRANSACTION_FLAGS_DRY_RUN) { RCD_XMLRPC_STRUCT_SET_INT (env, xtrans, "dry_run", 1); XMLRPC_FAIL_IF_FAULT (env); } if (transaction->flags & RCD_TRANSACTION_FLAGS_DOWNLOAD_ONLY) { RCD_XMLRPC_STRUCT_SET_INT (env, xtrans, "preposition", 1); XMLRPC_FAIL_IF_FAULT (env); } xmanifests = xmlrpc_build_value (env, "()"); XMLRPC_FAIL_IF_FAULT (env); xmlrpc_struct_set_value (env, xtrans, "packages", xmanifests); XMLRPC_FAIL_IF_FAULT (env); xmlrpc_DECREF (xmanifests); for (iter = transaction->install_packages; iter; iter = iter->next) { RCPackage *p = iter->data; RCPackage *sys_pkg; const char *action; xmlrpc_value *xmanifest; sys_pkg = rc_world_find_installed_version (rc_get_world (), p); if (sys_pkg) action = "update"; else action = "install"; xmanifest = manifest_xml_node (env, p, sys_pkg, action); XMLRPC_FAIL_IF_FAULT (env); xmlrpc_array_append_item (env, xmanifests, xmanifest); XMLRPC_FAIL_IF_FAULT (env); xmlrpc_DECREF (xmanifest); } for (iter = transaction->remove_packages; iter; iter = iter->next) { RCPackage *p = iter->data; xmlrpc_value *xmanifest; xmanifest = manifest_xml_node (env, p, NULL, "remove"); XMLRPC_FAIL_IF_FAULT (env); xmlrpc_array_append_item (env, xmanifests, xmanifest); XMLRPC_FAIL_IF_FAULT (env); xmlrpc_DECREF (xmanifest); } cleanup: return xtrans; } /* transaction_xml */
static xmlrpc_value * manifest_xml_node(xmlrpc_env *env, RCPackage *new_pkg, RCPackage *old_pkg, const char *action) { xmlrpc_value *xmanifest; xmlrpc_value *xpkg; #if 0 RCPackageUpdate *update; #endif xmanifest = xmlrpc_struct_new (env); XMLRPC_FAIL_IF_FAULT (env); RCD_XMLRPC_STRUCT_SET_STRING ( env, xmanifest, "bid", new_pkg->channel ? rc_channel_get_id (new_pkg->channel) : ""); XMLRPC_FAIL_IF_FAULT (env); RCD_XMLRPC_STRUCT_SET_STRING( env, xmanifest, "action", action); XMLRPC_FAIL_IF_FAULT (env); xpkg = xmlrpc_struct_new (env); XMLRPC_FAIL_IF_FAULT (env); xmlrpc_struct_set_value (env, xmanifest, "package", xpkg); XMLRPC_FAIL_IF_FAULT (env); xmlrpc_DECREF (xpkg); RCD_XMLRPC_STRUCT_SET_STRING( env, xpkg, "name", g_quark_to_string (new_pkg->spec.nameq)); XMLRPC_FAIL_IF_FAULT (env); RCD_XMLRPC_STRUCT_SET_INT( env, xpkg, "epoch", new_pkg->spec.epoch); XMLRPC_FAIL_IF_FAULT (env); RCD_XMLRPC_STRUCT_SET_STRING( env, xpkg, "version", new_pkg->spec.version); XMLRPC_FAIL_IF_FAULT (env); RCD_XMLRPC_STRUCT_SET_STRING( env, xpkg, "release", new_pkg->spec.release); XMLRPC_FAIL_IF_FAULT (env); #if 0 update = rc_package_get_latest_update (new_pkg); if (update) { RCD_XMLRPC_STRUCT_SET_INT( env, xpkg, "size", update->package_size); XMLRPC_FAIL_IF_FAULT (env); RCD_XMLRPC_STRUCT_SET_INT( env, xpkg, "hid", update->hid); XMLRPC_FAIL_IF_FAULT (env); if (new_pkg->channel) { RCD_XMLRPC_STRUCT_SET_STRING( env, xpkg, "channel_id", rc_channel_get_id (new_pkg->channel)); XMLRPC_FAIL_IF_FAULT (env); } if (update->package_url) { RCD_XMLRPC_STRUCT_SET_STRING( env, xpkg, "url", update->package_url); XMLRPC_FAIL_IF_FAULT (env); } } #endif if (old_pkg) { xpkg = xmlrpc_struct_new (env); XMLRPC_FAIL_IF_FAULT (env); xmlrpc_struct_set_value (env, xmanifest, "oldpackage", xpkg); XMLRPC_FAIL_IF_FAULT (env); xmlrpc_DECREF (xpkg); RCD_XMLRPC_STRUCT_SET_STRING( env, xpkg, "name", g_quark_to_string (new_pkg->spec.nameq)); XMLRPC_FAIL_IF_FAULT (env); RCD_XMLRPC_STRUCT_SET_INT( env, xpkg, "epoch", old_pkg->spec.epoch); XMLRPC_FAIL_IF_FAULT (env); RCD_XMLRPC_STRUCT_SET_STRING( env, xpkg, "version", old_pkg->spec.version); XMLRPC_FAIL_IF_FAULT (env); RCD_XMLRPC_STRUCT_SET_STRING( env, xpkg, "release", old_pkg->spec.release); XMLRPC_FAIL_IF_FAULT (env); } cleanup: return xmanifest; } /* manifest_xml_node */
cWrapper() { env_wrap env; this->valueP = xmlrpc_struct_new(&env.env_c); throwIfError(env); }
static gboolean add_service_cb (RCWorld *subworld, gpointer user_data) { RCWorldService *service = RC_WORLD_SERVICE (subworld); ServiceInfo *info = user_data; xmlrpc_value *xmlrpc_service; xmlrpc_service = xmlrpc_struct_new (info->env); XMLRPC_FAIL_IF_FAULT (info->env); RCD_XMLRPC_STRUCT_SET_STRING (info->env, xmlrpc_service, "url", service->url); if (service->name) { RCD_XMLRPC_STRUCT_SET_STRING (info->env, xmlrpc_service, "name", service->name); } if (service->unique_id) { RCD_XMLRPC_STRUCT_SET_STRING (info->env, xmlrpc_service, "id", service->unique_id); } RCD_XMLRPC_STRUCT_SET_INT (info->env, xmlrpc_service, "is_sticky", service->is_sticky); RCD_XMLRPC_STRUCT_SET_INT (info->env, xmlrpc_service, "is_invisible", service->is_invisible); RCD_XMLRPC_STRUCT_SET_INT (info->env, xmlrpc_service, "is_singleton", service->is_singleton); if (g_type_is_a (G_TYPE_FROM_INSTANCE (service), RCD_TYPE_WORLD_REMOTE)) { RCDWorldRemote *remote = RCD_WORLD_REMOTE (service); if (remote->distro) { RCD_XMLRPC_STRUCT_SET_STRING (info->env, xmlrpc_service, "distro_name", rc_distro_get_name (remote->distro)); RCD_XMLRPC_STRUCT_SET_STRING (info->env, xmlrpc_service, "distro_version", rc_distro_get_version (remote->distro)); RCD_XMLRPC_STRUCT_SET_STRING (info->env, xmlrpc_service, "distro_target", rc_distro_get_target (remote->distro)); } if (remote->contact_email) { RCD_XMLRPC_STRUCT_SET_STRING (info->env, xmlrpc_service, "contact_email", remote->contact_email); } RCD_XMLRPC_STRUCT_SET_INT (info->env, xmlrpc_service, "premium_service", remote->premium_service); } xmlrpc_array_append_item (info->env, info->result, xmlrpc_service); XMLRPC_FAIL_IF_FAULT (info->env); xmlrpc_DECREF (xmlrpc_service); cleanup: if (info->env->fault_occurred) return FALSE; return TRUE; }
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; }
void getDataBlock(xmlrpc_env * envP, xmlrpc_value * DataStructP, xmlrpc_value ** OutDataStructPP) { xmlrpc_value * ID_t, * PORT_t, * DATA_t, * IP_t; xmlrpc_struct_find_value(envP, DataStructP, "ID", &ID_t); xmlrpc_struct_find_value(envP, DataStructP, "IP", &IP_t); xmlrpc_struct_find_value(envP, DataStructP, "PORT", &PORT_t); xmlrpc_struct_find_value(envP, DataStructP, "DATA", &DATA_t); xmlrpc_int ID, PORT, DATA; char* IP; xmlrpc_read_int(envP, ID_t, &ID); xmlrpc_read_string(envP, IP_t, &IP); xmlrpc_read_int(envP, PORT_t, &PORT); xmlrpc_read_int(envP, DATA_t, &DATA); xmlrpc_DECREF(ID_t); xmlrpc_DECREF(IP_t); xmlrpc_DECREF(PORT_t); xmlrpc_DECREF(DATA_t); printf("The value of ID is %d\n", ID); printf("The value of ID is %s\n", IP); printf("The value of PORT is %d\n", PORT); printf("The value of DATA is %d\n", DATA); xmlrpc_value * ID_out, * IP_out, * PORT_out, * DATA_out, *DATAP_out; xmlrpc_value * ID1_out, * IP1_out, * PORT1_out, * DATA1_out, *DATAP1_out; xmlrpc_value * ID2_out, * IP2_out, * PORT2_out, * DATA2_out, *DATAP2_out; xmlrpc_value * structArray; structArray = xmlrpc_array_new(envP); ID_out = xmlrpc_int_new(envP, 78654); IP_out = xmlrpc_string_new(envP, "127.0.0.1"); PORT_out = xmlrpc_int_new(envP, 8090); DATA_out = xmlrpc_int_new(envP, 45425); ID1_out = xmlrpc_int_new(envP, 78764); IP1_out = xmlrpc_string_new(envP, "127.0.0.1"); PORT1_out = xmlrpc_int_new(envP, 8091); DATA1_out = xmlrpc_int_new(envP, 452135); ID2_out = xmlrpc_int_new(envP, 78123); IP2_out = xmlrpc_string_new(envP, "127.0.0.1"); PORT2_out = xmlrpc_int_new(envP, 8092); DATA2_out = xmlrpc_int_new(envP, 45563); DATAP_out = xmlrpc_struct_new(envP); DATAP1_out = xmlrpc_struct_new(envP); DATAP2_out = xmlrpc_struct_new(envP); xmlrpc_struct_set_value(envP, DATAP_out, "ID", ID_out); xmlrpc_struct_set_value(envP, DATAP_out, "IP", IP_out); xmlrpc_struct_set_value(envP, DATAP_out, "PORT", PORT_out); xmlrpc_struct_set_value(envP, DATAP_out, "DATA", DATA_out); xmlrpc_struct_set_value(envP, DATAP1_out, "ID", ID1_out); xmlrpc_struct_set_value(envP, DATAP1_out, "IP", IP1_out); xmlrpc_struct_set_value(envP, DATAP1_out, "PORT", PORT1_out); xmlrpc_struct_set_value(envP, DATAP1_out, "DATA", DATA1_out); xmlrpc_struct_set_value(envP, DATAP2_out, "ID", ID2_out); xmlrpc_struct_set_value(envP, DATAP2_out, "IP", IP2_out); xmlrpc_struct_set_value(envP, DATAP2_out, "PORT", PORT2_out); xmlrpc_struct_set_value(envP, DATAP2_out, "DATA", DATA2_out); xmlrpc_array_append_item(envP, structArray, DATAP_out); xmlrpc_array_append_item(envP, structArray, DATAP1_out); xmlrpc_array_append_item(envP, structArray, DATAP2_out); xmlrpc_DECREF(ID_out); xmlrpc_DECREF(IP_out); xmlrpc_DECREF(PORT_out); xmlrpc_DECREF(DATA_out); xmlrpc_DECREF(ID1_out); xmlrpc_DECREF(IP1_out); xmlrpc_DECREF(PORT1_out); xmlrpc_DECREF(DATA1_out); xmlrpc_DECREF(ID2_out); xmlrpc_DECREF(IP2_out); xmlrpc_DECREF(PORT2_out); xmlrpc_DECREF(DATA2_out); *OutDataStructPP = structArray; }
static xmlrpc_value * you_transaction_xml (xmlrpc_env *env, RCYouTransaction *transaction, gboolean successful, const char *message) { xmlrpc_value *xtrans; xmlrpc_value *xmanifests; RCYouPatchSList *iter; /* Common part for all logs */ xtrans = xmlrpc_struct_new (env); XMLRPC_FAIL_IF_FAULT (env); if (transaction->id) { RCD_XMLRPC_STRUCT_SET_STRING (env, xtrans, "trid", transaction->id); XMLRPC_FAIL_IF_FAULT (env); } RCD_XMLRPC_STRUCT_SET_INT (env, xtrans, "endtime", time (NULL)); XMLRPC_FAIL_IF_FAULT (env); RCD_XMLRPC_STRUCT_SET_STRING (env, xtrans, "client", transaction->client_id); XMLRPC_FAIL_IF_FAULT (env); RCD_XMLRPC_STRUCT_SET_STRING (env, xtrans, "version", transaction->client_version); XMLRPC_FAIL_IF_FAULT (env); RCD_XMLRPC_STRUCT_SET_INT (env, xtrans, "status", successful ? 1 : 0); XMLRPC_FAIL_IF_FAULT (env); if (message) { RCD_XMLRPC_STRUCT_SET_STRING (env, xtrans, "message", message); XMLRPC_FAIL_IF_FAULT (env); } /* Transaction part */ RCD_XMLRPC_STRUCT_SET_STRING (env, xtrans, "log_type", "patch"); XMLRPC_FAIL_IF_FAULT (env); if (transaction->flags & RCD_TRANSACTION_FLAGS_DRY_RUN) { RCD_XMLRPC_STRUCT_SET_INT (env, xtrans, "dry_run", 1); XMLRPC_FAIL_IF_FAULT (env); } if (transaction->flags & RCD_TRANSACTION_FLAGS_DOWNLOAD_ONLY) { RCD_XMLRPC_STRUCT_SET_INT (env, xtrans, "preposition", 1); XMLRPC_FAIL_IF_FAULT (env); } xmanifests = xmlrpc_build_value (env, "()"); XMLRPC_FAIL_IF_FAULT (env); xmlrpc_struct_set_value (env, xtrans, "patches", xmanifests); XMLRPC_FAIL_IF_FAULT (env); xmlrpc_DECREF (xmanifests); for (iter = transaction->patches; iter; iter = iter->next) { RCYouPatch *p = iter->data; xmlrpc_value *xpatch; xpatch = you_patch_to_xmlrpc (env, p); XMLRPC_FAIL_IF_FAULT (env); xmlrpc_array_append_item (env, xmanifests, xpatch); XMLRPC_FAIL_IF_FAULT (env); xmlrpc_DECREF (xpatch); } cleanup: return xtrans; } /* transaction_xml */
static void test_struct (void) { xmlrpc_env env; xmlrpc_value *s, *i, *i1, *i2, *i3, *key, *value; size_t size; int present; xmlrpc_int32 ival; xmlrpc_bool bval; char *sval; char const weirdKey[] = {'f', 'o', 'o', '\0', 'b', 'a', 'r'}; xmlrpc_env_init(&env); /* Create a struct. */ s = xmlrpc_struct_new(&env); TEST_NO_FAULT(&env); TEST(s != NULL); TEST(XMLRPC_TYPE_STRUCT == xmlrpc_value_type(s)); size = xmlrpc_struct_size(&env, s); TEST_NO_FAULT(&env); TEST(size == 0); /* Create some elements to insert into our struct. */ i1 = xmlrpc_build_value(&env, "s", "Item #1"); TEST_NO_FAULT(&env); i2 = xmlrpc_build_value(&env, "s", "Item #2"); TEST_NO_FAULT(&env); i3 = xmlrpc_build_value(&env, "s", "Item #3"); TEST_NO_FAULT(&env); /* Insert a single item. */ xmlrpc_struct_set_value(&env, s, "foo", i1); TEST_NO_FAULT(&env); size = xmlrpc_struct_size(&env, s); TEST_NO_FAULT(&env); TEST(size == 1); /* Insert two more items with conflicting hash codes. (We assume that ** nobody has changed the hash function.) */ xmlrpc_struct_set_value(&env, s, "bar", i2); TEST_NO_FAULT(&env); xmlrpc_struct_set_value(&env, s, "aas", i3); TEST_NO_FAULT(&env); size = xmlrpc_struct_size(&env, s); TEST_NO_FAULT(&env); TEST(size == 3); /* Replace an existing element with a different element. */ xmlrpc_struct_set_value(&env, s, "aas", i1); TEST_NO_FAULT(&env); size = xmlrpc_struct_size(&env, s); TEST_NO_FAULT(&env); TEST(size == 3); /* Insert an item with a NUL in the key */ xmlrpc_struct_set_value_n(&env, s, weirdKey, sizeof(weirdKey), i2); TEST_NO_FAULT(&env); size = xmlrpc_struct_size(&env, s); TEST_NO_FAULT(&env); TEST(size == 4); test_struct_get_element(s, i1, i2, weirdKey, sizeof(weirdKey)); /* Replace an existing element with the same element (tricky). */ xmlrpc_struct_set_value(&env, s, "aas", i1); TEST_NO_FAULT(&env); size = xmlrpc_struct_size(&env, s); TEST_NO_FAULT(&env); TEST(size == 4); i = xmlrpc_struct_get_value(&env, s, "aas"); TEST_NO_FAULT(&env); TEST(i == i1); /* Test for the presence and absence of elements. */ present = xmlrpc_struct_has_key(&env, s, "aas"); TEST_NO_FAULT(&env); TEST(present); present = xmlrpc_struct_has_key(&env, s, "bogus"); TEST_NO_FAULT(&env); TEST(!present); /* Make sure our typechecks work correctly. */ xmlrpc_struct_size(&env, i1); TEST_FAULT(&env, XMLRPC_TYPE_ERROR); xmlrpc_struct_has_key(&env, i1, "foo"); TEST_FAULT(&env, XMLRPC_TYPE_ERROR); xmlrpc_struct_set_value(&env, i1, "foo", i2); TEST_FAULT(&env, XMLRPC_TYPE_ERROR); xmlrpc_struct_set_value_v(&env, s, s, i2); TEST_FAULT(&env, XMLRPC_TYPE_ERROR); /* Test cleanup code (w/memprof). */ xmlrpc_DECREF(s); /* Build a struct using our automagic struct builder. */ s = xmlrpc_build_value(&env, "{s:s,s:i,s:b}", "foo", "Hello!", "bar", (xmlrpc_int32) 1, "baz", (xmlrpc_bool) 0); TEST_NO_FAULT(&env); TEST(s != NULL); TEST(XMLRPC_TYPE_STRUCT == xmlrpc_value_type(s)); size = xmlrpc_struct_size(&env, s); TEST_NO_FAULT(&env); TEST(size == 3); present = xmlrpc_struct_has_key(&env, s, "foo"); TEST_NO_FAULT(&env); TEST(present); present = xmlrpc_struct_has_key(&env, s, "bar"); TEST_NO_FAULT(&env); TEST(present); present = xmlrpc_struct_has_key(&env, s, "baz"); TEST_NO_FAULT(&env); TEST(present); i = xmlrpc_struct_get_value(&env, s, "baz"); TEST_NO_FAULT(&env); xmlrpc_decompose_value(&env, i, "b", &bval); TEST_NO_FAULT(&env); TEST(!bval); testStructReadout(s, 3); /* Test our automagic struct parser. */ xmlrpc_decompose_value(&env, s, "{s:b,s:s,s:i,*}", "baz", &bval, "foo", &sval, "bar", &ival); TEST_NO_FAULT(&env); TEST(ival == 1); TEST(!bval); TEST(strcmp(sval, "Hello!") == 0); free(sval); /* Test automagic struct parser with value of wrong type. */ xmlrpc_decompose_value(&env, s, "{s:b,s:i,*}", "baz", &bval, "foo", &sval); TEST_FAULT(&env, XMLRPC_TYPE_ERROR); /* Test automagic struct parser with bad key. */ xmlrpc_decompose_value(&env, s, "{s:b,s:i,*}", "baz", &bval, "nosuch", &sval); TEST_FAULT(&env, XMLRPC_INDEX_ERROR); /* Test type check. */ xmlrpc_struct_get_key_and_value(&env, i1, 0, &key, &value); TEST_FAULT(&env, XMLRPC_TYPE_ERROR); TEST(key == NULL && value == NULL); /* Test bounds checks. */ xmlrpc_struct_get_key_and_value(&env, s, -1, &key, &value); TEST_FAULT(&env, XMLRPC_INDEX_ERROR); TEST(key == NULL && value == NULL); xmlrpc_struct_get_key_and_value(&env, s, 3, &key, &value); TEST_FAULT(&env, XMLRPC_INDEX_ERROR); TEST(key == NULL && value == NULL); /* Test cleanup code (w/memprof). */ xmlrpc_DECREF(s); xmlrpc_DECREF(i1); xmlrpc_DECREF(i2); xmlrpc_DECREF(i3); xmlrpc_env_clean(&env); }