projects
/
citadel.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
b68b70e
)
I need to make the static web server just a static web server. I hate working in...
author
Art Cancro
<ajc@citadel.org>
Wed, 22 Dec 2021 21:46:50 +0000
(16:46 -0500)
committer
Art Cancro
<ajc@citadel.org>
Wed, 22 Dec 2021 21:46:50 +0000
(16:46 -0500)
webcit/static.c
patch
|
blob
|
history
webcit/subst.c
patch
|
blob
|
history
diff --git
a/webcit/static.c
b/webcit/static.c
index 58e44704778ee61773e9ae05012e7cf3f8af7954..650db18f02e3061fcdf11ca6abd4ddc23452f6ab 100644
(file)
--- a/
webcit/static.c
+++ b/
webcit/static.c
@@
-1,75
+1,28
@@
-/*
- * This is the main transaction loop of the web service. It maintains a
- * persistent session to the Citadel server, handling HTTP WebCit requests as
- * they arrive and presenting a user interface.
- */
+// The functions in this file handle static pages and objects -- a basic web server.
+
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
-
#include <unistd.h>
#include <stdio.h>
#include <stdarg.h>
#include <stddef.h>
#include <unistd.h>
#include <stdio.h>
#include <stdarg.h>
#include <stddef.h>
-
-
#include "webcit.h"
#include "webserver.h"
unsigned char OnePixelGif[37] = {
#include "webcit.h"
#include "webserver.h"
unsigned char OnePixelGif[37] = {
- 0x47,
- 0x49,
- 0x46,
- 0x38,
- 0x37,
- 0x61,
- 0x01,
- 0x00,
- 0x01,
- 0x00,
- 0x80,
- 0x00,
- 0x00,
- 0xff,
- 0xff,
- 0xff,
- 0xff,
- 0xff,
- 0xff,
- 0x2c,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x01,
- 0x00,
- 0x01,
- 0x00,
- 0x00,
- 0x02,
- 0x02,
- 0x44,
- 0x01,
- 0x00,
- 0x3b
+ 0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x01, 0x00,
+ 0x01, 0x00, 0x80, 0x00, 0x00, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, 0x00,
+ 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44,
+ 0x01, 0x00, 0x3b
};
HashList *StaticFilemappings[5] = {NULL, NULL, NULL, NULL, NULL};
};
HashList *StaticFilemappings[5] = {NULL, NULL, NULL, NULL, NULL};
-/*
- {
- syslog(LOG_DEBUG, "Suspicious request. Ignoring.");
- hprintf("HTTP/1.1 404 Security check failed\r\n");
- hprintf("Content-Type: text/plain\r\n\r\n");
- wc_printf("You have sent a malformed or invalid request.\r\n");
- end_burst();
- }
-*/
-
-void output_error_pic(const char *ErrMsg1, const char *ErrMsg2)
-{
+void output_error_pic(const char *ErrMsg1, const char *ErrMsg2) {
hprintf("HTTP/1.1 200 %s\r\n", ErrMsg1);
hprintf("Content-Type: image/gif\r\n");
hprintf("x-webcit-errormessage: %s\r\n", ErrMsg2);
hprintf("HTTP/1.1 200 %s\r\n", ErrMsg1);
hprintf("Content-Type: image/gif\r\n");
hprintf("x-webcit-errormessage: %s\r\n", ErrMsg2);
@@
-81,8
+34,7
@@
void output_error_pic(const char *ErrMsg1, const char *ErrMsg2)
/*
* dump out static pages from disk
*/
/*
* dump out static pages from disk
*/
-void output_static(const char *what)
-{
+void output_static(const char *what) {
int fd;
struct stat statbuf;
off_t bytes;
int fd;
struct stat statbuf;
off_t bytes;
@@
-90,32
+42,30
@@
void output_static(const char *what)
int len;
const char *Err;
int len;
const char *Err;
+ syslog(LOG_DEBUG, "output_static(%s)", what);
len = strlen (what);
content_type = GuessMimeByFilename(what, len);
fd = open(what, O_RDONLY);
if (fd <= 0) {
len = strlen (what);
content_type = GuessMimeByFilename(what, len);
fd = open(what, O_RDONLY);
if (fd <= 0) {
- syslog(LOG_INFO, "output_static('%s') [%s] -- NOT FOUND --\n", what, ChrPtr(WC->Hdr->this_page));
- if (strstr(content_type, "image/") != NULL)
- {
+ syslog(LOG_INFO, "output_static('%s') [%s] : %s", what, ChrPtr(WC->Hdr->this_page), strerror(errno));
+ if (strstr(content_type, "image/") != NULL) {
output_error_pic("the file you requsted is gone.", strerror(errno));
}
output_error_pic("the file you requsted is gone.", strerror(errno));
}
- else
- {
+ else {
hprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
hprintf("Content-Type: text/plain\r\n");
begin_burst();
wc_printf("Cannot open %s: %s\r\n", what, strerror(errno));
end_burst();
}
hprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
hprintf("Content-Type: text/plain\r\n");
begin_burst();
wc_printf("Cannot open %s: %s\r\n", what, strerror(errno));
end_burst();
}
- } else {
+ }
+ else {
if (fstat(fd, &statbuf) == -1) {
syslog(LOG_INFO, "output_static('%s') -- FSTAT FAILED --\n", what);
if (fstat(fd, &statbuf) == -1) {
syslog(LOG_INFO, "output_static('%s') -- FSTAT FAILED --\n", what);
- if (strstr(content_type, "image/") != NULL)
- {
+ if (strstr(content_type, "image/") != NULL) {
output_error_pic("Stat failed!", strerror(errno));
}
output_error_pic("Stat failed!", strerror(errno));
}
- else
- {
+ else {
hprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
hprintf("Content-Type: text/plain\r\n");
begin_burst();
hprintf("HTTP/1.1 404 %s\r\n", strerror(errno));
hprintf("Content-Type: text/plain\r\n");
begin_burst();
@@
-128,8
+78,7
@@
void output_static(const char *what)
bytes = statbuf.st_size;
bytes = statbuf.st_size;
- if (StrBufReadBLOB(WC->WBuf, &fd, 1, bytes, &Err) < 0)
- {
+ if (StrBufReadBLOB(WC->WBuf, &fd, 1, bytes, &Err) < 0) {
if (fd > 0) close(fd);
syslog(LOG_INFO, "output_static('%s') -- FREAD FAILED (%s) --\n", what, strerror(errno));
hprintf("HTTP/1.1 500 internal server error \r\n");
if (fd > 0) close(fd);
syslog(LOG_INFO, "output_static('%s') -- FREAD FAILED (%s) --\n", what, strerror(errno));
hprintf("HTTP/1.1 500 internal server error \r\n");
@@
-138,7
+87,6
@@
void output_static(const char *what)
return;
}
return;
}
-
close(fd);
http_transmit_thing(content_type, 2);
}
close(fd);
http_transmit_thing(content_type, 2);
}
@@
-148,8
+96,7
@@
void output_static(const char *what)
}
}
-int LoadStaticDir(const char *DirName, HashList *DirList, const char *RelDir)
-{
+int LoadStaticDir(const char *DirName, HashList *DirList, const char *RelDir) {
char dirname[PATH_MAX];
char reldir[PATH_MAX];
StrBuf *FileName = NULL;
char dirname[PATH_MAX];
char reldir[PATH_MAX];
StrBuf *FileName = NULL;
@@
-163,20
+110,17
@@
int LoadStaticDir(const char *DirName, HashList *DirList, const char *RelDir)
int d_namelen;
int istoplevel;
int d_namelen;
int istoplevel;
- if (IsEmptyStr(DirName))
- {
+ if (IsEmptyStr(DirName)) {
return 0;
}
filedir = opendir (DirName);
return 0;
}
filedir = opendir (DirName);
- if (filedir == NULL)
- {
+ if (filedir == NULL) {
return 0;
}
d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 1);
return 0;
}
d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 1);
- if (d == NULL)
- {
+ if (d == NULL) {
closedir(filedir);
return 0;
}
closedir(filedir);
return 0;
}
@@
-186,12
+130,9
@@
int LoadStaticDir(const char *DirName, HashList *DirList, const char *RelDir)
istoplevel = IsEmptyStr(RelDir);
OneWebName = NewStrBuf();
istoplevel = IsEmptyStr(RelDir);
OneWebName = NewStrBuf();
- while ((readdir_r(filedir, d, &filedir_entry) == 0) &&
- (filedir_entry != NULL))
- {
+ while ((readdir_r(filedir, d, &filedir_entry) == 0) && (filedir_entry != NULL)) {
#ifdef _DIRENT_HAVE_D_NAMLEN
d_namelen = filedir_entry->d_namlen;
#ifdef _DIRENT_HAVE_D_NAMLEN
d_namelen = filedir_entry->d_namlen;
-
#else
d_namelen = strlen(filedir_entry->d_name);
#endif
#else
d_namelen = strlen(filedir_entry->d_name);
#endif
@@
-233,8
+174,7
@@
int LoadStaticDir(const char *DirName, HashList *DirList, const char *RelDir)
}
}
}
}
- switch (d_type)
- {
+ switch (d_type) {
case DT_DIR:
/* Skip directories we are not interested in... */
if ((strcmp(filedir_entry->d_name, ".svn") == 0) ||
case DT_DIR:
/* Skip directories we are not interested in... */
if ((strcmp(filedir_entry->d_name, ".svn") == 0) ||
@@
-284,61
+224,53
@@
int LoadStaticDir(const char *DirName, HashList *DirList, const char *RelDir)
}
}
-void output_flat_static(void)
-{
+void output_flat_static(void) {
void *vFile;
StrBuf *File;
if (WC->Hdr->HR.Handler == NULL)
return;
void *vFile;
StrBuf *File;
if (WC->Hdr->HR.Handler == NULL)
return;
- if (GetHash(StaticFilemappings[0], SKEY(WC->Hdr->HR.Handler->Name), &vFile) &&
- (vFile != NULL))
- {
+ if (GetHash(StaticFilemappings[0], SKEY(WC->Hdr->HR.Handler->Name), &vFile) && (vFile != NULL)) {
File = (StrBuf*) vFile;
output_static(ChrPtr(File));
}
}
File = (StrBuf*) vFile;
output_static(ChrPtr(File));
}
}
-void output_static_safe(HashList *DirList)
-{
+void output_static_safe(HashList *DirList) {
void *vFile;
StrBuf *File;
const char *MimeType;
void *vFile;
StrBuf *File;
const char *MimeType;
- if (GetHash(DirList, SKEY(WC->Hdr->HR.ReqLine), &vFile) &&
- (vFile != NULL))
- {
+ if (GetHash(DirList, SKEY(WC->Hdr->HR.ReqLine), &vFile) && (vFile != NULL)) {
File = (StrBuf*) vFile;
output_static(ChrPtr(File));
}
else {
File = (StrBuf*) vFile;
output_static(ChrPtr(File));
}
else {
- syslog(LOG_INFO, "output_static_safe() file %s not found. \n",
- ChrPtr(WC->Hdr->HR.ReqLine));
+ syslog(LOG_INFO, "output_static_safe() %s: %s", ChrPtr(WC->Hdr->HR.ReqLine), strerror(errno));
MimeType = GuessMimeByFilename(SKEY(WC->Hdr->HR.ReqLine));
MimeType = GuessMimeByFilename(SKEY(WC->Hdr->HR.ReqLine));
- if (strstr(MimeType, "image/") != NULL)
- {
+ if (strstr(MimeType, "image/") != NULL) {
output_error_pic("the file you requested isn't known to our cache", "maybe reload webcit?");
}
output_error_pic("the file you requested isn't known to our cache", "maybe reload webcit?");
}
- else
- {
+ else {
do_404();
}
}
}
do_404();
}
}
}
-void output_static_0(void)
-{
+
+
+void output_static_0(void) {
output_static_safe(StaticFilemappings[0]);
}
output_static_safe(StaticFilemappings[0]);
}
-void output_static_1(void)
-{
+
+
void output_static_1(void)
{
output_static_safe(StaticFilemappings[1]);
}
output_static_safe(StaticFilemappings[1]);
}
-void output_static_2(void)
-{
+
+
void output_static_2(void)
{
output_static_safe(StaticFilemappings[2]);
}
output_static_safe(StaticFilemappings[2]);
}
-void output_static_3(void)
-{
+
+
void output_static_3(void)
{
output_static_safe(StaticFilemappings[4]);
}
output_static_safe(StaticFilemappings[4]);
}
diff --git
a/webcit/subst.c
b/webcit/subst.c
index b54e921ee9946b3c1c738ad9576f96dd26bb83ab..a3063e6f3168e099ed97e58f7615dacf9ecfd786 100644
(file)
--- a/
webcit/subst.c
+++ b/
webcit/subst.c
@@
-1,11
+1,11
@@
-#include "sysdep.h"
-
+// Spaghetti, technical debt, and an unmaintainable big mess.
+// No one knows how this works. This is why we started over with WebCit-NG.
+#include "sysdep.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
-
#include <unistd.h>
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <stdio.h>
#include <stdarg.h>
@@
-219,7
+219,6
@@
void DestroySortStruct(void *vSort)
void LogTemplateError (StrBuf *Target, const char *Type, int ErrorPos, WCTemplputParams *TP, const char *Format, ...)
{
void LogTemplateError (StrBuf *Target, const char *Type, int ErrorPos, WCTemplputParams *TP, const char *Format, ...)
{
- wcsession *WCC;
StrBuf *Error;
StrBuf *Info;
va_list arg_ptr;
StrBuf *Error;
StrBuf *Info;
va_list arg_ptr;
@@
-258,14
+257,13
@@
void LogTemplateError (StrBuf *Target, const char *Type, int ErrorPos, WCTemplpu
Type,
ChrPtr(Error));
}
Type,
ChrPtr(Error));
}
- WCC = WC;
- if (WCC == NULL) {
+ if (WC == NULL) {
FreeStrBuf(&Info);
FreeStrBuf(&Error);
return;
}
FreeStrBuf(&Info);
FreeStrBuf(&Error);
return;
}
- if (WC
C->WFBuf == NULL) WC
C->WFBuf = NewStrBuf();
+ if (WC
->WFBuf == NULL) W
C->WFBuf = NewStrBuf();
if (TP->Tokens != NULL)
{
/* deprecated:
if (TP->Tokens != NULL)
{
/* deprecated:
@@
-286,45
+284,25
@@
void LogTemplateError (StrBuf *Target, const char *Type, int ErrorPos, WCTemplpu
ChrPtr(TP->Tokens->FlatToken));
ChrPtr(TP->Tokens->FlatToken));
- SerializeJson(WC
C
->WFBuf, WildFireException(SKEY(TP->Tokens->FileName),
+ SerializeJson(WC->WFBuf, WildFireException(SKEY(TP->Tokens->FileName),
TP->Tokens->Line,
Info,
1), 1);
TP->Tokens->Line,
Info,
1), 1);
-/*
- SerializeJson(Header, WildFireMessage(SKEY(TP->Tokens->FileName),
- TP->Tokens->Line,
- Error,
- eERROR), 1);
-*/
-
}
}
- else
- {
- /* deprecated.
- StrBufAppendPrintf(
- Target,
- "<pre>\n%s: %s\n</pre>\n",
- Type,
- ChrPtr(Error));
- */
+ else {
StrBufPrintf(Info, "%s [%s] %s; [%s]",
Type,
Err,
ChrPtr(Error),
ChrPtr(TP->Tokens->FlatToken));
StrBufPrintf(Info, "%s [%s] %s; [%s]",
Type,
Err,
ChrPtr(Error),
ChrPtr(TP->Tokens->FlatToken));
- SerializeJson(WC
C
->WFBuf, WildFireException(HKEY(__FILE__), __LINE__, Info, 1), 1);
+ SerializeJson(WC->WFBuf, WildFireException(HKEY(__FILE__), __LINE__, Info, 1), 1);
}
FreeStrBuf(&Info);
FreeStrBuf(&Error);
}
FreeStrBuf(&Info);
FreeStrBuf(&Error);
-/*
- if (dbg_backtrace_template_errors)
- wc_backtrace(LOG_DEBUG);
-*/
}
}
-void LogError (StrBuf *Target, const char *Type, const char *Format, ...)
-{
- wcsession *WCC;
+
+void LogError (StrBuf *Target, const char *Type, const char *Format, ...) {
StrBuf *Error;
StrBuf *Info;
va_list arg_ptr;
StrBuf *Error;
StrBuf *Info;
va_list arg_ptr;
@@
-338,20
+316,15
@@
void LogError (StrBuf *Target, const char *Type, const char *Format, ...)
syslog(LOG_WARNING, "%s", ChrPtr(Error));
syslog(LOG_WARNING, "%s", ChrPtr(Error));
- WCC = WC;
- if (WCC->WFBuf == NULL) WCC->WFBuf = NewStrBuf();
+ if (WC->WFBuf == NULL) WC->WFBuf = NewStrBuf();
- SerializeJson(WC
C
->WFBuf, WildFireException(Type, strlen(Type),
+ SerializeJson(WC->WFBuf, WildFireException(Type, strlen(Type),
0,
Info,
1), 1);
FreeStrBuf(&Info);
FreeStrBuf(&Error);
0,
Info,
1), 1);
FreeStrBuf(&Info);
FreeStrBuf(&Error);
-/*
- if (dbg_backtrace_template_errors)
- wc_backtrace(LOG_DEBUG);
-*/
}
}
@@
-402,29
+375,10
@@
int CheckContext(StrBuf *Target, ContextFilter *Need, WCTemplputParams *TP, cons
ContextName(TP->Filter.ContextType));
return 0;
}
ContextName(TP->Filter.ContextType));
return 0;
}
-/*
- if (TP->Tokens->nParameters < Need->nMinArgs) {
- LogTemplateError(Target, ErrType, ERR_NAME, TP,
- "needs at least %ld params, have %ld",
- Need->nMinArgs,
- TP->Tokens->nParameters);
- return 0;
-
- }
- else if (TP->Tokens->nParameters > Need->nMaxArgs) {
- LogTemplateError(Target, ErrType, ERR_NAME, TP,
- "just needs %ld params, you gave %ld",
- Need->nMaxArgs,
- TP->Tokens->nParameters);
- return 0;
-
- }
-*/
return 1;
}
return 1;
}
-void FreeToken(WCTemplateToken **Token)
-{
+void FreeToken(WCTemplateToken **Token) {
int i;
FreeStrBuf(&(*Token)->FlatToken);
if ((*Token)->HaveParameters)
int i;
FreeStrBuf(&(*Token)->FlatToken);
if ((*Token)->HaveParameters)
@@
-435,9
+389,7
@@
void FreeToken(WCTemplateToken **Token)
}
}
-
-void FreeWCTemplate(void *vFreeMe)
-{
+void FreeWCTemplate(void *vFreeMe) {
int i;
WCTemplate *FreeMe = (WCTemplate*)vFreeMe;
int i;
WCTemplate *FreeMe = (WCTemplate*)vFreeMe;
@@
-479,12
+431,7
@@
int HaveTemplateTokenString(StrBuf *Target,
}
}
}
}
-void GetTemplateTokenString(StrBuf *Target,
- WCTemplputParams *TP,
- int N,
- const char **Value,
- long *len)
-{
+void GetTemplateTokenString(StrBuf *Target, WCTemplputParams *TP, int N, const char **Value, long *len) {
StrBuf *Buf;
if (N >= TP->Tokens->nParameters) {
StrBuf *Buf;
if (N >= TP->Tokens->nParameters) {
@@
-583,8
+530,7
@@
void GetTemplateTokenString(StrBuf *Target,
}
}
}
}
-long GetTemplateTokenNumber(StrBuf *Target, WCTemplputParams *TP, int N, long dflt)
-{
+long GetTemplateTokenNumber(StrBuf *Target, WCTemplputParams *TP, int N, long dflt) {
long Ret;
if (N >= TP->Tokens->nParameters) {
LogTemplateError(Target,
long Ret;
if (N >= TP->Tokens->nParameters) {
LogTemplateError(Target,
@@
-1293,12
+1239,11
@@
WCTemplateToken *NewTemplateSubstitute(StrBuf *Buf,
-/*
*
- *
\brief
Display a variable-substituted template
- *
\param
templatename template file to load
+/*
+ * Display a variable-substituted template
+ * templatename template file to load
*/
*/
-void *prepare_template(StrBuf *filename, StrBuf *Key, HashList *PutThere)
-{
+void *prepare_template(StrBuf *filename, StrBuf *Key, HashList *PutThere) {
WCTemplate *NewTemplate;
NewTemplate = (WCTemplate *) malloc(sizeof(WCTemplate));
WCTemplate *NewTemplate;
NewTemplate = (WCTemplate *) malloc(sizeof(WCTemplate));
@@
-1322,12
+1267,11
@@
void *prepare_template(StrBuf *filename, StrBuf *Key, HashList *PutThere)
return NewTemplate;
}
return NewTemplate;
}
-/*
*
- *
\brief
Display a variable-substituted template
- *
\param
templatename template file to load
+/*
+ * Display a variable-substituted template
+ * templatename template file to load
*/
*/
-void *duplicate_template(WCTemplate *OldTemplate)
-{
+void *duplicate_template(WCTemplate *OldTemplate) {
WCTemplate *NewTemplate;
NewTemplate = (WCTemplate *) malloc(sizeof(WCTemplate));
WCTemplate *NewTemplate;
NewTemplate = (WCTemplate *) malloc(sizeof(WCTemplate));
@@
-1343,16
+1287,13
@@
void *duplicate_template(WCTemplate *OldTemplate)
}
}
-void SanityCheckTemplate(StrBuf *Target, WCTemplate *CheckMe)
-{
+void SanityCheckTemplate(StrBuf *Target, WCTemplate *CheckMe) {
int i = 0;
int j;
int FoundConditionalEnd;
int i = 0;
int j;
int FoundConditionalEnd;
- for (i = 0; i < CheckMe->nTokensUsed; i++)
- {
- switch(CheckMe->Tokens[i]->Flags)
- {
+ for (i = 0; i < CheckMe->nTokensUsed; i++) {
+ switch(CheckMe->Tokens[i]->Flags) {
case SV_CONDITIONAL:
case SV_NEG_CONDITIONAL:
FoundConditionalEnd = 0;
case SV_CONDITIONAL:
case SV_NEG_CONDITIONAL:
FoundConditionalEnd = 0;
@@
-1388,9
+1329,9
@@
void SanityCheckTemplate(StrBuf *Target, WCTemplate *CheckMe)
}
}
}
}
-/*
*
- *
\brief
Display a variable-substituted template
- *
\param
templatename template file to load
+/*
+ * Display a variable-substituted template
+ * templatename template file to load
*/
void *load_template(StrBuf *Target, WCTemplate *NewTemplate)
{
*/
void *load_template(StrBuf *Target, WCTemplate *NewTemplate)
{