]> git.sesse.net Git - vlc/blobdiff - modules/access/mms/buffer.c
Qt: properly show the dialog buttons on Win32
[vlc] / modules / access / mms / buffer.c
index 06115d35f1e1e259593fecc6ab1332ffc4b7dfac..4e11e36b05caf28f0776e44b7f6805e20bfc6f26 100644 (file)
@@ -1,24 +1,24 @@
 /*****************************************************************************
  * buffer.c: MMS access plug-in
  *****************************************************************************
- * Copyright (C) 2001-2004 the VideoLAN team
+ * Copyright (C) 2001-2004 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -30,6 +30,8 @@
 #endif
 
 #include <vlc_common.h>
+#include <vlc_access.h>
+#include <vlc_charset.h>
 
 #include "asf.h"
 #include "buffer.h"
@@ -41,11 +43,8 @@ int var_buffer_initwrite( var_buffer_t *p_buf, int i_default_size )
 {
     p_buf->i_size =  ( i_default_size > 0 ) ? i_default_size : 2048;
     p_buf->i_data = 0;
-    if( !( p_buf->p_data = malloc( p_buf->i_size ) ) )
-    {
-        return( -1 );
-    }
-    return( 0 );
+    p_buf->p_data = malloc( p_buf->i_size );
+    return p_buf->p_data ? 0 : -1;
 }
 
 int var_buffer_reinitwrite( var_buffer_t *p_buf, int i_default_size )
@@ -62,11 +61,7 @@ int var_buffer_reinitwrite( var_buffer_t *p_buf, int i_default_size )
         p_buf->i_size =  ( i_default_size > 0 ) ? i_default_size : 2048;
         p_buf->p_data = malloc( p_buf->i_size );
     }
-    if( !p_buf->p_data )
-    {
-        return( -1 );
-    }
-    return( 0 );
+    return p_buf->p_data ? 0 : -1;
 }
 
 void var_buffer_add8 ( var_buffer_t *p_buf, uint8_t  i_byte )
@@ -75,7 +70,7 @@ void var_buffer_add8 ( var_buffer_t *p_buf, uint8_t  i_byte )
     if( p_buf->i_data >= p_buf->i_size )
     {
         p_buf->i_size += 1024;
-        p_buf->p_data = realloc( p_buf->p_data, p_buf->i_size );
+        p_buf->p_data = xrealloc( p_buf->p_data, p_buf->i_size );
     }
     p_buf->p_data[p_buf->i_data] = i_byte&0xff;
     p_buf->i_data++;
@@ -105,45 +100,38 @@ void var_buffer_addmemory( var_buffer_t *p_buf, void *p_mem, int i_mem )
     if( p_buf->i_data + i_mem >= p_buf->i_size )
     {
         p_buf->i_size += i_mem + 1024;
-        p_buf->p_data = realloc( p_buf->p_data, p_buf->i_size );
+        p_buf->p_data = xrealloc( p_buf->p_data, p_buf->i_size );
     }
 
-    memcpy( p_buf->p_data + p_buf->i_data,
-            p_mem,
-            i_mem );
+    memcpy( p_buf->p_data + p_buf->i_data, p_mem, i_mem );
     p_buf->i_data += i_mem;
 }
 
-void var_buffer_addUTF16( var_buffer_t *p_buf, const char *p_str )
+void var_buffer_addUTF16( access_t  *p_access, var_buffer_t *p_buf, const char *p_str )
 {
-    unsigned int i;
-    if( !p_str )
-    {
-        var_buffer_add16( p_buf, 0 );
-    }
+    uint16_t *p_out;
+    size_t i_out;
+
+    if( p_str != NULL )
+#ifdef WORDS_BIGENDIAN
+        p_out = ToCharset( "UTF-16BE", p_str, &i_out );
+#else
+        p_out = ToCharset( "UTF-16LE", p_str, &i_out );
+#endif
     else
+        p_out = NULL;
+    if( p_out == NULL )
     {
-        vlc_iconv_t iconv_handle;
-        size_t i_in = strlen( p_str );
-        size_t i_out = i_in * 4;
-        char *psz_out, *psz_tmp;
-
-        psz_out = psz_tmp = malloc( i_out + 1 );
-        iconv_handle = vlc_iconv_open( "UTF-16LE", "UTF-8" );
-        vlc_iconv( iconv_handle, &p_str, &i_in, &psz_tmp, &i_out );
-        vlc_iconv_close( iconv_handle );
-        psz_tmp[0] = '\0';
-        psz_tmp[1] = '\0';
-
-        for( i = 0; ; i += 2 )
-        {
-            uint16_t v = GetWLE( &psz_out[i] );
-            var_buffer_add16( p_buf, v );
-            if( !v )
-                break;
-        }
-        free( psz_out );
+        msg_Err( p_access, "UTF-16 conversion failed" );
+        i_out = 0;
     }
+
+    i_out /= 2;
+    for( size_t i = 0; i < i_out; i ++ )
+        var_buffer_add16( p_buf, p_out[i] );
+    free( p_out );
+
+    var_buffer_add16( p_buf, 0 );
 }
 
 void var_buffer_free( var_buffer_t *p_buf )
@@ -210,7 +198,7 @@ int var_buffer_getmemory ( var_buffer_t *p_buf, void *p_mem, int64_t i_mem )
     i_copy = __MIN( i_mem, p_buf->i_size - p_buf->i_data );
     if( i_copy > 0 && p_mem != NULL)
     {
-        memcpy( p_mem, p_buf + p_buf->i_data, i_copy );
+        memcpy( p_mem, p_buf->p_data + p_buf->i_data , i_copy );
     }
     if( i_copy < 0 )
     {
@@ -229,12 +217,12 @@ void var_buffer_getguid( var_buffer_t *p_buf, guid_t *p_guid )
 {
     int i;
 
-    p_guid->v1 = var_buffer_get32( p_buf );
-    p_guid->v2 = var_buffer_get16( p_buf );
-    p_guid->v3 = var_buffer_get16( p_buf );
+    p_guid->Data1 = var_buffer_get32( p_buf );
+    p_guid->Data2 = var_buffer_get16( p_buf );
+    p_guid->Data3 = var_buffer_get16( p_buf );
 
     for( i = 0; i < 8; i++ )
     {
-        p_guid->v4[i] = var_buffer_get8( p_buf );
+        p_guid->Data4[i] = var_buffer_get8( p_buf );
     }
 }