- Notifications
You must be signed in to change notification settings - Fork 826
/
Copy pathresources.cc
148 lines (130 loc) · 4.59 KB
/
resources.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
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.
*/
//////////////////////////////////////////////////////////////////////////////////////////////
// resources.cc: Implementation of the resources class.
//
//
#include"ts/ts.h"
#include"resources.h"
#include"lulu.h"
// Collect all resources
void
Resources::gather(const ResourceIDs ids, TSHttpHookID hook)
{
Dbg(pi_dbg_ctl, "Building resources, hook=%s", TSHttpHookNameLookup(hook));
// Clear the capture groups just in case
ovector_count = 0;
ovector_ptr = nullptr;
// If we need the client request headers, make sure it's also available in the client vars.
if (ids & RSRC_CLIENT_REQUEST_HEADERS) {
Dbg(pi_dbg_ctl, "\tAdding TXN client request header buffers");
if (TSHttpTxnClientReqGet(txnp, &client_bufp, &client_hdr_loc) != TS_SUCCESS) {
Dbg(pi_dbg_ctl, "could not gather bufp/hdr_loc for request");
return;
}
}
switch (hook) {
case TS_HTTP_READ_RESPONSE_HDR_HOOK:
// Read response headers from server
if (ids & RSRC_SERVER_RESPONSE_HEADERS) {
Dbg(pi_dbg_ctl, "\tAdding TXN server response header buffers");
if (TSHttpTxnServerRespGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) {
Dbg(pi_dbg_ctl, "could not gather bufp/hdr_loc for response");
return;
}
}
if (ids & RSRC_RESPONSE_STATUS) {
Dbg(pi_dbg_ctl, "\tAdding TXN server response status resource");
resp_status = TSHttpHdrStatusGet(bufp, hdr_loc);
}
break;
case TS_HTTP_SEND_REQUEST_HDR_HOOK:
Dbg(pi_dbg_ctl, "Processing TS_HTTP_SEND_REQUEST_HDR_HOOK");
// Read request headers to server
if (ids & RSRC_SERVER_REQUEST_HEADERS) {
Dbg(pi_dbg_ctl, "\tAdding TXN server request header buffers");
if (!TSHttpTxnServerReqGet(txnp, &bufp, &hdr_loc)) {
Dbg(pi_dbg_ctl, "could not gather bufp/hdr_loc for request");
return;
}
}
break;
case TS_HTTP_READ_REQUEST_HDR_HOOK:
case TS_HTTP_PRE_REMAP_HOOK:
// Read request from client
if (ids & RSRC_CLIENT_REQUEST_HEADERS) {
bufp = client_bufp;
hdr_loc = client_hdr_loc;
}
break;
case TS_HTTP_SEND_RESPONSE_HDR_HOOK:
// Send response headers to client
if (ids & RSRC_CLIENT_RESPONSE_HEADERS) {
Dbg(pi_dbg_ctl, "\tAdding TXN client response header buffers");
if (TSHttpTxnClientRespGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) {
Dbg(pi_dbg_ctl, "could not gather bufp/hdr_loc for request");
return;
}
if (ids & RSRC_RESPONSE_STATUS) {
Dbg(pi_dbg_ctl, "\tAdding TXN client response status resource");
resp_status = TSHttpHdrStatusGet(bufp, hdr_loc);
}
}
break;
case TS_REMAP_PSEUDO_HOOK:
// Pseudo-hook for a remap instance
if (client_bufp && client_hdr_loc) {
Dbg(pi_dbg_ctl, "\tAdding TXN client request header buffers for remap instance");
bufp = client_bufp;
hdr_loc = client_hdr_loc;
}
break;
case TS_HTTP_TXN_START_HOOK:
// Get TCP Info at transaction start
if (client_bufp && client_hdr_loc) {
Dbg(pi_dbg_ctl, "\tAdding TXN client request header buffers for TXN Start instance");
bufp = client_bufp;
hdr_loc = client_hdr_loc;
}
break;
case TS_HTTP_TXN_CLOSE_HOOK:
// Get TCP Info at transaction close
Dbg(pi_dbg_ctl, "\tAdding TXN close buffers");
if (TSHttpTxnClientRespGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) {
Dbg(pi_dbg_ctl, "could not gather bufp/hdr_loc for request");
return;
}
break;
default:
break;
}
_ready = true;
}
void
Resources::destroy()
{
if (bufp) {
if (hdr_loc) {
TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
}
}
if (client_bufp && (client_bufp != bufp)) {
if (client_hdr_loc && (client_hdr_loc != hdr_loc)) { // TODO: Is this check really necessary?
TSHandleMLocRelease(client_bufp, TS_NULL_MLOC, client_hdr_loc);
}
}
_ready = false;
}