Ejemplo n.º 1
0
void
ngx_http_file_cache_create_key(ngx_http_request_t *r)
{
    size_t             len;
    ngx_str_t         *key;
    ngx_uint_t         i;
    ngx_md5_t          md5;
    ngx_http_cache_t  *c;

    c = r->cache;

    len = 0;

    ngx_crc32_init(c->crc32);
    ngx_md5_init(&md5);

    key = c->keys.elts;
    for (i = 0; i < c->keys.nelts; i++) {
        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                       "http cache key: \"%V\"", &key[i]);

        len += key[i].len;

        ngx_crc32_update(&c->crc32, key[i].data, key[i].len);
        ngx_md5_update(&md5, key[i].data, key[i].len);
    }

    c->header_start = sizeof(ngx_http_file_cache_header_t)
                      + sizeof(ngx_http_file_cache_key) + len + 1;

    ngx_crc32_final(c->crc32);
    ngx_md5_final(c->key, &md5);
}
Ejemplo n.º 2
0
void
ngx_http_file_cache_create_key(ngx_http_request_t *r)
{
    size_t             len;
    ngx_str_t         *key;
    ngx_uint_t         i;
    ngx_md5_t          md5;
    ngx_http_cache_t  *c;

    c = r->cache;

    len = 0;

    ngx_crc32_init(c->crc32);	//Here,we do the crc get a key!
    ngx_md5_init(&md5);			//Here,we get the md5

    key = c->keys.elts;			//Means how much elements we used to caculate the key!
    for (i = 0; i < c->keys.nelts; i++) {
        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "http cache key: \"%V\"", &key[i]);

        len += key[i].len;

        ngx_crc32_update(&c->crc32, key[i].data, key[i].len);	//do the crc32
        ngx_md5_update(&md5, key[i].data, key[i].len);			//do the md5
    }

    c->header_start = sizeof(ngx_http_file_cache_header_t) + sizeof(ngx_http_file_cache_key) + len + 1;

    ngx_crc32_final(c->crc32);
    ngx_md5_final(c->key, &md5);
}
Ejemplo n.º 3
0
static ngx_int_t
ngx_http_limit_req_copy_variables(ngx_http_request_t *r, uint32_t *hash,
    ngx_http_limit_req_ctx_t *ctx, ngx_http_limit_req_node_t *node)
{
    u_char                        *p;
    size_t                         len, total_len;
    ngx_uint_t                     j;
    ngx_http_variable_value_t     *vv;
    ngx_http_limit_req_variable_t *lrv;

    len = 0;
    total_len = 0;
    p = NULL;

    if (node != NULL) {
        p = node->data;
    }

    lrv = ctx->limit_vars->elts;
    for (j = 0; j < ctx->limit_vars->nelts; j++) {
        vv = ngx_http_get_indexed_variable(r, lrv[j].index);
        if (vv == NULL || vv->not_found) {
            total_len = 0;
            break;
        }

        len = vv->len;

        if (len == 0) {
            total_len = 0;
            break;
        }

        if (len > 65535) {
            ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                          "the value of the \"%V\" variable "
                          "is more than 65535 bytes: \"%v\"",
                          &lrv[j].var, vv);
            total_len = 0;
            break;
        }

        if (node == NULL) {
            total_len += len;
            ngx_crc32_update(hash, vv->data, len);
        } else {
            p = ngx_cpymem(p, vv->data, len);
        }
    }

    return total_len;
}
Ejemplo n.º 4
0
static ngx_int_t
ngx_http_zip_subrequest_update_crc32(ngx_chain_t *in, 
        ngx_http_zip_file_t *file)
{
    ngx_chain_t *cl;
    size_t       len;
    u_char      *p;

    if (file == NULL) 
        return NGX_ERROR;

    for (cl = in; cl != NULL; cl = cl->next) {
        p = cl->buf->pos;
        len = cl->buf->last - p;

        ngx_crc32_update(&file->crc32, p, len);
    }

    return NGX_OK;
}
ngx_int_t
ngx_selective_cache_purge_file_cache_lookup_on_disk(ngx_http_request_t *r, ngx_http_file_cache_t *cache, ngx_str_t *cache_key, u_char *md5_key)
{
#if NGX_HTTP_CACHE
    ngx_http_cache_t  *c;
    ngx_str_t         *key;
    ngx_int_t          rc;

    c = r->cache;
    if ((c = ngx_pcalloc(r->pool, sizeof(ngx_http_cache_t))) == NULL) {
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "ngx_selective_cache_purge: could not alloc memory to ngx_http_cache_t structure");
        return NGX_ERROR;
    }

    ngx_memzero(c, sizeof(ngx_http_cache_t));

    rc = ngx_array_init(&c->keys, r->pool, 1, sizeof(ngx_str_t));
    if (rc != NGX_OK) {
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "ngx_selective_cache_purge: could not alloc memory to keys array");
        return NGX_ERROR;
    }

    key = ngx_array_push(&c->keys);
    if (key == NULL) {
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "ngx_selective_cache_purge: could not alloc memory to key item");
        return NGX_ERROR;
    }

    key->data = cache_key->data;
    key->len = cache_key->len;

    r->cache = c;
    c->body_start = ngx_pagesize;
    c->file_cache = cache;
    c->file.log = r->connection->log;

    ngx_crc32_init(c->crc32);
    ngx_crc32_update(&c->crc32, cache_key->data, cache_key->len);
    ngx_crc32_final(c->crc32);

    c->header_start = sizeof(ngx_http_file_cache_header_t) + NGX_HTTP_FILE_CACHE_KEY_LEN + cache_key->len + 1;

    ngx_memcpy(c->key, md5_key, NGX_HTTP_CACHE_KEY_LEN);

    switch (ngx_http_file_cache_open(r)) {
    case NGX_OK:
    case NGX_HTTP_CACHE_STALE:
    case NGX_HTTP_CACHE_UPDATING:
        return NGX_OK;
        break;
    case NGX_DECLINED:
        return NGX_DECLINED;
#  if (NGX_HAVE_FILE_AIO)
    case NGX_AGAIN:
        return NGX_AGAIN;
#  endif
    default:
        return NGX_ERROR;
    }
#else
    return NGX_OK;
#endif
}