#include "config_load.h" int config_load_ini(char *ini_fname, config_ini **config) { config_ini *res_conf=NULL; if (!ini_fname) { PERM(); return -1; } if (!config) { PERM(); return -1; } res_conf = calloc(1,sizeof(config_ini)); res_conf->ini = iniparser_load(ini_fname); if (!res_conf->ini) { ERROR("Cant parse ini file %s\n",ini_fname); free(res_conf); return -1; } *config = res_conf; return 0; } int config_server_num(config_ini *config) { int ret=-1; if (!config) { PERM(); return -1; } ret = iniparser_getnsec(config->ini); return ret; } int config_get_irc_config(config_ini *config, int n, irc_server_conf *server_conf) { int i; size_t buf_sz=128; char buf[buf_sz]; char *section_name=NULL; dictionary *ini; char *ini_str; int ini_int; int count; sds params; sds *tokens=NULL; if (!config) { PERM(); return -1; } if (!server_conf) { PERM(); return -1; } if (n<0) { PERM(); return -1; } ini = config->ini; section_name = (char *)iniparser_getsecname(ini, n); if (!section_name) { PERM(); return -1; } //section name server_conf->name = (char *)alloc_new_str(section_name); //get server name snprintf(buf, buf_sz, "%s:server", section_name); ini_str = (char *)iniparser_getstring(ini, buf, NULL); server_conf->server = alloc_new_str(ini_str); //get user name snprintf(buf, buf_sz, "%s:user", section_name); ini_str = (char *)iniparser_getstring(ini, buf, NULL); server_conf->user = alloc_new_str(ini_str); //get port number snprintf(buf, buf_sz, "%s:port", section_name); ini_str = (char *)iniparser_getstring(ini, buf, NULL); server_conf->port = (char *)alloc_new_str(ini_str); //get enabled snprintf(buf, buf_sz, "%s:enabled", section_name); ini_int = (int)iniparser_getint(ini, buf, -1); server_conf->enabled = ini_int; //get ssl snprintf(buf, buf_sz, "%s:ssl", section_name); ini_int = (int)iniparser_getint(ini, buf, -1); server_conf->ssl = ini_int; //get channel list snprintf(buf, buf_sz, "%s:channels", section_name); ini_str = (char *)iniparser_getstring(ini, buf, NULL); params = sdsnew(ini_str); tokens = sdssplitlen(params,sdslen(params),",",1,&count); for (i=0;(ichannels[i] = alloc_new_str(tokens[i]); } server_conf->channels[i]=NULL; sdsfree(params); sdsfreesplitres(tokens,count); return 0; } void config_free(config_ini *config) { if (!config) { PERM(); return; } iniparser_freedict(config->ini); config->ini = NULL; free(config); config = NULL; }