TT#81212 add trigger to set all calls to own or foreign

Change-Id: I9ee69680bccd79bae19332189a8531eaa2f6950b
pull/1126/head
Richard Fuchs 5 years ago
parent c9140f9f66
commit 260a170524

@ -2681,7 +2681,7 @@ static struct call *call_create(const str *callid) {
}
/* returns call with master_lock held in W */
struct call *call_get_or_create(const str *callid, enum call_type type) {
struct call *call_get_or_create(const str *callid, int foreign) {
struct call *c;
restart:
@ -2700,8 +2700,7 @@ restart:
}
g_hash_table_insert(rtpe_callhash, &c->callid, obj_get(c));
if (type == CT_FOREIGN_CALL) /* foreign call*/
c->foreign_call = 1;
c->foreign_call = foreign;
statistics_update_foreignown_inc(c);
@ -2740,7 +2739,7 @@ struct call *call_get(const str *callid) {
/* returns call with master_lock held in W, or possibly NULL iff opmode == OP_ANSWER */
struct call *call_get_opmode(const str *callid, enum call_opmode opmode) {
if (opmode == OP_OFFER)
return call_get_or_create(callid, CT_OWN_CALL);
return call_get_or_create(callid, 0);
return call_get(callid);
}

@ -1220,12 +1220,12 @@ static const char *call_offer_answer_ng(bencode_item_t *input,
rwlock_unlock_w(&call->master_lock);
call_destroy(call);
obj_put(call);
call = call_get_or_create(&flags.call_id, CT_OWN_CALL);
call = call_get_or_create(&flags.call_id, 0);
}
}
else {
/* call == NULL, should create call */
call = call_get_or_create(&flags.call_id, CT_OWN_CALL);
call = call_get_or_create(&flags.call_id, 0);
}
}

@ -45,6 +45,8 @@ static void cli_incoming_terminate(str *instr, struct cli_writer *cw);
static void cli_incoming_ksadd(str *instr, struct cli_writer *cw);
static void cli_incoming_ksrm(str *instr, struct cli_writer *cw);
static void cli_incoming_kslist(str *instr, struct cli_writer *cw);
static void cli_incoming_active(str *instr, struct cli_writer *cw);
static void cli_incoming_standby(str *instr, struct cli_writer *cw);
static void cli_incoming_set_maxopenfiles(str *instr, struct cli_writer *cw);
static void cli_incoming_set_maxsessions(str *instr, struct cli_writer *cw);
@ -100,6 +102,8 @@ static const cli_handler_t cli_top_handlers[] = {
{ "ksadd", cli_incoming_ksadd },
{ "ksrm", cli_incoming_ksrm },
{ "kslist", cli_incoming_kslist },
{ "active", cli_incoming_active },
{ "standby", cli_incoming_standby },
{ NULL, },
};
static const cli_handler_t cli_set_handlers[] = {
@ -169,7 +173,7 @@ static void cli_handler_do(const cli_handler_t *handlers, str *instr,
cw->cw_printf(cw, "%s:%s\n", "Unknown or incomplete command:", instr->s);
}
static void destroy_own_foreign_calls(unsigned int foreign_call, unsigned int uint_keyspace_db) {
static void destroy_own_foreign_calls(int foreign_call, unsigned int uint_keyspace_db) {
struct call *c = NULL;
struct call_monologue *ml = NULL;
GQueue call_list = G_QUEUE_INIT;
@ -224,15 +228,15 @@ static void destroy_own_foreign_calls(unsigned int foreign_call, unsigned int ui
}
static void destroy_all_foreign_calls(void) {
destroy_own_foreign_calls(CT_FOREIGN_CALL, UNDEFINED);
destroy_own_foreign_calls(1, UNDEFINED);
}
static void destroy_all_own_calls(void) {
destroy_own_foreign_calls(CT_OWN_CALL, UNDEFINED);
destroy_own_foreign_calls(0, UNDEFINED);
}
static void destroy_keyspace_foreign_calls(unsigned int uint_keyspace_db) {
destroy_own_foreign_calls(CT_FOREIGN_CALL, uint_keyspace_db);
destroy_own_foreign_calls(1, uint_keyspace_db);
}
static void cli_incoming_params_start(str *instr, struct cli_writer *cw) {
@ -1054,6 +1058,28 @@ static void cli_incoming_kslist(str *instr, struct cli_writer *cw) {
cw->cw_printf(cw, "\n");
}
static void cli_incoming_active_standby(struct cli_writer *cw, int foreign) {
GHashTableIter iter;
gpointer key, value;
rwlock_lock_r(&rtpe_callhash_lock);
g_hash_table_iter_init(&iter, rtpe_callhash);
while (g_hash_table_iter_next(&iter, &key, &value)) {
struct call *c = value;
call_make_own_foreign(c, foreign);
}
rwlock_unlock_r(&rtpe_callhash_lock);
cw->cw_printf(cw, "Ok, all calls set to '%s'\n", foreign ? "foreign (standby)" : "owned (active)");
}
static void cli_incoming_active(str *instr, struct cli_writer *cw) {
cli_incoming_active_standby(cw, 0);
}
static void cli_incoming_standby(str *instr, struct cli_writer *cw) {
cli_incoming_active_standby(cw, 1);
}
static void cli_incoming(struct streambuf_stream *s) {
ilog(LOG_INFO, "New cli connection from %s", s->addr);
}
@ -1079,7 +1105,6 @@ static void cli_stream_readable(struct streambuf_stream *s) {
return;
}
ilog(LOG_INFO, "Got CLI command: %s%s%s", FMT_M(inbuf));
str_init(&instr, inbuf);
struct cli_writer cw = {
@ -1094,6 +1119,7 @@ static void cli_stream_readable(struct streambuf_stream *s) {
}
void cli_handle(str *instr, struct cli_writer *cw) {
ilog(LOG_INFO, "Got CLI command: " STR_FORMAT_M, STR_FMT_M(instr));
cli_handler_do(cli_top_handlers, instr, cw);
}

@ -76,7 +76,7 @@ static int redisCommandNR(redisContext *r, const char *fmt, ...)
#define REDIS_FMT(x) (int) (x)->len, (x)->str
static int redis_check_conn(struct redis *r);
static void json_restore_call(struct redis *r, const str *id, enum call_type type);
static void json_restore_call(struct redis *r, const str *id, int foreign);
static int redis_connect(struct redis *r, int wait);
static void redis_pipe(struct redis *r, const char *fmt, ...) {
@ -367,7 +367,7 @@ void on_redis_notification(redisAsyncContext *actx, void *reply, void *privdata)
goto err;
}
}
json_restore_call(r, &callid, CT_FOREIGN_CALL);
json_restore_call(r, &callid, 1);
}
if (strncmp(rr->element[3]->str,"del",3)==0) {
@ -1713,7 +1713,7 @@ static int json_build_ssrc(struct call *c, JsonReader *root_reader) {
return 0;
}
static void json_restore_call(struct redis *r, const str *callid, enum call_type type) {
static void json_restore_call(struct redis *r, const str *callid, int foreign) {
redisReply* rr_jsonStr;
struct redis_hash call;
struct redis_list tags, sfds, streams, medias, maps;
@ -1739,7 +1739,7 @@ static void json_restore_call(struct redis *r, const str *callid, enum call_type
if (!root_reader)
goto err1;
c = call_get_or_create(callid, type);
c = call_get_or_create(callid, foreign);
err = "failed to create call struct";
if (!c)
goto err1;
@ -1891,7 +1891,7 @@ static void restore_thread(void *call_p, void *ctx_p) {
r = g_queue_pop_head(&ctx->r_q);
mutex_unlock(&ctx->r_m);
json_restore_call(r, &callid, CT_OWN_CALL);
json_restore_call(r, &callid, 0);
mutex_lock(&ctx->r_m);
g_queue_push_tail(&ctx->r_q, r);

@ -60,11 +60,6 @@ enum call_stream_state {
CSS_RUNNING,
};
enum call_type {
CT_OWN_CALL = 0,
CT_FOREIGN_CALL,
};
#define ERROR_NO_FREE_PORTS -100
#define ERROR_NO_FREE_LOGS -101
@ -409,7 +404,6 @@ struct call {
sockaddr_t xmlrpc_callback;
unsigned int redis_hosted_db;
unsigned int foreign_call; // created_via_redis_notify call
struct recording *recording;
str metadata;
@ -419,6 +413,7 @@ struct call {
int recording_on:1;
int rec_forwarding:1;
int drop_traffic:1;
int foreign_call:1; // created_via_redis_notify call
};
@ -440,7 +435,7 @@ void __monologue_viabranch(struct call_monologue *ml, const str *viabranch);
struct packet_stream *__packet_stream_new(struct call *call);
struct call *call_get_or_create(const str *callid, enum call_type);
struct call *call_get_or_create(const str *callid, int foreign);
struct call *call_get_opmode(const str *callid, enum call_opmode opmode);
void call_make_own_foreign(struct call *c, int foreign);
struct call_monologue *call_get_mono_dialogue(struct call *call, const str *fromtag, const str *totag,

Loading…
Cancel
Save