From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id qH/LB8pv22ANQgAAgWs5BA (envelope-from ) for ; Tue, 29 Jun 2021 21:08:58 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id yE97A8pv22AbCgAA1q6Kng (envelope-from ) for ; Tue, 29 Jun 2021 19:08:58 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (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 7885A273BC for ; Tue, 29 Jun 2021 21:08:57 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id CA0E22911D; Tue, 29 Jun 2021 15:08:47 -0400 (EDT) Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by mail.notmuchmail.org (Postfix) with ESMTPS id 94AD029117 for ; Tue, 29 Jun 2021 15:08:43 -0400 (EDT) Received: by mail-oi1-x22e.google.com with SMTP id 22so21412701oix.10 for ; Tue, 29 Jun 2021 12:08:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=b6Pu1fIAnBYog+98oX9ReT6vPJ8+QKzIDSeYKo20yEk=; b=MMyvn48K3WlDUsll5SA3h8rybJkby82ThfeM1gyi7BMyqlMoLppUX5+WKGnOXaUiVB jVOrKsRAg76w0iiaj+UFkwwkgNuewfZvcDi0XJPZyI5F2ED17kuHrjZc8o5yFmV2vHRb qaA9ceB8f0jSxY0o5iqUDvB+HM6UvCj/RdRArPwX//6UVc6XB94Rauuv8dgQ2LXihGyM N0mrqRULnsG6j7McrXv+T7iTwaIDtMXRo2jAiJ7f0Vkr0eAhi3UdWYMICG3ET3z+S8dJ AJk77ycy7F2hyA0VLy1s9OaYZl+zNHyJh6q/jrYN5+pbV/N0MsMvFfwzpYxxviqv/0ej s1nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=b6Pu1fIAnBYog+98oX9ReT6vPJ8+QKzIDSeYKo20yEk=; b=Kp7ZVHyt4KD0t35T91FEP2d3oKKmArLAE1m4f4MqPgVLX33/FBf11u5kwvkXSC4hJ1 RR06mBuHMo+7B/4x/dvFHPtDa7edyWfn3mAYk8jYnTVLZKdW+JaiozEIh50uRHwZ/I1w DrGtwfW9C7o9vpqIOKIAPTdRZg5YkED2WopUOYIPUMEYgLPKxmp/V79I4y13UnGaITlU aC1tzSqF34bO7L/mlCjeXQbWPSG/XXQZIKrUvaqMeMd6ZTmxUkPjX8syPU4IX0fuSjbv jp0Q5Wn9/meY3CMiU1pZJTas+m8h8w9CtCHPe559T/GkYpBkN+1Xj01lIOjh4Io3iEiF LufQ== X-Gm-Message-State: AOAM530ex0k7mKStYNLUgwz9LrZPgVka2Z/lJeYbFvM8YOxVmEsVYBxK FPAhAo0MduAE9SLV3FbGaPPPLDOHT7gPkQ== X-Google-Smtp-Source: ABdhPJxYWBVeL0RJx9joVjiUiHYMhaEluD4smi5bTJ8eQGZ2okN4kkxK8rvZKqvHaKyDx+VjybSmlA== X-Received: by 2002:aca:d9c4:: with SMTP id q187mr263933oig.95.1624993722692; Tue, 29 Jun 2021 12:08:42 -0700 (PDT) Received: from localhost (fixed-187-189-165-231.totalplay.net. [187.189.165.231]) by smtp.gmail.com with ESMTPSA id o24sm4318917otp.13.2021.06.29.12.08.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jun 2021 12:08:42 -0700 (PDT) From: Felipe Contreras To: notmuch@notmuchmail.org Cc: David Bremner , Felipe Contreras Subject: [PATCH v2 2/3] ruby: add db.config Date: Tue, 29 Jun 2021 14:08:34 -0500 Message-Id: <20210629190835.19381-3-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210629190835.19381-1-felipe.contreras@gmail.com> References: <20210629190835.19381-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Message-ID-Hash: ONSUGCHJ6S7DGXYG677OGNRSKMRXEL2V X-Message-ID-Hash: ONSUGCHJ6S7DGXYG677OGNRSKMRXEL2V X-MailFrom: felipe.contreras@gmail.com 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=1624993737; 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:dkim-signature; bh=5EtPHFKlsZVwaeP8tve+XbQXYz/saZePc5axGPIYGjA=; b=Rk9k5Durc0A3yxMecW0ih559XmtCn053Ze2ixbtgJlgNjb1tBvf1a+eyLcN0MoY7K7RbwP tLLy3J0/jHnsLJX/uCOBoLIj1fgkn2/DA1zDTsdyt3v+7kK4Qdt4dRZWbfAPgBAQHbPywc 9jV5e+8VJxz5qePsFib8GAiXFlF/hyIpZUlOxqhOb2mA+hlSMcXfUqISK8WCdIdkeVb6z8 6FjtmEq8WRyiqSOC9uEY99HOmoe2l7nFppN9See6z0B/fZRRiLiuqy72vH6jTy8rIWX/km Gazmegog/tl0a9VRR5PuHmxtg0tVlFW9+zyeTzIpqq/2E45ww8WSyIsjh09tCg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1624993737; a=rsa-sha256; cv=none; b=F5MXDUdBBNvpJZ++G/CxyVDpUClFMlLV2AOutDzo7Y9pF3ACBv2Oh0g+JlTICyDLK0IIIV pZ7HU9meM/ObWtQoBW27CkALd2wEjtboIBIlE+leUtk7Lh0vTrPVPb+wOcmz/xHP9foGsX tw9wmVFYHsdrANKmPpC9enZHzQ6IwRvETEUVcCiTGq6wWDiHaJ0PYKwmZbIITYKsZDuZRU sZtY5WqZZiwpMGK7VGAl+BbpX4+oSDkqfhMItJaqcJxVu9F/7CNOo8VeWr/iXV0FlO5uBr ylVgW4zBo0sA8s6Suis7e2Iy9jnvzQcB3U7/beLsFBBRTs5/A6BAMnr7cq4KnA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b=MMyvn48K; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -0.92 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b=MMyvn48K; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 7885A273BC X-Spam-Score: -0.92 X-Migadu-Scanner: scn0.migadu.com X-TUID: gsT2LoveBn04 In order to use notmuch_config_get_pairs. Signed-off-by: Felipe Contreras --- bindings/ruby/database.c | 31 +++++++++++++++++++++++++++++++ bindings/ruby/defs.h | 4 ++++ bindings/ruby/init.c | 1 + test/T395-ruby.sh | 8 ++++++++ 4 files changed, 44 insertions(+) diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c index 89d9619e..571f7e24 100644 --- a/bindings/ruby/database.c +++ b/bindings/ruby/database.c @@ -520,3 +520,34 @@ notmuch_rb_database_query_create (int argc, VALUE *argv, VALUE self) return Data_Wrap_Notmuch_Object (notmuch_rb_cQuery, ¬much_rb_query_type, query); } + +/* + * call-seq: DB.config(prefix) {|key, value| block} => nil + * + * Calls +block+ once for each key/value pair. + * + */ +VALUE +notmuch_rb_database_config (int argc, VALUE *argv, VALUE self) +{ + VALUE prefix; + notmuch_database_t *db; + notmuch_config_pairs_t *list; + const char *cprefix; + + Data_Get_Notmuch_Database (self, db); + + rb_scan_args (argc, argv, "01", &prefix); + + cprefix = prefix != Qnil ? RSTRING_PTR (prefix) : ""; + + list = notmuch_config_get_pairs (db, cprefix); + for (; notmuch_config_pairs_valid (list); notmuch_config_pairs_move_to_next (list)) { + const char *key = notmuch_config_pairs_key (list); + const char *value = notmuch_config_pairs_value (list); + rb_yield (rb_ary_new3(2, nm_str_new (key), nm_str_new (value))); + } + notmuch_config_pairs_destroy (list); + + return Qnil; +} diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h index cba9fd69..f3371b5d 100644 --- a/bindings/ruby/defs.h +++ b/bindings/ruby/defs.h @@ -57,6 +57,7 @@ extern ID ID_db_mode; /* Simple string helpers */ #define nm_str(str) (str != Qnil ? RSTRING_PTR (str) : NULL) +#define nm_str_new(str) (str ? rb_str_new_cstr (str) : Qnil) extern const rb_data_type_t notmuch_rb_object_type; extern const rb_data_type_t notmuch_rb_database_type; @@ -182,6 +183,9 @@ notmuch_rb_database_get_all_tags (VALUE self); VALUE notmuch_rb_database_query_create (int argc, VALUE *argv, VALUE self); +VALUE +notmuch_rb_database_config (int argc, VALUE *argv, VALUE self); + /* directory.c */ VALUE notmuch_rb_directory_destroy (VALUE self); diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c index 7b4de86a..fad357dc 100644 --- a/bindings/ruby/init.c +++ b/bindings/ruby/init.c @@ -277,6 +277,7 @@ Init_notmuch (void) notmuch_rb_database_find_message_by_filename, 1); /* in database.c */ rb_define_method (notmuch_rb_cDatabase, "all_tags", notmuch_rb_database_get_all_tags, 0); /* in database.c */ rb_define_method (notmuch_rb_cDatabase, "query", notmuch_rb_database_query_create, -1); /* in database.c */ + rb_define_method (notmuch_rb_cDatabase, "config", notmuch_rb_database_config, -1); /* in database.c */ /* * Document-class: Notmuch::Directory diff --git a/test/T395-ruby.sh b/test/T395-ruby.sh index 9a1df913..91c310c6 100755 --- a/test/T395-ruby.sh +++ b/test/T395-ruby.sh @@ -106,4 +106,12 @@ test_ruby < EXPECTED +test_ruby <<"EOF" +Notmuch::Database.open_with_config do |db| + db.config { |e| puts '%s=%s' % e } +end +EOF + test_done -- 2.32.0