From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id oAq8B1C302FvCAAAgWs5BA (envelope-from ) for ; Tue, 04 Jan 2022 03:56:16 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id aJdCBFC302Ho7QAAauVa8A (envelope-from ) for ; Tue, 04 Jan 2022 03:56:16 +0100 Received: from mail.notmuchmail.org (yantan.tethera.net [IPv6:2a01:4f9:c011:7a79::1]) (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 D2BB112C1C for ; Tue, 4 Jan 2022 03:56:15 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 6581C5F731; Tue, 4 Jan 2022 02:55:48 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id F06D55F726 for ; Tue, 4 Jan 2022 02:55:44 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id 1F7F15FC42; Mon, 3 Jan 2022 21:55:43 -0500 (EST) Received: (nullmailer pid 1725903 invoked by uid 1000); Tue, 04 Jan 2022 02:55:35 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 3/6] lib/date: factor out date range parsing. Date: Mon, 3 Jan 2022 22:55:26 -0400 Message-Id: <20220104025529.1725839-4-david@tethera.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220104025529.1725839-1-david@tethera.net> References: <20220104025529.1725839-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: B2L3HMZTTUSOOB4G4II3LJ35FC4NDJNF X-Message-ID-Hash: B2L3HMZTTUSOOB4G4II3LJ35FC4NDJNF 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; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1641264975; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to: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-owner:list-unsubscribe:list-subscribe:list-post; bh=hcqpPfa1ObGXbpwOCbw1x87i/A4BBwc43qSNweTeTaw=; b=ntoA8Taj8a32HCSkb/2t32ITMPKg6AfjMGVC08pjFuodNeA6c0qaSoF6BAS78twJHHzOX1 ZdgUiia5cShD50PQK5EggFzQwkKOsMfJrqrWB5+elYeqcyjs/1Dov+ESjW8HDYoxvHQlnj p+dIPUu70nqnVTvKqhJye0Fo0fDSL6+kFSqmBLE7NI3Dcb2oyw7IK6x89OBv1n/WBy5A68 aQJW0EF/9zX5Br7Vu+KCQgW7OheE3fTumTqzGm7OBTHaP+Wx+xam7INXy4ozRL+7N7hhbS Pipvj2v5MJmGzDfC1JTYp6zVfFDmbKu/BgEF8jA5mw2+VLr+njWX/vMT87pCDw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1641264975; a=rsa-sha256; cv=none; b=b5NzSjrmb7hWnUVALa+aAmz2dXE+g5VeMJIbyY/VSlL0NpIonVS3l/+u144/isTPnr3xkU bKi3yORjyGSKRjay3AYIMrgcjFJOMKDd50QSIzlTHw0PKfHRnW4wm6Gj3TbR+zY0hoJzxa CFqRNPkA+cK4oDgw5NZFsj1OaHC0zHlX9MzE0zzrAbGoTOTIuayoen1rkYIDiCM3TpwSAE LgqJj3G65RC4VYgjfOCyf7pft+AWE4XdfJX11V/AaJulYZb6OUqxlGlQL15vyUbmmJAnIu zh5j2c5fxgag9Hat/w+eKtiWZEOk9LA2cL6+6aPUjQvKH/Bm/dg4yjkb3vKsaA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.24 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: D2BB112C1C X-Spam-Score: -1.24 X-Migadu-Scanner: scn1.migadu.com X-TUID: l3sMd9HZwDt8 This will allow re-using the same logic in the s-expression parser. --- lib/database-private.h | 5 +++++ lib/parse-time-vrp.cc | 51 +++++++++++++++++++++++++++++------------- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/lib/database-private.h b/lib/database-private.h index 8133e364..1663ae3c 100644 --- a/lib/database-private.h +++ b/lib/database-private.h @@ -374,5 +374,10 @@ notmuch_status_t _notmuch_sexp_string_to_xapian_query (notmuch_database_t *notmuch, const char *querystr, Xapian::Query &output); #endif + +/* parse-time-vrp.h */ +notmuch_status_t +_notmuch_date_strings_to_query (Xapian::valueno slot, const std::string &from, const std::string &to, + Xapian::Query &output, std::string &msg); #endif #endif diff --git a/lib/parse-time-vrp.cc b/lib/parse-time-vrp.cc index 22bf2ab5..6b07970b 100644 --- a/lib/parse-time-vrp.cc +++ b/lib/parse-time-vrp.cc @@ -24,22 +24,28 @@ #include "parse-time-vrp.h" #include "parse-time-string.h" -Xapian::Query -ParseTimeRangeProcessor::operator() (const std::string &begin, const std::string &end) +notmuch_status_t +_notmuch_date_strings_to_query (Xapian::valueno slot, + const std::string &begin, const std::string &end, + Xapian::Query &output, std::string &msg) { double from = DBL_MIN, to = DBL_MAX; time_t parsed_time, now; std::string str; /* Use the same 'now' for begin and end. */ - if (time (&now) == (time_t) -1) - throw Xapian::QueryParserError ("unable to get current time"); + if (time (&now) == (time_t) -1) { + msg = "unable to get current time"; + return NOTMUCH_STATUS_ILLEGAL_ARGUMENT; + } if (! begin.empty ()) { - if (parse_time_string (begin.c_str (), &parsed_time, &now, PARSE_TIME_ROUND_DOWN)) - throw Xapian::QueryParserError ("Didn't understand date specification '" + begin + "'"); - else - from = (double) parsed_time; + if (parse_time_string (begin.c_str (), &parsed_time, &now, PARSE_TIME_ROUND_DOWN)) { + msg = "Didn't understand date specification '" + begin + "'"; + return NOTMUCH_STATUS_BAD_QUERY_SYNTAX; + } + + from = (double) parsed_time; } if (! end.empty ()) { @@ -48,15 +54,30 @@ ParseTimeRangeProcessor::operator() (const std::string &begin, const std::string else str = end; - if (parse_time_string (str.c_str (), &parsed_time, &now, PARSE_TIME_ROUND_UP_INCLUSIVE)) - throw Xapian::QueryParserError ("Didn't understand date specification '" + str + "'"); - else - to = (double) parsed_time; + if (parse_time_string (str.c_str (), &parsed_time, &now, PARSE_TIME_ROUND_UP_INCLUSIVE)) { + msg = "Didn't understand date specification '" + str + "'"; + return NOTMUCH_STATUS_BAD_QUERY_SYNTAX; + } + to = (double) parsed_time; } - return Xapian::Query (Xapian::Query::OP_VALUE_RANGE, slot, - Xapian::sortable_serialise (from), - Xapian::sortable_serialise (to)); + output = Xapian::Query (Xapian::Query::OP_VALUE_RANGE, slot, + Xapian::sortable_serialise (from), + Xapian::sortable_serialise (to)); + return NOTMUCH_STATUS_SUCCESS; +} + +Xapian::Query +ParseTimeRangeProcessor::operator() (const std::string &begin, const std::string &end) +{ + + Xapian::Query output; + std::string msg; + + if (_notmuch_date_strings_to_query (slot, begin, end, output, msg)) + throw Xapian::QueryParserError (msg); + + return output; } /* XXX TODO: is throwing an exception the right thing to do here? */ -- 2.34.1