@@ -1451,19 +1451,29 @@ static const char *media_block_match(call_t **call, struct call_monologue **mono
14511451 return NULL ;
14521452}
14531453
1454- static const char * medias_match (call_t * * call , medias_q * medias ,
1454+ static const char * medias_match (call_q * calls , medias_q * medias ,
14551455 sdp_ng_flags * flags , ng_command_ctx_t * ctx )
14561456{
14571457 call_ng_process_flags (flags , ctx );
14581458
14591459 if (!flags -> call_id .s )
14601460 return "No call-id in message" ;
1461- * call = call_get (& flags -> call_id );
1462- if (!* call )
1463- return "Unknown call-ID" ;
1461+
1462+ g_auto (str_q ) call_ids = TYPED_GQUEUE_INIT ;
1463+ t_queue_push_tail (& call_ids , & flags -> call_id );
1464+
1465+ if (flags -> to_call_id .len )
1466+ t_queue_push_tail (& call_ids , & flags -> to_call_id );
1467+
1468+ * calls = calls_get (& call_ids );
1469+ if (!calls -> length )
1470+ return "Unknown call-ID(s)" ;
1471+
1472+
1473+ call_t * call = calls -> head -> data ;
14641474
14651475 if (flags -> all == ALL_ALL ) {
1466- for (__auto_type l = ( * call ) -> medias .head ; l ; l = l -> next ) {
1476+ for (__auto_type l = call -> medias .head ; l ; l = l -> next ) {
14671477 struct call_media * media = l -> data ;
14681478 if (!media || (media -> monologue -> tagtype != FROM_TAG &&
14691479 media -> monologue -> tagtype != TO_TAG ))
@@ -1478,7 +1488,7 @@ static const char *medias_match(call_t **call, medias_q *medias,
14781488
14791489 /* is a single ml given? */
14801490 struct call_monologue * ml = NULL ;
1481- const char * err = media_match (* call , & ml , flags );
1491+ const char * err = media_match (call , & ml , flags );
14821492 if (err )
14831493 return err ;
14841494 if (ml ) {
@@ -1495,7 +1505,7 @@ static const char *medias_match(call_t **call, medias_q *medias,
14951505 /* handle from-tag list */
14961506 for (__auto_type l = flags -> from_tags .head ; l ; l = l -> next ) {
14971507 str * s = l -> data ;
1498- struct call_monologue * mlf = call_get_monologue (* call , s );
1508+ struct call_monologue * mlf = call_get_monologue (call , s );
14991509 if (!mlf ) {
15001510 ilog (LOG_WARN , "Given from-tag " STR_FORMAT_M " not found" , STR_FMT_M (s ));
15011511 } else {
@@ -2177,14 +2187,14 @@ const char *call_subscribe_request_ng(ng_command_ctx_t *ctx) {
21772187 const char * err = NULL ;
21782188 g_auto (sdp_ng_flags ) flags ;
21792189 char rand_buf [65 ];
2180- g_autoptr ( call_t ) call = NULL ;
2190+ g_auto ( call_q ) calls = TYPED_GQUEUE_INIT ;
21812191 g_auto (medias_q ) mq = TYPED_GQUEUE_INIT ;
21822192 g_auto (str ) sdp_out = STR_NULL ;
21832193 parser_arg output = ctx -> resp ;
21842194 const ng_parser_t * parser = ctx -> parser_ctx .parser ;
21852195
21862196 /* get source monologue */
2187- err = medias_match (& call , & mq , & flags , ctx );
2197+ err = medias_match (& calls , & mq , & flags , ctx );
21882198 if (err )
21892199 return err ;
21902200
@@ -2206,6 +2216,8 @@ const char *call_subscribe_request_ng(ng_command_ctx_t *ctx) {
22062216 rand_hex_str (flags .to_tag .s , flags .to_tag .len / 2 );
22072217 }
22082218
2219+ g_autoptr (call_t ) call = t_queue_pop_head (& calls );
2220+
22092221 struct call_monologue * dest_ml = call_get_or_create_monologue (call , & flags .to_tag );
22102222
22112223 int ret = monologue_subscribe_request (& mq , dest_ml , & flags );
@@ -2372,8 +2384,6 @@ const char *call_unsubscribe_ng(ng_command_ctx_t *ctx) {
23722384
23732385static const char * call_inject_ng (ng_command_ctx_t * ctx , bool start ) {
23742386 g_auto (sdp_ng_flags ) flags ;
2375- g_autoptr (call_t ) call = NULL ;
2376- g_autoptr (call_t ) call2 = NULL ;
23772387 parser_arg input = ctx -> req ;
23782388 const ng_parser_t * parser = ctx -> parser_ctx .parser ;
23792389
@@ -2394,29 +2404,29 @@ static const char *call_inject_ng(ng_command_ctx_t *ctx, bool start) {
23942404 if (!parser -> dict_get_str (input , "source-call-id" , & source_call_id ))
23952405 source_call_id = flags .call_id ;
23962406
2397- call = call_get ( & flags . call_id ) ;
2398- if (! call )
2399- return "Unknown call-ID" ;
2407+ g_auto ( str_q ) call_ids = TYPED_GQUEUE_INIT ;
2408+ t_queue_push_tail ( & call_ids , & flags . call_id );
2409+ t_queue_push_tail ( & call_ids , & source_call_id ) ;
24002410
2401- call2 = call_get2 (call , & source_call_id );
2402- if (!call2 )
2403- return "Unknown source call-ID" ;
2411+ g_auto (call_q ) calls = calls_get (& call_ids );
2412+ if (!calls .length )
2413+ return "Unknown call-ID(s)" ;
2414+
2415+ g_autoptr (call_t ) call = calls_merge (& calls );
2416+ if (!call )
2417+ return "Failed to merge two calls into one" ;
24042418
24052419 struct call_monologue * dst_ml = call_get_monologue (call , & flags .to_tag );
24062420 if (!dst_ml )
24072421 return "To-tag not found" ;
24082422
2409- struct call_monologue * src_ml = call_get_monologue (call2 , & source_tag );
2423+ struct call_monologue * src_ml = call_get_monologue (call , & source_tag );
24102424 if (!src_ml )
24112425 return "Source-tag not found" ;
24122426
24132427 if (src_ml == dst_ml )
24142428 return "Trying to inject to self" ;
24152429
2416- if (!call_merge (call , call2 ))
2417- return "Failed to merge two calls into one" ;
2418- call2 = NULL ;
2419-
24202430 int ret = start
24212431 ? monologue_inject_start (src_ml , dst_ml , & flags )
24222432 : monologue_inject_stop (src_ml , dst_ml , & flags );
@@ -2438,33 +2448,24 @@ const char *call_inject_stop_ng(ng_command_ctx_t *ctx) {
24382448
24392449const char * call_connect_ng (ng_command_ctx_t * ctx ) {
24402450 g_auto (sdp_ng_flags ) flags ;
2441- g_autoptr (call_t ) call = NULL ;
2442- g_autoptr (call_t ) call2 = NULL ;
2451+ g_auto (call_q ) calls = TYPED_GQUEUE_INIT ;
24432452 g_auto (medias_q ) medias = TYPED_GQUEUE_INIT ;
24442453
2445- const char * err = medias_match (& call , & medias , & flags , ctx );
2454+ const char * err = medias_match (& calls , & medias , & flags , ctx );
24462455 if (err )
24472456 return err ;
24482457
24492458 if (!flags .to_tag .s )
24502459 return "No to-tag in message" ;
24512460
2452- if (flags .to_call_id .len ) {
2453- call2 = call_get2 (call , & flags .to_call_id );
2454- if (!call2 )
2455- return "Unknown to-tag call-ID" ;
2456- }
2457- else
2458- call2 = obj_get (call );
2461+ g_autoptr (call_t ) call = calls_merge (& calls );
2462+ if (!call )
2463+ return "Failed to merge two calls into one (tag collision)" ;
24592464
2460- struct call_monologue * dest_ml = call_get_or_create_monologue (call2 , & flags .to_tag );
2465+ struct call_monologue * dest_ml = call_get_or_create_monologue (call , & flags .to_tag );
24612466 if (!dest_ml )
24622467 return "To-tag not found" ;
24632468
2464- if (!call_merge (call , call2 ))
2465- return "Failed to merge two calls into one (tag collision)" ;
2466- call2 = NULL ; // reference released
2467-
24682469 dialogue_connect (& medias , dest_ml , & flags );
24692470
24702471 call_unlock_release_update (& call );
0 commit comments