Merge branch '2361_url_path'

* 2361_url_path:
  Fixed errors while connect to IPv6 hosts
  custom_canonicalize_pathname(): Removed old-style path handling.
  Deprecated parser now used just in Hotlist widget.
  fixed relative symlink operations. Symlink now stay relative
  Ticket #2361: VFS URI reimplementation
This commit is contained in:
Slava Zanko 2011-07-05 16:20:01 +03:00
commit 906f688742
17 changed files with 103 additions and 131 deletions

View File

@ -69,47 +69,6 @@ test_chdir(const vfs_path_t * vpath)
strcmp(etalon, mc_get_current_wd(buffer,MC_MAXPATHLEN)) == 0, \
"\n expected(%s) doesn't equal \nto actual(%s)", etalon, buffer);
START_TEST (set_up_current_dir)
{
static struct vfs_s_subclass test_subclass;
static struct vfs_class vfs_test_ops;
char buffer[MC_MAXPATHLEN];
vfs_s_init_class (&vfs_test_ops, &test_subclass);
vfs_test_ops.name = "testfs";
vfs_test_ops.flags = VFSF_NOLINKS;
vfs_test_ops.prefix = "test";
vfs_test_ops.chdir = test_chdir;
vfs_register_class (&vfs_test_ops);
cd_and_check ("/dev/some.file#test", "/dev/some.file/test://");
cd_and_check ("/dev/some.file#test/bla-bla", "/dev/some.file/test://bla-bla");
cd_and_check ("..", "/dev/some.file/test://");
cd_and_check ("..", "/dev");
cd_and_check ("..", "/");
cd_and_check ("..", "/");
cd_and_check ("/dev/some.file/#test/bla-bla", "/dev/some.file/test://bla-bla");
cd_and_check ("..", "/dev/some.file/test://");
cd_and_check ("..", "/dev");
cd_and_check ("..", "/");
cd_and_check ("..", "/");
}
END_TEST
/* --------------------------------------------------------------------------------------------- */
START_TEST (set_up_current_dir_url)
{
static struct vfs_s_subclass test_subclass;
@ -161,7 +120,6 @@ main (void)
tcase_add_checked_fixture (tc_core, setup, teardown);
/* Add new tests here: *************** */
tcase_add_test (tc_core, set_up_current_dir);
tcase_add_test (tc_core, set_up_current_dir_url);
/* *********************************** */

View File

@ -115,7 +115,7 @@ START_TEST (test_path_serialize_deserialize)
char *serialized_vpath;
GError *error = NULL;
vpath = vfs_path_from_str (ETALON_PATH_STR);
vpath = vfs_path_from_str_flags (ETALON_PATH_STR, VPF_USE_DEPRECATED_PARSER);
serialized_vpath = vfs_path_serialize (vpath, &error);
vfs_path_free (vpath);

View File

@ -87,7 +87,7 @@ START_TEST (test_vfs_path_from_to_string)
vfs_path_t *vpath;
size_t vpath_len;
char *result;
vpath = vfs_path_from_str (ETALON_PATH_STR);
vpath = vfs_path_from_str_flags (ETALON_PATH_STR, VPF_USE_DEPRECATED_PARSER);
vpath_len = vfs_path_elements_count(vpath);
@ -133,7 +133,7 @@ START_TEST (test_vfs_path_from_to_partial_string_by_class)
{
vfs_path_t *vpath;
char *result;
vpath = vfs_path_from_str (ETALON_PATH_STR);
vpath = vfs_path_from_str_flags (ETALON_PATH_STR, VPF_USE_DEPRECATED_PARSER);
result = vfs_path_to_str_elements_count(vpath, -1);
@ -203,7 +203,7 @@ END_TEST
vfs_path_t *vpath; \
char *result; \
\
vpath = vfs_path_from_str (input); \
vpath = vfs_path_from_str_flags (input, VPF_USE_DEPRECATED_PARSER); \
result = vfs_path_to_str(vpath); \
fail_unless( result != NULL && strcmp(result, etalon) ==0, \
"\ninput : %s\nactual: %s\netalon: %s", input, result , etalon ); \
@ -262,7 +262,7 @@ START_TEST (test_vfs_path_encoding_at_end)
mc_global.sysconfig_dir = (char *) TEST_SHARE_DIR;
load_codepages_list ();
vpath = vfs_path_from_str ("/path/to/file.ext#test1:/#enc:KOI8-R");
vpath = vfs_path_from_str_flags ("/path/to/file.ext#test1:/#enc:KOI8-R", VPF_USE_DEPRECATED_PARSER);
result = vfs_path_to_str(vpath);
element = vfs_path_get_by_index(vpath, -1);

View File

@ -125,7 +125,8 @@ START_TEST (test_vfs_s_get_path)
struct vfs_s_super *archive;
const char *result;
vfs_path_t *vpath = vfs_path_from_str("/" ETALON_VFS_NAME ARCH_NAME "#test1:/" ETALON_PATH);
vfs_path_t *vpath = vfs_path_from_str_flags ("/" ETALON_VFS_NAME ARCH_NAME "#test1:/" ETALON_PATH,
VPF_USE_DEPRECATED_PARSER);
result = vfs_s_get_path (vpath, &archive, 0);

View File

@ -695,26 +695,8 @@ custom_canonicalize_pathname (char *path, CANON_PATH_FLAGS flags)
}
if (*s == PATH_SEP)
{
/* skip VFS prefix */
char *path_sep;
struct vfs_class *vclass;
break;
/* old parser mode */
if (*(s + 1) != '#')
break;
path_sep = strchr (s + 1, PATH_SEP);
if (path_sep != NULL)
*path_sep = '\0';
vclass = vfs_prefix_to_class (s + 2);
if (path_sep != NULL)
*path_sep = PATH_SEP;
if (vclass == NULL)
break;
}
s--;
}

View File

@ -265,12 +265,11 @@ mc_symlink (const char *name1, const char *path)
if (vpath1 == NULL)
return -1;
vpath2 = vfs_path_from_str (name1);
vpath2 = vfs_path_from_str_flags (name1, VPF_NO_CANON);
if (vpath2 != NULL)
{
vfs_path_element_t *path_element =
vfs_path_get_by_index (vpath1, vfs_path_elements_count (vpath1) - 1);
vfs_path_element_t *path_element = vfs_path_get_by_index (vpath1, -1);
if (vfs_path_element_valid (path_element))
{
result =
@ -330,8 +329,8 @@ int mc_##name (const char *fname1, const char *fname2) \
vfs_path_free(vpath1); \
return -1; \
}\
path_element1 = vfs_path_get_by_index (vpath1, vfs_path_elements_count (vpath1) - 1); \
path_element2 = vfs_path_get_by_index (vpath2, vfs_path_elements_count (vpath2) - 1); \
path_element1 = vfs_path_get_by_index (vpath1, - 1); \
path_element2 = vfs_path_get_by_index (vpath2, - 1); \
\
if (!vfs_path_element_valid (path_element1) || !vfs_path_element_valid (path_element2) || \
path_element1->class != path_element2->class) \

View File

@ -193,7 +193,11 @@ vfs_path_build_url_params_str (vfs_path_element_t * element)
{
if ((element->user != NULL) || (element->password != NULL))
g_string_append_c (buffer, '@');
if (element->ipv6)
g_string_append_c (buffer, '[');
g_string_append (buffer, element->host);
if (element->ipv6)
g_string_append_c (buffer, ']');
}
if ((element->port) != 0 && (element->host != NULL))
@ -314,6 +318,7 @@ vfs_path_url_split (vfs_path_element_t * path_element, const char *path)
colon[0] = '\0';
colon[1] = '\0';
colon++;
path_element->ipv6 = TRUE;
}
}
@ -605,6 +610,43 @@ vfs_path_to_str (const vfs_path_t * vpath)
return vfs_path_to_str_elements_count (vpath, vfs_path_elements_count (vpath));
}
/* --------------------------------------------------------------------------------------------- */
/**
* Split path string to path elements with flags for change parce process.
*
* @param path_str VFS-path
* @param flags flags for parser
*
* @return pointer to newly created vfs_path_t object with filled path elements array.
*/
vfs_path_t *
vfs_path_from_str_flags (const char *path_str, vfs_path_flag_t flags)
{
vfs_path_t *vpath;
char *path;
if (path_str == NULL)
return NULL;
if ((flags & VPF_NO_CANON) == 0)
path = vfs_canon (path_str);
else
path = g_strdup (path_str);
if (path == NULL)
return NULL;
if ((flags & VPF_USE_DEPRECATED_PARSER) != 0 && vfs_path_is_str_path_deprecated (path))
vpath = vfs_path_from_str_deprecated_parser (path);
else
vpath = vfs_path_from_str_uri_parser (path);
g_free (path);
return vpath;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Split path string to path elements.
@ -617,24 +659,7 @@ vfs_path_to_str (const vfs_path_t * vpath)
vfs_path_t *
vfs_path_from_str (const char *path_str)
{
vfs_path_t *vpath;
char *path;
if (path_str == NULL)
return NULL;
path = vfs_canon (path_str);
if (path == NULL)
return NULL;
if (vfs_path_is_str_path_deprecated (path))
vpath = vfs_path_from_str_deprecated_parser (path);
else
vpath = vfs_path_from_str_uri_parser (path);
g_free (path);
return vpath;
return vfs_path_from_str_flags (path_str, VPF_NONE);
}
/* --------------------------------------------------------------------------------------------- */
@ -664,10 +689,7 @@ vfs_path_new (void)
int
vfs_path_elements_count (const vfs_path_t * vpath)
{
if (vpath == NULL)
return 0;
return (vpath->path != NULL) ? g_list_length (vpath->path) : 0;
return (vpath != NULL && vpath->path != NULL) ? g_list_length (vpath->path) : 0;
}
/* --------------------------------------------------------------------------------------------- */
@ -683,19 +705,13 @@ vfs_path_elements_count (const vfs_path_t * vpath)
vfs_path_element_t *
vfs_path_get_by_index (const vfs_path_t * vpath, int element_index)
{
vfs_path_element_t *element;
if (vpath == NULL)
return NULL;
if (element_index < 0)
element_index += vfs_path_elements_count (vpath);
if (element_index < 0)
element_index = vfs_path_elements_count (vpath) + element_index;
element = g_list_nth_data (vpath->path, element_index);
if (element == NULL)
vfs_die ("vfs_path_get_by_index: incorrect index!");
return element;
return g_list_nth_data (vpath->path, element_index);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -7,6 +7,13 @@
/*** enums ***************************************************************************************/
typedef enum
{
VPF_NONE = 0,
VPF_NO_CANON = 1,
VPF_USE_DEPRECATED_PARSER = 2
} vfs_path_flag_t;
/*** structures declarations (and typedefs of structures)*****************************************/
struct vfs_class;
@ -22,6 +29,7 @@ typedef struct
char *user;
char *password;
char *host;
gboolean ipv6;
int port;
char *path;
struct vfs_class *class;
@ -33,8 +41,6 @@ typedef struct
GIConv converter;
DIR *info;
} dir;
struct vfs_s_super *current_super_block;
} vfs_path_element_t;
/*** global variables defined in .c file *********************************************************/
@ -50,6 +56,7 @@ int vfs_path_elements_count (const vfs_path_t * path);
char *vfs_path_to_str (const vfs_path_t * path);
char *vfs_path_to_str_elements_count (const vfs_path_t * path, int elements_count);
vfs_path_t *vfs_path_from_str (const char *path_str);
vfs_path_t *vfs_path_from_str_flags (const char *path_str, vfs_path_flag_t flags);
vfs_path_element_t *vfs_path_get_by_index (const vfs_path_t * path, int element_index);
vfs_path_element_t *vfs_path_element_clone (const vfs_path_element_t * element);

View File

@ -379,8 +379,7 @@ vfs_get_raw_current_dir (void)
void
vfs_set_raw_current_dir (const vfs_path_t * vpath)
{
if (current_path != NULL)
vfs_path_free (current_path);
vfs_path_free (current_path);
current_path = (vfs_path_t *) vpath;
}

View File

@ -163,7 +163,7 @@ typedef struct vfs_class
int (*lstat) (const vfs_path_t * vpath, struct stat * buf);
int (*fstat) (void *vfs_info, struct stat * buf);
int (*chmod) (const vfs_path_t * vpath, int mode);
int (*chmod) (const vfs_path_t * vpath, mode_t mode);
int (*chown) (const vfs_path_t * vpath, uid_t owner, gid_t group);
int (*utime) (const vfs_path_t * vpath, struct utimbuf * times);

View File

@ -1429,13 +1429,18 @@ hot_load_group (struct hotlist *grp)
current_group = grp;
break;
case TKN_ENTRY:
CHECK_TOKEN (TKN_STRING);
label = g_strdup (tkn_buf->str);
CHECK_TOKEN (TKN_URL);
CHECK_TOKEN (TKN_STRING);
url = g_strdup (tkn_buf->str);
add2hotlist (label, url, HL_TYPE_ENTRY, LISTBOX_APPEND_AT_END);
SKIP_TO_EOL;
{
vfs_path_t *vpath;
CHECK_TOKEN (TKN_STRING);
label = g_strdup (tkn_buf->str);
CHECK_TOKEN (TKN_URL);
CHECK_TOKEN (TKN_STRING);
vpath = vfs_path_from_str_flags (tkn_buf->str, VPF_USE_DEPRECATED_PARSER);
url = vfs_path_to_str (vpath);
vfs_path_free (vpath);
add2hotlist (label, url, HL_TYPE_ENTRY, LISTBOX_APPEND_AT_END);
SKIP_TO_EOL;
}
break;
case TKN_COMMENT:
label = g_strdup (tkn_buf->str);
@ -1481,13 +1486,18 @@ hot_load_file (struct hotlist *grp)
current_group = grp;
break;
case TKN_ENTRY:
CHECK_TOKEN (TKN_STRING);
label = g_strdup (tkn_buf->str);
CHECK_TOKEN (TKN_URL);
CHECK_TOKEN (TKN_STRING);
url = g_strdup (tkn_buf->str);
add2hotlist (label, url, HL_TYPE_ENTRY, LISTBOX_APPEND_AT_END);
SKIP_TO_EOL;
{
vfs_path_t *vpath;
CHECK_TOKEN (TKN_STRING);
label = g_strdup (tkn_buf->str);
CHECK_TOKEN (TKN_URL);
CHECK_TOKEN (TKN_STRING);
vpath = vfs_path_from_str_flags (tkn_buf->str, VPF_USE_DEPRECATED_PARSER);
url = vfs_path_to_str (vpath);
vfs_path_free (vpath);
add2hotlist (label, url, HL_TYPE_ENTRY, LISTBOX_APPEND_AT_END);
SKIP_TO_EOL;
}
break;
case TKN_COMMENT:
label = g_strdup (tkn_buf->str);

View File

@ -1177,7 +1177,7 @@ extfs_chown (const vfs_path_t * vpath, uid_t owner, gid_t group)
/* --------------------------------------------------------------------------------------------- */
static int
extfs_chmod (const vfs_path_t * vpath, int mode)
extfs_chmod (const vfs_path_t * vpath, mode_t mode)
{
(void) vpath;
(void) mode;

View File

@ -1244,7 +1244,7 @@ fish_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2)
/* --------------------------------------------------------------------------------------------- */
static int
fish_chmod (const vfs_path_t * vpath, int mode)
fish_chmod (const vfs_path_t * vpath, mode_t mode)
{
gchar *shell_commands = NULL;
char buf[BUF_LARGE];
@ -1262,7 +1262,7 @@ fish_chmod (const vfs_path_t * vpath, int mode)
shell_commands = g_strconcat (SUP->scr_env, "FISH_FILENAME=%s FISH_FILEMODE=%4.4o;\n",
SUP->scr_chmod, (char *) NULL);
g_snprintf (buf, sizeof (buf), shell_commands, rpath, mode & 07777);
g_snprintf (buf, sizeof (buf), shell_commands, rpath, (int) (mode & 07777));
g_free (shell_commands);
g_free (rpath);
return fish_send_command (path_element->class, super, buf, OPT_FLUSH);

View File

@ -1981,12 +1981,12 @@ ftpfs_send_command (const vfs_path_t * vpath, const char *cmd, int flags)
/* --------------------------------------------------------------------------------------------- */
static int
ftpfs_chmod (const vfs_path_t * vpath, int mode)
ftpfs_chmod (const vfs_path_t * vpath, mode_t mode)
{
char buf[BUF_SMALL];
int ret;
g_snprintf (buf, sizeof (buf), "SITE CHMOD %4.4o /%%s", mode & 07777);
g_snprintf (buf, sizeof (buf), "SITE CHMOD %4.4o /%%s", (int) (mode & 07777));
ret = ftpfs_send_command (vpath, buf, OPT_FLUSH);

View File

@ -141,7 +141,7 @@ local_lstat (const vfs_path_t * vpath, struct stat *buf)
/* --------------------------------------------------------------------------------------------- */
static int
local_chmod (const vfs_path_t * vpath, int mode)
local_chmod (const vfs_path_t * vpath, mode_t mode)
{
vfs_path_element_t *path_element = vfs_path_get_by_index (vpath, -1);

View File

@ -293,7 +293,7 @@ sfs_lstat (const vfs_path_t * vpath, struct stat *buf)
/* --------------------------------------------------------------------------------------------- */
static int
sfs_chmod (const vfs_path_t * vpath, int mode)
sfs_chmod (const vfs_path_t * vpath, mode_t mode)
{
return chmod (sfs_redirect (vpath), mode);
}

View File

@ -964,11 +964,11 @@ smbfs_closedir (void *info)
/* --------------------------------------------------------------------------------------------- */
static int
smbfs_chmod (const vfs_path_t * vpath, int mode)
smbfs_chmod (const vfs_path_t * vpath, mode_t mode)
{
vfs_path_element_t *path_element = vfs_path_get_by_index (vpath, -1);
DEBUG (3, ("smbfs_chmod(path:%s, mode:%d)\n", path_element->path, mode));
DEBUG (3, ("smbfs_chmod(path:%s, mode:%d)\n", path_element->path, (int) mode));
/* my_errno = EOPNOTSUPP;
return -1; *//* cannot chmod on smb filesystem */
return 0; /* make mc happy */