1 /*
2  * Copyright (C) 2012-2013 Crocodile RCS Ltd
3  *
4  * This file is part of Kamailio, a free SIP server.
5  *
6  * Kamailio is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version
10  *
11  * Kamailio is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * Exception: permission to copy, modify, propagate, and distribute a work
21  * formed by combining OpenSSL toolkit software and the code in this file,
22  * such as linking with software components and libraries released under
23  * OpenSSL project license.
24  *
25  */
26 
27 #ifndef _WS_CONN_H
28 #define _WS_CONN_H
29 
30 #include "../../core/atomic_ops.h"
31 
32 #include "../../core/counters.h"
33 #include "../../core/rpc.h"
34 #include "../../core/timer.h"
35 
36 typedef enum {
37 	WS_S_CONNECTING = 0, /* Never used - included for completeness */
38 	WS_S_OPEN,
39 	WS_S_CLOSING,
40 	WS_S_REMOVING,
41 	WS_S_CLOSED /* Never used - included for completeness */
42 } ws_conn_state_t;
43 
44 typedef struct ws_connection
45 {
46 	ws_conn_state_t state;
47 	int awaiting_pong;
48 	ticks_t rmticks;
49 
50 	int last_used;
51 	struct ws_connection *used_prev;
52 	struct ws_connection *used_next;
53 
54 	int id;			  /* id and id_hash are identical to the values */
55 	unsigned id_hash; /* for the corresponding TCP/TLS connection */
56 	struct ws_connection *id_prev;
57 	struct ws_connection *id_next;
58 
59 	struct receive_info rcv;
60 
61 	unsigned int sub_protocol;
62 
63 	atomic_t refcnt;
64 	int run_event;
65 
66 	str frag_buf;
67 } ws_connection_t;
68 
69 typedef struct ws_connection_id
70 {
71 	int id;
72 } ws_connection_id_t;
73 
74 typedef struct
75 {
76 	ws_connection_t *head;
77 	ws_connection_t *tail;
78 } ws_connection_list_t;
79 
80 typedef enum {
81 	WSCONN_EVENTROUTE_NO = 0,
82 	WSCONN_EVENTROUTE_YES
83 } ws_conn_eventroute_t;
84 
85 extern ws_connection_list_t *wsconn_used_list;
86 
87 extern char *wsconn_state_str[];
88 
89 extern stat_var *ws_current_connections;
90 extern stat_var *ws_max_concurrent_connections;
91 extern stat_var *ws_sip_current_connections;
92 extern stat_var *ws_sip_max_concurrent_connections;
93 extern stat_var *ws_msrp_current_connections;
94 extern stat_var *ws_msrp_max_concurrent_connections;
95 
96 int wsconn_init(void);
97 void wsconn_destroy(void);
98 int wsconn_add(struct receive_info *rcv, unsigned int sub_protocol);
99 int wsconn_rm(ws_connection_t *wsc, ws_conn_eventroute_t run_event_route);
100 int wsconn_update(ws_connection_t *wsc);
101 void wsconn_close_now(ws_connection_t *wsc);
102 ws_connection_t *wsconn_get(int id);
103 int wsconn_put(ws_connection_t *wsc);
104 ws_connection_t **wsconn_get_list(void);
105 int wsconn_put_list(ws_connection_t **list);
106 ws_connection_id_t *wsconn_get_list_ids(int idx);
107 int wsconn_put_list_ids(ws_connection_id_t *list);
108 int wsconn_put_id(int id);
109 void ws_rpc_dump(rpc_t *rpc, void *ctx);
110 void ws_timer(unsigned int ticks, void *param);
111 #endif /* _WS_CONN_H */
112