Example #1
0
int
eXosip_remove_transaction_from_call(osip_transaction_t *tr, eXosip_call_t *jc)
{
  eXosip_dialog_t *jd;

  if ((!tr) || (!jc))
    return 0;

  if (jc->c_inc_tr==tr)
    {
      jc->c_inc_tr = NULL; /* can be NULL */
      return 0;
    }

  if (jc->c_out_tr==tr)
    {
      jc->c_out_tr = NULL; /* can be NULL */
      return 0;
    }

  for (jd = jc->c_dialogs; jd; jd = jd->next)
    {
      if (!eXosip_list_remove_element(jd->d_inc_trs, tr))
	return 0;

      if (!eXosip_list_remove_element(jd->d_out_trs, tr))
	return 0;
    }

  OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO1,NULL,
				"eXosip: No information.\n"));

  return -1;
}
int
eXosip_message_build_answer (struct eXosip_t *excontext, int tid, int status, osip_message_t ** answer)
{
    osip_transaction_t *tr = NULL;
    int i;

    *answer = NULL;

    if (tid <= 0)
        return OSIP_BADPARAMETER;
    if (status < 200 || status > 699)
        return OSIP_BADPARAMETER;

    if (tid > 0) {
        _eXosip_transaction_find (excontext, tid, &tr);
    }
    if (tr == NULL) {
        OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: No call here?\n"));
        return OSIP_NOTFOUND;
    }

    i = -1;
    if (status < 300)             /* 2xx answer */
        i = _eXosip_build_response_default (excontext, answer, NULL, status, tr->orig_request);
    else if (status > 300)        /* 3456xx answer */
        i = _eXosip_build_response_default (excontext, answer, NULL, status, tr->orig_request);

    if (i != 0)
        return i;
    return OSIP_SUCCESS;
}
Example #3
0
int
osip_dialog_update_route_set_as_uas (osip_dialog_t * dialog, osip_message_t * invite)
{
    osip_contact_t *contact;
    int i;

    if (osip_list_eol (invite->contacts, 0))
    {
        OSIP_TRACE (osip_trace
                    (__FILE__, __LINE__, OSIP_WARNING, NULL,
                     "missing a contact in invite!\n"));
    }
    else
    {
        if (dialog->remote_contact_uri != NULL)
        {
            osip_contact_free (dialog->remote_contact_uri);
        }
        dialog->remote_contact_uri = NULL;
        contact = osip_list_get (invite->contacts, 0);
        i = osip_contact_clone (contact, &(dialog->remote_contact_uri));
        if (i != 0)
            return -1;
    }
    return 0;
}
Example #4
0
int
osip_fifo_insert (osip_fifo_t * ff, void *el)
{
#ifdef OSIP_MT
  osip_mutex_lock (ff->qislocked);
#endif

  if (ff->state != osip_full)
    {
      /* ff->nb_elt++; */
      osip_list_add (&ff->queue, el, 0); /* insert at end of queue */
  } else
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_WARNING, NULL,
                   "too much traffic in fifo.\n"));
#ifdef OSIP_MT
      osip_mutex_unlock (ff->qislocked);
#endif
      return -1;                /* stack is full */
    }
  /* if (ff->nb_elt >= MAX_LEN) */
  if (osip_list_size (&ff->queue) >= MAX_LEN)
    ff->state = osip_full;
  else
    ff->state = osip_ok;

#ifdef OSIP_MT
  osip_sem_post (ff->qisempty);
  osip_mutex_unlock (ff->qislocked);
#endif
  return 0;
}
Example #5
0
static int
_eXosip_default_gateway_with_getifaddrs(int type, char *address, int size)
{
	struct ifaddrs *ifp;

	struct ifaddrs *ifpstart;

	int ret = -1;

	if (getifaddrs(&ifpstart) < 0) {
		return OSIP_NO_NETWORK;
	}

	for (ifp = ifpstart; ifp != NULL; ifp = ifp->ifa_next) {
		if (ifp->ifa_addr && ifp->ifa_addr->sa_family == type
			&& (ifp->ifa_flags & IFF_RUNNING) && !(ifp->ifa_flags & IFF_LOOPBACK))
		{
			getnameinfo(ifp->ifa_addr,
						(type == AF_INET6) ?
						sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in),
						address, size, NULL, 0, NI_NUMERICHOST);
			if (strchr(address, '%') == NULL) {	/*avoid ipv6 link-local addresses */
				OSIP_TRACE(osip_trace
						   (__FILE__, __LINE__, OSIP_INFO2, NULL,
							"_eXosip_default_gateway_with_getifaddrs(): found %s\n",
							address));
				ret = 0;
				break;
			}
		}
	}
	freeifaddrs(ifpstart);
	return ret;
}
int
eXosip_message_send_answer (struct eXosip_t *excontext, int tid, int status, osip_message_t * answer)
{
    osip_transaction_t *tr = NULL;
    osip_event_t *evt_answer;
    int i = -1;

    if (tid <= 0)
        return OSIP_BADPARAMETER;
    if (status <= 100 || status > 699)
        return OSIP_BADPARAMETER;
    if (answer == NULL && status > 100 && status < 200)
        return OSIP_BADPARAMETER;

    if (tid > 0) {
        _eXosip_transaction_find (excontext, tid, &tr);
    }
    if (tr == NULL) {
        OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: No MESSAGE transaction found\n"));
        osip_message_free (answer);
        return OSIP_NOTFOUND;
    }

    /* is the transaction already answered? */
    if (tr->state == NIST_COMPLETED || tr->state == NIST_TERMINATED) {
        OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: transaction already answered\n"));
        osip_message_free (answer);
        return OSIP_WRONG_STATE;
    }

    if (answer == NULL) {
        i = -1;
        if (status > 199 && status < 300)
            i = _eXosip_build_response_default (excontext, &answer, NULL, status, tr->orig_request);
        else if (status > 300 && status <= 699)
            i = _eXosip_build_response_default (excontext, &answer, NULL, status, tr->orig_request);
        if (i != 0)
            return i;
    }

    evt_answer = osip_new_outgoing_sipmessage (answer);
    evt_answer->transactionid = tr->transactionid;

    osip_transaction_add_event (tr, evt_answer);
    _eXosip_wakeup (excontext);
    return OSIP_SUCCESS;
}
Example #7
0
int
_eXosip_answer_invite_3456xx (eXosip_call_t * jc, eXosip_dialog_t * jd,
                              int code, osip_message_t ** answer)
{
  int i;
  osip_transaction_t *tr;

  *answer = NULL;
  tr = eXosip_find_last_inc_invite (jc, jd);
  if (tr == NULL)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: cannot find transaction to answer"));
      return -1;
    }
  /* is the transaction already answered? */
  if (tr->state == IST_COMPLETED
      || tr->state == IST_CONFIRMED || tr->state == IST_TERMINATED)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: transaction already answered\n"));
      return -1;
    }

  i =
    _eXosip_build_response_default (answer, jd->d_dialog, code, tr->orig_request);
  if (i != 0)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_INFO1, NULL,
                   "ERROR: Could not create response for invite\n"));
      return -1;
    }

  if ((300 <= code) && (code <= 399))
    {
      /* Should add contact fields */
      /* ... */
    }

  osip_message_set_content_length (*answer, "0");
  /*  send message to transaction layer */

  return 0;
}
int
eXosip_insubscription_send_request (int did, osip_message_t * request)
{
    eXosip_dialog_t *jd = NULL;
    eXosip_notify_t *jn = NULL;

    osip_transaction_t *transaction;
    osip_event_t *sipevent;
    int i;

    if (request == NULL)
        return -1;

    if (did > 0)
    {
        eXosip_notify_dialog_find (did, &jn, &jd);
    }
    if (jd == NULL || jn == NULL)
    {
        OSIP_TRACE (osip_trace
                    (__FILE__, __LINE__, OSIP_ERROR, NULL,
                     "eXosip: No incoming subscription here?\n"));
        osip_message_free (request);
        return -1;
    }

    transaction = NULL;
    transaction = eXosip_find_last_out_notify (jn, jd);
    if (transaction != NULL)
    {
        if (transaction->state != NICT_TERMINATED &&
                transaction->state != NIST_TERMINATED &&
                transaction->state != NICT_COMPLETED &&
                transaction->state != NIST_COMPLETED)
        {
            osip_message_free (request);
            return -1;
        }
        transaction = NULL;
    }

    i = osip_transaction_init (&transaction, NICT, eXosip.j_osip, request);
    if (i != 0)
    {
        osip_message_free (request);
        return -1;
    }

    osip_list_add (jd->d_out_trs, transaction, 0);

    sipevent = osip_new_outgoing_sipmessage (request);
    sipevent->transactionid = transaction->transactionid;

    osip_transaction_set_your_instance (transaction,
                                        __eXosip_new_jinfo (NULL, jd, NULL, jn));
    osip_transaction_add_event (transaction, sipevent);
    __eXosip_wakeup ();
    return 0;
}
int
eXosip_insubscription_build_request (int did, const char *method,
                                     osip_message_t ** request)
{
    eXosip_dialog_t *jd = NULL;
    eXosip_notify_t *jn = NULL;

    osip_transaction_t *transaction;
    char *transport;
    int i;

    *request = NULL;
    if (method == NULL || method[0] == '\0')
        return -1;

    if (did > 0)
    {
        eXosip_notify_dialog_find (did, &jn, &jd);
    }
    if (jd == NULL || jn == NULL)
    {
        OSIP_TRACE (osip_trace
                    (__FILE__, __LINE__, OSIP_ERROR, NULL,
                     "eXosip: No incoming subscription here?\n"));
        return -1;
    }

    transaction = NULL;
    transaction = eXosip_find_last_out_notify (jn, jd);
    if (transaction != NULL)
    {
        if (transaction->state != NICT_TERMINATED &&
                transaction->state != NIST_TERMINATED &&
                transaction->state != NICT_COMPLETED &&
                transaction->state != NIST_COMPLETED)
            return -1;
    }

    transport = NULL;
    if (transaction == NULL)
        transaction = jn->n_inc_tr;

    if (transaction != NULL && transaction->orig_request != NULL)
        transport = _eXosip_transport_protocol (transaction->orig_request);

    transaction = NULL;

    if (transport == NULL)
        i = _eXosip_build_request_within_dialog (request, method, jd->d_dialog, "UDP");
    else
        i =
            _eXosip_build_request_within_dialog (request, method, jd->d_dialog,
                    transport);
    if (i != 0)
        return -2;

    return 0;
}
Example #10
0
int
__osip_nict_init (osip_nict_t ** nict, osip_t * osip, osip_message_t * request)
{
  osip_route_t *route;
  int i;

  OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO2, NULL, "allocating NICT context\n"));

  *nict = (osip_nict_t *) osip_malloc (sizeof (osip_nict_t));
  if (*nict == NULL)
    return OSIP_NOMEM;

  memset (*nict, 0, sizeof (osip_nict_t));
  /* for REQUEST retransmissions */
  {
    osip_via_t *via;
    char *proto;

    i = osip_message_get_via (request, 0, &via);        /* get top via */
    if (i < 0) {
      osip_free (*nict);
      *nict = NULL;
      return i;
    }
    proto = via_get_protocol (via);
    if (proto == NULL) {
      osip_free (*nict);
      *nict = NULL;
      return OSIP_UNDEFINED_ERROR;
    }
#ifdef USE_BLOCKINGSOCKET
    if (osip_strcasecmp (proto, "TCP") != 0 && osip_strcasecmp (proto, "TLS") != 0 && osip_strcasecmp (proto, "SCTP") != 0) {
      (*nict)->timer_e_length = DEFAULT_T1;
      (*nict)->timer_k_length = DEFAULT_T4;
      (*nict)->timer_e_start.tv_sec = -1;
      (*nict)->timer_k_start.tv_sec = -1;       /* not started */
    }
    else {                      /* reliable protocol is used: */
      (*nict)->timer_e_length = -1;     /* E is not ACTIVE */
      (*nict)->timer_k_length = 0;      /* MUST do the transition immediatly */
      (*nict)->timer_e_start.tv_sec = -1;
      (*nict)->timer_k_start.tv_sec = -1;       /* not started */
    }
  }
#else
    if (osip_strcasecmp (proto, "TCP") != 0 && osip_strcasecmp (proto, "TLS") != 0 && osip_strcasecmp (proto, "SCTP") != 0) {
      (*nict)->timer_e_length = DEFAULT_T1;
      (*nict)->timer_k_length = DEFAULT_T4;
      (*nict)->timer_e_start.tv_sec = -1;
      (*nict)->timer_k_start.tv_sec = -1;       /* not started */
    }
    else {                      /* reliable protocol is used: */
      (*nict)->timer_e_length = DEFAULT_T1;
      (*nict)->timer_k_length = 0;      /* MUST do the transition immediatly */
      (*nict)->timer_e_start.tv_sec = -1;
      (*nict)->timer_k_start.tv_sec = -1;       /* not started */
    }
  }
Example #11
0
int
_eXosip2_answer_invite_1xx(eXosip_call_t *jc, eXosip_dialog_t *jd, int code, osip_message_t **answer)
{
  int i;
  osip_transaction_t *tr;
  tr = eXosip_find_last_inc_invite(jc, jd);
  if (tr==NULL)
    {
      OSIP_TRACE (osip_trace
		  (__FILE__, __LINE__, OSIP_ERROR, NULL,
         "eXosip: cannot find transaction to answer"));
      return -1;
    }
  /* is the transaction already answered? */
  if (tr->state==IST_COMPLETED
      || tr->state==IST_CONFIRMED
      || tr->state==IST_TERMINATED)
    {
      OSIP_TRACE (osip_trace
		  (__FILE__, __LINE__, OSIP_ERROR, NULL,
         "eXosip: transaction already answered\n"));
      return -1;
    }

  if (jd==NULL)
    i = _eXosip_build_response_default(answer, NULL, code, tr->orig_request);
  else
    i = _eXosip_build_response_default(answer, jd->d_dialog, code, tr->orig_request);

  if (i!=0)
    {
      OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_ERROR,NULL,"ERROR: Could not create response for invite\n"));
      return -2;
    }

  osip_message_set_content_length(*answer, "0");
  /*  send message to transaction layer */

  if (code>100)
    {
      i = complete_answer_that_establish_a_dialog(*answer, tr->orig_request);
    }
  
  return 0;
}
Example #12
0
int
eXosip_options_build_answer (int tid, int status, osip_message_t ** answer)
{
  osip_transaction_t *tr = NULL;
  int i = -1;

  *answer = NULL;
  if (tid > 0)
    {
      eXosip_transaction_find (tid, &tr);
    }
  if (tr == NULL)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: No call here?\n"));
      return -1;
    }
  if (status > 100 && status < 200)
    {
#if 0
      /* TODO: not implemented */
      i = _eXosip_build_response_default (response, NULL, code, tr->orig_request);
#endif
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: status code 1xx for options not implemented (use 200<status<=699)\n"));
      return -1;
  } else if (status > 199 && status < 300)
    {
      i = _eXosip_build_response_default (answer, NULL, status, tr->orig_request);
  } else if (status > 300 && status <= 699)
    {
      i = _eXosip_build_response_default (answer, NULL, status, tr->orig_request);
  } else
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: wrong status code (200<status<=699)\n"));
      return -1;
    }
  if (i != 0)
    return -1;
  return 0;
}
Example #13
0
int
__osip_ist_free (osip_ist_t * ist)
{
  if (ist == NULL)
    return OSIP_SUCCESS;
  OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO2, NULL, "free ist resource\n"));
  osip_free (ist);
  return OSIP_SUCCESS;
}
Example #14
0
int
eXosip_register_send_register (int rid, osip_message_t * reg)
{
    osip_transaction_t *transaction;
    osip_event_t *sipevent;
    eXosip_reg_t *jr;
    int i;

    jr = eXosip_reg_find (rid);
    if (jr == NULL)
    {
        osip_message_free (reg);
        return -1;
    }

    if (jr->r_last_tr != NULL)
    {
        if (jr->r_last_tr->state != NICT_TERMINATED
                && jr->r_last_tr->state != NICT_COMPLETED)
        {
            osip_message_free (reg);
            return -1;
        }
    }

    if (reg == NULL)
    {
        i = _eXosip_register_build_register (jr, &reg);
        if (i != 0)
        {
            OSIP_TRACE (osip_trace
                        (__FILE__, __LINE__, OSIP_ERROR, NULL,
                         "eXosip: cannot build REGISTER!"));
            return i;
        }
    }

    i = _eXosip_transaction_init (&transaction, NICT, eXosip.j_osip, reg);
    if (i != 0)
    {
        /* TODO: release the j_call.. */

        osip_message_free (reg);
        return -2;
    }

    jr->r_last_tr = transaction;

    /* send REGISTER */
    sipevent = osip_new_outgoing_sipmessage (reg);
    sipevent->transactionid = transaction->transactionid;
    osip_message_force_update (reg);

    osip_transaction_add_event (transaction, sipevent);
    __eXosip_wakeup ();
    return 0;
}
Example #15
0
int
_eXosip_insubscription_answer_3456xx (eXosip_notify_t * jn,
                                      eXosip_dialog_t * jd, int code)
{
  osip_event_t *evt_answer;
  osip_message_t *response;
  int i;
  osip_transaction_t *tr;

  tr = eXosip_find_last_inc_subscribe (jn, jd);
  if (tr == NULL)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: cannot find transaction to answer"));
      return -1;
    }
  if (jd == NULL)
    i = _eXosip_build_response_default (&response, NULL, code, tr->orig_request);
  else
    i =
      _eXosip_build_response_default (&response, jd->d_dialog, code,
                                      tr->orig_request);
  if (i != 0)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_INFO1, NULL,
                   "ERROR: Could not create response for subscribe\n"));
      return -1;
    }

  if ((300 <= code) && (code <= 399))
    {
      /* Should add contact fields */
      /* ... */
    }

  evt_answer = osip_new_outgoing_sipmessage (response);
  evt_answer->transactionid = tr->transactionid;

  osip_transaction_add_event (tr, evt_answer);
  __eXosip_wakeup ();
  return 0;
}
Example #16
0
static jauthinfo_t *
eXosip_find_authentication_info (const char *username, const char *realm)
{
  jauthinfo_t *fallback = NULL;
  jauthinfo_t *authinfo;

  for (authinfo = eXosip.authinfos; authinfo != NULL; authinfo = authinfo->next)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_INFO3, NULL,
                   "INFO: authinfo: %s %s\n", realm, authinfo->realm));
      if (0 == strcmp (authinfo->username, username))
        {
          if (authinfo->realm == NULL || authinfo->realm[0] == '\0')
            {
              fallback = authinfo;
          } else if (strcmp (realm, authinfo->realm) == 0
                     || 0 == strncmp (realm + 1, authinfo->realm,
                                      strlen (realm) - 2))
            {
              return authinfo;
            }
        }
    }

  /* no matching username has been found for this realm,
     try with another username... */
  for (authinfo = eXosip.authinfos; authinfo != NULL; authinfo = authinfo->next)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_INFO3, NULL,
                   "INFO: authinfo: %s %s\n", realm, authinfo->realm));
      if ((authinfo->realm == NULL || authinfo->realm[0] == '\0') && fallback==NULL)
        {
          fallback = authinfo;
      } else if (strcmp (realm, authinfo->realm) == 0
                 || 0 == strncmp (realm + 1, authinfo->realm, strlen (realm) - 2))
        {
          return authinfo;
        }
    }

  return fallback;
}
Example #17
0
int
osip_dialog_update_route_set_as_uac (osip_dialog_t * dialog,
                                     osip_message_t * response)
{
  /* only the remote target URI is updated here... */
  osip_contact_t *contact;
  int i;

  if (dialog == NULL)
    return -1;
  if (response == NULL)
    return -1;

  if (osip_list_eol (&response->contacts, 0))
    {                           /* no contact header in response? */
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_WARNING, NULL,
                   "missing a contact in response!\n"));
  } else
    {
      /* I personally think it's a bad idea to keep the old
         value in case the new one is broken... */
      if (dialog->remote_contact_uri != NULL)
        {
          osip_contact_free (dialog->remote_contact_uri);
        }
      dialog->remote_contact_uri = NULL;
      contact = osip_list_get (&response->contacts, 0);
      i = osip_contact_clone (contact, &(dialog->remote_contact_uri));
      if (i != 0)
        return -1;
    }

  if (dialog->state == DIALOG_EARLY && osip_list_size (&dialog->route_set) == 0)
    {                           /* update the route set */
      int pos = 0;

      while (!osip_list_eol (&response->record_routes, pos))
        {
          osip_record_route_t *rr;
          osip_record_route_t *rr2;

          rr =
            (osip_record_route_t *) osip_list_get (&response->record_routes, pos);
          i = osip_record_route_clone (rr, &rr2);
          if (i != 0)
            return -1;
          osip_list_add (&dialog->route_set, rr2, 0);
          pos++;
        }
    }

  if (MSG_IS_STATUS_2XX (response))
    dialog->state = DIALOG_CONFIRMED;
  return 0;
}
Example #18
0
int SendMsg(osip_transaction_t *tr,osip_message_t *sip, char *host,int port, int out_socket)
{
	int len = 0;
	char *msgP;
	int msgLen;
	int i;
	int status;

	printf("SendMsg\n");

	if((i = osip_message_to_str(sip, &msgP, &msgLen)) != 0){
		OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_BUG,NULL,"failed to convert message\n"));
		return -1;
	}
	if(!networkMsgSend(sipSock,msgP,strlen(msgP),host,5080))
		OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO1,NULL,"Time: Udp message sent: \n%s\n",msgP));

	return 0;
}
Example #19
0
int
eXosip_subscribe_send_refresh_request (struct eXosip_t *excontext, int did, osip_message_t * sub)
{
  eXosip_dialog_t *jd = NULL;
  eXosip_subscribe_t *js = NULL;

  osip_transaction_t *transaction;
  osip_event_t *sipevent;
  int i;

  if (did <= 0)
    return OSIP_BADPARAMETER;

  if (did > 0) {
    _eXosip_subscribe_dialog_find (excontext, did, &js, &jd);
  }
  if (jd == NULL) {
    OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: No subscribe here?\n"));
    osip_message_free (sub);
    return OSIP_NOTFOUND;
  }

  transaction = NULL;
  transaction = _eXosip_find_last_out_subscribe (js, jd);

  if (transaction != NULL) {
    if (transaction->state != NICT_TERMINATED && transaction->state != NIST_TERMINATED && transaction->state != NICT_COMPLETED && transaction->state != NIST_COMPLETED) {
      osip_message_free (sub);
      return OSIP_WRONG_STATE;
    }
    transaction = NULL;
  }

  transaction = NULL;
  i = _eXosip_transaction_init (excontext, &transaction, NICT, excontext->j_osip, sub);

  if (i != 0) {
    osip_message_free (sub);
    return i;
  }

  js->s_reg_period = 3600;
  _eXosip_subscribe_set_refresh_interval (js, sub);
  osip_list_add (jd->d_out_trs, transaction, 0);

  sipevent = osip_new_outgoing_sipmessage (sub);
  sipevent->transactionid = transaction->transactionid;

  osip_transaction_set_reserved5 (transaction, js);
  osip_transaction_set_reserved3 (transaction, jd);

  osip_transaction_add_event (transaction, sipevent);
  _eXosip_wakeup (excontext);
  return OSIP_SUCCESS;
}
Example #20
0
int
__osip_nist_free (osip_nist_t * nist)
{
  if (nist == NULL)
    return -1;
  OSIP_TRACE (osip_trace
              (__FILE__, __LINE__, OSIP_INFO2, NULL, "free nist ressource\n"));

  osip_free (nist);
  return 0;
}
Example #21
0
int
eXosip_remove_transaction_from_call (osip_transaction_t * tr, eXosip_call_t * jc)
{
  osip_transaction_t *inc_tr;
  osip_transaction_t *out_tr;
  eXosip_dialog_t *jd;
  int pos = 0;

  if (jc->c_inc_tr == tr)
    {
      jc->c_inc_tr = NULL;      /* can be NULL */
      return 0;
    }

  for (jd = jc->c_dialogs; jd != NULL; jd = jd->next)
    {
      pos = 0;
      while (!osip_list_eol (jd->d_inc_trs, pos))
        {
          inc_tr = osip_list_get (jd->d_inc_trs, pos);
          if (inc_tr == tr)
            {
              osip_list_remove (jd->d_inc_trs, pos);
              return 0;
            }
          pos++;
        }
    }

  if (jc->c_out_tr == tr)
    {
      jc->c_out_tr = NULL;      /* can be NULL */
      return 0;
    }

  for (jd = jc->c_dialogs; jd != NULL; jd = jd->next)
    {
      pos = 0;
      while (!osip_list_eol (jd->d_out_trs, pos))
        {
          out_tr = osip_list_get (jd->d_out_trs, pos);
          if (out_tr == tr)
            {
              osip_list_remove (jd->d_out_trs, pos);
              return 0;
            }
          pos++;
        }
    }

  OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL,
                          "eXosip: No information.\n"));
  return -1;
}
Example #22
0
int
find_next_crlfcrlf (char *start_of_part, char **end_of_part)
{
  char *start_of_line;
  char *end_of_line;
  int i;

  start_of_line = start_of_part;

  for (;;)
    {
      i = find_next_crlf (start_of_line, &end_of_line);
      if (i == -1)
	{			/* error case??? no end of mesage found */
	  OSIP_TRACE (osip_trace
		      (__FILE__, __LINE__, OSIP_ERROR, NULL,
		       "Final CRLF is missing\n"));
	  return -1;
	}
      if ('\0' == end_of_line[0])
	{			/* error case??? no end of message found */
	  OSIP_TRACE (osip_trace
		      (__FILE__, __LINE__, OSIP_ERROR, NULL,
		       "Final CRLF is missing\n"));
	  return -1;
	}
      else if ('\r' == end_of_line[0])
	{
	  if ('\n' == end_of_line[1])
	    end_of_line++;
	  *end_of_part = end_of_line + 1;
	  return 0;
	}
      else if ('\n' == end_of_line[0])
	{
	  *end_of_part = end_of_line + 1;
	  return 0;
	}
      start_of_line = end_of_line;
    }
}
static int
__osip_message_startline_to_str (osip_message_t * sip, char **dest)
{

  if (sip->sip_method != NULL)
    return __osip_message_startline_to_strreq (sip, dest);
  if (sip->status_code != 0)
    return __osip_message_startline_to_strresp (sip, dest);

  OSIP_TRACE (osip_trace (__FILE__, __LINE__, TRACE_LEVEL1, NULL, "ERROR method has no value or status code is 0!\n"));
  return OSIP_BADPARAMETER;     /* should never come here */
}
int __osip_find_next_crlf(const char *start_of_header, const char **end_of_header)
{
	const char *soh = start_of_header;

	*end_of_header = NULL;		/* AMD fix */

	while (('\r' != *soh) && ('\n' != *soh)) {
		if (*soh)
			soh++;
		else {
			OSIP_TRACE(osip_trace
					   (__FILE__, __LINE__, OSIP_ERROR, NULL,
						"Final CRLF is missing\n"));
			return OSIP_SYNTAXERROR;
		}
	}

	if (('\r' == soh[0]) && ('\n' == soh[1]))
		/* case 1: CRLF is the separator
		   case 2 or 3: CR or LF is the separator */
		soh = soh + 1;


	/* VERIFY if TMP is the end of header or LWS.            */
	/* LWS are extra SP, HT, CR and LF contained in headers. */
	if ((' ' == soh[1]) || ('\t' == soh[1])) {
		/* From now on, incoming message that potentially
		   contains LWS must be processed with
		   -> void osip_util_replace_all_lws(char *)
		   This is because the parser methods does not
		   support detection of LWS inside. */
		OSIP_TRACE(osip_trace
				   (__FILE__, __LINE__, OSIP_BUG, NULL,
					"Message that contains LWS must be processed with osip_util_replace_all_lws(char *tmp) before being parsed.\n"));
		return -2;
	}

	*end_of_header = soh + 1;
	return OSIP_SUCCESS;
}
Example #25
0
int
eXosip_notify_init (eXosip_notify_t ** jn, osip_message_t * inc_subscribe)
{
  osip_contact_t *co;
  char *uri;
  int i;
  char locip[50];

#ifdef SM
  eXosip_get_localip_from_via (inc_subscribe, locip, 49);
#else
  i = _eXosip_find_protocol (inc_subscribe);
  if (i == IPPROTO_UDP)
    {
      eXosip_guess_ip_for_via (eXosip.net_interfaces[0].net_ip_family, locip, 49);
  } else if (i == IPPROTO_TCP)
    {
      eXosip_guess_ip_for_via (eXosip.net_interfaces[1].net_ip_family, locip, 49);
  } else
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: unsupported protocol (default to UDP)\n"));
      eXosip_guess_ip_for_via (eXosip.net_interfaces[0].net_ip_family, locip, 49);
      return -1;
    }

#endif
  if (inc_subscribe == NULL
      || inc_subscribe->to == NULL || inc_subscribe->to->url == NULL)
    return -1;
  co = (osip_contact_t *) osip_list_get (inc_subscribe->contacts, 0);
  if (co == NULL || co->url == NULL)
    return -1;

  *jn = (eXosip_notify_t *) osip_malloc (sizeof (eXosip_notify_t));
  if (*jn == NULL)
    return -1;
  memset (*jn, 0, sizeof (eXosip_notify_t));

  i = osip_uri_to_str (co->url, &uri);
  if (i != 0)
    {
      osip_free (*jn);
      *jn = NULL;
      return -1;
    }
  osip_strncpy ((*jn)->n_uri, uri, 254);
  osip_free (uri);

  return 0;
}
Example #26
0
int
eXosip_answer_options_1xx(eXosip_call_t *jc, eXosip_dialog_t *jd, int code)
{
  osip_event_t *evt_answer;
  osip_transaction_t *tr;
  osip_message_t *response;
  int i;

  tr = eXosip_find_last_inc_options(jc, jd);
  if (tr==NULL)
    {
      OSIP_TRACE (osip_trace
		  (__FILE__, __LINE__, OSIP_ERROR, NULL,
         "eXosip: cannot find transaction to answer"));
      return -1;
    }

  if (jd!=NULL)
    {
      i = _eXosip_build_response_default(&response, jd->d_dialog, code, tr->orig_request);
    }
  else
    {
      i = _eXosip_build_response_default(&response, NULL, code, tr->orig_request);
    }

  if (i!=0)
    {
      OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_ERROR,NULL,"ERROR: Could not create response for OPTIONS\n"));
      return -1;
    }

  evt_answer = osip_new_outgoing_sipmessage(response);
  evt_answer->transactionid = tr->transactionid;

  osip_transaction_add_event(tr, evt_answer);
  __eXosip_wakeup();
  return 0;
}
Example #27
0
/* This method calls the method that is able to parse the header */
int
__osip_message_call_method (int i, osip_message_t * dest, const char *hvalue)
{
  int err;

  err = pconfig[i].setheader (dest, hvalue);
  if (err < 0) {
    OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_WARNING, NULL, "Could not set header: %s: %s\n", pconfig[i].hname, hvalue));
  }
  if (pconfig[i].ignored_when_invalid == 1)
    return OSIP_SUCCESS;
  return err;
}
Example #28
0
static int
_eXosip_redirect (eXosip_event_t * je)
{
  switch (je->type)
    {
      case EXOSIP_CALL_REDIRECTED:
        return _eXosip_redirect_invite (je);

      case EXOSIP_CALL_MESSAGE_REDIRECTED:
      case EXOSIP_MESSAGE_REDIRECTED:
      case EXOSIP_SUBSCRIPTION_REDIRECTED:
        OSIP_TRACE (osip_trace
                    (__FILE__, __LINE__, OSIP_ERROR, NULL,
                     "eXosip: not implemented\n"));
        return -1;

      default:
        OSIP_TRACE (osip_trace
                    (__FILE__, __LINE__, OSIP_ERROR, NULL,
                     "eXosip: Can't redirect event %d\n", je->type));
        return -1;
    }
}
Example #29
0
PPL_DECLARE (ppl_pipe_t *) ppl_pipe ()
{
	ppl_pipe_t *my_pipe;
	int i;

	my_pipe = (ppl_pipe_t *) osip_malloc (sizeof (ppl_pipe_t));
	if (my_pipe==NULL)
	{
		OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL,
			"Failed to allocate pipe!\n"));
		return NULL;
	}

	i = CreatePipe(my_pipe->pipes[0], my_pipe->pipes[1], NULL, 0);
	if (i!=0)
	{
	  OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL,
				  "Failed to create pipe!\n"));
      osip_free (my_pipe);
	  return NULL;
	}
	return my_pipe;
}
Example #30
0
void
eXosip_reg_free (eXosip_reg_t * jreg)
{

  osip_free (jreg->r_aor);
  osip_free (jreg->r_contact);
  osip_free (jreg->r_registrar);

  if (jreg->r_last_tr != NULL)
    {
	  if (jreg->r_last_tr!=NULL && jreg->r_last_tr->orig_request!=NULL
		  && jreg->r_last_tr->orig_request->call_id!=NULL
		  && jreg->r_last_tr->orig_request->call_id->number!=NULL)
		  _eXosip_delete_nonce(jreg->r_last_tr->orig_request->call_id->number);

      if (jreg->r_last_tr->state == IST_TERMINATED ||
          jreg->r_last_tr->state == ICT_TERMINATED ||
          jreg->r_last_tr->state == NICT_TERMINATED ||
          jreg->r_last_tr->state == NIST_TERMINATED)
        {
          OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL,
                                  "Release a terminated transaction\n"));
          __eXosip_delete_jinfo (jreg->r_last_tr);
          if (jreg->r_last_tr != NULL)
            osip_list_add (eXosip.j_transactions, jreg->r_last_tr, 0);
      } else
        {
          OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL,
                                  "Release a non-terminated transaction\n"));
          __eXosip_delete_jinfo (jreg->r_last_tr);
          if (jreg->r_last_tr != NULL)
            osip_list_add (eXosip.j_transactions, jreg->r_last_tr, 0);
        }
    }

  osip_free (jreg);
}