path.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 (gboolean relative);
  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. char *vfs_path_free (vfs_path_t * path, gboolean free_str);
  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 * vpath);
  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 (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. char *vfs_get_encoding(const char *path, ssize_t len);
  70. gboolean vfs_path_element_need_cleanup_converter (const vfs_path_element_t * element);
  71. vfs_path_t *vfs_path_change_encoding (vfs_path_t * vpath, const char *encoding);
  72. #endif
  73. char *vfs_path_serialize (const vfs_path_t * vpath, GError ** error);
  74. vfs_path_t *vfs_path_deserialize (const char *data, GError ** error);
  75. GString *vfs_path_build_url_params_str (const vfs_path_element_t * element, gboolean keep_password);
  76. GString *vfs_path_element_build_pretty_path_str (const vfs_path_element_t * element);
  77. size_t vfs_path_len (const vfs_path_t * vpath);
  78. gboolean vfs_path_equal (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
  79. gboolean vfs_path_equal_len (const vfs_path_t * vpath1, const vfs_path_t * vpath2, size_t len);
  80. vfs_path_t *vfs_path_to_absolute (const vfs_path_t * vpath);
  81. /*** inline functions ****************************************************************************/
  82. static inline gboolean
  83. vfs_path_element_valid (const vfs_path_element_t *element)
  84. {
  85. return (element != NULL && element->class != NULL);
  86. }
  87. /* --------------------------------------------------------------------------------------------- */
  88. static inline const char *
  89. vfs_path_get_last_path_str (const vfs_path_t *vpath)
  90. {
  91. const vfs_path_element_t *element;
  92. if (vpath == NULL)
  93. return NULL;
  94. element = vfs_path_get_by_index (vpath, -1);
  95. return (element != NULL) ? element->path : NULL;
  96. }
  97. /* --------------------------------------------------------------------------------------------- */
  98. static inline const struct vfs_class *
  99. vfs_path_get_last_path_vfs (const vfs_path_t *vpath)
  100. {
  101. const vfs_path_element_t *element;
  102. if (vpath == NULL)
  103. return NULL;
  104. element = vfs_path_get_by_index (vpath, -1);
  105. return (element != NULL) ? element->class : NULL;
  106. }
  107. /* --------------------------------------------------------------------------------------------- */
  108. /**
  109. * Convert vfs_path_t to string representation.
  110. *
  111. * @param vpath pointer to vfs_path_t object
  112. *
  113. * @return pointer to constant string
  114. */
  115. static inline const char *
  116. vfs_path_as_str (const vfs_path_t *vpath)
  117. {
  118. return (vpath == NULL ? NULL : vpath->str);
  119. }
  120. /* --------------------------------------------------------------------------------------------- */
  121. #endif