Mercurial > gftp.yaz
comparison lib/cache.c @ 765:d553d14a2565
2006-7-13 Brian Masney <masneyb@gftp.org>
* lib/cache.c lib/config_file.c lib/fsp.c lib/ftps.c lib/gftp.h
lib/local.c lib/misc.c lib/options.h lib/protocols.c lib/rfc2068.c
lib/rfc959.c lib/sshv2.c - started to add some annotations for splint.
Fixed a few minor warnings from splint.
author | masneyb |
---|---|
date | Fri, 14 Jul 2006 00:34:11 +0000 |
parents | 7f54d0c0edbc |
children | 1808cebed602 |
comparison
equal
deleted
inserted
replaced
764:4ed80df6729d | 765:d553d14a2565 |
---|---|
34 | 34 |
35 typedef struct gftp_cache_entry_tag gftp_cache_entry; | 35 typedef struct gftp_cache_entry_tag gftp_cache_entry; |
36 | 36 |
37 | 37 |
38 static int | 38 static int |
39 gftp_parse_cache_line (gftp_request * request, gftp_cache_entry * centry, | 39 gftp_parse_cache_line (gftp_request * request, /*@out@*/ gftp_cache_entry * centry, |
40 char *line) | 40 char *line) |
41 { | 41 { |
42 char *pos; | 42 char *pos; |
43 | 43 |
44 memset (centry, 0, sizeof (*centry)); | 44 memset (centry, 0, sizeof (*centry)); |
86 return (0); | 86 return (0); |
87 } | 87 } |
88 | 88 |
89 | 89 |
90 static void | 90 static void |
91 gftp_restore_cache_line (gftp_cache_entry * centry, char *line) | 91 gftp_restore_cache_line (gftp_cache_entry * centry) |
92 { | 92 { |
93 if (centry->pos1 != NULL) | 93 if (centry->pos1 != NULL) |
94 *centry->pos1 = '\t'; | 94 *centry->pos1 = '\t'; |
95 | 95 |
96 if (centry->pos2 != NULL) | 96 if (centry->pos2 != NULL) |
100 *centry->pos3 = '\t'; | 100 *centry->pos3 = '\t'; |
101 } | 101 } |
102 | 102 |
103 | 103 |
104 void | 104 void |
105 gftp_generate_cache_description (gftp_request * request, char *description, | 105 gftp_generate_cache_description (gftp_request * request, |
106 char *description, | |
106 size_t len, int ignore_directory) | 107 size_t len, int ignore_directory) |
107 { | 108 { |
108 g_snprintf (description, len, "%s://%s@%s:%d%s", | 109 g_snprintf (description, len, "%s://%s@%s:%d%s", |
109 request->url_prefix, | 110 request->url_prefix, |
110 request->username == NULL ? "" : request->username, | 111 request->username == NULL ? "" : request->username, |
135 if (request != NULL) | 136 if (request != NULL) |
136 request->logging_function (gftp_logging_error, request, | 137 request->logging_function (gftp_logging_error, request, |
137 _("Error: Could not make directory %s: %s\n"), | 138 _("Error: Could not make directory %s: %s\n"), |
138 cachedir, g_strerror (errno)); | 139 cachedir, g_strerror (errno)); |
139 | 140 |
141 g_free (cachedir); | |
140 return (-1); | 142 return (-1); |
141 } | 143 } |
142 } | 144 } |
143 | 145 |
144 tempstr = g_strdup_printf ("%s/index.db", cachedir); | 146 tempstr = g_strdup_printf ("%s/index.db", cachedir); |
154 | 156 |
155 tempstr = g_strdup_printf ("%s/cache.XXXXXX", cachedir); | 157 tempstr = g_strdup_printf ("%s/cache.XXXXXX", cachedir); |
156 if ((cache_fd = mkstemp (tempstr)) < 0) | 158 if ((cache_fd = mkstemp (tempstr)) < 0) |
157 { | 159 { |
158 g_free (tempstr); | 160 g_free (tempstr); |
161 g_free (cachedir); | |
159 if (request != NULL) | 162 if (request != NULL) |
160 request->logging_function (gftp_logging_error, request, | 163 request->logging_function (gftp_logging_error, request, |
161 _("Error: Cannot create temporary file: %s\n"), | 164 _("Error: Cannot create temporary file: %s\n"), |
162 g_strerror (errno)); | 165 g_strerror (errno)); |
163 return (-1); | 166 return (-1); |
200 int indexfd, cachefd; | 203 int indexfd, cachefd; |
201 time_t now; | 204 time_t now; |
202 | 205 |
203 time (&now); | 206 time (&now); |
204 | 207 |
208 *description = '\0'; | |
205 gftp_generate_cache_description (request, description, sizeof (description), | 209 gftp_generate_cache_description (request, description, sizeof (description), |
206 0); | 210 0); |
207 | 211 |
208 indexfile = gftp_expand_path (NULL, BASE_CONF_DIR "/cache/index.db"); | 212 indexfile = gftp_expand_path (NULL, BASE_CONF_DIR "/cache/index.db"); |
209 if ((indexfd = gftp_fd_open (NULL, indexfile, O_RDONLY, 0)) == -1) | 213 if ((indexfd = gftp_fd_open (NULL, indexfile, O_RDONLY, 0)) == -1) |
274 { | 278 { |
275 g_free (indexfile); | 279 g_free (indexfile); |
276 return; | 280 return; |
277 } | 281 } |
278 | 282 |
283 *buf = '\0'; | |
279 rbuf = NULL; | 284 rbuf = NULL; |
280 while (gftp_get_line (NULL, &rbuf, buf, sizeof (buf), indexfd) > 0) | 285 while (gftp_get_line (NULL, &rbuf, buf, sizeof (buf), indexfd) > 0) |
281 { | 286 { |
282 if (gftp_parse_cache_line (NULL, ¢ry, buf) < 0) | 287 if (gftp_parse_cache_line (NULL, ¢ry, buf) < 0) |
283 continue; | 288 continue; |
305 g_return_if_fail (request != NULL || descr != NULL); | 310 g_return_if_fail (request != NULL || descr != NULL); |
306 | 311 |
307 time (&now); | 312 time (&now); |
308 if (request != NULL) | 313 if (request != NULL) |
309 { | 314 { |
315 *description = '\0'; | |
310 gftp_generate_cache_description (request, description, sizeof (description), | 316 gftp_generate_cache_description (request, description, sizeof (description), |
311 ignore_directory); | 317 ignore_directory); |
312 } | 318 } |
313 else if (descr != NULL) | 319 else if (descr != NULL) |
314 { | 320 { |
332 g_free (oldindexfile); | 338 g_free (oldindexfile); |
333 g_free (newindexfile); | 339 g_free (newindexfile); |
334 return; | 340 return; |
335 } | 341 } |
336 | 342 |
343 *buf = '\0'; | |
337 rbuf = NULL; | 344 rbuf = NULL; |
338 while (gftp_get_line (NULL, &rbuf, buf, sizeof (buf) - 1, indexfd) > 0) | 345 while (gftp_get_line (NULL, &rbuf, buf, sizeof (buf) - 1, indexfd) > 0) |
339 { | 346 { |
340 if (gftp_parse_cache_line (request, ¢ry, buf) < 0) | 347 if (gftp_parse_cache_line (request, ¢ry, buf) < 0) |
341 continue; | 348 continue; |
360 else | 367 else |
361 { | 368 { |
362 /* Make sure we put the tabs back in the line. I do it this way | 369 /* Make sure we put the tabs back in the line. I do it this way |
363 so that I don't have to allocate memory again for each line | 370 so that I don't have to allocate memory again for each line |
364 as we read it */ | 371 as we read it */ |
365 gftp_restore_cache_line (¢ry, buf); | 372 gftp_restore_cache_line (¢ry); |
366 | 373 |
367 /* Make sure when we call gftp_get_line() that we pass the read size | 374 /* Make sure when we call gftp_get_line() that we pass the read size |
368 as sizeof(buf) - 1 so that we'll have room to put the newline */ | 375 as sizeof(buf) - 1 so that we'll have room to put the newline */ |
369 len = strlen (buf); | 376 len = strlen (buf); |
370 buf[len--] = '\n'; | 377 buf[len--] = '\n'; |