This file is indexed.

/usr/share/perl5/AnyEvent/FCGI/Connection.pm is in libanyevent-fcgi-perl 0.04-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package AnyEvent::FCGI::Connection;

=head1 NAME

AnyEvent::FCGI::Connection - a single connection handle for L<AnyEvent::FCGI>

=head1 DESCRIPTION

This module represents a single connection for L<AnyEvent::FCGI>
This module would not be used directly by a program using C<AnyEvent::FCGI>.

=cut

use strict;
use warnings;

use Scalar::Util qw/weaken refaddr/;

use AnyEvent::Handle;
use AnyEvent::FCGI::Request;

use constant MAX_DATA_SIZE => 65535;

sub new {
    my ($class, %params) = @_;
    
    my $self = bless {
        fcgi => $params{fcgi},
        requests => {},
    }, $class;
    
    $self->{io} = new AnyEvent::Handle(
        fh => $params{fh},
        on_error => sub {$self->_on_error(@_)},
    );
    $self->{io}->push_read(chunk => 8, sub {$self->_on_read_header(@_)});
    
    weaken($self->{fcgi});
    
    return $self;
}

sub _on_error {
    my ($self, $io, $fatal, $message) = @_;
    
    if ($fatal) {
        $self->_shutdown;
    }
}

sub _shutdown {
    my ($self) = @_;
    
    $self->{requests} = {};
    delete $self->{fcgi}->{connections}->{refaddr($self)};
}

sub _on_read_header {
    my ($self, $io, $header) = @_;
    
    my %record;
    (
        $record{version},
        $record{type},
        $record{request_id},
        $record{length},
        $record{padding},
        undef
    ) = unpack('ccnncc', $header);
    $self->{record} = \%record;
    
    $io->push_read(chunk => ($record{length} + $record{padding}), sub {$self->_on_read_content(@_)});
}

sub _on_read_content {
    my ($self, $io, $data) = @_;
    
    $self->{record}->{content} = substr($data, 0, $self->{record}->{length});
    $self->_process_record($self->{record});
    
    $io->push_read(chunk => 8, sub {$self->_on_read_header(@_)});
}

sub _process_record {
    my ($self, $record) = @_;
    
    return unless $record->{version} == AnyEvent::FCGI->FCGI_VERSION_1;
    
    my $request = $self->{requests}->{$record->{request_id}};
    if ($record->{type} == AnyEvent::FCGI->FCGI_BEGIN_REQUEST) {
        unless (defined $request) {
            my ($role, $flags) = unpack('nc', $record->{content});
            
            if ($role == AnyEvent::FCGI->FCGI_RESPONDER) {
                $self->{requests}->{$record->{request_id}} = new AnyEvent::FCGI::Request(
                    fcgi => $self->{fcgi},
                    connection => $self,
                    flags => $flags,
                    id => $record->{request_id},
                );
            } else {
                warn 'AnyEvent::FCGI supports only responder role';
            }
        } else {
            warn "Request '$record->{request_id}' already running";
        }
    } elsif ($record->{type} == AnyEvent::FCGI->FCGI_STDIN && defined $request) {
        $request->_process_stdin_record($record);
    } elsif ($record->{type} == AnyEvent::FCGI->FCGI_PARAMS && defined $request) {
        $request->_process_params_record($record);
    } elsif ($record->{type} == AnyEvent::FCGI->FCGI_ABORT_REQUEST && defined $request) {
        delete $request->{connection};
        delete $self->{requests}->{$request->{id}};
    }
}

sub send_record {
    my ($self, $record) = @_;
    
    if (length $record->{content} > MAX_DATA_SIZE) {
        warn 'Record content length > MAX_DATA_SIZE, truncating';
        $record->{content} = substr($record->{content}, 0, MAX_DATA_SIZE);
    }
    
    $self->{io}->push_write(
        pack('ccnncc',
            AnyEvent::FCGI->FCGI_VERSION_1,
            $record->{type},
            $record->{request_id},
            length $record->{content},
            0,
            0,
        ) . $record->{content}
    );
}

sub DESTROY {
    my ($self) = @_;
    
    if ($self) {
        $self->_shutdown;
    }
}

1;