summaryrefslogtreecommitdiff
path: root/ares_parse_txt_reply.c
diff options
context:
space:
mode:
Diffstat (limited to 'ares_parse_txt_reply.c')
-rw-r--r--ares_parse_txt_reply.c52
1 files changed, 38 insertions, 14 deletions
diff --git a/ares_parse_txt_reply.c b/ares_parse_txt_reply.c
index 981db4c..4856b4c 100644
--- a/ares_parse_txt_reply.c
+++ b/ares_parse_txt_reply.c
@@ -44,9 +44,9 @@
#include "ares_data.h"
#include "ares_private.h"
-int
-ares_parse_txt_reply (const unsigned char *abuf, int alen,
- struct ares_txt_reply **txt_out)
+static int
+ares__parse_txt_reply (const unsigned char *abuf, int alen,
+ int ex, void **txt_out)
{
size_t substr_len;
unsigned int qdcount, ancount, i;
@@ -55,9 +55,9 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen,
int status, rr_type, rr_class, rr_len;
long len;
char *hostname = NULL, *rr_name = NULL;
- struct ares_txt_reply *txt_head = NULL;
- struct ares_txt_reply *txt_last = NULL;
- struct ares_txt_reply *txt_curr;
+ struct ares_txt_ext *txt_head = NULL;
+ struct ares_txt_ext *txt_last = NULL;
+ struct ares_txt_ext *txt_curr;
/* Set *txt_out to NULL for all failure cases. */
*txt_out = NULL;
@@ -82,7 +82,7 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen,
if (aptr + len + QFIXEDSZ > abuf + alen)
{
- free (hostname);
+ ares_free (hostname);
return ARES_EBADRESP;
}
aptr += len + QFIXEDSZ;
@@ -133,10 +133,9 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen,
break;
}
- ++strptr;
-
/* Allocate storage for this TXT answer appending it to the list */
- txt_curr = ares_malloc_data(ARES_DATATYPE_TXT_REPLY);
+ txt_curr = ares_malloc_data(ex ? ARES_DATATYPE_TXT_EXT :
+ ARES_DATATYPE_TXT_REPLY);
if (!txt_curr)
{
status = ARES_ENOMEM;
@@ -152,13 +151,17 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen,
}
txt_last = txt_curr;
+ if (ex)
+ txt_curr->record_start = (strptr == aptr);
txt_curr->length = substr_len;
- txt_curr->txt = malloc (substr_len + 1/* Including null byte */);
+ txt_curr->txt = ares_malloc (substr_len + 1/* Including null byte */);
if (txt_curr->txt == NULL)
{
status = ARES_ENOMEM;
break;
}
+
+ ++strptr;
memcpy ((char *) txt_curr->txt, strptr, substr_len);
/* Make sure we NULL-terminate */
@@ -168,8 +171,14 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen,
}
}
+ /* Propagate any failures */
+ if (status != ARES_SUCCESS)
+ {
+ break;
+ }
+
/* Don't lose memory in the next iteration */
- free (rr_name);
+ ares_free (rr_name);
rr_name = NULL;
/* Move on to the next record */
@@ -177,9 +186,9 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen,
}
if (hostname)
- free (hostname);
+ ares_free (hostname);
if (rr_name)
- free (rr_name);
+ ares_free (rr_name);
/* clean up on error */
if (status != ARES_SUCCESS)
@@ -194,3 +203,18 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen,
return ARES_SUCCESS;
}
+
+int
+ares_parse_txt_reply (const unsigned char *abuf, int alen,
+ struct ares_txt_reply **txt_out)
+{
+ return ares__parse_txt_reply(abuf, alen, 0, (void **) txt_out);
+}
+
+
+int
+ares_parse_txt_reply_ext (const unsigned char *abuf, int alen,
+ struct ares_txt_ext **txt_out)
+{
+ return ares__parse_txt_reply(abuf, alen, 1, (void **) txt_out);
+}