added qse_httpd_serverstd_root_t
This commit is contained in:
parent
b420a7c0dc
commit
779d7bc375
@ -180,7 +180,7 @@ static int daemonize (int devnull)
|
|||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
SCFG_NAME,
|
SCFG_NAME,
|
||||||
SCFG_DOCROOT,
|
SCFG_ROOT,
|
||||||
SCFG_REALM,
|
SCFG_REALM,
|
||||||
SCFG_AUTH,
|
SCFG_AUTH,
|
||||||
SCFG_DIRCSS,
|
SCFG_DIRCSS,
|
||||||
@ -250,6 +250,8 @@ struct server_xtn_t
|
|||||||
qse_httpd_serverstd_query_t orgquery;
|
qse_httpd_serverstd_query_t orgquery;
|
||||||
|
|
||||||
qse_mchar_t* scfg[SCFG_MAX];
|
qse_mchar_t* scfg[SCFG_MAX];
|
||||||
|
int root_is_nwad;
|
||||||
|
qse_nwad_t root_nwad;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
@ -438,8 +440,17 @@ static int query_server (
|
|||||||
*(const qse_mchar_t**)result = server_xtn->scfg[SCFG_NAME];
|
*(const qse_mchar_t**)result = server_xtn->scfg[SCFG_NAME];
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case QSE_HTTPD_SERVERSTD_DOCROOT:
|
case QSE_HTTPD_SERVERSTD_ROOT:
|
||||||
*(const qse_mchar_t**)result = server_xtn->scfg[SCFG_DOCROOT];
|
if (server_xtn->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;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
((qse_httpd_serverstd_root_t*)result)->type = QSE_HTTPD_SERVERSTD_ROOT_PATH;
|
||||||
|
((qse_httpd_serverstd_root_t*)result)->u.path = server_xtn->scfg[SCFG_ROOT];
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case QSE_HTTPD_SERVERSTD_REALM:
|
case QSE_HTTPD_SERVERSTD_REALM:
|
||||||
@ -560,7 +571,7 @@ static struct
|
|||||||
} scfg_items[] =
|
} scfg_items[] =
|
||||||
{
|
{
|
||||||
{ QSE_T("host['*'].location['/'].name"), QSE_T("default.name") },
|
{ QSE_T("host['*'].location['/'].name"), QSE_T("default.name") },
|
||||||
{ QSE_T("host['*'].location['/'].docroot"), QSE_T("default.docroot") },
|
{ QSE_T("host['*'].location['/'].root"), QSE_T("default.root") },
|
||||||
{ QSE_T("host['*'].location['/'].realm"), QSE_T("default.realm") },
|
{ QSE_T("host['*'].location['/'].realm"), QSE_T("default.realm") },
|
||||||
{ QSE_T("host['*'].location['/'].auth"), QSE_T("default.auth") },
|
{ QSE_T("host['*'].location['/'].auth"), QSE_T("default.auth") },
|
||||||
{ QSE_T("host['*'].location['/'].dir-css"), QSE_T("default.dir-css") },
|
{ QSE_T("host['*'].location['/'].dir-css"), QSE_T("default.dir-css") },
|
||||||
@ -830,6 +841,7 @@ static int load_server_config (
|
|||||||
qse_printf (QSE_T("WARNING: no colon in the auth string - [%hs]\n"), server_xtn->scfg[SCFG_AUTH]);
|
qse_printf (QSE_T("WARNING: no colon in the auth string - [%hs]\n"), server_xtn->scfg[SCFG_AUTH]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (qse_mbstonwad (server_xtn->scfg[SCFG_ROOT], &server_xtn->root_nwad) >= 0) server_xtn->root_is_nwad = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,8 @@ default {
|
|||||||
# generated by httpd.
|
# generated by httpd.
|
||||||
name = "QSEHTTPD v1";
|
name = "QSEHTTPD v1";
|
||||||
|
|
||||||
docroot = "/";
|
# document root
|
||||||
|
root = "/";
|
||||||
|
|
||||||
realm = "default realm";
|
realm = "default realm";
|
||||||
auth = "username:password";
|
auth = "username:password";
|
||||||
@ -71,7 +72,7 @@ server {
|
|||||||
#name = "QSEHTTPD v1";
|
#name = "QSEHTTPD v1";
|
||||||
|
|
||||||
# uncomment the followng block to override the default.
|
# uncomment the followng block to override the default.
|
||||||
#docroot = "/var/www";
|
#root = "/var/www";
|
||||||
|
|
||||||
# uncomment the followng block to override the default.
|
# uncomment the followng block to override the default.
|
||||||
# if you want to disable authentication while the default
|
# if you want to disable authentication while the default
|
||||||
@ -109,7 +110,7 @@ server {
|
|||||||
# virtual hosts are not supported yet.
|
# virtual hosts are not supported yet.
|
||||||
#host "www.google.com" {
|
#host "www.google.com" {
|
||||||
# location "/" {
|
# location "/" {
|
||||||
# docroot = "/home/www/google";
|
# root = "/home/www/google";
|
||||||
# auth {
|
# auth {
|
||||||
# realm = "jjjjjjjj";
|
# realm = "jjjjjjjj";
|
||||||
# name = "www.google.com";
|
# name = "www.google.com";
|
||||||
|
@ -474,7 +474,7 @@ struct qse_httpd_rsrc_cgi_t
|
|||||||
const qse_mchar_t* path;
|
const qse_mchar_t* path;
|
||||||
const qse_mchar_t* script;
|
const qse_mchar_t* script;
|
||||||
const qse_mchar_t* suffix;
|
const qse_mchar_t* suffix;
|
||||||
const qse_mchar_t* docroot;
|
const qse_mchar_t* root;
|
||||||
const qse_mchar_t* shebang;
|
const qse_mchar_t* shebang;
|
||||||
int nph;
|
int nph;
|
||||||
};
|
};
|
||||||
|
@ -33,7 +33,7 @@ struct task_cgi_arg_t
|
|||||||
qse_mcstr_t path;
|
qse_mcstr_t path;
|
||||||
qse_mcstr_t script;
|
qse_mcstr_t script;
|
||||||
qse_mcstr_t suffix;
|
qse_mcstr_t suffix;
|
||||||
qse_mcstr_t docroot;
|
qse_mcstr_t root;
|
||||||
qse_mcstr_t shebang;
|
qse_mcstr_t shebang;
|
||||||
int nph;
|
int nph;
|
||||||
qse_htre_t* req;
|
qse_htre_t* req;
|
||||||
@ -48,7 +48,7 @@ struct task_cgi_t
|
|||||||
const qse_mchar_t* path;
|
const qse_mchar_t* path;
|
||||||
const qse_mchar_t* script;
|
const qse_mchar_t* script;
|
||||||
const qse_mchar_t* suffix;
|
const qse_mchar_t* suffix;
|
||||||
const qse_mchar_t* docroot;
|
const qse_mchar_t* root;
|
||||||
const qse_mchar_t* shebang;
|
const qse_mchar_t* shebang;
|
||||||
qse_http_version_t version;
|
qse_http_version_t version;
|
||||||
int keepalive; /* taken from the request */
|
int keepalive; /* taken from the request */
|
||||||
@ -427,7 +427,7 @@ static int cgi_add_env (
|
|||||||
const qse_mchar_t* path,
|
const qse_mchar_t* path,
|
||||||
const qse_mchar_t* script,
|
const qse_mchar_t* script,
|
||||||
const qse_mchar_t* suffix,
|
const qse_mchar_t* suffix,
|
||||||
const qse_mchar_t* docroot,
|
const qse_mchar_t* root,
|
||||||
const qse_mchar_t* content_type,
|
const qse_mchar_t* content_type,
|
||||||
qse_size_t content_length,
|
qse_size_t content_length,
|
||||||
int chunked)
|
int chunked)
|
||||||
@ -455,13 +455,13 @@ static int cgi_add_env (
|
|||||||
|
|
||||||
qse_env_insertmbs (env, QSE_MT("SCRIPT_FILENAME"), path);
|
qse_env_insertmbs (env, QSE_MT("SCRIPT_FILENAME"), path);
|
||||||
qse_env_insertmbs (env, QSE_MT("SCRIPT_NAME"), script);
|
qse_env_insertmbs (env, QSE_MT("SCRIPT_NAME"), script);
|
||||||
qse_env_insertmbs (env, QSE_MT("DOCUMENT_ROOT"), docroot);
|
qse_env_insertmbs (env, QSE_MT("DOCUMENT_ROOT"), root);
|
||||||
if (suffix && suffix[0] != QSE_MT('\0'))
|
if (suffix && suffix[0] != QSE_MT('\0'))
|
||||||
{
|
{
|
||||||
const qse_mchar_t* tmp[3];
|
const qse_mchar_t* tmp[3];
|
||||||
qse_mchar_t* tr;
|
qse_mchar_t* tr;
|
||||||
|
|
||||||
tmp[0] = docroot;
|
tmp[0] = root;
|
||||||
tmp[1] = suffix;
|
tmp[1] = suffix;
|
||||||
tmp[2] = QSE_NULL;
|
tmp[2] = QSE_NULL;
|
||||||
|
|
||||||
@ -738,12 +738,12 @@ static int task_init_cgi (
|
|||||||
cgi->path = (qse_mchar_t*)(cgi + 1);
|
cgi->path = (qse_mchar_t*)(cgi + 1);
|
||||||
cgi->script = cgi->path + arg->path.len + 1;
|
cgi->script = cgi->path + arg->path.len + 1;
|
||||||
cgi->suffix = cgi->script + arg->script.len + 1;
|
cgi->suffix = cgi->script + arg->script.len + 1;
|
||||||
cgi->docroot = cgi->suffix + arg->suffix.len + 1;
|
cgi->root = cgi->suffix + arg->suffix.len + 1;
|
||||||
cgi->shebang = cgi->docroot + arg->docroot.len + 1;
|
cgi->shebang = cgi->root + arg->root.len + 1;
|
||||||
qse_mbscpy ((qse_mchar_t*)cgi->path, arg->path.ptr);
|
qse_mbscpy ((qse_mchar_t*)cgi->path, arg->path.ptr);
|
||||||
qse_mbscpy ((qse_mchar_t*)cgi->script, arg->script.ptr);
|
qse_mbscpy ((qse_mchar_t*)cgi->script, arg->script.ptr);
|
||||||
qse_mbscpy ((qse_mchar_t*)cgi->suffix, arg->suffix.ptr);
|
qse_mbscpy ((qse_mchar_t*)cgi->suffix, arg->suffix.ptr);
|
||||||
qse_mbscpy ((qse_mchar_t*)cgi->docroot, arg->docroot.ptr);
|
qse_mbscpy ((qse_mchar_t*)cgi->root, arg->root.ptr);
|
||||||
qse_mbscpy ((qse_mchar_t*)cgi->shebang, arg->shebang.ptr);
|
qse_mbscpy ((qse_mchar_t*)cgi->shebang, arg->shebang.ptr);
|
||||||
|
|
||||||
cgi->version = *qse_htre_getversion(arg->req);
|
cgi->version = *qse_htre_getversion(arg->req);
|
||||||
@ -884,7 +884,7 @@ done:
|
|||||||
|
|
||||||
if (cgi_add_env (
|
if (cgi_add_env (
|
||||||
httpd, client, cgi->env, arg->req,
|
httpd, client, cgi->env, arg->req,
|
||||||
cgi->path, cgi->script, cgi->suffix, cgi->docroot,
|
cgi->path, cgi->script, cgi->suffix, cgi->root,
|
||||||
(tmp? tmp->ptr: QSE_NULL), content_length,
|
(tmp? tmp->ptr: QSE_NULL), content_length,
|
||||||
(cgi->reqflags & CGI_REQ_FWDCHUNKED)) <= -1)
|
(cgi->reqflags & CGI_REQ_FWDCHUNKED)) <= -1)
|
||||||
{
|
{
|
||||||
@ -1523,7 +1523,7 @@ qse_httpd_task_t* qse_httpd_entaskcgi (
|
|||||||
rsrc = *cgi;
|
rsrc = *cgi;
|
||||||
if (rsrc.script == QSE_NULL) rsrc.script = qse_htre_getqpath(req);
|
if (rsrc.script == QSE_NULL) rsrc.script = qse_htre_getqpath(req);
|
||||||
if (rsrc.suffix == QSE_NULL) rsrc.suffix = QSE_MT("");
|
if (rsrc.suffix == QSE_NULL) rsrc.suffix = QSE_MT("");
|
||||||
if (rsrc.docroot == QSE_NULL) rsrc.docroot = QSE_MT("");
|
if (rsrc.root == QSE_NULL) rsrc.root = QSE_MT("");
|
||||||
if (rsrc.shebang == QSE_NULL) rsrc.shebang = QSE_MT("");
|
if (rsrc.shebang == QSE_NULL) rsrc.shebang = QSE_MT("");
|
||||||
|
|
||||||
arg.path.ptr = rsrc.path;
|
arg.path.ptr = rsrc.path;
|
||||||
@ -1532,8 +1532,8 @@ qse_httpd_task_t* qse_httpd_entaskcgi (
|
|||||||
arg.script.len = qse_mbslen(rsrc.script);
|
arg.script.len = qse_mbslen(rsrc.script);
|
||||||
arg.suffix.ptr = rsrc.suffix;
|
arg.suffix.ptr = rsrc.suffix;
|
||||||
arg.suffix.len = qse_mbslen(rsrc.suffix);
|
arg.suffix.len = qse_mbslen(rsrc.suffix);
|
||||||
arg.docroot.ptr = rsrc.docroot;
|
arg.root.ptr = rsrc.root;
|
||||||
arg.docroot.len = qse_mbslen(rsrc.docroot);
|
arg.root.len = qse_mbslen(rsrc.root);
|
||||||
arg.nph = rsrc.nph;
|
arg.nph = rsrc.nph;
|
||||||
arg.shebang.ptr = rsrc.shebang;
|
arg.shebang.ptr = rsrc.shebang;
|
||||||
arg.shebang.len = qse_mbslen(rsrc.shebang);
|
arg.shebang.len = qse_mbslen(rsrc.shebang);
|
||||||
@ -1551,7 +1551,7 @@ qse_httpd_task_t* qse_httpd_entaskcgi (
|
|||||||
((arg.path.len + 1) * QSE_SIZEOF(*arg.path.ptr)) +
|
((arg.path.len + 1) * QSE_SIZEOF(*arg.path.ptr)) +
|
||||||
((arg.script.len + 1) * QSE_SIZEOF(*arg.script.ptr)) +
|
((arg.script.len + 1) * QSE_SIZEOF(*arg.script.ptr)) +
|
||||||
((arg.suffix.len + 1) * QSE_SIZEOF(*arg.suffix.ptr)) +
|
((arg.suffix.len + 1) * QSE_SIZEOF(*arg.suffix.ptr)) +
|
||||||
((arg.docroot.len + 1) * QSE_SIZEOF(*arg.docroot.ptr)) +
|
((arg.root.len + 1) * QSE_SIZEOF(*arg.root.ptr)) +
|
||||||
((arg.shebang.len + 1) * QSE_SIZEOF(*arg.shebang.ptr))
|
((arg.shebang.len + 1) * QSE_SIZEOF(*arg.shebang.ptr))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2239,7 +2239,7 @@ struct rsrc_tmp_t
|
|||||||
const qse_mchar_t* idxfile;
|
const qse_mchar_t* idxfile;
|
||||||
qse_mchar_t* xpath;
|
qse_mchar_t* xpath;
|
||||||
|
|
||||||
const qse_mchar_t* docroot;
|
qse_httpd_serverstd_root_t root;
|
||||||
const qse_mchar_t* realm;
|
const qse_mchar_t* realm;
|
||||||
const qse_mchar_t* auth;
|
const qse_mchar_t* auth;
|
||||||
qse_httpd_serverstd_index_t index;
|
qse_httpd_serverstd_index_t index;
|
||||||
@ -2261,7 +2261,7 @@ static int attempt_cgi (
|
|||||||
|
|
||||||
if (tmp->final_match)
|
if (tmp->final_match)
|
||||||
{
|
{
|
||||||
/* it is a final match. tmp->xpath is tmp->docroot + tmp->qpath */
|
/* it is a final match. tmp->xpath is tmp->root + tmp->qpath */
|
||||||
if (server_xtn->query (httpd, client->server, req, tmp->xpath, QSE_HTTPD_SERVERSTD_CGI, &cgi) >= 0 && cgi.cgi)
|
if (server_xtn->query (httpd, client->server, req, tmp->xpath, QSE_HTTPD_SERVERSTD_CGI, &cgi) >= 0 && cgi.cgi)
|
||||||
{
|
{
|
||||||
if (tmp->idxfile)
|
if (tmp->idxfile)
|
||||||
@ -2304,7 +2304,7 @@ static int attempt_cgi (
|
|||||||
*
|
*
|
||||||
* tmp->xpath should be large enough to hold the merge path made of
|
* tmp->xpath should be large enough to hold the merge path made of
|
||||||
* the subsegments of the original query path and docroot. */
|
* the subsegments of the original query path and docroot. */
|
||||||
merge_paths_to_buf (httpd, tmp->docroot, tmp->qpath, slash - tmp->qpath, tmp->xpath);
|
merge_paths_to_buf (httpd, tmp->root.u.path, tmp->qpath, slash - tmp->qpath, tmp->xpath);
|
||||||
xpath_changed = 1;
|
xpath_changed = 1;
|
||||||
|
|
||||||
stx = stat_file (httpd, tmp->xpath, &st, 0);
|
stx = stat_file (httpd, tmp->xpath, &st, 0);
|
||||||
@ -2346,7 +2346,7 @@ static int attempt_cgi (
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* restore the xpath because it has changed... */
|
/* restore the xpath because it has changed... */
|
||||||
if (xpath_changed) merge_paths_to_buf (httpd, tmp->docroot, tmp->qpath, (qse_size_t)-1, tmp->xpath);
|
if (xpath_changed) merge_paths_to_buf (httpd, tmp->root.u.path, tmp->qpath, (qse_size_t)-1, tmp->xpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0; /* not a cgi */
|
return 0; /* not a cgi */
|
||||||
@ -2357,7 +2357,7 @@ bingo:
|
|||||||
target->u.cgi.path = tmp->xpath;
|
target->u.cgi.path = tmp->xpath;
|
||||||
target->u.cgi.script = script;
|
target->u.cgi.script = script;
|
||||||
target->u.cgi.suffix = suffix;
|
target->u.cgi.suffix = suffix;
|
||||||
target->u.cgi.docroot = tmp->docroot;
|
target->u.cgi.root = tmp->root.u.path;
|
||||||
target->u.cgi.shebang = shebang;
|
target->u.cgi.shebang = shebang;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@ -2386,7 +2386,18 @@ static int make_resource (
|
|||||||
|
|
||||||
server_xtn = qse_httpd_getserverxtn (httpd, client->server);
|
server_xtn = qse_httpd_getserverxtn (httpd, client->server);
|
||||||
|
|
||||||
if (server_xtn->query (httpd, client->server, req, tmp.xpath, QSE_HTTPD_SERVERSTD_DOCROOT, &tmp.docroot) <= -1) return -1;
|
if (server_xtn->query (httpd, client->server, req, tmp.xpath, QSE_HTTPD_SERVERSTD_ROOT, &tmp.root) <= -1) return -1;
|
||||||
|
if (tmp.root.type == QSE_HTTPD_SERVERSTD_ROOT_NWAD)
|
||||||
|
{
|
||||||
|
/* proxy the request */
|
||||||
|
target->type = QSE_HTTPD_RSRC_PROXY;
|
||||||
|
/*target->u.proxy.dst = client->orgdst_addr;*/
|
||||||
|
target->u.proxy.dst = tmp.root.u.nwad;
|
||||||
|
target->u.proxy.src = client->remote_addr;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSE_ASSERT (tmp.root.type == QSE_HTTPD_SERVERSTD_ROOT_PATH);
|
||||||
|
|
||||||
if (server_xtn->query (httpd, client->server, req, tmp.xpath, QSE_HTTPD_SERVERSTD_REALM, &tmp.realm) <= -1 ||
|
if (server_xtn->query (httpd, client->server, req, tmp.xpath, QSE_HTTPD_SERVERSTD_REALM, &tmp.realm) <= -1 ||
|
||||||
server_xtn->query (httpd, client->server, req, tmp.xpath, QSE_HTTPD_SERVERSTD_AUTH, &tmp.auth) <= -1 ||
|
server_xtn->query (httpd, client->server, req, tmp.xpath, QSE_HTTPD_SERVERSTD_AUTH, &tmp.auth) <= -1 ||
|
||||||
@ -2396,7 +2407,7 @@ static int make_resource (
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* default to the root directory. */
|
/* default to the root directory. */
|
||||||
if (!tmp.docroot) tmp.docroot = QSE_MT("/");
|
if (!tmp.root.u.path) tmp.root.u.path = QSE_MT("/");
|
||||||
|
|
||||||
if (tmp.realm && tmp.auth)
|
if (tmp.realm && tmp.auth)
|
||||||
{
|
{
|
||||||
@ -2438,7 +2449,7 @@ static int make_resource (
|
|||||||
}
|
}
|
||||||
|
|
||||||
auth_ok:
|
auth_ok:
|
||||||
tmp.xpath = merge_paths (httpd, tmp.docroot, tmp.qpath);
|
tmp.xpath = merge_paths (httpd, tmp.root.u.path, tmp.qpath);
|
||||||
if (tmp.xpath == QSE_NULL) return -1;
|
if (tmp.xpath == QSE_NULL) return -1;
|
||||||
|
|
||||||
stx = stat_file (httpd, tmp.xpath, &st, 0);
|
stx = stat_file (httpd, tmp.xpath, &st, 0);
|
||||||
@ -2601,7 +2612,14 @@ static int query_server (
|
|||||||
switch (code)
|
switch (code)
|
||||||
{
|
{
|
||||||
case QSE_HTTPD_SERVERSTD_NAME:
|
case QSE_HTTPD_SERVERSTD_NAME:
|
||||||
case QSE_HTTPD_SERVERSTD_DOCROOT:
|
*(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;
|
||||||
|
break;
|
||||||
|
|
||||||
case QSE_HTTPD_SERVERSTD_REALM:
|
case QSE_HTTPD_SERVERSTD_REALM:
|
||||||
case QSE_HTTPD_SERVERSTD_AUTH:
|
case QSE_HTTPD_SERVERSTD_AUTH:
|
||||||
case QSE_HTTPD_SERVERSTD_ERRCSS:
|
case QSE_HTTPD_SERVERSTD_ERRCSS:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user