From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id kCMKFcVv22AOQgAAgWs5BA (envelope-from ) for ; Tue, 29 Jun 2021 21:08:53 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id mJ6zEMVv22CyYgAAbx9fmQ (envelope-from ) for ; Tue, 29 Jun 2021 19:08:53 +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 91120273B3 for ; Tue, 29 Jun 2021 21:08:52 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 9CA8C29119; Tue, 29 Jun 2021 15:08:44 -0400 (EDT) Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by mail.notmuchmail.org (Postfix) with ESMTPS id DCC79290A2 for ; Tue, 29 Jun 2021 15:08:40 -0400 (EDT) Received: by mail-ot1-x329.google.com with SMTP id a5-20020a05683012c5b029046700014863so6969029otq.5 for ; Tue, 29 Jun 2021 12:08:40 -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=d512dXZsXS61B4dp5uy9IxVtMPcmYY/FJ6JuQelsAh8=; b=KxKI+/URAYnafI8+tAq9nDP0bZWP0JpinX61O50weioCGot8HCarqPnVDYASbwcCq5 9FdNzh/p7W3Yua88guftYw2ETn+amGtav9IpGmaeio7oV5YAYuSCrBLM0sNlNEoBxAHj R77wGkfgNQrzZr7taM+3hO4XdSUEgCENzha76eErxvdW6a8zxO59XTJ9SeFNezK4AH8n nyPDRBk8mME/cPpWbpK89GPtz+GGMQPOhlWT93+I0QQfUngeqeURx/mke77QDXau5PHM fcv4e1YysF1fOOQkvGuK7+lqbYy7DVnUGTYsbJ75LMiGUfslwvP6EqvGOgSuoH+QbTIC kf8Q== 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=d512dXZsXS61B4dp5uy9IxVtMPcmYY/FJ6JuQelsAh8=; b=N+a5cLV5BeiasSRO31X+3Z0uEwj4zE0KO4mponU0cAuv6Tv60ktwTmhOoWi5un7SJR GoGgbbk7tlzRXStoDqGmwNFP5ERg/v1YMvkGjx65M0xgJj1HckxBI1lk+I/RAMNS+9AM XlXEZLQVKOgysik7hhXg20ltBQ/8ak3n2WDG6IPx/Nov4eWaUq+Js3P4GOKnxq1AGK3k eM4uyNDtn7IP7DmBTvd3tQvLDFVPn7CJ0pz15CmzuA7xGsRrzJWPrsO0S0SsdmLSZYco aEWT1UaPDBwYjM8Q6dt4wNiOMmPL/HiNkK8miII4efqrsAsgNvv3EaSBLY5DMR+fx8RR KMZA== X-Gm-Message-State: AOAM530C6OCS+ESdy99t/m6+zx2woSzfwO/w3ziQC6jY9fiOVL2mv882 pR7JsBe/xfsUulMuzlRGLWoiodAXe5fyEQ== X-Google-Smtp-Source: ABdhPJxnWfvx4zLiaisBGrOx5TYG1XHNCrndHyH5RI0idj+exAY+4Oa2tZwz34ZvY7jagCDR404CeQ== X-Received: by 2002:a9d:6081:: with SMTP id m1mr5813952otj.226.1624993719811; Tue, 29 Jun 2021 12:08:39 -0700 (PDT) Received: from localhost (fixed-187-189-165-231.totalplay.net. [187.189.165.231]) by smtp.gmail.com with ESMTPSA id b25sm294282otk.6.2021.06.29.12.08.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jun 2021 12:08:39 -0700 (PDT) From: Felipe Contreras To: notmuch@notmuchmail.org Cc: David Bremner , Felipe Contreras Subject: [PATCH v2 1/3] ruby: add new Database.open_with_config Date: Tue, 29 Jun 2021 14:08:33 -0500 Message-Id: <20210629190835.19381-2-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: MRTBTB2II426UX2KKJDDYLDZTB3AQ65L X-Message-ID-Hash: MRTBTB2II426UX2KKJDDYLDZTB3AQ65L 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=1624993733; 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=WxlrhRgmiG1SDVRf5XktaBEYI7ttkuuF5CNPY6ykA9Y=; b=d4RntBgiyBrxRaUMIN7KXaVoCt0iY+hb63ny4i/LzeoMMII0N7Dvwy8HE+I3jsYLgQp3JJ ATrI6auvh4SCr0etdcnS8WrtrfjteLWPXH+yOBRqPlfUdzpADs7mVESCAiQrA6qN1KCEfZ JhygqajoEWCA4yu0fwFm7k0io7Vsctl+A/czV3WRFCAXpjKaNA14pLYUwC6k7ggGiKoIvI WIk7/m6Glf/1c3FD29WWgtNsGIh3Y5oAPWSFCXQL27QBYZpUOFIHgWcYtP85PCif5gIjcx MLvAyM2qvNaUcg5ej9QTK5sJak1oWILZsfDwMhtBB1eacCM4AoSZBrPN1fipJA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1624993733; a=rsa-sha256; cv=none; b=Fz5qUBBQn0nI8mTxhWFVHZ2bJ71WFbUOUHY3Xfri1eUeCR+reD18osozvX7B8O6MZefMWX Kr/IDa1/CgohTwiWqwigT7EHY7r1RoqH+Jz2TmdAMQVtUsR5FkoUKIzkRk1NF97o/eAM8T kHtsnWEyBw5lQ3vo5mt3dJ/X9C69UywYTghN7AEz0PG/G6BkONzpe5nBB6f0Vvb5NKjySa skXjvh2e3vuFUAcVyXjKubTzSQeON4C91kf0F4k42WioG1sjoMIip9tdxuRHwWzU66u+3s r96q2pW63cxtaivvhfm0FoyXEfcBBXCqNznqKF5alxsE2U4D31e1d8ZxtJX58A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b="KxKI+/UR"; 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 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -0.97 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b="KxKI+/UR"; 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 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 91120273B3 X-Spam-Score: -0.97 X-Migadu-Scanner: scn0.migadu.com X-TUID: w9+Bebz2cRYv In order to make use of notmuch_database_open_with_config. Signed-off-by: Felipe Contreras --- bindings/ruby/database.c | 62 ++++++++++++++++++++++++++++++++++++++++ bindings/ruby/defs.h | 6 ++++ bindings/ruby/init.c | 1 + test/T395-ruby.sh | 6 ++++ 4 files changed, 75 insertions(+) diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c index d6c804ac..89d9619e 100644 --- a/bindings/ruby/database.c +++ b/bindings/ruby/database.c @@ -105,6 +105,68 @@ notmuch_rb_database_open (int argc, VALUE *argv, VALUE klass) return rb_ensure (rb_yield, obj, notmuch_rb_database_close, obj); } +/* + * call-seq: Notmuch::Database.open_with_config([database_path:, mode:, config_path:, profile:]) [{|db| ... }] + * + * Opens a database with a configuration file. + * + */ +VALUE +notmuch_rb_database_open_with_config (int argc, VALUE *argv, VALUE klass) +{ + VALUE obj; + notmuch_database_t *db; + notmuch_status_t ret; + VALUE opts; + const char *database_path = NULL; + notmuch_database_mode_t mode = NOTMUCH_DATABASE_MODE_READ_ONLY; + const char *config_path = NULL; + const char *profile = NULL; + + rb_scan_args (argc, argv, ":", &opts); + + if (!NIL_P (opts)) { + VALUE rdatabase_path, rmode, rconfig_path, rprofile; + VALUE kwargs[4]; + static ID keyword_ids[4]; + + if (!keyword_ids[0]) { + keyword_ids[0] = rb_intern_const ("database_path"); + keyword_ids[1] = rb_intern_const ("mode"); + keyword_ids[2] = rb_intern_const ("config_path"); + keyword_ids[3] = rb_intern_const ("profile"); + } + + rb_get_kwargs (opts, keyword_ids, 0, 4, kwargs); + + rdatabase_path = kwargs[0]; + rmode = kwargs[1]; + rconfig_path = kwargs[2]; + rprofile = kwargs[3]; + + if (rdatabase_path != Qundef) + database_path = nm_str (rdatabase_path); + if (rmode != Qundef) + mode = FIX2INT (rmode); + if (rconfig_path != Qundef) + config_path = nm_str (rconfig_path); + if (rprofile != Qundef) + profile = nm_str (rprofile); + } + + ret = notmuch_database_open_with_config (database_path, mode, + config_path, profile, &db, + NULL); + notmuch_rb_status_raise (ret); + obj = notmuch_rb_database_alloc (klass); + DATA_PTR (obj) = db; + + if (!rb_block_given_p ()) + return obj; + + return rb_ensure (rb_yield, obj, notmuch_rb_database_close, obj); +} + /* * call-seq: DB.close => nil * diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h index 995bcafd..cba9fd69 100644 --- a/bindings/ruby/defs.h +++ b/bindings/ruby/defs.h @@ -55,6 +55,9 @@ extern ID ID_db_mode; # define RSTRING_PTR(v) (RSTRING((v))->ptr) #endif /* !defined (RSTRING_PTR) */ +/* Simple string helpers */ +#define nm_str(str) (str != Qnil ? RSTRING_PTR (str) : NULL) + extern const rb_data_type_t notmuch_rb_object_type; extern const rb_data_type_t notmuch_rb_database_type; extern const rb_data_type_t notmuch_rb_directory_type; @@ -134,6 +137,9 @@ notmuch_rb_database_initialize (int argc, VALUE *argv, VALUE klass); VALUE notmuch_rb_database_open (int argc, VALUE *argv, VALUE klass); +VALUE +notmuch_rb_database_open_with_config (int argc, VALUE *argv, VALUE klass); + VALUE notmuch_rb_database_close (VALUE self); diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c index d421c601..7b4de86a 100644 --- a/bindings/ruby/init.c +++ b/bindings/ruby/init.c @@ -259,6 +259,7 @@ Init_notmuch (void) notmuch_rb_cDatabase = rb_define_class_under (mod, "Database", rb_cObject); rb_define_alloc_func (notmuch_rb_cDatabase, notmuch_rb_database_alloc); rb_define_singleton_method (notmuch_rb_cDatabase, "open", notmuch_rb_database_open, -1); /* in database.c */ + rb_define_singleton_method (notmuch_rb_cDatabase, "open_with_config", notmuch_rb_database_open_with_config, -1); /* in database.c */ rb_define_method (notmuch_rb_cDatabase, "initialize", notmuch_rb_database_initialize, -1); /* in database.c */ rb_define_method (notmuch_rb_cDatabase, "close", notmuch_rb_database_close, 0); /* in database.c */ rb_define_method (notmuch_rb_cDatabase, "path", notmuch_rb_database_path, 0); /* in database.c */ diff --git a/test/T395-ruby.sh b/test/T395-ruby.sh index e828efed..9a1df913 100755 --- a/test/T395-ruby.sh +++ b/test/T395-ruby.sh @@ -100,4 +100,10 @@ q.search_threads.each do |t| end EOF +test_begin_subtest "open with config" +echo "$MAIL_DIR" > EXPECTED +test_ruby <