static void
testOneDouble(double const value) {

    /* Test serialize of a double.  */

    xmlrpc_env env;
    xmlrpc_value * valueP;
    xmlrpc_mem_block * serializedP;
    char * result;
        /* serialized result, as asciiz string */
    size_t resultLength;
        /* Length in characters of the serialized result */
    double serializedValue;
    char nextChar;
    int itemsMatched;
    
    xmlrpc_env_init(&env);

    /* Build a double to serialize */
    valueP = xmlrpc_double_new(&env, value);
    TEST_NO_FAULT(&env);
    
    /* Serialize the value. */
    serializedP = XMLRPC_MEMBLOCK_NEW(char, &env, 0);
    TEST_NO_FAULT(&env);
    xmlrpc_serialize_value(&env, serializedP, valueP);
    TEST_NO_FAULT(&env);

    /* Make sure we serialized the correct value.  Note that because
       doubles aren't precise, this might serialize as 3.1415899999
       or something like that.  So we check it arithmetically.
    */
    resultLength = XMLRPC_MEMBLOCK_SIZE(char, serializedP);
    result = malloc(resultLength + 1);

    memcpy(result, XMLRPC_MEMBLOCK_CONTENTS(char, serializedP), resultLength);
    result[resultLength] = '\0';
    
    itemsMatched = sscanf(result, 
                          "<value><double>%lf</double></value>\r\n%c",
                          &serializedValue, &nextChar);

    TEST(itemsMatched == 1);
    TESTFLOATEQUAL(serializedValue, value);

    free(result);
    
    /* Clean up our value. */
    XMLRPC_TYPED_MEM_BLOCK_FREE(char, serializedP);
    xmlrpc_DECREF(valueP);

    xmlrpc_env_clean(&env);
}
int 
main(int           const argc, 
     const char ** const argv) {

    const char * const serverUrl = "http://localhost:8080/RPC2";

    xmlrpc_env env;
    struct xmlrpc_clientparms clientParms;
    xmlrpc_client * clientP;

    if (argc-1 > 0) {
        fprintf(stderr, "This program has no arguments\n");
        exit(1);
    }

    setupSignalHandlers();

    /* Initialize our error-handling environment. */
    xmlrpc_env_init(&env);

    /* Required before any use of Xmlrpc-c client library: */
    xmlrpc_client_setup_global_const(&env);
    die_if_fault_occurred(&env);

    clientParms.transport = "curl";

    /* Create a client object */
    xmlrpc_client_create(&env, 0, NULL, NULL,
                         &clientParms, XMLRPC_CPSIZE(transport),
                         &clientP);

    die_if_fault_occurred(&env);

    xmlrpc_client_set_interrupt(clientP, &interrupt);

    /* If our server is running 'xmlrpc_sample_add_server' normally, the
       RPC will finish almost instantly.  UNLESS the adder is 1, in which
       case said server is programmed to take 3 seconds to do the
       computation, thus allowing us to demonstrate a timeout or CTL-C.
    */

    addInterruptibly(clientP, serverUrl, 5, 7);
        /* Should finish instantly */

    addInterruptibly(clientP, serverUrl, 5, 1);
        /* Should time out after 2 seconds */

    xmlrpc_env_clean(&env);
    xmlrpc_client_destroy(clientP);
    xmlrpc_client_teardown_global_const();

    return 0;
}
예제 #3
0
static void sigtermHandler(int const signalClass) {
    
    xmlrpc_env env;
    
    xmlrpc_env_init(&env);

    xmlrpc_server_abyss_terminate(&env, serverToTerminateP);

    dieIfFailed("xmlrpc_server_abyss_terminate", &env);
    
    xmlrpc_env_clean(&env);
}
예제 #4
0
파일: rcd-rpc.c 프로젝트: joeshaw/rcd
static void
soup_rpc_callback (SoupServerContext *context, SoupMessage *msg, gpointer data)
{
    xmlrpc_env env;
    xmlrpc_mem_block *output;
    const char *username;
    RCDIdentity *identity = NULL;
    RCDRPCMethodData *method_data;

    xmlrpc_env_init (&env);

    method_data = g_new0 (RCDRPCMethodData, 1);

    /* Get the username from the auth context and get its identity */
    username = soup_server_auth_get_user (context->auth);

    if (strcmp (username, rcd_prefs_get_mid ()) == 0) {
        identity = rcd_identity_new ();
        identity->username = g_strdup ("server");
        identity->privileges = rcd_privileges_from_string ("superuser");
    }
    else
        identity = rcd_identity_lookup (username);

    g_assert (identity != NULL);

    method_data->host = soup_server_context_get_client_host (context);
    method_data->identity = identity;

    output = process_rpc_call (
        &env, msg->request.body, msg->request.length, method_data);

    rcd_identity_free (method_data->identity);
    g_free (method_data);

    soup_message_add_header (msg->response_headers,
                             "Server", "Red Carpet Daemon/"VERSION);

    if (env.fault_occurred) {
        soup_message_set_status (msg, SOUP_STATUS_BAD_REQUEST);
        return;
    }

    /* Let Soup free the data for us */
    msg->response.owner = SOUP_BUFFER_SYSTEM_OWNED;
    msg->response.length = XMLRPC_TYPED_MEM_BLOCK_SIZE(char, output);
    msg->response.body = g_memdup(
        XMLRPC_TYPED_MEM_BLOCK_CONTENTS(char, output), msg->response.length);

    soup_message_set_status (msg, SOUP_STATUS_OK);

    xmlrpc_mem_block_free(output);
} /* soup_rpc_callback */
예제 #5
0
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;
	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");

	int rc = 0;
	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("could not allocate memory for 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);
}
예제 #6
0
int main(int argc, char **argv)
{
    abrt_init(argv);

    map_string_h *settings = new_map_string();
    const char *dump_dir_name = ".";
    GList *conf_file = NULL;

    /* Can't keep these strings/structs static: _() doesn't support that */
    const char *program_usage_string = _(
        "\b [-v] -c CONFFILE -d DIR\n"
        "\n"
        "Reports problem to Bugzilla"
    );
    enum {
        OPT_v = 1 << 0,
        OPT_d = 1 << 1,
        OPT_c = 1 << 2,
    };
    /* Keep enum above and order of options below in sync! */
    struct options program_options[] = {
        OPT__VERBOSE(&g_verbose),
        OPT_STRING('d', NULL, &dump_dir_name, "DIR" , _("Dump directory")),
        OPT_LIST(  'c', NULL, &conf_file    , "FILE", _("Configuration file (may be given many times)")),
        OPT_END()
    };
    /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage_string);

    export_abrt_envvars(0);

    while (conf_file)
    {
        char *fn = (char *)conf_file->data;
        VERB1 log("Loading settings from '%s'", fn);
        load_conf_file(fn, settings, /*skip key w/o values:*/ true);
        VERB3 log("Loaded '%s'", fn);
        conf_file = g_list_remove(conf_file, fn);
    }

    VERB1 log("Initializing XML-RPC library");
    xmlrpc_env env;
    xmlrpc_env_init(&env);
    xmlrpc_client_setup_global_const(&env);
    if (env.fault_occurred)
        error_msg_and_die("XML-RPC Fault: %s(%d)", env.fault_string, env.fault_code);
    xmlrpc_env_clean(&env);

    report_to_bugzilla(dump_dir_name, settings);

    free_map_string(settings);
    return 0;
}
예제 #7
0
/**************************************
* XmlHandler
*	Constructor
*************************************/
XmlHandler::XmlHandler()
{
	xmlrpc_env env;

	//Build the enviroment
	xmlrpc_env_init(&env);

	//Creamos el registro
	registry = xmlrpc_registry_new(&env);

	//Clean env
	xmlrpc_env_clean(&env);
}
예제 #8
0
파일: rhbz.c 프로젝트: mgorny/libreport
/* The only way this can fail is if arrayP is not actually an array XML-RPC
 * value. So it is usually not worth checking *envP.
 * die or return size of array
 */
unsigned rhbz_array_size(xmlrpc_value *xml)
{
    func_entry();

    xmlrpc_env env;
    xmlrpc_env_init(&env);

    unsigned size = xmlrpc_array_size(&env, xml);
    if (env.fault_occurred)
        abrt_xmlrpc_die(&env);

    return size;
}
예제 #9
0
static void
processCall(TSession *        const abyssSessionP,
            size_t            const contentSize,
            xmlrpc_registry * const registryP,
            bool              const wantChunk,
            const char *      const trace) {
/*----------------------------------------------------------------------------
   Handle an RPC request.  This is an HTTP request that has the proper form
   to be an XML-RPC call.

   The text of the call is available through the Abyss session
   'abyssSessionP'.

   Its content length is 'contentSize' bytes.
-----------------------------------------------------------------------------*/
    xmlrpc_env env;

    if (trace)
        fprintf(stderr,
                "xmlrpc_server_abyss URI path handler processing RPC.\n");

    xmlrpc_env_init(&env);

    if (contentSize > xmlrpc_limit_get(XMLRPC_XML_SIZE_LIMIT_ID))
        xmlrpc_env_set_fault_formatted(
            &env, XMLRPC_LIMIT_EXCEEDED_ERROR,
            "XML-RPC request too large (%d bytes)", contentSize);
    else {
        xmlrpc_mem_block * body;
        /* Read XML data off the wire. */
        getBody(&env, abyssSessionP, contentSize, trace, &body);
        if (!env.fault_occurred) {
            xmlrpc_mem_block * output;
            /* Process the RPC. */
            xmlrpc_registry_process_call2(
                &env, registryP,
                XMLRPC_MEMBLOCK_CONTENTS(char, body),
                XMLRPC_MEMBLOCK_SIZE(char, body),
                abyssSessionP,
                &output);
            if (!env.fault_occurred) {
                /* Send out the result. */
                sendXmlData(&env, abyssSessionP, 
                            XMLRPC_MEMBLOCK_CONTENTS(char, output),
                            XMLRPC_MEMBLOCK_SIZE(char, output),
                            wantChunk);
                
                XMLRPC_MEMBLOCK_FREE(char, output);
            }
            XMLRPC_MEMBLOCK_FREE(char, body);
        }
int 
main(int           const argc, 
     const char ** const argv) {

    struct xmlrpc_method_info3 const methodInfo = {
        /* .methodName     = */ "sample.add",
        /* .methodFunction = */ &sample_add,
    };
    xmlrpc_server_abyss_parms serverparm;
    xmlrpc_registry * registryP;
    xmlrpc_env env;

    if (argc-1 != 1) {
        fprintf(stderr, "You must specify 1 argument:  The TCP port "
                "number on which the server will accept connections "
                "for RPCs (8080 is a common choice).  "
                "You specified %d arguments.\n",  argc-1);
        exit(1);
    }
    
    xmlrpc_env_init(&env);

    registryP = xmlrpc_registry_new(&env);
    if (env.fault_occurred) {
        printf("xmlrpc_registry_new() failed.  %s\n", env.fault_string);
        exit(1);
    }

    xmlrpc_registry_add_method3(&env, registryP, &methodInfo);
    if (env.fault_occurred) {
        printf("xmlrpc_registry_add_method3() failed.  %s\n",
               env.fault_string);
        exit(1);
    }

    serverparm.config_file_name = NULL;   /* Select the modern normal API */
    serverparm.registryP        = registryP;
    serverparm.port_number      = atoi(argv[1]);
    serverparm.log_file_name    = "/tmp/xmlrpc_log";

    printf("Running XML-RPC server...\n");

    xmlrpc_server_abyss(&env, &serverparm, XMLRPC_APSIZE(log_file_name));
    if (env.fault_occurred) {
        printf("xmlrpc_server_abyss() failed.  %s\n", env.fault_string);
        exit(1);
    }
    /* xmlrpc_server_abyss() never returns unless it fails */

    return 0;
}
예제 #11
0
static void
test_value_string_wide_line(void) {
        /* Test with various line delimiters */

#if HAVE_UNICODE_WCHAR
    xmlrpc_env env;
    xmlrpc_value * valueP;
    const wchar_t * wcs;
    size_t len;

    wchar_t const wcs_lines[] = {'\n', '\r', '\r', '\n', '\0'};
    wchar_t const wcs_lines_lf[] = {'\n', '\n', '\n'};
    wchar_t const wcs_lines_crlf[] = {
        '\r', '\n', '\r', '\n', '\r', '\n' };
        
    xmlrpc_env_init(&env);

    valueP = xmlrpc_string_w_new(&env, wcs_lines);
    TEST_NO_FAULT(&env);

    xmlrpc_read_string_w_lp(&env, valueP, &len, &wcs);
    TEST_NO_FAULT(&env);
    TEST(len == 3);
    TEST(wcs[len] == '\0');
    TEST(wcsneq(wcs, wcs_lines_lf, len));
    free((void*)wcs);

    xmlrpc_read_string_w_lp_crlf(&env, valueP, &len, &wcs);
    TEST_NO_FAULT(&env);
    TEST(len == 6);
    TEST(wcs[len] == '\0');
    TEST(wcsneq(wcs, wcs_lines_crlf, len));
    free((void*)wcs);

    xmlrpc_DECREF(valueP);

    valueP = xmlrpc_string_w_new_cr(&env, wcs_lines);
    TEST_NO_FAULT(&env);

    xmlrpc_read_string_w_lp(&env, valueP, &len, &wcs);
    TEST_NO_FAULT(&env);
    TEST(len == 4);
    TEST(wcs[len] == '\0');
    TEST(wcsneq(wcs, wcs_lines, len));
    free((void*)wcs);

    xmlrpc_DECREF(valueP);

    xmlrpc_env_clean(&env);
#endif /* HAVE_UNICODE_WCHAR */
}
예제 #12
0
static void
test_xml_size_limit(void) {

    xmlrpc_env env;
    const char * methodName;
    xmlrpc_value * paramsP;
    
    /* NOTE - This test suite only verifies the last-ditch size-checking
       code.  There should also be matching code in all server (and
       preferably all client) modules as well.
    */

    /* Set our XML size limit to something ridiculous. */
    xmlrpc_limit_set(XMLRPC_XML_SIZE_LIMIT_ID, 6);
    
    /* Attempt to parse a call. */
    xmlrpc_env_init(&env);
    xmlrpc_parse_call(&env, serialized_call, strlen(serialized_call),
                      &methodName, &paramsP);
    TEST_FAULT(&env, XMLRPC_LIMIT_EXCEEDED_ERROR);
    xmlrpc_env_clean(&env);

    {
        xmlrpc_value * resultP;
        int faultCode;
        const char * faultString;

        /* Attempt to parse a response. */
        xmlrpc_env_init(&env);
        xmlrpc_parse_response2(&env,
                               good_response_xml, strlen(good_response_xml),
                               &resultP, &faultCode, &faultString);
        TEST_FAULT(&env, XMLRPC_LIMIT_EXCEEDED_ERROR);
        xmlrpc_env_clean(&env);
    }
    /* Reset the default limit. */
    xmlrpc_limit_set(XMLRPC_XML_SIZE_LIMIT_ID, XMLRPC_XML_SIZE_LIMIT_DEFAULT);
}
예제 #13
0
파일: pike_top.c 프로젝트: 4N7HR4X/kamailio
/* FIXME terminates the program if it fails */
int get_int_from_struct_by_idx(xmlrpc_value *structP, int index, int *rv)
{
	xmlrpc_env env;
	xmlrpc_env_init(&env);
	xmlrpc_value *keyP;
	xmlrpc_value *valueP;
	
	xmlrpc_struct_read_member(&env, structP, index, &keyP, &valueP);            /* increment refcount of returned values */
	die_if_fault_occurred_line(&env, __LINE__);
	xmlrpc_read_int(&env, valueP, rv);
	die_if_fault_occurred_line(&env, __LINE__);
	xmlrpc_DECREF(valueP);
	return 1;
}
예제 #14
0
static void
test_value_type_mismatch(void) {

    xmlrpc_value * v;
    xmlrpc_env env;
    xmlrpc_env env2;
    char * str;

    /* Test for one, simple kind of type mismatch error. We assume that
    ** if one of these typechecks works, the rest work fine. */

    xmlrpc_env_init(&env);
    xmlrpc_env_init(&env2);

    v = xmlrpc_build_value(&env, "i", (xmlrpc_int32) 5);
    TEST_NO_FAULT(&env);
    xmlrpc_decompose_value(&env2, v, "s", &str);
    xmlrpc_DECREF(v);
    TEST_FAULT(&env2, XMLRPC_TYPE_ERROR);

    xmlrpc_env_clean(&env2);
    xmlrpc_env_clean(&env);
}
예제 #15
0
static void
test_value_missing_struct_delim(void) {

    xmlrpc_value * v;
    xmlrpc_env env;
    
    /* Test missing closing brace on struct */

    xmlrpc_env_init(&env);
    v = xmlrpc_build_value(&env, "{");
    TEST_FAULT(&env, XMLRPC_INTERNAL_ERROR);
    xmlrpc_env_clean(&env);

    xmlrpc_env_init(&env);
    v = xmlrpc_build_value(&env, "{s:i", "key1", 7);
    TEST_FAULT(&env, XMLRPC_INTERNAL_ERROR);
    xmlrpc_env_clean(&env);

    xmlrpc_env_init(&env);
    v = xmlrpc_build_value(&env, "{s:i,s:i", "key1", 9, "key2", -4);
    TEST_FAULT(&env, XMLRPC_INTERNAL_ERROR);
    xmlrpc_env_clean(&env);
}
예제 #16
0
/**************************************
* XmlHandler
*	A�ade un metodo
*************************************/
int XmlHandler::AddMethod(const char *name,xmlrpc_method method,void *user_data)
{
	xmlrpc_env env;

	//Build the enviroment
	xmlrpc_env_init(&env);

	//Add Methods
	xmlrpc_registry_add_method(&env, registry, NULL, name, method, user_data);
 	//xmlrpc_registry_add_method_w_doc( &env, registry, NULL, method_name, method, user_data, signature, help);

	//Salimos
	return !env.fault_occurred;
}
예제 #17
0
파일: rcd-rpc.c 프로젝트: joeshaw/rcd
static xmlrpc_mem_block *
serialize_fault (int fault_code, const char *fault_string)
{
    xmlrpc_env tmp_env;
    xmlrpc_env fault;
    xmlrpc_mem_block *output;

    xmlrpc_env_init (&tmp_env);
    xmlrpc_env_init (&fault);

    output = xmlrpc_mem_block_new (&tmp_env, 0);
    XMLRPC_FAIL_IF_FAULT (&tmp_env);

    xmlrpc_env_set_fault (&fault, fault_code, (char *) fault_string);

    xmlrpc_serialize_fault (&tmp_env, output, &fault);
    XMLRPC_FAIL_IF_FAULT (&tmp_env);

    return output;

cleanup:
    return NULL;
} /* serialize_fault */
예제 #18
0
파일: pike_top.c 프로젝트: 4N7HR4X/kamailio
/* FIXME terminates the programm if it fails  */
int get_string_from_struct_by_name(xmlrpc_value *structP, const char *element_name, char **rv)
{
	xmlrpc_env env;
	xmlrpc_env_init(&env);
	xmlrpc_value *valueP;
	int length;
	
	xmlrpc_struct_find_value(&env, structP, element_name, &valueP);
	die_if_fault_occurred_line(&env, __LINE__);
	xmlrpc_read_string(&env, valueP, (const char **)rv);
	die_if_fault_occurred_line(&env, __LINE__);
	xmlrpc_DECREF(valueP);
	return 1;
}
예제 #19
0
void init_xmlrpc(const char* url)
{
  if (url != NULL)
    ubigraph_url = url;

  /* 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);
  die_if_fault_occurred(&env);

  xmlrpc_initialized = 1;
}
예제 #20
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;
}
예제 #21
0
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;
}
예제 #22
0
static void
test_parse_xml_call(void) {

    xmlrpc_env env;
    const char *method_name;
    xmlrpc_value *params;
    int i1, i2;
    const char **bad_call;
    xml_element *elem;

    xmlrpc_env_init(&env);

    /* Parse a valid call. */
    xmlrpc_parse_call(&env, serialized_call, strlen(serialized_call),
                      &method_name, &params);
    TEST_NO_FAULT(&env);
    TEST(params != NULL);
    xmlrpc_decompose_value(&env, params, "(ii)", &i1, &i2);
    xmlrpc_DECREF(params);    
    TEST_NO_FAULT(&env);
    TEST(streq(method_name, "gloom&doom"));
    TEST(i1 == 10 && i2 == 20);
    strfree(method_name);

    /* Test some poorly-formed XML data. */
    xmlrpc_parse_call(&env, unparseable_value, strlen(unparseable_value),
                      &method_name, &params);
    TEST_FAULT(&env, XMLRPC_PARSE_ERROR);
    TEST(method_name == NULL && params == NULL);

    /* Next, check for bogus values. These are all well-formed XML, but
       they aren't legal XML-RPC.
    */
    for (bad_call = bad_calls; *bad_call != NULL; ++bad_call) {
    
        /* First, check to make sure that our test case is well-formed XML.
        ** (It's easy to make mistakes when writing the test cases!) */
        xml_parse(&env, *bad_call, strlen(*bad_call), &elem);
        TEST_NO_FAULT(&env);
        xml_element_free(elem);

        /* Now, make sure the higher-level routine barfs appropriately. */
        xmlrpc_parse_call(&env, *bad_call, strlen(*bad_call),
                          &method_name, &params);
        TEST_FAULT(&env, XMLRPC_PARSE_ERROR);
        TEST(method_name == NULL && params == NULL);
    }
    xmlrpc_env_clean(&env);    
}
예제 #23
0
static void
test_value_AS_typecheck(void) {

    xmlrpc_env env;
    xmlrpc_env env2;
    xmlrpc_value *v;
    xmlrpc_value *v2;

    /* Test typechecks for 'A' and 'S'. */

    xmlrpc_env_init(&env);
    xmlrpc_env_init(&env2);

    v = xmlrpc_build_value(&env, "s", "foo");
    TEST_NO_FAULT(&env);
    xmlrpc_decompose_value(&env2, v, "A", &v2);
    TEST_FAULT(&env2, XMLRPC_TYPE_ERROR);

    xmlrpc_decompose_value(&env2, v, "S", &v2);
    TEST_FAULT(&env2, XMLRPC_TYPE_ERROR);
    xmlrpc_DECREF(v);
    xmlrpc_env_clean(&env2);
    xmlrpc_env_clean(&env);
}
예제 #24
0
static void
makeSignatureList(xmlrpc_env *            const envP,
                  const char *            const signatureString,
                  xmlrpc_signatureList ** const signatureListPP) {

    xmlrpc_env env;

    xmlrpc_env_init(&env);

    signatureListCreate(&env, signatureString, signatureListPP);

    if (env.fault_occurred)
        xmlrpc_faultf(envP, "Can't interpret signature string '%s'.  %s",
                      signatureString, env.fault_string);
}
예제 #25
0
static void
test_value_invalid_type(void) {

    xmlrpc_value * v;
    xmlrpc_env env;

    /* Test invalid type specifier in format string */

    xmlrpc_env_init(&env);

    v = xmlrpc_build_value(&env, "Q");
    TEST_FAULT(&env, XMLRPC_INTERNAL_ERROR);

    xmlrpc_env_clean(&env);
}
예제 #26
0
static void
interpretFaultCode(xmlrpc_env *   const envP,
                   xmlrpc_value * const faultCodeVP,
                   int *          const faultCodeP) {
                   
    xmlrpc_env fcEnv;
    xmlrpc_env_init(&fcEnv);

    xmlrpc_read_int(&fcEnv, faultCodeVP, faultCodeP);
    if (fcEnv.fault_occurred)
        xmlrpc_faultf(envP, "Invalid value for 'faultCode' member.  %s",
                      fcEnv.fault_string);

    xmlrpc_env_clean(&fcEnv);
}
예제 #27
0
void
xmlrpc_parse_value_xml(xmlrpc_env *    const envP,
                       const char *    const xmlData,
                       size_t          const xmlDataLen,
                       xmlrpc_value ** const valuePP) {
/*----------------------------------------------------------------------------
   Compute the xmlrpc_value represented by the XML document 'xmlData' (of
   length 'xmlDataLen' characters), which must consist of a single <value>
   element.  Return that xmlrpc_value.

   We call convert_array() and convert_struct(), which may ultimately
   call us recursively.  Don't recurse any more than 'maxRecursion'
   times.

   This isn't generally useful in XML-RPC programs, because such programs
   parse a whole XML-RPC call or response document, and never see the XML text
   of just a <value> element.  But a program may do some weird form of XML-RPC
   processing or just borrow Xmlrpc-c's value serialization facilities for
   something unrelated to XML-RPC.  In any case, it makes sense to have an
   inverse of xmlrpc_serialize_value2(), which generates XML text from an
   xmlrpc_value.
-----------------------------------------------------------------------------*/
    xmlrpc_env env;

    xml_element * valueEltP;

    XMLRPC_ASSERT_ENV_OK(envP);
    XMLRPC_ASSERT(xmlData != NULL);

    xmlrpc_env_init(&env);

    xml_parse(&env, xmlData, xmlDataLen, &valueEltP);

    if (env.fault_occurred) {
        setParseFault(envP, "Not valid XML.  %s", env.fault_string);
    } else {
        if (xmlrpc_streq(xml_element_name(valueEltP), "value")) {
            unsigned int const maxRecursion = (unsigned int)
                xmlrpc_limit_get(XMLRPC_NESTING_LIMIT_ID);
            xmlrpc_parseValue(envP, maxRecursion, valueEltP, valuePP);
        } else
            setParseFault(envP, "XML-RPC value XML document must consist of "
                          "a <value> element.  This has a <%s> instead.",
                          xml_element_name(valueEltP));
        xml_element_free(valueEltP);
    }
    xmlrpc_env_clean(&env);
}
예제 #28
0
int 
main(int           const argc, 
     const char ** const argv) {

    struct cmdlineInfo cmdline;
    xmlrpc_env env;
    xmlrpc_mem_block * callXmlP;
    xmlrpc_mem_block * respXmlP;
    const char * url;
    xmlrpc_server_info * serverInfoP;

    xmlrpc_env_init(&env);

    parseCommandLine(&env, argc, argv, &cmdline);
    die_if_fault_occurred(&env);

    computeUrl(cmdline.url, &url);

    createServerInfo(&env, url, cmdline.username, cmdline.password,
                     &serverInfoP);
    die_if_fault_occurred(&env);

    fprintf(stderr, "Reading call data from Standard Input...\n");

    readFile(&env, stdin, &callXmlP);
    die_if_fault_occurred(&env);

    fprintf(stderr, "Making call...\n");

    doCall(&env, cmdline.transport, serverInfoP, callXmlP,
           &respXmlP);
    die_if_fault_occurred(&env);

    fprintf(stderr, "Writing response data to Standard Output\n");
    writeFile(&env, stdout, respXmlP);
    die_if_fault_occurred(&env);

    XMLRPC_MEMBLOCK_FREE(char, callXmlP);
    XMLRPC_MEMBLOCK_FREE(char, respXmlP);
    
    strfree(url);

    freeCmdline(cmdline);

    xmlrpc_env_clean(&env);
    
    return 0;
}
예제 #29
0
static void
test_value_array_nil(void) {

    xmlrpc_value * arrayP;
    xmlrpc_env env;
    xmlrpc_int32 i1, i2;
    xmlrpc_value * itemP;
    size_t len;

    xmlrpc_env_init(&env);

    arrayP = xmlrpc_build_value(&env, "(nini)",
                                (xmlrpc_int32) 10, (xmlrpc_int32) 20);
    TEST_NO_FAULT(&env);
    TEST(XMLRPC_TYPE_ARRAY == xmlrpc_value_type(arrayP));

    len = xmlrpc_array_size(&env, arrayP);
    TEST_NO_FAULT(&env);
    TEST(len == 4);

    itemP = xmlrpc_array_get_item(&env, arrayP, 0);
    TEST_NO_FAULT(&env);
    xmlrpc_decompose_value(&env, itemP, "n");
    TEST_NO_FAULT(&env);

    itemP = xmlrpc_array_get_item(&env, arrayP, 1);
    TEST_NO_FAULT(&env);
    {
        int i;
        xmlrpc_decompose_value(&env, itemP, "i", &i);
        TEST_NO_FAULT(&env);
        TEST(i == 10);
    }
    xmlrpc_decompose_value(&env, arrayP, "(nini)", &i1, &i2);
    TEST_NO_FAULT(&env);
    TEST(i1 == 10 && i2 == 20);

    /* Test bounds check on xmlrpc_array_get_item. */
    xmlrpc_array_read_item(&env, arrayP, 4, &itemP);
    TEST_FAULT(&env, XMLRPC_INDEX_ERROR);

    xmlrpc_array_get_item(&env, arrayP, 4);
    TEST_FAULT(&env, XMLRPC_INDEX_ERROR);

    xmlrpc_DECREF(arrayP);

    xmlrpc_env_clean(&env);
}
예제 #30
0
static void
interpretFaultString(xmlrpc_env *   const envP,
                     xmlrpc_value * const faultStringVP,
                     const char **  const faultStringP) {

    xmlrpc_env fsEnv;
    xmlrpc_env_init(&fsEnv);

    xmlrpc_read_string(&fsEnv, faultStringVP, faultStringP);

    if (fsEnv.fault_occurred)
        xmlrpc_faultf(envP, "Invalid value for 'faultString' member.  %s",
                      fsEnv.fault_string);

    xmlrpc_env_clean(&fsEnv);
}