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

1.3       paf         1: /** @file
                      2:        Parser: @b form parser class.
                      3: 
1.35    ! 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.35    ! paf         8: static const char* IDENT_FORM_C="$Date: 2003/05/30 09:47:11 $";
1.1       paf         9: 
1.10      paf        10: #include "classes.h"
1.35    ! 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: 
                     21: class MForm : public Methoded {
1.11      paf        22: public: // Methoded
1.35    ! paf        23: 
1.4       paf        24:        bool used_directly() { return false; }
1.5       paf        25:        void configure_admin(Request& r);
1.35    ! paf        26: 
        !            27: public:
        !            28: 
        !            29:        MForm(): Methoded("form") {}
        !            30: 
1.4       paf        31: };
1.1       paf        32: 
1.35    ! paf        33: // global variable
        !            34: 
        !            35: DECLARE_CLASS_VAR(form, 0/*fictive*/, 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: static const String max_post_size_name(MAX_POST_SIZE_NAME);
        !            45: static const String limits_name(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: 
1.35    ! paf        53:        Value* limits=r.main_class.get_element(limits_name, r.main_class, false);
        !            54:        if(r.request_info.method && StrEqNc(r.request_info.method, "post", true)) {
1.6       paf        55:                // $limits.max_post_size default 10M
1.35    ! paf        56:                Value* element=limits?limits->get_element(max_post_size_name, *limits, false)
        !            57:                        :0;
1.5       paf        58:                size_t value=element?(size_t)element->as_double():0;
1.6       paf        59:                size_t max_post_size=value?value:MAX_POST_SIZE_DEFAULT;
1.5       paf        60:                
1.35    ! paf        61:                if(r.request_info.content_length>max_post_size)
1.22      paf        62:                        throw Exception("parser.runtime",
1.5       paf        63:                                0,
                     64:                                "posted content_length(%u) > max_post_size(%u)",
1.35    ! paf        65:                                        r.request_info.content_length, max_post_size);
1.5       paf        66: 
                     67:                // read POST data
1.35    ! paf        68:                if(r.request_info.content_length) {
        !            69:                        char *post_data=new(PointerFreeGC) char[r.request_info.content_length+1/*terminating zero*/];
        !            70:                        size_t post_size=SAPI::read_post(r.sapi_info, 
        !            71:                                        post_data, r.request_info.content_length);
        !            72:                        post_data[post_size]=0; // terminating zero
        !            73:                        r.request_info.post_data=post_data;
        !            74:                        r.request_info.post_size=post_size;
        !            75:                } else {
        !            76:                        r.request_info.post_data=0;
        !            77:                        r.request_info.post_size=0;
1.17      parser     78:                }
1.35    ! paf        79:                if(r.request_info.post_size!=r.request_info.content_length)
1.22      paf        80:                        throw Exception(0, 
1.5       paf        81:                                0, 
1.25      paf        82:                                "post_size(%u) != content_length(%u)", 
1.35    ! paf        83:                                        r.request_info.post_size, r.request_info.content_length);
1.6       paf        84:        }
1.1       paf        85: }

E-mail: