changeset 130:d6c006a27ffe noffle

[svn] Add article fetching and fix potential lock bug
author bears
date Wed, 09 Aug 2000 22:26:28 +0100
parents 6b2b93288caa
children 3598fc9581c1
files src/client.c
diffstat 1 files changed, 73 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/client.c	Wed Aug 09 22:20:12 2000 +0100
+++ b/src/client.c	Wed Aug 09 22:26:28 2000 +0100
@@ -1,7 +1,7 @@
 /*
   client.c
 
-  $Id: client.c 183 2000-07-25 12:14:54Z bears $
+  $Id: client.c 191 2000-08-09 21:26:28Z bears $
 */
 
 #if HAVE_CONFIG_H
@@ -23,6 +23,7 @@
 #include "content.h"
 #include "control.h"
 #include "dynamicstring.h"
+#include "filter.h"
 #include "group.h"
 #include "itemlist.h"
 #include "lock.h"
@@ -548,7 +549,7 @@
     if ( pattern[ 0 ] != '\0' && stat != STAT_GRPS_FOLLOW )
     {
 	*noServerPattern = TRUE;
-	if ( ! putCmd( "LIST ACTIVE" ) )
+	if ( ! putCmd( "LIST" ) )
 	    return FALSE;
 	stat = getStat();
     }    
@@ -895,18 +896,49 @@
 Client_getOver( const char *grp, int rmtFirst, int rmtLast, FetchMode mode )
 {
     size_t nbytes, nlines;
-    int rmtNumb, oldLast, cntMarked;
+    int rmtNumb, groupsNumb, oldLast, cntMarked;
     Over *ov;
-    Str line, subj, from, date, msgId, ref;
-    DynStr *response;
-    const char *lines;
+    Str line, subj, from, date, msgId, ref, groups;
+    DynStr *response, *newsgroups;
+    const char *lines, *groupLines;
+    char *p;
+    FilterAction action;
 
     ASSERT( ! Lock_gotLock() );
     ASSERT( strcmp( grp, "" ) != 0 );
+
+    /* Do we need the article Newsgroups: for filtering? */
+    if ( Flt_getNewsgroups() )
+    {
+	if ( ! putCmd( "XHDR Newsgroups %lu-%lu", rmtFirst, rmtLast ) )
+	    return FALSE;
+	if ( getStat() != STAT_HEAD_FOLLOWS )
+	{
+	    Log_err( "XHDR command failed: %s", client.lastStat );
+	    return FALSE;
+	}
+
+	Log_dbg( "Requesting Newsgroups headers for remote %lu-%lu",
+		 rmtFirst, rmtLast );
+
+	newsgroups = collectTxt();
+	groupLines = DynStr_str( newsgroups );
+    }
+    else
+    {
+	groupLines = NULL;
+	newsgroups = NULL;
+    }
+    
     if ( ! putCmd( "XOVER %lu-%lu", rmtFirst, rmtLast ) )
+    {
+	del_DynStr( newsgroups );
         return FALSE;
+    }
+    
     if ( getStat() != STAT_OVERS_FOLLOW )
     {
+	del_DynStr( newsgroups );
         Log_err( "XOVER command failed: %s", client.lastStat );
         return FALSE;
     }
@@ -914,15 +946,23 @@
 
     response = collectTxt();
     if ( response == NULL )
+    {
+	del_DynStr( newsgroups );
 	return FALSE;
+    }
 
     if ( ! Lock_openDatabases() )
+    {
+	del_DynStr( newsgroups );
+	del_DynStr( response );
 	return FALSE;
+    }
+    
     Cont_read( grp );
     oldLast = Cont_last();
     cntMarked = 0;
     lines = DynStr_str( response );
-    while ( ( lines = Utl_getLn( line, lines) ) != NULL )
+    while ( ( lines = Utl_getLn( line, lines ) ) != NULL )
     {
         if ( ! parseOvLn( line, &rmtNumb, subj, from, date, msgId, ref,
                           &nbytes, &nlines ) )
@@ -932,9 +972,28 @@
         else
         {
             ov = new_Over( subj, from, date, msgId, ref, nbytes, nlines );
+	    groupsNumb = 0;
+	    p = NULL;
+	    if ( groupLines != NULL )
+	    {
+		do
+		{
+		    groupLines = Utl_getLn( groups, groupLines );
+		    groupsNumb = strtoul( groups, &p, 10 );
+		} while ( groupLines != NULL
+			  && p > groups
+			  && groupsNumb < rmtNumb );
+		if ( groupsNumb != rmtNumb )
+		    p = NULL;
+	    }
+
+	    action = Flt_checkFilters( grp, p, ov, mode );
+	    if ( action == FILTER_DISCARD )
+		continue;
             Cont_app( ov );
             prepareEntry( ov );
-            if ( mode == FULL || ( mode == THREAD && needsMark( ref ) ) )
+            if ( action == FILTER_FULL
+		 || ( action == FILTER_THREAD && needsMark( ref ) ) )
             {
                 Req_add( client.serv, msgId );
                 ++cntMarked;
@@ -949,6 +1008,7 @@
     Grp_setFirstLast( grp, Cont_first(), Cont_last() );
     Lock_closeDatabases();
     del_DynStr( response );
+    del_DynStr( newsgroups );
     return TRUE;
 }
 
@@ -1087,13 +1147,15 @@
 {
     unsigned int stat;
     int estimatedNumb, first, last;
+    Bool res;
 
     ASSERT( Lock_gotLock() );
     if ( ! Grp_exists( name ) )
         return FALSE;
-    if ( ! putCmd( "GROUP %s", name ) )
-        return FALSE;
-    if ( getStat() != STAT_GRP_SELECTED )
+    Lock_closeDatabases();
+    res = putCmd( "GROUP %s", name );
+    res = res && ( getStat() == STAT_GRP_SELECTED );
+    if ( ! Lock_openDatabases() || ! res )
         return FALSE;
     if ( sscanf( client.lastStat, "%u %d %d %d",
                  &stat, &estimatedNumb, &first, &last ) != 4 )