Mercurial > noffle
comparison src/group.c @ 193:021d145e34e9 noffle
[svn] * src/fetch.c: Only leave articles in the requested list if the error
fetching them was fatal. Otherwise article requests will accumulate
indefinitely (e.g retrieving through NNTPcache when it can't find
the body of an article, now or event. Yes, this happened to me; I
had nearly 2000 requests backed up and never being cleared).
* src/group.c: The weekend's change introduced code that causes a bus
error on Sparc ( *(time_t *)p = xxx ). Replace with a safe memcpy,
and also use memcpy when reading the Entry and time items to remove
warnings on Sparc compilation.
author | bears |
---|---|
date | Mon, 22 Oct 2001 14:41:43 +0100 |
parents | 28488e0e3630 |
children | 24d4cd032da5 |
comparison
equal
deleted
inserted
replaced
192:b9ef99708d1c | 193:021d145e34e9 |
---|---|
5 the groups we know of. One database record is cached in the global struct | 5 the groups we know of. One database record is cached in the global struct |
6 grp. Group information is transfered between the grp and the database by | 6 grp. Group information is transfered between the grp and the database by |
7 loadGrp() and saveGrp(). This is done transparently. Access to the groups | 7 loadGrp() and saveGrp(). This is done transparently. Access to the groups |
8 database is done by group name, by the functions defined in group.h. | 8 database is done by group name, by the functions defined in group.h. |
9 | 9 |
10 $Id: group.c 310 2001-10-20 13:23:46Z bears $ | 10 $Id: group.c 312 2001-10-22 13:41:43Z bears $ |
11 */ | 11 */ |
12 | 12 |
13 #if HAVE_CONFIG_H | 13 #if HAVE_CONFIG_H |
14 #include <config.h> | 14 #include <config.h> |
15 #endif | 15 #endif |
89 gdbm_close( grp.dbf ); | 89 gdbm_close( grp.dbf ); |
90 grp.dbf = NULL; | 90 grp.dbf = NULL; |
91 Utl_cpyStr( grp.name, "" ); | 91 Utl_cpyStr( grp.name, "" ); |
92 } | 92 } |
93 | 93 |
94 /* Load group info from gdbm-database into global struct grp */ | 94 /* |
95 * Load group info from gdbm-database into global struct grp | |
96 * | |
97 * Note use of memcpy when packing buffer; avoids pointer alignment | |
98 * problems. | |
99 */ | |
95 static Bool | 100 static Bool |
96 loadGrp( const char *name ) | 101 loadGrp( const char *name ) |
97 { | 102 { |
98 const char *p; | 103 const char *p; |
99 datum key, val; | 104 datum key, val; |
104 key.dptr = (void *)name; | 109 key.dptr = (void *)name; |
105 key.dsize = strlen( name ) + 1; | 110 key.dsize = strlen( name ) + 1; |
106 val = gdbm_fetch( grp.dbf, key ); | 111 val = gdbm_fetch( grp.dbf, key ); |
107 if ( val.dptr == NULL ) | 112 if ( val.dptr == NULL ) |
108 return FALSE; | 113 return FALSE; |
109 grp.entry = *( (Entry *)val.dptr ); | 114 memcpy( &grp.entry, val.dptr, sizeof( grp.entry ) ); |
110 p = val.dptr + sizeof( grp.entry ); | 115 p = val.dptr + sizeof( grp.entry ); |
111 Utl_cpyStr( grp.serv, p ); | 116 Utl_cpyStr( grp.serv, p ); |
112 p += strlen( p ) + 1; | 117 p += strlen( p ) + 1; |
113 Utl_cpyStr( grp.dsc, p ); | 118 Utl_cpyStr( grp.dsc, p ); |
114 p += strlen( p) + 1; | 119 p += strlen( p) + 1; |
125 if ( p - val.dptr < val.dsize ) | 130 if ( p - val.dptr < val.dsize ) |
126 { | 131 { |
127 grp.postAllow = p[ 0 ]; | 132 grp.postAllow = p[ 0 ]; |
128 p++; | 133 p++; |
129 if ( p - val.dptr < val.dsize ) | 134 if ( p - val.dptr < val.dsize ) |
130 grp.lastPost = *((time_t *)p); | 135 memcpy( &grp.lastPost, p, sizeof( grp.lastPost ) ); |
131 } | 136 } |
132 | 137 |
133 Utl_cpyStr( grp.name, name ); | 138 Utl_cpyStr( grp.name, name ); |
134 free( val.dptr ); | 139 free( val.dptr ); |
135 return TRUE; | 140 return TRUE; |
136 } | 141 } |
137 | 142 |
138 /* Save group info from global struct grp into gdbm-database */ | 143 /* |
144 * Save group info from global struct grp into gdbm-database | |
145 * | |
146 * Note use of memcpy when packing buffer; avoids pointer alignment | |
147 * problems. | |
148 */ | |
139 static void | 149 static void |
140 saveGrp( void ) | 150 saveGrp( void ) |
141 { | 151 { |
142 size_t lenServ, lenDsc, bufLen; | 152 size_t lenServ, lenDsc, bufLen; |
143 datum key, val; | 153 datum key, val; |
149 lenDsc = strlen( grp.dsc ); | 159 lenDsc = strlen( grp.dsc ); |
150 bufLen = | 160 bufLen = |
151 sizeof( grp.entry ) + lenServ + lenDsc + 2 | 161 sizeof( grp.entry ) + lenServ + lenDsc + 2 |
152 + sizeof( char ) + sizeof( time_t ); | 162 + sizeof( char ) + sizeof( time_t ); |
153 buf = malloc( bufLen ); | 163 buf = malloc( bufLen ); |
154 memcpy( buf, (void *)&grp.entry, sizeof( grp.entry ) ); | 164 memcpy( buf, &grp.entry, sizeof( grp.entry ) ); |
155 p = (char *)buf + sizeof( grp.entry ); | 165 p = (char *)buf + sizeof( grp.entry ); |
156 strcpy( p, grp.serv ); | 166 strcpy( p, grp.serv ); |
157 p += lenServ + 1; | 167 p += lenServ + 1; |
158 strcpy( p, grp.dsc ); | 168 strcpy( p, grp.dsc ); |
159 p += lenDsc + 1; | 169 p += lenDsc + 1; |
160 p[ 0 ] = grp.postAllow; | 170 p[ 0 ] = grp.postAllow; |
161 p++; | 171 p++; |
162 *((time_t *) p) = grp.lastPost; | 172 memcpy( p, &grp.lastPost, sizeof( grp.lastPost ) ); |
163 key.dptr = (void *)grp.name; | 173 key.dptr = (void *)grp.name; |
164 key.dsize = strlen( grp.name ) + 1; | 174 key.dsize = strlen( grp.name ) + 1; |
165 val.dptr = buf; | 175 val.dptr = buf; |
166 val.dsize = bufLen; | 176 val.dsize = bufLen; |
167 if ( gdbm_store( grp.dbf, key, val, GDBM_REPLACE ) != 0 ) | 177 if ( gdbm_store( grp.dbf, key, val, GDBM_REPLACE ) != 0 ) |