Mercurial > noffle
comparison src/request.c @ 124:cfad9678e286 noffle
[svn] Applied patch from M.Nalis:
Modify Req_add() to append to requested/news.serv.er file each MsgID (and
do not clean dirty flag, because otherwise writeRequestfile() would nuke us
when overwriting file!).
author | enz |
---|---|
date | Sat, 22 Jul 2000 10:04:20 +0100 |
parents | 125d79c9e586 |
children | fed1334d766b |
comparison
equal
deleted
inserted
replaced
123:ec190bad201b | 124:cfad9678e286 |
---|---|
1 /* | 1 /* |
2 request.c | 2 request.c |
3 | 3 |
4 Collection of articles that are marked for download. | 4 Collection of articles that are marked for download. |
5 | 5 |
6 $Id: request.c 60 2000-05-09 22:28:38Z uh1763 $ | 6 $Id: request.c 178 2000-07-22 09:04:20Z enz $ |
7 */ | 7 */ |
8 | 8 |
9 #if HAVE_CONFIG_H | 9 #if HAVE_CONFIG_H |
10 #include <config.h> | 10 #include <config.h> |
11 #endif | 11 #endif |
63 /* local functions */ | 63 /* local functions */ |
64 static Reqserv* newReqserv (const char* serv); | 64 static Reqserv* newReqserv (const char* serv); |
65 static Bool getReqserv (const char* serv, Reqserv** rsz); | 65 static Bool getReqserv (const char* serv, Reqserv** rsz); |
66 static void fileRequest (Str file, const char *serv); | 66 static void fileRequest (Str file, const char *serv); |
67 static char** searchMsgId (const Reqserv * rs, const char *msgId); | 67 static char** searchMsgId (const Reqserv * rs, const char *msgId); |
68 static void storeMsgId (Reqserv* rs, const char* msgId); | 68 static Bool storeMsgId (Reqserv* rs, const char* msgId); |
69 static Bool readRequestfile (const char* serv, Reqserv** rsz); | 69 static Bool readRequestfile (const char* serv, Reqserv** rsz); |
70 static time_t get_mtime (const char* serv); | 70 static time_t get_mtime (const char* serv); |
71 | 71 |
72 /* read modification time of request file */ | 72 /* read modification time of request file */ |
73 static time_t get_mtime(const char* serv) | 73 static time_t get_mtime(const char* serv) |
176 return FALSE; | 176 return FALSE; |
177 return searchMsgId(rs, msgId) ? TRUE : FALSE; | 177 return searchMsgId(rs, msgId) ? TRUE : FALSE; |
178 } | 178 } |
179 | 179 |
180 | 180 |
181 static void storeMsgId(Reqserv* rs, const char* msgId) | 181 static Bool storeMsgId(Reqserv* rs, const char* msgId) |
182 { | 182 { |
183 char* msgid; | 183 char* msgid; |
184 | 184 |
185 if (searchMsgId(rs, msgId)) | 185 if (searchMsgId(rs, msgId)) |
186 /* already recorded */ | 186 /* already recorded */ |
187 return; | 187 return FALSE; |
188 | 188 |
189 msgid = strcpy(malloc(strlen(msgId)+1), msgId); | 189 msgid = strcpy(malloc(strlen(msgId)+1), msgId); |
190 | 190 |
191 if (rs->reql_length >= rs->reql_capacity) { | 191 if (rs->reql_length >= rs->reql_capacity) { |
192 int c1 = rs->reql_capacity*2 + 10; | 192 int c1 = rs->reql_capacity*2 + 10; |
194 rs->reql_capacity = c1; | 194 rs->reql_capacity = c1; |
195 } | 195 } |
196 | 196 |
197 *(rs->reql + rs->reql_length++) = msgid; | 197 *(rs->reql + rs->reql_length++) = msgid; |
198 rs->dirty = TRUE; | 198 rs->dirty = TRUE; |
199 return TRUE; | |
200 } | |
201 | |
202 static Bool | |
203 appRequest (Reqserv* rs, const char *msgId) | |
204 { | |
205 Str filename; | |
206 FILE* file; | |
207 | |
208 fileRequest(filename, rs->serv); | |
209 Log_dbg("appending to request file %s", filename); | |
210 | |
211 if (Log_check((file = fopen(filename, "a")) != 0, | |
212 "could not open %s for appending: %s", | |
213 filename, strerror(errno))) | |
214 return FALSE; | |
215 | |
216 if (Log_check( fputs(msgId, file) != EOF | |
217 && fputs("\n", file) != EOF, | |
218 "write error: %s", strerror(errno))) | |
219 return FALSE; | |
220 | |
221 if (Log_check(fclose(file) != EOF, | |
222 "could not close %s properly: %s\n", | |
223 filename, strerror(errno))) | |
224 return FALSE; | |
225 | |
226 return TRUE; | |
199 } | 227 } |
200 | 228 |
201 | 229 |
202 /* Add request for message "msgIg" from server "serv". Return TRUE iff | 230 /* Add request for message "msgIg" from server "serv". Return TRUE iff |
203 successful. | 231 successful. |
208 ASSERT( is_open ); | 236 ASSERT( is_open ); |
209 Log_dbg( "Marking %s on %s for download", msgId, serv ); | 237 Log_dbg( "Marking %s on %s for download", msgId, serv ); |
210 | 238 |
211 if (getReqserv(serv, &rs) == FALSE) | 239 if (getReqserv(serv, &rs) == FALSE) |
212 return FALSE; | 240 return FALSE; |
213 storeMsgId(rs, msgId); | 241 if (storeMsgId(rs, msgId) == FALSE) /* already recorded */ |
214 return TRUE; | 242 return TRUE; |
243 return appRequest(rs, msgId); | |
215 } | 244 } |
216 | 245 |
217 static Bool | 246 static Bool |
218 readLn( Str line, FILE* f ) | 247 readLn( Str line, FILE* f ) |
219 { | 248 { |