--- parser3/src/classes/op.C 2010/07/05 05:54:46 1.201 +++ parser3/src/classes/op.C 2011/05/15 12:56:10 1.207 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_OP_C="$Date: 2010/07/05 05:54:46 $"; +static const char * const IDENT_OP_C="$Date: 2011/05/15 12:56:10 $"; #include "classes.h" #include "pa_vmethod_frame.h" @@ -81,6 +81,7 @@ public: ULN("optimized-html", HTML|String::L_OPTIMIZE_BIT); ULN("regex", REGEX); ULN("parser-code", PARSER_CODE); + ULN("json", JSON); #undef ULN } } untaint_lang_name2enum; @@ -144,6 +145,13 @@ 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); + 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); + r.write_pass_lang(*new String(result_body, String::L_AS_IS)); +} + static void _process(Request& r, MethodParams& params) { Method* main_method; @@ -220,10 +228,10 @@ static void _process(Request& r, MethodP // after restoring current-request-lang // maybe-execute @main[] if(main_method) { - // temporarily set method_frame's self to target_self - Temp_method_frame_self tmfs(*r.get_method_frame(), *target_self); - // execute! - r.execute(*main_method->parser_code); + VMethodFrame frame(*main_method, r.get_method_frame()->caller(), *target_self); + frame.empty_params(); + r.op_call(frame); + r.write_pass_lang(frame.result()); } } @@ -290,7 +298,7 @@ static void _use(Request& r, MethodParam Value& vfile=params.as_no_junction(0, FILE_NAME_MUST_NOT_BE_CODE); // _use could be called from the parser3 method only, so caller is always defined - r.use_file(r.main_class, vfile.as_string(), r.get_method_filename(r.get_method_frame()->caller()->junction.method)); + r.use_file(r.main_class, vfile.as_string(), r.get_method_filename(&r.get_method_frame()->caller()->method)); } static void set_skip(Request& r, Request::Skip askip) { @@ -431,6 +439,7 @@ public: Request& r; const String* searching_string; double searching_double; + bool searching_bool; Value* found; Value* _default; public: @@ -440,9 +449,11 @@ public: if(asearching.is_string() || asearching.is_void()){ searching_string=&asearching.as_string(); searching_double=0; + searching_bool=false; } else { searching_string=0; searching_double=asearching.as_double(); + searching_bool=asearching.is_bool(); } } }; @@ -492,6 +503,8 @@ static void _case(Request& r, MethodPara bool matches; if(data->searching_string) matches=(*data->searching_string) == value.as_string(); + else if(data->searching_bool || value.is_bool()) + matches=(data->searching_double != 0) == value.as_bool(); else matches=data->searching_double == value.as_double(); @@ -868,7 +881,8 @@ static void _throw_operator(Request&, Me static void _sleep_operator(Request& r, MethodParams& params) { double seconds=params.as_double(0, "seconds must be double", r); - pa_sleep((int)trunc(seconds), (int)trunc(seconds*1000)); + if(seconds>0) + pa_sleep((int)trunc(seconds), (int)trunc((seconds-trunc(seconds))*1000000)); } #if defined(WIN32) && defined(_DEBUG) @@ -899,6 +913,9 @@ VClassMAIN::VClassMAIN(): VClass() { // ^taint[as-is|uri|sql|js|html|html-typo|regex|parser-code]{code} add_native_method("taint", Method::CT_ANY, _taint, 1, 2, Method::CO_WITHOUT_FRAME); + // ^apply-taint[untaint lang][string] + add_native_method("apply-taint", Method::CT_ANY, _apply_taint, 1, 2, Method::CO_WITHOUT_FRAME); + // ^process[code] add_native_method("process", Method::CT_ANY, _process, 1, 3);