18#define RESIPROCATE_SUBSYSTEM AppSubsystem::MOHPARKSERVER
28 mTlsDomain(
DnsUtil::getLocalHostName()),
29 mCertificatePath(
"./certs"),
31 mMediaPortRangeStart(50000),
32 mMediaPortRangeSize(100),
35 mLogFilename(
"mohparkserver.log"),
36 mLogFileMaxBytes(5000000),
42 parseConfigFile(
"mohparkserver.config");
46 parseCommandLine(argc, argv);
54 mTlsDomain(
DnsUtil::getLocalHostName()),
55 mCertificatePath(
"./certs"),
57 mMediaPortRangeStart(50000),
58 mMediaPortRangeSize(100),
61 mLogFilename(
"mohparkserver.log"),
62 mLogFileMaxBytes(5000000),
72ConfigParser::parseCommandLine(
int argc,
char** argv)
75 for(
int i = 1; i < argc; i++)
77 Data commandName(argv[i]);
85 cout <<
"Command line options are:" << endl;
86 cout <<
" -a <IP Address> - bind SIP transports to this IP address" << endl;
87 cout <<
" -d <DNS servers> - comma seperated list of DNS servers, overrides OS detected list" << endl;
88 cout <<
" -up <port num> - local port number to use for UDP SIP messaging" << endl;
89 cout <<
" -tp <port num> - local port number to use for TCP SIP messaging" << endl;
90 cout <<
" -sp <port num> - local port number to use for TLS SIP messaging" << endl;
91 cout <<
" -td <domain name> - domain name to use for TLS server connections" << endl;
92 cout <<
" -cp <certificate path> - path to load TLS certificates from" << endl;
93 cout <<
" -nk - no keepalives, set this to disable sending of keepalives" << endl;
94 cout <<
" -op <SIP URI> - URI of a proxy server to use a SIP outbound proxy" << endl;
95 cout <<
" -l <NONE|ERR|WARNING|INFO|DEBUG|STACK> - logging level" << endl;
97 cout <<
"Sample Command line:" << endl;
98 cout <<
"MOHParkServer -a 192.168.1.100 -l DEBUG" << endl;
105 else if(commandName.at(0) ==
'-')
107 commandName = commandName.substr(1);
110 Data commandValue(i+1 < argc ? argv[i+1] :
Data::Empty);
111 if(commandValue.
empty() || commandValue.
at(0) ==
'-')
113 cerr <<
"Invalid command line parameters!" << endl;
119 if(!processOption(commandName.lowercase(), commandValue))
121 cerr <<
"Invalid command line parameters!" << endl;
127 cerr <<
"Invalid command line parameters!" << endl;
134ConfigParser::parseConfigFile(
const Data& filename)
136 ifstream configFile(filename.
c_str());
139 while(getline(configFile, sline))
147 const char * anchor = pb.position();
148 if(pb.eof() || *anchor ==
'#')
continue;
150 pb.skipToOneOf(
"= \t");
153 pb.data(name,anchor);
154 if(*pb.position()!=
'=')
160 anchor = pb.position();
164 pb.data(value, anchor);
173ConfigParser::processOption(
const Data& name,
const Data& value)
178 unsigned int settingIndex = 0;
181 const char* anchor = pb.position();
182 while (!pb.eof() && *pb.position() >=
'0' && *pb.position() <=
'9')
186 if (anchor != pb.position())
188 settingIndex = pb.data(anchor).convertUnsignedLong();
191 anchor = pb.position();
194 if (subToken ==
"uri")
196 result = assignNameAddr(name, value,
mMOHSettingsMap[settingIndex].mUri);
198 else if (subToken ==
"password")
202 else if (subToken ==
"registrationtime")
206 else if (subToken ==
"outboundproxy")
210 else if (subToken ==
"filename")
212 result = assignMusicUrl(name, value,
mMOHSettingsMap[settingIndex].mMOHFilenameUrl);
215 else if (name.
prefix(
"park") && name.
size() > 5)
217 unsigned int settingIndex = 0;
220 const char* anchor = pb.position();
221 while (!pb.eof() && *pb.position() >=
'0' && *pb.position() <=
'9')
225 if (anchor != pb.position())
227 settingIndex = pb.data(anchor).convertUnsignedLong();
230 anchor = pb.position();
233 if (subToken ==
"uri")
237 else if (subToken ==
"password")
241 else if (subToken ==
"registrationtime")
245 else if (subToken ==
"outboundproxy")
249 else if (subToken ==
"mohfilename")
251 result = assignMusicUrl(name, value,
mParkSettingsMap[settingIndex].mMOHFilenameUrl);
253 else if (subToken ==
"orbitrangestart")
257 else if (subToken ==
"numorbits")
261 else if (subToken ==
"orbitregistrationtime")
265 else if (subToken ==
"orbitpassword")
269 else if (subToken ==
"maxparktime")
274 else if(name ==
"maxparktime")
280 else if(name ==
"a" || name ==
"ipaddress")
287 else if(name ==
"d" || name ==
"dnsservers")
291 else if(name ==
"up" || name ==
"udpport")
295 else if(name ==
"tp" || name ==
"tcpport")
299 else if(name ==
"sp" || name ==
"tlsport")
303 else if(name ==
"td" || name ==
"tlsdomain")
307 else if (name ==
"cp" || name ==
"certificatepath")
311 else if(name ==
"keepalives")
313 if(value ==
"1" || value ==
"true" || value ==
"on" || value ==
"enable")
317 else if(value ==
"0" || value ==
"false" || value ==
"off" || value ==
"disable")
322 else if(name ==
"op" || name ==
"outboundproxy")
326 else if(name ==
"mediaportrangestart")
330 else if(name ==
"mediaportrangesize")
334 else if(name ==
"httpport")
338 else if(name ==
"sipxlogfilename")
342 else if(name ==
"l" || name ==
"loglevel")
346 else if(name ==
"logfilename")
350 else if(name ==
"logfilemaxbytes")
362ConfigParser::assignNameAddr(
const Data& settingName,
const Data& settingValue,
NameAddr& nameAddr)
369 nameAddr = tempNameAddr;
373 cerr <<
"Invalid " << settingName <<
" NameAddr format=" << settingValue <<
": " << e << endl;
377 else if(!settingValue.
empty())
381 NameAddr tempNameAddr(settingValue);
382 nameAddr = tempNameAddr;
386 cerr <<
"Invalid " << settingName <<
" NameAddr format=" << settingValue <<
": " << e << endl;
400 urlData = settingValue +
";repeat";
404 urlData =
"file:" + settingValue +
";repeat";
413 cerr <<
"Invalid " << settingName <<
" Uri format=" << settingValue <<
": " << e << endl;
414 cerr <<
"Using " << url <<
" instead." << endl;
415 url =
Uri(
"file:music.wav;repeat");
unsigned short mMediaPortRangeSize
resip::NameAddr mOutboundProxy
MOHSettingsMap mMOHSettingsMap
unsigned int mLogFileMaxBytes
unsigned short mMediaPortRangeStart
ParkSettingsMap mParkSettingsMap
resip::Data mCertificatePath
resip::Data mSipXLogFilename
The abstract base-class for all exceptions thrown by resip code.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
const char * c_str() const
Returns a null-terminated string representing.
char & at(size_type p)
Returns the character at the specified position.
unsigned long convertUnsignedLong() const
bool prefix(const Data &pre) const noexcept
Returns true if this Data starts with the bytes indicated by the passed-in Data.
bool empty() const noexcept
Checks whether the Data is empty.
Data & lowercase()
Converts this Data to lowercase.
size_type size() const noexcept
Returns the number of bytes in this Data.
size_type find(const Data &match, size_type start=0) const
Finds a specified sequence of bytes in this Data.
static const size_type npos
Represents an impossible position; returned to indicate failure to find.
int convertInt() const
Takes the contents of the Data and converts them to an integer.
const char * data() const noexcept
Returns a pointer to the contents of this Data.
Provides a collection of utility functions for manipulating DNS names and IP addresses and discoverin...
Represents the "name-addr" and the "addr-spec" elements in the RFC 3261 grammar.
Provides string-parsing functionality with protection from buffer overflow.
Represents the "SIP-URI" and "SIPS-URI" elements in the RFC 3261 grammar.
dcm! – add UnusedChecking(_enum) below;
bool isEqualNoCase(const Data &left, const Data &right)