Ticket #23: innfeed-log-size.patch

File innfeed-log-size.patch, 11.9 KB (added by eagle, 14 years ago)

Patch against INN 2.4.1

  • innfeed/article.c

    #
    # Add size and post time of the article to tape (backlog file).
    #
    old new  
    5252    int refCount ;              /* the reference count on this article */
    5353    char *fname ;               /* the file name of the article */
    5454    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) */
    5557    Buffer contents ;           /* the buffer of the actual on disk stuff */
    5658    Buffer *nntpBuffers ;       /* list of buffers for transmisson */
    5759    const void *mMapping ;      /* base of memory mapping, or NULL if none */
     
    181183  /* Create a new article object. First looks to see if one with the given
    182184     message id already exists in the hash table and if so returns that
    183185     (after incrementing the reference count). */
    184 Article newArticle (const char *filename, const char *msgid)
     186Article newArticle (const char *filename,
     187                    const char *msgid,
     188                    int size,
     189                    time_t post)
    185190{
    186191  Article newArt = NULL ;
    187192 
     
    210215
    211216      newArt->fname = xstrdup (filename) ;
    212217      newArt->msgid = xstrdup (msgid) ;
    213      
     218      newArt->size = size ;
     219      newArt->post = post ;
     220
    214221      newArt->contents = NULL ;
    215222      newArt->mMapping = NULL ;
    216223      newArt->refCount = 1 ;
     
    412419int artSize (Article article)
    413420{
    414421  if (article == NULL || article->contents == NULL)
    415     return (int)0 ;
     422    return article->size ;
    416423  return (int)bufferDataSize(article->contents);
    417424}
    418425
     426  /* return article post time */
     427time_t artPostTime (Article article)
     428{
     429  return article->post ;
     430}
    419431
    420432  /* return how many NNTP-ready buffers the article contains */
    421433unsigned int artNntpBufferCount (Article article)
  • innfeed/article.h

    old new  
    2525
    2626#include "misc.h"
    2727
    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).             */
     32Article newArticle (const char *filename,
     33                    const char *msgid,
     34                    int size,
     35                    time_t post) ;
    3236
    3337  /* delete the given article. Just decrements refcount and then FREEs if the
    3438     refcount is 0. */
     
    5761     value can (must) be given to freeBufferArray */
    5862Buffer *artGetNntpBuffers (Article article) ;
    5963
    60   /* return the message id stoed in the article object */
     64  /* return the message id stored in the article object */
    6165const char *artMsgId (Article article) ;
    6266
    6367  /* return size of the article */
    6468int artSize (Article article) ;
     69
     70  /* return article post time */
     71time_t artPostTime (Article article) ;
    6572
    6673  /* return the number of buffers that artGetNntpBuffers() would return. */
    6774unsigned int artNntpBufferCount (Article article) ;
  • innfeed/innlistener.c

    old new  
    370370  InnListener lis = (InnListener) data ;
    371371  char *msgid, *msgidEnd ;
    372372  char *fileName, *fileNameEnd ;
     373  char *artSize, *artSizeEnd ;
     374  int size ;
     375  char *postTime, *postTimeEnd ;
     376  time_t post ;
    373377  char *peer, *peerEnd ;
    374378  char *cmd, *endc ;
    375379  char *bbase = bufferBase (buffs [0]) ;
     
    475479          d_printf (2,"INN Command: %s\n", cmd) ;
    476480
    477481          /* pick out the leading string (the filename) */
    478           if ((fileName = findNonBlankString (cmd,&fileNameEnd)) == NULL)
     482          fileName = findNonBlankString (cmd,&fileNameEnd) ;
     483          if (fileName == NULL)
    479484            {
    480485              warn ("ME source format bad, exiting: %s", cmd) ;
    481486              shutDown (lis) ;
     
    486491          *fileNameEnd = '\0' ; /* for the benefit of newArticle() */
    487492
    488493          /* 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)
    490496            {
    491497              *fileNameEnd = ' ' ; /* to make syslog work properly */
    492498              warn ("ME source format bad, exiting: %s", cmd) ;
     
    497503
    498504          *msgidEnd = '\0' ;    /* for the benefit of newArticle() */
    499505         
     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
    500544          /* now create an article object and give it all the peers on the
    501545             rest of the command line. Will return null if file is missing. */
    502           article = newArticle (fileName, msgid) ;
     546          article = newArticle (fileName, msgid, size, post) ;
    503547          *fileNameEnd = ' ' ;
    504548
    505549          /* Check the message ID length */
    506550          if (strlen(msgid) > NNTP_MSGID_MAXLEN) {
    507551            warn ("ME message id exceeds limit of %d octets: %s",
    508552                  NNTP_MSGID_MAXLEN, msgid) ;
    509             *(msgidEnd+1) = '\0' ;
     553            *(postTimeEnd+1) = '\0' ;
    510554          }
    511555          *msgidEnd = ' ' ;
    512556
    513557          /* Check if message ID starts with < and ends with > */
    514558          if (*msgid != '<' || *(msgidEnd-1) != '>') {
    515559            warn ("ME source format bad, exiting: %s", cmd) ;
    516             *(msgidEnd+1) = '\0';
     560            *(postTimeEnd+1) = '\0' ;
    517561          }
    518562
    519563          /* now get all the peernames off the rest of the command lines */
    520           peerEnd = msgidEnd ;
     564          peerEnd = postTimeEnd ;
    521565          do
    522566            {
    523567              *peerEnd = ' ' ;
     
    765809
    766810static void dropArticle (const char *peerName, Article article)
    767811{
     812  int size ;
     813  time_t post ;
     814
    768815  static bool logged = false ;
    769816
    770817  if (!logged)
     
    774821    }
    775822 
    776823  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) ;
    779832}
    780833
    781834
  • innfeed/tape.c

    old new  
    639639#if 0
    640640  QueueElem elem ;
    641641#endif
    642   int amt ;
     642  int amt, size, len ;
    643643  const char *fname, *msgid ;
     644  time_t post ;
     645  char buff [4096] ;
    644646
    645647  ASSERT (tape != NULL) ;
    646648
     
    653655
    654656  fname = artFileName (article) ;
    655657  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);
    657683
    658684  /* I'd rather know where I am each time, and I don't trust all
    659685    fprintf's to give me character counts. */
     
    668694
    669695#else
    670696
    671   tape->outputSize += strlen(fname) + strlen(msgid) + 2 ; /* " " + "\n" */
     697  tape->outputSize += strlen(buff) ;
    672698
    673699#endif
    674700#endif
     
    702728   are no more articles. */
    703729Article getArticle (Tape tape)
    704730{
    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 ;)                  */
    706733  char *p, *q ;
    707734  char *msgid, *filename ;
    708735  Article art = NULL ;
    709736  time_t now = theTime() ;
     737  time_t post ;
     738  int size ;
    710739
    711740  ASSERT (tape != NULL) ;
    712741
     
    740769      else
    741770        {
    742771          msgid = filename = NULL ;
     772          size = post = 0 ;
    743773         
    744774          for (p = line ; *p && CTYPE(isspace, *p) ; p++) /* eat whitespace */
    745775            /* nada */ ;
     
    763793                        *p = '\0' ;
    764794
    765795                      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                        }
    767820                      else
    768821                        filename = NULL ; /* no trailing newline or blank */
    769822                    }
     
    787840          }
    788841
    789842          if (filename != NULL && msgid != NULL)
    790             art = newArticle (filename, msgid) ;
     843            {
     844              art = newArticle (filename, msgid, size, post) ;
     845            }
    791846
    792847          /* art may be NULL here if the file is no longer valid. */
    793848        }
  • samples/newsfeeds.in

    old new  
    6666# innfeed funnel master.
    6767#innfeed!\
    6868#       :!*\
    69 #       :Tc,Wnm*:@prefix@/bin/startinnfeed
     69#       :Tc,Wnmbp*:@prefix@/bin/startinnfeed
    7070
    7171##  Only uncomment this feed if both enableoverview and useoverchan are
    7272##  set to true in inn.conf.  By default, innd will write out overview