annotate src/util.c @ 443:b415fa4d18ee noffle

[svn] update
author godisch
date Wed, 25 Jun 2003 16:41:02 +0100
parents 4426fde0a72c
children 95697d7c97a1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
1 /*
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
2 util.c
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
3
295
4426fde0a72c [svn] * src/util.c: Add cast to deal with compiler warning.
bears
parents: 281
diff changeset
4 $Id: util.c 427 2003-01-31 15:35:14Z bears $
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
5 */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
6
45
32ba1198c6fa [svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents: 43
diff changeset
7 #if HAVE_CONFIG_H
32ba1198c6fa [svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents: 43
diff changeset
8 #include <config.h>
32ba1198c6fa [svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents: 43
diff changeset
9 #endif
32ba1198c6fa [svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents: 43
diff changeset
10
54
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
11 #if TIME_WITH_SYS_TIME
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
12 #include <sys/time.h>
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
13 #include <time.h>
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
14 #else
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
15 #if HAVE_SYS_TIME_H
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
16 #include <sys/time.h>
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
17 #else
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
18 #include <time.h>
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
19 #endif
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
20 #endif
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 45
diff changeset
21
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
22 #include <errno.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
23 #include <ctype.h>
244
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
24 #include <netdb.h>
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
25 #include <sys/types.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
26 #include <sys/stat.h>
244
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
27 #include <sys/utsname.h>
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
28 #include <fcntl.h>
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
29 #include <stdlib.h>
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
30 #include <unistd.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
31 #include "configfile.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
32 #include "log.h"
197
24d4cd032da5 [svn] * AUTHORS,INSTALL,NEWS,README,TODO,docs/NOTES,src/client.c,src/protocol.c,
bears
parents: 186
diff changeset
33 #include "portable.h"
24d4cd032da5 [svn] * AUTHORS,INSTALL,NEWS,README,TODO,docs/NOTES,src/client.c,src/protocol.c,
bears
parents: 186
diff changeset
34 #include "util.h"
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
35 #include "wildmat.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
36
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
37 #if defined(UTIL_TEST)
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
38 #define Log_err printf
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
39 #endif
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
40
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
41 static const char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
42 nextWhiteSpace( const char *p )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
43 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
44 while ( *p && ! isspace( *p ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
45 ++p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
46 return p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
47 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
48
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
49 static const char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
50 nextNonWhiteSpace( const char *p )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
51 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
52 while ( *p && isspace( *p ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
53 ++p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
54 return p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
55 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
56
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
57 const char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
58 Utl_restOfLn( const char *line, unsigned int token )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
59 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
60 unsigned int i;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
61 const char *p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
62
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
63 p = line;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
64 for ( i = 0; i < token; ++i )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
65 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
66 p = nextNonWhiteSpace( p );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
67 p = nextWhiteSpace( p );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
68 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
69 p = nextNonWhiteSpace( p );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
70 return p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
71 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
72
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
73 const char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
74 Utl_getLn( Str result, const char *pos )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
75 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
76 int len = 0;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
77 const char *p = pos;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
78
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
79 if ( ! p )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
80 return NULL;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
81 while ( *p != '\n' )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
82 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
83 if ( *p == '\0' )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
84 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
85 if ( len > 0 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
86 Log_err( "Line not terminated by newline: '%s'", pos );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
87 return NULL;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
88 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
89 *(result++) = *(p++);
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
90 ++len;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
91 if ( len >= MAXCHAR - 1 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
92 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
93 *result = '\0';
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
94 Log_err( "Utl_getLn: line too long: %s", result );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
95 return ++p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
96 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
97 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
98 *result = '\0';
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
99 return ++p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
100
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
101 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
102
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
103 const char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
104 Utl_ungetLn( const char *str, const char *p )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
105 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
106 if ( str == p )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
107 return FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
108 --p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
109 if ( *p != '\n' )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
110 {
185
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 164
diff changeset
111 Log_err( "Utl_ungetLn: not at beginning of line" );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
112 return NULL;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
113 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
114 --p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
115 while ( TRUE )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
116 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
117 if ( p == str )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
118 return p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
119 if ( *p == '\n' )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
120 return p + 1;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
121 --p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
122 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
123 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
124
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
125 const char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
126 Utl_getHeaderLn( Str result, const char *p )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
127 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
128 const char * res = Utl_getLn( result, p );
202
mirkol
parents: 197
diff changeset
129 Bool not_too_long_header = TRUE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
130
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
131 /* Look for followon line if this isn't a blank line. */
109
2bedacfe1ba7 [svn] Fix header line reading buf
bears
parents: 91
diff changeset
132 if ( res != NULL && result[ 0 ] != '\0' && ! isspace( result[ 0 ] ) )
87
bf8c97460fd7 [svn] Preserve newslines and spaces in header lines
bears
parents: 59
diff changeset
133 for(;;)
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
134 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
135 Str nextLine;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
136 const char *here;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
137
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
138 here = res;
87
bf8c97460fd7 [svn] Preserve newslines and spaces in header lines
bears
parents: 59
diff changeset
139 nextLine[ 0 ] = '\0';
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
140 res = Utl_getLn( nextLine, res );
87
bf8c97460fd7 [svn] Preserve newslines and spaces in header lines
bears
parents: 59
diff changeset
141 if ( res == NULL || nextLine[ 0 ] == '\0'
109
2bedacfe1ba7 [svn] Fix header line reading buf
bears
parents: 91
diff changeset
142 || ! isspace( nextLine[ 0 ] ) )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
143 {
87
bf8c97460fd7 [svn] Preserve newslines and spaces in header lines
bears
parents: 59
diff changeset
144 res = here;
bf8c97460fd7 [svn] Preserve newslines and spaces in header lines
bears
parents: 59
diff changeset
145 break;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
146 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
147 else
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
148 {
202
mirkol
parents: 197
diff changeset
149 if ( not_too_long_header &&
mirkol
parents: 197
diff changeset
150 ( MAXCHAR > ( strlen( result ) + strlen( nextLine ) + 1 ) ) )
mirkol
parents: 197
diff changeset
151 {
mirkol
parents: 197
diff changeset
152 Utl_catStr( result, "\n" );
mirkol
parents: 197
diff changeset
153 Utl_catStr( result, nextLine );
mirkol
parents: 197
diff changeset
154 }
mirkol
parents: 197
diff changeset
155 else
mirkol
parents: 197
diff changeset
156 {
mirkol
parents: 197
diff changeset
157 Log_err( "Utl_getHeaderLn: skipped continued header: %s", nextLine );
mirkol
parents: 197
diff changeset
158 not_too_long_header = FALSE;
mirkol
parents: 197
diff changeset
159 /* Now let poor little noffle skip the header continuations. */
mirkol
parents: 197
diff changeset
160 /* We really need to up the size limit of headers much */
mirkol
parents: 197
diff changeset
161 /* higher than MAXCHAR = 2048. mliss */
mirkol
parents: 197
diff changeset
162 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
163 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
164 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
165
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
166 return res;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
167 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
168
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
169 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
170 Utl_toLower( Str line )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
171 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
172 char *p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
173
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
174 p = line;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
175 while ( *p )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
176 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
177 *p = tolower( *p );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
178 ++p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
179 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
180 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
181
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
182 char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
183 Utl_stripWhiteSpace( char *line )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
184 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
185 char *p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
186
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
187 while ( isspace( *line ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
188 ++line;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
189 p = line + strlen( line ) - 1;
240
fbff73fe5b40 [svn] * src/client.c: That wasn't a memory leak fixed on Feb 8th. That was a
bears
parents: 223
diff changeset
190 while ( p >= line && isspace( *p ) )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
191 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
192 *p = '\0';
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
193 --p;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
194 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
195 return line;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
196 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
197
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
198 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
199 Utl_stripComment( char *line )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
200 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
201 for ( ; *line != '\0'; line++ )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
202 if ( *line =='#' )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
203 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
204 *line = '\0';
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
205 break;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
206 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
207 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
208
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
209 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
210 Utl_cpyStr( Str dst, const char *src )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
211 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
212 dst[ 0 ] = '\0';
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
213 strncat( dst, src, MAXCHAR );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
214 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
215
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
216 void
59
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
217 Utl_cpyStrN( Str dst, const char *src, int n )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
218 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
219 if ( n > MAXCHAR )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
220 n = MAXCHAR;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
221 dst[ 0 ] = '\0';
59
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
222 strncat( dst, src, (size_t)n );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
223 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
224
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
225 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
226 Utl_catStr( Str dst, const char *src )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
227 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
228 strncat( dst, src, MAXCHAR - strlen( dst ) );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
229 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
230
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
231 void
59
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
232 Utl_catStrN( Str dst, const char *src, int n )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
233 {
59
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
234 size_t un;
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
235
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
236 ASSERT( n >= 0 );
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
237 un = (size_t)n;
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
238 if ( un > MAXCHAR - strlen( dst ) )
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
239 un = MAXCHAR - strlen( dst );
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
240 strncat( dst, src, un );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
241 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
242
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
243 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
244 Utl_stamp( Str file )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
245 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
246 FILE *f;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
247 time_t t;
206
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
248 Str tmpfname;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
249
206
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
250 snprintf( tmpfname, MAXCHAR, "%s/.#%d.stamp.update",
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
251 Cfg_spoolDir(), (int) getpid() );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
252 time( &t );
206
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
253 if ( ! ( f = fopen( tmpfname, "w" ) ) )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
254 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
255 Log_err( "Could not open %s for writing (%s)",
206
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
256 tmpfname, strerror( errno ) );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
257 return;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
258 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
259 fprintf( f, "%lu\n", t );
223
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 206
diff changeset
260 if ( fclose( f ) != 0 )
206
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
261 {
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
262 Log_err( "Error stamping into file %s: %s",
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
263 tmpfname, strerror( errno ) );
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
264
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
265 }
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
266 else
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
267 {
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
268 if ( rename( tmpfname, file ) < 0 )
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
269 Log_err( "Rename of stamp file %s to %s failed: %s",
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
270 tmpfname, file, strerror( errno ) );
eb2589384836 [svn] * TODO: Update the TODO list.
bears
parents: 202
diff changeset
271 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
272 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
273
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
274 Bool
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
275 Utl_getStamp( time_t *result, Str file )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
276 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
277 FILE *f;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
278
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
279 if ( ! ( f = fopen( file, "r" ) ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
280 return FALSE;
295
4426fde0a72c [svn] * src/util.c: Add cast to deal with compiler warning.
bears
parents: 281
diff changeset
281 if ( fscanf( f, "%lu", (unsigned long *) result ) != 1 )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
282 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
283 Log_err( "File %s corrupted", file );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
284 fclose( f );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
285 return FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
286 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
287 fclose( f );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
288 return TRUE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
289 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
290
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
291 static const char *DOTW[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri",
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
292 "Sat", NULL };
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
293 static const char *MON[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
294 "Aug", "Sep", "Oct", "Nov", "Dec", NULL };
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
295
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
296 /*
259
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
297 * Calculate the difference between local time and GMT at GMT time t.
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
298 *
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
299 * This is INN's 'always-works' method. It assumes the time differences
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
300 * is < 24hrs. Sounds reasonable to me. It also assumes it can ignore seconds.
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
301 * Returns localtime - GMT seconds. It will also trash the localtime/
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
302 * gmtime/etc. static buffer.
279
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
303 *
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
304 * Do some basic caching by returning the previous result if the new request
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
305 * is in the same hour as the previous one.
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
306 */
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
307 static int
259
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
308 localTimeDiff( time_t t )
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
309 {
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
310 struct tm local, gmt, *tm;
279
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
311 static time_t resHourStart = 0;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
312 static int res = 0;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
313
279
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
314 if ( labs( t - resHourStart ) < 60 )
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
315 return res;
279
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
316
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
317 /* Calculating for new hour */
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
318 resHourStart = ( t / 60 ) * 60;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
319
259
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
320 tm = localtime( &t );
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
321 if ( tm == NULL )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
322 return 0;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
323 local = *tm;
259
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
324 tm = gmtime( &t );
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
325 if ( tm == NULL )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
326 return 0;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
327 gmt = *tm;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
328
259
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
329 res = local.tm_yday - gmt.tm_yday;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
330 if ( res < -1 )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
331 res = -1; /* Year rollover? */
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
332 else if ( res > 1 )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
333 res = 1;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
334
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
335 res *= 24;
259
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
336 res += local.tm_hour - gmt.tm_hour;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
337 res *= 60;
259
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
338 res += local.tm_min - gmt.tm_min;
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
339 res *= 60;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
340
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
341 return res;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
342 }
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
343
259
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
344 time_t
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
345 Utl_mktimeGMT( struct tm *t )
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
346 {
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
347 #if HAVE_TIMEGM
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
348 return timegm( t );
279
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
349 #else
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
350 /* This comment and implmentation is taken from Wget's mktime_from_utc().
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
351 * We could
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
352 *
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
353 * Converts struct tm to time_t, assuming the data in tm is UTC rather
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
354 * than local timezone.
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
355 *
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
356 * mktime is similar but assumes struct tm, also known as the
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
357 * "broken-down" form of time, is in local time zone. mktime_from_utc
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
358 * uses mktime to make the conversion understanding that an offset
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
359 * will be introduced by the local time assumption.
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
360 *
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
361 * mktime_from_utc then measures the introduced offset by applying
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
362 * gmtime to the initial result and applying mktime to the resulting
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
363 * "broken-down" form. The difference between the two mktime results
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
364 * is the measured offset which is then subtracted from the initial
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
365 * mktime result to yield a calendar time which is the value returned.
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
366 *
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
367 * tm_isdst in struct tm is set to 0 to force mktime to introduce a
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
368 * consistent offset (the non DST offset) since tm and tm+o might be
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
369 * on opposite sides of a DST change.
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
370 *
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
371 * Some implementations of mktime return -1 for the nonexistent
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
372 * localtime hour at the beginning of DST. In this event, use
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
373 * mktime(tm - 1hr) + 3600.
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
374 *
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
375 * Schematically
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
376 * mktime(tm) --> t+o
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
377 * gmtime(t+o) --> tm+o
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
378 * mktime(tm+o) --> t+2o
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
379 * t+o - (t+2o - t+o) = t
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
380 *
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
381 * Note that glibc contains a function of the same purpose named
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
382 * `timegm' (reverse of gmtime). But obviously, it is not universally
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
383 * available, and unfortunately it is not straightforwardly
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
384 * extractable for use here. Perhaps configure should detect timegm
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
385 * and use it where available.
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
386 *
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
387 * Contributed by Roger Beeman <beeman@cisco.com>, with the help of
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
388 * Mark Baushke <mdb@cisco.com> and the rest of the Gurus at CISCO.
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
389 * Further improved by Roger with assistance from Edward J. Sabol
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
390 * based on input by Jamie Zawinski.
259
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
391 */
279
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
392 time_t tl, tb;
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
393 struct tm *tg;
259
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
394
279
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
395 tl = mktime (t);
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
396 if (tl == -1)
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
397 {
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
398 t->tm_hour--;
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
399 tl = mktime (t);
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
400 if (tl == -1)
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
401 return -1; /* can't deal with output from strptime */
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
402 tl += 3600;
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
403 }
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
404 tg = gmtime (&tl);
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
405 tg->tm_isdst = 0;
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
406 tb = mktime (tg);
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
407 if (tb == -1)
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
408 {
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
409 tg->tm_hour--;
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
410 tb = mktime (tg);
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
411 if (tb == -1)
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
412 return -1; /* can't deal with output from gmtime */
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
413 tb += 3600;
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
414 }
49b452b667a6 [svn] * src/util.c: localTimeDiff() cached its value and recalculated it every
bears
parents: 271
diff changeset
415 return (tl - (tb - tl));
259
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
416 #endif
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
417 }
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
418
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
419 void
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
420 Utl_newsDate( time_t t, Str res )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
421 {
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
422 struct tm *local;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
423 long tzdiff, hoffset, moffset;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
424
259
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
425 tzdiff = localTimeDiff( t ) / 60;
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
426
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
427 local = localtime( &t );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
428 if ( local == NULL )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
429 {
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
430 Utl_cpyStr( res, "** localtime failure **" );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
431 return;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
432 }
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
433
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
434 hoffset = tzdiff / 60;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
435 moffset = tzdiff % 60;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
436 if ( moffset < 0 )
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
437 moffset = - moffset;
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
438
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
439 sprintf( res, "%s, %d %s %4d %02d:%02d:%02d %+03ld%02ld",
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
440 DOTW[local->tm_wday], local->tm_mday,
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
441 MON[local->tm_mon], local->tm_year + 1900,
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
442 local->tm_hour, local->tm_min, local->tm_sec,
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
443 hoffset, moffset );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
444 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
445
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
446 time_t
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
447 Utl_parseNewsDate( const char *s )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
448 {
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
449 struct tm tm;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
450 int wday, offset, tzoffset;
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
451 char *p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
452 time_t res;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
453
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
454 memset( &tm, 0, sizeof( tm ) );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
455 wday = -1;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
456 tm.tm_isdst = -1;
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
457
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
458 s = nextNonWhiteSpace( s );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
459
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
460 /* Is this the day number, or a weekday? */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
461 if ( ! isdigit( *s ) )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
462 {
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
463 if ( strlen( s ) < 4 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
464 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
465
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
466 for ( wday = 0; DOTW[ wday ] != NULL; wday++ )
186
7d1f26e7c728 [svn] Remove case sensitivity in date parse.
bears
parents: 185
diff changeset
467 if ( strncasecmp( DOTW[ wday ], s, 3 ) == 0 )
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
468 break;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
469
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
470 if( DOTW[ wday ] == NULL || s[3] != ',' )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
471 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
472
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
473 s += 4;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
474 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
475
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
476 /* Get the day number */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
477 tm.tm_mday = (int) strtol( s, &p, 10 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
478 if ( p == s )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
479 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
480 s = p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
481
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
482 /* Look for month name */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
483 s = nextNonWhiteSpace( s );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
484 if ( strlen( s ) < 4 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
485 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
486 for ( tm.tm_mon = 0; MON[ tm.tm_mon ] != NULL; tm.tm_mon++ )
186
7d1f26e7c728 [svn] Remove case sensitivity in date parse.
bears
parents: 185
diff changeset
487 if ( strncasecmp( MON[ tm.tm_mon ], s, 3 ) == 0 )
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
488 break;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
489
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
490 if ( MON[ tm.tm_mon ] == NULL )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
491 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
492 s += 3;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
493
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
494 /* Year next */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
495 tm.tm_year = (int) strtol( s, &p, 10 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
496 if ( p == s || ( tm.tm_year >= 100 && tm.tm_year < 1900 ) )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
497 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
498 if ( tm.tm_year >= 1900 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
499 tm.tm_year -= 1900;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
500 s = p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
501
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
502 /* Hours */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
503 tm.tm_hour = (int) strtol( s, &p, 10 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
504 if ( p == s || *p != ':' )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
505 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
506 s = ++p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
507
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
508 /* Minutes */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
509 tm.tm_min = (int) strtol( s, &p, 10 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
510 if ( p == s || ( *p != ':' && *p != ' ' ) )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
511 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
512 s = p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
513
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
514 /* Seconds */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
515 if ( *s == ':' )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
516 {
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
517 s++;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
518 tm.tm_sec = (int) strtol( s, &p, 10 );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
519 if ( p == s )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
520 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
521 s = p;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
522 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
523
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
524 /* GMT/UT or timezone offset */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
525 tzoffset = 0;
202
mirkol
parents: 197
diff changeset
526 s = nextNonWhiteSpace( s );
186
7d1f26e7c728 [svn] Remove case sensitivity in date parse.
bears
parents: 185
diff changeset
527 if ( strncasecmp( s, "GMT", 3) == 0 )
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
528 s += 3;
186
7d1f26e7c728 [svn] Remove case sensitivity in date parse.
bears
parents: 185
diff changeset
529 else if ( strncasecmp( s, "UT", 2 ) == 0 )
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
530 s += 2;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
531 else
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
532 {
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
533 offset = (int) strtol( s, &p, 10 );
202
mirkol
parents: 197
diff changeset
534 if ( p == s )
mirkol
parents: 197
diff changeset
535 return (time_t) -1;
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
536 s = p;
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
537 tzoffset = ( offset / 100 ) * 60 + ( offset % 100 );
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
538 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
539
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
540 /* Check for following junk */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
541 if ( *s != '\0' && ! isspace( *s ) )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
542 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
543
259
b660fadc1814 [svn] * src/server.c,src/util.c,src/util.h: Recognise GMT/UTC on NNTP NEWGROUPS.
bears
parents: 244
diff changeset
544 res = Utl_mktimeGMT( &tm );
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
545 if ( res == (time_t) -1 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
546 return res;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
547
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
548 if ( wday >= 0 && wday != tm.tm_wday )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
549 return (time_t) -1;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
550
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
551 /* And now adjust for tzoffset */
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
552 res -= tzoffset * 60;
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
553
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
554 return res;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
555 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
556
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
557 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
558 Utl_allocAndCpy( char **dst, const char *src )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
559 {
281
5eece4dfd945 [svn] * src/log.c,src/log.h: Add Log_fatal() for reporting fatal errors
bears
parents: 279
diff changeset
560 size_t len = strlen( src );
5eece4dfd945 [svn] * src/log.c,src/log.h: Add Log_fatal() for reporting fatal errors
bears
parents: 279
diff changeset
561 if ( ! ( *dst = malloc( len + 1 ) ) )
5eece4dfd945 [svn] * src/log.c,src/log.h: Add Log_fatal() for reporting fatal errors
bears
parents: 279
diff changeset
562 Log_fatal( "Cannot allocate string with length %lu", len );
5eece4dfd945 [svn] * src/log.c,src/log.h: Add Log_fatal() for reporting fatal errors
bears
parents: 279
diff changeset
563 memcpy( *dst, src, len + 1 );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
564 }
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
565
271
3477050e8d10 [svn] * src/client.c,src/fetch.c,src/lock.c.src/protocol.c,src/util.h,src/util.c:
bears
parents: 259
diff changeset
566 SignalHandler
3477050e8d10 [svn] * src/client.c,src/fetch.c,src/lock.c.src/protocol.c,src/util.h,src/util.c:
bears
parents: 259
diff changeset
567 Utl_installSignalHandler( int sig, SignalHandler handler )
164
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
568 {
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
569 struct sigaction act, oldAct;
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
570
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
571 act.sa_handler = handler;
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
572 sigemptyset( &act.sa_mask );
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
573 act.sa_flags = 0;
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
574 if ( sig != SIGALRM )
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
575 act.sa_flags |= SA_RESTART;
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
576 if ( sigaction( sig, &act, &oldAct ) < 0 )
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
577 return SIG_ERR;
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
578 return oldAct.sa_handler;
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
579 }
94f2e5607772 [svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents: 127
diff changeset
580
244
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
581 static Bool
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
582 getHostFQDN( Str result )
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
583 {
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
584 struct hostent *myHostEnt;
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
585 struct utsname myName;
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
586
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
587 if ( uname( &myName ) >= 0
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
588 && ( myHostEnt = gethostbyname( myName.nodename ) ) )
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
589 {
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
590 Utl_cpyStr( result, myHostEnt->h_name );
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
591 return TRUE;
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
592 }
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
593 return FALSE;
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
594 }
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
595
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
596 Bool
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
597 Utl_getFQDN( Str result )
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
598 {
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
599 /* get hostname from Cfg-File */
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
600 Utl_cpyStr( result, Cfg_hostnameMsgId() );
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
601 if ( strlen( result ) != 0 )
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
602 return TRUE;
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
603 return getHostFQDN( result );
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
604 }
4e69e9b722ae [svn] * src/database.c,src/protocol.c,src/util.c,src/util.h: The latest IETF
bears
parents: 240
diff changeset
605
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
606 #if defined(UTIL_TEST)
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
607
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
608 /* Test code borrowed from wildmat.c. Yep, still uses gets(). */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
609 extern char *gets();
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
610
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
611 int
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
612 main()
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
613 {
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
614 Str line;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
615 time_t t;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
616
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
617 printf( "Util date tester. Enter date to test.\n" );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
618 printf( "A blank line exits the program.\n" );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
619
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
620 for ( ; ; )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
621 {
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
622 t = time( NULL );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
623 Utl_newsDate( t, line );
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
624 printf( "\n(%s) Enter date: ", line );
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
625 (void) fflush( stdout );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
626 if ( gets( line ) == NULL || line[0] == '\0' )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
627 break;
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
628
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
629 t = Utl_parseNewsDate( line );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
630 if ( t == (time_t) -1 )
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
631 printf( "Date parse failed\n" );
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
632 else
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
633 {
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
634 Utl_newsDate( t, line );
127
3c71e28c8eef [svn] Release-1-0 mergedocs/NOTES
bears
parents: 109
diff changeset
635 printf( "Utl_newsDate -> '%s'\n", line );
91
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
636 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
637 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
638
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
639 exit(0);
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
640 /* NOTREACHED */
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
641 }
93cc929329eb [svn] Date output change and now date parsing
bears
parents: 87
diff changeset
642 #endif