예제 #1
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);

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

    xmlrpc_env_init(&env2);
    xmlrpc_decompose_value(&env2, v, "S", &v2);
    TEST_FAULT(&env2, XMLRPC_TYPE_ERROR);
    xmlrpc_env_clean(&env2);
    xmlrpc_DECREF(v);
    xmlrpc_env_clean(&env);
}
예제 #2
0
static void test_bounds_checks (void)
{
    xmlrpc_env env;
    xmlrpc_value *array;
    int i1, i2, i3, i4;

    /* Get an array to work with. */
    xmlrpc_env_init(&env);
    array = xmlrpc_build_value(&env, "(iii)", 100, 200, 300);
    TEST_NO_FAULT(&env);
    xmlrpc_env_clean(&env);
    
    /* Test xmlrpc_decompose_value with too few values. */
    xmlrpc_env_init(&env);
    xmlrpc_decompose_value(&env, array, "(iiii)", &i1, &i2, &i3, &i4);
    TEST_FAULT(&env, XMLRPC_INDEX_ERROR);
    xmlrpc_env_clean(&env);

    /* Test xmlrpc_decompose_value with too many values. */
    xmlrpc_env_init(&env);
    xmlrpc_decompose_value(&env, array, "(ii)", &i1, &i2, &i3, &i4);
    TEST_FAULT(&env, XMLRPC_INDEX_ERROR);
    xmlrpc_env_clean(&env);

    /* Dispose of our array. */
    xmlrpc_DECREF(array);
}
예제 #3
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_env_clean(&env);
    xmlrpc_env_init(&env);

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

    xmlrpc_DECREF(arrayP);

    xmlrpc_env_clean(&env);
}
예제 #4
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);
}
예제 #5
0
/* vcd.user.remove(string username) */
xmlrpc_value *m_vcd_user_remove(xmlrpc_env *env, xmlrpc_value *p, void *c)
{
	LOG_TRACEME

	xmlrpc_value *params;
	char *user;
	int rc, uid = 0;

	params = method_init(env, p, c, VCD_CAP_AUTH, 0);
	method_return_if_fault(env);

	xmlrpc_decompose_value(env, params,
			"{s:s,*}",
			"username", &user);
	method_return_if_fault(env);

	if (!(uid = auth_getuid(user)))
		method_return_fault(env, MENOUSER);

	rc = vxdb_exec(
			"BEGIN TRANSACTION;"
			"DELETE FROM xid_uid_map WHERE uid = %d;"
			"DELETE FROM user_caps WHERE uid = %d;"
			"DELETE FROM user WHERE uid = %d;"
			"COMMIT TRANSACTION;",
		uid, uid, uid);

	if (rc != VXDB_OK)
		method_return_vxdb_fault(env);

	return xmlrpc_nil_new(env);
}
예제 #6
0
static xmlrpc_value *
test_default(xmlrpc_env *   const envP,
             const char *   const callInfo,
             const char *   const methodName,
             xmlrpc_value * const paramArrayP,
             void *         const serverInfo) {

    xmlrpc_int32 x, y;

    TEST_NO_FAULT(envP);
    TEST(paramArrayP != NULL);
    TEST(serverInfo == DEFAULT_SERVERINFO);

    TEST(streq(methodName, "test.nosuch") ||
         streq(methodName, "test.nosuch.old"));

    if (streq(methodName, "nosuch.method"))
        TEST(callInfo == DEFAULT_CALLINFO);
    else if (streq(methodName, "nosuch.method.old"))
        TEST(callInfo == NULL);

    xmlrpc_decompose_value(envP, paramArrayP, "(ii)", &x, &y);
    TEST_NO_FAULT(envP);
    TEST(x == 25);
    TEST(y == 17);

    return xmlrpc_build_value(envP, "i", 2 * (x + y));
}
예제 #7
0
int c_oneVmInfo(int vmid, char* ret_info, int length)
{
    xmlrpc_value *resultP;
    int return_code;
    char *return_string;
    int retval = -1;

    resultP = xmlrpc_client_call(&one_client.env, one_client.url,
        "one.vmget_info", "(si)", one_client.session, vmid);

    xmlrpc_decompose_value(&one_client.env, resultP, "(bs)",
        &return_code, &return_string);

    if( return_code )
    {
        if (virStrncpy(ret_info, return_string, length-1, length) != NULL)
            /* Only set the return value to 0 if we succeeded */
            retval = 0;
    }

    xmlrpc_DECREF(resultP);
    VIR_FREE(return_string);

    return retval;
}
예제 #8
0
xmlrpc_value * std_getblock(xmlrpc_env *   envP,
               xmlrpc_value * paramArrayP,
               void *         serverInfo,
               void *         channelInfo) {

    xmlrpc_value * retvalP;
    xmlrpc_int32 CheckSum;
    xmlrpc_value * DataStructP;

    xmlrpc_decompose_value(envP, paramArrayP, "(iS)",
                           &CheckSum, &DataStructP);
    if (envP->fault_occurred)
        return NULL;

    if (CheckSum != 100) {
        xmlrpc_env_set_fault(envP, 0, "Parameter list version must be 1");
        return NULL;
    }

    getDataBlock(envP, DataStructP, &retvalP);
    
    xmlrpc_DECREF(DataStructP);

    if (envP->fault_occurred)
        return NULL;

    return retvalP;
}
예제 #9
0
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 
handle_sample_add_response(const char *   const serverUrl,
                           const char *   const methodName,
                           xmlrpc_value * const paramArrayP,
                           void *         const user_data,
                           xmlrpc_env *   const faultP,
                           xmlrpc_value * const resultP) {

  xmlrpc_env env;
  xmlrpc_int addend, adder;
    
  /* Initialize our error environment variable */
  xmlrpc_env_init(&env);

  /* Our first four arguments provide helpful context.  Let's grab the
       addends from our parameter array. 
  */
  xmlrpc_decompose_value(&env, paramArrayP, "(ii)", &addend, &adder);
  die_if_fault_occurred(&env);

  printf("RPC with method '%s' at URL '%s' to add %d and %d "
	 "has completed\n", methodName, serverUrl, addend, adder);
    
  if (faultP->fault_occurred)
    printf("The RPC failed.  %s\n", faultP->fault_string);
  else {
    xmlrpc_int sum;

    xmlrpc_read_int(&env, resultP, &sum);
    die_if_fault_occurred(&env);

    printf("The sum is  %d\n", sum);
  }
}
예제 #11
0
static void
test_value_bool(void) {

    xmlrpc_value * v;
    xmlrpc_env env;
    xmlrpc_bool b;

    /* Test booleans. */

    xmlrpc_env_init(&env);

    TEST(streq(xmlrpc_type_name(XMLRPC_TYPE_BOOL), "BOOL"));

    v = xmlrpc_bool_new(&env, (xmlrpc_bool) 1);
    TEST_NO_FAULT(&env);
    TEST(XMLRPC_TYPE_BOOL == xmlrpc_value_type(v));
    xmlrpc_read_bool(&env, v, &b);
    TEST_NO_FAULT(&env);
    TEST(b);
    xmlrpc_DECREF(v);

    v = xmlrpc_build_value(&env, "b", (xmlrpc_bool) 0);
    TEST_NO_FAULT(&env);
    TEST(v != NULL);
    TEST(XMLRPC_TYPE_BOOL == xmlrpc_value_type(v));
    xmlrpc_decompose_value(&env, v, "b", &b);
    xmlrpc_DECREF(v);
    TEST_NO_FAULT(&env);
    TEST(!b);

    xmlrpc_env_clean(&env);
}
예제 #12
0
static void
test_value_double(void) {

    xmlrpc_value * v;
    xmlrpc_env env;
    double d;

    xmlrpc_env_init(&env);

    TEST(streq(xmlrpc_type_name(XMLRPC_TYPE_DOUBLE), "DOUBLE"));

    v = xmlrpc_double_new(&env, -3.25);
    TEST_NO_FAULT(&env);
    TEST(XMLRPC_TYPE_DOUBLE == xmlrpc_value_type(v));
    xmlrpc_read_double(&env, v, &d);
    TEST_NO_FAULT(&env);
    TEST(d == -3.25);
    xmlrpc_DECREF(v);

    v = xmlrpc_build_value(&env, "d", 1.0);
    TEST_NO_FAULT(&env);
    TEST(v != NULL);
    TEST(XMLRPC_TYPE_DOUBLE == xmlrpc_value_type(v));
    xmlrpc_decompose_value(&env, v, "d", &d);
    xmlrpc_DECREF(v);
    TEST_NO_FAULT(&env);
    TEST(d == 1.0);

    xmlrpc_env_clean(&env);
}
예제 #13
0
파일: list.c 프로젝트: linux-vserver/vcd
void cmd_list(xmlrpc_env *env, int argc, char **argv)
{
	xmlrpc_value *response, *result;
	char *username;
	int len, i;

	if (argc > 0)
		username = argv[0];
	else
		username = "";

	response = client_call("vxdb.list",
		"{s:s}",
		"username", username);
	return_if_fault(env);

	len = xmlrpc_array_size(env, response);
	return_if_fault(env);

	for (i = 0; i < len; i++) {
		xmlrpc_array_read_item(env, response, i, &result);
		return_if_fault(env);

		xmlrpc_decompose_value(env, result, "s", &username);
		return_if_fault(env);

		xmlrpc_DECREF(result);

		printf("%s\n", username);
	}

	xmlrpc_DECREF(response);
}
예제 #14
0
void cmd_vx_bcaps_get(xmlrpc_env *env, int argc, char **argv)
{
	xmlrpc_value *response, *result;
	char *name, *bcap;
	int len, i;

	if (argc < 1)
		usage(EXIT_FAILURE);

	name = argv[0];

	response = client_call("vxdb.vx.bcaps.get",
		"{s:s}",
		"name", name);
	return_if_fault(env);

	len = xmlrpc_array_size(env, response);
	return_if_fault(env);

	for (i = 0; i < len; i++) {
		xmlrpc_array_read_item(env, response, i, &result);
		return_if_fault(env);

		xmlrpc_decompose_value(env, result, "s", &bcap);
		return_if_fault(env);

		xmlrpc_DECREF(result);

		printf("%s\n", bcap);
	}

	xmlrpc_DECREF(response);
}
static xmlrpc_value * weblab_xmlrpc_test_me(xmlrpc_env * const env, xmlrpc_value * const param_array, void * const user_data) {
    char * arg;
    xmlrpc_decompose_value(env, param_array, "(s)", &arg);
    if (env->fault_occurred)
        return NULL;
    return xmlrpc_build_value(env, "s", arg);
}
static xmlrpc_value *
sample_add(xmlrpc_env *   const envP,
           xmlrpc_value * const paramArrayP,
           void *         const serverInfo,
           void *         const channelInfo) {

    xmlrpc_int32 x, y, z;

    /* Parse our argument array. */
    xmlrpc_decompose_value(envP, paramArrayP, "(ii)", &x, &y);
    if (envP->fault_occurred)
        return NULL;

    /* Add our two numbers. */
    z = x + y;

    /* Sometimes, make it look hard (so client can see what it's like
       to do an RPC that takes a while).
    */
    if (y == 1)
        sleep(1);

    /* Return our result. */
    return xmlrpc_build_value(envP, "i", z);
}
예제 #17
0
static void
test_value_AS(void) {

    xmlrpc_value *v;
    xmlrpc_value *v2;
    xmlrpc_value *v3;
    xmlrpc_env env;
    size_t len;

    /* Test parsing of 'A' and 'S'. */

    xmlrpc_env_init(&env);

    v = xmlrpc_build_value(&env, "((){})");
    TEST_NO_FAULT(&env);
    xmlrpc_decompose_value(&env, v, "(AS)", &v2, &v3);
    xmlrpc_DECREF(v);
    TEST_NO_FAULT(&env);
    TEST(XMLRPC_TYPE_ARRAY == xmlrpc_value_type(v2));
    TEST(XMLRPC_TYPE_STRUCT == xmlrpc_value_type(v3));
    len = xmlrpc_array_size(&env, v2);
    TEST_NO_FAULT(&env);
    TEST(len == 0);
    len = xmlrpc_struct_size(&env, v3);
    TEST_NO_FAULT(&env);
    TEST(len == 0);
    xmlrpc_DECREF(v2);
    xmlrpc_DECREF(v3);

    xmlrpc_env_clean(&env);
}
static xmlrpc_value * weblab_xmlrpc_send_command_to_device(xmlrpc_env * const env, xmlrpc_value * const param_array, void * const user_data) {
    char * command;
    char * response;
    xmlrpc_decompose_value(env, param_array, "(s)", &command);
    if (env->fault_occurred)
        return NULL;
    response = weblab_handlers.send_command(command);
    return xmlrpc_build_value(env, "s", response);
}
예제 #19
0
/* vxdb.mount.get(string name[, string dst]) */
xmlrpc_value *m_vxdb_mount_get(xmlrpc_env *env, xmlrpc_value *p, void *c)
{
	xmlrpc_value *params, *response = NULL;
	char *name, *dst;
	int rc;
	xid_t xid;

	params = method_init(env, p, c, VCD_CAP_MOUNT, M_OWNER);
	method_return_if_fault(env);

	xmlrpc_decompose_value(env, params,
			"{s:s,s:s,*}",
			"name", &name,
			"dst", &dst);
	method_return_if_fault(env);

	method_empty_params(1, &dst);

	if (dst && !validate_path(dst))
		method_return_faultf(env, MEINVAL,
				"invalid dst value: %s", dst);

	if (!(xid = vxdb_getxid(name)))
		method_return_fault(env, MENOVPS);

	if (dst)
		rc = vxdb_prepare(&dbr,
				"SELECT src,dst,type,opts FROM mount "
				"WHERE xid = %d AND dst = '%s'",
				xid, dst);

	else
		rc = vxdb_prepare(&dbr,
				"SELECT src,dst,type,opts FROM mount "
				"WHERE xid = %d ORDER BY dst ASC",
				xid);

	if (rc != VXDB_OK)
		method_return_vxdb_fault(env);

	response = xmlrpc_array_new(env);

	vxdb_foreach_step(rc, dbr)
		xmlrpc_array_append_item(env, response, xmlrpc_build_value(env,
				"{s:s,s:s,s:s,s:s}",
				"src",  vxdb_column_text(dbr, 0),
				"dst",  vxdb_column_text(dbr, 1),
				"type", vxdb_column_text(dbr, 2),
				"opts", vxdb_column_text(dbr, 3)));

	if (rc != VXDB_DONE)
		method_set_vxdb_fault(env);

	vxdb_finalize(dbr);

	return response;
}
예제 #20
0
static void
test_value_string_null(void) {

    xmlrpc_value * v;
    xmlrpc_env env;
    xmlrpc_env env2;
    const char * str;
    size_t len;

    /* Test a string with a '\0' byte. */

    xmlrpc_env_init(&env);

    v = xmlrpc_string_new_lp(&env, 7, "foo\0bar");
    TEST_NO_FAULT(&env);
    TEST(XMLRPC_TYPE_STRING == xmlrpc_value_type(v));
    xmlrpc_read_string_lp(&env, v, &len, &str);
    TEST_NO_FAULT(&env);
    TEST(len == 7);
    TEST(memeq(str, "foo\0bar", 7));
    xmlrpc_DECREF(v);
    strfree(str);

    v = xmlrpc_build_value(&env, "s#", "foo\0bar", (size_t) 7);
    TEST_NO_FAULT(&env);
    TEST(v != NULL);
    TEST(XMLRPC_TYPE_STRING == xmlrpc_value_type(v));

    xmlrpc_decompose_value(&env, v, "s#", &str, &len);
    TEST_NO_FAULT(&env);
    TEST(memeq(str, "foo\0bar", 7));
    TEST(len == 7);
    strfree(str);

    /* Test for type error when decoding a string with a zero byte to a
    ** regular C string. */
    xmlrpc_env_init(&env2);
    xmlrpc_decompose_value(&env2, v, "s", &str);
    TEST_FAULT(&env2, XMLRPC_TYPE_ERROR);
    xmlrpc_env_clean(&env2);
    xmlrpc_DECREF(v);

    xmlrpc_env_clean(&env);
}
예제 #21
0
/* vg.remove(string group, string name) */
xmlrpc_value *m_vg_remove(xmlrpc_env *env, xmlrpc_value *p, void *c)
{
	LOG_TRACEME

	xmlrpc_value *params;
	char *group, *name;
	int rc, gid = 0;
	xid_t xid;

	params = method_init(env, p, c, VCD_CAP_AUTH, 0);
	method_return_if_fault(env);

	xmlrpc_decompose_value(env, params,
			"{s:s,s:s,*}",
			"group", &group,
			"name",  &name);
	method_return_if_fault(env);

	if (!validate_group(group))
		method_return_faultf(env, MEINVAL,
				"invalid group value: %s", group);

	if (str_equal(group, "all"))
		method_return_faultf(env, MEINVAL,
				"cannot remove reserved group '%s'", group);

	if (!(gid = vxdb_getgid(group)))
		method_return_fault(env, MENOVG);

	if (!str_isempty(name)) {
		if (!validate_name(name))
			method_return_faultf(env, MEINVAL,
					"invalid name value: %s", name);

		if (!(xid = vxdb_getxid(name)))
			method_return_fault(env, MENOVPS);

		rc = vxdb_exec(
				"DELETE FROM xid_gid_map WHERE xid = %d AND gid = %d",
				xid, gid);
	}

	else {
		rc = vxdb_exec(
				"BEGIN EXCLUSIVE TRANSACTION;"
				"DELETE FROM xid_gid_map WHERE gid = %d;"
				"DELETE FROM groups WHERE gid = %d;"
				"COMMIT TRANSACTION;",
				gid, gid);
	}

	if (rc != VXDB_OK)
		method_return_vxdb_fault(env);

	return xmlrpc_nil_new(env);
}
예제 #22
0
static void
callOneMethod(xmlrpc_env *      const envP,
              xmlrpc_registry * const registryP,
              xmlrpc_value *    const rpcDescP,
              void *            const callInfo,
              xmlrpc_value **   const resultPP) {

    const char * methodName;
    xmlrpc_value * paramArrayP;

    XMLRPC_ASSERT_ENV_OK(envP);

    if (xmlrpc_value_type(rpcDescP) != XMLRPC_TYPE_STRUCT)
        xmlrpc_env_set_fault_formatted(
            envP, XMLRPC_TYPE_ERROR,
            "An element of the multicall array is type %u, but should "
            "be a struct (with members 'methodName' and 'params')",
            xmlrpc_value_type(rpcDescP));
    else {
        xmlrpc_decompose_value(envP, rpcDescP, "{s:s,s:A,*}",
                               "methodName", &methodName,
                               "params", &paramArrayP);
        if (!envP->fault_occurred) {
            /* Watch out for a deep recursion attack. */
            if (xmlrpc_streq(methodName, "system.multicall"))
                xmlrpc_env_set_fault_formatted(
                    envP,
                    XMLRPC_REQUEST_REFUSED_ERROR,
                    "Recursive system.multicall forbidden");
            else {
                xmlrpc_env env;
                xmlrpc_value * resultValP;

                xmlrpc_env_init(&env);
                xmlrpc_dispatchCall(&env, registryP, methodName, paramArrayP,
                                    callInfo,
                                    &resultValP);
                if (env.fault_occurred) {
                    /* Method failed, so result is a fault structure */
                    *resultPP = 
                        xmlrpc_build_value(
                            envP, "{s:i,s:s}",
                            "faultCode", (xmlrpc_int32) env.fault_code,
                            "faultString", env.fault_string);
                } else {
                    *resultPP = xmlrpc_build_value(envP, "(V)", resultValP);

                    xmlrpc_DECREF(resultValP);
                }
                xmlrpc_env_clean(&env);
            }
            xmlrpc_DECREF(paramArrayP);
            xmlrpc_strfree(methodName);
        }
    }
}
static xmlrpc_value * weblab_xmlrpc_send_file_to_device(xmlrpc_env * const env, xmlrpc_value * const param_array, void * const user_data) {
    char * encoded_file;
    char * fileinfo;
    char * response;
    xmlrpc_decompose_value(env, param_array, "(ss)", &encoded_file, &fileinfo);
    if (env->fault_occurred)
        return NULL;
    response = weblab_handlers.send_file(encoded_file, fileinfo);
    return xmlrpc_build_value(env, "s", response);
}
예제 #24
0
static void
test_value_datetime(void) {

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

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

    xmlrpc_env_init(&env);

    v = xmlrpc_datetime_new_str(&env, datestring);
    TEST_NO_FAULT(&env);
    TEST(XMLRPC_TYPE_DATETIME == xmlrpc_value_type(v));

    xmlrpc_read_datetime_str(&env, v, &ds);
    TEST_NO_FAULT(&env);
    TEST(strcmp(ds, datestring) == 0);
    strfree(ds);

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

    xmlrpc_DECREF(v);

    v = xmlrpc_datetime_new_sec(&env, datetime);
    TEST_NO_FAULT(&env);
    TEST(XMLRPC_TYPE_DATETIME == xmlrpc_value_type(v));

    xmlrpc_read_datetime_str(&env, v, &ds);
    TEST_NO_FAULT(&env);
    TEST(strcmp(ds, datestring) == 0);
    strfree(ds);

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

    xmlrpc_DECREF(v);

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

    xmlrpc_env_clean(&env);
}
예제 #25
0
static xmlrpc_value *freeswitch_api(xmlrpc_env * const envP, xmlrpc_value * const paramArrayP, void *const userData, void *const callInfo)
{
	char *command = NULL, *arg = NULL;
	switch_stream_handle_t stream = { 0 };
	xmlrpc_value *val = NULL;
	switch_bool_t freed = 0;


	/* Parse our argument array. */
	xmlrpc_decompose_value(envP, paramArrayP, "(ss)", &command, &arg);

	if (envP->fault_occurred) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Request!\n");
		return NULL;
	}

	if (!is_authorized((const TSession *) callInfo, command)) {
		val = xmlrpc_build_value(envP, "s", "UNAUTHORIZED!");
		goto end;
	}

	if (switch_stristr("unload", command) && switch_stristr("mod_xml_rpc", arg)) {
		switch_safe_free(command);
		switch_safe_free(arg);
		freed = 1;
		command = "bgapi";
		arg = "unload mod_xml_rpc";
	} else if (switch_stristr("reload", command) && switch_stristr("mod_xml_rpc", arg)) {
		switch_safe_free(command);
		switch_safe_free(arg);
		freed = 1;
		command = "bgapi";
		arg = "reload mod_xml_rpc";
	}

	SWITCH_STANDARD_STREAM(stream);
	if (switch_api_execute(command, arg, NULL, &stream) == SWITCH_STATUS_SUCCESS) {
		/* Return our result. */
		val = xmlrpc_build_value(envP, "s", stream.data);
		free(stream.data);
	} else {
		val = xmlrpc_build_value(envP, "s", "ERROR!");
	}

  end:

	/* xmlrpc-c requires us to free memory it malloced from xmlrpc_decompose_value */
	if (!freed) {
		switch_safe_free(command);
		switch_safe_free(arg);
	}

	return val;
}
예제 #26
0
static xmlrpc_value *freeswitch_man(xmlrpc_env * const envP, xmlrpc_value * const paramArrayP, void *const userData)
{
	char *oid = NULL, *relative_oid, *s_action = NULL, *data = NULL;
	char buf[SWITCH_MAX_MANAGEMENT_BUFFER_LEN] = "";
	switch_management_action_t action = SMA_NONE;
	xmlrpc_value *val = NULL;

	/* Parse our argument array. */
	xmlrpc_decompose_value(envP, paramArrayP, "(sss)", &oid, &s_action, &data);
	if (envP->fault_occurred) {
		return NULL;
	}

	if (!strncasecmp(oid, FREESWITCH_OID_PREFIX, strlen(FREESWITCH_OID_PREFIX))) {
		relative_oid = oid + strlen(FREESWITCH_OID_PREFIX);
	} else {
		relative_oid = oid;
	}

	if (!zstr(data)) {
		switch_copy_string(buf, data, sizeof(buf));
	}

	if (!strcasecmp(s_action, "get")) {
		action = SMA_GET;
	} else if (!strcasecmp(s_action, "set")) {
		action = SMA_SET;
	}

	if (action) {
		if (switch_core_management_exec(relative_oid, action, buf, sizeof(buf)) == SWITCH_STATUS_SUCCESS) {
			if (action == SMA_SET) {
				if (*buf != '\0') {
					switch_snprintf(buf, sizeof(buf), "OK\n");
				}
			}
		} else {
			if (*buf != '\0') {
				switch_snprintf(buf, sizeof(buf), "ERROR\n");
			}
		}
	} else {
		switch_snprintf(buf, sizeof(buf), "Invalid Action %s\n", s_action);
	}

	/* Return our result. */
	val = xmlrpc_build_value(envP, "s", buf);

	/* xmlrpc-c requires us to free memory it malloced from xmlrpc_decompose_value */
	switch_safe_free(oid);
	switch_safe_free(s_action);
	switch_safe_free(data);
	return val;
}
예제 #27
0
static void
test_value_string_no_null(void) {

    xmlrpc_value * v;
    xmlrpc_env env;
    const char * str;
    size_t len;

    /* Test strings (without '\0' bytes). */
    xmlrpc_env_init(&env);

    v = xmlrpc_string_new(&env, test_string_1);
    TEST_NO_FAULT(&env);
    TEST(XMLRPC_TYPE_STRING == xmlrpc_value_type(v));
    xmlrpc_read_string(&env, v, &str);
    TEST_NO_FAULT(&env);
    TEST(strcmp(str, test_string_1) == 0);
    xmlrpc_DECREF(v);
    strfree(str);

    v = xmlrpc_build_value(&env, "s", test_string_1);

    TEST_NO_FAULT(&env);
    TEST(v != NULL);
    TEST(XMLRPC_TYPE_STRING == xmlrpc_value_type(v));

    xmlrpc_decompose_value(&env, v, "s", &str);
    TEST_NO_FAULT(&env);
    TEST(strcmp(str, test_string_1) == 0);
    strfree(str);

    xmlrpc_decompose_value(&env, v, "s#", &str, &len);
    TEST_NO_FAULT(&env);
    TEST(memcmp(str, test_string_1, strlen(test_string_1)) == 0);
    TEST(strlen(str) == strlen(test_string_1));
    strfree(str);

    xmlrpc_DECREF(v);

    xmlrpc_env_clean(&env);
}
예제 #28
0
const char* extract_result (xmlrpc_env *env , xmlrpc_value *temp)
{
   xmlrpc_value * arrayP;	
   xmlrpc_decompose_value(env, temp, "(A)", &arrayP);
   size_t size = xmlrpc_array_size(env, arrayP);
   xmlrpc_value * strctP;
   strctP = xmlrpc_array_get_item(env, arrayP, 0);
   const char *primeResult = (const char *)malloc (256);
   size_t str1_len;
   xmlrpc_read_string_lp(env, strctP, &str1_len, &primeResult);			
   
   return primeResult;
}
예제 #29
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);    
}
예제 #30
0
static xmlrpc_value * method_stop_flow(xmlrpc_env * const env,
		   xmlrpc_value * const param_array,
		   void * const user_data)
{
	UNUSED_ARGUMENT(user_data);

	int rc;
	xmlrpc_value *ret = 0;
	int flow_id;
	struct _request_stop_flow *request = 0;

	DEBUG_MSG(LOG_WARNING, "Method stop_flow called");

	/* Parse our argument array. */
	xmlrpc_decompose_value(env, param_array, "({s:i,*})",

		/* flow id */
		"flow_id", &flow_id);

	if (env->fault_occurred)
		goto cleanup;

	request = malloc(sizeof(struct _request_stop_flow));
	request->flow_id = flow_id;
	rc = dispatch_request((struct _request*)request, REQUEST_STOP_FLOW);

	if (rc == -1) {
		XMLRPC_FAIL(env, XMLRPC_INTERNAL_ERROR, request->r.error); /* goto cleanup on failure */
	}

	/* Return our result. */
	ret = xmlrpc_build_value(env, "()");

cleanup:
	if (request) {
		free(request->r.error);
		free(request);
	}

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

	return ret;
}