Skip to content

Commit

Permalink
expose homer config via command-line params; update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
davehorton committed Feb 5, 2018
1 parent a263668 commit 9115cd8
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 26 deletions.
38 changes: 17 additions & 21 deletions drachtio.conf.xml
@@ -1,6 +1,6 @@
<drachtio>

<!-- udp port to listen on for client connections (default 8022), and shared secret used to authenticate clients -->
<!-- udp port to listen on for client connections (default 9022), and shared secret used to authenticate clients -->
<admin port="9022" secret="cymru">127.0.0.1</admin>

<!-- the server can either accept inbound connections from node apps, or make outbound requests
Expand All @@ -27,16 +27,13 @@
uriUser - the user part of the sip uri
uri - the complete sip uri
If additional information is needed, then a POST request can be used, and the full sip message
will be passed in the body of the post.
It is the responsibility of the HTTP server that receives the request to return a json response
with a top-level "action" of either "reject", "redirect", "proxy", or "route".
reject - reject the call with a specified status code
redirect = redirect the call to one or more specified sip uris
proxy - proxy the call to one or more specified sip uris
route - connect to a node application associated with the provided name:port
route - connect to a nodejs application that is listening on the specified host:port
example responses:
Expand Down Expand Up @@ -77,34 +74,34 @@
-->

<!-- comment this in and edit http url to use outbound connections
Note: currently only HTTP GET is supported as an HTTP METHOD
<request-handlers>
<request-handler sip-method="INVITE" http-method="GET">http://35.187.89.96:80</request-handler>
</request-handlers>
-->
<!-- sip configuration -->
<sip>
<contacts>
<contact>sip:*;transport=udp,tcp</contact>
<!-- local sip address to bind to. Default: 'sip:*', which means listens on port 5060 on all interfaces and transports -->
<!--
Other examples:
sip:192.168.1.100 -- listen on a specific address
sip:*;transport=tcp -- tcp connections only
sip:*:5061 -- listen on port 5061
sip:192.168.1.100 listen on a specific address
sip:*;transport=tcp tcp connections only
sip:*:5061 listen on port 5061
-->


<!-- here's how to listen for every protocol on their default ports -->
<!--
<contact>sip:*;transport=udp,tcp</contact>
<contact>sip:*:80;transport=ws</contact>
<contact>sips:*;transport=tls</contact>
<contact>sips:*:443;transport=wss</contact>
-->
<contact>sip:*:5061;transport=udp,tcp</contact>

</contacts>

<!-- if you want to change the sip stack timers
<!-- uncomment and modify these if you want to change the sip stack timers (globally)
<timers>
<t1>500</t1>
<t2>4000</t2>
Expand All @@ -113,7 +110,7 @@
</timers>
-->

<!-- if you want to send to homer
<!-- uncomment this if you send encapsulated SIP messages to homer
<capture-server port="9060" hep-version="3" id="101">127.0.0.1</capture-server>
-->

Expand Down Expand Up @@ -148,14 +145,15 @@
</spammers>
</sip>

<!-- set to true if you want to have an app receive cdr events -->
<!-- set to true if you want the server to cdr events to a connected client -->
<cdrs>false</cdrs>

<!-- logging configuration -->
<logging>

<!-- default: logging dumped to console, remove or comment out if you don't want this -->
<!-- uncomment this if you want logging dumped to console, in addition to any other log destinations
<console/>
-->

<!-- uncomment if you want logging sent to syslog (over UDP) -->
<!--
Expand All @@ -166,22 +164,20 @@
</syslog>
-->

<!-- uncomment if you want file-based logging -->
<!--
<!-- file-based logging -->
<file>
<name>/tmp/drachtioLogs//drachtio_%Y%m%d_%H%M%S-%N.log</name>
<archive>/tmp/drachtioLogs/archive</archive>
<name>/var/log/drachtio/drachtio.log</name>
<archive>/var/log/drachtio/archive</archive>
<maxSize>5120</maxSize>
<minSize>10240</minSize>
<auto-flush>true</auto-flush>
</file>
-->

<!-- sofia (internal sip library) log level, from 0 (minimal) to 9 (verbose) -->
<sofia-loglevel>8</sofia-loglevel>
<sofia-loglevel>3</sofia-loglevel>

<!-- general process log level: notice, warning, error, info, debug. Default: info -->
<loglevel>debug</loglevel>
<loglevel>info</loglevel>
</logging>

</drachtio>
File renamed without changes.
54 changes: 49 additions & 5 deletions src/controller.cpp
Expand Up @@ -65,6 +65,7 @@ THE SOFTWARE.
#include <sofia-sip/sip_util.h>

#define DEFAULT_CONFIG_FILENAME "/etc/drachtio.conf.xml"
#define DEFAULT_HOMER_PORT (9060)
#define MAXLOGLEN (8192)
/* from sofia */
#define MSG_SEPARATOR \
Expand Down Expand Up @@ -262,7 +263,8 @@ namespace drachtio {

DrachtioController::DrachtioController( int argc, char* argv[] ) : m_bDaemonize(false), m_bLoggingInitialized(false),
m_configFilename(DEFAULT_CONFIG_FILENAME), m_adminPort(0), m_bNoConfig(false),
m_current_severity_threshold(log_none), m_nSofiaLoglevel(-1), m_bIsOutbound(false), m_bConsoleLogging(false) {
m_current_severity_threshold(log_none), m_nSofiaLoglevel(-1), m_bIsOutbound(false), m_bConsoleLogging(false),
m_nHomerPort(0), m_nHomerId(0) {

if( !parseCmdArgs( argc, argv ) ) {
usage() ;
Expand Down Expand Up @@ -364,13 +366,15 @@ namespace drachtio {
{"loglevel", required_argument, 0, 'l'},
{"sofia-loglevel", required_argument, 0, 's'},
{"stdout", no_argument, 0, 'b'},
{"homer", required_argument, 0, 'y'},
{"homer-id", required_argument, 0, 'z'},
{"version", no_argument, 0, 'v'},
{0, 0, 0, 0}
};
/* getopt_long stores the option index here. */
int option_index = 0;

c = getopt_long (argc, argv, "f:i:p:c:",
c = getopt_long (argc, argv, "a:c:f:hi:l:m:p:n:u:vx:y:z:",
long_options, &option_index);

/* Detect the end of the options. */
Expand Down Expand Up @@ -480,6 +484,33 @@ namespace drachtio {
m_adminPort = ::atoi( port.c_str() ) ;
break;

case 'y':
{
m_nHomerPort = DEFAULT_HOMER_PORT;
vector<string>strs;
boost::split(strs, optarg, boost::is_any_of(":"));
if(strs.size() > 2) {
cerr << "invalid homer address: " << optarg << endl ;
return false ;
}
m_strHomerAddress = strs[0];
if( 2 == strs.size()) m_nHomerPort = boost::lexical_cast<uint32_t>(strs[1]);
}
break;

case 'z':
try {
m_nHomerId = boost::lexical_cast<uint32_t>(optarg);
} catch(boost::bad_lexical_cast& err) {
cerr << "--homer-id must be a positive 32-bit integer" << endl;
return false;
}
if(0 == m_nHomerId) {
cerr << "--homer-id must be a positive 32-bit integer" << endl;
return false;
}
break;

case 'v':
cout << DRACHTIO_VERSION << endl ;
exit(0) ;
Expand All @@ -493,6 +524,11 @@ namespace drachtio {
}
}

if(!m_strHomerAddress.empty() && 0 == m_nHomerId) {
cerr << "--homer-id is required to specify an agent id when using --homer" << endl;
return false;
}

if( !contact.empty() ) {
boost::shared_ptr<SipTransport> p = boost::make_shared<SipTransport>(contact, localNet, publicAddress);
for( std::vector<string>::const_iterator it = vecDnsNames.begin(); it != vecDnsNames.end(); ++it) {
Expand Down Expand Up @@ -525,14 +561,17 @@ namespace drachtio {
cerr << "-c, --contact Sip contact url to bind to (see /etc/drachtio.conf.xml for examples)" << endl ;
cerr << " --dns-name specifies a DNS name that resolves to the local host, if any" << endl ;
cerr << "-f, --file Path to configuration file (default /etc/drachtio.conf.xml)" << endl ;
cerr << " --homer ip:port of homer/sipcapture agent" << endl ;
cerr << " --homer-id homer agent id to use in HEP messages to identify this server" << endl ;
cerr << " --http-handler http(s) URL to optionally send routing request to for new incoming sip request" << endl ;
cerr << " --http-method method to use with http-handler: GET (default) or POST" << endl ;
cerr << " --loglevel Log level (choices: notice, error, warning, info, debug)" << endl ;
cerr << "-l --loglevel Log level (choices: notice, error, warning, info, debug)" << endl ;
cerr << " --local-net CIDR for local subnet (e.g. \"10.132.0.0/20\")" << endl ;
cerr << "-p, --port TCP port to listen on for application connections (default 9022)" << endl ;
cerr << " --sofia-loglevel Log level of internal sip stack (choices: 0-9)" << endl ;
cerr << " --external-ip External IP address to use in SIP messaging" << endl ;
cerr << " --stdout Log to standard output as well as any configured log destinations" << endl ;
cerr << "-v --version Print version and exit" << endl ;
}

void DrachtioController::daemonize() {
Expand Down Expand Up @@ -752,7 +791,12 @@ namespace drachtio {
uint32_t captureId ;
unsigned int hepVersion;
unsigned int capturePort ;
if (m_Config->getCaptureServer(captureServer, capturePort, captureId, hepVersion)) {
if (!m_strHomerAddress.empty()) {
captureString = "udp:" + m_strHomerAddress + ":" + boost::lexical_cast<std::string>(m_nHomerPort) +
";hep=3;capture_id=" + boost::lexical_cast<std::string>(m_nHomerId);
DR_LOG(log_notice) << "DrachtioController::run - sipcapture/Homer enabled: " << captureString;
}
else if (m_Config->getCaptureServer(captureServer, capturePort, captureId, hepVersion)) {
if (hepVersion < 1 || hepVersion > 3) {
DR_LOG(log_error) << "DrachtioController::run invalid hep-version " << hepVersion <<
"; must be between 1 and 3 inclusive";
Expand All @@ -761,7 +805,7 @@ namespace drachtio {
captureString = "udp:" + captureServer + ":" + boost::lexical_cast<std::string>(capturePort) +
";hep=" + boost::lexical_cast<std::string>(hepVersion) +
";capture_id=" + boost::lexical_cast<std::string>(captureId);
DR_LOG(log_notice) << "DrachtioController::run - capturing to " << captureString;
DR_LOG(log_notice) << "DrachtioController::run - sipcapture/Homer enabled: " << captureString;
}

}
Expand Down
3 changes: 3 additions & 0 deletions src/controller.hpp
Expand Up @@ -214,6 +214,9 @@ namespace drachtio {

severity_levels m_current_severity_threshold ;
int m_nSofiaLoglevel ;
string m_strHomerAddress;
unsigned int m_nHomerPort;
uint32_t m_nHomerId;

shared_ptr<ClientController> m_pClientController ;
shared_ptr<RequestHandler> m_pRequestHandler ;
Expand Down

0 comments on commit 9115cd8

Please sign in to comment.