2
0
Эх сурвалжийг харах

- added syslog suport, changed DPrint to LOG, etc.

Andrei Pelinescu-Onciul 24 жил өмнө
parent
commit
efeaaf53d6
8 өөрчлөгдсөн 143 нэмэгдсэн , 72 устгасан
  1. 8 5
      cfg_parser.c
  2. 66 1
      dprint.h
  3. 14 13
      forward.c
  4. 2 2
      main.c
  5. 31 29
      msg_parser.c
  6. 4 4
      receive.c
  7. 11 11
      route.c
  8. 7 7
      udp_server.c

+ 8 - 5
cfg_parser.c

@@ -95,9 +95,10 @@ int cfg_parse_stream(FILE* stream)
 			switch (cl.type){
 			switch (cl.type){
 				case CFG_RULE:
 				case CFG_RULE:
 					if ((ret=add_rule(&cl, &rlist))!=0){
 					if ((ret=add_rule(&cl, &rlist))!=0){
-						DPrint("ERROR: could not compile rule at line %d\n",
-							line);
-						DPrint(" ----: add_rule returned %d\n", ret);
+						LOG(L_CRIT, 
+								"ERROR: could not compile rule at line %d\n",
+								line);
+						LOG(L_CRIT, " ----: add_rule returned %d\n", ret);
 						goto error;
 						goto error;
 					}
 					}
 					break;
 					break;
@@ -105,14 +106,16 @@ int cfg_parse_stream(FILE* stream)
 				case CFG_SKIP:
 				case CFG_SKIP:
 					break;
 					break;
 				case CFG_ERROR:
 				case CFG_ERROR:
-					DPrint("ERROR: bad config line (%d):%s\n", line, buf);
+					LOG(L_CRIT, "ERROR: bad config line (%d):%s\n", line, buf);
 					goto error;
 					goto error;
 					break;
 					break;
 			}
 			}
 			line++;
 			line++;
 		}else{
 		}else{
 			if (ferror(stream)){
 			if (ferror(stream)){
-				DPrint("ERROR: reading configuration: %s\n", strerror(errno));
+				LOG(L_CRIT,
+						"ERROR: reading configuration: %s\n",
+						strerror(errno));
 				goto error;
 				goto error;
 			}
 			}
 			break;
 			break;

+ 66 - 1
dprint.h

@@ -6,6 +6,25 @@
 #ifndef dprint_h
 #ifndef dprint_h
 #define dprint_h
 #define dprint_h
 
 
+#include <syslog.h>
+
+#include "globals.h"
+
+#define L_ALERT -3
+#define L_CRIT  -2
+#define L_ERR   -1
+#define L_WARN   1
+#define L_NOTICE 2
+#define L_INFO   3
+#define L_DBG    4
+
+
+
+#define DPRINT_LEV	1
+/* log facility (see syslog(3)) */
+#define L_FAC  LOG_DAEMON
+/* priority at which we log */
+#define DPRINT_PRIO LOG_DEBUG
 
 
 
 
 void dprint (char* format, ...);
 void dprint (char* format, ...);
@@ -13,8 +32,54 @@ void dprint (char* format, ...);
 #ifdef NO_DEBUG
 #ifdef NO_DEBUG
 	#define DPrint(fmt, args...)
 	#define DPrint(fmt, args...)
 #else
 #else
-	#define DPrint(fmt,args...) dprint(fmt, ## args);
+	//#define DPrint(fmt,args...) dprint(fmt, ## args)
+	#define DPrint(fmt,args...) \
+		do{ \
+			if (debug>=DPRINT_LEV){ \
+				if (log_stderr){ \
+					dprint (fmt, ## args); \
+				}else{ \
+					syslog(DPRINT_LEV|L_FAC, fmt, ## args); \
+				}\
+			} \
+		}while(0)
+
 #endif
 #endif
 
 
 
 
+
+#define LOG(lev, fmt, args...) \
+			do { \
+				if (debug>=(lev)){ \
+					if (log_stderr) dprint (fmt, ## args); \
+					else { \
+						switch(lev){ \
+							case L_CRIT: \
+								syslog(LOG_CRIT | L_FAC, fmt, ##args); \
+								break; \
+							case L_ALERT: \
+								syslog(LOG_ALERT | L_FAC, fmt, ##args); \
+								break; \
+							case L_ERR: \
+								syslog(LOG_ERR | L_FAC, fmt, ##args); \
+								break; \
+							case L_WARN: \
+								syslog(LOG_WARNING | L_FAC, fmt, ##args); \
+								break; \
+							case L_NOTICE: \
+								syslog(LOG_NOTICE | L_FAC, fmt, ##args); \
+								break; \
+							case L_INFO: \
+								syslog(LOG_INFO | L_FAC, fmt, ##args); \
+								break; \
+							case L_DBG: \
+								syslog(LOG_DEBUG | L_FAC, fmt, ##args); \
+								break; \
+						} \
+					} \
+				} \
+			}while(0)
+
+#define DBG(fmt, args...) LOG(L_DBG, fmt, ## args)
+
 #endif /* ifndef dprint_h */
 #endif /* ifndef dprint_h */

+ 14 - 13
forward.c

@@ -76,7 +76,7 @@ int forward_request(char * orig, char* buf,
 	to=0;
 	to=0;
 	to=(struct sockaddr_in*)malloc(sizeof(struct sockaddr));
 	to=(struct sockaddr_in*)malloc(sizeof(struct sockaddr));
 	if (to==0){
 	if (to==0){
-		DPrint("ERROR: forward_reply: out of memory\n");
+		LOG(L_ERR, "ERROR: forward_reply: out of memory\n");
 		goto error;
 		goto error;
 	}
 	}
 
 
@@ -92,7 +92,7 @@ int forward_request(char * orig, char* buf,
 	new_len=len+via_len+received_len;
 	new_len=len+via_len+received_len;
 	new_buf=(char*)malloc(new_len+1);
 	new_buf=(char*)malloc(new_len+1);
 	if (new_buf==0){
 	if (new_buf==0){
-		DPrint("ERROR: forward_request: out of memory\n");
+		LOG(L_ERR, "ERROR: forward_request: out of memory\n");
 		goto error;
 		goto error;
 	}
 	}
 /* copy msg till first via */
 /* copy msg till first via */
@@ -126,8 +126,8 @@ int forward_request(char * orig, char* buf,
 	new_buf[new_len]=0;
 	new_buf[new_len]=0;
 
 
 	 /* send it! */
 	 /* send it! */
-	printf("Sending:\n%s.\n", new_buf);
-	printf("orig. len=%d, new_len=%d, via_len=%d, received_len=%d\n",
+	DBG("Sending:\n%s.\n", new_buf);
+	DBG("orig. len=%d, new_len=%d, via_len=%d, received_len=%d\n",
 			len, new_len, via_len, received_len);
 			len, new_len, via_len, received_len);
 
 
 	to->sin_family = AF_INET;
 	to->sin_family = AF_INET;
@@ -178,7 +178,7 @@ int forward_reply(char * orig, char* buf,
 	to=0;
 	to=0;
 	to=(struct sockaddr_in*)malloc(sizeof(struct sockaddr));
 	to=(struct sockaddr_in*)malloc(sizeof(struct sockaddr));
 	if (to==0){
 	if (to==0){
-		DPrint("ERROR: forward_reply: out of memory\n");
+		LOG(L_ERR, "ERROR: forward_reply: out of memory\n");
 		goto error;
 		goto error;
 	}
 	}
 
 
@@ -187,7 +187,7 @@ int forward_reply(char * orig, char* buf,
 		for (r=0; r<addresses_no; r++)
 		for (r=0; r<addresses_no; r++)
 			if(strcmp(msg->via1.host, names[r])==0) break;
 			if(strcmp(msg->via1.host, names[r])==0) break;
 		if (r==addresses_no){
 		if (r==addresses_no){
-			DPrint("ERROR: forward_reply: host in first via != me : %s\n",
+			LOG(L_NOTICE, "ERROR: forward_reply: host in first via!=me : %s\n",
 					msg->via1.host);
 					msg->via1.host);
 			/* send error msg back? */
 			/* send error msg back? */
 			goto error;
 			goto error;
@@ -196,21 +196,21 @@ int forward_reply(char * orig, char* buf,
 	/* we must remove the first via */
 	/* we must remove the first via */
 	via_len=msg->via1.size;
 	via_len=msg->via1.size;
 	size=msg->via1.hdr-buf;
 	size=msg->via1.hdr-buf;
-	printf("via len: %d, initial size: %d\n", via_len, size);
+	DBG("via len: %d, initial size: %d\n", via_len, size);
 	if (msg->via1.next){
 	if (msg->via1.next){
 		/* keep hdr =substract hdr size +1 (hdr':') and add
 		/* keep hdr =substract hdr size +1 (hdr':') and add
 		 */
 		 */
 		via_len-=strlen(msg->via1.hdr)+1;
 		via_len-=strlen(msg->via1.hdr)+1;
 		size+=strlen(msg->via1.hdr)+1;
 		size+=strlen(msg->via1.hdr)+1;
-	    printf(" adjusted via len: %d, initial size: %d\n",
+	    DBG(" adjusted via len: %d, initial size: %d\n",
 				via_len, size);
 				via_len, size);
 	}
 	}
 	new_len=len-via_len;
 	new_len=len-via_len;
 	
 	
-	printf(" old size: %d, new size: %d\n", len, new_len);
+	DBG(" old size: %d, new size: %d\n", len, new_len);
 	new_buf=(char*)malloc(new_len+1);/* +1 is for debugging (\0 to print it )*/
 	new_buf=(char*)malloc(new_len+1);/* +1 is for debugging (\0 to print it )*/
 	if (new_buf==0){
 	if (new_buf==0){
-		DPrint("ERROR: forward_reply: out of memory\n");
+		LOG(L_ERR, "ERROR: forward_reply: out of memory\n");
 		goto error;
 		goto error;
 	}
 	}
 	new_buf[new_len]=0; /* debug: print the message */
 	new_buf[new_len]=0; /* debug: print the message */
@@ -219,17 +219,18 @@ int forward_reply(char * orig, char* buf,
 	s_offset=size+via_len;
 	s_offset=size+via_len;
 	memcpy(new_buf+offset,orig+s_offset, len-s_offset);
 	memcpy(new_buf+offset,orig+s_offset, len-s_offset);
 	 /* send it! */
 	 /* send it! */
-	printf(" copied size: orig:%d, new: %d, rest: %d\n",
+	DBG(" copied size: orig:%d, new: %d, rest: %d\n",
 			s_offset, offset, 
 			s_offset, offset, 
 			len-s_offset );
 			len-s_offset );
-	printf("Sending: to %s:%d, \n%s.\n",
+	DBG("Sending: to %s:%d, \n%s.\n",
 			msg->via2.host, 
 			msg->via2.host, 
 			(unsigned short)msg->via2.port,
 			(unsigned short)msg->via2.port,
 			new_buf);
 			new_buf);
 	/* fork? gethostbyname will probably block... */
 	/* fork? gethostbyname will probably block... */
 	he=gethostbyname(msg->via2.host);
 	he=gethostbyname(msg->via2.host);
 	if (he==0){
 	if (he==0){
-		DPrint("ERROR:forward_reply:gethostbyname failure\n");
+		LOG(L_NOTICE, "ERROR:forward_reply:gethostbyname(%s) failure\n",
+				msg->via2.host);
 		goto error;
 		goto error;
 	}
 	}
 	to->sin_family = AF_INET;
 	to->sin_family = AF_INET;

+ 2 - 2
main.c

@@ -212,13 +212,13 @@ int main(int argc, char** argv)
 	/* load config file or die */
 	/* load config file or die */
 	cfg_stream=fopen (cfg_file, "r");
 	cfg_stream=fopen (cfg_file, "r");
 	if (cfg_stream==0){
 	if (cfg_stream==0){
-		DPrint("ERROR: loading config file(%s): %s\n", cfg_file,
+		fprintf(stderr, "ERROR: loading config file(%s): %s\n", cfg_file,
 				strerror(errno));
 				strerror(errno));
 		goto error;
 		goto error;
 	}
 	}
 
 
 	if (cfg_parse_stream(cfg_stream)!=0){
 	if (cfg_parse_stream(cfg_stream)!=0){
-		DPrint("ERROR: config parser failure\n");
+		fprintf(stderr, "ERROR: config parser failure\n");
 		goto error;
 		goto error;
 	}
 	}
 	
 	

+ 31 - 29
msg_parser.c

@@ -40,7 +40,7 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start * fl)
 	/* see if it's a reply (status) */
 	/* see if it's a reply (status) */
 	tmp=eat_token(buffer, len);
 	tmp=eat_token(buffer, len);
 	if ((tmp==buffer)||(tmp>=end)){
 	if ((tmp==buffer)||(tmp>=end)){
-		DPrint("ERROR: empty  or bad first line\n");
+		LOG(L_INFO, "ERROR:parse_first_line: empty  or bad first line\n");
 		goto error1;
 		goto error1;
 	}
 	}
 	if ((strlen(SIP_VERSION)==(tmp-buffer)) &&
 	if ((strlen(SIP_VERSION)==(tmp-buffer)) &&
@@ -103,11 +103,11 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start * fl)
 	return nl;
 	return nl;
 
 
 error:
 error:
-	DPrint("ERROR: bad %s first line\n", 
+	LOG(L_INFO, "ERROR:parse_first_line: bad %s first line\n", 
 		(fl->type==SIP_REPLY)?"reply(status)":"request");
 		(fl->type==SIP_REPLY)?"reply(status)":"request");
 error1:
 error1:
 	fl->type=SIP_INVALID;
 	fl->type=SIP_INVALID;
-	DPrint("ERROR: at line 0 char %d\n", offset);
+	LOG(L_INFO, "ERROR: at line 0 char %d\n", offset);
 	/* skip  line */
 	/* skip  line */
 	nl=eat_line(buffer,len);
 	nl=eat_line(buffer,len);
 	return nl;
 	return nl;
@@ -168,7 +168,7 @@ char* get_hdr_field(char *buffer, unsigned int len, struct hdr_field*  hdr_f)
 	}while( (*tmp==' ' ||  *tmp=='\t') && (offset<len) );
 	}while( (*tmp==' ' ||  *tmp=='\t') && (offset<len) );
 	if (offset==len){
 	if (offset==len){
 		hdr_f->type=HDR_ERROR;
 		hdr_f->type=HDR_ERROR;
-		DPrint("ERROR: field body too  long\n");
+		LOG(L_INFO, "ERROR: het_hdr_field: field body too  long\n");
 		goto error;
 		goto error;
 	}
 	}
 	*(tmp-1)=0; /* should be an LF */
 	*(tmp-1)=0; /* should be an LF */
@@ -193,7 +193,8 @@ char* parse_hostport(char* buf, char** host, short int* port)
 		invalid=0;
 		invalid=0;
 		*port=strtol(tmp+1, &invalid, 10);
 		*port=strtol(tmp+1, &invalid, 10);
 		if ((invalid!=0)&&(*invalid)){
 		if ((invalid!=0)&&(*invalid)){
-			DPrint("ERROR: hostport: trailing chars in port number: %s(%x)\n",
+			LOG(L_INFO, 
+					"ERROR: hostport: trailing chars in port number: %s(%x)\n",
 					invalid, invalid);
 					invalid, invalid);
 			/* report error? */
 			/* report error? */
 		}
 		}
@@ -362,23 +363,23 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
 	tmp=rest;
 	tmp=rest;
 	switch(fl.type){
 	switch(fl.type){
 		case SIP_INVALID:
 		case SIP_INVALID:
-			DPrint("invalid message\n");
+			DBG("parse_msg: invalid message\n");
 			goto error;
 			goto error;
 			break;
 			break;
 		case SIP_REQUEST:
 		case SIP_REQUEST:
-			DPrint("SIP Request:\n");
-			DPrint(" method:  <%s>\n",fl.u.request.method);
-			DPrint(" uri:     <%s>\n",fl.u.request.uri);
-			DPrint(" version: <%s>\n",fl.u.request.version);
+			DBG("SIP Request:\n");
+			DBG(" method:  <%s>\n",fl.u.request.method);
+			DBG(" uri:     <%s>\n",fl.u.request.uri);
+			DBG(" version: <%s>\n",fl.u.request.version);
 			break;
 			break;
 		case SIP_REPLY:
 		case SIP_REPLY:
-			DPrint("SIP Reply  (status):\n");
-			DPrint(" version: <%s>\n",fl.u.reply.version);
-			DPrint(" status:  <%s>\n",fl.u.reply.status);
-			DPrint(" reason:  <%s>\n",fl.u.reply.reason);
+			DBG("SIP Reply  (status):\n");
+			DBG(" version: <%s>\n",fl.u.reply.version);
+			DBG(" status:  <%s>\n",fl.u.reply.status);
+			DBG(" reason:  <%s>\n",fl.u.reply.reason);
 			break;
 			break;
 		default:
 		default:
-			DPrint("unknown type %d\n",fl.type);
+			DBG("unknown type %d\n",fl.type);
 	}
 	}
 	
 	
 	/*find first Via: */
 	/*find first Via: */
@@ -390,7 +391,7 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
 		offset+=rest-tmp;
 		offset+=rest-tmp;
 		switch (hf.type){
 		switch (hf.type){
 			case HDR_ERROR:
 			case HDR_ERROR:
-				DPrint("ERROR: bad header  field\n");
+				LOG(L_INFO,"ERROR: bad header  field\n");
 				goto  error;
 				goto  error;
 			case HDR_EOH: 
 			case HDR_EOH: 
 				goto skip;
 				goto skip;
@@ -402,11 +403,12 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
 						for (bar=first_via;(first_via) && (*bar);bar++)
 						for (bar=first_via;(first_via) && (*bar);bar++)
 							if ((*bar=='\r')||(*bar=='\n'))	*bar=' ';
 							if ((*bar=='\r')||(*bar=='\n'))	*bar=' ';
 				#ifdef DEBUG
 				#ifdef DEBUG
-						printf("first via: <%s>\n", first_via);
+						DBG("first via: <%s>\n", first_via);
 				#endif
 				#endif
 						bar=parse_via_body(first_via, strlen(first_via), &vb1);
 						bar=parse_via_body(first_via, strlen(first_via), &vb1);
 						if (vb1.error!=VIA_PARSE_OK){
 						if (vb1.error!=VIA_PARSE_OK){
-							DPrint("ERROR: parsing via body: %s\n", first_via);
+							LOG(L_INFO, "ERROR: parsing via body: %s\n",
+									first_via);
 							goto error;
 							goto error;
 						}
 						}
 						
 						
@@ -430,7 +432,7 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
 				break;
 				break;
 		}
 		}
 	#ifdef DEBUG
 	#ifdef DEBUG
-		printf("header field type %d, name=<%s>, body=<%s>\n",
+		DBG("header field type %d, name=<%s>, body=<%s>\n",
 			hf.type, hf.name, hf.body);
 			hf.type, hf.name, hf.body);
 	#endif
 	#endif
 		tmp=rest;
 		tmp=rest;
@@ -444,7 +446,7 @@ skip:
 	if (second_via) {
 	if (second_via) {
 		tmp=parse_via_body(second_via, strlen(second_via), &vb2);
 		tmp=parse_via_body(second_via, strlen(second_via), &vb2);
 		if (vb2.error!=VIA_PARSE_OK){
 		if (vb2.error!=VIA_PARSE_OK){
-			DPrint("ERROR: parsing via2 body: %s\n", second_via);
+			LOG(L_INFO, "ERROR: parsing via2 body: %s\n", second_via);
 			goto error;
 			goto error;
 		}
 		}
 		vb2.size=tmp-second_via; 
 		vb2.size=tmp-second_via; 
@@ -455,17 +457,17 @@ skip:
 
 
 #ifdef DEBUG
 #ifdef DEBUG
 	/* dump parsed data */
 	/* dump parsed data */
-	printf(" first  via: <%s/%s/%s> <%s:%d>",
+	DBG(" first  via: <%s/%s/%s> <%s:%d>",
 			vb1.name, vb1.version, vb1.transport, vb1.host, vb1.port);
 			vb1.name, vb1.version, vb1.transport, vb1.host, vb1.port);
-	if (vb1.params) printf(";<%s>", vb1.params);
-	if (vb1.comment) printf(" <%s>", vb1.comment);
-	printf ("\n");
+	if (vb1.params)  DBG(";<%s>", vb1.params);
+	if (vb1.comment) DBG(" <%s>", vb1.comment);
+	DBG ("\n");
 	if (second_via){
 	if (second_via){
-		printf(" second via: <%s/%s/%s> <%s:%d>",
+		DBG(" second via: <%s/%s/%s> <%s:%d>",
 				vb2.name, vb2.version, vb2.transport, vb2.host, vb2.port);
 				vb2.name, vb2.version, vb2.transport, vb2.host, vb2.port);
-		if (vb2.params) printf(";<%s>", vb2.params);
-		if (vb2.comment) printf(" <%s>", vb2.comment);
-		printf ("\n");
+		if (vb2.params)  DBG(";<%s>", vb2.params);
+		if (vb2.comment) DBG(" <%s>", vb2.comment);
+		DBG("\n");
 	}
 	}
 #endif
 #endif
 	
 	
@@ -475,7 +477,7 @@ skip:
 	memcpy(&(msg->via2), &vb2, sizeof(struct via_body));
 	memcpy(&(msg->via2), &vb2, sizeof(struct via_body));
 
 
 #ifdef DEBUG
 #ifdef DEBUG
-	printf ("exiting parse_msg\n");
+	DBG("exiting parse_msg\n");
 #endif
 #endif
 
 
 	return 0;
 	return 0;

+ 4 - 4
receive.c

@@ -20,7 +20,7 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
 	/* make a copy of the message */
 	/* make a copy of the message */
 	orig=(char*) malloc(len);
 	orig=(char*) malloc(len);
 	if (orig==0){
 	if (orig==0){
-		DPrint("ERROR: memory allocation failure\n");
+		LOG(L_ERR, "ERROR:receive_msg: memory allocation failure\n");
 		goto error1;
 		goto error1;
 	}
 	}
 	memcpy(orig, buf, len);
 	memcpy(orig, buf, len);
@@ -44,12 +44,12 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
 					  );
 					  );
 		if (re==0){
 		if (re==0){
 			/* no route found, send back error msg? */
 			/* no route found, send back error msg? */
-			DPrint("WARNING: no route found!\n");
+			LOG(L_WARN, "WARNING: receive_msg: no route found!\n");
 			goto skip;
 			goto skip;
 		}
 		}
 		re->tx++;
 		re->tx++;
 		/* send msg */
 		/* send msg */
-		DPrint(" found route to: %s\n", re->host.h_name);
+		DBG(" found route to: %s\n", re->host.h_name);
 		forward_request(orig, buf, len, &msg, re, src_ip);
 		forward_request(orig, buf, len, &msg, re, src_ip);
 	}else if (msg.first_line.type==SIP_REPLY){
 	}else if (msg.first_line.type==SIP_REPLY){
 		/* sanity checks */
 		/* sanity checks */
@@ -65,7 +65,7 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
 		
 		
 		/* send the msg */
 		/* send the msg */
 		if (forward_reply(orig, buf, len, &msg)==0){
 		if (forward_reply(orig, buf, len, &msg)==0){
-			DPrint(" reply forwarded to %s:%d\n", 
+			DBG(" reply forwarded to %s:%d\n", 
 						msg.via2.host,
 						msg.via2.host,
 						(unsigned short) msg.via2.port);
 						(unsigned short) msg.via2.port);
 		}
 		}

+ 11 - 11
route.c

@@ -95,12 +95,12 @@ int add_rule(struct cfg_line* cl, struct route_elem** head)
 	if (re==0) return E_OUT_OF_MEM;
 	if (re==0) return E_OUT_OF_MEM;
 
 
 	if (regcomp(&(re->method), cl->method, REG_EXTENDED|REG_NOSUB|REG_ICASE)){
 	if (regcomp(&(re->method), cl->method, REG_EXTENDED|REG_NOSUB|REG_ICASE)){
-		DPrint("ERROR: bad re \"%s\"\n", cl->method);
+		LOG(L_CRIT, "ERROR: add_rule: bad re \"%s\"\n", cl->method);
 		ret=E_BAD_RE;
 		ret=E_BAD_RE;
 		goto error;
 		goto error;
 	}
 	}
 	if (regcomp(&(re->uri), cl->uri, REG_EXTENDED|REG_NOSUB|REG_ICASE) ){
 	if (regcomp(&(re->uri), cl->uri, REG_EXTENDED|REG_NOSUB|REG_ICASE) ){
-		DPrint("ERROR: bad re \"%s\"\n", cl->uri);
+		LOG(L_CRIT, "ERROR: add_rule: bad re \"%s\"\n", cl->uri);
 		ret=E_BAD_RE;
 		ret=E_BAD_RE;
 		goto error;
 		goto error;
 	}
 	}
@@ -108,7 +108,7 @@ int add_rule(struct cfg_line* cl, struct route_elem** head)
 	
 	
 	he=gethostbyname(cl->address);
 	he=gethostbyname(cl->address);
 	if (he==0){
 	if (he==0){
-		DPrint("ERROR: cannot resolve \"%s\"\n", cl->address);
+		LOG(L_CRIT, "ERROR: add_rule: cannot resolve \"%s\"\n", cl->address);
 		ret=E_BAD_ADDRESS;
 		ret=E_BAD_ADDRESS;
 		goto error;
 		goto error;
 	}
 	}
@@ -181,7 +181,7 @@ struct route_elem* route_match(char* method, char* uri, struct route_elem** rl)
 {
 {
 	struct route_elem* t;
 	struct route_elem* t;
 	if (*rl==0){
 	if (*rl==0){
-		DPrint("WARNING: empty routing table\n");
+		LOG(L_ERR, "WARNING: route_match: empty routing table\n");
 		return 0;
 		return 0;
 	}
 	}
 	for (t=*rl; t; t=t->next){
 	for (t=*rl; t; t=t->next){
@@ -206,25 +206,25 @@ void print_rl()
 	int i,j;
 	int i,j;
 
 
 	if (rlist==0){
 	if (rlist==0){
-		DPrint("the routing table is empty\n");
+		LOG(L_INFO, "the routing table is empty\n");
 		return;
 		return;
 	}
 	}
 	
 	
 	for (t=rlist,i=0; t; i++, t=t->next){
 	for (t=rlist,i=0; t; i++, t=t->next){
-		DPrint("%2d.to=%s ; route ok=%d\n", i,
+		LOG(L_INFO, "%2d.to=%s ; route ok=%d\n", i,
 				t->host.h_name, t->ok);
 				t->host.h_name, t->ok);
-		DPrint("   ips: ");
+		LOG(L_INFO, "   ips: ");
 		for (j=0; t->host.h_addr_list[j]; j++){
 		for (j=0; t->host.h_addr_list[j]; j++){
-			DPrint("%d.%d.%d.%d ", 
+			LOG(L_INFO, "%d.%d.%d.%d ", 
 				(unsigned char) t->host.h_addr_list[j][0],
 				(unsigned char) t->host.h_addr_list[j][0],
 				(unsigned char) t->host.h_addr_list[j][1],
 				(unsigned char) t->host.h_addr_list[j][1],
 			    (unsigned char) t->host.h_addr_list[j][2],
 			    (unsigned char) t->host.h_addr_list[j][2],
 				(unsigned char) t->host.h_addr_list[j][3]
 				(unsigned char) t->host.h_addr_list[j][3]
 				  );
 				  );
 		}
 		}
-		DPrint("\n");
-		DPrint("   port:%d\n", (unsigned short)t->port);
-		DPrint("   Statistics: tx=%d, errors=%d, tx_bytes=%d, idx=%d\n",
+		LOG(L_INFO, "\n");
+		LOG(L_INFO, "   port:%d\n", (unsigned short)t->port);
+		LOG(L_INFO, "   Statistics: tx=%d, errors=%d, tx_bytes=%d, idx=%d\n",
 				t->tx, t->errors, t->tx_bytes, t->current_addr_idx);
 				t->tx, t->errors, t->tx_bytes, t->current_addr_idx);
 	}
 	}
 
 

+ 7 - 7
udp_server.c

@@ -24,7 +24,7 @@ int udp_init(unsigned long ip, unsigned short port)
 
 
 	addr=(struct sockaddr_in*)malloc(sizeof(struct sockaddr));
 	addr=(struct sockaddr_in*)malloc(sizeof(struct sockaddr));
 	if (addr==0){
 	if (addr==0){
-		DPrint("ERROR: udp_init: out of memory\n");
+		LOG(L_ERR, "ERROR: udp_init: out of memory\n");
 		goto error;
 		goto error;
 	}
 	}
 	addr->sin_family=AF_INET;
 	addr->sin_family=AF_INET;
@@ -33,7 +33,7 @@ int udp_init(unsigned long ip, unsigned short port)
 
 
 	udp_sock = socket(PF_INET, SOCK_DGRAM, 0);
 	udp_sock = socket(PF_INET, SOCK_DGRAM, 0);
 	if (udp_sock==-1){
 	if (udp_sock==-1){
-		DPrint("ERROR: udp_init: socket: %s\n", strerror());
+		LOG(L_ERR, "ERROR: udp_init: socket: %s\n", strerror());
 		goto error;
 		goto error;
 	}
 	}
 	/* set sock opts? */
 	/* set sock opts? */
@@ -41,12 +41,12 @@ int udp_init(unsigned long ip, unsigned short port)
 	if (setsockopt(udp_sock, SOL_SOCKET, SO_REUSEADDR,
 	if (setsockopt(udp_sock, SOL_SOCKET, SO_REUSEADDR,
 					(void*)&optval, sizeof(optval)) ==-1)
 					(void*)&optval, sizeof(optval)) ==-1)
 	{
 	{
-		DPrint("ERROR: udp_init: setsockopt: %s\n", strerror());
+		LOG(L_ERR, "ERROR: udp_init: setsockopt: %s\n", strerror());
 		goto error;
 		goto error;
 	}
 	}
 
 
 	if (bind(udp_sock, (struct sockaddr*) addr, sizeof(struct sockaddr))==-1){
 	if (bind(udp_sock, (struct sockaddr*) addr, sizeof(struct sockaddr))==-1){
-		DPrint("ERROR: udp_init: bind: %s\n", strerror());
+		LOG(L_ERR, "ERROR: udp_init: bind: %s\n", strerror());
 		goto error;
 		goto error;
 	}
 	}
 
 
@@ -69,7 +69,7 @@ int udp_rcv_loop()
 
 
 	from=(struct sockaddr*) malloc(sizeof(struct sockaddr));
 	from=(struct sockaddr*) malloc(sizeof(struct sockaddr));
 	if (from==0){
 	if (from==0){
-		DPrint("ERROR: udp_rcv_loop: out of memory\n");
+		LOG(L_ERR, "ERROR: udp_rcv_loop: out of memory\n");
 		goto error;
 		goto error;
 	}
 	}
 
 
@@ -77,7 +77,7 @@ int udp_rcv_loop()
 		fromlen=sizeof(struct sockaddr);
 		fromlen=sizeof(struct sockaddr);
 		len=recvfrom(udp_sock, buf, BUF_SIZE, 0, from, &fromlen);
 		len=recvfrom(udp_sock, buf, BUF_SIZE, 0, from, &fromlen);
 		if (len==-1){
 		if (len==-1){
-			DPrint("ERROR: udp_rcv_loop:recvfrom: %s\n", strerror());
+			LOG(L_ERR, "ERROR: udp_rcv_loop:recvfrom: %s\n", strerror());
 			if (errno==EINTR)	goto skip;
 			if (errno==EINTR)	goto skip;
 			else goto error;
 			else goto error;
 		}
 		}
@@ -108,7 +108,7 @@ int udp_send(char *buf, int len, struct sockaddr*  to, int tolen)
 again:
 again:
 	n=sendto(udp_sock, buf, len, 0, to, tolen);
 	n=sendto(udp_sock, buf, len, 0, to, tolen);
 	if (n==-1){
 	if (n==-1){
-		DPrint("ERROR: udp_send: sendto: %s\n", strerror());
+		LOG(L_ERR, "ERROR: udp_send: sendto: %s\n", strerror());
 		if (errno==EINTR) goto again;
 		if (errno==EINTR) goto again;
 	}
 	}
 	return n;
 	return n;