Annotation of parser3/src/main/pa_xml_io.C, revision 1.1
1.1 ! paf 1: /** @file
! 2: Parser: plugins to xml library, controlling i/o; implementation
! 3:
! 4: Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)
! 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
! 6: */
! 7:
! 8: #include "pa_xml_io.h"
! 9:
! 10: #ifdef XML
! 11:
! 12: static const char * const IDENT="$Date: 2003/11/20 16:34:26 $";
! 13:
! 14: #include "libxslt/extensions.h"
! 15:
! 16: #include "pa_globals.h"
! 17: #include "pa_request.h"
! 18:
! 19:
! 20: /**
! 21: * xmlFileMatchWithLocalhostEqDocumentRoot:
! 22: * filename: the URI for matching
! 23: *
! 24: * check if the URI matches an HTTP one
! 25: *
! 26: * Returns 1 if matches, 0 otherwise
! 27: */
! 28: static int
! 29: xmlFileMatchLocalhost(const char* filename) {
! 30: if (!strncmp(filename, "http://localhost", 16))
! 31: return(1);
! 32: return(0);
! 33: }
! 34:
! 35:
! 36: /**
! 37: * xmlFileOpenHttpLocalhost :
! 38: * filename: the URI for matching
! 39: *
! 40: * http://localhost/abc -> $ENV{DOCUMENT_ROOT}/abc | ./abc
! 41: *
! 42: * input from FILE *, supports compressed input
! 43: * if filename is " " then the standard input is used
! 44: *
! 45: * Returns an I/O context or NULL in case of error
! 46: */
! 47: static void *
! 48: xmlFileOpenLocalhost (const char* filename) {
! 49: //_asm int 3;
! 50: FILE *fd;
! 51: const char* document_root=pa_thread_request().request_info.document_root;
! 52: if(!document_root)
! 53: document_root=".";
! 54:
! 55: char path[MAX_STRING];
! 56: path[0]=0;
! 57: strcat(path, document_root);
! 58: strcat(path, &filename[16]);
! 59:
! 60: #ifdef WIN32
! 61: fd = fopen(path, "rb");
! 62: #else
! 63: fd = fopen(path, "r");
! 64: #endif /* WIN32 */
! 65: return((void *) fd);
! 66: }
! 67:
! 68: /**
! 69: * xmlFileRead:
! 70: * @context: the I/O context
! 71: * @buffer: where to drop data
! 72: * @len: number of bytes to write
! 73: *
! 74: * Read @len bytes to @buffer from the I/O channel.
! 75: *
! 76: * Returns the number of bytes written
! 77: */
! 78: static int
! 79: pa_xmlFileRead (void * context, char * buffer, int len) {
! 80: return(fread(&buffer[0], 1, len, (FILE *) context));
! 81: }
! 82:
! 83: /**
! 84: * xmlFileClose:
! 85: * @context: the I/O context
! 86: *
! 87: * Close an I/O channel
! 88: */
! 89: static int
! 90: pa_xmlFileClose (void * context) {
! 91: return ( ( fclose((FILE *) context) == EOF ) ? -1 : 0 );
! 92: }
! 93:
! 94:
! 95: void pa_xml_io_init() {
! 96: // http://localhost/abc -> $ENV{DOCUMENT_ROOT}/abc | ./abc
! 97: xmlRegisterInputCallbacks(
! 98: xmlFileMatchLocalhost, xmlFileOpenLocalhost,
! 99: pa_xmlFileRead, pa_xmlFileClose);
! 100: }
! 101:
! 102: #endif
E-mail: