]> git.sesse.net Git - vlc/blob - modules/misc/profile_parser.c
0b602c4ccf4641c1ca80156e61736e7c0a87db02
[vlc] / modules / misc / profile_parser.c
1 /*****************************************************************************
2  * profile_parser.c : VLC Streaming Profile parser
3  *****************************************************************************
4  * Copyright (C) 2003-2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *          Gildas Bazin <gbazin@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include <vlc_common.h>
29 #include <vlc_plugin.h>
30 #include <vlc_stream.h>
31 #include <vlc_streaming.h>
32 #include "vlc_xml.h"
33
34 /*****************************************************************************
35  * Module descriptor
36  *****************************************************************************/
37 static int  Open ( vlc_object_t * );
38
39 vlc_module_begin();
40     set_capability( "profile parser", 1 );
41     set_callbacks( Open, NULL );
42 vlc_module_end();
43
44 static int Open( vlc_object_t *p_this )
45 {
46     profile_parser_t *p_parser = (profile_parser_t *)p_this->p_private;
47     stream_t *p_stream = stream_UrlNew( p_this, p_parser->psz_profile );
48     xml_t *p_xml;
49     xml_reader_t *p_reader;
50     int i_ret;
51     char *psz_elname = NULL;
52
53     /* Open the profile and get a XML reader from it */
54     if( !p_stream )
55     {
56         msg_Err( p_this, "failed to parse profile %s", p_parser->psz_profile );
57         return VLC_EGENERIC;
58     }
59     p_xml = xml_Create( p_this );
60     if( !p_xml ) return VLC_EGENERIC;
61     p_reader = xml_ReaderCreate( p_xml, p_stream );
62
63     if( xml_ReaderRead( p_reader ) != 1 ||
64         xml_ReaderNodeType( p_reader ) != XML_READER_STARTELEM )
65     {
66         msg_Err( p_this, "invalid file (invalid root)" );
67         return VLC_EGENERIC;
68     }
69
70     /* Here goes the real parsing */
71
72     while( (i_ret = xml_ReaderRead( p_reader ) ) == 1 )
73     {
74         int i_type = xml_ReaderNodeType( p_reader );
75         switch( i_type )
76         {
77         case -1:
78             /* ERROR : Bail out */
79             return -1;
80
81         case XML_READER_STARTELEM:
82             free( psz_elname );
83             psz_elname = xml_ReaderName( p_reader );
84             if( !psz_elname ) return VLC_EGENERIC;
85             printf( "<%s", psz_elname );
86             break;
87
88         case XML_READER_TEXT:
89             break;
90         case XML_READER_ENDELEM:
91             free( psz_elname );
92             psz_elname = xml_ReaderName( p_reader );
93             if( !psz_elname ) return VLC_EGENERIC;
94             printf( ">" );
95             break;
96         }
97     }
98
99     if( i_ret != 0 )
100     {
101         msg_Err( p_this, "parse error" );
102         return VLC_EGENERIC;
103     }
104
105     if( p_reader ) xml_ReaderDelete( p_xml, p_reader );
106     if( p_xml ) xml_Delete( p_xml );
107
108     return VLC_SUCCESS;
109 }