1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
/* BSD-2-Clause license
*
* Copyright (c) 2018-2023 NST <www.newinfosec.ru>, sss <sss at dark-alexandr dot net>.
*
*/
#pragma once
#include <ev.h>
#include <wslay/wslay.h>
#include <sys/queue.h>
typedef enum ws_server_state_e
{
ws_server_state_http_handshake = 0,
ws_server_state_ws_running
} ws_server_state;
typedef enum
{
ws_session_initial,
ws_session_approved,
ws_session_denied,
ws_session_started,
ws_session_ended,
ws_session_error
} ws_session_state;
typedef struct
{
/* set session time limit and session idle timeout */
int64_t session_time_limit, session_idle_timeout;
} ws_session_settings;
typedef struct ws_session_s
{
ws_server_state http_state;
ws_session_state session_state;
ev_io ev_con_fd_r, ev_con_fd_w;
int connection_fd;
char read_buf[2048], *sid_base64, *attach_sid_base64, *token_base64,
*backend_module_name;
size_t read_size, prev_read_size;
wslay_event_context_ptr wslay_ctx;
bool token_verified;
void *task_info, *wrdp_thpool_task, *curlm;
/* backend settings cache */
SLIST_HEAD(settings_head, backend_setting_s) backend_settings_head;
SLIST_HEAD(curl_head, curls_easy_s) curls_easy_head;
} ws_session;
int ws_server_init();
int ws_server_init_unix();
bool ws_server_handle_data(ws_session *session);
|