summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiong Sauw Ming <ming@teluu.com>2016-10-27 05:47:06 +0000
committerLiong Sauw Ming <ming@teluu.com>2016-10-27 05:47:06 +0000
commitd77d36f42151dfb6c6c1aca842e09ad897acc4a3 (patch)
tree70e049184c67ff51457f5ad5acbdaf1bc8b32d35
parentc8a93aba0c56500aa4324b36f39e6a3a5615f3a4 (diff)
Fixed #1974: Various fixes for DNS IPv6
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5471 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjlib-util/src/pjlib-util/resolver.c11
-rw-r--r--pjlib-util/src/pjlib-util/srv_resolver.c17
-rw-r--r--pjsip/src/pjsip/sip_resolve.c14
3 files changed, 27 insertions, 15 deletions
diff --git a/pjlib-util/src/pjlib-util/resolver.c b/pjlib-util/src/pjlib-util/resolver.c
index 0a9819f1..debf8cd2 100644
--- a/pjlib-util/src/pjlib-util/resolver.c
+++ b/pjlib-util/src/pjlib-util/resolver.c
@@ -856,7 +856,7 @@ PJ_DEF(pj_status_t) pj_dns_resolver_start_query( pj_dns_resolver *resolver,
pj_time_val now;
struct res_key key;
struct cached_res *cache;
- pj_dns_async_query *q;
+ pj_dns_async_query *q, *p_q = NULL;
pj_uint32_t hval;
pj_status_t status = PJ_SUCCESS;
@@ -870,9 +870,6 @@ PJ_DEF(pj_status_t) pj_dns_resolver_start_query( pj_dns_resolver *resolver,
/* Check type */
PJ_ASSERT_RETURN(type > 0 && type < 0xFFFF, PJ_EINVAL);
- if (p_query)
- *p_query = NULL;
-
/* Build resource key for looking up hash tables */
init_res_key(&key, type, name);
@@ -991,10 +988,12 @@ PJ_DEF(pj_status_t) pj_dns_resolver_start_query( pj_dns_resolver *resolver,
pj_hash_set_np(resolver->hquerybyres, &q->key, sizeof(q->key),
0, q->hbufkey, q);
- if (p_query)
- *p_query = q;
+ p_q = q;
on_return:
+ if (p_query)
+ *p_query = p_q;
+
pj_mutex_unlock(resolver->mutex);
return status;
}
diff --git a/pjlib-util/src/pjlib-util/srv_resolver.c b/pjlib-util/src/pjlib-util/srv_resolver.c
index 339e5de6..8a4a599e 100644
--- a/pjlib-util/src/pjlib-util/srv_resolver.c
+++ b/pjlib-util/src/pjlib-util/srv_resolver.c
@@ -187,9 +187,12 @@ PJ_DEF(pj_status_t) pj_dns_srv_cancel_query(pj_dns_srv_async_query *query,
has_pending = PJ_TRUE;
}
if (srv->q_aaaa) {
- pj_dns_resolver_cancel_query(srv->q_aaaa, PJ_FALSE);
+ /* Check if it is a dummy query. */
+ if (srv->q_aaaa != (pj_dns_async_query*)0x1) {
+ pj_dns_resolver_cancel_query(srv->q_aaaa, PJ_FALSE);
+ has_pending = PJ_TRUE;
+ }
srv->q_aaaa = NULL;
- has_pending = PJ_TRUE;
}
}
@@ -485,12 +488,22 @@ static pj_status_t resolve_hostnames(pj_dns_srv_async_query *query_job)
srv->common.type = PJ_DNS_TYPE_A;
srv->common_aaaa.type = PJ_DNS_TYPE_AAAA;
srv->parent = query_job;
+ srv->q_a = NULL;
+ srv->q_aaaa = NULL;
status = PJ_SUCCESS;
/* Start DNA A record query */
if ((query_job->option & PJ_DNS_SRV_RESOLVE_AAAA_ONLY) == 0)
{
+ if ((query_job->option & PJ_DNS_SRV_RESOLVE_AAAA) != 0) {
+ /* If there will be DNS AAAA query too, let's setup
+ * a dummy one here, otherwise app callback may be called
+ * immediately (before DNS AAAA query is sent) when
+ * DNS A record is available in the cache.
+ */
+ srv->q_aaaa = (pj_dns_async_query*)0x1;
+ }
status = pj_dns_resolver_start_query(query_job->resolver,
&srv->target_name,
PJ_DNS_TYPE_A, 0,
diff --git a/pjsip/src/pjsip/sip_resolve.c b/pjsip/src/pjsip/sip_resolve.c
index e41e6e13..5053defc 100644
--- a/pjsip/src/pjsip/sip_resolve.c
+++ b/pjsip/src/pjsip/sip_resolve.c
@@ -453,7 +453,7 @@ PJ_DEF(void) pjsip_resolve( pjsip_resolver_t *resolver,
}
/* Resolve DNS AAAA record if address family is not fixed to IPv4 */
- if (af != pj_AF_INET()) {
+ if (af != pj_AF_INET() && status == PJ_SUCCESS) {
status = pj_dns_resolver_start_query(resolver->res,
&query->naptr[0].name,
PJ_DNS_TYPE_AAAA, 0,
@@ -531,9 +531,9 @@ static void dns_a_callback(void *user_data,
++srv->count;
}
-
- } else {
-
+ }
+
+ if (status != PJ_SUCCESS) {
char errmsg[PJ_ERR_MSG_SIZE];
/* Log error */
@@ -594,9 +594,9 @@ static void dns_aaaa_callback(void *user_data,
++srv->count;
}
-
- } else {
-
+ }
+
+ if (status != PJ_SUCCESS) {
char errmsg[PJ_ERR_MSG_SIZE];
/* Log error */