/* * url_redir.c: Do redirections based on uri instead of ppath * * * I'm using clf-request here because this easily shows the query string * without doing a lot of other work. This is just a proof-of-concept * program, no warranties, etc apply. * * Rob Crittenden 10-02-2001 * * How to install this program: * * Add the following lines to your obj.conf: * * Init fn=load-modules shlib= funcs=url_redir_init * ... * NameTrans fn=url-redir from="*foo=bar*" url="http://www.greyoak.com/" * */ #include "nsapi.h" /* * url_redir() * */ NSAPI_PUBLIC int url_redir(pblock *pb, Session *sn, Request *rq) { char *uri = pblock_findval("clf-request", rq->reqpb); char *from = pblock_findval("from", pb); char *url = pblock_findval("url", pb); if (!uri) { log_error(LOG_WARN, "url-redir", sn, rq, "Somehow there is no client request, this shouldn't happen"); return REQ_ABORTED; } if (!from || !url) { log_error(LOG_MISCONFIG, "url-redir", sn, rq, "Both url and from are required."); return REQ_NOACTION; } if (!WILDPAT_CMP(uri, from)) { protocol_status(sn, rq, PROTOCOL_REDIRECT, NULL); pblock_nvinsert("url", url, rq->vars); return REQ_ABORTED; } return REQ_NOACTION; }