--- parser3/src/main/pa_globals.C 2002/01/23 09:47:02 1.105 +++ parser3/src/main/pa_globals.C 2002/02/08 08:30:16 1.113 @@ -1,10 +1,10 @@ /** @file Parser: globals. - Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://paf.design.ru) + Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexandr Petrosian (http://paf.design.ru) - $Id: pa_globals.C,v 1.105 2002/01/23 09:47:02 paf Exp $ + $Id: pa_globals.C,v 1.113 2002/02/08 08:30:16 paf Exp $ */ #include "pa_config_includes.h" @@ -85,12 +85,14 @@ String *hash_default_element_name; Hash *untaint_lang_name2enum; -GdomeDOMImplementation *domimpl; - Charset *utf8_charset; short hex_value[0x100]; +#ifdef XML +GdomeDOMImplementation *domimpl; +#endif + static void setup_hex_value() { memset(hex_value, 0, sizeof(hex_value)); hex_value['0'] = 0; @@ -193,6 +195,93 @@ const char *xmlGenericErrors() { // it is up to caller to free it return result; } + +/** + * xmlFileMatchWithLocalhostEqDocumentRoot: + * filename: the URI for matching + * + * check if the URI matches an HTTP one + * + * Returns 1 if matches, 0 otherwise + */ +static int +xmlFileMatchLocalhost(const char *filename) { + if (!strncmp(filename, "http://localhost", 16)) + return(1); + return(0); +} + + +/** + * xmlFileOpenHttpLocalhost : + * filename: the URI for matching + * + * http://localhost/abc -> $ENV{DOCUMENT_ROOT}/abc | ./abc + * + * input from FILE *, supports compressed input + * if filename is " " then the standard input is used + * + * Returns an I/O context or NULL in case of error + */ +static void * +xmlFileOpenLocalhost (const char *filename) { + FILE *fd; + const char* documentRoot; + char path[1000]; + + path[0]=0; + strcat(path, (documentRoot=getenv("DOCUMENT_ROOT"))?documentRoot:"."); + strcat(path, &filename[16]); + +#ifdef WIN32 + fd = fopen(path, "rb"); +#else + fd = fopen(path, "r"); +#endif /* WIN32 */ + return((void *) fd); +} + +/** + * xmlFileRead: + * @context: the I/O context + * @buffer: where to drop data + * @len: number of bytes to write + * + * Read @len bytes to @buffer from the I/O channel. + * + * Returns the number of bytes written + */ +static int +xmlFileRead (void * context, char * buffer, int len) { + return(fread(&buffer[0], 1, len, (FILE *) context)); +} + +/** + * xmlFileWrite: + * @context: the I/O context + * @buffer: where to drop data + * @len: number of bytes to write + * + * Write @len bytes from @buffer to the I/O channel. + * + * Returns the number of bytes written + */ +static int +xmlFileWrite (void * context, const char * buffer, int len) { + return(fwrite(&buffer[0], 1, len, (FILE *) context)); +} + +/** + * xmlFileClose: + * @context: the I/O context + * + * Close an I/O channel + */ +static int +xmlFileClose (void * context) { + return ( ( fclose((FILE *) context) == EOF ) ? -1 : 0 ); +} + #endif void pa_globals_destroy(void *) { @@ -211,7 +300,7 @@ void pa_globals_destroy(void *) { } } -/// @test // replace entities on load. WARNING: in sources there is a hint on one should call this for each thread xmlSubstituteEntitiesDefault(1); +/// @test hint on one should call this for each thread xmlSubstituteEntitiesDefault(1); void pa_globals_init(Pool& pool) { pool.register_cleanup(pa_globals_destroy, 0); @@ -332,6 +421,15 @@ void pa_globals_init(Pool& pool) { * use in multithreaded programs. */ xmlInitParser(); + + // 1. this is needed for proper parsing of stylesheets + // there were a situation where honest entity ruined innocent xpath compilation + // doc says "you sould turn it on on stylesheet load" without deepening into details + // 2. when dom tree with entites goes under transform text nodes + // got [erroreosly] cut on first entity occurance + // -- + // that is why this is: + xmlSubstituteEntitiesDefault(1); // Bit in the loadsubset context field to tell to do ID/REFs lookups xmlLoadExtDtdDefaultValue |= XML_DETECT_IDS; @@ -348,6 +446,11 @@ void pa_globals_init(Pool& pool) { // FILE *f=fopen("y:\\xslt.log", "wt"); // xsltSetGenericDebugFunc(f/*stderr*/, 0); + // http://localhost/abc -> $ENV{DOCUMENT_ROOT}/abc | ./abc + xmlRegisterInputCallbacks( + xmlFileMatchLocalhost, xmlFileOpenLocalhost, + xmlFileRead, xmlFileClose); + // XSLT stylesheet manager cache_managers->put(*NEW String(pool, "stylesheet"), stylesheet_manager=NEW Stylesheet_manager(pool)); @@ -359,7 +462,7 @@ void pa_globals_init(Pool& pool) { # pragma comment(lib, XML_LIBS "/glib/lib/libglib-1.3-11.lib") # pragma comment(lib, XML_LIBS "/libxml2-2.4.12/win32/dsp/libxml2_so/libxml2.lib") # pragma comment(lib, XML_LIBS "/libxslt-1.0.9/win32/dsp/libexslt_so/libexslt.lib") -# pragma comment(lib, XML_LIBS "/libxslt-1.0.9/win32/dsp/libxslt_a/libxslt.lib") +# pragma comment(lib, XML_LIBS "/libxslt-1.0.9/win32/dsp/libxslt_so/libxslt.lib") # ifdef _DEBUG # pragma comment(lib, XML_LIBS "/gdome2-0.7.0/win32/dsp/Debug/libgdome.lib") # else