-
Notifications
You must be signed in to change notification settings - Fork 564
/
b2be_load.h
226 lines (189 loc) · 6.27 KB
/
b2be_load.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
/*
* Copyright (C) 2020 OpenSIPS Solutions
*
* This file is part of opensips, a free SIP server.
*
* opensips is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*
* opensips is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*
*/
#ifndef _B2BE_LOAD_H_
#define _B2BE_LOAD_H_
#include "../../bin_interface.h"
#define B2BCB_TRIGGER_EVENT (1<<0)
#define B2BCB_RECV_EVENT (1<<1)
#define B2BCB_BACKEND_DB (1<<0)
#define B2BCB_BACKEND_CLUSTER (1<<1)
#define B2B_REQUEST 0
#define B2B_REPLY 1
#define B2B_NOTIFY_FL_TERMINATED (1<<0)
#define B2B_NOTIFY_FL_ACK_NEG (1<<1)
enum b2b_entity_type {B2B_SERVER=0, B2B_CLIENT, B2B_NONE};
typedef struct client_info
{
str method;
str from_uri;
str from_dname;
str req_uri;
str dst_uri;
str to_uri;
str to_dname;
str* extra_headers;
str* client_headers;
str* body;
str* from_tag;
str local_contact;
unsigned int cseq;
unsigned int maxfwd;
struct socket_info* send_sock;
struct usr_avp *avps;
}client_info_t;
typedef struct b2b_dlginfo
{
str callid;
str fromtag;
str totag;
}b2b_dlginfo_t;
typedef struct b2b_req_data
{
enum b2b_entity_type et;
str* b2b_key;
str* method;
str* extra_headers;
str* client_headers;
str* body;
b2b_dlginfo_t* dlginfo;
unsigned int maxfwd;
unsigned int no_cb;
}b2b_req_data_t;
typedef struct b2b_rpl_data
{
enum b2b_entity_type et;
str* b2b_key;
int method;
int code;
str* text;
str* body;
str* extra_headers;
b2b_dlginfo_t* dlginfo;
}b2b_rpl_data_t;
typedef int (*b2b_tracer_cb)(struct sip_msg *msg, void *trans, void* param);
typedef void (*b2b_tracer_freep_cb)( void *param);
struct b2b_tracer {
b2b_tracer_cb f;
void *param;
b2b_tracer_freep_cb f_freep;
};
enum b2b_event_type {B2B_EVENT_CREATE, B2B_EVENT_ACK, B2B_EVENT_UPDATE,
B2B_EVENT_DELETE};
typedef void (*b2b_cb_t)(enum b2b_entity_type entity_type, str* entity_key,
str *param, enum b2b_event_type event_type, bin_packet_t *storage,
int backend);
typedef int (*b2b_notify_t)(struct sip_msg* msg, str* key, int type, void* param,
int flags);
typedef int (*b2b_add_dlginfo_t)(str* key, str* entity_key, int src,
b2b_dlginfo_t* info);
typedef str* (*b2b_server_new_t) (struct sip_msg* , str* local_contact,
b2b_notify_t , str *mod_name, str* param, struct b2b_tracer *tracer);
typedef str* (*b2b_client_new_t) (client_info_t* , b2b_notify_t b2b_cback,
b2b_add_dlginfo_t add_dlginfo_f, str *mod_name, str* param,
struct b2b_tracer *tracer);
typedef int (*b2b_send_request_t)(b2b_req_data_t*);
typedef int (*b2b_send_reply_t)(b2b_rpl_data_t*);
typedef void (*b2b_entity_delete_t)(enum b2b_entity_type et, str* b2b_key,
b2b_dlginfo_t* dlginfo, int db_del, int replicate);
typedef void (*b2b_db_delete_t)(str param);
typedef int (*b2b_restore_linfo_t)(enum b2b_entity_type type, str* key,
b2b_notify_t cback);
typedef int (*b2b_reg_cb_t) (b2b_cb_t cb, int cb_type, str *mod_name);
typedef int (*b2b_update_b2bl_param_t)(enum b2b_entity_type type, str* key,
str* param, int replicate);
typedef int (*b2b_get_b2bl_key_t)(str* callid, str* from_tag, str* to_tag,
str* entity_key, str* tuple_key);
typedef int (*b2b_apply_lumps_t)(struct sip_msg* msg);
typedef void* (*b2b_get_context_t)(void);
typedef struct b2b_api
{
b2b_server_new_t server_new;
b2b_client_new_t client_new;
b2b_send_request_t send_request;
b2b_send_reply_t send_reply;
b2b_entity_delete_t entity_delete;
b2b_db_delete_t entities_db_delete;
b2b_restore_linfo_t restore_logic_info;
b2b_reg_cb_t register_cb;
b2b_update_b2bl_param_t update_b2bl_param;
b2b_get_b2bl_key_t get_b2bl_key;
b2b_apply_lumps_t apply_lumps;
b2b_get_context_t get_context;
}b2b_api_t;
typedef int(*load_b2b_f) (b2b_api_t* api);
static inline int load_b2b_api( struct b2b_api *b2b_api)
{
load_b2b_f load_b2b;
/* import the b2b_entities auto-loading function */
if ( !(load_b2b=(load_b2b_f)find_export("load_b2b", 0))) {
LM_ERR("can't import load_b2b\n");
return -1;
}
/* let the auto-loading function load all B2B entities stuff */
return load_b2b( b2b_api );
}
static inline b2b_dlginfo_t *b2b_new_dlginfo(str *callid, str *fromtag, str *totag)
{
b2b_dlginfo_t* dlg = NULL;
int size;
size = sizeof(b2b_dlginfo_t) + callid->len;
if (totag && totag->s)
size += totag->len;
if (fromtag && fromtag->s)
size += fromtag->len;
dlg = shm_malloc(size);
if (!dlg)
return NULL;
memset(dlg, 0, size);
dlg->callid.s = (char *)(dlg + 1);
dlg->callid.len = callid->len;
memcpy(dlg->callid.s, callid->s, callid->len);
if (totag->s) {
dlg->totag.len = totag->len;
dlg->totag.s = dlg->callid.s + dlg->callid.len;
memcpy(dlg->totag.s, totag->s, totag->len);
}
if (fromtag->s) {
dlg->fromtag.len = fromtag->len;
dlg->fromtag.s = dlg->callid.s + dlg->callid.len + dlg->totag.len;
memcpy(dlg->fromtag.s, fromtag->s, fromtag->len);
}
return dlg;
}
static inline b2b_dlginfo_t *b2b_dup_dlginfo(b2b_dlginfo_t *info)
{
return b2b_new_dlginfo(&info->callid, &info->fromtag, &info->totag);
}
#endif