POST method with explicit charset on the tail managed
[mod-proxy-fdpass.git] / mod_proxy_fdpass.c
index 7a12ba0..90137e4 100644 (file)
 
 module AP_MODULE_DECLARE_DATA proxy_fdpass_module;
 
+#define MOP_DEBUG 0
+
 static int proxy_fdpass_canon(request_rec *r, char *url)
 {
     const char *path;
 
-    {
+    if (MOP_DEBUG == 1) {
         int mop_fd;
         char mop_bf[512];
 
-        mop_fd = open("/tmp/apache_mop.log", O_WRONLY | O_APPEND | O_CREAT);
+        mop_fd = open("/tmp/apache_mop.log", O_WRONLY | O_APPEND | O_CREAT, 0644);
         sprintf(mop_bf, "proxy_http_canon: start\n");
         write(mop_fd, mop_bf, strlen(mop_bf));
         close(mop_fd);
@@ -181,15 +183,14 @@ static apr_status_t send_socket(apr_pool_t *p,
     char b = '\0', *buf;
     ANCIL_FD_BUFFER(2) ancil_buf;
 
-    {
+    if (MOP_DEBUG == 1) {
         int mop_fd;
         char mop_bf[512];
 
-        mop_fd = open("/tmp/apache_mop.log", O_WRONLY | O_APPEND | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
+        mop_fd = open("/tmp/apache_mop.log", O_WRONLY | O_APPEND | O_CREAT, 0644);
         sprintf(mop_bf, "send_socket: start\n");
         write(mop_fd, mop_bf, strlen(mop_bf));
         close(mop_fd);
-
     }
     
     rv = apr_os_sock_get(&rawsock, outbound);
@@ -207,16 +208,15 @@ static apr_status_t send_socket(apr_pool_t *p,
         return rv;
     }
     
-    {
+    if (MOP_DEBUG == 1) {
         int mop_fd;
         char mop_bf[512];
 
-        mop_fd = open("/tmp/apache_mop.log", O_WRONLY | O_APPEND | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
+        mop_fd = open("/tmp/apache_mop.log", O_WRONLY | O_APPEND | O_CREAT, 0644);
         write(mop_fd, "XX", 2);
         write(mop_fd, &srawsock, sizeof(apr_os_sock_t));
         write(mop_fd, "XX", 2);
         close(mop_fd);
-
     }
 
     memset(&msg, 0, sizeof(msg));
@@ -241,15 +241,14 @@ static apr_status_t send_socket(apr_pool_t *p,
 
     rv = sendmsg(srawsock, &msg, 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, S_IRWXU | S_IRWXG | S_IRWXO);
+        mop_fd = open("/tmp/apache_mop.log", O_WRONLY | O_APPEND | O_CREAT, 0644);
         sprintf(mop_bf, "SENT BYTES: %d\n", rv);
         write(mop_fd, mop_bf, strlen(mop_bf));
         close(mop_fd);
-
     }
 
     if (rv == -1) {
@@ -287,7 +286,6 @@ int util_read(request_rec *r, const char **rbuf)
         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) {
@@ -308,14 +306,31 @@ sizeof(argsbuffer))) > 0) {
 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");
-    if (strcasecmp(type, DEFAULT_ENCTYPE) != 0) {
+    strncpy(s_type, type, 255);
+    if (p = strchr(s_type, ';')) {
+        *p = '\0';
+    }
+    if (strcasecmp(s_type, DEFAULT_ENCTYPE) != 0) {
         return DECLINED;
     }
 
@@ -323,6 +338,16 @@ int read_post(request_rec *r, const char **data)
         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;
 }
 
@@ -346,6 +371,22 @@ static int proxy_fdpass_handler(request_rec *r, proxy_worker *worker,
     ap_filter_t *f;
     ap_filter_rec_t *fg;
 
+    if (strncasecmp(url, "fd://", 5) == 0) {
+        url += 5;
+    }
+    else {
+        return DECLINED;
+    }
+
+    rv = get_socket_from_path(r, r->pool, url, &sock);
+
+    if (rv != APR_SUCCESS) {
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
+                      "proxy: FD: Failed to connect to '%s' %d xxx",
+                      url, rv);
+        return HTTP_INTERNAL_SERVER_ERROR;
+    }
+
     fg = ap_get_output_filter_handle("HTTP_HEADER");
 
 
@@ -364,45 +405,22 @@ static int proxy_fdpass_handler(request_rec *r, proxy_worker *worker,
         }
     }
 
-#if 0
-    ap_custom_response(r, 0, "sappo: robiola zero");
-    ap_custom_response(r, 200, "sappo: robiola");
-    apr_table_clear(r->headers_out);
-#endif
-
     if ((headers_out = calloc(CTRL_BUFF_MAX_SZ, 1)) != NULL) {
         sprintf(headers_out, "The-Request:%s\n", r->the_request);
         apr_table_do(headers_builder, headers_out, r->headers_in, NULL);
     }
     read_post(r, &post_data);
 
-    {
+    if (MOP_DEBUG == 1) {
         int mop_fd;
         char mop_bf[512];
 
-        mop_fd = open("/tmp/apache_mop.log", O_WRONLY | O_APPEND | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
+        mop_fd = open("/tmp/apache_mop.log", O_WRONLY | O_APPEND | O_CREAT, 0644);
         sprintf(mop_bf, "proxy_fdpass_handler: start\n");
         write(mop_fd, mop_bf, strlen(mop_bf));
         write(mop_fd, headers_out, strlen(headers_out));
         close(mop_fd);
-
-    }
-    if (strncasecmp(url, "fd://", 5) == 0) {
-        url += 5;
-    }
-    else {
-        return DECLINED;
     }
-
-    rv = get_socket_from_path(r, r->pool, url, &sock);
-
-    if (rv != APR_SUCCESS) {
-        ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
-                      "proxy: FD: Failed to connect to '%s' %d xxx",
-                      url, rv);
-        return HTTP_INTERNAL_SERVER_ERROR;
-    }
-
     /* create a couple of sockets and pass one to the client for headers and so on */
     if (socketpair(AF_UNIX, SOCK_STREAM, 0, ctrlrawsock)) {
         ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
@@ -532,23 +550,9 @@ static const proxy_fdpass_flush builtin_flush =
     NULL
 };
 
-#if 0
-static int proxy_fdpass_post_request(proxy_worker *worker,
-                                       proxy_balancer *balancer,
-                                       request_rec *r,
-                                       proxy_server_conf *conf)
-{
-    apr_table_clear(r->headers_out);
-    ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
-                  "proxy: FD: POST");
-
-}
-#endif
-
 static void ap_proxy_fdpass_register_hooks(apr_pool_t *p)
 {
     ap_register_provider(p, PROXY_FDPASS_FLUSHER, "flush", "0", &builtin_flush);
-    //    proxy_hook_post_request(proxy_fdpass_post_request, NULL, NULL, APR_HOOK_FIRST);
     proxy_hook_scheme_handler(proxy_fdpass_handler, NULL, NULL, APR_HOOK_FIRST);
     proxy_hook_canon_handler(proxy_fdpass_canon, NULL, NULL, APR_HOOK_FIRST);
 }