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 638BC431FAF for ; Fri, 28 Dec 2012 10:26:50 -0800 (PST) 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 KTh14KInYz0Y for ; Fri, 28 Dec 2012 10:26:49 -0800 (PST) Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU [18.9.25.15]) by olra.theworths.org (Postfix) with ESMTP id 53843431FBD for ; Fri, 28 Dec 2012 10:26:49 -0800 (PST) X-AuditID: 1209190f-b7f016d000000e07-1e-50dde4676cff Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP id 2C.80.03591.764EDD05; Fri, 28 Dec 2012 13:26:47 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id qBSIQk3n031994; Fri, 28 Dec 2012 13:26:46 -0500 Received: from drake.dyndns.org (c-76-21-105-205.hsd1.ca.comcast.net [76.21.105.205]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qBSIQf4B012711 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Fri, 28 Dec 2012 13:26:43 -0500 (EST) Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1Toedj-0000sN-Jp; Fri, 28 Dec 2012 13:26:39 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH v3 0/5] Use Xapian query syntax for batch-tag dump/restore Date: Fri, 28 Dec 2012 13:26:24 -0500 Message-Id: <1356719189-2837-1-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.10.4 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrKIsWRmVeSWpSXmKPExsUixCmqrJv+5G6AwZdlAhY3WrsZLZqmO1us nstjcf3mTGYHFo+ds+6ye9y6/5rd49mqW8weWw69Zw5gieKySUnNySxLLdK3S+DK+Hx5O0vB QaGKPedPMzYw7ubrYuTgkBAwkTjwVLSLkRPIFJO4cG89WxcjF4eQwD5GiRs7tzJCOBsYJa7u PwGVucgkcXTtTRYIZy6jxL/Dm5hA+tkENCS27V/OCGKLCEhL7Lw7mxXEZhZwlDjzuo0RZJ2w gJfE7v0VICaLgKrE7PeCIBW8AvYSH95sY4O4QlGi+9kEtgmMvAsYGVYxyqbkVunmJmbmFKcm 6xYnJ+blpRbpmujlZpbopaaUbmIEh44k/w7GbweVDjEKcDAq8fCeuH03QIg1say4MvcQoyQH k5Io7/IHQCG+pPyUyozE4oz4otKc1OJDjBIczEoivH3NQDnelMTKqtSifJiUNAeLkjjv1ZSb /kIC6YklqdmpqQWpRTBZGQ4OJQnepsdAjYJFqempFWmZOSUIaSYOTpDhPEDDp4DU8BYXJOYW Z6ZD5E8xKkqJ80aCJARAEhmleXC9sNh+xSgO9IowbyZIFQ8wLcB1vwIazAQ02JrnDsjgkkSE lFQDI/+eC10ue5XFFSdYr582e+b6j+e2zYyduHHnkYh1hRJBTWJfrtk1Cx55bbwk3KzE8LoJ 02rlcwkfYqdU1867/GTuP8UUNY+8yYHbJn+vNd/OPnGXo8ey912GWWtn8Jyv/dFzbGH0oeYj Vct3FsX49TJwbz2V0tw3z/HaJLOVz/m0/y2wPNS+64USS3FGoqEWc1FxIgAyrQ4CyAIAAA== 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, 28 Dec 2012 18:26:50 -0000 This obsoletes id:1356493723-11085-1-git-send-email-amdragon@mit.edu This version improves the documentation comment for make_boolean_term and hopefully simplifies parse_boolean_term (though in a somewhat different way than David suggested). The diff relative to v2 follows diff --git a/util/string-util.c b/util/string-util.c index db01b4b..83b4953 100644 --- a/util/string-util.c +++ b/util/string-util.c @@ -112,11 +112,12 @@ parse_boolean_term (void *ctx, const char *str, /* Implement de-quoting compatible with make_boolean_term. */ if (*pos == '"') { - char *out = talloc_strdup (ctx, pos + 1); + char *out = talloc_array (ctx, char, strlen (pos)); int closed = 0; - /* Find the closing quote and un-double doubled internal - * quotes. */ - for (pos = *term_out = out; *pos; ) { + *term_out = out; + /* Skip the opening quote, find the closing quote, and + * un-double doubled internal quotes. */ + for (++pos; *pos; ) { if (*pos == '"') { ++pos; if (*pos != '"') { @@ -133,12 +134,15 @@ parse_boolean_term (void *ctx, const char *str, goto FAIL; *out = '\0'; } else { - *term_out = talloc_strdup (ctx, pos); + const char *start = pos; /* Check for text after the boolean term. */ while (*pos > ' ' && *pos != ')') ++pos; if (*pos) goto FAIL; + /* No trailing text; dup the string so the caller can free + * it. */ + *term_out = talloc_strdup (ctx, start); } return 0; diff --git a/util/string-util.h b/util/string-util.h index aff2d65..43d49d0 100644 --- a/util/string-util.h +++ b/util/string-util.h @@ -20,7 +20,12 @@ char *strtok_len (char *s, const char *delim, size_t *len); /* Construct a boolean term query with the specified prefix (e.g., - * "id") and search term, quoting term as necessary. + * "id") and search term, quoting term as necessary. Specifically, if + * term contains any non-printable ASCII characters, non-ASCII + * characters, close parenthesis or double quotes, it will be enclosed + * in double quotes and any internal double quotes will be doubled + * (e.g. a"b -> "a""b"). The result will be a valid notmuch query and + * can be parsed by parse_boolean_term. * * Output is into buf; it may be talloc_realloced. * Return: 0 on success, non-zero on memory allocation failure.