Mercurial > noffle
diff src/server.c @ 259:b660fadc1814 noffle
[svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
Do small reorg of some of the timezone sensitive code, and introduce
use of timegm(). An implementation is provided for systems without
timegm().
author | bears |
---|---|
date | Wed, 26 Jun 2002 14:30:26 +0100 |
parents | d70e9dd6b308 |
children | 94b7962a0fbe |
line wrap: on
line diff
--- a/src/server.c Wed Jun 26 14:29:02 2002 +0100 +++ b/src/server.c Wed Jun 26 14:30:26 2002 +0100 @@ -1,7 +1,7 @@ /* server.c - $Id: server.c 372 2002-03-13 11:12:23Z mirkol $ + $Id: server.c 391 2002-06-26 13:30:26Z bears $ */ #if HAVE_CONFIG_H @@ -815,7 +815,7 @@ Str s, arg; const char *pat; - if ( sscanf( line, "%s", s ) != 1 ) + if ( sscanf( line, MAXCHAR_FMT, s ) != 1 ) doListActive( "*" ); else { @@ -874,9 +874,13 @@ return TRUE; } -/* Can return -1, if date is outside the range of time_t. */ +/* + * Given a time specification (local time or GMT), return a time_t. + */ static time_t -getTimeInSeconds( int year, int mon, int day, int hour, int min, int sec ) +getTimeInSeconds( int year, int mon, int day, + int hour, int min, int sec, + Bool timeIsGMT ) { struct tm t; time_t result; @@ -899,7 +903,8 @@ t.tm_hour = hour; t.tm_min = min; t.tm_sec = sec; - result = mktime( &t ); + t.tm_isdst = -1; + result = timeIsGMT ? Utl_mktimeGMT( &t ) : mktime( &t ); return result; } @@ -907,12 +912,26 @@ static Bool doNewgrps( char *arg, const Cmd *cmd ) { - time_t t, now, lastUpdate, nextCentBegin; - int year, mon, day, hour, min, sec, cent, len; + time_t t, now, lastUpdate; + int year, mon, day, hour, min, sec, len, fields, nowYear; const char *g; - Str date, timeofday, file; + Str date, timeofday, file, utc; + Bool timeIsGMT = FALSE; + struct tm *tm; - if ( sscanf( arg, "%s %s", date, timeofday ) != 2 ) + fields = sscanf( arg, MAXCHAR_FMT " " MAXCHAR_FMT " " MAXCHAR_FMT, + date, timeofday, utc ); + if ( fields == 3 ) + { + Utl_toLower( utc ); + if ( strcmp( utc, "gmt" ) != 0 && strcmp( utc, "utc" ) != 0 ) + { + putSyntax( cmd ); + return TRUE; + } + timeIsGMT = TRUE; + } + else if ( fields != 2 ) { putSyntax( cmd ); return TRUE; @@ -926,16 +945,16 @@ putSyntax( cmd ); return TRUE; } - now = time( NULL ); - cent = 1900; - nextCentBegin = getTimeInSeconds( cent + 100, 1, 1, 0, 0, 0 ); - while ( nextCentBegin != (time_t)-1 && now != (time_t)-1 - && now > nextCentBegin ) - { - cent += 100; - nextCentBegin = getTimeInSeconds( cent + 100, 1, 1, 0, 0, 0 ); - } - year += cent; + /* + * As per current IETF draft, year is this century if <= now, + * else last century. + */ + now = time( NULL ); + tm = timeIsGMT ? gmtime( &now ) : localtime( &now ); + nowYear = tm->tm_year + 1900; + year += ( nowYear / 100 ) * 100; + if ( year % 100 > nowYear % 100 ) + year -= 100; break; case 8: if ( sscanf( date, "%4d%2d%2d", &year, &mon, &day ) != 3 ) @@ -961,7 +980,7 @@ return TRUE; } snprintf( file, MAXCHAR, "%s/groupinfo.lastupdate", Cfg_spoolDir() ); - t = getTimeInSeconds( year, mon, day, hour, min, sec ); + t = getTimeInSeconds( year, mon, day, hour, min, sec, timeIsGMT ); if ( ! Utl_getStamp( &lastUpdate, file ) ) { @@ -969,8 +988,11 @@ putStat( STAT_PROGRAM_FAULT, "Server error reading %s", file ); return TRUE; } + + /* Show timestamp back as news format time for confirmation. */ + Utl_newsDate( t, timeofday ); - putStat( STAT_NEW_GRP_FOLLOW, "New groups since %s", arg ); + putStat( STAT_NEW_GRP_FOLLOW, "New groups since %s", timeofday ); if ( t == (time_t)-1 || t <= lastUpdate ) { @@ -1183,7 +1205,7 @@ const char *p; Str whatStr; - if ( sscanf( arg, "%s", whatStr ) != 1 ) + if ( sscanf( arg, MAXCHAR_FMT, whatStr ) != 1 ) { putSyntax( cmd ); return TRUE; @@ -1248,7 +1270,8 @@ enum XhdrType what; Str whatStr, articles, pat; - if ( sscanf( arg, "%s %s %s", whatStr, articles, pat ) != 3 ) + if ( sscanf( arg, MAXCHAR_FMT " " MAXCHAR_FMT " " MAXCHAR_FMT, + whatStr, articles, pat ) != 3 ) { putSyntax( cmd ); return TRUE; @@ -1393,7 +1416,7 @@ Str s, arg; Bool ret; - if ( sscanf( line, "%s", s ) == 1 ) + if ( sscanf( line, MAXCHAR_FMT, s ) == 1 ) { Utl_toLower( s ); strcpy( arg, Utl_restOfLn( line, 1 ) );