typedef struct
{
char *psz_protocol;
+ char *psz_username;
+ char *psz_password;
char *psz_host;
int i_port;
char *psz_path;
char *psz_option;
+
+ char *psz_buffer; /* to be freed */
} vlc_url_t;
/*****************************************************************************
*****************************************************************************
* option : if != 0 then path is split at this char
*
- * format [protocol://][host[:port]]/path[OPTIONoption]
+ * format [protocol://[login[:password]@]][host[:port]]/path[OPTIONoption]
*****************************************************************************/
-static inline void vlc_UrlParse( vlc_url_t *url, char *psz_url, char option )
+static inline void vlc_UrlParse( vlc_url_t *url, const char *psz_url,
+ char option )
{
- char *psz_dup = psz_url ? strdup( psz_url ) : 0;
- char *psz_parse = psz_dup;
+ char *psz_dup;
+ char *psz_parse;
char *p;
url->psz_protocol = NULL;
+ url->psz_username = NULL;
+ url->psz_password = NULL;
url->psz_host = NULL;
url->i_port = 0;
url->psz_path = NULL;
url->psz_option = NULL;
+
+ if( psz_url == NULL )
+ {
+ url->psz_buffer = NULL;
+ return;
+ }
+ url->psz_buffer = psz_parse = psz_dup = strdup( psz_url );
- if( !psz_url ) return;
-
- if( ( p = strstr( psz_parse, ":/" ) ) )
+ p = strstr( psz_parse, ":/" );
+ if( p != NULL )
{
/* we have a protocol */
/* skip :// */
*p++ = '\0';
- if( p[0] == '/' && p[1] == '/' )
- {
+ if( p[1] == '/' )
p += 2;
- }
- url->psz_protocol = strdup( psz_dup );
+ url->psz_protocol = psz_parse;
psz_parse = p;
+ p = strchr( psz_parse, '@' );
+ if( p != NULL )
+ {
+ /* We have a login */
+ url->psz_username = psz_parse;
+ *p++ = '\0';
+
+ psz_parse = strchr( psz_parse, ':' );
+ if( psz_parse != NULL )
+ {
+ /* We have a password */
+ *psz_parse++ = '\0';
+ url->psz_password = psz_parse;
+ }
+
+ psz_parse = p;
+ }
}
p = strchr( psz_parse, '/' );
/* Now parse psz_path and psz_option */
if( psz_parse )
{
- url->psz_path = strdup( psz_parse );
+ url->psz_path = psz_parse;
if( option != '\0' )
{
p = strchr( url->psz_path, option );
if( p )
{
*p++ = '\0';
- url->psz_option = strdup( p );
+ url->psz_option = p;
}
}
}
- free( psz_dup );
}
/*****************************************************************************
*****************************************************************************/
static inline void vlc_UrlClean( vlc_url_t *url )
{
- if( url->psz_protocol ) free( url->psz_protocol );
- if( url->psz_host ) free( url->psz_host );
- if( url->psz_path ) free( url->psz_path );
- if( url->psz_option ) free( url->psz_option );
+ if( url->psz_buffer ) free( url->psz_buffer );
+ if( url->psz_host ) free( url->psz_host );
url->psz_protocol = NULL;
+ url->psz_username = NULL;
+ url->psz_password = NULL;
url->psz_host = NULL;
url->i_port = 0;
url->psz_path = NULL;
url->psz_option = NULL;
+
+ url->psz_buffer = NULL;
}
/*****************************************************************************
#define net_OpenTCP(a, b, c) __net_OpenTCP(VLC_OBJECT(a), b, c)
VLC_EXPORT( int, __net_OpenTCP, ( vlc_object_t *p_this, const char *psz_host, int i_port ) );
-VLC_EXPORT( int, net_ConvertIPv4, ( uint32_t *p_addr, const char * psz_address ) );
-
#define net_ListenTCP(a, b, c) __net_ListenTCP(VLC_OBJECT(a), b, c)
VLC_EXPORT( int *, __net_ListenTCP, ( vlc_object_t *, const char *, int ) );
#define net_vaPrintf(a,b,c,d,e) __net_vaPrintf(VLC_OBJECT(a),b,c,d,e)
VLC_EXPORT( int, __net_vaPrintf, ( vlc_object_t *p_this, int fd, v_socket_t *, const char *psz_fmt, va_list args ) );
+#define net_CheckIP(a,b,c,d) __net_CheckIP(VLC_OBJECT(a),b,c,d)
+VLC_EXPORT( int, __net_CheckIP, ( vlc_object_t *p_this, char *psz_ip, char **ppsz_hosts, int i_hosts ) );
+
/* Portable network names/addresses resolution layer */
/* GAI error codes */
# define NI_MAXHOST 1025
# define NI_MAXSERV 32
# endif
+# define NI_MAXNUMERICHOST 48
# ifndef NI_NUMERICHOST
# define NI_NUMERICHOST 0x01
# endif
VLC_EXPORT( const char *, vlc_gai_strerror, ( int ) );
-VLC_EXPORT( int, vlc_getnameinfo, ( vlc_object_t *, const struct sockaddr *, int, char *, int, char *, int, int ) );
-VLC_EXPORT( int, vlc_getaddrinfo, ( vlc_object_t *, const char *, const char *, const struct addrinfo *, struct addrinfo ** ) );
+VLC_EXPORT( int, vlc_getnameinfo, ( const struct sockaddr *, int, char *, int, int *, int ) );
+VLC_EXPORT( int, vlc_getaddrinfo, ( vlc_object_t *, const char *, int, const struct addrinfo *, struct addrinfo ** ) );
VLC_EXPORT( void, vlc_freeaddrinfo, ( struct addrinfo * ) );
#endif