Mercurial > dnsbl
comparison src/dnsbl.cpp @ 92:505e77188317
optimize verification step, cleanup documentation
author | carl |
---|---|
date | Wed, 21 Sep 2005 08:00:08 -0700 |
parents | 962a1f8f1d9f |
children | e107ade3b1c0 |
comparison
equal
deleted
inserted
replaced
91:ca46fafc6621 | 92:505e77188317 |
---|---|
390 if (!syslog_opened) { | 390 if (!syslog_opened) { |
391 openlog("dnsbl", LOG_PID, LOG_MAIL); | 391 openlog("dnsbl", LOG_PID, LOG_MAIL); |
392 syslog_opened = true; | 392 syslog_opened = true; |
393 } | 393 } |
394 syslog(LOG_NOTICE, "%s", text); | 394 syslog(LOG_NOTICE, "%s", text); |
395 // closelog(); | |
396 // syslog_opened = false; | |
397 pthread_mutex_unlock(&syslog_mutex); | 395 pthread_mutex_unlock(&syslog_mutex); |
398 } | 396 } |
399 else { | 397 else { |
400 printf("%s \n", text); | 398 printf("%s \n", text); |
401 } | 399 } |
432 break; | 430 break; |
433 } | 431 } |
434 } | 432 } |
435 else { | 433 else { |
436 // peer closed the socket | 434 // peer closed the socket |
437 //my_syslog("!!child worker process, peer closed socket while reading question"); | 435 #ifdef RESOLVER_DEBUG |
436 my_syslog("process_resolver_requests() peer closed socket while reading question"); | |
437 #endif | |
438 shutdown(socket, SHUT_RDWR); | 438 shutdown(socket, SHUT_RDWR); |
439 close(socket); | 439 close(socket); |
440 return; | 440 return; |
441 } | 441 } |
442 } | 442 } |
443 question[rs-1] = '\0'; // ensure null termination | 443 question[rs-1] = '\0'; // ensure null termination |
444 | 444 |
445 // find the answer | 445 // find the answer |
446 #ifdef NS_PACKETSZ | 446 #ifdef NS_PACKETSZ |
447 //char text[1000]; | 447 #ifdef RESOLVER_DEBUG |
448 //snprintf(text, sizeof(text), "!!child worker process has a question %s", question); | 448 char text[1000]; |
449 //my_syslog(text); | 449 snprintf(text, sizeof(text), "process_resolver_requests() has a question %s", question); |
450 my_syslog(text); | |
451 #endif | |
450 glom.length = res_search(question, ns_c_in, ns_t_a, glom.answer, sizeof(glom.answer)); | 452 glom.length = res_search(question, ns_c_in, ns_t_a, glom.answer, sizeof(glom.answer)); |
451 if (glom.length < 0) glom.length = 0; // represent all errors as zero length answers | 453 if (glom.length < 0) glom.length = 0; // represent all errors as zero length answers |
452 #else | 454 #else |
453 glom.length = sizeof(glom.answer); | 455 glom.length = sizeof(glom.answer); |
454 glom.answer = 0; | 456 glom.answer = 0; |
459 #endif | 461 #endif |
460 | 462 |
461 // write the answer | 463 // write the answer |
462 char *buf = (char *)&glom; | 464 char *buf = (char *)&glom; |
463 int len = glom.length + sizeof(glom.length); | 465 int len = glom.length + sizeof(glom.length); |
464 //snprintf(text, sizeof(text), "!!child worker process writing answer length %d for total %d", glom.length, len); | 466 #ifdef RESOLVER_DEBUG |
465 //my_syslog(text); | 467 snprintf(text, sizeof(text), "process_resolver_requests() writing answer length %d for total %d", glom.length, len); |
468 my_syslog(text); | |
469 #endif | |
466 int ws = 0; | 470 int ws = 0; |
467 while (len > ws) { | 471 while (len > ws) { |
468 int ns = write(socket, buf+ws, len-ws); | 472 int ns = write(socket, buf+ws, len-ws); |
469 if (ns > 0) { | 473 if (ns > 0) { |
470 ws += ns; | 474 ws += ns; |
471 } | 475 } |
472 else { | 476 else { |
473 // peer closed the socket! | 477 // peer closed the socket! |
474 //my_syslog("!!child worker process, peer closed socket while writing answer"); | 478 #ifdef RESOLVER_DEBUG |
479 my_syslog("process_resolver_requests() peer closed socket while writing answer"); | |
480 #endif | |
475 shutdown(socket, SHUT_RDWR); | 481 shutdown(socket, SHUT_RDWR); |
476 close(socket); | 482 close(socket); |
477 return; | 483 return; |
478 } | 484 } |
479 } | 485 } |
496 priv.my_write(question, strlen(question)+1); // write the question including the null terminator | 502 priv.my_write(question, strlen(question)+1); // write the question including the null terminator |
497 glommer glom; | 503 glommer glom; |
498 char *buf = (char *)&glom; | 504 char *buf = (char *)&glom; |
499 priv.my_read(buf, sizeof(glom.length)); | 505 priv.my_read(buf, sizeof(glom.length)); |
500 buf += sizeof(glom.length); | 506 buf += sizeof(glom.length); |
501 ///char text[1000]; | 507 #ifdef RESOLVER_DEBUG |
502 ///snprintf(text, sizeof(text), "!!milter thread wrote question %s and has answer length %d", question, glom.length); | 508 char text[1000]; |
503 ///my_syslog(text); | 509 snprintf(text, sizeof(text), "dns_interface() wrote question %s and has answer length %d", question, glom.length); |
510 my_syslog(text); | |
511 #endif | |
504 if ((glom.length < 0) || (glom.length > sizeof(glom.answer))) { | 512 if ((glom.length < 0) || (glom.length > sizeof(glom.answer))) { |
505 priv.err = true; | 513 priv.err = true; |
506 return 0; // cannot process overlarge answers | 514 return 0; // cannot process overlarge answers |
507 } | 515 } |
508 priv.my_read(buf, glom.length); | 516 priv.my_read(buf, glom.length); |