diff src/post.c @ 282:baa6408d1bbc noffle

[svn] * src/database.c,src/post.c,src/protocol.h,src/protocol.c: When posting, check the article for those headers that are specified in section 5 of the IETF draft and ensure they only occur once. * src/post.c: Clean up a conditional.
author bears
date Mon, 06 Jan 2003 18:16:18 +0000
parents 7a830ce3211e
children b0ee77fa24d4
line wrap: on
line diff
--- a/src/post.c	Fri Dec 27 21:48:25 2002 +0000
+++ b/src/post.c	Mon Jan 06 18:16:18 2003 +0000
@@ -1,7 +1,7 @@
 /*
   post.c
 
-  $Id: post.c 379 2002-03-26 17:52:01Z mirkol $
+  $Id: post.c 414 2003-01-06 18:16:18Z bears $
 */
 
 #if HAVE_CONFIG_H
@@ -176,21 +176,33 @@
 {
     DynStr * s;
     Str line, field, value;
-    Bool replyToFound, pathFound, orgFound;
+    Bool dateFound, fromFound, msgIdFound, subjectFound;
+    Bool newsgroupsFound, pathFound;
+    Bool replyToFound, orgFound;
+    Bool continuation;
     time_t t;
     int sigLines;
 
     s = new_DynStr( 10000 );
     article.text = s;
 
-    replyToFound = pathFound = orgFound = FALSE;
+    /* RFC says only one of these headers. */
+    dateFound = fromFound = msgIdFound = subjectFound =
+	newsgroupsFound = pathFound = FALSE;
+
+    /* Stuff we might want to add. */
+    replyToFound = orgFound = FALSE;
 
     field[ 0 ] = '\0';
 
-    /* Grab header lines first, getting overview info as we go. */
+    /*
+     * Grab header lines first, getting overview info as we go.
+     * Note that a line may be a continuation line, hence we always
+     * cat the information into the destination.
+     */
     while ( ( p = Utl_getHeaderLn( line, p ) ) != NULL
 	    && line[ 0 ] != '\0'
-	    && Prt_getField( field, value, line ) )
+	    && Prt_getField( field, value, &continuation, line ) )
     {
         if ( field [ 0 ] == '\0' )
         {
@@ -201,28 +213,61 @@
 	/* Look for headers we need to stash. */
 	if ( strcmp( field, "subject" ) == 0 )
 	{
+	    if ( !continuation && subjectFound )
+	    {
+		Log_err( "Duplicate Subject: header" );
+		return FALSE;
+	    }
 	    Utl_catStr( article.over.subject, value );
 	    DynStr_appLn( s, line );
+	    subjectFound = TRUE;
 	}
 	else if ( strcmp ( field, "from" ) == 0 )
 	{
+	    if ( !continuation && fromFound )
+	    {
+		Log_err( "Duplicate From: header" );
+		return FALSE;
+	    }
 	    Utl_catStr( article.over.from, value );
 	    DynStr_appLn( s, line );
+	    fromFound = TRUE;
 	}
 	else if ( strcmp ( field, "date" ) == 0 )
+	{
+	    if ( !continuation && dateFound )
+	    {
+		Log_err( "Duplicate Date: header" );
+		return FALSE;
+	    }	    
 	    Utl_catStr( article.over.date, value );
+	    dateFound = TRUE;
+	}
 	else if ( strcmp ( field, "references" ) == 0 )
 	{
 	    Utl_catStr( article.over.ref, value );
 	    DynStr_appLn( s, line );
 	}
 	else if ( strcmp ( field, "message-id" ) == 0 )
-	/*    Utl_catStr( article.over.msgId, value ); */
-	    Utl_cpyStr( article.over.msgId, value );
+	{
+	    if ( !continuation && msgIdFound )
+	    {
+		Log_err( "Duplicate Message-Id: header" );
+		return FALSE;
+	    }
+	    Utl_catStr( article.over.msgId, value );
+	    msgIdFound = TRUE;
+	}
 	else if ( strcmp ( field, "newsgroups" ) == 0 )
 	{
+	    if ( !continuation && newsgroupsFound )
+	    {
+		Log_err( "Duplicate Newsgroups: header" );
+		return FALSE;
+	    }
 	    article.newsgroups = new_Itl( value, " ,\n\t" );
 	    DynStr_appLn( s, line );
+	    newsgroupsFound = TRUE;
 	}
 	else if ( strcmp ( field, "control" ) == 0 )
 	{
@@ -241,6 +286,11 @@
 	}
 	else if ( strcmp ( field, "path" ) == 0 )
 	{
+	    if ( !continuation && pathFound )
+	    {
+		Log_err( "Duplicate Path: header" );
+		return FALSE;
+	    }
 	    pathFound = TRUE;
 	    DynStr_appLn( s, line );
 	}
@@ -280,7 +330,7 @@
 	    return FALSE;
 	}
     }
-    if ( article.over.subject[ 0 ] == '\0' )
+    if ( ! subjectFound )
     {
 	Log_err( "Posted message has no Subject field" );
 	return FALSE;
@@ -543,9 +593,8 @@
 	 * for example, we don't want to immediately post locally articles
 	 * destined for the moderator of a moderated group.
 	 */
-	if ( ! local && ( ! postLocal || Grp_postAllow( grp ) != 'y' ) )
-	    continue;
-	err = addToGroup( grp ) && err;
+	if ( local || ( postLocal && Grp_postAllow( grp ) == 'y' ) )
+	    err = addToGroup( grp ) && err;
     }
 
     return postExternal() && err;