}
}
-static int nntp_parse_newsrc_line(nntp_server_t * news, const char *line)
+static int nntp_parse_newsrc_line(nntp_server_t *news, const char *line)
{
nntp_data_t *data;
char group[LONG_STRING];
data->group = p_dupstr(line, p - line);
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);
+ news->tail = nntp_data_list_append(news->tail, data);
} else {
p_delete(&data->entries);
}
data->entries = p_new(NEWSRC_ENTRY, x * 2);
data->max = x * 2;
data->subscribed = (*p++ == ':');
+ p = skipspaces(p);
for (x = 0; *p; p++) {
- p = skipspaces(p);
data->entries[x].first = strtol(p, (char **)&p, 10);
- p = skipspaces(p);
+ p += strcspn(p, "-,");
if (*p == '-') {
+ if (!*p)
+ break;
data->entries[x].last = strtol(p + 1, (char **)&p, 10);
} else {
data->entries[x].last = data->entries[x].first;
+ p = strchrnul(p, ',');
}
-
- p = strchrnul(p, ',');
x += data->entries[x].last != 0;
}
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);
+ news->tail = nntp_data_list_append(news->tail, data);
}
m_strreplace(&data->cache, p);
/* 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,
+static int nntp_parse_url(const char *server, ACCOUNT *act, char *group,
ssize_t group_len)
{
- ciss_url_t url;
- char *c;
- int ret = -1;
-
- /* Defaults */
- act->flags = 0;
- act->port = NNTP_PORT;
- act->type = M_ACCT_TYPE_NNTP;
+ ciss_url_t url;
+ char s[STRING];
- c = m_strdup(server);
- url_parse_ciss (&url, c);
+ act->flags = 0;
+ act->port = 0;
+ act->type = M_ACCT_TYPE_NNTP;
- if (url.scheme == U_NNTP || url.scheme == U_NNTPS) {
- if (url.scheme == U_NNTPS) {
- act->has_ssl = 1;
- act->port = NNTP_SSL_PORT;
- }
+ m_strcpy(s, sizeof(s), server);
+ url_parse_ciss(&url, s);
- *group = '\0';
- if (url.path)
- m_strcpy(group, group_len, url.path);
+ if (url.scheme != U_NNTP || url.scheme != U_NNTPS)
+ return -1;
- ret = mutt_account_fromurl (act, &url);
- }
+ act->has_ssl = (url.scheme == U_NNTPS);
+ if (!act->port) {
+ act->port = act->has_ssl ? NNTP_PORT : NNTP_SSL_PORT;
+ }
+ m_strcpy(group, group_len, url.path);
- p_delete(&c);
- return ret;
+ return mutt_account_fromurl(act, &url);
}
void nntp_expand_path (char *line, ssize_t len, ACCOUNT * act)
nntp_data = nntp_data_new();
nntp_data->group = m_strdup(group);
nntp_data->nserv = s;
- if (s->newsgroups->nelem < s->newsgroups->curnelem * 2)
- hash_resize (s->newsgroups, s->newsgroups->nelem * 2);
hash_insert(s->newsgroups, nntp_data->group, nntp_data);
- nntp_data_list_append(&s->list, nntp_data);
+ s->tail = nntp_data_list_append(s->tail, nntp_data);
}
nntp_data->deleted = 0;
nntp_data->firstMessage = first;
list->subscribed = list->rc = list->num = 0;
}
slurp_newsrc (serv);
- nntp_clear_cacheindex (serv);
}
if (serv->status == NNTP_BYE)
/* New newsserver */
serv = p_new(nntp_server_t, 1);
+ serv->tail = &serv->list;
serv->conn = conn;
serv->newsrc = m_strdup(file);
- serv->newsgroups = hash_new(1009, false);
+ 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)
p_delete(&serv);
return NULL;
}
- nntp_clear_cacheindex (serv);
conn->data = (void *) serv;
return serv;
h->old = 1;
}
-static void nntp_create_newsrc_line(nntp_data_t *data, buffer_t *buf)
-{
- buffer_addstr(buf, data->group);
- buffer_addch(buf, data->subscribed ? ':' : '!');
- buffer_addch(buf, ' ');
-
- for (int x = 0; x < data->num; x++) {
- if (x) {
- buffer_addch(buf, ',');
- }
-
- buffer_addf(buf, "%d-%d", data->entries[x].first,
- data->entries[x].last);
- }
- buffer_addch(buf, '\n');
-}
-
static void newsrc_gen_entries (CONTEXT * ctx)
{
nntp_data_t *data = (nntp_data_t *) ctx->data;
for (data = news->list; data; data = data->next) {
if (!data || !data->rc)
continue;
- nntp_create_newsrc_line(data, &buf);
+
+ buffer_addstr(&buf, data->group);
+ buffer_addch(&buf, data->subscribed ? ':' : '!');
+
+ for (int x = 0; x < data->num; x++) {
+ buffer_addch(&buf, x ? ',' : ' ');
+ buffer_addf(&buf, "%d-%d", data->entries[x].first,
+ data->entries[x].last);
+ }
+ buffer_addch(&buf, '\n');
}
+
/* newrc being fully rewritten */
if (news->newsrc
&& (r = mutt_update_list_file(news->newsrc, NULL, "", buf.data)) == 0)
if (data && data->group) {
key = data->group;
- snprintf (buf, sizeof (buf), "%s %s %d %d", key, data->cache,
- data->firstMessage, data->lastLoaded);
- }
- else {
+ snprintf(buf, sizeof(buf), "%s %s %d %d", key, data->cache,
+ data->firstMessage, data->lastLoaded);
+ } else {
m_strcpy(file, sizeof(file), serv->cache);
- snprintf (buf, sizeof (buf), "ALL %s 0 %d", file,
- (int) serv->newgroups_time);
+ snprintf(buf, sizeof (buf), "ALL %s 0 %d", file,
+ (int)serv->newgroups_time);
}
nntp_cache_expand(file, ssizeof(file), "%s.index", serv->conn->account.host);
return mutt_update_list_file(file, serv->conn->account.host, key, buf);
NULL);
}
-/* Remove cache files of unsubscribed newsgroups */
-void nntp_clear_cacheindex (nntp_server_t * news)
-{
- nntp_data_t *data;
-
- if (option (OPTSAVEUNSUB) || !news)
- return;
-
- for (data = news->list; data; data = data->next) {
- if (!data || data->subscribed || !data->cache)
- continue;
- nntp_delete_cache (data);
- }
- return;
-}
-
static int nntp_save_cache_index (nntp_server_t * news)
{
char buf[HUGE_STRING];
data->group = m_strdup(group);
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);
+ news->tail = nntp_data_list_append(news->tail, data);
}
if (!data->subscribed) {
data->subscribed = 1;
return NULL;
if (data->subscribed) {
data->subscribed = 0;
- if (!option (OPTSAVEUNSUB))
- data->rc = 0;
}
return data;
}
nntp_data = nntp_data_new();
nntp_data->group = m_strdup(buf);
hash_insert(serv->newsgroups, nntp_data->group, nntp_data);
- nntp_data_list_append(&serv->list, nntp_data);
+ serv->tail = nntp_data_list_append(serv->tail, nntp_data);
}
ctx->data = nntp_data;
nntp_data->nserv = serv;
if ((*l) == nntp_data) {
nntp_data_list_pop(l);
nntp_data_delete(&nntp_data);
+ if (!*l)
+ serv->tail = l;
break;
}
}
{
nntp_data_t *data = ctx->data;
- /* CACHE: update cache and .index files */
- if ((option (OPTSAVEUNSUB) || data->subscribed))
- nntp_save_cache_group (ctx);
- nntp_free_acache (data);
+ nntp_save_cache_group(ctx);
+ nntp_free_acache(data);
data->nserv->check_time = 0; /* next nntp_check_mailbox() will really check */
return 0;
tmp = &(*tmp)->next;
}
}
- nntp_save_cache_index (serv);
+ serv->tail = tmp;
+ nntp_save_cache_index(serv);
mutt_clear_error ();
return nntp.checked;