diff options
author | daurnimator <quae@daurnimator.com> | 2017-02-27 15:23:05 +1100 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-02-27 15:26:03 +1100 |
commit | 3d7180c36adb6b9be8f4bb9825d3e35eef146bf5 (patch) | |
tree | 95709f2dcbabe9550041f543a2570068f8a1649f | |
parent | b4bf06dcb61dbd735b328f47d8a36afb856d5d16 (diff) | |
download | luaossl-3d7180c36adb6b9be8f4bb9825d3e35eef146bf5.tar.gz luaossl-3d7180c36adb6b9be8f4bb9825d3e35eef146bf5.tar.bz2 luaossl-3d7180c36adb6b9be8f4bb9825d3e35eef146bf5.zip |
extension.new: Factor out conf loading to own function
-rw-r--r-- | src/openssl.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/openssl.c b/src/openssl.c index fa7dd79..900b909 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -4958,6 +4958,25 @@ static _Bool xe_new_isder(const char *value, _Bool *crit) { return 0; } /* xs_new_isder() */ +static CONF* loadconf(lua_State *L, int idx) { + CONF *conf; + size_t len; + const char *cdata = luaL_checklstring(L, idx, &len); + BIO *bio = getbio(L); + if (BIO_write(bio, cdata, len) < 0) + return NULL; + + if (!(conf = NCONF_new(NULL))) + return NULL; + + if (!NCONF_load_bio(conf, bio, NULL)) { + NCONF_free(conf); + return NULL; + } + + return conf; +} + static int xe_new(lua_State *L) { const char *name = luaL_checkstring(L, 1); const char *value = luaL_checkstring(L, 2); @@ -4991,13 +5010,7 @@ static int xe_new(lua_State *L) { return 1; } - BIO *bio = getbio(L); - if (BIO_puts(bio, cdata) < 0) - goto error; - - if (!(conf = NCONF_new(NULL))) - goto error; - if (!NCONF_load_bio(conf, bio, NULL)) + if (!(conf = loadconf(L, 3))) goto error; ctx = &cbuf; |