int ftp_list_files (gftp_window_data * wdata) { gftpui_callback_data * cdata; gtk_label_set (GTK_LABEL (wdata->hoststxt), _("Receiving file names...")); cdata = g_malloc0 (sizeof (*cdata)); cdata->request = wdata->request; cdata->uidata = wdata; cdata->run_function = gftpui_common_run_ls; cdata->dont_refresh = 1; gftpui_common_run_callback_function (cdata); wdata->files = cdata->files; g_free (cdata); if (wdata->files == NULL || !GFTP_IS_CONNECTED (wdata->request)) { gftpui_disconnect (wdata); return (0); } wdata->sorted = 0; sortrows (GTK_CLIST (wdata->listbox), -1, (gpointer) wdata); if (IS_NONE_SELECTED (wdata)) gtk_clist_select_row (GTK_CLIST (wdata->listbox), 0, 0); return (1); }
void delete_dialog (GtkAction * a, gpointer data) { gftp_file * tempfle, * newfle; GList * templist, * filelist; gftp_transfer * transfer; gftp_window_data * wdata; int ret; GtkTreeSelection *select; GtkTreeIter iter; GtkTreeModel * model; wdata = data; if (!check_status (_("Delete"), wdata, gftpui_common_use_threads (wdata->request), 0, 1, 1)) return; transfer = g_malloc0 (sizeof (*transfer)); transfer->fromreq = gftp_copy_request (wdata->request); transfer->fromwdata = wdata; select = gtk_tree_view_get_selection (GTK_TREE_VIEW (wdata->listbox)); templist = gtk_tree_selection_get_selected_rows(select, &model); for (filelist = templist ; filelist != NULL; filelist = g_list_next(filelist)) { gtk_tree_model_get_iter(model, &iter, (GtkTreePath*)filelist->data); gtk_tree_model_get(model, &iter, 0, &tempfle, -1); if (strcmp (tempfle->file, "..") == 0 || strcmp (tempfle->file, ".") == 0) continue; newfle = copy_fdata (tempfle); transfer->files = g_list_append (transfer->files, newfle); } g_list_foreach (templist, (GFunc) gtk_tree_path_free, NULL); g_list_free (templist); if (transfer->files == NULL) { free_tdata (transfer); return; } gftp_swap_socks (transfer->fromreq, wdata->request); ret = gftp_gtk_get_subdirs (transfer); gftp_swap_socks (wdata->request, transfer->fromreq); if (!GFTP_IS_CONNECTED (wdata->request)) { gftpui_disconnect (wdata); return; } if (!ret) return; askdel (transfer); }
int gftpui_common_cmd_open (void *uidata, gftp_request * request, void *other_uidata, gftp_request * other_request, const char *command) { gftpui_callback_data * cdata; intptr_t retries; if (GFTP_IS_CONNECTED (request)) gftpui_disconnect (uidata); if (command != NULL) { if (*command == '\0') { request->logging_function (gftp_logging_error, request, _("usage: open " GFTP_URL_USAGE "\n")); return (1); } if (gftp_parse_url (request, command) < 0) return (1); } if (gftp_need_username (request)) gftpui_prompt_username (uidata, request); if (gftp_need_password (request)) gftpui_prompt_password (uidata, request); gftp_lookup_request_option (request, "retries", &retries); cdata = g_malloc0 (sizeof (*cdata)); cdata->request = request; cdata->uidata = uidata; cdata->run_function = gftpui_common_run_connect; cdata->retries = retries; cdata->dont_check_connection = 1; if (request->refreshing) cdata->dont_refresh = 1; gftpui_show_busy (TRUE); gftpui_common_run_callback_function (cdata); gftpui_show_busy (FALSE); g_free (cdata); return (1); }
int gftpui_common_process_command (void *locui, gftp_request * locreq, void *remui, gftp_request * remreq, const char *command) { gftp_request * request, * other_request; void *uidata, *other_uidata; char *pos, *newstr; const char *stpos; size_t cmdlen; int ret, i; size_t len; for (stpos = command; *stpos == ' ' || *stpos == '\t'; stpos++); newstr = g_strdup (stpos); len = strlen (newstr); if (len > 0 && newstr[len - 1] == '\n') newstr[--len] = '\0'; if (len > 0 && newstr[len - 1] == '\r') newstr[--len] = '\0'; for (pos = newstr + len - 1; (*pos == ' ' || *pos == '\t') && pos > newstr; *pos-- = '\0'); if (*newstr == '\0') { g_free (newstr); return (1); } if ((pos = strchr (newstr, ' ')) != NULL) *pos = '\0'; cmdlen = strlen (newstr); for (i=0; gftpui_common_commands[i].command != NULL; i++) { if (strcmp (gftpui_common_commands[i].command, newstr) == 0) break; else if (cmdlen >= gftpui_common_commands[i].minlen && strncmp (gftpui_common_commands[i].command, newstr, cmdlen) == 0) break; } if (pos != NULL) pos++; else pos = ""; if (gftpui_common_commands[i].reqtype == gftpui_common_request_local) { request = locreq; uidata = locui; other_request = remreq; other_uidata = remui; } else if (gftpui_common_commands[i].reqtype == gftpui_common_request_remote) { request = remreq; uidata = remui; other_request = locreq; other_uidata = locui; } else { request = other_request = NULL; uidata = other_uidata = NULL; } if (gftpui_common_commands[i].command != NULL) { ret = gftpui_common_commands[i].func (uidata, request, other_uidata, other_request, pos); if (request != NULL && !GFTP_IS_CONNECTED (request)) gftpui_disconnect (uidata); } else { gftpui_common_logfunc (gftp_logging_error, request, _("Error: Command not recognized\n")); ret = 1; } g_free (newstr); return (ret); }
void transfer_window_files (gftp_window_data * fromwdata, gftp_window_data * towdata) { gftp_file * tempfle, * newfle; GList * templist, * filelist; gftp_transfer * transfer; int num, ret, disconnect; if (!check_status (_("Transfer Files"), fromwdata, 1, 0, 1, towdata->request->put_file != NULL && fromwdata->request->get_file != NULL)) return; if (!GFTP_IS_CONNECTED (fromwdata->request) || !GFTP_IS_CONNECTED (towdata->request)) { ftp_log (gftp_logging_error, NULL, _("Retrieve Files: Not connected to a remote site\n")); return; } if (check_reconnect (fromwdata) < 0 || check_reconnect (towdata) < 0) return; transfer = g_malloc0 (sizeof (*transfer)); transfer->fromreq = gftp_copy_request (fromwdata->request); transfer->toreq = gftp_copy_request (towdata->request); transfer->fromwdata = fromwdata; transfer->towdata = towdata; num = 0; templist = gftp_gtk_get_list_selection (fromwdata); filelist = fromwdata->files; while (templist != NULL) { templist = get_next_selection (templist, &filelist, &num); tempfle = filelist->data; if (strcmp (tempfle->file, "..") != 0) { newfle = copy_fdata (tempfle); transfer->files = g_list_append (transfer->files, newfle); } } if (transfer->files != NULL) { gftp_swap_socks (transfer->fromreq, fromwdata->request); gftp_swap_socks (transfer->toreq, towdata->request); ret = gftp_gtk_get_subdirs (transfer); if (ret < 0) disconnect = 1; else disconnect = 0; if (!GFTP_IS_CONNECTED (transfer->fromreq)) { gftpui_disconnect (fromwdata); disconnect = 1; } if (!GFTP_IS_CONNECTED (transfer->toreq)) { gftpui_disconnect (towdata); disconnect = 1; } if (disconnect) { free_tdata (transfer); return; } gftp_swap_socks (fromwdata->request, transfer->fromreq); gftp_swap_socks (towdata->request, transfer->toreq); } if (transfer->files != NULL) { gftpui_common_add_file_transfer (transfer->fromreq, transfer->toreq, transfer->fromwdata, transfer->towdata, transfer->files); g_free (transfer); } else free_tdata (transfer); }