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 5596B431FBC for ; Sat, 15 Dec 2012 15:21:14 -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 mCffs3Wdg9jU for ; Sat, 15 Dec 2012 15:21:13 -0800 (PST) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 90031431FB6 for ; Sat, 15 Dec 2012 15:21:13 -0800 (PST) Received: by mail-lb0-f181.google.com with SMTP id ge1so3677411lbb.26 for ; Sat, 15 Dec 2012 15:21:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version:content-type:x-gm-message-state; bh=MOqD5O13QkhyqjrXlfbSVRQQCwlYc7EV0orGni2VkD0=; b=anqjtj8CbbzSKIxitZeMUxhYKNIlvdMD8d84KVKfzPor0GebfbnyD17ay9zxtULHJ/ 6yPh5TZOviGbHyN1dJZNQY/1tXvkgQ36ZaBmmgOWhiQt5n9bCM2JWDqd8eoKuSFLF2+e EgDBlIcq47kT8hbBy44XNNbIQsNfa0tHAwpuLC8Rf8QR9C0+KI8fMWwc0EFVh8IGnmDN 5YWjtppFtOHva3NiOa3cDnGSy0L/hFrDFoAuO0D0IOFpYAkdbNR9FxrLNfRtyrMefITj LnOo3kOulMPPB3FlrG52Qp4oD/+dOyKGiHyEFJBOGSslh3F8TB/MjG5UKzFvHChXGOtP URAA== Received: by 10.152.114.65 with SMTP id je1mr6640908lab.33.1355613672076; Sat, 15 Dec 2012 15:21:12 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi. [80.223.81.27]) by mx.google.com with ESMTPS id fb1sm3279699lbb.15.2012.12.15.15.21.10 (version=SSLv3 cipher=OTHER); Sat, 15 Dec 2012 15:21:11 -0800 (PST) From: Jani Nikula To: david@tethera.net, notmuch@notmuchmail.org Subject: Re: [Patch v7 05/14] quote_and_decode_query: new function to quote hex-decoded queries In-Reply-To: <1355492062-7546-6-git-send-email-david@tethera.net> References: <1355492062-7546-1-git-send-email-david@tethera.net> <1355492062-7546-6-git-send-email-david@tethera.net> User-Agent: Notmuch/0.14+138~g7041c56 (http://notmuchmail.org) Emacs/23.4.1 (i686-pc-linux-gnu) Date: Sun, 16 Dec 2012 01:21:08 +0200 Message-ID: <87mwxeq4uz.fsf@nikula.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Gm-Message-State: ALoCoQkUugskuohKOrRftlHv/wUvcjLnxsM49B3UxoB6X5CfSmD6cFsmNI8C2x+C07LMBSzoLhx0 Cc: David Bremner 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: Sat, 15 Dec 2012 23:21:15 -0000 On Fri, 14 Dec 2012, david@tethera.net wrote: > From: David Bremner > > The query is split into tokens, with ' ' and ':' as delimiters. Any > token containing some hex-escaped character is quoted according to > Xapian rules. This maps id:foo%20%22bar to id:"foo ""bar". > This intentionally does not quote prefixes, so they still work as prefixes. > --- > tag-util.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 50 insertions(+) > > diff --git a/tag-util.c b/tag-util.c > index f89669a..e1181f8 100644 > --- a/tag-util.c > +++ b/tag-util.c > @@ -56,6 +56,56 @@ illegal_tag (const char *tag, notmuch_bool_t remove) > return NULL; > } > > +static tag_parse_status_t > +quote_and_decode_query (void *ctx, char *encoded, const char *line_for_error, > + char **query_string) > +{ > + char *tok = encoded; > + size_t tok_len = 0; > + char *buf = NULL; > + size_t buf_len = 0; > + tag_parse_status_t ret = TAG_PARSE_SUCCESS; > + > + *query_string = talloc_strdup (ctx, ""); > + > + while (*query_string && > + (tok = strtok_len (tok + tok_len, ": ", &tok_len)) != NULL) { strtok_len() will eat all the leading delimiters at each call, and will not return a zero-length token if you have multiple consecutive delimiters. Which means you may end up losing stuff here. Whether that matters or not I'm too tired to tell... BR, Jani. > + char delim = tok[tok_len]; > + > + *(tok + tok_len++) = '\0'; > + > + if (strcspn (tok, "%") < tok_len - 1) { > + /* something to decode */ > + if (hex_decode_inplace (tok) != HEX_SUCCESS) { > + ret = line_error (TAG_PARSE_INVALID, line_for_error, > + "hex decoding of token '%s' failed", tok); > + goto DONE; > + } > + > + if (double_quote_str (ctx, tok, &buf, &buf_len)) { > + ret = line_error (TAG_PARSE_OUT_OF_MEMORY, > + line_for_error, "aborting"); > + goto DONE; > + } > + *query_string = talloc_asprintf_append_buffer ( > + *query_string, "%s%c", buf, delim); > + > + } else { > + /* This is not just an optimization, but used to preserve > + * prefixes like id:, which cannot be quoted. > + */ > + *query_string = talloc_asprintf_append_buffer ( > + *query_string, "%s%c", tok, delim); > + } > + > + } > + > + DONE: > + if (ret != TAG_PARSE_SUCCESS && *query_string) > + talloc_free (*query_string); > + return ret; > +} > + > tag_parse_status_t > parse_tag_line (void *ctx, char *line, > tag_op_flag_t flags, > -- > 1.7.10.4 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch