return -1;
}
- while (getline(&buf, &n, fp)) {
+ while (getline(&buf, &n, fp) >= 0) {
nntp_parse_newsrc_line(news, buf);
}
p_delete(&buf);
return 0;
}
-static void nntp_cache_expand (char *dst, const char *src)
-{
- snprintf (dst, _POSIX_PATH_MAX, "%s/%s", NewsCacheDir, src);
- mutt_expand_path (dst, _POSIX_PATH_MAX);
-}
+#define nntp_cache_expand(dst, dlen, fmt, ...) \
+ do { \
+ snprintf((dst), (dlen), "%s/" fmt, NewsCacheDir, ##__VA_ARGS__); \
+ mutt_expand_path((dst), (dlen)); \
+ } while (0)
/* Loads $news_cache_dir/.index into memory, loads newsserver data
* and newsgroup cache names */
-static int nntp_parse_cacheindex (nntp_server_t * news)
+static int nntp_parse_cacheindex(nntp_server_t *news)
{
struct stat st;
char buf[HUGE_STRING], *cp;
mutt_expand_path (dir, sizeof (dir));
if (lstat (dir, &st) || (st.st_mode & S_IFDIR) == 0) {
- snprintf (buf, sizeof (buf), _("Directory %s not exist. Create it?"),
- dir);
+ snprintf(buf, sizeof(buf), _("Directory %s not exist. Create it?"), dir);
if (mutt_yesorno (buf, M_YES) != M_YES
|| mkdir (dir, (S_IRWXU + S_IRWXG + S_IRWXO))) {
mutt_error _("Cache directory not created!");
set_option (OPTNEWSCACHE);
p_delete(&news->cache);
- snprintf (buf, sizeof (buf), "%s/.index", dir);
+ snprintf(buf, sizeof (buf), "%s/%s.index", dir, news->conn->account.host);
if (!(idx = safe_fopen (buf, "a+")))
return 0;
rewind (idx);
return 0;
}
-const char *nntp_format_str(char *dest, ssize_t destlen, char op,
- const char *src, const char *fmt,
- const char *ifstr __attribute__((unused)),
- const char *elstr __attribute__((unused)),
- anytype data __attribute__((unused)),
- format_flag flags __attribute__((unused)))
-{
- char fn[STRING], tmp[STRING];
-
- switch (op) {
- case 's':
- m_strcpy(fn, sizeof (fn), NewsServer);
- m_strtolower(fn);
- snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
- snprintf (dest, destlen, tmp, fn);
- break;
- }
- return (src);
-}
-
/* nntp_parse_url: given an NNPT URL, return host, port,
* username, password and newsgroup will recognise. */
static int nntp_parse_url(const char *server, ACCOUNT * act, char *group,
char buf[HUGE_STRING];
FILE *f;
- nntp_cache_expand (buf, serv->cache);
+ nntp_cache_expand(buf, ssizeof(buf), "%s", serv->cache);
if ((f = safe_fopen (buf, "r"))) {
int i = 0;
if (!conn)
return NULL;
- m_strformat(file, sizeof(file), 0, NewsRc, nntp_format_str, NULL, 0);
- mutt_expand_path(file, sizeof(file));
-
+ nntp_cache_expand(file, sizeof(file), "%s.newsrc", conn->account.host);
serv = (nntp_server_t *) conn->data;
if (serv) {
struct stat sb;
int fd;
FILE *fp;
- nntp_cache_expand (buf, s);
+ nntp_cache_expand(buf, ssizeof(buf), "%s", s);
if ((fp = safe_fopen (buf, "w")))
return fp;
- nntp_cache_expand (buf, "cache-XXXXXX");
+ nntp_cache_expand(buf, ssizeof(buf), "cache-XXXXXX");
pc = buf + m_strlen(buf) - 12; /* positioning to "cache-XXXXXX" */
if ((fd = mkstemp (buf)) == -1)
return NULL;
snprintf (buf, sizeof (buf), "ALL %s 0 %d", file,
(int) serv->newgroups_time);
}
- nntp_cache_expand (file, ".index");
- return mutt_update_list_file (file, serv->conn->account.host, key, buf);
+ nntp_cache_expand(file, ssizeof(file), "%s.index", serv->conn->account.host);
+ return mutt_update_list_file(file, serv->conn->account.host, key, buf);
}
static void nntp_delete_cache (nntp_data_t * data)
if (!option (OPTNEWSCACHE) || !data || !data->cache || !data->nserv)
return;
- nntp_cache_expand (buf, data->cache);
+ nntp_cache_expand(buf, ssizeof(buf), "%s", data->cache);
unlink (buf);
p_delete(&data->cache);
data->lastCached = 0;
- nntp_cache_expand (buf, ".index");
- mutt_update_list_file (buf, data->nserv->conn->account.host, data->group,
- NULL);
+ nntp_cache_expand(buf, ssizeof(buf), "%s.index",
+ data->nserv->conn->account.host);
+ mutt_update_list_file(buf, data->nserv->conn->account.host, data->group,
+ NULL);
}
/* Remove cache files of unsubscribed newsgroups */
return 0;
if (news->cache) {
- nntp_cache_expand (file, news->cache);
- unlink (file);
- f = safe_fopen (file, "w");
- }
- else {
- m_strcpy(buf, sizeof(buf), news->conn->account.host);
- f = mutt_mkname (buf);
+ nntp_cache_expand(file, ssizeof(file), "%s", news->cache);
+ unlink(file);
+ f = safe_fopen(file, "w");
+ } else {
+ m_strcpy(buf, ssizeof(buf), news->conn->account.host);
+ f = mutt_mkname(buf);
news->cache = m_strdup(buf);
- nntp_cache_expand (file, buf);
+ nntp_cache_expand(file, ssizeof(file), "%s", buf);
}
if (!f)
return -1;
return -1;
if (((nntp_data_t *) ctx->data)->cache) {
- nntp_cache_expand (file, ((nntp_data_t *) ctx->data)->cache);
+ nntp_cache_expand(file, ssizeof(file), "%s",
+ ((nntp_data_t *)ctx->data)->cache);
unlink (file);
f = safe_fopen (file, "w");
}
else {
- snprintf (buf, sizeof (buf), "%s-%s",
- ((nntp_data_t *) ctx->data)->nserv->conn->account.host,
- ((nntp_data_t *) ctx->data)->group);
+ snprintf(buf, ssizeof(buf), "%s-%s",
+ ((nntp_data_t *)ctx->data)->nserv->conn->account.host,
+ ((nntp_data_t *)ctx->data)->group);
f = mutt_mkname (buf);
- ((nntp_data_t *) ctx->data)->cache = m_strdup(buf);
- nntp_cache_expand (file, buf);
+ ((nntp_data_t *)ctx->data)->cache = m_strdup(buf);
+ nntp_cache_expand(file, ssizeof(file), "%s", buf);
}
if (!f)
return -1;
/* CACHE: must be loaded xover cache here */
num = nntp_data->lastCached - first + 1;
if (option (OPTNEWSCACHE) && nntp_data->cache && num > 0) {
- nntp_cache_expand (buf, nntp_data->cache);
+ nntp_cache_expand(buf, ssizeof(buf), "%s", nntp_data->cache);
mutt_message (msg2);
if ((f = safe_fopen (buf, "r"))) {