Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
test_xmlrpc.c File Reference
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include "gwlib/gwlib.h"
#include "gwlib/http.h"
#include "gwlib/xmlrpc.h"

Go to the source code of this file.

Macros

#define MAX_THREADS   1024
 
#define MAX_IN_QUEUE   128
 

Functions

static void start_request (HTTPCaller *caller, List *reqh, long i)
 
static int receive_reply (HTTPCaller *caller)
 
static void client_thread (void *arg)
 
static void help (void)
 
int main (int argc, char **argv)
 

Variables

static Countercounter = NULL
 
static long max_requests = 1
 
static Octstrauth_username = NULL
 
static Octstrauth_password = NULL
 
static Octstrssl_client_certkey_file = NULL
 
static Octstrextra_headers = NULL
 
static Octstrcontent_file = NULL
 
static Octstrurl = NULL
 
static int file = 0
 
static XMLRPCDocumentmsg
 

Macro Definition Documentation

#define MAX_IN_QUEUE   128

Definition at line 74 of file test_xmlrpc.c.

Referenced by client_thread().

#define MAX_THREADS   1024

Definition at line 73 of file test_xmlrpc.c.

Referenced by main().

Function Documentation

static void client_thread ( void *  arg)
static

Definition at line 188 of file test_xmlrpc.c.

References caller, counter_increase(), gwlist_create, gwthread_self(), gwthread_sleep(), http_add_basic_auth(), http_caller_destroy(), http_header_add(), info(), MAX_IN_QUEUE, max_requests, receive_reply(), and start_request().

Referenced by main().

189 {
190  List *reqh;
191  long i, succeeded, failed;
193  char buf[1024];
194  long in_queue;
195 
196  caller = arg;
197  succeeded = 0;
198  failed = 0;
199  reqh = gwlist_create();
200 
201  sprintf(buf, "%ld", (long) gwthread_self());
202  http_header_add(reqh, "X-Thread", buf);
203  if (auth_username != NULL && auth_password != NULL)
205 
206  in_queue = 0;
207 
208  for (;;) {
209  while (in_queue < MAX_IN_QUEUE) {
211  if (i >= max_requests)
212  goto receive_rest;
213  start_request(caller, reqh, i);
214 #if 1
215  gwthread_sleep(0.1);
216 #endif
217  ++in_queue;
218  }
219  while (in_queue >= MAX_IN_QUEUE) {
220  if (receive_reply(caller) == -1)
221  ++failed;
222  else
223  ++succeeded;
224  --in_queue;
225  }
226  }
227 
228 receive_rest:
229  while (in_queue > 0) {
230  if (receive_reply(caller) == -1)
231  ++failed;
232  else
233  ++succeeded;
234  --in_queue;
235  }
236 
237  http_caller_destroy(caller);
238  info(0, "This thread: %ld succeeded, %ld failed.", succeeded, failed);
239 }
void info(int err, const char *fmt,...)
Definition: log.c:636
static int receive_reply(HTTPCaller *caller)
Definition: test_xmlrpc.c:113
long gwthread_self(void)
void http_header_add(List *headers, char *name, char *contents)
Definition: http.c:2863
static HTTPCaller * caller
Definition: smsbox.c:429
void http_add_basic_auth(List *headers, Octstr *username, Octstr *password)
Definition: http.c:3492
unsigned long counter_increase(Counter *counter)
Definition: counter.c:123
#define MAX_IN_QUEUE
Definition: test_xmlrpc.c:74
static Counter * counter
Definition: test_xmlrpc.c:76
static long max_requests
Definition: test_xmlrpc.c:77
void gwthread_sleep(double seconds)
static Octstr * auth_username
Definition: test_xmlrpc.c:79
#define gwlist_create()
Definition: list.h:136
static Octstr * auth_password
Definition: test_xmlrpc.c:80
void http_caller_destroy(HTTPCaller *caller)
Definition: http.c:907
static void start_request(HTTPCaller *caller, List *reqh, long i)
Definition: test_xmlrpc.c:89
Definition: list.c:102
static void help ( void  )
static

Definition at line 242 of file test_xmlrpc.c.

References info().

Referenced by main().

243 {
244  info(0, "Usage: test_xmlrpc [options] xml_source");
245  info(0, "where options are:");
246  info(0, "-u URL");
247  info(0, " send XML-RPC source as POST HTTP request to URL");
248  info(0, "-v number");
249  info(0, " set log level for stderr logging");
250  info(0, "-q");
251  info(0, " don't print the body or headers of the HTTP response");
252  info(0, "-r number");
253  info(0, " make `number' requests, repeating URLs as necessary");
254  info(0, "-p domain.name");
255  info(0, " use `domain.name' as a proxy");
256  info(0, "-P portnumber");
257  info(0, " connect to proxy at port `portnumber'");
258  info(0, "-S");
259  info(0, " use HTTPS scheme to access SSL-enabled proxy server");
260  info(0, "-e domain1:domain2:...");
261  info(0, " set exception list for proxy use");
262  info(0, "-s");
263  info(0, " use HTTPS scheme to access SSL-enabled HTTP server");
264  info(0, "-c ssl_client_cert_key_file");
265  info(0, " use this file as the SSL certificate and key file");
266 }
void info(int err, const char *fmt,...)
Definition: log.c:636
int main ( int  argc,
char **  argv 
)

Definition at line 269 of file test_xmlrpc.c.

References client_thread(), counter_create(), counter_destroy(), error(), file, getopt(), gwlib_init(), gwlib_shutdown(), gwlist_append(), gwlist_create, gwlist_destroy(), gwthread_create, gwthread_join(), help(), http_caller_create(), http_use_proxy(), info(), log_set_output_level(), max_requests, MAX_THREADS, octstr_create, octstr_destroy(), octstr_destroy_item(), octstr_get_cstr, octstr_print(), octstr_read_file(), optarg, optind, panic, proxy_password, proxy_port, proxy_ssl, proxy_username, ssl, start, threads, XMLRPC_COMPILE_OK, xmlrpc_destroy_call, xmlrpc_parse_call, xmlrpc_parse_error(), xmlrpc_parse_status(), and xmlrpc_print_call.

270 {
271  int i, opt, num_threads;
272  Octstr *proxy;
273  List *exceptions;
274  long proxy_port;
275  int proxy_ssl = 0;
278  Octstr *exceptions_regex;
279  char *p;
280  long threads[MAX_THREADS];
281  time_t start, end;
282  double run_time;
283  Octstr *output, *xml_doc;
284  int ssl = 0;
285 
286  gwlib_init();
287 
288  proxy = NULL;
289  proxy_port = -1;
290  exceptions = gwlist_create();
291  proxy_username = NULL;
292  proxy_password = NULL;
293  exceptions_regex = NULL;
294  num_threads = 0;
295  file = 0;
296 
297  while ((opt = getopt(argc, argv, "hvr:t:p:u:P:Se:a:sc:")) != EOF) {
298  switch (opt) {
299  case 'h':
300  help();
301  exit(1);
302  break;
303 
304  case 'v':
306  break;
307 
308  case 'r':
309  max_requests = atoi(optarg);
310  break;
311 
312  case 't':
313  num_threads = atoi(optarg);
314  if (num_threads > MAX_THREADS)
315  num_threads = MAX_THREADS;
316  break;
317 
318  case 'p':
319  proxy = octstr_create(optarg);
320  break;
321 
322  case 'u':
324  break;
325 
326  case 'P':
327  proxy_port = atoi(optarg);
328  break;
329 
330  case 'S':
331  proxy_ssl = 1;
332  break;
333 
334  case 'e':
335  p = strtok(optarg, ":");
336  while (p != NULL) {
337  gwlist_append(exceptions, octstr_create(p));
338  p = strtok(NULL, ":");
339  }
340  break;
341 
342  case 'E':
343  exceptions_regex = octstr_create(optarg);
344  break;
345 
346  case 'a':
347  p = strtok(optarg, ":");
348  if (p != NULL) {
350  p = strtok(NULL, "");
351  if (p != NULL)
353  }
354  break;
355 
356  case 's':
357  ssl = 1;
358  break;
359 
360  case 'c':
363  break;
364 
365  case '?':
366  default:
367  error(0, "Invalid option %c", opt);
368  help();
369  panic(0, "Stopping");
370  break;
371  }
372  }
373 
374  if (optind >= argc) {
375  error(0, "Missing arguments");
376  help();
377  panic(0, "Stopping");
378  }
379 
380 #ifdef HAVE_LIBSSL
381  /*
382  * check if we are doing a SSL-enabled client version here
383  * load the required cert and key file
384  */
385  if (ssl || proxy_ssl) {
386  if (ssl_client_certkey_file != NULL) {
387  conn_use_global_client_certkey_file(ssl_client_certkey_file);
388  } else {
389  panic(0, "client certkey file need to be given!");
390  }
391  }
392 #endif
393 
394  if (proxy != NULL && proxy_port > 0) {
395  http_use_proxy(proxy, proxy_port, proxy_ssl, exceptions,
396  proxy_username, proxy_password,
397  exceptions_regex);
398  }
399  octstr_destroy(proxy);
400  octstr_destroy(proxy_username);
401  octstr_destroy(proxy_password);
402  octstr_destroy(exceptions_regex);
403  gwlist_destroy(exceptions, octstr_destroy_item);
404 
406 
407  xml_doc = octstr_read_file(argv[optind]);
408  if (xml_doc == NULL)
409  panic(0, "Cannot read the XML document");
410 
411  /*
412  * parse the XML source
413  */
414  msg = xmlrpc_parse_call(xml_doc);
415 
417  ((output = xmlrpc_parse_error(msg)) != NULL)) {
418  /* parse failure */
419  error(0, "%s", octstr_get_cstr(output));
420  octstr_destroy(output);
421  }
422 
423  /*
424  * if no POST is desired then dump the re-formated XML
425  */
426  if (url != NULL) {
427 
428  time(&start);
429  if (num_threads == 0)
431  else {
432  for (i = 0; i < num_threads; ++i)
434  for (i = 0; i < num_threads; ++i)
435  gwthread_join(threads[i]);
436  }
437  time(&end);
438 
439 
440  run_time = difftime(end, start);
441  info(0, "%ld requests in %f seconds, %f requests/s.",
442  max_requests, run_time, max_requests / run_time);
443 
445 
446  } else {
447  output = xmlrpc_print_call(msg);
448  if (output != NULL) {
449  octstr_print(stderr, output);
450  octstr_destroy(output);
451  }
452  }
453 
460 
461 
463  octstr_destroy(xml_doc);
464 
465  gwlib_shutdown();
466 
467  return 0;
468 }
void error(int err, const char *fmt,...)
Definition: log.c:612
void info(int err, const char *fmt,...)
Definition: log.c:636
int threads
Definition: fakewap.c:239
int ssl
void counter_destroy(Counter *counter)
Definition: counter.c:110
void gwlist_append(List *list, void *item)
Definition: list.c:179
void gwthread_join(long thread)
static Octstr * content_file
Definition: test_xmlrpc.c:83
int optind
Definition: attgetopt.c:80
static Octstr * ssl_client_certkey_file
Definition: test_xmlrpc.c:81
int octstr_print(FILE *f, Octstr *ostr)
Definition: octstr.c:1189
static int proxy_ssl
Definition: http.c:202
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static void help(void)
Definition: test_xmlrpc.c:242
int xmlrpc_parse_status(XMLRPCDocument *xrdoc)
Definition: xmlrpc.c:1348
int getopt(int argc, char **argv, char *opts)
Definition: attgetopt.c:84
#define xmlrpc_parse_call(post_body)
Definition: xmlrpc.h:161
Counter * counter_create(void)
Definition: counter.c:94
void log_set_output_level(enum output_level level)
Definition: log.c:217
static Counter * counter
Definition: test_xmlrpc.c:76
static int proxy_port
Definition: http.c:201
static long max_requests
Definition: test_xmlrpc.c:77
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
static Octstr * proxy_username
Definition: http.c:203
#define gwthread_create(func, arg)
Definition: gwthread.h:90
#define octstr_create(cstr)
Definition: octstr.h:125
void octstr_destroy_item(void *os)
Definition: octstr.c:334
static void client_thread(void *arg)
Definition: test_xmlrpc.c:188
Octstr * octstr_read_file(const char *filename)
Definition: octstr.c:1546
static Octstr * auth_username
Definition: test_xmlrpc.c:79
static int file
Definition: test_xmlrpc.c:85
Definition: octstr.c:118
void http_use_proxy(Octstr *hostname, int port, int ssl, List *exceptions, Octstr *username, Octstr *password, Octstr *exceptions_regex)
Definition: http.c:268
#define xmlrpc_destroy_call(call)
Definition: xmlrpc.h:165
char * optarg
Definition: attgetopt.c:82
#define panic
Definition: log.h:87
HTTPCaller * http_caller_create(void)
Definition: http.c:897
void gwlib_shutdown(void)
Definition: gwlib.c:94
#define gwlist_create()
Definition: list.h:136
static Octstr * auth_password
Definition: test_xmlrpc.c:80
#define MAX_THREADS
Definition: test_xmlrpc.c:73
void gwlib_init(void)
Definition: gwlib.c:78
#define xmlrpc_print_call(call)
Definition: xmlrpc.h:187
static Octstr * url
Definition: test_xmlrpc.c:84
Definition: list.c:102
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86
static int start
static Octstr * extra_headers
Definition: test_xmlrpc.c:82
Octstr * xmlrpc_parse_error(XMLRPCDocument *xrdoc)
Definition: xmlrpc.c:1356
static Octstr * proxy_password
Definition: http.c:204
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145
static int receive_reply ( HTTPCaller caller)
static

Definition at line 113 of file test_xmlrpc.c.

References debug(), error(), http_destroy_headers(), http_receive_result, octstr_destroy(), octstr_get_cstr, XMLRPC_COMPILE_OK, xmlrpc_get_faultcode(), xmlrpc_get_faultstring(), xmlrpc_is_fault(), xmlrpc_parse_error(), xmlrpc_parse_response, and xmlrpc_parse_status().

Referenced by client_thread().

114 {
115  void *id;
116  int ret;
117  Octstr *final_url;
118  List *replyh;
119  Octstr *replyb;
120  Octstr *output;
121  XMLRPCDocument *xrdoc;
122  /*
123  Octstr *type, *os_xrdoc, *os;
124  Octstr *charset;
125  */
126 
127  id = http_receive_result(caller, &ret, &final_url, &replyh, &replyb);
128  octstr_destroy(final_url);
129  if (id == NULL || ret == -1) {
130  error(0, "http POST failed");
131  gw_free(id);
132  return -1;
133  }
134  debug("", 0, "Done with request %ld", *(long *) id);
135  gw_free(id);
136 
137 /*
138  http_header_get_content_type(replyh, &type, &charset);
139  debug("", 0, "Content-type is <%s>, charset is <%s>",
140  octstr_get_cstr(type), octstr_get_cstr(charset));
141  octstr_destroy(type);
142  octstr_destroy(charset);
143  if (verbose)
144  debug("", 0, "Reply headers:");
145  while ((os = gwlist_extract_first(replyh)) != NULL) {
146  if (verbose)
147  octstr_dump(os, 1);
148  octstr_destroy(os);
149  }
150  if (verbose) {
151  debug("", 0, "Reply body:");
152  octstr_dump(replyb, 1);
153  }
154 */
155  xrdoc = xmlrpc_parse_response(replyb);
156  debug("", 0, "Parsed xmlrpc");
157 
158  if ((xmlrpc_parse_status(xrdoc) != XMLRPC_COMPILE_OK) &&
159  ((output = xmlrpc_parse_error(xrdoc)) != NULL)) {
160  /* parse failure */
161  error(0, "%s", octstr_get_cstr(output));
162  octstr_destroy(output);
163  return -1;
164  } else {
165  /*parse proper xmlrpc */
166  if (xmlrpc_is_fault(xrdoc)) {
167  Octstr *fstring = xmlrpc_get_faultstring(xrdoc);
168  debug("xr", 0, "Got fault response with code:%ld and description: %s",
169  xmlrpc_get_faultcode(xrdoc),
170  octstr_get_cstr(fstring));
171  octstr_destroy(fstring);
172  http_destroy_headers(replyh);
173  octstr_destroy(replyb);
174  return -1;
175  }
176  /*
177  os_xrdoc = xmlrpc_print_response(xrdoc);
178  debug("xr", 0, "XMLRPC response:");
179  octstr_dump(os_xrdoc, 0);
180  */
181  }
182  http_destroy_headers(replyh);
183  octstr_destroy(replyb);
184  return 0;
185 }
void error(int err, const char *fmt,...)
Definition: log.c:612
int xmlrpc_is_fault(XMLRPCDocument *response)
Definition: xmlrpc.c:1317
long xmlrpc_get_faultcode(XMLRPCDocument *faultresponse)
Definition: xmlrpc.c:1325
#define xmlrpc_parse_response(post_body)
Definition: xmlrpc.h:216
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
int xmlrpc_parse_status(XMLRPCDocument *xrdoc)
Definition: xmlrpc.c:1348
Octstr * xmlrpc_get_faultstring(XMLRPCDocument *faultresponse)
Definition: xmlrpc.c:1335
void http_destroy_headers(List *headers)
Definition: http.c:2856
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define http_receive_result(caller, status, final_url, headers, body)
Definition: http.h:383
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
Definition: list.c:102
Octstr * xmlrpc_parse_error(XMLRPCDocument *xrdoc)
Definition: xmlrpc.c:1356
static void start_request ( HTTPCaller caller,
List reqh,
long  i 
)
static

Definition at line 89 of file test_xmlrpc.c.

References debug(), info(), and xmlrpc_send_call.

Referenced by client_thread().

90 {
91  long *id;
92 
93  if ((i % 1000) == 0)
94  info(0, "Starting fetch %ld", i);
95  id = gw_malloc(sizeof(long));
96  *id = i;
97 
98  /*
99  * not semd the XML-RPC document contained in msg to
100  * the URL 'url' using the POST method
101  */
102  xmlrpc_send_call(msg, caller, url, reqh, id);
103 
104  debug("", 0, "Started request %ld.", *id);
105  /*
106  debug("", 0, "Started request %ld with url:", *id);
107  octstr_url_decode(url);
108  octstr_dump(url, 0);
109  */
110 }
void info(int err, const char *fmt,...)
Definition: log.c:636
#define xmlrpc_send_call(call, http_ref, url, headers, ref)
Definition: xmlrpc.h:197
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
static Octstr * url
Definition: test_xmlrpc.c:84
static XMLRPCDocument * msg
Definition: test_xmlrpc.c:86

Variable Documentation

Octstr* auth_password = NULL
static

Definition at line 80 of file test_xmlrpc.c.

Octstr* auth_username = NULL
static

Definition at line 79 of file test_xmlrpc.c.

Octstr* content_file = NULL
static

Definition at line 83 of file test_xmlrpc.c.

Counter* counter = NULL
static

Definition at line 76 of file test_xmlrpc.c.

Octstr* extra_headers = NULL
static

Definition at line 82 of file test_xmlrpc.c.

int file = 0
static

Definition at line 85 of file test_xmlrpc.c.

Referenced by main().

long max_requests = 1
static

Definition at line 77 of file test_xmlrpc.c.

Referenced by client_thread(), and main().

XMLRPCDocument* msg
static

Definition at line 86 of file test_xmlrpc.c.

Referenced by at2_pdu_decode(), at2_send_messages(), at2_shutdown_cb(), at2_wait_modem_command(), bb_remove_message(), boxc_receiver(), boxc_sender(), boxc_sent_pop(), brunet_receive_sms(), cgw_handle_op(), cgw_open_send_connection(), cgw_send_loop(), cgw_sender(), cgw_shutdown_cb(), cimd2_accept_delivery_report_message(), cimd2_shutdown_cb(), cmp_route(), concat_handling_check_and_handle(), concat_handling_clear_old_parts(), data_sm_to_msg(), destroy_concatMsg(), dispatch(), dispatch_datagram(), dlr_find(), dlr_spool_add(), dlr_spool_get(), do_dump(), emi2_do_send(), emi2_sender(), emi_receive_msg(), empty_msg_lists(), fake_listener(), generic_receive_sms(), handle_operation(), handle_pdu(), heartbeat_thread(), http_queue_thread(), httpsmsc_send_cb(), httpsmsc_sender(), identify_to_bearerbox(), io_thread(), kannel_receive_sms(), main(), main_connection_loop(), msg_create_real(), msg_to_bb(), msg_unpack_real(), obey_request_thread(), ois_append_to_list(), ois_delete_queue(), ois_deliver_sm_invoke(), oisd_accept_delivery_report_message(), oisd_accept_message(), oisd_handle_request(), oisd_shutdown_cb(), open_send_connection(), ota_tokenize_bookmarks(), ota_tokenize_settings(), pack_ip_datagram(), pack_sms_datagram(), pdu_to_msg(), randomize(), read_from_box(), read_messages_from_bearerbox(), reconnect(), run_batch(), run_connects(), run_requests(), run_smsbox(), sema_msg_new(), send_messages(), send_pdu(), service_router(), shutdown_cb(), smpp_msg_create(), sms_router(), sms_to_smsboxes(), smsbox_req_sendota(), smsbox_sendota_post(), smsbox_thread(), smsbox_xmlrpc_post(), soap_listener(), soap_parse_mo(), soap_read_response(), soap_send_loop(), soap_shutdown_cb(), status_cb(), store_file_for_each_message(), store_file_load(), udp_receiver(), udp_sender(), url_result_thread(), wap_msg_recv(), wdp_create(), wdp_router(), wdp_to_wapboxes(), wrapper_receiver(), wrapper_sender(), wrapper_shutdown(), xidris_receive_sms(), and xml_error().

Octstr* ssl_client_certkey_file = NULL
static

Definition at line 81 of file test_xmlrpc.c.

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.