⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 torture_sdp.c

📁 Sofia SIP is an open-source SIP User-Agent library, compliant with the IETF RFC3261 specification.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * This file is part of the Sofia-SIP package * * Copyright (C) 2005 Nokia Corporation. * * Contact: Pekka Pessi <pekka.pessi@nokia.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * *//**@internal * * @CFILE sdp_torture.c   * * Torture testing sdp module. * * @author Pekka Pessi <Pekka.Pessi@nokia.com> * @author Kai Vehmanen <kai.vehmanen@nokia.com> * * @date Created: Tue Mar  6 18:33:42 2001 ppessi */#include "config.h"#include <stdio.h>#include <string.h>#include <stddef.h>#include <stdlib.h>#include <sofia-sip/su_types.h>#include <sofia-sip/sdp.h>#include <sofia-sip/su_tag.h>#include <sofia-sip/su_tag_io.h>#include <sofia-sip/sdp_tag.h>#define TSTFLAGS tstflags#include <sofia-sip/tstdef.h>int tstflags;char const *name = "torture_sdp.c";FILE *null;static char const e0_msg[] = "foo";static char const e1_msg[] =     "v=1\n"    "s=/sdp_torture\n"    "o=sdp_torture 0 0 IN IP4 0.0.0.0\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 *";static int test_error(void){  su_home_t *home = su_home_create();  sdp_parser_t *parser;  BEGIN();  su_home_check(home); TEST0(home);  TEST_1((parser = sdp_parse(home, e0_msg, sizeof(e0_msg), 0)));  TEST_1(sdp_session(parser) == NULL);  TEST_1(sdp_parsing_error(parser));  sdp_parser_free(parser);  TEST_1((parser = sdp_parse(home, e1_msg, sizeof(e1_msg), 0)));  TEST_1(sdp_session(parser) == NULL);  TEST_1(sdp_parsing_error(parser));  sdp_parser_free(parser);  /* destroy the home objects */  su_home_check(home); su_home_zap(home);  END();}static char const s0_msg[] =     "v=0\n"    "s=/sdp_torture\n"    "o=sdp_torture 0 0 IN IP4 0.0.0.0\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_session(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;  sdp_printer_t *printer;  sdp_media_t *m;  char buffer[512];  tagi_t *lst, *dup;  BEGIN();  su_home_check(home);  TEST_1(home);  su_home_check(home2);  TEST_1(home2);    TEST_1((parser = sdp_parse(home, s0_msg, sizeof(s0_msg), sdp_f_config)));  TEST_1((sdp_src = sdp_session(parser)));  TEST_1(sdp_src->sdp_media);  TEST_1(sdp_src->sdp_media->m_session);  TEST_P(sdp_src->sdp_media->m_session, sdp_src);  /* clone the session using 'home2' */  TEST_1((sdp_target = sdp_session_dup(home2, sdp_src)));  /* Check comparing */  TEST(sdp_session_cmp(sdp_src, sdp_target), 0);  /* check the cloned session */  TEST_1(sdp_target->sdp_subject);  TEST_S(sdp_target->sdp_subject, "/sdp_torture");  strcpy((char*)sdp_target->sdp_subject, "garbage");  TEST_S(sdp_src->sdp_subject, "/sdp_torture");  TEST_1(sdp_target->sdp_origin);  TEST_1(sdp_target->sdp_origin->o_username);  TEST_S(sdp_target->sdp_origin->o_username, "sdp_torture");  strcpy((char*)sdp_target->sdp_origin->o_username, "garbage");  TEST_S(sdp_src->sdp_origin->o_username, "sdp_torture");  TEST_1(m = sdp_target->sdp_media);  TEST_P(m->m_session, sdp_target);  TEST_1(sdp_src->sdp_media->m_session != sdp_target->sdp_media->m_session);  TEST(m->m_type, sdp_media_audio);  TEST_S(m->m_type_name, "audio");  TEST(m->m_port, 0);  TEST(m->m_number_of_ports, 0);  TEST(m->m_proto, sdp_proto_rtp);  TEST_S(m->m_proto_name, "RTP/AVP");  /* FIXME: add more tests */  /* 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);      /* access all cloned data by printing it */  printer = sdp_print(home2, sdp_target, buffer, sizeof(buffer), 0);  if (printer != NULL) {    char const *msg = sdp_message(printer);    if (tstflags & tst_verbatim) {      printf("sdp_torture.c: parsed SDP message:\"%s\".\n", msg);    }          sdp_printer_free(printer);  }  TEST_1(lst = tl_list(SDPTAG_SESSION(sdp_target), TAG_NULL()));  TEST_1(dup = tl_adup(home2, lst));  if (tstflags & tst_verbatim)    tl_print(stdout, "dup:\n", dup);  else    tl_print(null, "dup:\n", dup);  TEST(tl_gets(dup, SDPTAG_SESSION_REF(sdp), TAG_END()), 1);  /* access all copied data by printing it */  printer = sdp_print(home2, sdp, buffer, sizeof(buffer), 0);  if (printer != NULL) {    char const *msg = sdp_message(printer);    if (tstflags & tst_verbatim) {      printf("sdp_torture.c: "	     "SDP message passed through tag list:\n\"%s\".\n", msg);    }    sdp_printer_free(printer);  }  su_free(home2, dup);  tl_vfree(lst);  /* 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"  "s=-\r\n"  "c=IN IP4 172.21.137.44\r\n"  "t=0 0\r\n"  "a=sendonly\r\n"  "m=video 49154 RTP/AVP 96 24 25 26 28 31 32 33 34\r\n"  "a=rtpmap:96 H263-1998/90000\r\n"  "m=audio 49152 RTP/AVP 97 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19\r\n"  "a=rtpmap 97 AMR/8000\r\n"  "a=fmtp:97 mode-set=\"0,1,2,3,4\"\r\n"  "a=ptime:400\r\n";static char const s2_msg[] =   "v=0\r\n"  "o=- 308519342 2 IN IP4 172.168.1.55\r\n"  "s=-\r\n"  "c=IN IP4 172.168.1.55\r\n"  "t=0 0\r\n"  "a=recvonly\r\n"  "m=video 59154 RTP/AVP 96\r\n"  "b=AS:64\r\n"  "a=rtpmap:96 H263-1998/90000\r\n"  "a=framerate:8\r\n"  "a=fmtp:96 QCIF=4\r\n"  "m=audio 59152 RTP/AVP 97\r\n"  "b=AS:8\r\n"  "a=rtpmap:97 AMR/8000\r\n"  "a=fmtp:97 mode-set=\"0\"\r\n"  "a=maxptime:500\r\n";static int test_session2(void){  su_home_t *home = su_home_create();  sdp_session_t const *sdp = NULL;  sdp_parser_t *parser;  sdp_media_t *m;  sdp_rtpmap_t *rm;  BEGIN();  su_home_check(home); TEST_1(home);  TEST_1((parser = sdp_parse(home, s1_msg, sizeof(s1_msg), 0)));  TEST_1((sdp = sdp_session(parser)));  TEST_1(m = sdp->sdp_media);  TEST(m->m_mode, sdp_sendonly);  TEST_P(m->m_session, sdp);  TEST_1(rm = m->m_rtpmaps);  TEST(rm->rm_pt, 96);  TEST_S(rm->rm_encoding, "H263-1998");  TEST(rm->rm_rate, 90000);  {#define RTPMAP(pt, type, rate, params) \    { sizeof(sdp_rtpmap_t), NULL, type, rate, (char *)params, NULL, 1, pt, 0 }    /* rtpmaps for well-known video codecs */    static sdp_rtpmap_t const      sdp_rtpmap_celb = RTPMAP(25, "CelB", 90000, 0),      sdp_rtpmap_jpeg = RTPMAP(26, "JPEG", 90000, 0),      sdp_rtpmap_nv = RTPMAP(28, "nv", 90000, 0),      sdp_rtpmap_h261 = RTPMAP(31, "H261", 90000, 0),      sdp_rtpmap_mpv = RTPMAP(32, "MPV", 90000, 0),      sdp_rtpmap_mp2t = RTPMAP(33, "MP2T", 90000, 0),      sdp_rtpmap_h263 = RTPMAP(34, "H263", 90000, 0);    TEST_1(rm = rm->rm_next);    TEST_S(rm->rm_encoding, ""); TEST(rm->rm_rate, 0);    TEST_1(rm = rm->rm_next);    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_celb, rm), &sdp_rtpmap_celb);    TEST_1(rm = rm->rm_next);    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_jpeg, rm), &sdp_rtpmap_jpeg);    TEST_1(rm = rm->rm_next);    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_nv, rm), &sdp_rtpmap_nv);    TEST_1(rm = rm->rm_next);    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_h261, rm), &sdp_rtpmap_h261);    TEST_1(rm = rm->rm_next);    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_mpv, rm), &sdp_rtpmap_mpv);    TEST_1(rm = rm->rm_next);    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_mp2t, rm), &sdp_rtpmap_mp2t);    TEST_1(rm = rm->rm_next);    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_h263, rm), &sdp_rtpmap_h263);    TEST_1(!rm->rm_next);  }  TEST_1(m = m->m_next);  TEST(m->m_mode, sdp_sendonly);  TEST_P(m->m_session, sdp);  TEST_1(rm = m->m_rtpmaps);  TEST(rm->rm_pt, 97);  TEST_S(rm->rm_encoding, "AMR");  TEST(rm->rm_rate, 8000);  TEST_S(rm->rm_fmtp, "mode-set=\"0,1,2,3,4\"");  {    /* rtpmaps for well-known audio codecs */    static sdp_rtpmap_t const      sdp_rtpmap_pcmu = RTPMAP(0, "PCMU", 8000, "1"),      sdp_rtpmap_1016 = RTPMAP(1, "1016", 8000, "1"),      sdp_rtpmap_g721 = RTPMAP(2, "G721", 8000, "1"),      sdp_rtpmap_gsm = RTPMAP(3, "GSM", 8000, "1"),      sdp_rtpmap_g723 = RTPMAP(4, "G723", 8000, "1"),      sdp_rtpmap_dvi4_8000 = RTPMAP(5, "DVI4", 8000, "1"),      sdp_rtpmap_dvi4_16000 = RTPMAP(6, "DVI4", 16000, "1"),      sdp_rtpmap_lpc = RTPMAP(7, "LPC", 8000, "1"),      sdp_rtpmap_pcma = RTPMAP(8, "PCMA", 8000, "1"),      sdp_rtpmap_g722 = RTPMAP(9, "G722", 8000, "1"),      sdp_rtpmap_l16 = RTPMAP(10, "L16", 44100, "2"),      sdp_rtpmap_l16_stereo = RTPMAP(11, "L16", 44100, "1"),      sdp_rtpmap_qcelp = RTPMAP(12, "QCELP", 8000, "1"),      sdp_rtpmap_cn = RTPMAP(13, "CN", 8000, "1"),      sdp_rtpmap_mpa = RTPMAP(14, "MPA", 90000, 0),      sdp_rtpmap_g728 = RTPMAP(15, "G728", 8000, "1"),      sdp_rtpmap_dvi4_11025 = RTPMAP(16, "DVI4", 11025, "1"),      sdp_rtpmap_dvi4_22050 = RTPMAP(17, "DVI4", 22050, "1"),      sdp_rtpmap_g729 = RTPMAP(18, "G729", 8000, "1"),      sdp_rtpmap_cn_reserved = RTPMAP(19, "CN", 8000, "1");    TEST_1(rm = rm->rm_next);    TEST_1(sdp_rtpmap_match(&sdp_rtpmap_pcmu, rm));    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_pcmu, rm), &sdp_rtpmap_pcmu);    TEST_1(rm = rm->rm_next);    TEST_1(sdp_rtpmap_match(&sdp_rtpmap_1016, rm));    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_1016, rm), &sdp_rtpmap_1016);    TEST_1(rm = rm->rm_next);    TEST_1(sdp_rtpmap_match(&sdp_rtpmap_g721, rm));    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_g721, rm), &sdp_rtpmap_g721);    TEST_1(rm = rm->rm_next);    TEST_1(sdp_rtpmap_match(&sdp_rtpmap_gsm, rm));    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_gsm, rm), &sdp_rtpmap_gsm);    TEST_1(rm = rm->rm_next);    TEST_1(sdp_rtpmap_match(&sdp_rtpmap_g723, rm));    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_g723, rm), &sdp_rtpmap_g723);    TEST_1(rm = rm->rm_next);    TEST_1(sdp_rtpmap_match(&sdp_rtpmap_dvi4_8000, rm));    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_dvi4_8000, rm),	   &sdp_rtpmap_dvi4_8000);    TEST_1(rm = rm->rm_next);    TEST_1(sdp_rtpmap_match(&sdp_rtpmap_dvi4_16000, rm));    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_dvi4_16000, rm),	   &sdp_rtpmap_dvi4_16000);    TEST_1(rm = rm->rm_next);    TEST_1(sdp_rtpmap_match(&sdp_rtpmap_lpc, rm));    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_lpc, rm), &sdp_rtpmap_lpc);    TEST_1(rm = rm->rm_next);    TEST_1(sdp_rtpmap_match(&sdp_rtpmap_pcma, rm));    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_pcma, rm), &sdp_rtpmap_pcma);    TEST_1(rm = rm->rm_next);    TEST_1(sdp_rtpmap_match(&sdp_rtpmap_g722, rm));    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_g722, rm), &sdp_rtpmap_g722);    TEST_1(rm = rm->rm_next);    TEST_1(sdp_rtpmap_match(&sdp_rtpmap_l16, rm));    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_l16, rm), &sdp_rtpmap_l16);    TEST_1(rm = rm->rm_next);    TEST_1(sdp_rtpmap_match(&sdp_rtpmap_l16_stereo, rm));    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_l16_stereo, rm),	   &sdp_rtpmap_l16_stereo);    TEST_1(rm = rm->rm_next);    TEST_1(sdp_rtpmap_match(&sdp_rtpmap_qcelp, rm));    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_qcelp, rm), &sdp_rtpmap_qcelp);    TEST_1(rm = rm->rm_next);    TEST_1(sdp_rtpmap_match(&sdp_rtpmap_cn, rm));    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_cn, rm), &sdp_rtpmap_cn);    TEST_1(rm = rm->rm_next);    TEST_1(sdp_rtpmap_match(&sdp_rtpmap_mpa, rm));    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_mpa, rm), &sdp_rtpmap_mpa);    TEST_1(rm = rm->rm_next);    TEST_1(sdp_rtpmap_match(&sdp_rtpmap_g728, rm));    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_g728, rm), &sdp_rtpmap_g728);    TEST_1(rm = rm->rm_next);    TEST_1(sdp_rtpmap_match(&sdp_rtpmap_dvi4_11025, rm));    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_dvi4_11025, rm),	   &sdp_rtpmap_dvi4_11025);    TEST_1(rm = rm->rm_next);    TEST_1(sdp_rtpmap_match(&sdp_rtpmap_dvi4_22050, rm));    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_dvi4_22050, rm),	   &sdp_rtpmap_dvi4_22050);    TEST_1(rm = rm->rm_next);    TEST_1(sdp_rtpmap_match(&sdp_rtpmap_g729, rm));    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_g729, rm), &sdp_rtpmap_g729);    TEST_1(rm = rm->rm_next);    TEST_1(sdp_rtpmap_match(&sdp_rtpmap_cn_reserved, rm));    TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_cn_reserved, rm),	   &sdp_rtpmap_cn_reserved);    TEST_1(!rm->rm_next);  }    TEST_1((parser = sdp_parse(home, s2_msg, sizeof (s2_msg), 0)));  TEST_1((sdp = sdp_session(parser)));  TEST_1(m = sdp->sdp_media);  TEST(m->m_mode, sdp_recvonly);  TEST_P(m->m_session, sdp);  TEST_1(m->m_rtpmaps);  TEST(m->m_rtpmaps->rm_pt, 96);  TEST_S(m->m_rtpmaps->rm_encoding, "H263-1998");  TEST(m->m_rtpmaps->rm_rate, 90000);  TEST_S(m->m_rtpmaps->rm_fmtp, "QCIF=4");  TEST_1(m = sdp->sdp_media->m_next);  TEST(m->m_mode, sdp_recvonly);  TEST_P(m->m_session, sdp);  TEST_1(m->m_rtpmaps);  TEST(m->m_rtpmaps->rm_pt, 97);  TEST_S(m->m_rtpmaps->rm_encoding, "AMR");  TEST(m->m_rtpmaps->rm_rate, 8000);  TEST_S(m->m_rtpmaps->rm_fmtp, "mode-set=\"0\"");  su_home_unref(home);  END();}static char const s3_msg[] =   "v=0\r\n"  "o=- 2435697 2435697 IN IP4 172.21.137.44\r\n"  "s=-\r\n"  "t=0 0\r\n"  "m=video 49154 RTP/AVP 34\r\n"  "c=IN IP4 172.21.137.44\r\n"  "m=audio 49152 RTP/AVP 8 0\r\n"  "c=IN IP4 172.21.137.44\r\n"  "m=message 0 MSRP/TCP *\r\n"  ;static int test_sanity(void){  su_home_t *home = su_home_create();  sdp_parser_t *parser;  BEGIN();  su_home_check(home); TEST_1(home);  TEST_1((parser = sdp_parse(home, s3_msg, sizeof(s3_msg) - 1, 0)));    TEST_1(sdp_sanity_check(parser) == 0);  su_home_unref(home);  END();}static char const pint_msg[] = 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -