+#define CTRL_BUFF_MAX_SZ (8*1024)
+
+#define DEFAULT_ENCTYPE "application/x-www-form-urlencoded"
+
+int util_read(request_rec *r, const char **rbuf)
+{
+ int rc;
+
+ if ((rc = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR)) != OK) {
+ return rc;
+ }
+
+ if (ap_should_client_block(r)) {
+ char argsbuffer[HUGE_STRING_LEN];
+ int rsize, len_read, rpos=0;
+ long length = r->remaining;
+ *rbuf = (char *)apr_pcalloc(r->pool, length +1);
+ while ((len_read = ap_get_client_block(r, argsbuffer,
+sizeof(argsbuffer))) > 0) {
+ if ((rpos + len_read) > length) {
+ rsize = length - rpos;
+ } else {
+ rsize = len_read;
+ }
+
+ memcpy((char *)*rbuf + rpos, argsbuffer, rsize);
+ rpos += rsize;
+ }
+
+ }
+
+ return rc;
+}
+
+int read_post(request_rec *r, const char **data)
+{
+ const char *type;
+ char *p, s_type[256];
+ int rc = OK;
+
+ s_type[255] = '\0';
+ if (MOP_DEBUG == 1) {
+ int mop_fd;
+ char mop_bf[512];
+
+ mop_fd = open("/tmp/apache_mop.log", O_WRONLY | O_APPEND | O_CREAT, 0644);
+ sprintf(mop_bf, "read_post: start: numb: %d %d head_in: [%s]\n", r->method_number, M_POST, apr_table_get(r->headers_in, "Content-Type"));
+ write(mop_fd, mop_bf, strlen(mop_bf));
+ close(mop_fd);
+ }
+
+
+ if (r->method_number != M_POST) {
+ return rc;
+ }
+
+ type = apr_table_get(r->headers_in, "Content-Type");
+ strncpy(s_type, type, 255);
+ if (p = strchr(s_type, ';')) {
+ *p = '\0';
+ }
+ if (strcasecmp(s_type, DEFAULT_ENCTYPE) != 0) {
+ return DECLINED;
+ }
+
+ if ((rc = util_read(r, data)) != OK) {
+ return rc;
+ }
+
+ if (MOP_DEBUG == 1) {
+ int mop_fd;
+ char mop_bf[512];
+
+ mop_fd = open("/tmp/apache_mop.log", O_WRONLY | O_APPEND | O_CREAT, 0644);
+ sprintf(mop_bf, "read_post: finish\n");
+ write(mop_fd, mop_bf, strlen(mop_bf));
+ close(mop_fd);
+ }
+
+ return OK;
+}
+
+