comparison src/server.c @ 69:21e778b6c3e9 noffle

[svn] Rewrote getTimesInSeconds(): arguments ar now int and checked with assertions. Return value is time_t and must be checked for (time_t)-1.
author enz
date Sat, 13 May 2000 10:25:28 +0100
parents 7250be163ec4
children c7df2cc65cc1
comparison
equal deleted inserted replaced
68:f76e8586fab6 69:21e778b6c3e9
1 /* 1 /*
2 server.c 2 server.c
3 3
4 $Id: server.c 70 2000-05-12 17:35:00Z enz $ 4 $Id: server.c 75 2000-05-13 09:25:28Z 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
20 #endif 20 #endif
21 21
22 #include <stdio.h> 22 #include <stdio.h>
23 #include "server.h" 23 #include "server.h"
24 #include <ctype.h> 24 #include <ctype.h>
25 #include <errno.h>
25 #include <signal.h> 26 #include <signal.h>
26 #include <stdarg.h> 27 #include <stdarg.h>
27 #include <sys/types.h> 28 #include <sys/types.h>
28 #include <unistd.h> 29 #include <unistd.h>
29 #include "client.h" 30 #include "client.h"
785 { 786 {
786 putStat( STAT_READY_POST_ALLOW, "Ok" ); 787 putStat( STAT_READY_POST_ALLOW, "Ok" );
787 return TRUE; 788 return TRUE;
788 } 789 }
789 790
790 static unsigned long 791 /* Can return -1, if date is outside the range of time_t. */
791 getTimeInSeconds( unsigned int year, unsigned int mon, unsigned int day, 792 static time_t
792 unsigned int hour, unsigned int min, unsigned int sec ) 793 getTimeInSeconds( int year, int mon, int day, int hour, int min, int sec )
793 { 794 {
794 struct tm t; 795 struct tm t;
795 796 time_t result;
797
798 ASSERT( year >= 1900 );
799 ASSERT( mon >= 1 );
800 ASSERT( mon <= 12 );
801 ASSERT( day >= 1 );
802 ASSERT( day <= 31 );
803 ASSERT( hour >= 0 );
804 ASSERT( hour <= 23 );
805 ASSERT( min >= 0 );
806 ASSERT( min <= 59 );
807 ASSERT( sec >= 0 );
808 ASSERT( sec <= 59 );
796 memset( &t, 0, sizeof( t ) ); 809 memset( &t, 0, sizeof( t ) );
797 t.tm_year = year - 1900; 810 t.tm_year = year - 1900;
798 t.tm_mon = mon - 1; 811 t.tm_mon = mon - 1;
799 t.tm_mday = day; 812 t.tm_mday = day;
800 t.tm_hour = hour; 813 t.tm_hour = hour;
801 t.tm_min = min; 814 t.tm_min = min;
802 t.tm_sec = sec; 815 t.tm_sec = sec;
803 return mktime( &t ); 816 result = mktime( &t );
817 return result;
804 } 818 }
805 819
806 820
807 static Bool 821 static Bool
808 doNewgrps( char *arg, const Cmd *cmd ) 822 doNewgrps( char *arg, const Cmd *cmd )
809 { 823 {
810 time_t t, now, lastUpdate; 824 time_t t, now, lastUpdate, nextCentBegin;
811 unsigned int year, mon, day, hour, min, sec, cent, len; 825 int year, mon, day, hour, min, sec, cent, len;
812 const char *g; 826 const char *g;
813 Str date, timeofday, file; 827 Str date, timeofday, file;
814 828
815 if ( sscanf( arg, "%s %s", date, timeofday ) != 2 ) 829 if ( sscanf( arg, "%s %s", date, timeofday ) != 2 )
816 { 830 {
819 } 833 }
820 len = strlen( date ); 834 len = strlen( date );
821 switch ( len ) 835 switch ( len )
822 { 836 {
823 case 6: 837 case 6:
824 if ( sscanf( date, "%2u%2u%2u", &year, &mon, &day ) != 3 ) 838 if ( sscanf( date, "%2d%2d%2d", &year, &mon, &day ) != 3 )
825 { 839 {
826 putSyntax( cmd ); 840 putSyntax( cmd );
827 return TRUE; 841 return TRUE;
828 } 842 }
829 now = time( NULL ); 843 now = time( NULL );
830 cent = 1900; 844 cent = 1900;
831 while ( now > getTimeInSeconds( cent + 100, 1, 1, 0, 0, 0 ) ) 845 nextCentBegin = getTimeInSeconds( cent + 100, 1, 1, 0, 0, 0 );
846 while ( nextCentBegin != (time_t)-1 && now != (time_t)-1
847 && now > nextCentBegin )
848 {
832 cent += 100; 849 cent += 100;
850 nextCentBegin = getTimeInSeconds( cent + 100, 1, 1, 0, 0, 0 );
851 }
833 year += cent; 852 year += cent;
834 break; 853 break;
835 case 8: 854 case 8:
836 if ( sscanf( date, "%4u%2u%2u", &year, &mon, &day ) != 3 ) 855 if ( sscanf( date, "%4d%2d%2d", &year, &mon, &day ) != 3 )
837 { 856 {
838 putSyntax( cmd ); 857 putSyntax( cmd );
839 return TRUE; 858 return TRUE;
840 } 859 }
841 break; 860 break;
842 default: 861 default:
843 putSyntax( cmd ); 862 putSyntax( cmd );
844 return TRUE; 863 return TRUE;
845 } 864 }
846 if ( sscanf( timeofday, "%2u%2u%2u", &hour, &min, &sec ) != 3 ) 865 if ( sscanf( timeofday, "%2d%2d%2d", &hour, &min, &sec ) != 3 )
847 { 866 {
848 putSyntax( cmd ); 867 putSyntax( cmd );
849 return TRUE; 868 return TRUE;
850 } 869 }
851 if ( year < 1970 || mon == 0 || mon > 12 || day == 0 || day > 31 870 if ( year < 1970 || mon < 1 || mon > 12 || day < 1 || day > 31
852 || hour > 23 || min > 59 || sec > 60 ) 871 || hour < 0 || hour > 23 || min < 0 || min > 59
872 || sec < 0 || sec > 60 )
853 { 873 {
854 putSyntax( cmd ); 874 putSyntax( cmd );
855 return TRUE; 875 return TRUE;
856 } 876 }
857 snprintf( file, MAXCHAR, "%s/groupinfo.lastupdate", Cfg_spoolDir() ); 877 snprintf( file, MAXCHAR, "%s/groupinfo.lastupdate", Cfg_spoolDir() );
858 t = getTimeInSeconds( year, mon, day, hour, min, sec ); 878 t = getTimeInSeconds( year, mon, day, hour, min, sec );
859 putStat( STAT_NEW_GRP_FOLLOW, "New groups since %s", arg ); 879 putStat( STAT_NEW_GRP_FOLLOW, "New groups since %s", arg );
860 880
861 if ( ! Utl_getStamp( &lastUpdate, file ) || t <= lastUpdate ) 881 if ( ! Utl_getStamp( &lastUpdate, file )
882 || t == (time_t)-1 || t <= lastUpdate )
862 { 883 {
863 if ( Grp_firstGrp( &g ) ) 884 if ( Grp_firstGrp( &g ) )
864 do 885 do
865 if ( Grp_created( g ) > t ) 886 if ( Grp_created( g ) > t )
866 putGrp( g ); 887 putGrp( g );