]> git.ipfire.org Git - thirdparty/squid.git/blob - src/esi/ExpatParser.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / esi / ExpatParser.cc
1 /*
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 /* DEBUG: section 86 ESI processing */
10
11 #include "squid.h"
12
13 #if USE_SQUID_ESI && HAVE_LIBEXPAT
14
15 #include "esi/ExpatParser.h"
16
17 EsiParserDefinition(ESIExpatParser);
18
19 ESIExpatParser::ESIExpatParser(ESIParserClient *aClient) : theClient (aClient)
20 {
21 /* TODO: grab the document encoding from the headers */
22 p = XML_ParserCreateNS(NULL,'|');
23 XML_SetUserData (myParser(), static_cast<void *>(this));
24 XML_SetElementHandler(myParser(), Start, End);
25 XML_SetDefaultHandler(myParser(), Default);
26 XML_SetCommentHandler(myParser(), Comment);
27 XML_UseParserAsHandlerArg(myParser());
28 }
29
30 ESIExpatParser::~ESIExpatParser()
31 {
32 XML_ParserFree (myParser());
33 p = NULL;
34 }
35
36 void
37 ESIExpatParser::Start(void *data,const XML_Char *el, const char **attr)
38 {
39 XML_Parser parser = static_cast<XML_Parser>(data);
40 ESIExpatParser *me = (ESIExpatParser *)XML_GetUserData(parser);
41 me->theClient->start (el, attr, XML_GetSpecifiedAttributeCount (parser));
42 }
43
44 void
45 ESIExpatParser::End(void *data,const XML_Char *el)
46 {
47 XML_Parser parser = static_cast<XML_Parser>(data);
48 ESIExpatParser *me = (ESIExpatParser *)XML_GetUserData(parser);
49 me->theClient->end (el);
50 }
51
52 void
53 ESIExpatParser::Default(void *data, const XML_Char *s, int len)
54 {
55 XML_Parser parser = static_cast<XML_Parser>(data);
56 ESIExpatParser *me = (ESIExpatParser *)XML_GetUserData(parser);
57 me->theClient->parserDefault (s, len);
58 }
59
60 void
61 ESIExpatParser::Comment(void *data, const XML_Char *s)
62 {
63 XML_Parser parser = static_cast<XML_Parser>(data);
64 ESIExpatParser *me = (ESIExpatParser *)XML_GetUserData(parser);
65 me->theClient->parserComment (s);
66 }
67
68 bool
69 ESIExpatParser::parse(char const *dataToParse, size_t const lengthOfData, bool const endOfStream)
70 {
71 return XML_Parse(myParser(), dataToParse, lengthOfData, endOfStream);
72 }
73
74 long int
75 ESIExpatParser::lineNumber() const
76 {
77 return (long int)XML_GetCurrentLineNumber(myParser());
78 }
79
80 char const *
81 ESIExpatParser::errorString() const
82 {
83 return XML_ErrorString(XML_GetErrorCode(myParser()));
84 }
85
86 #endif /* USE_SQUID_ESI */
87