ReactOS  0.4.15-dev-3203-gacde1e0
enc.h File Reference
#include <libxml/tree.h>
Include dependency graph for enc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int xmlCharEncFirstLineInt (xmlCharEncodingHandler *handler, xmlBufferPtr out, xmlBufferPtr in, int len)
 
int xmlCharEncFirstLineInput (xmlParserInputBufferPtr input, int len)
 
int xmlCharEncInput (xmlParserInputBufferPtr input, int flush)
 
int xmlCharEncOutput (xmlOutputBufferPtr output, int init)
 

Function Documentation

◆ xmlCharEncFirstLineInput()

int xmlCharEncFirstLineInput ( xmlParserInputBufferPtr  input,
int  len 
)

xmlCharEncFirstLineInput: @input: a parser input buffer @len: number of bytes to convert for the first line, or -1

Front-end for the encoding handler input function, but handle only the very first line. Point is that this is based on autodetection of the encoding and once that first line is converted we may find out that a different decoder is needed to process the input.

Returns the number of byte written if success, or -1 general error -2 if the transcoding fails (for *in is not valid utf8 string or the result of transformation can't fit into the encoding we want), or

Definition at line 2156 of file encoding.c.

2157 {
2158  int ret;
2159  size_t written;
2160  size_t toconv;
2161  int c_in;
2162  int c_out;
2163  xmlBufPtr in;
2164  xmlBufPtr out;
2165 
2166  if ((input == NULL) || (input->encoder == NULL) ||
2167  (input->buffer == NULL) || (input->raw == NULL))
2168  return (-1);
2169  out = input->buffer;
2170  in = input->raw;
2171 
2172  toconv = xmlBufUse(in);
2173  if (toconv == 0)
2174  return (0);
2175  written = xmlBufAvail(out) - 1; /* count '\0' */
2176  /*
2177  * echo '<?xml version="1.0" encoding="UCS4"?>' | wc -c => 38
2178  * 45 chars should be sufficient to reach the end of the encoding
2179  * declaration without going too far inside the document content.
2180  * on UTF-16 this means 90bytes, on UCS4 this means 180
2181  * The actual value depending on guessed encoding is passed as @len
2182  * if provided
2183  */
2184  if (len >= 0) {
2185  if (toconv > (unsigned int) len)
2186  toconv = len;
2187  } else {
2188  if (toconv > 180)
2189  toconv = 180;
2190  }
2191  if (toconv * 2 >= written) {
2192  xmlBufGrow(out, toconv * 2);
2193  written = xmlBufAvail(out) - 1;
2194  }
2195  if (written > 360)
2196  written = 360;
2197 
2198  c_in = toconv;
2199  c_out = written;
2200  ret = xmlEncInputChunk(input->encoder, xmlBufEnd(out), &c_out,
2201  xmlBufContent(in), &c_in, 0);
2202  xmlBufShrink(in, c_in);
2203  xmlBufAddLen(out, c_out);
2204  if (ret == -1)
2205  ret = -3;
2206 
2207  switch (ret) {
2208  case 0:
2209 #ifdef DEBUG_ENCODING
2211  "converted %d bytes to %d bytes of input\n",
2212  c_in, c_out);
2213 #endif
2214  break;
2215  case -1:
2216 #ifdef DEBUG_ENCODING
2218  "converted %d bytes to %d bytes of input, %d left\n",
2219  c_in, c_out, (int)xmlBufUse(in));
2220 #endif
2221  break;
2222  case -3:
2223 #ifdef DEBUG_ENCODING
2225  "converted %d bytes to %d bytes of input, %d left\n",
2226  c_in, c_out, (int)xmlBufUse(in));
2227 #endif
2228  break;
2229  case -2: {
2230  char buf[50];
2231  const xmlChar *content = xmlBufContent(in);
2232 
2233  snprintf(&buf[0], 49, "0x%02X 0x%02X 0x%02X 0x%02X",
2234  content[0], content[1],
2235  content[2], content[3]);
2236  buf[49] = 0;
2237  xmlEncodingErr(XML_I18N_CONV_FAILED,
2238  "input conversion failed due to input error, bytes %s\n",
2239  buf);
2240  }
2241  }
2242  /*
2243  * Ignore when input buffer is not on a boundary
2244  */
2245  if (ret == -3) ret = 0;
2246  if (ret == -1) ret = 0;
2247  return(c_out ? c_out : ret);
2248 }
int xmlBufGrow(xmlBufPtr buf, int len)
Definition: buf.c:509
XMLPUBFUN xmlChar *XMLCALL xmlBufContent(const xmlBuf *buf)
Definition: buf.c:582
int xmlBufAddLen(xmlBufPtr buf, size_t len)
Definition: buf.c:621
XMLPUBFUN xmlChar *XMLCALL xmlBufEnd(xmlBufPtr buf)
Definition: buf.c:600
#define snprintf
Definition: wintirpc.h:48
static int xmlEncInputChunk(xmlCharEncodingHandler *handler, unsigned char *out, int *outlen, const unsigned char *in, int *inlen, int flush)
Definition: encoding.c:1954
Definition: buf.c:43
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
content
Definition: atl_ax.c:993
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:346
static FILE * out
Definition: regtests2xml.c:44
int ret
unsigned char xmlChar
Definition: xmlstring.h:28
GLenum GLsizei len
Definition: glext.h:6722
size_t xmlBufAvail(const xmlBufPtr buf)
Definition: buf.c:708
GLenum GLenum GLenum input
Definition: glext.h:9031
GLuint in
Definition: glext.h:9616
#define NULL
Definition: types.h:112
XMLPUBFUN size_t XMLCALL xmlBufUse(const xmlBufPtr buf)
Definition: buf.c:687
XMLPUBFUN size_t XMLCALL xmlBufShrink(xmlBufPtr buf, size_t len)
Definition: buf.c:388
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:362

Referenced by xmlSwitchInputEncodingInt().

◆ xmlCharEncFirstLineInt()

int xmlCharEncFirstLineInt ( xmlCharEncodingHandler handler,
xmlBufferPtr  out,
xmlBufferPtr  in,
int  len 
)

xmlCharEncFirstLineInt: @handler: char encoding transformation data structure @out: an xmlBuffer for the output. @in: an xmlBuffer for the input @len: number of bytes to convert for the first line, or -1

Front-end for the encoding handler input function, but handle only the very first line, i.e. limit itself to 45 chars.

Returns the number of byte written if success, or -1 general error -2 if the transcoding fails (for *in is not valid utf8 string or the result of transformation can't fit into the encoding we want), or

Definition at line 2049 of file encoding.c.

2050  {
2051  int ret;
2052  int written;
2053  int toconv;
2054 
2055  if (handler == NULL) return(-1);
2056  if (out == NULL) return(-1);
2057  if (in == NULL) return(-1);
2058 
2059  /* calculate space available */
2060  written = out->size - out->use - 1; /* count '\0' */
2061  toconv = in->use;
2062  /*
2063  * echo '<?xml version="1.0" encoding="UCS4"?>' | wc -c => 38
2064  * 45 chars should be sufficient to reach the end of the encoding
2065  * declaration without going too far inside the document content.
2066  * on UTF-16 this means 90bytes, on UCS4 this means 180
2067  * The actual value depending on guessed encoding is passed as @len
2068  * if provided
2069  */
2070  if (len >= 0) {
2071  if (toconv > len)
2072  toconv = len;
2073  } else {
2074  if (toconv > 180)
2075  toconv = 180;
2076  }
2077  if (toconv * 2 >= written) {
2078  xmlBufferGrow(out, toconv * 2);
2079  written = out->size - out->use - 1;
2080  }
2081 
2082  ret = xmlEncInputChunk(handler, &out->content[out->use], &written,
2083  in->content, &toconv, 0);
2084  xmlBufferShrink(in, toconv);
2085  out->use += written;
2086  out->content[out->use] = 0;
2087  if (ret == -1) ret = -3;
2088 
2089 #ifdef DEBUG_ENCODING
2090  switch (ret) {
2091  case 0:
2093  "converted %d bytes to %d bytes of input\n",
2094  toconv, written);
2095  break;
2096  case -1:
2097  xmlGenericError(xmlGenericErrorContext,"converted %d bytes to %d bytes of input, %d left\n",
2098  toconv, written, in->use);
2099  break;
2100  case -2:
2102  "input conversion failed due to input error\n");
2103  break;
2104  case -3:
2105  xmlGenericError(xmlGenericErrorContext,"converted %d bytes to %d bytes of input, %d left\n",
2106  toconv, written, in->use);
2107  break;
2108  default:
2109  xmlGenericError(xmlGenericErrorContext,"Unknown input conversion failed %d\n", ret);
2110  }
2111 #endif /* DEBUG_ENCODING */
2112  /*
2113  * Ignore when input buffer is not on a boundary
2114  */
2115  if (ret == -3) ret = 0;
2116  if (ret == -1) ret = 0;
2117  return(written ? written : ret);
2118 }
static int xmlEncInputChunk(xmlCharEncodingHandler *handler, unsigned char *out, int *outlen, const unsigned char *in, int *inlen, int flush)
Definition: encoding.c:1954
XMLPUBFUN int XMLCALL xmlBufferGrow(xmlBufferPtr buf, unsigned int len)
XMLPUBFUN int XMLCALL xmlBufferShrink(xmlBufferPtr buf, unsigned int len)
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:346
static FILE * out
Definition: regtests2xml.c:44
int ret
GLenum GLsizei len
Definition: glext.h:6722
GLuint in
Definition: glext.h:9616
#define NULL
Definition: types.h:112
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7786
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:362

Referenced by xmlCharEncFirstLine().

◆ xmlCharEncInput()

int xmlCharEncInput ( xmlParserInputBufferPtr  input,
int  flush 
)

xmlCharEncInput: @input: a parser input buffer @flush: try to flush all the raw buffer

Generic front-end for the encoding handler on parser input

Returns the number of byte written if success, or -1 general error -2 if the transcoding fails (for *in is not valid utf8 string or the result of transformation can't fit into the encoding we want), or

Definition at line 2263 of file encoding.c.

2264 {
2265  int ret;
2266  size_t written;
2267  size_t toconv;
2268  int c_in;
2269  int c_out;
2270  xmlBufPtr in;
2271  xmlBufPtr out;
2272 
2273  if ((input == NULL) || (input->encoder == NULL) ||
2274  (input->buffer == NULL) || (input->raw == NULL))
2275  return (-1);
2276  out = input->buffer;
2277  in = input->raw;
2278 
2279  toconv = xmlBufUse(in);
2280  if (toconv == 0)
2281  return (0);
2282  if ((toconv > 64 * 1024) && (flush == 0))
2283  toconv = 64 * 1024;
2284  written = xmlBufAvail(out);
2285  if (written > 0)
2286  written--; /* count '\0' */
2287  if (toconv * 2 >= written) {
2288  xmlBufGrow(out, toconv * 2);
2289  written = xmlBufAvail(out);
2290  if (written > 0)
2291  written--; /* count '\0' */
2292  }
2293  if ((written > 128 * 1024) && (flush == 0))
2294  written = 128 * 1024;
2295 
2296  c_in = toconv;
2297  c_out = written;
2298  ret = xmlEncInputChunk(input->encoder, xmlBufEnd(out), &c_out,
2299  xmlBufContent(in), &c_in, flush);
2300  xmlBufShrink(in, c_in);
2301  xmlBufAddLen(out, c_out);
2302  if (ret == -1)
2303  ret = -3;
2304 
2305  switch (ret) {
2306  case 0:
2307 #ifdef DEBUG_ENCODING
2309  "converted %d bytes to %d bytes of input\n",
2310  c_in, c_out);
2311 #endif
2312  break;
2313  case -1:
2314 #ifdef DEBUG_ENCODING
2316  "converted %d bytes to %d bytes of input, %d left\n",
2317  c_in, c_out, (int)xmlBufUse(in));
2318 #endif
2319  break;
2320  case -3:
2321 #ifdef DEBUG_ENCODING
2323  "converted %d bytes to %d bytes of input, %d left\n",
2324  c_in, c_out, (int)xmlBufUse(in));
2325 #endif
2326  break;
2327  case -2: {
2328  char buf[50];
2329  const xmlChar *content = xmlBufContent(in);
2330 
2331  snprintf(&buf[0], 49, "0x%02X 0x%02X 0x%02X 0x%02X",
2332  content[0], content[1],
2333  content[2], content[3]);
2334  buf[49] = 0;
2335  xmlEncodingErr(XML_I18N_CONV_FAILED,
2336  "input conversion failed due to input error, bytes %s\n",
2337  buf);
2338  }
2339  }
2340  /*
2341  * Ignore when input buffer is not on a boundary
2342  */
2343  if (ret == -3)
2344  ret = 0;
2345  return (c_out? c_out : ret);
2346 }
int xmlBufGrow(xmlBufPtr buf, int len)
Definition: buf.c:509
XMLPUBFUN xmlChar *XMLCALL xmlBufContent(const xmlBuf *buf)
Definition: buf.c:582
int xmlBufAddLen(xmlBufPtr buf, size_t len)
Definition: buf.c:621
XMLPUBFUN xmlChar *XMLCALL xmlBufEnd(xmlBufPtr buf)
Definition: buf.c:600
#define snprintf
Definition: wintirpc.h:48
static int xmlEncInputChunk(xmlCharEncodingHandler *handler, unsigned char *out, int *outlen, const unsigned char *in, int *inlen, int flush)
Definition: encoding.c:1954
Definition: buf.c:43
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
content
Definition: atl_ax.c:993
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:346
int flush
Definition: zlib.h:309
static FILE * out
Definition: regtests2xml.c:44
int ret
unsigned char xmlChar
Definition: xmlstring.h:28
size_t xmlBufAvail(const xmlBufPtr buf)
Definition: buf.c:708
GLenum GLenum GLenum input
Definition: glext.h:9031
GLuint in
Definition: glext.h:9616
#define NULL
Definition: types.h:112
XMLPUBFUN size_t XMLCALL xmlBufUse(const xmlBufPtr buf)
Definition: buf.c:687
XMLPUBFUN size_t XMLCALL xmlBufShrink(xmlBufPtr buf, size_t len)
Definition: buf.c:388
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:362

Referenced by xmlSwitchInputEncodingInt().

◆ xmlCharEncOutput()

int xmlCharEncOutput ( xmlOutputBufferPtr  output,
int  init 
)