diff --git a/configure.ac b/configure.ac index c95ab438c2f..f69f026be50 100644 --- a/configure.ac +++ b/configure.ac @@ -1846,6 +1846,7 @@ AC_CONFIG_FILES([ plugins/conf_remap/Makefile plugins/experimental/Makefile plugins/experimental/authproxy/Makefile + plugins/experimental/buffer_upload/Makefile plugins/experimental/channel_stats/Makefile plugins/experimental/custom_redirect/Makefile plugins/experimental/esi/Makefile diff --git a/plugins/experimental/Makefile.am b/plugins/experimental/Makefile.am index d284623a0cc..bb97af146d0 100644 --- a/plugins/experimental/Makefile.am +++ b/plugins/experimental/Makefile.am @@ -17,6 +17,7 @@ if BUILD_EXPERIMENTAL_PLUGINS SUBDIRS = \ lua \ + buffer_upload \ esi \ rfc5861 \ tcp_info \ diff --git a/plugins/experimental/buffer_upload/Makefile.am b/plugins/experimental/buffer_upload/Makefile.am new file mode 100644 index 00000000000..d21c09e97a5 --- /dev/null +++ b/plugins/experimental/buffer_upload/Makefile.am @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +include $(top_srcdir)/build/plugins.mk + +pkglib_LTLIBRARIES = buffer_upload.la +buffer_upload_la_SOURCES = buffer_upload.cc +buffer_upload_la_LDFLAGS = $(TS_PLUGIN_LDFLAGS) diff --git a/plugins/experimental/buffer_upload/buffer_upload.cc b/plugins/experimental/buffer_upload/buffer_upload.cc index 847c5192d1b..de2c7909463 100644 --- a/plugins/experimental/buffer_upload/buffer_upload.cc +++ b/plugins/experimental/buffer_upload/buffer_upload.cc @@ -41,9 +41,6 @@ #include #include -#define true 1 -#define false 0 - /* #define DEBUG 1 */ #define DEBUG_TAG "buffer_upload-dbg" @@ -64,6 +61,13 @@ #define VALID_PTR(X) (X != NULL) #define NOT_VALID_PTR(X) (X == NULL) +#define STRING_RELEASE_MASK_1 1 +#define STRING_RELEASE_MASK_2 2 +#define STRING_RELEASE_MASK_3 4 +#define STRING_RELEASE_MASK_4 8 +#define STRING_RELEASE_MASK_5 16 +#define STRING_RELEASE_MASK_6 32 + struct upload_config_t { @@ -78,6 +82,7 @@ struct upload_config_t char *base_dir; int subdir_num; int thread_num; + int string_release_mask; }; typedef struct upload_config_t upload_config; @@ -181,7 +186,7 @@ write_buffer_to_disk(TSIOBufferReader reader, pvc_state * my_state, TSCont contp LOG_ERROR_AND_RETURN("TSAIOWrite"); } memcpy(pBuf, ptr, size); - if (TSAIOWrite(my_state->fd, my_state->write_offset, pBuf, size, contp) < 0) { + if (TSAIOWrite(my_state->fd, my_state->write_offset, pBuf, size, contp) == TS_ERROR) { LOG_ERROR_AND_RETURN("TSAIOWrite"); } my_state->write_offset += size; @@ -690,30 +695,41 @@ attach_pvc_plugin(TSCont contp, TSEvent event, void *edata) int content_length = 0; const char *method; int method_len; - const char *str; - int str_len; - + const char *host_str; + int host_str_len; + const char *host_hdr_str_val; + int host_hdr_str_val_len; + + TSDebug(DEBUG_TAG, "inside attach_pvc_plugin"); switch (event) { case TS_EVENT_HTTP_READ_REQUEST_PRE_REMAP: // if the request is issued by the TSHttpConnect() in this plugin, don't get in the endless cycle. - if (TSHttpIsInternalRequest(txnp)) { + if (TSHttpIsInternalRequest(txnp) == TS_SUCCESS) { + TSDebug(DEBUG_TAG, "internal request"); break; } - if (!TSHttpTxnClientReqGet(txnp, &req_bufp, &req_loc)) { + if (TSHttpTxnClientReqGet(txnp, &req_bufp, &req_loc) == TS_ERROR) { LOG_ERROR("Error while retrieving client request header"); break; } method = TSHttpHdrMethodGet(req_bufp, req_loc, &method_len); + TSDebug(DEBUG_TAG, "inside handler"); if (NOT_VALID_PTR(method) || method_len == 0) { + TSDebug(DEBUG_TAG, "invalid method"); + TSHandleMLocRelease(req_bufp, TS_NULL_MLOC, req_loc); break; } // only deal with POST method + TSDebug(DEBUG_TAG, "method: %s", method); + if (static_cast(method_len) != strlen(TS_HTTP_METHOD_POST) || strncasecmp(method, TS_HTTP_METHOD_POST, method_len) != 0) { + TSDebug(DEBUG_TAG, "Not POST method"); + //TSHandleStringRelease(req_bufp, req_loc, method); TSHandleMLocRelease(req_bufp, TS_NULL_MLOC, req_loc); break; @@ -727,9 +743,11 @@ attach_pvc_plugin(TSCont contp, TSEvent event, void *edata) // check against URL list if (TSHttpHdrUrlGet(req_bufp, req_loc, &url_loc) == TS_ERROR) { LOG_ERROR("Couldn't get the url"); + TSHandleMLocRelease(req_bufp, TS_NULL_MLOC, req_loc); + break; } - str = TSUrlHostGet(req_bufp, url_loc, &str_len); - if (NOT_VALID_PTR(str) || str_len <= 0) { + host_str = TSUrlHostGet(req_bufp, url_loc, &host_str_len); + if (NOT_VALID_PTR(host_str) || host_str_len <= 0) { // reverse proxy mode field_loc = TSMimeHdrFieldFind(req_bufp, req_loc, TS_MIME_FIELD_HOST, -1); if (NOT_VALID_PTR(field_loc)) { @@ -740,8 +758,8 @@ attach_pvc_plugin(TSCont contp, TSEvent event, void *edata) TSHandleMLocRelease(req_bufp, TS_NULL_MLOC, req_loc); break; } - str = TSMimeHdrFieldValueStringGet(req_bufp, req_loc, field_loc, 0, &str_len); - if (NOT_VALID_PTR(str) || str_len <= 0) { + host_hdr_str_val = TSMimeHdrFieldValueStringGet(req_bufp, req_loc, field_loc, 0, &host_hdr_str_val_len); + if (NOT_VALID_PTR(host_hdr_str_val) || host_hdr_str_val_len <= 0) { //if (VALID_PTR(str)) // TSHandleStringRelease(req_bufp, field_loc, str); TSHandleMLocRelease(req_bufp, req_loc, field_loc); @@ -750,12 +768,12 @@ attach_pvc_plugin(TSCont contp, TSEvent event, void *edata) break; } - char replacement_host_str[str_len + 1]; + char replacement_host_str[host_hdr_str_val_len + 1]; memset(replacement_host_str, 0, sizeof replacement_host_str); - memcpy(replacement_host_str, str, str_len); + memcpy(replacement_host_str, host_hdr_str_val, host_hdr_str_val_len); TSDebug(DEBUG_TAG, "Adding host to request url: %s", replacement_host_str); - TSUrlHostSet(req_bufp, url_loc, str, str_len); + TSUrlHostSet(req_bufp, url_loc, host_hdr_str_val, host_hdr_str_val_len); //TSHandleStringRelease(req_bufp, field_loc, str); TSHandleMLocRelease(req_bufp, req_loc, field_loc); @@ -778,7 +796,7 @@ attach_pvc_plugin(TSCont contp, TSEvent event, void *edata) } } - //TSHandleStringRelease(req_bufp, url_loc, url); + TSfree(url); } TSHandleMLocRelease(req_bufp, req_loc, url_loc); @@ -794,8 +812,8 @@ attach_pvc_plugin(TSCont contp, TSEvent event, void *edata) convert_url_func(req_bufp, req_loc); } - if ((field_loc = TSMimeHdrFieldFind(req_bufp, req_loc, TS_MIME_FIELD_CONTENT_LENGTH, TS_MIME_LEN_CONTENT_LENGTH)) || - field_loc == NULL) { + field_loc = TSMimeHdrFieldFind(req_bufp, req_loc, TS_MIME_FIELD_CONTENT_LENGTH, TS_MIME_LEN_CONTENT_LENGTH); + if(field_loc == NULL) { TSHandleMLocRelease(req_bufp, TS_NULL_MLOC, req_loc); LOG_ERROR("TSMimeHdrFieldRetrieve"); break; @@ -875,7 +893,7 @@ attach_pvc_plugin(TSCont contp, TSEvent event, void *edata) if (!uconfig->use_disk_buffer && my_state->req_size > uconfig->mem_buffer_size) { TSDebug(DEBUG_TAG, - "The request size %lu is larger than memory buffer size %lu, bypass upload proxy feature for this request.", + "The request size %llu is larger than memory buffer size %llu, bypass upload proxy feature for this request.", my_state->req_size, uconfig->mem_buffer_size); pvc_cleanup(new_cont, my_state); @@ -1145,6 +1163,7 @@ read_upload_config(const char *file_name) uconfig->base_dir = NULL; uconfig->subdir_num = 64; uconfig->thread_num = 4; + uconfig->string_release_mask=0; struct config_val_ul config_vals[] = { {"use_disk_buffer", TYPE_BOOL, &(uconfig->use_disk_buffer)}, @@ -1156,6 +1175,7 @@ read_upload_config(const char *file_name) {"base_dir", TYPE_STRING, &(uconfig->base_dir)}, {"subdir_num", TYPE_UINT, &(uconfig->subdir_num)}, {"thread_num", TYPE_UINT, &(uconfig->thread_num)}, + {"string_release_mask", TYPE_UINT, &(uconfig->string_release_mask)}, {NULL, TYPE_LONG, NULL} }; TSFile conf_file; @@ -1193,6 +1213,12 @@ read_upload_config(const char *file_name) // default value uconfig->thread_num = 4; } + + if(uconfig->string_release_mask <= 0) + { + // turn on all string releases by default + uconfig->string_release_mask = 511; + } return true; } @@ -1249,3 +1275,4 @@ TSPluginInit(int argc, const char *argv[]) contp = TSContCreate(attach_pvc_plugin, NULL); TSHttpHookAdd(TS_HTTP_READ_REQUEST_PRE_REMAP_HOOK, contp); } +