10
0
Fork 0
softsim/src/demo_server.rb

64 lines
1.5 KiB
Ruby
Executable File

#!/usr/bin/env ruby
=begin
This file is part of softSIM.
softSIM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
softSIM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with sofSIM. If not, see <http://www.gnu.org/licenses/>.
Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info
=end
# this program is there to start a server
# the io the server should use (:tcp,:unix)
io_type = :tcp
# the server to use (:pcsc,:sim)
server_type = :pcsc
# the verbosity (from common)
$verbosity = 1
# create the IO
case io_type
when :tcp
require 'socket'
TCP_HOST = "localhost"
TCP_PORT = "1337"
socket = TCPServer.new(TCP_HOST,TCP_PORT)
when :unix
require 'socket'
UNIX = "/tmp/sap_server.socket"
socket = UNIXServer.new(APDU_SOCKET)
else
raise "unkown IO type"
end
# wait for a client to connect
io = socket.accept
case server_type
when :pcsc
require 'pcsc_server'
server = PCSCServer.new(io)
when :sim
require 'sim_server'
server = SIMServer.new(io)
else
raise "unkown server type"
end
# starting the server
server.start
# close IO when finished
io.close
server.close