void
ist_snd_3456xx (osip_transaction_t * ist, osip_event_t * evt)
{
  int i;

  if (ist->last_response != NULL) {
    osip_message_free (ist->last_response);
  }
  ist->last_response = evt->sip;

  i = __osip_transaction_snd_xxx (ist, evt->sip);
  if (i != 0) {
    ist_handle_transport_error (ist, i);
    return;
  }
  else {
    if (MSG_IS_STATUS_3XX (ist->last_response))
      __osip_message_callback (OSIP_IST_STATUS_3XX_SENT, ist, ist->last_response);
    else if (MSG_IS_STATUS_4XX (ist->last_response))
      __osip_message_callback (OSIP_IST_STATUS_4XX_SENT, ist, ist->last_response);
    else if (MSG_IS_STATUS_5XX (ist->last_response))
      __osip_message_callback (OSIP_IST_STATUS_5XX_SENT, ist, ist->last_response);
    else
      __osip_message_callback (OSIP_IST_STATUS_6XX_SENT, ist, ist->last_response);
  }

  if (ist->ist_context->timer_g_length != -1) {
    osip_gettimeofday (&ist->ist_context->timer_g_start, NULL);
    add_gettimeofday (&ist->ist_context->timer_g_start, ist->ist_context->timer_g_length);
  }
  osip_gettimeofday (&ist->ist_context->timer_h_start, NULL);
  add_gettimeofday (&ist->ist_context->timer_h_start, ist->ist_context->timer_h_length);
  __osip_transaction_set_state (ist, IST_COMPLETED);
  return;
}
Пример #2
0
void
nict_rcv_23456xx (osip_transaction_t * nict, osip_event_t * evt)
{
  /* leave this answer to the core application */

  if (nict->last_response != NULL)
    {
      osip_message_free (nict->last_response);
    }
  nict->last_response = evt->sip;

  if (EVT_IS_RCV_STATUS_2XX (evt))
    __osip_message_callback (OSIP_NICT_STATUS_2XX_RECEIVED, nict,
                             nict->last_response);
  else if (MSG_IS_STATUS_3XX (nict->last_response))
    __osip_message_callback (OSIP_NICT_STATUS_3XX_RECEIVED, nict,
                             nict->last_response);
  else if (MSG_IS_STATUS_4XX (nict->last_response))
    __osip_message_callback (OSIP_NICT_STATUS_4XX_RECEIVED, nict,
                             nict->last_response);
  else if (MSG_IS_STATUS_5XX (nict->last_response))
    __osip_message_callback (OSIP_NICT_STATUS_5XX_RECEIVED, nict,
                             nict->last_response);
  else
    __osip_message_callback (OSIP_NICT_STATUS_6XX_RECEIVED, nict,
                             nict->last_response);

  if (nict->state != NICT_COMPLETED)    /* reset timer K */
    {
      osip_gettimeofday (&nict->nict_context->timer_k_start, NULL);
      add_gettimeofday (&nict->nict_context->timer_k_start,
                        nict->nict_context->timer_k_length);
    }
  __osip_transaction_set_state (nict, NICT_COMPLETED);
}
Пример #3
0
void
osip_nict_timeout_e_event (osip_transaction_t * nict, osip_event_t * evt)
{
  osip_t *osip = (osip_t *) nict->config;
  int i;

  /* reset timer */
  if (nict->state == NICT_TRYING)
    {
      nict->nict_context->timer_e_length = nict->nict_context->timer_e_length * 2;
      if (nict->nict_context->timer_e_length > 4000)
        nict->nict_context->timer_e_length = 4000;
  } else                        /* in PROCEEDING STATE, TIMER is always 4000 */
    nict->nict_context->timer_e_length = 4000;

  osip_gettimeofday (&nict->nict_context->timer_e_start, NULL);
  add_gettimeofday (&nict->nict_context->timer_e_start,
                    nict->nict_context->timer_e_length);

  /* retransmit REQUEST */
  i = osip->cb_send_message (nict, nict->orig_request,
                             nict->nict_context->destination,
                             nict->nict_context->port, nict->out_socket);
  if (i != 0)
    {
      nict_handle_transport_error (nict, i);
      return;
    }
  __osip_message_callback (OSIP_NICT_REQUEST_SENT_AGAIN, nict, nict->orig_request);
}
Пример #4
0
void
osip_nict_timeout_e_event (osip_transaction_t * nict, osip_event_t * evt)
{
  osip_t *osip = (osip_t *) nict->config;
  int i;

  /* reset timer */
  if (nict->state == NICT_TRYING) {
    if (nict->nict_context->timer_e_length < DEFAULT_T1)
      nict->nict_context->timer_e_length = nict->nict_context->timer_e_length + DEFAULT_T1_TCP_PROGRESS;
    else
      nict->nict_context->timer_e_length = nict->nict_context->timer_e_length * 2;
    if (nict->nict_context->timer_e_length > DEFAULT_T2)
      nict->nict_context->timer_e_length = DEFAULT_T2;
  }
  else                          /* in PROCEEDING STATE, TIMER is always DEFAULT_T2 */
    nict->nict_context->timer_e_length = DEFAULT_T2;

  osip_gettimeofday (&nict->nict_context->timer_e_start, NULL);
  add_gettimeofday (&nict->nict_context->timer_e_start, nict->nict_context->timer_e_length);

  /* retransmit REQUEST */
  i = osip->cb_send_message (nict, nict->orig_request, nict->nict_context->destination, nict->nict_context->port, nict->out_socket);
  if (i < 0) {
    nict_handle_transport_error (nict, i);
    return;
  }
#ifndef USE_BLOCKINGSOCKET
  /*
     stop timer E in reliable transport - non blocking socket: 
     the message was just sent
   */
  if (i == 0) {                 /* but message was really sent */
    osip_via_t *via;
    char *proto;

    i = osip_message_get_via (nict->orig_request, 0, &via);     /* get top via */
    if (i < 0) {
      nict_handle_transport_error (nict, -1);
      return;
    }
    proto = via_get_protocol (via);
    if (proto == NULL) {
      nict_handle_transport_error (nict, -1);
      return;
    }
    if (osip_strcasecmp (proto, "TCP") != 0 && osip_strcasecmp (proto, "TLS") != 0 && osip_strcasecmp (proto, "SCTP") != 0) {
    }
    else {                      /* reliable protocol is used: */
      nict->nict_context->timer_e_length = -1;  /* E is not ACTIVE */
      nict->nict_context->timer_e_start.tv_sec = -1;
    }
  }
#endif
  if (i == 0)                   /* but message was really sent */
    __osip_message_callback (OSIP_NICT_REQUEST_SENT_AGAIN, nict, nict->orig_request);
}
Пример #5
0
void osip_ict_timeout_a_event(osip_transaction_t * ict, osip_event_t * evt)
{
	osip_t *osip = (osip_t *) ict->config;
	int i;

	/* reset timer */
	ict->ict_context->timer_a_length = ict->ict_context->timer_a_length * 2;
	osip_gettimeofday(&ict->ict_context->timer_a_start, NULL);
	add_gettimeofday(&ict->ict_context->timer_a_start,
					 ict->ict_context->timer_a_length);

	/* retransmit REQUEST */
	i = osip->cb_send_message(ict, ict->orig_request,
							  ict->ict_context->destination,
							  ict->ict_context->port, ict->out_socket);
	if (i < 0) {
		ict_handle_transport_error(ict, i);
		return;
	}
#ifndef USE_BLOCKINGSOCKET
	/*
	   stop timer E in reliable transport - non blocking socket: 
	   the message was just sent
	 */
	if (i == 0) {				/* but message was really sent */
		osip_via_t *via;
		char *proto;

		i = osip_message_get_via(ict->orig_request, 0, &via);	/* get top via */
		if (i < 0) {
			ict_handle_transport_error(ict, i);
			return;
		}
		proto = via_get_protocol(via);
		if (proto == NULL) {
			ict_handle_transport_error(ict, i);
			return;
		}
		if (osip_strcasecmp(proto, "TCP") != 0
			&& osip_strcasecmp(proto, "TLS") != 0
			&& osip_strcasecmp(proto, "SCTP") != 0) {
		} else {				/* reliable protocol is used: */
			ict->ict_context->timer_a_length = -1;	/* A is not ACTIVE */
			ict->ict_context->timer_a_start.tv_sec = -1;
		}
	}
#endif

	if (i == 0)
		__osip_message_callback(OSIP_ICT_INVITE_SENT_AGAIN, ict,
								ict->orig_request);
}
void
ist_rcv_ack (osip_transaction_t * ist, osip_event_t * evt)
{
  if (ist->ack != NULL) {
    osip_message_free (ist->ack);
  }

  ist->ack = evt->sip;

  if (ist->state == IST_COMPLETED)
    __osip_message_callback (OSIP_IST_ACK_RECEIVED, ist, ist->ack);
  else                          /* IST_CONFIRMED */
    __osip_message_callback (OSIP_IST_ACK_RECEIVED_AGAIN, ist, ist->ack);
  /* set the timer to 0 for reliable, and T4 for unreliable (already set) */
  osip_gettimeofday (&ist->ist_context->timer_i_start, NULL);
  add_gettimeofday (&ist->ist_context->timer_i_start, ist->ist_context->timer_i_length);
  __osip_transaction_set_state (ist, IST_CONFIRMED);
}
void
osip_ist_timeout_g_event (osip_transaction_t * ist, osip_event_t * evt)
{
  int i;

  ist->ist_context->timer_g_length = ist->ist_context->timer_g_length * 2;
  if (ist->ist_context->timer_g_length > 4000)
    ist->ist_context->timer_g_length = 4000;
  osip_gettimeofday (&ist->ist_context->timer_g_start, NULL);
  add_gettimeofday (&ist->ist_context->timer_g_start, ist->ist_context->timer_g_length);

  i = __osip_transaction_snd_xxx (ist, ist->last_response);
  if (i != 0) {
    ist_handle_transport_error (ist, i);
    return;
  }
  __osip_message_callback (OSIP_IST_STATUS_3456XX_SENT_AGAIN, ist, ist->last_response);
}
Пример #8
0
void
nist_snd_23456xx (osip_transaction_t * nist, osip_event_t * evt)
{
  int i;

  if (nist->last_response != NULL)
    {
      osip_message_free (nist->last_response);
    }
  nist->last_response = evt->sip;

  i = __osip_transaction_snd_xxx(nist, nist->last_response);
  if (i != 0)
    {
      nist_handle_transport_error (nist, i);
      return;
  } else
    {
      if (EVT_IS_SND_STATUS_2XX (evt))
        __osip_message_callback (OSIP_NIST_STATUS_2XX_SENT, nist,
                                 nist->last_response);
      else if (MSG_IS_STATUS_3XX (nist->last_response))
        __osip_message_callback (OSIP_NIST_STATUS_3XX_SENT, nist,
                                 nist->last_response);
      else if (MSG_IS_STATUS_4XX (nist->last_response))
        __osip_message_callback (OSIP_NIST_STATUS_4XX_SENT, nist,
                                 nist->last_response);
      else if (MSG_IS_STATUS_5XX (nist->last_response))
        __osip_message_callback (OSIP_NIST_STATUS_5XX_SENT, nist,
                                 nist->last_response);
      else
        __osip_message_callback (OSIP_NIST_STATUS_6XX_SENT, nist,
                                 nist->last_response);
    }

  if (nist->state != NIST_COMPLETED)    /* start J timer */
    {
      osip_gettimeofday (&nist->nist_context->timer_j_start, NULL);
      add_gettimeofday (&nist->nist_context->timer_j_start,
                        nist->nist_context->timer_j_length);
    }

  __osip_transaction_set_state (nist, NIST_COMPLETED);
}
Пример #9
0
void
nict_rcv_1xx (osip_transaction_t * nict, osip_event_t * evt)
{
  /* leave this answer to the core application */

  if (nict->last_response != NULL) {
    osip_message_free (nict->last_response);
  }
  nict->last_response = evt->sip;

  /* for unreliable transport increase the retransmission timeout */
  if (nict->nict_context->timer_e_length > 0) {
    nict->nict_context->timer_e_length = DEFAULT_T2;
    osip_gettimeofday (&nict->nict_context->timer_e_start, NULL);
    add_gettimeofday (&nict->nict_context->timer_e_start, nict->nict_context->timer_e_length);
  }

  __osip_message_callback (OSIP_NICT_STATUS_1XX_RECEIVED, nict, evt->sip);
  __osip_transaction_set_state (nict, NICT_PROCEEDING);
}
Пример #10
0
void
nict_snd_request (osip_transaction_t * nict, osip_event_t * evt)
{
  int i;
  osip_t *osip = (osip_t *) nict->config;

  /* Here we have ict->orig_request == NULL */
  nict->orig_request = evt->sip;

  i = osip->cb_send_message (nict, evt->sip, nict->nict_context->destination, nict->nict_context->port, nict->out_socket);

  if (i >= 0) {
    /* invoke the right callback! */
    if (MSG_IS_REGISTER (evt->sip))
      __osip_message_callback (OSIP_NICT_REGISTER_SENT, nict, nict->orig_request);
    else if (MSG_IS_BYE (evt->sip))
      __osip_message_callback (OSIP_NICT_BYE_SENT, nict, nict->orig_request);
    else if (MSG_IS_OPTIONS (evt->sip))
      __osip_message_callback (OSIP_NICT_OPTIONS_SENT, nict, nict->orig_request);
    else if (MSG_IS_INFO (evt->sip))
      __osip_message_callback (OSIP_NICT_INFO_SENT, nict, nict->orig_request);
    else if (MSG_IS_CANCEL (evt->sip))
      __osip_message_callback (OSIP_NICT_CANCEL_SENT, nict, nict->orig_request);
    else if (MSG_IS_NOTIFY (evt->sip))
      __osip_message_callback (OSIP_NICT_NOTIFY_SENT, nict, nict->orig_request);
    else if (MSG_IS_SUBSCRIBE (evt->sip))
      __osip_message_callback (OSIP_NICT_SUBSCRIBE_SENT, nict, nict->orig_request);
    else
      __osip_message_callback (OSIP_NICT_UNKNOWN_REQUEST_SENT, nict, nict->orig_request);
#ifndef USE_BLOCKINGSOCKET
    /*
       stop timer E in reliable transport - non blocking socket: 
       the message was just sent
     */
    {
      osip_via_t *via;
      char *proto;
      int k;
      k = osip_message_get_via (nict->orig_request, 0, &via);   /* get top via */
      if (k < 0) {
        nict_handle_transport_error (nict, -1);
        return;
      }
      proto = via_get_protocol (via);
      if (proto == NULL) {
        nict_handle_transport_error (nict, -1);
        return;
      }
      if (i == 0) {               /* but message was really sent */
        if (osip_strcasecmp (proto, "TCP") != 0 && osip_strcasecmp (proto, "TLS") != 0 && osip_strcasecmp (proto, "SCTP") != 0) {
        }
        else {                    /* reliable protocol is used: */
          nict->nict_context->timer_e_length = -1;        /* E is not ACTIVE */
          nict->nict_context->timer_e_start.tv_sec = -1;
        }
      } else {
        if (osip_strcasecmp (proto, "TCP") != 0 && osip_strcasecmp (proto, "TLS") != 0 && osip_strcasecmp (proto, "SCTP") != 0) {
        }
        else {                    /* reliable protocol is used: */
          nict->nict_context->timer_e_length = DEFAULT_T1_TCP_PROGRESS;
        }
      }
    }
#endif
    if (nict->nict_context->timer_e_length > 0) {
      osip_gettimeofday (&nict->nict_context->timer_e_start, NULL);
      add_gettimeofday (&nict->nict_context->timer_e_start, nict->nict_context->timer_e_length);
    }
    __osip_transaction_set_state (nict, NICT_TRYING);
  }
  else {
    nict_handle_transport_error (nict, i);
  }
}
Пример #11
0
void ict_rcv_3456xx(osip_transaction_t * ict, osip_event_t * evt)
{
	osip_route_t *route;
	int i;
	osip_t *osip = (osip_t *) ict->config;

	/* leave this answer to the core application */

	if (ict->last_response != NULL)
		osip_message_free(ict->last_response);

	ict->last_response = evt->sip;
	if (ict->state != ICT_COMPLETED) {	/* not a retransmission */
		/* automatic handling of ack! */
		osip_message_t *ack = ict_create_ack(ict, evt->sip);

		ict->ack = ack;

		if (ict->ack == NULL) {
			__osip_transaction_set_state(ict, ICT_TERMINATED);
			__osip_kill_transaction_callback(OSIP_ICT_KILL_TRANSACTION, ict);
			return;
		}

		/* reset ict->ict_context->destination only if
		   it is not yet set. */
		if (ict->ict_context->destination == NULL) {
			osip_message_get_route(ack, 0, &route);
			if (route != NULL && route->url != NULL) {
				osip_uri_param_t *lr_param;

				osip_uri_uparam_get_byname(route->url, "lr", &lr_param);
				if (lr_param == NULL) {
					/* using uncompliant proxy: destination is the request-uri */
					route = NULL;
				}
			}

			if (route != NULL && route->url != NULL) {
				int port = 5060;

				if (route->url->port != NULL)
					port = osip_atoi(route->url->port);
				osip_ict_set_destination(ict->ict_context,
										 osip_strdup(route->url->host), port);
			} else {
				int port = 5060;
				/* search for maddr parameter */
				osip_uri_param_t *maddr_param = NULL;

				port = 5060;
				if (ack->req_uri->port != NULL)
					port = osip_atoi(ack->req_uri->port);

				osip_uri_uparam_get_byname(ack->req_uri, "maddr", &maddr_param);
				if (maddr_param != NULL && maddr_param->gvalue != NULL)
					osip_ict_set_destination(ict->ict_context,
											 osip_strdup(maddr_param->gvalue),
											 port);
				else
					osip_ict_set_destination(ict->ict_context,
											 osip_strdup(ack->req_uri->host),
											 port);
			}
		}
		i = osip->cb_send_message(ict, ack, ict->ict_context->destination,
								  ict->ict_context->port, ict->out_socket);
		if (i != 0) {
			ict_handle_transport_error(ict, i);
			return;
		}
		if (MSG_IS_STATUS_3XX(evt->sip))
			__osip_message_callback(OSIP_ICT_STATUS_3XX_RECEIVED, ict, evt->sip);
		else if (MSG_IS_STATUS_4XX(evt->sip))
			__osip_message_callback(OSIP_ICT_STATUS_4XX_RECEIVED, ict, evt->sip);
		else if (MSG_IS_STATUS_5XX(evt->sip))
			__osip_message_callback(OSIP_ICT_STATUS_5XX_RECEIVED, ict, evt->sip);
		else
			__osip_message_callback(OSIP_ICT_STATUS_6XX_RECEIVED, ict, evt->sip);

		__osip_message_callback(OSIP_ICT_ACK_SENT, ict, evt->sip);
	}

	/* start timer D (length is set to MAX (64*DEFAULT_T1 or 32000) */
	osip_gettimeofday(&ict->ict_context->timer_d_start, NULL);
	add_gettimeofday(&ict->ict_context->timer_d_start,
					 ict->ict_context->timer_d_length);
	__osip_transaction_set_state(ict, ICT_COMPLETED);
}
Пример #12
0
int
__osip_ict_init (osip_ict_t ** ict, osip_t * osip, osip_message_t * invite)
{
  osip_route_t *route;
  int i;

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

  *ict = (osip_ict_t *) osip_malloc (sizeof (osip_ict_t));
  if (*ict == NULL)
    return OSIP_NOMEM;

  memset (*ict, 0, sizeof (osip_ict_t));
  /* for INVITE retransmissions */
  {
    osip_via_t *via;
    char *proto;

    i = osip_message_get_via (invite, 0, &via); /* get top via */
    if (i < 0) {
      osip_free (*ict);
      return i;
    }
    proto = via_get_protocol (via);
    if (proto == NULL) {
      osip_free (*ict);
      return OSIP_SYNTAXERROR;
    }
#ifdef USE_BLOCKINGSOCKET
    if (osip_strcasecmp (proto, "TCP") != 0 && osip_strcasecmp (proto, "TLS") != 0 && osip_strcasecmp (proto, "SCTP") != 0) {   /* for other reliable protocol than TCP, the timer
                                                                                                                                   must be desactived by the external application */
      (*ict)->timer_a_length = DEFAULT_T1;
      if (64 * DEFAULT_T1 < 32000)
        (*ict)->timer_d_length = 32000;
      else
        (*ict)->timer_d_length = 64 * DEFAULT_T1;
      osip_gettimeofday (&(*ict)->timer_a_start, NULL);
      add_gettimeofday (&(*ict)->timer_a_start, (*ict)->timer_a_length);
      (*ict)->timer_d_start.tv_sec = -1;        /* not started */
    }
    else {                      /* reliable protocol is used: */
      (*ict)->timer_a_length = -1;      /* A is not ACTIVE */
      (*ict)->timer_d_length = 0;       /* MUST do the transition immediatly */
      (*ict)->timer_a_start.tv_sec = -1;        /* not started */
      (*ict)->timer_d_start.tv_sec = -1;        /* not started */
    }
  }
#else
    if (osip_strcasecmp (proto, "TCP") != 0 && osip_strcasecmp (proto, "TLS") != 0 && osip_strcasecmp (proto, "SCTP") != 0) {   /* for other reliable protocol than TCP, the timer
                                                                                                                                   must be desactived by the external application */
      (*ict)->timer_a_length = DEFAULT_T1;
      if (64 * DEFAULT_T1 < 32000)
        (*ict)->timer_d_length = 32000;
      else
        (*ict)->timer_d_length = 64 * DEFAULT_T1;
      osip_gettimeofday (&(*ict)->timer_a_start, NULL);
      add_gettimeofday (&(*ict)->timer_a_start, (*ict)->timer_a_length);
      (*ict)->timer_d_start.tv_sec = -1;        /* not started */
    }
    else {                      /* reliable protocol is used: */
      (*ict)->timer_a_length = DEFAULT_T1;
      (*ict)->timer_d_length = 0;       /* MUST do the transition immediatly */
      osip_gettimeofday (&(*ict)->timer_a_start, NULL);
      add_gettimeofday (&(*ict)->timer_a_start, (*ict)->timer_a_length);
      (*ict)->timer_d_start.tv_sec = -1;        /* not started */
    }
  }