17#if USE_SQUID_ESI && HAVE_LIBXML2
30 void finalizeConfig()
override
36 std::unique_ptr<ESIParser::Register> registration;
45static htmlDocPtr entity_doc =
nullptr;
51esi_startElementSAXFunc(
void * ctx,
const xmlChar * name,
const xmlChar ** atts)
54 xmlChar **tmp = (xmlChar **)atts;
56 while (tmp && *tmp !=
nullptr) {
64 ESILibxml2Parser *p = (ESILibxml2Parser *)ctx;
66 p->getClient()->start((
const char *)name, (
const char **)atts, count);
70esi_endElementSAXFunc(
void *ctx,
const xmlChar *name)
72 ESILibxml2Parser *p = (ESILibxml2Parser *)ctx;
73 p->getClient()->end((
const char *)name);
77esi_commentSAXFunc(
void *ctx,
const xmlChar *value)
79 ESILibxml2Parser *p = (ESILibxml2Parser *)ctx;
80 p->getClient()->parserComment((
const char *)value);
84esi_charactersSAXFunc(
void *ctx,
const xmlChar *ch,
int len)
86 ESILibxml2Parser *p = (ESILibxml2Parser *)ctx;
87 p->getClient()->parserDefault((
const char *)ch, len);
91esi_getEntitySAXFunc(
void * ,
const xmlChar *name)
93 xmlEntityPtr res = xmlGetDocEntity(entity_doc, name);
96 const htmlEntityDesc *ent = htmlEntityLookup(name);
100 snprintf(tmp, 32,
"&#%d;", ent->value);
101 res = xmlAddDocEntity(entity_doc, (
const xmlChar *)name, XML_INTERNAL_GENERAL_ENTITY,
nullptr,
nullptr, (
const xmlChar *)tmp);
108ESILibxml2Parser::ESILibxml2Parser(
ESIParserClient *aClient) : theClient (aClient)
112 memset(&sax, 0,
sizeof(sax));
113 sax.startElement = esi_startElementSAXFunc;
114 sax.endElement = esi_endElementSAXFunc;
115 sax.comment = esi_commentSAXFunc;
116 sax.characters = esi_charactersSAXFunc;
117 sax.getEntity = esi_getEntitySAXFunc;
120 parser = xmlCreatePushParserCtxt(&sax,
static_cast<void *
>(
this),
nullptr, 0,
nullptr);
122 if (entity_doc ==
nullptr)
123 entity_doc = htmlNewDoc(
nullptr,
nullptr);
126ESILibxml2Parser::~ESILibxml2Parser()
128 xmlFreeParserCtxt(parser);
135 return (xmlParseChunk(parser, dataToParse, lengthOfData, endOfStream) == 0);
139ESILibxml2Parser::lineNumber()
const
141 return (
long int)xmlSAX2GetLineNumber(parser);
145ESILibxml2Parser::errorString()
const
147 xmlErrorPtr
error = xmlGetLastError();
149 if (
error ==
nullptr)
152 return error->message;
#define DefineRunnerRegistratorIn(Namespace, ClassName)
void error(char *format,...)
#define EsiParserDefinition(ThisClass)
ESI protocol types and operators.
static struct node * parse(FILE *fp)