Mercurial > noffle
comparison src/client.c @ 185:fed1334d766b noffle
[svn] * src/client.c: Change variable only used on constant to 'const'.
* src/filter.c: Add a couple of 'return's after ASSERT() to remove
compiler warnings about functions needing returns.
* NEWS,TODO,configure,configure.in,noffle.conf.example,docs/NOTES,
docs/noffle.conf.5,src/client.c,src/configfile.c,src/content.c,
src/control.c,src/database.c,src/fetch.c,src/fetchlist.c,src/filter.c,
src/group.c,src/lock.c,src/log.c,src/log.h,src/noffle.c,src/outgoing.c,
src/post.c,src/protocol.c,src/request.c,src/server.c,src/util.c:
Debug logging is always compiled and selected via noffle.conf. All debug
logs are classified as all, none, config, control, expire, fetch,
filter, newsbase, noffle, post, protocol, requests and server.
| author | bears |
|---|---|
| date | Sun, 05 Aug 2001 09:24:22 +0100 |
| parents | c912e8288164 |
| children | 166008a80f03 |
comparison
equal
deleted
inserted
replaced
| 184:9854ea5f295f | 185:fed1334d766b |
|---|---|
| 1 /* | 1 /* |
| 2 client.c | 2 client.c |
| 3 | 3 |
| 4 $Id: client.c 292 2001-05-15 12:07:53Z bears $ | 4 $Id: client.c 300 2001-08-05 08:24:22Z 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 |
| 107 static void | 107 static void |
| 108 putTxtBuf( const char *buf ) | 108 putTxtBuf( const char *buf ) |
| 109 { | 109 { |
| 110 Prt_putTxtBuf( buf, client.out ); | 110 Prt_putTxtBuf( buf, client.out ); |
| 111 fflush( client.out ); | 111 fflush( client.out ); |
| 112 Log_dbg( "[S FLUSH]" ); | 112 Log_dbg( LOG_DBG_PROTOCOL, "[S FLUSH]" ); |
| 113 } | 113 } |
| 114 | 114 |
| 115 static void | 115 static void |
| 116 putEndOfTxt( void ) | 116 putEndOfTxt( void ) |
| 117 { | 117 { |
| 118 Prt_putEndOfTxt( client.out ); | 118 Prt_putEndOfTxt( client.out ); |
| 119 fflush( client.out ); | 119 fflush( client.out ); |
| 120 Log_dbg( "[S FLUSH]" ); | 120 Log_dbg( LOG_DBG_PROTOCOL, "[S FLUSH]" ); |
| 121 } | 121 } |
| 122 | 122 |
| 123 static Bool | 123 static Bool |
| 124 putCmdLn( const char *line ) | 124 putCmdLn( const char *line ) |
| 125 { | 125 { |
| 126 Bool err; | 126 Bool err; |
| 127 unsigned int n; | 127 unsigned int n; |
| 128 | 128 |
| 129 strcpy( client.lastCmd, line ); | 129 strcpy( client.lastCmd, line ); |
| 130 strcpy( client.lastStat, "[no status available]" ); | 130 strcpy( client.lastStat, "[no status available]" ); |
| 131 Log_dbg( "[S] %s", line ); | 131 Log_dbg( LOG_DBG_PROTOCOL, "[S] %s", line ); |
| 132 n = fprintf( client.out, "%s\r\n", line ); | 132 n = fprintf( client.out, "%s\r\n", line ); |
| 133 err = ( n != strlen( line ) + 2 ); | 133 err = ( n != strlen( line ) + 2 ); |
| 134 if ( err ) | 134 if ( err ) |
| 135 logBreakDown();; | 135 logBreakDown();; |
| 136 return ! err; | 136 return ! err; |
| 146 vsnprintf( line, MAXCHAR, fmt, ap ); | 146 vsnprintf( line, MAXCHAR, fmt, ap ); |
| 147 va_end( ap ); | 147 va_end( ap ); |
| 148 if ( ! putCmdLn( line ) ) | 148 if ( ! putCmdLn( line ) ) |
| 149 return FALSE; | 149 return FALSE; |
| 150 fflush( client.out ); | 150 fflush( client.out ); |
| 151 Log_dbg( "[S FLUSH]" ); | 151 Log_dbg( LOG_DBG_PROTOCOL, "[S FLUSH]" ); |
| 152 return TRUE; | 152 return TRUE; |
| 153 } | 153 } |
| 154 | 154 |
| 155 static Bool | 155 static Bool |
| 156 putCmdNoFlush( const char *fmt, ... ) | 156 putCmdNoFlush( const char *fmt, ... ) |
| 484 Grp_setRmtNext( grp, first ); | 484 Grp_setRmtNext( grp, first ); |
| 485 Grp_setPostAllow( grp, postAllow ); | 485 Grp_setPostAllow( grp, postAllow ); |
| 486 groupupdate = TRUE; | 486 groupupdate = TRUE; |
| 487 } | 487 } |
| 488 else | 488 else |
| 489 Log_dbg( "Group %s is already fetched from %s", | 489 Log_dbg( LOG_DBG_FETCH, |
| 490 "Group %s is already fetched from %s", | |
| 490 grp, Grp_server( grp ) ); | 491 grp, Grp_server( grp ) ); |
| 491 } | 492 } |
| 492 } | 493 } |
| 493 | 494 |
| 494 snprintf( file, MAXCHAR, "%s/lastupdate.%s", | 495 snprintf( file, MAXCHAR, "%s/lastupdate.%s", |
| 645 if ( *noServerPattern && ! isGetGroup( name ) ) | 646 if ( *noServerPattern && ! isGetGroup( name ) ) |
| 646 continue; | 647 continue; |
| 647 strcpy( dsc, Utl_restOfLn( line, 1 ) ); | 648 strcpy( dsc, Utl_restOfLn( line, 1 ) ); |
| 648 if ( Grp_exists( name ) ) | 649 if ( Grp_exists( name ) ) |
| 649 { | 650 { |
| 650 Log_dbg( "Description of %s: %s", name, dsc ); | 651 Log_dbg( LOG_DBG_FETCH, "Description of %s: %s", name, dsc ); |
| 651 Grp_setDsc( name, dsc ); | 652 Grp_setDsc( name, dsc ); |
| 652 } | 653 } |
| 653 } | 654 } |
| 654 Lock_closeDatabases(); | 655 Lock_closeDatabases(); |
| 655 del_DynStr( response ); | 656 del_DynStr( response ); |
| 802 { | 803 { |
| 803 Log_err( "Corrupt Xref at position '%s'", pXref ); | 804 Log_err( "Corrupt Xref at position '%s'", pXref ); |
| 804 return NULL; | 805 return NULL; |
| 805 } | 806 } |
| 806 Utl_cpyStrN( grp, s, pColon - s ); | 807 Utl_cpyStrN( grp, s, pColon - s ); |
| 807 Log_dbg( "client.c: nextXref: grp '%s' numb %lu", grp, numb ); | 808 Log_dbg( LOG_DBG_FETCH, |
| 809 "client.c: nextXref: grp '%s' numb %lu", | |
| 810 grp, numb ); | |
| 808 return src; | 811 return src; |
| 809 } | 812 } |
| 810 | 813 |
| 811 static Bool | 814 static Bool |
| 812 needsMark( const char *ref ) | 815 needsMark( const char *ref ) |
| 813 { | 816 { |
| 814 Bool interesting, result; | 817 Bool interesting, result; |
| 815 const char *msgId; | 818 const char *msgId; |
| 816 int status; | 819 int status; |
| 817 time_t lastAccess, nowTime; | 820 time_t lastAccess, nowTime; |
| 818 double threadFollowTime, secPerDay, maxTime, timeSinceLastAccess; | 821 double threadFollowTime, maxTime, timeSinceLastAccess; |
| 819 ItemList *itl; | 822 ItemList *itl; |
| 823 const double secPerDay = 24.0 * 3600.0; | |
| 820 | 824 |
| 821 ASSERT( Lock_gotLock() ); | 825 ASSERT( Lock_gotLock() ); |
| 822 Log_dbg( "Checking references '%s' for thread mode", ref ); | 826 Log_dbg( LOG_DBG_FETCH, "Checking references '%s' for thread mode", ref ); |
| 823 result = FALSE; | 827 result = FALSE; |
| 824 itl = new_Itl( ref, " \t" ); | 828 itl = new_Itl( ref, " \t" ); |
| 825 nowTime = time( NULL ); | 829 nowTime = time( NULL ); |
| 826 threadFollowTime = (double)Cfg_threadFollowTime(); | 830 threadFollowTime = (double)Cfg_threadFollowTime(); |
| 827 secPerDay = 24.0 * 3600.0; | |
| 828 maxTime = threadFollowTime * secPerDay; | 831 maxTime = threadFollowTime * secPerDay; |
| 829 Log_dbg( "Max time = %.0f", maxTime ); | 832 Log_dbg( LOG_DBG_FETCH, "Max time = %.0f", maxTime ); |
| 830 for ( msgId = Itl_first( itl ); msgId != NULL; msgId = Itl_next( itl ) ) | 833 for ( msgId = Itl_first( itl ); msgId != NULL; msgId = Itl_next( itl ) ) |
| 831 { | 834 { |
| 832 /* | 835 /* |
| 833 References does not have to contain only Message IDs, | 836 References does not have to contain only Message IDs, |
| 834 but often it does, so we look up every item in the database. | 837 but often it does, so we look up every item in the database. |
| 837 { | 840 { |
| 838 status = Db_status( msgId ); | 841 status = Db_status( msgId ); |
| 839 lastAccess = Db_lastAccess( msgId ); | 842 lastAccess = Db_lastAccess( msgId ); |
| 840 interesting = ( status & DB_INTERESTING ); | 843 interesting = ( status & DB_INTERESTING ); |
| 841 timeSinceLastAccess = difftime( nowTime, lastAccess ); | 844 timeSinceLastAccess = difftime( nowTime, lastAccess ); |
| 842 Log_dbg( "Msg ID '%s': since last access = %.0f, interesting = %s", | 845 Log_dbg( LOG_DBG_FETCH, |
| 846 "Msg ID '%s': since last access = %.0f, interesting = %s", | |
| 843 msgId, timeSinceLastAccess, ( interesting ? "y" : "n" ) ); | 847 msgId, timeSinceLastAccess, ( interesting ? "y" : "n" ) ); |
| 844 if ( interesting && timeSinceLastAccess <= maxTime ) | 848 if ( interesting && timeSinceLastAccess <= maxTime ) |
| 845 { | 849 { |
| 846 result = TRUE; | 850 result = TRUE; |
| 847 break; | 851 break; |
| 848 } | 852 } |
| 849 } | 853 } |
| 850 else | 854 else |
| 851 { | 855 { |
| 852 Log_dbg( "MsgID '%s': not in database.", msgId ); | 856 Log_dbg( LOG_DBG_FETCH, "MsgID '%s': not in database.", msgId ); |
| 853 } | 857 } |
| 854 } | 858 } |
| 855 del_Itl( itl ); | 859 del_Itl( itl ); |
| 856 Log_dbg( "Article %s marking for download.", | 860 Log_dbg( LOG_DBG_FETCH, |
| 861 "Article %s marking for download.", | |
| 857 ( result ? "needs" : "doesn't need" ) ); | 862 ( result ? "needs" : "doesn't need" ) ); |
| 858 return result; | 863 return result; |
| 859 } | 864 } |
| 860 | 865 |
| 861 static void | 866 static void |
| 866 int n; | 871 int n; |
| 867 | 872 |
| 868 ASSERT( Lock_gotLock() ); | 873 ASSERT( Lock_gotLock() ); |
| 869 msgId = Ov_msgId( ov ); | 874 msgId = Ov_msgId( ov ); |
| 870 if ( Pseudo_isGeneralInfo( msgId ) ) | 875 if ( Pseudo_isGeneralInfo( msgId ) ) |
| 871 Log_dbg( "Skipping general info '%s'", msgId ); | 876 Log_dbg( LOG_DBG_FETCH, "Skipping general info '%s'", msgId ); |
| 872 else if ( Db_contains( msgId ) ) | 877 else if ( Db_contains( msgId ) ) |
| 873 { | 878 { |
| 874 xref = Db_xref( msgId ); | 879 xref = Db_xref( msgId ); |
| 875 Log_dbg( "Entry '%s' already in db with Xref '%s'", msgId, xref ); | 880 Log_dbg( LOG_DBG_FETCH, |
| 881 "Entry '%s' already in db with Xref '%s'", | |
| 882 msgId, xref ); | |
| 876 p = nextXref( xref, g, &n ); | 883 p = nextXref( xref, g, &n ); |
| 877 if ( p == NULL ) | 884 if ( p == NULL ) |
| 878 Log_err( "Overview with no group in Xref '%s'", msgId ); | 885 Log_err( "Overview with no group in Xref '%s'", msgId ); |
| 879 else | 886 else |
| 880 { | 887 { |
| 881 /* TODO: This code block seems unnessesary. Can we remove it? */ | 888 /* TODO: This code block seems unnessesary. Can we remove it? */ |
| 882 if ( Cfg_servIsPreferential( client.serv, Grp_server( g ) ) ) | 889 if ( Cfg_servIsPreferential( client.serv, Grp_server( g ) ) ) |
| 883 { | 890 { |
| 884 Log_dbg( "Changing first server for '%s' from '%s' to '%s'", | 891 Log_dbg( LOG_DBG_FETCH, |
| 892 "Changing first server for '%s' from '%s' to '%s'", | |
| 885 msgId, Grp_server( g ), client.serv ); | 893 msgId, Grp_server( g ), client.serv ); |
| 886 snprintf( t, MAXCHAR, "%s:%d %s", | 894 snprintf( t, MAXCHAR, "%s:%d %s", |
| 887 client.grp, Ov_numb( ov ), xref ); | 895 client.grp, Ov_numb( ov ), xref ); |
| 888 Db_setXref( msgId, t ); | 896 Db_setXref( msgId, t ); |
| 889 } | 897 } |
| 890 else | 898 else |
| 891 { | 899 { |
| 892 Log_dbg( "Adding '%s' to Xref of '%s'", g, msgId ); | 900 Log_dbg( LOG_DBG_FETCH, |
| 901 "Adding '%s' to Xref of '%s'", g, msgId ); | |
| 893 snprintf( t, MAXCHAR, "%s %s:%d", | 902 snprintf( t, MAXCHAR, "%s %s:%d", |
| 894 xref, client.grp, Ov_numb( ov ) ); | 903 xref, client.grp, Ov_numb( ov ) ); |
| 895 Db_setXref( msgId, t ); | 904 Db_setXref( msgId, t ); |
| 896 } | 905 } |
| 897 } | 906 } |
| 898 } | 907 } |
| 899 else | 908 else |
| 900 { | 909 { |
| 901 Log_dbg( "Preparing '%s' in database", msgId ); | 910 Log_dbg( LOG_DBG_FETCH, "Preparing '%s' in database", msgId ); |
| 902 Db_prepareEntry( ov, client.grp, Ov_numb( ov ) ); | 911 Db_prepareEntry( ov, client.grp, Ov_numb( ov ) ); |
| 903 } | 912 } |
| 904 } | 913 } |
| 905 | 914 |
| 906 Bool | 915 Bool |
| 927 { | 936 { |
| 928 Log_err( "XHDR command failed: %s", client.lastStat ); | 937 Log_err( "XHDR command failed: %s", client.lastStat ); |
| 929 return FALSE; | 938 return FALSE; |
| 930 } | 939 } |
| 931 | 940 |
| 932 Log_dbg( "Requesting Newsgroups headers for remote %lu-%lu", | 941 Log_dbg( LOG_DBG_FETCH, |
| 942 "Requesting Newsgroups headers for remote %lu-%lu", | |
| 933 rmtFirst, rmtLast ); | 943 rmtFirst, rmtLast ); |
| 934 | 944 |
| 935 newsgroups = collectTxt(); | 945 newsgroups = collectTxt(); |
| 936 if ( newsgroups == NULL ) | 946 if ( newsgroups == NULL ) |
| 937 return FALSE; | 947 return FALSE; |
| 954 { | 964 { |
| 955 del_DynStr( newsgroups ); | 965 del_DynStr( newsgroups ); |
| 956 Log_err( "XOVER command failed: %s", client.lastStat ); | 966 Log_err( "XOVER command failed: %s", client.lastStat ); |
| 957 return FALSE; | 967 return FALSE; |
| 958 } | 968 } |
| 959 Log_dbg( "Requesting overview for remote %lu-%lu", rmtFirst, rmtLast ); | 969 Log_dbg( LOG_DBG_FETCH, |
| 970 "Requesting overview for remote %lu-%lu", | |
| 971 rmtFirst, rmtLast ); | |
| 960 | 972 |
| 961 response = collectTxt(); | 973 response = collectTxt(); |
| 962 if ( response == NULL ) | 974 if ( response == NULL ) |
| 963 { | 975 { |
| 964 del_DynStr( newsgroups ); | 976 del_DynStr( newsgroups ); |
| 1145 else | 1157 else |
| 1146 DynStr_appLn( s, msgId ); | 1158 DynStr_appLn( s, msgId ); |
| 1147 | 1159 |
| 1148 Lock_closeDatabases(); | 1160 Lock_closeDatabases(); |
| 1149 fflush( client.out ); | 1161 fflush( client.out ); |
| 1150 Log_dbg( "[S FLUSH]" ); | 1162 Log_dbg( LOG_DBG_PROTOCOL, "[S FLUSH]" ); |
| 1151 | 1163 |
| 1152 p = DynStr_str( s ); | 1164 p = DynStr_str( s ); |
| 1153 res = TRUE; | 1165 res = TRUE; |
| 1154 while ( res && ( p = Utl_getLn( msgId, p ) ) ) | 1166 while ( res && ( p = Utl_getLn( msgId, p ) ) ) |
| 1155 { | 1167 { |
