[vlc-commits] smb2: refactor for next commit
Thomas Guillem
git at videolan.org
Fri Nov 23 16:32:26 CET 2018
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Nov 23 16:19:00 2018 +0100| [e9c9d72f504bd61d661b86b20ed56130d9e7166d] | committer: Thomas Guillem
smb2: refactor for next commit
vlc_smb2_resolve() now returns the resolved host instead of modifying the host
argument.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e9c9d72f504bd61d661b86b20ed56130d9e7166d
---
modules/access/smb2.c | 40 ++++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/modules/access/smb2.c b/modules/access/smb2.c
index e81511cc53..a99512d623 100644
--- a/modules/access/smb2.c
+++ b/modules/access/smb2.c
@@ -534,48 +534,43 @@ error:
return -1;
}
-static int
-vlc_smb2_resolve(stream_t *access, char **host, unsigned port)
+static char *
+vlc_smb2_resolve(stream_t *access, const char *host, unsigned port)
{
(void) access;
- if (!*host)
- return -1;
+ if (!host)
+ return NULL;
#ifdef HAVE_DSM
/* Test if the host is an IP */
struct in_addr addr;
- if (inet_pton(AF_INET, *host, &addr) == 1)
- return 0;
+ if (inet_pton(AF_INET, host, &addr) == 1)
+ return NULL;
/* Test if the host can be resolved */
struct addrinfo *info = NULL;
- if (vlc_getaddrinfo_i11e(*host, port, NULL, &info) == 0)
+ if (vlc_getaddrinfo_i11e(host, port, NULL, &info) == 0)
{
freeaddrinfo(info);
/* Let smb2 resolve it */
- return 0;
+ return NULL;
}
/* Test if the host is a netbios name */
+ char *out_host = NULL;
netbios_ns *ns = netbios_ns_new();
uint32_t ip4_addr;
- int ret = -1;
- if (netbios_ns_resolve(ns, *host, NETBIOS_FILESERVER, &ip4_addr) == 0)
+ if (netbios_ns_resolve(ns, host, NETBIOS_FILESERVER, &ip4_addr) == 0)
{
char ip[] = "xxx.xxx.xxx.xxx";
if (inet_ntop(AF_INET, &ip4_addr, ip, sizeof(ip)))
- {
- free(*host);
- *host = strdup(ip);
- if (*host)
- ret = 0;
- }
+ out_host = strdup(ip);
}
netbios_ns_destroy(ns);
- return ret;
+ return out_host;
#else
(void) port;
- return 0;
+ return NULL;
#endif
}
@@ -599,8 +594,13 @@ Open(vlc_object_t *p_obj)
goto error;
sys->encoded_url.i_port = 0;
- if (vlc_smb2_resolve(access, &sys->encoded_url.psz_host, CIFS_PORT))
- goto error;
+ char *resolved_host = vlc_smb2_resolve(access, sys->encoded_url.psz_host,
+ CIFS_PORT);
+ if (resolved_host)
+ {
+ free(sys->encoded_url.psz_host);
+ sys->encoded_url.psz_host = resolved_host;
+ }
if (sys->encoded_url.psz_path == NULL)
sys->encoded_url.psz_path = (char *) "/";
More information about the vlc-commits
mailing list