]> git.sesse.net Git - vlc/blob - modules/misc/profile_parser.c
Stupid platforms
[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: rtsp.c 16204 2006-08-03 16:58:10Z zorglub $
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 #include <vlc/vlc.h>
25 #include <vlc_streaming.h>
26 #include "vlc_stream.h"
27 #include "vlc_xml.h"
28
29 /*****************************************************************************
30  * Module descriptor
31  *****************************************************************************/
32 static int  Open ( vlc_object_t * );
33
34 vlc_module_begin();
35     set_capability( "profile parser", 1 );
36     set_callbacks( Open, NULL );
37 vlc_module_end();
38
39 static int Open( vlc_object_t *p_this )
40 {
41     profile_parser_t *p_parser = (profile_parser_t *)p_this->p_private;
42     stream_t *p_stream = stream_UrlNew( p_this, p_parser->psz_profile );
43     xml_t *p_xml;
44     xml_reader_t *p_reader;
45     int i_ret;
46     char *psz_elname;
47    
48     /* Open the profile and get a XML reader from it */
49     if( !p_stream )
50     {
51         msg_Err( p_this, "failed to parse profile %s", p_parser->psz_profile );
52         return VLC_EGENERIC;
53     }
54     p_xml = xml_Create( p_this );
55     if( !p_xml ) return VLC_EGENERIC;
56     p_reader = xml_ReaderCreate( p_xml, p_stream );
57
58
59     if( xml_ReaderRead( p_reader ) != 1 || 
60         xml_ReaderNodeType( p_reader ) != XML_READER_STARTELEM )
61     {
62         msg_Err( p_this, "invalid file (invalid root)" );
63         return VLC_EGENERIC;
64     }
65
66     /* Here goes the real parsing */
67
68     while( (i_ret = xml_ReaderRead( p_reader ) ) == 1 )
69     {
70         int i_type = xml_ReaderNodeType( p_reader );
71         switch( i_type )
72         {
73         case -1:
74             /* ERROR : Bail out */
75             return -1;
76
77         case XML_READER_STARTELEM:
78             FREE( psz_elname );
79             psz_elname = xml_ReaderName( p_reader );
80             if( !psz_elname ) return VLC_EGENERIC;
81             printf( "<%s", psz_elname );
82             break;
83
84         case XML_READER_TEXT:
85             break;
86         case XML_READER_ENDELEM:
87             FREE( psz_elname );
88             psz_elname = xml_ReaderName( p_reader );
89             if( !psz_elname ) return VLC_EGENERIC;
90             printf( ">" );
91             break;
92         }
93     }
94
95     if( i_ret != 0 )
96     {
97         msg_Err( p_this, "parse error" );
98         return VLC_EGENERIC;
99     }
100
101     if( p_reader ) xml_ReaderDelete( p_xml, p_reader );
102     if( p_xml ) xml_Delete( p_xml );
103
104     return VLC_SUCCESS;
105 }