1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
#
# Courier::Filter::Util
# Utility class for the Courier::Filter framework.
#
# (C) 2003-2008 Julian Mehnle <julian@mehnle.net>
# $Id: Util.pm 210 2008-03-21 19:30:31Z julian $
#
###############################################################################
=head1 NAME
Courier::Filter::Util - Utility class used by the Courier::Filter framework
=cut
package Courier::Filter::Util;
use warnings;
use strict;
use base 'Exporter';
use Error ':try';
use Courier::Error;
use constant TRUE => (0 == 0);
use constant FALSE => not TRUE;
our @EXPORT_OK = qw(
ipv4_address_pattern
ipv6_address_pattern
loopback_address_pattern
);
=head1 SYNOPSIS
use Courier::Filter::Util qw(
ipv4_address_pattern
ipv6_address_pattern
loopback_address_pattern
);
$message->remote_host =~ / ^ (?: ::ffff: )? $(\ipv4_address_pattern} $ /x;
$message->remote_host =~ / ^ $(\ipv6_address_pattern} $ /x;
$message->remote_host =~ / ^ ${\loopback_address_pattern} $ /x;
=head1 DESCRIPTION
B<Courier::Filter::Util> is Courier::Filter's utility class.
=cut
# Implementation:
###############################################################################
=head2 Constants
The following constants are provided:
=over
=item B<ipv4_address_pattern>
A regular expression matching an IPv4 address in "dotted decimal" notation.
=cut
use constant octet_decimal_pattern => qr/ 0*? \d | \d\d | [01]\d\d | 2[0-4]\d | 25[0-5] /x;
use constant ipv4_address_pattern => qr/ ${\octet_decimal_pattern} (?: \. ${\octet_decimal_pattern} ){3} /x;
=item B<ipv6_address_pattern>
A regular expression matching an IPv6 address in full RFC 4291 syntax.
=cut
use constant hexword_pattern => qr/\p{IsXDigit}{1,4}/;
use constant two_hexwords_or_ipv4_address_pattern => qr/
${\hexword_pattern} : ${\hexword_pattern} | ${\ipv4_address_pattern}
/x;
use constant ipv6_address_pattern => qr/
# x:x:x:x:x:x:x:x | x:x:x:x:x:x:n.n.n.n
(?: ${\hexword_pattern} : ){6} ${\two_hexwords_or_ipv4_address_pattern} |
# x::x:x:x:x:x:x | x::x:x:x:x:n.n.n.n
(?: ${\hexword_pattern} : ){1} : (?: ${\hexword_pattern} : ){4} ${\two_hexwords_or_ipv4_address_pattern} |
# x[:x]::x:x:x:x:x | x[:x]::x:x:x:n.n.n.n
(?: ${\hexword_pattern} : ){1,2} : (?: ${\hexword_pattern} : ){3} ${\two_hexwords_or_ipv4_address_pattern} |
# x[:...]::x:x:x:x | x[:...]::x:x:n.n.n.n
(?: ${\hexword_pattern} : ){1,3} : (?: ${\hexword_pattern} : ){2} ${\two_hexwords_or_ipv4_address_pattern} |
# x[:...]::x:x:x | x[:...]::x:n.n.n.n
(?: ${\hexword_pattern} : ){1,4} : (?: ${\hexword_pattern} : ){1} ${\two_hexwords_or_ipv4_address_pattern} |
# x[:...]::x:x | x[:...]::n.n.n.n
(?: ${\hexword_pattern} : ){1,5} : ${\two_hexwords_or_ipv4_address_pattern} |
# x[:...]::x | -
(?: ${\hexword_pattern} : ){1,6} : ${\hexword_pattern} |
# x[:...]:: | -
(?: ${\hexword_pattern} : ){1,7} : |
# ::[...:]x | -
:: (?: ${\hexword_pattern} : ){0,6} ${\hexword_pattern} |
# - | ::[...:]n.n.n.n
:: (?: ${\hexword_pattern} : ){0,5} ${\two_hexwords_or_ipv4_address_pattern} |
# :: | -
::
/x;
=item B<loopback_address_pattern>
A regular expression matching an IPv4 or IPv6 loopback address (C<127.n.n.n>,
C<::ffff:127.n.n.n.n>, C<::1>).
=cut
use constant loopback_address_pattern => qr/ (?: ::ffff: )? 127 (?: \.\d{1,3} ){3} | ::1 /x;
=back
=head1 SEE ALSO
L<Courier::Filter>.
For AVAILABILITY, SUPPORT, and LICENSE information, see
L<Courier::Filter::Overview>.
=head1 AUTHOR
Julian Mehnle <julian@mehnle.net>
=cut
TRUE;
|