Sure, here are attached changes.

Please let me know if I should improve them even further.


On Tue, May 27, 2014 at 12:39 PM, Jakub Hrozek <jhro...@redhat.com> wrote:

> On Tue, May 27, 2014 at 12:53:41AM +0400, Fedor Indutny wrote:
> > Agreed, will look into implementing it.
>
> Would you consider also adding TTL when creating this "ares_parse_txt2"
> ?
>
> >
> >
> > On Tue, May 27, 2014 at 12:50 AM, Daniel Stenberg <dan...@haxx.se>
> wrote:
> >
> > > On Thu, 22 May 2014, Fedor Indutny wrote:
> > >
> > >  Unfortunately, there is no certain description of how TXT records
> should
> > >> be used after parsing. Clearly some people may want to get each chunk
> of
> > >> each record separately and use them as they want to. Concatenation
> will
> > >> definitely make c-ares unusable for them.
> > >>
> > >
> > > An option is to introduce another function that can return this info
> and
> > > yet we maintain API and ABI backwards compatibility.
> > >
> > > --
> > >
> > >  / daniel.haxx.se
> > >
>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

- From 2dd4eec675ccc605cc88cc2099b109c2db05e128 Mon Sep 17 00:00:00 2001
From: Fedor Indutny <fe...@indutny.com>
Date: Fri, 28 Mar 2014 00:14:59 +0400
Subject: [PATCH] ares_parse_txt_reply: ares_parse_chunked_txt_reply

Introduce `ares_parse_chunked_txt_reply` function, that inserts empty
TXT chunks at the record boundary. With this information it is possible
to distinguish chunks from one record from chunks of another.
- ---
 ares.h                 |  3 +++
 ares_parse_txt_reply.c | 35 +++++++++++++++++++++++++++++++----
 2 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/ares.h b/ares.h
index 9b3f376..b74080a 100644
- --- a/ares.h
+++ b/ares.h
@@ -536,6 +536,9 @@ CARES_EXTERN int ares_parse_mx_reply(const unsigned char* 
abuf,
 CARES_EXTERN int ares_parse_txt_reply(const unsigned char* abuf,
                                       int alen,
                                       struct ares_txt_reply** txt_out);
+CARES_EXTERN int ares_parse_chunked_txt_reply(const unsigned char* abuf,
+                                              int alen,
+                                              struct ares_txt_reply** txt_out);
 
 CARES_EXTERN int ares_parse_naptr_reply(const unsigned char* abuf,
                                         int alen,
diff --git a/ares_parse_txt_reply.c b/ares_parse_txt_reply.c
index 981db4c..52662a8 100644
- --- a/ares_parse_txt_reply.c
+++ b/ares_parse_txt_reply.c
@@ -45,8 +45,8 @@
 #include "ares_private.h"
 
 int
- -ares_parse_txt_reply (const unsigned char *abuf, int alen,
- -                      struct ares_txt_reply **txt_out)
+ares__parse_txt_reply (const unsigned char *abuf, int alen,
+                       int chunked, struct ares_txt_reply **txt_out)
 {
   size_t substr_len;
   unsigned int qdcount, ancount, i;
@@ -54,6 +54,7 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen,
   const unsigned char *strptr;
   int status, rr_type, rr_class, rr_len;
   long len;
+  unsigned char record_start;
   char *hostname = NULL, *rr_name = NULL;
   struct ares_txt_reply *txt_head = NULL;
   struct ares_txt_reply *txt_last = NULL;
@@ -133,8 +134,6 @@ 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);
               if (!txt_curr)
@@ -142,6 +141,12 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen,
                   status = ARES_ENOMEM;
                   break;
                 }
+
+              /* Mark record starts with { .txt = NULL, .length = 0 } chunks */
+              record_start = chunked &&
+                             strptr == aptr &&
+                             txt_last != NULL &&
+                             txt_last->txt != NULL;
               if (txt_last)
                 {
                   txt_last->next = txt_curr;
@@ -152,6 +157,12 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen,
                 }
               txt_last = txt_curr;
 
+              if (record_start) {
+                txt_curr->txt = NULL;
+                txt_curr->length = 0;
+                continue;
+              }
+
               txt_curr->length = substr_len;
               txt_curr->txt = malloc (substr_len + 1/* Including null byte */);
               if (txt_curr->txt == NULL)
@@ -159,6 +170,8 @@ ares_parse_txt_reply (const unsigned char *abuf, int alen,
                   status = ARES_ENOMEM;
                   break;
                 }
+
+              ++strptr;
               memcpy ((char *) txt_curr->txt, strptr, substr_len);
 
               /* Make sure we NULL-terminate */
@@ -194,3 +207,17 @@ 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, txt_out);
+}
+
+int
+ares_parse_chunked_txt_reply (const unsigned char *abuf, int alen,
+                              struct ares_txt_reply **txt_out)
+{
+  return ares__parse_txt_reply(abuf, alen, 1, txt_out);
+}
- -- 
1.9.3

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBAgAGBQJThGGhAAoJEPsOEJWxeXmZ1F0P/1chcr7jjeQOWHmX1J72Mask
79eDr5gRXRPKk1aH6y5kyYKONbt8Pzmx+W9h57vqAuhaQfg22MVuGH+R07D4M+Ug
KSiyL5Q9XvQhZ6uc5Y8vE5KUHsNFir5nYqpyidRVe5zLfrs18KfLKbjpMghZw2T8
yRuGren27GbfJg2NWKGg3x/RbXCAnWy3hsgT4nYmOPUITTb135v6OYBBJUON7wn5
NQIxVAOYdEQMU15Yp9izUFuLaPFRFT/akJCqdByqs0hzhRPNLTiWAvN7I+u+OQ8+
7Yy5qNzM8D+fwJjzmicF8RK3qvdjK8JYuZVvLgmNuQa5Nksz5ePZFRF2jypllDg1
s/BsoJN9pNDe5pTP5PWG24YDJaGv7h+57KmstTtHwfpIqdZysIErw9hVcnScHyNR
3blYKpxxDs4PJSKzGWACNDfB02qs9knATh8ma83lb8HOoJABbYb5KxaaHzR0d+Z3
abMV+JJZmp60dpmBbXBtRLvHluO9xBK8wUuK7SEdp/FnKyDyrRBe+IteDk6AerB3
DcuaurbSc+NmAHcEGVkd5hybtrQwkDJV283tBKYk/vYI+gpyQCcliTZnHnug5etv
R58MmS49DDSUzdtOngm8zfBmSgEbVGe9SIVk+g98ONcH/QZwJlhX1+IuLiRDZi/v
tmPwV5csNLWaIUILUkqm
=GGPf
-----END PGP SIGNATURE-----

Attachment: 0001-ares_parse_txt_reply-ares_parse_chunked_txt_reply.patch
Description: Binary data

Reply via email to