jcallback.c

来自「mediastreamer2是开源的网络传输媒体流的库」· C语言 代码 · 共 2,026 行 · 第 1/5 页

C
2,026
字号
/*  eXosip - This is the eXtended osip library.  Copyright (C) 2002,2003,2004,2005,2006,2007  Aymeric MOIZARD  - jack@atosc.org    eXosip is free software; you can redistribute it and/or modify  it under the terms of the GNU General Public License as published by  the Free Software Foundation; either version 2 of the License, or  (at your option) any later version.    eXosip is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU General Public License for more details.    You should have received a copy of the GNU General Public License  along with this program; if not, write to the Free Software  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/#ifdef ENABLE_MPATROL#include <mpatrol.h>#endif#include <stdlib.h>#ifdef _WIN32_WCE#include <winsock2.h>#include "inet_ntop.h"#elif WIN32#include <windowsx.h>#include <winsock2.h>#include <ws2tcpip.h>#include "inet_ntop.h"#else#include <sys/wait.h>#include <sys/types.h>#include <unistd.h>#include <assert.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <sys/types.h>#include <sys/socket.h>#include <netdb.h>#endif#include <eXosip2/eXosip.h>#include "eXosip2.h"#ifdef HAVE_OPENSSL_SSL_H#include <openssl/ssl.h>#endifextern eXosip_t eXosip;/* Private functions */static void rcvregister_failure (osip_transaction_t * tr, osip_message_t * sip);static void cb_xixt_kill_transaction (int type, osip_transaction_t * tr);#ifndef MINISIZEstatic void cb_rcvinvite (int type, osip_transaction_t * tr, osip_message_t * sip);static void cb_rcvack (int type, osip_transaction_t * tr, osip_message_t * sip);static void cb_rcvack2 (int type, osip_transaction_t * tr, osip_message_t * sip);static void cb_rcvcancel (int type, osip_transaction_t * tr, osip_message_t * sip);#endifstatic void cb_rcvregister (int type, osip_transaction_t * tr,                            osip_message_t * sip);static void cb_rcvrequest (int type, osip_transaction_t * tr,                           osip_message_t * sip);#ifndef MINISIZEstatic void cb_sndinvite (int type, osip_transaction_t * tr, osip_message_t * sip);static void cb_sndack (int type, osip_transaction_t * tr, osip_message_t * sip);static void cb_sndregister (int type, osip_transaction_t * tr,                            osip_message_t * sip);static void cb_sndbye (int type, osip_transaction_t * tr, osip_message_t * sip);static void cb_sndcancel (int type, osip_transaction_t * tr, osip_message_t * sip);static void cb_sndinfo (int type, osip_transaction_t * tr, osip_message_t * sip);static void cb_sndoptions (int type, osip_transaction_t * tr,                           osip_message_t * sip);static void cb_sndnotify (int type, osip_transaction_t * tr, osip_message_t * sip);static void cb_sndsubscribe (int type, osip_transaction_t * tr,                             osip_message_t * sip);static void cb_sndunkrequest (int type, osip_transaction_t * tr,                              osip_message_t * sip);#endifstatic void cb_rcv1xx (int type, osip_transaction_t * tr, osip_message_t * sip);static void cb_rcv2xx_4invite (osip_transaction_t * tr, osip_message_t * sip);#ifndef MINISIZEstatic void cb_rcv2xx_4subscribe (osip_transaction_t * tr, osip_message_t * sip);#endifstatic void cb_rcv2xx (int type, osip_transaction_t * tr, osip_message_t * sip);static void cb_rcv3xx (int type, osip_transaction_t * tr, osip_message_t * sip);static void cb_rcv4xx (int type, osip_transaction_t * tr, osip_message_t * sip);static void cb_rcv5xx (int type, osip_transaction_t * tr, osip_message_t * sip);static void cb_rcv6xx (int type, osip_transaction_t * tr, osip_message_t * sip);static void cb_snd123456xx (int type, osip_transaction_t * tr,                            osip_message_t * sip);#ifndef MINISIZEstatic void cb_rcvresp_retransmission (int type, osip_transaction_t * tr,                                       osip_message_t * sip);static void cb_sndreq_retransmission (int type, osip_transaction_t * tr,                                      osip_message_t * sip);static void cb_sndresp_retransmission (int type, osip_transaction_t * tr,                                       osip_message_t * sip);static void cb_rcvreq_retransmission (int type, osip_transaction_t * tr,                                      osip_message_t * sip);#endifstatic void cb_transport_error (int type, osip_transaction_t * tr, int error);intcb_snd_message (osip_transaction_t * tr, osip_message_t * sip, char *host,                int port, int out_socket){  int i;  osip_via_t *via;#ifndef MINISIZE  if (eXosip.dontsend_101 != 0 && sip->status_code == 101)    return OSIP_SUCCESS;#else  if (sip->status_code == 101)    return OSIP_SUCCESS;#endif  via = (osip_via_t *) osip_list_get (&sip->vias, 0);  if (via == NULL || via->protocol == NULL)    return -1;  if (host == NULL)    {      if (MSG_IS_REQUEST (sip))        {          osip_route_t *route;          osip_message_get_route (sip, 0, &route);          if (route != NULL)            {              osip_uri_param_t *lr_param = NULL;              osip_uri_uparam_get_byname (route->url, "lr", &lr_param);              if (lr_param == NULL)                route = NULL;            }          if (route != NULL)            {              port = 5060;              if (route->url->port != NULL)                port = osip_atoi (route->url->port);              host = route->url->host;          } else            {              /* search for maddr parameter */              osip_uri_param_t *maddr_param = NULL;              osip_uri_uparam_get_byname (sip->req_uri, "maddr", &maddr_param);              host = NULL;              if (maddr_param != NULL && maddr_param->gvalue != NULL)                host = maddr_param->gvalue;              port = 5060;              if (sip->req_uri->port != NULL)                port = osip_atoi (sip->req_uri->port);              if (host == NULL)                host = sip->req_uri->host;            }      } else        {          osip_generic_param_t *maddr;          osip_generic_param_t *received;          osip_generic_param_t *rport;          osip_via_param_get_byname (via, "maddr", &maddr);          osip_via_param_get_byname (via, "received", &received);          osip_via_param_get_byname (via, "rport", &rport);          if (maddr != NULL && maddr->gvalue != NULL)            host = maddr->gvalue;          else if (received != NULL && received->gvalue != NULL)            host = received->gvalue;          else            host = via->host;          if (rport == NULL || rport->gvalue == NULL)            {              if (via->port != NULL)                port = osip_atoi (via->port);              else                port = 5060;          } else            port = osip_atoi (rport->gvalue);        }    }  if (eXosip.cbsipCallback != NULL)    {      eXosip.cbsipCallback (sip, 0);    }  i = -1;  if (osip_strcasecmp (via->protocol, "udp") == 0)    {      i = eXtl_udp.tl_send_message (tr, sip, host, port, out_socket);  } else if (osip_strcasecmp (via->protocol, "tcp") == 0)    {      i = eXtl_tcp.tl_send_message (tr, sip, host, port, out_socket);    }#ifdef HAVE_OPENSSL_SSL_H  else if (osip_strcasecmp (via->protocol, "tls") == 0)    {      i = eXtl_tls.tl_send_message (tr, sip, host, port, out_socket);  } else if (osip_strcasecmp (via->protocol, "dtls-udp") == 0)    {      i = -1;#if !(OPENSSL_VERSION_NUMBER < 0x00908000L)      i = eXtl_dtls.tl_send_message (tr, sip, host, port, out_socket);#endif    }#endif  if (i != 0)    {      return -1;    }  return OSIP_SUCCESS;}static voidcb_xixt_kill_transaction (int type, osip_transaction_t * tr){  int i;  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)    {      rcvregister_failure (tr, NULL);      return;    }#ifndef MINISIZE  if (type == OSIP_NICT_KILL_TRANSACTION)    {      eXosip_dialog_t *jd;      eXosip_subscribe_t *js;      eXosip_notify_t *jn;      eXosip_call_t *jc;      jinfo_t *jinfo = (jinfo_t *) osip_transaction_get_your_instance (tr);      if (jinfo == NULL && tr->last_response == NULL)        {          eXosip_event_t *je;          je = eXosip_event_init_for_message (EXOSIP_MESSAGE_REQUESTFAILURE, tr);          report_event (je, NULL);          return;        }      if (jinfo == NULL)        {          return;        }      jc = jinfo->jc;      jd = jinfo->jd;      jn = jinfo->jn;      js = jinfo->js;      if (jn == NULL && js == NULL)        {          eXosip_event_t *je;          if (jc != NULL && tr->last_response == NULL)            {              report_call_event (EXOSIP_CALL_MESSAGE_REQUESTFAILURE, jc, jd, tr);              return;            }          if (jc == NULL && tr->last_response == NULL)            {              je =                eXosip_event_init_for_message (EXOSIP_MESSAGE_REQUESTFAILURE, tr);              report_event (je, NULL);            }          return;        }      /* no answer to a NOTIFY request! */      if (MSG_IS_NOTIFY (tr->orig_request) && tr->last_response == NULL)        {          /* delete the dialog! */          eXosip_event_t *je;          je = eXosip_event_init_for_notify (EXOSIP_NOTIFICATION_REQUESTFAILURE,                                             jn, jd, tr);          report_event (je, NULL);          REMOVE_ELEMENT (eXosip.j_notifies, jn);          eXosip_notify_free (jn);          return;        }      if (MSG_IS_NOTIFY (tr->orig_request)          && 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)          && 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)          && (tr->last_response == NULL || tr->last_response->status_code <= 199))        {          eXosip_event_t *je;          je = eXosip_event_init_for_subscribe (EXOSIP_SUBSCRIPTION_REQUESTFAILURE,                                                js, jd, tr);          report_event (je, NULL);          /* delete the dialog! */          REMOVE_ELEMENT (eXosip.j_subscribes, js);          eXosip_subscribe_free (js);          return;        }      /* detect SUBSCRIBE request that close the dialogs! */      if (MSG_IS_SUBSCRIBE (tr->orig_request))        {          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;            }        }    }#endif}#ifndef MINISIZEstatic 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_rcvcancel (int type, osip_transaction_t * tr, osip_message_t * sip){

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?