jcallback.c
来自「libosip2-3版本的osip源代码」· C语言 代码 · 共 2,180 行 · 第 1/5 页
C
2,180 行
} net = &eXosip.net_interfaces[1]; i = osip_message_to_str (sip, &message, &length); if (i != 0 || length <= 0) { return -1; } /* Step 1: find existing socket to send message */ if (out_socket <= 0) { out_socket = _eXosip_tcp_find_socket (host, port); /* Step 2: create new socket with host:port */ if (out_socket <= 0) { out_socket = _eXosip_tcp_connect_socket (host, port); } OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL, "Message sent: \n%s (to dest=%s:%i)\n", message, host, port)); } else { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL, "Message sent: \n%s (reusing REQUEST connection)\n", message, host, port)); } if (out_socket <= 0) { return -1; } if (0 > send (out_socket, (const void *) message, length, 0)) {#ifdef WIN32 if (WSAECONNREFUSED == WSAGetLastError ())#else if (ECONNREFUSED == errno)#endif { /* This can be considered as an error, but for the moment, I prefer that the application continue to try sending message again and again... so we are not in a error case. Nevertheless, this error should be announced! ALSO, UAS may not have any other options than retry always on the same port. */ osip_free (message); return 1; } else { /* SIP_NETWORK_ERROR; */#if !defined(_WIN32_WCE)
OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "TCP error: \n%s\n", strerror (errno)));#endif
osip_free (message); return -1; } } osip_free (message); return 0;}static voidcb_ict_kill_transaction (int type, osip_transaction_t * tr){ int i; OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL, "cb_ict_kill_transaction (id=%i)\r\n", tr->transactionid)); i = osip_remove_transaction (eXosip.j_osip, tr); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_BUG, NULL, "cb_ict_kill_transaction Error: Could not remove transaction from the oSIP stack? (id=%i)\r\n", tr->transactionid)); }}static voidcb_ist_kill_transaction (int type, osip_transaction_t * tr){ int i; OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL, "cb_ist_kill_transaction (id=%i)\r\n", tr->transactionid)); i = osip_remove_transaction (eXosip.j_osip, tr); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_BUG, NULL, "cb_ist_kill_transaction Error: Could not remove transaction from the oSIP stack? (id=%i)\r\n", tr->transactionid)); }}static voidcb_nict_kill_transaction (int type, osip_transaction_t * tr){ int i; eXosip_dialog_t *jd; eXosip_call_t *jc; eXosip_subscribe_t *js; eXosip_notify_t *jn; jinfo_t *jinfo = (jinfo_t *) osip_transaction_get_your_instance (tr); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL, "cb_nict_kill_transaction (id=%i)\r\n", tr->transactionid)); i = osip_remove_transaction (eXosip.j_osip, tr); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_BUG, NULL, "cb_nict_kill_transaction Error: Could not remove transaction from the oSIP stack? (id=%i)\r\n", tr->transactionid)); } if (MSG_IS_REGISTER (tr->orig_request) && type == OSIP_NICT_KILL_TRANSACTION && tr->last_response == NULL) { eXosip_event_t *je; eXosip_reg_t *jreg = NULL; /* find matching j_reg */ _eXosip_reg_find (&jreg, tr); if (jreg != NULL) { je = eXosip_event_init_for_reg (EXOSIP_REGISTRATION_FAILURE, jreg, tr); report_event (je, NULL); } return; } if (jinfo == NULL) return; jd = jinfo->jd; jc = jinfo->jc; jn = jinfo->jn; js = jinfo->js; if (jn == NULL && js == NULL) return; /* no answer to a NOTIFY request! */ if (MSG_IS_NOTIFY (tr->orig_request) && type == OSIP_NICT_KILL_TRANSACTION && tr->last_response == NULL) { /* delete the dialog! */ REMOVE_ELEMENT (eXosip.j_notifies, jn); eXosip_notify_free (jn); return; } if (MSG_IS_NOTIFY (tr->orig_request) && type == OSIP_NICT_KILL_TRANSACTION && tr->last_response != NULL && tr->last_response->status_code > 299) { /* delete the dialog! */ if (tr->last_response->status_code != 407 && tr->last_response->status_code != 401) { REMOVE_ELEMENT (eXosip.j_notifies, jn); eXosip_notify_free (jn); return; } } if (MSG_IS_NOTIFY (tr->orig_request) && type == OSIP_NICT_KILL_TRANSACTION && tr->last_response != NULL && tr->last_response->status_code > 199 && tr->last_response->status_code < 300) { if (jn->n_ss_status == EXOSIP_SUBCRSTATE_TERMINATED) { /* delete the dialog! */ REMOVE_ELEMENT (eXosip.j_notifies, jn); eXosip_notify_free (jn); return; } } /* no answer to a SUBSCRIBE request! */ if (MSG_IS_SUBSCRIBE (tr->orig_request) && type == OSIP_NICT_KILL_TRANSACTION && tr->last_response == NULL) { /* delete the dialog! */ REMOVE_ELEMENT (eXosip.j_subscribes, js); eXosip_subscribe_free (js); return; } /* detect SUBSCRIBE request that close the dialogs! */ /* expires=0 with MSN */ if (MSG_IS_SUBSCRIBE (tr->orig_request) && type == OSIP_NICT_KILL_TRANSACTION) { osip_header_t *expires; osip_message_get_expires (tr->orig_request, 0, &expires); if (expires == NULL || expires->hvalue == NULL) { } else if (0 == strcmp (expires->hvalue, "0")) { /* delete the dialog! */ REMOVE_ELEMENT (eXosip.j_subscribes, js); eXosip_subscribe_free (js); return; } }}static voidcb_nist_kill_transaction (int type, osip_transaction_t * tr){ int i; OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL, "cb_nist_kill_transaction (id=%i)\r\n", tr->transactionid)); i = osip_remove_transaction (eXosip.j_osip, tr); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_BUG, NULL, "cb_nist_kill_transaction Error: Could not remove transaction from the oSIP stack? (id=%i)\r\n", tr->transactionid)); }}static voidcb_rcvinvite (int type, osip_transaction_t * tr, osip_message_t * sip){ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "cb_rcvinvite (id=%i)\n", tr->transactionid));}static voidcb_rcvack (int type, osip_transaction_t * tr, osip_message_t * sip){ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "cb_rcvack (id=%i)\n", tr->transactionid));}static voidcb_rcvack2 (int type, osip_transaction_t * tr, osip_message_t * sip){ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "cb_rcvack2 (id=%i)\r\n", tr->transactionid));}static voidcb_rcvregister (int type, osip_transaction_t * tr, osip_message_t * sip){ eXosip_event_t *je; OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "cb_rcvregister (id=%i)\r\n", tr->transactionid)); je = eXosip_event_init_for_message (EXOSIP_MESSAGE_NEW, tr); eXosip_event_add (je); return;}static voidcb_rcvcancel (int type, osip_transaction_t * tr, osip_message_t * sip){ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "cb_rcvcancel (id=%i)\r\n", tr->transactionid));}static voidcb_rcvrequest (int type, osip_transaction_t * tr, osip_message_t * sip){ eXosip_dialog_t *jd; eXosip_call_t *jc; eXosip_notify_t *jn; eXosip_subscribe_t *js; eXosip_event_t *je; jinfo_t *jinfo = (jinfo_t *) osip_transaction_get_your_instance (tr); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "cb_rcvunkrequest (id=%i)\r\n", tr->transactionid)); if (jinfo == NULL) { eXosip_event_t *je; je = eXosip_event_init_for_message (EXOSIP_MESSAGE_NEW, tr); eXosip_event_add (je); return; } jd = jinfo->jd; jc = jinfo->jc; jn = jinfo->jn; js = jinfo->js; if (jc == NULL && jn == NULL && js == NULL) { eXosip_event_t *je; je = eXosip_event_init_for_message (EXOSIP_MESSAGE_NEW, tr); eXosip_event_add (je); return; } else if (jc != NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "cb_rcv? (id=%i)\r\n", tr->transactionid)); if (MSG_IS_BYE(sip)) { /* already sent */ } else report_call_event (EXOSIP_CALL_MESSAGE_NEW, jc, jd, tr); return; } else if (jn != NULL) { if (MSG_IS_SUBSCRIBE (sip)) { je = eXosip_event_init_for_notify (EXOSIP_IN_SUBSCRIPTION_NEW, jn, jd, tr); report_event (je, NULL); return; } return; } else if (js != NULL) { if (MSG_IS_NOTIFY (sip)) { je = eXosip_event_init_for_subscribe (EXOSIP_SUBSCRIPTION_NOTIFY, js, jd, tr); report_event (je, NULL); return; } return; }}static voidcb_sndinvite (int type, osip_transaction_t * tr, osip_message_t * sip){ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "cb_sndinvite (id=%i)\r\n", tr->transactionid));}static voidcb_sndack (int type, osip_transaction_t * tr, osip_message_t * sip){ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "cb_sndack (id=%i)\r\n", tr->transactionid));}static voidcb_sndregister (int type, osip_transaction_t * tr, osip_message_t * sip){ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "cb_sndregister (id=%i)\r\n", tr->transactionid));}static voidcb_sndbye (int type, osip_transaction_t * tr, osip_message_t * sip){ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "cb_sndbye (id=%i)\r\n", tr->transactionid));}static voidcb_sndcancel (int type, osip_transaction_t * tr, osip_message_t * sip){ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "cb_sndcancel (id=%i)\r\n", tr->transactionid));}static voidcb_sndinfo (int type, osip_transaction_t * tr, osip_message_t * sip){ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "cb_sndinfo (id=%i)\r\n", tr->transactionid));}static voidcb_sndoptions (int type, osip_transaction_t * tr, osip_message_t * sip){ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "cb_sndoptions (id=%i)\r\n", tr->transactionid));}static voidcb_sndnotify (int type, osip_transaction_t * tr, osip_message_t * sip){ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "cb_sndnotify (id=%i)\r\n", tr->transactionid));}static voidcb_sndsubscribe (int type, osip_transaction_t * tr, osip_message_t * sip){ OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "cb_sndsubscibe (id=%i)\r\n", tr->transactionid));}static void
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?