ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Utilities/urlhandler.pm
Revision: 1.3
Committed: Wed Mar 3 17:04:14 1999 UTC (26 years, 2 months ago) by williamc
Content type: text/plain
Branch: MAIN
Changes since 1.2: +5 -0 lines
Log Message:
Updates towardsa release

File Contents

# Content
1 # url handler -> returns the location of the file
2 #
3 # returns file location - or crashes out
4 # can pass a file name for the item to be stored as
5 # if not then stores in a default cache.
6
7 package urlhandler;
8 require 5.001;
9 require Exporter;
10 @ISA = qw(Exporter);
11 @EXPORT = qw(urlhandler);
12
13
14 sub urlhandler($@) {
15 my $origurl=shift;
16 my $filename=shift;
17 my $rest;
18 my $type;
19 my $url;
20 my $version;
21
22 chomp $origurl;
23 # get our version info from the url (after last ??)
24 ( $url, $version) = split /\?\?/, $origurl;
25 if ( $url=~/:/ ) {
26 ($type,$rest) = split /:/, $url;
27 }
28 else {
29 $type='label';
30 $rest=$url.":".$version;
31 }
32
33 my @urltypes = qw(label file cvs);
34 foreach $ty ( @urltypes ) {
35 do { return &$ty($rest, $filename); $supported='yes'; last; }
36 if $type eq $ty;
37 }
38 if ( ! ( $supported=~/yes/ )) {
39 print "urlhandler: Unsupported type $type\n";
40 exit 1;
41 }
42 }
43 sub label {
44 my $label=shift;
45 my $filename=shift;
46 my $returnval="";
47
48 open ( LOOKUP, "$ENV{SCRAM_LOOKUPDB}" )
49 || die "urlhandler: Unable to open DataBase $ENV{SCRAM_LOOKUPDB} $!";
50 while ( <LOOKUP> ) {
51 next if /^#/;
52 if ( $_=~s/^$label\:// ) {
53 $returnval = urlhandler($_,$filename);
54 }
55 }
56 close LOOKUP;
57 return $returnval;
58
59 }
60
61 sub file {
62 use File::Copy;
63 my $urlfile=shift;
64 my $filename=shift;
65 if ( -e "$urlfile" ) {
66 if ( $filename=~/.*/ ) {
67 copy ( $urlfile, $filename ) || return $urlfile;
68 return $filename;
69 }
70 return $urlfile;
71 }
72 else {
73 print "urlhandler: Unable to find file $urlfile : $!\n";
74 exit 1;
75 }
76 }
77
78 sub cvs {
79 print "Coming soon\n";
80 }
81
82 sub http {
83 use LWP;
84
85 }
86
87 sub cachefilename {
88 use File::Basename;
89 use Utilities::AddDir;
90 my $filebase=dirname($rest);
91 $cache="/tmp/williamc/urlhandler$$";
92 adddir($cache);
93 $filename=$cache."/".$filebase;
94 }
95