----------------------------------------------------------------------------
| 378 | |
| 379 | //---------------------------------------------------------------------------- |
| 380 | static int |
| 381 | setup_request(TSCont contp, TSHttpTxn txnp) |
| 382 | { |
| 383 | TSMBuffer bufp; |
| 384 | TSMLoc hdr_loc; |
| 385 | TSMLoc url_loc; |
| 386 | TSCont scan_contp; |
| 387 | const char *path, *query; |
| 388 | cache_scan_state *cstate; |
| 389 | int path_len, query_len; |
| 390 | |
| 391 | TSAssert(contp == global_contp); |
| 392 | |
| 393 | if (TSHttpTxnClientReqGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) { |
| 394 | TSError("[%s] Couldn't retrieve client request header", PLUGIN_NAME); |
| 395 | TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE); |
| 396 | return TS_SUCCESS; |
| 397 | } |
| 398 | |
| 399 | if (TSHttpHdrUrlGet(bufp, hdr_loc, &url_loc) != TS_SUCCESS) { |
| 400 | TSError("[%s] Couldn't retrieve request url", PLUGIN_NAME); |
| 401 | TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); |
| 402 | TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE); |
| 403 | return TS_SUCCESS; |
| 404 | } |
| 405 | |
| 406 | path = TSUrlPathGet(bufp, url_loc, &path_len); |
| 407 | if (!path) { |
| 408 | TSError("[%s] Couldn't retrieve request path", PLUGIN_NAME); |
| 409 | TSHandleMLocRelease(bufp, hdr_loc, url_loc); |
| 410 | TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); |
| 411 | TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE); |
| 412 | return TS_SUCCESS; |
| 413 | } |
| 414 | |
| 415 | query = TSUrlHttpQueryGet(bufp, url_loc, &query_len); |
| 416 | |
| 417 | if (path_len == 10 && !strncmp(path, "show-cache", 10)) { |
| 418 | scan_contp = TSContCreate(cache_intercept, TSMutexCreate()); |
| 419 | TSHttpTxnIntercept(scan_contp, txnp); |
| 420 | cstate = static_cast<cache_scan_state *>(TSmalloc(sizeof(cache_scan_state))); |
| 421 | memset(cstate, 0, sizeof(cache_scan_state)); |
| 422 | cstate->http_txnp = txnp; |
| 423 | |
| 424 | if (query && query_len > 11) { |
| 425 | char querybuf[2048]; |
| 426 | query_len = static_cast<unsigned>(query_len) > sizeof(querybuf) - 1 ? sizeof(querybuf) - 1 : query_len; |
| 427 | char *start = querybuf, *end = querybuf + query_len; |
| 428 | size_t del_url_len; |
| 429 | memcpy(querybuf, query, query_len); |
| 430 | *end = '\0'; |
| 431 | start = strstr(querybuf, "remove_url="); |
| 432 | if (start && (start == querybuf || *(start - 1) == '&')) { |
| 433 | start += 11; |
| 434 | if ((end = strstr(start, "&")) != nullptr) { |
| 435 | *end = '\0'; |
| 436 | } |
| 437 | del_url_len = unescapifyStr(start); |
no test coverage detected