int
osip_accept_encoding_parse(osip_accept_encoding_t * accept_encoding,
						   const char *hvalue)
{
	int i;
	const char *osip_accept_encoding_params;

	osip_accept_encoding_params = strchr(hvalue, ';');

	if (osip_accept_encoding_params != NULL) {
		i = __osip_generic_param_parseall(&accept_encoding->gen_params,
										  osip_accept_encoding_params);
		if (i != 0)
			return i;
	} else
		osip_accept_encoding_params = hvalue + strlen(hvalue);

	if (osip_accept_encoding_params - hvalue + 1 < 2)
		return OSIP_SYNTAXERROR;
	accept_encoding->element =
		(char *) osip_malloc(osip_accept_encoding_params - hvalue + 1);
	if (accept_encoding->element == NULL)
		return OSIP_NOMEM;
	osip_clrncpy(accept_encoding->element, hvalue,
				 osip_accept_encoding_params - hvalue);

	return OSIP_SUCCESS;
}
int
osip_accept_encoding_parse (osip_accept_encoding_t * accept_encoding,
                            const char *hvalue)
{
  const char *osip_accept_encoding_params;

  osip_accept_encoding_params = strchr (hvalue, ';');

  if (osip_accept_encoding_params != NULL)
    {
      if (__osip_generic_param_parseall (&accept_encoding->gen_params,
                                         osip_accept_encoding_params) == -1)
        return -1;
  } else
    osip_accept_encoding_params = hvalue + strlen (hvalue);

  if (osip_accept_encoding_params - hvalue + 1 < 2)
    return -1;
  accept_encoding->element =
    (char *) osip_malloc (osip_accept_encoding_params - hvalue + 1);
  if (accept_encoding->element == NULL)
    return -1;
  osip_clrncpy (accept_encoding->element, hvalue,
                osip_accept_encoding_params - hvalue);

  return 0;
}
예제 #3
0
int
osip_call_info_parse (osip_call_info_t * call_info, const char *hvalue)
{
  const char *osip_call_info_params;

  osip_call_info_params = strchr (hvalue, '<');
  if (osip_call_info_params == NULL)
    return -1;

  osip_call_info_params = strchr (osip_call_info_params + 1, '>');
  if (osip_call_info_params == NULL)
    return -1;

  osip_call_info_params = strchr (osip_call_info_params + 1, ';');

  if (osip_call_info_params != NULL)
    {
      if (__osip_generic_param_parseall
          (call_info->gen_params, osip_call_info_params) == -1)
        return -1;
  } else
    osip_call_info_params = hvalue + strlen (hvalue);

  if (osip_call_info_params - hvalue + 1 < 2)
    return -1;
  call_info->element = (char *) osip_malloc (osip_call_info_params - hvalue + 1);
  if (call_info->element == NULL)
    return -1;
  osip_clrncpy (call_info->element, hvalue, osip_call_info_params - hvalue);

  return 0;
}
int
osip_call_info_parse (osip_call_info_t * call_info, const char *hvalue)
{
  const char *osip_call_info_params;
  int i;

  osip_call_info_params = strchr (hvalue, '<');
  if (osip_call_info_params == NULL)
    return OSIP_SYNTAXERROR;

  osip_call_info_params = strchr (osip_call_info_params + 1, '>');
  if (osip_call_info_params == NULL)
    return OSIP_SYNTAXERROR;

  osip_call_info_params = strchr (osip_call_info_params + 1, ';');

  if (osip_call_info_params != NULL)
    {
	  i = __osip_generic_param_parseall(&call_info->gen_params, osip_call_info_params);
      if (i != 0)
        return i;
  } else
    osip_call_info_params = hvalue + strlen (hvalue);

  if (osip_call_info_params - hvalue + 1 < 2)
    return OSIP_SYNTAXERROR;
  call_info->element = (char *) osip_malloc (osip_call_info_params - hvalue + 1);
  if (call_info->element == NULL)
    return OSIP_NOMEM;
  osip_clrncpy (call_info->element, hvalue, osip_call_info_params - hvalue);

  return OSIP_SUCCESS;
}
/* returns -1 on error. */
int
osip_content_type_parse (osip_content_type_t * content_type,
			 const char *hvalue)
{
  char *subtype;
  char *osip_content_type_params;

  /* How to parse:

     we'll place the pointers:
     subtype              =>  beginning of subtype
     osip_content_type_params  =>  beginning of params

     examples:

     application/multipart ; boundary=
     ^          ^
   */

  subtype = strchr (hvalue, '/');
  osip_content_type_params = strchr (hvalue, ';');

  if (subtype == NULL)
    return -1;			/* do we really mind such an error */

  if (osip_content_type_params != NULL)
    {
      if (__osip_generic_param_parseall (content_type->gen_params,
					 osip_content_type_params) == -1)
	return -1;
    }
  else
    osip_content_type_params = subtype + strlen (subtype);

  if (subtype - hvalue + 1 < 2)
    return -1;
  content_type->type = (char *) osip_malloc (subtype - hvalue + 1);
  if (content_type->type == NULL)
    return -1;
  osip_strncpy (content_type->type, hvalue, subtype - hvalue);
  osip_clrspace (content_type->type);

  if (osip_content_type_params - subtype < 2)
    return -1;
  content_type->subtype =
    (char *) osip_malloc (osip_content_type_params - subtype);
  if (content_type->subtype == NULL)
    return -1;
  osip_strncpy (content_type->subtype, subtype + 1,
		osip_content_type_params - subtype - 1);
  osip_clrspace (content_type->subtype);

  return 0;
}
예제 #6
0
/* returns -1 on error. */
int osip_content_type_parse(osip_content_type_t * content_type, const char *hvalue)
{
	char *subtype;
	char *osip_content_type_params;
	int i;

	/* How to parse:

	   we'll place the pointers:
	   subtype              =>  beginning of subtype
	   osip_content_type_params  =>  beginning of params

	   examples:

	   application/multipart ; boundary=
	   ^          ^
	 */
	if (hvalue == NULL || hvalue[0] == '\0')
		return OSIP_SUCCESS;	/* It's valid to add empty Accept header! */

	subtype = strchr(hvalue, '/');
	osip_content_type_params = strchr(hvalue, ';');

	if (subtype == NULL)
		return OSIP_SYNTAXERROR;	/* do we really mind such an error */

	if (osip_content_type_params != NULL) {
		i = __osip_generic_param_parseall(&content_type->gen_params,
										  osip_content_type_params);
		if (i != 0)
			return i;
	} else
		osip_content_type_params = subtype + strlen(subtype);

	if (subtype - hvalue + 1 < 2)
		return OSIP_SYNTAXERROR;
	content_type->type = (char *) osip_malloc(subtype - hvalue + 1);
	if (content_type->type == NULL)
		return OSIP_NOMEM;
	osip_clrncpy(content_type->type, hvalue, subtype - hvalue);

	if (osip_content_type_params - subtype < 2)
		return OSIP_SYNTAXERROR;
	content_type->subtype =
		(char *) osip_malloc(osip_content_type_params - subtype);
	if (content_type->subtype == NULL)
		return OSIP_NOMEM;
	osip_clrncpy(content_type->subtype, subtype + 1,
				 osip_content_type_params - subtype - 1);

	return OSIP_SUCCESS;
}
int
osip_content_disposition_parse (osip_content_disposition_t * cd,
                                const char *hvalue)
{
  const char *cd_params;

  cd_params = strchr (hvalue, ';');

  if (cd_params != NULL)
    {
      if (__osip_generic_param_parseall (&cd->gen_params, cd_params) == -1)
        return -1;
  } else
    cd_params = hvalue + strlen (hvalue);

  if (cd_params - hvalue + 1 < 2)
    return -1;
  cd->element = (char *) osip_malloc (cd_params - hvalue + 1);
  if (cd->element == NULL)
    return -1;
  osip_clrncpy (cd->element, hvalue, cd_params - hvalue);

  return 0;
}
예제 #8
0
int
osip_via_parse (osip_via_t * via, const char *hvalue)
{
  const char *version;
  const char *protocol;
  const char *host;
  const char *ipv6host;
  const char *port;
  const char *via_params;
  const char *comment;

  version = strchr (hvalue, '/');
  if (version == NULL)
    return -1;

  protocol = strchr (version + 1, '/');
  if (protocol == NULL)
    return -1;

  /* set the version */
  if (protocol - version < 2)
    return -1;
  via->version = (char *) osip_malloc (protocol - version);
  if (via->version == NULL)
    return -1;
  osip_strncpy (via->version, version + 1, protocol - version - 1);
  osip_clrspace (via->version);

  /* Here: we avoid matching an additionnal space */
  host = strchr (protocol + 1, ' ');
  if (host == NULL)
    return -1;			/* fixed in 0.8.4 */
  if (host == protocol + 1)	/* there are extra SPACE characters */
    {
      while (0 == strncmp (host, " ", 1))
	{
	  host++;
	  if (strlen (host) == 1)
	    return -1;		/* via is malformed */
	}
      /* here, we match the real space located after the protocol name */
      host = strchr (host + 1, ' ');
      if (host == NULL)
	return -1;		/* fixed in 0.8.4 */
    }

  /* set the protocol */
  if (host - protocol < 2)
    return -1;
  via->protocol = (char *) osip_malloc (host - protocol);
  if (via->protocol == NULL)
    return -1;
  osip_strncpy (via->protocol, protocol + 1, host - protocol - 1);
  osip_clrspace (via->protocol);

  /* comments in Via are not allowed any more in the latest draft (09) */
  comment = strchr (host, '(');

  if (comment != NULL)
    {
      char *end_comment;

      end_comment = strchr (host, ')');
      if (end_comment == NULL)
	return -1;		/* if '(' exist ')' MUST exist */
      if (end_comment - comment < 2)
	return -1;
      via->comment = (char *) osip_malloc (end_comment - comment);
      if (via->comment == NULL)
	return -1;
      osip_strncpy (via->comment, comment + 1, end_comment - comment - 1);
      comment--;
    }
  else
    comment = host + strlen (host);

  via_params = strchr (host, ';');

  if ((via_params != NULL) && (via_params < comment))
    /* via params exist */
    {
      char *tmp;

      if (comment - via_params + 1 < 2)
	return -1;
      tmp = (char *) osip_malloc (comment - via_params + 1);
      if (tmp == NULL)
	return -1;
      osip_strncpy (tmp, via_params, comment - via_params);
      __osip_generic_param_parseall (via->via_params, tmp);
      osip_free (tmp);
    }

  if (via_params == NULL)
    via_params = comment;

  /* add ipv6 support (0.8.4) */
  /* Via: SIP/2.0/UDP [mlke::zeezf:ezfz:zef:zefzf]:port;.... */
  ipv6host = strchr (host, '[');
  if (ipv6host != NULL && ipv6host < via_params)
    {
      port = strchr (ipv6host, ']');
      if (port == NULL || port > via_params)
	return -1;

      if (port - ipv6host < 2)
	return -1;
      via->host = (char *) osip_malloc (port - ipv6host);
      if (via->host == NULL)
	return -1;
      osip_strncpy (via->host, ipv6host + 1, port - ipv6host - 1);
      osip_clrspace (via->host);

      port = strchr (port, ':');
    }
  else
    {
      port = strchr (host, ':');
      ipv6host = NULL;
    }

  if ((port != NULL) && (port < via_params))
    {
      if (via_params - port < 2)
	return -1;
      via->port = (char *) osip_malloc (via_params - port);
      if (via->port == NULL)
	return -1;
      osip_strncpy (via->port, port + 1, via_params - port - 1);
      osip_clrspace (via->port);
    }
  else
    port = via_params;

  /* host is already set in the case of ipv6 */
  if (ipv6host != NULL)
    return 0;

  if (port - host < 2)
    return -1;
  via->host = (char *) osip_malloc (port - host);
  if (via->host == NULL)
    return -1;
  osip_strncpy (via->host, host + 1, port - host - 1);
  osip_clrspace (via->host);

  return 0;
}
예제 #9
0
/* returns -1 on error. */
int
osip_from_parse (osip_from_t * from, const char *hvalue)
{
  const char *displayname;
  const char *url;
  const char *url_end;
  const char *gen_params;

  /* How to parse:

     we'll place the pointers:
     displayname  =>  beginning of displayname
     url          =>  beginning of url
     url_end      =>  end       of url
     gen_params  =>  beginning of params

     examples:

     jack <sip:[email protected]>;tag=34erZ
     ^     ^                ^ ^

     sip:[email protected];tag=34erZ
     ^                ^^      
   */

  displayname = strchr (hvalue, '"');

  url = strchr (hvalue, '<');
  if (url != NULL)
    {
      url_end = strchr (url, '>');
      if (url_end == NULL)
        return -1;
    }

  /* SIPit day2: this case was not supported
     first '"' is placed after '<' and after '>'
     <sip:[email protected];method=INVITE>;description="OPEN";expires=28800
     if the fisrt quote is after '<' then
     this is not a quote for a displayname.
   */
  if (displayname != NULL)
    {
      if (displayname > url)
        displayname = NULL;
    }

  if ((displayname == NULL) && (url != NULL))
    {                           /* displayname IS A '*token' (not a quoted-string) */
      if (hvalue != url)        /* displayname exists */
        {
          if (url - hvalue + 1 < 2)
            return -1;
          from->displayname = (char *) osip_malloc (url - hvalue + 1);
          if (from->displayname == NULL)
            return -1;
          osip_clrncpy (from->displayname, hvalue, url - hvalue);
        }
      url++;                    /* place pointer on the beginning of url */
  } else
    {
      if ((displayname != NULL) && (url != NULL))
        {                       /* displayname IS A quoted-string (not a '*token') */
          const char *first;
          const char *second=NULL;

          /* search for quotes */
          first = __osip_quote_find (hvalue);
          if (first == NULL)
            return -1;          /* missing quote */
	  second = __osip_quote_find (first + 1);
          if (second == NULL)
            return -1;          /* missing quote */
          if ((first > url))
            return -1;

          if (second - first + 2 >= 2)
            {
              from->displayname = (char *) osip_malloc (second - first + 2);
              if (from->displayname == NULL)
                return -1;
              osip_strncpy (from->displayname, first, second - first + 1);
              /* osip_clrspace(from->displayname); *//*should we do that? */

              /* special case: "<sip:[email protected]>" <sip:[email protected]> */
            }                   /* else displayname is empty? */
          url = strchr (second + 1, '<');
          if (url == NULL)
            return -1;          /* '<' MUST exist */
          url++;
      } else
        url = hvalue;           /* field does not contains '<' and '>' */
    }

  /* DISPLAY-NAME SET   */
  /* START of URL KNOWN */

  url_end = strchr (url, '>');

  if (url_end == NULL)          /* sip:[email protected];tag=023 */
    {                           /* We are sure ';' is the delimiter for from-parameters */
      char *host = strchr (url, '@');

      if (host != NULL)
        gen_params = strchr (host, ';');
      else
        gen_params = strchr (url, ';');
      if (gen_params != NULL)
        url_end = gen_params - 1;
      else
        url_end = url + strlen (url);
  } else                        /* jack <sip:[email protected];user=phone>;tag=azer */
    {
      gen_params = strchr (url_end, ';');
      url_end--;                /* place pointer on the beginning of url */
    }

  if (gen_params != NULL)       /* now we are sure a param exist */
    if (__osip_generic_param_parseall (&from->gen_params, gen_params) == -1)
      {
        return -1;
      }

  /* set the url */
  {
    char *tmp;
    int i;

    if (url_end - url + 2 < 7)
      return -1;
    i = osip_uri_init (&(from->url));
    if (i != 0)
      return -1;
    tmp = (char *) osip_malloc (url_end - url + 2);
    if (tmp == NULL)
      return -1;
    osip_strncpy (tmp, url, url_end - url + 1);
    i = osip_uri_parse (from->url, tmp);
    osip_free (tmp);
    if (i != 0)
      return -1;
  }
  return 0;
}