INN commit: trunk/nnrpd (article.c group.c list.c nnrpd.c nnrpd.h)
INN Commit
Russ_Allbery at isc.org
Sun Aug 24 15:24:13 UTC 2008
Date: Sunday, August 24, 2008 @ 08:24:12
Author: iulius
Revision: 7966
Add support for the official LISTGROUP command.
A range can be specified as its third argument.
The range is now properly parsed: "42-12" is kept as "42-12"
and not changed to "42-".
Modified:
trunk/nnrpd/article.c
trunk/nnrpd/group.c
trunk/nnrpd/list.c
trunk/nnrpd/nnrpd.c
trunk/nnrpd/nnrpd.h
-----------+
article.c | 41 +++++++++++++++++++++++++++++++++--------
group.c | 35 +++++++++++++++++++++++++++++++----
list.c | 1 -
nnrpd.c | 4 ++--
nnrpd.h | 2 +-
5 files changed, 67 insertions(+), 16 deletions(-)
Modified: article.c
===================================================================
--- article.c 2008-08-24 12:30:32 UTC (rev 7965)
+++ article.c 2008-08-24 15:24:12 UTC (rev 7966)
@@ -60,6 +60,8 @@
static struct iovec iov[IOV_MAX > 1024 ? 1024 : IOV_MAX];
static int queued_iov = 0;
+bool CMDgetrange(int ac, char *av[], ARTRANGE *rp, bool *DidReply);
+
static void
PushIOvHelper(struct iovec* vec, int* countp)
{
@@ -740,7 +742,24 @@
}
-static bool
+/*
+** Parse a range (in av[1]) which may be any of the following:
+** - An article number.
+** - An article number followed by a dash to indicate all following.
+** - An article number followed by a dash followed by another article
+** number.
+**
+** In the last case, if the second number is less than the first number,
+** then the range contains no articles.
+**
+** ac is the number of arguments in the command:
+** LISTGROUP news.software.nntp 12-42
+** gives ac=3 and av[1] should match "12-42" (whence the "av+1" call
+** of CMDgetrange).
+**
+** *DidReply will be true if this function sends an answer.
+*/
+bool
CMDgetrange(int ac, char *av[], ARTRANGE *rp, bool *DidReply)
{
char *p;
@@ -763,7 +782,9 @@
return true;
}
- /* Got just a single number? */
+ /* Got just a single number?
+ * Note that atol() returns 0 if no valid number
+ * is found at the beginning of *p. */
if ((p = strchr(av[1], '-')) == NULL) {
rp->Low = rp->High = atol(av[1]);
return true;
@@ -772,13 +793,17 @@
/* Parse range. */
*p++ = '\0';
rp->Low = atol(av[1]);
- if (*p == '\0' || (rp->High = atol(p)) < rp->Low)
- /* "XHDR 234-0 header" gives everything to the end. */
- rp->High = ARThigh;
- else if (rp->High > ARThigh)
- rp->High = ARThigh;
+
+ /* Adjust the lowmark. */
if (rp->Low < ARTlow)
- rp->Low = ARTlow;
+ rp->Low = ARTlow;
+
+ /* Parse and adjust the highmark.
+ * "12-" gives everything from 12 to the end.
+ * We do not bother about "42-12" or "42-0" in this function. */
+ if ((*p == '\0') || ((rp->High = atol(p)) > ARThigh))
+ rp->High = ARThigh;
+
p--;
*p = '-';
Modified: group.c
===================================================================
--- group.c 2008-08-24 12:30:32 UTC (rev 7965)
+++ group.c 2008-08-24 15:24:12 UTC (rev 7966)
@@ -10,6 +10,8 @@
#include "nnrpd.h"
#include "inn/ov.h"
+extern bool CMDgetrange(int ac, char *av[], ARTRANGE *rp, bool *DidReply);
+
/*
** Change to or list the specified newsgroup. If invalid, stay in the old
** group.
@@ -155,27 +157,52 @@
} else
GRPcur = xstrdup(group);
} else {
- /* Must be doing a "listgroup" command. We used to just return
+ /* Must be doing a "listgroup" command. We used to just return
something bland here ("Article list follows"), but reference NNTP
returns the same data as GROUP does and since we have it all
available it shouldn't hurt to return the same thing. */
+ ARTRANGE range;
+ bool DidReply;
+
+ /* Parse the range. */
+ if (ac == 3) {
+ /* CMDgetrange() expects av[1] to contain the range.
+ * It is av[2] for LISTGROUP. */
+ if (!CMDgetrange(ac, av + 1, &range, &DidReply)) {
+ if (DidReply) {
+ free(group);
+ return;
+ }
+ }
+ } else {
+ range.Low = ARTlow;
+ range.High = ARThigh;
+ }
+
if (count == 0) {
if (ARTlow == 0)
ARTlow = 1;
Reply("%d 0 %lu %lu %s\r\n", NNTP_OK_GROUP, ARTlow, ARTlow-1, group);
Printf(".\r\n");
+ /* If OVopensearch() is restricted to the range, it returns NULL
+ * in case there isn't any article within the range. */
} else if ((handle = OVopensearch(group, ARTlow, ARThigh)) != NULL) {
Reply("%d %d %lu %lu %s\r\n", NNTP_OK_GROUP, count, ARTlow,
ARThigh, group);
+
while (OVsearch(handle, &i, NULL, NULL, &token, NULL)) {
- if (PERMaccessconf->nnrpdcheckart && !ARTinstorebytoken(token))
- continue;
- Printf("%lu\r\n", i);
+ if ((i >= range.Low) && (i <= range.High)) {
+ if (PERMaccessconf->nnrpdcheckart && !ARTinstorebytoken(token))
+ continue;
+ Printf("%lu\r\n", i);
+ }
}
+
OVclosesearch(handle);
Printf(".\r\n");
GRPcount++;
ARTnumber = ARTlow;
+
if (GRPcur) {
if (strcmp(GRPcur, group) != 0) {
OVctl(OVCACHEFREE, &boolval);
Modified: list.c
===================================================================
--- list.c 2008-08-24 12:30:32 UTC (rev 7965)
+++ list.c 2008-08-24 15:24:12 UTC (rev 7966)
@@ -129,7 +129,6 @@
mechlist != NULL ? mechlist : "");
}
- Printf("LISTGROUP\r\n");
Printf(".\r\n");
}
Modified: nnrpd.c
===================================================================
--- nnrpd.c 2008-08-24 12:30:32 UTC (rev 7965)
+++ nnrpd.c 2008-08-24 15:24:12 UTC (rev 7966)
@@ -131,8 +131,8 @@
NULL },
{ "list", CMDlist, true, 1, 3,
"[active [wildmat]|active.times [wildmat]|distrib.pats|distributions|extensions|moderators|motd|newsgroups [wildmat]|overview.fmt|subscriptions]" },
- { "listgroup", CMDgroup, true, 1, 2,
- "[newsgroup]" },
+ { "listgroup", CMDgroup, true, 1, 3,
+ "[newsgroup [range]]" },
{ "mode", CMDmode, false, 2, 2,
"reader" },
{ "newgroups", CMDnewgroups, true, 3, 4,
Modified: nnrpd.h
===================================================================
--- nnrpd.h 2008-08-24 12:30:32 UTC (rev 7965)
+++ nnrpd.h 2008-08-24 15:24:12 UTC (rev 7966)
@@ -243,7 +243,7 @@
extern void CMDnewnews (int ac, char** av);
extern void CMDnextlast (int ac, char** av);
extern void CMDpost (int ac, char** av);
-extern void CMDquit (int ac, char** av);
+extern void CMDquit (int ac, char** av);
extern void CMDxgtitle (int ac, char** av);
extern void CMDxover (int ac, char** av);
extern void CMDpat (int ac, char** av);
More information about the inn-committers
mailing list