diff --git a/libs/sofia-sip/.update b/libs/sofia-sip/.update index 935113b8cf..e7d19e5f3d 100644 --- a/libs/sofia-sip/.update +++ b/libs/sofia-sip/.update @@ -1 +1 @@ -Mon May 12 13:37:30 EDT 2008 +Mon May 12 14:41:23 EDT 2008 diff --git a/libs/sofia-sip/libsofia-sip-ua/soa/soa_static.c b/libs/sofia-sip/libsofia-sip-ua/soa/soa_static.c index 42e8518d28..bee4f4b949 100644 --- a/libs/sofia-sip/libsofia-sip-ua/soa/soa_static.c +++ b/libs/sofia-sip/libsofia-sip-ua/soa/soa_static.c @@ -731,10 +731,11 @@ int soa_sdp_upgrade(soa_session_t *ss, o_media = su_zalloc(home, (Ns + 1) * (sizeof *o_media)); u_media = su_zalloc(home, (Nu + 1) * (sizeof *u_media)); r_media = su_zalloc(home, (Nr + 1) * (sizeof *r_media)); + if (!s_media || !o_media || !u_media || !r_media) + return -1; um = sdp_media_dup_all(home, user->sdp_media, session); - - if (!s_media || !u_media || !r_media || !um) + if (!um && user->sdp_media) return -1; u2s = su_alloc(home, (Nu + 1) * sizeof(*u2s)); @@ -1022,9 +1023,13 @@ int soa_sdp_mode_set(sdp_session_t const *user, for (j = 0, um = user->sdp_media; j != s2u[i]; um = um->m_next, j++) assert(um); if (um == NULL) { + if (dryrun) + return 1; + else + retval = 1; sm->m_rejected = 1; sm->m_mode = sdp_inactive; - retval = 1; + sm->m_port = 0; continue; } @@ -1054,10 +1059,11 @@ int soa_sdp_mode_set(sdp_session_t const *user, } } - if (sm->m_mode != (unsigned)(recv_mode | send_mode)) - retval = 1; - - if (!dryrun) { + if (sm->m_mode != (unsigned)(recv_mode | send_mode)) { + if (dryrun) + return 1; + else + retval = 1; sm->m_mode = recv_mode | send_mode; } } @@ -1166,7 +1172,8 @@ static int offer_answer_step(soa_session_t *ss, *local0 = *local, local = local0; SU_DEBUG_7(("soa_static(%p, %s): %s\n", (void *)ss, by, "upgrade with local description")); - soa_sdp_upgrade(ss, tmphome, local, user, NULL, &u2s, &s2u); + if (soa_sdp_upgrade(ss, tmphome, local, user, NULL, &u2s, &s2u) < 0) + goto internal_error; break; case generate_answer: /* Upgrade local SDP based on remote SDP */ @@ -1178,7 +1185,8 @@ static int offer_answer_step(soa_session_t *ss, *local0 = *local, local = local0; SU_DEBUG_7(("soa_static(%p, %s): %s\n", (void *)ss, by, "upgrade with remote description")); - soa_sdp_upgrade(ss, tmphome, local, user, remote, &u2s, &s2u); + if (soa_sdp_upgrade(ss, tmphome, local, user, remote, &u2s, &s2u) < 0) + goto internal_error; } break; case process_answer: diff --git a/libs/sofia-sip/libsofia-sip-ua/soa/test_soa.c b/libs/sofia-sip/libsofia-sip-ua/soa/test_soa.c index 2b1a334f2f..fe76d96516 100644 --- a/libs/sofia-sip/libsofia-sip-ua/soa/test_soa.c +++ b/libs/sofia-sip/libsofia-sip-ua/soa/test_soa.c @@ -1311,6 +1311,159 @@ int test_media_replace(struct context *ctx) } +int test_media_removal(struct context *ctx) +{ + BEGIN(); + int n; + + soa_session_t *a, *b; + + char const *offer = NONE, *answer = NONE; + isize_t offerlen = (isize_t)-1, answerlen = (isize_t)-1; + + sdp_session_t const *a_sdp, *b_sdp; + sdp_media_t const *m; + + char const a_caps[] = + "v=0\r\n" + "o=left 219498671 2 IN IP4 127.0.0.2\r\n" + "c=IN IP4 127.0.0.2\r\n" + "m=audio 5008 RTP/AVP 0 8\r\n" + ; + + char const b_caps[] = + "v=0\n" + "m=audio 5004 RTP/AVP 0 8\n" + "a=rtpmap:96 G7231/8000\n" + "a=rtpmap:97 G729/8000\n"; + + TEST_1(a = soa_create("static", ctx->root, ctx)); + TEST_1(b = soa_create("static", ctx->root, ctx)); + + TEST(soa_set_user_sdp(a, 0, a_caps, strlen(a_caps)), 1); + TEST(soa_set_user_sdp(b, 0, b_caps, strlen(b_caps)), 1); + + TEST_1(soa_set_params(b, SOATAG_RTP_MISMATCH(0), + SOATAG_ORDERED_USER(1), + TAG_END())); + + n = soa_generate_offer(a, 1, test_completed); TEST(n, 0); + n = soa_get_local_sdp(a, NULL, &offer, &offerlen); TEST(n, 1); + TEST_1(offer != NULL && offer != NONE); + n = soa_set_remote_sdp(b, 0, offer, offerlen); TEST(n, 1); + n = soa_get_local_sdp(b, NULL, &answer, &answerlen); TEST(n, 0); + n = soa_generate_answer(b, test_completed); TEST(n, 0); + n = soa_get_local_sdp(b, &b_sdp, &answer, &answerlen); TEST(n, 1); + TEST_1(answer != NULL && answer != NONE); + n = soa_set_remote_sdp(a, 0, answer, -1); TEST(n, 1); + n = soa_process_answer(a, test_completed); TEST(n, 0); + + TEST_1(soa_is_complete(b)); + TEST(soa_activate(b, NULL), 0); + + TEST_1(soa_is_complete(a)); + TEST(soa_activate(a, NULL), 0); + + TEST(soa_is_audio_active(a), SOA_ACTIVE_SENDRECV); + TEST(soa_is_remote_audio_active(a), SOA_ACTIVE_SENDRECV); + + /* ---------------------------------------------------------------------- */ + /* Re-O/A: remove media stream */ + TEST(soa_set_user_sdp(b, 0, "v=0", -1), 1); + + n = soa_generate_offer(a, 1, test_completed); TEST(n, 0); + n = soa_get_local_sdp(a, &a_sdp, &offer, &offerlen); TEST(n, 1); + TEST_1(offer != NULL && offer != NONE); + n = soa_set_remote_sdp(b, 0, offer, offerlen); TEST(n, 1); + n = soa_generate_answer(b, test_completed); TEST(n, 0); + n = soa_get_local_sdp(b, &b_sdp, &answer, &answerlen); TEST(n, 1); + TEST_1(m = b_sdp->sdp_media); TEST_1(m->m_rejected); + TEST_1(answer != NULL && answer != NONE); + n = soa_set_remote_sdp(a, 0, answer, -1); TEST(n, 1); + n = soa_process_answer(a, test_completed); TEST(n, 0); + n = soa_get_local_sdp(a, &a_sdp, NULL, NULL); TEST(n, 1); + TEST_1(m = a_sdp->sdp_media); TEST_1(m->m_rejected); + + TEST_1(soa_is_complete(b)); + TEST(soa_activate(b, NULL), 0); + + TEST_1(soa_is_complete(a)); + TEST(soa_activate(a, NULL), 0); + + TEST(soa_is_audio_active(a), SOA_ACTIVE_REJECTED); + TEST(soa_is_remote_audio_active(a), SOA_ACTIVE_REJECTED); + + TEST_VOID(soa_terminate(a, NULL)); + TEST_VOID(soa_terminate(b, NULL)); + + TEST_VOID(soa_destroy(a)); + TEST_VOID(soa_destroy(b)); + + /* ---------------------------------------------------------------------- */ + + TEST_1(a = soa_create("static", ctx->root, ctx)); + TEST_1(b = soa_create("static", ctx->root, ctx)); + + TEST(soa_set_user_sdp(a, 0, a_caps, strlen(a_caps)), 1); + TEST(soa_set_user_sdp(b, 0, b_caps, strlen(b_caps)), 1); + + n = soa_generate_offer(a, 1, test_completed); TEST(n, 0); + n = soa_get_local_sdp(a, NULL, &offer, &offerlen); TEST(n, 1); + TEST_1(offer != NULL && offer != NONE); + n = soa_set_remote_sdp(b, 0, offer, offerlen); TEST(n, 1); + n = soa_get_local_sdp(b, NULL, &answer, &answerlen); TEST(n, 0); + n = soa_generate_answer(b, test_completed); TEST(n, 0); + n = soa_get_local_sdp(b, &b_sdp, &answer, &answerlen); TEST(n, 1); + TEST_1(answer != NULL && answer != NONE); + n = soa_set_remote_sdp(a, 0, answer, -1); TEST(n, 1); + n = soa_process_answer(a, test_completed); TEST(n, 0); + + TEST_1(soa_is_complete(b)); + TEST(soa_activate(b, NULL), 0); + + TEST_1(soa_is_complete(a)); + TEST(soa_activate(a, NULL), 0); + + TEST(soa_is_audio_active(a), SOA_ACTIVE_SENDRECV); + TEST(soa_is_remote_audio_active(a), SOA_ACTIVE_SENDRECV); + + /* ---------------------------------------------------------------------- */ + /* Re-O/A: offerer remove media stream from user sdp */ + TEST(soa_set_user_sdp(a, 0, "v=0", -1), 1); + + n = soa_generate_offer(a, 1, test_completed); TEST(n, 0); + n = soa_get_local_sdp(a, &a_sdp, &offer, &offerlen); TEST(n, 1); + TEST_1(m = a_sdp->sdp_media); TEST_1(m->m_rejected); + TEST_1(offer != NULL && offer != NONE); + n = soa_set_remote_sdp(b, 0, offer, offerlen); TEST(n, 1); + n = soa_generate_answer(b, test_completed); TEST(n, 0); + n = soa_get_local_sdp(b, &b_sdp, &answer, &answerlen); TEST(n, 1); + TEST_1(m = b_sdp->sdp_media); TEST_1(m->m_rejected); + TEST_1(answer != NULL && answer != NONE); + n = soa_set_remote_sdp(a, 0, answer, -1); TEST(n, 1); + n = soa_process_answer(a, test_completed); TEST(n, 0); + n = soa_get_local_sdp(a, &a_sdp, NULL, NULL); TEST(n, 1); + TEST_1(m = a_sdp->sdp_media); TEST_1(m->m_rejected); + + TEST_1(soa_is_complete(b)); + TEST(soa_activate(b, NULL), 0); + + TEST_1(soa_is_complete(a)); + TEST(soa_activate(a, NULL), 0); + + TEST(soa_is_audio_active(a), SOA_ACTIVE_REJECTED); + TEST(soa_is_remote_audio_active(a), SOA_ACTIVE_REJECTED); + + TEST_VOID(soa_terminate(a, NULL)); + TEST_VOID(soa_terminate(b, NULL)); + + TEST_VOID(soa_destroy(a)); + TEST_VOID(soa_destroy(b)); + + END(); +} + + int test_media_reject(struct context *ctx) { BEGIN(); @@ -1482,7 +1635,6 @@ int test_media_replace2(struct context *ctx) n = soa_get_local_sdp(b, &b_sdp, &offer, &offerlen); TEST(n, 1); TEST_1(offer != NULL && offer != NONE); n = soa_set_remote_sdp(a, 0, offer, offerlen); TEST(n, 1); - printf("offer 2:\n%s", offer); TEST_1(soa_set_params(a, SOATAG_RTP_MISMATCH(0), SOATAG_USER_SDP_STR(a_caps2), TAG_END()) > 0); @@ -1490,7 +1642,6 @@ int test_media_replace2(struct context *ctx) n = soa_generate_answer(a, test_completed); TEST(n, 0); n = soa_get_local_sdp(a, &a_sdp, &answer, &answerlen); TEST(n, 1); TEST_1(answer != NULL && answer != NONE); - printf("answer 2:\n%s", answer); n = soa_set_remote_sdp(b, 0, answer, -1); TEST(n, 1); n = soa_process_answer(b, test_completed); TEST(n, 0); n = soa_get_local_sdp(b, &b_sdp, NULL, NULL); TEST(n, 1); @@ -1730,6 +1881,7 @@ int main(int argc, char *argv[]) retval |= test_static_offer_answer(ctx); SINGLE_FAILURE_CHECK(); retval |= test_codec_selection(ctx); SINGLE_FAILURE_CHECK(); retval |= test_media_replace(ctx); SINGLE_FAILURE_CHECK(); + retval |= test_media_removal(ctx); SINGLE_FAILURE_CHECK(); retval |= test_media_reject(ctx); SINGLE_FAILURE_CHECK(); retval |= test_asynch_offer_answer(ctx); SINGLE_FAILURE_CHECK();