Browse Source

- added module support (loadmodule "...")
- added example dummy print module

Andrei Pelinescu-Onciul 24 years ago
parent
commit
96001c5015
5 changed files with 40 additions and 56 deletions
  1. 5 1
      INSTALL
  2. 33 35
      Makefile
  3. 2 3
      cfg.y
  4. 0 9
      data_lump.c
  5. 0 8
      forward.c

+ 5 - 1
INSTALL

@@ -2,7 +2,7 @@ $Id$
 
 Installation Notes
 
-Supported architectures: Linux, FreeBSD, Solaris
+Supported architectures: Linux, FreeBSD, Solaris, Win* (CYGWIN)
 (for other architectures the Makefile must be edited)
 
 Requirements:
@@ -17,6 +17,10 @@ Arhitecture Notes:
 
 - FreeBSD: make sure gmake, bison & flex are installed
 - Solaris: as above; you can use Solaris's yacc instead of bison
+- Windows: it works in windows but you must install a recent cygwin version
+	(http://www.cygwin.com/) and also install a newer regex library version
+	(>=0.12). 
+	
 
 Compile:
 

+ 33 - 35
Makefile

@@ -3,14 +3,13 @@
 # sip_router makefile
 #
 # WARNING: requires gmake (GNU Make)
-#  Arch supported: Linux, FreeBSD, SunOS (tested on Solaris 6)
+#  Arch supported: Linux, FreeBSD, SunOS (tested on Solaris 6), WinNT
 
-lex_f=lex.yy.c
-yacc_f=cfg.tab.c
-sources= $(filter-out $(lex_f) $(yacc_f), $(wildcard *.c)) $(lex_f) \
-$(yacc_f) 
-objs= $(sources:.c=.o)
-depends= $(sources:.c=.d)
+auto_gen=lex.yy.c cfg.tab.c   #lexx, yacc etc
+sources=$(filter-out $(auto_gen), $(wildcard *.c)) $(auto_gen) 
+objs=$(sources:.c=.o)
+depends=$(sources:.c=.d)
+modules=$(wildcard modules/*)
 
 NAME=ser
 
@@ -26,10 +25,11 @@ DEFS=-DNOCR -DMACROEATER
 
 ARCH = $(shell uname -s)
 
-ifeq ($(ARCH), Linux)
-
+#common
 CC=gcc
+LD=gcc
 CFLAGS=-O2 -Wcast-align #-Wmissing-prototypes 
+LDFLAGS=-Wl,-O2 -Wl,-E
 LEX=flex
 YACC=bison
 YACC_FLAGS=-d -b cfg
@@ -37,60 +37,48 @@ YACC_FLAGS=-d -b cfg
 # on solaris add -lxnet (e.g. LIBS= -lxnet)
 LIBS=-lfl -ldl
 
-endif 
+
+ifeq ($(ARCH), Linux)
+
+endif
 ifeq  ($(ARCH), SunOS)
 
 MAKE=gmake
-CC=gcc
-CFLAGS=-O2 -Wcast-align
-LEX=flex
 YACC=yacc
-YACC_FLAGS=-d -b cfg
-LIBS=-lfl -ldl -L/usr/local/lib -lxnet # or -lnsl -lsocket or -lglibc ?
+LIBS=$(LIBS) -L/usr/local/lib -lxnet # or -lnsl -lsocket or -lglibc ?
 
 endif
 ifeq ($(ARCH), FreeBSD)
 
 MAKE=gmake
-CC=gcc
-CFLAGS=-O2 -Wcast-align
-LEX=flex
 YACC=yacc
-YACC_FLAGS=-d -b cfg
-LIBS=-lfl -ldl
 
 endif
+ifneq (,$(findstring CYGWIN, $(ARCH)))
 
-ifeq ($(ARCH), CYGWIN_NT-4.0)
-
-CC=gcc
-CFLAGS=-O2 -Wcast-align #-Wmissing-prototypes  -Wall
-LEX=flex
-YACC=bison
-YACC_FLAGS=-d -b cfg
-# on linux and freebsd keep it empty (e.g. LIBS= )
-# on solaris add -lxnet (e.g. LIBS= -lxnet)
-LIBS=-lfl -ldl
+#cygwin is the same as common
 
 endif
 
 
-MKDEP=gcc -M $(DEFS)
+MKDEP=gcc -M 
 
 ALLDEP=Makefile
 
-#implicit rules
+export #export all variables for the sub-makes
 
 
+#implicit rules
 %.o:%.c $(ALLDEP)
 	$(CC) $(CFLAGS) $(DEFS) -c $< -o $@
 
 %.d: %.c
 	$(MKDEP) $< >$@
 
+
 # normal rules
 $(NAME): $(objs)
-	$(CC) $(CFLAGS) $(objs) -o $(NAME) $(LIBS)
+	$(LD) $(LDFLAGS) $(objs) $(LIBS) -o $(NAME) 
 
 lex.yy.c: cfg.lex $(ALLDEP)
 	$(LEX) $<
@@ -99,8 +87,9 @@ cfg.tab.c: cfg.y $(ALLDEP)
 	$(YACC) $(YACC_FLAGS) $<
 
 
+
 .PHONY: all
-all: $(NAME)
+all: $(NAME) modules
 
 .PHONY: dep
 dep: $(depends)
@@ -108,10 +97,19 @@ dep: $(depends)
 .PHONY: clean
 clean:
 	-rm $(objs) $(NAME)
+	-for r in $(modules); do $(MAKE) -C $$r clean ; done
+
+.PHONY: modules
+modules:
+	-for r in $(modules); do \
+		$(MAKE) -C $$r ; \
+	done
+
 
 .PHONY: proper
-proper: clean
+proper: clean 
 	-rm $(depends)
+	-for r in $(modules); do $(MAKE) -C $$r proper ; done
 
 include $(depends)
 

+ 2 - 3
cfg.y

@@ -209,7 +209,7 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
 		| error EQUAL { yyerror("unknown config variable"); }
 	;
 
-module_stm:	LOADMODULE STRING	{ DBG("loading module %s", $2);
+module_stm:	LOADMODULE STRING	{ DBG("loading module %s\n", $2);
 		  						  if (load_module($2)!=0){
 								  		yyerror("failed to load module");
 								  }
@@ -554,8 +554,7 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
 		| SET_URI error { $$=0; yyerror("missing '(' or ')' ?"); }
 		| SET_URI LPAREN error RPAREN { $$=0; yyerror("bad argument, "
 										"string expected"); }
-		| ID LPAREN STRING RPAREN { DBG(" %s - doing nothing", $1);
-									f_tmp=find_export($1);
+		| ID LPAREN STRING RPAREN { f_tmp=find_export($1);
 									if (f_tmp==0){
 										yyerror("unknown command %s, missing"
 										" loadmodule?\n");

+ 0 - 9
data_lump.c

@@ -159,13 +159,11 @@ struct lump* anchor_lump(struct lump** list, int offset, int len, int type)
 	tmp->u.offset=offset;
 	tmp->len=len;
 	prev=0;
-	DBG("anchor: new tmp=%x\n", tmp);
 	for (t=*list;t; prev=t, t=t->next){
 		/* insert it sorted after offset */
 		if (((t->op==LUMP_DEL)||(t->op==LUMP_NOP))&&(t->u.offset>offset))
 			break;
 	}
-	DBG("anchor: inserting it between %x and %x (*list=%x)\n", prev, t,*list);
 	tmp->next=t;
 	
 	if (prev) prev->next=tmp;
@@ -177,13 +175,11 @@ struct lump* anchor_lump(struct lump** list, int offset, int len, int type)
 
 void free_lump(struct lump* lmp)
 {
-	DBG("- free_lump(%x), op=%d\n", lmp, lmp->op);
 	if (lmp && (lmp->op==LUMP_ADD)){
 		if (lmp->u.value) free(lmp->u.value);
 		lmp->u.value=0;
 		lmp->len=0;
 	}
-	DBG("- exiting free_lump(%x)\n", lmp);
 }
 
 
@@ -192,19 +188,14 @@ void free_lump_list(struct lump* l)
 {
 	struct lump* t, *crt;
 	t=l;
-	DBG("+ free_lump_list(%x)\n", l);
 	while(t){
 		crt=t;
 		t=t->next;
-		DBG("free_lump_list: freeing %x\n", crt);
 		/* dangerous recursive clean*/
 		if (crt->before) free_lump_list(crt->before);
 		if (crt->after)  free_lump_list(crt->after);
-		DBG("free_lump_list: back from recursive calls (%x) \n", crt);
 		/*clean current elem*/
 		free_lump(crt);
 		free(crt);
-		DBG("after free_lump_list: %x\n", crt);
 	}
-	DBG("+ exiting free_lump_list(%x)\n", l);
 }

+ 0 - 8
forward.c

@@ -116,7 +116,6 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p)
 	
 	/* add via header to the list */
 	/* try to add it before msg. 1st via */
-	DBG("forward_request: before via\n");
 	/*add first via, as an anchor for second via*/
 	anchor=anchor_lump(&(msg->add_rm), msg->via1.hdr-buf, 0, HDR_VIA);
 	if (anchor==0) goto error;
@@ -124,7 +123,6 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p)
 		goto error;
 	/* if received needs to be added, add anchor after host and add it */
 	if (received_len){
-	DBG("forward_request: adding received\n");
 		if (msg->via1.params){
 				size= msg->via1.params-msg->via1.hdr-1; /*compensate for ';' */
 		}else{
@@ -142,11 +140,8 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p)
 	
 	/* compute new msg len*/
 	new_len=len;
-	DBG("forward_request: computing new_len\n");
 	for(t=msg->add_rm;t;t=t->next){
-		DBG("forward_request: in for t.(%x)..\n", t);
 		for(r=t->before;r;r=r->before){
-		DBG("- forward_request: in for r...\n");
 			switch(r->op){
 				case LUMP_ADD:
 					new_len+=r->len;
@@ -172,7 +167,6 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p)
 							" op for data lump (%x)\n", r->op);
 		}
 		for (r=t->after;r;r=r->after){
-		DBG("- forward_request: in for2 r...\n");
 			switch(r->op){
 				case LUMP_ADD:
 					new_len+=r->len;
@@ -190,7 +184,6 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p)
 		uri_len=strlen(msg->new_uri); 
 		new_len=new_len-strlen(msg->first_line.u.request.uri)+uri_len;
 	}
-	DBG("forward_request: new_len=%d\n",new_len);
 	new_buf=(char*)malloc(new_len+1);
 	if (new_buf==0){
 		LOG(L_ERR, "ERROR: forward_request: out of memory\n");
@@ -211,7 +204,6 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p)
 	}
 /* copy msg adding/removing lumps */
 	for (t=msg->add_rm;t;t=t->next){
-		DBG("adding/rming %x, op=%x, offset=%d\n", t, t->op, t->u.offset);
 		switch(t->op){
 			case LUMP_ADD:
 				/* just add it here! */