Example #1
0
/* If it's one of ours, fill in r->finfo now to avoid extra stat()... this is a
 * bit of a kludge, because we really want to run after core_translate runs.
 */
static int file_cache_xlat(request_rec *r)
{
    a_server_config *sconf;
    a_file *match;
    int res;

    sconf = ap_get_module_config(r->server->module_config, &file_cache_module);

    /* we only operate when at least one cachefile directive was used */
    if (!apr_hash_count(sconf->fileht)) {
        return DECLINED;
    }

    res = ap_core_translate(r);
    if (res != OK || !r->filename) {
        return res;
    }

    /* search the cache */
    match = (a_file *) apr_hash_get(sconf->fileht, r->filename, APR_HASH_KEY_STRING);
    if (match == NULL)
        return DECLINED;

    /* pass search results to handler */
    ap_set_module_config(r->request_config, &file_cache_module, match);

    /* shortcircuit the get_path_info() stat() calls and stuff */
    r->finfo = match->finfo;
    return OK;
}
Example #2
0
static int translate_thumb(request_rec *r)
{
    int res = ap_core_translate(r);
    if (res != OK || !r->filename) {
        return res;
    }

    char        *thumb_uri;
    char        *size;
    apr_finfo_t  finfo;
    if (parse_request_uri(r, &thumb_uri, &size) != APR_SUCCESS) {
        return DECLINED;
    }

    char *path = uri2thumbpath(r, thumb_uri, size);
    if (apr_stat(&finfo, path, APR_FINFO_INODE, r->pool) != APR_SUCCESS) {
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                      "Thumbnail does not exist: %s", path);
        path        = no_image_path(r, size);
        r->filename = path;
        r->status   = HTTP_NOT_FOUND;
    }
    else {
        r->filename = path;
    }

    return OK;
}