Skip to content

Commit

Permalink
Move unchanging conditions from the loops to the outer "if" block in …
Browse files Browse the repository at this point in the history
…outgoing_answer_aaaa() and outgoing_answer_a().
  • Loading branch information
morbit85 committed Sep 9, 2024
1 parent d9b502f commit c95c40d
Showing 1 changed file with 47 additions and 39 deletions.
86 changes: 47 additions & 39 deletions libsofia-sip-ua/nta/nta.c
Original file line number Diff line number Diff line change
Expand Up @@ -10876,43 +10876,47 @@ void outgoing_answer_aaaa(sres_context_t *orq, sres_query_t *q,
su_home_t *home = msg_home(orq->orq_request);
struct sipdns_query *sq = sr->sr_current;

size_t i, j, found;
size_t i, j, found = 0;
char *result, **results = NULL;

assert(sq); assert(sq->sq_type == sres_type_aaaa);

sr->sr_query = NULL;

for (i = 0, found = 0; answers && answers[i]; i++) {
sres_aaaa_record_t const *aaaa = answers[i]->sr_aaaa;
if (aaaa->aaaa_record->r_status == 0 &&
aaaa->aaaa_record->r_type == sres_type_aaaa)
found++;
if (answers) {
for (i = 0; answers[i]; i++) {
sres_aaaa_record_t const *aaaa = answers[i]->sr_aaaa;
if (aaaa->aaaa_record->r_status == 0 &&
aaaa->aaaa_record->r_type == sres_type_aaaa)
found++;
}
}

if (found > 1)
results = su_zalloc(home, (found + 1) * (sizeof *results));
else if (found)
results = &result;

for (i = j = 0; (found > 0) && answers && answers[i]; i++) {
char addr[SU_ADDRSIZE];
sres_aaaa_record_t const *aaaa = answers[i]->sr_aaaa;
if (found) {
for (i = j = 0; answers[i]; i++) {
char addr[SU_ADDRSIZE];
sres_aaaa_record_t const *aaaa = answers[i]->sr_aaaa;

if (aaaa->aaaa_record->r_status ||
aaaa->aaaa_record->r_type != sres_type_aaaa)
continue; /* There was an error */
if (aaaa->aaaa_record->r_status ||
aaaa->aaaa_record->r_type != sres_type_aaaa)
continue; /* There was an error */

su_inet_ntop(AF_INET6, &aaaa->aaaa_addr, addr, sizeof(addr));
su_inet_ntop(AF_INET6, &aaaa->aaaa_addr, addr, sizeof(addr));

if (j == 0)
SU_DEBUG_5(("nta(%p): %s IN AAAA %s\n", (void *)orq,
aaaa->aaaa_record->r_name, addr));
else
SU_DEBUG_5(("nta(%p): AAAA %s\n", (void *)orq, addr));
if (j == 0)
SU_DEBUG_5(("nta(%p): %s IN AAAA %s\n", (void *)orq,
aaaa->aaaa_record->r_name, addr));
else
SU_DEBUG_5(("nta(%p): AAAA %s\n", (void *)orq, addr));

assert(j < found);
results[j++] = su_strdup(home, addr);
assert(j < found);
results[j++] = su_strdup(home, addr);
}
}

sres_free_answers(orq->orq_agent->sa_resolver, answers);
Expand Down Expand Up @@ -10959,42 +10963,46 @@ void outgoing_answer_a(sres_context_t *orq, sres_query_t *q,
su_home_t *home = msg_home(orq->orq_request);
struct sipdns_query *sq = sr->sr_current;

int i, j, found;
int i, j, found = 0;
char *result, **results = NULL;

assert(sq); assert(sq->sq_type == sres_type_a);

sr->sr_query = NULL;

for (i = 0, found = 0; answers && answers[i]; i++) {
sres_a_record_t const *a = answers[i]->sr_a;
if (a->a_record->r_status == 0 &&
a->a_record->r_type == sres_type_a)
found++;
if (answers) {
for (i = 0; answers[i]; i++) {
sres_a_record_t const *a = answers[i]->sr_a;
if (a->a_record->r_status == 0 &&
a->a_record->r_type == sres_type_a)
found++;
}
}

if (found > 1)
results = su_zalloc(home, (found + 1) * (sizeof *results));
else if (found)
results = &result;

for (i = j = 0; (found > 0) && answers && answers[i]; i++) {
char addr[SU_ADDRSIZE];
sres_a_record_t const *a = answers[i]->sr_a;
if (found) {
for (i = j = 0; answers[i]; i++) {
char addr[SU_ADDRSIZE];
sres_a_record_t const *a = answers[i]->sr_a;

if (a->a_record->r_status ||
a->a_record->r_type != sres_type_a)
continue; /* There was an error */
if (a->a_record->r_status ||
a->a_record->r_type != sres_type_a)
continue; /* There was an error */

su_inet_ntop(AF_INET, &a->a_addr, addr, sizeof(addr));
su_inet_ntop(AF_INET, &a->a_addr, addr, sizeof(addr));

if (j == 0)
SU_DEBUG_5(("nta: %s IN A %s\n", a->a_record->r_name, addr));
else
SU_DEBUG_5(("nta(%p): A %s\n", (void *)orq, addr));
if (j == 0)
SU_DEBUG_5(("nta: %s IN A %s\n", a->a_record->r_name, addr));
else
SU_DEBUG_5(("nta(%p): A %s\n", (void *)orq, addr));

assert(j < found);
results[j++] = su_strdup(home, addr);
assert(j < found);
results[j++] = su_strdup(home, addr);
}
}

sres_free_answers(orq->orq_agent->sa_resolver, answers);
Expand Down

0 comments on commit c95c40d

Please sign in to comment.