@@ -301,23 +301,42 @@ sdp_session_t *soa_sdp_expand_media(su_home_t *home,
301
301
sdp_session_t const * truncated ,
302
302
sdp_session_t const * complete )
303
303
{
304
+ sdp_session_t * tmp_truncated ;
304
305
sdp_session_t * expanded ;
305
- sdp_media_t * * m0 ;
306
- sdp_media_t * const * m1 ;
306
+ sdp_media_t * * mE ;
307
+ sdp_media_t * * mT ;
308
+ sdp_media_t * const * mC ;
307
309
310
+ /* Truncated list that we will be reducing */
311
+ tmp_truncated = sdp_session_dup (home , truncated );
312
+ /* New resulting list */
308
313
expanded = sdp_session_dup (home , truncated );
309
314
310
315
if (expanded ) {
311
- for (m0 = & expanded -> sdp_media , m1 = & complete -> sdp_media ;
312
- * m1 ;
313
- m1 = & (* m1 )-> m_next ) {
314
- if (!* m0 ) {
315
- * m0 = soa_sdp_make_rejected_media (home , * m1 , expanded , 0 );
316
- if (!* m0 )
317
- return NULL ;
316
+ expanded -> sdp_media = NULL ; /* Empty the list of medias */
317
+ mE = & expanded -> sdp_media ; /* Pointer to the beginning of the new list */
318
+
319
+ /* Loop through all items in the complete list to preserve complete list's order */
320
+ for (mC = & complete -> sdp_media ; * mC ; mC = & (* mC )-> m_next ) {
321
+ /* Find the corresponding media in the truncated list */
322
+ if ((mT = sdp_media_exists (tmp_truncated , * mC ))) {
323
+ /* Copy the corresponding media from the truncated list to the new list */
324
+ * mE = sdp_media_dup (home , * mT , expanded );
325
+ if (!* mE )
326
+ return NULL ;
327
+
328
+ /* Remove corresponding media from the truncated list */
329
+ * mT = (* mT )-> m_next ;
330
+ } else {
331
+ /* If the corresponding media was not found in the truncated list, add a rejected media */
332
+ * mE = soa_sdp_make_rejected_media (home , * mC , expanded , 0 );
333
+ if (!* mE )
334
+ return NULL ;
335
+ }
336
+
337
+ /* Prepare pointer of the new list for a new item */
338
+ mE = & (* mE )-> m_next ;
318
339
}
319
- m0 = & (* m0 )-> m_next ;
320
- }
321
340
}
322
341
323
342
return expanded ;
0 commit comments