http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/ats_pagespeed/ats_pagespeed.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/ats_pagespeed/ats_pagespeed.cc b/plugins/experimental/ats_pagespeed/ats_pagespeed.cc index dbc1e10..05eebaf 100644 --- a/plugins/experimental/ats_pagespeed/ats_pagespeed.cc +++ b/plugins/experimental/ats_pagespeed/ats_pagespeed.cc @@ -103,7 +103,7 @@ static TransformCtx * ats_ctx_alloc() { TransformCtx *ctx; - + ctx = (TransformCtx *) TSmalloc(sizeof(TransformCtx)); ctx->downstream_vio = NULL; ctx->downstream_buffer = NULL; @@ -112,7 +112,7 @@ ats_ctx_alloc() ctx->base_fetch = NULL; ctx->proxy_fetch = NULL; - + ctx->inflater = NULL; ctx->url_string = NULL; ctx->gurl = NULL; @@ -186,16 +186,16 @@ ats_ctx_destroy(TransformCtx * ctx) delete ctx->to_host; ctx->to_host = NULL; } - if (ctx->driver != NULL) { + if (ctx->driver != NULL) { ctx->driver->Cleanup(); ctx->driver = NULL; } - if (ctx->recorder != NULL) { + if (ctx->recorder != NULL) { ctx->recorder->Fail(); ctx->recorder->DoneAndSetHeaders(NULL); // Deletes recorder. ctx->recorder = NULL; } - if (ctx->ipro_response_headers != NULL) { + if (ctx->ipro_response_headers != NULL) { delete ctx->ipro_response_headers; ctx->ipro_response_headers = NULL; } @@ -298,7 +298,7 @@ handle_send_response_headers(TSHttpTxn txnp) { // TODO(oschaaf): figure out when this happens. return; } - + if (TSHttpTxnClientRespGet(txnp, &bufp, &hdr_loc) == TS_SUCCESS) { ResponseHeaders* pagespeed_headers = ctx->base_fetch->response_headers(); @@ -310,7 +310,7 @@ handle_send_response_headers(TSHttpTxn txnp) { if ( StringCaseEqual(name_gs, "Connection") || StringCaseEqual(name_gs, "Transfer-Encoding") ) { continue; } - + TSMLoc field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, name_gs.data(), name_gs.size()); if (field_loc != NULL) { TSMimeHdrFieldValuesClear(bufp, hdr_loc, field_loc); @@ -327,9 +327,9 @@ handle_send_response_headers(TSHttpTxn txnp) { TSHandleMLocRelease(bufp, hdr_loc, field_loc); } else { CHECK(false) << "Field create failure"; - } + } } - + TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); } else { DCHECK(false) << "Could not get response headers?!"; @@ -472,7 +472,7 @@ ats_transform_init(TSCont contp, TransformCtx * ctx) } // TODO(oschaaf): fix host/ip(?) - SystemRequestContext* system_request_context = + SystemRequestContext* system_request_context = new SystemRequestContext(server_context->thread_system()->NewMutex(), server_context->timer(), "www.foo.com", @@ -482,12 +482,12 @@ ats_transform_init(TSCont contp, TransformCtx * ctx) ctx->base_fetch = new AtsBaseFetch(server_context, RequestContextPtr(system_request_context), ctx->downstream_vio, ctx->downstream_buffer, false); - + RewriteOptions* options = NULL; RequestHeaders* request_headers = new RequestHeaders(); ctx->base_fetch->SetRequestHeadersTakingOwnership(request_headers); copy_request_headers_to_psol(reqp, req_hdr_loc, request_headers); - + TSHttpStatus status = TSHttpHdrStatusGet(bufp, hdr_loc); // TODO(oschaaf): http version ctx->base_fetch->response_headers()->set_status_code(status); @@ -507,7 +507,7 @@ ats_transform_init(TSCont contp, TransformCtx * ctx) // Take ownership of custom_options. scoped_ptr<RewriteOptions> custom_options(options); - + if (!ok) { TSError("Failure while determining request options for psol"); options = server_context->global_options(); @@ -516,17 +516,17 @@ ats_transform_init(TSCont contp, TransformCtx * ctx) // parameters. Keep url_string in sync with url. ctx->gurl->Spec().CopyToString(ctx->url_string); } - + RewriteDriver* driver; if (custom_options.get() == NULL) { driver = server_context->NewRewriteDriver(ctx->base_fetch->request_context()); } else { driver = server_context->NewCustomRewriteDriver(custom_options.release(), ctx->base_fetch->request_context()); } - + driver->SetUserAgent(ctx->user_agent->c_str()); driver->SetRequestHeaders(*request_headers); - + bool page_callback_added = false; scoped_ptr<ProxyFetchPropertyCallbackCollector> property_callback( @@ -538,7 +538,7 @@ ats_transform_init(TSCont contp, TransformCtx * ctx) ctx->base_fetch, false /* requires_blink_cohort (no longer unused) */, &page_callback_added)); - + ctx->proxy_fetch = ats_process_context->proxy_fetch_factory()->CreateNewProxyFetch( *(ctx->url_string), ctx->base_fetch, driver, @@ -573,27 +573,27 @@ ats_transform_one(TransformCtx * ctx, TSIOBufferReader upstream_reader, int amou if (upstream_length > amount) { upstream_length = amount; } - + TSDebug("ats-speed", "transform!"); // TODO(oschaaf): use at least the message handler from the server conrtext here? if (ctx->inflater == NULL) { - if (ctx->recorder != NULL) { + if (ctx->recorder != NULL) { ctx->recorder->Write(StringPiece((char*)upstream_buffer, upstream_length), ats_process_context->message_handler()); } else { ctx->proxy_fetch->Write(StringPiece((char*)upstream_buffer, upstream_length), ats_process_context->message_handler()); } } else { char buf[net_instaweb::kStackBufferSize]; - + ctx->inflater->SetInput((char*)upstream_buffer, upstream_length); - + while (ctx->inflater->HasUnconsumedInput()) { int num_inflated_bytes = ctx->inflater->InflateBytes( buf, net_instaweb::kStackBufferSize); if (num_inflated_bytes < 0) { TSError("Corrupted inflation"); } else if (num_inflated_bytes > 0) { - if (ctx->recorder != NULL ) { + if (ctx->recorder != NULL ) { ctx->recorder->Write(StringPiece(buf, num_inflated_bytes), ats_process_context->message_handler()); } else { @@ -618,11 +618,11 @@ ats_transform_finish(TransformCtx * ctx) { if (ctx->state == transform_state_output) { ctx->state = transform_state_finished; - if (ctx->recorder != NULL ) { + if (ctx->recorder != NULL ) { TSDebug("ats-speed", "ipro recording finished"); ctx->recorder->DoneAndSetHeaders(ctx->ipro_response_headers); ctx->recorder = NULL; - } else { + } else { TSDebug("ats-speed", "proxy fetch finished"); ctx->proxy_fetch->Done(true); ctx->proxy_fetch = NULL; @@ -738,7 +738,7 @@ ats_pagespeed_transform_add(TSHttpTxn txnp) TSDebug("ats-speed", "transform added"); ctx->transform_added = true; } - + TSHttpTxnUntransformedRespCache(txnp, ctx->recorder == NULL ? 1 : 0); TSHttpTxnTransformedRespCache(txnp, 0); @@ -755,12 +755,12 @@ handle_read_request_header(TSHttpTxn txnp) { TSMLoc hdr_loc = NULL; char *url = NULL; int url_length = -1; - + TransformCtx* ctx = ats_ctx_alloc(); ctx->txn = txnp; TSHttpTxnArgSet(txnp, TXN_INDEX_ARG, (void*) ctx); TSHttpTxnArgSet(txnp, TXN_INDEX_OWNED_ARG, &TXN_INDEX_OWNED_ARG_SET); - + if (TSHttpTxnClientReqGet(txnp, &reqp, &hdr_loc) == TS_SUCCESS) { url = TSHttpTxnEffectiveUrlStringGet(txnp, &url_length); if (!url || url_length <= 0) { @@ -768,7 +768,7 @@ handle_read_request_header(TSHttpTxn txnp) { } else { std::string s_url = std::string(url,url_length); GoogleUrl gurl(s_url); - + ctx->url_string = new GoogleString(url, url_length); ctx->gurl = new GoogleUrl(*(ctx->url_string)); @@ -789,11 +789,11 @@ handle_read_request_header(TSHttpTxn txnp) { ctx->mps_user_agent = true; } if (ats_process_context->server_context()->IsPagespeedResource(gurl)) { - if (head_or_get && !ctx->mps_user_agent) { + if (head_or_get && !ctx->mps_user_agent) { ctx->resource_request = true; TSHttpTxnArgSet(txnp, TXN_INDEX_OWNED_ARG, &TXN_INDEX_OWNED_ARG_UNSET); } - } else if ( ctx->gurl->PathSansLeaf() == + } else if ( ctx->gurl->PathSansLeaf() == ((AtsRewriteDriverFactory*)ctx->server_context->factory())->static_asset_prefix()) { ctx->resource_request = true; TSHttpTxnArgSet(txnp, TXN_INDEX_OWNED_ARG, &TXN_INDEX_OWNED_ARG_UNSET); @@ -805,22 +805,22 @@ handle_read_request_header(TSHttpTxn txnp) { } else { AtsServerContext* server_context = ctx->server_context; // TODO(oschaaf): fix host/ip(?) - SystemRequestContext* system_request_context = + SystemRequestContext* system_request_context = new SystemRequestContext(server_context->thread_system()->NewMutex(), server_context->timer(), "www.foo.com", 80, "127.0.0.1"); - + ctx->base_fetch = new AtsBaseFetch(server_context, RequestContextPtr(system_request_context), ctx->downstream_vio, ctx->downstream_buffer, false); - - + + RewriteOptions* options = NULL; RequestHeaders* request_headers = new RequestHeaders(); ctx->base_fetch->SetRequestHeadersTakingOwnership(request_headers); copy_request_headers_to_psol(reqp, hdr_loc, request_headers); - + //TSHttpStatus status = TSHttpHdrStatusGet(bufp, hdr_loc); // TODO(oschaaf): http version //ctx->base_fetch->response_headers()->set_status_code(status); @@ -840,7 +840,7 @@ handle_read_request_header(TSHttpTxn txnp) { // Take ownership of custom_options. scoped_ptr<RewriteOptions> custom_options(options); - + if (!ok) { TSError("Failure while determining request options for psol"); options = server_context->global_options(); @@ -849,7 +849,7 @@ handle_read_request_header(TSHttpTxn txnp) { // parameters. Keep url_string in sync with url. ctx->gurl->Spec().CopyToString(ctx->url_string); } - + if (options->in_place_rewriting_enabled() && options->enabled() && options->IsAllowed(ctx->gurl->Spec())) { @@ -868,7 +868,7 @@ handle_read_request_header(TSHttpTxn txnp) { ctx->server_context->message_handler()->Message( kInfo, "Trying to serve rewritten resource in-place: %s", ctx->url_string->c_str()); - + ctx->in_place = true; ctx->base_fetch->set_handle_error(false); ctx->base_fetch->set_is_ipro(true); @@ -903,7 +903,7 @@ transform_plugin(TSCont contp, TSEvent event, void *edata) CHECK(event == TS_EVENT_HTTP_READ_RESPONSE_HDR || event == TS_EVENT_HTTP_READ_CACHE_HDR || event == TS_EVENT_HTTP_SEND_REQUEST_HDR || event == TS_EVENT_HTTP_READ_REQUEST_HDR - || event == TS_EVENT_HTTP_TXN_CLOSE || event == TS_EVENT_HTTP_SEND_RESPONSE_HDR) + || event == TS_EVENT_HTTP_TXN_CLOSE || event == TS_EVENT_HTTP_SEND_RESPONSE_HDR) << "Invalid transform event"; if (event != TS_EVENT_HTTP_READ_REQUEST_HDR) { @@ -922,9 +922,9 @@ transform_plugin(TSCont contp, TSEvent event, void *edata) } if (event == TS_EVENT_HTTP_TXN_CLOSE) { TransformCtx* ctx = get_transaction_context(txn); //if (ctx != NULL && !ctx->resource_request && !ctx->beacon_request && !ctx->html_rewrite) { - // For intercepted requests like beacons and resource requests, we don't own the + // For intercepted requests like beacons and resource requests, we don't own the // ctx here - the interceptor does. - + if (ctx != NULL) { bool is_owned = TSHttpTxnArgGet(txn, TXN_INDEX_OWNED_ARG) == &TXN_INDEX_OWNED_ARG_SET //TODO(oschaaf): rewrite this. @@ -937,11 +937,11 @@ transform_plugin(TSCont contp, TSEvent event, void *edata) return 0; } if (event == TS_EVENT_HTTP_READ_REQUEST_HDR) { handle_read_request_header(txn); - return 0; + return 0; } else if (event == TS_EVENT_HTTP_SEND_REQUEST_HDR) { TSMBuffer request_header_buf = NULL; TSMLoc request_header_loc = NULL; - + if (TSHttpTxnServerReqGet(txn, &request_header_buf, &request_header_loc) == TS_SUCCESS) { hide_accept_encoding(request_header_buf, request_header_loc, "@xxAccept-Encoding"); // Turn off pagespeed optimization at the origin @@ -955,7 +955,7 @@ transform_plugin(TSCont contp, TSEvent event, void *edata) } else if (event == TS_EVENT_HTTP_READ_RESPONSE_HDR) { TSMBuffer request_header_buf = NULL; TSMLoc request_header_loc = NULL; - + if (TSHttpTxnServerReqGet(txn, &request_header_buf, &request_header_loc) == TS_SUCCESS) { restore_accept_encoding(request_header_buf, request_header_loc, "@xxAccept-Encoding"); TSHandleMLocRelease(request_header_buf, TS_NULL_MLOC, request_header_loc); @@ -972,7 +972,7 @@ transform_plugin(TSCont contp, TSEvent event, void *edata) TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE); return 0; } - if (ctx->serve_in_place) { + if (ctx->serve_in_place) { TSHttpTxnArgSet(txn, TXN_INDEX_OWNED_ARG, &TXN_INDEX_OWNED_ARG_UNSET); TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE); return 0; @@ -992,15 +992,15 @@ transform_plugin(TSCont contp, TSEvent event, void *edata) override_expiry = get_override_expiry(host); } - + if (ctx->mps_user_agent && override_expiry) { if (TSHttpTxnServerRespGet(txn, &response_header_buf, &response_header_loc) == TS_SUCCESS) { // TODO => set cacheable. unset_header(response_header_buf, response_header_loc, "Cache-Control"); unset_header(response_header_buf, response_header_loc, "Expires"); unset_header(response_header_buf, response_header_loc, "Age"); - set_header(response_header_buf, response_header_loc, "Cache-Control", "public, max-age=3600"); - TSHandleMLocRelease(response_header_buf, TS_NULL_MLOC, response_header_loc); + set_header(response_header_buf, response_header_loc, "Cache-Control", "public, max-age=3600"); + TSHandleMLocRelease(response_header_buf, TS_NULL_MLOC, response_header_loc); } } bool ok = ctx->gurl->IsWebValid() && @@ -1009,9 +1009,9 @@ transform_plugin(TSCont contp, TSEvent event, void *edata) TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE); return 0; } - + bool have_response_header = false; - + if (TSHttpTxnServerRespGet(txn, &response_header_buf, &response_header_loc) == TS_SUCCESS) { have_response_header = true; if (override_expiry) { @@ -1023,7 +1023,7 @@ transform_plugin(TSCont contp, TSEvent event, void *edata) } else if (TSHttpTxnCachedRespGet(txn, &response_header_buf, &response_header_loc) == TS_SUCCESS) { have_response_header = true; - } + } if (!have_response_header) { TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE); return 0; @@ -1047,12 +1047,12 @@ transform_plugin(TSCont contp, TSEvent event, void *edata) } } - if (ok) { + if (ok) { StringPiece s_content_type = get_header(response_header_buf, response_header_loc, "Content-Type"); const net_instaweb::ContentType* content_type = net_instaweb::MimeTypeToContentType(s_content_type); - if (ctx->record_in_place && content_type != NULL) { + if (ctx->record_in_place && content_type != NULL) { GoogleString cache_url = *ctx->url_string; ctx->server_context->rewrite_stats()->ipro_not_in_cache()->Add(1); ctx->server_context->message_handler()->Message( @@ -1069,7 +1069,7 @@ transform_plugin(TSCont contp, TSEvent event, void *edata) // (or at least a note that it cannot be cached stored there). // We do that using an Apache output filter. // TODO(oschaaf): fix host/ip(?) - SystemRequestContext* system_request_context = + SystemRequestContext* system_request_context = new SystemRequestContext(ctx->server_context->thread_system()->NewMutex(), ctx->server_context->timer(), "www.foo.com", @@ -1100,14 +1100,14 @@ transform_plugin(TSCont contp, TSEvent event, void *edata) ok = false; TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE); return 0; - } + } } - + if (ok) { StringPiece content_encoding = get_header(response_header_buf, response_header_loc, "Content-Encoding"); net_instaweb::GzipInflater::InflateType inflate_type; bool is_encoded = false; - + if (StringCaseEqual(content_encoding, "deflate")) { is_encoded = true; inflate_type = GzipInflater::kDeflate; @@ -1125,7 +1125,7 @@ transform_plugin(TSCont contp, TSEvent event, void *edata) TSDebug(DEBUG_TAG, "Will optimize [%s]", ctx->url_string->c_str()); } else if (ctx->recorder != NULL) { TSDebug(DEBUG_TAG, "Will record in place: [%s]", ctx->url_string->c_str()); - } else { + } else { CHECK(false) << "At this point, adding a transform makes no sense"; } @@ -1133,9 +1133,9 @@ transform_plugin(TSCont contp, TSEvent event, void *edata) ats_pagespeed_transform_add(txn); } - TSHandleMLocRelease(response_header_buf, TS_NULL_MLOC, response_header_loc); + TSHandleMLocRelease(response_header_buf, TS_NULL_MLOC, response_header_loc); TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE); - + return 0; } @@ -1156,8 +1156,8 @@ bool RegisterPlugin() { void cleanup_process() { delete ats_process_context; - AtsRewriteDriverFactory::Terminate(); - AtsRewriteOptions::Terminate(); + AtsRewriteDriverFactory::Terminate(); + AtsRewriteOptions::Terminate(); } static void @@ -1166,7 +1166,7 @@ process_configuration() AtsConfig* new_config = new AtsConfig((AtsThreadSystem*)ats_process_context->server_context()->thread_system()); DIR *dir; struct dirent *ent; - + if ((dir = opendir ("/usr/local/etc/trafficserver/psol/")) != NULL) { while ((ent = readdir (dir)) != NULL) { size_t len = strlen(ent->d_name); @@ -1201,14 +1201,14 @@ config_notification_callback(void *data) int BUF_MAX = 1024 * (sizeof(struct inotify_event) + 16); char buf[BUF_MAX]; int fd,wd; - + fd = inotify_init(); if (fd < 0) { perror( "inotify_init" ); CHECK(false) << "Failed to initialize inotify"; } - + wd = inotify_add_watch(fd, "/usr/local/etc/trafficserver/psol/", IN_MODIFY | IN_CREATE | IN_DELETE); while (1) { @@ -1249,8 +1249,8 @@ void TSPluginInit(int argc, const char *argv[]) { CHECK(false) << "failed to reserve an argument index"; } - AtsRewriteOptions::Initialize(); - AtsRewriteDriverFactory::Initialize(); + AtsRewriteOptions::Initialize(); + AtsRewriteDriverFactory::Initialize(); net_instaweb::log_message_handler::Install(); atexit(cleanup_process); ats_process_context = new AtsProcessContext();
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/ats_pagespeed/ats_process_context.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/ats_pagespeed/ats_process_context.cc b/plugins/experimental/ats_pagespeed/ats_process_context.cc index f3ca481..866ee68 100644 --- a/plugins/experimental/ats_pagespeed/ats_process_context.cc +++ b/plugins/experimental/ats_pagespeed/ats_process_context.cc @@ -56,7 +56,7 @@ namespace net_instaweb { 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; @@ -70,9 +70,9 @@ namespace net_instaweb { //return NGX_ERROR; CHECK(false); } - + AtsRewriteDriverFactory::InitStats(global_statistics); - + driver_factory()->RootInit(); driver_factory()->ChildInit(); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/ats_pagespeed/ats_resource_intercept.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/ats_pagespeed/ats_resource_intercept.cc b/plugins/experimental/ats_pagespeed/ats_resource_intercept.cc index 3a3b90f..d2c1fc1 100644 --- a/plugins/experimental/ats_pagespeed/ats_resource_intercept.cc +++ b/plugins/experimental/ats_pagespeed/ats_resource_intercept.cc @@ -112,7 +112,7 @@ resource_intercept(TSCont cont, TSEvent event, void *edata) // 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) { + 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); @@ -120,7 +120,7 @@ resource_intercept(TSCont cont, TSEvent event, void *edata) AtsServerContext* server_context = intercept_ctx->request_ctx->server_context; // TODO:(oschaaf) host/port - SystemRequestContext* system_request_context = + SystemRequestContext* system_request_context = new SystemRequestContext(server_context->thread_system()->NewMutex(), server_context->timer(), "www.foo.com",// TODO(oschaaf): compute these @@ -140,7 +140,7 @@ resource_intercept(TSCont cont, TSEvent event, void *edata) 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, @@ -148,10 +148,10 @@ resource_intercept(TSCont cont, TSEvent event, void *edata) 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(); @@ -173,7 +173,7 @@ resource_intercept(TSCont cont, TSEvent event, void *edata) TSDebug("ats-speed", "resource intercept writing out a %d bytes response", (int)numBytesToWrite); 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 { @@ -227,7 +227,7 @@ read_cache_header_callback(TSCont cont, TSEvent event, void *edata) if (ctx == NULL) { TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE); return 0; - } else if (ctx->in_place && !cache_hit(txn) && !ctx->resource_request) { + } else if (ctx->in_place && !cache_hit(txn) && !ctx->resource_request) { ctx->base_fetch->set_ctx(ctx); ctx->base_fetch->set_ipro_callback((void*)resource_intercept); ctx->driver->FetchInPlaceResource( @@ -237,7 +237,7 @@ read_cache_header_callback(TSCont cont, TSEvent event, void *edata) return 0; } else if (!ctx->resource_request) { TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE); - return 0; + return 0; } // TODO(oschaaf): FIXME: Ownership of ctx has become too mucky. // This is because I realised too late that the intercepts @@ -248,7 +248,7 @@ read_cache_header_callback(TSCont cont, TSEvent event, void *edata) TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE); return 0; } - + if (cache_hit(txn)) { ats_ctx_destroy(ctx); TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE); @@ -263,8 +263,8 @@ read_cache_header_callback(TSCont cont, TSEvent event, void *edata) ContentType content_type = kContentTypeHtml; StringPiece cache_control = HttpAttributes::kNoCache; const char* error_message = NULL; - StringPiece request_uri_path = ctx->gurl->PathAndLeaf(); - + 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()); @@ -280,7 +280,7 @@ read_cache_header_callback(TSCont cont, TSEvent event, void *edata) } // TODO(oschaaf): /pagespeed_admin handling - } else { + } else { // Optimized resource are highly cacheable (1 year expiry) // TODO(oschaaf): configuration TSHttpTxnRespCacheableSet(txn, 1); @@ -293,7 +293,7 @@ read_cache_header_callback(TSCont cont, TSEvent event, void *edata) TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE); return 0; } - + TSCont interceptCont = TSContCreate(resource_intercept, TSMutexCreate()); InterceptCtx *intercept_ctx = new InterceptCtx(); intercept_ctx->request_ctx = ctx; @@ -301,12 +301,12 @@ read_cache_header_callback(TSCont cont, TSEvent event, void *edata) 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; @@ -334,9 +334,9 @@ read_cache_header_callback(TSCont cont, TSEvent event, void *edata) 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(); + InterceptCtx *intercept_ctx = new InterceptCtx(); intercept_ctx->request_ctx = ctx; header.append(output); TSHttpTxnRespCacheableSet(txn, 0); @@ -344,7 +344,7 @@ read_cache_header_callback(TSCont cont, TSEvent event, void *edata) TSContDataSet(interceptCont, intercept_ctx); TSHttpTxnServerIntercept(interceptCont, txn); intercept_ctx->response->append(header); - + TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE); return 0; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/ats_pagespeed/ats_resource_intercept.h ---------------------------------------------------------------------- diff --git a/plugins/experimental/ats_pagespeed/ats_resource_intercept.h b/plugins/experimental/ats_pagespeed/ats_resource_intercept.h index b6dcbe2..82dec7d 100644 --- a/plugins/experimental/ats_pagespeed/ats_resource_intercept.h +++ b/plugins/experimental/ats_pagespeed/ats_resource_intercept.h @@ -48,7 +48,7 @@ struct InterceptCtx GoogleString* response; TransformCtx* request_ctx; RequestHeaders* request_headers; - + InterceptCtx() : vconn(NULL) , req_buffer(NULL) http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/ats_pagespeed/ats_rewrite_driver_factory.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/ats_pagespeed/ats_rewrite_driver_factory.cc b/plugins/experimental/ats_pagespeed/ats_rewrite_driver_factory.cc index b270f3a..445891d 100644 --- a/plugins/experimental/ats_pagespeed/ats_rewrite_driver_factory.cc +++ b/plugins/experimental/ats_pagespeed/ats_rewrite_driver_factory.cc @@ -64,7 +64,7 @@ namespace net_instaweb { const ProcessContext& process_context, AtsThreadSystem* thread_system, StringPiece hostname, int port) - : SystemRewriteDriverFactory(process_context, + : 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())) @@ -76,7 +76,7 @@ namespace net_instaweb { default_options()->set_beacon_url("/ats_pagespeed_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/"); @@ -90,7 +90,7 @@ namespace net_instaweb { 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"); @@ -98,7 +98,7 @@ namespace net_instaweb { 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_); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/ats_pagespeed/ats_rewrite_driver_factory.h ---------------------------------------------------------------------- diff --git a/plugins/experimental/ats_pagespeed/ats_rewrite_driver_factory.h b/plugins/experimental/ats_pagespeed/ats_rewrite_driver_factory.h index ea0cb27..293e246 100644 --- a/plugins/experimental/ats_pagespeed/ats_rewrite_driver_factory.h +++ b/plugins/experimental/ats_pagespeed/ats_rewrite_driver_factory.h @@ -50,7 +50,7 @@ namespace net_instaweb { class StaticAssetManager; //class SystemCaches; -class AtsRewriteDriverFactory : public SystemRewriteDriverFactory { +class AtsRewriteDriverFactory : public SystemRewriteDriverFactory { public: explicit AtsRewriteDriverFactory(const ProcessContext& process_context, AtsThreadSystem* thread_system, @@ -71,7 +71,7 @@ class AtsRewriteDriverFactory : public SystemRewriteDriverFactory { } //virtual void InitStaticAssetManager(StaticAssetManager* static_js_manager); - + // Initializes all the statistics objects created transitively by // AtsRewriteDriverFactory, including nginx-specific and // platform-independent statistics. http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/ats_pagespeed/gzip/configuration.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/ats_pagespeed/gzip/configuration.cc b/plugins/experimental/ats_pagespeed/gzip/configuration.cc index b1c499d..dd4c4e8 100644 --- a/plugins/experimental/ats_pagespeed/gzip/configuration.cc +++ b/plugins/experimental/ats_pagespeed/gzip/configuration.cc @@ -130,7 +130,7 @@ namespace Gzip { bool HostConfiguration::ContentTypeIsCompressible(const char * content_type, int content_type_length) { string scontent_type(content_type, content_type_length); bool is_match = false; - + for (size_t i = 0; i < compressible_content_types_.size(); i++) { const char* match_string = compressible_content_types_[i].c_str(); bool exclude = match_string[0] == '!'; @@ -168,7 +168,7 @@ namespace Gzip { current_host_configuration->add_compressible_content_type("*javascript*"); current_host_configuration->add_compressible_content_type("image/svg+xml"); - + if (pathstring.empty()) { return c; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/ats_pagespeed/gzip/configuration.h ---------------------------------------------------------------------- diff --git a/plugins/experimental/ats_pagespeed/gzip/configuration.h b/plugins/experimental/ats_pagespeed/gzip/configuration.h index b38cb64..da11b35 100644 --- a/plugins/experimental/ats_pagespeed/gzip/configuration.h +++ b/plugins/experimental/ats_pagespeed/gzip/configuration.h @@ -29,7 +29,7 @@ #include <vector> #include "debug_macros.h" -namespace Gzip { +namespace Gzip { class HostConfiguration { public: //todo -> only configuration should be able to construct hostconfig explicit HostConfiguration(const std::string & host) @@ -40,11 +40,11 @@ namespace Gzip { {} inline bool enabled() { return enabled_; } - inline void set_enabled(bool x) { enabled_ = x; } + inline void set_enabled(bool x) { enabled_ = x; } inline bool cache() { return cache_; } - inline void set_cache(bool x) { cache_ = x; } + inline void set_cache(bool x) { cache_ = x; } inline bool remove_accept_encoding() { return remove_accept_encoding_; } - inline void set_remove_accept_encoding(bool x) { remove_accept_encoding_ = x; } + inline void set_remove_accept_encoding(bool x) { remove_accept_encoding_ = x; } inline std::string host() { return host_; } void add_disallow(const std::string & disallow); void add_compressible_content_type(const std::string & content_type); @@ -65,7 +65,7 @@ namespace Gzip { friend class HostConfiguration; public: static Configuration * Parse(const char * path); - HostConfiguration * Find(const char * host, int host_length); + HostConfiguration * Find(const char * host, int host_length); inline HostConfiguration * GlobalConfiguration() { return host_configurations_[0]; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/ats_pagespeed/gzip/gzip.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/ats_pagespeed/gzip/gzip.cc b/plugins/experimental/ats_pagespeed/gzip/gzip.cc index 057437f..ee92872 100644 --- a/plugins/experimental/ats_pagespeed/gzip/gzip.cc +++ b/plugins/experimental/ats_pagespeed/gzip/gzip.cc @@ -43,9 +43,9 @@ using namespace Gzip; // from mod_deflate: // ZLIB's compression algorithm uses a -// 0-9 based scale that GZIP does where '1' is 'Best speed' -// and '9' is 'Best compression'. Testing has proved level '6' -// to be about the best level to use in an HTTP Server. +// 0-9 based scale that GZIP does where '1' is 'Best speed' +// and '9' is 'Best compression'. Testing has proved level '6' +// to be about the best level to use in an HTTP Server. const int ZLIB_COMPRESSION_LEVEL = 6; @@ -152,7 +152,7 @@ gzip_vary_header(TSMBuffer bufp, TSMLoc hdr_loc) ce_loc = TSMimeHdrFieldFind(bufp, hdr_loc, "Vary", sizeof("Vary") - 1); if (ce_loc) { - int idx, count, len; + int idx, count, len; const char *value; count = TSMimeHdrFieldValuesCount(bufp, hdr_loc, ce_loc); @@ -558,7 +558,7 @@ gzip_transformable(TSHttpTxn txnp, int server, HostConfiguration * host_configur value = TSMimeHdrFieldValueStringGet(bufp, hdr_loc, field_loc, 0, &len); int rv = host_configuration->ContentTypeIsCompressible(value, len); - if (!rv) { + if (!rv) { info("content-type [%.*s] not compressible", len, value); } TSHandleMLocRelease(bufp, hdr_loc, field_loc); @@ -600,7 +600,7 @@ gzip_transform_add(TSHttpTxn txnp, int /* server ATS_UNUSED */, HostConfiguratio } TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); } - + TSHttpTxnTransformedRespCache(txnp, cache); } @@ -636,7 +636,7 @@ cache_transformable(TSHttpTxn txnp) return 0; } -HostConfiguration * +HostConfiguration * find_host_configuration(TSHttpTxn /* txnp ATS_UNUSED */, TSMBuffer bufp, TSMLoc locp) { TSMLoc fieldp = TSMimeHdrFieldFind(bufp, locp, TS_MIME_FIELD_HOST, TS_MIME_LEN_HOST); @@ -646,7 +646,7 @@ find_host_configuration(TSHttpTxn /* txnp ATS_UNUSED */, TSMBuffer bufp, TSMLoc const char *strv = TSMimeHdrFieldValueStringGet(bufp, locp, fieldp, -1, &strl); TSHandleMLocRelease(bufp, locp, fieldp); - HostConfiguration * host_configuration = config->Find(strv, strl); + HostConfiguration * host_configuration = config->Find(strv, strl); return host_configuration; } @@ -677,7 +677,7 @@ transform_plugin(TSCont /* contp ATS_UNUSED */, TSEvent event, void *edata) TSHttpTxnArgSet(txnp, arg_idx_url_disallowed, (void *) &GZIP_ONE); info("url [%.*s] not allowed", url_len, url); } else { - normalize_accept_encoding(txnp, req_buf, req_loc); + normalize_accept_encoding(txnp, req_buf, req_loc); } TSfree(url); TSHandleMLocRelease(req_buf, TS_NULL_MLOC, req_loc); @@ -691,7 +691,7 @@ transform_plugin(TSCont /* contp ATS_UNUSED */, TSEvent event, void *edata) //os: the accept encoding header needs to be restored.. //otherwise the next request won't get a cache hit on this HostConfiguration * hc = (HostConfiguration*)TSHttpTxnArgGet(txnp, arg_idx_host_configuration); - if (hc != NULL) { + if (hc != NULL) { if (hc->remove_accept_encoding()) { TSMBuffer req_buf; TSMLoc req_loc; @@ -731,7 +731,7 @@ transform_plugin(TSCont /* contp ATS_UNUSED */, TSEvent event, void *edata) { int allowed = !TSHttpTxnArgGet(txnp, arg_idx_url_disallowed); HostConfiguration * hc = (HostConfiguration*)TSHttpTxnArgGet(txnp, arg_idx_host_configuration); - if ( hc != NULL ) { + if ( hc != NULL ) { if (allowed && cache_transformable(txnp) && gzip_transformable(txnp, 0, hc, &compress_type)) { gzip_transform_add(txnp, 0, hc, compress_type); } @@ -780,7 +780,7 @@ TSPluginInit(int argc, const char *argv[]) if (argc > 2) { fatal("the gzip plugin does not accept more than 1 plugin argument"); - } else if (argc == 2) { + } else if (argc == 2) { config_path = std::string(argv[1]); } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/ats_pagespeed/gzip/misc.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/ats_pagespeed/gzip/misc.cc b/plugins/experimental/ats_pagespeed/gzip/misc.cc index 0ea6911..bb7e213 100644 --- a/plugins/experimental/ats_pagespeed/gzip/misc.cc +++ b/plugins/experimental/ats_pagespeed/gzip/misc.cc @@ -48,8 +48,8 @@ normalize_accept_encoding(TSHttpTxn /* txnp ATS_UNUSED */, TSMBuffer reqp, TSMLo int deflate = 0; int gzip = 0; - //remove the accept encoding field(s), - //while finding out if gzip or deflate is supported. + //remove the accept encoding field(s), + //while finding out if gzip or deflate is supported. while (field) { TSMLoc tmp; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/background_fetch/background_fetch.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/background_fetch/background_fetch.cc b/plugins/experimental/background_fetch/background_fetch.cc index 69ae162..4b00179 100644 --- a/plugins/experimental/background_fetch/background_fetch.cc +++ b/plugins/experimental/background_fetch/background_fetch.cc @@ -674,7 +674,7 @@ check_client_ip_configured(TSHttpTxn txnp, const char* cfg_ip) if ((strlen(cfg_ip) == strlen(ip_buf)) && !strcmp(cfg_ip, ip_buf)) { TSDebug(PLUGIN_NAME,"bg fetch for ip %s, configured ip %s", ip_buf, cfg_ip); - return true; + return true; } return false; @@ -819,7 +819,7 @@ cont_handle_response(TSCont contp, TSEvent /* event ATS_UNUSED */, void* edata) { // ToDo: If we want to support per-remap configurations, we have to pass along the data here TSHttpTxn txnp = static_cast<TSHttpTxn>(edata); - BgFetchRuleMap *ri = static_cast<BgFetchRuleMap*>(TSContDataGet(contp)); + BgFetchRuleMap *ri = static_cast<BgFetchRuleMap*>(TSContDataGet(contp)); if (ri == NULL) { // something wrong.. @@ -939,7 +939,7 @@ TSRemapNewInstance(int argc, char* argv[], void** ih, char* /* errbuf */, int / TSError("%s:Unable to create remap instance", PLUGIN_NAME); return TS_ERROR; } - + if (gConfig == NULL) { TSDebug(PLUGIN_NAME, "creating gConfig"); gConfig = new BGFetchConfig(); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/buffer_upload/buffer_upload.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/buffer_upload/buffer_upload.cc b/plugins/experimental/buffer_upload/buffer_upload.cc index d7f13e1..1957ab8 100644 --- a/plugins/experimental/buffer_upload/buffer_upload.cc +++ b/plugins/experimental/buffer_upload/buffer_upload.cc @@ -24,7 +24,7 @@ /* buffer_upload.c - plugin for buffering POST data on proxy server * before connecting to origin server. It supports two types of buffering: * memory-only buffering and disk buffering - * + * */ #include <stdio.h> @@ -45,7 +45,7 @@ #define DEBUG_TAG "buffer_upload-dbg" /************************************************** - Log macros for error code return verification + Log macros for error code return verification **************************************************/ #define PLUGIN_NAME "buffer_upload" //#define LOG_SET_FUNCTION_NAME(NAME) const char * FUNCTION_NAME = NAME @@ -275,7 +275,7 @@ pvc_process_accept(TSCont contp, int event, void *edata, pvc_state * my_state) my_state->req_reader = TSIOBufferReaderAlloc(my_state->req_buffer); // set the maximum memory buffer size for request (both request header and post data), default is 32K // only apply to memory buffer mode - if (uconfig->use_disk_buffer == 0) { + if (uconfig->use_disk_buffer == 0) { TSIOBufferWaterMarkSet(my_state->req_buffer, uconfig->mem_buffer_size); } my_state->resp_buffer = TSIOBufferCreate(); @@ -951,7 +951,7 @@ create_directory() } } dir = opendir("."); - if (dir == NULL) + if (dir == NULL) goto error_out; while ((d = readdir(dir))) { remove(d->d_name); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/custom_redirect/custom_redirect.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/custom_redirect/custom_redirect.cc b/plugins/experimental/custom_redirect/custom_redirect.cc index 5af9a83..9750693 100644 --- a/plugins/experimental/custom_redirect/custom_redirect.cc +++ b/plugins/experimental/custom_redirect/custom_redirect.cc @@ -102,11 +102,11 @@ plugin_main_handler (TSCont contp, TSEvent event, void *edata) handle_response(txnp, contp); break; } - - + + default: { - TSDebug( "[custom_redirect]", "default event"); + TSDebug( "[custom_redirect]", "default event"); break; } } @@ -134,14 +134,14 @@ TSPluginInit (int argc, const char *argv[]) info.plugin_name = (char*)""; info.vendor_name = (char*)"Apache Software Foundation"; info.support_email = (char*)"[email protected]"; -*/ +*/ /* This plugin supports following types of url redirect here: - * - * 1. User can specify a particular redirect-url header name in the plugin command line, + * + * 1. User can specify a particular redirect-url header name in the plugin command line, * in which case plugin will just look for that header in response and redirect to it. * *OR: - * 2. User can also specify a return error code, in which case if the code matches with + * 2. User can also specify a return error code, in which case if the code matches with * the response, plugin will look for the standard "Location" header and redirect to it * *OR: http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/esi/combo_handler.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/esi/combo_handler.cc b/plugins/experimental/esi/combo_handler.cc index c98be63..ff6003e 100644 --- a/plugins/experimental/esi/combo_handler.cc +++ b/plugins/experimental/esi/combo_handler.cc @@ -279,7 +279,7 @@ handleReadRequestHeader(TSCont /* contp ATS_UNUSED */, TSEvent event, void *edat TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE); return 0; } - + LOG_DEBUG("combo is enabled for this channel"); LOG_DEBUG("handling TS_EVENT_HTTP_OS_DNS event..."); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/esi/esi.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/esi/esi.cc b/plugins/experimental/esi/esi.cc index ce355b5..10f6f16 100644 --- a/plugins/experimental/esi/esi.cc +++ b/plugins/experimental/esi/esi.cc @@ -21,7 +21,7 @@ limitations under the License. */ -#include "ink_defs.h" +#include "ink_defs.h" #include <stdio.h> #include <stdlib.h> @@ -125,7 +125,7 @@ struct ContData ContData(TSCont contptr, TSHttpTxn tx) : curr_state(READING_ESI_DOC), input_vio(NULL), output_vio(NULL), output_buffer(NULL), output_reader(NULL), - esi_vars(NULL), data_fetcher(NULL), esi_proc(NULL), esi_gzip(NULL), esi_gunzip(NULL), + esi_vars(NULL), data_fetcher(NULL), esi_proc(NULL), esi_gzip(NULL), esi_gunzip(NULL), contp(contptr), txnp(tx), request_url(NULL), input_type(DATA_TYPE_RAW_ESI), packed_node_list(""), gzipped_data(""), gzip_output(false), @@ -245,7 +245,7 @@ ContData::init() createDebugTag(PARSER_DEBUG_TAG, contp, fetcher_tag), createDebugTag(EXPR_DEBUG_TAG, contp, expr_tag), &TSDebug, &TSError, *data_fetcher, *esi_vars, *gHandlerManager); - + esi_gzip = new EsiGzip(createDebugTag(GZIP_DEBUG_TAG, contp, gzip_tag), &TSDebug, &TSError); esi_gunzip = new EsiGunzip(createDebugTag(GUNZIP_DEBUG_TAG, contp, gunzip_tag), &TSDebug, &TSError); @@ -721,7 +721,7 @@ transformData(TSCont contp) if (cont_data->input_type != DATA_TYPE_PACKED_ESI) { bool gunzip_complete = true; if (cont_data->input_type == DATA_TYPE_GZIPPED_ESI) { - gunzip_complete = cont_data->esi_gunzip->stream_finish(); + gunzip_complete = cont_data->esi_gunzip->stream_finish(); } if (cont_data->esi_proc->completeParse() && gunzip_complete) { if (cont_data->option_info->packed_node_support && cont_data->os_response_cacheable @@ -826,7 +826,7 @@ transformData(TSCont contp) } else { TSError("[%s] ESI processor failed to process document; will return empty document", __FUNCTION__); out_data.assign(""); - + if(!cont_data->xform_closed) { TSVIONBytesSet(cont_data->output_vio, 0); TSVIOReenable(cont_data->output_vio); @@ -856,7 +856,7 @@ transformData(TSCont contp) } } } - if(!cont_data->xform_closed) { + if(!cont_data->xform_closed) { // should not set any fixed length if(cont_data->curr_state == ContData::PROCESSING_COMPLETE) { if(cont_data->gzip_output) { @@ -864,8 +864,8 @@ transformData(TSCont contp) int downstream_length; if(!cont_data->esi_gzip->stream_finish(cdata, downstream_length)) { TSError("[%s] Error while finishing gzip", __FUNCTION__); - return 0; - } else { + return 0; + } else { if(TSVIOBufferGet(cont_data->output_vio) == NULL) { TSError("[%s] Error while writing bytes to downstream VC", __FUNCTION__); return 0; @@ -877,7 +877,7 @@ transformData(TSCont contp) TSDebug(cont_data->debug_tag, "[%s] ESI processed overall/gzip: %d", __FUNCTION__, downstream_length ); - TSVIONBytesSet(cont_data->output_vio, downstream_length); + TSVIONBytesSet(cont_data->output_vio, downstream_length); } } else { TSDebug(cont_data->debug_tag, @@ -885,8 +885,8 @@ transformData(TSCont contp) __FUNCTION__, overall_len ); TSVIONBytesSet(cont_data->output_vio, overall_len); } - } - + } + // Reenable the output connection so it can read the data we've produced. TSVIOReenable(cont_data->output_vio); } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/esi/fetcher/FetchedDataProcessor.h ---------------------------------------------------------------------- diff --git a/plugins/experimental/esi/fetcher/FetchedDataProcessor.h b/plugins/experimental/esi/fetcher/FetchedDataProcessor.h index eaff189..e5b33ce 100644 --- a/plugins/experimental/esi/fetcher/FetchedDataProcessor.h +++ b/plugins/experimental/esi/fetcher/FetchedDataProcessor.h @@ -25,13 +25,13 @@ #define _FETCHED_DATA_PROCESSOR_H -class FetchedDataProcessor { +class FetchedDataProcessor { public: FetchedDataProcessor() { }; - virtual void processData(const char *reqeust_url, int request_url_len, + virtual void processData(const char *reqeust_url, int request_url_len, const char *response_data, int response_data_len) = 0; virtual ~FetchedDataProcessor() { }; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/esi/fetcher/HttpDataFetcherImpl.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/esi/fetcher/HttpDataFetcherImpl.cc b/plugins/experimental/esi/fetcher/HttpDataFetcherImpl.cc index 7de78cf..a44cc3d 100644 --- a/plugins/experimental/esi/fetcher/HttpDataFetcherImpl.cc +++ b/plugins/experimental/esi/fetcher/HttpDataFetcherImpl.cc @@ -55,16 +55,16 @@ HttpDataFetcherImpl::HttpDataFetcherImpl(TSCont contp,sockaddr const* client_add } HttpDataFetcherImpl::~HttpDataFetcherImpl() -{ - clear(); - TSHttpParserDestroy(_http_parser); +{ + clear(); + TSHttpParserDestroy(_http_parser); } bool HttpDataFetcherImpl::addFetchRequest(const string &url, FetchedDataProcessor *callback_obj /* = 0 */) { // do we already have a request for this? - std::pair<UrlToContentMap::iterator, bool> insert_result = + std::pair<UrlToContentMap::iterator, bool> insert_result = _pages.insert(UrlToContentMap::value_type(url, RequestData())); if (callback_obj) { ((insert_result.first)->second).callback_objects.push_back(callback_obj); @@ -75,7 +75,7 @@ HttpDataFetcherImpl::addFetchRequest(const string &url, FetchedDataProcessor *ca return true; } - char buff[1024]; + char buff[1024]; char *http_req; int length; @@ -102,7 +102,7 @@ HttpDataFetcherImpl::addFetchRequest(const string &url, FetchedDataProcessor *ca if (http_req != buff) { free(http_req); } - + TSDebug(_debug_tag, "[%s] Successfully added fetch request for URL [%s]", __FUNCTION__, url.data()); _page_entry_lookup.push_back(insert_result.first); ++_n_pending_requests; @@ -160,7 +160,7 @@ HttpDataFetcherImpl::handleFetchEvent(TSEvent event, void *edata) req_data.hdr_loc = TSHttpHdrCreate(req_data.bufp); TSHttpHdrTypeSet(req_data.bufp, req_data.hdr_loc, TS_HTTP_TYPE_RESPONSE); TSHttpParserClear(_http_parser); - + if (TSHttpHdrParseResp(_http_parser, req_data.bufp, req_data.hdr_loc, &startptr, endptr) == TS_PARSE_DONE) { req_data.resp_status = TSHttpHdrStatusGet(req_data.bufp, req_data.hdr_loc); valid_data_received = true; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/esi/fetcher/HttpDataFetcherImpl.h ---------------------------------------------------------------------- diff --git a/plugins/experimental/esi/fetcher/HttpDataFetcherImpl.h b/plugins/experimental/esi/fetcher/HttpDataFetcherImpl.h index 29dccaa..44860b3 100644 --- a/plugins/experimental/esi/fetcher/HttpDataFetcherImpl.h +++ b/plugins/experimental/esi/fetcher/HttpDataFetcherImpl.h @@ -41,11 +41,11 @@ public: HttpDataFetcherImpl(TSCont contp, sockaddr const* client_addr, const char *debug_tag); void useHeader(const EsiLib::HttpHeader &header); - + void useHeaders(const EsiLib::HttpHeaderList &headers); bool addFetchRequest(const std::string &url, FetchedDataProcessor *callback_obj = 0); - + bool handleFetchEvent(TSEvent event, void *edata); bool isFetchEvent(TSEvent event) const { @@ -88,12 +88,12 @@ public: ~HttpDataFetcherImpl(); private: - + TSCont _contp; char _debug_tag[64]; typedef std::list<FetchedDataProcessor *> CallbackObjectList; - + // used to track a request that was made struct RequestData { std::string response; @@ -130,7 +130,7 @@ private: std::string _headers_str; - + inline void _release(RequestData &req_data); sockaddr const* _client_addr; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/esi/lib/ComponentBase.h ---------------------------------------------------------------------- diff --git a/plugins/experimental/esi/lib/ComponentBase.h b/plugins/experimental/esi/lib/ComponentBase.h index 487a6c9..c746a48 100644 --- a/plugins/experimental/esi/lib/ComponentBase.h +++ b/plugins/experimental/esi/lib/ComponentBase.h @@ -41,16 +41,16 @@ public: typedef void (*Error)(const char *, ...); protected: - - ComponentBase(const char *debug_tag, Debug debug_func, Error error_func) + + ComponentBase(const char *debug_tag, Debug debug_func, Error error_func) : _debugLog(debug_func), _errorLog(error_func) { snprintf(_debug_tag, sizeof(_debug_tag), "%s", debug_tag); }; - + char _debug_tag[DEBUG_TAG_MAX_SIZE]; Debug _debugLog; Error _errorLog; - + virtual ~ComponentBase() { }; }; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/esi/lib/DocNode.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/esi/lib/DocNode.cc b/plugins/experimental/esi/lib/DocNode.cc index c35f28a..bffcba1 100644 --- a/plugins/experimental/esi/lib/DocNode.cc +++ b/plugins/experimental/esi/lib/DocNode.cc @@ -43,7 +43,7 @@ const char *DocNode::type_names_[] = { "UNKNOWN", "SPECIAL_INCLUDE" }; -// helper functions +// helper functions inline void packString(const char *str, int32_t str_len, string &buffer) { http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/esi/lib/DocNode.h ---------------------------------------------------------------------- diff --git a/plugins/experimental/esi/lib/DocNode.h b/plugins/experimental/esi/lib/DocNode.h index fa1986f..a6198a1 100644 --- a/plugins/experimental/esi/lib/DocNode.h +++ b/plugins/experimental/esi/lib/DocNode.h @@ -50,9 +50,9 @@ public: pack(buffer); return buffer; } - + bool unpack(const char *data, int data_len); - + inline bool unpack(const std::string &data) { return unpack(data.data(), data.size()); } @@ -60,7 +60,7 @@ public: private: void packToBuffer(std::string &buffer) const; - + friend class DocNode; // to use the method above }; @@ -68,7 +68,7 @@ private: class DocNode { - + public: enum TYPE { TYPE_UNKNOWN = 0, @@ -87,7 +87,7 @@ public: TYPE_SPECIAL_INCLUDE = 13, }; - // Use with care - only types defined above will have valid names + // Use with care - only types defined above will have valid names static const char *type_names_[]; TYPE type; @@ -98,7 +98,7 @@ public: DocNodeList child_nodes; - DocNode(TYPE _type = TYPE_UNKNOWN, const char *_data = 0, int32_t _data_len = 0) + DocNode(TYPE _type = TYPE_UNKNOWN, const char *_data = 0, int32_t _data_len = 0) : type(_type), data(_data), data_len(_data_len) { }; void pack(std::string &buffer) const; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/esi/lib/EsiGunzip.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/esi/lib/EsiGunzip.cc b/plugins/experimental/esi/lib/EsiGunzip.cc index 2c3042b..4e80d38 100644 --- a/plugins/experimental/esi/lib/EsiGunzip.cc +++ b/plugins/experimental/esi/lib/EsiGunzip.cc @@ -32,13 +32,13 @@ using namespace EsiLib; EsiGunzip::EsiGunzip(const char *debug_tag, ComponentBase::Debug debug_func, ComponentBase::Error error_func) : ComponentBase(debug_tag, debug_func, error_func), - _downstream_length(0), + _downstream_length(0), _total_data_length(0) { _init = false; _success = true; } -bool +bool EsiGunzip::stream_finish() { if(_init) { if (inflateEnd(&_zstrm) != Z_OK) { @@ -58,7 +58,7 @@ EsiGunzip::stream_decode(const char *data, int data_len, std::string &udata) { BufferList buf_list; if(!_init) { - + _zstrm.zalloc = Z_NULL; _zstrm.zfree = Z_NULL; _zstrm.opaque = Z_NULL; @@ -105,13 +105,13 @@ EsiGunzip::stream_decode(const char *data, int data_len, std::string &udata) { // avoid data copy for temporary buf_list.push_back(string()); string &curr_buf = buf_list.back(); - curr_buf.assign(raw_buf, curr_buf_size); + curr_buf.assign(raw_buf, curr_buf_size); if (inflate_result == Z_STREAM_END) { break; } } while (_zstrm.avail_in > 0); - + _total_data_length += data_len; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/esi/lib/EsiGunzip.h ---------------------------------------------------------------------- diff --git a/plugins/experimental/esi/lib/EsiGunzip.h b/plugins/experimental/esi/lib/EsiGunzip.h index b69b6b0..9314f6c 100644 --- a/plugins/experimental/esi/lib/EsiGunzip.h +++ b/plugins/experimental/esi/lib/EsiGunzip.h @@ -1,62 +1,62 @@ -/** @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 _ESI_GUNZIP_H -#define _ESI_GUNZIP_H - -#include "ComponentBase.h" -#include <zlib.h> -#include <string> - -class EsiGunzip : private EsiLib::ComponentBase -{ - -public: - - EsiGunzip(const char *debug_tag, - EsiLib::ComponentBase::Debug debug_func, EsiLib::ComponentBase::Error error_func); - - virtual ~EsiGunzip(); - - bool stream_decode(const char *data, int data_len, std::string &udata); - - inline bool stream_decode(std::string data, std::string &udata) { - return stream_decode(data.data(), data.size(), udata); - } - - bool stream_finish(); - -private: - - int _downstream_length; - int _total_data_length; - z_stream _zstrm; - - bool _init; - bool _success; -}; - - -#endif // _ESI_GUNZIP_H - - +/** @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 _ESI_GUNZIP_H +#define _ESI_GUNZIP_H + +#include "ComponentBase.h" +#include <zlib.h> +#include <string> + +class EsiGunzip : private EsiLib::ComponentBase +{ + +public: + + EsiGunzip(const char *debug_tag, + EsiLib::ComponentBase::Debug debug_func, EsiLib::ComponentBase::Error error_func); + + virtual ~EsiGunzip(); + + bool stream_decode(const char *data, int data_len, std::string &udata); + + inline bool stream_decode(std::string data, std::string &udata) { + return stream_decode(data.data(), data.size(), udata); + } + + bool stream_finish(); + +private: + + int _downstream_length; + int _total_data_length; + z_stream _zstrm; + + bool _init; + bool _success; +}; + + +#endif // _ESI_GUNZIP_H + + http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/esi/lib/EsiGzip.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/esi/lib/EsiGzip.cc b/plugins/experimental/esi/lib/EsiGzip.cc index c7d5534..e6fb56c 100644 --- a/plugins/experimental/esi/lib/EsiGzip.cc +++ b/plugins/experimental/esi/lib/EsiGzip.cc @@ -32,7 +32,7 @@ using namespace EsiLib; EsiGzip::EsiGzip(const char *debug_tag, ComponentBase::Debug debug_func, ComponentBase::Error error_func) : ComponentBase(debug_tag, debug_func, error_func), - _downstream_length(0), + _downstream_length(0), _total_data_length(0) { } @@ -83,7 +83,7 @@ EsiGzip::stream_encode(const char *data, int data_len, std::string &cdata) { _crc = crc32(0, Z_NULL, 0); } - + _zstrm.zalloc = Z_NULL; _zstrm.zfree = Z_NULL; _zstrm.opaque = Z_NULL; @@ -110,7 +110,7 @@ EsiGzip::stream_encode(const char *data, int data_len, std::string &cdata) { _total_data_length += data_len; } - deflateEnd(&_zstrm); + deflateEnd(&_zstrm); return true; } @@ -128,7 +128,7 @@ bool EsiGzip::stream_finish(std::string &cdata, int&downstream_length) { } _zstrm.next_in = reinterpret_cast<Bytef *>(buf); - _zstrm.avail_in = 0; + _zstrm.avail_in = 0; // required for the "finish" loop as no data has been given so far int deflate_result = runDeflateLoop(_zstrm, Z_FINISH, cdata); deflateEnd(&_zstrm); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/esi/lib/EsiParser.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/esi/lib/EsiParser.cc b/plugins/experimental/esi/lib/EsiParser.cc index 22b6856..cf0c2c6 100644 --- a/plugins/experimental/esi/lib/EsiParser.cc +++ b/plugins/experimental/esi/lib/EsiParser.cc @@ -57,9 +57,9 @@ const EsiParser::EsiNodeInfo EsiParser::ESI_NODES[] = { const EsiParser::EsiNodeInfo EsiParser::HTML_COMMENT_NODE_INFO(DocNode::TYPE_HTML_COMMENT, "<!--esi", 7, "-->", 3); -EsiParser::EsiParser(const char *debug_tag, - ComponentBase::Debug debug_func, - ComponentBase::Error error_func) +EsiParser::EsiParser(const char *debug_tag, + ComponentBase::Debug debug_func, + ComponentBase::Error error_func) : ComponentBase(debug_tag, debug_func, error_func), _parse_start_pos(-1) { // do this so that object doesn't move around in memory; // (because we return pointers into this object) @@ -118,7 +118,7 @@ EsiParser::_completeParse(string &data, int &parse_start_pos, size_t &orig_outpu return true; } if (!_parse(data, parse_start_pos, node_list, true)) { - _errorLog("[%s] Failed to complete parse of data of total size %d starting with [%.5s]...", + _errorLog("[%s] Failed to complete parse of data of total size %d starting with [%.5s]...", __FUNCTION__, data.size(), (data.size() ? data.data() : "(null)")); node_list.resize(orig_output_list_size); return false; @@ -130,7 +130,7 @@ EsiParser::MATCH_TYPE EsiParser::_searchData(const string &data, size_t start_pos, const char *str, int str_len, size_t &pos) const { const char *data_ptr = data.data() + start_pos; int data_len = data.size() - start_pos; - int i_data = 0, i_str = 0; + int i_data = 0, i_str = 0; while (i_data < data_len) { if (data_ptr[i_data] == str[i_str]) { @@ -147,12 +147,12 @@ EsiParser::_searchData(const string &data, size_t start_pos, const char *str, in if (i_str == str_len) { pos = start_pos + i_data + 1 - i_str; - _debugLog(_debug_tag, "[%s] Found full match of %.*s in [%.5s...] at position %d", + _debugLog(_debug_tag, "[%s] Found full match of %.*s in [%.5s...] at position %d", __FUNCTION__, str_len, str, data_ptr, pos); return COMPLETE_MATCH; } else if (i_str) { pos = start_pos + i_data - i_str; - _debugLog(_debug_tag, "[%s] Found partial match of %.*s in [%.5s...] at position %d", + _debugLog(_debug_tag, "[%s] Found partial match of %.*s in [%.5s...] at position %d", __FUNCTION__, str_len, str, data_ptr, pos); return PARTIAL_MATCH; } else { @@ -169,20 +169,20 @@ EsiParser::_compareData(const string &data, size_t pos, const char *str, int str if (data[i_data] == str[i_str]) { ++i_str; if (i_str == str_len) { - _debugLog(_debug_tag, "[%s] string [%.*s] is equal to data at position %d", + _debugLog(_debug_tag, "[%s] string [%.*s] is equal to data at position %d", __FUNCTION__, str_len, str, pos); return COMPLETE_MATCH; } } else { /* - _debugLog(_debug_tag, "[%s] string [%.*s] is not equal to data at position %d", + _debugLog(_debug_tag, "[%s] string [%.*s] is not equal to data at position %d", __FUNCTION__, str_len, str, pos); */ return NO_MATCH; } } - _debugLog(_debug_tag, "[%s] string [%.*s] is partially equal to data at position %d", + _debugLog(_debug_tag, "[%s] string [%.*s] is partially equal to data at position %d", __FUNCTION__, str_len, str, pos); return PARTIAL_MATCH; } @@ -299,13 +299,13 @@ EsiParser::_parse(const string &data, int &parse_start_pos, // we have a complete match of the opening tag if ((curr_pos - parse_start_pos) > 0) { // add text till here as a PRE node - _debugLog(_debug_tag, "[%s], Adding data of size %d before (newly found) ESI tag as PRE node", + _debugLog(_debug_tag, "[%s], Adding data of size %d before (newly found) ESI tag as PRE node", __FUNCTION__, curr_pos - parse_start_pos); - node_list.push_back(DocNode(DocNode::TYPE_PRE, + node_list.push_back(DocNode(DocNode::TYPE_PRE, data_start_ptr + parse_start_pos, curr_pos - parse_start_pos)); parse_start_pos = curr_pos; } - + if (is_html_comment_node) { _debugLog(_debug_tag, "[%s] Found html comment tag at position %d", __FUNCTION__, curr_pos); data_ptr = data_start_ptr + curr_pos; @@ -314,7 +314,7 @@ EsiParser::_parse(const string &data, int &parse_start_pos, } else { curr_pos += ESI_TAG_PREFIX_LEN; data_ptr = data_start_ptr + curr_pos; - + for (node_info = ESI_NODES; node_info->type != DocNode::TYPE_UNKNOWN; ++node_info) { search_result = _compareData(data, curr_pos, node_info->tag_suffix, node_info->tag_suffix_len); if (search_result == COMPLETE_MATCH) { @@ -354,7 +354,7 @@ EsiParser::_parse(const string &data, int &parse_start_pos, if ((search_result == NO_MATCH) || (search_result == PARTIAL_MATCH)) { if (last_chunk) { - _errorLog("[%s] ESI tag starting with [%.10s]... has no matching closing tag [%.*s]", __FUNCTION__, + _errorLog("[%s] ESI tag starting with [%.10s]... has no matching closing tag [%.*s]", __FUNCTION__, data_ptr - ESI_TAG_PREFIX_LEN, node_info->closing_tag_len, node_info->closing_tag); goto lFail; } @@ -414,7 +414,7 @@ EsiParser::_parse(const string &data, int &parse_start_pos, } if (!parse_result) { - _errorLog("[%s] Cannot handle ESI tag [%.*s]", __FUNCTION__, + _errorLog("[%s] Cannot handle ESI tag [%.*s]", __FUNCTION__, node_info->tag_suffix_len, node_info->tag_suffix); goto lFail; } @@ -431,9 +431,9 @@ EsiParser::_parse(const string &data, int &parse_start_pos, break; } if (last_chunk && (parse_start_pos < static_cast<int>(data_size))) { - _debugLog(_debug_tag, "[%s] Adding trailing text of size %d starting at [%.5s] as a PRE node", + _debugLog(_debug_tag, "[%s] Adding trailing text of size %d starting at [%.5s] as a PRE node", __FUNCTION__, data_size - parse_start_pos, data_start_ptr + parse_start_pos); - node_list.push_back(DocNode(DocNode::TYPE_PRE, + node_list.push_back(DocNode(DocNode::TYPE_PRE, data_start_ptr + parse_start_pos, data_size - parse_start_pos)); } _debugLog(_debug_tag, "[%s] Added %d node(s) during parse", __FUNCTION__, node_list.size() - orig_list_size); @@ -542,7 +542,7 @@ EsiParser::_processTryTag(const string &data, size_t curr_pos, size_t end_pos, _errorLog("[%s] Cannot have non-whitespace raw text as top level node in try block", __FUNCTION__); return false; } - _debugLog(_debug_tag, "[%s] Ignoring top-level whitespace raw text", __FUNCTION__); + _debugLog(_debug_tag, "[%s] Ignoring top-level whitespace raw text", __FUNCTION__); temp_iter = iter; ++temp_iter; try_node.child_nodes.erase(iter); @@ -590,7 +590,7 @@ EsiParser::_processChooseTag(const string &data, size_t curr_pos, size_t end_pos __FUNCTION__, DocNode::type_names_[iter->type]); return false; } - _debugLog(_debug_tag, "[%s] Ignoring top-level whitespace raw text", __FUNCTION__); + _debugLog(_debug_tag, "[%s] Ignoring top-level whitespace raw text", __FUNCTION__); temp_iter = iter; ++temp_iter; choose_node.child_nodes.erase(iter); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/esi/lib/EsiParser.h ---------------------------------------------------------------------- diff --git a/plugins/experimental/esi/lib/EsiParser.h b/plugins/experimental/esi/lib/EsiParser.h index 2dffc59..65dcff6 100644 --- a/plugins/experimental/esi/lib/EsiParser.h +++ b/plugins/experimental/esi/lib/EsiParser.h @@ -52,14 +52,14 @@ public: }; /** completes the parse including data from previous chunk(s); - * adds newly found nodes to list. optionally a final or the + * adds newly found nodes to list. optionally a final or the * only chunk can be provided. * * Output nodes contain pointers to internal data; use with care. */ bool completeParse(EsiLib::DocNodeList &node_list, const char *data = 0, int data_len = -1) { return _completeParse(_data, _parse_start_pos, _orig_output_list_size, node_list, data, data_len); } - + /** convenient alternative to method above */ bool completeParse(EsiLib::DocNodeList &node_list, const std::string &data) { return completeParse(node_list, data.data(), data.size()); @@ -78,24 +78,24 @@ public: private: - struct EsiNodeInfo + struct EsiNodeInfo { EsiLib::DocNode::TYPE type; const char *tag_suffix; int tag_suffix_len; const char *closing_tag; - int closing_tag_len; + int closing_tag_len; EsiNodeInfo(EsiLib::DocNode::TYPE t, const char *s, int s_len, const char *ct, int ct_len) : type(t), tag_suffix(s), tag_suffix_len(s_len), closing_tag(ct), closing_tag_len(ct_len) { }; }; - + std::string _data; int _parse_start_pos; size_t _orig_output_list_size; static const EsiNodeInfo ESI_NODES[]; static const EsiNodeInfo HTML_COMMENT_NODE_INFO; - + static const char *ESI_TAG_PREFIX; static const int ESI_TAG_PREFIX_LEN; @@ -106,18 +106,18 @@ private: static const unsigned int MAX_DOC_SIZE; enum MATCH_TYPE { NO_MATCH, COMPLETE_MATCH, PARTIAL_MATCH }; - + MATCH_TYPE _searchData(const std::string &data, size_t start_pos, const char *str, int str_len, size_t &pos) const; MATCH_TYPE _compareData(const std::string &data, size_t pos, const char *str, int str_len) const; - + MATCH_TYPE _findOpeningTag(const std::string &data, size_t start_pos, size_t &opening_tag_pos, bool &is_html_comment_node) const; bool _parse(const std::string &data, int &parse_start_pos, EsiLib::DocNodeList &node_list, bool last_chunk = false) const; - + bool _processIncludeTag(const std::string &data, size_t curr_pos, size_t end_pos, EsiLib::DocNodeList &node_list) const; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ab5ba9a8/plugins/experimental/esi/lib/EsiProcessor.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/esi/lib/EsiProcessor.cc b/plugins/experimental/esi/lib/EsiProcessor.cc index 74213d0..9cd8307 100644 --- a/plugins/experimental/esi/lib/EsiProcessor.cc +++ b/plugins/experimental/esi/lib/EsiProcessor.cc @@ -78,7 +78,7 @@ EsiProcessor::addParseData(const char *data, int data_len) { _debugLog(_debug_tag, "[%s] Can only parse in parse stage", __FUNCTION__); return false; } - + if (!_parser.parseChunk(data, _node_list, data_len)) { _errorLog("[%s] Failed to parse chunk; Stopping processor...", __FUNCTION__); error(); @@ -149,7 +149,7 @@ EsiProcessor::_handleParseComplete() { _debugLog(_debug_tag, "[%s] Parsed ESI document with %d nodes", __FUNCTION__, _node_list.size()); _curr_state = WAITING_TO_PROCESS; - + return true; } @@ -172,7 +172,7 @@ EsiProcessor::_getIncludeStatus(const DocNode &node) { } const string &processed_url = iter->second; DataStatus status = _fetcher.getRequestStatus(processed_url); - _debugLog(_debug_tag, "[%s] Got status %d successfully for URL [%.*s]", __FUNCTION__, status, + _debugLog(_debug_tag, "[%s] Got status %d successfully for URL [%.*s]", __FUNCTION__, status, processed_url.size(), processed_url.data()); return status; } else if (node.type == DocNode::TYPE_SPECIAL_INCLUDE) { @@ -183,7 +183,7 @@ EsiProcessor::_getIncludeStatus(const DocNode &node) { } } int include_data_id = attr_iter->value_len; - SpecialIncludeHandler *handler = + SpecialIncludeHandler *handler = reinterpret_cast<SpecialIncludeHandler *>(const_cast<char *>(attr_iter->value)); DataStatus status = handler->getIncludeStatus(include_data_id); _debugLog(_debug_tag, "[%s] Successfully got status for special include with id %d", @@ -228,12 +228,12 @@ EsiProcessor::_getIncludeData(const DocNode &node, const char **content_ptr /* = result = (_fetcher.getRequestStatus(processed_url) == STATUS_DATA_AVAILABLE); } if (!result) { - _errorLog("[%s] Couldn't get content for URL [%.*s]", + _errorLog("[%s] Couldn't get content for URL [%.*s]", __FUNCTION__, processed_url.size(), processed_url.data()); Stats::increment(Stats::N_INCLUDE_ERRS); return false; } - _debugLog(_debug_tag, "[%s] Got content successfully for URL [%.*s]", __FUNCTION__, + _debugLog(_debug_tag, "[%s] Got content successfully for URL [%.*s]", __FUNCTION__, processed_url.size(), processed_url.data()); return true; } else if (node.type == DocNode::TYPE_SPECIAL_INCLUDE) { @@ -244,7 +244,7 @@ EsiProcessor::_getIncludeData(const DocNode &node, const char **content_ptr /* = } } int include_data_id = attr_iter->value_len; - SpecialIncludeHandler *handler = + SpecialIncludeHandler *handler = reinterpret_cast<SpecialIncludeHandler *>(const_cast<char *>(attr_iter->value)); bool result; if (content_ptr && content_len_ptr) { @@ -287,7 +287,7 @@ EsiProcessor::process(const char *&data, int &data_len) { for (node_iter = try_iter->attempt_nodes.begin(); node_iter != try_iter->attempt_nodes.end(); ++node_iter) { if ((node_iter->type == DocNode::TYPE_INCLUDE) || (node_iter->type == DocNode::TYPE_SPECIAL_INCLUDE)) { - const Attribute &url = (*node_iter).attr_list.front(); + const Attribute &url = (*node_iter).attr_list.front(); string raw_url(url.value, url.value_len); attemptUrls.push_back(_expression.expand(raw_url)); if (!_getIncludeData(*node_iter)) { @@ -297,27 +297,27 @@ EsiProcessor::process(const char *&data, int &data_len) { } } } - + /* FAILURE CACHE */ FailureData* data=static_cast<FailureData*>(pthread_getspecific(threadKey)); _debugLog("plugin_esi_failureInfo","[%s]Fetched data related to thread specfic %p",__FUNCTION__,data); - + for (iter=try_iter->attempt_nodes.begin(); iter != try_iter->attempt_nodes.end(); ++iter) { if ((iter->type == DocNode::TYPE_INCLUDE) || iter->type == DocNode::TYPE_SPECIAL_INCLUDE) { if(!attempt_succeeded && iter==node_iter) continue; - const Attribute &url = (*iter).attr_list.front(); + const Attribute &url = (*iter).attr_list.front(); string raw_url(url.value, url.value_len); attemptUrls.push_back(_expression.expand(raw_url)); } } - + if(attemptUrls.size()>0 && data) - { + { FailureData::iterator it =data->find(attemptUrls[0]); FailureInfo* info; - + if(it == data->end()) { _debugLog("plugin_esi_failureInfo","[%s]Inserting object for the attempt URLS",__FUNCTION__); @@ -327,7 +327,7 @@ EsiProcessor::process(const char *&data, int &data_len) { _debugLog("plugin_esi_failureInfo", "[%s] Urls [%.*s]",__FUNCTION__,attemptUrls[i].size(),attemptUrls[i].data()); (*data)[attemptUrls[i]]=info; } - + info->registerSuccFail(attempt_succeeded); } else { @@ -335,15 +335,15 @@ EsiProcessor::process(const char *&data, int &data_len) { //Should be registered only if attemp was made //and it failed if(_reqAdded) - info->registerSuccFail(attempt_succeeded); - + info->registerSuccFail(attempt_succeeded); + } } if (attempt_succeeded) { _debugLog(_debug_tag, "[%s] attempt section succeded; using attempt section", __FUNCTION__); _node_list.splice(try_iter->pos, try_iter->attempt_nodes); } else { - _debugLog(_debug_tag, "[%s] attempt section errored; trying except section", __FUNCTION__); + _debugLog(_debug_tag, "[%s] attempt section errored; trying except section", __FUNCTION__); int n_prescanned_nodes = 0; if (!_preprocess(try_iter->except_nodes, n_prescanned_nodes)) { _errorLog("[%s] Failed to preprocess except nodes", __FUNCTION__); @@ -351,7 +351,7 @@ EsiProcessor::process(const char *&data, int &data_len) { return FAILURE; } _node_list.splice(try_iter->pos, try_iter->except_nodes); - if (_fetcher.getNumPendingRequests()) { + if (_fetcher.getNumPendingRequests()) { _debugLog(_debug_tag, "[%s] New fetch requests were triggered by except block; " "Returning NEED_MORE_DATA...", __FUNCTION__); return NEED_MORE_DATA; @@ -414,13 +414,13 @@ EsiProcessor::flush(string &data, int &overall_len) { if(attempt_pending) { break; } - + ++_n_try_blocks_processed; attempt_succeeded = true; for (node_iter = try_iter->attempt_nodes.begin(); node_iter != try_iter->attempt_nodes.end(); ++node_iter) { if ((node_iter->type == DocNode::TYPE_INCLUDE) || (node_iter->type == DocNode::TYPE_SPECIAL_INCLUDE)) { - const Attribute &url = (*node_iter).attr_list.front(); + const Attribute &url = (*node_iter).attr_list.front(); string raw_url(url.value, url.value_len); attemptUrls.push_back(_expression.expand(raw_url)); if (_getIncludeStatus(*node_iter) != STATUS_DATA_AVAILABLE) { @@ -430,27 +430,27 @@ EsiProcessor::flush(string &data, int &overall_len) { } } } - + /* FAILURE CACHE */ FailureData* fdata=static_cast<FailureData*>(pthread_getspecific(threadKey)); _debugLog("plugin_esi_failureInfo","[%s]Fetched data related to thread specfic %p",__FUNCTION__,fdata); - + for (iter=try_iter->attempt_nodes.begin(); iter != try_iter->attempt_nodes.end(); ++iter) { if ((iter->type == DocNode::TYPE_INCLUDE) || iter->type == DocNode::TYPE_SPECIAL_INCLUDE) { if(!attempt_succeeded && iter==node_iter) continue; - const Attribute &url = (*iter).attr_list.front(); + const Attribute &url = (*iter).attr_list.front(); string raw_url(url.value, url.value_len); attemptUrls.push_back(_expression.expand(raw_url)); } } - + if(attemptUrls.size()>0 && fdata) - { + { FailureData::iterator it =fdata->find(attemptUrls[0]); FailureInfo* info; - + if(it == fdata->end()) { _debugLog("plugin_esi_failureInfo","[%s]Inserting object for the attempt URLS",__FUNCTION__); @@ -460,7 +460,7 @@ EsiProcessor::flush(string &data, int &overall_len) { _debugLog("plugin_esi_failureInfo", "[%s] Urls [%.*s]",__FUNCTION__,attemptUrls[i].size(),attemptUrls[i].data()); (*fdata)[attemptUrls[i]]=info; } - + info->registerSuccFail(attempt_succeeded); } else { @@ -468,8 +468,8 @@ EsiProcessor::flush(string &data, int &overall_len) { //Should be registered only if attemp was made //and it failed if(_reqAdded) - info->registerSuccFail(attempt_succeeded); - + info->registerSuccFail(attempt_succeeded); + } } if (attempt_succeeded) { @@ -477,14 +477,14 @@ EsiProcessor::flush(string &data, int &overall_len) { _n_prescanned_nodes = _n_prescanned_nodes + try_iter->attempt_nodes.size(); _node_list.splice(try_iter->pos, try_iter->attempt_nodes); } else { - _debugLog(_debug_tag, "[%s] attempt section errored; trying except section", __FUNCTION__); + _debugLog(_debug_tag, "[%s] attempt section errored; trying except section", __FUNCTION__); int n_prescanned_nodes = 0; if (!_preprocess(try_iter->except_nodes, n_prescanned_nodes)) { _errorLog("[%s] Failed to preprocess except nodes", __FUNCTION__); } _n_prescanned_nodes = _n_prescanned_nodes + try_iter->except_nodes.size(); _node_list.splice(try_iter->pos, try_iter->except_nodes); - if (_fetcher.getNumPendingRequests()) { + if (_fetcher.getNumPendingRequests()) { _debugLog(_debug_tag, "[%s] New fetch requests were triggered by except block; " "Returning NEED_MORE_DATA...", __FUNCTION__); } @@ -514,7 +514,7 @@ EsiProcessor::flush(string &data, int &overall_len) { ++_n_processed_try_nodes; } } - + _debugLog(_debug_tag, "[%s] really Processing ESI node [%s] with data of size %d starting with [%.10s...]", __FUNCTION__, DocNode::type_names_[doc_node.type], doc_node.data_len, (doc_node.data_len ? doc_node.data: "(null)")); if (doc_node.type == DocNode::TYPE_PRE) { @@ -697,10 +697,10 @@ EsiProcessor::_preprocess(DocNodeList &node_list, int &n_prescanned_nodes) { DocNodeList::iterator list_iter = node_list.begin(); StringHash::iterator hash_iter; string raw_url; - + // skip previously examined nodes for (int i = 0; i < n_prescanned_nodes; ++i, ++list_iter); - + for (; list_iter != node_list.end(); ++list_iter, ++n_prescanned_nodes) { switch (list_iter->type) { case DocNode::TYPE_CHOOSE: @@ -773,7 +773,7 @@ EsiProcessor::_preprocess(DocNodeList &node_list, int &n_prescanned_nodes) { FailureInfo* info; if(it != threadData->end()) { - info=it->second; + info=it->second; fetch=_reqAdded=info->isAttemptReq(); _debugLog(_debug_tag,"[%s] Fetch result is %d",__FUNCTION__,fetch); }
