33 | 33 |
# ARG0 = Socket, ARG1 = Remote Address, ARG2 = Remote Port
|
34 | 34 |
my $socket = $_[ ARG0 ];
|
35 | 35 |
|
|
36 |
# testing stuff
|
|
37 |
warn "got connection from: " . inet_ntoa( ( unpack_sockaddr_in( getpeername( $socket ) ) )[1] ) . " - commencing Server_SSLify()";
|
|
38 |
|
36 | 39 |
# SSLify it!
|
37 | 40 |
$socket = Server_SSLify( $socket );
|
38 | 41 |
|
39 | 42 |
# testing stuff
|
40 | |
warn "got connection from: " . inet_ntoa( ( unpack_sockaddr_in( getpeername( SSLify_GetSocket( $socket ) ) ) )[1] ) . " cipher type: " . SSLify_GetCipher( $socket );
|
|
43 |
warn "SSLified: " . inet_ntoa( ( unpack_sockaddr_in( getpeername( SSLify_GetSocket( $socket ) ) ) )[1] ) . " cipher type: " . SSLify_GetCipher( $socket );
|
41 | 44 |
|
42 | 45 |
# Hand it off to ReadWrite
|
43 | 46 |
my $wheel = POE::Wheel::ReadWrite->new(
|
|
45 | 48 |
'Driver' => POE::Driver::SysRW->new(),
|
46 | 49 |
'Filter' => POE::Filter::Line->new(),
|
47 | 50 |
'InputEvent' => 'Got_Input',
|
48 | |
'FlushedEvent' => 'Got_Flush',
|
49 | 51 |
'ErrorEvent' => 'Got_Error',
|
50 | 52 |
);
|
51 | 53 |
|
52 | 54 |
# Store it...
|
53 | 55 |
$_[HEAP]->{'WHEELS'}->{ $wheel->ID } = $wheel;
|
54 | |
return 1;
|
|
56 |
return;
|
55 | 57 |
},
|
56 | 58 |
'ListenerError' => sub {
|
57 | 59 |
# ARG0 = operation, ARG1 = error number, ARG2 = error string, ARG3 = wheel ID
|
58 | 60 |
my ( $operation, $errnum, $errstr, $wheel_id ) = @_[ ARG0 .. ARG3 ];
|
59 | 61 |
warn "SocketFactory Wheel $wheel_id generated $operation error $errnum: $errstr\n";
|
60 | 62 |
|
61 | |
return 1;
|
|
63 |
return;
|
62 | 64 |
},
|
63 | 65 |
'Got_Input' => sub {
|
64 | 66 |
# ARG0: The Line, ARG1: Wheel ID
|
65 | 67 |
|
66 | 68 |
# Send back to the client the line!
|
67 | 69 |
$_[HEAP]->{'WHEELS'}->{ $_[ARG1] }->put( $_[ARG0] );
|
68 | |
return 1;
|
69 | |
},
|
70 | |
'Got_Flush' => sub {
|
71 | |
# We don't care about this event
|
72 | |
return 1;
|
|
70 |
return;
|
73 | 71 |
},
|
74 | 72 |
'Got_Error' => sub {
|
75 | 73 |
# ARG0 = operation, ARG1 = error number, ARG2 = error string, ARG3 = wheel ID
|
|
78 | 76 |
|
79 | 77 |
# Done with a wheel
|
80 | 78 |
delete $_[HEAP]->{'WHEELS'}->{ $_[ARG0] };
|
81 | |
return 1;
|
|
79 |
return;
|
82 | 80 |
},
|
83 | 81 |
},
|
84 | 82 |
);
|
|
97 | 95 |
|
98 | 96 |
# Connect to the server!
|
99 | 97 |
$_[KERNEL]->yield( 'do_connect' );
|
100 | |
return 1;
|
|
98 |
return;
|
101 | 99 |
},
|
102 | 100 |
'do_connect' => sub {
|
103 | 101 |
# Create the socketfactory wheel to listen for requests
|
|
108 | 106 |
'SuccessEvent' => 'Got_Connection',
|
109 | 107 |
'FailureEvent' => 'ConnectError',
|
110 | 108 |
);
|
111 | |
return 1;
|
|
109 |
return;
|
112 | 110 |
},
|
113 | 111 |
'Got_ReadLine' => sub {
|
114 | 112 |
if ( defined $_[ARG0] ) {
|
|
120 | 118 |
die 'stopped';
|
121 | 119 |
}
|
122 | 120 |
}
|
|
121 |
return;
|
123 | 122 |
},
|
124 | 123 |
'Got_Connection' => sub {
|
125 | 124 |
# ARG0 = Socket, ARG1 = Remote Address, ARG2 = Remote Port
|
126 | 125 |
my $socket = $_[ ARG0 ];
|
127 | 126 |
|
|
127 |
warn "Connected to server, commencing Client_SSLify()";
|
|
128 |
|
128 | 129 |
# SSLify it!
|
129 | 130 |
$socket = Client_SSLify( $socket );
|
|
131 |
|
|
132 |
warn "SSLified the connection to the server";
|
130 | 133 |
|
131 | 134 |
# Hand it off to ReadWrite
|
132 | 135 |
my $wheel = POE::Wheel::ReadWrite->new(
|
|
142 | 145 |
$_[HEAP]->{'RL'}->put( 'Connected to SSL server' );
|
143 | 146 |
$_[HEAP]->{'RL'}->get( 'Input: ' );
|
144 | 147 |
|
145 | |
return 1;
|
|
148 |
return;
|
146 | 149 |
},
|
147 | 150 |
'ConnectError' => sub {
|
148 | 151 |
# ARG0 = operation, ARG1 = error number, ARG2 = error string, ARG3 = wheel ID
|
|
151 | 154 |
delete $_[HEAP]->{'SOCKETFACTORY'};
|
152 | 155 |
$_[HEAP]->{'RL'}->put( 'Unable to connect to SSL server...' );
|
153 | 156 |
$_[KERNEL]->delay_set( 'do_connect', 5 );
|
154 | |
return 1;
|
|
157 |
return;
|
155 | 158 |
},
|
156 | 159 |
'Got_Input' => sub {
|
157 | 160 |
# ARG0: The Line, ARG1: Wheel ID
|
|
159 | 162 |
# Send back to the client the line!
|
160 | 163 |
$_[HEAP]->{'RL'}->put( 'Got Reply: ' . $_[ARG0] );
|
161 | 164 |
$_[HEAP]->{'RL'}->get( 'Input: ' );
|
162 | |
return 1;
|
|
165 |
return;
|
163 | 166 |
},
|
164 | 167 |
'Got_Error' => sub {
|
165 | 168 |
# ARG0 = operation, ARG1 = error number, ARG2 = error string, ARG3 = wheel ID
|
|
168 | 171 |
delete $_[HEAP]->{'WHEEL'};
|
169 | 172 |
$_[HEAP]->{'RL'}->put( 'Disconnected from SSL server...' );
|
170 | 173 |
$_[KERNEL]->delay_set( 'do_connect', 5 );
|
171 | |
return 1;
|
|
174 |
return;
|
172 | 175 |
},
|
173 | 176 |
},
|
174 | 177 |
);
|