1 # ---------------------------------------------------------------
2 # Copyright © 2014 Jason J.A. Stephenson <jason@sigio.com>
4 # This file is part of NCIPServer.
6 # NCIPServer is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # NCIPServer is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with NCIPServer. If not, see <http://www.gnu.org/licenses/>.
18 # ---------------------------------------------------------------
29 my $class = ref $invocant || $invocant;
30 my $self = bless {@_}, $class;
34 # Methods required for SHAREit:
40 return $self->unsupportedservice($request);
43 sub cancelrequestitem {
47 return $self->unsupportedservice($request);
54 return $self->unsupportedservice($request);
61 return $self->unsupportedservice($request);
68 return $self->unsupportedservice($request);
75 return $self->unsupportedservice($request);
82 return $self->unsupportedservice($request);
85 # Other methods, just because.
87 # Handle a LookupVersion Request. You probably want to just call this
88 # one from your subclasses rather than reimplement it.
93 my $response = NCIP::Response->new({type => "LookupVersionResponse"});
94 $response->header($self->make_header($request));
96 versions => [ NCIP::Const::SUPPORTED_VERSIONS ]
98 $response->data($payload);
103 # A few helper methods:
105 # This is a handy method that subclasses should probably not override.
106 # It returns a response containing an Unsupported Service problem. It
107 # is used by NCIP.pm when the ILS cannot handle a message, or your
108 # implementation could return this in the case of a service/message
109 # you don't actually handle, though you may have the proper function
111 sub unsupportedservice {
116 for my $key (keys %$request) {
117 if (ref $request->{$key} eq 'HASH') {
123 my $response = NCIP::Response->new({type => $service . 'Response'});
124 my $problem = NCIP::Problem->new();
125 $problem->ProblemType('Unsupported Service');
126 $problem->ProblemDetail("$service service is not supported by this implementation.");
127 $problem->ProblemElement("NULL");
128 $problem->ProblemValue("Not Supported");
129 $response->problem($problem);
134 # All subclasses will possibly want to create a ResponseHeader and the
135 # code for that would be highly redundant. We supply a default
136 # implementation here that can retrieve the agency information from
137 # the InitiationHeader of the message, swap their values, and return a
146 for my $key (keys %$request) {
147 if (ref $request->{$key} eq 'HASH'
148 && $request->{$key}->{InitiationHeader}) {
149 $initheader = $request->{$key}->{InitiationHeader};
154 if ($initheader && $initheader->{FromAgencyId}
155 && $initheader->{ToAgencyId}) {
156 $header = NCIP::Header->new({
157 FromAgencyId => $initheader->{ToAgencyId},
158 ToAgencyId => $initheader->{FromAgencyId}