📄 osip.c
字号:
}#ifdef OSIP_MT osip_mutex_unlock (ict_fastmutex);#endif return -1;}int__osip_remove_ist_transaction (osip_t * osip, osip_transaction_t * ist){ int pos = 0; osip_transaction_t *tmp;#ifdef OSIP_MT osip_mutex_lock (ist_fastmutex);#endif while (!osip_list_eol (osip->osip_ist_transactions, pos)) { tmp = osip_list_get (osip->osip_ist_transactions, pos); if (tmp->transactionid == ist->transactionid) { osip_list_remove (osip->osip_ist_transactions, pos);#ifdef OSIP_MT osip_mutex_unlock (ist_fastmutex);#endif return 0; } pos++; }#ifdef OSIP_MT osip_mutex_unlock (ist_fastmutex);#endif return -1;}int__osip_remove_nict_transaction (osip_t * osip, osip_transaction_t * nict){ int pos = 0; osip_transaction_t *tmp;#ifdef OSIP_MT osip_mutex_lock (nict_fastmutex);#endif while (!osip_list_eol (osip->osip_nict_transactions, pos)) { tmp = osip_list_get (osip->osip_nict_transactions, pos); if (tmp->transactionid == nict->transactionid) { osip_list_remove (osip->osip_nict_transactions, pos);#ifdef OSIP_MT osip_mutex_unlock (nict_fastmutex);#endif return 0; } pos++; }#ifdef OSIP_MT osip_mutex_unlock (nict_fastmutex);#endif return -1;}int__osip_remove_nist_transaction (osip_t * osip, osip_transaction_t * nist){ int pos = 0; osip_transaction_t *tmp;#ifdef OSIP_MT osip_mutex_lock (nist_fastmutex);#endif while (!osip_list_eol (osip->osip_nist_transactions, pos)) { tmp = osip_list_get (osip->osip_nist_transactions, pos); if (tmp->transactionid == nist->transactionid) { osip_list_remove (osip->osip_nist_transactions, pos);#ifdef OSIP_MT osip_mutex_unlock (nist_fastmutex);#endif return 0; } pos++; }#ifdef OSIP_MT osip_mutex_unlock (nist_fastmutex);#endif return -1;}#if 0/* this method is made obsolete because it contains bugs and is also too much limited. any call to this method should be replace this way: //osip_distribute(osip, evt); osip_transaction_t *transaction = osip_find_transaction_and_add_event(osip, evt); if (i!=0) // in case it's a new request { if (evt is an ACK) evt could be an ACK for INVITE (not handled by oSIP) else if ( evt is a 200 for INVITE) evt could be a retransmission of a 200 for INVITE (not handled by oSIP) else if (evt is a new request) == not a ACK and not a response { transaction = osip_create_transaction(osip, evt); if (transaction==NULL) printf("failed to create a transaction\"); } } else { // here, the message as been taken by the stack. }*//* finds the transaction context and add the sipevent in its fifo. *//* USED ONLY BY THE TRANSPORT LAYER. *//* INPUT : osip_t *osip | osip. contains the list of tr. context*//* INPUT : osip_event_t* sipevent | event to dispatch. */osip_transaction_t *osip_distribute_event (osip_t * osip, osip_event_t * evt){ osip_transaction_t *transaction = NULL; int i; osip_fsm_type_t ctx_type; if (EVT_IS_INCOMINGMSG (evt)) { /* event is for ict */ if (MSG_IS_REQUEST (evt->sip)) { if (0 == strcmp (evt->sip->cseq->method, "INVITE") || 0 == strcmp (evt->sip->cseq->method, "ACK")) {#ifdef OSIP_MT osip_mutex_lock (ist_fastmutex);#endif transaction = osip_transaction_find (osip->osip_ist_transactions, evt);#ifdef OSIP_MT osip_mutex_unlock (ist_fastmutex);#endif } else {#ifdef OSIP_MT osip_mutex_lock (nist_fastmutex);#endif transaction = osip_transaction_find (osip->osip_nist_transactions, evt);#ifdef OSIP_MT osip_mutex_unlock (nist_fastmutex);#endif } } else { if (0 == strcmp (evt->sip->cseq->method, "INVITE") || 0 == strcmp (evt->sip->cseq->method, "ACK")) {#ifdef OSIP_MT osip_mutex_lock (ict_fastmutex);#endif transaction = osip_transaction_find (osip->osip_ict_transactions, evt);#ifdef OSIP_MT osip_mutex_unlock (ict_fastmutex);#endif } else {#ifdef OSIP_MT osip_mutex_lock (nict_fastmutex);#endif transaction = osip_transaction_find (osip->osip_nict_transactions, evt);#ifdef OSIP_MT osip_mutex_unlock (nict_fastmutex);#endif } } if (transaction == NULL) { if (EVT_IS_RCV_STATUS_1XX (evt) || EVT_IS_RCV_STATUS_2XX (evt) || EVT_IS_RCV_STATUS_3456XX (evt) || EVT_IS_RCV_ACK (evt)) { /* event MUST be ignored! */ /* EXCEPT FOR 2XX THAT MUST BE GIVEN TO THE CORE LAYER!!! */ /* TODO */ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_WARNING, NULL, "transaction does not yet exist... %x callid:%s\n", evt, evt->sip->call_id->number)); osip_message_free (evt->sip); osip_free (evt); /* transaction thread will not delete it */ return NULL; } /* we create a new context for this incoming request */ if (0 == strcmp (evt->sip->cseq->method, "INVITE")) ctx_type = IST; else ctx_type = NIST; i = osip_transaction_init (&transaction, ctx_type, osip, evt->sip); if (i == -1) { osip_message_free (evt->sip); osip_free (evt); /* transaction thread will not delete it */ return NULL; } } evt->transactionid = transaction->transactionid; evt->transactionid = transaction->transactionid; osip_fifo_add (transaction->transactionff, evt); return transaction; } else { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_BUG, NULL, "wrong event type %x\n", evt)); return NULL; }}#endifintosip_find_transaction_and_add_event (osip_t * osip, osip_event_t * evt){ osip_transaction_t *transaction = __osip_find_transaction (osip, evt, 1); if (transaction == NULL) return -1; return 0;}osip_transaction_t *osip_find_transaction (osip_t * osip, osip_event_t * evt){#ifdef OSIP_MT OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_BUG, NULL, "\n\n\n\nYou are using a multithreaded application, but this method is not allowed! Use osip_find_transaction_add_add_event() instead.\n\n\\n"));#endif return __osip_find_transaction (osip, evt, 0);}osip_transaction_t *__osip_find_transaction (osip_t * osip, osip_event_t * evt, int consume){ osip_transaction_t *transaction = NULL; osip_list_t *transactions = NULL;#ifdef OSIP_MT struct osip_mutex *mut = NULL;#endif if (evt == NULL || evt->sip == NULL || evt->sip->cseq == NULL) return NULL; if (EVT_IS_INCOMINGMSG (evt)) { if (MSG_IS_REQUEST (evt->sip)) { if (0 == strcmp (evt->sip->cseq->method, "INVITE") || 0 == strcmp (evt->sip->cseq->method, "ACK")) { transactions = osip->osip_ist_transactions;#ifdef OSIP_MT mut = ist_fastmutex;#endif } else { transactions = osip->osip_nist_transactions;#ifdef OSIP_MT mut = nist_fastmutex;#endif } } else { if (0 == strcmp (evt->sip->cseq->method, "INVITE") || 0 == strcmp (evt->sip->cseq->method, "ACK")) { transactions = osip->osip_ict_transactions;#ifdef OSIP_MT mut = ict_fastmutex;#endif } else { transactions = osip->osip_nict_transactions;#ifdef OSIP_MT mut = nict_fastmutex;#endif } } } else if (EVT_IS_OUTGOINGMSG (evt)) { if (MSG_IS_RESPONSE (evt->sip)) { if (0 == strcmp (evt->sip->cseq->method, "INVITE") || 0 == strcmp (evt->sip->cseq->method, "ACK")) { transactions = osip->osip_ist_transactions;#ifdef OSIP_MT mut = ist_fastmutex;#endif } else { transactions = osip->osip_nist_transactions;#ifdef OSIP_MT mut = nist_fastmutex;#endif } } else { if (0 == strcmp (evt->sip->cseq->method, "INVITE") || 0 == strcmp (evt->sip->cseq->method, "ACK")) { transactions = osip->osip_ict_transactions;#ifdef OSIP_MT mut = ict_fastmutex;#endif } else { transactions = osip->osip_nict_transactions;#ifdef OSIP_MT mut = nict_fastmutex;#endif } } } if (transactions == NULL) return NULL; /* not a message??? */#ifdef OSIP_MT osip_mutex_lock (mut);#endif transaction = osip_transaction_find (transactions, evt); if (consume == 1) { /* we add the event before releasing the mutex!! */ if (transaction != NULL) { osip_transaction_add_event (transaction, evt);#ifdef OSIP_MT osip_mutex_unlock (mut);#endif return transaction; } }#ifdef OSIP_MT osip_mutex_unlock (mut);#endif return transaction;}osip_transaction_t *osip_create_transaction (osip_t * osip, osip_event_t * evt){ osip_transaction_t *transaction; int i; osip_fsm_type_t ctx_type; if (evt==NULL) return NULL; if (evt->sip==NULL) return NULL; /* make sure the request's method reflect the cseq value. */ if (MSG_IS_REQUEST (evt->sip)) { /* delete request where cseq method does not match the method in request-line */ if (evt->sip->cseq==NULL || evt->sip->cseq->method==NULL || evt->sip->sip_method==NULL) { return NULL; } if (0 != strcmp (evt->sip->cseq->method, evt->sip->sip_method)) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_WARNING, NULL, "core module: Discard invalid message with method!=cseq!\n")); return NULL; } } if (MSG_IS_ACK (evt->sip)) /* ACK never create transactions */ return NULL; if (EVT_IS_INCOMINGREQ (evt)) { /* we create a new context for this incoming request */ if (0 == strcmp (evt->sip->cseq->method, "INVITE")) ctx_type = IST; else ctx_type = NIST; } else if (EVT_IS_OUTGOINGREQ (evt)) { if (0 == strcmp (evt->sip->cseq->method, "INVITE")) ctx_type = ICT; else ctx_type = NICT; } else { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Cannot build a transction for this message!\n")); return NULL; } i = osip_transaction_init (&transaction, ctx_type, osip, evt->sip); if (i == -1) { return NULL; } evt->transactionid = transaction->transactionid; return transaction;}osip_transaction_t *osip_transaction_find (osip_list_t * transactions, osip_event_t * evt){ int pos = 0; osip_transaction_t *transaction; if (EVT_IS_INCOMINGREQ (evt)) { while (!osip_list_eol (transactions, pos)) { transaction = (osip_transaction_t *) osip_list_get (transactions, pos); if (0 == __osip_transaction_matching_request_osip_to_xist_17_2_3 (transaction, evt->sip)) return transaction; pos++; } } else if (EVT_IS_INCOMINGRESP (evt)) { while (!osip_list_eol (transactions, pos)) { transaction = (osip_transaction_t *) osip_list_get (transactions, pos); if (0 == __osip_transaction_matching_response_osip_to_xict_17_1_3 (transaction, evt->sip)) return transaction; pos++; } } else /* handle OUTGOING message */ { /* THE TRANSACTION ID MUST BE SET */ while (!osip_list_eol (transactions, pos)) { transaction = (osip_transaction_t *) osip_list_get (transactions, pos); if (transaction->transactionid == evt->transactionid) return transaction; pos++; } } return NULL;}static int ref_count = 0;#ifdef OSIP_MT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -