Exemplo n.º 1
0
static void
readStringW(xmlrpc_env *     const envP,
            xmlrpc_value *   const valueP,
            const wchar_t ** const stringValueP,
            bool             const oldstyleMemMgmt) {

    if (oldstyleMemMgmt) {
        xmlrpc_read_string_w_old(envP, valueP, stringValueP);
    } else
        xmlrpc_read_string_w(envP, valueP, stringValueP);
}
Exemplo n.º 2
0
static void 
test_value_string_wide(void) {

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

    xmlrpc_env_init(&env);

    /* Build a string from wchar_t data. */
    valueP = xmlrpc_string_w_new_lp(&env, 3, wcs_data);
    TEST_NO_FAULT(&env);
    TEST(valueP != NULL);

    /* Extract it as a wchar_t string. */
    xmlrpc_read_string_w_lp(&env, valueP, &len, &wcs);
    TEST_NO_FAULT(&env);
    TEST(wcs != NULL);
    TEST(len == 3);
    TEST(wcs[len] == '\0');
    TEST(wcsneq(wcs, wcs_data, len));
    free((void*)wcs);

    xmlrpc_read_string_w(&env, valueP, &wcs);
    TEST_NO_FAULT(&env);
    TEST(wcs != NULL);
    TEST(wcs[3] == '\0');
    TEST(wcsneq(wcs, wcs_data, 3));
    free((void*)wcs);

    xmlrpc_decompose_value(&env, valueP, "w#", &wcs, &len);
    TEST_NO_FAULT(&env);
    TEST(wcs != NULL);
    TEST(len == 3);
    TEST(wcs[len] == '\0');
    TEST(wcsneq(wcs, wcs_data, len));
    free((void*)wcs);

    {
        /* Extract it as a UTF-8 string. */
        const char * str;
        size_t len;

        xmlrpc_read_string_lp(&env, valueP, &len, &str);
        TEST_NO_FAULT(&env);
        TEST(str != NULL);
        TEST(len == 4);
        TEST(str[len] == '\0');
        TEST(xmlrpc_strneq(str, utf8_data, len));
        free((void*)str);
    }

    xmlrpc_DECREF(valueP);

    /* Build from null-terminated wchar_t string */
    valueP = xmlrpc_string_w_new(&env, wcs_data);
    TEST_NO_FAULT(&env);
    TEST(valueP != NULL);

    /* Verify it */
    xmlrpc_read_string_w_lp(&env, valueP, &len, &wcs);
    TEST_NO_FAULT(&env);
    TEST(wcs != NULL);
    TEST(len == 3);
    TEST(wcs[len] == '\0');
    TEST(wcsneq(wcs, wcs_data, len));
    free((void*)wcs);

    xmlrpc_DECREF(valueP);

    test_value_string_wide_build();

    /* Build a string from UTF-8 data. */
    valueP = xmlrpc_string_new(&env, utf8_data);
    TEST_NO_FAULT(&env);
    TEST(valueP != NULL);

    /* Extract it as a wchar_t string. */
    xmlrpc_read_string_w_lp(&env, valueP, &len, &wcs);
    TEST_NO_FAULT(&env);
    TEST(wcs != NULL);
    TEST(len == 3);
    TEST(wcs[len] == 0x0000);
    TEST(wcsneq(wcs, wcs_data, len));
    free((void*)wcs);
    xmlrpc_DECREF(valueP);

    /* Test with embedded NUL.  We use a length of 4 so that the terminating
       NUL actually becomes part of the string.
    */
    valueP = xmlrpc_string_w_new_lp(&env, 4, wcs_data);
    TEST_NO_FAULT(&env);
    TEST(valueP != NULL);

    /* Extract it as a wchar_t string. */
    xmlrpc_read_string_w_lp(&env, valueP, &len, &wcs);
    TEST_NO_FAULT(&env);
    TEST(wcs != NULL);
    TEST(len == 4);
    TEST(wcs[len] == '\0');
    TEST(wcsneq(wcs, wcs_data, len));
    free((void*)wcs);

    xmlrpc_read_string_w(&env, valueP, &wcs);
    TEST_FAULT(&env, XMLRPC_TYPE_ERROR);

    xmlrpc_DECREF(valueP);

    test_value_string_wide_line();

    xmlrpc_env_clean(&env);
#endif /* HAVE_UNICODE_WCHAR */
}
Exemplo n.º 3
0
struct mi_root * xr_parse_tree( xmlrpc_env * env, xmlrpc_value * paramArray ) {

	struct mi_root * mi_root;
	
	int size, i;
	size_t length;

	xmlrpc_int32 intValue;
	xmlrpc_bool boolValue;

	#ifdef XMLRPC_OLD_VERSION
	double doubleValue;
	char * contents;
	#else
	xmlrpc_double doubleValue;
	#endif

	char * stringValue = 0;
	char * byteStringValue =0;
	xmlrpc_value * item;
	
	mi_root = init_mi_tree(0, 0, 0);
	
	if ( !mi_root ) {
		LM_ERR("the MI tree cannot be initialized!\n");
		goto error;
	}

	size = xmlrpc_array_size(env, paramArray);
	
	for (i=0 ; i< size ; i++) {

		item = xmlrpc_array_get_item(env, paramArray, i);
		if ( env->fault_occurred ) {
			LM_ERR("failed to get array item: %s\n", env->fault_string);
			goto error;
		}
		
		switch ( xmlrpc_value_type(item) ) {
		
		case (XMLRPC_TYPE_INT):

			#ifdef XMLRPC_OLD_VERSION
			intValue = item->_value.i;
			#else 
			xmlrpc_read_int(env,item,&intValue);
			#endif

			if (addf_mi_node_child(&mi_root->node,0,0,0,"%d",intValue)==NULL) {
				LM_ERR("failed to add node to the MI tree.\n");
				goto error;
			}

			break;
		case (XMLRPC_TYPE_BOOL):

			#ifdef XMLRPC_OLD_VERSION
			boolValue = item->_value.b;
			#else
			xmlrpc_read_bool(env,item,&boolValue);
			#endif

			if (addf_mi_node_child(&mi_root->node,0,0,0,"%u",boolValue)==NULL){
				LM_ERR("failed to add node to the MI tree.\n");
				goto error;
			}

			break;

		case (XMLRPC_TYPE_DOUBLE):

			#ifdef XMLRPC_OLD_VERSION
			doubleValue = item->_value.d;
			#else
			xmlrpc_read_double(env,item,&doubleValue);
			#endif

			if ( addf_mi_node_child(&mi_root->node, 0, 0, 0, "%lf",
			doubleValue) == NULL ) {
				LM_ERR("failed to add node to the MI tree.\n");
				goto error;
			}

			break;

		case (XMLRPC_TYPE_STRING):

			#if HAVE_UNICODE_WCHAR
			
			#ifdef  XMLRPC_OLD_VERSION
			xmlrpc_read_string_w(env, item, &stringValue);
			#else
			xmlrpc_read_string_w(env, item , (const char **)&stringValue);
			#endif

			#else

			#ifdef  XMLRPC_OLD_VERSION
			xmlrpc_read_string(env, item, &stringValue);
			#else
			xmlrpc_read_string(env, item, (const char **)&stringValue);
			#endif

			#endif

			if ( env->fault_occurred ) {
				LM_ERR("failed to read stringValue: %s!\n", env->fault_string);
				goto error;
			}
			if ( add_mi_node_child(&mi_root->node, 0, 0, 0,
					       stringValue,
					       lflf_to_crlf_hack(stringValue)) == NULL ) {
				LM_ERR("failed to add node to the MI tree.\n");
				goto error;
			}
			
			break;

		case (XMLRPC_TYPE_BASE64):

			#ifdef XMLRPC_OLD_VERSION

			length = XMLRPC_TYPED_MEM_BLOCK_SIZE(char, &item->_block);
			contents = XMLRPC_TYPED_MEM_BLOCK_CONTENTS(char, &item->_block);
			byteStringValue = pkg_malloc(length);

			if ( !byteStringValue ){
				xmlrpc_env_set_fault_formatted(env, XMLRPC_INTERNAL_ERROR,
					"Unable to allocate %u bytes for byte string.", length);
				LM_ERR("pkg_malloc cannot allocate any more memory!\n");
				goto error;
			} else
				memcpy(byteStringValue, contents, length);

			if ( add_mi_node_child(&mi_root->node, 0, 0, 0, byteStringValue,
			length) == NULL ) {
				LM_ERR("failed to add node to the MI tree.\n");
				goto error;
			}

			#else

			xmlrpc_read_base64(env, item, &length,
				(const unsigned char **)(void*)&byteStringValue);

			if ( env->fault_occurred ) {
				LM_ERR("failed to read byteStringValue: %s!\n", 
						env->fault_string);
				goto error;
			}

			if ( add_mi_node_child(&mi_root->node, MI_DUP_VALUE, 0, 0, 
			byteStringValue, length) == NULL ) {
				LM_ERR("failed to add node to the MI tree.\n");
				goto error;
			}
			free(byteStringValue);

			#endif

			break;

		default :
			LM_ERR("unsupported node type %d\n",  xmlrpc_value_type(item)  );
			xmlrpc_env_set_fault_formatted( env, XMLRPC_TYPE_ERROR, 
				"Unsupported value of type %d supplied",
				xmlrpc_value_type(item));
			goto error;
		}
	}
	
	return mi_root;

error:
	if ( mi_root ) free_mi_tree(mi_root);
	if ( byteStringValue ) pkg_free(byteStringValue);
	return 0;
}