/* * ssl.c * Copyright (C) 2019 Ilja KartaĊĦov * * Distributed under terms of the MIT license. */ #include #include "ssl.h" #include "str-utils.h" #ifndef AISL_WITHOUT_SSL aisl_ssl_t aisl_ssl_new( const char * key_file, const char * crt_file, const char * host, SSL_CTX * ctx ) { aisl_ssl_t ssl; if ((ssl = calloc(1, sizeof(struct aisl_ssl))) != NULL) { if ((ssl->host = str_copy( host ? host : "*" )) != NULL) { if (ctx) { ssl->ctx = ctx; return ssl; } else { if ((ssl->key_file = str_copy(key_file)) != NULL) { if ((ssl->crt_file = str_copy(crt_file)) != NULL) { return ssl; } } } } aisl_ssl_free(ssl); } return NULL; } void aisl_ssl_free( aisl_ssl_t ssl ) { if (ssl->host) free(ssl->host); if (ssl->key_file) { free(ssl->key_file); SSL_CTX_free(ssl->ctx); } if (ssl->crt_file) free(ssl->crt_file); free(ssl); } #endif