Skip to content

Commit 1c2ad3c

Browse files
authored
feat: configurable document root for UFS-backed HTTP serving (#24)
Add httpd.docroot Lua config option (e.g. docroot="/www") that prefixes all UFS file paths in HTTP requests. This allows mounting a dedicated UFS disk on a subdirectory via UFSD parmlib and pointing HTTPD at it. - httpd.h: add docroot[128] field to HTTPD struct - httpconf.c: read httpd.docroot from Lua config, default empty - httpopen.c: prepend docroot to UFS paths in http_open (skipped for /DD: paths which bypass UFS) Example config: httpd.docroot = "/www" With UFSD parmlib: MOUNT DSN(HTTPD.WEBROOT) PATH(/www) MODE(RO) URL /index.html resolves to UFS path /www/index.html.
1 parent 4e07411 commit 1c2ad3c

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

include/httpd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ struct httpd {
150150
#define HTTPD_CGICTX_MVSMF 0 /* ... MVSMF CGI context index */
151151
#define HTTPD_CGICTX_MIN 0 /* ... minimum number of cgictx */
152152
#define HTTPD_CGICTX_MAX 255 /* ... maximum number of cgictx */
153-
}; /* A0 (160 bytes) */
153+
char docroot[128]; /* A0 UFS document root prefix */
154+
}; /* 120 */
154155

155156
/* Telemetry */
156157
struct httpt {

src/httpconf.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,24 @@ process_httpd_ufs(lua_State *L, HTTPD *httpd)
547547

548548
if (crt) crt->crtufs = ufs;
549549

550+
/* Read document root prefix (optional) */
551+
lua_getfield(L, -1, "docroot");
552+
{
553+
const char *dr = lua_tostring(L, -1);
554+
if (dr && dr[0] == '/') {
555+
int drlen = strlen(dr);
556+
/* strip trailing slash */
557+
if (drlen > 1 && dr[drlen - 1] == '/')
558+
drlen--;
559+
if (drlen >= (int)sizeof(httpd->docroot))
560+
drlen = (int)sizeof(httpd->docroot) - 1;
561+
memcpy(httpd->docroot, dr, drlen);
562+
httpd->docroot[drlen] = '\0';
563+
wtof("HTTPD047I Document root: %s", httpd->docroot);
564+
}
565+
}
566+
lua_pop(L, 1);
567+
550568
quit:
551569
return rc;
552570
}
@@ -1094,6 +1112,9 @@ setHttpdDefaults(lua_State *L)
10941112

10951113
lua_pushstring(L, "1");
10961114
lua_setfield(L,-2,"ufs"); // table.ufs="1"
1115+
1116+
lua_pushstring(L, "");
1117+
lua_setfield(L,-2,"docroot"); // table.docroot=""
10971118

10981119
lua_pushstring(L, "HTTPD.CGILUA");
10991120
lua_setfield(L,-2,"cgilua_dataset"); // table.cgilua_dataset="HTTPD.CGILUA"

src/httpopen.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,16 @@ http_open(HTTPC *httpc, const UCHAR *path, const HTTPM *mime)
9898

9999

100100
if (httpc->ufs) {
101-
httpc->ufp = ufs_fopen(httpc->ufs, buf, mode);
102-
// wtof("%s: ufs_fopen(%p, \"%s\", \"%s\") httpc->ufp=%p",
103-
// __func__, httpc->ufs, buf, mode, httpc->ufp);
101+
UCHAR ufspath[256];
102+
const char *dr = httpc->httpd->docroot;
103+
if (dr[0] && http_cmpn(buf, "/DD:", 4) != 0) {
104+
/* prepend document root to UFS path */
105+
snprintf((char *)ufspath, sizeof(ufspath), "%s%s", dr, buf);
106+
httpc->ufp = ufs_fopen(httpc->ufs, ufspath, mode);
107+
} else {
108+
httpc->ufp = ufs_fopen(httpc->ufs, buf, mode);
109+
}
104110
if (httpc->ufp) {
105-
/* wtof("%s opened \"%s\" UFS", __func__, buf); */
106111
goto quit; /* success, return NULL to caller */
107112
}
108113
}

0 commit comments

Comments
 (0)