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