Mercurial > noffle
diff src/client.c @ 88:1fcdced0246e noffle
[svn] Move posting code to post.c, add command line posting
author | bears |
---|---|
date | Thu, 18 May 2000 13:17:23 +0100 |
parents | c7df2cc65cc1 |
children | c3312022e657 |
line wrap: on
line diff
--- a/src/client.c Thu May 18 13:11:05 2000 +0100 +++ b/src/client.c Thu May 18 13:17:23 2000 +0100 @@ -1,7 +1,7 @@ /* client.c - $Id: client.c 80 2000-05-13 15:36:35Z bears $ + $Id: client.c 100 2000-05-18 12:17:23Z bears $ */ #if HAVE_CONFIG_H @@ -359,6 +359,47 @@ } static Bool +isGetGroup( const char *name ) +{ + GroupEnum *ge; + Bool emptyList; + const char *pattern; + + emptyList = TRUE; + ge = new_GetGrEn( client.serv ); + while ( ( pattern = GrEn_next( ge ) ) != NULL ) + { + emptyList = FALSE; + if ( Wld_match( name, pattern ) ) + { + del_GrEn( ge ); + return TRUE; + } + } + + del_GrEn( ge ); + return emptyList; +} + +static Bool +isOmitGroup( const char *name ) +{ + GroupEnum *ge; + const char *pattern; + + ge = new_OmitGrEn( client.serv ); + while ( ( pattern = GrEn_next( ge ) ) != NULL ) + if ( Wld_match( name, pattern ) ) + { + del_GrEn( ge ); + return TRUE; + } + + del_GrEn( ge ); + return FALSE; +} + +static Bool isForbiddenGroupName( const char *name ) { size_t i; @@ -378,7 +419,7 @@ } static void -processGrps( void ) +processGrps( Bool noServerPattern ) { char postAllow; Bool err; @@ -398,6 +439,10 @@ Log_inf( "Group %s forbidden", grp ); continue; } + if ( noServerPattern && ! isGetGroup( grp ) ) + continue; + if ( isOmitGroup( grp ) ) + continue; if ( ! Grp_exists( grp ) ) { Log_inf( "Registering new group '%s'", grp ); @@ -445,32 +490,94 @@ client.in = client.out = NULL; } -Bool -Client_getGrps( void ) +static Bool +doGetGrps( const char *pattern, Bool *noServerPattern ) { - if ( ! putCmd( "LIST ACTIVE" ) ) + Str cmd; + int stat; + + Utl_cpyStr( cmd, "LIST ACTIVE" ); + if ( pattern[ 0 ] != '\0' ) + { + Utl_catStr( cmd, " " ); + Utl_catStr( cmd, pattern ); + } + + *noServerPattern = FALSE; + if ( ! putCmd( cmd ) ) return FALSE; - if ( getStat() != STAT_GRPS_FOLLOW ) + stat = getStat(); + if ( pattern[ 0 ] != '\0' && stat != STAT_GRPS_FOLLOW ) { - Log_err( "LIST ACTIVE command failed: %s", client.lastStat ); - return FALSE; + *noServerPattern = TRUE; + if ( ! putCmd( "LIST ACTIVE" ) ) + return FALSE; + stat = getStat(); + } + if ( stat != STAT_GRPS_FOLLOW ) + { + Log_err( "%s failed: %s", cmd, client.lastStat ); + return FALSE; } - processGrps(); + processGrps( *noServerPattern ); return TRUE; } Bool -Client_getDsc( void ) +Client_getGrps( void ) +{ + GroupEnum *ge; + const char *pattern; + Bool doneOne, noServerPattern, res; + + Log_inf( "Getting groups" ); + + doneOne = FALSE; + res = TRUE; + ge = new_GetGrEn( client.serv ); + while ( res && ( pattern = GrEn_next( ge ) ) != NULL ) + { + res = doGetGrps( pattern, &noServerPattern ); + doneOne = TRUE; + if ( noServerPattern ) + break; + } + + if ( ! doneOne ) + res = doGetGrps( "", &noServerPattern ); + + del_GrEn( ge ); + return res; +} + +static Bool +doGetDsc( const char *pattern, Bool *noServerPattern ) { Bool err; - Str name, line, dsc; + Str name, line, dsc, cmd; + int stat; + + Utl_cpyStr( cmd, "LIST NEWSGROUPS" ); + if ( pattern[ 0 ] != '\0' ) + { + Utl_catStr( cmd, " " ); + Utl_catStr( cmd, pattern ); + } - Log_inf( "Querying group descriptions" ); - if ( ! putCmd( "LIST NEWSGROUPS" ) ) + *noServerPattern = FALSE; + if ( ! putCmd( cmd ) ) return FALSE; - if ( getStat() != STAT_GRPS_FOLLOW ) + stat = getStat(); + if ( pattern[ 0 ] != '\0' && stat != STAT_GRPS_FOLLOW ) { - Log_err( "LIST NEWSGROUPS failed: %s", client.lastStat ); + *noServerPattern = TRUE; + if ( !putCmd( "LIST NEWSGROUPS" ) ) + return FALSE; + stat = getStat(); + } + if ( stat != STAT_GRPS_FOLLOW ) + { + Log_err( "%s failed: %s", cmd, client.lastStat ); return FALSE; } while ( getTxtLn( line, &err ) && ! err ) @@ -480,6 +587,8 @@ Log_err( "Unknown reply to LIST NEWSGROUPS: %s", line ); continue; } + if ( *noServerPattern && ! isGetGroup( name ) ) + continue; strcpy( dsc, Utl_restOfLn( line, 1 ) ); if ( Grp_exists( name ) ) { @@ -491,18 +600,61 @@ } Bool -Client_getCreationTimes( void ) +Client_getDsc( void ) +{ + GroupEnum *ge; + const char *pattern; + Bool doneOne, noServerPattern, res; + + Log_inf( "Querying group descriptions" ); + + doneOne = FALSE; + res = TRUE; + ge = new_GetGrEn( client.serv ); + while ( res && ( pattern = GrEn_next( ge ) ) != NULL ) + { + res = doGetDsc( pattern, &noServerPattern ); + doneOne = TRUE; + if ( noServerPattern ) + break; + } + + if ( ! doneOne ) + res = doGetDsc( "", &noServerPattern ); + + del_GrEn( ge ); + return res; +} + +static Bool +doGetCreationTimes( const char *pattern, Bool *noServerPattern ) { Bool err; - Str name, line; + Str name, line, cmd; time_t t; + int stat; + + Utl_cpyStr( cmd, "LIST ACTIVE.TIMES" ); + if ( pattern[ 0 ] != '\0' ) + { + Utl_catStr( cmd, " " ); + Utl_catStr( cmd, pattern ); + } - Log_inf( "Querying group creation times" ); - if ( ! putCmd( "LIST ACTIVE.TIMES" ) ) + *noServerPattern = FALSE; + if ( ! putCmd( cmd ) ) return FALSE; - if ( getStat() != STAT_GRPS_FOLLOW ) + stat = getStat(); + if ( pattern[ 0 ] != '\0' && stat != STAT_GRPS_FOLLOW ) { - Log_err( "LIST ACTIVE.TIMES failes: %s", client.lastStat ); + *noServerPattern= TRUE; + if ( ! putCmd( "LIST ACTIVE.TIMES" ) ) + return FALSE; + stat = getStat(); + } + if ( stat != STAT_GRPS_FOLLOW ) + { + Log_err( "%s failed: %s", cmd, client.lastStat ); return FALSE; } while ( getTxtLn( line, &err ) && ! err ) @@ -512,6 +664,8 @@ Log_err( "Unknown reply to LIST ACTIVE.TIMES: %s", line ); continue; } + if ( *noServerPattern && ! isGetGroup( name ) ) + continue; if ( Grp_exists( name ) ) { Log_inf( "Creation time of %s: %ld", name, t ); @@ -522,6 +676,33 @@ } Bool +Client_getCreationTimes( void ) +{ + GroupEnum *ge; + const char *pattern; + Bool doneOne, noServerPattern, res; + + Log_inf( "Querying group creation times" ); + + doneOne = FALSE; + res = TRUE; + ge = new_GetGrEn( client.serv ); + while ( res && ( pattern = GrEn_next( ge ) ) != NULL ) + { + res = doGetCreationTimes( pattern, &noServerPattern ); + doneOne = TRUE; + if ( noServerPattern ) + break; + } + + if ( ! doneOne ) + res = doGetCreationTimes( "", &noServerPattern ); + + del_GrEn( ge ); + return res; +} + +Bool Client_getNewgrps( const time_t *lastTime ) { Str s; @@ -535,14 +716,14 @@ (directly using %y in fmt string causes a Y2K compiler warning) */ p = s + 2; - if ( ! putCmd( "NEWGROUPS %s", p ) ) + if ( ! putCmd( "NEWGROUPS %s GMT", p ) ) return FALSE; if ( getStat() != STAT_NEW_GRP_FOLLOW ) { Log_err( "NEWGROUPS command failed: %s", client.lastStat ); return FALSE; } - processGrps(); + processGrps( TRUE ); return TRUE; } @@ -745,6 +926,8 @@ if ( ! parseOvLn( line, &rmtNumb, subj, from, date, msgId, ref, &bytes, &lines ) ) Log_err( "Bad overview line: %s", line ); + else if ( Cont_find( msgId ) >= 0 ) + Log_inf( "Already have '%s'", msgId ); else { ov = new_Over( subj, from, date, msgId, ref, bytes, lines );