/* * Copyright (c) 2004-6, WebThing Ltd * Author: Nick Kew * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include #include #include #include typedef struct link { const char* val ; struct link* next ; } link ; static link* badrobots ; static int robot_check(request_rec* r) { link* l ; const char* ua = apr_table_get(r->headers_in, "User-Agent") ; if ( ua ) { for ( l = badrobots ; l ; l = l->next ) { if ( !strncmp(l->val, ua, strlen(l->val) ) ) { r->unparsed_uri = r->uri = r->parsed_uri.path = apr_pstrdup(r->pool, "/robots.txt") ; apr_table_unset(r->headers_in, "Host") ; return OK ; } } } return DECLINED ; } static int robot_init(apr_pool_t* p0, apr_pool_t* p1, apr_pool_t* p2) { badrobots = NULL ; return OK; } static void robots_hooks(apr_pool_t* pool) { ap_hook_post_read_request(robot_check, NULL, NULL, APR_HOOK_FIRST) ; ap_hook_pre_config(robot_init, NULL, NULL, APR_HOOK_MIDDLE) ; } static const char* robot_deny(cmd_parms* cmd, void* cfg, const char* arg) { link* newlink ; for ( newlink = badrobots ; newlink ; newlink = newlink->next ) { if ( !strcmp(arg, newlink->val) ) { return NULL ; } } newlink = apr_palloc(cmd->pool, sizeof(link)) ; newlink->val = arg ; newlink->next = badrobots ; badrobots = newlink ; return NULL ; } static const command_rec robots_cmds[] = { AP_INIT_TAKE1("RobotDeny", robot_deny, NULL, RSRC_CONF, NULL) , { NULL } } ; module AP_MODULE_DECLARE_DATA robots_module = { STANDARD20_MODULE_STUFF, NULL, NULL, NULL, NULL, robots_cmds, robots_hooks } ;