- Timestamp:
- Dec 19, 2008 12:26:42 PM (16 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/include/pjlib-util/srv_resolver.h
r2039 r2387 137 137 } pj_dns_srv_record; 138 138 139 140 /** Opaque declaration for DNS SRV query */ 141 typedef struct pj_dns_srv_async_query pj_dns_srv_async_query; 139 142 140 143 /** … … 185 188 void *token, 186 189 pj_dns_srv_resolver_cb *cb, 187 pj_dns_async_query **p_query); 190 pj_dns_srv_async_query **p_query); 191 192 193 /** 194 * Cancel an outstanding DNS SRV query. 195 * 196 * @param query The pending asynchronous query to be cancelled. 197 * @param notify If non-zero, the callback will be called with failure 198 * status to notify that the query has been cancelled. 199 * 200 * @return PJ_SUCCESS on success, or the appropriate error code, 201 */ 202 PJ_DECL(pj_status_t) pj_dns_srv_cancel_query(pj_dns_srv_async_query *query, 203 pj_bool_t notify); 188 204 189 205 -
pjproject/trunk/pjlib-util/src/pjlib-util/srv_resolver.c
r2039 r2387 22 22 #include <pj/assert.h> 23 23 #include <pj/log.h> 24 #include <pj/os.h> 24 25 #include <pj/pool.h> 25 26 #include <pj/rand.h> … … 31 32 #define ADDR_MAX_COUNT PJ_DNS_MAX_IP_IN_A_REC 32 33 34 struct common 35 { 36 pj_dns_type type; /**< Type of this structure.*/ 37 }; 38 33 39 struct srv_target 34 40 { 41 struct common common; 42 pj_dns_srv_async_query *parent; 35 43 pj_str_t target_name; 44 pj_dns_async_query *q_a; 36 45 char target_buf[PJ_MAX_HOSTNAME]; 37 46 pj_str_t cname; … … 45 54 }; 46 55 47 typedef struct pj_dns_srv_resolver_job 48 { 56 struct pj_dns_srv_async_query 57 { 58 struct common common; 49 59 char *objname; 50 60 61 pj_dns_type dns_state; /**< DNS type being resolved. */ 51 62 pj_dns_resolver *resolver; /**< Resolver SIP instance. */ 52 pj_dns_type dns_state; /**< DNS type being resolved. */53 63 void *token; 64 pj_dns_async_query *q_srv; 54 65 pj_dns_srv_resolver_cb *cb; 55 66 pj_status_t last_error; … … 68 79 unsigned host_resolved; 69 80 70 } pj_dns_srv_resolver_job;81 }; 71 82 72 83 … … 89 100 void *token, 90 101 pj_dns_srv_resolver_cb *cb, 91 pj_dns_ async_query **p_query)102 pj_dns_srv_async_query **p_query) 92 103 { 93 104 int len; 94 105 pj_str_t target_name; 95 pj_dns_srv_ resolver_job*query_job;106 pj_dns_srv_async_query *query_job; 96 107 pj_status_t status; 97 108 … … 112 123 113 124 /* Build the query_job state */ 114 query_job = PJ_POOL_ZALLOC_T(pool, pj_dns_srv_resolver_job); 125 query_job = PJ_POOL_ZALLOC_T(pool, pj_dns_srv_async_query); 126 query_job->common.type = PJ_DNS_TYPE_SRV; 115 127 query_job->objname = target_name.ptr; 116 128 query_job->resolver = resolver; … … 136 148 query_job->dns_state, 0, 137 149 &dns_callback, 138 query_job, p_query); 150 query_job, &query_job->q_srv); 151 if (status==PJ_SUCCESS && p_query) 152 *p_query = query_job; 153 139 154 return status; 140 155 } 141 156 157 158 /* 159 * Cancel pending query. 160 */ 161 PJ_DEF(pj_status_t) pj_dns_srv_cancel_query(pj_dns_srv_async_query *query, 162 pj_bool_t notify) 163 { 164 pj_bool_t has_pending = PJ_FALSE; 165 unsigned i; 166 167 if (query->q_srv) { 168 pj_dns_resolver_cancel_query(query->q_srv, PJ_FALSE); 169 query->q_srv = NULL; 170 has_pending = PJ_TRUE; 171 } 172 173 for (i=0; i<query->srv_cnt; ++i) { 174 struct srv_target *srv = &query->srv[i]; 175 if (srv->q_a) { 176 pj_dns_resolver_cancel_query(srv->q_a, PJ_FALSE); 177 srv->q_a = NULL; 178 has_pending = PJ_TRUE; 179 } 180 } 181 182 if (has_pending && notify && query->cb) { 183 (*query->cb)(query->token, PJ_ECANCELLED, NULL); 184 } 185 186 return has_pending? PJ_SUCCESS : PJ_EINVALIDOP; 187 } 142 188 143 189 … … 153 199 154 200 /* Build server entries in the query_job based on received SRV response */ 155 static void build_server_entries(pj_dns_srv_ resolver_job*query_job,201 static void build_server_entries(pj_dns_srv_async_query *query_job, 156 202 pj_dns_parsed_packet *response) 157 203 { … … 357 403 358 404 /* Start DNS A record queries for all SRV records in the query_job structure */ 359 static pj_status_t resolve_hostnames(pj_dns_srv_ resolver_job*query_job)405 static pj_status_t resolve_hostnames(pj_dns_srv_async_query *query_job) 360 406 { 361 407 unsigned i; … … 364 410 query_job->dns_state = PJ_DNS_TYPE_A; 365 411 for (i=0; i<query_job->srv_cnt; ++i) { 412 struct srv_target *srv = &query_job->srv[i]; 413 366 414 PJ_LOG(5, (query_job->objname, 367 415 "Starting async DNS A query_job for %.*s", 368 (int)query_job->srv[i].target_name.slen, 369 query_job->srv[i].target_name.ptr)); 416 (int)srv->target_name.slen, 417 srv->target_name.ptr)); 418 419 srv->common.type = PJ_DNS_TYPE_A; 420 srv->parent = query_job; 370 421 371 422 status = pj_dns_resolver_start_query(query_job->resolver, 372 & query_job->srv[i].target_name,423 &srv->target_name, 373 424 PJ_DNS_TYPE_A, 0, 374 425 &dns_callback, 375 query_job, NULL);426 srv, &srv->q_a); 376 427 if (status != PJ_SUCCESS) { 377 428 query_job->host_resolved++; … … 391 442 pj_dns_parsed_packet *pkt) 392 443 { 393 pj_dns_srv_resolver_job *query_job = (pj_dns_srv_resolver_job*) user_data; 444 struct common *common = (struct common*) user_data; 445 pj_dns_srv_async_query *query_job; 446 struct srv_target *srv = NULL; 394 447 unsigned i; 395 448 449 if (common->type == PJ_DNS_TYPE_SRV) { 450 query_job = (pj_dns_srv_async_query*) common; 451 srv = NULL; 452 } else if (common->type == PJ_DNS_TYPE_A) { 453 srv = (struct srv_target*) common; 454 query_job = srv->parent; 455 } else { 456 pj_assert(!"Unexpected user data!"); 457 query_job->last_error = status = PJ_EINVALIDOP; 458 goto on_error; 459 } 460 396 461 /* Proceed to next stage */ 397 398 462 if (query_job->dns_state == PJ_DNS_TYPE_SRV) { 399 463 400 464 /* We are getting SRV response */ 465 466 query_job->q_srv = NULL; 401 467 402 468 if (status == PJ_SUCCESS && pkt->hdr.anscount != 0) { … … 469 535 } else if (query_job->dns_state == PJ_DNS_TYPE_A) { 470 536 537 /* Clear the outstanding job */ 538 srv->q_a = NULL; 539 471 540 /* Check that we really have answer */ 472 541 if (status==PJ_SUCCESS && pkt->hdr.anscount != 0) { 473 unsigned srv_idx;474 struct srv_target *srv = NULL;475 542 pj_dns_a_record rec; 476 543 … … 481 548 482 549 pj_assert(rec.addr_count != 0); 483 484 /* Find which server entry to be updated. */485 for (srv_idx=0; srv_idx<query_job->srv_cnt; ++srv_idx) {486 srv = &query_job->srv[srv_idx];487 if (pj_stricmp(&rec.name, &srv->target_name)==0) {488 break;489 }490 }491 492 if (srv_idx==query_job->srv_cnt) {493 /* The DNS A response doesn't match any server names494 * we're querying!495 */496 status = PJLIB_UTIL_EDNSINANSWER;497 goto on_error;498 }499 500 srv = &query_job->srv[srv_idx];501 550 502 551 /* Update CNAME alias, if present. */ -
pjproject/trunk/pjnath/src/pjnath/stun_sock.c
r2383 r2387 48 48 pj_sockaddr mapped_addr; /* Our public address */ 49 49 50 pj_dns_ async_query*q; /* Pending DNS query */50 pj_dns_srv_async_query *q; /* Pending DNS query */ 51 51 pj_sock_t sock_fd; /* Socket descriptor */ 52 52 pj_activesock_t *active_sock; /* Active socket object */ … … 371 371 { 372 372 if (stun_sock->q) { 373 pj_dns_ resolver_cancel_query(stun_sock->q, PJ_FALSE);373 pj_dns_srv_cancel_query(stun_sock->q, PJ_FALSE); 374 374 stun_sock->q = NULL; 375 375 } -
pjproject/trunk/pjnath/src/pjnath/turn_session.c
r2386 r2387 87 87 pj_timer_entry timer; 88 88 89 pj_dns_ async_query*dns_async;89 pj_dns_srv_async_query *dns_async; 90 90 pj_uint16_t default_port; 91 91 … … 343 343 case PJ_TURN_STATE_RESOLVING: 344 344 if (sess->dns_async != NULL) { 345 pj_dns_ resolver_cancel_query(sess->dns_async, PJ_FALSE);345 pj_dns_srv_cancel_query(sess->dns_async, PJ_FALSE); 346 346 sess->dns_async = NULL; 347 347 }
Note: See TracChangeset
for help on using the changeset viewer.