Skip to content
Snippets Groups Projects
Commit 6cff8a36 authored by Niels Möller's avatar Niels Möller
Browse files

Added a callback to be called when a bad packet is received.

Rev: lib/modules/SSL.pmod/connection.pike:1.6
parent bd65a5f6
No related branches found
No related tags found
No related merge requests found
/* $Id: connection.pike,v 1.5 1997/05/31 22:03:53 grubba Exp $ /* $Id: connection.pike,v 1.6 1997/08/01 07:34:17 nisse Exp $
* *
* SSL packet layer * SSL packet layer
*/ */
...@@ -12,6 +12,8 @@ object packet; ...@@ -12,6 +12,8 @@ object packet;
int dying; int dying;
int closing; int closing;
function(object,int|object,string:void) alert_callback;
inherit "constants"; inherit "constants";
inherit "handshake"; inherit "handshake";
...@@ -36,6 +38,16 @@ void create(int is_server) ...@@ -36,6 +38,16 @@ void create(int is_server)
current_write_state = State(this_object()); current_write_state = State(this_object());
} }
/* Called with alert object, sequence number of bad packet,
* and raw data as arguments, if a bad packet is received.
*
* Can be used to support a fallback redirect https->http
*/
void set_alert_callback(function(object,int|object,string:void) callback)
{
alert_callback = callback;
}
object recv_packet(string data) object recv_packet(string data)
{ {
mixed res; mixed res;
...@@ -190,6 +202,9 @@ int handshake_finished = 0; ...@@ -190,6 +202,9 @@ int handshake_finished = 0;
* -1 if a fatal error occured */ * -1 if a fatal error occured */
string|int got_data(string s) string|int got_data(string s)
{ {
/* If alert_callback is called, this data is passed as an argument */
string alert_context = (left_over || "") + s;
string res = ""; string res = "";
object packet; object packet;
while (packet = recv_packet(s)) while (packet = recv_packet(s))
...@@ -202,6 +217,8 @@ string|int got_data(string s) ...@@ -202,6 +217,8 @@ string|int got_data(string s)
werror("SSL.connection: Bad received packet\n"); werror("SSL.connection: Bad received packet\n");
#endif #endif
send_packet(packet); send_packet(packet);
if (alert_callback)
alert_callback(packet, current_read_state->seq_num, alert_context);
if (packet->level == ALERT_fatal) if (packet->level == ALERT_fatal)
return -1; return -1;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment