]> git.sesse.net Git - vlc/blobdiff - modules/access/mms/buffer.c
mmstu: handle keepalive error case
[vlc] / modules / access / mms / buffer.c
index f7330f1559dca086a1578dab3e48396582839667..06115d35f1e1e259593fecc6ab1332ffc4b7dfac 100644 (file)
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>
 
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
 
 #include "asf.h"
 #include "buffer.h"
@@ -51,10 +54,7 @@ int var_buffer_reinitwrite( var_buffer_t *p_buf, int i_default_size )
     if( p_buf->i_size < i_default_size )
     {
         p_buf->i_size = i_default_size;
-        if( p_buf->p_data )
-        {
-            free( p_buf->p_data );
-        }
+        free( p_buf->p_data );
         p_buf->p_data = malloc( p_buf->i_size );
     }
     if( !p_buf->p_data )
@@ -99,7 +99,6 @@ void var_buffer_add64( var_buffer_t *p_buf, uint64_t i_long )
     var_buffer_add32( p_buf, ( i_long >> 32 )&0xffffffff );
 }
 
-
 void var_buffer_addmemory( var_buffer_t *p_buf, void *p_mem, int i_mem )
 {
     /* check if there is enough data */
@@ -115,7 +114,7 @@ void var_buffer_addmemory( var_buffer_t *p_buf, void *p_mem, int i_mem )
     p_buf->i_data += i_mem;
 }
 
-void var_buffer_addUTF16( var_buffer_t *p_buf, char *p_str )
+void var_buffer_addUTF16( var_buffer_t *p_buf, const char *p_str )
 {
     unsigned int i;
     if( !p_str )
@@ -124,19 +123,32 @@ void var_buffer_addUTF16( var_buffer_t *p_buf, char *p_str )
     }
     else
     {
-        for( i = 0; i < strlen( p_str ) + 1; i++ ) // and 0
+        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 )
         {
-            var_buffer_add16( p_buf, p_str[i] );
+            uint16_t v = GetWLE( &psz_out[i] );
+            var_buffer_add16( p_buf, v );
+            if( !v )
+                break;
         }
+        free( psz_out );
     }
 }
 
 void var_buffer_free( var_buffer_t *p_buf )
 {
-    if( p_buf->p_data )
-    {
-        free( p_buf->p_data );
-    }
+    free( p_buf->p_data );
     p_buf->i_data = 0;
     p_buf->i_size = 0;
 }
@@ -160,7 +172,6 @@ uint8_t var_buffer_get8 ( var_buffer_t *p_buf )
     return( i_byte );
 }
 
-
 uint16_t var_buffer_get16( var_buffer_t *p_buf )
 {
     uint16_t i_b1, i_b2;
@@ -203,7 +214,6 @@ int var_buffer_getmemory ( var_buffer_t *p_buf, void *p_mem, int64_t i_mem )
     }
     if( i_copy < 0 )
     {
-//        fprintf( stderr, "\n**************arrrrrrggggg\n" );
         i_copy = 0;
     }
     p_buf->i_data += i_copy;
@@ -228,4 +238,3 @@ void var_buffer_getguid( var_buffer_t *p_buf, guid_t *p_guid )
         p_guid->v4[i] = var_buffer_get8( p_buf );
     }
 }
-