... | ... |
@@ -95,9 +95,10 @@ int cfg_parse_stream(FILE* stream) |
95 | 95 |
switch (cl.type){ |
96 | 96 |
case CFG_RULE: |
97 | 97 |
if ((ret=add_rule(&cl, &rlist))!=0){ |
98 |
- DPrint("ERROR: could not compile rule at line %d\n", |
|
99 |
- line); |
|
100 |
- DPrint(" ----: add_rule returned %d\n", ret); |
|
98 |
+ LOG(L_CRIT, |
|
99 |
+ "ERROR: could not compile rule at line %d\n", |
|
100 |
+ line); |
|
101 |
+ LOG(L_CRIT, " ----: add_rule returned %d\n", ret); |
|
101 | 102 |
goto error; |
102 | 103 |
} |
103 | 104 |
break; |
... | ... |
@@ -105,14 +106,16 @@ int cfg_parse_stream(FILE* stream) |
105 | 106 |
case CFG_SKIP: |
106 | 107 |
break; |
107 | 108 |
case CFG_ERROR: |
108 |
- DPrint("ERROR: bad config line (%d):%s\n", line, buf); |
|
109 |
+ LOG(L_CRIT, "ERROR: bad config line (%d):%s\n", line, buf); |
|
109 | 110 |
goto error; |
110 | 111 |
break; |
111 | 112 |
} |
112 | 113 |
line++; |
113 | 114 |
}else{ |
114 | 115 |
if (ferror(stream)){ |
115 |
- DPrint("ERROR: reading configuration: %s\n", strerror(errno)); |
|
116 |
+ LOG(L_CRIT, |
|
117 |
+ "ERROR: reading configuration: %s\n", |
|
118 |
+ strerror(errno)); |
|
116 | 119 |
goto error; |
117 | 120 |
} |
118 | 121 |
break; |
... | ... |
@@ -6,6 +6,25 @@ |
6 | 6 |
#ifndef dprint_h |
7 | 7 |
#define dprint_h |
8 | 8 |
|
9 |
+#include <syslog.h> |
|
10 |
+ |
|
11 |
+#include "globals.h" |
|
12 |
+ |
|
13 |
+#define L_ALERT -3 |
|
14 |
+#define L_CRIT -2 |
|
15 |
+#define L_ERR -1 |
|
16 |
+#define L_WARN 1 |
|
17 |
+#define L_NOTICE 2 |
|
18 |
+#define L_INFO 3 |
|
19 |
+#define L_DBG 4 |
|
20 |
+ |
|
21 |
+ |
|
22 |
+ |
|
23 |
+#define DPRINT_LEV 1 |
|
24 |
+/* log facility (see syslog(3)) */ |
|
25 |
+#define L_FAC LOG_DAEMON |
|
26 |
+/* priority at which we log */ |
|
27 |
+#define DPRINT_PRIO LOG_DEBUG |
|
9 | 28 |
|
10 | 29 |
|
11 | 30 |
void dprint (char* format, ...); |
... | ... |
@@ -13,8 +32,54 @@ void dprint (char* format, ...); |
13 | 32 |
#ifdef NO_DEBUG |
14 | 33 |
#define DPrint(fmt, args...) |
15 | 34 |
#else |
16 |
- #define DPrint(fmt,args...) dprint(fmt, ## args); |
|
35 |
+ //#define DPrint(fmt,args...) dprint(fmt, ## args) |
|
36 |
+ #define DPrint(fmt,args...) \ |
|
37 |
+ do{ \ |
|
38 |
+ if (debug>=DPRINT_LEV){ \ |
|
39 |
+ if (log_stderr){ \ |
|
40 |
+ dprint (fmt, ## args); \ |
|
41 |
+ }else{ \ |
|
42 |
+ syslog(DPRINT_LEV|L_FAC, fmt, ## args); \ |
|
43 |
+ }\ |
|
44 |
+ } \ |
|
45 |
+ }while(0) |
|
46 |
+ |
|
17 | 47 |
#endif |
18 | 48 |
|
19 | 49 |
|
50 |
+ |
|
51 |
+#define LOG(lev, fmt, args...) \ |
|
52 |
+ do { \ |
|
53 |
+ if (debug>=(lev)){ \ |
|
54 |
+ if (log_stderr) dprint (fmt, ## args); \ |
|
55 |
+ else { \ |
|
56 |
+ switch(lev){ \ |
|
57 |
+ case L_CRIT: \ |
|
58 |
+ syslog(LOG_CRIT | L_FAC, fmt, ##args); \ |
|
59 |
+ break; \ |
|
60 |
+ case L_ALERT: \ |
|
61 |
+ syslog(LOG_ALERT | L_FAC, fmt, ##args); \ |
|
62 |
+ break; \ |
|
63 |
+ case L_ERR: \ |
|
64 |
+ syslog(LOG_ERR | L_FAC, fmt, ##args); \ |
|
65 |
+ break; \ |
|
66 |
+ case L_WARN: \ |
|
67 |
+ syslog(LOG_WARNING | L_FAC, fmt, ##args); \ |
|
68 |
+ break; \ |
|
69 |
+ case L_NOTICE: \ |
|
70 |
+ syslog(LOG_NOTICE | L_FAC, fmt, ##args); \ |
|
71 |
+ break; \ |
|
72 |
+ case L_INFO: \ |
|
73 |
+ syslog(LOG_INFO | L_FAC, fmt, ##args); \ |
|
74 |
+ break; \ |
|
75 |
+ case L_DBG: \ |
|
76 |
+ syslog(LOG_DEBUG | L_FAC, fmt, ##args); \ |
|
77 |
+ break; \ |
|
78 |
+ } \ |
|
79 |
+ } \ |
|
80 |
+ } \ |
|
81 |
+ }while(0) |
|
82 |
+ |
|
83 |
+#define DBG(fmt, args...) LOG(L_DBG, fmt, ## args) |
|
84 |
+ |
|
20 | 85 |
#endif /* ifndef dprint_h */ |
... | ... |
@@ -76,7 +76,7 @@ int forward_request(char * orig, char* buf, |
76 | 76 |
to=0; |
77 | 77 |
to=(struct sockaddr_in*)malloc(sizeof(struct sockaddr)); |
78 | 78 |
if (to==0){ |
79 |
- DPrint("ERROR: forward_reply: out of memory\n"); |
|
79 |
+ LOG(L_ERR, "ERROR: forward_reply: out of memory\n"); |
|
80 | 80 |
goto error; |
81 | 81 |
} |
82 | 82 |
|
... | ... |
@@ -92,7 +92,7 @@ int forward_request(char * orig, char* buf, |
92 | 92 |
new_len=len+via_len+received_len; |
93 | 93 |
new_buf=(char*)malloc(new_len+1); |
94 | 94 |
if (new_buf==0){ |
95 |
- DPrint("ERROR: forward_request: out of memory\n"); |
|
95 |
+ LOG(L_ERR, "ERROR: forward_request: out of memory\n"); |
|
96 | 96 |
goto error; |
97 | 97 |
} |
98 | 98 |
/* copy msg till first via */ |
... | ... |
@@ -126,8 +126,8 @@ int forward_request(char * orig, char* buf, |
126 | 126 |
new_buf[new_len]=0; |
127 | 127 |
|
128 | 128 |
/* send it! */ |
129 |
- printf("Sending:\n%s.\n", new_buf); |
|
130 |
- printf("orig. len=%d, new_len=%d, via_len=%d, received_len=%d\n", |
|
129 |
+ DBG("Sending:\n%s.\n", new_buf); |
|
130 |
+ DBG("orig. len=%d, new_len=%d, via_len=%d, received_len=%d\n", |
|
131 | 131 |
len, new_len, via_len, received_len); |
132 | 132 |
|
133 | 133 |
to->sin_family = AF_INET; |
... | ... |
@@ -178,7 +178,7 @@ int forward_reply(char * orig, char* buf, |
178 | 178 |
to=0; |
179 | 179 |
to=(struct sockaddr_in*)malloc(sizeof(struct sockaddr)); |
180 | 180 |
if (to==0){ |
181 |
- DPrint("ERROR: forward_reply: out of memory\n"); |
|
181 |
+ LOG(L_ERR, "ERROR: forward_reply: out of memory\n"); |
|
182 | 182 |
goto error; |
183 | 183 |
} |
184 | 184 |
|
... | ... |
@@ -187,7 +187,7 @@ int forward_reply(char * orig, char* buf, |
187 | 187 |
for (r=0; r<addresses_no; r++) |
188 | 188 |
if(strcmp(msg->via1.host, names[r])==0) break; |
189 | 189 |
if (r==addresses_no){ |
190 |
- DPrint("ERROR: forward_reply: host in first via != me : %s\n", |
|
190 |
+ LOG(L_NOTICE, "ERROR: forward_reply: host in first via!=me : %s\n", |
|
191 | 191 |
msg->via1.host); |
192 | 192 |
/* send error msg back? */ |
193 | 193 |
goto error; |
... | ... |
@@ -196,21 +196,21 @@ int forward_reply(char * orig, char* buf, |
196 | 196 |
/* we must remove the first via */ |
197 | 197 |
via_len=msg->via1.size; |
198 | 198 |
size=msg->via1.hdr-buf; |
199 |
- printf("via len: %d, initial size: %d\n", via_len, size); |
|
199 |
+ DBG("via len: %d, initial size: %d\n", via_len, size); |
|
200 | 200 |
if (msg->via1.next){ |
201 | 201 |
/* keep hdr =substract hdr size +1 (hdr':') and add |
202 | 202 |
*/ |
203 | 203 |
via_len-=strlen(msg->via1.hdr)+1; |
204 | 204 |
size+=strlen(msg->via1.hdr)+1; |
205 |
- printf(" adjusted via len: %d, initial size: %d\n", |
|
205 |
+ DBG(" adjusted via len: %d, initial size: %d\n", |
|
206 | 206 |
via_len, size); |
207 | 207 |
} |
208 | 208 |
new_len=len-via_len; |
209 | 209 |
|
210 |
- printf(" old size: %d, new size: %d\n", len, new_len); |
|
210 |
+ DBG(" old size: %d, new size: %d\n", len, new_len); |
|
211 | 211 |
new_buf=(char*)malloc(new_len+1);/* +1 is for debugging (\0 to print it )*/ |
212 | 212 |
if (new_buf==0){ |
213 |
- DPrint("ERROR: forward_reply: out of memory\n"); |
|
213 |
+ LOG(L_ERR, "ERROR: forward_reply: out of memory\n"); |
|
214 | 214 |
goto error; |
215 | 215 |
} |
216 | 216 |
new_buf[new_len]=0; /* debug: print the message */ |
... | ... |
@@ -219,17 +219,18 @@ int forward_reply(char * orig, char* buf, |
219 | 219 |
s_offset=size+via_len; |
220 | 220 |
memcpy(new_buf+offset,orig+s_offset, len-s_offset); |
221 | 221 |
/* send it! */ |
222 |
- printf(" copied size: orig:%d, new: %d, rest: %d\n", |
|
222 |
+ DBG(" copied size: orig:%d, new: %d, rest: %d\n", |
|
223 | 223 |
s_offset, offset, |
224 | 224 |
len-s_offset ); |
225 |
- printf("Sending: to %s:%d, \n%s.\n", |
|
225 |
+ DBG("Sending: to %s:%d, \n%s.\n", |
|
226 | 226 |
msg->via2.host, |
227 | 227 |
(unsigned short)msg->via2.port, |
228 | 228 |
new_buf); |
229 | 229 |
/* fork? gethostbyname will probably block... */ |
230 | 230 |
he=gethostbyname(msg->via2.host); |
231 | 231 |
if (he==0){ |
232 |
- DPrint("ERROR:forward_reply:gethostbyname failure\n"); |
|
232 |
+ LOG(L_NOTICE, "ERROR:forward_reply:gethostbyname(%s) failure\n", |
|
233 |
+ msg->via2.host); |
|
233 | 234 |
goto error; |
234 | 235 |
} |
235 | 236 |
to->sin_family = AF_INET; |
... | ... |
@@ -212,13 +212,13 @@ int main(int argc, char** argv) |
212 | 212 |
/* load config file or die */ |
213 | 213 |
cfg_stream=fopen (cfg_file, "r"); |
214 | 214 |
if (cfg_stream==0){ |
215 |
- DPrint("ERROR: loading config file(%s): %s\n", cfg_file, |
|
215 |
+ fprintf(stderr, "ERROR: loading config file(%s): %s\n", cfg_file, |
|
216 | 216 |
strerror(errno)); |
217 | 217 |
goto error; |
218 | 218 |
} |
219 | 219 |
|
220 | 220 |
if (cfg_parse_stream(cfg_stream)!=0){ |
221 |
- DPrint("ERROR: config parser failure\n"); |
|
221 |
+ fprintf(stderr, "ERROR: config parser failure\n"); |
|
222 | 222 |
goto error; |
223 | 223 |
} |
224 | 224 |
|
... | ... |
@@ -40,7 +40,7 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start * fl) |
40 | 40 |
/* see if it's a reply (status) */ |
41 | 41 |
tmp=eat_token(buffer, len); |
42 | 42 |
if ((tmp==buffer)||(tmp>=end)){ |
43 |
- DPrint("ERROR: empty or bad first line\n"); |
|
43 |
+ LOG(L_INFO, "ERROR:parse_first_line: empty or bad first line\n"); |
|
44 | 44 |
goto error1; |
45 | 45 |
} |
46 | 46 |
if ((strlen(SIP_VERSION)==(tmp-buffer)) && |
... | ... |
@@ -103,11 +103,11 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start * fl) |
103 | 103 |
return nl; |
104 | 104 |
|
105 | 105 |
error: |
106 |
- DPrint("ERROR: bad %s first line\n", |
|
106 |
+ LOG(L_INFO, "ERROR:parse_first_line: bad %s first line\n", |
|
107 | 107 |
(fl->type==SIP_REPLY)?"reply(status)":"request"); |
108 | 108 |
error1: |
109 | 109 |
fl->type=SIP_INVALID; |
110 |
- DPrint("ERROR: at line 0 char %d\n", offset); |
|
110 |
+ LOG(L_INFO, "ERROR: at line 0 char %d\n", offset); |
|
111 | 111 |
/* skip line */ |
112 | 112 |
nl=eat_line(buffer,len); |
113 | 113 |
return nl; |
... | ... |
@@ -168,7 +168,7 @@ char* get_hdr_field(char *buffer, unsigned int len, struct hdr_field* hdr_f) |
168 | 168 |
}while( (*tmp==' ' || *tmp=='\t') && (offset<len) ); |
169 | 169 |
if (offset==len){ |
170 | 170 |
hdr_f->type=HDR_ERROR; |
171 |
- DPrint("ERROR: field body too long\n"); |
|
171 |
+ LOG(L_INFO, "ERROR: het_hdr_field: field body too long\n"); |
|
172 | 172 |
goto error; |
173 | 173 |
} |
174 | 174 |
*(tmp-1)=0; /* should be an LF */ |
... | ... |
@@ -193,7 +193,8 @@ char* parse_hostport(char* buf, char** host, short int* port) |
193 | 193 |
invalid=0; |
194 | 194 |
*port=strtol(tmp+1, &invalid, 10); |
195 | 195 |
if ((invalid!=0)&&(*invalid)){ |
196 |
- DPrint("ERROR: hostport: trailing chars in port number: %s(%x)\n", |
|
196 |
+ LOG(L_INFO, |
|
197 |
+ "ERROR: hostport: trailing chars in port number: %s(%x)\n", |
|
197 | 198 |
invalid, invalid); |
198 | 199 |
/* report error? */ |
199 | 200 |
} |
... | ... |
@@ -362,23 +363,23 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg) |
362 | 363 |
tmp=rest; |
363 | 364 |
switch(fl.type){ |
364 | 365 |
case SIP_INVALID: |
365 |
- DPrint("invalid message\n"); |
|
366 |
+ DBG("parse_msg: invalid message\n"); |
|
366 | 367 |
goto error; |
367 | 368 |
break; |
368 | 369 |
case SIP_REQUEST: |
369 |
- DPrint("SIP Request:\n"); |
|
370 |
- DPrint(" method: <%s>\n",fl.u.request.method); |
|
371 |
- DPrint(" uri: <%s>\n",fl.u.request.uri); |
|
372 |
- DPrint(" version: <%s>\n",fl.u.request.version); |
|
370 |
+ DBG("SIP Request:\n"); |
|
371 |
+ DBG(" method: <%s>\n",fl.u.request.method); |
|
372 |
+ DBG(" uri: <%s>\n",fl.u.request.uri); |
|
373 |
+ DBG(" version: <%s>\n",fl.u.request.version); |
|
373 | 374 |
break; |
374 | 375 |
case SIP_REPLY: |
375 |
- DPrint("SIP Reply (status):\n"); |
|
376 |
- DPrint(" version: <%s>\n",fl.u.reply.version); |
|
377 |
- DPrint(" status: <%s>\n",fl.u.reply.status); |
|
378 |
- DPrint(" reason: <%s>\n",fl.u.reply.reason); |
|
376 |
+ DBG("SIP Reply (status):\n"); |
|
377 |
+ DBG(" version: <%s>\n",fl.u.reply.version); |
|
378 |
+ DBG(" status: <%s>\n",fl.u.reply.status); |
|
379 |
+ DBG(" reason: <%s>\n",fl.u.reply.reason); |
|
379 | 380 |
break; |
380 | 381 |
default: |
381 |
- DPrint("unknown type %d\n",fl.type); |
|
382 |
+ DBG("unknown type %d\n",fl.type); |
|
382 | 383 |
} |
383 | 384 |
|
384 | 385 |
/*find first Via: */ |
... | ... |
@@ -390,7 +391,7 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg) |
390 | 391 |
offset+=rest-tmp; |
391 | 392 |
switch (hf.type){ |
392 | 393 |
case HDR_ERROR: |
393 |
- DPrint("ERROR: bad header field\n"); |
|
394 |
+ LOG(L_INFO,"ERROR: bad header field\n"); |
|
394 | 395 |
goto error; |
395 | 396 |
case HDR_EOH: |
396 | 397 |
goto skip; |
... | ... |
@@ -402,11 +403,12 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg) |
402 | 403 |
for (bar=first_via;(first_via) && (*bar);bar++) |
403 | 404 |
if ((*bar=='\r')||(*bar=='\n')) *bar=' '; |
404 | 405 |
#ifdef DEBUG |
405 |
- printf("first via: <%s>\n", first_via); |
|
406 |
+ DBG("first via: <%s>\n", first_via); |
|
406 | 407 |
#endif |
407 | 408 |
bar=parse_via_body(first_via, strlen(first_via), &vb1); |
408 | 409 |
if (vb1.error!=VIA_PARSE_OK){ |
409 |
- DPrint("ERROR: parsing via body: %s\n", first_via); |
|
410 |
+ LOG(L_INFO, "ERROR: parsing via body: %s\n", |
|
411 |
+ first_via); |
|
410 | 412 |
goto error; |
411 | 413 |
} |
412 | 414 |
|
... | ... |
@@ -430,7 +432,7 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg) |
430 | 432 |
break; |
431 | 433 |
} |
432 | 434 |
#ifdef DEBUG |
433 |
- printf("header field type %d, name=<%s>, body=<%s>\n", |
|
435 |
+ DBG("header field type %d, name=<%s>, body=<%s>\n", |
|
434 | 436 |
hf.type, hf.name, hf.body); |
435 | 437 |
#endif |
436 | 438 |
tmp=rest; |
... | ... |
@@ -444,7 +446,7 @@ skip: |
444 | 446 |
if (second_via) { |
445 | 447 |
tmp=parse_via_body(second_via, strlen(second_via), &vb2); |
446 | 448 |
if (vb2.error!=VIA_PARSE_OK){ |
447 |
- DPrint("ERROR: parsing via2 body: %s\n", second_via); |
|
449 |
+ LOG(L_INFO, "ERROR: parsing via2 body: %s\n", second_via); |
|
448 | 450 |
goto error; |
449 | 451 |
} |
450 | 452 |
vb2.size=tmp-second_via; |
... | ... |
@@ -455,17 +457,17 @@ skip: |
455 | 457 |
|
456 | 458 |
#ifdef DEBUG |
457 | 459 |
/* dump parsed data */ |
458 |
- printf(" first via: <%s/%s/%s> <%s:%d>", |
|
460 |
+ DBG(" first via: <%s/%s/%s> <%s:%d>", |
|
459 | 461 |
vb1.name, vb1.version, vb1.transport, vb1.host, vb1.port); |
460 |
- if (vb1.params) printf(";<%s>", vb1.params); |
|
461 |
- if (vb1.comment) printf(" <%s>", vb1.comment); |
|
462 |
- printf ("\n"); |
|
462 |
+ if (vb1.params) DBG(";<%s>", vb1.params); |
|
463 |
+ if (vb1.comment) DBG(" <%s>", vb1.comment); |
|
464 |
+ DBG ("\n"); |
|
463 | 465 |
if (second_via){ |
464 |
- printf(" second via: <%s/%s/%s> <%s:%d>", |
|
466 |
+ DBG(" second via: <%s/%s/%s> <%s:%d>", |
|
465 | 467 |
vb2.name, vb2.version, vb2.transport, vb2.host, vb2.port); |
466 |
- if (vb2.params) printf(";<%s>", vb2.params); |
|
467 |
- if (vb2.comment) printf(" <%s>", vb2.comment); |
|
468 |
- printf ("\n"); |
|
468 |
+ if (vb2.params) DBG(";<%s>", vb2.params); |
|
469 |
+ if (vb2.comment) DBG(" <%s>", vb2.comment); |
|
470 |
+ DBG("\n"); |
|
469 | 471 |
} |
470 | 472 |
#endif |
471 | 473 |
|
... | ... |
@@ -475,7 +477,7 @@ skip: |
475 | 477 |
memcpy(&(msg->via2), &vb2, sizeof(struct via_body)); |
476 | 478 |
|
477 | 479 |
#ifdef DEBUG |
478 |
- printf ("exiting parse_msg\n"); |
|
480 |
+ DBG("exiting parse_msg\n"); |
|
479 | 481 |
#endif |
480 | 482 |
|
481 | 483 |
return 0; |
... | ... |
@@ -20,7 +20,7 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip) |
20 | 20 |
/* make a copy of the message */ |
21 | 21 |
orig=(char*) malloc(len); |
22 | 22 |
if (orig==0){ |
23 |
- DPrint("ERROR: memory allocation failure\n"); |
|
23 |
+ LOG(L_ERR, "ERROR:receive_msg: memory allocation failure\n"); |
|
24 | 24 |
goto error1; |
25 | 25 |
} |
26 | 26 |
memcpy(orig, buf, len); |
... | ... |
@@ -44,12 +44,12 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip) |
44 | 44 |
); |
45 | 45 |
if (re==0){ |
46 | 46 |
/* no route found, send back error msg? */ |
47 |
- DPrint("WARNING: no route found!\n"); |
|
47 |
+ LOG(L_WARN, "WARNING: receive_msg: no route found!\n"); |
|
48 | 48 |
goto skip; |
49 | 49 |
} |
50 | 50 |
re->tx++; |
51 | 51 |
/* send msg */ |
52 |
- DPrint(" found route to: %s\n", re->host.h_name); |
|
52 |
+ DBG(" found route to: %s\n", re->host.h_name); |
|
53 | 53 |
forward_request(orig, buf, len, &msg, re, src_ip); |
54 | 54 |
}else if (msg.first_line.type==SIP_REPLY){ |
55 | 55 |
/* sanity checks */ |
... | ... |
@@ -65,7 +65,7 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip) |
65 | 65 |
|
66 | 66 |
/* send the msg */ |
67 | 67 |
if (forward_reply(orig, buf, len, &msg)==0){ |
68 |
- DPrint(" reply forwarded to %s:%d\n", |
|
68 |
+ DBG(" reply forwarded to %s:%d\n", |
|
69 | 69 |
msg.via2.host, |
70 | 70 |
(unsigned short) msg.via2.port); |
71 | 71 |
} |
... | ... |
@@ -95,12 +95,12 @@ int add_rule(struct cfg_line* cl, struct route_elem** head) |
95 | 95 |
if (re==0) return E_OUT_OF_MEM; |
96 | 96 |
|
97 | 97 |
if (regcomp(&(re->method), cl->method, REG_EXTENDED|REG_NOSUB|REG_ICASE)){ |
98 |
- DPrint("ERROR: bad re \"%s\"\n", cl->method); |
|
98 |
+ LOG(L_CRIT, "ERROR: add_rule: bad re \"%s\"\n", cl->method); |
|
99 | 99 |
ret=E_BAD_RE; |
100 | 100 |
goto error; |
101 | 101 |
} |
102 | 102 |
if (regcomp(&(re->uri), cl->uri, REG_EXTENDED|REG_NOSUB|REG_ICASE) ){ |
103 |
- DPrint("ERROR: bad re \"%s\"\n", cl->uri); |
|
103 |
+ LOG(L_CRIT, "ERROR: add_rule: bad re \"%s\"\n", cl->uri); |
|
104 | 104 |
ret=E_BAD_RE; |
105 | 105 |
goto error; |
106 | 106 |
} |
... | ... |
@@ -108,7 +108,7 @@ int add_rule(struct cfg_line* cl, struct route_elem** head) |
108 | 108 |
|
109 | 109 |
he=gethostbyname(cl->address); |
110 | 110 |
if (he==0){ |
111 |
- DPrint("ERROR: cannot resolve \"%s\"\n", cl->address); |
|
111 |
+ LOG(L_CRIT, "ERROR: add_rule: cannot resolve \"%s\"\n", cl->address); |
|
112 | 112 |
ret=E_BAD_ADDRESS; |
113 | 113 |
goto error; |
114 | 114 |
} |
... | ... |
@@ -181,7 +181,7 @@ struct route_elem* route_match(char* method, char* uri, struct route_elem** rl) |
181 | 181 |
{ |
182 | 182 |
struct route_elem* t; |
183 | 183 |
if (*rl==0){ |
184 |
- DPrint("WARNING: empty routing table\n"); |
|
184 |
+ LOG(L_ERR, "WARNING: route_match: empty routing table\n"); |
|
185 | 185 |
return 0; |
186 | 186 |
} |
187 | 187 |
for (t=*rl; t; t=t->next){ |
... | ... |
@@ -206,25 +206,25 @@ void print_rl() |
206 | 206 |
int i,j; |
207 | 207 |
|
208 | 208 |
if (rlist==0){ |
209 |
- DPrint("the routing table is empty\n"); |
|
209 |
+ LOG(L_INFO, "the routing table is empty\n"); |
|
210 | 210 |
return; |
211 | 211 |
} |
212 | 212 |
|
213 | 213 |
for (t=rlist,i=0; t; i++, t=t->next){ |
214 |
- DPrint("%2d.to=%s ; route ok=%d\n", i, |
|
214 |
+ LOG(L_INFO, "%2d.to=%s ; route ok=%d\n", i, |
|
215 | 215 |
t->host.h_name, t->ok); |
216 |
- DPrint(" ips: "); |
|
216 |
+ LOG(L_INFO, " ips: "); |
|
217 | 217 |
for (j=0; t->host.h_addr_list[j]; j++){ |
218 |
- DPrint("%d.%d.%d.%d ", |
|
218 |
+ LOG(L_INFO, "%d.%d.%d.%d ", |
|
219 | 219 |
(unsigned char) t->host.h_addr_list[j][0], |
220 | 220 |
(unsigned char) t->host.h_addr_list[j][1], |
221 | 221 |
(unsigned char) t->host.h_addr_list[j][2], |
222 | 222 |
(unsigned char) t->host.h_addr_list[j][3] |
223 | 223 |
); |
224 | 224 |
} |
225 |
- DPrint("\n"); |
|
226 |
- DPrint(" port:%d\n", (unsigned short)t->port); |
|
227 |
- DPrint(" Statistics: tx=%d, errors=%d, tx_bytes=%d, idx=%d\n", |
|
225 |
+ LOG(L_INFO, "\n"); |
|
226 |
+ LOG(L_INFO, " port:%d\n", (unsigned short)t->port); |
|
227 |
+ LOG(L_INFO, " Statistics: tx=%d, errors=%d, tx_bytes=%d, idx=%d\n", |
|
228 | 228 |
t->tx, t->errors, t->tx_bytes, t->current_addr_idx); |
229 | 229 |
} |
230 | 230 |
|
... | ... |
@@ -24,7 +24,7 @@ int udp_init(unsigned long ip, unsigned short port) |
24 | 24 |
|
25 | 25 |
addr=(struct sockaddr_in*)malloc(sizeof(struct sockaddr)); |
26 | 26 |
if (addr==0){ |
27 |
- DPrint("ERROR: udp_init: out of memory\n"); |
|
27 |
+ LOG(L_ERR, "ERROR: udp_init: out of memory\n"); |
|
28 | 28 |
goto error; |
29 | 29 |
} |
30 | 30 |
addr->sin_family=AF_INET; |
... | ... |
@@ -33,7 +33,7 @@ int udp_init(unsigned long ip, unsigned short port) |
33 | 33 |
|
34 | 34 |
udp_sock = socket(PF_INET, SOCK_DGRAM, 0); |
35 | 35 |
if (udp_sock==-1){ |
36 |
- DPrint("ERROR: udp_init: socket: %s\n", strerror()); |
|
36 |
+ LOG(L_ERR, "ERROR: udp_init: socket: %s\n", strerror()); |
|
37 | 37 |
goto error; |
38 | 38 |
} |
39 | 39 |
/* set sock opts? */ |
... | ... |
@@ -41,12 +41,12 @@ int udp_init(unsigned long ip, unsigned short port) |
41 | 41 |
if (setsockopt(udp_sock, SOL_SOCKET, SO_REUSEADDR, |
42 | 42 |
(void*)&optval, sizeof(optval)) ==-1) |
43 | 43 |
{ |
44 |
- DPrint("ERROR: udp_init: setsockopt: %s\n", strerror()); |
|
44 |
+ LOG(L_ERR, "ERROR: udp_init: setsockopt: %s\n", strerror()); |
|
45 | 45 |
goto error; |
46 | 46 |
} |
47 | 47 |
|
48 | 48 |
if (bind(udp_sock, (struct sockaddr*) addr, sizeof(struct sockaddr))==-1){ |
49 |
- DPrint("ERROR: udp_init: bind: %s\n", strerror()); |
|
49 |
+ LOG(L_ERR, "ERROR: udp_init: bind: %s\n", strerror()); |
|
50 | 50 |
goto error; |
51 | 51 |
} |
52 | 52 |
|
... | ... |
@@ -69,7 +69,7 @@ int udp_rcv_loop() |
69 | 69 |
|
70 | 70 |
from=(struct sockaddr*) malloc(sizeof(struct sockaddr)); |
71 | 71 |
if (from==0){ |
72 |
- DPrint("ERROR: udp_rcv_loop: out of memory\n"); |
|
72 |
+ LOG(L_ERR, "ERROR: udp_rcv_loop: out of memory\n"); |
|
73 | 73 |
goto error; |
74 | 74 |
} |
75 | 75 |
|
... | ... |
@@ -77,7 +77,7 @@ int udp_rcv_loop() |
77 | 77 |
fromlen=sizeof(struct sockaddr); |
78 | 78 |
len=recvfrom(udp_sock, buf, BUF_SIZE, 0, from, &fromlen); |
79 | 79 |
if (len==-1){ |
80 |
- DPrint("ERROR: udp_rcv_loop:recvfrom: %s\n", strerror()); |
|
80 |
+ LOG(L_ERR, "ERROR: udp_rcv_loop:recvfrom: %s\n", strerror()); |
|
81 | 81 |
if (errno==EINTR) goto skip; |
82 | 82 |
else goto error; |
83 | 83 |
} |
... | ... |
@@ -108,7 +108,7 @@ int udp_send(char *buf, int len, struct sockaddr* to, int tolen) |
108 | 108 |
again: |
109 | 109 |
n=sendto(udp_sock, buf, len, 0, to, tolen); |
110 | 110 |
if (n==-1){ |
111 |
- DPrint("ERROR: udp_send: sendto: %s\n", strerror()); |
|
111 |
+ LOG(L_ERR, "ERROR: udp_send: sendto: %s\n", strerror()); |
|
112 | 112 |
if (errno==EINTR) goto again; |
113 | 113 |
} |
114 | 114 |
return n; |