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.

106 lines
2.3 KiB

  1. package URI::_server;
  2. require URI::_generic;
  3. @ISA=qw(URI::_generic);
  4. use strict;
  5. use URI::Escape qw(uri_unescape);
  6. sub userinfo
  7. {
  8. my $self = shift;
  9. my $old = $self->authority;
  10. if (@_) {
  11. my $new = $old;
  12. $new = "" unless defined $new;
  13. $new =~ s/^[^@]*@//; # remove old stuff
  14. my $ui = shift;
  15. if (defined $ui) {
  16. $ui =~ s/@/%40/g; # protect @
  17. $new = "$ui\@$new";
  18. }
  19. $self->authority($new);
  20. }
  21. return undef if !defined($old) || $old !~ /^([^@]*)@/;
  22. return $1;
  23. }
  24. sub host
  25. {
  26. my $self = shift;
  27. my $old = $self->authority;
  28. if (@_) {
  29. my $tmp = $old;
  30. $tmp = "" unless defined $tmp;
  31. my $ui = ($tmp =~ /^([^@]*@)/) ? $1 : "";
  32. my $port = ($tmp =~ /(:\d+)$/) ? $1 : "";
  33. my $new = shift;
  34. $new = "" unless defined $new;
  35. if (length $new) {
  36. $new =~ s/[@]/%40/g; # protect @
  37. $port = $1 if $new =~ s/(:\d+)$//;
  38. }
  39. $self->authority("$ui$new$port");
  40. }
  41. return undef unless defined $old;
  42. $old =~ s/^[^@]*@//;
  43. $old =~ s/:\d+$//;
  44. return uri_unescape($old);
  45. }
  46. sub _port
  47. {
  48. my $self = shift;
  49. my $old = $self->authority;
  50. if (@_) {
  51. my $new = $old;
  52. $new =~ s/:\d*$//;
  53. my $port = shift;
  54. $new .= ":$port" if defined $port;
  55. $self->authority($new);
  56. }
  57. return $1 if defined($old) && $old =~ /:(\d*)$/;
  58. return;
  59. }
  60. sub port
  61. {
  62. my $self = shift;
  63. my $port = $self->_port(@_);
  64. $port = $self->default_port if !defined($port) || $port eq "";
  65. $port;
  66. }
  67. sub host_port
  68. {
  69. my $self = shift;
  70. my $old = $self->authority;
  71. $self->host(shift) if @_;
  72. return undef unless defined $old;
  73. $old =~ s/^[^@]*@//; # zap userinfo
  74. $old =~ s/:$//; # empty port does not could
  75. $old .= ":" . $self->port unless $old =~ /:/;
  76. $old;
  77. }
  78. sub default_port { undef }
  79. sub canonical
  80. {
  81. my $self = shift;
  82. my $other = $self->SUPER::canonical;
  83. my $host = $other->host || "";
  84. my $port = $other->_port;
  85. my $uc_host = $host =~ /[A-Z]/;
  86. my $def_port = defined($port) && ($port eq "" ||
  87. $port == $self->default_port);
  88. if ($uc_host || $def_port) {
  89. $other = $other->clone if $other == $self;
  90. $other->host(lc $host) if $uc_host;
  91. $other->port(undef) if $def_port;
  92. }
  93. $other;
  94. }
  95. 1;