OLD | NEW |
1 /* | 1 /* |
2 * xmlIO.c : implementation of the I/O interfaces used by the parser | 2 * xmlIO.c : implementation of the I/O interfaces used by the parser |
3 * | 3 * |
4 * See Copyright for the status of this software. | 4 * See Copyright for the status of this software. |
5 * | 5 * |
6 * daniel@veillard.com | 6 * daniel@veillard.com |
7 * | 7 * |
8 * 14 Nov 2000 ht - for VMS, truncated name of long functions to under 32 char | 8 * 14 Nov 2000 ht - for VMS, truncated name of long functions to under 32 char |
9 */ | 9 */ |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 #endif | 28 #endif |
29 #ifdef HAVE_UNISTD_H | 29 #ifdef HAVE_UNISTD_H |
30 #include <unistd.h> | 30 #include <unistd.h> |
31 #endif | 31 #endif |
32 #ifdef HAVE_STDLIB_H | 32 #ifdef HAVE_STDLIB_H |
33 #include <stdlib.h> | 33 #include <stdlib.h> |
34 #endif | 34 #endif |
35 #ifdef HAVE_ZLIB_H | 35 #ifdef HAVE_ZLIB_H |
36 #include <zlib.h> | 36 #include <zlib.h> |
37 #endif | 37 #endif |
| 38 #ifdef HAVE_LZMA_H |
| 39 #include <lzma.h> |
| 40 #endif |
38 | 41 |
39 #if defined(WIN32) || defined(_WIN32) | 42 #if defined(WIN32) || defined(_WIN32) |
40 #include <windows.h> | 43 #include <windows.h> |
41 #endif | 44 #endif |
42 | 45 |
43 #if defined(_WIN32_WCE) | 46 #if defined(_WIN32_WCE) |
44 #include <winnls.h> /* for CP_UTF8 */ | 47 #include <winnls.h> /* for CP_UTF8 */ |
45 #endif | 48 #endif |
46 | 49 |
47 /* Figure a portable way to know if a file is a directory. */ | 50 /* Figure a portable way to know if a file is a directory. */ |
(...skipping 30 matching lines...) Expand all Loading... |
78 # endif | 81 # endif |
79 # endif | 82 # endif |
80 # endif | 83 # endif |
81 #endif | 84 #endif |
82 | 85 |
83 #include <libxml/xmlmemory.h> | 86 #include <libxml/xmlmemory.h> |
84 #include <libxml/parser.h> | 87 #include <libxml/parser.h> |
85 #include <libxml/parserInternals.h> | 88 #include <libxml/parserInternals.h> |
86 #include <libxml/xmlIO.h> | 89 #include <libxml/xmlIO.h> |
87 #include <libxml/uri.h> | 90 #include <libxml/uri.h> |
| 91 #include <libxml/nanohttp.h> |
| 92 #include <libxml/nanoftp.h> |
88 #include <libxml/xmlerror.h> | 93 #include <libxml/xmlerror.h> |
89 #ifdef LIBXML_CATALOG_ENABLED | 94 #ifdef LIBXML_CATALOG_ENABLED |
90 #include <libxml/catalog.h> | 95 #include <libxml/catalog.h> |
91 #endif | 96 #endif |
92 #include <libxml/globals.h> | 97 #include <libxml/globals.h> |
93 | 98 |
| 99 #include "buf.h" |
| 100 #include "enc.h" |
| 101 |
94 /* #define VERBOSE_FAILURE */ | 102 /* #define VERBOSE_FAILURE */ |
95 /* #define DEBUG_EXTERNAL_ENTITIES */ | 103 /* #define DEBUG_EXTERNAL_ENTITIES */ |
96 /* #define DEBUG_INPUT */ | 104 /* #define DEBUG_INPUT */ |
97 | 105 |
98 #ifdef DEBUG_INPUT | 106 #ifdef DEBUG_INPUT |
99 #define MINLEN 40 | 107 #define MINLEN 40 |
100 #else | 108 #else |
101 #define MINLEN 4000 | 109 #define MINLEN 4000 |
102 #endif | 110 #endif |
103 | 111 |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 * returns 1. if stat fails, returns 0 (if calling | 764 * returns 1. if stat fails, returns 0 (if calling |
757 * stat on the filename fails, it can't be right). | 765 * stat on the filename fails, it can't be right). |
758 * if stat succeeds and the file is a directory, | 766 * if stat succeeds and the file is a directory, |
759 * returns 2. otherwise returns 1. | 767 * returns 2. otherwise returns 1. |
760 */ | 768 */ |
761 | 769 |
762 int | 770 int |
763 xmlCheckFilename (const char *path) | 771 xmlCheckFilename (const char *path) |
764 { | 772 { |
765 #ifdef HAVE_STAT | 773 #ifdef HAVE_STAT |
766 » struct stat stat_buffer; | 774 struct stat stat_buffer; |
767 #endif | 775 #endif |
768 » if (path == NULL) | 776 if (path == NULL) |
769 » » return(0); | 777 » return(0); |
770 | 778 |
771 #ifdef HAVE_STAT | 779 #ifdef HAVE_STAT |
772 #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) | 780 #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) |
| 781 /* |
| 782 * On Windows stat and wstat do not work with long pathname, |
| 783 * which start with '\\?\' |
| 784 */ |
| 785 if ((path[0] == '\\') && (path[1] == '\\') && (path[2] == '?') && |
| 786 (path[3] == '\\') ) |
| 787 return 1; |
| 788 |
773 if (xmlWrapStat(path, &stat_buffer) == -1) | 789 if (xmlWrapStat(path, &stat_buffer) == -1) |
774 return 0; | 790 return 0; |
775 #else | 791 #else |
776 if (stat(path, &stat_buffer) == -1) | 792 if (stat(path, &stat_buffer) == -1) |
777 return 0; | 793 return 0; |
778 #endif | 794 #endif |
779 #ifdef S_ISDIR | 795 #ifdef S_ISDIR |
780 if (S_ISDIR(stat_buffer.st_mode)) | 796 if (S_ISDIR(stat_buffer.st_mode)) |
781 return 2; | 797 return 2; |
782 #endif | 798 #endif |
783 #endif /* HAVE_STAT */ | 799 #endif /* HAVE_STAT */ |
784 return 1; | 800 return 1; |
785 } | 801 } |
786 | 802 |
787 static int | 803 /** |
| 804 * xmlNop: |
| 805 * |
| 806 * No Operation function, does nothing, no input |
| 807 * |
| 808 * Returns zero |
| 809 */ |
| 810 int |
788 xmlNop(void) { | 811 xmlNop(void) { |
789 return(0); | 812 return(0); |
790 } | 813 } |
791 | 814 |
792 /** | 815 /** |
793 * xmlFdRead: | 816 * xmlFdRead: |
794 * @context: the I/O context | 817 * @context: the I/O context |
795 * @buffer: where to drop data | 818 * @buffer: where to drop data |
796 * @len: number of bytes to read | 819 * @len: number of bytes to read |
797 * | 820 * |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 * xmlFileOpen_real: | 887 * xmlFileOpen_real: |
865 * @filename: the URI for matching | 888 * @filename: the URI for matching |
866 * | 889 * |
867 * input from FILE *, supports compressed input | 890 * input from FILE *, supports compressed input |
868 * if @filename is " " then the standard input is used | 891 * if @filename is " " then the standard input is used |
869 * | 892 * |
870 * Returns an I/O context or NULL in case of error | 893 * Returns an I/O context or NULL in case of error |
871 */ | 894 */ |
872 static void * | 895 static void * |
873 xmlFileOpen_real (const char *filename) { | 896 xmlFileOpen_real (const char *filename) { |
874 const char *path = NULL; | 897 const char *path = filename; |
875 FILE *fd; | 898 FILE *fd; |
876 | 899 |
877 if (filename == NULL) | 900 if (filename == NULL) |
878 return(NULL); | 901 return(NULL); |
879 | 902 |
880 if (!strcmp(filename, "-")) { | 903 if (!strcmp(filename, "-")) { |
881 fd = stdin; | 904 fd = stdin; |
882 return((void *) fd); | 905 return((void *) fd); |
883 } | 906 } |
884 | 907 |
885 if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file://localhost/", 17)) { | 908 if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file://localhost/", 17)) { |
886 #if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) | 909 #if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) |
887 path = &filename[17]; | 910 path = &filename[17]; |
888 #else | 911 #else |
889 path = &filename[16]; | 912 path = &filename[16]; |
890 #endif | 913 #endif |
891 } else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:///", 8)) { | 914 } else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:///", 8)) { |
892 #if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) | 915 #if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) |
893 path = &filename[8]; | 916 path = &filename[8]; |
894 #else | 917 #else |
895 path = &filename[7]; | 918 path = &filename[7]; |
896 #endif | 919 #endif |
897 } else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:/", 6)) { | 920 } else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:/", 6)) { |
898 /* lots of generators seems to lazy to read RFC 1738 */ | 921 /* lots of generators seems to lazy to read RFC 1738 */ |
899 #if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) | 922 #if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) |
900 path = &filename[6]; | 923 path = &filename[6]; |
901 #else | 924 #else |
902 path = &filename[5]; | 925 path = &filename[5]; |
903 #endif | 926 #endif |
904 } else | 927 } |
905 » path = filename; | |
906 | 928 |
907 if (path == NULL) | |
908 return(NULL); | |
909 if (!xmlCheckFilename(path)) | 929 if (!xmlCheckFilename(path)) |
910 return(NULL); | 930 return(NULL); |
911 | 931 |
912 #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) | 932 #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) |
913 fd = xmlWrapOpen(path, 0); | 933 fd = xmlWrapOpen(path, 0); |
914 #else | 934 #else |
915 fd = fopen(path, "r"); | 935 fd = fopen(path, "r"); |
916 #endif /* WIN32 */ | 936 #endif /* WIN32 */ |
917 if (fd == NULL) xmlIOErr(0, path); | 937 if (fd == NULL) xmlIOErr(0, path); |
918 return((void *) fd); | 938 return((void *) fd); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 #endif | 998 #endif |
979 } else | 999 } else |
980 path = filename; | 1000 path = filename; |
981 | 1001 |
982 if (path == NULL) | 1002 if (path == NULL) |
983 return(NULL); | 1003 return(NULL); |
984 | 1004 |
985 #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) | 1005 #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) |
986 fd = xmlWrapOpen(path, 1); | 1006 fd = xmlWrapOpen(path, 1); |
987 #else | 1007 #else |
988 » fd = fopen(path, "wb"); | 1008 » fd = fopen(path, "wb"); |
989 #endif /* WIN32 */ | 1009 #endif /* WIN32 */ |
990 | 1010 |
991 if (fd == NULL) xmlIOErr(0, path); | 1011 if (fd == NULL) xmlIOErr(0, path); |
992 return((void *) fd); | 1012 return((void *) fd); |
993 } | 1013 } |
994 #endif /* LIBXML_OUTPUT_ENABLED */ | 1014 #endif /* LIBXML_OUTPUT_ENABLED */ |
995 | 1015 |
996 /** | 1016 /** |
997 * xmlFileRead: | 1017 * xmlFileRead: |
998 * @context: the I/O context | 1018 * @context: the I/O context |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 * if @filename is " " then the standard input is used | 1156 * if @filename is " " then the standard input is used |
1137 * | 1157 * |
1138 * Returns an I/O context or NULL in case of error | 1158 * Returns an I/O context or NULL in case of error |
1139 */ | 1159 */ |
1140 static void * | 1160 static void * |
1141 xmlGzfileOpen_real (const char *filename) { | 1161 xmlGzfileOpen_real (const char *filename) { |
1142 const char *path = NULL; | 1162 const char *path = NULL; |
1143 gzFile fd; | 1163 gzFile fd; |
1144 | 1164 |
1145 if (!strcmp(filename, "-")) { | 1165 if (!strcmp(filename, "-")) { |
1146 fd = gzdopen(dup(0), "rb"); | 1166 int duped_fd = dup(fileno(stdin)); |
| 1167 fd = gzdopen(duped_fd, "rb"); |
| 1168 if (fd == Z_NULL && duped_fd >= 0) { |
| 1169 close(duped_fd); /* gzdOpen() does not close on failure */ |
| 1170 } |
| 1171 |
1147 return((void *) fd); | 1172 return((void *) fd); |
1148 } | 1173 } |
1149 | 1174 |
1150 if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file://localhost/", 17)) | 1175 if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file://localhost/", 17)) |
1151 #if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) | 1176 #if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) |
1152 path = &filename[17]; | 1177 path = &filename[17]; |
1153 #else | 1178 #else |
1154 path = &filename[16]; | 1179 path = &filename[16]; |
1155 #endif | 1180 #endif |
1156 else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:///", 8)) { | 1181 else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:///", 8)) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1210 * Returns an I/O context or NULL in case of error | 1235 * Returns an I/O context or NULL in case of error |
1211 */ | 1236 */ |
1212 static void * | 1237 static void * |
1213 xmlGzfileOpenW (const char *filename, int compression) { | 1238 xmlGzfileOpenW (const char *filename, int compression) { |
1214 const char *path = NULL; | 1239 const char *path = NULL; |
1215 char mode[15]; | 1240 char mode[15]; |
1216 gzFile fd; | 1241 gzFile fd; |
1217 | 1242 |
1218 snprintf(mode, sizeof(mode), "wb%d", compression); | 1243 snprintf(mode, sizeof(mode), "wb%d", compression); |
1219 if (!strcmp(filename, "-")) { | 1244 if (!strcmp(filename, "-")) { |
1220 fd = gzdopen(dup(1), mode); | 1245 int duped_fd = dup(fileno(stdout)); |
| 1246 fd = gzdopen(duped_fd, "rb"); |
| 1247 if (fd == Z_NULL && duped_fd >= 0) { |
| 1248 close(duped_fd); /* gzdOpen() does not close on failure */ |
| 1249 } |
| 1250 |
1221 return((void *) fd); | 1251 return((void *) fd); |
1222 } | 1252 } |
1223 | 1253 |
1224 if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file://localhost/", 17)) | 1254 if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file://localhost/", 17)) |
1225 #if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) | 1255 #if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) |
1226 path = &filename[17]; | 1256 path = &filename[17]; |
1227 #else | 1257 #else |
1228 path = &filename[16]; | 1258 path = &filename[16]; |
1229 #endif | 1259 #endif |
1230 else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:///", 8)) { | 1260 else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:///", 8)) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1297 static int | 1327 static int |
1298 xmlGzfileClose (void * context) { | 1328 xmlGzfileClose (void * context) { |
1299 int ret; | 1329 int ret; |
1300 | 1330 |
1301 ret = (gzclose((gzFile) context) == Z_OK ) ? 0 : -1; | 1331 ret = (gzclose((gzFile) context) == Z_OK ) ? 0 : -1; |
1302 if (ret < 0) xmlIOErr(0, "gzclose()"); | 1332 if (ret < 0) xmlIOErr(0, "gzclose()"); |
1303 return(ret); | 1333 return(ret); |
1304 } | 1334 } |
1305 #endif /* HAVE_ZLIB_H */ | 1335 #endif /* HAVE_ZLIB_H */ |
1306 | 1336 |
| 1337 #ifdef HAVE_LZMA_H |
| 1338 /************************************************************************ |
| 1339 * * |
| 1340 * I/O for compressed file accesses * |
| 1341 * * |
| 1342 ************************************************************************/ |
| 1343 #include "xzlib.h" |
| 1344 /** |
| 1345 * xmlXzfileMatch: |
| 1346 * @filename: the URI for matching |
| 1347 * |
| 1348 * input from compressed file test |
| 1349 * |
| 1350 * Returns 1 if matches, 0 otherwise |
| 1351 */ |
| 1352 static int |
| 1353 xmlXzfileMatch (const char *filename ATTRIBUTE_UNUSED) { |
| 1354 return(1); |
| 1355 } |
| 1356 |
| 1357 /** |
| 1358 * xmlXzFileOpen_real: |
| 1359 * @filename: the URI for matching |
| 1360 * |
| 1361 * input from compressed file open |
| 1362 * if @filename is " " then the standard input is used |
| 1363 * |
| 1364 * Returns an I/O context or NULL in case of error |
| 1365 */ |
| 1366 static void * |
| 1367 xmlXzfileOpen_real (const char *filename) { |
| 1368 const char *path = NULL; |
| 1369 xzFile fd; |
| 1370 |
| 1371 if (!strcmp(filename, "-")) { |
| 1372 fd = __libxml2_xzdopen(dup(fileno(stdin)), "rb"); |
| 1373 return((void *) fd); |
| 1374 } |
| 1375 |
| 1376 if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file://localhost/", 17)) { |
| 1377 path = &filename[16]; |
| 1378 } else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:///", 8)) { |
| 1379 path = &filename[7]; |
| 1380 } else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:/", 6)) { |
| 1381 /* lots of generators seems to lazy to read RFC 1738 */ |
| 1382 path = &filename[5]; |
| 1383 } else |
| 1384 path = filename; |
| 1385 |
| 1386 if (path == NULL) |
| 1387 return(NULL); |
| 1388 if (!xmlCheckFilename(path)) |
| 1389 return(NULL); |
| 1390 |
| 1391 fd = __libxml2_xzopen(path, "rb"); |
| 1392 return((void *) fd); |
| 1393 } |
| 1394 |
| 1395 /** |
| 1396 * xmlXzfileOpen: |
| 1397 * @filename: the URI for matching |
| 1398 * |
| 1399 * Wrapper around xmlXzfileOpen_real that try it with an unescaped |
| 1400 * version of @filename, if this fails fallback to @filename |
| 1401 * |
| 1402 * Returns a handler or NULL in case or failure |
| 1403 */ |
| 1404 static void * |
| 1405 xmlXzfileOpen (const char *filename) { |
| 1406 char *unescaped; |
| 1407 void *retval; |
| 1408 |
| 1409 retval = xmlXzfileOpen_real(filename); |
| 1410 if (retval == NULL) { |
| 1411 unescaped = xmlURIUnescapeString(filename, 0, NULL); |
| 1412 if (unescaped != NULL) { |
| 1413 retval = xmlXzfileOpen_real(unescaped); |
| 1414 } |
| 1415 xmlFree(unescaped); |
| 1416 } |
| 1417 |
| 1418 return retval; |
| 1419 } |
| 1420 |
| 1421 /** |
| 1422 * xmlXzfileRead: |
| 1423 * @context: the I/O context |
| 1424 * @buffer: where to drop data |
| 1425 * @len: number of bytes to write |
| 1426 * |
| 1427 * Read @len bytes to @buffer from the compressed I/O channel. |
| 1428 * |
| 1429 * Returns the number of bytes written |
| 1430 */ |
| 1431 static int |
| 1432 xmlXzfileRead (void * context, char * buffer, int len) { |
| 1433 int ret; |
| 1434 |
| 1435 ret = __libxml2_xzread((xzFile) context, &buffer[0], len); |
| 1436 if (ret < 0) xmlIOErr(0, "xzread()"); |
| 1437 return(ret); |
| 1438 } |
| 1439 |
| 1440 /** |
| 1441 * xmlXzfileClose: |
| 1442 * @context: the I/O context |
| 1443 * |
| 1444 * Close a compressed I/O channel |
| 1445 */ |
| 1446 static int |
| 1447 xmlXzfileClose (void * context) { |
| 1448 int ret; |
| 1449 |
| 1450 ret = (__libxml2_xzclose((xzFile) context) == LZMA_OK ) ? 0 : -1; |
| 1451 if (ret < 0) xmlIOErr(0, "xzclose()"); |
| 1452 return(ret); |
| 1453 } |
| 1454 #endif /* HAVE_LZMA_H */ |
| 1455 |
1307 #ifdef LIBXML_HTTP_ENABLED | 1456 #ifdef LIBXML_HTTP_ENABLED |
1308 /************************************************************************ | 1457 /************************************************************************ |
1309 * * | 1458 * * |
1310 * I/O for HTTP file accesses * | 1459 * I/O for HTTP file accesses * |
1311 * * | 1460 * * |
1312 ************************************************************************/ | 1461 ************************************************************************/ |
1313 | 1462 |
1314 #ifdef LIBXML_OUTPUT_ENABLED | 1463 #ifdef LIBXML_OUTPUT_ENABLED |
1315 typedef struct xmlIOHTTPWriteCtxt_ | 1464 typedef struct xmlIOHTTPWriteCtxt_ |
1316 { | 1465 { |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1905 if ( ctxt->compression > 0 ) { | 2054 if ( ctxt->compression > 0 ) { |
1906 content_lgth = xmlZMemBuffGetContent( ctxt->doc_buff, &http_content ); | 2055 content_lgth = xmlZMemBuffGetContent( ctxt->doc_buff, &http_content ); |
1907 content_encoding = (char *) "Content-Encoding: gzip"; | 2056 content_encoding = (char *) "Content-Encoding: gzip"; |
1908 } | 2057 } |
1909 else | 2058 else |
1910 #endif | 2059 #endif |
1911 { | 2060 { |
1912 /* Pull the data out of the memory output buffer */ | 2061 /* Pull the data out of the memory output buffer */ |
1913 | 2062 |
1914 xmlOutputBufferPtr dctxt = ctxt->doc_buff; | 2063 xmlOutputBufferPtr dctxt = ctxt->doc_buff; |
1915 » http_content = (char *)dctxt->buffer->content; | 2064 » http_content = (char *) xmlBufContent(dctxt->buffer); |
1916 » content_lgth = dctxt->buffer->use; | 2065 » content_lgth = xmlBufUse(dctxt->buffer); |
1917 } | 2066 } |
1918 | 2067 |
1919 if ( http_content == NULL ) { | 2068 if ( http_content == NULL ) { |
1920 xmlChar msg[500]; | 2069 xmlChar msg[500]; |
1921 xmlStrPrintf(msg, 500, | 2070 xmlStrPrintf(msg, 500, |
1922 (const xmlChar *) "xmlIOHTTPCloseWrite: %s '%s' %s '%s'.\n
", | 2071 (const xmlChar *) "xmlIOHTTPCloseWrite: %s '%s' %s '%s'.\n
", |
1923 "Error retrieving content.\nUnable to", | 2072 "Error retrieving content.\nUnable to", |
1924 http_mthd, "data to URI", ctxt->uri ); | 2073 http_mthd, "data to URI", ctxt->uri ); |
1925 xmlIOErr(XML_IO_WRITE, (const char *) msg); | 2074 xmlIOErr(XML_IO_WRITE, (const char *) msg); |
1926 } | 2075 } |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2172 #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) | 2321 #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) |
2173 xmlInitPlatformSpecificIo(); | 2322 xmlInitPlatformSpecificIo(); |
2174 #endif | 2323 #endif |
2175 | 2324 |
2176 xmlRegisterInputCallbacks(xmlFileMatch, xmlFileOpen, | 2325 xmlRegisterInputCallbacks(xmlFileMatch, xmlFileOpen, |
2177 xmlFileRead, xmlFileClose); | 2326 xmlFileRead, xmlFileClose); |
2178 #ifdef HAVE_ZLIB_H | 2327 #ifdef HAVE_ZLIB_H |
2179 xmlRegisterInputCallbacks(xmlGzfileMatch, xmlGzfileOpen, | 2328 xmlRegisterInputCallbacks(xmlGzfileMatch, xmlGzfileOpen, |
2180 xmlGzfileRead, xmlGzfileClose); | 2329 xmlGzfileRead, xmlGzfileClose); |
2181 #endif /* HAVE_ZLIB_H */ | 2330 #endif /* HAVE_ZLIB_H */ |
| 2331 #ifdef HAVE_LZMA_H |
| 2332 xmlRegisterInputCallbacks(xmlXzfileMatch, xmlXzfileOpen, |
| 2333 xmlXzfileRead, xmlXzfileClose); |
| 2334 #endif /* HAVE_ZLIB_H */ |
2182 | 2335 |
2183 #ifdef LIBXML_HTTP_ENABLED | 2336 #ifdef LIBXML_HTTP_ENABLED |
2184 xmlRegisterInputCallbacks(xmlIOHTTPMatch, xmlIOHTTPOpen, | 2337 xmlRegisterInputCallbacks(xmlIOHTTPMatch, xmlIOHTTPOpen, |
2185 xmlIOHTTPRead, xmlIOHTTPClose); | 2338 xmlIOHTTPRead, xmlIOHTTPClose); |
2186 #endif /* LIBXML_HTTP_ENABLED */ | 2339 #endif /* LIBXML_HTTP_ENABLED */ |
2187 | 2340 |
2188 #ifdef LIBXML_FTP_ENABLED | 2341 #ifdef LIBXML_FTP_ENABLED |
2189 xmlRegisterInputCallbacks(xmlIOFTPMatch, xmlIOFTPOpen, | 2342 xmlRegisterInputCallbacks(xmlIOFTPMatch, xmlIOFTPOpen, |
2190 xmlIOFTPRead, xmlIOFTPClose); | 2343 xmlIOFTPRead, xmlIOFTPClose); |
2191 #endif /* LIBXML_FTP_ENABLED */ | 2344 #endif /* LIBXML_FTP_ENABLED */ |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2269 xmlParserInputBufferPtr | 2422 xmlParserInputBufferPtr |
2270 xmlAllocParserInputBuffer(xmlCharEncoding enc) { | 2423 xmlAllocParserInputBuffer(xmlCharEncoding enc) { |
2271 xmlParserInputBufferPtr ret; | 2424 xmlParserInputBufferPtr ret; |
2272 | 2425 |
2273 ret = (xmlParserInputBufferPtr) xmlMalloc(sizeof(xmlParserInputBuffer)); | 2426 ret = (xmlParserInputBufferPtr) xmlMalloc(sizeof(xmlParserInputBuffer)); |
2274 if (ret == NULL) { | 2427 if (ret == NULL) { |
2275 xmlIOErrMemory("creating input buffer"); | 2428 xmlIOErrMemory("creating input buffer"); |
2276 return(NULL); | 2429 return(NULL); |
2277 } | 2430 } |
2278 memset(ret, 0, (size_t) sizeof(xmlParserInputBuffer)); | 2431 memset(ret, 0, (size_t) sizeof(xmlParserInputBuffer)); |
2279 ret->buffer = xmlBufferCreateSize(2 * xmlDefaultBufferSize); | 2432 ret->buffer = xmlBufCreateSize(2 * xmlDefaultBufferSize); |
2280 if (ret->buffer == NULL) { | 2433 if (ret->buffer == NULL) { |
2281 xmlFree(ret); | 2434 xmlFree(ret); |
2282 return(NULL); | 2435 return(NULL); |
2283 } | 2436 } |
2284 ret->buffer->alloc = XML_BUFFER_ALLOC_DOUBLEIT; | 2437 xmlBufSetAllocationScheme(ret->buffer, XML_BUFFER_ALLOC_DOUBLEIT); |
2285 ret->encoder = xmlGetCharEncodingHandler(enc); | 2438 ret->encoder = xmlGetCharEncodingHandler(enc); |
2286 if (ret->encoder != NULL) | 2439 if (ret->encoder != NULL) |
2287 ret->raw = xmlBufferCreateSize(2 * xmlDefaultBufferSize); | 2440 ret->raw = xmlBufCreateSize(2 * xmlDefaultBufferSize); |
2288 else | 2441 else |
2289 ret->raw = NULL; | 2442 ret->raw = NULL; |
2290 ret->readcallback = NULL; | 2443 ret->readcallback = NULL; |
2291 ret->closecallback = NULL; | 2444 ret->closecallback = NULL; |
2292 ret->context = NULL; | 2445 ret->context = NULL; |
2293 ret->compressed = -1; | 2446 ret->compressed = -1; |
2294 ret->rawconsumed = 0; | 2447 ret->rawconsumed = 0; |
2295 | 2448 |
2296 return(ret); | 2449 return(ret); |
2297 } | 2450 } |
(...skipping 10 matching lines...) Expand all Loading... |
2308 xmlOutputBufferPtr | 2461 xmlOutputBufferPtr |
2309 xmlAllocOutputBuffer(xmlCharEncodingHandlerPtr encoder) { | 2462 xmlAllocOutputBuffer(xmlCharEncodingHandlerPtr encoder) { |
2310 xmlOutputBufferPtr ret; | 2463 xmlOutputBufferPtr ret; |
2311 | 2464 |
2312 ret = (xmlOutputBufferPtr) xmlMalloc(sizeof(xmlOutputBuffer)); | 2465 ret = (xmlOutputBufferPtr) xmlMalloc(sizeof(xmlOutputBuffer)); |
2313 if (ret == NULL) { | 2466 if (ret == NULL) { |
2314 xmlIOErrMemory("creating output buffer"); | 2467 xmlIOErrMemory("creating output buffer"); |
2315 return(NULL); | 2468 return(NULL); |
2316 } | 2469 } |
2317 memset(ret, 0, (size_t) sizeof(xmlOutputBuffer)); | 2470 memset(ret, 0, (size_t) sizeof(xmlOutputBuffer)); |
2318 ret->buffer = xmlBufferCreate(); | 2471 ret->buffer = xmlBufCreate(); |
2319 if (ret->buffer == NULL) { | 2472 if (ret->buffer == NULL) { |
2320 xmlFree(ret); | 2473 xmlFree(ret); |
2321 return(NULL); | 2474 return(NULL); |
2322 } | 2475 } |
2323 | 2476 |
2324 /* try to avoid a performance problem with Windows realloc() */ | 2477 /* try to avoid a performance problem with Windows realloc() */ |
2325 if (ret->buffer->alloc == XML_BUFFER_ALLOC_EXACT) | 2478 if (xmlBufGetAllocationScheme(ret->buffer) == XML_BUFFER_ALLOC_EXACT) |
2326 ret->buffer->alloc = XML_BUFFER_ALLOC_DOUBLEIT; | 2479 xmlBufSetAllocationScheme(ret->buffer, XML_BUFFER_ALLOC_DOUBLEIT); |
2327 | 2480 |
2328 ret->encoder = encoder; | 2481 ret->encoder = encoder; |
2329 if (encoder != NULL) { | 2482 if (encoder != NULL) { |
2330 ret->conv = xmlBufferCreateSize(4000); | 2483 ret->conv = xmlBufCreateSize(4000); |
2331 if (ret->conv == NULL) { | 2484 if (ret->conv == NULL) { |
2332 xmlFree(ret); | 2485 xmlFree(ret); |
2333 return(NULL); | 2486 return(NULL); |
2334 } | 2487 } |
2335 | 2488 |
2336 /* | 2489 /* |
2337 * This call is designed to initiate the encoder state | 2490 * This call is designed to initiate the encoder state |
2338 */ | 2491 */ |
2339 » xmlCharEncOutFunc(encoder, ret->conv, NULL); | 2492 » xmlCharEncOutput(ret, 1); |
2340 } else | 2493 } else |
2341 ret->conv = NULL; | 2494 ret->conv = NULL; |
2342 ret->writecallback = NULL; | 2495 ret->writecallback = NULL; |
2343 ret->closecallback = NULL; | 2496 ret->closecallback = NULL; |
2344 ret->context = NULL; | 2497 ret->context = NULL; |
2345 ret->written = 0; | 2498 ret->written = 0; |
2346 | 2499 |
2347 return(ret); | 2500 return(ret); |
2348 } | 2501 } |
2349 | 2502 |
2350 /** | 2503 /** |
2351 * xmlAllocOutputBufferInternal: | 2504 * xmlAllocOutputBufferInternal: |
2352 * @encoder: the encoding converter or NULL | 2505 * @encoder: the encoding converter or NULL |
2353 * | 2506 * |
2354 * Create a buffered parser output | 2507 * Create a buffered parser output |
2355 * | 2508 * |
2356 * Returns the new parser output or NULL | 2509 * Returns the new parser output or NULL |
2357 */ | 2510 */ |
2358 xmlOutputBufferPtr | 2511 xmlOutputBufferPtr |
2359 xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr encoder) { | 2512 xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr encoder) { |
2360 xmlOutputBufferPtr ret; | 2513 xmlOutputBufferPtr ret; |
2361 | 2514 |
2362 ret = (xmlOutputBufferPtr) xmlMalloc(sizeof(xmlOutputBuffer)); | 2515 ret = (xmlOutputBufferPtr) xmlMalloc(sizeof(xmlOutputBuffer)); |
2363 if (ret == NULL) { | 2516 if (ret == NULL) { |
2364 xmlIOErrMemory("creating output buffer"); | 2517 xmlIOErrMemory("creating output buffer"); |
2365 return(NULL); | 2518 return(NULL); |
2366 } | 2519 } |
2367 memset(ret, 0, (size_t) sizeof(xmlOutputBuffer)); | 2520 memset(ret, 0, (size_t) sizeof(xmlOutputBuffer)); |
2368 ret->buffer = xmlBufferCreate(); | 2521 ret->buffer = xmlBufCreate(); |
2369 if (ret->buffer == NULL) { | 2522 if (ret->buffer == NULL) { |
2370 xmlFree(ret); | 2523 xmlFree(ret); |
2371 return(NULL); | 2524 return(NULL); |
2372 } | 2525 } |
2373 | 2526 |
2374 | 2527 |
2375 /* | 2528 /* |
2376 * For conversion buffers we use the special IO handling | 2529 * For conversion buffers we use the special IO handling |
2377 * We don't do that from the exported API to avoid confusing | |
2378 * user's code. | |
2379 */ | 2530 */ |
2380 ret->buffer->alloc = XML_BUFFER_ALLOC_IO; | 2531 xmlBufSetAllocationScheme(ret->buffer, XML_BUFFER_ALLOC_IO); |
2381 ret->buffer->contentIO = ret->buffer->content; | |
2382 | 2532 |
2383 ret->encoder = encoder; | 2533 ret->encoder = encoder; |
2384 if (encoder != NULL) { | 2534 if (encoder != NULL) { |
2385 ret->conv = xmlBufferCreateSize(4000); | 2535 ret->conv = xmlBufCreateSize(4000); |
2386 if (ret->conv == NULL) { | 2536 if (ret->conv == NULL) { |
2387 xmlFree(ret); | 2537 xmlFree(ret); |
2388 return(NULL); | 2538 return(NULL); |
2389 } | 2539 } |
2390 | 2540 |
2391 /* | 2541 /* |
2392 * This call is designed to initiate the encoder state | 2542 * This call is designed to initiate the encoder state |
2393 */ | 2543 */ |
2394 » xmlCharEncOutFunc(encoder, ret->conv, NULL); | 2544 xmlCharEncOutput(ret, 1); |
2395 } else | 2545 } else |
2396 ret->conv = NULL; | 2546 ret->conv = NULL; |
2397 ret->writecallback = NULL; | 2547 ret->writecallback = NULL; |
2398 ret->closecallback = NULL; | 2548 ret->closecallback = NULL; |
2399 ret->context = NULL; | 2549 ret->context = NULL; |
2400 ret->written = 0; | 2550 ret->written = 0; |
2401 | 2551 |
2402 return(ret); | 2552 return(ret); |
2403 } | 2553 } |
2404 | 2554 |
2405 #endif /* LIBXML_OUTPUT_ENABLED */ | 2555 #endif /* LIBXML_OUTPUT_ENABLED */ |
2406 | 2556 |
2407 /** | 2557 /** |
2408 * xmlFreeParserInputBuffer: | 2558 * xmlFreeParserInputBuffer: |
2409 * @in: a buffered parser input | 2559 * @in: a buffered parser input |
2410 * | 2560 * |
2411 * Free up the memory used by a buffered parser input | 2561 * Free up the memory used by a buffered parser input |
2412 */ | 2562 */ |
2413 void | 2563 void |
2414 xmlFreeParserInputBuffer(xmlParserInputBufferPtr in) { | 2564 xmlFreeParserInputBuffer(xmlParserInputBufferPtr in) { |
2415 if (in == NULL) return; | 2565 if (in == NULL) return; |
2416 | 2566 |
2417 if (in->raw) { | 2567 if (in->raw) { |
2418 xmlBufferFree(in->raw); | 2568 xmlBufFree(in->raw); |
2419 in->raw = NULL; | 2569 in->raw = NULL; |
2420 } | 2570 } |
2421 if (in->encoder != NULL) { | 2571 if (in->encoder != NULL) { |
2422 xmlCharEncCloseFunc(in->encoder); | 2572 xmlCharEncCloseFunc(in->encoder); |
2423 } | 2573 } |
2424 if (in->closecallback != NULL) { | 2574 if (in->closecallback != NULL) { |
2425 in->closecallback(in->context); | 2575 in->closecallback(in->context); |
2426 } | 2576 } |
2427 if (in->buffer != NULL) { | 2577 if (in->buffer != NULL) { |
2428 xmlBufferFree(in->buffer); | 2578 xmlBufFree(in->buffer); |
2429 in->buffer = NULL; | 2579 in->buffer = NULL; |
2430 } | 2580 } |
2431 | 2581 |
2432 xmlFree(in); | 2582 xmlFree(in); |
2433 } | 2583 } |
2434 | 2584 |
2435 #ifdef LIBXML_OUTPUT_ENABLED | 2585 #ifdef LIBXML_OUTPUT_ENABLED |
2436 /** | 2586 /** |
2437 * xmlOutputBufferClose: | 2587 * xmlOutputBufferClose: |
2438 * @out: a buffered output | 2588 * @out: a buffered output |
(...skipping 11 matching lines...) Expand all Loading... |
2450 | 2600 |
2451 if (out == NULL) | 2601 if (out == NULL) |
2452 return (-1); | 2602 return (-1); |
2453 if (out->writecallback != NULL) | 2603 if (out->writecallback != NULL) |
2454 xmlOutputBufferFlush(out); | 2604 xmlOutputBufferFlush(out); |
2455 if (out->closecallback != NULL) { | 2605 if (out->closecallback != NULL) { |
2456 err_rc = out->closecallback(out->context); | 2606 err_rc = out->closecallback(out->context); |
2457 } | 2607 } |
2458 written = out->written; | 2608 written = out->written; |
2459 if (out->conv) { | 2609 if (out->conv) { |
2460 xmlBufferFree(out->conv); | 2610 xmlBufFree(out->conv); |
2461 out->conv = NULL; | 2611 out->conv = NULL; |
2462 } | 2612 } |
2463 if (out->encoder != NULL) { | 2613 if (out->encoder != NULL) { |
2464 xmlCharEncCloseFunc(out->encoder); | 2614 xmlCharEncCloseFunc(out->encoder); |
2465 } | 2615 } |
2466 if (out->buffer != NULL) { | 2616 if (out->buffer != NULL) { |
2467 xmlBufferFree(out->buffer); | 2617 xmlBufFree(out->buffer); |
2468 out->buffer = NULL; | 2618 out->buffer = NULL; |
2469 } | 2619 } |
2470 | 2620 |
2471 if (out->error) | 2621 if (out->error) |
2472 err_rc = -1; | 2622 err_rc = -1; |
2473 xmlFree(out); | 2623 xmlFree(out); |
2474 return ((err_rc == 0) ? written : err_rc); | 2624 return ((err_rc == 0) ? written : err_rc); |
2475 } | 2625 } |
2476 #endif /* LIBXML_OUTPUT_ENABLED */ | 2626 #endif /* LIBXML_OUTPUT_ENABLED */ |
2477 | 2627 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2526 if (strncmp(buff4, cptr, 4) == 0) | 2676 if (strncmp(buff4, cptr, 4) == 0) |
2527 ret->compressed = 0; | 2677 ret->compressed = 0; |
2528 else | 2678 else |
2529 ret->compressed = 1; | 2679 ret->compressed = 1; |
2530 gzrewind(context); | 2680 gzrewind(context); |
2531 } | 2681 } |
2532 } | 2682 } |
2533 #endif | 2683 #endif |
2534 } | 2684 } |
2535 #endif | 2685 #endif |
| 2686 #ifdef HAVE_LZMA_H |
| 2687 if ((xmlInputCallbackTable[i].opencallback == xmlXzfileOpen) && |
| 2688 (strcmp(URI, "-") != 0)) { |
| 2689 ret->compressed = __libxml2_xzcompressed(context); |
| 2690 } |
| 2691 #endif |
2536 } | 2692 } |
2537 else | 2693 else |
2538 xmlInputCallbackTable[i].closecallback (context); | 2694 xmlInputCallbackTable[i].closecallback (context); |
2539 | 2695 |
2540 return(ret); | 2696 return(ret); |
2541 } | 2697 } |
2542 | 2698 |
2543 /** | 2699 /** |
2544 * xmlParserInputBufferCreateFilename: | 2700 * xmlParserInputBufferCreateFilename: |
2545 * @URI: a C string containing the URI or filename | 2701 * @URI: a C string containing the URI or filename |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2787 if (buffer == NULL) return(NULL); | 2943 if (buffer == NULL) return(NULL); |
2788 | 2944 |
2789 ret = xmlOutputBufferCreateIO((xmlOutputWriteCallback) | 2945 ret = xmlOutputBufferCreateIO((xmlOutputWriteCallback) |
2790 xmlBufferWrite, | 2946 xmlBufferWrite, |
2791 (xmlOutputCloseCallback) | 2947 (xmlOutputCloseCallback) |
2792 NULL, (void *) buffer, encoder); | 2948 NULL, (void *) buffer, encoder); |
2793 | 2949 |
2794 return(ret); | 2950 return(ret); |
2795 } | 2951 } |
2796 | 2952 |
| 2953 /** |
| 2954 * xmlOutputBufferGetContent: |
| 2955 * @out: an xmlOutputBufferPtr |
| 2956 * |
| 2957 * Gives a pointer to the data currently held in the output buffer |
| 2958 * |
| 2959 * Returns a pointer to the data or NULL in case of error |
| 2960 */ |
| 2961 const xmlChar * |
| 2962 xmlOutputBufferGetContent(xmlOutputBufferPtr out) { |
| 2963 if ((out == NULL) || (out->buffer == NULL)) |
| 2964 return(NULL); |
| 2965 |
| 2966 return(xmlBufContent(out->buffer)); |
| 2967 } |
| 2968 |
| 2969 /** |
| 2970 * xmlOutputBufferGetSize: |
| 2971 * @out: an xmlOutputBufferPtr |
| 2972 * |
| 2973 * Gives the length of the data currently held in the output buffer |
| 2974 * |
| 2975 * Returns 0 in case or error or no data is held, the size otherwise |
| 2976 */ |
| 2977 size_t |
| 2978 xmlOutputBufferGetSize(xmlOutputBufferPtr out) { |
| 2979 if ((out == NULL) || (out->buffer == NULL)) |
| 2980 return(0); |
| 2981 |
| 2982 return(xmlBufUse(out->buffer)); |
| 2983 } |
| 2984 |
| 2985 |
2797 #endif /* LIBXML_OUTPUT_ENABLED */ | 2986 #endif /* LIBXML_OUTPUT_ENABLED */ |
2798 | 2987 |
2799 /** | 2988 /** |
2800 * xmlParserInputBufferCreateFd: | 2989 * xmlParserInputBufferCreateFd: |
2801 * @fd: a file descriptor number | 2990 * @fd: a file descriptor number |
2802 * @enc: the charset encoding if known | 2991 * @enc: the charset encoding if known |
2803 * | 2992 * |
2804 * Create a buffered parser input for the progressive parsing for the input | 2993 * Create a buffered parser input for the progressive parsing for the input |
2805 * from a file descriptor | 2994 * from a file descriptor |
2806 * | 2995 * |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2839 int errcode; | 3028 int errcode; |
2840 | 3029 |
2841 if (size <= 0) return(NULL); | 3030 if (size <= 0) return(NULL); |
2842 if (mem == NULL) return(NULL); | 3031 if (mem == NULL) return(NULL); |
2843 | 3032 |
2844 ret = xmlAllocParserInputBuffer(enc); | 3033 ret = xmlAllocParserInputBuffer(enc); |
2845 if (ret != NULL) { | 3034 if (ret != NULL) { |
2846 ret->context = (void *) mem; | 3035 ret->context = (void *) mem; |
2847 ret->readcallback = (xmlInputReadCallback) xmlNop; | 3036 ret->readcallback = (xmlInputReadCallback) xmlNop; |
2848 ret->closecallback = NULL; | 3037 ret->closecallback = NULL; |
2849 » errcode = xmlBufferAdd(ret->buffer, (const xmlChar *) mem, size); | 3038 » errcode = xmlBufAdd(ret->buffer, (const xmlChar *) mem, size); |
2850 if (errcode != 0) { | 3039 if (errcode != 0) { |
2851 xmlFree(ret); | 3040 xmlFree(ret); |
2852 return(NULL); | 3041 return(NULL); |
2853 } | 3042 } |
2854 } | 3043 } |
2855 | 3044 |
2856 return(ret); | 3045 return(ret); |
2857 } | 3046 } |
2858 | 3047 |
2859 /** | 3048 /** |
(...skipping 16 matching lines...) Expand all Loading... |
2876 | 3065 |
2877 if (size <= 0) return(NULL); | 3066 if (size <= 0) return(NULL); |
2878 if (mem == NULL) return(NULL); | 3067 if (mem == NULL) return(NULL); |
2879 | 3068 |
2880 ret = (xmlParserInputBufferPtr) xmlMalloc(sizeof(xmlParserInputBuffer)); | 3069 ret = (xmlParserInputBufferPtr) xmlMalloc(sizeof(xmlParserInputBuffer)); |
2881 if (ret == NULL) { | 3070 if (ret == NULL) { |
2882 xmlIOErrMemory("creating input buffer"); | 3071 xmlIOErrMemory("creating input buffer"); |
2883 return(NULL); | 3072 return(NULL); |
2884 } | 3073 } |
2885 memset(ret, 0, (size_t) sizeof(xmlParserInputBuffer)); | 3074 memset(ret, 0, (size_t) sizeof(xmlParserInputBuffer)); |
2886 ret->buffer = xmlBufferCreateStatic((void *)mem, (size_t) size); | 3075 ret->buffer = xmlBufCreateStatic((void *)mem, (size_t) size); |
2887 if (ret->buffer == NULL) { | 3076 if (ret->buffer == NULL) { |
2888 xmlFree(ret); | 3077 xmlFree(ret); |
2889 return(NULL); | 3078 return(NULL); |
2890 } | 3079 } |
2891 ret->encoder = xmlGetCharEncodingHandler(enc); | 3080 ret->encoder = xmlGetCharEncodingHandler(enc); |
2892 if (ret->encoder != NULL) | 3081 if (ret->encoder != NULL) |
2893 ret->raw = xmlBufferCreateSize(2 * xmlDefaultBufferSize); | 3082 ret->raw = xmlBufCreateSize(2 * xmlDefaultBufferSize); |
2894 else | 3083 else |
2895 ret->raw = NULL; | 3084 ret->raw = NULL; |
2896 ret->compressed = -1; | 3085 ret->compressed = -1; |
2897 ret->context = (void *) mem; | 3086 ret->context = (void *) mem; |
2898 ret->readcallback = NULL; | 3087 ret->readcallback = NULL; |
2899 ret->closecallback = NULL; | 3088 ret->closecallback = NULL; |
2900 | 3089 |
2901 return(ret); | 3090 return(ret); |
2902 } | 3091 } |
2903 | 3092 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3052 | 3241 |
3053 if (len < 0) return(0); | 3242 if (len < 0) return(0); |
3054 if ((in == NULL) || (in->error)) return(-1); | 3243 if ((in == NULL) || (in->error)) return(-1); |
3055 if (in->encoder != NULL) { | 3244 if (in->encoder != NULL) { |
3056 unsigned int use; | 3245 unsigned int use; |
3057 | 3246 |
3058 /* | 3247 /* |
3059 * Store the data in the incoming raw buffer | 3248 * Store the data in the incoming raw buffer |
3060 */ | 3249 */ |
3061 if (in->raw == NULL) { | 3250 if (in->raw == NULL) { |
3062 » in->raw = xmlBufferCreate(); | 3251 » in->raw = xmlBufCreate(); |
3063 } | 3252 } |
3064 » ret = xmlBufferAdd(in->raw, (const xmlChar *) buf, len); | 3253 » ret = xmlBufAdd(in->raw, (const xmlChar *) buf, len); |
3065 if (ret != 0) | 3254 if (ret != 0) |
3066 return(-1); | 3255 return(-1); |
3067 | 3256 |
3068 /* | 3257 /* |
3069 * convert as much as possible to the parser reading buffer. | 3258 * convert as much as possible to the parser reading buffer. |
3070 */ | 3259 */ |
3071 » use = in->raw->use; | 3260 » use = xmlBufUse(in->raw); |
3072 » nbchars = xmlCharEncInFunc(in->encoder, in->buffer, in->raw); | 3261 » nbchars = xmlCharEncInput(in, 1); |
3073 if (nbchars < 0) { | 3262 if (nbchars < 0) { |
3074 xmlIOErr(XML_IO_ENCODER, NULL); | 3263 xmlIOErr(XML_IO_ENCODER, NULL); |
3075 in->error = XML_IO_ENCODER; | 3264 in->error = XML_IO_ENCODER; |
3076 return(-1); | 3265 return(-1); |
3077 } | 3266 } |
3078 » in->rawconsumed += (use - in->raw->use); | 3267 » in->rawconsumed += (use - xmlBufUse(in->raw)); |
3079 } else { | 3268 } else { |
3080 nbchars = len; | 3269 nbchars = len; |
3081 ret = xmlBufferAdd(in->buffer, (xmlChar *) buf, nbchars); | 3270 ret = xmlBufAdd(in->buffer, (xmlChar *) buf, nbchars); |
3082 if (ret != 0) | 3271 if (ret != 0) |
3083 return(-1); | 3272 return(-1); |
3084 } | 3273 } |
3085 #ifdef DEBUG_INPUT | 3274 #ifdef DEBUG_INPUT |
3086 xmlGenericError(xmlGenericErrorContext, | 3275 xmlGenericError(xmlGenericErrorContext, |
3087 "I/O: pushed %d chars, buffer %d/%d\n", | 3276 "I/O: pushed %d chars, buffer %d/%d\n", |
3088 nbchars, in->buffer->use, in->buffer->size); | 3277 nbchars, xmlBufUse(in->buffer), xmlBufLength(in->buffer)); |
3089 #endif | 3278 #endif |
3090 return(nbchars); | 3279 return(nbchars); |
3091 } | 3280 } |
3092 | 3281 |
3093 /** | 3282 /** |
3094 * endOfInput: | 3283 * endOfInput: |
3095 * | 3284 * |
3096 * When reading from an Input channel indicated end of file or error | 3285 * When reading from an Input channel indicated end of file or error |
3097 * don't reread from it again. | 3286 * don't reread from it again. |
3098 */ | 3287 */ |
(...skipping 17 matching lines...) Expand all Loading... |
3116 * onto in->buffer or in->raw | 3305 * onto in->buffer or in->raw |
3117 * | 3306 * |
3118 * Returns the number of chars read and stored in the buffer, or -1 | 3307 * Returns the number of chars read and stored in the buffer, or -1 |
3119 * in case of error. | 3308 * in case of error. |
3120 */ | 3309 */ |
3121 int | 3310 int |
3122 xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len) { | 3311 xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len) { |
3123 char *buffer = NULL; | 3312 char *buffer = NULL; |
3124 int res = 0; | 3313 int res = 0; |
3125 int nbchars = 0; | 3314 int nbchars = 0; |
3126 int buffree; | |
3127 unsigned int needSize; | |
3128 | 3315 |
3129 if ((in == NULL) || (in->error)) return(-1); | 3316 if ((in == NULL) || (in->error)) return(-1); |
3130 if ((len <= MINLEN) && (len != 4)) | 3317 if ((len <= MINLEN) && (len != 4)) |
3131 len = MINLEN; | 3318 len = MINLEN; |
3132 | 3319 |
3133 buffree = in->buffer->size - in->buffer->use; | 3320 if (xmlBufAvail(in->buffer) <= 0) { |
3134 if (buffree <= 0) { | |
3135 xmlIOErr(XML_IO_BUFFER_FULL, NULL); | 3321 xmlIOErr(XML_IO_BUFFER_FULL, NULL); |
3136 in->error = XML_IO_BUFFER_FULL; | 3322 in->error = XML_IO_BUFFER_FULL; |
3137 return(-1); | 3323 return(-1); |
3138 } | 3324 } |
3139 | 3325 |
3140 needSize = in->buffer->use + len + 1; | 3326 if (xmlBufGrow(in->buffer, len + 1) < 0) { |
3141 if (needSize > in->buffer->size){ | 3327 xmlIOErrMemory("growing input buffer"); |
3142 if (!xmlBufferResize(in->buffer, needSize)){ | 3328 in->error = XML_ERR_NO_MEMORY; |
3143 » xmlIOErrMemory("growing input buffer"); | 3329 return(-1); |
3144 » in->error = XML_ERR_NO_MEMORY; | |
3145 return(-1); | |
3146 } | |
3147 } | 3330 } |
3148 buffer = (char *)&in->buffer->content[in->buffer->use]; | 3331 buffer = (char *)xmlBufEnd(in->buffer); |
3149 | 3332 |
3150 /* | 3333 /* |
3151 * Call the read method for this I/O type. | 3334 * Call the read method for this I/O type. |
3152 */ | 3335 */ |
3153 if (in->readcallback != NULL) { | 3336 if (in->readcallback != NULL) { |
3154 res = in->readcallback(in->context, &buffer[0], len); | 3337 res = in->readcallback(in->context, &buffer[0], len); |
3155 if (res <= 0) | 3338 if (res <= 0) |
3156 in->readcallback = endOfInput; | 3339 in->readcallback = endOfInput; |
3157 } else { | 3340 } else { |
3158 xmlIOErr(XML_IO_NO_INPUT, NULL); | 3341 xmlIOErr(XML_IO_NO_INPUT, NULL); |
3159 in->error = XML_IO_NO_INPUT; | 3342 in->error = XML_IO_NO_INPUT; |
3160 return(-1); | 3343 return(-1); |
3161 } | 3344 } |
3162 if (res < 0) { | 3345 if (res < 0) { |
3163 return(-1); | 3346 return(-1); |
3164 } | 3347 } |
| 3348 |
| 3349 /* |
| 3350 * try to establish compressed status of input if not done already |
| 3351 */ |
| 3352 if (in->compressed == -1) { |
| 3353 #ifdef HAVE_LZMA_H |
| 3354 if (in->readcallback == xmlXzfileRead) |
| 3355 in->compressed = __libxml2_xzcompressed(in->context); |
| 3356 #endif |
| 3357 } |
| 3358 |
3165 len = res; | 3359 len = res; |
3166 if (in->encoder != NULL) { | 3360 if (in->encoder != NULL) { |
3167 unsigned int use; | 3361 unsigned int use; |
3168 | 3362 |
3169 /* | 3363 /* |
3170 * Store the data in the incoming raw buffer | 3364 * Store the data in the incoming raw buffer |
3171 */ | 3365 */ |
3172 if (in->raw == NULL) { | 3366 if (in->raw == NULL) { |
3173 » in->raw = xmlBufferCreate(); | 3367 » in->raw = xmlBufCreate(); |
3174 } | 3368 } |
3175 » res = xmlBufferAdd(in->raw, (const xmlChar *) buffer, len); | 3369 » res = xmlBufAdd(in->raw, (const xmlChar *) buffer, len); |
3176 if (res != 0) | 3370 if (res != 0) |
3177 return(-1); | 3371 return(-1); |
3178 | 3372 |
3179 /* | 3373 /* |
3180 * convert as much as possible to the parser reading buffer. | 3374 * convert as much as possible to the parser reading buffer. |
3181 */ | 3375 */ |
3182 » use = in->raw->use; | 3376 » use = xmlBufUse(in->raw); |
3183 » nbchars = xmlCharEncInFunc(in->encoder, in->buffer, in->raw); | 3377 » nbchars = xmlCharEncInput(in, 1); |
3184 if (nbchars < 0) { | 3378 if (nbchars < 0) { |
3185 xmlIOErr(XML_IO_ENCODER, NULL); | 3379 xmlIOErr(XML_IO_ENCODER, NULL); |
3186 in->error = XML_IO_ENCODER; | 3380 in->error = XML_IO_ENCODER; |
3187 return(-1); | 3381 return(-1); |
3188 } | 3382 } |
3189 » in->rawconsumed += (use - in->raw->use); | 3383 » in->rawconsumed += (use - xmlBufUse(in->raw)); |
3190 } else { | 3384 } else { |
3191 nbchars = len; | 3385 nbchars = len; |
3192 » in->buffer->use += nbchars; | 3386 xmlBufAddLen(in->buffer, nbchars); |
3193 » buffer[nbchars] = 0; | |
3194 } | 3387 } |
3195 #ifdef DEBUG_INPUT | 3388 #ifdef DEBUG_INPUT |
3196 xmlGenericError(xmlGenericErrorContext, | 3389 xmlGenericError(xmlGenericErrorContext, |
3197 » "I/O: read %d chars, buffer %d/%d\n", | 3390 » "I/O: read %d chars, buffer %d\n", |
3198 nbchars, in->buffer->use, in->buffer->size); | 3391 nbchars, xmlBufUse(in->buffer)); |
3199 #endif | 3392 #endif |
3200 return(nbchars); | 3393 return(nbchars); |
3201 } | 3394 } |
3202 | 3395 |
3203 /** | 3396 /** |
3204 * xmlParserInputBufferRead: | 3397 * xmlParserInputBufferRead: |
3205 * @in: a buffered parser input | 3398 * @in: a buffered parser input |
3206 * @len: indicative value of the amount of chars to read | 3399 * @len: indicative value of the amount of chars to read |
3207 * | 3400 * |
3208 * Refresh the content of the input buffer, the old data are considered | 3401 * Refresh the content of the input buffer, the old data are considered |
3209 * consumed | 3402 * consumed |
3210 * This routine handle the I18N transcoding to internal UTF-8 | 3403 * This routine handle the I18N transcoding to internal UTF-8 |
3211 * | 3404 * |
3212 * Returns the number of chars read and stored in the buffer, or -1 | 3405 * Returns the number of chars read and stored in the buffer, or -1 |
3213 * in case of error. | 3406 * in case of error. |
3214 */ | 3407 */ |
3215 int | 3408 int |
3216 xmlParserInputBufferRead(xmlParserInputBufferPtr in, int len) { | 3409 xmlParserInputBufferRead(xmlParserInputBufferPtr in, int len) { |
3217 if ((in == NULL) || (in->error)) return(-1); | 3410 if ((in == NULL) || (in->error)) return(-1); |
3218 if (in->readcallback != NULL) | 3411 if (in->readcallback != NULL) |
3219 return(xmlParserInputBufferGrow(in, len)); | 3412 return(xmlParserInputBufferGrow(in, len)); |
3220 else if ((in->buffer != NULL) && | 3413 else if (xmlBufGetAllocationScheme(in->buffer) == XML_BUFFER_ALLOC_IMMUTABLE
) |
3221 (in->buffer->alloc == XML_BUFFER_ALLOC_IMMUTABLE)) | |
3222 return(0); | 3414 return(0); |
3223 else | 3415 else |
3224 return(-1); | 3416 return(-1); |
3225 } | 3417 } |
3226 | 3418 |
3227 #ifdef LIBXML_OUTPUT_ENABLED | 3419 #ifdef LIBXML_OUTPUT_ENABLED |
3228 /** | 3420 /** |
3229 * xmlOutputBufferWrite: | 3421 * xmlOutputBufferWrite: |
3230 * @out: a buffered parser output | 3422 * @out: a buffered parser output |
3231 * @len: the size in bytes of the array. | 3423 * @len: the size in bytes of the array. |
(...skipping 24 matching lines...) Expand all Loading... |
3256 chunk = 4 * MINLEN; | 3448 chunk = 4 * MINLEN; |
3257 | 3449 |
3258 /* | 3450 /* |
3259 * first handle encoding stuff. | 3451 * first handle encoding stuff. |
3260 */ | 3452 */ |
3261 if (out->encoder != NULL) { | 3453 if (out->encoder != NULL) { |
3262 /* | 3454 /* |
3263 * Store the data in the incoming raw buffer | 3455 * Store the data in the incoming raw buffer |
3264 */ | 3456 */ |
3265 if (out->conv == NULL) { | 3457 if (out->conv == NULL) { |
3266 » » out->conv = xmlBufferCreate(); | 3458 » » out->conv = xmlBufCreate(); |
3267 } | 3459 } |
3268 » ret = xmlBufferAdd(out->buffer, (const xmlChar *) buf, chunk); | 3460 » ret = xmlBufAdd(out->buffer, (const xmlChar *) buf, chunk); |
3269 if (ret != 0) | 3461 if (ret != 0) |
3270 return(-1); | 3462 return(-1); |
3271 | 3463 |
3272 » if ((out->buffer->use < MINLEN) && (chunk == len)) | 3464 » if ((xmlBufUse(out->buffer) < MINLEN) && (chunk == len)) |
3273 goto done; | 3465 goto done; |
3274 | 3466 |
3275 /* | 3467 /* |
3276 * convert as much as possible to the parser reading buffer. | 3468 * convert as much as possible to the parser reading buffer. |
3277 */ | 3469 */ |
3278 » ret = xmlCharEncOutFunc(out->encoder, out->conv, out->buffer); | 3470 » ret = xmlCharEncOutput(out, 0); |
3279 if ((ret < 0) && (ret != -3)) { | 3471 if ((ret < 0) && (ret != -3)) { |
3280 xmlIOErr(XML_IO_ENCODER, NULL); | 3472 xmlIOErr(XML_IO_ENCODER, NULL); |
3281 out->error = XML_IO_ENCODER; | 3473 out->error = XML_IO_ENCODER; |
3282 return(-1); | 3474 return(-1); |
3283 } | 3475 } |
3284 » nbchars = out->conv->use; | 3476 » nbchars = xmlBufUse(out->conv); |
3285 } else { | 3477 } else { |
3286 » ret = xmlBufferAdd(out->buffer, (const xmlChar *) buf, chunk); | 3478 » ret = xmlBufAdd(out->buffer, (const xmlChar *) buf, chunk); |
3287 if (ret != 0) | 3479 if (ret != 0) |
3288 return(-1); | 3480 return(-1); |
3289 » nbchars = out->buffer->use; | 3481 » nbchars = xmlBufUse(out->buffer); |
3290 } | 3482 } |
3291 buf += chunk; | 3483 buf += chunk; |
3292 len -= chunk; | 3484 len -= chunk; |
3293 | 3485 |
3294 if ((nbchars < MINLEN) && (len <= 0)) | 3486 if ((nbchars < MINLEN) && (len <= 0)) |
3295 goto done; | 3487 goto done; |
3296 | 3488 |
3297 if (out->writecallback) { | 3489 if (out->writecallback) { |
3298 /* | 3490 /* |
3299 * second write the stuff to the I/O channel | 3491 * second write the stuff to the I/O channel |
3300 */ | 3492 */ |
3301 if (out->encoder != NULL) { | 3493 if (out->encoder != NULL) { |
3302 ret = out->writecallback(out->context, | 3494 ret = out->writecallback(out->context, |
3303 » » » » (const char *)out->conv->content, nbchars); | 3495 (const char *)xmlBufContent(out->conv), nbchars); |
3304 if (ret >= 0) | 3496 if (ret >= 0) |
3305 » » xmlBufferShrink(out->conv, ret); | 3497 » » xmlBufShrink(out->conv, ret); |
3306 } else { | 3498 } else { |
3307 ret = out->writecallback(out->context, | 3499 ret = out->writecallback(out->context, |
3308 » » » » (const char *)out->buffer->content, nbchars); | 3500 (const char *)xmlBufContent(out->buffer), nbchars); |
3309 if (ret >= 0) | 3501 if (ret >= 0) |
3310 » » xmlBufferShrink(out->buffer, ret); | 3502 » » xmlBufShrink(out->buffer, ret); |
3311 } | 3503 } |
3312 if (ret < 0) { | 3504 if (ret < 0) { |
3313 xmlIOErr(XML_IO_WRITE, NULL); | 3505 xmlIOErr(XML_IO_WRITE, NULL); |
3314 out->error = XML_IO_WRITE; | 3506 out->error = XML_IO_WRITE; |
3315 return(ret); | 3507 return(ret); |
3316 } | 3508 } |
3317 out->written += ret; | 3509 out->written += ret; |
3318 } | 3510 } |
3319 written += nbchars; | 3511 written += nbchars; |
3320 } while (len > 0); | 3512 } while (len > 0); |
(...skipping 23 matching lines...) Expand all Loading... |
3344 xmlEscapeContent(unsigned char* out, int *outlen, | 3536 xmlEscapeContent(unsigned char* out, int *outlen, |
3345 const xmlChar* in, int *inlen) { | 3537 const xmlChar* in, int *inlen) { |
3346 unsigned char* outstart = out; | 3538 unsigned char* outstart = out; |
3347 const unsigned char* base = in; | 3539 const unsigned char* base = in; |
3348 unsigned char* outend = out + *outlen; | 3540 unsigned char* outend = out + *outlen; |
3349 const unsigned char* inend; | 3541 const unsigned char* inend; |
3350 | 3542 |
3351 inend = in + (*inlen); | 3543 inend = in + (*inlen); |
3352 | 3544 |
3353 while ((in < inend) && (out < outend)) { | 3545 while ((in < inend) && (out < outend)) { |
3354 » if (*in == '<') { | 3546 » if (*in == '<') { |
3355 if (outend - out < 4) break; | 3547 if (outend - out < 4) break; |
3356 *out++ = '&'; | 3548 *out++ = '&'; |
3357 *out++ = 'l'; | 3549 *out++ = 'l'; |
3358 *out++ = 't'; | 3550 *out++ = 't'; |
3359 *out++ = ';'; | 3551 *out++ = ';'; |
3360 } else if (*in == '>') { | 3552 } else if (*in == '>') { |
3361 if (outend - out < 4) break; | 3553 if (outend - out < 4) break; |
3362 *out++ = '&'; | 3554 *out++ = '&'; |
3363 *out++ = 'g'; | 3555 *out++ = 'g'; |
3364 *out++ = 't'; | 3556 *out++ = 't'; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3408 int nbchars = 0; /* number of chars to output to I/O */ | 3600 int nbchars = 0; /* number of chars to output to I/O */ |
3409 int ret; /* return from function call */ | 3601 int ret; /* return from function call */ |
3410 int written = 0; /* number of char written to I/O so far */ | 3602 int written = 0; /* number of char written to I/O so far */ |
3411 int oldwritten=0;/* loop guard */ | 3603 int oldwritten=0;/* loop guard */ |
3412 int chunk; /* number of byte currently processed from str */ | 3604 int chunk; /* number of byte currently processed from str */ |
3413 int len; /* number of bytes in str */ | 3605 int len; /* number of bytes in str */ |
3414 int cons; /* byte from str consumed */ | 3606 int cons; /* byte from str consumed */ |
3415 | 3607 |
3416 if ((out == NULL) || (out->error) || (str == NULL) || | 3608 if ((out == NULL) || (out->error) || (str == NULL) || |
3417 (out->buffer == NULL) || | 3609 (out->buffer == NULL) || |
3418 » (out->buffer->alloc == XML_BUFFER_ALLOC_IMMUTABLE)) return(-1); | 3610 » (xmlBufGetAllocationScheme(out->buffer) == XML_BUFFER_ALLOC_IMMUTABLE)) |
| 3611 return(-1); |
3419 len = strlen((const char *)str); | 3612 len = strlen((const char *)str); |
3420 if (len < 0) return(0); | 3613 if (len < 0) return(0); |
3421 if (out->error) return(-1); | 3614 if (out->error) return(-1); |
3422 if (escaping == NULL) escaping = xmlEscapeContent; | 3615 if (escaping == NULL) escaping = xmlEscapeContent; |
3423 | 3616 |
3424 do { | 3617 do { |
3425 oldwritten = written; | 3618 oldwritten = written; |
3426 | 3619 |
3427 /* | 3620 /* |
3428 * how many bytes to consume and how many bytes to store. | 3621 * how many bytes to consume and how many bytes to store. |
3429 */ | 3622 */ |
3430 cons = len; | 3623 cons = len; |
3431 » chunk = (out->buffer->size - out->buffer->use) - 1; | 3624 » chunk = xmlBufAvail(out->buffer) - 1; |
3432 | 3625 |
3433 /* | 3626 /* |
3434 * make sure we have enough room to save first, if this is | 3627 * make sure we have enough room to save first, if this is |
3435 * not the case force a flush, but make sure we stay in the loop | 3628 * not the case force a flush, but make sure we stay in the loop |
3436 */ | 3629 */ |
3437 if (chunk < 40) { | 3630 if (chunk < 40) { |
3438 » if (xmlBufferGrow(out->buffer, out->buffer->size + 100) < 0) | 3631 » if (xmlBufGrow(out->buffer, 100) < 0) |
3439 return(-1); | 3632 return(-1); |
3440 oldwritten = -1; | 3633 oldwritten = -1; |
3441 continue; | 3634 continue; |
3442 } | 3635 } |
3443 | 3636 |
3444 /* | 3637 /* |
3445 * first handle encoding stuff. | 3638 * first handle encoding stuff. |
3446 */ | 3639 */ |
3447 if (out->encoder != NULL) { | 3640 if (out->encoder != NULL) { |
3448 /* | 3641 /* |
3449 * Store the data in the incoming raw buffer | 3642 * Store the data in the incoming raw buffer |
3450 */ | 3643 */ |
3451 if (out->conv == NULL) { | 3644 if (out->conv == NULL) { |
3452 » » out->conv = xmlBufferCreate(); | 3645 » » out->conv = xmlBufCreate(); |
3453 } | 3646 } |
3454 » ret = escaping(out->buffer->content + out->buffer->use , | 3647 » ret = escaping(xmlBufEnd(out->buffer) , |
3455 &chunk, str, &cons); | 3648 &chunk, str, &cons); |
3456 if ((ret < 0) || (chunk == 0)) /* chunk==0 => nothing done */ | 3649 if ((ret < 0) || (chunk == 0)) /* chunk==0 => nothing done */ |
3457 return(-1); | 3650 return(-1); |
3458 » out->buffer->use += chunk; | 3651 xmlBufAddLen(out->buffer, chunk); |
3459 » out->buffer->content[out->buffer->use] = 0; | |
3460 | 3652 |
3461 » if ((out->buffer->use < MINLEN) && (cons == len)) | 3653 » if ((xmlBufUse(out->buffer) < MINLEN) && (cons == len)) |
3462 goto done; | 3654 goto done; |
3463 | 3655 |
3464 /* | 3656 /* |
3465 * convert as much as possible to the output buffer. | 3657 * convert as much as possible to the output buffer. |
3466 */ | 3658 */ |
3467 » ret = xmlCharEncOutFunc(out->encoder, out->conv, out->buffer); | 3659 » ret = xmlCharEncOutput(out, 0); |
3468 if ((ret < 0) && (ret != -3)) { | 3660 if ((ret < 0) && (ret != -3)) { |
3469 xmlIOErr(XML_IO_ENCODER, NULL); | 3661 xmlIOErr(XML_IO_ENCODER, NULL); |
3470 out->error = XML_IO_ENCODER; | 3662 out->error = XML_IO_ENCODER; |
3471 return(-1); | 3663 return(-1); |
3472 } | 3664 } |
3473 » nbchars = out->conv->use; | 3665 » nbchars = xmlBufUse(out->conv); |
3474 } else { | 3666 } else { |
3475 » ret = escaping(out->buffer->content + out->buffer->use , | 3667 » ret = escaping(xmlBufEnd(out->buffer), &chunk, str, &cons); |
3476 » &chunk, str, &cons); | |
3477 if ((ret < 0) || (chunk == 0)) /* chunk==0 => nothing done */ | 3668 if ((ret < 0) || (chunk == 0)) /* chunk==0 => nothing done */ |
3478 return(-1); | 3669 return(-1); |
3479 » out->buffer->use += chunk; | 3670 xmlBufAddLen(out->buffer, chunk); |
3480 » out->buffer->content[out->buffer->use] = 0; | 3671 » nbchars = xmlBufUse(out->buffer); |
3481 » nbchars = out->buffer->use; | |
3482 } | 3672 } |
3483 str += cons; | 3673 str += cons; |
3484 len -= cons; | 3674 len -= cons; |
3485 | 3675 |
3486 if ((nbchars < MINLEN) && (len <= 0)) | 3676 if ((nbchars < MINLEN) && (len <= 0)) |
3487 goto done; | 3677 goto done; |
3488 | 3678 |
3489 if (out->writecallback) { | 3679 if (out->writecallback) { |
3490 /* | 3680 /* |
3491 * second write the stuff to the I/O channel | 3681 * second write the stuff to the I/O channel |
3492 */ | 3682 */ |
3493 if (out->encoder != NULL) { | 3683 if (out->encoder != NULL) { |
3494 ret = out->writecallback(out->context, | 3684 ret = out->writecallback(out->context, |
3495 » » » » (const char *)out->conv->content, nbchars); | 3685 (const char *)xmlBufContent(out->conv), nbchars); |
3496 if (ret >= 0) | 3686 if (ret >= 0) |
3497 » » xmlBufferShrink(out->conv, ret); | 3687 » » xmlBufShrink(out->conv, ret); |
3498 } else { | 3688 } else { |
3499 ret = out->writecallback(out->context, | 3689 ret = out->writecallback(out->context, |
3500 » » » » (const char *)out->buffer->content, nbchars); | 3690 (const char *)xmlBufContent(out->buffer), nbchars); |
3501 if (ret >= 0) | 3691 if (ret >= 0) |
3502 » » xmlBufferShrink(out->buffer, ret); | 3692 » » xmlBufShrink(out->buffer, ret); |
3503 } | 3693 } |
3504 if (ret < 0) { | 3694 if (ret < 0) { |
3505 xmlIOErr(XML_IO_WRITE, NULL); | 3695 xmlIOErr(XML_IO_WRITE, NULL); |
3506 out->error = XML_IO_WRITE; | 3696 out->error = XML_IO_WRITE; |
3507 return(ret); | 3697 return(ret); |
3508 } | 3698 } |
3509 out->written += ret; | 3699 out->written += ret; |
3510 » } else if (out->buffer->size - out->buffer->use < MINLEN) { | 3700 » } else if (xmlBufAvail(out->buffer) < MINLEN) { |
3511 » xmlBufferResize(out->buffer, out->buffer->size + MINLEN); | 3701 » xmlBufGrow(out->buffer, MINLEN); |
3512 } | 3702 } |
3513 written += nbchars; | 3703 written += nbchars; |
3514 } while ((len > 0) && (oldwritten != written)); | 3704 } while ((len > 0) && (oldwritten != written)); |
3515 | 3705 |
3516 done: | 3706 done: |
3517 #ifdef DEBUG_INPUT | 3707 #ifdef DEBUG_INPUT |
3518 xmlGenericError(xmlGenericErrorContext, | 3708 xmlGenericError(xmlGenericErrorContext, |
3519 "I/O: wrote %d chars\n", written); | 3709 "I/O: wrote %d chars\n", written); |
3520 #endif | 3710 #endif |
3521 return(written); | 3711 return(written); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3559 int | 3749 int |
3560 xmlOutputBufferFlush(xmlOutputBufferPtr out) { | 3750 xmlOutputBufferFlush(xmlOutputBufferPtr out) { |
3561 int nbchars = 0, ret = 0; | 3751 int nbchars = 0, ret = 0; |
3562 | 3752 |
3563 if ((out == NULL) || (out->error)) return(-1); | 3753 if ((out == NULL) || (out->error)) return(-1); |
3564 /* | 3754 /* |
3565 * first handle encoding stuff. | 3755 * first handle encoding stuff. |
3566 */ | 3756 */ |
3567 if ((out->conv != NULL) && (out->encoder != NULL)) { | 3757 if ((out->conv != NULL) && (out->encoder != NULL)) { |
3568 /* | 3758 /* |
3569 » * convert as much as possible to the parser reading buffer. | 3759 » * convert as much as possible to the parser output buffer. |
3570 */ | 3760 */ |
3571 » nbchars = xmlCharEncOutFunc(out->encoder, out->conv, out->buffer); | 3761 » do { |
3572 » if (nbchars < 0) { | 3762 » nbchars = xmlCharEncOutput(out, 0); |
3573 » xmlIOErr(XML_IO_ENCODER, NULL); | 3763 » if (nbchars < 0) { |
3574 » out->error = XML_IO_ENCODER; | 3764 » » xmlIOErr(XML_IO_ENCODER, NULL); |
3575 » return(-1); | 3765 » » out->error = XML_IO_ENCODER; |
3576 » } | 3766 » » return(-1); |
| 3767 » } |
| 3768 » } while (nbchars); |
3577 } | 3769 } |
3578 | 3770 |
3579 /* | 3771 /* |
3580 * second flush the stuff to the I/O channel | 3772 * second flush the stuff to the I/O channel |
3581 */ | 3773 */ |
3582 if ((out->conv != NULL) && (out->encoder != NULL) && | 3774 if ((out->conv != NULL) && (out->encoder != NULL) && |
3583 (out->writecallback != NULL)) { | 3775 (out->writecallback != NULL)) { |
3584 ret = out->writecallback(out->context, | 3776 ret = out->writecallback(out->context, |
3585 » (const char *)out->conv->content, out->conv->use); | 3777 (const char *)xmlBufContent(out->conv), |
| 3778 xmlBufUse(out->conv)); |
3586 if (ret >= 0) | 3779 if (ret >= 0) |
3587 » xmlBufferShrink(out->conv, ret); | 3780 » xmlBufShrink(out->conv, ret); |
3588 } else if (out->writecallback != NULL) { | 3781 } else if (out->writecallback != NULL) { |
3589 ret = out->writecallback(out->context, | 3782 ret = out->writecallback(out->context, |
3590 » (const char *)out->buffer->content, out->buffer->use); | 3783 (const char *)xmlBufContent(out->buffer), |
| 3784 xmlBufUse(out->buffer)); |
3591 if (ret >= 0) | 3785 if (ret >= 0) |
3592 » xmlBufferShrink(out->buffer, ret); | 3786 » xmlBufShrink(out->buffer, ret); |
3593 } | 3787 } |
3594 if (ret < 0) { | 3788 if (ret < 0) { |
3595 xmlIOErr(XML_IO_FLUSH, NULL); | 3789 xmlIOErr(XML_IO_FLUSH, NULL); |
3596 out->error = XML_IO_FLUSH; | 3790 out->error = XML_IO_FLUSH; |
3597 return(ret); | 3791 return(ret); |
3598 } | 3792 } |
3599 out->written += ret; | 3793 out->written += ret; |
3600 | 3794 |
3601 #ifdef DEBUG_INPUT | 3795 #ifdef DEBUG_INPUT |
3602 xmlGenericError(xmlGenericErrorContext, | 3796 xmlGenericError(xmlGenericErrorContext, |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3983 } | 4177 } |
3984 } | 4178 } |
3985 input = xmlDefaultExternalEntityLoader((const char *) resource, ID, ctxt); | 4179 input = xmlDefaultExternalEntityLoader((const char *) resource, ID, ctxt); |
3986 if (resource != (xmlChar *) URL) | 4180 if (resource != (xmlChar *) URL) |
3987 xmlFree(resource); | 4181 xmlFree(resource); |
3988 return(input); | 4182 return(input); |
3989 } | 4183 } |
3990 | 4184 |
3991 #define bottom_xmlIO | 4185 #define bottom_xmlIO |
3992 #include "elfgcchack.h" | 4186 #include "elfgcchack.h" |
OLD | NEW |