1 Return-Path: <bremner@tethera.net>
\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 CE3DD431FDE
\r
6 for <notmuch@notmuchmail.org>; Fri, 21 Dec 2012 05:08:40 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 yFxlFkBB5X5D for <notmuch@notmuchmail.org>;
\r
16 Fri, 21 Dec 2012 05:08:39 -0800 (PST)
\r
17 Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])
\r
18 (using TLSv1 with cipher AES256-SHA (256/256 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 2A004431FBC
\r
21 for <notmuch@notmuchmail.org>; Fri, 21 Dec 2012 05:08:39 -0800 (PST)
\r
22 Received: from fctnnbsc30w-156034082078.dhcp-dynamic.fibreop.nb.bellaliant.net
\r
23 ([156.34.82.78] helo=zancas.localnet)
\r
24 by tesseract.cs.unb.ca with esmtpsa
\r
25 (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72)
\r
26 (envelope-from <bremner@tethera.net>)
\r
27 id 1Tm2L6-0005dd-RX; Fri, 21 Dec 2012 09:08:37 -0400
\r
28 Received: from bremner by zancas.localnet with local (Exim 4.80)
\r
29 (envelope-from <bremner@tethera.net>)
\r
30 id 1Tm2L1-0005yh-9F; Fri, 21 Dec 2012 09:08:31 -0400
\r
31 From: david@tethera.net
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [Patch v8 07/18] unhex_and_quote: new function to quote hex-decoded
\r
35 Date: Fri, 21 Dec 2012 09:08:16 -0400
\r
36 Message-Id: <1356095307-22895-7-git-send-email-david@tethera.net>
\r
37 X-Mailer: git-send-email 1.7.10.4
\r
38 In-Reply-To: <1356095307-22895-1-git-send-email-david@tethera.net>
\r
39 References: <1356095307-22895-1-git-send-email-david@tethera.net>
\r
41 Cc: David Bremner <bremner@debian.org>
\r
42 X-BeenThere: notmuch@notmuchmail.org
\r
43 X-Mailman-Version: 2.1.13
\r
45 List-Id: "Use and development of the notmuch mail system."
\r
46 <notmuch.notmuchmail.org>
\r
47 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
48 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
49 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
50 List-Post: <mailto:notmuch@notmuchmail.org>
\r
51 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
52 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
53 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
54 X-List-Received-Date: Fri, 21 Dec 2012 13:08:41 -0000
\r
56 From: David Bremner <bremner@debian.org>
\r
58 Space delimited tokens are hex decoded and then quoted according to
\r
59 Xapian rules. Prefixes and '*' are passed through unquoted, as is
\r
60 anything that hex-decoding would not change.
\r
62 tag-util.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
63 1 file changed, 81 insertions(+)
\r
65 diff --git a/tag-util.c b/tag-util.c
\r
66 index f89669a..46aab4e 100644
\r
69 @@ -56,6 +56,87 @@ illegal_tag (const char *tag, notmuch_bool_t remove)
\r
73 +/* Input is a hex encoded string, presumed to be a query for Xapian.
\r
75 + * Space delimited tokens are decoded and quoted, with '*' and prefixes
\r
76 + * of the form "foo:" passed through unquoted.
\r
78 +static tag_parse_status_t
\r
79 +unhex_and_quote (void *ctx, char *encoded, const char *line_for_error,
\r
80 + char **query_string)
\r
82 + char *tok = encoded;
\r
83 + size_t tok_len = 0;
\r
85 + size_t buf_len = 0;
\r
86 + tag_parse_status_t ret = TAG_PARSE_SUCCESS;
\r
88 + *query_string = talloc_strdup (ctx, "");
\r
90 + while ((tok = strtok_len (tok + tok_len, " ", &tok_len)) != NULL) {
\r
92 + size_t prefix_len;
\r
93 + char delim = *(tok + tok_len);
\r
95 + *(tok + tok_len++) = '\0';
\r
97 + prefix_len = hex_invariant (tok, tok_len);
\r
99 + if ((strcmp (tok, "*") == 0) || prefix_len >= tok_len - 1) {
\r
101 + /* pass some things through without quoting or decoding.
\r
102 + * Note for '*' this is mandatory.
\r
105 + if (! (*query_string = talloc_asprintf_append_buffer (
\r
106 + *query_string, "%s%c", tok, delim))) {
\r
108 + ret = line_error (TAG_PARSE_OUT_OF_MEMORY,
\r
109 + line_for_error, "aborting");
\r
114 + /* potential prefix: one for ':', then something after */
\r
115 + if ((tok_len - prefix_len > 2) && *(tok + prefix_len) == ':') {
\r
116 + if (! (*query_string = talloc_strndup_append (*query_string,
\r
118 + prefix_len + 1))) {
\r
119 + ret = line_error (TAG_PARSE_OUT_OF_MEMORY,
\r
120 + line_for_error, "aborting");
\r
123 + tok += prefix_len + 1;
\r
124 + tok_len -= prefix_len + 1;
\r
127 + if (hex_decode_inplace (tok) != HEX_SUCCESS) {
\r
128 + ret = line_error (TAG_PARSE_INVALID, line_for_error,
\r
129 + "hex decoding of token '%s' failed", tok);
\r
133 + if (double_quote_str (ctx, tok, &buf, &buf_len)) {
\r
134 + ret = line_error (TAG_PARSE_OUT_OF_MEMORY,
\r
135 + line_for_error, "aborting");
\r
139 + if (! (*query_string = talloc_asprintf_append_buffer (
\r
140 + *query_string, "%s%c", buf, delim))) {
\r
141 + ret = line_error (TAG_PARSE_OUT_OF_MEMORY,
\r
142 + line_for_error, "aborting");
\r
149 + if (ret != TAG_PARSE_SUCCESS && *query_string)
\r
150 + talloc_free (*query_string);
\r
155 parse_tag_line (void *ctx, char *line,
\r
156 tag_op_flag_t flags,
\r