/**
* mutt_account_fromurl - fill account with information from url
*/
-int mutt_account_fromurl(struct Account *account, struct CissUrl *url)
+int mutt_account_fromurl(struct Account *account, struct Url *url)
{
/* must be present */
if (url->host)
* account until you've finished with url (make a copy of account if you need
* it for a while).
*/
-void mutt_account_tourl(struct Account *account, struct CissUrl *url)
+void mutt_account_tourl(struct Account *account, struct Url *url)
{
url->scheme = U_UNKNOWN;
url->user = NULL;
#ifndef _MUTT_ACCOUNT_H
#define _MUTT_ACCOUNT_H
-struct CissUrl;
+struct Url;
/**
* enum AccountType - account types
};
int mutt_account_match(const struct Account *a1, const struct Account *m2);
-int mutt_account_fromurl(struct Account *account, struct CissUrl *url);
-void mutt_account_tourl(struct Account *account, struct CissUrl *url);
+int mutt_account_fromurl(struct Account *account, struct Url *url);
+void mutt_account_tourl(struct Account *account, struct Url *url);
int mutt_account_getuser(struct Account *account);
int mutt_account_getlogin(struct Account *account);
int mutt_account_getpass(struct Account *account);
{
char host[STRING];
char path[_POSIX_PATH_MAX];
- struct CissUrl url;
+ struct Url url;
int len;
if (!account || !MessageCachedir || !*MessageCachedir || !dst || !dstlen)
return -1;
- /* make up a CissUrl we can turn into a string */
- memset(&url, 0, sizeof(struct CissUrl));
+ /* make up a Url we can turn into a string */
+ memset(&url, 0, sizeof(struct Url));
mutt_account_tourl(account, &url);
/*
* mutt_account_tourl() just sets up some pointers;
* if this ever changes, we have a memleak here
*/
url.path = NULL;
- if (url_ciss_tostring(&url, host, sizeof(host), U_PATH) < 0)
+ if (url_tostring(&url, host, sizeof(host), U_PATH) < 0)
{
mutt_debug(1, "bcache_path: URL to string failed\n");
return -1;
else if (state.imap_browse)
{
int n;
- struct CissUrl url;
+ struct Url url;
strfcpy(LastDir, state.entry[menu->current].name, sizeof(LastDir));
/* tack on delimiter here */
n = strlen(LastDir) + 1;
/* special case "" needs no delimiter */
- url_parse_ciss(&url, state.entry[menu->current].name);
+ url_parse(&url, state.entry[menu->current].name);
if (url.path && (state.entry[menu->current].delim != '\0') &&
(n < sizeof(LastDir)))
{
char buf[STRING];
char errstr[STRING];
struct Buffer err, token;
- struct CissUrl url;
+ struct Url url;
struct ImapList list;
if (idata->cmddata && idata->cmdtype == IMAP_CT_LIST)
url.path[strlen(url.path) - 1] = '\0';
if (mutt_strcmp(url.user, ImapUser) == 0)
url.user = NULL;
- url_ciss_tostring(&url, buf + 11, sizeof(buf) - 11, 0);
+ url_tostring(&url, buf + 11, sizeof(buf) - 11, 0);
safe_strcat(buf, sizeof(buf), "\"");
mutt_buffer_init(&token);
mutt_buffer_init(&err);
for (conn = mutt_socket_head(); conn; conn = conn->next)
{
- struct CissUrl url;
+ struct Url url;
char urlstr[LONG_STRING];
if (conn->account.type != MUTT_ACCT_TYPE_IMAP)
/* FIXME: how to handle multiple users on the same host? */
url.user = NULL;
url.path = NULL;
- url_ciss_tostring(&url, urlstr, sizeof(urlstr), 0);
+ url_tostring(&url, urlstr, sizeof(urlstr), 0);
if (mutt_strncmp(dest, urlstr, matchlen) == 0)
{
if (rc)
* and absolute form. The buffer is rewritten in place with the canonical IMAP
* path.
*
- * Function can fail if imap_parse_path() or url_ciss_tostring() fail,
+ * Function can fail if imap_parse_path() or url_tostring() fail,
* of if the buffer isn't large enough.
*/
int imap_expand_path(char *path, size_t len)
{
struct ImapMbox mx;
struct ImapData *idata = NULL;
- struct CissUrl url;
+ struct Url url;
char fixedpath[LONG_STRING];
int rc;
imap_fix_path(idata, mx.mbox, fixedpath, sizeof(fixedpath));
url.path = fixedpath;
- rc = url_ciss_tostring(&url, path, len, U_DECODE_PASSWD);
+ rc = url_tostring(&url, path, len, U_DECODE_PASSWD);
FREE(&mx.mbox);
return rc;
header_cache_t *imap_hcache_open(struct ImapData *idata, const char *path)
{
struct ImapMbox mx;
- struct CissUrl url;
+ struct Url url;
char cachepath[LONG_STRING];
char mbox[LONG_STRING];
mutt_account_tourl(&idata->conn->account, &url);
url.path = mbox;
- url_ciss_tostring(&url, cachepath, sizeof(cachepath), U_PATH);
+ url_tostring(&url, cachepath, sizeof(cachepath), U_PATH);
return mutt_hcache_open(HeaderCache, cachepath, imap_hcache_namer);
}
static unsigned short ImapsPort = 0;
struct servent *service = NULL;
char tmp[128];
- struct CissUrl url;
+ struct Url url;
char *c = NULL;
int n;
mx->account.type = MUTT_ACCT_TYPE_IMAP;
c = safe_strdup(path);
- url_parse_ciss(&url, c);
+ url_parse(&url, c);
if (url.scheme == U_IMAP || url.scheme == U_IMAPS)
{
if (mutt_account_fromurl(&mx->account, &url) < 0 || !*mx->account.host)
void imap_pretty_mailbox(char *path)
{
struct ImapMbox home, target;
- struct CissUrl url;
+ struct Url url;
char *delim = NULL;
int tlen;
int hlen = 0;
/* FIXME: That hard-coded constant is bogus. But we need the actual
* size of the buffer from mutt_pretty_mailbox. And these pretty
* operations usually shrink the result. Still... */
- url_ciss_tostring(&url, path, 1024, 0);
+ url_tostring(&url, path, 1024, 0);
}
FREE(&target.mbox);
*/
void imap_qualify_path(char *dest, size_t len, struct ImapMbox *mx, char *path)
{
- struct CissUrl url;
+ struct Url url;
mutt_account_tourl(&mx->account, &url);
url.path = path;
- url_ciss_tostring(&url, dest, len, 0);
+ url_tostring(&url, dest, len, 0);
}
/**
struct Connection *mutt_conn_find(const struct Connection *start, const struct Account *account)
{
struct Connection *conn = NULL;
- struct CissUrl url;
+ struct Url url;
char hook[LONG_STRING];
/* account isn't actually modified, since url isn't either */
mutt_account_tourl((struct Account *) account, &url);
url.path = NULL;
- url_ciss_tostring(&url, hook, sizeof(hook), 0);
+ url_tostring(&url, hook, sizeof(hook), 0);
mutt_account_hook(hook);
conn = start ? start->next : Connections;
/* server subdirectory */
if (acct)
{
- struct CissUrl url;
+ struct Url url;
mutt_account_tourl(acct, &url);
url.path = src;
- url_ciss_tostring(&url, file, sizeof(file), U_PATH);
+ url_tostring(&url, file, sizeof(file), U_PATH);
}
else
strfcpy(file, src ? src : "", sizeof(file));
*/
void nntp_expand_path(char *line, size_t len, struct Account *acct)
{
- struct CissUrl url;
+ struct Url url;
mutt_account_tourl(acct, &url);
url.path = safe_strdup(line);
- url_ciss_tostring(&url, line, len, 0);
+ url_tostring(&url, line, len, 0);
FREE(&url.path);
}
*/
header_cache_t *nntp_hcache_open(struct NntpData *nntp_data)
{
- struct CissUrl url;
+ struct Url url;
char file[_POSIX_PATH_MAX];
if (!nntp_data->nserv || !nntp_data->nserv->cacheable ||
mutt_account_tourl(&nntp_data->nserv->conn->account, &url);
url.path = nntp_data->group;
- url_ciss_tostring(&url, file, sizeof(file), U_PATH);
+ url_tostring(&url, file, sizeof(file), U_PATH);
return mutt_hcache_open(NewsCacheDir, file, nntp_hcache_namer);
}
{
struct NntpServer *nserv = (struct NntpServer *) data;
struct Account *acct = &nserv->conn->account;
- struct CissUrl url;
+ struct Url url;
char fn[SHORT_STRING], tmp[SHORT_STRING], *p = NULL;
switch (op)
{
case 'a':
mutt_account_tourl(acct, &url);
- url_ciss_tostring(&url, fn, sizeof(fn), U_PATH);
+ url_tostring(&url, fn, sizeof(fn), U_PATH);
p = strchr(fn, '/');
if (p)
*p = '\0';
break;
case 'S':
mutt_account_tourl(acct, &url);
- url_ciss_tostring(&url, fn, sizeof(fn), U_PATH);
+ url_tostring(&url, fn, sizeof(fn), U_PATH);
p = strchr(fn, ':');
if (p)
*p = '\0';
struct NntpServer *nserv = NULL;
struct NntpData *nntp_data = NULL;
struct Connection *conn = NULL;
- struct CissUrl url;
+ struct Url url;
if (!server || !*server)
{
acct.port = NNTP_PORT;
acct.type = MUTT_ACCT_TYPE_NNTP;
snprintf(file, sizeof(file), "%s%s", strstr(server, "://") ? "" : "news://", server);
- if (url_parse_ciss(&url, file) < 0 || (url.path && *url.path) ||
+ if (url_parse(&url, file) < 0 || (url.path && *url.path) ||
!(url.scheme == U_NNTP || url.scheme == U_NNTPS) ||
mutt_account_fromurl(&acct, &url) < 0)
{
int rc;
void *hc = NULL;
anum_t first, last, count = 0;
- struct CissUrl url;
+ struct Url url;
strfcpy(buf, ctx->path, sizeof(buf));
- if (url_parse_ciss(&url, buf) < 0 || !url.path ||
+ if (url_parse(&url, buf) < 0 || !url.path ||
!(url.scheme == U_NNTP || url.scheme == U_NNTPS))
{
mutt_error(_("%s is an invalid newsgroup specification!"), ctx->path);
group = url.path;
url.path = strchr(url.path, '\0');
- url_ciss_tostring(&url, server, sizeof(server), 0);
+ url_tostring(&url, server, sizeof(server), 0);
nserv = nntp_select_server(server, 1);
if (!nserv)
return -1;
static header_cache_t *pop_hcache_open(struct PopData *pop_data, const char *path)
{
- struct CissUrl url;
+ struct Url url;
char p[LONG_STRING];
if (!pop_data || !pop_data->conn)
mutt_account_tourl(&pop_data->conn->account, &url);
url.path = HC_FNAME;
- url_ciss_tostring(&url, p, sizeof(p), U_PATH);
+ url_tostring(&url, p, sizeof(p), U_PATH);
return mutt_hcache_open(HeaderCache, p, pop_hcache_namer);
}
#endif
struct Connection *conn = NULL;
struct Account acct;
struct PopData *pop_data = NULL;
- struct CissUrl url;
+ struct Url url;
if (pop_parse_path(ctx->path, &acct))
{
mutt_account_tourl(&acct, &url);
url.path = NULL;
- url_ciss_tostring(&url, buf, sizeof(buf), 0);
+ url_tostring(&url, buf, sizeof(buf), 0);
conn = mutt_conn_find(NULL, &acct);
if (!conn)
return -1;
*/
int pop_parse_path(const char *path, struct Account *acct)
{
- struct CissUrl url;
+ struct Url url;
char *c = NULL;
struct servent *service = NULL;
acct->port = 0;
c = safe_strdup(path);
- url_parse_ciss(&url, c);
+ url_parse(&url, c);
if ((url.scheme != U_POP && url.scheme != U_POPS) || mutt_account_fromurl(acct, &url) < 0)
{
static unsigned short SmtpPort = 0;
struct servent *service = NULL;
- struct CissUrl url;
+ struct Url url;
char *urlstr = NULL;
account->flags = 0;
account->type = MUTT_ACCT_TYPE_SMTP;
urlstr = safe_strdup(SmtpUrl);
- url_parse_ciss(&url, urlstr);
+ url_parse(&url, urlstr);
if ((url.scheme != U_SMTP && url.scheme != U_SMTPS) ||
mutt_account_fromurl(account, &url) < 0)
{
}
/**
- * ciss_parse_userhost - fill in components of ciss with info from src
+ * parse_userhost - fill in components of Url 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(struct CissUrl *ciss, char *src)
+static int parse_userhost(struct Url *u, char *src)
{
char *t = NULL, *p = NULL;
- ciss->user = NULL;
- ciss->pass = NULL;
- ciss->host = NULL;
- ciss->port = 0;
+ u->user = NULL;
+ u->pass = NULL;
+ u->host = NULL;
+ u->port = 0;
if (strncmp(src, "//", 2) != 0)
{
- ciss->path = src;
- return url_pct_decode(ciss->path);
+ u->path = src;
+ return url_pct_decode(u->path);
}
src += 2;
- if ((ciss->path = strchr(src, '/')))
- *ciss->path++ = '\0';
+ if ((u->path = strchr(src, '/')))
+ *u->path++ = '\0';
if ((t = strrchr(src, '@')))
{
if ((p = strchr(src, ':')))
{
*p = '\0';
- ciss->pass = p + 1;
- if (url_pct_decode(ciss->pass) < 0)
+ u->pass = p + 1;
+ if (url_pct_decode(u->pass) < 0)
return -1;
}
- ciss->user = src;
- if (url_pct_decode(ciss->user) < 0)
+ u->user = src;
+ if (url_pct_decode(u->user) < 0)
return -1;
src = t + 1;
}
*p++ = '\0';
if (mutt_atoi(p, &num) < 0 || num < 0 || num > 0xffff)
return -1;
- ciss->port = (unsigned short) num;
+ u->port = (unsigned short) num;
}
else
- ciss->port = 0;
+ u->port = 0;
- ciss->host = src;
- return url_pct_decode(ciss->host) >= 0 &&
- (!ciss->path || url_pct_decode(ciss->path) >= 0) ?
- 0 :
- -1;
+ u->host = src;
+ return url_pct_decode(u->host) >= 0 && (!u->path || url_pct_decode(u->path) >= 0) ? 0 : -1;
}
/**
- * url_parse_ciss - Fill in CissUrl
+ * url_parse - Fill in Url
*
* char* elements are pointers into src, which is modified by this call
* (duplicate it first if you need to).
*/
-int url_parse_ciss(struct CissUrl *ciss, char *src)
+int url_parse(struct Url *u, char *src)
{
char *tmp = NULL;
- if ((ciss->scheme = url_check_scheme(src)) == U_UNKNOWN)
+ if ((u->scheme = url_check_scheme(src)) == U_UNKNOWN)
return -1;
tmp = strchr(src, ':') + 1;
- return ciss_parse_userhost(ciss, tmp);
+ return parse_userhost(u, tmp);
}
void url_pct_encode(char *dst, size_t l, const char *src)
}
/**
- * url_ciss_tostring - output the URL string for a given CISS object
+ * url_tostring - output the URL string for a given Url object
*/
-int url_ciss_tostring(struct CissUrl *ciss, char *dest, size_t len, int flags)
+int url_tostring(struct Url *u, char *dest, size_t len, int flags)
{
long l;
- if (ciss->scheme == U_UNKNOWN)
+ if (u->scheme == U_UNKNOWN)
return -1;
- snprintf(dest, len, "%s:", mutt_getnamebyvalue(ciss->scheme, UrlMap));
+ snprintf(dest, len, "%s:", mutt_getnamebyvalue(u->scheme, UrlMap));
- if (ciss->host)
+ if (u->host)
{
if (!(flags & U_PATH))
safe_strcat(dest, len, "//");
len -= (l = strlen(dest));
dest += l;
- if (ciss->user && (ciss->user[0] || !(flags & U_PATH)))
+ if (u->user && (u->user[0] || !(flags & U_PATH)))
{
- char u[STRING];
- url_pct_encode(u, sizeof(u), ciss->user);
+ char str[STRING];
+ url_pct_encode(str, sizeof(str), u->user);
- if (flags & U_DECODE_PASSWD && ciss->pass)
+ if (flags & U_DECODE_PASSWD && u->pass)
{
char p[STRING];
- url_pct_encode(p, sizeof(p), ciss->pass);
- snprintf(dest, len, "%s:%s@", u, p);
+ url_pct_encode(p, sizeof(p), u->pass);
+ snprintf(dest, len, "%s:%s@", str, p);
}
else
- snprintf(dest, len, "%s@", u);
+ snprintf(dest, len, "%s@", str);
len -= (l = strlen(dest));
dest += l;
}
- if (strchr(ciss->host, ':'))
- snprintf(dest, len, "[%s]", ciss->host);
+ if (strchr(u->host, ':'))
+ snprintf(dest, len, "[%s]", u->host);
else
- snprintf(dest, len, "%s", ciss->host);
+ snprintf(dest, len, "%s", u->host);
len -= (l = strlen(dest));
dest += l;
- if (ciss->port)
- snprintf(dest, len, ":%hu/", ciss->port);
+ if (u->port)
+ snprintf(dest, len, ":%hu/", u->port);
else
snprintf(dest, len, "/");
}
- if (ciss->path)
- safe_strcat(dest, len, ciss->path);
+ if (u->path)
+ safe_strcat(dest, len, u->path);
return 0;
}
#define U_PATH (1 << 1)
/**
- * struct CissUrl - A parsed URL `proto://user:password@host/path`
+ * struct Url - A parsed URL `proto://user:password@host:port/path`
*/
-struct CissUrl
+struct Url
{
enum UrlScheme scheme;
char *user;
};
enum UrlScheme url_check_scheme(const char *s);
-int url_parse_ciss(struct CissUrl *ciss, char *src);
-int url_ciss_tostring(struct CissUrl *ciss, char *dest, size_t len, int flags);
+int url_parse(struct Url *u, char *src);
+int url_tostring(struct Url *u, char *dest, size_t len, int flags);
int url_parse_mailto(struct Envelope *e, char **body, const char *src);
int url_pct_decode(char *s);
void url_pct_encode(char *dest, size_t len, const char *src);