Exemple #1
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 */
    }
  }
Exemple #2
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);
}
Exemple #3
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);
}
Exemple #4
0
int
__osip_ist_init (osip_ist_t ** ist, osip_t * osip, osip_message_t * invite)
{
  int i;

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

  *ist = (osip_ist_t *) osip_malloc (sizeof (osip_ist_t));
  if (*ist == NULL)
    return OSIP_NOMEM;
  memset (*ist, 0, sizeof (osip_ist_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 (*ist);
      *ist = NULL;
      return i;
    }
    proto = via_get_protocol (via);
    if (proto == NULL) {
      osip_free (*ist);
      *ist = NULL;
      return OSIP_UNDEFINED_ERROR;
    }

    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 */
      (*ist)->timer_g_length = DEFAULT_T1;
      (*ist)->timer_i_length = DEFAULT_T4;
      (*ist)->timer_g_start.tv_sec = -1;        /* not started */
      (*ist)->timer_i_start.tv_sec = -1;        /* not started */
    }
    else {                      /* reliable protocol is used: */
      (*ist)->timer_g_length = -1;      /* A is not ACTIVE */
      (*ist)->timer_i_length = 0;       /* MUST do the transition immediatly */
      (*ist)->timer_g_start.tv_sec = -1;        /* not started */
      (*ist)->timer_i_start.tv_sec = -1;        /* not started */
    }
  }

  (*ist)->timer_h_length = 64 * DEFAULT_T1;
  (*ist)->timer_h_start.tv_sec = -1;    /* not started */

  return OSIP_SUCCESS;
}
Exemple #5
0
void ict_snd_invite(osip_transaction_t * ict, osip_event_t * evt)
{
	int i;
	osip_t *osip = (osip_t *) ict->config;

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

	i = osip->cb_send_message(ict, evt->sip, 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

	__osip_message_callback(OSIP_ICT_INVITE_SENT, ict, ict->orig_request);
	__osip_transaction_set_state(ict, ICT_CALLING);
}
Exemple #6
0
int
__osip_nist_init (osip_nist_t ** nist, osip_t * osip, osip_message_t * invite)
{
  int i;

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

  *nist = (osip_nist_t *) osip_malloc (sizeof (osip_nist_t));
  if (*nist == NULL)
    return -1;
  memset (*nist, 0, sizeof (osip_nist_t));
  /* for INVITE retransmissions */
  {
    osip_via_t *via;
    char *proto;

    i = osip_message_get_via (invite, 0, &via); /* get top via */
    if (i != 0)
      goto ii_error_1;
    proto = via_get_protocol (via);
    if (proto == NULL)
      goto ii_error_1;

    if (osip_strcasecmp (proto, "TCP") != 0
        && osip_strcasecmp (proto, "TLS") != 0
        && osip_strcasecmp (proto, "SCTP") != 0)
      {
        (*nist)->timer_j_length = 64 * DEFAULT_T1;
        (*nist)->timer_j_start.tv_sec = -1;     /* not started */
    } else
      {                         /* reliable protocol is used: */
        (*nist)->timer_j_length = 0;    /* MUST do the transition immediatly */
        (*nist)->timer_j_start.tv_sec = -1;     /* not started */
      }
  }

  return 0;

ii_error_1:
  osip_free (*nist);
  return -1;
}
Exemple #7
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);
  }
}
Exemple #8
0
int
__osip_nict_init (osip_nict_t ** nict, osip_t * osip, osip_message_t * request)
{
  osip_route_t *route;
  int i;
  time_t now;

  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 -1;
  now = time (NULL);
#ifndef DISABLE_MEMSET
  memset (*nict, 0, sizeof (osip_nict_t));
#else
  (*ict)->destination = NULL;
#endif
  /* for REQUEST retransmissions */
  {
    osip_via_t *via;
    char *proto;

    i = osip_message_get_via (request, 0, &via);	/* get top via */
    if (i != 0)
      goto ii_error_1;
    proto = via_get_protocol (via);
    if (proto == NULL)
      goto ii_error_1;

    i = osip_strncasecmp (proto, "TCP", 3);
    if (i != 0)
      {				/* for other reliable protocol than TCP, the timer
				   must be desactived by the external application */
	(*nict)->timer_e_length = DEFAULT_T1;
	(*nict)->timer_e_start = now;	/* started */

	(*nict)->timer_k_length = DEFAULT_T4;
	(*nict)->timer_k_start = -1;	/* not started */
      }
    else
      {				/* TCP is used: */
	(*nict)->timer_e_length = -1;	/* E is not ACTIVE */
	(*nict)->timer_e_start = -1;

	(*nict)->timer_k_length = 0;	/* MUST do the transition immediatly */
	(*nict)->timer_k_start = -1;	/* not started */
      }
  }

  /* for PROXY, the destination MUST be set by the application layer,
     this one may not be correct. */
  osip_message_get_route (request, 0, &route);
  if (route != NULL)
    {
      int port = 5060;

      if (route->url->port != NULL)
	port = osip_atoi (route->url->port);
      osip_nict_set_destination ((*nict), osip_strdup (route->url->host), port);
    }
  else
    (*nict)->port = 5060;

  (*nict)->timer_f_length = 64 * DEFAULT_T1;
  (*nict)->timer_f_start = now;	/* started */

  /* Oups! a Bug! */
  /*  (*nict)->port  = 5060; */

  return 0;

ii_error_1:
  osip_free (*nict);
  return -1;
}
Exemple #9
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 */
    }
  }