Annotation of parser3/src/classes/exec.C, revision 1.1
1.1 ! paf 1: /** @file
! 2: Parser: @b exec parser class.
! 3:
! 4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
! 5:
! 6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
! 7:
! 8: $Id: op.C,v 1.2 2001/04/06 10:32:16 paf Exp $
! 9: */
! 10:
! 11: #include "pa_config_includes.h"
! 12: #include "pa_sapi.h"
! 13: #include "_exec.h"
! 14: #include "pa_request.h"
! 15:
! 16: VStateless_class *exec_class;
! 17:
! 18: /// ^exec[file-name]
! 19: /// ^exec[file-name;env hash]
! 20: /// ^exec[file-name;env hash;cmd;line;arg;s]
! 21: static void _cgi(Request& r, const String& method_name, Array *params) {
! 22: Pool& pool=r.pool();
! 23:
! 24: Value& vfile_name=*static_cast<Value *>(params->get(0));
! 25: // forcing [this param type]
! 26: r.fail_if_junction_(true, vfile_name,
! 27: method_name, "file name must not be code");
! 28:
! 29: Hash *env=0;
! 30: if(params->size()>1) {
! 31: Value& venv=*static_cast<Value *>(params->get(1));
! 32: // forcing [this param type]
! 33: r.fail_if_junction_(true, venv,
! 34: method_name, "env must not be code");
! 35: env=venv.get_hash();
! 36: if(!env)
! 37: PTHROW(0, 0,
! 38: &method_name,
! 39: "env must be hash");
! 40: }
! 41:
! 42: Array *argv=0;
! 43: if(params->size()>2) {
! 44: argv=new(pool) Array(pool, params->size()-2);
! 45: for(int i=2; i<params->size(); i++)
! 46: *argv+=&static_cast<Value *>(params->get(i))->as_string();
! 47: }
! 48:
! 49: const String in(pool, r.post_data, r.post_size);
! 50: String out(pool), err(pool);
! 51: SAPI::execute(vfile_name.as_string(), env, argv,
! 52: in, out, err);
! 53: r.write_pass_lang(out);
! 54: if(err.size())
! 55: SAPI::log(pool, "cgi:%s", err.cstr());
! 56: }
! 57:
! 58: // initialize
! 59:
! 60: void initialize_exec_class(Pool& pool, VStateless_class& vclass) {
! 61: // ^exec[file-name]
! 62: // ^exec[file-name;env hash]
! 63: // ^exec[file-name;env hash;1cmd;2line;3ar;4g;5s]
! 64: vclass.add_native_method("cgi", Method::CT_STATIC, _cgi, 1, 2+5);
! 65: }
E-mail: