unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Austin Clements <amdragon@MIT.EDU>
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	[thread overview]
Message-ID: <1356719189-2837-1-git-send-email-amdragon@mit.edu> (raw)

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.

             reply	other threads:[~2012-12-28 18:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-28 18:26 Austin Clements [this message]
2012-12-28 18:26 ` [PATCH v3 1/5] util: Factor out boolean term quoting routine Austin Clements
2012-12-28 18:26 ` [PATCH v3 2/5] util: Function to parse boolean term queries Austin Clements
2012-12-29 16:50   ` Mark Walters
2012-12-29 21:58   ` Tomi Ollila
2012-12-31  5:52     ` Austin Clements
2012-12-28 18:26 ` [PATCH v3 3/5] dump: Disallow \n in message IDs Austin Clements
2012-12-28 18:26 ` [PATCH v3 4/5] dump/restore: Use Xapian queries for batch-tag format Austin Clements
2012-12-28 18:26 ` [PATCH v3 5/5] man: Update notmuch-dump(1) and notmuch-restore(1) Austin Clements

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1356719189-2837-1-git-send-email-amdragon@mit.edu \
    --to=amdragon@mit.edu \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).