sixtop: refactoring sixp_trans_transit_state()
@@ -206,15 +206,12 @@ int
sixp_trans_transit_state(sixp_trans_t *trans, sixp_trans_state_t new_state)
{
sixp_nbr_t *nbr;
+ int ret_val;
assert(trans != NULL);
- if(trans == NULL) {
- LOG_ERR("6top: invalid argument, trans is NULL\n");
- return -1;
- }
-
/* enforce state transition rules */
- if(new_state == SIXP_TRANS_STATE_TERMINATING ||
+ if(trans != NULL &&
+ (new_state == SIXP_TRANS_STATE_TERMINATING ||
(new_state == SIXP_TRANS_STATE_REQUEST_SENT &&
trans->state == SIXP_TRANS_STATE_INIT) ||
(new_state == SIXP_TRANS_STATE_REQUEST_RECEIVED &&
@@ -228,7 +225,7 @@ sixp_trans_transit_state(sixp_trans_t *trans, sixp_trans_state_t new_state)
trans->mode == SIXP_TRANS_MODE_3_STEP) ||
(new_state == SIXP_TRANS_STATE_CONFIRMATION_SENT &&
trans->state == SIXP_TRANS_STATE_RESPONSE_RECEIVED &&
- trans->mode == SIXP_TRANS_MODE_3_STEP)) {
+ trans->mode == SIXP_TRANS_MODE_3_STEP))) {
LOG_INFO("6P-trans: trans %p state changes from %u to %u\n",
trans, trans->state, new_state);
@@ -258,16 +255,20 @@ sixp_trans_transit_state(sixp_trans_t *trans, sixp_trans_state_t new_state)
sixp_nbr_increment_next_seqno(nbr);
}
}
-
trans->state = new_state;
schedule_trans_process(trans);
- return 0;
- }
-
+ ret_val = 0;
+ } else if (trans != NULL){
/* invalid transition */
- LOG_ERR("6P-trans: invalid transaction, from %u to %u, detected on trans %p\n",
+ LOG_ERR("6P-trans: invalid transaction, from %u to %u, on trans %p\n",
trans->state, new_state, trans);
- return -1;
+ ret_val = -1;
+ } else {
+ /* trans == NULL */
+ LOG_ERR("6top: invalid argument, trans is NULL\n");
+ ret_val = -1;
+ }
+ return ret_val;
}
/*---------------------------------------------------------------------------*/
sixp_pkt_cmd_t
