Skip to content

Commit

Permalink
core: move DnD feature to menu
Browse files Browse the repository at this point in the history
  • Loading branch information
cspiel1 committed Apr 22, 2024
1 parent 7b9ebc9 commit a623caf
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 34 deletions.
7 changes: 5 additions & 2 deletions include/baresip.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ bool account_uas_isset(const struct account *acc);
*/

enum call_event {
CALL_EVENT_ARRIVED,
CALL_EVENT_INCOMING,
CALL_EVENT_OUTGOING,
CALL_EVENT_RINGING,
Expand All @@ -184,11 +185,13 @@ enum call_event {
/** Call States */
enum call_state {
CALL_STATE_IDLE = 0,
CALL_STATE_ARRIVED,
CALL_STATE_INCOMING,
CALL_STATE_OUTGOING,
CALL_STATE_RINGING,
CALL_STATE_EARLY,
CALL_STATE_ESTABLISHED,
CALL_STATE_REJECTED,
CALL_STATE_TERMINATED,
CALL_STATE_TRANSFER,
CALL_STATE_UNKNOWN
Expand Down Expand Up @@ -219,6 +222,7 @@ int call_answer(struct call *call, uint16_t scode, enum vidmode vmode);
int call_progress_dir(struct call *call,
enum sdp_dir adir, enum sdp_dir vdir);
int call_progress(struct call *call);
void call_reject(struct call *call, uint16_t scode, const char *reason);
void call_hangup(struct call *call, uint16_t scode, const char *reason);
int call_modify(struct call *call);
int call_hold(struct call *call, bool hold);
Expand Down Expand Up @@ -837,6 +841,7 @@ enum ua_event {
UA_EVENT_SHUTDOWN,
UA_EVENT_EXIT,

UA_EVENT_CALL_ARRIVED,
UA_EVENT_CALL_INCOMING,
UA_EVENT_CALL_OUTGOING,
UA_EVENT_CALL_RINGING,
Expand Down Expand Up @@ -951,8 +956,6 @@ int uag_hold_others(struct call *call);
void uag_set_nodial(bool nodial);
bool uag_nodial(void);
void uag_set_exit_handler(ua_exit_h *exith, void *arg);
void uag_set_dnd(bool dnd);
bool uag_dnd(void);
void uag_enable_sip_trace(bool enable);
int uag_reset_transp(bool reg, bool reinvite);
void uag_set_sub_handler(sip_msg_h *subh);
Expand Down
5 changes: 5 additions & 0 deletions modules/menu/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,11 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev,

switch (ev) {

case UA_EVENT_CALL_ARRIVED:
if (menu.dnd)
call_reject(call, 480, "Temporarily Unavailable");

break;
case UA_EVENT_CALL_INCOMING:

if (call_state(call) != CALL_STATE_INCOMING)
Expand Down
1 change: 1 addition & 0 deletions modules/menu/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct menu{
struct odict *ovaufile; /**< Override aufile dictionary */
struct tmr tmr_play; /**< Tones play timer */
size_t outcnt; /**< Outgoing call counter */
bool dnd; /**< Do not Disturb flag */
};

/*Get menu object*/
Expand Down
4 changes: 3 additions & 1 deletion modules/menu/static_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,12 +713,13 @@ static int cmd_dnd(struct re_printf *pf, void *arg)
int err = 0;
const struct cmd_arg *carg = arg;
bool en = false;
struct menu *menu = menu_get();

err = str_bool(&en, carg->prm);
if (err)
goto out;

uag_set_dnd(en);
menu->dnd = en;

out:
if (err)
Expand Down Expand Up @@ -877,6 +878,7 @@ static int cmd_hangupall(struct re_printf *pf, void *arg)
}
else if (!pl_strcmp(&pldir, "in")) {
hangup_callstate(CALL_STATE_INCOMING);
hangup_callstate(CALL_STATE_ARRIVED);
}
else {
err = EINVAL;
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);
/* TODO: 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);
/* TODO: set dnd=true */
uag_set_nodial(true);

for (leua = list_head(uag_list()); leua; leua = leua->next) {
Expand Down
33 changes: 33 additions & 0 deletions src/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct call {
struct menc_sess *mencs; /**< Media encryption session state */
int af; /**< Preferred Address Family */
uint16_t scode; /**< Termination status code */
char *reason; /**< Reject reason */
call_event_h *eh; /**< Event handler */
call_dtmf_h *dtmfh; /**< DTMF handler */
void *arg; /**< Handler argument */
Expand Down Expand Up @@ -95,6 +96,7 @@ static const char *state_name(enum call_state st)
switch (st) {

case CALL_STATE_IDLE: return "IDLE";
case CALL_STATE_ARRIVED: return "ARRIVED";
case CALL_STATE_INCOMING: return "INCOMING";
case CALL_STATE_OUTGOING: return "OUTGOING";
case CALL_STATE_RINGING: return "RINGING";
Expand Down Expand Up @@ -298,6 +300,7 @@ static void mnat_handler(int err, uint16_t scode, const char *reason,
(void)send_invite(call);
break;

case CALL_STATE_ARRIVED:
case CALL_STATE_INCOMING:
call_event_handler(call, CALL_EVENT_INCOMING, "%s",
call->peer_uri);
Expand Down Expand Up @@ -454,6 +457,7 @@ static void call_destructor(void *arg)
mem_deref(call->not);
mem_deref(call->acc);
mem_deref(call->user_data);
mem_deref(call->reason);

list_flush(&call->custom_hdrs);
}
Expand Down Expand Up @@ -1253,6 +1257,15 @@ void call_hangup(struct call *call, uint16_t scode, const char *reason)
}


void call_reject(struct call *call, uint16_t scode, const char *reason)
{
set_state(call, CALL_STATE_REJECTED);
call->scode = scode;
mem_deref(call->reason);
(void)str_dup(&call->reason, reason);
}


/**
* Send a SIP 183 Session Progress with configured media
*
Expand Down Expand Up @@ -2221,6 +2234,26 @@ static bool valid_addressfamily(struct call *call, const struct stream *strm)
}


int call_arrived(struct call *call,
const struct sip_msg *msg)
{
int err = 0;
set_state(call, CALL_STATE_ARRIVED);
call_event_handler(call, CALL_EVENT_ARRIVED, "%s", call->peer_uri);

if (call->state == CALL_STATE_REJECTED) {
(void)sip_treply(NULL, uag_sip(), msg, call->scode,
call->reason ? call->reason : "Rejected");

set_state(call, CALL_STATE_TERMINATED);
mem_deref(call);
err = ENOENT;
}

return err;
}


int call_accept(struct call *call, struct sipsess_sock *sess_sock,
const struct sip_msg *msg)
{
Expand Down
3 changes: 2 additions & 1 deletion src/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ int call_alloc(struct call **callp, const struct config *cfg,
const struct sip_msg *msg, struct call *xcall,
struct dnsc *dnsc,
call_event_h *eh, void *arg);
int call_arrived(struct call *call,
const struct sip_msg *msg);
int call_accept(struct call *call, struct sipsess_sock *sess_sock,
const struct sip_msg *msg);
int call_sdp_get(const struct call *call, struct mbuf **descp, bool offer);
Expand Down Expand Up @@ -393,7 +395,6 @@ struct uag {
sip_msg_h *subh; /**< Subscribe handler */
ua_exit_h *exith; /**< UA Exit handler */
bool nodial; /**< Prevent outgoing calls */
bool dnd; /**< Do not Disturb flag */
void *arg; /**< UA Exit handler argument */
char *eprm; /**< Extra UA parameters */
#ifdef USE_TLS
Expand Down
14 changes: 8 additions & 6 deletions src/ua.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,10 @@ static void call_event_handler(struct call *call, enum call_event ev,

switch (ev) {

case CALL_EVENT_ARRIVED:
ua_event(ua, UA_EVENT_CALL_ARRIVED, call, "%s", peeruri);
break;

case CALL_EVENT_INCOMING:

if (contact_block_access(baresip_contacts(),
Expand Down Expand Up @@ -709,12 +713,6 @@ void sipsess_conn_handler(const struct sip_msg *msg, void *arg)
return;
}

if (uag_dnd()) {
(void)sip_treply(NULL, uag_sip(), msg,
480,"Temporarily Unavailable");
return;
}

/* handle multiple calls */
if (config->call.max_calls &&
uag_call_count() + 1 > config->call.max_calls) {
Expand Down Expand Up @@ -791,6 +789,10 @@ void sipsess_conn_handler(const struct sip_msg *msg, void *arg)
list_flush(&hdrs);
}

err = call_arrived(call, msg);
if (err)
return;

err = call_accept(call, uag_sipsess_sock(), msg);
if (err)
goto error;
Expand Down
22 changes: 0 additions & 22 deletions src/uag.c
Original file line number Diff line number Diff line change
Expand Up @@ -1219,28 +1219,6 @@ const char *uag_eprm(void)
}


/**
* Set global Do not Disturb flag
*
* @param dnd DnD flag
*/
void uag_set_dnd(bool dnd)
{
uag.dnd = dnd;
}


/**
* Get DnD status of uag
*
* @return True if DnD is active, False if not
*/
bool uag_dnd(void)
{
return uag.dnd;
}


/**
* Enable/Disable a transport protocol
*
Expand Down

0 comments on commit a623caf

Please sign in to comment.