]> mj.ucw.cz Git - pciids.git/blobdiff - PciIds/Html/Jump.pm
Keep the current ssl mode in links
[pciids.git] / PciIds / Html / Jump.pm
index 9b650f258d1f84c1cfadb4bcea4b44816a722339..a693d56eac75add0c82b321731ce18747254879b 100644 (file)
@@ -1,3 +1,21 @@
+#      PciIds web database
+#      Copyright (C) 2008 Michal Vaner (vorner@ucw.cz)
+#
+#      This program is free software; you can redistribute it and/or modify
+#      it under the terms of the GNU General Public License as published by
+#      he Free Software Foundation; either version 2 of the License, or
+#      (at your option) any later version.
+#
+#      This program is distributed in the hope that it will be useful,
+#      but WITHOUT ANY WARRANTY; without even the implied warranty of
+#      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#
+#      GNU General Public License for more details.
+#
+#      You should have received a copy of the GNU General Public License
+#      along with this program; if not, write to the Free Software
+#      Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
 package PciIds::Html::Jump;
 use strict;
 use warnings;
@@ -19,10 +37,10 @@ sub jumpWindow( $$ ) {
        print "</form>\n";
 }
 
-sub redirect( $$$ ) {
-       my( $req, $args, $addr ) = @_;
+sub redirect( $$$$ ) {
+       my( $req, $args, $addr, $hasSSL ) = @_;
        my $prefix = ( !defined $args->{'action'} || $args->{'action'} eq '' || $args->{'action'} eq 'list' ) ? 'read' : 'mods';
-       my $url = "http://".$req->hostname()."/$prefix/$addr".buildArgs( $args );
+       my $url = protoName( $hasSSL )."://".$req->hostname()."/$prefix/$addr".buildArgs( $args );
        return HTTPRedirect( $req, $url );
 }
 
@@ -31,8 +49,8 @@ sub itemExists( $$ ) {
        return defined $tables->item( $addr );
 }
 
-sub tryDirect( $$$$ ) {
-       my( $req, $args, $tables, $search ) = @_;
+sub tryDirect( $$$$$ ) {
+       my( $req, $args, $tables, $search, $hasSSL ) = @_;
        my $address = PciIds::Address::new( $req->uri() );
        $search =~ s/:/\//g;
        $search =~ s/ //g;
@@ -40,10 +58,10 @@ sub tryDirect( $$$$ ) {
        $search =~ s/^\//$top\//;
        #Is it absolute address?
        my $saddr = PciIds::Address::new( $search );
-       return redirect( $req, $args, $saddr->get() ) if( defined $saddr && itemExists( $tables, $saddr->get() ) );
+       return redirect( $req, $args, $saddr->get(), $hasSSL ) if( defined $saddr && itemExists( $tables, $saddr->get() ) );
        while( defined $address ) {
                $saddr = PciIds::Address::new( $address->get()."/$search" );
-               return redirect( $req, $args, $saddr->get() ) if( defined $saddr && itemExists( $tables, $saddr->get() ) );
+               return redirect( $req, $args, $saddr->get(), $hasSSL ) if( defined $saddr && itemExists( $tables, $saddr->get() ) );
                $address = $address->parent();
        }
        return undef;
@@ -54,7 +72,7 @@ sub jump( $$$$ ) {
        $args->{'action'} = delete $args->{'origin'};
        my $search = getFormValue( 'where', '' );
        my $idOnly = $search =~ s/^#//;
-       my $direct = tryDirect( $req, $args, $tables, $search );
+       my $direct = tryDirect( $req, $args, $tables, $search, $auth->{'ssl'} );
        return $direct if defined $direct;
        my $address = PciIds::Address::new( $req->uri() );
        unless( $idOnly || length $search < 3 ) {#Try extended search
@@ -71,7 +89,7 @@ sub jump( $$$$ ) {
                        genPath( $req, $address, 1 );
                        print "<h2>Found items</h2>\n";
                        genTableHead( 'found', [ 'ID', 'Name', 'Parent' ], [] );
-                       my $prefix = 'http://'.$req->hostname().'/'.( ( !defined $args->{'action'} || $args->{'action'} eq '' || $args->{'action'} eq 'list' ) ? 'read/' : 'mods/' );
+                       my $prefix = $req->hostname().'/'.( ( !defined $args->{'action'} || $args->{'action'} eq '' || $args->{'action'} eq 'list' ) ? 'read/' : 'mods/' );
                        my $suffix = buildArgs( $args );
                        htmlFormatTable( $result, 3, [], [ sub {
                                my $addr = shift;