#!/usr/bin/perl
# vim: set ai shiftwidth=4 tabstop=4 expandtab:

# Copyright (C) 2006-2013 Christoph Berg <myon@debian.org>
#           (C) 2010 Uli Martens <uli@youam.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

use strict;
use warnings;
use Dpkg::Version;
use File::Basename;
use Getopt::Long qw(:config bundling permute no_getopt_compat);
use JSON::PP     qw(decode_json);

BEGIN {
    pop @INC if $INC[-1] eq '.';
    # Load the URI::Escape module safely
    eval { require URI::Escape; };
    if ($@) {
        my $progname = basename $0;
        if ($@ =~ /^Can\'t locate URI\/Escape\.pm/) {
            die
"$progname: you must have the liburi-perl package installed\nto use this script\n";
        }
        die
"$progname: problem loading the URI::Escape module:\n  $@\nHave you installed the liburi-perl package?\n";
    }
    import URI::Escape;
}

my $VERSION  = '0.4';
my $progname = basename($0);

my $params;
my $default_arch;
my $ssl_ca_file;
my $ssl_ca_path;

my @http_client;
my @ssl_errors;

sub version($) {
    my ($fd) = @_;
    print $fd <<EOT;
rmadison $VERSION (devscripts 2.26.12)
(C) 2006-2010 Christoph Berg <myon\@debian.org>
(C) 2010 Uli Martens <uli\@youam.net>
EOT
}

sub check_ssl_error($) {
    my ($rc) = @_;
    die
"Problem with SSL CACERT check:\n Have you installed the ca-certificates package?\n"
      if grep { $_ == $rc } @ssl_errors;
}

# Append a query string to a URL that may already carry one.
sub add_query($@) {
    my ($url, @query) = @_;
    return $url . ($url =~ /\?/ ? '&' : '?') . join('&', @query);
}

# Suite name suffix per Launchpad pocket, in the order the suites are
# configured in for madison-lite.
my @lp_pockets = qw(Release Security Proposed Updates Backports);
my %lp_suffix  = (
    Release   => '',
    Security  => '-security',
    Proposed  => '-proposed',
    Updates   => '-updates',
    Backports => '-backports',
);
my %lp_rank = map { $lp_pockets[$_] => $_ } 0 .. $#lp_pockets;

# Options the Launchpad web service cannot answer.
my %lp_unsupported = (
    'binary-type' => '-b/--binary-type',
    'regex'       => '-r/--regex',
    'time'        => '-t/--time',
);

my %lp_source_query = (
    kind    => 'source',
    op      => 'getPublishedSources',
    name    => 'source_name',
    package => 'source_package_name',
    version => 'source_package_version',
);
my %lp_binary_query = (
    kind    => 'binary',
    op      => 'getPublishedBinaries',
    name    => 'binary_name',
    package => 'binary_package_name',
    version => 'binary_package_version',
);

# The pocket a suite name belongs to.
sub lp_pocket($) {
    my ($suite) = @_;
    foreach my $pocket (@lp_pockets) {
        my $suffix = $lp_suffix{$pocket} or next;
        return $pocket if $suite =~ /\Q$suffix\E\z/;
    }
    return 'Release';
}

# The series a publication went into, the architecture -a selects it by, and
# the architecture madison lists it under.  The two differ for architecture-
# independent binaries.
sub lp_series_arch($) {
    my ($pub) = @_;

    unless ($pub->{distro_arch_series_link}) {
        my ($series) = $pub->{distro_series_link} =~ m{([^/]+)\z};
        return ($series, 'source', 'source');
    }

    my ($series, $arch)
      = $pub->{distro_arch_series_link} =~ m{([^/]+)/([^/]+)\z};
    return ($series, $arch, $pub->{architecture_specific} ? $arch : 'all');
}

sub lp_suite($) {
    my ($pub)    = @_;
    my ($series) = lp_series_arch($pub);
    return $series . ($lp_suffix{ $pub->{pocket} } // '');
}

# Fetch $url and return the decoded JSON document, or undef on failure.
sub lp_get($) {
    my ($url) = @_;

    open(my $fh, '-|', @http_client, $url)
      or die "$progname: cannot run $http_client[0]: $!\n";
    my $body = do { local $/; <$fh> };
    close $fh;

    my $rc = $? >> 8;
    check_ssl_error($rc);
    if ($rc) {
        warn "$progname: failed to fetch $url\n";
        return undef;
    }

    my $json = eval { decode_json($body) };
    warn "$progname: cannot parse the reply from $url: $@" if $@;
    return $json;
}

# Run a Launchpad named operation and return all entries of the resulting
# collection, following pagination.  Returns undef if a request failed.
sub lp_collection($%) {
    my ($archive_url, %query) = @_;

    my $url = add_query($archive_url,
        map { uri_escape($_) . '=' . uri_escape($query{$_}) }
        sort keys %query);

    my @entries;
    while ($url) {
        my $page = lp_get($url) or return undef;
        push @entries, @{ $page->{entries} // [] };
        $url = $page->{next_collection_link};
    }
    return \@entries;
}

sub query_launchpad($) {
    my ($archive_url) = @_;

    foreach my $option (sort keys %lp_unsupported) {
        warn "$progname: $lp_unsupported{$option} is not supported by the"
          . " Launchpad API, ignoring it\n"
          if $params->{$option};
    }

    my @suites     = split /[,\s]+/, $params->{suite} // '';
    my %suites     = map { $suites[$_] => $_ } 0 .. $#suites;
    my %components = map { $_          => 1 } split /[,\s]+/,
      $params->{component} // '';
    my %arches = map { $_ => 1 }
      split /[,\s]+/, $params->{architecture} // $default_arch // '';
    %arches = () if $arches{'*'};

    # -a source needs no binary query, and an -a naming only binary
    # architectures needs no source one.  -S needs the source publications
    # either way, as they are what the binaries are looked up from.
    my $want_source   = !%arches || $arches{source};
    my $want_binary   = !%arches || grep { $_ ne 'source' } keys %arches;
    my $want_children = $params->{'source-and-binary'} && $want_binary;

    my %filter = (
        'ws.size'     => 300,
        'exact_match' => 'true',
        'status'      => 'Published',
        'ordered'     => 'false',
    );
    my %pockets = map { lp_pocket($_) => 1 } keys %suites;
    $filter{pocket} = (keys %pockets)[0] if keys %pockets == 1;

    # A binary can sit in a different component than the source it was built
    # from, so with -S the component is only filtered on locally.  Launchpad
    # only knows the component itself, not the debian-installer subcomponent
    # madison appends to it for udebs.
    if (keys %components == 1 and !$want_children) {
        my ($component) = keys %components;
        $component =~ s{/debian-installer\z}{};
        $filter{component_name} = $component;
    }

    my (%found, $failed);

    # The package each row is listed under: itself, or, once -S found it to be
    # a binary of a source that was asked for, that source.
    my %group;

    my $collect = sub {
        my ($asked, $query, $pubs, $source) = @_;

        foreach my $pub (@$pubs) {
            next unless ($pub->{status} // 'Published') eq 'Published';

            # Launchpad files the automatic debug symbol packages under the
            # archive they were built in, but they are served from a separate
            # archive.
            next if $pub->{is_debug};
            my ($arch, $shown_arch) = (lp_series_arch($pub))[1, 2];
            my $suite = lp_suite($pub);

            my $component = $pub->{component_name};
            $component .= '/debian-installer'
              if $query->{kind} eq 'binary'
              and ($pub->{section_name} // '') eq 'debian-installer';
            next if %suites     && !exists $suites{$suite};
            next if %components && !$components{$component};
            next if %arches     && !$arches{$arch};

            my $name    = $pub->{ $query->{package} };
            my $version = $pub->{ $query->{version} };
            my $shown_suite
              = $suite . ($component eq 'main' ? '' : "/$component");
            if ($source) { $group{$name} = $asked }
            else         { $group{$name} //= $asked }
            my $row = $found{"$name\0$shown_suite\0$version"} //= {
                package   => $name,
                version   => $version,
                suite     => $shown_suite,
                order     => Dpkg::Version->new($version, check => 0),
                requested => $suites{$suite}            // 0,
                pocket    => $lp_rank{ $pub->{pocket} } // 0,
                date      => '',
            };
            $row->{arch}{$shown_arch} = 1;

            # Remember when the oldest of the publications sharing this row
            # went in, so that rows can be ordered by age below.
            my $date = $pub->{date_published} // '';
            $row->{date} = $date
              if $date and (!$row->{date} or $date lt $row->{date});
        }
    };

    foreach my $package (@ARGV) {
        if ($want_source or $want_children) {
            my $pubs = lp_collection(
                $archive_url, %filter,
                'ws.op'                => $lp_source_query{op},
                $lp_source_query{name} => $package
            );
            $failed = 1 unless $pubs;
            $collect->($package, \%lp_source_query, $pubs // [])
              if $want_source;

            # -S lists the binaries each matching source publication built.
            # Launchpad cannot select those in one query, so they have
            # to be asked for one source publication at a time.
            if ($want_children) {
                foreach my $pub (@{ $pubs // [] }) {
                    next if %suites && !exists $suites{ lp_suite($pub) };
                    my $binaries = lp_collection(
                        $pub->{self_link},
                        'ws.size' => 300,
                        'ws.op'   => $lp_binary_query{op});
                    $failed = 1 unless $binaries;
                    $collect->(
                        $package, \%lp_binary_query, $binaries // [], $package
                    );
                }
            }
        }

        if ($want_binary) {
            my $pubs = lp_collection(
                $archive_url, %filter,
                'ws.op'                => $lp_binary_query{op},
                $lp_binary_query{name} => $package
            );
            $failed = 1 unless $pubs;
            $collect->($package, \%lp_binary_query, $pubs // []);
        }
    }

    # Lists the packages in the order they were asked for, the
    # binaries of a source by name, and the publications of each package by
    # ascending version.  Two suites carrying the same version keep the order
    # -s asked for them in; without -s they keep madison-lite's configuration
    # order, which puts the older series and the earlier pocket first.
    my %argv_order;
    $argv_order{ $ARGV[$_] } //= $_ foreach 0 .. $#ARGV;
    my @rows = sort {
        $argv_order{ $group{ $a->{package} } }
          <=> $argv_order{ $group{ $b->{package} } }
          || $a->{package} cmp $b->{package}
          || $a->{order}     <=> $b->{order}
          || $a->{requested} <=> $b->{requested}
          || $a->{pocket}    <=> $b->{pocket}
          || $a->{date} cmp $b->{date}
          || $a->{suite} cmp $b->{suite}
    } values %found;

    # "source" first, then the architectures in sorted order.
    my @table = map {
        my $source = delete $_->{arch}{source};
        [
            $_->{package}, $_->{version}, $_->{suite},
            join(', ', ($source ? 'source' : ()), sort keys %{ $_->{arch} })];
    } @rows;

    my @width = (0, 0, 0);
    foreach my $row (@table) {
        foreach my $column (0 .. $#width) {
            my $length = length $row->[$column];
            $width[$column] = $length if $length > $width[$column];
        }
    }

    my $dep_wait
      = $params->{greaterorequal} ? '>='
      : $params->{greaterthan}    ? '>>'
      :                             undef;

    foreach my $i (0 .. $#table) {
        my $row = $table[$i];
        printf " %-*s | %-*s | %-*s | %s\n",
          $width[0], $row->[0], $width[1], $row->[1], $width[2], $row->[2],
          $row->[3];
        next
          if !$dep_wait
          or ($i < $#table and $table[$i + 1][0] eq $row->[0]);
        printf "\n%s (%s %s)\n", $row->[0], $dep_wait, $row->[1];
    }

    return $failed;
}

my %url_map = (
    'debian'  => "https://api.ftp-master.debian.org/madison",
    'new'     => "https://api.ftp-master.debian.org/madison?s=new",
    'qa'      => "https://qa.debian.org/madison.php",
    'ubuntu'  => "https://api.launchpad.net/devel/ubuntu/+archive/primary",
    'udd'     => 'https://qa.debian.org/cgi-bin/madison.cgi',
    'all'     => 'https://qa.debian.org/cgi-bin/madison.cgi?table=all',
    'archive' => 'https://qa.debian.org/cgi-bin/madison.cgi?table=archived',
    'ports'   => 'https://qa.debian.org/cgi-bin/madison.cgi?table=ports',
    'janitor' => 'https://janitor.debian.net/api/madison',
);
my $default_url = 'debian';
if (system('dpkg-vendor', '--is', 'ubuntu') == 0) {
    $default_url = 'ubuntu';
}

sub usage($$) {
    my ($fd, $exit) = @_;
    my @urls = split /,/, $default_url;
    my $url
      = (@urls > 1)
      ? join(', and ', join(', ', @urls[0 .. $#urls - 1]), $urls[-1])
      : $urls[0];

    print $fd <<EOT;
Usage: rmadison [OPTION] PACKAGE[...]
Display information about PACKAGE(s).

  -a, --architecture=ARCH    only show info for ARCH(s)
  -b, --binary-type=TYPE     only show info for binary TYPE
  -c, --component=COMPONENT  only show info for COMPONENT(s)
  -g, --greaterorequal       show buildd 'dep-wait pkg >= {highest version}' info
  -G, --greaterthan          show buildd 'dep-wait pkg >> {highest version}' info
  -h, --help                 show this help and exit
  -r, --regex                treat PACKAGE as a regex [not supported everywhere]
  -s, --suite=SUITE          only show info for this suite
  -S, --source-and-binary    show info for the binary children of source pkgs
  -t, --time                 show projectb snapshot date
  -u, --url=URL              use URL instead of $url

  --noconf, --no-conf        don\'t read devscripts configuration files

ARCH, COMPONENT and SUITE can be comma (or space) separated lists, e.g.
    --architecture=amd64,i386

Aliases for URLs:
EOT
    foreach my $alias (sort keys %url_map) {
        print $fd "\t$alias\t$url_map{$alias}\n";
    }
    exit $exit;
}

if (@ARGV and $ARGV[0] =~ /^--no-?conf$/) {
    shift;
} else {
    # We don't have any predefined variables, but allow any of the form
    # RMADISON_URL_MAP_SHORTCODE=URL
    my @config_files = ('/etc/devscripts.conf', '~/.devscripts');
    my @config_vars  = ();

    my $shell_cmd;
    # Set defaults
    $shell_cmd .= qq[unset `set | grep "^RMADISON_" | cut -d= -f1`;\n];
    $shell_cmd .= 'for file in ' . join(" ", @config_files) . "; do\n";
    $shell_cmd .= '[ -f $file ] && . $file; done;' . "\n";
    $shell_cmd .= 'for var in `set | grep "^RMADISON_" | cut -d= -f1`; do ';
    $shell_cmd .= 'eval echo $var=\$$var; done;' . "\n";
    # Read back values
    my $shell_out = `/bin/bash -c '$shell_cmd'`;
    @config_vars = split /\n/, $shell_out, -1;

    foreach my $confvar (@config_vars) {
        if ($confvar =~ /^RMADISON_URL_MAP_([^=]*)=(.*)$/) {
            $url_map{ lc($1) } = $2;
        } elsif ($confvar =~ /^RMADISON_DEFAULT_URL=(.*)$/) {
            $default_url = $1;
        } elsif ($confvar =~ /^RMADISON_ARCHITECTURE=(.*)$/) {
            $default_arch = $1;
        } elsif ($confvar =~ /^RMADISON_SSL_CA_FILE=(.*)$/) {
            $ssl_ca_file = $1;
        } elsif ($confvar =~ /^RMADISON_SSL_CA_PATH=(.*)$/) {
            $ssl_ca_path = $1;
        }
    }
}

unless (
    GetOptions(
        '-a=s'                => \$params->{'architecture'},
        '--architecture=s'    => \$params->{'architecture'},
        '-b=s'                => \$params->{'binary-type'},
        '--binary-type=s'     => \$params->{'binary-type'},
        '-c=s'                => \$params->{'component'},
        '--component=s'       => \$params->{'component'},
        '-g'                  => \$params->{'greaterorequal'},
        '--greaterorequal'    => \$params->{'greaterorequal'},
        '-G'                  => \$params->{'greaterthan'},
        '--greaterthan'       => \$params->{'greaterthan'},
        '-h'                  => \$params->{'help'},
        '--help'              => \$params->{'help'},
        '--noconf'            => \$params->{'noconf'},
        '--no-conf'           => \$params->{'noconf'},
        '-r'                  => \$params->{'regex'},
        '--regex'             => \$params->{'regex'},
        '-s=s'                => \$params->{'suite'},
        '--suite=s'           => \$params->{'suite'},
        '-S'                  => \$params->{'source-and-binary'},
        '--source-and-binary' => \$params->{'source-and-binary'},
        '-t'                  => \$params->{'time'},
        '--time'              => \$params->{'time'},
        '-u=s'                => \$params->{'url'},
        '--url=s'             => \$params->{'url'},
        '--version'           => \$params->{'version'},
    )
) {
    usage(\*STDERR, 1);
}

if ($params->{help}) {
    usage(\*STDOUT, 0);
}
if ($params->{version}) {
    version(\*STDOUT);
    exit 0;
}
if ($params->{'noconf'}) {
    print '--noconf must come first on the command line.';
    usage(\*STDOUT, 1);
}

unless (@ARGV) {
    print STDERR "E: need at least one package name as an argument.\n";
    exit 1;
}
if ($params->{greaterorequal} and $params->{greaterthan}) {
    print STDERR
      "E: -g/--greaterorequal and -G/--greaterthan are mutually exclusive.\n";
    exit 1;
}

my @args;

if ($params->{'architecture'}) {
    push @args, "a=$params->{'architecture'}";
} elsif ($default_arch) {
    push @args, "a=$default_arch";
}
push @args, "b=$params->{'binary-type'}" if $params->{'binary-type'};
push @args, "c=$params->{'component'}"   if $params->{'component'};
push @args, "g"                          if $params->{'greaterorequal'};
push @args, "G"                          if $params->{'greaterthan'};
push @args, "r"                          if $params->{'regex'};
push @args, "s=$params->{'suite'}"       if $params->{'suite'};
push @args, "S"                          if $params->{'source-and-binary'};
push @args, "t"                          if $params->{'time'};

my $url = $params->{'url'} ? $params->{'url'} : $default_url;
my @url = split /,/, $url;

my $status = 0;

# Strip arch qualifiers from the package name, to help those that are feeding
# in output from other commands
s/:.*// for (@ARGV);

if (-x "/usr/bin/curl") {
    @http_client = qw/curl -f -s -S -L/;
    push @http_client, "--cacert", $ssl_ca_file if $ssl_ca_file;
    push @http_client, "--capath", $ssl_ca_path if $ssl_ca_path;
    @ssl_errors = (60, 77);
} else {
    @http_client = qw/wget -q -O -/;
    push @http_client, "--ca-certificate=$ssl_ca_file" if $ssl_ca_file;
    push @http_client, "--ca-directory=$ssl_ca_path"   if $ssl_ca_path;
    @ssl_errors = (5);
}

foreach my $url (@url) {
    print "$url:\n"       if @url > 1;
    $url = $url_map{$url} if $url_map{$url};

    # Launchpad has no madison CGI, so build the table from its web service.
    if ($url =~ m{\Ahttps://api\.(?:[\w-]+\.)?launchpad\.net/}) {
        $status = 1 if query_launchpad($url);
        next;
    }

    system @http_client,
      add_query($url, "package=" . join("+", map { uri_escape($_) } @ARGV),
        "text=on", @args);
    my $rc = $? >> 8;
    if ($rc != 0) {
        check_ssl_error($rc);
        $status = 1;
    }
}

exit $status;

__END__

=head1 NAME

rmadison -- Remotely query the Debian archive database about packages

=head1 SYNOPSIS

=over

=item B<rmadison> [I<OPTIONS>] I<PACKAGE> ...

=back

=head1 DESCRIPTION

B<dak ls> queries the Debian archive database ("projectb") and
displays which package version is registered per architecture/component/suite.
The CGI at B<https://qa.debian.org/madison.php> provides that service without
requiring SSH access to ftp-master.debian.org or the mirror on
mirror.ftp-master.debian.org. This script, B<rmadison>, is a command line
frontend to this CGI.

Ubuntu has no such CGI. Queries against an B<https://api.launchpad.net/> URL,
such as the B<ubuntu> shorthand, are instead answered by asking the Launchpad
web service for the published sources and binaries and formatting the reply
like B<madison> would. See L</LAUNCHPAD ARCHIVES> below.

=head1 OPTIONS

=over

=item B<-a>, B<--architecture=>I<ARCH>

only show info for ARCH(s)

=item B<-b>, B<--binary-type=>I<TYPE>

only show info for binary TYPE

=item B<-c>, B<--component=>I<COMPONENT>

only show info for COMPONENT(s)

=item B<-g>, B<--greaterorequal>

show buildd 'dep-wait pkg >= {highest version}' info

=item B<-G>, B<--greaterthan>

show buildd 'dep-wait pkg >> {highest version}' info

=item B<-h>, B<--help>

show this help and exit

=item B<-s>, B<--suite=>I<SUITE>

only show info for this suite

=item B<-r>, B<--regex>

treat PACKAGE as a regex

B<Note:> Since B<-r> can easily DoS the database ("-r ."), this option is not
supported by the CGI on qa.debian.org and most other installations.

=item B<-S>, B<--source-and-binary>

show info for the binary children of source pkgs

=item B<-t>, B<--time>

show projectb snapshot and reload time (not supported by all archives)

=item B<-u>, B<--url=>I<URL>[B<,>I<URL> ...]

use I<URL> for the query. Supported shorthands are
 B<debian> https://api.ftp-master.debian.org/madison
 B<new> https://api.ftp-master.debian.org/madison?s=new
 B<qa> https://qa.debian.org/madison.php
 B<ubuntu> https://api.launchpad.net/devel/ubuntu/+archive/primary
 B<udd> https://qa.debian.org/cgi-bin/madison.cgi
 B<all> https://qa.debian.org/cgi-bin/madison.cgi?table=all
 B<archive> https://qa.debian.org/cgi-bin/madison.cgi?table=archived
 B<ports> https://qa.debian.org/cgi-bin/madison.cgi?table=ports

See the B<RMADISON_URL_MAP_> variable below for a method to add
new shorthands.

=item B<--version>

show version and exit

=item B<--no-conf>, B<--noconf>

don't read the devscripts configuration files

=back

ARCH, COMPONENT and SUITE can be comma (or space) separated lists, e.g.
--architecture=amd64,i386

=head1 CONFIGURATION VARIABLES

The two configuration files F</etc/devscripts.conf> and
F<~/.devscripts> are sourced by a shell in that order to set
configuration variables. Command line options can be used to override
configuration file settings. Environment variable settings are
ignored for this purpose. The currently recognised variables are:

=over 4

=item B<RMADISON_URL_MAP_>I<SHORTHAND>=I<URL>

Add an entry to the set of shorthand URLs listed above. I<SHORTHAND> should
be replaced with the shorthand form to be used to refer to I<URL>.

Multiple shorthand entries may be specified by using multiple
B<RMADISON_URL_MAP_*> variables.

=item B<RMADISON_DEFAULT_URL>=I<URL>

Set the default URL to use unless overridden by a command line option.
For Debian this defaults to debian. For Ubuntu this defaults to ubuntu.

=item B<RMADISON_ARCHITECTURE>=I<ARCH>

Set the default architecture to use unless overridden by a command line option.
To run an unrestricted query when B<RMADISON_ARCHITECTURE> is set, use
B<--architecture='*'>.

=item B<RMADISON_SSL_CA_FILE>=I<FILE>

Use the specified CA file instead of the default CA bundle for curl/wget,
passed as --cacert to curl, and as --ca-certificate to wget.

=item B<RMADISON_SSL_CA_PATH>=I<PATH>

Use the specified CA directory instead of the default CA bundle for curl/wget,
passed as --capath to curl, and as --ca-directory to wget.

=back

=head1 LAUNCHPAD ARCHIVES

Any I<URL> under B<https://api.launchpad.net/> is queried through the
Launchpad web service rather than through a B<madison> CGI. Besides the
B<ubuntu> shorthand this also works for any other archive Launchpad knows
about, for instance a PPA:

  RMADISON_URL_MAP_MYPPA=https://api.launchpad.net/devel/~user/+archive/ubuntu/ppa

Only B<-a>, B<-c>, B<-g>, B<-G>, B<-s> and B<-S> are supported for such a
query. B<-b>, B<-r> and B<-t> have no equivalent in the web service
and are ignored with a warning.

=head1 NOTES

B<dak ls> was formerly called B<madison>.

The protocol used by rmadison is fairly simple, the CGI accepts query the
parameters a, b, c, g, G, r, s, S, t, and package. The parameter text is passed to
enable plain-text output.

=head1 SEE ALSO

B<dak>(1), B<madison-lite>(1)

=head1 AUTHOR

rmadison and https://qa.debian.org/madison.php were written by Christoph Berg
<myon@debian.org>. dak was written by
James Troup <james@nocrew.org>, Anthony Towns <ajt@debian.org>, and others.

=cut
