# Copyright (c) 1999-2009 bivio Software, Inc. All rights reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library 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 # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: Dispatcher.pm,v 2.13 2011/10/16 23:01:45 nagler Exp $ package Bivio::Agent::HTTP::Dispatcher; use strict; use Bivio::Base 'Agent.Dispatcher'; use Bivio::IO::Trace; our($VERSION) = sprintf('%d.%02d', q$Revision: 2.13 $ =~ /\d+/g); our($_TRACE); my($_JD); my($_SELF); my($_C) = b_use('SQL.Connection'); my($_OK) = b_use('Ext.ApacheConstants')->OK; my($_REPLY) = b_use('AgentHTTP.Reply'); my($_REQUEST) = b_use('AgentHTTP.Request'); my($_T) = b_use('Agent.Task'); Bivio::Die->eval(q{ use BSD::Resource; setrlimit(RLIMIT_CORE, 0, 0); }); Bivio::IO::Trace->register; __PACKAGE__->initialize; sub create_request { my($self, $r) = @_; return $_REQUEST->new($r); } sub handler { my($r) = @_; _trace('begin: ', $r->uri) if $_TRACE; $r->set_handlers('PerlCleanupHandler', [sub { my($req) = $_REQUEST->get_current; if ($req) { b_warn( '[', $req->unsafe_get('client_addr'), '] request aborted, rolling back ', $req->unsafe_get('task_id'), ); $_T->rollback($req); $_REQUEST->clear_current; } else { $_JD->execute_queue; } return $_OK; }]); my($die) = $_SELF->process_request($r); if ($die && !$die->get('code')->equals_by_name('CLIENT_REDIRECT_TASK')) { my($c) = $r->connection(); my($u) = $c && $c->user() || 'ANONYMOUS'; my($ip) = $c && $c->remote_ip || '0.0.0.0'; $r->log_reason($ip.' '.$u.' '.$die->as_string); _trace($die) if $_TRACE; } _trace('reply: ', $_REPLY->die_to_http_code($die, $r)) if $_TRACE; return $_REPLY->die_to_http_code($die, $r); } sub initialize { my($proto) = @_; return if $_SELF; $_SELF = $proto->new; $_SELF->SUPER::initialize; # Avoids import problems use attributes (); $_REQUEST->if_apache_version(2, sub { b_use('APR::SockAddr'); Bivio::Die->eval(q{use attributes __PACKAGE__, \&handler, 'handler'}); return; }); $_JD = b_use('AgentJob.Dispatcher'); return; } sub trans_handler { shift->filename(''); return Bivio::Ext::ApacheConstants->OK(); } 1;