📄 osip.c
字号:
static struct osip_mutex * ref_mutex = NULL;#endifintincrease_ref_count (void){#ifdef OSIP_MT if (ref_count == 0) ref_mutex = osip_mutex_init(); /* Here we should assert() that the mutex was really generated. */ osip_mutex_lock (ref_mutex);#endif if (ref_count == 0) __osip_global_init (); ref_count++;#ifdef OSIP_MT osip_mutex_unlock (ref_mutex);#endif return 0;}voiddecrease_ref_count (void){#ifdef OSIP_MT osip_mutex_lock (ref_mutex);#endif /* assert (ref_count > 0); */ ref_count--; if (ref_count == 0) {#ifdef OSIP_MT osip_mutex_unlock (ref_mutex); osip_mutex_destroy (ref_mutex);#endif __osip_global_free (); return; }#ifdef OSIP_MT osip_mutex_unlock (ref_mutex);#endif}intosip_init (osip_t ** osip){ if (increase_ref_count () != 0) return -1; *osip = (osip_t *) osip_malloc (sizeof (osip_t)); if (*osip == NULL) return -1; /* allocation failed */ memset (*osip, 0, sizeof (osip_t)); (*osip)->osip_ict_transactions = (osip_list_t *) osip_malloc (sizeof (osip_list_t)); osip_list_init ((*osip)->osip_ict_transactions); (*osip)->osip_ist_transactions = (osip_list_t *) osip_malloc (sizeof (osip_list_t)); osip_list_init ((*osip)->osip_ist_transactions); (*osip)->osip_nict_transactions = (osip_list_t *) osip_malloc (sizeof (osip_list_t)); osip_list_init ((*osip)->osip_nict_transactions); (*osip)->osip_nist_transactions = (osip_list_t *) osip_malloc (sizeof (osip_list_t)); osip_list_init ((*osip)->osip_nist_transactions);#ifdef OSIP_RETRANSMIT_2XX (*osip)->ixt_retransmissions = (osip_list_t *) osip_malloc(sizeof (osip_list_t)); osip_list_init ((*osip)->ixt_retransmissions);#else (*osip)->ixt_retransmissions = NULL;#endif return 0;}voidosip_release (osip_t * osip){ osip_free (osip->osip_ict_transactions); osip_free (osip->osip_ist_transactions); osip_free (osip->osip_nict_transactions); osip_free (osip->osip_nist_transactions);#ifdef OSIP_RETRANSMIT_2XX osip_free (osip->ixt_retransmissions);#endif osip_free (osip); decrease_ref_count ();}voidosip_set_application_context (osip_t * osip, void *pointer){ osip->application_context = pointer;}void *osip_get_application_context (osip_t * osip){ if (osip == NULL) return NULL; return osip->application_context;}intosip_ict_execute (osip_t * osip){ osip_transaction_t *transaction; osip_event_t *se; int more_event; int tr; tr = 0; while (!osip_list_eol (osip->osip_ict_transactions, tr)) { transaction = osip_list_get (osip->osip_ict_transactions, tr); tr++; 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); } return 0;}intosip_ist_execute (osip_t * osip){ osip_transaction_t *transaction; osip_event_t *se; int more_event; int tr; tr = 0; while (!osip_list_eol (osip->osip_ist_transactions, tr)) { transaction = osip_list_get (osip->osip_ist_transactions, tr); tr++; 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); } return 0;}intosip_nict_execute (osip_t * osip){ osip_transaction_t *transaction; osip_event_t *se; int more_event; int tr; tr = 0; while (!osip_list_eol (osip->osip_nict_transactions, tr)) { transaction = osip_list_get (osip->osip_nict_transactions, tr); tr++; 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); } return 0;}intosip_nist_execute (osip_t * osip){ osip_transaction_t *transaction; osip_event_t *se; int more_event; int tr; tr = 0; while (!osip_list_eol (osip->osip_nist_transactions, tr)) { transaction = osip_list_get (osip->osip_nist_transactions, tr); tr++; 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); } return 0;}voidosip_timers_ict_execute (osip_t * osip){ osip_transaction_t *tr; int pos = 0;#ifdef OSIP_MT osip_mutex_lock (ict_fastmutex);#endif /* handle ict timers */ while (!osip_list_eol (osip->osip_ict_transactions, pos)) { osip_event_t *evt; tr = (osip_transaction_t *) osip_list_get (osip->osip_ict_transactions, pos); 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); } } } pos++; }#ifdef OSIP_MT osip_mutex_unlock (ict_fastmutex);#endif}voidosip_timers_ist_execute (osip_t * osip){ osip_transaction_t *tr; int pos = 0;#ifdef OSIP_MT osip_mutex_lock (ist_fastmutex);#endif /* handle ist timers */ while (!osip_list_eol (osip->osip_ist_transactions, pos)) { osip_event_t *evt; tr = (osip_transaction_t *) osip_list_get (osip->osip_ist_transactions, pos); 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); } } pos++; }#ifdef OSIP_MT osip_mutex_unlock (ist_fastmutex);#endif}voidosip_timers_nict_execute (osip_t * osip){ osip_transaction_t *tr; int pos = 0;#ifdef OSIP_MT osip_mutex_lock (nict_fastmutex);#endif /* handle nict timers */ while (!osip_list_eol (osip->osip_nict_transactions, pos)) { osip_event_t *evt; tr = (osip_transaction_t *) osip_list_get (osip->osip_nict_transactions, pos); 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); } } pos++; }#ifdef OSIP_MT osip_mutex_unlock (nict_fastmutex);#endif}voidosip_timers_nist_execute (osip_t * osip){ osip_transaction_t *tr; int pos = 0;#ifdef OSIP_MT osip_mutex_lock (nist_fastmutex);#endif /* handle nist timers */ while (!osip_list_eol (osip->osip_nist_transactions, pos)) { osip_event_t *evt; tr = (osip_transaction_t *) osip_list_get (osip->osip_nist_transactions, pos); evt = __osip_nist_need_timer_j_event (tr->nist_context, tr->state, tr->transactionid); if (evt != NULL) osip_fifo_add (tr->transactionff, evt); pos++; }#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; } 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 + -