static void
test_value_integer(void) { 

    xmlrpc_value * v;
    xmlrpc_env env;
    xmlrpc_int32 i;

    xmlrpc_env_init(&env);

    v = xmlrpc_int_new(&env, (xmlrpc_int32) 25);
    TEST_NO_FAULT(&env);
    TEST(XMLRPC_TYPE_INT == xmlrpc_value_type(v));
    xmlrpc_read_int(&env, v, &i);
    TEST_NO_FAULT(&env);
    TEST(i == 25);
    xmlrpc_DECREF(v);

    v = xmlrpc_build_value(&env, "i", (xmlrpc_int32) 10);
    TEST_NO_FAULT(&env);
    TEST(v != NULL);
    TEST(XMLRPC_TYPE_INT == xmlrpc_value_type(v));
    xmlrpc_decompose_value(&env, v, "i", &i);
    xmlrpc_DECREF(v);
    TEST_NO_FAULT(&env);
    TEST(i == 10);

    xmlrpc_env_clean(&env);
}
static void
parseInt(xmlrpc_env *    const envP,
         const char *    const str,
         xmlrpc_value ** const valuePP) {
/*----------------------------------------------------------------------------
   Parse the content of a <int> XML-RPC XML element, e.g. "34".

   'str' is that content.
-----------------------------------------------------------------------------*/
    XMLRPC_ASSERT_ENV_OK(envP);
    XMLRPC_ASSERT_PTR_OK(str);

    if (str[0] == '\0')
        setParseFault(envP, "<int> XML element content is empty");
    else if (isspace(str[0]))
        setParseFault(envP, "<int> content '%s' starts with white space",
                      str);
    else {
        long i;
        char * tail;

        errno = 0;
        i = strtol(str, &tail, 10);

        /* Look for ERANGE. */
        if (errno == ERANGE)
            setParseFault(envP, "<int> XML element value '%s' represents a "
                          "number beyond the range that "
                          "XML-RPC allows (%d - %d)", str,
                          XMLRPC_INT32_MIN, XMLRPC_INT32_MAX);
        else if (errno != 0)
            setParseFault(envP, "unexpected error parsing <int> XML element "
                          "value '%s'.  strtol() failed with errno %d (%s)",
                          str, errno, strerror(errno));
        else {
            /* Look for out-of-range errors which didn't produce ERANGE. */
            if (i < XMLRPC_INT32_MIN)
                setParseFault(envP,
                              "<int> value %ld is below the range allowed "
                              "by XML-RPC (minimum is %d)",
                              i, XMLRPC_INT32_MIN);
            else if (i > XMLRPC_INT32_MAX)
                setParseFault(envP,
                              "<int> value %ld is above the range allowed "
                              "by XML-RPC (maximum is %d)",
                              i, XMLRPC_INT32_MAX);
            else {
                if (tail[0] != '\0')
                    setParseFault(envP,
                                  "<int> value '%s' contains non-numerical "
                                  "junk: '%s'", str, tail);
                else
                    *valuePP = xmlrpc_int_new(envP, i);
            }
        }
    }
}
/****************************************************************************
**  Set result for the caller.  These procedures are used in the method
**  implementation to create a result object and append values.  The 
**  server then unpacks the result array when building the array for
**  the return.
*****************************************************************************
*/
void
xr_setIntInResult (void *data, int val)
{
    CallerP c = (Caller *) data;

    if (c->result)
	xmlrpc_DECREF (c->result);
    if (!xr_errstat)
        c->result = xmlrpc_int_new (c->env, val);
}
Exemple #4
0
void
xmlrpc_set_struct_int( xmlrpc_env * const envP,
			xmlrpc_value *pstruct, 
			const char *key,
			int val )
{
	xmlrpc_value *int_val = xmlrpc_int_new( envP, val );
	assertValue( int_val );

	xmlrpc_struct_set_value( envP, pstruct, key, int_val );
	xmlrpc_DECREF( int_val );
}
Exemple #5
0
static void
test_build_decomp_datetime(void) {

    const char * datestring = "19980717T14:08:55";
    time_t const datetime = 900684535;

    xmlrpc_env env;
    xmlrpc_value * v;
    time_t dt;
    const char * ds;

    xmlrpc_env_init(&env);

    v = xmlrpc_build_value(&env, "t", datetime);
    TEST_NO_FAULT(&env);
    TEST(v != NULL);
    TEST(xmlrpc_value_type(v) == XMLRPC_TYPE_DATETIME);

    dt = 0;
    xmlrpc_read_datetime_sec(&env, v, &dt);
    TEST(dt == datetime);

    dt = 0;
    xmlrpc_decompose_value(&env, v, "t", &dt);
    xmlrpc_DECREF(v);
    TEST_NO_FAULT(&env);
    TEST(dt == datetime);

    v = xmlrpc_int_new(&env, 9);
    TEST_NO_FAULT(&env);
    xmlrpc_decompose_value(&env, v, "t", &dt);
    TEST_FAULT(&env, XMLRPC_TYPE_ERROR);
    xmlrpc_env_clean(&env);
    xmlrpc_env_init(&env);
    xmlrpc_decompose_value(&env, v, "8", &ds);
    TEST_FAULT(&env, XMLRPC_TYPE_ERROR);
    xmlrpc_env_clean(&env);
    xmlrpc_env_init(&env);
    xmlrpc_DECREF(v);

    v = xmlrpc_build_value(&env, "8", datestring);
    TEST_NO_FAULT(&env);
    TEST(v != NULL);
    TEST(xmlrpc_value_type(v) == XMLRPC_TYPE_DATETIME);
    xmlrpc_decompose_value(&env, v, "8", &ds);
    xmlrpc_DECREF(v);
    TEST_NO_FAULT(&env);
    TEST(streq(ds, datestring));
    strfree(ds);

    xmlrpc_env_clean(&env);
}
Exemple #6
0
static void
test_value_array(void) {

    xmlrpc_value *v;
    xmlrpc_env env;
    size_t len;
    xmlrpc_value * itemP;

    /* Basic array-building test. */

    xmlrpc_env_init(&env);

    TEST(streq(xmlrpc_type_name(XMLRPC_TYPE_ARRAY), "ARRAY"));

    v = xmlrpc_array_new(&env);
    TEST_NO_FAULT(&env);
    TEST(XMLRPC_TYPE_ARRAY == xmlrpc_value_type(v));
    len = xmlrpc_array_size(&env, v);
    TEST_NO_FAULT(&env);
    TEST(len == 0);

    itemP = xmlrpc_int_new(&env, 7);
    TEST_NO_FAULT(&env);
    xmlrpc_array_append_item(&env, v, itemP);
    TEST_NO_FAULT(&env);
    len = xmlrpc_array_size(&env, v);
    TEST_NO_FAULT(&env);
    TEST(len == 1);
    xmlrpc_DECREF(itemP);

    xmlrpc_DECREF(v);

    v = xmlrpc_build_value(&env, "()");
    TEST_NO_FAULT(&env);
    TEST(XMLRPC_TYPE_ARRAY == xmlrpc_value_type(v));
    len = xmlrpc_array_size(&env, v);
    TEST_NO_FAULT(&env);
    TEST(len == 0);
    xmlrpc_DECREF(v);

    xmlrpc_env_clean(&env);
}
Exemple #7
0
static void
test_value_value(void) {

    xmlrpc_value *v, *v2, *v3;
    xmlrpc_env env;

    /* Test 'V' with building and parsing. */

    xmlrpc_env_init(&env);

    v2 = xmlrpc_int_new(&env, (xmlrpc_int32) 5);
    TEST_NO_FAULT(&env);
    v = xmlrpc_build_value(&env, "V", v2);
    TEST_NO_FAULT(&env);
    TEST(v == v2);
    xmlrpc_decompose_value(&env, v2, "V", &v3);
    xmlrpc_DECREF(v);
    TEST_NO_FAULT(&env);
    TEST(v2 == v3);
    xmlrpc_DECREF(v3);
    xmlrpc_DECREF(v2);

    xmlrpc_env_clean(&env);
}
Exemple #8
0
static xmlrpc_value * method_get_reports(xmlrpc_env * const env,
		   xmlrpc_value * const param_array,
		   void * const user_data)
{
	int has_more;
	xmlrpc_value *ret = 0, *item = 0;

	UNUSED_ARGUMENT(param_array);
	UNUSED_ARGUMENT(user_data);

	DEBUG_MSG(LOG_NOTICE, "Method get_reports called");

	struct _report *report = get_reports(&has_more);

	ret = xmlrpc_array_new(env);

	/* Add information if there's more reports pending */
	item = xmlrpc_int_new(env, has_more);
	xmlrpc_array_append_item(env, ret, item);
	xmlrpc_DECREF(item);

	while (report) {
		xmlrpc_value *rv = xmlrpc_build_value(env,
			"("
			"{s:i,s:i,s:i,s:i,s:i,s:i}" /* timeval */
			"{s:i,s:i,s:i,s:i}" /* bytes */
			"{s:i,s:i,s:i,s:i}" /* block counts */
			"{s:d,s:d,s:d,s:d,s:d,s:d,s:d,s:d,s:d}" /* RTT, IAT, Delay */
			"{s:i,s:i}" /* MTU */
			"{s:i,s:i,s:i,s:i,s:i}" /* TCP info */
			"{s:i,s:i,s:i,s:i,s:i}" /* ...      */
			"{s:i,s:i,s:i,s:i,s:i}" /* ...      */
			"{s:i}"
			")",

			"id", report->id,
			"type", report->type,
			"begin_tv_sec", (int)report->begin.tv_sec,
			"begin_tv_nsec", (int)report->begin.tv_nsec,
			"end_tv_sec", (int)report->end.tv_sec,
			"end_tv_nsec", (int)report->end.tv_nsec,

			"bytes_read_high", (int32_t)(report->bytes_read >> 32),
			"bytes_read_low", (int32_t)(report->bytes_read & 0xFFFFFFFF),
			"bytes_written_high", (int32_t)(report->bytes_written >> 32),
			"bytes_written_low", (int32_t)(report->bytes_written & 0xFFFFFFFF),

			"request_blocks_read", report->request_blocks_read,
			"request_blocks_written", report->request_blocks_written,
			"response_blocks_read", report->response_blocks_read,
			"response_blocks_written", report->response_blocks_written,

			"rtt_min", report->rtt_min,
			"rtt_max", report->rtt_max,
			"rtt_sum", report->rtt_sum,
			"iat_min", report->iat_min,
			"iat_max", report->iat_max,
			"iat_sum", report->iat_sum,
			"delay_min", report->delay_min,
			"delay_max", report->delay_max,
			"delay_sum", report->delay_sum,

			"pmtu", report->pmtu,
			"imtu", report->imtu,

/* Currently, not all members of the TCP_INFO socket option are used by the
 * FreeBSD kernel. Other members will contain zeroes */
			"tcpi_snd_cwnd", (int)report->tcp_info.tcpi_snd_cwnd,
			"tcpi_snd_ssthresh", (int)report->tcp_info.tcpi_snd_ssthresh,
			"tcpi_unacked", (int)report->tcp_info.tcpi_unacked,
			"tcpi_sacked", (int)report->tcp_info.tcpi_sacked,
			"tcpi_lost", (int)report->tcp_info.tcpi_lost,
			"tcpi_retrans", (int)report->tcp_info.tcpi_retrans,
			"tcpi_retransmits", (int)report->tcp_info.tcpi_retransmits,
			"tcpi_fackets", (int)report->tcp_info.tcpi_fackets,
			"tcpi_reordering", (int)report->tcp_info.tcpi_reordering,
			"tcpi_rtt", (int)report->tcp_info.tcpi_rtt,
			"tcpi_rttvar", (int)report->tcp_info.tcpi_rttvar,
			"tcpi_rto", (int)report->tcp_info.tcpi_rto,
			"tcpi_backoff", (int)report->tcp_info.tcpi_backoff,
			"tcpi_ca_state", (int)report->tcp_info.tcpi_ca_state,
			"tcpi_snd_mss", (int)report->tcp_info.tcpi_snd_mss,

			"status", report->status
		);

		xmlrpc_array_append_item(env, ret, rv);

		xmlrpc_DECREF(rv);

		struct _report *next = report->next;
		free(report);
		report = next;
	}

	if (env->fault_occurred)
		logging_log(LOG_WARNING, "Method get_reports failed: %s", env->fault_string);
	else {
		DEBUG_MSG(LOG_WARNING, "Method get_reports successful");
	}

	return ret;
}
Exemple #9
0
        cWrapper(int const cppvalue) {
            env_wrap env;

            this->valueP = xmlrpc_int_new(&env.env_c, cppvalue);
            throwIfError(env);
        }
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;
}