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

📄 torture_sip.c

📁 Internet Phone, Chat, Conferencing
💻 C
📖 第 1 页 / 共 5 页
字号:
  home = su_home_new(sizeof *home); TEST_1(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(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(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;  int 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(tl_len(lst), 5 * sizeof(tagi_t));  TEST(tl_xtra(lst, 0), xtra);  dup = tl_adup(NULL, lst);  TEST(dup != NULL, 1);  TEST(tl_len(dup), 5 * sizeof(tagi_t));  TEST(tl_xtra(dup, 0), xtra);  if (tstflags & tst_verbatim)    tl_print(stdout, "dup:\n", dup);  su_free(NULL, dup);  tl_vfree(lst);  TEST_1(t_scan(siptag_request, home, "INVITE sip:example.org SIP/2.0", &v));  TEST_1(request = (void *)v);  TEST_1(request->rq_common->h_class == sip_request_class);  TEST_S(request->rq_method_name, "INVITE");  TEST_S(request->rq_version, "SIP/2.0");    TEST_1(t_scan(siptag_to, home, "Example <sip:example.org>;tag=foo", &v));  TEST_1(to = (void *)v);  TEST_1(to->a_common->h_class == sip_to_class);  TEST_S(to->a_display, "Example");  TEST_S(to->a_tag, "foo");  su_home_check(home);  su_home_zap(home);  END();}/** Test advanced tag features */static int parser_tag_test(void){  tagi_t *lst, *dup, *filter1, *filter2, *filter3, *filter4;  tagi_t *b1, *b2, *b3, *b4;  msg_t *msg;  sip_t *sip;  su_home_t *home;  int xtra;  BEGIN();  home = su_home_create();  msg = read_message(MSG_DO_EXTRACT_COPY, "SIP/2.0 401 Unauthorized\r\n""Via: SIP/2.0/UDP srlab.sr.ntc.nokia.com:5060;maddr=192.168.102.5\r\n""Via: SIP/2.0/UDP 172.21.9.155\r\n""Record-Route: <sip:garage.sr.ntc.nokia.com:5060;maddr=srlab.sr.ntc.nokia.com>\r\n""From: sip:digest@garage.sr.ntc.nokia.com\r\n""To: sip:digest@garage.sr.ntc.nokia.com\r\n""Call-ID: 982773899-reg@172.21.9.155\r\n""CSeq: 1 REGISTER\r\n""WWW-Authenticate: Digest realm=\"garage.sr.ntc.nokia.com\",\r\n""  nonce=\"MjAwMS0wMS0yMSAxNTowODo1OA==\", algorithm=MD5, qop=\"auth\"\r\n""Proxy-Authenticate: Digest realm=\"IndigoSw\", domain=\"sip:indigosw.com\", ""nonce=\"V2VkIEF1ZyAxNSAxODoxMzozMiBCU1QgMjAwMVtCQDJkYjE5ZA==\", ""opaque=\"NzA3ZjJhYzU4MGY3MzU0MQ==\", stale=false, ""algorithm=md5, algorithm=sha1, qop=\"auth\"\r\n" /* , qop=\"auth, auth-int\"\r */"\r\n");  sip = sip_object(msg);  TEST_1(home && msg && sip);  TEST(sip->sip_size, sizeof *sip);  TEST_1(sip_is_status((sip_header_t *)sip->sip_status));  TEST_1(sip_is_via((sip_header_t *)sip->sip_via));  TEST_1(sip_is_via((sip_header_t *)sip->sip_via->v_next));  TEST_1(sip_is_record_route((sip_header_t *)sip->sip_record_route));  TEST_1(sip_is_from((sip_header_t *)sip->sip_from));  TEST_1(sip_is_to((sip_header_t *)sip->sip_to));  TEST_1(sip_is_call_id((sip_header_t *)sip->sip_call_id));  TEST_1(sip_is_cseq((sip_header_t *)sip->sip_cseq));  TEST_1(sip_is_www_authenticate(    (sip_header_t *)sip->sip_www_authenticate));  TEST_1(sip_complete_message(msg) == 0);  TEST_1(sip_is_content_length((sip_header_t *)sip->sip_content_length));  TEST(sip->sip_content_length->l_common->h_succ, sip->sip_separator);  lst = tl_list(SIPTAG_VIA(sip->sip_via), 		SIPTAG_RECORD_ROUTE(sip->sip_record_route), 		TAG_SKIP(2), 		SIPTAG_CSEQ(sip->sip_cseq), 		SIPTAG_PAYLOAD(sip->sip_payload), 		TAG_NULL());  filter1 = tl_list(SIPTAG_VIA(0), 		    TAG_NULL());  filter2 = tl_list(SIPTAG_CALL_ID(0), 		    SIPTAG_FROM(0),		    SIPTAG_ROUTE(0),		    SIPTAG_CSEQ(0),		    TAG_NULL());  filter3 = tl_list(SIPTAG_CSEQ(0), 		    SIPTAG_CONTENT_LENGTH(0), 		    TAG_NULL());  filter4 = tl_list(SIPTAG_STATUS(0),		    SIPTAG_VIA(0),		    SIPTAG_RECORD_ROUTE(0),		    SIPTAG_FROM(0),		    SIPTAG_TO(0),		    SIPTAG_CALL_ID(0),		    SIPTAG_CSEQ(0),		    SIPTAG_WWW_AUTHENTICATE(0),		    SIPTAG_PROXY_AUTHENTICATE(0),		    SIPTAG_CONTENT_LENGTH(0),		    TAG_NULL());  TEST_1(lst && filter1 && filter2 && filter3 && filter4);  b1 = tl_afilter(home, filter1, lst);  TEST(tl_len(b1), 2 * sizeof(tagi_t));  TEST_1(((sip_via_t *)b1->t_value)->v_next);  xtra = sip_header_size((sip_header_t *)sip->sip_via);  xtra += SU_ALIGN(xtra);  xtra += sip_header_size((sip_header_t *)sip->sip_via->v_next);  TEST(tl_xtra(b1, 0), xtra);  dup = tl_adup(home, lst);  TEST(tl_len(dup), tl_len(lst));  TEST(tl_xtra(dup, 0), tl_xtra(lst, 0));  tl_vfree(lst);  lst = tl_list(SIPTAG_SIP(sip), TAG_NULL());  b2 = tl_afilter(home, filter2, lst);  TEST(tl_len(b2), 4 * sizeof(tagi_t));  xtra = 0;  xtra += XTRA(xtra, sip->sip_call_id);  xtra += XTRA(xtra, sip->sip_from);  xtra += XTRA(xtra, sip->sip_cseq);  TEST(tl_xtra(b2, 0), xtra);  b3 = tl_afilter(home, filter3, lst);  TEST(tl_len(b3), 3 * sizeof(tagi_t));  TEST(tl_xtra(b3, 0),        sizeof(sip_content_length_t) + sizeof(sip_cseq_t));  b4 = tl_afilter(home, filter4, lst);  TEST(tl_len(b4), 11 * sizeof(tagi_t));  xtra = 0;  xtra += XTRA(xtra, sip->sip_status);   xtra += XTRA(xtra, sip->sip_via);   xtra += XTRA(xtra, sip->sip_via->v_next);   xtra += XTRA(xtra, sip->sip_record_route);  xtra += XTRA(xtra, sip->sip_from);   xtra += XTRA(xtra, sip->sip_to);   xtra += XTRA(xtra, sip->sip_call_id);   xtra += XTRA(xtra, sip->sip_cseq);   xtra += XTRA(xtra, sip->sip_www_authenticate);   xtra += XTRA(xtra, sip->sip_proxy_authenticate);   xtra += XTRA(xtra, sip->sip_content_length);   TEST(tl_xtra(b4, 0), xtra);  tl_vfree(filter1); tl_vfree(filter2); tl_vfree(filter3); tl_vfree(filter4);  tl_vfree(lst);  su_home_check(home);  su_free(home, b4);  su_free(home, b3);   su_free(home, b2);   su_free(home, dup);  su_free(home, b1);   su_home_check(home);  su_home_destroy(home), su_free(NULL, home);  msg_destroy(msg);  END();}/** Test error messages */static int response_phrase_test(void){  BEGIN();  {    struct { int status; char const *phrase; } const errors[] =       {	{ SIP_100_TRYING },	{ SIP_180_RINGING },	{ SIP_181_CALL_IS_BEING_FORWARDED },       	{ SIP_182_QUEUED },       	{ SIP_183_SESSION_PROGRESS },       	{ SIP_200_OK },       	{ SIP_202_ACCEPTED },       	{ SIP_300_MULTIPLE_CHOICES },       	{ SIP_301_MOVED_PERMANENTLY },       	{ SIP_302_MOVED_TEMPORARILY },       	{ SIP_305_USE_PROXY },       	{ SIP_380_ALTERNATIVE_SERVICE },       	{ SIP_400_BAD_REQUEST },       	{ SIP_401_UNAUTHORIZED },       	{ SIP_402_PAYMENT_REQUIRED },       	{ SIP_403_FORBIDDEN },       	{ SIP_404_NOT_FOUND },       	{ SIP_405_METHOD_NOT_ALLOWED },       	{ SIP_406_NOT_ACCEPTABLE },       	{ SIP_407_PROXY_AUTH_REQUIRED },       	{ SIP_408_REQUEST_TIMEOUT },       	{ SIP_409_CONFLICT },       	{ SIP_410_GONE },       	{ SIP_411_LENGTH_REQUIRED },       	{ SIP_413_REQUEST_TOO_LARGE },       	{ SIP_414_REQUEST_URI_TOO_LONG },       	{ SIP_415_UNSUPPORTED_MEDIA },       	{ SIP_416_UNSUPPORTED_URI },       	{ SIP_420_BAD_EXTENSION },       	{ SIP_421_EXTENSION_REQUIRED },       	{ SIP_422_SESSION_TIMER_TOO_SMALL },       	{ SIP_423_INTERVAL_TOO_BRIEF },       	{ SIP_423_REGISTRATION_TOO_BRIEF },       	{ SIP_480_TEMPORARILY_UNAVAILABLE },       	{ SIP_481_NO_TRANSACTION },       	{ SIP_481_NO_CALL },       	{ SIP_482_LOOP_DETECTED },       	{ SIP_483_TOO_MANY_HOPS },       	{ SIP_484_ADDRESS_INCOMPLETE },       	{ SIP_485_AMBIGUOUS },       	{ SIP_486_BUSY_HERE },       	{ SIP_487_REQUEST_TERMINATED },       	{ SIP_487_REQUEST_CANCELLED },       	{ SIP_488_NOT_ACCEPTABLE },       	{ SIP_489_BAD_EVENT },       	{ SIP_491_REQUEST_PENDING },       	{ SIP_493_UNDECIPHERABLE },       	{ SIP_500_INTERNAL_SERVER_ERROR },       	{ SIP_501_NOT_IMPLEMENTED },       	{ SIP_502_BAD_GATEWAY },       	{ SIP_503_SERVICE_UNAVAILABLE },       	{ SIP_504_GATEWAY_TIME_OUT },       	{ SIP_505_VERSION_NOT_SUPPORTED },       	{ SIP_513_MESSAGE_TOO_LARGE },       	{ SIP_600_BUSY_EVERYWHERE },       	{ SIP_603_DECLINE },       	{ SIP_604_DOES_NOT_EXIST_ANYWHERE },       	{ SIP_606_NOT_ACCEPTABLE },	{ 0, NULL }      };    int i;    for (i = 0; errors[i].status; i++)      TEST_S(errors[i].phrase, sip_status_phrase(errors[i].status));  }  END();}/** Test parser and header manipulation */static int parser_test(void){  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_hide_t        sip_hide[1] = { SIP_HIDE_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_also_t        sip_also[1] = { SIP_ALSO_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() };

⌨️ 快捷键说明

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