~vanvugt/+junk/mediatomb

« back to all changes in this revision

Viewing changes to src/mxml/parser_expat.cc

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia
  • Date: 2008-03-02 13:09:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080302130916-zlljdze3kt7vuq4b
Tags: 0.11.0-1
* New upstream release.
* Include message about which inotify headers will be used when enabling
  inotify runtime support.
* Fixed error with use of INTERFACE in init script. Also removed use of -m
  option.
* Including new config.xml options.
* Added more build dependencies for new upstream release.
* Removed build dependency of libid3-dev, taglib is now preferred.
* mediatomb.xpm and manpage.xml is now included in orig tarball.
* inotify patch is not needed anymore.
* md5 patch has been committed upstream and is no longer needed. Also removed
  README.Debian.
* TwinHelix PNG fix is now used. Removed from TODO.
* Adding dependency of iceweasel for mediatomb package.
* Updated copyright file.
* Updated watch file.
* Updated rules file for proper configure options.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*MT*
 
2
    
 
3
    MediaTomb - http://www.mediatomb.cc/
 
4
    
 
5
    parser_expat.cc - this file is part of MediaTomb.
 
6
    
 
7
    Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
 
8
                       Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
 
9
    
 
10
    Copyright (C) 2006-2008 Gena Batyan <bgeradz@mediatomb.cc>,
 
11
                            Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
 
12
                            Leonhard Wimmer <leo@mediatomb.cc>
 
13
    
 
14
    MediaTomb is free software; you can redistribute it and/or modify
 
15
    it under the terms of the GNU General Public License version 2
 
16
    as published by the Free Software Foundation.
 
17
    
 
18
    MediaTomb is distributed in the hope that it will be useful,
 
19
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
    GNU General Public License for more details.
 
22
    
 
23
    You should have received a copy of the GNU General Public License
 
24
    version 2 along with MediaTomb; if not, write to the Free Software
 
25
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
26
    
 
27
    $Id: parser_expat.cc 1698 2008-02-23 20:48:30Z lww $
 
28
*/
 
29
 
 
30
/// \file parser_expat.cc
 
31
 
 
32
#ifdef HAVE_CONFIG_H
 
33
    #include "autoconfig.h"
 
34
#endif
 
35
 
 
36
#ifdef HAVE_EXPAT
 
37
 
 
38
#include "parser.h"
 
39
 
 
40
using namespace zmm;
 
41
using namespace mxml;
 
42
 
 
43
#include "mxml.h"
 
44
#include "tools.h"
 
45
 
 
46
void XMLCALL Parser::element_start(void *userdata, const char *name, const char **attrs)
 
47
{
 
48
    Parser *parser = (Parser *)userdata;
 
49
    Ref<Element> el(new Element(String(name)));
 
50
    for (int i = 0; attrs[i]; i += 2) 
 
51
    {
 
52
        el->addAttribute(String(attrs[i]), String(attrs[i + 1]));
 
53
    }
 
54
 
 
55
    if (parser->root == nil)
 
56
        parser->root = el;
 
57
    else
 
58
    {
 
59
        parser->curEl->appendElementChild(el);
 
60
        parser->elements->push(parser->curEl);
 
61
    }
 
62
    parser->curEl = el;
 
63
}
 
64
 
 
65
void XMLCALL Parser::element_end(void *userdata, const char *name)
 
66
{
 
67
    Parser *parser = (Parser *)userdata;
 
68
    parser->curEl = parser->elements->pop();
 
69
}
 
70
 
 
71
void XMLCALL Parser::character_data(void *userdata, const XML_Char *s, int len)
 
72
{
 
73
    Parser *parser = (Parser *)userdata;
 
74
    String text = String(s, len);
 
75
    if (text != nil)
 
76
    {
 
77
        Ref<Text> textEl(new Text(text));
 
78
        parser->curEl->appendChild(RefCast(textEl, Node));
 
79
    }
 
80
}
 
81
 
 
82
void XMLCALL Parser::comment_callback(void *userdata, const XML_Char *s)
 
83
{
 
84
    Parser *parser = (Parser *)userdata;
 
85
    String text = String(s);
 
86
    if (text != nil)
 
87
    {
 
88
        Ref<Comment> cm(new Comment(text));
 
89
        parser->curEl->appendChild(RefCast(cm, Node));
 
90
    }
 
91
}
 
92
 
 
93
Parser::Parser()
 
94
{
 
95
 
 
96
}
 
97
 
 
98
Ref<Element> Parser::parseFile(String filename)
 
99
{
 
100
    Ref<Context> ctx(new Context(filename));
 
101
    return parse(ctx, read_text_file(filename));
 
102
}
 
103
 
 
104
Ref<Element> Parser::parseString(String str)
 
105
{
 
106
    Ref<Context> ctx(new Context(_("")));
 
107
    return parse(ctx, str);
 
108
}
 
109
 
 
110
Ref<Element> Parser::parse(Ref<Context> ctx, String input)
 
111
{
 
112
    XML_Parser parser = XML_ParserCreate(NULL);
 
113
    if (!parser)
 
114
        throw Exception(_("Unable to allocate XML parser"));
 
115
 
 
116
    XML_SetUserData(parser, this);
 
117
    XML_SetElementHandler(parser, Parser::element_start, Parser::element_end);
 
118
    XML_SetCharacterDataHandler(parser, Parser::character_data);
 
119
    XML_SetCommentHandler(parser, Parser::comment_callback);
 
120
 
 
121
    elements = Ref<ObjectStack<Element> >(new ObjectStack<Element>(8));
 
122
 
 
123
    if (XML_Parse(parser, input.c_str(), input.length(), 1) != XML_STATUS_OK)
 
124
    {
 
125
        ctx->line = XML_GetCurrentLineNumber(parser);
 
126
        ctx->col = XML_GetCurrentColumnNumber(parser);
 
127
        String message = String(XML_ErrorString(XML_GetErrorCode(parser)));
 
128
        XML_ParserFree(parser);
 
129
        throw ParseException(message, ctx);
 
130
    }
 
131
 
 
132
    XML_ParserFree(parser);
 
133
    return root;
 
134
}
 
135
 
 
136
#endif