📄 torture_sip.c
字号:
"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();}static int test_bad_packet(void){ msg_t *msg; sip_t *sip; su_home_t *home; 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\r\n" "Via: SIP/2.0/UDP [aa:bb::1]:5061\0\0")); 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_route->r_common), 0); TEST(sip->sip_request->rq_url->url_type, url_invalid); su_home_destroy(home), su_free(NULL, home), home = NULL; msg_destroy(msg), msg = NULL; END();}static int test_sip_list_header(void){ msg_t *msg; sip_t *sip; su_home_t *home; sip_allow_t *a; BEGIN(); home = su_home_create(); TEST_1(msg = read_message(0, "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" "From: <sip:joe@doe.org>;tag=foobar\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" "Allow: INVITE\r\n" "Allow: ACK\r\n" "Allow: CANCEL\r\n" "Allow: BYE\r\n" "Allow: OPTIONS\r\n" "Allow: MESSAGE\r\n" "Max-Forwards: 12\r\n" "Content-Type: text/plain\r\n" "\r\n" "hello\r\n")); TEST_1(sip = sip_object(msg)); TEST_1(a = sip->sip_allow); TEST_1(a->k_items); TEST_1(a->k_next == NULL); msg_destroy(msg), msg = NULL; TEST_1(a = sip_allow_make(home, "")); TEST_S(sip_header_as_string(home, (void *)a), ""); su_home_destroy(home), su_free(NULL, home), home = NULL; END();}static int test_prack(void){ /* Test RAck and RSeq */ su_home_t *home; sip_rack_t *rack, *rack0; sip_rseq_t *rseq, *rseq0; BEGIN(); TEST_1(home = su_home_create()); TEST_1(rack = sip_rack_make(home, "1 2 INVITE")); TEST(rack->ra_response, 1); TEST(rack->ra_cseq, 2); TEST(rack->ra_method, sip_method_invite); TEST_S(rack->ra_method_name, "INVITE"); TEST_1(rseq = sip_rseq_make(home, "3")); TEST(rseq->rs_response, 3); TEST_1(rack0 = sip_rack_dup(home, rack)); TEST(rack0->ra_method_name, rack->ra_method_name); TEST_1(rseq0 = sip_rseq_dup(home, rseq)); TEST_1(rack = sip_rack_make(home, "4\r\n\t5\r\n\tEXTRA")); TEST(rack->ra_response, 4); TEST(rack->ra_cseq, 5); TEST(rack->ra_method, sip_method_unknown); TEST_S(rack->ra_method_name, "EXTRA"); TEST_1(rseq = sip_rseq_make(home, " 6 ")); TEST(rseq->rs_response, 6); TEST_1(rack0 = sip_rack_dup(home, rack)); TEST_1(rack0->ra_method_name != rack->ra_method_name); TEST_1(rseq0 = sip_rseq_dup(home, rseq)); su_home_destroy(home), su_free(NULL, home); END();}/* Test MIME headers */static int test_accept(void){ /* Test Accept header */ sip_accept_t *ac, *ac0; sip_accept_encoding_t *aa; su_home_t *home; BEGIN(); TEST_1(home = su_home_create()); TEST_1(ac = ac0 = sip_accept_make(home, "image / jpeg ; q = 0.6,, image/png, image/*, */* ")); TEST_S(ac->ac_type, "image/jpeg"); TEST_S(ac->ac_subtype, "jpeg"); TEST_1(ac->ac_params && ac->ac_params[0]); TEST_S(ac->ac_params[0], "q=0.6"); TEST_S(ac->ac_q, "0.6"); TEST_1(ac = ac->ac_next); TEST_S(ac->ac_type, "image/png"); TEST_S(ac->ac_subtype, "png"); TEST_1(ac = ac->ac_next); TEST_S(ac->ac_type, "image/*"); TEST_S(ac->ac_subtype, "*"); TEST_1(aa = sip_accept_encoding_make(home, "gzip")); TEST_1(aa = sip_accept_encoding_make(home, "gzip;q=1.0,deflate;q=1.0")); TEST_S(aa->aa_value, "gzip"); TEST_S(aa->aa_q, "1.0"); TEST_1(aa->aa_next); TEST_S(aa->aa_next->aa_value, "deflate"); TEST_1(aa = sip_accept_encoding_make(home, ",")); TEST_S(aa->aa_value, ""); TEST_1(!aa->aa_next); TEST_1(aa = sip_accept_encoding_make(home, "")); TEST_S(aa->aa_value, ""); TEST_1(!aa->aa_next); TEST_1(aa = sip_accept_language_make(home, "fi")); TEST_1(aa = sip_accept_language_make(home, "fi;q=1.0,sv;q=1.0")); TEST_S(aa->aa_value, "fi"); TEST_S(aa->aa_q, "1.0"); TEST_1(aa->aa_next); TEST_S(aa->aa_next->aa_value, "sv"); TEST_1(aa = sip_accept_language_make(home, ",")); TEST_S(aa->aa_value, ""); TEST_1(!aa->aa_next); TEST_1(aa = sip_accept_language_make(home, "")); TEST_S(aa->aa_value, ""); TEST_1(!aa->aa_next); su_home_destroy(home), su_free(NULL, home); END();}static int test_content_disposition(void){ /* Test Accept header */ sip_content_disposition_t *cd, *cd0; su_home_t *home; BEGIN(); TEST_1(home = su_home_create()); TEST_1(cd = cd0 = sip_content_disposition_make(home, "sip-cgi ; action = store;handling=required ")); TEST_S(cd->cd_type, "sip-cgi"); TEST_1(cd->cd_params && cd->cd_params[0] && cd->cd_params[1] && !cd->cd_params[2]); TEST_S(cd->cd_params[0], "action=store"); TEST_S(cd->cd_params[1], "handling=required"); TEST_S(cd->cd_handling, "required"); TEST_1(cd->cd_required); TEST_1(!cd->cd_optional); su_home_destroy(home), su_free(NULL, home); END();}int test_retry_after(void){ /* Test Session-Expires header */ sip_retry_after_t *af, *af0; su_home_t *home; char buf[64]; BEGIN(); TEST_1(home = su_home_create()); TEST_1(af = sip_retry_after_make(home, "1800")); TEST(af->af_delta, 1800); TEST_1(af = sip_retry_after_make(home, "1800(foo); duration = 3600")); TEST_1(af->af_params && af->af_params[0]); TEST_S(af->af_comment, "foo"); TEST_S(af->af_params[0], "duration=3600"); TEST_S(af->af_duration, "3600"); TEST_1(af0 = sip_retry_after_dup(home, af)); TEST_1(af0->af_params && af0->af_params[0]); TEST_S(af0->af_comment, "foo"); TEST_S(af0->af_params[0], "duration=3600"); TEST_S(af0->af_duration, "3600"); TEST_1(sip_retry_after_e(buf, sizeof(buf), (sip_header_t *)af0, 0)); TEST_S(buf, "1800 (foo) ;duration=3600"); su_home_destroy(home), su_free(NULL, home); END();}int test_session_expires(void){ /* Test Session-Expires header */ sip_session_expires_t *x, *x0; su_home_t *home; BEGIN(); TEST_1(home = su_home_create()); TEST_1(x = x0 = sip_session_expires_make(home, "1800")); TEST(x->x_delta, 1800); TEST_1(x = x0 = sip_session_expires_make(home, "1800 ; refresher = uas")); TEST_1(x->x_params && x->x_params[0]); TEST_S(x->x_params[0], "refresher=uas"); TEST_S(x->x_refresher, "uas"); su_home_destroy(home), su_free(NULL, home); END();}int test_min_se(void){ /* Test Min-SE header */ sip_min_se_t *min, *min0; su_home_t *home; BEGIN(); TEST_1(home = su_home_create()); TEST_1(min = min0 = sip_min_se_make(home, "1800")); TEST(min->min_delta, 1800); TEST_1(min = sip_min_se_dup(home, min0)); TEST(min->min_delta, 1800); TEST_1(min = sip_min_se_copy(home, min0)); TEST(min->min_delta, 1800); TEST_1(min = sip_min_se_make(home, "1999 ; foo = bar")); TEST(min->min_delta, 1999); TEST_1(min->min_params); TEST_S(min->min_params[0], "foo=bar"); TEST_1(min0 = sip_min_se_dup(home, min)); TEST(min0->min_delta, 1999); TEST_1(min0->min_params); TEST_S(min0->min_params[0], "foo=bar"); su_home_destroy(home), su_free(NULL, home); END();} int test_refer(void){ sip_refer_to_t *r, *r0; sip_referred_by_t *b, *b0; sip_replaces_t *rp, *rp0; char const *s0; su_home_t *home; BEGIN(); TEST_1(home = su_home_create()); TEST_1(r = r0 = sip_refer_to_make(home, "http://example.com;foo=bar")); TEST(r->r_url->url_type, url_http); TEST_1(r->r_params); TEST_S(r->r_params[0], "foo=bar"); r = sip_refer_to_dup(home, r0); TEST(r->r_url->url_type, url_http); TEST_1(r->r_params); TEST_S(r->r_params[0], "foo=bar"); TEST_1(r = r0 = sip_refer_to_make(home, s0 = "<http://example.com>")); TEST_S(r->r_display, ""); TEST(r->r_url->url_type, url_http); TEST(r->r_params, NULL); r = sip_refer_to_dup(home, r0); TEST_S(r->r_display, ""); TEST(r->r_url->url_type, url_http); TEST(r->r_params, NULL); TEST_S(sip_header_as_string(home, (sip_header_t*)r), s0); TEST_1(r = r0 = sip_refer_to_make(home, "Web Site <http://example.com>;foo=bar")); TEST_S(r->r_display, "Web Site"); TEST(r->r_url->url_type, url_http); TEST_1(r->r_params); TEST_S(r->r_params[0], "foo=bar"); TEST(r->r_params[1], NULL); r = sip_refer_to_dup(home, r0); TEST(r->r_url->url_type, url_http); TEST_1(r->r_params); TEST_S(r->r_params[0], "foo=bar"); TEST(r->r_params[1], NULL); /* XXX */ su_home_destroy(home), su_free(NULL, home); TEST_1(home = su_home_create()); TEST_1(b = b0 = sip_referred_by_make(home, "sip:joe@example.edu;param=value")); TEST(b->b_display, NULL); TEST_1(b->b_params); TEST(b->b_cid, NULL); TEST_1(b = sip_referred_by_make(home, "John Doe <sip:joe@example.edu>" ";cid=\"foo@bar\"")); TEST_S(b->b_display, "John Doe"); TEST_1(b->b_params); TEST_1(b->b_cid); TEST_S(b->b_params[0] + 4, b->b_cid); b = sip_referred_by_dup(home, b0 = b); TEST_1(b); TEST_S(b->b_display, "John Doe"); TEST_1(b->b_cid); TEST_S(b->b_params[0] + 4, b->b_cid); TEST_S(b->b_cid, b0->b_cid); TEST(msg_header_replace_param(home, b->b_common, "cid=cid:8u432658725"), 1); TEST_S(b->b_cid, "cid:8u432658725"); TEST(msg_header_remove_param(b->b_common, "cid"), 1); TEST(b->b_cid, NULL); /* XXX */#define WORD ALPHA DIGIT "-.!%*_+`'~()<>:\\\"/[]?{}" rp = sip_replaces_make(home, WORD "@" WORD ";to-tag=foo;from-tag=bar" ";early-only = yes-ple
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -