Lines Matching refs:wsi

31 std::string GetPath(struct lws* wsi) {  in GetPath()  argument
32 auto len = lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI); in GetPath()
34 auto ret = lws_hdr_copy(wsi, path.data(), path.size(), WSI_TOKEN_GET_URI); in GetPath()
36 len = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COLON_PATH); in GetPath()
39 lws_hdr_copy(wsi, path.data(), path.size(), WSI_TOKEN_HTTP_COLON_PATH); in GetPath()
55 bool AddCORSHeaders(struct lws* wsi, unsigned char** buffer_ptr, in AddCORSHeaders() argument
61 wsi, reinterpret_cast<const unsigned char*>(name.c_str()), in AddCORSHeaders()
71 size_t content_len, struct lws* wsi) { in WriteCommonHttpHeaders() argument
77 if (lws_add_http_common_headers(wsi, status, mime_type, content_len, &p, in WriteCommonHttpHeaders()
82 if (!AddCORSHeaders(wsi, &p, end)) { in WriteCommonHttpHeaders()
86 if (lws_finalize_write_http_header(wsi, start, &p, end)) { in WriteCommonHttpHeaders()
246 int WebSocketServer::WebsocketCallback(struct lws* wsi, in WebsocketCallback() argument
249 auto protocol = lws_get_protocol(wsi); in WebsocketCallback()
253 return lws_callback_http_dummy(wsi, reason, user, in, len); in WebsocketCallback()
256 ->ServerCallback(wsi, reason, user, in, len); in WebsocketCallback()
259 int WebSocketServer::DynHttpCallback(struct lws* wsi, in DynHttpCallback() argument
262 auto protocol = lws_get_protocol(wsi); in DynHttpCallback()
268 ->DynServerCallback(wsi, reason, user, in, len); in DynHttpCallback()
271 int WebSocketServer::DynServerCallback(struct lws* wsi, in DynServerCallback() argument
278 auto method = lws_http_get_uri_and_method(wsi, &path_raw, &path_len); in DynServerCallback()
283 auto handler = InstantiateDynHandler(path, wsi); in DynServerCallback()
286 "application/json", 0, wsi)) { in DynServerCallback()
289 return lws_http_transaction_completed(wsi); in DynServerCallback()
291 dyn_handlers_[wsi] = std::move(handler); in DynServerCallback()
294 auto status = dyn_handlers_[wsi]->DoGet(); in DynServerCallback()
297 dyn_handlers_[wsi]->content_len(), wsi)) { in DynServerCallback()
301 lws_callback_on_writable(wsi); in DynServerCallback()
310 if (!WriteCommonHttpHeaders(static_cast<int>(status), "", 0, wsi)) { in DynServerCallback()
313 lws_callback_on_writable(wsi); in DynServerCallback()
323 auto handler = dyn_handlers_[wsi].get(); in DynServerCallback()
332 auto handler = dyn_handlers_[wsi].get(); in DynServerCallback()
339 dyn_handlers_[wsi]->content_len(), wsi)) { in DynServerCallback()
342 lws_callback_on_writable(wsi); in DynServerCallback()
346 auto handler = dyn_handlers_[wsi].get(); in DynServerCallback()
352 dyn_handlers_.erase(wsi); in DynServerCallback()
360 return lws_callback_http_dummy(wsi, reason, user, in, len); in DynServerCallback()
365 int WebSocketServer::ServerCallback(struct lws* wsi, in ServerCallback() argument
370 auto path = GetPath(wsi); in ServerCallback()
371 auto handler = InstantiateHandler(path, wsi); in ServerCallback()
374 lws_close_reason(wsi, LWS_CLOSE_STATUS_NOSTATUS, (uint8_t*)"404", 3); in ServerCallback()
377 handlers_[wsi] = handler; in ServerCallback()
382 auto handler = handlers_[wsi]; in ServerCallback()
385 handlers_.erase(wsi); in ServerCallback()
390 auto handler = handlers_[wsi]; in ServerCallback()
394 lws_close_reason(wsi, LWS_CLOSE_STATUS_NORMAL, nullptr, 0); in ServerCallback()
404 auto handler = handlers_[wsi]; in ServerCallback()
406 bool is_final = (lws_remaining_packet_payload(wsi) == 0) && in ServerCallback()
407 lws_is_final_fragment(wsi); in ServerCallback()
409 lws_frame_is_binary(wsi), is_final); in ServerCallback()
416 return lws_callback_http_dummy(wsi, reason, user, in, len); in ServerCallback()
422 const std::string& uri_path, struct lws* wsi) { in InstantiateHandler() argument
429 return it->second->Build(wsi); in InstantiateHandler()
434 const std::string& uri_path, struct lws* wsi) { in InstantiateDynHandler() argument
441 return it->second(wsi); in InstantiateDynHandler()