control/media_descriptor.c: Make sure we don't strdup a NULL ptr.
[vlc.git] / src / control / media_descriptor.c
index 8766772..d5c076e 100644 (file)
@@ -29,7 +29,7 @@
 
 
 /**************************************************************************
 
 
 /**************************************************************************
- * Create a new media descriptor object (Private)
+ * Preparse if not already done (Private)
  **************************************************************************/
 static void preparse_if_needed( libvlc_media_descriptor_t *p_media_desc )
 {
  **************************************************************************/
 static void preparse_if_needed( libvlc_media_descriptor_t *p_media_desc )
 {
@@ -56,9 +56,12 @@ libvlc_media_descriptor_t * libvlc_media_descriptor_new(
     p_input_item = input_ItemNew( p_instance->p_libvlc_int, psz_mrl, psz_mrl );
 
     if (!p_input_item)
     p_input_item = input_ItemNew( p_instance->p_libvlc_int, psz_mrl, psz_mrl );
 
     if (!p_input_item)
-        return NULL; /* XXX: throw an exception */
+    {
+        libvlc_exception_raise( p_e, "Can't create md's input_item" );
+        return NULL;
+    }
 
 
-    p_media_desc = malloc( sizeof(libvlc_input_t) );
+    p_media_desc = malloc( sizeof(libvlc_media_descriptor_t) );
     p_media_desc->p_libvlc_instance = p_instance;
     p_media_desc->p_input_item      = p_input_item;
     p_media_desc->b_preparsed       = VLC_FALSE;
     p_media_desc->p_libvlc_instance = p_instance;
     p_media_desc->p_input_item      = p_input_item;
     p_media_desc->b_preparsed       = VLC_FALSE;
@@ -66,22 +69,61 @@ libvlc_media_descriptor_t * libvlc_media_descriptor_new(
     return p_media_desc;
 }
 
     return p_media_desc;
 }
 
+/**************************************************************************
+ * Create a new media descriptor object from an input_item
+ * (libvlc internal)
+ **************************************************************************/
+libvlc_media_descriptor_t * libvlc_media_descriptor_new_from_input_item(
+                                   libvlc_instance_t *p_instance,
+                                   input_item_t *p_input_item,
+                                   libvlc_exception_t *p_e )
+{
+    libvlc_media_descriptor_t * p_media_desc;
+
+    if (!p_input_item)
+    {
+        libvlc_exception_raise( p_e, "No input item given" );
+        return NULL;
+    }
+
+    p_media_desc = malloc( sizeof(libvlc_media_descriptor_t) );
+    p_media_desc->p_libvlc_instance = p_instance;
+    p_media_desc->p_input_item      = p_input_item;
+    p_media_desc->b_preparsed       = VLC_TRUE;
+
+    return p_media_desc;
+}
+
 /**************************************************************************
  * Delete a media descriptor object
  **************************************************************************/
 /**************************************************************************
  * Delete a media descriptor object
  **************************************************************************/
-void libvlc_media_descriptor_destroy( libvlc_media_descriptor_t *p_meta_desc )
+void libvlc_media_descriptor_destroy( libvlc_media_descriptor_t *p_md )
 {
 {
-    if (!p_meta_desc)
+    if (!p_md)
         return;
 
     /* XXX: locking */
         return;
 
     /* XXX: locking */
-    input_ItemClean( p_meta_desc->p_input_item );
+    input_ItemClean( p_md->p_input_item );
+
+    free( p_md );
+}
 
 
-    free( p_meta_desc );
+/**************************************************************************
+ * Delete a media descriptor object
+ **************************************************************************/
+libvlc_media_descriptor_t *
+libvlc_media_descriptor_duplicate( libvlc_media_descriptor_t *p_md_orig )
+{
+    libvlc_media_descriptor_t * p_md;
+
+    p_md = malloc( sizeof(libvlc_media_descriptor_t) );
+    memcpy( p_md_orig, p_md, sizeof(libvlc_media_descriptor_t) );
+
+    return p_md;
 }
 
 /**************************************************************************
 }
 
 /**************************************************************************
- * Getters for meta information
+ * Getter for meta information
  **************************************************************************/
 static const int meta_conversion[] =
 {
  **************************************************************************/
 static const int meta_conversion[] =
 {
@@ -94,12 +136,17 @@ char * libvlc_media_descriptor_get_meta( libvlc_media_descriptor_t *p_meta_desc,
                                          libvlc_exception_t *p_e )
 {
     char ** ppsz_meta;
                                          libvlc_exception_t *p_e )
 {
     char ** ppsz_meta;
+    char *ppz_meta;
 
     /* XXX: locking */
 
     preparse_if_needed( p_meta_desc );
 
     ppsz_meta = (char**)p_meta_desc->p_input_item->p_meta;
 
     /* XXX: locking */
 
     preparse_if_needed( p_meta_desc );
 
     ppsz_meta = (char**)p_meta_desc->p_input_item->p_meta;
+    ppz_meta = ppsz_meta[ meta_conversion[e_meta] ];
+
+    if( !ppz_meta )
+        return NULL;
 
 
-    return strdup( ppsz_meta[ meta_conversion[e_meta] ] );
+    return strdup( ppz_meta );
 }
 }