Re: [PATCH] add has: query prefix to search for specific properties
[notmuch-archives.git] / ed / cb4c1856ba284f8cc7cb516d8c56c50f751627
1 Return-Path: <amdragon@mit.edu>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 37B14431FAF\r
6         for <notmuch@notmuchmail.org>; Fri, 27 Jul 2012 14:30:20 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id m9vMtwkBKBzl for <notmuch@notmuchmail.org>;\r
16         Fri, 27 Jul 2012 14:30:19 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU\r
18         [18.7.68.35])\r
19         by olra.theworths.org (Postfix) with ESMTP id 39740431FAE\r
20         for <notmuch@notmuchmail.org>; Fri, 27 Jul 2012 14:30:19 -0700 (PDT)\r
21 X-AuditID: 12074423-b7f396d0000008f4-1d-5013086abe92\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id C3.16.02292.A6803105; Fri, 27 Jul 2012 17:30:18 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q6RLUIYf017969; \r
27         Fri, 27 Jul 2012 17:30:18 -0400\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q6RLUG7H028955\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Fri, 27 Jul 2012 17:30:17 -0400 (EDT)\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1Sus6x-000126-TR; Fri, 27 Jul 2012 17:30:15 -0400\r
37 Date: Fri, 27 Jul 2012 17:30:15 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: Mark Walters <markwalters1009@gmail.com>\r
40 Subject: Re: [PATCH 03/13] sprinter: Add a string_len method\r
41 Message-ID: <20120727213015.GC8502@mit.edu>\r
42 References: <1343183693-17134-1-git-send-email-amdragon@mit.edu>\r
43         <1343183693-17134-4-git-send-email-amdragon@mit.edu>\r
44         <87a9ynis8s.fsf@qmul.ac.uk>\r
45 MIME-Version: 1.0\r
46 Content-Type: text/plain; charset=us-ascii\r
47 Content-Disposition: inline\r
48 In-Reply-To: <87a9ynis8s.fsf@qmul.ac.uk>\r
49 User-Agent: Mutt/1.5.21 (2010-09-15)\r
50 X-Brightmail-Tracker:\r
51  H4sIAAAAAAAAA+NgFmphleLIzCtJLcpLzFFi42IRYrdT183iEA4wmHtM12L1XB6L6zdnMjsw\r
52         eeycdZfd49mqW8wBTFFcNimpOZllqUX6dglcGXuP3WAvuKBXMe/DCcYGxvXKXYycHBICJhIz\r
53         t/xkgbDFJC7cW8/WxcjFISSwj1Fi19W37BDOBkaJ22vnMkE4J5kkln1/AOUsYZR4PvkoI0g/\r
54         i4CqxMzzW8FsNgENiW37l4PZIgI6ErcPLWAHsZkFpCW+/W5mArGFBWwkTsxdBrabV0BbYvuR\r
55         TSwQQ6cySqx+0s8OkRCUODnzCQtEs5bEjX8vgZo5wAYt/8cBEuYE2rVyXQsziC0qoCIx5eQ2\r
56         tgmMQrOQdM9C0j0LoXsBI/MqRtmU3Crd3MTMnOLUZN3i5MS8vNQiXTO93MwSvdSU0k2M4MB2\r
57         Ud7B+Oeg0iFGAQ5GJR5epetCAUKsiWXFlbmHGCU5mJREeUvZhAOE+JLyUyozEosz4otKc1KL\r
58         DzFKcDArifDa7AAq501JrKxKLcqHSUlzsCiJ815LuekvJJCeWJKanZpakFoEk5Xh4FCS4L3P\r
59         DjRUsCg1PbUiLTOnBCHNxMEJMpwHaPh7kBre4oLE3OLMdIj8KUZFKXHePpCEAEgiozQPrheW\r
60         eF4xigO9Isx7BaSKB5i04LpfAQ1mAhpsEQ1ydXFJIkJKqoHx3IdzJTOTWA0O/e6ycq3yZT7W\r
61         e9SOjcn1Ak+1l/XJN/rL6p41nFhVr3xM98mH7TZ7xWa/tY78s9J59pL5zBpXovqtOb83ixhI\r
62         5TNvtU5sSNC2XBYTeLky8tZzySkNu/47/j/odmt5n2G05JL2mAdTF7pmTnixpPzM+ba8e/LB\r
63         crXCJXeXSRorsRRnJBpqMRcVJwIA/ugG0BcDAAA=\r
64 Cc: notmuch@notmuchmail.org\r
65 X-BeenThere: notmuch@notmuchmail.org\r
66 X-Mailman-Version: 2.1.13\r
67 Precedence: list\r
68 List-Id: "Use and development of the notmuch mail system."\r
69         <notmuch.notmuchmail.org>\r
70 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
71         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
72 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
73 List-Post: <mailto:notmuch@notmuchmail.org>\r
74 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
75 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
76         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
77 X-List-Received-Date: Fri, 27 Jul 2012 21:30:20 -0000\r
78 \r
79 Quoth Mark Walters on Jul 25 at  7:57 pm:\r
80\r
81 > Hi\r
82\r
83 > I have read this series (apart from the test changes) and it is both\r
84 > very nice to review and looks good. It builds and all tests pass at all\r
85 > the interesting partial stages and when fully applied. I have a few very\r
86 > minor comments.\r
87\r
88 > On Wed, 25 Jul 2012, Austin Clements <amdragon@MIT.EDU> wrote:\r
89 > > This method allows callers to output strings with specific lengths.\r
90 > > It's useful both for strings with embedded NULs (which JSON can\r
91 > > represent, though parser support is apparently spotty), and\r
92 > > non-terminated strings.\r
93 > > ---\r
94 > >  sprinter-json.c |   11 +++++++++--\r
95 > >  sprinter-text.c |   11 +++++++++--\r
96 > >  sprinter.h      |    1 +\r
97 > >  3 files changed, 19 insertions(+), 4 deletions(-)\r
98 > >\r
99 > > diff --git a/sprinter-json.c b/sprinter-json.c\r
100 > > index 4649655..2587ca6 100644\r
101 > > --- a/sprinter-json.c\r
102 > > +++ b/sprinter-json.c\r
103 > > @@ -89,7 +89,7 @@ json_end (struct sprinter *sp)\r
104 > >  }\r
105 > >  \r
106 > >  static void\r
107 > > -json_string (struct sprinter *sp, const char *val)\r
108 > > +json_string_len (struct sprinter *sp, const char *val, size_t len)\r
109 > >  {\r
110\r
111 > I think this function could do with a comment along the lines of the\r
112 > commit message. It might be nice to document somewhere where/when we\r
113 \r
114 Will do.  I put a comment on this function explaining how it handles\r
115 NULs, as well as a comment on the generic vtable pointer explaining\r
116 string_len.\r
117 \r
118 > might actually have nulls in an encoded string (are they allowed in\r
119 > bodies, headers etc).\r
120 \r
121 Interestingly, RFC822, while being limited to 7-bit ASCII, explicitly\r
122 did allow NULs [RFC822, CHAR non-terminal].  RFC2822 explicitly\r
123 obsoletes them [RFC2822 4 or appendix B], which means consumers should\r
124 support them, but generators must not generate them.  As usual, MIME\r
125 makes things more complicated by supporting a "binary" content\r
126 transfer encoding that does permits NULs.  However, good luck getting\r
127 that through SMTP business; SMTP theoretically allows any ASCII\r
128 control character, but the standard specifically warns that control\r
129 characters other than SP, HT, CR, and LF should be avoided [RFC2821\r
130 4.1.1.4].  Even if you've negotiated the 8BITMIME extension [RFC1652],\r
131 you're limited by what MIME's "8bit" content transfer encoding\r
132 permits, which differs from the "binary" content transfer encoding by\r
133 disallowing (guess what) NULs and long lines.\r
134 \r
135 In other words: yes.\r
136 \r
137 > Actually, do we know that the json emacs parser handles nulls correctly?\r
138 \r
139 It does.  Emacs strings are clean, so json.el doesn't have to do\r
140 special anything to support them.\r
141 \r
142 > Best wishes\r
143\r
144 > Mark\r
145 > >      static const char *const escapes[] = {\r
146 > >     ['\"'] = "\\\"", ['\\'] = "\\\\", ['\b'] = "\\b",\r
147 > > @@ -98,7 +98,7 @@ json_string (struct sprinter *sp, const char *val)\r
148 > >      struct sprinter_json *spj = json_begin_value (sp);\r
149 > >  \r
150 > >      fputc ('"', spj->stream);\r
151 > > -    for (; *val; ++val) {\r
152 > > +    for (; len; ++val, --len) {\r
153 > >     unsigned char ch = *val;\r
154 > >     if (ch < ARRAY_SIZE (escapes) && escapes[ch])\r
155 > >         fputs (escapes[ch], spj->stream);\r
156 > > @@ -111,6 +111,12 @@ json_string (struct sprinter *sp, const char *val)\r
157 > >  }\r
158 > >  \r
159 > >  static void\r
160 > > +json_string (struct sprinter *sp, const char *val)\r
161 > > +{\r
162 > > +    json_string_len (sp, val, strlen (val));\r
163 > > +}\r
164 > > +\r
165 > > +static void\r
166 > >  json_integer (struct sprinter *sp, int val)\r
167 > >  {\r
168 > >      struct sprinter_json *spj = json_begin_value (sp);\r
169 > > @@ -166,6 +172,7 @@ sprinter_json_create (const void *ctx, FILE *stream)\r
170 > >         .begin_list = json_begin_list,\r
171 > >         .end = json_end,\r
172 > >         .string = json_string,\r
173 > > +       .string_len = json_string_len,\r
174 > >         .integer = json_integer,\r
175 > >         .boolean = json_boolean,\r
176 > >         .null = json_null,\r
177 > > diff --git a/sprinter-text.c b/sprinter-text.c\r
178 > > index b208840..dfa54b5 100644\r
179 > > --- a/sprinter-text.c\r
180 > > +++ b/sprinter-text.c\r
181 > > @@ -25,14 +25,20 @@ struct sprinter_text {\r
182 > >  };\r
183 > >  \r
184 > >  static void\r
185 > > -text_string (struct sprinter *sp, const char *val)\r
186 > > +text_string_len (struct sprinter *sp, const char *val, size_t len)\r
187 > >  {\r
188 > >      struct sprinter_text *sptxt = (struct sprinter_text *) sp;\r
189 > >  \r
190 > >      if (sptxt->current_prefix != NULL)\r
191 > >     fprintf (sptxt->stream, "%s:", sptxt->current_prefix);\r
192 > >  \r
193 > > -    fputs(val, sptxt->stream);\r
194 > > +    fwrite (val, len, 1, sptxt->stream);\r
195 > > +}\r
196 > > +\r
197 > > +static void\r
198 > > +text_string (struct sprinter *sp, const char *val)\r
199 > > +{\r
200 > > +    text_string_len (sp, val, strlen (val));\r
201 > >  }\r
202 > >  \r
203 > >  static void\r
204 > > @@ -105,6 +111,7 @@ sprinter_text_create (const void *ctx, FILE *stream)\r
205 > >         .begin_list = text_begin_list,\r
206 > >         .end = text_end,\r
207 > >         .string = text_string,\r
208 > > +       .string_len = text_string_len,\r
209 > >         .integer = text_integer,\r
210 > >         .boolean = text_boolean,\r
211 > >         .null = text_null,\r
212 > > diff --git a/sprinter.h b/sprinter.h\r
213 > > index 6680d41..826a852 100644\r
214 > > --- a/sprinter.h\r
215 > > +++ b/sprinter.h\r
216 > > @@ -28,6 +28,7 @@ typedef struct sprinter {\r
217 > >       * For string, the char * must be UTF-8 encoded.\r
218 > >       */\r
219 > >      void (*string) (struct sprinter *, const char *);\r
220 > > +    void (*string_len) (struct sprinter *, const char *, size_t);\r
221 > >      void (*integer) (struct sprinter *, int);\r
222 > >      void (*boolean) (struct sprinter *, notmuch_bool_t);\r
223 > >      void (*null) (struct sprinter *);\r
224 > >\r
225 > > _______________________________________________\r
226 > > notmuch mailing list\r
227 > > notmuch@notmuchmail.org\r
228 > > http://notmuchmail.org/mailman/listinfo/notmuch\r
229\r
230 \r
231 -- \r
232 Austin Clements                                      MIT/'06/PhD/CSAIL\r
233 amdragon@mit.edu                           http://web.mit.edu/amdragon\r
234        Somewhere in the dream we call reality you will find me,\r
235               searching for the reality we call dreams.\r