diff src/server.c @ 88:1fcdced0246e noffle

[svn] Move posting code to post.c, add command line posting
author bears
date Thu, 18 May 2000 13:17:23 +0100
parents dfcb28566d36
children 46062d2f9d20
line wrap: on
line diff
--- a/src/server.c	Thu May 18 13:11:05 2000 +0100
+++ b/src/server.c	Thu May 18 13:17:23 2000 +0100
@@ -1,7 +1,7 @@
 /*
   server.c
 
-  $Id: server.c 96 2000-05-17 10:51:22Z enz $
+  $Id: server.c 100 2000-05-18 12:17:23Z bears $
 */
 
 #if HAVE_CONFIG_H
@@ -31,7 +31,6 @@
 #include "common.h"
 #include "configfile.h"
 #include "content.h"
-#include "control.h"
 #include "database.h"
 #include "dynamicstring.h"
 #include "fetch.h"
@@ -41,7 +40,6 @@
 #include "lock.h"
 #include "log.h"
 #include "online.h"
-#include "outgoing.h"
 #include "over.h"
 #include "post.h"
 #include "protocol.h"
@@ -959,316 +957,35 @@
     return TRUE;
 }
 
-/* Cancel and return TRUE if need to send cancel message on to server. */
-static Bool
-controlCancel( const char *cancelId )
-{
-    return ( Ctrl_cancel( cancelId ) == CANCEL_NEEDS_MSG );
-}
-
-/*
-  It's a control message. Currently we only know about 'cancel'
-  messages; others are passed on for outside groups, and logged
-  as ignored for local groups.
- */
-static Bool
-handleControl( ItemList *control, ItemList *newsgroups,
-	       const char *msgId, const DynStr *art )
-{
-    const char *grp;
-    const char *op;
-    Bool err = FALSE;
-    Bool localDone = FALSE;
-
-    op = Itl_first( control );
-    if ( op == NULL )
-    {
-	Log_err( "Malformed control line." );
-	return TRUE;
-    }
-    else if ( strcasecmp( op, "cancel" ) == 0 )
-    {
-	if ( controlCancel( Itl_next( control ) ) )
-	    localDone = TRUE;
-	else
-	    return err;
-    }
-
-    /* Pass on for outside groups. */
-    for( grp = Itl_first( newsgroups );
-	 grp != NULL;
-	 grp = Itl_next( newsgroups ) )
-    {
-	if ( Grp_exists( grp ) && ! Grp_local( grp ) )
-	{
-	    if ( ! Out_add( Grp_server( grp ), msgId, art ) )
-	    {
-		Log_err( "Cannot add posted article to outgoing directory" );
-		err = TRUE;
-	    }
-	    break;
-	}
-    }
-
-    if ( localDone )
-	return err;
-
-    /* Log 'can't do' for internal groups. */
-    for( grp = Itl_first( newsgroups );
-	 grp != NULL;
-	 grp = Itl_next( newsgroups ) )
-    {
-	if ( Grp_exists( grp ) && Grp_local( grp ) )
-	    Log_inf( "Ignoring control '%s' for '%s'.", op, grp );
-    }
-
-    return err;
-}
-
-static Bool
-postArticle( ItemList *newsgroups, const char *msgId, const DynStr *art )
-{
-    const char *grp;
-    Bool err;
-    Bool oneLocal;
-
-    err = oneLocal = FALSE;
-
-    /* Run round first doing all local groups. */ 
-    for( grp = Itl_first( newsgroups );
-	 grp != NULL;
-	 grp = Itl_next( newsgroups ) )
-    {
-	if ( Grp_local( grp ) )
-	{
-	    if ( ! oneLocal )
-	    {
-		if ( ! Post_open( DynStr_str( art ) ) )
-		{
-		    err = TRUE;
-		    break;
-		}
-		else
-		    oneLocal = TRUE;
-	    }
-
-	    if ( ! Post_add( grp ) )
-		err = TRUE;
-	}
-    }
-    if ( oneLocal )
-	Post_close();
-
-    /* Now look for a valid external group. */
-    for( grp = Itl_first( newsgroups );
-	 grp != NULL;
-	 grp = Itl_next( newsgroups ) )
-    {
-	if ( Grp_exists( grp ) && ! Grp_local( grp ) )
-	{
-	    if ( ! Out_add( Grp_server( grp ), msgId, art ) )
-	    {
-		Log_err( "Cannot add posted article to outgoing directory" );
-		err = TRUE;
-	    }
-	    break;
-	}
-    }
-
-    return err;
-}
-
 static Bool
 doPost( char *arg, const Cmd *cmd )
 {
-    Bool err, replyToFound, dateFound, inHeader;
     DynStr *s;
-    Str line, field, val, msgId, from;
-    const char* p;
-    ItemList * newsgroups, *control;
+    Str line;
+    Bool err;
 
     UNUSED(arg);
     UNUSED(cmd);
     
-    /*
-      Get article and make following changes to the header:
-      - add/replace/cut Message-ID depending on config options
-      - add Reply-To with content of From, if missing
-      (some providers overwrite From field)
-      - rename X-Sender header to X-NOFFLE-X-Sender
-      (some providers want to insert their own X-Sender)
-
-      For doing this, it is not necessary to parse multiple-line
-      headers.
-    */
     putStat( STAT_SEND_ART, "Continue (end with period)" );
     fflush( stdout );
     Log_dbg( "[S FLUSH]" );
     s = new_DynStr( 10000 );
-    msgId[ 0 ] = '\0';
-    from[ 0 ] = '\0';
-    newsgroups = control = NULL;
-    replyToFound = dateFound = FALSE;
-    inHeader = TRUE;
-    while ( getTxtLn( line, &err ) )
-    {
-        if ( inHeader )
-        {
-            p = Utl_stripWhiteSpace( line );
-            if ( *p == '\0' )
-            {
-                inHeader = FALSE;
-                if ( from[ 0 ] == '\0' )
-                    Log_err( "Posted message has no From field" );
-                if ( Cfg_replaceMsgId() )
-                {
-                    Prt_genMsgId( msgId, from, "NOFFLE" );
-                    Log_dbg( "Replacing Message-ID with '%s'", msgId );
-                }
-                else if ( msgId[ 0 ] == '\0' )
-                {
-                    Prt_genMsgId( msgId, from, "NOFFLE" );
-                    
-                    Log_inf( "Adding missing Message-ID '%s'", msgId );
-                }
-                else if ( ! Prt_isValidMsgId( msgId ) )
-                {
-                    Log_ntc( "Replacing invalid Message-ID with '%s'",
-                             msgId );
-                    Prt_genMsgId( msgId, from, "NOFFLE" );
-                }
-                DynStr_app( s, "Message-ID: " );
-                DynStr_appLn( s, msgId );
-                if ( ! replyToFound && from[ 0 ] != '\0' )
-                {
-                    Log_dbg( "Adding Reply-To field to posted message." );
-                    DynStr_app( s, "Reply-To: " );
-                    DynStr_appLn( s, from );
-                }
-		if ( ! dateFound )
-		{
-		    time_t t;
+    err = FALSE;
+    while ( ! err && getTxtLn( line, &err ) )
+	DynStr_appLn( s, line );
 
-		    time( &t );
-		    Utl_rfc822Date( t, val );
-		    DynStr_app( s, "Date: " );
-		    DynStr_appLn( s, val );
-		}
-                DynStr_appLn( s, p );
-            }
-            else if ( Prt_getField( field, val, p ) )
-            {
-                if ( strcmp( field, "message-id" ) == 0 )
-                    strcpy( msgId, val );
-                else if ( strcmp( field, "from" ) == 0 )
-                {
-                    strcpy( from, val );
-                    DynStr_appLn( s, p );
-                }
-                else if ( strcmp( field, "newsgroups" ) == 0 )
-                {
-		    Utl_toLower( val );
-		    newsgroups = new_Itl ( val, " ," );
-                    DynStr_appLn( s, p );
-                }
-                else if ( strcmp( field, "control" ) == 0 )
-                {
-		    control = new_Itl ( val, " " );
-                    DynStr_appLn( s, p );
-                }
-                else if ( strcmp( field, "reply-to" ) == 0 )
-                {
-                    replyToFound = TRUE;
-                    DynStr_appLn( s, p );
-                }
-                else if ( strcmp( field, "date" ) == 0 )
-                {
-                    dateFound = TRUE;
-                    DynStr_appLn( s, p );
-                }
-                else if ( strcmp( field, "x-sender" ) == 0 )
-                {
-                    DynStr_app( s, "X-NOFFLE-X-Sender: " );
-                    DynStr_appLn( s, val );
-                }
-                else
-                    DynStr_appLn( s, p );
-            }
-            else
-                DynStr_appLn( s, line );
-        }
-        else
-            DynStr_appLn( s, line );
-    }
-    if ( inHeader )
-        Log_err( "Posted message has no body" );
-    if ( ! err )
-    {
-        if ( newsgroups == NULL || Itl_count( newsgroups ) == 0 )
-        {
-            Log_err( "Posted message has no valid Newsgroups header field" );
-            err = TRUE;
-        }
-        else
-	{
-	    const char *grp;
-	    Bool knownGrp = FALSE;
-	    Bool postAllowedGrp = FALSE;
-
-	    /* Check at least one group is known. */
-	    for( grp = Itl_first( newsgroups );
-		 grp != NULL;
-		 grp = Itl_next( newsgroups ) )
-	    {
-		if ( Grp_exists( grp ) )
-		{
-		    knownGrp = TRUE;
-		    switch( Grp_postAllow( grp ) )
-		    {
-		    case 'n':
-			break;
-		    case 'm':
-			/* Can't post to moderated local groups. */
-			postAllowedGrp = ! Grp_local( grp );
-			break;
-		    default:
-			postAllowedGrp = TRUE;
-		    }
-		    if ( postAllowedGrp )
-			break;
-		}
-	    }
-	    
-	    if ( ! knownGrp )
-	    {
-
-		Log_err( "No known group in Newsgroups header field" );
-		err = TRUE;
-	    }
-	    else if ( ! postAllowedGrp )
-	    {
-
-		Log_err( "No group permits posting" );
-		err = TRUE;
-	    }
-	    else
-	    {
-		err = ( control == NULL )
-		    ? postArticle( newsgroups, msgId, s )
-		    : handleControl( control, newsgroups, msgId, s );
-	    }	    
-	}
-    }
-    if ( err )
-        putStat( STAT_POST_FAILED, "Posting failed" );
-    else
+    if ( ! err
+	 && Post_open( DynStr_str( s ) )
+	 && Post_post( FALSE ) )
     {
         putStat( STAT_POST_OK, "Message posted" );
         if ( Online_true() )
             postArts();
     }
-    del_Itl( newsgroups );
-    del_Itl( control );
+    else
+        putStat( STAT_POST_FAILED, "Posting failed" );
+    Post_close();
     del_DynStr( s );
     return TRUE;
 }