ReactOS  0.4.14-dev-323-g6fe6a88
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 2096 of file encoding.c.

2097 {
2098  int ret;
2099  size_t written;
2100  size_t toconv;
2101  int c_in;
2102  int c_out;
2103  xmlBufPtr in;
2104  xmlBufPtr out;
2105 
2106  if ((input == NULL) || (input->encoder == NULL) ||
2107  (input->buffer == NULL) || (input->raw == NULL))
2108  return (-1);
2109  out = input->buffer;
2110  in = input->raw;
2111 
2112  toconv = xmlBufUse(in);
2113  if (toconv == 0)
2114  return (0);
2115  written = xmlBufAvail(out) - 1; /* count '\0' */
2116  /*
2117  * echo '<?xml version="1.0" encoding="UCS4"?>' | wc -c => 38
2118  * 45 chars should be sufficient to reach the end of the encoding
2119  * declaration without going too far inside the document content.
2120  * on UTF-16 this means 90bytes, on UCS4 this means 180
2121  * The actual value depending on guessed encoding is passed as @len
2122  * if provided
2123  */
2124  if (len >= 0) {
2125  if (toconv > (unsigned int) len)
2126  toconv = len;
2127  } else {
2128  if (toconv > 180)
2129  toconv = 180;
2130  }
2131  if (toconv * 2 >= written) {
2132  xmlBufGrow(out, toconv * 2);
2133  written = xmlBufAvail(out) - 1;
2134  }
2135  if (written > 360)
2136  written = 360;
2137 
2138  c_in = toconv;
2139  c_out = written;
2140  ret = xmlEncInputChunk(input->encoder, xmlBufEnd(out), &c_out,
2141  xmlBufContent(in), &c_in, 0);
2142  xmlBufShrink(in, c_in);
2143  xmlBufAddLen(out, c_out);
2144  if (ret == -1)
2145  ret = -3;
2146 
2147  switch (ret) {
2148  case 0:
2149 #ifdef DEBUG_ENCODING
2151  "converted %d bytes to %d bytes of input\n",
2152  c_in, c_out);
2153 #endif
2154  break;
2155  case -1:
2156 #ifdef DEBUG_ENCODING
2158  "converted %d bytes to %d bytes of input, %d left\n",
2159  c_in, c_out, (int)xmlBufUse(in));
2160 #endif
2161  break;
2162  case -3:
2163 #ifdef DEBUG_ENCODING
2165  "converted %d bytes to %d bytes of input, %d left\n",
2166  c_in, c_out, (int)xmlBufUse(in));
2167 #endif
2168  break;
2169  case -2: {
2170  char buf[50];
2171  const xmlChar *content = xmlBufContent(in);
2172 
2173  snprintf(&buf[0], 49, "0x%02X 0x%02X 0x%02X 0x%02X",
2174  content[0], content[1],
2175  content[2], content[3]);
2176  buf[49] = 0;
2177  xmlEncodingErr(XML_I18N_CONV_FAILED,
2178  "input conversion failed due to input error, bytes %s\n",
2179  buf);
2180  }
2181  }
2182  /*
2183  * Ignore when input buffer is not on a boundary
2184  */
2185  if (ret == -3) ret = 0;
2186  if (ret == -1) ret = 0;
2187  return(ret);
2188 }
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
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
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:1916
Definition: buf.c:43
content
Definition: atl_ax.c:993
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:346
smooth NULL
Definition: ftsmooth.c:416
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
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 enconding 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 1989 of file encoding.c.

1990  {
1991  int ret;
1992  int written;
1993  int toconv;
1994 
1995  if (handler == NULL) return(-1);
1996  if (out == NULL) return(-1);
1997  if (in == NULL) return(-1);
1998 
1999  /* calculate space available */
2000  written = out->size - out->use - 1; /* count '\0' */
2001  toconv = in->use;
2002  /*
2003  * echo '<?xml version="1.0" encoding="UCS4"?>' | wc -c => 38
2004  * 45 chars should be sufficient to reach the end of the encoding
2005  * declaration without going too far inside the document content.
2006  * on UTF-16 this means 90bytes, on UCS4 this means 180
2007  * The actual value depending on guessed encoding is passed as @len
2008  * if provided
2009  */
2010  if (len >= 0) {
2011  if (toconv > len)
2012  toconv = len;
2013  } else {
2014  if (toconv > 180)
2015  toconv = 180;
2016  }
2017  if (toconv * 2 >= written) {
2018  xmlBufferGrow(out, toconv * 2);
2019  written = out->size - out->use - 1;
2020  }
2021 
2022  ret = xmlEncInputChunk(handler, &out->content[out->use], &written,
2023  in->content, &toconv, 0);
2024  xmlBufferShrink(in, toconv);
2025  out->use += written;
2026  out->content[out->use] = 0;
2027  if (ret == -1) ret = -3;
2028 
2029 #ifdef DEBUG_ENCODING
2030  switch (ret) {
2031  case 0:
2033  "converted %d bytes to %d bytes of input\n",
2034  toconv, written);
2035  break;
2036  case -1:
2037  xmlGenericError(xmlGenericErrorContext,"converted %d bytes to %d bytes of input, %d left\n",
2038  toconv, written, in->use);
2039  break;
2040  case -2:
2042  "input conversion failed due to input error\n");
2043  break;
2044  case -3:
2045  xmlGenericError(xmlGenericErrorContext,"converted %d bytes to %d bytes of input, %d left\n",
2046  toconv, written, in->use);
2047  break;
2048  default:
2049  xmlGenericError(xmlGenericErrorContext,"Unknown input conversion failed %d\n", ret);
2050  }
2051 #endif /* DEBUG_ENCODING */
2052  /*
2053  * Ignore when input buffer is not on a boundary
2054  */
2055  if (ret == -3) ret = 0;
2056  if (ret == -1) ret = 0;
2057  return(ret);
2058 }
static int xmlEncInputChunk(xmlCharEncodingHandler *handler, unsigned char *out, int *outlen, const unsigned char *in, int *inlen, int flush)
Definition: encoding.c:1916
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
smooth NULL
Definition: ftsmooth.c:416
static FILE * out
Definition: regtests2xml.c:44
int ret
GLenum GLsizei len
Definition: glext.h:6722
GLuint in
Definition: glext.h:9616
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 2203 of file encoding.c.

2204 {
2205  int ret;
2206  size_t written;
2207  size_t toconv;
2208  int c_in;
2209  int c_out;
2210  xmlBufPtr in;
2211  xmlBufPtr out;
2212 
2213  if ((input == NULL) || (input->encoder == NULL) ||
2214  (input->buffer == NULL) || (input->raw == NULL))
2215  return (-1);
2216  out = input->buffer;
2217  in = input->raw;
2218 
2219  toconv = xmlBufUse(in);
2220  if (toconv == 0)
2221  return (0);
2222  if ((toconv > 64 * 1024) && (flush == 0))
2223  toconv = 64 * 1024;
2224  written = xmlBufAvail(out);
2225  if (written > 0)
2226  written--; /* count '\0' */
2227  if (toconv * 2 >= written) {
2228  xmlBufGrow(out, toconv * 2);
2229  written = xmlBufAvail(out);
2230  if (written > 0)
2231  written--; /* count '\0' */
2232  }
2233  if ((written > 128 * 1024) && (flush == 0))
2234  written = 128 * 1024;
2235 
2236  c_in = toconv;
2237  c_out = written;
2238  ret = xmlEncInputChunk(input->encoder, xmlBufEnd(out), &c_out,
2239  xmlBufContent(in), &c_in, flush);
2240  xmlBufShrink(in, c_in);
2241  xmlBufAddLen(out, c_out);
2242  if (ret == -1)
2243  ret = -3;
2244 
2245  switch (ret) {
2246  case 0:
2247 #ifdef DEBUG_ENCODING
2249  "converted %d bytes to %d bytes of input\n",
2250  c_in, c_out);
2251 #endif
2252  break;
2253  case -1:
2254 #ifdef DEBUG_ENCODING
2256  "converted %d bytes to %d bytes of input, %d left\n",
2257  c_in, c_out, (int)xmlBufUse(in));
2258 #endif
2259  break;
2260  case -3:
2261 #ifdef DEBUG_ENCODING
2263  "converted %d bytes to %d bytes of input, %d left\n",
2264  c_in, c_out, (int)xmlBufUse(in));
2265 #endif
2266  break;
2267  case -2: {
2268  char buf[50];
2269  const xmlChar *content = xmlBufContent(in);
2270 
2271  snprintf(&buf[0], 49, "0x%02X 0x%02X 0x%02X 0x%02X",
2272  content[0], content[1],
2273  content[2], content[3]);
2274  buf[49] = 0;
2275  xmlEncodingErr(XML_I18N_CONV_FAILED,
2276  "input conversion failed due to input error, bytes %s\n",
2277  buf);
2278  }
2279  }
2280  /*
2281  * Ignore when input buffer is not on a boundary
2282  */
2283  if (ret == -3)
2284  ret = 0;
2285  return (c_out? c_out : ret);
2286 }
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
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
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:1916
Definition: buf.c:43
content
Definition: atl_ax.c:993
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:346
smooth NULL
Definition: ftsmooth.c:416
static FILE * out
Definition: regtests2xml.c:44
int flush
Definition: zlib.h:309
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
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 
)