Logo Search packages:      
Sourcecode: linphone version File versions  Download package

int eXosip_init ( FILE *  input,
FILE *  output,
int  port 
)

Initiate the eXtented oSIP library.

Parameters:
input command input (RESERVED FOR FUTUR USE).
output resulting output (RESERVED FOR FUTUR USE).
port The SIP port to use. (5060 is the default)

Definition at line 388 of file eXosip.c.

References eXosip_guess_localip(), eXosip_sdp_negotiation_add_codec(), eXosip_set_mode(), and jpipe().

{
  osip_t *osip;
  int i;
  if (port<=0)
    {
     OSIP_TRACE (osip_trace
              (__FILE__, __LINE__, OSIP_ERROR, NULL,
         "eXosip: port must be higher than 0!\n"));
      return -1;
    }
  memset(&eXosip, 0, sizeof(eXosip));
  eXosip.localip = (char *) osip_malloc(50);
  memset(eXosip.localip, '\0', 50);

  if (ipv6_enable == 0)
    eXosip.ip_family = AF_INET;
  else
    {
      OSIP_TRACE (osip_trace
              (__FILE__, __LINE__, OSIP_INFO2, NULL,
               "IPv6 is enabled. Pls report bugs\n"));
      eXosip.ip_family = AF_INET6;
    }

  eXosip_guess_localip(eXosip.ip_family, eXosip.localip, 49);
  if (eXosip.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"));
      strcpy(eXosip.localip, "127.0.0.1");
            /* we should always fallback on something. The linphone user will surely
            start linphone BEFORE setting its dial up connection.*/
    }
  eXosip.user_agent = osip_strdup("eXosip/" EXOSIP_VERSION);

  eXosip_set_mode(EVENT_MODE);
  eXosip.j_input = input;
  eXosip.j_output = output;
  eXosip.j_calls = NULL;
  eXosip.j_stop_ua = 0;
  eXosip.j_thread = NULL;
  eXosip.j_transactions = (osip_list_t*) osip_malloc(sizeof(osip_list_t));
  osip_list_init(eXosip.j_transactions);
  eXosip.j_reg = NULL;

  eXosip.j_cond      = (struct osip_cond*)osip_cond_init();

  eXosip.j_mutexlock = (struct osip_mutex*)osip_mutex_init();

  if (-1==osip_init(&osip))
    {
      OSIP_TRACE (osip_trace
              (__FILE__, __LINE__, OSIP_ERROR, NULL,
         "eXosip: Cannot initialize osip!\n"));
      return -1;
    }

  eXosip_sdp_negotiation_init(&(eXosip.osip_negotiation));

  eXosip_sdp_negotiation_add_codec(osip_strdup("0"),
                           NULL,
                           osip_strdup("RTP/AVP"),
                           NULL, NULL, NULL,
                           NULL,NULL,
                           osip_strdup("0 PCMU/8000"));

  eXosip_sdp_negotiation_add_codec(osip_strdup("8"),
                           NULL,
                           osip_strdup("RTP/AVP"),
                           NULL, NULL, NULL,
                           NULL,NULL,
                           osip_strdup("8 PCMA/8000"));

  osip_set_application_context(osip, &eXosip);
  
  eXosip_set_callbacks(osip);
  
  eXosip.j_osip = osip;

#ifdef WIN32
   /* Initializing windows socket library */
   {
     WORD wVersionRequested;
     WSADATA wsaData;

     wVersionRequested = MAKEWORD(1,1);
     if(i = WSAStartup(wVersionRequested,  &wsaData))
       {
         OSIP_TRACE (osip_trace
                 (__FILE__, __LINE__, OSIP_ERROR, NULL,
               "eXosip: Unable to initialize WINSOCK, reason: %d\n",i));
       /* return -1; It might be already initilized?? */
       }
   }
#endif

  /* open a TCP socket to wake up the application when needed. */
  eXosip.j_socketctl = jpipe();
  if (eXosip.j_socketctl==NULL)
    return -1;

  eXosip.j_socketctl_event = jpipe();
  if (eXosip.j_socketctl_event==NULL)
    return -1;
  if (ipv6_enable == 0)
    {
      eXosip.j_socket = (int)socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
      if (eXosip.j_socket==-1)
      return -1;
      
      {
      struct sockaddr_in  raddr;
      raddr.sin_addr.s_addr = htons(INADDR_ANY);
      raddr.sin_port = htons((short)port);
      raddr.sin_family = AF_INET;
      
      i = bind(eXosip.j_socket, (struct sockaddr *)&raddr, sizeof(raddr));
      if (i < 0)
        {
       OSIP_TRACE (osip_trace
               (__FILE__, __LINE__, OSIP_ERROR, NULL,
             "eXosip: Cannot bind on port: %i!\n", i));
          return -1;
        }
      }
    }
  else
    {
      eXosip.j_socket = (int)socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
      if (eXosip.j_socket==-1)
      return -1;
      
      {
      struct sockaddr_in6  raddr;
      memset(&raddr, 0, sizeof(raddr));
      raddr.sin6_port = htons((short)port);
      raddr.sin6_family = AF_INET6;
      
      i = bind(eXosip.j_socket, (struct sockaddr *)&raddr, sizeof(raddr));
      if (i < 0)
        {
       OSIP_TRACE (osip_trace
              (__FILE__, __LINE__, OSIP_ERROR, NULL,
            "eXosip: Cannot bind on port: %i!\n", i));
          return -1;
        }
      }
    }


  eXosip.localport = (char*)osip_malloc(10);
  sprintf(eXosip.localport, "%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;
    }

  /* To be changed in osip! */
  eXosip.j_events = (osip_fifo_t*) osip_malloc(sizeof(osip_fifo_t));
  osip_fifo_init(eXosip.j_events);

  jfriend_load();
  jidentity_load();
  jsubscriber_load();
  return 0;
}


Generated by  Doxygen 1.6.0   Back to index