|
|
| version 1.17, 2001/03/11 21:41:03 | version 1.21, 2001/03/12 09:40:59 |
|---|---|
| Line 6 | Line 6 |
| $Id$ | $Id$ |
| */ | */ |
| #include <string.h> | |
| #include "pa_request.h" | #include "pa_request.h" |
| #include "_root.h" | #include "_root.h" |
| static void _if(Request& r, Array *params) { | static void _if(Request& r, const String&, Array *params) { |
| bool condition= | bool condition= |
| r.autocalc( | r.process( |
| *static_cast<Value *>(params->get(0)), | *static_cast<Value *>(params->get(0)), |
| 0/*no name*/, | 0/*no name*/, |
| false/*don't intercept string*/).get_bool(); | false/*don't intercept string*/).get_bool(); |
| if(condition) { | if(condition) { |
| Value& value=r.autocalc(*static_cast<Value *>(params->get(1))); | Value& value=r.process(*static_cast<Value *>(params->get(1))); |
| r.wcontext->write(value, String::Untaint_lang::PASS_APPENDED); | r.wcontext->write(value, String::Untaint_lang::PASS_APPENDED); |
| } else if(params->size()==3) { | } else if(params->size()==3) { |
| Value& value=r.autocalc(*static_cast<Value *>(params->get(2))); | Value& value=r.process(*static_cast<Value *>(params->get(2))); |
| r.wcontext->write(value, String::Untaint_lang::PASS_APPENDED); | r.wcontext->write(value, String::Untaint_lang::PASS_APPENDED); |
| } | } |
| } | } |
| static void _untaint(Request& r, Array *params) { | static void _untaint(Request& r, const String& name, Array *params) { |
| const String& lang_name=r.autocalc(*static_cast<Value *>(params->get(0))).as_string(); | const String& lang_name=r.process(*static_cast<Value *>(params->get(0))).as_string(); |
| String::Untaint_lang lang=static_cast<String::Untaint_lang>( | String::Untaint_lang lang=static_cast<String::Untaint_lang>( |
| untaint_lang_name_to_enum->get_int(lang_name)); | untaint_lang_name_to_enum->get_int(lang_name)); |
| if(!lang) | if(!lang) |
| R_THROW(0, 0, | R_THROW(0, 0, |
| &lang_name, | &lang_name, |
| "invalid language"); | "invalid untaint language"); |
| Temp_lang temp_lang(r, lang); | Temp_lang temp_lang(r, lang); |
| Value *value=static_cast<Value *>(params->get(1)); | Value *value=static_cast<Value *>(params->get(1)); |
| // forcing ^untaint[]{param type} | // forcing ^untaint[]{this param type} |
| if(!value->get_junction()) | if(!value->get_junction()) |
| R_THROW(0, 0, | R_THROW(0, 0, |
| &value->as_string(), | &name, |
| "untaint body must be junction"); | "body must be junction"); |
| value=&r.autocalc(*value); | value=&r.process(*value); |
| r.wcontext->write(*value, String::Untaint_lang::PASS_APPENDED); | r.wcontext->write(*value, String::Untaint_lang::PASS_APPENDED); |
| } | } |
| static void _process(Request& r, const String& name, Array *params) { | |
| // evaluate source to process | |
| const String& source=r.process(*static_cast<Value *>(params->get(0))).as_string(); | |
| // calculate pseudo file name of processed chars | |
| // would be something like "/some/file(4) process" | |
| char place[MAX_STRING]; | |
| #ifndef NO_STRING_ORIGIN | |
| const Origin& origin=source.origin(); | |
| snprintf(place, MAX_STRING, "%s(%d) %s", | |
| origin.file, 1+origin.line, | |
| name.cstr()); | |
| #else | |
| strncpy(place, MAX_STRING, name.cstr()); | |
| #endif | |
| VClass& self_class=*r.self->get_class(); | |
| // temporary zero @main so to maybe-replace it in processed code | |
| Temp_method temp_method(self_class, *main_method_name, 0); | |
| // process source code, append processed methods to 'self' class | |
| // maybe-define new @main | |
| r.use_buf(source.cstr(), place, &self_class); | |
| // maybe-execute @main[] | |
| if(const Method *method=self_class.get_method(*main_method_name)) { | |
| // execute! | |
| r.execute(*method->parser_code); | |
| } | |
| } | |
| void initialize_root_class(Pool& pool, VClass& vclass) { | void initialize_root_class(Pool& pool, VClass& vclass) { |
| // ^if(condition){code-when-true} | // ^if(condition){code-when-true} |
| // ^if(condition){code-when-true}{code-when-false} | // ^if(condition){code-when-true}{code-when-false} |
| Line 53 void initialize_root_class(Pool& pool, V | Line 87 void initialize_root_class(Pool& pool, V |
| // ^untaint[as-is|sql|js|html|html-typo]{code} | // ^untaint[as-is|sql|js|html|html-typo]{code} |
| vclass.add_native_method("untaint", _untaint, 2, 2); | vclass.add_native_method("untaint", _untaint, 2, 2); |
| // ^process[code] | |
| vclass.add_native_method("process", _process, 1, 1); | |
| } | } |