From 468bc65cca5af51a05d6a7d665d82a8c1e946cb7 Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Sat, 30 Aug 2008 20:42:52 +0200 Subject: [PATCH] Check a sub-system vendor exists --- PciIds/Address/Base.pm | 4 ++++ PciIds/Address/Pci.pm | 8 +++++++- PciIds/DBQ.pm | 5 ++++- PciIds/Html/Changes.pm | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/PciIds/Address/Base.pm b/PciIds/Address/Base.pm index 1ec3cb8..ad5f6f8 100644 --- a/PciIds/Address/Base.pm +++ b/PciIds/Address/Base.pm @@ -49,4 +49,8 @@ sub helpName( $ ) { return undef; } +sub addressDeps( $ ) { + return []; +} + 1; diff --git a/PciIds/Address/Pci.pm b/PciIds/Address/Pci.pm index c9b3a16..bf53d7a 100644 --- a/PciIds/Address/Pci.pm +++ b/PciIds/Address/Pci.pm @@ -18,7 +18,7 @@ sub pretty( $ ) { s/([0-9a-f]{4})([0-9a-f]{4})/$1 $2/g; my $prefix = ''; if( /:.*:/ ) { - $prefix = 'Subsystem'; + $prefix = 'Sub-system'; } elsif( /:/ ) { $prefix = 'Device'; } else { @@ -64,4 +64,10 @@ sub helpName( $ ) { return 'pci'; } +sub addressDeps( $ ) { + my( $addr ) = ( shift->get() =~ /^PC\/....\/....\/(....)/ ); + return [] unless defined $addr; + return [ [ PciIds::Address::new( "PC/$addr" ), "Sub-system vendor $addr does not exist" ] ]; +} + 1; diff --git a/PciIds/DBQ.pm b/PciIds/DBQ.pm index b671ea2..e3932f1 100644 --- a/PciIds/DBQ.pm +++ b/PciIds/DBQ.pm @@ -184,11 +184,14 @@ sub history( $$ ) { sub submitItem( $$$ ) { my( $self, $data, $auth ) = @_; my( $addr ) = ( $data->{'address'} ); + foreach( @{$addr->addressDeps()} ) { + my( $dep, $error ) = @{$_}; + return ( $error, undef ) unless defined $self->item( $dep->get(), 0 ); + } return( 'exists', undef ) if( defined( $self->item( $addr->get(), 0 ) ) ); eval { $self->command( 'newitem', [ $addr->get(), $addr->parent()->get() ] ); $self->command( 'newhistory', [ $addr->get(), $auth->{'authid'}, $data->{'discussion'}, $data->{'name'}, $data->{'note'} ] ); - }; if( $@ ) { $self->rollback(); diff --git a/PciIds/Html/Changes.pm b/PciIds/Html/Changes.pm index c03af9e..bd721ea 100644 --- a/PciIds/Html/Changes.pm +++ b/PciIds/Html/Changes.pm @@ -72,7 +72,7 @@ sub newItemSubmit( $$$$ ) { genHtmlTail(); return OK; } elsif( $result ) { - die "Failed to submit new item: $result\n"; + return genNewItemForm( $req, $args, $auth, $tables, $result, $data ); } notify( $tables, $data->{'address'}->get(), $comName, 2, 0 ); tulog( $auth->{'authid'}, "Item created ".$data->{'address'}->get()." ".logEscape( $data->{'name'} )." ".logEscape( $data->{'note'} )." ".logEscape( $data->{'discussion'} )." $comName" ); -- 2.39.5