]> git.sesse.net Git - mlt/blobdiff - src/modules/xml/producer_xml.c
fix regression due to not setting resource property in some contexts
[mlt] / src / modules / xml / producer_xml.c
index 082dd9cedb4952ce3b78ad9c38dcb169eb329453..2baec97d11b042ece5bfca8f63ca3e369fe99eb0 100644 (file)
@@ -153,7 +153,7 @@ static mlt_service context_pop_service( deserialise_context context, enum servic
 {
        mlt_service result = NULL;
        
-       *type = invalid_type;
+       if ( type ) *type = invalid_type;
        if ( context->stack_service_size > 0 )
        {
                result = context->stack_service[ -- context->stack_service_size ];
@@ -1301,7 +1301,7 @@ static void on_characters( void *ctx, const xmlChar *ch, int len )
 {
        struct _xmlParserCtxt *xmlcontext = ( struct _xmlParserCtxt* )ctx;
        deserialise_context context = ( deserialise_context )( xmlcontext->_private );
-       char *value = calloc( len + 1, 1 );
+       char *value = calloc( 1, len + 1 );
        enum service_type type;
        mlt_service service = context_pop_service( context, &type );
        mlt_properties properties = MLT_SERVICE_PROPERTIES( service );
@@ -1324,7 +1324,7 @@ static void on_characters( void *ctx, const xmlChar *ch, int len )
                if ( s != NULL )
                {
                        // Append new text to existing content
-                       char *new = calloc( strlen( s ) + len + 1, 1 );
+                       char *new = calloc( 1, strlen( s ) + len + 1 );
                        strcat( new, s );
                        strcat( new, value );
                        mlt_properties_set( properties, context->property, new );
@@ -1532,20 +1532,20 @@ static int file_exists( char *file )
 
 mlt_producer producer_xml_init( mlt_profile profile, mlt_service_type servtype, const char *id, char *data )
 {
-       xmlSAXHandler *sax = calloc( 1, sizeof( xmlSAXHandler ) );
+       xmlSAXHandler *sax;
        struct deserialise_context_s *context;
        mlt_properties properties = NULL;
        int i = 0;
        struct _xmlParserCtxt *xmlcontext;
        int well_formed = 0;
        char *filename = NULL;
-       int info = strcmp( id, "xml-string" ) ? 0 : 1;
+       int is_filename = strcmp( id, "xml-string" );
 
        // Strip file:// prefix
        if ( data && strlen( data ) >= 7 && strncmp( data, "file://", 7 ) == 0 )
                data += 7;
 
-       if ( data == NULL || !strcmp( data, "" ) || ( info == 0 && !file_exists( data ) ) )
+       if ( data == NULL || !strcmp( data, "" ) || ( is_filename && !file_exists( data ) ) )
                return NULL;
 
        context = calloc( 1, sizeof( struct deserialise_context_s ) );
@@ -1560,7 +1560,7 @@ mlt_producer producer_xml_init( mlt_profile profile, mlt_service_type servtype,
 
        // Decode URL and parse parameters
        mlt_properties_set( context->producer_map, "root", "" );
-       if ( info == 0 )
+       if ( is_filename )
        {
                filename = strdup( data );
                parse_url( context->params, url_decode( filename, data ) );
@@ -1590,6 +1590,7 @@ mlt_producer producer_xml_init( mlt_profile profile, mlt_service_type servtype,
        mlt_properties_set_int( context->destructors, "registered", 0 );
 
        // Setup SAX callbacks for first pass
+       sax = calloc( 1, sizeof( xmlSAXHandler ) );
        sax->startElement = on_start_element;
        sax->warning = on_error;
        sax->error = on_error;
@@ -1600,7 +1601,7 @@ mlt_producer producer_xml_init( mlt_profile profile, mlt_service_type servtype,
        xmlSubstituteEntitiesDefault( 1 );
        // This is used to facilitate entity substitution in the SAX parser
        context->entity_doc = xmlNewDoc( _x("1.0") );
-       if ( info == 0 )
+       if ( is_filename )
                xmlcontext = xmlCreateFileParserCtxt( filename );
        else
                xmlcontext = xmlCreateMemoryParserCtxt( data, strlen( data ) );
@@ -1645,7 +1646,7 @@ mlt_producer producer_xml_init( mlt_profile profile, mlt_service_type servtype,
 
        // Setup the second pass
        context->pass ++;
-       if ( info == 0 )
+       if ( is_filename )
                xmlcontext = xmlCreateFileParserCtxt( filename );
        else
                xmlcontext = xmlCreateMemoryParserCtxt( data, strlen( data ) );
@@ -1733,7 +1734,7 @@ mlt_producer producer_xml_init( mlt_profile profile, mlt_service_type servtype,
                if ( getenv( "MLT_XML_DEEP" ) == NULL )
                {
                        // Now assign additional properties
-                       if ( info == 0 && !mlt_properties_get( properties, "resource" ) )
+                       if ( is_filename && mlt_service_identify( service ) == tractor_type )
                                mlt_properties_set( properties, "resource", data );
 
                        // This tells consumer_xml not to deep copy