⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gftpui.c

📁 Linux下使用最为广泛的gftp的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
}static intgftpui_common_cmd_close (void *uidata, gftp_request * request,                         void *other_uidata, gftp_request * other_request,                         const char *command){  gftp_disconnect (request);  return (1);}static intgftpui_common_cmd_pwd (void *uidata, gftp_request * request,                       void *other_uidata, gftp_request * other_request,                       const char *command){  if (!GFTP_IS_CONNECTED (request))    {      request->logging_function (gftp_logging_error, request,                                 _("Error: Not connected to a remote site\n"));      return (1);    }  request->logging_function (gftp_logging_misc, request,                             "%s\n", request->directory);  return (1);}static intgftpui_common_cmd_quit (void *uidata, gftp_request * request,                        void *other_uidata, gftp_request * other_request,                        const char *command){  gftp_shutdown();  return (0);}static intgftpui_common_cmd_clear (void *uidata, gftp_request * request,                         void *other_uidata, gftp_request * other_request,                         const char *command){  if (strcasecmp (command, "cache") == 0)    gftp_clear_cache_files ();  else    {      gftpui_common_logfunc (gftp_logging_error, request,                             _("Invalid argument\n"));    }  return (1);}static intgftpui_common_clear_show_subhelp (const char *topic){  if (strcmp (topic, "cache") == 0)    {      gftpui_common_logfunc (gftp_logging_misc, NULL,                             _("Clear the directory cache\n"));      return (1);    }  return (0);}static intgftpui_common_set_show_subhelp (const char *topic){   gftp_config_vars * cv;      if ((cv = g_hash_table_lookup (gftp_global_options_htable, topic)) != NULL)    {      gftpui_common_logfunc (gftp_logging_misc, NULL, "%s\n", cv->comment);      return (1);    }  return (0);}   static intgftpui_common_cmd_ls (void *uidata, gftp_request * request,                      void *other_uidata, gftp_request * other_request,                      const char *command){  char *startcolor, *endcolor, *tempstr;  gftpui_callback_data * cdata;  GList * templist;  gftp_file * fle;  if (!GFTP_IS_CONNECTED (request))    {      request->logging_function (gftp_logging_error, request,                     _("Error: Not connected to a remote site\n"));      return (1);    }  cdata = g_malloc0 (sizeof (*cdata));  cdata->request = request;  cdata->uidata = uidata;  cdata->source_string = *command != '\0' ? (char *) command : NULL;  cdata->run_function = gftpui_common_run_ls;  cdata->dont_refresh = 1;  gftpui_common_run_callback_function (cdata);  templist = cdata->files;  while (templist != NULL)    {      fle = templist->data;      gftpui_lookup_file_colors (fle, &startcolor, &endcolor);      tempstr = gftp_gen_ls_string (fle, startcolor, endcolor);      request->logging_function (gftp_logging_misc_nolog, request, "%s\n",                                 tempstr);      g_free (tempstr);      templist = templist->next;      gftp_file_destroy (fle, 1);    }  if (cdata->files != NULL)    g_list_free (cdata->files);  g_free (cdata);  return (1);}intgftpui_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;  gftpui_common_run_callback_function (cdata);  g_free (cdata);  return (1);}static intgftpui_common_cmd_set (void *uidata, gftp_request * request,                       void *other_uidata, gftp_request * other_request,                       const char *command){  char *pos, *backpos, buf[256];  gftp_config_vars * cv, newcv;  GList * templist;  int i;    if (command == NULL || *command == '\0')    {      for (templist = gftp_options_list;           templist != NULL;            templist = templist->next)        {          cv = templist->data;          for (i=0; cv[i].key != NULL; i++)            {               if (!(cv[i].ports_shown & GFTP_PORT_TEXT))                continue;              if (*cv[i].key == '\0' ||                  gftp_option_types[cv[i].otype].write_function == NULL)                continue;              gftp_option_types[cv[i].otype].write_function (&cv[i], buf,                                                             sizeof (buf), 0);              gftpui_common_logfunc (gftp_logging_misc_nolog, request,                                     "%s = %s\n", cv[i].key, buf);            }        }    }  else    {      if ((pos = strchr (command, '=')) == NULL)        {          gftpui_common_logfunc (gftp_logging_error, request,                                 _("usage: set [variable = value]\n"));          return (1);        }      *pos = '\0';      for (backpos = pos - 1;           (*backpos == ' ' || *backpos == '\t') && backpos > command;           backpos--)        *backpos = '\0';      for (++pos; *pos == ' ' || *pos == '\t'; pos++);      if ((cv = g_hash_table_lookup (gftp_global_options_htable, command)) == NULL)        {          gftpui_common_logfunc (gftp_logging_error, request,                                 _("Error: Variable %s is not a valid configuration variable.\n"), command);          return (1);        }      if (!(cv->ports_shown & GFTP_PORT_TEXT))        {          gftpui_common_logfunc (gftp_logging_error, request,                                 _("Error: Variable %s is not available in the text port of gFTP\n"), command);          return (1);        }      if (gftp_option_types[cv->otype].read_function != NULL)        {          memcpy (&newcv, cv, sizeof (newcv));          newcv.flags &= ~GFTP_CVARS_FLAGS_DYNMEM;          gftp_option_types[cv->otype].read_function (pos, &newcv, 1);          gftp_set_global_option (command, newcv.value);          gftp_option_types[newcv.otype].write_function (&newcv, buf,                                                         sizeof (buf), 0);          gftpui_common_logfunc (gftp_logging_misc_nolog, request,                                 "%s = %s\n", newcv.key, buf);          if (newcv.flags & GFTP_CVARS_FLAGS_DYNMEM)            g_free (newcv.value);          gftp_configuration_changed = 1;        }    }  return (1);}static intgftpui_common_cmd_help (void *uidata, gftp_request * request,                        void *other_uidata, gftp_request * other_request,                        const char *command){  int i, j, ele, numrows, numcols = 6, handled, number_commands, cmdlen,      found;  char commands[128], cmdstr[30];  const char *pos;  for (number_commands=0;       gftpui_common_commands[number_commands].command != NULL;       number_commands++);  if (command != NULL && *command != '\0')    {      for (pos = command; *pos != ' ' && *pos != '\0'; pos++);      cmdlen = pos - command;      for (i=0; gftpui_common_commands[i].command != NULL; i++)        {          if (strncmp (gftpui_common_commands[i].command, command, cmdlen) == 0)            break;        }      if (gftpui_common_commands[i].cmd_description != NULL)        {          found = 1;          if (*pos != '\0' && *(pos + 1) != '\0' &&              gftpui_common_commands[i].subhelp_func != NULL)            handled = gftpui_common_commands[i].subhelp_func (pos + 1);          else            handled = 0;          if (!handled)            gftpui_common_logfunc (gftp_logging_misc_nolog, request, "%s\n",                                 _(gftpui_common_commands[i].cmd_description));        }      else        found = 0;    }  else    found = 0;    if (!found)    {      numrows = number_commands / numcols;      if (number_commands % numcols != 0)        numrows++;      gftpui_common_logfunc (gftp_logging_misc_nolog, request,                             _("Supported commands:\n\n"));            for (i=0; i<numrows; i++)        {          strncpy (commands, "\t", sizeof (commands));          for (j=0; j<numcols; j++)            {              ele = i + j * numrows;              if (ele >= number_commands)                break;              g_snprintf (cmdstr, sizeof (cmdstr), "%-10s",                          gftpui_common_commands[ele].command);              strncat (commands, cmdstr, sizeof (commands));            }          gftpui_common_logfunc (gftp_logging_misc_nolog, request, "%s\n",                                 commands);        }    }  return (1);}static void_gftpui_common_transfer_files (void *fromuidata, gftp_request * fromrequest,                               void *touidata, gftp_request * torequest,                               const char *cmd, const char *filespec){  gftp_transfer * tdata;  gftp_file * fle;  if (!GFTP_IS_CONNECTED (fromrequest) ||      !GFTP_IS_CONNECTED (torequest))    {      fromrequest->logging_function (gftp_logging_error, fromrequest,                                  _("Error: Not connected to a remote site\n"));      return;    }  if (*filespec == '\0')    {      fromrequest->logging_function (gftp_logging_error, fromrequest,                                      _("usage: %s <filespec>\n"), cmd);      return;    }  tdata = gftp_tdata_new ();  tdata->fromreq = fromrequest;  tdata->toreq = torequest;  if (gftp_list_files (tdata->fromreq) != 0)    {      tdata->fromreq = tdata->toreq = NULL;      free_tdata (tdata);      return;    }  fle = g_malloc0 (sizeof (*fle));  while (gftp_get_next_file (tdata->fromreq, filespec, fle) > 0)    {      if (strcmp (fle->file, ".") == 0 || strcmp (fle->file, "..") == 0)        {          gftp_file_destroy (fle, 0);          continue;        }      tdata->files = g_list_append (tdata->files, fle);      fle = g_malloc (sizeof (*fle));    }  g_free (fle);  gftp_end_transfer (tdata->fromreq);  if (tdata->files == NULL)    {      tdata->fromreq = tdata->toreq = NULL;      free_tdata (tdata);      return;    }  if (gftp_get_all_subdirs (tdata, NULL) != 0)    {      tdata->fromreq = tdata->toreq = NULL;      free_tdata (tdata);      return;    }  if (tdata->files == NULL)    {      tdata->fromreq = tdata->toreq = NULL;      free_tdata (tdata);      return;    }  gftpui_common_add_file_transfer (tdata->fromreq, tdata->toreq,                                   fromuidata, touidata, tdata->files);  g_free (tdata);  return;}intgftpui_common_cmd_mget_file (void *uidata, gftp_request * request,                             void *other_uidata, gftp_request * other_request,                             const char *command){  _gftpui_common_transfer_files (uidata, request, other_uidata, other_request,                                 "mget", command);  return (1);}intgftpui_common_cmd_mput_file (void *uidata, gftp_request * request,                             void *other_uidata, gftp_request * other_request,                             const char *command){  _gftpui_common_transfer_files (other_uidata, other_request, uidata, request,                                 "mput", command);  return (1);}gftpui_common_methods gftpui_common_commands[] = {        {N_("about"),   2, gftpui_common_cmd_about, gftpui_common_request_none,         N_("Shows gFTP information"), NULL},        {N_("ascii"),   2, gftpui_common_cmd_ascii, gftpui_common_request_remote,         N_("Sets the current file transfer mode to Ascii (only for FTP)"), NULL},        {N_("binary"),  1, gftpui_common_cmd_binary, gftpui_common_request_remote,         N_("Sets the current file transfer mode to Binary (only for FTP)"), NULL},        {N_("cd"),      2, gftpui_common_cmd_chdir, gftpui_common_request_remote,         N_("Changes the remote working directory"), NULL},        {N_("chdir"),   3, gftpui_common_cmd_chdir, gftpui_common_request_remote,         N_("Changes the remote working directory"), NULL},        {N_("chmod"),   3, gftpui_common_cmd_chmod, gftpui_common_request_remote,         N_("Changes the permissions of a remote file"), NULL},        {N_("clear"),   3, gftpui_common_cmd_clear, gftpui_common_request_none,         N_("Available options: cache"), gftpui_common_clear_show_subhelp},        {N_("close"),   3, gftpui_common_cmd_close, gftpui_common_request_remote,         N_("Disconnects from the remote site"), NULL},        {N_("delete"),  1, gftpui_common_cmd_delete, gftpui_common_request_remote,         N_("Removes a remote file"), NULL},        {N_("get"),     1, gftpui_common_cmd_mget_file, gftpui_common_request_remote,         N_("Downloads remote file(s)"), NULL},        {N_("help"),    1, gftpui_common_cmd_help, gftpui_common_request_none,         N_("Shows this help screen"), NULL},        {N_("lcd"),     3, gftpui_common_cmd_chdir, gftpui_common_request_local,         N_("Changes the local working directory"), NULL},        {N_("lchdir"),  4, gftpui_common_cmd_chdir, gftpui_common_request_local,         N_("Changes the local working directory"), NULL},        {N_("lchmod"),  4, gftpui_common_cmd_chmod,     gftpui_common_request_local,         N_("Changes the permissions of a local file"), NULL},        {N_("ldelete"), 2, gftpui_common_cmd_delete,    gftpui_common_request_local,         N_("Removes a local file"), NULL},        {N_("lls"),     2, gftpui_common_cmd_ls, gftpui_common_request_local,         N_("Shows the directory listing for the current local directory"), NULL},        {N_("lmkdir"),  2, gftpui_common_cmd_mkdir, gftpui_common_request_local,         N_("Creates a local directory"), NULL},        {N_("lpwd"),    2, gftpui_common_cmd_pwd, gftpui_common_request_local,         N_("Show current local directory"), NULL},        {N_("lrename"), 3, gftpui_common_cmd_rename, gftpui_common_request_local,         N_("Rename a local file"), NULL},        {N_("lrmdir"),  3, gftpui_common_cmd_rmdir, gftpui_common_request_local,         N_("Remove a local directory"), NULL},        {N_("ls"),      2, gftpui_common_cmd_ls, gftpui_common_request_remote,         N_("Shows the directory listing for the current remote directory"), NULL},        {N_("mget"),    2, gftpui_common_cmd_mget_file, gftpui_common_request_remote,         N_("Downloads remote file(s)"), NULL},        {N_("mkdir"),   2, gftpui_common_cmd_mkdir, gftpui_common_request_remote,         N_("Creates a remote directory"), NULL},        {N_("mput"),    2, gftpui_common_cmd_mput_file, gftpui_common_request_remote,         N_("Uploads local file(s)"), NULL},        {N_("open"),    1, gftpui_common_cmd_open, gftpui_common_request_remote,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -