Patch to innxmit (and nntpsend) for adding POST mode
Dmitry Yasir
dima at scm.com.ua
Mon Mar 18 10:29:57 UTC 2002
Hello!
I'm pathed inn-2.3.2. This patches add POST mode sending for
innxmit (new key -R in command line). This is very useful if users works
with forums with work as NEWS and organization for writing to it in
news-readers.
P.S.
If you have any questions, I'm happy to speak with you.
P.P.S.
Sorry for bad english. :-(
--
With best regards,
Dmitry Yasir (äÍÉÔÒÉÊ ñÓÙÒ)
-- Attached file included as plaintext by Ecartis --
-- File: innxmit.patch
--- inn-2.3.2/backends/innxmit.c Thu May 3 23:27:32 2001
+++ inn-2.3.2/backends/innxmit.c Mon Mar 18 11:52:21 2002
@@ -2,6 +2,17 @@
**
** Transmit articles to remote site.
** Modified for NNTP streaming: 3Jan96 Jerry Aguirre
+
+** Modified for POST article send mode by Dmitry Yasir (dima at scm.com.ua) :
+** 18Mar2002
+** Added option -R, with make POST article in READER mode.
+** In POST send mode drop header lines :
+** NNTP-Posting-Date:
+** NNTP-Posting-Host:
+** Xref:
+** X-Server-Date:
+** X-Trace:
+** X-Complaints-To:
*/
#include "config.h"
#include "clibrary.h"
@@ -33,6 +44,8 @@
# include <sys/select.h>
#endif
+#include <string.h>
+
#define OUTPUT_BUFFER_SIZE (16 * 1024)
/* Streaming extensions to NNTP. This extension removes the lock-step
@@ -74,7 +87,7 @@
static char modestream[] = "mode stream";
static long retries = 0;
static int logRejects = TRUE ; /* syslog the 437 responses. */
-
+static int PostSendMode = FALSE; /* Send article with POST directive */
/*
@@ -672,6 +685,197 @@
/*
+** Send a article in POST mode to the server.
+*/
+STATIC BOOL
+REMsendarticle_post_mode(char *Article, char *MessageID, ARTHANDLE *art) {
+ char buff[NNTP_STRLEN];
+ char *article_data_buff;
+ char *line_buffer; /* buffer for current line of message */
+ const int max_line_size = 512;
+ char *source_pointer; /* current source pointer */
+ char *dest_pointer; /* current dest pointer */
+ int counter; /* number bytes thet a worked */
+ int new_message_size;
+ int flag;
+ int line_size_val; /* size of current string */
+
+ if (!REMflush())
+ return FALSE;
+
+ /* We must scan art->data buffer with lenth art->len and delete same
+ header lines
+ */
+
+ article_data_buff = (char *) malloc(sizeof(char) * art->len);
+
+ if(article_data_buff == NULL)
+ return FALSE;
+
+ line_buffer = (char *) malloc(sizeof(char) * (max_line_size + 2));
+ if(line_buffer == NULL)
+ {
+ free(article_data_buff);
+ return FALSE;
+ }
+
+ source_pointer = art->data;
+ dest_pointer = article_data_buff;
+ flag = 0;
+ counter = 0;
+ new_message_size = 0;
+
+ while(counter < art->len)
+ {
+ line_size_val = strchr(source_pointer, '\n') - source_pointer + 1;
+ if(line_size_val > max_line_size)
+ {
+ syslog(L_FATAL, "Too long line in article Header\n");
+ free(line_buffer);
+ free(article_data_buff);
+ return FALSE;
+ }
+
+ memcpy(line_buffer, source_pointer, line_size_val);
+ *(line_buffer + line_size_val) = '\0';
+
+ if(line_size_val <= 2)
+ {
+ /* Current line - is Header bode */
+ memcpy(dest_pointer, source_pointer, (art->len - counter));
+ new_message_size += art->len - counter;
+ flag = 1;
+ break;
+ }
+
+ if(strstr(line_buffer, "NNTP-Posting-Date:") != NULL)
+ {
+ counter += line_size_val;
+ source_pointer += line_size_val;
+ continue;
+ }
+
+ if(strstr(line_buffer, "NNTP-Posting-Host:") != NULL)
+ {
+ counter += line_size_val;
+ source_pointer += line_size_val;
+ continue;
+ }
+
+ if(strstr(line_buffer, "Xref:") != NULL)
+ {
+ counter += line_size_val;
+ source_pointer += line_size_val;
+ continue;
+ }
+
+ if(strstr(line_buffer, "X-Server-Date:") != NULL)
+ {
+ counter += line_size_val;
+ source_pointer += line_size_val;
+ continue;
+ }
+
+ if(strstr(line_buffer, "X-Trace:") != NULL)
+ {
+ counter += line_size_val;
+ source_pointer += line_size_val;
+ continue;
+ }
+
+ if(strstr(line_buffer, "X-Complaints-To:") != NULL)
+ {
+ counter += line_size_val;
+ source_pointer += line_size_val;
+ continue;
+ }
+
+ memcpy(dest_pointer, source_pointer, line_size_val);
+ source_pointer += line_size_val;
+ dest_pointer += line_size_val;
+ counter += line_size_val;
+ new_message_size += line_size_val;
+ } /* end while */
+
+ free(line_buffer);
+
+ if(flag == 0)
+ {
+ syslog(L_FATAL, "Internal error, flag=0\n");
+ free(article_data_buff);
+ return FALSE;
+ }
+
+ if (xwrite(ToServer, article_data_buff, new_message_size) < 0)
+ {
+ free(article_data_buff);
+ return FALSE;
+ }
+
+ free(article_data_buff);
+
+ if (GotInterrupt)
+ Interrupted(Article, MessageID);
+ if (Debug) {
+ (void)fprintf(stderr, "> [ article %d ]\n", art->len);
+ (void)fprintf(stderr, "> .\n");
+ }
+
+ if (CanStream) return TRUE; /* streaming mode does not wait for ACK */
+
+ /* What did the remote site say? */
+ if (!REMread(buff, (int)sizeof buff)) {
+ (void)fprintf(stderr, "No reply after sending \"%s\", %s\n",
+ Article, strerror(errno));
+ return FALSE;
+ }
+ if (GotInterrupt)
+ Interrupted(Article, MessageID);
+ if (Debug)
+ (void)fprintf(stderr, "< %s", buff);
+
+ /* Parse the reply. */
+ switch (atoi(buff)) {
+ default:
+ (void)fprintf(stderr, "Unknown reply after \"%s\" -- %s",
+ Article, buff);
+ if (DoRequeue)
+ Requeue(Article, MessageID);
+ break;
+ case NNTP_BAD_COMMAND_VAL:
+ case NNTP_SYNTAX_VAL:
+ case NNTP_ACCESS_VAL:
+ /* The receiving server is likely confused...no point in continuing */
+ syslog(L_FATAL, GOT_BADCOMMAND, REMhost, MessageID, REMclean(buff));
+ RequeueRestAndExit(Article, MessageID);
+ /* NOTREACHED */
+ case NNTP_RESENDIT_VAL:
+ case NNTP_GOODBYE_VAL:
+#if 0
+ syslog(L_NOTICE, GOT_RESENDIT, REMhost, MessageID, REMclean(buff));
+#endif
+ Requeue(Article, MessageID);
+ break;
+ case NNTP_TOOKIT_VAL:
+ case NNTP_POSTEDOK_VAL:
+ STATaccepted++;
+ STATacceptedsize += (double)art->len;
+ break;
+ case NNTP_REJECTIT_VAL:
+ if (logRejects)
+ syslog(L_NOTICE, REJECTED, REMhost,
+ MessageID, Article, REMclean(buff));
+ STATrejected++;
+ STATrejectedsize += (double)art->len;
+ break;
+ }
+
+ /* Article sent, or we requeued it. */
+ return TRUE;
+} /* end REMsendarticle_post_mode() */
+
+
+/*
** Get the Message-ID header from an open article.
*/
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
--- inn-2.3.2/backends/nntpsend.in Fri Mar 15 14:59:55 2002
+++ inn-2.3.2/backends/nntpsend.in Fri Mar 15 15:25:04 2002
@@ -4,12 +4,13 @@
## $Revision: 1.2 $
## Send news via NNTP by running several innxmit processes in the background.
## Usage:
-## nntpsend [-n][-p][-r][-s size][-S][-t timeout][-T limit][host fqdn]...
+## nntpsend [-n][-p][-r][-R][-s size][-S][-t timeout][-T limit][host fqdn]...
## -a Always have innxmit rewrite the batchfile
## -d debug mode, run ixxmmits with debug as well
## -D same as -d except innxmits are not debugged
## -p Run innxmit with -p to prune batch files
## -r innxmit, don't requeue on unexpected error code
+## -R innxmit will send message in MODE READER by POST command
## -s size limit the =n file to size bytes
## -c disable message-ID checking in streaming mode
## -t timeout innxmit timeout to make connection (def: 180)
@@ -38,6 +39,7 @@
TIMELIMIT=
PP_FLAG=
NOLOCK=
+RM_FLAG=
## Parse JCL.
MORETODO=true
@@ -59,6 +61,9 @@
X-r)
R_FLAG="-r"
;;
+ X-R)
+ RM_FLAG="-R"
+ ;;
X-S)
S_FLAG="-S"
;;
@@ -219,6 +224,7 @@
PP_PARAM=
TIMEOUT_PARAM=
TIMELIMIT_PARAM=
+ RM_PARAM=
if [ -z "${FLAGS}" ]; then
MORETODO=false
else
@@ -241,6 +247,9 @@
X-r)
R_PARAM="-r"
;;
+ X-R)
+ RM_PARAM="-R"
+ ;;
X-S)
S_PARAM="-S"
;;
@@ -316,6 +325,11 @@
else
test -n "${R_PARAM}" && INNFLAGS="${INNFLAGS} ${R_PARAM}"
fi
+ if [ -n "${RM_FLAG}" ]; then
+ INNFLAGS = "${INNFLAGS} ${RP_FLAG}"
+ else
+ test -n "${RM_PARAM}" && INNFLAGS="${INNFLAGS} ${RM_PARAM}"
+ fi
if [ -n "${S_FLAG}" ]; then
INNFLAGS="${INNFLAGS} ${S_FLAG}"
else
More information about the inn-patches
mailing list