annotate lib/cache.c @ 323:18e3b7f4ae01

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