From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id ONcrKRKeuWD43QAAgWs5BA (envelope-from ) for ; Fri, 04 Jun 2021 05:29:22 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id MLNrJBKeuWBBMQAA1q6Kng (envelope-from ) for ; Fri, 04 Jun 2021 03:29:22 +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 3ECF4146FC for ; Fri, 4 Jun 2021 05:29:22 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id BB3272AA15; Thu, 3 Jun 2021 23:29:13 -0400 (EDT) Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by mail.notmuchmail.org (Postfix) with ESMTPS id 0878C20017 for ; Thu, 3 Jun 2021 23:29:06 -0400 (EDT) Received: by mail-ot1-x32e.google.com with SMTP id v19-20020a0568301413b0290304f00e3d88so7831097otp.4 for ; Thu, 03 Jun 2021 20:29:06 -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=lFKpdukhazpgDHCxhc6aqqP4BXDnFz287nkuJK0zgjY=; b=ClRbCcmj2PzUY/Agc38JmqNbQ7lYoLDaRPClzAjHMfIFgieelIKONTOtxa4MxXNDgb TwtEf8eVOTWD74MYDRV6H7mBx6PppMCBGK9EIS1CXeg6FXShnE2i2jHAZsqjy+FCdVK4 tU1qrSFGWYmkQy4O91YxPJsK8WVGL3Ja73XJEth/EHnQQsH2SSEVldSHCEuqpkO5T8uV 2yH8mbREk+24wATGwtkAg3miUy57qVaeuoc0pYBZb5SMaYSCVQuLh0DzGr1KhX9+72ql LkPqhgFHojpMwPh/uzmvPXtvDaqZUJDhJgyt1go2Krtug/txCJxPerJbMiPAWQ/uACp6 cgOA== 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=lFKpdukhazpgDHCxhc6aqqP4BXDnFz287nkuJK0zgjY=; b=f905gM+rySJJn/Drzcjql511FnP78LSa6bOWU8gRXWpdNcZt3n17oKhQr4S8HXOjeA Ve+6/z75UrsmvG0ZLnqvjXKUJg1lHxnPUEOJQFGssGMCwnnkpAKXZmI2TgaDnIy84gq4 uAH6kXwLt5NB9FcyLsv/z8+mS81ZIQaS9OYJXp4GGQ/+U1+x0WQCyCjfSk8xqWVWN19y 4R81zdNz2ATVQvFpgIFRP6X2kUFy3hJpuuOtZV+yf1eF97yc0qBiCtnBSNDEHNy6ZzJ3 muWegMdJFOJ+lVLNrWN//iYhfC+0NsKAfRpWj0uZBX8h3LegE0TYjRC7XL4DQZBipmYX 6ppQ== X-Gm-Message-State: AOAM5320cpb8xu+HsIad6IVNgWlaWJielN5vcb9vqFJpaVg99c/sBcNm DJpNRdi6AKQmw8PwFd4typWgE6j6bh7nmg== X-Google-Smtp-Source: ABdhPJx4eRHC4zbWjs2B2C3UYONF3LftRdZTQoYeoSp1dKQbfQfpWCmXvnElk+NcdR4pE6GNUMW24w== X-Received: by 2002:a05:6830:1505:: with SMTP id k5mr2129418otp.45.1622777344891; Thu, 03 Jun 2021 20:29:04 -0700 (PDT) Received: from localhost (fixed-187-190-78-172.totalplay.net. [187.190.78.172]) by smtp.gmail.com with ESMTPSA id p204sm209661oia.43.2021.06.03.20.29.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 20:29:04 -0700 (PDT) From: Felipe Contreras To: notmuch@notmuchmail.org Cc: David Bremner , Felipe Contreras Subject: [PATCH 1/3] ruby: add new Database.open_with_config Date: Thu, 3 Jun 2021 22:28:59 -0500 Message-Id: <20210604032901.3815539-2-felipe.contreras@gmail.com> X-Mailer: git-send-email 2.32.0.rc2 In-Reply-To: <20210604032901.3815539-1-felipe.contreras@gmail.com> References: <20210604032901.3815539-1-felipe.contreras@gmail.com> MIME-Version: 1.0 Message-ID-Hash: 7IT4KZFRGFSA6FGQ7TRL56RBZNF5UG5D X-Message-ID-Hash: 7IT4KZFRGFSA6FGQ7TRL56RBZNF5UG5D 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=1622777362; 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=RXPPo4a+5mZwwsgCpVGq9PTbCc6Uv9UO9RrBWyqyTJM=; b=PJiiFr6TY/Uy55MobBITqWo/uMpk3Tm5ynVhvzxasqeb2MASwTEcTQig51LH6pH+62lZq2 nYS9mLae9nZPA+qWvB+xJzt16qh+zlte3V34kgc6gI2xSa0t7TtYQfEy5jh3iQNVINt3KJ ShPyWPBnFBnIwdPgjZ43C2h2cceh4bRxacj1mMhtvxieXxa27+iES/LJioIltAjO5ZKGuu 034O3GQ3GfhkeywXKxyOiz26WG9cVUhUG37Xx/OWVD/Sxz/5sWiCp8i3UnqCBSGY75ahKP ulkh5KAhW7dGhV71uiiVQDx5uB7nh1+sfSFxBoXbGau5BHw9kLEwg+/fnp9rXA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1622777362; a=rsa-sha256; cv=none; b=iHKfkERzkXYsCm1qQwhG4u99wxMfkNprN/NDz92ZTj7k3LztZZtXiC1KPWojoUoTLa93Ao ABklV9IXu+//351s7S/szG1f6vKq56LysP/nk1QpjbtYH6OOHwwSKx2h6eLnEcCYqng6J5 iXr6aIC9EUcvXPyhvWPikaHlEk+sGs3TT3l9r6QU8RgM9q3x0IZFUpzHhyPjnWjMHKYkEa DkA4DObaYUQxrdBi8h7rJqRwOU/+di4ASnMN8o76IPHEqw3btKWxywszaVR7hE+fCDyrv5 Ic8Ax9ME5CmwGeBSqkOghuxoDMRLIoTVwJ3JBlRwfj7R5xyRHMLdR2JJluhs2g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b=ClRbCcmj; 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.94 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b=ClRbCcmj; 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: 3ECF4146FC X-Spam-Score: -0.94 X-Migadu-Scanner: scn0.migadu.com X-TUID: IBXdyqHl1Pos 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 bb993d86..bc0c22cb 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 9860ee17..78239229 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 bedfbf60..27c7eba3 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 d36d4aff..27ac4cc8 100755 --- a/test/T395-ruby.sh +++ b/test/T395-ruby.sh @@ -82,4 +82,10 @@ q.search_threads.each do |t| end EOF +test_begin_subtest "open with config" +echo "$MAIL_DIR" > EXPECTED +test_ruby <