static void test_value_string_cr(void) { xmlrpc_env env; xmlrpc_value * v; const char * str; size_t len; xmlrpc_env_init(&env); v = xmlrpc_string_new_cr(&env, "foo\r\nbar\r\nbaz"); TEST_NO_FAULT(&env); xmlrpc_read_string(&env, v, &str); TEST_NO_FAULT(&env); TEST(streq(str, "foo\r\nbar\r\nbaz")); xmlrpc_DECREF(v); strfree(str); v = xmlrpc_string_new_lp_cr(&env, 7, "\0foo\rbar"); TEST_NO_FAULT(&env); xmlrpc_read_string_lp(&env, v, &len, &str); TEST_NO_FAULT(&env); TEST(len == 7); TEST(memeq(str, "\0foo\rbar", len)); xmlrpc_DECREF(v); strfree(str); xmlrpc_env_clean(&env); }
char * xr_getStringFromParam (void *data, int index) { CallerP c = (Caller *) data; xmlrpc_value *val = xr_getArrValue (c->param, index); const char *s = (char *) NULL; size_t len; #ifdef OLD_SFP xmlrpc_read_string_lp (c->env, val, &len, &s); /* xmlrpc_read_string (c->env, val, &s); */ xmlrpc_DECREF (val); return (((xr_errstat=c->env->fault_occurred) ? (char *)NULL : (char *)s)); #else int lock; char *str = (char *) NULL; lock = pthread_mutex_lock (&method_mutex); xmlrpc_read_string (c->env, val, (const char **)&s); if (s) { len = strlen (s); str = calloc (1, (len + 1)); strcpy (str, s); free ((void *) s); } xmlrpc_DECREF (val); lock = pthread_mutex_unlock (&method_mutex); return ((char *) str); #endif }
static void readStringLp(xmlrpc_env * const envP, const xmlrpc_value * const valueP, size_t * const lengthP, const char ** const stringValueP, bool const oldstyleMemMgmt) { if (oldstyleMemMgmt) { xmlrpc_read_string_lp_old(envP, valueP, lengthP, stringValueP); } else xmlrpc_read_string_lp(envP, valueP, lengthP, stringValueP); }
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; }
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); }
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 */ }
static void test_value_string_multiline(void) { xmlrpc_env env; xmlrpc_value * v; const char * str; size_t len; xmlrpc_env_init(&env); /* LF line ending */ v = xmlrpc_string_new(&env, "foo\n"); TEST_NO_FAULT(&env); xmlrpc_read_string(&env, v, &str); TEST_NO_FAULT(&env); TEST(streq(str, "foo\n")); strfree(str); xmlrpc_read_string_crlf(&env, v, &str); TEST_NO_FAULT(&env); TEST(streq(str, "foo\r\n")); strfree(str); xmlrpc_DECREF(v); v = xmlrpc_string_new(&env, "foo\n\n"); TEST_NO_FAULT(&env); xmlrpc_read_string(&env, v, &str); TEST_NO_FAULT(&env); TEST(streq(str, "foo\n\n")); strfree(str); xmlrpc_read_string_crlf(&env, v, &str); TEST_NO_FAULT(&env); TEST(streq(str, "foo\r\n\r\n")); strfree(str); xmlrpc_DECREF(v); v = xmlrpc_string_new(&env, "foo\nbar"); TEST_NO_FAULT(&env); xmlrpc_read_string(&env, v, &str); TEST_NO_FAULT(&env); TEST(streq(str, "foo\nbar")); strfree(str); xmlrpc_read_string_crlf(&env, v, &str); TEST_NO_FAULT(&env); TEST(streq(str, "foo\r\nbar")); strfree(str); xmlrpc_DECREF(v); v = xmlrpc_string_new(&env, "foo\nbar\n"); TEST_NO_FAULT(&env); xmlrpc_read_string(&env, v, &str); TEST_NO_FAULT(&env); TEST(streq(str, "foo\nbar\n")); strfree(str); xmlrpc_read_string_crlf(&env, v, &str); TEST_NO_FAULT(&env); TEST(streq(str, "foo\r\nbar\r\n")); strfree(str); xmlrpc_DECREF(v); v = xmlrpc_string_new(&env, "foo\nbar\nbaz"); TEST_NO_FAULT(&env); xmlrpc_read_string(&env, v, &str); TEST_NO_FAULT(&env); TEST(streq(str, "foo\nbar\nbaz")); strfree(str); xmlrpc_read_string_crlf(&env, v, &str); TEST_NO_FAULT(&env); TEST(streq(str, "foo\r\nbar\r\nbaz")); strfree(str); xmlrpc_DECREF(v); /* CR line ending */ v = xmlrpc_string_new(&env, "foo\r"); TEST_NO_FAULT(&env); xmlrpc_read_string(&env, v, &str); TEST_NO_FAULT(&env); TEST(streq(str, "foo\n")); xmlrpc_DECREF(v); strfree(str); v = xmlrpc_string_new(&env, "foo\r\r"); TEST_NO_FAULT(&env); xmlrpc_read_string(&env, v, &str); TEST_NO_FAULT(&env); TEST(streq(str, "foo\n\n")); xmlrpc_DECREF(v); strfree(str); v = xmlrpc_string_new(&env, "foo\rbar"); TEST_NO_FAULT(&env); xmlrpc_read_string(&env, v, &str); TEST_NO_FAULT(&env); TEST(streq(str, "foo\nbar")); xmlrpc_DECREF(v); strfree(str); v = xmlrpc_string_new(&env, "foo\rbar\r"); TEST_NO_FAULT(&env); xmlrpc_read_string(&env, v, &str); TEST_NO_FAULT(&env); TEST(streq(str, "foo\nbar\n")); xmlrpc_DECREF(v); strfree(str); v = xmlrpc_string_new(&env, "foo\rbar\rbaz"); TEST_NO_FAULT(&env); xmlrpc_read_string(&env, v, &str); TEST_NO_FAULT(&env); TEST(streq(str, "foo\nbar\nbaz")); xmlrpc_DECREF(v); strfree(str); /* CRLF line ending */ v = xmlrpc_string_new(&env, "foo\r\n"); TEST_NO_FAULT(&env); xmlrpc_read_string(&env, v, &str); TEST_NO_FAULT(&env); TEST(streq(str, "foo\n")); xmlrpc_DECREF(v); strfree(str); v = xmlrpc_string_new(&env, "foo\r\n\r\n"); TEST_NO_FAULT(&env); xmlrpc_read_string(&env, v, &str); TEST_NO_FAULT(&env); TEST(streq(str, "foo\n\n")); xmlrpc_DECREF(v); strfree(str); v = xmlrpc_string_new(&env, "foo\r\nbar"); TEST_NO_FAULT(&env); xmlrpc_read_string(&env, v, &str); TEST_NO_FAULT(&env); TEST(streq(str, "foo\nbar")); xmlrpc_DECREF(v); strfree(str); v = xmlrpc_string_new(&env, "foo\r\nbar\r\n"); TEST_NO_FAULT(&env); xmlrpc_read_string(&env, v, &str); TEST_NO_FAULT(&env); TEST(streq(str, "foo\nbar\n")); xmlrpc_DECREF(v); strfree(str); v = xmlrpc_string_new(&env, "foo\r\nbar\r\nbaz"); TEST_NO_FAULT(&env); xmlrpc_read_string(&env, v, &str); TEST_NO_FAULT(&env); TEST(streq(str, "foo\nbar\nbaz")); xmlrpc_DECREF(v); strfree(str); /* Embedded null */ v = xmlrpc_string_new_lp(&env, 14, "foo\r\n\0bar\r\nbaz"); TEST_NO_FAULT(&env); xmlrpc_read_string_lp(&env, v, &len, &str); TEST_NO_FAULT(&env); TEST(len == 12); TEST(memeq(str, "foo\n\0bar\nbaz", len)); strfree(str); xmlrpc_read_string_lp_crlf(&env, v, &len, &str); TEST_NO_FAULT(&env); TEST(len == 14); TEST(memeq(str, "foo\r\n\0bar\r\nbaz", len)); strfree(str); xmlrpc_DECREF(v); xmlrpc_env_clean(&env); }
static xmlrpc_value * calculate_modexp(xmlrpc_env * const env, xmlrpc_value * const param_array, void * const serverInfo, void * const channelInfo) { int i = 0; Task temp; xmlrpc_value * retval; xmlrpc_value * arrayP; xmlrpc_decompose_value(env, param_array, "(A)", &arrayP); size_t size = xmlrpc_array_size(env, arrayP); if (env->fault_occurred) retval = NULL; else { for (i = 0; i < size && !env->fault_occurred; ++i) { xmlrpc_value * strctP; strctP = xmlrpc_array_get_item(env, arrayP, i); if (!env->fault_occurred) { if(i == 0) { const char * str1; size_t str1_len; xmlrpc_read_string_lp(env, strctP, &str1_len, &str1); //xmlrpc_int32 curly; //xmlrpc_decompose_value(env, strctP, "(s)",&ip[0]); strcpy(temp._clientid, str1); } else { const char * str1; size_t str1_len; xmlrpc_read_string_lp(env, strctP, &str1_len, &str1); if(i == 1) strcpy(temp.p,str1); else if(i == 2) strcpy(temp.m,str1); } } } } xmlrpc_DECREF(arrayP); if (env->fault_occurred) return NULL; printf("Received: %s %s %s\n",temp._clientid,temp.p,temp.m); /* 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). */ compute_mod(&temp); xmlrpc_value *arr = xmlrpc_array_new(env); xmlrpc_value *v1 = xmlrpc_build_value(env, "s", temp.response); xmlrpc_array_append_item (env,arr,v1); /* Return our result. */ return xmlrpc_build_value(env,"(A)", arr); }