static int register_test_with_random_port(const char *transport, const char *client_ip, const char *server_ip, int connection_family) { int ret=0; belle_sip_listener_callbacks_t client_callbacks; belle_sip_listener_callbacks_t server_callbacks; endpoint_t* client,*server; memset(&client_callbacks,0,sizeof(belle_sip_listener_callbacks_t)); memset(&server_callbacks,0,sizeof(belle_sip_listener_callbacks_t)); client_callbacks.process_response_event=client_process_response_event; client_callbacks.process_auth_requested=client_process_auth_requested; server_callbacks.process_request_event=server_process_request_event; client = create_endpoint(client_ip,-1,transport,&client_callbacks); client->connection_family=connection_family; client->register_count=1; server = create_endpoint(server_ip,6788,transport,&server_callbacks); server->expire_in_contact=client->expire_in_contact=0; server->auth=none; if (client->lp==NULL || server->lp==NULL){ belle_sip_warning("Cannot check ipv6 because host has no ipv6 support."); ret=-1; }else register_base(client,server); destroy_endpoint(client); destroy_endpoint(server); return ret; }
static void read_error_locked(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t) { t->endpoint_reading = 0; if (!t->writing_active && t->ep) { destroy_endpoint(exec_ctx, t); } }
void grpc_chttp2_terminate_writing(grpc_exec_ctx *exec_ctx, void *transport_writing_ptr, int success) { grpc_chttp2_transport_writing *transport_writing = transport_writing_ptr; grpc_chttp2_transport *t = TRANSPORT_FROM_WRITING(transport_writing); lock(t); allow_endpoint_shutdown_locked(exec_ctx, t); if (!success) { drop_connection(exec_ctx, t); } /* cleanup writing related jazz */ grpc_chttp2_cleanup_writing(exec_ctx, &t->global, &t->writing); /* leave the writing flag up on shutdown to prevent further writes in unlock() from starting */ t->writing_active = 0; if (t->ep && !t->endpoint_reading) { destroy_endpoint(exec_ctx, t); } unlock(exec_ctx, t); UNREF_TRANSPORT(exec_ctx, t, "writing"); }
static void ipv4_and_ipv6_dns_server(void) { struct addrinfo *ai; int timeout; endpoint_t *client; const char *nameservers[]={ "8.8.8.8", "2a01:e00::2", NULL }; if (!belle_sip_tester_ipv6_available()){ belle_sip_warning("Test skipped, IPv6 connectivity not available."); return; } client = create_endpoint(); CU_ASSERT_PTR_NOT_NULL_FATAL(client); timeout = belle_sip_stack_get_dns_timeout(client->stack); set_custom_resolv_conf(client->stack,nameservers); client->resolver_ctx = belle_sip_stack_resolve_a(client->stack, IPV4_SIP_DOMAIN, SIP_PORT, AF_INET, a_resolve_done, client); CU_ASSERT_NOT_EQUAL(client->resolver_ctx, NULL); CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); CU_ASSERT_PTR_NOT_EQUAL(client->ai_list, NULL); if (client->ai_list) { struct sockaddr_in *sock_in = (struct sockaddr_in *)client->ai_list->ai_addr; CU_ASSERT_EQUAL(ntohs(sock_in->sin_port), SIP_PORT); ai = belle_sip_ip_address_to_addrinfo(AF_INET, IPV4_SIP_IP, SIP_PORT); if (ai) { CU_ASSERT_EQUAL(sock_in->sin_addr.s_addr, ((struct sockaddr_in *)ai->ai_addr)->sin_addr.s_addr); belle_sip_freeaddrinfo(ai); } } destroy_endpoint(client); }
static void dns_fallback(void) { struct addrinfo *ai; int timeout; endpoint_t *client = create_endpoint(); const char *nameservers[]={ "94.23.19.176", /*linphone.org ; this is not a name server, it will not respond*/ "8.8.8.8", /* public nameserver, should work*/ NULL }; CU_ASSERT_PTR_NOT_NULL_FATAL(client); timeout = belle_sip_stack_get_dns_timeout(client->stack); set_custom_resolv_conf(client->stack,nameservers); client->resolver_ctx = belle_sip_stack_resolve_a(client->stack, IPV4_SIP_DOMAIN, SIP_PORT, AF_INET, a_resolve_done, client); CU_ASSERT_NOT_EQUAL(client->resolver_ctx, NULL); CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); CU_ASSERT_PTR_NOT_EQUAL(client->ai_list, NULL); if (client->ai_list) { struct sockaddr_in *sock_in = (struct sockaddr_in *)client->ai_list->ai_addr; CU_ASSERT_EQUAL(ntohs(sock_in->sin_port), SIP_PORT); ai = belle_sip_ip_address_to_addrinfo(AF_INET, IPV4_SIP_IP, SIP_PORT); if (ai) { CU_ASSERT_EQUAL(sock_in->sin_addr.s_addr, ((struct sockaddr_in *)ai->ai_addr)->sin_addr.s_addr); belle_sip_freeaddrinfo(ai); } } destroy_endpoint(client); }
static void register_early_refresher(void) { belle_sip_listener_callbacks_t client_callbacks; belle_sip_listener_callbacks_t server_callbacks; endpoint_t* client,*server; memset(&client_callbacks,0,sizeof(belle_sip_listener_callbacks_t)); memset(&server_callbacks,0,sizeof(belle_sip_listener_callbacks_t)); client_callbacks.process_response_event=client_process_response_event; client_callbacks.process_auth_requested=client_process_auth_requested; server_callbacks.process_request_event=server_process_request_event; client = create_udp_endpoint(3452,&client_callbacks); server = create_udp_endpoint(6788,&server_callbacks); server->expire_in_contact=1; server->auth=digest; client->early_refresher=1; register_base(client,server); destroy_endpoint(client); destroy_endpoint(server); }
/* Successful IPv6 AAAA query */ static void ipv6_aaaa_query(void) { struct addrinfo *ai; int timeout; endpoint_t *client; if (!belle_sip_tester_ipv6_available()){ belle_sip_warning("Test skipped, IPv6 connectivity not available."); return; } client = create_endpoint(); if (!BC_ASSERT_PTR_NOT_NULL(client)) return; timeout = belle_sip_stack_get_dns_timeout(client->stack); client->resolver_ctx = belle_sip_stack_resolve_a(client->stack, IPV6_SIP_DOMAIN, SIP_PORT, AF_INET6, a_resolve_done, client); BC_ASSERT_PTR_NOT_NULL(client->resolver_ctx); BC_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); BC_ASSERT_PTR_NOT_EQUAL(client->ai_list, NULL); if (client->ai_list) { struct addrinfo *next; struct sockaddr_in6 *sock_in6 = (struct sockaddr_in6 *)client->ai_list->ai_addr; int ntohsi = ntohs(sock_in6->sin6_port); BC_ASSERT_EQUAL(ntohsi, SIP_PORT, int, "%d"); /*the IPv6 address shall return first, and must be a real ipv6 address*/ BC_ASSERT_EQUAL(client->ai_list->ai_family,AF_INET6,int,"%d"); BC_ASSERT_FALSE(IN6_IS_ADDR_V4MAPPED(&sock_in6->sin6_addr)); ai = bctbx_ip_address_to_addrinfo(AF_INET6, SOCK_STREAM, IPV6_SIP_IP, SIP_PORT); BC_ASSERT_PTR_NOT_NULL(ai); if (ai) { struct in6_addr *ipv6_address = &((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr; int i; for (i = 0; i < 8; i++) { BC_ASSERT_EQUAL(sock_in6->sin6_addr.s6_addr[i], ipv6_address->s6_addr[i], int, "%d"); } bctbx_freeaddrinfo(ai); } next=client->ai_list->ai_next; BC_ASSERT_PTR_NOT_NULL(next); if (next){ int ntohsi = ntohs(sock_in6->sin6_port); sock_in6 = (struct sockaddr_in6 *)next->ai_addr; BC_ASSERT_EQUAL(next->ai_family,AF_INET6,int,"%d"); BC_ASSERT_TRUE(IN6_IS_ADDR_V4MAPPED(&sock_in6->sin6_addr)); BC_ASSERT_EQUAL(ntohsi, SIP_PORT, int, "%d"); ai = bctbx_ip_address_to_addrinfo(AF_INET6, SOCK_STREAM, IPV6_SIP_IPV4, SIP_PORT); BC_ASSERT_PTR_NOT_NULL(ai); if (ai) { struct in6_addr *ipv6_address = &((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr; int i; for (i = 0; i < 8; i++) { BC_ASSERT_EQUAL(sock_in6->sin6_addr.s6_addr[i], ipv6_address->s6_addr[i], int, "%d"); } bctbx_freeaddrinfo(ai); } } } destroy_endpoint(client); }
static void register_with_failure(void) { belle_sip_listener_callbacks_t client_callbacks; belle_sip_listener_callbacks_t server_callbacks; endpoint_t* client,*server; memset(&client_callbacks,0,sizeof(belle_sip_listener_callbacks_t)); memset(&server_callbacks,0,sizeof(belle_sip_listener_callbacks_t)); client_callbacks.process_response_event=client_process_response_event; client_callbacks.process_auth_requested=client_process_auth_requested; server_callbacks.process_request_event=server_process_request_event; client = create_udp_endpoint(3452,&client_callbacks); server = create_udp_endpoint(6788,&server_callbacks); server->expire_in_contact=1; server->auth=digest; client->transiant_network_failure=1; register_base(client,server); CU_ASSERT_EQUAL(client->stat.refreshKo,1); destroy_endpoint(client); destroy_endpoint(server); }
/* IPv4 A query send failure */ static void ipv4_a_query_send_failure(void) { endpoint_t *client = create_endpoint(); CU_ASSERT_PTR_NOT_NULL_FATAL(client); belle_sip_stack_set_resolver_send_error(client->stack, -1); client->resolver_ctx = belle_sip_stack_resolve_a(client->stack, IPV4_SIP_DOMAIN, SIP_PORT, AF_INET, a_resolve_done, client); CU_ASSERT_EQUAL(client->resolver_ctx, NULL); belle_sip_stack_set_resolver_send_error(client->stack, 0); destroy_endpoint(client); }
/* Successful IPv4 A query with no result */ static void ipv4_a_query_no_result(void) { int timeout; endpoint_t *client = create_endpoint(); if (!BC_ASSERT_PTR_NOT_NULL(client)) return; timeout = belle_sip_stack_get_dns_timeout(client->stack); client->resolver_ctx = belle_sip_stack_resolve_a(client->stack, IPV4_SIP_BAD_DOMAIN, SIP_PORT, AF_INET, a_resolve_done, client); BC_ASSERT_PTR_NOT_NULL(client->resolver_ctx); BC_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); BC_ASSERT_PTR_EQUAL(client->ai_list, NULL); destroy_endpoint(client); }
void rdr_repeater_destroy(struct rdr_repeater_ctx_t *ctx) { struct endpoint_t *ep, *next; assert(ctx != NULL); for (ep = ctx->head; ep != NULL; ep = next) { next = ep->next; destroy_endpoint(ep); } free(ctx); }
/* IPv4 A query timeout */ static void ipv4_a_query_timeout(void) { endpoint_t *client = create_endpoint(); CU_ASSERT_PTR_NOT_NULL_FATAL(client); belle_sip_stack_set_dns_timeout(client->stack, 0); client->resolver_ctx = belle_sip_stack_resolve_a(client->stack, "toto.com", SIP_PORT, AF_INET, a_resolve_done, client); CU_ASSERT_NOT_EQUAL(client->resolver_ctx, NULL); CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, 2000)); CU_ASSERT_PTR_EQUAL(client->ai_list, NULL); CU_ASSERT_EQUAL(client->resolve_ko,1); destroy_endpoint(client); }
/* Successful SRV + A or AAAA queries */ static void srv_a_query(void) { int timeout; endpoint_t *client = create_endpoint(); CU_ASSERT_PTR_NOT_NULL_FATAL(client); timeout = belle_sip_stack_get_dns_timeout(client->stack); client->resolver_ctx = belle_sip_stack_resolve(client->stack, "udp", SRV_DOMAIN, SIP_PORT, AF_INET, a_resolve_done, client); CU_ASSERT_NOT_EQUAL(client->resolver_ctx, NULL); CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); CU_ASSERT_PTR_NOT_EQUAL(client->ai_list, NULL); destroy_endpoint(client); }
void destroy_connection(connection_t *connection) { if (connection->call_id != NULL) { shm_free(connection->call_id); } if (connection->request_endpoint != NULL) { destroy_endpoint(connection->request_endpoint); } if (connection->response_endpoint != NULL) { destroy_endpoint(connection->response_endpoint); } if (connection->lock != NULL) { lock_destroy(connection->lock); } // we don't need to free next, prev, request and response endpoint IP // since they are just pointers and will be freed after whole connection is shm_free(connection); }
static void refresher_base_with_param_and_body(const char* method , unsigned char expire_in_contact , auth_mode_t auth_mode , int early_refresher , belle_sip_header_content_type_t* content_type ,const char* body){ belle_sip_listener_callbacks_t client_callbacks; belle_sip_listener_callbacks_t server_callbacks; endpoint_t* client,*server; memset(&client_callbacks,0,sizeof(belle_sip_listener_callbacks_t)); memset(&server_callbacks,0,sizeof(belle_sip_listener_callbacks_t)); client_callbacks.process_response_event=client_process_response_event; client_callbacks.process_auth_requested=client_process_auth_requested; server_callbacks.process_request_event=server_process_request_event; client = create_udp_endpoint(3452,&client_callbacks); server = create_udp_endpoint(6788,&server_callbacks); server->expire_in_contact=client->expire_in_contact=expire_in_contact; server->auth=auth_mode; client->early_refresher=early_refresher; refresher_base_with_body(client,server,method,content_type,body); destroy_endpoint(client); destroy_endpoint(server); }
static void local_full_query(void) { int timeout; endpoint_t *client = create_endpoint(); CU_ASSERT_PTR_NOT_NULL_FATAL(client); timeout = belle_sip_stack_get_dns_timeout(client->stack); client->resolver_ctx = belle_sip_stack_resolve(client->stack, "tcp", "localhost", SIP_PORT, AF_INET, a_resolve_done, client); CU_ASSERT_PTR_NOT_NULL(client->resolver_ctx); CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); CU_ASSERT_PTR_NOT_EQUAL(client->ai_list, NULL); if (client->ai_list) { struct sockaddr_in *sock_in = (struct sockaddr_in *)client->ai_list->ai_addr; CU_ASSERT_EQUAL(ntohs(sock_in->sin_port), SIP_PORT); } destroy_endpoint(client); }
/* Successful IPv4 A query with multiple results */ static void ipv4_a_query_multiple_results(void) { int timeout; endpoint_t *client = create_endpoint(); CU_ASSERT_PTR_NOT_NULL_FATAL(client); timeout = belle_sip_stack_get_dns_timeout(client->stack); client->resolver_ctx = belle_sip_stack_resolve_a(client->stack, IPV4_MULTIRES_DOMAIN, SIP_PORT, AF_INET, a_resolve_done, client); CU_ASSERT_NOT_EQUAL(client->resolver_ctx, NULL); CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); CU_ASSERT_PTR_NOT_EQUAL(client->ai_list, NULL); if (client->ai_list) { CU_ASSERT_PTR_NOT_NULL(client->ai_list->ai_next); } destroy_endpoint(client); }
/* Successful SRV query */ static void srv_query(void) { int timeout; endpoint_t *client = create_endpoint(); CU_ASSERT_PTR_NOT_NULL_FATAL(client); timeout = belle_sip_stack_get_dns_timeout(client->stack); client->resolver_ctx = belle_sip_stack_resolve_srv(client->stack, "udp", SRV_DOMAIN, srv_resolve_done, client); CU_ASSERT_NOT_EQUAL(client->resolver_ctx, NULL); CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); CU_ASSERT_PTR_NOT_EQUAL(client->srv_list, NULL); CU_ASSERT_NOT_EQUAL(belle_sip_list_size(client->srv_list), 0); if (client->srv_list && (belle_sip_list_size(client->srv_list) > 0)) { belle_sip_dns_srv_t *result_srv = belle_sip_list_nth_data(client->srv_list, 0); CU_ASSERT_EQUAL(belle_sip_dns_srv_get_port(result_srv), SIP_PORT); } destroy_endpoint(client); }
static void ipv4_a_query_with_v4mapped_results(void) { int timeout; endpoint_t *client; if (!belle_sip_tester_ipv6_available()){ belle_sip_warning("Test skipped, IPv6 connectivity not available."); return; } client = create_endpoint(); CU_ASSERT_PTR_NOT_NULL_FATAL(client); timeout = belle_sip_stack_get_dns_timeout(client->stack); client->resolver_ctx = belle_sip_stack_resolve_a(client->stack, IPV4_SIP_DOMAIN, SIP_PORT, AF_INET6, a_resolve_done, client); CU_ASSERT_NOT_EQUAL(client->resolver_ctx, NULL); CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); CU_ASSERT_PTR_NOT_NULL(client->ai_list); destroy_endpoint(client); }
/* No query needed because already resolved */ static void no_query_needed(void) { struct addrinfo *ai; endpoint_t *client = create_endpoint(); CU_ASSERT_PTR_NOT_NULL_FATAL(client); client->resolver_ctx = belle_sip_stack_resolve(client->stack, "udp", IPV4_SIP_IP, SIP_PORT, AF_INET, a_resolve_done, client); CU_ASSERT_EQUAL(client->resolver_ctx, NULL); CU_ASSERT_TRUE(client->resolve_done); CU_ASSERT_PTR_NOT_EQUAL(client->ai_list, NULL); if (client->ai_list) { struct sockaddr_in *sock_in = (struct sockaddr_in *)client->ai_list->ai_addr; CU_ASSERT_EQUAL(ntohs(sock_in->sin_port), SIP_PORT); ai = belle_sip_ip_address_to_addrinfo(AF_INET, IPV4_SIP_IP, SIP_PORT); if (ai) { CU_ASSERT_EQUAL(sock_in->sin_addr.s_addr, ((struct sockaddr_in *)ai->ai_addr)->sin_addr.s_addr); belle_sip_freeaddrinfo(ai); } } destroy_endpoint(client); }
static void local_query(void) { int timeout; endpoint_t *client = create_endpoint(); CU_ASSERT_PTR_NOT_NULL_FATAL(client); timeout = belle_sip_stack_get_dns_timeout(client->stack); client->resolver_ctx = belle_sip_stack_resolve_a(client->stack, "localhost", SIP_PORT, AF_INET, a_resolve_done, client); // A DNS query is needed on Windows platform #ifdef WIN32 CU_ASSERT_PTR_NOT_EQUAL(client->resolver_ctx, NULL); #else CU_ASSERT_PTR_EQUAL(client->resolver_ctx, NULL); #endif CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); CU_ASSERT_PTR_NOT_EQUAL(client->ai_list, NULL); if (client->ai_list) { struct sockaddr_in *sock_in = (struct sockaddr_in *)client->ai_list->ai_addr; CU_ASSERT_EQUAL(ntohs(sock_in->sin_port), SIP_PORT); } destroy_endpoint(client); }
/* Successful SRV query with no result + A query */ static void srv_a_query_no_srv_result(void) { struct addrinfo *ai; int timeout; endpoint_t *client = create_endpoint(); CU_ASSERT_PTR_NOT_NULL_FATAL(client); timeout = belle_sip_stack_get_dns_timeout(client->stack); client->resolver_ctx = belle_sip_stack_resolve(client->stack, "udp", IPV4_SIP_DOMAIN, SIP_PORT, AF_INET, a_resolve_done, client); CU_ASSERT_NOT_EQUAL(client->resolver_ctx, NULL); CU_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); CU_ASSERT_PTR_NOT_EQUAL(client->ai_list, NULL); if (client->ai_list) { struct sockaddr_in *sock_in = (struct sockaddr_in *)client->ai_list->ai_addr; CU_ASSERT_EQUAL(ntohs(sock_in->sin_port), SIP_PORT); ai = belle_sip_ip_address_to_addrinfo(AF_INET, IPV4_SIP_IP, SIP_PORT); if (ai) { CU_ASSERT_EQUAL(sock_in->sin_addr.s_addr, ((struct sockaddr_in *)ai->ai_addr)->sin_addr.s_addr); belle_sip_freeaddrinfo(ai); } } destroy_endpoint(client); }
/*This tests the recursion of dns.c*/ static void ipv4_cname_a_query(void) { struct addrinfo *ai; int timeout; endpoint_t *client = create_endpoint(); if (!BC_ASSERT_PTR_NOT_NULL(client)) return; timeout = belle_sip_stack_get_dns_timeout(client->stack); client->resolver_ctx = belle_sip_stack_resolve_a(client->stack, IPV4_CNAME, SIP_PORT, AF_INET, a_resolve_done, client); BC_ASSERT_PTR_NOT_NULL(client->resolver_ctx); BC_ASSERT_TRUE(wait_for(client->stack, &client->resolve_done, 1, timeout)); BC_ASSERT_PTR_NOT_EQUAL(client->ai_list, NULL); if (client->ai_list) { struct sockaddr_in *sock_in = (struct sockaddr_in *)client->ai_list->ai_addr; int ntohsi = (int)ntohs(sock_in->sin_port); BC_ASSERT_EQUAL(ntohsi, SIP_PORT, int, "%d"); ai = bctbx_ip_address_to_addrinfo(AF_INET, SOCK_STREAM, IPV4_CNAME_IP, SIP_PORT); if (ai) { BC_ASSERT_EQUAL(sock_in->sin_addr.s_addr, ((struct sockaddr_in *)ai->ai_addr)->sin_addr.s_addr, int, "%d"); bctbx_freeaddrinfo(ai); } } destroy_endpoint(client); }
int rdr_repeater_add_endpoint(struct rdr_repeater_ctx_t *ctx, const char *addrport, FILE *err_stream) { int error; char *servname; struct endpoint_t *ep; struct addrinfo hints; assert(ctx != NULL); assert(addrport != NULL); ep = (struct endpoint_t *)malloc(sizeof(*ep)); if (ep == NULL) { return -1; } ep->hostname = NULL; ep->servname = NULL; ep->addrinfo = NULL; ep->cur_addr = NULL; ep->next = NULL; ep->s = -1; ep->status = S_NOT_INITIALIZED; purge_buffer(ep); ep->hostname = strdup(addrport); if (ep->hostname == NULL) { destroy_endpoint(ep); if (err_stream != NULL) fprintf(err_stream, "%s strdup() error\n", TAG); return -1; } if (ep->hostname[0] == '\0') { destroy_endpoint(ep); if (err_stream != NULL) fprintf(err_stream, "%s empty hostname\n", TAG); return -1; } servname = strrchr(ep->hostname, '/'); if (servname != NULL) { *servname++ = '\0'; if (*servname == '\0') ep->servname = NULL; else { ep->servname = strdup(servname); if (ep->servname == NULL) { destroy_endpoint(ep); if (err_stream != NULL) fprintf(err_stream, "%s strdup() error\n", TAG); return -1; } } if (ep->hostname[0] == '\0') { free((void *)ep->hostname); ep->hostname = NULL; if (ep->servname == NULL) { destroy_endpoint(ep); if (err_stream != NULL) fprintf(err_stream, "%s hostname not defined\n", TAG); return -2; } } } assert(! ((ep->hostname == NULL) && (ep->servname == NULL))); if (ep->hostname != NULL) assert(ep->hostname[0] != '\0'); if (ep->servname != NULL) assert(ep->servname[0] != '\0'); if (ep->hostname == NULL) { ep->hostname = strdup(RDR_REPEATER_DEFAULT_HOST); if (ep->hostname == NULL) { destroy_endpoint(ep); if (err_stream != NULL) fprintf(err_stream, "%s strdup() error\n", TAG); return -1; } } if (ep->servname == NULL) { ep->servname = strdup(RDR_REPEATER_DEFAULT_PORT); if (ep->servname == NULL) { destroy_endpoint(ep); if (err_stream != NULL) fprintf(err_stream, "%s strdup() error\n", TAG); return -1; } } /* resolve */ memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_INET; hints.ai_socktype = SOCK_STREAM; #ifdef AI_ADDRCONFIG hints.ai_flags = AI_ADDRCONFIG; #else hints.ai_flags = 0; #endif error = getaddrinfo(ep->hostname, ep->servname, &hints, &ep->addrinfo); if (error) { if (err_stream != NULL) fprintf(err_stream, "%s getaddrinfo(%s) error: %s\n", TAG, addrport, gai_strerror(error)); destroy_endpoint(ep); return -2; } if (ep->addrinfo == NULL) { if (err_stream != NULL) fprintf(err_stream, "%s No addres found for %s\n", TAG, addrport); destroy_endpoint(ep); return -2; } if (ctx->tail == NULL) { assert(ctx->head == NULL); ctx->head = ctx->tail = ep; }else { ctx->tail->next = ep; ctx->tail = ep; } return 1; }
static void subscribe_test(void) { belle_sip_listener_callbacks_t client_callbacks; belle_sip_listener_callbacks_t server_callbacks; belle_sip_request_t* req; belle_sip_client_transaction_t* trans; belle_sip_header_route_t* destination_route; const char* identity = "sip:" USERNAME "@" SIPDOMAIN ; const char* domain="sip:" SIPDOMAIN ; endpoint_t* client,*server; belle_sip_uri_t *dest_uri; belle_sip_refresher_t* refresher; belle_sip_header_contact_t* contact=belle_sip_header_contact_new(); uint64_t begin; uint64_t end; memset(&client_callbacks,0,sizeof(belle_sip_listener_callbacks_t)); memset(&server_callbacks,0,sizeof(belle_sip_listener_callbacks_t)); client_callbacks.process_response_event=client_process_response_event; client_callbacks.process_auth_requested=client_process_auth_requested; server_callbacks.process_request_event=server_process_request_event; client = create_udp_endpoint(3452,&client_callbacks); server = create_udp_endpoint(6788,&server_callbacks); server->expire_in_contact=0; server->auth=digest_auth; dest_uri=(belle_sip_uri_t*)belle_sip_object_clone((belle_sip_object_t*)belle_sip_listening_point_get_uri(server->lp)); belle_sip_uri_set_host(dest_uri,"127.0.0.1"); destination_route=belle_sip_header_route_create(belle_sip_header_address_create(NULL,dest_uri)); req=belle_sip_request_create( belle_sip_uri_parse(domain), "SUBSCRIBE", belle_sip_provider_create_call_id(client->provider), belle_sip_header_cseq_create(20,"SUBSCRIBE"), belle_sip_header_from_create2(identity,BELLE_SIP_RANDOM_TAG), belle_sip_header_to_create2(identity,NULL), belle_sip_header_via_new(), 70); belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(contact)); belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_expires_create(1))); belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_create("Event","Presence"))); belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(destination_route)); trans=belle_sip_provider_create_client_transaction(client->provider,req); belle_sip_object_ref(trans);/*to avoid trans from being deleted before refresher can use it*/ belle_sip_client_transaction_send_request(trans); CU_ASSERT_TRUE(wait_for(server->stack,client->stack,&client->stat.fourHundredOne,1,1000)); req=belle_sip_client_transaction_create_authenticated_request(trans,NULL,NULL); belle_sip_object_unref(trans); trans=belle_sip_provider_create_client_transaction(client->provider,req); belle_sip_object_ref(trans); belle_sip_client_transaction_send_request(trans); CU_ASSERT_TRUE_FATAL(wait_for(server->stack,client->stack,&client->stat.twoHundredOk,1,1000)); /*maybe dialog should be automatically created*/ CU_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_transaction_get_dialog(BELLE_SIP_TRANSACTION(trans))) refresher = belle_sip_client_transaction_create_refresher(trans); belle_sip_object_unref(trans); belle_sip_refresher_set_listener(refresher,belle_sip_refresher_listener,client); begin = belle_sip_time_ms(); CU_ASSERT_TRUE(wait_for(server->stack,client->stack,&client->stat.refreshOk,3,4000)); end = belle_sip_time_ms(); CU_ASSERT_TRUE(end-begin>=3000); CU_ASSERT_TRUE(end-begin<5000); /*unsubscribe twice to make sure refresh operation can be safely cascaded*/ belle_sip_refresher_refresh(refresher,0); belle_sip_refresher_refresh(refresher,0); belle_sip_refresher_stop(refresher); belle_sip_object_unref(refresher); destroy_endpoint(client); destroy_endpoint(server); }