[asterisk-commits] transnexus: trunk r236756 - in /trunk: ./ apps/ configs/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Dec 29 04:59:58 CST 2009


Author: transnexus
Date: Tue Dec 29 04:59:55 2009
New Revision: 236756

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=236756
Log:
1. Updated for OSP Toolkit 3.6.0.
2. Added service type ported number query.
3. Formated code.

Modified:
    trunk/apps/app_osplookup.c
    trunk/configs/osp.conf.sample
    trunk/configure.ac

Modified: trunk/apps/app_osplookup.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_osplookup.c?view=diff&rev=236756&r1=236755&r2=236756
==============================================================================
--- trunk/apps/app_osplookup.c (original)
+++ trunk/apps/app_osplookup.c Tue Dec 29 04:59:55 2009
@@ -206,54 +206,65 @@
  ***/
 
 /* OSP Buffer Sizes */
-#define OSP_INTSTR_SIZE		((unsigned int)16)		/* OSP signed/unsigned int string buffer size */
-#define OSP_NORSTR_SIZE		((unsigned int)256)		/* OSP normal string buffer size */
-#define OSP_KEYSTR_SIZE		((unsigned int)1024)	/* OSP certificate string buffer size */
-#define OSP_TOKSTR_SIZE		((unsigned int)4096)	/* OSP token string buffer size */
-#define OSP_TECHSTR_SIZE	((unsigned int)32)		/* OSP signed/unsigned int string buffer size */
-#define OSP_UUID_SIZE		((unsigned int)16)		/* UUID size */
-#define OSP_UUIDSTR_SIZE	((unsigned int)36)		/* UUID string size */
-#define OSP_QOSSTR_SIZE		((unsigned int)1024)	/* QoS string buffer size */
+#define OSP_SIZE_INTSTR		((unsigned int)16)			/* OSP signed/unsigned int string buffer size */
+#define OSP_SIZE_NORSTR		((unsigned int)256)			/* OSP normal string buffer size */
+#define OSP_SIZE_KEYSTR		((unsigned int)1024)		/* OSP certificate string buffer size */
+#define OSP_SIZE_TOKSTR		((unsigned int)4096)		/* OSP token string buffer size */
+#define OSP_SIZE_TECHSTR	((unsigned int)32)			/* OSP signed/unsigned int string buffer size */
+#define OSP_SIZE_UUID		((unsigned int)16)			/* UUID size */
+#define OSP_SIZE_UUIDSTR	((unsigned int)36)			/* UUID string size */
+#define OSP_SIZE_QOSSTR		((unsigned int)1024)		/* QoS string buffer size */
+
+/* Call ID Type*/
+#define OSP_CALLID_UNDEF	((unsigned int)0)			/* Undefined */
+#define OSP_CALLID_SIP		((unsigned int)(1 << 0))	/* SIP */
+#define OSP_CALLID_H323		((unsigned int)(1 << 1))	/* H.323 */
+#define OSP_CALLID_IAX		((unsigned int)(1 << 2))	/* IAX2 */
+#define OSP_CALLID_MAXNUM	((unsigned int)3)			/* Max number of call ID types */
+
+/* OSP Supported Destination Protocols */
+#define OSP_PROT_SIP		((const char*)"SIP")		/* SIP protocol name */
+#define OSP_PROT_H323		((const char*)"H323")		/* H.323 Q.931 protocol name*/
+#define OSP_PROT_IAX		((const char*)"IAX")		/* IAX2 protocol name */
+#define OSP_PROT_SKYPE		((const char*)"SKYPE")		/* Skype protocol name */
+
+/* OSP supported Destination Tech */
+#define OSP_TECH_SIP		((const char*)"SIP")		/* SIP tech name */
+#define OSP_TECH_H323		((const char*)"H323")		/* OH323 tech name */
+#define OSP_TECH_IAX		((const char*)"IAX2")		/* IAX2 tech name */
+#define OSP_TECH_SKYPE		((const char*)"SKYPE")		/* Skype tech name */
+
+/* SIP OSP header field name */
+#define OSP_SIP_HEADER		((const char*)"P-OSP-Auth-Token")
 
 /* OSP Authentication Policy */
 enum osp_authpolicy {
-	OSP_AUTH_NO,		/* Accept any call */
+	OSP_AUTH_NO = 0,	/* Accept any call */
 	OSP_AUTH_YES,		/* Accept call with valid OSP token or without OSP token */
-	OSP_AUTH_EXCLUSIVE	/* Only accept call with valid OSP token */
+	OSP_AUTH_EXC		/* Only accept call with valid OSP token */
 };
 
-/* Call ID type*/
-#define OSP_CALLID_UNDEFINED	((unsigned int)0)			/* UNDEFINED */
-#define OSP_CALLID_SIP			((unsigned int)(1 << 0))	/* SIP */
-#define OSP_CALLID_H323			((unsigned int)(1 << 1))	/* H.323 */
-#define OSP_CALLID_IAX			((unsigned int)(1 << 2))	/* IAX2 */
-#define OSP_CALLID_MAXNUM		((unsigned int)3)			/* Max number of call ID type */
-
-/* OSP Supported Destination Protocols */
-#define OSP_PROT_SIP			((char*)"SIP")				/* SIP protocol name */
-#define OSP_PROT_H323			((char*)"H323")				/* H323 Q931 protocol name*/
-#define OSP_PROT_IAX			((char*)"IAX")				/* IAX protocol name */
-#define OSP_PROT_SKYPE			((char*)"SKYPE")			/* Skype protocol name */
-
-/* OSP supported Destination Tech */
-#define OSP_TECH_SIP			((char*)"SIP")				/* SIP tech name */
-#define OSP_TECH_H323			((char*)"H323")				/* OH323 tech name */
-#define OSP_TECH_IAX			((char*)"IAX2")				/* IAX2 tech name */
-#define OSP_TECH_SKYPE			((char*)"SKYPE")			/* Skype tech name */
-
-/* SIP OSP header field name */
-#define OSP_SIP_HEADER			((char*)"P-OSP-Auth-Token: ")
+/* OSP Service Type */
+enum osp_srvtype {
+	OSP_SRV_VOICE = 0,	/* Normal voice service */
+	OSP_SRV_NPQUERY		/* Ported number query service */
+};
 
 /* OSP Constants */
+#define OSP_OK					((int)1)					/* OSP function call successful */
+#define OSP_FAILED				((int)0)					/* OSP function call failed */
+#define OSP_ERROR				((int)-1)					/* OSP function call error */
+#define OSP_AST_OK				((int)0)					/* Asterisk function call successful */
+#define OSP_AST_ERROR			((int)-1)					/* Asterisk function call error */
 #define OSP_INVALID_HANDLE		((int)-1)					/* Invalid OSP handle, provider, transaction etc. */
 #define OSP_CONFIG_FILE			((const char*)"osp.conf")	/* OSP configuration file name */
 #define OSP_GENERAL_CAT			((const char*)"general")	/* OSP global configuration context name */
 #define OSP_DEF_PROVIDER		((const char*)"default")	/* OSP default provider context name */
 #define OSP_MAX_CERTS			((unsigned int)10)			/* OSP max number of cacerts */
-#define OSP_MAX_SRVS			((unsigned int)10)			/* OSP max number of service points */
-#define OSP_DEF_MAXCONNECTIONS	((unsigned int)20)			/* OSP default max_connections */
-#define OSP_MIN_MAXCONNECTIONS	((unsigned int)1)			/* OSP min max_connections */
-#define OSP_MAX_MAXCONNECTIONS	((unsigned int)1000)		/* OSP max max_connections */
+#define OSP_MAX_SPOINTS			((unsigned int)10)			/* OSP max number of service points */
+#define OSP_DEF_MAXCONNECT		((unsigned int)20)			/* OSP default max_connections */
+#define OSP_MIN_MAXCONNECT		((unsigned int)1)			/* OSP min max_connections */
+#define OSP_MAX_MAXCONNECT		((unsigned int)1000)		/* OSP max max_connections */
 #define OSP_DEF_RETRYDELAY		((unsigned int)0)			/* OSP default retry delay */
 #define OSP_MIN_RETRYDELAY		((unsigned int)0)			/* OSP min retry delay */
 #define OSP_MAX_RETRYDELAY		((unsigned int)10)			/* OSP max retry delay */
@@ -263,55 +274,59 @@
 #define OSP_DEF_TIMEOUT			((unsigned int)500)			/* OSP default timeout in ms */
 #define OSP_MIN_TIMEOUT			((unsigned int)200)			/* OSP min timeout in ms */
 #define OSP_MAX_TIMEOUT			((unsigned int)10000)		/* OSP max timeout in ms */
-#define OSP_DEF_AUTHPOLICY		((enum osp_authpolicy)OSP_AUTH_YES)
+#define OSP_DEF_AUTHPOLICY		OSP_AUTH_YES				/* OSP default auth policy, yes */
 #define OSP_AUDIT_URL			((const char*)"localhost")	/* OSP default Audit URL */
 #define OSP_LOCAL_VALIDATION	((int)1)					/* Validate OSP token locally */
 #define OSP_SSL_LIFETIME		((unsigned int)300)			/* SSL life time, in seconds */
 #define OSP_HTTP_PERSISTENCE	((int)1)					/* In seconds */
 #define OSP_CUSTOMER_ID			((const char*)"")			/* OSP customer ID */
 #define OSP_DEVICE_ID			((const char*)"")			/* OSP device ID */
-#define OSP_DEF_DESTINATIONS	((unsigned int)5)			/* OSP default max number of destinations */
+#define OSP_DEF_MAXDESTS		((unsigned int)5)			/* OSP default max number of destinations */
 #define OSP_DEF_TIMELIMIT		((unsigned int)0)			/* OSP default duration limit, no limit */
 #define OSP_DEF_PROTOCOL		OSP_PROT_SIP				/* OSP default destination protocol, SIP */
+#define OSP_DEF_SRVTYPE			OSP_SRV_VOICE				/* OSP default service type, voice */
 #define OSP_MAX_CUSTOMINFO		((unsigned int)8)			/* OSP max number of custom info */
+#define OSP_DEF_INTSTATS		((int)-1)					/* OSP default int statistic */
+#define OSP_DEF_FLOATSTATS		((float)-1)					/* OSP default float statistic */
 
 /* OSP Provider */
 struct osp_provider {
-	char name[OSP_NORSTR_SIZE];						/* OSP provider context name */
-	char privatekey[OSP_NORSTR_SIZE];				/* OSP private key file name */
-	char localcert[OSP_NORSTR_SIZE];				/* OSP local cert file name */
-	unsigned int cacount;							/* Number of cacerts */
-	char cacerts[OSP_MAX_CERTS][OSP_NORSTR_SIZE];	/* Cacert file names */
-	unsigned int spcount;							/* Number of service points */
-	char srvpoints[OSP_MAX_SRVS][OSP_NORSTR_SIZE];	/* Service point URLs */
-	int maxconnections;								/* Max number of connections */
-	int retrydelay;									/* Retry delay */
-	int retrylimit;									/* Retry limit */
-	int timeout;									/* Timeout in ms */
-	char source[OSP_NORSTR_SIZE];					/* IP of self */
+	OSPTPROVHANDLE handle;							/* OSP provider handle */
+	char name[OSP_SIZE_NORSTR];						/* OSP provider context name */
+	char privatekey[OSP_SIZE_NORSTR];				/* OSP private key file name */
+	char localcert[OSP_SIZE_NORSTR];				/* OSP local cert file name */
+	unsigned int canum;								/* Number of cacerts */
+	char cacerts[OSP_MAX_CERTS][OSP_SIZE_NORSTR];	/* Cacert file names */
+	unsigned int spnum;								/* Number of service points */
+	char spoints[OSP_MAX_SPOINTS][OSP_SIZE_NORSTR];	/* Service point URLs */
+	unsigned int maxconnect;						/* Max number of connections */
+	unsigned int retrydelay;						/* Retry delay */
+	unsigned int retrylimit;						/* Retry limit */
+	unsigned int timeout;							/* Timeout in ms */
+	char source[OSP_SIZE_NORSTR];					/* IP of self */
 	enum osp_authpolicy authpolicy;					/* OSP authentication policy */
-	char* defaultprotocol;							/* OSP default destination protocol */
-	OSPTPROVHANDLE handle;							/* OSP provider handle */
+	const char* defprotocol;						/* OSP default destination protocol */
+	enum osp_srvtype srvtype;						/* OSP default service type */
 	struct osp_provider* next;						/* Pointer to next OSP provider */
 };
 
 /* Call ID */
 struct osp_callid {
-	unsigned char buf[OSPC_CALLID_MAXSIZE];		/* Call ID string */
-	unsigned int len;							/* Call ID length */
+	unsigned char buf[OSP_SIZE_NORSTR];	/* Call ID string */
+	unsigned int len;					/* Call ID length */
 };
 
 /* Number Portability Parameters */
 struct osp_npparam {
-	const char* rn;		/* Rounding number */
-	const char* cic;	/* Carrier Identification Code */
-	int npdi;			/* NP Database Dip Indicator */
+	const char* rn;						/* Rounding number */
+	const char* cic;					/* Carrier Identification Code */
+	int npdi;							/* NP Database Dip Indicator */
 };
 
 /* SIP Diversion Header Parameters */
 struct osp_diversion {
-	const char* user;
-	const char* host;
+	const char* user;					/* Diversion header user info */
+	const char* host;					/* Diversion header host info */
 };
 
 /* OSP Application In/Output Results */
@@ -320,48 +335,48 @@
 	int outhandle;						/* Outbound transaction handle */
 	unsigned int intimelimit;			/* Inbound duration limit */
 	unsigned int outtimelimit;			/* Outbound duration limit */
-	char tech[OSP_TECHSTR_SIZE];		/* Outbound Asterisk TECH string */
-	char dest[OSP_NORSTR_SIZE];			/* Outbound destination IP address */
-	char calling[OSP_NORSTR_SIZE];		/* Outbound calling number, may be translated */
-	char called[OSP_NORSTR_SIZE];		/* Outbound called number, may be translated */
-	char token[OSP_TOKSTR_SIZE];		/* Outbound OSP token */
-	char networkid[OSP_NORSTR_SIZE];	/* Outbound network ID */
-	char nprn[OSP_NORSTR_SIZE];			/* Outbound NP routing number */
-	char npcic[OSP_NORSTR_SIZE];		/* Outbound NP carrier identification code */
+	char tech[OSP_SIZE_TECHSTR];		/* Outbound Asterisk TECH string */
+	char dest[OSP_SIZE_NORSTR];			/* Outbound destination IP address */
+	char calling[OSP_SIZE_NORSTR];		/* Outbound calling number, may be translated */
+	char called[OSP_SIZE_NORSTR];		/* Outbound called number, may be translated */
+	char token[OSP_SIZE_TOKSTR];		/* Outbound OSP token */
+	char networkid[OSP_SIZE_NORSTR];	/* Outbound network ID */
+	char nprn[OSP_SIZE_NORSTR];			/* Outbound NP routing number */
+	char npcic[OSP_SIZE_NORSTR];		/* Outbound NP carrier identification code */
 	int npdi;							/* Outbound NP database dip indicator */
-	unsigned int numresults;			/* Number of remain outbound destinations */
+	unsigned int numdests;				/* Number of remain outbound destinations */
 	struct osp_callid outcallid;		/* Outbound call ID */
 };
 
 /* OSP Call Leg */
 enum osp_callleg {
-	OSP_CALL_INBOUND,
-	OSP_CALL_OUTBOUND
+	OSP_CALL_INBOUND,	/* Inbound call leg */
+	OSP_CALL_OUTBOUND	/* Outbound call leg */
 };
 
-/* OSP */
+/* OSP Media Stream Direction */
 enum osp_direction {
-	OSP_DIR_RX = 0,
-	OSP_DIR_TX,
-	OSP_DIR_NUMBER
+	OSP_DIR_RX = 0,		/* Receive */
+	OSP_DIR_TX,			/* Send */
+	OSP_DIR_NUMBER		/* Number of directions */
 };
 
 /* OSP Metrics */
 struct osp_metrics {
-	int value;	/* Value */
-	float min;	/* Minimum */
-	float max;	/* Maximum */
-	float avg;	/* Average */
-	float ndev;	/* Normal deviation */
-	float sdev;	/* Standard deviation */
+	int value;			/* Value */
+	float min;			/* Minimum */
+	float max;			/* Maximum */
+	float avg;			/* Average */
+	float ndev;			/* Normal deviation */
+	float sdev;			/* Standard deviation */
 };
 
 /* OSP Module Global Variables */
-AST_MUTEX_DEFINE_STATIC(osplock);							/* Lock of OSP provider list */
+AST_MUTEX_DEFINE_STATIC(osp_lock);							/* Lock of OSP provider list */
 static int osp_initialized = 0;								/* Init flag */
 static int osp_hardware = 0;								/* Hardware accelleration flag */
 static int osp_security = 0;								/* Using security features flag */
-static struct osp_provider* ospproviders = NULL;			/* OSP provider list */
+static struct osp_provider* osp_providers = NULL;			/* OSP provider list */
 static unsigned int osp_tokenformat = TOKEN_ALGO_SIGNED;	/* Token format supported */
 
 /* OSP default certificates */
@@ -374,156 +389,163 @@
 /*!
  * \brief Create OSP provider handle according to configuration
  * \param cfg OSP configuration
- * \param provider OSP provider context name
- * \return 1 Success, 0 Failed, -1 Error
+ * \param name OSP provider context name
+ * \return OSP_OK Success, OSP_FAILED Failed, OSP_ERROR Error
  */
 static int osp_create_provider(
 	struct ast_config* cfg,
-	const char* provider)
-{
-	int res = 0;
-	struct ast_variable* v;
-	struct osp_provider* p;
+	const char* name)
+{
+	int res = OSP_FAILED;
+	struct ast_variable* var;
+	struct osp_provider* provider;
 	OSPTPRIVATEKEY privatekey;
 	OSPT_CERT localcert;
 	OSPT_CERT cacerts[OSP_MAX_CERTS];
 	const OSPT_CERT* pcacerts[OSP_MAX_CERTS];
-	const char* psrvpoints[OSP_MAX_SRVS];
-	unsigned char privatekeydata[OSP_KEYSTR_SIZE];
-	unsigned char localcertdata[OSP_KEYSTR_SIZE];
-	unsigned char cacertdata[OSP_KEYSTR_SIZE];
-	int i, t, error = OSPC_ERR_NO_ERROR;
-
-	if (!(p = ast_calloc(1, sizeof(*p)))) {
+	const char* pspoints[OSP_MAX_SPOINTS];
+	unsigned char privatekeydata[OSP_SIZE_KEYSTR];
+	unsigned char localcertdata[OSP_SIZE_KEYSTR];
+	unsigned char cacertdata[OSP_SIZE_KEYSTR];
+	int i, num, error = OSPC_ERR_NO_ERROR;
+
+	if (!(provider = ast_calloc(1, sizeof(*provider)))) {
 		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;
-	p->timeout = OSP_DEF_TIMEOUT;
-	p->authpolicy = OSP_DEF_AUTHPOLICY;
-	p->defaultprotocol = OSP_DEF_PROTOCOL;
-	p->handle = OSP_INVALID_HANDLE;
-
-	v = ast_variable_browse(cfg, provider);
-	while(v) {
-		if (!strcasecmp(v->name, "privatekey")) {
+		return OSP_ERROR;
+	}
+
+	/* ast_calloc has set 0 in provider */
+	provider->handle = OSP_INVALID_HANDLE;
+	ast_copy_string(provider->name, name, sizeof(provider->name));
+	snprintf(provider->privatekey, sizeof(provider->privatekey), "%s/%s-privatekey.pem", ast_config_AST_KEY_DIR, name);
+	snprintf(provider->localcert, sizeof(provider->localcert), "%s/%s-localcert.pem", ast_config_AST_KEY_DIR, name);
+	snprintf(provider->cacerts[0], sizeof(provider->cacerts[0]), "%s/%s-cacert_0.pem", ast_config_AST_KEY_DIR, name);
+	provider->maxconnect = OSP_DEF_MAXCONNECT;
+	provider->retrydelay = OSP_DEF_RETRYDELAY;
+	provider->retrylimit = OSP_DEF_RETRYLIMIT;
+	provider->timeout = OSP_DEF_TIMEOUT;
+	provider->authpolicy = OSP_DEF_AUTHPOLICY;
+	provider->defprotocol = OSP_DEF_PROTOCOL;
+	provider->srvtype = OSP_DEF_SRVTYPE;
+
+	for (var = ast_variable_browse(cfg, name); var != NULL; var = var->next) {
+		if (!strcasecmp(var->name, "privatekey")) {
 			if (osp_security) {
-				if (v->value[0] == '/') {
-					ast_copy_string(p->privatekey, v->value, sizeof(p->privatekey));
+				if (var->value[0] == '/') {
+					ast_copy_string(provider->privatekey, var->value, sizeof(provider->privatekey));
 				} else {
-					snprintf(p->privatekey, sizeof(p->privatekey), "%s/%s", ast_config_AST_KEY_DIR, v->value);
+					snprintf(provider->privatekey, sizeof(provider->privatekey), "%s/%s", ast_config_AST_KEY_DIR, var->value);
 				}
-				ast_debug(1, "OSP: privatekey '%s'\n", p->privatekey);
-			}
-		} else if (!strcasecmp(v->name, "localcert")) {
+				ast_debug(1, "OSP: privatekey '%s'\n", provider->privatekey);
+			}
+		} else if (!strcasecmp(var->name, "localcert")) {
 			if (osp_security) {
-				if (v->value[0] == '/') {
-					ast_copy_string(p->localcert, v->value, sizeof(p->localcert));
+				if (var->value[0] == '/') {
+					ast_copy_string(provider->localcert, var->value, sizeof(provider->localcert));
 				} else {
-					snprintf(p->localcert, sizeof(p->localcert), "%s/%s", ast_config_AST_KEY_DIR, v->value);
+					snprintf(provider->localcert, sizeof(provider->localcert), "%s/%s", ast_config_AST_KEY_DIR, var->value);
 				}
-				ast_debug(1, "OSP: localcert '%s'\n", p->localcert);
-			}
-		} else if (!strcasecmp(v->name, "cacert")) {
+				ast_debug(1, "OSP: localcert '%s'\n", provider->localcert);
+			}
+		} else if (!strcasecmp(var->name, "cacert")) {
 			if (osp_security) {
-				if (p->cacount < OSP_MAX_CERTS) {
-					if (v->value[0] == '/') {
-						ast_copy_string(p->cacerts[p->cacount], v->value, sizeof(p->cacerts[0]));
+				if (provider->canum < OSP_MAX_CERTS) {
+					if (var->value[0] == '/') {
+						ast_copy_string(provider->cacerts[provider->canum], var->value, sizeof(provider->cacerts[provider->canum]));
 					} else {
-						snprintf(p->cacerts[p->cacount], sizeof(p->cacerts[0]), "%s/%s", ast_config_AST_KEY_DIR, v->value);
+						snprintf(provider->cacerts[provider->canum], sizeof(provider->cacerts[provider->canum]), "%s/%s", ast_config_AST_KEY_DIR, var->value);
 					}
-					ast_debug(1, "OSP: cacerts[%d]: '%s'\n", p->cacount, p->cacerts[p->cacount]);
-					p->cacount++;
+					ast_debug(1, "OSP: cacerts[%d]: '%s'\n", provider->canum, provider->cacerts[provider->canum]);
+					provider->canum++;
 				} else {
-					ast_log(LOG_WARNING, "OSP: Too many CA Certificates at line %d\n", v->lineno);
+					ast_log(LOG_WARNING, "OSP: Too many CA Certificates at line %d\n", var->lineno);
 				}
 			}
-		} else if (!strcasecmp(v->name, "servicepoint")) {
-			if (p->spcount < OSP_MAX_SRVS) {
-				ast_copy_string(p->srvpoints[p->spcount], v->value, sizeof(p->srvpoints[0]));
-				ast_debug(1, "OSP: servicepoint[%d]: '%s'\n", p->spcount, p->srvpoints[p->spcount]);
-				p->spcount++;
+		} else if (!strcasecmp(var->name, "servicepoint")) {
+			if (provider->spnum < OSP_MAX_SPOINTS) {
+				ast_copy_string(provider->spoints[provider->spnum], var->value, sizeof(provider->spoints[provider->spnum]));
+				ast_debug(1, "OSP: servicepoint[%d]: '%s'\n", provider->spnum, provider->spoints[provider->spnum]);
+				provider->spnum++;
 			} else {
-				ast_log(LOG_WARNING, "OSP: Too many Service Points at line %d\n", v->lineno);
-			}
-		} else if (!strcasecmp(v->name, "maxconnections")) {
-			if ((sscanf(v->value, "%30d", &t) == 1) && (t >= OSP_MIN_MAXCONNECTIONS) && (t <= OSP_MAX_MAXCONNECTIONS)) {
-				p->maxconnections = t;
-				ast_debug(1, "OSP: maxconnections '%d'\n", t);
+				ast_log(LOG_WARNING, "OSP: Too many Service Points at line %d\n", var->lineno);
+			}
+		} else if (!strcasecmp(var->name, "maxconnect")) {
+			if ((sscanf(var->value, "%30d", &num) == 1) && (num >= OSP_MIN_MAXCONNECT) && (num <= OSP_MAX_MAXCONNECT)) {
+				provider->maxconnect = num;
+				ast_debug(1, "OSP: maxconnect '%d'\n", num);
 			} else {
-				ast_log(LOG_WARNING, "OSP: maxconnections should be an integer from %d to %d, not '%s' at line %d\n",
-					OSP_MIN_MAXCONNECTIONS, OSP_MAX_MAXCONNECTIONS, v->value, v->lineno);
-			}
-		} else if (!strcasecmp(v->name, "retrydelay")) {
-			if ((sscanf(v->value, "%30d", &t) == 1) && (t >= OSP_MIN_RETRYDELAY) && (t <= OSP_MAX_RETRYDELAY)) {
-				p->retrydelay = t;
-				ast_debug(1, "OSP: retrydelay '%d'\n", t);
+				ast_log(LOG_WARNING, "OSP: maxconnect should be an integer from %d to %d, not '%s' at line %d\n",
+					OSP_MIN_MAXCONNECT, OSP_MAX_MAXCONNECT, var->value, var->lineno);
+			}
+		} else if (!strcasecmp(var->name, "retrydelay")) {
+			if ((sscanf(var->value, "%30d", &num) == 1) && (num >= OSP_MIN_RETRYDELAY) && (num <= OSP_MAX_RETRYDELAY)) {
+				provider->retrydelay = num;
+				ast_debug(1, "OSP: retrydelay '%d'\n", num);
 			} else {
 				ast_log(LOG_WARNING, "OSP: retrydelay should be an integer from %d to %d, not '%s' at line %d\n",
-					OSP_MIN_RETRYDELAY, OSP_MAX_RETRYDELAY, v->value, v->lineno);
-			}
-		} else if (!strcasecmp(v->name, "retrylimit")) {
-			if ((sscanf(v->value, "%30d", &t) == 1) && (t >= OSP_MIN_RETRYLIMIT) && (t <= OSP_MAX_RETRYLIMIT)) {
-				p->retrylimit = t;
-				ast_debug(1, "OSP: retrylimit '%d'\n", t);
+					OSP_MIN_RETRYDELAY, OSP_MAX_RETRYDELAY, var->value, var->lineno);
+			}
+		} else if (!strcasecmp(var->name, "retrylimit")) {
+			if ((sscanf(var->value, "%30d", &num) == 1) && (num >= OSP_MIN_RETRYLIMIT) && (num <= OSP_MAX_RETRYLIMIT)) {
+				provider->retrylimit = num;
+				ast_debug(1, "OSP: retrylimit '%d'\n", num);
 			} else {
 				ast_log(LOG_WARNING, "OSP: retrylimit should be an integer from %d to %d, not '%s' at line %d\n",
-					OSP_MIN_RETRYLIMIT, OSP_MAX_RETRYLIMIT, v->value, v->lineno);
-			}
-		} else if (!strcasecmp(v->name, "timeout")) {
-			if ((sscanf(v->value, "%30d", &t) == 1) && (t >= OSP_MIN_TIMEOUT) && (t <= OSP_MAX_TIMEOUT)) {
-				p->timeout = t;
-				ast_debug(1, "OSP: timeout '%d'\n", t);
+					OSP_MIN_RETRYLIMIT, OSP_MAX_RETRYLIMIT, var->value, var->lineno);
+			}
+		} else if (!strcasecmp(var->name, "timeout")) {
+			if ((sscanf(var->value, "%30d", &num) == 1) && (num >= OSP_MIN_TIMEOUT) && (num <= OSP_MAX_TIMEOUT)) {
+				provider->timeout = num;
+				ast_debug(1, "OSP: timeout '%d'\n", num);
 			} else {
 				ast_log(LOG_WARNING, "OSP: timeout should be an integer from %d to %d, not '%s' at line %d\n",
-					OSP_MIN_TIMEOUT, OSP_MAX_TIMEOUT, v->value, v->lineno);
-			}
-		} else if (!strcasecmp(v->name, "source")) {
-			ast_copy_string(p->source, v->value, sizeof(p->source));
-			ast_debug(1, "OSP: source '%s'\n", p->source);
-		} else if (!strcasecmp(v->name, "authpolicy")) {
-			if ((sscanf(v->value, "%30d", &t) == 1) && ((t == OSP_AUTH_NO) || (t == OSP_AUTH_YES) || (t == OSP_AUTH_EXCLUSIVE))) {
-				p->authpolicy = t;
-				ast_debug(1, "OSP: authpolicy '%d'\n", t);
+					OSP_MIN_TIMEOUT, OSP_MAX_TIMEOUT, var->value, var->lineno);
+			}
+		} else if (!strcasecmp(var->name, "source")) {
+			ast_copy_string(provider->source, var->value, sizeof(provider->source));
+			ast_debug(1, "OSP: source '%s'\n", provider->source);
+		} else if (!strcasecmp(var->name, "authpolicy")) {
+			if ((sscanf(var->value, "%30d", &num) == 1) && ((num == OSP_AUTH_NO) || (num == OSP_AUTH_YES) || (num == OSP_AUTH_EXC))) {
+				provider->authpolicy = num;
+				ast_debug(1, "OSP: authpolicy '%d'\n", num);
 			} else {
 				ast_log(LOG_WARNING, "OSP: authpolicy should be %d, %d or %d, not '%s' at line %d\n",
-					OSP_AUTH_NO, OSP_AUTH_YES, OSP_AUTH_EXCLUSIVE, v->value, v->lineno);
-			}
-		} else if (!strcasecmp(v->name, "defaultprotocol")) {
-			if (!strcasecmp(v->value, OSP_PROT_SIP)) {
-				p->defaultprotocol = OSP_PROT_SIP;
+					OSP_AUTH_NO, OSP_AUTH_YES, OSP_AUTH_EXC, var->value, var->lineno);
+			}
+		} else if (!strcasecmp(var->name, "defprotocol")) {
+			if (!strcasecmp(var->value, OSP_PROT_SIP)) {
+				provider->defprotocol = OSP_PROT_SIP;
 				ast_debug(1, "OSP: default protocol SIP\n");
-			} else if (!strcasecmp(v->value, OSP_PROT_H323)) {
-				p->defaultprotocol = OSP_PROT_H323;
+			} else if (!strcasecmp(var->value, OSP_PROT_H323)) {
+				provider->defprotocol = OSP_PROT_H323;
 				ast_debug(1, "OSP: default protocol H.323\n");
-			} else if (!strcasecmp(v->value, OSP_PROT_IAX)) {
-				p->defaultprotocol = OSP_PROT_IAX;
+			} else if (!strcasecmp(var->value, OSP_PROT_IAX)) {
+				provider->defprotocol = OSP_PROT_IAX;
 				ast_debug(1, "OSP: default protocol IAX\n");
-			} else if (!strcasecmp(v->value, OSP_PROT_SKYPE)) {
-				p->defaultprotocol = OSP_PROT_SKYPE;
+			} else if (!strcasecmp(var->value, OSP_PROT_SKYPE)) {
+				provider->defprotocol = OSP_PROT_SKYPE;
 				ast_debug(1, "OSP: default protocol Skype\n");
 			} else {
 				ast_log(LOG_WARNING, "OSP: default protocol should be %s, %s, %s or %s not '%s' at line %d\n",
-					OSP_PROT_SIP, OSP_PROT_H323, OSP_PROT_IAX, OSP_PROT_SKYPE, v->value, v->lineno);
-			}
-		}
-		v = v->next;
-	}
-
-	if (p->cacount == 0) {
-		p->cacount = 1;
-	}
-
-	for (i = 0; i < p->spcount; i++) {
-		psrvpoints[i] = p->srvpoints[i];
+					OSP_PROT_SIP, OSP_PROT_H323, OSP_PROT_IAX, OSP_PROT_SKYPE, var->value, var->lineno);
+			}
+		} else if (!strcasecmp(var->name, "servicetype")) {
+			if ((sscanf(var->value, "%30d", &num) == 1) && ((num == OSP_SRV_VOICE) || (num == OSP_SRV_NPQUERY))) {
+				provider->srvtype = num;
+				ast_debug(1, "OSP: servicetype '%d'\n", num);
+			} else {
+				ast_log(LOG_WARNING, "OSP: servicetype should be %d or %d, not '%s' at line %d\n",
+					OSP_SRV_VOICE, OSP_SRV_NPQUERY, var->value, var->lineno);
+			}
+		}
+	}
+
+	if (provider->canum == 0) {
+		provider->canum = 1;
+	}
+
+	for (i = 0; i < provider->spnum; i++) {
+		pspoints[i] = provider->spoints[i];
 	}
 
 	if (osp_security) {
@@ -533,19 +555,19 @@
 		localcert.CertData = NULL;
 		localcert.CertDataLength = 0;
 
-		for (i = 0; i < p->cacount; i++) {
+		for (i = 0; i < provider->canum; i++) {
 			cacerts[i].CertData = NULL;
 			cacerts[i].CertDataLength = 0;
 		}
 
-		if ((error = OSPPUtilLoadPEMPrivateKey((unsigned char*)p->privatekey, &privatekey)) != OSPC_ERR_NO_ERROR) {
-			ast_log(LOG_WARNING, "OSP: Unable to load privatekey '%s', error '%d'\n", p->privatekey, error);
-		} else if ((error = OSPPUtilLoadPEMCert((unsigned char*)p->localcert, &localcert)) != OSPC_ERR_NO_ERROR) {
-			ast_log(LOG_WARNING, "OSP: Unable to load localcert '%s', error '%d'\n", p->localcert, error);
+		if ((error = OSPPUtilLoadPEMPrivateKey((unsigned char*)provider->privatekey, &privatekey)) != OSPC_ERR_NO_ERROR) {
+			ast_log(LOG_WARNING, "OSP: Unable to load privatekey '%s', error '%d'\n", provider->privatekey, error);
+		} else if ((error = OSPPUtilLoadPEMCert((unsigned char*)provider->localcert, &localcert)) != OSPC_ERR_NO_ERROR) {
+			ast_log(LOG_WARNING, "OSP: Unable to load localcert '%s', error '%d'\n", provider->localcert, error);
 		} else {
-			for (i = 0; i < p->cacount; i++) {
-				if ((error = OSPPUtilLoadPEMCert((unsigned char*)p->cacerts[i], &cacerts[i])) != OSPC_ERR_NO_ERROR) {
-					ast_log(LOG_WARNING, "OSP: Unable to load cacert '%s', error '%d'\n", p->cacerts[i], error);
+			for (i = 0; i < provider->canum; i++) {
+				if ((error = OSPPUtilLoadPEMCert((unsigned char*)provider->cacerts[i], &cacerts[i])) != OSPC_ERR_NO_ERROR) {
+					ast_log(LOG_WARNING, "OSP: Unable to load cacert '%s', error '%d'\n", provider->cacerts[i], error);
 					break;
 				} else {
 					pcacerts[i] = &cacerts[i];
@@ -573,40 +595,39 @@
 	}
 
 	if (error == OSPC_ERR_NO_ERROR) {
-		error = OSPPProviderNew(
-			p->spcount,
-			psrvpoints,
+		error = OSPPProviderNew(provider->spnum,
+			pspoints,
 			NULL,
 			OSP_AUDIT_URL,
 			&privatekey,
 			&localcert,
-			p->cacount,
+			provider->canum,
 			pcacerts,
 			OSP_LOCAL_VALIDATION,
 			OSP_SSL_LIFETIME,
-			p->maxconnections,
+			provider->maxconnect,
 			OSP_HTTP_PERSISTENCE,
-			p->retrydelay,
-			p->retrylimit,
-			p->timeout,
+			provider->retrydelay,
+			provider->retrylimit,
+			provider->timeout,
 			OSP_CUSTOMER_ID,
 			OSP_DEVICE_ID,
-			&p->handle);
+			&provider->handle);
 		if (error != OSPC_ERR_NO_ERROR) {
-			ast_log(LOG_WARNING, "OSP: Unable to create provider '%s', error '%d'\n", provider, error);
-			res = -1;
+			ast_log(LOG_WARNING, "OSP: Unable to create provider '%s', error '%d'\n", name, error);
+			res = OSP_ERROR;
 		} else {
-			ast_debug(1, "OSP: provider '%s'\n", provider);
-			ast_mutex_lock(&osplock);
-			p->next = ospproviders;
-			ospproviders = p;
-			ast_mutex_unlock(&osplock);
-			res = 1;
+			ast_debug(1, "OSP: provider '%s'\n", name);
+			ast_mutex_lock(&osp_lock);
+			provider->next = osp_providers;
+			osp_providers = provider;
+			ast_mutex_unlock(&osp_lock);
+			res = OSP_OK;
 		}
 	}
 
 	if (osp_security) {
-		for (i = 0; i < p->cacount; i++) {
+		for (i = 0; i < provider->canum; i++) {
 			if (cacerts[i].CertData) {
 				ast_free(cacerts[i].CertData);
 			}
@@ -619,8 +640,8 @@
 		}
 	}
 
-	if (res != 1) {
-		ast_free(p);
+	if (res != OSP_OK) {
+		ast_free(provider);
 	}
 
 	return res;
@@ -630,69 +651,76 @@
  * \brief Get OSP provider by name
  * \param name OSP provider context name
  * \param provider OSP provider structure
- * \return 1 Success, 0 Failed, -1 Error
+ * \return OSP_OK Success, OSP_FAILED Failed, OSP_ERROR Error
  */
 static int osp_get_provider(
 	const char* name,
 	struct osp_provider** provider)
 {
-	int res = 0;
+	int res = OSP_FAILED;
 	struct osp_provider* p;
 
-	ast_mutex_lock(&osplock);
-	p = ospproviders;
-	while(p) {
+    *provider = NULL;
+
+	ast_mutex_lock(&osp_lock);
+	for (p = osp_providers; p != NULL; p = p->next) {
 		if (!strcasecmp(p->name, name)) {
 			*provider = p;
 			ast_debug(1, "OSP: find provider '%s'\n", name);
-			res = 1;
+			res = OSP_OK;
 			break;
 		}
-		p = p->next;
-	}
-	ast_mutex_unlock(&osplock);
+	}
+	ast_mutex_unlock(&osp_lock);
 
 	return res;
 }
 
 /*!
  * \brief Create OSP transaction handle
- * \param provider OSP provider context name
- * \param transaction OSP transaction handle, output
+ * \param name OSP provider context name
+ * \param trans OSP transaction handle, output
  * \param source Source of provider, output
  * \param sourcesize Size of source buffer, in
- * \return 1 Success, 0 Failed, -1 Error
+ * \return OSK_OK Success, OSK_FAILED Failed, OSP_ERROR Error
  */
 static int osp_create_transaction(
-	const char* provider,
-	int* transaction,
+	const char* name,
+	int* trans,
 	char* source,
 	unsigned int srcsize)
 {
-	int res = 0;
-	struct osp_provider* p;
+	int res = OSP_FAILED;
+	struct osp_provider* provider;
 	int error;
 
-	ast_mutex_lock(&osplock);
-	p = ospproviders;
-	while(p) {
-		if (!strcasecmp(p->name, provider)) {
-			error = OSPPTransactionNew(p->handle, transaction);
+	if ((trans == NULL) || (source == NULL) || (srcsize <= 0)) {
+		ast_log(LOG_ERROR, "Invalid parameters\n");
+		return OSP_ERROR;
+	}
+
+	*trans = OSP_INVALID_HANDLE;
+	*source = '\0';
+
+	ast_mutex_lock(&osp_lock);
+	for (provider = osp_providers; provider; provider = provider->next) {
+		if (!strcasecmp(provider->name, name)) {
+			error = OSPPTransactionNew(provider->handle, trans);
 			if (error == OSPC_ERR_NO_ERROR) {
-				ast_debug(1, "OSP: transaction '%d'\n", *transaction);
-				ast_copy_string(source, p->source, srcsize);
+				ast_debug(1, "OSP: transaction '%d'\n", *trans);
+				ast_copy_string(source, provider->source, srcsize);
 				ast_debug(1, "OSP: source '%s'\n", source);
-				res = 1;
+				res = OSP_OK;
 			} else {
-				*transaction = OSP_INVALID_HANDLE;
+				*trans = OSP_INVALID_HANDLE;
 				ast_debug(1, "OSP: Unable to create transaction handle, error '%d'\n", error);
-				res = -1;
+				*source = '\0';
+				res = OSP_ERROR;
 			}
 			break;
 		}
-		p = p->next;
-	}
-	ast_mutex_unlock(&osplock);
+	}
+	ast_mutex_unlock(&osp_lock);
 
 	return res;
 }
@@ -706,32 +734,34 @@
 static void osp_convert_inout(
 	const char* src,
 	char* dest,
-	int destsize)
+	unsigned int destsize)
 {
 	struct in_addr inp;
-	char buffer[OSP_NORSTR_SIZE];
+	char buffer[OSP_SIZE_NORSTR];
 	char* port;
 
-	if (!ast_strlen_zero(src)) {
-		ast_copy_string(buffer, src, sizeof(buffer));
-
-		if((port = strchr(buffer, ':')) != NULL) {
-			*port = '\0';
-			port++;
-		}
-
-		if (inet_pton(AF_INET, buffer, &inp) == 1) {
-			if (port != NULL) {
-				snprintf(dest, destsize, "[%s]:%s", buffer, port);
+	if ((dest != NULL) && (destsize > 0)) {
+		if (!ast_strlen_zero(src)) {
+			ast_copy_string(buffer, src, sizeof(buffer));
+
+			if((port = strchr(buffer, ':')) != NULL) {
+				*port = '\0';
+				port++;
+			}
+
+			if (inet_pton(AF_INET, buffer, &inp) == 1) {
+				if (port != NULL) {
+					snprintf(dest, destsize, "[%s]:%s", buffer, port);
+				} else {
+					snprintf(dest, destsize, "[%s]", buffer);
+				}
+				dest[destsize - 1] = '\0';
 			} else {
-				snprintf(dest, destsize, "[%s]", buffer);
-			}
-			dest[destsize - 1] = '\0';
+				ast_copy_string(dest, src, destsize);
+			}
 		} else {
-			ast_copy_string(dest, src, destsize);
-		}
-	} else {
-		*dest = '\0';
+			*dest = '\0';
+		}
 	}
 }
 
@@ -744,52 +774,54 @@
 static void osp_convert_outin(
 	const char* src,
 	char* dest,
-	int destsize)
-{
-	char buffer[OSP_NORSTR_SIZE];
+	unsigned int destsize)
+{
+	char buffer[OSP_SIZE_NORSTR];
 	char* end;
 	char* port;
 
-	if (!ast_strlen_zero(src)) {
-		ast_copy_string(buffer, src, sizeof(buffer));
-
-		if (buffer[0] == '[') {
-			if((port = strchr(buffer + 1, ':')) != NULL) {
-				*port = '\0';
-				port++;
-			}
-
-			if ((end = strchr(buffer + 1, ']')) != NULL) {
-				*end = '\0';
-			}
-
-			if (port != NULL) {
-				snprintf(dest, destsize, "%s:%s", buffer + 1, port);
-				dest[destsize - 1] = '\0';
+	if ((dest != NULL) && (destsize > 0)) {
+		if (!ast_strlen_zero(src)) {
+			ast_copy_string(buffer, src, sizeof(buffer));
+
+			if (buffer[0] == '[') {
+				if((port = strchr(buffer + 1, ':')) != NULL) {
+					*port = '\0';
+					port++;
+				}
+
+				if ((end = strchr(buffer + 1, ']')) != NULL) {
+					*end = '\0';
+				}
+
+				if (port != NULL) {
+					snprintf(dest, destsize, "%s:%s", buffer + 1, port);
+					dest[destsize - 1] = '\0';
+				} else {
+					ast_copy_string(dest, buffer + 1, destsize);
+				}
 			} else {
-				ast_copy_string(dest, buffer + 1, destsize);
+				ast_copy_string(dest, src, destsize);
 			}
 		} else {
-			ast_copy_string(dest, src, destsize);
-		}
-	} else {
-		*dest = '\0';
+			*dest = '\0';
+		}
 	}
 }
 
 /*!
  * \brief Validate OSP token of inbound call
- * \param transaction OSP transaction handle
+ * \param trans OSP transaction handle
  * \param source Source of inbound call
  * \param destination Destination of inbound call
  * \param calling Calling number
  * \param called Called number
  * \param token OSP token, may be empty
  * \param timelimit Call duration limit, output
- * \return 1 Success, 0 Failed, -1 Error
+ * \return OSP_OK Success, OSP_FAILED Failed, OSP_ERROR Error
  */
 static int osp_validate_token(
-	int transaction,
+	int trans,
 	const char* source,
 	const char* destination,
 	const char* calling,
@@ -799,18 +831,22 @@
 {
 	int res;
 	int tokenlen;
-	unsigned char tokenstr[OSP_TOKSTR_SIZE];
-	char src[OSP_NORSTR_SIZE];
-	char dest[OSP_NORSTR_SIZE];
+	unsigned char tokenstr[OSP_SIZE_TOKSTR];
+	char src[OSP_SIZE_NORSTR];
+	char dest[OSP_SIZE_NORSTR];
 	unsigned int authorised;
 	unsigned int dummy = 0;
 	int error;
 
+	if (timelimit == NULL) {
+		ast_log(LOG_ERROR, "Invalid parameters\n");
+		return OSP_ERROR;
+	}
+
 	tokenlen = ast_base64decode(tokenstr, token, strlen(token));
 	osp_convert_inout(source, src, sizeof(src));
 	osp_convert_inout(destination, dest, sizeof(dest));
-	error = OSPPTransactionValidateAuthorisation(
-		transaction,
+	error = OSPPTransactionValidateAuthorisation(trans,
 		src,
 		dest,
 		NULL,
@@ -829,14 +865,15 @@
 		NULL,
 		osp_tokenformat);
 	if (error != OSPC_ERR_NO_ERROR) {
-		ast_debug(1, "OSP: Unable to validate inbound token, error '%d'\n", error);
-		res = -1;
+		ast_log(LOG_WARNING, "OSP: Unable to validate inbound token, error '%d'\n", error);
+		*timelimit = 0;
+		res = OSP_ERROR;
 	} else if (authorised) {
 		ast_debug(1, "OSP: Authorised\n");
-		res = 1;
+		res = OSP_OK;
 	} else {
 		ast_debug(1, "OSP: Unauthorised\n");
-		res = 0;
+		res = OSP_FAILED;
 	}
 
 	return res;
@@ -871,13 +908,13 @@
  * \param token OSP token
  * \param reason Failure reason, output
  * \param results OSP lookup results, in/output
- * \return 1 Success, 0 Failed, -1 Error
+ * \return OSP_OK Success, OSP_FAILED Failed, OSP_ERROR Error
  */
 static int osp_check_destination(
 	struct osp_provider* provider,
 	const char* calling,
 	const char* called,
-	char* destination,
+	const char* destination,
 	unsigned int tokenlen,
 	const char* token,
 	OSPEFAILREASON* reason,
@@ -886,13 +923,18 @@
 	int res;
 	OSPE_DEST_OSPENABLED enabled;
 	OSPE_DEST_PROTOCOL protocol;
-	char dest[OSP_NORSTR_SIZE];
+	char dest[OSP_SIZE_NORSTR];
 	int error;
+
+	if ((provider == NULL) || (reason == NULL) || (results == NULL)) {
+		ast_log(LOG_ERROR, "Invalid parameters\n");
+		return OSP_ERROR;
+	}
 
 	if ((error = OSPPTransactionIsDestOSPEnabled(results->outhandle, &enabled)) != OSPC_ERR_NO_ERROR) {
 		ast_debug(1, "OSP: Unable to get destination OSP version, error '%d'\n", error);
 		*reason = OSPC_FAIL_NORMAL_UNSPECIFIED;
-		return -1;
+		return OSP_ERROR;
 	}
 
 	if (enabled == OSPC_DOSP_FALSE) {
@@ -927,10 +969,10 @@
 		results->nprn[0] = '\0';
 		results->npcic[0] = '\0';
 		results->npdi = 0;
-		return -1;
-	}
-
-	res = 1;
+		return OSP_ERROR;
+	}
+
+	res = OSP_OK;
 	osp_convert_outin(destination, dest, sizeof(dest));
 	switch(protocol) {
 	case OSPC_DPROT_SIP:
@@ -964,8 +1006,8 @@
 	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);
-		ast_copy_string(results->tech, provider->defaultprotocol, sizeof(results->tech));
+		ast_debug(1, "OSP: use default protocol '%s'\n", provider->defprotocol);
+		ast_copy_string(results->tech, provider->defprotocol, sizeof(results->tech));
 		ast_copy_string(results->dest, dest, sizeof(results->dest));
 		ast_copy_string(results->calling, calling, sizeof(results->calling));
 		ast_copy_string(results->called, called, sizeof(results->called));
@@ -983,7 +1025,7 @@
 		results->nprn[0] = '\0';
 		results->npcic[0] = '\0';
 		results->npdi = 0;
-		res = 0;
+		res = OSP_FAILED;
 		break;
 	}
 
@@ -1003,18 +1045,18 @@
 
 /*!
  * \brief OSP Authentication function
- * \param provider OSP provider context name
- * \param transaction OSP transaction handle, output
+ * \param name OSP provider context name
+ * \param trans OSP transaction handle, output
  * \param source Source of inbound call
  * \param calling Calling number
  * \param called Called number
  * \param token OSP token, may be empty
  * \param timelimit Call duration limit, output
- * \return 1 Authenricated, 0 Unauthenticated, -1 Error
+ * \return OSP_OK Authenricated, OSP_FAILED Unauthenticated, OSP_ERROR Error
  */
 static int osp_auth(
-	const char* provider,
-	int* transaction,
+	const char* name,
+	int* trans,
 	const char* source,
 	const char* calling,

[... 1476 lines stripped ...]



More information about the asterisk-commits mailing list