path.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. #define VFS_PATH(x) ((vfs_path_t *)(x))
  6. #define VFS_PATH_STDIN VFS_PATH (GINT_TO_POINTER (-1))
  7. #define VFS_PATH_STDOUT VFS_PATH (GINT_TO_POINTER (-2))
  8. #define VFS_PATH_STDERR VFS_PATH (GINT_TO_POINTER (-3))
  9. /*** enums ***************************************************************************************/
  10. typedef enum
  11. {
  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;
  20. /*** structures declarations (and typedefs of structures)*****************************************/
  21. struct vfs_class;
  22. struct vfs_url_struct;
  23. typedef struct
  24. {
  25. gboolean relative;
  26. GArray *path;
  27. char *str;
  28. } vfs_path_t;
  29. typedef struct
  30. {
  31. char *user;
  32. char *password;
  33. char *host;
  34. gboolean ipv6;
  35. int port;
  36. char *path;
  37. struct vfs_class *class;
  38. #ifdef HAVE_CHARSET
  39. char *encoding;
  40. #endif
  41. char *vfs_prefix;
  42. struct
  43. {
  44. #ifdef HAVE_CHARSET
  45. GIConv converter;
  46. #endif
  47. DIR *info;
  48. } dir;
  49. } vfs_path_element_t;
  50. /*** global variables defined in .c file *********************************************************/
  51. /*** declarations of public functions ************************************************************/
  52. vfs_path_t *vfs_path_new (void);
  53. vfs_path_t *vfs_path_clone (const vfs_path_t * vpath);
  54. void vfs_path_remove_element_by_index (vfs_path_t * vpath, int element_index);
  55. void vfs_path_free (vfs_path_t * path);
  56. int vfs_path_elements_count (const vfs_path_t * path);
  57. char *vfs_path_to_str_elements_count (const vfs_path_t * path, int elements_count);
  58. char *vfs_path_to_str_flags (const vfs_path_t * vpath, int elements_count, vfs_path_flag_t flags);
  59. vfs_path_t *vfs_path_from_str (const char *path_str);
  60. vfs_path_t *vfs_path_from_str_flags (const char *path_str, vfs_path_flag_t flags);
  61. vfs_path_t *vfs_path_build_filename (const char *first_element, ...);
  62. vfs_path_t *vfs_path_append_new (const vfs_path_t * vpath, const char *first_element, ...);
  63. vfs_path_t *vfs_path_append_vpath_new (const vfs_path_t * first_vpath, ...);
  64. size_t vfs_path_tokens_count (const vfs_path_t *);
  65. char *vfs_path_tokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t length);
  66. vfs_path_t *vfs_path_vtokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t length);
  67. void vfs_path_add_element (vfs_path_t * vpath, const vfs_path_element_t * path_element);
  68. const vfs_path_element_t *vfs_path_get_by_index (const vfs_path_t * path, int element_index);
  69. vfs_path_element_t *vfs_path_element_clone (const vfs_path_element_t * element);
  70. void vfs_path_element_free (vfs_path_element_t * element);
  71. struct vfs_class *vfs_prefix_to_class (const char *prefix);
  72. #ifdef HAVE_CHARSET
  73. gboolean vfs_path_element_need_cleanup_converter (const vfs_path_element_t * element);
  74. vfs_path_t *vfs_path_change_encoding (vfs_path_t * vpath, const char *encoding);
  75. #endif
  76. char *vfs_path_serialize (const vfs_path_t * vpath, GError ** error);
  77. vfs_path_t *vfs_path_deserialize (const char *data, GError ** error);
  78. char *vfs_path_build_url_params_str (const vfs_path_element_t * element, gboolean keep_password);
  79. char *vfs_path_element_build_pretty_path_str (const vfs_path_element_t * element);
  80. size_t vfs_path_len (const vfs_path_t * vpath);
  81. gboolean vfs_path_equal (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
  82. gboolean vfs_path_equal_len (const vfs_path_t * vpath1, const vfs_path_t * vpath2, size_t len);
  83. vfs_path_t *vfs_path_to_absolute (const vfs_path_t * vpath);
  84. /* --------------------------------------------------------------------------------------------- */
  85. /*** inline functions ****************************************************************************/
  86. /* --------------------------------------------------------------------------------------------- */
  87. /**
  88. * Is vfs_path a standard I/O stream (stdin, stdout, stderr)?.
  89. *
  90. * @param vpath pointer to vfs_path_t object
  91. *
  92. * @return TRUE if @vpath points to stdin, stdout, or stderr, FALSE otherwise.
  93. */
  94. static inline gboolean
  95. vfs_path_is_stdio (const vfs_path_t * vpath)
  96. {
  97. return (vpath == VFS_PATH_STDIN || vpath == VFS_PATH_STDOUT || vpath == VFS_PATH_STDERR);
  98. }
  99. /* --------------------------------------------------------------------------------------------- */
  100. static inline gboolean
  101. vfs_path_element_valid (const vfs_path_element_t * element)
  102. {
  103. return (element != NULL && element->class != NULL);
  104. }
  105. /* --------------------------------------------------------------------------------------------- */
  106. static inline const char *
  107. vfs_path_get_last_path_str (const vfs_path_t * vpath)
  108. {
  109. const vfs_path_element_t *element;
  110. if (vpath == NULL || vfs_path_is_stdio (vpath))
  111. return NULL;
  112. element = vfs_path_get_by_index (vpath, -1);
  113. return (element != NULL) ? element->path : NULL;
  114. }
  115. /* --------------------------------------------------------------------------------------------- */
  116. static inline const struct vfs_class *
  117. vfs_path_get_last_path_vfs (const vfs_path_t * vpath)
  118. {
  119. const vfs_path_element_t *element;
  120. if (vpath == NULL || vfs_path_is_stdio (vpath))
  121. return NULL;
  122. element = vfs_path_get_by_index (vpath, -1);
  123. return (element != NULL) ? element->class : NULL;
  124. }
  125. /* --------------------------------------------------------------------------------------------- */
  126. /**
  127. * Convert vfs_path_t to string representation.
  128. *
  129. * @param vpath pointer to vfs_path_t object
  130. *
  131. * @return pointer to constant string
  132. */
  133. static inline const char *
  134. vfs_path_as_str (const vfs_path_t * vpath)
  135. {
  136. return (vpath == NULL || vfs_path_is_stdio (vpath) ? NULL : vpath->str);
  137. }
  138. /* --------------------------------------------------------------------------------------------- */
  139. #endif