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.

120 lines
2.5 KiB

  1. package URI::file::Mac;
  2. require URI::file::Base;
  3. @ISA=qw(URI::file::Base);
  4. use strict;
  5. use URI::Escape qw(uri_unescape);
  6. sub extract_path
  7. {
  8. my $class = shift;
  9. my $path = shift;
  10. my @pre;
  11. if ($path =~ s/^(:+)//) {
  12. if (length($1) == 1) {
  13. @pre = (".") unless length($path);
  14. } else {
  15. @pre = ("..") x (length($1) - 1);
  16. }
  17. } else { #absolute
  18. $pre[0] = "";
  19. }
  20. my $isdir = ($path =~ s/:$//);
  21. $path =~ s,([%/;]),$URI::Escape::escapes{$1},g;
  22. my @path = split(/:/, $path, -1);
  23. for (@path) {
  24. if ($_ eq "." || $_ eq "..") {
  25. $_ = "%2E" x length($_);
  26. }
  27. $_ = ".." unless length($_);
  28. }
  29. push (@path,"") if $isdir;
  30. (join("/", @pre, @path), 1);
  31. }
  32. sub file
  33. {
  34. my $class = shift;
  35. my $uri = shift;
  36. my @path;
  37. my $auth = $uri->authority;
  38. if (defined $auth) {
  39. if (lc($auth) ne "localhost") {
  40. my $u_auth = uri_unescape($auth);
  41. if (!$class->is_this_host($u_auth)) {
  42. # some other host (use it as volume name)
  43. @path = ("", $auth);
  44. # XXX or just return to make it illegal;
  45. }
  46. }
  47. }
  48. my @ps = split("/", $uri->path, -1);
  49. shift @ps if @path;
  50. push(@path, @ps);
  51. my $pre = "";
  52. if (!@path) {
  53. return; # empty path; XXX return ":" instead?
  54. } elsif ($path[0] eq "") {
  55. # absolute
  56. shift(@path);
  57. if (@path == 1) {
  58. return if $path[0] eq ""; # not root directory
  59. push(@path, ""); # volume only, effectively append ":"
  60. }
  61. @ps = @path;
  62. @path = ();
  63. my $part;
  64. for (@ps) { #fix up "." and "..", including interior, in relatives
  65. next if $_ eq ".";
  66. $part = $_ eq ".." ? "" : $_;
  67. push(@path,$part);
  68. }
  69. if ($ps[-1] eq "..") { #if this happens, we need another :
  70. push(@path,"");
  71. }
  72. } else {
  73. $pre = ":";
  74. @ps = @path;
  75. @path = ();
  76. my $part;
  77. for (@ps) { #fix up "." and "..", including interior, in relatives
  78. next if $_ eq ".";
  79. $part = $_ eq ".." ? "" : $_;
  80. push(@path,$part);
  81. }
  82. if ($ps[-1] eq "..") { #if this happens, we need another :
  83. push(@path,"");
  84. }
  85. }
  86. return unless $pre || @path;
  87. for (@path) {
  88. s/;.*//; # get rid of parameters
  89. #return unless length; # XXX
  90. $_ = uri_unescape($_);
  91. return if /\0/;
  92. return if /:/; # Should we?
  93. }
  94. $pre . join(":", @path);
  95. }
  96. sub dir
  97. {
  98. my $class = shift;
  99. my $path = $class->file(@_);
  100. return unless defined $path;
  101. $path .= ":" unless $path =~ /:$/;
  102. $path;
  103. }
  104. 1;