2 # Copyright (C) 2008 Equinox Software, Inc.
3 # Author: Bill Erickson <erickson@esilibrary.com>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # ----------------------------------------------------------------------------
16 # WARNING: This script provides no security layer. Any client that has
17 # access to the server+port can inject MARC records into the system.
18 # ----------------------------------------------------------------------------
20 # ----------------------------------------------------------------------------
21 # marc_stream_importer.pl -- Import MARC records via bare socket connection
24 # ./marc_stream_importer.pl /openils/conf/opensrf_core.xml \
25 # <eg_username> <eg_password> <bib_source> --port <port> --min_servers 2 \
26 # --max_servers 20 --log_file /openils/var/log/marc_net_importer.log &
28 # Note: this script has to be run in the same directory as $oils_header.pl
31 # ----------------------------------------------------------------------------
32 # To use this script with OCLC Connexion:
34 # Under Tools -> Options -> Export (tab)
35 # Create -> Choose Connection -> OK -> Leave translation at "None"
36 # -> Create -> Create -> choose TCP/IP (internet)
37 # -> Enter hostname and Port, leave 'Use Telnet Protocol' checked
38 # -> Create/OK your way out of the dialogs
39 # Record Characteristics (button) -> Choose 'UTF-8 Unicode' for
42 # OCLC and Connexion are trademark/service marks of OCLC Online Computer
43 # Library Center, Inc.
44 # ----------------------------------------------------------------------------
46 use strict; use warnings;
47 use Net::Server::PreFork;
48 use base qw/Net::Server::PreFork/;
52 use MARC::File::USMARC;
53 use OpenSRF::Utils::Logger qw/$logger/;
54 require 'oils_header.pl';
55 use vars qw/$apputils/;
59 my $osrf_config = shift;
60 my $oils_username = shift;
61 my $oils_password = shift;
62 my $bib_source = shift;
67 WARNING: This script provides no security layer. Any client that has
68 access to the server+port can inject MARC records into the system.
72 $0 = 'Evergreen MARC Stream Listener';
76 my $socket = $self->{server}->{client};
80 # Reading <STDIN> blocks until the client is closed. Instead of waiting
81 # for that, give each inbound record $wait_time seconds to fully arrive
82 # and pull the data directly from the socket
84 local $SIG{ALRM} = sub { die "alarm\n" };
86 while(my $n = $socket->sysread($buf, $bufsize)) {
93 open $handle, '<', \$data;
94 my $batch = MARC::Batch->new('USMARC', $handle);
103 eval { $rec = $batch->next; };
106 $logger->error("Failed parsing MARC record $index");
112 my $resp = $apputils->simplereq(
114 'open-ils.cat.biblio.record.xml.import',
120 # has the session timed out?
121 if(oils_event_equals($resp, 'NO_SESSION')) {
123 my $resp = $apputils->simplereq(
125 'open-ils.cat.biblio.record.xml.import',
130 oils_event_die($resp);
132 oils_event_die($resp);
138 # the authtoken will timeout after the configured inactivity period.
139 # When that happens, get a new one.
141 $authtoken = oils_login($oils_username, $oils_password, 'staff')
142 or die "Unable to login to Evergreen";
145 osrf_connect($osrf_config);