int
sdp_message_a_attribute_del_at_index (sdp_message_t * sdp, int pos_media,
                                      char *att_field, int pos_attr)
{
  int i;
  sdp_media_t *med;
  sdp_attribute_t *attr;

  if (sdp == NULL)
    return -1;
  if ((pos_media != -1) && (osip_list_size (&sdp->m_medias) < pos_media + 1))
    return -1;
  if (pos_media == -1)
    {
      if (pos_attr == -1)
        {
          for (i = 0; i < osip_list_size (&sdp->a_attributes);)
            {
              attr = osip_list_get (&sdp->a_attributes, i);
              if (strcmp (attr->a_att_field, att_field) == 0)
                {
                  osip_list_remove (&sdp->a_attributes, i);
                  sdp_attribute_free (attr);
              } else
                i++;
            }
      } else if ((attr = osip_list_get (&sdp->a_attributes, pos_attr)) != NULL)
        {
          osip_list_remove (&sdp->a_attributes, pos_attr);
          sdp_attribute_free (attr);
        }
      return 0;
    }
  med = (sdp_media_t *) osip_list_get (&sdp->m_medias, pos_media);
  if (med == NULL)
    return -1;
  for (i = 0; i < osip_list_size (&med->a_attributes);)
    {
      if (pos_attr == -1)
        {
          attr = osip_list_get (&med->a_attributes, i);
          if (strcmp (attr->a_att_field, att_field) == 0)
            {
              osip_list_remove (&med->a_attributes, i);
              sdp_attribute_free (attr);
          } else
            i++;
      } else if ((attr = osip_list_get (&med->a_attributes, pos_attr)) != NULL)
        {
          osip_list_remove (&med->a_attributes, pos_attr);
          sdp_attribute_free (attr);
        }
    }
  return 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 OSIP_BADPARAMETER;
  if (response == NULL)
    return OSIP_BADPARAMETER;

  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 i;
  }

  if (dialog->state == DIALOG_EARLY && osip_list_size (&dialog->route_set) > 0) {
    osip_list_special_free (&dialog->route_set, (void (*)(void *)) &osip_record_route_free);
    osip_list_init (&dialog->route_set);
  }

  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 i;
      osip_list_add (&dialog->route_set, rr2, 0);
      pos++;
    }
  }

  if (MSG_IS_STATUS_2XX (response))
    dialog->state = DIALOG_CONFIRMED;
  return OSIP_SUCCESS;
}
/* returns null on error. */
int
osip_content_type_to_str (const osip_content_type_t * content_type,
			  char **dest)
{
  char *buf;
  char *tmp;
  size_t len;

  *dest = NULL;
  if ((content_type == NULL) || (content_type->type == NULL)
      || (content_type->subtype == NULL))
    return -1;

  /* try to guess a long enough length */
  len = strlen (content_type->type) + strlen (content_type->subtype) + 4	/* for '/', ' ', ';' and '\0' */
    + 10 * osip_list_size (content_type->gen_params);

  buf = (char *) osip_malloc (len);
  tmp = buf;

  sprintf (tmp, "%s/%s", content_type->type, content_type->subtype);

  tmp = tmp + strlen (tmp);
  {
    int pos = 0;
    osip_generic_param_t *u_param;

    if (!osip_list_eol (content_type->gen_params, pos))
      {				/* needed for cannonical form! (authentication issue of rfc2543) */
	sprintf (tmp, " ");
	tmp++;
      }
    while (!osip_list_eol (content_type->gen_params, pos))
      {
	size_t tmp_len;

	u_param =
	  (osip_generic_param_t *) osip_list_get (content_type->gen_params,
						  pos);
	if (u_param->gvalue == NULL)
	  {
	    osip_free (buf);
	    return -1;
	  }
	tmp_len = strlen (buf) + 4 + strlen (u_param->gname)
	  + strlen (u_param->gvalue);
	if (len < tmp_len)
	  {
	    buf = osip_realloc (buf, tmp_len);
	    len = tmp_len;
	    tmp = buf + strlen (buf);
	  }
	sprintf (tmp, ";%s=%s", u_param->gname, u_param->gvalue);
	tmp = tmp + strlen (tmp);
	pos++;
      }
  }
  *dest = buf;
  return 0;
}
Exemple #4
0
GB_Record_Node * GB_Find_Record_Node_by_cmdType(GB_CONNECT_STATE *gb_cons, int cmdType, int idx, int *index)
{
	GB_Record_Node *record = NULL;
	int pos;
	int list_size = 0;

	if(gb_cons == NULL || cmdType < 0 || cmdType >= gb_CommandType_NUM || idx < 0)
	{
		TRACE(SCI_TRACE_NORMAL,MOD_GB,"%s  line=%d  Err\n",__FUNCTION__,__LINE__);
		return NULL;
	}

	list_size = osip_list_size(&(gb_cons->record_node_list));
	if(list_size <= 0)
	{
		return NULL;	
	}
	
	for(pos=idx; pos<list_size; pos++)
	{
		record = osip_list_get(&(gb_cons->record_node_list), pos);
		if(record)
		{
			if(record->cmd == cmdType && record->call_id == NULL)
			{
				*index = pos;
				return record;
			}
			record = NULL;
		}
	}

	return NULL;	
}
Exemple #5
0
GB_Record_Node * GB_Find_Record_Node_by_Call_ID(GB_CONNECT_STATE *gb_cons, osip_call_id_t *call_id, int *index)
{
	GB_Record_Node *record = NULL;
	int pos;
	int list_size = 0;

	if(gb_cons == NULL || call_id == NULL)
	{
		TRACE(SCI_TRACE_NORMAL,MOD_GB,"%s  line=%d  Err\n",__FUNCTION__,__LINE__);
		return NULL;
	}

	list_size = osip_list_size(&(gb_cons->record_node_list));
	if(list_size <= 0)
	{
		return NULL;	
	}
	
	for(pos=0; pos<list_size; pos++)
	{
		record = osip_list_get(&(gb_cons->record_node_list), pos);
		if(record)
		{
			if(osip_call_id_match(record->call_id, call_id) == 0)
			{
				*index = pos;
				return record;
			}
			record = NULL;
		}
	}

	return NULL;	
}
Exemple #6
0
int GB_Remove_Record_Node(GB_CONNECT_STATE *gb_cons, int index)
{
	GB_Record_Node *record = NULL;

	if(gb_cons == NULL)
	{
		TRACE(SCI_TRACE_NORMAL,MOD_GB,"%s  line=%d  Err\n",__FUNCTION__,__LINE__);
		return -1;
	}
	
	if(index <= osip_list_size(&(gb_cons->record_node_list)) && index >= 0)
	{
		record = (GB_Record_Node *)osip_list_get(&(gb_cons->record_node_list), index);

		if(record)
		{
			if(record->call_id)
				osip_call_id_free(record->call_id);
			if(record->data)
				SN_FREE(record->data);
			osip_list_remove(&(gb_cons->record_node_list), index);
			SN_FREE(record);

			return 0;
		}
	}

	return -1;
	
}
int
sdp_message_c_connection_add (sdp_message_t * sdp, int pos_media,
                              char *nettype, char *addrtype,
                              char *addr, char *addr_multicast_ttl,
                              char *addr_multicast_int)
{
  int i;
  sdp_media_t *med;
  sdp_connection_t *conn;

  if (sdp == NULL)
    return -1;
  if ((pos_media != -1) && (osip_list_size (&sdp->m_medias) < pos_media + 1))
    return -1;
  i = sdp_connection_init (&conn);
  if (i != 0)
    return -1;
  conn->c_nettype = nettype;
  conn->c_addrtype = addrtype;
  conn->c_addr = addr;
  conn->c_addr_multicast_ttl = addr_multicast_ttl;
  conn->c_addr_multicast_int = addr_multicast_int;
  if (pos_media == -1)
    {
      sdp->c_connection = conn;
      return 0;
    }
  med = (sdp_media_t *) osip_list_get (&sdp->m_medias, pos_media);
  osip_list_add (&med->c_connections, conn, -1);
  return 0;
}
Exemple #8
0
void GB_ResetConState(GB_CONNECT_STATE *gb_cons)
{
	if (gb_cons == NULL)
		return;

	TRACE(SCI_TRACE_NORMAL,MOD_GB,"GB_ResetConState\n");
	
	gb_cons->cur_state = GB_STATE_IDEL;
	gb_cons->connfd = -1;
	gb_cons->local_cseq = 1;
	gb_cons->bUnRegister = 0;

	if (gb_cons->wwwa)
	{
		osip_www_authenticate_free(gb_cons->wwwa);
		gb_cons->wwwa = NULL;	
	}
			
	GB_reset_recv_buffer(gb_cons, 0);

	if(osip_list_size(&(gb_cons->record_node_list)) > 0)
	{
		GB_reset_Record_Node_list(gb_cons);
	}
	osip_list_init(&(gb_cons->record_node_list));


	gb_cons->keepalive_timeout_cnt = 0;
	gb_cons->last_keepalivetime = 0;
	gb_cons->last_sendtime = 0;
	gb_cons->last_registertime = 0;

	return ;
}
int
sdp_message_b_bandwidth_add (sdp_message_t * sdp, int pos_media, char *bwtype,
                             char *bandwidth)
{
  int i;
  sdp_media_t *med;
  sdp_bandwidth_t *band;

  if (sdp == NULL)
    return -1;
  if ((pos_media != -1) && (osip_list_size (&sdp->m_medias) < pos_media + 1))
    return -1;
  i = sdp_bandwidth_init (&band);
  if (i != 0)
    return -1;
  band->b_bwtype = bwtype;
  band->b_bandwidth = bandwidth;
  if (pos_media == -1)
    {
      osip_list_add (&sdp->b_bandwidths, band, -1);
      return 0;
    }
  med = (sdp_media_t *) osip_list_get (&sdp->m_medias, pos_media);
  osip_list_add (&med->b_bandwidths, band, -1);
  return 0;
}
int
sdp_message_a_attribute_add (sdp_message_t * sdp, int pos_media,
                             char *att_field, char *att_value)
{
  int i;
  sdp_media_t *med;
  sdp_attribute_t *attr;

  if (sdp == NULL)
    return -1;
  if ((pos_media != -1) && (osip_list_size (&sdp->m_medias) < pos_media + 1))
    return -1;
  i = sdp_attribute_init (&attr);
  if (i != 0)
    return -1;
  attr->a_att_field = att_field;
  attr->a_att_value = att_value;
  if (pos_media == -1)
    {
      osip_list_add (&sdp->a_attributes, attr, -1);
      return 0;
    }
  med = (sdp_media_t *) osip_list_get (&sdp->m_medias, pos_media);
  osip_list_add (&med->a_attributes, attr, -1);
  return 0;
}
Exemple #11
0
int
osip_fifo_insert (osip_fifo_t * ff, void *el)
{
#ifdef OSIP_MT
  osip_mutex_lock (ff->qislocked);
#endif

  if (ff->etat != plein)
    {
      /* 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->etat = plein;
  else
    ff->etat = ok;

#ifdef OSIP_MT
  osip_sem_post (ff->qisempty);
  osip_mutex_unlock (ff->qislocked);
#endif
  return 0;
}
Exemple #12
0
void *
osip_fifo_get (osip_fifo_t * ff)
{
  void *el;
  int i = osip_sem_wait (ff->qisempty);

  if (i != 0)
    return NULL;
  osip_mutex_lock (ff->qislocked);

  if (ff->etat != vide)
    {
      el = osip_list_get (ff->queue, 0);
      osip_list_remove (ff->queue, 0);
      /* ff->nb_elt--; */
    }
  else
    {
      OSIP_TRACE (osip_trace
		  (__FILE__, __LINE__, OSIP_ERROR, NULL,
		   "no element in fifo.\n"));
      osip_mutex_unlock (ff->qislocked);
      return 0;			/* pile vide */
    }
  /* if (ff->nb_elt <= 0) */
  if (osip_list_size (ff->queue) <= 0)
    ff->etat = vide;
  else
    ff->etat = ok;

  osip_mutex_unlock (ff->qislocked);
  return el;
}
int
osip_message_get_knownheaderlist (osip_list_t * header_list, int pos, void **dest)
{
  *dest = NULL;
  if (osip_list_size (header_list) <= pos)
    return OSIP_UNDEFINED_ERROR;        /* does not exist */
  *dest = (void *) osip_list_get (header_list, pos);
  return pos;
}
Exemple #14
0
/* return null on error. */
int
osip_message_get_header (const osip_message_t * sip, int pos, osip_header_t ** dest)
{
  *dest = NULL;
  if (osip_list_size (sip->headers) <= pos)
    return -1;			/* NULL */
  *dest = (osip_header_t *) osip_list_get (sip->headers, pos);
  return 0;
}
Exemple #15
0
/* return null on error. */
int
osip_message_get_header(const osip_message_t * sip, int pos, osip_header_t ** dest)
{
	*dest = NULL;
	if (osip_list_size(&sip->headers) <= pos)
		return OSIP_UNDEFINED_ERROR;	/* NULL */
	*dest = (osip_header_t *) osip_list_get(&sip->headers, pos);
	return pos;
}
char *
sdp_message_e_email_get (sdp_message_t * sdp, int pos)
{
  if (sdp == NULL)
    return NULL;
  if (osip_list_size (&sdp->e_emails) > pos)
    return (char *) osip_list_get (&sdp->e_emails, pos);
  return NULL;
}
char *
sdp_message_p_phone_get (sdp_message_t * sdp, int pos)
{
  if (sdp == NULL)
    return NULL;
  if (osip_list_size (&sdp->p_phones) > pos)
    return (char *) osip_list_get (&sdp->p_phones, pos);
  return NULL;
}
static int
sdp_message_parse_i (sdp_message_t * sdp, char *buf, char **next)
{
  char *equal;
  char *crlf;
  int i;
  char *i_info;

  *next = buf;

  equal = buf;
  while ((*equal != '=') && (*equal != '\0'))
    equal++;
  if (*equal == '\0')
    return ERR_ERROR;

  /* check if header is "i" */
  if (equal[-1] != 'i')
    return ERR_DISCARD;

  crlf = equal + 1;

  while ((*crlf != '\r') && (*crlf != '\n') && (*crlf != '\0'))
    crlf++;
  if (*crlf == '\0')
    return ERR_ERROR;
  if (crlf == equal + 1)
    return ERR_ERROR;		/* o=\r ?? bad header */

  /* s=text */

  /* text is interpreted as ISO-10646 UTF8! */
  /* using ISO 8859-1 requires "a=charset:ISO-8859-1 */
  i_info = osip_malloc (crlf - (equal + 1) + 1);
  osip_strncpy (i_info, equal + 1, crlf - (equal + 1));

  /* add the bandwidth at the correct place:
     if there is no media line yet, then the "b=" is the
     global one.
   */
  i = osip_list_size (sdp->m_medias);
  if (i == 0)
    sdp->i_info = i_info;
  else
    {
      sdp_media_t *last_sdp_media =
	(sdp_media_t *) osip_list_get (sdp->m_medias, i - 1);
      last_sdp_media->i_info = i_info;
    }

  if (crlf[1] == '\n')
    *next = crlf + 2;
  else
    *next = crlf + 1;
  return WF;
}
Exemple #19
0
int
osip_from_param_get (osip_from_t * from, int pos, osip_generic_param_t ** fparam)
{
  *fparam = NULL;
  if (from == NULL)
    return -1;
  if (osip_list_size (&from->gen_params) <= pos)
    return -1;                  /* does not exist */
  *fparam = (osip_generic_param_t *) osip_list_get (&from->gen_params, pos);
  return pos;
}
Exemple #20
0
/* returns null on error. */
int
osip_message_get_route (const osip_message_t * sip, int pos, osip_route_t ** dest)
{
  osip_route_t *route;

  *dest = NULL;
  if (osip_list_size (&sip->routes) <= pos)
    return -1;                  /* does not exist */
  route = (osip_route_t *) osip_list_get (&sip->routes, pos);
  *dest = route;
  return pos;
}
Exemple #21
0
int
osip_message_get_allow (const osip_message_t * sip, int pos, osip_allow_t ** dest)
{
  osip_allow_t *allow;

  *dest = NULL;
  if (osip_list_size (&sip->allows) <= pos)
    return -1;                  /* does not exist */
  allow = (osip_allow_t *) osip_list_get (&sip->allows, pos);
  *dest = allow;
  return pos;
}
/* returns -1 on error. */
int
osip_message_get_contact(const osip_message_t * sip, int pos,
						 osip_contact_t ** dest)
{
	*dest = NULL;
	if (sip == NULL)
		return OSIP_BADPARAMETER;
	if (osip_list_size(&sip->contacts) <= pos)
		return OSIP_UNDEFINED_ERROR;	/* does not exist */
	*dest = (osip_contact_t *) osip_list_get(&sip->contacts, pos);
	return pos;
}
/* returns null on error. */
int
osip_message_get_authorization (const osip_message_t * sip, int pos, osip_authorization_t ** dest)
{
  osip_authorization_t *authorization;

  *dest = NULL;
  if (osip_list_size (&sip->authorizations) <= pos)
    return OSIP_UNDEFINED_ERROR;        /* does not exist */
  authorization = (osip_authorization_t *) osip_list_get (&sip->authorizations, pos);
  *dest = authorization;
  return pos;
}
Exemple #24
0
/* returns null on error. */
int
osip_message_get_via (const osip_message_t * sip, int pos, osip_via_t ** dest)
{
  *dest = NULL;
  if (sip == NULL)
    return -1;
  if (osip_list_size (sip->vias) <= pos)
    return -1;
  *dest = (osip_via_t *) osip_list_get (sip->vias, pos);

  return pos;
}
int
osip_message_get_accept_language (const osip_message_t * sip, int pos, osip_accept_language_t ** dest)
{
  osip_accept_language_t *accept_language;

  *dest = NULL;
  if (osip_list_size (&sip->accept_languages) <= pos)
    return OSIP_UNDEFINED_ERROR;        /* does not exist */
  accept_language = (osip_accept_language_t *) osip_list_get (&sip->accept_languages, pos);
  *dest = accept_language;
  return pos;
}
Exemple #26
0
int
osip_message_get_error_info (const osip_message_t * sip, int pos, osip_error_info_t ** dest)
{
  osip_error_info_t *error_info;

  *dest = NULL;
  if (osip_list_size (&sip->error_infos) <= pos)
    return OSIP_UNDEFINED_ERROR;        /* does not exist */
  error_info = (osip_error_info_t *) osip_list_get (&sip->error_infos, pos);
  *dest = error_info;
  return pos;
}
Exemple #27
0
/* and -1 on error. */
int
osip_message_header_get_byname(const osip_message_t * sip, const char *hname,
							   int pos, osip_header_t ** dest)
{
	int i;
	osip_header_t *tmp;

	*dest = NULL;
	i = pos;
	if (osip_list_size(&sip->headers) <= pos)
		return OSIP_UNDEFINED_ERROR;	/* NULL */
	while (osip_list_size(&sip->headers) > i) {
		tmp = (osip_header_t *) osip_list_get(&sip->headers, i);
		if (osip_strcasecmp(tmp->hname, hname) == 0) {
			*dest = tmp;
			return i;
		}
		i++;
	}
	return OSIP_UNDEFINED_ERROR;	/* not found */
}
int
osip_message_get_content_encoding (const osip_message_t * sip, int pos,
                                   osip_content_encoding_t ** dest)
{
  osip_content_encoding_t *ce;

  *dest = NULL;
  if (osip_list_size (sip->content_encodings) <= pos)
    return -1;                  /* does not exist */
  ce = (osip_content_encoding_t *) osip_list_get (sip->content_encodings, pos);
  *dest = ce;
  return pos;
}
/* returns -1 on error. */
int
osip_message_get_body (const osip_message_t * sip, int pos,
		       osip_body_t ** dest)
{
  osip_body_t *body;

  *dest = NULL;
  if (osip_list_size (sip->bodies) <= pos)
    return -1;			/* does not exist */
  body = (osip_body_t *) osip_list_get (sip->bodies, pos);
  *dest = body;
  return pos;
}
/* returns null on error. */
int
osip_message_get_record_route(const osip_message_t * sip, int pos,
							  osip_record_route_t ** dest)
{
	osip_record_route_t *record_route;

	*dest = NULL;
	if (osip_list_size(&sip->record_routes) <= pos)
		return OSIP_UNDEFINED_ERROR;	/* does not exist */
	record_route = (osip_record_route_t *) osip_list_get(&sip->record_routes, pos);
	*dest = record_route;
	return pos;
}