Mercurial > noffle
comparison src/group.c @ 191:28488e0e3630 noffle
[svn] * src/group.h,src/group.c,src/noffle.c,src/server.c: Grp_setLastAccess is
only ever called with last param as time(NULL), so remove it and call
time() inside the implementation of Grp_setLastAccess.
* src/client.c,src/group.h,src/group.c,src/noffle.c,src/post.c: Groups are
automatically unsubscribed when the last access to the group is older
than a particular threshold. However, for very low traffic groups, the
last access may exceed the threshold simply because there has been no new
article posted. In this case, rather than unsubscribe, update the group
last access time. This means that groups are now only unsubscribed if
the last access exceeds the threshold AND articles have arrived in the
group since. Add Grp_setLastPostTime() to track the last time an article
arrived in the group.
author | bears |
---|---|
date | Sat, 20 Oct 2001 14:23:46 +0100 |
parents | fed1334d766b |
children | 021d145e34e9 |
comparison
equal
deleted
inserted
replaced
190:47569cf4ad4a | 191:28488e0e3630 |
---|---|
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 300 2001-08-05 08:24:22Z bears $ | 10 $Id: group.c 310 2001-10-20 13:23:46Z 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 |
40 Str name; /* name of the group */ | 40 Str name; /* name of the group */ |
41 Entry entry; /* more information about this group */ | 41 Entry entry; /* more information about this group */ |
42 Str serv; /* server the group resides on */ | 42 Str serv; /* server the group resides on */ |
43 Str dsc; /* description of the group */ | 43 Str dsc; /* description of the group */ |
44 char postAllow; /* Posting status */ | 44 char postAllow; /* Posting status */ |
45 time_t lastPost; /* Time last article arrived */ | |
45 GDBM_FILE dbf; | 46 GDBM_FILE dbf; |
46 } grp = { "(no grp)", { 0, 0, 0, 0, 0 }, "", "", ' ', NULL }; | 47 } grp = { "(no grp)", { 0, 0, 0, 0, 0 }, "", "", ' ', (time_t) 0, NULL }; |
47 | 48 |
48 /* | 49 /* |
49 Note: postAllow should really go in Entry. But changing Entry would | 50 Note: postAllow and lastPost should really go in Entry. But |
50 make backwards group file format capability tricky, so it goes | 51 changing Entry would make backwards group file format capability |
51 where it is, and we test the length of the retrieved record to | 52 tricky, so they go where they are, and we test the length of the |
52 determine if it exists. | 53 retrieved record to determine if they exist. |
53 | 54 |
54 Someday if we really change the record format this should be tidied up. | 55 Someday if we really change the record format this should be tidied up. |
55 */ | 56 */ |
56 | 57 |
57 static const char * | 58 static const char * |
109 p = val.dptr + sizeof( grp.entry ); | 110 p = val.dptr + sizeof( grp.entry ); |
110 Utl_cpyStr( grp.serv, p ); | 111 Utl_cpyStr( grp.serv, p ); |
111 p += strlen( p ) + 1; | 112 p += strlen( p ) + 1; |
112 Utl_cpyStr( grp.dsc, p ); | 113 Utl_cpyStr( grp.dsc, p ); |
113 p += strlen( p) + 1; | 114 p += strlen( p) + 1; |
115 | |
116 /* | |
117 * Extension items. Initialise to default first. | |
118 * We default to allowing posting, and the time | |
119 * of the last post being a second before the last | |
120 * access. | |
121 */ | |
122 grp.postAllow = 'y'; | |
123 grp.lastPost = grp.entry.lastAccess - 1; | |
124 | |
114 if ( p - val.dptr < val.dsize ) | 125 if ( p - val.dptr < val.dsize ) |
126 { | |
115 grp.postAllow = p[ 0 ]; | 127 grp.postAllow = p[ 0 ]; |
116 else | 128 p++; |
117 grp.postAllow = 'y'; | 129 if ( p - val.dptr < val.dsize ) |
130 grp.lastPost = *((time_t *)p); | |
131 } | |
132 | |
118 Utl_cpyStr( grp.name, name ); | 133 Utl_cpyStr( grp.name, name ); |
119 free( val.dptr ); | 134 free( val.dptr ); |
120 return TRUE; | 135 return TRUE; |
121 } | 136 } |
122 | 137 |
130 char *p; | 145 char *p; |
131 | 146 |
132 ASSERT( grp.dbf ); | 147 ASSERT( grp.dbf ); |
133 lenServ = strlen( grp.serv ); | 148 lenServ = strlen( grp.serv ); |
134 lenDsc = strlen( grp.dsc ); | 149 lenDsc = strlen( grp.dsc ); |
135 bufLen = sizeof( grp.entry ) + lenServ + lenDsc + 2 + sizeof( char ); | 150 bufLen = |
151 sizeof( grp.entry ) + lenServ + lenDsc + 2 | |
152 + sizeof( char ) + sizeof( time_t ); | |
136 buf = malloc( bufLen ); | 153 buf = malloc( bufLen ); |
137 memcpy( buf, (void *)&grp.entry, sizeof( grp.entry ) ); | 154 memcpy( buf, (void *)&grp.entry, sizeof( grp.entry ) ); |
138 p = (char *)buf + sizeof( grp.entry ); | 155 p = (char *)buf + sizeof( grp.entry ); |
139 strcpy( p, grp.serv ); | 156 strcpy( p, grp.serv ); |
140 p += lenServ + 1; | 157 p += lenServ + 1; |
141 strcpy( p, grp.dsc ); | 158 strcpy( p, grp.dsc ); |
142 p += lenDsc + 1; | 159 p += lenDsc + 1; |
143 p[ 0 ] = grp.postAllow; | 160 p[ 0 ] = grp.postAllow; |
161 p++; | |
162 *((time_t *) p) = grp.lastPost; | |
144 key.dptr = (void *)grp.name; | 163 key.dptr = (void *)grp.name; |
145 key.dsize = strlen( grp.name ) + 1; | 164 key.dsize = strlen( grp.name ) + 1; |
146 val.dptr = buf; | 165 val.dptr = buf; |
147 val.dsize = bufLen; | 166 val.dsize = bufLen; |
148 if ( gdbm_store( grp.dbf, key, val, GDBM_REPLACE ) != 0 ) | 167 if ( gdbm_store( grp.dbf, key, val, GDBM_REPLACE ) != 0 ) |
265 return 0; | 284 return 0; |
266 return grp.postAllow; | 285 return grp.postAllow; |
267 } | 286 } |
268 | 287 |
269 | 288 |
289 time_t | |
290 Grp_lastPostTime( const char *name ) | |
291 { | |
292 if ( ! loadGrp( name ) ) | |
293 return 0; | |
294 return grp.lastPost; | |
295 } | |
296 | |
270 /* Replace group's description (only if value != ""). */ | 297 /* Replace group's description (only if value != ""). */ |
271 void | 298 void |
272 Grp_setDsc( const char *name, const char *value ) | 299 Grp_setDsc( const char *name, const char *value ) |
273 { | 300 { |
274 if ( loadGrp( name ) ) | 301 if ( loadGrp( name ) ) |
303 saveGrp(); | 330 saveGrp(); |
304 } | 331 } |
305 } | 332 } |
306 | 333 |
307 void | 334 void |
308 Grp_setLastAccess( const char *name, int value ) | 335 Grp_setLastAccess( const char *name ) |
309 { | 336 { |
310 if ( loadGrp( name ) ) | 337 if ( loadGrp( name ) ) |
311 { | 338 { |
312 grp.entry.lastAccess = value; | 339 grp.entry.lastAccess = time( NULL ); |
313 saveGrp(); | 340 saveGrp(); |
314 } | 341 } |
315 } | 342 } |
316 | 343 |
317 void | 344 void |
329 { | 356 { |
330 if ( loadGrp( name ) ) | 357 if ( loadGrp( name ) ) |
331 { | 358 { |
332 grp.entry.first = first; | 359 grp.entry.first = first; |
333 grp.entry.last = last; | 360 grp.entry.last = last; |
361 saveGrp(); | |
362 } | |
363 } | |
364 | |
365 void | |
366 Grp_setLastPostTime( const char *name ) | |
367 { | |
368 if ( loadGrp( name ) ) | |
369 { | |
370 grp.lastPost = time( NULL ); | |
334 saveGrp(); | 371 saveGrp(); |
335 } | 372 } |
336 } | 373 } |
337 | 374 |
338 static datum cursor = { NULL, 0 }; | 375 static datum cursor = { NULL, 0 }; |