You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by os...@apache.org on 2014/08/20 22:57:44 UTC
[4/7] ats_pagespeed: rename ats_speed -> ats_pagespeed
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1fe51067/plugins/experimental/ats_speed/ats_beacon_intercept.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/ats_speed/ats_beacon_intercept.cc b/plugins/experimental/ats_speed/ats_beacon_intercept.cc
deleted file mode 100644
index 9b14244..0000000
--- a/plugins/experimental/ats_speed/ats_beacon_intercept.cc
+++ /dev/null
@@ -1,364 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#include "ats_beacon_intercept.h"
-#include "ats_speed.h"
-#include "ats_server_context.h"
-
-#include "net/instaweb/system/public/system_request_context.h"
-
-#include <string>
-#include <limits.h>
-#include <strings.h>
-#include <stdio.h>
-
-using std::string;
-using namespace net_instaweb;
-
-#define DEBUG_TAG "ats_speed_beacon"
-
-struct InterceptCtx {
- TSVConn net_vc;
- TSCont contp;
-
- struct IoHandle {
- TSVIO vio;
- TSIOBuffer buffer;
- TSIOBufferReader reader;
- IoHandle()
- : vio(0), buffer(0), reader(0) { };
- ~IoHandle() {
- if (reader) {
- TSIOBufferReaderFree(reader);
- }
- if (buffer) {
- TSIOBufferDestroy(buffer);
- }
- };
- };
-
- IoHandle input;
- IoHandle output;
-
- TSHttpParser http_parser;
- string body;
- int req_content_len;
- TSMBuffer req_hdr_bufp;
- TSMLoc req_hdr_loc;
- bool req_hdr_parsed;
- bool initialized;
- TransformCtx* request_context;
- InterceptCtx(TSCont cont)
- : net_vc(0), contp(cont), input(), output(), body(""), req_content_len(0), req_hdr_bufp(0), req_hdr_loc(0),
- req_hdr_parsed(false), initialized(false) {
- http_parser = TSHttpParserCreate();
- }
-
- bool init(TSVConn vconn);
-
- void setupWrite();
-
- ~InterceptCtx() {
- TSDebug(DEBUG_TAG, "[%s] Destroying continuation data", __FUNCTION__);
- TSHttpParserDestroy(http_parser);
- if (req_hdr_loc) {
- TSHandleMLocRelease(req_hdr_bufp, TS_NULL_MLOC, req_hdr_loc);
- }
- if (req_hdr_bufp) {
- TSMBufferDestroy(req_hdr_bufp);
- }
- if (request_context) {
- ats_ctx_destroy(request_context);
- request_context = NULL;
- }
- };
-};
-
-bool
-InterceptCtx::init(TSVConn vconn)
-{
- if (initialized) {
- TSError("[%s] InterceptCtx already initialized!", __FUNCTION__);
- return false;
- }
-
- net_vc = vconn;
-
- input.buffer = TSIOBufferCreate();
- input.reader = TSIOBufferReaderAlloc(input.buffer);
- input.vio = TSVConnRead(net_vc, contp, input.buffer, INT_MAX);
-
- req_hdr_bufp = TSMBufferCreate();
- req_hdr_loc = TSHttpHdrCreate(req_hdr_bufp);
- TSHttpHdrTypeSet(req_hdr_bufp, req_hdr_loc, TS_HTTP_TYPE_REQUEST);
-
- initialized = true;
- TSDebug(DEBUG_TAG, "[%s] InterceptCtx initialized!", __FUNCTION__);
- return true;
-}
-
-void
-InterceptCtx::setupWrite() {
- TSAssert(output.buffer == 0);
- output.buffer = TSIOBufferCreate();
- output.reader = TSIOBufferReaderAlloc(output.buffer);
- output.vio = TSVConnWrite(net_vc, contp, output.reader, INT_MAX);
-}
-
-// Parses out query params from the request.
-void ps_query_params_handler(StringPiece unparsed_uri, StringPiece* data) {
- stringpiece_ssize_type question_mark_index = unparsed_uri.find("?");
- if (question_mark_index == StringPiece::npos) {
- *data = "";
- } else {
- *data = unparsed_uri.substr(
- question_mark_index+1, unparsed_uri.size() - (question_mark_index+1));
- }
-}
-
-static bool
-handleRead(InterceptCtx *cont_data, bool &read_complete) {
- int avail = TSIOBufferReaderAvail(cont_data->input.reader);
- if (avail == TS_ERROR) {
- TSError("[%s] Error while getting number of bytes available", __FUNCTION__);
- return false;
- }
-
- TSDebug(DEBUG_TAG, "[%s] Parsed header, avail: %d", __FUNCTION__, avail);
-
- int consumed = 0;
- if (avail > 0) {
- int64_t data_len;
- const char *data;
- TSIOBufferBlock block = TSIOBufferReaderStart(cont_data->input.reader);
- while (block != NULL) {
- data = TSIOBufferBlockReadStart(block, cont_data->input.reader, &data_len);
- if (!cont_data->req_hdr_parsed) {
- const char *endptr = data + data_len;
- if (TSHttpHdrParseReq(cont_data->http_parser, cont_data->req_hdr_bufp, cont_data->req_hdr_loc,
- &data, endptr) == TS_PARSE_DONE) {
- TSDebug(DEBUG_TAG, "[%s] Parsed header", __FUNCTION__);
- TSMLoc content_len_loc = TSMimeHdrFieldFind(cont_data->req_hdr_bufp, cont_data->req_hdr_loc,
- TS_MIME_FIELD_CONTENT_LENGTH, -1);
-
- /*if (!content_len_loc) {
- TSError("[%s] Error while searching content length header [%s]",
- __FUNCTION__, TS_MIME_FIELD_CONTENT_LENGTH);
- return false;
- }
- if (!content_len_loc) {
- TSError("[%s] request doesn't contain content length header [%s]",
- __FUNCTION__, TS_MIME_FIELD_CONTENT_TYPE);
- return false;
- }*/
- if (!content_len_loc) {
- cont_data->req_content_len = 0;
- } else {
- cont_data->req_content_len = TSMimeHdrFieldValueIntGet(cont_data->req_hdr_bufp, cont_data->req_hdr_loc,
- content_len_loc, 0);
- TSHandleMLocRelease(cont_data->req_hdr_bufp, cont_data->req_hdr_loc, content_len_loc);
- }
- TSDebug(DEBUG_TAG, "[%s] Got content length as %d", __FUNCTION__, cont_data->req_content_len);
- if (cont_data->req_content_len < 0) {
- TSError("[%s] Invalid content length [%d]", __FUNCTION__, cont_data->req_content_len);
- return false;
- }
- if (endptr - data) {
- TSDebug(DEBUG_TAG, "[%s] Appending %ld bytes to body", __FUNCTION__, static_cast<long int>(endptr - data));
- cont_data->body.append(data, endptr - data);
- }
- cont_data->req_hdr_parsed = true;
- }
- } else {
- //TSDebug(DEBUG_TAG, "[%s] Appending %" PRId64" bytes to body", __FUNCTION__, data_len);
- cont_data->body.append(data, data_len);
- }
- consumed += data_len;
- block = TSIOBufferBlockNext(block);
- }
- }
-
- TSIOBufferReaderConsume(cont_data->input.reader, consumed);
-
- TSDebug(DEBUG_TAG, "[%s] Consumed %d bytes from input vio, avail: %d", __FUNCTION__, consumed, avail);
-
- // Modify the input VIO to reflect how much data we've completed.
- TSVIONDoneSet(cont_data->input.vio, TSVIONDoneGet(cont_data->input.vio) + consumed);
-
- if (static_cast<int>(cont_data->body.size()) == cont_data->req_content_len) {
- TSDebug(DEBUG_TAG, "[%s] Completely read body of size %d", __FUNCTION__, cont_data->req_content_len);
- read_complete = true;
- } else {
- read_complete = false;
- TSDebug(DEBUG_TAG, "[%s] Reenabling input vio as %ld bytes still need to be read",
- __FUNCTION__, static_cast<long int>(cont_data->req_content_len - cont_data->body.size()));
- TSVIOReenable(cont_data->input.vio);
- }
- return true;
-}
-
-static bool
-processRequest(InterceptCtx *cont_data) {
- // OS: Looks like on 5.x we sometimes receive read complete / EOS events twice,
- // which needs looking into. Probably this intercept is doing something it shouldn't
- if (cont_data->output.buffer) {
- TSDebug("ats_speed", "Received read complete / EOS twice?!");
- return true;
- }
- string reply_header("HTTP/1.1 204 No Content\r\n");
- int body_size = static_cast<int>(cont_data->body.size());
- if (cont_data->req_content_len != body_size) {
- TSError("[%s] Read only %d bytes of body; expecting %d bytes", __FUNCTION__, body_size,
- cont_data->req_content_len);
- }
-
- char buf[64];
- //snprintf(buf, 64, "%s: %d\r\n\r\n", TS_MIME_FIELD_CONTENT_LENGTH, body_size);
- snprintf(buf, 64, "%s: %d\r\n\r\n", TS_MIME_FIELD_CONTENT_LENGTH, 0);
- reply_header.append(buf);
- reply_header.append("Cache-Control: max-age=0, no-cache");
- //TSError("[%s] reply header: \n%s", __FUNCTION__, reply_header.data());
-
- StringPiece query_param_beacon_data;
- ps_query_params_handler(cont_data->request_context->url_string->c_str(), &query_param_beacon_data);
-
- GoogleString beacon_data = net_instaweb::StrCat(
- query_param_beacon_data, "&", cont_data->body);
- ServerContext* server_context = cont_data->request_context->server_context;
-
- SystemRequestContext* system_request_context =
- new SystemRequestContext(server_context->thread_system()->NewMutex(),
- server_context->timer(),
- // TODO(oschaaf): determine these for real.
- "www.foo.com",
- 80,
- "127.0.0.1");
-
- if (!server_context->HandleBeacon(
- beacon_data,
- cont_data->request_context->user_agent->c_str(),
- net_instaweb::RequestContextPtr(system_request_context))) {
- TSError("Beacon handling failure!");
- } else {
- TSDebug(DEBUG_TAG, "Beacon post data processed OK: [%s]", beacon_data.c_str());
- }
-
- cont_data->setupWrite();
- if (TSIOBufferWrite(cont_data->output.buffer, reply_header.data(), reply_header.size()) == TS_ERROR) {
- TSError("[%s] Error while writing reply header", __FUNCTION__);
- return false;
- }
- /*
- if (TSIOBufferWrite(cont_data->output.buffer, cont_data->body.data(), body_size) == TS_ERROR) {
- TSError("[%s] Error while writing content", __FUNCTION__);
- return false;
- }*/
- int total_bytes_written = reply_header.size() + body_size;
- TSDebug(DEBUG_TAG, "[%s] Wrote reply of size %d", __FUNCTION__, total_bytes_written);
- TSVIONBytesSet(cont_data->output.vio, total_bytes_written);
-
- TSVIOReenable(cont_data->output.vio);
- return true;
-}
-
-static int
-txn_intercept(TSCont contp, TSEvent event, void *edata) {
- TSDebug(DEBUG_TAG, "[%s] Received event: %d", __FUNCTION__, (int)event);
-
- InterceptCtx *cont_data = static_cast<InterceptCtx *>(TSContDataGet(contp));
- bool read_complete = false;
- bool shutdown = false;
- switch (event) {
- case TS_EVENT_NET_ACCEPT:
- TSDebug(DEBUG_TAG, "[%s] Received net accept event", __FUNCTION__);
- TSAssert(cont_data->initialized == false);
- if (!cont_data->init(static_cast<TSVConn>(edata))) {
- TSError("[%s] Could not initialize continuation data!", __FUNCTION__);
- return 1;
- }
- break;
- case TS_EVENT_VCONN_READ_READY:
- TSDebug(DEBUG_TAG, "[%s] Received read ready event", __FUNCTION__);
- if (!handleRead(cont_data, read_complete)) {
- TSError("[%s] Error while reading from input vio", __FUNCTION__);
- //return 0;
- read_complete = true;
- }
- break;
- case TS_EVENT_VCONN_READ_COMPLETE:
- case TS_EVENT_VCONN_EOS:
- // intentional fall-through
- TSDebug(DEBUG_TAG, "[%s] Received read complete/eos event %d", __FUNCTION__, event);
- read_complete = true;
- break;
- case TS_EVENT_VCONN_WRITE_READY:
- TSDebug(DEBUG_TAG, "[%s] Received write ready event", __FUNCTION__);
- break;
- case TS_EVENT_VCONN_WRITE_COMPLETE:
- TSDebug(DEBUG_TAG, "[%s] Received write complete event", __FUNCTION__);
- shutdown = true;
- break;
- case TS_EVENT_ERROR:
- // todo: do some error handling here
- TSDebug(DEBUG_TAG, "[%s] Received error event; going to shutdown, event: %d", __FUNCTION__, event);
- TSError("[%s] Received error event; going to shutdown, event: %d", __FUNCTION__, event);
- shutdown = true;
- break;
- default:
- break;
- }
-
- if (read_complete) {
- if (!processRequest(cont_data)) {
- TSError("[%s] Failed to process process", __FUNCTION__);
- } else {
- TSDebug(DEBUG_TAG, "[%s] Processed request successfully", __FUNCTION__);
- }
- }
-
- if (shutdown) {
- TSDebug(DEBUG_TAG, "[%s] Completed request processing. Shutting down...", __FUNCTION__);
- if (cont_data->net_vc) {
- TSVConnClose(cont_data->net_vc);
- }
- delete cont_data;
- TSContDestroy(contp);
- }
-
- return 1;
-}
-
-bool
-hook_beacon_intercept(TSHttpTxn txnp) {
- TSCont contp = TSContCreate(txn_intercept, TSMutexCreate());
- if (!contp) {
- TSError("[%s] Could not create intercept request", __FUNCTION__);
- return false;
- }
- InterceptCtx *cont_data = new InterceptCtx(contp);
- cont_data->request_context = get_transaction_context(txnp);
- TSContDataSet(contp, cont_data);
- TSHttpTxnIntercept(contp, txnp);
- TSDebug(DEBUG_TAG, "[%s] Setup server intercept successfully", __FUNCTION__);
- return true;
-}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1fe51067/plugins/experimental/ats_speed/ats_beacon_intercept.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/ats_speed/ats_beacon_intercept.h b/plugins/experimental/ats_speed/ats_beacon_intercept.h
deleted file mode 100644
index d53d81c..0000000
--- a/plugins/experimental/ats_speed/ats_beacon_intercept.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#ifndef _ATS_BEACON_INTERCEPT_H
-#define _ATS_BEACON_INTERCEPT_H
-
-#include "ts/ts.h"
-
-bool hook_beacon_intercept(TSHttpTxn txnp);
-
-#endif
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1fe51067/plugins/experimental/ats_speed/ats_config.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/ats_speed/ats_config.cc b/plugins/experimental/ats_speed/ats_config.cc
deleted file mode 100644
index e0adf42..0000000
--- a/plugins/experimental/ats_speed/ats_config.cc
+++ /dev/null
@@ -1,204 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#include "ats_config.h"
-
-#include <ts/ts.h>
-#include <fstream>
-
-#include "net/instaweb/util/public/string_util.h"
-
-#include "ats_message_handler.h"
-#include "ats_rewrite_options.h"
-
-namespace net_instaweb {
-
-using namespace std;
-
-
-
-void ltrim_if(string& s, int (* fp) (int)) {
- for (size_t i = 0; i < s.size();) {
- if (fp(s[i])) {
- s.erase(i,1);
- } else {
- break;
- }
- }
-}
-
-void rtrim_if(string& s, int (* fp) (int)) {
- for (ssize_t i = (ssize_t)s.size() - 1; i >= 0; i--) {
- if (fp(s[i])) {
- s.erase(i,1);
- } else {
- break;
- }
- }
-}
-
-void trim_if(string& s, int (* fp) (int)) {
- ltrim_if(s, fp);
- rtrim_if(s, fp);
-}
-
-vector<string> tokenize(const string &s, int (* fp) (int)) {
- vector<string> r;
- string tmp;
-
- for (size_t i = 0; i < s.size(); i++) {
- if ( fp(s[i]) ) {
- if ( tmp.size() ) {
- r.push_back(tmp);
- tmp = "";
- }
- } else {
- tmp += s[i];
- }
- }
-
- if ( tmp.size() ) {
- r.push_back(tmp);
- }
-
- return r;
-}
-
-AtsConfig::AtsConfig(AtsThreadSystem* thread_system)
- : thread_system_(thread_system) {
- AddHostConfig(new AtsHostConfig(GoogleString("(XXXXXX)"), new AtsRewriteOptions(thread_system_)));
-}
-
-AtsConfig::~AtsConfig() {
- for (size_t i = 0; i < host_configurations_.size(); i++) {
- delete host_configurations_[i];
- host_configurations_.clear();
- }
-}
-
-void AtsConfig::AddHostConfig(AtsHostConfig* hc){
- host_configurations_.push_back(hc);
-}
-
-AtsHostConfig::~AtsHostConfig() {
- if (options_ != NULL) {
- delete options_;
- options_ = NULL;
- }
-}
-
-AtsHostConfig * AtsConfig::Find(const char * host, int host_length) {
- AtsHostConfig * host_configuration = host_configurations_[0];
-
- std::string shost(host, host_length);
-
- for (size_t i = 1; i < host_configurations_.size(); i++ ) {
- if (host_configurations_[i]->host() == shost){
- host_configuration = host_configurations_[i];
- break;
- }
- }
-
- return host_configuration;
-}
-
-bool AtsConfig::Parse(const char * path ) {
- string pathstring(path);
-
- // If we have a path and it's not an absolute path, make it relative to the
- // configuration directory.
- if (!pathstring.empty() && pathstring[0] != '/') {
- pathstring.assign(TSConfigDirGet());
- pathstring.append("/");
- pathstring.append(path);
- }
-
- trim_if(pathstring, isspace);
-
- AtsHostConfig* current_host_configuration = host_configurations_[0];
-
- if (pathstring.empty()) {
- TSError("Empty path passed in AtsConfig::Parse");
- return false;
- }
-
- path = pathstring.c_str();
- std::ifstream f;
-
- size_t lineno = 0;
-
- f.open(path, std::ios::in);
-
- if (!f.is_open()) {
- TSError("could not open file [%s], skip",path);
- return false;
- }
-
-
- while (!f.eof()) {
- std::string line;
- getline(f, line);
- ++lineno;
-
- trim_if(line, isspace);
- if (line.size() == 0) {
- continue;
- }
- if (line[0] == '#') {
- continue;
- }
-
- vector<string> v = tokenize( line, isspace );
- if (v.size() == 0)
- continue;
- GoogleString msg;
- AtsMessageHandler handler(thread_system_->NewMutex());
- if (v.size() == 1) {
- string token = v[0];
- if ((token[0] == '[') && (token[token.size()-1] == ']')) {
- GoogleString current_host = token.substr(1, token.size() - 2);
- current_host_configuration = new AtsHostConfig(current_host, new AtsRewriteOptions(thread_system_));
- AddHostConfig(current_host_configuration);
- } else if (StringCaseEqual(token,"override_expiry")) {
- current_host_configuration->set_override_expiry(true);
- } else {
- msg = "unknown single token on a line";
- }
- } else {
- global_settings settings;
- v.erase (v.begin());
- const char* err = current_host_configuration->options()->ParseAndSetOptions(v, &handler, settings);
- if (err) {
- msg.append(err);
- }
- }
- if (msg.size() > 0) {
- TSDebug("ats-speed", "Error parsing line [%s]: [%s]", line.c_str(), msg.c_str());
- }
- }
-
- return true;
-}
-
-
-} // namespace net_instaweb
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1fe51067/plugins/experimental/ats_speed/ats_config.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/ats_speed/ats_config.h b/plugins/experimental/ats_speed/ats_config.h
deleted file mode 100644
index d3b0e40..0000000
--- a/plugins/experimental/ats_speed/ats_config.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#ifndef ATS_CONFIG_H_
-#define ATS_CONFIG_H_
-
-#include <string>
-#include <vector>
-
-#include <ts/ts.h>
-
-#include "ats_thread_system.h"
-
-#include "net/instaweb/util/public/string.h"
-#include "net/instaweb/util/public/string_util.h"
-
-
-namespace net_instaweb {
-
-class AtsRewriteOptions;
-
-class AtsHostConfig {
-public:
- explicit AtsHostConfig(const GoogleString & host, AtsRewriteOptions* options)
- : host_(host)
- , options_(options)
- {
- }
- virtual ~AtsHostConfig();
-
- inline GoogleString host() { return host_; }
- inline AtsRewriteOptions* options() { return options_; }
- inline bool override_expiry() { return override_expiry_; }
- inline void set_override_expiry(bool x) { override_expiry_ = x; }
-private:
- GoogleString host_;
- AtsRewriteOptions* options_;
- bool override_expiry_;
- DISALLOW_COPY_AND_ASSIGN(AtsHostConfig);
-}; // class AtsHostConfig
-
-class AtsConfig {
- friend class AtsHostConfig;
-public:
- explicit AtsConfig(AtsThreadSystem* thread_system);
- virtual ~AtsConfig();
-
- // TODO(oschaaf): destructor??
- bool Parse(const char * path);
- AtsHostConfig * Find(const char * host, int host_length);
- inline AtsHostConfig * GlobalConfiguration() {
- return host_configurations_[0];
- }
- AtsThreadSystem* thread_system() {
- return thread_system_;
- }
-
-private:
- void AddHostConfig(AtsHostConfig* hc);
-
- std::vector<AtsHostConfig *> host_configurations_;
- AtsThreadSystem* thread_system_;
- //todo: destructor. delete owned host configurations
- DISALLOW_COPY_AND_ASSIGN(AtsConfig);
-}; // class Configuration
-
-
-} // namespace net_instaweb
-
-#endif // ATS_CONFIG_H
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1fe51067/plugins/experimental/ats_speed/ats_header_utils.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/ats_speed/ats_header_utils.cc b/plugins/experimental/ats_speed/ats_header_utils.cc
deleted file mode 100644
index a61c784..0000000
--- a/plugins/experimental/ats_speed/ats_header_utils.cc
+++ /dev/null
@@ -1,96 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#include "ats_header_utils.h"
-
-GoogleString get_header(TSMBuffer bufp, TSMLoc hdr_loc, const char * header_name)
-{
- const char * val = NULL;
- int val_len;
- TSMLoc field_loc = TSMimeHdrFieldFind( bufp, hdr_loc, header_name, -1);
-
- if (field_loc) {
- val = TSMimeHdrFieldValueStringGet (bufp, hdr_loc, field_loc, 0, &val_len);
- TSHandleMLocRelease(bufp,hdr_loc,field_loc);
- return GoogleString(val,val_len);
- }
-
- return GoogleString("");
-}
-
-void unset_header(TSMBuffer bufp, TSMLoc hdr_loc, const char * header_name)
-{
- TSMLoc field_loc = TSMimeHdrFieldFind( bufp, hdr_loc, header_name, -1);
-
- if (field_loc) {
- TSMimeHdrFieldDestroy(bufp, hdr_loc, field_loc);
- TSHandleMLocRelease(bufp, hdr_loc, field_loc);
- }
-}
-
-void hide_accept_encoding(TSMBuffer reqp, TSMLoc hdr_loc, const char * hidden_header_name)
-{
- TSMLoc field = TSMimeHdrFieldFind(reqp, hdr_loc, TS_MIME_FIELD_ACCEPT_ENCODING, TS_MIME_LEN_ACCEPT_ENCODING);
- while (field) {
- TSMLoc tmp;
- tmp = TSMimeHdrFieldNextDup(reqp, hdr_loc, field);
- TSMimeHdrFieldNameSet(reqp, hdr_loc, field, hidden_header_name, -1);
- TSHandleMLocRelease(reqp, hdr_loc, field);
- field = tmp;
- }
-}
-
-void restore_accept_encoding(TSMBuffer reqp, TSMLoc hdr_loc, const char * hidden_header_name)
-{
- TSMLoc field = TSMimeHdrFieldFind(reqp, hdr_loc, hidden_header_name, -1);
-
- while (field) {
- TSMLoc tmp;
- tmp = TSMimeHdrFieldNextDup(reqp, hdr_loc, field);
- TSMimeHdrFieldNameSet(reqp, hdr_loc, field, TS_MIME_FIELD_ACCEPT_ENCODING, TS_MIME_LEN_ACCEPT_ENCODING);
- TSHandleMLocRelease(reqp, hdr_loc, field);
- field = tmp;
- }
-}
-
-void set_header(TSMBuffer bufp, TSMLoc hdr_loc, const char * header_name, const char * header_value)
-{
- TSMLoc field_loc = TSMimeHdrFieldFind( bufp, hdr_loc, header_name, -1);
-
- if (field_loc) {
- TSMimeHdrFieldValueStringSet(bufp, hdr_loc, field_loc, -1, header_value, -1);
- } else {
- if ( TSMimeHdrFieldCreate(bufp, hdr_loc, &field_loc) == TS_SUCCESS ) {
- TSMimeHdrFieldNameSet(bufp, hdr_loc, field_loc, header_name, -1);
- TSMimeHdrFieldAppend(bufp, hdr_loc, field_loc);
- TSMimeHdrFieldValueStringSet(bufp,hdr_loc,field_loc,-1,header_value,-1);
- } else {
- TSError("field creation error for field [%s]", header_name);
- return;
- }
- }
-
- if (field_loc) {
- TSHandleMLocRelease(bufp,hdr_loc,field_loc);
- }
-}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1fe51067/plugins/experimental/ats_speed/ats_header_utils.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/ats_speed/ats_header_utils.h b/plugins/experimental/ats_speed/ats_header_utils.h
deleted file mode 100644
index 1d6c567..0000000
--- a/plugins/experimental/ats_speed/ats_header_utils.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#ifndef ATS_HEADER_UTILS_H
-#define ATS_HEADER_UTILS_H
-
-#include <string>
-
-#include <ts/ts.h>
-
-#include "net/instaweb/util/public/string.h"
-#include "net/instaweb/util/public/string_util.h"
-
-
-GoogleString get_header(TSMBuffer bufp, TSMLoc hdr_loc, const char * header_name);
-void unset_header(TSMBuffer bufp, TSMLoc hdr_loc, const char * header_name);
-void hide_accept_encoding(TSMBuffer reqp, TSMLoc hdr_loc, const char * hidden_header_name);
-void restore_accept_encoding(TSMBuffer reqp, TSMLoc hdr_loc, const char * hidden_header_name);
-void set_header(TSMBuffer bufp, TSMLoc hdr_loc, const char * header_name, const char * header_value);
-
-#endif // ATS_HEADER_UTILS_H
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1fe51067/plugins/experimental/ats_speed/ats_log_message_handler.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/ats_speed/ats_log_message_handler.cc b/plugins/experimental/ats_speed/ats_log_message_handler.cc
deleted file mode 100644
index f41b9cc..0000000
--- a/plugins/experimental/ats_speed/ats_log_message_handler.cc
+++ /dev/null
@@ -1,101 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#include "ats_log_message_handler.h"
-
-#include <ts/ts.h>
-
-#include <unistd.h>
-
-#include <limits>
-#include <string>
-
-#include "base/debug/debugger.h"
-#include "base/debug/stack_trace.h"
-#include "base/logging.h"
-#include "net/instaweb/public/version.h"
-#include "net/instaweb/util/public/string_util.h"
-
-// Make sure we don't attempt to use LOG macros here, since doing so
-// would cause us to go into an infinite log loop.
-#undef LOG
-#define LOG USING_LOG_HERE_WOULD_CAUSE_INFINITE_RECURSION
-
-namespace {
-
-bool LogMessageHandler(int severity, const char* file, int line,
- size_t message_start, const GoogleString& str) {
- GoogleString message = str;
- if (severity == logging::LOG_FATAL) {
- if (base::debug::BeingDebugged()) {
- base::debug::BreakDebugger();
- } else {
- base::debug::StackTrace trace;
- std::ostringstream stream;
- trace.OutputToStream(&stream);
- message.append(stream.str());
- }
- }
-
- // Trim the newline off the end of the message string.
- size_t last_msg_character_index = message.length() - 1;
- if (message[last_msg_character_index] == '\n') {
- message.resize(last_msg_character_index);
- }
-
- TSDebug("ats-speed-vlog", "[%s] %s",
- net_instaweb::kModPagespeedVersion,
- message.c_str());
-
- if (severity == logging::LOG_FATAL) {
- // Crash the process to generate a dump.
- base::debug::BreakDebugger();
- }
-
- return true;
-}
-
-} // namespace
-
-
-namespace net_instaweb {
-
-namespace log_message_handler {
-
-
-const int kDebugLogLevel = -2;
-
-void Install() {
- logging::SetLogMessageHandler(&LogMessageHandler);
-
- // All VLOG(2) and higher will be displayed as DEBUG logs if the nginx log
- // level is DEBUG.
- // TODO(oschaaf): from config
- //if (log->log_level >= NGX_LOG_DEBUG) {
- logging::SetMinLogLevel(-2);
- //}
-}
-
-} // namespace log_message_handler
-
-} // namespace net_instaweb
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1fe51067/plugins/experimental/ats_speed/ats_log_message_handler.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/ats_speed/ats_log_message_handler.h b/plugins/experimental/ats_speed/ats_log_message_handler.h
deleted file mode 100644
index bf57634..0000000
--- a/plugins/experimental/ats_speed/ats_log_message_handler.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#ifndef ATS_LOG_MESSAGE_HANDLER_H_
-#define ATS_LOG_MESSAGE_HANDLER_H_
-
-
-namespace net_instaweb {
-
- namespace log_message_handler {
- void Install();
- } // namespace log_message_handler
-
-} // namespace net_instaweb
-
-#endif // ATS_LOG_MESSAGE_HANDLER_H_
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1fe51067/plugins/experimental/ats_speed/ats_message_handler.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/ats_speed/ats_message_handler.cc b/plugins/experimental/ats_speed/ats_message_handler.cc
deleted file mode 100644
index 370f317..0000000
--- a/plugins/experimental/ats_speed/ats_message_handler.cc
+++ /dev/null
@@ -1,114 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#include "ats_message_handler.h"
-
-#include <signal.h>
-#include <unistd.h>
-
-#include "net/instaweb/util/public/abstract_mutex.h"
-#include "net/instaweb/util/public/debug.h"
-#include "net/instaweb/util/public/shared_circular_buffer.h"
-#include "net/instaweb/util/public/string_util.h"
-#include "net/instaweb/public/version.h"
-#include "pagespeed/kernel/base/posix_timer.h"
-#include "pagespeed/kernel/base/time_util.h"
-
-
-namespace {
-
-// This will be prefixed to every logged message.
-const char kModuleName[] = "ats_pagespeed";
-
-} // namespace
-
-namespace net_instaweb {
-
-AtsMessageHandler::AtsMessageHandler(AbstractMutex* mutex)
- : mutex_(mutex),
- buffer_(NULL) {
- SetPidString(static_cast<int64>(getpid()));
-}
-
-
-bool AtsMessageHandler::Dump(Writer* writer) {
- // Can't dump before SharedCircularBuffer is set up.
- if (buffer_ == NULL) {
- return false;
- }
- return buffer_->Dump(writer, &handler_);
-}
-
-void AtsMessageHandler::set_buffer(SharedCircularBuffer* buff) {
- ScopedMutex lock(mutex_.get());
- buffer_ = buff;
-}
-
-void AtsMessageHandler::MessageVImpl(MessageType type, const char* msg,
- va_list args) {
- GoogleString formatted_message = Format(msg, args);
-
- TSDebug("ats-speed", "[%s %s] %s", kModuleName, kModPagespeedVersion,
- formatted_message.c_str());
-
- // Prepare a log message for the SharedCircularBuffer only.
- // Prepend time and severity to message.
- // Format is [time] [severity] [pid] message.
- GoogleString message;
- GoogleString time;
- PosixTimer timer;
- if (!ConvertTimeToString(timer.NowMs(), &time)) {
- time = "?";
- }
-
- StrAppend(&message, "[", time, "] ",
- "[", MessageTypeToString(type), "] ");
- StrAppend(&message, pid_string_, " ", formatted_message, "\n");
- {
- ScopedMutex lock(mutex_.get());
- if (buffer_ != NULL) {
- buffer_->Write(message);
- }
- }
-}
-
-void AtsMessageHandler::FileMessageVImpl(MessageType type, const char* file,
- int line, const char* msg,
- va_list args) {
- GoogleString formatted_message = Format(msg, args);
- TSDebug("ats-speed", "[%s %s] %s:%d:%s",
- kModuleName, kModPagespeedVersion, file, line,
- formatted_message.c_str());
-}
-
-// TODO(sligocki): It'd be nice not to do so much string copying.
-GoogleString AtsMessageHandler::Format(const char* msg, va_list args) {
- GoogleString buffer;
-
- // Ignore the name of this routine: it formats with vsnprintf.
- // See base/stringprintf.cc.
- StringAppendV(&buffer, msg, args);
- return buffer;
-}
-
-} // namespace net_instaweb
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1fe51067/plugins/experimental/ats_speed/ats_message_handler.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/ats_speed/ats_message_handler.h b/plugins/experimental/ats_speed/ats_message_handler.h
deleted file mode 100644
index b8248cf..0000000
--- a/plugins/experimental/ats_speed/ats_message_handler.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#ifndef NGX_MESSAGE_HANDLER_H_
-#define NGX_MESSAGE_HANDLER_H_
-
-#include <ts/ts.h>
-#include <cstdarg>
-
-#include "net/instaweb/util/public/basictypes.h"
-#include "net/instaweb/util/public/google_message_handler.h"
-#include "net/instaweb/util/public/message_handler.h"
-#include "net/instaweb/util/public/scoped_ptr.h"
-#include "net/instaweb/util/public/string.h"
-#include "net/instaweb/util/public/string_util.h"
-
-namespace net_instaweb {
-
- class AbstractMutex;
- class SharedCircularBuffer;
- class Timer;
- class Writer;
-
- class AtsMessageHandler : public GoogleMessageHandler {
- public:
- explicit AtsMessageHandler(AbstractMutex* mutex);
-
- void set_buffer(SharedCircularBuffer* buff);
-
- void SetPidString(const int64 pid) {
- pid_string_ = StrCat("[", Integer64ToString(pid), "]");
- }
- // Dump contents of SharedCircularBuffer.
- bool Dump(Writer* writer);
-
- protected:
- virtual void MessageVImpl(MessageType type, const char* msg, va_list args);
-
- virtual void FileMessageVImpl(MessageType type, const char* filename,
- int line, const char* msg, va_list args);
-
- private:
- GoogleString Format(const char* msg, va_list args);
-
- scoped_ptr<AbstractMutex> mutex_;
- GoogleString pid_string_;
- GoogleMessageHandler handler_;
- SharedCircularBuffer* buffer_;
-
- DISALLOW_COPY_AND_ASSIGN(AtsMessageHandler);
- };
-
-} // namespace net_instaweb
-
-#endif // NGX_MESSAGE_HANDLER_H_
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1fe51067/plugins/experimental/ats_speed/ats_process_context.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/ats_speed/ats_process_context.cc b/plugins/experimental/ats_speed/ats_process_context.cc
deleted file mode 100644
index f3ca481..0000000
--- a/plugins/experimental/ats_speed/ats_process_context.cc
+++ /dev/null
@@ -1,86 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#include "ats_process_context.h"
-
-#include <vector>
-
-#include "ats_rewrite_driver_factory.h"
-#include "ats_server_context.h"
-#include "ats_message_handler.h"
-#include "ats_thread_system.h"
-
-#include "net/instaweb/automatic/public/proxy_fetch.h"
-#include "net/instaweb/util/public/pthread_shared_mem.h"
-
-namespace net_instaweb {
-
- AtsProcessContext::AtsProcessContext() : ProcessContext() {
- AtsThreadSystem* ts = new AtsThreadSystem();
- message_handler_.reset(new AtsMessageHandler(ts->NewMutex()));
- driver_factory_.reset(
- new AtsRewriteDriverFactory(
- *this, ts, ""/*hostname, not used*/, -1/*port, not used*/));
- server_context_ = driver_factory()->MakeAtsServerContext();
-
- AtsRewriteOptions* root_options_ = (AtsRewriteOptions*)driver_factory_->default_options();
- AtsRewriteOptions* server_options = root_options_->Clone();
- AtsRewriteOptions* options = new AtsRewriteOptions(driver_factory_->thread_system());
- server_options->Merge(*options);
- delete options;
-
- server_context_->global_options()->Merge(*server_options);
- delete server_options;
-
- message_handler_->Message(kInfo,"global default options:\r\n[%s]",driver_factory_->default_options()->OptionsToString().c_str());
- message_handler_->Message(kInfo,"server ctx default options:\r\n[%s]",server_context_->global_options()->OptionsToString().c_str());
- std::vector<SystemServerContext*> server_contexts;
- server_contexts.push_back(server_context_);
-
- //Statistics* statistics =
- // driver_factory_->MakeGlobalSharedMemStatistics(*(SystemRewriteOptions*)server_context_->global_options());
- GoogleString error_message;
- int error_index = -1;
- Statistics* global_statistics = NULL;
- driver_factory_.get()->PostConfig(
- server_contexts, &error_message, &error_index, &global_statistics);
- if (error_index != -1) {
- server_contexts[error_index]->message_handler()->Message(
- kError, "ngx_pagespeed is enabled. %s", error_message.c_str());
- //return NGX_ERROR;
- CHECK(false);
- }
-
- AtsRewriteDriverFactory::InitStats(global_statistics);
-
- driver_factory()->RootInit();
- driver_factory()->ChildInit();
-
- proxy_fetch_factory_.reset(new ProxyFetchFactory(server_context_));
- message_handler_->Message(kInfo, "Process context constructed");
-}
-
-AtsProcessContext::~AtsProcessContext() {
-}
-
-} // namespace net_instaweb
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1fe51067/plugins/experimental/ats_speed/ats_process_context.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/ats_speed/ats_process_context.h b/plugins/experimental/ats_speed/ats_process_context.h
deleted file mode 100644
index aa344b2..0000000
--- a/plugins/experimental/ats_speed/ats_process_context.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#ifndef ATS_PROCESS_CONTEXT_H_
-#define ATS_PROCESS_CONTEXT_H_
-
-#include "net/instaweb/util/public/google_message_handler.h"
-#include "net/instaweb/util/public/message_handler.h"
-#include "net/instaweb/util/public/scoped_ptr.h"
-#include "net/instaweb/rewriter/public/process_context.h"
-
-namespace net_instaweb {
-
-class AtsRewriteDriverFactory;
-class ProxyFetchFactory;
-class AtsServerContext;
-
-class AtsProcessContext : ProcessContext {
- public:
- explicit AtsProcessContext();
- virtual ~AtsProcessContext();
-
- // TODO(oschaaf): const correctness
- MessageHandler* message_handler() { return message_handler_.get(); }
- AtsRewriteDriverFactory* driver_factory() { return driver_factory_.get(); }
- ProxyFetchFactory* proxy_fetch_factory() { return proxy_fetch_factory_.get(); }
- AtsServerContext* server_context() { return server_context_; }
- private:
- scoped_ptr<MessageHandler> message_handler_;
- scoped_ptr<AtsRewriteDriverFactory> driver_factory_;
- scoped_ptr<ProxyFetchFactory> proxy_fetch_factory_;
- AtsServerContext* server_context_;
-};
-
-
-} // namespace net_instaweb
-
-#endif // ATS_PROCESS_CONTEXT_H_
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1fe51067/plugins/experimental/ats_speed/ats_resource_intercept.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/ats_speed/ats_resource_intercept.cc b/plugins/experimental/ats_speed/ats_resource_intercept.cc
deleted file mode 100644
index 0afeae5..0000000
--- a/plugins/experimental/ats_speed/ats_resource_intercept.cc
+++ /dev/null
@@ -1,363 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#include <ts/ts.h>
-
-#include <stdio.h>
-
-#include "ats_resource_intercept.h"
-
-
-#include "ats_base_fetch.h"
-#include "ats_rewrite_driver_factory.h"
-#include "ats_rewrite_options.h"
-#include "ats_server_context.h"
-#include "ats_speed.h"
-
-#include "net/instaweb/http/public/request_context.h"
-#include "net/instaweb/rewriter/public/resource_fetch.h"
-#include "net/instaweb/rewriter/public/static_asset_manager.h"
-#include "net/instaweb/system/public/system_request_context.h"
-
-#include "net/instaweb/util/public/string_writer.h"
-
-
-using namespace net_instaweb;
-
-struct InterceptCtx
-{
- TSVConn vconn;
- TSIOBuffer req_buffer;
- TSIOBufferReader req_reader;
- TSIOBuffer resp_buffer;
- TSIOBufferReader resp_reader;
- GoogleString* response;
- TransformCtx* request_ctx;
- RequestHeaders* request_headers;
-
- InterceptCtx()
- : vconn(NULL)
- , req_buffer(NULL)
- , req_reader(NULL)
- , resp_buffer(NULL)
- , resp_reader(NULL)
- , response( new GoogleString() )
- , request_ctx(NULL)
- , request_headers(NULL)
- {
- };
-};
-
-static void
-shutdown (TSCont cont, InterceptCtx * intercept_ctx) {
- if (intercept_ctx->req_reader != NULL) {
- TSIOBufferReaderFree(intercept_ctx->req_reader);
- intercept_ctx->req_reader = NULL;
- }
- if (intercept_ctx->req_buffer != NULL) {
- TSIOBufferDestroy(intercept_ctx->req_buffer);
- intercept_ctx->req_buffer = NULL;
- }
- if (intercept_ctx->resp_reader != NULL) {
- TSIOBufferReaderFree(intercept_ctx->resp_reader);
- intercept_ctx->resp_reader = NULL;
- }
- if (intercept_ctx->resp_buffer != NULL) {
- TSIOBufferDestroy(intercept_ctx->resp_buffer);
- intercept_ctx->resp_buffer = NULL;
- }
- if (intercept_ctx->vconn != NULL) {
- TSVConnShutdown(intercept_ctx->vconn, 0, 1);
- TSVConnClose(intercept_ctx->vconn);
- intercept_ctx->vconn = NULL;
- }
- if (intercept_ctx->response != NULL) {
- delete intercept_ctx->response;
- intercept_ctx->response = NULL;
- }
- // TODO(oschaaf): think the ordering of this one through.
- if (intercept_ctx->request_ctx) {
- ats_ctx_destroy(intercept_ctx->request_ctx);
- intercept_ctx->request_ctx = NULL;
- }
- if (intercept_ctx->request_headers != NULL) {
- delete intercept_ctx->request_headers;
- intercept_ctx->request_headers = NULL;
- }
- delete intercept_ctx;
- TSContDestroy(cont);
-}
-
-static int
-resource_intercept(TSCont cont, TSEvent event, void *edata)
-{
- InterceptCtx *intercept_ctx = static_cast<InterceptCtx *>(TSContDataGet(cont));
- bool shutDown = false;
-
- // TODO(oschaaf): have a look at https://github.com/apache/trafficserver/blob/master/plugins/experimental/esi/serverIntercept.c
- // and see if we have any edge cases we should fix.
- switch (event) {
- case TS_EVENT_NET_ACCEPT: {
- intercept_ctx->vconn = static_cast<TSVConn>(edata);
- intercept_ctx->req_buffer = TSIOBufferCreate();
- intercept_ctx->req_reader = TSIOBufferReaderAlloc(intercept_ctx->req_buffer);
- intercept_ctx->resp_buffer = TSIOBufferCreate();
- intercept_ctx->resp_reader = TSIOBufferReaderAlloc(intercept_ctx->resp_buffer);
- TSVConnRead(intercept_ctx->vconn, cont, intercept_ctx->req_buffer, 0x7fffffff);
- } break;
- case TS_EVENT_VCONN_READ_READY: {
- CHECK(intercept_ctx->request_ctx->base_fetch == NULL) << "Base fetch must not be set!";
- CHECK(intercept_ctx->request_ctx->url_string != NULL) << "Url must be set!";
-
- TSVConnShutdown(intercept_ctx->vconn, 1, 0);
-
- // response will already have a size for internal pages at this point.
- // resources, however, will have to be fetched.
- // TODO(oschaaf): this is extremely ugly.
- if (intercept_ctx->response->size() == 0) {
- // TODO(oschaaf): unused - must we close / clean this up?
- TSVIO downstream_vio = TSVConnWrite(
- intercept_ctx->vconn, cont, intercept_ctx->resp_reader, 0x7fffffff);
-
- AtsServerContext* server_context = intercept_ctx->request_ctx->server_context;
-
- // TODO:(oschaaf) host/port
- SystemRequestContext* system_request_context =
- new SystemRequestContext(server_context->thread_system()->NewMutex(),
- server_context->timer(),
- "www.foo.com",// TODO(oschaaf): compute these
- 80,
- "127.0.0.1");
-
- intercept_ctx->request_ctx->base_fetch = new AtsBaseFetch(
- server_context, RequestContextPtr(system_request_context),
- downstream_vio, intercept_ctx->resp_buffer, true);
- intercept_ctx->request_ctx->base_fetch->set_request_headers(
- intercept_ctx->request_headers);
-
- RewriteOptions* options = NULL;
-
- //const char* host = intercept_ctx->request_headers->Lookup1(HttpAttributes::kHost);
- const char* host = intercept_ctx->request_ctx->gurl->HostAndPort().as_string().c_str();
- if (host != NULL && strlen(host) > 0) {
- intercept_ctx->request_ctx->options = get_host_options(host);
- }
-
- // TODO(oschaaf): directory options should be coming from configuration!
- bool ok = ps_determine_options(server_context,
- intercept_ctx->request_ctx->options,
- intercept_ctx->request_ctx->base_fetch->request_headers(),
- intercept_ctx->request_ctx->base_fetch->response_headers(),
- &options,
- intercept_ctx->request_ctx->gurl);
-
- // Take ownership of custom_options.
- scoped_ptr<RewriteOptions> custom_options(options);
-
- if (!ok) {
- TSError("Failure while determining request options for psol resource");
- // options = server_context->global_options();
- } else {
- // ps_determine_options modified url, removing any ModPagespeedFoo=Bar query
- // parameters. Keep url_string in sync with url.
- // TODO(oschaaf): we really should determine if we have to do the lookup
- intercept_ctx->request_ctx->gurl->Spec().CopyToString(intercept_ctx->request_ctx->url_string);
- }
-
- // The url we have here is already checked for IsWebValid()
- net_instaweb::ResourceFetch::Start(
- GoogleUrl(*intercept_ctx->request_ctx->url_string),
- custom_options.release() /* null if there aren't custom options */,
- false /* using_spdy */, server_context, intercept_ctx->request_ctx->base_fetch);
- } else {
- int64_t numBytesToWrite, numBytesWritten;
- numBytesToWrite = intercept_ctx->response->size();
- numBytesWritten = TSIOBufferWrite(intercept_ctx->resp_buffer,
- intercept_ctx->response->c_str(), numBytesToWrite);
-
- if (numBytesWritten == numBytesToWrite) {
- TSVConnWrite(intercept_ctx->vconn, cont, intercept_ctx->resp_reader, numBytesToWrite);
- } else {
- TSError("Not all output could be written in one go");
- DCHECK(false);
- }
- }
- } break;
- case TS_EVENT_VCONN_EOS:
- TSVConnShutdown(intercept_ctx->vconn, 1, 0);
- break;
- case TS_EVENT_VCONN_READ_COMPLETE: {
- TSVConnShutdown(intercept_ctx->vconn, 1, 0);
- } break;
- case TS_EVENT_VCONN_WRITE_READY:
- break;
- case TS_EVENT_VCONN_WRITE_COMPLETE:
- shutDown = true;
- break;
- case TS_EVENT_ERROR:
- TSError("vconn event: error %s", intercept_ctx->request_ctx->url_string->c_str());
- shutDown = true;
- break;
- case TS_EVENT_NET_ACCEPT_FAILED:
- TSError("vconn event: accept failed");
- shutDown = true;
- break;
- case TS_EVENT_IMMEDIATE:
- case TS_EVENT_TIMEOUT:
- break;
- default:
- TSError("default clause event: %d", event);
- break;
- }
-
- if (shutDown) {
- shutdown(cont, intercept_ctx);
- }
-
- return 1;
-}
-
-// We intercept here because serving from ats's own cache is faster
-// then serving from pagespeed's cache. (which needs to be looked in to)
-static int
-read_cache_header_callback(TSCont cont, TSEvent event, void *edata)
-{
- TSHttpTxn txn = static_cast<TSHttpTxn>(edata);
- TransformCtx* ctx = get_transaction_context(txn);
-
- if (ctx == NULL) {
- TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE);
- return 0;
- }
- if (!ctx->resource_request) {
- TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE);
- return 0;
- }
- // TODO(oschaaf): FIXME: Ownership of ctx has become too mucky.
- // This is because I realised too late that the intercepts
- // are able to outlive the transaction, which I hacked
- // to work.
- if (TSHttpIsInternalRequest(txn) == TS_SUCCESS) {
- ats_ctx_destroy(ctx);
- TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE);
- return 0;
- }
-
- if (cache_hit(txn)) {
- ats_ctx_destroy(ctx);
- TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE);
- return 0;
- }
-
- AtsServerContext* server_context = ctx->server_context;
- AtsRewriteDriverFactory* factory = (AtsRewriteDriverFactory*)server_context->factory();
- GoogleString output;
- StringWriter writer(&output);
- HttpStatus::Code status = HttpStatus::kOK;
- ContentType content_type = kContentTypeHtml;
- StringPiece cache_control = HttpAttributes::kNoCache;
- const char* error_message = NULL;
- StringPiece request_uri_path = ctx->gurl->PathAndLeaf();
-
- if (false && ctx->gurl->PathSansQuery() == "/robots.txt") {
- content_type = kContentTypeText;
- writer.Write("User-agent: *\n", server_context->message_handler());
- writer.Write("Disallow: /\n", server_context->message_handler());
- }
-
- // TODO(oschaaf): /pagespeed_admin handling
- else {
- // Optimized resource are highly cacheable (1 year expiry)
- // TODO(oschaaf): configuration
- TSHttpTxnRespCacheableSet(txn, 1);
- TSHttpTxnReqCacheableSet(txn, 1);
-
- TSMBuffer reqp;
- TSMLoc req_hdr_loc;
- if (TSHttpTxnClientReqGet(ctx->txn, &reqp, &req_hdr_loc) != TS_SUCCESS) {
- TSError("Error TSHttpTxnClientReqGet for resource!");
- TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE);
- return 0;
- }
-
- TSCont interceptCont = TSContCreate(resource_intercept, TSMutexCreate());
- InterceptCtx *intercept_ctx = new InterceptCtx();
- intercept_ctx->request_ctx = ctx;
- intercept_ctx->request_headers = new RequestHeaders();
- copy_request_headers_to_psol(reqp, req_hdr_loc, intercept_ctx->request_headers);
- TSHandleMLocRelease(reqp, TS_NULL_MLOC, req_hdr_loc);
-
-
- TSContDataSet(interceptCont, intercept_ctx);
- TSHttpTxnServerIntercept(interceptCont, txn);
- TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE);
- return 0;
- }
-
- if (error_message != NULL) {
- status = HttpStatus::kNotFound;
- content_type = kContentTypeHtml;
- output = error_message;
- }
-
- ResponseHeaders response_headers;
- response_headers.SetStatusAndReason(status);
- response_headers.set_major_version(1);
- response_headers.set_minor_version(0);
-
- response_headers.Add(HttpAttributes::kContentType, content_type.mime_type());
-
- int64 now_ms = factory->timer()->NowMs();
- response_headers.SetDate(now_ms);
- response_headers.SetLastModified(now_ms);
- response_headers.Add(HttpAttributes::kCacheControl, cache_control);
-
- if (FindIgnoreCase(cache_control, "private") ==
- static_cast<int>(StringPiece::npos)) {
- response_headers.Add(HttpAttributes::kEtag, "W/\"0\"");
- }
-
- GoogleString header;
- StringWriter header_writer(&header);
- response_headers.WriteAsHttp(&header_writer, server_context->message_handler());
-
- TSCont interceptCont = TSContCreate(resource_intercept, TSMutexCreate());
- InterceptCtx *intercept_ctx = new InterceptCtx();
- intercept_ctx->request_ctx = ctx;
- header.append(output);
- TSHttpTxnRespCacheableSet(txn, 0);
- TSHttpTxnReqCacheableSet(txn, 0);
- TSContDataSet(interceptCont, intercept_ctx);
- TSHttpTxnServerIntercept(interceptCont, txn);
- intercept_ctx->response->append(header);
-
- TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE);
- return 0;
-}
-
-void setup_resource_intercept()
-{
- TSCont cont = TSContCreate(read_cache_header_callback, NULL);
- TSHttpHookAdd(TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK, cont);
-}
-
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1fe51067/plugins/experimental/ats_speed/ats_resource_intercept.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/ats_speed/ats_resource_intercept.h b/plugins/experimental/ats_speed/ats_resource_intercept.h
deleted file mode 100644
index 933f20f..0000000
--- a/plugins/experimental/ats_speed/ats_resource_intercept.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#ifndef ATS_RESOURCE_INTERCEPT_H
-#define ATS_RESOURCE_INTERCEPT_H
-
-void setup_resource_intercept();
-
-#endif // ATS_INTERCEPT_H
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1fe51067/plugins/experimental/ats_speed/ats_rewrite_driver_factory.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/ats_speed/ats_rewrite_driver_factory.cc b/plugins/experimental/ats_speed/ats_rewrite_driver_factory.cc
deleted file mode 100644
index cf73ed3..0000000
--- a/plugins/experimental/ats_speed/ats_rewrite_driver_factory.cc
+++ /dev/null
@@ -1,196 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#include "ats_rewrite_driver_factory.h"
-
-#include <cstdio>
-#include <vector>
-
-#include "ats_thread_system.h"
-#include "ats_message_handler.h"
-#include "ats_server_context.h"
-
-#include "net/instaweb/http/public/content_type.h"
-#include "net/instaweb/http/public/rate_controller.h"
-#include "net/instaweb/http/public/rate_controlling_url_async_fetcher.h"
-#include "net/instaweb/http/public/wget_url_fetcher.h"
-#include "net/instaweb/rewriter/public/rewrite_driver.h"
-#include "net/instaweb/rewriter/public/rewrite_driver_factory.h"
-#include "net/instaweb/rewriter/public/server_context.h"
-#include "net/instaweb/rewriter/public/static_asset_manager.h"
-#include "net/instaweb/system/public/in_place_resource_recorder.h"
-#include "net/instaweb/system/public/serf_url_async_fetcher.h"
-#include "net/instaweb/system/public/system_caches.h"
-#include "net/instaweb/system/public/system_rewrite_options.h"
-#include "net/instaweb/util/public/google_message_handler.h"
-#include "net/instaweb/util/public/null_shared_mem.h"
-#include "net/instaweb/util/public/posix_timer.h"
-#include "net/instaweb/util/public/property_cache.h"
-#include "net/instaweb/util/public/pthread_shared_mem.h"
-#include "net/instaweb/util/public/scheduler_thread.h"
-#include "net/instaweb/util/public/shared_circular_buffer.h"
-#include "net/instaweb/util/public/shared_mem_statistics.h"
-#include "net/instaweb/util/public/slow_worker.h"
-#include "net/instaweb/util/public/stdio_file_system.h"
-#include "net/instaweb/util/public/string.h"
-#include "net/instaweb/util/public/string_util.h"
-#include "net/instaweb/util/public/thread_system.h"
-
-
-namespace net_instaweb {
-
-
- AtsRewriteDriverFactory::AtsRewriteDriverFactory(
- const ProcessContext& process_context,
- AtsThreadSystem* thread_system,
- StringPiece hostname, int port)
- : SystemRewriteDriverFactory(process_context,
- thread_system, NULL /*default shared mem runtime*/,
- "" /*hostname, not used*/, -1/*port, not used*/)
- , ats_message_handler_(new AtsMessageHandler(thread_system->NewMutex()))
- , ats_html_parse_message_handler_(new AtsMessageHandler(thread_system->NewMutex()))
- , use_per_vhost_statistics_(false)
- , threads_started_(false)
- {
- InitializeDefaultOptions();
- default_options()->set_beacon_url("/ats_speed_beacon");
- default_options()->set_enabled(RewriteOptions::kEnabledOn);
- default_options()->SetRewriteLevel(RewriteOptions::kCoreFilters);
-
- SystemRewriteOptions* system_options = dynamic_cast<SystemRewriteOptions*>(
- default_options());
- system_options->set_log_dir("/tmp/ps_log/");
- system_options->set_statistics_logging_enabled(true);
-
- system_options->set_file_cache_clean_inode_limit(500000);
- system_options->set_file_cache_clean_size_kb(1024*10000);// 10 GB
- system_options->set_avoid_renaming_introspective_javascript(true);
- system_options->set_file_cache_path("/tmp/ats_ps/");
- system_options->set_lru_cache_byte_limit(163840);
- system_options->set_lru_cache_kb_per_process(1024*500);//500 MB
-
- system_options->set_flush_html(true);
-
- AtsRewriteOptions* ats_options = (AtsRewriteOptions*)system_options;
- std::vector<std::string> args;
- args.push_back("RateLimitBackgroundFetches");
- args.push_back("on");
- global_settings settings;
- const char* msg = ats_options->ParseAndSetOptions(args, ats_message_handler_, settings);
- CHECK(!msg);
-
- set_message_buffer_size(1024*128);
- set_message_handler(ats_message_handler_);
- set_html_parse_message_handler(ats_html_parse_message_handler_);
- StartThreads();
- }
-
- AtsRewriteDriverFactory::~AtsRewriteDriverFactory() {
- ShutDown();
- delete ats_message_handler_;
- ats_message_handler_ = NULL;
- delete ats_html_parse_message_handler_;
- ats_html_parse_message_handler_ = NULL;
- STLDeleteElements(&uninitialized_server_contexts_);
- }
-
- void AtsRewriteDriverFactory::InitStaticAssetManager(StaticAssetManager* static_js_manager) {
- static_js_manager->set_library_url_prefix("/ats_speed_static/");
- }
-
- Hasher* AtsRewriteDriverFactory::NewHasher() {
- return new MD5Hasher;
- }
-
- MessageHandler* AtsRewriteDriverFactory::DefaultHtmlParseMessageHandler() {
- return ats_html_parse_message_handler_;
- }
-
- MessageHandler* AtsRewriteDriverFactory::DefaultMessageHandler() {
- return ats_message_handler_;
- }
-
- FileSystem* AtsRewriteDriverFactory::DefaultFileSystem() {
- return new StdioFileSystem();
- }
-
- Timer* AtsRewriteDriverFactory::DefaultTimer() {
- return new PosixTimer;
- }
-
- NamedLockManager* AtsRewriteDriverFactory::DefaultLockManager() {
- CHECK(false) << "default lock manager should not be called";
- return NULL;
- }
-
- RewriteOptions* AtsRewriteDriverFactory::NewRewriteOptions() {
- AtsRewriteOptions* options = new AtsRewriteOptions(thread_system());
- options->SetRewriteLevel(RewriteOptions::kCoreFilters);
- return options;
- }
-
- ServerContext* AtsRewriteDriverFactory::NewDecodingServerContext() {
- ServerContext* sc = new AtsServerContext(this);
- InitStubDecodingServerContext(sc);
- return sc;
- }
-
- void AtsRewriteDriverFactory::InitStats(Statistics* statistics) {
- // Init standard PSOL stats.
- SystemRewriteDriverFactory::InitStats(statistics);
- // Init Ats-specific stats.
- AtsServerContext::InitStats(statistics);
- }
-
-
- AtsServerContext* AtsRewriteDriverFactory::MakeAtsServerContext() {
- AtsServerContext* server_context = new AtsServerContext(this);
- uninitialized_server_contexts_.insert(server_context);
- return server_context;
- }
-
- ServerContext* AtsRewriteDriverFactory::NewServerContext() {
- LOG(DFATAL) << "MakeAtsServerContext should be used instead";
- return NULL;
- }
-
-net_instaweb::QueuedWorkerPool* AtsRewriteDriverFactory::CreateWorkerPool(net_instaweb::RewriteDriverFactory::WorkerPoolCategory pool,
- StringPiece name) {
- int tc = 8;
- TSDebug("ats_speed", "Created new QueuedWorkerPool of type %d named '%s' of size %d", pool, name.data(), tc);
- net_instaweb::QueuedWorkerPool *q_pool = new net_instaweb::QueuedWorkerPool(tc, name, thread_system());
- return q_pool;
-}
-
-void AtsRewriteDriverFactory::StartThreads() {
- if (threads_started_) {
- CHECK(false) << "threads already started";
- }
- SchedulerThread* thread = new SchedulerThread(thread_system(), scheduler());
- bool ok = thread->Start();
- CHECK(ok) << "Unable to start scheduler thread";
- defer_cleanup(thread->MakeDeleter());
- threads_started_ = true;
-}
-
-} // namespace net_instaweb
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1fe51067/plugins/experimental/ats_speed/ats_rewrite_driver_factory.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/ats_speed/ats_rewrite_driver_factory.h b/plugins/experimental/ats_speed/ats_rewrite_driver_factory.h
deleted file mode 100644
index de18a28..0000000
--- a/plugins/experimental/ats_speed/ats_rewrite_driver_factory.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#ifndef ATS_REWRITE_DRIVER_FACTORY_H_
-#define ATS_REWRITE_DRIVER_FACTORY_H_
-
-#include <set>
-
-#include "net/instaweb/system/public/system_rewrite_driver_factory.h"
-#include "net/instaweb/util/public/md5_hasher.h"
-#include "net/instaweb/util/public/scoped_ptr.h"
-
-
-namespace net_instaweb {
-
-
- class AbstractSharedMem;
- //class NgxMessageHandler;
- //class NgxRewriteOptions;
- class AtsServerContext;
- class AtsThreadSystem;
- class GoogleMessageHandler;
- //class NgxUrlAsyncFetcher;
- class SharedCircularBuffer;
- class SharedMemRefererStatistics;
- class SharedMemStatistics;
- class SlowWorker;
- class StaticAssetManager;
- class Statistics;
- class StaticAssetManager;
- //class SystemCaches;
-
-class AtsRewriteDriverFactory : public SystemRewriteDriverFactory {
- public:
- explicit AtsRewriteDriverFactory(const ProcessContext& process_context,
- AtsThreadSystem* thread_system,
- StringPiece hostname, int port);
- virtual ~AtsRewriteDriverFactory();
-
- virtual Hasher* NewHasher();
- virtual MessageHandler* DefaultHtmlParseMessageHandler();
- virtual MessageHandler* DefaultMessageHandler();
- virtual FileSystem* DefaultFileSystem();
- virtual Timer* DefaultTimer();
- virtual NamedLockManager* DefaultLockManager();
- virtual RewriteOptions* NewRewriteOptions();
- virtual ServerContext* NewDecodingServerContext();
-
- virtual bool UseBeaconResultsInFilters() const {
- return true;
- }
-
- virtual void InitStaticAssetManager(StaticAssetManager* static_js_manager);
-
- // Initializes all the statistics objects created transitively by
- // AtsRewriteDriverFactory, including nginx-specific and
- // platform-independent statistics.
- static void InitStats(Statistics* statistics);
-
- virtual net_instaweb::QueuedWorkerPool* CreateWorkerPool(WorkerPoolCategory pool,
- StringPiece name);
- virtual void NonStaticInitStats(Statistics* statistics) {
- InitStats(statistics);
- }
-
- AtsServerContext* MakeAtsServerContext();
- ServerContext* NewServerContext();
- //AbstractSharedMem* shared_mem_runtime() const {
- // return shared_mem_runtime_.get();
- //}
-
- // Starts pagespeed threads if they've not been started already. Must be
- // called after the caller has finished any forking it intends to do.
- void StartThreads();
- bool use_per_vhost_statistics() const {
- return use_per_vhost_statistics_;
- }
- void set_use_per_vhost_statistics(bool x) {
- use_per_vhost_statistics_ = x;
- }
-
- protected:
- private:
- //scoped_ptr<AbstractSharedMem> shared_mem_runtime_;
- GoogleMessageHandler* ats_message_handler_;
- GoogleMessageHandler* ats_html_parse_message_handler_;
- bool use_per_vhost_statistics_;
- bool threads_started_;
-};
-
-} // namespace net_instaweb
-
-#endif // ATS_REWRITE_DRIVER_FACTORY_H_
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1fe51067/plugins/experimental/ats_speed/ats_rewrite_options.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/ats_speed/ats_rewrite_options.cc b/plugins/experimental/ats_speed/ats_rewrite_options.cc
deleted file mode 100644
index 172db83..0000000
--- a/plugins/experimental/ats_speed/ats_rewrite_options.cc
+++ /dev/null
@@ -1,263 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#include "ats_rewrite_options.h"
-
-#include "net/instaweb/public/version.h"
-#include "net/instaweb/rewriter/public/rewrite_options.h"
-#include "net/instaweb/util/public/timer.h"
-
-#include "net/instaweb/util/public/message_handler.h"
-#include "net/instaweb/rewriter/public/file_load_policy.h"
-
-#include "net/instaweb/util/public/stdio_file_system.h"
-
-#include "ats_message_handler.h"
-#include "ats_rewrite_driver_factory.h"
-
-using namespace std;
-
-namespace net_instaweb {
-
-
-RewriteOptions::Properties* AtsRewriteOptions::ats_properties_ = NULL;
-
-AtsRewriteOptions::AtsRewriteOptions(ThreadSystem* thread_system)
- : SystemRewriteOptions(thread_system) {
-
- Init();
-}
-
-void AtsRewriteOptions::Init() {
- DCHECK(ats_properties_ != NULL)
- << "Call AtsRewriteOptions::Initialize() before construction";
- InitializeOptions(ats_properties_);
-}
-
-void AtsRewriteOptions::AddProperties() {
- MergeSubclassProperties(ats_properties_);
- AtsRewriteOptions dummy_config(NULL);
-
- dummy_config.set_default_x_header_value(MOD_PAGESPEED_VERSION_STRING "-" LASTCHANGE_STRING);
-}
-
-void AtsRewriteOptions::Initialize() {
- if (Properties::Initialize(&ats_properties_)) {
- SystemRewriteOptions::Initialize();
- AddProperties();
- }
-}
-
-void AtsRewriteOptions::Terminate() {
- if (Properties::Terminate(&ats_properties_)) {
- SystemRewriteOptions::Terminate();
- }
-}
-
-bool AtsRewriteOptions::IsDirective(StringPiece config_directive,
- StringPiece compare_directive) {
- return StringCaseEqual(config_directive, compare_directive);
-}
-
-RewriteOptions::OptionSettingResult AtsRewriteOptions::ParseAndSetOptions0(
- StringPiece directive, GoogleString* msg, MessageHandler* handler) {
- if (IsDirective(directive, "on")) {
- set_enabled(RewriteOptions::kEnabledOn);
- } else if (IsDirective(directive, "off")) {
- set_enabled(RewriteOptions::kEnabledOff);
- } else if (IsDirective(directive, "unplugged")) {
- set_enabled(RewriteOptions::kEnabledUnplugged);
- } else {
- return RewriteOptions::kOptionNameUnknown;
- }
- return RewriteOptions::kOptionOk;
-}
-
-
-RewriteOptions::OptionSettingResult
-AtsRewriteOptions::ParseAndSetOptionFromName1(
- StringPiece name, StringPiece arg,
- GoogleString* msg, MessageHandler* handler) {
- // FileCachePath needs error checking.
- if (StringCaseEqual(name, kFileCachePath)) {
- if (!StringCaseStartsWith(arg, "/")) {
- *msg = "must start with a slash";
- return RewriteOptions::kOptionValueInvalid;
- }
- }
-
- return SystemRewriteOptions::ParseAndSetOptionFromName1(
- name, arg, msg, handler);
-}
-
-bool AtsRewriteOptions::SetBoolFlag(bool* v, StringPiece arg) {
- if (IsDirective(arg, "on")) {
- *v=true;
- return true;
- } else if (IsDirective(arg, "off")) {
- *v=false;
- return true;
- }
- return false;
-}
-
-const char*
-AtsRewriteOptions::ParseAndSetOptions(
- vector<string> args, MessageHandler* handler, global_settings& global_config) {
- int n_args = args.size();
- CHECK_GE(n_args, 1);
-
- StringPiece directive = args[0];
-
- // Remove initial "ModPagespeed" if there is one.
- StringPiece mod_pagespeed("ModPagespeed");
- if (StringCaseStartsWith(directive, mod_pagespeed)) {
- directive.remove_prefix(mod_pagespeed.size());
- }
-
- GoogleString msg;
- OptionSettingResult result;
- if (n_args == 1) {
- result = ParseAndSetOptions0(directive, &msg, handler);
- } else if (n_args == 2) {
- StringPiece arg = args[1];
- if (IsDirective(directive, "UsePerVHostStatistics")) {
- if (!SetBoolFlag(&global_config.use_per_vhost_statistics,arg)) {
- msg = "Failed to set UsePerVHostStatistics value";
- result = RewriteOptions::kOptionValueInvalid;
- } else {
- result = RewriteOptions::kOptionOk;
- }
- } /* else if (IsDirective(directive, "InstallCrashHandler")) {
- // Not applicable
- } */ else if (IsDirective(directive, "MessageBufferSize")) {
- int message_buffer_size;
- bool ok = StringToInt(arg.as_string(), &message_buffer_size);
- if (ok && message_buffer_size >= 0) {
- global_config.message_buffer_size = message_buffer_size;
- result = RewriteOptions::kOptionOk;
- } else {
- msg = "Failed to set MessageBufferSize value";
- result = RewriteOptions::kOptionValueInvalid;
- }
- } else if (IsDirective(directive, "UseNativeFetcher")) {
- if (!SetBoolFlag(&global_config.info_urls_local_only,arg)) {
- msg = "Failed to set UseNativeFetcher value";
- result = RewriteOptions::kOptionValueInvalid;
- } else {
- msg = "Native fetcher is not available in this release";
-
- result = RewriteOptions::kOptionValueInvalid;
- }
- } else if (IsDirective(directive, "InfoUrlsLocalOnly")) {
- if (!SetBoolFlag(&global_config.info_urls_local_only, arg)) {
- msg = "Failed to set InfoUrlsLocalOnly value";
- result = RewriteOptions::kOptionValueInvalid;
- } else {
- result = RewriteOptions::kOptionOk;
- }
- }/* else if (IsDirective(directive, "RateLimitBackgroundFetches")) {
- if (!SetBoolFlag(&global_config.rate_limit_background_fetches, arg)) {
- msg = "Failed to set RateLimitBackgroundFetches value";
- result = RewriteOptions::kOptionValueInvalid;
- } else {
- result = RewriteOptions::kOptionOk;
- }
- } else if (IsDirective(directive, "ForceCaching")) {
- if (!SetBoolFlag(&global_config.force_caching, arg)) {
- msg = "Failed to set ForceCaching value";
- result = RewriteOptions::kOptionValueInvalid;
- } else {
- result = RewriteOptions::kOptionOk;
- }
- } else if (IsDirective(directive, "ListOutstandingUrlsOnError")) {
- if (!SetBoolFlag(&global_config.list_outstanding_urls_on_error, arg)) {
- msg = "Failed to set ListOutstandingUrlsOnError value";
- result = RewriteOptions::kOptionValueInvalid;
- } else {
- result = RewriteOptions::kOptionOk;
- }
- } else if (IsDirective(directive, "TrackOriginalContentLength")) {
- if (!SetBoolFlag(&global_config.track_original_content_length, arg)) {
- msg = "Failed to set TrackOriginalContentLength value";
- result = RewriteOptions::kOptionValueInvalid;
- } else {
- result = RewriteOptions::kOptionOk;
- }
- } */else {
- result = ParseAndSetOptionFromName1(directive, args[1], &msg, handler);
- }
- } else if (n_args == 3) {
- if (StringCaseEqual(directive, "CreateSharedMemoryMetadataCache")) {
- int64 kb = 0;
- if (!StringToInt64(args[2], &kb) || kb < 0) {
- result = RewriteOptions::kOptionValueInvalid;
- msg = "size_kb must be a positive 64-bit integer";
- } else {
- global_config.shm_cache_size_kb = kb;
- result = kOptionOk;
- //bool ok = driver_factory->caches()->CreateShmMetadataCache(
- // args[1].as_string(), kb, &msg);
- //result = ok ? kOptionOk : kOptionValueInvalid;
- }
- } else {
- result = ParseAndSetOptionFromName2(directive, args[1], args[2],
- &msg, handler);
- }
- } else if (n_args == 4) {
- result = ParseAndSetOptionFromName3(
- directive, args[1], args[2], args[3], &msg, handler);
- } else {
- return "unknown option";
- }
-
- if (msg.size()) {
- handler->Message(kWarning, "Error handling config line [%s]: [%s]",
- JoinString(args, ' ').c_str(), msg.c_str());
- }
-
- switch (result) {
- case RewriteOptions::kOptionOk:
- return NULL;
- case RewriteOptions::kOptionNameUnknown:
- handler->Message(kWarning, "%s", JoinString(args, ' ').c_str());
- return "unknown option";
- case RewriteOptions::kOptionValueInvalid: {
- handler->Message(kWarning, "%s", JoinString(args, ' ').c_str());
- return "Invalid value";
- }
- }
-
- CHECK(false);
- return NULL;
-}
-
-AtsRewriteOptions* AtsRewriteOptions::Clone() const {
- AtsRewriteOptions* options = new AtsRewriteOptions(this->thread_system());
- options->Merge(*this);
- return options;
-}
-
-
-} // namespace net_instaweb
-
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1fe51067/plugins/experimental/ats_speed/ats_rewrite_options.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/ats_speed/ats_rewrite_options.h b/plugins/experimental/ats_speed/ats_rewrite_options.h
deleted file mode 100644
index 4a39dcd..0000000
--- a/plugins/experimental/ats_speed/ats_rewrite_options.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/** @file
-
- A brief file description
-
- @section license License
-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-#ifndef ATS_REWRITE_OPTIONS_H_
-#define ATS_REWRITE_OPTIONS_H_
-
-#include <string>
-#include <vector>
-
-#include "net/instaweb/util/public/string.h"
-#include "net/instaweb/util/public/string_util.h"
-#include "net/instaweb/rewriter/public/rewrite_options.h"
-#include "net/instaweb/system/public/system_rewrite_options.h"
-
-
-//#include "ats_configuration.h"
-
-
-namespace net_instaweb {
-
-class ThreadSystem;
-
-struct global_settings {
- global_settings()
- : info_urls_local_only(true)
- , use_native_fetcher(false)
- , use_per_vhost_statistics(true)
- , message_buffer_size(1024*128)
- , shm_cache_size_kb(0)
- //, rate_limit_background_fetches(true)
- //, force_caching(false)
- //, list_outstanding_urls_on_error(false)
- //, track_original_content_length(false)
- {
- }
- bool info_urls_local_only;
- bool use_native_fetcher;
- bool use_per_vhost_statistics;
- int message_buffer_size;
- //bool rate_limit_background_fetches;
- //bool force_caching;
- //bool list_outstanding_urls_on_error;
- //bool track_original_content_length;
- int shm_cache_size_kb;
-};
-
-
-class AtsRewriteOptions : public SystemRewriteOptions {
- public:
- // See rewrite_options::Initialize and ::Terminate
- static void Initialize();
- static void Terminate();
-
- AtsRewriteOptions(ThreadSystem* thread_system);
- virtual ~AtsRewriteOptions() {
- }
-
- const char* ParseAndSetOptions(
- std::vector<std::string> args, MessageHandler* handler, global_settings& global_config);
-
- virtual AtsRewriteOptions* Clone() const;
- OptionSettingResult ParseAndSetOptions0(
- StringPiece directive, GoogleString* msg, MessageHandler* handler);
-
- virtual OptionSettingResult ParseAndSetOptionFromName1(
- StringPiece name, StringPiece arg,
- GoogleString* msg, MessageHandler* handler);
-
-
- private:
- bool SetBoolFlag(bool* v, StringPiece arg);
- static Properties* ats_properties_;
- static void AddProperties();
- void Init();
-
- bool IsDirective(StringPiece config_directive, StringPiece compare_directive);
-
- DISALLOW_COPY_AND_ASSIGN(AtsRewriteOptions);
- };
-
-} // namespace net_instaweb
-
-#endif // ATS_REWRITE_OPTIONS_H_