osip_transaction_t * _eXosip_find_last_invite (eXosip_call_t * jc, eXosip_dialog_t * jd) { osip_transaction_t *inc_tr; osip_transaction_t *out_tr; inc_tr = _eXosip_find_last_inc_invite (jc, jd); out_tr = _eXosip_find_last_out_invite (jc, jd); if (inc_tr == NULL) return out_tr; if (out_tr == NULL) return inc_tr; if (inc_tr->birth_time > out_tr->birth_time) return inc_tr; return out_tr; }
int _eXosip_answer_invite_123456xx (struct eXosip_t *excontext, eXosip_call_t * jc, eXosip_dialog_t * jd, int code, osip_message_t ** answer, int send) { int i; osip_transaction_t *tr; *answer = NULL; tr = _eXosip_find_last_inc_invite (jc, jd); if (tr == NULL || tr->orig_request == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot find transaction to answer\n")); return OSIP_NOTFOUND; } if (code >= 200 && code < 300 && jd != NULL && jd->d_dialog == NULL) { /* element previously removed */ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot answer this closed transaction\n")); return OSIP_WRONG_STATE; } /* is the transaction already answered? */ if (tr->state == IST_COMPLETED || tr->state == IST_CONFIRMED || tr->state == IST_TERMINATED) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: transaction already answered\n")); return OSIP_WRONG_STATE; } if (jd == NULL) i = _eXosip_build_response_default (excontext, answer, NULL, code, tr->orig_request); else i = _eXosip_build_response_default (excontext, answer, jd->d_dialog, code, tr->orig_request); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL, "ERROR: Could not create response for invite\n")); *answer = NULL; return i; } /* request that estabish a dialog: */ /* 12.1.1 UAS Behavior */ if (code > 100 && code < 300) { i = _eXosip_complete_answer_that_establish_a_dialog (excontext, *answer, tr->orig_request); if (i != 0) { osip_message_free (*answer); *answer = NULL; return i; } } if (send == 1) { osip_event_t *evt_answer; if (code >= 200 && code < 300 && jd != NULL) { _eXosip_dialog_set_200ok (jd, *answer); /* wait for a ACK */ osip_dialog_set_state (jd->d_dialog, DIALOG_CONFIRMED); } evt_answer = osip_new_outgoing_sipmessage (*answer); evt_answer->transactionid = tr->transactionid; osip_transaction_add_event (tr, evt_answer); _eXosip_wakeup (excontext); *answer = NULL; } return OSIP_SUCCESS; }