annotate lib/fsp.c @ 900:1e44c7b7f41b

2007-3-22 Brian Masney <masneyb@gftp.org> * configure.in - updated to use automake 1.9. * cvsclean - remove more files when cleaning up the directory. * po/he.po - removed string that gettext was complaining about.
author masneyb
date Sat, 24 Mar 2007 01:32:03 +0000
parents 4ab11f70a7f4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
661
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
1 /*****************************************************************************/
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
2 /* fsp.c - functions interfacing with FSP v2 protocol library */
885
1808cebed602 2007-3-12 Brian Masney <masneyb@gftp.org>
masneyb
parents: 832
diff changeset
3 /* Copyright (C) 1998-2007 Brian Masney <masneyb@gftp.org> */
661
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
4 /* Copyright (C) 2004 Radim Kolar <hsn@netmag.cz> */
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
5 /* */
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
6 /* This program is free software; you can redistribute it and/or modify */
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
7 /* it under the terms of the GNU General Public License as published by */
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
8 /* the Free Software Foundation; either version 2 of the License, or */
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
9 /* (at your option) any later version. */
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
10 /* */
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
11 /* This program is distributed in the hope that it will be useful, */
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
14 /* GNU General Public License for more details. */
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
15 /* */
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
16 /* You should have received a copy of the GNU General Public License */
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
17 /* along with this program; if not, write to the Free Software */
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
18 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
19 /*****************************************************************************/
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
20
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
21 #include "gftp.h"
765
d553d14a2565 2006-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 663
diff changeset
22 static const char cvsid[] = "$Id$";
663
2d3ea4db3106 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 661
diff changeset
23
661
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
24 #define FSP_USE_SHAREMEM_AND_SEMOP 1
663
2d3ea4db3106 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 661
diff changeset
25 #include "fsplib/fsplib.h"
2d3ea4db3106 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 661
diff changeset
26 #include "fsplib/lock.h"
661
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
27
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
28 typedef struct fsp_protocol_data_tag
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
29 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
30 FSP_SESSION *fsp;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
31 FSP_DIR *dir;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
32 FSP_FILE *file;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
33 } fsp_protocol_data;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
34
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
35 static void
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
36 fsp_destroy (gftp_request * request)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
37 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
38 g_return_if_fail (request != NULL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
39 g_return_if_fail (request->protonum == GFTP_FSP_NUM);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
40 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
41
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
42 static int
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
43 fsp_connect (gftp_request * request)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
44 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
45 fsp_protocol_data * lpd;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
46 intptr_t network_timeout;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
47
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
48 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
49 g_return_val_if_fail (request->protonum == GFTP_FSP_NUM, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
50
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
51 if(! request->port)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
52 request->port = gftp_protocol_default_port (request);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
53
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
54 lpd = request->protocol_data;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
55 lpd->fsp=fsp_open_session(request->hostname, request->port, request->password);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
56
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
57 if(lpd->fsp == NULL)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
58 return (GFTP_ERETRYABLE);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
59 /* set up network timeout */
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
60 gftp_lookup_request_option (request, "network_timeout", &network_timeout);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
61 lpd->fsp->timeout=1000*network_timeout;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
62
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
63 if (!request->directory)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
64 request->directory = g_strdup ("/");
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
65
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
66 request->datafd = lpd->fsp->fd;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
67 return (0);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
68 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
69
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
70 static void
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
71 fsp_disconnect (gftp_request * request)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
72 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
73 fsp_protocol_data * lpd;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
74
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
75 g_return_if_fail (request != NULL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
76 g_return_if_fail (request->protonum == GFTP_FSP_NUM);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
77
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
78 lpd = request->protocol_data;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
79 g_return_if_fail (lpd != NULL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
80
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
81 if(lpd->file)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
82 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
83 fsp_fclose(lpd->file);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
84 lpd->file=NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
85 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
86 fsp_close_session(lpd->fsp);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
87 lpd->fsp=NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
88 request->datafd = -1;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
89 if(lpd->dir)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
90 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
91 fsp_closedir(lpd->dir);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
92 lpd->dir=NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
93 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
94 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
95
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
96 static off_t
895
4ab11f70a7f4 2007-3-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 885
diff changeset
97 fsp_get_file (gftp_request * request, const char *filename,
661
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
98 off_t startsize)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
99 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
100 fsp_protocol_data * lpd;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
101 struct stat sb;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
102
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
103 g_return_val_if_fail (request != NULL,GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
104 g_return_val_if_fail (request->protonum == GFTP_FSP_NUM,GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
105 g_return_val_if_fail (filename != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
106
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
107 lpd = request->protocol_data;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
108 g_return_val_if_fail (lpd != NULL,GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
109 g_return_val_if_fail (lpd->fsp != NULL,GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
110
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
111 /* CHECK: close prev. opened file, is this needed? */
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
112 if(lpd->file != NULL)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
113 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
114 fsp_fclose(lpd->file);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
115 lpd->file=NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
116 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
117
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
118 if(fsp_stat(lpd->fsp,filename,&sb))
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
119 return (GFTP_ERETRYABLE);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
120 if(!S_ISREG(sb.st_mode))
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
121 return (GFTP_ERETRYABLE);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
122 lpd->file=fsp_fopen(lpd->fsp,filename,"rb");
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
123
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
124 if (fsp_fseek (lpd->file, startsize, SEEK_SET) == -1)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
125 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
126 request->logging_function (gftp_logging_error, request,
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
127 _("Error: Cannot seek on file %s: %s\n"),
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
128 filename, g_strerror (errno));
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
129 gftp_disconnect (request);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
130 return (GFTP_ERETRYABLE);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
131 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
132
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
133 return (sb.st_size);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
134 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
135
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
136 static ssize_t fsp_read_function(gftp_request *request, void *buf, size_t size,int fd)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
137 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
138 fsp_protocol_data * lpd;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
139
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
140 g_return_val_if_fail (request != NULL, -1);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
141 g_return_val_if_fail (request->protonum == GFTP_FSP_NUM, -1);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
142 g_return_val_if_fail (buf != NULL, -1);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
143
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
144 lpd = request->protocol_data;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
145 g_return_val_if_fail (lpd != NULL, -1);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
146 g_return_val_if_fail (lpd->file != NULL, -1);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
147
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
148 return fsp_fread(buf,1,size,lpd->file);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
149 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
150
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
151 static ssize_t fsp_write_function(gftp_request *request, const char *buf, size_t size,int fd)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
152 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
153 fsp_protocol_data * lpd;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
154
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
155 g_return_val_if_fail (request != NULL, -1);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
156 g_return_val_if_fail (request->protonum == GFTP_FSP_NUM, -1);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
157 g_return_val_if_fail (buf != NULL, -1);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
158
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
159 lpd = request->protocol_data;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
160 g_return_val_if_fail (lpd != NULL, -1);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
161 g_return_val_if_fail (lpd->file != NULL, -1);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
162
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
163 return fsp_fwrite(buf,1,size,lpd->file);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
164 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
165
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
166 static int
895
4ab11f70a7f4 2007-3-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 885
diff changeset
167 fsp_put_file (gftp_request * request, const char *filename,
661
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
168 off_t startsize, off_t totalsize)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
169 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
170 fsp_protocol_data * lpd;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
171
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
172 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
173 g_return_val_if_fail (request->protonum == GFTP_FSP_NUM, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
174 g_return_val_if_fail (filename != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
175
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
176 lpd = request->protocol_data;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
177 g_return_val_if_fail (lpd != NULL,GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
178 g_return_val_if_fail (lpd->fsp != NULL,GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
179
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
180 if(lpd->file != NULL)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
181 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
182 fsp_fclose(lpd->file);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
183 lpd->file=NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
184 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
185
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
186 if(fsp_canupload(lpd->fsp,filename))
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
187 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
188 request->logging_function (gftp_logging_error, request,
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
189 _("Error: Cannot upload file %s\n"),
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
190 filename );
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
191 return (GFTP_ERETRYABLE);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
192 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
193
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
194
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
195 lpd->file=fsp_fopen(lpd->fsp,filename, "wb");
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
196 if(lpd->file == NULL)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
197 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
198 request->logging_function (gftp_logging_error, request,
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
199 _("Error: Cannot write to file %s: %s\n"),
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
200 filename, g_strerror (errno));
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
201 return (GFTP_ERETRYABLE);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
202 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
203
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
204 if (fsp_fseek (lpd->file, startsize, SEEK_SET) == -1)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
205 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
206 request->logging_function (gftp_logging_error, request,
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
207 _("Error: Cannot seek on file %s: %s\n"),
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
208 filename, g_strerror (errno));
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
209 gftp_disconnect (request);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
210 return (GFTP_ERETRYABLE);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
211 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
212 return (0);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
213 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
214
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
215 static int
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
216 fsp_end_transfer (gftp_request * request)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
217 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
218 fsp_protocol_data * lpd;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
219
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
220 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
221 g_return_val_if_fail (request->protonum == GFTP_FSP_NUM, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
222
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
223 lpd = request->protocol_data;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
224 g_return_val_if_fail (lpd->fsp != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
225
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
226 if (lpd->dir)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
227 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
228 fsp_closedir (lpd->dir);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
229 lpd->dir = NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
230 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
231 if (lpd ->file)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
232 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
233 if(fsp_fclose(lpd->file))
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
234 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
235 lpd -> file = NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
236 request->logging_function (gftp_logging_error, request,
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
237 _("Error: Error closing file: %s\n"),
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
238 g_strerror (errno));
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
239 return GFTP_EFATAL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
240 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
241 lpd->file=NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
242 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
243
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
244 return (0);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
245 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
246
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
247 static int
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
248 fsp_abort_transfer (gftp_request * request)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
249 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
250 fsp_protocol_data * lpd;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
251
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
252 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
253 g_return_val_if_fail (request->protonum == GFTP_FSP_NUM, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
254
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
255 lpd = request->protocol_data;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
256 g_return_val_if_fail (lpd->fsp != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
257
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
258 if (lpd->dir)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
259 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
260 fsp_closedir (lpd->dir);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
261 lpd->dir = NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
262 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
263 if (lpd ->file)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
264 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
265 if(lpd->file->writing && lpd->file->pos>0)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
266 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
267 /* need to cancel upload in progress */
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
268 lpd->file->writing=0;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
269 fsp_install(lpd->fsp,"",0);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
270 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
271 /* we can safely ignore file close error on abort */
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
272 fsp_fclose(lpd->file);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
273 lpd->file=NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
274 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
275
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
276 return (0);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
277 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
278
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
279 static int
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
280 fsp_stat_filename (gftp_request * request, const char *filename,
787
3751478bb260 2006-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
281 mode_t * mode, off_t * filesize)
661
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
282 {
787
3751478bb260 2006-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
283 fsp_protocol_data * lpd;
661
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
284 struct stat st;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
285
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
286 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
287 g_return_val_if_fail (request->protonum == GFTP_FSP_NUM, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
288 g_return_val_if_fail (filename != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
289
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
290 lpd = request->protocol_data;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
291 g_return_val_if_fail (lpd->fsp != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
292
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
293 if (fsp_stat (lpd->fsp,filename, &st) != 0)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
294 return (GFTP_ERETRYABLE);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
295
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
296 *mode = st.st_mode;
787
3751478bb260 2006-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
297 *filesize = st.st_size;
3751478bb260 2006-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
298
661
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
299 return (0);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
300 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
301
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
302 static int
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
303 fsp_get_next_file (gftp_request * request, gftp_file * fle, int fd)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
304 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
305 fsp_protocol_data *lpd;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
306 struct FSP_RDENTRY dirent;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
307 struct FSP_RDENTRY *result;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
308 char *symlink;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
309
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
310 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
311 g_return_val_if_fail (request->protonum == GFTP_FSP_NUM, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
312 g_return_val_if_fail (fle != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
313
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
314 lpd = request->protocol_data;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
315
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
316 g_return_val_if_fail (lpd != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
317
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
318 memset (fle, 0, sizeof (*fle));
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
319
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
320 result=&dirent;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
321
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
322 if ( fsp_readdir_native (lpd->dir,&dirent,&result))
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
323 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
324 fsp_closedir (lpd->dir);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
325 lpd->dir = NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
326 request->logging_function (gftp_logging_error, request,
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
327 _("Corrupted file listing from FSP server %s\n"),
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
328 request->directory );
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
329 return (GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
330 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
331
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
332 if ( result == NULL)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
333 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
334 fsp_closedir (lpd->dir);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
335 lpd->dir = NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
336 return 0;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
337 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
338
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
339 fle->user = g_strdup (_("unknown"));
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
340 fle->group = g_strdup (_("unknown"));
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
341
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
342 /* turn FSP symlink into normal file */
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
343 symlink=strchr(dirent.name,'\n');
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
344 if (symlink)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
345 *symlink='\0';
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
346 fle->file = g_strdup (dirent.name);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
347 if (dirent.type==FSP_RDTYPE_DIR)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
348 fle->st_mode = S_IFDIR | 0755;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
349 else
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
350 fle->st_mode = S_IFREG | 0644;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
351 fle->datetime = dirent.lastmod;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
352 fle->size = dirent.size;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
353 return (1);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
354 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
355
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
356 static int
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
357 fsp_list_files (gftp_request * request)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
358 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
359 fsp_protocol_data *lpd;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
360
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
361 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
362 g_return_val_if_fail (request->directory != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
363 g_return_val_if_fail (request->protonum == GFTP_FSP_NUM, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
364
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
365 lpd = request->protocol_data;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
366
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
367 g_return_val_if_fail (lpd != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
368
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
369 if (request->directory == NULL)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
370 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
371 request->directory = g_strdup("/");
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
372 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
373
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
374 if ((lpd->dir = fsp_opendir (lpd->fsp,request->directory)) == NULL)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
375 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
376 request->logging_function (gftp_logging_error, request,
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
377 _("Could not get FSP directory listing %s: %s\n"),
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
378 request->directory, g_strerror (errno));
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
379 return (GFTP_ERETRYABLE);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
380 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
381
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
382 return (0);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
383 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
384
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
385
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
386 static off_t
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
387 fsp_get_file_size (gftp_request * request, const char *filename)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
388 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
389 struct stat st;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
390 fsp_protocol_data * lpd;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
391
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
392 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
393 g_return_val_if_fail (request->protonum == GFTP_FSP_NUM, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
394 g_return_val_if_fail (filename != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
395
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
396 lpd = request->protocol_data;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
397 g_return_val_if_fail (lpd->fsp != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
398
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
399 if (fsp_stat (lpd->fsp,filename, &st) != 0)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
400 return (GFTP_ERETRYABLE);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
401
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
402 return (st.st_size);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
403 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
404
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
405 static int
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
406 fsp_chdir (gftp_request * request, const char *directory)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
407 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
408 fsp_protocol_data *lpd;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
409 char *tempstr, *olddir;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
410
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
411 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
412 g_return_val_if_fail (request->protonum == GFTP_FSP_NUM, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
413 g_return_val_if_fail (directory != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
414
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
415 lpd = request->protocol_data;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
416
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
417 g_return_val_if_fail (lpd != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
418 g_return_val_if_fail (lpd->fsp != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
419
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
420 olddir=NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
421 /* build new directory string */
787
3751478bb260 2006-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
422 olddir = request->directory;
661
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
423
787
3751478bb260 2006-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
424 if (*directory != '/' && request->directory != NULL)
3751478bb260 2006-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
425 {
3751478bb260 2006-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
426 tempstr = g_strconcat (request->directory, "/", directory, NULL);
3751478bb260 2006-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
427 request->directory = gftp_expand_path (request, tempstr);
3751478bb260 2006-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
428 g_free (tempstr);
661
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
429 }
787
3751478bb260 2006-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
430 else
3751478bb260 2006-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
431 request->directory = gftp_expand_path (request, directory);
661
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
432
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
433 if (fsp_getpro (lpd->fsp,request->directory,NULL) == 0)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
434 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
435 request->logging_function (gftp_logging_misc, request,
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
436 _("Successfully changed directory to %s\n"),
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
437 directory);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
438
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
439 if (olddir != NULL)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
440 g_free (olddir);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
441 return (0);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
442 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
443 else
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
444 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
445 request->logging_function (gftp_logging_error, request,
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
446 _("Could not change directory to %s\n"),
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
447 directory);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
448 g_free (request->directory);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
449 request->directory = olddir;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
450 return (GFTP_ERETRYABLE);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
451 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
452 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
453
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
454 static int
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
455 fsp_removedir (gftp_request * request, const char *directory)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
456 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
457 fsp_protocol_data *lpd;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
458
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
459 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
460 g_return_val_if_fail (request->protonum == GFTP_FSP_NUM, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
461 g_return_val_if_fail (directory != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
462
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
463 lpd = request->protocol_data;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
464
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
465 g_return_val_if_fail (lpd != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
466 g_return_val_if_fail (lpd->fsp != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
467
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
468 if (fsp_rmdir (lpd->fsp,directory) == 0)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
469 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
470 request->logging_function (gftp_logging_misc, request,
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
471 _("Successfully removed %s\n"), directory);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
472 return (0);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
473 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
474 else
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
475 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
476 request->logging_function (gftp_logging_error, request,
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
477 _("Error: Could not remove directory %s: %s\n"),
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
478 directory, g_strerror (errno));
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
479 return (GFTP_ERETRYABLE);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
480 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
481 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
482
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
483
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
484 static int
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
485 fsp_rmfile (gftp_request * request, const char *file)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
486 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
487 fsp_protocol_data *lpd;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
488
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
489 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
490 g_return_val_if_fail (request->protonum == GFTP_FSP_NUM, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
491 g_return_val_if_fail (file != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
492
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
493 lpd = request->protocol_data;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
494 g_return_val_if_fail (lpd != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
495 g_return_val_if_fail (lpd->fsp != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
496
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
497 if (fsp_unlink (lpd->fsp,file) == 0)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
498 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
499 request->logging_function (gftp_logging_misc, request,
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
500 _("Successfully removed %s\n"), file);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
501 return (0);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
502 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
503 else
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
504 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
505 request->logging_function (gftp_logging_error, request,
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
506 _("Error: Could not remove file %s: %s\n"),
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
507 file, g_strerror (errno));
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
508 return (GFTP_ERETRYABLE);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
509 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
510 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
511
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
512 static int
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
513 fsp_makedir (gftp_request * request, const char *directory)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
514 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
515 fsp_protocol_data *lpd;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
516
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
517 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
518 g_return_val_if_fail (request->protonum == GFTP_FSP_NUM, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
519 g_return_val_if_fail (directory != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
520
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
521 lpd = request->protocol_data;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
522 g_return_val_if_fail (lpd != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
523 g_return_val_if_fail (lpd->fsp != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
524
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
525 if (fsp_mkdir (lpd->fsp,directory) == 0)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
526 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
527 request->logging_function (gftp_logging_misc, request,
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
528 _("Successfully made directory %s\n"),
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
529 directory);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
530 return (0);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
531 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
532 else
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
533 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
534 request->logging_function (gftp_logging_error, request,
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
535 _("Error: Could not make directory %s: %s\n"),
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
536 directory, g_strerror (errno));
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
537 return (GFTP_ERETRYABLE);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
538 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
539 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
540
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
541 static int
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
542 fsp_ren (gftp_request * request, const char *oldname,
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
543 const char *newname)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
544 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
545 char *newname1,*newname2;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
546 fsp_protocol_data *lpd;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
547
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
548 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
549 g_return_val_if_fail (request->protonum == GFTP_FSP_NUM, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
550 g_return_val_if_fail (oldname != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
551 g_return_val_if_fail (newname != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
552
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
553 lpd = request->protocol_data;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
554 g_return_val_if_fail (lpd != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
555 g_return_val_if_fail (lpd->fsp != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
556
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
557 newname1= g_strconcat (request->directory, "/", oldname, NULL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
558 newname2= g_strconcat (request->directory, "/", newname, NULL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
559
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
560 if (fsp_rename (lpd->fsp,newname1, newname2) == 0)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
561 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
562 request->logging_function (gftp_logging_misc, request,
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
563 _("Successfully renamed %s to %s\n"),
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
564 oldname, newname);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
565 g_free(newname1);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
566 g_free(newname2);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
567 return (0);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
568 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
569 else
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
570 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
571 g_free(newname1);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
572 g_free(newname2);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
573
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
574 request->logging_function (gftp_logging_error, request,
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
575 _("Error: Could not rename %s to %s: %s\n"),
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
576 oldname, newname, g_strerror (errno));
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
577 return (GFTP_ERETRYABLE);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
578 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
579 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
580
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
581 /* TODO: FSP needs to know file last modification time while starting
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
582 upload. It can not change last mod time of existing files on server.
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
583 */
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
584
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
585 void
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
586 fsp_register_module (void)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
587 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
588 }
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
589
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
590 int
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
591 fsp_init (gftp_request * request)
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
592 {
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
593 fsp_protocol_data *lpd;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
594
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
595 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
596
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
597 request->protonum = GFTP_FSP_NUM;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
598 request->init = fsp_init;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
599 request->copy_param_options = NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
600 request->destroy = fsp_destroy;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
601 request->read_function = fsp_read_function;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
602 request->write_function = fsp_write_function;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
603 request->connect = fsp_connect;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
604 request->post_connect = NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
605 request->disconnect = fsp_disconnect;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
606 request->get_file = fsp_get_file;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
607 request->put_file = fsp_put_file;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
608 request->transfer_file = NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
609 request->get_next_file_chunk = NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
610 request->put_next_file_chunk = NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
611 request->end_transfer = fsp_end_transfer;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
612 request->abort_transfer = fsp_abort_transfer;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
613 request->stat_filename = fsp_stat_filename;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
614 request->list_files = fsp_list_files;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
615 request->get_next_file = fsp_get_next_file;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
616 request->get_next_dirlist_line = NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
617 request->get_file_size = fsp_get_file_size;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
618 request->chdir = fsp_chdir;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
619 request->rmdir = fsp_removedir;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
620 request->rmfile = fsp_rmfile;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
621 request->mkdir = fsp_makedir;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
622 request->rename = fsp_ren;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
623 request->chmod = NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
624 request->set_file_time = NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
625 request->site = NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
626 request->parse_url = NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
627 request->set_config_options = NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
628 request->swap_socks = NULL;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
629 request->url_prefix = "fsp";
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
630 request->need_hostport = 1;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
631 request->need_username = 0;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
632 request->need_password = 0;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
633 request->use_cache = 1;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
634 request->always_connected = 0;
832
f2772ac00751 2006-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 787
diff changeset
635 request->use_local_encoding = 0;
661
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
636
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
637 lpd = g_malloc0 (sizeof (*lpd));
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
638 request->protocol_data = lpd;
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
639
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
640 return (gftp_set_config_options (request));
2e718fba351e 2005-1-16 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
641 }