Ticket #31: innxmit-post.patch

File innxmit-post.patch, 10.2 KB (added by eagle, 15 years ago)

Patch against INN 2.3.2

  • inn-2.3.2/backends/innxmit.c

     
    22**
    33**  Transmit articles to remote site.
    44**  Modified for NNTP streaming: 3Jan96 Jerry Aguirre
     5
     6**  Modified for POST article send mode by Dmitry Yasir (dima@scm.com.ua) :
     7**  18Mar2002
     8**  Added option -R, with make POST article in READER mode.
     9**  In POST send mode drop header lines :
     10**  NNTP-Posting-Date:
     11**  NNTP-Posting-Host:
     12**  Xref:
     13**  X-Server-Date:
     14**  X-Trace:
     15**  X-Complaints-To:
    516*/
    617#include "config.h"
    718#include "clibrary.h"
     
    3344# include <sys/select.h>
    3445#endif
    3546
     47#include <string.h>
     48
    3649#define OUTPUT_BUFFER_SIZE      (16 * 1024)
    3750
    3851/* Streaming extensions to NNTP.  This extension removes the lock-step
     
    7487static char modestream[] = "mode stream";
    7588static long retries = 0;
    7689static int logRejects = TRUE ;  /* syslog the 437 responses. */
    77 
     90static int PostSendMode = FALSE; /* Send article with POST directive */
    7891
    7992
    8093/*
     
    672685
    673686
    674687
    675688/*
     689**  Send a article in POST mode to the server.
     690*/
     691STATIC BOOL
     692REMsendarticle_post_mode(char *Article, char *MessageID, ARTHANDLE *art) {
     693    char        buff[NNTP_STRLEN];
     694    char *article_data_buff;
     695    char *line_buffer;    /* buffer for current line of message */
     696    const int max_line_size = 512;
     697    char *source_pointer; /* current source pointer */
     698    char *dest_pointer; /* current dest pointer */
     699    int counter; /* number bytes thet a worked */
     700    int new_message_size;
     701    int flag;
     702    int line_size_val; /* size of current string */
     703
     704    if (!REMflush())
     705        return FALSE;
     706       
     707    /* We must scan art->data buffer with lenth art->len and delete same
     708       header lines
     709    */
     710   
     711    article_data_buff = (char *) malloc(sizeof(char) * art->len);
     712   
     713    if(article_data_buff == NULL)
     714     return FALSE;
     715     
     716    line_buffer = (char *) malloc(sizeof(char) * (max_line_size + 2));
     717    if(line_buffer == NULL)
     718    {
     719     free(article_data_buff);
     720     return FALSE;
     721    }
     722     
     723    source_pointer = art->data;
     724    dest_pointer = article_data_buff;
     725    flag = 0;
     726    counter = 0;
     727    new_message_size = 0;
     728   
     729    while(counter < art->len)
     730    {
     731     line_size_val = strchr(source_pointer, '\n') - source_pointer + 1;
     732     if(line_size_val > max_line_size)
     733     {
     734      syslog(L_FATAL, "Too long line in article Header\n");
     735      free(line_buffer);
     736      free(article_data_buff);
     737      return FALSE;
     738     }
     739         
     740     memcpy(line_buffer, source_pointer, line_size_val);
     741     *(line_buffer + line_size_val) = '\0';
     742
     743     if(line_size_val <= 2)
     744     {
     745      /* Current line - is Header bode */
     746      memcpy(dest_pointer, source_pointer, (art->len - counter));
     747      new_message_size += art->len - counter;
     748      flag = 1;
     749      break;
     750     }
     751     
     752     if(strstr(line_buffer, "NNTP-Posting-Date:") != NULL)
     753     {
     754      counter += line_size_val;
     755      source_pointer += line_size_val;
     756      continue;
     757     }
     758     
     759     if(strstr(line_buffer, "NNTP-Posting-Host:") != NULL)
     760     {
     761      counter += line_size_val;
     762      source_pointer += line_size_val;
     763      continue;     
     764     }
     765     
     766     if(strstr(line_buffer, "Xref:") != NULL)
     767     {
     768      counter += line_size_val;
     769      source_pointer += line_size_val;
     770      continue;     
     771     }
     772     
     773     if(strstr(line_buffer, "X-Server-Date:") != NULL)
     774     {
     775      counter += line_size_val;
     776      source_pointer += line_size_val;
     777      continue;     
     778     }
     779     
     780     if(strstr(line_buffer, "X-Trace:") != NULL)
     781     {
     782      counter += line_size_val;
     783      source_pointer += line_size_val;
     784      continue;     
     785     }
     786     
     787     if(strstr(line_buffer, "X-Complaints-To:") != NULL)
     788     {
     789      counter += line_size_val;
     790      source_pointer += line_size_val;
     791      continue;           
     792     }
     793     
     794     memcpy(dest_pointer, source_pointer, line_size_val);
     795     source_pointer += line_size_val;
     796     dest_pointer += line_size_val;
     797     counter += line_size_val;
     798     new_message_size += line_size_val;
     799    } /* end while */
     800   
     801    free(line_buffer);
     802   
     803    if(flag == 0)
     804    {
     805     syslog(L_FATAL, "Internal error, flag=0\n");
     806     free(article_data_buff);
     807     return FALSE;
     808    }
     809
     810    if (xwrite(ToServer, article_data_buff, new_message_size) < 0)
     811    {
     812        free(article_data_buff);
     813        return FALSE;
     814    }
     815   
     816    free(article_data_buff);
     817   
     818    if (GotInterrupt)
     819        Interrupted(Article, MessageID);
     820    if (Debug) {
     821        (void)fprintf(stderr, "> [ article %d ]\n", art->len);
     822        (void)fprintf(stderr, "> .\n");
     823    }
     824
     825    if (CanStream) return TRUE; /* streaming mode does not wait for ACK */
     826
     827    /* What did the remote site say? */
     828    if (!REMread(buff, (int)sizeof buff)) {
     829        (void)fprintf(stderr, "No reply after sending \"%s\", %s\n",
     830                Article, strerror(errno));
     831        return FALSE;
     832    }
     833    if (GotInterrupt)
     834        Interrupted(Article, MessageID);
     835    if (Debug)
     836        (void)fprintf(stderr, "< %s", buff);
     837
     838    /* Parse the reply. */
     839    switch (atoi(buff)) {
     840    default:
     841        (void)fprintf(stderr, "Unknown reply after \"%s\" -- %s",
     842                Article, buff);
     843        if (DoRequeue)
     844            Requeue(Article, MessageID);
     845        break;
     846    case NNTP_BAD_COMMAND_VAL:
     847    case NNTP_SYNTAX_VAL:
     848    case NNTP_ACCESS_VAL:
     849        /* The receiving server is likely confused...no point in continuing */
     850        syslog(L_FATAL, GOT_BADCOMMAND, REMhost, MessageID, REMclean(buff));
     851        RequeueRestAndExit(Article, MessageID);
     852        /* NOTREACHED */
     853    case NNTP_RESENDIT_VAL:
     854    case NNTP_GOODBYE_VAL:
     855#if 0
     856        syslog(L_NOTICE, GOT_RESENDIT, REMhost, MessageID, REMclean(buff));
     857#endif
     858        Requeue(Article, MessageID);
     859        break;
     860    case NNTP_TOOKIT_VAL:
     861    case NNTP_POSTEDOK_VAL:
     862        STATaccepted++;
     863        STATacceptedsize += (double)art->len;
     864        break;
     865    case NNTP_REJECTIT_VAL:
     866        if (logRejects)
     867            syslog(L_NOTICE, REJECTED, REMhost,
     868                   MessageID, Article, REMclean(buff));
     869        STATrejected++;
     870        STATrejectedsize += (double)art->len;
     871        break;
     872    }
     873
     874    /* Article sent, or we requeued it. */
     875    return TRUE;
     876} /* end REMsendarticle_post_mode() */
     877
     878
     879/*
    676880**  Get the Message-ID header from an open article.
    677881*/
  • inn-2.3.2/backends/nntpsend.in

     STATIC char *
    @@ -891,7 +1095,7 @@
     STATIC NORETURN
     Usage() {
         (void)fprintf(stderr,
    -	"Usage: innxmit [-a] [-c] [-d] [-p] [-r] [-s] [-t#] [-T#] host file\n");
    +	"Usage: innxmit [-a] [-c] [-d] [-p] [-r] [-s] [-R] [-t#] [-T#] host file\n");
         exit(1);
     }
     
    @@ -1006,7 +1210,7 @@
         (void)umask(NEWSUMASK);
     
         /* Parse JCL. */
    -    while ((i = getopt(ac, av, "lacdprst:T:vP:")) != EOF)
    +    while ((i = getopt(ac, av, "lacdprsRt:T:vP:")) != EOF)
     	switch (i) {
     	default:
     	    Usage();
    @@ -1045,6 +1249,10 @@
     	case 'v':
     	    STATprint = TRUE;
     	    break;
    +	case 'R':
    +	    PostSendMode = TRUE;
    +	    TryStream = FALSE; /* disable streaming mode */
    +	    break;
     	}
         ac -= optind;
         av += optind;
    @@ -1375,13 +1583,29 @@
     	    }
     	    continue; /* next article */
     	}
    -	(void)sprintf(buff, "ihave %s", MessageID);
    -	if (!REMwrite(buff, (int)strlen(buff), FALSE)) {
    -	    (void)fprintf(stderr, "Can't offer article, %s\n",
    +	
    +	if(PostSendMode)
    +	{
    +	 (void)sprintf(buff, "post");
    +	 if (!REMwrite(buff, (int)strlen(buff), FALSE))
    +	 {
    +	  (void)fprintf(stderr, "Can't send POST command, %s\n",
     		    strerror(errno));
    -            article_free(art);
    +           article_free(art);
    +	   RequeueRestAndExit(Article, MessageID);
    +	 }
    +	} /* end if(PostSendMode) */
    +	else
    +	{
    +	 (void)sprintf(buff, "ihave %s", MessageID);
    +	 if (!REMwrite(buff, (int)strlen(buff), FALSE)) {
    +	    (void)fprintf(stderr, "Can't offer article, %s\n",
    +		strerror(errno));
    +	    article_free(art);
     	    RequeueRestAndExit(Article, MessageID);
    -	}
    +	  }
    +	 } /* end else */
    +	 
     	STAToffered++;
     	if (Debug)
     	    (void)fprintf(stderr, "> %s\n", buff);
    @@ -1390,7 +1614,10 @@
     
     	/* Does he want it? */
     	if (!REMread(buff, (int)sizeof buff)) {
    -	    (void)fprintf(stderr, "No reply to ihave, %s\n", strerror(errno));
    +	 if(PostSendMode)
    +	  (void)fprintf(stderr, "No reply to post, %s\n", strerror(errno));
    +	 else
    +          (void)fprintf(stderr, "No reply to ihave, %s\n", strerror(errno));
                 article_free(art);
     	    RequeueRestAndExit(Article, MessageID);
     	}
    @@ -1425,6 +1652,10 @@
     	    if (!REMsendarticle(Article, MessageID, art))
     		RequeueRestAndExit(Article, MessageID);
     	    break;
    +	case NNTP_START_POST_VAL:
    +	    if(!REMsendarticle_post_mode(Article, MessageID, art))
    +		RequeueRestAndExit(Article, MessageID);
    +	    break;
     	case NNTP_HAVEIT_VAL:
     	    STATrefused++;
     	    break;
    
    -- Attached file included as plaintext by Ecartis --
    -- File: nntpsend.patch
    
     
    44##  $Revision: 1.2 $
    55##  Send news via NNTP by running several innxmit processes in the background.
    66##  Usage:
    7 ##      nntpsend [-n][-p][-r][-s size][-S][-t timeout][-T limit][host fqdn]...
     7##      nntpsend [-n][-p][-r][-R][-s size][-S][-t timeout][-T limit][host fqdn]...
    88##      -a              Always have innxmit rewrite the batchfile
    99##      -d              debug mode, run ixxmmits with debug as well
    1010##      -D              same as -d except innxmits are not debugged
    1111##      -p              Run innxmit with -p to prune batch files
    1212##      -r              innxmit, don't requeue on unexpected error code
     13##      -R              innxmit will send message in MODE READER by POST command
    1314##      -s size         limit the =n file to size bytes
    1415##      -c              disable message-ID checking in streaming mode
    1516##      -t timeout      innxmit timeout to make connection (def: 180)
     
    3839TIMELIMIT=
    3940PP_FLAG=
    4041NOLOCK=
     42RM_FLAG=
    4143
    4244##  Parse JCL.
    4345MORETODO=true
     
    5961    X-r)
    6062        R_FLAG="-r"
    6163        ;;
     64    X-R)
     65        RM_FLAG="-R"
     66        ;;
    6267    X-S)
    6368        S_FLAG="-S"
    6469        ;;
     
    219224    PP_PARAM=
    220225    TIMEOUT_PARAM=
    221226    TIMELIMIT_PARAM=
     227    RM_PARAM=
    222228    if [ -z "${FLAGS}" ]; then
    223229        MORETODO=false
    224230    else
     
    241247        X-r)
    242248            R_PARAM="-r"
    243249            ;;
     250        X-R)
     251            RM_PARAM="-R"
     252            ;;
    244253        X-S)
    245254            S_PARAM="-S"
    246255            ;;
     
    316325    else
    317326        test -n "${R_PARAM}" && INNFLAGS="${INNFLAGS} ${R_PARAM}"
    318327    fi
     328    if [ -n "${RM_FLAG}" ]; then
     329        INNFLAGS = "${INNFLAGS} ${RP_FLAG}"
     330    else
     331        test -n "${RM_PARAM}" && INNFLAGS="${INNFLAGS} ${RM_PARAM}"
     332    fi
    319333    if [ -n "${S_FLAG}" ]; then
    320334        INNFLAGS="${INNFLAGS} ${S_FLAG}"
    321335    else