2003-07-23 12:12:24 -04:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
* 'OpenSSL for Ruby' project
|
|
|
|
* Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* This program is licenced under the same licence as Ruby.
|
|
|
|
* (See the file 'LICENCE'.)
|
|
|
|
*/
|
|
|
|
#include "ossl.h"
|
|
|
|
|
|
|
|
#define WrapConfig(klass, obj, conf) do { \
|
|
|
|
if (!conf) { \
|
|
|
|
ossl_raise(rb_eRuntimeError, "Config wasn't intitialized!"); \
|
|
|
|
} \
|
|
|
|
obj = Data_Wrap_Struct(klass, 0, NCONF_free, conf); \
|
|
|
|
} while (0)
|
|
|
|
#define GetConfig(obj, conf) do { \
|
|
|
|
Data_Get_Struct(obj, CONF, conf); \
|
|
|
|
if (!conf) { \
|
|
|
|
ossl_raise(rb_eRuntimeError, "Config wasn't intitialized!"); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2003-09-08 06:31:38 -04:00
|
|
|
#define SafeGetConfig(obj, conf) do { \
|
|
|
|
OSSL_Check_Kind(obj, cConfig); \
|
|
|
|
GetConfig(obj, conf); \
|
|
|
|
} while(0);
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Classes
|
|
|
|
*/
|
|
|
|
VALUE cConfig;
|
|
|
|
VALUE eConfigError;
|
|
|
|
|
2010-04-22 04:04:13 -04:00
|
|
|
/*
|
|
|
|
* Public
|
2003-07-23 12:12:24 -04:00
|
|
|
*/
|
|
|
|
|
2003-09-08 06:31:38 -04:00
|
|
|
static CONF *parse_config(VALUE, CONF*);
|
|
|
|
|
|
|
|
CONF *
|
|
|
|
GetConfigPtr(VALUE obj)
|
|
|
|
{
|
|
|
|
CONF *conf;
|
|
|
|
|
|
|
|
SafeGetConfig(obj, conf);
|
|
|
|
|
|
|
|
return conf;
|
|
|
|
}
|
|
|
|
|
|
|
|
CONF *
|
|
|
|
DupConfigPtr(VALUE obj)
|
|
|
|
{
|
|
|
|
VALUE str;
|
|
|
|
|
|
|
|
OSSL_Check_Kind(obj, cConfig);
|
|
|
|
str = rb_funcall(obj, rb_intern("to_s"), 0);
|
|
|
|
|
|
|
|
return parse_config(str, NULL);
|
|
|
|
}
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
/*
|
|
|
|
* Private
|
|
|
|
*/
|
2003-09-08 06:31:38 -04:00
|
|
|
static CONF *
|
|
|
|
parse_config(VALUE str, CONF *dst)
|
|
|
|
{
|
|
|
|
CONF *conf;
|
|
|
|
BIO *bio;
|
|
|
|
long eline = -1;
|
|
|
|
|
|
|
|
bio = ossl_obj2bio(str);
|
|
|
|
conf = dst ? dst : NCONF_new(NULL);
|
|
|
|
if(!conf){
|
|
|
|
BIO_free(bio);
|
|
|
|
ossl_raise(eConfigError, NULL);
|
|
|
|
}
|
|
|
|
if(!NCONF_load_bio(conf, bio, &eline)){
|
|
|
|
BIO_free(bio);
|
|
|
|
if(!dst) NCONF_free(conf);
|
|
|
|
if (eline <= 0) ossl_raise(eConfigError, "wrong config format");
|
|
|
|
else ossl_raise(eConfigError, "error in line %d", eline);
|
|
|
|
ossl_raise(eConfigError, NULL);
|
|
|
|
}
|
|
|
|
BIO_free(bio);
|
|
|
|
|
|
|
|
return conf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_config_s_parse(VALUE klass, VALUE str)
|
|
|
|
{
|
|
|
|
CONF *conf;
|
|
|
|
VALUE obj;
|
|
|
|
|
|
|
|
conf = parse_config(str, NULL);
|
|
|
|
WrapConfig(klass, obj, conf);
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_config_s_alloc(VALUE klass)
|
|
|
|
{
|
|
|
|
CONF *conf;
|
|
|
|
VALUE obj;
|
|
|
|
|
|
|
|
if(!(conf = NCONF_new(NULL)))
|
2003-09-08 07:02:35 -04:00
|
|
|
ossl_raise(eConfigError, NULL);
|
2003-09-08 06:31:38 -04:00
|
|
|
WrapConfig(klass, obj, conf);
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_config_copy(VALUE self, VALUE other)
|
|
|
|
{
|
|
|
|
VALUE str;
|
|
|
|
CONF *conf;
|
|
|
|
|
|
|
|
str = rb_funcall(self, rb_intern("to_s"), 0);
|
2004-12-15 01:35:55 -05:00
|
|
|
GetConfig(other, conf);
|
2003-09-08 06:31:38 -04:00
|
|
|
parse_config(str, conf);
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
2003-09-08 06:31:38 -04:00
|
|
|
ossl_config_initialize(int argc, VALUE *argv, VALUE self)
|
2003-07-23 12:12:24 -04:00
|
|
|
{
|
|
|
|
CONF *conf;
|
2003-09-08 06:31:38 -04:00
|
|
|
long eline = -1;
|
2003-07-23 12:12:24 -04:00
|
|
|
char *filename;
|
2003-09-08 06:31:38 -04:00
|
|
|
VALUE path;
|
2003-07-23 12:12:24 -04:00
|
|
|
|
2003-09-08 06:31:38 -04:00
|
|
|
rb_scan_args(argc, argv, "01", &path);
|
|
|
|
if(!NIL_P(path)){
|
2003-07-23 12:12:24 -04:00
|
|
|
SafeStringValue(path);
|
2003-09-08 06:31:38 -04:00
|
|
|
filename = StringValuePtr(path);
|
2004-12-15 01:35:55 -05:00
|
|
|
GetConfig(self, conf);
|
2003-09-08 06:31:38 -04:00
|
|
|
if (!NCONF_load(conf, filename, &eline)){
|
|
|
|
if (eline <= 0)
|
|
|
|
ossl_raise(eConfigError, "wrong config file %s", filename);
|
|
|
|
else
|
|
|
|
ossl_raise(eConfigError, "error in %s:%d", filename, eline);
|
|
|
|
}
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
2003-09-10 09:43:27 -04:00
|
|
|
#ifdef OSSL_NO_CONF_API
|
2004-03-29 02:54:38 -05:00
|
|
|
else rb_raise(rb_eArgError, "wrong number of arguments (0 for 1)");
|
2003-09-10 09:43:27 -04:00
|
|
|
#else
|
2004-12-15 01:35:55 -05:00
|
|
|
else {
|
|
|
|
GetConfig(self, conf);
|
|
|
|
_CONF_new_data(conf);
|
|
|
|
}
|
2003-09-10 09:43:27 -04:00
|
|
|
#endif
|
2010-04-22 04:04:13 -04:00
|
|
|
|
2003-09-08 06:31:38 -04:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_config_add_value(VALUE self, VALUE section, VALUE name, VALUE value)
|
|
|
|
{
|
2003-09-10 09:43:27 -04:00
|
|
|
#ifdef OSSL_NO_CONF_API
|
|
|
|
rb_notimplement();
|
|
|
|
#else
|
2003-09-08 06:31:38 -04:00
|
|
|
CONF *conf;
|
|
|
|
CONF_VALUE *sv, *cv;
|
|
|
|
|
|
|
|
StringValue(section);
|
|
|
|
StringValue(name);
|
|
|
|
StringValue(value);
|
2004-12-15 01:35:55 -05:00
|
|
|
GetConfig(self, conf);
|
2006-08-31 06:30:33 -04:00
|
|
|
if(!(sv = _CONF_get_section(conf, RSTRING_PTR(section)))){
|
|
|
|
if(!(sv = _CONF_new_section(conf, RSTRING_PTR(section)))){
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(eConfigError, NULL);
|
|
|
|
}
|
|
|
|
}
|
2003-09-08 06:31:38 -04:00
|
|
|
if(!(cv = OPENSSL_malloc(sizeof(CONF_VALUE)))){
|
2003-07-23 12:12:24 -04:00
|
|
|
ossl_raise(eConfigError, NULL);
|
|
|
|
}
|
2006-08-31 06:30:33 -04:00
|
|
|
cv->name = BUF_strdup(RSTRING_PTR(name));
|
|
|
|
cv->value = BUF_strdup(RSTRING_PTR(value));
|
2003-09-08 06:31:38 -04:00
|
|
|
if(!cv->name || !cv->value || !_CONF_add_string(conf, sv, cv)){
|
|
|
|
OPENSSL_free(cv->name);
|
|
|
|
OPENSSL_free(cv->value);
|
|
|
|
OPENSSL_free(cv);
|
|
|
|
ossl_raise(eConfigError, "_CONF_add_string failure");
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
2010-04-22 04:04:13 -04:00
|
|
|
|
2003-09-08 06:31:38 -04:00
|
|
|
return value;
|
2003-09-10 09:43:27 -04:00
|
|
|
#endif
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
|
2009-09-21 12:12:46 -04:00
|
|
|
static void
|
|
|
|
rb_ossl_config_modify_check(VALUE config)
|
|
|
|
{
|
|
|
|
if (OBJ_FROZEN(config)) rb_error_frozen("OpenSSL::Config");
|
|
|
|
if (!OBJ_UNTRUSTED(config) && rb_safe_level() >= 4)
|
|
|
|
rb_raise(rb_eSecurityError, "Insecure: can't modify OpenSSL config");
|
|
|
|
}
|
|
|
|
|
2009-04-18 10:10:06 -04:00
|
|
|
#if !defined(OSSL_NO_CONF_API)
|
|
|
|
static VALUE
|
|
|
|
ossl_config_add_value_m(VALUE self, VALUE section, VALUE name, VALUE value)
|
|
|
|
{
|
2009-09-21 12:12:46 -04:00
|
|
|
rb_ossl_config_modify_check(self);
|
2009-04-18 10:10:06 -04:00
|
|
|
return ossl_config_add_value(self, section, name, value);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define ossl_config_add_value_m rb_f_notimplement
|
|
|
|
#endif
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
static VALUE
|
2003-09-08 06:31:38 -04:00
|
|
|
ossl_config_get_value(VALUE self, VALUE section, VALUE name)
|
2003-07-23 12:12:24 -04:00
|
|
|
{
|
|
|
|
CONF *conf;
|
2003-09-08 06:31:38 -04:00
|
|
|
char *str;
|
|
|
|
|
|
|
|
StringValue(section);
|
|
|
|
StringValue(name);
|
2004-12-15 01:35:55 -05:00
|
|
|
GetConfig(self, conf);
|
2006-08-31 06:30:33 -04:00
|
|
|
str = NCONF_get_string(conf, RSTRING_PTR(section), RSTRING_PTR(name));
|
2003-11-10 13:31:36 -05:00
|
|
|
if(!str){
|
|
|
|
ERR_clear_error();
|
|
|
|
return Qnil;
|
|
|
|
}
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
return rb_str_new2(str);
|
|
|
|
}
|
|
|
|
|
2003-09-08 06:31:38 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_config_get_value_old(int argc, VALUE *argv, VALUE self)
|
|
|
|
{
|
|
|
|
VALUE section, name;
|
2010-04-22 04:04:13 -04:00
|
|
|
|
2003-09-08 06:31:38 -04:00
|
|
|
rb_scan_args(argc, argv, "11", §ion, &name);
|
2003-09-12 09:46:48 -04:00
|
|
|
|
|
|
|
/* support conf.value(nil, "HOME") -> conf.get_value("", "HOME") */
|
|
|
|
if (NIL_P(section)) section = rb_str_new2("");
|
|
|
|
/* support conf.value("HOME") -> conf.get_value("", "HOME") */
|
|
|
|
if (NIL_P(name)) {
|
|
|
|
name = section;
|
|
|
|
section = rb_str_new2("");
|
|
|
|
}
|
|
|
|
/* NOTE: Don't care about conf.get_value(nil, nil) */
|
2003-09-08 06:31:38 -04:00
|
|
|
rb_warn("Config#value is deprecated; use Config#get_value");
|
|
|
|
return ossl_config_get_value(self, section, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
set_conf_section_i(VALUE i, VALUE *arg)
|
|
|
|
{
|
|
|
|
VALUE name, value;
|
|
|
|
|
2003-09-10 09:58:31 -04:00
|
|
|
Check_Type(i, T_ARRAY);
|
2003-09-08 06:31:38 -04:00
|
|
|
name = rb_ary_entry(i, 0);
|
|
|
|
value = rb_ary_entry(i, 1);
|
|
|
|
ossl_config_add_value(arg[0], arg[1], name, value);
|
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_config_set_section(VALUE self, VALUE section, VALUE hash)
|
|
|
|
{
|
2007-07-20 02:22:54 -04:00
|
|
|
VALUE arg[2];
|
|
|
|
|
2009-09-21 12:12:46 -04:00
|
|
|
rb_ossl_config_modify_check(self);
|
2007-07-20 02:22:54 -04:00
|
|
|
arg[0] = self;
|
|
|
|
arg[1] = section;
|
2006-02-03 04:15:42 -05:00
|
|
|
rb_block_call(hash, rb_intern("each"), 0, 0, set_conf_section_i, (VALUE)arg);
|
2003-09-08 06:31:38 -04:00
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
/*
|
|
|
|
* Get all numbers as strings - use str.to_i to convert
|
|
|
|
* long number = CONF_get_number(confp->config, sect, StringValuePtr(item));
|
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
ossl_config_get_section(VALUE self, VALUE section)
|
|
|
|
{
|
|
|
|
CONF *conf;
|
|
|
|
STACK_OF(CONF_VALUE) *sk;
|
|
|
|
CONF_VALUE *entry;
|
|
|
|
int i, entries;
|
|
|
|
VALUE hash;
|
|
|
|
|
2003-11-10 13:31:36 -05:00
|
|
|
hash = rb_hash_new();
|
2004-12-15 01:35:55 -05:00
|
|
|
StringValue(section);
|
2003-07-23 12:12:24 -04:00
|
|
|
GetConfig(self, conf);
|
|
|
|
if (!(sk = NCONF_get_section(conf, StringValuePtr(section)))) {
|
2003-11-10 13:31:36 -05:00
|
|
|
ERR_clear_error();
|
|
|
|
return hash;
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|
|
|
|
if ((entries = sk_CONF_VALUE_num(sk)) < 0) {
|
|
|
|
OSSL_Debug("# of items in section is < 0?!?");
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
for (i=0; i<entries; i++) {
|
2010-04-22 04:21:01 -04:00
|
|
|
entry = sk_CONF_VALUE_value(sk, i);
|
2003-07-23 12:12:24 -04:00
|
|
|
rb_hash_aset(hash, rb_str_new2(entry->name), rb_str_new2(entry->value));
|
|
|
|
}
|
2003-09-08 06:31:38 -04:00
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2003-09-08 06:31:38 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_config_get_section_old(VALUE self, VALUE section)
|
|
|
|
{
|
|
|
|
rb_warn("Config#section is deprecated; use Config#[]");
|
|
|
|
return ossl_config_get_section(self, section);
|
|
|
|
}
|
|
|
|
|
2010-04-23 10:28:56 -04:00
|
|
|
#if defined(IMPLEMENT_LHASH_DOALL_ARG_FN) && defined(LHASH_OF)
|
2003-09-08 06:31:38 -04:00
|
|
|
static void
|
2010-04-23 04:37:55 -04:00
|
|
|
get_conf_section_doall_arg(CONF_VALUE *cv, void *tmp)
|
2003-09-08 06:31:38 -04:00
|
|
|
{
|
2010-04-23 04:37:55 -04:00
|
|
|
VALUE ary = (VALUE)tmp;
|
2003-09-08 06:31:38 -04:00
|
|
|
if(cv->name) return;
|
|
|
|
rb_ary_push(ary, rb_str_new2(cv->section));
|
|
|
|
}
|
|
|
|
|
2010-04-23 04:37:55 -04:00
|
|
|
static IMPLEMENT_LHASH_DOALL_ARG_FN(get_conf_section, CONF_VALUE, void)
|
2003-09-08 06:31:38 -04:00
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_config_get_sections(VALUE self)
|
|
|
|
{
|
|
|
|
CONF *conf;
|
|
|
|
VALUE ary;
|
|
|
|
|
|
|
|
GetConfig(self, conf);
|
|
|
|
ary = rb_ary_new();
|
2010-04-23 04:37:55 -04:00
|
|
|
lh_doall_arg((_LHASH *)conf->data, LHASH_DOALL_ARG_FN(get_conf_section),
|
|
|
|
(void*)ary);
|
2003-09-08 06:31:38 -04:00
|
|
|
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-04-23 04:37:55 -04:00
|
|
|
dump_conf_value_doall_arg(CONF_VALUE *cv, void *tmp)
|
2003-09-08 06:31:38 -04:00
|
|
|
{
|
2010-04-23 04:37:55 -04:00
|
|
|
VALUE str = (VALUE)tmp;
|
2003-09-08 06:31:38 -04:00
|
|
|
STACK_OF(CONF_VALUE) *sk;
|
|
|
|
CONF_VALUE *v;
|
|
|
|
int i, num;
|
|
|
|
|
|
|
|
if (cv->name) return;
|
|
|
|
sk = (STACK_OF(CONF_VALUE)*)cv->value;
|
|
|
|
num = sk_CONF_VALUE_num(sk);
|
|
|
|
rb_str_cat2(str, "[ ");
|
|
|
|
rb_str_cat2(str, cv->section);
|
|
|
|
rb_str_cat2(str, " ]\n");
|
|
|
|
for(i = 0; i < num; i++){
|
|
|
|
v = sk_CONF_VALUE_value(sk, i);
|
|
|
|
rb_str_cat2(str, v->name ? v->name : "None");
|
|
|
|
rb_str_cat2(str, "=");
|
|
|
|
rb_str_cat2(str, v->value ? v->value : "None");
|
|
|
|
rb_str_cat2(str, "\n");
|
|
|
|
}
|
|
|
|
rb_str_cat2(str, "\n");
|
|
|
|
}
|
|
|
|
|
2010-04-23 04:37:55 -04:00
|
|
|
static IMPLEMENT_LHASH_DOALL_ARG_FN(dump_conf_value, CONF_VALUE, void)
|
2003-09-08 06:31:38 -04:00
|
|
|
|
|
|
|
static VALUE
|
|
|
|
dump_conf(CONF *conf)
|
|
|
|
{
|
|
|
|
VALUE str;
|
|
|
|
|
|
|
|
str = rb_str_new(0, 0);
|
2010-04-23 04:37:55 -04:00
|
|
|
lh_doall_arg((_LHASH *)conf->data, LHASH_DOALL_ARG_FN(dump_conf_value),
|
|
|
|
(void*)str);
|
2003-09-08 06:31:38 -04:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_config_to_s(VALUE self)
|
|
|
|
{
|
|
|
|
CONF *conf;
|
|
|
|
|
|
|
|
GetConfig(self, conf);
|
|
|
|
|
|
|
|
return dump_conf(conf);
|
|
|
|
}
|
2004-02-23 13:45:41 -05:00
|
|
|
|
|
|
|
static void
|
2010-04-23 04:37:55 -04:00
|
|
|
each_conf_value_doall_arg(CONF_VALUE *cv, void *dummy)
|
2004-02-23 13:45:41 -05:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-23 04:37:55 -04:00
|
|
|
static IMPLEMENT_LHASH_DOALL_ARG_FN(each_conf_value, CONF_VALUE, void *)
|
2004-02-23 13:45:41 -05:00
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_config_each(VALUE self)
|
|
|
|
{
|
|
|
|
CONF *conf;
|
|
|
|
|
* ext/dbm/dbm.c (fdbm_each_value, fdbm_each_key, fdbm_each_pair):
GDBM#{each,each_pair,each_key,each_value}: Return an enumerator
if no block is given.
* ext/gdbm/gdbm.c (fgdbm_each_value, fgdbm_each_key,
fgdbm_each_pair): GDBM#{each,each_pair,each_key,each_value}:
Return an enumerator if no block is given.
* ext/openssl/ossl_config.c (ossl_config_each):
OpenSSL::Config#each: Return an enumerator if no block is given.
* ext/readline/readline.c (hist_each): Readline::HISTORY#each:
Return an enumerator if no block is given.
* ext/sdbm/init.c (fsdbm_each_value, fsdbm_each_key,
fsdbm_each_pair): SDBM#{each,each_pair,each_key,each_value}:
Return an enumerator if no block is given.
* ext/stringio/stringio.c (strio_each_byte, strio_each):
StringIO#{each,each_line,each_byte}: Return an enumerator if no
block is given.
* ext/stringio/stringio.c (Init_stringio): Add #lines and #bytes,
which are aliases to #each_line and #each_byte, respectively.
* ext/win32ole/win32ole.c (fole_each): WIN32OLE#each: Return an
enumerator if no block is given.
* ext/zlib/zlib.c (rb_gzreader_each_byte, rb_gzreader_each):
Zlib::GzipReader#{each,each_line,each_byte}: Return an
enumerator if no block is given.
* ext/zlib/zlib.c (Init_zlib): Add Zlib::GzipReader#lines and
#bytes, which are aliases to #each_line and #each_byte,
respectively.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16125 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-04-21 04:48:33 -04:00
|
|
|
RETURN_ENUMERATOR(self, 0, 0);
|
|
|
|
|
2004-02-23 13:45:41 -05:00
|
|
|
GetConfig(self, conf);
|
2010-04-23 04:37:55 -04:00
|
|
|
lh_doall_arg((_LHASH *)conf->data, LHASH_DOALL_ARG_FN(each_conf_value),
|
|
|
|
(void*)NULL);
|
2004-02-23 13:45:41 -05:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
2003-09-08 16:19:01 -04:00
|
|
|
#else
|
2004-02-23 13:45:41 -05:00
|
|
|
static VALUE
|
|
|
|
ossl_config_get_sections(VALUE self)
|
|
|
|
{
|
|
|
|
rb_warn("#sections don't work with %s", OPENSSL_VERSION_TEXT);
|
|
|
|
return rb_ary_new();
|
|
|
|
}
|
|
|
|
|
2003-09-08 16:19:01 -04:00
|
|
|
static VALUE
|
|
|
|
ossl_config_to_s(VALUE self)
|
|
|
|
{
|
2004-02-23 13:45:41 -05:00
|
|
|
rb_warn("#to_s don't work with %s", OPENSSL_VERSION_TEXT);
|
2003-09-08 16:19:01 -04:00
|
|
|
return rb_str_new(0, 0);
|
|
|
|
}
|
2004-02-23 13:45:41 -05:00
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_config_each(VALUE self)
|
|
|
|
{
|
|
|
|
rb_warn("#each don't work with %s", OPENSSL_VERSION_TEXT);
|
|
|
|
return self;
|
|
|
|
}
|
2003-09-08 16:19:01 -04:00
|
|
|
#endif
|
2003-09-08 06:31:38 -04:00
|
|
|
|
|
|
|
static VALUE
|
|
|
|
ossl_config_inspect(VALUE self)
|
|
|
|
{
|
|
|
|
VALUE str, ary = ossl_config_get_sections(self);
|
2008-07-22 11:34:23 -04:00
|
|
|
const char *cname = rb_class2name(rb_obj_class(self));
|
2003-09-08 06:31:38 -04:00
|
|
|
|
|
|
|
str = rb_str_new2("#<");
|
|
|
|
rb_str_cat2(str, cname);
|
|
|
|
rb_str_cat2(str, " sections=");
|
|
|
|
rb_str_append(str, rb_inspect(ary));
|
|
|
|
rb_str_cat2(str, ">");
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2003-07-23 12:12:24 -04:00
|
|
|
/*
|
|
|
|
* INIT
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Init_ossl_config()
|
|
|
|
{
|
2008-08-30 23:36:09 -04:00
|
|
|
char *default_config_file;
|
2003-07-23 12:12:24 -04:00
|
|
|
eConfigError = rb_define_class_under(mOSSL, "ConfigError", eOSSLError);
|
|
|
|
cConfig = rb_define_class_under(mOSSL, "Config", rb_cObject);
|
|
|
|
|
2008-08-30 23:36:09 -04:00
|
|
|
default_config_file = CONF_get1_default_config_file();
|
2003-09-08 06:31:38 -04:00
|
|
|
rb_define_const(cConfig, "DEFAULT_CONFIG_FILE",
|
2008-08-30 02:54:25 -04:00
|
|
|
rb_str_new2(default_config_file));
|
|
|
|
OPENSSL_free(default_config_file);
|
2004-02-23 13:45:41 -05:00
|
|
|
rb_include_module(cConfig, rb_mEnumerable);
|
2003-09-08 06:31:38 -04:00
|
|
|
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);
|
|
|
|
rb_define_copy_func(cConfig, ossl_config_copy);
|
|
|
|
rb_define_method(cConfig, "initialize", ossl_config_initialize, -1);
|
|
|
|
rb_define_method(cConfig, "get_value", ossl_config_get_value, 2);
|
|
|
|
rb_define_method(cConfig, "value", ossl_config_get_value_old, -1);
|
2009-04-18 10:10:06 -04:00
|
|
|
rb_define_method(cConfig, "add_value", ossl_config_add_value_m, 3);
|
2003-09-08 06:31:38 -04:00
|
|
|
rb_define_method(cConfig, "[]", ossl_config_get_section, 1);
|
|
|
|
rb_define_method(cConfig, "section", ossl_config_get_section_old, 1);
|
|
|
|
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);
|
2004-02-23 13:45:41 -05:00
|
|
|
rb_define_method(cConfig, "each", ossl_config_each, 0);
|
2003-09-08 06:31:38 -04:00
|
|
|
rb_define_method(cConfig, "inspect", ossl_config_inspect, 0);
|
2003-07-23 12:12:24 -04:00
|
|
|
}
|