aboutsummaryrefslogtreecommitdiff
path: root/src/http/ngx_http_cache.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2003-11-03 17:33:31 +0000
committerIgor Sysoev <igor@sysoev.ru>2003-11-03 17:33:31 +0000
commita1512b1904fc7e3a0a5b99e49cff480085518445 (patch)
tree9ce4e5578c5957507b16ce0d48de3deaf2562976 /src/http/ngx_http_cache.c
parent659774979feb9741a441505e26774b35830fd4ca (diff)
downloadnginx-a1512b1904fc7e3a0a5b99e49cff480085518445.tar.gz
nginx-a1512b1904fc7e3a0a5b99e49cff480085518445.zip
nginx-0.0.1-2003-11-03-20:33:31 import
Diffstat (limited to 'src/http/ngx_http_cache.c')
-rw-r--r--src/http/ngx_http_cache.c72
1 files changed, 19 insertions, 53 deletions
diff --git a/src/http/ngx_http_cache.c b/src/http/ngx_http_cache.c
index 261229361..b3a7e46fa 100644
--- a/src/http/ngx_http_cache.c
+++ b/src/http/ngx_http_cache.c
@@ -8,12 +8,12 @@
int ngx_http_cache_get_file(ngx_http_request_t *r, ngx_http_cache_ctx_t *ctx)
{
- int small;
- ssize_t n, len;
- MD5_CTX md5;
- ngx_err_t err;
- ngx_str_t key;
- ngx_http_bin_cache_t *h;
+ ssize_t n;
+ MD5_CTX md5;
+ ngx_err_t err;
+ ngx_http_cache_file_t *h;
+
+ ctx->header_size = sizeof(ngx_http_cache_file_t) + ctx->key.len + 1;
ctx->file.name.len = ctx->path->name.len + 1 + ctx->path->len + 32;
if (!(ctx->file.name.data = ngx_palloc(r->pool, ctx->file.name.len + 1))) {
@@ -43,13 +43,6 @@ ngx_log_debug(r->connection->log, "FILE: %s" _ ctx->file.name.data);
err = ngx_errno;
if (err == NGX_ENOENT || err == NGX_ENOTDIR) {
-
- /* TODO: text size */
-
- ctx->header.size = 2 * sizeof(ssize_t)
- + sizeof(ngx_http_cache_header_t)
- + ctx->key.len + 1;
-
return NGX_DECLINED;
}
@@ -65,58 +58,31 @@ ngx_log_debug(r->connection->log, "FILE: %s" _ ctx->file.name.data);
return n;
}
- len = 0;
- small = 1;
-
- if (n > 1) {
- if (ctx->buf->pos[0] == 'T') {
- /* STUB */
- return NGX_ERROR;
-
- } else if (ctx->buf->pos[0] == 'B') {
-
- len = sizeof(ngx_http_bin_cache_t);
-
- if (n > len) {
- h = (ngx_http_bin_cache_t *) ctx->buf->pos;
- key.len = h->key_len;
-
- if (n >= len + (ssize_t) key.len + 1) {
- ctx->header = h->header;
- key.data = h->key;
-
- small = 0;
- }
- }
-
- } else {
- ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
- "unknown type of cache file \"%s\"",
- ctx->file.name.data);
- return NGX_ERROR;
- }
-
- }
-
- if (small) {
+ if (n <= ctx->header_size) {
ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
- "cache file \"%s\" is to small", ctx->file.name.data);
+ "cache file \"%s\" is too small", ctx->file.name.data);
return NGX_ERROR;
}
- if (key.len != ctx->key.len
- || ngx_strncmp(key.data, ctx->key.data, key.len) != 0)
+ h = (ngx_http_cache_file_t *) ctx->buf->pos;
+ ctx->header = h->header;
+
+ if (h->key_len != ctx->key.len
+ || ngx_strncmp(h->key, ctx->key.data, h->key_len) != 0)
{
- key.data[key.len] = '\0';
+ h->key[h->key_len] = '\0';
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
"md5 collision: \"%s\" and \"%s\"",
- key.data, ctx->key.data);
+ h->key, ctx->key.data);
return NGX_DECLINED;
}
- ctx->header.size = len + key.len + 1;
ctx->buf->last += n;
+ if (ctx->header.expires < ngx_time()) {
+ return NGX_STALE;
+ }
+
return NGX_OK;
}