3 #----------------------------------------------------------------
4 # Generic header for tesing OpenSRF methods
5 #----------------------------------------------------------------
12 use OpenSRF::AppSession;
13 use OpenSRF::EX qw(:try);
14 use Time::HiRes qw/time/;
15 use Digest::MD5 qw(md5_hex);
16 use OpenILS::Utils::Fieldmapper;
17 use OpenILS::Application::AppUtils;
18 use OpenSRF::Utils::SettingsClient;
19 use OpenSRF::Utils::Logger qw/:logger/;
23 our $apputils = "OpenILS::Application::AppUtils";
29 # Some constants for our services
30 our $AUTH = 'open-ils.auth';
31 our $STORAGE = 'open-ils.storage';
32 our $SEARCH = 'open-ils.search';
33 our $CIRC = 'open-ils.circ';
34 our $CAT = 'open-ils.cat';
35 our $MATH = 'opensrf.math';
36 our $SETTINGS = 'opensrf.settings';
37 our $ACTOR = 'open-ils.actor';
39 sub AUTH { return $AUTH; }
40 sub STORAGE { return $STORAGE; }
41 sub SEARCH { return $SEARCH; }
42 sub CIRC { return $CIRC; }
43 sub CAT { return $CAT; }
44 sub MATH { return $MATH; }
45 sub SETTINGS { return $SETTINGS; }
46 sub ACTOR { return $ACTOR; }
49 #----------------------------------------------------------------
51 #----------------------------------------------------------------
53 my ($pkg, $file, $line, $sub) = _caller();
55 die "Script halted with error ".
56 "($pkg : $file : $line : $sub):\n" . shift() . "\n";
59 #----------------------------------------------------------------
61 #----------------------------------------------------------------
62 sub printl { print "@_\n"; }
64 #----------------------------------------------------------------
65 # Print with Data::Dumper
66 #----------------------------------------------------------------
67 sub debug { printl(Dumper(@_)); }
70 #----------------------------------------------------------------
71 # This is not the function you're looking for
72 #----------------------------------------------------------------
74 my ($pkg, $file, $line, $sub) = caller(2);
76 ($pkg, $file, $line) = caller(1);
79 return ($pkg, $file, $line, $sub);
83 #----------------------------------------------------------------
84 # Connect to the servers
85 #----------------------------------------------------------------
88 err("Bootstrap config required") unless $config;
89 OpenSRF::System->bootstrap_client( config_file => $config );
90 Fieldmapper->import(IDL =>
91 OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
96 #----------------------------------------------------------------
97 # Get a handle for the memcache object
98 #----------------------------------------------------------------
100 eval 'use OpenSRF::Utils::Cache;';
101 $memcache = OpenSRF::Utils::Cache->new('global') unless $memcache;
105 #----------------------------------------------------------------
106 # Is the given object an OILS event?
107 #----------------------------------------------------------------
110 if( $e and ref($e) eq 'HASH' ) {
111 return 1 if defined($e->{ilsevent});
116 sub oils_event_equals {
117 my( $e, $name ) = @_;
118 return 1 if (oils_is_event($e) and ($e->{textcode} eq $name));
122 #----------------------------------------------------------------
123 # If the given object is an event, this prints the event info
124 # and exits the script
125 #----------------------------------------------------------------
128 my ($pkg, $file, $line, $sub) = _caller();
129 if(oils_is_event($evt)) {
130 if($evt->{ilsevent}) {
131 printl("\nReceived Event($pkg : $file : $line : $sub): \n" . Dumper($evt));
138 #----------------------------------------------------------------
139 # Login to the auth server and set the global $authtoken var
140 #----------------------------------------------------------------
142 my( $username, $password, $type ) = @_;
146 my $seed = $apputils->simplereq( $AUTH,
147 'open-ils.auth.authenticate.init', $username );
148 err("No auth seed") unless $seed;
150 my $response = $apputils->simplereq( $AUTH,
151 'open-ils.auth.authenticate.complete',
152 { username => $username,
153 password => md5_hex($seed . md5_hex($password)),
156 err("No auth response returned on login") unless $response;
158 oils_event_die($response);
160 $authtime = $response->{payload}->{authtime};
161 $authtoken = $response->{payload}->{authtoken};
166 #----------------------------------------------------------------
167 # Destroys the login session on the server
168 #----------------------------------------------------------------
170 $apputils->simplereq(
172 'open-ils.auth.session.delete', $authtoken );
175 #----------------------------------------------------------------
176 # Fetches the user object and sets the global $user var
177 #----------------------------------------------------------------
178 sub oils_fetch_session {
180 my $resp = $apputils->simplereq( $AUTH,
181 'open-ils.auth.session.retrieve', $ses, 'staff' );
182 oils_event_die($resp);
183 return $user = $resp;
186 #----------------------------------------------------------------
187 # var $response = simplereq( $service, $method, @params );
188 #----------------------------------------------------------------
189 sub simplereq { return $apputils->simplereq(@_); }
190 sub osrf_request { return $apputils->simplereq(@_); }