Browse code

test: added parse to body test program

- added parse to body test program that uses the same code as
sip-router. E.g. test/parse_to_body "Foo <foo@bar>CR".
- update p_uri (parse uri test) to compile with sip-router.

Andrei Pelinescu-Onciul authored on 03/03/2010 18:30:04
Showing 2 changed files
... ...
@@ -1,6 +1,6 @@
1 1
 /** uri parser test program. */
2 2
 /* compile with:
3
-    gcc -Wall p_uri.c   -o p_uri -DFAST_LOCK -D__CPU_i386 -DSHM_MEM */
3
+    gcc -Wall p_uri.c   -o p_uri -DFAST_LOCK -D__CPU_i386 */
4 4
 #include <stdio.h>
5 5
 #include <stdlib.h> /* exit() */
6 6
 #include <string.h>
... ...
@@ -10,6 +10,7 @@
10 10
 /* ser compat defs */
11 11
 #define EXTRA_DEBUG
12 12
 #include "../parser/parse_uri.c"
13
+#include "../dprint.c"
13 14
 
14 15
 
15 16
 int ser_error=0;
... ...
@@ -17,7 +18,7 @@ int log_stderr=1;
17 17
 int process_no=0;
18 18
 struct process_table* pt=0;
19 19
 int phone2tel=1;
20
-volatile int dprint_crit=0;
20
+/*volatile int dprint_crit=0; */
21 21
 int my_pid() {return 0; };
22 22
 
23 23
 struct cfg_group_core default_core_cfg = {
... ...
@@ -68,7 +69,6 @@ struct cfg_group_core default_core_cfg = {
68 68
 
69 69
 void	*core_cfg = &default_core_cfg;
70 70
 
71
-
72 71
 void dprint(char * format, ...)
73 72
 {
74 73
 	va_list ap;
... ...
@@ -82,7 +82,6 @@ void dprint(char * format, ...)
82 82
 
83 83
 
84 84
 
85
-
86 85
 int main (int argc, char** argv)
87 86
 {
88 87
 
89 88
new file mode 100644
... ...
@@ -0,0 +1,116 @@
0
+/** to/from body parser test program. */
1
+/* compile with:
2
+    gcc -Wall parse_to_body.c -o parse_to_body -DFAST_LOCK -D__CPU_i386 */
3
+#include <stdio.h>
4
+#include <stdlib.h> /* exit() */
5
+#include <string.h>
6
+#include <stdarg.h>
7
+#include "../str.h"
8
+
9
+/* ser compat defs */
10
+#define EXTRA_DEBUG
11
+#include "../parser/parse_to.c"
12
+#include "../dprint.c"
13
+
14
+
15
+int ser_error=0;
16
+int log_stderr=1;
17
+int process_no=0;
18
+struct process_table* pt=0;
19
+int phone2tel=1;
20
+/*volatile int dprint_crit=0; */
21
+int my_pid() {return 0; };
22
+
23
+struct cfg_group_core default_core_cfg = {
24
+	L_DBG, /*  print only msg. < L_WARN */
25
+	LOG_DAEMON,	/* log_facility -- see syslog(3) */
26
+#ifdef USE_DST_BLACKLIST
27
+	/* blacklist */
28
+	0, /* dst blacklist is disabled by default */
29
+	DEFAULT_BLST_TIMEOUT,
30
+	DEFAULT_BLST_MAX_MEM,
31
+#endif
32
+	/* resolver */
33
+#ifdef USE_IPV6
34
+	1,  /* dns_try_ipv6 -- on by default */
35
+#else
36
+	0,  /* dns_try_ipv6 -- off, if no ipv6 support */
37
+#endif
38
+	0,  /* dns_try_naptr -- off by default */
39
+	30,  /* udp transport preference (for naptr) */
40
+	20,  /* tcp transport preference (for naptr) */
41
+	10,  /* tls transport preference (for naptr) */
42
+	20,  /* sctp transport preference (for naptr) */
43
+	-1, /* dns_retr_time */
44
+	-1, /* dns_retr_no */
45
+	-1, /* dns_servers_no */
46
+	1,  /* dns_search_list */
47
+	1,  /* dns_search_fmatch */
48
+	0,  /* dns_reinit */
49
+	/* DNS cache */
50
+#ifdef USE_DNS_CACHE
51
+	1,  /* use_dns_cache -- on by default */
52
+	0,  /* dns_cache_flags */
53
+	0,  /* use_dns_failover -- off by default */
54
+	0,  /* dns_srv_lb -- off by default */
55
+	DEFAULT_DNS_NEG_CACHE_TTL, /* neg. cache ttl */
56
+	DEFAULT_DNS_CACHE_MIN_TTL, /* minimum ttl */
57
+	DEFAULT_DNS_CACHE_MAX_TTL, /* maximum ttl */
58
+	DEFAULT_DNS_MAX_MEM, /* dns_cache_max_mem */
59
+	0, /* dns_cache_del_nonexp -- delete only expired entries by default */
60
+#endif
61
+#ifdef PKG_MALLOC
62
+	0, /* mem_dump_pkg */
63
+#endif
64
+#ifdef SHM_MEM
65
+	0, /* mem_dump_shm */
66
+#endif
67
+};
68
+
69
+void	*core_cfg = &default_core_cfg;
70
+
71
+void dprint(char * format, ...)
72
+{
73
+	va_list ap;
74
+
75
+	fprintf(stderr, "%2d(%d) ", process_no, my_pid());
76
+	va_start(ap, format);
77
+	vfprintf(stderr,format,ap);
78
+	fflush(stderr);
79
+	va_end(ap);
80
+}
81
+
82
+
83
+
84
+int main (int argc, char** argv)
85
+{
86
+
87
+	int r;
88
+	struct to_body to_b;
89
+	struct to_param *p;
90
+
91
+	if (argc<2){
92
+		printf("usage:    %s  to_body [, to_body...]\n", argv[0]);
93
+		exit(1);
94
+	}
95
+	
96
+	for (r=1; r<argc; r++){
97
+		/*memset(&to_b, 0, sizeof(to_b));*/
98
+		if (parse_to(argv[r], argv[r]+strlen(argv[r]), &to_b)==0 ||
99
+				to_b.error!=1){
100
+			printf("error: parsing %s\n", argv[r]);
101
+			continue;
102
+		}
103
+		printf("body:    [%.*s]\n", to_b.body.len, to_b.body.s);
104
+		printf("uri:     [%.*s]\n", to_b.uri.len, to_b.uri.s);
105
+		printf("display: [%.*s]\n", to_b.display.len, to_b.display.s);
106
+		printf("tag:     [%.*s]\n\n", to_b.tag_value.len, to_b.tag_value.s);
107
+		for (p=to_b.param_lst; p; p=p->next){
108
+			printf("	param type: %d\n", p->type);
109
+			printf("	param name: [%.*s]\n", p->name.len, p->name.s);
110
+			printf("	param value: [%.*s]\n\n", p->value.len, p->value.s);
111
+		}
112
+		printf("\n");
113
+	}
114
+	return 0;
115
+}