Skip to content

Commit

Permalink
ua,call: add API for rejecting incoming call
Browse files Browse the repository at this point in the history
  • Loading branch information
cspiel1 committed Nov 28, 2024
1 parent 6d9a4a2 commit 1f2f3de
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/baresip.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ int call_progress_dir(struct call *call,
enum sdp_dir adir, enum sdp_dir vdir);
int call_progress(struct call *call);
void call_hangup(struct call *call, uint16_t scode, const char *reason);
void call_reject(struct call *call, uint16_t scode, const char *reason,
const char *fmt, ...);
int call_modify(struct call *call);
int call_hold(struct call *call, bool hold);
void call_set_audio_ldir(struct call *call, enum sdp_dir dir);
Expand Down Expand Up @@ -916,6 +918,8 @@ int ua_connect_dir(struct ua *ua, struct call **callp,
enum vidmode vmode, enum sdp_dir adir, enum sdp_dir vdir);
void ua_hangup(struct ua *ua, struct call *call,
uint16_t scode, const char *reason);
void ua_reject(struct ua *ua, struct call *call,
uint16_t scode, const char *reason, const char *fmt, ...);
int ua_accept(struct ua *ua, const struct sip_msg *msg);
int ua_answer(struct ua *ua, struct call *call, enum vidmode vmode);
int ua_hold_answer(struct ua *ua, struct call *call, enum vidmode vmode);
Expand Down
33 changes: 33 additions & 0 deletions src/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,39 @@ void call_hangup(struct call *call, uint16_t scode, const char *reason)
}


/**
* Reject an incoming call
*
* @param call Call to reject, or NULL for current call
* @param scode Optional status code
* @param reason Optional reason
* @param fmt Formatted headers
* @param ... Variable arguments
*/
void call_reject(struct call *call, uint16_t scode, const char *reason,
const char *fmt, ...)
{
if (!scode)
scode = 486;

if (!str_isset(reason))
reason = "Busy Here";

info("call: rejecting incoming call from %s (%u %s)\n",
call->peer_uri, scode, reason);

va_list ap;
va_start(ap, fmt);
(void)sipsess_reject(call->sess, scode, reason,
fmt ? "%v" : NULL, fmt, &ap);
va_end(ap);

set_state(call, CALL_STATE_TERMINATED);

call_stream_stop(call);
}


/**
* Send a SIP 183 Session Progress with configured media
*
Expand Down
34 changes: 34 additions & 0 deletions src/ua.c
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,40 @@ void ua_hangup(struct ua *ua, struct call *call,
}


/**
* Reject an incoming call
*
* @param ua User-Agent
* @param call Call to reject, or NULL for current call
* @param scode Optional status code
* @param reason Optional reason
* @param fmt Formatted headers
* @param ... Variable arguments
*/
void ua_reject(struct ua *ua, struct call *call,
uint16_t scode, const char *reason, const char *fmt, ...)
{
if (!ua)
return;

if (!call) {
call = ua_call(ua);
if (!call)
return;
}

va_list ap;
va_start(ap, fmt);
call_reject(call, scode, reason, fmt ? "%v" : NULL, fmt, &ap);
va_end(ap);

bevent_call_emit(UA_EVENT_CALL_CLOSED, call,
reason ? reason : "Rejected by user");

mem_deref(call);
}


/**
* Answer an incoming call
*
Expand Down

0 comments on commit 1f2f3de

Please sign in to comment.