📄 torture_sip.c
字号:
{ sip_cseq_t *cs, *cs0; TEST_1(cs = sip_cseq_create(home, 123456789, sip_method_invite, "1nvite")); TEST(cs->cs_seq, 123456789); TEST(cs->cs_method, sip_method_invite); TEST_S(cs->cs_method_name, "INVITE"); su_free(home, cs); TEST_1(cs = sip_cseq_create(home, 123456789, sip_method_invite, NULL)); TEST(cs->cs_seq, 123456789); TEST(cs->cs_method, sip_method_invite); TEST_S(cs->cs_method_name, "INVITE"); TEST_1(cs0 = sip_cseq_dup(home, cs)); su_free(home, cs); su_free(home, cs0); TEST_1(!sip_cseq_create(home, 123456789, sip_method_unknown, NULL)); TEST_1(cs = sip_cseq_create(home, 123456789, sip_method_unknown, "invite")); TEST(cs->cs_seq, 123456789); TEST(cs->cs_method, sip_method_unknown); TEST_S(cs->cs_method_name, "invite"); TEST_1(cs0 = sip_cseq_dup(home, cs)); su_free(home, cs); su_free(home, cs0); } { sip_contact_t *m, *m0; TEST_1(!sip_contact_make(home, ",,")); TEST_1(m = sip_contact_create(home, (void *)"sip:joe@bar", "q=0.2", "+message", NULL)); TEST_S(m->m_q, "0.2"); TEST_1(m0 = sip_contact_dup(home, m)); TEST_1(sip_contact_add_param(home, m, "q=0.5") >= 0); TEST_1(sip_contact_add_param(home, m, "video=FALSE") >= 0); TEST_1(sip_contact_add_param(home, m, NULL) == -1); TEST_1(sip_contact_add_param(home, NULL, "video=FALSE") == -1); TEST_1(sip_contact_add_param(home, m, "audio=FALSE") == 0); TEST_1(sip_contact_add_param(home, m, "expires=0") == 0); TEST_S(m->m_q, "0.5"); TEST_S(m->m_expires, "0"); TEST_1(!sip_contact_create(home, (void *)"sip:joe@[baa", "audio", "video", NULL)); TEST_1(sip_header_format(home, sip_contact_class, "*")); su_free(home, m); su_free(home, m0); } { sip_via_t *v; char *s; v = sip_via_make(home, "SIP/2.0/UDP domain.invalid:5060"); TEST_1(v); s = sip_contact_string_from_via(home, v, NULL, v->v_protocol); TEST_S(s, "<sip:domain.invalid:5060;transport=udp>"); su_free(home, v), su_free(home, s); TEST_1(sip_transport_has_tls("SIP/2.0/TLS-SCTP")); TEST_1(sip_transport_has_tls("TLS-UDP")); v = sip_via_make(home, "SIP/2.0/TLS-SCTP domain.invalid"); TEST_1(v); s = sip_contact_string_from_via(home, v, NULL, v->v_protocol); TEST_S(s, "<sips:domain.invalid;transport=tls-sctp>"); su_free(home, v), su_free(home, s); } { sip_expires_t *ex; TEST_1(!sip_expires_make(home, "-12+1")); TEST_1(ex = sip_expires_make(home, "4294967297")); /* XXX */ su_free(home, ex); TEST_1(ex = sip_expires_make(home, "Wed, 25 Mar 2004 14:49:29 GMT")); su_free(home, ex); TEST_1(ex = sip_expires_create(home, 3600)); su_free(home, ex); } { sip_retry_after_t *ra; char const *s; TEST_1(!(ra = sip_retry_after_make(home, "50 (foo"))); TEST_1(ra = sip_retry_after_make(home, "50 (foo) ; duration = 13")); TEST_S(ra->af_duration, "13"); TEST_S(ra->af_comment, "foo"); TEST(msg_header_remove_param(ra->af_common, "duration"), 1); TEST(ra->af_duration, NULL); s = sip_header_as_string(home, (void*)ra); TEST_S(s, "50 (foo)"); TEST(msg_header_add_param(home, ra->af_common, "x=z"), 0); s = sip_header_as_string(home, (void*)ra); TEST_S(s, "50 (foo) ;x=z"); su_free(home, ra); } { sip_date_t *d; TEST_1(!(d = sip_date_make(home, "Mon, 30 Feb 1896 23:59:59 GMT"))); su_free(home, d); TEST_1(d = sip_date_create(home, (1<<30))); su_free(home, d); TEST_1(d = sip_date_create(home, 0)); TEST_1(d->d_time != 0); su_free(home, d); } { sip_route_t *r, *r0; TEST_1(!sip_route_make(home, "<sip:foo@[bar:50>;lr")); TEST_1(r = sip_route_make(home, "<sip:foo@[baa::1]:5060>;lr")); TEST_1(r0 = sip_route_dup(home, r)); TEST_1(sip_route_fix(r)); TEST_1(url_has_param(r->r_url, "lr")); su_free(home, r); TEST_1(r = sip_route_create(home, r0->r_url, r0->r_url)); su_free(home, r); su_free(home, r0); } { sip_record_route_t *r, *r0; TEST_1(!sip_record_route_make(home, "<sip:foo@[bar:50>;lr")); TEST_1(!sip_record_route_make(home, "<sip:foo@[baa::1]>;lr bar, sip:foo")); TEST_1(r = sip_record_route_make(home, "<sip:foo@[baa::1]:5060>;lr")); TEST_1(r0 = sip_record_route_dup(home, r)); su_free(home, r); TEST_1(r = sip_route_create(home, r0->r_url, r0->r_url)); su_free(home, r), su_free(home, r0); } { sip_via_t *v, *v0; TEST_1(!sip_via_make(home, ",,")); TEST_1(!sip_via_make(home, "SIP// host:5060 (foo),")); TEST_1(!sip_via_make(home, "SIP/2.0/TCP host:5060 (foo) bar,")); TEST_1(!sip_via_make(home, "SIP/2.0/TCP [3ffe::1:5060 (foo),")); TEST_1(v = sip_via_create(home, "bar.com", "50600", "SIP/2.0/UDP", "hidden", "rport=50601", "comp=sigcomp", "branch=1", "q=0.2", NULL)); TEST_S(v->v_branch, "1"); TEST_S(v->v_rport, "50601"); TEST_S(v->v_comp, "sigcomp"); TEST_1(v = sip_via_make(home, "SIP/2.0/UDP bar.com:50600" " ;hidden;rport=50601;comp=sigcomp;branch=1;ttl=15" " ; maddr=[::227.0.0.1]" " (This is a comment) ")); TEST_S(v->v_ttl, "15"); TEST_S(v->v_maddr, "[::227.0.0.1]"); TEST_S(v->v_branch, "1"); TEST_S(v->v_rport, "50601"); TEST_S(v->v_comp, "sigcomp"); TEST_1(v0 = sip_via_dup(home, v)); TEST(msg_header_add_param(home, v->v_common, "rport"), 0); TEST_S(v->v_rport, ""); TEST(msg_header_remove_param(v->v_common, "comp"), 1); TEST(v->v_comp, NULL); TEST(msg_header_remove_param(v->v_common, "ttl"), 1); TEST(v->v_ttl, NULL); TEST(msg_header_remove_param(v->v_common, "maddr"), 1); TEST(v->v_maddr, NULL); TEST(msg_header_remove_param(v->v_common, "rport"), 1); TEST(v->v_rport, NULL); TEST(msg_header_remove_param(v->v_common, "branch"), 1); TEST(v->v_branch, NULL); TEST_1(sip_via_add_param(home, v, "video=FALSE") == 0); TEST_1(sip_via_add_param(home, v, NULL) == -1); TEST_1(sip_via_add_param(home, NULL, "video=FALSE") == -1); TEST_1(sip_via_add_param(home, v, "audio=FALSE") == 0); TEST_1(sip_via_add_param(home, v, "branch=0") == 0); su_free(home, v); su_free(home, v0); TEST_1(v = sip_via_create(home, "bar.com", "50600", NULL, "rport=50601", "branch=1", "q=0.2", NULL)); TEST_S(v->v_protocol, "SIP/2.0/UDP"); su_free(home, v); } { sip_call_info_t *ci, *ci0; TEST_1(ci = sip_call_info_make(home, "<http://www.nokia.com>;purpose=info")); TEST_S(ci->ci_purpose, "info"); TEST_1(ci0 = sip_call_info_dup(home, ci)); TEST_S(ci0->ci_purpose, "info"); TEST_1(ci->ci_purpose != ci0->ci_purpose); TEST(msg_header_remove_param(ci->ci_common, "purpose"), 1); TEST(ci->ci_purpose, NULL); su_free(home, ci); su_free(home, ci0); } su_home_check(home); su_home_zap(home); END();}int test_sip_msg_class(msg_mclass_t const *mc){ int i, j, N; msg_hclass_t *hc; BEGIN(); N = mc->mc_hash_size; /* check hashes */ for (i = 0; i < N; i++) { if (!(hc = mc->mc_hash[i].hr_class)) continue; for (j = i + 1; j < N; j++) { if (!mc->mc_hash[j].hr_class) continue; if (hc->hc_hash == mc->mc_hash[j].hr_class->hc_hash) { fprintf(stderr, "\t%s and %s have same hash\n", hc->hc_name, mc->mc_hash[j].hr_class->hc_name); return 1; } } } /* Check parser table sanity */ for (i = 0; i < N; i++) { /* Verify each header entry */ hc = mc->mc_hash[i].hr_class; if (hc == NULL) continue; /* Short form */ if (hc->hc_short[0]) TEST(mc->mc_short[hc->hc_short[0] - 'a'].hr_class, hc); /* Long form */ j = msg_header_name_hash(hc->hc_name, NULL); TEST(j, hc->hc_hash); for (j = MC_HASH(hc->hc_name, N); j != i; j = (j + 1) % N) TEST_1(mc->mc_hash[j].hr_class); } END(); return 0;}msg_t *read_message(int flags, char const buffer[]){ int n, m; msg_t *msg; msg_iovec_t iovec[2]; n = strlen(buffer); if (n == 0) return NULL; msg = msg_create(test_mclass, flags); if (msg_recv_iovec(msg, iovec, 2, n, 1) < 0) { perror("msg_recv_iovec"); } memcpy(iovec->mv_base, buffer, n); msg_recv_commit(msg, n, 1); m = msg_extract(msg); return msg;}static int test_encoding(void){ msg_header_t *h, *h1; msg_common_t *c; msg_t *msg; sip_t *sip; su_home_t *home; BEGIN(); TEST_1(home = su_home_new(sizeof *home)); msg = read_message(MSG_DO_EXTRACT_COPY, "SUBSCRIBE sip:foo@bar SIP/2.0\r\n" "To: Joe User <sip:foo@bar>\r\n" "From: \"Bar Owner\" <sip:bar@foo>;tag=foobar\r\n" "P-Asserted-Identity: <sip:bar@foo>\r\n" "P-Preferred-Identity: <sip:bar-owner@foo>\r\n" "Call-ID: 0ha0isndaksdj@10.1.2.3\r\n" "CSeq: 8 SUBSCRIBE\r\n" "Via: SIP/2.0/UDP 135.180.130.133\r\n" "Extension-Header: extended, more\r\n" "Reason: Q.850;cause=16;text=\"Terminated\"\r\n" "Contact: <sip:bar@pc.foo:5060>\r\n" "Date: Wed, 25 Mar 2004 14:49:29 GMT\r\n" "Max-Forwards: 80\r\n" "Min-Expires: 30\r\n" "Retry-After: 48 (this is a comment) ;duration=321\r\n" "Route: <sip:proxy.bar;maddr=172.21.40.40>\r\n" "Request-Disposition: proxy\r\n" "Accept-Contact: *;audio\r\n" "Reject-Contact: *;video\r\n" "Expires: 1200\r\n" "Event: presence;id=1\r\n" "In-Reply-To: {0h!a0i\"sndaksdj}@[kjsafi3], {0h!a0i\"snj}@[kjsfi3]\r\n" "Organization: Nuoret Banaani-Kotkat y.r.\r\n" "Priority: urgent\r\n" "Subject: ynk\r\n" "Timestamp: 3289129810.798259\r\n" "SIP-If-Match: foobar\r\n" "Proxy-Requires: prefs\r\n" "Supported: vnd.nokia\r\n" "User-Agent: Unknown Subscriber (1.0) Tonto (2.0)\r\n" "Accept: application/pidf+xml;version=1.0\r\n" "Accept-Encoding: gzip\r\n" /* Test loop below cannot encode multiple Accept-Language on one line */ "Accept-Language: "/* "fi, "*/"en;q=0.2\r\n" "RAck: 421413 214214 INVITE\r\n" "Referred-By: <sips:bob@biloxi.example.com>\r\n" "Replaces: 12345601@atlanta.example.com;from-tag=314159;to-tag=1234567\r\n" "Authorization: Digest realm=\"foo\"\r\n" "Proxy-Authorization: Digest realm=\"foo\"\r\n" "Security-Client: tls\r\n" "Security-Verify: tls;q=0.2\r\n" "Privacy: none\r\n" "Content-Length: 7\r\n" "Content-Encoding: gzip, deflate, identity\r\n" "Content-Disposition: filter\r\n" "Content-Language: fi\r\n" "MIME-Version: 1.0\r\n" "Min-SE: 123\r\n" "Session-Expires: 1200\r\n" "Content-Type: text/plain\r\n" "\r\n" "Heippa!"); sip = sip_object(msg); TEST_1(msg); TEST_1(sip); TEST_1(!sip->sip_error); for (h = (msg_header_t *)sip->sip_request; h; h = h->sh_succ) { char b[80]; int n; if (h == (msg_header_t*)sip->sip_payload) break; TEST_1(h1 = msg_header_dup(home, h)); n = msg_header_e(b, sizeof b, h1, 0); TEST(n, h->sh_len); TEST_M(b, h->sh_data, n); su_free(home, h1); } msg_destroy(msg), msg = NULL; /* Note: this should be canonic! */ msg = read_message(MSG_DO_EXTRACT_COPY, "SIP/2.0 200 Ok\r\n" "To: Joe User <sip:foo@bar>;tag=deadbeef\r\n" "From: sip:bar@foo;tag=foobar\r\n" "Call-ID: {0h!a0i\"sndaksdj}@[kjsafi3]\r\n" "CSeq: 8912734 SUBSCRIBE\r\n" "Via: SIP/2.0/UDP 135.180.130.133\r\n"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -