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.

68 lines
1.5 KiB

  1. package URI::news; # draft-gilman-news-url-01
  2. require URI::_server;
  3. @ISA=qw(URI::_server);
  4. use strict;
  5. use URI::Escape qw(uri_unescape);
  6. use Carp ();
  7. sub default_port { 119 }
  8. # newsURL = scheme ":" [ news-server ] [ refbygroup | message ]
  9. # scheme = "news" | "snews" | "nntp"
  10. # news-server = "//" server "/"
  11. # refbygroup = group [ "/" messageno [ "-" messageno ] ]
  12. # message = local-part "@" domain
  13. sub _group
  14. {
  15. my $self = shift;
  16. my $old = $self->path;
  17. if (@_) {
  18. my($group,$from,$to) = @_;
  19. if ($group =~ /\@/) {
  20. $group =~ s/^<(.*)>$/$1/; # "<" and ">" should not be part of it
  21. }
  22. $group =~ s,%,%25,g;
  23. $group =~ s,/,%2F,g;
  24. my $path = $group;
  25. if (defined $from) {
  26. $path .= "/$from";
  27. $path .= "-$to" if defined $to;
  28. }
  29. $self->path($path);
  30. }
  31. $old =~ s,^/,,;
  32. if ($old !~ /\@/ && $old =~ s,/(.*),, && wantarray) {
  33. my $extra = $1;
  34. return (uri_unescape($old), split(/-/, $extra));
  35. }
  36. uri_unescape($old);
  37. }
  38. sub group
  39. {
  40. my $self = shift;
  41. if (@_) {
  42. Carp::croak("Group name can't contain '\@'") if $_[0] =~ /\@/;
  43. }
  44. my @old = $self->_group(@_);
  45. return if $old[0] =~ /\@/;
  46. wantarray ? @old : $old[0];
  47. }
  48. sub message
  49. {
  50. my $self = shift;
  51. if (@_) {
  52. Carp::croak("Message must contain '\@'") unless $_[0] =~ /\@/;
  53. }
  54. my $old = $self->_group(@_);
  55. return unless $old =~ /\@/;
  56. return $old;
  57. }
  58. 1;