summaryrefslogtreecommitdiff
path: root/ext/openssl/ossl_config.c
diff options
context:
space:
mode:
authorgotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-02-23 18:45:41 +0000
committergotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-02-23 18:45:41 +0000
commit2d0e62faf11eeee5c7564113ae76ddae49626087 (patch)
tree43bdc1302978d1710a08cdd4515d6f65b2fb7793 /ext/openssl/ossl_config.c
parent31e13087b6b88e77c1acb561a17020bdef4e470a (diff)
* ext/openssl/ossl_config.c (ossl_config_each): add new method
OpenSSL::Config#each. it iterates with section name, field name and value. * ext/openssl/ossl_config.c (Init_ossl_config): include Enumerable. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5813 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/openssl/ossl_config.c')
-rw-r--r--ext/openssl/ossl_config.c61
1 files changed, 51 insertions, 10 deletions
diff --git a/ext/openssl/ossl_config.c b/ext/openssl/ossl_config.c
index 7e6f696..655517c 100644
--- a/ext/openssl/ossl_config.c
+++ b/ext/openssl/ossl_config.c
@@ -307,16 +307,7 @@ ossl_config_get_sections(VALUE self)
return ary;
}
-#else
-static VALUE
-ossl_config_get_sections(VALUE self)
-{
- rb_warn("Config::sections don't work with %s", OPENSSL_VERSION_TEXT);
- return rb_ary_new();
-}
-#endif
-#ifdef IMPLEMENT_LHASH_DOALL_ARG_FN
static void
dump_conf_value(CONF_VALUE *cv, VALUE str)
{
@@ -362,13 +353,61 @@ ossl_config_to_s(VALUE self)
return dump_conf(conf);
}
+
+static void
+each_conf_value(CONF_VALUE *cv, void* dummy)
+{
+ STACK_OF(CONF_VALUE) *sk;
+ CONF_VALUE *v;
+ VALUE section, name, value, args;
+ int i, num;
+
+ if (cv->name) return;
+ sk = (STACK_OF(CONF_VALUE)*)cv->value;
+ num = sk_CONF_VALUE_num(sk);
+ section = rb_str_new2(cv->section);
+ for(i = 0; i < num; i++){
+ v = sk_CONF_VALUE_value(sk, i);
+ name = v->name ? rb_str_new2(v->name) : Qnil;
+ value = v->value ? rb_str_new2(v->value) : Qnil;
+ args = rb_ary_new3(3, section, name, value);
+ rb_yield(args);
+ }
+}
+
+static IMPLEMENT_LHASH_DOALL_ARG_FN(each_conf_value, CONF_VALUE*, void*);
+
+static VALUE
+ossl_config_each(VALUE self)
+{
+ CONF *conf;
+
+ GetConfig(self, conf);
+ lh_doall_arg(conf->data, LHASH_DOALL_ARG_FN(each_conf_value), (void*)NULL);
+
+ return self;
+}
#else
static VALUE
+ossl_config_get_sections(VALUE self)
+{
+ rb_warn("#sections don't work with %s", OPENSSL_VERSION_TEXT);
+ return rb_ary_new();
+}
+
+static VALUE
ossl_config_to_s(VALUE self)
{
- rb_warn("Config::to_s don't work with %s", OPENSSL_VERSION_TEXT);
+ rb_warn("#to_s don't work with %s", OPENSSL_VERSION_TEXT);
return rb_str_new(0, 0);
}
+
+static VALUE
+ossl_config_each(VALUE self)
+{
+ rb_warn("#each don't work with %s", OPENSSL_VERSION_TEXT);
+ return self;
+}
#endif
static VALUE
@@ -397,6 +436,7 @@ Init_ossl_config()
rb_define_const(cConfig, "DEFAULT_CONFIG_FILE",
rb_str_new2(CONF_get1_default_config_file()));
+ rb_include_module(cConfig, rb_mEnumerable);
rb_define_singleton_method(cConfig, "parse", ossl_config_s_parse, 1);
rb_define_alias(CLASS_OF(cConfig), "load", "new");
rb_define_alloc_func(cConfig, ossl_config_s_alloc);
@@ -410,5 +450,6 @@ Init_ossl_config()
rb_define_method(cConfig, "[]=", ossl_config_set_section, 2);
rb_define_method(cConfig, "sections", ossl_config_get_sections, 0);
rb_define_method(cConfig, "to_s", ossl_config_to_s, 0);
+ rb_define_method(cConfig, "each", ossl_config_each, 0);
rb_define_method(cConfig, "inspect", ossl_config_inspect, 0);
}