Ruby 2.0.0p353(2013-11-22revision43784)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

ossl_config.c
Go to the documentation of this file.
1 /*
2 * $Id: ossl_config.c 29359 2010-09-29 03:37:44Z nobu $
3 * 'OpenSSL for Ruby' project
4 * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
5 * All rights reserved.
6 */
7 /*
8 * This program is licenced under the same licence as Ruby.
9 * (See the file 'LICENCE'.)
10 */
11 #include "ossl.h"
12
13
14 /*
15 * Classes
16 */
17 VALUE cConfig;
18 VALUE eConfigError;
19
20 /*
21 * Public
22 */
23
24 /*
25 * GetConfigPtr is a public C-level function for getting OpenSSL CONF struct
26 * from an OpenSSL::Config(eConfig) instance. We decided to implement
27 * OpenSSL::Config in Ruby level but we need to pass native CONF struct for
28 * some OpenSSL features such as X509V3_EXT_*.
29 */
30 CONF *
31 GetConfigPtr(VALUE obj)
32 {
33 CONF *conf;
34 VALUE str;
35 BIO *bio;
36 long eline = -1;
37
38 OSSL_Check_Kind(obj, cConfig);
39 str = rb_funcall(obj, rb_intern("to_s"), 0);
40 bio = ossl_obj2bio(str);
41 conf = NCONF_new(NULL);
42 if(!conf){
43 BIO_free(bio);
44 ossl_raise(eConfigError, NULL);
45 }
46 if(!NCONF_load_bio(conf, bio, &eline)){
47 BIO_free(bio);
48 NCONF_free(conf);
49 if (eline <= 0) ossl_raise(eConfigError, "wrong config format");
50 else ossl_raise(eConfigError, "error in line %d", eline);
51 ossl_raise(eConfigError, NULL);
52 }
53 BIO_free(bio);
54
55 return conf;
56 }
57
58
59 /*
60 * INIT
61 */
62 void
63 Init_ossl_config()
64 {
65 char *default_config_file;
66 eConfigError = rb_define_class_under(mOSSL, "ConfigError", eOSSLError);
67 cConfig = rb_define_class_under(mOSSL, "Config", rb_cObject);
68
69 default_config_file = CONF_get1_default_config_file();
70 rb_define_const(cConfig, "DEFAULT_CONFIG_FILE",
71 rb_str_new2(default_config_file));
72 OPENSSL_free(default_config_file);
73 /* methods are defined by openssl/config.rb */
74 }
mOSSL
VALUE mOSSL
Definition: ossl.c:259
Init_ossl_config
void Init_ossl_config()
Definition: ossl_config.c:63
rb_funcall
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:774
rb_define_class_under
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:545
rb_str_new2
#define rb_str_new2
str
static VALUE char * str
Definition: tcltklib.c:3547
rb_define_const
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:2202
obj
static VALUE VALUE obj
Definition: tcltklib.c:3158
eOSSLError
VALUE eOSSLError
Definition: ossl.c:264
eConfigError
VALUE eConfigError
Definition: ossl_config.c:18
ossl_obj2bio
BIO * ossl_obj2bio(VALUE obj)
Definition: ossl_bio.c:17
GetConfigPtr
CONF * GetConfigPtr(VALUE obj)
Definition: ossl_config.c:31
OSSL_Check_Kind
#define OSSL_Check_Kind(obj, klass)
Definition: ossl.h:96
rb_cObject
RUBY_EXTERN VALUE rb_cObject
Definition: ripper.y:1426
ossl_raise
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:328
ossl.h
VALUE
unsigned long VALUE
Definition: ripper.y:104
CONF_get1_default_config_file
char * CONF_get1_default_config_file(void)
Definition: openssl_missing.c:286
rb_intern
#define rb_intern(str)
NULL
#define NULL
Definition: _sdbm.c:103
cConfig
VALUE cConfig
Definition: ossl_config.c:17