Strings simplification for translations
[vlc.git] / modules / access / nfs.c
blob1f323790949c9d298962774700bc2c415c8a1055
1 /*****************************************************************************
2 * nfs.c: NFS VLC access plug-in
3 *****************************************************************************
4 * Copyright © 2016 VLC authors, VideoLAN and VideoLabs
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include <assert.h>
26 #include <errno.h>
27 #include <stdint.h>
28 #include <stdlib.h>
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #include <fcntl.h>
32 #ifdef HAVE_POLL
33 # include <poll.h>
34 #endif
36 #include <vlc_common.h>
37 #include <vlc_access.h>
38 #include <vlc_dialog.h>
39 #include <vlc_input_item.h>
40 #include <vlc_plugin.h>
41 #include <vlc_url.h>
42 #include <vlc_interrupt.h>
44 #include <nfsc/libnfs.h>
45 #include <nfsc/libnfs-raw.h>
46 #include <nfsc/libnfs-raw-nfs.h>
47 #include <nfsc/libnfs-raw-mount.h>
49 #define AUTO_GUID_TEXT N_("Set NFS uid/guid automatically")
50 #define AUTO_GUID_LONGTEXT N_("If uid/gid are not specified in " \
51 "the url, VLC will automatically set a uid/gid.")
53 static int Open(vlc_object_t *);
54 static void Close(vlc_object_t *);
56 vlc_module_begin()
57 set_shortname(N_("NFS"))
58 set_description(N_("NFS input"))
59 set_category(CAT_INPUT)
60 set_subcategory(SUBCAT_INPUT_ACCESS)
61 add_bool("nfs-auto-guid", true, AUTO_GUID_TEXT, AUTO_GUID_LONGTEXT, true)
62 set_capability("access", 2)
63 add_shortcut("nfs")
64 set_callbacks(Open, Close)
65 vlc_module_end()
67 struct access_sys_t
69 struct rpc_context * p_mount; /* used to to get exports mount point */
70 struct nfs_context * p_nfs;
71 struct nfs_url * p_nfs_url;
72 struct nfs_stat_64 stat;
73 struct nfsfh * p_nfsfh;
74 struct nfsdir * p_nfsdir;
75 vlc_url_t encoded_url;
76 char * psz_url_decoded;
77 char * psz_url_decoded_slash;
78 bool b_eof;
79 bool b_error;
80 bool b_auto_guid;
82 union {
83 struct
85 char ** ppsz_names;
86 int i_count;
87 } exports;
88 struct
90 uint8_t *p_buf;
91 size_t i_len;
92 } read;
93 struct
95 bool b_done;
96 } seek;
97 } res;
100 static bool
101 nfs_check_status(stream_t *p_access, int i_status, const char *psz_error,
102 const char *psz_func)
104 access_sys_t *sys = p_access->p_sys;
106 if (i_status < 0)
108 if (i_status != -EINTR)
110 msg_Err(p_access, "%s failed: %d, '%s'", psz_func, i_status,
111 psz_error);
112 if (!sys->b_error)
113 vlc_dialog_display_error(p_access,
114 _("NFS operation failed"), "%s",
115 psz_error);
117 else
118 msg_Warn(p_access, "%s interrupted", psz_func);
119 sys->b_error = true;
120 return true;
122 else
123 return false;
125 #define NFS_CHECK_STATUS(p_access, i_status, p_data) \
126 nfs_check_status(p_access, i_status, (const char *)p_data, __func__)
128 static int
129 vlc_rpc_mainloop(stream_t *p_access, struct rpc_context *p_rpc_ctx,
130 bool (*pf_until_cb)(stream_t *))
132 access_sys_t *p_sys = p_access->p_sys;
134 while (!p_sys->b_error && !pf_until_cb(p_access))
136 struct pollfd p_fds[1];
137 int i_ret;
138 p_fds[0].fd = rpc_get_fd(p_rpc_ctx);
139 p_fds[0].events = rpc_which_events(p_rpc_ctx);
141 if ((i_ret = vlc_poll_i11e(p_fds, 1, -1)) < 0)
143 if (errno == EINTR)
144 msg_Warn(p_access, "vlc_poll_i11e interrupted");
145 else
146 msg_Err(p_access, "vlc_poll_i11e failed");
147 p_sys->b_error = true;
149 else if (i_ret > 0 && p_fds[0].revents
150 && rpc_service(p_rpc_ctx, p_fds[0].revents) < 0)
152 msg_Err(p_access, "nfs_service failed");
153 p_sys->b_error = true;
156 return p_sys->b_error ? -1 : 0;
159 static int
160 vlc_nfs_mainloop(stream_t *p_access, bool (*pf_until_cb)(stream_t *))
162 access_sys_t *p_sys = p_access->p_sys;
163 assert(p_sys->p_nfs != NULL);
164 return vlc_rpc_mainloop(p_access, nfs_get_rpc_context(p_sys->p_nfs),
165 pf_until_cb);
168 static int
169 vlc_mount_mainloop(stream_t *p_access, bool (*pf_until_cb)(stream_t *))
171 access_sys_t *p_sys = p_access->p_sys;
172 assert(p_sys->p_mount != NULL);
173 return vlc_rpc_mainloop(p_access, p_sys->p_mount, pf_until_cb);
176 static void
177 nfs_read_cb(int i_status, struct nfs_context *p_nfs, void *p_data,
178 void *p_private_data)
180 VLC_UNUSED(p_nfs);
181 stream_t *p_access = p_private_data;
182 access_sys_t *p_sys = p_access->p_sys;
183 assert(p_sys->p_nfs == p_nfs);
184 if (NFS_CHECK_STATUS(p_access, i_status, p_data))
185 return;
187 if (i_status == 0)
188 p_sys->b_eof = true;
189 else
191 p_sys->res.read.i_len = i_status;
192 memcpy(p_sys->res.read.p_buf, p_data, i_status);
196 static bool
197 nfs_read_finished_cb(stream_t *p_access)
199 access_sys_t *p_sys = p_access->p_sys;
200 return p_sys->res.read.i_len > 0 || p_sys->b_eof;
203 static ssize_t
204 FileRead(stream_t *p_access, void *p_buf, size_t i_len)
206 access_sys_t *p_sys = p_access->p_sys;
208 if (p_sys->b_eof)
209 return 0;
211 p_sys->res.read.i_len = 0;
212 p_sys->res.read.p_buf = p_buf;
213 if (nfs_read_async(p_sys->p_nfs, p_sys->p_nfsfh, i_len, nfs_read_cb,
214 p_access) < 0)
216 msg_Err(p_access, "nfs_read_async failed");
217 return -1;
220 if (vlc_nfs_mainloop(p_access, nfs_read_finished_cb) < 0)
221 return -1;
223 return p_sys->res.read.i_len;
226 static void
227 nfs_seek_cb(int i_status, struct nfs_context *p_nfs, void *p_data,
228 void *p_private_data)
230 VLC_UNUSED(p_nfs);
231 stream_t *p_access = p_private_data;
232 access_sys_t *p_sys = p_access->p_sys;
233 assert(p_sys->p_nfs == p_nfs);
234 (void) p_data;
235 if (NFS_CHECK_STATUS(p_access, i_status, p_data))
236 return;
238 p_sys->res.seek.b_done = true;
241 static bool
242 nfs_seek_finished_cb(stream_t *p_access)
244 access_sys_t *p_sys = p_access->p_sys;
245 return p_sys->res.seek.b_done;
248 static int
249 FileSeek(stream_t *p_access, uint64_t i_pos)
251 access_sys_t *p_sys = p_access->p_sys;
253 p_sys->res.seek.b_done = false;
254 if (nfs_lseek_async(p_sys->p_nfs, p_sys->p_nfsfh, i_pos, SEEK_SET,
255 nfs_seek_cb, p_access) < 0)
257 msg_Err(p_access, "nfs_seek_async failed");
258 return VLC_EGENERIC;
261 if (vlc_nfs_mainloop(p_access, nfs_seek_finished_cb) < 0)
262 return VLC_EGENERIC;
264 return VLC_SUCCESS;
267 static int
268 FileControl(stream_t *p_access, int i_query, va_list args)
270 access_sys_t *p_sys = p_access->p_sys;
272 switch (i_query)
274 case STREAM_CAN_SEEK:
275 *va_arg(args, bool *) = true;
276 break;
278 case STREAM_CAN_FASTSEEK:
279 *va_arg(args, bool *) = false;
280 break;
282 case STREAM_CAN_PAUSE:
283 case STREAM_CAN_CONTROL_PACE:
284 *va_arg(args, bool *) = true;
285 break;
287 case STREAM_GET_SIZE:
289 *va_arg(args, uint64_t *) = p_sys->stat.nfs_size;
290 break;
293 case STREAM_GET_PTS_DELAY:
294 *va_arg(args, int64_t *) = var_InheritInteger(p_access,
295 "network-caching");
296 break;
298 case STREAM_SET_PAUSE_STATE:
299 break;
301 default:
302 return VLC_EGENERIC;
304 return VLC_SUCCESS;
307 static char *
308 NfsGetUrl(vlc_url_t *p_url, const char *psz_file)
310 /* nfs://<psz_host><psz_path><psz_file>?<psz_option> */
311 char *psz_url;
312 if (asprintf(&psz_url, "nfs://%s%s%s%s%s%s", p_url->psz_host,
313 p_url->psz_path != NULL ? p_url->psz_path : "",
314 p_url->psz_path != NULL && p_url->psz_path[0] != '\0' &&
315 p_url->psz_path[strlen(p_url->psz_path) - 1] != '/' ? "/" : "",
316 psz_file,
317 p_url->psz_option != NULL ? "?" : "",
318 p_url->psz_option != NULL ? p_url->psz_option : "") == -1)
319 return NULL;
320 else
321 return psz_url;
324 static int
325 DirRead(stream_t *p_access, input_item_node_t *p_node)
327 access_sys_t *p_sys = p_access->p_sys;
328 struct nfsdirent *p_nfsdirent;
329 int i_ret = VLC_SUCCESS;
330 assert(p_sys->p_nfsdir);
332 struct vlc_readdir_helper rdh;
333 vlc_readdir_helper_init(&rdh, p_access, p_node);
335 while (i_ret == VLC_SUCCESS
336 && (p_nfsdirent = nfs_readdir(p_sys->p_nfs, p_sys->p_nfsdir)) != NULL)
338 char *psz_name_encoded = vlc_uri_encode(p_nfsdirent->name);
339 if (psz_name_encoded == NULL)
341 i_ret = VLC_ENOMEM;
342 break;
344 char *psz_url = NfsGetUrl(&p_sys->encoded_url, psz_name_encoded);
345 free(psz_name_encoded);
346 if (psz_url == NULL)
348 i_ret = VLC_ENOMEM;
349 break;
352 int i_type;
353 switch (p_nfsdirent->type)
355 case NF3REG:
356 i_type = ITEM_TYPE_FILE;
357 break;
358 case NF3DIR:
359 i_type = ITEM_TYPE_DIRECTORY;
360 break;
361 default:
362 i_type = ITEM_TYPE_UNKNOWN;
364 i_ret = vlc_readdir_helper_additem(&rdh, psz_url, NULL, p_nfsdirent->name,
365 i_type, ITEM_NET);
366 free(psz_url);
369 vlc_readdir_helper_finish(&rdh, i_ret == VLC_SUCCESS);
371 return i_ret;
374 static int
375 MountRead(stream_t *p_access, input_item_node_t *p_node)
377 access_sys_t *p_sys = p_access->p_sys;
378 assert(p_sys->p_mount != NULL && p_sys->res.exports.i_count >= 0);
379 int i_ret = VLC_SUCCESS;
381 struct vlc_readdir_helper rdh;
382 vlc_readdir_helper_init(&rdh, p_access, p_node);
384 for (int i = 0; i < p_sys->res.exports.i_count && i_ret == VLC_SUCCESS; ++i)
386 char *psz_name = p_sys->res.exports.ppsz_names[i];
388 char *psz_url = NfsGetUrl(&p_sys->encoded_url, psz_name);
389 if (psz_url == NULL)
391 i_ret = VLC_ENOMEM;
392 break;
394 i_ret = vlc_readdir_helper_additem(&rdh, psz_url, NULL, psz_name,
395 ITEM_TYPE_DIRECTORY, ITEM_NET);
396 free(psz_url);
399 vlc_readdir_helper_finish(&rdh, i_ret == VLC_SUCCESS);
401 return i_ret;
404 static void
405 nfs_opendir_cb(int i_status, struct nfs_context *p_nfs, void *p_data,
406 void *p_private_data)
408 VLC_UNUSED(p_nfs);
409 stream_t *p_access = p_private_data;
410 access_sys_t *p_sys = p_access->p_sys;
411 assert(p_sys->p_nfs == p_nfs);
412 if (NFS_CHECK_STATUS(p_access, i_status, p_data))
413 return;
415 p_sys->p_nfsdir = p_data;
418 static void
419 nfs_open_cb(int i_status, struct nfs_context *p_nfs, void *p_data,
420 void *p_private_data)
422 VLC_UNUSED(p_nfs);
423 stream_t *p_access = p_private_data;
424 access_sys_t *p_sys = p_access->p_sys;
425 assert(p_sys->p_nfs == p_nfs);
426 if (NFS_CHECK_STATUS(p_access, i_status, p_data))
427 return;
429 p_sys->p_nfsfh = p_data;
432 static void
433 nfs_stat64_cb(int i_status, struct nfs_context *p_nfs, void *p_data,
434 void *p_private_data)
436 VLC_UNUSED(p_nfs);
437 stream_t *p_access = p_private_data;
438 access_sys_t *p_sys = p_access->p_sys;
439 assert(p_sys->p_nfs == p_nfs);
440 if (NFS_CHECK_STATUS(p_access, i_status, p_data))
441 return;
443 struct nfs_stat_64 *p_stat = p_data;
444 p_sys->stat = *p_stat;
446 if (p_sys->b_auto_guid)
448 nfs_set_uid(p_sys->p_nfs, p_sys->stat.nfs_uid);
449 nfs_set_gid(p_sys->p_nfs, p_sys->stat.nfs_gid);
452 if (S_ISDIR(p_sys->stat.nfs_mode))
454 msg_Dbg(p_access, "nfs_opendir: '%s'", p_sys->p_nfs_url->file);
455 if (nfs_opendir_async(p_sys->p_nfs, p_sys->p_nfs_url->file,
456 nfs_opendir_cb, p_access) != 0)
458 msg_Err(p_access, "nfs_opendir_async failed");
459 p_sys->b_error = true;
462 else if (S_ISREG(p_sys->stat.nfs_mode))
464 msg_Dbg(p_access, "nfs_open: '%s'", p_sys->p_nfs_url->file);
465 if (nfs_open_async(p_sys->p_nfs, p_sys->p_nfs_url->file, O_RDONLY,
466 nfs_open_cb, p_access) < 0)
468 msg_Err(p_access, "nfs_open_async failed");
469 p_sys->b_error = true;
472 else
474 msg_Err(p_access, "nfs_stat64_cb: file type not handled");
475 p_sys->b_error = true;
479 static void
480 nfs_mount_cb(int i_status, struct nfs_context *p_nfs, void *p_data,
481 void *p_private_data)
483 VLC_UNUSED(p_nfs);
484 stream_t *p_access = p_private_data;
485 access_sys_t *p_sys = p_access->p_sys;
486 assert(p_sys->p_nfs == p_nfs);
487 (void) p_data;
489 /* If a directory url doesn't end with '/', there is no way to know which
490 * part of the url is the export point and which part is the path. An
491 * example with "nfs://myhost/mnt/data": we can't know if /mnt or /mnt/data
492 * is the export point. Therefore, in case of EACCES error, retry to mount
493 * the url by adding a '/' to the decoded path. */
494 if (i_status == -EACCES && p_sys->psz_url_decoded_slash == NULL)
496 vlc_url_t url;
497 vlc_UrlParse(&url, p_sys->psz_url_decoded);
498 if (url.psz_path == NULL || url.psz_path[0] == '\0'
499 || url.psz_path[strlen(url.psz_path) - 1] == '/'
500 || (p_sys->psz_url_decoded_slash = NfsGetUrl(&url, "/")) == NULL)
502 vlc_UrlClean(&url);
503 NFS_CHECK_STATUS(p_access, i_status, p_data);
504 return;
506 else
508 vlc_UrlClean(&url);
509 msg_Warn(p_access, "trying to mount '%s' again by adding a '/'",
510 p_access->psz_url);
511 return;
515 if (NFS_CHECK_STATUS(p_access, i_status, p_data))
516 return;
518 if (nfs_stat64_async(p_sys->p_nfs, p_sys->p_nfs_url->file, nfs_stat64_cb,
519 p_access) < 0)
521 msg_Err(p_access, "nfs_stat64_async failed");
522 p_sys->b_error = true;
526 static bool
527 nfs_mount_open_finished_cb(stream_t *p_access)
529 access_sys_t *p_sys = p_access->p_sys;
530 return p_sys->p_nfsfh != NULL || p_sys->p_nfsdir != NULL
531 || p_sys->psz_url_decoded_slash != NULL;
534 static bool
535 nfs_mount_open_slash_finished_cb(stream_t *p_access)
537 access_sys_t *p_sys = p_access->p_sys;
538 return p_sys->p_nfsfh != NULL || p_sys->p_nfsdir != NULL;
541 static void
542 mount_export_cb(struct rpc_context *p_ctx, int i_status, void *p_data,
543 void *p_private_data)
545 VLC_UNUSED(p_ctx);
546 stream_t *p_access = p_private_data;
547 access_sys_t *p_sys = p_access->p_sys;
548 assert(p_sys->p_mount == p_ctx);
549 if (NFS_CHECK_STATUS(p_access, i_status, p_data))
550 return;
552 exports p_export = *(exports *)p_data;
553 p_sys->res.exports.i_count = 0;
555 /* Dup the export linked list into an array of const char * */
556 while (p_export != NULL)
558 p_sys->res.exports.i_count++;
559 p_export = p_export->ex_next;
561 if (p_sys->res.exports.i_count == 0)
562 return;
564 p_sys->res.exports.ppsz_names = calloc(p_sys->res.exports.i_count,
565 sizeof(char *));
566 if (p_sys->res.exports.ppsz_names == NULL)
568 p_sys->b_error = true;
569 return;
572 p_export = *(exports *)p_data;
573 unsigned int i_idx = 0;
574 while (p_export != NULL)
576 p_sys->res.exports.ppsz_names[i_idx] = strdup(p_export->ex_dir);
577 if (p_sys->res.exports.ppsz_names[i_idx] == NULL)
579 for (unsigned int i = 0; i < i_idx; ++i)
580 free(p_sys->res.exports.ppsz_names[i]);
581 free(p_sys->res.exports.ppsz_names);
582 p_sys->res.exports.ppsz_names = NULL;
583 p_sys->res.exports.i_count = 0;
584 p_sys->b_error = true;
585 return;
587 i_idx++;
588 p_export = p_export->ex_next;
592 static bool
593 mount_getexports_finished_cb(stream_t *p_access)
595 access_sys_t *p_sys = p_access->p_sys;
596 return p_sys->res.exports.i_count != -1;
599 static int
600 NfsInit(stream_t *p_access, const char *psz_url_decoded)
602 access_sys_t *p_sys = p_access->p_sys;
603 p_sys->p_nfs = nfs_init_context();
604 if (p_sys->p_nfs == NULL)
606 msg_Err(p_access, "nfs_init_context failed");
607 return -1;
610 p_sys->p_nfs_url = nfs_parse_url_incomplete(p_sys->p_nfs, psz_url_decoded);
611 if (p_sys->p_nfs_url == NULL || p_sys->p_nfs_url->server == NULL)
613 msg_Err(p_access, "nfs_parse_url_incomplete failed: '%s'",
614 nfs_get_error(p_sys->p_nfs));
615 return -1;
617 return 0;
620 static int
621 Open(vlc_object_t *p_obj)
623 stream_t *p_access = (stream_t *)p_obj;
624 access_sys_t *p_sys = vlc_obj_calloc(p_obj, 1, sizeof (*p_sys));
626 if (unlikely(p_sys == NULL))
627 return VLC_ENOMEM;
628 p_access->p_sys = p_sys;
630 p_sys->b_auto_guid = var_InheritBool(p_obj, "nfs-auto-guid");
632 /* nfs_* functions need a decoded url */
633 p_sys->psz_url_decoded = vlc_uri_decode_duplicate(p_access->psz_url);
634 if (p_sys->psz_url_decoded == NULL)
635 goto error;
637 /* Parse the encoded URL */
638 vlc_UrlParse(&p_sys->encoded_url, p_access->psz_url);
639 if (p_sys->encoded_url.psz_option)
641 if (strstr(p_sys->encoded_url.psz_option, "uid")
642 || strstr(p_sys->encoded_url.psz_option, "gid"))
643 p_sys->b_auto_guid = false;
646 if (NfsInit(p_access, p_sys->psz_url_decoded) == -1)
647 goto error;
649 if (p_sys->p_nfs_url->path != NULL && p_sys->p_nfs_url->file != NULL)
651 /* The url has a valid path and file, mount the path and open/opendir
652 * the file */
653 msg_Dbg(p_access, "nfs_mount: server: '%s', path: '%s'",
654 p_sys->p_nfs_url->server, p_sys->p_nfs_url->path);
656 if (nfs_mount_async(p_sys->p_nfs, p_sys->p_nfs_url->server,
657 p_sys->p_nfs_url->path, nfs_mount_cb, p_access) < 0)
659 msg_Err(p_access, "nfs_mount_async failed");
660 goto error;
663 if (vlc_nfs_mainloop(p_access, nfs_mount_open_finished_cb) < 0)
664 goto error;
666 if (p_sys->psz_url_decoded_slash != NULL)
668 /* Retry to mount by adding a '/' to the path, see comment in
669 * nfs_mount_cb */
670 nfs_destroy_url(p_sys->p_nfs_url);
671 nfs_destroy_context(p_sys->p_nfs);
672 p_sys->p_nfs_url = NULL;
673 p_sys->p_nfs = NULL;
675 if (NfsInit(p_access, p_sys->psz_url_decoded_slash) == -1
676 || p_sys->p_nfs_url->path == NULL || p_sys->p_nfs_url->file == NULL)
677 goto error;
679 if (nfs_mount_async(p_sys->p_nfs, p_sys->p_nfs_url->server,
680 p_sys->p_nfs_url->path, nfs_mount_cb, p_access) < 0)
682 msg_Err(p_access, "nfs_mount_async failed");
683 goto error;
686 if (vlc_nfs_mainloop(p_access, nfs_mount_open_slash_finished_cb) < 0)
687 goto error;
690 if (p_sys->p_nfsfh != NULL)
692 p_access->pf_read = FileRead;
693 p_access->pf_seek = FileSeek;
694 p_access->pf_control = FileControl;
696 else if (p_sys->p_nfsdir != NULL)
698 p_access->pf_readdir = DirRead;
699 p_access->pf_seek = NULL;
700 p_access->pf_control = access_vaDirectoryControlHelper;
702 else
703 vlc_assert_unreachable();
705 else
707 /* url is just a server: fetch exports point */
708 nfs_destroy_context(p_sys->p_nfs);
709 p_sys->p_nfs = NULL;
711 p_sys->p_mount = rpc_init_context();
712 if (p_sys->p_mount == NULL)
714 msg_Err(p_access, "rpc_init_context failed");
715 goto error;
718 p_sys->res.exports.ppsz_names = NULL;
719 p_sys->res.exports.i_count = -1;
721 if (mount_getexports_async(p_sys->p_mount, p_sys->p_nfs_url->server,
722 mount_export_cb, p_access) < 0)
724 msg_Err(p_access, "mount_getexports_async failed");
725 goto error;
728 if (vlc_mount_mainloop(p_access, mount_getexports_finished_cb) < 0)
729 goto error;
731 p_access->pf_readdir = MountRead;
732 p_access->pf_seek = NULL;
733 p_access->pf_control = access_vaDirectoryControlHelper;
736 return VLC_SUCCESS;
738 error:
739 Close(p_obj);
740 return VLC_EGENERIC;
743 static void
744 Close(vlc_object_t *p_obj)
746 stream_t *p_access = (stream_t *)p_obj;
747 access_sys_t *p_sys = p_access->p_sys;
749 if (p_sys->p_nfsfh != NULL)
750 nfs_close(p_sys->p_nfs, p_sys->p_nfsfh);
752 if (p_sys->p_nfsdir != NULL)
753 nfs_closedir(p_sys->p_nfs, p_sys->p_nfsdir);
755 if (p_sys->p_nfs != NULL)
756 nfs_destroy_context(p_sys->p_nfs);
758 if (p_sys->p_mount != NULL)
760 for (int i = 0; i < p_sys->res.exports.i_count; ++i)
761 free(p_sys->res.exports.ppsz_names[i]);
762 free(p_sys->res.exports.ppsz_names);
763 rpc_destroy_context(p_sys->p_mount);
766 if (p_sys->p_nfs_url != NULL)
767 nfs_destroy_url(p_sys->p_nfs_url);
769 vlc_UrlClean(&p_sys->encoded_url);
771 free(p_sys->psz_url_decoded);
772 free(p_sys->psz_url_decoded_slash);