#include "sasl.h"
#endif
-int getdnsdomainname(char *d, size_t len);
+int getdnsdomainname(char *buf, size_t buflen);
#endif /* _CONN_CONN_H */
/**
* getdnsdomainname - Lookup the host's name using DNS
- * @param d Buffer for the result
- * @param len Length of the buffer
+ * @param buf Buffer for the result
+ * @param buflen Length of the buffer
* @retval 0 Success
* @retval -1 Error
*/
-int getdnsdomainname(char *d, size_t len)
+int getdnsdomainname(char *buf, size_t buflen)
{
int rc = -1;
struct addrinfo hints;
struct addrinfo *h = NULL;
- *d = '\0';
+ *buf = '\0';
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_flags = AI_CANONNAME;
hints.ai_family = AF_UNSPEC;
char *p = NULL;
if (h && h->ai_canonname && (p = strchr(h->ai_canonname, '.')))
{
- mutt_str_strfcpy(d, ++p, len);
+ mutt_str_strfcpy(buf, ++p, buflen);
rc = 0;
- mutt_debug(1, "Hostname: %s\n", d);
+ mutt_debug(1, "Hostname: %s\n", buf);
freeaddrinfo(h);
}
/**
* mutt_sasl_conn_read - Read data from an SASL connection
- * @param conn Connection to a server
- * @param buf Buffer to store the data
- * @param len Number of bytes to read
+ * @param conn Connection to a server
+ * @param buf Buffer to store the data
+ * @param buflen Number of bytes to read
* @retval >0 Success, number of bytes read
* @retval -1 Error, see errno
*/
-static int mutt_sasl_conn_read(struct Connection *conn, char *buf, size_t len)
+static int mutt_sasl_conn_read(struct Connection *conn, char *buf, size_t buflen)
{
int rc;
unsigned int olen;
/* if we still have data in our read buffer, copy it into buf */
if (sasldata->blen > sasldata->bpos)
{
- olen = (sasldata->blen - sasldata->bpos > len) ? len :
+ olen = (sasldata->blen - sasldata->bpos > buflen) ? buflen :
sasldata->blen - sasldata->bpos;
memcpy(buf, sasldata->buf + sasldata->bpos, olen);
do
{
/* call the underlying read function to fill the buffer */
- rc = (sasldata->msasl_read)(conn, buf, len);
+ rc = (sasldata->msasl_read)(conn, buf, buflen);
if (rc <= 0)
goto out;
}
} while (sasldata->blen == 0);
- olen = (sasldata->blen - sasldata->bpos > len) ? len :
+ olen = (sasldata->blen - sasldata->bpos > buflen) ? buflen :
sasldata->blen - sasldata->bpos;
memcpy(buf, sasldata->buf, olen);
rc = olen;
}
else
- rc = (sasldata->msasl_read)(conn, buf, len);
+ rc = (sasldata->msasl_read)(conn, buf, buflen);
out:
conn->sockdata = sasldata;
/**
* mutt_sasl_conn_write - Write to an SASL connection
- * @param conn Connection to a server
- * @param buf Buffer to store the data
- * @param len Number of bytes to read
+ * @param conn Connection to a server
+ * @param buf Buffer to store the data
+ * @param buflen Number of bytes to read
* @retval >0 Success, number of bytes read
* @retval -1 Error, see errno
*/
-static int mutt_sasl_conn_write(struct Connection *conn, const char *buf, size_t len)
+static int mutt_sasl_conn_write(struct Connection *conn, const char *buf, size_t buflen)
{
int rc;
const char *pbuf = NULL;
/* handle data larger than MAXOUTBUF */
do
{
- olen = (len > *sasldata->pbufsize) ? *sasldata->pbufsize : len;
+ olen = (buflen > *sasldata->pbufsize) ? *sasldata->pbufsize : buflen;
rc = sasl_encode(sasldata->saslconn, buf, olen, &pbuf, &plen);
if (rc != SASL_OK)
if (rc != plen)
goto fail;
- len -= olen;
+ buflen -= olen;
buf += olen;
- } while (len > *sasldata->pbufsize);
+ } while (buflen > *sasldata->pbufsize);
}
else
{
/* just write using the underlying socket function */
- rc = (sasldata->msasl_write)(conn, buf, len);
+ rc = (sasldata->msasl_write)(conn, buf, buflen);
}
conn->sockdata = sasldata;
/**
* ssl_passwd_cb - Callback to get a password
* @param buf Buffer for the password
- * @param size Length of the buffer
+ * @param buflen Length of the buffer
* @param rwflag 0 if writing, 1 if reading (UNUSED)
* @param userdata Account whose password is requested
* @retval >0 Success, number of chars written to buf
* @retval 0 Error
*/
-static int ssl_passwd_cb(char *buf, int size, int rwflag, void *userdata)
+static int ssl_passwd_cb(char *buf, int buflen, int rwflag, void *userdata)
{
struct Account *account = (struct Account *) userdata;
if (mutt_account_getpass(account) < 0)
return 0;
- return snprintf(buf, size, "%s", account->pass);
+ return snprintf(buf, buflen, "%s", account->pass);
}
/**
/**
* tls_fingerprint - Create a fingerprint of a TLS Certificate
- * @param algo Fingerprint algorithm, e.g. GNUTLS_MAC_SHA256
- * @param s Buffer for the fingerprint
- * @param l Length of the buffer
+ * @param algo Fingerprint algorithm, e.g. GNUTLS_MAC_SHA256
+ * @param buf Buffer for the fingerprint
+ * @param buflen Length of the buffer
* @param data Certificate
*/
-static void tls_fingerprint(gnutls_digest_algorithm_t algo, char *s, int l,
+static void tls_fingerprint(gnutls_digest_algorithm_t algo, char *buf, size_t buflen,
const gnutls_datum_t *data)
{
unsigned char md[36];
if (gnutls_fingerprint(algo, data, (char *) md, &n) < 0)
{
- snprintf(s, l, _("[unable to calculate]"));
+ snprintf(buf, buflen, _("[unable to calculate]"));
}
else
{
{
char ch[8];
snprintf(ch, 8, "%02X%s", md[i], ((i % 2) ? " " : ""));
- mutt_str_strcat(s, l, ch);
+ mutt_str_strcat(buf, buflen, ch);
}
- s[2 * n + n / 2 - 1] = '\0'; /* don't want trailing space */
+ buf[2 * n + n / 2 - 1] = '\0'; /* don't want trailing space */
}
}
/**
* url_pct_encode - Percent-encode a string
- * @param dst Buffer for the result
- * @param l Length of buffer
+ * @param buf Buffer for the result
+ * @param buflen Length of buffer
* @param src String to encode
*
* e.g. turn "hello world" into "hello%20world"
*/
-void url_pct_encode(char *dst, size_t l, const char *src)
+void url_pct_encode(char *buf, size_t buflen, const char *src)
{
static const char *alph = "0123456789ABCDEF";
- *dst = 0;
- l--;
- while (src && *src && (l != 0))
+ *buf = 0;
+ buflen--;
+ while (src && *src && (buflen != 0))
{
if (strchr("/:&%", *src))
{
- if (l < 3)
+ if (buflen < 3)
break;
- *dst++ = '%';
- *dst++ = alph[(*src >> 4) & 0xf];
- *dst++ = alph[*src & 0xf];
+ *buf++ = '%';
+ *buf++ = alph[(*src >> 4) & 0xf];
+ *buf++ = alph[*src & 0xf];
src++;
- l -= 3;
+ buflen -= 3;
continue;
}
- *dst++ = *src++;
- l--;
+ *buf++ = *src++;
+ buflen--;
}
- *dst = 0;
+ *buf = 0;
}
/**
* url_tostring - Output the URL string for a given Url object
- * @param u Url to turn into a string
- * @param dest Buffer for the result
- * @param len Length of buffer
- * @param flags Flags, e.g. #U_DECODE_PASSWD
+ * @param u Url to turn into a string
+ * @param buf Buffer for the result
+ * @param buflen Length of buffer
+ * @param flags Flags, e.g. #U_DECODE_PASSWD
* @retval 0 Success
* @retval -1 Error
*/
-int url_tostring(struct Url *u, char *dest, size_t len, int flags)
+int url_tostring(struct Url *u, char *buf, size_t buflen, int flags)
{
if (u->scheme == U_UNKNOWN)
return -1;
- snprintf(dest, len, "%s:", mutt_map_get_name(u->scheme, UrlMap));
+ snprintf(buf, buflen, "%s:", mutt_map_get_name(u->scheme, UrlMap));
if (u->host)
{
if (!(flags & U_PATH))
- mutt_str_strcat(dest, len, "//");
- size_t l = strlen(dest);
- len -= l;
- dest += l;
+ mutt_str_strcat(buf, buflen, "//");
+ size_t l = strlen(buf);
+ buflen -= l;
+ buf += l;
if (u->user && (u->user[0] || !(flags & U_PATH)))
{
{
char p[STRING];
url_pct_encode(p, sizeof(p), u->pass);
- snprintf(dest, len, "%s:%s@", str, p);
+ snprintf(buf, buflen, "%s:%s@", str, p);
}
else
- snprintf(dest, len, "%s@", str);
+ snprintf(buf, buflen, "%s@", str);
- l = strlen(dest);
- len -= l;
- dest += l;
+ l = strlen(buf);
+ buflen -= l;
+ buf += l;
}
if (strchr(u->host, ':'))
- snprintf(dest, len, "[%s]", u->host);
+ snprintf(buf, buflen, "[%s]", u->host);
else
- snprintf(dest, len, "%s", u->host);
+ snprintf(buf, buflen, "%s", u->host);
- l = strlen(dest);
- len -= l;
- dest += l;
+ l = strlen(buf);
+ buflen -= l;
+ buf += l;
if (u->port)
- snprintf(dest, len, ":%hu/", u->port);
+ snprintf(buf, buflen, ":%hu/", u->port);
else
- snprintf(dest, len, "/");
+ snprintf(buf, buflen, "/");
}
if (u->path)
- mutt_str_strcat(dest, len, u->path);
+ mutt_str_strcat(buf, buflen, u->path);
return 0;
}
void url_free(struct Url *u);
int url_parse(struct Url *u, char *src);
int url_pct_decode(char *s);
-void url_pct_encode(char *dst, size_t l, const char *src);
-int url_tostring(struct Url *u, char *dest, size_t len, int flags);
+void url_pct_encode(char *buf, size_t buflen, const char *src);
+int url_tostring(struct Url *u, char *buf, size_t buflen, int flags);
#endif /* _EMAIL_URL_H */
* @param path Mailbox URI
* @param hidata Server data
* @param buf Buffer to store mailbox name
- * @param blen Length of buffer
+ * @param buflen Length of buffer
* @retval 0 Success
* @retval -1 Failure
*
* Split up a mailbox URI. The connection info is stored in the ImapData and
* the mailbox name is stored in buf.
*/
-static int get_mailbox(const char *path, struct ImapData **hidata, char *buf, size_t blen)
+static int get_mailbox(const char *path, struct ImapData **hidata, char *buf, size_t buflen)
{
struct ImapMbox mx;
return -1;
}
- imap_fix_path(*hidata, mx.mbox, buf, blen);
+ imap_fix_path(*hidata, mx.mbox, buf, buflen);
if (!*buf)
- mutt_str_strfcpy(buf, "INBOX", blen);
+ mutt_str_strfcpy(buf, "INBOX", buflen);
FREE(&mx.mbox);
return 0;
void imap_logout_all(void);
/* util.c */
-int imap_expand_path(char *path, size_t len);
+int imap_expand_path(char *buf, size_t buflen);
int imap_parse_path(const char *path, struct ImapMbox *mx);
void imap_pretty_mailbox(char *path);
char *imap_get_qualifier(char *buf);
int imap_mxcmp(const char *mx1, const char *mx2);
char *imap_next_word(char *s);
-void imap_qualify_path(char *dest, size_t len, struct ImapMbox *mx, char *path);
+void imap_qualify_path(char *buf, size_t buflen, struct ImapMbox *mx, char *path);
void imap_quote_string(char *dest, size_t dlen, const char *src, bool quote_backtick);
void imap_unquote_string(char *s);
void imap_munge_mbox_name(struct ImapData *idata, char *dest, size_t dlen, const char *src);
/**
* imap_expand_path - Canonicalise an IMAP path
- * @param path Buffer containing path
- * @param len Buffer length
+ * @param buf Buffer containing path
+ * @param buflen Buffer length
* @retval 0 Success
* @retval -1 Error
*
* 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)
+int imap_expand_path(char *buf, size_t buflen)
{
struct ImapMbox mx;
struct ImapData *idata = NULL;
char fixedpath[LONG_STRING];
int rc;
- if (imap_parse_path(path, &mx) < 0)
+ if (imap_parse_path(buf, &mx) < 0)
return -1;
idata = imap_conn_find(&mx.account, MUTT_IMAP_CONN_NONEW);
imap_fix_path(idata, mx.mbox, fixedpath, sizeof(fixedpath));
url.path = fixedpath;
- rc = url_tostring(&url, path, len, U_DECODE_PASSWD);
+ rc = url_tostring(&url, buf, buflen, U_DECODE_PASSWD);
FREE(&mx.mbox);
return rc;
/**
* imap_qualify_path - Make an absolute IMAP folder target
- * @param dest Buffer for the result
- * @param len Length of buffer
- * @param mx Imap mailbox
- * @param path Path relative to the mailbox
+ * @param buf Buffer for the result
+ * @param buflen Length of buffer
+ * @param mx Imap mailbox
+ * @param path Path relative to the mailbox
*
* given ImapMbox and relative path.
*/
-void imap_qualify_path(char *dest, size_t len, struct ImapMbox *mx, char *path)
+void imap_qualify_path(char *buf, size_t buflen, struct ImapMbox *mx, char *path)
{
struct Url url;
mutt_account_tourl(&mx->account, &url);
url.path = path;
- url_tostring(&url, dest, len, 0);
+ url_tostring(&url, buf, buflen, 0);
}
/**
/**
* mutt_file_read_keyword - Read a keyword from a file
* @param file File to read
- * @param buffer Buffer to store the keyword
- * @param buflen Length of the buffer
+ * @param buf Buffer to store the keyword
+ * @param buflen Length of the buf
* @retval ptr Start of the keyword
*
* Read one line from the start of a file.
* Skip any leading whitespace and extract the first token.
*/
-char *mutt_file_read_keyword(const char *file, char *buffer, size_t buflen)
+char *mutt_file_read_keyword(const char *file, char *buf, size_t buflen)
{
FILE *fp = mutt_file_fopen(file, "r");
if (!fp)
return NULL;
- buffer = fgets(buffer, buflen, fp);
+ buf = fgets(buf, buflen, fp);
mutt_file_fclose(&fp);
- if (!buffer)
+ if (!buf)
return NULL;
- SKIPWS(buffer);
- char *start = buffer;
+ SKIPWS(buf);
+ char *start = buf;
- while (*buffer && !isspace(*buffer))
- buffer++;
+ while (*buf && !isspace(*buf))
+ buf++;
- *buffer = '\0';
+ *buf = '\0';
return start;
}
#define mutt_file_mkstemp() mutt_file_mkstemp_full(__FILE__, __LINE__, __func__)
int mutt_file_open(const char *path, int flags);
size_t mutt_file_quote_filename(char *d, size_t l, const char *f);
-char * mutt_file_read_keyword(const char *file, char *buffer, size_t buflen);
+char * mutt_file_read_keyword(const char *file, char *buf, size_t buflen);
char * mutt_file_read_line(char *s, size_t *size, FILE *fp, int *line, int flags);
int mutt_file_rename(char *oldfile, char *newfile);
int mutt_file_rmtree(const char *path);
/**
* nntp_expand_path - Make fully qualified url from newsgroup name
- * @param line String containing newsgroup name
- * @param len Length of string
+ * @param buf Buffer containing newsgroup name
+ * @param buflen Length of buffer
* @param acct Account to save result
*/
-void nntp_expand_path(char *line, size_t len, struct Account *acct)
+void nntp_expand_path(char *buf, size_t buflen, struct Account *acct)
{
struct Url url;
mutt_account_tourl(acct, &url);
- url.path = mutt_str_strdup(line);
- url_tostring(&url, line, len, 0);
+ url.path = mutt_str_strdup(buf);
+ url_tostring(&url, buf, buflen, 0);
FREE(&url.path);
}
/**
* nntp_mailbox - Get first newsgroup with new messages
* @param buf Buffer for result
- * @param len Length of buffer
+ * @param buflen Length of buffer
*/
-void nntp_mailbox(char *buf, size_t len)
+void nntp_mailbox(char *buf, size_t buflen)
{
for (unsigned int i = 0; i < CurrentNewsSrv->groups_num; i++)
{
if (!unread)
continue;
}
- mutt_str_strfcpy(buf, nntp_data->group, len);
+ mutt_str_strfcpy(buf, nntp_data->group, buflen);
break;
}
}
int nntp_check_children(struct Context *ctx, const char *msgid);
int nntp_newsrc_parse(struct NntpServer *nserv);
void nntp_newsrc_close(struct NntpServer *nserv);
-void nntp_mailbox(char *buf, size_t len);
-void nntp_expand_path(char *line, size_t len, struct Account *acct);
+void nntp_mailbox(char *buf, size_t buflen);
+void nntp_expand_path(char *buf, size_t buflen, struct Account *acct);
void nntp_clear_cache(struct NntpServer *nserv);
const char *nntp_format_str(char *buf, size_t buflen, size_t col, int cols, char op,
const char *src, const char *prec, const char *if_str,
/**
* valid_smtp_code - Is the is a valid SMTP return code?
* @param[in] buf String to check
- * @param[in] len Length of string
+ * @param[in] buflen Length of string
* @param[out] n Numeric value of code
* @retval true Valid number
*/
-static bool valid_smtp_code(char *buf, size_t len, int *n)
+static bool valid_smtp_code(char *buf, size_t buflen, int *n)
{
char code[4];
- if (len < 4)
+ if (buflen < 4)
return false;
code[0] = buf[0];
code[1] = buf[1];