Module: sip-router
Branch: master
Commit: 2cedf1626147ce0bcf67435a57dc23643c55d7d6
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=2cedf16…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Wed Mar 3 19:30:04 2010 +0100
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.
---
test/p_uri.c | 7 +--
test/parse_to_body.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 119 insertions(+), 4 deletions(-)
diff --git a/test/p_uri.c b/test/p_uri.c
index 1f2cc99..ea75676 100644
--- a/test/p_uri.c
+++ b/test/p_uri.c
@@ -1,6 +1,6 @@
/** uri parser test program. */
/* compile with:
- gcc -Wall p_uri.c -o p_uri -DFAST_LOCK -D__CPU_i386 -DSHM_MEM */
+ gcc -Wall p_uri.c -o p_uri -DFAST_LOCK -D__CPU_i386 */
#include <stdio.h>
#include <stdlib.h> /* exit() */
#include <string.h>
@@ -10,6 +10,7 @@
/* ser compat defs */
#define EXTRA_DEBUG
#include "../parser/parse_uri.c"
+#include "../dprint.c"
int ser_error=0;
@@ -17,7 +18,7 @@ int log_stderr=1;
int process_no=0;
struct process_table* pt=0;
int phone2tel=1;
-volatile int dprint_crit=0;
+/*volatile int dprint_crit=0; */
int my_pid() {return 0; };
struct cfg_group_core default_core_cfg = {
@@ -68,7 +69,6 @@ struct cfg_group_core default_core_cfg = {
void *core_cfg = &default_core_cfg;
-
void dprint(char * format, ...)
{
va_list ap;
@@ -82,7 +82,6 @@ void dprint(char * format, ...)
-
int main (int argc, char** argv)
{
diff --git a/test/parse_to_body.c b/test/parse_to_body.c
new file mode 100644
index 0000000..fe92371
--- /dev/null
+++ b/test/parse_to_body.c
@@ -0,0 +1,116 @@
+/** to/from body parser test program. */
+/* compile with:
+ gcc -Wall parse_to_body.c -o parse_to_body -DFAST_LOCK -D__CPU_i386 */
+#include <stdio.h>
+#include <stdlib.h> /* exit() */
+#include <string.h>
+#include <stdarg.h>
+#include "../str.h"
+
+/* ser compat defs */
+#define EXTRA_DEBUG
+#include "../parser/parse_to.c"
+#include "../dprint.c"
+
+
+int ser_error=0;
+int log_stderr=1;
+int process_no=0;
+struct process_table* pt=0;
+int phone2tel=1;
+/*volatile int dprint_crit=0; */
+int my_pid() {return 0; };
+
+struct cfg_group_core default_core_cfg = {
+ L_DBG, /* print only msg. < L_WARN */
+ LOG_DAEMON, /* log_facility -- see syslog(3) */
+#ifdef USE_DST_BLACKLIST
+ /* blacklist */
+ 0, /* dst blacklist is disabled by default */
+ DEFAULT_BLST_TIMEOUT,
+ DEFAULT_BLST_MAX_MEM,
+#endif
+ /* resolver */
+#ifdef USE_IPV6
+ 1, /* dns_try_ipv6 -- on by default */
+#else
+ 0, /* dns_try_ipv6 -- off, if no ipv6 support */
+#endif
+ 0, /* dns_try_naptr -- off by default */
+ 30, /* udp transport preference (for naptr) */
+ 20, /* tcp transport preference (for naptr) */
+ 10, /* tls transport preference (for naptr) */
+ 20, /* sctp transport preference (for naptr) */
+ -1, /* dns_retr_time */
+ -1, /* dns_retr_no */
+ -1, /* dns_servers_no */
+ 1, /* dns_search_list */
+ 1, /* dns_search_fmatch */
+ 0, /* dns_reinit */
+ /* DNS cache */
+#ifdef USE_DNS_CACHE
+ 1, /* use_dns_cache -- on by default */
+ 0, /* dns_cache_flags */
+ 0, /* use_dns_failover -- off by default */
+ 0, /* dns_srv_lb -- off by default */
+ DEFAULT_DNS_NEG_CACHE_TTL, /* neg. cache ttl */
+ DEFAULT_DNS_CACHE_MIN_TTL, /* minimum ttl */
+ DEFAULT_DNS_CACHE_MAX_TTL, /* maximum ttl */
+ DEFAULT_DNS_MAX_MEM, /* dns_cache_max_mem */
+ 0, /* dns_cache_del_nonexp -- delete only expired entries by default */
+#endif
+#ifdef PKG_MALLOC
+ 0, /* mem_dump_pkg */
+#endif
+#ifdef SHM_MEM
+ 0, /* mem_dump_shm */
+#endif
+};
+
+void *core_cfg = &default_core_cfg;
+
+void dprint(char * format, ...)
+{
+ va_list ap;
+
+ fprintf(stderr, "%2d(%d) ", process_no, my_pid());
+ va_start(ap, format);
+ vfprintf(stderr,format,ap);
+ fflush(stderr);
+ va_end(ap);
+}
+
+
+
+int main (int argc, char** argv)
+{
+
+ int r;
+ struct to_body to_b;
+ struct to_param *p;
+
+ if (argc<2){
+ printf("usage: %s to_body [, to_body...]\n", argv[0]);
+ exit(1);
+ }
+
+ for (r=1; r<argc; r++){
+ /*memset(&to_b, 0, sizeof(to_b));*/
+ if (parse_to(argv[r], argv[r]+strlen(argv[r]), &to_b)==0 ||
+ to_b.error!=1){
+ printf("error: parsing %s\n", argv[r]);
+ continue;
+ }
+ printf("body: [%.*s]\n", to_b.body.len, to_b.body.s);
+ printf("uri: [%.*s]\n", to_b.uri.len, to_b.uri.s);
+ printf("display: [%.*s]\n", to_b.display.len, to_b.display.s);
+ printf("tag: [%.*s]\n\n", to_b.tag_value.len, to_b.tag_value.s);
+ for (p=to_b.param_lst; p; p=p->next){
+ printf(" param type: %d\n", p->type);
+ printf(" param name: [%.*s]\n", p->name.len, p->name.s);
+ printf(" param value: [%.*s]\n\n", p->value.len, p->value.s);
+ }
+ printf("\n");
+ }
+ return 0;
+}