path.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #ifndef MC__VFS_PATH_H
  2. #define MC__VFS_PATH_H
  3. /*** typedefs(not structures) and defined constants **********************************************/
  4. #define VFS_PATH_URL_DELIMITER "://"
  5. /*** enums ***************************************************************************************/
  6. typedef enum
  7. {
  8. VPF_NONE = 0,
  9. VPF_NO_CANON = 1 << 0,
  10. VPF_USE_DEPRECATED_PARSER = 1 << 1,
  11. VPF_RECODE = 1 << 2,
  12. VPF_STRIP_HOME = 1 << 3,
  13. VPF_STRIP_PASSWORD = 1 << 4,
  14. VPF_HIDE_CHARSET = 1 << 5
  15. } vfs_path_flag_t;
  16. /*** structures declarations (and typedefs of structures)*****************************************/
  17. struct vfs_class;
  18. struct vfs_url_struct;
  19. typedef struct
  20. {
  21. gboolean relative;
  22. GArray *path;
  23. } vfs_path_t;
  24. typedef struct
  25. {
  26. char *user;
  27. char *password;
  28. char *host;
  29. gboolean ipv6;
  30. int port;
  31. char *path;
  32. struct vfs_class *class;
  33. char *encoding;
  34. char *vfs_prefix;
  35. struct
  36. {
  37. GIConv converter;
  38. DIR *info;
  39. } dir;
  40. } vfs_path_element_t;
  41. /*** global variables defined in .c file *********************************************************/
  42. /*** declarations of public functions ************************************************************/
  43. vfs_path_t *vfs_path_new (void);
  44. vfs_path_t *vfs_path_clone (const vfs_path_t * vpath);
  45. void vfs_path_remove_element_by_index (vfs_path_t * vpath, int element_index);
  46. void vfs_path_free (vfs_path_t * path);
  47. int vfs_path_elements_count (const vfs_path_t * path);
  48. char *vfs_path_to_str (const vfs_path_t * path);
  49. char *vfs_path_to_str_elements_count (const vfs_path_t * path, int elements_count);
  50. char *vfs_path_to_str_flags (const vfs_path_t * vpath, int elements_count, vfs_path_flag_t flags);
  51. vfs_path_t *vfs_path_from_str (const char *path_str);
  52. vfs_path_t *vfs_path_from_str_flags (const char *path_str, vfs_path_flag_t flags);
  53. vfs_path_t *vfs_path_build_filename (const char *first_element, ...);
  54. vfs_path_t *vfs_path_append_new (const vfs_path_t * vpath, const char *first_element, ...);
  55. vfs_path_t *vfs_path_append_vpath_new (const vfs_path_t * first_vpath, ...);
  56. size_t vfs_path_tokens_count (const vfs_path_t *);
  57. char *vfs_path_tokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t length);
  58. vfs_path_t *vfs_path_vtokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t length);
  59. void vfs_path_add_element (const vfs_path_t * vpath, const vfs_path_element_t * path_element);
  60. const vfs_path_element_t *vfs_path_get_by_index (const vfs_path_t * path, int element_index);
  61. vfs_path_element_t *vfs_path_element_clone (const vfs_path_element_t * element);
  62. void vfs_path_element_free (vfs_path_element_t * element);
  63. struct vfs_class *vfs_prefix_to_class (const char *prefix);
  64. gboolean vfs_path_element_need_cleanup_converter (const vfs_path_element_t * element);
  65. char *vfs_path_serialize (const vfs_path_t * vpath, GError ** error);
  66. vfs_path_t *vfs_path_deserialize (const char *data, GError ** error);
  67. char *vfs_path_build_url_params_str (const vfs_path_element_t * element, gboolean keep_password);
  68. char *vfs_path_element_build_pretty_path_str (const vfs_path_element_t * element);
  69. size_t vfs_path_len (const vfs_path_t * vpath);
  70. int vfs_path_cmp (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
  71. int vfs_path_ncmp (const vfs_path_t * vpath1, const vfs_path_t * vpath2, size_t len);
  72. vfs_path_t *vfs_path_to_absolute (const vfs_path_t * vpath);
  73. /*** inline functions ****************************************************************************/
  74. static inline gboolean
  75. vfs_path_element_valid (const vfs_path_element_t * element)
  76. {
  77. return (element != NULL && element->class != NULL);
  78. }
  79. /* --------------------------------------------------------------------------------------------- */
  80. static inline const char *
  81. vfs_path_get_last_path_str (const vfs_path_t * vpath)
  82. {
  83. const vfs_path_element_t *element;
  84. if (vpath == NULL)
  85. return NULL;
  86. element = vfs_path_get_by_index (vpath, -1);
  87. return (element != NULL) ? element->path : NULL;
  88. }
  89. /* --------------------------------------------------------------------------------------------- */
  90. static inline const struct vfs_class *
  91. vfs_path_get_last_path_vfs (const vfs_path_t * vpath)
  92. {
  93. const vfs_path_element_t *element;
  94. if (vpath == NULL)
  95. return NULL;
  96. element = vfs_path_get_by_index (vpath, -1);
  97. return (element != NULL) ? element->class : NULL;
  98. }
  99. #endif