added QSE_HTTPD_SERVERSTD_PSEUDONYM

This commit is contained in:
hyung-hwan 2014-07-30 16:42:25 +00:00
parent ae759f21e3
commit 019475149c
6 changed files with 100 additions and 13 deletions

View File

@ -72,6 +72,7 @@ enum
XCFG_DIRFOOT, XCFG_DIRFOOT,
XCFG_ERRHEAD, XCFG_ERRHEAD,
XCFG_ERRFOOT, XCFG_ERRFOOT,
XCFG_PSEUDONYM,
XCFG_MAX XCFG_MAX
}; };
@ -593,6 +594,10 @@ static int query_server (
*(const qse_mchar_t**)result = loccfg->xcfg[XCFG_ERRFOOT]; *(const qse_mchar_t**)result = loccfg->xcfg[XCFG_ERRFOOT];
return 0; return 0;
case QSE_HTTPD_SERVERSTD_PSEUDONYM:
*(const qse_mchar_t**)result = loccfg->xcfg[XCFG_PSEUDONYM];
return 0;
case QSE_HTTPD_SERVERSTD_INDEX: case QSE_HTTPD_SERVERSTD_INDEX:
((qse_httpd_serverstd_index_t*)result)->count = loccfg->index.count; ((qse_httpd_serverstd_index_t*)result)->count = loccfg->index.count;
((qse_httpd_serverstd_index_t*)result)->files = loccfg->index.files; ((qse_httpd_serverstd_index_t*)result)->files = loccfg->index.files;
@ -731,6 +736,7 @@ static struct
{ QSE_T("dir-foot"), QSE_T("server-default.dir-foot") }, { QSE_T("dir-foot"), QSE_T("server-default.dir-foot") },
{ QSE_T("error-head"), QSE_T("server-default.error-head") }, { QSE_T("error-head"), QSE_T("server-default.error-head") },
{ QSE_T("error-foot"), QSE_T("server-default.error-foot") }, { QSE_T("error-foot"), QSE_T("server-default.error-foot") },
{ QSE_T("pseudonym"), QSE_T("server-default.pseudonym") }
}; };
static struct static struct
@ -1425,6 +1431,7 @@ static int open_config_file (qse_httpd_t* httpd)
{ QSE_T("server-default.dir-foot"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } }, { QSE_T("server-default.dir-foot"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
{ QSE_T("server-default.error-head"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } }, { QSE_T("server-default.error-head"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
{ QSE_T("server-default.error-foot"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } }, { QSE_T("server-default.error-foot"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
{ QSE_T("server-default.pseudonym"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
{ QSE_T("server"), { QSE_XLI_SCM_VALLIST, 0, 0 } }, { QSE_T("server"), { QSE_XLI_SCM_VALLIST, 0, 0 } },
{ QSE_T("server.bind"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } }, { QSE_T("server.bind"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
@ -1464,7 +1471,8 @@ static int open_config_file (qse_httpd_t* httpd)
{ QSE_T("server.host.location.dir-head"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } }, { QSE_T("server.host.location.dir-head"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
{ QSE_T("server.host.location.dir-foot"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } }, { QSE_T("server.host.location.dir-foot"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
{ QSE_T("server.host.location.error-head"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } }, { QSE_T("server.host.location.error-head"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
{ QSE_T("server.host.location.error-foot"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } } { QSE_T("server.host.location.error-foot"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } },
{ QSE_T("server.host.location.pseudonym"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } }
}; };

View File

@ -23,6 +23,9 @@ server-default {
#################################################################### ####################################################################
root = "/var/www"; root = "/var/www";
# pseudonym to use in Via: for proxying
#pseudonym = "my-host";
realm = "default realm"; realm = "default realm";
auth = "username:password"; auth = "username:password";
index = "index.html", index = "index.html",
@ -119,6 +122,9 @@ server {
# uncomment the followng block to override the default. # uncomment the followng block to override the default.
#root = "/var/www"; #root = "/var/www";
# pseudonym to use in Via: for proxying
#pseudonym = "my-host";
# 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
# enables it, don't put a value like 'realm;' # enables it, don't put a value like 'realm;'

View File

@ -537,6 +537,8 @@ struct qse_httpd_rsrc_proxy_t
qse_nwad_t nwad; qse_nwad_t nwad;
const qse_mchar_t* str; const qse_mchar_t* str;
} dst; /* remote destination address to connect to */ } dst; /* remote destination address to connect to */
const qse_mchar_t* pseudonym; /* pseudonym to use in Via: */
}; };
typedef struct qse_httpd_rsrc_dir_t qse_httpd_rsrc_dir_t; typedef struct qse_httpd_rsrc_dir_t qse_httpd_rsrc_dir_t;

View File

@ -114,12 +114,13 @@ enum qse_httpd_serverstd_query_code_t
QSE_HTTPD_SERVERSTD_DIRHEAD, /* const qse_mchar_t* */ QSE_HTTPD_SERVERSTD_DIRHEAD, /* const qse_mchar_t* */
QSE_HTTPD_SERVERSTD_DIRFOOT, /* const qse_mchar_t* */ QSE_HTTPD_SERVERSTD_DIRFOOT, /* const qse_mchar_t* */
QSE_HTTPD_SERVERSTD_PSEUDONYM, /* const qse_mchar_t*, pseudonym to use in Via: */
QSE_HTTPD_SERVERSTD_INDEX, /* qse_httpd_serverstd_index_t */ QSE_HTTPD_SERVERSTD_INDEX, /* qse_httpd_serverstd_index_t */
QSE_HTTPD_SERVERSTD_CGI, /* qse_httpd_serverstd_cgi_t */ QSE_HTTPD_SERVERSTD_CGI, /* qse_httpd_serverstd_cgi_t */
QSE_HTTPD_SERVERSTD_MIME, /* const qse_mchar_t* */ QSE_HTTPD_SERVERSTD_MIME, /* const qse_mchar_t* */
QSE_HTTPD_SERVERSTD_DIRACC, /* int (http error code) */ QSE_HTTPD_SERVERSTD_DIRACC, /* int (http error code) */
QSE_HTTPD_SERVERSTD_FILEACC, /* int (http error code) */ QSE_HTTPD_SERVERSTD_FILEACC /* int (http error code) */
}; };
typedef enum qse_httpd_serverstd_query_code_t qse_httpd_serverstd_query_code_t; typedef enum qse_httpd_serverstd_query_code_t qse_httpd_serverstd_query_code_t;

View File

@ -51,6 +51,7 @@ struct task_proxy_t
int keepalive; /* taken from the request */ int keepalive; /* taken from the request */
int raw; int raw;
qse_mchar_t* pseudonym;
qse_htrd_t* peer_htrd; qse_htrd_t* peer_htrd;
qse_mchar_t* peer_name; qse_mchar_t* peer_name;
@ -180,16 +181,26 @@ static int proxy_capture_peer_header (qse_htre_t* req, const qse_mchar_t* key, c
if (qse_mbscasecmp (key, QSE_MT("Via")) == 0) if (qse_mbscasecmp (key, QSE_MT("Via")) == 0)
{ {
qse_mchar_t extra[128]; qse_mchar_t extra[128];
const qse_mchar_t* pseudonym;
proxy->flags |= PROXY_VIA_RETURNING; proxy->flags |= PROXY_VIA_RETURNING;
if (proxy->pseudonym[0])
{
pseudonym = proxy->pseudonym;
}
else
{
qse_nwadtombs (&proxy->client->local_addr, extra, QSE_COUNTOF(extra), QSE_NWADTOMBS_ALL); qse_nwadtombs (&proxy->client->local_addr, extra, QSE_COUNTOF(extra), QSE_NWADTOMBS_ALL);
pseudonym = extra;
}
return proxy_add_header_to_buffer_with_extra_data ( return proxy_add_header_to_buffer_with_extra_data (
proxy, proxy->res, key, val, proxy, proxy->res, key, val,
QSE_MT(", %d.%d %hs (%hs)"), QSE_MT(", %d.%d %hs (%hs)"),
(int)proxy->version.major, (int)proxy->version.major,
(int)proxy->version.minor, (int)proxy->version.minor,
extra, pseudonym,
qse_httpd_getname(proxy->httpd)); qse_httpd_getname(proxy->httpd));
} }
} }
@ -245,16 +256,25 @@ static int proxy_capture_client_header (qse_htre_t* req, const qse_mchar_t* key,
if (qse_mbscasecmp (key, QSE_MT("Via")) == 0) if (qse_mbscasecmp (key, QSE_MT("Via")) == 0)
{ {
qse_mchar_t extra[128]; qse_mchar_t extra[128];
const qse_mchar_t* pseudonym;
proxy->flags |= PROXY_VIA; proxy->flags |= PROXY_VIA;
if (proxy->pseudonym[0])
{
pseudonym = proxy->pseudonym;
}
else
{
qse_nwadtombs (&proxy->client->local_addr, extra, QSE_COUNTOF(extra), QSE_NWADTOMBS_ALL); qse_nwadtombs (&proxy->client->local_addr, extra, QSE_COUNTOF(extra), QSE_NWADTOMBS_ALL);
pseudonym = extra;
}
return proxy_add_header_to_buffer_with_extra_data ( return proxy_add_header_to_buffer_with_extra_data (
proxy, proxy->reqfwdbuf, key, val, proxy, proxy->reqfwdbuf, key, val,
QSE_MT(", %d.%d %hs (%hs)"), QSE_MT(", %d.%d %hs (%hs)"),
(int)proxy->version.major, (int)proxy->version.major,
(int)proxy->version.minor, (int)proxy->version.minor,
extra, pseudonym,
qse_httpd_getname(proxy->httpd)); qse_httpd_getname(proxy->httpd));
} }
} }
@ -673,16 +693,26 @@ static int proxy_htrd_peek_peer_output (qse_htrd_t* htrd, qse_htre_t* res)
/* add the Via: header into the response if it is not 100. */ /* add the Via: header into the response if it is not 100. */
qse_size_t tmp; qse_size_t tmp;
qse_mchar_t extra[128]; qse_mchar_t extra[128];
const qse_mchar_t* pseudonym;
qse_http_version_t v; qse_http_version_t v;
proxy->flags |= PROXY_VIA_RETURNING; proxy->flags |= PROXY_VIA_RETURNING;
v = *qse_htre_getversion(res); v = *qse_htre_getversion(res);
if (proxy->pseudonym[0])
{
pseudonym = proxy->pseudonym;
}
else
{
qse_nwadtombs (&proxy->client->local_addr, extra, QSE_COUNTOF(extra), QSE_NWADTOMBS_ALL); qse_nwadtombs (&proxy->client->local_addr, extra, QSE_COUNTOF(extra), QSE_NWADTOMBS_ALL);
pseudonym = extra;
}
tmp = qse_mbs_fcat ( tmp = qse_mbs_fcat (
proxy->res, QSE_MT("Via: %d.%d %hs (%hs)\r\n"), proxy->res, QSE_MT("Via: %d.%d %hs (%hs)\r\n"),
(int)v.major, (int)v.minor, (int)v.major, (int)v.minor,
extra, qse_httpd_getname(httpd)); pseudonym, qse_httpd_getname(httpd));
if (tmp == (qse_size_t)-1) if (tmp == (qse_size_t)-1)
{ {
httpd->errnum = QSE_HTTPD_ENOMEM; httpd->errnum = QSE_HTTPD_ENOMEM;
@ -860,6 +890,17 @@ static int task_init_proxy (
proxy->version = *qse_htre_getversion(arg->req); proxy->version = *qse_htre_getversion(arg->req);
proxy->keepalive = (arg->req->attr.flags & QSE_HTRE_ATTR_KEEPALIVE); proxy->keepalive = (arg->req->attr.flags & QSE_HTRE_ATTR_KEEPALIVE);
proxy->pseudonym = (qse_mchar_t*)(proxy + 1);
if (arg->rsrc->pseudonym)
{
len = qse_mbscpy (proxy->pseudonym, arg->rsrc->pseudonym);
}
else
{
proxy->pseudonym[0] = QSE_MT('\0');
len = 0;
}
if (arg->rsrc->flags & QSE_HTTPD_RSRC_PROXY_RAW) proxy->flags |= PROXY_RAW; if (arg->rsrc->flags & QSE_HTTPD_RSRC_PROXY_RAW) proxy->flags |= PROXY_RAW;
proxy->peer.local = arg->rsrc->src.nwad; proxy->peer.local = arg->rsrc->src.nwad;
if (arg->rsrc->flags & QSE_HTTPD_RSRC_PROXY_DST_STR) if (arg->rsrc->flags & QSE_HTTPD_RSRC_PROXY_DST_STR)
@ -867,7 +908,7 @@ static int task_init_proxy (
qse_mchar_t* colon; qse_mchar_t* colon;
proxy->flags |= PROXY_RESOL_PEER_NAME; proxy->flags |= PROXY_RESOL_PEER_NAME;
proxy->peer_name = (qse_mchar_t*)(proxy + 1); proxy->peer_name = proxy->pseudonym + len + 1;
qse_mbscpy (proxy->peer_name, arg->rsrc->dst.str); qse_mbscpy (proxy->peer_name, arg->rsrc->dst.str);
colon = qse_mbschr (proxy->peer_name, QSE_MT(':')); colon = qse_mbschr (proxy->peer_name, QSE_MT(':'));
@ -970,14 +1011,23 @@ static int task_init_proxy (
/* add the Via: header into the request */ /* add the Via: header into the request */
qse_size_t tmp; qse_size_t tmp;
qse_mchar_t extra[128]; qse_mchar_t extra[128];
const qse_mchar_t* pseudonym;
proxy->flags |= PROXY_VIA; proxy->flags |= PROXY_VIA;
if (proxy->pseudonym[0])
{
pseudonym = proxy->pseudonym;
}
else
{
qse_nwadtombs (&proxy->client->local_addr, extra, QSE_COUNTOF(extra), QSE_NWADTOMBS_ALL); qse_nwadtombs (&proxy->client->local_addr, extra, QSE_COUNTOF(extra), QSE_NWADTOMBS_ALL);
pseudonym = extra;
}
tmp = qse_mbs_fcat ( tmp = qse_mbs_fcat (
proxy->reqfwdbuf, QSE_MT("Via: %d.%d %hs (%hs)\r\n"), proxy->reqfwdbuf, QSE_MT("Via: %d.%d %hs (%hs)\r\n"),
(int)proxy->version.major, (int)proxy->version.minor, (int)proxy->version.major, (int)proxy->version.minor,
extra, qse_httpd_getname(httpd)); pseudonym, qse_httpd_getname(httpd));
if (tmp == (qse_size_t)-1) goto oops; if (tmp == (qse_size_t)-1) goto oops;
} }
@ -1931,8 +1981,14 @@ qse_httpd_task_t* qse_httpd_entaskproxy (
arg.rsrc = proxy; arg.rsrc = proxy;
arg.req = req; arg.req = req;
if (proxy->pseudonym)
xtnsize += qse_mbslen (proxy->pseudonym) + 1;
else
xtnsize += 1;
if (proxy->flags & QSE_HTTPD_RSRC_PROXY_DST_STR) if (proxy->flags & QSE_HTTPD_RSRC_PROXY_DST_STR)
xtnsize = qse_mbslen (proxy->dst.str) + 1; xtnsize += qse_mbslen (proxy->dst.str) + 1;
QSE_MEMSET (&task, 0, QSE_SIZEOF(task)); QSE_MEMSET (&task, 0, QSE_SIZEOF(task));
task.init = task_init_proxy; task.init = task_init_proxy;

View File

@ -3354,6 +3354,10 @@ static int make_resource (
target->u.proxy.src.nwad.type = target->u.proxy.dst.nwad.type; target->u.proxy.src.nwad.type = target->u.proxy.dst.nwad.type;
} }
/* pseudonym for raw proxying should not be useful. set it for consistency */
if (server_xtn->query (httpd, client->server, QSE_NULL, QSE_NULL, QSE_HTTPD_SERVERSTD_PSEUDONYM, &target->u.proxy.pseudonym) <= -1)
target->u.proxy.pseudonym = QSE_NULL;
/* mark that this request is going to be proxied. */ /* mark that this request is going to be proxied. */
req->attr.flags |= QSE_HTRE_ATTR_PROXIED; req->attr.flags |= QSE_HTRE_ATTR_PROXIED;
return 0; return 0;
@ -3394,6 +3398,9 @@ static int make_resource (
target->u.proxy.src.nwad.type = target->u.proxy.dst.nwad.type; target->u.proxy.src.nwad.type = target->u.proxy.dst.nwad.type;
} }
if (server_xtn->query (httpd, client->server, QSE_NULL, QSE_NULL, QSE_HTTPD_SERVERSTD_PSEUDONYM, &target->u.proxy.pseudonym) <= -1)
target->u.proxy.pseudonym = QSE_NULL;
/* TODO: refrain from manipulating the request like this */ /* TODO: refrain from manipulating the request like this */
req->u.q.path = slash; /* TODO: use setqpath or something... */ req->u.q.path = slash; /* TODO: use setqpath or something... */
@ -3418,6 +3425,9 @@ static int make_resource (
target->u.proxy.dst.nwad = tmp.root.u.nwad; target->u.proxy.dst.nwad = tmp.root.u.nwad;
target->u.proxy.src.nwad.type = target->u.proxy.dst.nwad.type; target->u.proxy.src.nwad.type = target->u.proxy.dst.nwad.type;
if (server_xtn->query (httpd, client->server, QSE_NULL, QSE_NULL, QSE_HTTPD_SERVERSTD_PSEUDONYM, &target->u.proxy.pseudonym) <= -1)
target->u.proxy.pseudonym = QSE_NULL;
/* mark that this request is going to be proxied. */ /* mark that this request is going to be proxied. */
req->attr.flags |= QSE_HTRE_ATTR_PROXIED; req->attr.flags |= QSE_HTRE_ATTR_PROXIED;
return 0; return 0;
@ -3809,6 +3819,10 @@ static int query_server (
} }
return 0; return 0;
} }
case QSE_HTTPD_SERVERSTD_PSEUDONYM:
*(const qse_mchar_t**)result = QSE_NULL;
return 0;
} }
qse_httpd_seterrnum (httpd, QSE_HTTPD_EINVAL); qse_httpd_seterrnum (httpd, QSE_HTTPD_EINVAL);