summaryrefslogtreecommitdiffstats
path: root/usr.sbin/httpd/src/modules/proxy/proxy_cache.c
diff options
context:
space:
mode:
authorbeck <beck@openbsd.org>2000-01-25 18:29:14 +0000
committerbeck <beck@openbsd.org>2000-01-25 18:29:14 +0000
commit12f0c5d08ae7073963c5bdae9257b9d13dc0d4fc (patch)
tree0b0a69f1fcfa59fbe79cfa55ca3ea8b769545fc2 /usr.sbin/httpd/src/modules/proxy/proxy_cache.c
parentOk, so setsoftnet is md. (diff)
downloadwireguard-openbsd-12f0c5d08ae7073963c5bdae9257b9d13dc0d4fc.tar.xz
wireguard-openbsd-12f0c5d08ae7073963c5bdae9257b9d13dc0d4fc.zip
Apache 1.3.11 + mod_ssl 2.5.0 merge
Diffstat (limited to 'usr.sbin/httpd/src/modules/proxy/proxy_cache.c')
-rw-r--r--usr.sbin/httpd/src/modules/proxy/proxy_cache.c74
1 files changed, 48 insertions, 26 deletions
diff --git a/usr.sbin/httpd/src/modules/proxy/proxy_cache.c b/usr.sbin/httpd/src/modules/proxy/proxy_cache.c
index 90de9a057e1..00854cb8f21 100644
--- a/usr.sbin/httpd/src/modules/proxy/proxy_cache.c
+++ b/usr.sbin/httpd/src/modules/proxy/proxy_cache.c
@@ -73,6 +73,9 @@
#include <sys/types.h>
#include <sys/stat.h>
#endif
+#ifdef TPF
+#include "os.h"
+#endif
DEF_Explain
@@ -123,7 +126,7 @@ static int sub_garbage_coll(request_rec *r, array_header *files,
const char *cachedir, const char *cachesubdir);
static void help_proxy_garbage_coll(request_rec *r);
static int should_proxy_garbage_coll(request_rec *r);
-#if !defined(WIN32) && !defined(MPE) && !defined(OS2)
+#if !defined(WIN32) && !defined(MPE) && !defined(OS2) && !defined(NETWARE) && !defined(TPF)
static void detached_proxy_garbage_coll(request_rec *r);
#endif
@@ -143,7 +146,7 @@ void ap_proxy_garbage_coll(request_rec *r)
ap_block_alarms(); /* avoid SIGALRM on big cache cleanup */
if (should_proxy_garbage_coll(r))
-#if !defined(WIN32) && !defined(MPE) && !defined(OS2)
+#if !defined(WIN32) && !defined(MPE) && !defined(OS2) && !defined(NETWARE) && !defined(TPF)
detached_proxy_garbage_coll(r);
#else
help_proxy_garbage_coll(r);
@@ -203,7 +206,7 @@ static int gcdiff(const void *ap, const void *bp)
return 0;
}
-#if !defined(WIN32) && !defined(MPE) && !defined(OS2)
+#if !defined(WIN32) && !defined(MPE) && !defined(OS2) && !defined(NETWARE) && !defined(TPF)
static void detached_proxy_garbage_coll(request_rec *r)
{
pid_t pid;
@@ -465,9 +468,19 @@ static int sub_garbage_coll(request_rec *r, array_header *files,
/* if (strlen(ent->d_name) != HASH_LEN) continue; */
/* under OS/2 use dirent's d_attr to identify a diretory */
-#ifdef OS2
+/* under TPF use stat to identify a directory */
+#if defined(OS2) || defined(TPF)
/* is it a directory? */
+#ifdef OS2
if (ent->d_attr & A_DIR) {
+#elif defined(TPF)
+ if (stat(filename, &buf) == -1) {
+ if (errno != ENOENT)
+ ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
+ "proxy gc: stat(%s)", filename);
+ }
+ if (S_ISDIR(buf.st_mode)) {
+#endif
char newcachedir[HUGE_STRING_LEN];
ap_snprintf(newcachedir, sizeof(newcachedir),
"%s%s/", cachesubdir, ent->d_name);
@@ -500,8 +513,8 @@ static int sub_garbage_coll(request_rec *r, array_header *files,
continue;
}
-/* In OS/2 this has already been done above */
-#ifndef OS2
+/* In OS/2 and TPF this has already been done above */
+#if !defined(OS2) && !defined(TPF)
if (S_ISDIR(buf.st_mode)) {
char newcachedir[HUGE_STRING_LEN];
close(fd);
@@ -728,7 +741,7 @@ int ap_proxy_cache_check(request_rec *r, char *url, struct cache_conf *conf,
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, r,
"proxy: bad (short?) cache file: %s", c->filename);
if (i != 1) {
- ap_pclosef(r->pool, cachefp->fd);
+ ap_pclosef(r->pool, ap_bfileno(cachefp, B_WR));
cachefp = NULL;
}
}
@@ -754,7 +767,7 @@ int ap_proxy_cache_check(request_rec *r, char *url, struct cache_conf *conf,
if ((q = ap_table_get(c->hdrs, "Expires")) != NULL)
ap_table_set(r->headers_out, "Expires", q);
}
- ap_pclosef(r->pool, cachefp->fd);
+ ap_pclosef(r->pool, ap_bfileno(cachefp, B_WR));
Explain0("Use local copy, cached file hasn't changed");
return HTTP_NOT_MODIFIED;
}
@@ -772,7 +785,7 @@ int ap_proxy_cache_check(request_rec *r, char *url, struct cache_conf *conf,
r->sent_bodyct = 1;
if (!r->header_only)
ap_proxy_send_fb(cachefp, r, NULL);
- ap_pclosef(r->pool, cachefp->fd);
+ ap_pclosef(r->pool, ap_bfileno(cachefp, B_WR));
return OK;
}
@@ -876,7 +889,7 @@ int ap_proxy_cache_update(cache_req *c, table *resp_hdrs,
Explain1("Response is not cacheable, unlinking %s", c->filename);
/* close the file */
if (c->fp != NULL) {
- ap_pclosef(r->pool, c->fp->fd);
+ ap_pclosef(r->pool, ap_bfileno(c->fp, B_WR));
c->fp = NULL;
}
/* delete the previously cached file */
@@ -973,17 +986,17 @@ int ap_proxy_cache_update(cache_req *c, table *resp_hdrs,
/* set any changed headers somehow */
/* update dates and version, but not content-length */
if (lmod != c->lmod || expc != c->expire || date != c->date) {
- off_t curpos = lseek(c->fp->fd, 0, SEEK_SET);
+ off_t curpos = lseek(ap_bfileno(c->fp, B_WR), 0, SEEK_SET);
if (curpos == -1)
ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
"proxy: error seeking on cache file %s",
c->filename);
- else if (write(c->fp->fd, buff, 35) == -1)
+ else if (write(ap_bfileno(c->fp, B_WR), buff, 35) == -1)
ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
"proxy: error updating cache file %s",
c->filename);
}
- ap_pclosef(r->pool, c->fp->fd);
+ ap_pclosef(r->pool, ap_bfileno(c->fp, B_WR));
Explain0("Remote document not modified, use local copy");
/* CHECKME: Is this right? Shouldn't we check IMS again here? */
return HTTP_NOT_MODIFIED;
@@ -1005,31 +1018,31 @@ int ap_proxy_cache_update(cache_req *c, table *resp_hdrs,
/* set any changed headers somehow */
/* update dates and version, but not content-length */
if (lmod != c->lmod || expc != c->expire || date != c->date) {
- off_t curpos = lseek(c->fp->fd, 0, SEEK_SET);
+ off_t curpos = lseek(ap_bfileno(c->fp, B_WR), 0, SEEK_SET);
if (curpos == -1)
ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
"proxy: error seeking on cache file %s",
c->filename);
- else if (write(c->fp->fd, buff, 35) == -1)
+ else if (write(ap_bfileno(c->fp, B_WR), buff, 35) == -1)
ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
"proxy: error updating cache file %s",
c->filename);
}
- ap_pclosef(r->pool, c->fp->fd);
+ ap_pclosef(r->pool, ap_bfileno(c->fp, B_WR));
return OK;
}
}
/* new or modified file */
if (c->fp != NULL) {
- ap_pclosef(r->pool, c->fp->fd);
- c->fp->fd = -1;
+ ap_pclosef(r->pool, ap_bfileno(c->fp, B_WR));
}
c->version = 0;
ap_proxy_sec2hex(0, buff + 27);
buff[35] = ' ';
/* open temporary file */
+#ifndef TPF
#define TMPFILESTR "/tmpXXXXXX"
if (conf->cache.root == NULL)
return DECLINED;
@@ -1038,6 +1051,15 @@ int ap_proxy_cache_update(cache_req *c, table *resp_hdrs,
strcat(c->tempfile, TMPFILESTR);
#undef TMPFILESTR
p = mktemp(c->tempfile);
+#else
+ if (conf->cache.root == NULL)
+ return DECLINED;
+ c->tempfile = ap_palloc(r->pool, strlen(conf->cache.root) +1+ L_tmpnam);
+ strcpy(c->tempfile, conf->cache.root);
+ strcat(c->tempfile, "/");
+ p = tmpnam(NULL);
+ strcat(c->tempfile, p);
+#endif
if (p == NULL)
return DECLINED;
@@ -1057,7 +1079,7 @@ int ap_proxy_cache_update(cache_req *c, table *resp_hdrs,
if (ap_bvputs(c->fp, buff, "X-URL: ", c->url, "\n", NULL) == -1) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
"proxy: error writing cache file(%s)", c->tempfile);
- ap_pclosef(r->pool, c->fp->fd);
+ ap_pclosef(r->pool, ap_bfileno(c->fp, B_WR));
unlink(c->tempfile);
c->fp = NULL;
}
@@ -1082,7 +1104,7 @@ void ap_proxy_cache_tidy(cache_req *c)
if (c->len != -1) {
/* file lengths don't match; don't cache it */
if (bc != c->len) {
- ap_pclosef(c->req->pool, c->fp->fd); /* no need to flush */
+ ap_pclosef(c->req->pool, ap_bfileno(c->fp, B_WR)); /* no need to flush */
unlink(c->tempfile);
return;
}
@@ -1102,11 +1124,11 @@ void ap_proxy_cache_tidy(cache_req *c)
c->len = bc;
ap_bflush(c->fp);
ap_proxy_sec2hex(c->len, buff);
- curpos = lseek(c->fp->fd, 36, SEEK_SET);
+ curpos = lseek(ap_bfileno(c->fp, B_WR), 36, SEEK_SET);
if (curpos == -1)
ap_log_error(APLOG_MARK, APLOG_ERR, s,
"proxy: error seeking on cache file %s", c->tempfile);
- else if (write(c->fp->fd, buff, 8) == -1)
+ else if (write(ap_bfileno(c->fp, B_WR), buff, 8) == -1)
ap_log_error(APLOG_MARK, APLOG_ERR, s,
"proxy: error updating cache file %s", c->tempfile);
}
@@ -1115,12 +1137,12 @@ void ap_proxy_cache_tidy(cache_req *c)
ap_log_error(APLOG_MARK, APLOG_ERR, s,
"proxy: error writing to cache file %s",
c->tempfile);
- ap_pclosef(c->req->pool, c->fp->fd);
+ ap_pclosef(c->req->pool, ap_bfileno(c->fp, B_WR));
unlink(c->tempfile);
return;
}
- if (ap_pclosef(c->req->pool, c->fp->fd) == -1) {
+ if (ap_pclosef(c->req->pool, ap_bfileno(c->fp, B_WR)) == -1) {
ap_log_error(APLOG_MARK, APLOG_ERR, s,
"proxy: error closing cache file %s", c->tempfile);
unlink(c->tempfile);
@@ -1142,7 +1164,7 @@ void ap_proxy_cache_tidy(cache_req *c)
if (!p)
break;
*p = '\0';
-#ifdef WIN32
+#if defined(WIN32) || defined(NETWARE)
if (mkdir(c->filename) < 0 && errno != EEXIST)
#elif defined(__TANDEM)
if (mkdir(c->filename, S_IRWXU | S_IRWXG | S_IRWXO) < 0 && errno != EEXIST)
@@ -1155,7 +1177,7 @@ void ap_proxy_cache_tidy(cache_req *c)
*p = '/';
++p;
}
-#if defined(OS2) || defined(WIN32)
+#if defined(OS2) || defined(WIN32) || defined(NETWARE)
/* Under OS/2 use rename. */
if (rename(c->tempfile, c->filename) == -1)
ap_log_error(APLOG_MARK, APLOG_ERR, s,