Pārlūkot izejas kodu

- fixed memory leak when rewritting uri
- route match after new uri
- dmalloc debuging support

Andrei Pelinescu-Onciul 24 gadi atpakaļ
vecāks
revīzija
031500989c
12 mainītis faili ar 54 papildinājumiem un 4 dzēšanām
  1. 2 2
      Makefile
  2. 4 0
      action.c
  3. 5 0
      cfg.lex
  4. 4 0
      cfg.y
  5. 4 0
      forward.c
  6. 5 0
      main.c
  7. 4 0
      msg_parser.c
  8. 3 0
      proxy.c
  9. 5 0
      receive.c
  10. 11 2
      route.c
  11. 4 0
      route_struct.c
  12. 3 0
      udp_server.c

+ 2 - 2
Makefile

@@ -16,13 +16,13 @@ NAME=sip_router
 
 
 CC=gcc
-CFLAGS=-O2 -Wcast-align  #-Wmissing-prototypes  -Wall
+CFLAGS=-O2 -Wcast-align #-Wmissing-prototypes  -Wall
 LEX=lex
 YACC=yacc
 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 -L/usr/local/lib
+LIBS=-lfl -L/usr/local/lib 
 ALLDEP=Makefile
 
 MKDEP=gcc -M

+ 4 - 0
action.c

@@ -21,6 +21,10 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
+#ifdef DEBUG_DMALLOC
+#include <dmalloc.h>
+#endif
+
 
 /* ret= 0! if action -> end of list(e.g DROP), 
       > 0 to continue processing next actions

+ 5 - 0
cfg.lex

@@ -9,6 +9,11 @@
 	#include "cfg.tab.h"
 	#include "dprint.h"
 	#include <string.h>
+	#include <stdlib.h>
+
+#ifdef DEBUG_DMALLOC
+#include <dmalloc.h>
+#endif
 
 	/* states */
 	#define INITIAL_S		0

+ 4 - 0
cfg.y

@@ -17,6 +17,10 @@
 #include "route.h"
 #include "dprint.h"
 
+#ifdef DEBUG_DMALLOC
+#include <dmalloc.h>
+#endif
+
 void yyerror(char* s);
 char* tmp;
 

+ 4 - 0
forward.c

@@ -20,6 +20,10 @@
 #include "udp_server.h"
 #include "globals.h"
 
+#ifdef DEBUG_DMALLOC
+#include <dmalloc.h>
+#endif
+
 #define MAX_VIA_LINE_SIZE      240
 #define MAX_RECEIVED_SIZE  57
 

+ 5 - 0
main.c

@@ -21,6 +21,11 @@
 #include "globals.h"
 
 
+#ifdef DEBUG_DMALLOC
+#include <dmalloc.h>
+#endif
+
+
 static char id[]="@(#) $Id$";
 static char version[]="sip_router 0.6";
 static char help_msg[]= "\

+ 4 - 0
msg_parser.c

@@ -13,6 +13,10 @@
 #include "error.h"
 #include "dprint.h"
 
+#ifdef DEBUG_DMALLOC
+#include <dmalloc.h>
+#endif
+
 
 
 #define DEBUG

+ 3 - 0
proxy.c

@@ -13,6 +13,9 @@
 #include <string.h>
 #include <stdlib.h>
 
+#ifdef DEBUG_DMALLOC
+#include <dmalloc.h>
+#endif
 
 struct proxy_l* proxies=0;
 

+ 5 - 0
receive.c

@@ -12,6 +12,9 @@
 #include "forward.h"
 #include "action.h"
 
+#ifdef DEBUG_DMALLOC
+#include <dmalloc.h>
+#endif
 
 int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
 {
@@ -78,9 +81,11 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
 		}
 	}
 skip:
+	if (msg.new_uri) free(msg.new_uri);
 	free(msg.orig);
 	return 0;
 error:
+	if (msg.new_uri) free(msg.new_uri);
 	free(msg.orig);
 error1:
 	return -1;

+ 11 - 2
route.c

@@ -19,6 +19,10 @@
 #include "dprint.h"
 #include "proxy.h"
 
+#ifdef DEBUG_DMALLOC
+#include <dmalloc.h>
+#endif
+
 /* main routing list */
 struct route_elem* rlist[RT_NO];
 
@@ -284,8 +288,13 @@ static int eval_elem(struct expr* e, struct sip_msg* msg)
 								e->op, e->subtype);
 				break;
 		case URI_O:
-				ret=comp_str(msg->first_line.u.request.uri, e->r.param,
-								e->op, e->subtype);
+				if(msg->new_uri){
+					ret=comp_str(msg->new_uri, e->r.param,
+									e->op, e->subtype);
+				}else{
+					ret=comp_str(msg->first_line.u.request.uri, e->r.param,
+									e->op, e->subtype);
+				}
 				break;
 		case SRCIP_O:
 				ret=comp_ip(msg->src_ip, e->r.param, e->op, e->subtype);

+ 4 - 0
route_struct.c

@@ -14,6 +14,10 @@
 
 #include "dprint.h"
 
+#ifdef DEBUG_DMALLOC
+#include <dmalloc.h>
+#endif
+
 struct expr* mk_exp(int op, struct expr* left, struct expr* right)
 {
 	struct expr * e;

+ 3 - 0
udp_server.c

@@ -15,6 +15,9 @@
 #include "dprint.h"
 #include "receive.h"
 
+#ifdef DEBUG_DMALLOC
+#include <dmalloc.h>
+#endif
 
 int udp_sock;