[patch] fakewap: +POST +Connect-debug +hexdump
Jan Kratochvil <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi,
just a little patch. Sorry for the merge of multiple functionalities:
* -C connect-file Supply WSP connect packet in this file
- to be able to reply some suspicious WSP Connect packets
* -P content-type WSP PDU type Post (default is Get)
argument if "" then: text/plain
- read the content to POST from stdin
* input data dumping improved for a better readable hex+ascii output
Regards,
Lace
--
Jan Kratochvil; Captive: free r/w NTFS Filesystem; http://www.jankratochvil.net/
fakewap.c-postetc.patch
(text/plain, 6 KB)
Index: test/fakewap.c
===================================================================
RCS file: /home/cvs/gateway/test/fakewap.c,v
retrieving revision 1.47
diff -u -p -r1.47 fakewap.c
--- test/fakewap.c 19 Feb 2004 07:56:23 -0000 1.47
+++ test/fakewap.c 25 Jun 2004 01:44:08 -0000
@@ -145,6 +145,9 @@ where options are:\n\
-c threads number concurrent of clients simulated (default: 1)\n\
-V protoversion protocol version field, as an integer (default: 0)\n\
-T pdu-type PDU type, as an integer (default: 1)\n\
+-C connect-file Supply WSP connect packet in this file\n\
+-P content-type WSP PDU type Post (default is Get)\n\
+ argument if "" then: text/plain\n\
-t tcl transaction class, as an integer (default: 2)\n\
-n set tid_new flag in packets, forces gateway to flush cache\n\
(default: off)\n\
@@ -207,6 +210,8 @@ int verbose = 0;
int nofailexit = 0;
int writedata = 0;
int test_separation = 0;
+const char *post_content_type = NULL;
+const char *wsp_connect_file = NULL;
/*
* PDU type, version number and transaction class are supplied by a
@@ -228,6 +233,7 @@ unsigned char WTP_Ack[] = {0x18
unsigned char WTP_TidVe[] = {0x1C, 0x00, 0x00 };
unsigned char WTP_Abort[] = {0x20, 0x00, 0x00, 0x00 };
unsigned char WSP_Get[] = {0x0E, 0x00, 0x00, 0x02, 0x40 };
+unsigned char WSP_Post[] = {0x0E, 0x00, 0x00, 0x02, 0x60 };
/* This used to also expect a content-type of 0x94, but that's too difficult
* to check now that Kannel does full header encoding. */
unsigned char WSP_Reply[] = {0x16, 0x80, 0x00, 0x04, 0x20 };
@@ -292,13 +298,27 @@ static void print_msg( const char * trac
*/
static void print_data( const char * trace, unsigned char * msg,
int msg_len ) {
- int i;
+ int i, j;
if (verbose || writedata) {
mutex_lock( mutex );
- printf( "%s (len %d): ", trace, msg_len );
- for (i = 0; i < msg_len && i < msg_len; i++)
- printf( "%c", isprint(msg[i]) ? msg[i] : '_');
+ printf( "%s (len %d)\n", trace, msg_len );
+ for (i = 0; i < msg_len; i+=0x10) {
+ printf( "%04X:",i);
+ for (j = 0; j < 0x10; j++) {
+ if (((i+j)%0x04) == 0)
+ putchar(' ');
+ if (i+j < msg_len)
+ printf( " %02X", msg[i+j] );
+ else
+ fputs( " ", stdout );
+ }
+ fputs( " ", stdout );
+ for (j = 0; j < 0x10 && i+j < msg_len; j++) {
+ putchar((!isprint(msg[i+j]) ? '.' : msg[i+j]));
+ }
+ putchar('\n');
+ }
printf( "\n");
mutex_unlock( mutex );
}
@@ -521,7 +541,7 @@ static void client_session( void * arg)
{
int fd;
int ret;
- int url_len = 0, url_off = 0;
+ int url_len = 0, buf_off = 0;
double nowsec, lastsec, tmp, sleepTime;
long uSleepTime;
struct timeval now;
@@ -564,7 +584,23 @@ static void client_session( void * arg)
old_tid = tid;
tid = next_tid(old_tid);
tid_new = (tid < old_tid); /* Did we wrap? */
- ret = wap_msg_send( fd, WSP_Connect, sizeof(WSP_Connect),
+ memcpy( buf, WSP_Connect, sizeof(WSP_Connect) );
+ buf_off = sizeof(WSP_Connect);
+ if (wsp_connect_file) {
+ FILE *f;
+ size_t fread_got;
+
+ if (!(f = fopen( wsp_connect_file, "r" )))
+ panic(0, "Failed to open wsp_connect_file: %s", wsp_connect_file);
+ buf_off = 4;
+ while (0 < (fread_got = fread( buf+buf_off, 1, sizeof(buf)-buf_off, f))){
+ buf_off += fread_got;
+ if (buf_off >= sizeof(buf))
+ break;
+ }
+ fclose( f );
+ }
+ ret = wap_msg_send( fd, buf, buf_off,
tid, tid_new, NULL, 0 );
if (ret == -1) panic(0, "Send WSP_Connect failed");
@@ -606,12 +642,35 @@ static void client_session( void * arg)
tid = next_tid(old_tid);
tid_new = (tid < old_tid); /* Did we wrap? */
url = choose_message(urls, num_urls);
url_len = strlen(url);
- url_off = StoreVarInt( buf, url_len );
- memcpy( buf+url_off, url, url_len );
- ret = wap_msg_send( fd, WSP_Get, sizeof(WSP_Get), tid, tid_new,
- buf, url_len+url_off );
- if (ret == -1) break;
+ if (!post_content_type){
+ buf_off = 0;
+ buf_off += StoreVarInt( buf+buf_off, url_len );
+ memcpy( buf+buf_off, url, url_len );
+ buf_off += url_len;
+ ret = wap_msg_send( fd, WSP_Get, sizeof(WSP_Get), tid, tid_new,
+ buf, buf_off );
+ if (ret == -1) break;
+ } else {
+ size_t fread_got;
+
+ buf_off = 0;
+ buf_off += StoreVarInt( buf+buf_off, url_len );
+ buf_off += StoreVarInt( buf+buf_off, 0+(strlen(post_content_type)+1) ); /* headers */
+ memcpy( buf+buf_off, url, url_len );
+ buf_off += url_len;
+ strcpy( buf+buf_off, post_content_type );
+ buf_off += strlen(post_content_type)+1; /* +1 for '\0' */
+ while (0 < (fread_got = fread( buf+buf_off, 1, sizeof(buf)-buf_off, stdin))){
+ buf_off += fread_got;
+ if (buf_off >= sizeof(buf))
+ break;
+ }
+ /* headers: none */
+ ret = wap_msg_send( fd, WSP_Post, sizeof(WSP_Post), tid, tid_new,
+ buf, buf_off );
+ if (ret == -1) break;
+ }
CONSTRUCT_EXPECTED_REPLY_HDR( reply_hdr, WSP_Reply, tid );
ret = wap_msg_recv( fd, reply_hdr, sizeof(WSP_Reply),
@@ -707,7 +767,7 @@ int main(int argc, char **argv)
hostname = octstr_create("localhost");
- while ((opt = getopt(argc, argv, "Fhvc:g:p:P:m:i:t:V:T:t:nsd:w")) != EOF) {
+ while ((opt = getopt(argc, argv, "Fhvc:g:p:P:m:i:t:V:T:t:nsd:wC:")) != EOF) {
switch (opt) {
case 'g':
octstr_destroy(hostname);
@@ -718,6 +778,13 @@ int main(int argc, char **argv)
port = atoi(optarg);
break;
+ case 'P':
+ if (!*optarg)
+ post_content_type = "text/plain";
+ else
+ post_content_type = strdup(optarg);
+ break;
+
case 'm':
max_send = atoi(optarg);
break;
@@ -771,6 +838,10 @@ int main(int argc, char **argv)
writedata = 1;
break;
+ case 'C':
+ wsp_connect_file = strdup(optarg);
+ break;
+
case '?':
default:
error(0, "Unknown option %c", opt);