From 7401269517dde71e0fdc392b5b9996e0b9ef9a49 Mon Sep 17 00:00:00 2001 From: Andreas Steffen Date: Thu, 23 Jun 2011 19:52:30 +0200 Subject: [PATCH] refactoring of change_state() --- src/libimcv/imc/imc_agent.c | 8 +++++++- src/libimcv/imc/imc_agent.h | 4 +++- src/libimcv/imv/imv_agent.c | 7 ++++++- src/libimcv/imv/imv_agent.h | 4 +++- src/libimcv/plugins/imc_test/imc_test.c | 24 +++++++++++------------- src/libimcv/plugins/imv_test/imv_test.c | 13 +++++++------ 6 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/libimcv/imc/imc_agent.c b/src/libimcv/imc/imc_agent.c index a19e7ed66..94f1c1b66 100644 --- a/src/libimcv/imc/imc_agent.c +++ b/src/libimcv/imc/imc_agent.c @@ -209,7 +209,8 @@ METHOD(imc_agent_t, delete_state, TNC_Result, METHOD(imc_agent_t, change_state, TNC_Result, private_imc_agent_t *this, TNC_ConnectionID connection_id, - TNC_ConnectionState new_state) + TNC_ConnectionState new_state, + imc_state_t **state_p) { imc_state_t *state; @@ -220,6 +221,7 @@ METHOD(imc_agent_t, change_state, TNC_Result, case TNC_CONNECTION_STATE_ACCESS_ISOLATED: case TNC_CONNECTION_STATE_ACCESS_NONE: state = find_connection(this, connection_id); + if (!state) { DBG1(DBG_IMC, "IMC %u \"%s\" has no state for Connection ID %u", @@ -230,6 +232,10 @@ METHOD(imc_agent_t, change_state, TNC_Result, DBG2(DBG_IMC, "IMC %u \"%s\" changed state of Connection ID %u to '%N'", this->id, this->name, connection_id, TNC_Connection_State_names, new_state); + if (state_p) + { + *state_p = state; + } break; case TNC_CONNECTION_STATE_CREATE: DBG1(DBG_IMC, "state '%N' should be handled by create_state()", diff --git a/src/libimcv/imc/imc_agent.h b/src/libimcv/imc/imc_agent.h index f9d16fa50..1912a39c1 100644 --- a/src/libimcv/imc/imc_agent.h +++ b/src/libimcv/imc/imc_agent.h @@ -79,11 +79,13 @@ struct imc_agent_t { * * @param connection_id network connection ID assigned by TNCS * @param new_state new state of TNCCS connection + * @param state_p internal IMC state instance [optional argument] * @return TNC result code */ TNC_Result (*change_state)(imc_agent_t *this, TNC_ConnectionID connection_id, - TNC_ConnectionState new_state); + TNC_ConnectionState new_state, + imc_state_t **state_p); /** * Get the IMC state for a TNCCS connection instance diff --git a/src/libimcv/imv/imv_agent.c b/src/libimcv/imv/imv_agent.c index 571daf807..bf9956879 100644 --- a/src/libimcv/imv/imv_agent.c +++ b/src/libimcv/imv/imv_agent.c @@ -274,7 +274,8 @@ METHOD(imv_agent_t, delete_state, TNC_Result, METHOD(imv_agent_t, change_state, TNC_Result, private_imv_agent_t *this, TNC_ConnectionID connection_id, - TNC_ConnectionState new_state) + TNC_ConnectionState new_state, + imv_state_t **state_p) { imv_state_t *state; @@ -295,6 +296,10 @@ METHOD(imv_agent_t, change_state, TNC_Result, DBG2(DBG_IMV, "IMV %u \"%s\" changed state of Connection ID %u to '%N'", this->id, this->name, connection_id, TNC_Connection_State_names, new_state); + if (state_p) + { + *state_p = state; + } break; case TNC_CONNECTION_STATE_CREATE: DBG1(DBG_IMV, "state '%N' should be handled by create_state()", diff --git a/src/libimcv/imv/imv_agent.h b/src/libimcv/imv/imv_agent.h index bffa1addc..b6c8841f2 100644 --- a/src/libimcv/imv/imv_agent.h +++ b/src/libimcv/imv/imv_agent.h @@ -79,11 +79,13 @@ struct imv_agent_t { * * @param connection_id network connection ID assigned by TNCS * @param new_state new state of TNCCS connection + * @param state_p internal IMV state instance [optional argument] * @return TNC result code */ TNC_Result (*change_state)(imv_agent_t *this, TNC_ConnectionID connection_id, - TNC_ConnectionState new_state); + TNC_ConnectionState new_state, + imv_state_t **state_p); /** * Get the IMV state for a TNCCS connection instance diff --git a/src/libimcv/plugins/imc_test/imc_test.c b/src/libimcv/plugins/imc_test/imc_test.c index 4c7c2d144..7a2bb5e36 100644 --- a/src/libimcv/plugins/imc_test/imc_test.c +++ b/src/libimcv/plugins/imc_test/imc_test.c @@ -70,6 +70,7 @@ TNC_Result TNC_IMC_NotifyConnectionChange(TNC_IMCID imc_id, { imc_state_t *state; imc_test_state_t *test_state; + TNC_Result result; char *command; bool retry; @@ -89,15 +90,13 @@ TNC_Result TNC_IMC_NotifyConnectionChange(TNC_IMCID imc_id, return imc_test->create_state(imc_test, state); case TNC_CONNECTION_STATE_HANDSHAKE: - /* get current IMC state and update it */ - if (!imc_test->get_state(imc_test, connection_id, &state)) + /* get updated IMC state */ + result = imc_test->change_state(imc_test, connection_id, + new_state, &state); + if (result != TNC_RESULT_SUCCESS) { return TNC_RESULT_FATAL; } - state->change_state(state, new_state); - DBG2(DBG_IMC, "IMC %u \"%s\" changed state of Connection ID %u to '%N'", - imc_id, imc_name, connection_id, - TNC_Connection_State_names, new_state); test_state = (imc_test_state_t*)state; /* is it the first handshake or a retry ? */ @@ -115,15 +114,13 @@ TNC_Result TNC_IMC_NotifyConnectionChange(TNC_IMCID imc_id, case TNC_CONNECTION_STATE_ACCESS_ISOLATED: case TNC_CONNECTION_STATE_ACCESS_NONE: - /* get current IMC state and update it */ - if (!imc_test->get_state(imc_test, connection_id, &state)) + /* get updated IMC state */ + result = imc_test->change_state(imc_test, connection_id, + new_state, &state); + if (result != TNC_RESULT_SUCCESS) { return TNC_RESULT_FATAL; } - state->change_state(state, new_state); - DBG2(DBG_IMC, "IMC %u \"%s\" changed state of Connection ID %u to '%N'", - imc_id, imc_name, connection_id, - TNC_Connection_State_names, new_state); test_state = (imc_test_state_t*)state; /* do a handshake retry? */ @@ -135,7 +132,8 @@ TNC_Result TNC_IMC_NotifyConnectionChange(TNC_IMCID imc_id, return TNC_RESULT_SUCCESS; default: - return imc_test->change_state(imc_test, connection_id, new_state); + return imc_test->change_state(imc_test, connection_id, + new_state, NULL); } } diff --git a/src/libimcv/plugins/imv_test/imv_test.c b/src/libimcv/plugins/imv_test/imv_test.c index f2230a48c..6ef6ab661 100644 --- a/src/libimcv/plugins/imv_test/imv_test.c +++ b/src/libimcv/plugins/imv_test/imv_test.c @@ -70,6 +70,7 @@ TNC_Result TNC_IMV_NotifyConnectionChange(TNC_IMVID imv_id, { imv_state_t *state; imv_test_state_t *test_state; + TNC_Result result; int rounds; if (!imv_test) @@ -85,14 +86,13 @@ TNC_Result TNC_IMV_NotifyConnectionChange(TNC_IMVID imv_id, case TNC_CONNECTION_STATE_DELETE: return imv_test->delete_state(imv_test, connection_id); case TNC_CONNECTION_STATE_HANDSHAKE: - if (!imv_test->get_state(imv_test, connection_id, &state)) + /* get updated IMV state */ + result = imv_test->change_state(imv_test, connection_id, + new_state, &state); + if (result != TNC_RESULT_SUCCESS) { return TNC_RESULT_FATAL; } - state->change_state(state, new_state); - DBG2(DBG_IMV, "IMV %u \"%s\" changed state of Connection ID %u to '%N'", - imv_id, imv_name, connection_id, - TNC_Connection_State_names, new_state); test_state = (imv_test_state_t*)state; /* set the number of measurement rounds */ @@ -101,7 +101,8 @@ TNC_Result TNC_IMV_NotifyConnectionChange(TNC_IMVID imv_id, test_state->set_rounds(test_state, rounds); return TNC_RESULT_SUCCESS; default: - return imv_test->change_state(imv_test, connection_id, new_state); + return imv_test->change_state(imv_test, connection_id, + new_state, NULL); } }