]> git.sesse.net Git - vlc/blobdiff - include/vlc_url.h
Implement basic panel change
[vlc] / include / vlc_url.h
index 60cade1bc41ab0a33c2dfabbb88da6ccee585541..ab30180b74fa210a15362c97d0e5f621e5e92ce8 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * vlc_url.h: URL related macros
  *****************************************************************************
- * Copyright (C) 2002-2005 the VideoLAN team
+ * Copyright (C) 2002-2006 the VideoLAN team
  * $Id$
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
@@ -169,52 +169,16 @@ static inline void vlc_UrlClean( vlc_url_t *url )
     url->psz_buffer   = NULL;
 }
 
-static inline int isurlsafe( int c )
-{
-    return ( (unsigned char)( c - 'a' ) < 26 )
-        || ( (unsigned char)( c - 'A' ) < 26 )
-        || ( (unsigned char)( c - '0' ) < 10 )
-        /* Hmm, we should not encode character that are allowed in URLs
-         * (even if they are not URL-safe), nor URL-safe characters.
-         * We still encode some of them because of Microsoft's crap browser.
-         */
-        || ( strchr( "-_.", c ) != NULL );
-}
+VLC_EXPORT( char *, unescape_URI_duplicate, ( const char *psz ) );
+VLC_EXPORT( void, unescape_URI, ( char *psz ) );
+VLC_EXPORT( char *, decode_URI_duplicate, ( const char *psz ) );
+VLC_EXPORT( void, decode_URI, ( char *psz ) );
+VLC_EXPORT( char *, encode_URI_component, ( const char *psz ) );
 
-/*****************************************************************************
- * vlc_UrlEncode:
- *****************************************************************************
- * perform URL encoding
- * (you do NOT want to do URL decoding - it is not reversible - do NOT do it)
- *****************************************************************************/
 static inline char *vlc_UrlEncode( const char *psz_url )
 {
-    char *psz_enc, *out;
-    const unsigned char *in;
-
-    psz_enc = (char *)malloc( 3 * strlen( psz_url ) + 1 );
-    if( psz_enc == NULL )
-        return NULL;
-
-    out = psz_enc;
-    for( in = (const unsigned char *)psz_url; *in; in++ )
-    {
-        unsigned char c = *in;
-
-        if( isurlsafe( c ) )
-            *out++ = (char)c;
-        else
-        {
-            *out++ = '%';
-            *out++ = ( ( c >> 4 ) >= 0xA ) ? 'A' + ( c >> 4 ) - 0xA
-                                           : '0' + ( c >> 4 );
-            *out++ = ( ( c & 0xf ) >= 0xA ) ? 'A' + ( c & 0xf ) - 0xA
-                                           : '0' + ( c & 0xf );
-        }
-    }
-    *out++ = '\0';
-
-    return (char *)realloc( psz_enc, out - psz_enc );
+    /* FIXME: do not encode / : ? and & _when_ not needed */
+    return encode_URI_component( psz_url );
 }
 
 /*****************************************************************************
@@ -239,7 +203,10 @@ static inline int vlc_UrlIsNotEncoded( const char *psz_url )
             ptr += 2;
         }
         else
-        if( !isurlsafe( c ) )
+        if(  ( (unsigned char)( c - 'a' ) < 26 )
+          || ( (unsigned char)( c - 'A' ) < 26 )
+          || ( (unsigned char)( c - '0' ) < 10 )
+          || ( strchr( "-_.", c ) != NULL ) )
             return 1;
     }
     return 0; /* looks fine - but maybe it is not encoded */