📄 test_nua.c
字号:
__FILE__, __LINE__); a_uri = NULL; } if (print_headings) { if (ctx->nat && a_uri) { printf("TEST NUA-2.1.2: PASSED\n"); } else { printf("TEST NUA-2.1.2: FAILED\n"); } } } if (print_headings) printf("TEST NUA-2.2.1: init endpoint A\n"); if (a_uri == NULL) a_uri = p_uri; ctx->a.instance = nua_generate_instance_identifier(ctx->home); ctx->a.nua = nua_create(ctx->root, a_callback, ctx, NUTAG_PROXY(a_uri ? a_uri : o_proxy), SIPTAG_FROM_STR("sip:alice@example.com"), NUTAG_URL(a_bind), TAG_IF(a_bind != a_bind2, NUTAG_SIPS_URL(a_bind2)), SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"), NTATAG_SIP_T1X64(4000), NUTAG_INSTANCE(ctx->a.instance), TAG_END()); TEST_1(ctx->a.nua); nua_get_params(ctx->a.nua, TAG_ANY(), TAG_END()); run_a_until(ctx, nua_r_get_params, save_until_final_response); TEST_1(e = ctx->a.events->head); TEST(tl_gets(e->data->e_tags, NTATAG_CONTACT_REF(m), SIPTAG_FROM_REF(sipaddress), TAG_END()), 2); TEST_1(m); TEST_1(ctx->a.contact = sip_contact_dup(ctx->home, m)); TEST_1(ctx->a.to = sip_to_dup(ctx->home, sipaddress)); free_events_in_list(ctx, ctx->a.events); if (print_headings) printf("TEST NUA-2.2.1: PASSED\n"); if (print_headings) printf("TEST NUA-2.2.2: init endpoint B\n"); ctx->b.instance = nua_generate_instance_identifier(ctx->home); ctx->b.nua = nua_create(ctx->root, b_callback, ctx, NUTAG_PROXY(p_uri ? p_uri : o_proxy), SIPTAG_FROM_STR("sip:bob@example.org"), NUTAG_URL("sip:0.0.0.0:*"), SOATAG_USER_SDP_STR("m=audio 5006 RTP/AVP 8 0"), NUTAG_INSTANCE(ctx->b.instance), TAG_END()); TEST_1(ctx->b.nua); nua_get_params(ctx->b.nua, TAG_ANY(), TAG_END()); run_b_until(ctx, nua_r_get_params, save_until_final_response); TEST_1(e = ctx->b.events->head); TEST(tl_gets(e->data->e_tags, NTATAG_CONTACT_REF(m), SIPTAG_FROM_REF(sipaddress), TAG_END()), 2); TEST_1(m); TEST_1(ctx->b.contact = sip_contact_dup(ctx->home, m)); TEST_1(ctx->b.to = sip_to_dup(ctx->home, sipaddress)); free_events_in_list(ctx, ctx->b.events); if (print_headings) printf("TEST NUA-2.2.2: PASSED\n"); if (print_headings) printf("TEST NUA-2.2.3: init endpoint C\n"); /* ctx->c.instance = nua_generate_instance_identifier(ctx->home); */ ctx->c.nua = nua_create(ctx->root, c_callback, ctx, NUTAG_PROXY(p_uri ? p_uri : o_proxy), SIPTAG_FROM_STR("sip:charlie@example.net"), NUTAG_URL("sip:0.0.0.0:*"), SOATAG_USER_SDP_STR("m=audio 5400 RTP/AVP 8 0"), NUTAG_INSTANCE(ctx->c.instance), TAG_END()); TEST_1(ctx->c.nua); nua_get_params(ctx->c.nua, TAG_ANY(), TAG_END()); run_c_until(ctx, nua_r_get_params, save_until_final_response); TEST_1(e = ctx->c.events->head); TEST(tl_gets(e->data->e_tags, NTATAG_CONTACT_REF(m), SIPTAG_FROM_REF(sipaddress), TAG_END()), 2); TEST_1(m); TEST_1(ctx->c.contact = sip_contact_dup(ctx->home, m)); TEST_1(ctx->c.to = sip_to_dup(ctx->home, sipaddress)); free_events_in_list(ctx, ctx->c.events); if (print_headings) printf("TEST NUA-2.2.3: PASSED\n"); END();}/* ======================================================================== *//* Test REGISTER */int test_register(struct context *ctx){ if (!ctx->proxy_tests) return 0; /* No proxy */ BEGIN(); struct endpoint *a = &ctx->a, *b = &ctx->b, *c = &ctx->c; struct call *a_reg = a->reg, *b_reg = b->reg, *c_reg = c->reg; struct event *e; sip_t const *sip; if (ctx->p) test_proxy_set_expiration(ctx->p, 5, 5, 10); if (print_headings) printf("TEST NUA-2.3.0.1: un-REGISTER a\n"); TEST_1(a_reg->nh = nua_handle(a->nua, a_reg, TAG_END())); UNREGISTER(a, a_reg, a_reg->nh, SIPTAG_TO(a->to), SIPTAG_CONTACT_STR("*"), TAG_END()); run_a_until(ctx, -1, until_final_response); AUTHENTICATE(a, a_reg, a_reg->nh, NUTAG_AUTH("Digest:\"test-proxy\":alice:secret"), TAG_END()); run_a_until(ctx, -1, until_final_response); nua_handle_destroy(a_reg->nh); if (print_headings) printf("TEST NUA-2.3.0.1: PASSED\n"); if (print_headings) printf("TEST NUA-2.3.0.2: un-REGISTER b\n"); TEST_1(b_reg->nh = nua_handle(b->nua, b_reg, TAG_END())); UNREGISTER(b, b_reg, b_reg->nh, SIPTAG_TO(b->to), SIPTAG_CONTACT_STR("*"), TAG_END()); run_b_until(ctx, -1, until_final_response); AUTHENTICATE(b, b_reg, b_reg->nh, NUTAG_AUTH("Digest:\"test-proxy\":bob:secret"), TAG_END()); run_b_until(ctx, -1, until_final_response); nua_handle_destroy(b_reg->nh); if (print_headings) printf("TEST NUA-2.3.0.2: PASSED\n"); if (print_headings) printf("TEST NUA-2.3.0.3: un-REGISTER c\n"); TEST_1(c_reg->nh = nua_handle(c->nua, c_reg, TAG_END())); UNREGISTER(c, c_reg, c_reg->nh, SIPTAG_TO(c->to), SIPTAG_CONTACT_STR("*"), TAG_END()); run_c_until(ctx, -1, until_final_response); AUTHENTICATE(c, c_reg, c_reg->nh, NUTAG_AUTH("Digest:\"test-proxy\":charlie:secret"), TAG_END()); run_c_until(ctx, -1, until_final_response); nua_handle_destroy(c_reg->nh); if (print_headings) printf("TEST NUA-2.3.0.3: PASSED\n");/* REGISTER test A B |------REGISTER----->| |<-------401---------| |------REGISTER----->| |<-------200---------| | |*/ if (print_headings) printf("TEST NUA-2.3.1: REGISTER a\n"); TEST_1(a_reg->nh = nua_handle(a->nua, a_reg, TAG_END())); REGISTER(a, a_reg, a_reg->nh, SIPTAG_TO(a->to), NUTAG_OUTBOUND("natify options-keepalive validate"), NUTAG_KEEPALIVE(1000), TAG_END()); run_a_until(ctx, -1, save_until_final_response); TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_register); TEST_1(sip = sip_object(e->data->e_msg)); TEST(e->data->e_status, 401); TEST(sip->sip_status->st_status, 401); TEST_1(!sip->sip_contact); TEST_1(!e->next); free_events_in_list(ctx, a->events); AUTHENTICATE(a, a_reg, a_reg->nh, NUTAG_AUTH("Digest:\"test-proxy\":alice:secret"), TAG_END()); run_a_until(ctx, -1, save_until_final_response); TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_register); TEST(e->data->e_status, 200); TEST_1(sip = sip_object(e->data->e_msg)); TEST_1(sip->sip_contact); TEST_1(!e->next); free_events_in_list(ctx, a->events); if (ctx->nat) { TEST_1(e = a->specials->head); } if (print_headings) printf("TEST NUA-2.3.1: PASSED\n"); if (print_headings) printf("TEST NUA-2.3.2: REGISTER b\n"); TEST_1(b_reg->nh = nua_handle(b->nua, b_reg, TAG_END())); REGISTER(b, b_reg, b_reg->nh, SIPTAG_TO(b->to), TAG_END()); run_b_until(ctx, -1, save_until_final_response); TEST_1(e = b->events->head); TEST_E(e->data->e_event, nua_r_register); TEST_1(sip = sip_object(e->data->e_msg)); TEST(e->data->e_status, 401); TEST(sip->sip_status->st_status, 401); TEST_1(!sip->sip_contact); TEST_1(!e->next); free_events_in_list(ctx, b->events); AUTHENTICATE(b, b_reg, b_reg->nh, NUTAG_AUTH("Digest:\"test-proxy\":bob:secret"), TAG_END()); run_b_until(ctx, -1, save_until_final_response); TEST_1(e = b->events->head); TEST_E(e->data->e_event, nua_r_register); TEST(e->data->e_status, 200); TEST_1(sip = sip_object(e->data->e_msg)); TEST_1(sip->sip_contact); TEST_1(!e->next); free_events_in_list(ctx, b->events); if (print_headings) printf("TEST NUA-2.3.2: PASSED\n"); if (ctx->p) test_proxy_set_expiration(ctx->p, 30, 3600, 36000); if (print_headings) printf("TEST NUA-2.3.3: REGISTER c\n"); TEST_1(c_reg->nh = nua_handle(c->nua, c_reg, TAG_END())); REGISTER(c, c_reg, c_reg->nh, SIPTAG_TO(c->to), SIPTAG_EXPIRES_STR("5"), /* Test 423 negotiation */ TAG_END()); run_c_until(ctx, -1, save_until_final_response); TEST_1(e = c->events->head); TEST_E(e->data->e_event, nua_r_register); TEST_1(sip = sip_object(e->data->e_msg)); TEST(e->data->e_status, 401); TEST(sip->sip_status->st_status, 401); TEST_1(!sip->sip_contact); TEST_1(!e->next); free_events_in_list(ctx, c->events); AUTHENTICATE(c, c_reg, c_reg->nh, NUTAG_AUTH("Digest:\"test-proxy\":charlie:secret"), TAG_END()); run_c_until(ctx, -1, save_until_final_response); TEST_1(e = c->events->head); TEST_E(e->data->e_event, nua_r_register); TEST(e->data->e_status, 100); TEST_1(sip = sip_object(e->data->e_msg)); TEST(sip->sip_status->st_status, 423); TEST_1(e = e->next); TEST(e->data->e_status, 200); TEST_1(sip = sip_object(e->data->e_msg)); TEST_1(sip->sip_contact); TEST_1(!e->next); free_events_in_list(ctx, c->events); if (print_headings) printf("TEST NUA-2.3.3: PASSED\n"); if (!ctx->p) return 0; if (print_headings) printf("TEST NUA-2.3.4: refresh REGISTER\n"); /* Wait for A and B to refresh their registrations */ run_ab_until(ctx, -1, save_until_final_response, -1, save_until_final_response); TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_register); TEST(e->data->e_status, 200); TEST_1(sip = sip_object(e->data->e_msg)); TEST_1(sip->sip_contact); TEST_S(sip->sip_contact->m_expires, "3600"); TEST_1(!e->next); free_events_in_list(ctx, a->events); TEST_1(e = b->events->head); TEST_E(e->data->e_event, nua_r_register); TEST(e->data->e_status, 200); TEST_1(sip = sip_object(e->data->e_msg)); TEST_1(sip->sip_contact); TEST_S(sip->sip_contact->m_expires, "3600"); TEST_1(!e->next); free_events_in_list(ctx, b->events); if (print_headings) printf("TEST NUA-2.3.4: PASSED\n"); END();}int test_connectivity(struct context *ctx){ if (!ctx->proxy_tests) return 0; /* No proxy */ BEGIN(); struct endpoint *a = &ctx->a, *b = &ctx->b, *c = &ctx->c; struct call *a_call = a->call, *b_call = b->call, *c_call = c->call; struct event *e; sip_t const *sip; /* Connectivity test using OPTIONS */ if (print_headings) printf("TEST NUA-2.4.1: OPTIONS from A to B\n"); TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END())); OPTIONS(a, a_call, a_call->nh, TAG_IF(!ctx->proxy_tests, NUTAG_URL(b->contact->m_url)), TAG_END()); run_ab_until(ctx, -1, save_until_final_response, -1, save_until_received); /* Client events: nua_options(), nua_r_options */ TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_options); TEST(e->data->e_status, 200); TEST_1(sip = sip_object(e->data->e_msg)); TEST_1(sip->sip_allow); TEST_1(sip->sip_accept); TEST_1(sip->sip_supported); /* TEST_1(sip->sip_content_type); */ /* TEST_1(sip->sip_payload); */ TEST_1(!e->next); free_events_in_list(ctx, a->events); nua_handle_destroy(a_call->nh), a_call->nh = NULL; /* Server events: nua_i_options */ TEST_1(e = b->events->head); TEST_E(e->data->e_event, nua_i_options); TEST(e->data->e_status, 200); TEST_1(!e->next); free_events_in_list(ctx, b->events); nua_handle_destroy(b_call->nh), b_call->nh = NULL; if (print_headings) printf("TEST NUA-2.4.1: PASSED\n"); if (print_headings) printf("TEST NUA-2.4.2: OPTIONS from B to C\n"); TEST_1(b_call->nh = nua_handle(b->nua, b_call, SIPTAG_TO(c->to), TAG_END())); OPTIONS(b, b_call, b_call->nh, TAG_IF(!ctx->proxy_tests, NUTAG_URL(c->contact->m_url)), TAG_END()); run_abc_until(ctx, -1, NULL, -1, save_until_final_response, -1, save_until_received); /* Client events: nua_options(), nua_r_options */ TEST_1(e = b->events->head); TEST_E(e->data->e_event, nua_r_options); TEST(e->data->e_status, 200); TEST_1(sip = sip_object(e->data->e_msg)); TEST_1(sip->sip_allow); TEST_1(sip->sip_accept); TEST_1(sip->sip_supported); /* TEST_1(sip->sip_content_type); */ /* TEST_1(sip->sip_payload); */ TEST_1(!e->next); free_events_in_list(ctx, b->events); nua_handle_destroy(b_call->nh), b_call->nh = NULL; /* Server events: nua_i_options */ TEST_1(e = c->events->head); TEST_E(e->data->e_event, nua_i_options); TEST(e->data->e_status, 200); TEST_1(!e->next); free_events_in_list(ctx, c->events); nua_handle_destroy(c_call->nh), c_call->nh = NULL; if (print_headings) printf("TEST NUA-2.4.2: PASSED\n"); if (print_headings) printf("TEST NUA-2.4.3: OPTIONS from C to A\n"); TEST_1(c_call->nh = nua_handle(c->nua, c_call, SIPTAG_TO(a->to), TAG_END())); OPTIONS(c, c_call, c_call->nh, TAG_IF(!ctx->proxy_tests, NUTAG_URL(a->contact->m_url)), TAG_END()); run_abc_until(ctx, -1, save_until_received, -1, NULL, -1, save_until_final_response); /* Client events: nua_options(), nua_r_options */ TEST_1(e = c->events->head); TEST_E(e->data->e_event, nua_r_options); TEST(e->data->e_status, 200); TEST_1(sip = sip_object(e->data->e_msg)); TEST_1(sip->sip_allow); TEST_1(sip->sip_accept); TEST_1(sip->sip_supported); /* TEST_1(sip->sip_content_type); */ /* TEST_1(sip->sip_payload); */ TEST_1(!e->next); free_events_in_list(ctx, c->events); nua_handle_destroy(c_call->nh), c_call->nh = NULL; /* Server events: nua_i_options */ TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_i_options); TEST(e->data->e_status, 200); TEST_1(!e->next); free_events_in_list(ctx, a->events); nua_handle_destroy(a_call->nh), a_call->nh = NULL; if (print_headings) printf("TEST NUA-2.4.3: PASSED\n"); END();}int test_nat_timeout(struct context *ctx){ if (!ctx->proxy_tests || !ctx->nat) return 0; /* No proxy */ BEGIN(); struct endpoint *a = &ctx->a, *b = &ctx->b, *c = &ctx->c; struct event *e; sip_t const *sip; /* Test what happens when NAT bindings go away */ if (print_headings) printf("TEST NUA-2.5.1: NAT binding change\n"); free_events_in_list(ctx, a->specials); test_nat_flush(ctx->nat); /* Break our connections */ /* Run until we get final response to REGISTER */ run_a_until(ctx, -1, save_until_final_response); TEST_1(e = a->specials->head); TEST_E(e->data->e_event, nua_i_outbound); TEST(e->data->e_status, 102); TEST_S(e->data->e_phrase, "NAT binding changed"); TEST_1(!e->next); free_events_in_list(ctx, a->specials); TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_register); TEST(e->data->e_status, 200);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -