File: Connection.pm

package info (click to toggle)
libanyevent-ftp-perl 0.20-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 640 kB
  • sloc: perl: 4,048; sh: 9; makefile: 2
file content (141 lines) | stat: -rw-r--r-- 2,239 bytes parent folder | download
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
package AnyEvent::FTP::Server::Connection;

use strict;
use warnings;
use 5.010;
use Moo;
use AnyEvent::FTP::Request;

# ABSTRACT: FTP Server connection class
our $VERSION = '0.20'; # VERSION

with 'AnyEvent::FTP::Role::Event';

__PACKAGE__->define_events(qw( request response close ));

has context => (
  is       => 'ro',
  required => 1,
);

has response_encoder => (
  is => 'ro',
  lazy => 1,
  default => sub {
    require AnyEvent::FTP::Server::UnambiguousResponseEncoder;
    AnyEvent::FTP::Server::UnambiguousResponseEncoder->new;
  },
);

has ip => (
  is       => 'ro',
  required => 1,
);

sub process_request
{
  my($self, $line) = @_;

  my $raw = $line;

  $self->emit(request => $raw);

  $line =~ s/\015?\012//g;

  if($line =~ s/^([A-Z]{1,4})\s?//i)
  {
    $self->context->push_request($self, AnyEvent::FTP::Request->new(uc $1, $line, $raw));
  }
  else
  {
    $self->context->invalid_syntax($self, $raw);
  }

  $self;
}

sub send_response
{
  my $self = shift;
  my $raw = $self->response_encoder->encode(@_);
  $self->emit(response => $raw);
  $self;
}

sub close
{
  my($self) = shift;
  $self->emit('close');
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

AnyEvent::FTP::Server::Connection - FTP Server connection class

=head1 VERSION

version 0.20

=head1 METHODS

=head2 close

 $conn->close;

Emits a close signal.

=head2 context

 my $context_obj = $conn->context;

Required to be specified by the constructor and readonly - this is the
context object.

=head2 ip

 my $ip = $conn->ip;

Required to be specified by the constructor and readonly - this is the
IP address.

=head2 process_request

 $conn->process_request($line);

Process a single request. Returns the connection object ($conn).

=head2 send_response

 $conn->send_response($res)
 $conn->send_response($code, $message)

Sends the response. Returns the connection object ($conn).

=head1 AUTHOR

Author: Graham Ollis E<lt>plicease@cpan.orgE<gt>

Contributors:

Ryo Okamoto

Shlomi Fish

José Joaquín Atria

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2017-2022 by Graham Ollis.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut