2011-04-14 16:21:30 +04:00
|
|
|
#ifndef MC__VFS_PATH_H
|
|
|
|
#define MC__VFS_PATH_H
|
|
|
|
|
|
|
|
/*** typedefs(not structures) and defined constants **********************************************/
|
|
|
|
|
2011-06-14 16:09:59 +04:00
|
|
|
#define VFS_PATH_URL_DELIMITER "://"
|
|
|
|
|
2011-04-14 16:21:30 +04:00
|
|
|
/*** enums ***************************************************************************************/
|
|
|
|
|
2011-06-29 14:12:19 +04:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
VPF_NONE = 0,
|
2011-08-15 15:37:59 +04:00
|
|
|
VPF_NO_CANON = 1 << 0,
|
2011-11-27 00:12:52 +04:00
|
|
|
VPF_USE_DEPRECATED_PARSER = 1 << 1,
|
|
|
|
VPF_RECODE = 1 << 2,
|
|
|
|
VPF_STRIP_HOME = 1 << 3,
|
2011-11-27 04:09:41 +04:00
|
|
|
VPF_STRIP_PASSWORD = 1 << 4,
|
|
|
|
VPF_HIDE_CHARSET = 1 << 5
|
2011-06-29 14:12:19 +04:00
|
|
|
} vfs_path_flag_t;
|
|
|
|
|
2011-04-14 16:21:30 +04:00
|
|
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
|
|
|
|
|
|
|
struct vfs_class;
|
2011-04-28 15:39:59 +04:00
|
|
|
struct vfs_url_struct;
|
2011-04-14 16:21:30 +04:00
|
|
|
|
2011-04-20 16:59:06 +04:00
|
|
|
typedef struct
|
|
|
|
{
|
2012-02-07 15:54:58 +04:00
|
|
|
gboolean relative;
|
2011-09-29 13:02:23 +04:00
|
|
|
GArray *path;
|
2013-04-14 17:38:37 +04:00
|
|
|
char *str;
|
2011-04-14 16:21:30 +04:00
|
|
|
} vfs_path_t;
|
|
|
|
|
2011-04-20 16:59:06 +04:00
|
|
|
typedef struct
|
|
|
|
{
|
2011-06-07 14:18:08 +04:00
|
|
|
char *user;
|
|
|
|
char *password;
|
|
|
|
char *host;
|
2011-07-05 17:05:15 +04:00
|
|
|
gboolean ipv6;
|
2011-06-07 14:18:08 +04:00
|
|
|
int port;
|
2011-04-14 16:21:30 +04:00
|
|
|
char *path;
|
|
|
|
struct vfs_class *class;
|
2012-04-30 14:58:25 +04:00
|
|
|
#ifdef HAVE_CHARSET
|
2011-04-14 16:21:30 +04:00
|
|
|
char *encoding;
|
2012-04-30 14:58:25 +04:00
|
|
|
#endif
|
2011-06-13 14:19:47 +04:00
|
|
|
char *vfs_prefix;
|
2011-04-28 15:39:59 +04:00
|
|
|
|
2011-05-30 11:16:40 +04:00
|
|
|
struct
|
|
|
|
{
|
2012-04-30 14:58:25 +04:00
|
|
|
#ifdef HAVE_CHARSET
|
2011-05-30 11:16:40 +04:00
|
|
|
GIConv converter;
|
2012-04-30 14:58:25 +04:00
|
|
|
#endif
|
2011-05-30 11:16:40 +04:00
|
|
|
DIR *info;
|
2011-05-27 19:28:46 +04:00
|
|
|
} dir;
|
2011-04-14 16:21:30 +04:00
|
|
|
} vfs_path_element_t;
|
|
|
|
|
|
|
|
/*** global variables defined in .c file *********************************************************/
|
|
|
|
|
|
|
|
/*** declarations of public functions ************************************************************/
|
|
|
|
|
2023-04-02 15:46:26 +03:00
|
|
|
vfs_path_t *vfs_path_new (gboolean relative);
|
2011-06-08 17:40:36 +04:00
|
|
|
vfs_path_t *vfs_path_clone (const vfs_path_t * vpath);
|
|
|
|
void vfs_path_remove_element_by_index (vfs_path_t * vpath, int element_index);
|
2021-02-21 19:30:18 +03:00
|
|
|
char *vfs_path_free (vfs_path_t * path, gboolean free_str);
|
2011-04-28 15:39:59 +04:00
|
|
|
int vfs_path_elements_count (const vfs_path_t * path);
|
2011-04-14 16:21:30 +04:00
|
|
|
|
2011-04-28 15:39:59 +04:00
|
|
|
char *vfs_path_to_str_elements_count (const vfs_path_t * path, int elements_count);
|
2011-11-27 00:12:52 +04:00
|
|
|
char *vfs_path_to_str_flags (const vfs_path_t * vpath, int elements_count, vfs_path_flag_t flags);
|
2011-04-20 16:59:06 +04:00
|
|
|
vfs_path_t *vfs_path_from_str (const char *path_str);
|
2011-06-29 14:12:19 +04:00
|
|
|
vfs_path_t *vfs_path_from_str_flags (const char *path_str, vfs_path_flag_t flags);
|
2011-07-17 20:59:47 +04:00
|
|
|
vfs_path_t *vfs_path_build_filename (const char *first_element, ...);
|
2011-09-25 15:36:44 +04:00
|
|
|
vfs_path_t *vfs_path_append_new (const vfs_path_t * vpath, const char *first_element, ...);
|
|
|
|
vfs_path_t *vfs_path_append_vpath_new (const vfs_path_t * first_vpath, ...);
|
2021-05-16 13:56:44 +03:00
|
|
|
size_t vfs_path_tokens_count (const vfs_path_t * vpath);
|
2011-11-08 23:44:38 +04:00
|
|
|
char *vfs_path_tokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t length);
|
|
|
|
vfs_path_t *vfs_path_vtokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t length);
|
2011-04-14 16:21:30 +04:00
|
|
|
|
2016-02-20 13:13:31 +03:00
|
|
|
void vfs_path_add_element (vfs_path_t * vpath, const vfs_path_element_t * path_element);
|
2012-01-03 13:35:57 +04:00
|
|
|
const vfs_path_element_t *vfs_path_get_by_index (const vfs_path_t * path, int element_index);
|
2011-06-08 17:40:36 +04:00
|
|
|
vfs_path_element_t *vfs_path_element_clone (const vfs_path_element_t * element);
|
2011-04-20 16:59:06 +04:00
|
|
|
void vfs_path_element_free (vfs_path_element_t * element);
|
2011-04-14 16:21:30 +04:00
|
|
|
|
2011-04-28 15:39:59 +04:00
|
|
|
struct vfs_class *vfs_prefix_to_class (const char *prefix);
|
2011-04-14 16:21:30 +04:00
|
|
|
|
2012-04-30 14:58:25 +04:00
|
|
|
#ifdef HAVE_CHARSET
|
2024-10-03 14:29:28 +03:00
|
|
|
char *vfs_get_encoding(const char *path, ssize_t len);
|
2011-06-01 14:56:52 +04:00
|
|
|
gboolean vfs_path_element_need_cleanup_converter (const vfs_path_element_t * element);
|
2013-07-22 16:25:12 +04:00
|
|
|
vfs_path_t *vfs_path_change_encoding (vfs_path_t * vpath, const char *encoding);
|
2012-04-30 14:58:25 +04:00
|
|
|
#endif
|
2011-06-01 14:56:52 +04:00
|
|
|
|
2011-06-07 13:22:31 +04:00
|
|
|
char *vfs_path_serialize (const vfs_path_t * vpath, GError ** error);
|
|
|
|
vfs_path_t *vfs_path_deserialize (const char *data, GError ** error);
|
|
|
|
|
2022-10-30 09:28:25 +03:00
|
|
|
GString *vfs_path_build_url_params_str (const vfs_path_element_t * element, gboolean keep_password);
|
2022-10-30 09:13:58 +03:00
|
|
|
GString *vfs_path_element_build_pretty_path_str (const vfs_path_element_t * element);
|
2012-04-20 15:03:53 +04:00
|
|
|
|
2011-10-04 15:04:48 +04:00
|
|
|
size_t vfs_path_len (const vfs_path_t * vpath);
|
2013-01-28 17:20:42 +04:00
|
|
|
gboolean vfs_path_equal (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
|
|
|
|
gboolean vfs_path_equal_len (const vfs_path_t * vpath1, const vfs_path_t * vpath2, size_t len);
|
2012-02-07 15:54:58 +04:00
|
|
|
vfs_path_t *vfs_path_to_absolute (const vfs_path_t * vpath);
|
2011-09-28 00:31:20 +04:00
|
|
|
|
2011-04-14 16:21:30 +04:00
|
|
|
/*** inline functions ****************************************************************************/
|
|
|
|
|
2011-06-17 14:28:37 +04:00
|
|
|
static inline gboolean
|
2024-06-01 21:12:14 +03:00
|
|
|
vfs_path_element_valid (const vfs_path_element_t *element)
|
2011-06-17 14:28:37 +04:00
|
|
|
{
|
|
|
|
return (element != NULL && element->class != NULL);
|
|
|
|
}
|
|
|
|
|
2011-07-23 17:18:53 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2012-01-03 13:35:57 +04:00
|
|
|
static inline const char *
|
2024-06-01 21:12:14 +03:00
|
|
|
vfs_path_get_last_path_str (const vfs_path_t *vpath)
|
2011-07-23 17:18:53 +04:00
|
|
|
{
|
|
|
|
const vfs_path_element_t *element;
|
2024-10-05 14:42:11 +03:00
|
|
|
|
2011-07-23 17:18:53 +04:00
|
|
|
if (vpath == NULL)
|
|
|
|
return NULL;
|
|
|
|
element = vfs_path_get_by_index (vpath, -1);
|
|
|
|
return (element != NULL) ? element->path : NULL;
|
|
|
|
}
|
|
|
|
|
2011-07-23 17:24:36 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2012-01-03 13:35:57 +04:00
|
|
|
static inline const struct vfs_class *
|
2024-06-01 21:12:14 +03:00
|
|
|
vfs_path_get_last_path_vfs (const vfs_path_t *vpath)
|
2011-07-23 17:24:36 +04:00
|
|
|
{
|
|
|
|
const vfs_path_element_t *element;
|
2024-10-05 14:42:11 +03:00
|
|
|
|
2011-07-23 17:24:36 +04:00
|
|
|
if (vpath == NULL)
|
|
|
|
return NULL;
|
|
|
|
element = vfs_path_get_by_index (vpath, -1);
|
|
|
|
return (element != NULL) ? element->class : NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-14 17:38:37 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/**
|
|
|
|
* Convert vfs_path_t to string representation.
|
|
|
|
*
|
|
|
|
* @param vpath pointer to vfs_path_t object
|
|
|
|
*
|
2013-06-18 11:50:57 +04:00
|
|
|
* @return pointer to constant string
|
2013-04-14 17:38:37 +04:00
|
|
|
*/
|
|
|
|
|
2013-06-18 11:50:57 +04:00
|
|
|
static inline const char *
|
2024-06-01 21:12:14 +03:00
|
|
|
vfs_path_as_str (const vfs_path_t *vpath)
|
2013-04-14 17:38:37 +04:00
|
|
|
{
|
2013-06-18 11:50:57 +04:00
|
|
|
return (vpath == NULL ? NULL : vpath->str);
|
2013-04-14 17:38:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2011-04-14 16:21:30 +04:00
|
|
|
#endif
|