VFS: Added new function vfs_path_to_str_flags()
[midnight-commander.git] / lib / vfs / path.h
blob8aa3fcfce835e9261f6d6f41b858fa248616768f
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 } vfs_path_flag_t;
20 /*** structures declarations (and typedefs of structures)*****************************************/
22 struct vfs_class;
23 struct vfs_url_struct;
25 typedef struct
27 GArray *path;
28 } vfs_path_t;
30 typedef struct
32 char *user;
33 char *password;
34 char *host;
35 gboolean ipv6;
36 int port;
37 char *path;
38 struct vfs_class *class;
39 char *encoding;
40 char *vfs_prefix;
42 struct
44 GIConv converter;
45 DIR *info;
46 } dir;
47 } vfs_path_element_t;
49 /*** global variables defined in .c file *********************************************************/
51 /*** declarations of public functions ************************************************************/
53 vfs_path_t *vfs_path_new (void);
54 vfs_path_t *vfs_path_clone (const vfs_path_t * vpath);
55 void vfs_path_remove_element_by_index (vfs_path_t * vpath, int element_index);
56 void vfs_path_free (vfs_path_t * path);
57 int vfs_path_elements_count (const vfs_path_t * path);
59 char *vfs_path_to_str (const vfs_path_t * path);
60 char *vfs_path_to_str_elements_count (const vfs_path_t * path, int elements_count);
61 char *vfs_path_to_str_flags (const vfs_path_t * vpath, int elements_count, vfs_path_flag_t flags);
62 vfs_path_t *vfs_path_from_str (const char *path_str);
63 vfs_path_t *vfs_path_from_str_flags (const char *path_str, vfs_path_flag_t flags);
64 vfs_path_t *vfs_path_build_filename (const char *first_element, ...);
65 vfs_path_t *vfs_path_append_new (const vfs_path_t * vpath, const char *first_element, ...);
66 vfs_path_t *vfs_path_append_vpath_new (const vfs_path_t * first_vpath, ...);
67 size_t vfs_path_tokens_count (const vfs_path_t *);
68 char *vfs_path_tokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t length);
69 vfs_path_t *vfs_path_vtokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t length);
71 vfs_path_element_t *vfs_path_get_by_index (const vfs_path_t * path, int element_index);
72 vfs_path_element_t *vfs_path_element_clone (const vfs_path_element_t * element);
73 void vfs_path_element_free (vfs_path_element_t * element);
75 struct vfs_class *vfs_prefix_to_class (const char *prefix);
77 gboolean vfs_path_element_need_cleanup_converter (const vfs_path_element_t * element);
79 char *vfs_path_serialize (const vfs_path_t * vpath, GError ** error);
80 vfs_path_t *vfs_path_deserialize (const char *data, GError ** error);
82 char *vfs_path_build_url_params_str (const vfs_path_element_t * element, gboolean keep_password);
83 size_t vfs_path_len (const vfs_path_t * vpath);
84 int vfs_path_cmp (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
85 int vfs_path_ncmp (const vfs_path_t * vpath1, const vfs_path_t * vpath2, size_t len);
87 /*** inline functions ****************************************************************************/
89 static inline gboolean
90 vfs_path_element_valid (const vfs_path_element_t * element)
92 return (element != NULL && element->class != NULL);
95 /* --------------------------------------------------------------------------------------------- */
97 static inline char *
98 vfs_path_get_last_path_str (const vfs_path_t * vpath)
100 const vfs_path_element_t *element;
101 if (vpath == NULL)
102 return NULL;
103 element = vfs_path_get_by_index (vpath, -1);
104 return (element != NULL) ? element->path : NULL;
107 /* --------------------------------------------------------------------------------------------- */
109 static inline struct vfs_class *
110 vfs_path_get_last_path_vfs (const vfs_path_t * vpath)
112 const vfs_path_element_t *element;
113 if (vpath == NULL)
114 return NULL;
115 element = vfs_path_get_by_index (vpath, -1);
116 return (element != NULL) ? element->class : NULL;
119 #endif