static int parse_description (char *line, void *n)
{
-#define news ((NNTP_SERVER *) n)
register char *d = line;
NNTP_DATA *data;
+ NNTP_SERVER *news = n;
if (!line)
return 0;
data->desc = m_strdup(d);
}
return 0;
-#undef news
}
static void nntp_get_desc (NNTP_DATA * data, const char *mask, char *msg, progress_t* bar)
typedef struct {
CONTEXT *ctx;
- int base;
int first;
int last;
- char *messages;
+ bits_t messages;
const char *msg;
} FETCH_CONTEXT;
static int nntp_fetch_numbers (char *line, void *c)
{
- int num;
- FETCH_CONTEXT *fc = c;
+ FETCH_CONTEXT *fc = c;
- if (!line)
- return 0;
+ if (line) {
+ int num = atoi(line);
+ if (num < fc->first || num > fc->last)
+ return 0;
- num = atoi(line);
- if (num < fc->base || num > fc->last)
+ bit_set(&fc->messages, num);
+ }
return 0;
-
- fc->messages[num - fc->base] = 1;
- return 0;
}
static int add_xover_line (char *line, void *c)
nntp_parse_xover (ctx, line, ctx->hdrs[ctx->msgcount]);
num = ctx->hdrs[ctx->msgcount]->article_num;
- if (num >= fc->first && num <= fc->last && fc->messages[num - fc->base]) {
+ if (bit_isset(&fc->messages, num)) {
ctx->msgcount++;
if (num > data->lastLoaded)
data->lastLoaded = num;
return 0;
}
-#undef fc
static int nntp_fetch_headers(CONTEXT * ctx, int first, int last)
{
/* fetch list of articles */
mutt_message _("Fetching list of articles...");
- fc.ctx = ctx;
- fc.base = first;
- fc.last = last;
- fc.messages = p_new(char, last - first + 1);
+ fc.ctx = ctx;
+ fc.first = first;
+ fc.last = last;
+ bits_init(&fc.messages);
if (nntp_data->nserv->hasLISTGROUP) {
snprintf (buf, sizeof (buf), "LISTGROUP %s\r\n", nntp_data->group);
{
mutt_error (_("LISTGROUP command failed: %s"), buf);
sleep (2);
- p_delete(&fc.messages);
+ bits_wipe(&fc.messages);
return -1;
}
} else {
- for (num = 0; num < last - first + 1; num++)
- fc.messages[num] = 1;
+ for (num = first; num <= last; num++)
+ bit_set(&fc.messages, num);
}
-/* 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);
-mutt_message (msg2);
-
-if ((f = safe_fopen (buf, "r"))) {
- int r = 0, c = 0;
-
- /* counting number of lines */
- while (fgets (buf, sizeof (buf), f) != NULL)
- r++;
- rewind (f);
- while (r > num && fgets (buf, sizeof (buf), f) != NULL)
- r--;
- oldmsgcount = ctx->msgcount;
- fc.first = first;
- fc.last = first + num - 1;
- fc.msg = NULL;
- while (fgets (buf, sizeof (buf), f) != NULL) {
- if (ReadInc && ((++c) % ReadInc == 0))
- mutt_message ("%s %d/%d", msg2, c, r);
- add_xover_line (buf, &fc);
+ /* 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);
+ mutt_message (msg2);
+
+ if ((f = safe_fopen (buf, "r"))) {
+ int r = 0, c = 0;
+
+ /* counting number of lines */
+ while (fgets (buf, sizeof (buf), f) != NULL)
+ r++;
+ rewind (f);
+ while (r > num && fgets (buf, sizeof (buf), f) != NULL)
+ r--;
+ oldmsgcount = ctx->msgcount;
+ fc.first = first;
+ fc.last = first + num - 1;
+ fc.msg = NULL;
+ while (fgets (buf, sizeof (buf), f) != NULL) {
+ if (ReadInc && ((++c) % ReadInc == 0))
+ mutt_message ("%s %d/%d", msg2, c, r);
+ add_xover_line (buf, &fc);
+ }
+ m_fclose(&f);
+ nntp_data->lastLoaded = fc.last;
+ first = fc.last + 1;
+ if (ctx->msgcount > oldmsgcount)
+ mx_update_context (ctx, ctx->msgcount - oldmsgcount);
+ }
+ else
+ nntp_delete_cache (nntp_data);
+ }
+ num = last - first + 1;
+ if (num <= 0) {
+ bits_wipe(&fc.messages);
+ return 0;
}
- m_fclose(&f);
- nntp_data->lastLoaded = fc.last;
- first = fc.last + 1;
- if (ctx->msgcount > oldmsgcount)
- mx_update_context (ctx, ctx->msgcount - oldmsgcount);
-}
-else
- nntp_delete_cache (nntp_data);
-}
-num = last - first + 1;
-if (num <= 0) {
-p_delete(&fc.messages);
-return 0;
-}
-/*
-* Without XOVER, we have to fetch each article header and parse
-* it. With XOVER, we ask for all of them
-*/
-mutt_message (msg);
-if (nntp_data->nserv->hasXOVER) {
-oldmsgcount = ctx->msgcount;
-fc.first = first;
-fc.last = last;
-fc.msg = msg;
-snprintf (buf, sizeof (buf), "XOVER %d-%d\r\n", first, last);
-ret = mutt_nntp_fetch (nntp_data, buf, NULL, NULL, add_xover_line, &fc, 0);
-if (ctx->msgcount > oldmsgcount)
- mx_update_context (ctx, ctx->msgcount - oldmsgcount);
-if (ret != 0) {
- mutt_error (_("XOVER command failed: %s"), buf);
- p_delete(&fc.messages);
- return -1;
-}
-/* fetched OK */
-}
-else
-for (current = first; current <= last; current++) {
- HEADER *h;
+ /*
+ * Without XOVER, we have to fetch each article header and parse
+ * it. With XOVER, we ask for all of them
+ */
+ mutt_message (msg);
+ if (nntp_data->nserv->hasXOVER) {
+ oldmsgcount = ctx->msgcount;
+ fc.first = first;
+ fc.last = last;
+ fc.msg = msg;
+ snprintf (buf, sizeof (buf), "XOVER %d-%d\r\n", first, last);
+ ret = mutt_nntp_fetch (nntp_data, buf, NULL, NULL, add_xover_line, &fc, 0);
+ if (ctx->msgcount > oldmsgcount)
+ mx_update_context (ctx, ctx->msgcount - oldmsgcount);
+ if (ret != 0) {
+ mutt_error (_("XOVER command failed: %s"), buf);
+ bits_wipe(&fc.messages);
+ return -1;
+ }
+ /* fetched OK */
+ } else {
+ for (current = first; current <= last; current++) {
+ HEADER *h;
- ret = current - first + 1;
- mutt_message ("%s %d/%d", msg, ret, num);
+ ret = current - first + 1;
+ mutt_message ("%s %d/%d", msg, ret, num);
- if (!fc.messages[current - fc.base])
+ if (!bit_isset(&fc.messages, current))
continue;
if (ctx->msgcount >= ctx->hdrmax)
else
header_delete(&h); /* skip it */
if (ret == -1) {
- p_delete(&fc.messages);
+ bits_wipe(&fc.messages);
return -1;
}
if (current > nntp_data->lastLoaded)
nntp_data->lastLoaded = current;
}
- p_delete(&fc.messages);
+ }
+ bits_wipe(&fc.messages);
nntp_data->lastLoaded = last;
mutt_clear_error ();
return 0;
static int add_group (char *buf, void *serv)
{
-#define s ((NNTP_SERVER *) serv)
+ NNTP_SERVER *s = serv;
char group[LONG_STRING], mod, desc[HUGE_STRING];
int first, last;
NNTP_DATA *nntp_data;
nntp_data->unread = 0;
return 0;
-#undef s
}
int nntp_check_newgroups (NNTP_SERVER * serv, int force)