From 847a08c45533290b29f99f19a8b820396a8f6295 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 11 Mar 2013 16:34:41 +0000 Subject: [PATCH] enhanced cmd/http/httpd.c to load host/location-specific configuration data --- qse/cmd/awk/awk.c | 4 +- qse/cmd/http/httpd.c | 987 ++++++++++++-------------------- qse/include/qse/cmn/htb.h | 45 +- qse/include/qse/cmn/map.h | 32 +- qse/include/qse/cmn/rbt.h | 47 +- qse/include/qse/cmn/str.h | 4 +- qse/include/qse/http/stdhttpd.h | 11 +- qse/lib/awk/Awk.cpp | 4 +- qse/lib/awk/StdAwk.cpp | 4 +- qse/lib/awk/awk.c | 24 +- qse/lib/awk/mod-dir.c | 2 +- qse/lib/awk/mod-uci.c | 2 +- qse/lib/awk/run.c | 4 +- qse/lib/awk/std.c | 4 +- qse/lib/awk/val.c | 4 +- qse/lib/cmn/htb.c | 87 +-- qse/lib/cmn/rbt.c | 58 +- qse/lib/http/htre.c | 6 +- qse/lib/http/httpd-dir.c | 2 +- qse/lib/http/httpd-std.c | 62 +- qse/lib/sed/sed.c | 8 +- qse/lib/xli/xli.c | 16 +- 22 files changed, 596 insertions(+), 821 deletions(-) diff --git a/qse/cmd/awk/awk.c b/qse/cmd/awk/awk.c index 52b0dae6..b5dc9eb2 100644 --- a/qse/cmd/awk/awk.c +++ b/qse/cmd/awk/awk.c @@ -595,8 +595,8 @@ static int comparg (int argc, qse_char_t* argv[], struct arg_t* arg) goto oops; } - qse_htb_setmancbs (gvm, - qse_gethtbmancbs(QSE_HTB_MANCBS_INLINE_VALUE_COPIER) + qse_htb_setstyle (gvm, + qse_gethtbstyle(QSE_HTB_STYLE_INLINE_VALUE_COPIER) ); while ((c = qse_getopt (argc, argv, &opt)) != QSE_CHAR_EOF) diff --git a/qse/cmd/http/httpd.c b/qse/cmd/http/httpd.c index fe2f0f6d..b27e0a2e 100644 --- a/qse/cmd/http/httpd.c +++ b/qse/cmd/http/httpd.c @@ -52,6 +52,138 @@ static int g_debug = 0; /* --------------------------------------------------------------------- */ +enum +{ + SCFG_SSLCERTFILE, + SCFG_SSLKEYFILE, + SCFG_MAX +}; + +enum +{ + XCFG_NAME, + XCFG_ROOT, + XCFG_REALM, + XCFG_AUTH, + XCFG_DIRCSS, + XCFG_ERRCSS, + XCFG_MAX +}; + +struct cgi_t +{ + enum { + CGI_PREFIX, + CGI_SUFFIX, + CGI_NAME, + CGI_MAX + } type; + + qse_mchar_t* spec; + int nph; + qse_mchar_t* shebang; + + struct cgi_t* next; +}; + +struct mime_t +{ + enum { + MIME_PREFIX, + MIME_SUFFIX, + MIME_NAME, + MIME_OTHER, + MIME_MAX + } type; + + qse_mchar_t* spec; + qse_mchar_t* value; + + struct mime_t* next; +}; + +struct access_t +{ + /* TODO: support more types like ACCESS_GLOB + not-only the base name, find a way to use query path or xpath */ + enum { + ACCESS_PREFIX, + ACCESS_SUFFIX, + ACCESS_NAME, + ACCESS_OTHER, + ACCESS_MAX + } type; + + qse_mchar_t* spec; + int value; + + struct access_t* next; +}; + + +typedef struct loccfg_t loccfg_t; +struct loccfg_t +{ + qse_mxstr_t locname; + + qse_mchar_t* xcfg[XCFG_MAX]; + int root_is_nwad; + qse_nwad_t root_nwad; + struct + { + qse_size_t count; + qse_mchar_t* files; + } index; + + struct + { + struct cgi_t* head; + struct cgi_t* tail; + } cgi[CGI_MAX]; + + struct + { + struct mime_t* head; + struct mime_t* tail; + } mime[MIME_MAX]; + + struct + { + struct access_t* head; + struct access_t* tail; + } access[2][ACCESS_MAX]; + + loccfg_t* next; +}; + +typedef struct server_hostcfg_t server_hostcfg_t; +struct server_hostcfg_t +{ + qse_mchar_t* hostname; + loccfg_t* loccfg; + server_hostcfg_t* next; +}; + +typedef struct server_xtn_t server_xtn_t; +struct server_xtn_t +{ + int tproxy; + int nodir; /* no directory listing */ + + int num; + qse_nwad_t bind; + int secure; + qse_mchar_t* scfg[SCFG_MAX]; + + qse_httpd_serverstd_makersrc_t orgmakersrc; + qse_httpd_serverstd_freersrc_t orgfreersrc; + qse_httpd_serverstd_query_t orgquery; + + qse_htb_t* cfgtab; +}; + +/* --------------------------------------------------------------------- */ + typedef struct httpd_xtn_t httpd_xtn_t; struct httpd_xtn_t { @@ -59,6 +191,8 @@ struct httpd_xtn_t qse_xli_t* xli; qse_httpd_impede_t orgimpede; int impede_code; + + loccfg_t dflcfg; }; /* --------------------------------------------------------------------- */ @@ -172,163 +306,6 @@ static int daemonize (int devnull) /* --------------------------------------------------------------------- */ -enum -{ - SCFG_SSLCERTFILE, - SCFG_SSLKEYFILE, - SCFG_MAX -}; - -enum -{ - XCFG_NAME, - XCFG_ROOT, - XCFG_REALM, - XCFG_AUTH, - XCFG_DIRCSS, - XCFG_ERRCSS, - XCFG_MAX -}; - -struct cgi_t -{ - enum { - CGI_PREFIX, - CGI_SUFFIX, - CGI_NAME, - CGI_MAX - } type; - - qse_mchar_t* spec; - int nph; - qse_mchar_t* shebang; - - struct cgi_t* next; -}; - -struct mime_t -{ - enum { - MIME_PREFIX, - MIME_SUFFIX, - MIME_NAME, - MIME_OTHER, - MIME_MAX - } type; - - qse_mchar_t* spec; - qse_mchar_t* value; - - struct mime_t* next; -}; - -struct access_t -{ - /* TODO: support more types like ACCESS_GLOB - not-only the base name, find a way to use query path or xpath */ - enum { - ACCESS_PREFIX, - ACCESS_SUFFIX, - ACCESS_NAME, - ACCESS_OTHER, - ACCESS_MAX - } type; - - qse_mchar_t* spec; - int value; - - struct access_t* next; -}; - - -typedef struct server_loccfg_t server_loccfg_t; -struct server_loccfg_t -{ - qse_mchar_t* locname; - - qse_mchar_t* xcfg[XCFG_MAX]; - int root_is_nwad; - qse_nwad_t root_nwad; - struct - { - qse_size_t count; - qse_mchar_t* files; - } index; - - struct - { - struct cgi_t* head; - struct cgi_t* tail; - } cgi[CGI_MAX]; - - struct - { - struct mime_t* head; - struct mime_t* tail; - } mime[MIME_MAX]; - - struct - { - struct access_t* head; - struct access_t* tail; - } access[2][ACCESS_MAX]; - - server_loccfg_t* next; -}; - -typedef struct server_hostcfg_t server_hostcfg_t; -struct server_hostcfg_t -{ - qse_mchar_t* hostname; - server_loccfg_t* loccfg; - server_hostcfg_t* next; -}; - -typedef struct server_xtn_t server_xtn_t; -struct server_xtn_t -{ - int tproxy; - int nodir; /* no directory listing */ - - int num; - qse_nwad_t bind; - int secure; - qse_mchar_t* scfg[SCFG_MAX]; - - qse_httpd_serverstd_makersrc_t orgmakersrc; - qse_httpd_serverstd_freersrc_t orgfreersrc; - qse_httpd_serverstd_query_t orgquery; - - qse_htb_t cfgtab; - - /* ---------------------------------------------- */ - qse_mchar_t* xcfg[XCFG_MAX]; - int root_is_nwad; - qse_nwad_t root_nwad; - struct - { - qse_size_t count; - qse_mchar_t* files; - } index; - - struct - { - struct cgi_t* head; - struct cgi_t* tail; - } cgi[CGI_MAX]; - - struct - { - struct mime_t* head; - struct mime_t* tail; - } mime[MIME_MAX]; - - struct - { - struct access_t* head; - struct access_t* tail; - } access[2][ACCESS_MAX]; -}; static int make_resource ( qse_httpd_t* httpd, qse_httpd_client_t* client, @@ -394,128 +371,102 @@ static void free_resource ( } } /* --------------------------------------------------------------------- */ -static void clear_server_config (qse_httpd_t* httpd, qse_httpd_server_t* server) + +static loccfg_t* find_loccfg ( + qse_httpd_t* httpd, qse_htb_t* cfgtab, + const qse_mchar_t* host, const qse_mchar_t* qpath) { - server_xtn_t* server_xtn; - qse_size_t i, j; + qse_htb_pair_t* pair; + server_hostcfg_t* hostcfg; + loccfg_t* loccfg; - server_xtn = qse_httpd_getserverstdxtn (httpd, server); - - for (i = 0; i < QSE_COUNTOF(server_xtn->scfg); i++) + pair = qse_htb_search (cfgtab, host, qse_mbslen(host)); + if (pair) { - if (server_xtn->scfg[i]) + hostcfg = (server_hostcfg_t*)QSE_HTB_VPTR(pair); + + /* the location names are inspected in the order as shown + * in the configuration. */ + for (loccfg = hostcfg->loccfg; loccfg; loccfg = loccfg->next) { - qse_httpd_freemem (httpd, server_xtn->scfg[i]); - server_xtn->scfg[i] = QSE_NULL; + if (qse_mbsbeg (qpath, loccfg->locname.ptr) && + (qpath[loccfg->locname.len] == QSE_MT('/') || + qpath[loccfg->locname.len] == QSE_MT('\0'))) return loccfg; } } - for (i = 0; i < QSE_COUNTOF(server_xtn->xcfg); i++) - { - if (server_xtn->xcfg[i]) - { - qse_httpd_freemem (httpd, server_xtn->xcfg[i]); - server_xtn->xcfg[i] = QSE_NULL; - } - } - - if (server_xtn->index.files) - { - qse_httpd_freemem (httpd, server_xtn->index.files); - server_xtn->index.files = QSE_NULL; - server_xtn->index.count = 0; - } - - for (i = 0; i < QSE_COUNTOF(server_xtn->cgi); i++) - { - struct cgi_t* cgi = server_xtn->cgi[i].head; - while (cgi) - { - struct cgi_t* x = cgi; - cgi = x->next; - - if (x->shebang) qse_httpd_freemem (httpd, x->shebang); - if (x->spec) qse_httpd_freemem (httpd, x->spec); - if (x) qse_httpd_freemem (httpd, x); - } - - server_xtn->cgi[i].head = QSE_NULL; - server_xtn->cgi[i].tail = QSE_NULL; - } - - for (i = 0; i < QSE_COUNTOF(server_xtn->mime); i++) - { - struct mime_t* mime = server_xtn->mime[i].head; - while (mime) - { - struct mime_t* x = mime; - mime = x->next; - - if (x->spec) qse_httpd_freemem (httpd, x->spec); - if (x->value) qse_httpd_freemem (httpd, x->value); - if (x) qse_httpd_freemem (httpd, x); - } - - server_xtn->mime[i].head = QSE_NULL; - server_xtn->mime[i].tail = QSE_NULL; - } - - for (j = 0; j < QSE_COUNTOF(server_xtn->access); j++) - { - for (i = 0; i < QSE_COUNTOF(server_xtn->access[j]); i++) - { - struct access_t* access = server_xtn->access[j][i].head; - while (access) - { - struct access_t* x = access; - access = x->next; - - if (x->spec) qse_httpd_freemem (httpd, x->spec); - if (x) qse_httpd_freemem (httpd, x); - } - - server_xtn->access[j][i].head = QSE_NULL; - server_xtn->access[j][i].tail = QSE_NULL; - } - } + return QSE_NULL; } -static void detach_server (qse_httpd_t* httpd, qse_httpd_server_t* server) -{ - clear_server_config (httpd, server); -} static int query_server ( qse_httpd_t* httpd, qse_httpd_server_t* server, qse_htre_t* req, const qse_mchar_t* xpath, qse_httpd_serverstd_query_code_t code, void* result) { + httpd_xtn_t* httpd_xtn; server_xtn_t* server_xtn; + loccfg_t* loccfg = QSE_NULL; + httpd_xtn = qse_httpd_getxtnstd (httpd); server_xtn = qse_httpd_getserverstdxtn (httpd, server); + if (code == QSE_HTTPD_SERVERSTD_SSL) + { + /* SSL is a server-wide configuration item. + * handle this without inspecting the host and the query path. */ + qse_httpd_serverstd_ssl_t* ssl; + ssl = (qse_httpd_serverstd_ssl_t*)result; + ssl->certfile = server_xtn->scfg[SCFG_SSLCERTFILE]; + ssl->keyfile = server_xtn->scfg[SCFG_SSLKEYFILE]; + return 0; + } + + if (req) + { + const qse_htre_hdrval_t* hosthdr; + + const qse_mchar_t* host; + const qse_mchar_t* qpath; + + qpath = qse_htre_getqpath (req); + + hosthdr = qse_htre_getheaderval (req, QSE_MT("Host")); + if (hosthdr) + { + /* take the last host value and search */ + while (hosthdr->next) hosthdr = hosthdr->next; + host = hosthdr->ptr; + loccfg = find_loccfg (httpd, server_xtn->cfgtab, host, qpath); + } + if (loccfg == QSE_NULL) loccfg = find_loccfg (httpd, server_xtn->cfgtab, QSE_MT("*"), qpath); + } + if (loccfg == QSE_NULL) loccfg = find_loccfg (httpd, server_xtn->cfgtab, QSE_MT("*"), QSE_MT("/")); + if (loccfg == QSE_NULL) loccfg = &httpd_xtn->dflcfg; + switch (code) { case QSE_HTTPD_SERVERSTD_NAME: - *(const qse_mchar_t**)result = server_xtn->xcfg[XCFG_NAME]; + *(const qse_mchar_t**)result = loccfg->xcfg[XCFG_NAME]; return 0; case QSE_HTTPD_SERVERSTD_ROOT: - if (server_xtn->root_is_nwad) + if (loccfg->root_is_nwad) { ((qse_httpd_serverstd_root_t*)result)->type = QSE_HTTPD_SERVERSTD_ROOT_NWAD; - ((qse_httpd_serverstd_root_t*)result)->u.nwad = server_xtn->root_nwad; + ((qse_httpd_serverstd_root_t*)result)->u.nwad = loccfg->root_nwad; } else { ((qse_httpd_serverstd_root_t*)result)->type = QSE_HTTPD_SERVERSTD_ROOT_PATH; - ((qse_httpd_serverstd_root_t*)result)->u.path = server_xtn->xcfg[XCFG_ROOT]; + ((qse_httpd_serverstd_root_t*)result)->u.path.val = loccfg->xcfg[XCFG_ROOT]; + ((qse_httpd_serverstd_root_t*)result)->u.path.rpl = loccfg->locname.len; } return 0; case QSE_HTTPD_SERVERSTD_REALM: - ((qse_httpd_serverstd_realm_t*)result)->name = server_xtn->xcfg[XCFG_REALM]; - ((qse_httpd_serverstd_realm_t*)result)->authreq = (server_xtn->xcfg[XCFG_REALM] != QSE_NULL); + ((qse_httpd_serverstd_realm_t*)result)->name = loccfg->xcfg[XCFG_REALM]; + ((qse_httpd_serverstd_realm_t*)result)->authreq = (loccfg->xcfg[XCFG_REALM] != QSE_NULL); return 0; case QSE_HTTPD_SERVERSTD_AUTH: @@ -525,9 +476,9 @@ static int query_server ( auth = (qse_httpd_serverstd_auth_t*)result; auth->authok = 0; - if (server_xtn->xcfg[XCFG_AUTH]) + if (loccfg->xcfg[XCFG_AUTH]) { - if (qse_mbsxcmp (auth->key.ptr, auth->key.len, server_xtn->xcfg[XCFG_AUTH]) == 0) + if (qse_mbsxcmp (auth->key.ptr, auth->key.len, loccfg->xcfg[XCFG_AUTH]) == 0) { auth->authok = 1; } @@ -536,16 +487,16 @@ static int query_server ( } case QSE_HTTPD_SERVERSTD_DIRCSS: - *(const qse_mchar_t**)result = server_xtn->xcfg[XCFG_DIRCSS]; + *(const qse_mchar_t**)result = loccfg->xcfg[XCFG_DIRCSS]; return 0; case QSE_HTTPD_SERVERSTD_ERRCSS: - *(const qse_mchar_t**)result = server_xtn->xcfg[XCFG_ERRCSS]; + *(const qse_mchar_t**)result = loccfg->xcfg[XCFG_ERRCSS]; return 0; case QSE_HTTPD_SERVERSTD_INDEX: - ((qse_httpd_serverstd_index_t*)result)->count = server_xtn->index.count; - ((qse_httpd_serverstd_index_t*)result)->files = server_xtn->index.files; + ((qse_httpd_serverstd_index_t*)result)->count = loccfg->index.count; + ((qse_httpd_serverstd_index_t*)result)->files = loccfg->index.files; return 0; case QSE_HTTPD_SERVERSTD_CGI: @@ -559,10 +510,10 @@ static int query_server ( scgi = (qse_httpd_serverstd_cgi_t*)result; qse_memset (scgi, 0, QSE_SIZEOF(*scgi)); - for (i = 0; i < QSE_COUNTOF(server_xtn->cgi); i++) + for (i = 0; i < QSE_COUNTOF(loccfg->cgi); i++) { struct cgi_t* cgi; - for (cgi = server_xtn->cgi[i].head; cgi; cgi = cgi->next) + for (cgi = loccfg->cgi[i].head; cgi; cgi = cgi->next) { if ((cgi->type == CGI_PREFIX && qse_mbsbeg (xpath_base, cgi->spec)) || (cgi->type == CGI_SUFFIX && qse_mbsend (xpath_base, cgi->spec)) || @@ -587,10 +538,10 @@ static int query_server ( xpath_base = qse_mbsbasename (xpath); *(const qse_mchar_t**)result = QSE_NULL; - for (i = 0; i < QSE_COUNTOF(server_xtn->mime); i++) + for (i = 0; i < QSE_COUNTOF(loccfg->mime); i++) { struct mime_t* mime; - for (mime = server_xtn->mime[i].head; mime; mime = mime->next) + for (mime = loccfg->mime[i].head; mime; mime = mime->next) { if ((mime->type == MIME_PREFIX && qse_mbsbeg (xpath_base, mime->spec)) || (mime->type == MIME_SUFFIX && qse_mbsend (xpath_base, mime->spec)) || @@ -617,10 +568,10 @@ static int query_server ( xpath_base = qse_mbsbasename (xpath); *(int*)result = 200; - for (i = 0; i < QSE_COUNTOF(server_xtn->access[id]); i++) + for (i = 0; i < QSE_COUNTOF(loccfg->access[id]); i++) { struct access_t* access; - for (access = server_xtn->access[id][i].head; access; access = access->next) + for (access = loccfg->access[id][i].head; access; access = access->next) { if ((access->type == ACCESS_PREFIX && qse_mbsbeg (xpath_base, access->spec)) || (access->type == ACCESS_SUFFIX && qse_mbsend (xpath_base, access->spec)) || @@ -634,16 +585,6 @@ static int query_server ( } return 0; } - - case QSE_HTTPD_SERVERSTD_SSL: - { - qse_httpd_serverstd_ssl_t* ssl; - ssl = (qse_httpd_serverstd_ssl_t*)result; - ssl->certfile = server_xtn->scfg[SCFG_SSLCERTFILE]; - ssl->keyfile = server_xtn->scfg[SCFG_SSLKEYFILE]; - return 0; - } - } return server_xtn->orgquery (httpd, server, req, xpath, code, result); @@ -661,310 +602,6 @@ static struct { QSE_T("ssl-key-file"), QSE_T("default.ssl-key-file") } }; -static struct -{ - const qse_char_t* x; - const qse_char_t* y; -} xcfg_items[] = -{ - { QSE_T("host['*'].location['/'].name"), QSE_T("default.name") }, - { QSE_T("host['*'].location['/'].root"), QSE_T("default.root") }, - { QSE_T("host['*'].location['/'].realm"), QSE_T("default.realm") }, - { QSE_T("host['*'].location['/'].auth"), QSE_T("default.auth") }, - { QSE_T("host['*'].location['/'].dir-css"), QSE_T("default.dir-css") }, - { QSE_T("host['*'].location['/'].error-css"), QSE_T("default.error-css") } -}; - -static struct -{ - const qse_char_t* x; - const qse_char_t* y; -} acc_items[] = -{ - { QSE_T("host['*'].location['/'].dir-access"), QSE_T("default.dir-access") }, - { QSE_T("host['*'].location['/'].file-access"), QSE_T("default.file-access") }, -}; - -static int load_server_config ( - qse_httpd_t* httpd, qse_httpd_server_t* server, qse_xli_list_t* list) -{ - qse_size_t i; - httpd_xtn_t* httpd_xtn; - server_xtn_t* server_xtn; - qse_xli_pair_t* pair; - qse_xli_atom_t* atom; - - httpd_xtn = qse_httpd_getxtnstd (httpd); - server_xtn = qse_httpd_getserverstdxtn (httpd, server); - - for (i = 0; i < QSE_COUNTOF(scfg_items); i++) - { - pair = qse_xli_findpairbyname (httpd_xtn->xli, list, scfg_items[i].x); - if (!pair) pair = qse_xli_findpairbyname (httpd_xtn->xli, QSE_NULL, scfg_items[i].y); - if (pair && pair->val->type == QSE_XLI_STR) - { - server_xtn->scfg[i] = qse_httpd_strtombsdup (httpd, ((qse_xli_str_t*)pair->val)->ptr); - if (server_xtn->scfg[i] == QSE_NULL) - { - /*qse_printf (QSE_T("ERROR in copying - %s\n"), qse_httpd_geterrmsg (httpd));*/ - qse_printf (QSE_T("ERROR in copying\n")); - return -1; - } - } - } - - for (i = 0; i < QSE_COUNTOF(xcfg_items); i++) - { - pair = qse_xli_findpairbyname (httpd_xtn->xli, list, xcfg_items[i].x); - if (!pair) pair = qse_xli_findpairbyname (httpd_xtn->xli, QSE_NULL, xcfg_items[i].y); - if (pair && pair->val->type == QSE_XLI_STR) - { - server_xtn->xcfg[i] = qse_httpd_strtombsdup (httpd, ((qse_xli_str_t*)pair->val)->ptr); - if (server_xtn->xcfg[i] == QSE_NULL) - { - /*qse_printf (QSE_T("ERROR in copying - %s\n"), qse_httpd_geterrmsg (httpd));*/ - qse_printf (QSE_T("ERROR in copying\n")); - return -1; - } - } - } - - pair = qse_xli_findpairbyname (httpd_xtn->xli, list, QSE_T("host['*'].location['/'].index")); - if (!pair) pair = qse_xli_findpairbyname (httpd_xtn->xli, QSE_NULL, QSE_T("default.index")); - if (pair && pair->val->type == QSE_XLI_STR) - { - const qse_char_t* tmpptr, * tmpend; - qse_size_t count; - - tmpptr = ((qse_xli_str_t*)pair->val)->ptr; - tmpend = tmpptr + ((qse_xli_str_t*)pair->val)->len; - - for (count = 0; tmpptr < tmpend; count++) tmpptr += qse_strlen (tmpptr) + 1; - - server_xtn->index.count = count; - server_xtn->index.files = qse_httpd_strntombsdup ( - httpd, ((qse_xli_str_t*)pair->val)->ptr, ((qse_xli_str_t*)pair->val)->len); - if (server_xtn->index.files == QSE_NULL) - { - qse_printf (QSE_T("ERROR: in copying index\n")); - return -1; - } - } - - pair = qse_xli_findpairbyname (httpd_xtn->xli, list, QSE_T("host['*'].location['/'].cgi")); - if (!pair) pair = qse_xli_findpairbyname (httpd_xtn->xli, QSE_NULL, QSE_T("default.cgi")); - if (pair && pair->val->type == QSE_XLI_LIST) - { - /* TODO: more sanity check... this can be done with xli schema... if supported */ - qse_xli_list_t* cgilist = (qse_xli_list_t*)pair->val; - for (atom = cgilist->head; atom; atom = atom->next) - { - if (atom->type != QSE_XLI_PAIR) continue; - - pair = (qse_xli_pair_t*)atom; - if (pair->key && pair->name && - (pair->val->type == QSE_XLI_NIL || pair->val->type == QSE_XLI_STR)) - { - struct cgi_t* cgi; - int type; - - if (qse_strcmp (pair->key, QSE_T("prefix")) == 0) type = CGI_PREFIX; - else if (qse_strcmp (pair->key, QSE_T("suffix")) == 0) type = CGI_SUFFIX; - else if (qse_strcmp (pair->key, QSE_T("name")) == 0) type = CGI_NAME; - else continue; - - cgi = qse_httpd_callocmem (httpd, QSE_SIZEOF(*cgi)); - if (cgi == QSE_NULL) - { - qse_printf (QSE_T("ERROR: memory failure in copying cgi\n")); - return -1; - } - - cgi->type = type; - cgi->spec = qse_httpd_strtombsdup (httpd, pair->name); - if (!cgi->spec) - { - qse_httpd_freemem (httpd, cgi); - qse_printf (QSE_T("ERROR: memory failure in copying cgi\n")); - return -1; - } - if (pair->val->type == QSE_XLI_STR) - { - const qse_char_t* tmpptr, * tmpend; - qse_size_t count; - - tmpptr = ((qse_xli_str_t*)pair->val)->ptr; - tmpend = tmpptr + ((qse_xli_str_t*)pair->val)->len; - - for (count = 0; tmpptr < tmpend; count++) - { - if (count == 0) - { - if (qse_strcmp (tmpptr, QSE_T("nph")) == 0) cgi->nph = 1; - } - else if (count == 1) - { - cgi->shebang = qse_httpd_strtombsdup (httpd, tmpptr); - if (!cgi->shebang) - { - qse_httpd_freemem (httpd, cgi->spec); - qse_httpd_freemem (httpd, cgi); - qse_printf (QSE_T("ERROR: memory failure in copying cgi\n")); - return -1; - } - } - - tmpptr += qse_strlen (tmpptr) + 1; - - /* TODO: more sanity check */ - } - - } - if (server_xtn->cgi[type].tail) - server_xtn->cgi[type].tail->next = cgi; - else - server_xtn->cgi[type].head = cgi; - server_xtn->cgi[type].tail = cgi; - } - } - } - - pair = qse_xli_findpairbyname (httpd_xtn->xli, list, QSE_T("host['*'].location['/'].mime")); - if (!pair) pair = qse_xli_findpairbyname (httpd_xtn->xli, QSE_NULL, QSE_T("default.mime")); - if (pair && pair->val->type == QSE_XLI_LIST) - { - qse_xli_list_t* mimelist = (qse_xli_list_t*)pair->val; - for (atom = mimelist->head; atom; atom = atom->next) - { - if (atom->type != QSE_XLI_PAIR) continue; - - pair = (qse_xli_pair_t*)atom; - if (pair->key && pair->val->type == QSE_XLI_STR) - { - struct mime_t* mime; - int type; - - if (qse_strcmp (pair->key, QSE_T("prefix")) == 0 && pair->name) type = MIME_PREFIX; - else if (qse_strcmp (pair->key, QSE_T("suffix")) == 0 && pair->name) type = MIME_SUFFIX; - else if (qse_strcmp (pair->key, QSE_T("name")) == 0 && pair->name) type = MIME_NAME; - else if (qse_strcmp (pair->key, QSE_T("other")) == 0 && !pair->name) type = MIME_OTHER; - else continue; - - mime = qse_httpd_callocmem (httpd, QSE_SIZEOF(*mime)); - if (mime == QSE_NULL) - { - qse_printf (QSE_T("ERROR: memory failure in copying mime\n")); - return -1; - } - - mime->type = type; - mime->spec = qse_httpd_strtombsdup (httpd, pair->name); - if (!mime->spec) - { - qse_httpd_freemem (httpd, mime); - qse_printf (QSE_T("ERROR: memory failure in copying mime\n")); - return -1; - } - - mime->value = qse_httpd_strtombsdup (httpd, ((qse_xli_str_t*)pair->val)->ptr); - if (!mime->value) - { - qse_httpd_freemem (httpd, mime->spec); - qse_httpd_freemem (httpd, mime); - qse_printf (QSE_T("ERROR: memory failure in copying mime\n")); - return -1; - } - - if (server_xtn->mime[type].tail) - server_xtn->mime[type].tail->next = mime; - else - server_xtn->mime[type].head = mime; - server_xtn->mime[type].tail = mime; - } - } - } - - for (i = 0; i < 2; i++) - { - - pair = qse_xli_findpairbyname (httpd_xtn->xli, list, acc_items[i].x); - if (!pair) pair = qse_xli_findpairbyname (httpd_xtn->xli, QSE_NULL, acc_items[i].y); - if (pair && pair->val->type == QSE_XLI_LIST) - { - qse_xli_list_t* acclist = (qse_xli_list_t*)pair->val; - for (atom = acclist->head; atom; atom = atom->next) - { - if (atom->type != QSE_XLI_PAIR) continue; - - pair = (qse_xli_pair_t*)atom; - if (pair->key && pair->val->type == QSE_XLI_STR) - { - struct access_t* acc; - const qse_char_t* tmp; - int type, value; - - if (qse_strcmp (pair->key, QSE_T("prefix")) == 0 && pair->name) type = ACCESS_PREFIX; - else if (qse_strcmp (pair->key, QSE_T("suffix")) == 0 && pair->name) type = ACCESS_SUFFIX; - else if (qse_strcmp (pair->key, QSE_T("name")) == 0 && pair->name) type = ACCESS_NAME; - else if (qse_strcmp (pair->key, QSE_T("other")) == 0 && !pair->name) type = ACCESS_OTHER; - else continue; - - tmp = ((qse_xli_str_t*)pair->val)->ptr; - if (qse_strcmp (tmp, QSE_T("noent")) == 0) value = 404; - else if (qse_strcmp (tmp, QSE_T("forbid")) == 0) value = 403; - else if (qse_strcmp (tmp, QSE_T("ok")) == 0) value = 200; - else continue; - /* TODO: more sanity check */ - - acc = qse_httpd_callocmem (httpd, QSE_SIZEOF(*acc)); - if (acc == QSE_NULL) - { - qse_printf (QSE_T("ERROR: memory failure in copying acc\n")); - return -1; - } - - acc->type = type; - if (pair->name) - { - acc->spec = qse_httpd_strtombsdup (httpd, pair->name); - if (!acc->spec) - { - qse_httpd_freemem (httpd, acc); - qse_printf (QSE_T("ERROR: memory failure in copying access\n")); - return -1; - } - } - acc->value = value; - - if (server_xtn->access[i][type].tail) - server_xtn->access[i][type].tail->next = acc; - else - server_xtn->access[i][type].head = acc; - server_xtn->access[i][type].tail = acc; - } - } - } - } - - /* perform more sanity check */ -/* TODO: support multiple auth entries here and above */ -#if 0 - if (qse_mbschr (server_xtn->xcfg[XCFG_AUTH], QSE_MT(':')) == QSE_NULL) - { - qse_printf (QSE_T("WARNING: no colon in the auth string - [%hs]\n"), server_xtn->xcfg[XCFG_AUTH]); - } -#endif - - if (server_xtn->xcfg[XCFG_ROOT] && - qse_mbstonwad (server_xtn->xcfg[XCFG_ROOT], &server_xtn->root_nwad) >= 0) - { - server_xtn->root_is_nwad = 1; - } - - return 0; -} - - static struct { const qse_char_t* x; @@ -989,7 +626,7 @@ static struct { QSE_T("file-access"), QSE_T("default.file-access") } }; -static void free_server_loccfg (qse_httpd_t* httpd, server_loccfg_t* loccfg) +static void free_loccfg_contents (qse_httpd_t* httpd, loccfg_t* loccfg) { qse_size_t i, j; @@ -1062,26 +699,10 @@ static void free_server_loccfg (qse_httpd_t* httpd, server_loccfg_t* loccfg) } } - qse_httpd_freemem (httpd, loccfg->locname); - qse_httpd_freemem (httpd, loccfg); + if (loccfg->locname.ptr) qse_httpd_freemem (httpd, loccfg->locname.ptr); } -static void free_server_hostcfg (qse_httpd_t* httpd, server_hostcfg_t* hostcfg) -{ - server_loccfg_t* lc, * cur; - - lc = hostcfg->loccfg; - while (lc) - { - cur = lc; - lc = lc->next; - free_server_loccfg (httpd, cur); - } - qse_httpd_freemem (httpd, hostcfg->hostname); - qse_httpd_freemem (httpd, hostcfg); -} - -static int load_server_loccfg (qse_httpd_t* httpd, qse_xli_list_t* list, server_loccfg_t* cfg) +static int load_loccfg (qse_httpd_t* httpd, qse_xli_list_t* list, loccfg_t* cfg) { qse_size_t i; qse_xli_pair_t* pair; @@ -1106,7 +727,7 @@ static int load_server_loccfg (qse_httpd_t* httpd, qse_xli_list_t* list, server_ } } - pair = qse_xli_findpairbyname (httpd_xtn->xli, list, QSE_T("host['*'].location['/'].index")); + pair = qse_xli_findpairbyname (httpd_xtn->xli, list, QSE_T("index")); if (!pair) pair = qse_xli_findpairbyname (httpd_xtn->xli, QSE_NULL, QSE_T("default.index")); if (pair && pair->val->type == QSE_XLI_STR) { @@ -1128,7 +749,7 @@ static int load_server_loccfg (qse_httpd_t* httpd, qse_xli_list_t* list, server_ } } - pair = qse_xli_findpairbyname (httpd_xtn->xli, list, QSE_T("host['*'].location['/'].cgi")); + pair = qse_xli_findpairbyname (httpd_xtn->xli, list, QSE_T("cgi")); if (!pair) pair = qse_xli_findpairbyname (httpd_xtn->xli, QSE_NULL, QSE_T("default.cgi")); if (pair && pair->val->type == QSE_XLI_LIST) { @@ -1206,7 +827,7 @@ static int load_server_loccfg (qse_httpd_t* httpd, qse_xli_list_t* list, server_ } } - pair = qse_xli_findpairbyname (httpd_xtn->xli, list, QSE_T("host['*'].location['/'].mime")); + pair = qse_xli_findpairbyname (httpd_xtn->xli, list, QSE_T("mime")); if (!pair) pair = qse_xli_findpairbyname (httpd_xtn->xli, QSE_NULL, QSE_T("default.mime")); if (pair && pair->val->type == QSE_XLI_LIST) { @@ -1341,43 +962,119 @@ static int load_server_loccfg (qse_httpd_t* httpd, qse_xli_list_t* list, server_ return 0; } -static int load_server_hostcfg (qse_httpd_t* httpd, qse_httpd_server_t* server, qse_xli_list_t* list) +static void free_server_hostcfg (qse_httpd_t* httpd, server_hostcfg_t* hostcfg) +{ + loccfg_t* lc, * cur; + + lc = hostcfg->loccfg; + while (lc) + { + cur = lc; + lc = lc->next; + + free_loccfg_contents (httpd, cur); + qse_httpd_freemem (httpd, cur); + } + + if (hostcfg->hostname) qse_httpd_freemem (httpd, hostcfg->hostname); + qse_httpd_freemem (httpd, hostcfg); +} + +static void free_cfgtab_value (qse_htb_t* htb, void* vptr, qse_size_t vlen) +{ + qse_httpd_t* httpd; + httpd = *(qse_httpd_t**) qse_htb_getxtn(htb); + free_server_hostcfg (httpd, (server_hostcfg_t*)vptr); +} + +static int load_server_config (qse_httpd_t* httpd, qse_httpd_server_t* server, qse_xli_list_t* list) { qse_size_t i, j, host_count, loc_count; - qse_xli_pair_t* host, * loc; httpd_xtn_t* httpd_xtn; server_xtn_t* server_xtn; - qse_char_t buf[32]; server_hostcfg_t* hostcfg; - server_loccfg_t* loccfg; + loccfg_t* loccfg; + + static qse_htb_style_t cfgtab_style = + { + { + QSE_HTB_COPIER_DEFAULT, + QSE_HTB_COPIER_DEFAULT + }, + { + QSE_HTB_FREEER_DEFAULT, + free_cfgtab_value + }, + QSE_HTB_COMPER_DEFAULT, + QSE_HTB_KEEPER_DEFAULT, + QSE_HTB_SIZER_DEFAULT, + QSE_HTB_HASHER_DEFAULT + }; httpd_xtn = qse_httpd_getxtnstd (httpd); server_xtn = qse_httpd_getserverstdxtn (httpd, server); + /* load the server-wide configuration not specific to host/location */ + for (i = 0; i < SCFG_MAX; i++) + { + qse_xli_pair_t* pair; + + pair = qse_xli_findpairbyname (httpd_xtn->xli, list, scfg_items[i].x); + if (!pair) pair = qse_xli_findpairbyname (httpd_xtn->xli, QSE_NULL, scfg_items[i].y); + if (pair && pair->val->type == QSE_XLI_STR) + { + server_xtn->scfg[i] = qse_httpd_strtombsdup (httpd, ((qse_xli_str_t*)pair->val)->ptr); + if (server_xtn->scfg[i] == QSE_NULL) + { + /*qse_printf (QSE_T("ERROR in copying - %s\n"), qse_httpd_geterrmsg (httpd));*/ + qse_printf (QSE_T("ERROR in copying\n")); + return -1; + } + } + } + + /* load host/location specific configuration */ host_count = qse_xli_getnumpairsbyname (httpd_xtn->xli, list, QSE_T("host")); if (host_count <= 0) return 0; /* nothing to load */ - qse_htb_init (&server_xtn->cfgtab, qse_httpd_getmmgr (httpd), host_count + (host_count / 3) + 1, 70, 0, 0); + QSE_ASSERT (server_xtn->cfgtab == QSE_NULL); + server_xtn->cfgtab = qse_htb_open ( + qse_httpd_getmmgr (httpd), QSE_SIZEOF(httpd), + host_count + (host_count / 3) + 1, 70, QSE_SIZEOF(qse_mchar_t), 0); + if (server_xtn->cfgtab == QSE_NULL) + { + /* TOOD: print error */ + return -1; + } + + /* store the back reference into the configuration table */ + *(qse_httpd_t**)qse_htb_getxtn (server_xtn->cfgtab) = httpd; + qse_htb_setstyle (server_xtn->cfgtab, &cfgtab_style); for (i = 0; i < host_count; i++) { + qse_xli_pair_t* host; + qse_char_t buf[32]; + qse_sprintf (buf, QSE_COUNTOF(buf), QSE_T("host[%d]"), i); host = qse_xli_findpairbyname (httpd_xtn->xli, list, buf); if (!host) break; if (host->val->type == QSE_XLI_LIST && host->name) { - loc_count = qse_xli_getnumpairsbyname (httpd_xtn->xli, host->val, QSE_T("location")); + loc_count = qse_xli_getnumpairsbyname (httpd_xtn->xli, (qse_xli_list_t*)host->val, QSE_T("location")); - hostcfg = qse_httpd_callocmem (httpd, QSE_SIZEOF(*hostcfg)); - if (hostcfg == QSE_NULL) return -1; + if (((hostcfg = qse_httpd_callocmem (httpd, QSE_SIZEOF(*hostcfg))) == QSE_NULL) || + ((hostcfg->hostname = qse_httpd_strtombsdup (httpd, host->name)) == QSE_NULL)) goto oops; for (j = loc_count; j > 0; ) { + qse_xli_pair_t* loc; + j--; qse_sprintf (buf, QSE_COUNTOF(buf), QSE_T("location[%d]"), j); - loc = qse_xli_findpairbyname (httpd_xtn->xli, host->val, buf); + loc = qse_xli_findpairbyname (httpd_xtn->xli, (qse_xli_list_t*)host->val, buf); if (!loc) break; if (loc->val->type == QSE_XLI_LIST && loc->name) @@ -1385,28 +1082,25 @@ static int load_server_hostcfg (qse_httpd_t* httpd, qse_httpd_server_t* server, loccfg = qse_httpd_callocmem (httpd, QSE_SIZEOF(*loccfg)); if (loccfg == QSE_NULL) goto oops; - hostcfg->loccfg = loccfg; + /* just chain it before loading the actual data */ loccfg->next = hostcfg->loccfg; + hostcfg->loccfg = loccfg; - if (load_server_loccfg (httpd, loc, loccfg) <= -1) goto oops; + /* load the data now */ + if (load_loccfg (httpd, (qse_xli_list_t*)loc->val, loccfg) <= -1) goto oops; - loccfg->locname = qse_httpd_strtombsdup (httpd, loc->name); - if (loccfg->locname == QSE_NULL) goto oops; + /* clone the location name */ + loccfg->locname.ptr = qse_httpd_strtombsdup (httpd, loc->name); + if (loccfg->locname.ptr == QSE_NULL) goto oops; + + loccfg->locname.len = qse_mbslen (loccfg->locname.ptr); } } - if (hostcfg->loccfg) + if (qse_htb_upsert (server_xtn->cfgtab, hostcfg->hostname, qse_mbslen(hostcfg->hostname), hostcfg, 0) == QSE_NULL) { - hostcfg->hostname = qse_httpd_strtombsdup (httpd, host->name); - if (hostcfg->hostname == QSE_NULL) goto oops; - - if (qse_htb_insert (&server_xtn->cfgtab, hostcfg->hostname, 0, hostcfg, 0) == QSE_NULL) goto oops; - } - else - { - /* no location configuration found in the host configuration */ - qse_httpd_freemem (httpd, hostcfg); - hostcfg = QSE_NULL; + /* TODO: print error */ + goto oops; } } } @@ -1418,6 +1112,29 @@ oops: return -1; } +static void free_server_config (qse_httpd_t* httpd, qse_httpd_server_t* server) +{ + server_xtn_t* server_xtn; + qse_size_t i; + + server_xtn = qse_httpd_getserverstdxtn (httpd, server); + + for (i = 0; i < SCFG_MAX; i++) + { + if (server_xtn->scfg[i]) + { + qse_httpd_freemem (httpd, server_xtn->scfg[i]); + server_xtn->scfg[i] = QSE_NULL; + } + } + + if (server_xtn->cfgtab) + { + qse_htb_close (server_xtn->cfgtab); + server_xtn->cfgtab = QSE_NULL; + } +} + static qse_httpd_server_t* attach_server (qse_httpd_t* httpd, int num, qse_xli_list_t* list) { qse_httpd_server_dope_t dope; @@ -1448,7 +1165,7 @@ static qse_httpd_server_t* attach_server (qse_httpd_t* httpd, int num, qse_xli_l if (!pair) pair = qse_xli_findpairbyname (httpd_xtn->xli, QSE_NULL, QSE_T("default.ssl")); if (pair && pair->val->type == QSE_XLI_STR) dope.flags |= QSE_HTTPD_SERVER_SECURE; - dope.detach = detach_server; + dope.detach = free_server_config; xserver = qse_httpd_attachserverstd (httpd, &dope, QSE_SIZEOF(server_xtn_t)); if (xserver == QSE_NULL) { @@ -1528,7 +1245,6 @@ static int close_config_file (qse_httpd_t* httpd) static int load_config (qse_httpd_t* httpd) { - qse_xli_iostd_t xli_in; qse_xli_pair_t* pair; httpd_xtn_t* httpd_xtn; int i; @@ -1555,20 +1271,32 @@ static int load_config (qse_httpd_t* httpd) server = attach_server (httpd, i, (qse_xli_list_t*)pair->val); if (server) { - load_server_config (httpd, server, (qse_xli_list_t*)pair->val); - /* TODO: error check */ - load_server_hostcfg (httpd, server, (qse_xli_list_t*)pair->val); - /* TODO: error check */ + if (load_server_config (httpd, server, (qse_xli_list_t*)pair->val) <= -1) + { + qse_fprintf (QSE_STDERR, QSE_T("failed to load configuration from %s\n"), httpd_xtn->cfgfile); + goto oops; + } } } } if (i == 0) { - qse_fprintf (QSE_STDERR, QSE_T("No valid server specified in %s\n"), xli_in.u.file.path); + qse_fprintf (QSE_STDERR, QSE_T("No valid server specified in %s\n"), httpd_xtn->cfgfile); goto oops; } + /* load the global default */ + pair = qse_xli_findpairbyname (httpd_xtn->xli, QSE_NULL, QSE_T("default")); + if (pair && pair->val->type == QSE_XLI_LIST) + { + if (load_loccfg (httpd, (qse_xli_list_t*)pair->val, &httpd_xtn->dflcfg) <= -1) + { + qse_fprintf (QSE_STDERR, QSE_T("failed to load configuration from %s\n"), httpd_xtn->cfgfile); + goto oops; + } + } + pair = qse_xli_findpairbyname (httpd_xtn->xli, QSE_NULL, QSE_T("default.name")); if (pair && pair->val->type == QSE_XLI_STR) { @@ -1612,7 +1340,7 @@ static void reconf_server (qse_httpd_t* httpd, qse_httpd_server_t* server) if (pair && pair->val->type == QSE_XLI_LIST) { - clear_server_config (httpd, server); + free_server_config (httpd, server); load_server_config (httpd, server, (qse_xli_list_t*)pair->val); } } @@ -1797,6 +1525,13 @@ wrongusage: return -1; } +static void free_httpd_xtn (qse_httpd_t* httpd) +{ + httpd_xtn_t* httpd_xtn; + httpd_xtn = qse_httpd_getxtnstd (httpd); + free_loccfg_contents (httpd, &httpd_xtn->dflcfg); +} + static int httpd_main (int argc, qse_char_t* argv[]) { qse_httpd_t* httpd = QSE_NULL; @@ -1804,6 +1539,7 @@ static int httpd_main (int argc, qse_char_t* argv[]) qse_ntime_t tmout; int trait, ret; qse_httpd_rcb_t rcb; + qse_httpd_ecb_t ecb; ret = handle_args (argc, argv); if (ret <= -1) return -1; @@ -1816,6 +1552,9 @@ static int httpd_main (int argc, qse_char_t* argv[]) goto oops; } + qse_memset (&ecb, 0, QSE_SIZEOF(ecb)); + ecb.close = free_httpd_xtn; + qse_httpd_pushecb (httpd, &ecb); httpd_xtn = qse_httpd_getxtnstd (httpd); httpd_xtn->cfgfile = g_cfgfile; diff --git a/qse/include/qse/cmn/htb.h b/qse/include/qse/cmn/htb.h index 57f8da76..4ed556da 100644 --- a/qse/include/qse/cmn/htb.h +++ b/qse/include/qse/cmn/htb.h @@ -49,7 +49,7 @@ * int i; * * s1 = qse_htb_open (QSE_MMGR_GETDFL(), 0, 30, 75, 1, 1); // error handling skipped - * qse_htb_setmancbs (s1, qse_gethtbmancbs(QSE_HTB_MANCBS_INLINE_COPIERS)); + * qse_htb_setstyle (s1, qse_gethtbstyle(QSE_HTB_STYLE_INLINE_COPIERS)); * * for (i = 0; i < 20; i++) * { @@ -202,9 +202,9 @@ struct qse_htb_pair_t qse_htb_pair_t* next; }; -typedef struct qse_htb_mancbs_t qse_htb_mancbs_t; +typedef struct qse_htb_style_t qse_htb_style_t; -struct qse_htb_mancbs_t +struct qse_htb_style_t { qse_htb_copier_t copier[2]; qse_htb_freeer_t freeer[2]; @@ -215,22 +215,22 @@ struct qse_htb_mancbs_t }; /** - * The qse_htb_mancbs_kind_t type defines the type of predefined + * The qse_htb_style_kind_t type defines the type of predefined * callback set for pair manipulation. */ -enum qse_htb_mancbs_kind_t +enum qse_htb_style_kind_t { /** store the key and the value pointer */ - QSE_HTB_MANCBS_DEFAULT, + QSE_HTB_STYLE_DEFAULT, /** copy both key and value into the pair */ - QSE_HTB_MANCBS_INLINE_COPIERS, + QSE_HTB_STYLE_INLINE_COPIERS, /** copy the key into the pair but store the value pointer */ - QSE_HTB_MANCBS_INLINE_KEY_COPIER, + QSE_HTB_STYLE_INLINE_KEY_COPIER, /** copy the value into the pair but store the key pointer */ - QSE_HTB_MANCBS_INLINE_VALUE_COPIER + QSE_HTB_STYLE_INLINE_VALUE_COPIER }; -typedef enum qse_htb_mancbs_kind_t qse_htb_mancbs_kind_t; +typedef enum qse_htb_style_kind_t qse_htb_style_kind_t; /** * The qse_htb_t type defines a hash table. @@ -239,7 +239,7 @@ struct qse_htb_t { qse_mmgr_t* mmgr; - const qse_htb_mancbs_t* mancbs; + const qse_htb_style_t* style; qse_byte_t scale[2]; /**< length scale */ qse_byte_t factor; /**< load factor in percentage */ @@ -300,11 +300,11 @@ extern "C" { #endif /** - * The qse_gethtbmancbs() functions returns a predefined callback set for + * The qse_gethtbstyle() functions returns a predefined callback set for * pair manipulation. */ -QSE_EXPORT const qse_htb_mancbs_t* qse_gethtbmancbs ( - qse_htb_mancbs_kind_t kind +QSE_EXPORT const qse_htb_style_t* qse_gethtbstyle ( + qse_htb_style_kind_t kind ); /** @@ -364,19 +364,22 @@ QSE_EXPORT void* qse_htb_getxtn ( ); /** - * The qse_htb_getmancbs() function gets manipulation callback function set. + * The qse_htb_getstyle() function gets manipulation callback function set. */ -QSE_EXPORT const qse_htb_mancbs_t* qse_htb_getmancbs ( +QSE_EXPORT const qse_htb_style_t* qse_htb_getstyle ( const qse_htb_t* htb /**< hash table */ ); /** - * The qse_htb_setmancbs() function sets internal manipulation callback + * The qse_htb_setstyle() function sets internal manipulation callback * functions for data construction, destruction, resizing, hashing, etc. + * The callback structure pointed to by \a style must outlive the hash + * table pointed to by \a htb as the hash table doesn't copy the contents + * of the structure. */ -QSE_EXPORT void qse_htb_setmancbs ( - qse_htb_t* htb, /**< hash table */ - const qse_htb_mancbs_t* mancbs /**< callback function set */ +QSE_EXPORT void qse_htb_setstyle ( + qse_htb_t* htb, /**< hash table */ + const qse_htb_style_t* style /**< callback function set */ ); /** @@ -533,7 +536,7 @@ QSE_EXPORT qse_htb_pair_t* qse_htb_update ( * QSE_MMGR_GETDFL(), 0, 10, 70, * QSE_SIZEOF(qse_char_t), QSE_SIZEOF(qse_char_t) * ); // note error check is skipped - * qse_htb_setmancbs (s1, &mancbs1); + * qse_htb_setstyle (s1, &style1); * * for (i = 0; i < QSE_COUNTOF(vals); i++) * { diff --git a/qse/include/qse/cmn/map.h b/qse/include/qse/cmn/map.h index ac1e545f..b1630e7b 100644 --- a/qse/include/qse/cmn/map.h +++ b/qse/include/qse/cmn/map.h @@ -29,19 +29,19 @@ #if defined(QSE_MAP_AS_HTB) # include -# define QSE_MAP_MANCBS_DEFAULT QSE_HTB_MANCBS_DEFAULT -# define QSE_MAP_MANCBS_INLINE_COPIERS QSE_HTB_MANCBS_INLINE_COPIERS -# define QSE_MAP_MANCBS_INLINE_KEY_COPIER QSE_HTB_MANCBS_INLINE_KEY_COPIER -# define QSE_MAP_MANCBS_INLINE_VALUE_COPIER QSE_HTB_MANCBS_INLINE_VALUE_COPIER -# define qse_getmapmancbs(kind) qse_gethtbmancbs(kind) +# define QSE_MAP_STYLE_DEFAULT QSE_HTB_STYLE_DEFAULT +# define QSE_MAP_STYLE_INLINE_COPIERS QSE_HTB_STYLE_INLINE_COPIERS +# define QSE_MAP_STYLE_INLINE_KEY_COPIER QSE_HTB_STYLE_INLINE_KEY_COPIER +# define QSE_MAP_STYLE_INLINE_VALUE_COPIER QSE_HTB_STYLE_INLINE_VALUE_COPIER +# define qse_getmapstyle(kind) qse_gethtbstyle(kind) # define qse_map_open(mmgr,ext,capa,factor,ks,vs) qse_htb_open(mmgr,ext,capa,factor,ks,vs) # define qse_map_close(map) qse_htb_close(map) # define qse_map_init(map,mmgr,capa,factor,ks,vs) qse_htb_init(map,mmgr,capa,factor,ks,vs) # define qse_map_fini(map) qse_htb_fini(map) # define qse_map_getsize(map) qse_htb_getsize(map) # define qse_map_getcapa(map) qse_htb_getcapa(map) -# define qse_map_getmancbs(map) qse_htb_getmancbs(map) -# define qse_map_setmancbs(map,cbs) qse_htb_setmancbs(map,cbs) +# define qse_map_getstyle(map) qse_htb_getstyle(map) +# define qse_map_setstyle(map,cbs) qse_htb_setstyle(map,cbs) # define qse_map_search(map,kptr,klen) qse_htb_search(map,kptr,klen) # define qse_map_upsert(map,kptr,klen,vptr,vlen) qse_htb_upsert(map,kptr,klen,vptr,vlen) # define qse_map_ensert(map,kptr,klen,vptr,vlen) qse_htb_ensert(map,kptr,klen,vptr,vlen) @@ -59,7 +59,7 @@ # define qse_map_id_t qse_htb_id_t # define qse_map_t qse_htb_t # define qse_map_pair_t qse_htb_pair_t -# define qse_map_mancbs_t qse_htb_mancbs_t +# define qse_map_style_t qse_htb_style_t # define qse_map_cbserter_t qse_htb_cbserter_t # define qse_map_walker_t qse_htb_walker_t # define QSE_MAP_COPIER_SIMPLE QSE_HTB_COPIER_SIMPLE @@ -87,19 +87,19 @@ # define QSE_MAP_VLEN(p) QSE_HTB_VLEN(p) #elif defined(QSE_MAP_AS_RBT) # include -# define QSE_MAP_MANCBS_DEFAULT QSE_RBT_MANCBS_DEFAULT -# define QSE_MAP_MANCBS_INLINE_COPIERS QSE_RBT_MANCBS_INLINE_COPIERS -# define QSE_MAP_MANCBS_INLINE_KEY_COPIER QSE_RBT_MANCBS_INLINE_KEY_COPIER -# define QSE_MAP_MANCBS_INLINE_VALUE_COPIER QSE_RBT_MANCBS_INLINE_VALUE_COPIER -# define qse_getmapmancbs(kind) qse_getrbtmancbs(kind) +# define QSE_MAP_STYLE_DEFAULT QSE_RBT_STYLE_DEFAULT +# define QSE_MAP_STYLE_INLINE_COPIERS QSE_RBT_STYLE_INLINE_COPIERS +# define QSE_MAP_STYLE_INLINE_KEY_COPIER QSE_RBT_STYLE_INLINE_KEY_COPIER +# define QSE_MAP_STYLE_INLINE_VALUE_COPIER QSE_RBT_STYLE_INLINE_VALUE_COPIER +# define qse_getmapstyle(kind) qse_getrbtstyle(kind) # define qse_map_open(mmgr,ext,capa,factor,ks,vs) qse_rbt_open(mmgr,ext,ks,vs) # define qse_map_close(map) qse_rbt_close(map) # define qse_map_init(map,mmgr,capa,factor,ks,vs) qse_rbt_init(map,mmgr,ks,vs) # define qse_map_fini(map) qse_rbt_fini(map) # define qse_map_getsize(map) qse_rbt_getsize(map) # define qse_map_getcapa(map) qse_rbt_getsize(map) -# define qse_map_getmancbs(map) qse_rbt_getmancbs(map) -# define qse_map_setmancbs(map,cbs) qse_rbt_setmancbs(map,cbs) +# define qse_map_getstyle(map) qse_rbt_getstyle(map) +# define qse_map_setstyle(map,cbs) qse_rbt_setstyle(map,cbs) # define qse_map_search(map,kptr,klen) qse_rbt_search(map,kptr,klen) # define qse_map_upsert(map,kptr,klen,vptr,vlen) qse_rbt_upsert(map,kptr,klen,vptr,vlen) # define qse_map_ensert(map,kptr,klen,vptr,vlen) qse_rbt_ensert(map,kptr,klen,vptr,vlen) @@ -117,7 +117,7 @@ # define qse_map_id_t qse_rbt_id_t # define qse_map_t qse_rbt_t # define qse_map_pair_t qse_rbt_pair_t -# define qse_map_mancbs_t qse_rbt_mancbs_t +# define qse_map_style_t qse_rbt_style_t # define qse_map_cbserter_t qse_rbt_cbserter_t # define qse_map_walker_t qse_rbt_walker_t # define QSE_MAP_COPIER_SIMPLE QSE_RBT_COPIER_SIMPLE diff --git a/qse/include/qse/cmn/rbt.h b/qse/include/qse/cmn/rbt.h index d1257922..5c667357 100644 --- a/qse/include/qse/cmn/rbt.h +++ b/qse/include/qse/cmn/rbt.h @@ -49,7 +49,7 @@ * int i; * * s1 = qse_rbt_open (QSE_MMGR_GETDFL(), 0, 1, 1); // error handling skipped - * qse_rbt_setmancbs (s1, qse_getrbtmancbs(QSE_RBT_MANCBS_INLINE_COPIERS)); + * qse_rbt_setstyle (s1, qse_getrbtstyle(QSE_RBT_STYLE_INLINE_COPIERS)); * * for (i = 0; i < 20; i++) * { @@ -183,13 +183,13 @@ struct qse_rbt_pair_t qse_rbt_pair_t* child[2]; /* left and right */ }; -typedef struct qse_rbt_mancbs_t qse_rbt_mancbs_t; +typedef struct qse_rbt_style_t qse_rbt_style_t; /** - * The qse_rbt_mancbs_t type defines callback function sets for key/value + * The qse_rbt_style_t type defines callback function sets for key/value * pair manipulation. */ -struct qse_rbt_mancbs_t +struct qse_rbt_style_t { qse_rbt_copier_t copier[2]; /**< key and value copier */ qse_rbt_freeer_t freeer[2]; /**< key and value freeer */ @@ -198,22 +198,22 @@ struct qse_rbt_mancbs_t }; /** - * The qse_rbt_mancbs_kind_t type defines the type of predefined + * The qse_rbt_style_kind_t type defines the type of predefined * callback set for pair manipulation. */ -enum qse_rbt_mancbs_kind_t +enum qse_rbt_style_kind_t { /** store the key and the value pointer */ - QSE_RBT_MANCBS_DEFAULT, + QSE_RBT_STYLE_DEFAULT, /** copy both key and value into the pair */ - QSE_RBT_MANCBS_INLINE_COPIERS, + QSE_RBT_STYLE_INLINE_COPIERS, /** copy the key into the pair but store the value pointer */ - QSE_RBT_MANCBS_INLINE_KEY_COPIER, + QSE_RBT_STYLE_INLINE_KEY_COPIER, /** copy the value into the pair but store the key pointer */ - QSE_RBT_MANCBS_INLINE_VALUE_COPIER + QSE_RBT_STYLE_INLINE_VALUE_COPIER }; -typedef enum qse_rbt_mancbs_kind_t qse_rbt_mancbs_kind_t; +typedef enum qse_rbt_style_kind_t qse_rbt_style_kind_t; /** * The qse_rbt_t type defines a red-black tree. @@ -222,7 +222,7 @@ struct qse_rbt_t { qse_mmgr_t* mmgr; - const qse_rbt_mancbs_t* mancbs; + const qse_rbt_style_t* style; qse_byte_t scale[2]; /**< length scale */ @@ -271,11 +271,11 @@ extern "C" { #endif /** - * The qse_getrbtmancbs() functions returns a predefined callback set for + * The qse_getrbtstyle() functions returns a predefined callback set for * pair manipulation. */ -QSE_EXPORT const qse_rbt_mancbs_t* qse_getrbtmancbs ( - qse_rbt_mancbs_kind_t kind +QSE_EXPORT const qse_rbt_style_t* qse_getrbtstyle ( + qse_rbt_style_kind_t kind ); /** @@ -322,19 +322,22 @@ QSE_EXPORT void* qse_rbt_getxtn ( ); /** - * The qse_rbt_getmancbs() function gets manipulation callback function set. + * The qse_rbt_getstyle() function gets manipulation callback function set. */ -QSE_EXPORT const qse_rbt_mancbs_t* qse_rbt_getmancbs ( +QSE_EXPORT const qse_rbt_style_t* qse_rbt_getstyle ( const qse_rbt_t* rbt /**< red-black tree */ ); /** - * The qse_rbt_setmancbs() function sets internal manipulation callback + * The qse_rbt_setstyle() function sets internal manipulation callback * functions for data construction, destruction, comparison, etc. + * The callback structure pointed to by \a style must outlive the tree + * pointed to by \a htb as the tree doesn't copy the contents of the + * structure. */ -QSE_EXPORT void qse_rbt_setmancbs ( - qse_rbt_t* rbt, /**< red-black tree */ - const qse_rbt_mancbs_t* mancbs /**< callback function set */ +QSE_EXPORT void qse_rbt_setstyle ( + qse_rbt_t* rbt, /**< red-black tree */ + const qse_rbt_style_t* style /**< callback function set */ ); /** @@ -483,7 +486,7 @@ QSE_EXPORT qse_rbt_pair_t* qse_rbt_update ( * QSE_MMGR_GETDFL(), 0, * QSE_SIZEOF(qse_char_t), QSE_SIZEOF(qse_char_t) * ); // note error check is skipped - * qse_rbt_setmancbs (s1, &mancbs1); + * qse_rbt_setstyle (s1, &style1); * * for (i = 0; i < QSE_COUNTOF(vals); i++) * { diff --git a/qse/include/qse/cmn/str.h b/qse/include/qse/cmn/str.h index 394dc012..7f28a132 100644 --- a/qse/include/qse/cmn/str.h +++ b/qse/include/qse/cmn/str.h @@ -1542,12 +1542,12 @@ QSE_EXPORT qse_wchar_t* qse_wcsxnend ( ); #if defined(QSE_CHAR_IS_MCHAR) -# define qse_strend(str,sub) qse_mbsxend(str,sub) +# define qse_strend(str,sub) qse_mbsend(str,sub) # define qse_strxend(str,len,sub) qse_mbsxend(str,len,sub) # define qse_strnend(str,sub,len) qse_mbsnend(str,sub,len) # define qse_strxnend(str,len1,sub,len2) qse_mbsxnend(str,len1,sub,len2) #else -# define qse_strend(str,sub) qse_wcsxend(str,sub) +# define qse_strend(str,sub) qse_wcsend(str,sub) # define qse_strxend(str,len,sub) qse_wcsxend(str,len,sub) # define qse_strnend(str,sub,len) qse_wcsnend(str,sub,len) # define qse_strxnend(str,len1,sub,len2) qse_wcsxnend(str,len1,sub,len2) diff --git a/qse/include/qse/http/stdhttpd.h b/qse/include/qse/http/stdhttpd.h index e89d1ca8..395263b9 100644 --- a/qse/include/qse/http/stdhttpd.h +++ b/qse/include/qse/http/stdhttpd.h @@ -51,7 +51,11 @@ struct qse_httpd_serverstd_root_t qse_httpd_serverstd_root_type_t type; union { - const qse_mchar_t* path; + struct + { + const qse_mchar_t* val; + qse_size_t rpl; /* replacement length */ + } path; qse_nwad_t nwad; } u; }; @@ -94,6 +98,8 @@ struct qse_httpd_serverstd_ssl_t enum qse_httpd_serverstd_query_code_t { + QSE_HTTPD_SERVERSTD_SSL, /* qse_httpd_serverstd_ssl_t */ + QSE_HTTPD_SERVERSTD_NAME, /* const qse_mchar_t* */ QSE_HTTPD_SERVERSTD_ROOT, /* qse_httpd_serverstd_root_t */ QSE_HTTPD_SERVERSTD_REALM, /* qse_httpd_serverstd_realm_t */ @@ -105,9 +111,8 @@ enum qse_httpd_serverstd_query_code_t QSE_HTTPD_SERVERSTD_CGI, /* qse_httpd_serverstd_cgi_t */ QSE_HTTPD_SERVERSTD_MIME, /* const qse_mchar_t* */ QSE_HTTPD_SERVERSTD_DIRACC, /* int (http error code) */ - QSE_HTTPD_SERVERSTD_FILEACC, /* int (http error code) */ + QSE_HTTPD_SERVERSTD_FILEACC /* int (http error code) */ - QSE_HTTPD_SERVERSTD_SSL /* qse_httpd_serverstd_ssl_t */ }; typedef enum qse_httpd_serverstd_query_code_t qse_httpd_serverstd_query_code_t; diff --git a/qse/lib/awk/Awk.cpp b/qse/lib/awk/Awk.cpp index 6fe7e631..334c2fb2 100644 --- a/qse/lib/awk/Awk.cpp +++ b/qse/lib/awk/Awk.cpp @@ -1141,7 +1141,7 @@ int Awk::open () *(Awk**)QSE_XTN(functionMap) = this; - static qse_htb_mancbs_t mancbs = + static qse_htb_style_t style = { { QSE_HTB_COPIER_INLINE, @@ -1156,7 +1156,7 @@ int Awk::open () QSE_HTB_SIZER_DEFAULT, QSE_HTB_HASHER_DEFAULT }; - qse_htb_setmancbs (functionMap, &mancbs); + qse_htb_setstyle (functionMap, &style); return 0; } diff --git a/qse/lib/awk/StdAwk.cpp b/qse/lib/awk/StdAwk.cpp index 81387156..44cf864e 100644 --- a/qse/lib/awk/StdAwk.cpp +++ b/qse/lib/awk/StdAwk.cpp @@ -206,8 +206,8 @@ StdAwk::Run* StdAwk::parse (Source& in, Source& out) this->setError (QSE_AWK_ENOMEM); return QSE_NULL; } - qse_htb_setmancbs (&this->cmgrtab, - qse_gethtbmancbs(QSE_HTB_MANCBS_INLINE_KEY_COPIER)); + qse_htb_setstyle (&this->cmgrtab, + qse_gethtbstyle(QSE_HTB_STYLE_INLINE_KEY_COPIER)); this->cmgrtab_inited = true; } diff --git a/qse/lib/awk/awk.c b/qse/lib/awk/awk.c index 8a9f29b2..312121aa 100644 --- a/qse/lib/awk/awk.c +++ b/qse/lib/awk/awk.c @@ -74,7 +74,7 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_awk_prm_t* pr { qse_awk_t* awk; - static qse_htb_mancbs_t treefuncbs = + static qse_htb_style_t treefuncbs = { { QSE_HTB_COPIER_INLINE, @@ -90,7 +90,7 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_awk_prm_t* pr QSE_HTB_HASHER_DEFAULT }; - static qse_htb_mancbs_t fncusercbs = + static qse_htb_style_t fncusercbs = { { QSE_HTB_COPIER_INLINE, @@ -156,8 +156,8 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_awk_prm_t* pr ); if (awk->sio_names == QSE_NULL) goto oops; *(qse_awk_t**)QSE_XTN(awk->sio_names) = awk; - qse_htb_setmancbs (awk->sio_names, - qse_gethtbmancbs(QSE_HTB_MANCBS_INLINE_KEY_COPIER) + qse_htb_setstyle (awk->sio_names, + qse_gethtbstyle(QSE_HTB_STYLE_INLINE_KEY_COPIER) ); /* TODO: initial map size?? */ @@ -166,15 +166,15 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_awk_prm_t* pr ); if (awk->tree.funs == QSE_NULL) goto oops; *(qse_awk_t**)QSE_XTN(awk->tree.funs) = awk; - qse_htb_setmancbs (awk->tree.funs, &treefuncbs); + qse_htb_setstyle (awk->tree.funs, &treefuncbs); awk->parse.funs = qse_htb_open ( mmgr, QSE_SIZEOF(awk), 256, 70, QSE_SIZEOF(qse_char_t), 1 ); if (awk->parse.funs == QSE_NULL) goto oops; *(qse_awk_t**)QSE_XTN(awk->parse.funs) = awk; - qse_htb_setmancbs (awk->parse.funs, - qse_gethtbmancbs(QSE_HTB_MANCBS_INLINE_KEY_COPIER) + qse_htb_setstyle (awk->parse.funs, + qse_gethtbstyle(QSE_HTB_STYLE_INLINE_KEY_COPIER) ); awk->parse.named = qse_htb_open ( @@ -182,8 +182,8 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_awk_prm_t* pr ); if (awk->parse.named == QSE_NULL) goto oops; *(qse_awk_t**)QSE_XTN(awk->parse.named) = awk; - qse_htb_setmancbs (awk->parse.named, - qse_gethtbmancbs(QSE_HTB_MANCBS_INLINE_KEY_COPIER) + qse_htb_setstyle (awk->parse.named, + qse_gethtbstyle(QSE_HTB_STYLE_INLINE_KEY_COPIER) ); awk->parse.gbls = qse_lda_open (mmgr, QSE_SIZEOF(awk), 128); @@ -234,13 +234,13 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_awk_prm_t* pr ); if (awk->fnc.user == QSE_NULL) goto oops; *(qse_awk_t**)QSE_XTN(awk->fnc.user) = awk; - qse_htb_setmancbs (awk->fnc.user, &fncusercbs); + qse_htb_setstyle (awk->fnc.user, &fncusercbs); awk->modtab = qse_rbt_open (mmgr, 0, QSE_SIZEOF(qse_char_t), 1); if (awk->modtab == QSE_NULL) goto oops; - qse_rbt_setmancbs ( + qse_rbt_setstyle ( awk->modtab, - qse_getrbtmancbs(QSE_RBT_MANCBS_INLINE_COPIERS) + qse_getrbtstyle(QSE_RBT_STYLE_INLINE_COPIERS) ); if (qse_awk_initgbls (awk) <= -1) goto oops; diff --git a/qse/lib/awk/mod-dir.c b/qse/lib/awk/mod-dir.c index 238bf41f..57835148 100644 --- a/qse/lib/awk/mod-dir.c +++ b/qse/lib/awk/mod-dir.c @@ -595,7 +595,7 @@ int qse_awk_mod_dir (qse_awk_mod_t* mod, qse_awk_t* awk) qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL); return -1; } - qse_rbt_setmancbs (rbt, qse_getrbtmancbs(QSE_RBT_MANCBS_INLINE_COPIERS)); + qse_rbt_setstyle (rbt, qse_getrbtstyle(QSE_RBT_STYLE_INLINE_COPIERS)); mod->ctx = rbt; return 0; diff --git a/qse/lib/awk/mod-uci.c b/qse/lib/awk/mod-uci.c index 520d2157..637eda80 100644 --- a/qse/lib/awk/mod-uci.c +++ b/qse/lib/awk/mod-uci.c @@ -1422,7 +1422,7 @@ int qse_awk_mod_uci (qse_awk_mod_t* mod, qse_awk_t* awk) qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL); return -1; } - qse_rbt_setmancbs (rbt, qse_getrbtmancbs(QSE_RBT_MANCBS_INLINE_COPIERS)); + qse_rbt_setstyle (rbt, qse_getrbtstyle(QSE_RBT_STYLE_INLINE_COPIERS)); mod->ctx = rbt; return 0; diff --git a/qse/lib/awk/run.c b/qse/lib/awk/run.c index ec2646f5..cff58f38 100644 --- a/qse/lib/awk/run.c +++ b/qse/lib/awk/run.c @@ -894,7 +894,7 @@ static void same_namedval (qse_htb_t* map, void* dptr, qse_size_t dlen) static int init_rtx (qse_awk_rtx_t* rtx, qse_awk_t* awk, qse_awk_rio_t* rio) { - static qse_htb_mancbs_t mancbs_for_named = + static qse_htb_style_t style_for_named = { { QSE_HTB_COPIER_INLINE, @@ -942,7 +942,7 @@ static int init_rtx (qse_awk_rtx_t* rtx, qse_awk_t* awk, qse_awk_rio_t* rio) rtx->named = qse_htb_open (MMGR(rtx), QSE_SIZEOF(rtx), 1024, 70, QSE_SIZEOF(qse_char_t), 1); if (rtx->named == QSE_NULL) goto oops_5; *(qse_awk_rtx_t**)QSE_XTN(rtx->named) = rtx; - qse_htb_setmancbs (rtx->named, &mancbs_for_named); + qse_htb_setstyle (rtx->named, &style_for_named); rtx->format.tmp.ptr = (qse_char_t*) QSE_AWK_ALLOC (rtx->awk, 4096*QSE_SIZEOF(qse_char_t*)); diff --git a/qse/lib/awk/std.c b/qse/lib/awk/std.c index 2d48c1d8..4f068264 100644 --- a/qse/lib/awk/std.c +++ b/qse/lib/awk/std.c @@ -2095,8 +2095,8 @@ qse_awk_rtx_t* qse_awk_rtx_openstd ( qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL); return QSE_NULL; } - qse_htb_setmancbs (&rxtn->cmgrtab, - qse_gethtbmancbs(QSE_HTB_MANCBS_INLINE_COPIERS)); + qse_htb_setstyle (&rxtn->cmgrtab, + qse_gethtbstyle(QSE_HTB_STYLE_INLINE_COPIERS)); rxtn->cmgrtab_inited = 1; } diff --git a/qse/lib/awk/val.c b/qse/lib/awk/val.c index 8f808524..2d04e689 100644 --- a/qse/lib/awk/val.c +++ b/qse/lib/awk/val.c @@ -488,7 +488,7 @@ static void same_mapval (qse_htb_t* map, void* dptr, qse_size_t dlen) qse_awk_val_t* qse_awk_rtx_makemapval (qse_awk_rtx_t* rtx) { - static qse_htb_mancbs_t mancbs = + static qse_htb_style_t style = { /* the key is copied inline into a pair and is freed when the pair * is destroyed. not setting copier for a value means that the pointer @@ -559,7 +559,7 @@ qse_awk_val_t* qse_awk_rtx_makemapval (qse_awk_rtx_t* rtx) return QSE_NULL; } *(qse_awk_rtx_t**)QSE_XTN(val->map) = rtx; - qse_htb_setmancbs (val->map, &mancbs); + qse_htb_setstyle (val->map, &style); /* END CHECK */ return (qse_awk_val_t*)val; diff --git a/qse/lib/cmn/htb.c b/qse/lib/cmn/htb.c index 632e3903..f15b8cb4 100644 --- a/qse/lib/cmn/htb.c +++ b/qse/lib/cmn/htb.c @@ -32,8 +32,8 @@ #define sizer_t qse_htb_sizer_t #define walker_t qse_htb_walker_t #define cbserter_t qse_htb_cbserter_t -#define mancbs_t qse_htb_mancbs_t -#define mancbs_kind_t qse_htb_mancbs_kind_t +#define style_t qse_htb_style_t +#define style_kind_t qse_htb_style_kind_t #define KPTR(p) QSE_HTB_KPTR(p) #define KLEN(p) QSE_HTB_KLEN(p) @@ -53,10 +53,13 @@ QSE_INLINE pair_t* qse_htb_allocpair ( htb_t* htb, void* kptr, size_t klen, void* vptr, size_t vlen) { pair_t* n; - copier_t kcop = htb->mancbs->copier[QSE_HTB_KEY]; - copier_t vcop = htb->mancbs->copier[QSE_HTB_VAL]; + copier_t kcop, vcop; + size_t as; - size_t as = SIZEOF(pair_t); + kcop = htb->style->copier[QSE_HTB_KEY]; + vcop = htb->style->copier[QSE_HTB_VAL]; + + as = SIZEOF(pair_t); if (kcop == QSE_HTB_COPIER_INLINE) as += KTOB(htb,klen); if (vcop == QSE_HTB_COPIER_INLINE) as += VTOB(htb,vlen); @@ -106,8 +109,8 @@ QSE_INLINE pair_t* qse_htb_allocpair ( VPTR(n) = vcop (htb, vptr, vlen); if (VPTR(n) != QSE_NULL) { - if (htb->mancbs->freeer[QSE_HTB_KEY] != QSE_NULL) - htb->mancbs->freeer[QSE_HTB_KEY] (htb, KPTR(n), KLEN(n)); + if (htb->style->freeer[QSE_HTB_KEY] != QSE_NULL) + htb->style->freeer[QSE_HTB_KEY] (htb, KPTR(n), KLEN(n)); QSE_MMGR_FREE (htb->mmgr, n); return QSE_NULL; } @@ -118,10 +121,10 @@ QSE_INLINE pair_t* qse_htb_allocpair ( QSE_INLINE void qse_htb_freepair (htb_t* htb, pair_t* pair) { - if (htb->mancbs->freeer[QSE_HTB_KEY] != QSE_NULL) - htb->mancbs->freeer[QSE_HTB_KEY] (htb, KPTR(pair), KLEN(pair)); - if (htb->mancbs->freeer[QSE_HTB_VAL] != QSE_NULL) - htb->mancbs->freeer[QSE_HTB_VAL] (htb, VPTR(pair), VLEN(pair)); + if (htb->style->freeer[QSE_HTB_KEY] != QSE_NULL) + htb->style->freeer[QSE_HTB_KEY] (htb, KPTR(pair), KLEN(pair)); + if (htb->style->freeer[QSE_HTB_VAL] != QSE_NULL) + htb->style->freeer[QSE_HTB_VAL] (htb, VPTR(pair), VLEN(pair)); QSE_MMGR_FREE (htb->mmgr, pair); } @@ -133,14 +136,14 @@ static QSE_INLINE pair_t* change_pair_val ( /* if the old value and the new value are the same, * it just calls the handler for this condition. * No value replacement occurs. */ - if (htb->mancbs->keeper != QSE_NULL) + if (htb->style->keeper != QSE_NULL) { - htb->mancbs->keeper (htb, vptr, vlen); + htb->style->keeper (htb, vptr, vlen); } } else { - copier_t vcop = htb->mancbs->copier[QSE_HTB_VAL]; + copier_t vcop = htb->style->copier[QSE_HTB_VAL]; void* ovptr = VPTR(pair); size_t ovlen = VLEN(pair); @@ -176,9 +179,9 @@ static QSE_INLINE pair_t* change_pair_val ( } /* free up the old value */ - if (htb->mancbs->freeer[QSE_HTB_VAL] != QSE_NULL) + if (htb->style->freeer[QSE_HTB_VAL] != QSE_NULL) { - htb->mancbs->freeer[QSE_HTB_VAL] (htb, ovptr, ovlen); + htb->style->freeer[QSE_HTB_VAL] (htb, ovptr, ovlen); } } @@ -186,9 +189,9 @@ static QSE_INLINE pair_t* change_pair_val ( return pair; } -static mancbs_t mancbs[] = +static style_t style[] = { - /* == QSE_HTB_MANCBS_DEFAULT == */ + /* == QSE_HTB_STYLE_DEFAULT == */ { { QSE_HTB_COPIER_DEFAULT, @@ -204,7 +207,7 @@ static mancbs_t mancbs[] = QSE_HTB_HASHER_DEFAULT }, - /* == QSE_HTB_MANCBS_INLINE_COPIERS == */ + /* == QSE_HTB_STYLE_INLINE_COPIERS == */ { { QSE_HTB_COPIER_INLINE, @@ -220,7 +223,7 @@ static mancbs_t mancbs[] = QSE_HTB_HASHER_DEFAULT }, - /* == QSE_HTB_MANCBS_INLINE_KEY_COPIER == */ + /* == QSE_HTB_STYLE_INLINE_KEY_COPIER == */ { { QSE_HTB_COPIER_INLINE, @@ -236,7 +239,7 @@ static mancbs_t mancbs[] = QSE_HTB_HASHER_DEFAULT }, - /* == QSE_HTB_MANCBS_INLINE_VALUE_COPIER == */ + /* == QSE_HTB_STYLE_INLINE_VALUE_COPIER == */ { { QSE_HTB_COPIER_DEFAULT, @@ -253,9 +256,9 @@ static mancbs_t mancbs[] = } }; -const mancbs_t* qse_gethtbmancbs (mancbs_kind_t kind) +const style_t* qse_gethtbstyle (style_kind_t kind) { - return &mancbs[kind]; + return &style[kind]; } htb_t* qse_htb_open ( @@ -318,7 +321,7 @@ int qse_htb_init ( htb->threshold = htb->capa * htb->factor / 100; if (htb->capa > 0 && htb->threshold <= 0) htb->threshold = 1; - htb->mancbs = &mancbs[0]; + htb->style = &style[0]; return 0; } @@ -338,15 +341,15 @@ void* qse_htb_getxtn (qse_htb_t* htb) return QSE_XTN (htb); } -const mancbs_t* qse_htb_getmancbs (const htb_t* htb) +const style_t* qse_htb_getstyle (const htb_t* htb) { - return htb->mancbs; + return htb->style; } -void qse_htb_setmancbs (htb_t* htb, const mancbs_t* mancbs) +void qse_htb_setstyle (htb_t* htb, const style_t* style) { - QSE_ASSERT (mancbs != QSE_NULL); - htb->mancbs = mancbs; + QSE_ASSERT (style != QSE_NULL); + htb->style = style; } size_t qse_htb_getsize (const htb_t* htb) @@ -364,12 +367,12 @@ pair_t* qse_htb_search (const htb_t* htb, const void* kptr, size_t klen) pair_t* pair; size_t hc; - hc = htb->mancbs->hasher(htb,kptr,klen) % htb->capa; + hc = htb->style->hasher(htb,kptr,klen) % htb->capa; pair = htb->bucket[hc]; while (pair != QSE_NULL) { - if (htb->mancbs->comper (htb, KPTR(pair), KLEN(pair), kptr, klen) == 0) + if (htb->style->comper (htb, KPTR(pair), KLEN(pair), kptr, klen) == 0) { return pair; } @@ -385,9 +388,9 @@ static QSE_INLINE_ALWAYS int reorganize (htb_t* htb) size_t i, hc, new_capa; pair_t** new_buck; - if (htb->mancbs->sizer) + if (htb->style->sizer) { - new_capa = htb->mancbs->sizer (htb, htb->capa + 1); + new_capa = htb->style->sizer (htb, htb->capa + 1); /* if no change in capacity, return success * without reorganization */ @@ -423,7 +426,7 @@ static QSE_INLINE_ALWAYS int reorganize (htb_t* htb) { pair_t* next = NEXT(pair); - hc = htb->mancbs->hasher (htb, + hc = htb->style->hasher (htb, KPTR(pair), KLEN(pair)) % new_capa; @@ -454,7 +457,7 @@ static pair_t* insert ( pair_t* pair, * p, * prev, * next; size_t hc; - hc = htb->mancbs->hasher(htb,kptr,klen) % htb->capa; + hc = htb->style->hasher(htb,kptr,klen) % htb->capa; pair = htb->bucket[hc]; prev = QSE_NULL; @@ -462,7 +465,7 @@ static pair_t* insert ( { next = NEXT(pair); - if (htb->mancbs->comper (htb, KPTR(pair), KLEN(pair), kptr, klen) == 0) + if (htb->style->comper (htb, KPTR(pair), KLEN(pair), kptr, klen) == 0) { /* found a pair with a matching key */ switch (opt) @@ -509,7 +512,7 @@ static pair_t* insert ( * more bucket collision and performance penalty. */ if (reorganize(htb) == 0) { - hc = htb->mancbs->hasher(htb,kptr,klen) % htb->capa; + hc = htb->style->hasher(htb,kptr,klen) % htb->capa; } } @@ -556,7 +559,7 @@ pair_t* qse_htb_cbsert ( pair_t* pair, * p, * prev, * next; size_t hc; - hc = htb->mancbs->hasher(htb,kptr,klen) % htb->capa; + hc = htb->style->hasher(htb,kptr,klen) % htb->capa; pair = htb->bucket[hc]; prev = QSE_NULL; @@ -564,7 +567,7 @@ pair_t* qse_htb_cbsert ( { next = NEXT(pair); - if (htb->mancbs->comper (htb, KPTR(pair), KLEN(pair), kptr, klen) == 0) + if (htb->style->comper (htb, KPTR(pair), KLEN(pair), kptr, klen) == 0) { /* found a pair with a matching key */ p = cbserter (htb, pair, kptr, klen, ctx); @@ -596,7 +599,7 @@ pair_t* qse_htb_cbsert ( * more bucket collision and performance penalty. */ if (reorganize(htb) == 0) { - hc = htb->mancbs->hasher(htb,kptr,klen) % htb->capa; + hc = htb->style->hasher(htb,kptr,klen) % htb->capa; } } @@ -617,13 +620,13 @@ int qse_htb_delete (htb_t* htb, const void* kptr, size_t klen) pair_t* pair, * prev; size_t hc; - hc = htb->mancbs->hasher(htb,kptr,klen) % htb->capa; + hc = htb->style->hasher(htb,kptr,klen) % htb->capa; pair = htb->bucket[hc]; prev = QSE_NULL; while (pair != QSE_NULL) { - if (htb->mancbs->comper (htb, KPTR(pair), KLEN(pair), kptr, klen) == 0) + if (htb->style->comper (htb, KPTR(pair), KLEN(pair), kptr, klen) == 0) { if (prev == QSE_NULL) htb->bucket[hc] = NEXT(pair); diff --git a/qse/lib/cmn/rbt.c b/qse/lib/cmn/rbt.c index 548f4454..95d85ed2 100644 --- a/qse/lib/cmn/rbt.c +++ b/qse/lib/cmn/rbt.c @@ -30,8 +30,8 @@ #define keeper_t qse_rbt_keeper_t #define walker_t qse_rbt_walker_t #define cbserter_t qse_rbt_cbserter_t -#define mancbs_t qse_rbt_mancbs_t -#define mancbs_kind_t qse_rbt_mancbs_kind_t +#define style_t qse_rbt_style_t +#define style_kind_t qse_rbt_style_kind_t #define KPTR(p) QSE_RBT_KPTR(p) #define KLEN(p) QSE_RBT_KLEN(p) @@ -64,8 +64,8 @@ QSE_INLINE pair_t* qse_rbt_allocpair ( { pair_t* n; - copier_t kcop = rbt->mancbs->copier[QSE_RBT_KEY]; - copier_t vcop = rbt->mancbs->copier[QSE_RBT_VAL]; + copier_t kcop = rbt->style->copier[QSE_RBT_KEY]; + copier_t vcop = rbt->style->copier[QSE_RBT_VAL]; size_t as = SIZEOF(pair_t); if (kcop == QSE_RBT_COPIER_INLINE) as += KTOB(rbt,klen); @@ -116,8 +116,8 @@ QSE_INLINE pair_t* qse_rbt_allocpair ( VPTR(n) = vcop (rbt, vptr, vlen); if (VPTR(n) != QSE_NULL) { - if (rbt->mancbs->freeer[QSE_RBT_KEY] != QSE_NULL) - rbt->mancbs->freeer[QSE_RBT_KEY] (rbt, KPTR(n), KLEN(n)); + if (rbt->style->freeer[QSE_RBT_KEY] != QSE_NULL) + rbt->style->freeer[QSE_RBT_KEY] (rbt, KPTR(n), KLEN(n)); QSE_MMGR_FREE (rbt->mmgr, n); return QSE_NULL; } @@ -128,14 +128,14 @@ QSE_INLINE pair_t* qse_rbt_allocpair ( QSE_INLINE void qse_rbt_freepair (rbt_t* rbt, pair_t* pair) { - if (rbt->mancbs->freeer[QSE_RBT_KEY] != QSE_NULL) - rbt->mancbs->freeer[QSE_RBT_KEY] (rbt, KPTR(pair), KLEN(pair)); - if (rbt->mancbs->freeer[QSE_RBT_VAL] != QSE_NULL) - rbt->mancbs->freeer[QSE_RBT_VAL] (rbt, VPTR(pair), VLEN(pair)); + if (rbt->style->freeer[QSE_RBT_KEY] != QSE_NULL) + rbt->style->freeer[QSE_RBT_KEY] (rbt, KPTR(pair), KLEN(pair)); + if (rbt->style->freeer[QSE_RBT_VAL] != QSE_NULL) + rbt->style->freeer[QSE_RBT_VAL] (rbt, VPTR(pair), VLEN(pair)); QSE_MMGR_FREE (rbt->mmgr, pair); } -static mancbs_t mancbs[] = +static style_t style[] = { { { @@ -190,9 +190,9 @@ static mancbs_t mancbs[] = } }; -const mancbs_t* qse_getrbtmancbs (mancbs_kind_t kind) +const style_t* qse_getrbtstyle (style_kind_t kind) { - return &mancbs[kind]; + return &style[kind]; } rbt_t* qse_rbt_open (mmgr_t* mmgr, size_t xtnsize, int kscale, int vscale) @@ -228,7 +228,7 @@ int qse_rbt_init (rbt_t* rbt, mmgr_t* mmgr, int kscale, int vscale) rbt->scale[QSE_RBT_VAL] = (vscale < 1)? 1: vscale; rbt->size = 0; - rbt->mancbs = &mancbs[0]; + rbt->style = &style[0]; /* self-initializing nil */ QSE_MEMSET(&rbt->xnil, 0, QSE_SIZEOF(rbt->xnil)); @@ -257,15 +257,15 @@ void* qse_rbt_getxtn (qse_rbt_t* rbt) return QSE_XTN (rbt); } -const mancbs_t* qse_rbt_getmancbs (const rbt_t* rbt) +const style_t* qse_rbt_getstyle (const rbt_t* rbt) { - return rbt->mancbs; + return rbt->style; } -void qse_rbt_setmancbs (rbt_t* rbt, const mancbs_t* mancbs) +void qse_rbt_setstyle (rbt_t* rbt, const style_t* style) { - QSE_ASSERT (mancbs != QSE_NULL); - rbt->mancbs = mancbs; + QSE_ASSERT (style != QSE_NULL); + rbt->style = style; } size_t qse_rbt_getsize (const rbt_t* rbt) @@ -279,7 +279,7 @@ pair_t* qse_rbt_search (const rbt_t* rbt, const void* kptr, size_t klen) while (!IS_NIL(rbt,pair)) { - int n = rbt->mancbs->comper (rbt, kptr, klen, KPTR(pair), KLEN(pair)); + int n = rbt->style->comper (rbt, kptr, klen, KPTR(pair), KLEN(pair)); if (n == 0) return pair; if (n > 0) pair = pair->right; @@ -429,14 +429,14 @@ static pair_t* change_pair_val ( /* if the old value and the new value are the same, * it just calls the handler for this condition. * No value replacement occurs. */ - if (rbt->mancbs->keeper != QSE_NULL) + if (rbt->style->keeper != QSE_NULL) { - rbt->mancbs->keeper (rbt, vptr, vlen); + rbt->style->keeper (rbt, vptr, vlen); } } else { - copier_t vcop = rbt->mancbs->copier[QSE_RBT_VAL]; + copier_t vcop = rbt->style->copier[QSE_RBT_VAL]; void* ovptr = VPTR(pair); size_t ovlen = VLEN(pair); @@ -495,9 +495,9 @@ static pair_t* change_pair_val ( } /* free up the old value */ - if (rbt->mancbs->freeer[QSE_RBT_VAL] != QSE_NULL) + if (rbt->style->freeer[QSE_RBT_VAL] != QSE_NULL) { - rbt->mancbs->freeer[QSE_RBT_VAL] (rbt, ovptr, ovlen); + rbt->style->freeer[QSE_RBT_VAL] (rbt, ovptr, ovlen); } } @@ -513,7 +513,7 @@ static pair_t* insert ( while (!IS_NIL(rbt,x_cur)) { - int n = rbt->mancbs->comper (rbt, kptr, klen, KPTR(x_cur), KLEN(x_cur)); + int n = rbt->style->comper (rbt, kptr, klen, KPTR(x_cur), KLEN(x_cur)); if (n == 0) { switch (opt) @@ -552,7 +552,7 @@ static pair_t* insert ( else { /* perform normal binary insert */ - int n = rbt->mancbs->comper (rbt, kptr, klen, KPTR(x_par), KLEN(x_par)); + int n = rbt->style->comper (rbt, kptr, klen, KPTR(x_par), KLEN(x_par)); if (n > 0) { QSE_ASSERT (x_par->right == &rbt->xnil); @@ -607,7 +607,7 @@ pair_t* qse_rbt_cbsert ( while (!IS_NIL(rbt,x_cur)) { - int n = rbt->mancbs->comper (rbt, kptr, klen, KPTR(x_cur), KLEN(x_cur)); + int n = rbt->style->comper (rbt, kptr, klen, KPTR(x_cur), KLEN(x_cur)); if (n == 0) { /* back up the contents of the current pair @@ -672,7 +672,7 @@ pair_t* qse_rbt_cbsert ( else { /* perform normal binary insert */ - int n = rbt->mancbs->comper (rbt, kptr, klen, KPTR(x_par), KLEN(x_par)); + int n = rbt->style->comper (rbt, kptr, klen, KPTR(x_par), KLEN(x_par)); if (n > 0) { QSE_ASSERT (x_par->right == &rbt->xnil); diff --git a/qse/lib/http/htre.c b/qse/lib/http/htre.c index be58499c..9a7ebfcb 100644 --- a/qse/lib/http/htre.c +++ b/qse/lib/http/htre.c @@ -37,7 +37,7 @@ static void free_hdrval (qse_htb_t* htb, void* vptr, qse_size_t vlen) int qse_htre_init (qse_htre_t* re, qse_mmgr_t* mmgr) { - static qse_htb_mancbs_t mancbs = + static qse_htb_style_t style = { { QSE_HTB_COPIER_DEFAULT, @@ -59,8 +59,8 @@ int qse_htre_init (qse_htre_t* re, qse_mmgr_t* mmgr) if (qse_htb_init (&re->hdrtab, mmgr, 60, 70, 1, 1) <= -1) return -1; if (qse_htb_init (&re->trailers, mmgr, 20, 70, 1, 1) <= -1) return -1; - qse_htb_setmancbs (&re->hdrtab, &mancbs); - qse_htb_setmancbs (&re->trailers, &mancbs); + qse_htb_setstyle (&re->hdrtab, &style); + qse_htb_setstyle (&re->trailers, &style); qse_mbs_init (&re->content, mmgr, 0); #if 0 diff --git a/qse/lib/http/httpd-dir.c b/qse/lib/http/httpd-dir.c index 77c03d2a..3b0983ac 100644 --- a/qse/lib/http/httpd-dir.c +++ b/qse/lib/http/httpd-dir.c @@ -399,7 +399,7 @@ static QSE_INLINE int task_main_dir ( dir = (task_dir_t*)task->ctx; x = task; - if (qse_mbsend (dir->path.ptr, QSE_MT("/"))) + if (qse_mbsend (dir->qpath.ptr, QSE_MT("/"))) { if (httpd->opt.scb.dir.open (httpd, dir->path.ptr, &handle) <= -1) { diff --git a/qse/lib/http/httpd-std.c b/qse/lib/http/httpd-std.c index 89b80b4d..0888d31b 100644 --- a/qse/lib/http/httpd-std.c +++ b/qse/lib/http/httpd-std.c @@ -2209,8 +2209,11 @@ static qse_mchar_t* merge_paths ( qse_size_t idx = 0; ta[idx++] = base; - ta[idx++] = QSE_MT("/"); - ta[idx++] = path; + if (path[0] != QSE_MT('\0')) + { + ta[idx++] = QSE_MT("/"); + ta[idx++] = path; + } ta[idx++] = QSE_NULL; xpath = qse_mbsadup (ta, QSE_NULL, httpd->mmgr); if (xpath == QSE_NULL) @@ -2231,11 +2234,17 @@ static void merge_paths_to_buf ( * to hold the result. it doesn't duplicate the result */ qse_size_t len = 0; len += qse_mbscpy (&xpath[len], base); - len += qse_mbscpy (&xpath[len], QSE_MT("/")); + if (plen == (qse_size_t)-1) + { + len += qse_mbscpy (&xpath[len], QSE_MT("/")); len += qse_mbscpy (&xpath[len], path); - else + } + else if (plen > 0) + { + len += qse_mbscpy (&xpath[len], QSE_MT("/")); len += qse_mbsncpy (&xpath[len], path, plen); + } qse_canonmbspath (xpath, xpath, 0); } @@ -2245,6 +2254,9 @@ struct rsrc_tmp_t const qse_mchar_t* idxfile; qse_mchar_t* xpath; + qse_size_t qpath_len; + const qse_mchar_t* qpath_rp; + qse_httpd_serverstd_root_t root; qse_httpd_serverstd_realm_t realm; qse_httpd_serverstd_auth_t auth; @@ -2295,7 +2307,7 @@ static int attempt_cgi ( QSE_ASSERT (tmp->qpath[0] == QSE_T('/')); - ptr = tmp->qpath + 1; + ptr = tmp->qpath_rp + 1; while (*ptr != QSE_MT('\0')) { slash = qse_mbschr (ptr, QSE_MT('/')); @@ -2309,8 +2321,9 @@ static int attempt_cgi ( /* a slash is found and the segment is not empty. * * tmp->xpath should be large enough to hold the merge path made of - * the subsegments of the original query path and docroot. */ - merge_paths_to_buf (httpd, tmp->root.u.path, tmp->qpath, slash - tmp->qpath, tmp->xpath); + * the subsegments of the original query path and docroot. + */ + merge_paths_to_buf (httpd, tmp->root.u.path.val, tmp->qpath_rp, slash - tmp->qpath_rp, tmp->xpath); xpath_changed = 1; stx = stat_file (httpd, tmp->xpath, &st, 0); @@ -2326,7 +2339,10 @@ static int attempt_cgi ( { if (server_xtn->query (httpd, client->server, req, tmp->xpath, QSE_HTTPD_SERVERSTD_CGI, &cgi) >= 0 && cgi.cgi) { - script = qse_mbsxdup (tmp->qpath, slash - tmp->qpath , httpd->mmgr); + /* the script name is composed of the orginal query path. + * the pointer held in 'slash' is valid for tmp->qpath as + * tmp->qpath_rp is at most the tail part of tmp->qpath. */ + script = qse_mbsxdup (tmp->qpath, slash - tmp->qpath, httpd->mmgr); suffix = qse_mbsdup (slash, httpd->mmgr); if (!script || !suffix) goto oops; @@ -2351,8 +2367,8 @@ static int attempt_cgi ( } } - /* restore the xpath because it has changed... */ - if (xpath_changed) merge_paths_to_buf (httpd, tmp->root.u.path, tmp->qpath, (qse_size_t)-1, tmp->xpath); + /* restore xpath because it has changed... */ + if (xpath_changed) merge_paths_to_buf (httpd, tmp->root.u.path.val, tmp->qpath_rp, (qse_size_t)-1, tmp->xpath); } return 0; /* not a cgi */ @@ -2363,7 +2379,7 @@ bingo: target->u.cgi.path = tmp->xpath; target->u.cgi.script = script; target->u.cgi.suffix = suffix; - target->u.cgi.root = tmp->root.u.path; + target->u.cgi.root = tmp->root.u.path.val; target->u.cgi.shebang = shebang; return 1; @@ -2387,6 +2403,7 @@ static int make_resource ( QSE_MEMSET (&tmp, 0, QSE_SIZEOF(tmp)); tmp.qpath = qse_htre_getqpath(req); + tmp.qpath_len = qse_mbslen (tmp.qpath); QSE_MEMSET (target, 0, QSE_SIZEOF(*target)); @@ -2411,9 +2428,11 @@ static int make_resource ( return -1; } - /* default to the root directory. */ - if (!tmp.root.u.path) tmp.root.u.path = QSE_MT("/"); + if (!tmp.root.u.path.val) tmp.root.u.path.val = QSE_MT("/"); + + tmp.qpath_rp = (tmp.root.u.path.rpl >= tmp.qpath_len)? + &tmp.qpath[tmp.qpath_len]: &tmp.qpath[tmp.root.u.path.rpl]; if (tmp.realm.authreq && tmp.realm.name) { @@ -2458,7 +2477,7 @@ static int make_resource ( } auth_ok: - tmp.xpath = merge_paths (httpd, tmp.root.u.path, tmp.qpath); + tmp.xpath = merge_paths (httpd, tmp.root.u.path.val, tmp.qpath_rp); if (tmp.xpath == QSE_NULL) return -1; stx = stat_file (httpd, tmp.xpath, &st, 0); @@ -2620,13 +2639,20 @@ static int query_server ( switch (code) { + case QSE_HTTPD_SERVERSTD_SSL: + /* you must specify the certificate and the key file to be able + * to use SSL */ + qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOENT); + return -1; + case QSE_HTTPD_SERVERSTD_NAME: *(const qse_mchar_t**)result = QSE_NULL; break; case QSE_HTTPD_SERVERSTD_ROOT: ((qse_httpd_serverstd_root_t*)result)->type = QSE_HTTPD_SERVERSTD_ROOT_PATH; - ((qse_httpd_serverstd_root_t*)result)->u.path = QSE_NULL; + ((qse_httpd_serverstd_root_t*)result)->u.path.val = QSE_NULL; + ((qse_httpd_serverstd_root_t*)result)->u.path.rpl = 0; break; case QSE_HTTPD_SERVERSTD_REALM: @@ -2685,12 +2711,6 @@ static int query_server ( case QSE_HTTPD_SERVERSTD_FILEACC: *(int*)result = 200; return 0; - - case QSE_HTTPD_SERVERSTD_SSL: - /* you must specify the certificate and the key file to be able - * to use SSL */ - qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOENT); - return -1; } qse_httpd_seterrnum (httpd, QSE_HTTPD_EINVAL); diff --git a/qse/lib/sed/sed.c b/qse/lib/sed/sed.c index 3fccb3e1..cb0aca59 100644 --- a/qse/lib/sed/sed.c +++ b/qse/lib/sed/sed.c @@ -97,9 +97,9 @@ int qse_sed_init (qse_sed_t* sed, qse_mmgr_t* mmgr) if (qse_map_init (&sed->tmp.labs, mmgr, 128, 70, QSE_SIZEOF(qse_char_t), 1) <= -1) goto oops_3; - qse_map_setmancbs ( + qse_map_setstyle ( &sed->tmp.labs, - qse_getmapmancbs(QSE_MAP_MANCBS_INLINE_KEY_COPIER) + qse_getmapstyle(QSE_MAP_STYLE_INLINE_KEY_COPIER) ); /* init_append (sed); */ @@ -3911,7 +3911,7 @@ int qse_sed_exec (qse_sed_t* sed, qse_sed_io_impl_t inf, qse_sed_io_impl_t outf) qse_ssize_t n; int ret = 0; - static qse_map_mancbs_t mancbs = + static qse_map_style_t style = { { QSE_MAP_COPIER_INLINE, @@ -3955,7 +3955,7 @@ int qse_sed_exec (qse_sed_t* sed, qse_sed_io_impl_t inf, qse_sed_io_impl_t outf) return -1; } *(qse_sed_t**)QSE_XTN(&sed->e.out.files) = sed; - qse_map_setmancbs (&sed->e.out.files, &mancbs); + qse_map_setstyle (&sed->e.out.files, &style); sed->e.in.fun = inf; sed->e.in.eof = 0; diff --git a/qse/lib/xli/xli.c b/qse/lib/xli/xli.c index c2715d32..760aaddb 100644 --- a/qse/lib/xli/xli.c +++ b/qse/lib/xli/xli.c @@ -72,8 +72,8 @@ int qse_xli_init (qse_xli_t* xli, qse_mmgr_t* mmgr) ); if (xli->sio_names == QSE_NULL) goto oops; *(qse_xli_t**)QSE_XTN(xli->sio_names) = xli; - qse_htb_setmancbs (xli->sio_names, - qse_gethtbmancbs(QSE_HTB_MANCBS_INLINE_KEY_COPIER) + qse_htb_setstyle (xli->sio_names, + qse_gethtbstyle(QSE_HTB_STYLE_INLINE_KEY_COPIER) ); xli->root.type = QSE_XLI_LIST; @@ -433,9 +433,9 @@ static qse_xli_pair_t* find_pair_byindex ( qse_xli_pair_t* qse_xli_findpairbyname (qse_xli_t* xli, const qse_xli_list_t* list, const qse_char_t* name) { const qse_char_t* ptr; - qse_cstr_t seg; - qse_xli_list_t* curlist; + const qse_xli_list_t* curlist; qse_xli_pair_t* pair; + qse_cstr_t seg; curlist = list? list: &xli->root; @@ -557,9 +557,9 @@ noent: qse_size_t qse_xli_getnumpairsbyname (qse_xli_t* xli, const qse_xli_list_t* list, const qse_char_t* name) { const qse_char_t* ptr; - qse_cstr_t seg; - qse_xli_list_t* curlist; + const qse_xli_list_t* curlist; qse_xli_pair_t* pair; + qse_cstr_t seg; curlist = list? list: &xli->root; @@ -679,7 +679,9 @@ qse_size_t qse_xli_getnumpairsbyname (qse_xli_t* xli, const qse_xli_list_t* list curlist = (qse_xli_list_t*)pair->val; } - return pair; + /* this part must never be reached */ + qse_xli_seterrnum (xli, QSE_XLI_EINTERN, QSE_NULL); + return 0; inval: qse_xli_seterrnum (xli, QSE_XLI_EINVAL, QSE_NULL);