enhanced httpd to relocate when an index file is found for a directory.

enhanced httpd to match host names better
This commit is contained in:
hyung-hwan 2013-03-13 16:50:18 +00:00
parent 5584375bf3
commit a90299e9ce
2 changed files with 52 additions and 13 deletions

View File

@ -374,13 +374,13 @@ static void free_resource (
static loccfg_t* find_loccfg (
qse_httpd_t* httpd, qse_htb_t* cfgtab,
const qse_mchar_t* host, const qse_mchar_t* qpath)
const qse_mchar_t* host, qse_size_t hostlen, const qse_mchar_t* qpath)
{
qse_htb_pair_t* pair;
server_hostcfg_t* hostcfg;
loccfg_t* loccfg;
pair = qse_htb_search (cfgtab, host, qse_mbslen(host));
pair = qse_htb_search (cfgtab, host, hostlen);
if (pair)
{
hostcfg = (server_hostcfg_t*)QSE_HTB_VPTR(pair);
@ -425,7 +425,6 @@ static int query_server (
if (req)
{
const qse_htre_hdrval_t* hosthdr;
const qse_mchar_t* host;
const qse_mchar_t* qpath;
@ -434,14 +433,25 @@ static int query_server (
hosthdr = qse_htre_getheaderval (req, QSE_MT("Host"));
if (hosthdr)
{
const qse_mchar_t* colon;
qse_size_t hostlen;
/* 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);
/* remove :port-number if the host name contains it */
colon = qse_mbsrchr(host, QSE_MT(':'));
if (colon) hostlen = colon - host;
else hostlen = qse_mbslen(hostlen);
loccfg = find_loccfg (httpd, server_xtn->cfgtab, host, hostlen, qpath);
if (loccfg == QSE_NULL && qse_mbscmp(qpath, QSE_MT("/")) != 0)
loccfg = find_loccfg (httpd, server_xtn->cfgtab, host, hostlen, QSE_MT("/"));
}
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("*"), 1, qpath);
}
if (loccfg == QSE_NULL) loccfg = find_loccfg (httpd, server_xtn->cfgtab, QSE_MT("*"), QSE_MT("/"));
if (loccfg == QSE_NULL) loccfg = find_loccfg (httpd, server_xtn->cfgtab, QSE_MT("*"), 1, QSE_MT("/"));
if (loccfg == QSE_NULL) loccfg = &httpd_xtn->dflcfg;
switch (code)

View File

@ -2195,6 +2195,11 @@ static void free_resource (
QSE_MMGR_FREE (httpd->mmgr, (qse_mchar_t*)target->u.cgi.path);
break;
case QSE_HTTPD_RSRC_RELOC:
if (target->u.reloc.dst != qpath)
QSE_MMGR_FREE (httpd->mmgr, (qse_mchar_t*)target->u.reloc.dst);
break;
default:
/* nothing to do */
break;
@ -2284,8 +2289,19 @@ static int attempt_cgi (
{
if (tmp->idxfile)
{
#if 0
script = merge_paths (httpd, tmp->qpath, tmp->idxfile);
if (script == QSE_NULL) goto oops;
#endif
/* create a relocation resource */
target->type = QSE_HTTPD_RSRC_RELOC;
target->u.reloc.dst = merge_paths (httpd, tmp->qpath, tmp->idxfile);
if (target->u.reloc.dst == QSE_NULL) goto oops;
/* free tmp->xpath here upon success since it's not used for relocation.
* it is freed by the called upon failure so the 'oops' part don't free it */
QSE_MMGR_FREE (httpd->mmgr, tmp->xpath);
return 1;
}
else script = (qse_mchar_t*)tmp->qpath;
@ -2575,20 +2591,33 @@ auth_ok:
if (server_xtn->query (httpd, client->server, req, tmp.xpath, QSE_HTTPD_SERVERSTD_FILEACC, &target->u.err.code) <= -1) target->u.err.code = 500;
if (target->u.err.code != 200)
{
target->type = QSE_HTTPD_RSRC_ERR;
/* free xpath since it won't be used */
QSE_MMGR_FREE (httpd->mmgr, tmp.xpath);
target->type = QSE_HTTPD_RSRC_ERR;
}
else
{
/* fall back to a normal file. */
target->type = QSE_HTTPD_RSRC_FILE;
target->u.file.path = tmp.xpath;
if (server_xtn->query (httpd, client->server, req, tmp.xpath, QSE_HTTPD_SERVERSTD_MIME, &target->u.file.mime) <= -1)
if (tmp.idxfile)
{
/* don't care about failure */
target->u.file.mime = QSE_NULL;
/* free xpath since it won't be used */
QSE_MMGR_FREE (httpd->mmgr, tmp.xpath);
/* create a relocation resource */
target->type = QSE_HTTPD_RSRC_RELOC;
target->u.reloc.dst = merge_paths (httpd, tmp.qpath, tmp.idxfile);
if (target->u.reloc.dst == QSE_NULL) return -1;
}
else
{
target->type = QSE_HTTPD_RSRC_FILE;
target->u.file.path = tmp.xpath;
if (server_xtn->query (httpd, client->server, req, tmp.xpath, QSE_HTTPD_SERVERSTD_MIME, &target->u.file.mime) <= -1)
{
/* don't care about failure */
target->u.file.mime = QSE_NULL;
}
}
}
}