📄 test_nua.c
字号:
/* Respond via endpoint and handle */int respond(struct endpoint *ep, struct call *call, nua_handle_t *nh, int status, char const *phrase, tag_type_t tag, tag_value_t value, ...){ ta_list ta; ta_start(ta, tag, value); if (ep->printer) ep->printer(-1, "nua_respond", status, phrase, ep->nua, ep->ctx, ep, nh, call, NULL, ta_args(ta)); nua_respond(nh, status, phrase, ta_tags(ta)); ta_end(ta); return 0;}/* Reject all but currently used handles */struct call *check_handle(struct endpoint *ep, struct call *call, nua_handle_t *nh, int status, char const *phrase){ if (call) return call; if (status) respond(ep, call, nh, status, phrase, TAG_END()); nua_handle_destroy(nh); return NULL;}static voidcall_init(struct call *call){ call->events.tail = &call->events.head;}/* Save nua event in call-specific list */staticint save_event_in_list(struct context *ctx, nua_event_t nevent, struct endpoint *ep, struct call *call){ struct event *e; if (nevent == nua_i_active || nevent == nua_i_terminated) return 0; e = su_zalloc(ctx->home, sizeof *e); if (!e) { perror("su_zalloc"), abort(); } if (!nua_save_event(ep->nua, e->saved_event)) { su_free(ctx->home, e); return -1; } *(e->prev = call->events.tail) = e; call->events.tail = &e->next; e->data = nua_event_data(e->saved_event); return 1;}/* Save nua event in endpoint list */staticvoid free_events_in_list(struct context *ctx, struct call *call){ struct event *e; while ((e = call->events.head)) { if ((*e->prev = e->next)) e->next->prev = e->prev; nua_destroy_event(e->saved_event); su_free(ctx->home, e); } call->events.tail = &call->events.head;}void nolog(void *stream, char const *fmt, va_list ap) {}int check_set_status(int status, char const *phrase){ return status == 200 && strcmp(phrase, sip_200_OK) == 0;}int test_api_errors(struct context *ctx){ BEGIN(); /* Invoke every API function with invalid arguments */ int level; int status; char const *phrase; if (print_headings) printf("TEST NUA-1.0: test API\n"); /* This is a nasty macro. Test it. */#define SET_STATUS1(x) ((status = x), status), (phrase = ((void)x)) TEST_1(check_set_status(SET_STATUS1(SIP_200_OK))); TEST(status, 200); TEST_S(phrase, sip_200_OK); su_log_init(nua_log); level = nua_log->log_level; if (!(tstflags & tst_verbatim)) su_log_set_level(nua_log, 0); TEST_1(!nua_create(NULL, NULL, NULL, TAG_END())); TEST_VOID(nua_shutdown(NULL)); TEST_VOID(nua_destroy(NULL)); TEST_VOID(nua_set_params(NULL, TAG_END())); TEST_VOID(nua_get_params(NULL, TAG_END())); TEST_1(!nua_default(NULL)); TEST_1(!nua_handle(NULL, NULL, TAG_END())); TEST_VOID(nua_handle_destroy(NULL)); TEST_VOID(nua_handle_bind(NULL, NULL)); TEST_1(!nua_handle_has_invite(NULL)); TEST_1(!nua_handle_has_subscribe(NULL)); TEST_1(!nua_handle_has_register(NULL)); TEST_1(!nua_handle_has_active_call(NULL)); TEST_1(!nua_handle_has_call_on_hold(NULL)); TEST_1(!nua_handle_has_events(NULL)); TEST_1(!nua_handle_has_registrations(NULL)); TEST_1(!nua_handle_remote(NULL)); TEST_1(!nua_handle_local(NULL)); TEST_S(nua_event_name(-1), "NUA_UNKNOWN"); TEST_VOID(nua_register(NULL, TAG_END())); TEST_VOID(nua_unregister(NULL, TAG_END())); TEST_VOID(nua_invite(NULL, TAG_END())); TEST_VOID(nua_ack(NULL, TAG_END())); TEST_VOID(nua_options(NULL, TAG_END())); TEST_VOID(nua_publish(NULL, TAG_END())); TEST_VOID(nua_message(NULL, TAG_END())); TEST_VOID(nua_chat(NULL, TAG_END())); TEST_VOID(nua_info(NULL, TAG_END())); TEST_VOID(nua_subscribe(NULL, TAG_END())); TEST_VOID(nua_unsubscribe(NULL, TAG_END())); TEST_VOID(nua_notify(NULL, TAG_END())); TEST_VOID(nua_notifier(NULL, TAG_END())); TEST_VOID(nua_terminate(NULL, TAG_END())); TEST_VOID(nua_refer(NULL, TAG_END())); TEST_VOID(nua_update(NULL, TAG_END())); TEST_VOID(nua_bye(NULL, TAG_END())); TEST_VOID(nua_cancel(NULL, TAG_END())); TEST_VOID(nua_authenticate(NULL, TAG_END())); TEST_VOID(nua_redirect(NULL, TAG_END())); TEST_VOID(nua_respond(NULL, 0, "", TAG_END())); TEST_1(!nua_handle_home(NULL)); TEST_1(!nua_save_event(NULL, NULL)); TEST_1(!nua_event_data(NULL)); TEST_VOID(nua_destroy_event(NULL)); { nua_saved_event_t event[1]; memset(event, 0, sizeof event); TEST_1(!nua_save_event(NULL, event)); TEST_1(!nua_event_data(event)); TEST_VOID(nua_destroy_event(event)); } su_log_set_level(nua_log, level); if (print_headings) printf("TEST NUA-1.0: PASSED\n"); END();}#include <sofia-sip/su_tag_class.h>int test_tag_filter(void){ BEGIN();#undef TAG_NAMESPACE#define TAG_NAMESPACE "test" tag_typedef_t tag_a = STRTAG_TYPEDEF(a);#define TAG_A(s) tag_a, tag_str_v((s)) tag_typedef_t tag_b = STRTAG_TYPEDEF(b);#define TAG_B(s) tag_b, tag_str_v((s)) tagi_t filter[2] = {{ NUTAG_ANY() }, { TAG_END() }}; tagi_t *lst, *result; lst = tl_list(TAG_A("X"), TAG_SKIP(2), NUTAG_URL((void *)"urn:foo"), TAG_B("Y"), NUTAG_URL((void *)"urn:bar"), TAG_NULL()); TEST_1(lst); result = tl_afilter(NULL, filter, lst); TEST_1(result); TEST(result[0].t_tag, nutag_url); TEST(result[1].t_tag, nutag_url); tl_vfree(lst); free(result); END();}int test_params(struct context *ctx){ BEGIN(); char const Alice[] = "Alice <sip:a@wonderland.org>"; sip_from_t const *from; su_home_t tmphome[SU_HOME_AUTO_SIZE(16384)]; nua_handle_t *nh; su_home_auto(tmphome, sizeof(tmphome)); if (print_headings) printf("TEST NUA-1.1: PARAMETERS\n"); ctx->root = su_root_create(NULL); TEST_1(ctx->root); /* Disable threading by command line switch? */ su_root_threading(ctx->root, ctx->threading); ctx->a.nua = nua_create(ctx->root, a_callback, ctx, SIPTAG_FROM_STR("sip:alice@example.com"), NUTAG_URL("sip:0.0.0.0:*;transport=udp"), TAG_END()); TEST_1(ctx->a.nua); nh = nua_handle(ctx->a.nua, NULL, TAG_END()); TEST_1(nh); nua_handle_unref(nh); nh = nua_handle(ctx->a.nua, NULL, TAG_END()); TEST_1(nh); nua_handle_destroy(nh); from = sip_from_make(tmphome, Alice); nh = nua_handle(ctx->a.nua, NULL, TAG_END()); nua_set_hparams(nh, NUTAG_INVITE_TIMER(90), TAG_END()); run_a_until(ctx, nua_r_set_params, until_final_response); /* Modify all pointer values */ nua_set_params(ctx->a.nua, SIPTAG_FROM_STR(Alice), SIPTAG_SUPPORTED_STR("test"), SIPTAG_ALLOW_STR("DWIM, OPTIONS, INFO"), SIPTAG_USER_AGENT_STR("test_nua/1.0"), SIPTAG_ORGANIZATION_STR("Te-Ras y.r."), NUTAG_REGISTRAR("sip:openlaboratory.net"), TAG_END()); run_a_until(ctx, nua_r_set_params, until_final_response); /* Modify everything from their default value */ nua_set_params(ctx->a.nua, SIPTAG_FROM(from), NUTAG_RETRY_COUNT(9), NUTAG_MAX_SUBSCRIPTIONS(6), NUTAG_ENABLEINVITE(0), NUTAG_AUTOALERT(1), NUTAG_EARLY_MEDIA(1), NUTAG_AUTOANSWER(1), NUTAG_AUTOACK(0), NUTAG_INVITE_TIMER(60), NUTAG_SESSION_TIMER(600), NUTAG_MIN_SE(35), NUTAG_SESSION_REFRESHER(nua_remote_refresher), NUTAG_UPDATE_REFRESH(1), NUTAG_ENABLEMESSAGE(0), NUTAG_ENABLEMESSENGER(1), /* NUTAG_MESSAGE_AUTOANSWER(0), */ NUTAG_CALLEE_CAPS(1), NUTAG_MEDIA_FEATURES(1), NUTAG_SERVICE_ROUTE_ENABLE(0), NUTAG_PATH_ENABLE(0), NUTAG_SUBSTATE(nua_substate_pending), SIPTAG_SUPPORTED(sip_supported_make(tmphome, "humppaa,kuole")), SIPTAG_ALLOW(sip_allow_make(tmphome, "OPTIONS, INFO")), SIPTAG_USER_AGENT(sip_user_agent_make(tmphome, "test_nua")), SIPTAG_ORGANIZATION(sip_organization_make(tmphome, "Pussy Galore's Flying Circus")), NUTAG_MEDIA_ENABLE(0), NUTAG_REGISTRAR(url_hdup(tmphome, (url_t *)"sip:sip.wonderland.org")), TAG_END()); run_a_until(ctx, nua_r_set_params, until_final_response); /* Modify something... */ nua_set_params(ctx->a.nua, NUTAG_RETRY_COUNT(5), TAG_END()); run_a_until(ctx, nua_r_set_params, until_final_response); { sip_from_t const *from = NONE; char const *from_str = "NONE"; unsigned retry_count = -1; unsigned max_subscriptions = -1; int invite_enable = -1; int auto_alert = -1; int early_media = -1; int auto_answer = -1; int auto_ack = -1; unsigned invite_timeout = -1; unsigned session_timer = -1; unsigned min_se = -1; int refresher = -1; int update_refresh = -1; int message_enable = -1; int win_messenger_enable = -1; int message_auto_respond = -1; int callee_caps = -1; int media_features = -1; int service_route_enable = -1; int path_enable = -1; int substate = -1; sip_allow_t const *allow = NONE; char const *allow_str = "NONE"; sip_supported_t const *supported = NONE; char const *supported_str = "NONE"; sip_user_agent_t const *user_agent = NONE; char const *user_agent_str = "NONE"; sip_organization_t const *organization = NONE; char const *organization_str = "NONE"; url_string_t const *registrar = NONE; int n; struct event *e; 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.call->events.head); TEST_E(e->data->e_event, nua_r_get_params); n = tl_gets(e->data->e_tags, SIPTAG_FROM_REF(from), SIPTAG_FROM_STR_REF(from_str), NUTAG_RETRY_COUNT_REF(retry_count), NUTAG_MAX_SUBSCRIPTIONS_REF(max_subscriptions), NUTAG_ENABLEINVITE_REF(invite_enable), NUTAG_AUTOALERT_REF(auto_alert), NUTAG_EARLY_MEDIA_REF(early_media), NUTAG_AUTOANSWER_REF(auto_answer), NUTAG_AUTOACK_REF(auto_ack), NUTAG_INVITE_TIMER_REF(invite_timeout), NUTAG_SESSION_TIMER_REF(session_timer), NUTAG_MIN_SE_REF(min_se), NUTAG_SESSION_REFRESHER_REF(refresher), NUTAG_UPDATE_REFRESH_REF(update_refresh), NUTAG_ENABLEMESSAGE_REF(message_enable), NUTAG_ENABLEMESSENGER_REF(win_messenger_enable), /* NUTAG_MESSAGE_AUTOANSWER(message_auto_respond), */ NUTAG_CALLEE_CAPS_REF(callee_caps), NUTAG_MEDIA_FEATURES_REF(media_features), NUTAG_SERVICE_ROUTE_ENABLE_REF(service_route_enable), NUTAG_PATH_ENABLE_REF(path_enable), NUTAG_SUBSTATE_REF(substate), SIPTAG_SUPPORTED_REF(supported), SIPTAG_SUPPORTED_STR_REF(supported_str), SIPTAG_ALLOW_REF(allow), SIPTAG_ALLOW_STR_REF(allow_str), SIPTAG_USER_AGENT_REF(user_agent), SIPTAG_USER_AGENT_STR_REF(user_agent_str), SIPTAG_ORGANIZATION_REF(organization), SIPTAG_ORGANIZATION_STR_REF(organization_str), NUTAG_REGISTRAR_REF(registrar), TAG_END()); TEST(n, 30); TEST_S(sip_header_as_string(tmphome, (void *)from), Alice); TEST_S(from_str, Alice); TEST(retry_count, 5); TEST(max_subscriptions, 6); TEST(invite_enable, 0); TEST(auto_alert, 1); TEST(early_media, 1); TEST(auto_answer, 1); TEST(auto_ack, 0); TEST(invite_timeout, 60); TEST(session_timer, 600); TEST(min_se, 35); TEST(refresher, nua_remote_refresher); TEST(update_refresh, 1); TEST(message_enable, 0); TEST(win_messenger_enable, 1); TEST(message_auto_respond, -1); /* XXX */ TEST(callee_caps, 1); TEST(media_features, 1); TEST(service_route_enable, 0); TEST(path_enable, 0); TEST(substate, nua_substate_pending); TEST_S(sip_header_as_string(tmphome, (void *)allow), "OPTIONS, INFO"); TEST_S(allow_str, "OPTIONS, INFO"); TEST_S(sip_header_as_string(tmphome, (void *)supported), "humppaa, kuole"); TEST_S(supported_str, "humppaa, kuole"); TEST_S(sip_header_as_string(tmphome, (void *)user_agent), "test_nua"); TEST_S(user_agent_str, "test_nua"); TEST_S(sip_header_as_string(tmphome, (void *)organization), "Pussy Galore's Flying Circus"); TEST_S(organization_str, "Pussy Galore's Flying Circus"); TEST_S(url_as_string(tmphome, registrar->us_url), "sip:sip.wonderland.org"); free_events_in_list(ctx, ctx->a.call); } /* Test that only those tags that have been set per handle are returned by nua_get_hparams() */ { sip_from_t const *from = NONE; char const *from_str = "NONE"; unsigned retry_count = -1; unsigned max_subscriptions = -1; int invite_enable = -1; int auto_alert = -1; int early_media = -1; int auto_answer = -1; int auto_ack = -1; unsigned invite_timeout = -1; unsigned session_timer = -1; unsigned min_se = -1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -