Mercurial > gftp.yaz
comparison src/uicommon/gftpui.c @ 367:d5409bf03ff1
2003-1-18 Brian Masney <masneyb@gftp.org>
* lib/protocols.c (gftp_parse_url) - if the URL is the local filesystem, skip over the whitespace at the beginning.
* lib/rfc959.c (rfc959_syst) - allow the string MVS and OS/MVS for the
MVS directory listings.
* src/gtk/gtkui_transfer.c src/gtk/transfer.c src/gtk/gftpui.c -
started to move the transfer functionality into the uicommon directory.
Added the text and GTK+ UI specific transfer functions.
* src/gtk/Makefile.am po/POTFILES.in - added gtkui_transfer.c
* src/gtk/dnd.c src/gtk/gtkui_transfer.c src/gtk/view_dialog.c -
s/add_file_transfer/gtkui_common_add_file_transfer/
* src/gtk/gftp-gtk.c src/gtk/gftp-gtk.h - removed transfer_mutex
* src/gtk/gtkui.c src/text/textui.c - added
gftpui_add_file_to_transfer()
* src/uicommon/gftpui_callbacks.c src/uicommon/gftpui.c - in all of the
thread callback functions, don't alter the return value in the function. Return it as is.
author | masneyb |
---|---|
date | Sun, 18 Jan 2004 20:09:28 +0000 |
parents | 7cb3327f96f7 |
children | af541d789f4c |
comparison
equal
deleted
inserted
replaced
366:2e408d9918d4 | 367:d5409bf03ff1 |
---|---|
22 | 22 |
23 sigjmp_buf gftpui_common_jmp_environment; | 23 sigjmp_buf gftpui_common_jmp_environment; |
24 volatile int gftpui_common_use_jmp_environment = 0; | 24 volatile int gftpui_common_use_jmp_environment = 0; |
25 | 25 |
26 static void *gftpui_common_local_uidata, *gftpui_common_remote_uidata; | 26 static void *gftpui_common_local_uidata, *gftpui_common_remote_uidata; |
27 static gftp_request * gftpui_common_local_request, * gftpui_common_remote_request; | 27 static gftp_request * gftpui_common_local_request, |
28 * gftpui_common_remote_request; | |
29 GStaticMutex gftpui_common_transfer_mutex = G_STATIC_MUTEX_INIT; | |
28 | 30 |
29 | 31 |
30 static gftp_logging_func | 32 static gftp_logging_func |
31 _gftpui_common_log (gftp_request * request) | 33 _gftpui_common_log (gftp_request * request) |
32 { | 34 { |
38 | 40 |
39 | 41 |
40 static void * | 42 static void * |
41 _gftpui_common_thread_callback (void * data) | 43 _gftpui_common_thread_callback (void * data) |
42 { | 44 { |
45 intptr_t network_timeout, sleep_time; | |
43 gftpui_callback_data * cdata; | 46 gftpui_callback_data * cdata; |
44 intptr_t network_timeout; | |
45 int success, sj; | 47 int success, sj; |
46 | 48 |
47 cdata = data; | 49 cdata = data; |
48 gftp_lookup_request_option (cdata->request, "network_timeout", | 50 gftp_lookup_request_option (cdata->request, "network_timeout", |
49 &network_timeout); | 51 &network_timeout); |
52 gftp_lookup_request_option (cdata->request, "sleep_time", | |
53 &sleep_time); | |
50 | 54 |
51 sj = sigsetjmp (gftpui_common_jmp_environment, 1); | 55 sj = sigsetjmp (gftpui_common_jmp_environment, 1); |
52 gftpui_common_use_jmp_environment = 1; | 56 gftpui_common_use_jmp_environment = 1; |
53 | 57 |
54 success = 0; | 58 success = GFTP_ERETRYABLE; |
55 if (sj == 0) | 59 if (sj == 0) |
56 { | 60 { |
57 if (network_timeout > 0) | 61 while (1) |
58 alarm (network_timeout); | 62 { |
59 | 63 if (network_timeout > 0) |
60 success = cdata->run_function (cdata); | 64 alarm (network_timeout); |
61 | 65 success = cdata->run_function (cdata); |
62 alarm (0); | 66 alarm (0); |
67 | |
68 if (success == GFTP_EFATAL || success == 0 || cdata->retries == 0) | |
69 break; | |
70 | |
71 cdata->request->logging_function (gftp_logging_misc, cdata->request, | |
72 _("Waiting %d seconds until trying to connect again\n"), | |
73 sleep_time); | |
74 alarm (sleep_time); | |
75 pause (); | |
76 cdata->retries--; | |
77 } | |
63 } | 78 } |
64 else | 79 else |
65 { | 80 { |
66 gftp_disconnect (cdata->request); | 81 gftp_disconnect (cdata->request); |
67 cdata->request->logging_function (gftp_logging_error, cdata->request, | 82 cdata->request->logging_function (gftp_logging_error, cdata->request, |
86 if (gftp_protocols[cdata->request->protonum].use_threads) | 101 if (gftp_protocols[cdata->request->protonum].use_threads) |
87 ret = GPOINTER_TO_INT (gftpui_generic_thread (_gftpui_common_thread_callback, cdata)); | 102 ret = GPOINTER_TO_INT (gftpui_generic_thread (_gftpui_common_thread_callback, cdata)); |
88 else | 103 else |
89 ret = GPOINTER_TO_INT (cdata->run_function (cdata)); | 104 ret = GPOINTER_TO_INT (cdata->run_function (cdata)); |
90 | 105 |
91 if (ret && cdata->run_function != gftpui_common_run_ls) | 106 if (ret == 0 && cdata->run_function != gftpui_common_run_ls) |
92 gftpui_refresh (cdata->uidata); | 107 gftpui_refresh (cdata->uidata); |
93 | 108 |
94 return (ret); | 109 return (ret == 0); |
95 } | 110 } |
96 | 111 |
97 | 112 |
98 RETSIGTYPE | 113 RETSIGTYPE |
99 gftpui_common_signal_handler (int signo) | 114 gftpui_common_signal_handler (int signo) |
543 | 558 |
544 return (1); | 559 return (1); |
545 } | 560 } |
546 | 561 |
547 | 562 |
548 static int | 563 int |
549 gftpui_common_cmd_open (void *uidata, gftp_request * request, char *command) | 564 gftpui_common_cmd_open (void *uidata, gftp_request * request, char *command) |
550 { | 565 { |
566 gftpui_callback_data * cdata; | |
567 intptr_t retries; | |
551 char *tempstr; | 568 char *tempstr; |
552 | 569 |
553 if (GFTP_IS_CONNECTED (request)) | 570 if (GFTP_IS_CONNECTED (request)) |
554 { | 571 { |
555 gftp_disconnect (request); /* FIXME */ | 572 gftp_disconnect (request); /* FIXME */ |
556 } | 573 } |
557 | 574 |
558 if (*command == '\0') | 575 if (command != NULL) |
559 { | 576 { |
560 request->logging_function (gftp_logging_error, request, | 577 if (*command == '\0') |
561 _("usage: open " GFTP_URL_USAGE "\n")); | 578 { |
562 return (1); | 579 request->logging_function (gftp_logging_error, request, |
563 } | 580 _("usage: open " GFTP_URL_USAGE "\n")); |
581 return (1); | |
582 } | |
564 | 583 |
565 if (gftp_parse_url (request, command) < 0) | 584 if (gftp_parse_url (request, command) < 0) |
566 return (1); | 585 return (1); |
586 } | |
567 | 587 |
568 if (request->need_userpass) | 588 if (request->need_userpass) |
569 { | 589 { |
570 if (request->username == NULL || *request->username == '\0') | 590 if (request->username == NULL || *request->username == '\0') |
571 { | 591 { |
587 g_free (tempstr); | 607 g_free (tempstr); |
588 } | 608 } |
589 } | 609 } |
590 } | 610 } |
591 | 611 |
592 /* FIXME gftp_connect (request); */ | 612 gftp_lookup_request_option (request, "retries", &retries); |
613 | |
614 cdata = g_malloc0 (sizeof (*cdata)); | |
615 cdata->request = request; | |
616 cdata->uidata = uidata; | |
617 cdata->run_function = gftpui_common_run_connect; | |
618 cdata->retries = retries; | |
619 | |
620 gftpui_common_run_callback_function (cdata); | |
621 | |
622 g_free (cdata); | |
593 | 623 |
594 return (1); | 624 return (1); |
595 } | 625 } |
596 | 626 |
597 | 627 |
916 | 946 |
917 g_free (newstr); | 947 g_free (newstr); |
918 return (ret); | 948 return (ret); |
919 } | 949 } |
920 | 950 |
951 | |
952 gftp_transfer * | |
953 gftpui_common_add_file_transfer (gftp_request * fromreq, gftp_request * toreq, | |
954 void *fromuidata, void *touidata, | |
955 GList * files) | |
956 { | |
957 intptr_t append_transfers, one_transfer; | |
958 GList * templist, *curfle; | |
959 gftp_transfer * tdata; | |
960 gftp_file * tempfle; | |
961 int show_dialog; | |
962 char *pos; | |
963 | |
964 for (templist = files; templist != NULL; templist = templist->next) | |
965 { | |
966 tempfle = templist->data; | |
967 if (tempfle->startsize > 0) | |
968 break; | |
969 } | |
970 show_dialog = templist != NULL; | |
971 | |
972 gftp_lookup_request_option (fromreq, "append_transfers", | |
973 &append_transfers); | |
974 gftp_lookup_request_option (fromreq, "one_transfer", | |
975 &one_transfer); | |
976 | |
977 tdata = NULL; | |
978 if (append_transfers && one_transfer && !show_dialog) | |
979 { | |
980 if (g_thread_supported ()) | |
981 g_static_mutex_lock (&gftpui_common_transfer_mutex); | |
982 | |
983 for (templist = gftp_file_transfers; | |
984 templist != NULL; | |
985 templist = templist->next) | |
986 { | |
987 tdata = templist->data; | |
988 | |
989 if (g_thread_supported ()) | |
990 g_static_mutex_lock (&tdata->structmutex); | |
991 | |
992 if (!compare_request (tdata->fromreq, fromreq, 0) || | |
993 !compare_request (tdata->toreq, toreq, 0) || | |
994 tdata->curfle == NULL) | |
995 { | |
996 if (g_thread_supported ()) | |
997 g_static_mutex_unlock (&tdata->structmutex); | |
998 | |
999 continue; | |
1000 } | |
1001 | |
1002 tdata->files = g_list_concat (tdata->files, files); | |
1003 | |
1004 for (curfle = files; curfle != NULL; curfle = curfle->next) | |
1005 { | |
1006 tempfle = curfle->data; | |
1007 | |
1008 if (tempfle->isdir) | |
1009 tdata->numdirs++; | |
1010 else | |
1011 tdata->numfiles++; | |
1012 | |
1013 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
1014 tdata->total_bytes += tempfle->size; | |
1015 | |
1016 if ((pos = strrchr (tempfle->file, '/')) == NULL) | |
1017 pos = tempfle->file; | |
1018 else | |
1019 pos++; | |
1020 | |
1021 gftpui_add_file_to_transfer (tdata, curfle, pos); | |
1022 } | |
1023 | |
1024 if (g_thread_supported ()) | |
1025 g_static_mutex_unlock (&tdata->structmutex); | |
1026 | |
1027 break; | |
1028 } | |
1029 | |
1030 if (g_thread_supported ()) | |
1031 g_static_mutex_unlock (&gftpui_common_transfer_mutex); | |
1032 } | |
1033 else | |
1034 templist = NULL; | |
1035 | |
1036 if (templist == NULL) | |
1037 { | |
1038 tdata = gftp_tdata_new (); | |
1039 tdata->fromreq = copy_request (fromreq, 0); | |
1040 tdata->toreq = copy_request (toreq, 0); | |
1041 | |
1042 tdata->fromwdata = fromuidata; | |
1043 tdata->towdata = touidata; | |
1044 | |
1045 if (!show_dialog) | |
1046 tdata->show = tdata->ready = 1; | |
1047 | |
1048 tdata->files = files; | |
1049 for (curfle = files; curfle != NULL; curfle = curfle->next) | |
1050 { | |
1051 tempfle = curfle->data; | |
1052 if (tempfle->isdir) | |
1053 tdata->numdirs++; | |
1054 else | |
1055 tdata->numfiles++; | |
1056 | |
1057 if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) | |
1058 tdata->total_bytes += tempfle->size; | |
1059 } | |
1060 | |
1061 if (g_thread_supported ()) | |
1062 g_static_mutex_lock (&gftpui_common_transfer_mutex); | |
1063 | |
1064 gftp_file_transfers = g_list_append (gftp_file_transfers, tdata); | |
1065 | |
1066 if (g_thread_supported ()) | |
1067 g_static_mutex_unlock (&gftpui_common_transfer_mutex); | |
1068 | |
1069 if (show_dialog) | |
1070 gftpui_ask_transfer (tdata); | |
1071 } | |
1072 | |
1073 return (tdata); | |
1074 } | |
1075 | |
1076 | |
1077 static void | |
1078 _gftpui_common_setup_fds (gftp_transfer * tdata, gftp_file * curfle, | |
1079 int *fromfd, int *tofd) | |
1080 { | |
1081 *tofd = -1; | |
1082 *fromfd = -1; | |
1083 | |
1084 if (curfle->is_fd) | |
1085 { | |
1086 if (tdata->toreq->protonum == GFTP_LOCAL_NUM) | |
1087 *tofd = curfle->fd; | |
1088 else if (tdata->fromreq->protonum == GFTP_LOCAL_NUM) | |
1089 *fromfd = curfle->fd; | |
1090 } | |
1091 } | |
1092 | |
1093 | |
1094 static void | |
1095 _gftpui_common_done_with_fds (gftp_transfer * tdata, gftp_file * curfle) | |
1096 { | |
1097 if (curfle->is_fd) | |
1098 { | |
1099 if (tdata->toreq->protonum == GFTP_LOCAL_NUM) | |
1100 tdata->toreq->datafd = -1; | |
1101 else | |
1102 tdata->fromreq->datafd = -1; | |
1103 } | |
1104 } | |
1105 | |
1106 | |
1107 int | |
1108 gftpui_common_transfer_files (gftp_transfer * tdata) | |
1109 { | |
1110 int i, mode, tofd, fromfd; | |
1111 intptr_t preserve_permissions; | |
1112 char buf[8192]; | |
1113 off_t fromsize, total; | |
1114 gftp_file * curfle; | |
1115 ssize_t num_read, ret; | |
1116 | |
1117 tdata->curfle = tdata->files; | |
1118 gettimeofday (&tdata->starttime, NULL); | |
1119 memcpy (&tdata->lasttime, &tdata->starttime, | |
1120 sizeof (tdata->lasttime)); | |
1121 | |
1122 gftp_lookup_request_option (tdata->fromreq, "preserve_permissions", | |
1123 &preserve_permissions); | |
1124 | |
1125 while (tdata->curfle != NULL) | |
1126 { | |
1127 num_read = -1; | |
1128 | |
1129 if (g_thread_supported ()) | |
1130 g_static_mutex_lock (&tdata->structmutex); | |
1131 | |
1132 curfle = tdata->curfle->data; | |
1133 tdata->current_file_number++; | |
1134 | |
1135 if (g_thread_supported ()) | |
1136 g_static_mutex_unlock (&tdata->structmutex); | |
1137 | |
1138 if (curfle->transfer_action == GFTP_TRANS_ACTION_SKIP) | |
1139 { | |
1140 if (g_thread_supported ()) | |
1141 g_static_mutex_lock (&tdata->structmutex); | |
1142 | |
1143 tdata->next_file = 1; | |
1144 tdata->curfle = tdata->curfle->next; | |
1145 | |
1146 if (g_thread_supported ()) | |
1147 g_static_mutex_unlock (&tdata->structmutex); | |
1148 continue; | |
1149 } | |
1150 | |
1151 fromsize = -1; | |
1152 if (gftp_connect (tdata->fromreq) == 0 && | |
1153 gftp_connect (tdata->toreq) == 0) | |
1154 { | |
1155 if (curfle->isdir) | |
1156 { | |
1157 if (tdata->toreq->mkdir != NULL) | |
1158 { | |
1159 tdata->toreq->mkdir (tdata->toreq, curfle->destfile); | |
1160 if (!GFTP_IS_CONNECTED (tdata->toreq)) | |
1161 break; | |
1162 } | |
1163 | |
1164 if (g_thread_supported ()) | |
1165 g_static_mutex_lock (&tdata->structmutex); | |
1166 | |
1167 tdata->next_file = 1; | |
1168 tdata->curfle = tdata->curfle->next; | |
1169 | |
1170 if (g_thread_supported ()) | |
1171 g_static_mutex_unlock (&tdata->structmutex); | |
1172 continue; | |
1173 } | |
1174 | |
1175 _gftpui_common_setup_fds (tdata, curfle, &fromfd, &tofd); | |
1176 | |
1177 if (curfle->size == 0) | |
1178 { | |
1179 curfle->size = gftp_get_file_size (tdata->fromreq, curfle->file); | |
1180 tdata->total_bytes += curfle->size; | |
1181 } | |
1182 | |
1183 if (GFTP_IS_CONNECTED (tdata->fromreq) && | |
1184 GFTP_IS_CONNECTED (tdata->toreq)) | |
1185 { | |
1186 fromsize = gftp_transfer_file (tdata->fromreq, curfle->file, | |
1187 fromfd, | |
1188 curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? | |
1189 curfle->startsize : 0, | |
1190 tdata->toreq, curfle->destfile, tofd, | |
1191 curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? | |
1192 curfle->startsize : 0); | |
1193 } | |
1194 } | |
1195 | |
1196 if (!GFTP_IS_CONNECTED (tdata->fromreq) || | |
1197 !GFTP_IS_CONNECTED (tdata->toreq)) | |
1198 { | |
1199 tdata->fromreq->logging_function (gftp_logging_misc, | |
1200 tdata->fromreq, | |
1201 _("Error: Remote site disconnected after trying to tdata file\n")); | |
1202 } | |
1203 else if (fromsize < 0) | |
1204 { | |
1205 if (g_thread_supported ()) | |
1206 g_static_mutex_lock (&tdata->structmutex); | |
1207 | |
1208 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; | |
1209 tdata->next_file = 1; | |
1210 tdata->curfle = tdata->curfle->next; | |
1211 | |
1212 if (g_thread_supported ()) | |
1213 g_static_mutex_unlock (&tdata->structmutex); | |
1214 continue; | |
1215 } | |
1216 else | |
1217 { | |
1218 if (g_thread_supported ()) | |
1219 g_static_mutex_lock (&tdata->structmutex); | |
1220 | |
1221 tdata->curtrans = 0; | |
1222 tdata->curresumed = curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? curfle->startsize : 0; | |
1223 tdata->resumed_bytes += tdata->curresumed; | |
1224 | |
1225 if (g_thread_supported ()) | |
1226 g_static_mutex_unlock (&tdata->structmutex); | |
1227 | |
1228 total = 0; | |
1229 i = 0; | |
1230 while (!tdata->cancel && | |
1231 (num_read = gftp_get_next_file_chunk (tdata->fromreq, | |
1232 buf, sizeof (buf))) > 0) | |
1233 { | |
1234 total += num_read; | |
1235 gftp_calc_kbs (tdata, num_read); | |
1236 | |
1237 if ((ret = gftp_put_next_file_chunk (tdata->toreq, buf, | |
1238 num_read)) < 0) | |
1239 { | |
1240 num_read = (int) ret; | |
1241 break; | |
1242 } | |
1243 } | |
1244 } | |
1245 | |
1246 if (tdata->cancel) | |
1247 { | |
1248 if (gftp_abort_transfer (tdata->fromreq) != 0) | |
1249 gftp_disconnect (tdata->fromreq); | |
1250 | |
1251 if (gftp_abort_transfer (tdata->toreq) != 0) | |
1252 gftp_disconnect (tdata->toreq); | |
1253 } | |
1254 else if (num_read < 0) | |
1255 { | |
1256 tdata->fromreq->logging_function (gftp_logging_misc, | |
1257 tdata->fromreq, | |
1258 _("Could not download %s from %s\n"), | |
1259 curfle->file, | |
1260 tdata->fromreq->hostname); | |
1261 | |
1262 if (gftp_get_transfer_status (tdata, num_read) == GFTP_ERETRYABLE) | |
1263 continue; | |
1264 | |
1265 break; | |
1266 } | |
1267 else | |
1268 { | |
1269 _gftpui_common_done_with_fds (tdata, curfle); | |
1270 if (gftp_end_transfer (tdata->fromreq) != 0) | |
1271 { | |
1272 if (gftp_get_transfer_status (tdata, -1) == GFTP_ERETRYABLE) | |
1273 continue; | |
1274 | |
1275 break; | |
1276 } | |
1277 gftp_end_transfer (tdata->toreq); | |
1278 | |
1279 tdata->fromreq->logging_function (gftp_logging_misc, | |
1280 tdata->fromreq, | |
1281 _("Successfully tdatared %s at %.2f KB/s\n"), | |
1282 curfle->file, tdata->kbs); | |
1283 } | |
1284 | |
1285 if (!curfle->is_fd && preserve_permissions) | |
1286 { | |
1287 if (curfle->attribs) | |
1288 { | |
1289 mode = gftp_parse_attribs (curfle->attribs); | |
1290 if (mode != 0) | |
1291 gftp_chmod (tdata->toreq, curfle->destfile, mode); | |
1292 } | |
1293 | |
1294 if (curfle->datetime != 0) | |
1295 gftp_set_file_time (tdata->toreq, curfle->destfile, | |
1296 curfle->datetime); | |
1297 } | |
1298 | |
1299 if (g_thread_supported ()) | |
1300 g_static_mutex_lock (&tdata->structmutex); | |
1301 | |
1302 tdata->curtrans = 0; | |
1303 tdata->next_file = 1; | |
1304 curfle->transfer_done = 1; | |
1305 tdata->curfle = tdata->curfle->next; | |
1306 | |
1307 if (g_thread_supported ()) | |
1308 g_static_mutex_unlock (&tdata->structmutex); | |
1309 | |
1310 if (tdata->cancel && !tdata->skip_file) | |
1311 break; | |
1312 tdata->cancel = 0; | |
1313 tdata->fromreq->cancel = 0; | |
1314 tdata->toreq->cancel = 0; | |
1315 } | |
1316 tdata->done = 1; | |
1317 | |
1318 return (1); /* FIXME */ | |
1319 } | |
1320 |