INN commit: branches/2.5 (23 files)

INN Commit rra at isc.org
Tue Nov 17 18:58:24 UTC 2009


    Date: Tuesday, November 17, 2009 @ 10:58:24
  Author: iulius
Revision: 8818

Integrate showtoken into the main distribution.  "sm -c" will now
show clear, decoded information about storage API tokens.

A new SMexplaintoken() function has been added to the storage manager.

Modified:
  branches/2.5/MANIFEST
  branches/2.5/contrib/	(properties)
  branches/2.5/contrib/Makefile
  branches/2.5/contrib/README
  branches/2.5/doc/pod/news.pod
  branches/2.5/doc/pod/sm.pod
  branches/2.5/frontends/sm.c
  branches/2.5/include/inn/storage.h
  branches/2.5/storage/buildconfig.in
  branches/2.5/storage/cnfs/cnfs.c
  branches/2.5/storage/cnfs/cnfs.h
  branches/2.5/storage/interface.c
  branches/2.5/storage/interface.h
  branches/2.5/storage/timecaf/timecaf.c
  branches/2.5/storage/timecaf/timecaf.h
  branches/2.5/storage/timehash/timehash.c
  branches/2.5/storage/timehash/timehash.h
  branches/2.5/storage/tradspool/tradspool.c
  branches/2.5/storage/tradspool/tradspool.h
  branches/2.5/storage/trash/trash.c
  branches/2.5/storage/trash/trash.h
  branches/2.5/support/mkmanifest
Deleted:
  branches/2.5/contrib/showtoken.in

-------------------------------+
 MANIFEST                      |    1 
 contrib/Makefile              |    3 -
 contrib/README                |    4 -
 contrib/showtoken.in          |   95 ----------------------------------------
 doc/pod/news.pod              |    7 ++
 doc/pod/sm.pod                |   27 +++++++----
 frontends/sm.c                |   20 ++++++--
 include/inn/storage.h         |    1 
 storage/buildconfig.in        |    2 
 storage/cnfs/cnfs.c           |   47 ++++++++++++++++---
 storage/cnfs/cnfs.h           |    1 
 storage/interface.c           |   11 ++++
 storage/interface.h           |    1 
 storage/timecaf/timecaf.c     |   41 +++++++++++++----
 storage/timecaf/timecaf.h     |    1 
 storage/timehash/timehash.c   |   40 +++++++++++++---
 storage/timehash/timehash.h   |    1 
 storage/tradspool/tradspool.c |   53 +++++++++++++++++-----
 storage/tradspool/tradspool.h |    1 
 storage/trash/trash.c         |   10 ++++
 storage/trash/trash.h         |    1 
 support/mkmanifest            |    1 
 22 files changed, 215 insertions(+), 154 deletions(-)

Modified: MANIFEST
===================================================================
--- MANIFEST	2009-11-17 18:57:19 UTC (rev 8817)
+++ MANIFEST	2009-11-17 18:58:24 UTC (rev 8818)
@@ -79,7 +79,6 @@
 contrib/reset-cnfs.c                  Reset the state parts of a CNFS buffer
 contrib/respool.c                     Respool articles in the storage manager
 contrib/sample.init.script            Example SysV-style init.d script
-contrib/showtoken.in                  Decode storage API tokens
 contrib/stathist.in                   Parse history statistics
 contrib/thdexpire.in                  Dynamic expire for timehash and timecaf
 contrib/tunefeed.in                   Tune a feed by comparing active files


Property changes on: branches/2.5/contrib
___________________________________________________________________
Modified: svn:ignore
   - .libs
archivegz
backlogstat
cleannewsgroups
delayer
findreadgroups
makeexpctl
makestorconf
mlockfile
newsresp
pullart
reset-cnfs
respool
showtoken
stathist
thdexpire
tunefeed

   + .libs
archivegz
backlogstat
cleannewsgroups
delayer
findreadgroups
makeexpctl
makestorconf
mlockfile
newsresp
pullart
reset-cnfs
respool
stathist
thdexpire
tunefeed


Modified: contrib/Makefile
===================================================================
--- contrib/Makefile	2009-11-17 18:57:19 UTC (rev 8817)
+++ contrib/Makefile	2009-11-17 18:58:24 UTC (rev 8818)
@@ -11,7 +11,7 @@
 
 ALL	      = archivegz backlogstat cleannewsgroups delayer \
 		findreadgroups makeexpctl makestorconf mlockfile newsresp \
-		pullart reset-cnfs respool showtoken stathist thdexpire \
+		pullart reset-cnfs respool stathist thdexpire \
 		tunefeed
 
 all: $(ALL)
@@ -49,7 +49,6 @@
 findreadgroups:  findreadgroups.in  $(FIX) ; $(FIX) findreadgroups.in
 makeexpctl:      makeexpctl.in      $(FIX) ; $(FIX) makeexpctl.in
 makestorconf:    makestorconf.in    $(FIX) ; $(FIX) makestorconf.in
-showtoken:       showtoken.in       $(FIX) ; $(FIX) -i showtoken.in
 stathist:        stathist.in        $(FIX) ; $(FIX) -i stathist.in
 thdexpire:       thdexpire.in       $(FIX) ; $(FIX) thdexpire.in
 tunefeed:        tunefeed.in        $(FIX) ; $(FIX) -i tunefeed.in

Modified: contrib/README
===================================================================
--- contrib/README	2009-11-17 18:57:19 UTC (rev 8817)
+++ contrib/README	2009-11-17 18:58:24 UTC (rev 8818)
@@ -148,10 +148,6 @@
     the system since INN and related programs can be file descriptor hogs.
     It then starts INN.
 
-showtoken
-
-    Decodes storage API tokens.
-
 stathist
 
     Parses and summarizes the log files created by the history profiling

Deleted: contrib/showtoken.in
===================================================================
--- contrib/showtoken.in	2009-11-17 18:57:19 UTC (rev 8817)
+++ contrib/showtoken.in	2009-11-17 18:58:24 UTC (rev 8818)
@@ -1,95 +0,0 @@
-#!/usr/bin/perl -w
-# showtoken - decode SM tokens
-# Olaf Titz, 1999. Marco d'Itri, 2000. Public domain.
-# Takes tokens on stdin and write them along with a decoded form on stdout.
-
-use strict;
-
-my ($pathspool, %NG);
-
-my @types = ('trash', '', 'timehash', 'cnfs', 'timecaf', 'tradspool');
-
-if ($ARGV[0]) {
-	$pathspool = $ARGV[0];
-	if (open(MAP, "$pathspool/tradspool.map")) {
-		while (<MAP>) {
-			my ($ng, $gnum) = split;
-			$NG{$gnum} = $ng;
-		}
-		close MAP;
-	}
-}
-
-$| = 1;
-while (<STDIN>) {
-	chomp;
-	next if not /^@.+@/;
-	print "$_ ";
-	splittoken($_);
-}
-
-sub splittoken {
-	my $t = shift;
-
-	$t =~ tr/@//d;
-	$t = pack('H*', $t);
-	my ($type, $class, $token, $index, $offset, $overlen, $cancelled) =
-		unpack('C C a16 CLnc', $t);
-
-	if (not $types[$type]) {
-		print "type=$type unknown!\n";
-		next;
-	}
-	print "type=$types[$type] class=$class ";
-
-	if ($type == 0) {		# trash
-	} elsif ($type == 2) {	# timehash
-		my ($time, $seq) = unpack('Nn', $token);
-		my ($a, $b, $c, $d) = unpack('CCCC', $token);
-		printf 'time=%08lX seq=%04X file=time-%02x/%02x/%02x/%04x-%02x%02x',
-			$time, $seq, $class, $b, $c, $seq, $a, $d;
-	} elsif ($type == 3) {	# cnfs
-		my ($buffn, $offset, $cnum) = unpack('A8NN', $token);
-		printf 'buffer=%s offset=%x cycnum=%x', $buffn, $offset * 512, $cnum;
-	} elsif ($type == 4) {	# timecaf
-		my ($time, $seq) = unpack('Nn', $token);
-		my (undef, $b, $c, $d) = unpack('CCCC', $token);
-		printf 'time=%06lX seq=%04X caf=timecaf-%02x/%02x/%02x%02x.CF',
-			$time, $seq, $class, $c, $b, $d;
-	} elsif ($type == 5) {	# tradspool
-		my ($gnum, $art) = unpack('NN', $token);
-		printf 'ng=%08X art=%d', $gnum, $art;
-		print "file=articles/$NG{$gnum}/$art" if $NG{$gnum};
-	} else {
-		die "invalid type $type";
-	}
-	print " over=$index offset=$offset overlen=$overlen cancelled=$cancelled"
-		if length $t > 36;
-	print "\n";
-}
-__END__
-# Format of a token:
-#  1   type
-#  1   class
-# 16   token
-#  1   index
-#  4   offset
-#  2   overlen
-#  2   cancelled
-# The fields "index" and following are not available with OV3 (INN 2.3 up)
-#
-# the "token" field is:
-# for type=0 (trash) ignored
-# for type=2 (timehash)
-#  4   time
-#  2   seqnum
-# for type=3 (cnfs)
-#  8   cycbuffname
-#  4   offset/512
-#  4   cycnum
-# for type=4 (timecaf)
-#  4   time
-#  2   seqnum
-# for type=5 (tradspool)
-#  4   ngnum
-#  4   artnum

Modified: doc/pod/news.pod
===================================================================
--- doc/pod/news.pod	2009-11-17 18:57:19 UTC (rev 8817)
+++ doc/pod/news.pod	2009-11-17 18:58:24 UTC (rev 8818)
@@ -70,6 +70,13 @@
 
 =item *
 
+A new feature has been added to B<sm>.  When the B<-c> flag is used,
+it shows a clear, decoded form of the storage API token.  This
+was previously done by the contrib B<showtoken> script developed
+by Olaf Titz and Marco d'Itri.
+
+=item *
+
 A new "unsigned long" type bas been added to the configuration parser.  It
 will properly warn the news administrator when a variable supposed to
 be positive contains a negative integer.  It will prevent INN

Modified: doc/pod/sm.pod
===================================================================
--- doc/pod/sm.pod	2009-11-17 18:57:19 UTC (rev 8817)
+++ doc/pod/sm.pod	2009-11-17 18:58:24 UTC (rev 8818)
@@ -4,11 +4,11 @@
 
 =head1 SYNOPSIS
 
-B<sm> [B<-dHiqRrS>] [I<token> ...]
+B<sm> [B<-cdHiqRrSs>] [I<token> ...]
 
 =head1 DESCRIPTION
 
-The INN storage manager is the subsystesm that stores and keeps track of
+The INN storage manager is the subsystem that stores and keeps track of
 all of the articles and what storage backend they're in.  All stored
 articles are assigned a storage API token.  B<sm> is a command-line
 interface to that storage manager, primarily used to retrieve articles by
@@ -16,11 +16,11 @@
 subsystem.
 
 I<token> is the token of an article (the same thing that's returned by
-B<grephistory> or stored in the history file).  It looks something like:
+B<grephistory> or stored in the F<history> file).  It looks something like:
 
     @0502000005A4000000010000000000000000@
 
-Any number of tokens can be given on the command line for any function
+Any number of tokens can be given on the command-line for any function
 other than B<-s>.  If none are, B<sm> normally reads tokens from standard
 input, one per line.  The default operation is to retrieve and write to
 standard output the corresponding article for each token given.
@@ -36,16 +36,23 @@
 
 =over 4
 
+=item B<-c>
+
+Show a clear, decoded form of the storage API token.  Each part of the token
+is explained, in a human-readable string.  Amongst other elements, this
+command gives the path to where the corresponding article is supposed
+to be stored.
+
 =item B<-d>, B<-r>
 
 Rather than retrieving the specified article, remove the article.  This
 will delete the article out of the news spool and it will not subsequently
 be retrievable by any part of INN.  It's equivalent to C<ctlinnd cancel>
-except it takes a storage API token instead of a message ID.
+except it takes a storage API token instead of a message-ID.
 
 =item B<-H>
 
-Retrieve only the header of the article rather than the entire article.
+Retrieve only the headers of the article rather than the entire article.
 This option cannot be used with B<-d>, B<-r>, B<-i>, or B<-S>.
 
 =item B<-i>
@@ -62,15 +69,15 @@
 =item B<-R>
 
 Display the raw article.  This means that line endings won't be converted
-to native line endings and will be left as CRLF sequences, leading periods
+to native line endings and will be left as CRLF sequences; leading periods
 will still be escaped for sending over NNTP, and the article will end in
 a CRLF.CRLF sequence.
 
 =item B<-S>
 
-Write the article to standard output in the format used by rnews spool
+Write the article to standard output in the format used by B<rnews> spool
 files.  Multiple articles can be written in this format, and the resulting
-output can be fed to rnews (on another system, for example) to inject
+output can be fed to B<rnews> (on another system, for example) to inject
 those articles into INN.  This option cannot be used with B<-d>, B<-r>,
 B<-H>, B<-i>, or B<-R>.
 
@@ -93,7 +100,7 @@
 still exit with status 1.
 
 This means that if you need to be sure whether a particular operation
-succeeded, you should run sm on one token at a time.
+succeeded, you should run B<sm> on one token at a time.
 
 =head1 HISTORY
 

Modified: frontends/sm.c
===================================================================
--- frontends/sm.c	2009-11-17 18:57:19 UTC (rev 8817)
+++ frontends/sm.c	2009-11-17 18:58:24 UTC (rev 8818)
@@ -1,6 +1,6 @@
 /*  $Id$
 **
-**  Provide a command line interface to the storage manager
+**  Provide a command line interface to the storage manager.
 */
 
 #include "config.h"
@@ -16,13 +16,14 @@
 #include "inn/storage.h"
 
 static const char usage[] = "\
-Usage: sm [-dHiqrRSs] [token ...]\n\
+Usage: sm [-cdHiqrRSs] [token ...]\n\
 \n\
 Command-line interface to the INN storage manager.  The default action is\n\
 to display the complete article associated with each token given.  If no\n\
 tokens are specified on the command line, they're read from stdin, one per\n\
 line.\n\
 \n\
+    -c          Show clear information about a token\n\
     -d, -r      Delete the articles associated with the given tokens\n\
     -H          Display the headers of articles only\n\
     -i          Translate tokens into newsgroup names and article numbers\n\
@@ -35,6 +36,7 @@
    do with each token. */
 struct options {
     bool artinfo;               /* Show newsgroup and article number. */
+    bool clearinfo;             /* Show clear information about a token. */
     bool delete;                /* Delete articles instead of showing them. */
     bool header;                /* Display article headers only. */
     bool raw;                   /* Show the raw wire-format articles. */
@@ -156,6 +158,10 @@
             printf("%s: %lu\n", artinfo.groupname, artinfo.artnum);
             free(artinfo.groupname);
         }
+    } else if (options->clearinfo) {
+        text = SMexplaintoken(token);
+        printf("%s %s\n", id, text);
+        free(text);
     } else if (options->delete) {
         if (!SMcancel(token)) {
             warn("could not remove %s: %s", id, SMerrorstr);
@@ -189,7 +195,7 @@
 {
     int option;
     bool okay, status;
-    struct options options = { false, false, false, false, false };
+    struct options options = { false, false, false, false, false, false };
     bool store = false;
 
     /* Suppress notice messages like tradspool rebuilding its map. */
@@ -200,8 +206,11 @@
     if (!innconf_read(NULL))
         exit(1);
 
-    while ((option = getopt(argc, argv, "iqrdRSsH")) != EOF) {
+    while ((option = getopt(argc, argv, "cdHiqrRSs")) != EOF) {
         switch (option) {
+        case 'c':
+            options.clearinfo = true;
+            break;
         case 'd':
         case 'r':
             options.delete = true;
@@ -246,6 +255,9 @@
         die("-s cannot be used with -i, -r, -d, -H, -R, or -S");
     if (store && (options.raw || options.rnews))
         die("-s cannot be used with -i, -r, -d, -H, -R, or -S");
+    if (options.clearinfo && (options.artinfo || options.delete || options.header
+                              || options.raw || options.rnews || store))
+        die("-c cannot be used with -i, -r, -d, -H, -R, -S, or -s");
 
     /* Initialize the storage manager.  If we're doing article deletions, we
        need to open it read/write. */

Modified: include/inn/storage.h
===================================================================
--- include/inn/storage.h	2009-11-17 18:57:19 UTC (rev 8817)
+++ include/inn/storage.h	2009-11-17 18:58:24 UTC (rev 8818)
@@ -85,6 +85,7 @@
 bool        SMprobe(PROBETYPE type, TOKEN *token, void *value);
 bool        SMflushcacheddata(FLUSHTYPE type);
 void        SMprintfiles(FILE *file, TOKEN token, char **xref, int ngroups);
+char *      SMexplaintoken(const TOKEN token);
 void        SMshutdown(void);
 
 END_DECLS

Modified: storage/buildconfig.in
===================================================================
--- storage/buildconfig.in	2009-11-17 18:57:19 UTC (rev 8817)
+++ storage/buildconfig.in	2009-11-17 18:58:24 UTC (rev 8818)
@@ -15,7 +15,7 @@
 
 # Storage API functions.
 @STORAGE = qw(init store retrieve next freearticle cancel ctl flushcacheddata
-              printfiles shutdown);
+              printfiles explaintoken shutdown);
 
 # Overview API functions.
 @OVERVIEW = qw(open groupstats groupadd groupdel add cancel opensearch search

Modified: storage/cnfs/cnfs.c
===================================================================
--- storage/cnfs/cnfs.c	2009-11-17 18:57:19 UTC (rev 8817)
+++ storage/cnfs/cnfs.c	2009-11-17 18:58:24 UTC (rev 8818)
@@ -60,18 +60,51 @@
 static int		metabuff_update = METACYCBUFF_UPDATE;
 static int		refresh_interval = REFRESH_INTERVAL;
 
+static CYCBUFF          *CNFSgetcycbuffbyname(char *name);
+
+
+/*
+**  The token is @03nnxxxxxxxxxxxxxxxxyyyyyyyyzzzzzzzz@
+**  where "03" is the cnfs method number,
+**  "nn" the hexadecimal value of the storage class,
+**  "xxxxxxxxxxxxxxxx" the name of the cyclic buffer (as defined
+**  in <pathetc>/cycbuff.conf),
+**  "yyyyyyyy" the block,
+**  "zzzzzzzz" the cyclic number.
+*/
+char *
+cnfs_explaintoken(const TOKEN token)
+{
+    char                *text;
+    CYCBUFF             *cycbuff;
+    char                cycbuffname[CNFSMAXCYCBUFFNAME+1];
+    unsigned int        blksz;
+    uint32_t            block;
+    uint32_t            cycnum;
+
+    snprintf(cycbuffname, sizeof(cycbuffname), "%s", token.token);
+
+    if ((cycbuff = CNFSgetcycbuffbyname(cycbuffname)) == NULL) {
+        blksz = CNFS_DFL_BLOCKSIZE;
+    } else {
+        blksz = (unsigned int) cycbuff->blksz;
+    }
+
+    memcpy(&block, &token.token[8], sizeof(block));
+    memcpy(&cycnum, &token.token[12], sizeof(cycnum));
+    xasprintf(&text, "method=cnfs class=%u buffer=%s block=%lu blocksize=%u cycnum=%lu file=%s",
+              (unsigned int) token.class, cycbuffname, ntohl(block), blksz, ntohl(cycnum),
+              cycbuff ? cycbuff->path : "");
+
+    return text;
+}
+
+
 static TOKEN CNFSMakeToken(char *cycbuffname, off_t offset,
 			   int blksz, uint32_t cycnum, STORAGECLASS class) {
     TOKEN               token;
     uint32_t		uint32;
 
-    /* The token is @03nnxxxxxxxxxxxxxxxxyyyyyyyyzzzzzzzz@
-     * where "03" is the cnfs method number,
-     * "nn" the hexadecimal value of the storage class,
-     * "xxxxxxxxxxxxxxxx" the name of the cyclic buffer (as defined
-     * in <pathetc>/cycbuff.conf),
-     * "yyyyyyyy" the offset,
-     * "zzzzzzzz" the cyclic number. */
     token.type = TOKEN_CNFS;
     token.class = class;
     memcpy(token.token, cycbuffname, CNFSMAXCYCBUFFNAME);

Modified: storage/cnfs/cnfs.h
===================================================================
--- storage/cnfs/cnfs.h	2009-11-17 18:57:19 UTC (rev 8817)
+++ storage/cnfs/cnfs.h	2009-11-17 18:58:24 UTC (rev 8818)
@@ -15,6 +15,7 @@
 bool cnfs_ctl(PROBETYPE type, TOKEN *token, void *value);
 bool cnfs_flushcacheddata(FLUSHTYPE type);
 void cnfs_printfiles(FILE *file, TOKEN token, char **xref, int ngroups);
+char *cnfs_explaintoken(const TOKEN token);
 void cnfs_shutdown(void);
 
 #endif

Modified: storage/interface.c
===================================================================
--- storage/interface.c	2009-11-17 18:57:19 UTC (rev 8817)
+++ storage/interface.c	2009-11-17 18:58:24 UTC (rev 8818)
@@ -1,6 +1,6 @@
 /*  $Id$
 **
-**  Storage Manager interface
+**  Storage Manager interface.
 */
 #include "config.h"
 #include "clibrary.h"
@@ -792,6 +792,15 @@
     storage_methods[typetoindex[token.type]].printfiles(file, token, xref, ngroups);
 }
 
+/*
+**  Print a clear, decoded information on a token.
+*/
+char *
+SMexplaintoken(const TOKEN token)
+{
+    return storage_methods[typetoindex[token.type]].explaintoken(token);
+}
+
 void SMshutdown(void) {
     int                 i;
     STORAGE_SUB         *old;

Modified: storage/interface.h
===================================================================
--- storage/interface.h	2009-11-17 18:57:19 UTC (rev 8817)
+++ storage/interface.h	2009-11-17 18:58:24 UTC (rev 8818)
@@ -27,6 +27,7 @@
     bool                (*ctl)(PROBETYPE type, TOKEN *token, void *value);
     bool                (*flushcacheddata)(FLUSHTYPE type);
     void                (*printfiles)(FILE *, TOKEN, char **xref, int ngroups);
+    char                *(*explaintoken)(const TOKEN token);
     void                (*shutdown)(void);
 } STORAGE_METHOD;
 

Modified: storage/timecaf/timecaf.c
===================================================================
--- storage/timecaf/timecaf.c	2009-11-17 18:57:19 UTC (rev 8817)
+++ storage/timecaf/timecaf.c	2009-11-17 18:58:24 UTC (rev 8818)
@@ -97,17 +97,45 @@
 static CAFTOCL3CACHE *TOCCache[256]; /* indexed by storage class! */
 static int TOCCacheHits, TOCCacheMisses;
 
+/*
+**  The token is @04nn00aabbccyyyyxxxx0000000000000000@
+**  where "04" is the timecaf method number,
+**  "nn" the hexadecimal value of the storage class,
+**  "aabbccdd" the arrival time in hexadecimal (dd is unused),
+**  "xxxxyyyy" the hexadecimal sequence number seqnum.
+**
+**  innconf->patharticles + '/timecaf-nn/bb/aacc.CF'
+**  where "nn" is the hexadecimal value of the storage class,
+**  "aabbccdd" the arrival time in hexadecimal (dd is unused).
+*/
+char *
+timecaf_explaintoken(const TOKEN token)
+{
+    char                *text;
+    uint32_t            arrival;
+    uint16_t            seqnum1;
+    uint16_t            seqnum2;
 
+    memcpy(&arrival, &token.token[0], sizeof(arrival));
+    memcpy(&seqnum1, &token.token[4], sizeof(seqnum1));
+    memcpy(&seqnum2, &token.token[6], sizeof(seqnum2));
+ 
+    xasprintf(&text, "method=timecaf class=%u time=%lu seqnum=%lu file=%s/timecaf-%02x/%02x/%02x%02x.CF",
+              (unsigned int) token.class, ntohl(arrival) << 8,
+              ntohs(seqnum1) + (ntohs(seqnum2) << 16),
+              innconf->patharticles, token.class,
+              (ntohl(arrival) >> 8) & 0xff,
+              (ntohl(arrival) >> 16) & 0xff,
+              ntohl(arrival) & 0xff);
+
+    return text;
+}
+
 static TOKEN MakeToken(time_t now, ARTNUM seqnum, STORAGECLASS class, TOKEN *oldtoken) {
     TOKEN               token;
     uint32_t            i;
     uint16_t            s;
 
-    /* The token is @04nn00aabbccyyyyxxxx0000000000000000@
-     * where "04" is the timecaf method number,
-     * "nn" the hexadecimal value of the storage class,
-     * "aabbccdd" the arrival time in hexadecimal (dd is unused),
-     * "xxxxyyyy" the hexadecimal sequence number seqnum. */
     if (oldtoken == (TOKEN *)NULL)
 	memset(&token, '\0', sizeof(token));
     else
@@ -144,9 +172,6 @@
     char *path;
     size_t length;
 
-    /* innconf->patharticles + '/timecaf-nn/bb/aacc.CF'
-     * where "nn" is the hexadecimal value of the storage class,
-     * "aabbccdd" the arrival time in hexadecimal (dd is unused). */
     length = strlen(innconf->patharticles) + 32;
     path = xmalloc(length);
     snprintf(path, length, "%s/timecaf-%02x/%02x/%02x%02x.CF",

Modified: storage/timecaf/timecaf.h
===================================================================
--- storage/timecaf/timecaf.h	2009-11-17 18:57:19 UTC (rev 8817)
+++ storage/timecaf/timecaf.h	2009-11-17 18:58:24 UTC (rev 8818)
@@ -20,6 +20,7 @@
 bool timecaf_ctl(PROBETYPE type, TOKEN *token, void *value);
 bool timecaf_flushcacheddata(FLUSHTYPE type);
 void timecaf_printfiles(FILE *file, TOKEN token, char **xref, int ngroups);
+char *timecaf_explaintoken(const TOKEN token);
 void timecaf_shutdown(void);
 
 #endif

Modified: storage/timehash/timehash.c
===================================================================
--- storage/timehash/timehash.c	2009-11-17 18:57:19 UTC (rev 8817)
+++ storage/timehash/timehash.c	2009-11-17 18:58:24 UTC (rev 8818)
@@ -38,16 +38,42 @@
 
 static int SeqNum = 0;
 
+/*
+**  The token is @02nnaabbccddyyyy00000000000000000000@
+**  where "02" is the timehash method number,
+**  "nn" the hexadecimal value of the storage class,
+**  "aabbccdd" the arrival time in hexadecimal,
+**  "yyyy" the hexadecimal sequence number seqnum.
+**
+**  innconf->patharticles + '/time-nn/bb/cc/yyyy-aadd'
+**  where "nn" is the hexadecimal value of the storage class,
+**  "aabbccdd" the arrival time in hexadecimal,
+**  "yyyy" the hexadecimal sequence number seqnum.
+*/
+char *
+timehash_explaintoken(const TOKEN token)
+{
+    char                *text;
+    uint32_t            arrival;
+    uint16_t            seqnum;
+
+    memcpy(&arrival, &token.token[0], sizeof(arrival));
+    memcpy(&seqnum, &token.token[4], sizeof(seqnum));
+
+    xasprintf(&text, "method=timehash class=%u time=%lu seqnum=%lu file=%s/time-%02x/%02x/%02x/%04x-%02x%02x",
+              (unsigned int) token.class, ntohl(arrival), ntohs(seqnum),
+              innconf->patharticles, token.class, (ntohl(arrival) >> 16) & 0xff,
+              (ntohl(arrival) >> 8) & 0xff, ntohs(seqnum),
+              (ntohl(arrival) >> 24) & 0xff, ntohl(arrival) & 0xff);
+
+    return text;
+}
+
 static TOKEN MakeToken(time_t now, int seqnum, STORAGECLASS class, TOKEN *oldtoken) {
     TOKEN               token;
     uint32_t            i;
     uint16_t            s;
 
-    /* The token is @02nnaabbccddyyyy00000000000000000000@
-     * where "02" is the timehash method number,
-     * "nn" the hexadecimal value of the storage class,
-     * "aabbccdd" the arrival time in hexadecimal,
-     * "yyyy" the hexadecimal sequence number seqnum. */
     if (oldtoken == (TOKEN *)NULL)
 	memset(&token, '\0', sizeof(token));
     else
@@ -75,10 +101,6 @@
     char *path;
     size_t length;
 
-    /* innconf->patharticles + '/time-nn/bb/cc/yyyy-aadd'
-     * where "nn" is the hexadecimal value of the storage class,
-     * "aabbccdd" the arrival time in hexadecimal,
-     * "yyyy" the hexadecimal sequence number seqnum. */
     length = strlen(innconf->patharticles) + 32;
     path = xmalloc(length);
     snprintf(path, length, "%s/time-%02x/%02x/%02x/%04x-%04x",

Modified: storage/timehash/timehash.h
===================================================================
--- storage/timehash/timehash.h	2009-11-17 18:57:19 UTC (rev 8817)
+++ storage/timehash/timehash.h	2009-11-17 18:58:24 UTC (rev 8818)
@@ -18,6 +18,7 @@
 bool timehash_ctl(PROBETYPE type, TOKEN *token, void *value);
 bool timehash_flushcacheddata(FLUSHTYPE type);
 void timehash_printfiles(FILE *file, TOKEN token, char **xref, int ngroups);
+char *timehash_explaintoken(const TOKEN token);
 void timehash_shutdown(void);
 
 #endif

Modified: storage/tradspool/tradspool.c
===================================================================
--- storage/tradspool/tradspool.c	2009-11-17 18:57:19 UTC (rev 8817)
+++ storage/tradspool/tradspool.c	2009-11-17 18:58:24 UTC (rev 8818)
@@ -78,6 +78,8 @@
 bool NGTableUpdated; /* set to true if we've added any entries since reading
 			in the database file */
 
+static char * TokenToPath(TOKEN token);
+
 /*
 ** Convert all .s to /s in a newsgroup name.  Modifies the passed string
 ** inplace.
@@ -462,19 +464,52 @@
     return InitNGTable();
 }
 
-/* Make a token for an article given the primary newsgroup name and article # */
+/*
+**  The token is @05nnxxxxxxxxyyyyyyyy0000000000000000@
+**  where "05" is the tradspool method number,
+**  "nn" the hexadecimal value of the storage class,
+**  "xxxxxxxx" the name of the primary newsgroup (as defined
+**  in <pathspool>/tradspool.map),
+**  "yyyyyyyy" the article number in the primary newsgroup.
+**
+**  innconf->patharticles + '/news/group/path/yyyyyyyy'
+**  where "news/group/path" is the path of the primary newsgroup
+**  (as defined in <pathspool>/tradspool.map),
+**  "yyyyyyyy" the article number in the primary newsgroup.
+*/
+char *
+tradspool_explaintoken(const TOKEN token)
+{
+    char                *text;
+    char                *path;
+    uint32_t            ngnum;
+    uint32_t            artnum;
+
+    memcpy(&ngnum, &token.token[0], sizeof(ngnum));
+    memcpy(&artnum, &token.token[4], sizeof(artnum));
+
+    path = TokenToPath(token);
+
+    xasprintf(&text, "method=tradspool class=%u ngnum=%lu artnum=%lu file=%s",
+              (unsigned int) token.class, ntohl(ngnum), ntohl(artnum),
+              path != NULL ? path : "");
+
+    if (path != NULL)
+        free(path);
+
+    return text;
+}
+
+/*
+**  Make a token for an article given the primary newsgroup name and
+**  article number.
+*/
 static TOKEN
 MakeToken(char *ng, unsigned long artnum, STORAGECLASS class) {
     TOKEN token;
     NGTENT *ngtp;
     unsigned long num;
 
-    /* The token is @05nnxxxxxxxxyyyyyyyy0000000000000000@
-     * where "05" is the tradspool method number,
-     * "nn" the hexadecimal value of the storage class,
-     * "xxxxxxxx" the name of the primary newsgroup (as defined
-     * in <pathspool>/tradspool.map),
-     * "yyyyyyyy" the article number in the primary newsgroup. */
     memset(&token, '\0', sizeof(token));
 
     token.type = TOKEN_TRADSPOOL;
@@ -507,10 +542,6 @@
     char *ng, *path;
     size_t length;
 
-    /* innconf->patharticles + '/news/group/path/yyyyyyyy'
-     * where "news/group/path" is the path of the primary newsgroup
-     * (as defined in <pathspool>/tradspool.map),
-     * "yyyyyyyy" the article number in the primary newsgroup. */
     CheckNeedReloadDB(false);
 
     memcpy(&ngnum, &token.token[0], sizeof(ngnum));

Modified: storage/tradspool/tradspool.h
===================================================================
--- storage/tradspool/tradspool.h	2009-11-17 18:57:19 UTC (rev 8817)
+++ storage/tradspool/tradspool.h	2009-11-17 18:58:24 UTC (rev 8818)
@@ -18,6 +18,7 @@
 bool tradspool_ctl(PROBETYPE type, TOKEN *token, void *value);
 bool tradspool_flushcacheddata(FLUSHTYPE type);
 void tradspool_printfiles(FILE *file, TOKEN token, char **xref, int ngroups);
+char *tradspool_explaintoken(const TOKEN token);
 void tradspool_shutdown(void);
 
 #endif

Modified: storage/trash/trash.c
===================================================================
--- storage/trash/trash.c	2009-11-17 18:57:19 UTC (rev 8817)
+++ storage/trash/trash.c	2009-11-17 18:58:24 UTC (rev 8818)
@@ -82,6 +82,16 @@
 {
 }
 
+char *
+trash_explaintoken(const TOKEN token UNUSED)
+{
+    char *text;
+
+    xasprintf(&text, "method=%s", "trash");
+
+    return text;
+}
+
 ARTHANDLE *
 trash_next(ARTHANDLE *article UNUSED, const RETRTYPE amount UNUSED)
 {

Modified: storage/trash/trash.h
===================================================================
--- storage/trash/trash.h	2009-11-17 18:57:19 UTC (rev 8817)
+++ storage/trash/trash.h	2009-11-17 18:58:24 UTC (rev 8818)
@@ -18,6 +18,7 @@
 bool trash_ctl(PROBETYPE type, TOKEN *token, void *value);
 bool trash_flushcacheddata(FLUSHTYPE type);
 void trash_printfiles(FILE *file, TOKEN token, char **xref, int ngroups);
+char *trash_explaintoken(const TOKEN token);
 void trash_shutdown(void);
 
 #endif

Modified: support/mkmanifest
===================================================================
--- support/mkmanifest	2009-11-17 18:57:19 UTC (rev 8817)
+++ support/mkmanifest	2009-11-17 18:58:24 UTC (rev 8818)
@@ -123,7 +123,6 @@
 contrib/pullart
 contrib/reset-cnfs
 contrib/respool
-contrib/showtoken
 contrib/stathist
 contrib/thdexpire
 contrib/tunefeed




More information about the inn-committers mailing list