Annotation of parser3/src/classes/form.C, revision 1.34.2.7

1.3       paf         1: /** @file
                      2:        Parser: @b form parser class.
                      3: 
1.34.2.1  paf         4:        Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)
1.21      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.27      paf         6: */
1.3       paf         7: 
1.34.2.7! paf         8: static const char* IDENT_FORM_C="$Date: 2003/02/19 16:18:59 $";
1.1       paf         9: 
1.10      paf        10: #include "classes.h"
1.34.2.3  paf        11: #include "pa_vmethod_frame.h"
                     12: 
1.1       paf        13: #include "pa_request.h"
                     14: #include "pa_vform.h"
                     15: 
1.6       paf        16: /// $LIMITS.max_post_size default 10M
1.25      paf        17: const size_t MAX_POST_SIZE_DEFAULT=10*0x400*0x400;
1.5       paf        18: 
1.4       paf        19: // class
                     20: 
1.34.2.6  paf        21: class MForm : public Methoded {
                     22: public:
                     23:        MForm(Pool& pool);
1.11      paf        24: public: // Methoded
1.34.2.4  paf        25: 
1.4       paf        26:        bool used_directly() { return false; }
1.5       paf        27:        void configure_admin(Request& r);
1.34.2.4  paf        28: 
                     29: public:
                     30: 
1.34.2.6  paf        31:        MForm(): Methoded("form") {}
1.34.2.4  paf        32: 
1.4       paf        33: };
1.1       paf        34: 
1.34.2.4  paf        35: // global variable
                     36: 
1.34.2.7! paf        37: DECLARE_CLASS_VAR(form, 0/*fictive*/, new MForm);
1.34.2.4  paf        38: 
                     39: // defines for statics
                     40: 
                     41: #define LIMITS_NAME "LIMITS"
                     42: #define MAX_POST_SIZE_NAME "post_max_size"
                     43: 
                     44: // statics
                     45: 
                     46: StringPtr max_post_size_name(new String(MAX_POST_SIZE_NAME));
                     47: StringPtr limits_name(new String(LIMITS_NAME));
                     48: 
1.1       paf        49: // methods
                     50: 
1.5       paf        51: // constructor & configurator
1.4       paf        52: 
1.5       paf        53: void MForm::configure_admin(Request& r) {
                     54:        Pool& pool=r.pool();
                     55: 
1.34.2.4  paf        56:        ValuePtr limits=r.main_class->get_element(limits_name, *r.main_class, false);
                     57:        if(r.request_info.method && StrEqNc(r.request_info.method, "post", true)) {
1.6       paf        58:                // $limits.max_post_size default 10M
1.34.2.4  paf        59:                ValuePtr element=limits?limits->get_element(max_post_size_name, *limits, false)
                     60:                        :ValuePtr(0);
1.5       paf        61:                size_t value=element?(size_t)element->as_double():0;
1.6       paf        62:                size_t max_post_size=value?value:MAX_POST_SIZE_DEFAULT;
1.5       paf        63:                
1.34.2.4  paf        64:                if(r.request_info.content_length>max_post_size)
1.22      paf        65:                        throw Exception("parser.runtime",
1.34.2.4  paf        66:                                Exception::undefined_source,
1.5       paf        67:                                "posted content_length(%u) > max_post_size(%u)",
1.34.2.4  paf        68:                                        r.request_info.content_length, max_post_size);
                     69:                if(r.request_info.content_length<0)
                     70:                        throw Exception(Exception::undefined_type,
                     71:                                Exception::undefined_source,
1.17      parser     72:                                "posted content_length(%u) < 0",
1.34.2.4  paf        73:                                        r.request_info.content_length);
1.5       paf        74: 
                     75:                // read POST data
1.34.2.4  paf        76:                if(r.request_info.content_length) {
                     77:                        char *post_data=new(pool) char[r.request_info.content_length];
                     78:                        r.request_info.post_size=SAPI::read_post(r.sapi_info, 
                     79:                                        post_data, r.request_info.content_length);
                     80:                        r.request_info.post_data=post_data;
1.17      parser     81:                }
1.34.2.4  paf        82:                if(r.request_info.post_size!=r.request_info.content_length)
                     83:                        throw Exception(Exception::undefined_type, 
                     84:                                Exception::undefined_source, 
1.25      paf        85:                                "post_size(%u) != content_length(%u)", 
1.34.2.4  paf        86:                                        r.request_info.post_size, r.request_info.content_length);
1.6       paf        87:        }
1.1       paf        88: }

E-mail: