Annotation of parser3/src/classes/form.C, revision 1.34.2.5
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.5! paf 8: static const char* IDENT_FORM_C="$Date: 2003/02/06 14:31:53 $";
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:
1.34.2.5! paf 35: MethodedPtr form_class(0); // fictive
1.34.2.4 paf 36: MethodedPtr form_base_class(new MForm);
37:
38: // defines for statics
39:
40: #define LIMITS_NAME "LIMITS"
41: #define MAX_POST_SIZE_NAME "post_max_size"
42:
43: // statics
44:
45: StringPtr max_post_size_name(new String(MAX_POST_SIZE_NAME));
46: StringPtr limits_name(new String(LIMITS_NAME));
47:
1.1 paf 48: // methods
49:
1.5 paf 50: // constructor & configurator
1.4 paf 51:
1.5 paf 52: void MForm::configure_admin(Request& r) {
53: Pool& pool=r.pool();
54:
1.34.2.4 paf 55: ValuePtr limits=r.main_class->get_element(limits_name, *r.main_class, false);
56: if(r.request_info.method && StrEqNc(r.request_info.method, "post", true)) {
1.6 paf 57: // $limits.max_post_size default 10M
1.34.2.4 paf 58: ValuePtr element=limits?limits->get_element(max_post_size_name, *limits, false)
59: :ValuePtr(0);
1.5 paf 60: size_t value=element?(size_t)element->as_double():0;
1.6 paf 61: size_t max_post_size=value?value:MAX_POST_SIZE_DEFAULT;
1.5 paf 62:
1.34.2.4 paf 63: if(r.request_info.content_length>max_post_size)
1.22 paf 64: throw Exception("parser.runtime",
1.34.2.4 paf 65: Exception::undefined_source,
1.5 paf 66: "posted content_length(%u) > max_post_size(%u)",
1.34.2.4 paf 67: r.request_info.content_length, max_post_size);
68: if(r.request_info.content_length<0)
69: throw Exception(Exception::undefined_type,
70: Exception::undefined_source,
1.17 parser 71: "posted content_length(%u) < 0",
1.34.2.4 paf 72: r.request_info.content_length);
1.5 paf 73:
74: // read POST data
1.34.2.4 paf 75: if(r.request_info.content_length) {
76: char *post_data=new(pool) char[r.request_info.content_length];
77: r.request_info.post_size=SAPI::read_post(r.sapi_info,
78: post_data, r.request_info.content_length);
79: r.request_info.post_data=post_data;
1.17 parser 80: }
1.34.2.4 paf 81: if(r.request_info.post_size!=r.request_info.content_length)
82: throw Exception(Exception::undefined_type,
83: Exception::undefined_source,
1.25 paf 84: "post_size(%u) != content_length(%u)",
1.34.2.4 paf 85: r.request_info.post_size, r.request_info.content_length);
1.6 paf 86: }
1.1 paf 87: }
E-mail: