Description: Fix FTBFS with libxml2/2.14.x.
Origin: upstream, commit:f21c71f, commit:80daf2b
Bug-Debian: https://bugs.debian.org/1106637
Forwarded: not-needed
Last-Update: 2025-08-10
---

--- parser.orig/src/include/pa_charset.h
+++ parser/src/include/pa_charset.h
@@ -8,7 +8,7 @@
 #ifndef PA_CHARSET_H
 #define PA_CHARSET_H
 
-#define IDENT_PA_CHARSET_H "$Id: pa_charset.h,v 1.60 2024/12/11 21:57:35 moko Exp $"
+#define IDENT_PA_CHARSET_H "$Id: pa_charset.h,v 1.62 2025/06/28 15:38:04 moko Exp $"
 
 
 #include "pa_exception.h"
@@ -75,10 +75,6 @@
 
 	void store_Char(XMLByte*& outPtr, XMLCh src, XMLByte not_found);
 
-#ifdef XML
-	xmlCharEncodingHandler& transcoder(const String::Body NAME);
-#endif
-
 public:
 
 	unsigned char pcre_tables[tables_length];
@@ -139,7 +135,6 @@
 
 private:
 	void addEncoding(char* name_cstr);
-	void initTranscoder(const String::Body name, const char* name_cstr);
 
 public:
 	/// converts xmlChar* null-terminated string to char* 
@@ -158,7 +153,8 @@
 
 private:
 
-	xmlCharEncodingHandler* ftranscoder;
+	xmlCharEncodingInputFunc ftranscoder_input;
+	xmlCharEncodingOutputFunc ftranscoder_output;
 
 #endif
 
--- parser.orig/src/main/pa_charset.C
+++ parser/src/main/pa_charset.C
@@ -11,15 +11,13 @@
 // we are using some pcre_internal.h stuff as well
 #include "../lib/pcre/pa_pcre_internal.h"
 
-volatile const char * IDENT_PA_CHARSET_C="$Id: pa_charset.C,v 1.115 2024/12/11 21:57:35 moko Exp $" IDENT_PA_CHARSET_H;
+volatile const char * IDENT_PA_CHARSET_C="$Id: pa_charset.C,v 1.117 2025/06/28 15:42:00 moko Exp $" IDENT_PA_CHARSET_H;
 
 #ifdef XML
 #include "libxml/xmlmemory.h"
 #include "libxml/encoding.h"
 #endif
 
-//#define PA_PATCHED_LIBXML_BACKWARD
-
 // reduce memory usage by pre-calculation utf-8 string length
 #define PRECALCULATE_DEST_LENGTH
 
@@ -125,10 +123,6 @@
 		// grab default onces [for UTF-8 so to be able to make a-z =>A-Z
 		memcpy(pcre_tables, pa_pcre_default_tables, sizeof(pcre_tables));
 	}
-
-#ifdef XML
-	initTranscoder(FNAME, FNAME_CSTR);
-#endif
 }
 
 void Charset::load_definition(Request_charsets& acharsets, const String& afile_spec) {
@@ -993,29 +987,6 @@
 #ifdef XML
 
 static const Charset::Tables* tables[MAX_CHARSETS];
-static xmlCharEncodingHandler xml_encoding_handlers[MAX_CHARSETS];
-
-#ifdef PA_PATCHED_LIBXML_BACKWARD
-
-#define declareXml256ioFuncs(i) \
-	static int xml256CharEncodingInputFunc##i( \
-		unsigned char *out, int *outlen, \
-		const unsigned char *in, int *inlen, void*) { \
-		return transcodeToUTF8( \
-			in, *inlen, \
-			out, *outlen, \
-			*tables[i]); \
-	} \
-	static int xml256CharEncodingOutputFunc##i( \
-		unsigned char *out, int *outlen, \
-		const unsigned char *in, int *inlen, void*) { \
-		return transcodeFromUTF8( \
-			in, *inlen, \
-			out, *outlen, \
-			*tables[i]); \
-	}
-
-#else
 
 #define declareXml256ioFuncs(i) \
 	static int xml256CharEncodingInputFunc##i( \
@@ -1035,9 +1006,6 @@
 			*tables[i]); \
 	}
 
-#endif
-
-
 declareXml256ioFuncs(0)	declareXml256ioFuncs(1)
 declareXml256ioFuncs(2)	declareXml256ioFuncs(3)
 declareXml256ioFuncs(4)	declareXml256ioFuncs(5)
@@ -1064,28 +1032,14 @@
 	if(handlers_count==MAX_CHARSETS)
 		throw Exception(0, 0, "already allocated %d handlers, no space for new encoding '%s'", MAX_CHARSETS, name_cstr);
 
-	xmlCharEncodingHandler* handler=&xml_encoding_handlers[handlers_count];
-	{
-		handler->name=name_cstr;
-		handler->input=inputFuncs[handlers_count]; 
-		handler->output=outputFuncs[handlers_count]; 
-		::tables[handlers_count]=&tables;
-		handlers_count++;
-	}
-	
+	ftranscoder_input=inputFuncs[handlers_count];
+	ftranscoder_output=outputFuncs[handlers_count];
+	::tables[handlers_count++]=&tables;
+
+	xmlCharEncodingHandler* handler=xmlNewCharEncodingHandler(name_cstr, ftranscoder_input, ftranscoder_output);
+	if(!handler)
+		throw Exception(0, new String(name_cstr, String::L_TAINTED), "unable to register XML encoding handler");
 	xmlRegisterCharEncodingHandler(handler);
-
-}
-
-void Charset::initTranscoder(const String::Body NAME, const char* name_cstr) {
-	ftranscoder=xmlFindCharEncodingHandler(name_cstr);
-	transcoder(NAME); // check right way
-}
-
-xmlCharEncodingHandler& Charset::transcoder(const String::Body NAME) {
-	if(!ftranscoder)
-		throw Exception(PARSER_RUNTIME, new String(NAME, String::L_TAINTED), "unsupported encoding");
-	return *ftranscoder;
 }
 
 String::C Charset::transcode_cstr(const xmlChar* s) {
@@ -1100,14 +1054,8 @@
 	char *out=new(PointerFreeGC) char[outlen+1];
 	
 	int error;
-	if(xmlCharEncodingOutputFunc output=transcoder(FNAME).output) {
-		error=output(
-			(unsigned char*)out, &outlen,
-			(const unsigned char*)s, &inlen
-#ifdef PA_PATCHED_LIBXML_BACKWARD
-			,0
-#endif
-			);
+	if(!fisUTF8) {
+		error=ftranscoder_output((unsigned char*)out, &outlen, (const unsigned char*)s, &inlen);
 	} else {
 		memcpy(out, s, outlen=inlen);
 		error=0;
@@ -1131,19 +1079,13 @@
 #ifndef NDEBUG
 	int saved_outlen;
 #endif
-	if(xmlCharEncodingInputFunc input=transcoder(FNAME).input) {
+	if(!fisUTF8) {
 		outlen=buf_size*6/*max UTF8 bytes per char*/;
 #ifndef NDEBUG
 		saved_outlen=outlen;
 #endif
 		out=(xmlChar*)xmlMalloc(outlen+1);
-		error=input(
-			out, &outlen,
-			(const unsigned char*)buf, (int*)&buf_size
-#ifdef PA_PATCHED_LIBXML_BACKWARD
-			,0
-#endif
-			);
+		error=ftranscoder_input(out, &outlen, (const unsigned char*)buf, (int*)&buf_size);
 	} else {
 		outlen=buf_size;
 #ifndef NDEBUG
