|
|
| version 1.24.2.1, 2001/03/20 17:21:53 | version 1.98, 2001/12/28 14:52:40 |
|---|---|
| Line 2 | Line 2 |
| Parser: globals. | Parser: globals. |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru) | |
| Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) | |
| $Id$ | $Id$ |
| */ | */ |
| #include "pa_globals.h" | #include "pa_globals.h" |
| #include "_string.h" | #include "pa_string.h" |
| #include "_double.h" | #include "pa_hash.h" |
| #include "_int.h" | #include "pa_sql_driver_manager.h" |
| #include "_table.h" | #include "pa_dictionary.h" |
| #include "_form.h" | //#include "pa_stylesheet_manager.h" |
| #include "_response.h" | #include "pa_sapi.h" |
| #include "_file.h" | #include "pa_cache_managers.h" |
| #include "pa_charsets.h" | |
| Service_funcs service_funcs; | #include "pa_charset.h" |
| #ifdef DB2 | |
| #include "pa_db_manager.h" | |
| #endif | |
| #ifdef XML | |
| //#include "libxml/parser.h" | |
| //#include "libxslt/xslt.h" | |
| //#include "libxslt/libxslt.h" | |
| #include "libxslt/extensions.h" | |
| #include "libexslt/exslt.h" | |
| #endif | |
| String *content_type_name; | String *content_type_name; |
| String *charset_name; | |
| String *body_name; | String *body_name; |
| String *value_name; | String *value_name; |
| String *expires_name; | String *expires_name; |
| Line 29 String *size_name; | Line 41 String *size_name; |
| String *text_name; | String *text_name; |
| String *exception_method_name; | String *exception_method_name; |
| String *post_process_method_name; | |
| String *content_disposition_name; | |
| String *content_disposition_filename_name; | |
| String *unnamed_name; | String *unnamed_name; |
| String *empty_string; | |
| String *auto_method_name; | String *auto_method_name; |
| String *main_method_name; | String *main_method_name; |
| String *root_class_name; | |
| String *main_class_name; | String *main_class_name; |
| String *env_class_name; | |
| String *table_class_name; | |
| String *form_class_name; | |
| String *request_class_name; | |
| String *response_class_name; | |
| String *cookie_class_name; | |
| String *result_var_name; | String *result_var_name; |
| String *match_var_name; | |
| String *string_pre_match_name; | |
| String *string_match_name; | |
| String *string_post_match_name; | |
| String *charsets_name; | |
| String *mime_types_name; | |
| String *vfile_mime_type_name; | |
| String *origins_mode_name; | |
| String *class_path_name; | |
| String *switch_data_name; | |
| String *case_default_value; | |
| String *sql_limit_name; | |
| String *sql_offset_name; | |
| String *sql_default_name; | |
| String *limits_name; | String *charset_UTF8_name; |
| String *post_max_size_name; | |
| String *defaults_name; | String *hash_default_element_name; |
| Hash *untaint_lang_name2enum; | Hash *untaint_lang_name2enum; |
| GdomeDOMImplementation *domimpl; | |
| Charset *utf8_charset; | |
| short hex_value[0x100]; | short hex_value[0x100]; |
| static void setup_hex_value() { | static void setup_hex_value() { |
| int i; | memset(hex_value, 0, sizeof(hex_value)); |
| for (i=0; (i < 0x100); i++) { | |
| hex_value[i] = 0; | |
| } | |
| hex_value['0'] = 0; | hex_value['0'] = 0; |
| hex_value['1'] = 1; | hex_value['1'] = 1; |
| hex_value['2'] = 2; | hex_value['2'] = 2; |
| Line 85 static void setup_hex_value() { | Line 111 static void setup_hex_value() { |
| hex_value['f'] = 15; | hex_value['f'] = 15; |
| } | } |
| void globals_init(Pool& pool) { | void pa_globals_destroy(void *) { |
| try { | |
| #ifdef XML | |
| GdomeException exc; | |
| gdome_di_unref (domimpl, &exc); | |
| #endif | |
| if(cache_managers) | |
| cache_managers->~Cache_managers(); | |
| charsets->~Charsets(); | |
| } catch(const Exception& e) { | |
| SAPI::die("pa_globals_destroy failed: %s", e.comment()); | |
| } | |
| } | |
| void pa_globals_init(Pool& pool) { | |
| pool.register_cleanup(pa_globals_destroy, 0); | |
| #undef NEW | |
| #define NEW new(pool) | |
| // hex value | // hex value |
| setup_hex_value(); | setup_hex_value(); |
| // names | // names |
| content_type_name=new(pool) String(pool, CONTENT_TYPE_NAME); | content_type_name=NEW String(pool, CONTENT_TYPE_NAME); |
| body_name=new(pool) String(pool, BODY_NAME); | charset_name=NEW String(pool, CHARSET_NAME); |
| value_name=new(pool) String(pool, VALUE_NAME); | body_name=NEW String(pool, BODY_NAME); |
| expires_name=new(pool) String(pool, EXPIRES_NAME); | value_name=NEW String(pool, VALUE_NAME); |
| path_name=new(pool) String(pool, PATH_NAME); | expires_name=NEW String(pool, EXPIRES_NAME); |
| name_name=new(pool) String(pool, NAME_NAME); | path_name=NEW String(pool, PATH_NAME); |
| size_name=new(pool) String(pool, SIZE_NAME); | name_name=NEW String(pool, NAME_NAME); |
| text_name=new(pool) String(pool, TEXT_NAME); | size_name=NEW String(pool, SIZE_NAME); |
| text_name=NEW String(pool, TEXT_NAME); | |
| exception_method_name=new(pool) String(pool, EXCEPTION_METHOD_NAME); | |
| unnamed_name=new(pool) String(pool, UNNAMED_NAME); | |
| empty_string=new(pool) String(pool); | |
| auto_method_name=new(pool) String(pool, AUTO_METHOD_NAME); | |
| main_method_name=new(pool) String(pool, MAIN_METHOD_NAME); | |
| root_class_name=new(pool) String(pool, ROOT_CLASS_NAME); | |
| main_class_name=new(pool) String(pool, MAIN_CLASS_NAME); | |
| table_class_name=new(pool) String(pool, TABLE_CLASS_NAME); | |
| env_class_name=new(pool) String(pool, ENV_CLASS_NAME); | |
| form_class_name=new(pool) String(pool, FORM_CLASS_NAME); | |
| request_class_name=new(pool) String(pool, REQUEST_CLASS_NAME); | |
| response_class_name=new(pool) String(pool, RESPONSE_CLASS_NAME); | |
| cookie_class_name=new(pool) String(pool, COOKIE_CLASS_NAME); | |
| result_var_name=new(pool) String(pool, RESULT_VAR_NAME); | exception_method_name=NEW String(pool, EXCEPTION_METHOD_NAME); |
| post_process_method_name=NEW String(pool, POST_PROCESS_METHOD_NAME); | |
| content_disposition_name=NEW String(pool, CONTENT_DISPOSITION_NAME); | |
| content_disposition_filename_name=NEW String(pool, CONTENT_DISPOSITION_FILENAME_NAME); | |
| limits_name=new(pool) String(pool, LIMITS_NAME); | unnamed_name=NEW String(pool, UNNAMED_NAME); |
| post_max_size_name=new(pool) String(pool, POST_MAX_SIZE_NAME); | |
| defaults_name=new(pool) String(pool, DEFAULTS_NAME); | auto_method_name=NEW String(pool, AUTO_METHOD_NAME); |
| main_method_name=NEW String(pool, MAIN_METHOD_NAME); | |
| // hashes | main_class_name=NEW String(pool, MAIN_CLASS_NAME); |
| untaint_lang_name2enum=new(pool) Hash(pool); | |
| String as_is(pool, "as-is"); | result_var_name=NEW String(pool, RESULT_VAR_NAME); |
| untaint_lang_name2enum->put(as_is, (int)String::UL_AS_IS); | match_var_name=NEW String(pool, MATCH_VAR_NAME); |
| String file_name(pool, "file-name"); | string_pre_match_name=NEW String(pool, STRING_PRE_MATCH_NAME); |
| untaint_lang_name2enum->put(file_name, (int)String::UL_FILE_NAME); | string_match_name=NEW String(pool, STRING_MATCH_NAME); |
| String header(pool, "header"); | string_post_match_name=NEW String(pool, STRING_POST_MATCH_NAME); |
| untaint_lang_name2enum->put(header, (int)String::UL_HEADER); | |
| String uri(pool, "uri"); | |
| untaint_lang_name2enum->put(uri, (int)String::UL_URI); | charsets_name=NEW String(pool, CHARSETS_NAME); |
| String table(pool, "table"); | mime_types_name=NEW String(pool, MIME_TYPES_NAME); |
| untaint_lang_name2enum->put(table, (int)String::UL_TABLE); | vfile_mime_type_name=NEW String(pool, VFILE_MIME_TYPE_NAME); |
| String sql(pool, "sql"); | origins_mode_name=NEW String(pool, ORIGINS_MODE_NAME); |
| untaint_lang_name2enum->put(sql, (int)String::UL_SQL); | |
| String js(pool, "js"); | class_path_name=NEW String(pool, CLASS_PATH_NAME); |
| untaint_lang_name2enum->put(js, (int)String::UL_JS); | |
| String html(pool, "html"); | |
| untaint_lang_name2enum->put(html, (int)String::UL_HTML); | |
| String html_typo(pool, "html-typo"); | |
| untaint_lang_name2enum->put(html_typo, (int)String::UL_HTML_TYPO); | |
| // read-only stateless classes | |
| initialize_string_class(pool, *(string_class=new(pool) VStateless_class(pool))); string_class->freeze(); | |
| initialize_double_class(pool, *(double_class=new(pool) VStateless_class(pool))); double_class->freeze(); | |
| initialize_int_class(pool, *(int_class=new(pool) VStateless_class(pool))); int_class->freeze(); | |
| initialize_table_class(pool, *(table_class=new(pool) VStateless_class(pool))); table_class->freeze(); | |
| initialize_file_class(pool, *(file_class=new(pool) VStateless_class(pool))); file_class->freeze(); | |
| initialize_response_class(pool, *(response_class=new(pool) VStateless_class(pool))); response_class->freeze(); | |
| // read-only stateless base classes | //^switch ^case |
| initialize_form_base_class(pool, *(form_base_class=new(pool) VStateless_class(pool))); form_base_class->set_name(*form_class_name); form_base_class->freeze(); | switch_data_name=NEW String(pool, SWITCH_DATA_NAME); |
| case_default_value=NEW String(pool, CASE_DEFAULT_VALUE); | |
| // sql | |
| sql_limit_name=NEW String(pool, SQL_LIMIT_NAME); | |
| sql_offset_name=NEW String(pool, SQL_OFFSET_NAME); | |
| sql_default_name=NEW String(pool, SQL_DEFAULT_NAME); | |
| // charsets | |
| charset_UTF8_name=NEW String(pool, CHARSET_UTF8_NAME); | |
| // hash | |
| hash_default_element_name=NEW String(pool, HASH_DEFAULT_ELEMENT_NAME); | |
| // hashes | |
| untaint_lang_name2enum=NEW Hash(pool); | |
| #define ULN(cstr, LANG) \ | |
| untaint_lang_name2enum->put(*NEW String(pool, cstr), (int)String::UL_##LANG); | |
| ULN("as-is", AS_IS); | |
| ULN("file-spec", FILE_SPEC); | |
| ULN("http-header", HTTP_HEADER); | |
| ULN("mail-header", MAIL_HEADER); | |
| ULN("uri", URI); | |
| ULN("table", TABLE); | |
| ULN("sql", SQL); | |
| ULN("js", JS); | |
| ULN("xml", XML); | |
| ULN("html", HTML); | |
| ULN("optimized-html", HTML|String::UL_OPTIMIZE_BIT); | |
| // charsets | |
| charsets=NEW Charsets(pool); | |
| charsets->put(*charset_UTF8_name, | |
| utf8_charset=NEW Charset(pool, *charset_UTF8_name, 0/*no file=system*/)); | |
| // Status registration, must be initialized before all registrants | |
| cache_managers=NEW Cache_managers(pool); | |
| // SQL driver manager | |
| cache_managers->put(*NEW String(pool, "sql"), | |
| SQL_driver_manager=NEW SQL_Driver_manager(pool)); | |
| #ifdef DB2 | |
| // DB driver manager | |
| cache_managers->put(*NEW String(pool, "db"), | |
| DB_manager=NEW DB_Manager(pool)); | |
| #endif | |
| #ifdef XML | |
| // initializing xml libs | |
| /* First I get a DOMImplementation reference */ | |
| domimpl = gdome_di_mkref (); | |
| /* | |
| * Register the EXSLT extensions and the test module | |
| */ | |
| exsltRegisterAll(); | |
| xsltRegisterTestModule(); | |
| xmlDefaultSAXHandlerInit(); | |
| /* | |
| * disable CDATA from being built in the document tree | |
| */ | |
| xmlDefaultSAXHandler.cdataBlock = NULL; | |
| /* | |
| // XSLT stylesheet manager | |
| cache_managers->put(*NEW String(pool, "stylesheet"), | |
| stylesheet_manager=NEW Stylesheet_manager(pool)); | |
| */ | |
| #endif | |
| } | } |
| #if defined(XML) && defined(_MSC_VER) | |
| # define XML_LIBS "/parser3project/win32xml" | |
| # 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") | |
| # ifdef _DEBUG | |
| # pragma comment(lib, XML_LIBS "/gdome2-0.7.0/win32/dsp/Debug/libgdome.lib") | |
| # else | |
| # pragma comment(lib, XML_LIBS "/gdome2-0.7.0/win32/dsp/Release/libgdome.lib") | |
| # endif | |
| #endif | |
| #if defined(DB2) && defined(_MSC_VER) | |
| # define LIBDB2_WIN32_BUILD "/parser3project/win32db/lib" | |
| # ifdef _DEBUG | |
| # pragma comment(lib, LIBDB2_WIN32_BUILD "/debug/libdb.lib") | |
| # else | |
| # pragma comment(lib, LIBDB2_WIN32_BUILD "/release/libdb.lib") | |
| # endif | |
| #endif |