From 7c1ab90452899e778ee3612d79ddbfbd74240745 Mon Sep 17 00:00:00 2001 From: Alan Rykhus Date: Thu, 29 Aug 2013 13:10:27 -0500 Subject: [PATCH] This is my start to the NCIPServer, the only real code is the Apache NCIPResponder, reading of the configuration file, and creation of a generic NCIP object --- NCIP.pm | 29 ++++++++++ NCIP/Configuration.pm | 91 +++++++++++++++++++++++++++++++ NCIP/Configuration/Account.pm | 52 ++++++++++++++++++ NCIP/Configuration/Institution.pm | 47 ++++++++++++++++ NCIPResponder.pm | 45 +++++++++++++++ 5 files changed, 264 insertions(+) create mode 100644 NCIP.pm create mode 100644 NCIP/Configuration.pm create mode 100644 NCIP/Configuration/Account.pm create mode 100644 NCIP/Configuration/Institution.pm create mode 100644 NCIPResponder.pm diff --git a/NCIP.pm b/NCIP.pm new file mode 100644 index 0000000..1f66106 --- /dev/null +++ b/NCIP.pm @@ -0,0 +1,29 @@ + +package NCIPServer::NCIP; +use strict; +use warnings; + +use NCIPServer::NCIP::Configuration; + +use FileHandle; + +sub new { + my $self = shift; + my $config_file = shift; + + my $config = NCIPServer::NCIP::Configuration->new($config_file); + + return bless $config, $self; + +} + +sub process_request { + my $self = shift; + my $xml = shift; + + my $response = " Hello There

Hello You Big JERK!

Who would take this book seriously if the first eaxample didn't say \"hello world\"? "; + + return $response; +} + +1; diff --git a/NCIP/Configuration.pm b/NCIP/Configuration.pm new file mode 100644 index 0000000..6d0efbe --- /dev/null +++ b/NCIP/Configuration.pm @@ -0,0 +1,91 @@ +# +# Copyright (C) 2013 MnSCU/PALS +# +# Author: Alan Rykhus +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of version 2 of the GNU General Public +# License as published by the Free Software Foundation. +# +# 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., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# parse-config: Parse an XML-format +# ACS configuration file and build the configuration +# structure. +# + +package NCIPServer::NCIP::Configuration; + +our $VERSION = 0.02; + +use strict; +use warnings; +use XML::Simple qw(:strict); + +use NCIPServer::NCIP::Configuration::Account; +use NCIPServer::NCIP::Configuration::Institution; + +my $parser = new XML::Simple( + KeyAttr => { + login => '+id', + institution => '+id', + }, + GroupTags => { + accounts => 'login', + institutions => 'institution', + }, + ForceArray => [ 'login', 'institution' ], +); + +sub new { + my ($class, $config_file) = @_; + my $cfg = $parser->XMLin($config_file); + + foreach my $acct (values %{$cfg->{accounts}}) { + new NCIPServer::NCIP::Configuration::Account $acct; + } + + foreach my $inst (values %{$cfg->{institutions}}) { + new NCIPServer::NCIP::Configuration::Institution $inst; + } + + return bless $cfg, $class; +} + +sub accounts { + my $self = shift; + return values %{$self->{accounts}}; +} + +sub institutions { + my $self = shift; + return values %{$self->{institutions}}; +} + +1; +__END__ + +=head1 NAME + +NCIPServer::NCIP::Configuration - abstraction/accessor for NCIP configs + +=head1 SYNOPSIS + +use NCIPServer::NCIP::Configuration; +my $config = NCIPServer::NCIP::Configuration->new($ARGV[0]); + +foreach my $acct ($config->accounts) { + print "Found account: '", $acct->id, "', part of '"; + print $acct->institution, "'\n"; +} + +=cut + diff --git a/NCIP/Configuration/Account.pm b/NCIP/Configuration/Account.pm new file mode 100644 index 0000000..47d48f4 --- /dev/null +++ b/NCIP/Configuration/Account.pm @@ -0,0 +1,52 @@ +# +# Copyright (C) 2013 MnSCU/PALS +# +# Author: Alan Rykhus +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of version 2 of the GNU General Public +# License as published by the Free Software Foundation. +# +# 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., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# + +package NCIPServer::NCIP::Configuration::Account; + +use strict; +use warnings; + +sub new { + my ($class, $obj) = @_; + my $type = ref($class) || $class; + + if (ref($obj) eq "HASH") { + return bless $obj, $type; # Just bless the object + } + + return bless {}, $type; +} + +sub id { + my $self = shift; + return $self->{id}; +} + +sub institution { + my $self = shift; + return $self->{institution}; +} + +sub password { + my $self = shift; + return $self->{password}; +} + +1; diff --git a/NCIP/Configuration/Institution.pm b/NCIP/Configuration/Institution.pm new file mode 100644 index 0000000..6ea58e1 --- /dev/null +++ b/NCIP/Configuration/Institution.pm @@ -0,0 +1,47 @@ +# +# Copyright (C) 2013 MnSCU/PALS +# +# Author: Alan Rykhus +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of version 2 of the GNU General Public +# License as published by the Free Software Foundation. +# +# 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., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# + +package NCIPServer::NCIP::Configuration::Institution; + +use strict; +use warnings; + +sub new { + my ($class, $obj) = @_; + my $type = ref($class) || $class; + + if (ref($obj) eq "HASH") { + return bless $obj, $type; # Just bless the object + } + + return bless {}, $type; +} + +sub id { + my $self = shift; + return $self->{id}; +} + +sub implementation { + my $self = shift; + return $self->{implementation}; +} + +1; diff --git a/NCIPResponder.pm b/NCIPResponder.pm new file mode 100644 index 0000000..29c4651 --- /dev/null +++ b/NCIPResponder.pm @@ -0,0 +1,45 @@ + +package NCIPServer::NCIPResponder; +use strict; +use warnings; + +use FileHandle; + +use Apache2::Const -compile => qw(OK :log :http :methods :cmd_how :override); +use Apache2::RequestRec (); +use Apache2::RequestIO (); +use NCIPServer::NCIP; + +sub handler { + my $r = shift; + + return Apache2::Const::HTTP_METHOD_NOT_ALLOWED unless $r->method_number eq Apache2::Const::M_POST; + + my $NCIPConfigFile = $r->dir_config('NCIPConfigFile'); + + if (!defined($NCIPConfigFile)) { + die sprintf "error: There is no NCIPConfigFile defined\n"; + } else { + if (! (-r $NCIPConfigFile)) { + die sprintf "error: NCIPConfigFile %s does not exist or is not readable\n", $NCIPConfigFile; + } + } + + my $ncip = NCIPServer::NCIP->new($NCIPConfigFile); + + $r->content_type('text/html'); + my $tmp_buf; + my $input_xml; + + while ($r->read($tmp_buf, 1024)) + { + $input_xml .= $tmp_buf; + } + + my $response_xml = $ncip->process_request($input_xml); + + $r->print($response_xml); + return Apache2::Const::OK; +} + +1; -- 2.43.2