chiark / gitweb /
update debian version
[inn-innduct.git] / contrib / showtoken.in
1 #!/usr/bin/perl -w
2 # showtoken - decode SM tokens
3 # Olaf Titz, 1999. Marco d'Itri, 2000. Public domain.
4 # Takes tokens on stdin and write them along with a decoded form on stdout.
5
6 use strict;
7
8 my ($pathspool, %NG);
9
10 my @types = ('trash', '', 'timehash', 'cnfs', 'timecaf', 'tradspool');
11
12 if ($ARGV[0]) {
13         $pathspool = $ARGV[0];
14         if (open(MAP, "$pathspool/tradspool.map")) {
15                 while (<MAP>) {
16                         my ($ng, $gnum) = split;
17                         $NG{$gnum} = $ng;
18                 }
19                 close MAP;
20         }
21 }
22
23 $| = 1;
24 while (<STDIN>) {
25         chomp;
26         next if not /^@.+@/;
27         print "$_ ";
28         splittoken($_);
29 }
30
31 sub splittoken {
32         my $t = shift;
33
34         $t =~ tr/@//d;
35         $t = pack('H*', $t);
36         my ($type, $class, $token, $index, $offset, $overlen, $cancelled) =
37                 unpack('C C a16 CLnc', $t);
38
39         if (not $types[$type]) {
40                 print "type=$type unknown!\n";
41                 next;
42         }
43         print "type=$types[$type] class=$class ";
44
45         if ($type == 0) {               # trash
46         } elsif ($type == 2) {  # timehash
47                 my ($time, $seq) = unpack('Nn', $token);
48                 my ($a, $b, $c, $d) = unpack('CCCC', $token);
49                 printf 'time=%08lX seq=%04X file=time-%02x/%02x/%02x/%04x-%02x%02x',
50                         $time, $seq, $class, $b, $c, $seq, $a, $d;
51         } elsif ($type == 3) {  # cnfs
52                 my ($buffn, $offset, $cnum) = unpack('A8NN', $token);
53                 printf 'buffer=%s offset=%x cycnum=%x', $buffn, $offset * 512, $cnum;
54         } elsif ($type == 4) {  # timecaf
55                 my ($time, $seq) = unpack('Nn', $token);
56                 my (undef, $b, $c, $d) = unpack('CCCC', $token);
57                 printf 'time=%06lX seq=%04X caf=timecaf-%02x/%02x/%02x%02x.CF',
58                         $time, $seq, $class, $c, $b, $d;
59         } elsif ($type == 5) {  # tradspool
60                 my ($gnum, $art) = unpack('NN', $token);
61                 printf 'ng=%08X art=%d', $gnum, $art;
62                 print "file=articles/$NG{$gnum}/$art" if $NG{$gnum};
63         } else {
64                 die "invalid type $type";
65         }
66         print " over=$index offset=$offset overlen=$overlen cancelled=$cancelled"
67                 if length $t > 36;
68         print "\n";
69 }
70 __END__
71 # Format of a token:
72 #  1   type
73 #  1   class
74 # 16   token
75 #  1   index
76 #  4   offset
77 #  2   overlen
78 #  2   cancelled
79 # The fields "index" and following are not available with OV3 (INN 2.3 up)
80 #
81 # the "token" field is:
82 # for type=0 (trash) ignored
83 # for type=2 (timehash)
84 #  4   time
85 #  2   seqnum
86 # for type=3 (cnfs)
87 #  8   cycbuffname
88 #  4   offset/512
89 #  4   cycnum
90 # for type=4 (timecaf)
91 #  4   time
92 #  2   seqnum
93 # for type=5 (tradspool)
94 #  4   ngnum
95 #  4   artnum