trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpe...@apache.org
Subject [1/3] git commit: TS-2116: Making buffer_upload compile
Date Wed, 21 Aug 2013 21:58:52 GMT
Updated Branches:
  refs/heads/master 0f585e999 -> db31fe532


TS-2116: Making buffer_upload compile


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/fdfdc624
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/fdfdc624
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/fdfdc624

Branch: refs/heads/master
Commit: fdfdc624348d02eecc606b68e2d4390fed2249bf
Parents: 0f585e9
Author: Kit Chan <chanshukit@gmail.com>
Authored: Tue Aug 20 09:23:03 2013 -0700
Committer: James Peach <jpeach@apache.org>
Committed: Wed Aug 21 14:58:04 2013 -0700

----------------------------------------------------------------------
 configure.ac                                    |  1 +
 plugins/experimental/Makefile.am                |  1 +
 plugins/experimental/buffer_upload/Makefile.am  | 21 ++++++++
 .../experimental/buffer_upload/buffer_upload.cc | 53 +++++++++++++-------
 4 files changed, 57 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/fdfdc624/configure.ac
----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index 015380e..8765984 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

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/fdfdc624/plugins/experimental/Makefile.am
----------------------------------------------------------------------
diff --git a/plugins/experimental/Makefile.am b/plugins/experimental/Makefile.am
index d284623..bb97af1 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 \

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/fdfdc624/plugins/experimental/buffer_upload/Makefile.am
----------------------------------------------------------------------
diff --git a/plugins/experimental/buffer_upload/Makefile.am b/plugins/experimental/buffer_upload/Makefile.am
new file mode 100644
index 0000000..d21c09e
--- /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)

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/fdfdc624/plugins/experimental/buffer_upload/buffer_upload.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/buffer_upload/buffer_upload.cc b/plugins/experimental/buffer_upload/buffer_upload.cc
index 847c519..373818c 100644
--- a/plugins/experimental/buffer_upload/buffer_upload.cc
+++ b/plugins/experimental/buffer_upload/buffer_upload.cc
@@ -40,6 +40,7 @@
 #include <dirent.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <inttypes.h>
 
 #define true 1
 #define false 0
@@ -64,7 +65,6 @@
 #define VALID_PTR(X) (X != NULL)
 #define NOT_VALID_PTR(X) (X == NULL)
 
-
 struct upload_config_t
 {
   bool use_disk_buffer;
@@ -181,7 +181,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;
@@ -675,7 +675,7 @@ convert_url_func(TSMBuffer req_bufp, TSMLoc req_loc)
 }
 
 static int
-attach_pvc_plugin(TSCont contp, TSEvent event, void *edata)
+attach_pvc_plugin(TSCont /* contp ATS_UNUSED */, TSEvent event, void *edata)
 {
   TSHttpTxn txnp = (TSHttpTxn) edata;
   TSMutex mutex;
@@ -690,30 +690,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<size_t>(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 +738,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 +753,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 +763,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 +791,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 +807,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 +888,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 %" PRId64 " is larger than memory buffer size %" PRId64 ",
bypass upload proxy feature for this request.",
               my_state->req_size, uconfig->mem_buffer_size);
 
       pvc_cleanup(new_cont, my_state);
@@ -1193,6 +1206,7 @@ read_upload_config(const char *file_name)
     // default value
     uconfig->thread_num = 4;
   }
+
   return true;
 }
 
@@ -1249,3 +1263,4 @@ TSPluginInit(int argc, const char *argv[])
   contp = TSContCreate(attach_pvc_plugin, NULL);
   TSHttpHookAdd(TS_HTTP_READ_REQUEST_PRE_REMAP_HOOK, contp);
 }
+


Mime
View raw message