record network-provided-number as ANI when supplied (bug #4537)

git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@229 2fbb986a-6c06-0410-b554-c9c1f0a7f128
This commit is contained in:
Kevin P. Fleming 2005-06-21 20:37:22 +00:00
parent 849ec03cb0
commit 6694b84e88
4 changed files with 46 additions and 29 deletions

View File

@ -299,6 +299,7 @@ typedef struct pri_event_ring {
int channel; /* Channel requested */ int channel; /* Channel requested */
int callingpres; /* Presentation of Calling CallerID */ int callingpres; /* Presentation of Calling CallerID */
int callingplan; /* Dialing plan of Calling entity */ int callingplan; /* Dialing plan of Calling entity */
char callingani[256]; /* Calling ANI */
char callingnum[256]; /* Calling number */ char callingnum[256]; /* Calling number */
char callingname[256]; /* Calling name (if provided) */ char callingname[256]; /* Calling name (if provided) */
int calledplan; /* Dialing plan of Called number */ int calledplan; /* Dialing plan of Called number */
@ -558,6 +559,7 @@ extern void pri_enslave(struct pri *master, struct pri *slave);
#define PRI_RECEIVE_SUBADDR #define PRI_RECEIVE_SUBADDR
#define PRI_REDIRECTING_REASON #define PRI_REDIRECTING_REASON
#define PRI_AOC_UNITS #define PRI_AOC_UNITS
#define PRI_ANI
/* Send notification */ /* Send notification */
extern int pri_notify(struct pri *pri, q931_call *c, int channel, int info); extern int pri_notify(struct pri *pri, q931_call *c, int channel, int info);

View File

@ -187,7 +187,7 @@ int asn1_name_decode(void * data, int len, char *namebuf, int buflen)
int datalen = 0, res = 0; int datalen = 0, res = 0;
if (comp->len == ASN1_LEN_INDEF) { if (comp->len == ASN1_LEN_INDEF) {
datalen = strlen(comp->data); datalen = strlen((char *)comp->data);
res = datalen + 2; res = datalen + 2;
} else } else
datalen = res = comp->len; datalen = res = comp->len;
@ -234,7 +234,7 @@ static int rose_number_digits_decode(struct pri *pri, q931_call *call, unsigned
return -1; return -1;
} }
if (comp->len == ASN1_LEN_INDEF) { if (comp->len == ASN1_LEN_INDEF) {
datalen = strlen(comp->data); datalen = strlen((char *)comp->data);
res = datalen + 2; res = datalen + 2;
} else } else
res = datalen = comp->len; res = datalen = comp->len;

View File

@ -200,7 +200,8 @@ struct q931_call {
int callerplan; int callerplan;
int callerpres; /* Caller presentation */ int callerpres; /* Caller presentation */
char callernum[256]; /* Caller */ char callerani[256]; /* Caller */
char callernum[256];
char callername[256]; char callername[256];
char digitbuf[64]; /* Buffer for digits that come in KEYPAD_FACILITY */ char digitbuf[64]; /* Buffer for digits that come in KEYPAD_FACILITY */

66
q931.c
View File

@ -866,7 +866,7 @@ static FUNC_SEND(transmit_redirecting_number)
{ {
if (order > 1) if (order > 1)
return 0; return 0;
if (call->redirectingnum && strlen(call->redirectingnum)) { if (call->redirectingnum && *call->redirectingnum) {
ie->data[0] = call->redirectingplan; ie->data[0] = call->redirectingplan;
ie->data[1] = call->redirectingpres; ie->data[1] = call->redirectingpres;
ie->data[2] = (call->redirectingreason & 0x0f) | 0x80; ie->data[2] = (call->redirectingreason & 0x0f) | 0x80;
@ -904,32 +904,45 @@ static FUNC_RECV(receive_called_party_number)
static FUNC_SEND(transmit_called_party_number) static FUNC_SEND(transmit_called_party_number)
{ {
ie->data[0] = 0x80 | call->calledplan; ie->data[0] = 0x80 | call->calledplan;
if (strlen(call->callednum)) if (*call->callednum)
memcpy(ie->data + 1, call->callednum, strlen(call->callednum)); memcpy(ie->data + 1, call->callednum, strlen(call->callednum));
return strlen(call->callednum) + 3; return strlen(call->callednum) + 3;
} }
static FUNC_RECV(receive_calling_party_number) static FUNC_RECV(receive_calling_party_number)
{ {
int extbit; u_int8_t *data;
size_t length;
int extbit;
call->callerplan = ie->data[0] & 0x7f; call->callerplan = ie->data[0] & 0x7f;
extbit = (ie->data[0] >> 7) & 0x01; extbit = (ie->data[0] >> 7) & 0x01;
/* Somebody's broken PRI stack sent a calling if (extbit) {
party number IE twice. One with the callernam data = ie->data + 1;
and one without. */ length = len - 3;
if (strlen(call->callernum)) call->callerpres = 0; /* PI presentation allowed
return 0; SI user-provided, not screened */
}
else {
data = ie->data + 2;
length = len - 4;
call->callerpres = ie->data[1] & 0x7f;
}
if (call->callerpres == PRES_ALLOWED_NETWORK_NUMBER ||
call->callerpres == PRES_PROHIB_NETWORK_NUMBER) {
q931_get_number((u_int8_t *)call->callerani, sizeof(call->callerani), data, length);
/*
* Copy ANI to Caller*ID if Caller*ID is not already set
*/
if (!*call->callernum)
strncpy(call->callernum, call->callerani, sizeof(call->callernum) - 1);
}
else
q931_get_number((u_int8_t *)call->callernum, sizeof(call->callernum), data, length);
if (extbit) {
q931_get_number((unsigned char *) call->callernum, sizeof(call->callernum), ie->data + 1, len - 3);
call->callerpres = 0; /* PI presentation allowed
SI user-provided, not screened */
} else {
q931_get_number((unsigned char *) call->callernum, sizeof(call->callernum), ie->data + 2, len - 4);
call->callerpres = ie->data[1] & 0x7f;
}
return 0; return 0;
} }
@ -937,7 +950,7 @@ static FUNC_SEND(transmit_calling_party_number)
{ {
ie->data[0] = call->callerplan; ie->data[0] = call->callerplan;
ie->data[1] = 0x80 | call->callerpres; ie->data[1] = 0x80 | call->callerpres;
if (strlen(call->callernum)) if (*call->callernum)
memcpy(ie->data + 2, call->callernum, strlen(call->callernum)); memcpy(ie->data + 2, call->callernum, strlen(call->callernum));
return strlen(call->callernum) + 4; return strlen(call->callernum) + 4;
} }
@ -1027,7 +1040,7 @@ static FUNC_RECV(receive_display)
static FUNC_SEND(transmit_display) static FUNC_SEND(transmit_display)
{ {
int i; int i;
if ((pri->switchtype != PRI_SWITCH_NI1) && strlen(call->callername)) { if ((pri->switchtype != PRI_SWITCH_NI1) && *call->callername) {
i = 0; i = 0;
if(pri->switchtype != PRI_SWITCH_EUROISDN_E1) { if(pri->switchtype != PRI_SWITCH_EUROISDN_E1) {
ie->data[0] = 0xb1; ie->data[0] = 0xb1;
@ -1150,7 +1163,7 @@ static FUNC_SEND(transmit_facility)
} }
} while (0); } while (0);
} }
if (/*(pri->switchtype == PRI_SWITCH_EUROISDN_E1) &&*/ call->redirectingnum && strlen(call->redirectingnum)) { if (/*(pri->switchtype == PRI_SWITCH_EUROISDN_E1) &&*/ call->redirectingnum && *call->redirectingnum) {
if (!(first_i = i)) { if (!(first_i = i)) {
/* Add protocol information header */ /* Add protocol information header */
ie->data[i++] = 0x80 | Q932_PROTOCOL_ROSE; ie->data[i++] = 0x80 | Q932_PROTOCOL_ROSE;
@ -1185,7 +1198,7 @@ static FUNC_SEND(transmit_facility)
switch(call->redirectingpres) { switch(call->redirectingpres) {
case PRES_ALLOWED_USER_NUMBER_NOT_SCREENED: case PRES_ALLOWED_USER_NUMBER_NOT_SCREENED:
case PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN: case PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN:
if (call->redirectingnum && strlen(call->redirectingnum)) { if (call->redirectingnum && *call->redirectingnum) {
ASN1_ADD_SIMPLE(comp, 0xA0, ie->data, i); ASN1_ADD_SIMPLE(comp, 0xA0, ie->data, i);
ASN1_PUSH(compstk, compsp, comp); ASN1_PUSH(compstk, compsp, comp);
@ -1234,7 +1247,7 @@ static FUNC_SEND(transmit_facility)
switch(call->redirectingpres) { switch(call->redirectingpres) {
case PRES_ALLOWED_USER_NUMBER_NOT_SCREENED: case PRES_ALLOWED_USER_NUMBER_NOT_SCREENED:
case PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN: case PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN:
if (call->redirectingnum && strlen(call->redirectingnum)) { if (call->redirectingnum && *call->redirectingnum) {
ASN1_ADD_SIMPLE(comp, 0xA0, ie->data, i); ASN1_ADD_SIMPLE(comp, 0xA0, ie->data, i);
ASN1_PUSH(compstk, compsp, comp); ASN1_PUSH(compstk, compsp, comp);
@ -1569,7 +1582,7 @@ static void dump_ie_data(unsigned char *c, int len)
((*c >= 'a') && (*c <= 'z')) || ((*c >= 'a') && (*c <= 'z')) ||
((*c >= '0') && (*c <= '9'))) { ((*c >= '0') && (*c <= '9'))) {
if (!lastascii) { if (!lastascii) {
if (strlen(tmp)) { if (*tmp) {
tmp[x++] = ','; tmp[x++] = ',';
tmp[x++] = ' '; tmp[x++] = ' ';
} }
@ -1581,7 +1594,7 @@ static void dump_ie_data(unsigned char *c, int len)
if (lastascii) { if (lastascii) {
tmp[x++] = '\''; tmp[x++] = '\'';
} }
if (strlen(tmp)) { if (*tmp) {
tmp[x++] = ','; tmp[x++] = ',';
tmp[x++] = ' '; tmp[x++] = ' ';
} }
@ -3368,6 +3381,7 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
pri->ev.ring.callingpres = c->callerpres; pri->ev.ring.callingpres = c->callerpres;
pri->ev.ring.callingplan = c->callerplan; pri->ev.ring.callingplan = c->callerplan;
pri->ev.ring.ani2 = c->ani2; pri->ev.ring.ani2 = c->ani2;
strncpy(pri->ev.ring.callingani, c->callerani, sizeof(pri->ev.ring.callingani) - 1);
strncpy(pri->ev.ring.callingnum, c->callernum, sizeof(pri->ev.ring.callingnum) - 1); strncpy(pri->ev.ring.callingnum, c->callernum, sizeof(pri->ev.ring.callingnum) - 1);
strncpy(pri->ev.ring.callingname, c->callername, sizeof(pri->ev.ring.callingname) - 1); strncpy(pri->ev.ring.callingname, c->callername, sizeof(pri->ev.ring.callingname) - 1);
pri->ev.ring.calledplan = c->calledplan; pri->ev.ring.calledplan = c->calledplan;
@ -3434,7 +3448,7 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
} }
pri->ev.e = PRI_EVENT_FACNAME; pri->ev.e = PRI_EVENT_FACNAME;
strncpy(pri->ev.facname.callingname, c->callername, sizeof(pri->ev.facname.callingname) - 1); strncpy(pri->ev.facname.callingname, c->callername, sizeof(pri->ev.facname.callingname) - 1);
strncpy(pri->ev.facname.callingnum, c->callernum, sizeof(pri->ev.facname.callingname) - 1); strncpy(pri->ev.facname.callingnum, c->callernum, sizeof(pri->ev.facname.callingnum) - 1);
pri->ev.facname.channel = c->channelno | (c->ds1no << 8) | (c->ds1explicit << 16); pri->ev.facname.channel = c->channelno | (c->ds1no << 8) | (c->ds1explicit << 16);
pri->ev.facname.cref = c->cr; pri->ev.facname.cref = c->cr;
pri->ev.facname.call = c; pri->ev.facname.call = c;