| 1 | # HTTP Expectation; Section 14.20 of RFC 2616 | ||
| 2 | # | ||
| 3 | # subclass of HTTP:Part; see that for interface requirements | ||
| 4 | # | ||
| 5 | |||
| 6 | package IDS::DataSource::HTTP::Expectation; | ||
| 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::Expectation::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 | |||
| 29 | if ($data eq "100-continue") { | ||
| 30 | push @tokens, "Expectation: 100-continue"; | ||
| 31 | } elsif ($data =~ /^($tokenpat)(=("$tokenpat"|$tokenpat))?(.*)$/) { | ||
| 32 | push @tokens, "Expectation token: $1"; | ||
| 33 | push @tokens, "Expectation $1 value: $3" if defined($3); | ||
| 34 | if ($4) { | ||
| 35 | my $params = $4; | ||
| 36 | $params = s/^;\s*//; | ||
| 37 | # params are ; separated. | ||
| 38 | for my $param (split /;\s*/, $params) { | ||
| 39 | if ($param =~ /^($tokenpat)(=("$tokenpat"|$tokenpat))?$/) { | ||
| 40 | push @tokens, "Expectation parameter: $1"; | ||
| 41 | push @tokens, "Expectation $1 parameter value: $3" | ||
| 42 | if defined($3); | ||
| 43 | } else { | ||
| 44 | my $pmsg = *parse{PACKAGE} . "::parse: In " . | ||
| 45 | ${$self->{"params"}}{"source"} . | ||
| 46 | " invalid expect param '$param'\n"; | ||
| 47 | $self->warn($pmsg, \@tokens, "!Invalid expect param"); | ||
| 48 | } | ||
| 49 | } | ||
| 50 | } | ||
| 51 | } else { | ||
| 52 | my $pmsg = *parse{PACKAGE} . "::parse: In " . | ||
| 53 | ${$self->{"params"}}{"source"} . | ||
| 54 | " invalid expectation '$data'\n"; | ||
| 55 | $self->warn($pmsg, \@tokens, "!Invalid expectation"); | ||
| 56 | } | ||
| 57 | |||
| 58 | $self->mesg(2, *parse{PACKAGE} . "::parse: tokens\n ", | ||
| 59 | "\n ", \@tokens); | ||
| 60 | $self->{"tokens"} = \@tokens; | ||
| 61 | } | ||
| 62 | |||
| 63 | # accessor functions not provided by the superclass | ||
| 64 | |||
| 65 | =head1 AUTHOR INFORMATION | ||
| 66 | |||
| 67 | Copyright 2005-2007, Kenneth Ingham. All rights reserved. | ||
| 68 | |||
| 69 | This library is free software; you can redistribute it and/or modify | ||
| 70 | it under the same terms as Perl itself. | ||
| 71 | |||
| 72 | Address bug reports and comments to: ids_test at i-pi.com. When sending | ||
| 73 | bug reports, please provide the versions of IDS::Test.pm, IDS::Algorithm.pm, | ||
| 74 | IDS::DataSource.pm, the version of Perl, and the name and version of the | ||
| 75 | operating system you are using. Since Kenneth is a PhD student, the | ||
| 76 | speed of the reponse depends on how the research is proceeding. | ||
| 77 | |||
| 78 | =head1 BUGS | ||
| 79 | |||
| 80 | Please report them. | ||
| 81 | |||
| 82 | =head1 SEE ALSO | ||
| 83 | |||
| 84 | L<IDS::Algorithm>, L<IDS::DataSource> | ||
| 85 | |||
| 86 | =cut | ||
| 87 | |||
| 88 | 1; |