OSDN Git Service

* Added feature.
authorAtsushi Konno <konn@users.sourceforge.jp>
Tue, 8 Mar 2011 14:59:04 +0000 (23:59 +0900)
committerAtsushi Konno <konn@users.sourceforge.jp>
Tue, 8 Mar 2011 14:59:04 +0000 (23:59 +0900)
    - remove output_filter if it is not necessary.
    - remove chxj_specified_cleanup.

include/chxj_specified_device.h
include/mod_chxj.h
src/chxj_img_conv_format.c
src/chxj_specified_device.c
src/mod_chxj.c

index 0a48abd..a591a1b 100644 (file)
@@ -131,5 +131,4 @@ extern device_table* chxj_specified_device(
   request_rec             *r, 
   const char              *user_agent);
 
-extern void chxj_specified_cleanup(request_rec *r);
 #endif
index dfb9aae..29221dd 100644 (file)
@@ -366,6 +366,7 @@ struct mod_chxj_config {
 struct mod_chxj_req_config_t {
   char *user_agent;
   device_table *spec;
+  ap_filter_t     *f;
 };
 
 #define IS_COOKIE_STORE_DBM(X)      ((X) == COOKIE_STORE_TYPE_DBM)
@@ -490,6 +491,8 @@ extern char *chxj_node_convert_chxjif_only(
   apr_size_t   *len
 );
 
+extern void chxj_remove_filter(request_rec *r);
+
 #define IMAGE_CACHE_LIMIT_FMT_LEN  (20)
 
 
index fa0f1ee..8ccd5b9 100644 (file)
@@ -301,10 +301,10 @@ chxj_img_conv_format_handler(request_rec *r)
 
 
 
+  mod_chxj_req_config *request_conf = chxj_get_module_config(r->request_config, &chxj_module);
   if (qsp->ua_flag == UA_IGN)
     spec = &v_ignore_spec;
   else {
-    mod_chxj_req_config *request_conf = chxj_get_module_config(r->request_config, &chxj_module);
     if (request_conf->user_agent 
         && user_agent 
         && strcmp(request_conf->user_agent, user_agent) != 0) {
@@ -319,6 +319,10 @@ chxj_img_conv_format_handler(request_rec *r)
   DBG(r,"REQ[%X] User-Agent=[%s]", TO_ADDR(r), user_agent);
 
 
+  /* 
+   * Do not process output_filter
+   */
+  chxj_remove_filter(r);
   rtn = s_img_conv_format_from_file(r, conf, user_agent, qsp, spec);
   DBG(r,"REQ[%X] end %s()",TO_ADDR(r),__func__);
   return rtn;
index 668d02b..1ef2ef9 100644 (file)
@@ -139,13 +139,6 @@ chxj_specified_device(request_rec *r, const char *user_agent)
   return &UNKNOWN_DEVICE;
 }
 
-void
-chxj_specified_cleanup(request_rec *r) 
-{
-  DBG(r,"REQ[%X] start %s()",TO_ADDR(r), __func__);
-  DBG(r,"REQ[%X] end %s()",TO_ADDR(r), __func__);
-}
-
 
 #include <stdlib.h>
 static int 
index 2721656..c07b030 100644 (file)
@@ -198,6 +198,7 @@ chxj_headers_fixup(request_rec *r)
     request_conf = apr_pcalloc(r->pool, sizeof(mod_chxj_req_config));
     request_conf->spec = NULL;
     request_conf->user_agent = NULL;
+    request_conf->f = NULL;
     chxj_set_module_config(r->request_config, &chxj_module, request_conf);
   }
 
@@ -1099,7 +1100,6 @@ chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
     s_add_no_cache_headers(r, entryp);
     /* must not send body. */
     rv = pass_data_to_filter(f, "", 0);
-    chxj_specified_cleanup(r);
     DBG(f->r, "REQ[%X] end of %s()", TO_ADDR(r),__func__);
     return rv;
   }
@@ -1153,7 +1153,6 @@ chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
       }
       s_add_no_cache_headers(r, entryp);
       ap_pass_brigade(f->next, bb);
-      chxj_specified_cleanup(r);
       DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
       return APR_SUCCESS;
     }
@@ -1161,7 +1160,6 @@ chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
   else {
     DBG(r, "REQ[%X] not convert content-type:[(null)]", TO_ADDR(r));
     ap_pass_brigade(f->next, bb);
-    chxj_specified_cleanup(r);
     DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
     return APR_SUCCESS;
   }
@@ -1280,7 +1278,6 @@ chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
             if (sts != OK) {
               ERR(r, "REQ[%X] qrcode create failed.", TO_ADDR(r));
               chxj_cookie_unlock(r, lock);
-              chxj_specified_cleanup(r);
               DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
               return sts;
             }
@@ -1351,7 +1348,6 @@ chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
                                    (const char *)ctx->buffer, 
                                    (apr_size_t)ctx->len);
         }
-        chxj_specified_cleanup(r);
         DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
         return rv;
       }
@@ -1398,7 +1394,6 @@ chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
         apr_table_setn(r->headers_out, "Content-Length", "0");
         s_add_no_cache_headers(r, entryp);
         rv = pass_data_to_filter(f, (const char *)"", (apr_size_t)0);
-        chxj_specified_cleanup(r);
         DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r), __func__);
         return rv;
       }
@@ -1406,7 +1401,6 @@ chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
   }
   apr_brigade_destroy(bb);
 
-  chxj_specified_cleanup(r);
   DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r), __func__);
 
   return APR_SUCCESS;
@@ -1671,6 +1665,7 @@ chxj_insert_filter(request_rec *r)
   char                *user_agent;
   device_table        *spec;
   mod_chxj_config     *dconf;
+  mod_chxj_req_config *req_conf;
   chxjconvrule_entry  *entryp;
   mod_chxj_ctx        *ctx;
   apr_status_t        rv;
@@ -1679,6 +1674,7 @@ chxj_insert_filter(request_rec *r)
   DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
 
   dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
+  req_conf = chxj_get_module_config(r->request_config, &chxj_module);
 
   /* we get User-Agent from CHXJ_HTTP_USER_AGENT header if any */
   user_agent = (char *)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
@@ -1739,13 +1735,27 @@ chxj_insert_filter(request_rec *r)
 
 
   if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
-    ap_add_output_filter("chxj_output_filter", ctx, r, r->connection);
+    req_conf->f = ap_add_output_filter("chxj_output_filter", ctx, r, r->connection);
     DBG(r, "REQ[%X] added Output Filter", TO_ADDR(r));
   }
 
   DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
 }
 
+void 
+chxj_remove_filter(request_rec *r)
+{
+  mod_chxj_req_config *req_conf;
+
+  DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
+  req_conf = chxj_get_module_config(r->request_config, &chxj_module);
+  if (req_conf && req_conf->f) {
+    ap_remove_output_filter(req_conf->f);
+    DBG(r, "REQ[%X] REMOVE Output Filter", TO_ADDR(r));
+  }
+  DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
+}
+
 
 /**
  * The hook is registered.