fix a compiler warning and clean up the code a bit.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@37047 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.4
Matt O'Gorman 19 years ago
parent 2127a0b7e5
commit 76f85726aa

@ -143,9 +143,7 @@ static unsigned int osp_tokenformat = TOKEN_ALGO_SIGNED; /* Token format support
* \param provider OSP provider context name * \param provider OSP provider context name
* \return 1 Success, 0 Failed, -1 Error * \return 1 Success, 0 Failed, -1 Error
*/ */
static int osp_create_provider( static int osp_create_provider(struct ast_config* cfg, const char* provider)
struct ast_config* cfg, /* OSP configuration */
const char* provider) /* OSP provider context name */
{ {
int res; int res;
unsigned int t, i, j; unsigned int t, i, j;
@ -303,23 +301,9 @@ static int osp_create_provider(
psrvpoints[i] = p->srvpoints[i]; psrvpoints[i] = p->srvpoints[i];
} }
error = OSPPProviderNew( error = OSPPProviderNew(p->spcount, psrvpoints, NULL, OSP_AUDIT_URL, &privatekey, &localcert, p->cacount, pcacerts, OSP_LOCAL_VALIDATION,
p->spcount, psrvpoints, OSP_SSL_LIFETIME, p->maxconnections, OSP_HTTP_PERSISTENCE, p->retrydelay, p->retrylimit,p->timeout, OSP_CUSTOMER_ID,
NULL, OSP_DEVICE_ID, &p->handle);
OSP_AUDIT_URL,
&privatekey,
&localcert,
p->cacount, pcacerts,
OSP_LOCAL_VALIDATION,
OSP_SSL_LIFETIME,
p->maxconnections,
OSP_HTTP_PERSISTENCE,
p->retrydelay,
p->retrylimit,
p->timeout,
OSP_CUSTOMER_ID,
OSP_DEVICE_ID,
&p->handle);
if (error != OSPC_ERR_NO_ERROR) { if (error != OSPC_ERR_NO_ERROR) {
ast_log(LOG_WARNING, "OSP: Unable to create provider '%s', error '%d'\n", provider, error); ast_log(LOG_WARNING, "OSP: Unable to create provider '%s', error '%d'\n", provider, error);
free(p); free(p);
@ -354,9 +338,7 @@ static int osp_create_provider(
* \param policy OSP authentication policy, output * \param policy OSP authentication policy, output
* \return 1 Success, 0 Failed, -1 Error * \return 1 Success, 0 Failed, -1 Error
*/ */
static int osp_get_policy( static int osp_get_policy(const char* provider, int* policy)
const char* provider, /* OSP provider context name */
int* policy) /* OSP authentication policy, output */
{ {
int res = 0; int res = 0;
struct osp_provider* p; struct osp_provider* p;
@ -385,11 +367,7 @@ static int osp_get_policy(
* \param source Source of provider, output * \param source Source of provider, output
* \return 1 Success, 0 Failed, -1 Error * \return 1 Success, 0 Failed, -1 Error
*/ */
static int osp_create_transaction( static int osp_create_transaction(const char* provider, int* transaction, unsigned int sourcesize, char* source)
const char* provider, /* OSP provider context name */
int* transaction, /* OSP transaction handle, output */
unsigned int sourcesize, /* Size of source buffer, in/output */
char* source) /* Source of provider context, output */
{ {
int res = 0; int res = 0;
struct osp_provider* p; struct osp_provider* p;
@ -430,14 +408,7 @@ static int osp_create_transaction(
* \param timelimit Call duration limit, output * \param timelimit Call duration limit, output
* \return 1 Success, 0 Failed, -1 Error * \return 1 Success, 0 Failed, -1 Error
*/ */
static int osp_validate_token( static int osp_validate_token(int transaction, const char* source, const char* dest, const char* calling, const char* called, const char* token, unsigned int* timelimit)
int transaction, /* OSP transaction handle */
const char* source, /* Source of inbound call */
const char* dest, /* Destination of inbound call */
const char* calling, /* Calling number */
const char* called, /* Called number */
const char* token, /* OSP token, may be empty */
unsigned int* timelimit) /* Call duration limit, output */
{ {
int res; int res;
int tokenlen; int tokenlen;
@ -478,9 +449,7 @@ static int osp_validate_token(
* \param out Outbound duration limit * \param out Outbound duration limit
* \return min duration limit * \return min duration limit
*/ */
static unsigned int osp_choose_timelimit( static unsigned int osp_choose_timelimit(unsigned int in, unsigned int out)
unsigned int in, /* Inbound duration timelimit */
unsigned int out) /* Outbound duration timelimit */
{ {
if (in == OSP_DEF_TIMELIMIT) { if (in == OSP_DEF_TIMELIMIT) {
return out; return out;
@ -502,14 +471,7 @@ static unsigned int osp_choose_timelimit(
* \param result OSP lookup results, in/output * \param result OSP lookup results, in/output
* \return 1 Success, 0 Failed, -1 Error * \return 1 Success, 0 Failed, -1 Error
*/ */
static int osp_check_destination( static int osp_check_destination(const char* called, const char* calling, char* destination, unsigned int tokenlen, const char* token, enum OSPEFAILREASON* reason, struct osp_result* result)
const char* called, /* Called number */
const char* calling, /* Calling number */
char* destination, /* Destination IP in '[x.x.x.x]' format */
unsigned int tokenlen, /* OSP token length */
const char* token, /* OSP token */
enum OSPEFAILREASON* reason, /* Failure reason, output */
struct osp_result* result) /* OSP lookup results, in/output */
{ {
int res; int res;
OSPE_DEST_OSP_ENABLED enabled; OSPE_DEST_OSP_ENABLED enabled;
@ -578,8 +540,7 @@ static int osp_check_destination(
* \param cause Asterisk hangup cause * \param cause Asterisk hangup cause
* \return OSP TC code * \return OSP TC code
*/ */
static enum OSPEFAILREASON asterisk2osp( static enum OSPEFAILREASON asterisk2osp(int cause)
int cause) /* Asterisk hangup cause */
{ {
return (enum OSPEFAILREASON)cause; return (enum OSPEFAILREASON)cause;
} }
@ -595,23 +556,16 @@ static enum OSPEFAILREASON asterisk2osp(
* \param timelimit Call duration limit, output * \param timelimit Call duration limit, output
* \return 1 Authenricated, 0 Unauthenticated, -1 Error * \return 1 Authenricated, 0 Unauthenticated, -1 Error
*/ */
static int osp_auth( static int osp_auth(const char* provider, int* transaction, const char* source, const char* calling, const char* called, const char* token, unsigned int* timelimit)
const char* provider, /* OSP provider context name */
int* transaction, /* OSP transaction handle, output */
const char* source, /* Source of inbound call */
const char* calling, /* Calling number */
const char* called, /* Called number */
const char* token, /* OSP token, may be empty */
unsigned int* timelimit) /* Call duration limit, output */
{ {
int res; int res;
int policy; int policy = OSP_AUTH_YES;
char dest[OSP_NORSTR_SIZE]; char dest[OSP_NORSTR_SIZE];
*transaction = OSP_INVALID_HANDLE; *transaction = OSP_INVALID_HANDLE;
*timelimit = OSP_DEF_TIMELIMIT; *timelimit = OSP_DEF_TIMELIMIT;
res = osp_get_policy(provider, &policy);
if ((res = osp_get_policy(provider, &policy)) <= 0) { if (!res) {
ast_log(LOG_DEBUG, "OSP: Unabe to find OSP authentication policy\n"); ast_log(LOG_DEBUG, "OSP: Unabe to find OSP authentication policy\n");
return res; return res;
} }
@ -657,12 +611,7 @@ static int osp_auth(
* \param result Lookup results * \param result Lookup results
* \return 1 Found , 0 No route, -1 Error * \return 1 Found , 0 No route, -1 Error
*/ */
static int osp_lookup( static int osp_lookup(const char* provider, const char* srcdev, const char* calling, const char* called, struct osp_result* result)
const char* provider, /* OSP provider conttext name */
const char* srcdev, /* Source device of outbound call */
const char* calling, /* Calling number */
const char* called, /* Called number */
struct osp_result* result) /* OSP lookup results, in/output */
{ {
int res; int res;
char source[OSP_NORSTR_SIZE]; char source[OSP_NORSTR_SIZE];
@ -695,16 +644,8 @@ static int osp_lookup(
} }
result->numresults = OSP_DEF_DESTINATIONS; result->numresults = OSP_DEF_DESTINATIONS;
error = OSPPTransactionRequestAuthorisation( error = OSPPTransactionRequestAuthorisation(result->outhandle, source, srcdev, calling ? calling : "",
result->outhandle, OSPC_E164, called, OSPC_E164, NULL, 0, NULL, NULL, &result->numresults, &dummy, NULL);
source, srcdev,
calling ? calling : "", OSPC_E164,
called, OSPC_E164,
NULL,
0, NULL,
NULL,
&result->numresults,
&dummy, NULL);
if (error != OSPC_ERR_NO_ERROR) { if (error != OSPC_ERR_NO_ERROR) {
ast_log(LOG_DEBUG, "OSP: Unable to request authorization\n"); ast_log(LOG_DEBUG, "OSP: Unable to request authorization\n");
result->numresults = 0; result->numresults = 0;
@ -724,16 +665,8 @@ static int osp_lookup(
callidlen = sizeof(callid); callidlen = sizeof(callid);
tokenlen = sizeof(token); tokenlen = sizeof(token);
error = OSPPTransactionGetFirstDestination( error = OSPPTransactionGetFirstDestination(result->outhandle, 0, NULL, NULL, &result->outtimelimit, &callidlen, callid,
result->outhandle, sizeof(callednum), callednum, sizeof(callingnum), callingnum, sizeof(destination), destination, 0, NULL, &tokenlen, token);
0, NULL, NULL,
&result->outtimelimit,
&callidlen, callid,
sizeof(callednum), callednum,
sizeof(callingnum), callingnum,
sizeof(destination), destination,
0, NULL,
&tokenlen, token);
if (error != OSPC_ERR_NO_ERROR) { if (error != OSPC_ERR_NO_ERROR) {
ast_log(LOG_DEBUG, "OSP: Unable to get first route\n"); ast_log(LOG_DEBUG, "OSP: Unable to get first route\n");
result->numresults = 0; result->numresults = 0;
@ -769,17 +702,8 @@ static int osp_lookup(
while(result->numresults) { while(result->numresults) {
callidlen = sizeof(callid); callidlen = sizeof(callid);
tokenlen = sizeof(token); tokenlen = sizeof(token);
error = OSPPTransactionGetNextDestination( error = OSPPTransactionGetNextDestination(result->outhandle, reason, 0, NULL, NULL, &result->outtimelimit, &callidlen, callid,
result->outhandle, sizeof(callednum), callednum, sizeof(callingnum), callingnum, sizeof(destination), destination, 0, NULL, &tokenlen, token);
reason,
0, NULL, NULL,
&result->outtimelimit,
&callidlen, callid,
sizeof(callednum), callednum,
sizeof(callingnum), callingnum,
sizeof(destination), destination,
0, NULL,
&tokenlen, token);
if (error == OSPC_ERR_NO_ERROR) { if (error == OSPC_ERR_NO_ERROR) {
result->numresults--; result->numresults--;
result->outtimelimit = osp_choose_timelimit(result->intimelimit, result->outtimelimit); result->outtimelimit = osp_choose_timelimit(result->intimelimit, result->outtimelimit);
@ -819,9 +743,7 @@ static int osp_lookup(
* \param result Lookup results, in/output * \param result Lookup results, in/output
* \return 1 Found , 0 No route, -1 Error * \return 1 Found , 0 No route, -1 Error
*/ */
static int osp_next( static int osp_next(int cause, struct osp_result* result)
int cause, /* Asterisk hangup cuase */
struct osp_result* result) /* OSP lookup results, in/output */
{ {
int res; int res;
unsigned int callidlen; unsigned int callidlen;
@ -863,17 +785,8 @@ static int osp_next(
while(result->numresults) { while(result->numresults) {
callidlen = sizeof(callid); callidlen = sizeof(callid);
tokenlen = sizeof(token); tokenlen = sizeof(token);
error = OSPPTransactionGetNextDestination( error = OSPPTransactionGetNextDestination(result->outhandle, reason, 0, NULL, NULL, &result->outtimelimit, &callidlen,
result->outhandle, callid, sizeof(callednum), callednum, sizeof(callingnum), callingnum, sizeof(destination), destination, 0, NULL, &tokenlen, token);
reason,
0, NULL, NULL,
&result->outtimelimit,
&callidlen, callid,
sizeof(callednum), callednum,
sizeof(callingnum), callingnum,
sizeof(destination), destination,
0, NULL,
&tokenlen, token);
if (error == OSPC_ERR_NO_ERROR) { if (error == OSPC_ERR_NO_ERROR) {
result->numresults--; result->numresults--;
result->outtimelimit = osp_choose_timelimit(result->intimelimit, result->outtimelimit); result->outtimelimit = osp_choose_timelimit(result->intimelimit, result->outtimelimit);
@ -921,14 +834,7 @@ static int osp_next(
* \param release Who release first, 0 source, 1 destination * \param release Who release first, 0 source, 1 destination
* \return 1 Success, 0 Failed, -1 Error * \return 1 Success, 0 Failed, -1 Error
*/ */
static int osp_finish( static int osp_finish(int handle, int recorded, int cause, time_t start, time_t connect, time_t end, unsigned int release)
int handle, /* OSP in/outbound transaction handle */
int recorded, /* If failure reason has been recorded */
int cause, /* Asterisk hangup cause */
time_t start, /* Call start time */
time_t connect, /* Call connect time */
time_t end, /* Call end time */
unsigned int release) /* Who release first, 0 source, 1 destination */
{ {
int res; int res;
enum OSPEFAILREASON reason; enum OSPEFAILREASON reason;
@ -948,14 +854,8 @@ static int osp_finish(
OSPPTransactionRecordFailure(handle, reason); OSPPTransactionRecordFailure(handle, reason);
} }
error = OSPPTransactionReportUsage( error = OSPPTransactionReportUsage(handle, difftime(end, connect), start, end, alert, connect, isPddInfoPresent, pdd,
handle, release, confId, 0, 0, 0, 0, &dummy, NULL);
difftime(end, connect), start, end, alert, connect,
isPddInfoPresent, pdd,
release,
confId,
0, 0, 0, 0,
&dummy, NULL);
if (error == OSPC_ERR_NO_ERROR) { if (error == OSPC_ERR_NO_ERROR) {
ast_log(LOG_DEBUG, "OSP: Usage reported\n"); ast_log(LOG_DEBUG, "OSP: Usage reported\n");
res = 1; res = 1;

Loading…
Cancel
Save