00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "ossl.h"
00012
00013
00014
00015
00016
00017 VALUE cConfig;
00018
00019
00020
00021
00022
00023 VALUE eConfigError;
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 CONF *
00036 GetConfigPtr(VALUE obj)
00037 {
00038 CONF *conf;
00039 VALUE str;
00040 BIO *bio;
00041 long eline = -1;
00042
00043 OSSL_Check_Kind(obj, cConfig);
00044 str = rb_funcall(obj, rb_intern("to_s"), 0);
00045 bio = ossl_obj2bio(str);
00046 conf = NCONF_new(NULL);
00047 if(!conf){
00048 BIO_free(bio);
00049 ossl_raise(eConfigError, NULL);
00050 }
00051 if(!NCONF_load_bio(conf, bio, &eline)){
00052 BIO_free(bio);
00053 NCONF_free(conf);
00054 if (eline <= 0) ossl_raise(eConfigError, "wrong config format");
00055 else ossl_raise(eConfigError, "error in line %d", eline);
00056 ossl_raise(eConfigError, NULL);
00057 }
00058 BIO_free(bio);
00059
00060 return conf;
00061 }
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 void
00072 Init_ossl_config()
00073 {
00074 char *default_config_file;
00075 eConfigError = rb_define_class_under(mOSSL, "ConfigError", eOSSLError);
00076 cConfig = rb_define_class_under(mOSSL, "Config", rb_cObject);
00077
00078 default_config_file = CONF_get1_default_config_file();
00079 rb_define_const(cConfig, "DEFAULT_CONFIG_FILE",
00080 rb_str_new2(default_config_file));
00081 OPENSSL_free(default_config_file);
00082
00083 }
00084