Annotation of parser3/src/main/pa_globals.C, revision 1.102
1.15 paf 1: /** @file
1.16 paf 2: Parser: globals.
3:
1.1 paf 4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.89 paf 5: Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru)
1.16 paf 6:
1.102 ! paf 7: $Id: pa_globals.C,v 1.101 2002/01/21 12:10:08 paf Exp $
1.1 paf 8: */
9:
1.102 ! paf 10: #include "pa_config_includes.h"
! 11:
! 12: #ifdef XML
! 13: //#include "libxml/parser.h"
! 14: //#include "libxslt/xslt.h"
! 15: //#include "libxslt/libxslt.h"
! 16: #include "libxslt/extensions.h"
! 17: #include "libxslt/xsltutils.h"
! 18: #include "libexslt/exslt.h"
! 19: #endif
! 20:
1.1 paf 21: #include "pa_globals.h"
1.32 paf 22: #include "pa_string.h"
23: #include "pa_hash.h"
1.42 paf 24: #include "pa_sql_driver_manager.h"
1.77 parser 25: #include "pa_dictionary.h"
1.100 paf 26: #include "pa_stylesheet_manager.h"
1.83 parser 27: #include "pa_sapi.h"
1.90 paf 28: #include "pa_cache_managers.h"
1.95 paf 29: #include "pa_charsets.h"
30: #include "pa_charset.h"
1.101 paf 31: #include "pa_threads.h"
1.84 parser 32:
1.86 paf 33: #ifdef DB2
1.83 parser 34: #include "pa_db_manager.h"
1.84 parser 35: #endif
1.1 paf 36:
1.8 paf 37: String *content_type_name;
1.75 parser 38: String *charset_name;
1.8 paf 39: String *body_name;
1.13 paf 40: String *value_name;
1.14 paf 41: String *expires_name;
42: String *path_name;
1.17 paf 43: String *name_name;
44: String *size_name;
45: String *text_name;
1.8 paf 46:
1.1 paf 47: String *exception_method_name;
1.38 paf 48: String *post_process_method_name;
1.1 paf 49:
1.39 paf 50: String *content_disposition_name;
51: String *content_disposition_filename_name;
52:
1.1 paf 53: String *unnamed_name;
54:
55: String *auto_method_name;
56: String *main_method_name;
57:
58: String *main_class_name;
59:
1.6 paf 60: String *result_var_name;
1.64 parser 61: String *match_var_name;
1.41 paf 62: String *string_pre_match_name;
1.40 paf 63: String *string_match_name;
1.41 paf 64: String *string_post_match_name;
1.6 paf 65:
1.79 parser 66: String *charsets_name;
1.36 paf 67: String *mime_types_name;
68: String *vfile_mime_type_name;
1.63 parser 69: String *origins_mode_name;
1.67 parser 70:
1.69 parser 71: String *class_path_name;
72:
1.67 parser 73: String *switch_data_name;
74: String *case_default_value;
75:
1.70 parser 76: String *sql_limit_name;
77: String *sql_offset_name;
78: String *sql_default_name;
79:
1.95 paf 80: String *charset_UTF8_name;
81:
1.71 parser 82: String *hash_default_element_name;
1.42 paf 83:
1.1 paf 84: Hash *untaint_lang_name2enum;
85:
1.97 paf 86: GdomeDOMImplementation *domimpl;
87:
1.95 paf 88: Charset *utf8_charset;
1.32 paf 89:
1.5 paf 90: short hex_value[0x100];
91:
92: static void setup_hex_value() {
1.68 parser 93: memset(hex_value, 0, sizeof(hex_value));
1.5 paf 94: hex_value['0'] = 0;
95: hex_value['1'] = 1;
96: hex_value['2'] = 2;
97: hex_value['3'] = 3;
98: hex_value['4'] = 4;
99: hex_value['5'] = 5;
100: hex_value['6'] = 6;
101: hex_value['7'] = 7;
102: hex_value['8'] = 8;
103: hex_value['9'] = 9;
104: hex_value['A'] = 10;
105: hex_value['B'] = 11;
106: hex_value['C'] = 12;
107: hex_value['D'] = 13;
108: hex_value['E'] = 14;
109: hex_value['F'] = 15;
110: hex_value['a'] = 10;
111: hex_value['b'] = 11;
112: hex_value['c'] = 12;
113: hex_value['d'] = 13;
114: hex_value['e'] = 14;
115: hex_value['f'] = 15;
116: }
1.1 paf 117:
1.99 paf 118: #ifdef XML
1.101 paf 119:
120: const int MAX_CONCURRENT_XML_GENERIC_ERROR_THREADS=10;
121:
122: struct XML_Generic_error_info {
123: pa_thread_t thread_id;
124: char *message;
125: } xml_generic_error_infos[MAX_CONCURRENT_XML_GENERIC_ERROR_THREADS];
126:
127: XML_Generic_error_info *xml_generic_error_info(pa_thread_t thread_id) {
128: for(int i=0; i<MAX_CONCURRENT_XML_GENERIC_ERROR_THREADS; i++) {
129: XML_Generic_error_info *p=xml_generic_error_infos+i;
130: if(p->thread_id==thread_id)
131: return p;
132: }
133: return 0;
134: }
135:
1.99 paf 136: static void
1.101 paf 137: xmlParserGenericErrorFunc(void *ctx, const char *msg, ...) {
138: pa_thread_t thread_id=pa_get_thread_id();
139:
140: // infinitely looking for free slot to fill it
141: while(true) {
142: SYNCHRONIZED; // find+fill blocked
143:
144: // first try to get existing for this thread_id
145: XML_Generic_error_info *p=xml_generic_error_info(thread_id);
146: if(!p) { // occupy empty one
147: p=xml_generic_error_info(0);
148: if(!p) // wait for empty for it to appear
149: continue;
150: }
151:
1.102 ! paf 152: p->thread_id=thread_id;
1.101 paf 153: size_t offset=p->message?strlen(p->message):0;
154: p->message=(char *)realloc(p->message, offset+MAX_STRING);
155: if(!p->message)
156: SAPI::die(
157: "out of memory in 'xmlParserGenericErrorFunc', failed to reallocate to %u bytes",
158: offset+MAX_STRING);
159:
160: va_list args;
161: va_start(args, msg);
162: vsnprintf(p->message+offset, MAX_STRING, msg, args);
163: va_end(args);
164:
165: break;
166: }
167: }
168:
1.102 ! paf 169: bool xmlHaveGenericErrors() {
! 170: pa_thread_t thread_id=pa_get_thread_id();
! 171:
! 172: SYNCHRONIZED; // find blocked
! 173:
! 174: return xml_generic_error_info(thread_id)!=0;
! 175: }
! 176:
1.101 paf 177: const char *xmlGenericErrors() {
178: pa_thread_t thread_id=pa_get_thread_id();
179:
180: SYNCHRONIZED; // find+free blocked
181:
182: XML_Generic_error_info *p=xml_generic_error_info(thread_id);
183: if(!p) // no errors for our thread_id registered
184: return 0;
185:
186: const char *result=p->message;
187:
188: // free slot up
189: memset(p, 0, sizeof(*p));
190:
191: // it is up to caller to free it
192: return result;
1.99 paf 193: }
194: #endif
195:
1.83 parser 196: void pa_globals_destroy(void *) {
197: try {
1.96 paf 198: #ifdef XML
199: GdomeException exc;
200: gdome_di_unref (domimpl, &exc);
201: #endif
1.93 paf 202: if(cache_managers)
203: cache_managers->~Cache_managers();
1.95 paf 204:
205: charsets->~Charsets();
1.83 parser 206:
207: } catch(const Exception& e) {
208: SAPI::die("pa_globals_destroy failed: %s", e.comment());
209: }
210: }
211:
1.27 paf 212: void pa_globals_init(Pool& pool) {
1.83 parser 213: pool.register_cleanup(pa_globals_destroy, 0);
214:
1.32 paf 215: #undef NEW
216: #define NEW new(pool)
217:
1.5 paf 218: // hex value
219: setup_hex_value();
220:
1.1 paf 221: // names
1.32 paf 222: content_type_name=NEW String(pool, CONTENT_TYPE_NAME);
1.75 parser 223: charset_name=NEW String(pool, CHARSET_NAME);
1.32 paf 224: body_name=NEW String(pool, BODY_NAME);
225: value_name=NEW String(pool, VALUE_NAME);
226: expires_name=NEW String(pool, EXPIRES_NAME);
227: path_name=NEW String(pool, PATH_NAME);
228: name_name=NEW String(pool, NAME_NAME);
229: size_name=NEW String(pool, SIZE_NAME);
230: text_name=NEW String(pool, TEXT_NAME);
231:
232: exception_method_name=NEW String(pool, EXCEPTION_METHOD_NAME);
1.38 paf 233: post_process_method_name=NEW String(pool, POST_PROCESS_METHOD_NAME);
1.39 paf 234:
235: content_disposition_name=NEW String(pool, CONTENT_DISPOSITION_NAME);
236: content_disposition_filename_name=NEW String(pool, CONTENT_DISPOSITION_FILENAME_NAME);
1.32 paf 237:
238: unnamed_name=NEW String(pool, UNNAMED_NAME);
239:
240: auto_method_name=NEW String(pool, AUTO_METHOD_NAME);
241: main_method_name=NEW String(pool, MAIN_METHOD_NAME);
242:
243: main_class_name=NEW String(pool, MAIN_CLASS_NAME);
1.6 paf 244:
1.32 paf 245: result_var_name=NEW String(pool, RESULT_VAR_NAME);
1.64 parser 246: match_var_name=NEW String(pool, MATCH_VAR_NAME);
1.41 paf 247: string_pre_match_name=NEW String(pool, STRING_PRE_MATCH_NAME);
1.40 paf 248: string_match_name=NEW String(pool, STRING_MATCH_NAME);
1.41 paf 249: string_post_match_name=NEW String(pool, STRING_POST_MATCH_NAME);
1.6 paf 250:
1.4 paf 251:
1.79 parser 252: charsets_name=NEW String(pool, CHARSETS_NAME);
1.36 paf 253: mime_types_name=NEW String(pool, MIME_TYPES_NAME);
254: vfile_mime_type_name=NEW String(pool, VFILE_MIME_TYPE_NAME);
1.63 parser 255: origins_mode_name=NEW String(pool, ORIGINS_MODE_NAME);
1.69 parser 256:
257: class_path_name=NEW String(pool, CLASS_PATH_NAME);
1.66 parser 258:
259: //^switch ^case
260: switch_data_name=NEW String(pool, SWITCH_DATA_NAME);
261: case_default_value=NEW String(pool, CASE_DEFAULT_VALUE);
1.70 parser 262:
263: // sql
264: sql_limit_name=NEW String(pool, SQL_LIMIT_NAME);
265: sql_offset_name=NEW String(pool, SQL_OFFSET_NAME);
266: sql_default_name=NEW String(pool, SQL_DEFAULT_NAME);
1.71 parser 267:
1.95 paf 268: // charsets
269: charset_UTF8_name=NEW String(pool, CHARSET_UTF8_NAME);
270:
1.71 parser 271: // hash
272: hash_default_element_name=NEW String(pool, HASH_DEFAULT_ELEMENT_NAME);
1.70 parser 273:
1.66 parser 274:
1.1 paf 275: // hashes
1.32 paf 276: untaint_lang_name2enum=NEW Hash(pool);
1.87 paf 277: #define ULN(cstr, LANG) \
278: untaint_lang_name2enum->put(*NEW String(pool, cstr), (int)String::UL_##LANG);
279: ULN("as-is", AS_IS);
280: ULN("file-spec", FILE_SPEC);
281: ULN("http-header", HTTP_HEADER);
282: ULN("mail-header", MAIL_HEADER);
283: ULN("uri", URI);
284: ULN("table", TABLE);
285: ULN("sql", SQL);
286: ULN("js", JS);
287: ULN("xml", XML);
288: ULN("html", HTML);
1.92 paf 289: ULN("optimized-html", HTML|String::UL_OPTIMIZE_BIT);
1.1 paf 290:
1.95 paf 291: // charsets
292: charsets=NEW Charsets(pool);
293: charsets->put(*charset_UTF8_name,
294: utf8_charset=NEW Charset(pool, *charset_UTF8_name, 0/*no file=system*/));
1.88 paf 295:
1.101 paf 296:
1.88 paf 297: // Status registration, must be initialized before all registrants
1.90 paf 298: cache_managers=NEW Cache_managers(pool);
1.42 paf 299:
1.73 parser 300: // SQL driver manager
1.90 paf 301: cache_managers->put(*NEW String(pool, "sql"),
302: SQL_driver_manager=NEW SQL_Driver_manager(pool));
1.74 parser 303:
1.86 paf 304: #ifdef DB2
1.83 parser 305: // DB driver manager
1.90 paf 306: cache_managers->put(*NEW String(pool, "db"),
307: DB_manager=NEW DB_Manager(pool));
1.83 parser 308: #endif
309:
1.76 parser 310: #ifdef XML
1.96 paf 311: // initializing xml libs
312:
313: /* First I get a DOMImplementation reference */
314: domimpl = gdome_di_mkref ();
315: /*
316: * Register the EXSLT extensions and the test module
317: */
318: exsltRegisterAll();
319: xsltRegisterTestModule();
320: xmlDefaultSAXHandlerInit();
321: /*
322: * disable CDATA from being built in the document tree
323: */
1.101 paf 324: // never added yet xmlDefaultSAXHandler.cdataBlock = NULL;
1.99 paf 325:
326: /*
327: * Initialization function for the XML parser.
328: * This is not reentrant. Call once before processing in case of
329: * use in multithreaded programs.
330: */
331: xmlInitParser();
1.100 paf 332:
333: // Bit in the loadsubset context field to tell to do ID/REFs lookups
334: xmlLoadExtDtdDefaultValue |= XML_DETECT_IDS;
335: // Bit in the loadsubset context field to tell to do complete the elements attributes lists
336: // with the ones defaulted from the DTDs
337: //never added yet xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS;
1.99 paf 338:
1.101 paf 339: memset(xml_generic_error_infos, 0, sizeof(xml_generic_error_infos));
340: xmlSetGenericErrorFunc(0, xmlParserGenericErrorFunc);
1.102 ! paf 341: xsltSetGenericErrorFunc(0, xmlParserGenericErrorFunc);
1.96 paf 342:
343: // XSLT stylesheet manager
1.90 paf 344: cache_managers->put(*NEW String(pool, "stylesheet"),
345: stylesheet_manager=NEW Stylesheet_manager(pool));
1.76 parser 346: #endif
1.1 paf 347: }
1.76 parser 348:
349: #if defined(XML) && defined(_MSC_VER)
1.96 paf 350: # define XML_LIBS "/parser3project/win32xml"
351: # pragma comment(lib, XML_LIBS "/glib/lib/libglib-1.3-11.lib")
352: # pragma comment(lib, XML_LIBS "/libxml2-2.4.12/win32/dsp/libxml2_so/libxml2.lib")
353: # pragma comment(lib, XML_LIBS "/libxslt-1.0.9/win32/dsp/libexslt_so/libexslt.lib")
354: # pragma comment(lib, XML_LIBS "/libxslt-1.0.9/win32/dsp/libxslt_a/libxslt.lib")
1.76 parser 355: # ifdef _DEBUG
1.98 paf 356: # pragma comment(lib, XML_LIBS "/gdome2-0.7.0/win32/dsp/Debug/libgdome.lib")
1.76 parser 357: # else
1.98 paf 358: # pragma comment(lib, XML_LIBS "/gdome2-0.7.0/win32/dsp/Release/libgdome.lib")
1.76 parser 359: # endif
360: #endif
1.85 paf 361:
362:
1.86 paf 363: #if defined(DB2) && defined(_MSC_VER)
364: # define LIBDB2_WIN32_BUILD "/parser3project/win32db/lib"
1.85 paf 365: # ifdef _DEBUG
1.86 paf 366: # pragma comment(lib, LIBDB2_WIN32_BUILD "/debug/libdb.lib")
1.85 paf 367: # else
1.86 paf 368: # pragma comment(lib, LIBDB2_WIN32_BUILD "/release/libdb.lib")
1.85 paf 369: # endif
370: #endif
E-mail: