• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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=d0cfc5e4c052a2d1fe43d1c0ae264642db03c04c$
13 //
14 
15 #include "libcef_dll/cpptoc/server_cpptoc.h"
16 #include "libcef_dll/cpptoc/task_runner_cpptoc.h"
17 #include "libcef_dll/ctocpp/server_handler_ctocpp.h"
18 #include "libcef_dll/shutdown_checker.h"
19 #include "libcef_dll/transfer_util.h"
20 
21 // GLOBAL FUNCTIONS - Body may be edited by hand.
22 
cef_server_create(const cef_string_t * address,uint16 port,int backlog,struct _cef_server_handler_t * handler)23 CEF_EXPORT void cef_server_create(const cef_string_t* address,
24                                   uint16 port,
25                                   int backlog,
26                                   struct _cef_server_handler_t* handler) {
27   shutdown_checker::AssertNotShutdown();
28 
29   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
30 
31   // Verify param: address; type: string_byref_const
32   DCHECK(address);
33   if (!address)
34     return;
35   // Verify param: handler; type: refptr_diff
36   DCHECK(handler);
37   if (!handler)
38     return;
39 
40   // Execute
41   CefServer::CreateServer(CefString(address), port, backlog,
42                           CefServerHandlerCToCpp::Wrap(handler));
43 }
44 
45 namespace {
46 
47 // MEMBER FUNCTIONS - Body may be edited by hand.
48 
49 struct _cef_task_runner_t* CEF_CALLBACK
server_get_task_runner(struct _cef_server_t * self)50 server_get_task_runner(struct _cef_server_t* self) {
51   shutdown_checker::AssertNotShutdown();
52 
53   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
54 
55   DCHECK(self);
56   if (!self)
57     return NULL;
58 
59   // Execute
60   CefRefPtr<CefTaskRunner> _retval =
61       CefServerCppToC::Get(self)->GetTaskRunner();
62 
63   // Return type: refptr_same
64   return CefTaskRunnerCppToC::Wrap(_retval);
65 }
66 
server_shutdown(struct _cef_server_t * self)67 void CEF_CALLBACK server_shutdown(struct _cef_server_t* self) {
68   shutdown_checker::AssertNotShutdown();
69 
70   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
71 
72   DCHECK(self);
73   if (!self)
74     return;
75 
76   // Execute
77   CefServerCppToC::Get(self)->Shutdown();
78 }
79 
server_is_running(struct _cef_server_t * self)80 int CEF_CALLBACK server_is_running(struct _cef_server_t* self) {
81   shutdown_checker::AssertNotShutdown();
82 
83   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
84 
85   DCHECK(self);
86   if (!self)
87     return 0;
88 
89   // Execute
90   bool _retval = CefServerCppToC::Get(self)->IsRunning();
91 
92   // Return type: bool
93   return _retval;
94 }
95 
96 cef_string_userfree_t CEF_CALLBACK
server_get_address(struct _cef_server_t * self)97 server_get_address(struct _cef_server_t* self) {
98   shutdown_checker::AssertNotShutdown();
99 
100   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
101 
102   DCHECK(self);
103   if (!self)
104     return NULL;
105 
106   // Execute
107   CefString _retval = CefServerCppToC::Get(self)->GetAddress();
108 
109   // Return type: string
110   return _retval.DetachToUserFree();
111 }
112 
server_has_connection(struct _cef_server_t * self)113 int CEF_CALLBACK server_has_connection(struct _cef_server_t* self) {
114   shutdown_checker::AssertNotShutdown();
115 
116   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
117 
118   DCHECK(self);
119   if (!self)
120     return 0;
121 
122   // Execute
123   bool _retval = CefServerCppToC::Get(self)->HasConnection();
124 
125   // Return type: bool
126   return _retval;
127 }
128 
server_is_valid_connection(struct _cef_server_t * self,int connection_id)129 int CEF_CALLBACK server_is_valid_connection(struct _cef_server_t* self,
130                                             int connection_id) {
131   shutdown_checker::AssertNotShutdown();
132 
133   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
134 
135   DCHECK(self);
136   if (!self)
137     return 0;
138 
139   // Execute
140   bool _retval = CefServerCppToC::Get(self)->IsValidConnection(connection_id);
141 
142   // Return type: bool
143   return _retval;
144 }
145 
server_send_http200response(struct _cef_server_t * self,int connection_id,const cef_string_t * content_type,const void * data,size_t data_size)146 void CEF_CALLBACK server_send_http200response(struct _cef_server_t* self,
147                                               int connection_id,
148                                               const cef_string_t* content_type,
149                                               const void* data,
150                                               size_t data_size) {
151   shutdown_checker::AssertNotShutdown();
152 
153   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
154 
155   DCHECK(self);
156   if (!self)
157     return;
158   // Verify param: content_type; type: string_byref_const
159   DCHECK(content_type);
160   if (!content_type)
161     return;
162   // Verify param: data; type: simple_byaddr
163   DCHECK(data);
164   if (!data)
165     return;
166 
167   // Execute
168   CefServerCppToC::Get(self)->SendHttp200Response(
169       connection_id, CefString(content_type), data, data_size);
170 }
171 
server_send_http404response(struct _cef_server_t * self,int connection_id)172 void CEF_CALLBACK server_send_http404response(struct _cef_server_t* self,
173                                               int connection_id) {
174   shutdown_checker::AssertNotShutdown();
175 
176   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
177 
178   DCHECK(self);
179   if (!self)
180     return;
181 
182   // Execute
183   CefServerCppToC::Get(self)->SendHttp404Response(connection_id);
184 }
185 
186 void CEF_CALLBACK
server_send_http500response(struct _cef_server_t * self,int connection_id,const cef_string_t * error_message)187 server_send_http500response(struct _cef_server_t* self,
188                             int connection_id,
189                             const cef_string_t* error_message) {
190   shutdown_checker::AssertNotShutdown();
191 
192   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
193 
194   DCHECK(self);
195   if (!self)
196     return;
197   // Verify param: error_message; type: string_byref_const
198   DCHECK(error_message);
199   if (!error_message)
200     return;
201 
202   // Execute
203   CefServerCppToC::Get(self)->SendHttp500Response(connection_id,
204                                                   CefString(error_message));
205 }
206 
207 void CEF_CALLBACK
server_send_http_response(struct _cef_server_t * self,int connection_id,int response_code,const cef_string_t * content_type,int64 content_length,cef_string_multimap_t extra_headers)208 server_send_http_response(struct _cef_server_t* self,
209                           int connection_id,
210                           int response_code,
211                           const cef_string_t* content_type,
212                           int64 content_length,
213                           cef_string_multimap_t extra_headers) {
214   shutdown_checker::AssertNotShutdown();
215 
216   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
217 
218   DCHECK(self);
219   if (!self)
220     return;
221   // Verify param: content_type; type: string_byref_const
222   DCHECK(content_type);
223   if (!content_type)
224     return;
225   // Unverified params: extra_headers
226 
227   // Translate param: extra_headers; type: string_map_multi_byref_const
228   std::multimap<CefString, CefString> extra_headersMultimap;
229   transfer_string_multimap_contents(extra_headers, extra_headersMultimap);
230 
231   // Execute
232   CefServerCppToC::Get(self)->SendHttpResponse(
233       connection_id, response_code, CefString(content_type), content_length,
234       extra_headersMultimap);
235 }
236 
server_send_raw_data(struct _cef_server_t * self,int connection_id,const void * data,size_t data_size)237 void CEF_CALLBACK server_send_raw_data(struct _cef_server_t* self,
238                                        int connection_id,
239                                        const void* data,
240                                        size_t data_size) {
241   shutdown_checker::AssertNotShutdown();
242 
243   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
244 
245   DCHECK(self);
246   if (!self)
247     return;
248   // Verify param: data; type: simple_byaddr
249   DCHECK(data);
250   if (!data)
251     return;
252 
253   // Execute
254   CefServerCppToC::Get(self)->SendRawData(connection_id, data, data_size);
255 }
256 
server_close_connection(struct _cef_server_t * self,int connection_id)257 void CEF_CALLBACK server_close_connection(struct _cef_server_t* self,
258                                           int connection_id) {
259   shutdown_checker::AssertNotShutdown();
260 
261   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
262 
263   DCHECK(self);
264   if (!self)
265     return;
266 
267   // Execute
268   CefServerCppToC::Get(self)->CloseConnection(connection_id);
269 }
270 
server_send_web_socket_message(struct _cef_server_t * self,int connection_id,const void * data,size_t data_size)271 void CEF_CALLBACK server_send_web_socket_message(struct _cef_server_t* self,
272                                                  int connection_id,
273                                                  const void* data,
274                                                  size_t data_size) {
275   shutdown_checker::AssertNotShutdown();
276 
277   // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
278 
279   DCHECK(self);
280   if (!self)
281     return;
282   // Verify param: data; type: simple_byaddr
283   DCHECK(data);
284   if (!data)
285     return;
286 
287   // Execute
288   CefServerCppToC::Get(self)->SendWebSocketMessage(connection_id, data,
289                                                    data_size);
290 }
291 
292 }  // namespace
293 
294 // CONSTRUCTOR - Do not edit by hand.
295 
CefServerCppToC()296 CefServerCppToC::CefServerCppToC() {
297   GetStruct()->get_task_runner = server_get_task_runner;
298   GetStruct()->shutdown = server_shutdown;
299   GetStruct()->is_running = server_is_running;
300   GetStruct()->get_address = server_get_address;
301   GetStruct()->has_connection = server_has_connection;
302   GetStruct()->is_valid_connection = server_is_valid_connection;
303   GetStruct()->send_http200response = server_send_http200response;
304   GetStruct()->send_http404response = server_send_http404response;
305   GetStruct()->send_http500response = server_send_http500response;
306   GetStruct()->send_http_response = server_send_http_response;
307   GetStruct()->send_raw_data = server_send_raw_data;
308   GetStruct()->close_connection = server_close_connection;
309   GetStruct()->send_web_socket_message = server_send_web_socket_message;
310 }
311 
312 // DESTRUCTOR - Do not edit by hand.
313 
~CefServerCppToC()314 CefServerCppToC::~CefServerCppToC() {
315   shutdown_checker::AssertNotShutdown();
316 }
317 
318 template <>
319 CefRefPtr<CefServer>
UnwrapDerived(CefWrapperType type,cef_server_t * s)320 CefCppToCRefCounted<CefServerCppToC, CefServer, cef_server_t>::UnwrapDerived(
321     CefWrapperType type,
322     cef_server_t* s) {
323   NOTREACHED() << "Unexpected class type: " << type;
324   return nullptr;
325 }
326 
327 template <>
328 CefWrapperType CefCppToCRefCounted<CefServerCppToC, CefServer, cef_server_t>::
329     kWrapperType = WT_SERVER;
330