]> git.ipfire.org Git - thirdparty/squid.git/blame - src/esi/ExpatParser.cc
Renamed squid.h to squid-old.h and config.h to squid.h
[thirdparty/squid.git] / src / esi / ExpatParser.cc
CommitLineData
43ae1d95 1
2/*
262a0e14 3 * $Id$
43ae1d95 4 *
5 * DEBUG: section 86 ESI processing
6 * AUTHOR: Robert Collins
7 *
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
26ac0430 24 *
43ae1d95 25 * This program is distributed in the hope that it will be useful,
26 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
26ac0430 29 *
43ae1d95 30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 *
34 */
35
f7f3304a 36#include "squid-old.h"
da783331 37
95cd9022 38#if USE_SQUID_ESI && HAVE_LIBEXPAT
da783331 39
f99c2cfe 40#include "esi/ExpatParser.h"
43ae1d95 41
019db3c6 42EsiParserDefinition(ESIExpatParser);
c2d4889f 43
43ae1d95 44ESIExpatParser::ESIExpatParser(ESIParserClient *aClient) : theClient (aClient)
45{
46 /* TODO: grab the document encoding from the headers */
47 p = XML_ParserCreateNS(NULL,'|');
48 XML_SetUserData (myParser(), static_cast<void *>(this));
49 XML_SetElementHandler(myParser(), Start, End);
50 XML_SetDefaultHandler(myParser(), Default);
51 XML_SetCommentHandler(myParser(), Comment);
52 XML_UseParserAsHandlerArg(myParser());
53}
54
55ESIExpatParser::~ESIExpatParser()
56{
57 XML_ParserFree (myParser());
58 p = NULL;
59}
60
61void
62ESIExpatParser::Start(void *data,const XML_Char *el, const char **attr)
63{
64 XML_Parser parser = static_cast<XML_Parser>(data);
65 ESIExpatParser *me = (ESIExpatParser *)XML_GetUserData(parser);
66 me->theClient->start (el, attr, XML_GetSpecifiedAttributeCount (parser));
67}
68
69void
70ESIExpatParser::End(void *data,const XML_Char *el)
71{
72 XML_Parser parser = static_cast<XML_Parser>(data);
73 ESIExpatParser *me = (ESIExpatParser *)XML_GetUserData(parser);
74 me->theClient->end (el);
75}
76
77void
78ESIExpatParser::Default(void *data, const XML_Char *s, int len)
79{
80 XML_Parser parser = static_cast<XML_Parser>(data);
81 ESIExpatParser *me = (ESIExpatParser *)XML_GetUserData(parser);
82 me->theClient->parserDefault (s, len);
83}
84
85void
86ESIExpatParser::Comment(void *data, const XML_Char *s)
87{
88 XML_Parser parser = static_cast<XML_Parser>(data);
89 ESIExpatParser *me = (ESIExpatParser *)XML_GetUserData(parser);
90 me->theClient->parserComment (s);
91}
92
93bool
94ESIExpatParser::parse(char const *dataToParse, size_t const lengthOfData, bool const endOfStream)
95{
96 return XML_Parse(myParser(), dataToParse, lengthOfData, endOfStream);
97}
98
137a13ea 99long int
43ae1d95 100ESIExpatParser::lineNumber() const
101{
137a13ea 102 return (long int)XML_GetCurrentLineNumber(myParser());
43ae1d95 103}
104
105char const *
106ESIExpatParser::errorString() const
107{
108 return XML_ErrorString(XML_GetErrorCode(myParser()));
109}
da783331
AJ
110
111#endif /* USE_SQUID_ESI */