Ticket #31: innxmit-post.patch
File innxmit-post.patch, 10.2 KB (added by , 15 years ago) |
---|
-
inn-2.3.2/backends/innxmit.c
2 2 ** 3 3 ** Transmit articles to remote site. 4 4 ** 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: 5 16 */ 6 17 #include "config.h" 7 18 #include "clibrary.h" … … 33 44 # include <sys/select.h> 34 45 #endif 35 46 47 #include <string.h> 48 36 49 #define OUTPUT_BUFFER_SIZE (16 * 1024) 37 50 38 51 /* Streaming extensions to NNTP. This extension removes the lock-step … … 74 87 static char modestream[] = "mode stream"; 75 88 static long retries = 0; 76 89 static int logRejects = TRUE ; /* syslog the 437 responses. */ 77 90 static int PostSendMode = FALSE; /* Send article with POST directive */ 78 91 79 92 80 93 /* … … 672 685 673 686 674 687 675 688 /* 689 ** Send a article in POST mode to the server. 690 */ 691 STATIC BOOL 692 REMsendarticle_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 /* 676 880 ** Get the Message-ID header from an open article. 677 881 */ -
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
4 4 ## $Revision: 1.2 $ 5 5 ## Send news via NNTP by running several innxmit processes in the background. 6 6 ## 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]... 8 8 ## -a Always have innxmit rewrite the batchfile 9 9 ## -d debug mode, run ixxmmits with debug as well 10 10 ## -D same as -d except innxmits are not debugged 11 11 ## -p Run innxmit with -p to prune batch files 12 12 ## -r innxmit, don't requeue on unexpected error code 13 ## -R innxmit will send message in MODE READER by POST command 13 14 ## -s size limit the =n file to size bytes 14 15 ## -c disable message-ID checking in streaming mode 15 16 ## -t timeout innxmit timeout to make connection (def: 180) … … 38 39 TIMELIMIT= 39 40 PP_FLAG= 40 41 NOLOCK= 42 RM_FLAG= 41 43 42 44 ## Parse JCL. 43 45 MORETODO=true … … 59 61 X-r) 60 62 R_FLAG="-r" 61 63 ;; 64 X-R) 65 RM_FLAG="-R" 66 ;; 62 67 X-S) 63 68 S_FLAG="-S" 64 69 ;; … … 219 224 PP_PARAM= 220 225 TIMEOUT_PARAM= 221 226 TIMELIMIT_PARAM= 227 RM_PARAM= 222 228 if [ -z "${FLAGS}" ]; then 223 229 MORETODO=false 224 230 else … … 241 247 X-r) 242 248 R_PARAM="-r" 243 249 ;; 250 X-R) 251 RM_PARAM="-R" 252 ;; 244 253 X-S) 245 254 S_PARAM="-S" 246 255 ;; … … 316 325 else 317 326 test -n "${R_PARAM}" && INNFLAGS="${INNFLAGS} ${R_PARAM}" 318 327 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 319 333 if [ -n "${S_FLAG}" ]; then 320 334 INNFLAGS="${INNFLAGS} ${S_FLAG}" 321 335 else