Annotation of parser3/src/classes/exec.C, revision 1.2

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: 
1.2     ! paf         8:        $Id: exec.C,v 1.1 2001/04/09 09:48:15 paf Exp $
1.1       paf         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);
1.2     ! paf        50:        String out(pool);
        !            51:        String err(pool);
        !            52:        SAPI::execute(r.absolute(vfile_name.as_string()), env, argv,
1.1       paf        53:                in, out, err);
                     54:        r.write_pass_lang(out);
                     55:        if(err.size())
                     56:                SAPI::log(pool, "cgi:%s", err.cstr());
                     57: }
                     58: 
                     59: // initialize
                     60: 
                     61: void initialize_exec_class(Pool& pool, VStateless_class& vclass) {
                     62:        // ^exec[file-name]
                     63:        // ^exec[file-name;env hash]
                     64:        // ^exec[file-name;env hash;1cmd;2line;3ar;4g;5s]
                     65:        vclass.add_native_method("cgi", Method::CT_STATIC, _cgi, 1, 2+5);
                     66: }

E-mail: