|
|
|
@ -182,25 +182,26 @@ static int osp_create_provider(
|
|
|
|
|
struct ast_config* cfg,
|
|
|
|
|
const char* provider)
|
|
|
|
|
{
|
|
|
|
|
int res;
|
|
|
|
|
unsigned int t, i, j;
|
|
|
|
|
struct osp_provider* p;
|
|
|
|
|
int res = 0;
|
|
|
|
|
struct ast_variable* v;
|
|
|
|
|
struct osp_provider* p;
|
|
|
|
|
OSPTPRIVATEKEY privatekey;
|
|
|
|
|
OSPTCERT localcert;
|
|
|
|
|
OSPT_CERT localcert;
|
|
|
|
|
OSPT_CERT cacerts[OSP_MAX_CERTS];
|
|
|
|
|
const OSPT_CERT* pcacerts[OSP_MAX_CERTS];
|
|
|
|
|
const char* psrvpoints[OSP_MAX_SRVS];
|
|
|
|
|
OSPTCERT cacerts[OSP_MAX_CERTS];
|
|
|
|
|
const OSPTCERT* pcacerts[OSP_MAX_CERTS];
|
|
|
|
|
int error = OSPC_ERR_NO_ERROR;
|
|
|
|
|
int t, i, j, error = OSPC_ERR_NO_ERROR;
|
|
|
|
|
|
|
|
|
|
if (!(p = ast_calloc(1, sizeof(*p)))) {
|
|
|
|
|
ast_log(LOG_ERROR, "Out of memory\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ast_calloc has set 0 in p */
|
|
|
|
|
ast_copy_string(p->name, provider, sizeof(p->name));
|
|
|
|
|
snprintf(p->privatekey, sizeof(p->privatekey), "%s/%s-privatekey.pem", ast_config_AST_KEY_DIR, provider);
|
|
|
|
|
snprintf(p->localcert, sizeof(p->localcert), "%s/%s-localcert.pem", ast_config_AST_KEY_DIR, provider);
|
|
|
|
|
snprintf(p->cacerts[0], sizeof(p->cacerts[0]), "%s/%s-cacert_0.pem", ast_config_AST_KEY_DIR, provider);
|
|
|
|
|
p->maxconnections = OSP_DEF_MAXCONNECTIONS;
|
|
|
|
|
p->retrydelay = OSP_DEF_RETRYDELAY;
|
|
|
|
|
p->retrylimit = OSP_DEF_RETRYLIMIT;
|
|
|
|
@ -530,9 +531,9 @@ static int osp_validate_token(
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
calling ? calling : "",
|
|
|
|
|
OSPC_E164,
|
|
|
|
|
OSPC_NFORMAT_E164,
|
|
|
|
|
called,
|
|
|
|
|
OSPC_E164,
|
|
|
|
|
OSPC_NFORMAT_E164,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
tokenlen,
|
|
|
|
@ -543,7 +544,7 @@ static int osp_validate_token(
|
|
|
|
|
NULL,
|
|
|
|
|
osp_tokenformat);
|
|
|
|
|
if (error != OSPC_ERR_NO_ERROR) {
|
|
|
|
|
ast_debug(1, "OSP: Unable to validate inbound token\n");
|
|
|
|
|
ast_debug(1, "OSP: Unable to validate inbound token, error '%d'\n", error);
|
|
|
|
|
res = -1;
|
|
|
|
|
} else if (authorised) {
|
|
|
|
|
ast_debug(1, "OSP: Authorised\n");
|
|
|
|
@ -594,12 +595,12 @@ static int osp_check_destination(
|
|
|
|
|
char* destination,
|
|
|
|
|
unsigned int tokenlen,
|
|
|
|
|
const char* token,
|
|
|
|
|
enum OSPEFAILREASON* reason,
|
|
|
|
|
OSPEFAILREASON* reason,
|
|
|
|
|
struct osp_result* result)
|
|
|
|
|
{
|
|
|
|
|
int res;
|
|
|
|
|
OSPE_DEST_OSP_ENABLED enabled;
|
|
|
|
|
OSPE_DEST_PROT protocol;
|
|
|
|
|
OSPE_DEST_OSPENABLED enabled;
|
|
|
|
|
OSPE_DEST_PROTOCOL protocol;
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
if (strlen(destination) <= 2) {
|
|
|
|
@ -614,7 +615,7 @@ static int osp_check_destination(
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (enabled == OSPE_OSP_FALSE) {
|
|
|
|
|
if (enabled == OSPC_DOSP_FALSE) {
|
|
|
|
|
result->token[0] = '\0';
|
|
|
|
|
} else {
|
|
|
|
|
ast_base64encode(result->token, (const unsigned char*)token, tokenlen, sizeof(result->token) - 1);
|
|
|
|
@ -637,29 +638,29 @@ static int osp_check_destination(
|
|
|
|
|
/* Strip leading and trailing brackets */
|
|
|
|
|
destination[strlen(destination) - 1] = '\0';
|
|
|
|
|
switch(protocol) {
|
|
|
|
|
case OSPE_DEST_PROT_H323_SETUP:
|
|
|
|
|
case OSPC_DPROT_Q931:
|
|
|
|
|
ast_debug(1, "OSP: protocol '%s'\n", OSP_PROT_H323);
|
|
|
|
|
ast_copy_string(result->tech, OSP_TECH_H323, sizeof(result->tech));
|
|
|
|
|
ast_copy_string(result->dest, destination + 1, sizeof(result->dest));
|
|
|
|
|
ast_copy_string(result->called, called, sizeof(result->called));
|
|
|
|
|
ast_copy_string(result->calling, calling, sizeof(result->calling));
|
|
|
|
|
break;
|
|
|
|
|
case OSPE_DEST_PROT_SIP:
|
|
|
|
|
case OSPC_DPROT_SIP:
|
|
|
|
|
ast_debug(1, "OSP: protocol '%s'\n", OSP_PROT_SIP);
|
|
|
|
|
ast_copy_string(result->tech, OSP_TECH_SIP, sizeof(result->tech));
|
|
|
|
|
ast_copy_string(result->dest, destination + 1, sizeof(result->dest));
|
|
|
|
|
ast_copy_string(result->called, called, sizeof(result->called));
|
|
|
|
|
ast_copy_string(result->calling, calling, sizeof(result->calling));
|
|
|
|
|
break;
|
|
|
|
|
case OSPE_DEST_PROT_IAX:
|
|
|
|
|
case OSPC_DPROT_IAX:
|
|
|
|
|
ast_debug(1, "OSP: protocol '%s'\n", OSP_PROT_IAX);
|
|
|
|
|
ast_copy_string(result->tech, OSP_TECH_IAX, sizeof(result->tech));
|
|
|
|
|
ast_copy_string(result->dest, destination + 1, sizeof(result->dest));
|
|
|
|
|
ast_copy_string(result->called, called, sizeof(result->called));
|
|
|
|
|
ast_copy_string(result->calling, calling, sizeof(result->calling));
|
|
|
|
|
break;
|
|
|
|
|
case OSPE_DEST_PROT_UNDEFINED:
|
|
|
|
|
case OSPE_DEST_PROT_UNKNOWN:
|
|
|
|
|
case OSPC_DPROT_UNDEFINED:
|
|
|
|
|
case OSPC_DPROT_UNKNOWN:
|
|
|
|
|
ast_debug(1, "OSP: unknown/undefined protocol '%d'\n", protocol);
|
|
|
|
|
ast_debug(1, "OSP: use default protocol '%s'\n", provider->defaultprotocol);
|
|
|
|
|
|
|
|
|
@ -668,7 +669,7 @@ static int osp_check_destination(
|
|
|
|
|
ast_copy_string(result->called, called, sizeof(result->called));
|
|
|
|
|
ast_copy_string(result->calling, calling, sizeof(result->calling));
|
|
|
|
|
break;
|
|
|
|
|
case OSPE_DEST_PROT_H323_LRQ:
|
|
|
|
|
case OSPC_DPROT_LRQ:
|
|
|
|
|
default:
|
|
|
|
|
ast_log(LOG_WARNING, "OSP: unsupported protocol '%d'\n", protocol);
|
|
|
|
|
*reason = OSPC_FAIL_PROTOCOL_ERROR;
|
|
|
|
@ -686,10 +687,10 @@ static int osp_check_destination(
|
|
|
|
|
* \param cause Asterisk hangup cause
|
|
|
|
|
* \return OSP TC code
|
|
|
|
|
*/
|
|
|
|
|
static enum OSPEFAILREASON asterisk2osp(
|
|
|
|
|
static OSPEFAILREASON asterisk2osp(
|
|
|
|
|
int cause)
|
|
|
|
|
{
|
|
|
|
|
return (enum OSPEFAILREASON)cause;
|
|
|
|
|
return (OSPEFAILREASON)cause;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@ -873,9 +874,9 @@ static int osp_lookup(
|
|
|
|
|
unsigned int i, type;
|
|
|
|
|
struct osp_callid callid;
|
|
|
|
|
unsigned int callidnum;
|
|
|
|
|
OSPTCALLID* callids[OSP_CALLID_MAXNUM];
|
|
|
|
|
OSPT_CALL_ID* callids[OSP_CALLID_MAXNUM];
|
|
|
|
|
unsigned int dummy = 0;
|
|
|
|
|
enum OSPEFAILREASON reason;
|
|
|
|
|
OSPEFAILREASON reason;
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
result->outhandle = OSP_INVALID_HANDLE;
|
|
|
|
@ -923,9 +924,9 @@ static int osp_lookup(
|
|
|
|
|
src,
|
|
|
|
|
dev,
|
|
|
|
|
calling ? calling : "",
|
|
|
|
|
OSPC_E164,
|
|
|
|
|
OSPC_NFORMAT_E164,
|
|
|
|
|
called,
|
|
|
|
|
OSPC_E164,
|
|
|
|
|
OSPC_NFORMAT_E164,
|
|
|
|
|
NULL,
|
|
|
|
|
callidnum,
|
|
|
|
|
callids,
|
|
|
|
@ -939,7 +940,7 @@ static int osp_lookup(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error != OSPC_ERR_NO_ERROR) {
|
|
|
|
|
ast_debug(1, "OSP: Unable to request authorization\n");
|
|
|
|
|
ast_debug(1, "OSP: Unable to request authorization, error '%d'\n", error);
|
|
|
|
|
result->numresults = 0;
|
|
|
|
|
if (result->inhandle != OSP_INVALID_HANDLE) {
|
|
|
|
|
OSPPTransactionRecordFailure(result->inhandle, OSPC_FAIL_NORMAL_UNSPECIFIED);
|
|
|
|
@ -976,7 +977,7 @@ static int osp_lookup(
|
|
|
|
|
&tokenlen,
|
|
|
|
|
token);
|
|
|
|
|
if (error != OSPC_ERR_NO_ERROR) {
|
|
|
|
|
ast_debug(1, "OSP: Unable to get first route\n");
|
|
|
|
|
ast_debug(1, "OSP: Unable to get first route, error '%d'\n", error);
|
|
|
|
|
result->numresults = 0;
|
|
|
|
|
result->outtimelimit = OSP_DEF_TIMELIMIT;
|
|
|
|
|
if (result->inhandle != OSP_INVALID_HANDLE) {
|
|
|
|
@ -1082,7 +1083,7 @@ static int osp_next(
|
|
|
|
|
char destination[OSP_NORSTR_SIZE];
|
|
|
|
|
unsigned int tokenlen;
|
|
|
|
|
char token[OSP_TOKSTR_SIZE];
|
|
|
|
|
enum OSPEFAILREASON reason;
|
|
|
|
|
OSPEFAILREASON reason;
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
result->tech[0] = '\0';
|
|
|
|
@ -1193,12 +1194,12 @@ static int osp_finish(
|
|
|
|
|
int recorded,
|
|
|
|
|
int cause,
|
|
|
|
|
time_t start,
|
|
|
|
|
time_t connect_time,
|
|
|
|
|
time_t connect,
|
|
|
|
|
time_t end,
|
|
|
|
|
unsigned int release)
|
|
|
|
|
{
|
|
|
|
|
int res;
|
|
|
|
|
enum OSPEFAILREASON reason;
|
|
|
|
|
OSPEFAILREASON reason;
|
|
|
|
|
time_t alert = 0;
|
|
|
|
|
unsigned isPddInfoPresent = 0;
|
|
|
|
|
unsigned pdd = 0;
|
|
|
|
@ -1216,19 +1217,19 @@ static int osp_finish(
|
|
|
|
|
|
|
|
|
|
error = OSPPTransactionReportUsage(
|
|
|
|
|
handle,
|
|
|
|
|
difftime(end, connect_time),
|
|
|
|
|
difftime(end, connect),
|
|
|
|
|
start,
|
|
|
|
|
end,
|
|
|
|
|
alert,
|
|
|
|
|
connect_time,
|
|
|
|
|
connect,
|
|
|
|
|
isPddInfoPresent,
|
|
|
|
|
pdd,
|
|
|
|
|
release,
|
|
|
|
|
(unsigned char*)"",
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
-1,
|
|
|
|
|
-1,
|
|
|
|
|
-1,
|
|
|
|
|
-1,
|
|
|
|
|
&dummy,
|
|
|
|
|
NULL);
|
|
|
|
|
if (error == OSPC_ERR_NO_ERROR) {
|
|
|
|
@ -1340,7 +1341,7 @@ static int osplookup_exec(
|
|
|
|
|
struct varshead* headp;
|
|
|
|
|
struct ast_var_t* current;
|
|
|
|
|
const char* srcdev = "";
|
|
|
|
|
const char* netid = "";
|
|
|
|
|
const char* snetid = "";
|
|
|
|
|
char buffer[OSP_TOKSTR_SIZE];
|
|
|
|
|
unsigned int callidtypes = OSP_CALLID_UNDEFINED;
|
|
|
|
|
struct osp_result result;
|
|
|
|
@ -1399,14 +1400,14 @@ static int osplookup_exec(
|
|
|
|
|
result.intimelimit = OSP_DEF_TIMELIMIT;
|
|
|
|
|
}
|
|
|
|
|
} else if (!strcasecmp(ast_var_name(current), "OSPINNETWORKID")) {
|
|
|
|
|
netid = ast_var_value(current);
|
|
|
|
|
snetid = ast_var_value(current);
|
|
|
|
|
} else if (!strcasecmp(ast_var_name(current), "OSPPEERIP")) {
|
|
|
|
|
srcdev = ast_var_value(current);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ast_debug(1, "OSPLookup: OSPINHANDLE '%d'\n", result.inhandle);
|
|
|
|
|
ast_debug(1, "OSPLookup: OSPINTIMELIMIT '%d'\n", result.intimelimit);
|
|
|
|
|
ast_debug(1, "OSPLookup: OSPINNETWORKID '%s'\n", netid);
|
|
|
|
|
ast_debug(1, "OSPLookup: OSPINNETWORKID '%s'\n", snetid);
|
|
|
|
|
ast_debug(1, "OSPLookup: source device '%s'\n", srcdev);
|
|
|
|
|
|
|
|
|
|
if ((cres = ast_autoservice_start(chan)) < 0) {
|
|
|
|
@ -1664,7 +1665,7 @@ static int ospfinished_exec(
|
|
|
|
|
int inhandle = OSP_INVALID_HANDLE;
|
|
|
|
|
int outhandle = OSP_INVALID_HANDLE;
|
|
|
|
|
int recorded = 0;
|
|
|
|
|
time_t start, connect_time, end;
|
|
|
|
|
time_t start, connect, end;
|
|
|
|
|
unsigned int release;
|
|
|
|
|
char buffer[OSP_INTSTR_SIZE];
|
|
|
|
|
const char* status;
|
|
|
|
@ -1713,24 +1714,24 @@ static int ospfinished_exec(
|
|
|
|
|
|
|
|
|
|
if (chan->cdr) {
|
|
|
|
|
start = chan->cdr->start.tv_sec;
|
|
|
|
|
connect_time = chan->cdr->answer.tv_sec;
|
|
|
|
|
if (connect_time) {
|
|
|
|
|
connect = chan->cdr->answer.tv_sec;
|
|
|
|
|
if (connect) {
|
|
|
|
|
end = time(NULL);
|
|
|
|
|
} else {
|
|
|
|
|
end = connect_time;
|
|
|
|
|
end = connect;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
start = 0;
|
|
|
|
|
connect_time = 0;
|
|
|
|
|
connect = 0;
|
|
|
|
|
end = 0;
|
|
|
|
|
}
|
|
|
|
|
ast_debug(1, "OSPFinish: start '%ld'\n", start);
|
|
|
|
|
ast_debug(1, "OSPFinish: connect '%ld'\n", connect_time);
|
|
|
|
|
ast_debug(1, "OSPFinish: connect '%ld'\n", connect);
|
|
|
|
|
ast_debug(1, "OSPFinish: end '%ld'\n", end);
|
|
|
|
|
|
|
|
|
|
release = ast_check_hangup(chan) ? 0 : 1;
|
|
|
|
|
|
|
|
|
|
if (osp_finish(outhandle, recorded, cause, start, connect_time, end, release) <= 0) {
|
|
|
|
|
if (osp_finish(outhandle, recorded, cause, start, connect, end, release) <= 0) {
|
|
|
|
|
ast_debug(1, "OSPFinish: Unable to report usage for outbound call\n");
|
|
|
|
|
}
|
|
|
|
|
switch (cause) {
|
|
|
|
@ -1740,7 +1741,7 @@ static int ospfinished_exec(
|
|
|
|
|
cause = AST_CAUSE_NO_ROUTE_DESTINATION;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (osp_finish(inhandle, recorded, cause, start, connect_time, end, release) <= 0) {
|
|
|
|
|
if (osp_finish(inhandle, recorded, cause, start, connect, end, release) <= 0) {
|
|
|
|
|
ast_debug(1, "OSPFinish: Unable to report usage for inbound call\n");
|
|
|
|
|
}
|
|
|
|
|
snprintf(buffer, sizeof(buffer), "%d", OSP_INVALID_HANDLE);
|
|
|
|
|