Package list libpoe-component-sslify-perl / 79116f5
add more POD about callback and make the status a boolean value Apocalypse 10 years ago
5 changed file(s) with 38 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
5454 # also, ERROR_WANT_ACCEPT isn't exported by Net::SSLeay, huh?
5555 if ( $errval != ERROR_WANT_READ and $errval != ERROR_WANT_WRITE ) {
5656 # call the hook function for error connect
57 $self->{'on_connect'}->( $self->{'orig_socket'}, 'ERR', $errval );
57 $self->{'on_connect'}->( $self->{'orig_socket'}, 0, $errval );
5858 }
5959 } elsif ( $self->{'status'} == 1 ) {
6060 # call the hook function for successful connect
61 $self->{'on_connect'}->( $self->{'orig_socket'}, 'OK' );
61 $self->{'on_connect'}->( $self->{'orig_socket'}, 1 );
6262 }
6363 }
6464
5555
5656 my $socket = shift;
5757 $socket = Client_SSLify( $socket, $version, $options, $ctx, $callback );
58 $socket is the non-ssl socket you got from somewhere ( probably SocketFactory )
58 $socket is the non-ssl socket you got from somewhere ( probably POE::Wheel::SocketFactory )
5959 $version is the SSL version you want to use, see SSLify_ContextCreate
6060 $options is the SSL options you want to use, see SSLify_ContextCreate
6161 $ctx is the custom SSL context you want to use, see SSLify_ContextCreate
6262 $callback is the callback hook on success/failure of sslification
6363
64 # This is an example of the callback and you should pass it as Client_SSLify( ... \&callback );
6465 sub callback {
6566 my( $socket, $status, $errval ) = @_;
6667 # $socket is the original sslified socket in case you need to play with it
67 # $status is either 'OK' or 'ERR'
68 # $errval will be defined if $status eq 'ERR' - it's the numeric SSL error code
68 # $status is either 1 or 0; with 1 signifying success and 0 failure
69 # $errval will be defined if $status == 0; it's the numeric SSL error code
70 # check http://www.openssl.org/docs/ssl/SSL_get_error.html for the possible error values ( and import them from Net::SSLeay! )
71
72 # The return value from the callback is discarded
6973 }
7074
7175 If $ctx is defined, SSLify will ignore $version and $options. Otherwise, it will be created from the $version and
8387 NOTE: You can pass the callback anywhere in the arguments, we'll figure it out for you! If you want to call a POE event, please look
8488 into the postback/callback stuff in L<POE::Session>.
8589
86 $socket = Client_SSLify( $socket, $session->callback( 'got_connect' => @args ) );
87
90 # we got this from POE::Wheel::SocketFactory
91 sub event_SuccessEvent {
92 my $socket = $_[ARG0];
93 $socket = Client_SSLify( $socket, $_[SESSION]->callback( 'sslify_result' ) );
94 $_[HEAP]->{client} = POE::Wheel::ReadWrite->new(
95 Handle => $socket,
96 ...
97 );
98 return;
99 }
100
101 # the callback event
102 sub event_sslify_result {
103 my ($creation_args, $called_args) = @_[ARG0, ARG1];
104 my( $socket, $status, $errval ) = @$called_args;
105
106 if ( $status ) {
107 print "Yay, SSLification worked!";
108 } else {
109 print "Aw, SSLification failed with error $errval";
110 }
111 }
88112 =cut
89113
90114 sub Client_SSLify {
138162 $ctx is the custom SSL context you want to use, see SSLify_ContextCreate ( overrides the global set in SSLify_Options )
139163 $callback is the callback hook on success/failure of sslification
140164
141 sub callback {
142 my( $socket, $status, $errval ) = @_;
143 # $socket is the original sslified socket in case you need to play with it
144 # $status is either 'OK' or 'ERR'
145 # $errval will be defined if $status eq 'ERR' - it's the numeric SSL error code
146 }
147
148 NOTE: SSLify_Options must be set first if you aren't passing a $ctx. If you want to set some options per-connection, do this:
165 Please look at L</Client_SSLify> for more details on the callback hook.
166
167 SSLify_Options must be set first if you aren't passing a $ctx. If you want to set some options per-connection, do this:
149168
150169 my $socket = shift; # get the socket from somewhere
151170 my $ctx = SSLify_ContextCreate();
154173
155174 NOTE: You can use SSLify_GetCTX to modify the global, and avoid doing this on every connection if the
156175 options are the same...
157
158 NOTE: You can pass the callback anywhere in the arguments, we'll figure it out for you! If you want to call a POE event, please look
159 into the postback/callback stuff in POE::Session.
160
161 $socket = Server_SSLify( $socket, $session->callback( 'got_connect' => @args ) );
162176 =cut
163177
164178 sub Server_SSLify {
5454 my( $socket, $status, $errval ) = @_;
5555
5656 pass( "SERVER: Got callback hook" );
57 is( $status, 'OK', "SERVER: Status received from callback is OK" );
57 is( $status, 1, "SERVER: Status received from callback is OK" );
5858
5959 ## At this point, connection MUST be encrypted.
6060 my $cipher = SSLify_GetCipher($socket);
105105 my( $socket, $status, $errval ) = @_;
106106
107107 pass( "CLIENT: Got callback hook" );
108 is( $status, 'OK', "CLIENT: Status received from callback is OK" );
108 is( $status, 1, "CLIENT: Status received from callback is OK" );
109109
110110 ## At this point, connection MUST be encrypted.
111111 my $cipher = SSLify_GetCipher($socket);
8787 my( $socket, $status, $errval ) = @_;
8888
8989 pass( "CLIENT: Got callback hook" );
90 is( $status, 'ERR', "CLIENT: Status received from callback is ERR - $errval" );
90 is( $status, 0, "CLIENT: Status received from callback is ERR - $errval" );
9191
9292 $poe_kernel->post( 'myclient' => 'shutdown' );
9393 }) };
5353 my( $socket, $status, $errval ) = @_;
5454
5555 pass( "SERVER: Got callback hook" );
56 is( $status, 'ERR', "SERVER: Status received from callback is ERR - $errval" );
56 is( $status, 0, "SERVER: Status received from callback is ERR - $errval" );
5757
5858 $poe_kernel->post( 'myserver' => 'shutdown');
5959 } ) };