ExpatParser.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2022 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 "base/RunnersRegistry.h"
16 #include "esi/ExpatParser.h"
17 
18 #include <memory>
19 
20 namespace Esi
21 {
22 
23 class ExpatRr : public RegisteredRunner
24 {
25 public:
26  void finalizeConfig()
27  {
28  registration.reset(new ESIParser::Register("expat", &ESIExpatParser::NewParser));
29  }
30 
31 private:
32  std::unique_ptr<ESIParser::Register> registration;
33 };
34 
36 
37 }
38 
39 EsiParserDefinition(ESIExpatParser);
40 
41 ESIExpatParser::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 
52 ESIExpatParser::~ESIExpatParser()
53 {
54  XML_ParserFree (myParser());
55  p = nullptr;
56 }
57 
58 void
59 ESIExpatParser::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 
66 void
67 ESIExpatParser::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 
74 void
75 ESIExpatParser::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 
82 void
83 ESIExpatParser::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 
90 bool
91 ESIExpatParser::parse(char const *dataToParse, size_t const lengthOfData, bool const endOfStream)
92 {
93  return XML_Parse(myParser(), dataToParse, lengthOfData, endOfStream);
94 }
95 
96 long int
97 ESIExpatParser::lineNumber() const
98 {
99  return (long int)XML_GetCurrentLineNumber(myParser());
100 }
101 
102 char const *
103 ESIExpatParser::errorString() const
104 {
105  return XML_ErrorString(XML_GetErrorCode(myParser()));
106 }
107 
108 #endif /* USE_SQUID_ESI */
109 
#define RunnerRegistrationEntry(Who)
convenience macro: register one RegisteredRunner kid as early as possible
#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