TS-2336 First attempt at moving the Prefetch APIs into some usable state

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

Branch: refs/heads/5.0.x
Commit: 4da6c48344c554669e8a0ccefe2efe42fe88a321
Parents: a151cfc
Author: Leif Hedstrom <zw...@apache.org>
Authored: Fri Jan 3 16:09:16 2014 -0700
Committer: Leif Hedstrom <zw...@apache.org>
Committed: Fri Jan 10 14:47:47 2014 -0700

----------------------------------------------------------------------
 example/prefetch/prefetch-plugin-eg1.c |  50 +++++-----
 example/prefetch/test-hns-plugin.c     |  29 +++---
 proxy/Prefetch.cc                      |  45 ++++-----
 proxy/Prefetch.h                       |  21 ++---
 proxy/api/ts/InkAPIHughes.h            | 138 ----------------------------
 proxy/api/ts/Makefile.am               |   1 -
 proxy/api/ts/experimental.h            | 136 +++++++++++++++++++++++++--
 7 files changed, 194 insertions(+), 226 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4da6c483/example/prefetch/prefetch-plugin-eg1.c
----------------------------------------------------------------------
diff --git a/example/prefetch/prefetch-plugin-eg1.c 
b/example/prefetch/prefetch-plugin-eg1.c
index 47d8740..72013dc 100644
--- a/example/prefetch/prefetch-plugin-eg1.c
+++ b/example/prefetch/prefetch-plugin-eg1.c
@@ -32,31 +32,8 @@
 #include <ts/ts.h>
 #include <ts/experimental.h>
 
-/* We will register the following two hooks */
-
-int my_preparse_hook(int hook, TSPrefetchInfo * info);
-int my_embedded_url_hook(int hook, TSPrefetchInfo * info);
-
-void
-TSPluginInit(int argc, const char *argv[])
-{
-  TSPluginRegistrationInfo info;
-
-  info.plugin_name = "prefetch_plugin_eg1";
-  info.vendor_name = "MyCompany";
-  info.support_email = "ts-api-supp...@mycompany.com";
-
-  if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) {
-    TSError("Plugin registration failed.\n");
-  }
-
-  /* register our hooks */
-  TSPrefetchHookSet(TS_PREFETCH_PRE_PARSE_HOOK, &my_preparse_hook);
-  TSPrefetchHookSet(TS_PREFETCH_EMBEDDED_URL_HOOK, &my_embedded_url_hook);
-}
-
-int
-my_preparse_hook(int hook, TSPrefetchInfo * info)
+TSPrefetchReturnCode
+my_preparse_hook(TSPrefetchHookID hook, TSPrefetchInfo * info)
 {
   unsigned char *ip = (unsigned char *) &info->client_ip;
 
@@ -67,8 +44,8 @@ my_preparse_hook(int hook, TSPrefetchInfo * info)
   return TS_PREFETCH_CONTINUE;
 }
 
-int
-my_embedded_url_hook(int hook, TSPrefetchInfo * info)
+TSPrefetchReturnCode
+my_embedded_url_hook(TSPrefetchHookID hook, TSPrefetchInfo * info)
 {
 
   unsigned char *ip = (unsigned char *) &info->client_ip;
@@ -88,3 +65,22 @@ my_embedded_url_hook(int hook, TSPrefetchInfo * info)
 
   return TS_PREFETCH_CONTINUE;
 }
+
+
+void
+TSPluginInit(int argc, const char *argv[])
+{
+  TSPluginRegistrationInfo info;
+
+  info.plugin_name = "prefetch_plugin_eg1";
+  info.vendor_name = "MyCompany";
+  info.support_email = "ts-api-supp...@mycompany.com";
+
+  if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) {
+    TSError("Plugin registration failed.\n");
+  }
+
+  /* register our hooks */
+  TSPrefetchHookSet(TS_PREFETCH_PRE_PARSE_HOOK, &my_preparse_hook);
+  TSPrefetchHookSet(TS_PREFETCH_EMBEDDED_URL_HOOK, &my_embedded_url_hook);
+}

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4da6c483/example/prefetch/test-hns-plugin.c
----------------------------------------------------------------------
diff --git a/example/prefetch/test-hns-plugin.c 
b/example/prefetch/test-hns-plugin.c
index fa5b01e..e1da4c9 100644
--- a/example/prefetch/test-hns-plugin.c
+++ b/example/prefetch/test-hns-plugin.c
@@ -58,6 +58,7 @@ correctness of the parse/prefetch module. It has the 
following options:
 #include <stdio.h>
 #include <string.h>
 #include <fcntl.h>
+#include <getopt.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <ts/ts.h>
@@ -75,30 +76,25 @@ static int embedded_object = 0;
 
 static TSMutex file_write_mutex;
 
-int pre_parse_hook(int hook, TSPrefetchInfo * info);
-int embedded_url_hook(int hook, TSPrefetchInfo * info);
-int embedded_object_hook(int hook, TSPrefetchInfo * info);
 
-
-int
-embedded_object_hook(int hook, TSPrefetchInfo * info)
+TSPrefetchReturnCode
+embedded_object_hook(TSPrefetchHookID hook, TSPrefetchInfo * info)
 {
-  int total_avail;
-
   TSIOBufferBlock block;
   const char *block_start;
-  int block_avail;
+  int64_t block_avail, total_avail;
 
   TSMutexLock(file_write_mutex);
 
   printf("(%s) >>> TS_PREFETCH_EMBEDDED_OBJECT_HOOK (%d)\n", TAG, hook);
 
-  printf("(%s) \tobject size for: %s is %d\n",
-         TAG, info->embedded_url, 
TSIOBufferReaderAvail(info->object_buf_reader));
+  printf("(%s) \tobject size for: %s is %lld\n",
+         TAG, info->embedded_url, (long 
long)TSIOBufferReaderAvail(info->object_buf_reader));
 
   /* Get the embedded objects here */
   total_avail = TSIOBufferReaderAvail(info->object_buf_reader);
 
+  printf("(%s) >>> TSIOBufferReaderAvail returns %lld\n", TAG, (long 
long)total_avail);
 
   block = TSIOBufferReaderStart(info->object_buf_reader);
   while (block) {
@@ -123,8 +119,8 @@ embedded_object_hook(int hook, TSPrefetchInfo * info)
   return 0;
 }
 
-int
-embedded_url_hook(int hook, TSPrefetchInfo * info)
+TSPrefetchReturnCode
+embedded_url_hook(TSPrefetchHookID hook, TSPrefetchInfo* info)
 {
 
   unsigned char *ip = (unsigned char *) &info->client_ip;
@@ -159,8 +155,8 @@ embedded_url_hook(int hook, TSPrefetchInfo * info)
 }
 
 
-int
-pre_parse_hook(int hook, TSPrefetchInfo * info)
+TSPrefetchReturnCode
+pre_parse_hook(TSPrefetchHookID hook, TSPrefetchInfo* info)
 {
   unsigned char *ip = (unsigned char *) &info->client_ip;
 
@@ -187,7 +183,6 @@ TSPluginInit(int argc, const char *argv[])
 {
   int c, arg;
   extern char *optarg;
-  extern int optind, opterr, optopt;
   TSPluginRegistrationInfo plugin_info;
   char file_name[512] = { 0 };
   plugin_info.plugin_name = "test-prefetch";
@@ -237,7 +232,7 @@ TSPluginInit(int argc, const char *argv[])
   if (embedded_object) {
     filep1 = TSfopen(file_name, "w");
     if (!filep1) {
-      TSError("Cannot open file %d for writing\n", file_name);
+      TSError("Cannot open file %s for writing\n", file_name);
       return;
     }
     TSfwrite(filep1, "", 1);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4da6c483/proxy/Prefetch.cc
----------------------------------------------------------------------
diff --git a/proxy/Prefetch.cc b/proxy/Prefetch.cc
index 182e4c3..c5b332d 100644
--- a/proxy/Prefetch.cc
+++ b/proxy/Prefetch.cc
@@ -78,8 +78,8 @@ KeepAliveConnTable *g_conn_table;
 static int prefetch_udp_fd = 0;
 static int32_t udp_seq_no;
 
-PrefetchBlastData const UDP_BLAST_DATA = { UDP_BLAST };
-PrefetchBlastData const TCP_BLAST_DATA = { TCP_BLAST };
+TSPrefetchBlastData const UDP_BLAST_DATA = { TS_PREFETCH_UDP_BLAST };
+TSPrefetchBlastData const TCP_BLAST_DATA = { TS_PREFETCH_TCP_BLAST };
 
 #define PrefetchEstablishStaticConfigStringAlloc(_ix,_n) \
   REC_EstablishStaticConfigStringAlloc(_ix,_n); \
@@ -725,7 +725,7 @@ check_n_attach_prefetch_transform(HttpSM *sm, HTTPHdr 
*resp, bool from_cache)
     info.response_buf = reinterpret_cast<TSMBuffer>(resp);
     info.response_loc = reinterpret_cast<TSMLoc>(resp->m_http);
 
-    info.client_ip = client_ip;
+    ats_ip_copy(ats_ip_sa_cast(&info.client_ip), &client_ip);
     info.embedded_url = 0;
     info.present_in_cache = from_cache;
     ink_zero(info.url_blast);
@@ -966,13 +966,13 @@ PrefetchUrlBlaster::udpUrlBlaster(int event, void *data)
       MIOBuffer *buf = new_MIOBuffer();
       IOBufferReader *reader = buf->alloc_reader();
 
-      int udp_hdr_len = (TCP_BLAST == blast.type) ? 0 : PRELOAD_UDP_HEADER_LEN;
+      int udp_hdr_len = (TS_PREFETCH_TCP_BLAST == blast.type) ? 0 : 
PRELOAD_UDP_HEADER_LEN;
 
       buf->fill(udp_hdr_len + PRELOAD_HEADER_LEN);
 
       writeBuffer(buf);
 
-      if (TCP_BLAST == blast.type) {
+      if (TS_PREFETCH_TCP_BLAST == blast.type) {
         setup_object_header(reader->start(), reader->read_avail(), true);
         g_conn_table->append(url_head->child_ip, buf, reader);
         free();
@@ -1726,7 +1726,7 @@ PrefetchBlaster::blastObject(int event, void *data)
       break;
     }
 
-    if (data_blast.type == TCP_BLAST) {
+    if (data_blast.type == TS_PREFETCH_TCP_BLAST) {
       g_conn_table->append(url_ent->child_ip, buf, reader);
       buf = 0;
       free();
@@ -1795,7 +1795,7 @@ PrefetchBlaster::invokeBlaster()
   int ret = (cache_http_info && !prefetch_config->push_cached_objects)
     ? TS_PREFETCH_DISCONTINUE : TS_PREFETCH_CONTINUE;
 
-  PrefetchBlastData url_blast = prefetch_config->default_url_blast;
+  TSPrefetchBlastData url_blast = prefetch_config->default_url_blast;
   data_blast = prefetch_config->default_data_blast;
 
   if (prefetch_config->embedded_url_hook) {
@@ -1811,7 +1811,7 @@ PrefetchBlaster::invokeBlaster()
     info.object_buf_reader = 0;
     info.object_buf_status = TS_PREFETCH_OBJ_BUF_NOT_NEEDED;
 
-    info.client_ip = url_ent->child_ip;
+    ats_ip_copy(ats_ip_sa_cast(&info.client_ip), &url_ent->child_ip);
     info.embedded_url = url_ent->url;
     info.present_in_cache = (cache_http_info != NULL);
     info.url_blast = url_blast;
@@ -1828,13 +1828,13 @@ PrefetchBlaster::invokeBlaster()
 
   if (ret == TS_PREFETCH_CONTINUE) {
 
-    if (MULTICAST_BLAST == url_blast.type)
-      ats_ip_copy(&url_ent->url_multicast_ip.sa, &url_blast.ip.sa);
-    if (MULTICAST_BLAST == data_blast.type)
-      ats_ip_copy(&url_ent->data_multicast_ip.sa, &data_blast.ip.sa);
+    if (TS_PREFETCH_MULTICAST_BLAST == url_blast.type)
+      ats_ip_copy(&url_ent->url_multicast_ip, ats_ip_sa_cast(&url_blast.ip));
+    if (TS_PREFETCH_MULTICAST_BLAST == data_blast.type)
+      ats_ip_copy(&url_ent->data_multicast_ip, ats_ip_sa_cast(&data_blast.ip));
 
     if (url_ent->object_buf_status != TS_PREFETCH_OBJ_BUF_NEEDED) {
-      if (url_blast.type == TCP_BLAST)
+      if (url_blast.type == TS_PREFETCH_TCP_BLAST)
         url_list = transform->tcp_url_list;
       else
         url_list = transform->udp_url_list;
@@ -1876,22 +1876,22 @@ PrefetchBlaster::initCacheLookupConfig()
 }
 
 static int
-config_read_proto(PrefetchBlastData &blast, const char *str)
+config_read_proto(TSPrefetchBlastData &blast, const char *str)
 {
   if (strncasecmp(str, "udp", 3) == 0)
-    blast.type = UDP_BLAST;
+    blast.type = TS_PREFETCH_UDP_BLAST;
   else if (strncasecmp(str, "tcp", 3) == 0)
-    blast.type = TCP_BLAST;
+    blast.type = TS_PREFETCH_TCP_BLAST;
   else {                        // this is a multicast address:
     if (strncasecmp("multicast:", str, 10) == 0) {
-      if (0 != ats_ip_pton(str, &blast.ip.sa)) {
+      if (0 != ats_ip_pton(str, ats_ip_sa_cast(&blast.ip))) {
         Error("PrefetchProcessor: Address specified for multicast does not 
seem to "
               "be of the form multicast:ip_addr (eg: multicast:224.0.0.1)");
         return 1;
       } else {
         ip_text_buffer ipb;
-        blast.type = MULTICAST_BLAST;
-        Debug("Prefetch", "Setting multicast address: %s\n", 
ats_ip_ntop(&blast.ip.sa, ipb, sizeof(ipb)));
+        blast.type = TS_PREFETCH_MULTICAST_BLAST;
+        Debug("Prefetch", "Setting multicast address: %s\n", 
ats_ip_ntop(ats_ip_sa_cast(&blast.ip), ipb, sizeof(ipb)));
       }
     } else {
       Error("PrefetchProcessor: The protocol for Prefetch should of the form: 
" "tcp or udp or multicast:ip_address");
@@ -2253,13 +2253,6 @@ KeepAliveLockHandler::handleEvent(int event, void * /* 
data ATS_UNUSED */)
 
 /* API */
 int
-TSPrefetchStart()
-{
-  printf("TSPrefetchStart() is called\n");
-  return 0;
-}
-
-int
 TSPrefetchHookSet(int hook_no, TSPrefetchHook hook)
 {
   switch (hook_no) {

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4da6c483/proxy/Prefetch.h
----------------------------------------------------------------------
diff --git a/proxy/Prefetch.h b/proxy/Prefetch.h
index 34289fa..9d60141 100644
--- a/proxy/Prefetch.h
+++ b/proxy/Prefetch.h
@@ -31,7 +31,6 @@
 
 #include "Update.h"
 #include "api/ts/experimental.h"
-#include "api/ts/InkAPIHughes.h"
 
 class BlasterUrlList;
 class PrefetchUrlBlaster;
@@ -51,8 +50,8 @@ struct PrefetchConfiguration
   int url_buffer_size;
   int url_buffer_timeout;
 
-  PrefetchBlastData default_url_blast;
-  PrefetchBlastData default_data_blast;
+  TSPrefetchBlastData default_url_blast;
+  TSPrefetchBlastData default_data_blast;
 
   int keepalive_timeout;
   int push_cached_objects;
@@ -189,8 +188,8 @@ public:
   bool no_dot_in_host;
 };
 
-extern PrefetchBlastData const UDP_BLAST_DATA;
-extern PrefetchBlastData const TCP_BLAST_DATA;
+extern TSPrefetchBlastData const UDP_BLAST_DATA;
+extern TSPrefetchBlastData const TCP_BLAST_DATA;
 
 //blaster
 class BlasterUrlList:public Continuation
@@ -199,7 +198,7 @@ class BlasterUrlList:public Continuation
   int timeout;                  //in milliseconds
   Action *action;
   int mtu;
-  PrefetchBlastData blast;
+  TSPrefetchBlastData blast;
 
   PrefetchUrlEntry *list_head;
   int cur_len;
@@ -209,7 +208,7 @@ public:
     : Continuation(), timeout(0), action(0), mtu(0), list_head(0), cur_len(0)
   {  }
 
-  void init(PrefetchBlastData const& bdata = UDP_BLAST_DATA, int tout = 0, int 
xmtu = INT_MAX) {
+  void init(TSPrefetchBlastData const& bdata = UDP_BLAST_DATA, int tout = 0, 
int xmtu = INT_MAX) {
     SET_HANDLER((int (BlasterUrlList::*)(int, void 
*))(&BlasterUrlList::handleEvent));
     mutex = new_ProxyMutex();
     blast = bdata;
@@ -243,12 +242,12 @@ public:
     ink_zero(blast);
   }
 
-  void init(PrefetchUrlEntry * list_head, PrefetchBlastData const& u_bd = 
UDP_BLAST_DATA);
+  void init(PrefetchUrlEntry * list_head, TSPrefetchBlastData const& u_bd = 
UDP_BLAST_DATA);
 
   void free();
 
   PrefetchUrlEntry *url_head;
-  PrefetchBlastData blast;
+  TSPrefetchBlastData blast;
 
   Action *action;
 
@@ -261,7 +260,7 @@ public:
 extern ClassAllocator<PrefetchUrlBlaster> prefetchUrlBlasterAllocator;
 
 void
-PrefetchUrlBlaster::init(PrefetchUrlEntry * list_head, PrefetchBlastData 
const& u_bd)
+PrefetchUrlBlaster::init(PrefetchUrlEntry * list_head, TSPrefetchBlastData 
const& u_bd)
 {
   /* More clean up necessary... we should not need this class
      XXXXXXXXX */
@@ -326,7 +325,7 @@ public:
 
   VConnection *serverVC;
 
-  PrefetchBlastData data_blast;
+  TSPrefetchBlastData data_blast;
 
   CacheLookupHttpConfig cache_lookup_config;
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4da6c483/proxy/api/ts/InkAPIHughes.h
----------------------------------------------------------------------
diff --git a/proxy/api/ts/InkAPIHughes.h b/proxy/api/ts/InkAPIHughes.h
deleted file mode 100644
index 32bf883..0000000
--- a/proxy/api/ts/InkAPIHughes.h
+++ /dev/null
@@ -1,138 +0,0 @@
-/** @file
-
-  A brief file description
-
-  @section license License
-
-  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.
- */
-
-/*
-  This file is created for Prefetch API and is used only by Hughes
-*/
-
-/// Type of connection.
-typedef enum
-{
-  ILL_BLAST = 0,
-  UDP_BLAST,
-  TCP_BLAST,
-  MULTICAST_BLAST
-} PrefetchBlastType;
-
-typedef struct {
-  PrefetchBlastType type;
-  IpEndpoint ip;
-} PrefetchBlastData;
-
-typedef struct
-{
-
-  /*request header */
-  TSMBuffer request_buf;
-  TSMLoc request_loc;
-
-  /*response header */
-  TSMBuffer response_buf;
-  TSMLoc response_loc;
-
-  /*child ip addr in network order */
-  IpEndpoint client_ip;
-
-  /*the embedded url parsed by the parser */
-  const char *embedded_url;
-
-  /* flag which says if a perticular embedded url is present in the cache */
-  int present_in_cache;
-
-  /* Reader for the buffer which contains the prefetched object */
-  TSIOBuffer object_buf;
-  TSIOBufferReader object_buf_reader;
-
-  /* This specifies if we need to invoke the OBJECT_HOOK and whether we
-     need to send the buffer to child as well
-     This should set inside EMBEDDED_URL_HOOK by the user
-   */
-  int object_buf_status;
-
-  /** Method of sending data to child.
-
-      If set to @c MULTICAST_BLAST then the corresponding address
-      value must be set to a multicast address to use.
-   */
-  PrefetchBlastData url_blast;
-  PrefetchBlastData url_response_blast;
-
-} TSPrefetchInfo;
-
-typedef int (*TSPrefetchHook) (int hook, TSPrefetchInfo * prefetch_info);
-
-enum
-{                               /* return type for TSPrefetchHook */
-  TS_PREFETCH_CONTINUE,
-  TS_PREFETCH_DISCONTINUE
-};
-
-enum
-{
-  TS_PREFETCH_OBJ_BUF_NOT_NEEDED = 0,
-  TS_PREFETCH_OBJ_BUF_NEEDED,  /* The user wants the buffer but does not
-                                   want it to be transmitted to the child */
-  TS_PREFETCH_OBJ_BUF_NEEDED_N_TRANSMITTED     /* The object should
-                                                   be transmitted as well */
-};
-
-enum
-{                               /* prefetch hooks */
-  TS_PREFETCH_PRE_PARSE_HOOK,
-  /* This hook is invoked just before we begin to parse a document
-     request and response headers are available.
-     Return value: TS_PREFETCH_CONTINUE  :continue parsing
-     TS_PREFETCH_DISCONTIUE: don't bother parser
-   */
-
-  TS_PREFETCH_EMBEDDED_URL_HOOK,
-  /* This hook is invoked when a URL is extracted.
-     url_proto and url_response_proto contain the default protocols used
-     for sending the url and actual url object respectively to the child.
-     The hook can change thes to one of the 3 methods mentioned above.
-     Return value: TS_PREFETCH_CONTINUE  : prefetch this url.
-     TS_PREFETCH_DISCONTIUE: don't bother prefetching this
-     url
-   */
-
-  TS_PREFETCH_EMBEDDED_OBJECT_HOOK
-    /* This hook is invoked when the user wants to have access to the buffer
-       of the embedded object we prefetched. We pass in the buffer reader.
-       The reader contains the data in the format specified in the Prefetch
-       document (with 12 byte header etc).
-       It is the users responsibility to free the reader.
-       The only valid field in the PrefetchInfo structure object_buf_reader.
-       embedded_url, object_buf, object_buf_reader, and object_buf_status are
-       set in TSPrefetchInfo passed as arguments
-     */
-    /* more hooks */
-};
-
-tsapi int TSPrefetchStart();
-/* This starts the Prefetch engine in Traffic Server
-   Return value 0 indicates success.*/
-
-tsapi int TSPrefetchHookSet(int hook_no, TSPrefetchHook hook_fn);
-/* Registers a hook for the given hook_no.
-   A hook is already present, it is replace by hook_fn
-   return value 0 indicates success */

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4da6c483/proxy/api/ts/Makefile.am
----------------------------------------------------------------------
diff --git a/proxy/api/ts/Makefile.am b/proxy/api/ts/Makefile.am
index e22dd42..16c76d3 100644
--- a/proxy/api/ts/Makefile.am
+++ b/proxy/api/ts/Makefile.am
@@ -24,5 +24,4 @@ include_HEADERS = \
   experimental.h
 
 noinst_HEADERS = \
-  InkAPIHughes.h \
   InkAPIPrivateIOCore.h

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4da6c483/proxy/api/ts/experimental.h
----------------------------------------------------------------------
diff --git a/proxy/api/ts/experimental.h b/proxy/api/ts/experimental.h
index e8d10f7..9fefb19 100644
--- a/proxy/api/ts/experimental.h
+++ b/proxy/api/ts/experimental.h
@@ -37,8 +37,8 @@ extern "C"
 {
 #endif                          /* __cplusplus */
 
-  // Forward declaration of in_addr, any user of these APIs should probably 
-  // include net/netinet.h or whatever is appropriate on the platform.
+  /* Forward declaration of in_addr, any user of these APIs should probably 
+     include net/netinet.h or whatever is appropriate on the platform. */
   struct in_addr;
 
   /* Cache APIs that are not yet fully supported and/or frozen nor complete. */
@@ -122,7 +122,7 @@ extern "C"
 #define TS_HRTIME_USECOND  (1000*TS_HRTIME_NSECOND)
 #define TS_HRTIME_NSECOND  (1LL)
 
-#define TS_HRTIME_APPROX_SECONDS(_x) ((_x)>>30)    // off by 7.3%
+#define TS_HRTIME_APPROX_SECONDS(_x) ((_x)>>30)    /*  off by 7.3% */
 #define TS_HRTIME_APPROX_FACTOR      
(((float)(1<<30))/(((float)HRTIME_SECOND)))
 
   /*
@@ -187,11 +187,11 @@ extern "C"
   tsapi TSReturnCode TSHttpTxnShutDown(TSHttpTxn txnp, TSEvent event);
   tsapi TSReturnCode TSHttpTxnCloseAfterResponse(TSHttpTxn txnp, int 
should_close);
 
-  // TS-2195: TSHttpTxnCacheLookupSkip() is deprecated, because 
TSHttpTxnConfigIntSet(txn, TS_CONFIG_HTTP_CACHE_HTTP, 0)
-  // does the same thing, but better. TSHttpTxnCacheLookupSkip will be removed 
in TrafficServer 5.0.
+  /* TS-2195: TSHttpTxnCacheLookupSkip() is deprecated, because 
TSHttpTxnConfigIntSet(txn, TS_CONFIG_HTTP_CACHE_HTTP, 0)
+     does the same thing, but better. TSHttpTxnCacheLookupSkip will be removed 
in TrafficServer 5.0. */
   tsapi TS_DEPRECATED TSReturnCode TSHttpTxnCacheLookupSkip(TSHttpTxn txnp);
 
-  // TS-1996: These API swill be removed after v3.4.0 is cut. Do not use them!
+  /* TS-1996: These API swill be removed after v3.4.0 is cut. Do not use them! 
*/
   tsapi TSReturnCode TSHttpTxnNewCacheLookupDo(TSHttpTxn txnp, TSMBuffer bufp, 
TSMLoc url_loc);
   tsapi TSReturnCode TSHttpTxnSecondUrlTryLock(TSHttpTxn txnp);
 
@@ -480,6 +480,130 @@ extern "C"
    
****************************************************************************/
   tsapi int TSSendClusterRPC(TSNodeHandle_t *nh, TSClusterRPCMsg_t *msg);
 
+
+
+  /*
+    This is for the prefetch APIs, this really has to be cleaned out. This is
+    some pretty seriously broken stuff, and we should decide whether it should
+    die and be redone properly. A few of the issues include:
+
+       * The hooks are not normal ATS continuations, just plain callbacks.
+       * The hooks are therefore not registered the normal way either...
+       * And thusly, there can only be one callback for each of the three
+         Prefetch "hooks".
+       * The example plugins don't compile, there are old / missing pieces.
+  */
+
+  typedef enum
+  {
+    TS_PREFETCH_UDP_BLAST = 0,
+    TS_PREFETCH_TCP_BLAST,
+    TS_PREFETCH_MULTICAST_BLAST
+  } TSPrefetchBlastType;
+
+  typedef struct
+  {
+    TSPrefetchBlastType type;
+    struct sockaddr_storage ip;
+  } TSPrefetchBlastData;
+
+  typedef enum
+  {
+    TS_PREFETCH_OBJ_BUF_NOT_NEEDED = 0,
+    TS_PREFETCH_OBJ_BUF_NEEDED,  /* The user wants the buffer but does not
+                                    want it to be transmitted to the child */
+    TS_PREFETCH_OBJ_BUF_NEEDED_N_TRANSMITTED     /* The object should
+                                                    be transmitted as well */
+  } TSPrefetchStatus;
+
+  /* return type for TSPrefetchHook */
+  typedef enum
+    {
+      TS_PREFETCH_CONTINUE,
+      TS_PREFETCH_DISCONTINUE
+    } TSPrefetchReturnCode;
+
+
+  /* prefetch hooks, which are *not* normal hooks (no continuations) */
+  typedef enum
+  {
+    TS_PREFETCH_PRE_PARSE_HOOK,
+    /* This hook is invoked just before we begin to parse a document
+       request and response headers are available.
+       Return value: TS_PREFETCH_CONTINUE  :continue parsing
+       TS_PREFETCH_DISCONTIUE: don't bother parser
+    */
+
+    TS_PREFETCH_EMBEDDED_URL_HOOK,
+    /* This hook is invoked when a URL is extracted.
+       url_proto and url_response_proto contain the default protocols used
+       for sending the url and actual url object respectively to the child.
+       The hook can change thes to one of the 3 methods mentioned above.
+       Return value: TS_PREFETCH_CONTINUE  : prefetch this url.
+       TS_PREFETCH_DISCONTIUE: don't bother prefetching this
+       url
+    */
+
+    TS_PREFETCH_EMBEDDED_OBJECT_HOOK
+    /* This hook is invoked when the user wants to have access to the buffer
+       of the embedded object we prefetched. We pass in the buffer reader.
+       The reader contains the data in the format specified in the Prefetch
+       document (with 12 byte header etc).
+       It is the users responsibility to free the reader.
+       The only valid field in the PrefetchInfo structure object_buf_reader.
+       embedded_url, object_buf, object_buf_reader, and object_buf_status are
+       set in TSPrefetchInfo passed as arguments
+    */
+  } TSPrefetchHookID;
+
+
+  /* This holds the main Prefetch information as used by the hook callbacks. */
+  typedef struct
+  {
+    /*request header */
+    TSMBuffer request_buf;
+    TSMLoc request_loc;
+
+    /*response header */
+    TSMBuffer response_buf;
+    TSMLoc response_loc;
+
+    /*child ip addr in network order */
+    struct sockaddr_storage client_ip;
+
+    /*the embedded url parsed by the parser */
+    const char *embedded_url;
+
+    /* flag which says if a perticular embedded url is present in the cache */
+    int present_in_cache;
+
+    /* Reader for the buffer which contains the prefetched object */
+    TSIOBuffer object_buf;
+    TSIOBufferReader object_buf_reader;
+
+    /* This specifies if we need to invoke the OBJECT_HOOK and whether we
+       need to send the buffer to child as well
+       This should set inside EMBEDDED_URL_HOOK by the user
+    */
+    int object_buf_status;
+
+    /** Method of sending data to child.
+
+        If set to @c MULTICAST_BLAST then the corresponding address
+        value must be set to a multicast address to use.
+    */
+    TSPrefetchBlastData url_blast;
+    TSPrefetchBlastData url_response_blast;
+
+  } TSPrefetchInfo;
+
+  typedef TSPrefetchReturnCode (*TSPrefetchHook) (TSPrefetchHookID hook, 
TSPrefetchInfo* prefetch_info);
+
+  /* Registers a hook for the given hook_no.
+     A hook is already present, it is replace by hook_fn
+     return value 0 indicates success */
+  tsapi int TSPrefetchHookSet(int hook_no, TSPrefetchHook hook_fn);
+
 #ifdef __cplusplus
 }
 #endif                          /* __cplusplus */

Reply via email to