ExpatParser.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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
16#include "esi/ExpatParser.h"
17
18#include <memory>
19
20namespace Esi
21{
22
23class ExpatRr : public RegisteredRunner
24{
25public:
26 void finalizeConfig() override
27 {
28 registration.reset(new ESIParser::Register("expat", &ESIExpatParser::NewParser));
29 }
30
31private:
32 std::unique_ptr<ESIParser::Register> registration;
33};
34
35}
36
38
39EsiParserDefinition(ESIExpatParser);
40
41ESIExpatParser::ESIExpatParser(ESIParserClient *aClient) : theClient (aClient)
42{
43 /* TODO: grab the document encoding from the headers */
44 p = XML_ParserCreateNS(nullptr,'|');
45 XML_SetUserData (myParser(), static_cast<void *>(this));
46 XML_SetElementHandler(myParser(), Start, End);
47 XML_SetDefaultHandler(myParser(), Default);
48 XML_SetCommentHandler(myParser(), Comment);
49 XML_UseParserAsHandlerArg(myParser());
50}
51
52ESIExpatParser::~ESIExpatParser()
53{
54 XML_ParserFree (myParser());
55 p = nullptr;
56}
57
58void
59ESIExpatParser::Start(void *data,const XML_Char *el, const char **attr)
60{
61 XML_Parser parser = static_cast<XML_Parser>(data);
62 ESIExpatParser *me = (ESIExpatParser *)XML_GetUserData(parser);
63 me->theClient->start (el, attr, XML_GetSpecifiedAttributeCount (parser));
64}
65
66void
67ESIExpatParser::End(void *data,const XML_Char *el)
68{
69 XML_Parser parser = static_cast<XML_Parser>(data);
70 ESIExpatParser *me = (ESIExpatParser *)XML_GetUserData(parser);
71 me->theClient->end (el);
72}
73
74void
75ESIExpatParser::Default(void *data, const XML_Char *s, int len)
76{
77 XML_Parser parser = static_cast<XML_Parser>(data);
78 ESIExpatParser *me = (ESIExpatParser *)XML_GetUserData(parser);
79 me->theClient->parserDefault (s, len);
80}
81
82void
83ESIExpatParser::Comment(void *data, const XML_Char *s)
84{
85 XML_Parser parser = static_cast<XML_Parser>(data);
86 ESIExpatParser *me = (ESIExpatParser *)XML_GetUserData(parser);
87 me->theClient->parserComment (s);
88}
89
90bool
91ESIExpatParser::parse(char const *dataToParse, size_t const lengthOfData, bool const endOfStream)
92{
93 return XML_Parse(myParser(), dataToParse, lengthOfData, endOfStream);
94}
95
96long int
97ESIExpatParser::lineNumber() const
98{
99 return (long int)XML_GetCurrentLineNumber(myParser());
100}
101
102char const *
103ESIExpatParser::errorString() const
104{
105 return XML_ErrorString(XML_GetErrorCode(myParser()));
106}
107
108#endif /* USE_SQUID_ESI */
109
#define DefineRunnerRegistratorIn(Namespace, ClassName)
#define EsiParserDefinition(ThisClass)
Definition: Parser.h:64
ESI protocol types and operators.
Definition: Element.h:89
void Start(const Comm::ConnectionPointer &conn, IDCB *callback, void *cbdata)
Definition: Ident.cc:264
static struct node * parse(FILE *fp)
Definition: parse.c:965

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors