summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2013-07-11 22:53:34 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2013-07-11 22:53:34 +0200
commit9710537aec5de17d07ae6d2b07c956db8e8257bf (patch)
tree071d45c64c197d96ef1abc96f7b3d8a3c68999f0
parentd8e8378663bb4534a7238a86d80f213e70bfbe91 (diff)
downloadgnutls-9710537aec5de17d07ae6d2b07c956db8e8257bf.tar.gz
Revert "simplified hook function, to apply only to post-processing or generation of messages."
This reverts commit 7b14a8217b78aaf3367d13181237bf937292f5ba.
-rw-r--r--lib/gnutls_handshake.c27
-rw-r--r--lib/gnutls_state.c2
-rw-r--r--lib/includes/gnutls/gnutls.h.in3
3 files changed, 24 insertions, 8 deletions
diff --git a/lib/gnutls_handshake.c b/lib/gnutls_handshake.c
index f2b3fa5f85..a90d1a580d 100644
--- a/lib/gnutls_handshake.c
+++ b/lib/gnutls_handshake.c
@@ -1143,14 +1143,14 @@ _gnutls_send_empty_handshake (gnutls_session_t session,
inline
static int call_hook_func(gnutls_session_t session, gnutls_handshake_description_t type,
- unsigned incoming)
+ unsigned post, unsigned incoming)
{
if (session->internals.h_hook == NULL)
return 0;
else
{
if (session->internals.h_type == type || session->internals.h_type == GNUTLS_HANDSHAKE_ANY)
- return session->internals.h_hook(session, type, incoming);
+ return session->internals.h_hook(session, type, post, incoming);
return 0;
}
@@ -1222,15 +1222,16 @@ _gnutls_send_handshake (gnutls_session_t session, mbuffer_st * bufel,
return ret;
}
- session->internals.last_handshake_out = type;
-
- ret = call_hook_func(session, type, 0);
+ ret = call_hook_func(session, type, 0, 0);
if (ret < 0)
{
gnutls_assert ();
+ _mbuffer_xfree(&bufel);
return ret;
}
+ session->internals.last_handshake_out = type;
+
ret = _gnutls_handshake_io_cache_int (session, type, bufel);
if (ret < 0)
{
@@ -1263,6 +1264,13 @@ _gnutls_send_handshake (gnutls_session_t session, mbuffer_st * bufel,
break;
}
+ ret = call_hook_func(session, type, 1, 0);
+ if (ret < 0)
+ {
+ gnutls_assert ();
+ return ret;
+ }
+
return ret;
}
@@ -1389,6 +1397,13 @@ _gnutls_recv_handshake (gnutls_session_t session,
session->internals.last_handshake_in = hsk.htype;
+ ret = call_hook_func(session, hsk.htype, 0, 1);
+ if (ret < 0)
+ {
+ gnutls_assert ();
+ goto cleanup;
+ }
+
ret = _gnutls_handshake_hash_add_recvd (session, hsk.htype,
hsk.header, hsk.header_size,
hsk.data.data, hsk.data.length);
@@ -1460,7 +1475,7 @@ _gnutls_recv_handshake (gnutls_session_t session,
goto cleanup;
}
- ret2 = call_hook_func(session, hsk.htype, 1);
+ ret2 = call_hook_func(session, hsk.htype, 1, 1);
if (ret2 < 0)
{
ret = ret2;
diff --git a/lib/gnutls_state.c b/lib/gnutls_state.c
index bc7abae4e3..a5b8ec8c99 100644
--- a/lib/gnutls_state.c
+++ b/lib/gnutls_state.c
@@ -1414,7 +1414,7 @@ gnutls_handshake_set_random (gnutls_session_t session, const gnutls_datum_t* ran
* @htype: the %gnutls_handshake_description_t of the message to hook at.
* @func: is the function to be called
*
- * This function will set a callback to be called after the specified
+ * This function will set a callback to be called after or before the specified
* handshake message has been received or generated. This is a
* generalization of gnutls_handshake_set_post_client_hello_function().
*
diff --git a/lib/includes/gnutls/gnutls.h.in b/lib/includes/gnutls/gnutls.h.in
index 542d3e9929..35d5ed3ecf 100644
--- a/lib/includes/gnutls/gnutls.h.in
+++ b/lib/includes/gnutls/gnutls.h.in
@@ -1179,6 +1179,7 @@ gnutls_ecc_curve_t gnutls_ecc_curve_get(gnutls_session_t session);
* gnutls_handshake_hook_func:
* @session: the current session
* @htype: the type of the handshake message (%gnutls_handshake_description_t)
+ * @post: non zero if this is an post-process/generation call and zero otherwise
* @incoming: non zero if this is an incoming message and zero if this is an outgoing message
*
* Function prototype for handshake hooks. It is set using
@@ -1187,7 +1188,7 @@ gnutls_ecc_curve_t gnutls_ecc_curve_get(gnutls_session_t session);
* Returns: Non zero on error.
*/
- typedef int (*gnutls_handshake_hook_func) (gnutls_session_t, unsigned int htype, unsigned int incoming);
+ typedef int (*gnutls_handshake_hook_func) (gnutls_session_t, unsigned int htype, unsigned int post, unsigned int incoming);
void gnutls_handshake_set_hook_function (gnutls_session_t session,
unsigned int htype,
gnutls_handshake_hook_func func);