comparison src/client.c @ 130:d6c006a27ffe noffle

[svn] Add article fetching and fix potential lock bug
author bears
date Wed, 09 Aug 2000 22:26:28 +0100
parents 3c71e28c8eef
children 8b9366fc1361
comparison
equal deleted inserted replaced
129:6b2b93288caa 130:d6c006a27ffe
1 /* 1 /*
2 client.c 2 client.c
3 3
4 $Id: client.c 183 2000-07-25 12:14:54Z bears $ 4 $Id: client.c 191 2000-08-09 21:26:28Z bears $
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 "control.h" 24 #include "control.h"
25 #include "dynamicstring.h" 25 #include "dynamicstring.h"
26 #include "filter.h"
26 #include "group.h" 27 #include "group.h"
27 #include "itemlist.h" 28 #include "itemlist.h"
28 #include "lock.h" 29 #include "lock.h"
29 #include "log.h" 30 #include "log.h"
30 #include "over.h" 31 #include "over.h"
546 return FALSE; 547 return FALSE;
547 stat = getStat(); 548 stat = getStat();
548 if ( pattern[ 0 ] != '\0' && stat != STAT_GRPS_FOLLOW ) 549 if ( pattern[ 0 ] != '\0' && stat != STAT_GRPS_FOLLOW )
549 { 550 {
550 *noServerPattern = TRUE; 551 *noServerPattern = TRUE;
551 if ( ! putCmd( "LIST ACTIVE" ) ) 552 if ( ! putCmd( "LIST" ) )
552 return FALSE; 553 return FALSE;
553 stat = getStat(); 554 stat = getStat();
554 } 555 }
555 if ( stat != STAT_GRPS_FOLLOW ) 556 if ( stat != STAT_GRPS_FOLLOW )
556 { 557 {
893 894
894 Bool 895 Bool
895 Client_getOver( const char *grp, int rmtFirst, int rmtLast, FetchMode mode ) 896 Client_getOver( const char *grp, int rmtFirst, int rmtLast, FetchMode mode )
896 { 897 {
897 size_t nbytes, nlines; 898 size_t nbytes, nlines;
898 int rmtNumb, oldLast, cntMarked; 899 int rmtNumb, groupsNumb, oldLast, cntMarked;
899 Over *ov; 900 Over *ov;
900 Str line, subj, from, date, msgId, ref; 901 Str line, subj, from, date, msgId, ref, groups;
901 DynStr *response; 902 DynStr *response, *newsgroups;
902 const char *lines; 903 const char *lines, *groupLines;
904 char *p;
905 FilterAction action;
903 906
904 ASSERT( ! Lock_gotLock() ); 907 ASSERT( ! Lock_gotLock() );
905 ASSERT( strcmp( grp, "" ) != 0 ); 908 ASSERT( strcmp( grp, "" ) != 0 );
909
910 /* Do we need the article Newsgroups: for filtering? */
911 if ( Flt_getNewsgroups() )
912 {
913 if ( ! putCmd( "XHDR Newsgroups %lu-%lu", rmtFirst, rmtLast ) )
914 return FALSE;
915 if ( getStat() != STAT_HEAD_FOLLOWS )
916 {
917 Log_err( "XHDR command failed: %s", client.lastStat );
918 return FALSE;
919 }
920
921 Log_dbg( "Requesting Newsgroups headers for remote %lu-%lu",
922 rmtFirst, rmtLast );
923
924 newsgroups = collectTxt();
925 groupLines = DynStr_str( newsgroups );
926 }
927 else
928 {
929 groupLines = NULL;
930 newsgroups = NULL;
931 }
932
906 if ( ! putCmd( "XOVER %lu-%lu", rmtFirst, rmtLast ) ) 933 if ( ! putCmd( "XOVER %lu-%lu", rmtFirst, rmtLast ) )
907 return FALSE; 934 {
935 del_DynStr( newsgroups );
936 return FALSE;
937 }
938
908 if ( getStat() != STAT_OVERS_FOLLOW ) 939 if ( getStat() != STAT_OVERS_FOLLOW )
909 { 940 {
941 del_DynStr( newsgroups );
910 Log_err( "XOVER command failed: %s", client.lastStat ); 942 Log_err( "XOVER command failed: %s", client.lastStat );
911 return FALSE; 943 return FALSE;
912 } 944 }
913 Log_dbg( "Requesting overview for remote %lu-%lu", rmtFirst, rmtLast ); 945 Log_dbg( "Requesting overview for remote %lu-%lu", rmtFirst, rmtLast );
914 946
915 response = collectTxt(); 947 response = collectTxt();
916 if ( response == NULL ) 948 if ( response == NULL )
949 {
950 del_DynStr( newsgroups );
917 return FALSE; 951 return FALSE;
952 }
918 953
919 if ( ! Lock_openDatabases() ) 954 if ( ! Lock_openDatabases() )
955 {
956 del_DynStr( newsgroups );
957 del_DynStr( response );
920 return FALSE; 958 return FALSE;
959 }
960
921 Cont_read( grp ); 961 Cont_read( grp );
922 oldLast = Cont_last(); 962 oldLast = Cont_last();
923 cntMarked = 0; 963 cntMarked = 0;
924 lines = DynStr_str( response ); 964 lines = DynStr_str( response );
925 while ( ( lines = Utl_getLn( line, lines) ) != NULL ) 965 while ( ( lines = Utl_getLn( line, lines ) ) != NULL )
926 { 966 {
927 if ( ! parseOvLn( line, &rmtNumb, subj, from, date, msgId, ref, 967 if ( ! parseOvLn( line, &rmtNumb, subj, from, date, msgId, ref,
928 &nbytes, &nlines ) ) 968 &nbytes, &nlines ) )
929 Log_err( "Bad overview line: %s", line ); 969 Log_err( "Bad overview line: %s", line );
930 else if ( Cont_find( msgId ) >= 0 ) 970 else if ( Cont_find( msgId ) >= 0 )
931 Log_inf( "Already have '%s'", msgId ); 971 Log_inf( "Already have '%s'", msgId );
932 else 972 else
933 { 973 {
934 ov = new_Over( subj, from, date, msgId, ref, nbytes, nlines ); 974 ov = new_Over( subj, from, date, msgId, ref, nbytes, nlines );
975 groupsNumb = 0;
976 p = NULL;
977 if ( groupLines != NULL )
978 {
979 do
980 {
981 groupLines = Utl_getLn( groups, groupLines );
982 groupsNumb = strtoul( groups, &p, 10 );
983 } while ( groupLines != NULL
984 && p > groups
985 && groupsNumb < rmtNumb );
986 if ( groupsNumb != rmtNumb )
987 p = NULL;
988 }
989
990 action = Flt_checkFilters( grp, p, ov, mode );
991 if ( action == FILTER_DISCARD )
992 continue;
935 Cont_app( ov ); 993 Cont_app( ov );
936 prepareEntry( ov ); 994 prepareEntry( ov );
937 if ( mode == FULL || ( mode == THREAD && needsMark( ref ) ) ) 995 if ( action == FILTER_FULL
996 || ( action == FILTER_THREAD && needsMark( ref ) ) )
938 { 997 {
939 Req_add( client.serv, msgId ); 998 Req_add( client.serv, msgId );
940 ++cntMarked; 999 ++cntMarked;
941 } 1000 }
942 } 1001 }
947 Log_inf( "%u articles marked for download in %s", cntMarked, client.grp ); 1006 Log_inf( "%u articles marked for download in %s", cntMarked, client.grp );
948 Cont_write(); 1007 Cont_write();
949 Grp_setFirstLast( grp, Cont_first(), Cont_last() ); 1008 Grp_setFirstLast( grp, Cont_first(), Cont_last() );
950 Lock_closeDatabases(); 1009 Lock_closeDatabases();
951 del_DynStr( response ); 1010 del_DynStr( response );
1011 del_DynStr( newsgroups );
952 return TRUE; 1012 return TRUE;
953 } 1013 }
954 1014
955 static void 1015 static void
956 retrievingFailed( const char* msgId, const char *reason ) 1016 retrievingFailed( const char* msgId, const char *reason )
1085 Bool 1145 Bool
1086 Client_changeToGrp( const char* name ) 1146 Client_changeToGrp( const char* name )
1087 { 1147 {
1088 unsigned int stat; 1148 unsigned int stat;
1089 int estimatedNumb, first, last; 1149 int estimatedNumb, first, last;
1150 Bool res;
1090 1151
1091 ASSERT( Lock_gotLock() ); 1152 ASSERT( Lock_gotLock() );
1092 if ( ! Grp_exists( name ) ) 1153 if ( ! Grp_exists( name ) )
1093 return FALSE; 1154 return FALSE;
1094 if ( ! putCmd( "GROUP %s", name ) ) 1155 Lock_closeDatabases();
1095 return FALSE; 1156 res = putCmd( "GROUP %s", name );
1096 if ( getStat() != STAT_GRP_SELECTED ) 1157 res = res && ( getStat() == STAT_GRP_SELECTED );
1158 if ( ! Lock_openDatabases() || ! res )
1097 return FALSE; 1159 return FALSE;
1098 if ( sscanf( client.lastStat, "%u %d %d %d", 1160 if ( sscanf( client.lastStat, "%u %d %d %d",
1099 &stat, &estimatedNumb, &first, &last ) != 4 ) 1161 &stat, &estimatedNumb, &first, &last ) != 4 )
1100 { 1162 {
1101 Log_err( "Bad server response to GROUP: %s", client.lastStat ); 1163 Log_err( "Bad server response to GROUP: %s", client.lastStat );