Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 37B14431FAF for ; Fri, 27 Jul 2012 14:30:20 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id m9vMtwkBKBzl for ; Fri, 27 Jul 2012 14:30:19 -0700 (PDT) Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU [18.7.68.35]) by olra.theworths.org (Postfix) with ESMTP id 39740431FAE for ; Fri, 27 Jul 2012 14:30:19 -0700 (PDT) X-AuditID: 12074423-b7f396d0000008f4-1d-5013086abe92 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP id C3.16.02292.A6803105; Fri, 27 Jul 2012 17:30:18 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q6RLUIYf017969; Fri, 27 Jul 2012 17:30:18 -0400 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q6RLUG7H028955 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Fri, 27 Jul 2012 17:30:17 -0400 (EDT) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) (envelope-from ) id 1Sus6x-000126-TR; Fri, 27 Jul 2012 17:30:15 -0400 Date: Fri, 27 Jul 2012 17:30:15 -0400 From: Austin Clements To: Mark Walters Subject: Re: [PATCH 03/13] sprinter: Add a string_len method Message-ID: <20120727213015.GC8502@mit.edu> References: <1343183693-17134-1-git-send-email-amdragon@mit.edu> <1343183693-17134-4-git-send-email-amdragon@mit.edu> <87a9ynis8s.fsf@qmul.ac.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87a9ynis8s.fsf@qmul.ac.uk> User-Agent: Mutt/1.5.21 (2010-09-15) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmphleLIzCtJLcpLzFFi42IRYrdT183iEA4wmHtM12L1XB6L6zdnMjsw eeycdZfd49mqW8wBTFFcNimpOZllqUX6dglcGXuP3WAvuKBXMe/DCcYGxvXKXYycHBICJhIz t/xkgbDFJC7cW8/WxcjFISSwj1Fi19W37BDOBkaJ22vnMkE4J5kkln1/AOUsYZR4PvkoI0g/ i4CqxMzzW8FsNgENiW37l4PZIgI6ErcPLWAHsZkFpCW+/W5mArGFBWwkTsxdBrabV0BbYvuR TSwQQ6cySqx+0s8OkRCUODnzCQtEs5bEjX8vgZo5wAYt/8cBEuYE2rVyXQsziC0qoCIx5eQ2 tgmMQrOQdM9C0j0LoXsBI/MqRtmU3Crd3MTMnOLUZN3i5MS8vNQiXTO93MwSvdSU0k2M4MB2 Ud7B+Oeg0iFGAQ5GJR5epetCAUKsiWXFlbmHGCU5mJREeUvZhAOE+JLyUyozEosz4otKc1KL DzFKcDArifDa7AAq501JrKxKLcqHSUlzsCiJ815LuekvJJCeWJKanZpakFoEk5Xh4FCS4L3P DjRUsCg1PbUiLTOnBCHNxMEJMpwHaPh7kBre4oLE3OLMdIj8KUZFKXHePpCEAEgiozQPrheW eF4xigO9Isx7BaSKB5i04LpfAQ1mAhpsEQ1ydXFJIkJKqoHx3IdzJTOTWA0O/e6ycq3yZT7W e9SOjcn1Ak+1l/XJN/rL6p41nFhVr3xM98mH7TZ7xWa/tY78s9J59pL5zBpXovqtOb83ixhI 5TNvtU5sSNC2XBYTeLky8tZzySkNu/47/j/odmt5n2G05JL2mAdTF7pmTnixpPzM+ba8e/LB crXCJXeXSRorsRRnJBpqMRcVJwIA/ugG0BcDAAA= Cc: notmuch@notmuchmail.org X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Jul 2012 21:30:20 -0000 Quoth Mark Walters on Jul 25 at 7:57 pm: > > Hi > > I have read this series (apart from the test changes) and it is both > very nice to review and looks good. It builds and all tests pass at all > the interesting partial stages and when fully applied. I have a few very > minor comments. > > On Wed, 25 Jul 2012, Austin Clements wrote: > > This method allows callers to output strings with specific lengths. > > It's useful both for strings with embedded NULs (which JSON can > > represent, though parser support is apparently spotty), and > > non-terminated strings. > > --- > > sprinter-json.c | 11 +++++++++-- > > sprinter-text.c | 11 +++++++++-- > > sprinter.h | 1 + > > 3 files changed, 19 insertions(+), 4 deletions(-) > > > > diff --git a/sprinter-json.c b/sprinter-json.c > > index 4649655..2587ca6 100644 > > --- a/sprinter-json.c > > +++ b/sprinter-json.c > > @@ -89,7 +89,7 @@ json_end (struct sprinter *sp) > > } > > > > static void > > -json_string (struct sprinter *sp, const char *val) > > +json_string_len (struct sprinter *sp, const char *val, size_t len) > > { > > I think this function could do with a comment along the lines of the > commit message. It might be nice to document somewhere where/when we Will do. I put a comment on this function explaining how it handles NULs, as well as a comment on the generic vtable pointer explaining string_len. > might actually have nulls in an encoded string (are they allowed in > bodies, headers etc). Interestingly, RFC822, while being limited to 7-bit ASCII, explicitly did allow NULs [RFC822, CHAR non-terminal]. RFC2822 explicitly obsoletes them [RFC2822 4 or appendix B], which means consumers should support them, but generators must not generate them. As usual, MIME makes things more complicated by supporting a "binary" content transfer encoding that does permits NULs. However, good luck getting that through SMTP business; SMTP theoretically allows any ASCII control character, but the standard specifically warns that control characters other than SP, HT, CR, and LF should be avoided [RFC2821 4.1.1.4]. Even if you've negotiated the 8BITMIME extension [RFC1652], you're limited by what MIME's "8bit" content transfer encoding permits, which differs from the "binary" content transfer encoding by disallowing (guess what) NULs and long lines. In other words: yes. > Actually, do we know that the json emacs parser handles nulls correctly? It does. Emacs strings are clean, so json.el doesn't have to do special anything to support them. > Best wishes > > Mark > > static const char *const escapes[] = { > > ['\"'] = "\\\"", ['\\'] = "\\\\", ['\b'] = "\\b", > > @@ -98,7 +98,7 @@ json_string (struct sprinter *sp, const char *val) > > struct sprinter_json *spj = json_begin_value (sp); > > > > fputc ('"', spj->stream); > > - for (; *val; ++val) { > > + for (; len; ++val, --len) { > > unsigned char ch = *val; > > if (ch < ARRAY_SIZE (escapes) && escapes[ch]) > > fputs (escapes[ch], spj->stream); > > @@ -111,6 +111,12 @@ json_string (struct sprinter *sp, const char *val) > > } > > > > static void > > +json_string (struct sprinter *sp, const char *val) > > +{ > > + json_string_len (sp, val, strlen (val)); > > +} > > + > > +static void > > json_integer (struct sprinter *sp, int val) > > { > > struct sprinter_json *spj = json_begin_value (sp); > > @@ -166,6 +172,7 @@ sprinter_json_create (const void *ctx, FILE *stream) > > .begin_list = json_begin_list, > > .end = json_end, > > .string = json_string, > > + .string_len = json_string_len, > > .integer = json_integer, > > .boolean = json_boolean, > > .null = json_null, > > diff --git a/sprinter-text.c b/sprinter-text.c > > index b208840..dfa54b5 100644 > > --- a/sprinter-text.c > > +++ b/sprinter-text.c > > @@ -25,14 +25,20 @@ struct sprinter_text { > > }; > > > > static void > > -text_string (struct sprinter *sp, const char *val) > > +text_string_len (struct sprinter *sp, const char *val, size_t len) > > { > > struct sprinter_text *sptxt = (struct sprinter_text *) sp; > > > > if (sptxt->current_prefix != NULL) > > fprintf (sptxt->stream, "%s:", sptxt->current_prefix); > > > > - fputs(val, sptxt->stream); > > + fwrite (val, len, 1, sptxt->stream); > > +} > > + > > +static void > > +text_string (struct sprinter *sp, const char *val) > > +{ > > + text_string_len (sp, val, strlen (val)); > > } > > > > static void > > @@ -105,6 +111,7 @@ sprinter_text_create (const void *ctx, FILE *stream) > > .begin_list = text_begin_list, > > .end = text_end, > > .string = text_string, > > + .string_len = text_string_len, > > .integer = text_integer, > > .boolean = text_boolean, > > .null = text_null, > > diff --git a/sprinter.h b/sprinter.h > > index 6680d41..826a852 100644 > > --- a/sprinter.h > > +++ b/sprinter.h > > @@ -28,6 +28,7 @@ typedef struct sprinter { > > * For string, the char * must be UTF-8 encoded. > > */ > > void (*string) (struct sprinter *, const char *); > > + void (*string_len) (struct sprinter *, const char *, size_t); > > void (*integer) (struct sprinter *, int); > > void (*boolean) (struct sprinter *, notmuch_bool_t); > > void (*null) (struct sprinter *); > > > > _______________________________________________ > > notmuch mailing list > > notmuch@notmuchmail.org > > http://notmuchmail.org/mailman/listinfo/notmuch > -- Austin Clements MIT/'06/PhD/CSAIL amdragon@mit.edu http://web.mit.edu/amdragon Somewhere in the dream we call reality you will find me, searching for the reality we call dreams.