]> git.sesse.net Git - vlc/blobdiff - include/vlc_url.h
NEWS: nitpicking
[vlc] / include / vlc_url.h
index a5e9438d5a1d34566854261bc4b36f8c27e5fa04..820250f963fbc31ff56ef1e866fe6bd020686ef0 100644 (file)
  * This file defines functions for manipulating URL in vlc
  */
 
+VLC_API char *vlc_path2uri (const char *path, const char *scheme) VLC_MALLOC;
+
 struct vlc_url_t
 {
     char *psz_protocol;
     char *psz_username;
     char *psz_password;
     char *psz_host;
-    int  i_port;
-
+    unsigned i_port;
     char *psz_path;
-
     char *psz_option;
 
     char *psz_buffer; /* to be freed */
@@ -48,149 +48,8 @@ struct vlc_url_t
 VLC_API char * decode_URI_duplicate( const char *psz ) VLC_MALLOC;
 VLC_API char * decode_URI( char *psz );
 VLC_API char * encode_URI_component( const char *psz ) VLC_MALLOC;
-VLC_API char * make_URI( const char *path, const char *scheme ) VLC_MALLOC;
 VLC_API char * make_path( const char *url ) VLC_MALLOC;
 
-/*****************************************************************************
- * vlc_UrlParse:
- *****************************************************************************
- * option : if != 0 then path is split at this char
- *
- * format [protocol://[login[:password]@]][host[:port]]/path[OPTIONoption]
- *****************************************************************************/
-static inline void vlc_UrlParse( vlc_url_t *url, const char *psz_url,
-                                 char option )
-{
-    char *psz_dup;
-    char *psz_parse;
-    char *p;
-    char *p2;
-
-    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 );
-
-    /* Search a valid protocol */
-    p  = strstr( psz_parse, ":/" );
-    if( p != NULL )
-    {
-        for( p2 = psz_parse; p2 < p; p2++ )
-        {
-#define I(i,a,b) ( (a) <= (i) && (i) <= (b) )
-            if( !I(*p2, 'a', 'z' ) && !I(*p2, 'A', 'Z') && !I(*p2, '0', '9') && *p2 != '+' && *p2 != '-' && *p2 != '.' )
-            {
-                p = NULL;
-                break;
-            }
-#undef I
-        }
-    }
-
-    if( p != NULL )
-    {
-        /* we have a protocol */
-
-        /* skip :// */
-        *p++ = '\0';
-        if( p[1] == '/' )
-            p += 2;
-        url->psz_protocol = psz_parse;
-        psz_parse = p;
-    }
-    p = strchr( psz_parse, '@' );
-    p2 = strchr( psz_parse, '/' );
-    if( p != NULL && ( p2 != NULL ? p < p2 : 1 ) )
-    {
-        /* 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;
-            decode_URI( url->psz_password );
-        }
-        decode_URI( url->psz_username );
-        psz_parse = p;
-    }
-
-    p = strchr( psz_parse, '/' );
-    if( !p || psz_parse < p )
-    {
-        /* We have a host[:port] */
-        url->psz_host = strdup( psz_parse );
-        if( p )
-        {
-            url->psz_host[p - psz_parse] = '\0';
-        }
-
-        if( *url->psz_host == '[' )
-        {
-            /* Ipv6 address */
-            p2 = strchr( url->psz_host, ']' );
-            if( p2 )
-            {
-                p2 = strchr( p2, ':' );
-            }
-        }
-        else
-        {
-            p2 = strchr( url->psz_host, ':' );
-        }
-        if( p2 )
-        {
-            *p2++ = '\0';
-            url->i_port = atoi( p2 );
-        }
-    }
-    psz_parse = p;
-
-    /* Now parse psz_path and psz_option */
-    if( psz_parse )
-    {
-        url->psz_path = psz_parse;
-        if( option != '\0' )
-        {
-            p = strchr( url->psz_path, option );
-            if( p )
-            {
-                *p++ = '\0';
-                url->psz_option = p;
-            }
-        }
-    }
-}
-
-/*****************************************************************************
- * vlc_UrlClean:
- *****************************************************************************/
-static inline void vlc_UrlClean( vlc_url_t *url )
-{
-    free( url->psz_buffer );
-    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;
-}
+VLC_API void vlc_UrlParse (vlc_url_t *, const char *, unsigned char);
+VLC_API void vlc_UrlClean (vlc_url_t *);
 #endif