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

📄 test_nua.c

📁 Internet Phone, Chat, Conferencing
💻 C
📖 第 1 页 / 共 5 页
字号:
    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_hparams(nh, 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, 3);    TEST(invite_timeout, 90);    TEST_1(from != NULL && from != NONE);    TEST_1(strcmp(from_str, "NONE"));    /* Nothing else should be set */    TEST(retry_count, (unsigned)-1);    TEST(max_subscriptions, (unsigned)-1);    TEST(invite_enable, -1);    TEST(auto_alert, -1);    TEST(early_media, -1);    TEST(auto_answer, -1);    TEST(auto_ack, -1);    TEST(session_timer, (unsigned)-1);    TEST(min_se, (unsigned)-1);    TEST(refresher, -1);    TEST(update_refresh, -1);    TEST(message_enable, -1);    TEST(win_messenger_enable, -1);    TEST(message_auto_respond, -1); /* XXX */    TEST(callee_caps, -1);    TEST(media_features, -1);    TEST(service_route_enable, -1);    TEST(path_enable, -1);    TEST(substate, -1);    TEST(allow, NONE);    TEST_S(allow_str, "NONE");    TEST(supported, NONE);    TEST_S(supported_str, "NONE");    TEST(user_agent, NONE);    TEST_S(user_agent_str, "NONE");    TEST(organization, NONE);    TEST_S(organization_str, "NONE");    TEST(registrar->us_url, NONE);    free_events_in_list(ctx, ctx->a.call);  }  nua_handle_destroy(nh);  nua_shutdown(ctx->a.nua);  run_a_until(ctx, nua_r_shutdown, until_final_response);  nua_destroy(ctx->a.nua), ctx->a.nua = NULL;  su_root_destroy(ctx->root), ctx->root = NULL;  su_home_deinit(tmphome);  if (print_headings)    printf("TEST NUA-1.1: PASSED\n");  END();}/* ======================================================================== */static char passwd_name[] = "tmp_sippasswd.XXXXXX";static void remove_tmp(void){  if (passwd_name[0])    unlink(passwd_name);}static char const passwd[] =  "alice:secret:\n"  "bob:secret:\n"  "charlie:secret:\n";int test_init(struct context *ctx, 	      int start_proxy,	      url_t const *o_proxy,	      int start_nat){  BEGIN();  struct event *e;  sip_contact_t const *m = NULL;  sip_from_t const *sipaddress = NULL;  url_t const *p_uri, *a_uri;		/* Proxy URI */  char const *a_bind = "sip:0.0.0.0:*";  ctx->root = su_root_create(NULL); TEST_1(ctx->root);  /* Disable threading by command line switch? */  su_root_threading(ctx->root, ctx->threading);  if (start_proxy && !o_proxy) {    int temp;    if (print_headings)      printf("TEST NUA-2.1.1: init proxy P\n");#ifndef _WIN32    temp = mkstemp(passwd_name);#else    temp = open(passwd_name, O_WRONLY|O_CREAT|O_TRUNC, 666);#endif    TEST_1(temp != -1);    atexit(remove_tmp);		/* Make sure temp file is unlinked */        TEST(write(temp, passwd, strlen(passwd)), strlen(passwd));    TEST_1(close(temp) == 0);    ctx->p = test_proxy_create(ctx->root, 			       AUTHTAG_METHOD("Digest"),			       AUTHTAG_REALM("test-proxy"),			       AUTHTAG_OPAQUE("kuik"),			       AUTHTAG_DB(passwd_name),			       AUTHTAG_QOP("auth-int"),			       AUTHTAG_ALGORITHM("md5-sess"),			       TAG_END());    if (print_headings)      printf("TEST NUA-2.1.1: PASSED\n");  }  p_uri = a_uri = test_proxy_uri(ctx->p);  if (start_nat && p_uri == NULL)    p_uri = url_hdup(ctx->home, (void *)o_proxy);  if (start_nat && p_uri != NULL) {    int family = 0;    su_sockaddr_t su[1];    socklen_t sulen = sizeof su;    char b[64];    int len;    if (print_headings)      printf("TEST NUA-2.1.2: creating test NAT\n");    /* Try to use different family than proxy. */    if (p_uri->url_host[0] == '[')      family = AF_INET;#if defined(SU_HAVE_IN6)    else      family = AF_INET6;#endif    ctx->nat = test_nat_create(ctx->root, family, TAG_END());    if (test_nat_private(ctx->nat, su, &sulen) < 0) {      printf("%s:%u: NUA-2.1.2: failed to get private NAT address\n",	     __FILE__, __LINE__);    }#if defined(SU_HAVE_IN6)    else if (su->su_family == AF_INET6) {      a_uri = (void *)	su_sprintf(ctx->home, "sip:[%s]:%u",		   inet_ntop(su->su_family, SU_ADDR(su), b, sizeof b),		   ntohs(su->su_port));      a_bind = "sip:[::]:*";    }#endif    else if (su->su_family == AF_INET) {      a_uri = (void *)	su_sprintf(ctx->home, "sip:%s:%u",		   inet_ntop(su->su_family, SU_ADDR(su), b, sizeof b),		   ntohs(su->su_port));      a_bind = "sip:0.0.0.0:*";    }#if defined(SU_HAVE_IN6)    if (p_uri->url_host[0] == '[') {      su->su_len = sulen = (sizeof su->su_sin6), su->su_family = AF_INET6;      len = strcspn(p_uri->url_host + 1, "]"); assert(len < sizeof b);      memcpy(b, p_uri->url_host + 1, len); b[len] = '\0';      inet_pton(su->su_family, b, SU_ADDR(su));    }    else {      su->su_len = sulen = (sizeof su->su_sin), su->su_family = AF_INET;      inet_pton(su->su_family, p_uri->url_host, SU_ADDR(su));    }#else    su->su_len = sulen = (sizeof su->su_sin), su->su_family = AF_INET;    inet_pton(su->su_family, p_uri->url_host, SU_ADDR(su));#endif    su->su_port = htons(strtoul(url_port(p_uri), NULL, 10));    if (test_nat_public(ctx->nat, su, sulen) < 0) {      printf("%s:%u: NUA-2.1.2: failed to set public address\n",	     __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.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),			  SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),			  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.call->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.call);  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.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"),			  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.call->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.call);  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.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"),			  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.call->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.call);    if (print_headings)    printf("TEST NUA-2.2.3: PASSED\n");  END();}/* ======================================================================== *//* Test REGISTER */int test_register(struct context *ctx){  if (!ctx->p)    return 0;			/* No proxy */  BEGIN();  struct endpoint *a = &ctx->a,  *b = &ctx->b, *c = &ctx->c;  struct call *a_call = a->reg, *b_call = b->reg, *c_call = c->reg;  struct event *e;  sip_t const *sip;/* REGISTER test   A			B   |------REGISTER----->|   |<-------200---------|   |			|*/  if (print_headings)    printf("TEST NUA-2.3.1: REGISTER a\n");  TEST_1(a_call->nh = nua_handle(a->nua, a_call, TAG_END()));  do_register(a, a_call, a_call->nh, SIPTAG_TO(a->to), TAG_END());  run_a_until(ctx, -1, save_until_final_response);  TEST_1(e = a->call->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->call);  authenticate(a, a_call, a_call->nh, 	       NUTAG_AUTH("Digest:\"test-proxy\":alice:secret"), TAG_END());  run_a_until(ctx, -1, save_until_final_response);  TEST_1(e = a->call->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->call);  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_call->nh = nua_handle(b->nua, b_call, TAG_END()));  do_register(b, b_call, b_call->nh, SIPTAG_TO(b->to), TAG_END());  run_b_until(ctx, -1, save_until_final_response);  TEST_1(e = b->call->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->call);  authenticate(b, b_call, b_call->nh, 	       NUTAG_AUTH("Digest:\"test-proxy\":bob:secret"), TAG_END());  run_b_until(ctx, -1, save_until_final_response);  TEST_1(e = b->call->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->call);  if (print_headings)    printf("TEST NUA-2.3.2: PASSED\n");  if (print_headings)    printf("TEST NUA-2.3.3: REGISTER c\n");  TEST_1(c_call->nh = nua_handle(c->nua, c_call, TAG_END()));  do_register(c, c_call, c_call->nh, SIPTAG_TO(c->to), TAG_END());  run_c_until(ctx, -1, save_until_final_response);  TEST_1(e = c->call->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->call);  authenticate(c, c_call, c_call->nh, 	       NUTAG_AUTH("Digest:\"test-proxy\":charlie:secret"), TAG_END());  run_c_until(ctx, -1, save_until_final_response);  TEST_1(e = c->call->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, c->call);  if (print_headings)    printf("TEST NUA-2.3.3: PASSED\n");  END();

⌨️ 快捷键说明

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