[vlc-commits] [Git][videolan/vlc][3.0.x] 2 commits: smb2: build smb2 urls using memstream rather than complex printf construct
Steve Lhomme (@robUx4)
gitlab at videolan.org
Fri Jun 10 12:54:03 UTC 2022
Steve Lhomme pushed to branch 3.0.x at VideoLAN / VLC
Commits:
0ab339ea by Pierre Lamot at 2022-06-10T15:20:26+03:00
smb2: build smb2 urls using memstream rather than complex printf construct
(cherry picked from commit 9775ae34a9a44156b7de21d98f3662381c22df47)
- - - - -
095bfffb by Pierre Lamot at 2022-06-10T15:20:26+03:00
smb2: support browsing files when running on a non standard port
(cherry picked from commit b967d0a028f138c8d10aa7b0ce8d865691b6855e)
- - - - -
1 changed file:
- modules/access/smb2.c
Changes:
=====================================
modules/access/smb2.c
=====================================
@@ -42,6 +42,7 @@
#include <vlc_keystore.h>
#include <vlc_interrupt.h>
#include <vlc_network.h>
+#include <vlc_memstream.h>
#include <smb2/smb2.h>
#include <smb2/libsmb2.h>
@@ -399,18 +400,31 @@ FileControl(stream_t *access, int i_query, va_list args)
static char *
vlc_smb2_get_url(vlc_url_t *url, const char *file)
{
- /* smb2://<psz_host><psz_path><file>?<psz_option> */
- char *buf;
- if (asprintf(&buf, "smb://%s%s%s%s%s%s", url->psz_host,
- url->psz_path != NULL ? url->psz_path : "",
- url->psz_path != NULL && url->psz_path[0] != '\0' &&
- url->psz_path[strlen(url->psz_path) - 1] != '/' ? "/" : "",
- file,
- url->psz_option != NULL ? "?" : "",
- url->psz_option != NULL ? url->psz_option : "") == -1)
- return NULL;
+ /* smb2://<psz_host><i_port><psz_path><file>?<psz_option> */
+ struct vlc_memstream buf;
+ vlc_memstream_open(&buf);
+ vlc_memstream_printf(&buf, "smb://%s", url->psz_host);
+
+ if (url->i_port != 0)
+ vlc_memstream_printf(&buf, ":%d", url->i_port);
+
+ if (url->psz_path != NULL)
+ {
+ vlc_memstream_puts(&buf, url->psz_path);
+ if (url->psz_path[0] != '\0' && url->psz_path[strlen(url->psz_path) - 1] != '/')
+ vlc_memstream_putc(&buf, '/');
+ }
else
- return buf;
+ vlc_memstream_putc(&buf, '/');
+
+ vlc_memstream_puts(&buf, file);
+
+ if (url->psz_option)
+ vlc_memstream_printf(&buf, "?%s", url->psz_option);
+
+ if (vlc_memstream_close(&buf))
+ return NULL;
+ return buf.ptr;
}
static int AddItem(stream_t *access, struct vlc_readdir_helper *rdh,
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/0f7d74a4ac554aa4c6ce68dac83b678b840d5c06...095bfffb29fbe0fa4cb0542f3654139738df6c88
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/0f7d74a4ac554aa4c6ce68dac83b678b840d5c06...095bfffb29fbe0fa4cb0542f3654139738df6c88
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list