예제 #1
0
파일: url.c 프로젝트: Wuodan/mutt-kz
/* ciss_parse_userhost: fill in components of ciss with info from src. Note
 *   these are pointers into src, which is altered with '\0's. Port of 0
 *   means no port given. */
static int ciss_parse_userhost (ciss_url_t *ciss, char *src)
{
  char *t, *p;

  ciss->user = NULL;
  ciss->pass = NULL;
  ciss->host = NULL;
  ciss->port = 0;

  if (strncmp (src, "//", 2) != 0)
  {
    ciss->path = src;
    return url_pct_decode (ciss->path);
  }

  src += 2;

  if ((ciss->path = strchr (src, '/')))
    *ciss->path++ = '\0';

  if ((t = strrchr (src, '@')))
  {
    *t = '\0';
    if ((p = strchr (src, ':')))
    {
      *p = '\0';
      ciss->pass = p + 1;
      if (url_pct_decode (ciss->pass) < 0)
	return -1;
    }
    ciss->user = src;
    if (url_pct_decode (ciss->user) < 0)
      return -1;
    t++;
  }
  else
    t = src;

  if ((p = strchr (t, ':')))
  {
    int t;
    *p++ = '\0';
    if (mutt_atoi (p, &t) < 0 || t < 0 || t > 0xffff)
      return -1;
    ciss->port = (unsigned short)t;
  }
  else
    ciss->port = 0;

  ciss->host = t;
  return url_pct_decode (ciss->host) >= 0 &&
    (!ciss->path || url_pct_decode (ciss->path) >= 0) ? 0 : -1;
}
예제 #2
0
파일: url.c 프로젝트: Wuodan/mutt-kz
int url_parse_file (char *d, const char *src, size_t dl)
{
  if (ascii_strncasecmp (src, "file:", 5))
    return -1;
  else if (!ascii_strncasecmp (src, "file://", 7))	/* we don't support remote files */
    return -1;
  else
    strfcpy (d, src + 5, dl);

  return url_pct_decode (d);
}
예제 #3
0
static int url_parse_query(char *url, char **filename, struct uri_tag **tags)
{
    char *p = strstr(url, "://");	/* remote unsupported */
    char *e;
    struct uri_tag *tag, *last = NULL;

    *filename = NULL;
    *tags = NULL;

    if (!p || !*(p + 3))
        return -1;

    p += 3;
    *filename = p;

    e = strchr(p, '?');

    *filename = e ? e == p ? NULL : strndup(p, e - p) : safe_strdup(p);
    if (!e)
        return 0;

    if (*filename && url_pct_decode(*filename) < 0)
        goto err;
    if (!e)
        return 0;	/* only filename */

    ++e;	/* skip '?' */
    p = e;

    while (p && *p) {
        tag = safe_calloc(1, sizeof(struct uri_tag));
        if (!tag)
            goto err;

        if (!*tags)
            last = *tags = tag;
        else {
            last->next = tag;
            last = tag;
        }

        e = strchr(p, '=');
        if (!e)
            e = strchr(p, '&');
        tag->name = e ? strndup(p, e - p) : safe_strdup(p);
        if (!tag->name || url_pct_decode(tag->name) < 0)
            goto err;
        if (!e)
            break;

        p = e + 1;

        if (*e == '&')
            continue;

        e = strchr(p, '&');
        tag->value = e ? strndup(p, e - p) : safe_strdup(p);
        if (!tag->value || url_pct_decode(tag->value) < 0)
            goto err;
        if (!e)
            break;
        p = e + 1;
    }

    return 0;
err:
    FREE(&(*filename));
    url_free_tags(*tags);
    return -1;
}