🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #11133

Re: Wanted: News searching utility

#11133
From: Christopher Davis
Date: Tue, 30 Aug 1994 14:55
251 lines
9053 bytes
GK> == Greg Kuperberg <gk00@quads.uchicago.edu>

 GK> In principle, these searches are reasonably fast with a threaded NNTP
 GK> server, using XHDR commands and some computation.  I'm thinking of
 GK> writing a PERL script to do the job.  I'd like to know there already
 GK> is such an animal.

Even faster--use XOVER if you have it.  Here's a quick hack I threw
together from parts of other things I'd written.

It just spews out a list of msgids, but those are easily converted into
articles.  Something like 'nnrpArticle' can be easily added to the code.

It could be a lot faster than it is; one proposed extension to LIST would
replace the "download active file and search it" bit.  It could also use
XPAT (under INN) for searches which didn't require regexps.

-f and -s are from, and subject, case insensitive.  -F and -S are case
sensitive.  -g is a group glob list (-g 'uchi.*,comp.mail.*' for example).

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  novgrep.pl nnrpfunc.pl
# Wrapped by ckd@loiosh.kei.com on Tue Aug 30 10:53:47 1994
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'novgrep.pl' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'novgrep.pl'\"
else
echo shar: Extracting \"'novgrep.pl'\" \(1442 characters\)
sed "s/^X//" >'novgrep.pl' <<'END_OF_FILE'
X#!/usr/bin/perl
X
X$nntpserver = $ENV{'NNTPSERVER'} || 'news';
X
Xrequire 'nnrpfunc.pl';
Xrequire 'getopts.pl';
X
X&Getopts('f:s:F:S:g:');
X
Xdie "need at least one of -[fsFS]\n"
X    unless ($opt_f || $opt_s || $opt_F || $opt_S);
X
Xdie "no group list\n"
X    unless $opt_g;
X
X$checksub = 'sub checkForHit {
X    local($overviewline) = @_;
X
X    local($artnum,$subject,$from,$date,$msgid,$bytes,$lines,$rest)=
X	split(/\t/,$overviewline);
X
X    push(@hits,$msgid) if (';
X
Xpush(@checks,"(\$subject =~ /$opt_s/i)") if $opt_s;
Xpush(@checks,"(\$from =~ /$opt_f/i)") if $opt_f;
Xpush(@checks,"(\$subject =~ /$opt_S/)") if $opt_S;
Xpush(@checks,"(\$from =~ /$opt_F/)") if $opt_F;
X
X$checksub .= join(" && ",@checks);
X$checksub .= ");\n}\n";
X
Xeval $checksub;
X
X# turn the @groups into a regex.  (convert wildmat-style)
X@grouppats = split(',',$opt_g);
X
Xforeach (@grouppats) {
X    s/\./\\./g;
X    s/\*/.*/g;
X    s/,/|/g;
X    s/\?/./g;
X}
X
X$grouppat = '^' . join('|',@grouppats) . '$'; #';
X
X$connection = &nnrpOpen($nntpserver);
X
X@active = &nnrpList($connection,"");
X
Xforeach (@active) {
X    ($group,$hi,$lo,$flags) = split(' ',$_,4);
X    next unless ($flags =~ /^[ynm]$/); # no aliased groups please
X    $groups{$group}++ if ($group =~ /$grouppat/o);
X}
X
Xforeach $group (keys %groups) {
X    ($first,$last,$num) = &nnrpGroup($connection,$group);
X    foreach $line (&nnrpXover($connection,$first,$last)) {
X	&checkForHit($line);
X    }
X}
X
Xforeach (@hits) {
X    print $_,"\n";
X}
END_OF_FILE
if test 1442 -ne `wc -c <'novgrep.pl'`; then
    echo shar: \"'novgrep.pl'\" unpacked with wrong size!
fi
chmod +x 'novgrep.pl'
# end of 'novgrep.pl'
fi
if test -f 'nnrpfunc.pl' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'nnrpfunc.pl'\"
else
echo shar: Extracting \"'nnrpfunc.pl'\" \(3860 characters\)
sed "s/^X//" >'nnrpfunc.pl' <<'END_OF_FILE'
X# this is a library routine file.  it is not separately executable.
X
X# somewhat based on nntp.pl by ishii@hexard.co.jp and jik@gza.com
X
X# set $nnrpfunc'debug for debugging output.
X
Xrequire "sys/socket.ph";
X
Xpackage nnrpfunc;
X
X$fhsym="nnrpfunc000000";	# for generating filehandle names
X
X$sockaddr_t = "S n a4 x8";	# or so we hope.  should be c2ph'ed, really
Xchop($myhost = `hostname`);	# cache this for future reference
X
X# send command, read response code.  internal.
Xsub nnrpCommand {
X    local($filehandle,$command) = @_;
X    local($response);
X
X    print $filehandle $command,"\r\n"; # Internet line-ending convention CRLF
X    print STDERR ">> $filehandle >> $command\n" if $debug;
X    $response = <$filehandle>;
X    $response =~ s/\r$//;
X    print STDERR "<< $filehandle << $response" if $debug;
X    $response;			# implicit return
X}
X
X# open connection to server, return name of filehandle.  public.
Xsub main'nnrpOpen {		# '{
X    local($servername) = @_;
X    local($name,$aliases,$proto,$port,$type,$len,$thisaddr,$thataddr,
X	  $this,$that,$filehandle,$banner,$readermode,$bannercode,
X	  $readermodecode);
X
X    # set up all the socket gubbish.  you call this an API?
X    ($name,$aliases,$proto) = getprotobyname('tcp');
X    ($name,$aliases,$port) = getservbyname('nntp','tcp');
X    ($name,$aliases,$type,$len,$thisaddr) = gethostbyname($hostname);
X    ($name,$aliases,$type,$len,$thataddr) = gethostbyname($servername);
X    $this = pack($sockaddr_t, &main'AF_INET, 0, $thisaddr); #');
X    $that = pack($sockaddr_t, &main'AF_INET, $port, $thataddr); #');
X
X    # now that the rigmarole is done, connect to the server with more rigmarole
X    $filehandle = $fhsym++;
X    socket($filehandle, &main'PF_INET, &main'SOCK_STREAM, $proto) ||
X	die "socket failed";
X    bind($filehandle, $this) || die "bind failed";
X    connect($filehandle, $that) || die "connect failed";
X
X    # turn off stdio buffering so we can work effectively
X    local($savefh) = select($filehandle);
X    $| = 1;
X    select($savefh);
X
X    $banner = <$filehandle>;
X    $banner =~ s/\r$//;
X
X    print STDERR "<< $filehandle << $banner" if $debug;
X
X    die "Server $servername must not like you: $banner"
X	unless ($banner =~ /^20[01]/);
X
X    $readermode = &nnrpCommand($filehandle,"MODE READER");
X
X    die "MODE READER blew up in some annoying way: $readermode"
X	unless ($readermode =~ /^(20[01]|500)/);
X
X    ($bannercode) = ($banner =~ /^(\d\d\d)/);
X
X    $can_post{$filehandle} = ($bannercode eq "200");
X
X    $filehandle;		# implicit return
X}
X
Xsub main'nnrpQuit {		# '{
X    local($filehandle) = @_;
X
X    &nnrpCommand($filehandle,"QUIT"); # implicit return
X}
X
X# for reading in a bunch of lines, each ended by CRNL, terminating in a line
X# with a lone dot.  returns an array of NL-terminated strings.  does not
X# return the lone dot.  (Also handles NNTP dot-doubling.)
Xsub nnrpGetLongResponse {
X    local($filehandle) = @_;
X    local(@retval);
X
X    while(<$filehandle>) {
X	s/\r$//;		# clean off CR
X	print "<< $filehandle << $_" if $debug;
X	s/^\.//;		# take out first dot if any
X	last if /^$/;		# if it was "." then done
X	push(@retval,$_);	# if not, keep it
X    }
X    @retval;			# implicit return
X}
X
Xsub main'nnrpGroup {		# '{
X    local($filehandle,$group) = @_;
X    local($respcode,$numarts,$firstart,$lastart);
X
X    ($respcode,$numarts,$firstart,$lastart) =
X	split(/\s+/,&nnrpCommand($filehandle, "GROUP $group"));
X
X    return undef unless ($respcode =~ /^[23]/);
X    ($firstart,$lastart,$numarts); # implicit return
X}
X
Xsub main'nnrpXover {		#'{
X    local($filehandle,$first,$last) = @_;
X
X    $last = $first unless $last; # make sure there's a range
X
X    &nnrpCommand($filehandle,"XOVER $first-$last");
X    &nnrpGetLongResponse($filehandle);
X}
X
Xsub main'nnrpList {		#'{
X    local($filehandle,$listtype) = @_;
X
X    &nnrpCommand($filehandle,"LIST $listtype");
X    &nnrpGetLongResponse($filehandle);
X}
X
END_OF_FILE
if test 3860 -ne `wc -c <'nnrpfunc.pl'`; then
    echo shar: \"'nnrpfunc.pl'\" unpacked with wrong size!
fi
# end of 'nnrpfunc.pl'
fi
echo shar: End of shell archive.
exit 0
-- 
Christopher Davis * <ckd@kei.com> * (was <ckd@eff.org>) * MIME * PGP * [CKD1]
  "It's 106 ms to Chicago, we've got a full disk of GIFs, half a meg of
     hypertext, it's dark, and we're wearing sunglasses."  "Click it."
      - Looking for: _The Big U_, by Neal Stephenson (out of print) -
Technical Details
Message-ID: <33vh9c$1c4@kei.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp!wupost!udel!MathWorks.Com!news.kei.com!usenet
References: <1994Aug29.214842.3996@midway.uchicago.edu>

Show Full Headers
Complete Article Headers
Message-ID: <33vh9c$1c4@kei.com>
Subject: Re: Wanted: News searching utility
Date: Tue, 30 Aug 1994 14:55:40 +0000
From: ckd@loiosh.kei.com (Christopher Davis)
References: <1994Aug29.214842.3996@midway.uchicago.edu>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp!wupost!udel!MathWorks.Com!news.kei.com!usenet
Newsgroups: news.software.readers,comp.lang.perl,alt.sources
Followup-To: news.software.readers
Organization: Hellspark Trading Association
Lines: 250
NNTP-Posting-Host: loiosh.kei.com
In-reply-to: gk00@quads.uchicago.edu's message of Mon, 29 Aug 1994 21:48:42 GMT
X-Attribution: ckd