annotate lib/cache.c @ 485:7334a74db6f6

2004-6-15 Brian Masney <masneyb@gftp.org> * lib/protocols.c - added supported for multiline VMS directory listings. Also, parse the date correctly for single line VMS directory listings * lib/gftp.h lib/local.c lib/rfc2068.c lib/rfc959.c lib/sshv.c - added function pointer get_next_dirlist_line to gftp_request structure. This will retrieve the next line of input for the directory listing. This is only implemented in the FTP protocol at the moment. It shouldn't be needed in the other protocols
author masneyb
date Wed, 16 Jun 2004 02:57:02 +0000
parents 075f89b4395c
children fbb5a02beddb
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 */
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
3 /* Copyright (C) 1998-2003 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
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
39 gftp_parse_cache_line (gftp_request * request, gftp_cache_entry * centry,
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
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
91 gftp_restore_cache_line (gftp_cache_entry * centry, char *line)
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
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
105 gftp_generate_cache_description (gftp_request * request, char *description,
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
106 size_t len, int ignore_directory)
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
107 {
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
108 g_snprintf (description, len, "%s://%s@%s:%d%s",
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
109 request->url_prefix,
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
110 request->username == NULL ? "" : request->username,
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
111 request->hostname == NULL ? "" : request->hostname,
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
112 request->port,
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
113 ignore_directory || request->directory == NULL ? "" : request->directory);
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
114 }
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
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
117 int
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
118 gftp_new_cache_entry (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
119 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
120 char *cachedir, *tempstr, *temp1str;
325
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 253
diff changeset
121 int cache_fd, fd;
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 253
diff changeset
122 intptr_t cache_ttl;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
123 ssize_t ret;
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
124 time_t t;
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
125
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
126 gftp_lookup_request_option (request, "cache_ttl", &cache_ttl);
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
127 time (&t);
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
128 t += cache_ttl;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
129
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
130 cachedir = expand_path (BASE_CONF_DIR "/cache");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
131 if (access (cachedir, F_OK) == -1)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
132 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
133 if (mkdir (cachedir, S_IRUSR | S_IWUSR | S_IXUSR) < 0)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
134 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
135 if (request != NULL)
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
136 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
137 _("Error: Could not make directory %s: %s\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
138 cachedir, g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
139
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
140 return (-1);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
141 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
142 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
143
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
144 tempstr = g_strdup_printf ("%s/index.db", cachedir);
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
145 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
146 S_IRUSR | S_IWUSR)) == -1)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
147 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
148 g_free (tempstr);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
149 g_free (cachedir);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
150 return (-1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
151 }
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
152
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
153 g_free (tempstr);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
154
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
155 tempstr = g_strdup_printf ("%s/cache.XXXXXX", cachedir);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
156 if ((cache_fd = mkstemp (tempstr)) < 0)
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
157 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
158 g_free (tempstr);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
159 if (request != NULL)
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
160 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
161 _("Error: Cannot create temporary file: %s\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
162 g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
163 return (-1);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
164 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
165 g_free (cachedir);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
166
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
167 lseek (fd, 0, SEEK_END);
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
168 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
169 request->url_prefix,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
170 request->username == NULL ? "" : request->username,
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
171 request->hostname == NULL ? "" : request->hostname,
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
172 request->port,
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
173 request->directory == NULL ? "" : request->directory,
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
174 tempstr, request->server_type, t);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
175 g_free (tempstr);
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
176 ret = gftp_fd_write (NULL, temp1str, strlen (temp1str), fd);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
177 g_free (temp1str);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
178
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
179 if (close (fd) != 0 || ret < 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
180 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
181 if (request != NULL)
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
182 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
183 _("Error closing file descriptor: %s\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
184 g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
185
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
186 close (cache_fd);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
187 return (-1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
188 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
189
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
190 return (cache_fd);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
191 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
192
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
193
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
194 int
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
195 gftp_find_cache_entry (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
196 {
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
197 char *indexfile, buf[BUFSIZ], description[BUFSIZ];
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
198 gftp_getline_buffer * rbuf;
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
199 gftp_cache_entry centry;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
200 int indexfd, cachefd;
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
201 time_t now;
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
202
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
203 time (&now);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
204
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
205 gftp_generate_cache_description (request, description, sizeof (description),
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
206 0);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
207
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
208 indexfile = expand_path (BASE_CONF_DIR "/cache/index.db");
190
876747813a60 2003-6-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 186
diff changeset
209 if ((indexfd = gftp_fd_open (NULL, indexfile, O_RDONLY, 0)) == -1)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
210 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
211 g_free (indexfile);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
212 return (-1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
213 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
214 g_free (indexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
215
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
216 rbuf = NULL;
60
8a9324fb63a4 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
217 while (gftp_get_line (NULL, &rbuf, buf, sizeof (buf), indexfd) > 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
218 {
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
219 if (gftp_parse_cache_line (request, &centry, buf) < 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
220 continue;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
221
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
222 /* See if this entry is still valid... */
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
223 if (centry.expiration_date < now)
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
224 continue;
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
225
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
226 if (strcmp (description, centry.url) == 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
227 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
228 if (close (indexfd) != 0)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
229 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
230 if (request != NULL)
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
231 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
232 _("Error closing file descriptor: %s\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
233 g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
234 return (-1);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
235 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
236
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
237 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
238 return (-1);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
239
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
240 if (lseek (cachefd, 0, SEEK_END) == 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
241 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
242 close (cachefd);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
243 return (-1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
244 }
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
245
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
246 if (lseek (cachefd, 0, SEEK_SET) == -1)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
247 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
248 if (request != NULL)
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
249 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
250 _("Error: Cannot seek on file %s: %s\n"),
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
251 centry.file, g_strerror (errno));
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
252
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
253 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
254
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
255 request->server_type = centry.server_type;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
256 return (cachefd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
257 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
258 }
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
259 close (indexfd);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
260 return (-1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
261 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
262
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
263
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
264 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
265 gftp_clear_cache_files (void)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
266 {
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
267 char *indexfile, buf[BUFSIZ];
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
268 gftp_getline_buffer * rbuf;
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
269 gftp_cache_entry centry;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
270 int indexfd;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
271
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
272 indexfile = expand_path (BASE_CONF_DIR "/cache/index.db");
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
273 if ((indexfd = gftp_fd_open (NULL, indexfile, O_RDONLY, 0)) == -1)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
274 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
275 g_free (indexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
276 return;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
277 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
278
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
279 rbuf = NULL;
60
8a9324fb63a4 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
280 while (gftp_get_line (NULL, &rbuf, buf, sizeof (buf), indexfd) > 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
281 {
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
282 if (gftp_parse_cache_line (NULL, &centry, buf) < 0)
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
283 continue;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
284
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
285 unlink (centry.file);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
286 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
287
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
288 close (indexfd);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
289 unlink (indexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
290 g_free (indexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
291 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
292
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
293
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
294 void
253
a46c2eef5139 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
295 gftp_delete_cache_entry (gftp_request * request, char *descr,
a46c2eef5139 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
296 int ignore_directory)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
297 {
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
298 char *oldindexfile, *newindexfile, buf[BUFSIZ], description[BUFSIZ];
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
299 gftp_getline_buffer * rbuf;
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
300 gftp_cache_entry centry;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
301 int indexfd, newfd;
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 325
diff changeset
302 size_t len;
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
303 time_t now;
47
eec25f215772 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
304 int remove;
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
305
253
a46c2eef5139 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
306 g_return_if_fail (request != NULL || descr != NULL);
a46c2eef5139 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
307
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
308 time (&now);
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
309 if (request != NULL)
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
310 {
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
311 gftp_generate_cache_description (request, description, sizeof (description),
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
312 ignore_directory);
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
313 }
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
314 else if (descr != NULL)
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
315 {
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
316 strncpy (description, descr, sizeof (description));
249
094e83b55cb1 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 222
diff changeset
317 description[sizeof (description) - 1] = '\0';
182
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
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
320 return;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
321
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
322 oldindexfile = expand_path (BASE_CONF_DIR "/cache/index.db");
190
876747813a60 2003-6-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 186
diff changeset
323 if ((indexfd = gftp_fd_open (NULL, oldindexfile, O_RDONLY, 0)) == -1)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
324 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
325 g_free (oldindexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
326 return;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
327 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
328
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
329 newindexfile = expand_path (BASE_CONF_DIR "/cache/index.db.new");
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
330 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
331 S_IRUSR | S_IWUSR)) == -1)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
332 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
333 g_free (oldindexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
334 g_free (newindexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
335 return;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
336 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
337
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
338 rbuf = NULL;
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
339 while (gftp_get_line (NULL, &rbuf, buf, sizeof (buf) - 1, indexfd) > 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
340 {
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
341 if (gftp_parse_cache_line (request, &centry, buf) < 0)
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
342 continue;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
343
47
eec25f215772 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
344 remove = 0;
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
345 if (centry.expiration_date < now)
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
346 remove = 1;
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 190
diff changeset
347 else if (ignore_directory)
47
eec25f215772 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
348 {
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
349 if (strncmp (centry.url, description, strlen (description)) == 0)
47
eec25f215772 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
350 remove = 1;
eec25f215772 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
351 }
eec25f215772 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
352 else
eec25f215772 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
353 {
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
354 if (strcmp (centry.url, description) == 0)
47
eec25f215772 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
355 remove = 1;
eec25f215772 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
356 }
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
eec25f215772 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
359 if (remove)
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
360 unlink (centry.file);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
361 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
362 {
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
363 /* 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
364 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
365 as we read it */
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
366 gftp_restore_cache_line (&centry, buf);
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
367
179
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
368 /* 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
369 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
370 len = strlen (buf);
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 325
diff changeset
371 buf[len--] = '\n';
179
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
372
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 325
diff changeset
373 if (gftp_fd_write (NULL, buf, len, newfd) < 0)
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
374 break;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
375 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
376 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
377
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
378 close (indexfd);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 47
diff changeset
379 close (newfd);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
380
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
381 unlink (oldindexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
382 rename (newindexfile, oldindexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
383
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
384 g_free (oldindexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
385 g_free (newindexfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
386 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
387