Browse code

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

Andrei Pelinescu-Onciul authored on 24/10/2001 19:17:54
Showing 5 changed files
... ...
@@ -2,7 +2,7 @@ $Id$
2 2
 
3 3
 Installation Notes
4 4
 
5
-Supported architectures: Linux, FreeBSD, Solaris
5
+Supported architectures: Linux, FreeBSD, Solaris, Win* (CYGWIN)
6 6
 (for other architectures the Makefile must be edited)
7 7
 
8 8
 Requirements:
... ...
@@ -17,6 +17,10 @@ Arhitecture Notes:
17 17
 
18 18
 - FreeBSD: make sure gmake, bison & flex are installed
19 19
 - Solaris: as above; you can use Solaris's yacc instead of bison
20
+- Windows: it works in windows but you must install a recent cygwin version
21
+	(http://www.cygwin.com/) and also install a newer regex library version
22
+	(>=0.12). 
23
+	
20 24
 
21 25
 Compile:
22 26
 
... ...
@@ -3,14 +3,13 @@
3 3
 # sip_router makefile
4 4
 #
5 5
 # WARNING: requires gmake (GNU Make)
6
-#  Arch supported: Linux, FreeBSD, SunOS (tested on Solaris 6)
6
+#  Arch supported: Linux, FreeBSD, SunOS (tested on Solaris 6), WinNT
7 7
 
8
-lex_f=lex.yy.c
9
-yacc_f=cfg.tab.c
10
-sources= $(filter-out $(lex_f) $(yacc_f), $(wildcard *.c)) $(lex_f) \
11
-$(yacc_f) 
12
-objs= $(sources:.c=.o)
13
-depends= $(sources:.c=.d)
8
+auto_gen=lex.yy.c cfg.tab.c   #lexx, yacc etc
9
+sources=$(filter-out $(auto_gen), $(wildcard *.c)) $(auto_gen) 
10
+objs=$(sources:.c=.o)
11
+depends=$(sources:.c=.d)
12
+modules=$(wildcard modules/*)
14 13
 
15 14
 NAME=ser
16 15
 
... ...
@@ -26,10 +25,11 @@ DEFS=-DNOCR -DMACROEATER
26 26
 
27 27
 ARCH = $(shell uname -s)
28 28
 
29
-ifeq ($(ARCH), Linux)
30
-
29
+#common
31 30
 CC=gcc
31
+LD=gcc
32 32
 CFLAGS=-O2 -Wcast-align #-Wmissing-prototypes 
33
+LDFLAGS=-Wl,-O2 -Wl,-E
33 34
 LEX=flex
34 35
 YACC=bison
35 36
 YACC_FLAGS=-d -b cfg
... ...
@@ -37,60 +37,48 @@ YACC_FLAGS=-d -b cfg
37 37
 # on solaris add -lxnet (e.g. LIBS= -lxnet)
38 38
 LIBS=-lfl -ldl
39 39
 
40
-endif 
40
+
41
+ifeq ($(ARCH), Linux)
42
+
43
+endif
41 44
 ifeq  ($(ARCH), SunOS)
42 45
 
43 46
 MAKE=gmake
44
-CC=gcc
45
-CFLAGS=-O2 -Wcast-align
46
-LEX=flex
47 47
 YACC=yacc
48
-YACC_FLAGS=-d -b cfg
49
-LIBS=-lfl -ldl -L/usr/local/lib -lxnet # or -lnsl -lsocket or -lglibc ?
48
+LIBS=$(LIBS) -L/usr/local/lib -lxnet # or -lnsl -lsocket or -lglibc ?
50 49
 
51 50
 endif
52 51
 ifeq ($(ARCH), FreeBSD)
53 52
 
54 53
 MAKE=gmake
55
-CC=gcc
56
-CFLAGS=-O2 -Wcast-align
57
-LEX=flex
58 54
 YACC=yacc
59
-YACC_FLAGS=-d -b cfg
60
-LIBS=-lfl -ldl
61 55
 
62 56
 endif
57
+ifneq (,$(findstring CYGWIN, $(ARCH)))
63 58
 
64
-ifeq ($(ARCH), CYGWIN_NT-4.0)
65
-
66
-CC=gcc
67
-CFLAGS=-O2 -Wcast-align #-Wmissing-prototypes  -Wall
68
-LEX=flex
69
-YACC=bison
70
-YACC_FLAGS=-d -b cfg
71
-# on linux and freebsd keep it empty (e.g. LIBS= )
72
-# on solaris add -lxnet (e.g. LIBS= -lxnet)
73
-LIBS=-lfl -ldl
59
+#cygwin is the same as common
74 60
 
75 61
 endif
76 62
 
77 63
 
78
-MKDEP=gcc -M $(DEFS)
64
+MKDEP=gcc -M 
79 65
 
80 66
 ALLDEP=Makefile
81 67
 
82
-#implicit rules
68
+export #export all variables for the sub-makes
83 69
 
84 70
 
71
+#implicit rules
85 72
 %.o:%.c $(ALLDEP)
86 73
 	$(CC) $(CFLAGS) $(DEFS) -c $< -o $@
87 74
 
88 75
 %.d: %.c
89 76
 	$(MKDEP) $< >$@
90 77
 
78
+
91 79
 # normal rules
92 80
 $(NAME): $(objs)
93
-	$(CC) $(CFLAGS) $(objs) -o $(NAME) $(LIBS)
81
+	$(LD) $(LDFLAGS) $(objs) $(LIBS) -o $(NAME) 
94 82
 
95 83
 lex.yy.c: cfg.lex $(ALLDEP)
96 84
 	$(LEX) $<
... ...
@@ -99,8 +87,9 @@ cfg.tab.c: cfg.y $(ALLDEP)
99 99
 	$(YACC) $(YACC_FLAGS) $<
100 100
 
101 101
 
102
+
102 103
 .PHONY: all
103
-all: $(NAME)
104
+all: $(NAME) modules
104 105
 
105 106
 .PHONY: dep
106 107
 dep: $(depends)
... ...
@@ -108,10 +97,19 @@ dep: $(depends)
108 108
 .PHONY: clean
109 109
 clean:
110 110
 	-rm $(objs) $(NAME)
111
+	-for r in $(modules); do $(MAKE) -C $$r clean ; done
112
+
113
+.PHONY: modules
114
+modules:
115
+	-for r in $(modules); do \
116
+		$(MAKE) -C $$r ; \
117
+	done
118
+
111 119
 
112 120
 .PHONY: proper
113
-proper: clean
121
+proper: clean 
114 122
 	-rm $(depends)
123
+	-for r in $(modules); do $(MAKE) -C $$r proper ; done
115 124
 
116 125
 include $(depends)
117 126
 
... ...
@@ -209,7 +209,7 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
209 209
 		| error EQUAL { yyerror("unknown config variable"); }
210 210
 	;
211 211
 
212
-module_stm:	LOADMODULE STRING	{ DBG("loading module %s", $2);
212
+module_stm:	LOADMODULE STRING	{ DBG("loading module %s\n", $2);
213 213
 		  						  if (load_module($2)!=0){
214 214
 								  		yyerror("failed to load module");
215 215
 								  }
... ...
@@ -554,8 +554,7 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
554 554
 		| SET_URI error { $$=0; yyerror("missing '(' or ')' ?"); }
555 555
 		| SET_URI LPAREN error RPAREN { $$=0; yyerror("bad argument, "
556 556
 										"string expected"); }
557
-		| ID LPAREN STRING RPAREN { DBG(" %s - doing nothing", $1);
558
-									f_tmp=find_export($1);
557
+		| ID LPAREN STRING RPAREN { f_tmp=find_export($1);
559 558
 									if (f_tmp==0){
560 559
 										yyerror("unknown command %s, missing"
561 560
 										" loadmodule?\n");
... ...
@@ -159,13 +159,11 @@ struct lump* anchor_lump(struct lump** list, int offset, int len, int type)
159 159
 	tmp->u.offset=offset;
160 160
 	tmp->len=len;
161 161
 	prev=0;
162
-	DBG("anchor: new tmp=%x\n", tmp);
163 162
 	for (t=*list;t; prev=t, t=t->next){
164 163
 		/* insert it sorted after offset */
165 164
 		if (((t->op==LUMP_DEL)||(t->op==LUMP_NOP))&&(t->u.offset>offset))
166 165
 			break;
167 166
 	}
168
-	DBG("anchor: inserting it between %x and %x (*list=%x)\n", prev, t,*list);
169 167
 	tmp->next=t;
170 168
 	
171 169
 	if (prev) prev->next=tmp;
... ...
@@ -177,13 +175,11 @@ struct lump* anchor_lump(struct lump** list, int offset, int len, int type)
177 177
 
178 178
 void free_lump(struct lump* lmp)
179 179
 {
180
-	DBG("- free_lump(%x), op=%d\n", lmp, lmp->op);
181 180
 	if (lmp && (lmp->op==LUMP_ADD)){
182 181
 		if (lmp->u.value) free(lmp->u.value);
183 182
 		lmp->u.value=0;
184 183
 		lmp->len=0;
185 184
 	}
186
-	DBG("- exiting free_lump(%x)\n", lmp);
187 185
 }
188 186
 
189 187
 
... ...
@@ -192,19 +188,14 @@ void free_lump_list(struct lump* l)
192 192
 {
193 193
 	struct lump* t, *crt;
194 194
 	t=l;
195
-	DBG("+ free_lump_list(%x)\n", l);
196 195
 	while(t){
197 196
 		crt=t;
198 197
 		t=t->next;
199
-		DBG("free_lump_list: freeing %x\n", crt);
200 198
 		/* dangerous recursive clean*/
201 199
 		if (crt->before) free_lump_list(crt->before);
202 200
 		if (crt->after)  free_lump_list(crt->after);
203
-		DBG("free_lump_list: back from recursive calls (%x) \n", crt);
204 201
 		/*clean current elem*/
205 202
 		free_lump(crt);
206 203
 		free(crt);
207
-		DBG("after free_lump_list: %x\n", crt);
208 204
 	}
209
-	DBG("+ exiting free_lump_list(%x)\n", l);
210 205
 }
... ...
@@ -116,7 +116,6 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p)
116 116
 	
117 117
 	/* add via header to the list */
118 118
 	/* try to add it before msg. 1st via */
119
-	DBG("forward_request: before via\n");
120 119
 	/*add first via, as an anchor for second via*/
121 120
 	anchor=anchor_lump(&(msg->add_rm), msg->via1.hdr-buf, 0, HDR_VIA);
122 121
 	if (anchor==0) goto error;
... ...
@@ -124,7 +123,6 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p)
124 124
 		goto error;
125 125
 	/* if received needs to be added, add anchor after host and add it */
126 126
 	if (received_len){
127
-	DBG("forward_request: adding received\n");
128 127
 		if (msg->via1.params){
129 128
 				size= msg->via1.params-msg->via1.hdr-1; /*compensate for ';' */
130 129
 		}else{
... ...
@@ -142,11 +140,8 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p)
142 142
 	
143 143
 	/* compute new msg len*/
144 144
 	new_len=len;
145
-	DBG("forward_request: computing new_len\n");
146 145
 	for(t=msg->add_rm;t;t=t->next){
147
-		DBG("forward_request: in for t.(%x)..\n", t);
148 146
 		for(r=t->before;r;r=r->before){
149
-		DBG("- forward_request: in for r...\n");
150 147
 			switch(r->op){
151 148
 				case LUMP_ADD:
152 149
 					new_len+=r->len;
... ...
@@ -172,7 +167,6 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p)
172 172
 							" op for data lump (%x)\n", r->op);
173 173
 		}
174 174
 		for (r=t->after;r;r=r->after){
175
-		DBG("- forward_request: in for2 r...\n");
176 175
 			switch(r->op){
177 176
 				case LUMP_ADD:
178 177
 					new_len+=r->len;
... ...
@@ -190,7 +184,6 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p)
190 190
 		uri_len=strlen(msg->new_uri); 
191 191
 		new_len=new_len-strlen(msg->first_line.u.request.uri)+uri_len;
192 192
 	}
193
-	DBG("forward_request: new_len=%d\n",new_len);
194 193
 	new_buf=(char*)malloc(new_len+1);
195 194
 	if (new_buf==0){
196 195
 		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)
211 211
 	}
212 212
 /* copy msg adding/removing lumps */
213 213
 	for (t=msg->add_rm;t;t=t->next){
214
-		DBG("adding/rming %x, op=%x, offset=%d\n", t, t->op, t->u.offset);
215 214
 		switch(t->op){
216 215
 			case LUMP_ADD:
217 216
 				/* just add it here! */