Apache-ImageMagick

 view release on metacpan or  search on metacpan

mod_aimproxy.c  view on Meta::CPAN


    c = (aimconfig *) ap_get_module_config(r->server->module_config, &aimproxy_module);
    
    ent = (aimpass *) c->pass->elts;
    uri  = r -> uri ;
    n    = c -> pass -> nelts ;
    for (i = 0; i < n; i++) 
	{
        if (strncmp (uri, ent[i].proxysrc, ent[i].proxysrclen) == 0)
	    {
	    /*fprintf(stderr, "found %s -> %s\n" , ent[i].proxysrc, ent[i].proxyhost) ;*/
	    found = 1 ;
	    break ;
	    }
	}

    if (!found)
	{
        /*fprintf(stderr, "aimproxy not found %s\n" , uri) ;*/
	return DECLINED ; /* is not our request */
	}
    proxyhost = ent[i].proxyhost ;

    args = r -> args ;
    path_info = r -> path_info ;

    /* If the file exists and there are no transformation arguments
       just decline the transaction.  It will be handled as usual. */
    /*fprintf(stderr, "uri %s  args %s  path_info %s\n" , uri, args, path_info) ;*/
    /*fprintf(stderr, "r -> finfo.st_mode %d\n" , r -> finfo.st_mode) ;*/
    if ((!args || !*args) && (!path_info || !*path_info) && r -> finfo.st_mode)  
	return DECLINED ;

    /* calculate name of cache file */
    file = r->filename;
    md5  = ap_md5 (r -> pool, ap_pstrcat (r -> pool, uri, args, NULL)) ;
    ext  = strchr (file, '.') ;
    if (ext)
	ext++ ;
    else
	ext = "" ;
    cachefn = ap_pstrcat (r -> pool, md5, ".", ext, NULL) ;
    /*fprintf(stderr, "cachefn = %s\n" , cachefn) ;*/
    cachedir  = c -> cachedir ;
    cachepath = ap_pstrcat (r -> pool, cachedir, "/", cachefn, NULL) ;
    
    /*fprintf(stderr, "cachepath = %s\n" , cachepath) ;*/
    if (stat (cachepath, &finfo) == 0)
        { /* let apache do the rest if image already exists */
        r -> filename = cachepath ;
        r -> path_info = "" ;
        memcpy (&r -> finfo, &finfo, sizeof (r -> finfo)) ;
	return OK ;
        }

   /* otherwise send it to the backend */

   r->filename = ap_pstrcat(r->pool, "proxy:http://", proxyhost, r-> uri, NULL);
   r->handler = "proxy-server";
   r->proxyreq = PROXY_PASS;

   /*fprintf(stderr, "proxy to = %s\n" , r->filename) ;*/

   return OK;
   }



static void *aimproxySrvConfig(pool *p, char *d)
    {
    aimconfig *rec = (aimconfig *) ap_pcalloc(p, sizeof(aimconfig));
    memset (rec, 0, sizeof(aimconfig)) ;



( run in 0.303 second using v1.01-cache-2.11-cpan-26ccb49234f )