Re: [PATCH v2] Omit User-Agent: header by default
[notmuch-archives.git] / 12 / ddcd28cfd161e676545ea4a65908acbb97528e
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 8032A431FB6\r
6         for <notmuch@notmuchmail.org>; Sun, 30 Dec 2012 21:52:24 -0800 (PST)\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 V-44hOknVuAK for <notmuch@notmuchmail.org>;\r
16         Sun, 30 Dec 2012 21:52:23 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU\r
18         [18.7.68.36])\r
19         by olra.theworths.org (Postfix) with ESMTP id 1836E431FAF\r
20         for <notmuch@notmuchmail.org>; Sun, 30 Dec 2012 21:52:23 -0800 (PST)\r
21 X-AuditID: 12074424-b7f4e6d0000004ca-7e-50e128149662\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
23         by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 3C.80.01226.41821E05; Mon, 31 Dec 2012 00:52:20 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id qBV5qKr4025387; \r
27         Mon, 31 Dec 2012 00:52:20 -0500\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 qBV5qHf6006487\r
32         (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT);\r
33         Mon, 31 Dec 2012 00:52:19 -0500 (EST)\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1TpYIL-0007eU-Ay; Mon, 31 Dec 2012 00:52:17 -0500\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: Tomi Ollila <tomi.ollila@iki.fi>, notmuch@notmuchmail.org\r
39 Subject: Re: [PATCH v3 2/5] util: Function to parse boolean term queries\r
40 In-Reply-To: <m2han4sepu.fsf@guru.guru-group.fi>\r
41 References: <1356719189-2837-1-git-send-email-amdragon@mit.edu>\r
42         <1356719189-2837-3-git-send-email-amdragon@mit.edu>\r
43         <m2han4sepu.fsf@guru.guru-group.fi>\r
44 User-Agent: Notmuch/0.14+236~gf64406d (http://notmuchmail.org) Emacs/23.4.1\r
45         (i486-pc-linux-gnu)\r
46 Date: Mon, 31 Dec 2012 00:52:17 -0500\r
47 Message-ID: <87a9sulqem.fsf@awakening.csail.mit.edu>\r
48 MIME-Version: 1.0\r
49 Content-Type: text/plain; charset=us-ascii\r
50 X-Brightmail-Tracker:\r
51  H4sIAAAAAAAAA+NgFnrAIsWRmVeSWpSXmKPExsUixCmqrCui8TDAYP9Ma4vrN2cyW7xZOY/V\r
52         gcnj8NeFLB7PVt1iDmCK4rJJSc3JLEst0rdL4Mo49ymmYLdixctfr5gbGA9IdjFycEgImEhs\r
53         OVzWxcgJZIpJXLi3ng3EFhLYxyjR+IGzi5ELyN7AKLHw0QMmCOcik8SiyQ0sEM4SRompvcvZ\r
54         QVrYBDQktu1fzghiiwjYSlxZcpIVxBYW8JDYuPEsE4jNKWAg8ej0U3aI5umMEi1rHoIlRAXi\r
55         JZ7f+8YCYrMIqErMXb6ZGcTmBTpv3b1J7BC2oMTJmU/AapgFtCRu/HvJNIFRYBaS1CwkqQWM\r
56         TKsYZVNyq3RzEzNzilOTdYuTE/PyUot0zfVyM0v0UlNKNzGCApLdRWUHY/MhpUOMAhyMSjy8\r
57         G/4/CBBiTSwrrsw9xCjJwaQkyquu/DBAiC8pP6UyI7E4I76oNCe1+BCjBAezkgjv0XlA5bwp\r
58         iZVVqUX5MClpDhYlcd7rKTf9hQTSE0tSs1NTC1KLYLIyHBxKErxa6kBDBYtS01Mr0jJzShDS\r
59         TBycIMN5gIabgtTwFhck5hZnpkPkTzEqSonzioEkBEASGaV5cL2whPGKURzoFWFeIZAqHmCy\r
60         get+BTSYCWiwFgPI1cUliQgpqQZGj/5foq4lzgzHljXNUprd0utrdLRePXbiI84oibNxsSkt\r
61         j5+8emDRt/+Nnc8jWZkzrNUxbZ+zCvQTVob9nidut2jv4iMzN3PuzpfVsp/y5OKit00WV/5w\r
62         XFlz/n4lo23u7UnzfNes+dL3qtXzghLDhV/VTLMjKsuCGNU8jt7d6exqPGfxvVg7JZbijERD\r
63         Leai4kQA9lwoOfMCAAA=\r
64 X-BeenThere: notmuch@notmuchmail.org\r
65 X-Mailman-Version: 2.1.13\r
66 Precedence: list\r
67 List-Id: "Use and development of the notmuch mail system."\r
68         <notmuch.notmuchmail.org>\r
69 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
70         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
71 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
72 List-Post: <mailto:notmuch@notmuchmail.org>\r
73 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
74 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
75         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
76 X-List-Received-Date: Mon, 31 Dec 2012 05:52:24 -0000\r
77 \r
78 On Sat, 29 Dec 2012, Tomi Ollila <tomi.ollila@iki.fi> wrote:\r
79 > On Fri, Dec 28 2012, Austin Clements <amdragon@MIT.EDU> wrote:\r
80 >\r
81 >> This parses the subset of Xapian's boolean term quoting rules that are\r
82 >> used by make_boolean_term.  This is provided as a generic string\r
83 >> utility, but will be used shortly in notmuch restore to parse and\r
84 >> optimize for ID queries.\r
85 >> ---\r
86 >>  util/string-util.c |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++\r
87 >>  util/string-util.h |   11 +++++++++++\r
88 >>  2 files changed, 66 insertions(+)\r
89 >>\r
90 >> diff --git a/util/string-util.c b/util/string-util.c\r
91 >> index e4bea21..83b4953 100644\r
92 >> --- a/util/string-util.c\r
93 >> +++ b/util/string-util.c\r
94 >> @@ -96,3 +96,58 @@ make_boolean_term (void *ctx, const char *prefix, const char *term,\r
95 >>  \r
96 >>      return 0;\r
97 >>  }\r
98 >> +\r
99 >> +int\r
100 >> +parse_boolean_term (void *ctx, const char *str,\r
101 >> +                char **prefix_out, char **term_out)\r
102 >> +{\r
103 >> +    *prefix_out = *term_out = NULL;\r
104 >> +\r
105 >> +    /* Parse prefix */\r
106 >> +    const char *pos = strchr (str, ':');\r
107 >> +    if (! pos)\r
108 >> +    goto FAIL;\r
109 >> +    *prefix_out = talloc_strndup (ctx, str, pos - str);\r
110 >> +    ++pos;\r
111 >> +\r
112 >> +    /* Implement de-quoting compatible with make_boolean_term. */\r
113 >> +    if (*pos == '"') {\r
114 >> +    char *out = talloc_array (ctx, char, strlen (pos));\r
115 >> +    int closed = 0;\r
116 >> +    *term_out = out;\r
117 >> +    /* Skip the opening quote, find the closing quote, and\r
118 >> +     * un-double doubled internal quotes. */\r
119 >> +    for (++pos; *pos; ) {\r
120 >> +        if (*pos == '"') {\r
121 >> +            ++pos;\r
122 >> +            if (*pos != '"') {\r
123 >> +                /* Found the closing quote. */\r
124 >> +                closed = 1;\r
125 >> +                break;\r
126 >> +            }\r
127 >> +        }\r
128 >> +        *out++ = *pos++;\r
129 >> +    }\r
130 >> +    /* Did the term terminate without a closing quote or is there\r
131 >> +     * trailing text after the closing quote? */\r
132 >> +    if (!closed || *pos)\r
133 >> +        goto FAIL;\r
134 >> +    *out = '\0';\r
135 >> +    } else {\r
136 >> +    const char *start = pos;\r
137 >> +    /* Check for text after the boolean term. */\r
138 >> +    while (*pos > ' ' && *pos != ')')\r
139 >> +        ++pos;\r
140 >> +    if (*pos)\r
141 >> +        goto FAIL;\r
142 >\r
143 > Mark pointed out a good case about trailing whitespace -- It would be nice\r
144 > if the core were lenient for such cases. I personally remember once wasting\r
145 > hours of work by just failing to notice trailing whitespace in one system\r
146 > so this subject is sensitive to me...\r
147 \r
148 Will do.\r
149 \r
150 > Another thing I saw earlyer today: make_boolean_term() checks\r
151 >\r
152 >    if (*in <= ' ' || *in == ')' || *in == '"' || (unsigned char)*in > 127)\r
153 >\r
154 > but here the check is only\r
155 >\r
156 >    while (*pos > ' ' && *pos != ')')\r
157 >\r
158 > I wonder whether it matters...\r
159 \r
160 This is correct in a conservative way.  We quote things that we don't\r
161 strictly need to quote (for example, a double quote in the middle of a\r
162 term doesn't actually require the term to be quoted, but we do anyway),\r
163 but we look for the end of an unquoted term in exactly the same way\r
164 Xapian does.\r
165 \r
166 > Everyting else looks good to me.\r
167 >\r
168 >\r
169 > Tomi\r
170 >\r
171 >> +    /* No trailing text; dup the string so the caller can free\r
172 >> +     * it. */\r
173 >> +    *term_out = talloc_strdup (ctx, start);\r
174 >> +    }\r
175 >> +    return 0;\r
176 >> +\r
177 >> + FAIL:\r
178 >> +    talloc_free (*prefix_out);\r
179 >> +    talloc_free (*term_out);\r
180 >> +    return 1;\r
181 >> +}\r
182 >> diff --git a/util/string-util.h b/util/string-util.h\r
183 >> index b8844a3..43d49d0 100644\r
184 >> --- a/util/string-util.h\r
185 >> +++ b/util/string-util.h\r
186 >> @@ -33,4 +33,15 @@ char *strtok_len (char *s, const char *delim, size_t *len);\r
187 >>  int make_boolean_term (void *talloc_ctx, const char *prefix, const char *term,\r
188 >>                     char **buf, size_t *len);\r
189 >>  \r
190 >> +/* Parse a boolean term query produced by make_boolean_term, returning\r
191 >> + * the prefix in *prefix_out and the term in *term_out.  *prefix_out\r
192 >> + * and *term_out will be talloc'd with context ctx.\r
193 >> + *\r
194 >> + * Return: 0 on success, non-zero on parse error (including trailing\r
195 >> + * data in str).\r
196 >> + */\r
197 >> +int\r
198 >> +parse_boolean_term (void *ctx, const char *str,\r
199 >> +                char **prefix_out, char **term_out);\r
200 >> +\r
201 >>  #endif\r
202 >> -- \r
203 >> 1.7.10.4\r
204 >>\r
205 >> _______________________________________________\r
206 >> notmuch mailing list\r
207 >> notmuch@notmuchmail.org\r
208 >> http://notmuchmail.org/mailman/listinfo/notmuch\r