Annotation of parser3/src/classes/root.C, revision 1.18
1.1 paf 1: /*
1.10 paf 2: Parser
3: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.12 paf 4: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.10 paf 5:
1.18 ! paf 6: $Id: root.C,v 1.17 2001/03/11 21:41:03 paf Exp $
1.1 paf 7: */
8:
1.18 ! paf 9: #include <string.h>
! 10:
1.1 paf 11: #include "pa_request.h"
1.8 paf 12: #include "_root.h"
1.1 paf 13:
1.18 ! paf 14: static void _if(Request& r, const String&, Array *params) {
1.2 paf 15: bool condition=
1.18 ! paf 16: r.process(
1.6 paf 17: *static_cast<Value *>(params->get(0)),
1.11 paf 18: 0/*no name*/,
1.14 paf 19: false/*don't intercept string*/).get_bool();
1.6 paf 20: if(condition) {
1.18 ! paf 21: Value& value=r.process(*static_cast<Value *>(params->get(1)));
1.9 paf 22: r.wcontext->write(value, String::Untaint_lang::PASS_APPENDED);
1.6 paf 23: } else if(params->size()==3) {
1.18 ! paf 24: Value& value=r.process(*static_cast<Value *>(params->get(2)));
1.9 paf 25: r.wcontext->write(value, String::Untaint_lang::PASS_APPENDED);
1.6 paf 26: }
1.1 paf 27: }
28:
1.18 ! paf 29: static void _untaint(Request& r, const String& name, Array *params) {
! 30: const String& lang_name=r.process(*static_cast<Value *>(params->get(0))).as_string();
1.15 paf 31: String::Untaint_lang lang=static_cast<String::Untaint_lang>(
1.16 paf 32: untaint_lang_name_to_enum->get_int(lang_name));
1.15 paf 33: if(!lang)
34: R_THROW(0, 0,
35: &lang_name,
1.18 ! paf 36: "invalid untaint language");
1.15 paf 37:
38: Temp_lang temp_lang(r, lang);
1.17 paf 39: Value *value=static_cast<Value *>(params->get(1));
1.18 ! paf 40: // forcing ^untaint[]{this param type}
1.17 paf 41: if(!value->get_junction())
42: R_THROW(0, 0,
1.18 ! paf 43: &name,
! 44: "body must be junction");
1.17 paf 45:
1.18 ! paf 46: value=&r.process(*value);
1.17 paf 47: r.wcontext->write(*value, String::Untaint_lang::PASS_APPENDED);
1.15 paf 48: }
49:
50:
1.18 ! paf 51: static void _process(Request& r, const String& name, Array *params) {
! 52: Value *vsource=static_cast<Value *>(params->get(0));
! 53: // evaluate source to process
! 54: const String& source=r.process(*vsource).as_string();
! 55:
! 56: // process source code, append processed methods to 'self' class
! 57: char place[MAX_STRING];
! 58: #ifndef NO_STRING_ORIGIN
! 59: const Origin& origin=source.origin();
! 60: snprintf(place, MAX_STRING, "%s(%d) %s",
! 61: origin.file, 1+origin.line,
! 62: name.cstr());
! 63: #else
! 64: strncpy(place, MAX_STRING, name.cstr());
! 65: #endif
! 66: r.use_buf(source.cstr(), place, r.self->get_class());
! 67:
! 68: // execute @main[]
! 69: if(Value *value=r.self->get_element(*main_method_name)) { // found some 'main' element
! 70: if(Junction *junction=value->get_junction()) // it even has junction!
! 71: if(const Method *method=junction->method) { // and junction is method-junction! call it
! 72: // execute!
! 73: r.execute(*method->parser_code);
! 74: return;
! 75: }
! 76: }
! 77:
! 78: R_THROW(0, 0,
! 79: &name,
! 80: "'"MAIN_METHOD_NAME"' method not found");
! 81: }
! 82:
! 83:
1.7 paf 84: void initialize_root_class(Pool& pool, VClass& vclass) {
1.15 paf 85: // ^if(condition){code-when-true}
86: // ^if(condition){code-when-true}{code-when-false}
87: vclass.add_native_method("if", _if, 2, 3);
88:
89: // ^untaint[as-is|sql|js|html|html-typo]{code}
90: vclass.add_native_method("untaint", _untaint, 2, 2);
1.18 ! paf 91:
! 92: // ^process[code]
! 93: vclass.add_native_method("process", _process, 1, 1);
1.1 paf 94: }
E-mail: