Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 46 additions & 12 deletions bin/sip2-mediator
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ my $http_host = '127.0.0.1';
my $http_port = 80;
my $http_proto = 'http';
my $http_path = '/sip2-mediator';
my $http_method = 'POST';
my $sess_param = 'session';
my $mess_param = 'message';
my $response_jpath = '';
my $max_clients = 120;
my $syslog_facility = 'LOCAL0';
my $syslog_level = 'LOG_INFO';
Expand Down Expand Up @@ -62,6 +66,29 @@ Options:

--http-path <$http_path>
URL path for HTTP API server
To use the Evergreen gateway directly, use
"/osrf-gateway-v1?service=open-ils.sip2&method=open-ils.sip2.request".
To use the Evergreen OpenAPI server, use
"/openapi3/v0/

--http-method <$http_method>
HTTP method to use with the server
To use the Evergreen gateway directly, use
"GET".

--session-param <$sess_param>
CGI parameter name to pass the session key
To use the Evergreen gateway directly, use
"param".

--message-param <$mess_param>
CGI parameter name to pass the SIP2 message
To use the Evergreen gateway directly, use
"param".

--response-json-path <$response_jpath>
JSON Path expression used to extract the result message
from the HTTP response. For Evergreen use "\$.payload[0]".

--max-clients <$max_clients>
Maximum number of SIP client connections allowed.
Expand All @@ -83,18 +110,22 @@ USAGE
}

GetOptions(
'sip-address=s' => \$sip_address,
'sip-port=s' => \$sip_port,
'http-host=s' => \$http_host,
'http-port=s' => \$http_port,
'http-proto=s' => \$http_proto,
'http-path=s' => \$http_path,
'max-clients=s' => \$max_clients,
'syslog-facility=s' => \$syslog_facility,
'syslog-level=s' => \$syslog_level,
'daemonize' => \$daemonize,
'ascii' => \$ascii,
'help' => sub { usage(0); }
'sip-address=s' => \$sip_address,
'sip-port=s' => \$sip_port,
'http-host=s' => \$http_host,
'http-port=s' => \$http_port,
'http-proto=s' => \$http_proto,
'http-path=s' => \$http_path,
'http-method=s' => \$http_method,
'session-param=s' => \$sess_param,
'message-param=s' => \$mess_param,
'response-json-path=s' => \$response_jpath,
'max-clients=s' => \$max_clients,
'syslog-facility=s' => \$syslog_facility,
'syslog-level=s' => \$syslog_level,
'daemonize' => \$daemonize,
'ascii' => \$ascii,
'help' => sub { usage(0); }
) or usage(1);

my $mediator = SIP2Mediator::Server->new({
Expand All @@ -104,6 +135,9 @@ my $mediator = SIP2Mediator::Server->new({
http_port => $http_port,
http_proto => $http_proto,
http_path => $http_path,
session_param => $sess_param,
message_param => $sess_param,
response_jpath => $response_jpath,
max_clients => $max_clients,
syslog_facility => $syslog_facility,
syslog_level => $syslog_level,
Expand Down
4 changes: 3 additions & 1 deletion lib/SIP2Mediator/Message.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use strict; use warnings;
use Locale::gettext;
use JSON::XS;
use Sys::Syslog qw(syslog);
use JSON::Path qw/jpath1/;
use SIP2Mediator::Spec;
use SIP2Mediator::Field;
use SIP2Mediator::FixedField;
Expand Down Expand Up @@ -157,11 +158,12 @@ sub to_json {
}

sub from_json {
my ($class, $msg_json) = @_;
my ($class, $msg_json, $jpath) = @_;

return undef unless $msg_json;

my $hash = $json->decode($msg_json);
$hash = jpath1($hash, $jpath) if $jpath;

return $class->from_hash($hash);
}
Expand Down
22 changes: 16 additions & 6 deletions lib/SIP2Mediator/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,23 @@ sub relay_sip_request {
syslog(LOG_WARNING => "[$sclient] SIP socket disapeared ".$self->seskey);
return 0;
}
my $sess_param = $self->config->{session_param} || 'session';
my $mess_param = $self->config->{message_param} || 'message';
my $http_method = $self->config->{http_method} || 'POST';

my $post = sprintf('%s=%s&%s=%s',
$sess_param, $self->seskey, $mess_param, url_encode_utf8($msg->to_json));

my $path = $self->config->{http_path};
if ($http_method eq 'GET') {
$path .= ($path =~ /\?/) ? '&' : '?';
$path .= $post;
$post = undef;
}

my $post = sprintf('session=%s&message=%s',
$self->seskey, url_encode_utf8($msg->to_json));

syslog(LOG_DEBUG => "POST: $post");
syslog(LOG_DEBUG => "$http_method: $post");

$self->http_socket->write_request(POST => $self->config->{http_path}, $post);
$self->http_socket->write_request($http_method => $path, $post);

return 1;
}
Expand Down Expand Up @@ -310,7 +320,7 @@ sub read_http_socket {

syslog(LOG_DEBUG => "[$sclient] HTTP response: $content");

my $msg = SIP2Mediator::Message->from_json($content);
my $msg = SIP2Mediator::Message->from_json($content, $self->config->{response_jpath});

if (!$msg) {
syslog('LOG_ERR',
Expand Down