Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.4 KiB

  1. package URI::file::Win32;
  2. require URI::file::Base;
  3. @ISA=qw(URI::file::Base);
  4. use strict;
  5. use URI::Escape qw(uri_unescape);
  6. sub extract_authority
  7. {
  8. my $class = shift;
  9. return $1 if $_[0] =~ s,^\\\\([^\\]+),,; # UNC
  10. return $1 if $_[0] =~ s,^//([^/]+),,; # UNC too?
  11. if ($_[0] =~ s,^([a-zA-Z]:),,) {
  12. my $auth = $1;
  13. $auth .= "relative" if $_[0] !~ m,^[\\/],;
  14. return $auth;
  15. }
  16. return;
  17. }
  18. sub extract_path
  19. {
  20. my($class, $path) = @_;
  21. $path =~ s,\\,/,g;
  22. $path =~ s,//+,/,g;
  23. $path =~ s,(/\.)+/,/,g;
  24. $path;
  25. }
  26. sub file
  27. {
  28. my $class = shift;
  29. my $uri = shift;
  30. my $auth = $uri->authority;
  31. my $rel; # is filename relative to drive specified in authority
  32. if (defined $auth) {
  33. $auth = uri_unescape($auth);
  34. if ($auth =~ /^([a-zA-Z])[:|](relative)?/) {
  35. $auth = uc($1) . ":";
  36. $rel++ if $2;
  37. } elsif (lc($auth) eq "localhost") {
  38. $auth = "";
  39. } elsif (length $auth) {
  40. $auth = "\\\\" . $auth; # UNC
  41. }
  42. } else {
  43. $auth = "";
  44. }
  45. my @path = $uri->path_segments;
  46. for (@path) {
  47. return if /\0/;
  48. return if /\//;
  49. #return if /\\/; # URLs with "\" is not uncommon
  50. }
  51. return unless $class->fix_path(@path);
  52. my $path = join("\\", @path);
  53. $path =~ s/^\\// if $rel;
  54. $path = $auth . $path;
  55. $path =~ s,^\\([a-zA-Z])[:|],\u$1:,;
  56. $path;
  57. }
  58. sub fix_path { 1; }
  59. 1;