static int nntp_check_newgroups (nntp_server_t *, int);
+static void nntp_free_acache(nntp_data_t * data)
+{
+ for (int i = 0; i < countof(data->acache); i++) {
+ if (data->acache[i].path) {
+ unlink(data->acache[i].path);
+ p_delete(&data->acache[i].path);
+ }
+ }
+}
+
+void nntp_data_wipe(nntp_data_t *data)
+{
+ p_delete(&data->entries);
+ p_delete(&data->desc);
+ p_delete(&data->cache);
+ p_delete(&data->group);
+ nntp_free_acache(data);
+}
+
/* newsrc {{{ */
static void mutt_newsgroup_stat(nntp_data_t *data)
{
data->unread = 0;
- if (data->lastMessage == 0 || data->firstMessage > data->lastMessage)
+ if (data->last == 0 || data->first > data->last)
return;
- data->unread = data->lastMessage - data->firstMessage + 1;
+ data->unread = data->last - data->first + 1;
for (int i = 0; i < data->num; i++) {
- int first = MAX(data->entries[i].first, data->firstMessage);
- int last = MIN(data->entries[i].last, data->lastMessage);
+ int first = MAX(data->entries[i].first, data->first);
+ int last = MIN(data->entries[i].last, data->last);
data->unread -= MAX(0, last - first + 1);
}
}
x += data->entries[x].last != 0;
}
- if (x && !data->lastMessage)
- data->lastMessage = data->entries[x - 1].last;
+ if (x && !data->last)
+ data->last = data->entries[x - 1].last;
data->num = x;
mutt_newsgroup_stat(data);
return 0;
}
m_strreplace(&data->cache, p);
- t = !data->firstMessage || data->lastMessage < m;
- if (!data->firstMessage)
- data->firstMessage = l;
- if (data->lastMessage < m)
- data->lastMessage = m;
+ t = !data->first || data->last < m;
+ if (!data->first)
+ data->first = l;
+ if (data->last < m)
+ data->last = m;
data->lastCached = m;
if (t || !data->unread)
mutt_newsgroup_stat(data);
return mutt_account_fromurl(act, &url);
}
-void nntp_expand_path (char *line, ssize_t len, ACCOUNT * act)
+void nntp_expand_path(char *line, ssize_t len, ACCOUNT *act)
{
- ciss_url_t url;
+ ciss_url_t url = { .path = alloca(len) };
- url.path = m_strdup(line);
- mutt_account_tourl (act, &url);
- url_ciss_tostring (&url, line, len, 0);
- p_delete(&url.path);
+ m_strcpy(url.path, len, line);
+ mutt_account_tourl (act, &url);
+ url_ciss_tostring(&url, line, len, 0);
}
-static int add_group (char *buf, void *serv)
+static int add_group(char *buf, void *serv)
{
- nntp_server_t *s = serv;
- char group[LONG_STRING], mod, desc[HUGE_STRING];
- int first, last;
- nntp_data_t *nntp_data;
- static int n = 0;
+ char mod, group[HUGE_STRING], desc[HUGE_STRING];
+ nntp_server_t *srv = serv;
+ nntp_data_t *data;
+ static int n = 0;
+ int first, last;
- nntp.checked = n; /* nntp.checked have N, where N = number of groups */
- if (!buf) /* at EOF must be zerouth */
- n = 0;
+ nntp.checked = n; /* nntp.checked have N, where N = number of groups */
+ if (!buf) /* at EOF must be zerouth */
+ n = 0;
- if (!s || !buf)
- return 0;
+ if (!srv || !buf)
+ return 0;
- *desc = 0;
- sscanf (buf, "%s %d %d %c %[^\n]", group, &last, &first, &mod, desc);
- if (!group)
- return 0;
- if ((nntp_data = hash_find(s->newsgroups, group)) == NULL) {
- n++;
- nntp_data = nntp_data_new();
- nntp_data->group = m_strdup(group);
- nntp_data->nserv = s;
- hash_insert(s->newsgroups, nntp_data->group, nntp_data);
- s->tail = nntp_data_list_append(s->tail, nntp_data);
- }
- nntp_data->deleted = 0;
- nntp_data->firstMessage = first;
- nntp_data->lastMessage = last;
- if (mod == 'y')
- nntp_data->allowed = 1;
- else
- nntp_data->allowed = 0;
- if (nntp_data->desc)
- p_delete(&nntp_data->desc);
- if (*desc)
- nntp_data->desc = m_strdup(desc);
- if (nntp_data->rc || nntp_data->lastCached)
- mutt_newsgroup_stat (nntp_data);
- else if (nntp_data->lastMessage &&
- nntp_data->firstMessage <= nntp_data->lastMessage)
- nntp_data->unread = nntp_data->lastMessage - nntp_data->firstMessage + 1;
- else
- nntp_data->unread = 0;
+ *desc = '\0';
+ sscanf(buf, "%s %d %d %c %[^\n]", group, &last, &first, &mod, desc);
- return 0;
+ if (!(data = hash_find(srv->newsgroups, group))) {
+ n++;
+ data = nntp_data_new();
+ data->group = m_strdup(group);
+ data->nserv = srv;
+ hash_insert(srv->newsgroups, data->group, data);
+ srv->tail = nntp_data_list_append(srv->tail, data);
+ }
+
+ data->deleted = 0;
+ data->first = first;
+ data->last = last;
+ data->allowed = mod == 'y';
+ m_strreplace(&data->desc, desc);
+ mutt_newsgroup_stat(data);
+ return 0;
}
-/* Load list of all newsgroups from cache ALL */
-static int nntp_get_cache_all (nntp_server_t * serv)
+static int nntp_get_cache_all(nntp_server_t * serv)
{
- char buf[HUGE_STRING];
- FILE *f;
+ char buf[HUGE_STRING];
+ FILE *f;
- nntp_cache_expand(buf, ssizeof(buf), "%s", serv->cache);
- if ((f = safe_fopen (buf, "r"))) {
- int i = 0;
+ nntp_cache_expand(buf, ssizeof(buf), "%s", serv->cache);
+ if ((f = fopen(buf, "r"))) {
+ int i = 0;
- while (fgets (buf, sizeof (buf), f) != NULL) {
- if (ReadInc && (i % ReadInc == 0))
- mutt_message (_("Loading list from cache... %d"), i);
- add_group (buf, serv);
- i++;
+ while (fgets(buf, sizeof(buf), f)) {
+ if (ReadInc && (i % ReadInc == 0))
+ mutt_message (_("Loading list from cache... %d"), i);
+ add_group(buf, serv);
+ i++;
+ }
+ add_group (NULL, NULL);
+ m_fclose(&f);
+ mutt_clear_error();
+ return 0;
}
- add_group (NULL, NULL);
- m_fclose(&f);
- mutt_clear_error ();
- return 0;
- }
- else {
+
p_delete(&serv->cache);
return -1;
- }
}
/*
p_clear(&act, 1);
- if (!server || !*server) {
+ if (m_strisempty(server)) {
mutt_error _("No newsserver defined!");
-
return NULL;
}
}
strcpy (p, server);
- if ((nntp_parse_url (buf, &act, file, sizeof (file))) < 0 || *file) {
+ if ((nntp_parse_url(buf, &act, file, sizeof(file))) < 0 || *file) {
p_delete(&buf);
mutt_error (_("%s is an invalid newsserver specification!"), server);
return NULL;
struct stat sb;
/* externally modified? */
- if (serv->stat != stat(file, &sb) || (!serv->stat &&
- (serv->size != sb.st_size
- || serv->mtime != sb.st_mtime)))
+ if (serv->stat != stat(file, &sb)
+ || (!serv->stat && (serv->size != sb.st_size
+ || serv->mtime != sb.st_mtime)))
{
for (list = serv->list; list; list = list->next) {
list->subscribed = list->rc = list->num = 0;
}
- slurp_newsrc (serv);
+ slurp_newsrc(serv);
}
if (serv->status == NNTP_BYE)
serv->status = NNTP_NONE;
- nntp_check_newgroups (serv, 0);
+ nntp_check_newgroups(serv, 0);
return serv;
}
serv->conn = conn;
serv->newsrc = m_strdup(file);
serv->newsgroups = hash_new(SHRT_MAX, false);
- slurp_newsrc (serv); /* load .newsrc */
- nntp_parse_cacheindex (serv); /* load .index */
- if (nntp.use_cache && serv->cache && nntp_get_cache_all (serv) >= 0)
+ slurp_newsrc(serv); /* load .newsrc */
+ nntp_parse_cacheindex(serv); /* load .index */
+ if (nntp.use_cache && serv->cache && nntp_get_cache_all(serv) >= 0) {
nntp_check_newgroups (serv, 1);
- else if (nntp_get_active (serv) < 0) {
+ } else if (nntp_get_active(serv) < 0) {
hash_delete(&serv->newsgroups, NULL);
nntp_data_list_wipe(&serv->list);
p_delete(&serv->newsrc);
p_delete(&serv);
return NULL;
}
- conn->data = (void *) serv;
+ conn->data = serv;
return serv;
}
* "missing" entries as read/deleted
*/
last = ctx->hdrs[x]->article_num;
- if (last >= data->firstMessage && !ctx->hdrs[x]->deleted &&
+ if (last >= data->first && !ctx->hdrs[x]->deleted &&
!ctx->hdrs[x]->read) {
if (data->num >= data->max) {
data->max = data->max * 2;
if (data && data->group) {
key = data->group;
snprintf(buf, sizeof(buf), "%s %s %d %d", key, data->cache,
- data->firstMessage, data->lastLoaded);
+ data->first, data->lastLoaded);
} else {
m_strcpy(file, sizeof(file), serv->cache);
snprintf(buf, sizeof (buf), "ALL %s 0 %d", file,
if (!d->deleted) {
if (d->desc)
snprintf (buf, sizeof (buf), "%s %d %d %c %s\n", d->group,
- d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n',
+ d->last, d->first, d->allowed ? 'y' : 'n',
d->desc);
else
snprintf (buf, sizeof (buf), "%s %d %d %c\n", d->group,
- d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n');
+ d->last, d->first, d->allowed ? 'y' : 'n');
if (fputs (buf, f) == EOF) {
m_fclose(&f);
unlink (file);
data->num = 1;
data->entries[0].first = 1;
data->unread = 0;
- data->entries[0].last = data->lastMessage;
+ data->entries[0].last = data->last;
if (Context && Context->data == data) {
int x;
}
data->num = 1;
data->entries[0].first = 1;
- data->entries[0].last = data->firstMessage - 1;
+ data->entries[0].last = data->first - 1;
if (Context && Context->data == data) {
int x;
mutt_set_flag (Context, Context->hdrs[x], M_READ, 0);
}
else
- data->unread = data->lastMessage - data->entries[0].last;
+ data->unread = data->last - data->entries[0].last;
return data;
}
tmp = Incoming.arr[i];
/* copied from browser.c */
if (option (OPTMARKOLD) &&
- data->lastCached >= data->firstMessage &&
- data->lastCached <= data->lastMessage)
- tmp->msg_unread = data->lastMessage - data->lastCached;
+ data->lastCached >= data->first &&
+ data->lastCached <= data->last)
+ tmp->msg_unread = data->last - data->lastCached;
else
tmp->msg_unread = data->unread;
tmp->new = data->unread > 0;
/* this is closest to a "total" count we can get */
- tmp->msgcount = data->lastMessage - data->firstMessage;
+ tmp->msgcount = data->last - data->first;
}
static int nntp_auth (nntp_server_t * serv)
return -1;
}
- sscanf (buf + 4, "%d %u %u %s", &count, &nntp_data->firstMessage,
- &nntp_data->lastMessage, buf);
+ sscanf (buf + 4, "%d %u %u %s", &count, &nntp_data->first,
+ &nntp_data->last, buf);
nntp_data->deleted = 0;
* Check for max adding context. If it is greater than $nntp_context,
* strip off extra articles
*/
- first = nntp_data->firstMessage;
- if (NntpContext && nntp_data->lastMessage - first + 1 > NntpContext)
- first = nntp_data->lastMessage - NntpContext + 1;
+ first = nntp_data->first;
+ if (NntpContext && nntp_data->last - first + 1 > NntpContext)
+ first = nntp_data->last - NntpContext + 1;
if (first)
nntp_data->lastLoaded = first - 1;
- return nntp_fetch_headers (ctx, first, nntp_data->lastMessage);
+ return nntp_fetch_headers (ctx, first, nntp_data->last);
}
int nntp_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno)
}
}
-static void nntp_free_acache (nntp_data_t * data)
-{
- int i;
-
- for (i = 0; i < NNTP_CACHE_LEN; i++) {
- if (data->acache[i].path) {
- unlink (data->acache[i].path);
- p_delete(&data->acache[i].path);
- }
- }
-}
-
-void nntp_data_wipe(nntp_data_t *data)
-{
- p_delete(&data->entries);
- p_delete(&data->desc);
- p_delete(&data->cache);
- p_delete(&data->group);
- nntp_free_acache(data);
-}
-
static int nntp_sync_mailbox (CONTEXT * ctx, int unused1, int* unused2)
{
nntp_data_t *data = ctx->data;
int last;
sscanf (buf + 4, "%d %d %d", &count, &first, &last);
- nntp_data->firstMessage = first;
- nntp_data->lastMessage = last;
+ nntp_data->first = first;
+ nntp_data->last = last;
if (ctx && last > nntp_data->lastLoaded) {
nntp_fetch_headers (ctx, nntp_data->lastLoaded + 1, last);
time (&nntp_data->nserv->check_time);
if (!nntp_data || !nntp_data->nserv || !nntp_data->nserv->conn ||
!nntp_data->nserv->conn->account.host)
return -1;
- if (nntp_data->firstMessage > nntp_data->lastLoaded)
+ if (nntp_data->first > nntp_data->lastLoaded)
return 0;
if (!nntp_data->nserv->hasXPAT) {
mutt_error (_("Server %s does not support this operation!"),
}
snprintf (buf, sizeof (buf), "XPAT References %d-%d *%s*\r\n",
- nntp_data->firstMessage, nntp_data->lastLoaded, msgid);
+ nntp_data->first, nntp_data->lastLoaded, msgid);
if (mutt_nntp_fetch (nntp_data, buf, NULL, NULL, check_children, &cc, 0)) {
p_delete(&cc.child);