X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=nntp.c;h=a61bcf8b2cd34e5bd28f8f0df1b61bcc4ad5f72e;hp=eb5cd42d5dd1c3a0aa47f2cb7af350d9f0da7986;hb=803edc39e2be84e93432e6dc2859a1380c5a9af5;hpb=57ad79c17d6c89072cd119fa66631b8b094e36c2 diff --git a/nntp.c b/nntp.c index eb5cd42..a61bcf8 100644 --- a/nntp.c +++ b/nntp.c @@ -51,7 +51,7 @@ static void mutt_newsgroup_stat(nntp_data_t *data) } } -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]; @@ -73,10 +73,8 @@ static int nntp_parse_newsrc_line(nntp_server_t * news, const char *line) 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); } @@ -85,18 +83,19 @@ static int nntp_parse_newsrc_line(nntp_server_t * news, const char *line) 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; } @@ -200,10 +199,8 @@ static int nntp_parse_cacheindex(nntp_server_t *news) 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); @@ -290,10 +287,8 @@ static int add_group (char *buf, void *serv) 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; @@ -403,7 +398,6 @@ nntp_server_t *mutt_select_newsserver (char *server) list->subscribed = list->rc = list->num = 0; } slurp_newsrc (serv); - nntp_clear_cacheindex (serv); } if (serv->status == NNTP_BYE) @@ -414,9 +408,10 @@ nntp_server_t *mutt_select_newsserver (char *server) /* 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) @@ -429,7 +424,6 @@ nntp_server_t *mutt_select_newsserver (char *server) p_delete(&serv); return NULL; } - nntp_clear_cacheindex (serv); conn->data = (void *) serv; return serv; @@ -764,22 +758,6 @@ static void nntp_delete_cache (nntp_data_t * data) 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]; @@ -924,10 +902,8 @@ nntp_data_t *mutt_newsgroup_subscribe (nntp_server_t * news, char *group) 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; @@ -945,8 +921,6 @@ nntp_data_t *mutt_newsgroup_unsubscribe (nntp_server_t * news, char *group) return NULL; if (data->subscribed) { data->subscribed = 0; - if (!option (OPTSAVEUNSUB)) - data->rc = 0; } return data; } @@ -1832,7 +1806,7 @@ static int nntp_open_mailbox (CONTEXT * ctx) 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; @@ -1865,6 +1839,8 @@ static int nntp_open_mailbox (CONTEXT * ctx) if ((*l) == nntp_data) { nntp_data_list_pop(l); nntp_data_delete(&nntp_data); + if (!*l) + serv->tail = l; break; } } @@ -2090,10 +2066,8 @@ static int nntp_sync_mailbox (CONTEXT * ctx, int unused1, int* unused2) { 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; @@ -2301,7 +2275,8 @@ int nntp_get_active (nntp_server_t * serv) tmp = &(*tmp)->next; } } - nntp_save_cache_index (serv); + serv->tail = tmp; + nntp_save_cache_index(serv); mutt_clear_error (); return nntp.checked;