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