--- parser3/src/classes/op.C 2011/05/15 12:56:10 1.207 +++ parser3/src/classes/op.C 2013/08/21 12:11:13 1.215 @@ -1,12 +1,10 @@ /** @file Parser: parser @b operators. - Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_OP_C="$Date: 2011/05/15 12:56:10 $"; - #include "classes.h" #include "pa_vmethod_frame.h" @@ -20,6 +18,8 @@ static const char * const IDENT_OP_C="$D #include "pa_vclass.h" #include "pa_charset.h" +volatile const char * IDENT_OP_C="$Id: op.C,v 1.215 2013/08/21 12:11:13 moko Exp $"; + // limits #define MAX_LOOPS 20000 @@ -104,13 +104,10 @@ static void _if(Request& r, MethodParams r.process_write(*params.get(i)); } -static String::Language get_untaint_lang(MethodParams& params, int index){ - const String& lang_name=params.as_string(index, "lang must be string"); +String::Language get_untaint_lang(const String& lang_name){ String::Language lang=untaint_lang_name2enum.get(lang_name); if(!lang) - throw Exception(PARSER_RUNTIME, - &lang_name, - "invalid taint language"); + throw Exception(PARSER_RUNTIME, &lang_name, "invalid taint language"); return lang; } @@ -119,7 +116,7 @@ static void _untaint(Request& r, MethodP if(params.count()==1) lang=String::L_AS_IS; // mark as simply 'as-is'. useful in html from sql else - lang=get_untaint_lang(params, 0); + lang=get_untaint_lang(params.as_string(0, "lang must be string")); { Value& vbody=params.as_junction(params.count()-1, "body must be code"); @@ -135,7 +132,7 @@ static void _taint(Request& r, MethodPar if(params.count()==1) lang=String::L_TAINTED; // mark as simply 'tainted'. useful in table:create else - lang=get_untaint_lang(params, 0); + lang=get_untaint_lang(params.as_string(0, "lang must be string")); { Value& vbody=params.as_no_junction(params.count()-1, "body must not be code"); @@ -146,9 +143,9 @@ static void _taint(Request& r, MethodPar } static void _apply_taint(Request& r, MethodParams& params) { - String::Language lang=params.count()==1 ? String::L_AS_IS : get_untaint_lang(params, 0); + String::Language lang=params.count()==1 ? String::L_AS_IS : get_untaint_lang(params.as_string(0, "lang must be string")); const String &sbody=params.as_string(params.count()-1, "body must be string"); - String::Body result_body=sbody.cstr_to_string_body_untaint(lang, 0, &r.charsets); + String::Body result_body=sbody.cstr_to_string_body_untaint(lang, r.connection(false), &r.charsets); r.write_pass_lang(*new String(result_body, String::L_AS_IS)); } @@ -178,36 +175,30 @@ static void _process(Request& r, MethodP // temporary zero @auto so it wouldn't be auto-called in Request::use_buf Temp_method temp_method_auto(*target_class, auto_method_name, 0); - size_t options_index=index+1; - HashStringValue* options=0; - if(options_indexget(PROCESS_MAIN_OPTION_NAME)) { - valid_options++; - main_alias=&vmain_alias->as_string(); - } - if(Value* vfile_alias=options->get(PROCESS_FILE_OPTION_NAME)) { - valid_options++; - file_alias=&vfile_alias->as_string(); - } - if(Value* vline_no_alias_offset=options->get(PROCESS_LINENO_OPTION_NAME)) { - valid_options++; - line_no_alias_offset=vline_no_alias_offset->as_int(); + + size_t options_index=index+1; + if(options_indexget(PROCESS_MAIN_OPTION_NAME)) { + valid_options++; + main_alias=&vmain_alias->as_string(); + } + if(Value* vfile_alias=options->get(PROCESS_FILE_OPTION_NAME)) { + valid_options++; + file_alias=&vfile_alias->as_string(); + } + if(Value* vline_no_alias_offset=options->get(PROCESS_LINENO_OPTION_NAME)) { + valid_options++; + line_no_alias_offset=vline_no_alias_offset->as_int(); + } + + if(valid_options!=options->count()) + throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); } - - if(valid_options!=options->count()) - throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); - } uint processe_file_no=file_alias? r.register_file(r.absolute(*file_alias)) @@ -303,7 +294,7 @@ static void _use(Request& r, MethodParam static void set_skip(Request& r, Request::Skip askip) { if(!r.get_in_cycle()) - throw Exception(PARSER_RUNTIME, + throw Exception(askip==Request::SKIP_BREAK?"parser.break":"parser.continue", 0, "without cycle"); @@ -387,9 +378,6 @@ static void _eval(Request& r, MethodPara } static void _connect(Request& r, MethodParams& params) { -#ifdef RESOURCES_DEBUG -struct timeval mt[2]; -#endif Value& url=params.as_no_junction(0, "url must not be code"); Value& body_code=params.as_junction(1, "body must be code"); @@ -400,27 +388,14 @@ struct timeval mt[2]; } } -#ifdef RESOURCES_DEBUG -//measure:before -gettimeofday(&mt[0],NULL); -#endif // connect SQL_Connection* connection=SQL_driver_manager->get_connection(url.as_string(), protocol2driver_and_client, r.charsets.source().NAME().cstr(), r.request_info.document_root); -#ifdef RESOURCES_DEBUG -//measure:after connect -gettimeofday(&mt[1],NULL); - -double t[2]; -for(int i=0;i<2;i++) - t[i]=mt[i].tv_sec+mt[i].tv_usec/1000000.0; - -r.sql_connect_time+=t[1]-t[0]; -#endif Temp_connection temp_connection(r, connection); + // execute body try { r.process_write(body_code); @@ -460,8 +435,7 @@ public: #endif static void _switch(Request& r, MethodParams& params) { Switch_data* data=new Switch_data(r, r.process_to_value(params[0])); - Temp_hash_value - switch_data_setter(r.classes_conf, switch_data_name, data); + Temp_hash_value, void*> switch_data_setter(&r.classes_conf, switch_data_name, data); Value& cases_code=params.as_junction(1, "switch cases must be code"); // execution of found ^case[...]{code} must be in context of ^switch[...]{code} @@ -772,8 +746,7 @@ static void _cache(Request& r, MethodPar Cache_scope scope={as_expires(r, params, 1, now), 0}; - Temp_hash_value - cache_scope_setter(r.classes_conf, cache_data_name, &scope); + Temp_hash_value, void*> cache_scope_setter(&r.classes_conf, cache_data_name, &scope); Value& body_code=params.as_junction(2, "body_code must be code"); Value* catch_code=0; if(params.count()>3)