⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exconf.c

📁 libosip2-3版本的osip源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  eXosip - This is the eXtended osip library.  Copyright (C) 2002, 2003  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 "eXosip2.h"#include <eXosip2/eXosip.h>#include <osip2/osip_mt.h>#include <osip2/osip_condv.h>extern eXosip_t eXosip;int ipv6_enable = 0;static void *_eXosip_thread (void *arg);static int _eXosip_execute (void);static void _eXosip_keep_alive (void);voideXosip_enable_ipv6 (int _ipv6_enable){  ipv6_enable = _ipv6_enable;}voideXosip_masquerade_contact (const char *public_address, int port){  if (public_address == NULL || public_address[0] == '\0')    {      memset (eXosip.net_interfaces[0].net_firewall_ip, '\0',              sizeof (eXosip.net_interfaces[0].net_firewall_ip));      memset (eXosip.net_interfaces[1].net_firewall_ip, '\0',              sizeof (eXosip.net_interfaces[1].net_firewall_ip));      memset (eXosip.net_interfaces[2].net_firewall_ip, '\0',              sizeof (eXosip.net_interfaces[2].net_firewall_ip));      return;    }  snprintf (eXosip.net_interfaces[0].net_firewall_ip,            sizeof (eXosip.net_interfaces[0].net_firewall_ip), "%s",            public_address);  snprintf (eXosip.net_interfaces[1].net_firewall_ip,            sizeof (eXosip.net_interfaces[1].net_firewall_ip), "%s",            public_address);  snprintf (eXosip.net_interfaces[2].net_firewall_ip,            sizeof (eXosip.net_interfaces[2].net_firewall_ip), "%s",            public_address);  if (port > 0)    {      snprintf (eXosip.net_interfaces[0].net_port,                sizeof (eXosip.net_interfaces[0].net_port), "%i", port);      snprintf (eXosip.net_interfaces[1].net_port,                sizeof (eXosip.net_interfaces[1].net_port), "%i", port);      snprintf (eXosip.net_interfaces[2].net_port,                sizeof (eXosip.net_interfaces[2].net_port), "%i", port);    }  return;}inteXosip_force_masquerade_contact (const char *public_address){  if (public_address == NULL || public_address[0] == '\0')    {      memset (eXosip.net_interfaces[0].net_firewall_ip, '\0',              sizeof (eXosip.net_interfaces[0].net_firewall_ip));      memset (eXosip.net_interfaces[1].net_firewall_ip, '\0',              sizeof (eXosip.net_interfaces[1].net_firewall_ip));      memset (eXosip.net_interfaces[2].net_firewall_ip, '\0',              sizeof (eXosip.net_interfaces[2].net_firewall_ip));      eXosip.forced_localip = 0;      return 0;    }  eXosip.forced_localip = 1;  snprintf (eXosip.net_interfaces[0].net_firewall_ip, 50, "%s", public_address);  snprintf (eXosip.net_interfaces[1].net_firewall_ip, 50, "%s", public_address);  snprintf (eXosip.net_interfaces[2].net_firewall_ip, 50, "%s", public_address);  return 0;}inteXosip_guess_localip (int family, char *address, int size){  return eXosip_guess_ip_for_via (family, address, size);}inteXosip_is_public_address (const char *c_address){  return (0 != strncmp (c_address, "192.168", 7)          && 0 != strncmp (c_address, "10.", 3)          && 0 != strncmp (c_address, "172.16.", 7)          && 0 != strncmp (c_address, "172.17.", 7)          && 0 != strncmp (c_address, "172.18.", 7)          && 0 != strncmp (c_address, "172.19.", 7)          && 0 != strncmp (c_address, "172.20.", 7)          && 0 != strncmp (c_address, "172.21.", 7)          && 0 != strncmp (c_address, "172.22.", 7)          && 0 != strncmp (c_address, "172.23.", 7)          && 0 != strncmp (c_address, "172.24.", 7)          && 0 != strncmp (c_address, "172.25.", 7)          && 0 != strncmp (c_address, "172.26.", 7)          && 0 != strncmp (c_address, "172.27.", 7)          && 0 != strncmp (c_address, "172.28.", 7)          && 0 != strncmp (c_address, "172.29.", 7)          && 0 != strncmp (c_address, "172.30.", 7)          && 0 != strncmp (c_address, "172.31.", 7)          && 0 != strncmp (c_address, "169.254", 7));}voideXosip_set_user_agent (const char *user_agent){  osip_free (eXosip.user_agent);  eXosip.user_agent = osip_strdup (user_agent);}voideXosip_kill_transaction (osip_list_t * transactions){  osip_transaction_t *transaction;  if (!osip_list_eol (transactions, 0))    {      /* some transaction are still used by osip,         transaction should be released by modules! */      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_ERROR, NULL,                   "module sfp: _osip_kill_transaction transaction should be released by modules!\n"));    }  while (!osip_list_eol (transactions, 0))    {      transaction = osip_list_get (transactions, 0);      __eXosip_delete_jinfo (transaction);      osip_transaction_free (transaction);    }}voideXosip_quit (void){  jauthinfo_t *jauthinfo;  eXosip_call_t *jc;  eXosip_notify_t *jn;  eXosip_subscribe_t *js;  eXosip_reg_t *jreg;  eXosip_pub_t *jpub;  int i;  int pos;  if (eXosip.j_stop_ua==-1)  {		OSIP_TRACE (osip_trace					(__FILE__, __LINE__, OSIP_WARNING, NULL,					"eXosip: already stopped!\n"));	  return;  }  eXosip.j_stop_ua = 1;         /* ask to quit the application */  __eXosip_wakeup ();  __eXosip_wakeup_event ();  if (eXosip.j_thread!=NULL)  {    i = osip_thread_join ((struct osip_thread *) eXosip.j_thread);    if (i != 0)        {        OSIP_TRACE (osip_trace                    (__FILE__, __LINE__, OSIP_ERROR, NULL,                    "eXosip: can't terminate thread!\n"));        }    osip_free ((struct osip_thread *) eXosip.j_thread);  }  jpipe_close (eXosip.j_socketctl);  jpipe_close (eXosip.j_socketctl_event);  osip_free (eXosip.user_agent);  for (jc = eXosip.j_calls; jc != NULL; jc = eXosip.j_calls)    {      REMOVE_ELEMENT (eXosip.j_calls, jc);      eXosip_call_free (jc);    }  for (js = eXosip.j_subscribes; js != NULL; js = eXosip.j_subscribes)    {      REMOVE_ELEMENT (eXosip.j_subscribes, js);      eXosip_subscribe_free (js);    }  for (jn = eXosip.j_notifies; jn != NULL; jn = eXosip.j_notifies)    {      REMOVE_ELEMENT (eXosip.j_notifies, jn);      eXosip_notify_free (jn);    }  osip_mutex_destroy ((struct osip_mutex *) eXosip.j_mutexlock);#if !defined (_WIN32_WCE)  osip_cond_destroy ((struct osip_cond *) eXosip.j_cond);#endif  if (eXosip.net_interfaces[0].net_socket)    {      close (eXosip.net_interfaces[0].net_socket);      eXosip.net_interfaces[0].net_socket = -1;    }  if (eXosip.net_interfaces[1].net_socket)    {      close (eXosip.net_interfaces[1].net_socket);      eXosip.net_interfaces[1].net_socket = -1;    }  if (eXosip.net_interfaces[2].net_socket)    {      close (eXosip.net_interfaces[2].net_socket);      eXosip.net_interfaces[2].net_socket = -1;    }  for (pos = 0; pos < EXOSIP_MAX_SOCKETS; pos++)    {      if (eXosip.net_interfaces[0].net_socket_tab[pos].socket != 0)        close (eXosip.net_interfaces[0].net_socket_tab[pos].socket);      if (eXosip.net_interfaces[1].net_socket_tab[pos].socket != 0)        close (eXosip.net_interfaces[1].net_socket_tab[pos].socket);      if (eXosip.net_interfaces[2].net_socket_tab[pos].socket != 0)        close (eXosip.net_interfaces[2].net_socket_tab[pos].socket);    }  for (jreg = eXosip.j_reg; jreg != NULL; jreg = eXosip.j_reg)    {      REMOVE_ELEMENT (eXosip.j_reg, jreg);      eXosip_reg_free (jreg);    }  for (jpub = eXosip.j_pub; jpub != NULL; jpub = eXosip.j_pub)    {      REMOVE_ELEMENT (eXosip.j_pub, jpub);      _eXosip_pub_free (jpub);    }  while (!osip_list_eol (eXosip.j_transactions, 0))    {      osip_transaction_t *tr =        (osip_transaction_t *) osip_list_get (eXosip.j_transactions, 0);      if (tr->state == IST_TERMINATED || tr->state == ICT_TERMINATED          || tr->state == NICT_TERMINATED || tr->state == NIST_TERMINATED)        {          OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL,                                  "Release a terminated transaction\n"));          osip_list_remove (eXosip.j_transactions, 0);          __eXosip_delete_jinfo (tr);          osip_transaction_free (tr);      } else        {          osip_list_remove (eXosip.j_transactions, 0);          __eXosip_delete_jinfo (tr);          osip_transaction_free (tr);        }    }  osip_free (eXosip.j_transactions);  eXosip_kill_transaction (&eXosip.j_osip->osip_ict_transactions);  eXosip_kill_transaction (&eXosip.j_osip->osip_nict_transactions);  eXosip_kill_transaction (&eXosip.j_osip->osip_ist_transactions);  eXosip_kill_transaction (&eXosip.j_osip->osip_nist_transactions);  osip_release (eXosip.j_osip);  {    eXosip_event_t *ev;    for (ev = osip_fifo_tryget (eXosip.j_events); ev != NULL;         ev = osip_fifo_tryget (eXosip.j_events))      eXosip_event_free (ev);  }  osip_fifo_free (eXosip.j_events);  for (jauthinfo = eXosip.authinfos; jauthinfo != NULL;       jauthinfo = eXosip.authinfos)    {      REMOVE_ELEMENT (eXosip.authinfos, jauthinfo);      osip_free (jauthinfo);    }  memset (&eXosip, 0, sizeof (eXosip));  eXosip.j_stop_ua = -1;  return;}inteXosip_set_socket (int transport, int socket, int port){  if (eXosip.net_interfaces[0].net_socket > 0)    close (eXosip.net_interfaces[0].net_socket);  eXosip.net_interfaces[0].net_protocol = transport;  eXosip.net_interfaces[0].net_ip_family = AF_INET;  eXosip.net_interfaces[0].net_socket = socket;  snprintf (eXosip.net_interfaces[0].net_port,            sizeof (eXosip.net_interfaces[0].net_port), "%i", port);  eXosip.j_thread = (void *) osip_thread_create (20000, _eXosip_thread, NULL);  if (eXosip.j_thread == NULL)    {      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_ERROR, NULL,                   "eXosip: Cannot start thread!\n"));      return -1;    }  return 0;}#ifdef IPV6_V6ONLYintsetsockopt_ipv6only (int sock){  int on = 1;  return setsockopt (sock, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &on, sizeof (on));}#endif /* IPV6_V6ONLY */inteXosip_listen_addr (int transport, const char *addr, int port, int family,                    int secure){  int res;  struct addrinfo *addrinfo = NULL;  struct addrinfo *curinfo;  const char *node = addr;  int sock = -1;  struct eXosip_net *net_int;  char localip[256];  if (transport == IPPROTO_UDP)    net_int = &eXosip.net_interfaces[0];  else if (transport == IPPROTO_TCP)    net_int = &eXosip.net_interfaces[1];  else if (transport == IPPROTO_TCP && secure != 0)    net_int = &eXosip.net_interfaces[2];  else    {      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_ERROR, NULL,                   "eXosip: unknown protocol (use IPPROTO_UDP or IPPROTO_TCP!\n"));      return -1;    }  if (eXosip.http_port)    {      /* USE TUNNEL CAPABILITY */      transport = IPPROTO_TCP;    }  if (port < 0)    {      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_ERROR, NULL,                   "eXosip: port must be higher than 0!\n"));      return -1;    }  net_int->net_ip_family = family;  if (family == AF_INET6)    {      ipv6_enable = 1;      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_INFO1, NULL,                   "IPv6 is enabled. Pls report bugs\n"));    }  eXosip_guess_localip (net_int->net_ip_family, localip, sizeof (localip));  if (localip[0] == '\0')    {      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_ERROR, NULL,                   "eXosip: No ethernet interface found!\n"));      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_ERROR, NULL,                   "eXosip: using 127.0.0.1 (debug mode)!\n"));      /* we should always fallback on something. The linphone user will surely         start linphone BEFORE setting its dial up connection. */    }  if (!node)    {      node = ipv6_enable ? "::" : "0.0.0.0";    }  res = eXosip_get_addrinfo (&addrinfo, node, port, transport);  if (res)    return -1;  for (curinfo = addrinfo; curinfo; curinfo = curinfo->ai_next)    {      socklen_t len;      if (curinfo->ai_protocol && curinfo->ai_protocol != transport)        {          OSIP_TRACE (osip_trace                      (__FILE__, __LINE__, OSIP_INFO3, NULL,                       "eXosip: Skipping protocol %d\n", curinfo->ai_protocol));          continue;        }      sock = (int) socket (curinfo->ai_family, curinfo->ai_socktype,                           curinfo->ai_protocol);      if (sock < 0)        {
#if !defined(_WIN32_WCE)

⌨️ 快捷键说明

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