X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fstatic.c;h=34a656ee2b6058ed3203c4fc5d70cf9ad816dd98;hb=c73091a2ae896b6be5aa94b911c1c89d76a85688;hp=ece24acf5905d1e76485b0e8d6b499c160bbee52;hpb=a15ba5c1ede7c86a85d62ed5b539dcfc9f415bc1;p=citadel.git diff --git a/webcit/static.c b/webcit/static.c index ece24acf5..34a656ee2 100644 --- a/webcit/static.c +++ b/webcit/static.c @@ -56,10 +56,10 @@ unsigned char OnePixelGif[37] = { }; -HashList *StaticFilemappings[4] = {NULL, NULL, NULL, NULL}; +HashList *StaticFilemappings[5] = {NULL, NULL, NULL, NULL, NULL}; /* { - syslog(9, "Suspicious request. Ignoring."); + 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"); @@ -94,7 +94,7 @@ void output_static(const char *what) content_type = GuessMimeByFilename(what, len); fd = open(what, O_RDONLY); if (fd <= 0) { - syslog(9, "output_static('%s') [%s] -- NOT FOUND --\n", what, ChrPtr(WC->Hdr->this_page)); + syslog(LOG_INFO, "output_static('%s') [%s] -- NOT FOUND --\n", what, ChrPtr(WC->Hdr->this_page)); if (strstr(content_type, "image/") != NULL) { output_error_pic("the file you requsted is gone.", strerror(errno)); @@ -109,7 +109,7 @@ void output_static(const char *what) } } else { if (fstat(fd, &statbuf) == -1) { - syslog(9, "output_static('%s') -- FSTAT FAILED --\n", what); + syslog(LOG_INFO, "output_static('%s') -- FSTAT FAILED --\n", what); if (strstr(content_type, "image/") != NULL) { output_error_pic("Stat failed!", strerror(errno)); @@ -131,7 +131,7 @@ void output_static(const char *what) if (StrBufReadBLOB(WC->WBuf, &fd, 1, bytes, &Err) < 0) { if (fd > 0) close(fd); - syslog(9, "output_static('%s') -- FREAD FAILED (%s) --\n", what, strerror(errno)); + syslog(LOG_INFO, "output_static('%s') -- FREAD FAILED (%s) --\n", what, strerror(errno)); hprintf("HTTP/1.1 500 internal server error \r\n"); hprintf("Content-Type: text/plain\r\n"); end_burst(); @@ -163,13 +163,21 @@ int LoadStaticDir(const char *DirName, HashList *DirList, const char *RelDir) int d_namelen; int istoplevel; + if (IsEmptyStr(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); - if (d == NULL) { + if (d == NULL) + { + closedir(filedir); return 0; } @@ -181,8 +189,14 @@ int LoadStaticDir(const char *DirName, HashList *DirList, const char *RelDir) while ((readdir_r(filedir, d, &filedir_entry) == 0) && (filedir_entry != NULL)) { -#ifdef _DIRENT_HAVE_D_NAMELEN - d_namelen = filedir_entry->d_namelen; +#ifdef _DIRENT_HAVE_D_NAMLEN + d_namelen = filedir_entry->d_namlen; + +#else + d_namelen = strlen(filedir_entry->d_name); +#endif + +#ifdef _DIRENT_HAVE_D_TYPE d_type = filedir_entry->d_type; #else @@ -195,7 +209,6 @@ int LoadStaticDir(const char *DirName, HashList *DirList, const char *RelDir) #define IFTODT(mode) (((mode) & 0170000) >> 12) #define DTTOIF(dirtype) ((dirtype) << 12) #endif - d_namelen = strlen(filedir_entry->d_name); d_type = DT_UNKNOWN; #endif if ((d_namelen > 1) && filedir_entry->d_name[d_namelen - 1] == '~') @@ -215,7 +228,7 @@ int LoadStaticDir(const char *DirName, HashList *DirList, const char *RelDir) char path[PATH_MAX]; snprintf(path, PATH_MAX, "%s/%s", DirName, filedir_entry->d_name); - if (stat(path, &s) == 0) { + if (lstat(path, &s) == 0) { d_type = IFTODT(s.st_mode); } } @@ -254,7 +267,7 @@ int LoadStaticDir(const char *DirName, HashList *DirList, const char *RelDir) StrBufAppendBufPlain(OneWebName, filedir_entry->d_name, d_namelen, 0); Put(DirList, SKEY(OneWebName), FileName, HFreeStrBuf); - /* syslog(9, "[%s | %s]\n", ChrPtr(OneWebName), ChrPtr(FileName)); */ + /* syslog(LOG_DEBUG, "[%s | %s]\n", ChrPtr(OneWebName), ChrPtr(FileName)); */ break; default: break; @@ -301,7 +314,7 @@ void output_static_safe(HashList *DirList) output_static(ChrPtr(File)); } else { - syslog(1, "output_static_safe() file %s not found. \n", + syslog(LOG_INFO, "output_static_safe() file %s not found. \n", ChrPtr(WCC->Hdr->HR.ReqLine)); MimeType = GuessMimeByFilename(SKEY(WCC->Hdr->HR.ReqLine)); if (strstr(MimeType, "image/") != NULL) @@ -328,7 +341,7 @@ void output_static_2(void) } void output_static_3(void) { - output_static_safe(StaticFilemappings[3]); + output_static_safe(StaticFilemappings[4]); } @@ -354,6 +367,7 @@ void robots_txt(void) { "Disallow: /readnew\r\n" "Disallow: /display_enter\r\n" "Disallow: /skip\r\n" + "Disallow: /ungoto\r\n" "Sitemap: %s/sitemap.xml\r\n" "\r\n" , @@ -372,6 +386,7 @@ ServerStartModule_STATIC StaticFilemappings[1] = NewHash(1, NULL); StaticFilemappings[2] = NewHash(1, NULL); StaticFilemappings[3] = NewHash(1, NULL); + StaticFilemappings[4] = NewHash(1, NULL); } void ServerShutdownModule_STATIC @@ -381,6 +396,7 @@ ServerShutdownModule_STATIC DeleteHash(&StaticFilemappings[1]); DeleteHash(&StaticFilemappings[2]); DeleteHash(&StaticFilemappings[3]); + DeleteHash(&StaticFilemappings[4]); } @@ -392,6 +408,7 @@ InitModule_STATIC LoadStaticDir(static_dirs[1], StaticFilemappings[1], ""); LoadStaticDir(static_dirs[2], StaticFilemappings[2], ""); LoadStaticDir(static_dirs[3], StaticFilemappings[3], ""); + LoadStaticDir(static_dirs[4], StaticFilemappings[4], ""); WebcitAddUrlHandler(HKEY("robots.txt"), "", 0, robots_txt, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC|LOGCHATTY); WebcitAddUrlHandler(HKEY("favicon.ico"), "", 0, output_flat_static, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC|LOGCHATTY); @@ -399,4 +416,5 @@ InitModule_STATIC WebcitAddUrlHandler(HKEY("static.local"), "", 0, output_static_1, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC|LOGCHATTY); WebcitAddUrlHandler(HKEY("tinymce"), "", 0, output_static_2, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC|LOGCHATTY); WebcitAddUrlHandler(HKEY("tiny_mce"), "", 0, output_static_2, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC|LOGCHATTY); + WebcitAddUrlHandler(HKEY("epiceditor"), "", 0, output_static_3, ANONYMOUS|COOKIEUNNEEDED|ISSTATIC|LOGCHATTY); }