annotate lib/local.c @ 320:853981bbd4d7

2003-11-30 Brian Masney <masneyb@gftp.org> * src/gtk/transfer.c - shows status information in title bar. (patch from Jamil Geor <jamil_geor@yahoo.co.nz>, cleaned up by me some) * lib/options.h - added show_trans_in_title option. 2003-11-25 Brian Masney <masneyb@gftp.org> * lib/misc.c (gftp_locale_init) - call bindtextdomain() so that the directory is setup properly * lib/misc.c lib/gftp.h lib/config_file.c - move copyfile() to config_file.c and declare it to be static. On the destination file, set the flag O_EXCL
author masneyb
date Sun, 30 Nov 2003 19:35:24 +0000
parents cc2eeb30b793
children eedc2c5727fa
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 /* local.c - functions that will use the local system */
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
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: 19
diff changeset
21 static const char cvsid[] = "$Id$";
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
22
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
23 typedef struct local_protocol_data_tag
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
24 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
25 DIR *dir;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
26 GHashTable *userhash, *grouphash;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
27 } local_protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
28
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
29
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
30 static void
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
31 local_remove_key (gpointer key, gpointer value, gpointer user_data)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
32 {
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
33 g_free (value);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
34 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
35
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
36
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
37 static void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
38 local_destroy (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
39 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
40 local_protocol_data * lpd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
41
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
42 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
43 g_return_if_fail (request->protonum == GFTP_LOCAL_NUM);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
44
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
45 lpd = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
46 g_hash_table_foreach (lpd->userhash, local_remove_key, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
47 g_hash_table_destroy (lpd->userhash);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
48 g_hash_table_foreach (lpd->grouphash, local_remove_key, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
49 g_hash_table_destroy (lpd->grouphash);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
50 lpd->userhash = lpd->grouphash = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
51 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
52
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
53
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
54 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
55 local_connect (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
56 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
57 char tempstr[PATH_MAX];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
58
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
59 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
60 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
61
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
62 if (request->directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
63 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
64 if (chdir (request->directory) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
65 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
66 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
67 _("Could not change local directory to %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
68 request->directory, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
69 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
70 g_free (request->directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
71 request->directory = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
72 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
73
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
74 if (getcwd (tempstr, sizeof (tempstr)) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
75 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
76 tempstr[sizeof (tempstr) - 1] = '\0';
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
77 request->directory = g_strdup (tempstr);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
78 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
79 else
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
80 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
81 _("Could not get current working directory: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
82 g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
83
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
84 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
85 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
86
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
87
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
88 static void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
89 local_disconnect (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
90 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
91 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
92 g_return_if_fail (request->protonum == GFTP_LOCAL_NUM);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
93
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
94 if (request->datafd != -1)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
95 {
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
96 if (close (request->datafd) == -1)
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
97 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
98 _("Error closing file descriptor: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
99 g_strerror (errno));
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
100 request->datafd = -1;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
101 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
102 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
103
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
104
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
105 static off_t
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
106 local_get_file (gftp_request * request, const char *filename, int fd,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
107 off_t startsize)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
108 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
109 off_t size;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
110 int flags;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
111
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
112 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
113 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
114 g_return_val_if_fail (filename != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
115
66
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
116 if (fd <= 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
117 {
7
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
118 flags = O_RDONLY;
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
119 #if defined (_LARGEFILE_SOURCE)
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
120 flags |= O_LARGEFILE;
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
121 #endif
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
122
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
123 if ((request->datafd = gftp_fd_open (request, filename, flags, 0)) == -1)
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
124 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
125 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
126 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
127 request->datafd = fd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
128
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
129 if ((size = lseek (request->datafd, 0, SEEK_END)) == -1)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
130 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
131 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
132 _("Error: Cannot seek on file %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
133 filename, g_strerror (errno));
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
134 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
135 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
136 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
137
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
138 if (lseek (request->datafd, startsize, SEEK_SET) == -1)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
139 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
140 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
141 _("Error: Cannot seek on file %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
142 filename, g_strerror (errno));
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
143 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
144 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
145 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
146
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
147 return (size);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
148 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
149
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
150
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
151 static int
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
152 local_put_file (gftp_request * request, const char *filename, int fd,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
153 off_t startsize, off_t totalsize)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
154 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
155 int flags;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
156
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
157 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
158 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
159 g_return_val_if_fail (filename != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
160
66
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
161 if (fd <= 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
162 {
7
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
163 flags = O_WRONLY | O_CREAT;
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
164 if (startsize > 0)
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
165 flags |= O_APPEND;
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
166 #if defined (_LARGEFILE_SOURCE)
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
167 flags |= O_LARGEFILE;
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
168 #endif
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
169
244
afbbc72b73e2 2003-8-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 186
diff changeset
170 if ((request->datafd = gftp_fd_open (request, filename, flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1)
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
171 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
172 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
173 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
174 request->datafd = fd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
175
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
176 if (ftruncate (request->datafd, startsize) == -1)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
177 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
178 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
179 _("Error: Cannot truncate local file %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
180 filename, g_strerror (errno));
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
181 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
182 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
183 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
184
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
185 if (lseek (request->datafd, startsize, SEEK_SET) == -1)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
186 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
187 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
188 _("Error: Cannot seek on file %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
189 filename, g_strerror (errno));
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
190 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
191 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
192 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
193 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
194 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
195
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
196
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
197 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
198 local_end_transfer (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
199 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
200 local_protocol_data * lpd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
201
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
202 lpd = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
203 if (lpd->dir)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
204 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
205 closedir (lpd->dir);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
206 lpd->dir = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
207 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
208
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
209 if (request->datafd > 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
210 {
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
211 if (close (request->datafd) == -1)
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
212 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
213 _("Error closing file descriptor: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
214 g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
215
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
216 request->datafd = -1;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
217 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
218
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
219 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
220 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
221
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
222
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
223 static char *
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
224 make_text_mode (mode_t mode)
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
225 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
226 char *str;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
227
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
228 str = g_malloc0 (11);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
229
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
230 str[0] = '?';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
231 if (S_ISREG (mode))
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
232 str[0] = '-';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
233
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
234 if (S_ISLNK (mode))
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
235 str[0] = 'l';
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
236
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
237 if (S_ISBLK (mode))
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
238 str[0] = 'b';
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
239
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
240 if (S_ISCHR (mode))
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
241 str[0] = 'c';
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
242
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
243 if (S_ISFIFO (mode))
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
244 str[0] = 'p';
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
245
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
246 if (S_ISSOCK (mode))
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
247 str[0] = 's';
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
248
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
249 if (S_ISDIR (mode))
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
250 str[0] = 'd';
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
251
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
252 str[1] = mode & S_IRUSR ? 'r' : '-';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
253 str[2] = mode & S_IWUSR ? 'w' : '-';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
254
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
255 if ((mode & S_ISUID) && (mode & S_IXUSR))
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
256 str[3] = 's';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
257 else if (mode & S_ISUID)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
258 str[3] = 'S';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
259 else if (mode & S_IXUSR)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
260 str[3] = 'x';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
261 else
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
262 str[3] = '-';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
263
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
264 str[4] = mode & S_IRGRP ? 'r' : '-';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
265 str[5] = mode & S_IWGRP ? 'w' : '-';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
266
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
267 if ((mode & S_ISGID) && (mode & S_IXGRP))
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
268 str[6] = 's';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
269 else if (mode & S_ISGID)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
270 str[6] = 'S';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
271 else if (mode & S_IXGRP)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
272 str[6] = 'x';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
273 else
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
274 str[6] = '-';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
275
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
276 str[7] = mode & S_IROTH ? 'r' : '-';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
277 str[8] = mode & S_IWOTH ? 'w' : '-';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
278
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
279 if ((mode & S_ISVTX) && (mode & S_IXOTH))
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
280 str[9] = 't';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
281 else if (mode & S_ISVTX)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
282 str[9] = 'T';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
283 else if (mode & S_IXOTH)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
284 str[9] = 'x';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
285 else
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
286 str[9] = '-';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
287 return (str);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
288 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
289
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
290
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
291 static int
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
292 local_get_next_file (gftp_request * request, gftp_file * fle, int fd)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
293 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
294 local_protocol_data * lpd;
255
2ad324cf4930 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 253
diff changeset
295 struct stat st, fst;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
296 struct dirent *dirp;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
297 char *user, *group;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
298 struct passwd *pw;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
299 struct group *gr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
300
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
301 /* the struct passwd and struct group are not thread safe. But,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
302 we're ok here because I have threading turned off for the local
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
303 protocol (see use_threads in local_init above) */
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
304 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
305 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
306 g_return_val_if_fail (fle != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
307
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
308 lpd = request->protocol_data;
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
309
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
310 g_return_val_if_fail (lpd != NULL, GFTP_EFATAL);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
311
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
312 memset (fle, 0, sizeof (*fle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
313
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
314 if ((dirp = readdir (lpd->dir)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
315 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
316 closedir (lpd->dir);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
317 lpd->dir = NULL;
274
4610d25d4abb 2003-9-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 255
diff changeset
318 return (GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
319 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
320
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
321 fle->file = g_strdup (dirp->d_name);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
322 if (lstat (fle->file, &st) != 0)
274
4610d25d4abb 2003-9-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 255
diff changeset
323 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
324
255
2ad324cf4930 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 253
diff changeset
325 if (stat (fle->file, &fst) != 0)
274
4610d25d4abb 2003-9-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 255
diff changeset
326 return (GFTP_ERETRYABLE);
255
2ad324cf4930 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 253
diff changeset
327
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
328 if ((user = g_hash_table_lookup (lpd->userhash,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
329 GUINT_TO_POINTER(st.st_uid))) != NULL)
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
330 fle->user = g_strdup (user);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
331 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
332 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
333 if ((pw = getpwuid (st.st_uid)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
334 fle->user = g_strdup_printf ("%u", st.st_uid);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
335 else
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
336 fle->user = g_strdup (pw->pw_name);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
337
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
338 user = g_strdup (fle->user);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
339 g_hash_table_insert (lpd->userhash, GUINT_TO_POINTER (st.st_uid), user);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
340 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
341
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
342 if ((group = g_hash_table_lookup (lpd->grouphash,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
343 GUINT_TO_POINTER(st.st_gid))) != NULL)
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
344 fle->group = g_strdup (group);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
345 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
346 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
347 if ((gr = getgrgid (st.st_gid)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
348 fle->group = g_strdup_printf ("%u", st.st_gid);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
349 else
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
350 fle->group = g_strdup (gr->gr_name);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
351
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
352 group = g_strdup (fle->group);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
353 g_hash_table_insert (lpd->grouphash, GUINT_TO_POINTER (st.st_gid), group);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
354 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
355
294
4747f621b79b 2003-10-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 274
diff changeset
356 fle->attribs = make_text_mode (fst.st_mode);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
357 fle->datetime = st.st_mtime;
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
358
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
359 if ((fle->attribs[0] == 'b' || fle->attribs[0] == 'u' ||
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
360 fle->attribs[0] == 'c'))
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
361 fle->size = (off_t) st.st_rdev;
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
362 else
294
4747f621b79b 2003-10-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 274
diff changeset
363 fle->size = fst.st_size;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
364
255
2ad324cf4930 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 253
diff changeset
365 fle->isdir = S_ISDIR (fst.st_mode);
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
366 fle->islink = S_ISLNK (st.st_mode);
255
2ad324cf4930 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 253
diff changeset
367 fle->isexe = (fst.st_mode & S_IXUSR) ||
2ad324cf4930 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 253
diff changeset
368 (fst.st_mode & S_IXGRP) ||
2ad324cf4930 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 253
diff changeset
369 (fst.st_mode & S_IXOTH);
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
370
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
371 return (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
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
375 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
376 local_list_files (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
377 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
378 local_protocol_data *lpd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
379 char *tempstr;
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
380 int freeit;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
381
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
382 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
383 g_return_val_if_fail (request->directory != NULL, GFTP_EFATAL);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
384 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, GFTP_EFATAL);
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
385
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
386 lpd = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
387
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
388 g_return_val_if_fail (lpd != NULL, GFTP_EFATAL);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
389
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
390 if (request->directory[strlen (request->directory) - 1] != '/')
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
391 {
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
392 tempstr = g_strconcat (request->directory, "/", NULL);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
393 freeit = 1;
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
394 }
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
395 else
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
396 {
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
397 tempstr = request->directory;
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
398 freeit = 0;
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
399 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
400
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
401 if ((lpd->dir = opendir (tempstr)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
402 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
403 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
404 _("Could not get local directory listing %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
405 tempstr, g_strerror (errno));
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
406 if (freeit)
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
407 g_free (tempstr);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
408 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
409 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
410
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
411 if (freeit)
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
412 g_free (tempstr);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
413
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
414 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
415 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
416
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
417
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
418 static off_t
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
419 local_get_file_size (gftp_request * request, const char *filename)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
420 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
421 struct stat st;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
422
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
423 if (stat (filename, &st) == -1)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
424 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
425 return (st.st_size);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
426 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
427
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
428
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
429 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
430 local_chdir (gftp_request * request, const char *directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
431 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
432 char tempstr[255];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
433
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
434 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
435 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
436 g_return_val_if_fail (directory != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
437
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
438 if (chdir (directory) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
439 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
440 request->logging_function (gftp_logging_misc, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
441 _("Successfully changed local directory to %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
442 directory);
136
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
443
253
a46c2eef5139 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
444 if (request->directory != directory)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
445 {
253
a46c2eef5139 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
446 if (getcwd (tempstr, sizeof (tempstr)) == NULL)
a46c2eef5139 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
447 {
a46c2eef5139 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
448 request->logging_function (gftp_logging_error, request,
a46c2eef5139 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
449 _("Could not get current working directory: %s\n"),
a46c2eef5139 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
450 g_strerror (errno));
a46c2eef5139 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
451 return (GFTP_ERETRYABLE);
a46c2eef5139 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
452 }
a46c2eef5139 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
453
a46c2eef5139 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
454 if (request->directory)
a46c2eef5139 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
455 g_free (request->directory);
a46c2eef5139 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
456 request->directory = g_strdup (tempstr);
136
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
457 }
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
458
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
459 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
460 }
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
461 else
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
462 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
463 request->logging_function (gftp_logging_error, request,
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
464 _("Could not change local directory to %s: %s\n"),
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
465 directory, g_strerror (errno));
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
466 return (GFTP_ERETRYABLE);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
467 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
468 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
469
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
470
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
471 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
472 local_rmdir (gftp_request * request, const char *directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
473 {
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
474 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
475 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
476 g_return_val_if_fail (directory != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
477
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
478 if (rmdir (directory) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
479 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
480 request->logging_function (gftp_logging_misc, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
481 _("Successfully removed %s\n"), directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
482 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
483 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
484 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
485 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
486 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
487 _("Error: Could not remove directory %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
488 directory, g_strerror (errno));
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
489 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
490 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
491 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
492
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
493
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
494 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
495 local_rmfile (gftp_request * request, const char *file)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
496 {
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
497 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
498 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
499 g_return_val_if_fail (file != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
500
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
501 if (unlink (file) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
502 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
503 request->logging_function (gftp_logging_misc, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
504 _("Successfully removed %s\n"), file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
505 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
506 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
507 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
508 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
509 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
510 _("Error: Could not remove file %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
511 file, g_strerror (errno));
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
512 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
513 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
514 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
515
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
516
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
517 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
518 local_mkdir (gftp_request * request, const char *directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
519 {
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
520 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
521 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
522 g_return_val_if_fail (directory != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
523
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
524 if (mkdir (directory, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
525 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
526 request->logging_function (gftp_logging_misc, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
527 _("Successfully made directory %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
528 directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
529 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
530 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
531 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
532 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
533 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
534 _("Error: Could not make directory %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
535 directory, g_strerror (errno));
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
536 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
537 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
538 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
539
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
540
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
541 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
542 local_rename (gftp_request * request, const char *oldname,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
543 const char *newname)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
544 {
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
545 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
546 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
547 g_return_val_if_fail (oldname != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
548 g_return_val_if_fail (newname != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
549
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
550 if (rename (oldname, newname) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
551 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
552 request->logging_function (gftp_logging_misc, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
553 _("Successfully renamed %s to %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
554 oldname, newname);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
555 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
556 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
557 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
558 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
559 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
560 _("Error: Could not rename %s to %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
561 oldname, newname, g_strerror (errno));
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
562 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
563 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
564 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
565
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
566
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
567 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
568 local_chmod (gftp_request * request, const char *file, int mode)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
569 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
570 char buf[10];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
571 int newmode;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
572
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
573 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
574 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
575 g_return_val_if_fail (file != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
576
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
577 g_snprintf (buf, sizeof (buf), "%d", mode);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
578 newmode = strtol (buf, NULL, 8);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
579
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
580 if (chmod (file, newmode) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
581 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
582 request->logging_function (gftp_logging_misc, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
583 _("Successfully changed mode of %s to %d\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
584 file, mode);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
585 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
586 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
587 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
588 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
589 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
590 _("Error: Could not change mode of %s to %d: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
591 file, mode, g_strerror (errno));
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
592 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
593 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
594 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
595
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
596
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
597 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
598 local_set_file_time (gftp_request * request, const char *file,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
599 time_t datetime)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
600 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
601 struct utimbuf time_buf;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
602
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
603 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
604 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
605 g_return_val_if_fail (file != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
606
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
607 time_buf.modtime = time_buf.actime = datetime;
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
608 return (utime (file, &time_buf) == 0 ? 0 : GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
609 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
610
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
611
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
612 static gint
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
613 hash_compare (gconstpointer path1, gconstpointer path2)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
614 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
615 return (GPOINTER_TO_UINT (path1) == GPOINTER_TO_UINT (path2));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
616 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
617
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
618
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
619 static guint
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
620 hash_function (gconstpointer key)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
621 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
622 return (GPOINTER_TO_UINT (key));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
623 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
624
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
625
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
626 void
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
627 local_register_module (void)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
628 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
629 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
630
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
631
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
632 int
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
633 local_init (gftp_request * request)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
634 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
635 local_protocol_data *lpd;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
636
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
637 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
638
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
639 request->protonum = GFTP_LOCAL_NUM;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
640 request->init = local_init;
309
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
641 request->copy_param_options = NULL;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
642 request->destroy = local_destroy;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
643 request->read_function = gftp_fd_read;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
644 request->write_function = gftp_fd_write;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
645 request->connect = local_connect;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 136
diff changeset
646 request->post_connect = NULL;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
647 request->disconnect = local_disconnect;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
648 request->get_file = local_get_file;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
649 request->put_file = local_put_file;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
650 request->transfer_file = NULL;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
651 request->get_next_file_chunk = NULL;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
652 request->put_next_file_chunk = NULL;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
653 request->end_transfer = local_end_transfer;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
654 request->abort_transfer = local_end_transfer; /* NOTE: uses end_transfer */
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
655 request->list_files = local_list_files;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
656 request->get_next_file = local_get_next_file;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
657 request->get_file_size = local_get_file_size;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
658 request->chdir = local_chdir;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
659 request->rmdir = local_rmdir;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
660 request->rmfile = local_rmfile;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
661 request->mkdir = local_mkdir;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
662 request->rename = local_rename;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
663 request->chmod = local_chmod;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
664 request->set_file_time = local_set_file_time;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
665 request->site = NULL;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
666 request->parse_url = NULL;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
667 request->set_config_options = NULL;
63
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 62
diff changeset
668 request->swap_socks = NULL;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
669 request->url_prefix = "file";
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
670 request->need_hostport = 0;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
671 request->need_userpass = 0;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
672 request->use_cache = 0;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
673 request->use_threads = 0;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
674 request->always_connected = 1;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
675
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
676 lpd = g_malloc0 (sizeof (*lpd));
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
677 request->protocol_data = lpd;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
678 lpd->userhash = g_hash_table_new (hash_function, hash_compare);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
679 lpd->grouphash = g_hash_table_new (hash_function, hash_compare);
66
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
680
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
681 if (request->hostname != NULL)
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
682 g_free (request->hostname);
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
683 request->hostname = g_strdup (_("local filesystem"));
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
684
177
aec4b4541d3a 2003-6-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
685 return (gftp_set_config_options (request));
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
686 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
687