|
|
|
|
@ -19,6 +19,7 @@
|
|
|
|
|
#include "../dm/dm_core.h" |
|
|
|
|
#include "../utun_instance.h" |
|
|
|
|
#include "../chat/chat_event.h" |
|
|
|
|
#include "../chat/chat_setting.h" |
|
|
|
|
#include "../ntp_time.h" |
|
|
|
|
#include "../routing_layer/etcp_router.h" |
|
|
|
|
#include "../routing_layer/route_crypto.h" |
|
|
|
|
@ -206,7 +207,7 @@ static void call_event_incoming(struct call_ctx* ctx, uint64_t group_id, uint64_
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
uint8_t call_phone_status(struct UTUN_INSTANCE* inst) { |
|
|
|
|
if (!inst || inst->phone_status_hidden) return 0; |
|
|
|
|
if (!inst || !(inst->incoming_call_policy & CALL_POLICY_PUBLISH_PHONE)) return 0; |
|
|
|
|
if (inst->phone_state == 2 || call_busy(inst)) return TOPO_FLAG_PHONE_KNOWN | TOPO_FLAG_PHONE_BUSY; |
|
|
|
|
return inst->phone_state == 1 ? TOPO_FLAG_PHONE_KNOWN : 0; |
|
|
|
|
} |
|
|
|
|
@ -231,15 +232,14 @@ static void call_publish_phone_status(struct UTUN_INSTANCE* inst) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void call_set_phone_state(struct UTUN_INSTANCE* inst, int state, int publish, int notify, int reject) { |
|
|
|
|
if (!inst || state < 0 || state > 2) { DEBUG_ERROR(DEBUG_CATEGORY_CALL, "invalid phone state=%d", state); return; } |
|
|
|
|
if (inst->phone_state == state && inst->phone_status_hidden == !publish && inst->phone_notify_enabled == !!notify && |
|
|
|
|
inst->phone_reject_enabled == !!reject) return; |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_CALL, "phone state old=%u new=%d publish=%d notify=%d reject=%d", |
|
|
|
|
inst->phone_state, state, !!publish, !!notify, !!reject); |
|
|
|
|
void call_set_phone_state(struct UTUN_INSTANCE* inst, int state, unsigned policy) { |
|
|
|
|
if (!inst || state < 0 || state > 2 || policy > 31) { |
|
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_CALL, "invalid phone state=%d policy=%u", state, policy); return; |
|
|
|
|
} |
|
|
|
|
if (inst->phone_state == state && inst->incoming_call_policy == policy) return; |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_CALL, "phone state old=%u new=%d policy=%u", inst->phone_state, state, policy); |
|
|
|
|
inst->phone_state = (uint8_t)state; |
|
|
|
|
inst->phone_status_hidden = !publish; inst->phone_notify_enabled = !!notify; |
|
|
|
|
inst->phone_reject_enabled = !!reject; |
|
|
|
|
inst->incoming_call_policy = (uint8_t)policy; |
|
|
|
|
call_publish_phone_status(inst); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -580,8 +580,10 @@ static void call_handle_invite(struct call_ctx* ctx, uint64_t from, uint64_t gro
|
|
|
|
|
DEBUG_WARN(DEBUG_CATEGORY_CALL, "call invite tuple/role mismatch id=%016llx", (unsigned long long)call_id); return; |
|
|
|
|
} |
|
|
|
|
if (s->state == CALL_ST_RINGING || s->state == CALL_ST_WAIT_DECISION) { |
|
|
|
|
if (s->state == CALL_ST_WAIT_DECISION && ctx->inst->phone_state == 2 && ctx->inst->phone_reject_enabled) { |
|
|
|
|
call_end(ctx, s, CALL_REASON_PHONE_BUSY, CALL_SUBCMD_DECLINE); return; |
|
|
|
|
if (s->state == CALL_ST_WAIT_DECISION && ((ctx->inst->incoming_call_policy & CALL_POLICY_BLOCK_CALLS) || |
|
|
|
|
(ctx->inst->phone_state == 2 && (ctx->inst->incoming_call_policy & CALL_POLICY_REJECT_PHONE)))) { |
|
|
|
|
call_end(ctx, s, (ctx->inst->incoming_call_policy & CALL_POLICY_BLOCK_CALLS) ? CALL_REASON_DECLINE : CALL_REASON_PHONE_BUSY, |
|
|
|
|
CALL_SUBCMD_DECLINE); return; |
|
|
|
|
} |
|
|
|
|
if (get_time_tb() - s->started_tb >= CALL_RING_TIMEOUT_TB) { |
|
|
|
|
call_end(ctx, s, CALL_REASON_RING_TIMEOUT, CALL_SUBCMD_CANCEL); return; |
|
|
|
|
@ -640,11 +642,16 @@ static void call_handle_invite(struct call_ctx* ctx, uint64_t from, uint64_t gro
|
|
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_CALL, "%s: session alloc failed id=%016llx", CALL_ID, (unsigned long long)call_id); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (ctx->inst->phone_state == 2 && ctx->inst->phone_reject_enabled) { |
|
|
|
|
if (ctx->inst->incoming_call_policy & CALL_POLICY_BLOCK_CALLS) { |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_CALL, "incoming call blocked by policy id=%016llx", (unsigned long long)call_id); |
|
|
|
|
call_end(ctx, s, CALL_REASON_DECLINE, CALL_SUBCMD_DECLINE); return; |
|
|
|
|
} |
|
|
|
|
if (ctx->inst->phone_state == 2 && (ctx->inst->incoming_call_policy & CALL_POLICY_REJECT_PHONE)) { |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_CALL, "phone busy; incoming call rejected id=%016llx", (unsigned long long)call_id); |
|
|
|
|
call_end(ctx, s, CALL_REASON_PHONE_BUSY, CALL_SUBCMD_DECLINE); return; |
|
|
|
|
} |
|
|
|
|
s->state = ctx->inst->phone_notify_enabled && ctx->inst->phone_state == 2 ? CALL_ST_WAIT_DECISION : CALL_ST_RINGING; |
|
|
|
|
s->state = (ctx->inst->incoming_call_policy & CALL_POLICY_WARN_PHONE) && ctx->inst->phone_state == 2 |
|
|
|
|
? CALL_ST_WAIT_DECISION : CALL_ST_RINGING; |
|
|
|
|
call_publish_phone_status(ctx->inst); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_CALL, "%s: INVITE id=%016llx from=0x%016llx group=0x%016llx (declared group=0x%016llx)", |
|
|
|
|
CALL_ID, (unsigned long long)call_id, (unsigned long long)from, |
|
|
|
|
@ -890,6 +897,8 @@ int call_init(struct UTUN_INSTANCE* inst) {
|
|
|
|
|
if (!ctx) return -1; |
|
|
|
|
ctx->inst = inst; |
|
|
|
|
inst->call = ctx; |
|
|
|
|
inst->incoming_call_policy = (uint8_t)chat_setting_get_int(inst, "incoming_call_policy", CALL_POLICY_PUBLISH_PHONE); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_CALL, "incoming call policy=%u", inst->incoming_call_policy); |
|
|
|
|
|
|
|
|
|
ctx->sessions = queue_new(inst->ua, 256, offsetof(struct call_session, call_id), 8, "call_sessions"); |
|
|
|
|
if (!ctx->sessions) { |
|
|
|
|
|