-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer2.cpp
More file actions
94 lines (82 loc) · 2.66 KB
/
Server2.cpp
File metadata and controls
94 lines (82 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/***********************************************************************
Server2 - Server executable for the second-generation collaboration
infrastructure.
Copyright (c) 2019-2020 Oliver Kreylos
***********************************************************************/
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <string>
#include <stdexcept>
#include <Misc/MessageLogger.h>
#include <Misc/StandardValueCoders.h>
#include <Misc/ConfigurationFile.h>
#include <Collaboration2/Config.h>
#include <Collaboration2/Server.h>
/*************
Main function:
*************/
int main(int argc,char* argv[])
{
/* Ignore SIGPIPE and leave handling of pipe errors to TCP sockets: */
struct sigaction sigPipeAction;
sigPipeAction.sa_handler=SIG_IGN;
sigemptyset(&sigPipeAction.sa_mask);
sigPipeAction.sa_flags=0x0;
sigaction(SIGPIPE,&sigPipeAction,0);
try
{
/* Open the collaboration configuration file: */
Misc::ConfigurationFile configFile(COLLABORATION_CONFIGDIR "/" COLLABORATION_CONFIGFILENAME);
Misc::ConfigurationFileSection serverConfig=configFile.getSection("Collaboration2Server");
/* Parse the command line: */
int portId=serverConfig.retrieveValue<int>("./listenPort",26000);
std::string serverName=serverConfig.retrieveString("./serverName","Default Server Name");
const char* sessionPassword=0;
for(int argi=1;argi<argc;++argi)
{
if(argv[argi][0]=='-')
{
if(strcasecmp(argv[argi]+1,"port")==0)
{
if(argi+1<argc)
portId=atoi(argv[argi+1]);
else
Misc::formattedUserWarning("Server: Ignoring dangling command line option %s",argv[argi]);
++argi;
}
else if(strcasecmp(argv[argi]+1,"password")==0)
{
if(argi+1<argc)
sessionPassword=argv[argi+1];
else
Misc::formattedUserWarning("Server: Ignoring dangling command line option %s",argv[argi]);
++argi;
}
else if(strcasecmp(argv[argi]+1,"name")==0)
{
if(argi+1<argc)
serverName=argv[argi+1];
else
Misc::formattedUserWarning("Server: Ignoring dangling command line option %s",argv[argi]);
++argi;
}
else
Misc::formattedUserWarning("Server: Ignoring unrecognized command line option %s",argv[argi]);
}
else
Misc::formattedUserWarning("Server: Ignoring command line argument %s",argv[argi]);
}
/* Create the server: */
Server server(serverConfig,portId,serverName.c_str());
server.setPassword(sessionPassword);
/* Run the server: */
server.run();
}
catch(const std::runtime_error& err)
{
Misc::formattedUserError("Server: Shutting down server due to exception %s",err.what());
}
/* Clean up and return: */
return 0;
}