Commit c130b4eb authored by Simon Morlat's avatar Simon Morlat

add method to configure dns servers externally

parent 39a660c0
......@@ -61,6 +61,13 @@ BELLESIP_EXPORT unsigned char belle_sip_stack_dns_srv_enabled(const belle_sip_st
BELLESIP_EXPORT void belle_sip_stack_enable_dns_srv(belle_sip_stack_t *stack, unsigned char enable);
/**
* Override system's DNS servers used for DNS resolving by app-supplied list of dns servers.
* @param stack the stack
* @param servers a list of char*. It is copied internally.
**/
BELLESIP_EXPORT void belle_sip_stack_set_dns_servers(belle_sip_stack_t *stack, const belle_sip_list_t *servers);
/**
* Can be used to simulate network transmission delays, for tests.
**/
......
......@@ -523,13 +523,15 @@ struct belle_sip_stack{
int dscp;
char *dns_user_hosts_file; /* used to load additional hosts file for tests */
char *dns_resolv_conf; /*used to load custom resolv.conf, for tests*/
unsigned char dns_srv_enabled;
belle_sip_list_t *dns_servers; /*used when dns servers are supplied by app layer*/
/*http proxy stuff to be used by both http and sip provider*/
char *http_proxy_host;
int http_proxy_port;
char *http_proxy_username; /*for futur use*/
char *http_proxy_passwd; /*for futur use*/
char *http_proxy_username; /*for future use*/
char *http_proxy_passwd; /*for future use*/
unsigned char dns_srv_enabled;
};
belle_sip_hop_t* belle_sip_hop_new(const char* transport, const char *cname, const char* host,int port);
......
......@@ -168,8 +168,22 @@ void belle_sip_resolver_context_init(belle_sip_resolver_context_t *obj, belle_si
belle_sip_init_sockets(); /* Need to be called for DNS resolution to work on Windows platform. */
}
static int dns_resconf_nameservers_from_list(struct dns_resolv_conf *resconf, const belle_sip_list_t *l) {
int max_servers = sizeof(resconf->nameserver)/sizeof(struct sockaddr_storage);
int i;
const belle_sip_list_t *elem;
for (i = 0, elem = l; i < max_servers && elem != NULL; elem = elem->next) {
int error = dns_resconf_pton(&resconf->nameserver[i], (const char *) elem->data);
if (error == 0) ++i;
}
return i > 0 ? 0 : -1;
}
static struct dns_resolv_conf *resconf(belle_sip_simple_resolver_context_t *ctx) {
const char *path;
const belle_sip_list_t *servers;
int error;
if (ctx->resconf)
......@@ -180,8 +194,13 @@ static struct dns_resolv_conf *resconf(belle_sip_simple_resolver_context_t *ctx)
return NULL;
}
path=belle_sip_stack_get_dns_resolv_conf_file(ctx->base.stack);
if (!path){
path = belle_sip_stack_get_dns_resolv_conf_file(ctx->base.stack);
servers = ctx->base.stack->dns_servers;
if (servers){
belle_sip_message("%s using application supplied dns server list.", __FUNCTION__);
error = dns_resconf_nameservers_from_list(ctx->resconf, servers);
}else if (!path){
#if defined(USE_FIXED_NAMESERVERS)
error = dns_resconf_load_fixed_nameservers(ctx->resconf);
if (error) {
......
......@@ -4017,7 +4017,7 @@ static enum dns_resconf_keyword dns_resconf_keyword(const char *word) {
/** OpenBSD-style "[1.2.3.4]:53" nameserver syntax */
static int dns_resconf_pton(struct sockaddr_storage *ss, const char *src) {
int dns_resconf_pton(struct sockaddr_storage *ss, const char *src) {
struct { char buf[128], *p; } addr = { "", addr.buf };
unsigned short port = 0;
char *percent;
......
......@@ -910,6 +910,8 @@ int dns_resconf_loadfile(struct dns_resolv_conf *, FILE *);
int dns_resconf_loadpath(struct dns_resolv_conf *, const char *);
int dns_resconf_pton(struct sockaddr_storage *ss, const char *src);
#ifdef USE_FIXED_NAMESERVERS
int dns_resconf_load_fixed_nameservers(struct dns_resolv_conf *resconf);
#endif /* USE_FIXED_NAMESERVERS */
......
......@@ -104,6 +104,7 @@ static void belle_sip_stack_destroy(belle_sip_stack_t *stack){
if (stack->http_proxy_host) belle_sip_free(stack->http_proxy_host);
if (stack->http_proxy_passwd) belle_sip_free(stack->http_proxy_passwd);
if (stack->http_proxy_username) belle_sip_free(stack->http_proxy_username);
belle_sip_list_free_with_data(stack->dns_servers, belle_sip_free);
}
......@@ -251,6 +252,15 @@ void belle_sip_stack_set_dns_resolv_conf_file(belle_sip_stack_t *stack, const ch
stack->dns_resolv_conf = resolv_conf_file?belle_sip_strdup(resolv_conf_file):NULL;
}
void belle_sip_stack_set_dns_servers(belle_sip_stack_t *stack, const belle_sip_list_t *servers){
belle_sip_list_t *newservers = NULL;
if (servers) newservers = belle_sip_list_copy_with_data(servers, (void *(*)(void*))belle_sip_strdup);
if (stack->dns_servers){
belle_sip_list_free_with_data(stack->dns_servers, belle_sip_free);
}
stack->dns_servers = newservers;
}
const char* belle_sip_version_to_string() {
#ifdef BELLESIP_VERSION
return BELLESIP_VERSION;
......
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