📄 torture_sip.c
字号:
TEST(msg_header_remove_param(v->v_common, "ttl"), 1); TEST_P(v->v_ttl, NULL); TEST(msg_header_remove_param(v->v_common, "maddr"), 1); TEST_P(v->v_maddr, NULL); TEST(msg_header_remove_param(v->v_common, "rport"), 1); TEST_P(v->v_rport, NULL); TEST(msg_header_remove_param(v->v_common, "branch"), 1); TEST_P(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_P(ci->ci_purpose, NULL); su_free(home, ci); su_free(home, ci0); } { sip_alert_info_t *ai, *ai0; TEST_1(ai = sip_alert_info_make(home, "<http://www.nokia.com/ringtone.mp3>;x-format=mp3")); TEST_1(ai0 = sip_alert_info_dup(home, ai)); TEST(msg_header_remove_param(ai->ai_common, "x-format"), 1); TEST(msg_header_remove_param(ai0->ai_common, "x-format"), 1); su_free(home, ai); su_free(home, ai0); } { sip_reply_to_t *rplyto, *rplyto0; TEST_1(rplyto = sip_reply_to_make(home, "sip:joe@bar")); TEST_1(msg_header_add_param(home, (msg_common_t *)rplyto, "x-extra=extra") == 0); while (rplyto->rplyto_params && rplyto->rplyto_params[0]) msg_header_remove_param(rplyto->rplyto_common, rplyto->rplyto_params[0]); su_free(home, rplyto); TEST_1(!sip_reply_to_make(home, (void *)"sip:joe@[baa")); TEST_1(rplyto = sip_reply_to_make(home, (void *)"sip:joe@bar")); su_free(home, rplyto); TEST_1(rplyto = sip_reply_to_make(home, (void *)"Joe <sip:joe@bar;user=ip>;x-extra=extra")); TEST_1(rplyto0 = sip_reply_to_dup(home, rplyto)); su_free(home, rplyto); su_free(home, rplyto0); } 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_P(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();}msg_t *read_message(int flags, char const buffer[]){ size_t n; int 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" "Refer-Sub: true\r\n" "Suppress-Body-If-Match: humppa\r\n" "Suppress-Notify-If-Match: zumppa\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]; size_t 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_SIZE(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" "Extension-Header: extended, more\r\n" "Reason: SIP;cause=400;text=\"Bad Message\"\r\n" "Contact: <sip:bar@pc.foo:5060>;audio\r\n" "Date: Wed, 25 Mar 2004 14:49:29 GMT\r\n" "Max-Forwards: 80\r\n" "Min-Expires: 30\r\n" "Expires: Wed, 25 Mar 2004 15:49:29 GMT\r\n" "Retry-After: 48;duration=321\r\n" "Record-Route: <sip:record-route@proxy.bar;maddr=172.21.40.40>\r\n" "Event: presence;id=1\r\n" "Allow-Events: presence, presence.winfo\r\n" "Subscription-State: active;expires=1800\r\n" "Call-Info: <http://www.bar.com/xcap/joe/>;purpose=xcap\r\n" "Error-Info: <http://www.bar.com/xcap/joe/errors>;param=xcap\r\n" "Server: None\r\n" "Timestamp: 3289129810.798259 0.084054\r\n" "SIP-ETag: foobar\r\n" "SIP-If-Match: foobar\r\n" "Requires: vnd.nokia\r\n" "Unsupported: vnd.nokia.pic\r\n" "Accept-Disposition: filter\r\n" "Warning: 399 presence.bar:5060 \"Unimplemented filter\"\r\n" "RSeq: 421414\r\n" "Refer-To: <sip:hsdf@cdwf.xcfw.com?Subject=test&Organization=Bar>\r\n" "Alert-Info: <http://alert.example.org/test.mp3>\r\n" "Reply-To: Bob <sip:bob@example.com>\r\n" "WWW-Authenticate: Digest realm=\"foo\"\r\n" "Proxy-Authenticate: Digest realm=\"foo\"\r\n" "Security-Server: tls;q=0.2\r\n" "Session-Expires: 1200;refresher=uac\r\n" "Content-Length: 7\r\n" "Content-Type: text/plain;charset=iso8859-1\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_status; h; h = h->sh_succ) { char b[80]; size_t n; if (h == (sip_header_t*)sip->sip_payload) break; TEST_1(h1 = sip_header_dup(home, h)); n = sip_header_e(b, sizeof b, h1, 0); TEST_SIZE(n, h->sh_len); TEST_M(b, h->sh_data, n); su_free(home, h1); } TEST_1(sip->sip_etag); TEST_S(sip->sip_etag->g_value, "foobar"); TEST_1(sip->sip_if_match); msg_destroy(msg), msg = NULL; su_home_check(home); su_home_zap(home); msg = read_message(0, "SIP/2.0 200 Ok\r\n" "Via: SIP/2.0/UDP 135.180.130.133\r\n" "Via: SIP/2.0/UDP 135.180.130.130:5060\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" "Record-Route: <sip:135.180.130.133;lr>\r\n" "Record-Route: <sip:135.180.130.130;lr>\r\n" "Content-Length: 0\r\n" "\r\n"); sip = sip_object(msg); TEST_1(msg); TEST_1(sip); TEST_1(!sip->sip_error); sip->sip_flags |= MSG_FLG_COMPACT; TEST_1(msg_prepare(msg) != 0); TEST_1(c = sip->sip_status->st_common); TEST_M(c->h_data, "SIP/2.0 200 Ok\r\n", c->h_len); TEST_1(c = sip->sip_to->a_common); TEST_M(c->h_data, "t:Joe User<sip:foo@bar>;tag=deadbeef\r\n", c->h_len); TEST_1(c = sip->sip_from->a_common); TEST_M(c->h_data, "f:sip:bar@foo;tag=foobar\r\n", c->h_len); TEST_1(c = sip->sip_call_id->i_common); TEST_M(c->h_data, "i:{0h!a0i\"sndaksdj}@[kjsafi3]\r\n", c->h_len); TEST_1(c = sip->sip_cseq->cs_common); TEST_M(c->h_data, "CSeq:8912734 SUBSCRIBE\r\n", c->h_len); TEST_1(c = sip->sip_via->v_common); TEST_M(c->h_data, "v:SIP/2.0/UDP 135.180.130.133,SIP/2.0/UDP 135.180.130.130:5060\r\n", c->h_len); TEST_1(c = sip->sip_via->v_next->v_common); TEST_SIZE(c->h_len, 0); TEST_1(c->h_data); TEST_1(c = sip->sip_record_route->r_common); TEST_M(c->h_data, "Record-Route:<sip:135.180.130.133;lr>,<sip:135.180.130.130;lr>\r\n", c->h_len); TEST_1(c = sip->sip_record_route->r_next->r_common); TEST_SIZE(c->h_len, 0); TEST_1(c->h_data); TEST_1(c = sip->sip_content_length->l_common); TEST_M(c->h_data, "l:0\r\n", c->h_len); END();}#define XTRA(xtra, h) SU_ALIGN(xtra) + sip_header_size((sip_header_t*)h)/** Test header filtering and duplicating */int tag_test(void){ su_home_t *home = su_home_new(sizeof(*home)); sip_request_t *request = sip_request_make(home, "INVITE sip:joe@example.com SIP/2.0"); sip_to_t *to = sip_to_make(home, "Joe User <sip:joe.user@example.com;param=1>" ";tag=12345678"); sip_via_t *via = sip_via_make(home, "SIP/2.0/UDP sip.example.com" ";maddr=128.12.9.254" ";branch=289412978y641.321312"); url_t *url = url_hdup(home, (url_t *)"sip:test:pass@example.com;baz=1?foo&bar"); tagi_t *lst, *dup; size_t xtra; tag_value_t v; BEGIN(); su_home_check(home); TEST_1(home && request && to && via); lst = tl_list(SIPTAG_REQUEST(request), SIPTAG_TO(to), SIPTAG_VIA(via), URLTAG_URL(url), TAG_NULL()); xtra = 0; xtra += XTRA(xtra, request); xtra += XTRA(xtra, to); xtra += XTRA(xtra, via); xtra += SU_ALIGN(xtra) + sizeof(*url) + url_xtra(url); TEST_SIZE(tl_len(lst), 5 * sizeof(tagi_t)); TEST_SIZE(tl_xtra(lst, 0), xtra); dup = tl_adup(NULL, lst);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -