Ticket #2779: Active VFS directories list contain incorrect current path
[midnight-commander.git] / lib / vfs / path.h
blob98db436aa09ea3f6850fb659a5030adf536065d7
1 #ifndef MC__VFS_PATH_H
2 #define MC__VFS_PATH_H
4 /*** typedefs(not structures) and defined constants **********************************************/
6 #define VFS_PATH_URL_DELIMITER "://"
8 /*** enums ***************************************************************************************/
10 typedef enum
12 VPF_NONE = 0,
13 VPF_NO_CANON = 1 << 0,
14 VPF_USE_DEPRECATED_PARSER = 1 << 1,
15 VPF_RECODE = 1 << 2,
16 VPF_STRIP_HOME = 1 << 3,
17 VPF_STRIP_PASSWORD = 1 << 4,
18 VPF_HIDE_CHARSET = 1 << 5
19 } vfs_path_flag_t;
21 /*** structures declarations (and typedefs of structures)*****************************************/
23 struct vfs_class;
24 struct vfs_url_struct;
26 typedef struct
28 gboolean relative;
29 GArray *path;
30 } vfs_path_t;
32 typedef struct
34 char *user;
35 char *password;
36 char *host;
37 gboolean ipv6;
38 int port;
39 char *path;
40 struct vfs_class *class;
41 char *encoding;
42 char *vfs_prefix;
44 struct
46 GIConv converter;
47 DIR *info;
48 } dir;
49 } vfs_path_element_t;
51 /*** global variables defined in .c file *********************************************************/
53 /*** declarations of public functions ************************************************************/
55 vfs_path_t *vfs_path_new (void);
56 vfs_path_t *vfs_path_clone (const vfs_path_t * vpath);
57 void vfs_path_remove_element_by_index (vfs_path_t * vpath, int element_index);
58 void vfs_path_free (vfs_path_t * path);
59 int vfs_path_elements_count (const vfs_path_t * path);
61 char *vfs_path_to_str (const vfs_path_t * path);
62 char *vfs_path_to_str_elements_count (const vfs_path_t * path, int elements_count);
63 char *vfs_path_to_str_flags (const vfs_path_t * vpath, int elements_count, vfs_path_flag_t flags);
64 vfs_path_t *vfs_path_from_str (const char *path_str);
65 vfs_path_t *vfs_path_from_str_flags (const char *path_str, vfs_path_flag_t flags);
66 vfs_path_t *vfs_path_build_filename (const char *first_element, ...);
67 vfs_path_t *vfs_path_append_new (const vfs_path_t * vpath, const char *first_element, ...);
68 vfs_path_t *vfs_path_append_vpath_new (const vfs_path_t * first_vpath, ...);
69 size_t vfs_path_tokens_count (const vfs_path_t *);
70 char *vfs_path_tokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t length);
71 vfs_path_t *vfs_path_vtokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t length);
73 void vfs_path_add_element (const vfs_path_t * vpath, const vfs_path_element_t * path_element);
74 const vfs_path_element_t *vfs_path_get_by_index (const vfs_path_t * path, int element_index);
75 vfs_path_element_t *vfs_path_element_clone (const vfs_path_element_t * element);
76 void vfs_path_element_free (vfs_path_element_t * element);
78 struct vfs_class *vfs_prefix_to_class (const char *prefix);
80 gboolean vfs_path_element_need_cleanup_converter (const vfs_path_element_t * element);
82 char *vfs_path_serialize (const vfs_path_t * vpath, GError ** error);
83 vfs_path_t *vfs_path_deserialize (const char *data, GError ** error);
85 char *vfs_path_build_url_params_str (const vfs_path_element_t * element, gboolean keep_password);
86 char *vfs_path_element_build_pretty_path_str (const vfs_path_element_t * element);
88 size_t vfs_path_len (const vfs_path_t * vpath);
89 int vfs_path_cmp (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
90 int vfs_path_ncmp (const vfs_path_t * vpath1, const vfs_path_t * vpath2, size_t len);
91 vfs_path_t *vfs_path_to_absolute (const vfs_path_t * vpath);
93 /*** inline functions ****************************************************************************/
95 static inline gboolean
96 vfs_path_element_valid (const vfs_path_element_t * element)
98 return (element != NULL && element->class != NULL);
101 /* --------------------------------------------------------------------------------------------- */
103 static inline const char *
104 vfs_path_get_last_path_str (const vfs_path_t * vpath)
106 const vfs_path_element_t *element;
107 if (vpath == NULL)
108 return NULL;
109 element = vfs_path_get_by_index (vpath, -1);
110 return (element != NULL) ? element->path : NULL;
113 /* --------------------------------------------------------------------------------------------- */
115 static inline const struct vfs_class *
116 vfs_path_get_last_path_vfs (const vfs_path_t * vpath)
118 const vfs_path_element_t *element;
119 if (vpath == NULL)
120 return NULL;
121 element = vfs_path_get_by_index (vpath, -1);
122 return (element != NULL) ? element->class : NULL;
125 #endif