Skip to content

Commit

Permalink
MT#61368 add OP_CONNECT
Browse files Browse the repository at this point in the history
Change-Id: Ie07cb5bd139f5e039c5736009ae18733850b0c55
  • Loading branch information
rfuchs committed Dec 23, 2024
1 parent bce7dcf commit 3af3e79
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 7 deletions.
54 changes: 54 additions & 0 deletions daemon/call_interfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -1997,6 +1997,9 @@ void call_ng_main_flags(const ng_parser_t *parser, str *key, parser_arg value, h
case CSH_LOOKUP("to-label"):
out->to_label = s;
break;
case CSH_LOOKUP("to-call-id"):
out->to_call_id = s;
break;
case CSH_LOOKUP("to-tag"):
out->to_tag = s;
break;
Expand Down Expand Up @@ -4007,6 +4010,57 @@ const char *call_unsubscribe_ng(ng_command_ctx_t *ctx) {
}


const char *call_connect_ng(ng_command_ctx_t *ctx) {
g_auto(sdp_ng_flags) flags;
g_autoptr(call_t) call = NULL;
g_autoptr(call_t) call2 = NULL;

call_ng_process_flags(&flags, ctx);

if (!flags.call_id.s)
return "No call-id in message";
if (!flags.from_tag.s)
return "No from-tag in message";
if (!flags.to_tag.s)
return "No to-tag in message";

if (flags.to_call_id.s) {
call_get2_ret_t ret = call_get2(&call, &call2, &flags.call_id, &flags.to_call_id);
if (ret == CG2_NF1)
return "Unknown call-ID";
if (ret == CG2_NF2)
return "Unknown to-tag call-ID";
}
else {
call = call_get(&flags.call_id);
if (!call)
return "Unknown call-ID";
}

struct call_monologue *src_ml = call_get_or_create_monologue(call, &flags.from_tag);
if (!src_ml)
return "From-tag not found";

struct call_monologue *dest_ml = call_get_or_create_monologue(call2 ?: call, &flags.to_tag);
if (!dest_ml)
return "To-tag not found";

if (src_ml == dest_ml)
return "Trying to connect to self"; // XXX should this be allowed?

if (call2) {
if (!call_merge(call, &call2))
return "Failed to merge two calls into one";
}

dialogue_connect(src_ml, dest_ml, &flags);

call_unlock_release_update(&call);

return NULL;
}


void call_interfaces_free(void) {
if (info_re) {
pcre2_code_free(info_re);
Expand Down
7 changes: 7 additions & 0 deletions daemon/control_ng.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const char *ng_command_strings[OP_COUNT] = {
"block silence media", "unblock silence media",
"publish", "subscribe request",
"subscribe answer", "unsubscribe",
"connect"
};
const char *ng_command_strings_esc[OP_COUNT] = {
"ping", "offer", "answer", "delete", "query", "list",
Expand All @@ -56,6 +57,7 @@ const char *ng_command_strings_esc[OP_COUNT] = {
"block_silence_media", "unblock_silence_media",
"publish", "subscribe_request",
"subscribe_answer", "unsubscribe",
"connect"
};
const char *ng_command_strings_short[OP_COUNT] = {
"Ping", "Offer", "Answer", "Delete", "Query", "List",
Expand All @@ -65,6 +67,7 @@ const char *ng_command_strings_short[OP_COUNT] = {
"PlayDTMF", "Stats", "SlnMedia", "UnslnMedia",
"BlkSlnMedia", "UnblkSlnMedia",
"Pub", "SubReq", "SubAns", "Unsub",
"Conn"
};

typedef struct ng_ctx {
Expand Down Expand Up @@ -841,6 +844,10 @@ static void control_ng_process_payload(ng_ctx *hctx, str *reply, str *data, cons
command_ctx.opmode = OP_UNSUBSCRIBE;
errstr = call_unsubscribe_ng(&command_ctx);
break;
case CSH_LOOKUP("connect"):
command_ctx.opmode = OP_CONNECT;
errstr = call_connect_ng(&command_ctx);
break;
default:
errstr = "Unrecognized command";
}
Expand Down
18 changes: 18 additions & 0 deletions docs/ng_control_protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Currently the following commands are defined:
* subscribe request
* subscribe answer
* unsubscribe
* connect

The response dictionary must contain at least one key called `result`.
The value can be either `ok` or `error`.
Expand Down Expand Up @@ -2322,3 +2323,20 @@ forwarding will start to the endpoint given in the answer SDP.

This message is a counterpart to `subsscribe answer` to stop an established
subscription. The subscription to be stopped is identified by the `to-tag`.

## `connect` Message

This message makes it posible to directly connect the media of two call parties
without the need for a full offer/answer exchange. The required keys are
`call-id` to identify the call, and `from-tag and `to-tag` to identify the two
call parties to connect. The media will be connected in the same way as it
would through an offer/answer exchange. Transcoding will automaticaly be
engaged if needed.

It's also possible to connect two call parties from two different calls
(different call IDs). To do so, the second call ID must be given as
`to-call-id`, with the given `to-tag` then being one of the call parties from
that second call. Internally, both calls will be merged into a single call
object, with both call IDs then corresponding to the same call. This will be
visible in certain statistics (e.g. two call IDs appearing in the list, but
only one call being counted).
2 changes: 2 additions & 0 deletions include/call_interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct sdp_ng_flags {
enum message_type message_type;
unsigned int code;
str call_id;
str to_call_id;
str from_tag;
str to_tag;
str via_branch;
Expand Down Expand Up @@ -303,6 +304,7 @@ const char *call_publish_ng(ng_command_ctx_t *, const char *,
const char *call_subscribe_request_ng(ng_command_ctx_t *);
const char *call_subscribe_answer_ng(ng_command_ctx_t *);
const char *call_unsubscribe_ng(ng_command_ctx_t *);
const char *call_connect_ng(ng_command_ctx_t *);

void add_media_to_sub_list(subscription_q *q, struct call_media *media, struct call_monologue *ml);

Expand Down
1 change: 1 addition & 0 deletions include/control_ng.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum ng_opmode {
OP_SUBSCRIBE_REQ,
OP_SUBSCRIBE_ANS,
OP_UNSUBSCRIBE,
OP_CONNECT,

OP_COUNT, // last, number of elements
OP_OTHER = OP_COUNT // alias to above
Expand Down
Loading

0 comments on commit 3af3e79

Please sign in to comment.