1 /** @file
2
3 nexthop unit test stubs for unit testing nexthop strategies.
4
5 @section license License
6
7 Licensed to the Apache Software Foundation (ASF) under one
8 or more contributor license agreements. See the NOTICE file
9 distributed with this work for additional information
10 regarding copyright ownership. The ASF licenses this file
11 to you under the Apache License, Version 2.0 (the
12 "License"); you may not use this file except in compliance
13 with the License. You may obtain a copy of the License at
14
15 http://www.apache.org/licenses/LICENSE-2.0
16
17 Unless required by applicable law or agreed to in writing, software
18 distributed under the License is distributed on an "AS IS" BASIS,
19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 See the License for the specific language governing permissions and
21 limitations under the License.
22
23 @section details Details
24
25 Implements code necessary for Reverse Proxy which mostly consists of
26 general purpose hostname substitution in URLs.
27
28 */
29
30 #include "HttpSM.h"
31 #include "nexthop_test_stubs.h"
32
HttpSM()33 HttpSM::HttpSM() : Continuation(nullptr), vc_table(this) {}
34 void
cleanup()35 HttpSM::cleanup()
36 {
37 }
38 void
destroy()39 HttpSM::destroy()
40 {
41 }
42 void
handle_api_return()43 HttpSM::handle_api_return()
44 {
45 }
46 void
set_next_state()47 HttpSM::set_next_state()
48 {
49 }
50
HttpVCTable(HttpSM * smp)51 HttpVCTable::HttpVCTable(HttpSM *smp)
52 {
53 sm = smp;
54 }
HttpCacheAction()55 HttpCacheAction::HttpCacheAction() {}
56 void
cancel(Continuation * c)57 HttpCacheAction::cancel(Continuation *c)
58 {
59 }
~PostDataBuffers()60 PostDataBuffers::~PostDataBuffers() {}
61 void
clear()62 APIHooks::clear()
63 {
64 }
65
HttpTunnel()66 HttpTunnel::HttpTunnel() {}
HttpCacheSM()67 HttpCacheSM::HttpCacheSM() {}
HttpHookState()68 HttpHookState::HttpHookState() {}
HttpTunnelConsumer()69 HttpTunnelConsumer::HttpTunnelConsumer() {}
HttpTunnelProducer()70 HttpTunnelProducer::HttpTunnelProducer() {}
ChunkedHandler()71 ChunkedHandler::ChunkedHandler() {}
72
73 alignas(OverridableHttpConfigParams) char _my_txn_conf[sizeof(OverridableHttpConfigParams)];
74
75 // this is done to cleanup and avoid memory leaks in the unit tests.
76 static HdrHeap *myHeap = nullptr;
77 void
br_destroy(HttpSM & sm)78 br_destroy(HttpSM &sm)
79 {
80 HttpRequestData *h = &sm.t_state.request_data;
81 if (myHeap != nullptr) {
82 myHeap->destroy();
83 myHeap = nullptr;
84 }
85 delete h->hdr;
86 delete h->api_info;
87 ats_free(h->hostname_str);
88 }
89
90 void
build_request(int64_t sm_id,HttpSM * sm,sockaddr_in * ip,const char * os_hostname,sockaddr const * dest_ip)91 build_request(int64_t sm_id, HttpSM *sm, sockaddr_in *ip, const char *os_hostname, sockaddr const *dest_ip)
92 {
93 sm->sm_id = sm_id;
94
95 if (myHeap == nullptr) {
96 myHeap = new_HdrHeap(HdrHeap::DEFAULT_SIZE + 64);
97 }
98 if (sm->t_state.request_data.hdr != nullptr) {
99 delete sm->t_state.request_data.hdr;
100 }
101 sm->t_state.request_data.hdr = new HTTPHdr();
102 sm->t_state.request_data.hdr->create(HTTP_TYPE_REQUEST, myHeap);
103 if (sm->t_state.request_data.hostname_str != nullptr) {
104 ats_free(sm->t_state.request_data.hostname_str);
105 }
106 sm->t_state.request_data.hostname_str = ats_strdup(os_hostname);
107 sm->t_state.request_data.xact_start = time(nullptr);
108 ink_zero(sm->t_state.request_data.src_ip);
109 ink_zero(sm->t_state.request_data.dest_ip);
110 ats_ip_copy(&sm->t_state.request_data.dest_ip.sa, dest_ip);
111 sm->t_state.request_data.incoming_port = 80;
112 if (sm->t_state.request_data.api_info != nullptr) {
113 delete sm->t_state.request_data.api_info;
114 }
115 sm->t_state.request_data.api_info = new HttpApiInfo();
116 if (ip != nullptr) {
117 memcpy(&sm->t_state.request_data.src_ip.sa, ip, sizeof(sm->t_state.request_data.src_ip.sa));
118 }
119 sm->t_state.request_data.xact_start = time(0);
120
121 memset(_my_txn_conf, 0, sizeof(_my_txn_conf));
122 OverridableHttpConfigParams *oride = reinterpret_cast<OverridableHttpConfigParams *>(_my_txn_conf);
123 oride->parent_retry_time = 1;
124 oride->parent_fail_threshold = 1;
125 sm->t_state.txn_conf = reinterpret_cast<OverridableHttpConfigParams *>(_my_txn_conf);
126 }
127
128 void
PrintToStdErr(const char * fmt,...)129 PrintToStdErr(const char *fmt, ...)
130 {
131 va_list args;
132 va_start(args, fmt);
133 vfprintf(stderr, fmt, args);
134 va_end(args);
135 }
136
137 char *
get_string()138 HttpRequestData::get_string()
139 {
140 return nullptr;
141 }
142 const char *
get_host()143 HttpRequestData::get_host()
144 {
145 return nullptr;
146 }
147 sockaddr const *
get_ip()148 HttpRequestData::get_ip()
149 {
150 return nullptr;
151 }
152
153 sockaddr const *
get_client_ip()154 HttpRequestData::get_client_ip()
155 {
156 return &src_ip.sa;
157 }
158
159 #include "InkAPIInternal.h"
160 void
invoke(char const * p)161 ConfigUpdateCbTable::invoke(char const *p)
162 {
163 }
164
165 #include "I_Machine.h"
166
167 static Machine *my_machine = nullptr;
168
Machine(char const * hostname,sockaddr const * addr)169 Machine::Machine(char const *hostname, sockaddr const *addr) {}
~Machine()170 Machine::~Machine()
171 {
172 delete my_machine;
173 }
174 Machine *
instance()175 Machine::instance()
176 {
177 if (my_machine == nullptr) {
178 my_machine = new Machine(nullptr, nullptr);
179 }
180 return my_machine;
181 }
182 bool
is_self(const char * name)183 Machine::is_self(const char *name)
184 {
185 return false;
186 }
187
188 #include "HostStatus.h"
189
HostStatRec()190 HostStatRec::HostStatRec(){};
HostStatus()191 HostStatus::HostStatus() {}
192
~HostStatus()193 HostStatus::~HostStatus()
194 {
195 for (auto i = this->hosts_statuses.begin(); i != this->hosts_statuses.end(); ++i) {
196 delete i->second;
197 }
198 }
199
200 HostStatRec *
getHostStatus(const char * name)201 HostStatus::getHostStatus(const char *name)
202 {
203 if (this->hosts_statuses[name] == nullptr) {
204 // for unit tests only, always return a record with HOST_STATUS_UP, if it wasn't set with setHostStatus
205 static HostStatRec rec;
206 rec.status = HostStatus_t::HOST_STATUS_UP;
207 return &rec;
208 }
209 return this->hosts_statuses[name];
210 }
211
212 void
setHostStatus(char const * host,HostStatus_t status,unsigned int down_time,unsigned int reason)213 HostStatus::setHostStatus(char const *host, HostStatus_t status, unsigned int down_time, unsigned int reason)
214 {
215 if (this->hosts_statuses[host] == nullptr) {
216 this->hosts_statuses[host] = new (HostStatRec);
217 }
218 this->hosts_statuses[host]->status = status;
219 this->hosts_statuses[host]->reasons = reason;
220 this->hosts_statuses[host]->local_down_time = down_time;
221 NH_Debug("next_hop", "setting host status for '%s' to %s", host, HostStatusNames[status]);
222 }
223
224 #include "I_UDPConnection.h"
225
226 void
Release()227 UDPConnection::Release()
228 {
229 }
230
231 #include "P_UDPPacket.h"
232 inkcoreapi ClassAllocator<UDPPacketInternal> udpPacketAllocator("udpPacketAllocator");
233 // for UDPPacketInternal::free()
234