/* * This is the handler to receive state changed notification from the * transaction. It is used to verify that the transaction behaves according * to the test scenario. */ static void tsx_user_on_tsx_state(pjsip_transaction *tsx, pjsip_event *e) { if (pj_strcmp2(&tsx->branch, TEST1_BRANCH_ID)==0) { /* * Transaction with TEST1_BRANCH_ID should terminate with transaction * timeout status. */ if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { if (test_complete == 0) test_complete = 1; /* Test the status code. */ if (tsx->status_code != PJSIP_SC_TSX_TIMEOUT) { PJ_LOG(3,(THIS_FILE, " error: status code is %d instead of %d", tsx->status_code, PJSIP_SC_TSX_TIMEOUT)); test_complete = -710; } /* If transport is reliable, then there must not be any * retransmissions. */ if (tp_flag & PJSIP_TRANSPORT_RELIABLE) { if (recv_count != 1) { PJ_LOG(3,(THIS_FILE, " error: there were %d (re)transmissions", recv_count)); test_complete = -715; } } else { /* Check the number of transmissions, which must be * 6 for INVITE and 10 for non-INVITE */ if (tsx->method.id==PJSIP_INVITE_METHOD && recv_count != 7) { PJ_LOG(3,(THIS_FILE, " error: there were %d (re)transmissions", recv_count)); test_complete = -716; } else if (tsx->method.id==PJSIP_OPTIONS_METHOD && recv_count != 11) { PJ_LOG(3,(THIS_FILE, " error: there were %d (re)transmissions", recv_count)); test_complete = -717; } else if (tsx->method.id!=PJSIP_INVITE_METHOD && tsx->method.id!=PJSIP_OPTIONS_METHOD) { PJ_LOG(3,(THIS_FILE, " error: unexpected method")); test_complete = -718; } } } } else if (pj_strcmp2(&tsx->branch, TEST2_BRANCH_ID)==0) { /* * Transaction with TEST2_BRANCH_ID should terminate with transport error. */ if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { /* Test the status code. */ if (tsx->status_code != PJSIP_SC_TSX_TRANSPORT_ERROR) { PJ_LOG(3,(THIS_FILE, " error: status code is %d instead of %d", tsx->status_code, PJSIP_SC_TSX_TRANSPORT_ERROR)); test_complete = -720; } if (test_complete == 0) test_complete = 1; } } else if (pj_strcmp2(&tsx->branch, TEST3_BRANCH_ID)==0) { /* * This test terminates the transaction while resolver is still * running. */ if (tsx->state == PJSIP_TSX_STATE_CALLING) { /* Terminate the transaction. */ pjsip_tsx_terminate(tsx, PJSIP_SC_REQUEST_TERMINATED); } else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { /* Check if status code is correct. */ if (tsx->status_code != PJSIP_SC_REQUEST_TERMINATED) { PJ_LOG(3,(THIS_FILE, " error: status code is %d instead of %d", tsx->status_code, PJSIP_SC_REQUEST_TERMINATED)); test_complete = -730; } if (test_complete == 0) test_complete = 1; } } else if (pj_strcmp2(&tsx->branch, TEST4_BRANCH_ID)==0) { /* * This test simulates transport failure after several * retransmissions. */ if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { /* Status code must be transport error. */ if (tsx->status_code != PJSIP_SC_TSX_TRANSPORT_ERROR) { PJ_LOG(3,(THIS_FILE, " error: status code is %d instead of %d", tsx->status_code, PJSIP_SC_TSX_TRANSPORT_ERROR)); test_complete = -730; } /* Must have correct retransmission count. */ if (tsx->retransmit_count != TEST4_RETRANSMIT_CNT) { PJ_LOG(3,(THIS_FILE, " error: retransmit cnt is %d instead of %d", tsx->retransmit_count, TEST4_RETRANSMIT_CNT)); test_complete = -731; } if (test_complete == 0) test_complete = 1; } } else if (pj_strcmp2(&tsx->branch, TEST5_BRANCH_ID)==0) { /* * This test simulates transport failure after several * retransmissions. */ if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { /* Status code must be PJSIP_SC_REQUEST_TERMINATED. */ if (tsx->status_code != PJSIP_SC_REQUEST_TERMINATED) { PJ_LOG(3,(THIS_FILE, " error: status code is %d instead of %d", tsx->status_code, PJSIP_SC_REQUEST_TERMINATED)); test_complete = -733; } /* Must have correct retransmission count. */ if (tsx->retransmit_count != TEST5_RETRANSMIT_CNT) { PJ_LOG(3,(THIS_FILE, " error: retransmit cnt is %d instead of %d", tsx->retransmit_count, TEST5_RETRANSMIT_CNT)); test_complete = -734; } if (test_complete == 0) test_complete = 1; } } else if (pj_strcmp2(&tsx->branch, TEST6_BRANCH_ID)==0) { /* * Successfull non-INVITE transaction. */ if (tsx->state == PJSIP_TSX_STATE_COMPLETED) { /* Status code must be 202. */ if (tsx->status_code != 202) { PJ_LOG(3,(THIS_FILE, " error: status code is %d instead of %d", tsx->status_code, 202)); test_complete = -736; } /* Must have correct retransmission count. */ if (tsx->retransmit_count != 0) { PJ_LOG(3,(THIS_FILE, " error: retransmit cnt is %d instead of %d", tsx->retransmit_count, 0)); test_complete = -737; } /* Must still keep last_tx */ if (tsx->last_tx == NULL) { PJ_LOG(3,(THIS_FILE, " error: transaction lost last_tx")); test_complete = -738; } if (test_complete == 0) { test_complete = 1; pjsip_tsx_terminate(tsx, 202); } } else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { /* Previous state must be COMPLETED. */ if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { test_complete = -7381; } } } else if (pj_strcmp2(&tsx->branch, TEST7_BRANCH_ID)==0) { /* * Successfull non-INVITE transaction. */ if (tsx->state == PJSIP_TSX_STATE_COMPLETED) { /* Check prev state. */ if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_PROCEEDING) { PJ_LOG(3,(THIS_FILE, " error: prev state is %s instead of %s", pjsip_tsx_state_str(e->body.tsx_state.prev_state), pjsip_tsx_state_str(PJSIP_TSX_STATE_PROCEEDING))); test_complete = -739; } /* Status code must be 202. */ if (tsx->status_code != 202) { PJ_LOG(3,(THIS_FILE, " error: status code is %d instead of %d", tsx->status_code, 202)); test_complete = -740; } /* Must have correct retransmission count. */ if (tsx->retransmit_count != 0) { PJ_LOG(3,(THIS_FILE, " error: retransmit cnt is %d instead of %d", tsx->retransmit_count, 0)); test_complete = -741; } /* Must still keep last_tx */ if (tsx->last_tx == NULL) { PJ_LOG(3,(THIS_FILE, " error: transaction lost last_tx")); test_complete = -741; } if (test_complete == 0) { test_complete = 1; pjsip_tsx_terminate(tsx, 202); } } else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { /* Previous state must be COMPLETED. */ if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { test_complete = -742; } } } else if (pj_strcmp2(&tsx->branch, TEST8_BRANCH_ID)==0) { /* * Failed INVITE transaction. */ if (tsx->state == PJSIP_TSX_STATE_COMPLETED) { /* Status code must be 301. */ if (tsx->status_code != 301) { PJ_LOG(3,(THIS_FILE, " error: status code is %d instead of %d", tsx->status_code, 301)); test_complete = -745; } /* Must have correct retransmission count. */ if (tsx->retransmit_count != 0) { PJ_LOG(3,(THIS_FILE, " error: retransmit cnt is %d instead of %d", tsx->retransmit_count, 0)); test_complete = -746; } /* Must still keep last_tx */ if (tsx->last_tx == NULL) { PJ_LOG(3,(THIS_FILE, " error: transaction lost last_tx")); test_complete = -747; } /* last_tx MUST be the INVITE request * (authorization depends on this behavior) */ if (tsx->last_tx && tsx->last_tx->msg->line.req.method.id != PJSIP_INVITE_METHOD) { PJ_LOG(3,(THIS_FILE, " error: last_tx is not INVITE")); test_complete = -748; } } else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { test_complete = 1; /* Previous state must be COMPLETED. */ if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { test_complete = -750; } /* Status code must be 301. */ if (tsx->status_code != 301) { PJ_LOG(3,(THIS_FILE, " error: status code is %d instead of %d", tsx->status_code, 301)); test_complete = -751; } } } else if (pj_strcmp2(&tsx->branch, TEST9_BRANCH_ID)==0) { /* * Failed INVITE transaction with provisional response. */ if (tsx->state == PJSIP_TSX_STATE_COMPLETED) { /* Previous state must be PJSIP_TSX_STATE_PROCEEDING. */ if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_PROCEEDING) { test_complete = -760; } /* Status code must be 302. */ if (tsx->status_code != 302) { PJ_LOG(3,(THIS_FILE, " error: status code is %d instead of %d", tsx->status_code, 302)); test_complete = -761; } /* Must have correct retransmission count. */ if (tsx->retransmit_count != 0) { PJ_LOG(3,(THIS_FILE, " error: retransmit cnt is %d instead of %d", tsx->retransmit_count, 0)); test_complete = -762; } /* Must still keep last_tx */ if (tsx->last_tx == NULL) { PJ_LOG(3,(THIS_FILE, " error: transaction lost last_tx")); test_complete = -763; } /* last_tx MUST be INVITE. * (authorization depends on this behavior) */ if (tsx->last_tx && tsx->last_tx->msg->line.req.method.id != PJSIP_INVITE_METHOD) { PJ_LOG(3,(THIS_FILE, " error: last_tx is not INVITE")); test_complete = -764; } } else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { test_complete = 1; /* Previous state must be COMPLETED. */ if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { test_complete = -767; } /* Status code must be 302. */ if (tsx->status_code != 302) { PJ_LOG(3,(THIS_FILE, " error: status code is %d instead of %d", tsx->status_code, 302)); test_complete = -768; } } } }
/* * This is the handler to receive state changed notification from the * transaction. It is used to verify that the transaction behaves according * to the test scenario. */ static void tsx_user_on_tsx_state(pjsip_transaction *tsx, pjsip_event *e) { if (pj_stricmp2(&tsx->branch, TEST1_BRANCH_ID)==0 || pj_stricmp2(&tsx->branch, TEST2_BRANCH_ID)==0) { /* * TEST1_BRANCH_ID tests that non-INVITE transaction transmits final * response using correct transport and terminates transaction after * T4 (PJSIP_T4_TIMEOUT, 5 seconds). * * TEST2_BRANCH_ID does similar test for non-2xx final response. */ int status_code = (pj_stricmp2(&tsx->branch, TEST1_BRANCH_ID)==0) ? TEST1_STATUS_CODE : TEST2_STATUS_CODE; if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { test_complete = 1; /* Check that status code is status_code. */ if (tsx->status_code != status_code) { PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); test_complete = -100; } /* Previous state must be completed. */ if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); test_complete = -101; } } else if (tsx->state == PJSIP_TSX_STATE_COMPLETED) { /* Previous state must be TRYING. */ if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) { PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); test_complete = -102; } } } else if (pj_stricmp2(&tsx->branch, TEST3_BRANCH_ID)==0) { /* * TEST3_BRANCH_ID tests sending provisional response. */ if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { test_complete = 1; /* Check that status code is status_code. */ if (tsx->status_code != TEST3_STATUS_CODE) { PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); test_complete = -110; } /* Previous state must be completed. */ if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); test_complete = -111; } } else if (tsx->state == PJSIP_TSX_STATE_PROCEEDING) { /* Previous state must be TRYING. */ if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) { PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); test_complete = -112; } /* Check that status code is status_code. */ if (tsx->status_code != TEST3_PROVISIONAL_CODE) { PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); test_complete = -113; } /* Check that event must be TX_MSG */ if (e->body.tsx_state.type != PJSIP_EVENT_TX_MSG) { PJ_LOG(3,(THIS_FILE, " error: incorrect event")); test_complete = -114; } } else if (tsx->state == PJSIP_TSX_STATE_COMPLETED) { /* Previous state must be PROCEEDING. */ if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_PROCEEDING) { PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); test_complete = -115; } /* Check that status code is status_code. */ if (tsx->status_code != TEST3_STATUS_CODE) { PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); test_complete = -116; } /* Check that event must be TX_MSG */ if (e->body.tsx_state.type != PJSIP_EVENT_TX_MSG) { PJ_LOG(3,(THIS_FILE, " error: incorrect event")); test_complete = -117; } } } else if (pj_stricmp2(&tsx->branch, TEST4_BRANCH_ID)==0) { /* * TEST4_BRANCH_ID tests receiving retransmissions in TRYING state. */ if (tsx->state == PJSIP_TSX_STATE_TRYING) { /* Request is received. */ } else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { /* Check that status code is status_code. */ if (tsx->status_code != TEST4_STATUS_CODE) { PJ_LOG(3,(THIS_FILE, " error: incorrect status code %d " "(expecting %d)", tsx->status_code, TEST4_STATUS_CODE)); test_complete = -120; } /* Previous state. */ if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) { PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); test_complete = -121; } } else if (tsx->state != PJSIP_TSX_STATE_DESTROYED) { PJ_LOG(3,(THIS_FILE, " error: unexpected state %s (122)", pjsip_tsx_state_str(tsx->state))); test_complete = -122; } } else if (pj_stricmp2(&tsx->branch, TEST5_BRANCH_ID)==0) { /* * TEST5_BRANCH_ID tests receiving retransmissions in PROCEEDING state */ if (tsx->state == PJSIP_TSX_STATE_TRYING) { /* Request is received. */ } else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { /* Check that status code is status_code. */ if (tsx->status_code != TEST5_STATUS_CODE) { PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); test_complete = -130; } /* Previous state. */ if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_PROCEEDING) { PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); test_complete = -131; } } else if (tsx->state == PJSIP_TSX_STATE_PROCEEDING) { /* Check status code. */ if (tsx->status_code != TEST5_PROVISIONAL_CODE) { PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); test_complete = -132; } } else if (tsx->state != PJSIP_TSX_STATE_DESTROYED) { PJ_LOG(3,(THIS_FILE, " error: unexpected state %s (133)", pjsip_tsx_state_str(tsx->state))); test_complete = -133; } } else if (pj_stricmp2(&tsx->branch, TEST6_BRANCH_ID)==0) { /* * TEST6_BRANCH_ID tests receiving retransmissions in COMPLETED state */ if (tsx->state == PJSIP_TSX_STATE_TRYING) { /* Request is received. */ } else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { /* Check that status code is status_code. */ if (tsx->status_code != TEST6_STATUS_CODE) { PJ_LOG(3,(THIS_FILE, " error: incorrect status code %d " "(expecting %d)", tsx->status_code, TEST6_STATUS_CODE)); test_complete = -140; } /* Previous state. */ if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); test_complete = -141; } } else if (tsx->state != PJSIP_TSX_STATE_PROCEEDING && tsx->state != PJSIP_TSX_STATE_COMPLETED && tsx->state != PJSIP_TSX_STATE_DESTROYED) { PJ_LOG(3,(THIS_FILE, " error: unexpected state %s (142)", pjsip_tsx_state_str(tsx->state))); test_complete = -142; } } else if (pj_stricmp2(&tsx->branch, TEST7_BRANCH_ID)==0 || pj_stricmp2(&tsx->branch, TEST8_BRANCH_ID)==0) { /* * TEST7_BRANCH_ID and TEST8_BRANCH_ID test retransmission of * INVITE final response */ int code; if (pj_stricmp2(&tsx->branch, TEST7_BRANCH_ID) == 0) code = TEST7_STATUS_CODE; else code = TEST8_STATUS_CODE; if (tsx->state == PJSIP_TSX_STATE_TRYING) { /* Request is received. */ } else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { if (test_complete == 0) test_complete = 1; /* Check status code. */ if (tsx->status_code != PJSIP_SC_TSX_TIMEOUT) { PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); test_complete = -150; } /* Previous state. */ if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); test_complete = -151; } /* Check the number of retransmissions */ if (tp_flag & PJSIP_TRANSPORT_RELIABLE) { if (tsx->retransmit_count != 0) { PJ_LOG(3,(THIS_FILE, " error: should not retransmit")); test_complete = -1510; } } else { if (tsx->retransmit_count != 10) { PJ_LOG(3,(THIS_FILE, " error: incorrect retransmit count %d " "(expecting 10)", tsx->retransmit_count)); test_complete = -1510; } } } else if (tsx->state == PJSIP_TSX_STATE_COMPLETED) { /* Check that status code is status_code. */ if (tsx->status_code != code) { PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); test_complete = -152; } /* Previous state. */ if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) { PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); test_complete = -153; } } else if (tsx->state != PJSIP_TSX_STATE_DESTROYED) { PJ_LOG(3,(THIS_FILE, " error: unexpected state (154)")); test_complete = -154; } } else if (pj_stricmp2(&tsx->branch, TEST9_BRANCH_ID)==0) { /* * TEST9_BRANCH_ID tests that retransmission of INVITE final response * must cease when ACK is received. */ if (tsx->state == PJSIP_TSX_STATE_TRYING) { /* Request is received. */ } else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { if (test_complete == 0) test_complete = 1; /* Check status code. */ if (tsx->status_code != TEST9_STATUS_CODE) { PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); test_complete = -160; } /* Previous state. */ if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_CONFIRMED) { PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); test_complete = -161; } } else if (tsx->state == PJSIP_TSX_STATE_COMPLETED) { /* Check that status code is status_code. */ if (tsx->status_code != TEST9_STATUS_CODE) { PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); test_complete = -162; } /* Previous state. */ if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_TRYING) { PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); test_complete = -163; } } else if (tsx->state == PJSIP_TSX_STATE_CONFIRMED) { /* Check that status code is status_code. */ if (tsx->status_code != TEST9_STATUS_CODE) { PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); test_complete = -164; } /* Previous state. */ if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { PJ_LOG(3,(THIS_FILE, " error: incorrect prev_state")); test_complete = -165; } } else if (tsx->state != PJSIP_TSX_STATE_DESTROYED) { PJ_LOG(3,(THIS_FILE, " error: unexpected state (166)")); test_complete = -166; } } else if (pj_stricmp2(&tsx->branch, TEST10_BRANCH_ID)==0 || pj_stricmp2(&tsx->branch, TEST11_BRANCH_ID)==0 || pj_stricmp2(&tsx->branch, TEST12_BRANCH_ID)==0) { if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { if (!test_complete) test_complete = 1; if (tsx->status_code != PJSIP_SC_TSX_TRANSPORT_ERROR) { PJ_LOG(3,(THIS_FILE," error: incorrect status code")); test_complete = -170; } } } }