/* * Set calling number if translated * param msg SIP message * param dest Destination structure * return 0 success, 1 calling number same or not support calling number translation, -1 failure */ static int ospSetCalling( struct sip_msg* msg, osp_dest* dest) { str rpid; int_str val; char calling[OSP_STRBUF_SIZE]; char buffer[OSP_STRBUF_SIZE]; int result; if ((ospGetRpidUserpart(msg, calling, sizeof(calling)) != 0) && (ospGetFromUserpart(msg, calling, sizeof(calling)) != 0)) { LM_ERR("failed to extract calling number\n"); result = -1; } else if (strcmp(calling, dest->calling) == 0) { LM_DBG("calling number does not been translated\n"); result = 1; } else if ((osp_auth.rpid_avp.s.s == NULL) || (osp_auth.rpid_avp.s.len == 0)) { LM_WARN("rpid_avp is not foune, cannot set rpid avp\n"); result = -1; } else { snprintf(buffer, sizeof(buffer), "\"%s\" <sip:%s@%s>", dest->calling, dest->calling, dest->source); buffer[sizeof(buffer) - 1] = '\0'; rpid.s = buffer; rpid.len = strlen(buffer); add_avp(osp_auth.rpid_avp_type | AVP_VAL_STR, (int_str)osp_auth.rpid_avp, (int_str)rpid); result = 0; } if (result == 0) { val.n = 1; } else { val.n = 0; } add_avp(AVP_NAME_STR, (int_str)OSP_CALLING_NAME, val); return result; }
/* * Report OSP usage from OSP cookie * param msg SIP message * param cookie OSP cookie (buffer owned by ospReportUsage, can be modified) * param callid Call ID * param release Who releases the call first. 0 orig, 1 term * param type Usage type * return */ static int ospReportUsageFromCookie( struct sip_msg* msg, char* cookie, OSPT_CALL_ID* callid, OSPE_RELEASE release, OSPE_ROLE type) { char* tmp; char* token; char tag; char* value; unsigned long long transid = 0; time_t authtime = 0; unsigned destcount = 0; time_t duration = 0; time_t endtime = time(NULL); int cookieflags = 0; unsigned releasecode; char firstvia[OSP_STRBUF_SIZE]; char from[OSP_STRBUF_SIZE]; char rpid[OSP_STRBUF_SIZE]; char pai[OSP_STRBUF_SIZE]; char divuser[OSP_STRBUF_SIZE]; char divhost[OSP_STRBUF_SIZE]; char pci[OSP_STRBUF_SIZE]; char to[OSP_STRBUF_SIZE]; char nexthop[OSP_STRBUF_SIZE]; char* snid = NULL; char* dnid = NULL; char* calling; char* called; char* originator = NULL; char* terminator; char source[OSP_STRBUF_SIZE]; char dest[OSP_STRBUF_SIZE]; char srcdev[OSP_STRBUF_SIZE]; OSPTTRANHANDLE transaction = -1; int errorcode; LM_DBG("cookie '%s' type '%d'\n", cookie == NULL ? "NULL" : cookie, type); if (cookie != NULL) { for (token = strtok_r(cookie, "_", &tmp); token; token = strtok_r(NULL, "_", &tmp)) { tag = *token; value= token + 1; switch (tag) { case OSP_COOKIE_TRANSID: case OSP_COOKIE_TRANSIDUP: transid = atoll(value); cookieflags |= OSP_COOKIEHAS_TRANSID; break; case OSP_COOKIE_AUTHTIME: case OSP_COOKIE_AUTHTIMEUP: authtime = atoi(value); duration = endtime - authtime; cookieflags |= OSP_COOKIEHAS_AUTHTIME; break; case OSP_COOKIE_SRCIP: case OSP_COOKIE_SRCIPUP: originator = value; cookieflags |= OSP_COOKIEHAS_SRCIP; break; case OSP_COOKIE_DCOUNT: case OSP_COOKIE_DCOUNTUP: destcount = (unsigned)atoi(value); cookieflags |= OSP_COOKIEHAS_DSTCOUNT; break; case OSP_COOKIE_SNID: case OSP_COOKIE_SNIDUP: snid = value; break; case OSP_COOKIE_DNID: case OSP_COOKIE_DNIDUP: dnid = value; break; default: LM_ERR("unexpected tag '%c' / value '%s'\n", tag, value); break; } } } switch (type) { case OSPC_ROLE_DESTINATION: if (cookieflags == OSP_COOKIEHAS_TERMALL) { releasecode = 10016; } else { releasecode = 9016; } break; case OSPC_ROLE_SOURCE: case OSPC_ROLE_OTHER: case OSPC_ROLE_UNDEFINED: default: if (cookieflags == OSP_COOKIEHAS_ORIGALL) { releasecode = 10016; } else { releasecode = 9016; } break; } if (releasecode == 9016) { transid = 0; originator = NULL; authtime = 0; duration = 0; destcount = 0; } ospGetViaAddress(msg, firstvia, sizeof(firstvia)); ospGetFromUserpart(msg, from, sizeof(from)); ospGetRpidUserpart(msg, rpid, sizeof(rpid)); ospGetPaiUserpart(msg, pai, sizeof(pai)); ospGetDiversion(msg, divuser, sizeof(divuser), divhost, sizeof(divhost)); ospGetPChargeInfoUserpart(msg, pci, sizeof(pci)); ospGetToUserpart(msg, to, sizeof(to)); ospGetNextHop(msg, nexthop, sizeof(nexthop)); LM_DBG("first via '%s' from '%s' to '%s' next hop '%s'\n", firstvia, from, to, nexthop); if (release == OSPC_RELEASE_DESTINATION) { LM_DBG("term '%s' released the call, call_id '%.*s' transaction_id '%llu'\n", firstvia, callid->Length, callid->Value, transid); if (originator == NULL) { originator = nexthop; } calling = to; called = from; terminator = firstvia; } else { if (release == OSPC_RELEASE_SOURCE) { LM_DBG("orig '%s' released the call, call_id '%.*s' transaction_id '%llu'\n", firstvia, callid->Length, callid->Value, transid); } else { LM_DBG("unknown '%s' released the call, call_id '%.*s' transaction_id '%llu'\n", firstvia, callid->Length, callid->Value, transid); } if (originator == NULL) { originator = firstvia; } calling = from; called = to; terminator = nexthop; } errorcode = OSPPTransactionNew(_osp_provider, &transaction); LM_DBG("created transaction handle '%d' (%d)\n", transaction, errorcode); switch (type) { case OSPC_ROLE_DESTINATION: srcdev[0] = '\0'; ospConvertToOutAddress(originator, source, sizeof(source)); strncpy(dest, _osp_out_device, sizeof(dest)); dest[sizeof(dest) - 1] = '\0'; break; case OSPC_ROLE_SOURCE: case OSPC_ROLE_OTHER: case OSPC_ROLE_UNDEFINED: default: ospConvertToOutAddress(originator, srcdev, sizeof(srcdev)); strncpy(source, _osp_out_device, sizeof(source)); source[sizeof(source) - 1] = '\0'; ospConvertToOutAddress(terminator, dest, sizeof(dest)); break; } /* RoleInfo must be set before BuildUsageFromScratch */ OSPPTransactionSetRoleInfo(transaction, OSPC_RSTATE_STOP, OSPC_RFORMAT_OSP, OSPC_RVENDOR_OPENSIPS); errorcode = OSPPTransactionBuildUsageFromScratch( transaction, transid, type, source, dest, srcdev, "", calling, OSPC_NFORMAT_E164, called, OSPC_NFORMAT_E164, callid->Length, callid->Value, 0, NULL, NULL); LM_DBG("built usage handle '%d' (%d)\n", transaction, errorcode); if ((errorcode == OSPC_ERR_NO_ERROR) && (destcount > 0)) { errorcode = OSPPTransactionSetDestinationCount( transaction, destcount); } if (errorcode == OSPC_ERR_NO_ERROR) { OSPPTransactionSetProtocol(transaction, OSPC_PROTTYPE_SOURCE, OSPC_PROTNAME_SIP); OSPPTransactionSetProtocol(transaction, OSPC_PROTTYPE_DESTINATION, OSPC_PROTNAME_SIP); OSPPTransactionSetSrcNetworkId(transaction, snid); OSPPTransactionSetDestNetworkId(transaction, dnid); OSPPTransactionSetRemotePartyId(transaction, OSPC_NFORMAT_E164, rpid); OSPPTransactionSetAssertedId(transaction, OSPC_NFORMAT_E164, pai); OSPPTransactionSetDiversion(transaction, divuser, divhost); OSPPTransactionSetChargeInfo(transaction, OSPC_NFORMAT_E164, pci); ospReportUsageWrapper( transaction, releasecode, duration, authtime, endtime, 0, 0, 0, 0, release); } return errorcode; }
/* * Request OSP authorization and routeing * param msg SIP message * param ignore1 * param ignore2 * return MODULE_RETURNCODE_TRUE success, MODULE_RETURNCODE_FALSE failure, MODULE_RETURNCODE_ERROR error */ int ospRequestRouting( struct sip_msg* msg, char* ignore1, char* ignore2) { int errcode; time_t authtime; char calling[OSP_STRBUF_SIZE]; char called[OSP_STRBUF_SIZE]; char rn[OSP_STRBUF_SIZE]; char cic[OSP_STRBUF_SIZE]; int npdi; OSPE_OPERATOR_NAME type; char opname[OSPC_OPNAME_NUMBER][OSP_STRBUF_SIZE]; char source[OSP_STRBUF_SIZE]; char sourcebuf[OSP_STRBUF_SIZE]; char srcdev[OSP_STRBUF_SIZE]; char srcdevbuf[OSP_STRBUF_SIZE]; char rpid[OSP_STRBUF_SIZE]; char pai[OSP_STRBUF_SIZE]; char divuser[OSP_STRBUF_SIZE]; char divhost[OSP_STRBUF_SIZE]; char divhostbuf[OSP_STRBUF_SIZE]; char pci[OSP_STRBUF_SIZE]; struct usr_avp* snidavp = NULL; int_str snidval; char snid[OSP_STRBUF_SIZE]; struct usr_avp* cinfoavp = NULL; int_str cinfoval; unsigned int cinfonum = 0, i; char cinfo[OSP_DEF_CINFOS][OSP_STRBUF_SIZE]; char cinfostr[OSP_STRBUF_SIZE]; unsigned int callidnumber = 1; OSPT_CALL_ID* callids[callidnumber]; unsigned int logsize = 0; char* detaillog = NULL; char tohost[OSP_STRBUF_SIZE]; char tohostbuf[OSP_STRBUF_SIZE]; const char* preferred[2] = { NULL }; unsigned int destcount; OSPTTRANHANDLE trans = -1; int result = MODULE_RETURNCODE_FALSE; if ((errcode = OSPPTransactionNew(_osp_provider, &trans)) != OSPC_ERR_NO_ERROR) { LM_ERR("failed to create new OSP transaction (%d)\n", errcode); } else if (ospGetFromUserpart(msg, calling, sizeof(calling)) != 0) { LM_ERR("failed to extract calling number\n"); } else if ((ospGetUriUserpart(msg, called, sizeof(called)) != 0) && (ospGetToUserpart(msg, called, sizeof(called)) != 0)) { LM_ERR("failed to extract called number\n"); } else if (ospGetCallId(msg, &(callids[0])) != 0) { LM_ERR("failed to extract call id\n"); } else if (ospGetSource(msg, source, sizeof(source)) != 0) { LM_ERR("failed to extract source address\n"); } else if (ospGetSourceDevice(msg, srcdev, sizeof(srcdev)) != 0) { LM_ERR("failed to extract source deivce address\n"); } else { authtime = time(NULL); ospConvertToOutAddress(source, sourcebuf, sizeof(sourcebuf)); ospConvertToOutAddress(srcdev, srcdevbuf, sizeof(srcdevbuf)); switch (_osp_service_type) { case 1: OSPPTransactionSetServiceType(trans, OSPC_SERVICE_NPQUERY); ospGetToHostpart(msg, tohost, sizeof(tohost)); ospConvertToOutAddress(tohost, tohostbuf, sizeof(tohostbuf)); preferred[0] = tohostbuf; destcount = 1; break; case 0: default: OSPPTransactionSetServiceType(trans, OSPC_SERVICE_VOICE); destcount = _osp_max_dests; break; } if (ospGetNpParameters(msg, rn, sizeof(rn), cic, sizeof(cic), &npdi) == 0) { OSPPTransactionSetNumberPortability(trans, rn, cic, npdi); } for (type = OSPC_OPNAME_START; type < OSPC_OPNAME_NUMBER; type++) { if (ospGetOperatorName(msg, type, opname[type], sizeof(opname[type])) == 0) { OSPPTransactionSetOperatorName(trans, type, opname[type]); } } if (ospGetRpidUserpart(msg, rpid, sizeof(rpid)) == 0) { OSPPTransactionSetRemotePartyId(trans, OSPC_NFORMAT_E164, rpid); } if (ospGetPaiUserpart(msg, pai, sizeof(pai)) == 0) { OSPPTransactionSetAssertedId(trans, OSPC_NFORMAT_E164, pai); } if (ospGetDiversion(msg, divuser, sizeof(divuser), divhost, sizeof(divhost)) == 0) { ospConvertToOutAddress(divhost, divhostbuf, sizeof(divhostbuf)); } else { divhostbuf[0] = '\0'; } OSPPTransactionSetDiversion(trans, divuser, divhostbuf); OSPPTransactionSetProtocol(trans, OSPC_PROTTYPE_SOURCE, OSPC_PROTNAME_SIP); if (ospGetPChargeInfoUserpart(msg, pci, sizeof(pci)) == 0) { OSPPTransactionSetChargeInfo(trans, OSPC_NFORMAT_E164, pci); } if ((_osp_snid_avpid >= 0) && ((snidavp = search_first_avp(_osp_snid_avptype, _osp_snid_avpid, &snidval, 0)) != NULL) && (snidavp->flags & AVP_VAL_STR) && (snidval.s.s && snidval.s.len)) { snprintf(snid, sizeof(snid), "%.*s", snidval.s.len, snidval.s.s); snid[sizeof(snid) - 1] = '\0'; OSPPTransactionSetNetworkIds(trans, snid, ""); } else { snid[0] = '\0'; } if (_osp_cinfo_avpid >= 0) { for (i = 0, cinfoavp = search_first_avp(_osp_cinfo_avptype, _osp_cinfo_avpid, NULL, 0); ((i < OSP_DEF_CINFOS) && (cinfoavp != NULL)); i++, cinfoavp = search_next_avp(cinfoavp, NULL)) { get_avp_val(cinfoavp, &cinfoval); if ((cinfoavp->flags & AVP_VAL_STR) && (cinfoval.s.s && cinfoval.s.len)) { snprintf(cinfo[i], sizeof(cinfo[i]), "%.*s", cinfoval.s.len, cinfoval.s.s); cinfo[i][sizeof(cinfo[i]) - 1] = '\0'; } else { cinfo[i][0] = '\0'; } } cinfonum = i; cinfostr[0] = '\0'; for (i = 0; i < cinfonum; i++) { if (cinfo[cinfonum - i - 1][0] != '\0') { OSPPTransactionSetCustomInfo(trans, i, cinfo[cinfonum - i - 1]); snprintf(cinfostr + strlen(cinfostr), sizeof(cinfostr) - strlen(cinfostr), "custom_info%d '%s' ", i + 1, cinfo[cinfonum - i - 1]); } } cinfostr[sizeof(cinfostr) - 1] = '\0'; } LM_INFO("request auth and routing for: " "service_type '%d' " "source '%s' " "source_dev '%s' " "source_networkid '%s' " "calling '%s' " "called '%s' " "preferred '%s' " "nprn '%s' " "npcic '%s' " "npdi '%d' " /* "spid '%s' " "ocn '%s' " "spn '%s' " "altspn '%s' " "mcc '%s' " "mnc '%s' " */ "rpid '%s' " "pai '%s' " "div_user '%s' " "div_host '%s' " "pci '%s' " "call_id '%.*s' " "dest_count '%d' " "%s\n", _osp_service_type, sourcebuf, srcdevbuf, snid, calling, called, (preferred[0] == NULL) ? "" : preferred[0], rn, cic, npdi, /* opname[OSPC_OPNAME_SPID], opname[OSPC_OPNAME_OCN], opname[OSPC_OPNAME_SPN], opname[OSPC_OPNAME_ALTSPN], opname[OSPC_OPNAME_MCC], opname[OSPC_OPNAME_MNC], */ rpid, pai, divuser, divhostbuf, pci, callids[0]->Length, callids[0]->Value, destcount, cinfostr); /* try to request authorization */ errcode = OSPPTransactionRequestAuthorisation( trans, /* transaction handle */ sourcebuf, /* from the configuration file */ srcdevbuf, /* source device of call, protocol specific, in OSP format */ calling, /* calling number in nodotted e164 notation */ OSPC_NFORMAT_E164, /* calling number format */ called, /* called number */ OSPC_NFORMAT_E164, /* called number format */ "", /* optional username string, used if no number */ callidnumber, /* number of call ids, here always 1 */ callids, /* sized-1 array of call ids */ preferred, /* preferred destinations */ &destcount, /* max destinations, after call dest_count */ &logsize, /* size allocated for detaillog (next param) 0=no log */ detaillog); /* memory location for detaillog to be stored */ if ((errcode == OSPC_ERR_NO_ERROR) && (ospLoadRoutes(trans, destcount, source, srcdev, called, authtime, rpid, pai, divuser, divhostbuf, pci) == 0)) { LM_INFO("there are '%d' OSP routes, call_id '%.*s'\n", destcount, callids[0]->Length, callids[0]->Value); result = MODULE_RETURNCODE_TRUE; } else { LM_ERR("failed to request auth and routing (%d), call_id '%.*s'\n", errcode, callids[0]->Length, callids[0]->Value); switch (errcode) { case OSPC_ERR_TRAN_ROUTE_BLOCKED: result = -403; break; case OSPC_ERR_TRAN_ROUTE_NOT_FOUND: result = -404; break; case OSPC_ERR_TRAN_CALLING_INVALID: result = -428; break; case OSPC_ERR_TRAN_CALLED_FILTERING: result = -484; break; case OSPC_ERR_NO_ERROR: /* AuthRsp ok but ospLoadRoutes fails */ result = MODULE_RETURNCODE_ERROR; break; default: result = MODULE_RETURNCODE_FALSE; break; } } } if (callids[0] != NULL) { OSPPCallIdDelete(&(callids[0])); } if (trans != -1) { OSPPTransactionDelete(trans); } return result; }
/* * Validate OSP token * param ignore1 * param ignore2 * return MODULE_RETURNCODE_TRUE success, MODULE_RETURNCODE_FALSE failure */ int ospValidateHeader ( struct sip_msg* msg, char* ignore1, char* ignore2) { int errorcode; OSPTTRANHANDLE transaction = -1; unsigned int authorized = 0; unsigned int timelimit = 0; void* detaillog = NULL; unsigned int logsize = 0; unsigned char* callidval = (unsigned char*)""; OSPTCALLID* callid = NULL; unsigned callidsize = 0; unsigned char token[OSP_TOKENBUF_SIZE]; unsigned int tokensize = sizeof(token); osp_dest dest; int result = MODULE_RETURNCODE_FALSE; LOG(L_DBG, "osp: ospValidateHeader\n"); ospInitDestination(&dest); if ((errorcode = OSPPTransactionNew(_osp_provider, &transaction) != 0)) { LOG(L_ERR, "osp: ERROR: failed to create a new OSP transaction handle (%d)\n", errorcode); } else if ((ospGetRpidUserpart(msg, dest.calling, sizeof(dest.calling)) != 0) && (ospGetFromUserpart(msg, dest.calling, sizeof(dest.calling)) != 0)) { LOG(L_ERR, "osp: ERROR: failed to extract calling number\n"); } else if ((ospGetUriUserpart(msg, dest.called, sizeof(dest.called)) != 0) && (ospGetToUserpart(msg, dest.called, sizeof(dest.called)) != 0)) { LOG(L_ERR, "osp: ERROR: failed to extract called number\n"); } else if (ospGetCallId(msg, &callid) != 0) { LOG(L_ERR, "osp: ERROR: failed to extract call id\n"); } else if (ospGetSourceAddress(msg, dest.source, sizeof(dest.source)) != 0) { LOG(L_ERR, "osp: ERROR: failed to extract source address\n"); } else if (ospGetOspHeader(msg, token, &tokensize) != 0) { LOG(L_ERR, "osp: ERROR: failed to extract OSP authorization token\n"); } else { LOG(L_INFO, "osp: validate token for: " "transaction_handle '%i' " "e164_source '%s' " "e164_dest '%s' " "validate_call_id '%s' " "call_id '%.*s'\n", transaction, dest.calling, dest.called, _osp_validate_callid == 0 ? "No" : "Yes", callid->ospmCallIdLen, callid->ospmCallIdVal); if (_osp_validate_callid != 0) { callidsize = callid->ospmCallIdLen; callidval = callid->ospmCallIdVal; } errorcode = OSPPTransactionValidateAuthorisation( transaction, "", "", "", "", dest.calling, OSPC_E164, dest.called, OSPC_E164, callidsize, callidval, tokensize, token, &authorized, &timelimit, &logsize, detaillog, _osp_token_format); if (callid->ospmCallIdLen > sizeof(dest.callid) - 1) { dest.callidsize = sizeof(dest.callid) - 1; } else { dest.callidsize = callid->ospmCallIdLen; } memcpy(dest.callid, callid->ospmCallIdVal, dest.callidsize); dest.callid[dest.callidsize] = 0; dest.tid = ospGetTransactionId(transaction); dest.type = OSPC_DESTINATION; dest.authtime = time(NULL); strcpy(dest.host, _osp_device_ip); ospSaveTermDestination(&dest); if ((errorcode == 0) && (authorized == 1)) { LOG(L_DBG, "osp: call is authorized for %d seconds, call_id '%.*s' transaction_id '%lld'", timelimit, dest.callidsize, dest.callid, dest.tid); ospRecordTermTransaction(msg, transaction, dest.source, dest.calling, dest.called, dest.authtime); result = MODULE_RETURNCODE_TRUE; } else { LOG(L_ERR, "osp: ERROR: token is invalid (%i)\n", errorcode); /* * Update terminating status code to 401 and report terminating setup usage. * We may need to make 401 configurable, just in case a user decides to reply with * a different code. Other options - trigger call setup usage reporting from the cpl * (after replying with an error code), or maybe use a different tm callback. */ ospRecordEvent(0, 401); } } if (transaction != -1) { OSPPTransactionDelete(transaction); } if (callid != NULL) { OSPPCallIdDelete(&callid); } return result; }
/* * Request OSP authorization and routeing * param msg SIP message * param ignore1 * param ignore2 * return MODULE_RETURNCODE_TRUE success, MODULE_RETURNCODE_FALSE failure */ int ospRequestRouting( struct sip_msg* msg, char* ignore1, char* ignore2) { int errorcode; time_t authtime; char source[OSP_E164BUF_SIZE]; char sourcedev[OSP_STRBUF_SIZE]; char src[OSP_STRBUF_SIZE]; char destination[OSP_E164BUF_SIZE]; unsigned int callidnumber = 1; OSPTCALLID* callids[callidnumber]; unsigned int logsize = 0; char* detaillog = NULL; const char** preferred = NULL; unsigned int destcount; OSPTTRANHANDLE transaction = -1; int result = MODULE_RETURNCODE_FALSE; LOG(L_DBG, "osp: ospRequestRouting\n"); authtime = time(NULL); destcount = _osp_max_dests; if ((errorcode = OSPPTransactionNew(_osp_provider, &transaction)) != OSPC_ERR_NO_ERROR) { LOG(L_ERR, "osp: ERROR: failed to create new OSP transaction (%d)\n", errorcode); } else if ((ospGetRpidUserpart(msg, source, sizeof(source)) != 0) && (ospGetFromUserpart(msg, source, sizeof(source)) != 0)) { LOG(L_ERR, "osp: ERROR: failed to extract calling number\n"); } else if ((ospGetUriUserpart(msg, destination, sizeof(destination)) != 0) && (ospGetToUserpart(msg, destination, sizeof(destination)) != 0)) { LOG(L_ERR, "osp: ERROR: failed to extract called number\n"); } else if (ospGetCallId(msg, &(callids[0])) != 0) { LOG(L_ERR, "osp: ERROR: failed to extract call id\n"); } else if (ospGetSourceAddress(msg, sourcedev, sizeof(sourcedev)) != 0) { LOG(L_ERR, "osp: ERROR: failed to extract source address\n"); } else { ospConvertAddress(sourcedev, src, sizeof(src)); LOG(L_INFO, "osp: request auth and routing for: " "source '%s' " "source_port '%s' " "source_dev '%s' " "e164_source '%s' " "e164_dest '%s' " "call_id '%.*s' " "dest_count '%i'\n", _osp_device_ip, _osp_device_port, src, /* sourcedev in "[x.x.x.x]" or host.domain format */ source, destination, callids[0]->ospmCallIdLen, callids[0]->ospmCallIdVal, destcount ); /* try to request authorization */ errorcode = OSPPTransactionRequestAuthorisation( transaction, /* transaction handle */ _osp_device_ip, /* from the configuration file */ src, /* source of call, protocol specific, in OSP format */ source, /* calling number in nodotted e164 notation */ OSPC_E164, /* calling number format */ destination, /* called number */ OSPC_E164, /* called number format */ "", /* optional username string, used if no number */ callidnumber, /* number of call ids, here always 1 */ callids, /* sized-1 array of call ids */ preferred, /* preferred destinations, here always NULL */ &destcount, /* max destinations, after call dest_count */ &logsize, /* size allocated for detaillog (next param) 0=no log */ detaillog); /* memory location for detaillog to be stored */ if ((errorcode == OSPC_ERR_NO_ERROR) && (ospLoadRoutes(transaction, destcount, _osp_device_ip, sourcedev, destination, authtime) == 0)) { LOG(L_INFO, "osp: there are '%d' OSP routes, call_id '%.*s'\n", destcount, callids[0]->ospmCallIdLen, callids[0]->ospmCallIdVal); result = MODULE_RETURNCODE_TRUE; } else { LOG(L_ERR, "osp: ERROR: failed to request auth and routing (%i), call_id '%.*s\n", errorcode, callids[0]->ospmCallIdLen, callids[0]->ospmCallIdVal); switch (errorcode) { case OSPC_ERR_TRAN_ROUTE_BLOCKED: result = -403; break; case OSPC_ERR_TRAN_ROUTE_NOT_FOUND: result = -404; break; case OSPC_ERR_NO_ERROR: /* AuthRsp ok but ospLoadRoutes fails */ result = -500; break; default: result = MODULE_RETURNCODE_FALSE; break; } } } if (callids[0] != NULL) { OSPPCallIdDelete(&(callids[0])); } if (transaction != -1) { OSPPTransactionDelete(transaction); } return result; }