Re: [PATCH 03/13] sprinter: Add a string_len method
authorMark Walters <markwalters1009@gmail.com>
Wed, 25 Jul 2012 18:57:07 +0000 (19:57 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:48:37 +0000 (09:48 -0800)
b4/2b0ef5467f91f55886866abe1ee358e5b03ac8 [new file with mode: 0644]

diff --git a/b4/2b0ef5467f91f55886866abe1ee358e5b03ac8 b/b4/2b0ef5467f91f55886866abe1ee358e5b03ac8
new file mode 100644 (file)
index 0000000..646a4e9
--- /dev/null
@@ -0,0 +1,203 @@
+Return-Path: <m.walters@qmul.ac.uk>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id F1B18431FAF\r
+       for <notmuch@notmuchmail.org>; Wed, 25 Jul 2012 11:57:15 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.098\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
+       tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+       NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id s+piZPTySxP4 for <notmuch@notmuchmail.org>;\r
+       Wed, 25 Jul 2012 11:57:14 -0700 (PDT)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 1CD36431FAE\r
+       for <notmuch@notmuchmail.org>; Wed, 25 Jul 2012 11:57:14 -0700 (PDT)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+       by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+       (envelope-from <m.walters@qmul.ac.uk>)\r
+       id 1Su6le-00025K-Re; Wed, 25 Jul 2012 19:57:09 +0100\r
+Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223]\r
+       helo=localhost)\r
+       by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
+       (envelope-from <m.walters@qmul.ac.uk>)\r
+       id 1Su6le-0001NX-F7; Wed, 25 Jul 2012 19:57:06 +0100\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 03/13] sprinter: Add a string_len method\r
+In-Reply-To: <1343183693-17134-4-git-send-email-amdragon@mit.edu>\r
+References: <1343183693-17134-1-git-send-email-amdragon@mit.edu>\r
+       <1343183693-17134-4-git-send-email-amdragon@mit.edu>\r
+User-Agent: Notmuch/0.13.2+93~gf33b188 (http://notmuchmail.org) Emacs/23.4.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Wed, 25 Jul 2012 19:57:07 +0100\r
+Message-ID: <87a9ynis8s.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 94.192.233.223\r
+X-QM-SPAM-Info: Sender has good ham record.  :)\r
+X-QM-Body-MD5: 0a00e831d3ee6423799d992541306787 (of first 20000 bytes)\r
+X-SpamAssassin-Score: -1.8\r
+X-SpamAssassin-SpamBar: -\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+       determine if it is\r
+       spam. We require at least 5.0 points to mark a message as spam.\r
+       This message scored -1.8 points.\r
+       Summary of the scoring: \r
+       * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
+       *      medium trust\r
+       *      [138.37.6.40 listed in list.dnswl.org]\r
+       * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+       provider *      (markwalters1009[at]gmail.com)\r
+       * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
+       *      domain\r
+       *  0.5 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Wed, 25 Jul 2012 18:57:16 -0000\r
+\r
+\r
+Hi\r
+\r
+I have read this series (apart from the test changes) and it is both\r
+very nice to review and looks good. It builds and all tests pass at all\r
+the interesting partial stages and when fully applied. I have a few very\r
+minor comments.\r
+\r
+On Wed, 25 Jul 2012, Austin Clements <amdragon@MIT.EDU> wrote:\r
+> This method allows callers to output strings with specific lengths.\r
+> It's useful both for strings with embedded NULs (which JSON can\r
+> represent, though parser support is apparently spotty), and\r
+> non-terminated strings.\r
+> ---\r
+>  sprinter-json.c |   11 +++++++++--\r
+>  sprinter-text.c |   11 +++++++++--\r
+>  sprinter.h      |    1 +\r
+>  3 files changed, 19 insertions(+), 4 deletions(-)\r
+>\r
+> diff --git a/sprinter-json.c b/sprinter-json.c\r
+> index 4649655..2587ca6 100644\r
+> --- a/sprinter-json.c\r
+> +++ b/sprinter-json.c\r
+> @@ -89,7 +89,7 @@ json_end (struct sprinter *sp)\r
+>  }\r
+>  \r
+>  static void\r
+> -json_string (struct sprinter *sp, const char *val)\r
+> +json_string_len (struct sprinter *sp, const char *val, size_t len)\r
+>  {\r
+\r
+I think this function could do with a comment along the lines of the\r
+commit message. It might be nice to document somewhere where/when we\r
+might actually have nulls in an encoded string (are they allowed in\r
+bodies, headers etc).\r
+\r
+Actually, do we know that the json emacs parser handles nulls correctly?\r
+\r
+Best wishes\r
+\r
+Mark\r
+>      static const char *const escapes[] = {\r
+>      ['\"'] = "\\\"", ['\\'] = "\\\\", ['\b'] = "\\b",\r
+> @@ -98,7 +98,7 @@ json_string (struct sprinter *sp, const char *val)\r
+>      struct sprinter_json *spj = json_begin_value (sp);\r
+>  \r
+>      fputc ('"', spj->stream);\r
+> -    for (; *val; ++val) {\r
+> +    for (; len; ++val, --len) {\r
+>      unsigned char ch = *val;\r
+>      if (ch < ARRAY_SIZE (escapes) && escapes[ch])\r
+>          fputs (escapes[ch], spj->stream);\r
+> @@ -111,6 +111,12 @@ json_string (struct sprinter *sp, const char *val)\r
+>  }\r
+>  \r
+>  static void\r
+> +json_string (struct sprinter *sp, const char *val)\r
+> +{\r
+> +    json_string_len (sp, val, strlen (val));\r
+> +}\r
+> +\r
+> +static void\r
+>  json_integer (struct sprinter *sp, int val)\r
+>  {\r
+>      struct sprinter_json *spj = json_begin_value (sp);\r
+> @@ -166,6 +172,7 @@ sprinter_json_create (const void *ctx, FILE *stream)\r
+>          .begin_list = json_begin_list,\r
+>          .end = json_end,\r
+>          .string = json_string,\r
+> +        .string_len = json_string_len,\r
+>          .integer = json_integer,\r
+>          .boolean = json_boolean,\r
+>          .null = json_null,\r
+> diff --git a/sprinter-text.c b/sprinter-text.c\r
+> index b208840..dfa54b5 100644\r
+> --- a/sprinter-text.c\r
+> +++ b/sprinter-text.c\r
+> @@ -25,14 +25,20 @@ struct sprinter_text {\r
+>  };\r
+>  \r
+>  static void\r
+> -text_string (struct sprinter *sp, const char *val)\r
+> +text_string_len (struct sprinter *sp, const char *val, size_t len)\r
+>  {\r
+>      struct sprinter_text *sptxt = (struct sprinter_text *) sp;\r
+>  \r
+>      if (sptxt->current_prefix != NULL)\r
+>      fprintf (sptxt->stream, "%s:", sptxt->current_prefix);\r
+>  \r
+> -    fputs(val, sptxt->stream);\r
+> +    fwrite (val, len, 1, sptxt->stream);\r
+> +}\r
+> +\r
+> +static void\r
+> +text_string (struct sprinter *sp, const char *val)\r
+> +{\r
+> +    text_string_len (sp, val, strlen (val));\r
+>  }\r
+>  \r
+>  static void\r
+> @@ -105,6 +111,7 @@ sprinter_text_create (const void *ctx, FILE *stream)\r
+>          .begin_list = text_begin_list,\r
+>          .end = text_end,\r
+>          .string = text_string,\r
+> +        .string_len = text_string_len,\r
+>          .integer = text_integer,\r
+>          .boolean = text_boolean,\r
+>          .null = text_null,\r
+> diff --git a/sprinter.h b/sprinter.h\r
+> index 6680d41..826a852 100644\r
+> --- a/sprinter.h\r
+> +++ b/sprinter.h\r
+> @@ -28,6 +28,7 @@ typedef struct sprinter {\r
+>       * For string, the char * must be UTF-8 encoded.\r
+>       */\r
+>      void (*string) (struct sprinter *, const char *);\r
+> +    void (*string_len) (struct sprinter *, const char *, size_t);\r
+>      void (*integer) (struct sprinter *, int);\r
+>      void (*boolean) (struct sprinter *, notmuch_bool_t);\r
+>      void (*null) (struct sprinter *);\r
+> -- \r
+> 1.7.10\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r