diff --git a/lib/POE/Component/SSLify/ServerHandle.pm b/lib/POE/Component/SSLify/ServerHandle.pm index d0b2160..037f0bd 100644 --- a/lib/POE/Component/SSLify/ServerHandle.pm +++ b/lib/POE/Component/SSLify/ServerHandle.pm @@ -55,11 +55,11 @@ # also, ERROR_WANT_ACCEPT isn't exported by Net::SSLeay, huh? if ( $errval != ERROR_WANT_READ and $errval != ERROR_WANT_WRITE ) { # call the hook function for error connect - $self->{'on_connect'}->( $self->{'orig_socket'}, 'ERR', $errval ); + $self->{'on_connect'}->( $self->{'orig_socket'}, 0, $errval ); } } elsif ( $self->{'status'} == 1 ) { # call the hook function for successful connect - $self->{'on_connect'}->( $self->{'orig_socket'}, 'OK' ); + $self->{'on_connect'}->( $self->{'orig_socket'}, 1 ); } } diff --git a/lib/POE/Component/SSLify.pm b/lib/POE/Component/SSLify.pm index 87a94f4..34b6703 100644 --- a/lib/POE/Component/SSLify.pm +++ b/lib/POE/Component/SSLify.pm @@ -56,17 +56,21 @@ my $socket = shift; $socket = Client_SSLify( $socket, $version, $options, $ctx, $callback ); - $socket is the non-ssl socket you got from somewhere ( probably SocketFactory ) + $socket is the non-ssl socket you got from somewhere ( probably POE::Wheel::SocketFactory ) $version is the SSL version you want to use, see SSLify_ContextCreate $options is the SSL options you want to use, see SSLify_ContextCreate $ctx is the custom SSL context you want to use, see SSLify_ContextCreate $callback is the callback hook on success/failure of sslification + # This is an example of the callback and you should pass it as Client_SSLify( ... \&callback ); sub callback { my( $socket, $status, $errval ) = @_; # $socket is the original sslified socket in case you need to play with it - # $status is either 'OK' or 'ERR' - # $errval will be defined if $status eq 'ERR' - it's the numeric SSL error code + # $status is either 1 or 0; with 1 signifying success and 0 failure + # $errval will be defined if $status == 0; it's the numeric SSL error code + # check http://www.openssl.org/docs/ssl/SSL_get_error.html for the possible error values ( and import them from Net::SSLeay! ) + + # The return value from the callback is discarded } If $ctx is defined, SSLify will ignore $version and $options. Otherwise, it will be created from the $version and @@ -84,8 +88,28 @@ 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 into the postback/callback stuff in L. - $socket = Client_SSLify( $socket, $session->callback( 'got_connect' => @args ) ); - + # we got this from POE::Wheel::SocketFactory + sub event_SuccessEvent { + my $socket = $_[ARG0]; + $socket = Client_SSLify( $socket, $_[SESSION]->callback( 'sslify_result' ) ); + $_[HEAP]->{client} = POE::Wheel::ReadWrite->new( + Handle => $socket, + ... + ); + return; + } + + # the callback event + sub event_sslify_result { + my ($creation_args, $called_args) = @_[ARG0, ARG1]; + my( $socket, $status, $errval ) = @$called_args; + + if ( $status ) { + print "Yay, SSLification worked!"; + } else { + print "Aw, SSLification failed with error $errval"; + } + } =cut sub Client_SSLify { @@ -139,14 +163,9 @@ $ctx is the custom SSL context you want to use, see SSLify_ContextCreate ( overrides the global set in SSLify_Options ) $callback is the callback hook on success/failure of sslification - sub callback { - my( $socket, $status, $errval ) = @_; - # $socket is the original sslified socket in case you need to play with it - # $status is either 'OK' or 'ERR' - # $errval will be defined if $status eq 'ERR' - it's the numeric SSL error code - } - -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: +Please look at L for more details on the callback hook. + +SSLify_Options must be set first if you aren't passing a $ctx. If you want to set some options per-connection, do this: my $socket = shift; # get the socket from somewhere my $ctx = SSLify_ContextCreate(); @@ -155,11 +174,6 @@ NOTE: You can use SSLify_GetCTX to modify the global, and avoid doing this on every connection if the options are the same... - -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 -into the postback/callback stuff in POE::Session. - - $socket = Server_SSLify( $socket, $session->callback( 'got_connect' => @args ) ); =cut sub Server_SSLify { diff --git a/t/4_connect_hook.t b/t/4_connect_hook.t index 88dad4f..d0acecf 100644 --- a/t/4_connect_hook.t +++ b/t/4_connect_hook.t @@ -55,7 +55,7 @@ my( $socket, $status, $errval ) = @_; pass( "SERVER: Got callback hook" ); - is( $status, 'OK', "SERVER: Status received from callback is OK" ); + is( $status, 1, "SERVER: Status received from callback is OK" ); ## At this point, connection MUST be encrypted. my $cipher = SSLify_GetCipher($socket); @@ -106,7 +106,7 @@ my( $socket, $status, $errval ) = @_; pass( "CLIENT: Got callback hook" ); - is( $status, 'OK', "CLIENT: Status received from callback is OK" ); + is( $status, 1, "CLIENT: Status received from callback is OK" ); ## At this point, connection MUST be encrypted. my $cipher = SSLify_GetCipher($socket); diff --git a/t/5_connfail_client.t b/t/5_connfail_client.t index 64009e2..d9dacb4 100644 --- a/t/5_connfail_client.t +++ b/t/5_connfail_client.t @@ -88,7 +88,7 @@ my( $socket, $status, $errval ) = @_; pass( "CLIENT: Got callback hook" ); - is( $status, 'ERR', "CLIENT: Status received from callback is ERR - $errval" ); + is( $status, 0, "CLIENT: Status received from callback is ERR - $errval" ); $poe_kernel->post( 'myclient' => 'shutdown' ); }) }; diff --git a/t/6_connfail_server.t b/t/6_connfail_server.t index 4a6a1c1..4e8c08f 100644 --- a/t/6_connfail_server.t +++ b/t/6_connfail_server.t @@ -54,7 +54,7 @@ my( $socket, $status, $errval ) = @_; pass( "SERVER: Got callback hook" ); - is( $status, 'ERR', "SERVER: Status received from callback is ERR - $errval" ); + is( $status, 0, "SERVER: Status received from callback is ERR - $errval" ); $poe_kernel->post( 'myserver' => 'shutdown'); } ) };