MT#58535 Add support of the rest of opmodes

Synchronize the `enum call_opmode` with the
kamailio module list of operation modes, as well
as with the `enum ng_command`.

This allows to operate based on `call_opmode`
in a more specific way, for example for a proper
setting of From/To tags based on directional flag,
which in its turn is being set using `call_opmode`.

Additionally introduce a macro checker, which covers
all previously non-existent operation mode types
as OP_OTHER, for backwards compatibility in conditions.

Change-Id: Idf4b9d910b81ee24be51008996c3fd02d8336a38
pull/1809/head
Donat Zenichev 1 year ago
parent 36c19b9111
commit bb52ae4ebc

@ -2187,8 +2187,10 @@ static void __update_media_id(struct call_media *media, struct call_media *other
struct call_monologue *ml = media ? media->monologue : NULL;
struct call_monologue *other_ml = other_media->monologue;
if (flags->opmode == OP_OFFER || flags->opmode == OP_OTHER || flags->opmode == OP_PUBLISH
|| flags->opmode == OP_REQUEST)
if (flags->opmode == OP_OFFER ||
flags->opmode == OP_PUBLISH ||
flags->opmode == OP_REQUEST ||
IS_OP_OTHER(flags->opmode))
{
if (!other_media->media_id.s) {
// incoming side: we copy what we received

@ -411,7 +411,7 @@ str *call_query_udp(char **out) {
str fromtag = STR_INIT(out[RE_UDP_DQ_FROMTAG]);
str totag = STR_INIT(out[RE_UDP_DQ_TOTAG]);
c = call_get_opmode(&callid, OP_OTHER);
c = call_get_opmode(&callid, OP_QUERY);
if (!c) {
ilog(LOG_INFO, "[" STR_FORMAT_M "] Call-ID to query not found", STR_FMT_M(&callid));
goto err;
@ -2704,7 +2704,7 @@ const char *call_query_ng(bencode_item_t *input, bencode_item_t *output) {
if (!bencode_dictionary_get_str(input, "call-id", &callid))
return "No call-id in message";
call = call_get_opmode(&callid, OP_OTHER);
call = call_get_opmode(&callid, OP_QUERY);
if (!call)
return "Unknown call-id";
bencode_dictionary_get_str(input, "from-tag", &fromtag);
@ -2736,16 +2736,17 @@ const char *call_list_ng(bencode_item_t *input, bencode_item_t *output) {
static const char *call_recording_common_ng(bencode_item_t *input, bencode_item_t *output,
enum call_opmode opmode,
void (*fn)(bencode_item_t *input, call_t *call))
{
g_auto(sdp_ng_flags) flags;
g_autoptr(call_t) call = NULL;
call_ng_process_flags(&flags, input, OP_OTHER);
call_ng_process_flags(&flags, input, opmode);
if (!bencode_dictionary_get_str(input, "call-id", &flags.call_id))
return "No call-id in message";
call = call_get_opmode(&flags.call_id, OP_OTHER);
call = call_get_opmode(&flags.call_id, opmode);
if (!call)
return "Unknown call-id";
@ -2775,7 +2776,7 @@ static void start_recording_fn(bencode_item_t *input, call_t *call) {
recording_start(call);
}
const char *call_start_recording_ng(bencode_item_t *input, bencode_item_t *output) {
return call_recording_common_ng(input, output, start_recording_fn);
return call_recording_common_ng(input, output, OP_START_RECORDING, start_recording_fn);
}
@ -2783,7 +2784,7 @@ static void pause_recording_fn(bencode_item_t *input, call_t *call) {
recording_pause(call);
}
const char *call_pause_recording_ng(bencode_item_t *input, bencode_item_t *output) {
return call_recording_common_ng(input, output, pause_recording_fn);
return call_recording_common_ng(input, output, OP_PAUSE_RECORDING, pause_recording_fn);
}
@ -2814,7 +2815,7 @@ static void stop_recording_fn(bencode_item_t *input, call_t *call) {
recording_stop(call);
}
const char *call_stop_recording_ng(bencode_item_t *input, bencode_item_t *output) {
return call_recording_common_ng(input, output, stop_recording_fn);
return call_recording_common_ng(input, output, OP_STOP_RECORDING, stop_recording_fn);
}
@ -2883,7 +2884,7 @@ static const char *media_block_match(call_t **call, struct call_monologue **mono
return err;
// for generic ops, handle set-label here if given
if (opmode == OP_OTHER && flags->set_label.len && *monologue) {
if (IS_OP_OTHER(opmode) && flags->set_label.len && *monologue) {
call_str_cpy(*call, &(*monologue)->label, &flags->set_label);
t_hash_table_replace((*call)->labels, &(*monologue)->label, *monologue);
}
@ -2967,7 +2968,7 @@ const char *call_start_forwarding_ng(bencode_item_t *input, bencode_item_t *outp
const char *errstr = NULL;
g_auto(sdp_ng_flags) flags;
errstr = media_block_match(&call, &monologue, &flags, input, OP_OTHER);
errstr = media_block_match(&call, &monologue, &flags, input, OP_START_FORWARDING);
if (errstr)
return errstr;
@ -2996,7 +2997,7 @@ const char *call_stop_forwarding_ng(bencode_item_t *input, bencode_item_t *outpu
const char *errstr = NULL;
g_auto(sdp_ng_flags) flags;
errstr = media_block_match(&call, &monologue, &flags, input, OP_OTHER);
errstr = media_block_match(&call, &monologue, &flags, input, OP_STOP_FORWARDING);
if (errstr)
return errstr;
@ -3104,7 +3105,7 @@ const char *call_block_dtmf_ng(bencode_item_t *input, bencode_item_t *output) {
const char *errstr = NULL;
g_auto(sdp_ng_flags) flags;
errstr = media_block_match(&call, &monologue, &flags, input, OP_OTHER);
errstr = media_block_match(&call, &monologue, &flags, input, OP_BLOCK_DTMF);
if (errstr)
return errstr;
@ -3119,7 +3120,7 @@ const char *call_unblock_dtmf_ng(bencode_item_t *input, bencode_item_t *output)
const char *errstr = NULL;
g_auto(sdp_ng_flags) flags;
errstr = media_block_match(&call, &monologue, &flags, input, OP_OTHER);
errstr = media_block_match(&call, &monologue, &flags, input, OP_UNBLOCK_DTMF);
if (errstr)
return errstr;
@ -3182,7 +3183,7 @@ static const char *call_block_silence_media(bencode_item_t *input, bool on_off,
g_auto(sdp_ng_flags) flags;
bool found_subscriptions = false;
errstr = media_block_match(&call, &monologue, &flags, input, OP_OTHER);
errstr = media_block_match(&call, &monologue, &flags, input, OP_BLOCK_SILENCE_MEDIA);
if (errstr)
return errstr;
@ -3299,7 +3300,7 @@ static const char *call_block_silence_media(bencode_item_t *input, bool on_off,
return "Media flow not found (to-tag not subscribed)";
}
update_init_subscribers(monologue, OP_OTHER);
update_init_subscribers(monologue, OP_BLOCK_SILENCE_MEDIA);
} else {
/* it seems no to-monologue is given and no "all" flag is given as well.
@ -3359,7 +3360,7 @@ static const char *play_media_select_party(call_t **call, monologues_q *monologu
t_queue_init(monologues);
const char *err = media_block_match(call, &monologue, flags, input, OP_OTHER);
const char *err = media_block_match(call, &monologue, flags, input, OP_PLAY_MEDIA);
if (err)
return err;
if (flags->all == ALL_ALL)
@ -3453,7 +3454,7 @@ const char *call_stop_media_ng(bencode_item_t *input, bencode_item_t *output) {
// restore to non-mixing if needed
codec_update_all_source_handlers(monologue, NULL);
update_init_subscribers(monologue, OP_OTHER);
update_init_subscribers(monologue, OP_STOP_MEDIA);
}
bencode_dictionary_add_integer(output, "last-frame-pos", last_frame_pos);

@ -1299,7 +1299,7 @@ static void media_player_run(void *ptr) {
MEDIA_CLEAR(mp->media, BLOCK_EGRESS);
codec_update_all_source_handlers(mp->media->monologue, NULL);
update_init_subscribers(mp->media->monologue, OP_OTHER);
update_init_subscribers(mp->media->monologue, OP_PLAY_MEDIA);
rwlock_unlock_w(&call->master_lock);
}

@ -3009,11 +3009,11 @@ struct packet_stream *print_rtcp(GString *s, struct call_media *media, packet_st
}
if (proto_is_rtp(media->protocol)) {
if (MEDIA_ISSET(media, RTCP_MUX)
&& (flags->opmode == OP_ANSWER || flags->opmode == OP_OTHER
|| flags->opmode == OP_PUBLISH
|| ((flags->opmode == OP_OFFER || flags->opmode == OP_REQUEST)
&& flags->rtcp_mux_require)))
if (MEDIA_ISSET(media, RTCP_MUX) &&
(flags->opmode == OP_ANSWER ||
flags->opmode == OP_PUBLISH ||
((flags->opmode == OP_OFFER || flags->opmode == OP_REQUEST) && flags->rtcp_mux_require) ||
IS_OP_OTHER(flags->opmode)))
{
insert_rtcp_attr(s, ps, flags, sdp_media);
append_attr_to_gstring(s, "rtcp-mux", NULL, flags, media->type_id);

@ -58,10 +58,48 @@ enum call_opmode {
OP_REQUEST,
OP_REQ_ANSWER,
OP_PUBLISH,
OP_DELETE,
OP_QUERY,
OP_LIST,
OP_PING,
OP_STATISTICS,
OP_PLAY_DTMF,
OP_BLOCK_DTMF,
OP_UNBLOCK_DTMF,
OP_BLOCK_MEDIA,
OP_UNBLOCK_MEDIA,
OP_SILENCE_MEDIA,
OP_UNSILENCE_MEDIA,
OP_BLOCK_SILENCE_MEDIA,
OP_UNBLOCK_SILENCE_MEDIA,
OP_PLAY_MEDIA,
OP_STOP_MEDIA,
OP_START_FORWARDING,
OP_STOP_FORWARDING,
OP_SUBSCRIBER_REQ,
OP_SUBSCRIBER_ANS,
OP_UNSUBSCRIBE,
OP_START_RECORDING,
OP_STOP_RECORDING,
OP_PAUSE_RECORDING,
OP_OTHER,
};
#define IS_OP_OTHER(opmode) \
((opmode == OP_DELETE || opmode == OP_QUERY) \
|| (opmode == OP_LIST || opmode == OP_PING) \
|| (opmode == OP_STATISTICS || opmode == OP_PLAY_DTMF) \
|| (opmode == OP_BLOCK_DTMF || opmode == OP_UNBLOCK_DTMF) \
|| (opmode == OP_BLOCK_MEDIA || opmode == OP_UNBLOCK_MEDIA) \
|| (opmode == OP_SILENCE_MEDIA || opmode == OP_UNSILENCE_MEDIA) \
|| (opmode == OP_BLOCK_SILENCE_MEDIA || opmode == OP_UNBLOCK_SILENCE_MEDIA) \
|| (opmode == OP_PLAY_MEDIA || opmode == OP_STOP_MEDIA) \
|| (opmode == OP_START_FORWARDING || opmode == OP_STOP_FORWARDING) \
|| (opmode == OP_SUBSCRIBER_REQ || opmode == OP_SUBSCRIBER_ANS) \
|| (opmode == OP_UNSUBSCRIBE || opmode == OP_START_RECORDING) \
|| (opmode == OP_STOP_RECORDING || opmode == OP_PAUSE_RECORDING) \
|| (opmode == OP_OTHER))
enum call_media_counted {
CMC_INCREMENT = 0,
CMC_DECREMENT,

Loading…
Cancel
Save