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