GCC Code Coverage Report


Directory: src/gate/
File: src/gate/net/cxx_httpservers.cpp
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 99 118 83.9%
Functions: 31 37 83.8%
Branches: 17 44 38.6%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28 #include "gate/net/httpservers.hpp"
29 #include "gate/exceptions.hpp"
30
31 namespace gate
32 {
33 namespace net
34 {
35
36 2 HttpServer::Config::Config()
37 {
38 2 result_t result = gate_httpserver_config_init(&this->impl);
39
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_ERROR(result);
40 2 }
41
42 2 HttpServer::Config::Config(Config const& src)
43 {
44 2 result_t result = gate_httpserver_config_copy(&this->impl, &src.impl);
45
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_ERROR(result);
46 2 }
47
48 1 HttpServer::Config& HttpServer::Config::operator=(Config const& src)
49 {
50
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (this != &src)
51 {
52
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 Config that(src);
53 1 this->swap(that);
54 }
55 1 return *this;
56 }
57
58 1 void HttpServer::Config::swap(Config& that) noexcept
59 {
60 1 gate_mem_swap_bytes(this->c_impl(), that.c_impl(), sizeof(this->impl));
61 1 }
62
63 1 gate_httpserver_config_t const* HttpServer::Config::c_impl() const noexcept
64 {
65 1 return &this->impl;
66 }
67
68 3 gate_httpserver_config_t* HttpServer::Config::c_impl() noexcept
69 {
70 3 return &this->impl;
71 }
72
73 8 HttpServer::Config::~Config() noexcept
74 {
75 4 gate_httpserver_config_destroy(&this->impl);
76 4 }
77
78 1 String HttpServer::Config::getAddress() const
79 {
80 1 return String::clone(this->impl.address);
81 }
82
83 1 void HttpServer::Config::setAddress(String const& value)
84 {
85 1 String::assign(this->impl.address, value);
86 1 }
87
88 1 uint16_t HttpServer::Config::getPort() const
89 {
90 1 return this->impl.port;
91 }
92
93 1 void HttpServer::Config::setPort(uint16_t value)
94 {
95 1 this->impl.port = value;
96 1 }
97
98 1 bool_t HttpServer::Config::getSecure() const
99 {
100 1 return this->impl.secure;
101 }
102
103 1 void HttpServer::Config::setSecure(bool_t value)
104 {
105 1 this->impl.secure = value;
106 1 }
107
108 1 size_t HttpServer::Config::getMaxConnections() const
109 {
110 1 return this->impl.max_connections;
111 }
112
113 1 void HttpServer::Config::setMaxConnections(size_t value)
114 {
115 1 this->impl.max_connections = value;
116 1 }
117
118
119
120 2 HttpServer::Response::Response(gate_httpserver_response_t* response_stream)
121 2 : Stream((gate_stream_t*)response_stream)
122 {
123 2 }
124
125 HttpServer::Response::Response(Response const& src)
126 : Stream(src)
127 {
128 }
129
130 2 HttpServer::Response::~Response() noexcept
131 {
132 2 }
133
134 24 gate_httpserver_response_t* HttpServer::Response::c_impl() const noexcept
135 {
136 24 return (gate_httpserver_response_t*)Stream::c_impl();
137 }
138
139 2 void HttpServer::Response::setStatus(uint32_t status)
140 {
141 2 result_t result = gate_httpserver_response_set_status(this->c_impl(), status);
142
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
143 2 }
144
145 2 String HttpServer::Response::getHeader(String const& name)
146 {
147 2 gate_string_t value = GATE_STRING_INIT_EMPTY;
148
1/2
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 result_t result = gate_httpserver_response_get_header(this->c_impl(), name.c_impl(), &value);
149
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
2 GATEXX_CHECK_EXCEPTION(result);
150 4 return String::createFrom(value);
151 }
152
153 2 void HttpServer::Response::setHeader(String const& name, String const& value)
154 {
155 2 result_t result = gate_httpserver_response_set_header(this->c_impl(), name.c_impl(), value.c_impl());
156
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
157 2 }
158
159 2 void HttpServer::Response::sendHeaders()
160 {
161 2 result_t result = gate_httpserver_response_send_headers(this->c_impl());
162
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
163 2 }
164
165 4 bool_t HttpServer::Response::areHeadersSent()
166 {
167 4 return gate_httpserver_response_are_headers_sent(this->c_impl());
168 }
169
170
171 HttpServer::Handler::Handler(gate_httpserver_handler_t* strm)
172 : object_impl_t(strm)
173 {
174 if (this->impl_ptr == NULL)
175 {
176 GATEXX_RAISE_ERROR(results::NullPointer);
177 }
178 }
179
180 HttpServer::Handler::Handler(Handler const& src) noexcept
181 : object_impl_t(src)
182 {
183 }
184
185 VoidResult HttpServer::Handler::tryProcess(Request const& request, Response& response) noexcept
186 {
187 result_t result = gate_httpserver_handler_process(this->impl_ptr, &request, response.c_impl());
188 return makeResult(result);
189 }
190
191 void HttpServer::Handler::process(Request const& request, Response& response)
192 {
193 tryProcess(request, response).checkException("HttpServer::Handler::process");
194 }
195
196
197
198 1 HttpServer::HttpServer()
199 {
200 1 result_t result = gate_httpserver_create(&this->impl);
201
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
202 1 }
203 2 HttpServer::~HttpServer() noexcept
204 {
205 1 result_t result = gate_httpserver_destroy(&this->impl);
206
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATE_DEBUG_TRACE_FAILED(result, "gate_httpserver_destroy() failed");
207 1 }
208
209 gate_httpserver_t const* HttpServer::c_impl() const noexcept
210 {
211 return &this->impl;
212 }
213 1 gate_httpserver_t* HttpServer::c_impl() noexcept
214 {
215 1 return &this->impl;
216 }
217
218
219 1 HttpServer::HostId HttpServer::addHost(Config const& config, Callback callback, void* userparam)
220 {
221 HostId id;
222
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 result_t result = gate_httpserver_add_host(&this->impl, config.c_impl(), callback, userparam, &id);
223
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
224 1 return id;
225 }
226
227 1 void HttpServer::removeHost(HostId host)
228 {
229 1 result_t result = gate_httpserver_remove_host(&this->impl, host);
230
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
231 1 }
232
233 1 void HttpServer::removeAllHosts()
234 {
235 1 result_t result = gate_httpserver_remove_all_hosts(&this->impl);
236
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
237 1 }
238
239 1 void HttpServer::start()
240 {
241 1 result_t result = gate_httpserver_start(&this->impl);
242
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
243 1 }
244
245 1 void HttpServer::stop()
246 {
247 1 result_t result = gate_httpserver_stop(&this->impl);
248
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
249 1 }
250
251 } // end of namespace net
252 } // end of namespace gate
253