read from config file probably maybe
This commit is contained in:
parent
7c3dd51315
commit
1a55c5b72e
|
@ -40,20 +40,20 @@ class PosBookieHandler : virtual public PosBookieIf {
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PosBookieHandler(char* serverHost, int serverPort)
|
PosBookieHandler(char* serverHost, int serverPort, SaltStore* saltStore)
|
||||||
: socket(new TSocket(serverHost, serverPort))
|
: socket(new TSocket(serverHost, serverPort))
|
||||||
, transport(new TFramedTransport(socket))
|
, transport(new TFramedTransport(socket))
|
||||||
, protocol(new TBinaryProtocol(transport))
|
, protocol(new TBinaryProtocol(transport))
|
||||||
, client(protocol)
|
, client(protocol)
|
||||||
{
|
{
|
||||||
|
this->saltStore = saltStore;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
this->client.ping();
|
this->client.ping();
|
||||||
} catch {
|
} catch {
|
||||||
printf("failed to contact server");
|
fprintf(stderr, "Failed to contact server '%s:%d'!\n", serverHost, serverPort);
|
||||||
exit(1);
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
saltStore = new SaltStore(120, 256, "SEKRET!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ping() { }
|
void ping() { }
|
||||||
|
@ -97,15 +97,36 @@ class PosBookieHandler : virtual public PosBookieIf {
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
if(argc != 4) {
|
if(argc != 2) {
|
||||||
printf("usage: posbookie <serverhost> <serverport> <listenport>\n");
|
printf("usage: posbookie <configFile>\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int server_port = STRTOINT(argv[2]);
|
ConfigFile conf(argv[1]);
|
||||||
int listen_port = STRTOINT(argv[3]);
|
|
||||||
|
|
||||||
shared_ptr<PosBookieHandler> handler(new PosBookieHandler(argv[1], server_port));
|
char* server_host;
|
||||||
|
int server_port;
|
||||||
|
int listen_port;
|
||||||
|
SaltStore * saltStore;
|
||||||
|
|
||||||
|
try {
|
||||||
|
server_host = conf.read<char*>("server_host", "localhost");
|
||||||
|
server_port = conf.read<int>("server_port", 9090);
|
||||||
|
listen_port = conf.read<int>("listen_port", 9091);
|
||||||
|
saltStore = new SaltStore(
|
||||||
|
conf.read<uint64_t>("key_lifetime", 120),
|
||||||
|
conf.read<size_t>("salt_size", 256),
|
||||||
|
conf.read<std::string>("secret")
|
||||||
|
);
|
||||||
|
} catch(ConfigFile::file_not_found & e) {
|
||||||
|
fprintf(stderr, "Could not open configuration file '%s'!\n", e.filename.c_str());
|
||||||
|
abort();
|
||||||
|
} catch(ConfigFile::key_not_found & e) {
|
||||||
|
fprintf(stderr, "Could not find required configuration key '%s'!\n", e.key.c_str());
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
shared_ptr<PosBookieHandler> handler(new PosBookieHandler(server_host, server_port, saltStore));
|
||||||
shared_ptr<TProcessor> processor(new PosBookieProcessor(handler));
|
shared_ptr<TProcessor> processor(new PosBookieProcessor(handler));
|
||||||
|
|
||||||
TNonblockingServer server(processor, listen_port);
|
TNonblockingServer server(processor, listen_port);
|
||||||
|
|
Loading…
Reference in New Issue