Commit 9add158a authored by Ghislain MARY's avatar Ghislain MARY

Change resolver API to be able to specify the service to resolve with DNS SRV queries.

parent 99e37954
......@@ -55,6 +55,7 @@ BELLESIP_EXPORT unsigned short belle_sip_dns_srv_get_port(const belle_sip_dns_sr
/**
* Asynchronously performs DNS SRV followed A/AAAA query. Automatically fallbacks to A/AAAA if SRV isn't found.
* @param stack the belle_sip_stack_t, used to schedule asynchronous execution.
* @param service the queried service ("sip", "stun", "turn"...)
* @param transport the queried transport ("udp", "tcp", "tls")
* @param name the SIP domain name
* @param port a port that will be filled in the addrinfo list returned by the callback, for the case where no SRV records are found.
......@@ -64,7 +65,7 @@ BELLESIP_EXPORT unsigned short belle_sip_dns_srv_get_port(const belle_sip_dns_sr
* @param data a user pointer passed through the callback as first argument.
* @return a #belle_sip_resolver_context_t that can be used to cancel the resolution if needed. The context must have been ref'd with belle_sip_object_ref().
**/
BELLESIP_EXPORT belle_sip_resolver_context_t * belle_sip_stack_resolve(belle_sip_stack_t *stack, const char *transport, const char *name, int port, int family,
BELLESIP_EXPORT belle_sip_resolver_context_t * belle_sip_stack_resolve(belle_sip_stack_t *stack, const char *service, const char *transport, const char *name, int port, int family,
belle_sip_resolver_callback_t cb, void *data);
/**
......@@ -84,7 +85,7 @@ BELLESIP_EXPORT belle_sip_resolver_context_t * belle_sip_stack_resolve_a(belle_s
* Asynchronously performs DNS SRV query.
* @return a #belle_sip_resolver_context_t that can be used to cancel the resolution if needed. The context must have been ref'd with belle_sip_object_ref().
**/
BELLESIP_EXPORT belle_sip_resolver_context_t * belle_sip_stack_resolve_srv(belle_sip_stack_t *stack, const char *transport, const char *name, belle_sip_resolver_srv_callback_t cb, void *data);
BELLESIP_EXPORT belle_sip_resolver_context_t * belle_sip_stack_resolve_srv(belle_sip_stack_t *stack, const char *service, const char *transport, const char *name, belle_sip_resolver_srv_callback_t cb, void *data);
/**
* Cancel a pending asynchronous DNS query. The context is unref'd automatically, as a result the context shall no longer be used after this call.
......
......@@ -855,19 +855,16 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_combined_resolver_context_t)
}
BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_END
static char * srv_prefix_from_transport(const char *transport) {
char *prefix = "";
static char * srv_prefix_from_service_and_transport(const char *service, const char *transport) {
if (service == NULL) service = "sip";
if (strcasecmp(transport, "udp") == 0) {
prefix = "_sip._udp.";
return belle_sip_strdup_printf("_%s._udp.", service);
} else if (strcasecmp(transport, "tcp") == 0) {
prefix = "_sip._tcp.";
return belle_sip_strdup_printf("_%s._tcp.", service);
} else if (strcasecmp(transport, "tls") == 0) {
prefix = "_sips._tcp.";
} else {
prefix = "_sip._udp.";
return belle_sip_strdup_printf("_%ss._tcp.", service);
}
return prefix;
return belle_sip_strdup_printf("_%s._udp.", service);
}
static void combined_notify_results(belle_sip_combined_resolver_context_t *obj){
......@@ -958,7 +955,7 @@ static void process_srv_results(void *data, const char *name, belle_sip_list_t *
/**
* Perform combined SRV + A / AAAA resolution.
**/
belle_sip_resolver_context_t * belle_sip_stack_resolve(belle_sip_stack_t *stack, const char *transport, const char *name, int port, int family, belle_sip_resolver_callback_t cb, void *data) {
belle_sip_resolver_context_t * belle_sip_stack_resolve(belle_sip_stack_t *stack, const char *service, const char *transport, const char *name, int port, int family, belle_sip_resolver_callback_t cb, void *data) {
struct addrinfo *res = bctbx_ip_address_to_addrinfo(family, SOCK_STREAM, name, port);
if (res == NULL) {
/* First perform asynchronous DNS SRV query */
......@@ -973,7 +970,7 @@ belle_sip_resolver_context_t * belle_sip_stack_resolve(belle_sip_stack_t *stack,
ctx->family = family;
/*take a ref for the entire duration of the DNS procedure, it will be released when it is finished*/
belle_sip_object_ref(ctx);
ctx->srv_ctx=belle_sip_stack_resolve_srv(stack,transport,name,process_srv_results,ctx);
ctx->srv_ctx=belle_sip_stack_resolve_srv(stack,service,transport,name,process_srv_results,ctx);
if (ctx->srv_ctx) belle_sip_object_ref(ctx->srv_ctx);
if (ctx->base.done){
belle_sip_object_unref(ctx);
......@@ -1077,12 +1074,12 @@ belle_sip_resolver_context_t * belle_sip_stack_resolve_a(belle_sip_stack_t *stac
return NULL;
}
belle_sip_resolver_context_t * belle_sip_stack_resolve_srv(belle_sip_stack_t *stack, const char *transport, const char *name, belle_sip_resolver_srv_callback_t cb, void *data) {
belle_sip_resolver_context_t * belle_sip_stack_resolve_srv(belle_sip_stack_t *stack, const char *service, const char *transport, const char *name, belle_sip_resolver_srv_callback_t cb, void *data) {
belle_sip_simple_resolver_context_t *ctx = belle_sip_object_new(belle_sip_simple_resolver_context_t);
belle_sip_resolver_context_init((belle_sip_resolver_context_t*)ctx,stack);
ctx->srv_cb_data = data;
ctx->srv_cb = cb;
ctx->name = belle_sip_concat(srv_prefix_from_transport(transport), name, NULL);
ctx->name = belle_sip_concat(srv_prefix_from_service_and_transport(service, transport), name, NULL);
ctx->type = DNS_T_SRV;
return (belle_sip_resolver_context_t*)resolver_start_query(ctx);
}
......
......@@ -1381,7 +1381,7 @@ void belle_sip_channel_resolve(belle_sip_channel_t *obj){
belle_sip_message("channel [%p]: starting resolution of %s", obj, obj->peer_name);
channel_set_state(obj,BELLE_SIP_CHANNEL_RES_IN_PROGRESS);
if (belle_sip_stack_dns_srv_enabled(obj->stack) && obj->lp!=NULL)
obj->resolver_ctx=belle_sip_stack_resolve(obj->stack, belle_sip_channel_get_transport_name_lower_case(obj), obj->peer_name, obj->peer_port, obj->ai_family, channel_res_done, obj);
obj->resolver_ctx=belle_sip_stack_resolve(obj->stack, "sip", belle_sip_channel_get_transport_name_lower_case(obj), obj->peer_name, obj->peer_port, obj->ai_family, channel_res_done, obj);
else
obj->resolver_ctx=belle_sip_stack_resolve_a(obj->stack, obj->peer_name, obj->peer_port, obj->ai_family, channel_res_done, obj);
if (obj->resolver_ctx){
......
......@@ -327,7 +327,7 @@ static void srv_query(void) {
if (!BC_ASSERT_PTR_NOT_NULL(client)) return;
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);
client->resolver_ctx = belle_sip_stack_resolve_srv(client->stack, "sip", "udp", SRV_DOMAIN, srv_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_NULL(client->srv_list);
......@@ -347,7 +347,7 @@ static void srv_a_query(void) {
if (!BC_ASSERT_PTR_NOT_NULL(client)) return;
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);
client->resolver_ctx = belle_sip_stack_resolve(client->stack, "sip", "udp", SRV_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_NOT_EQUAL(client->ai_list, NULL);
......@@ -363,7 +363,7 @@ static void srv_a_query_no_srv_result(void) {
if (!BC_ASSERT_PTR_NOT_NULL(client)) return;
timeout = belle_sip_stack_get_dns_timeout(client->stack);
client->resolver_ctx = belle_sip_stack_resolve(client->stack, "udp", IPV4_CNAME, SIP_PORT, AF_INET, a_resolve_done, client);
client->resolver_ctx = belle_sip_stack_resolve(client->stack, "sip", "udp", 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_NULL(client->ai_list);
......@@ -387,7 +387,7 @@ static void local_full_query(void) {
if (!BC_ASSERT_PTR_NOT_NULL(client)) return;
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);
client->resolver_ctx = belle_sip_stack_resolve(client->stack, "sip", "tcp", "localhost", 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);
......@@ -405,7 +405,7 @@ static void no_query_needed(void) {
endpoint_t *client = create_endpoint();
if (!BC_ASSERT_PTR_NOT_NULL(client)) return;
client->resolver_ctx = belle_sip_stack_resolve(client->stack, "udp", IPV4_SIP_IP, SIP_PORT, AF_INET, a_resolve_done, client);
client->resolver_ctx = belle_sip_stack_resolve(client->stack, "sip", "udp", IPV4_SIP_IP, SIP_PORT, AF_INET, a_resolve_done, client);
BC_ASSERT_PTR_NULL(client->resolver_ctx);
BC_ASSERT_TRUE(client->resolve_done);
BC_ASSERT_PTR_NOT_EQUAL(client->ai_list, NULL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment