From: Richard Russon Date: Mon, 7 Aug 2017 15:46:07 +0000 (+0100) Subject: url drop ciss X-Git-Tag: neomutt-20170907~27^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c7cda5411e2e0383181506d7ef5d80474438ee6f;p=neomutt url drop ciss --- diff --git a/account.c b/account.c index 74a260fd9..c8fc17bb5 100644 --- a/account.c +++ b/account.c @@ -80,7 +80,7 @@ int mutt_account_match(const struct Account *a1, const struct Account *a2) /** * 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) @@ -114,7 +114,7 @@ int mutt_account_fromurl(struct Account *account, struct CissUrl *url) * 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; diff --git a/account.h b/account.h index baf758eab..59541d6c4 100644 --- a/account.h +++ b/account.h @@ -25,7 +25,7 @@ #ifndef _MUTT_ACCOUNT_H #define _MUTT_ACCOUNT_H -struct CissUrl; +struct Url; /** * enum AccountType - account types @@ -61,8 +61,8 @@ struct Account }; 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); diff --git a/bcache.c b/bcache.c index a02d90f65..51029c971 100644 --- a/bcache.c +++ b/bcache.c @@ -49,21 +49,21 @@ static int bcache_path(struct Account *account, const char *mailbox, char *dst, { 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; diff --git a/browser.c b/browser.c index d4b36d0c4..42b4c0530 100644 --- a/browser.c +++ b/browser.c @@ -1382,14 +1382,14 @@ void _mutt_select_file(char *f, size_t flen, int flags, char ***files, int *numf 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))) { diff --git a/imap/command.c b/imap/command.c index 894f1b704..a26b43aed 100644 --- a/imap/command.c +++ b/imap/command.c @@ -427,7 +427,7 @@ static void cmd_parse_lsub(struct ImapData *idata, char *s) 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) @@ -458,7 +458,7 @@ static void cmd_parse_lsub(struct ImapData *idata, char *s) 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); diff --git a/imap/imap.c b/imap/imap.c index 25d703d6a..f22d04d64 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -2082,7 +2082,7 @@ static int imap_complete_hosts(char *dest, size_t len) 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) @@ -2092,7 +2092,7 @@ static int imap_complete_hosts(char *dest, size_t len) /* 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) diff --git a/imap/util.c b/imap/util.c index bb6595bd0..1e0608924 100644 --- a/imap/util.c +++ b/imap/util.c @@ -68,14 +68,14 @@ * 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; @@ -87,7 +87,7 @@ int imap_expand_path(char *path, size_t len) 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; @@ -202,7 +202,7 @@ static int imap_hcache_namer(const char *path, char *dest, size_t dlen) 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]; @@ -219,7 +219,7 @@ header_cache_t *imap_hcache_open(struct ImapData *idata, const char *path) 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); } @@ -291,7 +291,7 @@ int imap_parse_path(const char *path, struct ImapMbox *mx) static unsigned short ImapsPort = 0; struct servent *service = NULL; char tmp[128]; - struct CissUrl url; + struct Url url; char *c = NULL; int n; @@ -320,7 +320,7 @@ int imap_parse_path(const char *path, struct ImapMbox *mx) 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) @@ -429,7 +429,7 @@ int imap_mxcmp(const char *mx1, const char *mx2) void imap_pretty_mailbox(char *path) { struct ImapMbox home, target; - struct CissUrl url; + struct Url url; char *delim = NULL; int tlen; int hlen = 0; @@ -473,7 +473,7 @@ void imap_pretty_mailbox(char *path) /* 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); @@ -752,12 +752,12 @@ void imap_make_date(char *buf, time_t timestamp) */ 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); } /** diff --git a/mutt_socket.c b/mutt_socket.c index 3f0b44c1d..d4bb01674 100644 --- a/mutt_socket.c +++ b/mutt_socket.c @@ -279,13 +279,13 @@ static struct Connection *socket_new_conn(void) 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; diff --git a/newsrc.c b/newsrc.c index 804db066d..d959870f9 100644 --- a/newsrc.c +++ b/newsrc.c @@ -513,11 +513,11 @@ static void cache_expand(char *dst, size_t dstlen, struct Account *acct, char *s /* 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)); @@ -536,11 +536,11 @@ static void cache_expand(char *dst, size_t dstlen, struct Account *acct, char *s */ 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); } @@ -669,7 +669,7 @@ static int nntp_hcache_namer(const char *path, char *dest, size_t destlen) */ 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 || @@ -679,7 +679,7 @@ header_cache_t *nntp_hcache_open(struct NntpData *nntp_data) 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); } @@ -872,14 +872,14 @@ const char *nntp_format_str(char *dest, size_t destlen, size_t col, int cols, { 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'; @@ -906,7 +906,7 @@ const char *nntp_format_str(char *dest, size_t destlen, size_t col, int cols, 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'; @@ -940,7 +940,7 @@ struct NntpServer *nntp_select_server(char *server, int leave_lock) struct NntpServer *nserv = NULL; struct NntpData *nntp_data = NULL; struct Connection *conn = NULL; - struct CissUrl url; + struct Url url; if (!server || !*server) { @@ -954,7 +954,7 @@ struct NntpServer *nntp_select_server(char *server, int leave_lock) 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) { diff --git a/nntp.c b/nntp.c index d98d54410..35afa5e38 100644 --- a/nntp.c +++ b/nntp.c @@ -1450,10 +1450,10 @@ static int nntp_open_mailbox(struct Context *ctx) 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); @@ -1463,7 +1463,7 @@ static int nntp_open_mailbox(struct Context *ctx) 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; diff --git a/pop.c b/pop.c index 1c4014faa..03a0e36a2 100644 --- a/pop.c +++ b/pop.c @@ -231,7 +231,7 @@ static int pop_hcache_namer(const char *path, char *dest, size_t destlen) 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) @@ -239,7 +239,7 @@ static header_cache_t *pop_hcache_open(struct PopData *pop_data, const char *pat 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 @@ -424,7 +424,7 @@ static int pop_open_mailbox(struct Context *ctx) 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)) { @@ -435,7 +435,7 @@ static int pop_open_mailbox(struct Context *ctx) 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; diff --git a/pop_lib.c b/pop_lib.c index 4bd71d2c1..9178f88b2 100644 --- a/pop_lib.c +++ b/pop_lib.c @@ -55,7 +55,7 @@ */ int pop_parse_path(const char *path, struct Account *acct) { - struct CissUrl url; + struct Url url; char *c = NULL; struct servent *service = NULL; @@ -65,7 +65,7 @@ int pop_parse_path(const char *path, struct Account *acct) 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) { diff --git a/smtp.c b/smtp.c index 99282f625..bef7e926d 100644 --- a/smtp.c +++ b/smtp.c @@ -283,7 +283,7 @@ static int smtp_fill_account(struct Account *account) static unsigned short SmtpPort = 0; struct servent *service = NULL; - struct CissUrl url; + struct Url url; char *urlstr = NULL; account->flags = 0; @@ -291,7 +291,7 @@ static int smtp_fill_account(struct Account *account) 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) { diff --git a/url.c b/url.c index d1c198e6f..f2e70ab67 100644 --- a/url.c +++ b/url.c @@ -98,30 +98,30 @@ enum UrlScheme url_check_scheme(const char *s) } /** - * 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, '@'))) { @@ -129,12 +129,12 @@ static int ciss_parse_userhost(struct CissUrl *ciss, char *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; } @@ -156,34 +156,31 @@ static int ciss_parse_userhost(struct CissUrl *ciss, char *src) *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) @@ -208,58 +205,58 @@ 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; } diff --git a/url.h b/url.h index 1940d1ca2..84243a50e 100644 --- a/url.h +++ b/url.h @@ -50,9 +50,9 @@ enum UrlScheme #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; @@ -63,8 +63,8 @@ struct CissUrl }; 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);