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.

304 lines
5.7 KiB

  1. package URI::URL;
  2. require URI::WithBase;
  3. @ISA=qw(URI::WithBase);
  4. use strict;
  5. use vars qw(@EXPORT $VERSION);
  6. $VERSION = "5.02";
  7. # Provide as much as possible of the old URI::URL interface for backwards
  8. # compatibility...
  9. require Exporter;
  10. *import = \&Exporter::import;
  11. @EXPORT = qw(url);
  12. # Easy to use constructor
  13. sub url ($;$) { URI::URL->new(@_); }
  14. use URI::Escape qw(uri_unescape);
  15. sub new
  16. {
  17. my $class = shift;
  18. my $self = $class->SUPER::new(@_);
  19. $self->[0] = $self->[0]->canonical;
  20. $self;
  21. }
  22. sub newlocal
  23. {
  24. my $class = shift;
  25. require URI::file;
  26. bless [URI::file->new_abs(shift)], $class;
  27. }
  28. {package URI::_foreign;
  29. sub _init # hope it is not defined
  30. {
  31. my $class = shift;
  32. die "Unknown URI::URL scheme $_[1]:" if $URI::URL::STRICT;
  33. $class->SUPER::_init(@_);
  34. }
  35. }
  36. sub strict
  37. {
  38. my $old = $URI::URL::STRICT;
  39. $URI::URL::STRICT = shift if @_;
  40. $old;
  41. }
  42. sub print_on
  43. {
  44. my $self = shift;
  45. require Data::Dumper;
  46. print STDERR Data::Dumper::Dumper($self);
  47. }
  48. sub _try
  49. {
  50. my $self = shift;
  51. my $method = shift;
  52. scalar(eval { $self->$method(@_) });
  53. }
  54. sub crack
  55. {
  56. # should be overridden by subclasses
  57. my $self = shift;
  58. (scalar($self->scheme),
  59. $self->_try("user"),
  60. $self->_try("password"),
  61. $self->_try("host"),
  62. $self->_try("port"),
  63. $self->_try("path"),
  64. $self->_try("params"),
  65. $self->_try("query"),
  66. scalar($self->fragment),
  67. )
  68. }
  69. sub full_path
  70. {
  71. my $self = shift;
  72. my $path = $self->path_query;
  73. $path = "/" unless length $path;
  74. $path;
  75. }
  76. sub netloc
  77. {
  78. shift->authority(@_);
  79. }
  80. sub epath
  81. {
  82. my $path = shift->SUPER::path(@_);
  83. $path =~ s/;.*//;
  84. $path;
  85. }
  86. sub eparams
  87. {
  88. my $self = shift;
  89. my @p = $self->path_segments;
  90. return unless ref($p[-1]);
  91. @p = @{$p[-1]};
  92. shift @p;
  93. join(";", @p);
  94. }
  95. sub params { shift->eparams(@_); }
  96. sub path {
  97. my $self = shift;
  98. my $old = $self->epath(@_);
  99. return unless defined wantarray;
  100. return '/' if !defined($old) || !length($old);
  101. Carp::croak("Path components contain '/' (you must call epath)")
  102. if $old =~ /%2[fF]/ and !@_;
  103. $old = "/$old" if $old !~ m|^/| && defined $self->netloc;
  104. return uri_unescape($old);
  105. }
  106. sub path_components {
  107. shift->path_segments(@_);
  108. }
  109. sub query {
  110. my $self = shift;
  111. my $old = $self->equery(@_);
  112. if (defined(wantarray) && defined($old)) {
  113. if ($old =~ /%(?:26|2[bB]|3[dD])/) { # contains escaped '=' '&' or '+'
  114. my $mess;
  115. for ($old) {
  116. $mess = "Query contains both '+' and '%2B'"
  117. if /\+/ && /%2[bB]/;
  118. $mess = "Form query contains escaped '=' or '&'"
  119. if /=/ && /%(?:3[dD]|26)/;
  120. }
  121. if ($mess) {
  122. Carp::croak("$mess (you must call equery)");
  123. }
  124. }
  125. # Now it should be safe to unescape the string without loosing
  126. # information
  127. return uri_unescape($old);
  128. }
  129. undef;
  130. }
  131. sub abs
  132. {
  133. my $self = shift;
  134. my $base = shift;
  135. my $allow_scheme = shift;
  136. $allow_scheme = $URI::URL::ABS_ALLOW_RELATIVE_SCHEME
  137. unless defined $allow_scheme;
  138. local $URI::ABS_ALLOW_RELATIVE_SCHEME = $allow_scheme;
  139. local $URI::ABS_REMOTE_LEADING_DOTS = $URI::URL::ABS_REMOTE_LEADING_DOTS;
  140. $self->SUPER::abs($base);
  141. }
  142. sub frag { shift->fragment(@_); }
  143. sub keywords { shift->query_keywords(@_); }
  144. # file:
  145. sub local_path { shift->file; }
  146. sub unix_path { shift->file("unix"); }
  147. sub dos_path { shift->file("dos"); }
  148. sub mac_path { shift->file("mac"); }
  149. sub vms_path { shift->file("vms"); }
  150. # mailto:
  151. sub address { shift->to(@_); }
  152. sub encoded822addr { shift->to(@_); }
  153. sub URI::mailto::authority { shift->to(@_); } # make 'netloc' method work
  154. # news:
  155. sub groupart { shift->_group(@_); }
  156. sub article { shift->message(@_); }
  157. 1;
  158. __END__
  159. =head1 NAME
  160. URI::URL - Uniform Resource Locators
  161. =head1 SYNOPSIS
  162. $u1 = URI::URL->new($str, $base);
  163. $u2 = $u1->abs;
  164. =head1 DESCRIPTION
  165. This module is provided for backwards compatibility with modules that
  166. depend on the interface provided by the C<URI::URL> class that used to
  167. be distributed with the libwww-perl library.
  168. The following differences compared to the C<URI> class interface exist:
  169. =over 3
  170. =item *
  171. The URI::URL module exports the url() function as an alternate
  172. constructor interface.
  173. =item *
  174. The constructor takes an optional $base argument. See L<URI::WithBase>.
  175. =item *
  176. The URI::URL->newlocal class method is the same as URI::file->new_abs
  177. =item *
  178. URI::URL::strict(1)
  179. =item *
  180. $url->print_on method
  181. =item *
  182. $url->crack method
  183. =item *
  184. $url->full_path; same as ($uri->abs_path || "/")
  185. =item *
  186. $url->netloc; same as $uri->authority
  187. =item *
  188. $url->epath, $url->equery; same as $uri->path, $uri->query
  189. =item *
  190. $url->path and $url->query pass unescaped strings.
  191. =item *
  192. $url->path_components; same as $uri->path_segments (if you don't
  193. consider path segment parameters).
  194. =item *
  195. $url->params and $url->eparams methods.
  196. =item *
  197. $url->base method. See L<URI::WithBase>.
  198. =item *
  199. $url->abs and $url->rel have an optional $base argument. See
  200. L<URI::WithBase>.
  201. =item *
  202. $url->frag; same as $uri->fragment
  203. =item *
  204. $url->keywords; same as $uri->query_keywords;
  205. =item *
  206. $url->localpath with friends map to $uri->file
  207. =item *
  208. $url->address and $url->encoded822addr; same as $uri->to for mailto URI.
  209. =item *
  210. $url->groupart method for news URI.
  211. =item *
  212. $url->article; same as $uri->message
  213. =back
  214. =head1 SEE ALSO
  215. L<URI>, L<URI::WithBase>
  216. =head1 COPYRIGHT
  217. Copyright 1998-2000 Gisle Aas.
  218. =cut