* xmlTextReaderPushData: * @reader: the xmlTextReaderPtr used * * Push data down the progressive parser until a significant callback * got raised. * * Returns -1 in case of failure, 0 otherwise */
| 769 | * Returns -1 in case of failure, 0 otherwise |
| 770 | */ |
| 771 | static int |
| 772 | xmlTextReaderPushData(xmlTextReaderPtr reader) { |
| 773 | xmlBufPtr inbuf; |
| 774 | int val, s; |
| 775 | xmlTextReaderState oldstate; |
| 776 | |
| 777 | if ((reader->input == NULL) || (reader->input->buffer == NULL)) |
| 778 | return(-1); |
| 779 | |
| 780 | oldstate = reader->state; |
| 781 | reader->state = XML_TEXTREADER_NONE; |
| 782 | inbuf = reader->input->buffer; |
| 783 | |
| 784 | while (reader->state == XML_TEXTREADER_NONE) { |
| 785 | if (xmlBufUse(inbuf) < reader->cur + CHUNK_SIZE) { |
| 786 | /* |
| 787 | * Refill the buffer unless we are at the end of the stream |
| 788 | */ |
| 789 | if (reader->mode != XML_TEXTREADER_MODE_EOF) { |
| 790 | val = xmlParserInputBufferRead(reader->input, 4096); |
| 791 | if (val == 0) { |
| 792 | if (xmlBufUse(inbuf) == reader->cur) { |
| 793 | reader->mode = XML_TEXTREADER_MODE_EOF; |
| 794 | break; |
| 795 | } |
| 796 | } else if (val < 0) { |
| 797 | xmlCtxtErrIO(reader->ctxt, reader->input->error, NULL); |
| 798 | reader->mode = XML_TEXTREADER_MODE_ERROR; |
| 799 | reader->state = XML_TEXTREADER_ERROR; |
| 800 | return(-1); |
| 801 | } |
| 802 | |
| 803 | } else |
| 804 | break; |
| 805 | } |
| 806 | /* |
| 807 | * parse by block of CHUNK_SIZE bytes, various tests show that |
| 808 | * it's the best tradeoff at least on a 1.2GH Duron |
| 809 | */ |
| 810 | if (xmlBufUse(inbuf) >= reader->cur + CHUNK_SIZE) { |
| 811 | val = xmlParseChunk(reader->ctxt, |
| 812 | (const char *) xmlBufContent(inbuf) + reader->cur, |
| 813 | CHUNK_SIZE, 0); |
| 814 | reader->cur += CHUNK_SIZE; |
| 815 | if (val != 0) |
| 816 | reader->ctxt->wellFormed = 0; |
| 817 | if (reader->ctxt->wellFormed == 0) |
| 818 | break; |
| 819 | } else { |
| 820 | s = xmlBufUse(inbuf) - reader->cur; |
| 821 | val = xmlParseChunk(reader->ctxt, |
| 822 | (const char *) xmlBufContent(inbuf) + reader->cur, |
| 823 | s, 0); |
| 824 | reader->cur += s; |
| 825 | if (val != 0) |
| 826 | reader->ctxt->wellFormed = 0; |
| 827 | break; |
| 828 | } |
no test coverage detected