comparison src/http/ngx_http_cache.c @ 174:ea464a6c0581

nginx-0.0.1-2003-11-05-01:12:39 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 04 Nov 2003 22:12:39 +0000
parents caa57ddf6d77
children e92c2c647c57
comparison
equal deleted inserted replaced
173:4fb2a2cff023 174:ea464a6c0581
6 #include <md5.h> 6 #include <md5.h>
7 7
8 8
9 int ngx_http_cache_get_file(ngx_http_request_t *r, ngx_http_cache_ctx_t *ctx) 9 int ngx_http_cache_get_file(ngx_http_request_t *r, ngx_http_cache_ctx_t *ctx)
10 { 10 {
11 ssize_t n; 11 ssize_t n;
12 MD5_CTX md5; 12 MD5_CTX md5;
13 ngx_err_t err; 13 ngx_err_t err;
14 ngx_http_cache_file_t *h; 14 ngx_http_cache_header_t *h;
15 15
16 ctx->header_size = sizeof(ngx_http_cache_file_t) + ctx->key.len + 1; 16 ctx->header_size = sizeof(ngx_http_cache_header_t) + ctx->key.len + 1;
17 17
18 ctx->file.name.len = ctx->path->name.len + 1 + ctx->path->len + 32; 18 ctx->file.name.len = ctx->path->name.len + 1 + ctx->path->len + 32;
19 if (!(ctx->file.name.data = ngx_palloc(r->pool, ctx->file.name.len + 1))) { 19 if (!(ctx->file.name.data = ngx_palloc(r->pool, ctx->file.name.len + 1))) {
20 return NGX_ERROR; 20 return NGX_ERROR;
21 } 21 }
22 22
23 ngx_memcpy(ctx->file.name.data, ctx->path->name.data, ctx->path->name.len); 23 ngx_memcpy(ctx->file.name.data, ctx->path->name.data, ctx->path->name.len);
24 24
25 MD5Init(&md5); 25 MD5Init(&md5);
26 MD5Update(&md5, (u_char *) ctx->key.data, ctx->key.len); 26 MD5Update(&md5, (u_char *) ctx->key.data, ctx->key.len);
27 MD5Final(ctx->md5, &md5);
28
29 ngx_print_md5(
30 ctx->file.name.data + ctx->path->name.len + 1 + ctx->path->len,
31 ctx->md5);
32 #if 0
27 MD5End(&md5, 33 MD5End(&md5,
28 ctx->file.name.data + ctx->path->name.len + 1 + ctx->path->len); 34 ctx->file.name.data + ctx->path->name.len + 1 + ctx->path->len);
35 #endif
29 36
30 ngx_log_debug(r->connection->log, "URL: %s, md5: %s" _ ctx->key.data _ 37 ngx_log_debug(r->connection->log, "URL: %s, md5: %s" _ ctx->key.data _
31 ctx->file.name.data + ctx->path->name.len + 1 + ctx->path->len); 38 ctx->file.name.data + ctx->path->name.len + 1 + ctx->path->len);
32 39
33 ngx_create_hashed_filename(&ctx->file, ctx->path); 40 ngx_create_hashed_filename(&ctx->file, ctx->path);
62 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0, 69 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
63 "cache file \"%s\" is too small", ctx->file.name.data); 70 "cache file \"%s\" is too small", ctx->file.name.data);
64 return NGX_ERROR; 71 return NGX_ERROR;
65 } 72 }
66 73
67 h = (ngx_http_cache_file_t *) ctx->buf->pos; 74 h = (ngx_http_cache_header_t *) ctx->buf->pos;
68 ctx->header = h->header; 75 ctx->expires = h->expires;
76 ctx->last_modified= h->last_modified;
77 ctx->date = h->date;
78 ctx->length = h->length;
69 79
70 if (h->key_len != ctx->key.len 80 if (h->key_len != ctx->key.len
71 || ngx_strncmp(h->key, ctx->key.data, h->key_len) != 0) 81 || ngx_strncmp(h->key, ctx->key.data, h->key_len) != 0)
72 { 82 {
73 h->key[h->key_len] = '\0'; 83 h->key[h->key_len] = '\0';
77 return NGX_DECLINED; 87 return NGX_DECLINED;
78 } 88 }
79 89
80 ctx->buf->last += n; 90 ctx->buf->last += n;
81 91
82 if (ctx->header.expires < ngx_time()) { 92 if (ctx->expires < ngx_time()) {
83 return NGX_HTTP_CACHE_STALE; 93 return NGX_HTTP_CACHE_STALE;
84 } 94 }
85 95
86 /* TODO: NGX_HTTP_CACHE_AGED */ 96 /* TODO: NGX_HTTP_CACHE_AGED */
87 97