73 #include <sys/types.h> 74 #include <sys/socket.h> 106 #define WSP_VERSION 0x10 121 static volatile sig_atomic_t
dying = 0;
161 result = (result << 7) | (c & 0x7f);
175 "<?xml version=\"1.0\"?>\n" 176 "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"\n" 177 " \"http://www.wapforum.org/DTD/wml_1.1.xml\">\n" 179 "<card id=\"main\" title=\"Hello, world\" newcontext=\"true\">\n" 180 " <p>Hello, world.</p>\n" 221 panic(0,
"No ports available for http server");
223 port_copy = gw_malloc(
sizeof(*port_copy));
227 panic(0,
"Cannot start http thread");
237 panic(0,
"Couldn't make wapbox port\n");
239 wapbox = accept(wap_socket, NULL, NULL);
241 panic(errno,
"Wapbox could not connect\n");
284 if (
client->wtp_tid == 0x7fff)
299 static unsigned char data[] = { 0x0e, 0x00, 0x00, 0x00 };
312 static unsigned char data[] = { 0x18, 0x00, 0x00 };
318 0x03, 0x80, 0x90, 0x00, 0x03, 0x81, 0x90, 0x00,
319 0x02, 0x82, 0x30, 0x02, 0x83, 0x01, 0x02, 0x84,
320 0x01, 0x28, 0x85, 0x50, 0x58, 0x2d, 0x55, 0x50,
321 0x2d, 0x41, 0x47, 0x45, 0x54, 0x00, 0x51, 0x58,
322 0x2d, 0x55, 0x50, 0x2d, 0x47, 0x45, 0x54, 0x4e,
323 0x4f, 0x54, 0x49, 0x46, 0x59, 0x00, 0x70, 0x58,
324 0x2d, 0x55, 0x50, 0x2d, 0x41, 0x50, 0x4f, 0x53,
325 0x54, 0x00, 0x09, 0x86, 0x02, 0x78, 0x2d, 0x75,
326 0x70, 0x2d, 0x31, 0x00 };
358 c = (tid >> 8) | (c & 0x80);
376 msg->wdp_datagram.source_port =
client->port;
378 msg->wdp_datagram.destination_port = 9201;
389 debug(
"test", 0,
"Sending:");
436 client->wsp_connected = 0;
437 client->wsp_session_id = -1;
438 client->pages_fetched = 0;
469 error(0,
"Unexpected CONNECT reply");
481 client->wsp_connected = 1;
495 error(0,
"Unexpected GET reply");
527 panic(0,
"got packet for nonexisting client %ld",
528 (
long)
reply->wdp_datagram.destination_port);
530 wtp =
reply->wdp_datagram.user_data;
534 debug(
"test", 0,
"Received:");
539 if (
client->wtp_invoked == 0) {
540 error(0,
"Got packet for client that wasn't waiting");
550 error(0,
"Got packet with wrong tid %d, expected %d.",
569 error(0,
"Got unexpected packet");
582 if (
client->wsp_connected == 0) {
610 panic(0,
"Wapbox dead.");
617 panic(0,
"Received bad data from wapbox.");
619 if (
msg->type == wdp_datagram)
627 info(0,
"Timeout. %ld requests unsatisfied.",
634 info(0,
"Usage: drive_wapbox [options...]\n");
635 info(0,
" -r requests Stop after this many; default 1.");
636 info(0,
" -c clients # of concurrent clients; default 1.");
637 info(0,
" -w wapport Port wapbox should connect to; default 30188");
638 info(0,
" -u url Use this url instead of internal http server");
639 info(0,
" -g requests Number of requests per WSP session; default 1");
640 info(0,
" -U Set the User ack flag on all WTP transactions");
643 int main(
int argc,
char **argv) {
645 struct timeval
start, end;
652 while ((opt =
getopt(argc, argv,
"hv:r:c:w:du:Ug:")) != EOF) {
692 error(0,
"Invalid option %c", opt);
694 panic(0,
"Stopping.");
704 if (gettimeofday(&
start, NULL) < 0)
705 panic(errno,
"gettimeofday failed");
707 if (gettimeofday(&end, NULL) < 0)
708 panic(errno,
"gettimeofday failed");
712 run_time = end.tv_sec -
start.tv_sec;
713 run_time += (double) (end.tv_usec -
start.tv_usec) / 1000000.0;
719 info(0,
"%ld request%s in %0.1f seconds, %0.1f requests/s.",
720 completed, completed != 1 ?
"s" :
"",
static Client * find_client(unsigned short port)
void error(int err, const char *fmt,...)
void info(int err, const char *fmt,...)
static int start_http_thread(void)
static Octstr * wtp_ack_create(void)
static void add_wsp_connect(Octstr *pdu)
static long requests_complete
void octstr_append_data(Octstr *ostr, const char *data, long len)
static unsigned short http_port
gw_assert(wtls_machine->packet_to_send !=NULL)
static void http_thread(void *arg)
void gwlist_append(List *list, void *item)
static void start_request(Connection *boxc, Client *client)
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
void gwthread_join(long thread)
static void client(int port)
void octstr_set_bits(Octstr *ostr, long bitpos, int numbits, unsigned long value)
void octstr_append_char(Octstr *ostr, int ch)
static void set_tid(Octstr *pdu, int tid)
static Octstr * wtp_invoke_create(int class)
int conn_eof(Connection *conn)
static long run_requests(Connection *boxc)
static volatile sig_atomic_t dying
static void handle_connect_reply(Connection *boxc, Client *client, Octstr *pdu)
void http_destroy_headers(List *headers)
int getopt(int argc, char **argv, char *opts)
void http_destroy_cgiargs(List *args)
void http_send_reply(HTTPClient *client, int status, List *headers, Octstr *body)
long octstr_get_bits(Octstr *ostr, long bitpos, int numbits)
void * gwlist_extract_first(List *list)
void log_set_output_level(enum output_level level)
HTTPClient * http_accept_request(int port, Octstr **client_ip, Octstr **url, List **headers, Octstr **body, List **cgivars)
void conn_destroy(Connection *conn)
static void handle_reply(Connection *boxc, Msg *reply)
#define octstr_duplicate(ostr)
#define octstr_dump(ostr, level,...)
static void handle_get_reply(Connection *boxc, Client *client, Octstr *pdu)
static void add_wsp_get(Octstr *pdu)
void msg_destroy(Msg *msg)
int make_server_socket(int port, const char *interface_name)
static unsigned long get_varint(Octstr *pdu, int pos)
Octstr * octstr_format(const char *fmt,...)
static void initialize_clients(void)
void octstr_destroy(Octstr *ostr)
#define gwthread_create(func, arg)
#define octstr_create(cstr)
static int wtp_type(Octstr *pdu)
Octstr * conn_read_withlen(Connection *conn)
static void send_invoke_disconnect(Connection *boxc, Client *client)
int http_open_port(int port, int ssl)
int conn_write_withlen(Connection *conn, Octstr *data)
void http_close_all_ports(void)
long octstr_len(const Octstr *ostr)
static void destroy_clients(void)
void octstr_append_uintvar(Octstr *ostr, unsigned long value)
static long http_thread_id
static int get_tid(Octstr *pdu)
static void client_done(Client *client)
int conn_wait(Connection *conn, double seconds)
static long req_per_session
void debug(const char *place, int err, const char *fmt,...)
static void send_invoke_connect(Connection *boxc, Client *client)
void gwlib_shutdown(void)
Octstr * msg_pack(Msg *msg)
static Connection * start_wapbox(void)
static Msg * wdp_create(Octstr *data, Client *client)
static void set_user_ack(Octstr *pdu)
int octstr_get_char(const Octstr *ostr, long pos)
void octstr_set_char(Octstr *ostr, long pos, int ch)
int main(int argc, char **argv)
#define octstr_create_from_data(data, len)
static void send_invoke_get(Connection *boxc, Client *client)
static void send_pdu(Octstr *pdu, Connection *boxc, Client *client)
static XMLRPCDocument * msg
static void add_wsp_disconnect(Octstr *pdu, long session_id)
static void record_disconnect(Client *client)
Connection * conn_wrap_fd(int fd, int ssl)
static void reply(HTTPClient *c, List *push_headers)
static void increment_tid(Client *client)
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)