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

📄 torture_sdp.c

📁 Sofia SIP is an open-source SIP User-Agent library, compliant with the IETF RFC3261 specification.
💻 C
📖 第 1 页 / 共 2 页
字号:
  "v=0\r\n"  "o=- 2353687640 2353687640 IN IP4 128.3.4.5\r\n"  "s=marketing\r\n"  "e=john.jones.3@chinet.net\r\n"  "c=TN RFC2543 +1-201-406-4090\r\n"  "t=2353687640 0\r\n"  "m=audio 1 voice -\r\n"  ;static char const pint_torture_msg[] =   "v=0\r\n"  "o=- 2353687640 2353687640 IN IP4 128.3.4.5\r\n"  "s=marketing\r\n"  "c= TN RFC2543 123\r\n"  "a=phone-context:+97252\r\n"  "t=2353687640 0\r\n"  "m= text 1  fax plain\r\n"  "a=fmtp:plain  spr:fi6MeoclEjaF3EDfYHlkqx1zn8A1lMoiJFUHpQ5Xo\r\n"  ;static int test_pint(void){  su_home_t *home = su_home_create();  sdp_parser_t *parser;  sdp_session_t *sdp;  sdp_printer_t *printer;  char const *m;  BEGIN();  su_home_check(home); TEST_1(home);  TEST_1((parser = sdp_parse(home, pint_msg, sizeof(pint_msg) - 1, sdp_f_anynet)));  TEST_1((sdp = sdp_session(parser)));  TEST_1((printer = sdp_print(home, sdp, NULL, -1, 0)));  TEST_1((m = sdp_message(printer)));  TEST_S(m, pint_msg);  TEST(sdp_message_size(printer), sizeof(pint_msg) - 1);  TEST_1((parser = sdp_parse(home, pint_torture_msg, sizeof(pint_torture_msg) - 1,			     sdp_f_anynet)));  TEST_1((sdp = sdp_session(parser)));    su_home_check(home);  su_home_unref(home);  END();}static sdp_list_t const l0[1] = {{ sizeof(l0), NULL, "foo" }};static sdp_list_t const l1[1] = {{ sizeof(l1), (sdp_list_t *)l0, "bar" }};/** Test list things */int test_list(void){  su_home_t *home = su_home_create();  sdp_list_t *l;  BEGIN();  su_home_check(home);  TEST_1(home);  TEST_1((l = sdp_list_dup(home, l0)));  TEST_P(l->l_next, NULL);  TEST_S(l->l_text, "foo");  TEST_1((l = sdp_list_dup(home, l1)));  TEST_1(l->l_next != NULL);  TEST_1(l->l_next->l_next == NULL);  TEST_S(l->l_text, "bar");  TEST_S(l->l_next->l_text, "foo");  su_home_check(home);  su_home_unref(home);  END();}staticsdp_rtpmap_t const rm0[1] =   {{       sizeof(rm0), NULL, "AMR", 8000, "1",      "mode-set=4,5,6 interleaving crc use-redundancy=1",      0, 96, 0  }};staticsdp_rtpmap_t const rm1[1] =   {{       sizeof(rm1), (sdp_rtpmap_t *)rm0, "PCMA", 8000, "1",      NULL,      1, 8, 0,  }};/** Test rtpmap-related things */int test_rtpmap(void){  su_home_t *home = su_home_create();  sdp_rtpmap_t *rm;  BEGIN();  su_home_check(home);  TEST_1(home);  TEST_1((rm = sdp_rtpmap_dup(home, rm0)));  TEST_P(rm->rm_next, NULL);  TEST_S(rm->rm_encoding, "AMR");  TEST_S(rm->rm_params, "1");  TEST(rm->rm_pt, 96);  TEST_S(rm->rm_fmtp, "mode-set=4,5,6 interleaving crc use-redundancy=1");  TEST_1((rm = sdp_rtpmap_dup(home, rm1)));  TEST_1(rm->rm_next != NULL);  TEST_1(rm->rm_next->rm_next == NULL);  TEST_S(rm->rm_encoding, "PCMA");  TEST_S(rm->rm_params, "1");  TEST(rm->rm_pt, 8);  su_home_check(home);  su_home_unref(home);  END();}static sdp_attribute_t const a0[1] =  {{ sizeof(a0), NULL, "foo", "2"}};static sdp_attribute_t const a1[1] =   {{ sizeof(a1), (sdp_attribute_t *)a0, "bar", "1" }};static int test_attribute(void){  su_home_t *home = su_home_create();  sdp_attribute_t *a, *a_new, *list, *replaced;  BEGIN();  su_home_check(home);  TEST_1(home);  TEST_1((a = sdp_attribute_dup(home, a0)));  TEST_P(a->a_next, NULL);  TEST_S(a->a_name, "foo");  TEST_S(a->a_value, "2");  strcpy((char *)a->a_name, "FOO");  TEST_S(a0->a_name, "foo");  strcpy((char *)a->a_value, "X");  TEST_S(a0->a_value, "2");  TEST_1((a = sdp_attribute_dup(home, a1)));  TEST_1(a->a_next != NULL);  TEST_1(a->a_next->a_next == NULL);  TEST_S(a->a_name, "bar");  TEST_S(a->a_value, "1");  TEST_S(a->a_next->a_name, "foo");  TEST_S(a->a_next->a_value, "2");  list = a;  TEST_P(sdp_attribute_remove(&list, NULL), NULL);  TEST_P(sdp_attribute_remove(&list, "kuik"), NULL);  TEST_P(sdp_attribute_remove(&list, "barf"), NULL);  TEST_P(sdp_attribute_remove(&list, "bar"), a);  TEST_1(a_new = sdp_attribute_dup(home, a));  replaced = (void *)-1;  TEST(sdp_attribute_replace(&list, NULL, &replaced), -1);  TEST_P(replaced, NULL);  TEST(sdp_attribute_replace(&list, a, &replaced), 0);   TEST_P(replaced, NULL);  TEST(sdp_attribute_replace(&list, a_new, &replaced), 1);   TEST_P(replaced, a);  TEST_VOID(sdp_attribute_append(&list, a));   TEST_P(sdp_attribute_remove(&list, "bAr"), a_new);  TEST_P(sdp_attribute_remove(&list, "BAR"), a);  TEST_P(sdp_attribute_remove(&list, "bar"), NULL);  su_home_check(home);  su_home_unref(home);  END();}static int test_connection(void){  BEGIN();  END();}static char const media_msg[] = "v=0\n""s=/sdp_torture\n""o=sdp_torture 0 0 IN IP4 1.2.3.4\n""c=IN IP4 1.2.3.4\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 RTP/AVP 31\n""c=IN IP4 2.3.4.5\n";static sdp_media_t const m0[1] =  {{ sizeof(m0),      NULL,      NULL,     sdp_media_audio,     NULL,      1234,      5,      sdp_proto_udp,     "udp",  }};static int test_media(void){  su_home_t *home = su_home_create();  sdp_media_t *media;  sdp_session_t *sdp;  sdp_parser_t *parser;  BEGIN();  su_home_check(home);  TEST_1(home);  TEST_1((parser = sdp_parse(home, media_msg, sizeof(media_msg), 0)));  TEST_1((sdp = sdp_session(parser)));  TEST_1((media = sdp_media_dup(home, m0, sdp)));  /* Check comparing */  TEST(sdp_media_cmp(media, m0), 0);  TEST(media->m_type, sdp_media_audio);  TEST(media->m_port, 1234);  TEST(media->m_number_of_ports, 5);  TEST_P(media->m_session, sdp);  /* FIXME: add more tests */  media->m_next = (sdp_media_t *)m0;  TEST_1((media = sdp_media_dup_all(home, media, sdp)));  TEST_P(media->m_connections, NULL);  TEST_1(media->m_next);  TEST_P(media->m_next->m_connections, NULL);  TEST_P(sdp_media_connections(media), sdp->sdp_connection);  TEST_P(sdp_media_connections(media->m_next), sdp->sdp_connection);  sdp_parser_free(parser);  su_home_check(home);  su_home_unref(home);  END();}static int test_origin(void){  BEGIN();  END();}static int test_bandwidth(void){  BEGIN();  END();}static char const t_msg[] ="v=0\n""s=/sdp_torture\n""o=sdp_torture 1 1 IN IP4 1.2.3.4\n""c=IN IP4 1.2.3.4\n""t=3309789956 3309793556\n""t=3309789956 3309793557\n""t=3309789955 3309793557\n""r=604800 3600 0 90000\n""z=2882844526 -1h 2898848070 0\n""t=3309789955 3309793557\n""r=604800 3600 0 90000\n""z=2882844526 -1h 2898848070 0\n"  ;static int test_time(void){  sdp_parser_t *parser;  sdp_session_t *sdp;  sdp_time_t *t, t1[1], t2[1];  BEGIN();  TEST_1((parser = sdp_parse(NULL, t_msg, sizeof(t_msg), 0)));  TEST_1((sdp = sdp_session(parser)));  TEST_1((t = sdp->sdp_time)); *t1 = *t; t1->t_next = NULL; *t2 = *t1;  TEST_1(sdp_time_cmp(t1, t1) == 0);  TEST_1(sdp_time_cmp(t1, t2) == 0);  TEST_1(sdp_time_cmp(t2, t1) == 0);  TEST_1((t = t->t_next)); *t1 = *t; t1->t_next = NULL;   TEST_1(sdp_time_cmp(t1, t2) > 0);  TEST_1(sdp_time_cmp(t2, t1) < 0);  TEST_1((t = t->t_next)); *t2 = *t; t2->t_next = NULL;   TEST_1(t2->t_zone); TEST_1(t2->t_repeat);  TEST_1(sdp_time_cmp(t2, t2) == 0);  TEST_1(sdp_time_cmp(t1, t2) > 0);  TEST_1(sdp_time_cmp(t2, t1) < 0);  TEST_1((t = t->t_next)); *t1 = *t; t1->t_next = NULL;   TEST_1(t1->t_zone); TEST_1(t1->t_repeat);  TEST_1(sdp_time_cmp(t1, t1) == 0);  TEST_1(sdp_time_cmp(t2, t2) == 0);  TEST_1(sdp_time_cmp(t1, t2) == 0);    sdp_parser_free(parser);  END();}static int test_key(void){  BEGIN();  END();}#include <time.h>#include <stdlib.h>static int test_build(void){  sdp_session_t *sdp, *dup;  sdp_origin_t *o;  sdp_time_t *t;  sdp_connection_t *c;  sdp_media_t *m, *m1;  sdp_rtpmap_t *rm;  sdp_list_t *l, *l1;  sdp_attribute_t *a;  su_home_t *home;  sdp_printer_t *printer;  char const *data;  BEGIN();  srand(time(NULL));  TEST_1(home = su_home_create());  /*    * Allocate an SDP structure using su_salloc().   * su_salloc() puts memory area size to the beginning of structure    * and zeroes rest of the structure.   */  TEST_1(sdp = su_salloc(home, sizeof(*sdp)));  TEST_1(o = su_salloc(home, sizeof(*o)));  TEST_1(t = su_salloc(home, sizeof(*t)));  TEST_1(c = su_salloc(home, sizeof(*c)));  TEST_1(m = su_salloc(home, sizeof(*m)));  TEST_1(rm = su_salloc(home, sizeof(*rm)));  sdp->sdp_origin = o;  sdp->sdp_time = t;		/* zero time is fine for SIP */  sdp->sdp_connection = c;  sdp->sdp_media = m;  o->o_username = "test";  o->o_id = rand();  o->o_version = 1;  o->o_address = c;    c->c_nettype = sdp_net_in;  c->c_addrtype = sdp_addr_ip4;  c->c_address = "172.21.40.40";  m->m_session = sdp;  m->m_type = sdp_media_audio; m->m_type_name = "audio";  m->m_port = 5004;  m->m_proto = sdp_proto_rtp; m->m_proto_name = "RTP/AVP";  m->m_rtpmaps = rm;    rm->rm_predef = 1;  rm->rm_pt = 8;  rm->rm_encoding = "PCMA";   rm->rm_rate = 8000;  TEST_1(m1 = su_salloc(home, sizeof(*m1)));  TEST_1(l = su_salloc(home, sizeof(*l)));  TEST_1(l1 = su_salloc(home, sizeof(*l1)));  TEST_1(a = su_salloc(home, sizeof(*a)));  m->m_next = m1;  m1->m_session = sdp;  m1->m_type = sdp_media_message; m->m_type_name = "message";  m1->m_port = 5060;  m1->m_proto = sdp_proto_tcp; m->m_proto_name = "TCP";  m1->m_format = l;  m1->m_attributes = a;  l->l_text = "sip";  l->l_next = l1;  l1->l_text = "cpim";  a->a_name = "user";  a->a_value = "chat-81273845";  TEST_1(dup = sdp_session_dup(home, sdp));  TEST_1(printer = sdp_print(home, dup, NULL, 0, 0));  TEST_1(data = sdp_message(printer));  if (tstflags & tst_verbatim)    printf("sdp_torture.c: built SDP message:\"%s\".\n", data);  sdp_printer_free(printer);  END();}void usage(int exitcode){  fprintf(stderr, "usage: %s [-v] [-a]\n", name);  exit(exitcode);}int main(int argc, char *argv[]){  int retval = 0;  int i;  for (i = 1; argv[i]; i++) {    if (strcmp(argv[i], "-v") == 0)      tstflags |= tst_verbatim;    else if (strcmp(argv[i], "-a") == 0)      tstflags |= tst_abort;    else      usage(1);  }  null = fopen("/dev/null", "ab");  retval |= test_error(); fflush(stdout);  retval |= test_session(); fflush(stdout);  retval |= test_session2(); fflush(stdout);  retval |= test_pint(); fflush(stdout);  retval |= test_sanity(); fflush(stdout);  retval |= test_list(); fflush(stdout);  retval |= test_rtpmap(); fflush(stdout);  retval |= test_origin(); fflush(stdout);  retval |= test_connection(); fflush(stdout);  retval |= test_bandwidth(); fflush(stdout);  retval |= test_time(); fflush(stdout);  retval |= test_key(); fflush(stdout);  retval |= test_attribute(); fflush(stdout);  retval |= test_media(); fflush(stdout);  retval |= test_build(); fflush(stdout);  return retval;}

⌨️ 快捷键说明

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