| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 xmlOutputOpenCallback opencallback; | 128 xmlOutputOpenCallback opencallback; |
| 129 xmlOutputWriteCallback writecallback; | 129 xmlOutputWriteCallback writecallback; |
| 130 xmlOutputCloseCallback closecallback; | 130 xmlOutputCloseCallback closecallback; |
| 131 } xmlOutputCallback; | 131 } xmlOutputCallback; |
| 132 | 132 |
| 133 #define MAX_OUTPUT_CALLBACK 15 | 133 #define MAX_OUTPUT_CALLBACK 15 |
| 134 | 134 |
| 135 static xmlOutputCallback xmlOutputCallbackTable[MAX_OUTPUT_CALLBACK]; | 135 static xmlOutputCallback xmlOutputCallbackTable[MAX_OUTPUT_CALLBACK]; |
| 136 static int xmlOutputCallbackNr = 0; | 136 static int xmlOutputCallbackNr = 0; |
| 137 static int xmlOutputCallbackInitialized = 0; | 137 static int xmlOutputCallbackInitialized = 0; |
| 138 |
| 139 xmlOutputBufferPtr |
| 140 xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr encoder); |
| 138 #endif /* LIBXML_OUTPUT_ENABLED */ | 141 #endif /* LIBXML_OUTPUT_ENABLED */ |
| 139 | 142 |
| 140 /************************************************************************ | 143 /************************************************************************ |
| 141 * * | 144 * * |
| 142 * » » Tree memory error handler» » » » * | 145 *» » Tree memory error handler» » » » * |
| 143 * * | 146 * * |
| 144 ************************************************************************/ | 147 ************************************************************************/ |
| 145 | 148 |
| 146 static const char *IOerr[] = { | 149 static const char *IOerr[] = { |
| 147 "Unknown IO error", /* UNKNOWN */ | 150 "Unknown IO error", /* UNKNOWN */ |
| 148 "Permission denied", /* EACCES */ | 151 "Permission denied", /* EACCES */ |
| 149 "Resource temporarily unavailable",/* EAGAIN */ | 152 "Resource temporarily unavailable",/* EAGAIN */ |
| 150 "Bad file descriptor", /* EBADF */ | 153 "Bad file descriptor", /* EBADF */ |
| 151 "Bad message", /* EBADMSG */ | 154 "Bad message", /* EBADMSG */ |
| 152 "Resource busy", /* EBUSY */ | 155 "Resource busy", /* EBUSY */ |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 #endif | 418 #endif |
| 416 #ifdef EAFNOSUPPORT | 419 #ifdef EAFNOSUPPORT |
| 417 else if (errno == EAFNOSUPPORT) code = XML_IO_EAFNOSUPPORT; | 420 else if (errno == EAFNOSUPPORT) code = XML_IO_EAFNOSUPPORT; |
| 418 #endif | 421 #endif |
| 419 else code = XML_IO_UNKNOWN; | 422 else code = XML_IO_UNKNOWN; |
| 420 #endif /* HAVE_ERRNO_H */ | 423 #endif /* HAVE_ERRNO_H */ |
| 421 } | 424 } |
| 422 idx = 0; | 425 idx = 0; |
| 423 if (code >= XML_IO_UNKNOWN) idx = code - XML_IO_UNKNOWN; | 426 if (code >= XML_IO_UNKNOWN) idx = code - XML_IO_UNKNOWN; |
| 424 if (idx >= (sizeof(IOerr) / sizeof(IOerr[0]))) idx = 0; | 427 if (idx >= (sizeof(IOerr) / sizeof(IOerr[0]))) idx = 0; |
| 425 | 428 |
| 426 __xmlSimpleError(domain, code, NULL, IOerr[idx], extra); | 429 __xmlSimpleError(domain, code, NULL, IOerr[idx], extra); |
| 427 } | 430 } |
| 428 | 431 |
| 429 /** | 432 /** |
| 430 * xmlIOErr: | 433 * xmlIOErr: |
| 431 * @code: the error number | 434 * @code: the error number |
| 432 * @extra: extra informations | 435 * @extra: extra informations |
| 433 * | 436 * |
| 434 * Handle an I/O error | 437 * Handle an I/O error |
| 435 */ | 438 */ |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 level = XML_ERR_WARNING; | 470 level = XML_ERR_WARNING; |
| 468 } | 471 } |
| 469 if (ctxt->sax->initialized == XML_SAX2_MAGIC) | 472 if (ctxt->sax->initialized == XML_SAX2_MAGIC) |
| 470 schannel = ctxt->sax->serror; | 473 schannel = ctxt->sax->serror; |
| 471 data = ctxt->userData; | 474 data = ctxt->userData; |
| 472 } | 475 } |
| 473 __xmlRaiseError(schannel, channel, data, ctxt, NULL, XML_FROM_IO, | 476 __xmlRaiseError(schannel, channel, data, ctxt, NULL, XML_FROM_IO, |
| 474 XML_IO_LOAD_ERROR, level, NULL, 0, | 477 XML_IO_LOAD_ERROR, level, NULL, 0, |
| 475 filename, NULL, NULL, 0, 0, | 478 filename, NULL, NULL, 0, 0, |
| 476 msg, filename); | 479 msg, filename); |
| 477 | 480 |
| 478 } | 481 } |
| 479 | 482 |
| 480 /************************************************************************ | 483 /************************************************************************ |
| 481 * * | 484 * * |
| 482 * » » Tree memory error handler» » » » * | 485 *» » Tree memory error handler» » » » * |
| 483 * * | 486 * * |
| 484 ************************************************************************/ | 487 ************************************************************************/ |
| 485 /** | 488 /** |
| 486 * xmlNormalizeWindowsPath: | 489 * xmlNormalizeWindowsPath: |
| 487 * @path: the input file path | 490 * @path: the input file path |
| 488 * | 491 * |
| 489 * This function is obsolete. Please see xmlURIFromPath in uri.c for | 492 * This function is obsolete. Please see xmlURIFromPath in uri.c for |
| 490 * a better solution. | 493 * a better solution. |
| 491 * | 494 * |
| 492 * Returns a canonicalized version of the path | 495 * Returns a canonicalized version of the path |
| 493 */ | 496 */ |
| 494 xmlChar * | 497 xmlChar * |
| 495 xmlNormalizeWindowsPath(const xmlChar *path) | 498 xmlNormalizeWindowsPath(const xmlChar *path) |
| 496 { | 499 { |
| 497 return xmlCanonicPath(path); | 500 return xmlCanonicPath(path); |
| 498 } | 501 } |
| 499 | 502 |
| 500 /** | 503 /** |
| 501 * xmlCleanupInputCallbacks: | 504 * xmlCleanupInputCallbacks: |
| 502 * | 505 * |
| 503 * clears the entire input callback table. this includes the | 506 * clears the entire input callback table. this includes the |
| 504 * compiled-in I/O. | 507 * compiled-in I/O. |
| 505 */ | 508 */ |
| 506 void | 509 void |
| 507 xmlCleanupInputCallbacks(void) | 510 xmlCleanupInputCallbacks(void) |
| 508 { | 511 { |
| 509 int i; | 512 int i; |
| 510 | 513 |
| 511 if (!xmlInputCallbackInitialized) | 514 if (!xmlInputCallbackInitialized) |
| 512 return; | 515 return; |
| 513 | 516 |
| 514 for (i = xmlInputCallbackNr - 1; i >= 0; i--) { | 517 for (i = xmlInputCallbackNr - 1; i >= 0; i--) { |
| 515 xmlInputCallbackTable[i].matchcallback = NULL; | 518 xmlInputCallbackTable[i].matchcallback = NULL; |
| 516 xmlInputCallbackTable[i].opencallback = NULL; | 519 xmlInputCallbackTable[i].opencallback = NULL; |
| 517 xmlInputCallbackTable[i].readcallback = NULL; | 520 xmlInputCallbackTable[i].readcallback = NULL; |
| 518 xmlInputCallbackTable[i].closecallback = NULL; | 521 xmlInputCallbackTable[i].closecallback = NULL; |
| 519 } | 522 } |
| 520 | 523 |
| 521 xmlInputCallbackNr = 0; | 524 xmlInputCallbackNr = 0; |
| 522 xmlInputCallbackInitialized = 0; | 525 xmlInputCallbackInitialized = 0; |
| 523 } | 526 } |
| 524 | 527 |
| 525 /** | 528 /** |
| 526 * xmlPopInputCallbacks: | 529 * xmlPopInputCallbacks: |
| 527 * | 530 * |
| 528 * Clear the top input callback from the input stack. this includes the | 531 * Clear the top input callback from the input stack. this includes the |
| 529 * compiled-in I/O. | 532 * compiled-in I/O. |
| 530 * | 533 * |
| 531 * Returns the number of input callback registered or -1 in case of error. | 534 * Returns the number of input callback registered or -1 in case of error. |
| 532 */ | 535 */ |
| 533 int | 536 int |
| 534 xmlPopInputCallbacks(void) | 537 xmlPopInputCallbacks(void) |
| 535 { | 538 { |
| 536 if (!xmlInputCallbackInitialized) | 539 if (!xmlInputCallbackInitialized) |
| 537 return(-1); | 540 return(-1); |
| 538 | 541 |
| 539 if (xmlInputCallbackNr <= 0) | 542 if (xmlInputCallbackNr <= 0) |
| 540 return(-1); | 543 return(-1); |
| 541 | 544 |
| 542 xmlInputCallbackNr--; | 545 xmlInputCallbackNr--; |
| 543 xmlInputCallbackTable[xmlInputCallbackNr].matchcallback = NULL; | 546 xmlInputCallbackTable[xmlInputCallbackNr].matchcallback = NULL; |
| 544 xmlInputCallbackTable[xmlInputCallbackNr].opencallback = NULL; | 547 xmlInputCallbackTable[xmlInputCallbackNr].opencallback = NULL; |
| 545 xmlInputCallbackTable[xmlInputCallbackNr].readcallback = NULL; | 548 xmlInputCallbackTable[xmlInputCallbackNr].readcallback = NULL; |
| 546 xmlInputCallbackTable[xmlInputCallbackNr].closecallback = NULL; | 549 xmlInputCallbackTable[xmlInputCallbackNr].closecallback = NULL; |
| 547 | 550 |
| 548 return(xmlInputCallbackNr); | 551 return(xmlInputCallbackNr); |
| 549 } | 552 } |
| 550 | 553 |
| 551 #ifdef LIBXML_OUTPUT_ENABLED | 554 #ifdef LIBXML_OUTPUT_ENABLED |
| 552 /** | 555 /** |
| 553 * xmlCleanupOutputCallbacks: | 556 * xmlCleanupOutputCallbacks: |
| 554 * | 557 * |
| 555 * clears the entire output callback table. this includes the | 558 * clears the entire output callback table. this includes the |
| 556 * compiled-in I/O callbacks. | 559 * compiled-in I/O callbacks. |
| 557 */ | 560 */ |
| 558 void | 561 void |
| 559 xmlCleanupOutputCallbacks(void) | 562 xmlCleanupOutputCallbacks(void) |
| 560 { | 563 { |
| 561 int i; | 564 int i; |
| 562 | 565 |
| 563 if (!xmlOutputCallbackInitialized) | 566 if (!xmlOutputCallbackInitialized) |
| 564 return; | 567 return; |
| 565 | 568 |
| 566 for (i = xmlOutputCallbackNr - 1; i >= 0; i--) { | 569 for (i = xmlOutputCallbackNr - 1; i >= 0; i--) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 fd = _wfopen(wPath, mode ? L"wb" : L"rb"); | 606 fd = _wfopen(wPath, mode ? L"wb" : L"rb"); |
| 604 xmlFree(wPath); | 607 xmlFree(wPath); |
| 605 } | 608 } |
| 606 /* maybe path in native encoding */ | 609 /* maybe path in native encoding */ |
| 607 if(fd == NULL) | 610 if(fd == NULL) |
| 608 fd = fopen(path, mode ? "wb" : "rb"); | 611 fd = fopen(path, mode ? "wb" : "rb"); |
| 609 | 612 |
| 610 return fd; | 613 return fd; |
| 611 } | 614 } |
| 612 | 615 |
| 616 #ifdef HAVE_ZLIB_H |
| 617 static gzFile |
| 618 xmlWrapGzOpenUtf8(const char *path, const char *mode) |
| 619 { |
| 620 gzFile fd; |
| 621 wchar_t *wPath; |
| 622 |
| 623 fd = gzopen (path, mode); |
| 624 if (fd) |
| 625 return fd; |
| 626 |
| 627 wPath = __xmlIOWin32UTF8ToWChar(path); |
| 628 if(wPath) |
| 629 { |
| 630 int d, m = (strstr(mode, "r") ? O_RDONLY : O_RDWR); |
| 631 #ifdef _O_BINARY |
| 632 m |= (strstr(mode, "b") ? _O_BINARY : 0); |
| 633 #endif |
| 634 d = _wopen(wPath, m); |
| 635 if (d >= 0) |
| 636 fd = gzdopen(d, mode); |
| 637 xmlFree(wPath); |
| 638 } |
| 639 |
| 640 return fd; |
| 641 } |
| 642 #endif |
| 643 |
| 613 /** | 644 /** |
| 614 * xmlWrapStatUtf8: | 645 * xmlWrapStatUtf8: |
| 615 * @path: the path in utf-8 encoding | 646 * @path: the path in utf-8 encoding |
| 616 * @info: structure that stores results | 647 * @info: structure that stores results |
| 617 * | 648 * |
| 618 * function obtains information about the file or directory | 649 * function obtains information about the file or directory |
| 619 * | 650 * |
| 620 */ | 651 */ |
| 621 static int | 652 static int |
| 622 xmlWrapStatUtf8(const char *path,struct stat *info) | 653 xmlWrapStatUtf8(const char *path,struct stat *info) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 return stat(path,info); | 700 return stat(path,info); |
| 670 #else | 701 #else |
| 671 return -1; | 702 return -1; |
| 672 #endif | 703 #endif |
| 673 } | 704 } |
| 674 | 705 |
| 675 typedef int (* xmlWrapStatFunc) (const char *f, struct stat *s); | 706 typedef int (* xmlWrapStatFunc) (const char *f, struct stat *s); |
| 676 static xmlWrapStatFunc xmlWrapStat = xmlWrapStatNative; | 707 static xmlWrapStatFunc xmlWrapStat = xmlWrapStatNative; |
| 677 typedef FILE* (* xmlWrapOpenFunc)(const char *f,int mode); | 708 typedef FILE* (* xmlWrapOpenFunc)(const char *f,int mode); |
| 678 static xmlWrapOpenFunc xmlWrapOpen = xmlWrapOpenNative; | 709 static xmlWrapOpenFunc xmlWrapOpen = xmlWrapOpenNative; |
| 679 | 710 #ifdef HAVE_ZLIB_H |
| 711 typedef gzFile (* xmlWrapGzOpenFunc) (const char *f, const char *mode); |
| 712 static xmlWrapGzOpenFunc xmlWrapGzOpen = gzopen; |
| 713 #endif |
| 680 /** | 714 /** |
| 681 * xmlInitPlatformSpecificIo: | 715 * xmlInitPlatformSpecificIo: |
| 682 * | 716 * |
| 683 * Initialize platform specific features. | 717 * Initialize platform specific features. |
| 684 */ | 718 */ |
| 685 static void | 719 static void |
| 686 xmlInitPlatformSpecificIo(void) | 720 xmlInitPlatformSpecificIo(void) |
| 687 { | 721 { |
| 688 static int xmlPlatformIoInitialized = 0; | 722 static int xmlPlatformIoInitialized = 0; |
| 689 OSVERSIONINFO osvi; | 723 OSVERSIONINFO osvi; |
| 690 | 724 |
| 691 if(xmlPlatformIoInitialized) | 725 if(xmlPlatformIoInitialized) |
| 692 return; | 726 return; |
| 693 | 727 |
| 694 osvi.dwOSVersionInfoSize = sizeof(osvi); | 728 osvi.dwOSVersionInfoSize = sizeof(osvi); |
| 695 | 729 |
| 696 if(GetVersionEx(&osvi) && (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)) { | 730 if(GetVersionEx(&osvi) && (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)) { |
| 697 xmlWrapStat = xmlWrapStatUtf8; | 731 xmlWrapStat = xmlWrapStatUtf8; |
| 698 xmlWrapOpen = xmlWrapOpenUtf8; | 732 xmlWrapOpen = xmlWrapOpenUtf8; |
| 733 #ifdef HAVE_ZLIB_H |
| 734 xmlWrapGzOpen = xmlWrapGzOpenUtf8; |
| 735 #endif |
| 699 } else { | 736 } else { |
| 700 xmlWrapStat = xmlWrapStatNative; | 737 xmlWrapStat = xmlWrapStatNative; |
| 701 xmlWrapOpen = xmlWrapOpenNative; | 738 xmlWrapOpen = xmlWrapOpenNative; |
| 739 #ifdef HAVE_ZLIB_H |
| 740 xmlWrapGzOpen = gzopen; |
| 741 #endif |
| 702 } | 742 } |
| 703 | 743 |
| 704 xmlPlatformIoInitialized = 1; | 744 xmlPlatformIoInitialized = 1; |
| 705 return; | 745 return; |
| 706 } | 746 } |
| 707 | 747 |
| 708 #endif | 748 #endif |
| 709 | 749 |
| 710 /** | 750 /** |
| 711 * xmlCheckFilename: | 751 * xmlCheckFilename: |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 #else | 896 #else |
| 857 path = &filename[7]; | 897 path = &filename[7]; |
| 858 #endif | 898 #endif |
| 859 } else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:/", 6)) { | 899 } else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:/", 6)) { |
| 860 /* lots of generators seems to lazy to read RFC 1738 */ | 900 /* lots of generators seems to lazy to read RFC 1738 */ |
| 861 #if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) | 901 #if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) |
| 862 path = &filename[6]; | 902 path = &filename[6]; |
| 863 #else | 903 #else |
| 864 path = &filename[5]; | 904 path = &filename[5]; |
| 865 #endif | 905 #endif |
| 866 } else | 906 } else |
| 867 path = filename; | 907 path = filename; |
| 868 | 908 |
| 869 if (path == NULL) | 909 if (path == NULL) |
| 870 return(NULL); | 910 return(NULL); |
| 871 if (!xmlCheckFilename(path)) | 911 if (!xmlCheckFilename(path)) |
| 872 return(NULL); | 912 return(NULL); |
| 873 | 913 |
| 874 #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) | 914 #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) |
| 875 fd = xmlWrapOpen(path, 0); | 915 fd = xmlWrapOpen(path, 0); |
| 876 #else | 916 #else |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 path = &filename[17]; | 971 path = &filename[17]; |
| 932 #else | 972 #else |
| 933 path = &filename[16]; | 973 path = &filename[16]; |
| 934 #endif | 974 #endif |
| 935 else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:///", 8)) { | 975 else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:///", 8)) { |
| 936 #if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) | 976 #if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) |
| 937 path = &filename[8]; | 977 path = &filename[8]; |
| 938 #else | 978 #else |
| 939 path = &filename[7]; | 979 path = &filename[7]; |
| 940 #endif | 980 #endif |
| 941 } else | 981 } else |
| 942 path = filename; | 982 path = filename; |
| 943 | 983 |
| 944 if (path == NULL) | 984 if (path == NULL) |
| 945 return(NULL); | 985 return(NULL); |
| 946 | 986 |
| 947 #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) | 987 #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) |
| 948 fd = xmlWrapOpen(path, 1); | 988 fd = xmlWrapOpen(path, 1); |
| 949 #else | 989 #else |
| 950 » fd = fopen(path, "wb"); | 990 » fd = fopen(path, "wb"); |
| 951 #endif /* WIN32 */ | 991 #endif /* WIN32 */ |
| 952 | 992 |
| 953 if (fd == NULL) xmlIOErr(0, path); | 993 if (fd == NULL) xmlIOErr(0, path); |
| 954 return((void *) fd); | 994 return((void *) fd); |
| 955 } | 995 } |
| 956 #endif /* LIBXML_OUTPUT_ENABLED */ | 996 #endif /* LIBXML_OUTPUT_ENABLED */ |
| 957 | 997 |
| 958 /** | 998 /** |
| 959 * xmlFileRead: | 999 * xmlFileRead: |
| 960 * @context: the I/O context | 1000 * @context: the I/O context |
| 961 * @buffer: where to drop data | 1001 * @buffer: where to drop data |
| 962 * @len: number of bytes to write | 1002 * @len: number of bytes to write |
| 963 * | 1003 * |
| 964 * Read @len bytes to @buffer from the I/O channel. | 1004 * Read @len bytes to @buffer from the I/O channel. |
| 965 * | 1005 * |
| 966 * Returns the number of bytes written or < 0 in case of failure | 1006 * Returns the number of bytes written or < 0 in case of failure |
| 967 */ | 1007 */ |
| 968 int | 1008 int |
| 969 xmlFileRead (void * context, char * buffer, int len) { | 1009 xmlFileRead (void * context, char * buffer, int len) { |
| 970 int ret; | 1010 int ret; |
| 971 if ((context == NULL) || (buffer == NULL)) | 1011 if ((context == NULL) || (buffer == NULL)) |
| 972 return(-1); | 1012 return(-1); |
| 973 ret = fread(&buffer[0], 1, len, (FILE *) context); | 1013 ret = fread(&buffer[0], 1, len, (FILE *) context); |
| 974 if (ret < 0) xmlIOErr(0, "fread()"); | 1014 if (ret < 0) xmlIOErr(0, "fread()"); |
| 975 return(ret); | 1015 return(ret); |
| 976 } | 1016 } |
| 977 | 1017 |
| 978 #ifdef LIBXML_OUTPUT_ENABLED | 1018 #ifdef LIBXML_OUTPUT_ENABLED |
| 979 /** | 1019 /** |
| 980 * xmlFileWrite: | 1020 * xmlFileWrite: |
| 981 * @context: the I/O context | 1021 * @context: the I/O context |
| 982 * @buffer: where to drop data | 1022 * @buffer: where to drop data |
| 983 * @len: number of bytes to write | 1023 * @len: number of bytes to write |
| 984 * | 1024 * |
| 985 * Write @len bytes from @buffer to the I/O channel. | 1025 * Write @len bytes from @buffer to the I/O channel. |
| 986 * | 1026 * |
| 987 * Returns the number of bytes written | 1027 * Returns the number of bytes written |
| 988 */ | 1028 */ |
| 989 static int | 1029 static int |
| 990 xmlFileWrite (void * context, const char * buffer, int len) { | 1030 xmlFileWrite (void * context, const char * buffer, int len) { |
| 991 int items; | 1031 int items; |
| 992 | 1032 |
| 993 if ((context == NULL) || (buffer == NULL)) | 1033 if ((context == NULL) || (buffer == NULL)) |
| 994 return(-1); | 1034 return(-1); |
| 995 items = fwrite(&buffer[0], len, 1, (FILE *) context); | 1035 items = fwrite(&buffer[0], len, 1, (FILE *) context); |
| 996 if ((items == 0) && (ferror((FILE *) context))) { | 1036 if ((items == 0) && (ferror((FILE *) context))) { |
| 997 xmlIOErr(0, "fwrite()"); | 1037 xmlIOErr(0, "fwrite()"); |
| 998 return(-1); | 1038 return(-1); |
| 999 } | 1039 } |
| 1000 return(items * len); | 1040 return(items * len); |
| 1001 } | 1041 } |
| 1002 #endif /* LIBXML_OUTPUT_ENABLED */ | 1042 #endif /* LIBXML_OUTPUT_ENABLED */ |
| 1003 | 1043 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 path = &filename[17]; | 1154 path = &filename[17]; |
| 1115 #else | 1155 #else |
| 1116 path = &filename[16]; | 1156 path = &filename[16]; |
| 1117 #endif | 1157 #endif |
| 1118 else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:///", 8)) { | 1158 else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:///", 8)) { |
| 1119 #if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) | 1159 #if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) |
| 1120 path = &filename[8]; | 1160 path = &filename[8]; |
| 1121 #else | 1161 #else |
| 1122 path = &filename[7]; | 1162 path = &filename[7]; |
| 1123 #endif | 1163 #endif |
| 1124 } else | 1164 } else |
| 1125 path = filename; | 1165 path = filename; |
| 1126 | 1166 |
| 1127 if (path == NULL) | 1167 if (path == NULL) |
| 1128 return(NULL); | 1168 return(NULL); |
| 1129 if (!xmlCheckFilename(path)) | 1169 if (!xmlCheckFilename(path)) |
| 1130 return(NULL); | 1170 return(NULL); |
| 1131 | 1171 |
| 1172 #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) |
| 1173 fd = xmlWrapGzOpen(path, "rb"); |
| 1174 #else |
| 1132 fd = gzopen(path, "rb"); | 1175 fd = gzopen(path, "rb"); |
| 1176 #endif |
| 1133 return((void *) fd); | 1177 return((void *) fd); |
| 1134 } | 1178 } |
| 1135 | 1179 |
| 1136 /** | 1180 /** |
| 1137 * xmlGzfileOpen: | 1181 * xmlGzfileOpen: |
| 1138 * @filename: the URI for matching | 1182 * @filename: the URI for matching |
| 1139 * | 1183 * |
| 1140 * Wrapper around xmlGzfileOpen if the open fais, it will | 1184 * Wrapper around xmlGzfileOpen if the open fais, it will |
| 1141 * try to unescape @filename | 1185 * try to unescape @filename |
| 1142 */ | 1186 */ |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1184 path = &filename[17]; | 1228 path = &filename[17]; |
| 1185 #else | 1229 #else |
| 1186 path = &filename[16]; | 1230 path = &filename[16]; |
| 1187 #endif | 1231 #endif |
| 1188 else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:///", 8)) { | 1232 else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:///", 8)) { |
| 1189 #if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) | 1233 #if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) |
| 1190 path = &filename[8]; | 1234 path = &filename[8]; |
| 1191 #else | 1235 #else |
| 1192 path = &filename[7]; | 1236 path = &filename[7]; |
| 1193 #endif | 1237 #endif |
| 1194 } else | 1238 } else |
| 1195 path = filename; | 1239 path = filename; |
| 1196 | 1240 |
| 1197 if (path == NULL) | 1241 if (path == NULL) |
| 1198 return(NULL); | 1242 return(NULL); |
| 1199 | 1243 |
| 1244 #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__) |
| 1245 fd = xmlWrapGzOpen(path, mode); |
| 1246 #else |
| 1200 fd = gzopen(path, mode); | 1247 fd = gzopen(path, mode); |
| 1248 #endif |
| 1201 return((void *) fd); | 1249 return((void *) fd); |
| 1202 } | 1250 } |
| 1203 #endif /* LIBXML_OUTPUT_ENABLED */ | 1251 #endif /* LIBXML_OUTPUT_ENABLED */ |
| 1204 | 1252 |
| 1205 /** | 1253 /** |
| 1206 * xmlGzfileRead: | 1254 * xmlGzfileRead: |
| 1207 * @context: the I/O context | 1255 * @context: the I/O context |
| 1208 * @buffer: where to drop data | 1256 * @buffer: where to drop data |
| 1209 * @len: number of bytes to write | 1257 * @len: number of bytes to write |
| 1210 * | 1258 * |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1312 static void | 1360 static void |
| 1313 append_reverse_ulong( xmlZMemBuff * buff, unsigned long data ) { | 1361 append_reverse_ulong( xmlZMemBuff * buff, unsigned long data ) { |
| 1314 | 1362 |
| 1315 int idx; | 1363 int idx; |
| 1316 | 1364 |
| 1317 if ( buff == NULL ) | 1365 if ( buff == NULL ) |
| 1318 return; | 1366 return; |
| 1319 | 1367 |
| 1320 /* | 1368 /* |
| 1321 ** This is plagiarized from putLong in gzio.c (zlib source) where | 1369 ** This is plagiarized from putLong in gzio.c (zlib source) where |
| 1322 ** the number "4" is hardcoded. If zlib is ever patched to | 1370 ** the number "4" is hardcoded. If zlib is ever patched to |
| 1323 ** support 64 bit file sizes, this code would need to be patched | 1371 ** support 64 bit file sizes, this code would need to be patched |
| 1324 ** as well. | 1372 ** as well. |
| 1325 */ | 1373 */ |
| 1326 | 1374 |
| 1327 for ( idx = 0; idx < 4; idx++ ) { | 1375 for ( idx = 0; idx < 4; idx++ ) { |
| 1328 *buff->zctrl.next_out = ( data & 0xff ); | 1376 *buff->zctrl.next_out = ( data & 0xff ); |
| 1329 data >>= 8; | 1377 data >>= 8; |
| 1330 buff->zctrl.next_out++; | 1378 buff->zctrl.next_out++; |
| 1331 } | 1379 } |
| 1332 | 1380 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1364 xmlFree( buff ); | 1412 xmlFree( buff ); |
| 1365 return; | 1413 return; |
| 1366 } | 1414 } |
| 1367 | 1415 |
| 1368 /** | 1416 /** |
| 1369 * xmlCreateZMemBuff | 1417 * xmlCreateZMemBuff |
| 1370 *@compression: Compression value to use | 1418 *@compression: Compression value to use |
| 1371 * | 1419 * |
| 1372 * Create a memory buffer to hold the compressed XML document. The | 1420 * Create a memory buffer to hold the compressed XML document. The |
| 1373 * compressed document in memory will end up being identical to what | 1421 * compressed document in memory will end up being identical to what |
| 1374 * would be created if gzopen/gzwrite/gzclose were being used to | 1422 * would be created if gzopen/gzwrite/gzclose were being used to |
| 1375 * write the document to disk. The code for the header/trailer data to | 1423 * write the document to disk. The code for the header/trailer data to |
| 1376 * the compression is plagiarized from the zlib source files. | 1424 * the compression is plagiarized from the zlib source files. |
| 1377 */ | 1425 */ |
| 1378 static void * | 1426 static void * |
| 1379 xmlCreateZMemBuff( int compression ) { | 1427 xmlCreateZMemBuff( int compression ) { |
| 1380 | 1428 |
| 1381 int z_err; | 1429 int z_err; |
| 1382 int hdr_lgth; | 1430 int hdr_lgth; |
| 1383 xmlZMemBuffPtr buff = NULL; | 1431 xmlZMemBuffPtr buff = NULL; |
| 1384 | 1432 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1413 "Error initializing compression context. ZLIB error:", | 1461 "Error initializing compression context. ZLIB error:", |
| 1414 z_err ); | 1462 z_err ); |
| 1415 xmlIOErr(XML_IO_WRITE, (const char *) msg); | 1463 xmlIOErr(XML_IO_WRITE, (const char *) msg); |
| 1416 return ( NULL ); | 1464 return ( NULL ); |
| 1417 } | 1465 } |
| 1418 | 1466 |
| 1419 /* Set the header data. The CRC will be needed for the trailer */ | 1467 /* Set the header data. The CRC will be needed for the trailer */ |
| 1420 buff->crc = crc32( 0L, NULL, 0 ); | 1468 buff->crc = crc32( 0L, NULL, 0 ); |
| 1421 hdr_lgth = snprintf( (char *)buff->zbuff, buff->size, | 1469 hdr_lgth = snprintf( (char *)buff->zbuff, buff->size, |
| 1422 "%c%c%c%c%c%c%c%c%c%c", | 1470 "%c%c%c%c%c%c%c%c%c%c", |
| 1423 » » » GZ_MAGIC1, GZ_MAGIC2, Z_DEFLATED, | 1471 » » » GZ_MAGIC1, GZ_MAGIC2, Z_DEFLATED, |
| 1424 0, 0, 0, 0, 0, 0, LXML_ZLIB_OS_CODE ); | 1472 0, 0, 0, 0, 0, 0, LXML_ZLIB_OS_CODE ); |
| 1425 buff->zctrl.next_out = buff->zbuff + hdr_lgth; | 1473 buff->zctrl.next_out = buff->zbuff + hdr_lgth; |
| 1426 buff->zctrl.avail_out = buff->size - hdr_lgth; | 1474 buff->zctrl.avail_out = buff->size - hdr_lgth; |
| 1427 | 1475 |
| 1428 return ( buff ); | 1476 return ( buff ); |
| 1429 } | 1477 } |
| 1430 | 1478 |
| 1431 /** | 1479 /** |
| 1432 * xmlZMemBuffExtend | 1480 * xmlZMemBuffExtend |
| 1433 * @buff: Buffer used to compress and consolidate data. | 1481 * @buff: Buffer used to compress and consolidate data. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1451 if ( buff == NULL ) | 1499 if ( buff == NULL ) |
| 1452 return ( -1 ); | 1500 return ( -1 ); |
| 1453 | 1501 |
| 1454 else if ( ext_amt == 0 ) | 1502 else if ( ext_amt == 0 ) |
| 1455 return ( 0 ); | 1503 return ( 0 ); |
| 1456 | 1504 |
| 1457 cur_used = buff->zctrl.next_out - buff->zbuff; | 1505 cur_used = buff->zctrl.next_out - buff->zbuff; |
| 1458 new_size = buff->size + ext_amt; | 1506 new_size = buff->size + ext_amt; |
| 1459 | 1507 |
| 1460 #ifdef DEBUG_HTTP | 1508 #ifdef DEBUG_HTTP |
| 1461 if ( cur_used > new_size ) | 1509 if ( cur_used > new_size ) |
| 1462 xmlGenericError( xmlGenericErrorContext, | 1510 xmlGenericError( xmlGenericErrorContext, |
| 1463 "xmlZMemBuffExtend: %s\n%s %d bytes.\n", | 1511 "xmlZMemBuffExtend: %s\n%s %d bytes.\n", |
| 1464 "Buffer overwrite detected during compressed memory", | 1512 "Buffer overwrite detected during compressed memory", |
| 1465 » » » "buffer extension. Overflowed by", | 1513 » » » "buffer extension. Overflowed by", |
| 1466 (cur_used - new_size ) ); | 1514 (cur_used - new_size ) ); |
| 1467 #endif | 1515 #endif |
| 1468 | 1516 |
| 1469 tmp_ptr = xmlRealloc( buff->zbuff, new_size ); | 1517 tmp_ptr = xmlRealloc( buff->zbuff, new_size ); |
| 1470 if ( tmp_ptr != NULL ) { | 1518 if ( tmp_ptr != NULL ) { |
| 1471 rc = 0; | 1519 rc = 0; |
| 1472 buff->size = new_size; | 1520 buff->size = new_size; |
| 1473 buff->zbuff = tmp_ptr; | 1521 buff->zbuff = tmp_ptr; |
| 1474 buff->zctrl.next_out = tmp_ptr + cur_used; | 1522 buff->zctrl.next_out = tmp_ptr + cur_used; |
| 1475 buff->zctrl.avail_out = new_size - cur_used; | 1523 buff->zctrl.avail_out = new_size - cur_used; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1593 *data_ref = (char *)buff->zbuff; | 1641 *data_ref = (char *)buff->zbuff; |
| 1594 } | 1642 } |
| 1595 | 1643 |
| 1596 else { | 1644 else { |
| 1597 xmlChar msg[500]; | 1645 xmlChar msg[500]; |
| 1598 xmlStrPrintf(msg, 500, | 1646 xmlStrPrintf(msg, 500, |
| 1599 (const xmlChar *) "xmlZMemBuffGetContent: %s - %d\n", | 1647 (const xmlChar *) "xmlZMemBuffGetContent: %s - %d\n", |
| 1600 "Error flushing zlib buffers. Error code", z_err ); | 1648 "Error flushing zlib buffers. Error code", z_err ); |
| 1601 xmlIOErr(XML_IO_WRITE, (const char *) msg); | 1649 xmlIOErr(XML_IO_WRITE, (const char *) msg); |
| 1602 } | 1650 } |
| 1603 | 1651 |
| 1604 return ( zlgth ); | 1652 return ( zlgth ); |
| 1605 } | 1653 } |
| 1606 #endif /* LIBXML_OUTPUT_ENABLED */ | 1654 #endif /* LIBXML_OUTPUT_ENABLED */ |
| 1607 #endif /* HAVE_ZLIB_H */ | 1655 #endif /* HAVE_ZLIB_H */ |
| 1608 | 1656 |
| 1609 #ifdef LIBXML_OUTPUT_ENABLED | 1657 #ifdef LIBXML_OUTPUT_ENABLED |
| 1610 /** | 1658 /** |
| 1611 * xmlFreeHTTPWriteCtxt | 1659 * xmlFreeHTTPWriteCtxt |
| 1612 * @ctxt: Context to cleanup | 1660 * @ctxt: Context to cleanup |
| 1613 * | 1661 * |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1713 #ifdef HAVE_ZLIB_H | 1761 #ifdef HAVE_ZLIB_H |
| 1714 if ((compression > 0) && (compression <= 9)) { | 1762 if ((compression > 0) && (compression <= 9)) { |
| 1715 | 1763 |
| 1716 ctxt->compression = compression; | 1764 ctxt->compression = compression; |
| 1717 ctxt->doc_buff = xmlCreateZMemBuff(compression); | 1765 ctxt->doc_buff = xmlCreateZMemBuff(compression); |
| 1718 } else | 1766 } else |
| 1719 #endif | 1767 #endif |
| 1720 { | 1768 { |
| 1721 /* Any character conversions should have been done before this */ | 1769 /* Any character conversions should have been done before this */ |
| 1722 | 1770 |
| 1723 ctxt->doc_buff = xmlAllocOutputBuffer(NULL); | 1771 ctxt->doc_buff = xmlAllocOutputBufferInternal(NULL); |
| 1724 } | 1772 } |
| 1725 | 1773 |
| 1726 if (ctxt->doc_buff == NULL) { | 1774 if (ctxt->doc_buff == NULL) { |
| 1727 xmlFreeHTTPWriteCtxt(ctxt); | 1775 xmlFreeHTTPWriteCtxt(ctxt); |
| 1728 ctxt = NULL; | 1776 ctxt = NULL; |
| 1729 } | 1777 } |
| 1730 | 1778 |
| 1731 return (ctxt); | 1779 return (ctxt); |
| 1732 } | 1780 } |
| 1733 #endif /* LIBXML_OUTPUT_ENABLED */ | 1781 #endif /* LIBXML_OUTPUT_ENABLED */ |
| 1734 » » » » | 1782 |
| 1735 #ifdef LIBXML_OUTPUT_ENABLED | 1783 #ifdef LIBXML_OUTPUT_ENABLED |
| 1736 /** | 1784 /** |
| 1737 * xmlIOHTTPDfltOpenW | 1785 * xmlIOHTTPDfltOpenW |
| 1738 * @post_uri: The destination URI for this document. | 1786 * @post_uri: The destination URI for this document. |
| 1739 * | 1787 * |
| 1740 * Calls xmlIOHTTPOpenW with no compression to set up for a subsequent | 1788 * Calls xmlIOHTTPOpenW with no compression to set up for a subsequent |
| 1741 * HTTP post command. This function should generally not be used as | 1789 * HTTP post command. This function should generally not be used as |
| 1742 * the open callback is short circuited in xmlOutputBufferCreateFile. | 1790 * the open callback is short circuited in xmlOutputBufferCreateFile. |
| 1743 * | 1791 * |
| 1744 * Returns a pointer to the new IO context. | 1792 * Returns a pointer to the new IO context. |
| 1745 */ | 1793 */ |
| 1746 static void * | 1794 static void * |
| 1747 xmlIOHTTPDfltOpenW( const char * post_uri ) { | 1795 xmlIOHTTPDfltOpenW( const char * post_uri ) { |
| 1748 return ( xmlIOHTTPOpenW( post_uri, 0 ) ); | 1796 return ( xmlIOHTTPOpenW( post_uri, 0 ) ); |
| 1749 } | 1797 } |
| 1750 #endif /* LIBXML_OUTPUT_ENABLED */ | 1798 #endif /* LIBXML_OUTPUT_ENABLED */ |
| 1751 | 1799 |
| 1752 /** | 1800 /** |
| 1753 * xmlIOHTTPRead: | 1801 * xmlIOHTTPRead: |
| 1754 * @context: the I/O context | 1802 * @context: the I/O context |
| 1755 * @buffer: where to drop data | 1803 * @buffer: where to drop data |
| 1756 * @len: number of bytes to write | 1804 * @len: number of bytes to write |
| 1757 * | 1805 * |
| 1758 * Read @len bytes to @buffer from the I/O channel. | 1806 * Read @len bytes to @buffer from the I/O channel. |
| 1759 * | 1807 * |
| 1760 * Returns the number of bytes written | 1808 * Returns the number of bytes written |
| 1761 */ | 1809 */ |
| 1762 int | 1810 int |
| 1763 xmlIOHTTPRead(void * context, char * buffer, int len) { | 1811 xmlIOHTTPRead(void * context, char * buffer, int len) { |
| 1764 if ((buffer == NULL) || (len < 0)) return(-1); | 1812 if ((buffer == NULL) || (len < 0)) return(-1); |
| 1765 return(xmlNanoHTTPRead(context, &buffer[0], len)); | 1813 return(xmlNanoHTTPRead(context, &buffer[0], len)); |
| 1766 } | 1814 } |
| 1767 | 1815 |
| 1768 #ifdef LIBXML_OUTPUT_ENABLED | 1816 #ifdef LIBXML_OUTPUT_ENABLED |
| 1769 /** | 1817 /** |
| 1770 * xmlIOHTTPWrite | 1818 * xmlIOHTTPWrite |
| 1771 * @context: previously opened writing context | 1819 * @context: previously opened writing context |
| 1772 * @buffer: data to output to temporary buffer | 1820 * @buffer: data to output to temporary buffer |
| 1773 * @len: bytes to output | 1821 * @len: bytes to output |
| 1774 * | 1822 * |
| 1775 * Collect data from memory buffer into a temporary file for later | 1823 * Collect data from memory buffer into a temporary file for later |
| 1776 * processing. | 1824 * processing. |
| 1777 * | 1825 * |
| 1778 * Returns number of bytes written. | 1826 * Returns number of bytes written. |
| 1779 */ | 1827 */ |
| 1780 | 1828 |
| 1781 static int | 1829 static int |
| 1782 xmlIOHTTPWrite( void * context, const char * buffer, int len ) { | 1830 xmlIOHTTPWrite( void * context, const char * buffer, int len ) { |
| 1783 | 1831 |
| 1784 xmlIOHTTPWriteCtxtPtr ctxt = context; | 1832 xmlIOHTTPWriteCtxtPtr ctxt = context; |
| 1785 | 1833 |
| 1786 if ( ( ctxt == NULL ) || ( ctxt->doc_buff == NULL ) || ( buffer == NULL ) ) | 1834 if ( ( ctxt == NULL ) || ( ctxt->doc_buff == NULL ) || ( buffer == NULL ) ) |
| 1787 return ( -1 ); | 1835 return ( -1 ); |
| 1788 | 1836 |
| 1789 if ( len > 0 ) { | 1837 if ( len > 0 ) { |
| 1790 | 1838 |
| 1791 /* Use gzwrite or fwrite as previously setup in the open call */ | 1839 /* Use gzwrite or fwrite as previously setup in the open call */ |
| 1792 | 1840 |
| 1793 #ifdef HAVE_ZLIB_H | 1841 #ifdef HAVE_ZLIB_H |
| 1794 » if ( ctxt->compression > 0 ) | 1842 » if ( ctxt->compression > 0 ) |
| 1795 len = xmlZMemBuffAppend( ctxt->doc_buff, buffer, len ); | 1843 len = xmlZMemBuffAppend( ctxt->doc_buff, buffer, len ); |
| 1796 | 1844 |
| 1797 else | 1845 else |
| 1798 #endif | 1846 #endif |
| 1799 len = xmlOutputBufferWrite( ctxt->doc_buff, len, buffer ); | 1847 len = xmlOutputBufferWrite( ctxt->doc_buff, len, buffer ); |
| 1800 | 1848 |
| 1801 if ( len < 0 ) { | 1849 if ( len < 0 ) { |
| 1802 xmlChar msg[500]; | 1850 xmlChar msg[500]; |
| 1803 xmlStrPrintf(msg, 500, | 1851 xmlStrPrintf(msg, 500, |
| 1804 (const xmlChar *) "xmlIOHTTPWrite: %s\n%s '%s'.\n", | 1852 (const xmlChar *) "xmlIOHTTPWrite: %s\n%s '%s'.\n", |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1875 xmlStrPrintf(msg, 500, | 1923 xmlStrPrintf(msg, 500, |
| 1876 (const xmlChar *) "xmlIOHTTPCloseWrite: %s '%s' %s '%s'.\n
", | 1924 (const xmlChar *) "xmlIOHTTPCloseWrite: %s '%s' %s '%s'.\n
", |
| 1877 "Error retrieving content.\nUnable to", | 1925 "Error retrieving content.\nUnable to", |
| 1878 http_mthd, "data to URI", ctxt->uri ); | 1926 http_mthd, "data to URI", ctxt->uri ); |
| 1879 xmlIOErr(XML_IO_WRITE, (const char *) msg); | 1927 xmlIOErr(XML_IO_WRITE, (const char *) msg); |
| 1880 } | 1928 } |
| 1881 | 1929 |
| 1882 else { | 1930 else { |
| 1883 | 1931 |
| 1884 http_ctxt = xmlNanoHTTPMethod( ctxt->uri, http_mthd, http_content, | 1932 http_ctxt = xmlNanoHTTPMethod( ctxt->uri, http_mthd, http_content, |
| 1885 » » » » » &content_type, content_encoding, | 1933 » » » » » &content_type, content_encoding, |
| 1886 content_lgth ); | 1934 content_lgth ); |
| 1887 | 1935 |
| 1888 if ( http_ctxt != NULL ) { | 1936 if ( http_ctxt != NULL ) { |
| 1889 #ifdef DEBUG_HTTP | 1937 #ifdef DEBUG_HTTP |
| 1890 /* If testing/debugging - dump reply with request content */ | 1938 /* If testing/debugging - dump reply with request content */ |
| 1891 | 1939 |
| 1892 FILE * tst_file = NULL; | 1940 FILE * tst_file = NULL; |
| 1893 char buffer[ 4096 ]; | 1941 char buffer[ 4096 ]; |
| 1894 char * dump_name = NULL; | 1942 char * dump_name = NULL; |
| 1895 int avail; | 1943 int avail; |
| 1896 | 1944 |
| 1897 xmlGenericError( xmlGenericErrorContext, | 1945 xmlGenericError( xmlGenericErrorContext, |
| 1898 "xmlNanoHTTPCloseWrite: HTTP %s to\n%s returned %d.\n", | 1946 "xmlNanoHTTPCloseWrite: HTTP %s to\n%s returned %d.\n", |
| 1899 http_mthd, ctxt->uri, | 1947 http_mthd, ctxt->uri, |
| 1900 xmlNanoHTTPReturnCode( http_ctxt ) ); | 1948 xmlNanoHTTPReturnCode( http_ctxt ) ); |
| 1901 | 1949 |
| 1902 /* | 1950 /* |
| 1903 ** Since either content or reply may be gzipped, | 1951 ** Since either content or reply may be gzipped, |
| 1904 » ** dump them to separate files instead of the | 1952 » ** dump them to separate files instead of the |
| 1905 ** standard error context. | 1953 ** standard error context. |
| 1906 */ | 1954 */ |
| 1907 | 1955 |
| 1908 dump_name = tempnam( NULL, "lxml" ); | 1956 dump_name = tempnam( NULL, "lxml" ); |
| 1909 if ( dump_name != NULL ) { | 1957 if ( dump_name != NULL ) { |
| 1910 (void)snprintf( buffer, sizeof(buffer), "%s.content", dump_name
); | 1958 (void)snprintf( buffer, sizeof(buffer), "%s.content", dump_name
); |
| 1911 | 1959 |
| 1912 tst_file = fopen( buffer, "wb" ); | 1960 tst_file = fopen( buffer, "wb" ); |
| 1913 if ( tst_file != NULL ) { | 1961 if ( tst_file != NULL ) { |
| 1914 xmlGenericError( xmlGenericErrorContext, | 1962 xmlGenericError( xmlGenericErrorContext, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2031 /** | 2079 /** |
| 2032 * xmlIOFTPRead: | 2080 * xmlIOFTPRead: |
| 2033 * @context: the I/O context | 2081 * @context: the I/O context |
| 2034 * @buffer: where to drop data | 2082 * @buffer: where to drop data |
| 2035 * @len: number of bytes to write | 2083 * @len: number of bytes to write |
| 2036 * | 2084 * |
| 2037 * Read @len bytes to @buffer from the I/O channel. | 2085 * Read @len bytes to @buffer from the I/O channel. |
| 2038 * | 2086 * |
| 2039 * Returns the number of bytes written | 2087 * Returns the number of bytes written |
| 2040 */ | 2088 */ |
| 2041 int | 2089 int |
| 2042 xmlIOFTPRead(void * context, char * buffer, int len) { | 2090 xmlIOFTPRead(void * context, char * buffer, int len) { |
| 2043 if ((buffer == NULL) || (len < 0)) return(-1); | 2091 if ((buffer == NULL) || (len < 0)) return(-1); |
| 2044 return(xmlNanoFTPRead(context, &buffer[0], len)); | 2092 return(xmlNanoFTPRead(context, &buffer[0], len)); |
| 2045 } | 2093 } |
| 2046 | 2094 |
| 2047 /** | 2095 /** |
| 2048 * xmlIOFTPClose: | 2096 * xmlIOFTPClose: |
| 2049 * @context: the I/O context | 2097 * @context: the I/O context |
| 2050 * | 2098 * |
| 2051 * Close an FTP I/O channel | 2099 * Close an FTP I/O channel |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2094 * @closeFunc: the xmlOutputCloseCallback | 2142 * @closeFunc: the xmlOutputCloseCallback |
| 2095 * | 2143 * |
| 2096 * Register a new set of I/O callback for handling output. | 2144 * Register a new set of I/O callback for handling output. |
| 2097 * | 2145 * |
| 2098 * Returns the registered handler number or -1 in case of error | 2146 * Returns the registered handler number or -1 in case of error |
| 2099 */ | 2147 */ |
| 2100 int | 2148 int |
| 2101 xmlRegisterOutputCallbacks(xmlOutputMatchCallback matchFunc, | 2149 xmlRegisterOutputCallbacks(xmlOutputMatchCallback matchFunc, |
| 2102 xmlOutputOpenCallback openFunc, xmlOutputWriteCallback writeFunc, | 2150 xmlOutputOpenCallback openFunc, xmlOutputWriteCallback writeFunc, |
| 2103 xmlOutputCloseCallback closeFunc) { | 2151 xmlOutputCloseCallback closeFunc) { |
| 2104 if (xmlOutputCallbackNr >= MAX_INPUT_CALLBACK) { | 2152 if (xmlOutputCallbackNr >= MAX_OUTPUT_CALLBACK) { |
| 2105 return(-1); | 2153 return(-1); |
| 2106 } | 2154 } |
| 2107 xmlOutputCallbackTable[xmlOutputCallbackNr].matchcallback = matchFunc; | 2155 xmlOutputCallbackTable[xmlOutputCallbackNr].matchcallback = matchFunc; |
| 2108 xmlOutputCallbackTable[xmlOutputCallbackNr].opencallback = openFunc; | 2156 xmlOutputCallbackTable[xmlOutputCallbackNr].opencallback = openFunc; |
| 2109 xmlOutputCallbackTable[xmlOutputCallbackNr].writecallback = writeFunc; | 2157 xmlOutputCallbackTable[xmlOutputCallbackNr].writecallback = writeFunc; |
| 2110 xmlOutputCallbackTable[xmlOutputCallbackNr].closecallback = closeFunc; | 2158 xmlOutputCallbackTable[xmlOutputCallbackNr].closecallback = closeFunc; |
| 2111 xmlOutputCallbackInitialized = 1; | 2159 xmlOutputCallbackInitialized = 1; |
| 2112 return(xmlOutputCallbackNr++); | 2160 return(xmlOutputCallbackNr++); |
| 2113 } | 2161 } |
| 2114 #endif /* LIBXML_OUTPUT_ENABLED */ | 2162 #endif /* LIBXML_OUTPUT_ENABLED */ |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2267 if (ret == NULL) { | 2315 if (ret == NULL) { |
| 2268 xmlIOErrMemory("creating output buffer"); | 2316 xmlIOErrMemory("creating output buffer"); |
| 2269 return(NULL); | 2317 return(NULL); |
| 2270 } | 2318 } |
| 2271 memset(ret, 0, (size_t) sizeof(xmlOutputBuffer)); | 2319 memset(ret, 0, (size_t) sizeof(xmlOutputBuffer)); |
| 2272 ret->buffer = xmlBufferCreate(); | 2320 ret->buffer = xmlBufferCreate(); |
| 2273 if (ret->buffer == NULL) { | 2321 if (ret->buffer == NULL) { |
| 2274 xmlFree(ret); | 2322 xmlFree(ret); |
| 2275 return(NULL); | 2323 return(NULL); |
| 2276 } | 2324 } |
| 2277 ret->buffer->alloc = XML_BUFFER_ALLOC_DOUBLEIT; | 2325 |
| 2326 /* try to avoid a performance problem with Windows realloc() */ |
| 2327 if (ret->buffer->alloc == XML_BUFFER_ALLOC_EXACT) |
| 2328 ret->buffer->alloc = XML_BUFFER_ALLOC_DOUBLEIT; |
| 2329 |
| 2278 ret->encoder = encoder; | 2330 ret->encoder = encoder; |
| 2279 if (encoder != NULL) { | 2331 if (encoder != NULL) { |
| 2280 ret->conv = xmlBufferCreateSize(4000); | 2332 ret->conv = xmlBufferCreateSize(4000); |
| 2333 if (ret->conv == NULL) { |
| 2334 xmlFree(ret); |
| 2335 return(NULL); |
| 2336 } |
| 2337 |
| 2281 /* | 2338 /* |
| 2282 * This call is designed to initiate the encoder state | 2339 * This call is designed to initiate the encoder state |
| 2283 */ | 2340 */ |
| 2284 » xmlCharEncOutFunc(encoder, ret->conv, NULL); | 2341 » xmlCharEncOutFunc(encoder, ret->conv, NULL); |
| 2285 } else | 2342 } else |
| 2286 ret->conv = NULL; | 2343 ret->conv = NULL; |
| 2287 ret->writecallback = NULL; | 2344 ret->writecallback = NULL; |
| 2288 ret->closecallback = NULL; | 2345 ret->closecallback = NULL; |
| 2289 ret->context = NULL; | 2346 ret->context = NULL; |
| 2290 ret->written = 0; | 2347 ret->written = 0; |
| 2291 | 2348 |
| 2292 return(ret); | 2349 return(ret); |
| 2293 } | 2350 } |
| 2351 |
| 2352 /** |
| 2353 * xmlAllocOutputBufferInternal: |
| 2354 * @encoder: the encoding converter or NULL |
| 2355 * |
| 2356 * Create a buffered parser output |
| 2357 * |
| 2358 * Returns the new parser output or NULL |
| 2359 */ |
| 2360 xmlOutputBufferPtr |
| 2361 xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr encoder) { |
| 2362 xmlOutputBufferPtr ret; |
| 2363 |
| 2364 ret = (xmlOutputBufferPtr) xmlMalloc(sizeof(xmlOutputBuffer)); |
| 2365 if (ret == NULL) { |
| 2366 xmlIOErrMemory("creating output buffer"); |
| 2367 return(NULL); |
| 2368 } |
| 2369 memset(ret, 0, (size_t) sizeof(xmlOutputBuffer)); |
| 2370 ret->buffer = xmlBufferCreate(); |
| 2371 if (ret->buffer == NULL) { |
| 2372 xmlFree(ret); |
| 2373 return(NULL); |
| 2374 } |
| 2375 |
| 2376 |
| 2377 /* |
| 2378 * For conversion buffers we use the special IO handling |
| 2379 * We don't do that from the exported API to avoid confusing |
| 2380 * user's code. |
| 2381 */ |
| 2382 ret->buffer->alloc = XML_BUFFER_ALLOC_IO; |
| 2383 ret->buffer->contentIO = ret->buffer->content; |
| 2384 |
| 2385 ret->encoder = encoder; |
| 2386 if (encoder != NULL) { |
| 2387 ret->conv = xmlBufferCreateSize(4000); |
| 2388 if (ret->conv == NULL) { |
| 2389 xmlFree(ret); |
| 2390 return(NULL); |
| 2391 } |
| 2392 |
| 2393 /* |
| 2394 * This call is designed to initiate the encoder state |
| 2395 */ |
| 2396 xmlCharEncOutFunc(encoder, ret->conv, NULL); |
| 2397 } else |
| 2398 ret->conv = NULL; |
| 2399 ret->writecallback = NULL; |
| 2400 ret->closecallback = NULL; |
| 2401 ret->context = NULL; |
| 2402 ret->written = 0; |
| 2403 |
| 2404 return(ret); |
| 2405 } |
| 2406 |
| 2294 #endif /* LIBXML_OUTPUT_ENABLED */ | 2407 #endif /* LIBXML_OUTPUT_ENABLED */ |
| 2295 | 2408 |
| 2296 /** | 2409 /** |
| 2297 * xmlFreeParserInputBuffer: | 2410 * xmlFreeParserInputBuffer: |
| 2298 * @in: a buffered parser input | 2411 * @in: a buffered parser input |
| 2299 * | 2412 * |
| 2300 * Free up the memory used by a buffered parser input | 2413 * Free up the memory used by a buffered parser input |
| 2301 */ | 2414 */ |
| 2302 void | 2415 void |
| 2303 xmlFreeParserInputBuffer(xmlParserInputBufferPtr in) { | 2416 xmlFreeParserInputBuffer(xmlParserInputBufferPtr in) { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2398 * Allocate the Input buffer front-end. | 2511 * Allocate the Input buffer front-end. |
| 2399 */ | 2512 */ |
| 2400 ret = xmlAllocParserInputBuffer(enc); | 2513 ret = xmlAllocParserInputBuffer(enc); |
| 2401 if (ret != NULL) { | 2514 if (ret != NULL) { |
| 2402 ret->context = context; | 2515 ret->context = context; |
| 2403 ret->readcallback = xmlInputCallbackTable[i].readcallback; | 2516 ret->readcallback = xmlInputCallbackTable[i].readcallback; |
| 2404 ret->closecallback = xmlInputCallbackTable[i].closecallback; | 2517 ret->closecallback = xmlInputCallbackTable[i].closecallback; |
| 2405 #ifdef HAVE_ZLIB_H | 2518 #ifdef HAVE_ZLIB_H |
| 2406 if ((xmlInputCallbackTable[i].opencallback == xmlGzfileOpen) && | 2519 if ((xmlInputCallbackTable[i].opencallback == xmlGzfileOpen) && |
| 2407 (strcmp(URI, "-") != 0)) { | 2520 (strcmp(URI, "-") != 0)) { |
| 2521 #if defined(ZLIB_VERNUM) && ZLIB_VERNUM >= 0x1230 |
| 2522 ret->compressed = !gzdirect(context); |
| 2523 #else |
| 2408 if (((z_stream *)context)->avail_in > 4) { | 2524 if (((z_stream *)context)->avail_in > 4) { |
| 2409 char *cptr, buff4[4]; | 2525 char *cptr, buff4[4]; |
| 2410 cptr = (char *) ((z_stream *)context)->next_in; | 2526 cptr = (char *) ((z_stream *)context)->next_in; |
| 2411 if (gzread(context, buff4, 4) == 4) { | 2527 if (gzread(context, buff4, 4) == 4) { |
| 2412 if (strncmp(buff4, cptr, 4) == 0) | 2528 if (strncmp(buff4, cptr, 4) == 0) |
| 2413 ret->compressed = 0; | 2529 ret->compressed = 0; |
| 2414 else | 2530 else |
| 2415 ret->compressed = 1; | 2531 ret->compressed = 1; |
| 2416 gzrewind(context); | 2532 gzrewind(context); |
| 2417 } | 2533 } |
| 2418 } | 2534 } |
| 2535 #endif |
| 2419 } | 2536 } |
| 2420 #endif | 2537 #endif |
| 2421 } | 2538 } |
| 2422 else | 2539 else |
| 2423 xmlInputCallbackTable[i].closecallback (context); | 2540 xmlInputCallbackTable[i].closecallback (context); |
| 2424 | 2541 |
| 2425 return(ret); | 2542 return(ret); |
| 2426 } | 2543 } |
| 2427 | 2544 |
| 2428 /** | 2545 /** |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2484 /* | 2601 /* |
| 2485 * Try to find one of the output accept method accepting that scheme | 2602 * Try to find one of the output accept method accepting that scheme |
| 2486 * Go in reverse to give precedence to user defined handlers. | 2603 * Go in reverse to give precedence to user defined handlers. |
| 2487 * try with an unescaped version of the URI | 2604 * try with an unescaped version of the URI |
| 2488 */ | 2605 */ |
| 2489 if (unescaped != NULL) { | 2606 if (unescaped != NULL) { |
| 2490 #ifdef HAVE_ZLIB_H | 2607 #ifdef HAVE_ZLIB_H |
| 2491 if ((compression > 0) && (compression <= 9) && (is_file_uri == 1)) { | 2608 if ((compression > 0) && (compression <= 9) && (is_file_uri == 1)) { |
| 2492 context = xmlGzfileOpenW(unescaped, compression); | 2609 context = xmlGzfileOpenW(unescaped, compression); |
| 2493 if (context != NULL) { | 2610 if (context != NULL) { |
| 2494 » » ret = xmlAllocOutputBuffer(encoder); | 2611 » » ret = xmlAllocOutputBufferInternal(encoder); |
| 2495 if (ret != NULL) { | 2612 if (ret != NULL) { |
| 2496 ret->context = context; | 2613 ret->context = context; |
| 2497 ret->writecallback = xmlGzfileWrite; | 2614 ret->writecallback = xmlGzfileWrite; |
| 2498 ret->closecallback = xmlGzfileClose; | 2615 ret->closecallback = xmlGzfileClose; |
| 2499 } | 2616 } |
| 2500 xmlFree(unescaped); | 2617 xmlFree(unescaped); |
| 2501 return(ret); | 2618 return(ret); |
| 2502 } | 2619 } |
| 2503 } | 2620 } |
| 2504 #endif | 2621 #endif |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2521 | 2638 |
| 2522 /* | 2639 /* |
| 2523 * If this failed try with a non-escaped URI this may be a strange | 2640 * If this failed try with a non-escaped URI this may be a strange |
| 2524 * filename | 2641 * filename |
| 2525 */ | 2642 */ |
| 2526 if (context == NULL) { | 2643 if (context == NULL) { |
| 2527 #ifdef HAVE_ZLIB_H | 2644 #ifdef HAVE_ZLIB_H |
| 2528 if ((compression > 0) && (compression <= 9) && (is_file_uri == 1)) { | 2645 if ((compression > 0) && (compression <= 9) && (is_file_uri == 1)) { |
| 2529 context = xmlGzfileOpenW(URI, compression); | 2646 context = xmlGzfileOpenW(URI, compression); |
| 2530 if (context != NULL) { | 2647 if (context != NULL) { |
| 2531 » » ret = xmlAllocOutputBuffer(encoder); | 2648 » » ret = xmlAllocOutputBufferInternal(encoder); |
| 2532 if (ret != NULL) { | 2649 if (ret != NULL) { |
| 2533 ret->context = context; | 2650 ret->context = context; |
| 2534 ret->writecallback = xmlGzfileWrite; | 2651 ret->writecallback = xmlGzfileWrite; |
| 2535 ret->closecallback = xmlGzfileClose; | 2652 ret->closecallback = xmlGzfileClose; |
| 2536 } | 2653 } |
| 2537 return(ret); | 2654 return(ret); |
| 2538 } | 2655 } |
| 2539 } | 2656 } |
| 2540 #endif | 2657 #endif |
| 2541 for (i = xmlOutputCallbackNr - 1;i >= 0;i--) { | 2658 for (i = xmlOutputCallbackNr - 1;i >= 0;i--) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2554 } | 2671 } |
| 2555 } | 2672 } |
| 2556 | 2673 |
| 2557 if (context == NULL) { | 2674 if (context == NULL) { |
| 2558 return(NULL); | 2675 return(NULL); |
| 2559 } | 2676 } |
| 2560 | 2677 |
| 2561 /* | 2678 /* |
| 2562 * Allocate the Output buffer front-end. | 2679 * Allocate the Output buffer front-end. |
| 2563 */ | 2680 */ |
| 2564 ret = xmlAllocOutputBuffer(encoder); | 2681 ret = xmlAllocOutputBufferInternal(encoder); |
| 2565 if (ret != NULL) { | 2682 if (ret != NULL) { |
| 2566 ret->context = context; | 2683 ret->context = context; |
| 2567 ret->writecallback = xmlOutputCallbackTable[i].writecallback; | 2684 ret->writecallback = xmlOutputCallbackTable[i].writecallback; |
| 2568 ret->closecallback = xmlOutputCallbackTable[i].closecallback; | 2685 ret->closecallback = xmlOutputCallbackTable[i].closecallback; |
| 2569 } | 2686 } |
| 2570 return(ret); | 2687 return(ret); |
| 2571 } | 2688 } |
| 2572 | 2689 |
| 2573 /** | 2690 /** |
| 2574 * xmlOutputBufferCreateFilename: | 2691 * xmlOutputBufferCreateFilename: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2591 int compression ATTRIBUTE_UNUSED) { | 2708 int compression ATTRIBUTE_UNUSED) { |
| 2592 if ((xmlOutputBufferCreateFilenameValue)) { | 2709 if ((xmlOutputBufferCreateFilenameValue)) { |
| 2593 return xmlOutputBufferCreateFilenameValue(URI, encoder, compress
ion); | 2710 return xmlOutputBufferCreateFilenameValue(URI, encoder, compress
ion); |
| 2594 } | 2711 } |
| 2595 return __xmlOutputBufferCreateFilename(URI, encoder, compression); | 2712 return __xmlOutputBufferCreateFilename(URI, encoder, compression); |
| 2596 } | 2713 } |
| 2597 #endif /* LIBXML_OUTPUT_ENABLED */ | 2714 #endif /* LIBXML_OUTPUT_ENABLED */ |
| 2598 | 2715 |
| 2599 /** | 2716 /** |
| 2600 * xmlParserInputBufferCreateFile: | 2717 * xmlParserInputBufferCreateFile: |
| 2601 * @file: a FILE* | 2718 * @file: a FILE* |
| 2602 * @enc: the charset encoding if known | 2719 * @enc: the charset encoding if known |
| 2603 * | 2720 * |
| 2604 * Create a buffered parser input for the progressive parsing of a FILE * | 2721 * Create a buffered parser input for the progressive parsing of a FILE * |
| 2605 * buffered C I/O | 2722 * buffered C I/O |
| 2606 * | 2723 * |
| 2607 * Returns the new parser input or NULL | 2724 * Returns the new parser input or NULL |
| 2608 */ | 2725 */ |
| 2609 xmlParserInputBufferPtr | 2726 xmlParserInputBufferPtr |
| 2610 xmlParserInputBufferCreateFile(FILE *file, xmlCharEncoding enc) { | 2727 xmlParserInputBufferCreateFile(FILE *file, xmlCharEncoding enc) { |
| 2611 xmlParserInputBufferPtr ret; | 2728 xmlParserInputBufferPtr ret; |
| 2612 | 2729 |
| 2613 if (xmlInputCallbackInitialized == 0) | 2730 if (xmlInputCallbackInitialized == 0) |
| 2614 xmlRegisterDefaultInputCallbacks(); | 2731 xmlRegisterDefaultInputCallbacks(); |
| 2615 | 2732 |
| 2616 if (file == NULL) return(NULL); | 2733 if (file == NULL) return(NULL); |
| 2617 | 2734 |
| 2618 ret = xmlAllocParserInputBuffer(enc); | 2735 ret = xmlAllocParserInputBuffer(enc); |
| 2619 if (ret != NULL) { | 2736 if (ret != NULL) { |
| 2620 ret->context = file; | 2737 ret->context = file; |
| 2621 ret->readcallback = xmlFileRead; | 2738 ret->readcallback = xmlFileRead; |
| 2622 ret->closecallback = xmlFileFlush; | 2739 ret->closecallback = xmlFileFlush; |
| 2623 } | 2740 } |
| 2624 | 2741 |
| 2625 return(ret); | 2742 return(ret); |
| 2626 } | 2743 } |
| 2627 | 2744 |
| 2628 #ifdef LIBXML_OUTPUT_ENABLED | 2745 #ifdef LIBXML_OUTPUT_ENABLED |
| 2629 /** | 2746 /** |
| 2630 * xmlOutputBufferCreateFile: | 2747 * xmlOutputBufferCreateFile: |
| 2631 * @file: a FILE* | 2748 * @file: a FILE* |
| 2632 * @encoder: the encoding converter or NULL | 2749 * @encoder: the encoding converter or NULL |
| 2633 * | 2750 * |
| 2634 * Create a buffered output for the progressive saving to a FILE * | 2751 * Create a buffered output for the progressive saving to a FILE * |
| 2635 * buffered C I/O | 2752 * buffered C I/O |
| 2636 * | 2753 * |
| 2637 * Returns the new parser output or NULL | 2754 * Returns the new parser output or NULL |
| 2638 */ | 2755 */ |
| 2639 xmlOutputBufferPtr | 2756 xmlOutputBufferPtr |
| 2640 xmlOutputBufferCreateFile(FILE *file, xmlCharEncodingHandlerPtr encoder) { | 2757 xmlOutputBufferCreateFile(FILE *file, xmlCharEncodingHandlerPtr encoder) { |
| 2641 xmlOutputBufferPtr ret; | 2758 xmlOutputBufferPtr ret; |
| 2642 | 2759 |
| 2643 if (xmlOutputCallbackInitialized == 0) | 2760 if (xmlOutputCallbackInitialized == 0) |
| 2644 xmlRegisterDefaultOutputCallbacks(); | 2761 xmlRegisterDefaultOutputCallbacks(); |
| 2645 | 2762 |
| 2646 if (file == NULL) return(NULL); | 2763 if (file == NULL) return(NULL); |
| 2647 | 2764 |
| 2648 ret = xmlAllocOutputBuffer(encoder); | 2765 ret = xmlAllocOutputBufferInternal(encoder); |
| 2649 if (ret != NULL) { | 2766 if (ret != NULL) { |
| 2650 ret->context = file; | 2767 ret->context = file; |
| 2651 ret->writecallback = xmlFileWrite; | 2768 ret->writecallback = xmlFileWrite; |
| 2652 ret->closecallback = xmlFileFlush; | 2769 ret->closecallback = xmlFileFlush; |
| 2653 } | 2770 } |
| 2654 | 2771 |
| 2655 return(ret); | 2772 return(ret); |
| 2656 } | 2773 } |
| 2657 | 2774 |
| 2658 /** | 2775 /** |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2785 | 2902 |
| 2786 return(ret); | 2903 return(ret); |
| 2787 } | 2904 } |
| 2788 | 2905 |
| 2789 #ifdef LIBXML_OUTPUT_ENABLED | 2906 #ifdef LIBXML_OUTPUT_ENABLED |
| 2790 /** | 2907 /** |
| 2791 * xmlOutputBufferCreateFd: | 2908 * xmlOutputBufferCreateFd: |
| 2792 * @fd: a file descriptor number | 2909 * @fd: a file descriptor number |
| 2793 * @encoder: the encoding converter or NULL | 2910 * @encoder: the encoding converter or NULL |
| 2794 * | 2911 * |
| 2795 * Create a buffered output for the progressive saving | 2912 * Create a buffered output for the progressive saving |
| 2796 * to a file descriptor | 2913 * to a file descriptor |
| 2797 * | 2914 * |
| 2798 * Returns the new parser output or NULL | 2915 * Returns the new parser output or NULL |
| 2799 */ | 2916 */ |
| 2800 xmlOutputBufferPtr | 2917 xmlOutputBufferPtr |
| 2801 xmlOutputBufferCreateFd(int fd, xmlCharEncodingHandlerPtr encoder) { | 2918 xmlOutputBufferCreateFd(int fd, xmlCharEncodingHandlerPtr encoder) { |
| 2802 xmlOutputBufferPtr ret; | 2919 xmlOutputBufferPtr ret; |
| 2803 | 2920 |
| 2804 if (fd < 0) return(NULL); | 2921 if (fd < 0) return(NULL); |
| 2805 | 2922 |
| 2806 ret = xmlAllocOutputBuffer(encoder); | 2923 ret = xmlAllocOutputBufferInternal(encoder); |
| 2807 if (ret != NULL) { | 2924 if (ret != NULL) { |
| 2808 ret->context = (void *) (long) fd; | 2925 ret->context = (void *) (long) fd; |
| 2809 ret->writecallback = xmlFdWrite; | 2926 ret->writecallback = xmlFdWrite; |
| 2810 ret->closecallback = NULL; | 2927 ret->closecallback = NULL; |
| 2811 } | 2928 } |
| 2812 | 2929 |
| 2813 return(ret); | 2930 return(ret); |
| 2814 } | 2931 } |
| 2815 #endif /* LIBXML_OUTPUT_ENABLED */ | 2932 #endif /* LIBXML_OUTPUT_ENABLED */ |
| 2816 | 2933 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2857 * Returns the new parser output or NULL | 2974 * Returns the new parser output or NULL |
| 2858 */ | 2975 */ |
| 2859 xmlOutputBufferPtr | 2976 xmlOutputBufferPtr |
| 2860 xmlOutputBufferCreateIO(xmlOutputWriteCallback iowrite, | 2977 xmlOutputBufferCreateIO(xmlOutputWriteCallback iowrite, |
| 2861 xmlOutputCloseCallback ioclose, void *ioctx, | 2978 xmlOutputCloseCallback ioclose, void *ioctx, |
| 2862 xmlCharEncodingHandlerPtr encoder) { | 2979 xmlCharEncodingHandlerPtr encoder) { |
| 2863 xmlOutputBufferPtr ret; | 2980 xmlOutputBufferPtr ret; |
| 2864 | 2981 |
| 2865 if (iowrite == NULL) return(NULL); | 2982 if (iowrite == NULL) return(NULL); |
| 2866 | 2983 |
| 2867 ret = xmlAllocOutputBuffer(encoder); | 2984 ret = xmlAllocOutputBufferInternal(encoder); |
| 2868 if (ret != NULL) { | 2985 if (ret != NULL) { |
| 2869 ret->context = (void *) ioctx; | 2986 ret->context = (void *) ioctx; |
| 2870 ret->writecallback = iowrite; | 2987 ret->writecallback = iowrite; |
| 2871 ret->closecallback = ioclose; | 2988 ret->closecallback = ioclose; |
| 2872 } | 2989 } |
| 2873 | 2990 |
| 2874 return(ret); | 2991 return(ret); |
| 2875 } | 2992 } |
| 2876 #endif /* LIBXML_OUTPUT_ENABLED */ | 2993 #endif /* LIBXML_OUTPUT_ENABLED */ |
| 2877 | 2994 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3067 use = in->raw->use; | 3184 use = in->raw->use; |
| 3068 nbchars = xmlCharEncInFunc(in->encoder, in->buffer, in->raw); | 3185 nbchars = xmlCharEncInFunc(in->encoder, in->buffer, in->raw); |
| 3069 if (nbchars < 0) { | 3186 if (nbchars < 0) { |
| 3070 xmlIOErr(XML_IO_ENCODER, NULL); | 3187 xmlIOErr(XML_IO_ENCODER, NULL); |
| 3071 in->error = XML_IO_ENCODER; | 3188 in->error = XML_IO_ENCODER; |
| 3072 return(-1); | 3189 return(-1); |
| 3073 } | 3190 } |
| 3074 in->rawconsumed += (use - in->raw->use); | 3191 in->rawconsumed += (use - in->raw->use); |
| 3075 } else { | 3192 } else { |
| 3076 nbchars = len; | 3193 nbchars = len; |
| 3077 » in->buffer->use += nbchars; | 3194 » in->buffer->use += nbchars; |
| 3078 buffer[nbchars] = 0; | 3195 buffer[nbchars] = 0; |
| 3079 } | 3196 } |
| 3080 #ifdef DEBUG_INPUT | 3197 #ifdef DEBUG_INPUT |
| 3081 xmlGenericError(xmlGenericErrorContext, | 3198 xmlGenericError(xmlGenericErrorContext, |
| 3082 "I/O: read %d chars, buffer %d/%d\n", | 3199 "I/O: read %d chars, buffer %d/%d\n", |
| 3083 nbchars, in->buffer->use, in->buffer->size); | 3200 nbchars, in->buffer->use, in->buffer->size); |
| 3084 #endif | 3201 #endif |
| 3085 return(nbchars); | 3202 return(nbchars); |
| 3086 } | 3203 } |
| 3087 | 3204 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3177 len -= chunk; | 3294 len -= chunk; |
| 3178 | 3295 |
| 3179 if ((nbchars < MINLEN) && (len <= 0)) | 3296 if ((nbchars < MINLEN) && (len <= 0)) |
| 3180 goto done; | 3297 goto done; |
| 3181 | 3298 |
| 3182 if (out->writecallback) { | 3299 if (out->writecallback) { |
| 3183 /* | 3300 /* |
| 3184 * second write the stuff to the I/O channel | 3301 * second write the stuff to the I/O channel |
| 3185 */ | 3302 */ |
| 3186 if (out->encoder != NULL) { | 3303 if (out->encoder != NULL) { |
| 3187 » » ret = out->writecallback(out->context, | 3304 » » ret = out->writecallback(out->context, |
| 3188 (const char *)out->conv->content, nbchars); | 3305 (const char *)out->conv->content, nbchars); |
| 3189 if (ret >= 0) | 3306 if (ret >= 0) |
| 3190 xmlBufferShrink(out->conv, ret); | 3307 xmlBufferShrink(out->conv, ret); |
| 3191 } else { | 3308 } else { |
| 3192 » » ret = out->writecallback(out->context, | 3309 » » ret = out->writecallback(out->context, |
| 3193 (const char *)out->buffer->content, nbchars); | 3310 (const char *)out->buffer->content, nbchars); |
| 3194 if (ret >= 0) | 3311 if (ret >= 0) |
| 3195 xmlBufferShrink(out->buffer, ret); | 3312 xmlBufferShrink(out->buffer, ret); |
| 3196 } | 3313 } |
| 3197 if (ret < 0) { | 3314 if (ret < 0) { |
| 3198 xmlIOErr(XML_IO_WRITE, NULL); | 3315 xmlIOErr(XML_IO_WRITE, NULL); |
| 3199 out->error = XML_IO_WRITE; | 3316 out->error = XML_IO_WRITE; |
| 3200 return(ret); | 3317 return(ret); |
| 3201 } | 3318 } |
| 3202 out->written += ret; | 3319 out->written += ret; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3227 */ | 3344 */ |
| 3228 static int | 3345 static int |
| 3229 xmlEscapeContent(unsigned char* out, int *outlen, | 3346 xmlEscapeContent(unsigned char* out, int *outlen, |
| 3230 const xmlChar* in, int *inlen) { | 3347 const xmlChar* in, int *inlen) { |
| 3231 unsigned char* outstart = out; | 3348 unsigned char* outstart = out; |
| 3232 const unsigned char* base = in; | 3349 const unsigned char* base = in; |
| 3233 unsigned char* outend = out + *outlen; | 3350 unsigned char* outend = out + *outlen; |
| 3234 const unsigned char* inend; | 3351 const unsigned char* inend; |
| 3235 | 3352 |
| 3236 inend = in + (*inlen); | 3353 inend = in + (*inlen); |
| 3237 | 3354 |
| 3238 while ((in < inend) && (out < outend)) { | 3355 while ((in < inend) && (out < outend)) { |
| 3239 » if (*in == '<') { | 3356 » if (*in == '<') { |
| 3240 if (outend - out < 4) break; | 3357 if (outend - out < 4) break; |
| 3241 *out++ = '&'; | 3358 *out++ = '&'; |
| 3242 *out++ = 'l'; | 3359 *out++ = 'l'; |
| 3243 *out++ = 't'; | 3360 *out++ = 't'; |
| 3244 *out++ = ';'; | 3361 *out++ = ';'; |
| 3245 } else if (*in == '>') { | 3362 } else if (*in == '>') { |
| 3246 if (outend - out < 4) break; | 3363 if (outend - out < 4) break; |
| 3247 *out++ = '&'; | 3364 *out++ = '&'; |
| 3248 *out++ = 'g'; | 3365 *out++ = 'g'; |
| 3249 *out++ = 't'; | 3366 *out++ = 't'; |
| 3250 *out++ = ';'; | 3367 *out++ = ';'; |
| 3251 } else if (*in == '&') { | 3368 } else if (*in == '&') { |
| 3252 if (outend - out < 5) break; | 3369 if (outend - out < 5) break; |
| 3253 *out++ = '&'; | 3370 *out++ = '&'; |
| 3254 *out++ = 'a'; | 3371 *out++ = 'a'; |
| 3255 *out++ = 'm'; | 3372 *out++ = 'm'; |
| 3256 *out++ = 'p'; | 3373 *out++ = 'p'; |
| 3257 *out++ = ';'; | 3374 *out++ = ';'; |
| 3258 } else if (*in == '\r') { | 3375 } else if (*in == '\r') { |
| 3259 if (outend - out < 5) break; | 3376 if (outend - out < 5) break; |
| 3260 *out++ = '&'; | 3377 *out++ = '&'; |
| 3261 *out++ = '#'; | 3378 *out++ = '#'; |
| 3262 *out++ = '1'; | 3379 *out++ = '1'; |
| 3263 *out++ = '3'; | 3380 *out++ = '3'; |
| 3264 *out++ = ';'; | 3381 *out++ = ';'; |
| 3265 } else { | 3382 } else { |
| 3266 *out++ = (unsigned char) *in; | 3383 *out++ = (unsigned char) *in; |
| 3267 } | 3384 } |
| 3268 ++in; | 3385 ++in; |
| 3269 }» | 3386 } |
| 3270 *outlen = out - outstart; | 3387 *outlen = out - outstart; |
| 3271 *inlen = in - base; | 3388 *inlen = in - base; |
| 3272 return(0); | 3389 return(0); |
| 3273 } | 3390 } |
| 3274 | 3391 |
| 3275 /** | 3392 /** |
| 3276 * xmlOutputBufferWriteEscape: | 3393 * xmlOutputBufferWriteEscape: |
| 3277 * @out: a buffered parser output | 3394 * @out: a buffered parser output |
| 3278 * @str: a zero terminated UTF-8 string | 3395 * @str: a zero terminated UTF-8 string |
| 3279 * @escaping: an optional escaping function (or NULL) | 3396 * @escaping: an optional escaping function (or NULL) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3313 * how many bytes to consume and how many bytes to store. | 3430 * how many bytes to consume and how many bytes to store. |
| 3314 */ | 3431 */ |
| 3315 cons = len; | 3432 cons = len; |
| 3316 chunk = (out->buffer->size - out->buffer->use) - 1; | 3433 chunk = (out->buffer->size - out->buffer->use) - 1; |
| 3317 | 3434 |
| 3318 /* | 3435 /* |
| 3319 * make sure we have enough room to save first, if this is | 3436 * make sure we have enough room to save first, if this is |
| 3320 * not the case force a flush, but make sure we stay in the loop | 3437 * not the case force a flush, but make sure we stay in the loop |
| 3321 */ | 3438 */ |
| 3322 if (chunk < 40) { | 3439 if (chunk < 40) { |
| 3323 » nbchars = 0; | 3440 » if (xmlBufferGrow(out->buffer, out->buffer->size + 100) < 0) |
| 3324 » oldwritten = -1; | 3441 » return(-1); |
| 3325 » goto flush; | 3442 oldwritten = -1; |
| 3443 » continue; |
| 3326 } | 3444 } |
| 3327 | 3445 |
| 3328 /* | 3446 /* |
| 3329 * first handle encoding stuff. | 3447 * first handle encoding stuff. |
| 3330 */ | 3448 */ |
| 3331 if (out->encoder != NULL) { | 3449 if (out->encoder != NULL) { |
| 3332 /* | 3450 /* |
| 3333 * Store the data in the incoming raw buffer | 3451 * Store the data in the incoming raw buffer |
| 3334 */ | 3452 */ |
| 3335 if (out->conv == NULL) { | 3453 if (out->conv == NULL) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 3363 out->buffer->use += chunk; | 3481 out->buffer->use += chunk; |
| 3364 out->buffer->content[out->buffer->use] = 0; | 3482 out->buffer->content[out->buffer->use] = 0; |
| 3365 nbchars = out->buffer->use; | 3483 nbchars = out->buffer->use; |
| 3366 } | 3484 } |
| 3367 str += cons; | 3485 str += cons; |
| 3368 len -= cons; | 3486 len -= cons; |
| 3369 | 3487 |
| 3370 if ((nbchars < MINLEN) && (len <= 0)) | 3488 if ((nbchars < MINLEN) && (len <= 0)) |
| 3371 goto done; | 3489 goto done; |
| 3372 | 3490 |
| 3373 flush: | |
| 3374 if (out->writecallback) { | 3491 if (out->writecallback) { |
| 3375 /* | 3492 /* |
| 3376 * second write the stuff to the I/O channel | 3493 * second write the stuff to the I/O channel |
| 3377 */ | 3494 */ |
| 3378 if (out->encoder != NULL) { | 3495 if (out->encoder != NULL) { |
| 3379 » » ret = out->writecallback(out->context, | 3496 » » ret = out->writecallback(out->context, |
| 3380 (const char *)out->conv->content, nbchars); | 3497 (const char *)out->conv->content, nbchars); |
| 3381 if (ret >= 0) | 3498 if (ret >= 0) |
| 3382 xmlBufferShrink(out->conv, ret); | 3499 xmlBufferShrink(out->conv, ret); |
| 3383 } else { | 3500 } else { |
| 3384 » » ret = out->writecallback(out->context, | 3501 » » ret = out->writecallback(out->context, |
| 3385 (const char *)out->buffer->content, nbchars); | 3502 (const char *)out->buffer->content, nbchars); |
| 3386 if (ret >= 0) | 3503 if (ret >= 0) |
| 3387 xmlBufferShrink(out->buffer, ret); | 3504 xmlBufferShrink(out->buffer, ret); |
| 3388 } | 3505 } |
| 3389 if (ret < 0) { | 3506 if (ret < 0) { |
| 3390 xmlIOErr(XML_IO_WRITE, NULL); | 3507 xmlIOErr(XML_IO_WRITE, NULL); |
| 3391 out->error = XML_IO_WRITE; | 3508 out->error = XML_IO_WRITE; |
| 3392 return(ret); | 3509 return(ret); |
| 3393 } | 3510 } |
| 3394 out->written += ret; | 3511 out->written += ret; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 3415 * This routine handle the I18N transcoding from internal UTF-8 | 3532 * This routine handle the I18N transcoding from internal UTF-8 |
| 3416 * The buffer is lossless, i.e. will store in case of partial | 3533 * The buffer is lossless, i.e. will store in case of partial |
| 3417 * or delayed writes. | 3534 * or delayed writes. |
| 3418 * | 3535 * |
| 3419 * Returns the number of chars immediately written, or -1 | 3536 * Returns the number of chars immediately written, or -1 |
| 3420 * in case of error. | 3537 * in case of error. |
| 3421 */ | 3538 */ |
| 3422 int | 3539 int |
| 3423 xmlOutputBufferWriteString(xmlOutputBufferPtr out, const char *str) { | 3540 xmlOutputBufferWriteString(xmlOutputBufferPtr out, const char *str) { |
| 3424 int len; | 3541 int len; |
| 3425 | 3542 |
| 3426 if ((out == NULL) || (out->error)) return(-1); | 3543 if ((out == NULL) || (out->error)) return(-1); |
| 3427 if (str == NULL) | 3544 if (str == NULL) |
| 3428 return(-1); | 3545 return(-1); |
| 3429 len = strlen(str); | 3546 len = strlen(str); |
| 3430 | 3547 |
| 3431 if (len > 0) | 3548 if (len > 0) |
| 3432 return(xmlOutputBufferWrite(out, len, str)); | 3549 return(xmlOutputBufferWrite(out, len, str)); |
| 3433 return(len); | 3550 return(len); |
| 3434 } | 3551 } |
| 3435 | 3552 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3632 path = &URL[17]; | 3749 path = &URL[17]; |
| 3633 #else | 3750 #else |
| 3634 path = &URL[16]; | 3751 path = &URL[16]; |
| 3635 #endif | 3752 #endif |
| 3636 else if (!xmlStrncasecmp(BAD_CAST URL, BAD_CAST "file:///", 8)) { | 3753 else if (!xmlStrncasecmp(BAD_CAST URL, BAD_CAST "file:///", 8)) { |
| 3637 #if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) | 3754 #if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__) |
| 3638 path = &URL[8]; | 3755 path = &URL[8]; |
| 3639 #else | 3756 #else |
| 3640 path = &URL[7]; | 3757 path = &URL[7]; |
| 3641 #endif | 3758 #endif |
| 3642 } else | 3759 } else |
| 3643 path = URL; | 3760 path = URL; |
| 3644 » | 3761 |
| 3645 return xmlCheckFilename(path); | 3762 return xmlCheckFilename(path); |
| 3646 } | 3763 } |
| 3647 | 3764 |
| 3648 #ifdef LIBXML_CATALOG_ENABLED | 3765 #ifdef LIBXML_CATALOG_ENABLED |
| 3649 | 3766 |
| 3650 /** | 3767 /** |
| 3651 * xmlResolveResourceFromCatalog: | 3768 * xmlResolveResourceFromCatalog: |
| 3652 * @URL: the URL for the entity to load | 3769 * @URL: the URL for the entity to load |
| 3653 * @ID: the System ID for the entity to load | 3770 * @ID: the System ID for the entity to load |
| 3654 * @ctxt: the context in which the entity is called or NULL | 3771 * @ctxt: the context in which the entity is called or NULL |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3822 } | 3939 } |
| 3823 | 3940 |
| 3824 ret = xmlCurrentExternalEntityLoader(canonicFilename, ID, ctxt); | 3941 ret = xmlCurrentExternalEntityLoader(canonicFilename, ID, ctxt); |
| 3825 xmlFree(canonicFilename); | 3942 xmlFree(canonicFilename); |
| 3826 return(ret); | 3943 return(ret); |
| 3827 } | 3944 } |
| 3828 return(xmlCurrentExternalEntityLoader(URL, ID, ctxt)); | 3945 return(xmlCurrentExternalEntityLoader(URL, ID, ctxt)); |
| 3829 } | 3946 } |
| 3830 | 3947 |
| 3831 /************************************************************************ | 3948 /************************************************************************ |
| 3832 * » » » » » » » » » * | 3949 *» » » » » » » » » * |
| 3833 * » » Disabling Network access» » » » * | 3950 *» » Disabling Network access» » » » * |
| 3834 * » » » » » » » » » * | 3951 *» » » » » » » » » * |
| 3835 ************************************************************************/ | 3952 ************************************************************************/ |
| 3836 | 3953 |
| 3837 /** | 3954 /** |
| 3838 * xmlNoNetExternalEntityLoader: | 3955 * xmlNoNetExternalEntityLoader: |
| 3839 * @URL: the URL for the entity to load | 3956 * @URL: the URL for the entity to load |
| 3840 * @ID: the System ID for the entity to load | 3957 * @ID: the System ID for the entity to load |
| 3841 * @ctxt: the context in which the entity is called or NULL | 3958 * @ctxt: the context in which the entity is called or NULL |
| 3842 * | 3959 * |
| 3843 * A specific entity loader disabling network accesses, though still | 3960 * A specific entity loader disabling network accesses, though still |
| 3844 * allowing local catalog accesses for resolution. | 3961 * allowing local catalog accesses for resolution. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3868 } | 3985 } |
| 3869 } | 3986 } |
| 3870 input = xmlDefaultExternalEntityLoader((const char *) resource, ID, ctxt); | 3987 input = xmlDefaultExternalEntityLoader((const char *) resource, ID, ctxt); |
| 3871 if (resource != (xmlChar *) URL) | 3988 if (resource != (xmlChar *) URL) |
| 3872 xmlFree(resource); | 3989 xmlFree(resource); |
| 3873 return(input); | 3990 return(input); |
| 3874 } | 3991 } |
| 3875 | 3992 |
| 3876 #define bottom_xmlIO | 3993 #define bottom_xmlIO |
| 3877 #include "elfgcchack.h" | 3994 #include "elfgcchack.h" |
| OLD | NEW |