Ejemplo n.º 1
0
/* TODO:
   digest-challenge tken has no order preference??
   verify many situations (extra SP....)
*/
int
osip_www_authenticate_parse (osip_www_authenticate_t * wwwa, const char *hvalue)
{
  const char *space;
  const char *next = NULL;
  int i;

  space = strchr (hvalue, ' '); /* SEARCH FOR SPACE */
  if (space == NULL)
    return OSIP_SYNTAXERROR;

  if (space - hvalue + 1 < 2)
    return OSIP_SYNTAXERROR;
  wwwa->auth_type = (char *) osip_malloc (space - hvalue + 1);
  if (wwwa->auth_type == NULL)
    return OSIP_NOMEM;
  osip_strncpy (wwwa->auth_type, hvalue, space - hvalue);

  for (;;) {
    int parse_ok = 0;

    i = __osip_quoted_string_set ("realm", space, &(wwwa->realm), &next);
    if (i != 0)
      return i;
    if (next == NULL)
      return OSIP_SUCCESS;      /* end of header detected! */
    else if (next != space) {
      space = next;
      parse_ok++;
    }
    i = __osip_quoted_string_set ("domain", space, &(wwwa->domain), &next);
    if (i != 0)
      return i;
    if (next == NULL)
      return OSIP_SUCCESS;      /* end of header detected! */
    else if (next != space) {
      space = next;
      parse_ok++;
    }
    i = __osip_quoted_string_set ("nonce", space, &(wwwa->nonce), &next);
    if (i != 0)
      return i;
    if (next == NULL)
      return OSIP_SUCCESS;      /* end of header detected! */
    else if (next != space) {
      space = next;
      parse_ok++;
    }
    i = __osip_quoted_string_set ("opaque", space, &(wwwa->opaque), &next);
    if (i != 0)
      return i;
    if (next == NULL)
      return OSIP_SUCCESS;      /* end of header detected! */
    else if (next != space) {
      space = next;
      parse_ok++;
    }
    i = __osip_token_set ("stale", space, &(wwwa->stale), &next);
    if (i != 0)
      return i;
    if (next == NULL)
      return OSIP_SUCCESS;      /* end of header detected! */
    else if (next != space) {
      space = next;
      parse_ok++;
    }
    i = __osip_token_set ("algorithm", space, &(wwwa->algorithm), &next);
    if (i != 0)
      return i;
    if (next == NULL)
      return OSIP_SUCCESS;      /* end of header detected! */
    else if (next != space) {
      space = next;
      parse_ok++;
    }
    i = __osip_quoted_string_set ("qop", space, &(wwwa->qop_options), &next);
    if (i != 0)
      return i;
    if (next == NULL)
      return OSIP_SUCCESS;      /* end of header detected! */
    else if (next != space) {
      space = next;
      parse_ok++;
    }
    i = __osip_token_set ("version", space, &(wwwa->version), &next);
    if (i!=0)
      return i;
    if (next == NULL)
      return OSIP_SUCCESS;               /* end of header detected! */
    else if (next != space)
      {
        space = next;
        parse_ok++;
      }
       i = __osip_quoted_string_set ("targetname", space, &(wwwa->targetname), &next);
    if (i!=0)
      return i;
    if (next == NULL)
      return OSIP_SUCCESS;               /* end of header detected! */
    else if (next != space)
      {
        space = next;
        parse_ok++;
      }
       i = __osip_quoted_string_set ("gssapi-data", space, &(wwwa->gssapi_data), &next);
    if (i!=0)
      return i;
    if (next == NULL)
      return OSIP_SUCCESS;               /* end of header detected! */
    else if (next != space)
      {
        space = next;
        parse_ok++;
      }
    if (0 == parse_ok) {
      const char *quote1, *quote2, *tmp;

      /* CAUTION */
      /* parameter not understood!!! I'm too lazy to handle IT */
      /* let's simply bypass it */
      if (strlen (space) < 1)
        return OSIP_SUCCESS;
      tmp = strchr (space + 1, ',');
      if (tmp == NULL)          /* it was the last header */
        return OSIP_SUCCESS;
      quote1 = __osip_quote_find (space);
      if ((quote1 != NULL) && (quote1 < tmp)) { /* this may be a quoted string! */
        quote2 = __osip_quote_find (quote1 + 1);
        if (quote2 == NULL)
          return OSIP_SYNTAXERROR;      /* bad header format... */
        if (tmp < quote2)       /* the comma is inside the quotes! */
          space = strchr (quote2, ',');
        else
          space = tmp;
        if (space == NULL)      /* it was the last header */
          return OSIP_SUCCESS;
      }
      else
        space = tmp;
      /* continue parsing... */
    }
  }
  return OSIP_SUCCESS;          /* ok */
}
/* TODO:
   digest-challenge tken has no order preference??
   verify many situations (extra SP....)
*/
int
osip_authorization_parse (osip_authorization_t * auth, const char *hvalue)
{
  const char *space;
  const char *next = NULL;
  int i;

  space = strchr (hvalue, ' '); /* SEARCH FOR SPACE */
  if (space == NULL)
    return OSIP_SYNTAXERROR;

  if (space - hvalue < 1)
    return OSIP_SYNTAXERROR;
  auth->auth_type = (char *) osip_malloc (space - hvalue + 1);
  if (auth->auth_type==NULL)
	  return OSIP_NOMEM;
  osip_strncpy (auth->auth_type, hvalue, space - hvalue);

  for (;;)
    {
      int parse_ok = 0;

	  i = __osip_quoted_string_set ("username", space, &(auth->username), &next);
      if (i!=0)
        return i;
      if (next == NULL)
        return OSIP_SUCCESS;               /* end of header detected! */
      else if (next != space)
        {
          space = next;
          parse_ok++;
        }
      i = __osip_quoted_string_set ("realm", space, &(auth->realm), &next);
      if (i!=0)
        return i;
      if (next == NULL)
        return OSIP_SUCCESS;
      else if (next != space)
        {
          space = next;
          parse_ok++;
        }
      i = __osip_quoted_string_set ("nonce", space, &(auth->nonce), &next);
      if (i!=0)
        return i;
      if (next == NULL)
        return OSIP_SUCCESS;               /* end of header detected! */
      else if (next != space)
        {
          space = next;
          parse_ok++;
        }
      i = __osip_quoted_string_set ("uri", space, &(auth->uri), &next);
      if (i!=0)
        return i;
      if (next == NULL)
        return OSIP_SUCCESS;               /* end of header detected! */
      else if (next != space)
        {
          space = next;
          parse_ok++;
        }
      i = __osip_quoted_string_set ("response", space, &(auth->response), &next);
      if (i!=0)
        return i;
      if (next == NULL)
        return OSIP_SUCCESS;               /* end of header detected! */
      else if (next != space)
        {
          space = next;
          parse_ok++;
        }
      i = __osip_quoted_string_set ("digest", space, &(auth->digest), &next);
      if (i!=0)
        return i;
      if (next == NULL)
        return OSIP_SUCCESS;               /* end of header detected! */
      else if (next != space)
        {
          space = next;
          parse_ok++;
        }
      i = __osip_token_set ("algorithm", space, &(auth->algorithm), &next);
      if (i!=0)
        return i;
      if (next == NULL)
        return OSIP_SUCCESS;               /* end of header detected! */
      else if (next != space)
        {
          space = next;
          parse_ok++;
        }
      i = __osip_quoted_string_set ("cnonce", space, &(auth->cnonce), &next);
      if (i!=0)
        return i;
      if (next == NULL)
        return OSIP_SUCCESS;               /* end of header detected! */
      else if (next != space)
        {
          space = next;
          parse_ok++;
        }
      i = __osip_quoted_string_set ("opaque", space, &(auth->opaque), &next);
      if (i!=0)
        return i;
      if (next == NULL)
        return OSIP_SUCCESS;               /* end of header detected! */
      else if (next != space)
        {
          space = next;
          parse_ok++;
        }
      i = __osip_token_set ("qop", space, &(auth->message_qop), &next);
      if (i!=0)
        return i;
      if (next == NULL)
        return OSIP_SUCCESS;               /* end of header detected! */
      else if (next != space)
        {
          space = next;
          parse_ok++;
        }
      i = __osip_token_set ("nc", space, &(auth->nonce_count), &next);
      if (i!=0)
        return i;
      if (next == NULL)
        return OSIP_SUCCESS;               /* end of header detected! */
      else if (next != space)
        {
          space = next;
          parse_ok++;
        }
      /* nothing was recognized:
         here, we should handle a list of unknown tokens where:
         token1 = ( token2 | quoted_text ) */
      /* TODO */

      if (0 == parse_ok)
        {
          const char *quote1, *quote2, *tmp;

          /* CAUTION */
          /* parameter not understood!!! I'm too lazy to handle IT */
          /* let's simply bypass it */
          if (strlen (space) < 1)
            return OSIP_SUCCESS;
          tmp = strchr (space + 1, ',');
          if (tmp == NULL)      /* it was the last header */
            return OSIP_SUCCESS;
          quote1 = __osip_quote_find (space);
          if ((quote1 != NULL) && (quote1 < tmp))       /* this may be a quoted string! */
            {
              quote2 = __osip_quote_find (quote1 + 1);
              if (quote2 == NULL)
                return OSIP_SYNTAXERROR;      /* bad header format... */
              if (tmp < quote2) /* the comma is inside the quotes! */
                space = strchr (quote2, ',');
              else
                space = tmp;
              if (space == NULL)        /* it was the last header */
                return OSIP_SUCCESS;
          } else
            space = tmp;
          /* continue parsing... */
        }
    }
  return OSIP_SUCCESS;                     /* ok */
}
Ejemplo n.º 3
0
/* TODO:
   digest-challenge tken has no order preference??
   verify many situations (extra SP....)
*/
int
osip_authentication_info_parse (osip_authentication_info_t * ainfo,
                                const char *hvalue)
{
  const char *space;
  const char *next = NULL;

  space = hvalue;

  for (;;)
    {
      int parse_ok = 0;

      if (__osip_quoted_string_set
          ("nextnonce", space, &(ainfo->nextnonce), &next))
        return -1;
      if (next == NULL)
        return 0;               /* end of header detected! */
      else if (next != space)
        {
          space = next;
          parse_ok++;
        }
      if (__osip_quoted_string_set ("cnonce", space, &(ainfo->cnonce), &next))
        return -1;
      if (next == NULL)
        return 0;               /* end of header detected! */
      else if (next != space)
        {
          space = next;
          parse_ok++;
        }
      if (__osip_quoted_string_set ("rspauth", space, &(ainfo->rspauth), &next))
        return -1;
      if (next == NULL)
        return 0;               /* end of header detected! */
      else if (next != space)
        {
          space = next;
          parse_ok++;
        }
      if (__osip_token_set ("nc", space, &(ainfo->nonce_count), &next))
        return -1;
      if (next == NULL)
        return 0;               /* end of header detected! */
      else if (next != space)
        {
          space = next;
          parse_ok++;
        }
      if (__osip_token_set ("qop", space, &(ainfo->qop_options), &next))
        return -1;
      if (next == NULL)
        return 0;               /* end of header detected! */
      else if (next != space)
        {
          space = next;
          parse_ok++;
        }
      if (0 == parse_ok)
        {
          char *quote1, *quote2, *tmp;

          /* CAUTION */
          /* parameter not understood!!! I'm too lazy to handle IT */
          /* let's simply bypass it */
          if (strlen (space) < 1)
            return 0;
          tmp = strchr (space + 1, ',');
          if (tmp == NULL)      /* it was the last header */
            return 0;
          quote1 = __osip_quote_find (space);
          if ((quote1 != NULL) && (quote1 < tmp))       /* this may be a quoted string! */
            {
              quote2 = __osip_quote_find (quote1 + 1);
              if (quote2 == NULL)
                return -1;      /* bad header format... */
              if (tmp < quote2) /* the comma is inside the quotes! */
                space = strchr (quote2, ',');
              else
                space = tmp;
              if (space == NULL)        /* it was the last header */
                return 0;
          } else
            space = tmp;
          /* continue parsing... */
        }
    }
  return 0;                     /* ok */
}