--- parser3/src/classes/Attic/root.C 2001/03/10 11:03:47 1.7 +++ parser3/src/classes/Attic/root.C 2001/03/11 12:04:42 1.15 @@ -1,33 +1,49 @@ /* -$Id: root.C,v 1.7 2001/03/10 11:03:47 paf Exp $ + Parser + Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexander Petrosyan (http://design.ru/paf) + + $Id: root.C,v 1.15 2001/03/11 12:04:42 paf Exp $ */ #include "pa_request.h" +#include "_root.h" static void _if(Request& r, Array *params) { bool condition= r.autocalc( *static_cast(params->get(0)), - false/*don't make it string*/).get_bool(); + 0/*no name*/, + false/*don't intercept string*/).get_bool(); if(condition) { Value& value=r.autocalc(*static_cast(params->get(1))); - r.wcontext->write(value); + r.wcontext->write(value, String::Untaint_lang::PASS_APPENDED); } else if(params->size()==3) { Value& value=r.autocalc(*static_cast(params->get(2))); - r.wcontext->write(value); + r.wcontext->write(value, String::Untaint_lang::PASS_APPENDED); } } -void initialize_root_class(Pool& pool, VClass& vclass) { - String& IF_NAME=*new(pool) String(pool); - IF_NAME.APPEND_CONST("if"); +static void _untaint(Request& r, Array *params) { + const String& lang_name=r.autocalc(*static_cast(params->get(0))).as_string(); + String::Untaint_lang lang=static_cast( + untaint_lang_name_to_value->get_int(lang_name)); + if(!lang) + R_THROW(0, 0, + &lang_name, + "invalid language"); - Method& IF_METHOD=*new(pool) Method(pool, - IF_NAME, - 2, 3, // min,max numbered_params_count - 0/*params_names*/, 0/*locals_names*/, - 0/*parser_code*/, _if - ); + Temp_lang temp_lang(r, lang); + Value& value=r.autocalc(*static_cast(params->get(1))); + r.wcontext->write(value, String::Untaint_lang::PASS_APPENDED); +} + + +void initialize_root_class(Pool& pool, VClass& vclass) { + // ^if(condition){code-when-true} + // ^if(condition){code-when-true}{code-when-false} + vclass.add_native_method("if", _if, 2, 3); - vclass.add_method(IF_NAME, IF_METHOD); + // ^untaint[as-is|sql|js|html|html-typo]{code} + vclass.add_native_method("untaint", _untaint, 2, 2); }