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); }
value_double::operator double() const { double retval; env_wrap env; xmlrpc_read_double(&env.env_c, this->cValueP, &retval); throwIfError(env); return retval; }
double xr_getDoubleFromParam (void *data, int index) { CallerP c = (Caller *) data; xmlrpc_value *val = xr_getArrValue (c->param, index); double dval; xmlrpc_read_double (c->env, val, &dval); xmlrpc_DECREF (val); return ( ((xr_errstat=c->env->fault_occurred) ? (double)0.0 : dval) ); }
static void decomposeValueWithTree(xmlrpc_env * const envP, xmlrpc_value * const valueP, bool const oldstyleMemMgmt, const struct decompTreeNode * const decompRootP) { /*---------------------------------------------------------------------------- Decompose XML-RPC value *valueP, given the decomposition tree *decompRootP. The decomposition tree tells what structure *valueP is expected to have and where to put the various components of it (e.g. it says "it's an array of 3 integers. Put their values at locations x, y, and z") -----------------------------------------------------------------------------*/ switch (decompRootP->formatSpecChar) { case '-': /* There's nothing to validate or return */ break; case 'i': xmlrpc_read_int(envP, valueP, decompRootP->store.Tinteger.valueP); break; case 'b': xmlrpc_read_bool(envP, valueP, decompRootP->store.Tbool.valueP); break; case 'd': xmlrpc_read_double(envP, valueP, decompRootP->store.Tdouble.valueP); break; case 't': xmlrpc_read_datetime_sec(envP, valueP, decompRootP->store.TdatetimeT.valueP); break; case '8': readDatetime8Str(envP, valueP, decompRootP->store.Tdatetime8.valueP, oldstyleMemMgmt); break; case 's': if (decompRootP->store.Tstring.sizeP) readStringLp(envP, valueP, decompRootP->store.Tstring.sizeP, decompRootP->store.Tstring.valueP, oldstyleMemMgmt); else readString(envP, valueP, decompRootP->store.Tstring.valueP, oldstyleMemMgmt); break; case 'w': #if HAVE_UNICODE_WCHAR if (decompRootP->store.Tstring.sizeP) readStringWLp(envP, valueP, decompRootP->store.TwideString.sizeP, decompRootP->store.TwideString.valueP, oldstyleMemMgmt); else readStringW(envP, valueP, decompRootP->store.TwideString.valueP, oldstyleMemMgmt); #else XMLRPC_ASSERT(false); #endif /* HAVE_UNICODE_WCHAR */ break; case '6': readBase64(envP, valueP, decompRootP->store.TbitString.sizeP, decompRootP->store.TbitString.valueP, oldstyleMemMgmt); break; case 'n': xmlrpc_read_nil(envP, valueP); break; case 'I': xmlrpc_read_i8(envP, valueP, decompRootP->store.Ti8.valueP); break; case 'p': xmlrpc_read_cptr(envP, valueP, decompRootP->store.Tcptr.valueP); break; case 'V': *decompRootP->store.Tvalue.valueP = valueP; if (!oldstyleMemMgmt) xmlrpc_INCREF(valueP); break; case 'A': if (xmlrpc_value_type(valueP) != XMLRPC_TYPE_ARRAY) xmlrpc_env_set_fault_formatted( envP, XMLRPC_TYPE_ERROR, "Value to be decomposed is of type " "%s, but the 'A' specifier requires type ARRAY", xmlrpc_type_name(xmlrpc_value_type(valueP))); else { *decompRootP->store.TarrayVal.valueP = valueP; if (!oldstyleMemMgmt) xmlrpc_INCREF(valueP); } break; case 'S': if (xmlrpc_value_type(valueP) != XMLRPC_TYPE_STRUCT) xmlrpc_env_set_fault_formatted( envP, XMLRPC_TYPE_ERROR, "Value to be decomposed is of type " "%s, but the 'S' specifier requires type STRUCT.", xmlrpc_type_name(xmlrpc_value_type(valueP))); else { *decompRootP->store.TstructVal.valueP = valueP; if (!oldstyleMemMgmt) xmlrpc_INCREF(valueP); } break; case '(': if (xmlrpc_value_type(valueP) != XMLRPC_TYPE_ARRAY) xmlrpc_env_set_fault_formatted( envP, XMLRPC_TYPE_ERROR, "Value to be decomposed is of type " "%s, but the '(...)' specifier requires type ARRAY", xmlrpc_type_name(xmlrpc_value_type(valueP))); else parsearray(envP, valueP, decompRootP->store.Tarray, oldstyleMemMgmt); break; case '{': if (xmlrpc_value_type(valueP) != XMLRPC_TYPE_STRUCT) xmlrpc_env_set_fault_formatted( envP, XMLRPC_TYPE_ERROR, "Value to be decomposed is of type " "%s, but the '{...}' specifier requires type STRUCT", xmlrpc_type_name(xmlrpc_value_type(valueP))); else parsestruct(envP, valueP, decompRootP->store.Tstruct, oldstyleMemMgmt); break; default: /* Every format character that is allowed in a decomposition tree node is handled above. */ XMLRPC_ASSERT(false); } }
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; }