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 "nexthop_test_stubs.h"
31 
32 #include "HttpTransact.h"
33 
34 void
br(HttpRequestData * h,const char * os_hostname,sockaddr const * dest_ip)35 br(HttpRequestData *h, const char *os_hostname, sockaddr const *dest_ip)
36 {
37   HdrHeap *heap = new_HdrHeap(HdrHeap::DEFAULT_SIZE + 64);
38   h->hdr        = new HTTPHdr();
39   h->hdr->create(HTTP_TYPE_REQUEST, heap);
40   h->hostname_str = ats_strdup(os_hostname);
41   h->xact_start   = time(nullptr);
42   ink_zero(h->src_ip);
43   ink_zero(h->dest_ip);
44   ats_ip_copy(&h->dest_ip.sa, dest_ip);
45   h->incoming_port = 80;
46   h->api_info      = new HttpApiInfo();
47 }
48 
49 void
br_reinit(HttpRequestData * h)50 br_reinit(HttpRequestData *h)
51 {
52   if (h->hdr) {
53     ats_free(h->hdr);
54     ats_free(h->hostname_str);
55     if (h->hdr) {
56       delete h->hdr;
57     }
58     if (h->api_info) {
59       delete h->api_info;
60     }
61   }
62 }
63 
64 void
PrintToStdErr(const char * fmt,...)65 PrintToStdErr(const char *fmt, ...)
66 {
67   va_list args;
68   va_start(args, fmt);
69   vfprintf(stderr, fmt, args);
70   va_end(args);
71 }
72 
73 char *
get_string()74 HttpRequestData::get_string()
75 {
76   return nullptr;
77 }
78 const char *
get_host()79 HttpRequestData::get_host()
80 {
81   return nullptr;
82 }
83 sockaddr const *
get_ip()84 HttpRequestData::get_ip()
85 {
86   return nullptr;
87 }
88 
89 sockaddr const *
get_client_ip()90 HttpRequestData::get_client_ip()
91 {
92   return nullptr;
93 }
94 
95 #include "InkAPIInternal.h"
96 void
invoke(char const * p)97 ConfigUpdateCbTable::invoke(char const *p)
98 {
99 }
100 
101 #include "I_Machine.h"
102 
Machine(char const * hostname,sockaddr const * addr)103 Machine::Machine(char const *hostname, sockaddr const *addr) {}
~Machine()104 Machine::~Machine() {}
105 Machine *
instance()106 Machine::instance()
107 {
108   return new Machine(nullptr, nullptr);
109 }
110 bool
is_self(const char * name)111 Machine::is_self(const char *name)
112 {
113   return false;
114 }
115 
116 #include "HostStatus.h"
117 
HostStatRec()118 HostStatRec::HostStatRec(){};
HostStatus()119 HostStatus::HostStatus() {}
~HostStatus()120 HostStatus::~HostStatus(){};
121 HostStatRec *
getHostStatus(const char * name)122 HostStatus::getHostStatus(const char *name)
123 {
124   // for unit tests only, always return a record with HOST_STATUS_UP
125   static HostStatRec rec;
126   rec.status = HostStatus_t::HOST_STATUS_UP;
127   return &rec;
128 }
129 void
setHostStatus(char const * host,HostStatus_t status,unsigned int,unsigned int)130 HostStatus::setHostStatus(char const *host, HostStatus_t status, unsigned int, unsigned int)
131 {
132   NH_Debug("next_hop", "setting host status for '%s' to %s", host, HostStatusNames[status]);
133 }
134 
135 #include "I_UDPConnection.h"
136 
137 void
Release()138 UDPConnection::Release()
139 {
140 }
141 
142 #include "P_UDPPacket.h"
143 inkcoreapi ClassAllocator<UDPPacketInternal> udpPacketAllocator("udpPacketAllocator");
144 // for UDPPacketInternal::free()
145