From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id ADdMGHb3A2FtgQEAgWs5BA (envelope-from ) for ; Fri, 30 Jul 2021 14:58:30 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 6EfQE3b3A2GONQAAbx9fmQ (envelope-from ) for ; Fri, 30 Jul 2021 12:58:30 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id DC3E0D88A for ; Fri, 30 Jul 2021 14:58:29 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 5268E29905; Fri, 30 Jul 2021 08:57:12 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 705F729205 for ; Fri, 30 Jul 2021 08:56:34 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 68ECE5FD17; Fri, 30 Jul 2021 08:56:34 -0400 (EDT) Received: (nullmailer pid 2166868 invoked by uid 1000); Fri, 30 Jul 2021 12:56:10 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 03/27] lib: define notmuch_query_create_with_syntax Date: Fri, 30 Jul 2021 09:55:43 -0300 Message-Id: <20210730125607.2165433-4-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210730125607.2165433-1-david@tethera.net> References: <20210730125607.2165433-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: 3WZML77LWT4R57GAR3T45BNOR5U3O6UB X-Message-ID-Hash: 3WZML77LWT4R57GAR3T45BNOR5U3O6UB X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1627649910; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Yg/ijaht3ePH6T4ikOFx3Jh2JJs1OIYRjhjOWUX48cU=; b=OlONt72yyGZBI8feX05Nl2el9pg1GG/qw2QQaOTMgjnLoI1sGIrtK1mvquFImr4AsNjFu0 hU4CB8h73eIdGJfu0vjytuqi7tlHOzCTuhc+eVfCBtBBwwbznVgBPhI0Q9FG2fG044hIMs tbxmtVbd4LmJAyavGQtzGOAvsAvoJq6YczVdyCHBCeVvWTgaw9JxcrZnQdCbd9QW/a6OhH RVBA00C8ztGf03eS6DnEGLu4VkhLwxWMVown7nJM8J8MCTNQYU8YvdJBIBVm4sjyZBfAW/ S8JZsv61xVl6Oh5jnCm120+nNj0w42OHL34phkBRq/Ig4AldtdWmWh4O8+wNjw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1627649910; a=rsa-sha256; cv=none; b=NooIcGtwEAoCxm5VS33q+4MCCat0Z4n5jbdRrz+dts3ziY2UONAJlLAEqpD0PPZft+FfS0 YRpCHEt+fiTF25HHExCM6Nk5Xft6MMEXZLt5tdRnOtKnek7b6oQPtFEnpL6pHAWtACs+PB DWl4BPouKjbKnmQ9tRquvTgUBIVcCykWxPjgWJ0HO9V19aXbbRMSJyMwlqlmra2BIcp324 ANTaIruosZ+4o4rlUa7MjSdKWompO76RhaMIBxRIt9JDTX/cm+VRpsqc0ywt8B9YdALXIf DQrSeDX+NL9Bp2AvRmz65047cfXg9sLMv42verwv+pPrFDp0jZVU6tgixrK9sw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: 0.49 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: DC3E0D88A X-Spam-Score: 0.49 X-Migadu-Scanner: scn0.migadu.com X-TUID: svCdZeKpaOz2 Set the parsing syntax when the (notmuch) query object is created. Initially the library always returns a trivial query that matches all messages when using s-expression syntax. It seems better to select the syntax at query creation time because the lazy parsing is an implementation detail. --- lib/notmuch.h | 10 +++++++ lib/query.cc | 73 ++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 76 insertions(+), 7 deletions(-) diff --git a/lib/notmuch.h b/lib/notmuch.h index 3b28bea3..6f33c045 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -961,6 +961,16 @@ notmuch_query_t * notmuch_query_create (notmuch_database_t *database, const char *query_string); +typedef enum { + NOTMUCH_QUERY_SYNTAX_XAPIAN, + NOTMUCH_QUERY_SYNTAX_SEXP +} notmuch_query_syntax_t; + +notmuch_status_t +notmuch_query_create_with_syntax (notmuch_database_t *database, + const char *query_string, + notmuch_query_syntax_t syntax, + notmuch_query_t **output); /** * Sort values for notmuch_query_set_sort. */ diff --git a/lib/query.cc b/lib/query.cc index 39b85e91..12fd9482 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -23,6 +23,8 @@ #include /* GHashTable, GPtrArray */ +#include "sexp.h" + struct _notmuch_query { notmuch_database_t *notmuch; const char *query_string; @@ -30,6 +32,7 @@ struct _notmuch_query { notmuch_string_list_t *exclude_terms; notmuch_exclude_t omit_excluded; bool parsed; + notmuch_query_syntax_t syntax; Xapian::Query xapian_query; std::set terms; }; @@ -105,7 +108,10 @@ _notmuch_query_constructor (notmuch_database_t *notmuch, query->notmuch = notmuch; - query->query_string = talloc_strdup (query, query_string); + if (query_string) + query->query_string = talloc_strdup (query, query_string); + else + query->query_string = NULL; query->sort = NOTMUCH_SORT_NEWEST_FIRST; @@ -121,20 +127,49 @@ notmuch_query_create (notmuch_database_t *notmuch, const char *query_string) { - notmuch_query_t *query = _notmuch_query_constructor (notmuch, query_string); + notmuch_query_t *query; + notmuch_status_t status; - if (! query) + status = notmuch_query_create_with_syntax (notmuch, query_string, + NOTMUCH_QUERY_SYNTAX_XAPIAN, + &query); + if (status) return NULL; return query; } -static notmuch_status_t -_notmuch_query_ensure_parsed (notmuch_query_t *query) +notmuch_status_t +notmuch_query_create_with_syntax (notmuch_database_t *notmuch, + const char *query_string, + notmuch_query_syntax_t syntax, + notmuch_query_t **output) { - if (query->parsed) - return NOTMUCH_STATUS_SUCCESS; + notmuch_query_t *query; + + if (! output) + return NOTMUCH_STATUS_NULL_POINTER; + + query = _notmuch_query_constructor (notmuch, query_string); + if (! query) + return NOTMUCH_STATUS_OUT_OF_MEMORY; + + if (syntax == NOTMUCH_QUERY_SYNTAX_SEXP && ! HAVE_SFSEXP) { + _notmuch_database_log (notmuch, "sexp query parser not available"); + return NOTMUCH_STATUS_ILLEGAL_ARGUMENT; + } + + query->syntax = syntax; + + *output = query; + + return NOTMUCH_STATUS_SUCCESS; +} + +static notmuch_status_t +_notmuch_query_ensure_parsed_xapian (notmuch_query_t *query) +{ try { query->xapian_query = query->notmuch->query_parser-> @@ -167,6 +202,30 @@ _notmuch_query_ensure_parsed (notmuch_query_t *query) return NOTMUCH_STATUS_SUCCESS; } +static notmuch_status_t +_notmuch_query_ensure_parsed_sexpr (notmuch_query_t *query) +{ + if (query->parsed) + return NOTMUCH_STATUS_SUCCESS; + + query->xapian_query = Xapian::Query::MatchAll; + return NOTMUCH_STATUS_SUCCESS; +} + +static notmuch_status_t +_notmuch_query_ensure_parsed (notmuch_query_t *query) +{ + if (query->parsed) + return NOTMUCH_STATUS_SUCCESS; + +#if HAVE_SFSEXP + if (query->syntax == NOTMUCH_QUERY_SYNTAX_SEXP) + return _notmuch_query_ensure_parsed_sexpr (query); +#endif + + return _notmuch_query_ensure_parsed_xapian (query); +} + const char * notmuch_query_get_query_string (const notmuch_query_t *query) { -- 2.30.2