http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/Response.cc ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/Response.cc b/lib/atscppapi/src/Response.cc index 2ec042c..b60d4f1 100644 --- a/lib/atscppapi/src/Response.cc +++ b/lib/atscppapi/src/Response.cc @@ -26,89 +26,103 @@ using namespace atscppapi; using std::string; -namespace atscppapi { - +namespace atscppapi +{ /** * @private */ -struct ResponseState: noncopyable { +struct ResponseState : noncopyable { TSMBuffer hdr_buf_; TSMLoc hdr_loc_; Headers headers_; - ResponseState() : hdr_buf_(NULL), hdr_loc_(NULL) { } + ResponseState() : hdr_buf_(NULL), hdr_loc_(NULL) {} }; - } -Response::Response() { +Response::Response() +{ state_ = new ResponseState(); -// state_->headers_.setType(Headers::TYPE_RESPONSE); + // state_->headers_.setType(Headers::TYPE_RESPONSE); } -void Response::init(void *hdr_buf, void *hdr_loc) { +void +Response::init(void *hdr_buf, void *hdr_loc) +{ state_->hdr_buf_ = static_cast<TSMBuffer>(hdr_buf); state_->hdr_loc_ = static_cast<TSMLoc>(hdr_loc); state_->headers_.reset(state_->hdr_buf_, state_->hdr_loc_); LOG_DEBUG("Initializing response %p with hdr_buf=%p and hdr_loc=%p", this, state_->hdr_buf_, state_->hdr_loc_); } -HttpVersion Response::getVersion() const { +HttpVersion +Response::getVersion() const +{ HttpVersion ret_val = HTTP_VERSION_UNKNOWN; if (state_->hdr_buf_ && state_->hdr_loc_) { ret_val = utils::internal::getHttpVersion(state_->hdr_buf_, state_->hdr_loc_); - LOG_DEBUG("Initializing response version to %d [%s] with hdr_buf=%p and hdr_loc=%p", - ret_val, HTTP_VERSION_STRINGS[ret_val].c_str(), state_->hdr_buf_, state_->hdr_loc_); + LOG_DEBUG("Initializing response version to %d [%s] with hdr_buf=%p and hdr_loc=%p", ret_val, + HTTP_VERSION_STRINGS[ret_val].c_str(), state_->hdr_buf_, state_->hdr_loc_); } return ret_val; } -HttpStatus Response::getStatusCode() const { +HttpStatus +Response::getStatusCode() const +{ HttpStatus ret_val = HTTP_STATUS_UNKNOWN; if (state_->hdr_buf_ && state_->hdr_loc_) { ret_val = static_cast<HttpStatus>(TSHttpHdrStatusGet(state_->hdr_buf_, state_->hdr_loc_)); - LOG_DEBUG("Initializing response status code to %d with hdr_buf=%p and hdr_loc=%p", - ret_val, state_->hdr_buf_, state_->hdr_loc_); + LOG_DEBUG("Initializing response status code to %d with hdr_buf=%p and hdr_loc=%p", ret_val, state_->hdr_buf_, + state_->hdr_loc_); } return ret_val; } -void Response::setStatusCode(HttpStatus code) { +void +Response::setStatusCode(HttpStatus code) +{ if (state_->hdr_buf_ && state_->hdr_loc_) { TSHttpHdrStatusSet(state_->hdr_buf_, state_->hdr_loc_, static_cast<TSHttpStatus>(code)); - LOG_DEBUG("Changing response status code to %d with hdr_buf=%p and hdr_loc=%p", - code, state_->hdr_buf_, state_->hdr_loc_); + LOG_DEBUG("Changing response status code to %d with hdr_buf=%p and hdr_loc=%p", code, state_->hdr_buf_, state_->hdr_loc_); } } -string Response::getReasonPhrase() const { +string +Response::getReasonPhrase() const +{ string ret_str; if (state_->hdr_buf_ && state_->hdr_loc_) { int length; const char *str = TSHttpHdrReasonGet(state_->hdr_buf_, state_->hdr_loc_, &length); if (str && length) { ret_str.assign(str, length); - LOG_DEBUG("Initializing response reason phrase to '%s' with hdr_buf=%p and hdr_loc=%p", - ret_str.c_str(), state_->hdr_buf_, state_->hdr_loc_); + LOG_DEBUG("Initializing response reason phrase to '%s' with hdr_buf=%p and hdr_loc=%p", ret_str.c_str(), state_->hdr_buf_, + state_->hdr_loc_); } else { - LOG_ERROR("TSHttpHdrReasonGet returned null string or zero length. str=%p, length=%d, hdr_buf=%p, hdr_loc=%p", - str, length, state_->hdr_buf_, state_->hdr_loc_); + LOG_ERROR("TSHttpHdrReasonGet returned null string or zero length. str=%p, length=%d, hdr_buf=%p, hdr_loc=%p", str, length, + state_->hdr_buf_, state_->hdr_loc_); } } return ret_str; // if not initialized, we will just return an empty string } -void Response::setReasonPhrase(const string &phrase) { +void +Response::setReasonPhrase(const string &phrase) +{ if (state_->hdr_buf_ && state_->hdr_loc_) { TSHttpHdrReasonSet(state_->hdr_buf_, state_->hdr_loc_, phrase.c_str(), phrase.length()); - LOG_DEBUG("Changing response reason phrase to '%s' with hdr_buf=%p and hdr_loc=%p", - phrase.c_str(), state_->hdr_buf_, state_->hdr_loc_); + LOG_DEBUG("Changing response reason phrase to '%s' with hdr_buf=%p and hdr_loc=%p", phrase.c_str(), state_->hdr_buf_, + state_->hdr_loc_); } } -Headers &Response::getHeaders() const { - return state_->headers_; // if not initialized, we will just return an empty object +Headers & +Response::getHeaders() const +{ + return state_->headers_; // if not initialized, we will just return an empty object } -Response::~Response() { +Response::~Response() +{ delete state_; }
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/Stat.cc ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/Stat.cc b/lib/atscppapi/src/Stat.cc index b10082b..0885c84 100644 --- a/lib/atscppapi/src/Stat.cc +++ b/lib/atscppapi/src/Stat.cc @@ -28,19 +28,24 @@ using namespace atscppapi; using std::string; -Stat::Stat() : stat_id_(TS_ERROR) { -// ATS Guarantees that stat ids will always be > 0. So we can use stat_id_ > 0 to -// verify that this stat has been properly initialized. +Stat::Stat() : stat_id_(TS_ERROR) +{ + // ATS Guarantees that stat ids will always be > 0. So we can use stat_id_ > 0 to + // verify that this stat has been properly initialized. } -Stat::~Stat() { -// we really dont have any cleanup since ATS doesn't expose a method to destroy stats +Stat::~Stat() +{ + // we really dont have any cleanup since ATS doesn't expose a method to destroy stats } -bool Stat::init(string name, Stat::SyncType type, bool persistent) { +bool +Stat::init(string name, Stat::SyncType type, bool persistent) +{ // TS_RECORDDATATYPE_INT is the only type currently supported // so that's why this api doesn't expose other types, TSStatSync is equivalent to StatSyncType - stat_id_ = TSStatCreate(name.c_str(), TS_RECORDDATATYPE_INT, persistent ? TS_STAT_PERSISTENT : TS_STAT_NON_PERSISTENT, static_cast<TSStatSync>(type)); + stat_id_ = TSStatCreate(name.c_str(), TS_RECORDDATATYPE_INT, persistent ? TS_STAT_PERSISTENT : TS_STAT_NON_PERSISTENT, + static_cast<TSStatSync>(type)); if (stat_id_ != TS_ERROR) { LOG_DEBUG("Created new stat named '%s' with stat_id = %d", name.c_str(), stat_id_); } else { @@ -58,7 +63,9 @@ bool Stat::init(string name, Stat::SyncType type, bool persistent) { return true; } -void Stat::set(int64_t value) { +void +Stat::set(int64_t value) +{ if (stat_id_ == TS_ERROR) { return; } @@ -66,7 +73,9 @@ void Stat::set(int64_t value) { TSStatIntSet(stat_id_, value); } -int64_t Stat::get() const { +int64_t +Stat::get() const +{ if (stat_id_ == TS_ERROR) { return 0; } @@ -74,7 +83,9 @@ int64_t Stat::get() const { return TSStatIntGet(stat_id_); } -void Stat::increment(int64_t amount) { +void +Stat::increment(int64_t amount) +{ if (stat_id_ == TS_ERROR) { return; } @@ -82,15 +93,12 @@ void Stat::increment(int64_t amount) { TSStatIntIncrement(stat_id_, amount); } -void Stat::decrement(int64_t amount) { +void +Stat::decrement(int64_t amount) +{ if (stat_id_ == TS_ERROR) { return; } TSStatIntDecrement(stat_id_, amount); } - - - - - http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/Transaction.cc ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/Transaction.cc b/lib/atscppapi/src/Transaction.cc index b1ff159..823bee7 100644 --- a/lib/atscppapi/src/Transaction.cc +++ b/lib/atscppapi/src/Transaction.cc @@ -39,7 +39,7 @@ using namespace atscppapi; /** * @private */ -struct atscppapi::TransactionState: noncopyable { +struct atscppapi::TransactionState : noncopyable { TSHttpTxn txn_; std::list<TransactionPlugin *> plugins_; TSMBuffer client_request_hdr_buf_; @@ -58,28 +58,28 @@ struct atscppapi::TransactionState: noncopyable { TransactionState(TSHttpTxn txn, TSMBuffer client_request_hdr_buf, TSMLoc client_request_hdr_loc) : txn_(txn), client_request_hdr_buf_(client_request_hdr_buf), client_request_hdr_loc_(client_request_hdr_loc), - client_request_(txn, client_request_hdr_buf, client_request_hdr_loc), - server_request_hdr_buf_(NULL), server_request_hdr_loc_(NULL), - server_response_hdr_buf_(NULL), server_response_hdr_loc_(NULL), - client_response_hdr_buf_(NULL), client_response_hdr_loc_(NULL) - { }; + client_request_(txn, client_request_hdr_buf, client_request_hdr_loc), server_request_hdr_buf_(NULL), + server_request_hdr_loc_(NULL), server_response_hdr_buf_(NULL), server_response_hdr_loc_(NULL), client_response_hdr_buf_(NULL), + client_response_hdr_loc_(NULL){}; }; -Transaction::Transaction(void *raw_txn) { +Transaction::Transaction(void *raw_txn) +{ TSHttpTxn txn = static_cast<TSHttpTxn>(raw_txn); TSMBuffer hdr_buf; TSMLoc hdr_loc; - (void) TSHttpTxnClientReqGet(txn, &hdr_buf, &hdr_loc); + (void)TSHttpTxnClientReqGet(txn, &hdr_buf, &hdr_loc); if (!hdr_buf || !hdr_loc) { LOG_ERROR("TSHttpTxnClientReqGet tshttptxn=%p returned a null hdr_buf=%p or hdr_loc=%p.", txn, hdr_buf, hdr_loc); } state_ = new TransactionState(txn, hdr_buf, hdr_loc); - LOG_DEBUG("Transaction tshttptxn=%p constructing Transaction object %p, client req hdr_buf=%p, client req hdr_loc=%p", - txn, this, hdr_buf, hdr_loc); + LOG_DEBUG("Transaction tshttptxn=%p constructing Transaction object %p, client req hdr_buf=%p, client req hdr_loc=%p", txn, this, + hdr_buf, hdr_loc); } -Transaction::~Transaction() { +Transaction::~Transaction() +{ LOG_DEBUG("Transaction tshttptxn=%p destroying Transaction object %p", state_->txn_, this); static const TSMLoc NULL_PARENT_LOC = NULL; TSHandleMLocRelease(state_->client_request_hdr_buf_, NULL_PARENT_LOC, state_->client_request_hdr_loc_); @@ -98,43 +98,61 @@ Transaction::~Transaction() { delete state_; } -void Transaction::resume() { +void +Transaction::resume() +{ TSHttpTxnReenable(state_->txn_, static_cast<TSEvent>(TS_EVENT_HTTP_CONTINUE)); } -void Transaction::error() { +void +Transaction::error() +{ LOG_DEBUG("Transaction tshttptxn=%p reenabling to error state", state_->txn_); TSHttpTxnReenable(state_->txn_, static_cast<TSEvent>(TS_EVENT_HTTP_ERROR)); } -void Transaction::error(const std::string &page) { +void +Transaction::error(const std::string &page) +{ setErrorBody(page); error(); // finally, reenable with HTTP_ERROR } -void Transaction::setErrorBody(const std::string &page) { +void +Transaction::setErrorBody(const std::string &page) +{ LOG_DEBUG("Transaction tshttptxn=%p setting error body page: %s", state_->txn_, page.c_str()); TSHttpTxnErrorBodySet(state_->txn_, TSstrdup(page.c_str()), page.length(), NULL); // Default to text/html } -bool Transaction::isInternalRequest() const { +bool +Transaction::isInternalRequest() const +{ return TSHttpIsInternalRequest(state_->txn_) == TS_SUCCESS; } -void *Transaction::getAtsHandle() const { +void * +Transaction::getAtsHandle() const +{ return static_cast<void *>(state_->txn_); } -const std::list<atscppapi::TransactionPlugin *> &Transaction::getPlugins() const { +const std::list<atscppapi::TransactionPlugin *> & +Transaction::getPlugins() const +{ return state_->plugins_; } -void Transaction::addPlugin(TransactionPlugin *plugin) { +void +Transaction::addPlugin(TransactionPlugin *plugin) +{ LOG_DEBUG("Transaction tshttptxn=%p registering new TransactionPlugin %p.", state_->txn_, plugin); state_->plugins_.push_back(plugin); } -shared_ptr<Transaction::ContextValue> Transaction::getContextValue(const std::string &key) { +shared_ptr<Transaction::ContextValue> +Transaction::getContextValue(const std::string &key) +{ shared_ptr<Transaction::ContextValue> return_context_value; map<string, shared_ptr<Transaction::ContextValue> >::iterator iter = state_->context_values_.find(key); if (iter != state_->context_values_.end()) { @@ -144,66 +162,92 @@ shared_ptr<Transaction::ContextValue> Transaction::getContextValue(const std::st return return_context_value; } -void Transaction::setContextValue(const std::string &key, shared_ptr<Transaction::ContextValue> value) { +void +Transaction::setContextValue(const std::string &key, shared_ptr<Transaction::ContextValue> value) +{ state_->context_values_[key] = value; } -ClientRequest &Transaction::getClientRequest() { +ClientRequest & +Transaction::getClientRequest() +{ return state_->client_request_; } -Request &Transaction::getServerRequest() { +Request & +Transaction::getServerRequest() +{ return state_->server_request_; } -Response &Transaction::getServerResponse() { +Response & +Transaction::getServerResponse() +{ return state_->server_response_; } -Response &Transaction::getClientResponse() { +Response & +Transaction::getClientResponse() +{ return state_->client_response_; } -string Transaction::getEffectiveUrl() { - string ret_val; - int length = 0; - char *buf = TSHttpTxnEffectiveUrlStringGet(state_->txn_, &length); - if (buf && length) { - ret_val.assign(buf, length); - } +string +Transaction::getEffectiveUrl() +{ + string ret_val; + int length = 0; + char *buf = TSHttpTxnEffectiveUrlStringGet(state_->txn_, &length); + if (buf && length) { + ret_val.assign(buf, length); + } - if (buf) - TSfree(buf); + if (buf) + TSfree(buf); - return ret_val; + return ret_val; } -bool Transaction::setCacheUrl(const string &cache_url) { +bool +Transaction::setCacheUrl(const string &cache_url) +{ TSReturnCode res = TSCacheUrlSet(state_->txn_, cache_url.c_str(), cache_url.length()); return (res == TS_SUCCESS); } -const sockaddr *Transaction::getIncomingAddress() const { +const sockaddr * +Transaction::getIncomingAddress() const +{ return TSHttpTxnIncomingAddrGet(state_->txn_); } -const sockaddr *Transaction::getClientAddress() const { +const sockaddr * +Transaction::getClientAddress() const +{ return TSHttpTxnClientAddrGet(state_->txn_); } -const sockaddr *Transaction::getNextHopAddress() const { +const sockaddr * +Transaction::getNextHopAddress() const +{ return TSHttpTxnNextHopAddrGet(state_->txn_); } -const sockaddr *Transaction::getServerAddress() const { +const sockaddr * +Transaction::getServerAddress() const +{ return TSHttpTxnServerAddrGet(state_->txn_); } -bool Transaction::setServerAddress(const sockaddr *sockaddress) { - return TSHttpTxnServerAddrSet(state_->txn_,sockaddress) == TS_SUCCESS; +bool +Transaction::setServerAddress(const sockaddr *sockaddress) +{ + return TSHttpTxnServerAddrSet(state_->txn_, sockaddress) == TS_SUCCESS; } -bool Transaction::setIncomingPort(uint16_t port) { +bool +Transaction::setIncomingPort(uint16_t port) +{ TSHttpTxnClientIncomingPortSet(state_->txn_, port); return true; // In reality TSHttpTxnClientIncomingPortSet should return SUCCESS or ERROR. } @@ -214,49 +258,61 @@ bool Transaction::setIncomingPort(uint16_t port) { * know that it's a server or client response because of the * TS C api which is TSHttpTxnServerRespBodyBytesGet. */ -size_t Transaction::getServerResponseBodySize() { +size_t +Transaction::getServerResponseBodySize() +{ return static_cast<size_t>(TSHttpTxnServerRespBodyBytesGet(state_->txn_)); } -size_t Transaction::getServerResponseHeaderSize() { +size_t +Transaction::getServerResponseHeaderSize() +{ return static_cast<size_t>(TSHttpTxnServerRespHdrBytesGet(state_->txn_)); } -size_t Transaction::getClientResponseBodySize() { +size_t +Transaction::getClientResponseBodySize() +{ return static_cast<size_t>(TSHttpTxnClientRespBodyBytesGet(state_->txn_)); } -size_t Transaction::getClientResponseHeaderSize() { +size_t +Transaction::getClientResponseHeaderSize() +{ return static_cast<size_t>(TSHttpTxnClientRespHdrBytesGet(state_->txn_)); } -void Transaction::setTimeout(Transaction::TimeoutType type, int time_ms) { +void +Transaction::setTimeout(Transaction::TimeoutType type, int time_ms) +{ switch (type) { - case TIMEOUT_DNS: - TSHttpTxnDNSTimeoutSet(state_->txn_, time_ms); - break; - case TIMEOUT_CONNECT: - TSHttpTxnConnectTimeoutSet(state_->txn_, time_ms); - break; - case TIMEOUT_NO_ACTIVITY: - TSHttpTxnNoActivityTimeoutSet(state_->txn_, time_ms); - break; - case TIMEOUT_ACTIVE: - TSHttpTxnActiveTimeoutSet(state_->txn_, time_ms); - break; - default: - break; + case TIMEOUT_DNS: + TSHttpTxnDNSTimeoutSet(state_->txn_, time_ms); + break; + case TIMEOUT_CONNECT: + TSHttpTxnConnectTimeoutSet(state_->txn_, time_ms); + break; + case TIMEOUT_NO_ACTIVITY: + TSHttpTxnNoActivityTimeoutSet(state_->txn_, time_ms); + break; + case TIMEOUT_ACTIVE: + TSHttpTxnActiveTimeoutSet(state_->txn_, time_ms); + break; + default: + break; } } -void Transaction::redirectTo(std::string const& url) { - char* s = ats_strdup(url.c_str()); +void +Transaction::redirectTo(std::string const &url) +{ + char *s = ats_strdup(url.c_str()); // Must re-alloc the string locally because ownership is transferred to the transaction. TSHttpTxnRedirectUrlSet(state_->txn_, s, url.length()); } -namespace { - +namespace +{ /** * initializeHandles is a convenience functor that takes a pointer to a TS Function that * will return the TSMBuffer and TSMLoc for a given server request/response or client/request response @@ -267,52 +323,59 @@ namespace { * @param hdr_loc the address where the mem loc will be storeds * @param name name of the entity - used for logging */ -class initializeHandles { +class initializeHandles +{ public: typedef TSReturnCode (*GetterFunction)(TSHttpTxn, TSMBuffer *, TSMLoc *); - initializeHandles(GetterFunction getter) : getter_(getter) { } - bool operator()(TSHttpTxn txn, TSMBuffer &hdr_buf, TSMLoc &hdr_loc, const char *handles_name) { + initializeHandles(GetterFunction getter) : getter_(getter) {} + bool operator()(TSHttpTxn txn, TSMBuffer &hdr_buf, TSMLoc &hdr_loc, const char *handles_name) + { if (!hdr_buf && !hdr_loc) { if (getter_(txn, &hdr_buf, &hdr_loc) == TS_SUCCESS) { return true; - } - else { + } else { LOG_ERROR("Could not get %s", handles_name); } - } - else { + } else { LOG_ERROR("%s already initialized", handles_name); } return false; } + private: GetterFunction getter_; }; } // anonymous namespace -void Transaction::initServerRequest() { +void +Transaction::initServerRequest() +{ static initializeHandles initializeServerRequestHandles(TSHttpTxnServerReqGet); - if (initializeServerRequestHandles(state_->txn_, state_->server_request_hdr_buf_, - state_->server_request_hdr_loc_, "server request")) { + if (initializeServerRequestHandles(state_->txn_, state_->server_request_hdr_buf_, state_->server_request_hdr_loc_, + "server request")) { LOG_DEBUG("Initializing server request"); state_->server_request_.init(state_->server_request_hdr_buf_, state_->server_request_hdr_loc_); } } -void Transaction::initServerResponse() { +void +Transaction::initServerResponse() +{ static initializeHandles initializeServerResponseHandles(TSHttpTxnServerRespGet); - if (initializeServerResponseHandles(state_->txn_, state_->server_response_hdr_buf_, - state_->server_response_hdr_loc_, "server response")) { + if (initializeServerResponseHandles(state_->txn_, state_->server_response_hdr_buf_, state_->server_response_hdr_loc_, + "server response")) { LOG_DEBUG("Initializing server response"); state_->server_response_.init(state_->server_response_hdr_buf_, state_->server_response_hdr_loc_); } } -void Transaction::initClientResponse() { +void +Transaction::initClientResponse() +{ static initializeHandles initializeClientResponseHandles(TSHttpTxnClientRespGet); - if (initializeClientResponseHandles(state_->txn_, state_->client_response_hdr_buf_, - state_->client_response_hdr_loc_, "client response")) { + if (initializeClientResponseHandles(state_->txn_, state_->client_response_hdr_buf_, state_->client_response_hdr_loc_, + "client response")) { LOG_DEBUG("Initializing client response"); state_->client_response_.init(state_->client_response_hdr_buf_, state_->client_response_hdr_loc_); } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/TransactionPlugin.cc ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/TransactionPlugin.cc b/lib/atscppapi/src/TransactionPlugin.cc index 52af478..537a25c 100644 --- a/lib/atscppapi/src/TransactionPlugin.cc +++ b/lib/atscppapi/src/TransactionPlugin.cc @@ -36,17 +36,18 @@ using atscppapi::TransactionPlugin; /** * @private */ -struct atscppapi::TransactionPluginState: noncopyable { +struct atscppapi::TransactionPluginState : noncopyable { TSCont cont_; TSHttpTxn ats_txn_handle_; shared_ptr<Mutex> mutex_; - TransactionPluginState(TSHttpTxn ats_txn_handle) : ats_txn_handle_(ats_txn_handle), - mutex_(new Mutex(Mutex::TYPE_RECURSIVE)) { } + TransactionPluginState(TSHttpTxn ats_txn_handle) : ats_txn_handle_(ats_txn_handle), mutex_(new Mutex(Mutex::TYPE_RECURSIVE)) {} }; -namespace { - -static int handleTransactionPluginEvents(TSCont cont, TSEvent event, void *edata) { +namespace +{ +static int +handleTransactionPluginEvents(TSCont cont, TSEvent event, void *edata) +{ TSHttpTxn txn = static_cast<TSHttpTxn>(edata); TransactionPlugin *plugin = static_cast<TransactionPlugin *>(TSContDataGet(cont)); LOG_DEBUG("cont=%p, event=%d, tshttptxn=%p, plugin=%p", cont, event, edata, plugin); @@ -56,28 +57,33 @@ static int handleTransactionPluginEvents(TSCont cont, TSEvent event, void *edata } /* anonymous namespace */ -TransactionPlugin::TransactionPlugin(Transaction &transaction) { +TransactionPlugin::TransactionPlugin(Transaction &transaction) +{ state_ = new TransactionPluginState(static_cast<TSHttpTxn>(transaction.getAtsHandle())); TSMutex mutex = NULL; state_->cont_ = TSContCreate(handleTransactionPluginEvents, mutex); TSContDataSet(state_->cont_, static_cast<void *>(this)); - LOG_DEBUG("Creating new TransactionPlugin=%p tshttptxn=%p, cont=%p", this, state_->ats_txn_handle_, - state_->cont_); + LOG_DEBUG("Creating new TransactionPlugin=%p tshttptxn=%p, cont=%p", this, state_->ats_txn_handle_, state_->cont_); } -shared_ptr<Mutex> TransactionPlugin::getMutex() { +shared_ptr<Mutex> +TransactionPlugin::getMutex() +{ return state_->mutex_; } -TransactionPlugin::~TransactionPlugin() { +TransactionPlugin::~TransactionPlugin() +{ LOG_DEBUG("Destroying TransactionPlugin=%p", this); TSContDestroy(state_->cont_); delete state_; } -void TransactionPlugin::registerHook(Plugin::HookType hook_type) { - LOG_DEBUG("TransactionPlugin=%p tshttptxn=%p registering hook_type=%d [%s]", this, state_->ats_txn_handle_, - hook_type, HOOK_TYPE_STRINGS[hook_type].c_str()); +void +TransactionPlugin::registerHook(Plugin::HookType hook_type) +{ + LOG_DEBUG("TransactionPlugin=%p tshttptxn=%p registering hook_type=%d [%s]", this, state_->ats_txn_handle_, hook_type, + HOOK_TYPE_STRINGS[hook_type].c_str()); TSHttpHookID hook_id = atscppapi::utils::internal::convertInternalHookToTsHook(hook_type); TSHttpTxnHookAdd(state_->ats_txn_handle_, hook_id, state_->cont_); } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/TransformationPlugin.cc ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/TransformationPlugin.cc b/lib/atscppapi/src/TransformationPlugin.cc index 8c21ea9..8ef496b 100644 --- a/lib/atscppapi/src/TransformationPlugin.cc +++ b/lib/atscppapi/src/TransformationPlugin.cc @@ -39,7 +39,7 @@ using atscppapi::TransformationPlugin; /** * @private */ -struct atscppapi::TransformationPluginState: noncopyable { +struct atscppapi::TransformationPluginState : noncopyable { TSVConn vconn_; Transaction &transaction_; TransformationPlugin &transformation_plugin_; @@ -59,15 +59,16 @@ struct atscppapi::TransformationPluginState: noncopyable { std::string request_xform_output_; // in case of request xform, data produced is buffered here TransformationPluginState(atscppapi::Transaction &transaction, TransformationPlugin &transformation_plugin, - TransformationPlugin::Type type, TSHttpTxn txn) - : vconn_(NULL), transaction_(transaction), transformation_plugin_(transformation_plugin), type_(type), - output_vio_(NULL), txn_(txn), output_buffer_(NULL), output_buffer_reader_(NULL), bytes_written_(0), - input_complete_dispatched_(false) { + TransformationPlugin::Type type, TSHttpTxn txn) + : vconn_(NULL), transaction_(transaction), transformation_plugin_(transformation_plugin), type_(type), output_vio_(NULL), + txn_(txn), output_buffer_(NULL), output_buffer_reader_(NULL), bytes_written_(0), input_complete_dispatched_(false) + { output_buffer_ = TSIOBufferCreate(); output_buffer_reader_ = TSIOBufferReaderAlloc(output_buffer_); }; - ~TransformationPluginState() { + ~TransformationPluginState() + { if (output_buffer_reader_) { TSIOBufferReaderFree(output_buffer_reader_); output_buffer_reader_ = NULL; @@ -80,15 +81,19 @@ struct atscppapi::TransformationPluginState: noncopyable { } }; -namespace { - -void cleanupTransformation(TSCont contp) { +namespace +{ +void +cleanupTransformation(TSCont contp) +{ LOG_DEBUG("Destroying transformation contp=%p", contp); TSContDataSet(contp, reinterpret_cast<void *>(0xDEADDEAD)); TSContDestroy(contp); } -int handleTransformationPluginRead(TSCont contp, TransformationPluginState *state) { +int +handleTransformationPluginRead(TSCont contp, TransformationPluginState *state) +{ // Traffic Server naming is quite confusing, in this context the write_vio // is actually the vio we read from. TSVIO write_vio = TSVConnWriteVIOGet(contp); @@ -102,11 +107,14 @@ int handleTransformationPluginRead(TSCont contp, TransformationPluginState *stat * the amount of data actually in the read buffer. **/ int64_t avail = TSIOBufferReaderAvail(TSVIOReaderGet(write_vio)); - LOG_DEBUG("Transformation contp=%p write_vio=%p, to_read=%" PRId64 ", buffer reader avail=%" PRId64, contp, write_vio, to_read, avail); + LOG_DEBUG("Transformation contp=%p write_vio=%p, to_read=%" PRId64 ", buffer reader avail=%" PRId64, contp, write_vio, + to_read, avail); if (to_read > avail) { to_read = avail; - LOG_DEBUG("Transformation contp=%p write_vio=%p, to read > avail, fixing to_read to be equal to avail. to_read=%" PRId64 ", buffer reader avail=%" PRId64, contp, write_vio, to_read, avail); + LOG_DEBUG("Transformation contp=%p write_vio=%p, to read > avail, fixing to_read to be equal to avail. to_read=%" PRId64 + ", buffer reader avail=%" PRId64, + contp, write_vio, to_read, avail); } if (to_read > 0) { @@ -133,7 +141,7 @@ int handleTransformationPluginRead(TSCont contp, TransformationPluginState *stat /* Now call the client to tell them about data */ if (in_data.length() > 0) { - state->transformation_plugin_.consume(in_data); + state->transformation_plugin_.consume(in_data); } } @@ -141,7 +149,8 @@ int handleTransformationPluginRead(TSCont contp, TransformationPluginState *stat TSCont vio_cont = TSVIOContGet(write_vio); // for some reason this can occasionally be null if (TSVIONTodoGet(write_vio) > 0) { - LOG_DEBUG("Transformation contp=%p write_vio=%p, vio_cont=%p still has bytes left to process, todo > 0.", contp, write_vio, vio_cont); + LOG_DEBUG("Transformation contp=%p write_vio=%p, vio_cont=%p still has bytes left to process, todo > 0.", contp, write_vio, + vio_cont); if (to_read > 0) { TSVIOReenable(write_vio); @@ -152,15 +161,16 @@ int handleTransformationPluginRead(TSCont contp, TransformationPluginState *stat } } } else { - LOG_DEBUG("Transformation contp=%p write_vio=%p, vio_cont=%p has no bytes left to process, will send WRITE_COMPLETE.", contp, write_vio, vio_cont); + LOG_DEBUG("Transformation contp=%p write_vio=%p, vio_cont=%p has no bytes left to process, will send WRITE_COMPLETE.", + contp, write_vio, vio_cont); /* Call back the write VIO continuation to let it know that we have completed the write operation. */ if (!state->input_complete_dispatched_) { - state->transformation_plugin_.handleInputComplete(); - state->input_complete_dispatched_ = true; - if (vio_cont && 0 != TSVIOBufferGet(write_vio)) { - TSContCall(vio_cont, static_cast<TSEvent>(TS_EVENT_VCONN_WRITE_COMPLETE), write_vio); - } + state->transformation_plugin_.handleInputComplete(); + state->input_complete_dispatched_ = true; + if (vio_cont && 0 != TSVIOBufferGet(write_vio)) { + TSContCall(vio_cont, static_cast<TSEvent>(TS_EVENT_VCONN_WRITE_COMPLETE), write_vio); + } } } } else { @@ -169,11 +179,11 @@ int handleTransformationPluginRead(TSCont contp, TransformationPluginState *stat /* Call back the write VIO continuation to let it know that we have completed the write operation. */ if (!state->input_complete_dispatched_) { - state->transformation_plugin_.handleInputComplete(); - state->input_complete_dispatched_ = true; - if (vio_cont && 0 != TSVIOBufferGet(write_vio)) { - TSContCall(vio_cont, static_cast<TSEvent>(TS_EVENT_VCONN_WRITE_COMPLETE), write_vio); - } + state->transformation_plugin_.handleInputComplete(); + state->input_complete_dispatched_ = true; + if (vio_cont && 0 != TSVIOBufferGet(write_vio)) { + TSContCall(vio_cont, static_cast<TSEvent>(TS_EVENT_VCONN_WRITE_COMPLETE), write_vio); + } } } } else { @@ -182,7 +192,9 @@ int handleTransformationPluginRead(TSCont contp, TransformationPluginState *stat return 0; } -int handleTransformationPluginEvents(TSCont contp, TSEvent event, void *edata) { +int +handleTransformationPluginEvents(TSCont contp, TSEvent event, void *edata) +{ TransformationPluginState *state = static_cast<TransformationPluginState *>(TSContDataGet(contp)); LOG_DEBUG("Transformation contp=%p event=%d edata=%p tshttptxn=%p", contp, event, edata, state->txn_); @@ -196,8 +208,9 @@ int handleTransformationPluginEvents(TSCont contp, TSEvent event, void *edata) { if (event == TS_EVENT_VCONN_WRITE_COMPLETE) { TSVConn output_vconn = TSTransformOutputVConnGet(state->vconn_); - LOG_DEBUG("Transformation contp=%p tshttptxn=%p received WRITE_COMPLETE, shutting down outputvconn=%p ", contp, state->txn_, output_vconn); - TSVConnShutdown(output_vconn, 0, 1); // The other end is done reading our output + LOG_DEBUG("Transformation contp=%p tshttptxn=%p received WRITE_COMPLETE, shutting down outputvconn=%p ", contp, state->txn_, + output_vconn); + TSVConnShutdown(output_vconn, 0, 1); // The other end is done reading our output return 0; } else if (event == TS_EVENT_ERROR) { TSVIO write_vio; @@ -206,7 +219,8 @@ int handleTransformationPluginEvents(TSCont contp, TSEvent event, void *edata) { our parent transformation. */ write_vio = TSVConnWriteVIOGet(state->vconn_); TSCont vio_cont = TSVIOContGet(write_vio); - LOG_ERROR("Transformation contp=%p tshttptxn=%p received EVENT_ERROR forwarding to write_vio=%p viocont=%p", contp, state->txn_, write_vio, vio_cont); + LOG_ERROR("Transformation contp=%p tshttptxn=%p received EVENT_ERROR forwarding to write_vio=%p viocont=%p", contp, state->txn_, + write_vio, vio_cont); if (vio_cont) { TSContCall(vio_cont, TS_EVENT_ERROR, write_vio); } @@ -220,21 +234,26 @@ int handleTransformationPluginEvents(TSCont contp, TSEvent event, void *edata) { } /* anonymous namespace */ TransformationPlugin::TransformationPlugin(Transaction &transaction, TransformationPlugin::Type type) - : TransactionPlugin(transaction) { + : TransactionPlugin(transaction) +{ state_ = new TransformationPluginState(transaction, *this, type, static_cast<TSHttpTxn>(transaction.getAtsHandle())); state_->vconn_ = TSTransformCreate(handleTransformationPluginEvents, state_->txn_); TSContDataSet(state_->vconn_, static_cast<void *>(state_)); // edata in a TransformationHandler is NOT a TSHttpTxn. - LOG_DEBUG("Creating TransformationPlugin=%p (vconn)contp=%p tshttptxn=%p transformation_type=%d", this, state_->vconn_, state_->txn_, type); + LOG_DEBUG("Creating TransformationPlugin=%p (vconn)contp=%p tshttptxn=%p transformation_type=%d", this, state_->vconn_, + state_->txn_, type); TSHttpTxnHookAdd(state_->txn_, utils::internal::convertInternalTransformationTypeToTsHook(type), state_->vconn_); } -TransformationPlugin::~TransformationPlugin() { +TransformationPlugin::~TransformationPlugin() +{ LOG_DEBUG("Destroying TransformationPlugin=%p", this); cleanupTransformation(state_->vconn_); delete state_; } -size_t TransformationPlugin::doProduce(const std::string &data) { +size_t +TransformationPlugin::doProduce(const std::string &data) +{ LOG_DEBUG("TransformationPlugin=%p tshttptxn=%p producing output with length=%ld", this, state_->txn_, data.length()); int64_t write_length = static_cast<int64_t>(data.length()); if (!write_length) { @@ -249,14 +268,14 @@ size_t TransformationPlugin::doProduce(const std::string &data) { // You always write INT64_MAX, this basically says you're not sure how much data you're going to write state_->output_vio_ = TSVConnWrite(output_vconn, state_->vconn_, state_->output_buffer_reader_, INT64_MAX); } else { - LOG_ERROR("TransformationPlugin=%p tshttptxn=%p output_vconn=%p cannot issue TSVConnWrite due to null output vconn.", - this, state_->txn_, output_vconn); + LOG_ERROR("TransformationPlugin=%p tshttptxn=%p output_vconn=%p cannot issue TSVConnWrite due to null output vconn.", this, + state_->txn_, output_vconn); return 0; } if (!state_->output_vio_) { - LOG_ERROR("TransformationPlugin=%p tshttptxn=%p state_->output_vio=%p, TSVConnWrite failed.", - this, state_->txn_, state_->output_vio_); + LOG_ERROR("TransformationPlugin=%p tshttptxn=%p state_->output_vio=%p, TSVConnWrite failed.", this, state_->txn_, + state_->output_vio_); return 0; } } @@ -264,58 +283,69 @@ size_t TransformationPlugin::doProduce(const std::string &data) { // Finally we can copy this data into the output_buffer int64_t bytes_written = TSIOBufferWrite(state_->output_buffer_, data.c_str(), write_length); state_->bytes_written_ += bytes_written; // So we can set BytesDone on outputComplete(). - LOG_DEBUG("TransformationPlugin=%p tshttptxn=%p write to TSIOBuffer %" PRId64 " bytes total bytes written %" PRId64, this, state_->txn_, bytes_written, state_->bytes_written_); + LOG_DEBUG("TransformationPlugin=%p tshttptxn=%p write to TSIOBuffer %" PRId64 " bytes total bytes written %" PRId64, this, + state_->txn_, bytes_written, state_->bytes_written_); // Sanity Checks if (bytes_written != write_length) { - LOG_ERROR("TransformationPlugin=%p tshttptxn=%p bytes written < expected. bytes_written=%" PRId64 " write_length=%" PRId64, this, state_->txn_, bytes_written, write_length); + LOG_ERROR("TransformationPlugin=%p tshttptxn=%p bytes written < expected. bytes_written=%" PRId64 " write_length=%" PRId64, + this, state_->txn_, bytes_written, write_length); } int connection_closed = TSVConnClosedGet(state_->vconn_); - LOG_DEBUG("TransformationPlugin=%p tshttptxn=%p vconn=%p connection_closed=%d", this, state_->txn_, state_->vconn_, connection_closed); + LOG_DEBUG("TransformationPlugin=%p tshttptxn=%p vconn=%p connection_closed=%d", this, state_->txn_, state_->vconn_, + connection_closed); if (!connection_closed) { TSVIOReenable(state_->output_vio_); // Wake up the downstream vio } else { - LOG_ERROR("TransformationPlugin=%p tshttptxn=%p output_vio=%p connection_closed=%d : Couldn't reenable output vio (connection closed).", this, state_->txn_, state_->output_vio_, connection_closed); + LOG_ERROR( + "TransformationPlugin=%p tshttptxn=%p output_vio=%p connection_closed=%d : Couldn't reenable output vio (connection closed).", + this, state_->txn_, state_->output_vio_, connection_closed); } return static_cast<size_t>(bytes_written); } -size_t TransformationPlugin::produce(const std::string &data) { +size_t +TransformationPlugin::produce(const std::string &data) +{ if (state_->type_ == REQUEST_TRANSFORMATION) { state_->request_xform_output_.append(data); return data.size(); - } - else { + } else { return doProduce(data); } } -size_t TransformationPlugin::setOutputComplete() { +size_t +TransformationPlugin::setOutputComplete() +{ if (state_->type_ == REQUEST_TRANSFORMATION) { doProduce(state_->request_xform_output_); } int connection_closed = TSVConnClosedGet(state_->vconn_); - LOG_DEBUG("OutputComplete TransformationPlugin=%p tshttptxn=%p vconn=%p connection_closed=%d, total bytes written=%" PRId64, this, state_->txn_, state_->vconn_, connection_closed,state_->bytes_written_); + LOG_DEBUG("OutputComplete TransformationPlugin=%p tshttptxn=%p vconn=%p connection_closed=%d, total bytes written=%" PRId64, this, + state_->txn_, state_->vconn_, connection_closed, state_->bytes_written_); if (!connection_closed && !state_->output_vio_) { - LOG_DEBUG("TransformationPlugin=%p tshttptxn=%p output complete without writing any data, initiating write of 0 bytes.", this, state_->txn_); + LOG_DEBUG("TransformationPlugin=%p tshttptxn=%p output complete without writing any data, initiating write of 0 bytes.", this, + state_->txn_); - // We're done without ever outputting anything, to correctly - // clean up we'll initiate a write then immeidately set it to 0 bytes done. - state_->output_vio_ = TSVConnWrite(TSTransformOutputVConnGet(state_->vconn_), state_->vconn_, state_->output_buffer_reader_, 0); + // We're done without ever outputting anything, to correctly + // clean up we'll initiate a write then immeidately set it to 0 bytes done. + state_->output_vio_ = TSVConnWrite(TSTransformOutputVConnGet(state_->vconn_), state_->vconn_, state_->output_buffer_reader_, 0); - if (state_->output_vio_) { - TSVIONDoneSet(state_->output_vio_, 0); - TSVIOReenable(state_->output_vio_); // Wake up the downstream vio - } else { - LOG_ERROR("TransformationPlugin=%p tshttptxn=%p unable to reenable output_vio=%p because VConnWrite failed.", this, state_->txn_, state_->output_vio_); - } + if (state_->output_vio_) { + TSVIONDoneSet(state_->output_vio_, 0); + TSVIOReenable(state_->output_vio_); // Wake up the downstream vio + } else { + LOG_ERROR("TransformationPlugin=%p tshttptxn=%p unable to reenable output_vio=%p because VConnWrite failed.", this, + state_->txn_, state_->output_vio_); + } - return 0; + return 0; } if (!connection_closed) { @@ -326,10 +356,12 @@ size_t TransformationPlugin::setOutputComplete() { TSVIONBytesSet(state_->output_vio_, state_->bytes_written_); TSVIOReenable(state_->output_vio_); // Wake up the downstream vio } else { - LOG_ERROR("TransformationPlugin=%p tshttptxn=%p unable to reenable output_vio=%p connection was closed=%d.", this, state_->txn_, state_->output_vio_, connection_closed); + LOG_ERROR("TransformationPlugin=%p tshttptxn=%p unable to reenable output_vio=%p connection was closed=%d.", this, + state_->txn_, state_->output_vio_, connection_closed); } } else { - LOG_ERROR("TransformationPlugin=%p tshttptxn=%p unable to reenable output_vio=%p connection was closed=%d.", this, state_->txn_, state_->output_vio_, connection_closed); + LOG_ERROR("TransformationPlugin=%p tshttptxn=%p unable to reenable output_vio=%p connection was closed=%d.", this, state_->txn_, + state_->output_vio_, connection_closed); } return state_->bytes_written_; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/Url.cc ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/Url.cc b/lib/atscppapi/src/Url.cc index 1b69f4c..177cd9e 100644 --- a/lib/atscppapi/src/Url.cc +++ b/lib/atscppapi/src/Url.cc @@ -30,40 +30,47 @@ using std::string; /** * @private */ -struct atscppapi::UrlState: noncopyable { +struct atscppapi::UrlState : noncopyable { TSMBuffer hdr_buf_; TSMLoc url_loc_; - UrlState(TSMBuffer hdr_buf, TSMLoc url_loc) : - hdr_buf_(hdr_buf), url_loc_(url_loc) { - } + UrlState(TSMBuffer hdr_buf, TSMLoc url_loc) : hdr_buf_(hdr_buf), url_loc_(url_loc) {} }; -Url::Url() { +Url::Url() +{ state_ = new UrlState(static_cast<TSMBuffer>(NULL), static_cast<TSMLoc>(NULL)); } -Url::Url(void *hdr_buf, void *url_loc) { +Url::Url(void *hdr_buf, void *url_loc) +{ state_ = new UrlState(static_cast<TSMBuffer>(hdr_buf), static_cast<TSMLoc>(url_loc)); } -void Url::init(void *hdr_buf, void *url_loc) { +void +Url::init(void *hdr_buf, void *url_loc) +{ state_->hdr_buf_ = static_cast<TSMBuffer>(hdr_buf); state_->url_loc_ = static_cast<TSMLoc>(url_loc); } -Url::~Url() { +Url::~Url() +{ delete state_; } -bool inline Url::isInitialized() const { +bool inline Url::isInitialized() const +{ return state_->hdr_buf_ && state_->url_loc_; } -void Url::reset() { - +void +Url::reset() +{ } -std::string Url::getUrlString() const { +std::string +Url::getUrlString() const +{ std::string ret_str; if (isInitialized()) { int length; @@ -73,14 +80,16 @@ std::string Url::getUrlString() const { TSfree(memptr); LOG_DEBUG("Got URL [%s]", ret_str.c_str()); } else { - LOG_ERROR("Got null/zero-length URL string; hdr_buf %p, url_loc %p, ptr %p, length %d", state_->hdr_buf_, - state_->url_loc_, memptr, length); + LOG_ERROR("Got null/zero-length URL string; hdr_buf %p, url_loc %p, ptr %p, length %d", state_->hdr_buf_, state_->url_loc_, + memptr, length); } } return ret_str; } -std::string Url::getPath() const { +std::string +Url::getPath() const +{ std::string ret_str; if (isInitialized()) { int length; @@ -93,7 +102,9 @@ std::string Url::getPath() const { return ret_str; } -std::string Url::getQuery() const { +std::string +Url::getQuery() const +{ std::string ret_str; if (isInitialized()) { int length; @@ -106,7 +117,9 @@ std::string Url::getQuery() const { return ret_str; } -std::string Url::getScheme() const { +std::string +Url::getScheme() const +{ std::string ret_str; if (isInitialized()) { int length; @@ -119,7 +132,9 @@ std::string Url::getScheme() const { return ret_str; } -std::string Url::getHost() const { +std::string +Url::getHost() const +{ std::string ret_str; if (isInitialized()) { int length; @@ -132,7 +147,9 @@ std::string Url::getHost() const { return ret_str; } -uint16_t Url::getPort() const { +uint16_t +Url::getPort() const +{ uint16_t ret_val = 0; if (isInitialized()) { ret_val = static_cast<uint16_t>(TSUrlPortGet(state_->hdr_buf_, state_->url_loc_)); @@ -141,7 +158,9 @@ uint16_t Url::getPort() const { return ret_val; } -void Url::setPath(const std::string &path) { +void +Url::setPath(const std::string &path) +{ if (!isInitialized()) { LOG_ERROR("Url %p not initialized", this); return; @@ -154,7 +173,9 @@ void Url::setPath(const std::string &path) { } } -void Url::setQuery(const std::string &query) { +void +Url::setQuery(const std::string &query) +{ if (!isInitialized()) { LOG_ERROR("Url %p not initialized", this); return; @@ -167,9 +188,12 @@ void Url::setQuery(const std::string &query) { } } -void Url::setScheme(const std::string &scheme) { +void +Url::setScheme(const std::string &scheme) +{ if (!isInitialized()) { - LOG_ERROR("Url %p not initialized", this);; + LOG_ERROR("Url %p not initialized", this); + ; return; } @@ -180,7 +204,9 @@ void Url::setScheme(const std::string &scheme) { } } -void Url::setHost(const std::string &host) { +void +Url::setHost(const std::string &host) +{ if (!isInitialized()) { LOG_ERROR("Url %p not initialized", this); return; @@ -193,7 +219,9 @@ void Url::setHost(const std::string &host) { } } -void Url::setPort(const uint16_t port) { +void +Url::setPort(const uint16_t port) +{ if (!isInitialized()) { LOG_ERROR("Url %p not initialized", this); return; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/Async.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/Async.h b/lib/atscppapi/src/include/atscppapi/Async.h index 72e0eb5..56aaa2a 100644 --- a/lib/atscppapi/src/include/atscppapi/Async.h +++ b/lib/atscppapi/src/include/atscppapi/Async.h @@ -29,8 +29,8 @@ #include <atscppapi/noncopyable.h> #include <atscppapi/shared_ptr.h> -namespace atscppapi { - +namespace atscppapi +{ /** * @private * @@ -38,7 +38,8 @@ namespace atscppapi { * is used to dispatch an event to a receiver. This interface exists so that the types in this * header file can be defined. */ -class AsyncDispatchControllerBase : noncopyable { +class AsyncDispatchControllerBase : noncopyable +{ public: /** * Dispatches an async event to a receiver. @@ -53,7 +54,7 @@ public: /** Returns true if receiver can be communicated with */ virtual bool isEnabled() = 0; - virtual ~AsyncDispatchControllerBase() { } + virtual ~AsyncDispatchControllerBase() {} }; /** @@ -63,7 +64,8 @@ public: * handles this case. Because of this decoupling, it is the responsibility of the provider * to manage it's expiration - self-destruct on completion is a good option. */ -class AsyncProvider { +class AsyncProvider +{ public: /** * This method is invoked when the async operation is requested. This call should be used @@ -74,20 +76,28 @@ public: /** Base implementation just breaks communication channel with receiver. Implementations * should add business logic here. */ - virtual void cancel() { + virtual void + cancel() + { if (dispatch_controller_) { dispatch_controller_->disable(); } } - virtual ~AsyncProvider() { } + virtual ~AsyncProvider() {} protected: - shared_ptr<AsyncDispatchControllerBase> getDispatchController() { return dispatch_controller_; } + shared_ptr<AsyncDispatchControllerBase> + getDispatchController() + { + return dispatch_controller_; + } private: shared_ptr<AsyncDispatchControllerBase> dispatch_controller_; - void doRun(shared_ptr<AsyncDispatchControllerBase> dispatch_controller) { + void + doRun(shared_ptr<AsyncDispatchControllerBase> dispatch_controller) + { dispatch_controller_ = dispatch_controller; run(); } @@ -100,10 +110,13 @@ private: * @brief Dispatch controller implementation. When invoking the receiver, it verifies that the * receiver is still alive, locks the mutex and then invokes handleAsyncComplete(). */ -template<typename AsyncEventReceiverType, typename AsyncProviderType> -class AsyncDispatchController : public AsyncDispatchControllerBase { +template <typename AsyncEventReceiverType, typename AsyncProviderType> +class AsyncDispatchController : public AsyncDispatchControllerBase +{ public: - bool dispatch() { + bool + dispatch() + { bool ret = false; ScopedSharedMutexLock scopedLock(dispatch_mutex_); if (event_receiver_) { @@ -113,12 +126,16 @@ public: return ret; } - void disable() { + void + disable() + { ScopedSharedMutexLock scopedLock(dispatch_mutex_); event_receiver_ = NULL; } - bool isEnabled() { + bool + isEnabled() + { return (event_receiver_ != NULL); } @@ -129,14 +146,17 @@ public: * @param provider Async operation provider that is passed to the receiver on dispatch. * @param mutex Mutex of the receiver that is locked during the dispatch */ - AsyncDispatchController(AsyncEventReceiverType *event_receiver, AsyncProviderType *provider, shared_ptr<Mutex> mutex) : - event_receiver_(event_receiver), dispatch_mutex_(mutex), provider_(provider) { + AsyncDispatchController(AsyncEventReceiverType *event_receiver, AsyncProviderType *provider, shared_ptr<Mutex> mutex) + : event_receiver_(event_receiver), dispatch_mutex_(mutex), provider_(provider) + { } - virtual ~AsyncDispatchController() { } + virtual ~AsyncDispatchController() {} + public: AsyncEventReceiverType *event_receiver_; shared_ptr<Mutex> dispatch_mutex_; + private: AsyncProviderType *provider_; }; @@ -148,16 +168,20 @@ private: * alive to receive the async complete dispatch. When the receiver dies, this promise is * broken and it automatically updates the dispatch controller. */ -template<typename AsyncEventReceiverType, typename AsyncProviderType> -class AsyncReceiverPromise : noncopyable { +template <typename AsyncEventReceiverType, typename AsyncProviderType> class AsyncReceiverPromise : noncopyable +{ public: - AsyncReceiverPromise(shared_ptr<AsyncDispatchController<AsyncEventReceiverType, AsyncProviderType> > dispatch_controller) : - dispatch_controller_(dispatch_controller) { } + AsyncReceiverPromise(shared_ptr<AsyncDispatchController<AsyncEventReceiverType, AsyncProviderType> > dispatch_controller) + : dispatch_controller_(dispatch_controller) + { + } - ~AsyncReceiverPromise() { + ~AsyncReceiverPromise() + { ScopedSharedMutexLock scopedLock(dispatch_controller_->dispatch_mutex_); dispatch_controller_->event_receiver_ = NULL; } + protected: shared_ptr<AsyncDispatchController<AsyncEventReceiverType, AsyncProviderType> > dispatch_controller_; }; @@ -166,8 +190,8 @@ protected: * @brief AsyncReceiver is the interface that receivers of async operations must implement. It is * templated on the type of the async operation provider. */ -template<typename AsyncProviderType> -class AsyncReceiver : noncopyable { +template <typename AsyncProviderType> class AsyncReceiver : noncopyable +{ public: /** * This method is invoked when the async operation is completed. The @@ -177,10 +201,12 @@ public: * @param provider A reference to the provider which completed the async operation. */ virtual void handleAsyncComplete(AsyncProviderType &provider) = 0; - virtual ~AsyncReceiver() { } + virtual ~AsyncReceiver() {} + protected: - AsyncReceiver() { } + AsyncReceiver() {} friend class Async; + private: mutable std::list<shared_ptr<AsyncReceiverPromise<AsyncReceiver<AsyncProviderType>, AsyncProviderType> > > receiver_promises_; }; @@ -188,7 +214,8 @@ private: /** * @brief This class provides a method to create an async operation. */ -class Async : noncopyable { +class Async : noncopyable +{ public: /** * This method sets up the dispatch controller to link the async operation provider and @@ -201,20 +228,21 @@ public: * TransactionPlugin::getMutex() here and global plugins can pass an appropriate * or NULL mutex. */ - template<typename AsyncProviderType> - static void execute(AsyncReceiver<AsyncProviderType> *event_receiver, AsyncProviderType *provider, shared_ptr<Mutex> mutex) { + template <typename AsyncProviderType> + static void + execute(AsyncReceiver<AsyncProviderType> *event_receiver, AsyncProviderType *provider, shared_ptr<Mutex> mutex) + { if (!mutex.get()) { mutex.reset(new Mutex(Mutex::TYPE_RECURSIVE)); } - shared_ptr<AsyncDispatchController<AsyncReceiver<AsyncProviderType>, AsyncProviderType > > dispatcher( - new AsyncDispatchController<AsyncReceiver<AsyncProviderType>, AsyncProviderType >(event_receiver, provider, mutex)); - shared_ptr<AsyncReceiverPromise<AsyncReceiver<AsyncProviderType>, AsyncProviderType > > receiver_promise( - new AsyncReceiverPromise<AsyncReceiver<AsyncProviderType>, AsyncProviderType >(dispatcher)); + shared_ptr<AsyncDispatchController<AsyncReceiver<AsyncProviderType>, AsyncProviderType> > dispatcher( + new AsyncDispatchController<AsyncReceiver<AsyncProviderType>, AsyncProviderType>(event_receiver, provider, mutex)); + shared_ptr<AsyncReceiverPromise<AsyncReceiver<AsyncProviderType>, AsyncProviderType> > receiver_promise( + new AsyncReceiverPromise<AsyncReceiver<AsyncProviderType>, AsyncProviderType>(dispatcher)); event_receiver->receiver_promises_.push_back(receiver_promise); // now if the event receiver dies, we're safe. provider->doRun(dispatcher); } }; - } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/AsyncHttpFetch.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/AsyncHttpFetch.h b/lib/atscppapi/src/include/atscppapi/AsyncHttpFetch.h index 35f5091..57d40e0 100644 --- a/lib/atscppapi/src/include/atscppapi/AsyncHttpFetch.h +++ b/lib/atscppapi/src/include/atscppapi/AsyncHttpFetch.h @@ -30,11 +30,14 @@ #include <atscppapi/Request.h> #include <atscppapi/Response.h> -namespace atscppapi { - +namespace atscppapi +{ // forward declarations struct AsyncHttpFetchState; -namespace utils { class internal; } +namespace utils +{ + class internal; +} /** * @brief This class provides an implementation of AsyncProvider that @@ -43,7 +46,8 @@ namespace utils { class internal; } * * See example async_http_fetch{,_streaming} for sample usage. */ -class AsyncHttpFetch : public AsyncProvider { +class AsyncHttpFetch : public AsyncProvider +{ public: /** Deprecated. Use variant with streaming flag argument */ AsyncHttpFetch(const std::string &url_str, HttpMethod http_method = HTTP_METHOD_GET); @@ -53,11 +57,10 @@ public: enum StreamingFlag { STREAMING_DISABLED = 0, - STREAMING_ENABLED = 0x1 + STREAMING_ENABLED = 0x1, }; - AsyncHttpFetch(const std::string &url_str, StreamingFlag streaming_flag, - HttpMethod http_method = HTTP_METHOD_GET); + AsyncHttpFetch(const std::string &url_str, StreamingFlag streaming_flag, HttpMethod http_method = HTTP_METHOD_GET); AsyncHttpFetch(const std::string &url_str, StreamingFlag streaming_flag, const std::string &request_body); @@ -68,8 +71,14 @@ public: */ Headers &getRequestHeaders(); - enum Result { RESULT_SUCCESS = 10000, RESULT_TIMEOUT, RESULT_FAILURE, RESULT_HEADER_COMPLETE, - RESULT_PARTIAL_BODY, RESULT_BODY_COMPLETE }; + enum Result { + RESULT_SUCCESS = 10000, + RESULT_TIMEOUT, + RESULT_FAILURE, + RESULT_HEADER_COMPLETE, + RESULT_PARTIAL_BODY, + RESULT_BODY_COMPLETE + }; /** * Used to extract the response after request completion. Without @@ -115,13 +124,13 @@ public: * Starts a HTTP fetch of the Request contained. */ virtual void run(); + protected: virtual ~AsyncHttpFetch(); private: AsyncHttpFetchState *state_; - void init(const std::string &url_str, HttpMethod http_method, const std::string &request_body, - StreamingFlag streaming_flag); + void init(const std::string &url_str, HttpMethod http_method, const std::string &request_body, StreamingFlag streaming_flag); friend class utils::internal; }; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/AsyncTimer.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/AsyncTimer.h b/lib/atscppapi/src/include/atscppapi/AsyncTimer.h index ecb6621..a6f51ff 100644 --- a/lib/atscppapi/src/include/atscppapi/AsyncTimer.h +++ b/lib/atscppapi/src/include/atscppapi/AsyncTimer.h @@ -30,8 +30,8 @@ #include <atscppapi/Request.h> #include <atscppapi/Response.h> -namespace atscppapi { - +namespace atscppapi +{ // forward declarations struct AsyncTimerState; @@ -45,10 +45,13 @@ struct AsyncTimerState; * * See example async_timer for sample usage. */ -class AsyncTimer : public AsyncProvider { +class AsyncTimer : public AsyncProvider +{ public: - - enum Type { TYPE_ONE_OFF = 0, TYPE_PERIODIC }; + enum Type { + TYPE_ONE_OFF = 0, + TYPE_PERIODIC, + }; /** * Constructor. http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/CaseInsensitiveStringComparator.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/CaseInsensitiveStringComparator.h b/lib/atscppapi/src/include/atscppapi/CaseInsensitiveStringComparator.h index a47462a..a131ea0 100644 --- a/lib/atscppapi/src/include/atscppapi/CaseInsensitiveStringComparator.h +++ b/lib/atscppapi/src/include/atscppapi/CaseInsensitiveStringComparator.h @@ -26,14 +26,15 @@ #include <string> -namespace atscppapi { - +namespace atscppapi +{ /** * @brief A case insensitive comparator that can be used with standard library containers. * * The primary use for this class is to make all Headers case insensitive. */ -class CaseInsensitiveStringComparator { +class CaseInsensitiveStringComparator +{ public: /** * @return true if lhs is lexicographically "less-than" rhs; meant for use in std::map or other standard library containers. @@ -45,7 +46,6 @@ public: */ int compare(const std::string &lhs, const std::string &rhs) const; }; - } #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/ClientRequest.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/ClientRequest.h b/lib/atscppapi/src/include/atscppapi/ClientRequest.h index 0eee284..ef057bb 100644 --- a/lib/atscppapi/src/include/atscppapi/ClientRequest.h +++ b/lib/atscppapi/src/include/atscppapi/ClientRequest.h @@ -26,8 +26,8 @@ #include <atscppapi/Request.h> -namespace atscppapi { - +namespace atscppapi +{ struct ClientRequestState; /** @@ -35,7 +35,8 @@ struct ClientRequestState; * server request as it has two URLs - the pristine URL sent by the client * and a remapped URL created by the server. */ -class ClientRequest : public Request { +class ClientRequest : public Request +{ public: /** * @private @@ -50,10 +51,10 @@ public: const Url &getPristineUrl() const; ~ClientRequest(); + private: ClientRequestState *state_; }; - } #endif /* ATSCPPAPI_CLIENTREQUEST_H_ */ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/GlobalPlugin.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/GlobalPlugin.h b/lib/atscppapi/src/include/atscppapi/GlobalPlugin.h index 2c77769..4325a21 100644 --- a/lib/atscppapi/src/include/atscppapi/GlobalPlugin.h +++ b/lib/atscppapi/src/include/atscppapi/GlobalPlugin.h @@ -27,8 +27,8 @@ #include <atscppapi/Plugin.h> -namespace atscppapi { - +namespace atscppapi +{ struct GlobalPluginState; /** @@ -56,7 +56,8 @@ struct GlobalPluginState; * \endcode * @see Plugin */ -class GlobalPlugin : public Plugin { +class GlobalPlugin : public Plugin +{ public: /** * registerHook is the mechanism used to attach a global hook. @@ -71,6 +72,7 @@ public: */ void registerHook(Plugin::HookType); virtual ~GlobalPlugin(); + protected: /** * Constructor. @@ -80,6 +82,7 @@ protected: * when other plugins create requests). Defaults to false. */ GlobalPlugin(bool ignore_internal_transactions = false); + private: GlobalPluginState *state_; /**< Internal state tied to a GlobalPlugin */ }; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/GzipDeflateTransformation.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/GzipDeflateTransformation.h b/lib/atscppapi/src/include/atscppapi/GzipDeflateTransformation.h index 6a6443f..4740fec 100644 --- a/lib/atscppapi/src/include/atscppapi/GzipDeflateTransformation.h +++ b/lib/atscppapi/src/include/atscppapi/GzipDeflateTransformation.h @@ -28,63 +28,63 @@ #include <string> #include "atscppapi/TransformationPlugin.h" -namespace atscppapi { - -namespace transformations { - -/** - * Internal state for Deflate Transformations - * @private - */ -struct GzipDeflateTransformationState; - -/** - * @brief A TransformationPlugin to easily add gzip deflate to your TransformationPlugin chain. - * - * The GzipDeflateTransformation is a helper transformation that can be used - * to easily compress content. For a full example of GzipDeflateTransformation - * and GzipInflateTransformation see examples/gzip_transformation/. - * - * @note GzipDeflateTransformation DOES NOT set Content-Encoding headers, it is the - * users responsibility to set any applicable headers. - * - * @see GzipInflateTransformation - */ -class GzipDeflateTransformation : public TransformationPlugin { -public: +namespace atscppapi +{ +namespace transformations +{ /** - * A full example of how to use GzipDeflateTransformation and GzipInflateTransformation is available - * in examples/gzip_tranformation/ - * - * @param transaction As with any TransformationPlugin you must pass in the transaction - * @param type because the GzipDeflateTransformation can be used with both requests and responses - * you must specify the Type. - * - * @see TransformationPlugin::Type + * Internal state for Deflate Transformations + * @private */ - GzipDeflateTransformation(Transaction &transaction, TransformationPlugin::Type type); + struct GzipDeflateTransformationState; /** - * Any TransformationPlugin must implement consume(), this method will take content - * from the transformation chain and gzip compress it. + * @brief A TransformationPlugin to easily add gzip deflate to your TransformationPlugin chain. * - * @param data the input data to compress - */ - void consume(const std::string &data); - - /** - * Any TransformationPlugin must implement handleInputComplete(), this method will - * finalize the gzip compression and flush any remaining data and the epilouge. + * The GzipDeflateTransformation is a helper transformation that can be used + * to easily compress content. For a full example of GzipDeflateTransformation + * and GzipInflateTransformation see examples/gzip_transformation/. + * + * @note GzipDeflateTransformation DOES NOT set Content-Encoding headers, it is the + * users responsibility to set any applicable headers. + * + * @see GzipInflateTransformation */ - void handleInputComplete(); - - virtual ~GzipDeflateTransformation(); -private: - GzipDeflateTransformationState *state_; /** Internal state for Gzip Deflate Transformations */ -}; - + class GzipDeflateTransformation : public TransformationPlugin + { + public: + /** + * A full example of how to use GzipDeflateTransformation and GzipInflateTransformation is available + * in examples/gzip_tranformation/ + * + * @param transaction As with any TransformationPlugin you must pass in the transaction + * @param type because the GzipDeflateTransformation can be used with both requests and responses + * you must specify the Type. + * + * @see TransformationPlugin::Type + */ + GzipDeflateTransformation(Transaction &transaction, TransformationPlugin::Type type); + + /** + * Any TransformationPlugin must implement consume(), this method will take content + * from the transformation chain and gzip compress it. + * + * @param data the input data to compress + */ + void consume(const std::string &data); + + /** + * Any TransformationPlugin must implement handleInputComplete(), this method will + * finalize the gzip compression and flush any remaining data and the epilouge. + */ + void handleInputComplete(); + + virtual ~GzipDeflateTransformation(); + + private: + GzipDeflateTransformationState *state_; /** Internal state for Gzip Deflate Transformations */ + }; } - } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/GzipInflateTransformation.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/GzipInflateTransformation.h b/lib/atscppapi/src/include/atscppapi/GzipInflateTransformation.h index 1c32663..d0e4713 100644 --- a/lib/atscppapi/src/include/atscppapi/GzipInflateTransformation.h +++ b/lib/atscppapi/src/include/atscppapi/GzipInflateTransformation.h @@ -28,62 +28,64 @@ #include <string> #include "atscppapi/TransformationPlugin.h" -namespace atscppapi { - -namespace transformations { - -/** - * Internal state for Inflate Transformations - * @private - */ -struct GzipInflateTransformationState; - -/** - * @brief A TransformationPlugin to easily add gzip inflate to your TransformationPlugin chain. - * - * The GzipInflateTransformation is a helper transformation that can be used - * to easily decompress gzipped content. For a full example of GzipInflateTransformation - * and GzipDeflateTransformation see examples/gzip_transformation/. - * - * @note GzipDeflateTransformation DOES NOT set or check Content-Encoding headers, it is the - * users responsibility to set any applicable headers and check that the content is acctually - * gzipped by checking the Content-Encoding header before creating a GzipInflateTransformation, - * see examples/gzip_transformation/ for a full example. - * - * @see GzipDeflateTransformation - */ -class GzipInflateTransformation : public TransformationPlugin { -public: +namespace atscppapi +{ +namespace transformations +{ /** - * A full example of how to use GzipInflateTransformation and GzipDeflateTransformation is available - * in examples/gzip_tranformation/ - * - * @param transaction As with any TransformationPlugin you must pass in the transaction - * @param type because the GzipInflateTransformation can be used with both requests and responses - * you must specify the Type. - * - * @see TransformationPlugin::Type + * Internal state for Inflate Transformations + * @private */ - GzipInflateTransformation(Transaction &transaction, TransformationPlugin::Type type); + struct GzipInflateTransformationState; /** - * Any TransformationPlugin must implement consume(), this method will take content - * from the transformation chain and gzip decompress it. + * @brief A TransformationPlugin to easily add gzip inflate to your TransformationPlugin chain. + * + * The GzipInflateTransformation is a helper transformation that can be used + * to easily decompress gzipped content. For a full example of GzipInflateTransformation + * and GzipDeflateTransformation see examples/gzip_transformation/. * - * @param data the input data to decompress + * @note GzipDeflateTransformation DOES NOT set or check Content-Encoding headers, it is the + * users responsibility to set any applicable headers and check that the content is acctually + * gzipped by checking the Content-Encoding header before creating a GzipInflateTransformation, + * see examples/gzip_transformation/ for a full example. + * + * @see GzipDeflateTransformation */ - void consume(const std::string &); + class GzipInflateTransformation : public TransformationPlugin + { + public: + /** + * A full example of how to use GzipInflateTransformation and GzipDeflateTransformation is available + * in examples/gzip_tranformation/ + * + * @param transaction As with any TransformationPlugin you must pass in the transaction + * @param type because the GzipInflateTransformation can be used with both requests and responses + * you must specify the Type. + * + * @see TransformationPlugin::Type + */ + GzipInflateTransformation(Transaction &transaction, TransformationPlugin::Type type); - /** - * Any TransformationPlugin must implement handleInputComplete(), this method will - * finalize the gzip decompression. - */ - void handleInputComplete(); + /** + * Any TransformationPlugin must implement consume(), this method will take content + * from the transformation chain and gzip decompress it. + * + * @param data the input data to decompress + */ + void consume(const std::string &); + + /** + * Any TransformationPlugin must implement handleInputComplete(), this method will + * finalize the gzip decompression. + */ + void handleInputComplete(); + + virtual ~GzipInflateTransformation(); - virtual ~GzipInflateTransformation(); -private: - GzipInflateTransformationState *state_; /** Internal state for Gzip Deflate Transformations */ -}; + private: + GzipInflateTransformationState *state_; /** Internal state for Gzip Deflate Transformations */ + }; } /* transformations */ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/Headers.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/Headers.h b/lib/atscppapi/src/include/atscppapi/Headers.h index 751ff6b..563be66 100644 --- a/lib/atscppapi/src/include/atscppapi/Headers.h +++ b/lib/atscppapi/src/include/atscppapi/Headers.h @@ -27,8 +27,8 @@ #include <atscppapi/noncopyable.h> #include <string> -namespace atscppapi { - +namespace atscppapi +{ struct HeadersState; struct HeaderFieldIteratorState; struct HeaderFieldValueIteratorState; @@ -41,67 +41,69 @@ class Response; * Because header field names must be case insensitive this allows easy case insentive comparisons of names. * */ -class HeaderFieldName { - private: - std::string name_; - public: - typedef std::string::size_type size_type; +class HeaderFieldName +{ +private: + std::string name_; - /** - * Constructor: build a new HeaderField name with the given string - */ - HeaderFieldName(const std::string &name); +public: + typedef std::string::size_type size_type; - /** - * std::string conversion - * @return a string which is this HeaderFieldName - */ - operator std::string(); + /** + * Constructor: build a new HeaderField name with the given string + */ + HeaderFieldName(const std::string &name); - /** - * const char * conversion - * @return a const char * which is this HeaderFieldName - */ - operator const char*(); + /** + * std::string conversion + * @return a string which is this HeaderFieldName + */ + operator std::string(); - /** - * @return the length of this HeaderFieldName + /** + * const char * conversion + * @return a const char * which is this HeaderFieldName */ - size_type length(); + operator const char *(); - /** - * @return a string which is this HeaderFieldName + /** + * @return the length of this HeaderFieldName + */ + size_type length(); + + /** + * @return a string which is this HeaderFieldName + */ + std::string str(); + + /** + * @return a const char * which points to the name of this HeaderFIeldName + */ + const char *c_str(); + + /** + * Case insensitive comparison of this HeaderFieldName + * @return true if the two strings are equal. + */ + bool operator==(const char *field_name); + + /** + * Case insensitive comparison of this HeaderFieldName + * @return true if the two strings are equal. */ - std::string str(); + bool operator==(const std::string &field_name); - /** - * @return a const char * which points to the name of this HeaderFIeldName + /** + * Case insensitive comparison of this HeaderFieldName + * @return true if the two strings are not equal. */ - const char *c_str(); + bool operator!=(const char *field_name); - /** + /** * Case insensitive comparison of this HeaderFieldName - * @return true if the two strings are equal. + * @return true if the two strings are not equal. */ - bool operator==(const char *field_name); - - /** - * Case insensitive comparison of this HeaderFieldName - * @return true if the two strings are equal. - */ - bool operator==(const std::string &field_name); - - /** - * Case insensitive comparison of this HeaderFieldName - * @return true if the two strings are not equal. - */ - bool operator!=(const char *field_name); - - /** - * Case insensitive comparison of this HeaderFieldName - * @return true if the two strings are not equal. - */ - bool operator!=(const std::string &field_name); + bool operator!=(const std::string &field_name); }; class HeaderField; @@ -111,58 +113,59 @@ class HeaderField; */ class header_field_value_iterator : public std::iterator<std::forward_iterator_tag, int> { - private: - HeaderFieldValueIteratorState *state_; - public: - /** - * Constructor for header_field_value_iterator, this shouldn't need to be used directly. - * @param bufp the TSMBuffer associated with the headers - * @param mloc the TSMLoc associated with the headers. - * @param field_loc the TSMLoc assocated with the field. - * @param index the index of the value in the HeaderField - * @warning This shouldn't need to be used directly! - */ - header_field_value_iterator(void *bufp, void *hdr_loc, void *field_loc, int index); - - /** - * Copy Constructor for header_field_value_iterator, this shouldn't need to be used directly. - * @param header_field_value_iterator an existing iterator to copy - * @warning This shouldn't need to be used directly! - */ - header_field_value_iterator(const header_field_value_iterator& it); - ~header_field_value_iterator(); - - /** - * Dereference this iterator into a string (get the value pointed to by this iterator) - * @return a string which is the value pointed to by this iterator - */ - std::string operator*(); - - /** - * Advance the iterator to the next header field value - * @return a reference to a the next iterator - */ - header_field_value_iterator& operator++(); - - /** - * Advance the current iterator to the next header field - * @return a new iterator which points to the next element - */ - header_field_value_iterator operator++(int); - - /** - * Compare two iterators returning true if they are equal - * @return true if two iterators are equal - */ - bool operator==(const header_field_value_iterator& rhs) const; - - /** - * Compare two iterators returning true if they are NOT equal - * @return true if two iterators are not equal. - */ - bool operator!=(const header_field_value_iterator& rhs) const; - - friend class HeaderField; +private: + HeaderFieldValueIteratorState *state_; + +public: + /** + * Constructor for header_field_value_iterator, this shouldn't need to be used directly. + * @param bufp the TSMBuffer associated with the headers + * @param mloc the TSMLoc associated with the headers. + * @param field_loc the TSMLoc assocated with the field. + * @param index the index of the value in the HeaderField + * @warning This shouldn't need to be used directly! + */ + header_field_value_iterator(void *bufp, void *hdr_loc, void *field_loc, int index); + + /** + * Copy Constructor for header_field_value_iterator, this shouldn't need to be used directly. + * @param header_field_value_iterator an existing iterator to copy + * @warning This shouldn't need to be used directly! + */ + header_field_value_iterator(const header_field_value_iterator &it); + ~header_field_value_iterator(); + + /** + * Dereference this iterator into a string (get the value pointed to by this iterator) + * @return a string which is the value pointed to by this iterator + */ + std::string operator*(); + + /** + * Advance the iterator to the next header field value + * @return a reference to a the next iterator + */ + header_field_value_iterator &operator++(); + + /** + * Advance the current iterator to the next header field + * @return a new iterator which points to the next element + */ + header_field_value_iterator operator++(int); + + /** + * Compare two iterators returning true if they are equal + * @return true if two iterators are equal + */ + bool operator==(const header_field_value_iterator &rhs) const; + + /** + * Compare two iterators returning true if they are NOT equal + * @return true if two iterators are not equal. + */ + bool operator!=(const header_field_value_iterator &rhs) const; + + friend class HeaderField; }; /** @@ -170,69 +173,71 @@ class header_field_value_iterator : public std::iterator<std::forward_iterator_t */ class header_field_iterator : public std::iterator<std::forward_iterator_tag, int> { - private: - HeaderFieldIteratorState *state_; - header_field_iterator(void *hdr_buf, void *hdr_loc, void *field_loc); - public: - ~header_field_iterator(); - - /** - * Copy Constructor for header_field_iterator, this shouldn't need to be used directly. - * @param header_field_iterator: for constructing the iterator. - * @warning This shouldn't need to be used directly! - */ - header_field_iterator(const header_field_iterator& it); - - header_field_iterator &operator=(const header_field_iterator &rhs); - - /** - * Advance the iterator to the next header field - * @return a reference to a the next iterator - */ - header_field_iterator& operator++(); - - /** - * Advance the current iterator to the next header field - * @return a new iterator which points to the next element - */ - header_field_iterator operator++(int); - - /** - * Advance the iterator to the next header field with the same name - * @return a reference to a the next iterator - */ - header_field_iterator& nextDup(); - - /** - * Comparison operator, compare two iterators - * @return true if the two iterators point to the same HeaderField - */ - bool operator==(const header_field_iterator& rhs) const; - - /** - * Inequality Operator, compare two iterators - * @return false if the two iterators are the same. - */ - bool operator!=(const header_field_iterator& rhs) const; - - /** - * Dereference an iterator - * @return a HeaderField pointed to by this iterator - */ - HeaderField operator*(); - - friend class HeaderField; - friend class Headers; +private: + HeaderFieldIteratorState *state_; + header_field_iterator(void *hdr_buf, void *hdr_loc, void *field_loc); + +public: + ~header_field_iterator(); + + /** + * Copy Constructor for header_field_iterator, this shouldn't need to be used directly. + * @param header_field_iterator: for constructing the iterator. + * @warning This shouldn't need to be used directly! + */ + header_field_iterator(const header_field_iterator &it); + + header_field_iterator &operator=(const header_field_iterator &rhs); + + /** + * Advance the iterator to the next header field + * @return a reference to a the next iterator + */ + header_field_iterator &operator++(); + + /** + * Advance the current iterator to the next header field + * @return a new iterator which points to the next element + */ + header_field_iterator operator++(int); + + /** + * Advance the iterator to the next header field with the same name + * @return a reference to a the next iterator + */ + header_field_iterator &nextDup(); + + /** + * Comparison operator, compare two iterators + * @return true if the two iterators point to the same HeaderField + */ + bool operator==(const header_field_iterator &rhs) const; + + /** + * Inequality Operator, compare two iterators + * @return false if the two iterators are the same. + */ + bool operator!=(const header_field_iterator &rhs) const; + + /** + * Dereference an iterator + * @return a HeaderField pointed to by this iterator + */ + HeaderField operator*(); + + friend class HeaderField; + friend class Headers; }; /** * @brief A HeaderField is a class that contains the header field name and all of the values. * @note You may have several HeaderFields with the same name for a given set of Headers. */ -class HeaderField { +class HeaderField +{ private: header_field_iterator iter_; - HeaderField(header_field_iterator iter) : iter_(iter) { } + HeaderField(header_field_iterator iter) : iter_(iter) {} public: typedef unsigned int size_type; @@ -350,7 +355,7 @@ public: * @note This is a case insensitive comparison. * @return true if the name is NOT equal (case insensitive comparison). */ - bool operator!=(const std::string &field_name) const ; + bool operator!=(const std::string &field_name) const; /** * Set the VALUES of the header field to the given value string @@ -379,7 +384,7 @@ public: * Get a string representing all the header field's values * @return a string representation of all the header fields */ - friend std::ostream& operator<<(std::ostream& os, HeaderField& obj); + friend std::ostream &operator<<(std::ostream &os, HeaderField &obj); /** * Get a string representing all the header field's values. @@ -393,7 +398,8 @@ public: /** * @brief Encapsulates the headers portion of a request or response. */ -class Headers: noncopyable { +class Headers : noncopyable +{ public: /** * Constructor for Headers. This creates a "detached" headers, i.e., not tied to any transaction. @@ -404,7 +410,8 @@ public: * Constructor for Headers, this shouldn't be used directly unless you're trying to mix the C++ and C apis. * @param bufp the TSMBuffer associated with the headers * @param mloc the TSMLoc associated with the headers. - * @warning This should only be used if you're mixing the C++ and C apis, it will be constructed automatically if using only the C++ api. + * @warning This should only be used if you're mixing the C++ and C apis, it will be constructed automatically if using only the + * C++ api. */ Headers(void *bufp, void *mloc); @@ -585,16 +592,16 @@ public: */ std::string wireStr(); - friend std::ostream& operator<<(std::ostream &os, Headers &obj); + friend std::ostream &operator<<(std::ostream &os, Headers &obj); ~Headers(); + private: HeadersState *state_; friend class Request; friend class ClientRequest; friend class Response; }; - } #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/HttpMethod.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/HttpMethod.h b/lib/atscppapi/src/include/atscppapi/HttpMethod.h index 44029f7..7dc3b3d 100644 --- a/lib/atscppapi/src/include/atscppapi/HttpMethod.h +++ b/lib/atscppapi/src/include/atscppapi/HttpMethod.h @@ -26,8 +26,8 @@ #include <string> -namespace atscppapi { - +namespace atscppapi +{ /** * An enumeration of all available Http Methods. */ @@ -53,7 +53,6 @@ enum HttpMethod { * \endcode */ extern const std::string HTTP_METHOD_STRINGS[]; - } #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/HttpStatus.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/HttpStatus.h b/lib/atscppapi/src/include/atscppapi/HttpStatus.h index e1ba25b..bfea2fd 100644 --- a/lib/atscppapi/src/include/atscppapi/HttpStatus.h +++ b/lib/atscppapi/src/include/atscppapi/HttpStatus.h @@ -27,13 +27,12 @@ #include <string> -namespace atscppapi { - +namespace atscppapi +{ /** * An enumeration of all available Http Status Codes. */ -enum HttpStatus -{ +enum HttpStatus { HTTP_STATUS_UNKNOWN = 0, HTTP_STATUS_CONTINUE = 100, @@ -98,7 +97,6 @@ enum HttpStatus HTTP_STATUS_NETWORK_AUTHENTICATION_REQUIRED = 511 }; - } #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/HttpVersion.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/HttpVersion.h b/lib/atscppapi/src/include/atscppapi/HttpVersion.h index fdbd639..8cf0839 100644 --- a/lib/atscppapi/src/include/atscppapi/HttpVersion.h +++ b/lib/atscppapi/src/include/atscppapi/HttpVersion.h @@ -27,8 +27,8 @@ #include <string> -namespace atscppapi { - +namespace atscppapi +{ /** * An enumeration of all available Http Versions. */ @@ -46,7 +46,6 @@ enum HttpVersion { * \endcode */ extern const std::string HTTP_VERSION_STRINGS[]; - } #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/InterceptPlugin.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/InterceptPlugin.h b/lib/atscppapi/src/include/atscppapi/InterceptPlugin.h index 709e9c5..48c2de8 100644 --- a/lib/atscppapi/src/include/atscppapi/InterceptPlugin.h +++ b/lib/atscppapi/src/include/atscppapi/InterceptPlugin.h @@ -28,16 +28,15 @@ #include <atscppapi/Transaction.h> #include <atscppapi/TransactionPlugin.h> -namespace atscppapi { - - - +namespace atscppapi +{ /** * Allows a plugin to act as a server and return the response. This * plugin can be created in read request headers hook (pre or post * remap). */ -class InterceptPlugin : public TransactionPlugin { +class InterceptPlugin : public TransactionPlugin +{ protected: /** * The available types of intercepts. @@ -53,7 +52,7 @@ protected: public: enum RequestDataType { REQUEST_HEADER = 0, - REQUEST_BODY + REQUEST_BODY, }; /** @@ -82,7 +81,11 @@ protected: */ bool produce(const void *data, int data_size); - bool produce(const std::string &data) { return produce(data.data(), data.size()); } + bool + produce(const std::string &data) + { + return produce(data.data(), data.size()); + } bool setOutputComplete();
