Skip to content

Commit

Permalink
Updated to support CNAM diversion use case.
Browse files Browse the repository at this point in the history
  • Loading branch information
Di-Shi Sun committed Oct 6, 2015
1 parent 1de872c commit 2ef4444
Show file tree
Hide file tree
Showing 13 changed files with 398 additions and 346 deletions.
69 changes: 25 additions & 44 deletions modules/osp/README
Expand Up @@ -67,11 +67,10 @@ Di-Shi Sun
1.4.4. requestosprouting()
1.4.5. checkosproute()
1.4.6. prepareosproute()
1.4.7. prepareredirectosproutes()
1.4.7. prepareospresponse()
1.4.8. prepareallosproutes()
1.4.9. preparecnamresponse()
1.4.10. checkcallingtranslation()
1.4.11. reportospusage()
1.4.9. checkcallingtranslation()
1.4.10. reportospusage()

2. Developer Guide

Expand Down Expand Up @@ -114,11 +113,10 @@ Di-Shi Sun
1.33. requestosprouting usage
1.34. checkosproute usage
1.35. prepareosproute usage
1.36. prepareredirectosproutes usage
1.36. prepareospresponse usage
1.37. prepareallosproutes usage
1.38. preparecnamresponse usage
1.39. checkcallingtranslation usage
1.40. reportospusage usage
1.38. checkcallingtranslation usage
1.39. reportospusage usage

Chapter 1. Admin Guide

Expand Down Expand Up @@ -561,7 +559,7 @@ modparam("osp", "destination_media_avp", "$avp(destmedia)")
This function checks for the existence of the OSP-Auth-Token
header field.

This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.
This function can be used from REQUEST_ROUTE.

Example 1.30. checkospheader usage
...
Expand All @@ -580,7 +578,7 @@ if (checkospheader()) {
header is found or the header token is invalid or expired, -1
is returned; on successful validation 1 is returned.

This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.
This function can be used from REQUEST_ROUTE.

Example 1.31. validateospheader usage
...
Expand Down Expand Up @@ -625,7 +623,7 @@ if (getlocaladdress()) {
authentication failed or there is no route to destination or
the route is blocked) -1 is returned.

This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.
This function can be used from REQUEST_ROUTE.

Example 1.33. requestosprouting usage
...
Expand All @@ -641,7 +639,7 @@ if (requestosprouting()) {
This function is used to check if there is any route for the
call.

This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.
This function can be used from REQUEST_ROUTE.

Example 1.34. checkosproute usage
...
Expand Down Expand Up @@ -675,22 +673,22 @@ if (prepareosproute()) {
};
...

1.4.7. prepareredirectosproutes()
1.4.7. prepareospresponse()

This function tries to prepare all the routes in the list
returned by the peering server into a SIP 300 Redirect message.
The message is then replied to the source. If unsuccessful in
preparing the routes a SIP 500 is sent back and a trace message
is logged.
returned by the peering server into SIP 300 Redirect or SIP 380
Alternative Service message. The message is then replied to the
source. If unsuccessful in preparing the routes a SIP 500 is
sent back and a trace message is logged.

This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.
This function can be used from REQUEST_ROUTE.

Example 1.36. prepareredirectosproutes usage
Example 1.36. prepareospresponse usage
...
if (prepareredirectosproutes()) {
log(1,"Routes are prepared, now redirecting the call\n");
if (prepareospresponse()) {
log(1,"Response is prepared.\n");
} else {
log(1,"Could not prepare the routes. No destination available\n");
log(1,"Could not prepare the response.\n");
};
...

Expand All @@ -701,7 +699,7 @@ if (prepareredirectosproutes()) {
to the destinations. If unsuccessful in preparing the routes a
SIP 500 is sent back and a trace message is logged.

This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.
This function can be used from REQUEST_ROUTE.

Example 1.37. prepareallosproutes usage
...
Expand All @@ -712,24 +710,7 @@ if (prepareallosproutes()) {
};
...

1.4.9. preparecnamresponse()

This function tries to prepare the CNAM returned by the peering
server. If unsuccessful in preparing the routes a SIP 500 is
sent back and a trace message is logged.

This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.

Example 1.38. preparecnamresponse usage
...
if (preparecnamresponse()) {
log(1,"CNAM is prepared, new sending the response\n");
} else {
log(1,"Could not prepare CNAM\n");
};
...

1.4.10. checkcallingtranslation()
1.4.9. checkcallingtranslation()

This function is used to check if the calling number is
translated. Before calling checkcallingtranslation,
Expand All @@ -742,7 +723,7 @@ if (preparecnamresponse()) {

This function can be used from BRANCH_ROUTE.

Example 1.39. checkcallingtranslation usage
Example 1.38. checkcallingtranslation usage
...
if (checkcallingtranslation()) {
# Remove the Remote_Party-ID from the received message
Expand All @@ -754,7 +735,7 @@ if (checkcallingtranslation()) {
}
...

1.4.11. reportospusage()
1.4.10. reportospusage()

This function should be called after receiving a BYE message.
If the message contains an OSP cookie, the function will
Expand All @@ -771,7 +752,7 @@ if (checkcallingtranslation()) {

This function can be used from REQUEST_ROUTE.

Example 1.40. reportospusage usage
Example 1.39. reportospusage usage
...
if (is_direction("downstream")) {
log(1,"This BYE message is from SOURCE\n");
Expand Down
4 changes: 4 additions & 0 deletions modules/osp/RELEASE-NOTES.txt
Expand Up @@ -179,3 +179,7 @@ Support TotalSetupAttempts for completed calls.
2015 September 1
Updated to support media addresses, local address and provider post dial delay.
Updated to support CNAM.

2015 September 15
Updated to support CNAM diversion use case.

84 changes: 76 additions & 8 deletions modules/osp/destination.c
Expand Up @@ -39,18 +39,20 @@
#include "destination.h"
#include "usage.h"

extern int _osp_inbound_avpid;
extern int _osp_origdest_avpid;
extern int _osp_termdest_avpid;
extern int _osp_calling_avpid;
extern int _osp_destmedia_avpid;
extern unsigned short _osp_destmedia_avptype;

/* Name of AVP of OSP */
static str OSP_INBOUND_NAME = {"_osp_inbound_", 13};
static str OSP_ORIGDEST_NAME = {"_osp_orig_dests_", 16};
static str OSP_TERMDEST_NAME = {"_osp_term_dests_", 16};
static str OSP_CALLING_NAME = {"_osp_calling_translated_", 24};

static int ospSaveDestination(osp_dest* dest, int name);
static int ospSaveDestination(osp_dest* dest, int avpid);
static void ospRecordCode(int code, osp_dest* dest);
static int ospIsToReportUsage(int code);

Expand All @@ -60,6 +62,11 @@ static int ospIsToReportUsage(int code);
*/
int ospParseAvps(void)
{
if (parse_avp_spec(&OSP_INBOUND_NAME, &_osp_inbound_avpid)) {
LM_ERR("cannot get INBOUND AVP id\n");
return -1;
}

if (parse_avp_spec(&OSP_ORIGDEST_NAME, &_osp_origdest_avpid)) {
LM_ERR("cannot get ORIGDEST AVP id\n");
return -1;
Expand All @@ -78,6 +85,67 @@ int ospParseAvps(void)
return 0;
}

/*
* Initialize inbound info structure
* param inbound Inbound info data structure
*/
void ospInitInboundInfo(
osp_inbound* inbound)
{
memset(inbound, 0, sizeof(osp_inbound));
}

/*
* Save inbound info as an AVP
* avpid - osp_inbound_avpid
* value - osp_inbound wrapped in a string
* param inbound Inbound info structure
* return 0 success, -1 failure
*/
int ospSaveInboundInfo(
osp_inbound* inbound)
{
str wrapper;
int result = -1;

wrapper.s = (char*)inbound;
wrapper.len = sizeof(osp_inbound);

/*
* add_avp will make a private copy of both the avpid and value in shared
* memory which will be released by TM at the end of the transaction
*/
if (add_avp(AVP_VAL_STR, _osp_inbound_avpid, (int_str)wrapper) == 0) {
LM_DBG("inbound info saved\n");
result = 0;
} else {
LM_ERR("failed to save inbound info\n");
}

return result;
}

/*
* Retrieved the inbound info from an AVP
* avpid - osp_inbound_avpid
* value - osp_inbound wrapped in a string
* return NULL on failure
*/
osp_inbound* ospGetInboundInfo(void)
{
int_str inboundval;
osp_inbound* inbound = NULL;

if (search_first_avp(AVP_VAL_STR, _osp_inbound_avpid, &inboundval, 0) != NULL) {
/* OSP inbound info is wrapped in a string */
inbound = (osp_inbound*)inboundval.s.s;

LM_DBG("inbound info found\n");
}

return inbound;
}

/*
* Initialize destination structure
* param dest Destination data structure
Expand All @@ -98,7 +166,7 @@ osp_dest* ospInitDestination(

/*
* Save destination as an AVP
* name - osp_origdest_id / osp_origdest_id
* avpid - osp_origdest_avpid / osp_termdest_avpid
* value - osp_dest wrapped in a string
* param dest Destination structure
* param avpid ID of AVP
Expand All @@ -115,8 +183,8 @@ static int ospSaveDestination(
wrapper.len = sizeof(osp_dest);

/*
* add_avp will make a private copy of both the name and value in shared memory
* which will be released by TM at the end of the transaction
* add_avp will make a private copy of both the avpid and value in shared
* memory which will be released by TM at the end of the transaction
*/
if (add_avp(AVP_VAL_STR, avpid, (int_str)wrapper) == 0) {
LM_DBG("destination saved\n");
Expand Down Expand Up @@ -152,7 +220,7 @@ int ospSaveTermDestination(

/*
* Check if there is an unused and supported originate destination from an AVP
* name - OSP_ORIGDEST_NAME
* avpid - osp_origdest_avpid
* value - osp_dest wrapped in a string
* search unused (used==0) & supported (support==1)
* return 0 success, -1 failure
Expand Down Expand Up @@ -200,7 +268,7 @@ int ospCheckOrigDestination(void)

/*
* Retrieved an unused and supported originate destination from an AVP
* name - OSP_ORIGDEST_NAME
* avpid - osp_origdest_avpid
* value - osp_dest wrapped in a string
* There can be 0, 1 or more originate destinations.
* Find the 1st unused destination (used==0) & supported (support==1),
Expand Down Expand Up @@ -250,7 +318,7 @@ osp_dest* ospGetNextOrigDestination(void)

/*
* Retrieved the last used originate destination from an AVP
* name - OSP_ORIGDEST_NAME
* avpid - osp_origdest_avpid
* value - osp_dest wrapped in a string
* There can be 0, 1 or more destinations.
* Find the last used destination (used==1) & supported (support==1),
Expand Down Expand Up @@ -290,7 +358,7 @@ osp_dest* ospGetLastOrigDestination(void)

/*
* Retrieved the terminate destination from an AVP
* name - OSP_TERMDEST_NAME
* avpid - osp_termdest_avpid
* value - osp_dest wrapped in a string
* There can be 0 or 1 term destinations. Find and return it.
* return NULL on failure (no terminate destination)
Expand Down
34 changes: 21 additions & 13 deletions modules/osp/destination.h
Expand Up @@ -35,6 +35,23 @@
#include <osp/osp.h>
#include "osp_mod.h"

typedef struct _osp_inbound {
char ingress[OSP_STRBUF_SIZE];
char srcdev[OSP_STRBUF_SIZE];
char source[OSP_STRBUF_SIZE];
char snid[OSP_STRBUF_SIZE];
char calling[OSP_STRBUF_SIZE];
char called[OSP_STRBUF_SIZE];
char display[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 srcmedia[OSP_STRBUF_SIZE];
time_t authtime;
} osp_inbound;

typedef struct _osp_dest {
int type;
unsigned int destcount;
Expand All @@ -48,34 +65,22 @@ typedef struct _osp_dest {
unsigned int callidsize;
char calling[OSP_STRBUF_SIZE];
char called[OSP_STRBUF_SIZE];
char origcalled[OSP_STRBUF_SIZE];
char srcdev[OSP_STRBUF_SIZE];
char source[OSP_STRBUF_SIZE];
char host[OSP_STRBUF_SIZE];
char destdev[OSP_STRBUF_SIZE];
char snid[OSP_STRBUF_SIZE];
char dnid[OSP_STRBUF_SIZE];
char nprn[OSP_STRBUF_SIZE];
char npcic[OSP_STRBUF_SIZE];
int npdi;
char opname[OSPC_OPNAME_NUMBER][OSP_STRBUF_SIZE];
char display[OSP_STRBUF_SIZE];
char cnam[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 srcmedia[OSP_STRBUF_SIZE];
char destmedia[OSP_STRBUF_SIZE];
char ingress[OSP_STRBUF_SIZE];
char egress[OSP_STRBUF_SIZE];
unsigned char token[OSP_TOKENBUF_SIZE];
unsigned int tokensize;
unsigned int timelimit;
OSPE_PROTOCOL_NAME protocol;
OSPE_SERVICE srvtype;
int lastcode;
time_t authtime;
time_t starttime;
time_t endtime;
time_t time100;
Expand All @@ -84,6 +89,9 @@ typedef struct _osp_dest {
} osp_dest;

int ospParseAvps(void);
void ospInitInboundInfo(osp_inbound* inbound);
int ospSaveInboundInfo(osp_inbound* inbound);
osp_inbound* ospGetInboundInfo(void);
osp_dest* ospInitDestination(osp_dest* dest);
int ospSaveOrigDestination(osp_dest* dest);
int ospSaveTermDestination(osp_dest* dest);
Expand Down

0 comments on commit 2ef4444

Please sign in to comment.