xml.c 3.92 KB
Newer Older
1 2 3
/*****************************************************************************
 * xml.c: XML parser wrapper for XML modules
 *****************************************************************************
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
4
 * Copyright (C) 2004-2010 VLC authors and VideoLAN
5 6 7
 *
 * Authors: Gildas Bazin <gbazin@videolan.org>
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
8 9 10
 * 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
11 12 13 14
 * (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
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
15 16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
17
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
18 19 20
 * 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.
21 22
 *****************************************************************************/

23 24 25 26
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

27
#include <vlc_common.h>
28 29
#include <vlc_xml.h>
#include <vlc_modules.h>
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
30
#include "../libvlc.h"
31

32
#undef xml_Create
33 34 35 36 37 38
/*****************************************************************************
 * xml_Create:
 *****************************************************************************
 * Create an instance of an XML parser.
 * Returns NULL on error.
 *****************************************************************************/
39
xml_t *xml_Create( vlc_object_t *p_this )
40 41 42
{
    xml_t *p_xml;

43
    p_xml = vlc_custom_create( p_this, sizeof( *p_xml ), "xml" );
44

45
    p_xml->p_module = module_need( p_xml, "xml", NULL, false );
46 47
    if( !p_xml->p_module )
    {
48
        vlc_object_release( p_xml );
49 50 51 52 53 54 55 56 57 58 59 60
        msg_Err( p_this, "XML provider not found" );
        return NULL;
    }

    return p_xml;
}

/*****************************************************************************
 * xml_Delete: Deletes an instance of xml_t
 *****************************************************************************/
void xml_Delete( xml_t *p_xml )
{
61
    module_unneed( p_xml, p_xml->p_module );
62
    vlc_object_release( p_xml );
63
}
64 65 66 67 68 69 70 71 72 73 74 75 76


#undef xml_ReaderCreate
/**
 * Creates an XML reader.
 * @param obj parent VLC object
 * @param stream stream to read XML from
 * @return NULL on error.
 */
xml_reader_t *xml_ReaderCreate(vlc_object_t *obj, stream_t *stream)
{
    xml_reader_t *reader;

77
    reader = vlc_custom_create(obj, sizeof(*reader), "xml reader");
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92

    reader->p_stream = stream;
    reader->p_module = module_need(reader, "xml reader", NULL, false);
    if (unlikely(reader->p_module == NULL))
    {
        msg_Err(reader, "XML reader not found");
        vlc_object_release(reader);
        return NULL;
    }
    return reader;
}


/**
 * Deletes an XML reader.
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
93
 * @param reader XML reader created with xml_ReaderCreate().
94 95 96
 */
void xml_ReaderDelete(xml_reader_t *reader)
{
97 98
    if (reader->p_stream)
        module_stop(reader, reader->p_module);
99 100
    vlc_object_release(reader);
}
101 102 103 104 105 106


/**
 * Resets an existing XML reader.
 * If you need to parse several XML files, this function is much faster than
 * xml_ReaderCreate() and xml_ReaderDelete() combined.
107 108 109
 * If the stream parameter is NULL, the XML reader will be stopped, but
 * not restarted until the next xml_ReaderReset() call with a non-NULL stream.
 *
110
 * @param reader XML reader to reinitialize
111 112 113
 * @param stream new stream to read XML data from (or NULL)
 * @return reader on success,
 *         NULL on error (in that case, the reader is destroyed).
114 115 116
 */
xml_reader_t *xml_ReaderReset(xml_reader_t *reader, stream_t *stream)
{
117 118
    if (reader->p_stream)
        module_stop(reader, reader->p_module);
119 120

    reader->p_stream = stream;
121
    if ((stream != NULL) && module_start(reader, reader->p_module))
122 123 124 125 126 127
    {
        vlc_object_release(reader);
        return NULL;
    }
    return reader;
}