MCPcopy Create free account
hub / github.com/apache/trafficserver / intercept_hook

Function intercept_hook

plugins/slice/intercept.cc:26–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24#include "slice.h"
25
26int
27intercept_hook(TSCont contp, TSEvent event, void *edata)
28{
29 Data *const data = static_cast<Data *>(TSContDataGet(contp));
30
31 if (nullptr == data) {
32 ERROR_LOG("intercept_hook called without data");
33 TSContDestroy(contp);
34 return TS_EVENT_ERROR;
35 }
36
37 // After the initial TS_EVENT_NET_ACCEPT
38 // any "events" will be handled by the vio read or write channel handler
39 switch (event) {
40 case TS_EVENT_NET_ACCEPT: {
41 // set up reader from client
42 TSVConn const downvc = static_cast<TSVConn>(edata);
43 data->m_dnstream.setupConnection(downvc);
44 data->m_dnstream.setupVioRead(contp, INT64_MAX);
45 } break;
46
47 case TS_EVENT_NET_ACCEPT_FAILED:
48 case TS_EVENT_VCONN_INACTIVITY_TIMEOUT:
49 case TS_EVENT_VCONN_ACTIVE_TIMEOUT:
50 case TS_EVENT_ERROR: {
51 abort(contp, data);
52 } break;
53
54 default: {
55 // data from client -- only the initial header
56 if (data->m_dnstream.m_read.isOpen() && edata == data->m_dnstream.m_read.m_vio) {
57 if (handle_client_req(contp, event, data)) {
58 // DEBUG_LOG("shutting down read from client pipe");
59 TSVConnShutdown(data->m_dnstream.m_vc, 1, 0);
60 }
61 }
62 // server wants more data from us, should never happen
63 // every time TSHttpConnect is called this resets
64 else if (data->m_upstream.m_write.isOpen() && edata == data->m_upstream.m_write.m_vio) {
65 // DEBUG_LOG("shutting down send to server pipe");
66 TSVConnShutdown(data->m_upstream.m_vc, 0, 1);
67 }
68 // server has data for us
69 else if (data->m_upstream.m_read.isOpen() && edata == data->m_upstream.m_read.m_vio) {
70 handle_server_resp(contp, event, data);
71 }
72 // client wants more data from us, only body content
73 else if (data->m_dnstream.m_write.isOpen() && edata == data->m_dnstream.m_write.m_vio) {
74 handle_client_resp(contp, event, data);
75 } else {
76 ERROR_LOG("Unhandled event: %d", event);
77 }
78 } break;
79 }
80
81 return TS_EVENT_CONTINUE;
82}

Callers

nothing calls this directly

Calls 10

TSContDataGetFunction · 0.85
TSContDestroyFunction · 0.85
abortFunction · 0.85
handle_client_reqFunction · 0.85
TSVConnShutdownFunction · 0.85
handle_server_respFunction · 0.85
handle_client_respFunction · 0.85
setupConnectionMethod · 0.80
setupVioReadMethod · 0.80
isOpenMethod · 0.45

Tested by

no test coverage detected