Mercurial > noffle
changeset 115:3b4db42990e0 noffle
[svn] Approved: header, group check before post, all external servers.
author | bears |
---|---|
date | Sat, 24 Jun 2000 21:47:40 +0100 |
parents | af7bea7515b2 |
children | 0a12fc56db30 |
files | src/post.c src/post.h src/server.c |
diffstat | 3 files changed, 103 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/src/post.c Sat Jun 24 21:36:38 2000 +0100 +++ b/src/post.c Sat Jun 24 21:47:40 2000 +0100 @@ -1,7 +1,7 @@ /* post.c - $Id: post.c 123 2000-05-26 09:46:29Z bears $ + $Id: post.c 159 2000-06-24 20:47:40Z bears $ */ #if HAVE_CONFIG_H @@ -41,12 +41,12 @@ DynStr *text; /* Processed article text */ ItemList *newsgroups; /* Newsgroups for dispatch */ ItemList *control; /* Control message? NULL if not */ - Bool posted; /* Has it been put in the article database? */ - const char *server; /* Server for external post */ + Bool approved; /* Has Approved: header? */ + Bool posted; /* Has it been put in the article database? */ struct OverInfo over; }; -static struct Article article = { NULL, NULL, NULL, FALSE, NULL, +static struct Article article = { NULL, NULL, NULL, FALSE, FALSE, { "", "", "", "", "", 0, 0 } }; /* Add the article to a group. */ @@ -95,49 +95,51 @@ } static Bool -checkPostableNewsgroup( Bool localOnly ) +checkPostableNewsgroup( void ) { - const char *grp; + const char * grp; Bool knownGrp = FALSE; - Bool postAllowedGrp = FALSE; + Bool postAllowedGrp = TRUE; Bool local; /* - Check at least one group is known. Look for external group and - set server. + * Check all known groups are writeable, and there is + * at least one known group. */ - article.server = NULL; for( grp = Itl_first( article.newsgroups ); - grp != NULL; + postAllowedGrp && grp != NULL; grp = Itl_next( article.newsgroups ) ) { if ( Grp_exists( grp ) ) { local = Grp_local( grp ); - if ( localOnly && ! local ) - continue; knownGrp = TRUE; switch( Grp_postAllow( grp ) ) { case 'n': - if ( localOnly ) - postAllowedGrp = TRUE; + postAllowedGrp = FALSE; break; case 'y': - postAllowedGrp = TRUE; + break; + case 'm': + /* + * Can post to moderated groups if *either* + * 1. Group is local and article approved, or + * 2. Group is external + */ + postAllowedGrp = + ! local || + article.approved; break; default: - if ( localOnly ) - postAllowedGrp = TRUE; - else - /* Can't post to moderated local groups. */ - postAllowedGrp = ! local; + /* + * Unknown mode for local groups. Forward + * to server for external groups; presumably the + * server knows what to do. + */ + postAllowedGrp = ! local; break; } - if ( postAllowedGrp && ! local && article.server == NULL ) - article.server = Grp_server( grp ); - if ( postAllowedGrp && article.server != NULL ) - break; } } @@ -148,7 +150,7 @@ } else if ( ! postAllowedGrp ) { - Log_err( "No group permits posting" ); + Log_err( "A group does not permit posting" ); return FALSE; } @@ -161,14 +163,14 @@ { DynStr * s; Str line, field, value; - Bool replyToFound; + Bool replyToFound, pathFound; time_t t; s = new_DynStr( 10000 ); article.text = s; memset( &article.over, 0, sizeof( article.over ) ); - replyToFound = FALSE; + replyToFound = pathFound = FALSE; /* Grab header lines first, getting overview info as we go. */ while ( ( p = Utl_getHeaderLn( line, p ) ) != NULL @@ -210,6 +212,16 @@ replyToFound = TRUE; DynStr_appLn( s, line ); } + else if ( strcmp ( field, "approved" ) == 0 ) + { + article.approved = TRUE; + DynStr_appLn( s, line ); + } + else if ( strcmp ( field, "path" ) == 0 ) + { + pathFound = TRUE; + DynStr_appLn( s, line ); + } else if ( strcmp ( field, "x-sender" ) == 0 ) { DynStr_app( s, "X-NOFFLE-X-Sender: " ); @@ -267,6 +279,19 @@ DynStr_app( s, "Message-ID: " ); DynStr_appLn( s, article.over.msgId ); + /* Ensure Path header */ + if ( ! pathFound ) + { + Str path; + + Log_dbg( "Adding Path field to posted message." ); + DynStr_app( s, "Path: " ); + Utl_cpyStr( path, Cfg_pathHeader() ); + if ( path[ 0 ] == '\0' ) + Prt_genPathHdr( path, article.over.from ); + DynStr_appLn( s, path ); + } + /* Ensure Reply-To header */ if ( ! replyToFound ) { @@ -299,16 +324,39 @@ static Bool postExternal( void ) { - if ( article.server == NULL ) - return TRUE; + const char * grp; + Str serversSeen; + Bool err; - if ( ! Out_add( article.server, article.over.msgId, article.text ) ) + /* + * For each external group, send to that group's server if it has + * not seen the post already. + */ + serversSeen[ 0 ] = '\0'; + err = FALSE; + + for ( grp = Itl_first( article.newsgroups ); + grp != NULL; + grp = Itl_next( article.newsgroups ) ) { - Log_err( "Cannot add posted article to outgoing directory" ); - return FALSE; + if ( Grp_exists( grp ) && ! Grp_local( grp ) ) + { + const char * servName = Grp_server( grp ); + + if ( strstr( serversSeen, servName ) != NULL ) + continue; + + if ( ! Out_add( servName, article.over.msgId, article.text ) ) + { + Log_err( "Cannot add posted article to outgoing directory" ); + err = TRUE; + } + Utl_catStr( serversSeen, " " ); + Utl_catStr( serversSeen, servName ); + } } - return TRUE; + return err; } /* Cancel and return TRUE if need to send cancel message on to server. */ @@ -356,33 +404,32 @@ } static Bool -postArticle( Bool localOnly ) +postArticle( void ) { const char *grp; Bool err; + Bool local; Bool postLocal; - Bool local; + char postAllow; err = FALSE; postLocal = Cfg_postLocal(); - /* Run round & post locally */ + /* + * Run round first doing all local groups. + * Remember, we've already checked it is OK to post to them all. + */ for( grp = Itl_first( article.newsgroups ); grp != NULL; grp = Itl_next( article.newsgroups ) ) { local = Grp_local( grp ); - if ( localOnly && ! local ) + if ( ! ( postLocal || local ) ) continue; - if ( ( local || postLocal ) - && ( Grp_postAllow( grp ) == 'y' || localOnly ) ) - err = addToGroup( grp ) && err; + err = addToGroup( grp ) && err; } - if ( localOnly ) - return err; - else - return postExternal() && err; + return postExternal() && err; } /* Register an article for posting. */ @@ -400,6 +447,7 @@ if ( Db_contains( article.over.msgId ) ) { + Post_close(); Log_err( "Duplicate article %s.", article.over.msgId ); return FALSE; } @@ -409,13 +457,13 @@ /* Process the posting */ Bool -Post_post( Bool localOnly ) +Post_post( void ) { - if ( ! checkPostableNewsgroup( localOnly ) ) + if ( ! checkPostableNewsgroup() ) return FALSE; return ( article.control == NULL ) - ? ! postArticle( localOnly ) + ? ! postArticle() : ! handleControl(); } @@ -438,7 +486,8 @@ del_Itl( article.control ); article.control = NULL; } + article.approved = FALSE; article.posted = FALSE; - article.server = NULL; } +
--- a/src/post.h Sat Jun 24 21:36:38 2000 +0100 +++ b/src/post.h Sat Jun 24 21:47:40 2000 +0100 @@ -5,7 +5,7 @@ necessary, and add to the local database and/or queue for external posting as appropriate. - $Id: post.h 100 2000-05-18 12:17:23Z bears $ + $Id: post.h 159 2000-06-24 20:47:40Z bears $ */ #ifndef POST_H @@ -21,12 +21,9 @@ Bool Post_open( const char * text ); -/* - Post the article. If localOnly, article is only posted to local - groups, and is posted regardless of group posting status. - */ +/* Post the article. */ Bool -Post_post( Bool localOnly ); +Post_post( void ); /* Done with article - tidy up. */ void
--- a/src/server.c Sat Jun 24 21:36:38 2000 +0100 +++ b/src/server.c Sat Jun 24 21:47:40 2000 +0100 @@ -1,7 +1,7 @@ /* server.c - $Id: server.c 145 2000-06-13 06:38:18Z bears $ + $Id: server.c 159 2000-06-24 20:47:40Z bears $ */ #if HAVE_CONFIG_H @@ -977,7 +977,7 @@ if ( ! err && Post_open( DynStr_str( s ) ) - && Post_post( FALSE ) ) + && Post_post() ) { putStat( STAT_POST_OK, "Message posted" ); if ( Online_true() )