qLibc
qconfig.c File Reference

INI-style configuration file parser. More...

Go to the source code of this file.

Macros

#define _INCLUDE_DIRECTIVE   "@INCLUDE "
 

Functions

qlisttbl_t * qconfig_parse_file (qlisttbl_t *tbl, const char *filepath, char sepchar)
 Load & parse configuration file.
 
qlisttbl_t * qconfig_parse_str (qlisttbl_t *tbl, const char *str, char sepchar)
 Parse string.
 

Detailed Description

INI-style configuration file parser.

Definition in file qconfig.c.

Macro Definition Documentation

◆ _INCLUDE_DIRECTIVE

#define _INCLUDE_DIRECTIVE   "@INCLUDE "

Definition at line 47 of file qconfig.c.

Function Documentation

◆ qconfig_parse_file()

qlisttbl_t * qconfig_parse_file ( qlisttbl_t *  tbl,
const char *  filepath,
char  sepchar 
)

Load & parse configuration file.

Parameters
tbla pointer of qlisttbl_t. NULL will generate a new table.
filepathconfiguration file path
sepcharseparater used in configuration file to divice key and value
Returns
a pointer of qlisttbl_t in case of successful, otherwise(file not found) returns NULL
# This is "config.conf" file.
# A line which starts with # character is comment
@INCLUDE config.def => include 'config.def' file.
prefix=/tmp => set static value. 'prefix' is the key for this entry.
log=${prefix}/log => get the value from previously defined key 'prefix'.
user=${%USER} => get environment variable.
host=${!/bin/hostname -s} => run external command and put it's output.
id=${user}@${host}
# now entering into 'system' section.
[system] => a key 'system.' with value 'system' will be inserted.
ostype=${%OSTYPE} => 'system.ostype' is the key for this entry.
machtype=${%MACHTYPE} => 'system.machtype' is the key for this entry.
# entering into 'daemon' section.
[daemon]
port=1234
name=${user}_${host}_${system.ostype}_${system.machtype}
# escape section. (go back to root)
[]
rev=822
static bool put(qhttpclient_t *client, const char *uri, int fd, off_t length, int *rescode, qlisttbl_t *reqheaders, qlisttbl_t *resheaders, bool(*callback)(void *userdata, off_t sentbytes), void *userdata)
qhttpclient->put(): Uploads a file to the remote host using PUT method.
static bool get(qhttpclient_t *client, const char *uri, int fd, off_t *savesize, int *rescode, qlisttbl_t *reqheaders, qlisttbl_t *resheaders, bool(*callback)(void *userdata, off_t recvbytes), void *userdata)
qhttpclient->get(): Downloads a file from the remote host using GET method.
# This is "config.def" file.
prefix = /usr/local
bin = ${prefix}/bin
log = ${prefix}/log
user = unknown
host = unknown
qlisttbl_t *tbl = qconfig_parse_file(NULL, "config.conf", '=', true);
tbl->debug(tbl, stdout);
[Output]
bin=/usr/local/bin? (15)
prefix=/tmp? (5)
log=/tmp/log? (9)
user=seungyoung.kim? (9)
host=eng22? (6)
id=seungyoung.kim@eng22? (15)
system.=system? (7)
system.ostype=linux? (6)
system.machtype=x86_64? (7)
daemon.=daemon? (7)
daemon.port=1234? (5)
daemon.name=seungyoung.kim_eng22_linux_x86_64? (28)
rev=822? (4)
qlisttbl_t * qconfig_parse_file(qlisttbl_t *tbl, const char *filepath, char sepchar)
Load & parse configuration file.
Definition qconfig.c:126

Definition at line 126 of file qconfig.c.

◆ qconfig_parse_str()

qlisttbl_t * qconfig_parse_str ( qlisttbl_t *  tbl,
const char *  str,
char  sepchar 
)

Parse string.

Parameters
tbla pointer of qlisttbl_t. NULL will generate a new table.
strkey, value pair strings
sepcharseparater used in configuration file to divice key and value
Returns
a pointer of qlisttbl_t in case of successful, otherwise(file not found) returns NULL
See also
qconfig_parse_file
qlisttbl_t *tbl;
tbl = qconfig_parse_str(NULL, "key = value\nhello = world", '=');
qlisttbl_t * qconfig_parse_str(qlisttbl_t *tbl, const char *str, char sepchar)
Parse string.
Definition qconfig.c:216

Definition at line 216 of file qconfig.c.