1 // Copyright (c) 2022 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4 //
5 // ---------------------------------------------------------------------------
6 //
7 // This file was generated by the CEF translator tool. If making changes by
8 // hand only do so within the body of existing method and function
9 // implementations. See the translator.README.txt file in the tools directory
10 // for more information.
11 //
12 // $hash=d8cfb6cafc2a9aa0cffe4a998071e8a96b04740b$
13 //
14
15 #include "libcef_dll/ctocpp/server_ctocpp.h"
16 #include "libcef_dll/cpptoc/server_handler_cpptoc.h"
17 #include "libcef_dll/ctocpp/task_runner_ctocpp.h"
18 #include "libcef_dll/shutdown_checker.h"
19 #include "libcef_dll/transfer_util.h"
20
21 // STATIC METHODS - Body may be edited by hand.
22
23 NO_SANITIZE("cfi-icall")
CreateServer(const CefString & address,uint16 port,int backlog,CefRefPtr<CefServerHandler> handler)24 void CefServer::CreateServer(const CefString& address,
25 uint16 port,
26 int backlog,
27 CefRefPtr<CefServerHandler> handler) {
28 shutdown_checker::AssertNotShutdown();
29
30 // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
31
32 // Verify param: address; type: string_byref_const
33 DCHECK(!address.empty());
34 if (address.empty())
35 return;
36 // Verify param: handler; type: refptr_diff
37 DCHECK(handler.get());
38 if (!handler.get())
39 return;
40
41 // Execute
42 cef_server_create(address.GetStruct(), port, backlog,
43 CefServerHandlerCppToC::Wrap(handler));
44 }
45
46 // VIRTUAL METHODS - Body may be edited by hand.
47
48 NO_SANITIZE("cfi-icall")
GetTaskRunner()49 CefRefPtr<CefTaskRunner> CefServerCToCpp::GetTaskRunner() {
50 shutdown_checker::AssertNotShutdown();
51
52 cef_server_t* _struct = GetStruct();
53 if (CEF_MEMBER_MISSING(_struct, get_task_runner))
54 return nullptr;
55
56 // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
57
58 // Execute
59 cef_task_runner_t* _retval = _struct->get_task_runner(_struct);
60
61 // Return type: refptr_same
62 return CefTaskRunnerCToCpp::Wrap(_retval);
63 }
64
Shutdown()65 NO_SANITIZE("cfi-icall") void CefServerCToCpp::Shutdown() {
66 shutdown_checker::AssertNotShutdown();
67
68 cef_server_t* _struct = GetStruct();
69 if (CEF_MEMBER_MISSING(_struct, shutdown))
70 return;
71
72 // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
73
74 // Execute
75 _struct->shutdown(_struct);
76 }
77
IsRunning()78 NO_SANITIZE("cfi-icall") bool CefServerCToCpp::IsRunning() {
79 shutdown_checker::AssertNotShutdown();
80
81 cef_server_t* _struct = GetStruct();
82 if (CEF_MEMBER_MISSING(_struct, is_running))
83 return false;
84
85 // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
86
87 // Execute
88 int _retval = _struct->is_running(_struct);
89
90 // Return type: bool
91 return _retval ? true : false;
92 }
93
GetAddress()94 NO_SANITIZE("cfi-icall") CefString CefServerCToCpp::GetAddress() {
95 shutdown_checker::AssertNotShutdown();
96
97 cef_server_t* _struct = GetStruct();
98 if (CEF_MEMBER_MISSING(_struct, get_address))
99 return CefString();
100
101 // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
102
103 // Execute
104 cef_string_userfree_t _retval = _struct->get_address(_struct);
105
106 // Return type: string
107 CefString _retvalStr;
108 _retvalStr.AttachToUserFree(_retval);
109 return _retvalStr;
110 }
111
HasConnection()112 NO_SANITIZE("cfi-icall") bool CefServerCToCpp::HasConnection() {
113 shutdown_checker::AssertNotShutdown();
114
115 cef_server_t* _struct = GetStruct();
116 if (CEF_MEMBER_MISSING(_struct, has_connection))
117 return false;
118
119 // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
120
121 // Execute
122 int _retval = _struct->has_connection(_struct);
123
124 // Return type: bool
125 return _retval ? true : false;
126 }
127
128 NO_SANITIZE("cfi-icall")
IsValidConnection(int connection_id)129 bool CefServerCToCpp::IsValidConnection(int connection_id) {
130 shutdown_checker::AssertNotShutdown();
131
132 cef_server_t* _struct = GetStruct();
133 if (CEF_MEMBER_MISSING(_struct, is_valid_connection))
134 return false;
135
136 // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
137
138 // Execute
139 int _retval = _struct->is_valid_connection(_struct, connection_id);
140
141 // Return type: bool
142 return _retval ? true : false;
143 }
144
145 NO_SANITIZE("cfi-icall")
SendHttp200Response(int connection_id,const CefString & content_type,const void * data,size_t data_size)146 void CefServerCToCpp::SendHttp200Response(int connection_id,
147 const CefString& content_type,
148 const void* data,
149 size_t data_size) {
150 shutdown_checker::AssertNotShutdown();
151
152 cef_server_t* _struct = GetStruct();
153 if (CEF_MEMBER_MISSING(_struct, send_http200response))
154 return;
155
156 // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
157
158 // Verify param: content_type; type: string_byref_const
159 DCHECK(!content_type.empty());
160 if (content_type.empty())
161 return;
162 // Verify param: data; type: simple_byaddr
163 DCHECK(data);
164 if (!data)
165 return;
166
167 // Execute
168 _struct->send_http200response(_struct, connection_id,
169 content_type.GetStruct(), data, data_size);
170 }
171
172 NO_SANITIZE("cfi-icall")
SendHttp404Response(int connection_id)173 void CefServerCToCpp::SendHttp404Response(int connection_id) {
174 shutdown_checker::AssertNotShutdown();
175
176 cef_server_t* _struct = GetStruct();
177 if (CEF_MEMBER_MISSING(_struct, send_http404response))
178 return;
179
180 // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
181
182 // Execute
183 _struct->send_http404response(_struct, connection_id);
184 }
185
186 NO_SANITIZE("cfi-icall")
SendHttp500Response(int connection_id,const CefString & error_message)187 void CefServerCToCpp::SendHttp500Response(int connection_id,
188 const CefString& error_message) {
189 shutdown_checker::AssertNotShutdown();
190
191 cef_server_t* _struct = GetStruct();
192 if (CEF_MEMBER_MISSING(_struct, send_http500response))
193 return;
194
195 // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
196
197 // Verify param: error_message; type: string_byref_const
198 DCHECK(!error_message.empty());
199 if (error_message.empty())
200 return;
201
202 // Execute
203 _struct->send_http500response(_struct, connection_id,
204 error_message.GetStruct());
205 }
206
207 NO_SANITIZE("cfi-icall")
SendHttpResponse(int connection_id,int response_code,const CefString & content_type,int64 content_length,const HeaderMap & extra_headers)208 void CefServerCToCpp::SendHttpResponse(int connection_id,
209 int response_code,
210 const CefString& content_type,
211 int64 content_length,
212 const HeaderMap& extra_headers) {
213 shutdown_checker::AssertNotShutdown();
214
215 cef_server_t* _struct = GetStruct();
216 if (CEF_MEMBER_MISSING(_struct, send_http_response))
217 return;
218
219 // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
220
221 // Verify param: content_type; type: string_byref_const
222 DCHECK(!content_type.empty());
223 if (content_type.empty())
224 return;
225 // Unverified params: extra_headers
226
227 // Translate param: extra_headers; type: string_map_multi_byref_const
228 cef_string_multimap_t extra_headersMultimap = cef_string_multimap_alloc();
229 DCHECK(extra_headersMultimap);
230 if (extra_headersMultimap)
231 transfer_string_multimap_contents(extra_headers, extra_headersMultimap);
232
233 // Execute
234 _struct->send_http_response(_struct, connection_id, response_code,
235 content_type.GetStruct(), content_length,
236 extra_headersMultimap);
237
238 // Restore param:extra_headers; type: string_map_multi_byref_const
239 if (extra_headersMultimap)
240 cef_string_multimap_free(extra_headersMultimap);
241 }
242
243 NO_SANITIZE("cfi-icall")
SendRawData(int connection_id,const void * data,size_t data_size)244 void CefServerCToCpp::SendRawData(int connection_id,
245 const void* data,
246 size_t data_size) {
247 shutdown_checker::AssertNotShutdown();
248
249 cef_server_t* _struct = GetStruct();
250 if (CEF_MEMBER_MISSING(_struct, send_raw_data))
251 return;
252
253 // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
254
255 // Verify param: data; type: simple_byaddr
256 DCHECK(data);
257 if (!data)
258 return;
259
260 // Execute
261 _struct->send_raw_data(_struct, connection_id, data, data_size);
262 }
263
264 NO_SANITIZE("cfi-icall")
CloseConnection(int connection_id)265 void CefServerCToCpp::CloseConnection(int connection_id) {
266 shutdown_checker::AssertNotShutdown();
267
268 cef_server_t* _struct = GetStruct();
269 if (CEF_MEMBER_MISSING(_struct, close_connection))
270 return;
271
272 // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
273
274 // Execute
275 _struct->close_connection(_struct, connection_id);
276 }
277
278 NO_SANITIZE("cfi-icall")
SendWebSocketMessage(int connection_id,const void * data,size_t data_size)279 void CefServerCToCpp::SendWebSocketMessage(int connection_id,
280 const void* data,
281 size_t data_size) {
282 shutdown_checker::AssertNotShutdown();
283
284 cef_server_t* _struct = GetStruct();
285 if (CEF_MEMBER_MISSING(_struct, send_web_socket_message))
286 return;
287
288 // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
289
290 // Verify param: data; type: simple_byaddr
291 DCHECK(data);
292 if (!data)
293 return;
294
295 // Execute
296 _struct->send_web_socket_message(_struct, connection_id, data, data_size);
297 }
298
299 // CONSTRUCTOR - Do not edit by hand.
300
CefServerCToCpp()301 CefServerCToCpp::CefServerCToCpp() {}
302
303 // DESTRUCTOR - Do not edit by hand.
304
~CefServerCToCpp()305 CefServerCToCpp::~CefServerCToCpp() {
306 shutdown_checker::AssertNotShutdown();
307 }
308
309 template <>
310 cef_server_t*
UnwrapDerived(CefWrapperType type,CefServer * c)311 CefCToCppRefCounted<CefServerCToCpp, CefServer, cef_server_t>::UnwrapDerived(
312 CefWrapperType type,
313 CefServer* c) {
314 NOTREACHED() << "Unexpected class type: " << type;
315 return nullptr;
316 }
317
318 template <>
319 CefWrapperType CefCToCppRefCounted<CefServerCToCpp, CefServer, cef_server_t>::
320 kWrapperType = WT_SERVER;
321