Source: nn Version: 6.7.3-14 Severity: normal Tags: patch Dear Maintainer,
>From c8c65bbca53fba5acac88955bb15b47cb66e1b19 Mon Sep 17 00:00:00 2001 >From: Bjarni Ingi Gislason <bjarn...@rhi.hi.is> >Date: Sun, 21 Feb 2021 19:15:05 +0000 >Subject: [PATCH] db.c: add subroutine "readpartactfile" Signed-off-by: Bjarni Ingi Gislason <bjarn...@rhi.hi.is> --- db.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/db.c b/db.c index 4278dda..99c2695 100644 --- a/db.c +++ b/db.c @@ -44,6 +44,7 @@ static void db_init_group(group_header * gh, int num); static void db_init_active(group_header * gh); static void readtimfile(void); static void readactfile(void); +static void readpartactfile(void); static void db_fixup_cross_postings(data_header * dhp, data_dynamic_data * ddp, @@ -1112,6 +1113,125 @@ readactfile(void) } + +static void +readpartactfile(void) +{ + char *cp; + char actline[512]; + char newsrcline[256]; + int count = 0; + int i, n; + FILE *actfp; + stlist_t *sthead, *stp = NULL; + int get_group_line(const char *, char *, size_t); + extern char *newsrc_file; + static FILE *f_user = NULL; + extern int nntp_debug; + + if (actlist != NULL) + return; + + if (newsrc_file == NULL) + newsrc_file = home_relative(".newsrc"); + + actfp = fopen(newsrc_file, "r"); + + if (actfp == NULL) { + nn_exitmsg(1, "could not open .newsrc file %s\n", newsrc_file); + } + + /* + * Snarf all of active up in first pass. This gives us a count of the + * groups we can use for internal tables. + */ + sthead = NULL; + gotoxy(0, 3); + tprintf("Reading active file for groups in %s ... ", newsrc_file); + fflush(stdout); + strcpy(actline, "GROUP "); + + if (nntp_debug) { + if (f_user == NULL) { +/* f_user = open_file(relative(nn_directory, "partial_active_file"), OPEN_CREATE);*/ + f_user = open_file(relative(active_directory, "partial_active_file"), OPEN_CREATE); + if (f_user == NULL) { + msg("Could not open file in the %s directoy for writing the active file\n", nn_directory); + } + } + } + while (fgets(newsrcline, sizeof newsrcline, actfp)) + + { +/* Get the group name from the .newsrc file and the data with the GROUP + nntp command. Data in actline should be the same as from the "LIST" + command group: last first p +*/ + if ((cp = strchr(newsrcline, ':')) == NULL) + continue; + *cp = NUL; + n = get_group_line(newsrcline, actline, sizeof actline); + + if (n != OK_GROUP) { + msg("newsrc-group %s is not on server", newsrcline); + continue; + } + if (nntp_debug && (f_user != NULL)) + fprintf(f_user, "%s\n", actline); + +/* tprintf("%s\n", actline); + nn_exitmsg(1, "Testing ask_server\n"); +*/ + stlist_t *stnew = (stlist_t *) strkeep(actline, sizeof(stlisthdr_t), POOL_ACT); + if (stnew == NULL) { + nn_exitmsg(1, "Out of memory for active file (at line %d)\n", count + 1); + } + if (sthead != NULL) { + stp->n.next = stnew; + stp = stnew; + } else { + sthead = stnew; + stp = sthead; + } + count++; + } + stp->n.next = NULL; + + if (!use_nntp) + (void) fclose(actfp); + + actlist = (char **) calloc(count + 1, sizeof(char *)); + grplist = (char **) calloc(count + 1, sizeof(char *)); + if (grplist == NULL) { + nn_exitmsg(1, "can't create active or group list (%d entries)\n", + count + 1); + } + + /* + * Second pass (in core): Put active lines and group names into string + * arrays. + */ + + for (i = 0, stp = sthead; stp && i < count; stp = stp->n.next, i++) { + char *p = strchr(stp->str, ' '); + + if (p == NULL) + actlist[i] = NULL; + else { + *p++ = NUL; + actlist[i] = p; + } + grplist[i] = strkeep(stp->str, 0, POOL_GRP); + } + tprintf("done. %d groups.\n\n", count); + actlist[count] = NULL; + grplist[count] = NULL; + + /* init the master struct */ + clearobj(&master, sizeof(master), 1); + master.number_of_groups = count; +} + #endif /* NOV */ -- 2.30.0 -- System Information: Debian Release: bullseye/sid APT prefers testing APT policy: (500, 'testing'), (500, 'stable') Architecture: amd64 (x86_64) Kernel: Linux 5.10.9-1 (SMP w/2 CPU threads) Locale: LANG=is_IS.iso88591, LC_CTYPE=is_IS.iso88591 (charmap=ISO-8859-1), LANGUAGE not set Shell: /bin/sh linked to /bin/dash Init: sysvinit (via /sbin/init) -- debconf information excluded -- Bjarni I. Gislason