📄 torture_sip.c
字号:
{ msg_t *msg; sip_t *sip; su_home_t *home; sip_route_t *r; sip_request_t sip_request[1] = { SIP_REQUEST_INIT() }; sip_status_t sip_status[1] = { SIP_STATUS_INIT() }; sip_header_t sip_unknown[1] = { SIP_UNKNOWN_INIT() }; sip_separator_t sip_separator[1] = { SIP_SEPARATOR_INIT() }; sip_payload_t sip_payload[1] = { SIP_PAYLOAD_INIT() }; sip_via_t sip_via[1] = { SIP_VIA_INIT() }; sip_route_t sip_route[1] = { SIP_ROUTE_INIT() }; sip_record_route_t sip_record_route[1] = { SIP_RECORD_ROUTE_INIT() }; sip_max_forwards_t sip_max_forwards[1] = { SIP_MAX_FORWARDS_INIT() }; sip_from_t sip_from[1] = { SIP_FROM_INIT() }; sip_to_t sip_to[1] = { SIP_TO_INIT() }; sip_call_id_t sip_call_id[1] = { SIP_CALL_ID_INIT() }; sip_cseq_t sip_cseq[1] = { SIP_CSEQ_INIT() }; sip_contact_t sip_contact[1] = { SIP_CONTACT_INIT() }; sip_expires_t sip_expires[1] = { SIP_EXPIRES_INIT() }; sip_date_t sip_date[1] = { SIP_DATE_INIT() }; sip_retry_after_t sip_retry_after[1] = { SIP_RETRY_AFTER_INIT() }; sip_timestamp_t sip_timestamp[1] = { SIP_TIMESTAMP_INIT() }; sip_subject_t sip_subject[1] = { SIP_SUBJECT_INIT() }; sip_priority_t sip_priority[1] = { SIP_PRIORITY_INIT() }; sip_call_info_t sip_call_info[1] = { SIP_CALL_INFO_INIT() }; sip_organization_t sip_organization[1] = { SIP_ORGANIZATION_INIT() }; sip_server_t sip_server[1] = { SIP_SERVER_INIT() }; sip_user_agent_t sip_user_agent[1] = { SIP_USER_AGENT_INIT() }; sip_in_reply_to_t sip_in_reply_to[1] = { SIP_IN_REPLY_TO_INIT() }; sip_accept_t sip_accept[1] = { SIP_ACCEPT_INIT() }; sip_accept_encoding_t sip_accept_encoding[1] = { SIP_ACCEPT_ENCODING_INIT() }; sip_accept_language_t sip_accept_language[1] = { SIP_ACCEPT_LANGUAGE_INIT() }; sip_session_expires_t sip_session_expires[1] = { SIP_SESSION_EXPIRES_INIT() }; sip_min_se_t sip_min_se[1] = { SIP_MIN_SE_INIT() }; sip_allow_t sip_allow[1] = { SIP_ALLOW_INIT() }; sip_require_t sip_require[1] = { SIP_REQUIRE_INIT() }; sip_proxy_require_t sip_proxy_require[1] = { SIP_PROXY_REQUIRE_INIT() }; sip_supported_t sip_supported[1] = { SIP_SUPPORTED_INIT() }; sip_unsupported_t sip_unsupported[1] = { SIP_UNSUPPORTED_INIT() };#if SIP_HAVE_ENCRYPTION sip_encryption_t sip_encryption[1] = { SIP_ENCRYPTION_INIT() };#endif#if SIP_HAVE_RESPONSE_KEY sip_response_key_t sip_response_key[1] = { SIP_RESPONSE_KEY_INIT() };#endif sip_proxy_authenticate_t sip_proxy_authenticate[1] = { SIP_PROXY_AUTHENTICATE_INIT() }; sip_proxy_authorization_t sip_proxy_authorization[1] = { SIP_PROXY_AUTHORIZATION_INIT() }; sip_authorization_t sip_authorization[1] = { SIP_AUTHORIZATION_INIT() }; sip_www_authenticate_t sip_www_authenticate[1] = { SIP_WWW_AUTHENTICATE_INIT() }; 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_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_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_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_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_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(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"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -