📄 osip.c
字号:
else osip_transaction_execute (transaction, se); } while (more_event == 1); } osip_free (array); return 0;}intosip_nist_execute (osip_t * osip){ osip_transaction_t *transaction; osip_event_t *se; int more_event; osip_list_iterator_t iterator; void **array; int len; int index = 0; /* list must be copied because osip_transaction_execute() may change it */#ifdef OSIP_MT osip_mutex_lock (nist_fastmutex);#endif len = osip_list_size (&osip->osip_nist_transactions); if (0 >= len) {#ifdef OSIP_MT osip_mutex_unlock (nist_fastmutex);#endif return 0; } array = osip_malloc (sizeof (void *) * len); if (array==NULL) {#ifdef OSIP_MT osip_mutex_unlock (nist_fastmutex);#endif return 0; } transaction = (osip_transaction_t *) osip_list_get_first (&osip->osip_nist_transactions, &iterator); while (osip_list_iterator_has_elem (iterator)) { array[index++] = transaction; transaction = (osip_transaction_t *) osip_list_get_next (&iterator); }#ifdef OSIP_MT osip_mutex_unlock (nist_fastmutex);#endif for (index = 0; index < len; ++index) { transaction = (osip_transaction_t *) array[index]; more_event = 1; do { se = (osip_event_t *) osip_fifo_tryget (transaction->transactionff); if (se == NULL) /* no more event for this transaction */ more_event = 0; else osip_transaction_execute (transaction, se); } while (more_event == 1); } osip_free (array); return 0;}voidosip_timers_gettimeout (osip_t * osip, struct timeval *lower_tv){ struct timeval now; osip_transaction_t *tr; osip_list_iterator_t iterator; osip_gettimeofday (&now, NULL); lower_tv->tv_sec = now.tv_sec + 3600 * 24 * 365; /* wake up evry year :-) */ lower_tv->tv_usec = now.tv_usec;#ifdef OSIP_MT osip_mutex_lock (ict_fastmutex);#endif /* handle ict timers */ tr = (osip_transaction_t *) osip_list_get_first (&osip->osip_ict_transactions, &iterator); while (osip_list_iterator_has_elem (iterator)) { if (1 <= osip_fifo_size (tr->transactionff)) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO4, NULL, "1 Pending event already in transaction !\n")); lower_tv->tv_sec = 0; lower_tv->tv_usec = 0;#ifdef OSIP_MT osip_mutex_unlock (ict_fastmutex);#endif return; } else { if (tr->state == ICT_CALLING) min_timercmp (lower_tv, &tr->ict_context->timer_b_start); if (tr->state == ICT_CALLING) min_timercmp (lower_tv, &tr->ict_context->timer_a_start); if (tr->state == ICT_COMPLETED) min_timercmp (lower_tv, &tr->ict_context->timer_d_start); if (osip_timercmp (&now, lower_tv, >)) { lower_tv->tv_sec = 0; lower_tv->tv_usec = 0;#ifdef OSIP_MT osip_mutex_unlock (ict_fastmutex);#endif return; } } tr = (osip_transaction_t *) osip_list_get_next (&iterator); }#ifdef OSIP_MT osip_mutex_unlock (ict_fastmutex);#endif#ifdef OSIP_MT osip_mutex_lock (ist_fastmutex);#endif /* handle ist timers */ tr = (osip_transaction_t *) osip_list_get_first (&osip->osip_ist_transactions, &iterator); while (osip_list_iterator_has_elem (iterator)) { if (tr->state == IST_CONFIRMED) min_timercmp (lower_tv, &tr->ist_context->timer_i_start); if (tr->state == IST_COMPLETED) min_timercmp (lower_tv, &tr->ist_context->timer_h_start); if (tr->state == IST_COMPLETED) min_timercmp (lower_tv, &tr->ist_context->timer_g_start); if (osip_timercmp (&now, lower_tv, >)) { lower_tv->tv_sec = 0; lower_tv->tv_usec = 0;#ifdef OSIP_MT osip_mutex_unlock (ist_fastmutex);#endif return; } tr = (osip_transaction_t *) osip_list_get_next (&iterator); }#ifdef OSIP_MT osip_mutex_unlock (ist_fastmutex);#endif#ifdef OSIP_MT osip_mutex_lock (nict_fastmutex);#endif /* handle nict timers */ tr = (osip_transaction_t *) osip_list_get_first (&osip->osip_nict_transactions, &iterator); while (osip_list_iterator_has_elem (iterator)) { if (tr->state == NICT_COMPLETED) min_timercmp (lower_tv, &tr->nict_context->timer_k_start); if (tr->state == NICT_PROCEEDING || tr->state == NICT_TRYING) min_timercmp (lower_tv, &tr->nict_context->timer_f_start); if (tr->state == NICT_PROCEEDING || tr->state == NICT_TRYING) min_timercmp (lower_tv, &tr->nict_context->timer_e_start); if (osip_timercmp (&now, lower_tv, >)) { lower_tv->tv_sec = 0; lower_tv->tv_usec = 0;#ifdef OSIP_MT osip_mutex_unlock (nict_fastmutex);#endif return; } tr = (osip_transaction_t *) osip_list_get_next (&iterator); }#ifdef OSIP_MT osip_mutex_unlock (nict_fastmutex);#endif#ifdef OSIP_MT osip_mutex_lock (nist_fastmutex);#endif /* handle nist timers */ tr = (osip_transaction_t *) osip_list_get_first (&osip->osip_nist_transactions, &iterator); while (osip_list_iterator_has_elem (iterator)) { if (tr->state == NIST_COMPLETED) min_timercmp (lower_tv, &tr->nist_context->timer_j_start); if (osip_timercmp (&now, lower_tv, >)) { lower_tv->tv_sec = 0; lower_tv->tv_usec = 0;#ifdef OSIP_MT osip_mutex_unlock (nist_fastmutex);#endif return; } tr = (osip_transaction_t *) osip_list_get_next (&iterator); }#ifdef OSIP_MT osip_mutex_unlock (nist_fastmutex);#endif#ifdef OSIP_MT osip_mutex_lock (ixt_fastmutex);#endif { ixt_t *ixt; ixt = (ixt_t *) osip_list_get_first (&osip->ixt_retransmissions, &iterator); while (osip_list_iterator_has_elem (iterator)) { min_timercmp (lower_tv, &ixt->start); if (osip_timercmp (&now, lower_tv, >)) { lower_tv->tv_sec = 0; lower_tv->tv_usec = 0;#ifdef OSIP_MT osip_mutex_unlock (ixt_fastmutex);#endif return; } ixt = (ixt_t *) osip_list_get_next (&iterator); } }#ifdef OSIP_MT osip_mutex_unlock (ixt_fastmutex);#endif lower_tv->tv_sec = lower_tv->tv_sec - now.tv_sec; lower_tv->tv_usec = lower_tv->tv_usec - now.tv_usec; /* just make sure the value is correct! */ if (lower_tv->tv_usec < 0) { lower_tv->tv_usec = lower_tv->tv_usec + 1000000; lower_tv->tv_sec--; } if (lower_tv->tv_sec < 0) { lower_tv->tv_sec = 0; lower_tv->tv_usec = 0; } if (lower_tv->tv_usec > 1000000) { lower_tv->tv_usec = lower_tv->tv_usec - 1000000; lower_tv->tv_sec++; } return;}voidosip_timers_ict_execute (osip_t * osip){ osip_transaction_t *tr; osip_list_iterator_t iterator;#ifdef OSIP_MT osip_mutex_lock (ict_fastmutex);#endif /* handle ict timers */ tr = (osip_transaction_t *) osip_list_get_first (&osip->osip_ict_transactions, &iterator); while (osip_list_iterator_has_elem (iterator)) { osip_event_t *evt; if (1 <= osip_fifo_size (tr->transactionff)) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO4, NULL, "1 Pending event already in transaction !\n")); } else { evt = __osip_ict_need_timer_b_event (tr->ict_context, tr->state, tr->transactionid); if (evt != NULL) osip_fifo_add (tr->transactionff, evt); else { evt = __osip_ict_need_timer_a_event (tr->ict_context, tr->state, tr->transactionid); if (evt != NULL) osip_fifo_add (tr->transactionff, evt); else { evt = __osip_ict_need_timer_d_event (tr->ict_context, tr->state, tr->transactionid); if (evt != NULL) osip_fifo_add (tr->transactionff, evt); } } } tr = (osip_transaction_t *) osip_list_get_next (&iterator); }#ifdef OSIP_MT osip_mutex_unlock (ict_fastmutex);#endif}voidosip_timers_ist_execute (osip_t * osip){ osip_transaction_t *tr; osip_list_iterator_t iterator;#ifdef OSIP_MT osip_mutex_lock (ist_fastmutex);#endif /* handle ist timers */ tr = (osip_transaction_t *) osip_list_get_first (&osip->osip_ist_transactions, &iterator); while (osip_list_iterator_has_elem (iterator)) { osip_event_t *evt; evt = __osip_ist_need_timer_i_event (tr->ist_context, tr->state, tr->transactionid); if (evt != NULL) osip_fifo_add (tr->transactionff, evt); else { evt = __osip_ist_need_timer_h_event (tr->ist_context, tr->state, tr->transactionid); if (evt != NULL) osip_fifo_add (tr->transactionff, evt); else { evt = __osip_ist_need_timer_g_event (tr->ist_context, tr->state, tr->transactionid); if (evt != NULL) osip_fifo_add (tr->transactionff, evt); } } tr = (osip_transaction_t *) osip_list_get_next (&iterator); }#ifdef OSIP_MT osip_mutex_unlock (ist_fastmutex);#endif}voidosip_timers_nict_execute (osip_t * osip){ osip_transaction_t *tr; osip_list_iterator_t iterator;#ifdef OSIP_MT osip_mutex_lock (nict_fastmutex);#endif /* handle nict timers */ tr = (osip_transaction_t *) osip_list_get_first (&osip->osip_nict_transactions, &iterator); while (osip_list_iterator_has_elem (iterator)) { osip_event_t *evt; evt = __osip_nict_need_timer_k_event (tr->nict_context, tr->state, tr->transactionid); if (evt != NULL) osip_fifo_add (tr->transactionff, evt); else { evt = __osip_nict_need_timer_f_event (tr->nict_context, tr->state, tr->transactionid); if (evt != NULL) osip_fifo_add (tr->transactionff, evt); else { evt = __osip_nict_need_timer_e_event (tr->nict_context, tr->state, tr->transactionid); if (evt != NULL) osip_fifo_add (tr->transactionff, evt); } } tr = (osip_transaction_t *) osip_list_get_next (&iterator); }#ifdef OSIP_MT osip_mutex_unlock (nict_fastmutex);#endif}voidosip_timers_nist_execute (osip_t * osip){ osip_transaction_t *tr; osip_list_iterator_t iterator;#ifdef OSIP_MT osip_mutex_lock (nist_fastmutex);#endif /* handle nist timers */ tr = (osip_transaction_t *) osip_list_get_first (&osip->osip_nist_transactions, &iterator); while (osip_list_iterator_has_elem (iterator)) { osip_event_t *evt; evt = __osip_nist_need_timer_j_event (tr->nist_context, tr->state, tr->transactionid); if (evt != NULL) osip_fifo_add (tr->transactionff, evt); tr = (osip_transaction_t *) osip_list_get_next (&iterator); }#ifdef OSIP_MT osip_mutex_unlock (nist_fastmutex);#endif}voidosip_set_cb_send_message (osip_t * cf, int (*cb) (osip_transaction_t *, osip_message_t *, char *, int, int)){ cf->cb_send_message = cb;}void__osip_message_callback (int type, osip_transaction_t * tr, osip_message_t * msg){ osip_t *config = tr->config; if (type >= OSIP_MESSAGE_CALLBACK_COUNT) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_BUG, NULL, "invalid callback type %d\n", type)); return; } if (config->msg_callbacks[type] == NULL) return; config->msg_callbacks[type] (type, tr, msg);}void__osip_kill_transaction_callback (int type, osip_transaction_t * tr){ osip_t *config = tr->config; if (type >= OSIP_KILL_CALLBACK_COUNT) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_BUG, NULL, "invalid callback type %d\n", type)); return; } tr->completed_time = time (NULL); if (config->kill_callbacks[type] == NULL) return; config->kill_callbacks[type] (type, tr);}void__osip_transport_error_callback (int type, osip_transaction_t * tr, int error){ osip_t *config = tr->config; if (type >= OSIP_TRANSPORT_ERROR_CALLBACK_COUNT) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_BUG, NULL, "invalid callback type %d\n", type)); return; } if (config->tp_error_callbacks[type] == NULL) return; config->tp_error_callbacks[type] (type, tr, error);}intosip_set_message_callback (osip_t * config, int type, osip_message_cb_t cb){ if (type >= OSIP_MESSAGE_CALLBACK_COUNT) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "invalid callback type %d\n", type)); return -1; } config->msg_callbacks[type] = cb; return 0;}intosip_set_kill_transaction_callback (osip_t * config, int type, osip_kill_transaction_cb_t cb){ if (type >= OSIP_KILL_CALLBACK_COUNT) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "invalid callback type %d\n", type)); return -1; } config->kill_callbacks[type] = cb; return 0;}intosip_set_transport_error_callback (osip_t * config, int type, osip_transport_error_cb_t cb){ if (type >= OSIP_TRANSPORT_ERROR_CALLBACK_COUNT) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "invalid callback type %d\n", type)); return -1; } config->tp_error_callbacks[type] = cb; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -