Skip to content

Commit

Permalink
mc: move DnD feature to multicast and fix build (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
cspiel1 authored Sep 13, 2024
1 parent 490ea5d commit c8f6124
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 24 deletions.
93 changes: 71 additions & 22 deletions modules/multicast/multicast.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@ struct mccfg {
char iface[128];
};

static struct mccfg mccfg = {
0,
1,
125,
""
struct mc {
bool dnd;
struct mccfg cfg;
};

static struct mc mc = {
false,
{
0,
1,
125,
"",
}
};

/**
* Decode IP-address <IP>:<PORT>
Expand Down Expand Up @@ -117,7 +124,18 @@ static int check_rtp_pt(struct aucodec *ac)
*/
uint8_t multicast_callprio(void)
{
return mccfg.callprio;
return mc.cfg.callprio;
}


/**
* Set the do not disturb flag
*
* @param v true if incoming calls should be rejected
*/
void multicast_set_dnd(bool v)
{
mc.dnd = v;
}


Expand All @@ -128,7 +146,7 @@ uint8_t multicast_callprio(void)
*/
uint8_t multicast_ttl(void)
{
return mccfg.ttl;
return mc.cfg.ttl;
}


Expand All @@ -139,7 +157,7 @@ uint8_t multicast_ttl(void)
*/
uint32_t multicast_fade_time(void)
{
return mccfg.tfade;
return mc.cfg.tfade;
}


Expand Down Expand Up @@ -317,12 +335,12 @@ static int cmd_mcreg(struct re_printf *pf, void *arg)
}

#ifdef HAVE_GETIFADDRS
if (str_isset(mccfg.iface)) {
if (str_isset(mc.cfg.iface)) {
unsigned int if_index;
if_index = if_nametoindex(mccfg.iface);
if_index = if_nametoindex(mc.cfg.iface);
if (!if_index) {
warning("multicast: could not find interface %s\n",
&mccfg.iface);
&mc.cfg.iface);
if (sa_af(&addr) == AF_INET6) {
err = EINVAL;
goto out;
Expand Down Expand Up @@ -658,20 +676,21 @@ static int module_read_config(void)
int err = 0, prio = 1;
struct sa laddr;

(void)conf_get_u32(conf_cur(), "multicast_call_prio", &mccfg.callprio);
if (mccfg.callprio > 255)
mccfg.callprio = 255;
(void)conf_get_u32(conf_cur(), "multicast_call_prio",
&mc.cfg.callprio);
if (mc.cfg.callprio > 255)
mc.cfg.callprio = 255;

(void)conf_get_u32(conf_cur(), "multicast_ttl", &mccfg.ttl);
if (mccfg.ttl > 255)
mccfg.ttl = 255;
(void)conf_get_u32(conf_cur(), "multicast_ttl", &mc.cfg.ttl);
if (mc.cfg.ttl > 255)
mc.cfg.ttl = 255;

(void)conf_get_u32(conf_cur(), "multicast_fade_time", &mccfg.tfade);
if (mccfg.tfade > 2000)
mccfg.tfade = 2000;
(void)conf_get_u32(conf_cur(), "multicast_fade_time", &mc.cfg.tfade);
if (mc.cfg.tfade > 2000)
mc.cfg.tfade = 2000;

(void)conf_get_str(conf_cur(), "multicast_iface", mccfg.iface,
sizeof(mccfg.iface));
(void)conf_get_str(conf_cur(), "multicast_iface", mc.cfg.iface,
sizeof(mc.cfg.iface));

sa_init(&laddr, AF_INET);
err = conf_apply(conf_cur(), "multicast_listener",
Expand Down Expand Up @@ -705,12 +724,41 @@ static const struct cmd cmdv[] = {
};


static void event_handler(enum ua_event ev, struct bevent *event, void *arg)
{
(void)arg;
const struct sip_msg *msg = bevent_get_msg(event);

switch (ev) {

case UA_EVENT_SIPSESS_CONN:
if (mc.dnd) {
(void)sip_treply(NULL, uag_sip(), msg, 480,
"Temporarily Unavailable");
info("menu: incoming call from %r <%r> rejected: "
"480 Temporarily Unavailable\n",
&msg->from.dname, &msg->from.auri);
bevent_stop(event);
break;
}

break;

default:
break;
}
}


static int module_init(void)
{
int err = 0;

err = module_read_config();
err |= cmd_register(baresip_commands(), cmdv, RE_ARRAY_SIZE(cmdv));
err |= bevent_register(event_handler, NULL);
if (err)
return err;

err |= mcsource_init();
err |= mcplayer_init();
Expand All @@ -727,6 +775,7 @@ static int module_close(void)
mcsender_stopall();
mcreceiver_unregall();

bevent_unregister(event_handler);
cmd_unregister(baresip_commands(), cmdv);

mcsource_terminate();
Expand Down
1 change: 1 addition & 0 deletions modules/multicast/multicast.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum {
uint8_t multicast_callprio(void);
uint8_t multicast_ttl(void);
uint32_t multicast_fade_time(void);
void multicast_set_dnd(bool v);


/* Sender */
Expand Down
4 changes: 2 additions & 2 deletions modules/multicast/receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static void resume_uag_state(void)
}

if (h > multicast_callprio()) {
uag_set_dnd(false);
multicast_set_dnd(false);
uag_set_nodial(false);
uag_hold_resume(NULL);
}
Expand Down Expand Up @@ -288,7 +288,7 @@ static int prio_handling(struct mcreceiver *mcreceiver, uint32_t ssrc)
struct le *leua;
struct ua *ua;

uag_set_dnd(true);
multicast_set_dnd(true);
uag_set_nodial(true);

for (leua = list_head(uag_list()); leua; leua = leua->next) {
Expand Down

0 comments on commit c8f6124

Please sign in to comment.