📄 test_nta.c
字号:
} nta_leg_destroy(ag->ag_alice_leg), ag->ag_alice_leg = NULL; nta_leg_destroy(ag->ag_bob_leg), ag->ag_bob_leg = NULL; END();}/* ---------------------------------------------------------------------- *//* Test INVITE, dialogs */staticint test_for_ack(agent_t *ag, nta_incoming_t *irq, sip_t const *sip){ sip_method_t method; BEGIN(); method = sip ? sip->sip_request->rq_method : sip_method_unknown; nta_incoming_destroy(irq); TEST(irq, ag->ag_irq); ag->ag_irq = NULL; TEST(method, sip_method_ack); ag->ag_status = 200; END();}staticint test_for_prack(agent_t *ag, nta_reliable_t *rel, nta_incoming_t *prack, sip_t const *sip){ sip_method_t method = sip ? sip->sip_request->rq_method : sip_method_unknown; nta_incoming_treply(ag->ag_irq, SIP_200_OK, SIPTAG_CONTACT(ag->ag_m_alice), TAG_END()); TEST(method, sip_method_prack); return 200;}int alice_leg_callback(agent_t *ag, nta_leg_t *leg, nta_incoming_t *irq, sip_t const *sip){ BEGIN(); if (tstflags & tst_verbatim) { printf("%s: %s: %s " URL_PRINT_FORMAT " %s\n", name, __func__, sip->sip_request->rq_method_name, URL_PRINT_ARGS(sip->sip_request->rq_url), sip->sip_request->rq_version); } TEST_1(sip->sip_content_length); TEST_1(sip->sip_via); TEST_1(sip->sip_from && sip->sip_from->a_tag); if (sip->sip_request->rq_method == sip_method_prack) return 481; ag->ag_latest_leg = leg; if (leg != ag->ag_alice_leg) { leg_match(ag, leg, 1, __func__); return 500; } if (sip->sip_request->rq_method == sip_method_invite) { TEST_1(sip_has_feature(sip->sip_supported, "100rel")); nta_incoming_bind(irq, test_for_ack, ag); nta_incoming_treply(irq, SIP_100_TRYING, TAG_END()); nta_agent_set_params(ag->ag_agent, NTATAG_DEBUG_DROP_PROB(ag->ag_drop), TAG_END()); ag->ag_reliable = nta_reliable_treply(irq, NULL, NULL, SIP_183_SESSION_PROGRESS, SIPTAG_CONTENT_TYPE(ag->ag_content_type), SIPTAG_PAYLOAD(ag->ag_payload), SIPTAG_CONTACT(ag->ag_m_alice), TAG_END()); TEST_1(ag->ag_reliable); ag->ag_reliable = nta_reliable_treply(irq, NULL, NULL, 184, "Next", SIPTAG_CONTACT(ag->ag_m_alice), TAG_END()); TEST_1(ag->ag_reliable); ag->ag_reliable = nta_reliable_treply(irq, test_for_prack, ag, 185, "Last", SIPTAG_CONTACT(ag->ag_m_alice), TAG_END()); TEST_1(ag->ag_reliable); ag->ag_irq = irq; return 0; } if (sip->sip_request->rq_method == sip_method_bye) { leg_zap(ag, leg); } return 200; END();}int bob_leg_callback(agent_t *ag, nta_leg_t *leg, nta_incoming_t *irq, sip_t const *sip){ BEGIN(); if (tstflags & tst_verbatim) { printf("%s: %s: %s " URL_PRINT_FORMAT " %s\n", name, __func__, sip->sip_request->rq_method_name, URL_PRINT_ARGS(sip->sip_request->rq_url), sip->sip_request->rq_version); } TEST_1(sip->sip_content_length); TEST_1(sip->sip_via); TEST_1(sip->sip_from && sip->sip_from->a_tag); if (sip->sip_request->rq_method == sip_method_prack) return 481; ag->ag_latest_leg = leg; if (ag->ag_bob_leg && leg != ag->ag_bob_leg) { leg_match(ag, leg, 1, __func__); return 500; } if (ag->ag_bob_leg == NULL) { nta_leg_bind(leg, leg_callback_500, ag); ag->ag_bob_leg = nta_leg_tcreate(ag->ag_agent, bob_leg_callback, ag, SIPTAG_CALL_ID(sip->sip_call_id), SIPTAG_FROM(sip->sip_to), SIPTAG_TO(sip->sip_from), TAG_END()); TEST_1(ag->ag_bob_leg); TEST_1(nta_leg_tag(ag->ag_bob_leg, NULL)); TEST_1(nta_leg_get_tag(ag->ag_bob_leg)); TEST_1(nta_incoming_tag(irq, nta_leg_get_tag(ag->ag_bob_leg))); TEST(nta_leg_server_route(ag->ag_bob_leg, sip->sip_record_route, sip->sip_contact), 0); } if (sip->sip_request->rq_method == sip_method_invite) { nta_incoming_bind(irq, test_for_ack, ag); #if 1 nta_incoming_treply(irq, SIP_180_RINGING, SIPTAG_CONTACT(ag->ag_m_bob), TAG_END()); nta_incoming_treply(irq, SIP_180_RINGING, SIPTAG_CONTACT(ag->ag_m_bob), TAG_END());#endif nta_incoming_treply(irq, SIP_200_OK, SIPTAG_CONTENT_TYPE(ag->ag_content_type), SIPTAG_PAYLOAD(ag->ag_payload), SIPTAG_CONTACT(ag->ag_m_bob), TAG_END()); ag->ag_irq = irq; return 0; } else { return 200; } END();}int outgoing_invite_callback(agent_t *ag, nta_outgoing_t *orq, sip_t const *sip){ BEGIN(); int status = sip->sip_status->st_status; if (tstflags & tst_verbatim) { printf("%s: %s: %s %03d %s\n", name, __func__, sip->sip_status->st_version, sip->sip_status->st_status, sip->sip_status->st_phrase); } { msg_t *msg; TEST_1(msg = nta_outgoing_getresponse(orq)); TEST_1(msg->m_refs == 2); TEST_1(sip_object(msg) == sip); if (ag->ag_probe_msg == NULL) ag->ag_probe_msg = msg; msg_destroy(msg); } if (status < 200) { if (sip->sip_require && sip_has_feature(sip->sip_require, "100rel")) { TEST_1(sip->sip_rseq); orq = nta_outgoing_prack(ag->ag_call_leg, orq, NULL, NULL, NULL, sip, TAG_END()); TEST_1(orq); nta_outgoing_destroy(orq); } return 0; } if (status < 300) { nta_outgoing_t *ack; TEST_1(nta_leg_rtag(ag->ag_call_leg, sip->sip_to->a_tag)); TEST(nta_leg_client_route(ag->ag_call_leg, sip->sip_record_route, sip->sip_contact), 0); ack = nta_outgoing_tcreate(ag->ag_call_leg, NULL, NULL, NULL, SIP_METHOD_ACK, NULL, SIPTAG_CSEQ(sip->sip_cseq), TAG_END()); TEST_1(ack); nta_outgoing_destroy(ack); } else { ag->ag_status = status; } TEST_1(sip->sip_to && sip->sip_to->a_tag); nta_outgoing_destroy(orq); ag->ag_orq = NULL; ag->ag_call_leg = NULL; return 0; END();}int test_call(agent_t *ag){ sip_content_type_t *c = ag->ag_content_type; sip_payload_t *sdp = ag->ag_payload; nta_leg_t *old_leg; BEGIN(); /* * Test establishing a call * * Alice sends a INVITE to Bob, then Bob sends 200 Ok. */ TEST_1(ag->ag_alice_leg = nta_leg_tcreate(ag->ag_agent, alice_leg_callback, ag, SIPTAG_FROM(ag->ag_alice), SIPTAG_TO(ag->ag_bob), TAG_END())); TEST_1(nta_leg_tag(ag->ag_alice_leg, NULL)); nta_leg_bind(ag->ag_server_leg, bob_leg_callback, ag); /* Send INVITE */ ag->ag_expect_leg = ag->ag_server_leg; TEST_1(ag->ag_orq = nta_outgoing_tcreate(ag->ag_call_leg = ag->ag_alice_leg, outgoing_invite_callback, ag, ag->ag_obp, SIP_METHOD_INVITE, (url_string_t *)ag->ag_m_bob->m_url, SIPTAG_SUBJECT_STR("Call 1"), SIPTAG_CONTACT(ag->ag_m_alice), SIPTAG_CONTENT_TYPE(c), SIPTAG_ACCEPT_CONTACT_STR("*;audio"), SIPTAG_PAYLOAD(sdp), NTATAG_USE_TIMESTAMP(1), NTATAG_PASS_100(1), TAG_END())); /* Try to CANCEL it immediately */ TEST_1(nta_outgoing_cancel(ag->ag_orq) == 0); /* As Bob immediately answers INVITE with 200 Ok, cancel should be answered with 487. */ nta_test_run(ag); TEST(ag->ag_status, 200); TEST(ag->ag_orq, NULL); TEST(ag->ag_latest_leg, ag->ag_server_leg); TEST_1(ag->ag_bob_leg != NULL); /* Re-INVITE from Bob to Alice. * * Alice first sends 183, waits for PRACK, then sends 184 and 185, * waits for PRACKs, then sends 200, waits for ACK. */ ag->ag_expect_leg = ag->ag_alice_leg; TEST_1(ag->ag_orq = nta_outgoing_tcreate(ag->ag_call_leg = ag->ag_bob_leg, outgoing_invite_callback, ag, NULL, SIP_METHOD_INVITE, NULL, SIPTAG_SUBJECT_STR("Re-INVITE"), SIPTAG_CONTACT(ag->ag_m_bob), SIPTAG_SUPPORTED_STR("foo"), SIPTAG_CONTENT_TYPE(c), SIPTAG_PAYLOAD(sdp), TAG_END())); nta_test_run(ag); TEST(ag->ag_status, 200); TEST(ag->ag_orq, NULL); TEST(ag->ag_latest_leg, ag->ag_alice_leg); nta_agent_set_params(ag->ag_agent, NTATAG_DEBUG_DROP_PROB(0), TAG_END()); /* Send BYE from Bob to Alice */ old_leg = ag->ag_expect_leg = ag->ag_alice_leg; TEST_1(ag->ag_orq = nta_outgoing_tcreate(ag->ag_bob_leg, outgoing_callback, ag, NULL, SIP_METHOD_BYE, NULL, SIPTAG_SUBJECT_STR("Hangup"), SIPTAG_FROM(ag->ag_alice), SIPTAG_TO(ag->ag_bob), SIPTAG_CONTACT(ag->ag_m_alice), SIPTAG_CONTENT_TYPE(c), SIPTAG_PAYLOAD(sdp), TAG_END())); nta_test_run(ag); TEST(ag->ag_status, 200); TEST(ag->ag_orq, NULL); TEST(ag->ag_latest_leg, old_leg); TEST(ag->ag_alice_leg, NULL); nta_leg_destroy(ag->ag_bob_leg), ag->ag_bob_leg = NULL; ag->ag_latest_leg = NULL; ag->ag_call_leg = NULL; END();}/* ============================================================================ *//* Test early dialogs, PRACK */int test_for_ack_or_timeout(agent_t *ag, nta_incoming_t *irq, sip_t const *sip){ BEGIN(); sip_method_t method = sip ? sip->sip_request->rq_method : sip_method_unknown; nta_incoming_destroy(irq); TEST(irq, ag->ag_irq); ag->ag_irq = NULL; if (sip) { TEST(method, sip_method_ack); ag->ag_status = 200; } else { if (ag->ag_bob_leg) { nta_leg_destroy(ag->ag_bob_leg), ag->ag_bob_leg = NULL; } } return 0; END();}/* */int bob_leg_callback2(agent_t *ag, nta_leg_t *leg, nta_incoming_t *irq, sip_t const *sip){ BEGIN(); if (tstflags & tst_verbatim) { printf("%s: %s: %s " URL_PRINT_FORMAT " %s\n", name, __func__, sip->sip_request->rq_method_name, URL_PRINT_ARGS(sip->sip_request->rq_url), sip->sip_request->rq_version); } TEST_1(sip->sip_content_length); TEST_1(sip->sip_via); TEST_1(sip->sip_from && sip->sip_from->a_tag); ag->ag_latest_leg = leg; if (ag->ag_bob_leg && leg != ag->ag_bob_leg) { leg_match(ag, leg, 1, __func__); return 500; } if (ag->ag_bob_leg == NULL) { nta_leg_bind(leg, leg_callback_500, ag); ag->ag_bob_leg = nta_leg_tcreate(ag->ag_agent, bob_leg_callback, ag, SIPTAG_CALL_ID(sip->sip_call_id), SIPTAG_FROM(sip->sip_to), SIPTAG_TO(sip->sip_from), TAG_END()); TEST_1(ag->ag_bob_leg); TEST_1(nta_leg_tag(ag->ag_bob_leg, NULL)); TEST_1(nta_leg_get_tag(ag->ag_bob_leg)); TEST_1(nta_incoming_tag(irq, nta_leg_get_tag(ag->ag_bob_leg))); TEST(nta_leg_server_route(ag->ag_bob_leg, sip->sip_record_route, sip->sip_contact), 0); } if (sip->sip_request->rq_method == sip_method_invite) { nta_incoming_bind(irq, test_for_ack_or_timeout, ag); nta_incoming_treply(irq, SIP_183_SESSION_PROGRESS, SIPTAG_CONTENT_TYPE(ag->ag_content_type), SIPTAG_PAYLOAD(ag->ag_payload), SIPTAG_CONTACT(ag->ag_m_bob), TAG_END()); if (0) nta_incoming_treply(irq, SIP_180_RINGING, SIPTAG_CONTENT_TYPE(ag->ag_content_type), SIPTAG_PAYLOAD(ag->ag_payload), SIPTAG_CONTACT(ag->ag_m_bob), TAG_END()); nta_incoming_treply(irq, SIP_200_OK, SIPTAG_CONTACT(ag->ag_m_bob), TAG_END()); ag->ag_irq = irq; return 0; } else { return 200; } END();}int invite_prack_callback(agent_t *ag, nta_outgoing_t *orq, sip_t const *sip){ BEGIN(); int status = sip->sip_status->st_status; if (tstflags & tst_verbatim) { printf("%s: %s: %s %03d %s\n", name, __func__, sip->sip_status->st_version, sip->sip_status->st_status, sip->sip_status->st_phrase); } if (!ag->ag_call_tag && (status >= 200 || (status > 100 && sip->sip_rseq))) { nta_outgoing_t *tagged; TEST_1(sip->sip_to->a_tag); ag->ag_tag_status = status; ag->ag_call_tag = su_strdup(ag->ag_home, sip->sip_to->a_tag); TEST_S(ag->ag_call_tag, sip->sip_to->a_tag); TEST_S(nta_leg_rtag(ag->ag_c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -