comparison src/client.c @ 67:2e47992d7f5c noffle

[svn] Rewrote needsMark(): use itemlist.h, more debugging output.
author enz
date Sat, 13 May 2000 09:27:26 +0100
parents adf0af5152f7
children 6aa3a8eff5a9
comparison
equal deleted inserted replaced
66:40a7493238e8 67:2e47992d7f5c
1 /* 1 /*
2 client.c 2 client.c
3 3
4 $Id: client.c 67 2000-05-12 17:19:38Z enz $ 4 $Id: client.c 73 2000-05-13 08:27:26Z enz $
5 */ 5 */
6 6
7 #if HAVE_CONFIG_H 7 #if HAVE_CONFIG_H
8 #include <config.h> 8 #include <config.h>
9 #endif 9 #endif
21 #include <unistd.h> 21 #include <unistd.h>
22 #include "configfile.h" 22 #include "configfile.h"
23 #include "content.h" 23 #include "content.h"
24 #include "dynamicstring.h" 24 #include "dynamicstring.h"
25 #include "group.h" 25 #include "group.h"
26 #include "itemlist.h"
26 #include "log.h" 27 #include "log.h"
27 #include "over.h" 28 #include "over.h"
28 #include "protocol.h" 29 #include "protocol.h"
29 #include "pseudo.h" 30 #include "pseudo.h"
30 #include "request.h" 31 #include "request.h"
625 } 626 }
626 627
627 static Bool 628 static Bool
628 needsMark( const char *ref ) 629 needsMark( const char *ref )
629 { 630 {
630 Bool done = FALSE, interesting; 631 Bool interesting, result;
631 char *p; 632 const char *msgId;
632 Str msgId; 633 int status;
633 int status, len;
634 time_t lastAccess, nowTime; 634 time_t lastAccess, nowTime;
635 double threadFollowTime, limit, age; 635 double threadFollowTime, secPerDay, maxTime, timeSinceLastAccess;
636 636 ItemList *itl;
637
638 Log_dbg( "Checking references '%s' for thread mode", ref );
639 result = FALSE;
640 itl = new_Itl( ref, " \t" );
637 nowTime = time( NULL ); 641 nowTime = time( NULL );
638 threadFollowTime = (double)Cfg_threadFollowTime(); 642 threadFollowTime = (double)Cfg_threadFollowTime();
639 limit = threadFollowTime * 24. * 3600.; 643 secPerDay = 24.0 * 3600.0;
640 while ( ! done ) 644 maxTime = threadFollowTime * secPerDay;
641 { 645 Log_dbg( "Max time = %.0f", maxTime );
642 p = msgId; 646 for ( msgId = Itl_first( itl ); msgId != NULL; msgId = Itl_next( itl ) )
643 while ( *ref != '<' ) 647 {
644 if ( *(ref++) == '\0' ) 648 /*
645 return FALSE; 649 References does not have to contain only Message IDs,
646 len = 0; 650 but often it does, so we look up every item in the database.
647 while ( *ref != '>' ) 651 */
648 {
649 if ( *ref == '\0' || ++len >= MAXCHAR - 1 )
650 return FALSE;
651 *(p++) = *(ref++);
652 }
653 *(p++) = '>';
654 *p = '\0';
655 if ( Db_contains( msgId ) ) 652 if ( Db_contains( msgId ) )
656 { 653 {
657 status = Db_status( msgId ); 654 status = Db_status( msgId );
658 lastAccess = Db_lastAccess( msgId ); 655 lastAccess = Db_lastAccess( msgId );
659 interesting = ( status & DB_INTERESTING ); 656 interesting = ( status & DB_INTERESTING );
660 age = difftime( nowTime, lastAccess ); 657 timeSinceLastAccess = difftime( nowTime, lastAccess );
661 if ( interesting && age <= limit ) 658 Log_dbg( "Msg ID '%s': since last access = %.0f, interesting = %s",
662 return TRUE; 659 msgId, timeSinceLastAccess, ( interesting ? "y" : "n" ) );
663 } 660 if ( interesting && timeSinceLastAccess <= maxTime )
664 } 661 {
665 return FALSE; 662 result = TRUE;
663 break;
664 }
665 }
666 else
667 {
668 Log_dbg( "MsgID '%s': not in database." );
669 }
670 }
671 del_Itl( itl );
672 Log_dbg( "Article %s marking for download.",
673 ( result ? "needs" : "doesn't need" ) );
674 return result;
666 } 675 }
667 676
668 static void 677 static void
669 prepareEntry( Over *ov ) 678 prepareEntry( Over *ov )
670 { 679 {