Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/httpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ struct httpd {
#define HTTPD_CGICTX_MVSMF 0 /* ... MVSMF CGI context index */
#define HTTPD_CGICTX_MIN 0 /* ... minimum number of cgictx */
#define HTTPD_CGICTX_MAX 255 /* ... maximum number of cgictx */
}; /* A0 (160 bytes) */
char docroot[128]; /* A0 UFS document root prefix */
}; /* 120 */

/* Telemetry */
struct httpt {
Expand Down
21 changes: 21 additions & 0 deletions src/httpconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,24 @@ process_httpd_ufs(lua_State *L, HTTPD *httpd)

if (crt) crt->crtufs = ufs;

/* Read document root prefix (optional) */
lua_getfield(L, -1, "docroot");
{
const char *dr = lua_tostring(L, -1);
if (dr && dr[0] == '/') {
int drlen = strlen(dr);
/* strip trailing slash */
if (drlen > 1 && dr[drlen - 1] == '/')
drlen--;
if (drlen >= (int)sizeof(httpd->docroot))
drlen = (int)sizeof(httpd->docroot) - 1;
memcpy(httpd->docroot, dr, drlen);
httpd->docroot[drlen] = '\0';
wtof("HTTPD047I Document root: %s", httpd->docroot);
}
}
lua_pop(L, 1);

quit:
return rc;
}
Expand Down Expand Up @@ -1094,6 +1112,9 @@ setHttpdDefaults(lua_State *L)

lua_pushstring(L, "1");
lua_setfield(L,-2,"ufs"); // table.ufs="1"

lua_pushstring(L, "");
lua_setfield(L,-2,"docroot"); // table.docroot=""

lua_pushstring(L, "HTTPD.CGILUA");
lua_setfield(L,-2,"cgilua_dataset"); // table.cgilua_dataset="HTTPD.CGILUA"
Expand Down
13 changes: 9 additions & 4 deletions src/httpopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,16 @@ http_open(HTTPC *httpc, const UCHAR *path, const HTTPM *mime)


if (httpc->ufs) {
httpc->ufp = ufs_fopen(httpc->ufs, buf, mode);
// wtof("%s: ufs_fopen(%p, \"%s\", \"%s\") httpc->ufp=%p",
// __func__, httpc->ufs, buf, mode, httpc->ufp);
UCHAR ufspath[256];
const char *dr = httpc->httpd->docroot;
if (dr[0] && http_cmpn(buf, "/DD:", 4) != 0) {
/* prepend document root to UFS path */
snprintf((char *)ufspath, sizeof(ufspath), "%s%s", dr, buf);
httpc->ufp = ufs_fopen(httpc->ufs, ufspath, mode);
} else {
httpc->ufp = ufs_fopen(httpc->ufs, buf, mode);
}
if (httpc->ufp) {
/* wtof("%s opened \"%s\" UFS", __func__, buf); */
goto quit; /* success, return NULL to caller */
}
}
Expand Down
Loading