Index: apps/app_osplookup.c =================================================================== --- apps/app_osplookup.c (revision 43625) +++ apps/app_osplookup.c (working copy) @@ -59,7 +59,29 @@ #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_TOKSTR_SIZE ((unsigned int)4096) /* OSP token string buffer size */ +#define OSP_TECHSTR_SIZE ((unsigned int)32) /* OSP signed/unsigned int string buffer size */ +/* OSP Authentication Policy */ +enum osp_authpolicy { + OSP_AUTH_NO, /* 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 Supported Destination Protocols */ +#define OSP_PROT_H323 ((char*)"H323") /* H323 Q931 protocol name*/ +#define OSP_PROT_SIP ((char*)"SIP") /* SIP protocol name */ +#define OSP_PROT_IAX ((char*)"IAX") /* IAX protocol name */ +#define OSP_PROT_OTHER ((char*)"OTHER") /* Other protocol name */ + +/* OSP supported Destination Tech */ +#define OSP_TECH_H323 ((char*)"OOH323") /* OOH323 tech name */ +#define OSP_TECH_SIP ((char*)"SIP") /* SIP tech name */ +#define OSP_TECH_IAX ((char*)"IAX2") /* IAX2 tech name */ + +/* SIP OSP header field name */ +#define OSP_SIP_HEADER ((char*)"P-OSP-Auth-Token: ") + /* OSP Constants */ #define OSP_INVALID_HANDLE ((int)-1) /* Invalid OSP handle, provider, transaction etc. */ #define OSP_CONFIG_FILE ((const char*)"osp.conf") /* OSP configuration file name */ @@ -88,14 +110,8 @@ #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_TIMELIMIT ((unsigned int)0) /* OSP default duration limit, no limit */ +#define OSP_DEF_PROTOCOL OSP_PROT_SIP /* OSP default destination protocol, SIP */ -/* OSP Authentication Policy */ -enum osp_authpolicy { - OSP_AUTH_NO, /* 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 Provider */ struct osp_provider { char name[OSP_NORSTR_SIZE]; /* OSP provider context name */ @@ -111,6 +127,7 @@ int timeout; /* Timeout in ms */ char source[OSP_NORSTR_SIZE]; /* IP of self */ enum osp_authpolicy authpolicy; /* OSP authentication policy */ + char* defaultprotocol; /* OSP default destination protocol */ OSPTPROVHANDLE handle; /* OSP provider handle */ struct osp_provider* next; /* Pointer to next OSP provider */ }; @@ -121,11 +138,13 @@ int outhandle; /* Outbound transaction handle */ unsigned int intimelimit; /* Inbound duration limit */ unsigned int outtimelimit; /* Outbound duration limit */ - char tech[20]; /* Asterisk TECH string */ - char dest[OSP_NORSTR_SIZE]; /* Destination in called@IP format */ - char calling[OSP_NORSTR_SIZE]; /* Calling number, may be translated */ + char tech[OSP_TECHSTR_SIZE]; /* Outbound Asterisk TECH string */ + char dest[OSP_NORSTR_SIZE]; /* Outbound destination IP address */ + char called[OSP_NORSTR_SIZE]; /* Outbound called number, may be translated */ + char calling[OSP_NORSTR_SIZE]; /* Outbound calling number, may be translated */ char token[OSP_TOKSTR_SIZE]; /* Outbound OSP token */ - unsigned int numresults; /* Number of remain destinations */ + char networkid[OSP_NORSTR_SIZE]; /* Outbound network ID */ + unsigned int numresults; /* Number of remain outbound destinations */ }; /* OSP Module Global Variables */ @@ -169,6 +188,7 @@ 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); @@ -250,6 +270,20 @@ 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; + ast_log(LOG_DEBUG, "OSP: default protocol '%s'\n", p->defaultprotocol); + } else if (!strcasecmp(v->value, OSP_PROT_H323)) { + p->defaultprotocol = OSP_PROT_H323; + ast_log(LOG_DEBUG, "OSP: default protocol '%s'\n", p->defaultprotocol); + } else if (!strcasecmp(v->value, OSP_PROT_IAX)) { + p->defaultprotocol = OSP_PROT_IAX; + ast_log(LOG_DEBUG, "OSP: default protocol '%s'\n", p->defaultprotocol); + } 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_OTHER, v->value, v->lineno); + } } v = v->next; } @@ -333,12 +367,12 @@ } /*! - * \brief Get OSP authenticiation policy of provider - * \param provider OSP provider context name - * \param policy OSP authentication policy, output + * \brief Get OSP provider by name + * \param name OSP provider context name + * \param provider OSP provider structure * \return 1 Success, 0 Failed, -1 Error */ -static int osp_get_policy(const char* provider, int* policy) +static int osp_get_provider(const char* name, struct osp_provider** provider) { int res = 0; struct osp_provider* p; @@ -346,9 +380,9 @@ ast_mutex_lock(&osplock); p = ospproviders; while(p) { - if (!strcasecmp(p->name, provider)) { - *policy = p->authpolicy; - ast_log(LOG_DEBUG, "OSP: authpolicy '%d'\n", *policy); + if (!strcasecmp(p->name, name)) { + *provider = p; + ast_log(LOG_DEBUG, "OSP: find provider '%s'\n", name); res = 1; break; } @@ -398,29 +432,53 @@ } /*! + * \brief Convert address to "[x.x.x.x]" or "host.domain" format + * \param src Source address string + * \param dst Destination address string + * \param buffersize Size of dst buffer + */ +static void osp_convert_address( + const char* src, + char* dst, + int buffersize) +{ + struct in_addr inp; + + if (inet_aton(src, &inp) != 0) { + snprintf(dst, buffersize, "[%s]", src); + } else { + snprintf(dst, buffersize, "%s", src); + } +} + +/*! * \brief Validate OSP token of inbound call * \param transaction OSP transaction handle * \param source Source of inbound call - * \param dest Destination 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 */ -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) +static int osp_validate_token(int transaction, const char* source, const char* destination, const char* calling, const char* called, const char* token, unsigned int* timelimit) { int res; int tokenlen; unsigned char tokenstr[OSP_TOKSTR_SIZE]; + char src[OSP_TOKSTR_SIZE]; + char dst[OSP_TOKSTR_SIZE]; unsigned int authorised; unsigned int dummy = 0; int error; tokenlen = ast_base64decode(tokenstr, token, strlen(token)); + osp_convert_address(source, src, sizeof(src)); + osp_convert_address(destination, dst, sizeof(dst)); error = OSPPTransactionValidateAuthorisation( transaction, - source, dest, NULL, NULL, + src, dst, NULL, NULL, calling ? calling : "", OSPC_E164, called, OSPC_E164, 0, NULL, @@ -462,6 +520,7 @@ /*! * \brief Choose min duration limit + * \param provider OSP provider * \param called Called number * \param calling Calling number * \param destination Destination IP in '[x.x.x.x]' format @@ -471,7 +530,7 @@ * \param result OSP lookup results, in/output * \return 1 Success, 0 Failed, -1 Error */ -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) +static int osp_check_destination(struct osp_provider* provider, const char* called, const char* calling, char* destination, unsigned int tokenlen, const char* token, enum OSPEFAILREASON* reason, struct osp_result* result) { int res; OSPE_DEST_OSP_ENABLED enabled; @@ -496,10 +555,16 @@ ast_base64encode(result->token, (const unsigned char *) token, tokenlen, sizeof(result->token) - 1); } + if ((error = OSPPTransactionGetDestNetworkId(result->outhandle, result->networkid)) != OSPC_ERR_NO_ERROR) { + ast_log(LOG_DEBUG, "OSP: Unable to get destination network ID, error '%d'\n", error); + result->networkid[0] = '\0'; + } + if ((error = OSPPTransactionGetDestProtocol(result->outhandle, &protocol)) != OSPC_ERR_NO_ERROR) { ast_log(LOG_DEBUG, "OSP: Unable to get destination protocol, error '%d'\n", error); *reason = OSPC_FAIL_NORMAL_UNSPECIFIED; result->token[0] = '\0'; + result->networkid[0] = '\0'; return -1; } @@ -508,28 +573,43 @@ destination[strlen(destination) - 1] = '\0'; switch(protocol) { case OSPE_DEST_PROT_H323_SETUP: - ast_log(LOG_DEBUG, "OSP: protocol '%d'\n", protocol); - ast_copy_string(result->tech, "H323", sizeof(result->tech)); - snprintf(result->dest, sizeof(result->dest), "%s@%s", called, destination + 1); + ast_log(LOG_DEBUG, "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: - ast_log(LOG_DEBUG, "OSP: protocol '%d'\n", protocol); - ast_copy_string(result->tech, "SIP", sizeof(result->tech)); - snprintf(result->dest, sizeof(result->dest), "%s@%s", called, destination + 1); + ast_log(LOG_DEBUG, "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: - ast_log(LOG_DEBUG, "OSP: protocol '%d'\n", protocol); - ast_copy_string(result->tech, "IAX", sizeof(result->tech)); - snprintf(result->dest, sizeof(result->dest), "%s@%s", called, destination + 1); + ast_log(LOG_DEBUG, "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: + ast_log(LOG_DEBUG, "OSP: unknown/undefined protocol '%d'\n", protocol); + ast_log(LOG_DEBUG, "OSP: use default protocol '%s'\n", provider->defaultprotocol); + ast_copy_string(result->tech, provider->defaultprotocol, 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_H323_LRQ: default: - ast_log(LOG_DEBUG, "OSP: Unknown protocol '%d'\n", protocol); + ast_log(LOG_ERROR, "OSP: unsupported protocol '%d'\n", protocol); *reason = OSPC_FAIL_PROTOCOL_ERROR; result->token[0] = '\0'; + result->networkid[0] = '\0'; res = 0; + break; } return res; @@ -559,18 +639,18 @@ static int osp_auth(const char* provider, int* transaction, const char* source, const char* calling, const char* called, const char* token, unsigned int* timelimit) { int res; - int policy = OSP_AUTH_YES; + struct osp_provider* p; char dest[OSP_NORSTR_SIZE]; *transaction = OSP_INVALID_HANDLE; *timelimit = OSP_DEF_TIMELIMIT; - res = osp_get_policy(provider, &policy); - if (!res) { - ast_log(LOG_DEBUG, "OSP: Unabe to find OSP authentication policy\n"); + + if ((res = osp_get_provider(provider, &p)) <= 0) { + ast_log(LOG_DEBUG, "OSP: Unabe to find OSP provider '%s'\n", provider); return res; } - switch (policy) { + switch (p->authpolicy) { case OSP_AUTH_NO: res = 1; break; @@ -614,6 +694,7 @@ static int osp_lookup(const char* provider, const char* srcdev, const char* calling, const char* called, struct osp_result* result) { int res; + struct osp_provider* p; char source[OSP_NORSTR_SIZE]; unsigned int callidlen; char callid[OSPC_CALLID_MAXSIZE]; @@ -622,6 +703,8 @@ char destination[OSP_NORSTR_SIZE]; unsigned int tokenlen; char token[OSP_TOKSTR_SIZE]; + char src[OSP_NORSTR_SIZE]; + char dev[OSP_NORSTR_SIZE]; unsigned int dummy = 0; enum OSPEFAILREASON reason; int error; @@ -629,11 +712,18 @@ result->outhandle = OSP_INVALID_HANDLE; result->tech[0] = '\0'; result->dest[0] = '\0'; + result->called[0] = '\0'; result->calling[0] = '\0'; result->token[0] = '\0'; + result->networkid[0] = '\0'; result->numresults = 0; result->outtimelimit = OSP_DEF_TIMELIMIT; + if ((res = osp_get_provider(provider, &p)) <= 0) { + ast_log(LOG_DEBUG, "OSP: Unabe to find OSP provider '%s'\n", provider); + return res; + } + if ((res = osp_create_transaction(provider, &result->outhandle, sizeof(source), source)) <= 0) { ast_log(LOG_DEBUG, "OSP: Unable to generate transaction handle\n"); result->outhandle = OSP_INVALID_HANDLE; @@ -643,8 +733,10 @@ return -1; } + osp_convert_address(source, src, sizeof(src)); + osp_convert_address(srcdev, dev, sizeof(dev)); result->numresults = OSP_DEF_DESTINATIONS; - error = OSPPTransactionRequestAuthorisation(result->outhandle, source, srcdev, calling ? calling : "", + error = OSPPTransactionRequestAuthorisation(result->outhandle, src, dev, calling ? calling : "", OSPC_E164, called, OSPC_E164, NULL, 0, NULL, NULL, &result->numresults, &dummy, NULL); if (error != OSPC_ERR_NO_ERROR) { ast_log(LOG_DEBUG, "OSP: Unable to request authorization\n"); @@ -685,7 +777,7 @@ ast_log(LOG_DEBUG, "OSP: destination '%s'\n", destination); ast_log(LOG_DEBUG, "OSP: token size '%d'\n", tokenlen); - if ((res = osp_check_destination(callednum, callingnum, destination, tokenlen, token, &reason, result)) > 0) { + if ((res = osp_check_destination(p, callednum, callingnum, destination, tokenlen, token, &reason, result)) > 0) { return 1; } @@ -712,7 +804,7 @@ ast_log(LOG_DEBUG, "OSP: calling '%s'\n", callingnum); ast_log(LOG_DEBUG, "OSP: destination '%s'\n", destination); ast_log(LOG_DEBUG, "OSP: token size '%d'\n", tokenlen); - if ((res = osp_check_destination(callednum, callingnum, destination, tokenlen, token, &reason, result)) > 0) { + if ((res = osp_check_destination(p, callednum, callingnum, destination, tokenlen, token, &reason, result)) > 0) { break; } else if (!result->numresults) { ast_log(LOG_DEBUG, "OSP: No more destination\n"); @@ -743,9 +835,10 @@ * \param result Lookup results, in/output * \return 1 Found , 0 No route, -1 Error */ -static int osp_next(int cause, struct osp_result* result) +static int osp_next(const char* provider, int cause,struct osp_result* result) { int res; + struct osp_provider* p; unsigned int callidlen; char callid[OSPC_CALLID_MAXSIZE]; char callingnum[OSP_NORSTR_SIZE]; @@ -758,10 +851,17 @@ result->tech[0] = '\0'; result->dest[0] = '\0'; + result->called[0] = '\0'; result->calling[0] = '\0'; result->token[0] = '\0'; + result->networkid[0] = '\0'; result->outtimelimit = OSP_DEF_TIMELIMIT; + if ((res = osp_get_provider(provider, &p)) <= 0) { + ast_log(LOG_DEBUG, "OSP: Unabe to find OSP provider '%s'\n", provider); + return res; + } + if (result->outhandle == OSP_INVALID_HANDLE) { ast_log(LOG_DEBUG, "OSP: Transaction handle undefined\n"); result->numresults = 0; @@ -795,7 +895,7 @@ ast_log(LOG_DEBUG, "OSP: calling '%s'\n", callingnum); ast_log(LOG_DEBUG, "OSP: destination '%s'\n", destination); ast_log(LOG_DEBUG, "OSP: token size '%d'\n", tokenlen); - if ((res = osp_check_destination(callednum, callingnum, destination, tokenlen, token, &reason, result)) > 0) { + if ((res = osp_check_destination(p, callednum, callingnum, destination, tokenlen, token, &reason, result)) > 0) { res = 1; break; } else if (!result->numresults) { @@ -979,6 +1079,7 @@ struct varshead *headp; struct ast_var_t* current; const char *srcdev = ""; + const char* netid = ""; char buffer[OSP_TOKSTR_SIZE]; struct osp_result result; const char *status; @@ -1030,12 +1131,15 @@ if (sscanf(ast_var_value(current), "%d", &result.intimelimit) != 1) { result.intimelimit = OSP_DEF_TIMELIMIT; } + } else if (!strcasecmp(ast_var_name(current), "OSPINNETWORKID")) { + netid = ast_var_value(current); } else if (!strcasecmp(ast_var_name(current), "OSPPEERIP")) { srcdev = ast_var_value(current); } } ast_log(LOG_DEBUG, "OSPLookup: OSPINHANDLE '%d'\n", result.inhandle); ast_log(LOG_DEBUG, "OSPLookup: OSPINTIMELIMIT '%d'\n", result.intimelimit); + ast_log(LOG_DEBUG, "OSPLookup: OSPINNETWORKID '%s'\n", netid); ast_log(LOG_DEBUG, "OSPLookup: source device '%s'\n", srcdev); if ((cres = ast_autoservice_start(chan)) < 0) { @@ -1048,8 +1152,10 @@ } else { result.tech[0] = '\0'; result.dest[0] = '\0'; + result.called[0] = '\0'; result.calling[0] = '\0'; result.token[0] = '\0'; + result.networkid[0] = '\0'; result.numresults = 0; result.outtimelimit = OSP_DEF_TIMELIMIT; if (!res) { @@ -1066,6 +1172,8 @@ ast_log(LOG_DEBUG, "OSPLookup: OSPTECH '%s'\n", result.tech); pbx_builtin_setvar_helper(chan, "OSPDEST", result.dest); ast_log(LOG_DEBUG, "OSPLookup: OSPDEST '%s'\n", result.dest); + pbx_builtin_setvar_helper(chan, "OSPCALLED", result.called); + ast_log(LOG_DEBUG, "OSPLookup: OSPCALLED '%s'\n", result.called); pbx_builtin_setvar_helper(chan, "OSPCALLING", result.calling); ast_log(LOG_DEBUG, "OSPLookup: OSPCALLING '%s'\n", result.calling); pbx_builtin_setvar_helper(chan, "OSPOUTTOKEN", result.token); @@ -1079,14 +1187,20 @@ pbx_builtin_setvar_helper(chan, "OSPLOOKUPSTATUS", status); ast_log(LOG_DEBUG, "OSPLookup: %s\n", status); - if (!strcasecmp(result.tech, "SIP")) { + if (!strcasecmp(result.tech, OSP_TECH_H323)) { + snprintf(buffer, sizeof(buffer), "%s/%s@%s", result.tech, result.called, result.dest); + pbx_builtin_setvar_helper(chan, "OSPDIALSTR", buffer); + } else if (!strcasecmp(result.tech, OSP_TECH_SIP)) { + snprintf(buffer, sizeof(buffer), "%s/%s@%s", result.tech, result.called, result.dest); + pbx_builtin_setvar_helper(chan, "OSPDIALSTR", buffer); if (!ast_strlen_zero(result.token)) { - snprintf(buffer, sizeof(buffer), "P-OSP-Auth-Token: %s", result.token); + snprintf(buffer, sizeof(buffer), "%s%s", OSP_SIP_HEADER, result.token); pbx_builtin_setvar_helper(chan, "_SIPADDHEADER", buffer); ast_log(LOG_DEBUG, "OSPLookup: SIPADDHEADER size '%zd'\n", strlen(buffer)); } - } else if (!strcasecmp(result.tech, "H323")) { - } else if (!strcasecmp(result.tech, "IAX")) { + } else if (!strcasecmp(result.tech, OSP_TECH_IAX)) { + snprintf(buffer, sizeof(buffer), "%s/%s/%s", result.tech, result.dest, result.called); + pbx_builtin_setvar_helper(chan, "OSPDIALSTR", buffer); } if ((cres = ast_autoservice_stop(chan)) < 0) { @@ -1120,6 +1234,7 @@ { int res; struct ast_module_user *u; + const char* provider = OSP_DEF_PROVIDER; int priority_jump = 0; int cause = 0; struct varshead* headp; @@ -1131,11 +1246,12 @@ AST_DECLARE_APP_ARGS(args, AST_APP_ARG(cause); + AST_APP_ARG(provider); AST_APP_ARG(options); ); if (ast_strlen_zero(data)) { - ast_log(LOG_WARNING, "OSPNext: Arg required, OSPNext(cause[|options])\n"); + ast_log(LOG_WARNING, "OSPNext: Arg required, OSPNext(cause[|provider[|options]])\n"); return -1; } @@ -1154,6 +1270,11 @@ } ast_log(LOG_DEBUG, "OSPNext: cause '%d'\n", cause); + if (!ast_strlen_zero(args.provider)) { + provider = args.provider; + } + ast_log(LOG_DEBUG, "OSPlookup: provider '%s'\n", provider); + if ((args.options) && (strchr(args.options, 'j'))) { priority_jump = 1; } @@ -1189,13 +1310,15 @@ ast_log(LOG_DEBUG, "OSPNext: OSPINTIMELIMIT '%d'\n", result.intimelimit); ast_log(LOG_DEBUG, "OSPNext: OSPRESULTS '%d'\n", result.numresults); - if ((res = osp_next(cause, &result)) > 0) { + if ((res = osp_next(provider, cause, &result)) > 0) { status = AST_OSP_SUCCESS; } else { result.tech[0] = '\0'; result.dest[0] = '\0'; + result.called[0] = '\0'; result.calling[0] = '\0'; result.token[0] = '\0'; + result.networkid[0] = '\0'; result.numresults = 0; result.outtimelimit = OSP_DEF_TIMELIMIT; if (!res) { @@ -1209,6 +1332,8 @@ ast_log(LOG_DEBUG, "OSPNext: OSPTECH '%s'\n", result.tech); pbx_builtin_setvar_helper(chan, "OSPDEST", result.dest); ast_log(LOG_DEBUG, "OSPNext: OSPDEST '%s'\n", result.dest); + pbx_builtin_setvar_helper(chan, "OSPCALLED", result.called); + ast_log(LOG_DEBUG, "OSPNext: OSPCALLED'%s'\n", result.called); pbx_builtin_setvar_helper(chan, "OSPCALLING", result.calling); ast_log(LOG_DEBUG, "OSPNext: OSPCALLING '%s'\n", result.calling); pbx_builtin_setvar_helper(chan, "OSPOUTTOKEN", result.token); @@ -1222,14 +1347,20 @@ pbx_builtin_setvar_helper(chan, "OSPNEXTSTATUS", status); ast_log(LOG_DEBUG, "OSPNext: %s\n", status); - if (!strcasecmp(result.tech, "SIP")) { + if (!strcasecmp(result.tech, OSP_TECH_H323)) { + snprintf(buffer, sizeof(buffer), "%s/%s@%s", result.tech, result.called, result.dest); + pbx_builtin_setvar_helper(chan, "OSPDIALSTR", buffer); + } else if (!strcasecmp(result.tech, OSP_TECH_SIP)) { + snprintf(buffer, sizeof(buffer), "%s/%s@%s", result.tech, result.called, result.dest); + pbx_builtin_setvar_helper(chan, "OSPDIALSTR", buffer); if (!ast_strlen_zero(result.token)) { - snprintf(buffer, sizeof(buffer), "P-OSP-Auth-Token: %s", result.token); + snprintf(buffer, sizeof(buffer), "%s%s", OSP_SIP_HEADER, result.token); pbx_builtin_setvar_helper(chan, "_SIPADDHEADER", buffer); ast_log(LOG_DEBUG, "OSPLookup: SIPADDHEADER size '%zd'\n", strlen(buffer)); } - } else if (!strcasecmp(result.tech, "H323")) { - } else if (!strcasecmp(result.tech, "IAX")) { + } else if (!strcasecmp(result.tech, OSP_TECH_IAX)) { + snprintf(buffer, sizeof(buffer), "%s/%s/%s", result.tech, result.dest, result.called); + pbx_builtin_setvar_helper(chan, "OSPDIALSTR", buffer); } if(res <= 0) { @@ -1517,6 +1648,7 @@ ast_cli(fd, "Timeout: %d milliseconds\n", p->timeout); ast_cli(fd, "Source: %s\n", strlen(p->source) ? p->source : ""); ast_cli(fd, "Auth Policy %d\n", p->authpolicy); + ast_cli(fd, "Default protocol %s\n", p->defaultprotocol); ast_cli(fd, "OSP Handle: %d\n", p->handle); found++; } @@ -1556,7 +1688,9 @@ " ${OSPOUTHANDLE}: The OSP Handle for anything remaining\n" " ${OSPTECH}: The technology to use for the call\n" " ${OSPDEST}: The destination to use for the call\n" +" ${OSPCALLED}: The called number to use for the call\n" " ${OSPCALLING}: The calling number to use for the call\n" +" ${OSPDIALSTR}: The dial command string\n" " ${OSPOUTTOKEN}: The actual OSP token as a string\n" " ${OSPOUTTIMELIMIT}: The outbound call duration limit in seconds\n" " ${OSPRESULTS}: The number of OSP results total remaining\n" @@ -1570,14 +1704,14 @@ static const char* app3 = "OSPNext"; static const char* synopsis3 = "Lookup next destination by OSP"; static const char* descrip3 = -" OSPNext(cause[|options]): Looks up the next OSP Destination for ${OSPOUTHANDLE}\n" +" OSPNext(cause[|provider[|options]]): Looks up the next OSP Destination for ${OSPOUTHANDLE}\n" "See OSPLookup for more information\n" "\n" "The option string may contain the following character:\n" " 'j' -- jump to n+101 priority if the lookup was NOT successful\n" "This application sets the following channel variable upon completion:\n" " OSPNEXTSTATUS The status of the OSP Next attempt as a text string, one of\n" -" SUCCESS | FAILED |ERROR\n"; +" SUCCESS | FAILED | ERROR\n"; static const char* app4 = "OSPFinish"; static const char* synopsis4 = "Record OSP entry"; @@ -1590,14 +1724,14 @@ " 'j' -- jump to n+101 priority if the finish attempt was NOT successful\n" "This application sets the following channel variable upon completion:\n" " OSPFINISHSTATUS The status of the OSP Finish attempt as a text string, one of\n" -" SUCCESS | FAILED |ERROR \n"; +" SUCCESS | FAILED | ERROR \n"; static const char osp_usage[] = "Usage: osp show\n" " Displays information on Open Settlement Protocol support\n"; static struct ast_cli_entry cli_osp[] = { - { { "osp", "show", NULL}, + { {"osp", "show", NULL}, osp_show, "Displays OSP information", osp_usage }, };