squidii inii revisionii
This commit is contained in:
parent
466c1e5cc7
commit
6960ec36a3
9 changed files with 71 additions and 14 deletions
|
@ -1 +0,0 @@
|
|||
NULL
|
5
resources/config_sample.ini
Normal file
5
resources/config_sample.ini
Normal file
|
@ -0,0 +1,5 @@
|
|||
; Sample global configuration file, generally called config.ini
|
||||
|
||||
[SSL]
|
||||
Certificate = cert.pem
|
||||
Private Key = key.pem
|
17
src/conf/conf.c
Normal file
17
src/conf/conf.c
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include "conf.h"
|
||||
|
||||
int glv_config_load_global(const char* path) {
|
||||
_config.global = glv_ini_read_file(path);
|
||||
if(_config.global == NULL) {
|
||||
printf(GLV_CRIT "Global configuration failed to load.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void glv_config_unload(void) {
|
||||
glv_ini_destroy(_config.global);
|
||||
}
|
14
src/conf/conf.h
Normal file
14
src/conf/conf.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef GLV_CONF_CONF_H
|
||||
#define GLV_CONF_CONF_H
|
||||
|
||||
#include "conf/ini.h"
|
||||
|
||||
struct {
|
||||
glv_ini_t* global;
|
||||
} _config;
|
||||
|
||||
int glv_config_load_global(const char* path);
|
||||
|
||||
void glv_config_unload(void);
|
||||
|
||||
#endif
|
|
@ -1,7 +1,5 @@
|
|||
#include "ini.h"
|
||||
|
||||
|
||||
|
||||
glv_ini_t* glv_ini_read_file(const char* path) {
|
||||
char *split, line[GLV_INI_MAX_LN + 1];
|
||||
glv_map_t* section = NULL;
|
||||
|
@ -21,7 +19,7 @@ glv_ini_t* glv_ini_read_file(const char* path) {
|
|||
continue;
|
||||
|
||||
length = strlen(line);
|
||||
if(length == GLV_INI_MAX_LN && line[length - 1] != '\n' && !feof(file))
|
||||
if(length == GLV_INI_MAX_LN && !feof(file))
|
||||
{
|
||||
printf(GLV_ERR
|
||||
"INI file '%s' has line that exceeds %i bytes.",
|
||||
|
@ -34,13 +32,13 @@ glv_ini_t* glv_ini_read_file(const char* path) {
|
|||
}
|
||||
|
||||
if(line[0] == '[') {
|
||||
if(line[length - 2] == ']') {
|
||||
line[length - 2] = '\0';
|
||||
if(line[length - 1] == ']') {
|
||||
line[length - 1] = '\0';
|
||||
strlower(trim(line + 1));
|
||||
|
||||
if(!glv_map_has_key(ini, line + 1)) {
|
||||
section = glv_map_create();
|
||||
glv_map_set_copy(ini, line + 1, section, GLV_STRLEN);
|
||||
glv_map_set_copy(ini, line + 1, section, sizeof(glv_ini_t));
|
||||
}
|
||||
} else {
|
||||
printf(GLV_ERR
|
||||
|
|
11
src/main.c
11
src/main.c
|
@ -1,10 +1,15 @@
|
|||
#include <stdio.h>
|
||||
#include "sock/ipaddr.h"
|
||||
#include "util/containers.h"
|
||||
#include "util/etc.h"
|
||||
#include "conf/conf.h"
|
||||
#include "sock/tcp_ssl.c"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
printf("Starting Glove Chat server...");
|
||||
|
||||
if(!glv_config_load_global("config.ini"))
|
||||
return -1;
|
||||
|
||||
glv_ssl_init();
|
||||
|
||||
glv_config_unload();
|
||||
return 0;
|
||||
}
|
|
@ -31,7 +31,8 @@
|
|||
#include <openssl/ssl.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "ipaddr.h"
|
||||
#include "conf/conf.h"
|
||||
#include "sock/ipaddr.h"
|
||||
#include "util/thread.h"
|
||||
|
||||
#define GLV_TCP_FLAG_TYPE 1
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#ifndef _WIN32
|
||||
|
||||
#include "tcp.h"
|
||||
#include "tcp_ssl.c"
|
||||
|
||||
glv_tcp_t* glv_tcp_create_server(uint16_t port) {
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include <conf/conf.h>
|
||||
#include "tcp.h"
|
||||
|
||||
struct {
|
||||
|
@ -8,8 +9,8 @@ struct {
|
|||
glv_mutex_t client_mtx;
|
||||
} _ssl_ctx;
|
||||
|
||||
static int ssl_init() {
|
||||
/*static int is_inited = 0;
|
||||
static int glv_ssl_init() {
|
||||
static int is_inited = 0;
|
||||
if(is_inited)
|
||||
return 1;
|
||||
|
||||
|
@ -30,6 +31,21 @@ static int ssl_init() {
|
|||
int success = 0;
|
||||
success |= SSL_CTX_use_certificate_file(
|
||||
_ssl_ctx.server,
|
||||
glv_ini_get(_config.global, "SSL", "Certificate"),
|
||||
SSL_FILETYPE_PEM
|
||||
);
|
||||
success |= SSL_CTX_use_PrivateKey_file(
|
||||
_ssl_ctx.server,
|
||||
glv_ini_get(_config.global, "SSL", "Private Key"),
|
||||
SSL_FILETYPE_PEM
|
||||
);
|
||||
|
||||
);*/
|
||||
if(success <= 0) {
|
||||
SSL_CTX_free(_ssl_ctx.client);
|
||||
SSL_CTX_free(_ssl_ctx.server);
|
||||
return 0;
|
||||
}
|
||||
|
||||
is_inited = 1;
|
||||
return 1;
|
||||
}
|
Reference in a new issue