Ticket #23: innfeed-log-size.patch
File innfeed-log-size.patch, 11.9 KB (added by , 14 years ago) |
---|
-
innfeed/article.c
# # Add size and post time of the article to tape (backlog file). #
old new 52 52 int refCount ; /* the reference count on this article */ 53 53 char *fname ; /* the file name of the article */ 54 54 char *msgid ; /* the msgid of the article (INN tells us) */ 55 int size ; /* the size of the article (INN tells us) */ 56 time_t post ; /* the article post time (INN tells us) */ 55 57 Buffer contents ; /* the buffer of the actual on disk stuff */ 56 58 Buffer *nntpBuffers ; /* list of buffers for transmisson */ 57 59 const void *mMapping ; /* base of memory mapping, or NULL if none */ … … 181 183 /* Create a new article object. First looks to see if one with the given 182 184 message id already exists in the hash table and if so returns that 183 185 (after incrementing the reference count). */ 184 Article newArticle (const char *filename, const char *msgid) 186 Article newArticle (const char *filename, 187 const char *msgid, 188 int size, 189 time_t post) 185 190 { 186 191 Article newArt = NULL ; 187 192 … … 210 215 211 216 newArt->fname = xstrdup (filename) ; 212 217 newArt->msgid = xstrdup (msgid) ; 213 218 newArt->size = size ; 219 newArt->post = post ; 220 214 221 newArt->contents = NULL ; 215 222 newArt->mMapping = NULL ; 216 223 newArt->refCount = 1 ; … … 412 419 int artSize (Article article) 413 420 { 414 421 if (article == NULL || article->contents == NULL) 415 return (int)0;422 return article->size ; 416 423 return (int)bufferDataSize(article->contents); 417 424 } 418 425 426 /* return article post time */ 427 time_t artPostTime (Article article) 428 { 429 return article->post ; 430 } 419 431 420 432 /* return how many NNTP-ready buffers the article contains */ 421 433 unsigned int artNntpBufferCount (Article article) -
innfeed/article.h
old new 25 25 26 26 #include "misc.h" 27 27 28 29 /* Create a new Article object. FILENAME is the path of the file the */ 30 /* article is in. MSGID is the news message id of the article */ 31 Article newArticle (const char *filename, const char *msgid) ; 28 /* Create a new Article object. FILENAME is the path of the file the */ 29 /* article is in. MSGID is the news message id of the article. SIZE is */ 30 /* the size of the article got from the INN. POST is the article post */ 31 /* time (a seconds since epoch, got from the INN). */ 32 Article newArticle (const char *filename, 33 const char *msgid, 34 int size, 35 time_t post) ; 32 36 33 37 /* delete the given article. Just decrements refcount and then FREEs if the 34 38 refcount is 0. */ … … 57 61 value can (must) be given to freeBufferArray */ 58 62 Buffer *artGetNntpBuffers (Article article) ; 59 63 60 /* return the message id sto ed in the article object */64 /* return the message id stored in the article object */ 61 65 const char *artMsgId (Article article) ; 62 66 63 67 /* return size of the article */ 64 68 int artSize (Article article) ; 69 70 /* return article post time */ 71 time_t artPostTime (Article article) ; 65 72 66 73 /* return the number of buffers that artGetNntpBuffers() would return. */ 67 74 unsigned int artNntpBufferCount (Article article) ; -
innfeed/innlistener.c
old new 370 370 InnListener lis = (InnListener) data ; 371 371 char *msgid, *msgidEnd ; 372 372 char *fileName, *fileNameEnd ; 373 char *artSize, *artSizeEnd ; 374 int size ; 375 char *postTime, *postTimeEnd ; 376 time_t post ; 373 377 char *peer, *peerEnd ; 374 378 char *cmd, *endc ; 375 379 char *bbase = bufferBase (buffs [0]) ; … … 475 479 d_printf (2,"INN Command: %s\n", cmd) ; 476 480 477 481 /* pick out the leading string (the filename) */ 478 if ((fileName = findNonBlankString (cmd,&fileNameEnd)) == NULL) 482 fileName = findNonBlankString (cmd,&fileNameEnd) ; 483 if (fileName == NULL) 479 484 { 480 485 warn ("ME source format bad, exiting: %s", cmd) ; 481 486 shutDown (lis) ; … … 486 491 *fileNameEnd = '\0' ; /* for the benefit of newArticle() */ 487 492 488 493 /* now pick out the next string (the message id) */ 489 if ((msgid = findNonBlankString (fileNameEnd + 1,&msgidEnd)) == NULL) 494 msgid = findNonBlankString (fileNameEnd + 1,&msgidEnd) ; 495 if (msgid == NULL) 490 496 { 491 497 *fileNameEnd = ' ' ; /* to make syslog work properly */ 492 498 warn ("ME source format bad, exiting: %s", cmd) ; … … 497 503 498 504 *msgidEnd = '\0' ; /* for the benefit of newArticle() */ 499 505 506 /* now pick out the next string (the message size) */ 507 artSize = findNonBlankString (msgidEnd + 1,&artSizeEnd) ; 508 if ((artSize ) == NULL) 509 { 510 *fileNameEnd = ' ' ; /* to make syslog work properly */ 511 *msgidEnd = ' ' ; 512 warn ("ME source format bad, exiting: %s", cmd) ; 513 shutDown (lis) ; 514 515 return ; 516 } 517 *artSizeEnd = '\0' ; 518 size = strtoul (artSize, &s, 10) ; 519 if (*s != '\0') 520 size = 0 ; 521 *artSizeEnd = ' ' ; 522 if (size == 0) 523 artSizeEnd = msgidEnd ; 524 525 /* now pick out the next string (the message post time) */ 526 postTime = findNonBlankString (artSizeEnd + 1,&postTimeEnd) ; 527 if (postTime == NULL) 528 { 529 *fileNameEnd = ' ' ; /* to make syslog work properly */ 530 *msgidEnd = ' ' ; 531 warn ("ME source format bad, exiting: %s", cmd) ; 532 shutDown (lis) ; 533 534 return ; 535 } 536 *postTimeEnd = '\0' ; 537 post = strtoul (postTime, &s, 10) ; 538 if (*s != '\0') 539 post = 0 ; 540 *postTimeEnd = ' ' ; 541 if (post == 0) 542 postTimeEnd = artSizeEnd ; 543 500 544 /* now create an article object and give it all the peers on the 501 545 rest of the command line. Will return null if file is missing. */ 502 article = newArticle (fileName, msgid ) ;546 article = newArticle (fileName, msgid, size, post) ; 503 547 *fileNameEnd = ' ' ; 504 548 505 549 /* Check the message ID length */ 506 550 if (strlen(msgid) > NNTP_MSGID_MAXLEN) { 507 551 warn ("ME message id exceeds limit of %d octets: %s", 508 552 NNTP_MSGID_MAXLEN, msgid) ; 509 *( msgidEnd+1) = '\0' ;553 *(postTimeEnd+1) = '\0' ; 510 554 } 511 555 *msgidEnd = ' ' ; 512 556 513 557 /* Check if message ID starts with < and ends with > */ 514 558 if (*msgid != '<' || *(msgidEnd-1) != '>') { 515 559 warn ("ME source format bad, exiting: %s", cmd) ; 516 *( msgidEnd+1) = '\0';560 *(postTimeEnd+1) = '\0' ; 517 561 } 518 562 519 563 /* now get all the peernames off the rest of the command lines */ 520 peerEnd = msgidEnd ;564 peerEnd = postTimeEnd ; 521 565 do 522 566 { 523 567 *peerEnd = ' ' ; … … 765 809 766 810 static void dropArticle (const char *peerName, Article article) 767 811 { 812 int size ; 813 time_t post ; 814 768 815 static bool logged = false ; 769 816 770 817 if (!logged) … … 774 821 } 775 822 776 823 droppedCount++ ; 777 fprintf (droppedFp,"%s %s %s\n",artFileName (article), 778 artMsgId (article), peerName) ; 824 fprintf (droppedFp,"%s %s",artFileName (article),artMsgId (article)) ; 825 if ((size = artSize (article)) != 0) 826 { 827 fprintf (droppedFp," %d", size) ; 828 if ((post = artPostTime (article)) != 0) 829 fprintf (droppedFp," %ld", (long)post) ; 830 } 831 fprintf (droppedFp," %s\n", peerName) ; 779 832 } 780 833 781 834 -
innfeed/tape.c
old new 639 639 #if 0 640 640 QueueElem elem ; 641 641 #endif 642 int amt ;642 int amt, size, len ; 643 643 const char *fname, *msgid ; 644 time_t post ; 645 char buff [4096] ; 644 646 645 647 ASSERT (tape != NULL) ; 646 648 … … 653 655 654 656 fname = artFileName (article) ; 655 657 msgid = artMsgId (article) ; 656 amt = fprintf (tape->outFp,"%s %s\n", fname, msgid) ; 658 size = artSize (article) ; 659 post = artPostTime (article) ; 660 amt = snprintf (buff, sizeof (buff), "%s %s", fname, msgid) ; 661 if (size != 0) 662 { 663 len = strlen (buff) ; 664 amt += snprintf (buff + len, sizeof (buff) - len, " %d", size) ; 665 if (post != 0) 666 { 667 len = strlen (buff) ; 668 amt += snprintf (buff+len,sizeof(buff)-len," %ld",(long)post) ; 669 } 670 } 671 len = strlen (buff) ; 672 amt += snprintf (buff + len, sizeof (buff) - len, "\n") ; 673 674 /* return immediately if buffer overflow (if happen ;) */ 675 if (amt != strlen (buff)) 676 { 677 warn ("ME buffer overflow, skip article: %s %s", fname, msgid) ; 678 delArticle (article) ; 679 return; 680 } 681 682 amt = fprintf (tape->outFp, "%s", buff); 657 683 658 684 /* I'd rather know where I am each time, and I don't trust all 659 685 fprintf's to give me character counts. */ … … 668 694 669 695 #else 670 696 671 tape->outputSize += strlen( fname) + strlen(msgid) + 2 ; /* " " + "\n" */697 tape->outputSize += strlen(buff) ; 672 698 673 699 #endif 674 700 #endif … … 702 728 are no more articles. */ 703 729 Article getArticle (Tape tape) 704 730 { 705 char line [2048] ; /* ick. 1024 for filename + 1024 for msgid */ 731 char line [4096] ; /* ick. 1024 for filename + 1024 for msgid 732 and 2048 for other ;) */ 706 733 char *p, *q ; 707 734 char *msgid, *filename ; 708 735 Article art = NULL ; 709 736 time_t now = theTime() ; 737 time_t post ; 738 int size ; 710 739 711 740 ASSERT (tape != NULL) ; 712 741 … … 740 769 else 741 770 { 742 771 msgid = filename = NULL ; 772 size = post = 0 ; 743 773 744 774 for (p = line ; *p && CTYPE(isspace, *p) ; p++) /* eat whitespace */ 745 775 /* nada */ ; … … 763 793 *p = '\0' ; 764 794 765 795 if (p != NULL) 766 msgid = q ; 796 { 797 msgid = q ; 798 for (p++ ; *p && CTYPE(isspace, *p) ; p++) ; 799 q = strpbrk (p, " \n") ; 800 if (q != NULL) 801 { 802 *q = '\0' ; 803 size = strtoul (p, &p, 10) ; 804 if (*p != '\0') 805 size = 0 ; 806 } 807 if (size != 0) 808 { 809 for (q++ ; *q && CTYPE(isspace, *q) ; q++) ; 810 p = strpbrk (q, " \n") ; 811 if (p != NULL) 812 { 813 *p = '\0' ; 814 post = strtoul (q, &q, 10) ; 815 if (*q != '\0') 816 post = 0 ; 817 } 818 } 819 } 767 820 else 768 821 filename = NULL ; /* no trailing newline or blank */ 769 822 } … … 787 840 } 788 841 789 842 if (filename != NULL && msgid != NULL) 790 art = newArticle (filename, msgid) ; 843 { 844 art = newArticle (filename, msgid, size, post) ; 845 } 791 846 792 847 /* art may be NULL here if the file is no longer valid. */ 793 848 } -
samples/newsfeeds.in
old new 66 66 # innfeed funnel master. 67 67 #innfeed!\ 68 68 # :!*\ 69 # :Tc,Wnm *:@prefix@/bin/startinnfeed69 # :Tc,Wnmbp*:@prefix@/bin/startinnfeed 70 70 71 71 ## Only uncomment this feed if both enableoverview and useoverchan are 72 72 ## set to true in inn.conf. By default, innd will write out overview