Commit 7a8402c9 authored by Alexander Barkov's avatar Alexander Barkov

Replacing iconv converstion routines in libdoc.cc to MariaDB routines.

TODO: Access to Field->charset() instead of hardcoded latin1 conversion.

modified:
  storage/connect/libdoc.cpp
  storage/connect/libdoc.h
parent 1e976f42
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include "xobject.h" #include "xobject.h"
#include "libdoc.h" #include "libdoc.h"
#include "sql_string.h"
extern "C" { extern "C" {
extern char version[]; extern char version[];
extern int trace; extern int trace;
...@@ -64,8 +66,6 @@ void CloseXML2File(PGLOBAL g, PFBLOCK fp, bool all) ...@@ -64,8 +66,6 @@ void CloseXML2File(PGLOBAL g, PFBLOCK fp, bool all)
if (xp && xp->Count > 1 && !all) { if (xp && xp->Count > 1 && !all) {
xp->Count--; xp->Count--;
} else if (xp && xp->Count > 0) { } else if (xp && xp->Count > 0) {
iconv_close(xp->Cd);
iconv_close(xp->Cd2);
xmlFreeDoc(xp->Docp); xmlFreeDoc(xp->Docp);
xp->Count = 0; xp->Count = 0;
} // endif } // endif
...@@ -85,8 +85,6 @@ LIBXMLDOC::LIBXMLDOC(char *nsl, char *nsdf, char *enc, PFBLOCK fp) ...@@ -85,8 +85,6 @@ LIBXMLDOC::LIBXMLDOC(char *nsl, char *nsdf, char *enc, PFBLOCK fp)
Nlist = NULL; Nlist = NULL;
Ctxp = NULL; Ctxp = NULL;
Xop = NULL; Xop = NULL;
Cd = (fp) ? ((PX2BLOCK)fp)->Cd : NULL;
Cd2 = (fp) ? ((PX2BLOCK)fp)->Cd2 : NULL;
} // end of LIBXMLDOC constructor } // end of LIBXMLDOC constructor
/******************************************************************/ /******************************************************************/
...@@ -95,8 +93,6 @@ LIBXMLDOC::LIBXMLDOC(char *nsl, char *nsdf, char *enc, PFBLOCK fp) ...@@ -95,8 +93,6 @@ LIBXMLDOC::LIBXMLDOC(char *nsl, char *nsdf, char *enc, PFBLOCK fp)
bool LIBXMLDOC::Initialize(PGLOBAL g) bool LIBXMLDOC::Initialize(PGLOBAL g)
{ {
//int n = xmlKeepBlanksDefault(0); //int n = xmlKeepBlanksDefault(0);
Cd = iconv_open("ISO-8859-1", "UTF-8");
Cd2 = iconv_open("UTF-8", "ISO-8859-1");
return MakeNSlist(g); return MakeNSlist(g);
} // end of Initialize } // end of Initialize
...@@ -135,8 +131,6 @@ PFBLOCK LIBXMLDOC::LinkXblock(PGLOBAL g, MODE m, int rc, char *fn) ...@@ -135,8 +131,6 @@ PFBLOCK LIBXMLDOC::LinkXblock(PGLOBAL g, MODE m, int rc, char *fn)
xp->Docp = Docp; xp->Docp = Docp;
// xp->Ctxp = Ctxp; // xp->Ctxp = Ctxp;
// xp->Xop = Xop; // xp->Xop = Xop;
xp->Cd = Cd;
xp->Cd2 = Cd2; // Temporary
// Return xp as a fp // Return xp as a fp
return (PFBLOCK)xp; return (PFBLOCK)xp;
...@@ -379,17 +373,12 @@ bool LIBXMLDOC::CheckDocument(FILE *of, xmlNodePtr np) ...@@ -379,17 +373,12 @@ bool LIBXMLDOC::CheckDocument(FILE *of, xmlNodePtr np)
/******************************************************************/ /******************************************************************/
int LIBXMLDOC::Decode(xmlChar *cnt, char *buf, int n) int LIBXMLDOC::Decode(xmlChar *cnt, char *buf, int n)
{ {
#if defined(WIN32) || defined(AIX) uint dummy_errors;
const char *inp = (const char *)cnt; uint32 len= copy_and_convert(buf, n, &my_charset_latin1,
#else cnt, strlen(cnt), &my_charset_utf8_bin,
char *inp = (char *)cnt; &dummy_errors);
#endif buf[len]= '\0';
char *outp = buf; return 0;
size_t i = strlen(inp), o = n;
int rc = iconv(Cd, &inp, &i, &outp, &o);
buf[n - o] = '\0';
return rc;
} // end of Decode } // end of Decode
/******************************************************************/ /******************************************************************/
...@@ -397,27 +386,22 @@ int LIBXMLDOC::Decode(xmlChar *cnt, char *buf, int n) ...@@ -397,27 +386,22 @@ int LIBXMLDOC::Decode(xmlChar *cnt, char *buf, int n)
/******************************************************************/ /******************************************************************/
xmlChar *LIBXMLDOC::Encode(PGLOBAL g, char *txt) xmlChar *LIBXMLDOC::Encode(PGLOBAL g, char *txt)
{ {
#if defined(WIN32) || defined(AIX) const CHARSET_INFO *ics= &my_charset_latin1; // TODO: Field->charset()
const char *inp = (const char *)txt; const CHARSET_INFO *ocs= &my_charset_utf8_bin;
#else size_t i = strlen(txt);
char *inp = (char *)txt; size_t o = i * ocs->mbmaxlen / ics->mbmaxlen + 1;
#endif char *buf;
int rc;
size_t i = strlen(inp);
size_t n, o = 2*i + 1;
char *outp, *buf;
if (g) { if (g) {
n = o; buf = (char*)PlugSubAlloc(g, NULL, o);
buf = (char*)PlugSubAlloc(g, NULL, n);
} else { } else {
n = o = 1024; o = 1024;
buf = Buf; buf = Buf;
} // endif g } // endif g
uint dummy_errors;
outp = buf; uint32 len= copy_and_convert(buf, o, ocs,
rc = iconv(Cd2, &inp, &i, &outp, &o); txt, i, ics,
buf[n - o] = '\0'; &dummy_errors);
buf[len]= '\0';
return BAD_CAST buf; return BAD_CAST buf;
} // end of Encode } // end of Encode
......
...@@ -22,8 +22,6 @@ typedef struct _x2block { /* Loaded XML file block */ ...@@ -22,8 +22,6 @@ typedef struct _x2block { /* Loaded XML file block */
xmlDocPtr Docp; /* Document interface pointer */ xmlDocPtr Docp; /* Document interface pointer */
// xmlXPathContextPtr Ctxp; // xmlXPathContextPtr Ctxp;
// xmlXPathObjectPtr Xop; // xmlXPathObjectPtr Xop;
iconv_t Cd;
iconv_t Cd2;
} X2BLOCK, *PX2BLOCK; } X2BLOCK, *PX2BLOCK;
/******************************************************************/ /******************************************************************/
...@@ -65,8 +63,6 @@ class LIBXMLDOC : public XMLDOCUMENT { ...@@ -65,8 +63,6 @@ class LIBXMLDOC : public XMLDOCUMENT {
xmlNodeSetPtr Nlist; xmlNodeSetPtr Nlist;
xmlXPathContextPtr Ctxp; xmlXPathContextPtr Ctxp;
xmlXPathObjectPtr Xop; xmlXPathObjectPtr Xop;
iconv_t Cd;
iconv_t Cd2; // Temporary
char *Buf; // Temporary char *Buf; // Temporary
}; // end of class LIBXMLDOC }; // end of class LIBXMLDOC
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment