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

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.4! paf         8: static const char* IDENT_FORM_C="$Date: 2003/02/04 14:12:41 $";
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.4! paf        21: class MForm: public Methoded {
1.11      paf        22: public: // Methoded
1.34.2.4! paf        23: 
1.4       paf        24:        bool used_directly() { return false; }
1.5       paf        25:        void configure_admin(Request& r);
1.34.2.4! paf        26: 
        !            27: public:
        !            28: 
        !            29:        MForm(): Methoded(0) {}
        !            30: 
1.4       paf        31: };
1.1       paf        32: 
1.34.2.4! paf        33: // global variable
        !            34: 
        !            35: MethodedPtr form_base_class(new MForm);
        !            36: 
        !            37: // defines for statics
        !            38: 
        !            39: #define LIMITS_NAME "LIMITS"
        !            40: #define MAX_POST_SIZE_NAME "post_max_size"
        !            41: 
        !            42: // statics
        !            43: 
        !            44: StringPtr max_post_size_name(new String(MAX_POST_SIZE_NAME));
        !            45: StringPtr limits_name(new String(LIMITS_NAME));
        !            46: 
1.1       paf        47: // methods
                     48: 
1.5       paf        49: // constructor & configurator
1.4       paf        50: 
1.5       paf        51: void MForm::configure_admin(Request& r) {
                     52:        Pool& pool=r.pool();
                     53: 
1.34.2.4! paf        54:        ValuePtr limits=r.main_class->get_element(limits_name, *r.main_class, false);
        !            55:        if(r.request_info.method && StrEqNc(r.request_info.method, "post", true)) {
1.6       paf        56:                // $limits.max_post_size default 10M
1.34.2.4! paf        57:                ValuePtr element=limits?limits->get_element(max_post_size_name, *limits, false)
        !            58:                        :ValuePtr(0);
1.5       paf        59:                size_t value=element?(size_t)element->as_double():0;
1.6       paf        60:                size_t max_post_size=value?value:MAX_POST_SIZE_DEFAULT;
1.5       paf        61:                
1.34.2.4! paf        62:                if(r.request_info.content_length>max_post_size)
1.22      paf        63:                        throw Exception("parser.runtime",
1.34.2.4! paf        64:                                Exception::undefined_source,
1.5       paf        65:                                "posted content_length(%u) > max_post_size(%u)",
1.34.2.4! paf        66:                                        r.request_info.content_length, max_post_size);
        !            67:                if(r.request_info.content_length<0)
        !            68:                        throw Exception(Exception::undefined_type,
        !            69:                                Exception::undefined_source,
1.17      parser     70:                                "posted content_length(%u) < 0",
1.34.2.4! paf        71:                                        r.request_info.content_length);
1.5       paf        72: 
                     73:                // read POST data
1.34.2.4! paf        74:                if(r.request_info.content_length) {
        !            75:                        char *post_data=new(pool) char[r.request_info.content_length];
        !            76:                        r.request_info.post_size=SAPI::read_post(r.sapi_info, 
        !            77:                                        post_data, r.request_info.content_length);
        !            78:                        r.request_info.post_data=post_data;
1.17      parser     79:                }
1.34.2.4! paf        80:                if(r.request_info.post_size!=r.request_info.content_length)
        !            81:                        throw Exception(Exception::undefined_type, 
        !            82:                                Exception::undefined_source, 
1.25      paf        83:                                "post_size(%u) != content_length(%u)", 
1.34.2.4! paf        84:                                        r.request_info.post_size, r.request_info.content_length);
1.6       paf        85:        }
1.1       paf        86: }

E-mail: