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
5 changes: 5 additions & 0 deletions include/httpcgi.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ struct httpx {
HTTPCP *xlate_cp037; /* 114 CP037 codepage pair */
HTTPCP *xlate_1047; /* 118 IBM-1047 codepage pair */
HTTPCP *xlate_legacy; /* 11C legacy hybrid codepage pair */
UFS * (*http_get_ufs)(HTTPC *);
/* 120 get/create UFS handle */
};

/* Eye-catcher for HTTPD pointer identification (ABI constant) */
Expand Down Expand Up @@ -522,4 +524,7 @@ struct httpx {
#define http_xlate(buf,len,tbl) \
((httpx->http_xlate)((buf),(len),(tbl)))

#define http_get_ufs(httpc) \
((httpx->http_get_ufs)((httpc)))

#endif /* HTTPCGI_H */
6 changes: 6 additions & 0 deletions include/httpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ struct httpx {
HTTPCP *xlate_cp037; /* 114 CP037 codepage pair */
HTTPCP *xlate_1047; /* 118 IBM-1047 codepage pair */
HTTPCP *xlate_legacy; /* 11C legacy hybrid codepage pair */
UFS * (*http_get_ufs)(HTTPC *);
/* 120 get/create UFS handle */
};

extern int http_in(HTTPC*) asm("HTTPIN");
Expand Down Expand Up @@ -489,6 +491,7 @@ extern HTTPCGI *http_find_cgi(HTTPD *httpd, const char *path) asm("HTT
extern HTTPCGI *http_add_cgi(HTTPD *httpd, const char *pgm, const char *path, int login) asm("HTTPACGI");
extern int http_process_cgi(HTTPC *httpc, HTTPCGI *cgi) asm("HTTPPCGI");
extern unsigned char *http_xlate(unsigned char *, int, const unsigned char *) asm("HTTPXLAT");
extern UFS *http_get_ufs(HTTPC *) asm("HTTPGUFS");
extern double httpsecs(double *psecs) asm("HTTPSECS");
extern int httpcred(HTTPC *httpc) asm("HTTPCRED");
extern int httpd048(HTTPD *httpd) asm("HTTPD048");
Expand Down Expand Up @@ -719,6 +722,9 @@ extern int http_gets(HTTPC *httpc, UCHAR *buf, unsigned max) asm("HTT
#define http_xlate(buf,len,tbl) \
((httpx->http_xlate)((buf),(len),(tbl)))

#define http_get_ufs(httpc) \
((httpx->http_get_ufs)((httpc)))

#endif /* ifndef HTTPX_H */

#endif
18 changes: 2 additions & 16 deletions src/httpconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,18 +514,17 @@ process_httpd(lua_State *L, HTTPD *httpd)
static int
process_httpd_ufs(lua_State *L, HTTPD *httpd)
{
CLIBCRT *crt = __crtget();
int rc = 0;
int i;
UFS *ufs;

lua_getfield(L,-1,"ufs");
i = (int) lua_tointeger(L, -1);
lua_pop(L,1);

if (i<=0) goto quit;

/* Stub system handle — signals UFS availability to FTPD */
/* Stub system handle — signals UFS availability to FTPD and
** http_get_ufs(). Per-client sessions are created lazily. */
httpd->ufssys = ufs_sys_new();
if (!httpd->ufssys) {
wtof("HTTPD044W Unable to initialize file system");
Expand All @@ -534,19 +533,6 @@ process_httpd_ufs(lua_State *L, HTTPD *httpd)

if (httpd->ftpd) httpd->ftpd->sys = httpd->ufssys;

/* Open server-level UFS session to UFSD STC */
httpd->ufs = ufs = ufsnew();
if (!ufs) {
wtof("HTTPD044W Unable to open UFSD session");
ufs_sys_term(&httpd->ufssys);
httpd->ufssys = NULL;
goto quit;
}

wtof("HTTPD046I UFS session opened via UFSD subsystem");

if (crt) crt->crtufs = ufs;

/* Read document root prefix (optional) */
lua_getfield(L, -1, "docroot");
{
Expand Down
11 changes: 2 additions & 9 deletions src/httpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,9 @@ terminate(void)
array_free(&httpd->httpcgi);
}

if (httpd->ufs) {
ufsfree(&httpd->ufs);
}
/* httpd->ufs removed — per-client sessions freed in httpclos.c */

if (httpd->ufssys) {
wtof("HTTPD047I Terminating File System");
ufs_sys_term(&httpd->ufssys);
httpd->ufssys = NULL;
}
Expand Down Expand Up @@ -671,11 +668,7 @@ socket_thread(void *arg1, void *arg2)
httpc->port = a->sin_port;
httpc->state = CSTATE_IN;
httpsecs(&httpc->start);
if (httpd->ufs) {
/* create UFS handle */
httpc->ufs = ufsnew();
crt->crtufs = httpc->ufs;
}
/* UFS session created lazily by http_get_ufs() */

mgr = httpd->mgr;
if (mgr) {
Expand Down
5 changes: 5 additions & 0 deletions src/httpdone.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ httpdone(HTTPC *httpc)
httpc->fp = NULL;
}

if (httpc->ufp) {
/* close UFS file handle */
ufs_fclose(&httpc->ufp);
}

httpsecs(&httpc->end);

quit:
Expand Down
2 changes: 1 addition & 1 deletion src/httpget.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ httpget(HTTPC *httpc)
__asm__("DC\tH'0'");
}

if (httpc->ufs) {
if (http_get_ufs(httpc)) {
/* try to open path asis */
mime = http_mime(path);
fp = http_open(httpc, path, mime);
Expand Down
21 changes: 21 additions & 0 deletions src/httpgufs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* HTTPGUFS.C
** Get or create per-client UFS session (lazy init)
*/
#define HTTP_PRIVATE
#include "httpd.h"

__asm__("\n&FUNC SETC 'HTTPGUFS'");

#undef http_get_ufs
UFS *
http_get_ufs(HTTPC *httpc)
{
if (!httpc->ufs && httpc->httpd->ufssys) {
httpc->ufs = ufsnew();
if (httpc->ufs) {
CLIBCRT *crt = __crtget();
if (crt) crt->crtufs = httpc->ufs;
}
}
return httpc->ufs;
}
27 changes: 15 additions & 12 deletions src/httpopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,21 @@ http_open(HTTPC *httpc, const UCHAR *path, const HTTPM *mime)
}


if (httpc->ufs) {
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) {
goto quit; /* success, return NULL to caller */
{
UFS *ufs = http_get_ufs(httpc);
if (ufs) {
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(ufs, ufspath, mode);
} else {
httpc->ufp = ufs_fopen(ufs, buf, mode);
}
if (httpc->ufp) {
goto quit; /* success, return NULL to caller */
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/httprese.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ httprese(HTTPC *httpc)
httpc->end = 0.0;
memset(httpc->buf, 0, CBUFSIZE);

/* clear ACEE on UFS session between requests */
if (httpc->ufs) {
ufs_set_acee(httpc->ufs, NULL);
}

/* if this is was HTTP1.1 or higher client then we
** *could* transition to CSTATE_IN. We'll leave that
** for another time.
Expand Down
1 change: 1 addition & 0 deletions src/httpx.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ static HTTPX vect = {
&http_cp037, /* 114 CP037 codepage pair */
&http_cp1047, /* 118 IBM-1047 codepage pair */
&http_legacy, /* 11C legacy hybrid codepage pair */
http_get_ufs, /* 120 http_get_ufs() */
};

HTTPX *httpx = &vect;
Loading