| 1 | # HTTP URI authority; implements RFC 2396 (primary), 2616 (primary), | ||
| 2 | # 2732 (IPv6 updates) standards. | ||
| 3 | # no 2732 yet | ||
| 4 | # | ||
| 5 | # subclass of HTTP:Part; see that for interface requirements | ||
| 6 | # | ||
| 7 | |||
| 8 | package IDS::DataSource::HTTP::URIAuthority; | ||
| 9 | |||
| 10 | use strict; | ||
| 11 | use warnings; | ||
| 12 | use Carp qw(carp confess); | ||
| 13 | use base qw(IDS::DataSource::HTTP::Part); | ||
| 14 | |||
| 15 | $IDS::DataSource::HTTP::URIAuthority::VERSION = "1.0"; | ||
| 16 | |||
| 17 | sub empty { | ||
| 18 | my $self = shift; | ||
| 19 | undef $self->{"data"}, $self->{"user"}, $self->{"host"}, | ||
| 20 | $self->{"port"}, $self->{"tokens"}; | ||
| 21 | } | ||
| 22 | |||
| 23 | sub parse { | ||
| 24 | my $self = shift; | ||
| 25 | my $authority = $self->{"data"}; # convenience | ||
| 26 | my @tokens; | ||
| 27 | |||
| 28 | $self->mesg(1, *parse{PACKAGE} . "::parse: authority '$authority'"); | ||
| 29 | |||
| 30 | if ($authority =~ m!;:@?/!) { | ||
| 31 | # specifically noted illegal character | ||
| 32 | my $pmsg = *parse{PACKAGE} . "::parse: In " . | ||
| 33 | ${$self->{"params"}}{"source"} . | ||
| 34 | " authority '$authority' contains an illegal char"; | ||
| 35 | $self->warn($pmsg, \@tokens, "!Illegal character in authority"); | ||
| 36 | } | ||
| 37 | |||
| 38 | # <userinfo>@<host>:<port> | ||
| 39 | ### user expr below needs to handle escaped chars | ||
| 40 | my $userpat = qr/[-_.!~*';:&=+\$,()A-Za-z0-9]*/; | ||
| 41 | if ($authority =~ m!^(($userpat)@)?([^:]+)(:(\d+))?!) { | ||
| 42 | my $user = $2; # may be empty | ||
| 43 | my $host = $3; | ||
| 44 | my $port = $5; # may be empty | ||
| 45 | |||
| 46 | # handling and detailed checking of each part now | ||
| 47 | $self->{"user"} = $user; | ||
| 48 | defined($user) and push @tokens, "Userinfo: '$user'"; | ||
| 49 | |||
| 50 | $self->{"host"} = new IDS::DataSource::HTTP::Host($self->{"params"}, $host); | ||
| 51 | push @tokens, $self->{"host"}->tokens; | ||
| 52 | |||
| 53 | if (defined($port)) { | ||
| 54 | $self->{"port"} = $port; | ||
| 55 | push @tokens, "Port: $port"; | ||
| 56 | unless($port =~ /^\d*$/) { | ||
| 57 | my $pmsg = *parse{PACKAGE} . "::parse: In " . | ||
| 58 | ${$self->{"params"}}{"source"} . | ||
| 59 | " port '$port' contains non-digit"; | ||
| 60 | $self->warn($pmsg, \@tokens, "!non-digit in port '$port'"); | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | $self->mesg(2, *parse{PACKAGE} . "::parse: tokens\n ", | ||
| 66 | "\n ", \@tokens); | ||
| 67 | $self->{"tokens"} = \@tokens; | ||
| 68 | } | ||
| 69 | |||
| 70 | # accessor functions not provided by the superclass | ||
| 71 | sub hostname { | ||
| 72 | my $self = shift; | ||
| 73 | return $self->{"host"}; | ||
| 74 | } | ||
| 75 | |||
| 76 | sub port { | ||
| 77 | my $self = shift; | ||
| 78 | return $self->{"port"} || 80; | ||
| 79 | } | ||
| 80 | |||
| 81 | sub userinfo { | ||
| 82 | my $self = shift; | ||
| 83 | return $self->{"user"}; | ||
| 84 | } | ||
| 85 | |||
| 86 | =head1 AUTHOR INFORMATION | ||
| 87 | |||
| 88 | Copyright 2005-2007, Kenneth Ingham. All rights reserved. | ||
| 89 | |||
| 90 | This library is free software; you can redistribute it and/or modify | ||
| 91 | it under the same terms as Perl itself. | ||
| 92 | |||
| 93 | Address bug reports and comments to: ids_test at i-pi.com. When sending | ||
| 94 | bug reports, please provide the versions of IDS::Test.pm, IDS::Algorithm.pm, | ||
| 95 | IDS::DataSource.pm, the version of Perl, and the name and version of the | ||
| 96 | operating system you are using. Since Kenneth is a PhD student, the | ||
| 97 | speed of the reponse depends on how the research is proceeding. | ||
| 98 | |||
| 99 | =head1 BUGS | ||
| 100 | |||
| 101 | Please report them. | ||
| 102 | |||
| 103 | =head1 SEE ALSO | ||
| 104 | |||
| 105 | L<IDS::Algorithm>, L<IDS::DataSource> | ||
| 106 | |||
| 107 | =cut | ||
| 108 | |||
| 109 | 1; |