]> git.ipfire.org Git - thirdparty/squid.git/blob - src/esi/ExpatParser.cc
Renamed squid.h to squid-old.h and config.h to squid.h
[thirdparty/squid.git] / src / esi / ExpatParser.cc
1
2 /*
3 * $Id$
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.
24 *
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.
29 *
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
36 #include "squid-old.h"
37
38 #if USE_SQUID_ESI && HAVE_LIBEXPAT
39
40 #include "esi/ExpatParser.h"
41
42 EsiParserDefinition(ESIExpatParser);
43
44 ESIExpatParser::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
55 ESIExpatParser::~ESIExpatParser()
56 {
57 XML_ParserFree (myParser());
58 p = NULL;
59 }
60
61 void
62 ESIExpatParser::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
69 void
70 ESIExpatParser::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
77 void
78 ESIExpatParser::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
85 void
86 ESIExpatParser::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
93 bool
94 ESIExpatParser::parse(char const *dataToParse, size_t const lengthOfData, bool const endOfStream)
95 {
96 return XML_Parse(myParser(), dataToParse, lengthOfData, endOfStream);
97 }
98
99 long int
100 ESIExpatParser::lineNumber() const
101 {
102 return (long int)XML_GetCurrentLineNumber(myParser());
103 }
104
105 char const *
106 ESIExpatParser::errorString() const
107 {
108 return XML_ErrorString(XML_GetErrorCode(myParser()));
109 }
110
111 #endif /* USE_SQUID_ESI */