Skip to content

Commit cafa49a

Browse files
committed
Merge branch 'feature/media_exchange'
2 parents 166afb2 + dfe1d93 commit cafa49a

24 files changed

+4536
-25
lines changed

modules/b2b_entities/b2b_entities.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "../../dprint.h"
3636
#include "../../error.h"
3737
#include "../../ut.h"
38+
#include "../../pt.h"
3839
#include "../../script_cb.h"
3940
#include "../../parser/parse_from.h"
4041
#include "../dialog/dlg_load.h"
@@ -411,11 +412,12 @@ int b2b_restore_logic_info(enum b2b_entity_type type, str* key,
411412
}
412413

413414
int b2b_update_b2bl_param(enum b2b_entity_type type, str* key,
414-
str* param)
415+
str* param, int replicate)
415416
{
416417
b2b_dlg_t* dlg;
417418
b2b_table table;
418419
unsigned int hash_index, local_index;
420+
int unlock = 1;
419421

420422
if(!param)
421423
{
@@ -442,19 +444,25 @@ int b2b_update_b2bl_param(enum b2b_entity_type type, str* key,
442444
LM_ERR("Wrong format for b2b key [%.*s]\n", key->len, key->s);
443445
return -1;
444446
}
445-
lock_get(&table[hash_index].lock);
447+
if (table[hash_index].locked_by != process_no)
448+
lock_get(&table[hash_index].lock);
449+
else
450+
unlock = 0;
451+
446452
dlg = b2b_search_htable(table, hash_index, local_index);
447453
if(dlg == NULL)
448454
{
449455
LM_ERR("No dialog found\n");
450-
lock_release(&table[hash_index].lock);
456+
if (unlock)
457+
lock_release(&table[hash_index].lock);
451458
return -1;
452459
}
453460
memcpy(dlg->param.s, param->s, param->len);
454461
dlg->param.len = param->len;
455-
lock_release(&table[hash_index].lock);
462+
if (unlock)
463+
lock_release(&table[hash_index].lock);
456464

457-
if (b2be_cluster)
465+
if (b2be_cluster && replicate)
458466
replicate_entity_update(dlg, type, hash_index, param, NULL);
459467

460468
return 0;

modules/b2b_entities/b2be_clustering.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "b2be_clustering.h"
3838
#include "b2b_entities.h"
3939
#include "b2be_db.h"
40+
#include "../../pt.h"
4041

4142
#define NO_REPL_CONSTANT_STRS 10
4243

@@ -456,14 +457,16 @@ int receive_entity_create(bin_packet_t *packet, b2b_dlg_t *dlg, int type,
456457

457458
lock_get(&htable[h_idx].lock);
458459

459-
b2b_run_cb(new_dlg, type, B2BCB_RECV_EVENT, B2B_EVENT_CREATE, packet);
460-
461460
new_key = b2b_htable_insert(htable, new_dlg, hash_index, type, 1, 1);
462461
if (new_key == NULL) {
463462
LM_ERR("Failed to insert new record\n");
464463
goto error;
465464
}
466465

466+
htable[h_idx].locked_by = process_no;
467+
b2b_run_cb(new_dlg, type, B2BCB_RECV_EVENT, B2B_EVENT_CREATE, packet);
468+
htable[h_idx].locked_by = -1;
469+
467470
lock_release(&htable[h_idx].lock);
468471

469472
pkg_free(new_key);
@@ -551,7 +554,9 @@ int receive_entity_update(bin_packet_t *packet)
551554
if (packet->type == REPL_ENTITY_UPDATE) {
552555
unpack_update_fields(packet, dlg);
553556

557+
htable[hash_index].locked_by = process_no;
554558
b2b_run_cb(dlg, type, B2BCB_RECV_EVENT, B2B_EVENT_UPDATE, packet);
559+
htable[hash_index].locked_by = -1;
555560
} else {
556561
rc = recv_b2bl_param_update(packet, dlg);
557562
}
@@ -605,7 +610,9 @@ int receive_entity_delete(bin_packet_t *packet)
605610
return 0;
606611
}
607612

613+
htable[hash_index].locked_by = process_no;
608614
b2b_run_cb(dlg, type, B2BCB_RECV_EVENT, B2B_EVENT_DELETE, packet);
615+
htable[hash_index].locked_by = -1;
609616

610617
b2b_entity_db_delete(type, dlg);
611618
b2b_delete_record(dlg, htable, hash_index);

modules/b2b_entities/b2be_load.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ typedef int (*b2b_restore_linfo_t)(enum b2b_entity_type type, str* key,
124124
typedef int (*b2b_reg_cb_t) (b2b_cb_t cb, int cb_type, str *mod_name);
125125

126126
typedef int (*b2b_update_b2bl_param_t)(enum b2b_entity_type type, str* key,
127-
str* param);
127+
str* param, int replicate);
128128
typedef int (*b2b_get_b2bl_key_t)(str* callid, str* from_tag, str* to_tag,
129129
str* entity_key, str* tuple_key);
130130

modules/b2b_entities/dlg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ typedef struct b2b_entry
117117
{
118118
b2b_dlg_t* first;
119119
gen_lock_t lock;
120+
int locked_by;
120121
int checked;
121122
}b2b_entry_t;
122123

modules/b2b_entities/doc/b2b_entities_devel.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ typedef int (*b2b_restore_linfo_t)(enum b2b_entity_type type, str* key,
218218
<programlisting format="linespecific">
219219
...
220220
typedef int (*b2b_update_b2bl_param_t)(enum b2b_entity_type type, str* key,
221-
str* param);
221+
str* param, int replicate);
222222
...
223223
</programlisting>
224224
<para>

modules/b2b_logic/logic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4090,7 +4090,7 @@ int b2bl_bridge_2calls(str* key1, str* key2)
40904090
e1->no = 0;
40914091
e2->no = 1;
40924092

4093-
if(b2b_api.update_b2bl_param(e2->type, &e2->key, tuple->key) < 0)
4093+
if(b2b_api.update_b2bl_param(e2->type, &e2->key, tuple->key, 1) < 0)
40944094
{
40954095
LM_ERR("Failed to update b2bl parameter in b2b_entities\n");
40964096
goto error;

modules/dialog/dialog.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,10 @@ int load_dlg( struct dlg_binds *dlgb )
594594
dlgb->dlg_ref = _ref_dlg;
595595
dlgb->dlg_unref = unref_dlg_destroy_safe;
596596

597+
dlgb->get_direction = get_dlg_direction;
598+
dlgb->get_dlg_by_callid = get_dlg_by_callid;
599+
dlgb->send_indialog_request = send_indialog_request;
600+
597601
dlgb->get_rr_param = get_rr_param;
598602

599603
/* dlg context functions */
@@ -1563,20 +1567,26 @@ int pv_get_dlg_timeout(struct sip_msg *msg, pv_param_t *param,
15631567
int pv_get_dlg_dir(struct sip_msg *msg, pv_param_t *param,
15641568
pv_value_t *res)
15651569
{
1566-
struct dlg_cell *dlg;
1570+
int dir;
15671571

15681572
if(res==NULL)
15691573
return -1;
15701574

1571-
if ( (dlg=get_current_dialog())==NULL || ctx_lastdstleg_get()<0)
1572-
return pv_get_null( msg, param, res);
1573-
1574-
if (ctx_lastdstleg_get()==0) {
1575-
res->rs.s = "upstream";
1576-
res->rs.len = 8;
1577-
} else {
1578-
res->rs.s = "downstream";
1579-
res->rs.len = 10;
1575+
dir = get_dlg_direction();
1576+
switch (dir) {
1577+
case DLG_DIR_NONE:
1578+
return pv_get_null( msg, param, res);
1579+
case DLG_DIR_UPSTREAM:
1580+
res->rs.s = "upstream";
1581+
res->rs.len = 8;
1582+
break;
1583+
case DLG_DIR_DOWNSTREAM:
1584+
res->rs.s = "downstream";
1585+
res->rs.len = 10;
1586+
break;
1587+
default:
1588+
LM_BUG("unknwn dlg direction %d!\n", dir);
1589+
return -1;
15801590
}
15811591

15821592
res->flags = PV_VAL_STR;

modules/dialog/dlg_handlers.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ int terminate_dlg(str *callid, unsigned int h_entry, unsigned int h_id,
127127
typedef int (*terminate_dlg_f)(str *callid, unsigned int h_entry, unsigned int h_id,
128128
str *reason);
129129

130+
typedef int (*indialog_reply_f) (struct sip_msg *msg, int statuscode, void *param);
131+
typedef int (*send_indialog_req_f)(struct dlg_cell *dlg, str *method,
132+
int leg, str *body, str *ct, indialog_reply_f func, void *param);
133+
int send_indialog_request(struct dlg_cell *dlg, str *method,
134+
int leg, str *body, str *ct, indialog_reply_f func, void *param);
135+
130136
void unreference_dialog(void *dialog);
131137

132138
static inline int parse_dlg_rr_param(char *p, char *end,

modules/dialog/dlg_hash.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ extern int dlg_enable_stats;
206206
#define other_leg(dlg, l) \
207207
(l == DLG_CALLER_LEG? callee_idx(dlg): DLG_CALLER_LEG)
208208

209+
#define dlg_get_out_sdp(_dlg, _dst) \
210+
((_dlg)->legs[(_dst)].out_sdp.s? \
211+
(_dlg)->legs[(_dst)].out_sdp:(_dlg)->legs[other_leg(_dlg, _dst)].in_sdp)
212+
209213

210214
#define ctx_dialog_get() \
211215
((struct dlg_cell*)context_get_ptr(CONTEXT_GLOBAL,current_processing_ctx,ctx_dlg_idx) )
@@ -403,6 +407,8 @@ struct dlg_cell* get_dlg_by_val(str *attr, str *val);
403407

404408
struct dlg_cell* get_dlg_by_callid( str *callid, int active_only);
405409

410+
int get_dlg_direction(void);
411+
406412
void link_dlg(struct dlg_cell *dlg, int extra_refs);
407413

408414
#define _link_dlg_unsafe(d_entry, dlg) \

modules/dialog/dlg_load.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
#include "../../sr_module.h"
3636

3737
typedef struct dlg_cell *(*get_dlg_f) (void);
38+
typedef struct dlg_cell *(*get_dlg_by_callid_f) (str *, int);
3839
typedef int (*match_dialog_f) (struct sip_msg *msg, int _seq_match_mode);
40+
typedef int (*get_direction_f) (void);
3941

4042
struct dlg_binds {
4143
register_dlgcb_f register_dlgcb;
@@ -60,6 +62,10 @@ struct dlg_binds {
6062
ref_dlg_f dlg_ref;
6163
unref_dlg_f dlg_unref;
6264

65+
get_direction_f get_direction;
66+
get_dlg_by_callid_f get_dlg_by_callid;
67+
send_indialog_req_f send_indialog_request;
68+
6369
get_rr_param_f get_rr_param;
6470

6571
dlg_ctx_register_int_f dlg_ctx_register_int;

0 commit comments

Comments
 (0)