#define NNTP_PORT 119
#define NNTP_SSL_PORT 563
-static unsigned int _checked = 0;
+static struct {
+ unsigned use_cache : 1;
+
+ int checked;
+} nntp = { true, 0 };
static int nntp_check_newgroups (nntp_server_t *, int);
* and newsgroup cache names */
static int nntp_parse_cacheindex(nntp_server_t *news)
{
- nntp_data_t *data;
- char file[_POSIX_PATH_MAX], buf[HUGE_STRING], *cp;
- FILE *idx;
- int l, m, t;
+ char buf[HUGE_STRING];
+ FILE *idx;
+
+ p_delete(&news->cache);
+ if (m_strisempty(mod_core.cachedir))
+ return 0;
+
+ nntp_cache_expand(buf, sizeof(buf), "%s.index", news->conn->account.host);
+ if (!(idx = safe_fopen(buf, "a+")))
+ return 0;
+ rewind(idx);
+
+ while (fgets(buf, sizeof(buf), idx)) {
+ buf[m_strlen(buf) - 1] = 0; /* strip ending '\n' */
+ if (!m_strncmp(buf, "#: ", 3)
+ && !m_strcasecmp(buf + 3, news->conn->account.host)) {
+ break;
+ }
+ }
- if (m_strisempty(mod_core.cachedir)) {
- unset_option(OPTNEWSCACHE);
- return 0;
- } else {
- set_option(OPTNEWSCACHE);
- }
+ while (fgets(buf, sizeof(buf), idx)) {
+ char *p, *q;
+ int l, m, t;
- p_delete(&news->cache);
- nntp_cache_expand(buf, sizeof(buf), "%s.index", news->conn->account.host);
- if (!(idx = safe_fopen (buf, "a+")))
- return 0;
- rewind (idx);
- while (fgets (buf, sizeof (buf), idx)) {
- buf[m_strlen(buf) - 1] = 0; /* strip ending '\n' */
- if (!m_strncmp(buf, "#: ", 3) &&
- !m_strcasecmp(buf + 3, news->conn->account.host))
- break;
- }
- while (fgets (buf, sizeof (buf), idx)) {
- cp = buf;
- while (*cp && *cp != ' ')
- cp++;
- if (!*cp)
- continue;
- cp[0] = 0;
- if (!m_strcmp(buf, "#:"))
- break;
- sscanf (cp + 1, "%s %d %d", file, &l, &m);
- if (!m_strcmp(buf, "ALL")) {
- news->cache = m_strdup(file);
- news->newgroups_time = m;
- }
- else if (news->newsgroups) {
- if ((data = hash_find (news->newsgroups, buf)) == NULL) {
- data = nntp_data_new();
- data->group = m_strdup(buf);
- data->nserv = news;
- data->deleted = 1;
- if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
- hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
- hash_insert (news->newsgroups, data->group, data);
- nntp_data_list_append(&news->list, data);
- }
- data->cache = m_strdup(file);
- t = 0;
- if (!data->firstMessage || data->lastMessage < m)
- t = 1;
- if (!data->firstMessage)
- data->firstMessage = l;
- if (data->lastMessage < m)
- data->lastMessage = m;
- data->lastCached = m;
- if (t || !data->unread)
- mutt_newsgroup_stat (data);
+ if (m_strstart(buf, "#:", NULL))
+ break;
+
+ p = strchrnul(buf, ' ');
+ if (!*p)
+ continue;
+ *p++ = '\0';
+ p = vskipspaces(p);
+ q = strchrnul(p, ' ');
+ if (!*q)
+ continue;
+ *q++ = '\0';
+ l = strtol(q, &q, 10);
+ m = strtol(q, &q, 10);
+
+ if (!m_strcmp(buf, "ALL")) {
+ m_strreplace(&news->cache, m_strdup(p));
+ news->newgroups_time = m;
+ continue;
+ }
+
+ if (news->newsgroups) {
+ nntp_data_t *data = hash_find(news->newsgroups, buf);
+
+ if (!data) {
+ data = nntp_data_new();
+ data->group = m_strdup(buf);
+ data->nserv = news;
+ data->deleted = 1;
+ if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
+ hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
+ hash_insert (news->newsgroups, data->group, data);
+ nntp_data_list_append(&news->list, data);
+ }
+ m_strreplace(&data->cache, p);
+
+ t = !data->firstMessage || data->lastMessage < m;
+ if (!data->firstMessage)
+ data->firstMessage = l;
+ if (data->lastMessage < m)
+ data->lastMessage = m;
+ data->lastCached = m;
+ if (t || !data->unread)
+ mutt_newsgroup_stat(data);
+ }
}
- }
- m_fclose(&idx);
- return 0;
+
+ m_fclose(&idx);
+ return 0;
}
/* nntp_parse_url: given an NNPT URL, return host, port,
nntp_data_t *nntp_data;
static int n = 0;
- _checked = n; /* _checked have N, where N = number of groups */
- if (!buf) /* at EOF must be zerouth */
+ nntp.checked = n; /* nntp.checked have N, where N = number of groups */
+ if (!buf) /* at EOF must be zerouth */
n = 0;
if (!s || !buf)
serv->newsgroups = hash_new(1009, false);
slurp_newsrc (serv); /* load .newsrc */
nntp_parse_cacheindex (serv); /* load .index */
- if (option (OPTNEWSCACHE) && serv->cache && nntp_get_cache_all (serv) >= 0)
+ if (nntp.use_cache && serv->cache && nntp_get_cache_all (serv) >= 0)
nntp_check_newgroups (serv, 1);
else if (nntp_get_active (serv) < 0) {
hash_delete(&serv->newsgroups, NULL);
{
char buf[_POSIX_PATH_MAX];
- if (!option (OPTNEWSCACHE) || !data || !data->cache || !data->nserv)
+ if (!nntp.use_cache || !data || !data->cache || !data->nserv)
return;
nntp_cache_expand(buf, ssizeof(buf), "%s", data->cache);
if (!news || !news->newsgroups)
return -1;
- if (!option (OPTNEWSCACHE))
+ if (!nntp.use_cache)
return 0;
if (news->cache) {
int i = 0, save = SORT_ORDER;
int prev = 0;
- if (!option (OPTNEWSCACHE))
+ if (!nntp.use_cache)
return 0;
if (!ctx || !ctx->data || ctx->magic != M_NNTP)
return -1;
/* CACHE: must be loaded xover cache here */
num = nntp_data->lastCached - first + 1;
- if (option (OPTNEWSCACHE) && nntp_data->cache && num > 0) {
+ if (nntp.use_cache && nntp_data->cache && num > 0) {
nntp_cache_expand(buf, ssizeof(buf), "%s", nntp_data->cache);
mutt_message (msg2);
if (*emp)
nntp_save_cache_index(serv);
mutt_clear_error();
- return _checked;
+ return nntp.checked;
}
/* Load list of all newsgroups from active */
nntp_save_cache_index (serv);
mutt_clear_error ();
- return _checked;
+ return nntp.checked;
}
/*
* made sure that we dont have the article, so we need to visit
* the server. Reading the cache at this point is also bad
* because it would duplicate messages */
- if (option (OPTNEWSCACHE)) {
+ if (nntp.use_cache) {
tmp++;
- unset_option (OPTNEWSCACHE);
+ nntp.use_cache = false;
}
for (i = 0; i < cc.num; i++) {
if ((ret = nntp_fetch_headers (ctx, cc.child[i], cc.child[i])))
ctx->hdrs[ctx->msgcount - 1]->read = 0;
}
if (tmp)
- set_option (OPTNEWSCACHE);
+ nntp.use_cache = true;
p_delete(&cc.child);
return ret;
}