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

int eXosip_initiate_call ( osip_message_t *  invite,
void *  reference,
void *  sdp_context_reference,
char *  local_sdp_port 
)

Initiate a call.

Parameters:
invite SIP INVITE message to send.
reference Application context. (optionnal)
sdp_reference_context Sdp Application context. (optionnal)
local_sdp_port The port to be used for this call.

Definition at line 1046 of file eXosip.c.

{
  eXosip_call_t *jc;
  osip_header_t *subject;
  osip_transaction_t *transaction;
  osip_event_t *sipevent;
  int i;
  sdp_message_t *sdp;
  char *body;
  char *size;
  
  if (invite==NULL || invite->req_uri==NULL || invite->req_uri->host==NULL  ) return -1;
  
  if (local_sdp_port!=NULL)
    {
      osip_negotiation_sdp_build_offer(eXosip.osip_negotiation, NULL, &sdp, local_sdp_port, NULL);
      
      /*
      if speex codec is supported, add bandwith attribute:
      b=AS:110 20
      b=AS:111 20
      */
      if (sdp!=NULL)
      {
        int pos=0;
        while (!sdp_message_endof_media (sdp, pos))
          {
            int k = 0;
            char *tmp = sdp_message_m_media_get (sdp, pos);
            if (0 == osip_strncasecmp (tmp, "audio", 5))
            {
              char *payload = NULL;
              do {
                payload = sdp_message_m_payload_get (sdp, pos, k);
                if (payload == NULL)
                  {
                  }
                else if (0==strcmp("110",payload))
                  {
                  sdp_message_a_attribute_add (sdp,
                                         pos,
                                         osip_strdup ("AS"),
                                         osip_strdup ("110 20"));
                  }
                else if (0==strcmp("111",payload))
                  {
                  sdp_message_a_attribute_add (sdp,
                                         pos,
                                         osip_strdup ("AS"),
                                         osip_strdup ("111 20"));
                  }
                k++;
              } while (payload != NULL);
            }
            pos++;
          }
      }

        if (eXosip.j_firewall_ip[0]!='\0')
        {
              char *c_address = invite->req_uri->host;
              int pos=0;
              struct addrinfo *addrinfo;
              struct __eXosip_sockaddr addr;
              i = eXosip_get_addrinfo(&addrinfo, invite->req_uri->host, 5060);
              if (i==0)
                  {
                    memcpy (&addr, addrinfo->ai_addr, addrinfo->ai_addrlen);
                    freeaddrinfo (addrinfo);
                    c_address = inet_ntoa (((struct sockaddr_in *) &addr)->sin_addr);
                    OSIP_TRACE (osip_trace
                          (__FILE__, __LINE__, OSIP_INFO1, NULL,
                          "eXosip: here is the resolved destination host=%s\n", c_address));
                  }

              /* If remote message contains a Public IP, we have to replace the SDP
                  connection address */
              if (eXosip_is_public_address(c_address))
              {
                    /* replace the IP with our firewall ip */
                    sdp_connection_t *conn = sdp_message_connection_get(sdp, -1, 0);
                    if (conn!=NULL && conn->c_addr!=NULL )
                    {
                          osip_free(conn->c_addr);
                          conn->c_addr = osip_strdup(eXosip.j_firewall_ip);
                    }
                    pos=0;
                    conn = sdp_message_connection_get(sdp, pos, 0);
                    while (conn!=NULL)
                    {
                          if (conn!=NULL && conn->c_addr!=NULL )
                          {
                                osip_free(conn->c_addr);
                                conn->c_addr = osip_strdup(eXosip.j_firewall_ip);
                          }
                          pos++;
                          conn = sdp_message_connection_get(sdp, pos, 0);
                    }
              }

        }

      i = sdp_message_to_str(sdp, &body);
      if (body!=NULL)
      {
        size= (char *)osip_malloc(7*sizeof(char));
#ifdef __APPLE_CC__
        sprintf(size,"%li",strlen(body));
#else
        sprintf(size,"%i",strlen(body));
#endif
        osip_message_set_content_length(invite, size);
        osip_free(size);
        
        osip_message_set_body(invite, body, strlen(body));
        osip_free(body);
        osip_message_set_content_type(invite, "application/sdp");
      }
      else
      osip_message_set_content_length(invite, "0");
    }

  eXosip_call_init(&jc);
  if (local_sdp_port!=NULL)
    snprintf(jc->c_sdp_port,9, "%s", local_sdp_port);
  i = osip_message_get_subject(invite, 0, &subject);
  if (subject!=NULL && subject->hvalue!=NULL && subject->hvalue[0]!='\0')
        snprintf(jc->c_subject, 99, "%s", subject->hvalue);
  
  if (sdp_context_reference==NULL)
    osip_negotiation_ctx_set_mycontext(jc->c_ctx, jc);
  else
    osip_negotiation_ctx_set_mycontext(jc->c_ctx, sdp_context_reference);

  if (local_sdp_port!=NULL)
    {
      osip_negotiation_ctx_set_local_sdp(jc->c_ctx, sdp);
      jc->c_ack_sdp = 0;
    }
  else
    jc->c_ack_sdp = 1;

  i = osip_transaction_init(&transaction,
                   ICT,
                   eXosip.j_osip,
                   invite);
  if (i!=0)
    {
      eXosip_call_free(jc);
      osip_message_free(invite);
      return -1;
    }
  
  jc->c_out_tr = transaction;
  
  sipevent = osip_new_outgoing_sipmessage(invite);
  sipevent->transactionid =  transaction->transactionid;
  
  osip_transaction_set_your_instance(transaction, __eXosip_new_jinfo(jc, NULL, NULL, NULL));
  osip_transaction_add_event(transaction, sipevent);

  jc->external_reference = reference;
  ADD_ELEMENT(eXosip.j_calls, jc);

  eXosip_update(); /* fixed? */
  __eXosip_wakeup();
  return jc->c_id;
}


Generated by  Doxygen 1.6.0   Back to index