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

Function TSPluginInit

tests/tools/plugins/test_hooks.cc:284–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

282} // end anonymous namespace
283
284void
285TSPluginInit(int /* argc ATS_UNUSED */, const char ** /* argv ATS_UNUSED */)
286{
287 TSPluginRegistrationInfo info;
288
289 info.plugin_name = PIName;
290 info.vendor_name = "Apache Software Foundation";
291 info.support_email = "dev@trafficserver.apache.org";
292
293 if (TSPluginRegister(&info) != TS_SUCCESS) {
294 TSError(PINAME ": Plugin registration failed");
295
296 return;
297 }
298
299 const char *fileSpec = std::getenv("OUTPUT_FILE");
300
301 if (nullptr == fileSpec) {
302 TSError(PINAME ": Environment variable OUTPUT_FILE not found.");
303
304 return;
305 }
306
307 // Disable output buffering for logFile, so that explicit flushing is not necessary.
308 logFile.rdbuf()->pubsetbuf(nullptr, 0);
309
310 logFile.open(fileSpec, std::ios::out);
311 if (!logFile.is_open()) {
312 TSError(PINAME ": could not open log file \"%s\"", fileSpec);
313
314 return;
315 }
316
317 // Mutex to protect the logFile object.
318 //
319 TSMutex mtx = TSMutexCreate();
320
321 gCont = TSContCreate(globalContFunc, mtx);
322
323 // Setup the global hook
324 TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, gCont);
325 TSHttpHookAdd(TS_HTTP_SSN_START_HOOK, gCont);
326 TSHttpHookAdd(TS_HTTP_SSN_CLOSE_HOOK, gCont);
327 TSHttpHookAdd(TS_HTTP_TXN_START_HOOK, gCont);
328 TSHttpHookAdd(TS_HTTP_TXN_CLOSE_HOOK, gCont);
329 TSHttpHookAdd(TS_SSL_CERT_HOOK, gCont);
330 TSHttpHookAdd(TS_SSL_SERVERNAME_HOOK, gCont);
331 // NOTE: as of January 2019 these two hooks are only triggered for TLS connections. It seems that, at trafficserver
332 // startup, spurious data on the TLS TCP port may cause trafficserver to attempt (and fail) to create a TLS
333 // connection. If this happens, it will result in TS_VCONN_START_HOOK being triggered, and then TS_VCONN_CLOSE_HOOK
334 // will be triggered when the connection closes due to failure.
335 //
336 TSHttpHookAdd(TS_VCONN_START_HOOK, gCont);
337 TSHttpHookAdd(TS_VCONN_CLOSE_HOOK, gCont);
338
339 // TSHttpHookAdd(TS_SSL_SESSION_HOOK, gCont); -- Event is TS_EVENT_SSL_SESSION_NEW -- Event data is TSHttpSsn
340 // TSHttpHookAdd(TS_SSL_SERVER_VERIFY_HOOK, gCont);
341 // TSHttpHookAdd(TS_SSL_VERIFY_CLIENT_HOOK, gCont);

Callers

nothing calls this directly

Calls 7

TSPluginRegisterFunction · 0.85
TSMutexCreateFunction · 0.85
TSContCreateFunction · 0.85
TSHttpHookAddFunction · 0.85
TSErrorFunction · 0.50
openMethod · 0.45
is_openMethod · 0.45

Tested by

no test coverage detected