From: djfiander Date: Sat, 16 Sep 2006 13:50:14 +0000 (+0000) Subject: Move code that connects to ILS back end out of X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=a0140fe512a9a5f68af200cf17042d275b9ff4aa;p=SIPServer.git Move code that connects to ILS back end out of sip_protocol_loop() and into handle_login(). This way, if there's a problem loading or initializing the ILS implementation, the client will be told that login failed, rather than "successfully" logging in and then having the server die later. --- diff --git a/SIPServer.pm b/SIPServer.pm index 5c67e27..9517c3e 100644 --- a/SIPServer.pm +++ b/SIPServer.pm @@ -136,8 +136,8 @@ sub raw_transport { }; if ($@) { - syslog("LOG_ERR", "raw_transport: LOGIN TIMED OUT: '$@'"); - die "raw_transport: login timed out, exiting"; + syslog("LOG_ERR", "raw_transport: LOGIN ERROR: '$@'"); + die "raw_transport: login error, exiting"; } elsif (!$self->{account}) { syslog("LOG_ERR", "raw_transport: LOGIN FAILED"); die "raw_transport: Login failed, exiting"; @@ -147,10 +147,6 @@ sub raw_transport { $self->{account}->{id}, $self->{account}->{institution}); - $inst = $self->{account}->{institution}; - $self->{institution} = $self->{config}->{institutions}->{$inst}; - $self->{policy} = $self->{institution}->{policy}; - $self->sip_protocol_loop(); syslog("LOG_INFO", "raw_transport: shutting down"); @@ -231,28 +227,6 @@ sub sip_protocol_loop { my $config = $self->{config}; my $input; - # - # initialize connection to ILS - # - my $module = $config - ->{institutions} - ->{ $self->{account}->{institution} } - ->{implementation}; - $module->use; - - if ($@) { - syslog("LOG_ERR", "%s: Loading ILS implementation '%s' failed, exiting", - $self->{service}, $self->{account}->{institution}); - die("ILS initialization failed"); - } - - $self->{ils} = $module->new($self->{institution}, $self->{account}); - - if (!$self->{ils}) { - syslog("LOG_ERR", "%s: ILS connection to '%s' failed, exiting", - $self->{service}, $self->{account}->{institution}); - die("ILS initialization failed"); - } # Now that the terminal has logged in, the first message # we recieve must be an SC_STATUS message. But it might be # an SC_REQUEST_RESEND. So, as long as we keep receiving diff --git a/Sip/MsgType.pm b/Sip/MsgType.pm index 8262014..93346dd 100644 --- a/Sip/MsgType.pm +++ b/Sip/MsgType.pm @@ -800,6 +800,7 @@ sub handle_login { my ($self, $server) = @_; my ($uid_algorithm, $pwd_algorithm); my ($uid, $pwd); + my $inst; my $fields; my $status = 1; # Assume it all works @@ -821,13 +822,38 @@ sub handle_login { syslog("LOG_WARNING", "MsgType::handle_login: Invalid password for login '$uid'"); $status = 0; - } - - # Store the active account someplace handy for everybody else to find. - if ($status) { + } else { + # Store the active account someplace handy for everybody else to find. $server->{account} = $server->{config}->{accounts}->{$uid}; + $inst = $server->{account}->{institution}; + $server->{institution} = $server->{config}->{institutions}->{$inst}; + $server->{policy} = $server->{institution}->{policy}; + + syslog("LOG_INFO", "Successful login for '%s' of '%s'", - $server->{account}->{id}, $server->{account}->{institution}); + $server->{account}->{id}, $inst); + # + # initialize connection to ILS + # + my $module = $server->{config} + ->{institutions} + ->{ $inst } + ->{implementation}; + $module->use; + + if ($@) { + syslog("LOG_ERR", "%s: Loading ILS implementation '%s' for institution '%s' failed", + $server->{service}, $module, $inst); + die("Failed to load ILS implementation '$module'"); + } + + $server->{ils} = $module->new($server->{institution}, $server->{account}); + + if (!$server->{ils}) { + syslog("LOG_ERR", "%s: ILS connection to '%s' failed", + $server->{service}, $inst); + die("Unable to connect to ILS '$inst'"); + } } $self->write_msg(LOGIN_RESP . $status);