-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathmod_verto.h
360 lines (285 loc) · 7.05 KB
/
mod_verto.h
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2012, Anthony Minessale II <[email protected]>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Anthony Minessale II <[email protected]>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Anthony Minessale II <[email protected]>
* Seven Du <[email protected]>
*
* mod_html.h -- HTML 5 interface
*
*/
#ifndef MOD_VERTO_H
#define MOD_VERTO_H
#include <switch.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#ifdef WIN32
#include <WinSock2.h>
#else
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#endif
#include <string.h>
#ifndef WIN32
#include <unistd.h>
#include <poll.h>
#endif
#include <stdarg.h>
#ifndef WIN32
#include <netinet/tcp.h>
#include <sys/un.h>
#endif
#include <assert.h>
#include <errno.h>
#ifndef WIN32
#include <pwd.h>
#include <netdb.h>
#endif
#include <openssl/ssl.h>
#include "mcast.h"
#include "libks/ks.h"
#define MAX_QUEUE_LEN 100000
#define MAX_MISSED 500
#define MAXPENDING 10000
#define STACK_SIZE 80 * 1024
#define VERTO_CHAT_PROTO "verto"
#define copy_string(x,y,z) strncpy(x, y, z - 1)
#define set_string(x,y) strncpy(x, y, sizeof(x)-1)
#define CODE_INVALID -32600
#define CODE_AUTH_REQUIRED -32000
#define CODE_AUTH_FAILED -32001
#define CODE_SESSION_ERROR -32002
#define MY_EVENT_CLIENT_CONNECT "verto::client_connect"
#define MY_EVENT_CLIENT_DISCONNECT "verto::client_disconnect"
#define MY_EVENT_LOGIN "verto::login"
typedef enum {
PTYPE_CLIENT = (1 << 0),
PTYPE_CLIENT_SSL = (1 << 1)
} jsock_type_t;
typedef enum {
JPFLAG_INIT = (1 << 0),
JPFLAG_AUTHED = (1 << 1),
JPFLAG_CHECK_ATTACH = (1 << 2),
JPFLAG_EVENTS = (1 << 3),
JPFLAG_AUTH_EVENTS = (1 << 4),
JPFLAG_ALL_EVENTS_AUTHED = (1 << 5),
JPFLAG_AUTH_EXPIRED = (1 << 6)
} jpflag_t;
struct verto_profile_s;
struct jsock_s {
ks_socket_t client_socket;
switch_memory_pool_t *pool;
switch_thread_t *thread;
ks_pool_t *kpool;
kws_t *ws;
unsigned char buf[65535];
char *name;
jsock_type_t ptype;
struct sockaddr_in remote_addr;
struct sockaddr_in6 remote_addr6;
#ifndef WIN32
struct passwd pw;
#endif
uint32_t attach_timer;
uint8_t drop;
uint8_t nodelete;
ks_socket_t local_sock;
SSL *ssl;
jpflag_t flags;
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
switch_event_t *allowed_methods;
switch_event_t *allowed_jsapi;
switch_event_t *allowed_fsapi;
switch_event_t *allowed_event_channels;
char *id;
char *domain;
char *uid;
char *dialplan;
char *context;
char remote_host[256];
int remote_port;
int family;
switch_time_t exptime;
switch_time_t logintime;
struct verto_profile_s *profile;
switch_thread_rwlock_t *rwlock;
switch_mutex_t *write_mutex;
switch_mutex_t *filter_mutex;
switch_mutex_t *flag_mutex;
switch_event_t *params;
switch_event_t *vars;
switch_event_t *user_vars;
switch_queue_t *event_queue;
int lost_events;
int ready;
struct jsock_s *next;
};
typedef struct jsock_s jsock_t;
#define MAX_BIND 25
#define MAX_RTPIP 25
typedef struct ips {
char local_ip[256];
uint16_t local_port;
int secure;
int family;
} ips_t;
typedef enum {
TFLAG_SENT_MEDIA = (1 << 0),
TFLAG_ATTACH_REQ = (1 << 1),
TFLAG_TRACKED = (1 << 2)
} tflag_t;
typedef struct verto_pvt_s {
switch_memory_pool_t *pool;
char *jsock_uuid;
char *call_id;
char *r_sdp;
tflag_t flags;
switch_core_session_t *session;
switch_channel_t *channel;
switch_media_handle_t *smh;
switch_core_media_params_t *mparams;
switch_call_cause_t remote_hangup_cause;
switch_time_t detach_time;
struct verto_pvt_s *next;
switch_byte_t text_read_frame_data[SWITCH_RTP_MAX_BUF_LEN];
switch_frame_t text_read_frame;
switch_thread_cond_t *text_cond;
switch_mutex_t *text_cond_mutex;
switch_mutex_t *text_read_mutex;
switch_mutex_t *text_write_mutex;
switch_buffer_t *text_read_buffer;
switch_buffer_t *text_write_buffer;
} verto_pvt_t;
typedef struct verto_vhost_s {
char *domain;
char *alias;
char *root;
char *script_root;
char *index;
char *auth_realm;
char *auth_user;
char *auth_pass;
switch_event_t *rewrites;
switch_memory_pool_t *pool;
struct verto_vhost_s *next;
} verto_vhost_t;
struct verto_profile_s {
char *name;
switch_mutex_t *mutex;
switch_memory_pool_t *pool;
switch_thread_rwlock_t *rwlock;
struct ips ip[MAX_BIND];
int i;
const SSL_METHOD *ssl_method;
SSL_CTX *ssl_ctx;
char cert[512];
char key[512];
char chain[512];
jsock_t *jsock_head;
int jsock_count;
ks_socket_t server_socket[MAX_BIND];
int running;
int ssl_ready;
int ready;
int debug;
int chop_domain;
int in_thread;
int blind_reg;
char *userauth;
char *root_passwd;
int send_passwd;
char *context;
char *dialplan;
char *mcast_ip;
switch_port_t mcast_port;
mcast_handle_t mcast_sub;
mcast_handle_t mcast_pub;
char *extrtpip;
char *rtpip[MAX_RTPIP];
int rtpip_index;
int rtpip_cur;
char *rtpip6[MAX_RTPIP];
int rtpip_index6;
int rtpip_cur6;
char *cand_acl[SWITCH_MAX_CAND_ACL];
uint32_t cand_acl_count;
char *conn_acl[SWITCH_MAX_CAND_ACL];
uint32_t conn_acl_count;
char *inbound_codec_string;
char *outbound_codec_string;
char *jb_msec;
char *timer_name;
char *local_network;
verto_vhost_t *vhosts;
char *register_domain;
int enable_text;
struct verto_profile_s *next;
};
typedef struct verto_profile_s verto_profile_t;
struct globals_s {
switch_mutex_t *mutex;
switch_memory_pool_t *pool;
int profile_count;
verto_profile_t *profile_head;
int sig;
int running;
switch_hash_t *method_hash;
switch_mutex_t *method_mutex;
switch_hash_t *event_channel_hash;
switch_thread_rwlock_t *event_channel_rwlock;
int debug;
int ready;
int send_passwd;
int profile_threads;
int enable_presence;
int enable_fs_events;
switch_bool_t kslog_on;
switch_hash_t *jsock_hash;
switch_mutex_t *jsock_mutex;
verto_pvt_t *tech_head;
switch_thread_rwlock_t *tech_rwlock;
switch_thread_cond_t *detach_cond;
switch_mutex_t *detach_mutex;
switch_mutex_t *detach2_mutex;
uint32_t detached;
uint32_t detach_timeout;
switch_event_channel_id_t event_channel_id;
switch_log_level_t debug_level;
};
typedef switch_bool_t (*jrpc_func_t)(const char *method, cJSON *params, jsock_t *jsock, cJSON **response);
void set_log_path(const char *path);
/** @} */
#endif
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
*/