Mercurial > gftp.yaz
annotate lib/protocols.c @ 855:30eaf54a63f7
2006-11-16 Brian Masney <masneyb@gftp.org>
* lib/protocols.c (gftp_get_all_subdirs) - don't return if there was a
problem running gftp_stat_filename(). Only return if there was a fatal
error. (closes #314929)
| author | masneyb |
|---|---|
| date | Fri, 17 Nov 2006 03:04:57 +0000 |
| parents | 5e3005923374 |
| children | 1fae947d4418 |
| rev | line source |
|---|---|
| 1 | 1 /*****************************************************************************/ |
| 2 /* protocols.c - Skeleton functions for the protocols gftp supports */ | |
| 122 | 3 /* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> */ |
| 1 | 4 /* */ |
| 5 /* This program is free software; you can redistribute it and/or modify */ | |
| 6 /* it under the terms of the GNU General Public License as published by */ | |
| 7 /* the Free Software Foundation; either version 2 of the License, or */ | |
| 8 /* (at your option) any later version. */ | |
| 9 /* */ | |
| 10 /* This program is distributed in the hope that it will be useful, */ | |
| 11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ | |
| 12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ | |
| 13 /* GNU General Public License for more details. */ | |
| 14 /* */ | |
| 15 /* You should have received a copy of the GNU General Public License */ | |
| 16 /* along with this program; if not, write to the Free Software */ | |
| 17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */ | |
| 18 /*****************************************************************************/ | |
| 19 | |
| 20 #include "gftp.h" | |
| 33 | 21 static const char cvsid[] = "$Id$"; |
| 1 | 22 |
| 23 gftp_request * | |
| 24 gftp_request_new (void) | |
| 25 { | |
| 26 gftp_request *request; | |
| 27 | |
| 28 request = g_malloc0 (sizeof (*request)); | |
| 66 | 29 request->datafd = -1; |
| 30 request->cachefd = -1; | |
| 122 | 31 request->server_type = GFTP_DIRTYPE_OTHER; |
| 1 | 32 return (request); |
| 33 } | |
| 136 | 34 |
| 1 | 35 |
| 36 void | |
| 67 | 37 gftp_request_destroy (gftp_request * request, int free_request) |
| 1 | 38 { |
| 39 g_return_if_fail (request != NULL); | |
| 40 | |
| 41 gftp_disconnect (request); | |
| 42 | |
| 43 if (request->destroy != NULL) | |
| 44 request->destroy (request); | |
| 45 | |
| 46 if (request->hostname) | |
| 47 g_free (request->hostname); | |
| 48 if (request->username) | |
| 49 g_free (request->username); | |
| 50 if (request->password) | |
| 51 { | |
| 52 memset (request->password, 0, strlen (request->password)); | |
| 53 g_free (request->password); | |
| 54 } | |
| 55 if (request->account) | |
| 56 { | |
| 57 memset (request->account, 0, strlen (request->account)); | |
| 58 g_free (request->account); | |
| 59 } | |
| 60 if (request->directory) | |
| 61 g_free (request->directory); | |
| 62 if (request->last_ftp_response) | |
| 63 g_free (request->last_ftp_response); | |
| 64 if (request->protocol_data) | |
| 65 g_free (request->protocol_data); | |
| 67 | 66 |
| 198 | 67 if (request->local_options_vars != NULL) |
| 68 { | |
| 201 | 69 gftp_config_free_options (request->local_options_vars, |
| 70 request->local_options_hash, | |
| 71 request->num_local_options_vars); | |
| 198 | 72 } |
| 73 | |
| 1 | 74 memset (request, 0, sizeof (*request)); |
| 67 | 75 |
| 76 if (free_request) | |
| 77 g_free (request); | |
| 78 else | |
| 79 { | |
| 80 request->datafd = -1; | |
| 81 request->cachefd = -1; | |
| 82 } | |
| 1 | 83 } |
| 84 | |
| 85 | |
| 309 | 86 /* This function is called to copy protocol specific data from one request |
| 87 structure to another. This is typically called when a file transfer is | |
| 88 completed, state information can be copied back to the main window */ | |
| 89 void | |
| 90 gftp_copy_param_options (gftp_request * dest_request, | |
| 91 gftp_request * src_request) | |
| 92 { | |
| 93 g_return_if_fail (dest_request != NULL); | |
| 94 g_return_if_fail (src_request != NULL); | |
| 95 g_return_if_fail (dest_request->protonum == src_request->protonum); | |
| 96 | |
| 97 if (dest_request->copy_param_options) | |
| 98 dest_request->copy_param_options (dest_request, src_request); | |
| 99 } | |
| 100 | |
| 101 | |
| 1 | 102 void |
| 598 | 103 gftp_file_destroy (gftp_file * file, int free_it) |
| 1 | 104 { |
| 105 g_return_if_fail (file != NULL); | |
| 106 | |
| 107 if (file->file) | |
| 108 g_free (file->file); | |
| 109 if (file->user) | |
| 110 g_free (file->user); | |
| 111 if (file->group) | |
| 112 g_free (file->group); | |
| 113 if (file->destfile) | |
| 114 g_free (file->destfile); | |
| 598 | 115 |
| 116 if (free_it) | |
| 117 g_free (file); | |
| 118 else | |
| 119 memset (file, 0, sizeof (*file)); | |
| 1 | 120 } |
| 121 | |
| 122 | |
| 123 int | |
| 124 gftp_connect (gftp_request * request) | |
| 125 { | |
| 177 | 126 int ret; |
| 127 | |
| 84 | 128 g_return_val_if_fail (request != NULL, GFTP_EFATAL); |
| 1 | 129 |
| 130 if (request->connect == NULL) | |
| 84 | 131 return (GFTP_EFATAL); |
| 1 | 132 |
| 177 | 133 if ((ret = gftp_set_config_options (request)) < 0) |
| 134 return (ret); | |
| 1 | 135 |
| 136 return (request->connect (request)); | |
| 137 } | |
| 138 | |
| 139 | |
| 140 void | |
| 141 gftp_disconnect (gftp_request * request) | |
| 142 { | |
| 143 g_return_if_fail (request != NULL); | |
| 144 | |
| 145 #if defined (HAVE_GETADDRINFO) && defined (HAVE_GAI_STRERROR) | |
| 151 | 146 if (request->free_hostp && request->hostp != NULL) |
| 1 | 147 freeaddrinfo (request->hostp); |
| 148 #endif | |
| 149 request->hostp = NULL; | |
| 150 | |
| 168 | 151 #ifdef USE_SSL |
| 152 if (request->ssl != NULL) | |
| 153 { | |
| 154 SSL_free (request->ssl); | |
| 155 request->ssl = NULL; | |
| 156 } | |
| 157 #endif | |
| 158 | |
| 187 | 159 #if GLIB_MAJOR_VERSION > 1 |
| 160 if (request->iconv_initialized) | |
| 161 { | |
| 162 g_iconv_close (request->iconv); | |
| 163 request->iconv_initialized = 0; | |
| 842 | 164 g_free (request->iconv_charset); |
| 165 request->iconv_charset = NULL; | |
| 187 | 166 } |
| 167 #endif | |
| 168 | |
| 1 | 169 request->cached = 0; |
| 170 if (request->disconnect == NULL) | |
| 171 return; | |
| 172 request->disconnect (request); | |
| 173 } | |
| 174 | |
| 175 | |
| 58 | 176 off_t |
| 177 gftp_get_file (gftp_request * request, const char *filename, int fd, | |
| 244 | 178 off_t startsize) |
| 1 | 179 { |
| 84 | 180 g_return_val_if_fail (request != NULL, GFTP_EFATAL); |
| 1 | 181 |
| 182 request->cached = 0; | |
| 183 if (request->get_file == NULL) | |
| 84 | 184 return (GFTP_EFATAL); |
| 244 | 185 |
| 1 | 186 return (request->get_file (request, filename, fd, startsize)); |
| 187 } | |
| 188 | |
| 189 | |
| 190 int | |
| 58 | 191 gftp_put_file (gftp_request * request, const char *filename, int fd, |
| 244 | 192 off_t startsize, off_t totalsize) |
| 1 | 193 { |
| 84 | 194 g_return_val_if_fail (request != NULL, GFTP_EFATAL); |
| 1 | 195 |
| 196 request->cached = 0; | |
| 197 if (request->put_file == NULL) | |
| 84 | 198 return (GFTP_EFATAL); |
| 566 | 199 |
| 599 | 200 return (request->put_file (request, filename, fd, startsize, totalsize)); |
| 1 | 201 } |
| 202 | |
| 203 | |
| 261 | 204 off_t |
| 1 | 205 gftp_transfer_file (gftp_request * fromreq, const char *fromfile, |
| 244 | 206 int fromfd, off_t fromsize, |
| 1 | 207 gftp_request * toreq, const char *tofile, |
| 244 | 208 int tofd, off_t tosize) |
| 1 | 209 { |
| 469 | 210 /* Needed for systems that size(float) < size(void *) */ |
| 211 union { intptr_t i; float f; } maxkbs; | |
| 261 | 212 off_t size; |
| 84 | 213 int ret; |
| 1 | 214 |
| 84 | 215 g_return_val_if_fail (fromreq != NULL, GFTP_EFATAL); |
| 216 g_return_val_if_fail (fromfile != NULL, GFTP_EFATAL); | |
| 217 g_return_val_if_fail (toreq != NULL, GFTP_EFATAL); | |
| 218 g_return_val_if_fail (tofile != NULL, GFTP_EFATAL); | |
| 219 | |
| 469 | 220 gftp_lookup_request_option (toreq, "maxkbs", &maxkbs.f); |
| 221 | |
| 222 if (maxkbs.f > 0) | |
| 294 | 223 { |
| 224 toreq->logging_function (gftp_logging_misc, toreq, | |
| 225 _("File transfer will be throttled to %.2f KB/s\n"), | |
| 469 | 226 maxkbs.f); |
| 294 | 227 } |
| 228 | |
| 87 | 229 if (fromreq->protonum == toreq->protonum && |
| 84 | 230 fromreq->transfer_file != NULL) |
| 231 return (fromreq->transfer_file (fromreq, fromfile, fromsize, toreq, | |
| 232 tofile, tosize)); | |
| 1 | 233 |
| 234 fromreq->cached = 0; | |
| 235 toreq->cached = 0; | |
| 443 | 236 |
| 237 get_file: | |
| 238 size = gftp_get_file (fromreq, fromfile, fromfd, tosize); | |
| 239 if (size < 0) | |
| 1 | 240 { |
| 443 | 241 if (size == GFTP_ETIMEDOUT) |
| 242 { | |
| 243 ret = gftp_connect (fromreq); | |
| 244 if (ret < 0) | |
| 245 return (ret); | |
| 246 | |
| 247 goto get_file; | |
| 248 } | |
| 249 | |
| 250 return (size); | |
| 251 } | |
| 252 | |
| 253 put_file: | |
| 254 ret = gftp_put_file (toreq, tofile, tofd, tosize, size); | |
| 255 if (ret != 0) | |
| 256 { | |
| 257 if (size == GFTP_ETIMEDOUT) | |
| 258 { | |
| 259 ret = gftp_connect (fromreq); | |
| 260 if (ret < 0) | |
| 261 return (ret); | |
| 262 | |
| 263 goto put_file; | |
| 264 } | |
| 265 | |
| 40 | 266 if (gftp_abort_transfer (fromreq) != 0) |
| 267 gftp_end_transfer (fromreq); | |
| 268 | |
| 84 | 269 return (ret); |
| 1 | 270 } |
| 271 | |
| 272 return (size); | |
| 273 } | |
| 274 | |
| 275 | |
| 58 | 276 ssize_t |
| 1 | 277 gftp_get_next_file_chunk (gftp_request * request, char *buf, size_t size) |
| 278 { | |
| 84 | 279 g_return_val_if_fail (request != NULL, GFTP_EFATAL); |
| 280 g_return_val_if_fail (buf != NULL, GFTP_EFATAL); | |
| 1 | 281 |
| 282 if (request->get_next_file_chunk != NULL) | |
| 283 return (request->get_next_file_chunk (request, buf, size)); | |
| 284 | |
| 168 | 285 return (request->read_function (request, buf, size, request->datafd)); |
| 1 | 286 } |
| 287 | |
| 288 | |
| 58 | 289 ssize_t |
| 1 | 290 gftp_put_next_file_chunk (gftp_request * request, char *buf, size_t size) |
| 291 { | |
| 84 | 292 g_return_val_if_fail (request != NULL, GFTP_EFATAL); |
| 293 g_return_val_if_fail (buf != NULL, GFTP_EFATAL); | |
| 1 | 294 |
| 295 if (request->put_next_file_chunk != NULL) | |
| 296 return (request->put_next_file_chunk (request, buf, size)); | |
| 297 | |
| 168 | 298 return (request->write_function (request, buf, size, request->datafd)); |
| 1 | 299 } |
| 300 | |
| 301 | |
| 302 int | |
| 303 gftp_end_transfer (gftp_request * request) | |
| 304 { | |
| 305 int ret; | |
| 306 | |
| 84 | 307 g_return_val_if_fail (request != NULL, GFTP_EFATAL); |
| 1 | 308 |
| 40 | 309 if (!request->cached && |
| 310 request->end_transfer != NULL) | |
| 311 ret = request->end_transfer (request); | |
| 312 else | |
| 313 ret = 0; | |
| 1 | 314 |
| 58 | 315 if (request->cachefd > 0) |
| 1 | 316 { |
| 58 | 317 close (request->cachefd); |
| 318 request->cachefd = -1; | |
| 1 | 319 } |
| 320 | |
| 321 if (request->last_dir_entry) | |
| 322 { | |
| 323 g_free (request->last_dir_entry); | |
| 324 request->last_dir_entry = NULL; | |
| 325 request->last_dir_entry_len = 0; | |
| 326 } | |
| 327 | |
| 328 return (ret); | |
| 329 } | |
| 330 | |
| 331 | |
| 332 int | |
| 40 | 333 gftp_abort_transfer (gftp_request * request) |
| 334 { | |
| 84 | 335 g_return_val_if_fail (request != NULL, GFTP_EFATAL); |
| 40 | 336 |
| 337 if (request->abort_transfer == NULL) | |
| 84 | 338 return (GFTP_EFATAL); |
| 40 | 339 |
| 813 | 340 /* FIXME - end the transfer if it is not successful */ |
| 40 | 341 return (request->abort_transfer (request)); |
| 342 } | |
| 343 | |
| 344 | |
| 520 | 345 int |
| 787 | 346 gftp_stat_filename (gftp_request * request, const char *filename, mode_t * mode, |
| 347 off_t * filesize) | |
| 500 | 348 { |
| 349 g_return_val_if_fail (request != NULL, GFTP_EFATAL); | |
| 520 | 350 g_return_val_if_fail (filename != NULL, GFTP_EFATAL); |
| 500 | 351 |
| 352 if (request->stat_filename != NULL) | |
| 787 | 353 return (request->stat_filename (request, filename, mode, filesize)); |
| 500 | 354 else |
| 520 | 355 return (0); |
| 500 | 356 } |
| 357 | |
| 358 | |
| 40 | 359 int |
| 1 | 360 gftp_list_files (gftp_request * request) |
| 361 { | |
| 473 | 362 char *remote_lc_time, *locret; |
| 58 | 363 int fd; |
| 1 | 364 |
| 84 | 365 g_return_val_if_fail (request != NULL, GFTP_EFATAL); |
| 1 | 366 |
| 623 | 367 #if ENABLE_NLS |
| 473 | 368 gftp_lookup_request_option (request, "remote_lc_time", &remote_lc_time); |
| 369 if (remote_lc_time != NULL && *remote_lc_time != '\0') | |
| 370 locret = setlocale (LC_TIME, remote_lc_time); | |
| 371 else | |
| 372 locret = setlocale (LC_TIME, NULL); | |
| 373 | |
| 374 if (locret == NULL) | |
| 375 { | |
| 376 locret = setlocale (LC_TIME, NULL); | |
| 677 | 377 request->logging_function (gftp_logging_error, request, |
| 473 | 378 _("Error setting LC_TIME to '%s'. Falling back to '%s'\n"), |
| 379 remote_lc_time, locret); | |
| 380 } | |
| 623 | 381 #else |
| 382 locret = _("<unknown>"); | |
| 383 #endif | |
| 473 | 384 |
| 1 | 385 request->cached = 0; |
| 58 | 386 if (request->use_cache && (fd = gftp_find_cache_entry (request)) > 0) |
| 1 | 387 { |
| 186 | 388 request->logging_function (gftp_logging_misc, request, |
| 473 | 389 _("Loading directory listing %s from cache (LC_TIME=%s)\n"), |
| 390 request->directory, locret); | |
| 1 | 391 |
| 392 request->cachefd = fd; | |
| 393 request->cached = 1; | |
| 394 return (0); | |
| 395 } | |
| 396 else if (request->use_cache) | |
| 397 { | |
| 473 | 398 request->logging_function (gftp_logging_misc, request, |
| 399 _("Loading directory listing %s from server (LC_TIME=%s)\n"), | |
| 400 request->directory, locret); | |
| 401 | |
| 1 | 402 request->cachefd = gftp_new_cache_entry (request); |
| 403 request->cached = 0; | |
| 404 } | |
| 405 | |
| 406 if (request->list_files == NULL) | |
| 84 | 407 return (GFTP_EFATAL); |
| 473 | 408 |
| 1 | 409 return (request->list_files (request)); |
| 410 } | |
| 411 | |
| 412 | |
| 184 | 413 #if GLIB_MAJOR_VERSION > 1 |
| 291 | 414 |
| 765 | 415 static /*@null@*/ char * |
| 423 | 416 _gftp_get_next_charset (char **curpos) |
| 184 | 417 { |
| 418 char *ret, *endpos; | |
| 842 | 419 size_t len, retlen; |
| 184 | 420 |
| 421 if (**curpos == '\0') | |
| 422 return (NULL); | |
| 423 | |
| 842 | 424 for (; **curpos == ' ' || **curpos == '\t'; (*curpos)++); |
| 425 | |
| 185 | 426 if ((endpos = strchr (*curpos, ',')) == NULL) |
| 842 | 427 len = strlen (*curpos); |
| 428 else | |
| 429 len = endpos - *curpos + 1; | |
| 430 | |
| 431 for (retlen = len - 1; | |
| 432 (*curpos)[retlen - 1] == ' ' || (*curpos)[retlen - 1] == '\t'; | |
| 433 retlen--); | |
| 434 | |
| 435 ret = g_malloc0 (retlen + 1); | |
| 436 memcpy (ret, *curpos, retlen); | |
| 437 | |
| 438 for (*curpos += len; **curpos == ','; (*curpos)++); | |
| 439 | |
| 440 return (ret); | |
| 441 } | |
| 442 | |
| 443 | |
| 444 static void | |
| 445 _do_show_iconv_error (const char *str, char *charset, int from_utf8, | |
| 446 GError * error) | |
| 447 { | |
| 448 const char *fromset, *toset; | |
| 449 | |
| 450 if (from_utf8) | |
| 451 { | |
| 452 fromset = "UTF-8"; | |
| 453 toset = charset; | |
| 454 } | |
| 184 | 455 else |
| 456 { | |
| 842 | 457 fromset = charset; |
| 458 toset = "UTF-8"; | |
| 184 | 459 } |
| 460 | |
| 842 | 461 printf (_("Error converting string '%s' from character set %s to character set %s: %s\n"), |
| 462 str, fromset, toset, error->message); | |
| 184 | 463 } |
| 464 | |
| 465 | |
| 765 | 466 /*@null@*/ char * |
| 845 | 467 _do_convert_string (gftp_request * request, int is_filename, int force_local, |
| 468 const char *str, size_t *dest_len, int from_utf8) | |
| 184 | 469 { |
| 842 | 470 char *remote_charsets, *ret, *fromset, *toset, *stpos, *cur_charset; |
| 471 GError * error; | |
| 838 | 472 gsize bread; |
| 184 | 473 |
| 188 | 474 if (request == NULL) |
| 475 return (NULL); | |
| 476 | |
| 842 | 477 if (g_utf8_validate (str, -1, NULL) != from_utf8) |
| 579 | 478 return (NULL); |
| 842 | 479 |
| 480 error = NULL; | |
| 481 gftp_lookup_request_option (request, "remote_charsets", &remote_charsets); | |
| 845 | 482 if (*remote_charsets == '\0' || request->use_local_encoding || |
| 483 force_local == 1) | |
| 582 | 484 { |
| 842 | 485 if (from_utf8) |
| 845 | 486 { |
| 487 if (is_filename) | |
| 488 ret = g_filename_from_utf8 (str, -1, &bread, dest_len, &error); | |
| 489 else | |
| 490 ret = g_locale_from_utf8 (str, -1, &bread, dest_len, &error); | |
| 491 } | |
| 842 | 492 else |
| 845 | 493 { |
| 494 if (is_filename) | |
| 495 ret = g_filename_to_utf8 (str, -1, &bread, dest_len, &error); | |
| 496 else | |
| 497 ret = g_locale_to_utf8 (str, -1, &bread, dest_len, &error); | |
| 498 } | |
| 842 | 499 |
| 582 | 500 if (ret == NULL) |
| 842 | 501 _do_show_iconv_error (str, request->iconv_charset, from_utf8, error); |
| 582 | 502 |
| 503 return (ret); | |
| 504 } | |
| 184 | 505 |
| 842 | 506 if (request->iconv_initialized) |
| 184 | 507 { |
| 842 | 508 ret = g_convert_with_iconv (str, -1, request->iconv, &bread, dest_len, |
| 509 &error); | |
| 510 if (ret == NULL) | |
| 511 _do_show_iconv_error (str, request->iconv_charset, from_utf8, error); | |
| 512 | |
| 513 return (ret); | |
| 184 | 514 } |
| 515 | |
| 516 stpos = remote_charsets; | |
| 423 | 517 while ((cur_charset = _gftp_get_next_charset (&stpos)) != NULL) |
| 184 | 518 { |
| 842 | 519 if (from_utf8) |
| 520 { | |
| 521 fromset = "UTF-8"; | |
| 522 toset = cur_charset; | |
| 523 } | |
| 524 else | |
| 525 { | |
| 526 fromset = cur_charset; | |
| 527 toset = "UTF-8"; | |
| 528 } | |
| 529 | |
| 530 if ((request->iconv = g_iconv_open (toset, fromset)) == (GIConv) -1) | |
| 531 { | |
| 532 g_free (cur_charset); | |
| 533 continue; | |
| 534 } | |
| 184 | 535 |
| 536 error = NULL; | |
| 838 | 537 if ((ret = g_convert_with_iconv (str, -1, request->iconv, &bread, |
| 538 dest_len, &error)) == NULL) | |
| 184 | 539 { |
| 540 g_iconv_close (request->iconv); | |
| 541 request->iconv = NULL; | |
| 842 | 542 _do_show_iconv_error (str, cur_charset, from_utf8, error); |
| 543 g_free (cur_charset); | |
| 184 | 544 } |
| 842 | 545 |
| 546 request->iconv_initialized = 1; | |
| 547 request->iconv_charset = cur_charset; | |
| 548 return (ret); | |
| 184 | 549 } |
| 550 | |
| 842 | 551 return (NULL); |
| 552 } | |
| 553 | |
| 845 | 554 char * |
| 842 | 555 gftp_string_to_utf8 (gftp_request * request, const char *str, size_t *dest_len) |
| 556 { | |
| 845 | 557 return (_do_convert_string (request, 0, 0, str, dest_len, 0)); |
| 184 | 558 } |
| 291 | 559 |
| 560 | |
| 561 char * | |
| 845 | 562 gftp_string_from_utf8 (gftp_request * request, int force_local, const char *str, |
| 838 | 563 size_t *dest_len) |
| 291 | 564 { |
| 845 | 565 return (_do_convert_string (request, 0, force_local, str, dest_len, 1)); |
| 566 } | |
| 567 | |
| 568 | |
| 569 char * | |
| 570 gftp_filename_to_utf8 (gftp_request * request, const char *str, | |
| 571 size_t *dest_len) | |
| 572 { | |
| 573 return (_do_convert_string (request, 1, 0, str, dest_len, 0)); | |
| 574 } | |
| 575 | |
| 576 | |
| 577 char * | |
| 578 gftp_filename_from_utf8 (gftp_request * request, const char *str, | |
| 579 size_t *dest_len) | |
| 580 { | |
| 581 return (_do_convert_string (request, 1, 0, str, dest_len, 1)); | |
| 291 | 582 } |
| 583 | |
| 584 #else | |
| 585 | |
| 586 char * | |
| 838 | 587 gftp_string_to_utf8 (gftp_request * request, const char *str, size_t dest_len) |
| 291 | 588 { |
| 589 return (NULL); | |
| 590 } | |
| 591 | |
| 592 | |
| 593 char * | |
| 845 | 594 gftp_string_from_utf8 (gftp_request * request, int force_local, const char *str, |
| 595 size_t dest_len) | |
| 596 { | |
| 597 return (NULL); | |
| 598 } | |
| 599 | |
| 600 | |
| 601 char * | |
| 602 gftp_filename_to_utf8 (gftp_request * request, const char *str, size_t dest_len) | |
| 603 { | |
| 604 return (NULL); | |
| 605 } | |
| 606 | |
| 607 | |
| 608 char * | |
| 609 gftp_filename_from_utf8 (gftp_request * request, int force_local, | |
| 610 const char *str, size_t dest_len) | |
| 291 | 611 { |
| 612 return (NULL); | |
| 613 } | |
| 614 | |
| 184 | 615 #endif |
| 616 | |
| 617 | |
| 1 | 618 int |
| 377 | 619 gftp_get_next_file (gftp_request * request, const char *filespec, |
| 620 gftp_file * fle) | |
| 1 | 621 { |
| 830 | 622 char *slashpos, *tmpfile, *utf8; |
| 838 | 623 size_t destlen; |
| 58 | 624 int fd, ret; |
| 1 | 625 |
| 84 | 626 g_return_val_if_fail (request != NULL, GFTP_EFATAL); |
| 1 | 627 |
| 628 if (request->get_next_file == NULL) | |
| 84 | 629 return (GFTP_EFATAL); |
| 1 | 630 |
| 58 | 631 if (request->cached && request->cachefd > 0) |
| 1 | 632 fd = request->cachefd; |
| 633 else | |
| 634 fd = request->datafd; | |
| 635 | |
| 636 memset (fle, 0, sizeof (*fle)); | |
| 637 do | |
| 638 { | |
| 598 | 639 gftp_file_destroy (fle, 0); |
| 1 | 640 ret = request->get_next_file (request, fle, fd); |
| 666 | 641 if (fle->file != NULL && (slashpos = strrchr (fle->file, '/')) != NULL) |
| 642 { | |
| 643 if (*(slashpos + 1) == '\0') | |
| 644 { | |
| 645 gftp_file_destroy (fle, 0); | |
| 646 continue; | |
| 647 } | |
| 648 | |
| 649 *slashpos = '\0'; | |
| 830 | 650 tmpfile = g_strdup (slashpos + 1); |
| 666 | 651 |
| 652 if (strcmp (fle->file, request->directory) != 0) | |
| 653 request->logging_function (gftp_logging_error, request, | |
| 654 _("Warning: Stripping path off of file '%s'. The stripped path (%s) doesn't match the current directory (%s)\n"), | |
| 830 | 655 tmpfile, fle->file, request->directory, |
| 666 | 656 g_strerror (errno)); |
| 657 | |
| 658 g_free (fle->file); | |
| 830 | 659 fle->file = tmpfile; |
| 666 | 660 } |
| 1 | 661 |
| 291 | 662 if (ret >= 0 && fle->file != NULL) |
| 830 | 663 { |
| 845 | 664 utf8 = gftp_filename_to_utf8 (request, fle->file, &destlen); |
| 830 | 665 if (utf8 != NULL) |
| 666 { | |
| 667 tmpfile = fle->file; | |
| 668 fle->file = utf8; | |
| 669 g_free (tmpfile); | |
| 670 } | |
| 671 } | |
| 45 | 672 |
| 60 | 673 if (ret >= 0 && !request->cached && request->cachefd > 0 && |
| 1 | 674 request->last_dir_entry != NULL) |
| 675 { | |
| 168 | 676 if (gftp_fd_write (request, request->last_dir_entry, |
| 60 | 677 request->last_dir_entry_len, request->cachefd) < 0) |
| 1 | 678 { |
| 186 | 679 request->logging_function (gftp_logging_error, request, |
| 1 | 680 _("Error: Cannot write to cache: %s\n"), |
| 681 g_strerror (errno)); | |
| 60 | 682 close (request->cachefd); |
| 683 request->cachefd = -1; | |
| 1 | 684 } |
| 685 } | |
| 821 | 686 } while (ret > 0 && !gftp_match_filespec (request, fle->file, filespec)); |
| 1 | 687 |
| 688 return (ret); | |
| 689 } | |
| 690 | |
| 691 | |
| 692 int | |
| 243 | 693 gftp_parse_bookmark (gftp_request * request, gftp_request * local_request, |
| 275 | 694 const char * bookmark, int *refresh_local) |
| 87 | 695 { |
| 696 gftp_logging_func logging_function; | |
| 122 | 697 gftp_bookmarks_var * tempentry; |
| 838 | 698 char *default_protocol; |
| 646 | 699 const char *email; |
| 173 | 700 int i, init_ret; |
| 838 | 701 size_t destlen; |
| 87 | 702 |
| 703 g_return_val_if_fail (request != NULL, GFTP_EFATAL); | |
| 704 g_return_val_if_fail (bookmark != NULL, GFTP_EFATAL); | |
| 705 | |
| 706 logging_function = request->logging_function; | |
| 707 gftp_request_destroy (request, 0); | |
| 708 request->logging_function = logging_function; | |
| 709 | |
| 122 | 710 if ((tempentry = g_hash_table_lookup (gftp_bookmarks_htable, |
| 711 bookmark)) == NULL) | |
| 87 | 712 { |
| 186 | 713 request->logging_function (gftp_logging_error, request, |
| 87 | 714 _("Error: Could not find bookmark %s\n"), |
| 715 bookmark); | |
| 716 return (GFTP_EFATAL); | |
| 717 } | |
| 718 else if (tempentry->hostname == NULL || *tempentry->hostname == '\0') | |
| 719 { | |
| 186 | 720 request->logging_function (gftp_logging_error, request, |
| 87 | 721 _("Bookmarks Error: The bookmark entry %s does not have a hostname\n"), bookmark); |
| 722 return (GFTP_EFATAL); | |
| 723 } | |
| 724 | |
| 725 if (tempentry->user != NULL) | |
| 726 gftp_set_username (request, tempentry->user); | |
| 727 | |
| 728 if (tempentry->pass != NULL) | |
| 646 | 729 { |
| 730 if (strcmp (tempentry->pass, "@EMAIL@") == 0) | |
| 731 { | |
| 732 gftp_lookup_request_option (request, "email", &email); | |
| 733 gftp_set_password (request, email); | |
| 734 } | |
| 735 else | |
| 736 gftp_set_password (request, tempentry->pass); | |
| 737 } | |
| 87 | 738 |
| 739 if (tempentry->acct != NULL) | |
| 740 gftp_set_account (request, tempentry->acct); | |
| 741 | |
| 742 gftp_set_hostname (request, tempentry->hostname); | |
| 838 | 743 gftp_set_directory (request, tempentry->remote_dir); |
| 87 | 744 gftp_set_port (request, tempentry->port); |
| 745 | |
| 516 | 746 if (local_request != NULL && tempentry->local_dir != NULL && |
| 243 | 747 *tempentry->local_dir != '\0') |
| 275 | 748 { |
| 838 | 749 gftp_set_directory (local_request, tempentry->local_dir); |
| 516 | 750 if (refresh_local != NULL) |
| 751 *refresh_local = 1; | |
| 275 | 752 } |
| 516 | 753 else if (refresh_local != NULL) |
| 275 | 754 *refresh_local = 0; |
| 243 | 755 |
| 87 | 756 for (i = 0; gftp_protocols[i].name; i++) |
| 757 { | |
| 758 if (strcmp (gftp_protocols[i].name, tempentry->protocol) == 0) | |
| 759 { | |
| 173 | 760 if ((init_ret = gftp_protocols[i].init (request)) < 0) |
| 761 { | |
| 762 gftp_request_destroy (request, 0); | |
| 763 return (init_ret); | |
| 764 } | |
| 87 | 765 break; |
| 766 } | |
| 767 } | |
| 768 | |
| 122 | 769 if (gftp_protocols[i].name == NULL) |
| 87 | 770 { |
| 122 | 771 gftp_lookup_request_option (request, "default_protocol", |
| 772 &default_protocol); | |
| 773 | |
| 125 | 774 if (default_protocol != NULL && *default_protocol != '\0') |
| 87 | 775 { |
| 122 | 776 for (i = 0; gftp_protocols[i].url_prefix; i++) |
| 777 { | |
| 778 if (strcmp (gftp_protocols[i].name, default_protocol) == 0) | |
| 779 break; | |
| 780 } | |
| 87 | 781 } |
| 782 | |
| 783 if (gftp_protocols[i].url_prefix == NULL) | |
| 784 i = GFTP_FTP_NUM; | |
| 785 } | |
| 786 | |
| 199 | 787 gftp_copy_local_options (&request->local_options_vars, |
| 788 &request->local_options_hash, | |
| 429 | 789 &request->num_local_options_vars, |
| 199 | 790 tempentry->local_options_vars, |
| 791 tempentry->num_local_options_vars); | |
| 792 | |
| 173 | 793 if ((init_ret = gftp_protocols[i].init (request)) < 0) |
| 794 { | |
| 795 gftp_request_destroy (request, 0); | |
| 796 return (init_ret); | |
| 797 } | |
| 798 | |
| 87 | 799 return (0); |
| 800 } | |
| 801 | |
| 802 | |
| 803 int | |
| 1 | 804 gftp_parse_url (gftp_request * request, const char *url) |
| 805 { | |
| 676 | 806 char *pos, *endpos, *default_protocol, *new_url; |
| 67 | 807 gftp_logging_func logging_function; |
| 676 | 808 const char *clear_pos; |
| 809 int i, ret; | |
| 1 | 810 |
| 84 | 811 g_return_val_if_fail (request != NULL, GFTP_EFATAL); |
| 812 g_return_val_if_fail (url != NULL, GFTP_EFATAL); | |
| 1 | 813 |
| 67 | 814 logging_function = request->logging_function; |
| 815 gftp_request_destroy (request, 0); | |
| 816 request->logging_function = logging_function; | |
| 817 | |
| 676 | 818 for (clear_pos = url; |
| 819 *clear_pos == ' ' || *clear_pos == '\t'; | |
| 820 clear_pos++); | |
| 821 | |
| 822 new_url = g_strdup (clear_pos); | |
| 823 | |
| 824 for (pos = new_url + strlen (new_url) - 1; | |
| 825 *pos == ' ' || *pos == '\t'; | |
| 826 pos--) | |
| 168 | 827 *pos = '\0'; |
| 1 | 828 |
| 676 | 829 /* See if the URL has a protocol... */ |
| 830 if ((pos = strstr (new_url, "://")) != NULL) | |
| 1 | 831 { |
| 832 *pos = '\0'; | |
| 833 | |
| 834 for (i = 0; gftp_protocols[i].url_prefix; i++) | |
| 835 { | |
| 676 | 836 if (strcmp (gftp_protocols[i].url_prefix, new_url) == 0) |
| 1 | 837 break; |
| 838 } | |
| 839 | |
| 840 if (gftp_protocols[i].url_prefix == NULL) | |
| 168 | 841 { |
| 677 | 842 request->logging_function (gftp_logging_error, NULL, |
| 173 | 843 _("The protocol '%s' is currently not supported.\n"), |
| 676 | 844 new_url); |
| 845 g_free (new_url); | |
| 168 | 846 return (GFTP_EFATAL); |
| 847 } | |
| 173 | 848 |
| 849 *pos = ':'; | |
| 676 | 850 pos += 3; |
| 1 | 851 } |
| 852 else | |
| 853 { | |
| 122 | 854 gftp_lookup_request_option (request, "default_protocol", |
| 855 &default_protocol); | |
| 856 | |
| 676 | 857 i = GFTP_FTP_NUM; |
| 125 | 858 if (default_protocol != NULL && *default_protocol != '\0') |
| 1 | 859 { |
| 122 | 860 for (i = 0; gftp_protocols[i].url_prefix; i++) |
| 861 { | |
| 862 if (strcmp (gftp_protocols[i].name, default_protocol) == 0) | |
| 863 break; | |
| 864 } | |
| 1 | 865 } |
| 676 | 866 |
| 867 if (gftp_protocols[i].url_prefix == NULL) | |
| 868 { | |
| 677 | 869 request->logging_function (gftp_logging_error, NULL, |
| 676 | 870 _("The protocol '%s' is currently not supported.\n"), |
| 871 default_protocol); | |
| 872 g_free (new_url); | |
| 873 return (GFTP_EFATAL); | |
| 874 } | |
| 875 | |
| 876 pos = new_url; | |
| 122 | 877 } |
| 1 | 878 |
| 676 | 879 if ((ret = gftp_protocols[i].init (request)) < 0) |
| 173 | 880 { |
| 881 gftp_request_destroy (request, 0); | |
| 676 | 882 return (ret); |
| 883 } | |
| 884 | |
| 885 if ((endpos = strchr (pos, '/')) != NULL) | |
| 886 { | |
| 887 gftp_set_directory (request, endpos); | |
| 888 *endpos = '\0'; | |
| 173 | 889 } |
| 1 | 890 |
| 891 if (request->parse_url != NULL) | |
| 168 | 892 { |
| 676 | 893 ret = request->parse_url (request, new_url); |
| 894 g_free (new_url); | |
| 895 return (ret); | |
| 168 | 896 } |
| 897 | |
| 676 | 898 if (*pos != '\0') |
| 1 | 899 { |
| 676 | 900 if (endpos == NULL) |
| 901 endpos = pos + strlen (pos) - 1; | |
| 902 else | |
| 903 endpos--; | |
| 904 | |
| 905 for (; isdigit (*endpos); endpos--); | |
| 906 | |
| 907 if (*endpos == ':' && isdigit (*(endpos + 1))) | |
| 168 | 908 { |
| 676 | 909 gftp_set_port (request, strtol (endpos + 1, NULL, 10)); |
| 910 *endpos = '\0'; | |
| 168 | 911 } |
| 1 | 912 |
| 676 | 913 if ((endpos = strrchr (pos, '@')) != NULL) |
| 168 | 914 { |
| 676 | 915 gftp_set_hostname (request, endpos + 1); |
| 168 | 916 *endpos = '\0'; |
| 676 | 917 |
| 918 if ((endpos = strchr (pos, ':')) != NULL) | |
| 919 { | |
| 920 *endpos = '\0'; | |
| 921 gftp_set_username (request, pos); | |
| 922 gftp_set_password (request, endpos + 1); | |
| 923 } | |
| 924 else | |
| 925 { | |
| 926 gftp_set_username (request, pos); | |
| 927 gftp_set_password (request, ""); | |
| 928 } | |
| 168 | 929 } |
| 676 | 930 else |
| 931 gftp_set_hostname (request, pos); | |
| 1 | 932 } |
| 933 | |
| 676 | 934 g_free (new_url); |
| 1 | 935 return (0); |
| 936 } | |
| 937 | |
| 938 | |
| 939 void | |
| 940 gftp_set_hostname (gftp_request * request, const char *hostname) | |
| 941 { | |
| 942 g_return_if_fail (request != NULL); | |
| 943 g_return_if_fail (hostname != NULL); | |
| 944 | |
| 945 if (request->hostname) | |
| 946 g_free (request->hostname); | |
| 124 | 947 request->hostname = g_strdup (hostname); |
| 1 | 948 } |
| 949 | |
| 950 | |
| 951 void | |
| 952 gftp_set_username (gftp_request * request, const char *username) | |
| 953 { | |
| 954 g_return_if_fail (request != NULL); | |
| 955 | |
| 956 if (request->username) | |
| 957 g_free (request->username); | |
| 169 | 958 |
| 959 if (username != NULL) | |
| 960 request->username = g_strdup (username); | |
| 961 else | |
| 962 request->username = NULL; | |
| 1 | 963 } |
| 964 | |
| 965 | |
| 966 void | |
| 967 gftp_set_password (gftp_request * request, const char *password) | |
| 968 { | |
| 969 g_return_if_fail (request != NULL); | |
| 970 | |
| 971 if (request->password) | |
| 972 g_free (request->password); | |
| 169 | 973 |
| 974 if (password != NULL) | |
| 975 request->password = g_strdup (password); | |
| 976 else | |
| 977 request->password = NULL; | |
| 1 | 978 } |
| 979 | |
| 980 | |
| 981 void | |
| 982 gftp_set_account (gftp_request * request, const char *account) | |
| 983 { | |
| 984 g_return_if_fail (request != NULL); | |
| 985 g_return_if_fail (account != NULL); | |
| 986 | |
| 987 if (request->account) | |
| 988 g_free (request->account); | |
| 124 | 989 request->account = g_strdup (account); |
| 1 | 990 } |
| 991 | |
| 992 | |
| 993 int | |
| 994 gftp_set_directory (gftp_request * request, const char *directory) | |
| 995 { | |
| 84 | 996 g_return_val_if_fail (request != NULL, GFTP_EFATAL); |
| 997 g_return_val_if_fail (directory != NULL, GFTP_EFATAL); | |
| 1 | 998 |
| 999 | |
| 169 | 1000 if (request->datafd <= 0 && !request->always_connected) |
| 1 | 1001 { |
| 1002 if (directory != request->directory) | |
| 168 | 1003 { |
| 1004 if (request->directory) | |
| 1005 g_free (request->directory); | |
| 1006 request->directory = g_strdup (directory); | |
| 1007 } | |
| 1 | 1008 return (0); |
| 1009 } | |
| 1010 else if (request->chdir == NULL) | |
| 84 | 1011 return (GFTP_EFATAL); |
| 1 | 1012 return (request->chdir (request, directory)); |
| 1013 } | |
| 1014 | |
| 1015 | |
| 1016 void | |
| 1017 gftp_set_port (gftp_request * request, unsigned int port) | |
| 1018 { | |
| 1019 g_return_if_fail (request != NULL); | |
| 1020 | |
| 1021 request->port = port; | |
| 1022 } | |
| 1023 | |
| 1024 | |
| 1025 int | |
| 1026 gftp_remove_directory (gftp_request * request, const char *directory) | |
| 1027 { | |
| 84 | 1028 g_return_val_if_fail (request != NULL, GFTP_EFATAL); |
| 1 | 1029 |
| 1030 if (request->rmdir == NULL) | |
| 84 | 1031 return (GFTP_EFATAL); |
| 1 | 1032 return (request->rmdir (request, directory)); |
| 1033 } | |
| 1034 | |
| 1035 | |
| 1036 int | |
| 1037 gftp_remove_file (gftp_request * request, const char *file) | |
| 1038 { | |
| 84 | 1039 g_return_val_if_fail (request != NULL, GFTP_EFATAL); |
| 1 | 1040 |
| 1041 if (request->rmfile == NULL) | |
| 84 | 1042 return (GFTP_EFATAL); |
| 1 | 1043 return (request->rmfile (request, file)); |
| 1044 } | |
| 1045 | |
| 1046 | |
| 1047 int | |
| 1048 gftp_make_directory (gftp_request * request, const char *directory) | |
| 1049 { | |
| 291 | 1050 int ret; |
| 1051 | |
| 84 | 1052 g_return_val_if_fail (request != NULL, GFTP_EFATAL); |
| 1 | 1053 |
| 1054 if (request->mkdir == NULL) | |
| 84 | 1055 return (GFTP_EFATAL); |
| 291 | 1056 |
| 838 | 1057 return (request->mkdir (request, directory)); |
| 1 | 1058 } |
| 1059 | |
| 1060 | |
| 1061 int | |
| 1062 gftp_rename_file (gftp_request * request, const char *oldname, | |
| 168 | 1063 const char *newname) |
| 1 | 1064 { |
| 291 | 1065 int ret; |
| 1066 | |
| 84 | 1067 g_return_val_if_fail (request != NULL, GFTP_EFATAL); |
| 1 | 1068 |
| 1069 if (request->rename == NULL) | |
| 84 | 1070 return (GFTP_EFATAL); |
| 291 | 1071 |
| 838 | 1072 return (request->rename (request, oldname, newname)); |
| 1 | 1073 } |
| 1074 | |
| 1075 | |
| 1076 int | |
| 499 | 1077 gftp_chmod (gftp_request * request, const char *file, mode_t mode) |
| 1 | 1078 { |
| 84 | 1079 g_return_val_if_fail (request != NULL, GFTP_EFATAL); |
| 1 | 1080 |
| 1081 if (request->chmod == NULL) | |
| 84 | 1082 return (GFTP_EFATAL); |
| 504 | 1083 |
| 1084 mode &= S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX; | |
| 1 | 1085 return (request->chmod (request, file, mode)); |
| 1086 } | |
| 1087 | |
| 1088 | |
| 1089 int | |
| 1090 gftp_set_file_time (gftp_request * request, const char *file, time_t datetime) | |
| 1091 { | |
| 84 | 1092 g_return_val_if_fail (request != NULL, GFTP_EFATAL); |
| 1 | 1093 |
| 1094 if (request->set_file_time == NULL) | |
| 84 | 1095 return (GFTP_EFATAL); |
| 1 | 1096 return (request->set_file_time (request, file, datetime)); |
| 1097 } | |
| 1098 | |
| 1099 | |
| 765 | 1100 int |
| 478 | 1101 gftp_site_cmd (gftp_request * request, int specify_site, const char *command) |
| 1 | 1102 { |
| 84 | 1103 g_return_val_if_fail (request != NULL, GFTP_EFATAL); |
| 1 | 1104 |
| 1105 if (request->site == NULL) | |
| 84 | 1106 return (GFTP_EFATAL); |
| 478 | 1107 return (request->site (request, specify_site, command)); |
| 1 | 1108 } |
| 1109 | |
| 1110 | |
| 58 | 1111 off_t |
| 1 | 1112 gftp_get_file_size (gftp_request * request, const char *filename) |
| 1113 { | |
| 1114 g_return_val_if_fail (request != NULL, 0); | |
| 1115 | |
| 1116 if (request->get_file_size == NULL) | |
| 1117 return (0); | |
| 1118 return (request->get_file_size (request, filename)); | |
| 1119 } | |
| 1120 | |
| 1121 | |
| 122 | 1122 static int |
| 1123 gftp_need_proxy (gftp_request * request, char *service, char *proxy_hostname, | |
| 518 | 1124 unsigned int proxy_port) |
| 1 | 1125 { |
| 122 | 1126 gftp_config_list_vars * proxy_hosts; |
| 1 | 1127 gftp_proxy_hosts * hostname; |
| 460 | 1128 size_t hostlen, domlen; |
| 1 | 1129 unsigned char addy[4]; |
| 1130 struct sockaddr *addr; | |
| 1131 GList * templist; | |
| 1132 gint32 netaddr; | |
| 1133 char *pos; | |
| 1134 #if defined (HAVE_GETADDRINFO) && defined (HAVE_GAI_STRERROR) | |
| 1135 struct addrinfo hints; | |
| 516 | 1136 unsigned int port; |
| 1137 int errnum; | |
| 1 | 1138 char serv[8]; |
| 122 | 1139 #endif |
| 1140 | |
| 218 | 1141 gftp_lookup_global_option ("dont_use_proxy", &proxy_hosts); |
| 122 | 1142 |
| 1143 if (proxy_hostname == NULL || *proxy_hostname == '\0') | |
| 1144 return (0); | |
| 1145 else if (proxy_hosts->list == NULL) | |
| 1146 return (proxy_hostname != NULL && | |
| 1147 *proxy_hostname != '\0'); | |
| 1 | 1148 |
| 1149 request->hostp = NULL; | |
| 122 | 1150 #if defined (HAVE_GETADDRINFO) && defined (HAVE_GAI_STRERROR) |
| 151 | 1151 request->free_hostp = 1; |
| 1 | 1152 memset (&hints, 0, sizeof (hints)); |
| 1153 hints.ai_flags = AI_CANONNAME; | |
| 146 | 1154 hints.ai_family = PF_UNSPEC; |
| 1 | 1155 hints.ai_socktype = SOCK_STREAM; |
| 1156 | |
| 122 | 1157 port = request->use_proxy ? proxy_port : request->port; |
| 1 | 1158 if (port == 0) |
| 1159 strcpy (serv, service); | |
| 1160 else | |
| 1161 snprintf (serv, sizeof (serv), "%d", port); | |
| 1162 | |
| 186 | 1163 request->logging_function (gftp_logging_misc, request, |
| 1 | 1164 _("Looking up %s\n"), request->hostname); |
| 1165 | |
| 1166 if ((errnum = getaddrinfo (request->hostname, serv, &hints, | |
| 1167 &request->hostp)) != 0) | |
| 1168 { | |
| 186 | 1169 request->logging_function (gftp_logging_error, request, |
| 1 | 1170 _("Cannot look up hostname %s: %s\n"), |
| 1171 request->hostname, gai_strerror (errnum)); | |
| 84 | 1172 return (GFTP_ERETRYABLE); |
| 1 | 1173 } |
| 1174 | |
| 1175 addr = request->hostp->ai_addr; | |
| 1176 | |
| 1177 #else /* !HAVE_GETADDRINFO */ | |
| 186 | 1178 request->logging_function (gftp_logging_misc, request, |
| 1 | 1179 _("Looking up %s\n"), request->hostname); |
| 1180 | |
| 1181 if (!(request->hostp = r_gethostbyname (request->hostname, &request->host, | |
| 1182 NULL))) | |
| 1183 { | |
| 186 | 1184 request->logging_function (gftp_logging_error, request, |
| 1 | 1185 _("Cannot look up hostname %s: %s\n"), |
| 1186 request->hostname, g_strerror (errno)); | |
| 84 | 1187 return (GFTP_ERETRYABLE); |
| 1 | 1188 } |
| 1189 | |
| 1190 addr = (struct sockaddr *) request->host.h_addr_list[0]; | |
| 1191 | |
| 1192 #endif /* HAVE_GETADDRINFO */ | |
| 1193 | |
| 122 | 1194 templist = proxy_hosts->list; |
| 1 | 1195 while (templist != NULL) |
| 1196 { | |
| 1197 hostname = templist->data; | |
| 460 | 1198 if (hostname->domain != NULL) |
| 168 | 1199 { |
| 460 | 1200 hostlen = strlen (request->hostname); |
| 1201 domlen = strlen (hostname->domain); | |
| 1202 if (hostlen > domlen) | |
| 1203 { | |
| 1204 pos = request->hostname + hostlen - domlen; | |
| 1205 if (strcmp (hostname->domain, pos) == 0) | |
| 1206 return (0); | |
| 1207 } | |
| 168 | 1208 } |
| 1 | 1209 |
| 1210 if (hostname->ipv4_network_address != 0) | |
| 168 | 1211 { |
| 516 | 1212 memcpy (addy, addr, sizeof (*addy)); |
| 168 | 1213 netaddr = |
| 1214 (((addy[0] & 0xff) << 24) | ((addy[1] & 0xff) << 16) | | |
| 1215 ((addy[2] & 0xff) << 8) | (addy[3] & 0xff)) & | |
| 1 | 1216 hostname->ipv4_netmask; |
| 168 | 1217 if (netaddr == hostname->ipv4_network_address) |
| 1218 return (0); | |
| 1219 } | |
| 1 | 1220 templist = templist->next; |
| 1221 } | |
| 1222 | |
| 122 | 1223 return (proxy_hostname != NULL && *proxy_hostname != '\0'); |
| 1 | 1224 } |
| 1225 | |
| 1226 | |
| 48 | 1227 static char * |
| 765 | 1228 copy_token (/*@out@*/ char **dest, char *source) |
| 1 | 1229 { |
| 48 | 1230 /* This function is used internally by gftp_parse_ls () */ |
| 1231 char *endpos, savepos; | |
| 1 | 1232 |
| 48 | 1233 endpos = source; |
| 1234 while (*endpos != ' ' && *endpos != '\t' && *endpos != '\0') | |
| 1235 endpos++; | |
| 1236 if (*endpos == '\0') | |
| 765 | 1237 { |
| 1238 *dest = NULL; | |
| 1239 return (NULL); | |
| 1240 } | |
| 1 | 1241 |
| 48 | 1242 savepos = *endpos; |
| 1243 *endpos = '\0'; | |
| 765 | 1244 *dest = g_malloc ((gulong) (endpos - source + 1)); |
| 48 | 1245 strcpy (*dest, source); |
| 1246 *endpos = savepos; | |
| 1 | 1247 |
| 48 | 1248 /* Skip the blanks till we get to the next entry */ |
| 1249 source = endpos + 1; | |
| 1250 while ((*source == ' ' || *source == '\t') && *source != '\0') | |
| 1251 source++; | |
| 1252 return (source); | |
| 1253 } | |
| 1 | 1254 |
| 1255 | |
| 48 | 1256 static char * |
| 1257 goto_next_token (char *pos) | |
| 1258 { | |
| 1259 while (*pos != ' ' && *pos != '\t' && *pos != '\0') | |
| 1260 pos++; | |
| 1 | 1261 |
| 516 | 1262 while (*pos == ' ' || *pos == '\t') |
| 48 | 1263 pos++; |
| 1264 | |
| 1265 return (pos); | |
| 1 | 1266 } |
| 1267 | |
| 1268 | |
| 485 | 1269 static time_t |
| 1270 parse_vms_time (char *str, char **endpos) | |
| 1271 { | |
| 1272 struct tm curtime; | |
| 1273 time_t ret; | |
| 1274 | |
| 1275 /* 8-JUN-2004 13:04:14 */ | |
| 1276 memset (&curtime, 0, sizeof (curtime)); | |
| 1277 | |
| 1278 *endpos = strptime (str, "%d-%b-%Y %H:%M:%S", &curtime); | |
| 1279 if (*endpos == NULL) | |
| 1280 *endpos = strptime (str, "%d-%b-%Y %H:%M", &curtime); | |
| 1281 | |
| 1282 if (*endpos != NULL) | |
| 1283 { | |
| 1284 ret = mktime (&curtime); | |
| 1285 for (; **endpos == ' ' || **endpos == '\t'; (*endpos)++); | |
| 1286 } | |
| 1287 else | |
| 1288 { | |
| 1289 ret = 0; | |
| 1290 *endpos = goto_next_token (str); | |
| 1291 if (*endpos != NULL) | |
| 1292 *endpos = goto_next_token (*endpos); | |
| 1293 } | |
| 1294 | |
| 1295 return (ret); | |
| 1296 } | |
| 1297 | |
| 1298 | |
| 102 | 1299 time_t |
| 1300 parse_time (char *str, char **endpos) | |
| 1 | 1301 { |
| 102 | 1302 struct tm curtime, *loctime; |
| 105 | 1303 time_t t, ret; |
| 102 | 1304 char *tmppos; |
| 460 | 1305 size_t slen; |
| 260 | 1306 int i, num; |
| 1 | 1307 |
| 460 | 1308 slen = strlen (str); |
| 102 | 1309 memset (&curtime, 0, sizeof (curtime)); |
| 1310 curtime.tm_isdst = -1; | |
| 460 | 1311 |
| 1312 if (slen > 4 && isdigit ((int) str[0]) && str[2] == '-' && | |
| 260 | 1313 isdigit ((int) str[3])) |
| 1 | 1314 { |
| 1315 /* This is how DOS will return the date/time */ | |
| 1316 /* 07-06-99 12:57PM */ | |
| 1317 | |
| 102 | 1318 tmppos = strptime (str, "%m-%d-%y %I:%M%p", &curtime); |
| 1 | 1319 } |
| 460 | 1320 else if (slen > 4 && isdigit ((int) str[0]) && str[2] == '-' && |
| 260 | 1321 isalpha (str[3])) |
| 105 | 1322 { |
| 1323 /* 10-Jan-2003 09:14 */ | |
| 1324 tmppos = strptime (str, "%d-%h-%Y %H:%M", &curtime); | |
| 1325 } | |
| 460 | 1326 else if (slen > 4 && isdigit ((int) str[0]) && str[4] == '/') |
| 358 | 1327 { |
| 1328 /* 2003/12/25 */ | |
| 1329 tmppos = strptime (str, "%Y/%m/%d", &curtime); | |
| 1330 } | |
| 1 | 1331 else |
| 1332 { | |
| 1333 /* This is how most UNIX, Novell, and MacOS ftp servers send their time */ | |
| 102 | 1334 /* Jul 06 12:57 or Jul 6 1999 */ |
| 1 | 1335 |
| 102 | 1336 if (strchr (str, ':') != NULL) |
| 1337 { | |
| 1338 tmppos = strptime (str, "%h %d %H:%M", &curtime); | |
| 1339 t = time (NULL); | |
| 1340 loctime = localtime (&t); | |
| 359 | 1341 |
| 1342 if (curtime.tm_mon > loctime->tm_mon) | |
| 1343 curtime.tm_year = loctime->tm_year - 1; | |
| 1344 else | |
| 1345 curtime.tm_year = loctime->tm_year; | |
| 102 | 1346 } |
| 1347 else | |
| 1348 tmppos = strptime (str, "%h %d %Y", &curtime); | |
| 1349 } | |
| 1 | 1350 |
| 105 | 1351 if (tmppos != NULL) |
| 1352 ret = mktime (&curtime); | |
| 1353 else | |
| 1354 ret = 0; | |
| 1355 | |
| 102 | 1356 if (endpos != NULL) |
| 105 | 1357 { |
| 1358 if (tmppos == NULL) | |
| 1359 { | |
| 260 | 1360 /* We cannot parse this date format. So, just skip this date field |
| 1361 and continue to the next token. This is mainly for the HTTP | |
| 1362 support */ | |
| 1363 | |
| 1364 *endpos = str; | |
| 1365 for (num = 0; num < 2 && **endpos != '\0'; num++) | |
| 1366 { | |
| 1367 for (i=0; | |
| 1368 (*endpos)[i] != ' ' && (*endpos)[i] != '\t' && | |
| 1369 (*endpos)[i] != '\0'; | |
| 1370 i++); | |
| 1371 *endpos += i; | |
| 1372 | |
| 1373 for (i=0; (*endpos)[i] == ' ' || (*endpos)[i] == '\t'; i++); | |
| 1374 *endpos += i; | |
| 1375 } | |
| 105 | 1376 } |
| 1377 else | |
| 1378 *endpos = tmppos; | |
| 1379 } | |
| 1 | 1380 |
| 281 | 1381 return (ret); |
| 1 | 1382 } |
| 1383 | |
| 1384 | |
| 499 | 1385 static mode_t |
| 1386 gftp_parse_vms_attribs (char **src, mode_t mask) | |
| 107 | 1387 { |
| 1388 char *endpos; | |
| 499 | 1389 mode_t ret; |
| 107 | 1390 |
| 1391 if (*src == NULL) | |
| 499 | 1392 return (0); |
| 107 | 1393 |
| 1394 if ((endpos = strchr (*src, ',')) != NULL) | |
| 1395 *endpos = '\0'; | |
| 1396 | |
| 499 | 1397 ret = 0; |
| 107 | 1398 if (strchr (*src, 'R') != NULL) |
| 499 | 1399 ret |= S_IRUSR | S_IRGRP | S_IROTH; |
| 107 | 1400 if (strchr (*src, 'W') != NULL) |
| 499 | 1401 ret |= S_IWUSR | S_IWGRP | S_IWOTH; |
| 107 | 1402 if (strchr (*src, 'E') != NULL) |
| 499 | 1403 ret |= S_IXUSR | S_IXGRP | S_IXOTH; |
| 107 | 1404 |
| 1405 *src = endpos + 1; | |
| 499 | 1406 |
| 1407 return (ret & mask); | |
| 107 | 1408 } |
| 1409 | |
| 1410 | |
| 1411 static int | |
| 485 | 1412 gftp_parse_ls_vms (gftp_request * request, int fd, char *str, gftp_file * fle) |
| 107 | 1413 { |
| 485 | 1414 char *curpos, *endpos, tempstr[1024]; |
| 1415 int multiline; | |
| 1416 ssize_t len; | |
| 107 | 1417 |
| 1418 /* .PINE-DEBUG1;1 9 21-AUG-2002 20:06 [MYERSRG] (RWED,RWED,,) */ | |
| 1419 /* WWW.DIR;1 1 23-NOV-1999 05:47 [MYERSRG] (RWE,RWE,RE,E) */ | |
| 1420 | |
| 485 | 1421 /* Multiline VMS |
| 1422 $MAIN.TPU$JOURNAL;1 | |
| 1423 1/18 8-JUN-2004 13:04:14 [NUCLEAR,FISSION] (RWED,RWED,RE,) | |
| 1424 TCPIP$FTP_SERVER.LOG;29 | |
| 1425 0/18 8-JUN-2004 14:42:04 [NUCLEAR,FISSION] (RWED,RWED,RE,) | |
| 1426 TCPIP$FTP_SERVER.LOG;28 | |
| 1427 5/18 8-JUN-2004 13:05:11 [NUCLEAR,FISSION] (RWED,RWED,RE,) | |
| 1428 TCPIP$FTP_SERVER.LOG;27 | |
| 1429 5/18 8-JUN-2004 13:03:51 [NUCLEAR,FISSION] (RWED,RWED,RE,) */ | |
| 1430 | |
| 107 | 1431 if ((curpos = strchr (str, ';')) == NULL) |
| 1432 return (GFTP_EFATAL); | |
| 1433 | |
| 485 | 1434 multiline = strchr (str, ' ') == NULL; |
| 1435 | |
| 107 | 1436 *curpos = '\0'; |
| 1437 if (strlen (str) > 4 && strcmp (curpos - 4, ".DIR") == 0) | |
| 1438 { | |
| 499 | 1439 fle->st_mode |= S_IFDIR; |
| 107 | 1440 *(curpos - 4) = '\0'; |
| 1441 } | |
| 1442 | |
| 1443 fle->file = g_strdup (str); | |
| 1444 | |
| 485 | 1445 if (multiline) |
| 1446 { | |
| 1447 if (request->get_next_dirlist_line == NULL) | |
| 1448 return (GFTP_EFATAL); | |
| 1449 | |
| 1450 len = request->get_next_dirlist_line (request, fd, tempstr, | |
| 1451 sizeof (tempstr)); | |
| 1452 if (len <= 0) | |
| 1453 return ((int) len); | |
| 1454 | |
| 1455 for (curpos = tempstr; *curpos == ' ' || *curpos == '\t'; curpos++); | |
| 1456 } | |
| 1457 else | |
| 1458 curpos = goto_next_token (curpos + 1); | |
| 1459 | |
| 244 | 1460 fle->size = gftp_parse_file_size (curpos) * 512; /* Is this correct? */ |
| 107 | 1461 |
| 1462 curpos = goto_next_token (curpos); | |
| 1463 | |
| 485 | 1464 fle->datetime = parse_vms_time (curpos, &curpos); |
| 1465 | |
| 107 | 1466 if (*curpos != '[') |
| 1467 return (GFTP_EFATAL); | |
| 485 | 1468 |
| 107 | 1469 if ((endpos = strchr (curpos, ']')) == NULL) |
| 1470 return (GFTP_EFATAL); | |
| 1471 | |
| 1472 curpos = goto_next_token (endpos + 1); | |
| 1473 if ((curpos = strchr (curpos, ',')) == NULL) | |
| 1474 return (0); | |
| 1475 curpos++; | |
| 1476 | |
| 499 | 1477 fle->st_mode = gftp_parse_vms_attribs (&curpos, S_IRWXU); |
| 1478 fle->st_mode |= gftp_parse_vms_attribs (&curpos, S_IRWXG); | |
| 1479 fle->st_mode |= gftp_parse_vms_attribs (&curpos, S_IRWXO); | |
| 107 | 1480 |
| 485 | 1481 fle->user = g_strdup (""); |
| 1482 fle->group = g_strdup (""); | |
| 1483 | |
| 107 | 1484 return (0); |
| 1485 } | |
| 358 | 1486 |
| 1487 | |
| 1488 static int | |
| 1489 gftp_parse_ls_mvs (char *str, gftp_file * fle) | |
| 1490 { | |
| 1491 char *curpos; | |
| 1492 | |
| 1493 /* Volume Unit Referred Ext Used Recfm Lrecl BlkSz Dsorg Dsname */ | |
| 1494 /* SVI52A 3390 2003/12/10 8 216 FB 80 27920 PS CARDS.DELETES */ | |
| 1495 /* SVI528 3390 2003/12/12 1 5 FB 80 24000 PO CLIST */ | |
| 1496 | |
| 1497 curpos = goto_next_token (str + 1); | |
| 1498 if (curpos == NULL) | |
| 1499 return (GFTP_EFATAL); | |
| 1500 | |
| 1501 curpos = goto_next_token (curpos + 1); | |
| 1502 if (curpos == NULL) | |
| 1503 return (GFTP_EFATAL); | |
| 1504 | |
| 479 | 1505 fle->datetime = parse_time (curpos, &curpos); |
| 1506 | |
| 1507 curpos = goto_next_token (curpos); | |
| 1508 if (curpos == NULL) | |
| 358 | 1509 return (GFTP_EFATAL); |
| 1510 | |
| 1511 curpos = goto_next_token (curpos + 1); | |
| 1512 if (curpos == NULL) | |
| 1513 return (GFTP_EFATAL); | |
| 1514 | |
| 1515 fle->size = gftp_parse_file_size (curpos) * 55996; | |
| 1516 curpos = goto_next_token (curpos + 1); | |
| 1517 if (curpos == NULL) | |
| 1518 return (GFTP_EFATAL); | |
| 1519 | |
| 1520 curpos = goto_next_token (curpos + 1); | |
| 1521 if (curpos == NULL) | |
| 1522 return (GFTP_EFATAL); | |
| 1523 | |
| 1524 curpos = goto_next_token (curpos + 1); | |
| 1525 if (curpos == NULL) | |
| 1526 return (GFTP_EFATAL); | |
| 1527 | |
| 1528 curpos = goto_next_token (curpos + 1); | |
| 1529 if (curpos == NULL) | |
| 1530 return (GFTP_EFATAL); | |
| 1531 | |
| 1532 if (strncmp (curpos, "PS", 2) == 0) | |
| 499 | 1533 fle->st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; |
| 358 | 1534 else if (strncmp (curpos, "PO", 2) == 0) |
| 499 | 1535 fle->st_mode = S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; |
| 358 | 1536 else |
| 1537 return (GFTP_EFATAL); | |
| 1538 | |
| 1539 curpos = goto_next_token (curpos + 1); | |
| 1540 | |
| 1541 fle->user = g_strdup (_("unknown")); | |
| 1542 fle->group = g_strdup (_("unknown")); | |
| 1543 fle->file = g_strdup (curpos); | |
| 1544 | |
| 1545 return (0); | |
| 1546 } | |
| 107 | 1547 |
| 1548 | |
| 1 | 1549 static int |
| 1550 gftp_parse_ls_eplf (char *str, gftp_file * fle) | |
| 1551 { | |
| 1552 char *startpos; | |
| 358 | 1553 int isdir = 0; |
| 1 | 1554 |
| 1555 startpos = str; | |
| 1556 while (startpos) | |
| 1557 { | |
| 1558 startpos++; | |
| 1559 switch (*startpos) | |
| 168 | 1560 { |
| 516 | 1561 case '/': |
| 1562 isdir = 1; | |
| 1563 break; | |
| 1564 case 's': | |
| 1565 fle->size = gftp_parse_file_size (startpos + 1); | |
| 1566 break; | |
| 1567 case 'm': | |
| 1568 fle->datetime = strtol (startpos + 1, NULL, 10); | |
| 1569 break; | |
| 168 | 1570 } |
| 1 | 1571 startpos = strchr (startpos, ','); |
| 1572 } | |
| 358 | 1573 |
| 1 | 1574 if ((startpos = strchr (str, 9)) == NULL) |
| 84 | 1575 return (GFTP_EFATAL); |
| 358 | 1576 |
| 1577 if (isdir) | |
| 499 | 1578 fle->st_mode = S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; |
| 358 | 1579 else |
| 499 | 1580 fle->st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; |
| 358 | 1581 |
| 124 | 1582 fle->file = g_strdup (startpos + 1); |
| 1583 fle->user = g_strdup (_("unknown")); | |
| 1584 fle->group = g_strdup (_("unknown")); | |
| 1 | 1585 return (0); |
| 1586 } | |
| 1587 | |
| 1588 | |
| 1589 static int | |
| 460 | 1590 gftp_parse_ls_unix (gftp_request * request, char *str, size_t slen, |
| 1591 gftp_file * fle) | |
| 1 | 1592 { |
| 499 | 1593 char *endpos, *startpos, *pos, *attribs; |
| 91 | 1594 int cols; |
| 1595 | |
| 1596 /* If there is no space between the attribs and links field, just make one */ | |
| 460 | 1597 if (slen > 10) |
| 91 | 1598 str[10] = ' '; |
| 1599 | |
| 1600 /* Determine the number of columns */ | |
| 1601 cols = 0; | |
| 1602 pos = str; | |
| 1603 while (*pos != '\0') | |
| 1604 { | |
| 1605 while (*pos != '\0' && *pos != ' ' && *pos != '\t') | |
| 1606 { | |
| 1607 if (*pos == ':') | |
| 1608 break; | |
| 1609 pos++; | |
| 1610 } | |
| 1611 | |
| 1612 cols++; | |
| 1613 | |
| 1614 if (*pos == ':') | |
| 1615 { | |
| 1616 cols++; | |
| 1617 break; | |
| 1618 } | |
| 1619 | |
| 1620 while (*pos == ' ' || *pos == '\t') | |
| 1621 pos++; | |
| 1622 } | |
| 1 | 1623 |
| 1624 startpos = str; | |
| 1625 /* Copy file attributes */ | |
| 499 | 1626 if ((startpos = copy_token (&attribs, startpos)) == NULL) |
| 84 | 1627 return (GFTP_EFATAL); |
| 1 | 1628 |
| 798 | 1629 if (strlen (attribs) < 10) |
| 1630 return (GFTP_EFATAL); | |
| 1631 | |
| 499 | 1632 fle->st_mode = gftp_convert_attributes_to_mode_t (attribs); |
| 1633 g_free (attribs); | |
| 1634 | |
| 1 | 1635 if (cols >= 9) |
| 1636 { | |
| 1637 /* Skip the number of links */ | |
| 1638 startpos = goto_next_token (startpos); | |
| 1639 | |
| 1640 /* Copy the user that owns this file */ | |
| 1641 if ((startpos = copy_token (&fle->user, startpos)) == NULL) | |
| 168 | 1642 return (GFTP_EFATAL); |
| 1 | 1643 |
| 1644 /* Copy the group that owns this file */ | |
| 1645 if ((startpos = copy_token (&fle->group, startpos)) == NULL) | |
| 168 | 1646 return (GFTP_EFATAL); |
| 1 | 1647 } |
| 1648 else | |
| 1649 { | |
| 124 | 1650 fle->group = g_strdup (_("unknown")); |
| 1 | 1651 if (cols == 8) |
| 168 | 1652 { |
| 1653 if ((startpos = copy_token (&fle->user, startpos)) == NULL) | |
| 1654 return (GFTP_EFATAL); | |
| 1655 } | |
| 1 | 1656 else |
| 124 | 1657 fle->user = g_strdup (_("unknown")); |
| 1 | 1658 startpos = goto_next_token (startpos); |
| 1659 } | |
| 1660 | |
| 281 | 1661 if (request->server_type == GFTP_DIRTYPE_CRAY) |
| 1 | 1662 { |
| 91 | 1663 /* See if this is a Cray directory listing. It has the following format: |
| 1664 drwx------ 2 feiliu g913 DK common 4096 Sep 24 2001 wv */ | |
| 1665 if (cols == 11 && strstr (str, "->") == NULL) | |
| 1666 { | |
| 1667 startpos = goto_next_token (startpos); | |
| 1668 startpos = goto_next_token (startpos); | |
| 1669 } | |
| 1 | 1670 } |
| 1671 | |
| 1672 /* See if this is a block or character device. We will store the major number | |
| 1673 in the high word and the minor number in the low word. */ | |
| 499 | 1674 if (GFTP_IS_SPECIAL_DEVICE (fle->st_mode) && |
| 1675 (endpos = strchr (startpos, ',')) != NULL) | |
| 1 | 1676 { |
| 765 | 1677 fle->size = (unsigned long) strtol (startpos, NULL, 10) << 16; |
| 1 | 1678 |
| 1679 startpos = endpos + 1; | |
| 1680 while (*startpos == ' ') | |
| 168 | 1681 startpos++; |
| 1 | 1682 |
| 1683 /* Get the minor number */ | |
| 1684 if ((endpos = strchr (startpos, ' ')) == NULL) | |
| 168 | 1685 return (GFTP_EFATAL); |
|
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
7
diff
changeset
|
1686 fle->size |= strtol (startpos, NULL, 10) & 0xFF; |
| 1 | 1687 } |
| 1688 else | |
| 1689 { | |
| 1690 /* This is a regular file */ | |
| 1691 if ((endpos = strchr (startpos, ' ')) == NULL) | |
| 168 | 1692 return (GFTP_EFATAL); |
| 244 | 1693 fle->size = gftp_parse_file_size (startpos); |
| 1 | 1694 } |
| 1695 | |
| 1696 /* Skip the blanks till we get to the next entry */ | |
| 1697 startpos = endpos + 1; | |
| 1698 while (*startpos == ' ') | |
| 1699 startpos++; | |
| 1700 | |
| 479 | 1701 fle->datetime = parse_time (startpos, &startpos); |
| 1 | 1702 |
| 1703 /* Skip the blanks till we get to the next entry */ | |
| 1704 startpos = goto_next_token (startpos); | |
| 1705 | |
| 1706 /* Parse the filename. If this file is a symbolic link, remove the -> part */ | |
| 499 | 1707 if (S_ISLNK (fle->st_mode) && ((endpos = strstr (startpos, "->")) != NULL)) |
| 1 | 1708 *(endpos - 1) = '\0'; |
| 1709 | |
| 124 | 1710 fle->file = g_strdup (startpos); |
| 1 | 1711 |
| 1712 /* Uncomment this if you want to strip the spaces off of the end of the file. | |
| 1713 I don't want to do this by default since there are valid filenames with | |
| 1714 spaces at the end of them. Some broken FTP servers like the Paradyne IPC | |
| 1715 DSLAMS append a bunch of spaces at the end of the file. | |
| 1716 for (endpos = fle->file + strlen (fle->file) - 1; | |
| 1717 *endpos == ' '; | |
| 1718 *endpos-- = '\0'); | |
| 1719 */ | |
| 1720 | |
| 1721 return (0); | |
| 1722 } | |
| 1723 | |
| 1724 | |
| 1725 static int | |
| 1726 gftp_parse_ls_nt (char *str, gftp_file * fle) | |
| 1727 { | |
| 1728 char *startpos; | |
| 1729 | |
| 1730 startpos = str; | |
| 479 | 1731 fle->datetime = parse_time (startpos, &startpos); |
| 1 | 1732 |
| 124 | 1733 fle->user = g_strdup (_("unknown")); |
| 1734 fle->group = g_strdup (_("unknown")); | |
| 1 | 1735 |
| 1736 startpos = goto_next_token (startpos); | |
| 499 | 1737 |
| 1 | 1738 if (startpos[0] == '<') |
| 499 | 1739 fle->st_mode = S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; |
| 1 | 1740 else |
| 1741 { | |
| 499 | 1742 fle->st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; |
| 244 | 1743 fle->size = gftp_parse_file_size (startpos); |
| 1 | 1744 } |
| 124 | 1745 |
| 1 | 1746 startpos = goto_next_token (startpos); |
| 124 | 1747 fle->file = g_strdup (startpos); |
| 1 | 1748 return (0); |
| 1749 } | |
| 1750 | |
| 1751 | |
| 1752 static int | |
| 1753 gftp_parse_ls_novell (char *str, gftp_file * fle) | |
| 1754 { | |
| 1755 char *startpos; | |
| 1756 | |
| 1757 if (str[12] != ' ') | |
| 84 | 1758 return (GFTP_EFATAL); |
| 499 | 1759 |
| 1 | 1760 str[12] = '\0'; |
| 499 | 1761 fle->st_mode = gftp_convert_attributes_to_mode_t (str); |
| 1 | 1762 startpos = str + 13; |
| 1763 | |
| 1764 while ((*startpos == ' ' || *startpos == '\t') && *startpos != '\0') | |
| 1765 startpos++; | |
| 1766 | |
| 1767 if ((startpos = copy_token (&fle->user, startpos)) == NULL) | |
| 84 | 1768 return (GFTP_EFATAL); |
| 1 | 1769 |
| 124 | 1770 fle->group = g_strdup (_("unknown")); |
| 1 | 1771 |
| 601 | 1772 while (*startpos != '\0' && !isdigit (*startpos)) |
| 1773 startpos++; | |
| 1774 | |
| 244 | 1775 fle->size = gftp_parse_file_size (startpos); |
| 1 | 1776 |
| 1777 startpos = goto_next_token (startpos); | |
| 479 | 1778 fle->datetime = parse_time (startpos, &startpos); |
| 1 | 1779 |
| 1780 startpos = goto_next_token (startpos); | |
| 124 | 1781 fle->file = g_strdup (startpos); |
| 1 | 1782 return (0); |
| 1783 } | |
| 1784 | |
| 1785 | |
| 48 | 1786 int |
| 485 | 1787 gftp_parse_ls (gftp_request * request, const char *lsoutput, gftp_file * fle, |
| 1788 int fd) | |
| 1 | 1789 { |
| 107 | 1790 char *str, *endpos, tmpchar; |
| 1791 int result, is_vms; | |
| 91 | 1792 size_t len; |
| 48 | 1793 |
| 84 | 1794 g_return_val_if_fail (lsoutput != NULL, GFTP_EFATAL); |
| 1795 g_return_val_if_fail (fle != NULL, GFTP_EFATAL); | |
| 48 | 1796 |
| 124 | 1797 str = g_strdup (lsoutput); |
| 48 | 1798 memset (fle, 0, sizeof (*fle)); |
| 1 | 1799 |
| 91 | 1800 len = strlen (str); |
| 107 | 1801 if (len > 0 && str[len - 1] == '\n') |
| 91 | 1802 str[--len] = '\0'; |
| 1803 if (len > 0 && str[len - 1] == '\r') | |
| 1804 str[--len] = '\0'; | |
| 39 | 1805 |
| 91 | 1806 switch (request->server_type) |
| 1807 { | |
| 122 | 1808 case GFTP_DIRTYPE_CRAY: |
| 1809 case GFTP_DIRTYPE_UNIX: | |
| 460 | 1810 result = gftp_parse_ls_unix (request, str, len, fle); |
| 91 | 1811 break; |
| 122 | 1812 case GFTP_DIRTYPE_EPLF: |
| 91 | 1813 result = gftp_parse_ls_eplf (str, fle); |
| 1814 break; | |
| 122 | 1815 case GFTP_DIRTYPE_NOVELL: |
| 91 | 1816 result = gftp_parse_ls_novell (str, fle); |
| 1817 break; | |
| 122 | 1818 case GFTP_DIRTYPE_DOS: |
| 91 | 1819 result = gftp_parse_ls_nt (str, fle); |
| 1820 break; | |
| 122 | 1821 case GFTP_DIRTYPE_VMS: |
| 485 | 1822 result = gftp_parse_ls_vms (request, fd, str, fle); |
| 107 | 1823 break; |
| 358 | 1824 case GFTP_DIRTYPE_MVS: |
| 1825 result = gftp_parse_ls_mvs (str, fle); | |
| 1826 break; | |
| 91 | 1827 default: /* autodetect */ |
| 1828 if (*lsoutput == '+') | |
| 1829 result = gftp_parse_ls_eplf (str, fle); | |
| 1830 else if (isdigit ((int) str[0]) && str[2] == '-') | |
| 1831 result = gftp_parse_ls_nt (str, fle); | |
| 1832 else if (str[1] == ' ' && str[2] == '[') | |
| 1833 result = gftp_parse_ls_novell (str, fle); | |
| 1834 else | |
| 107 | 1835 { |
| 1836 if ((endpos = strchr (str, ' ')) != NULL) | |
| 1837 { | |
| 1838 /* If the first token in the string has a ; in it, then */ | |
| 1839 /* we'll assume that this is a VMS directory listing */ | |
| 1840 tmpchar = *endpos; | |
| 1841 *endpos = '\0'; | |
| 1842 is_vms = strchr (str, ';') != NULL; | |
| 1843 *endpos = tmpchar; | |
| 1844 } | |
| 1845 else | |
| 1846 is_vms = 0; | |
| 48 | 1847 |
| 107 | 1848 if (is_vms) |
| 485 | 1849 result = gftp_parse_ls_vms (request, fd, str, fle); |
| 107 | 1850 else |
| 460 | 1851 result = gftp_parse_ls_unix (request, str, len, fle); |
| 107 | 1852 } |
| 91 | 1853 break; |
| 48 | 1854 } |
| 1855 g_free (str); | |
| 1856 | |
| 1857 return (result); | |
| 1 | 1858 } |
| 1859 | |
| 1860 | |
| 48 | 1861 static GHashTable * |
| 469 | 1862 gftp_gen_dir_hash (gftp_request * request, int *ret) |
| 1 | 1863 { |
| 48 | 1864 GHashTable * dirhash; |
| 1865 gftp_file * fle; | |
| 516 | 1866 off_t *newsize; |
| 48 | 1867 |
| 851 | 1868 dirhash = g_hash_table_new (string_hash_function, string_hash_compare); |
| 850 | 1869 *ret = gftp_list_files (request); |
| 851 | 1870 if (*ret == 0) |
| 48 | 1871 { |
| 851 | 1872 fle = g_malloc0 (sizeof (*fle)); |
| 1873 while (gftp_get_next_file (request, NULL, fle) > 0) | |
| 48 | 1874 { |
| 851 | 1875 newsize = g_malloc (sizeof (*newsize)); |
| 1876 *newsize = fle->size; | |
| 1877 g_hash_table_insert (dirhash, fle->file, newsize); | |
| 1878 fle->file = NULL; | |
| 598 | 1879 gftp_file_destroy (fle, 0); |
| 48 | 1880 } |
| 851 | 1881 gftp_end_transfer (request); |
| 1882 g_free (fle); | |
| 48 | 1883 } |
| 851 | 1884 else |
| 1885 { | |
| 1886 g_hash_table_destroy (dirhash); | |
| 1887 dirhash = NULL; | |
| 1888 } | |
| 509 | 1889 |
| 48 | 1890 return (dirhash); |
| 1891 } | |
| 39 | 1892 |
| 48 | 1893 |
| 1894 static void | |
| 1895 destroy_hash_ent (gpointer key, gpointer value, gpointer user_data) | |
| 1896 { | |
| 39 | 1897 |
| 48 | 1898 g_free (key); |
| 1899 g_free (value); | |
| 1900 } | |
| 1901 | |
| 1902 | |
| 1903 static void | |
| 1904 gftp_destroy_dir_hash (GHashTable * dirhash) | |
| 1905 { | |
| 787 | 1906 if (dirhash == NULL) |
| 1907 return; | |
| 1908 | |
| 48 | 1909 g_hash_table_foreach (dirhash, destroy_hash_ent, NULL); |
| 1910 g_hash_table_destroy (dirhash); | |
| 1 | 1911 } |
| 1912 | |
| 1913 | |
| 1914 static GList * | |
| 469 | 1915 gftp_get_dir_listing (gftp_transfer * transfer, int getothdir, int *ret) |
| 1 | 1916 { |
| 1917 GHashTable * dirhash; | |
| 1918 GList * templist; | |
| 1919 gftp_file * fle; | |
| 516 | 1920 off_t *newsize; |
| 1 | 1921 char *newname; |
| 1922 | |
| 787 | 1923 if (getothdir && transfer->toreq != NULL) |
| 469 | 1924 { |
| 1925 dirhash = gftp_gen_dir_hash (transfer->toreq, ret); | |
| 787 | 1926 if (*ret == GFTP_EFATAL) |
| 469 | 1927 return (NULL); |
| 1928 } | |
| 1 | 1929 else |
| 1930 dirhash = NULL; | |
| 1931 | |
| 509 | 1932 *ret = gftp_list_files (transfer->fromreq); |
| 1933 if (*ret < 0) | |
| 787 | 1934 { |
| 1935 gftp_destroy_dir_hash (dirhash); | |
| 1936 return (NULL); | |
| 1937 } | |
| 1 | 1938 |
| 1939 fle = g_malloc (sizeof (*fle)); | |
| 1940 templist = NULL; | |
| 1941 while (gftp_get_next_file (transfer->fromreq, NULL, fle) > 0) | |
| 1942 { | |
| 851 | 1943 if (strcmp (fle->file, ".") == 0 || strcmp (fle->file, "..") == 0) |
| 1 | 1944 { |
| 598 | 1945 gftp_file_destroy (fle, 0); |
| 1 | 1946 continue; |
| 1947 } | |
| 1948 | |
| 1949 if (dirhash && | |
| 1950 (newsize = g_hash_table_lookup (dirhash, fle->file)) != NULL) | |
| 787 | 1951 { |
| 1952 fle->exists_other_side = 1; | |
| 1953 fle->startsize = *newsize; | |
| 1954 } | |
| 1955 else | |
| 1956 fle->exists_other_side = 0; | |
| 1 | 1957 |
| 381 | 1958 if (transfer->toreq && fle->destfile == NULL) |
| 555 | 1959 fle->destfile = gftp_build_path (transfer->toreq, |
| 1960 transfer->toreq->directory, | |
| 245 | 1961 fle->file, NULL); |
| 1962 | |
| 381 | 1963 if (transfer->fromreq->directory != NULL && |
| 1964 *transfer->fromreq->directory != '\0' && | |
| 1965 *fle->file != '/') | |
| 1966 { | |
| 555 | 1967 newname = gftp_build_path (transfer->fromreq, |
| 1968 transfer->fromreq->directory, | |
| 381 | 1969 fle->file, NULL); |
| 1970 | |
| 1971 g_free (fle->file); | |
| 1972 fle->file = newname; | |
| 1973 } | |
| 1 | 1974 |
| 1975 templist = g_list_append (templist, fle); | |
| 1976 | |
| 787 | 1977 fle = g_malloc0 (sizeof (*fle)); |
| 1 | 1978 } |
| 1979 gftp_end_transfer (transfer->fromreq); | |
| 1980 | |
| 598 | 1981 gftp_file_destroy (fle, 1); |
| 787 | 1982 gftp_destroy_dir_hash (dirhash); |
| 1 | 1983 |
| 1984 return (templist); | |
| 1985 } | |
| 1986 | |
| 1987 | |
| 787 | 1988 static void |
| 1989 _cleanup_get_all_subdirs (gftp_transfer * transfer, char *oldfromdir, | |
| 1990 char *oldtodir, | |
| 1991 void (*update_func) (gftp_transfer * transfer)) | |
| 1 | 1992 { |
| 787 | 1993 if (update_func != NULL) |
| 1994 { | |
| 1995 transfer->numfiles = transfer->numdirs = -1; | |
| 1996 update_func (transfer); | |
| 1997 } | |
| 1998 | |
| 1999 if (oldfromdir != NULL) | |
| 2000 g_free (oldfromdir); | |
| 2001 | |
| 2002 if (oldtodir != NULL) | |
| 2003 g_free (oldtodir); | |
| 2004 } | |
| 2005 | |
| 2006 | |
| 2007 static GList * | |
| 2008 _setup_current_directory_transfer (gftp_transfer * transfer, int *ret) | |
| 2009 { | |
| 1 | 2010 GHashTable * dirhash; |
| 787 | 2011 char *pos, *newname; |
| 1 | 2012 gftp_file * curfle; |
| 787 | 2013 GList * lastlist; |
| 516 | 2014 off_t *newsize; |
| 787 | 2015 |
| 2016 *ret = 0; | |
| 1 | 2017 if (transfer->toreq != NULL) |
| 469 | 2018 { |
| 787 | 2019 dirhash = gftp_gen_dir_hash (transfer->toreq, ret); |
| 2020 if (*ret == GFTP_EFATAL) | |
| 2021 return (NULL); | |
| 469 | 2022 } |
| 1 | 2023 else |
| 2024 dirhash = NULL; | |
| 2025 | |
| 2026 for (lastlist = transfer->files; ; lastlist = lastlist->next) | |
| 2027 { | |
| 2028 curfle = lastlist->data; | |
| 381 | 2029 |
| 2030 if ((pos = strrchr (curfle->file, '/')) != NULL) | |
| 2031 pos++; | |
| 2032 else | |
| 2033 pos = curfle->file; | |
| 2034 | |
| 2035 if (dirhash != NULL && | |
| 2036 (newsize = g_hash_table_lookup (dirhash, pos)) != NULL) | |
| 787 | 2037 { |
| 2038 curfle->exists_other_side = 1; | |
| 2039 curfle->startsize = *newsize; | |
| 2040 } | |
| 2041 else | |
| 2042 curfle->exists_other_side = 0; | |
| 1 | 2043 |
| 381 | 2044 if (curfle->size < 0 && GFTP_IS_CONNECTED (transfer->fromreq)) |
| 509 | 2045 { |
| 2046 curfle->size = gftp_get_file_size (transfer->fromreq, curfle->file); | |
| 787 | 2047 if (curfle->size == GFTP_EFATAL) |
| 2048 { | |
| 2049 gftp_destroy_dir_hash (dirhash); | |
| 2050 *ret = curfle->size; | |
| 2051 return (NULL); | |
| 2052 } | |
| 509 | 2053 } |
| 381 | 2054 |
| 2055 if (transfer->toreq && curfle->destfile == NULL) | |
| 555 | 2056 curfle->destfile = gftp_build_path (transfer->toreq, |
| 2057 transfer->toreq->directory, | |
| 381 | 2058 curfle->file, NULL); |
| 2059 | |
| 2060 if (transfer->fromreq->directory != NULL && | |
| 509 | 2061 *transfer->fromreq->directory != '\0' && *curfle->file != '/') |
| 381 | 2062 { |
| 555 | 2063 newname = gftp_build_path (transfer->fromreq, |
| 2064 transfer->fromreq->directory, | |
| 381 | 2065 curfle->file, NULL); |
| 2066 g_free (curfle->file); | |
| 2067 curfle->file = newname; | |
| 2068 } | |
| 1 | 2069 |
| 2070 if (lastlist->next == NULL) | |
| 2071 break; | |
| 2072 } | |
| 2073 | |
| 787 | 2074 gftp_destroy_dir_hash (dirhash); |
| 2075 | |
| 2076 return (lastlist); | |
| 2077 } | |
| 2078 | |
| 2079 | |
| 852 | 2080 static int |
| 2081 _lookup_curfle_in_device_hash (gftp_request * request, gftp_file * curfle, | |
| 2082 GHashTable * device_hash) | |
| 2083 { | |
| 2084 GHashTable * inode_hash; | |
| 2085 | |
| 2086 if (curfle->st_dev == 0 || curfle->st_ino == 0) | |
| 2087 return (0); | |
| 2088 | |
| 2089 if ((inode_hash = g_hash_table_lookup (device_hash, | |
| 2090 GUINT_TO_POINTER ((guint) curfle->st_dev))) != NULL) | |
| 2091 { | |
| 2092 if (g_hash_table_lookup (inode_hash, | |
| 2093 GUINT_TO_POINTER ((guint) curfle->st_ino))) | |
| 2094 { | |
| 2095 request->logging_function (gftp_logging_error, request, | |
| 2096 _("Found recursive symbolic link %s\n"), | |
| 2097 curfle->file); | |
| 2098 return (1); | |
| 2099 } | |
| 2100 | |
| 2101 g_hash_table_insert (inode_hash, GUINT_TO_POINTER ((guint) curfle->st_ino), | |
| 2102 GUINT_TO_POINTER (1)); | |
| 2103 return (0); | |
| 2104 } | |
| 2105 else | |
| 2106 { | |
| 2107 inode_hash = g_hash_table_new (uint_hash_function, uint_hash_compare); | |
| 2108 g_hash_table_insert (inode_hash, GUINT_TO_POINTER ((guint) curfle->st_ino), | |
| 2109 GUINT_TO_POINTER (1)); | |
| 2110 g_hash_table_insert (device_hash, GUINT_TO_POINTER ((guint) curfle->st_dev), | |
| 2111 inode_hash); | |
| 2112 return (0); | |
| 2113 } | |
| 2114 | |
| 2115 } | |
| 2116 | |
| 2117 | |
| 2118 static void | |
| 2119 _free_inode_hash (gpointer key, gpointer value, gpointer user_data) | |
| 2120 { | |
| 2121 g_hash_table_destroy (value); | |
| 2122 } | |
| 2123 | |
| 2124 | |
| 2125 static void | |
| 2126 _free_device_hash (GHashTable * device_hash) | |
| 2127 { | |
| 2128 g_hash_table_foreach (device_hash, _free_inode_hash, NULL); | |
| 2129 g_hash_table_destroy (device_hash); | |
| 2130 } | |
| 2131 | |
| 2132 | |
| 787 | 2133 int |
| 2134 gftp_get_all_subdirs (gftp_transfer * transfer, | |
| 2135 void (*update_func) (gftp_transfer * transfer)) | |
| 2136 { | |
| 2137 GList * templist, * lastlist; | |
| 2138 char *oldfromdir, *oldtodir; | |
| 852 | 2139 GHashTable * device_hash; |
| 787 | 2140 gftp_file * curfle; |
| 2141 off_t linksize; | |
| 2142 mode_t st_mode; | |
| 2143 int ret; | |
| 2144 | |
| 2145 g_return_val_if_fail (transfer != NULL, GFTP_EFATAL); | |
| 2146 g_return_val_if_fail (transfer->fromreq != NULL, GFTP_EFATAL); | |
| 2147 g_return_val_if_fail (transfer->files != NULL, GFTP_EFATAL); | |
| 2148 | |
| 2149 if (transfer->files == NULL) | |
| 2150 return (0); | |
| 2151 | |
| 2152 ret = 0; | |
| 2153 lastlist = _setup_current_directory_transfer (transfer, &ret); | |
| 2154 if (lastlist == NULL) | |
| 2155 return (ret); | |
| 1 | 2156 |
| 2157 oldfromdir = oldtodir = NULL; | |
| 852 | 2158 device_hash = g_hash_table_new (uint_hash_function, uint_hash_compare); |
| 787 | 2159 |
| 1 | 2160 for (templist = transfer->files; templist != NULL; templist = templist->next) |
| 2161 { | |
| 2162 curfle = templist->data; | |
| 2163 | |
| 852 | 2164 if (_lookup_curfle_in_device_hash (transfer->fromreq, curfle, |
| 2165 device_hash)) | |
| 2166 continue; | |
| 2167 | |
| 500 | 2168 if (S_ISLNK (curfle->st_mode) && !S_ISDIR (curfle->st_mode)) |
| 2169 { | |
| 520 | 2170 st_mode = 0; |
| 787 | 2171 linksize = 0; |
| 2172 ret = gftp_stat_filename (transfer->fromreq, curfle->file, &st_mode, | |
| 2173 &linksize); | |
| 855 | 2174 if (ret == GFTP_EFATAL) |
| 787 | 2175 { |
| 2176 _cleanup_get_all_subdirs (transfer, oldfromdir, oldtodir, | |
| 2177 update_func); | |
| 2178 return (ret); | |
| 2179 } | |
| 855 | 2180 else if (ret == 0) |
| 2181 { | |
| 2182 if (S_ISDIR (st_mode)) | |
| 2183 curfle->st_mode = st_mode; | |
| 2184 else | |
| 2185 curfle->size = linksize; | |
| 2186 } | |
| 500 | 2187 } |
| 2188 | |
| 826 | 2189 if (!S_ISDIR (curfle->st_mode)) |
| 1 | 2190 { |
| 787 | 2191 transfer->numfiles++; |
| 2192 continue; | |
| 2193 } | |
| 2194 | |
| 2195 /* Got a directory... */ | |
| 826 | 2196 transfer->numdirs++; |
| 2197 | |
| 787 | 2198 if (oldfromdir == NULL) |
| 2199 oldfromdir = g_strdup (transfer->fromreq->directory); | |
| 2200 | |
| 2201 ret = gftp_set_directory (transfer->fromreq, curfle->file); | |
| 2202 if (ret < 0) | |
| 2203 { | |
| 2204 _cleanup_get_all_subdirs (transfer, oldfromdir, oldtodir, | |
| 2205 update_func); | |
| 852 | 2206 _free_device_hash (device_hash); |
| 787 | 2207 return (ret); |
| 2208 } | |
| 2209 | |
| 2210 if (transfer->toreq != NULL) | |
| 2211 { | |
| 2212 if (oldtodir == NULL) | |
| 2213 oldtodir = g_strdup (transfer->toreq->directory); | |
| 2214 | |
| 2215 if (curfle->exists_other_side) | |
| 1 | 2216 { |
| 787 | 2217 ret = gftp_set_directory (transfer->toreq, curfle->destfile); |
| 2218 if (ret == GFTP_EFATAL) | |
| 2219 { | |
| 2220 _cleanup_get_all_subdirs (transfer, oldfromdir, oldtodir, | |
| 2221 update_func); | |
| 852 | 2222 _free_device_hash (device_hash); |
| 787 | 2223 return (ret); |
| 2224 } | |
| 2225 } | |
| 2226 else | |
| 509 | 2227 { |
| 787 | 2228 if (transfer->toreq->directory != NULL) |
| 2229 g_free (transfer->toreq->directory); | |
| 2230 | |
| 2231 transfer->toreq->directory = g_strdup (curfle->destfile); | |
| 1 | 2232 } |
| 787 | 2233 } |
| 2234 | |
| 2235 ret = 0; | |
| 2236 lastlist->next = gftp_get_dir_listing (transfer, | |
| 2237 curfle->exists_other_side, &ret); | |
| 2238 if (ret < 0) | |
| 2239 { | |
| 2240 _cleanup_get_all_subdirs (transfer, oldfromdir, oldtodir, | |
| 2241 update_func); | |
| 852 | 2242 _free_device_hash (device_hash); |
| 787 | 2243 return (ret); |
| 1 | 2244 } |
| 787 | 2245 |
| 2246 if (lastlist->next != NULL) | |
| 2247 { | |
| 2248 lastlist->next->prev = lastlist; | |
| 2249 for (; lastlist->next != NULL; lastlist = lastlist->next); | |
| 2250 } | |
| 2251 | |
| 2252 if (update_func != NULL) | |
| 2253 update_func (transfer); | |
| 1 | 2254 } |
| 2255 | |
| 852 | 2256 _free_device_hash (device_hash); |
| 2257 | |
| 787 | 2258 if (oldfromdir != NULL) |
| 509 | 2259 { |
| 787 | 2260 ret = gftp_set_directory (transfer->fromreq, oldfromdir); |
| 855 | 2261 if (ret == GFTP_EFATAL) |
| 787 | 2262 { |
| 2263 _cleanup_get_all_subdirs (transfer, oldfromdir, oldtodir, | |
| 2264 update_func); | |
| 2265 return (ret); | |
| 2266 } | |
| 509 | 2267 } |
| 2268 | |
| 787 | 2269 if (oldtodir != NULL) |
| 509 | 2270 { |
| 787 | 2271 ret = gftp_set_directory (transfer->toreq, oldtodir); |
| 855 | 2272 if (ret == GFTP_EFATAL) |
| 787 | 2273 { |
| 2274 _cleanup_get_all_subdirs (transfer, oldfromdir, oldtodir, | |
| 2275 update_func); | |
| 2276 return (ret); | |
| 2277 } | |
| 509 | 2278 } |
| 2279 | |
| 787 | 2280 _cleanup_get_all_subdirs (transfer, oldfromdir, oldtodir, update_func); |
| 509 | 2281 |
| 1 | 2282 return (0); |
| 2283 } | |
| 2284 | |
| 2285 | |
| 2286 #if defined (HAVE_GETADDRINFO) && defined (HAVE_GAI_STRERROR) | |
| 122 | 2287 static int |
| 1 | 2288 get_port (struct addrinfo *addr) |
| 2289 { | |
| 2290 struct sockaddr_in * saddr; | |
| 2291 int port; | |
| 2292 | |
| 2293 if (addr->ai_family == AF_INET) | |
| 2294 { | |
| 2295 saddr = (struct sockaddr_in *) addr->ai_addr; | |
| 2296 port = ntohs (saddr->sin_port); | |
| 2297 } | |
| 2298 else | |
| 2299 port = 0; | |
| 2300 | |
| 2301 return (port); | |
| 2302 } | |
| 2303 #endif | |
| 2304 | |
| 2305 | |
| 2306 int | |
| 122 | 2307 gftp_connect_server (gftp_request * request, char *service, |
| 516 | 2308 char *proxy_hostname, unsigned int proxy_port) |
| 1 | 2309 { |
| 2310 char *connect_host, *disphost; | |
| 516 | 2311 unsigned int port; |
| 2312 int sock = -1; | |
| 1 | 2313 #if defined (HAVE_GETADDRINFO) && defined (HAVE_GAI_STRERROR) |
| 2314 struct addrinfo hints, *res; | |
| 463 | 2315 intptr_t enable_ipv6; |
| 1 | 2316 char serv[8]; |
| 463 | 2317 int errnum; |
| 1 | 2318 |
| 516 | 2319 if ((errnum = gftp_need_proxy (request, service, proxy_hostname, |
| 2320 proxy_port)) < 0) | |
| 2321 return (errnum); | |
| 2322 else | |
| 2323 { | |
| 2324 request->use_proxy = errnum; | |
| 2325 if (request->use_proxy) | |
| 2326 request->hostp = NULL; | |
| 2327 } | |
| 1 | 2328 |
| 313 | 2329 gftp_lookup_request_option (request, "enable_ipv6", &enable_ipv6); |
| 2330 | |
| 151 | 2331 request->free_hostp = 1; |
| 1 | 2332 memset (&hints, 0, sizeof (hints)); |
| 2333 hints.ai_flags = AI_CANONNAME; | |
| 313 | 2334 |
| 2335 if (enable_ipv6) | |
| 2336 hints.ai_family = PF_UNSPEC; | |
| 2337 else | |
| 2338 hints.ai_family = AF_INET; | |
| 2339 | |
| 1 | 2340 hints.ai_socktype = SOCK_STREAM; |
| 2341 | |
| 122 | 2342 if (request->use_proxy) |
| 2343 { | |
| 2344 connect_host = proxy_hostname; | |
| 2345 port = proxy_port; | |
| 2346 } | |
| 2347 else | |
| 2348 { | |
| 2349 connect_host = request->hostname; | |
| 2350 port = request->port; | |
| 2351 } | |
| 1 | 2352 |
| 2353 if (request->hostp == NULL) | |
| 2354 { | |
| 2355 if (port == 0) | |
| 2356 strcpy (serv, service); | |
| 2357 else | |
| 2358 snprintf (serv, sizeof (serv), "%d", port); | |
| 2359 | |
| 186 | 2360 request->logging_function (gftp_logging_misc, request, |
| 168 | 2361 _("Looking up %s\n"), connect_host); |
| 1 | 2362 if ((errnum = getaddrinfo (connect_host, serv, &hints, |
| 2363 &request->hostp)) != 0) | |
| 168 | 2364 { |
| 186 | 2365 request->logging_function (gftp_logging_error, request, |
| 168 | 2366 _("Cannot look up hostname %s: %s\n"), |
| 2367 connect_host, gai_strerror (errnum)); | |
| 2368 return (GFTP_ERETRYABLE); | |
| 2369 } | |
| 1 | 2370 } |
| 2371 | |
| 2372 disphost = connect_host; | |
| 2373 for (res = request->hostp; res != NULL; res = res->ai_next) | |
| 2374 { | |
| 2375 disphost = res->ai_canonname ? res->ai_canonname : connect_host; | |
| 2376 port = get_port (res); | |
| 56 | 2377 if (!request->use_proxy) |
| 2378 request->port = port; | |
| 2379 | |
| 1 | 2380 if ((sock = socket (res->ai_family, res->ai_socktype, |
| 2381 res->ai_protocol)) < 0) | |
| 2382 { | |
| 186 | 2383 request->logging_function (gftp_logging_error, request, |
| 1 | 2384 _("Failed to create a socket: %s\n"), |
| 2385 g_strerror (errno)); | |
| 2386 continue; | |
| 66 | 2387 } |
| 1 | 2388 |
| 186 | 2389 request->logging_function (gftp_logging_misc, request, |
| 168 | 2390 _("Trying %s:%d\n"), disphost, port); |
| 1 | 2391 |
| 2392 if (connect (sock, res->ai_addr, res->ai_addrlen) == -1) | |
| 168 | 2393 { |
| 186 | 2394 request->logging_function (gftp_logging_error, request, |
| 168 | 2395 _("Cannot connect to %s: %s\n"), |
| 2396 disphost, g_strerror (errno)); | |
| 1 | 2397 close (sock); |
| 2398 continue; | |
| 168 | 2399 } |
| 547 | 2400 |
| 572 | 2401 request->current_hostp = res; |
| 547 | 2402 request->ai_family = res->ai_family; |
| 1 | 2403 break; |
| 2404 } | |
| 2405 | |
| 2406 if (res == NULL) | |
| 2407 { | |
| 2408 if (request->hostp != NULL) | |
| 2409 { | |
| 2410 freeaddrinfo (request->hostp); | |
| 2411 request->hostp = NULL; | |
| 2412 } | |
| 84 | 2413 return (GFTP_ERETRYABLE); |
| 1 | 2414 } |
| 2415 | |
| 2416 #else /* !HAVE_GETADDRINFO */ | |
| 2417 struct sockaddr_in remote_address; | |
| 2418 struct servent serv_struct; | |
| 765 | 2419 int ret; |
| 2420 | |
| 2421 if ((ret = gftp_need_proxy (request, service, proxy_hostname, | |
| 2422 proxy_port)) < 0) | |
| 2423 return (ret); | |
| 2424 | |
| 2425 request->use_proxy = ret; | |
| 2426 if (request->use_proxy == 1) | |
| 1 | 2427 request->hostp = NULL; |
| 2428 | |
| 547 | 2429 request->ai_family = AF_INET; |
| 1 | 2430 if ((sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) |
| 2431 { | |
| 186 | 2432 request->logging_function (gftp_logging_error, request, |
| 313 | 2433 _("Failed to create a IPv4 socket: %s\n"), |
| 1 | 2434 g_strerror (errno)); |
| 84 | 2435 return (GFTP_ERETRYABLE); |
| 1 | 2436 } |
| 2437 | |
| 2438 memset (&remote_address, 0, sizeof (remote_address)); | |
| 2439 remote_address.sin_family = AF_INET; | |
| 2440 | |
| 122 | 2441 if (request->use_proxy) |
| 2442 { | |
| 2443 connect_host = proxy_hostname; | |
| 2444 port = proxy_port; | |
| 2445 } | |
| 2446 else | |
| 2447 { | |
| 2448 connect_host = request->hostname; | |
| 2449 port = request->port; | |
| 2450 } | |
| 1 | 2451 |
| 2452 if (port == 0) | |
| 2453 { | |
| 2454 if (!r_getservbyname (service, "tcp", &serv_struct, NULL)) | |
| 2455 { | |
| 186 | 2456 request->logging_function (gftp_logging_error, request, |
| 122 | 2457 _("Cannot look up service name %s/tcp. Please check your services file\n"), |
| 2458 service); | |
| 2459 close (sock); | |
| 2460 return (GFTP_EFATAL); | |
| 1 | 2461 } |
| 451 | 2462 |
| 2463 port = ntohs (serv_struct.s_port); | |
| 56 | 2464 |
| 2465 if (!request->use_proxy) | |
| 451 | 2466 request->port = port; |
| 1 | 2467 } |
| 451 | 2468 |
| 2469 remote_address.sin_port = htons (port); | |
| 1 | 2470 |
| 2471 if (request->hostp == NULL) | |
| 2472 { | |
| 186 | 2473 request->logging_function (gftp_logging_misc, request, |
| 168 | 2474 _("Looking up %s\n"), connect_host); |
| 1 | 2475 if (!(request->hostp = r_gethostbyname (connect_host, &request->host, |
| 2476 NULL))) | |
| 2477 { | |
| 186 | 2478 request->logging_function (gftp_logging_error, request, |
| 1 | 2479 _("Cannot look up hostname %s: %s\n"), |
| 2480 connect_host, g_strerror (errno)); | |
| 2481 close (sock); | |
| 84 | 2482 return (GFTP_ERETRYABLE); |
| 1 | 2483 } |
| 2484 } | |
| 2485 | |
| 2486 disphost = NULL; | |
| 641 | 2487 for (request->curhost = 0; |
| 2488 request->host.h_addr_list[request->curhost] != NULL; | |
| 2489 request->curhost++) | |
| 1 | 2490 { |
| 2491 disphost = request->host.h_name; | |
| 641 | 2492 memcpy (&remote_address.sin_addr, |
| 2493 request->host.h_addr_list[request->curhost], | |
| 1 | 2494 request->host.h_length); |
| 186 | 2495 request->logging_function (gftp_logging_misc, request, |
| 1 | 2496 _("Trying %s:%d\n"), |
| 451 | 2497 request->host.h_name, port); |
| 1 | 2498 |
| 2499 if (connect (sock, (struct sockaddr *) &remote_address, | |
| 2500 sizeof (remote_address)) == -1) | |
| 2501 { | |
| 186 | 2502 request->logging_function (gftp_logging_error, request, |
| 1 | 2503 _("Cannot connect to %s: %s\n"), |
| 2504 connect_host, g_strerror (errno)); | |
| 2505 } | |
| 2506 break; | |
| 2507 } | |
| 2508 | |
| 641 | 2509 if (request->host.h_addr_list[request->curhost] == NULL) |
| 1 | 2510 { |
| 2511 close (sock); | |
| 84 | 2512 return (GFTP_ERETRYABLE); |
| 1 | 2513 } |
| 2514 #endif /* HAVE_GETADDRINFO */ | |
| 2515 | |
| 182 | 2516 if (fcntl (sock, F_SETFD, 1) == -1) |
| 2517 { | |
| 186 | 2518 request->logging_function (gftp_logging_error, request, |
| 182 | 2519 _("Error: Cannot set close on exec flag: %s\n"), |
| 2520 g_strerror (errno)); | |
| 2521 | |
| 2522 return (GFTP_ERETRYABLE); | |
| 2523 } | |
| 2524 | |
| 186 | 2525 request->logging_function (gftp_logging_misc, request, |
| 168 | 2526 _("Connected to %s:%d\n"), connect_host, port); |
| 58 | 2527 |
| 168 | 2528 if (gftp_fd_set_sockblocking (request, sock, 1) < 0) |
| 58 | 2529 { |
| 2530 close (sock); | |
| 84 | 2531 return (GFTP_ERETRYABLE); |
| 58 | 2532 } |
| 2533 | |
| 169 | 2534 request->datafd = sock; |
| 168 | 2535 |
| 2536 if (request->post_connect != NULL) | |
| 2537 return (request->post_connect (request)); | |
| 2538 | |
| 2539 return (0); | |
| 1 | 2540 } |
| 2541 | |
| 2542 | |
| 177 | 2543 int |
| 1 | 2544 gftp_set_config_options (gftp_request * request) |
| 2545 { | |
| 58 | 2546 if (request->set_config_options != NULL) |
| 177 | 2547 return (request->set_config_options (request)); |
| 2548 else | |
| 2549 return (0); | |
| 1 | 2550 } |
| 2551 | |
| 2552 | |
| 2553 void | |
| 2554 print_file_list (GList * list) | |
| 2555 { | |
| 2556 gftp_file * tempfle; | |
| 2557 GList * templist; | |
| 499 | 2558 char *attribs; |
| 1 | 2559 |
| 2560 printf ("--START OF FILE LISTING - TOP TO BOTTOM--\n"); | |
| 2561 for (templist = list; ; templist = templist->next) | |
| 2562 { | |
| 2563 tempfle = templist->data; | |
| 499 | 2564 attribs = gftp_convert_attributes_from_mode_t (tempfle->st_mode); |
| 2565 | |
| 532 | 2566 printf ("%s:%s:" GFTP_OFF_T_PRINTF_MOD ":" GFTP_OFF_T_PRINTF_MOD ":%s:%s:%s\n", |
| 372 | 2567 tempfle->file, tempfle->destfile, |
| 516 | 2568 tempfle->size, tempfle->startsize, |
| 499 | 2569 tempfle->user, tempfle->group, attribs); |
| 2570 | |
| 2571 g_free (attribs); | |
| 1 | 2572 if (templist->next == NULL) |
| 2573 break; | |
| 2574 } | |
| 2575 | |
| 2576 printf ("--START OF FILE LISTING - BOTTOM TO TOP--\n"); | |
| 2577 for (; ; templist = templist->prev) | |
| 2578 { | |
| 2579 tempfle = templist->data; | |
| 499 | 2580 attribs = gftp_convert_attributes_from_mode_t (tempfle->st_mode); |
| 2581 | |
| 532 | 2582 printf ("%s:%s:" GFTP_OFF_T_PRINTF_MOD ":" GFTP_OFF_T_PRINTF_MOD ":%s:%s:%s\n", |
| 372 | 2583 tempfle->file, tempfle->destfile, |
| 516 | 2584 tempfle->size, tempfle->startsize, |
| 499 | 2585 tempfle->user, tempfle->group, attribs); |
| 2586 | |
| 2587 g_free (attribs); | |
| 1 | 2588 if (templist == list) |
| 2589 break; | |
| 2590 } | |
| 2591 printf ("--END OF FILE LISTING--\n"); | |
| 2592 } | |
| 2593 | |
| 41 | 2594 |
| 201 | 2595 void |
| 58 | 2596 gftp_free_getline_buffer (gftp_getline_buffer ** rbuf) |
| 41 | 2597 { |
| 58 | 2598 g_free ((*rbuf)->buffer); |
| 2599 g_free (*rbuf); | |
| 2600 *rbuf = NULL; | |
| 41 | 2601 } |
| 2602 | |
| 2603 | |
| 58 | 2604 ssize_t |
| 2605 gftp_get_line (gftp_request * request, gftp_getline_buffer ** rbuf, | |
| 2606 char * str, size_t len, int fd) | |
| 41 | 2607 { |
| 168 | 2608 ssize_t (*read_function) (gftp_request * request, void *ptr, size_t size, |
| 2609 int fd); | |
| 516 | 2610 char *pos, *nextpos; |
| 2611 size_t rlen, nslen; | |
| 179 | 2612 int end_of_buffer; |
| 516 | 2613 ssize_t ret; |
| 168 | 2614 |
| 2615 if (request == NULL || request->read_function == NULL) | |
| 2616 read_function = gftp_fd_read; | |
| 2617 else | |
| 2618 read_function = request->read_function; | |
| 58 | 2619 |
| 2620 if (*rbuf == NULL) | |
| 2621 { | |
| 2622 *rbuf = g_malloc0 (sizeof (**rbuf)); | |
| 2623 (*rbuf)->max_bufsize = len; | |
| 765 | 2624 (*rbuf)->buffer = g_malloc0 ((gulong) ((*rbuf)->max_bufsize + 1)); |
| 168 | 2625 |
| 2626 if ((ret = read_function (request, (*rbuf)->buffer, | |
| 2627 (*rbuf)->max_bufsize, fd)) <= 0) | |
| 58 | 2628 { |
| 2629 gftp_free_getline_buffer (rbuf); | |
| 2630 return (ret); | |
| 2631 } | |
| 60 | 2632 (*rbuf)->buffer[ret] = '\0'; |
| 58 | 2633 (*rbuf)->cur_bufsize = ret; |
| 2634 (*rbuf)->curpos = (*rbuf)->buffer; | |
| 2635 } | |
| 2636 | |
| 516 | 2637 ret = 0; |
| 2638 while (1) | |
| 58 | 2639 { |
| 179 | 2640 pos = strchr ((*rbuf)->curpos, '\n'); |
| 2641 end_of_buffer = (*rbuf)->curpos == (*rbuf)->buffer && | |
| 2642 ((*rbuf)->max_bufsize == (*rbuf)->cur_bufsize || (*rbuf)->eof); | |
| 2643 | |
| 2644 if ((*rbuf)->cur_bufsize > 0 && (pos != NULL || end_of_buffer)) | |
| 58 | 2645 { |
| 2646 if (pos != NULL) | |
| 2647 { | |
| 516 | 2648 nslen = pos - (*rbuf)->curpos + 1; |
| 58 | 2649 nextpos = pos + 1; |
| 2650 if (pos > (*rbuf)->curpos && *(pos - 1) == '\r') | |
| 2651 pos--; | |
| 2652 *pos = '\0'; | |
| 2653 } | |
| 2654 else | |
| 249 | 2655 { |
| 516 | 2656 nslen = (*rbuf)->cur_bufsize; |
| 249 | 2657 nextpos = NULL; |
| 2658 | |
| 2659 /* This is not an overflow since we allocated one extra byte to | |
| 2660 buffer above */ | |
| 798 | 2661 ((*rbuf)->buffer)[nslen] = '\0'; |
| 249 | 2662 } |
| 58 | 2663 |
| 2664 strncpy (str, (*rbuf)->curpos, len); | |
| 249 | 2665 str[len - 1] = '\0'; |
| 516 | 2666 (*rbuf)->cur_bufsize -= nslen; |
| 58 | 2667 |
| 168 | 2668 if (nextpos != NULL) |
| 2669 (*rbuf)->curpos = nextpos; | |
| 2670 else | |
| 2671 (*rbuf)->cur_bufsize = 0; | |
| 516 | 2672 |
| 2673 ret = nslen; | |
| 58 | 2674 break; |
| 2675 } | |
| 2676 else | |
| 2677 { | |
| 2678 if ((*rbuf)->cur_bufsize == 0 || *(*rbuf)->curpos == '\0') | |
| 2679 { | |
| 2680 rlen = (*rbuf)->max_bufsize; | |
| 2681 pos = (*rbuf)->buffer; | |
| 2682 } | |
| 2683 else | |
| 2684 { | |
| 168 | 2685 memmove ((*rbuf)->buffer, (*rbuf)->curpos, (*rbuf)->cur_bufsize); |
| 2686 pos = (*rbuf)->buffer + (*rbuf)->cur_bufsize; | |
| 2687 rlen = (*rbuf)->max_bufsize - (*rbuf)->cur_bufsize; | |
| 58 | 2688 } |
| 168 | 2689 |
| 58 | 2690 (*rbuf)->curpos = (*rbuf)->buffer; |
| 2691 | |
| 209 | 2692 if ((*rbuf)->eof) |
| 2693 ret = 0; | |
| 2694 else | |
| 58 | 2695 { |
| 798 | 2696 ret = read_function (request, pos, rlen, fd); |
| 2697 if (ret < 0) | |
| 2698 { | |
| 2699 gftp_free_getline_buffer (rbuf); | |
| 2700 return (ret); | |
| 2701 } | |
| 58 | 2702 } |
| 798 | 2703 |
| 2704 if (ret == 0) | |
| 168 | 2705 { |
| 179 | 2706 if ((*rbuf)->cur_bufsize == 0) |
| 2707 { | |
| 2708 gftp_free_getline_buffer (rbuf); | |
| 2709 return (ret); | |
| 2710 } | |
| 2711 | |
| 2712 (*rbuf)->eof = 1; | |
| 168 | 2713 } |
| 2714 | |
| 2715 (*rbuf)->cur_bufsize += ret; | |
| 798 | 2716 (*rbuf)->buffer[(*rbuf)->cur_bufsize] = '\0'; |
| 58 | 2717 } |
| 2718 } | |
| 516 | 2719 |
| 2720 return (ret); | |
| 58 | 2721 } |
| 2722 | |
| 2723 | |
| 2724 ssize_t | |
| 168 | 2725 gftp_fd_read (gftp_request * request, void *ptr, size_t size, int fd) |
| 58 | 2726 { |
| 325 | 2727 intptr_t network_timeout; |
| 58 | 2728 struct timeval tv; |
| 2729 fd_set fset; | |
| 2730 ssize_t ret; | |
| 817 | 2731 int s_ret; |
| 41 | 2732 |
| 813 | 2733 g_return_val_if_fail (fd >= 0, GFTP_EFATAL); |
| 2734 | |
| 122 | 2735 gftp_lookup_request_option (request, "network_timeout", &network_timeout); |
| 2736 | |
| 41 | 2737 errno = 0; |
| 2738 ret = 0; | |
| 518 | 2739 |
| 546 | 2740 do |
| 41 | 2741 { |
| 58 | 2742 FD_ZERO (&fset); |
| 2743 FD_SET (fd, &fset); | |
| 122 | 2744 tv.tv_sec = network_timeout; |
| 58 | 2745 tv.tv_usec = 0; |
| 817 | 2746 s_ret = select (fd + 1, &fset, NULL, NULL, &tv); |
| 2747 if (s_ret == -1 && (errno == EINTR || errno == EAGAIN)) | |
| 41 | 2748 { |
| 546 | 2749 if (request != NULL && request->cancel) |
| 2750 { | |
| 2751 gftp_disconnect (request); | |
| 2752 return (GFTP_ERETRYABLE); | |
| 2753 } | |
| 2754 | |
| 2755 continue; | |
| 58 | 2756 } |
| 817 | 2757 else if (s_ret <= 0) |
| 58 | 2758 { |
| 2759 if (request != NULL) | |
| 41 | 2760 { |
| 186 | 2761 request->logging_function (gftp_logging_error, request, |
| 58 | 2762 _("Connection to %s timed out\n"), |
| 2763 request->hostname); | |
| 2764 gftp_disconnect (request); | |
| 2765 } | |
| 546 | 2766 |
| 84 | 2767 return (GFTP_ERETRYABLE); |
| 41 | 2768 } |
| 2769 | |
| 58 | 2770 if ((ret = read (fd, ptr, size)) < 0) |
| 41 | 2771 { |
| 546 | 2772 if (errno == EINTR || errno == EAGAIN) |
| 41 | 2773 { |
| 58 | 2774 if (request != NULL && request->cancel) |
| 546 | 2775 { |
| 2776 gftp_disconnect (request); | |
| 2777 return (GFTP_ERETRYABLE); | |
| 2778 } | |
| 2779 | |
| 2780 continue; | |
| 518 | 2781 } |
| 41 | 2782 |
| 58 | 2783 if (request != NULL) |
| 2784 { | |
| 186 | 2785 request->logging_function (gftp_logging_error, request, |
| 58 | 2786 _("Error: Could not read from socket: %s\n"), |
| 41 | 2787 g_strerror (errno)); |
| 58 | 2788 gftp_disconnect (request); |
| 2789 } | |
| 546 | 2790 |
| 84 | 2791 return (GFTP_ERETRYABLE); |
| 41 | 2792 } |
| 546 | 2793 |
| 518 | 2794 break; |
| 41 | 2795 } |
| 546 | 2796 while (1); |
| 41 | 2797 |
| 2798 return (ret); | |
| 2799 } | |
| 2800 | |
| 58 | 2801 |
| 2802 ssize_t | |
| 168 | 2803 gftp_fd_write (gftp_request * request, const char *ptr, size_t size, int fd) |
| 58 | 2804 { |
| 325 | 2805 intptr_t network_timeout; |
| 58 | 2806 struct timeval tv; |
| 817 | 2807 int ret, s_ret; |
| 248 | 2808 ssize_t w_ret; |
| 58 | 2809 fd_set fset; |
| 2810 | |
| 813 | 2811 g_return_val_if_fail (fd >= 0, GFTP_EFATAL); |
| 2812 | |
| 122 | 2813 gftp_lookup_request_option (request, "network_timeout", &network_timeout); |
| 2814 | |
| 58 | 2815 errno = 0; |
| 2816 ret = 0; | |
| 2817 do | |
| 2818 { | |
| 2819 FD_ZERO (&fset); | |
| 2820 FD_SET (fd, &fset); | |
| 122 | 2821 tv.tv_sec = network_timeout; |
| 58 | 2822 tv.tv_usec = 0; |
| 817 | 2823 s_ret = select (fd + 1, NULL, &fset, NULL, &tv); |
| 2824 if (s_ret == -1 && (errno == EINTR || errno == EAGAIN)) | |
| 58 | 2825 { |
| 2826 if (request != NULL && request->cancel) | |
| 546 | 2827 { |
| 2828 gftp_disconnect (request); | |
| 2829 return (GFTP_ERETRYABLE); | |
| 2830 } | |
| 2831 | |
| 2832 continue; | |
| 58 | 2833 } |
| 817 | 2834 else if (s_ret <= 0) |
| 58 | 2835 { |
| 2836 if (request != NULL) | |
| 2837 { | |
| 186 | 2838 request->logging_function (gftp_logging_error, request, |
| 58 | 2839 _("Connection to %s timed out\n"), |
| 2840 request->hostname); | |
| 2841 gftp_disconnect (request); | |
| 2842 } | |
| 546 | 2843 |
| 84 | 2844 return (GFTP_ERETRYABLE); |
| 58 | 2845 } |
| 2846 | |
| 248 | 2847 w_ret = write (fd, ptr, size); |
| 2848 if (w_ret < 0) | |
| 58 | 2849 { |
| 546 | 2850 if (errno == EINTR || errno == EAGAIN) |
| 58 | 2851 { |
| 2852 if (request != NULL && request->cancel) | |
| 546 | 2853 { |
| 2854 gftp_disconnect (request); | |
| 2855 return (GFTP_ERETRYABLE); | |
| 2856 } | |
| 2857 | |
| 2858 continue; | |
| 58 | 2859 } |
| 2860 | |
| 2861 if (request != NULL) | |
| 2862 { | |
| 186 | 2863 request->logging_function (gftp_logging_error, request, |
| 58 | 2864 _("Error: Could not write to socket: %s\n"), |
| 2865 g_strerror (errno)); | |
| 2866 gftp_disconnect (request); | |
| 2867 } | |
| 546 | 2868 |
| 84 | 2869 return (GFTP_ERETRYABLE); |
| 58 | 2870 } |
| 2871 | |
| 2872 ptr += w_ret; | |
| 2873 size -= w_ret; | |
| 2874 ret += w_ret; | |
| 2875 } | |
| 2876 while (size > 0); | |
| 2877 | |
| 2878 return (ret); | |
| 2879 } | |
| 2880 | |
| 2881 | |
| 2882 ssize_t | |
| 2883 gftp_writefmt (gftp_request * request, int fd, const char *fmt, ...) | |
| 2884 { | |
| 2885 char *tempstr; | |
| 2886 va_list argp; | |
| 2887 ssize_t ret; | |
| 2888 | |
| 2889 va_start (argp, fmt); | |
| 2890 tempstr = g_strdup_vprintf (fmt, argp); | |
| 2891 va_end (argp); | |
| 2892 | |
| 168 | 2893 ret = request->write_function (request, tempstr, strlen (tempstr), fd); |
| 58 | 2894 g_free (tempstr); |
| 2895 return (ret); | |
| 2896 } | |
| 2897 | |
| 2898 | |
| 2899 int | |
| 168 | 2900 gftp_fd_set_sockblocking (gftp_request * request, int fd, int non_blocking) |
| 58 | 2901 { |
| 2902 int flags; | |
| 2903 | |
| 813 | 2904 g_return_val_if_fail (fd >= 0, GFTP_EFATAL); |
| 2905 | |
| 84 | 2906 if ((flags = fcntl (fd, F_GETFL, 0)) < 0) |
| 58 | 2907 { |
| 186 | 2908 request->logging_function (gftp_logging_error, request, |
| 58 | 2909 _("Cannot get socket flags: %s\n"), |
| 2910 g_strerror (errno)); | |
| 2911 gftp_disconnect (request); | |
| 84 | 2912 return (GFTP_ERETRYABLE); |
| 58 | 2913 } |
| 2914 | |
| 2915 if (non_blocking) | |
| 2916 flags |= O_NONBLOCK; | |
| 2917 else | |
| 2918 flags &= ~O_NONBLOCK; | |
| 2919 | |
| 84 | 2920 if (fcntl (fd, F_SETFL, flags) < 0) |
| 58 | 2921 { |
| 186 | 2922 request->logging_function (gftp_logging_error, request, |
| 58 | 2923 _("Cannot set socket to non-blocking: %s\n"), |
| 2924 g_strerror (errno)); | |
| 2925 gftp_disconnect (request); | |
| 84 | 2926 return (GFTP_ERETRYABLE); |
| 58 | 2927 } |
| 2928 | |
| 2929 return (0); | |
| 2930 } | |
| 2931 | |
| 2932 | |
| 63 | 2933 void |
| 2934 gftp_swap_socks (gftp_request * dest, gftp_request * source) | |
| 2935 { | |
| 2936 g_return_if_fail (dest != NULL); | |
| 2937 g_return_if_fail (source != NULL); | |
| 2938 g_return_if_fail (dest->protonum == source->protonum); | |
| 2939 | |
| 2940 dest->datafd = source->datafd; | |
| 2941 dest->cached = 0; | |
| 397 | 2942 #ifdef USE_SSL |
| 2943 dest->ssl = source->ssl; | |
| 2944 #endif | |
| 2945 | |
| 63 | 2946 if (!source->always_connected) |
| 2947 { | |
| 2948 source->datafd = -1; | |
| 2949 source->cached = 1; | |
| 397 | 2950 #ifdef USE_SSL |
| 2951 source->ssl = NULL; | |
| 2952 #endif | |
| 63 | 2953 } |
| 2954 | |
| 516 | 2955 if (dest->swap_socks != NULL) |
| 63 | 2956 dest->swap_socks (dest, source); |
| 2957 } | |
| 2958 | |
| 122 | 2959 |
| 2960 void | |
| 2961 gftp_calc_kbs (gftp_transfer * tdata, ssize_t num_read) | |
| 2962 { | |
| 469 | 2963 /* Needed for systems that size(float) < size(void *) */ |
| 2964 union { intptr_t i; float f; } maxkbs; | |
| 122 | 2965 unsigned long waitusecs; |
| 220 | 2966 double start_difftime; |
| 122 | 2967 struct timeval tv; |
| 222 | 2968 int waited; |
| 122 | 2969 |
| 469 | 2970 gftp_lookup_request_option (tdata->fromreq, "maxkbs", &maxkbs.f); |
| 122 | 2971 |
| 2972 if (g_thread_supported ()) | |
| 2973 g_static_mutex_lock (&tdata->statmutex); | |
| 2974 | |
| 220 | 2975 gettimeofday (&tv, NULL); |
| 2976 | |
| 122 | 2977 tdata->trans_bytes += num_read; |
| 2978 tdata->curtrans += num_read; | |
| 2979 tdata->stalled = 0; | |
| 2980 | |
| 220 | 2981 start_difftime = (tv.tv_sec - tdata->starttime.tv_sec) + ((double) (tv.tv_usec - tdata->starttime.tv_usec) / 1000000.0); |
| 2982 | |
| 2983 if (start_difftime <= 0) | |
| 2984 tdata->kbs = tdata->trans_bytes / 1024.0; | |
| 122 | 2985 else |
| 220 | 2986 tdata->kbs = tdata->trans_bytes / 1024.0 / start_difftime; |
| 2987 | |
| 222 | 2988 waited = 0; |
| 469 | 2989 if (maxkbs.f > 0 && tdata->kbs > maxkbs.f) |
| 122 | 2990 { |
| 469 | 2991 waitusecs = num_read / 1024.0 / maxkbs.f * 1000000.0 - start_difftime; |
| 122 | 2992 |
| 2993 if (waitusecs > 0) | |
| 2994 { | |
| 2995 if (g_thread_supported ()) | |
| 2996 g_static_mutex_unlock (&tdata->statmutex); | |
| 2997 | |
| 222 | 2998 waited = 1; |
| 122 | 2999 usleep (waitusecs); |
| 3000 | |
| 3001 if (g_thread_supported ()) | |
| 3002 g_static_mutex_lock (&tdata->statmutex); | |
| 3003 } | |
| 222 | 3004 |
| 122 | 3005 } |
| 3006 | |
| 222 | 3007 if (waited) |
| 3008 gettimeofday (&tdata->lasttime, NULL); | |
| 3009 else | |
| 3010 memcpy (&tdata->lasttime, &tv, sizeof (tdata->lasttime)); | |
| 122 | 3011 |
| 3012 if (g_thread_supported ()) | |
| 3013 g_static_mutex_unlock (&tdata->statmutex); | |
| 3014 } | |
| 3015 | |
| 125 | 3016 |
| 764 | 3017 static int |
| 3018 _do_sleep (int sleep_time) | |
| 3019 { | |
| 3020 struct timeval tv; | |
| 3021 int ret; | |
| 3022 | |
| 3023 tv.tv_sec = sleep_time; | |
| 3024 tv.tv_usec = 0; | |
| 3025 | |
| 3026 /* FIXME - check for user aborted connection */ | |
| 3027 do | |
| 3028 { | |
| 3029 ret = select (0, NULL, NULL, NULL, &tv); | |
| 3030 } | |
| 3031 while (ret == -1 && (errno == EINTR || errno == EAGAIN)); | |
| 3032 | |
| 3033 return (ret); | |
| 3034 } | |
| 3035 | |
| 3036 | |
| 125 | 3037 int |
| 3038 gftp_get_transfer_status (gftp_transfer * tdata, ssize_t num_read) | |
| 3039 { | |
| 325 | 3040 intptr_t retries, sleep_time; |
| 125 | 3041 gftp_file * tempfle; |
| 498 | 3042 int ret1, ret2; |
| 125 | 3043 |
| 3044 gftp_lookup_request_option (tdata->fromreq, "retries", &retries); | |
| 3045 gftp_lookup_request_option (tdata->fromreq, "sleep_time", &sleep_time); | |
| 3046 | |
| 3047 if (g_thread_supported ()) | |
| 3048 g_static_mutex_lock (&tdata->structmutex); | |
| 3049 | |
| 3050 if (tdata->curfle == NULL) | |
| 3051 { | |
| 3052 if (g_thread_supported ()) | |
| 3053 g_static_mutex_unlock (&tdata->structmutex); | |
| 3054 | |
| 3055 return (GFTP_EFATAL); | |
| 3056 } | |
| 3057 | |
| 3058 tempfle = tdata->curfle->data; | |
| 3059 | |
| 3060 if (g_thread_supported ()) | |
| 3061 g_static_mutex_unlock (&tdata->structmutex); | |
| 3062 | |
| 3063 gftp_disconnect (tdata->fromreq); | |
| 3064 gftp_disconnect (tdata->toreq); | |
| 3065 | |
| 764 | 3066 if (tdata->cancel || num_read == GFTP_EFATAL) |
| 3067 return (GFTP_EFATAL); | |
| 3068 else if (num_read >= 0 && !tdata->skip_file) | |
| 3069 return (0); | |
| 3070 | |
| 3071 if (num_read != GFTP_ETIMEDOUT && !tdata->conn_error_no_timeout) | |
| 125 | 3072 { |
| 764 | 3073 if (retries != 0 && |
| 3074 tdata->current_file_retries >= retries) | |
| 3075 { | |
| 3076 tdata->fromreq->logging_function (gftp_logging_error, tdata->fromreq, | |
| 3077 _("Error: Remote site %s disconnected. Max retries reached...giving up\n"), | |
| 3078 tdata->fromreq->hostname != NULL ? | |
| 3079 tdata->fromreq->hostname : tdata->toreq->hostname); | |
| 3080 return (GFTP_EFATAL); | |
| 3081 } | |
| 3082 else | |
| 125 | 3083 { |
| 764 | 3084 tdata->fromreq->logging_function (gftp_logging_error, tdata->fromreq, |
| 3085 _("Error: Remote site %s disconnected. Will reconnect in %d seconds\n"), | |
| 3086 tdata->fromreq->hostname != NULL ? | |
| 3087 tdata->fromreq->hostname : tdata->toreq->hostname, | |
| 3088 sleep_time); | |
| 3089 } | |
| 3090 } | |
| 3091 | |
| 3092 while (retries == 0 || | |
| 3093 tdata->current_file_retries <= retries) | |
| 3094 { | |
| 3095 /* Look up the options in case the user changes them... */ | |
| 3096 gftp_lookup_request_option (tdata->fromreq, "retries", &retries); | |
| 3097 gftp_lookup_request_option (tdata->fromreq, "sleep_time", &sleep_time); | |
| 3098 | |
| 3099 if (num_read != GFTP_ETIMEDOUT && !tdata->conn_error_no_timeout && | |
| 3100 !tdata->skip_file) | |
| 3101 _do_sleep (sleep_time); | |
| 3102 | |
| 3103 tdata->current_file_retries++; | |
| 3104 | |
| 3105 ret1 = ret2 = 0; | |
| 3106 if ((ret1 = gftp_connect (tdata->fromreq)) == 0 && | |
| 3107 (ret2 = gftp_connect (tdata->toreq)) == 0) | |
| 3108 { | |
| 3109 if (g_thread_supported ()) | |
| 3110 g_static_mutex_lock (&tdata->structmutex); | |
| 3111 | |
| 3112 tdata->resumed_bytes = tdata->resumed_bytes + tdata->trans_bytes - tdata->curresumed - tdata->curtrans; | |
| 3113 tdata->trans_bytes = 0; | |
| 3114 if (tdata->skip_file) | |
| 303 | 3115 { |
| 764 | 3116 tdata->total_bytes -= tempfle->size; |
| 3117 tdata->curtrans = 0; | |
| 3118 | |
| 3119 tdata->curfle = tdata->curfle->next; | |
| 3120 tdata->next_file = 1; | |
| 3121 tdata->skip_file = 0; | |
| 3122 tdata->cancel = 0; | |
| 3123 tdata->fromreq->cancel = 0; | |
| 3124 tdata->toreq->cancel = 0; | |
| 303 | 3125 } |
| 3126 else | |
| 3127 { | |
| 764 | 3128 tempfle->transfer_action = GFTP_TRANS_ACTION_RESUME; |
| 3129 tempfle->startsize = tdata->curtrans + tdata->curresumed; | |
| 3130 /* We decrement this here because it will be incremented in | |
| 3131 the loop again */ | |
| 3132 tdata->curresumed = 0; | |
| 3133 tdata->current_file_number--; /* Decrement this because it | |
| 3134 will be incremented when we | |
| 3135 continue in the loop */ | |
| 125 | 3136 } |
| 3137 | |
| 764 | 3138 gettimeofday (&tdata->starttime, NULL); |
| 3139 | |
| 3140 if (g_thread_supported ()) | |
| 3141 g_static_mutex_unlock (&tdata->structmutex); | |
| 3142 | |
| 3143 return (GFTP_ERETRYABLE); | |
| 3144 } | |
| 3145 else if (ret1 == GFTP_EFATAL || ret2 == GFTP_EFATAL) | |
| 3146 { | |
| 3147 gftp_disconnect (tdata->fromreq); | |
| 3148 gftp_disconnect (tdata->toreq); | |
| 3149 return (GFTP_EFATAL); | |
| 125 | 3150 } |
| 3151 } | |
| 3152 | |
| 3153 return (0); | |
| 3154 } | |
| 3155 | |
| 182 | 3156 |
| 3157 int | |
| 3158 gftp_fd_open (gftp_request * request, const char *pathname, int flags, mode_t mode) | |
| 3159 { | |
| 3160 int fd; | |
| 3161 | |
| 227 | 3162 if (mode == 0) |
| 3163 fd = open (pathname, flags); | |
| 3164 else | |
| 3165 fd = open (pathname, flags, mode); | |
| 3166 | |
| 3167 if (fd < 0) | |
| 182 | 3168 { |
| 3169 if (request != NULL) | |
| 186 | 3170 request->logging_function (gftp_logging_error, request, |
| 182 | 3171 _("Error: Cannot open local file %s: %s\n"), |
| 3172 pathname, g_strerror (errno)); | |
| 3173 return (GFTP_ERETRYABLE); | |
| 3174 } | |
| 3175 | |
| 3176 if (fcntl (fd, F_SETFD, 1) == -1) | |
| 3177 { | |
| 3178 if (request != NULL) | |
| 186 | 3179 request->logging_function (gftp_logging_error, request, |
| 182 | 3180 _("Error: Cannot set close on exec flag: %s\n"), |
| 3181 g_strerror (errno)); | |
| 3182 | |
| 3183 return (-1); | |
| 3184 } | |
| 3185 | |
| 3186 return (fd); | |
| 3187 } | |
| 422 | 3188 |
| 3189 | |
| 3190 void | |
| 792 | 3191 gftp_setup_startup_directory (gftp_request * request, const char *option_name) |
| 422 | 3192 { |
| 3193 char *startup_directory, *tempstr; | |
| 3194 | |
| 792 | 3195 gftp_lookup_request_option (request, option_name, &startup_directory); |
| 422 | 3196 |
| 3197 if (*startup_directory != '\0' && | |
| 555 | 3198 (tempstr = gftp_expand_path (request, startup_directory)) != NULL) |
| 422 | 3199 { |
| 3200 gftp_set_directory (request, tempstr); | |
| 3201 g_free (tempstr); | |
| 3202 } | |
| 3203 } | |
| 3204 | |
| 499 | 3205 |
| 3206 char * | |
| 3207 gftp_convert_attributes_from_mode_t (mode_t mode) | |
| 3208 { | |
| 3209 char *str; | |
| 3210 | |
| 765 | 3211 str = g_malloc0 (11UL); |
| 499 | 3212 |
| 3213 str[0] = '?'; | |
| 3214 if (S_ISREG (mode)) | |
| 3215 str[0] = '-'; | |
| 3216 | |
| 3217 if (S_ISLNK (mode)) | |
| 3218 str[0] = 'l'; | |
| 3219 | |
| 3220 if (S_ISBLK (mode)) | |
| 3221 str[0] = 'b'; | |
| 3222 | |
| 3223 if (S_ISCHR (mode)) | |
| 3224 str[0] = 'c'; | |
| 3225 | |
| 3226 if (S_ISFIFO (mode)) | |
| 3227 str[0] = 'p'; | |
| 3228 | |
| 3229 if (S_ISSOCK (mode)) | |
| 3230 str[0] = 's'; | |
| 3231 | |
| 3232 if (S_ISDIR (mode)) | |
| 3233 str[0] = 'd'; | |
| 3234 | |
| 3235 str[1] = mode & S_IRUSR ? 'r' : '-'; | |
| 3236 str[2] = mode & S_IWUSR ? 'w' : '-'; | |
| 3237 | |
| 3238 if ((mode & S_ISUID) && (mode & S_IXUSR)) | |
| 3239 str[3] = 's'; | |
| 3240 else if (mode & S_ISUID) | |
| 3241 str[3] = 'S'; | |
| 3242 else if (mode & S_IXUSR) | |
| 3243 str[3] = 'x'; | |
| 3244 else | |
| 3245 str[3] = '-'; | |
| 3246 | |
| 3247 str[4] = mode & S_IRGRP ? 'r' : '-'; | |
| 3248 str[5] = mode & S_IWGRP ? 'w' : '-'; | |
| 3249 | |
| 3250 if ((mode & S_ISGID) && (mode & S_IXGRP)) | |
| 3251 str[6] = 's'; | |
| 3252 else if (mode & S_ISGID) | |
| 3253 str[6] = 'S'; | |
| 3254 else if (mode & S_IXGRP) | |
| 3255 str[6] = 'x'; | |
| 3256 else | |
| 3257 str[6] = '-'; | |
| 3258 | |
| 3259 str[7] = mode & S_IROTH ? 'r' : '-'; | |
| 3260 str[8] = mode & S_IWOTH ? 'w' : '-'; | |
| 3261 | |
| 3262 if ((mode & S_ISVTX) && (mode & S_IXOTH)) | |
| 3263 str[9] = 't'; | |
| 3264 else if (mode & S_ISVTX) | |
| 3265 str[9] = 'T'; | |
| 3266 else if (mode & S_IXOTH) | |
| 3267 str[9] = 'x'; | |
| 3268 else | |
| 3269 str[9] = '-'; | |
| 3270 | |
| 3271 return (str); | |
| 3272 } | |
| 3273 | |
| 3274 | |
| 3275 mode_t | |
| 3276 gftp_convert_attributes_to_mode_t (char *attribs) | |
| 3277 { | |
| 3278 mode_t mode; | |
| 3279 | |
| 3280 if (attribs[0] == 'd') | |
| 3281 mode = S_IFDIR; | |
| 3282 else if (attribs[0] == 'l') | |
| 3283 mode = S_IFLNK; | |
| 3284 else if (attribs[0] == 's') | |
| 3285 mode = S_IFSOCK; | |
| 3286 else if (attribs[0] == 'b') | |
| 3287 mode = S_IFBLK; | |
| 3288 else if (attribs[0] == 'c') | |
| 3289 mode = S_IFCHR; | |
| 3290 else | |
| 3291 mode = S_IFREG; | |
| 3292 | |
| 3293 if (attribs[1] == 'r') | |
| 3294 mode |= S_IRUSR; | |
| 3295 if (attribs[2] == 'w') | |
| 3296 mode |= S_IWUSR; | |
| 3297 if (attribs[3] == 'x' || attribs[3] == 's') | |
| 3298 mode |= S_IXUSR; | |
| 3299 if (attribs[3] == 's' || attribs[3] == 'S') | |
| 3300 mode |= S_ISUID; | |
| 3301 | |
| 3302 if (attribs[4] == 'r') | |
| 3303 mode |= S_IRGRP; | |
| 3304 if (attribs[5] == 'w') | |
| 3305 mode |= S_IWGRP; | |
| 3306 if (attribs[6] == 'x' || | |
| 3307 attribs[6] == 's') | |
| 3308 mode |= S_IXGRP; | |
| 3309 if (attribs[6] == 's' || attribs[6] == 'S') | |
| 3310 mode |= S_ISGID; | |
| 3311 | |
| 3312 if (attribs[7] == 'r') | |
| 3313 mode |= S_IROTH; | |
| 3314 if (attribs[8] == 'w') | |
| 3315 mode |= S_IWOTH; | |
| 3316 if (attribs[9] == 'x' || | |
| 3317 attribs[9] == 's') | |
| 3318 mode |= S_IXOTH; | |
| 3319 if (attribs[9] == 't' || attribs[9] == 'T') | |
| 3320 mode |= S_ISVTX; | |
| 3321 | |
| 3322 return (mode); | |
| 3323 } | |
| 3324 | |
| 542 | 3325 |
| 3326 unsigned int | |
| 3327 gftp_protocol_default_port (gftp_request * request) | |
| 3328 { | |
| 3329 struct servent serv_struct; | |
| 3330 | |
| 3331 if (r_getservbyname (gftp_protocols[request->protonum].url_prefix, "tcp", | |
| 3332 &serv_struct, NULL) == NULL) | |
| 3333 return (gftp_protocols[request->protonum].default_port); | |
| 3334 else | |
| 3335 return (ntohs (serv_struct.s_port)); | |
| 3336 } | |
| 3337 |
