annotate lib/cache.c @ 900:1e44c7b7f41b

2007-3-22 Brian Masney <masneyb@gftp.org> * configure.in - updated to use automake 1.9. * cvsclean - remove more files when cleaning up the directory. * po/he.po - removed string that gettext was complaining about.
author masneyb
date Sat, 24 Mar 2007 01:32:03 +0000
parents 1808cebed602
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1 /*****************************************************************************/
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2 /* cache.c - contains the cache routines */
885
1808cebed602 2007-3-12 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
3 /* Copyright (C) 1998-2007 Brian Masney <masneyb@gftp.org> */
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
4 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
5 /* This program is free software; you can redistribute it and/or modify */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
6 /* it under the terms of the GNU General Public License as published by */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
7 /* the Free Software Foundation; either version 2 of the License, or */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
8 /* (at your option) any later version. */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
9 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
10 /* This program is distributed in the hope that it will be useful, */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
13 /* GNU General Public License for more details. */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
14 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
15 /* You should have received a copy of the GNU General Public License */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
16 /* along with this program; if not, write to the Free Software */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
18 /*****************************************************************************/
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
19
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
20 #include "gftp.h"
33
c8ec7877432e 2002-10-06 Brian Masney <masneyb@gftp.org>
masneyb
parents: 1
diff changeset
21 static const char cvsid[] = "$Id$";
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
22
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
23 struct gftp_cache_entry_tag
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
24 {
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
25 char *url,
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
26 *file;
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
27 int server_type;
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
28 time_t expiration_date;
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
29
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
30 char *pos1,
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
31 *pos2,
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
32 *pos3;
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
33 };
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
34
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
35 typedef struct gftp_cache_entry_tag gftp_cache_entry;
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
36
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
37
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
38 static int
765
d553d14a2565 2006-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 555
diff changeset
39 gftp_parse_cache_line (gftp_request * request, /*@out@*/ gftp_cache_entry * centry,
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
40 char *line)
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
41 {
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
42 char *pos;
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
43
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
44 memset (centry, 0, sizeof (*centry));
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
45
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
46 if ((pos = strchr (line, '\t')) == NULL || *(pos + 1) == '\0')
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
47 {
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
48 if (request != NULL)
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
49 request->logging_function (gftp_logging_error, request,
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
50 _("Error: Invalid line %s in cache index file\n"),
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
51 line);
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
52 return (-1);
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
53 }
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
54
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
55 centry->pos1 = pos;
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
56 *pos++ = '\0';
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
57 centry->url = line;
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
58 centry->file = pos;
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
59
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
60 if ((pos = strchr (pos, '\t')) == NULL || *(pos + 1) == '\0')
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
61 {
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
62 if (request != NULL)
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
63 request->logging_function (gftp_logging_error, request,
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
64 _("Error: Invalid line %s in cache index file\n"),
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
65 line);
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
66 return (-1);
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
67 }
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
68
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
69 centry->pos2 = pos;
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
70 *pos++ = '\0';
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
71 centry->server_type = strtol (pos, NULL, 10);
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
72
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
73 if ((pos = strchr (pos, '\t')) == NULL || *(pos + 1) == '\0')
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
74 {
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
75 if (request != NULL)
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
76 request->logging_function (gftp_logging_error, request,
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
77 _("Error: Invalid line %s in cache index file\n"),
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
78 line);
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
79 return (-1);
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
80 }
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
81
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
82 centry->pos3 = pos;
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
83 *pos++ = '\0';
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
84 centry->expiration_date = strtol (pos, NULL, 10);
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
85
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
86 return (0);
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
87 }
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
88
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
89
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
90 static void
765
d553d14a2565 2006-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 555
diff changeset
91 gftp_restore_cache_line (gftp_cache_entry * centry)
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
92 {
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
93 if (centry->pos1 != NULL)
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
94 *centry->pos1 = '\t';
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
95
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
96 if (centry->pos2 != NULL)
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
97 *centry->pos2 = '\t';
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
98
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
99 if (centry->pos3 != NULL)
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
100 *centry->pos3 = '\t';
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
101 }
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
102
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
103
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
104 void
765
d553d14a2565 2006-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 555
diff changeset
105 gftp_generate_cache_description (gftp_request * request,
d553d14a2565 2006-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 555
diff changeset
106 char *description,
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
107 size_t len, int ignore_directory)
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
108 {
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
109 g_snprintf (description, len, "%s://%s@%s:%d%s",
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
110 request->url_prefix,
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
111 request->username == NULL ? "" : request->username,
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
112 request->hostname == NULL ? "" : request->hostname,
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
113 request->port,
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
114 ignore_directory || request->directory == NULL ? "" : request->directory);
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
115 }
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
116
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
117
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
118 int
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
119 gftp_new_cache_entry (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
120 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
121 char *cachedir, *tempstr, *temp1str;
325
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 253
diff changeset
122 int cache_fd, fd;
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 253
diff changeset
123 intptr_t cache_ttl;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
124 ssize_t ret;
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
125 time_t t;
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
126
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
127 gftp_lookup_request_option (request, "cache_ttl", &cache_ttl);
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
128 time (&t);
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
129 t += cache_ttl;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
130
555
7f54d0c0edbc 2004-9-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 516
diff changeset
131 cachedir = gftp_expand_path (NULL, BASE_CONF_DIR "/cache");
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
132 if (access (cachedir, F_OK) == -1)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
133 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
134 if (mkdir (cachedir, S_IRUSR | S_IWUSR | S_IXUSR) < 0)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
135 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
136 if (request != NULL)
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
137 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
138 _("Error: Could not make directory %s: %s\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
139 cachedir, g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
140
765
d553d14a2565 2006-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 555
diff changeset
141 g_free (cachedir);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
142 return (-1);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
143 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
144 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
145
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
146 tempstr = g_strdup_printf ("%s/index.db", cachedir);
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
147 if ((fd = gftp_fd_open (request, tempstr, O_WRONLY | O_APPEND | O_CREAT,
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
148 S_IRUSR | S_IWUSR)) == -1)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
149 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
150 g_free (tempstr);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
151 g_free (cachedir);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
152 return (-1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
153 }
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
154
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
155 g_free (tempstr);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
156
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
157 tempstr = g_strdup_printf ("%s/cache.XXXXXX", cachedir);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
158 if ((cache_fd = mkstemp (tempstr)) < 0)
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
159 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
160 g_free (tempstr);
765
d553d14a2565 2006-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 555
diff changeset
161 g_free (cachedir);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
162 if (request != NULL)
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
163 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
164 _("Error: Cannot create temporary file: %s\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
165 g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
166 return (-1);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
167 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
168 g_free (cachedir);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
169
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
170 lseek (fd, 0, SEEK_END);
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
171 temp1str = g_strdup_printf ("%s://%s@%s:%d%s\t%s\t%d\t%ld\n",
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
172 request->url_prefix,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
173 request->username == NULL ? "" : request->username,
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
174 request->hostname == NULL ? "" : request->hostname,
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
175 request->port,
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
176 request->directory == NULL ? "" : request->directory,
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
177 tempstr, request->server_type, t);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
178 g_free (tempstr);
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
179 ret = gftp_fd_write (NULL, temp1str, strlen (temp1str), fd);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
180 g_free (temp1str);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
181
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
182 if (close (fd) != 0 || ret < 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
183 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
184 if (request != NULL)
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
185 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
186 _("Error closing file descriptor: %s\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
187 g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
188
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
189 close (cache_fd);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
190 return (-1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
191 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
192
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
193 return (cache_fd);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
194 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
195
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
196
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
197 int
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
198 gftp_find_cache_entry (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
199 {
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
200 char *indexfile, buf[BUFSIZ], description[BUFSIZ];
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
201 gftp_getline_buffer * rbuf;
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
202 gftp_cache_entry centry;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
203 int indexfd, cachefd;
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
204 time_t now;
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
205
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
206 time (&now);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
207
765
d553d14a2565 2006-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 555
diff changeset
208 *description = '\0';
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
209 gftp_generate_cache_description (request, description, sizeof (description),
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
210 0);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
211
555
7f54d0c0edbc 2004-9-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 516
diff changeset
212 indexfile = gftp_expand_path (NULL, BASE_CONF_DIR "/cache/index.db");
190
876747813a60 2003-6-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 186
diff changeset
213 if ((indexfd = gftp_fd_open (NULL, indexfile, O_RDONLY, 0)) == -1)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
214 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
215 g_free (indexfile);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
216 return (-1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
217 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
218 g_free (indexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
219
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
220 rbuf = NULL;
60
8a9324fb63a4 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
221 while (gftp_get_line (NULL, &rbuf, buf, sizeof (buf), indexfd) > 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
222 {
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
223 if (gftp_parse_cache_line (request, &centry, buf) < 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
224 continue;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
225
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
226 /* See if this entry is still valid... */
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
227 if (centry.expiration_date < now)
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
228 continue;
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
229
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
230 if (strcmp (description, centry.url) == 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
231 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
232 if (close (indexfd) != 0)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
233 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
234 if (request != NULL)
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
235 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
236 _("Error closing file descriptor: %s\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
237 g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
238 return (-1);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
239 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
240
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
241 if ((cachefd = gftp_fd_open (request, centry.file, O_RDONLY, 0)) == -1)
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
242 return (-1);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
243
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
244 if (lseek (cachefd, 0, SEEK_END) == 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
245 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
246 close (cachefd);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
247 return (-1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
248 }
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
249
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
250 if (lseek (cachefd, 0, SEEK_SET) == -1)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
251 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
252 if (request != NULL)
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
253 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
254 _("Error: Cannot seek on file %s: %s\n"),
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
255 centry.file, g_strerror (errno));
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
256
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
257 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
258
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
259 request->server_type = centry.server_type;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
260 return (cachefd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
261 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
262 }
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
263 close (indexfd);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
264 return (-1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
265 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
266
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
267
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
268 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
269 gftp_clear_cache_files (void)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
270 {
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
271 char *indexfile, buf[BUFSIZ];
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
272 gftp_getline_buffer * rbuf;
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
273 gftp_cache_entry centry;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
274 int indexfd;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
275
555
7f54d0c0edbc 2004-9-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 516
diff changeset
276 indexfile = gftp_expand_path (NULL, BASE_CONF_DIR "/cache/index.db");
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
277 if ((indexfd = gftp_fd_open (NULL, indexfile, O_RDONLY, 0)) == -1)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
278 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
279 g_free (indexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
280 return;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
281 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
282
765
d553d14a2565 2006-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 555
diff changeset
283 *buf = '\0';
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
284 rbuf = NULL;
60
8a9324fb63a4 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
285 while (gftp_get_line (NULL, &rbuf, buf, sizeof (buf), indexfd) > 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
286 {
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
287 if (gftp_parse_cache_line (NULL, &centry, buf) < 0)
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
288 continue;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
289
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
290 unlink (centry.file);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
291 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
292
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
293 close (indexfd);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
294 unlink (indexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
295 g_free (indexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
296 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
297
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
298
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
299 void
253
a46c2eef5139 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
300 gftp_delete_cache_entry (gftp_request * request, char *descr,
a46c2eef5139 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
301 int ignore_directory)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
302 {
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
303 char *oldindexfile, *newindexfile, buf[BUFSIZ], description[BUFSIZ];
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
304 int indexfd, newfd, del_entry;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
305 gftp_getline_buffer * rbuf;
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
306 gftp_cache_entry centry;
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 325
diff changeset
307 size_t len;
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
308 time_t now;
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
309
253
a46c2eef5139 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
310 g_return_if_fail (request != NULL || descr != NULL);
a46c2eef5139 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
311
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
312 time (&now);
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
313 if (request != NULL)
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
314 {
765
d553d14a2565 2006-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 555
diff changeset
315 *description = '\0';
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
316 gftp_generate_cache_description (request, description, sizeof (description),
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
317 ignore_directory);
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
318 }
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
319 else if (descr != NULL)
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
320 {
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
321 strncpy (description, descr, sizeof (description));
249
094e83b55cb1 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 222
diff changeset
322 description[sizeof (description) - 1] = '\0';
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
323 }
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
324 else
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
325 return;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
326
555
7f54d0c0edbc 2004-9-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 516
diff changeset
327 oldindexfile = gftp_expand_path (NULL, BASE_CONF_DIR "/cache/index.db");
190
876747813a60 2003-6-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 186
diff changeset
328 if ((indexfd = gftp_fd_open (NULL, oldindexfile, O_RDONLY, 0)) == -1)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
329 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
330 g_free (oldindexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
331 return;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
332 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
333
555
7f54d0c0edbc 2004-9-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 516
diff changeset
334 newindexfile = gftp_expand_path (NULL, BASE_CONF_DIR "/cache/index.db.new");
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
335 if ((newfd = gftp_fd_open (request, newindexfile, O_WRONLY | O_CREAT,
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
336 S_IRUSR | S_IWUSR)) == -1)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
337 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
338 g_free (oldindexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
339 g_free (newindexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
340 return;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
341 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
342
765
d553d14a2565 2006-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 555
diff changeset
343 *buf = '\0';
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
344 rbuf = NULL;
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
345 while (gftp_get_line (NULL, &rbuf, buf, sizeof (buf) - 1, indexfd) > 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
346 {
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
347 if (gftp_parse_cache_line (request, &centry, buf) < 0)
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
348 continue;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
349
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
350 del_entry = 0;
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
351 if (centry.expiration_date < now)
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
352 del_entry = 1;
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
353 else if (ignore_directory)
47
eec25f215772 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
354 {
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
355 if (strncmp (centry.url, description, strlen (description)) == 0)
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
356 del_entry = 1;
47
eec25f215772 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
357 }
eec25f215772 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
358 else
eec25f215772 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
359 {
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
360 if (strcmp (centry.url, description) == 0)
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
361 del_entry = 1;
47
eec25f215772 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
362 }
eec25f215772 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
363
eec25f215772 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
364
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
365 if (del_entry)
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
366 unlink (centry.file);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
367 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
368 {
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
369 /* Make sure we put the tabs back in the line. I do it this way
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
370 so that I don't have to allocate memory again for each line
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
371 as we read it */
765
d553d14a2565 2006-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 555
diff changeset
372 gftp_restore_cache_line (&centry);
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
373
179
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
374 /* Make sure when we call gftp_get_line() that we pass the read size
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
375 as sizeof(buf) - 1 so that we'll have room to put the newline */
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 325
diff changeset
376 len = strlen (buf);
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 325
diff changeset
377 buf[len--] = '\n';
179
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
378
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 325
diff changeset
379 if (gftp_fd_write (NULL, buf, len, newfd) < 0)
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
380 break;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
381 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
382 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
383
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
384 close (indexfd);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
385 close (newfd);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
386
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
387 unlink (oldindexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
388 rename (newindexfile, oldindexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
389
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
390 g_free (oldindexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
391 g_free (newindexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
392 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
393