本文整理汇总了C++中xmlrpc_env_init函数的典型用法代码示例。如果您正苦于以下问题:C++ xmlrpc_env_init函数的具体用法?C++ xmlrpc_env_init怎么用?C++ xmlrpc_env_init使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xmlrpc_env_init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testOneDouble
static void
testOneDouble(double const value) {
/* Test serialize of a double. */
xmlrpc_env env;
xmlrpc_value * valueP;
xmlrpc_mem_block * serializedP;
char * result;
/* serialized result, as asciiz string */
size_t resultLength;
/* Length in characters of the serialized result */
double serializedValue;
char nextChar;
int itemsMatched;
xmlrpc_env_init(&env);
/* Build a double to serialize */
valueP = xmlrpc_double_new(&env, value);
TEST_NO_FAULT(&env);
/* Serialize the value. */
serializedP = XMLRPC_MEMBLOCK_NEW(char, &env, 0);
TEST_NO_FAULT(&env);
xmlrpc_serialize_value(&env, serializedP, valueP);
TEST_NO_FAULT(&env);
/* Make sure we serialized the correct value. Note that because
doubles aren't precise, this might serialize as 3.1415899999
or something like that. So we check it arithmetically.
*/
resultLength = XMLRPC_MEMBLOCK_SIZE(char, serializedP);
result = malloc(resultLength + 1);
memcpy(result, XMLRPC_MEMBLOCK_CONTENTS(char, serializedP), resultLength);
result[resultLength] = '\0';
itemsMatched = sscanf(result,
"<value><double>%lf</double></value>\r\n%c",
&serializedValue, &nextChar);
TEST(itemsMatched == 1);
TESTFLOATEQUAL(serializedValue, value);
free(result);
/* Clean up our value. */
XMLRPC_TYPED_MEM_BLOCK_FREE(char, serializedP);
xmlrpc_DECREF(valueP);
xmlrpc_env_clean(&env);
}
示例2: main
int
main(int const argc,
const char ** const argv) {
const char * const serverUrl = "http://localhost:8080/RPC2";
xmlrpc_env env;
struct xmlrpc_clientparms clientParms;
xmlrpc_client * clientP;
if (argc-1 > 0) {
fprintf(stderr, "This program has no arguments\n");
exit(1);
}
setupSignalHandlers();
/* Initialize our error-handling environment. */
xmlrpc_env_init(&env);
/* Required before any use of Xmlrpc-c client library: */
xmlrpc_client_setup_global_const(&env);
die_if_fault_occurred(&env);
clientParms.transport = "curl";
/* Create a client object */
xmlrpc_client_create(&env, 0, NULL, NULL,
&clientParms, XMLRPC_CPSIZE(transport),
&clientP);
die_if_fault_occurred(&env);
xmlrpc_client_set_interrupt(clientP, &interrupt);
/* If our server is running 'xmlrpc_sample_add_server' normally, the
RPC will finish almost instantly. UNLESS the adder is 1, in which
case said server is programmed to take 3 seconds to do the
computation, thus allowing us to demonstrate a timeout or CTL-C.
*/
addInterruptibly(clientP, serverUrl, 5, 7);
/* Should finish instantly */
addInterruptibly(clientP, serverUrl, 5, 1);
/* Should time out after 2 seconds */
xmlrpc_env_clean(&env);
xmlrpc_client_destroy(clientP);
xmlrpc_client_teardown_global_const();
return 0;
}
示例3: sigtermHandler
static void sigtermHandler(int const signalClass) {
xmlrpc_env env;
xmlrpc_env_init(&env);
xmlrpc_server_abyss_terminate(&env, serverToTerminateP);
dieIfFailed("xmlrpc_server_abyss_terminate", &env);
xmlrpc_env_clean(&env);
}
示例4: soup_rpc_callback
static void
soup_rpc_callback (SoupServerContext *context, SoupMessage *msg, gpointer data)
{
xmlrpc_env env;
xmlrpc_mem_block *output;
const char *username;
RCDIdentity *identity = NULL;
RCDRPCMethodData *method_data;
xmlrpc_env_init (&env);
method_data = g_new0 (RCDRPCMethodData, 1);
/* Get the username from the auth context and get its identity */
username = soup_server_auth_get_user (context->auth);
if (strcmp (username, rcd_prefs_get_mid ()) == 0) {
identity = rcd_identity_new ();
identity->username = g_strdup ("server");
identity->privileges = rcd_privileges_from_string ("superuser");
}
else
identity = rcd_identity_lookup (username);
g_assert (identity != NULL);
method_data->host = soup_server_context_get_client_host (context);
method_data->identity = identity;
output = process_rpc_call (
&env, msg->request.body, msg->request.length, method_data);
rcd_identity_free (method_data->identity);
g_free (method_data);
soup_message_add_header (msg->response_headers,
"Server", "Red Carpet Daemon/"VERSION);
if (env.fault_occurred) {
soup_message_set_status (msg, SOUP_STATUS_BAD_REQUEST);
return;
}
/* Let Soup free the data for us */
msg->response.owner = SOUP_BUFFER_SYSTEM_OWNED;
msg->response.length = XMLRPC_TYPED_MEM_BLOCK_SIZE(char, output);
msg->response.body = g_memdup(
XMLRPC_TYPED_MEM_BLOCK_CONTENTS(char, output), msg->response.length);
soup_message_set_status (msg, SOUP_STATUS_OK);
xmlrpc_mem_block_free(output);
} /* soup_rpc_callback */
示例5: stop_flows
static void stop_flows(const char* address)
{
xmlrpc_env env;
xmlrpc_client *client = 0;
xmlrpc_value * resultP = 0;
int port = DEFAULT_LISTEN_PORT;
bool is_ipv6 = false;
char *arg, *url = 0;
char *rpc_address = arg = strdup(address);
struct sockaddr_in6 source_in6;
source_in6.sin6_family = AF_INET6;
parse_rpc_address(&rpc_address, &port, &is_ipv6);
if (is_ipv6 && (inet_pton(AF_INET6, rpc_address,
(char*)&source_in6.sin6_addr) <= 0))
errx("invalid IPv6 address '%s' for RPC", rpc_address);
if (port < 1 || port > 65535)
errx("invalid port for RPC");
int rc = 0;
if (is_ipv6)
rc = asprintf(&url, "http://[%s]:%d/RPC2", rpc_address, port);
else
rc = asprintf(&url, "http://%s:%d/RPC2", rpc_address, port);
if (rc == -1)
critx("could not allocate memory for RPC URL");
printf("Stopping all flows on %s\n", url);
/* Stop the flows */
xmlrpc_env_init(&env);
xmlrpc_client_create(&env, XMLRPC_CLIENT_NO_FLAGS, "Flowgrind", FLOWGRIND_VERSION, NULL, 0, &client);
if (env.fault_occurred)
goto cleanup;
xmlrpc_client_call2f(&env, client, url, "stop_flow", &resultP,
"({s:i})", "flow_id", -1); /* -1 stops all flows */
if (resultP)
xmlrpc_DECREF(resultP);
cleanup:
if (env.fault_occurred) {
warnx("could not stop flows on %s: %s (%d)",
url, env.fault_string, env.fault_code);
}
if (client)
xmlrpc_client_destroy(client);
xmlrpc_env_clean(&env);
free_all(arg, url);
}
示例6: main
int main(int argc, char **argv)
{
abrt_init(argv);
map_string_h *settings = new_map_string();
const char *dump_dir_name = ".";
GList *conf_file = NULL;
/* Can't keep these strings/structs static: _() doesn't support that */
const char *program_usage_string = _(
"\b [-v] -c CONFFILE -d DIR\n"
"\n"
"Reports problem to Bugzilla"
);
enum {
OPT_v = 1 << 0,
OPT_d = 1 << 1,
OPT_c = 1 << 2,
};
/* Keep enum above and order of options below in sync! */
struct options program_options[] = {
OPT__VERBOSE(&g_verbose),
OPT_STRING('d', NULL, &dump_dir_name, "DIR" , _("Dump directory")),
OPT_LIST( 'c', NULL, &conf_file , "FILE", _("Configuration file (may be given many times)")),
OPT_END()
};
/*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage_string);
export_abrt_envvars(0);
while (conf_file)
{
char *fn = (char *)conf_file->data;
VERB1 log("Loading settings from '%s'", fn);
load_conf_file(fn, settings, /*skip key w/o values:*/ true);
VERB3 log("Loaded '%s'", fn);
conf_file = g_list_remove(conf_file, fn);
}
VERB1 log("Initializing XML-RPC library");
xmlrpc_env env;
xmlrpc_env_init(&env);
xmlrpc_client_setup_global_const(&env);
if (env.fault_occurred)
error_msg_and_die("XML-RPC Fault: %s(%d)", env.fault_string, env.fault_code);
xmlrpc_env_clean(&env);
report_to_bugzilla(dump_dir_name, settings);
free_map_string(settings);
return 0;
}
示例7: xmlrpc_env_init
/**************************************
* XmlHandler
* Constructor
*************************************/
XmlHandler::XmlHandler()
{
xmlrpc_env env;
//Build the enviroment
xmlrpc_env_init(&env);
//Creamos el registro
registry = xmlrpc_registry_new(&env);
//Clean env
xmlrpc_env_clean(&env);
}
示例8: rhbz_array_size
/* The only way this can fail is if arrayP is not actually an array XML-RPC
* value. So it is usually not worth checking *envP.
* die or return size of array
*/
unsigned rhbz_array_size(xmlrpc_value *xml)
{
func_entry();
xmlrpc_env env;
xmlrpc_env_init(&env);
unsigned size = xmlrpc_array_size(&env, xml);
if (env.fault_occurred)
abrt_xmlrpc_die(&env);
return size;
}
示例9: processCall
static void
processCall(TSession * const abyssSessionP,
size_t const contentSize,
xmlrpc_registry * const registryP,
bool const wantChunk,
const char * const trace) {
/*----------------------------------------------------------------------------
Handle an RPC request. This is an HTTP request that has the proper form
to be an XML-RPC call.
The text of the call is available through the Abyss session
'abyssSessionP'.
Its content length is 'contentSize' bytes.
-----------------------------------------------------------------------------*/
xmlrpc_env env;
if (trace)
fprintf(stderr,
"xmlrpc_server_abyss URI path handler processing RPC.\n");
xmlrpc_env_init(&env);
if (contentSize > xmlrpc_limit_get(XMLRPC_XML_SIZE_LIMIT_ID))
xmlrpc_env_set_fault_formatted(
&env, XMLRPC_LIMIT_EXCEEDED_ERROR,
"XML-RPC request too large (%d bytes)", contentSize);
else {
xmlrpc_mem_block * body;
/* Read XML data off the wire. */
getBody(&env, abyssSessionP, contentSize, trace, &body);
if (!env.fault_occurred) {
xmlrpc_mem_block * output;
/* Process the RPC. */
xmlrpc_registry_process_call2(
&env, registryP,
XMLRPC_MEMBLOCK_CONTENTS(char, body),
XMLRPC_MEMBLOCK_SIZE(char, body),
abyssSessionP,
&output);
if (!env.fault_occurred) {
/* Send out the result. */
sendXmlData(&env, abyssSessionP,
XMLRPC_MEMBLOCK_CONTENTS(char, output),
XMLRPC_MEMBLOCK_SIZE(char, output),
wantChunk);
XMLRPC_MEMBLOCK_FREE(char, output);
}
XMLRPC_MEMBLOCK_FREE(char, body);
}
示例10: main
int
main(int const argc,
const char ** const argv) {
struct xmlrpc_method_info3 const methodInfo = {
/* .methodName = */ "sample.add",
/* .methodFunction = */ &sample_add,
};
xmlrpc_server_abyss_parms serverparm;
xmlrpc_registry * registryP;
xmlrpc_env env;
if (argc-1 != 1) {
fprintf(stderr, "You must specify 1 argument: The TCP port "
"number on which the server will accept connections "
"for RPCs (8080 is a common choice). "
"You specified %d arguments.\n", argc-1);
exit(1);
}
xmlrpc_env_init(&env);
registryP = xmlrpc_registry_new(&env);
if (env.fault_occurred) {
printf("xmlrpc_registry_new() failed. %s\n", env.fault_string);
exit(1);
}
xmlrpc_registry_add_method3(&env, registryP, &methodInfo);
if (env.fault_occurred) {
printf("xmlrpc_registry_add_method3() failed. %s\n",
env.fault_string);
exit(1);
}
serverparm.config_file_name = NULL; /* Select the modern normal API */
serverparm.registryP = registryP;
serverparm.port_number = atoi(argv[1]);
serverparm.log_file_name = "/tmp/xmlrpc_log";
printf("Running XML-RPC server...\n");
xmlrpc_server_abyss(&env, &serverparm, XMLRPC_APSIZE(log_file_name));
if (env.fault_occurred) {
printf("xmlrpc_server_abyss() failed. %s\n", env.fault_string);
exit(1);
}
/* xmlrpc_server_abyss() never returns unless it fails */
return 0;
}
示例11: test_value_string_wide_line
static void
test_value_string_wide_line(void) {
/* Test with various line delimiters */
#if HAVE_UNICODE_WCHAR
xmlrpc_env env;
xmlrpc_value * valueP;
const wchar_t * wcs;
size_t len;
wchar_t const wcs_lines[] = {'\n', '\r', '\r', '\n', '\0'};
wchar_t const wcs_lines_lf[] = {'\n', '\n', '\n'};
wchar_t const wcs_lines_crlf[] = {
'\r', '\n', '\r', '\n', '\r', '\n' };
xmlrpc_env_init(&env);
valueP = xmlrpc_string_w_new(&env, wcs_lines);
TEST_NO_FAULT(&env);
xmlrpc_read_string_w_lp(&env, valueP, &len, &wcs);
TEST_NO_FAULT(&env);
TEST(len == 3);
TEST(wcs[len] == '\0');
TEST(wcsneq(wcs, wcs_lines_lf, len));
free((void*)wcs);
xmlrpc_read_string_w_lp_crlf(&env, valueP, &len, &wcs);
TEST_NO_FAULT(&env);
TEST(len == 6);
TEST(wcs[len] == '\0');
TEST(wcsneq(wcs, wcs_lines_crlf, len));
free((void*)wcs);
xmlrpc_DECREF(valueP);
valueP = xmlrpc_string_w_new_cr(&env, wcs_lines);
TEST_NO_FAULT(&env);
xmlrpc_read_string_w_lp(&env, valueP, &len, &wcs);
TEST_NO_FAULT(&env);
TEST(len == 4);
TEST(wcs[len] == '\0');
TEST(wcsneq(wcs, wcs_lines, len));
free((void*)wcs);
xmlrpc_DECREF(valueP);
xmlrpc_env_clean(&env);
#endif /* HAVE_UNICODE_WCHAR */
}
示例12: test_xml_size_limit
static void
test_xml_size_limit(void) {
xmlrpc_env env;
const char * methodName;
xmlrpc_value * paramsP;
/* NOTE - This test suite only verifies the last-ditch size-checking
code. There should also be matching code in all server (and
preferably all client) modules as well.
*/
/* Set our XML size limit to something ridiculous. */
xmlrpc_limit_set(XMLRPC_XML_SIZE_LIMIT_ID, 6);
/* Attempt to parse a call. */
xmlrpc_env_init(&env);
xmlrpc_parse_call(&env, serialized_call, strlen(serialized_call),
&methodName, ¶msP);
TEST_FAULT(&env, XMLRPC_LIMIT_EXCEEDED_ERROR);
xmlrpc_env_clean(&env);
{
xmlrpc_value * resultP;
int faultCode;
const char * faultString;
/* Attempt to parse a response. */
xmlrpc_env_init(&env);
xmlrpc_parse_response2(&env,
good_response_xml, strlen(good_response_xml),
&resultP, &faultCode, &faultString);
TEST_FAULT(&env, XMLRPC_LIMIT_EXCEEDED_ERROR);
xmlrpc_env_clean(&env);
}
/* Reset the default limit. */
xmlrpc_limit_set(XMLRPC_XML_SIZE_LIMIT_ID, XMLRPC_XML_SIZE_LIMIT_DEFAULT);
}
示例13: get_int_from_struct_by_idx
/* FIXME terminates the program if it fails */
int get_int_from_struct_by_idx(xmlrpc_value *structP, int index, int *rv)
{
xmlrpc_env env;
xmlrpc_env_init(&env);
xmlrpc_value *keyP;
xmlrpc_value *valueP;
xmlrpc_struct_read_member(&env, structP, index, &keyP, &valueP); /* increment refcount of returned values */
die_if_fault_occurred_line(&env, __LINE__);
xmlrpc_read_int(&env, valueP, rv);
die_if_fault_occurred_line(&env, __LINE__);
xmlrpc_DECREF(valueP);
return 1;
}
示例14: test_value_type_mismatch
static void
test_value_type_mismatch(void) {
xmlrpc_value * v;
xmlrpc_env env;
xmlrpc_env env2;
char * str;
/* Test for one, simple kind of type mismatch error. We assume that
** if one of these typechecks works, the rest work fine. */
xmlrpc_env_init(&env);
xmlrpc_env_init(&env2);
v = xmlrpc_build_value(&env, "i", (xmlrpc_int32) 5);
TEST_NO_FAULT(&env);
xmlrpc_decompose_value(&env2, v, "s", &str);
xmlrpc_DECREF(v);
TEST_FAULT(&env2, XMLRPC_TYPE_ERROR);
xmlrpc_env_clean(&env2);
xmlrpc_env_clean(&env);
}
示例15: test_value_missing_struct_delim
static void
test_value_missing_struct_delim(void) {
xmlrpc_value * v;
xmlrpc_env env;
/* Test missing closing brace on struct */
xmlrpc_env_init(&env);
v = xmlrpc_build_value(&env, "{");
TEST_FAULT(&env, XMLRPC_INTERNAL_ERROR);
xmlrpc_env_clean(&env);
xmlrpc_env_init(&env);
v = xmlrpc_build_value(&env, "{s:i", "key1", 7);
TEST_FAULT(&env, XMLRPC_INTERNAL_ERROR);
xmlrpc_env_clean(&env);
xmlrpc_env_init(&env);
v = xmlrpc_build_value(&env, "{s:i,s:i", "key1", 9, "key2", -4);
TEST_FAULT(&env, XMLRPC_INTERNAL_ERROR);
xmlrpc_env_clean(&env);
}