From c23e2a4a7c7d407378ff70ead90db144a24224d5 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 12 Nov 2014 15:39:45 +0000 Subject: [PATCH] added experimental code to pass unvalidated configuration items to a module --- qse/cmd/http/httpd.c | 11 ++++++----- qse/cmd/http/httpd.conf | 4 ++++ qse/include/qse/http/httpd.h | 10 ++++++---- qse/include/qse/xli/xli.h | 4 ++-- qse/lib/http/httpd.c | 4 ++-- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/qse/cmd/http/httpd.c b/qse/cmd/http/httpd.c index 55ec3614..8618f0fe 100644 --- a/qse/cmd/http/httpd.c +++ b/qse/cmd/http/httpd.c @@ -2045,7 +2045,7 @@ static qse_httpd_server_t* attach_server (qse_httpd_t* httpd, int num, qse_xli_l static int load_hook_modules (qse_httpd_t* httpd, qse_xli_list_t* hook_list) { qse_char_t buf[32]; - qse_xli_pair_t* pair; + qse_xli_pair_t* pair, * cfg; httpd_xtn_t* httpd_xtn; int i; @@ -2065,7 +2065,8 @@ static int load_hook_modules (qse_httpd_t* httpd, qse_xli_list_t* hook_list) } else { - qse_httpd_loadmod (httpd, ((qse_xli_str_t*)pair->val)->ptr); + cfg = qse_xli_findpair (httpd_xtn->xli, (qse_xli_list_t*)pair->val, QSE_T("config")); + qse_httpd_loadmod (httpd, ((qse_xli_str_t*)pair->val)->ptr, (cfg? cfg->val: QSE_NULL)); /* TODO: error handling and logging */ } } @@ -2239,11 +2240,11 @@ static int open_config_file (qse_httpd_t* httpd) xli_in.type = QSE_XLI_IOSTD_FILE; xli_in.u.file.path = httpd_xtn->cfgfile; xli_in.u.file.cmgr = QSE_NULL; - + if (qse_xli_readstd (httpd_xtn->xli, &xli_in) <= -1) { const qse_xli_loc_t* errloc; - + errloc = qse_xli_geterrloc (httpd_xtn->xli); if (errloc->line > 0 || errloc->colm > 0) @@ -2361,7 +2362,7 @@ static int load_config (qse_httpd_t* httpd) else { qse_httpd_server_t* server; - + server = attach_server (httpd, i, (qse_xli_list_t*)pair->val); if (server) { diff --git a/qse/cmd/http/httpd.conf b/qse/cmd/http/httpd.conf index a966ab64..94d54b72 100644 --- a/qse/cmd/http/httpd.conf +++ b/qse/cmd/http/httpd.conf @@ -12,6 +12,10 @@ max-nproc = none; #hooks { # module "ext-1" { # file = "ext"; +# config { +# item1 = abc; +# item2 = def; +# } # } #} diff --git a/qse/include/qse/http/httpd.h b/qse/include/qse/http/httpd.h index 9689073b..9e748386 100644 --- a/qse/include/qse/http/httpd.h +++ b/qse/include/qse/http/httpd.h @@ -29,7 +29,7 @@ #include #include #include - +#include typedef struct qse_httpd_t qse_httpd_t; typedef struct qse_httpd_mate_t qse_httpd_mate_t; @@ -103,7 +103,8 @@ typedef enum qse_httpd_trait_t qse_httpd_trait_t; typedef struct qse_httpd_mod_t qse_httpd_mod_t; typedef int (*qse_httpd_mod_load_t) ( - qse_httpd_mod_t* mod + qse_httpd_mod_t* mod, + const qse_xli_list_t* cfg ); typedef void (*qse_httpd_mod_unload_t) ( @@ -1419,8 +1420,9 @@ QSE_EXPORT int qse_httpd_rewriteurl ( ); QSE_EXPORT int qse_httpd_loadmod ( - qse_httpd_t* httpd, - const qse_char_t* name + qse_httpd_t* httpd, + const qse_char_t* name, + const qse_xli_list_t* list ); QSE_EXPORT qse_httpd_mod_t* qse_httpd_findmod ( diff --git a/qse/include/qse/xli/xli.h b/qse/include/qse/xli/xli.h index 71b1d447..8e36aee6 100644 --- a/qse/include/qse/xli/xli.h +++ b/qse/include/qse/xli/xli.h @@ -115,6 +115,7 @@ enum qse_xli_trait_t * "tg" is stored into the tag field of qse_xli_str_t. */ QSE_XLI_STRTAG = (1 << 10), + /** enable pair validation against pair definitions while reading */ QSE_XLI_VALIDATE = (1 << 11) }; typedef enum qse_xli_trait_t qse_xli_trait_t; @@ -668,7 +669,7 @@ QSE_EXPORT int qse_xli_undefinepair ( QSE_EXPORT void qse_xli_undefinepairs ( qse_xli_t* xli ); - + QSE_EXPORT int qse_xli_read ( qse_xli_t* xli, qse_xli_io_impl_t io @@ -679,7 +680,6 @@ QSE_EXPORT int qse_xli_write ( qse_xli_io_impl_t io ); - QSE_EXPORT void* qse_getxlipairxtn ( qse_xli_pair_t* pair ); diff --git a/qse/lib/http/httpd.c b/qse/lib/http/httpd.c index 27d5481a..2b56e676 100644 --- a/qse/lib/http/httpd.c +++ b/qse/lib/http/httpd.c @@ -2236,7 +2236,7 @@ static void unload_all_modules (qse_httpd_t* httpd) } } -int qse_httpd_loadmod (qse_httpd_t* httpd, const qse_char_t* name) +int qse_httpd_loadmod (qse_httpd_t* httpd, const qse_char_t* name, const qse_xli_list_t* cfg) { qse_httpd_mod_t* mod; qse_size_t name_len, prefix_len, postfix_len, fullname_len; @@ -2308,7 +2308,7 @@ int qse_httpd_loadmod (qse_httpd_t* httpd, const qse_char_t* name) } } - if (load == QSE_NULL || load (mod) <= -1) + if (load == QSE_NULL || load (mod, cfg) <= -1) { httpd->opt.scb.mod.close (httpd, mod->handle); qse_httpd_freemem (httpd, mod);