From 0f870c6ebde05d01988583267cd83dd0d0f45539 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 3 Oct 2022 17:47:33 +0200 Subject: Remove support for XML HAFAS interfaces --- Build.PL | 2 +- Dockerfile | 4 +- README.md | 2 - bin/hafas-m | 2 - cpanfile | 2 +- lib/Travel/Status/DE/DeutscheBahn.pm | 2 - lib/Travel/Status/DE/HAFAS.pm | 245 --------------------------- scripts/makedeb-docker-helper | 2 +- t/30-invalid-xml.t | 32 ---- t/in/NAHSH.Flensburg.xml | 40 ----- t/in/NASA.Wernigerode Hbf.xml | 18 -- t/in/NVV.Kassel Hauptbahnhof.xml | 67 -------- t/in/RSAG.Rostock Hbf.xml | 98 ----------- "t/in/VBB.Berlin Jannowitzbr\303\274cke.xml" | 75 -------- t/in/VBN.Diepholz.xml | 8 - "t/in/\303\226BB.Wien Praterstern.xml" | 101 ----------- 16 files changed, 5 insertions(+), 695 deletions(-) delete mode 100755 t/30-invalid-xml.t delete mode 100644 t/in/NAHSH.Flensburg.xml delete mode 100644 t/in/NASA.Wernigerode Hbf.xml delete mode 100644 t/in/NVV.Kassel Hauptbahnhof.xml delete mode 100644 t/in/RSAG.Rostock Hbf.xml delete mode 100644 "t/in/VBB.Berlin Jannowitzbr\303\274cke.xml" delete mode 100644 t/in/VBN.Diepholz.xml delete mode 100644 "t/in/\303\226BB.Wien Praterstern.xml" diff --git a/Build.PL b/Build.PL index b5c8a7b..98098ff 100644 --- a/Build.PL +++ b/Build.PL @@ -22,6 +22,7 @@ Module::Build->new( 'Class::Accessor' => '0.16', 'DateTime' => 0, 'DateTime::Format::Strptime' => 0, + 'Digest::MD5' => 0, 'Getopt::Long' => 0, 'JSON' => 0, 'List::MoreUtils' => 0, @@ -29,7 +30,6 @@ Module::Build->new( 'LWP::UserAgent' => 0, 'LWP::Protocol::https' => 0, 'POSIX' => 0, - 'XML::LibXML' => '1.70', }, script_files => 'bin/', sign => 1, diff --git a/Dockerfile b/Dockerfile index 0313f62..334951d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,12 +10,12 @@ ARG DEBIAN_FRONTEND=noninteractive ARG APT_LISTCHANGES_FRONTEND=none RUN apt-get update \ - && apt-get -y --no-install-recommends install ca-certificates curl gcc libc6-dev libssl1.1 libssl-dev libxml2 libxml2-dev make zlib1g-dev \ + && apt-get -y --no-install-recommends install ca-certificates curl gcc libc6-dev libssl1.1 libssl-dev make zlib1g-dev \ && cpanm -n --no-man-pages --installdeps . \ && perl Build.PL \ && perl Build \ && rm -rf ~/.cpanm \ - && apt-get -y purge curl gcc libc6-dev libssl-dev libxml2-dev make zlib1g-dev \ + && apt-get -y purge curl gcc libc6-dev libssl-dev make zlib1g-dev \ && apt-get -y autoremove \ && apt-get -y clean \ && rm -rf /var/cache/apt/* /var/lib/apt/lists/* diff --git a/README.md b/README.md index c4551ef..f8e86c8 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ interfaces, and can also be pointed to URLs not listed here. * [Nahverkehrsverbund Schleswig-Holstein](https://nah.sh.hafas.de/bin/stboard.exe) * [Nahverkehrsservice Sachsen-Anhalt](https://reiseauskunft.insa.de/bin/stboard.exe) * [Nordhessischer VerkehrsVerbund](https://auskunft.nvv.de/auskunft/bin/jp/stboard.exe) -* [Rostocker Straßenbahn AG](https://fahrplan.rsag-online.de/hafas/stboard.exe) * [Verkehrsverbund Berlin-Brandenburg](https://fahrinfo.vbb.de/bin/stboard.exe) * [Verkehrsverbund Bremen/Niedersachsen](https://fahrplaner.vbn.de/hafas/stboard.exe) * [Österreichische Bundesbahnen](https://fahrplan.oebb.at/bin/stboard.exe) @@ -78,7 +77,6 @@ pkg-config and a C compiler) installed. You will also need the following libraries with development headers: * libssl -* libxml2 * zlib Now, use a tool of your choice to install the module. Minimum working example: diff --git a/bin/hafas-m b/bin/hafas-m index d4590f6..f0e0299 100755 --- a/bin/hafas-m +++ b/bin/hafas-m @@ -350,8 +350,6 @@ None. =item * LWP::UserAgent(3pm) -=item * XML::LibXML(3pm) - =back =head1 BUGS AND LIMITATIONS diff --git a/cpanfile b/cpanfile index d82ea81..55ed329 100644 --- a/cpanfile +++ b/cpanfile @@ -1,6 +1,7 @@ requires 'Class::Accessor'; requires 'DateTime'; requires 'DateTime::Format::Strptime'; +requires 'Digest::MD5'; requires 'Getopt::Long'; requires 'JSON'; requires 'List::MoreUtils'; @@ -8,7 +9,6 @@ requires 'List::Util'; requires 'LWP::UserAgent'; requires 'LWP::Protocol::https'; requires 'POSIX'; -requires 'XML::LibXML'; on test => sub { requires 'File::Slurp'; diff --git a/lib/Travel/Status/DE/DeutscheBahn.pm b/lib/Travel/Status/DE/DeutscheBahn.pm index a55ccdd..5235dcb 100644 --- a/lib/Travel/Status/DE/DeutscheBahn.pm +++ b/lib/Travel/Status/DE/DeutscheBahn.pm @@ -91,8 +91,6 @@ None. =item * Travel::Status::DE::HAFAS(3pm) -=item * XML::LibXML(3pm) - =back =head1 BUGS AND LIMITATIONS diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm index e04f6a5..2a2b3f4 100644 --- a/lib/Travel/Status/DE/HAFAS.pm +++ b/lib/Travel/Status/DE/HAFAS.pm @@ -19,7 +19,6 @@ use POSIX qw(strftime); use Travel::Status::DE::HAFAS::Message; use Travel::Status::DE::HAFAS::Result; use Travel::Status::DE::HAFAS::StopFinder; -use XML::LibXML; our $VERSION = '3.01'; @@ -322,145 +321,6 @@ sub new_mgate { return $self; } -sub new_legacy { - my ( $self, %conf ) = @_; - - my $now = $self->{now}; - my $date = ( $conf{datetime} // $now )->strftime('%d.%m.%Y'); - my $time = ( $conf{datetime} // $now )->strftime('%H:%M'); - my $mode = $conf{arrivals} ? 'arr' : 'dep'; - my $lang = 'd'; - my $service = $conf{service}; - - $self->{post} = { - input => $conf{station}, - date => $date, - time => $time, - start => 'yes', # value doesn't matter, just needs to be set - boardType => $mode, - L => 'vs_java3', - }; - - $self->set_productfilter; - - my $url = ( $conf{url} // $hafas_instance{$service}{url} ) . "/${lang}n"; - - if ( $conf{xml} ) { - - # used for testing - $self->{raw_xml} = $conf{xml}; - } - else { - if ( $self->{developer_mode} ) { - say "requesting from $url"; - } - my $reply = $self->{ua}->post( $url, $self->{post} ); - - if ( $reply->is_error ) { - $self->{errstr} = $reply->status_line; - return $self; - } - - $self->{raw_xml} = $reply->content; - } - - # the interface often does not return valid XML (but it's close!) - if ( substr( $self->{raw_xml}, 0, 5 ) ne '{raw_xml} - = '' - . $self->{raw_xml} - . ''; - } - - if ( defined $service and $service =~ m{ ^ VBB | NVV $ }x ) { - - # Returns invalid XML with tags inside HIMMessage's lead attribute. - # Fix this. - $self->{raw_xml} - =~ s{ lead = " \K ( [^"]+ ) }{ $1 =~ s{ < [^>]+ > }{}grx }egx; - } - - # TODO the DB backend also retuns invalid XML (similar to above, but with - # errors in delay="...") when setting the language to dutch/italian. - # No, I don't know why. - - eval { $self->{tree} = XML::LibXML->load_xml( string => $self->{raw_xml} ) }; - - if ( my $err = $@ ) { - if ( $self->{developer_mode} ) { - say $self->{raw_xml}; - } - $self->{errstr} = "Backend returned invalid XML: $err"; - return $self; - } - - if ( $self->{developer_mode} ) { - say $self->{tree}->toString(1); - } - - $self->check_input_error; - $self->prepare_results; - return $self; -} - -sub set_productfilter { - my ($self) = @_; - - my $service = $self->{active_service}; - my $mot_default = '1'; - - if ( not $service or not exists $hafas_instance{$service}{productbits} ) { - return; - } - - my %mot_pos; - for my $i ( 0 .. $#{ $hafas_instance{$service}{productbits} } ) { - $mot_pos{ $hafas_instance{$service}{productbits}[$i] } = $i; - } - - if ( $self->{exclusive_mots} and @{ $self->{exclusive_mots} } ) { - $mot_default = '0'; - } - - $self->{post}{productsFilter} - = $mot_default x ( scalar @{ $hafas_instance{$service}{productbits} } ); - - if ( $self->{exclusive_mots} and @{ $self->{exclusive_mots} } ) { - for my $mot ( @{ $self->{exclusive_mots} } ) { - if ( exists $mot_pos{$mot} ) { - substr( $self->{post}{productsFilter}, $mot_pos{$mot}, 1, '1' ); - } - } - } - - if ( $self->{excluded_mots} and @{ $self->{excluded_mots} } ) { - for my $mot ( @{ $self->{excluded_mots} } ) { - if ( exists $mot_pos{$mot} ) { - substr( $self->{post}{productsFilter}, $mot_pos{$mot}, 1, '0' ); - } - } - } - - return; -} - -sub check_input_error { - my ($self) = @_; - - my $xp_err = XML::LibXML::XPathExpression->new('//Err'); - my $err = ( $self->{tree}->findnodes($xp_err) )[0]; - - if ($err) { - $self->{errstr} - = $err->getAttribute('text') - . ' (code ' - . $err->getAttribute('code') . ')'; - $self->{errcode} = $err->getAttribute('code'); - } - - return $self; -} - sub check_mgate { my ($self) = @_; @@ -559,114 +419,11 @@ sub add_message { return $message; } -sub add_message_node { - my ( $self, $node ) = @_; - - my $header = $node->getAttribute('header'); - my $lead = $node->getAttribute('lead'); - - for my $message ( @{ $self->{messages} } ) { - if ( $header eq $message->{header} and $lead eq $message->{lead} ) { - $message->{ref_count}++; - return $message; - } - } - my $message = Travel::Status::DE::HAFAS::Message->new( - header => $header, - lead => $lead, - ref_count => 1, - ); - push( @{ $self->{messages} }, $message ); - return $message; -} - sub messages { my ($self) = @_; return @{ $self->{messages} }; } -sub prepare_results { - my ($self) = @_; - my $mode = $self->{post}->{boardType}; - - my $xp_element = XML::LibXML::XPathExpression->new('//Journey'); - my $xp_msg = XML::LibXML::XPathExpression->new('./HIMMessage'); - - if ( not defined $self->{tree} ) { - return; - } - - $self->{results} = []; - - $self->{strptime_obj} //= DateTime::Format::Strptime->new( - pattern => '%d.%m.%YT%H:%M', - time_zone => 'Europe/Berlin', - ); - - for my $tr ( @{ $self->{tree}->findnodes($xp_element) } ) { - - my @message_nodes = $tr->findnodes($xp_msg); - my $train = $tr->getAttribute('prod'); - my $time = $tr->getAttribute('fpTime'); - my $date = $tr->getAttribute('fpDate'); - my $dest = $tr->getAttribute('targetLoc'); - my $platform = $tr->getAttribute('platform'); - my $new_platform = $tr->getAttribute('newpl'); - my $delay = $tr->getAttribute('delay'); - my $e_delay = $tr->getAttribute('e_delay'); - my $info = $tr->getAttribute('delayReason'); - my $operator = $tr->getAttribute('operator'); - my @messages; - - if ( not( $time and $dest ) ) { - next; - } - - for my $n (@message_nodes) { - push( @messages, $self->add_message_node($n) ); - } - - # Some backends report dd.mm.yy, some report dd.mm.yyyy - # -> map all dates to dd.mm.yyyy - if ( length($date) == 8 ) { - substr( $date, 6, 0, '20' ); - } - - # TODO the first charactor of delayReason is special: - # " " -> no additional data, rest (if any) is delay reason - # else -> first word is not a delay reason but additional data, - # for instance "Zusatzfahrt/Ersatzfahrt" for a replacement train - if ( defined $info and $info eq q{ } ) { - $info = undef; - } - elsif ( defined $info and substr( $info, 0, 1 ) eq q{ } ) { - substr( $info, 0, 1, q{} ); - } - - $train =~ s{#.*$}{}; - - my $datetime = $self->{strptime_obj}->parse_datetime("${date}T${time}"); - - push( - @{ $self->{results} }, - Travel::Status::DE::HAFAS::Result->new( - sched_datetime => $datetime, - datetime_now => $self->{now}, - raw_delay => $delay, - raw_e_delay => $e_delay, - messages => \@messages, - train => $train, - operator => $operator, - route_end => $dest, - platform => $platform, - new_platform => $new_platform, - info => $info, - ) - ); - } - return $self; -} - sub parse_mgate { my ($self) = @_; @@ -973,8 +730,6 @@ None. =item * LWP::UserAgent(3pm) -=item * XML::LibXML(3pm) - =back =head1 BUGS AND LIMITATIONS diff --git a/scripts/makedeb-docker-helper b/scripts/makedeb-docker-helper index da859eb..3da3ea6 100755 --- a/scripts/makedeb-docker-helper +++ b/scripts/makedeb-docker-helper @@ -11,7 +11,7 @@ apt-get -y install \ libclass-accessor-perl libdatetime-perl libdatetime-format-strptime-perl \ liblwp-protocol-https-perl libjson-perl libjson-xs-perl \ liblist-moreutils-perl \ - libwww-perl libxml-libxml-perl \ + libwww-perl \ libtest-compile-perl libtest-pod-perl \ libtest-simple-perl diff --git a/t/30-invalid-xml.t b/t/30-invalid-xml.t deleted file mode 100755 index f8f7d58..0000000 --- a/t/30-invalid-xml.t +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use 5.020; - -use utf8; - -use File::Slurp qw(read_file); -use Test::More tests => 2; - -use Travel::Status::DE::HAFAS; - -my $xml = 'lol'; - -my $status = Travel::Status::DE::HAFAS->new( - service => 'NASA', - station => 'Berlin Jannowitzbrücke', - xml => $xml -); - -is( scalar $status->results, - 0, 'no results on valid XML with invalid HAFAS data' ); - -$xml = 'lol<'; - -$status = Travel::Status::DE::HAFAS->new( - service => 'NASA', - station => 'Berlin Jannowitzbrücke', - xml => $xml -); - -is( scalar $status->results, 0, 'no results on invalid XML' ); diff --git a/t/in/NAHSH.Flensburg.xml b/t/in/NAHSH.Flensburg.xml deleted file mode 100644 index aeaf89b..0000000 --- a/t/in/NAHSH.Flensburg.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/t/in/NASA.Wernigerode Hbf.xml b/t/in/NASA.Wernigerode Hbf.xml deleted file mode 100644 index 0803d15..0000000 --- a/t/in/NASA.Wernigerode Hbf.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/t/in/NVV.Kassel Hauptbahnhof.xml b/t/in/NVV.Kassel Hauptbahnhof.xml deleted file mode 100644 index 4c5a1d8..0000000 --- a/t/in/NVV.Kassel Hauptbahnhof.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/t/in/RSAG.Rostock Hbf.xml b/t/in/RSAG.Rostock Hbf.xml deleted file mode 100644 index ae03be1..0000000 --- a/t/in/RSAG.Rostock Hbf.xml +++ /dev/null @@ -1,98 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git "a/t/in/VBB.Berlin Jannowitzbr\303\274cke.xml" "b/t/in/VBB.Berlin Jannowitzbr\303\274cke.xml" deleted file mode 100644 index 698d0a4..0000000 --- "a/t/in/VBB.Berlin Jannowitzbr\303\274cke.xml" +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/t/in/VBN.Diepholz.xml b/t/in/VBN.Diepholz.xml deleted file mode 100644 index c431830..0000000 --- a/t/in/VBN.Diepholz.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git "a/t/in/\303\226BB.Wien Praterstern.xml" "b/t/in/\303\226BB.Wien Praterstern.xml" deleted file mode 100644 index b9a455e..0000000 --- "a/t/in/\303\226BB.Wien Praterstern.xml" +++ /dev/null @@ -1,101 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- cgit v1.2.3