1 # This module is part of debbugs, and is released
2 # under the terms of the GPL version 2, or any later version at your option.
3 # See the file README and COPYING for more information.
4 # Copyright 2007 by Don Armstrong <don@donarmstrong.com>.
26 use vars qw($DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT);
27 use base qw(Exporter SOAP::Server::Parameters);
30 $DEBUG = 0 unless defined $DEBUG;
36 Exporter::export_ok_tags();
37 $EXPORT_TAGS{all} = [@EXPORT_OK];
43 use Debbugs::Status qw(get_bug_status);
44 use Debbugs::Common qw(make_list getbuglocation getbugcomponent);
45 use Storable qw(nstore retrieve);
46 use Scalar::Util qw(looks_like_number);
49 our $CURRENT_VERSION = 1;
53 my %ut = get_usertag('don@donarmstrong.com','this-bug-sucks','eat-this-bug');
54 my %ut = get_usertag('don@donarmstrong.com');
56 Returns a hashref of bugs which have the specified usertags for the
59 In the second case, returns all of the usertags for the user passed.
63 use Debbugs::User qw(read_usertags);
66 my $VERSION = __populate_version(pop);
67 my ($self,$email, @tags) = @_;
69 read_usertags(\%ut, $email);
71 @tags{@tags} = (1) x @tags;
73 for my $tag (keys %ut) {
74 delete $ut{$tag} unless exists $tags{$tag};
85 my @statuses = get_status(@bugs);
86 my @statuses = get_status([bug => 304234,
94 Returns an arrayref of hashrefs which output the status for specific
97 In the first case, no options are passed to
98 L<Debbugs::Status::get_bug_status> besides the bug number; in the
99 second the bug, dist, arch, bugusertags, sourceversions, and version
100 parameters are passed if they are present.
102 As a special case for suboptimal SOAP implementations, if only one
103 argument is passed to get_status and it is an arrayref which either is
104 empty, has a number as the first element, or contains an arrayref as
105 the first element, the outer arrayref is dereferenced, and processed
106 as in the examples above.
108 See L<Debbugs::Status::get_bug_status> for details.
113 my $VERSION = __populate_version(pop);
114 my ($self,@bugs) = @_;
120 looks_like_number($bugs[0][0])
126 for my $bug (@bugs) {
129 my %param = __collapse_params(@{$bug});
130 $bug_status = get_bug_status(map {(exists $param{$_})?($_,$param{$_}):()}
131 qw(bug dist arch bugusertags sourceversions version indicatesource)
135 $bug_status = get_bug_status(bug => $bug);
137 if (defined $bug_status and keys %{$bug_status} > 0) {
138 $status{$bug} = $bug_status;
141 # __prepare_response($self);
147 my @bugs = get_bugs(...);
148 my @bugs = get_bugs([...]);
150 Returns a list of bugs. In the second case, allows the variable
151 parameters to be specified as an array reference in case your favorite
152 language's SOAP implementation is craptacular.
154 See L<Debbugs::Bugs::get_bugs> for details on what C<...> actually
159 use Debbugs::Bugs qw();
162 my $VERSION = __populate_version(pop);
163 my ($self,@params) = @_;
164 # Because some soap implementations suck and can't handle
165 # variable numbers of arguments we allow get_bugs([]);
166 if (@params == 1 and ref($params[0]) eq 'ARRAY') {
167 @params = @{$params[0]};
169 my %params = __collapse_params(@params);
171 @bugs = Debbugs::Bugs::get_bugs(%params);
177 my @bugs = newest_bugs(5);
179 Returns a list of the newest bugs. [Note that all bugs are *not*
180 guaranteed to exist, but they should in the most common cases.]
185 my $VERSION = __populate_version(pop);
186 my ($self,$num) = @_;
187 my $newest_bug = Debbugs::Bugs::newest_bug();
188 return [($newest_bug - $num + 1) .. $newest_bug];
194 my $bug_log = get_bug_log($bug);
195 my $bug_log = get_bug_log($bug,$msg_num);
197 Retuns a parsed set of the bug log; this is an array of hashes with
214 Currently $msg_num is completely ignored.
218 use Debbugs::Log qw();
219 use Debbugs::MIME qw(parse);
222 my $VERSION = __populate_version(pop);
223 my ($self,$bug,$msg_num) = @_;
225 my $location = getbuglocation($bug,'log');
226 my $bug_log = getbugcomponent($bug,'log',$location);
228 my $log_fh = IO::File->new($bug_log, 'r') or
229 die "Unable to open bug log $bug_log for reading: $!";
231 my $log = Debbugs::Log->new($log_fh) or
232 die "Debbugs::Log was unable to be initialized";
238 while (my $record = $log->read_record()) {
240 #next if defined $msg_num and ($current_msg ne $msg_num);
241 next unless $record->{type} eq 'incoming-recv';
242 my ($msg_id) = $record->{text} =~ /^Message-Id:\s+<(.+)>/im;
243 next if defined $msg_id and exists $seen_msg_ids{$msg_id};
244 $seen_msg_ids{$msg_id} = 1 if defined $msg_id;
245 next if defined $msg_id and $msg_id =~ /handler\..+\.ack(?:info)?\@/;
246 my $message = parse($record->{text});
247 my ($header,$body) = map {join("\n",make_list($_))}
248 @{$message}{qw(header body)};
249 push @messages,{header => $header,
252 msg_num => $current_msg,
258 =head2 binary_to_source
260 binary_to_source($binary_name,$binary_version,$binary_architecture)
262 Returns a reference to the source package name and version pair
263 corresponding to a given binary package name, version, and
264 architecture. If undef is passed as the architecture, returns a list
265 of references to all possible pairs of source package names and
266 versions for all architectures, with any duplicates removed.
268 (This function corresponds to L<Debbugs::Packages::binarytosource>)
272 sub binary_to_source{
273 my $VERSION = __populate_version(pop);
275 return [binarytosource(@_)];
278 =head2 source_to_binary
280 source_to_binary($source_name,$source_version);
282 Returns a reference to an array of references to binary package name,
283 version, and architecture corresponding to a given source package name
284 and version. In the case that the given name and version cannot be
285 found, the unversioned package to source map is consulted, and the
286 architecture is not returned.
288 (This function corresponds to L<Debbugs::Packages::sourcetobinary>)
292 sub source_to_binary {
293 my $VERSION = __populate_version(pop);
295 return [source_to_binary(@_)];
300 get_version(package=>'foopkg',
305 Returns a list of the versions of package in the distributions and
306 architectures listed. This routine only returns unique values.
310 =item package -- package to return list of versions
312 =item dist -- distribution (unstable, stable, testing); can be an
315 =item arch -- architecture (i386, source, ...); can be an arrayref
317 =item time -- returns a version=>time hash at which the newest package
318 matching this version was uploaded
320 =item source -- returns source/version instead of just versions
322 =item no_source_arch -- discards the source architecture when arch is
323 not passed. [Used for finding the versions of binary packages only.]
324 Defaults to 0, which does not discard the source architecture. (This
325 may change in the future, so if you care, please code accordingly.)
327 =item return_archs -- returns a version=>[archs] hash indicating which
328 architectures are at which versions.
332 This function correponds to L<Debbugs::Packages::get_versions>
337 my $VERSION = __populate_version(pop);
339 return scalar get_versions(@_);
342 =head1 VERSION COMPATIBILITY
344 The functionality provided by the SOAP interface will change over time.
346 To the greatest extent possible, we will attempt to provide backwards
347 compatibility with previous versions; however, in order to have
348 backwards compatibility, you need to specify the version with which
353 sub __populate_version{
355 return $request->{___debbugs_soap_version};
358 sub __collapse_params{
362 # Because some clients can't handle passing arrayrefs, we allow
363 # options to be specified multiple times
364 while (my ($key,$value) = splice @params,0,2) {
365 push @{$params{$key}}, make_list($value);
367 # However, for singly specified options, we want to pull them
369 for my $key (keys %params) {
370 if (@{$params{$key}} == 1) {
371 ($params{$key}) = @{$params{$key}}