📄 exosip.c
字号:
/* replace with the new tr */ if (MSG_IS_PUBLISH (msg)) { /* old transaction is put in the garbage list */ osip_list_add (&eXosip.j_transactions, out_tr, 0); /* new transaction is put in the publish context */ *ptr = tr; } else osip_list_add (&eXosip.j_transactions, tr, 0); sipevent = osip_new_outgoing_sipmessage (msg); ji = osip_transaction_get_your_instance (out_tr); osip_transaction_set_your_instance (out_tr, NULL); osip_transaction_set_your_instance (tr, ji); osip_transaction_add_event (tr, sipevent); if (retry) (*retry)++; eXosip_update (); /* fixed? */ __eXosip_wakeup (); return OSIP_SUCCESS;}static int_eXosip_retry_register_with_auth (eXosip_event_t * je){ eXosip_reg_t *jr = NULL; int i; i = eXosip_reg_find_id (&jr, je->rid); if (i < 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: registration not found\n")); return i; } if (jr->r_retry < 3) { jr->r_retry++; return eXosip_register_send_register (jr->r_id, NULL); } return OSIP_UNDEFINED_ERROR;}static int_eXosip_retry_invite_with_auth (eXosip_event_t * je){ eXosip_dialog_t *jd = NULL; eXosip_call_t *jc = NULL; int *retry = NULL; osip_transaction_t *tr = NULL; int i; i = _eXosip_call_transaction_find (je->tid, &jc, &jd, &tr); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: call dialog not found\n")); return i; } if (jd && jd->d_dialog) retry = &jd->d_retry; else retry = &jc->c_retry; if (*retry < 3) { (*retry)++; return _eXosip_call_retry_request (jc, jd, tr); } return OSIP_UNDEFINED_ERROR;}static int_eXosip_redirect_invite (eXosip_event_t * je){ eXosip_dialog_t *jd = NULL; eXosip_call_t *jc = NULL; osip_transaction_t *tr = NULL; int i; i = _eXosip_call_transaction_find (je->tid, &jc, &jd, &tr); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: call dialog not found\n")); return i; } return _eXosip_call_retry_request (jc, jd, tr);}static int_eXosip_retry_subscribe_with_auth (eXosip_event_t * je){ eXosip_dialog_t *jd = NULL; eXosip_subscribe_t *js = NULL; int *retry = NULL; osip_transaction_t *tr = NULL; int i; i = _eXosip_subscribe_transaction_find (je->tid, &js, &jd, &tr); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: subscribe dialog not found\n")); return i; } if (jd && jd->d_dialog) retry = &jd->d_retry; else retry = &js->s_retry; if (*retry < 3) { (*retry)++; return _eXosip_subscribe_send_request_with_credential (js, jd, tr); } return OSIP_UNDEFINED_ERROR;}static int_eXosip_retry_publish_with_auth (eXosip_event_t * je){ eXosip_pub_t *jp = NULL; int i; i = _eXosip_pub_find_by_tid (&jp, je->tid); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: publish transaction not found\n")); return i; } return _eXosip_retry_with_auth (NULL, &jp->p_last_tr, NULL);}static int_eXosip_retry_notify_with_auth (eXosip_event_t * je){ /* TODO untested */ eXosip_dialog_t *jd = NULL; eXosip_notify_t *jn = NULL; osip_transaction_t *tr = NULL; int i; i = _eXosip_insubscription_transaction_find (je->tid, &jn, &jd, &tr); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: notify dialog not found\n")); return i; } return _eXosip_insubscription_send_request_with_credential (jn, jd, tr);}static inteXosip_retry_with_auth (eXosip_event_t * je){ if (!je || !je->request || !je->response) return OSIP_BADPARAMETER; if (je->rid > 0) { return _eXosip_retry_register_with_auth (je); } else if (je->cid > 0) { return _eXosip_retry_invite_with_auth (je); }#ifndef MINISIZE else if (je->sid > 0) { return _eXosip_retry_subscribe_with_auth (je); } else if (je->nid > 0) { return _eXosip_retry_notify_with_auth (je); } else if (MSG_IS_PUBLISH (je->request)) return _eXosip_retry_publish_with_auth (je);#endif else { osip_transaction_t *tr = NULL; eXosip_transaction_find (je->tid, &tr); if (tr != NULL) { return _eXosip_retry_with_auth (NULL, &tr, NULL); } } OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: Can't retry event %d with auth\n", je->type)); return OSIP_UNDEFINED_ERROR;}static int_eXosip_redirect (eXosip_event_t * je){ switch (je->type) { case EXOSIP_CALL_REDIRECTED: return _eXosip_redirect_invite (je); case EXOSIP_CALL_MESSAGE_REDIRECTED: case EXOSIP_MESSAGE_REDIRECTED: case EXOSIP_SUBSCRIPTION_REDIRECTED: OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: not implemented\n")); return OSIP_UNDEFINED_ERROR; default: OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: Can't redirect event %d\n", je->type)); return OSIP_UNDEFINED_ERROR; }}inteXosip_default_action (eXosip_event_t * je){ if (!je || !je->response) return OSIP_BADPARAMETER; if (je->response->status_code == 401 || je->response->status_code == 407) return eXosip_retry_with_auth (je); else if (je->response->status_code >= 300 && je->response->status_code <= 399) return _eXosip_redirect (je); else return 1;}voideXosip_automatic_refresh (void){ eXosip_subscribe_t *js; eXosip_dialog_t *jd; eXosip_reg_t *jr; time_t now; now = time (NULL); for (js = eXosip.j_subscribes; js != NULL; js = js->next) { for (jd = js->s_dialogs; jd != NULL; jd = jd->next) { if (jd->d_dialog != NULL && (jd->d_id >= 1)) /* finished call */ { osip_transaction_t *out_tr = NULL; out_tr = osip_list_get (jd->d_out_trs, 0); if (out_tr == NULL) out_tr = js->s_out_tr; if (js->s_reg_period == 0 || out_tr == NULL) { } else if (now - out_tr->birth_time > js->s_reg_period - 60) { /* will expires in 60 sec: send refresh! */ int i; i = _eXosip_subscribe_automatic_refresh (js, jd, out_tr); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: could not send subscribe for refresh\n")); } } } } } for (jr = eXosip.j_reg; jr != NULL; jr = jr->next) { if (jr->r_id >= 1 && jr->r_last_tr != NULL) { if (jr->r_reg_period == 0) { /* skip refresh! */ } else if (now - jr->r_last_tr->birth_time > 900) { /* automatic refresh */ eXosip_register_send_register (jr->r_id, NULL); } else if (now - jr->r_last_tr->birth_time > jr->r_reg_period - 60) { /* automatic refresh */ eXosip_register_send_register (jr->r_id, NULL); } else if (now - jr->r_last_tr->birth_time > 120 && (jr->r_last_tr->last_response == NULL || (!MSG_IS_STATUS_2XX (jr->r_last_tr->last_response)))) { /* automatic refresh */ eXosip_register_send_register (jr->r_id, NULL); } } }}#endifvoideXosip_retransmit_lost200ok (){ eXosip_call_t *jc; eXosip_dialog_t *jd; time_t now; now = time (NULL); for (jc = eXosip.j_calls; jc != NULL; jc = jc->next) { if (jc->c_id >= 1 && jc->c_dialogs != NULL) { for (jd = jc->c_dialogs; jd != NULL; jd = jd->next) { if (jd->d_id >= 1 && jd->d_dialog != NULL && jd->d_200Ok != NULL) { if (jd->d_count == 9) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: no ACK received during 20s: dropping call\n")); /* hard for users to detect than I sent this BYE... */ jd->d_count = 0; osip_message_free (jd->d_200Ok); jd->d_200Ok = NULL; eXosip_call_terminate (jc->c_id, jd->d_id); } else if (jd->d_timer < now) { /* a dialog exist: retransmit lost 200ok */ jd->d_count++; if (jd->d_count == 1) jd->d_timer = time (NULL) + 1; if (jd->d_count == 2) jd->d_timer = time (NULL) + 2; if (jd->d_count >= 3) jd->d_timer = time (NULL) + 4; jd = jc->c_dialogs; /* TU retransmission */ cb_snd_message (NULL, jd->d_200Ok, NULL, 0, -1); } } } } } return;}voideXosip_automatic_action (void){ eXosip_call_t *jc; eXosip_dialog_t *jd;#ifndef MINISIZE eXosip_subscribe_t *js; eXosip_notify_t *jn;#endif eXosip_reg_t *jr;#ifndef MINISIZE eXosip_pub_t *jpub;#endif time_t now; now = time (NULL); for (jc = eXosip.j_calls; jc != NULL; jc = jc->next) { if (jc->c_id < 1) { } else if (jc->c_dialogs == NULL || jc->c_dialogs->d_dialog == NULL) { /* an EARLY dialog may have failed with 401,407 or 3Xx */ osip_transaction_t *out_tr = NULL; out_tr = jc->c_out_tr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -