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

📄 torture_sip.c

📁 Internet Phone, Chat, Conferencing
💻 C
📖 第 1 页 / 共 5 页
字号:
  sip_error_info_t     sip_error_info[1] = { SIP_ERROR_INFO_INIT() };  sip_warning_t        sip_warning[1] = { SIP_WARNING_INIT() };		         sip_mime_version_t   sip_mime_version[1] = { SIP_MIME_VERSION_INIT() };  sip_content_type_t   sip_content_type[1] = { SIP_CONTENT_TYPE_INIT() };  sip_content_encoding_t sip_content_encoding[1] = { SIP_CONTENT_ENCODING_INIT() };  sip_content_disposition_t sip_content_disposition[1] = { SIP_CONTENT_DISPOSITION_INIT() };  sip_content_length_t sip_content_length[1] = { SIP_CONTENT_LENGTH_INIT() };  BEGIN();  home = su_home_create();  msg = read_message(MSG_DO_EXTRACT_COPY,     "INVITE sip:John_Smith@tct.hut.fi SIP/2.0\r\n"    "To: John Smith <sip:John_Smith@tct.hut.fi:5066;user=ip;maddr=131.228.16.2>\r\n"    "  ; tag = deadbeef\r\n"    "From: http://www.cs.columbia.edu\r\n"    "Call-ID: 0ha0isndaksdj@10.1.2.3\r\n"    "CSeq : 8 INVITE\r\n"    "Via: SIP/2.0/UDP 135.180.130.133\r\n"    "Route: <sip:1@a;lr>, sip:2@b;lr=2, <sip:3@c;lr=3>\r\n"    "Route: <sip:1@d;lr=4>\r\n"    "Route: sip:2@e;lr=5, <sip:3@f;lr=6>\r\n"    "Route: <sip:1@g;lr=7>, <sip:2@h>;lr=8\r\n"    "Content-Type: application/sdp\r\n"    "Contact: Joe Bob Briggs <urn:ipaddr:122.1.2.3> ; bar=\"foo baa\", sip:kuik@foo.invalid\r\n"    "Via: SIP/2.0/UDP [aa:bb::1]:5061\r\n"    "\r\n"    "v=0\r\n"    "o=mhandley 29739 7272939 IN IP4 126.5.4.3\r\n"    "c=IN IP4 135.180.130.88\r\n"    "m=audio 492170 RTP/AVP 0 12\r\n"    "m=video 3227 RTP/AVP 31\r\n"    "a=rtpmap:31 LPC\r\n");  sip = sip_object(msg);  TEST_1(home && msg && sip);  TEST_1(sip_is_request((sip_header_t *)sip->sip_request));  TEST_1(sip->sip_via); TEST_1(sip->sip_via->v_next);  TEST_1(sip->sip_via->v_next->v_next == NULL);  TEST_1(sip_sanity_check(sip) == 0);  TEST_1(r = sip->sip_route); TEST_1(r->r_common->h_data);   TEST_1(r = r->r_next); TEST_1(r->r_common->h_data);   TEST_1(r = r->r_next); TEST_1(r->r_common->h_data);   TEST_1(r = r->r_next); TEST_1(r->r_common->h_data);   TEST_1(r = r->r_next); TEST_1(r->r_common->h_data);   TEST_1(r = r->r_next); TEST_1(r->r_common->h_data);   TEST_1(r = r->r_next); TEST_1(r->r_common->h_data);   TEST_1(r = r->r_next); TEST_1(r->r_common->h_data);   TEST_1(!r->r_next);  TEST_1(r = sip_route_fix(sip->sip_route)); TEST_1(!r->r_common->h_data);  TEST_1(r = r->r_next); TEST_1(!r->r_common->h_data);  TEST_1(r = r->r_next); TEST_1(!r->r_common->h_data);   TEST_1(r = r->r_next); TEST_1(r->r_common->h_data);   TEST_1(r = r->r_next); TEST_1(!r->r_common->h_data);   TEST_1(r = r->r_next); TEST_1(!r->r_common->h_data);   TEST_1(r = r->r_next); TEST_1(!r->r_common->h_data);   TEST_1(r = r->r_next); TEST_1(!r->r_common->h_data);   TEST_1(!r->r_next);  /* Quiet lots of warnings */  #define _msg_header_offset msg_header_offset  #define msg_header_offset(msg, sip, h) \    _msg_header_offset(msg, (msg_pub_t *)sip, (msg_header_t *)h)  TEST(msg_header_offset(msg, sip, sip_request), &sip->sip_request);  TEST(msg_header_offset(msg, sip, sip_status), &sip->sip_status);  TEST(msg_header_offset(msg, sip, sip_unknown), &sip->sip_unknown);  TEST(msg_header_offset(msg, sip, sip_separator), &sip->sip_separator);  TEST(msg_header_offset(msg, sip, sip_payload), &sip->sip_payload);  TEST(msg_header_offset(msg, sip, sip_via), &sip->sip_via);  TEST(msg_header_offset(msg, sip, sip_route), &sip->sip_route);  TEST(msg_header_offset(msg, sip, sip_record_route), &sip->sip_record_route);  // TEST(msg_header_offset(msg, sip, sip_hide), &sip->sip_hide);  TEST(msg_header_offset(msg, sip, sip_max_forwards), &sip->sip_max_forwards);  TEST(msg_header_offset(msg, sip, sip_from), &sip->sip_from);  TEST(msg_header_offset(msg, sip, sip_to), &sip->sip_to);  TEST(msg_header_offset(msg, sip, sip_call_id), &sip->sip_call_id);  TEST(msg_header_offset(msg, sip, sip_cseq), &sip->sip_cseq);  TEST(msg_header_offset(msg, sip, sip_contact), &sip->sip_contact);						  TEST(msg_header_offset(msg, sip, sip_expires), &sip->sip_expires);  TEST(msg_header_offset(msg, sip, sip_date), &sip->sip_date);  TEST(msg_header_offset(msg, sip, sip_retry_after), &sip->sip_retry_after);  TEST(msg_header_offset(msg, sip, sip_timestamp), &sip->sip_timestamp);  TEST(msg_header_offset(msg, sip, sip_subject), &sip->sip_subject);  TEST(msg_header_offset(msg, sip, sip_priority), &sip->sip_priority);		           		  // TEST(msg_header_offset(msg, sip, sip_also), &sip->sip_also);  TEST(msg_header_offset(msg, sip, sip_call_info), &sip->sip_call_info);  TEST(msg_header_offset(msg, sip, sip_organization), &sip->sip_organization);  TEST(msg_header_offset(msg, sip, sip_server), &sip->sip_server);  TEST(msg_header_offset(msg, sip, sip_user_agent), &sip->sip_user_agent);  TEST(msg_header_offset(msg, sip, sip_in_reply_to), &sip->sip_in_reply_to);		           		  TEST(msg_header_offset(msg, sip, sip_accept), &sip->sip_accept);  TEST(msg_header_offset(msg, sip, sip_accept_encoding), &sip->sip_accept_encoding);  TEST(msg_header_offset(msg, sip, sip_accept_language), &sip->sip_accept_language);  TEST(msg_header_offset(msg, sip, sip_session_expires), &sip->sip_session_expires);  TEST(msg_header_offset(msg, sip, sip_min_se), &sip->sip_min_se);        TEST(msg_header_offset(msg, sip, sip_allow), &sip->sip_allow);  TEST(msg_header_offset(msg, sip, sip_require), &sip->sip_require);  TEST(msg_header_offset(msg, sip, sip_proxy_require), &sip->sip_proxy_require);  TEST(msg_header_offset(msg, sip, sip_supported), &sip->sip_supported);  TEST(msg_header_offset(msg, sip, sip_unsupported), &sip->sip_unsupported);#if SIP_HAVE_ENCRYPTION  TEST(msg_header_offset(msg, sip, sip_encryption), &sip->sip_encryption);#endif#if SIP_HAVE_RESPONSE_KEY  TEST(msg_header_offset(msg, sip, sip_response_key), &sip->sip_response_key);#endif  TEST(msg_header_offset(msg, sip, sip_proxy_authenticate), &sip->sip_proxy_authenticate);  TEST(msg_header_offset(msg, sip, sip_proxy_authorization), &sip->sip_proxy_authorization);  TEST(msg_header_offset(msg, sip, sip_authorization), &sip->sip_authorization);  TEST(msg_header_offset(msg, sip, sip_www_authenticate), &sip->sip_www_authenticate);  TEST(msg_header_offset(msg, sip, sip_error_info), &sip->sip_error_info);  TEST(msg_header_offset(msg, sip, sip_warning), &sip->sip_warning);		         TEST(msg_header_offset(msg, sip, sip_mime_version), &sip->sip_mime_version);  TEST(msg_header_offset(msg, sip, sip_content_type), &sip->sip_content_type);  TEST(msg_header_offset(msg, sip, sip_content_encoding), &sip->sip_content_encoding);  TEST(msg_header_offset(msg, sip, sip_content_disposition), &sip->sip_content_disposition);  TEST(msg_header_offset(msg, sip, sip_content_length), &sip->sip_content_length);  TEST(sip_request_class->hc_params, 0);  TEST(sip_status_class->hc_params, 0);  TEST(sip_unknown_class->hc_params, 0);  TEST(sip_separator_class->hc_params, 0);  TEST(sip_payload_class->hc_params, 0);  TEST(sip_via_class->hc_params, offsetof(sip_via_t, v_params));  TEST(sip_route_class->hc_params, offsetof(sip_route_t, r_params));  TEST(sip_record_route_class->hc_params,        offsetof(sip_record_route_t, r_params));  // TEST(sip_hide_class->hc_params, 0);  TEST(sip_max_forwards_class->hc_params, 0);  TEST(sip_from_class->hc_params, offsetof(sip_from_t, a_params));  TEST(sip_to_class->hc_params, offsetof(sip_to_t, a_params));  TEST(sip_call_id_class->hc_params, 0);  TEST(sip_cseq_class->hc_params, 0);  TEST(sip_contact_class->hc_params, offsetof(sip_contact_t, m_params));						  TEST(sip_expires_class->hc_params, 0);  TEST(sip_date_class->hc_params, 0);  TEST(sip_retry_after_class->hc_params,        offsetof(sip_retry_after_t, af_params));  TEST(sip_timestamp_class->hc_params, 0);  TEST(sip_subject_class->hc_params, 0);  TEST(sip_priority_class->hc_params, 0);		           		  // TEST(sip_also_class->hc_params, 0);  TEST(sip_call_info_class->hc_params,        offsetof(sip_call_info_t, ci_params));  TEST(sip_organization_class->hc_params, 0);  TEST(sip_server_class->hc_params, 0);  TEST(sip_user_agent_class->hc_params, 0);  TEST(sip_in_reply_to_class->hc_params,        offsetof(sip_in_reply_to_t, k_items));  TEST(sip_accept_class->hc_params, offsetof(sip_accept_t, ac_params));  TEST(sip_accept_encoding_class->hc_params,        offsetof(sip_accept_encoding_t, aa_params));  TEST(sip_accept_language_class->hc_params,        offsetof(sip_accept_language_t, aa_params));     TEST(sip_session_expires_class->hc_params, offsetof(sip_session_expires_t, x_params));  TEST(sip_min_se_class->hc_params, offsetof(sip_min_se_t, min_params));  TEST(sip_allow_class->hc_params, offsetof(sip_allow_t, k_items));  TEST(sip_require_class->hc_params, offsetof(sip_require_t, k_items));  TEST(sip_proxy_require_class->hc_params,        offsetof(sip_proxy_require_t, k_items));  TEST(sip_supported_class->hc_params,        offsetof(sip_supported_t, k_items));  TEST(sip_unsupported_class->hc_params,        offsetof(sip_unsupported_t, k_items));#if SIP_HAVE_ENCRYPTION  TEST(sip_encryption_class->hc_params,      offsetof(sip_encryption_t, au_params));#endif#if SIP_HAVE_RESPONSE_KEY  TEST(sip_response_key_class->hc_params,        offsetof(sip_response_key_t, au_params));#endif  TEST(sip_proxy_authenticate_class->hc_params,         offsetof(sip_proxy_authenticate_t, au_params));  TEST(sip_proxy_authorization_class->hc_params,         offsetof(sip_proxy_authorization_t, au_params));  TEST(sip_authorization_class->hc_params,         offsetof(sip_authorization_t, au_params));  TEST(sip_www_authenticate_class->hc_params,         offsetof(sip_www_authenticate_t, au_params));  TEST(sip_error_info_class->hc_params,        offsetof(sip_error_info_t, ei_params));  TEST(sip_warning_class->hc_params, 0);		         TEST(sip_mime_version_class->hc_params, 0);  TEST(sip_content_type_class->hc_params,        offsetof(sip_content_type_t, c_params));  TEST(sip_content_encoding_class->hc_params,        offsetof(sip_content_encoding_t, k_items));  TEST(sip_content_disposition_class->hc_params,        offsetof(sip_content_disposition_t, cd_params));  TEST(sip_content_length_class->hc_params, 0);  msg_destroy(msg);  su_home_destroy(home), su_free(NULL, home);  END();}static int count(sip_common_t *h){  sip_header_t *sh = (sip_header_t *)h;  unsigned n;    for (n = 0; sh; sh = sh->sh_next)    n++;    return n;}static int len(sip_common_t *h){  sip_header_t *sh = (sip_header_t *)h;  unsigned n;  for (n = 0; sh; sh = sh->sh_next) {    if (n) n +=2;    n += sip_header_field_e(NULL, 0, sh, 0);  }  return n;}static int sip_header_test(void){  msg_t *msg;  sip_t *sip;  su_home_t *home;  void const *x;  sip_via_t *v, *v0;  tagi_t const *tl, *tl0;  BEGIN();  home = su_home_create();  TEST_1(msg = read_message(MSG_DO_EXTRACT_COPY,     "MESSAGE sip:John_Smith@tct.hut.fi SIP/2.0\r\n"    "To: John Smith <sip:John_Smith@tct.hut.fi:5066;user=ip;maddr=131.228.16.2>\r\n"    "  ; tag = deadbeef\r\n"    "From:h<http://www.cs.columbia.edu>\r\n"    "Call-ID: 0ha0isndaksdj@10.1.2.3\r\n"    "CSeq : 8 MESSAGE\r\n"    "Via: SIP/2.0/UDP 135.180.130.133;received=defa:daf::00:12\r\n"    "Via: SIP/2.0/TCP 135.180.130.131;branch=deadbeef.barf;ttl=3;hidden,,"    "SIP/2.0/UDP\r\n 135.180.130.131:5061;received=[defa::00:12]\r\n"    "Contact: Joe Bob Briggs <urn:ipaddr:122.1.2.3> ; bar=\042foo baa\042, <sip:kuik@foo.invalid>, sip:barf\r\n"    "Via: SIP/2.0/UDP [aa:bb::1]:5061\r\n"    "Record-Route: Test Element <sip:[defa::00:12]:5061>;param=12+1\r\n"    "Record-Route: sip:135.180.130.133,<sip:135.180.130.131;transport=tcp>,\r\n"    "\t,Test Element <sip:[defa::00:12]:5061>;param=12+1\r\n"    "Path: Test <sip:[defa::00:12]:5061>\r\n"    "Service-Route: Test <sip:[defa::00:12]:5061>\r\n"    "Route: ,\r\n"    "Unknown-Extension: hip\r\n"    "Hide: hop\r\n"    "Max-Forwards: 12\r\n"    "Min-Expires: 150\r\n"    "Timestamp: 10.010 0.000100\r\n"    "Content-Type: application/sdp\r\n"    "\r\n"    "v=0\r\n"    "o=mhandley 29739 7272939 IN IP4 126.5.4.3\r\n"    "c=IN IP4 135.180.130.88\r\n"    "m=audio 492170 RTP/AVP 0 12\r\n"    "m=video 3227 RTP/AVP 31\r\n"    "a=rtpmap:31 LPC\r\n"));  TEST_1(sip = sip_object(msg));  TEST(count(sip->sip_request->rq_common), 1);  TEST(count(sip->sip_to->a_common), 1);  TEST(count(sip->sip_from->a_common), 1);  TEST(count(sip->sip_cseq->cs_common), 1);  TEST(count(sip->sip_call_id->i_common), 1);  TEST(count(sip->sip_via->v_common), 4);  TEST(count(sip->sip_contact->m_common), 3);  TEST(count(sip->sip_content_type->c_common), 1);  TEST(count(sip->sip_route->r_common), 0);  TEST(count(sip->sip_record_route->r_common), 4);  //TEST(count(sip->sip_hide->g_common), 1);  TEST(count(sip->sip_unknown->un_common), 2);  TEST(count(sip->sip_error->er_common), 1);  TEST(count(sip->sip_max_forwards->mf_common), 1);  TEST(count(sip->sip_min_expires->me_common), 1);  TEST(count(sip->sip_timestamp->ts_common), 1);  TEST_S(sip->sip_contact->m_display, "Joe Bob Briggs");  TEST_1(sip->sip_contact->m_next->m_display != NULL);  TEST_S(sip->sip_contact->m_next->m_display, "");  TEST_1(sip->sip_contact->m_next->m_next->m_display == NULL);  TEST(sip->sip_max_forwards->mf_count, 12);  TEST(sip->sip_min_expires->me_delta, 150);  TEST_1(sip->sip_from->a_display);  TEST_S(sip->sip_from->a_display, "h");  v0 = sip->sip_via;  //TEST_1(m = sip_contact_create_from_via(home, v0, "joe"));  //TEST_S(m->m_url->url_user, "joe");  TEST_1(v = sip_via_copy(home, v0));  TEST(len(v->v_common), len(v0->v_common));  for (; v && v0; v = v->v_next, v0 = v0->v_next) {    if (v->v_params)      TEST_1(v->v_params != v0->v_params);    if (v->v_branch)      TEST_1(v->v_branch == v0->v_branch);  }  TEST_1(v == NULL && v0 == NULL);    v0 = sip->sip_via;    TEST_1(v = sip_via_dup(home, v0));  TEST(len(v->v_common), len(v0->v_common));  for (; v && v0; v = v->v_next, v0 = v0->v_next) {    if (v->v_params)      TEST_1(v->v_params != v0->v_params);    if (v->v_branch)      TEST_1(v->v_branch != v0->v_branch);  }  TEST_1(v == NULL && v0 == NULL);  TEST(sip_add_dup(msg, sip, (sip_header_t *)sip->sip_max_forwards), 0);  /* Max-Forwards is last header? */  TEST(sip->sip_max_forwards, sip->sip_content_type->c_common->h_succ);  TEST(sip_to_tag(home, sip->sip_to, sip->sip_to->a_tag), 0);  TEST(sip_to_tag(home, sip->sip_to, "tag=deadbeef"), 0);  TEST(sip_to_tag(home, sip->sip_to, "foofaa"), -1);  msg_header_remove(msg, (msg_pub_t *)sip, (msg_header_t *)sip->sip_payload);  TEST(sip_add_tl(msg, sip, 		  SIPTAG_FROM(SIP_NONE),		  SIPTAG_VIA(SIP_NONE),		  SIPTAG_VIA_STR("SIP/2.0/SCTP foo.bar.com:5060;branch=foo"),		  SIPTAG_TO_STR("<sip:foo@bar>"),		  SIPTAG_HEADER_STR("Authorization: Basic foobar\n"				    "Priority:\n urgent"),		  SIPTAG_HEADER_STR("Accept: foo/bar\n"				    "\n"				    "test payload\n"),		  SIPTAG_TIMESTAMP(sip->sip_timestamp),		  SIPTAG_END(),		  SIPTAG_REFER_TO_STR("<sip:foo@bar>"),		  TAG_END()), 0);  TEST_1(sip->sip_from == NULL);  TEST_1(sip->sip_via); TEST_1(sip->sip_via->v_next == NULL);  TEST_S(sip->sip_via->v_protocol, "SIP/2.0/SCTP");  TEST_1(sip->sip_authorization);  TEST_1(sip->sip_priority);  TEST_1(sip->sip_payload);  TEST_S(sip->sip_payload->pl_data, "test payload\n");  TEST_1(sip->sip_timestamp);  TEST_S(sip->sip_timestamp->ts_stamp, "10.010");  TEST_S(sip->sip_timestamp->ts_delay, "0.000100");  TEST_1(!sip->sip_refer_to);  TEST_1(tl = tl0 = tl_list(SIPTAG_TO_STR("<sip:foo@bar>"),			    SIPTAG_END(),			    SIPTAG_REFER_TO_STR("<sip:foo@bar>"),			    TAG_END()));  /* sip_add_tagis should stop after SIPTAG_END() */  TEST(sip_add_tagis(msg, sip, &tl), 0);  TEST(tl, tl0 + 2);  TEST(sip_timestamp_make(home, "+1"), NULL);  TEST(sip_timestamp_make(home, "1.0e6 13.0"), NULL);  TEST_1(sip_timestamp_make(home, "1.0 .001"));  TEST(sip_timestamp_make(home, ".0001 13.0"), NULL);  TEST_1(x = sip->sip_path);  TEST_1(sip_add_make(msg, sip, sip_path_class, "<sip:135.180.130.133>") == 0);  TEST(x, sip->sip_path->r_next);  TEST_1(x = sip->sip_service_route);  TEST_1(sip_add_make(msg, sip, sip_service_route_class, 		      "<sip:135.180.130.133>") == 0);  TEST(x, sip->sip_service_route);  TEST_1(sip->sip_service_route->r_next);  /* Detect parsing errors */  TEST_1(!sip_cseq_make(home, "21874624876976 INVITE"));  TEST_1(!sip_cseq_make(home, "218746INVITE"));    msg_destroy(msg), msg = NULL;  su_home_destroy(home), su_free(NULL, home), home = NULL;  END();}

⌨️ 快捷键说明

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