diff --git a/qse/cmd/http/httpd.c b/qse/cmd/http/httpd.c index 551faa5c..b31e7edf 100644 --- a/qse/cmd/http/httpd.c +++ b/qse/cmd/http/httpd.c @@ -72,6 +72,7 @@ enum XCFG_DIRFOOT, XCFG_ERRHEAD, XCFG_ERRFOOT, + XCFG_PSEUDONYM, XCFG_MAX }; @@ -593,6 +594,10 @@ static int query_server ( *(const qse_mchar_t**)result = loccfg->xcfg[XCFG_ERRFOOT]; return 0; + case QSE_HTTPD_SERVERSTD_PSEUDONYM: + *(const qse_mchar_t**)result = loccfg->xcfg[XCFG_PSEUDONYM]; + return 0; + case QSE_HTTPD_SERVERSTD_INDEX: ((qse_httpd_serverstd_index_t*)result)->count = loccfg->index.count; ((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("error-head"), QSE_T("server-default.error-head") }, { QSE_T("error-foot"), QSE_T("server-default.error-foot") }, + { QSE_T("pseudonym"), QSE_T("server-default.pseudonym") } }; 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.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.pseudonym"), { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 } }, { QSE_T("server"), { QSE_XLI_SCM_VALLIST, 0, 0 } }, { 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-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-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 } } }; diff --git a/qse/cmd/http/httpd.conf b/qse/cmd/http/httpd.conf index c7dea056..230b8099 100644 --- a/qse/cmd/http/httpd.conf +++ b/qse/cmd/http/httpd.conf @@ -23,6 +23,9 @@ server-default { #################################################################### root = "/var/www"; + # pseudonym to use in Via: for proxying + #pseudonym = "my-host"; + realm = "default realm"; auth = "username:password"; index = "index.html", @@ -119,6 +122,9 @@ server { # uncomment the followng block to override the default. #root = "/var/www"; + # pseudonym to use in Via: for proxying + #pseudonym = "my-host"; + # uncomment the followng block to override the default. # if you want to disable authentication while the default # enables it, don't put a value like 'realm;' diff --git a/qse/include/qse/http/httpd.h b/qse/include/qse/http/httpd.h index 42384831..6fe9b50b 100644 --- a/qse/include/qse/http/httpd.h +++ b/qse/include/qse/http/httpd.h @@ -537,6 +537,8 @@ struct qse_httpd_rsrc_proxy_t qse_nwad_t nwad; const qse_mchar_t* str; } 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; diff --git a/qse/include/qse/http/stdhttpd.h b/qse/include/qse/http/stdhttpd.h index ea8897cd..56ecba55 100644 --- a/qse/include/qse/http/stdhttpd.h +++ b/qse/include/qse/http/stdhttpd.h @@ -114,12 +114,13 @@ enum qse_httpd_serverstd_query_code_t QSE_HTTPD_SERVERSTD_DIRHEAD, /* 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_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) */ }; typedef enum qse_httpd_serverstd_query_code_t qse_httpd_serverstd_query_code_t; diff --git a/qse/lib/http/httpd-proxy.c b/qse/lib/http/httpd-proxy.c index 1dbab463..b7a5fc32 100644 --- a/qse/lib/http/httpd-proxy.c +++ b/qse/lib/http/httpd-proxy.c @@ -51,6 +51,7 @@ struct task_proxy_t int keepalive; /* taken from the request */ int raw; + qse_mchar_t* pseudonym; qse_htrd_t* peer_htrd; 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) { qse_mchar_t extra[128]; + const qse_mchar_t* pseudonym; proxy->flags |= PROXY_VIA_RETURNING; - qse_nwadtombs (&proxy->client->local_addr, extra, QSE_COUNTOF(extra), QSE_NWADTOMBS_ALL); + + if (proxy->pseudonym[0]) + { + pseudonym = proxy->pseudonym; + } + else + { + qse_nwadtombs (&proxy->client->local_addr, extra, QSE_COUNTOF(extra), QSE_NWADTOMBS_ALL); + pseudonym = extra; + } return proxy_add_header_to_buffer_with_extra_data ( proxy, proxy->res, key, val, QSE_MT(", %d.%d %hs (%hs)"), (int)proxy->version.major, (int)proxy->version.minor, - extra, + pseudonym, 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) { qse_mchar_t extra[128]; + const qse_mchar_t* pseudonym; proxy->flags |= PROXY_VIA; - qse_nwadtombs (&proxy->client->local_addr, extra, QSE_COUNTOF(extra), QSE_NWADTOMBS_ALL); + if (proxy->pseudonym[0]) + { + pseudonym = proxy->pseudonym; + } + else + { + qse_nwadtombs (&proxy->client->local_addr, extra, QSE_COUNTOF(extra), QSE_NWADTOMBS_ALL); + pseudonym = extra; + } return proxy_add_header_to_buffer_with_extra_data ( proxy, proxy->reqfwdbuf, key, val, QSE_MT(", %d.%d %hs (%hs)"), (int)proxy->version.major, (int)proxy->version.minor, - extra, + pseudonym, 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. */ qse_size_t tmp; qse_mchar_t extra[128]; + const qse_mchar_t* pseudonym; qse_http_version_t v; proxy->flags |= PROXY_VIA_RETURNING; v = *qse_htre_getversion(res); - qse_nwadtombs (&proxy->client->local_addr, extra, QSE_COUNTOF(extra), QSE_NWADTOMBS_ALL); + if (proxy->pseudonym[0]) + { + pseudonym = proxy->pseudonym; + } + else + { + qse_nwadtombs (&proxy->client->local_addr, extra, QSE_COUNTOF(extra), QSE_NWADTOMBS_ALL); + pseudonym = extra; + } + tmp = qse_mbs_fcat ( proxy->res, QSE_MT("Via: %d.%d %hs (%hs)\r\n"), (int)v.major, (int)v.minor, - extra, qse_httpd_getname(httpd)); + pseudonym, qse_httpd_getname(httpd)); if (tmp == (qse_size_t)-1) { httpd->errnum = QSE_HTTPD_ENOMEM; @@ -860,6 +890,17 @@ static int task_init_proxy ( proxy->version = *qse_htre_getversion(arg->req); 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; proxy->peer.local = arg->rsrc->src.nwad; if (arg->rsrc->flags & QSE_HTTPD_RSRC_PROXY_DST_STR) @@ -867,7 +908,7 @@ static int task_init_proxy ( qse_mchar_t* colon; 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); colon = qse_mbschr (proxy->peer_name, QSE_MT(':')); @@ -970,14 +1011,23 @@ static int task_init_proxy ( /* add the Via: header into the request */ qse_size_t tmp; qse_mchar_t extra[128]; + const qse_mchar_t* pseudonym; proxy->flags |= PROXY_VIA; - qse_nwadtombs (&proxy->client->local_addr, extra, QSE_COUNTOF(extra), QSE_NWADTOMBS_ALL); + if (proxy->pseudonym[0]) + { + pseudonym = proxy->pseudonym; + } + else + { + qse_nwadtombs (&proxy->client->local_addr, extra, QSE_COUNTOF(extra), QSE_NWADTOMBS_ALL); + pseudonym = extra; + } tmp = qse_mbs_fcat ( proxy->reqfwdbuf, QSE_MT("Via: %d.%d %hs (%hs)\r\n"), (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; } @@ -1931,8 +1981,14 @@ qse_httpd_task_t* qse_httpd_entaskproxy ( arg.rsrc = proxy; arg.req = req; + if (proxy->pseudonym) + xtnsize += qse_mbslen (proxy->pseudonym) + 1; + else + xtnsize += 1; + 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)); task.init = task_init_proxy; diff --git a/qse/lib/http/httpd-std.c b/qse/lib/http/httpd-std.c index 0fde4fc5..a1fb7492 100644 --- a/qse/lib/http/httpd-std.c +++ b/qse/lib/http/httpd-std.c @@ -3354,6 +3354,10 @@ static int make_resource ( 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. */ req->attr.flags |= QSE_HTRE_ATTR_PROXIED; return 0; @@ -3394,6 +3398,9 @@ static int make_resource ( 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 */ 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.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. */ req->attr.flags |= QSE_HTRE_ATTR_PROXIED; return 0; @@ -3809,6 +3819,10 @@ static int query_server ( } return 0; } + + case QSE_HTTPD_SERVERSTD_PSEUDONYM: + *(const qse_mchar_t**)result = QSE_NULL; + return 0; } qse_httpd_seterrnum (httpd, QSE_HTTPD_EINVAL);