📄 udp.c
字号:
/* we don't match any existing dialog: send a ACK & send a BYE */ osip_event_free (evt);}int_eXosip_handle_incoming_message (char *buf, size_t length, int socket, char *host, int port){ int i; osip_event_t *se; se = (osip_event_t *) osip_malloc (sizeof (osip_event_t)); if (se == NULL) return OSIP_NOMEM; se->type = UNKNOWN_EVT; se->sip = NULL; se->transactionid = 0; /* parse message and set up an event */ i = osip_message_init (&(se->sip)); if (i != 0) { osip_free (se); return i; } i = osip_message_parse (se->sip, buf, length); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "could not parse message\n")); osip_message_free (se->sip); osip_free (se); return i; } if (se->sip->call_id != NULL && se->sip->call_id->number != NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "MESSAGE REC. CALLID:%s\n", se->sip->call_id->number)); } if (eXosip.cbsipCallback != NULL) { eXosip.cbsipCallback (se->sip, 1); } if (MSG_IS_REQUEST (se->sip)) { if (se->sip->sip_method == NULL || se->sip->req_uri == NULL) { osip_message_free (se->sip); osip_free (se); return OSIP_SYNTAXERROR; } } if (MSG_IS_REQUEST (se->sip)) { if (MSG_IS_INVITE (se->sip)) se->type = RCV_REQINVITE; else if (MSG_IS_ACK (se->sip)) se->type = RCV_REQACK; else se->type = RCV_REQUEST; } else { if (MSG_IS_STATUS_1XX (se->sip)) se->type = RCV_STATUS_1XX; else if (MSG_IS_STATUS_2XX (se->sip)) se->type = RCV_STATUS_2XX; else se->type = RCV_STATUS_3456XX; } OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL, "Message received from: %s:%i\n", host, port)); osip_message_fix_last_via_header (se->sip, host, port); i = osip_find_transaction_and_add_event (eXosip.j_osip, se); if (i != 0) { /* this event has no transaction, */ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL, "This is a request\n", buf)); eXosip_lock (); if (MSG_IS_REQUEST (se->sip)) eXosip_process_newrequest (se, socket); else if (MSG_IS_RESPONSE (se->sip)) eXosip_process_response_out_of_transaction (se); eXosip_unlock (); } else { /* handled by oSIP ! */ return OSIP_SUCCESS; } return OSIP_SUCCESS;}#if defined (WIN32) || defined (_WIN32_WCE)#define eXFD_SET(A, B) FD_SET((unsigned int) A, B)#else#define eXFD_SET(A, B) FD_SET(A, B)#endif/* if second==-1 && useconds==-1 -> wait for ever if max_message_nb<=0 -> infinite loop.... */inteXosip_read_message (int max_message_nb, int sec_max, int usec_max){ fd_set osip_fdset; struct timeval tv; tv.tv_sec = sec_max; tv.tv_usec = usec_max; while (max_message_nb != 0 && eXosip.j_stop_ua == 0) { int i; int max = 0;#ifdef OSIP_MT int wakeup_socket = jpipe_get_read_descr (eXosip.j_socketctl);#endif FD_ZERO (&osip_fdset); eXtl_udp.tl_set_fdset (&osip_fdset, &max); eXtl_tcp.tl_set_fdset (&osip_fdset, &max);#ifdef HAVE_OPENSSL_SSL_H#if !(OPENSSL_VERSION_NUMBER < 0x00908000L) eXtl_dtls.tl_set_fdset (&osip_fdset, &max);#endif eXtl_tls.tl_set_fdset (&osip_fdset, &max);#endif#ifdef OSIP_MT eXFD_SET (wakeup_socket, &osip_fdset); if (wakeup_socket > max) max = wakeup_socket;#endif if ((sec_max == -1) || (usec_max == -1)) i = select (max + 1, &osip_fdset, NULL, NULL, NULL); else i = select (max + 1, &osip_fdset, NULL, NULL, &tv);#if defined (_WIN32_WCE) /* TODO: fix me for wince */ /* if (i == -1) continue; */#else if ((i == -1) && (errno == EINTR || errno == EAGAIN)) continue;#endif#ifdef OSIP_MT if ((i > 0) && FD_ISSET (wakeup_socket, &osip_fdset)) { char buf2[500]; jpipe_read (eXosip.j_socketctl, buf2, 499); }#endif if (0 == i || eXosip.j_stop_ua != 0) { } else if (-1 == i) {#if !defined (_WIN32_WCE) /* TODO: fix me for wince */ return -2000; /* error */#endif } else { eXtl_udp.tl_read_message (&osip_fdset); eXtl_tcp.tl_read_message (&osip_fdset);#ifdef HAVE_OPENSSL_SSL_H#if !(OPENSSL_VERSION_NUMBER < 0x00908000L) eXtl_dtls.tl_read_message (&osip_fdset);#endif eXtl_tls.tl_read_message (&osip_fdset);#endif } max_message_nb--; } return OSIP_SUCCESS;}static inteXosip_pendingosip_transaction_exist (eXosip_call_t * jc, eXosip_dialog_t * jd){ osip_transaction_t *tr; time_t now = time (NULL); tr = eXosip_find_last_inc_transaction (jc, jd, "BYE"); if (tr != NULL && tr->state != NIST_TERMINATED) { /* Don't want to wait forever on broken transaction!! */ if (tr->birth_time + 180 < now) /* Wait a max of 2 minutes */ { /* remove the transaction from oSIP: */ osip_remove_transaction (eXosip.j_osip, tr); eXosip_remove_transaction_from_call (tr, jc); osip_list_add (&eXosip.j_transactions, tr, 0); } else return OSIP_SUCCESS; } tr = eXosip_find_last_out_transaction (jc, jd, "BYE"); if (tr != NULL && tr->state != NICT_TERMINATED) { /* Don't want to wait forever on broken transaction!! */ if (tr->birth_time + 180 < now) /* Wait a max of 2 minutes */ { /* remove the transaction from oSIP: */ osip_remove_transaction (eXosip.j_osip, tr); eXosip_remove_transaction_from_call (tr, jc); osip_list_add (&eXosip.j_transactions, tr, 0); } else return OSIP_SUCCESS; } tr = eXosip_find_last_inc_invite (jc, jd); if (tr != NULL && tr->state != IST_TERMINATED) { /* Don't want to wait forever on broken transaction!! */ if (tr->birth_time + 180 < now) /* Wait a max of 2 minutes */ { /* remove the transaction from oSIP: */ /* osip_remove_transaction(eXosip.j_osip, tr); eXosip_remove_transaction_from_call(tr, jc); osip_transaction_free(tr); */ } else return OSIP_SUCCESS; } tr = eXosip_find_last_out_invite (jc, jd); if (tr != NULL && tr->state != ICT_TERMINATED) { /* Don't want to wait forever on broken transaction!! */ if (tr->birth_time + 180 < now) /* Wait a max of 2 minutes */ { /* remove the transaction from oSIP: */ /* osip_remove_transaction(eXosip.j_osip, tr); eXosip_remove_transaction_from_call(tr, jc); osip_transaction_free(tr); */ } else return OSIP_SUCCESS; } tr = eXosip_find_last_inc_transaction (jc, jd, "REFER"); if (tr != NULL && tr->state != NIST_TERMINATED) { /* Don't want to wait forever on broken transaction!! */ if (tr->birth_time + 180 < now) /* Wait a max of 2 minutes */ { /* remove the transaction from oSIP: */ osip_remove_transaction (eXosip.j_osip, tr); eXosip_remove_transaction_from_call (tr, jc); osip_list_add (&eXosip.j_transactions, tr, 0); } else return OSIP_SUCCESS; } tr = eXosip_find_last_out_transaction (jc, jd, "REFER"); if (tr != NULL && tr->state != NICT_TERMINATED) { /* Don't want to wait forever on broken transaction!! */ if (tr->birth_time + 180 < now) /* Wait a max of 2 minutes */ { /* remove the transaction from oSIP: */ osip_remove_transaction (eXosip.j_osip, tr); eXosip_remove_transaction_from_call (tr, jc); osip_list_add (&eXosip.j_transactions, tr, 0); } else return OSIP_SUCCESS; } return OSIP_UNDEFINED_ERROR;}static inteXosip_release_finished_transactions (eXosip_call_t * jc, eXosip_dialog_t * jd){ time_t now = time (NULL); osip_transaction_t *inc_tr; osip_transaction_t *out_tr; osip_transaction_t *last_invite; int pos; int ret; ret = -1; last_invite = eXosip_find_last_inc_invite (jc, jd); if (jd != NULL) { /* go through all incoming transactions of this dialog */ pos = 1; while (!osip_list_eol (jd->d_inc_trs, pos)) { inc_tr = osip_list_get (jd->d_inc_trs, pos); if (0 != osip_strcasecmp (inc_tr->cseq->method, "INVITE")) { /* remove, if transaction too old, independent of the state */ if ((inc_tr->state == NIST_TERMINATED) && (inc_tr->birth_time + 30 < now)) /* Wait a max of 30 seconds */ { /* remove the transaction from oSIP */ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO2, NULL, "eXosip: release non-INVITE server transaction (did=%i)\n", jd->d_id)); osip_remove_transaction (eXosip.j_osip, inc_tr); osip_list_remove (jd->d_inc_trs, pos); osip_list_add (&eXosip.j_transactions, inc_tr, 0); ret = 0; break; } } else { /* remove, if transaction too old, independent of the state */ if (last_invite != inc_tr && (inc_tr->state == IST_TERMINATED) && (inc_tr->birth_time + 30 < now)) /* Wait a max of 30 seconds */ { /* remove the transaction from oSIP */ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO2, NULL, "eXosip: release INVITE server transaction (did=%i)\n", jd->d_id)); osip_remove_transaction (eXosip.j_osip, inc_tr); osip_list_remove (jd->d_inc_trs, pos); osip_list_add (&eXosip.j_transactions, inc_tr, 0); ret = 0; break; } } pos++; } last_invite = eXosip_find_last_out_invite (jc, jd); /* go through all outgoing transactions of this dialog */ pos = 1; while (!osip_list_eol (jd->d_out_trs, pos)) { out_tr = osip_list_get (jd->d_out_trs, pos); if (0 != osip_strcasecmp (out_tr->cseq->method, "INVITE")) { /* remove, if transaction too old, independent of the state */ if ((out_tr->state == NICT_TERMINATED) && (out_tr->birth_time + 30 < now)) /* Wait a max of 30 seconds */ { /* remove the transaction from oSIP */ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO2, NULL, "eXosip: release non INVITE client transaction (did=%i)\n", jd->d_id)); osip_remove_transaction (eXosip.j_osip, out_tr); osip_list_remove (jd->d_out_trs, pos); osip_list_add (&eXosip.j_transactions, out_tr, 0); ret = 0; break; } } else { /* remove, if transaction too old, independent of the state */ if (last_invite != out_tr && (out_tr->state == ICT_TERMINATED) && (out_tr->birth_time + 30 < now)) /* Wait a max of 30 seconds */ { /* remove the transaction from oSIP */ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO2, NULL, "eXosip: release INVITE client transaction (did=%i)\n", jd->d_id)); osip_remove_transaction (eXosip.j_osip, out_tr); osip_list_remove (jd->d_out_trs, pos); osip_list_add (&eXosip.j_transactions, out_tr, 0); ret = 0; break; } } pos++; } } return ret;}static inteXosip_release_finished_calls (eXosip_call_t * jc, eXosip_dialog_t * jd){ osip_transaction_t *tr; tr = eXosip_find_last_inc_transaction (jc, jd, "BYE"); if (tr == NULL) tr = eXosip_find_last_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -