From 765b1e3bca234c3ed40746024a1de6786a3f3f76 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 8 Jul 2021 11:43:46 -0400 Subject: [PATCH] TT#89352 use bool type for foreign call functions Change-Id: If8d5e28db534e6aeaaffb885e732e2bdd7338831 --- daemon/call.c | 8 ++++---- daemon/call_interfaces.c | 4 ++-- daemon/cli.c | 7 ++++--- daemon/main.c | 7 ++++--- daemon/media_socket.c | 2 +- daemon/redis.c | 11 ++++++----- include/call.h | 4 ++-- include/redis.h | 2 +- 8 files changed, 24 insertions(+), 21 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index 3f6950f9c..0290c2450 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -123,7 +123,7 @@ out: -void call_make_own_foreign(struct call *c, int foreign) { +void call_make_own_foreign(struct call *c, bool foreign) { statistics_update_foreignown_dec(c); c->foreign_call = foreign ? 1 : 0; statistics_update_foreignown_inc(c); @@ -3100,7 +3100,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, int foreign) { +struct call *call_get_or_create(const str *callid, bool foreign) { struct call *c; restart: @@ -3119,7 +3119,7 @@ restart: } g_hash_table_insert(rtpe_callhash, &c->callid, obj_get(c)); - c->foreign_call = foreign; + c->foreign_call = foreign ? 1 : 0; statistics_update_foreignown_inc(c); @@ -3188,7 +3188,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, 0); + return call_get_or_create(callid, false); return call_get(callid); } diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index e94aa39fb..0caa72ed8 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -1401,7 +1401,7 @@ static const char *call_offer_answer_ng(struct ng_buffer *ngbuf, bencode_item_t goto out; } - call = call_get_or_create(&flags.call_id, 0); + call = call_get_or_create(&flags.call_id, false); } errstr = "Unknown call-id"; @@ -1412,7 +1412,7 @@ static const char *call_offer_answer_ng(struct ng_buffer *ngbuf, bencode_item_t call->debug = 1; if (rtpe_config.active_switchover && IS_FOREIGN_CALL(call)) - call_make_own_foreign(call, 0); + call_make_own_foreign(call, false); if (!call->created_from && addr) { call->created_from = call_strdup(call, addr); diff --git a/daemon/cli.c b/daemon/cli.c index f563405b9..7b0f915d5 100644 --- a/daemon/cli.c +++ b/daemon/cli.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "poller.h" #include "aux.h" @@ -1076,7 +1077,7 @@ 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) { +static void cli_incoming_active_standby(struct cli_writer *cw, bool foreign) { GHashTableIter iter; gpointer key, value; @@ -1100,10 +1101,10 @@ static void cli_incoming_active_standby(struct cli_writer *cw, int foreign) { 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); + cli_incoming_active_standby(cw, false); } static void cli_incoming_standby(str *instr, struct cli_writer *cw) { - cli_incoming_active_standby(cw, 1); + cli_incoming_active_standby(cw, true); } static void cli_incoming_debug(str *instr, struct cli_writer *cw) { diff --git a/daemon/main.c b/daemon/main.c index 495b16153..097e21b4a 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -16,6 +16,7 @@ #include #include #include +#include #ifdef HAVE_MQTT #include #endif @@ -1149,14 +1150,14 @@ no_kernel: // first as the "owned" DB can do a stray update back to Redis for (GList *l = rtpe_config.redis_subscribed_keyspaces.head; l; l = l->next) { int db = GPOINTER_TO_INT(l->data); - if (redis_restore(rtpe_redis_notify, 1, db)) + if (redis_restore(rtpe_redis_notify, true, db)) ilog(LOG_WARN, "Unable to restore calls from the active-active peer"); } - if (redis_restore(rtpe_redis_write, 0, -1)) + if (redis_restore(rtpe_redis_write, false, -1)) die("Refusing to continue without working Redis database"); } else { - if (redis_restore(rtpe_redis, 0, -1)) + if (redis_restore(rtpe_redis, false, -1)) die("Refusing to continue without working Redis database"); } diff --git a/daemon/media_socket.c b/daemon/media_socket.c index b5933120a..c14ba20f8 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -2229,7 +2229,7 @@ static int stream_packet(struct packet_handler_ctx *phc) { #endif if (rtpe_config.active_switchover && IS_FOREIGN_CALL(phc->mp.call)) - call_make_own_foreign(phc->mp.call, 0); + call_make_own_foreign(phc->mp.call, false); // this sets rtcp, in_srtp, and sinks media_packet_rtcp_demux(phc); diff --git a/daemon/redis.c b/daemon/redis.c index db08749ef..c4380f57f 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "compat.h" #include "aux.h" @@ -76,7 +77,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, int foreign); +static void json_restore_call(struct redis *r, const str *id, bool foreign); static int redis_connect(struct redis *r, int wait); static int json_build_ssrc(struct call_monologue *ml, JsonReader *root_reader); @@ -382,7 +383,7 @@ void on_redis_notification(redisAsyncContext *actx, void *reply, void *privdata) mutex_unlock(&r->lock); // unlock before restoring calls to avoid deadlock in case err happens - json_restore_call(r, &callid, 1); + json_restore_call(r, &callid, true); mutex_lock(&r->lock); } @@ -1798,7 +1799,7 @@ next: return 0; } -static void json_restore_call(struct redis *r, const str *callid, int foreign) { +static void json_restore_call(struct redis *r, const str *callid, bool foreign) { redisReply* rr_jsonStr; struct redis_hash call; struct redis_list tags, sfds, streams, medias, maps; @@ -1975,7 +1976,7 @@ err1: struct thread_ctx { GQueue r_q; mutex_t r_m; - int foreign; + bool foreign; }; static void restore_thread(void *call_p, void *ctx_p) { @@ -1998,7 +1999,7 @@ static void restore_thread(void *call_p, void *ctx_p) { mutex_unlock(&ctx->r_m); } -int redis_restore(struct redis *r, int foreign, int db) { +int redis_restore(struct redis *r, bool foreign, int db) { redisReply *calls = NULL, *call; int i, ret = -1; GThreadPool *gtp; diff --git a/include/call.h b/include/call.h index c6a0ced66..98ea20521 100644 --- a/include/call.h +++ b/include/call.h @@ -536,9 +536,9 @@ void free_sink_handler(void *); void __add_sink_handler(GQueue *, struct packet_stream *); -struct call *call_get_or_create(const str *callid, int foreign); +struct call *call_get_or_create(const str *callid, bool foreign); struct call *call_get_opmode(const str *callid, enum call_opmode opmode); -void call_make_own_foreign(struct call *c, int foreign); +void call_make_own_foreign(struct call *c, bool foreign); int call_get_mono_dialogue(struct call_monologue *dialogue[2], struct call *call, const str *fromtag, const str *totag, const str *viabranch); diff --git a/include/redis.h b/include/redis.h index a33fb513f..31f811990 100644 --- a/include/redis.h +++ b/include/redis.h @@ -108,7 +108,7 @@ void redis_delete_async_loop(void *d); struct redis *redis_new(const endpoint_t *, int, const char *, enum redis_role, int); void redis_close(struct redis *r); -int redis_restore(struct redis *, int foreign, int db); +int redis_restore(struct redis *, bool foreign, int db); void redis_update(struct call *, struct redis *); void redis_update_onekey(struct call *c, struct redis *r); void redis_delete(struct call *, struct redis *);