]> git.sesse.net Git - vlc/blobdiff - src/misc/xml.c
Define explicit makefile variable for libpthread
[vlc] / src / misc / xml.c
index f5e2fec74b51d427cf39706e6f7c6ea9ad63b1b6..e145a5fa7ae83959137eb6142fa80e07d9fec04f 100644 (file)
@@ -1,23 +1,23 @@
 /*****************************************************************************
  * xml.c: XML parser wrapper for XML modules
  *****************************************************************************
- * Copyright (C) 2004-2010 the VideoLAN team
+ * Copyright (C) 2004-2010 VLC authors and VideoLAN
  *
  * Authors: Gildas Bazin <gbazin@videolan.org>
  *
- * 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.
  *****************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -40,9 +40,7 @@ xml_t *xml_Create( vlc_object_t *p_this )
 {
     xml_t *p_xml;
 
-    p_xml = vlc_custom_create( p_this, sizeof( *p_xml ), VLC_OBJECT_GENERIC,
-                               "xml" );
-    vlc_object_attach( p_xml, p_this );
+    p_xml = vlc_custom_create( p_this, sizeof( *p_xml ), "xml" );
 
     p_xml->p_module = module_need( p_xml, "xml", NULL, false );
     if( !p_xml->p_module )
@@ -76,9 +74,7 @@ xml_reader_t *xml_ReaderCreate(vlc_object_t *obj, stream_t *stream)
 {
     xml_reader_t *reader;
 
-    reader = vlc_custom_create(obj, sizeof(*reader), VLC_OBJECT_GENERIC,
-                               "xml reader");
-    vlc_object_attach(reader, obj);
+    reader = vlc_custom_create(obj, sizeof(*reader), "xml reader");
 
     reader->p_stream = stream;
     reader->p_module = module_need(reader, "xml reader", NULL, false);
@@ -94,10 +90,38 @@ xml_reader_t *xml_ReaderCreate(vlc_object_t *obj, stream_t *stream)
 
 /**
  * Deletes an XML reader.
- * @param reader XML reader created with xml_RaederCreate().
+ * @param reader XML reader created with xml_ReaderCreate().
  */
 void xml_ReaderDelete(xml_reader_t *reader)
 {
-    module_unneed(reader, reader->p_module);
+    if (reader->p_stream)
+        module_stop(reader, reader->p_module);
     vlc_object_release(reader);
 }
+
+
+/**
+ * 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.
+ * 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.
+ *
+ * @param reader XML reader to reinitialize
+ * @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).
+ */
+xml_reader_t *xml_ReaderReset(xml_reader_t *reader, stream_t *stream)
+{
+    if (reader->p_stream)
+        module_stop(reader, reader->p_module);
+
+    reader->p_stream = stream;
+    if ((stream != NULL) && module_start(reader, reader->p_module))
+    {
+        vlc_object_release(reader);
+        return NULL;
+    }
+    return reader;
+}