path.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. char *str;
  24. } vfs_path_t;
  25. typedef struct
  26. {
  27. char *user;
  28. char *password;
  29. char *host;
  30. gboolean ipv6;
  31. int port;
  32. char *path;
  33. struct vfs_class *class;
  34. #ifdef HAVE_CHARSET
  35. char *encoding;
  36. #endif
  37. char *vfs_prefix;
  38. struct
  39. {
  40. #ifdef HAVE_CHARSET
  41. GIConv converter;
  42. #endif
  43. DIR *info;
  44. } dir;
  45. } vfs_path_element_t;
  46. /*** global variables defined in .c file *********************************************************/
  47. /*** declarations of public functions ************************************************************/
  48. vfs_path_t *vfs_path_new (void);
  49. vfs_path_t *vfs_path_clone (const vfs_path_t * vpath);
  50. void vfs_path_remove_element_by_index (vfs_path_t * vpath, int element_index);
  51. void vfs_path_free (vfs_path_t * path);
  52. int vfs_path_elements_count (const vfs_path_t * path);
  53. char *vfs_path_to_str_elements_count (const vfs_path_t * path, int elements_count);
  54. char *vfs_path_to_str_flags (const vfs_path_t * vpath, int elements_count, vfs_path_flag_t flags);
  55. vfs_path_t *vfs_path_from_str (const char *path_str);
  56. vfs_path_t *vfs_path_from_str_flags (const char *path_str, vfs_path_flag_t flags);
  57. vfs_path_t *vfs_path_build_filename (const char *first_element, ...);
  58. vfs_path_t *vfs_path_append_new (const vfs_path_t * vpath, const char *first_element, ...);
  59. vfs_path_t *vfs_path_append_vpath_new (const vfs_path_t * first_vpath, ...);
  60. size_t vfs_path_tokens_count (const vfs_path_t *);
  61. char *vfs_path_tokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t length);
  62. vfs_path_t *vfs_path_vtokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t length);
  63. void vfs_path_add_element (const vfs_path_t * vpath, const vfs_path_element_t * path_element);
  64. const vfs_path_element_t *vfs_path_get_by_index (const vfs_path_t * path, int element_index);
  65. vfs_path_element_t *vfs_path_element_clone (const vfs_path_element_t * element);
  66. void vfs_path_element_free (vfs_path_element_t * element);
  67. struct vfs_class *vfs_prefix_to_class (const char *prefix);
  68. #ifdef HAVE_CHARSET
  69. gboolean vfs_path_element_need_cleanup_converter (const vfs_path_element_t * element);
  70. vfs_path_t *vfs_path_change_encoding (vfs_path_t * vpath, const char *encoding);
  71. #endif
  72. char *vfs_path_serialize (const vfs_path_t * vpath, GError ** error);
  73. vfs_path_t *vfs_path_deserialize (const char *data, GError ** error);
  74. char *vfs_path_build_url_params_str (const vfs_path_element_t * element, gboolean keep_password);
  75. char *vfs_path_element_build_pretty_path_str (const vfs_path_element_t * element);
  76. size_t vfs_path_len (const vfs_path_t * vpath);
  77. gboolean vfs_path_equal (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
  78. gboolean vfs_path_equal_len (const vfs_path_t * vpath1, const vfs_path_t * vpath2, size_t len);
  79. vfs_path_t *vfs_path_to_absolute (const vfs_path_t * vpath);
  80. /*** inline functions ****************************************************************************/
  81. static inline gboolean
  82. vfs_path_element_valid (const vfs_path_element_t * element)
  83. {
  84. return (element != NULL && element->class != NULL);
  85. }
  86. /* --------------------------------------------------------------------------------------------- */
  87. static inline const char *
  88. vfs_path_get_last_path_str (const vfs_path_t * vpath)
  89. {
  90. const vfs_path_element_t *element;
  91. if (vpath == NULL)
  92. return NULL;
  93. element = vfs_path_get_by_index (vpath, -1);
  94. return (element != NULL) ? element->path : NULL;
  95. }
  96. /* --------------------------------------------------------------------------------------------- */
  97. static inline const struct vfs_class *
  98. vfs_path_get_last_path_vfs (const vfs_path_t * vpath)
  99. {
  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->class : NULL;
  105. }
  106. /* --------------------------------------------------------------------------------------------- */
  107. /**
  108. * Convert vfs_path_t to string representation.
  109. *
  110. * @param vpath pointer to vfs_path_t object
  111. *
  112. * @return pointer to constant string
  113. */
  114. static inline const char *
  115. vfs_path_as_str (const vfs_path_t * vpath)
  116. {
  117. return (vpath == NULL ? NULL : vpath->str);
  118. }
  119. /* --------------------------------------------------------------------------------------------- */
  120. #endif