| 1 | # HTTP Via; Section 14.45 RFC 2616. | ||
| 2 | # | ||
| 3 | # subclass of HTTP:Part; see that for interface requirements | ||
| 4 | # | ||
| 5 | |||
| 6 | package IDS::DataSource::HTTP::Via; | ||
| 7 | |||
| 8 | use strict; | ||
| 9 | use warnings; | ||
| 10 | use Carp qw(carp confess); | ||
| 11 | use base qw(IDS::DataSource::HTTP::Part); | ||
| 12 | |||
| 13 | $IDS::DataSource::HTTP::Via::VERSION = "1.0"; | ||
| 14 | |||
| 15 | sub empty { | ||
| 16 | my $self = shift; | ||
| 17 | undef $self->{"data"}, $self->{"tokens"}; | ||
| 18 | } | ||
| 19 | |||
| 20 | sub parse { | ||
| 21 | my $self = shift; | ||
| 22 | my $data = $self->{"data"}; # convenience | ||
| 23 | my @tokens; | ||
| 24 | |||
| 25 | $self->mesg(1, *parse{PACKAGE} . "::parse: data '$data'"); | ||
| 26 | |||
| 27 | my $tokenpat = qr/[-a-zA-Z0-9!#\$%^&*_+|.~]+/; # missing '"` (3 chars) | ||
| 28 | my $viapat = qr!(($tokenpat)/)?($tokenpat)\s+([0-9A-Za-z.:]+)([^,]*)?(,\s*)?!; | ||
| 29 | while ($data =~ m!$viapat!g) { | ||
| 30 | my ($name, $version, $received, $comment) = ($2, $3, $4, $5); | ||
| 31 | if (defined($name) && $name) { | ||
| 32 | push @tokens, "Via protocol: $name"; | ||
| 33 | } else { | ||
| 34 | push @tokens, "Via protocol implied: HTTP"; | ||
| 35 | } | ||
| 36 | push @tokens, "Via protocol version: $version"; | ||
| 37 | |||
| 38 | # abusing the protocol slghtly, since an authority can also | ||
| 39 | # include user info. | ||
| 40 | my $ua = new IDS::DataSource::HTTP::URIAuthority($self->{"params"}, $received); | ||
| 41 | push @tokens, $ua->tokens; | ||
| 42 | if (defined($comment) && $comment) { | ||
| 43 | push @tokens, "Via comment: $comment"; | ||
| 44 | } | ||
| 45 | } | ||
| 46 | if ($data !~ m!$viapat!g) { | ||
| 47 | my $pmsg = *parse{PACKAGE} . "::parse: In " . | ||
| 48 | ${$self->{"params"}}{"source"} . | ||
| 49 | " invalid via '$data'\n"; | ||
| 50 | $self->warn($pmsg, \@tokens, "!Invalid via value"); | ||
| 51 | } | ||
| 52 | |||
| 53 | $self->mesg(2, *parse{PACKAGE} . "::parse: tokens\n ", | ||
| 54 | "\n ", \@tokens); | ||
| 55 | $self->{"tokens"} = \@tokens; | ||
| 56 | } | ||
| 57 | |||
| 58 | # accessor functions not provided by the superclass | ||
| 59 | |||
| 60 | =head1 AUTHOR INFORMATION | ||
| 61 | |||
| 62 | Copyright 2005-2007, Kenneth Ingham. All rights reserved. | ||
| 63 | |||
| 64 | This library is free software; you can redistribute it and/or modify | ||
| 65 | it under the same terms as Perl itself. | ||
| 66 | |||
| 67 | Address bug reports and comments to: ids_test at i-pi.com. When sending | ||
| 68 | bug reports, please provide the versions of IDS::Test.pm, IDS::Algorithm.pm, | ||
| 69 | IDS::DataSource.pm, the version of Perl, and the name and version of the | ||
| 70 | operating system you are using. Since Kenneth is a PhD student, the | ||
| 71 | speed of the reponse depends on how the research is proceeding. | ||
| 72 | |||
| 73 | =head1 BUGS | ||
| 74 | |||
| 75 | Please report them. | ||
| 76 | |||
| 77 | =head1 SEE ALSO | ||
| 78 | |||
| 79 | L<IDS::Algorithm>, L<IDS::DataSource> | ||
| 80 | |||
| 81 | =cut | ||
| 82 | |||
| 83 | 1; |