5 # check if we are using an already existing and session and if there
6 # has been established a client connection for it.
7 if (defined $session_id
8 && defined $session_cache{$session_id}) {
9 # this session has already been established
10 return $session_cache{$session_id};
13 # FIXME: don't use environment but rather a proper configuration
14 my $socketfile = $ENV{OPENXPKI_SOCKET_FILE};
15 my $client = OpenXPKI::Client::HTML::Mason->new(
17 SOCKETFILE => $socketfile,
21 if (defined $session_id) {
22 # this may happen after a restart: the client still knows its session
23 # ID, but we were restarted and the session cache is empty.
24 # try to recreate the session based on the given session_id.
25 $args{SESSION_ID} = $session_id;
27 $client->init_session(\%args);
28 $session_id = $client->get_session_id();
29 $session_cache{$session_id}->{client} = $client;
30 $session_cache{$session_id}->{session_id} = $session_id;
32 # reap the first server message and throw it away in order to get into
33 # the correct communication state
34 if ($client->get_communication_state()
36 $client->collect(); # discard first server message
39 return $session_cache{$session_id};