From 77761cd6861490775d0d617f962ad213019517d9 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Fri, 19 Oct 2007 12:58:48 +0000 Subject: Bug 396243: Allow extensions (aka plugins) to extend the WebService interface This also includes the first checkin of the example plugin. Patch By Max Kanat-Alexander r=ghendricks, a=mkanat --- .cvsignore | 1 - Bugzilla/Hook.pm | 35 ++++++++++++++++++++++++++++++++++- extensions/example/code/webservice.pl | 5 +++++ extensions/example/disabled | 0 extensions/example/lib/WSExample.pm | 10 ++++++++++ xmlrpc.cgi | 6 ++++++ 6 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 extensions/example/code/webservice.pl create mode 100644 extensions/example/disabled create mode 100644 extensions/example/lib/WSExample.pm diff --git a/.cvsignore b/.cvsignore index 1d378db06..cba381bab 100644 --- a/.cvsignore +++ b/.cvsignore @@ -4,4 +4,3 @@ data localconfig index.html old-params.txt -extensions diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm index a9cfc649c..9d65fbe69 100644 --- a/Bugzilla/Hook.pm +++ b/Bugzilla/Hook.pm @@ -62,7 +62,7 @@ __END__ =head1 NAME -Bugzilla::Hook - Extendible extension hooks for Bugzilla code +Bugzilla::Hook - Extendable extension hooks for Bugzilla code =head1 SYNOPSIS @@ -193,3 +193,36 @@ definitions. F will automatically add these tables to the database when run. =back + +=head2 webservice + +This hook allows you to add your own modules to the WebService. (See +L.) + +Params: + +=over + +=item C + +A hashref that you can specify the names of your modules and what Perl +module handles the functions for that module. (This is actually sent to +L. You can see how that's used in F.) + +The Perl module name must start with C +(replace C with the name of your extension). The C +declaration inside that module must also start with +C in that module's code. + +Example: + + $dispatch->{Example} = "extensions::example::lib::Example"; + +And then you'd have a module F + +It's recommended that all the keys you put in C start with the +name of your extension, so that you don't conflict with the standard Bugzilla +WebService functions (and so that you also don't conflict with other +plugins). + +=back diff --git a/extensions/example/code/webservice.pl b/extensions/example/code/webservice.pl new file mode 100644 index 000000000..cf608c0e2 --- /dev/null +++ b/extensions/example/code/webservice.pl @@ -0,0 +1,5 @@ +use strict; +use warnings; +use Bugzilla; +my $dispatch = Bugzilla->hook_args->{dispatch}; +$dispatch->{Example} = "extensions::example::lib::WSExample"; diff --git a/extensions/example/disabled b/extensions/example/disabled new file mode 100644 index 000000000..e69de29bb diff --git a/extensions/example/lib/WSExample.pm b/extensions/example/lib/WSExample.pm new file mode 100644 index 000000000..05975b874 --- /dev/null +++ b/extensions/example/lib/WSExample.pm @@ -0,0 +1,10 @@ +package extensions::example::lib::WSExample; +use strict; +use warnings; + +use base qw(Bugzilla::WebService); + +# This can be called as Example.hello() from XML-RPC. +sub hello { return 'Hello!'; } + +1; diff --git a/xmlrpc.cgi b/xmlrpc.cgi index 227815d26..2ac34e675 100755 --- a/xmlrpc.cgi +++ b/xmlrpc.cgi @@ -20,6 +20,7 @@ use lib qw(. lib); use Bugzilla; use Bugzilla::Constants; +use Bugzilla::Hook; # Use an eval here so that runtests.pl accepts this script even if SOAP-Lite # is not installed. @@ -29,11 +30,16 @@ $@ && ThrowCodeError('soap_not_installed'); Bugzilla->usage_mode(Bugzilla::Constants::USAGE_MODE_WEBSERVICE); +my %hook_dispatch; +Bugzilla::Hook::process('webservice', { dispatch => \%hook_dispatch }); +local @INC = (bz_locations()->{extensionsdir}, @INC); + my $response = Bugzilla::WebService::XMLRPC::Transport::HTTP::CGI ->dispatch_with({'Bugzilla' => 'Bugzilla::WebService::Bugzilla', 'Bug' => 'Bugzilla::WebService::Bug', 'User' => 'Bugzilla::WebService::User', 'Product' => 'Bugzilla::WebService::Product', + %hook_dispatch }) ->on_action(\&Bugzilla::WebService::handle_login) ->handle; -- cgit v1.2.3-24-g4f1b