Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
97fedd1
TS-3560: Make slow log overridable.
persiaAziz-zz May 26, 2015
924c721
removed comment, whitespace and edited lua enum
persiaAziz May 27, 2015
004ea19
removed comment, whitespace and edited lua enum
persiaAziz-zz May 26, 2015
9daf246
added enum field in apidefs.h.in
persiaAziz May 29, 2015
138ad9e
Merge branch 'ts-3560' of https://github.com/persiaAziz/trafficserver…
persiaAziz May 29, 2015
23dfc32
slow log added to the inktestAPI.cc
persiaAziz Jun 1, 2015
2cf58a6
3647
persiaAziz Jun 3, 2015
df2fa64
plugininit
persiaAziz Jun 3, 2015
3ce2376
3647: CPP API for overridqable config functions
persiaAziz Jun 4, 2015
90db5ed
adding pluginregister in globalhookplugin and helloworldplugin
persiaAziz Jun 4, 2015
9b31f73
TS-3560: Make slow log overridable.
persiaAziz-zz May 26, 2015
57f59a6
removed comment, whitespace and edited lua enum
persiaAziz May 27, 2015
bbbaf50
3647
persiaAziz Jun 3, 2015
61b88bb
plugininit
persiaAziz Jun 3, 2015
4529c4f
3647: CPP API for overridqable config functions
persiaAziz Jun 4, 2015
a3a6d60
adding pluginregister in globalhookplugin and helloworldplugin
persiaAziz Jun 4, 2015
1a9ef55
TS-3647: include TSRegisterPlugin in plugin.h
persiaAziz Jun 5, 2015
4e563f9
TSregisterplugin included in all the pluginit implementations of CPP-…
persiaAziz Jun 8, 2015
1931b5b
minor conflicts fixed
persiaAziz Jun 8, 2015
4cf7524
minor formatting problem fixed
persiaAziz Jun 8, 2015
2d7b704
minor formatting problem fixed
persiaAziz Jun 8, 2015
e2c8775
minor formatting problem fixed
persiaAziz Jun 8, 2015
1c7774a
TS 3467- format fixning
persiaAziz Jun 19, 2015
d084b75
TS-3647 : fixing whitespace
persiaAziz Jun 19, 2015
3cf4f8c
TS-3647: renamed TSRegisterPlugin to RegsiterGlobalPlugin
persiaAziz Jun 19, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added README.md
Empty file.
1 change: 1 addition & 0 deletions lib/atscppapi/examples/async_http_fetch/AsyncHttpFetch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ void
TSPluginInit(int argc ATSCPPAPI_UNUSED, const char *argv[] ATSCPPAPI_UNUSED)
{
TS_DEBUG(TAG, "Loaded async_http_fetch_example plugin");
RegisterGlobalPlugin("CPP_Example_AsyncHttpFetch", "apache", "users@trafficserver.apache.org");
GlobalPlugin *instance = new GlobalHookPlugin();

(void)instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class InterceptInstaller : public GlobalPlugin
void
TSPluginInit(int /* argc ATS_UNUSED */, const char * /* argv ATS_UNUSED */ [])
{
RegisterGlobalPlugin("CPP_Example_AsyncHttpFetchStreaming", "apache", "users@trafficserver.apache.org");
new InterceptInstaller();
}

Expand Down
1 change: 1 addition & 0 deletions lib/atscppapi/examples/async_timer/AsyncTimer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class TimerEventReceiver : public AsyncReceiver<AsyncTimer>
void
TSPluginInit(int argc ATSCPPAPI_UNUSED, const char *argv[] ATSCPPAPI_UNUSED)
{
RegisterGlobalPlugin("CPP_Example_AsyncTimer", "apache", "users@trafficserver.apache.org");
int period_in_ms = 1000;
TimerEventReceiver *timer1 = new TimerEventReceiver(AsyncTimer::TYPE_PERIODIC, period_in_ms);
TS_DEBUG(TAG, "Created periodic timer %p with initial period 0, regular period %d and max instances 0", timer1, period_in_ms);
Expand Down
1 change: 1 addition & 0 deletions lib/atscppapi/examples/boom/boom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ BoomGlobalPlugin::handleReadResponseHeaders(Transaction &transaction)
void
TSPluginInit(int argc, const char *argv[])
{
RegisterGlobalPlugin("CPP_Example_Boom", "apache", "users@trafficserver.apache.org");
boom_counter.init(BOOM_COUNTER);
BoomResponseRegistry *pregistry = new BoomResponseRegistry();

Expand Down
1 change: 1 addition & 0 deletions lib/atscppapi/examples/clientredirect/ClientRedirect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ class ClientRedirectGlobalPlugin : public GlobalPlugin
void
TSPluginInit(int argc ATSCPPAPI_UNUSED, const char *argv[] ATSCPPAPI_UNUSED)
{
RegisterGlobalPlugin("CPP_Example_ClientDirect", "apache", "users@trafficserver.apache.org");
new ClientRedirectGlobalPlugin();
}
1 change: 1 addition & 0 deletions lib/atscppapi/examples/clientrequest/ClientRequest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,6 @@ class GlobalHookPlugin : public GlobalPlugin
void
TSPluginInit(int argc ATSCPPAPI_UNUSED, const char *argv[] ATSCPPAPI_UNUSED)
{
RegisterGlobalPlugin("CPP_Example_ClientRequest", "apache", "users@trafficserver.apache.org");
new GlobalHookPlugin();
}
1 change: 1 addition & 0 deletions lib/atscppapi/examples/customresponse/CustomResponse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@ class ClientRedirectGlobalPlugin : public GlobalPlugin
void
TSPluginInit(int argc ATSCPPAPI_UNUSED, const char *argv[] ATSCPPAPI_UNUSED)
{
RegisterGlobalPlugin("CPP_Example_CustomResponse", "apache", "users@trafficserver.apache.org");
new ClientRedirectGlobalPlugin();
}
4 changes: 2 additions & 2 deletions lib/atscppapi/examples/globalhook/GlobalHookPlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
#include <iostream>
#include <atscppapi/GlobalPlugin.h>
#include <atscppapi/PluginInit.h>

using namespace atscppapi;

class GlobalHookPlugin : public GlobalPlugin
{
public:
Expand All @@ -38,5 +36,7 @@ class GlobalHookPlugin : public GlobalPlugin
void
TSPluginInit(int argc ATSCPPAPI_UNUSED, const char *argv[] ATSCPPAPI_UNUSED)
{
RegisterGlobalPlugin("CPP_Example_GlobalHookPplugin", "apache", "users@trafficserver.apache.org");
std::cout << "Hello from " << argv[0] << std::endl;
new GlobalHookPlugin();
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class GlobalHookPlugin : public GlobalPlugin
void
TSPluginInit(int argc ATSCPPAPI_UNUSED, const char *argv[] ATSCPPAPI_UNUSED)
{
RegisterGlobalPlugin("CPP_Example_GzipTransformation", "apache", "users@trafficserver.apache.org");
TS_DEBUG(TAG, "TSPluginInit");
new GlobalHookPlugin();
}
7 changes: 5 additions & 2 deletions lib/atscppapi/examples/helloworld/HelloWorldPlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@
#include <iostream>
#include <atscppapi/GlobalPlugin.h>
#include <atscppapi/PluginInit.h>

class HelloWorldPlugin : public atscppapi::GlobalPlugin
{
public:
HelloWorldPlugin() { std::cout << "Hello World!" << std::endl; }
HelloWorldPlugin() {
std::cout << "Hello World!" << std::endl;
}
};

void
TSPluginInit(int argc ATSCPPAPI_UNUSED, const char *argv[] ATSCPPAPI_UNUSED)
{

std::cout << "Hello from " << argv[0] << std::endl;
atscppapi::RegisterGlobalPlugin("CPP_Example_HelloWorld", "apache", "users@trafficserver.apache.org");
new HelloWorldPlugin();
}
1 change: 1 addition & 0 deletions lib/atscppapi/examples/intercept/intercept.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class InterceptInstaller : public GlobalPlugin
void
TSPluginInit(int /* argc ATS_UNUSED */, const char * /* argv ATS_UNUSED */ [])
{
RegisterGlobalPlugin("CPP_Example_Intercept", "apache", "users@trafficserver.apache.org");
new InterceptInstaller();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class NoInternalTransactionsGlobalPlugin : public GlobalPlugin, public AsyncRece
void
TSPluginInit(int argc ATSCPPAPI_UNUSED, const char *argv[] ATSCPPAPI_UNUSED)
{
RegisterGlobalPlugin("CPP_Example_InternalTransactionHandling", "apache", "users@trafficserver.apache.org");
TS_DEBUG(TAG, "Loaded async_http_fetch_example plugin");
new AllTransactionsGlobalPlugin();
new NoInternalTransactionsGlobalPlugin();
Expand Down
1 change: 1 addition & 0 deletions lib/atscppapi/examples/logger_example/LoggerExample.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class GlobalHookPlugin : public GlobalPlugin
void
TSPluginInit(int argc ATSCPPAPI_UNUSED, const char *argv[] ATSCPPAPI_UNUSED)
{
RegisterGlobalPlugin("CPP_Example_Logger", "apache", "users@trafficserver.apache.org");
// Create a new logger
// This will create a log file with the name logger_example.log (since we left off
// the extension it will automatically add .log)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,6 @@ class GlobalHookPlugin : public atscppapi::GlobalPlugin
void
TSPluginInit(int argc ATSCPPAPI_UNUSED, const char *argv[] ATSCPPAPI_UNUSED)
{
RegisterGlobalPlugin("CPP_Example_MultipleTransactionHook", "apache", "users@trafficserver.apache.org");
new GlobalHookPlugin();
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class GlobalHookPlugin : public GlobalPlugin
void
TSPluginInit(int argc ATSCPPAPI_UNUSED, const char *argv[] ATSCPPAPI_UNUSED)
{
RegisterGlobalPlugin("CPP_Example_NullTransformation", "apache", "users@trafficserver.apache.org");
TS_DEBUG(TAG, "TSPluginInit");
new GlobalHookPlugin();
}
1 change: 1 addition & 0 deletions lib/atscppapi/examples/post_buffer/PostBuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,6 @@ class GlobalHookPlugin : public GlobalPlugin
void
TSPluginInit(int argc ATSCPPAPI_UNUSED, const char *argv[] ATSCPPAPI_UNUSED)
{
RegisterGlobalPlugin("CPP_Example_PostBuffer", "apache", "users@trafficserver.apache.org");
new GlobalHookPlugin();
}
2 changes: 1 addition & 1 deletion lib/atscppapi/examples/remap_plugin/RemapPlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class MyRemapPlugin : public RemapPlugin
}
};

TsReturnCode
TSReturnCode
TSRemapNewInstance(int argc ATSCPPAPI_UNUSED, char *argv[] ATSCPPAPI_UNUSED, void **instance_handle, char *errbuf ATSCPPAPI_UNUSED,
int errbuf_size ATSCPPAPI_UNUSED)
{
Expand Down
1 change: 1 addition & 0 deletions lib/atscppapi/examples/serverresponse/ServerResponse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,6 @@ class ServerResponsePlugin : public GlobalPlugin
void
TSPluginInit(int argc ATSCPPAPI_UNUSED, const char *argv[] ATSCPPAPI_UNUSED)
{
RegisterGlobalPlugin("CPP_Example_ServerResponse", "apache", "users@trafficserver.apache.org");
new ServerResponsePlugin();
}
1 change: 1 addition & 0 deletions lib/atscppapi/examples/stat_example/StatExample.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class GlobalHookPlugin : public GlobalPlugin
void
TSPluginInit(int argc ATSCPPAPI_UNUSED, const char *argv[] ATSCPPAPI_UNUSED)
{
RegisterGlobalPlugin("CPP_Example_Stat", "apache", "users@trafficserver.apache.org");
TS_DEBUG(TAG, "Loaded stat_example plugin");

// Since this stat is not persistent it will be initialized to 0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class TimeoutExamplePlugin : public GlobalPlugin
void
TSPluginInit(int argc ATSCPPAPI_UNUSED, const char *argv[] ATSCPPAPI_UNUSED)
{
RegisterGlobalPlugin( "CPP_Example_Timeout", "apache", "users@trafficserver.apache.org");
TS_DEBUG(TAG, "TSPluginInit");
new TimeoutExamplePlugin();
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ class GlobalHookPlugin : public atscppapi::GlobalPlugin
void
TSPluginInit(int argc ATSCPPAPI_UNUSED, const char *argv[] ATSCPPAPI_UNUSED)
{
RegisterGlobalPlugin("CPP_Example_TransactionHook", "apache", "users@trafficserver.apache.org");
new GlobalHookPlugin();
}
11 changes: 10 additions & 1 deletion lib/atscppapi/src/Plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,18 @@
* @file Plugin.cc
*/
#include "atscppapi/Plugin.h"

#include <ts/ts.h>
const std::string atscppapi::HOOK_TYPE_STRINGS[] = {
std::string("HOOK_READ_REQUEST_HEADERS_PRE_REMAP"), std::string("HOOK_READ_REQUEST_HEADERS_POST_REMAP"),
std::string("HOOK_SEND_REQUEST_HEADERS"), std::string("HOOK_READ_RESPONSE_HEADERS"), std::string("HOOK_SEND_RESPONSE_HEADERS"),
std::string("HOOK_OS_DNS"), std::string("HOOK_READ_REQUEST_HEADERS"), std::string("HOOK_READ_CACHE_HEADERS"),
std::string("HOOK_CACHE_LOOKUP_COMPLETE"), std::string("HOOK_SELECT_ALT")};

void atscppapi::RegisterGlobalPlugin(std::string name, std::string vendor, std::string email)
{
TSPluginRegistrationInfo info;
info.plugin_name=const_cast<char*>(name.c_str());
info.vendor_name=const_cast<char*>(vendor.c_str());
info.support_email=const_cast<char*>(email.c_str());
TSPluginRegister(TS_SDK_VERSION_3_0, &info);
}
44 changes: 42 additions & 2 deletions lib/atscppapi/src/Transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@
#include <cstring>
#include <map>
#include <string>
#include <ts/ts.h>
#include <ink_memory.h>
#include "atscppapi/shared_ptr.h"
#include "logging_internal.h"
#include "utils_internal.h"
#include "atscppapi/noncopyable.h"

using std::map;
using std::string;
using namespace atscppapi;
Expand Down Expand Up @@ -98,6 +96,48 @@ Transaction::~Transaction()
delete state_;
}

bool Transaction::configIntSet(TSOverridableConfigKey conf, int value)
{
return (TS_SUCCESS==TSHttpTxnConfigIntSet(state_->txn_,conf,(TSMgmtInt)value));
}
bool Transaction::configIntGet(TSOverridableConfigKey conf, int *value)
{
return (TS_SUCCESS==TSHttpTxnConfigIntGet(state_->txn_, conf, (TSMgmtInt*)value));
}

bool Transaction::configFloatSet(TSOverridableConfigKey conf, float value)
{
return (TS_SUCCESS==TSHttpTxnConfigFloatSet(state_->txn_,conf,(TSMgmtFloat)value));
}

bool Transaction::configFloatGet(TSOverridableConfigKey conf, float *value)
{
return (TS_SUCCESS==TSHttpTxnConfigFloatGet(state_->txn_, conf, value));
}

bool Transaction::configStringSet(TSOverridableConfigKey conf, std::string const& value,int length)
{
return (TS_SUCCESS==TSHttpTxnConfigStringSet(state_->txn_,conf,(TSMgmtString)value.c_str(),length));
}

bool Transaction::configStringGet(TSOverridableConfigKey conf,std::string& value, int* length)
{
const char* svalue;
TSReturnCode res=TSHttpTxnConfigStringGet(state_->txn_, conf, &svalue,length);
if(res==TS_SUCCESS)
{
value.assign(svalue);
return true;
}
else
return false;
}

bool Transaction::configFind(std::string const& name, int length, TSOverridableConfigKey *conf, TSRecordDataType *type)
{
return (TS_SUCCESS==TSHttpTxnConfigFind(name.c_str(),length,conf,type));
}

void
Transaction::resume()
{
Expand Down
2 changes: 2 additions & 0 deletions lib/atscppapi/src/include/atscppapi/Plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <atscppapi/Transaction.h>
#include <atscppapi/noncopyable.h>


namespace atscppapi
{
/**
Expand Down Expand Up @@ -166,6 +167,7 @@ class Plugin : noncopyable

/**< Human readable strings for each HookType, you can access them as HOOK_TYPE_STRINGS[HOOK_OS_DNS] for example. */
extern const std::string HOOK_TYPE_STRINGS[];
void RegisterGlobalPlugin(std::string name, std::string vendor, std::string email);

} /* atscppapi */

Expand Down
11 changes: 2 additions & 9 deletions lib/atscppapi/src/include/atscppapi/PluginInit.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
#pragma once
#ifndef ATSCPPAPI_PLUGININIT_H_
#define ATSCPPAPI_PLUGININIT_H_

#include <../ts/apidefs.h>
#include <atscppapi/utils.h>

extern "C" {

/**
Expand All @@ -36,12 +35,6 @@ extern "C" {
* @param argv Array of pointers pointing to arguments
*/
void TSPluginInit(int argc, const char *argv[]);

enum TsReturnCode {
TS_ERROR = -1,
TS_SUCCESS = 0,
};

/**
* Invoked for remap plugins - listed in remap.config. The arguments provided as @pparam
* in the remap.config line are provided in this invocation.
Expand All @@ -52,7 +45,7 @@ enum TsReturnCode {
* @param errbuf Not used
* @param errbuf_size Not used
*/
TsReturnCode TSRemapNewInstance(int argc, char *argv[], void **instance_handle, char *errbuf, int errbuf_size);
TSReturnCode TSRemapNewInstance(int argc, char *argv[], void **instance_handle, char *errbuf, int errbuf_size);
}


Expand Down
10 changes: 9 additions & 1 deletion lib/atscppapi/src/include/atscppapi/Transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "atscppapi/shared_ptr.h"
#include "atscppapi/ClientRequest.h"
#include "atscppapi/Response.h"

#include <../ts/apidefs.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't do this. The pattern we've always followed with the ats c++ api is that it shouldn't require including any C header files. We've typically just duplicated enums so TSOverridableConfigKey should be an enum in Transaction.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. Let me think about that a bit. I have an idea on how to deal with this but I need to flesh it out.

namespace atscppapi
{
// forward declarations
Expand Down Expand Up @@ -321,6 +321,14 @@ class Transaction : noncopyable
*/
void redirectTo(std::string const &url);

bool configIntSet(TSOverridableConfigKey conf, int value);
bool configIntGet(TSOverridableConfigKey conf, int* value);
bool configFloatSet(TSOverridableConfigKey conf, float value);
bool configFloatGet(TSOverridableConfigKey conf, float* value);
bool configStringSet(TSOverridableConfigKey conf, std::string const& value,int length);
bool configStringGet(TSOverridableConfigKey conf,std::string& value, int* length);
bool configFind(std::string const& name, int length, TSOverridableConfigKey *conf, TSRecordDataType *type);

private:
TransactionState *state_; //!< The internal TransactionState object tied to the current Transaction
friend class TransactionPlugin; //!< TransactionPlugin is a friend so it can call addPlugin()
Expand Down