1
1

Remove vfs_url_t structure (replace with vfs_path_element_t)

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Этот коммит содержится в:
Slava Zanko 2011-06-07 13:18:08 +03:00
родитель 3eafe7308a
Коммит 997876a109
10 изменённых файлов: 165 добавлений и 175 удалений

Просмотреть файл

@ -86,10 +86,10 @@ teardown (void)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
#define ETALON_PATH_STR "/local/path/#test1:user:pass@some.host:12345/bla-bla/some/path/#test2:/#enc:KOI8-R/bla-bla/some/path#test3:/111/22/33" #define ETALON_PATH_STR "/local/path/#test1:user:pass@some.host:12345/bla-bla/some/path/#test2:/#enc:KOI8-R/bla-bla/some/path#test3:/111/22/33"
#define ETALON_SERIALIZED_PATH "g14:path-element-0p4:pathv12:/local/path/p10:class-namev7:localfs" \ #define ETALON_SERIALIZED_PATH "g14:path-element-0p4:pathv12:/local/path/p10:class-namev7:localfsp4:portv1:0" \
"g14:path-element-1p4:pathv18:bla-bla/some/path/p10:class-namev7:testfs1p11:raw_url_strv31:test1:user:pass@some.host:12345" \ "g14:path-element-1p4:pathv18:bla-bla/some/path/p10:class-namev7:testfs1p11:raw_url_strv31:test1:user:pass@some.host:12345p4:portv1:0" \
"g14:path-element-2p4:pathv17:bla-bla/some/pathp10:class-namev7:testfs2p8:encodingv6:KOI8-Rp11:raw_url_strv6:test2:" \ "g14:path-element-2p4:pathv17:bla-bla/some/pathp10:class-namev7:testfs2p8:encodingv6:KOI8-Rp11:raw_url_strv6:test2:p4:portv1:0" \
"g14:path-element-3p4:pathv9:111/22/33p10:class-namev7:testfs3p11:raw_url_strv6:test3:" "g14:path-element-3p4:pathv9:111/22/33p10:class-namev7:testfs3p11:raw_url_strv6:test3:p4:portv1:0"
START_TEST (test_path_serialize_deserialize) START_TEST (test_path_serialize_deserialize)
{ {

Просмотреть файл

@ -385,7 +385,7 @@ vfs_s_free_super (struct vfs_class *me, struct vfs_s_super *super)
CALL (free_archive) (me, super); CALL (free_archive) (me, super);
#ifdef ENABLE_VFS_NET #ifdef ENABLE_VFS_NET
vfs_url_free (super->url); vfs_path_element_free (super->path_element);
#endif #endif
g_free (super->name); g_free (super->name);
g_free (super); g_free (super);

Просмотреть файл

@ -418,7 +418,9 @@ vfs_path_element_free (vfs_path_element_t * element)
if (element == NULL) if (element == NULL)
return; return;
vfs_url_free (element->url); g_free (element->user);
g_free (element->password);
g_free (element->host);
g_free (element->path); g_free (element->path);
g_free (element->encoding); g_free (element->encoding);
@ -526,15 +528,10 @@ vfs_path_serialize (const vfs_path_t * vpath, GError ** error)
mc_config_set_string_raw (cpath, groupname, "raw_url_str", element->raw_url_str); mc_config_set_string_raw (cpath, groupname, "raw_url_str", element->raw_url_str);
if (element->url != NULL) mc_config_set_string_raw (cpath, groupname, "user", element->user);
{ mc_config_set_string_raw (cpath, groupname, "password", element->password);
mc_config_set_bool (cpath, groupname, "has-url", TRUE); mc_config_set_string_raw (cpath, groupname, "host", element->host);
mc_config_set_string_raw (cpath, groupname, "url-user", element->url->user); mc_config_set_int (cpath, groupname, "port", element->port);
mc_config_set_string_raw (cpath, groupname, "url-password", element->url->password);
mc_config_set_string_raw (cpath, groupname, "url-host", element->url->host);
mc_config_set_int (cpath, groupname, "url-port", element->url->port);
mc_config_set_string_raw (cpath, groupname, "url-path", element->url->path);
}
g_free (groupname); g_free (groupname);
} }
@ -600,16 +597,11 @@ vfs_path_deserialize (const char *data, GError ** error)
element->raw_url_str = mc_config_get_string_raw (cpath, groupname, "raw_url_str", NULL); element->raw_url_str = mc_config_get_string_raw (cpath, groupname, "raw_url_str", NULL);
if (mc_config_get_bool (cpath, groupname, "has-url", FALSE)) element->user = mc_config_get_string_raw (cpath, groupname, "user", NULL);
{ element->password = mc_config_get_string_raw (cpath, groupname, "password", NULL);
element->url = g_new0 (vfs_url_t, 1); element->host = mc_config_get_string_raw (cpath, groupname, "host", NULL);
element->url->user = mc_config_get_string_raw (cpath, groupname, "url-user", NULL); element->port = mc_config_get_int (cpath, groupname, "port", 0);
element->url->password =
mc_config_get_string_raw (cpath, groupname, "url-password", NULL);
element->url->host = mc_config_get_string_raw (cpath, groupname, "url-host", NULL);
element->url->port = mc_config_get_int (cpath, groupname, "url-port", 0);
element->url->path = mc_config_get_string_raw (cpath, groupname, "url-path", NULL);
}
vpath->path = g_list_append (vpath->path, element); vpath->path = g_list_append (vpath->path, element);
g_free (groupname); g_free (groupname);

Просмотреть файл

@ -17,6 +17,10 @@ typedef struct
typedef struct typedef struct
{ {
char *user;
char *password;
char *host;
int port;
char *path; char *path;
struct vfs_class *class; struct vfs_class *class;
char *encoding; char *encoding;
@ -28,7 +32,6 @@ typedef struct
} dir; } dir;
char *raw_url_str; char *raw_url_str;
struct vfs_url_struct *url;
struct vfs_s_super *current_super_block; struct vfs_s_super *current_super_block;
} vfs_path_element_t; } vfs_path_element_t;

Просмотреть файл

@ -383,17 +383,17 @@ vfs_mkstemps (char **pname, const char *prefix, const char *param_basename)
* host. * host.
*/ */
vfs_url_t * vfs_path_element_t *
vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags) vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags)
{ {
vfs_url_t *url; vfs_path_element_t *path_element;
char *pcopy; char *pcopy;
const char *pend; const char *pend;
char *dir, *colon, *inner_colon, *at, *rest; char *dir, *colon, *inner_colon, *at, *rest;
url = g_new0 (vfs_url_t, 1); path_element = g_new0 (vfs_path_element_t, 1);
url->port = default_port; path_element->port = default_port;
pcopy = g_strdup (path); pcopy = g_strdup (path);
pend = pcopy + strlen (pcopy); pend = pcopy + strlen (pcopy);
@ -405,10 +405,10 @@ vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags)
while (*dir != PATH_SEP && *dir != '\0') while (*dir != PATH_SEP && *dir != '\0')
dir++; dir++;
if (*dir == '\0') if (*dir == '\0')
url->path = g_strdup (PATH_SEP_STR); path_element->path = g_strdup (PATH_SEP_STR);
else else
{ {
url->path = g_strdup (dir); path_element->path = g_strdup (dir);
*dir = '\0'; *dir = '\0';
} }
} }
@ -427,11 +427,11 @@ vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags)
{ {
*inner_colon = '\0'; *inner_colon = '\0';
inner_colon++; inner_colon++;
url->password = g_strdup (inner_colon); path_element->password = g_strdup (inner_colon);
} }
if (*pcopy != '\0') if (*pcopy != '\0')
url->user = g_strdup (pcopy); path_element->user = g_strdup (pcopy);
if (pend == at + 1) if (pend == at + 1)
rest = at; rest = at;
@ -440,7 +440,7 @@ vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags)
} }
if ((flags & URL_USE_ANONYMOUS) == 0) if ((flags & URL_USE_ANONYMOUS) == 0)
url->user = vfs_get_local_username (); path_element->user = vfs_get_local_username ();
/* Check if the host comes with a port spec, if so, chop it */ /* Check if the host comes with a port spec, if so, chop it */
if (*rest != '[') if (*rest != '[')
@ -456,7 +456,7 @@ vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags)
} }
else else
{ {
vfs_url_free (url); vfs_path_element_free (path_element);
return NULL; return NULL;
} }
} }
@ -464,10 +464,10 @@ vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags)
if (colon != NULL) if (colon != NULL)
{ {
*colon = '\0'; *colon = '\0';
if (sscanf (colon + 1, "%d", &url->port) == 1) if (sscanf (colon + 1, "%d", &path_element->port) == 1)
{ {
if (url->port <= 0 || url->port >= 65536) if (path_element->port <= 0 || path_element->port >= 65536)
url->port = default_port; path_element->port = default_port;
} }
else else
while (*(++colon) != '\0') while (*(++colon) != '\0')
@ -475,33 +475,18 @@ vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags)
switch (*colon) switch (*colon)
{ {
case 'C': case 'C':
url->port = 1; path_element->port = 1;
break; break;
case 'r': case 'r':
url->port = 2; path_element->port = 2;
break; break;
} }
} }
} }
url->host = g_strdup (rest); path_element->host = g_strdup (rest);
return url; return path_element;
}
/* --------------------------------------------------------------------------------------------- */
void
vfs_url_free (vfs_url_t * url)
{
if (url != NULL)
{
g_free (url->user);
g_free (url->password);
g_free (url->host);
g_free (url->path);
g_free (url);
}
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */

Просмотреть файл

@ -12,6 +12,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include "lib/global.h" #include "lib/global.h"
#include "path.h"
/*** typedefs(not structures) and defined constants **********************************************/ /*** typedefs(not structures) and defined constants **********************************************/
@ -31,15 +32,6 @@ typedef enum
/*** structures declarations (and typedefs of structures)*****************************************/ /*** structures declarations (and typedefs of structures)*****************************************/
typedef struct vfs_url_struct
{
char *user;
char *password;
char *host;
int port;
char *path;
} vfs_url_t;
/*** global variables defined in .c file *********************************************************/ /*** global variables defined in .c file *********************************************************/
/*** declarations of public functions ************************************************************/ /*** declarations of public functions ************************************************************/
@ -47,8 +39,7 @@ typedef struct vfs_url_struct
int vfs_finduid (const char *name); int vfs_finduid (const char *name);
int vfs_findgid (const char *name); int vfs_findgid (const char *name);
vfs_url_t *vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags); vfs_path_element_t *vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags);
void vfs_url_free (vfs_url_t * url);
int vfs_split_text (char *p); int vfs_split_text (char *p);
int vfs_mkstemps (char **pname, const char *prefix, const char *basename); int vfs_mkstemps (char **pname, const char *prefix, const char *basename);

Просмотреть файл

@ -64,7 +64,7 @@ struct vfs_s_super
int ino_usage; /* Usage count of this superblock */ int ino_usage; /* Usage count of this superblock */
int want_stale; /* If set, we do not flush cache properly */ int want_stale; /* If set, we do not flush cache properly */
#ifdef ENABLE_VFS_NET #ifdef ENABLE_VFS_NET
vfs_url_t *url; vfs_path_element_t *path_element;
#endif /* ENABLE_VFS_NET */ #endif /* ENABLE_VFS_NET */
void *data; /* This is for filesystem-specific use */ void *data; /* This is for filesystem-specific use */

Просмотреть файл

@ -430,17 +430,17 @@ fish_open_archive_pipeopen (struct vfs_s_super *super)
{ {
char gbuf[10]; char gbuf[10];
const char *argv[10]; /* All of 10 is used now */ const char *argv[10]; /* All of 10 is used now */
const char *xsh = (super->url->port == FISH_FLAG_RSH ? "rsh" : "ssh"); const char *xsh = (super->path_element->port == FISH_FLAG_RSH ? "rsh" : "ssh");
int i = 0; int i = 0;
argv[i++] = xsh; argv[i++] = xsh;
if (super->url->port == FISH_FLAG_COMPRESSED) if (super->path_element->port == FISH_FLAG_COMPRESSED)
argv[i++] = "-C"; argv[i++] = "-C";
if (super->url->port > FISH_FLAG_RSH) if (super->path_element->port > FISH_FLAG_RSH)
{ {
argv[i++] = "-p"; argv[i++] = "-p";
g_snprintf (gbuf, sizeof (gbuf), "%d", super->url->port); g_snprintf (gbuf, sizeof (gbuf), "%d", super->path_element->port);
argv[i++] = gbuf; argv[i++] = gbuf;
} }
@ -451,18 +451,18 @@ fish_open_archive_pipeopen (struct vfs_s_super *super)
* option breaks it for some) * option breaks it for some)
*/ */
if (super->url->user != NULL) if (super->path_element->user != NULL)
{ {
argv[i++] = "-l"; argv[i++] = "-l";
argv[i++] = super->url->user; argv[i++] = super->path_element->user;
} }
else else
{ {
/* The rest of the code assumes it to be a valid username */ /* The rest of the code assumes it to be a valid username */
super->url->user = vfs_get_local_username (); super->path_element->user = vfs_get_local_username ();
} }
argv[i++] = super->url->host; argv[i++] = super->path_element->host;
argv[i++] = "echo FISH:; /bin/sh"; argv[i++] = "echo FISH:; /bin/sh";
argv[i++] = NULL; argv[i++] = NULL;
@ -490,15 +490,15 @@ fish_open_archive_talk (struct vfs_class *me, struct vfs_s_super *super)
return FALSE; return FALSE;
#if 0 #if 0
if (super->url->password == NULL) if (super->path_element->password == NULL)
{ {
char *p, *op; char *p, *op;
p = g_strdup_printf (_("fish: Password is required for %s"), super->url->user); p = g_strdup_printf (_("fish: Password is required for %s"), super->path_element->user);
op = vfs_get_password (p); op = vfs_get_password (p);
g_free (p); g_free (p);
if (op == NULL) if (op == NULL)
return FALSE; return FALSE;
super->url->password = op; super->path_element->password = op;
} }
@ -507,8 +507,8 @@ fish_open_archive_talk (struct vfs_class *me, struct vfs_s_super *super)
{ {
size_t str_len; size_t str_len;
str_len = strlen (super->url->password); str_len = strlen (super->path_element->password);
if ((write (SUP.sockw, super->url->password, str_len) != (ssize_t) str_len) if ((write (SUP.sockw, super->path_element->password, str_len) != (ssize_t) str_len)
|| (write (SUP->sockw, "\n", 1) != 1)) || (write (SUP->sockw, "\n", 1) != 1))
return FALSE; return FALSE;
} }
@ -564,11 +564,12 @@ fish_open_archive_int (struct vfs_class *me, struct vfs_s_super *super)
SUP->scr_env = fish_set_env (SUP->host_flags); SUP->scr_env = fish_set_env (SUP->host_flags);
vfs_print_message (_("fish: Setting up current directory...")); vfs_print_message (_("fish: Setting up current directory..."));
super->url->path = fish_getcwd (me, super); super->path_element->path = fish_getcwd (me, super);
vfs_print_message (_("fish: Connected, home %s."), super->url->path); vfs_print_message (_("fish: Connected, home %s."), super->path_element->path);
#if 0 #if 0
super->name = super->name =
g_strconcat ("/#sh:", super->url->user, "@", super->url->host, "/", (char *) NULL); g_strconcat ("/#sh:", super->path_element->user, "@", super->path_element->host, "/",
(char *) NULL);
#else #else
super->name = g_strdup (PATH_SEP_STR); super->name = g_strdup (PATH_SEP_STR);
#endif #endif
@ -586,37 +587,49 @@ fish_open_archive (struct vfs_class *me, struct vfs_s_super *super,
(void) archive_name; (void) archive_name;
super->data = g_new0 (fish_super_data_t, 1); super->data = g_new0 (fish_super_data_t, 1);
super->url = vfs_url_split (strchr (op, ':') + 1, 0, URL_NOSLASH | URL_USE_ANONYMOUS); super->path_element = vfs_url_split (strchr (op, ':') + 1, 0, URL_NOSLASH | URL_USE_ANONYMOUS);
if (strncmp (op, "rsh:", 4) == 0) if (strncmp (op, "rsh:", 4) == 0)
super->url->port = FISH_FLAG_RSH; super->path_element->port = FISH_FLAG_RSH;
SUP->scr_ls = fish_load_script_from_file (super->url->host, FISH_LS_FILE, FISH_LS_DEF_CONTENT); SUP->scr_ls =
fish_load_script_from_file (super->path_element->host, FISH_LS_FILE, FISH_LS_DEF_CONTENT);
SUP->scr_exists = SUP->scr_exists =
fish_load_script_from_file (super->url->host, FISH_EXISTS_FILE, FISH_EXISTS_DEF_CONTENT); fish_load_script_from_file (super->path_element->host, FISH_EXISTS_FILE,
FISH_EXISTS_DEF_CONTENT);
SUP->scr_mkdir = SUP->scr_mkdir =
fish_load_script_from_file (super->url->host, FISH_MKDIR_FILE, FISH_MKDIR_DEF_CONTENT); fish_load_script_from_file (super->path_element->host, FISH_MKDIR_FILE,
FISH_MKDIR_DEF_CONTENT);
SUP->scr_unlink = SUP->scr_unlink =
fish_load_script_from_file (super->url->host, FISH_UNLINK_FILE, FISH_UNLINK_DEF_CONTENT); fish_load_script_from_file (super->path_element->host, FISH_UNLINK_FILE,
FISH_UNLINK_DEF_CONTENT);
SUP->scr_chown = SUP->scr_chown =
fish_load_script_from_file (super->url->host, FISH_CHOWN_FILE, FISH_CHOWN_DEF_CONTENT); fish_load_script_from_file (super->path_element->host, FISH_CHOWN_FILE,
FISH_CHOWN_DEF_CONTENT);
SUP->scr_chmod = SUP->scr_chmod =
fish_load_script_from_file (super->url->host, FISH_CHMOD_FILE, FISH_CHMOD_DEF_CONTENT); fish_load_script_from_file (super->path_element->host, FISH_CHMOD_FILE,
FISH_CHMOD_DEF_CONTENT);
SUP->scr_rmdir = SUP->scr_rmdir =
fish_load_script_from_file (super->url->host, FISH_RMDIR_FILE, FISH_RMDIR_DEF_CONTENT); fish_load_script_from_file (super->path_element->host, FISH_RMDIR_FILE,
SUP->scr_ln = fish_load_script_from_file (super->url->host, FISH_LN_FILE, FISH_LN_DEF_CONTENT); FISH_RMDIR_DEF_CONTENT);
SUP->scr_mv = fish_load_script_from_file (super->url->host, FISH_MV_FILE, FISH_MV_DEF_CONTENT); SUP->scr_ln =
fish_load_script_from_file (super->path_element->host, FISH_LN_FILE, FISH_LN_DEF_CONTENT);
SUP->scr_mv =
fish_load_script_from_file (super->path_element->host, FISH_MV_FILE, FISH_MV_DEF_CONTENT);
SUP->scr_hardlink = SUP->scr_hardlink =
fish_load_script_from_file (super->url->host, FISH_HARDLINK_FILE, fish_load_script_from_file (super->path_element->host, FISH_HARDLINK_FILE,
FISH_HARDLINK_DEF_CONTENT); FISH_HARDLINK_DEF_CONTENT);
SUP->scr_get = SUP->scr_get =
fish_load_script_from_file (super->url->host, FISH_GET_FILE, FISH_GET_DEF_CONTENT); fish_load_script_from_file (super->path_element->host, FISH_GET_FILE, FISH_GET_DEF_CONTENT);
SUP->scr_send = SUP->scr_send =
fish_load_script_from_file (super->url->host, FISH_SEND_FILE, FISH_SEND_DEF_CONTENT); fish_load_script_from_file (super->path_element->host, FISH_SEND_FILE,
FISH_SEND_DEF_CONTENT);
SUP->scr_append = SUP->scr_append =
fish_load_script_from_file (super->url->host, FISH_APPEND_FILE, FISH_APPEND_DEF_CONTENT); fish_load_script_from_file (super->path_element->host, FISH_APPEND_FILE,
FISH_APPEND_DEF_CONTENT);
SUP->scr_info = SUP->scr_info =
fish_load_script_from_file (super->url->host, FISH_INFO_FILE, FISH_INFO_DEF_CONTENT); fish_load_script_from_file (super->path_element->host, FISH_INFO_FILE,
FISH_INFO_DEF_CONTENT);
return fish_open_archive_int (me, super); return fish_open_archive_int (me, super);
} }
@ -627,23 +640,23 @@ static int
fish_archive_same (struct vfs_class *me, struct vfs_s_super *super, fish_archive_same (struct vfs_class *me, struct vfs_s_super *super,
const char *archive_name, char *op, void *cookie) const char *archive_name, char *op, void *cookie)
{ {
vfs_url_t *url; vfs_path_element_t *path_element;
int result; int result;
(void) me; (void) me;
(void) archive_name; (void) archive_name;
(void) cookie; (void) cookie;
url = vfs_url_split (strchr (op, ':') + 1, 0, URL_NOSLASH | URL_USE_ANONYMOUS); path_element = vfs_url_split (strchr (op, ':') + 1, 0, URL_NOSLASH | URL_USE_ANONYMOUS);
if (url->user == NULL) if (path_element->user == NULL)
url->user = vfs_get_local_username (); path_element->user = vfs_get_local_username ();
result = ((strcmp (url->host, super->url->host) == 0) result = ((strcmp (path_element->host, super->path_element->host) == 0)
&& (strcmp (url->user, super->url->user) == 0) && (strcmp (path_element->user, super->path_element->user) == 0)
&& (url->port == super->url->port)) ? 1 : 0; && (path_element->port == super->path_element->port)) ? 1 : 0;
vfs_url_free (url); vfs_path_element_free (path_element);
return result; return result;
} }
@ -836,8 +849,8 @@ fish_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
reply_code = fish_decode_reply (buffer + 4, 0); reply_code = fish_decode_reply (buffer + 4, 0);
if (reply_code == COMPLETE) if (reply_code == COMPLETE)
{ {
g_free (super->url->path); g_free (super->path_element->path);
super->url->path = g_strdup (remote_path); super->path_element->path = g_strdup (remote_path);
vfs_print_message (_("%s: done."), me->name); vfs_print_message (_("%s: done."), me->name);
return 0; return 0;
} }
@ -1506,7 +1519,7 @@ fish_fill_names (struct vfs_class *me, fill_names_f func)
char gbuf[10]; char gbuf[10];
const char *flags = ""; const char *flags = "";
switch (super->url->port) switch (super->path_element->port)
{ {
case FISH_FLAG_RSH: case FISH_FLAG_RSH:
flags = ":r"; flags = ":r";
@ -1515,16 +1528,17 @@ fish_fill_names (struct vfs_class *me, fill_names_f func)
flags = ":C"; flags = ":C";
break; break;
default: default:
if (super->url->port > FISH_FLAG_RSH) if (super->path_element->port > FISH_FLAG_RSH)
{ {
g_snprintf (gbuf, sizeof (gbuf), ":%d", super->url->port); g_snprintf (gbuf, sizeof (gbuf), ":%d", super->path_element->port);
flags = gbuf; flags = gbuf;
} }
break; break;
} }
name = g_strconcat ("/#sh:", super->url->user, "@", super->url->host, flags, "/", name =
super->url->path, (char *) NULL); g_strconcat ("/#sh:", super->path_element->user, "@", super->path_element->host, flags,
"/", super->path_element->path, (char *) NULL);
func (name); func (name);
g_free (name); g_free (name);
} }

Просмотреть файл

@ -321,40 +321,40 @@ ftpfs_translate_path (struct vfs_class *me, struct vfs_s_super *super, const cha
* is supplied. * is supplied.
*/ */
static vfs_url_t * static vfs_path_element_t *
ftpfs_split_url (const char *path) ftpfs_split_url (const char *path)
{ {
vfs_url_t *p; vfs_path_element_t *path_element;
p = vfs_url_split (path, FTP_COMMAND_PORT, URL_USE_ANONYMOUS); path_element = vfs_url_split (path, FTP_COMMAND_PORT, URL_USE_ANONYMOUS);
if (p->user != NULL) if (path_element->user != NULL)
{ {
/* Look up user and password in netrc */ /* Look up user and password in netrc */
if (ftpfs_use_netrc) if (ftpfs_use_netrc)
ftpfs_netrc_lookup (p->host, &p->user, &p->password); ftpfs_netrc_lookup (path_element->host, &path_element->user, &path_element->password);
} }
if (p->user == NULL) if (path_element->user == NULL)
p->user = g_strdup ("anonymous"); path_element->user = g_strdup ("anonymous");
/* Look up password in netrc for known user */ /* Look up password in netrc for known user */
if (ftpfs_use_netrc && p->user != NULL && p->password != NULL) if (ftpfs_use_netrc && path_element->user != NULL && path_element->password != NULL)
{ {
char *new_user = NULL; char *new_user = NULL;
ftpfs_netrc_lookup (p->host, &new_user, &p->password); ftpfs_netrc_lookup (path_element->host, &new_user, &path_element->password);
/* If user is different, remove password */ /* If user is different, remove password */
if (new_user != NULL && strcmp (p->user, new_user) != 0) if (new_user != NULL && strcmp (path_element->user, new_user) != 0)
{ {
g_free (p->password); g_free (path_element->password);
p->password = NULL; path_element->password = NULL;
} }
g_free (new_user); g_free (new_user);
} }
return p; return path_element;
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -415,14 +415,14 @@ ftpfs_reconnect (struct vfs_class *me, struct vfs_s_super *super)
sock = ftpfs_open_socket (me, super); sock = ftpfs_open_socket (me, super);
if (sock != -1) if (sock != -1)
{ {
char *cwdir = super->url->path; char *cwdir = super->path_element->path;
close (SUP->sock); close (SUP->sock);
SUP->sock = sock; SUP->sock = sock;
super->url->path = NULL; super->path_element->path = NULL;
if (ftpfs_login_server (me, super, super->url->password) != 0) if (ftpfs_login_server (me, super, super->path_element->password) != 0)
{ {
if (cwdir == NULL) if (cwdir == NULL)
return 1; return 1;
@ -431,7 +431,7 @@ ftpfs_reconnect (struct vfs_class *me, struct vfs_s_super *super)
return sock == COMPLETE ? 1 : 0; return sock == COMPLETE ? 1 : 0;
} }
super->url->path = cwdir; super->path_element->path = cwdir;
} }
return 0; return 0;
@ -535,7 +535,7 @@ ftpfs_free_archive (struct vfs_class *me, struct vfs_s_super *super)
{ {
if (SUP->sock != -1) if (SUP->sock != -1)
{ {
vfs_print_message (_("ftpfs: Disconnecting from %s"), super->url->host); vfs_print_message (_("ftpfs: Disconnecting from %s"), super->path_element->host);
ftpfs_command (me, super, NONE, "QUIT"); ftpfs_command (me, super, NONE, "QUIT");
close (SUP->sock); close (SUP->sock);
} }
@ -571,11 +571,12 @@ ftpfs_login_server (struct vfs_class *me, struct vfs_s_super *super, const char
SUP->isbinary = TYPE_UNKNOWN; SUP->isbinary = TYPE_UNKNOWN;
if (super->url->password != NULL) /* explicit password */ if (super->path_element->password != NULL) /* explicit password */
op = g_strdup (super->url->password); op = g_strdup (super->path_element->password);
else if (netrcpass != NULL) /* password from netrc */ else if (netrcpass != NULL) /* password from netrc */
op = g_strdup (netrcpass); op = g_strdup (netrcpass);
else if (strcmp (super->url->user, "anonymous") == 0 || strcmp (super->url->user, "ftp") == 0) else if (strcmp (super->path_element->user, "anonymous") == 0
|| strcmp (super->path_element->user, "ftp") == 0)
{ {
if (ftpfs_anonymous_passwd == NULL) /* default anonymous password */ if (ftpfs_anonymous_passwd == NULL) /* default anonymous password */
ftpfs_init_passwd (); ftpfs_init_passwd ();
@ -586,12 +587,12 @@ ftpfs_login_server (struct vfs_class *me, struct vfs_s_super *super, const char
{ /* ask user */ { /* ask user */
char *p; char *p;
p = g_strdup_printf (_("FTP: Password required for %s"), super->url->user); p = g_strdup_printf (_("FTP: Password required for %s"), super->path_element->user);
op = vfs_get_password (p); op = vfs_get_password (p);
g_free (p); g_free (p);
if (op == NULL) if (op == NULL)
ERRNOR (EPERM, 0); ERRNOR (EPERM, 0);
super->url->password = g_strdup (op); super->path_element->password = g_strdup (op);
} }
if (!anon || MEDATA->logfile) if (!anon || MEDATA->logfile)
@ -605,11 +606,12 @@ ftpfs_login_server (struct vfs_class *me, struct vfs_s_super *super, const char
/* Proxy server accepts: username@host-we-want-to-connect */ /* Proxy server accepts: username@host-we-want-to-connect */
if (SUP->proxy) if (SUP->proxy)
name = name =
g_strconcat (super->url->user, "@", g_strconcat (super->path_element->user, "@",
super->url->host[0] == '!' ? super->url->host + 1 : super->url->host, super->path_element->host[0] ==
'!' ? super->path_element->host + 1 : super->path_element->host,
(char *) NULL); (char *) NULL);
else else
name = g_strdup (super->url->user); name = g_strdup (super->path_element->user);
if (ftpfs_get_reply (me, SUP->sock, reply_string, sizeof (reply_string) - 1) == COMPLETE) if (ftpfs_get_reply (me, SUP->sock, reply_string, sizeof (reply_string) - 1) == COMPLETE)
{ {
@ -636,7 +638,8 @@ ftpfs_login_server (struct vfs_class *me, struct vfs_s_super *super, const char
{ {
char *p; char *p;
p = g_strdup_printf (_("FTP: Account required for user %s"), super->url->user); p = g_strdup_printf (_("FTP: Account required for user %s"),
super->path_element->user);
op = input_dialog (p, _("Account:"), MC_HISTORY_FTPFS_ACCOUNT, ""); op = input_dialog (p, _("Account:"), MC_HISTORY_FTPFS_ACCOUNT, "");
g_free (p); g_free (p);
if (op == NULL) if (op == NULL)
@ -657,14 +660,15 @@ ftpfs_login_server (struct vfs_class *me, struct vfs_s_super *super, const char
default: default:
SUP->failed_on_login = 1; SUP->failed_on_login = 1;
wipe_password (super->url->password); wipe_password (super->path_element->password);
super->url->password = NULL; super->path_element->password = NULL;
goto login_fail; goto login_fail;
} }
} }
message (D_ERROR, MSG_ERROR, _("ftpfs: Login incorrect for user %s "), super->url->user); message (D_ERROR, MSG_ERROR, _("ftpfs: Login incorrect for user %s "),
super->path_element->user);
login_fail: login_fail:
wipe_password (pass); wipe_password (pass);
@ -763,12 +767,12 @@ ftpfs_check_proxy (const char *host)
static void static void
ftpfs_get_proxy_host_and_port (const char *proxy, char **host, int *port) ftpfs_get_proxy_host_and_port (const char *proxy, char **host, int *port)
{ {
vfs_url_t *url; vfs_path_element_t *path_element;
url = vfs_url_split (proxy, FTP_COMMAND_PORT, URL_USE_ANONYMOUS); path_element = vfs_url_split (proxy, FTP_COMMAND_PORT, URL_USE_ANONYMOUS);
*host = g_strdup (url->host); *host = g_strdup (path_element->host);
*port = url->port; *port = path_element->port;
vfs_url_free (url); vfs_path_element_free (path_element);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -786,7 +790,7 @@ ftpfs_open_socket (struct vfs_class *me, struct vfs_s_super *super)
(void) me; (void) me;
/* Use a proxy host? */ /* Use a proxy host? */
host = g_strdup (super->url->host); host = g_strdup (super->path_element->host);
if (host == NULL || *host == '\0') if (host == NULL || *host == '\0')
{ {
@ -797,7 +801,7 @@ ftpfs_open_socket (struct vfs_class *me, struct vfs_s_super *super)
} }
/* Hosts to connect to that start with a ! should use proxy */ /* Hosts to connect to that start with a ! should use proxy */
tmp_port = super->url->port; tmp_port = super->path_element->port;
if (SUP->proxy != NULL) if (SUP->proxy != NULL)
ftpfs_get_proxy_host_and_port (ftpfs_proxy_host, &host, &tmp_port); ftpfs_get_proxy_host_and_port (ftpfs_proxy_host, &host, &tmp_port);
@ -945,9 +949,9 @@ ftpfs_open_archive_int (struct vfs_class *me, struct vfs_s_super *super)
} }
while (retry_seconds != 0); while (retry_seconds != 0);
super->url->path = ftpfs_get_current_directory (me, super); super->path_element->path = ftpfs_get_current_directory (me, super);
if (super->url->path == NULL) if (super->path_element->path == NULL)
super->url->path = g_strdup (PATH_SEP_STR); super->path_element->path = g_strdup (PATH_SEP_STR);
return 0; return 0;
} }
@ -962,9 +966,9 @@ ftpfs_open_archive (struct vfs_class *me, struct vfs_s_super *super,
super->data = g_new0 (ftp_super_data_t, 1); super->data = g_new0 (ftp_super_data_t, 1);
super->url = ftpfs_split_url (strchr (op, ':') + 1); super->path_element = ftpfs_split_url (strchr (op, ':') + 1);
SUP->proxy = NULL; SUP->proxy = NULL;
if (ftpfs_check_proxy (super->url->host)) if (ftpfs_check_proxy (super->path_element->host))
SUP->proxy = ftpfs_proxy_host; SUP->proxy = ftpfs_proxy_host;
SUP->use_passive_connection = ftpfs_use_passive_connections; SUP->use_passive_connection = ftpfs_use_passive_connections;
SUP->strict = ftpfs_use_unix_list_options ? RFC_AUTODETECT : RFC_STRICT; SUP->strict = ftpfs_use_unix_list_options ? RFC_AUTODETECT : RFC_STRICT;
@ -982,20 +986,20 @@ static int
ftpfs_archive_same (struct vfs_class *me, struct vfs_s_super *super, ftpfs_archive_same (struct vfs_class *me, struct vfs_s_super *super,
const char *archive_name, char *op, void *cookie) const char *archive_name, char *op, void *cookie)
{ {
vfs_url_t *url; vfs_path_element_t *path_element;
int result; int result;
(void) me; (void) me;
(void) archive_name; (void) archive_name;
(void) cookie; (void) cookie;
url = ftpfs_split_url (strchr (op, ':') + 1); path_element = ftpfs_split_url (strchr (op, ':') + 1);
result = ((strcmp (url->host, super->url->host) == 0) result = ((strcmp (path_element->host, super->path_element->host) == 0)
&& (strcmp (url->user, super->url->user) == 0) && (strcmp (path_element->user, super->path_element->user) == 0)
&& (url->port == super->url->port)) ? 1 : 0; && (path_element->port == super->path_element->port)) ? 1 : 0;
vfs_url_free (url); vfs_path_element_free (path_element);
return result; return result;
} }
@ -2023,9 +2027,9 @@ ftpfs_is_same_dir (struct vfs_class *me, struct vfs_s_super *super, const char *
{ {
(void) me; (void) me;
if (super->url->path == NULL) if (super->path_element->path == NULL)
return FALSE; return FALSE;
return (strcmp (path, super->url->path) == 0); return (strcmp (path, super->path_element->path) == 0);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -2047,8 +2051,8 @@ ftpfs_chdir_internal (struct vfs_class *me, struct vfs_s_super *super, const cha
ftpfs_errno = EIO; ftpfs_errno = EIO;
else else
{ {
g_free (super->url->path); g_free (super->path_element->path);
super->url->path = g_strdup (remote_path); super->path_element->path = g_strdup (remote_path);
SUP->cwd_deferred = 0; SUP->cwd_deferred = 0;
} }
return r; return r;
@ -2206,8 +2210,9 @@ ftpfs_fill_names (struct vfs_class *me, fill_names_f func)
const struct vfs_s_super *super = (const struct vfs_s_super *) iter->data; const struct vfs_s_super *super = (const struct vfs_s_super *) iter->data;
char *name; char *name;
name = g_strconcat ("/#ftp:", super->url->user, "@", super->url->host, "/", name =
super->url->path, (char *) NULL); g_strconcat ("/#ftp:", super->path_element->user, "@", super->path_element->host, "/",
super->path_element->path, (char *) NULL);
func (name); func (name);
g_free (name); g_free (name);
} }

Просмотреть файл

@ -1321,7 +1321,7 @@ static char *
smbfs_get_path (smbfs_connection ** sc, const vfs_path_t * vpath) smbfs_get_path (smbfs_connection ** sc, const vfs_path_t * vpath)
{ {
char *remote_path = NULL; char *remote_path = NULL;
vfs_url_t *url; vfs_path_element_t *url;
vfs_path_element_t *path_element = vfs_path_get_by_index (vpath, -1); vfs_path_element_t *path_element = vfs_path_get_by_index (vpath, -1);
char *path = path_element->path; char *path = path_element->path;
@ -1343,7 +1343,7 @@ smbfs_get_path (smbfs_connection ** sc, const vfs_path_t * vpath)
if (*sc != NULL) if (*sc != NULL)
remote_path = g_strdup (url->path); remote_path = g_strdup (url->path);
vfs_url_free (url); vfs_path_element_free (url);
} }
if (remote_path == NULL) if (remote_path == NULL)
@ -1949,7 +1949,7 @@ smbfs_free (vfsid id)
static void static void
smbfs_forget (const char *path) smbfs_forget (const char *path)
{ {
vfs_url_t *p; vfs_path_element_t *p;
if (strncmp (path, URL_HEADER, HEADER_LEN) != 0) if (strncmp (path, URL_HEADER, HEADER_LEN) != 0)
return; return;
@ -1981,7 +1981,7 @@ smbfs_forget (const char *path)
} }
} }
vfs_url_free (p); vfs_path_element_free (p);
} }
} }