2 Virtual File System path handlers
5 The Free Software Foundation, Inc.
8 Slava Zanko <slavazanko@gmail.com>, 2011
10 This file is part of the Midnight Commander.
12 The Midnight Commander is free software: you can redistribute it
13 and/or modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation, either version 3 of the License,
15 or (at your option) any later version.
17 The Midnight Commander is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 * \brief Source: Virtual File System: path handlers
36 #include "lib/global.h"
37 #include "lib/strutil.h"
38 #include "lib/util.h" /* concat_dir_and_file */
39 #include "lib/serialize.h"
43 #include "xdirentry.h"
46 extern GPtrArray
*vfs__classes_list
;
48 /*** global variables ****************************************************************************/
50 /*** file scope macro definitions ****************************************************************/
52 /*** file scope type declarations ****************************************************************/
54 /*** file scope variables ************************************************************************/
56 /*** file scope functions ************************************************************************/
57 /* --------------------------------------------------------------------------------------------- */
60 path_magic (const char *path
)
64 return (stat (path
, &buf
) != 0);
67 /* --------------------------------------------------------------------------------------------- */
70 * Splits path extracting vfs part.
73 * \verbatim /p1#op/inpath \endverbatim
75 * \verbatim inpath,op; \endverbatim
76 * returns which vfs it is.
77 * What is left in path is p1. You still want to g_free(path), you DON'T
78 * want to free neither *inpath nor *op
81 static struct vfs_class
*
82 _vfs_split_with_semi_skip_count (char *path
, const char **inpath
, const char **op
,
87 struct vfs_class
*ret
;
90 vfs_die ("Cannot split NULL");
92 semi
= strrstr_skip_count (path
, "#", skip_count
);
94 if ((semi
== NULL
) || (!path_magic (path
)))
97 slash
= strchr (semi
, PATH_SEP
);
109 ret
= vfs_prefix_to_class (semi
+ 1);
115 *inpath
= slash
!= NULL
? slash
+ 1 : NULL
;
123 ret
= _vfs_split_with_semi_skip_count (path
, inpath
, op
, skip_count
+ 1);
127 /* --------------------------------------------------------------------------------------------- */
129 * remove //, /./ and /../
131 * @return newly allocated string
135 vfs_canon (const char *path
)
138 vfs_die ("Cannot canonicalize NULL");
140 /* Relative to current directory */
141 if (*path
!= PATH_SEP
)
143 char *result
, *local
;
145 local
= tilde_expand (path
);
146 if (*local
!= PATH_SEP
)
151 curr_dir
= vfs_get_current_dir ();
152 local
= concat_dir_and_file (curr_dir
, path
);
156 result
= vfs_canon (local
);
162 * So we have path of following form:
163 * /p1/p2#op/.././././p3#op/p4. Good luck.
168 result
= g_strdup (path
);
169 canonicalize_pathname (result
);
174 /* --------------------------------------------------------------------------------------------- */
176 * Build URL parameters (such as user:pass@host:port) from one path element object
178 * @param element path element
180 * @return newly allocated string
184 vfs_path_build_url_params_str (vfs_path_element_t
* element
)
191 buffer
= g_string_new ("");
193 if (element
->user
!= NULL
)
194 g_string_append (buffer
, element
->user
);
196 if (element
->password
!= NULL
)
198 g_string_append_c (buffer
, ':');
199 g_string_append (buffer
, element
->password
);
202 if (element
->host
!= NULL
)
204 if ((element
->user
!= NULL
) || (element
->password
!= NULL
))
205 g_string_append_c (buffer
, '@');
207 g_string_append_c (buffer
, '[');
208 g_string_append (buffer
, element
->host
);
210 g_string_append_c (buffer
, ']');
213 if ((element
->port
) != 0 && (element
->host
!= NULL
))
215 g_string_append_c (buffer
, ':');
216 g_string_append_printf (buffer
, "%d", element
->port
);
219 return g_string_free (buffer
, FALSE
);
222 /* --------------------------------------------------------------------------------------------- */
223 /** get encoding after last #enc: or NULL, if part does not contain #enc:
227 * @return newly allocated string.
231 vfs_get_encoding (const char *path
)
237 work
= g_strdup (path
);
239 /* try found #enc: */
240 semi
= g_strrstr (work
, VFS_ENCODING_PREFIX
);
242 if (semi
!= NULL
&& (semi
== work
|| *(semi
- 1) == PATH_SEP
))
244 semi
+= strlen (VFS_ENCODING_PREFIX
); /* skip "#enc:" */
245 slash
= strchr (semi
, PATH_SEP
);
249 g_strlcpy (result
, semi
, sizeof (result
));
251 return g_strdup (result
);
260 /* --------------------------------------------------------------------------------------------- */
261 /** Extract the hostname and username from the path
263 * Format of the path is [user@]hostname:port/remote-dir, e.g.:
265 * ftp://sunsite.unc.edu/pub/linux
266 * ftp://miguel@sphinx.nuclecu.unam.mx/c/nc
267 * ftp://tsx-11.mit.edu:8192/
268 * ftp://joe@foo.edu:11321/private
269 * ftp://joe:password@foo.se
271 * @param path_element is an input string to be parsed
272 * @param path is an input string to be parsed
274 * @return g_malloc()ed url info.
275 * If the user is empty, e.g. ftp://@roxanne/private, and URL_USE_ANONYMOUS
276 * is not set, then the current login name is supplied.
277 * Return value is a g_malloc()ed structure with the pathname relative to the
282 vfs_path_url_split (vfs_path_element_t
* path_element
, const char *path
)
286 char *dir
, *colon
, *inner_colon
, *at
, *rest
;
288 path_element
->port
= 0;
290 pcopy
= g_strdup (path
);
291 pend
= pcopy
+ strlen (pcopy
);
294 /* search for any possible user */
295 at
= strrchr (pcopy
, '@');
297 /* We have a username */
303 inner_colon
= strchr (pcopy
, ':');
304 if (inner_colon
!= NULL
)
308 path_element
->password
= g_strdup (inner_colon
);
312 path_element
->user
= g_strdup (pcopy
);
320 /* Check if the host comes with a port spec, if so, chop it */
322 colon
= strchr (rest
, ':');
325 colon
= strchr (++rest
, ']');
331 path_element
->ipv6
= TRUE
;
338 if (sscanf (colon
+ 1, "%d", &path_element
->port
) == 1)
340 if (path_element
->port
<= 0 || path_element
->port
>= 65536)
341 path_element
->port
= 0;
344 while (*(++colon
) != '\0')
349 path_element
->port
= 1;
352 path_element
->port
= 2;
357 path_element
->host
= g_strdup (rest
);
361 /* --------------------------------------------------------------------------------------------- */
363 * get VFS class for the given name
365 * @param class_name name of class
367 * @return pointer to class structure or NULL if class not found
370 static struct vfs_class
*
371 vfs_get_class_by_name (const char *class_name
)
375 if (class_name
== NULL
)
378 for (i
= 0; i
< vfs__classes_list
->len
; i
++)
380 struct vfs_class
*vfs
= (struct vfs_class
*) g_ptr_array_index (vfs__classes_list
, i
);
381 if ((vfs
->name
!= NULL
) && (strcmp (vfs
->name
, class_name
) == 0))
388 /* --------------------------------------------------------------------------------------------- */
390 * Check if path string contain URL-like elements
392 * @param path_str path
394 * @return TRUE if path is deprecated or FALSE otherwise
398 vfs_path_is_str_path_deprecated (const char *path_str
)
400 return strstr (path_str
, VFS_PATH_URL_DELIMITER
) == NULL
;
403 /* --------------------------------------------------------------------------------------------- */
404 /** Split path string to path elements by deprecated algorithm.
406 * @param path_str VFS-path
408 * @return pointer to newly created vfs_path_t object with filled path elements array.
412 vfs_path_from_str_deprecated_parser (char *path
)
415 vfs_path_element_t
*element
;
416 struct vfs_class
*class;
417 const char *local
, *op
;
419 vpath
= vfs_path_new ();
421 while ((class = _vfs_split_with_semi_skip_count (path
, &local
, &op
, 0)) != NULL
)
424 element
= g_new0 (vfs_path_element_t
, 1);
425 element
->class = class;
428 element
->path
= vfs_translate_path_n (local
);
430 element
->encoding
= vfs_get_encoding (local
);
431 element
->dir
.converter
=
432 (element
->encoding
!= NULL
) ? str_crt_conv_from (element
->encoding
) : INVALID_CONV
;
434 url_params
= strchr (op
, ':'); /* skip VFS prefix */
435 if (url_params
!= NULL
)
439 vfs_path_url_split (element
, url_params
);
443 element
->vfs_prefix
= g_strdup (op
);
445 vpath
->path
= g_list_prepend (vpath
->path
, element
);
449 element
= g_new0 (vfs_path_element_t
, 1);
450 element
->class = g_ptr_array_index (vfs__classes_list
, 0);
451 element
->path
= vfs_translate_path_n (path
);
453 element
->encoding
= vfs_get_encoding (path
);
454 element
->dir
.converter
=
455 (element
->encoding
!= NULL
) ? str_crt_conv_from (element
->encoding
) : INVALID_CONV
;
456 vpath
->path
= g_list_prepend (vpath
->path
, element
);
462 /* --------------------------------------------------------------------------------------------- */
463 /** Split path string to path elements by URL algorithm.
465 * @param path_str VFS-path
467 * @return pointer to newly created vfs_path_t object with filled path elements array.
471 vfs_path_from_str_uri_parser (char *path
)
474 vfs_path_element_t
*element
;
478 vpath
= vfs_path_new ();
480 while ((url_delimiter
= g_strrstr (path
, VFS_PATH_URL_DELIMITER
)) != NULL
)
482 char *vfs_prefix_start
;
483 char *real_vfs_prefix_start
= url_delimiter
;
485 struct vfs_s_subclass
*sub
= NULL
;
487 while (real_vfs_prefix_start
> path
&& *(real_vfs_prefix_start
) != PATH_SEP
)
488 real_vfs_prefix_start
--;
489 vfs_prefix_start
= real_vfs_prefix_start
;
491 if (*(vfs_prefix_start
) == PATH_SEP
)
492 vfs_prefix_start
+= 1;
494 *url_delimiter
= '\0';
496 element
= g_new0 (vfs_path_element_t
, 1);
497 element
->class = vfs_prefix_to_class (vfs_prefix_start
);
498 element
->vfs_prefix
= g_strdup (vfs_prefix_start
);
500 url_delimiter
+= strlen (VFS_PATH_URL_DELIMITER
);
501 sub
= VFSDATA (element
);
502 if (sub
!= NULL
&& sub
->flags
& VFS_S_REMOTE
)
504 slash_pointer
= strchr (url_delimiter
, PATH_SEP
);
505 if (slash_pointer
== NULL
)
507 element
->path
= g_strdup ("");
511 element
->path
= vfs_translate_path_n (slash_pointer
+ 1);
512 element
->encoding
= vfs_get_encoding (slash_pointer
);
514 *slash_pointer
= '\0';
516 vfs_path_url_split (element
, url_delimiter
);
520 element
->path
= vfs_translate_path_n (url_delimiter
);
521 element
->encoding
= vfs_get_encoding (url_delimiter
);
523 element
->dir
.converter
=
524 (element
->encoding
!= NULL
) ? str_crt_conv_from (element
->encoding
) : INVALID_CONV
;
525 vpath
->path
= g_list_prepend (vpath
->path
, element
);
527 if (real_vfs_prefix_start
> path
&& *(real_vfs_prefix_start
) == PATH_SEP
)
528 *real_vfs_prefix_start
= '\0';
530 *(real_vfs_prefix_start
+ 1) = '\0';
535 element
= g_new0 (vfs_path_element_t
, 1);
536 element
->class = g_ptr_array_index (vfs__classes_list
, 0);
537 element
->path
= vfs_translate_path_n (path
);
538 element
->encoding
= vfs_get_encoding (path
);
539 element
->dir
.converter
=
540 (element
->encoding
!= NULL
) ? str_crt_conv_from (element
->encoding
) : INVALID_CONV
;
541 vpath
->path
= g_list_prepend (vpath
->path
, element
);
547 /* --------------------------------------------------------------------------------------------- */
548 /*** public functions ****************************************************************************/
549 /* --------------------------------------------------------------------------------------------- */
551 * Convert first elements_count elements from vfs_path_t to string representation.
553 * @param vpath pointer to vfs_path_t object
554 * @param elements_count count of first elements for convert
555 * @param flags flags for parser
557 * @return pointer to newly created string.
560 #define vfs_append_from_path(appendfrom) \
562 if ((*appendfrom != PATH_SEP) && (*appendfrom != '\0') \
563 && (buffer->str[buffer->len - 1] != PATH_SEP)) \
564 g_string_append_c (buffer, PATH_SEP); \
565 g_string_append (buffer, appendfrom); \
569 vfs_path_to_str_elements_count (const vfs_path_t
* vpath
, int elements_count
)
573 GString
*recode_buffer
;
578 if (elements_count
> vfs_path_elements_count (vpath
))
579 elements_count
= vfs_path_elements_count (vpath
);
581 if (elements_count
< 0)
582 elements_count
= vfs_path_elements_count (vpath
) + elements_count
;
584 buffer
= g_string_new ("");
585 recode_buffer
= g_string_new ("");
587 for (element_index
= 0; element_index
< elements_count
; element_index
++)
589 vfs_path_element_t
*element
= vfs_path_get_by_index (vpath
, element_index
);
591 if (element
->vfs_prefix
!= NULL
)
595 if (buffer
->str
[buffer
->len
- 1] != '/')
596 g_string_append_c (buffer
, '/');
598 g_string_append (buffer
, element
->vfs_prefix
);
599 g_string_append (buffer
, VFS_PATH_URL_DELIMITER
);
601 url_str
= vfs_path_build_url_params_str (element
);
602 if (*url_str
!= '\0')
603 g_string_append (buffer
, url_str
);
608 if (vfs_path_element_need_cleanup_converter (element
))
610 if (buffer
->str
[buffer
->len
- 1] != PATH_SEP
)
611 g_string_append (buffer
, PATH_SEP_STR
);
612 g_string_append (buffer
, VFS_ENCODING_PREFIX
);
613 g_string_append (buffer
, element
->encoding
);
614 str_vfs_convert_from (element
->dir
.converter
, element
->path
, recode_buffer
);
615 vfs_append_from_path (recode_buffer
->str
);
616 g_string_set_size (recode_buffer
, 0);
620 vfs_append_from_path (element
->path
);
623 g_string_free (recode_buffer
, TRUE
);
624 return g_string_free (buffer
, FALSE
);
627 #undef vfs_append_from_path
629 /* --------------------------------------------------------------------------------------------- */
631 * Convert vfs_path_t to string representation.
633 * @param vpath pointer to vfs_path_t object
635 * @return pointer to newly created string.
639 vfs_path_to_str (const vfs_path_t
* vpath
)
641 return vfs_path_to_str_elements_count (vpath
, vfs_path_elements_count (vpath
));
644 /* --------------------------------------------------------------------------------------------- */
646 * Split path string to path elements with flags for change parce process.
648 * @param path_str VFS-path
649 * @param flags flags for parser
651 * @return pointer to newly created vfs_path_t object with filled path elements array.
655 vfs_path_from_str_flags (const char *path_str
, vfs_path_flag_t flags
)
660 if (path_str
== NULL
)
663 if ((flags
& VPF_NO_CANON
) == 0)
664 path
= vfs_canon (path_str
);
666 path
= g_strdup (path_str
);
671 if ((flags
& VPF_USE_DEPRECATED_PARSER
) != 0 && vfs_path_is_str_path_deprecated (path
))
672 vpath
= vfs_path_from_str_deprecated_parser (path
);
674 vpath
= vfs_path_from_str_uri_parser (path
);
681 /* --------------------------------------------------------------------------------------------- */
683 * Split path string to path elements.
685 * @param path_str VFS-path
687 * @return pointer to newly created vfs_path_t object with filled path elements array.
691 vfs_path_from_str (const char *path_str
)
693 return vfs_path_from_str_flags (path_str
, VPF_NONE
);
696 /* --------------------------------------------------------------------------------------------- */
698 * Create new vfs_path_t object.
700 * @return pointer to newly created vfs_path_t object.
707 vpath
= g_new0 (vfs_path_t
, 1);
711 /* --------------------------------------------------------------------------------------------- */
713 * Get count of path elements.
715 * @param vpath pointer to vfs_path_t object
717 * @return count of path elements.
721 vfs_path_elements_count (const vfs_path_t
* vpath
)
723 return (vpath
!= NULL
&& vpath
->path
!= NULL
) ? g_list_length (vpath
->path
) : 0;
726 /* --------------------------------------------------------------------------------------------- */
728 * Get one path element by index.
730 * @param vpath pointer to vfs_path_t object
731 * @param element_index element index. May have negative value (in this case count was started at the end of list).
733 * @return path element.
737 vfs_path_get_by_index (const vfs_path_t
* vpath
, int element_index
)
739 if (element_index
< 0)
740 element_index
+= vfs_path_elements_count (vpath
);
742 if (element_index
< 0)
743 vfs_die ("vfs_path_get_by_index: incorrect index!");
745 return g_list_nth_data (vpath
->path
, element_index
);
748 /* --------------------------------------------------------------------------------------------- */
750 * Clone one path element
752 * @param element pointer to vfs_path_element_t object
754 * @return Newly allocated path element
758 vfs_path_element_clone (const vfs_path_element_t
* element
)
760 vfs_path_element_t
*new_element
= g_new0 (vfs_path_element_t
, 1);
761 memcpy (new_element
, element
, sizeof (vfs_path_element_t
));
763 new_element
->user
= g_strdup (element
->user
);
764 new_element
->password
= g_strdup (element
->password
);
765 new_element
->host
= g_strdup (element
->host
);
766 new_element
->path
= g_strdup (element
->path
);
767 new_element
->encoding
= g_strdup (element
->encoding
);
768 if (vfs_path_element_need_cleanup_converter (element
) && new_element
->encoding
!= NULL
)
769 new_element
->dir
.converter
= str_crt_conv_from (new_element
->encoding
);
770 new_element
->vfs_prefix
= g_strdup (element
->vfs_prefix
);
775 /* --------------------------------------------------------------------------------------------- */
777 * Free one path element.
779 * @param element pointer to vfs_path_element_t object
784 vfs_path_element_free (vfs_path_element_t
* element
)
789 g_free (element
->user
);
790 g_free (element
->password
);
791 g_free (element
->host
);
792 g_free (element
->path
);
793 g_free (element
->encoding
);
794 g_free (element
->vfs_prefix
);
796 if (vfs_path_element_need_cleanup_converter (element
))
798 str_close_conv (element
->dir
.converter
);
804 /* --------------------------------------------------------------------------------------------- */
808 * @param vpath pointer to vfs_path_t object
810 * @return Newly allocated path object
814 vfs_path_clone (const vfs_path_t
* vpath
)
816 vfs_path_t
*new_vpath
;
817 int vpath_element_index
;
821 new_vpath
= vfs_path_new ();
822 for (vpath_element_index
= 0; vpath_element_index
< vfs_path_elements_count (vpath
);
823 vpath_element_index
++)
826 g_list_append (new_vpath
->path
,
827 vfs_path_element_clone (vfs_path_get_by_index
828 (vpath
, vpath_element_index
)));
834 /* --------------------------------------------------------------------------------------------- */
836 * Free vfs_path_t object.
838 * @param vpath pointer to vfs_path_t object
843 vfs_path_free (vfs_path_t
* path
)
847 g_list_foreach (path
->path
, (GFunc
) vfs_path_element_free
, NULL
);
848 g_list_free (path
->path
);
852 /* --------------------------------------------------------------------------------------------- */
854 * Remove one path element by index
856 * @param vpath pointer to vfs_path_t object
857 * @param element_index element index. May have negative value (in this case count was started at the end of list).
862 vfs_path_remove_element_by_index (vfs_path_t
* vpath
, int element_index
)
864 vfs_path_element_t
*element
;
866 if ((vpath
== NULL
) || (vfs_path_elements_count (vpath
) == 1))
869 if (element_index
< 0)
870 element_index
= vfs_path_elements_count (vpath
) + element_index
;
872 element
= g_list_nth_data (vpath
->path
, element_index
);
873 vpath
->path
= g_list_remove (vpath
->path
, element
);
874 vfs_path_element_free (element
);
877 /* --------------------------------------------------------------------------------------------- */
878 /** Return VFS class for the given prefix */
881 vfs_prefix_to_class (const char *prefix
)
885 /* Avoid first class (localfs) that would accept any prefix */
886 for (i
= 1; i
< vfs__classes_list
->len
; i
++)
888 struct vfs_class
*vfs
= (struct vfs_class
*) g_ptr_array_index (vfs__classes_list
, i
);
889 if (vfs
->which
!= NULL
)
891 if (vfs
->which (vfs
, prefix
) == -1)
896 if (vfs
->prefix
!= NULL
&& strncmp (prefix
, vfs
->prefix
, strlen (vfs
->prefix
)) == 0)
903 /* --------------------------------------------------------------------------------------------- */
905 * Check if need cleanup charset converter for vfs_path_element_t
907 * @param element part of path
909 * @return TRUE if need cleanup converter or FALSE otherwise
913 vfs_path_element_need_cleanup_converter (const vfs_path_element_t
* element
)
915 return (element
->dir
.converter
!= str_cnv_from_term
&& element
->dir
.converter
!= INVALID_CONV
);
918 /* --------------------------------------------------------------------------------------------- */
920 * Serialize vfs_path_t object to string
922 * @param vpath data for serialization
923 * @param error contain pointer to object for handle error code and message
925 * @return serialized vpath as newly allocated string
929 vfs_path_serialize (const vfs_path_t
* vpath
, GError
** error
)
931 mc_config_t
*cpath
= mc_config_init (NULL
);
932 ssize_t element_index
;
935 if ((vpath
== NULL
) || (vfs_path_elements_count (vpath
) == 0))
937 g_set_error (error
, MC_ERROR
, -1, "vpath object is empty");
941 for (element_index
= 0; element_index
< vfs_path_elements_count (vpath
); element_index
++)
943 char *groupname
= g_strdup_printf ("path-element-%zd", element_index
);
944 vfs_path_element_t
*element
= vfs_path_get_by_index (vpath
, element_index
);
946 /* convert one element to config group */
948 mc_config_set_string_raw (cpath
, groupname
, "path", element
->path
);
949 mc_config_set_string_raw (cpath
, groupname
, "class-name", element
->class->name
);
950 mc_config_set_string_raw (cpath
, groupname
, "encoding", element
->encoding
);
952 mc_config_set_string_raw (cpath
, groupname
, "vfs_prefix", element
->vfs_prefix
);
954 mc_config_set_string_raw (cpath
, groupname
, "user", element
->user
);
955 mc_config_set_string_raw (cpath
, groupname
, "password", element
->password
);
956 mc_config_set_string_raw (cpath
, groupname
, "host", element
->host
);
957 if (element
->port
!= 0)
958 mc_config_set_int (cpath
, groupname
, "port", element
->port
);
963 ret_value
= mc_serialize_config (cpath
, error
);
964 mc_config_deinit (cpath
);
968 /* --------------------------------------------------------------------------------------------- */
970 * Deserialize string to vfs_path_t object
972 * @param data data for serialization
973 * @param error contain pointer to object for handle error code and message
975 * @return newly allocated vfs_path_t object
979 vfs_path_deserialize (const char *data
, GError
** error
)
981 mc_config_t
*cpath
= mc_deserialize_config (data
, error
);
982 size_t element_index
= 0;
988 vpath
= vfs_path_new ();
992 vfs_path_element_t
*element
;
996 groupname
= g_strdup_printf ("path-element-%zd", element_index
);
997 if (!mc_config_has_group (cpath
, groupname
))
1003 element
= g_new0 (vfs_path_element_t
, 1);
1005 cfg_value
= mc_config_get_string_raw (cpath
, groupname
, "class-name", NULL
);
1006 element
->class = vfs_get_class_by_name (cfg_value
);
1007 if (element
->class == NULL
)
1010 vfs_path_free (vpath
);
1011 g_set_error (error
, MC_ERROR
, -1, "Unable to find VFS class by name '%s'", cfg_value
);
1013 mc_config_deinit (cpath
);
1018 element
->path
= mc_config_get_string_raw (cpath
, groupname
, "path", NULL
);
1019 element
->encoding
= mc_config_get_string_raw (cpath
, groupname
, "encoding", NULL
);
1020 element
->dir
.converter
=
1021 (element
->encoding
!= NULL
) ? str_crt_conv_from (element
->encoding
) : INVALID_CONV
;
1023 element
->vfs_prefix
= mc_config_get_string_raw (cpath
, groupname
, "vfs_prefix", NULL
);
1025 element
->user
= mc_config_get_string_raw (cpath
, groupname
, "user", NULL
);
1026 element
->password
= mc_config_get_string_raw (cpath
, groupname
, "password", NULL
);
1027 element
->host
= mc_config_get_string_raw (cpath
, groupname
, "host", NULL
);
1028 element
->port
= mc_config_get_int (cpath
, groupname
, "port", 0);
1030 vpath
->path
= g_list_append (vpath
->path
, element
);
1036 mc_config_deinit (cpath
);
1037 if (vfs_path_elements_count (vpath
) == 0)
1039 vfs_path_free (vpath
);
1040 g_set_error (error
, MC_ERROR
, -1, "No any path elements found");
1047 /* --------------------------------------------------------------------------------------------- */
1049 * Build vfs_path_t object from arguments.
1051 * return newly allocated vfs_path_t object
1055 vfs_path_build_filename (const char *first_element
, ...)
1061 if (first_element
== NULL
)
1064 va_start (args
, first_element
);
1065 str_path
= mc_build_filenamev (first_element
, args
);
1067 vpath
= vfs_path_from_str (str_path
);
1072 /* --------------------------------------------------------------------------------------------- */
1075 vfs_path_append_new (const vfs_path_t
* vpath
, const char *first_element
, ...)
1078 char *str_path
, *result_str
;
1079 vfs_path_t
*ret_vpath
;
1081 if (vpath
== NULL
|| first_element
== NULL
)
1084 va_start (args
, first_element
);
1085 str_path
= mc_build_filenamev (first_element
, args
);
1088 result_str
= vfs_path_to_str (vpath
);
1089 ret_vpath
= vfs_path_build_filename (result_str
, str_path
, NULL
);
1090 g_free (result_str
);
1097 /* --------------------------------------------------------------------------------------------- */