for (ab = a->sdp_bandwidths, bb = b->sdp_bandwidths;
ab || bb;
- ab = ab->b_next, bb = bb->b_next)
- if ((rv = sdp_bandwidth_cmp(a->sdp_bandwidths, b->sdp_bandwidths)))
+ ab = (ab ? ab->b_next : NULL), bb = (bb ? bb->b_next : NULL))
+ if ((rv = sdp_bandwidth_cmp(ab, bb)))
return rv;
if ((rv = sdp_time_cmp(a->sdp_time, b->sdp_time)))
return rv;
for (aa = a->sdp_attributes, ba = b->sdp_attributes;
- aa || bb;
- aa = aa->a_next, ba = ba->a_next)
+ aa || ba;
+ aa = (aa ? aa->a_next : NULL), ba = (ba ? ba->a_next : NULL))
if ((rv = sdp_attribute_cmp(aa, ba)))
return rv;
for (am = a->sdp_media, bm = b->sdp_media;
am || bm;
- am = am->m_next, bm = bm->m_next)
+ am = (am ? am->m_next : NULL), bm = (bm ? bm->m_next : NULL))
if ((rv = sdp_media_cmp(am, bm)))
return rv;
if ((a != NULL) != (b != NULL))
return (a != NULL) < (b != NULL) ? -1 : 1;
+ if (!a || !b)
+ return -1;
+
if (a->b_modifier != b->b_modifier)
return a->b_modifier < b->b_modifier ? -1 : 1;
if (a->b_modifier == sdp_bw_x &&
if ((a != NULL) != (b != NULL))
return (a != NULL) < (b != NULL) ? -1 : 1;
+ if (!a || !b)
+ return -1;
+
if (a->r_interval != b->r_interval)
return a->r_interval < b->r_interval ? -1 : 1;
if (a->r_duration != b->r_duration)
if ((a != NULL) != (b != NULL))
return (a != NULL) < (b != NULL) ? -1 : 1;
+ if (!a || !b)
+ return -1;
+
if (a->rm_pt != b->rm_pt)
return a->rm_pt < b->rm_pt ? -1 : 1;
if ((rv = (a != NULL) - (b != NULL)))
return rv;
+ if (!a || !b)
+ return -1;
+
if (a->m_type != b->m_type)
return a->m_type < b->m_type ? -1 : 1;
if (a->m_type == sdp_media_x)
for (arm = a->m_rtpmaps, brm = b->m_rtpmaps;
arm || brm;
- arm = arm->rm_next, brm = brm->rm_next)
+ arm = (arm ? arm->rm_next : NULL), brm = (brm ? brm->rm_next : NULL))
if ((rv = sdp_rtpmap_cmp(arm, brm)))
return rv;
for (ac = a->m_connections, bc = b->m_connections;
ac || bc;
- ac = ac->c_next, bc = bc->c_next)
+ ac = (ac ? ac->c_next : NULL), bc = (bc ? bc->c_next : NULL))
if ((rv = sdp_connection_cmp(ac, bc)))
return rv;
for (ab = a->m_bandwidths, bb = b->m_bandwidths;
ab || bb;
- ab = ab->b_next, bb = bb->b_next)
+ ab = (ab ? ab->b_next : NULL), bb = (bb ? bb->b_next : NULL))
if ((rv = sdp_bandwidth_cmp(ab, bb)))
return rv;
for (aa = a->m_attributes, ba = b->m_attributes;
aa || ba;
- aa = aa->a_next, ba = ba->a_next)
+ aa = (aa ? aa->a_next : NULL), ba = (ba ? ba->a_next : NULL))
if ((rv = sdp_attribute_cmp(aa, ba)))
return rv;
END();
}
+
+static char const s0_cmp_msg[] =
+"v=0\n"
+"s=/sdp_torture\n"
+"o=sdp_torture 0 0 IN IP4 0.0.0.0\n"
+"b=AS:64\n"
+"b=CRASH:32\n"
+"m=audio 0 RTP/AVP 96 97 98 10 99 8 0\n"
+"a=rtpmap:96 X-AMR-WB/16000\n"
+"a=rtpmap:97 X-AMR/8000\n"
+"a=rtpmap:98 GSM-EFR/8000\n"
+"a=rtpmap:10 L16/16000\n"
+"a=rtpmap:99 G723/8000\n"
+"a=rtpmap:8 PCMA/8000\n"
+"a=rtpmap:0 PCMU/8000\n"
+"m=video 0 *\n"
+"m=* 0 RTP/AVP *\n"
+;
+
+static char const s1_cmp_msg[] =
+"v=0\n"
+"s=/sdp_torture\n"
+"o=sdp_torture 0 0 IN IP4 0.0.0.0\n"
+"b=AS:64\n"
+"m=audio 0 RTP/AVP 96 97 98 10 99 8 0\n"
+"a=rtpmap:96 X-AMR-WB/16000\n"
+"a=rtpmap:97 X-AMR/8000\n"
+"a=rtpmap:98 GSM-EFR/8000\n"
+"a=rtpmap:10 L16/16000\n"
+"a=rtpmap:99 G723/8000\n"
+"a=rtpmap:8 PCMA/8000\n"
+"a=rtpmap:0 PCMU/8000\n"
+"m=video 0 *\n"
+"m=* 0 RTP/AVP *\n"
+;
+
+static int test_sdp_session_cmp(void)
+{
+ su_home_t *home = su_home_create(), *home2 = su_home_create();
+ sdp_session_t *sdp_src, *sdp_target;
+ sdp_session_t const *sdp = NULL;
+ sdp_parser_t *parser, *parser2;
+
+ BEGIN();
+
+ su_home_check(home);
+ TEST_1(home);
+
+ su_home_check(home2);
+ TEST_1(home2);
+
+ TEST_1((parser = sdp_parse(home, s0_cmp_msg, sizeof(s0_cmp_msg), sdp_f_config)));
+ TEST_1((sdp_src = sdp_session(parser)));
+
+ TEST_1((parser2 = sdp_parse(home2, s1_cmp_msg, sizeof(s1_cmp_msg), sdp_f_config)));
+ TEST_1((sdp_target = sdp_session(parser2)));
+
+ /* Check comparing */
+ TEST(sdp_session_cmp(sdp_src, sdp_target), 1);
+
+ /* frees all data created by the parser including 'sdp_src' */
+ sdp_parser_free(parser);
+
+ /* destroy the first home instance */
+ su_home_check(home);
+ su_home_unref(home);
+
+ /* frees all data created by the parser including 'sdp_target' */
+ sdp_parser_free(parser2);
+
+ /* destroy the second home object */
+ su_home_check(home2);
+ su_home_unref(home2);
+
+ END();
+}
+
static char const s1_msg[] =
"v=0\r\n"
"o=- 2435697 2435697 IN IP4 172.21.137.44\r\n"
null = fopen("/dev/null", "ab");
retval |= test_error(); fflush(stdout);
+ retval |= test_sdp_session_cmp(); fflush(stdout);
retval |= test_session(); fflush(stdout);
retval |= test_session2(); fflush(stdout);
retval |= test_pint(); fflush(stdout);