Class: OpenSSL::Config
Constant Summary collapse
- DEFAULT_CONFIG_FILE =
rb_str_new2(CONF_get1_default_config_file())
Class Method Summary collapse
Instance Method Summary collapse
-
#[](section) ⇒ Object
Get all numbers as strings - use str.to_i to convert long number = CONF_get_number(confp->config, sect, StringValuePtr(item));.
- #[]=(section, hash) ⇒ Object
- #add_value(section, name, value) ⇒ Object
- #each ⇒ Object
- #get_value(section, name) ⇒ Object
- #initialize(*args) ⇒ Object constructor
- #inspect ⇒ Object
- #section(section) ⇒ Object
- #sections ⇒ Object
- #to_s ⇒ Object
- #value(*args) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'ossl_config.c', line 129
static VALUE
ossl_config_initialize(int argc, VALUE *argv, VALUE self)
{
CONF *conf;
long eline = -1;
char *filename;
VALUE path;
rb_scan_args(argc, argv, "01", &path);
if(!NIL_P(path)){
SafeStringValue(path);
filename = StringValuePtr(path);
GetConfig(self, conf);
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);
}
}
#ifdef OSSL_NO_CONF_API
else rb_raise(rb_eArgError, "wrong number of arguments (0 for 1)");
#else
else {
GetConfig(self, conf);
_CONF_new_data(conf);
}
#endif
return self;
}
|
Class Method Details
.parse(str) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 |
# File 'ossl_config.c', line 91
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;
}
|
Instance Method Details
#[](section) ⇒ Object
Get all numbers as strings - use str.to_i to convert long number = CONF_get_number(confp->config, sect, StringValuePtr(item));
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'ossl_config.c', line 257
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;
hash = rb_hash_new();
StringValue(section);
GetConfig(self, conf);
if (!(sk = NCONF_get_section(conf, StringValuePtr(section)))) {
ERR_clear_error();
return hash;
}
if ((entries = sk_CONF_VALUE_num(sk)) < 0) {
OSSL_Debug("# of items in section is < 0?!?");
return hash;
}
for (i=0; i<entries; i++) {
entry = sk_CONF_VALUE_value(sk, i);
rb_hash_aset(hash, rb_str_new2(entry->name), rb_str_new2(entry->value));
}
return hash;
}
|
#[]=(section, hash) ⇒ Object
245 246 247 248 249 250 251 |
# File 'ossl_config.c', line 245
static VALUE
ossl_config_set_section(VALUE self, VALUE section, VALUE hash)
{
VALUE arg[2] = { self, section };
rb_iterate(rb_each, hash, set_conf_section_i, (VALUE)arg);
return hash;
}
|
#add_value(section, name, value) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'ossl_config.c', line 161
static VALUE
ossl_config_add_value(VALUE self, VALUE section, VALUE name, VALUE value)
{
#ifdef OSSL_NO_CONF_API
rb_notimplement();
#else
CONF *conf;
CONF_VALUE *sv, *cv;
StringValue(section);
StringValue(name);
StringValue(value);
GetConfig(self, conf);
if(!(sv = _CONF_get_section(conf, RSTRING(section)->ptr))){
if(!(sv = _CONF_new_section(conf, RSTRING(section)->ptr))){
ossl_raise(eConfigError, NULL);
}
}
if(!(cv = OPENSSL_malloc(sizeof(CONF_VALUE)))){
ossl_raise(eConfigError, NULL);
}
cv->name = BUF_strdup(RSTRING(name)->ptr);
cv->value = BUF_strdup(RSTRING(value)->ptr);
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");
}
return value;
#endif
}
|
#each ⇒ Object
409 410 411 412 413 414 |
# File 'ossl_config.c', line 409
static VALUE
ossl_config_each(VALUE self)
{
rb_warn("#each don't work with %s", OPENSSL_VERSION_TEXT);
return self;
}
|
#get_value(section, name) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'ossl_config.c', line 195
static VALUE
ossl_config_get_value(VALUE self, VALUE section, VALUE name)
{
CONF *conf;
char *str;
StringValue(section);
StringValue(name);
GetConfig(self, conf);
str = NCONF_get_string(conf, RSTRING(section)->ptr, RSTRING(name)->ptr);
if(!str){
ERR_clear_error();
return Qnil;
}
return rb_str_new2(str);
}
|
#inspect ⇒ Object
417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
# File 'ossl_config.c', line 417
static VALUE
ossl_config_inspect(VALUE self)
{
VALUE str, ary = ossl_config_get_sections(self);
char *cname = rb_class2name(rb_obj_class(self));
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;
}
|
#section(section) ⇒ Object
285 286 287 288 289 290 |
# File 'ossl_config.c', line 285
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);
}
|
#sections ⇒ Object
395 396 397 398 399 400 |
# File 'ossl_config.c', line 395
static VALUE
ossl_config_get_sections(VALUE self)
{
rb_warn("#sections don't work with %s", OPENSSL_VERSION_TEXT);
return rb_ary_new();
}
|
#to_s ⇒ Object
402 403 404 405 406 407 |
# File 'ossl_config.c', line 402
static VALUE
ossl_config_to_s(VALUE self)
{
rb_warn("#to_s don't work with %s", OPENSSL_VERSION_TEXT);
return rb_str_new(0, 0);
}
|
#value(*args) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'ossl_config.c', line 213
static VALUE
ossl_config_get_value_old(int argc, VALUE *argv, VALUE self)
{
VALUE section, name;
rb_scan_args(argc, argv, "11", §ion, &name);
/* 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) */
rb_warn("Config#value is deprecated; use Config#get_value");
return ossl_config_get_value(self, section, name);
}
|