]> git.sesse.net Git - vlc/blobdiff - modules/control/http/util.c
Control interfaces first string review.
[vlc] / modules / control / http / util.c
index b12ccde8bdf9aabaa30fc85387dada09b8e8f676..0d45dcc5cb5e7e77cc19d4f78190c8b896d540b2 100644 (file)
@@ -135,14 +135,14 @@ int E_(ParseDirectory)( intf_thread_t *p_intf, char *psz_root,
 
     if( ( p_dir = utf8_opendir( psz_dir ) ) == NULL )
     {
-        msg_Err( p_intf, "cannot open dir (%s)", psz_dir );
+        msg_Err( p_intf, "cannot open directory (%s)", psz_dir );
         return VLC_EGENERIC;
     }
 
     i_dirlen = strlen( psz_dir );
     if( i_dirlen + 10 > MAX_DIR_SIZE )
     {
-        msg_Warn( p_intf, "skipping too deep dir (%s)", psz_dir );
+        msg_Warn( p_intf, "skipping too deep directory (%s)", psz_dir );
         return 0;
     }
 
@@ -262,12 +262,25 @@ int E_(ParseDirectory)( intf_thread_t *p_intf, char *psz_root,
 
             if( !f->b_handler )
             {
+                char *psz_type = strdup( p_sys->psz_html_type );
+                if( strstr( &dir[strlen( psz_root )], ".xml" ) )
+                {
+                    char *psz = strstr( psz_type, "html;" );
+                    if( psz )
+                    {
+                        psz[0] = 'x';
+                        psz[1] = 'm';
+                        psz[2] = 'l';
+                        psz[3] = ';';
+                        psz[4] = ' ';
+                    }
+                }
                 f->p_file = httpd_FileNew( p_sys->p_httpd_host,
                                            f->name,
-                                           f->b_html ? ( strstr( &dir[strlen( psz_root )], ".xml" ) ? "text/xml; charset=UTF-8" : p_sys->psz_html_type ) :
-                                            NULL,
+                                           f->b_html ? psz_type : NULL,
                                            user, password, p_acl,
                                            E_(HttpCallback), f );
+                free( psz_type );
                 if( f->p_file != NULL )
                 {
                     TAB_APPEND( p_sys->i_files, p_sys->pp_files, f );
@@ -344,26 +357,9 @@ char *E_(FromUTF8)( intf_thread_t *p_intf, char *psz_utf8 )
         char *psz_out = psz_local;
         size_t i_ret;
         char psz_tmp[i_in + 1];
-        char *psz_in = psz_tmp;
-        uint8_t *p = (uint8_t *)psz_tmp;
+        const char *psz_in = psz_tmp;
         strcpy( psz_tmp, psz_utf8 );
 
-        /* Fix Unicode quotes. If we are here we are probably converting
-         * to an inferior charset not understanding Unicode quotes. */
-        while( *p )
-        {
-            if( p[0] == 0xe2 && p[1] == 0x80 && p[2] == 0x99 )
-            {
-                *p = '\'';
-                memmove( &p[1], &p[3], strlen((char *)&p[3]) + 1 );
-            }
-            if( p[0] == 0xe2 && p[1] == 0x80 && p[2] == 0x9a )
-            {
-                *p = '"';
-                memmove( &p[1], &p[3], strlen((char *)&p[3]) + 1 );
-            }
-            p++;
-        }
         i_in = strlen( psz_tmp );
 
         i_ret = vlc_iconv( p_sys->iconv_from_utf8, &psz_in, &i_in,
@@ -390,7 +386,7 @@ char *E_(ToUTF8)( intf_thread_t *p_intf, char *psz_local )
 
     if ( p_sys->iconv_to_utf8 != (vlc_iconv_t)-1 )
     {
-        char *psz_in = psz_local;
+        const char *psz_in = psz_local;
         size_t i_in = strlen(psz_in);
         size_t i_out = i_in * 6;
         char *psz_utf8 = malloc(i_out + 1);
@@ -458,7 +454,7 @@ void E_(PlaylistListNode)( intf_thread_t *p_intf, playlist_t *p_pl,
                 E_(mvar_AppendNewVar)( itm, "ro", "rw" );
             }
 
-            sprintf( value, "%d", p_node->input.i_duration );
+            sprintf( value, "%ld", (long)p_node->input.i_duration );
             E_(mvar_AppendNewVar)( itm, "duration", value );
 
             E_(mvar_AppendVar)( s, itm );
@@ -570,8 +566,10 @@ void E_(HandleSeek)( intf_thread_t *p_intf, char *p_value )
                 {
                     i_value += 3600 * i_stock;
                     i_stock = 0;
-                    /* other characters which are not numbers are not important */
-                    while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
+                    /* other characters which are not numbers are not
+                     * important */
+                    while( ((p_value[0] < '0') || (p_value[0] > '9'))
+                           && (p_value[0] != '\0') )
                     {
                         p_value++;
                     }
@@ -582,7 +580,8 @@ void E_(HandleSeek)( intf_thread_t *p_intf, char *p_value )
                     i_value += 60 * i_stock;
                     i_stock = 0;
                     p_value++;
-                    while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
+                    while( ((p_value[0] < '0') || (p_value[0] > '9'))
+                           && (p_value[0] != '\0') )
                     {
                         p_value++;
                     }
@@ -592,7 +591,8 @@ void E_(HandleSeek)( intf_thread_t *p_intf, char *p_value )
                 {
                     i_value += i_stock;
                     i_stock = 0;
-                    while( ((p_value[0] < '0') || (p_value[0] > '9')) && (p_value[0] != '\0') )
+                    while( ((p_value[0] < '0') || (p_value[0] > '9'))
+                           && (p_value[0] != '\0') )
                     {
                         p_value++;
                     }
@@ -606,7 +606,8 @@ void E_(HandleSeek)( intf_thread_t *p_intf, char *p_value )
             }
         }
 
-        /* if there is no known symbol, I consider it as seconds. Otherwise, i_stock = 0 */
+        /* if there is no known symbol, I consider it as seconds.
+         * Otherwise, i_stock = 0 */
         i_value += i_stock;
 
         switch(i_relative)
@@ -652,30 +653,35 @@ void E_(HandleSeek)( intf_thread_t *p_intf, char *p_value )
             }
             case POSITION_ABSOLUTE:
             {
-                val.f_float = __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
+                val.f_float = __MIN( __MAX( ((float) i_value ) / 100.0 ,
+                                            0.0 ), 100.0 );
                 var_Set( p_sys->p_input, "position", val );
-                msg_Dbg( p_intf, "requested seek percent: %d", i_value );
+                msg_Dbg( p_intf, "requested seek percent: %d%%", i_value );
                 break;
             }
             case POSITION_REL_FOR:
             {
                 var_Get( p_sys->p_input, "position", &val );
-                val.f_float += __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
+                val.f_float += __MIN( __MAX( ((float) i_value ) / 100.0,
+                                             0.0 ) , 100.0 );
                 var_Set( p_sys->p_input, "position", val );
-                msg_Dbg( p_intf, "requested seek percent forward: %d", i_value );
+                msg_Dbg( p_intf, "requested seek percent forward: %d%%",
+                         i_value );
                 break;
             }
             case POSITION_REL_BACK:
             {
                 var_Get( p_sys->p_input, "position", &val );
-                val.f_float -= __MIN( __MAX( ((float) i_value ) / 100.0 , 0.0 ) , 100.0 );
+                val.f_float -= __MIN( __MAX( ((float) i_value ) / 100.0,
+                                             0.0 ) , 100.0 );
                 var_Set( p_sys->p_input, "position", val );
-                msg_Dbg( p_intf, "requested seek percent backward: %d", i_value );
+                msg_Dbg( p_intf, "requested seek percent backward: %d%%",
+                         i_value );
                 break;
             }
             default:
             {
-                msg_Dbg( p_intf, "requested seek: what the f*** is going on here ?" );
+                msg_Dbg( p_intf, "invalid seek request" );
                 break;
             }
         }
@@ -918,10 +924,8 @@ playlist_item_t *E_(MRLParse)( intf_thread_t *p_intf, char *psz,
     playlist_item_t * p_item = NULL;
 
     /* In case there is spaces before the mrl */
-    while( ( *s_mrl == ' ' ) && ( *s_mrl != '\0' ) )
-    {
+    while( *s_mrl == ' ' )
         s_mrl++;
-    }
 
     /* extract the mrl */
     s_temp = strstr( s_mrl , " :" );