changeset 481:0a5dc5f69746 noffle

[svn] * src/filter.c: Log filter matches when log category filter is selected.
author bears
date Wed, 13 Oct 2004 22:59:41 +0100
parents 5d32ceec7f25
children a04c52f87b6e
files ChangeLog src/filter.c
diffstat 2 files changed, 141 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Oct 13 22:49:53 2004 +0100
+++ b/ChangeLog	Wed Oct 13 22:59:41 2004 +0100
@@ -1,6 +1,7 @@
 Wed Oct 13 2004 Jim Hague <jim.hague@acm.org>
 
 * docs/FAQ: Improve X-NOFFLE-Status entry.
+* src/filter.c: Log filter matches when log category filter is selected.
 
 Wed Sep 29 2004 Jim Hague <jim.hague@acm.org>
 
--- a/src/filter.c	Wed Oct 13 22:49:53 2004 +0100
+++ b/src/filter.c	Wed Oct 13 22:59:41 2004 +0100
@@ -3,7 +3,7 @@
   
   Article filtering.
   
-  $Id: filter.c 517 2003-04-03 17:21:24Z bears $
+  $Id: filter.c 628 2004-10-13 21:59:41Z bears $
 */
 
 #if HAVE_CONFIG_H
@@ -79,51 +79,112 @@
     ItemList *grps;
     const char *p;
     time_t articletime;
+    Bool res;
     
     switch( r->type )
     {
     case RULE_NEWSGROUP:
 	if ( Wld_match( thisGrp, r->data.grp ) )
+	{
+	    Log_dbg( LOG_DBG_FILTER,
+		     "Newsgroup rule: %s matches current group",
+		     r->data.grp, thisGrp );
 	    return TRUE;
+	}
 	if ( newsgroups != NULL )
 	{
 	    grps = new_Itl( newsgroups, " ,\t" );
 	    for ( p = Itl_first( grps ); p != NULL; p = Itl_next( grps ) )
 		if ( Wld_match( p, r->data.grp ) )
-		     return TRUE;
+		{
+		    Log_dbg( LOG_DBG_FILTER,
+			     "Newsgroup rule: %s matched in %s",
+			     r->data.grp, newsgroups );
+		    return TRUE;
+		}	    
 	    del_Itl( grps );
 	}
 	return FALSE;
 
     case RULE_SUBJECT:
-	return ( regexec( &r->data.regex, Ov_subj( ov ), 0, NULL, 0 ) == 0 );
+	res = ( regexec( &r->data.regex, Ov_subj( ov ), 0, NULL, 0 ) == 0 );
+	if ( res )
+	    Log_dbg( LOG_DBG_FILTER,
+		     "Subject rule: %s matches",
+		     Ov_subj( ov ) );
+	return res;
 
     case RULE_REFERENCE:        /* kill thread by Msg-Id in References: */
-	return ( regexec( &r->data.regex, Ov_ref( ov ), 0, NULL, 0 ) == 0 );
+	res = ( regexec( &r->data.regex, Ov_ref( ov ), 0, NULL, 0 ) == 0 );
+	if ( res )
+	    Log_dbg( LOG_DBG_FILTER,
+		     "Reference rule: %s matches",
+		     Ov_ref( ov ) );
+	return res;
 
     case RULE_FROM:
-	return ( regexec( &r->data.regex, Ov_from( ov ), 0, NULL, 0 ) == 0 );
+	res = ( regexec( &r->data.regex, Ov_from( ov ), 0, NULL, 0 ) == 0 );
+	if ( res )
+	    Log_dbg( LOG_DBG_FILTER,
+		     "From rule: %s matches",
+		     Ov_from( ov ) );
+	return res;
 
     case RULE_BYTES_LT:
-	return ( Ov_bytes( ov ) < r->data.amount );
+	res = ( Ov_bytes( ov ) < r->data.amount );
+	if ( res )
+	    Log_dbg( LOG_DBG_FILTER,
+		     "Length rule: bytes %d < %d",
+		     Ov_bytes( ov ), r->data.amount );
+	return res;
 
     case RULE_BYTES_EQ:
-	return ( Ov_bytes( ov ) == r->data.amount );
+	res = ( Ov_bytes( ov ) == r->data.amount );
+	if ( res )
+	    Log_dbg( LOG_DBG_FILTER,
+		     "Length rule: bytes %d = %d",
+		     Ov_bytes( ov ), r->data.amount );
+	return res;
 
     case RULE_BYTES_GT:
-	return ( Ov_bytes( ov ) > r->data.amount );
+	res = ( Ov_bytes( ov ) > r->data.amount );
+	if ( res )
+	    Log_dbg( LOG_DBG_FILTER,
+		     "Length rule: bytes %d > %d",
+		     Ov_bytes( ov ), r->data.amount );
+	return res;
 
     case RULE_LINES_LT:
-	return ( Ov_lines( ov ) < r->data.amount );
+	res = ( Ov_lines( ov ) < r->data.amount );
+	if ( res )
+	    Log_dbg( LOG_DBG_FILTER,
+		     "Length rule: lines %d < %d",
+		     Ov_lines( ov ), r->data.amount );
+	return res;
 
     case RULE_LINES_EQ:
-	return ( Ov_lines( ov ) == r->data.amount );
+	res = ( Ov_lines( ov ) == r->data.amount );
+	if ( res )
+	    Log_dbg( LOG_DBG_FILTER,
+		     "Length rule: lines %d = %d",
+		     Ov_lines( ov ), r->data.amount );
+	return res;
 
     case RULE_LINES_GT:
-	return ( Ov_lines( ov ) > r->data.amount );
+	res = ( Ov_lines( ov ) > r->data.amount );
+	if ( res )
+	    Log_dbg( LOG_DBG_FILTER,
+		     "Length rule: lines %d > %d",
+		     Ov_lines( ov ), r->data.amount );
+	return res;
 
     case RULE_MSGID:
-	return ( regexec( &r->data.regex, Ov_msgId( ov ), 0, NULL, 0 ) == 0 );
+	res = ( regexec( &r->data.regex, Ov_msgId( ov ), 0, NULL, 0 ) == 0 );
+	if ( res )
+	    Log_dbg( LOG_DBG_FILTER,
+		     "Msg-Id rule: %s matches",
+		     Ov_msgId( ov ) );
+	return res;
 
     case RULE_DATE_LT:
         /* Utl_parseNewsDate() is quite picky. I'm not entirely happy 
@@ -131,60 +192,114 @@
 	articletime = Utl_parseNewsDate( Ov_date( ov ) );
         if ( articletime == (time_t) -1 )
             return FALSE;
-        return ( articletime < r->data.reftime.calctime );
+        res = ( articletime < r->data.reftime.calctime );
+	if ( res )
+	    Log_dbg( LOG_DBG_FILTER,
+		     "Date before rule: %s matches",
+		     Ov_date( ov ) );
+	return res;
 
     case RULE_DATE_EQ:
 	articletime = Utl_parseNewsDate( Ov_date( ov ) );
         if ( ( articletime == (time_t) -1) 
             && ( r->data.reftime.vartime == INVALID ))
-                return TRUE;
+	{
+	    Log_dbg( LOG_DBG_FILTER,
+		     "Date equals rule: invalid date matches" );
+	    return TRUE;
+	}
         if ( ( articletime == (time_t) -1) 
             != ( r->data.reftime.vartime == INVALID ))
                 return FALSE;
-        return ( ( articletime <= r->data.reftime.calctime 
-                                    + RULE_DATE_EQ_PRECISION )
-              && ( articletime >= r->data.reftime.calctime 
-                                    - RULE_DATE_EQ_PRECISION )  );
+        res =  ( ( articletime <= r->data.reftime.calctime 
+		   + RULE_DATE_EQ_PRECISION )
+		 && ( articletime >= r->data.reftime.calctime 
+		      - RULE_DATE_EQ_PRECISION ) );
+	if ( res )
+	    Log_dbg( LOG_DBG_FILTER,
+		     "Date equals rule: %s matches",
+		     Ov_date( ov ) );
+	return res;
 
     case RULE_DATE_GT:
 	articletime = Utl_parseNewsDate( Ov_date( ov ) );
         if ( articletime == (time_t) -1 )
             return FALSE;
-	return ( articletime > r->data.reftime.calctime );
+	res = ( articletime > r->data.reftime.calctime );
+	if ( res )
+	    Log_dbg( LOG_DBG_FILTER,
+		     "Date after rule: %s matches",
+		     Ov_date( ov ) );
+	return res;
 
     case RULE_NOREFS_LT:
 	ul = countRefs( Ov_ref( ov ) );
-	return ( ul < r->data.amount );
+	res = ( ul < r->data.amount );
+	if ( res )
+	    Log_dbg( LOG_DBG_FILTER,
+		     "Number of references rule: %d < %d",
+		     ul, r->data.amount );
+	return res;
 
     case RULE_NOREFS_EQ:
 	ul = countRefs( Ov_ref( ov ) );
-	return ( ul == r->data.amount );
+	res = ( ul == r->data.amount );
+	if ( res )
+	    Log_dbg( LOG_DBG_FILTER,
+		     "Number of references rule: %d = %d",
+		     ul, r->data.amount );
+	return res;
 
     case RULE_NOREFS_GT:
 	ul = countRefs( Ov_ref( ov ) );
-	return ( ul > r->data.amount );
+	res = ( ul > r->data.amount );
+	if ( res )
+	    Log_dbg( LOG_DBG_FILTER,
+		     "Number of references rule: %d > %d",
+		     ul, r->data.amount );
+	return res;
 
     case RULE_XPOSTS_LT:
 	if ( newsgroups == NULL )
 	    return FALSE;
 	ul = countGroups( newsgroups );
-	return ( ul < r->data.amount );
+	res = ( ul < r->data.amount );
+	if ( res )
+	    Log_dbg( LOG_DBG_FILTER,
+		     "Number of cross-posts rule: %d < %d",
+		     ul, r->data.amount );
+	return res;
 
     case RULE_XPOSTS_EQ:
 	if ( newsgroups == NULL )
 	    return FALSE;
 	ul = countGroups( newsgroups );
-	return ( ul == r->data.amount );
+	res = ( ul == r->data.amount );
+	if ( res )
+	    Log_dbg( LOG_DBG_FILTER,
+		     "Number of cross-posts rule: %d = %d",
+		     ul, r->data.amount );
+	return res;
 
     case RULE_XPOSTS_GT:
 	if ( newsgroups == NULL )
 	    return FALSE;
 	ul = countGroups( newsgroups );
-	return ( ul > r->data.amount );
+	res = ( ul > r->data.amount );
+	if ( res )
+	    Log_dbg( LOG_DBG_FILTER,
+		     "Number of cross-posts rule: %d > %d",
+		     ul, r->data.amount );
+	return res;
 
     case RULE_POST_STATUS:
 	if ( Grp_postAllow( thisGrp ) == r->data.postAllow )
+	{
+	    Log_dbg( LOG_DBG_FILTER,
+		     "Post status rule: group status matches %c",
+		     r->data.postAllow );
 	    return TRUE;
+	}
         return FALSE;
 
     }