Here is how to proceed:
This is can be done with a G-WAN "connection handler"
or with a MIME "content-type handler"
if you want to restrict the check to *.gif or to *.png files:
http_t *http = (http_t*)get_env(argv, HTTP_HEADERS);
static char my_site[] = "www.my_site.com";
if(strcmp(my_site, http->h_referer)) // not my site
{
char *request = (char*)get_env(argv, REQUEST);
if(strstr(request, "_thumb"))
return 0; // 0: Close the client connection
}
return 255; // continue normally
Alternatively, you can redirect to another page or image instead of just closing the connection:
char szURI[] = "http://another-place.org";
xbuf_t *reply = get_reply(argv);
xbuf_xcat(reply,
"<html><head><title>Redirect</title></head>"
"<body>Click <a href=\"%s\">here</a>.</body></html>",
szURI);
// set the HTTP reply code accordingly
int *pHTTP_status = (int*)get_env(argv, HTTP_CODE);
if(pHTTP_status)
*pHTTP_status = 301; // 301:'moved permanently'
// 2: Send a server reply based on a reply buffer/HTTP status code
return 2;