Esempio n. 1
0
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;
}
Esempio n. 2
0
static int
sdp_message_parse_c (sdp_message_t * sdp, char *buf, char **next)
{
  char *equal;
  char *crlf;
  char *tmp;
  char *tmp_next;
  sdp_connection_t *c_header;
  int i;

  *next = buf;

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

  /* check if header is "c" */
  if (equal[-1] != 'c')
    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;		/* c=\r ?? bad header */

  tmp = equal + 1;
  i = sdp_connection_init (&c_header);
  if (i != 0)
    return ERR_ERROR;
  /* c=nettype addrtype (multicastaddr | addr) */

  /* nettype is "IN" and will be extended */
  i = __osip_set_next_token (&(c_header->c_nettype), tmp, ' ', &tmp_next);
  if (i != 0)
    return -1;
  tmp = tmp_next;

  /* nettype is "IP4" or "IP6" and will be extended */
  i = __osip_set_next_token (&(c_header->c_addrtype), tmp, ' ', &tmp_next);
  if (i != 0)
    return -1;
  tmp = tmp_next;

  /* there we have a multicast or unicast address */
  /* multicast can be ip/ttl [/integer] */
  /* unicast is FQDN or ip (no ttl, no integer) */

  /* is MULTICAST? */
  {
    char *slash = strchr (tmp, '/');

    if (slash != NULL && slash < crlf)	/* it's a multicast address! */
      {
	i = __osip_set_next_token (&(c_header->c_addr), tmp, '/', &tmp_next);
	if (i != 0)
	  return -1;
	tmp = tmp_next;
	slash = strchr (slash + 1, '/');
	if (slash != NULL && slash < crlf)	/* optionnal integer is there! */
	  {
	    i =
	      __osip_set_next_token (&(c_header->c_addr_multicast_ttl), tmp,
				     '/', &tmp_next);
	    if (i != 0)
	      return -1;
	    tmp = tmp_next;
	    i =
	      __osip_set_next_token (&(c_header->c_addr_multicast_int), tmp,
				     '\r', &tmp_next);
	    if (i != 0)
	      {
		i =
		  __osip_set_next_token (&(c_header->c_addr_multicast_int),
					 tmp, '\n', &tmp_next);
		if (i != 0)
		  {
		    sdp_connection_free (c_header);
		    return -1;
		  }
	      }
	  }
	else
	  {
	    i =
	      __osip_set_next_token (&(c_header->c_addr_multicast_ttl), tmp,
				     '\r', &tmp_next);
	    if (i != 0)
	      {
		i =
		  __osip_set_next_token (&(c_header->c_addr_multicast_ttl),
					 tmp, '\n', &tmp_next);
		if (i != 0)
		  {
		    sdp_connection_free (c_header);
		    return -1;
		  }
	      }
	  }
      }
    else
      {
	/* in this case, we have a unicast address */
	i = __osip_set_next_token (&(c_header->c_addr), tmp, '\r', &tmp_next);
	if (i != 0)
	  {
	    i =
	      __osip_set_next_token (&(c_header->c_addr), tmp, '\n',
				     &tmp_next);
	    if (i != 0)
	      {
		sdp_connection_free (c_header);
		return -1;
	      }
	  }
      }
  }

  /* add the connection at the correct place:
     if there is no media line yet, then the "c=" is the
     global one.
   */
  i = osip_list_size (sdp->m_medias);
  if (i == 0)
    sdp->c_connection = c_header;
  else
    {
      sdp_media_t *last_sdp_media =
	(sdp_media_t *) osip_list_get (sdp->m_medias, i - 1);
      osip_list_add (last_sdp_media->c_connections, c_header, -1);
    }
  if (crlf[1] == '\n')
    *next = crlf + 2;
  else
    *next = crlf + 1;
  return WF;
}