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

Function handle_dns

example/plugins/c-api/output_header/output_header.cc:48–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48static void
49handle_dns(TSHttpTxn txnp, TSCont contp ATS_UNUSED)
50{
51 TSMBuffer bufp;
52 TSMLoc hdr_loc;
53
54 TSIOBuffer output_buffer;
55 TSIOBufferReader reader;
56 int total_avail;
57
58 TSIOBufferBlock block;
59 const char *block_start;
60 int64_t block_avail;
61
62 char *output_string;
63 int64_t output_len;
64
65 if (TSHttpTxnClientReqGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) {
66 Dbg(dbg_ctl, "couldn't retrieve client request header");
67 TSError("[%s] Couldn't retrieve client request header", PLUGIN_NAME);
68 goto done;
69 }
70
71 output_buffer = TSIOBufferCreate();
72 reader = TSIOBufferReaderAlloc(output_buffer);
73
74 /* This will print just MIMEFields and not
75 the http request line */
76 Dbg(dbg_ctl, "Printing the hdrs ... ");
77 TSMimeHdrPrint(hdr_loc, output_buffer);
78
79 if (TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc) == TS_ERROR) {
80 Dbg(dbg_ctl, "non-fatal: error releasing MLoc");
81 TSError("[%s] non-fatal: Couldn't release MLoc", PLUGIN_NAME);
82 }
83
84 /* Find out how the big the complete header is by
85 seeing the total bytes in the buffer. We need to
86 look at the buffer rather than the first block to
87 see the size of the entire header */
88 total_avail = TSIOBufferReaderAvail(reader);
89
90 /* Allocate the string with an extra byte for the string
91 terminator */
92 output_string = static_cast<char *>(TSmalloc(total_avail + 1));
93 output_len = 0;
94
95 /* We need to loop over all the buffer blocks to make
96 sure we get the complete header since the header can
97 be in multiple blocks */
98 block = TSIOBufferReaderStart(reader);
99 while (block) {
100 block_start = TSIOBufferBlockReadStart(block, reader, &block_avail);
101
102 /* We'll get a block pointer back even if there is no data
103 left to read so check for this condition and break out of
104 the loop. A block with no data to read means we've exhausted
105 buffer of data since if there was more data on a later

Callers 1

hdr_pluginFunction · 0.70

Calls 15

TSHttpTxnClientReqGetFunction · 0.85
TSIOBufferCreateFunction · 0.85
TSIOBufferReaderAllocFunction · 0.85
TSMimeHdrPrintFunction · 0.85
TSHandleMLocReleaseFunction · 0.85
TSIOBufferReaderAvailFunction · 0.85
TSmallocFunction · 0.85
TSIOBufferReaderFreeFunction · 0.85
TSIOBufferDestroyFunction · 0.85
TSfreeFunction · 0.85
TSHttpTxnReenableFunction · 0.85
TSErrorFunction · 0.50

Tested by

no test coverage detected