🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nntp
17 messages
17 total messages Started by Mark W Modrall Fri, 19 Jan 2001 20:53
docs on filter_art? Mime tools?
#50004
Author: Mark W Modrall
Date: Fri, 19 Jan 2001 20:53
20 lines
1224 bytes
Hi...

	I've been wondering where to find documentation on
the whole environment for writing perl filters?  I know 
there's the hdr array, and the text is in __BODY__ but
i haven't seen much more about what else is in the env.

	I'm trying to use MIME tools in conjunction with
the perl hook, and it seems like a waste to reconstruct
the message text from hdr and pass it to the parser for
processing...

	i didn't see any man pages that seemed right on
point, and wading through web page searches doesn't turn
up much...

thanks
-mark

Re: docs on filter_art? Mime tools?
#50000
Author: Russ Allbery
Date: Fri, 19 Jan 2001 23:17
17 lines
1443 bytes
Mark W Modrall <modrall@world.std.com> writes:

> I've been wondering where to find documentation on the whole environment
> for writing perl filters?

README.perl_hook in the top level of the INN source tree.

> I'm trying to use MIME tools in conjunction with the perl hook, and it
> seems like a waste to reconstruct the message text from hdr and pass it
> to the parser for processing...

You pretty much have to do that with the current interface at present,
though.

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>
Re: docs on filter_art? Mime tools?
#50005
Author: Andrew Gierth
Date: Sat, 20 Jan 2001 07:22
19 lines
1831 bytes
>>>>> "Mark" == Mark W Modrall <modrall@world.std.com> writes:

 Mark> Hi...
 Mark> 	I've been wondering where to find documentation on the whole
 Mark> environment for writing perl filters?  I know there's the hdr
 Mark> array, and the text is in __BODY__ but i haven't seen much more
 Mark> about what else is in the env.

 Mark> 	I'm trying to use MIME tools in conjunction with the perl
 Mark> hook, and it seems like a waste to reconstruct the message text
 Mark> from hdr and pass it to the parser for processing...

I did a hack at one point to include __ART__ and __HEAD__ in the
%hdr array for roughly this reason, and in order to get at headers
that were not in the compiled-in header list.

-- 
Andrew.
Re: docs on filter_art? Mime tools?
#50036
Author: Mark W Modrall
Date: Mon, 22 Jan 2001 16:24
41 lines
2176 bytes
Thanks Russ...  at least it's nice to know i wasn't missing something
obvious...

Kind of on a related topic (related since it's something i'm trying
to lay out) - is there any support for wildmat-type matching extended
to the perl hooks?

I'm thinking of trying to implement a perl hook with a configuration
array that would hold various wildmats on newsgroups to allow for
different check functions to be run depending on what groups it's in...

unless i'm just missing something, it seems that the wildmat is an
extension on regexps, and it would be nice to have something like that
in perl...  i suppose i can just set up an associative array holding some
patterns and match against them in perl

thanks
-mark


In article <yllms7cesh.fsf@windlord.stanford.edu>,
Russ Allbery  <rra@stanford.edu> wrote:
>Mark W Modrall <modrall@world.std.com> writes:
>
>> I've been wondering where to find documentation on the whole environment
>> for writing perl filters?
>
>README.perl_hook in the top level of the INN source tree.
>
>> I'm trying to use MIME tools in conjunction with the perl hook, and it
>> seems like a waste to reconstruct the message text from hdr and pass it
>> to the parser for processing...
>
>You pretty much have to do that with the current interface at present,
>though.
>
>-- 
>Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>


Re: docs on filter_art? Mime tools?
#50035
Author: Mark W Modrall
Date: Mon, 22 Jan 2001 16:25
31 lines
1803 bytes
Hi Andrew...

	that sounds very interesting...  would you be willing to make
it generally available?  Maybe they'd even put it in the core code...

thanks
-mark

In article <873deesn59.fsf@erlenstar.demon.co.uk>,
Andrew Gierth  <andrew@erlenstar.demon.co.uk> wrote:
>>>>>> "Mark" == Mark W Modrall <modrall@world.std.com> writes:
>
> Mark> Hi...
> Mark> 	I've been wondering where to find documentation on the whole
> Mark> environment for writing perl filters?  I know there's the hdr
> Mark> array, and the text is in __BODY__ but i haven't seen much more
> Mark> about what else is in the env.
>
> Mark> 	I'm trying to use MIME tools in conjunction with the perl
> Mark> hook, and it seems like a waste to reconstruct the message text
> Mark> from hdr and pass it to the parser for processing...
>
>I did a hack at one point to include __ART__ and __HEAD__ in the
>%hdr array for roughly this reason, and in order to get at headers
>that were not in the compiled-in header list.
>
>-- 
>Andrew.


Re: docs on filter_art? Mime tools?
#50053
Author: Russ Allbery
Date: Mon, 22 Jan 2001 23:54
34 lines
2306 bytes
Mark W Modrall <modrall@world.std.com> writes:

> Thanks Russ...  at least it's nice to know i wasn't missing something
> obvious...

> Kind of on a related topic (related since it's something i'm trying to
> lay out) - is there any support for wildmat-type matching extended to
> the perl hooks?

Regexes are generally much more powerful, so it's easier to just use them,
although that does mean learning two syntaxes.

> I'm thinking of trying to implement a perl hook with a configuration
> array that would hold various wildmats on newsgroups to allow for
> different check functions to be run depending on what groups it's in...

> unless i'm just missing something, it seems that the wildmat is an
> extension on regexps,

No, wildmat is basically modelled after shell wildcards and is a good bit
less powerful than regexes (particularly Perl regexes).

> and it would be nice to have something like that in perl...  i suppose i
> can just set up an associative array holding some patterns and match
> against them in perl

I'd recommend doing it that way.

There's a rough wildmat to regex converter in the same authentication
hook code, although it doesn't fully handle character classes.

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>
Re: docs on filter_art? Mime tools?
#50069
Author: Andrew Gierth
Date: Tue, 23 Jan 2001 12:23
109 lines
4555 bytes
>>>>> "Russ" == Russ Allbery <rra@stanford.edu> writes:

 Russ> There's a rough wildmat to regex converter in the same
 Russ> authentication hook code, although it doesn't fully handle
 Russ> character classes.

this is the best I've come up with so far for wildmat->regex
conversion:

sub wildmat_to_regex
{
    my $w = quotemeta shift;
    $w =~ s{\\([*?]|\[(?:\\\^)?(?:\\\])?[^]]*\\\])}
           {($1 eq '*' ? '.*' :
	     $1 eq '?' ? '.'  :
	     do { my $p = $1; $p =~ s/\\([][^-])/$1/g; $p; })}eg;
    return $w;
}

notes:
  - currently '\' is not special in a wildmat, most converters I've seen
    get this wrong. Likewise, '*' and '?' are not special inside [].
  - this code makes no attempt to detect invalid wildmats, and may behave
    strangely in such cases (but then this is also true of the C code),
    _but_ it shouldn't leak any dangerous constructs through to Perl
    since (, ?, { etc are always escaped.
  - this function doesn't anchor the regexp, the caller must do that, e.g.
    by using qr/^$re$/o to compile the result.

The above only handles single wildmats, not lists of wildmats. Turning
a list of wildmats into a single regexp is a more interesting
challenge, the following code _seems_ to work, but no guarantees:


# wildmat_list_to_regexp
# (C) 2001 Andrew Gierth, andrew@erlenstar.demon.co.uk
# This code is provided "AS IS" and WITHOUT ANY WARRANTY. It may be
# freely distributed in source form only, with or without modification,
# provided this copyright notice and disclaimer are preserved.

# notes:
#  assumes a default acceptance match if the first entry is a negated one.
#  i.e. !foo.* matches everything except foo.*, same as *,!foo.*
#  caller is responsible for splitting the pattern list and providing it
#  to this routine in list form.
#  e.g. wildmat_list_to_regex('foo.*', '!foo.private.*')
#  or wildmat_list_to_regex(split(/,+/,$patlist))
#  The basic idea is to use lookahead negative assertions to exclude
#  those patterns that should not match. The complicated part is dealing
#  with accepting patterns that follow rejecting ones; this requires
#  negative lookahead assertions inside negative lookahead assertions
#  (ow, my brane hurts). The complexity of the resulting regexp thus
#  grows according to the number of sense-reversals in the pattern list.
#  We reverse the order of the list during processing in order to handle
#  this.
#  This function _does_ include the ^ $ anchors in the returned string,
#  because they are necessary for correctness (lots of $ anchors are
#  embedded in the result).
 

sub wildmat_list_to_regex
{
    my @list = @_;
    my @clist;
    for (@list)
    {
	my $neg = s/^!//;
	my $pat = wildmat_to_regex($_);
	if (!@clist || $neg != $clist[0][0])
	{
	    unshift @clist,[ $neg, $pat ];
	}
	else
	{
	    $clist[0][1] .= "|$pat";
	}
    }
    push @clist,[ 0, ".*" ] if !@clist or $clist[-1][0];
    my @accept;
    my @reject;
    for (@clist)
    {
	my $pat = $_->[1];
	if ($_->[0])
	{
	    if (@accept)
	    {
		$pat = "(?!(?:".join('|',@accept).")\$)(?:$pat)";
	    }
	    unshift @reject,$pat;
	}
	else
	{
	    unshift @accept,$pat;
	}
    }

    my $pat = "^";
    $pat .= "(?!(?:".join('|',@reject).")\$)" if @reject;
    $pat .= "(?:".join('|',@accept).")";
    $pat .= "\$";
    return $pat;
}

__END__

-- 
Andrew.
Re: docs on filter_art? Mime tools?
#50074
Author: Mark W Modrall
Date: Tue, 23 Jan 2001 18:08
35 lines
2086 bytes
In article <yl7l3n3zy7.fsf@windlord.stanford.edu>,
Russ Allbery  <rra@stanford.edu> wrote:
>Mark W Modrall <modrall@world.std.com> writes:
>
>> Thanks Russ...  at least it's nice to know i wasn't missing something
>> obvious...
>
>> Kind of on a related topic (related since it's something i'm trying to
>> lay out) - is there any support for wildmat-type matching extended to
>> the perl hooks?
>
>Regexes are generally much more powerful, so it's easier to just use them,
>although that does mean learning two syntaxes.

	when i actually read the wildmat module, i saw what you mean...
I'd assumed that the boolean join logic (ie *,!comp.foobar.*,etc) would
be part of the wildmat package; i saw that it was implemented elsewhere...

>> and it would be nice to have something like that in perl...  i suppose i
>> can just set up an associative array holding some patterns and match
>> against them in perl
>
>I'd recommend doing it that way.

	i've implemented the boolean join stuff with the associative
array in perl, but i have to input the match with $_ (to get 
eval ($pattern) to produce the right result when pattern =
/rec.*/&&!/rec.arts.michael-bolton/)  Not the cheapest thing but
it works...

thanks
-mark


Re: docs on filter_art? Mime tools?
#50075
Author: bill davidsen
Date: Tue, 23 Jan 2001 18:23
15 lines
1852 bytes
In article <yl7l3n3zy7.fsf@windlord.stanford.edu>,
Russ Allbery  <rra@stanford.edu> wrote:

| Regexes are generally much more powerful, so it's easier to just use them,
| although that does mean learning two syntaxes.

  It's slightly worse than that, since there are two regex sets, the one
used by grep and sed, which I think is the regex library, and the one
used in perl, which has more features and is slower for it.

-- 
  bill davidsen <davidsen@tmr.com>  CTO, TMR Associates, Inc
"I am lost. I am out looking for myself. If I should come back before I
return, please ask me to wait."  -seen in a doctor's office
Re: docs on filter_art? Mime tools?
#50078
Author: Russ Allbery
Date: Tue, 23 Jan 2001 19:04
13 lines
1669 bytes
Mark W Modrall <modrall@world.std.com> writes:

> when i actually read the wildmat module, i saw what you mean...  I'd
> assumed that the boolean join logic (ie *,!comp.foobar.*,etc) would be
> part of the wildmat package; i saw that it was implemented elsewhere...

It's part of wildmat in CURRENT, but not in STABLE.  However, regex has
that too (with |).  The one thing that regex doesn't have quite is the !
and @ stuff, which makes wildmat more useful for some things.

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>
Re: docs on filter_art? Mime tools?
#50079
Author: Russ Allbery
Date: Tue, 23 Jan 2001 19:06
17 lines
1846 bytes
bill davidsen <davidsen@tmr.com> writes:
> Russ Allbery  <rra@stanford.edu> wrote:

> | Regexes are generally much more powerful, so it's easier to just use them,
> | although that does mean learning two syntaxes.

> It's slightly worse than that, since there are two regex sets, the one
> used by grep and sed, which I think is the regex library, and the one
> used in perl, which has more features and is slower for it.

I'd be interested to see timings for that, since my experience is that
Perl's regex engine is about as fast or a little faster than most sed
implementations.  (grep I'll buy, but grep doesn't use an NFA.)

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>
Re: docs on filter_art? Mime tools?
#50088
Author: Russ Allbery
Date: Tue, 23 Jan 2001 23:10
12 lines
1469 bytes
Andrew Gierth <andrew@erlenstar.demon.co.uk> writes:

> notes:
>   - currently '\' is not special in a wildmat, most converters I've seen
>     get this wrong. Likewise, '*' and '?' are not special inside [].

I'm not sure quite what you meant here, but '\' is special outside of [];
it always escapes the next character.

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>
Re: docs on filter_art? Mime tools?
#50091
Author: Andrew Gierth
Date: Wed, 24 Jan 2001 00:20
30 lines
2265 bytes
>>>>> "Russ" == Russ Allbery <rra@stanford.edu> writes:

 >> notes:
 >> - currently '\' is not special in a wildmat, most converters I've seen
 >> get this wrong. Likewise, '*' and '?' are not special inside [].

 Russ> I'm not sure quite what you meant here, but '\' is special
 Russ> outside of []; it always escapes the next character.

all this regexp hackery has obviously destroyed my brane; I have no idea
what I actually meant, and was probably confused.

Yes, \ outside [] is an escape. \ inside [] is a literal \ (at least in
deployed implementations. So a more correct version of the code would be
something like:

sub wildmat_to_regex
{
    my $w = quotemeta shift;
    $w =~ s{\\([*?]|\\(\\?.)|\[(?:\\\^)?(?:\\\])?[^]]*\\\])}
           {($1 eq '*' ? '.*' :
	     $1 eq '?' ? '.'  :
	     defined($2) ? $2 :
	     do { my $p = $1; $p =~ s/\\([][^-])/$1/g; $p; })}eg;
    return $w;
}

-- 
Andrew.
Re: docs on filter_art? Mime tools?
#50143
Author: bill davidsen
Date: Thu, 25 Jan 2001 21:23
22 lines
1853 bytes
In article <87lms1hkci.fsf@erlenstar.demon.co.uk>,
Andrew Gierth  <andrew@erlenstar.demon.co.uk> wrote:

| sub wildmat_to_regex
| {
|     my $w = quotemeta shift;
|     $w =~ s{\\([*?]|\\(\\?.)|\[(?:\\\^)?(?:\\\])?[^]]*\\\])}
|            {($1 eq '*' ? '.*' :
| 	     $1 eq '?' ? '.'  :
| 	     defined($2) ? $2 :
| 	     do { my $p = $1; $p =~ s/\\([][^-])/$1/g; $p; })}eg;
|     return $w;
| }

  Practicing for the Obfuscated PERL contest?

-- 
  bill davidsen <davidsen@tmr.com>  CTO, TMR Associates, Inc
Usenet is like a herd of performing elephants: massive, difficult to 
control, awe-inspiring, entertaining, and a source of mind-boggling 
amounts of excrement when you least expect it.
Re: docs on filter_art? Mime tools?
#50144
Author: Andrew Gierth
Date: Thu, 25 Jan 2001 21:49
21 lines
1753 bytes
>>>>> "bill" == bill davidsen <davidsen@tmr.com> writes:

 >> | sub wildmat_to_regex
 >> | {
 >> |     my $w = quotemeta shift;
 >> |     $w =~ s{\\([*?]|\\(\\?.)|\[(?:\\\^)?(?:\\\])?[^]]*\\\])}
 >> |            {($1 eq '*' ? '.*' :
 >> | 	           $1 eq '?' ? '.'  :
 >> | 	           defined($2) ? $2 :
 >> | 	           do { my $p = $1; $p =~ s/\\([][^-])/$1/g; $p; })}eg;
 >> |     return $w;
 >> | }

 bill>   Practicing for the Obfuscated PERL contest?

that's not obfuscated, it's perfectly clear and readable, indeed
obvious :-)

-- 
Andrew.
Re: docs on filter_art? Mime tools?
#50290
Author: bill davidsen
Date: Mon, 29 Jan 2001 19:46
27 lines
2107 bytes
In article <87elxr481c.fsf@erlenstar.demon.co.uk>,
Andrew Gierth  <andrew@erlenstar.demon.co.uk> wrote:
| >>>>> "bill" == bill davidsen <davidsen@tmr.com> writes:
| 
|  >> | sub wildmat_to_regex
|  >> | {
|  >> |     my $w = quotemeta shift;
|  >> |     $w =~ s{\\([*?]|\\(\\?.)|\[(?:\\\^)?(?:\\\])?[^]]*\\\])}
|  >> |            {($1 eq '*' ? '.*' :
|  >> | 	           $1 eq '?' ? '.'  :
|  >> | 	           defined($2) ? $2 :
|  >> | 	           do { my $p = $1; $p =~ s/\\([][^-])/$1/g; $p; })}eg;
|  >> |     return $w;
|  >> | }
| 
|  bill>   Practicing for the Obfuscated PERL contest?
| 
AG> that's not obfuscated, it's perfectly clear and readable, indeed
AG> obvious :-)

  Did you ever write APL? LISP?

-- 
  bill davidsen <davidsen@tmr.com>  CTO, TMR Associates, Inc
"I am lost. I am out looking for myself. If I should come back before I
return, please ask me to wait."  -seen in a doctor's office
Re: docs on filter_art? Mime tools?
#50294
Author: Andrew Gierth
Date: Mon, 29 Jan 2001 20:21
18 lines
1771 bytes
>>>>> "bill" == bill davidsen <davidsen@tmr.com> writes:

 AG> that's not obfuscated, it's perfectly clear and readable, indeed
 AG> obvious :-)

 bill>   Did you ever write APL? LISP?

not APL, though I've read books on the subject and am familiar with
the theory. I've written a small amount of LISP, though recently
nothing more involved than Emacs customisations.

If you want to see what obfuscated code looks like, try www.ioccc.org.
The winners of last year's contest include some truly spectacular
examples of the art, well beyond my capabilities.

-- 
Andrew.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads