Clean up code in res_adsi.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@83182 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Joshua Colp
2007-09-19 20:01:34 +00:00
parent 2897a41de8
commit c1d1440e59

View File

@@ -76,22 +76,19 @@ static int alignment = 0;
static int adsi_generate(unsigned char *buf, int msgtype, unsigned char *msg, int msglen, int msgnum, int last, int codec) static int adsi_generate(unsigned char *buf, int msgtype, unsigned char *msg, int msglen, int msgnum, int last, int codec)
{ {
int sum; int sum, x, bytes = 0;
int x;
int bytes=0;
/* Initial carrier (imaginary) */ /* Initial carrier (imaginary) */
float cr = 1.0; float cr = 1.0, ci = 0.0, scont = 0.0;
float ci = 0.0;
float scont = 0.0;
if (msglen > 255) if (msglen > 255)
msglen = 255; msglen = 255;
/* If first message, Send 150ms of MARK's */ /* If first message, Send 150ms of MARK's */
if (msgnum == 1) { if (msgnum == 1) {
for (x=0;x<150;x++) /* was 150 */ for (x = 0; x < 150; x++) /* was 150 */
PUT_CLID_MARKMS; PUT_CLID_MARKMS;
} }
/* Put message type */ /* Put message type */
PUT_CLID(msgtype); PUT_CLID(msgtype);
sum = msgtype; sum = msgtype;
@@ -105,7 +102,7 @@ static int adsi_generate(unsigned char *buf, int msgtype, unsigned char *msg, in
sum += msgnum; sum += msgnum;
/* Put actual message */ /* Put actual message */
for (x=0;x<msglen;x++) { for (x = 0; x < msglen; x++) {
PUT_CLID(msg[x]); PUT_CLID(msg[x]);
sum += msg[x]; sum += msg[x];
} }
@@ -116,7 +113,7 @@ static int adsi_generate(unsigned char *buf, int msgtype, unsigned char *msg, in
#if 0 #if 0
if (last) { if (last) {
/* Put trailing marks */ /* Put trailing marks */
for (x=0;x<50;x++) for (x = 0; x < 50; x++)
PUT_CLID_MARKMS; PUT_CLID_MARKMS;
} }
#endif #endif
@@ -162,34 +159,38 @@ static int adsi_careful_send(struct ast_channel *chan, unsigned char *buf, int l
about it */ about it */
if (ast_waitfor(chan, 1000) < 1) if (ast_waitfor(chan, 1000) < 1)
return -1; return -1;
inf = ast_read(chan);
/* Detect hangup */ /* Detect hangup */
if (!inf) if (!(inf = ast_read(chan)))
return -1; return -1;
if (inf->frametype == AST_FRAME_VOICE) {
/* Read a voice frame */ /* Drop any frames that are not voice */
if (inf->subclass != AST_FORMAT_ULAW) { if (inf->frametype != AST_FRAME_VOICE) {
ast_log(LOG_WARNING, "Channel not in ulaw?\n"); ast_frfree(inf);
return -1; continue;
}
/* Send no more than they sent us */
if (amt > inf->datalen)
amt = inf->datalen;
else if (remainder)
*remainder = inf->datalen - amt;
outf.frametype = AST_FRAME_VOICE;
outf.subclass = AST_FORMAT_ULAW;
outf.data = buf;
outf.datalen = amt;
outf.samples = amt;
if (ast_write(chan, &outf)) {
ast_log(LOG_WARNING, "Failed to carefully write frame\n");
return -1;
}
/* Update pointers and lengths */
buf += amt;
len -= amt;
} }
if (inf->subclass != AST_FORMAT_ULAW) {
ast_log(LOG_WARNING, "Channel not in ulaw?\n");
ast_frfree(inf);
return -1;
}
/* Send no more than they sent us */
if (amt > inf->datalen)
amt = inf->datalen;
else if (remainder)
*remainder = inf->datalen - amt;
outf.frametype = AST_FRAME_VOICE;
outf.subclass = AST_FORMAT_ULAW;
outf.data = buf;
outf.datalen = amt;
outf.samples = amt;
if (ast_write(chan, &outf)) {
ast_log(LOG_WARNING, "Failed to carefully write frame\n");
return -1;
}
/* Update pointers and lengths */
buf += amt;
len -= amt;
ast_frfree(inf); ast_frfree(inf);
} }
return 0; return 0;
@@ -199,18 +200,9 @@ static int __adsi_transmit_messages(struct ast_channel *chan, unsigned char **ms
{ {
/* msglen must be no more than 256 bits, each */ /* msglen must be no more than 256 bits, each */
unsigned char buf[24000 * 5]; unsigned char buf[24000 * 5];
int pos = 0, res; int pos = 0, res, x, start = 0, retries = 0, waittime, rem = 0, def;
int x;
int start=0;
int retries = 0;
char ack[3]; char ack[3];
/* Wait up to 500 ms for initial ACK */
int waittime;
struct ast_frame *f; struct ast_frame *f;
int rem = 0;
int def;
if (chan->adsicpe == AST_ADSI_UNAVAILABLE) { if (chan->adsicpe == AST_ADSI_UNAVAILABLE) {
/* Don't bother if we know they don't support ADSI */ /* Don't bother if we know they don't support ADSI */
@@ -224,9 +216,9 @@ static int __adsi_transmit_messages(struct ast_channel *chan, unsigned char **ms
ast_gen_cas(buf, 0, 680, AST_FORMAT_ULAW); ast_gen_cas(buf, 0, 680, AST_FORMAT_ULAW);
/* Send CAS */ /* Send CAS */
if (adsi_careful_send(chan, buf, 680, NULL)) { if (adsi_careful_send(chan, buf, 680, NULL))
ast_log(LOG_WARNING, "Unable to send CAS\n"); ast_log(LOG_WARNING, "Unable to send CAS\n");
}
/* Wait For DTMF result */ /* Wait For DTMF result */
waittime = 500; waittime = 500;
for(;;) { for(;;) {
@@ -239,8 +231,7 @@ static int __adsi_transmit_messages(struct ast_channel *chan, unsigned char **ms
return -1; return -1;
} }
waittime = res; waittime = res;
f = ast_read(chan); if (!(f = ast_read(chan))) {
if (!f) {
ast_debug(1, "Hangup in ADSI\n"); ast_debug(1, "Hangup in ADSI\n");
return -1; return -1;
} }
@@ -251,9 +242,9 @@ static int __adsi_transmit_messages(struct ast_channel *chan, unsigned char **ms
chan->adsicpe = AST_ADSI_AVAILABLE; chan->adsicpe = AST_ADSI_AVAILABLE;
break; break;
} else { } else {
if (f->subclass == 'D') { if (f->subclass == 'D')
ast_debug(1, "Off-hook capable CPE only, not ADSI\n"); ast_debug(1, "Off-hook capable CPE only, not ADSI\n");
} else else
ast_log(LOG_WARNING, "Unknown ADSI response '%c'\n", f->subclass); ast_log(LOG_WARNING, "Unknown ADSI response '%c'\n", f->subclass);
if (!chan->adsicpe) if (!chan->adsicpe)
chan->adsicpe = AST_ADSI_UNAVAILABLE; chan->adsicpe = AST_ADSI_UNAVAILABLE;
@@ -274,9 +265,8 @@ static int __adsi_transmit_messages(struct ast_channel *chan, unsigned char **ms
#if 1 #if 1
def= ast_channel_defer_dtmf(chan); def= ast_channel_defer_dtmf(chan);
#endif #endif
while((x < 6) && msg[x]) { while ((x < 6) && msg[x]) {
res = adsi_generate(buf + pos, msgtype[x], msg[x], msglen[x], x+1 - start, (x == 5) || !msg[x+1], AST_FORMAT_ULAW); if ((res = adsi_generate(buf + pos, msgtype[x], msg[x], msglen[x], x+1 - start, (x == 5) || !msg[x+1], AST_FORMAT_ULAW)) < 0) {
if (res < 0) {
ast_log(LOG_WARNING, "Failed to generate ADSI message %d on channel %s\n", x + 1, chan->name); ast_log(LOG_WARNING, "Failed to generate ADSI message %d on channel %s\n", x + 1, chan->name);
return -1; return -1;
} }
@@ -296,10 +286,8 @@ static int __adsi_transmit_messages(struct ast_channel *chan, unsigned char **ms
ast_debug(1, "Sent total spill of %d bytes\n", pos); ast_debug(1, "Sent total spill of %d bytes\n", pos);
memset(ack, 0, sizeof(ack)); memset(ack, 0, sizeof(ack));
/* Get real result */ /* Get real result and check for hangup */
res = ast_readstring(chan, ack, 2, 1000, 1000, ""); if ((res = ast_readstring(chan, ack, 2, 1000, 1000, "")) < 0)
/* Check for hangup */
if (res < 0)
return -1; return -1;
if (ack[0] == 'D') { if (ack[0] == 'D') {
ast_debug(1, "Acked up to message %d\n", atoi(ack + 1)); start += atoi(ack + 1); ast_debug(1, "Acked up to message %d\n", atoi(ack + 1)); start += atoi(ack + 1);
@@ -325,10 +313,10 @@ static int __adsi_transmit_messages(struct ast_channel *chan, unsigned char **ms
static int _ast_adsi_begin_download(struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version) static int _ast_adsi_begin_download(struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version)
{ {
int bytes; int bytes = 0;
unsigned char buf[256]; unsigned char buf[256];
char ack[2]; char ack[2];
bytes = 0;
/* Setup the resident soft key stuff, a piece at a time */ /* Setup the resident soft key stuff, a piece at a time */
/* Upload what scripts we can for voicemail ahead of time */ /* Upload what scripts we can for voicemail ahead of time */
bytes += ast_adsi_download_connect(buf + bytes, service, fdn, sec, version); bytes += ast_adsi_download_connect(buf + bytes, service, fdn, sec, version);
@@ -344,9 +332,9 @@ static int _ast_adsi_begin_download(struct ast_channel *chan, char *service, uns
static int _ast_adsi_end_download(struct ast_channel *chan) static int _ast_adsi_end_download(struct ast_channel *chan)
{ {
int bytes; int bytes = 0;
unsigned char buf[256]; unsigned char buf[256];
bytes = 0;
/* Setup the resident soft key stuff, a piece at a time */ /* Setup the resident soft key stuff, a piece at a time */
/* Upload what scripts we can for voicemail ahead of time */ /* Upload what scripts we can for voicemail ahead of time */
bytes += ast_adsi_download_disconnect(buf + bytes); bytes += ast_adsi_download_disconnect(buf + bytes);
@@ -358,20 +346,9 @@ static int _ast_adsi_end_download(struct ast_channel *chan)
static int _ast_adsi_transmit_message_full(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype, int dowait) static int _ast_adsi_transmit_message_full(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype, int dowait)
{ {
unsigned char *msgs[5] = { NULL, NULL, NULL, NULL, NULL }; unsigned char *msgs[5] = { NULL, NULL, NULL, NULL, NULL };
int msglens[5]; int msglens[5], msgtypes[5], newdatamode = (chan->adsicpe & ADSI_FLAG_DATAMODE), res, x, writeformat = chan->writeformat, readformat = chan->readformat, waitforswitch = 0;
int msgtypes[5];
int newdatamode;
int res;
int x;
int writeformat, readformat;
int waitforswitch = 0;
writeformat = chan->writeformat; for (x = 0; x < msglen; x += (msg[x+1]+2)) {
readformat = chan->readformat;
newdatamode = chan->adsicpe & ADSI_FLAG_DATAMODE;
for (x=0;x<msglen;x+=(msg[x+1]+2)) {
if (msg[x] == ADSI_SWITCH_TO_DATA) { if (msg[x] == ADSI_SWITCH_TO_DATA) {
ast_debug(1, "Switch to data is sent!\n"); ast_debug(1, "Switch to data is sent!\n");
waitforswitch++; waitforswitch++;
@@ -439,7 +416,7 @@ static int _ast_adsi_transmit_message(struct ast_channel *chan, unsigned char *m
static inline int ccopy(unsigned char *dst, const unsigned char *src, int max) static inline int ccopy(unsigned char *dst, const unsigned char *src, int max)
{ {
int x=0; int x = 0;
/* Carefully copy the requested data */ /* Carefully copy the requested data */
while ((x < max) && src[x] && (src[x] != 0xff)) { while ((x < max) && src[x] && (src[x] != 0xff)) {
dst[x] = src[x]; dst[x] = src[x];
@@ -450,11 +427,12 @@ static inline int ccopy(unsigned char *dst, const unsigned char *src, int max)
static int _ast_adsi_load_soft_key(unsigned char *buf, int key, const char *llabel, const char *slabel, char *ret, int data) static int _ast_adsi_load_soft_key(unsigned char *buf, int key, const char *llabel, const char *slabel, char *ret, int data)
{ {
int bytes=0; int bytes = 0;
/* Abort if invalid key specified */ /* Abort if invalid key specified */
if ((key < 2) || (key > 33)) if ((key < 2) || (key > 33))
return -1; return -1;
buf[bytes++] = ADSI_LOAD_SOFTKEY; buf[bytes++] = ADSI_LOAD_SOFTKEY;
/* Reserve for length */ /* Reserve for length */
bytes++; bytes++;
@@ -489,8 +467,7 @@ static int _ast_adsi_load_soft_key(unsigned char *buf, int key, const char *llab
static int _ast_adsi_connect_session(unsigned char *buf, unsigned char *fdn, int ver) static int _ast_adsi_connect_session(unsigned char *buf, unsigned char *fdn, int ver)
{ {
int bytes=0; int bytes = 0, x;
int x;
/* Message type */ /* Message type */
buf[bytes++] = ADSI_CONNECT_SESSION; buf[bytes++] = ADSI_CONNECT_SESSION;
@@ -499,7 +476,7 @@ static int _ast_adsi_connect_session(unsigned char *buf, unsigned char *fdn, int
bytes++; bytes++;
if (fdn) { if (fdn) {
for (x=0;x<4;x++) for (x = 0; x < 4; x++)
buf[bytes++] = fdn[x]; buf[bytes++] = fdn[x];
if (ver > -1) if (ver > -1)
buf[bytes++] = ver & 0xff; buf[bytes++] = ver & 0xff;
@@ -512,8 +489,7 @@ static int _ast_adsi_connect_session(unsigned char *buf, unsigned char *fdn, int
static int _ast_adsi_download_connect(unsigned char *buf, char *service, unsigned char *fdn, unsigned char *sec, int ver) static int _ast_adsi_download_connect(unsigned char *buf, char *service, unsigned char *fdn, unsigned char *sec, int ver)
{ {
int bytes=0; int bytes = 0, x;
int x;
/* Message type */ /* Message type */
buf[bytes++] = ADSI_DOWNLOAD_CONNECT; buf[bytes++] = ADSI_DOWNLOAD_CONNECT;
@@ -527,11 +503,12 @@ static int _ast_adsi_download_connect(unsigned char *buf, char *service, unsign
/* Delimiter */ /* Delimiter */
buf[bytes++] = 0xff; buf[bytes++] = 0xff;
for (x=0;x<4;x++) { for (x = 0; x < 4; x++)
buf[bytes++] = fdn[x]; buf[bytes++] = fdn[x];
}
for (x=0;x<4;x++) for (x = 0; x < 4; x++)
buf[bytes++] = sec[x]; buf[bytes++] = sec[x];
buf[bytes++] = ver & 0xff; buf[bytes++] = ver & 0xff;
buf[1] = bytes - 2; buf[1] = bytes - 2;
@@ -542,7 +519,7 @@ static int _ast_adsi_download_connect(unsigned char *buf, char *service, unsign
static int _ast_adsi_disconnect_session(unsigned char *buf) static int _ast_adsi_disconnect_session(unsigned char *buf)
{ {
int bytes=0; int bytes = 0;
/* Message type */ /* Message type */
buf[bytes++] = ADSI_DISC_SESSION; buf[bytes++] = ADSI_DISC_SESSION;
@@ -577,16 +554,14 @@ static int _ast_adsi_query_cpeinfo(unsigned char *buf)
static int _ast_adsi_read_encoded_dtmf(struct ast_channel *chan, unsigned char *buf, int maxlen) static int _ast_adsi_read_encoded_dtmf(struct ast_channel *chan, unsigned char *buf, int maxlen)
{ {
int bytes = 0; int bytes = 0, res, gotstar = 0, pos = 0;
int res;
unsigned char current = 0; unsigned char current = 0;
int gotstar = 0;
int pos = 0;
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
while(bytes <= maxlen) { while(bytes <= maxlen) {
/* Wait up to a second for a digit */ /* Wait up to a second for a digit */
res = ast_waitfordigit(chan, 1000); if (!(res = ast_waitfordigit(chan, 1000)))
if (!res)
break; break;
if (res == '*') { if (res == '*') {
gotstar = 1; gotstar = 1;
@@ -607,14 +582,15 @@ static int _ast_adsi_read_encoded_dtmf(struct ast_channel *chan, unsigned char *
} }
gotstar = 0; gotstar = 0;
} }
return bytes; return bytes;
} }
static int _ast_adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, int voice) static int _ast_adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, int voice)
{ {
unsigned char buf[256]; unsigned char buf[256] = "";
int bytes = 0; int bytes = 0, res;
int res;
bytes += ast_adsi_data_mode(buf); bytes += ast_adsi_data_mode(buf);
ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0); ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0);
@@ -623,7 +599,6 @@ static int _ast_adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, i
ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0); ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0);
/* Get response */ /* Get response */
memset(buf, 0, sizeof(buf));
res = ast_adsi_read_encoded_dtmf(chan, cpeid, 4); res = ast_adsi_read_encoded_dtmf(chan, cpeid, 4);
if (res != 4) { if (res != 4) {
ast_log(LOG_WARNING, "Got %d bytes back of encoded DTMF, expecting 4\n", res); ast_log(LOG_WARNING, "Got %d bytes back of encoded DTMF, expecting 4\n", res);
@@ -644,9 +619,9 @@ static int _ast_adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, i
static int _ast_adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *height, int *buttons, int voice) static int _ast_adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *height, int *buttons, int voice)
{ {
unsigned char buf[256]; unsigned char buf[256] = "";
int bytes = 0; int bytes = 0, res;
int res;
bytes += ast_adsi_data_mode(buf); bytes += ast_adsi_data_mode(buf);
ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0); ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0);
@@ -655,9 +630,7 @@ static int _ast_adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *heig
ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0); ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0);
/* Get width */ /* Get width */
memset(buf, 0, sizeof(buf)); if ((res = ast_readstring(chan, (char *)buf, 2, 1000, 500, "")) < 0)
res = ast_readstring(chan, (char *)buf, 2, 1000, 500, "");
if (res < 0)
return res; return res;
if (strlen((char *)buf) != 2) { if (strlen((char *)buf) != 2) {
ast_log(LOG_WARNING, "Got %d bytes of width, expecting 2\n", res); ast_log(LOG_WARNING, "Got %d bytes of width, expecting 2\n", res);
@@ -670,8 +643,7 @@ static int _ast_adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *heig
/* Get height */ /* Get height */
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
if (res) { if (res) {
res = ast_readstring(chan, (char *)buf, 2, 1000, 500, ""); if ((res = ast_readstring(chan, (char *)buf, 2, 1000, 500, "")) < 0)
if (res < 0)
return res; return res;
if (strlen((char *)buf) != 2) { if (strlen((char *)buf) != 2) {
ast_log(LOG_WARNING, "Got %d bytes of height, expecting 2\n", res); ast_log(LOG_WARNING, "Got %d bytes of height, expecting 2\n", res);
@@ -685,8 +657,7 @@ static int _ast_adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *heig
/* Get buttons */ /* Get buttons */
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
if (res) { if (res) {
res = ast_readstring(chan, (char *)buf, 1, 1000, 500, ""); if ((res = ast_readstring(chan, (char *)buf, 1, 1000, 500, "")) < 0)
if (res < 0)
return res; return res;
if (strlen((char *)buf) != 1) { if (strlen((char *)buf) != 1) {
ast_log(LOG_WARNING, "Got %d bytes of buttons, expecting 1\n", res); ast_log(LOG_WARNING, "Got %d bytes of buttons, expecting 1\n", res);
@@ -709,7 +680,7 @@ static int _ast_adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *heig
static int _ast_adsi_data_mode(unsigned char *buf) static int _ast_adsi_data_mode(unsigned char *buf)
{ {
int bytes=0; int bytes = 0;
/* Message type */ /* Message type */
buf[bytes++] = ADSI_SWITCH_TO_DATA; buf[bytes++] = ADSI_SWITCH_TO_DATA;
@@ -724,7 +695,7 @@ static int _ast_adsi_data_mode(unsigned char *buf)
static int _ast_adsi_clear_soft_keys(unsigned char *buf) static int _ast_adsi_clear_soft_keys(unsigned char *buf)
{ {
int bytes=0; int bytes = 0;
/* Message type */ /* Message type */
buf[bytes++] = ADSI_CLEAR_SOFTKEY; buf[bytes++] = ADSI_CLEAR_SOFTKEY;
@@ -739,7 +710,7 @@ static int _ast_adsi_clear_soft_keys(unsigned char *buf)
static int _ast_adsi_clear_screen(unsigned char *buf) static int _ast_adsi_clear_screen(unsigned char *buf)
{ {
int bytes=0; int bytes = 0;
/* Message type */ /* Message type */
buf[bytes++] = ADSI_CLEAR_SCREEN; buf[bytes++] = ADSI_CLEAR_SCREEN;
@@ -754,7 +725,7 @@ static int _ast_adsi_clear_screen(unsigned char *buf)
static int _ast_adsi_voice_mode(unsigned char *buf, int when) static int _ast_adsi_voice_mode(unsigned char *buf, int when)
{ {
int bytes=0; int bytes = 0;
/* Message type */ /* Message type */
buf[bytes++] = ADSI_SWITCH_TO_VOICE; buf[bytes++] = ADSI_SWITCH_TO_VOICE;
@@ -780,7 +751,7 @@ static int _ast_adsi_available(struct ast_channel *chan)
static int _ast_adsi_download_disconnect(unsigned char *buf) static int _ast_adsi_download_disconnect(unsigned char *buf)
{ {
int bytes=0; int bytes = 0;
/* Message type */ /* Message type */
buf[bytes++] = ADSI_DOWNLOAD_DISC; buf[bytes++] = ADSI_DOWNLOAD_DISC;
@@ -796,7 +767,7 @@ static int _ast_adsi_download_disconnect(unsigned char *buf)
static int _ast_adsi_display(unsigned char *buf, int page, int line, int just, int wrap, static int _ast_adsi_display(unsigned char *buf, int page, int line, int just, int wrap,
char *col1, char *col2) char *col1, char *col2)
{ {
int bytes=0; int bytes = 0;
/* Sanity check line number */ /* Sanity check line number */
@@ -841,7 +812,7 @@ static int _ast_adsi_display(unsigned char *buf, int page, int line, int just, i
static int _ast_adsi_input_control(unsigned char *buf, int page, int line, int display, int format, int just) static int _ast_adsi_input_control(unsigned char *buf, int page, int line, int display, int format, int just)
{ {
int bytes=0; int bytes = 0;
if (page) { if (page) {
if (line > 4) return -1; if (line > 4) return -1;
@@ -883,14 +854,14 @@ static int _ast_adsi_input_format(unsigned char *buf, int num, int dir, int wrap
static int _ast_adsi_set_keys(unsigned char *buf, unsigned char *keys) static int _ast_adsi_set_keys(unsigned char *buf, unsigned char *keys)
{ {
int bytes=0; int bytes = 0, x;
int x;
/* Message type */ /* Message type */
buf[bytes++] = ADSI_INIT_SOFTKEY_LINE; buf[bytes++] = ADSI_INIT_SOFTKEY_LINE;
/* Space for size */ /* Space for size */
bytes++; bytes++;
/* Key definitions */ /* Key definitions */
for (x=0;x<6;x++) for (x = 0; x < 6; x++)
buf[bytes++] = (keys[x] & 0x3f) ? keys[x] : (keys[x] | 0x1); buf[bytes++] = (keys[x] & 0x3f) ? keys[x] : (keys[x] | 0x1);
buf[1] = bytes - 2; buf[1] = bytes - 2;
return bytes; return bytes;
@@ -898,7 +869,7 @@ static int _ast_adsi_set_keys(unsigned char *buf, unsigned char *keys)
static int _ast_adsi_set_line(unsigned char *buf, int page, int line) static int _ast_adsi_set_line(unsigned char *buf, int page, int line)
{ {
int bytes=0; int bytes = 0;
/* Sanity check line number */ /* Sanity check line number */
@@ -929,12 +900,8 @@ static int speeds = 0;
static int _ast_adsi_channel_restore(struct ast_channel *chan) static int _ast_adsi_channel_restore(struct ast_channel *chan)
{ {
unsigned char dsp[256]; unsigned char dsp[256] = "", keyd[6] = "";
int bytes; int bytes, x;
int x;
unsigned char keyd[6];
memset(dsp, 0, sizeof(dsp));
/* Start with initial display setup */ /* Start with initial display setup */
bytes = 0; bytes = 0;
@@ -943,10 +910,8 @@ static int _ast_adsi_channel_restore(struct ast_channel *chan)
/* Prepare key setup messages */ /* Prepare key setup messages */
if (speeds) { if (speeds) {
memset(keyd, 0, sizeof(keyd)); for (x = 0; x < speeds; x++)
for (x=0;x<speeds;x++) {
keyd[x] = ADSI_SPEED_DIAL + x; keyd[x] = ADSI_SPEED_DIAL + x;
}
bytes += ast_adsi_set_keys(dsp + bytes, keyd); bytes += ast_adsi_set_keys(dsp + bytes, keyd);
} }
ast_adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0); ast_adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0);
@@ -957,34 +922,27 @@ static int _ast_adsi_channel_restore(struct ast_channel *chan)
static int _ast_adsi_print(struct ast_channel *chan, char **lines, int *aligns, int voice) static int _ast_adsi_print(struct ast_channel *chan, char **lines, int *aligns, int voice)
{ {
unsigned char buf[4096]; unsigned char buf[4096];
int bytes=0; int bytes = 0, res, x;
int res;
int x; for(x = 0; lines[x]; x++)
for(x=0;lines[x];x++)
bytes += ast_adsi_display(buf + bytes, ADSI_INFO_PAGE, x+1, aligns[x], 0, lines[x], ""); bytes += ast_adsi_display(buf + bytes, ADSI_INFO_PAGE, x+1, aligns[x], 0, lines[x], "");
bytes += ast_adsi_set_line(buf + bytes, ADSI_INFO_PAGE, 1); bytes += ast_adsi_set_line(buf + bytes, ADSI_INFO_PAGE, 1);
if (voice) { if (voice)
bytes += ast_adsi_voice_mode(buf + bytes, 0); bytes += ast_adsi_voice_mode(buf + bytes, 0);
}
res = ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0); res = ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0);
if (voice) { if (voice)
/* Ignore the resulting DTMF B announcing it's in voice mode */ /* Ignore the resulting DTMF B announcing it's in voice mode */
ast_waitfordigit(chan, 1000); ast_waitfordigit(chan, 1000);
}
return res; return res;
} }
static int _ast_adsi_load_session(struct ast_channel *chan, unsigned char *app, int ver, int data) static int _ast_adsi_load_session(struct ast_channel *chan, unsigned char *app, int ver, int data)
{ {
unsigned char dsp[256]; unsigned char dsp[256] = "";
int bytes; int bytes = 0, res;
int res;
char resp[2]; char resp[2];
memset(dsp, 0, sizeof(dsp));
/* Connect to session */ /* Connect to session */
bytes = 0;
bytes += ast_adsi_connect_session(dsp + bytes, app, ver); bytes += ast_adsi_connect_session(dsp + bytes, app, ver);
if (data) if (data)
@@ -994,8 +952,7 @@ static int _ast_adsi_load_session(struct ast_channel *chan, unsigned char *app,
if (ast_adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0)) if (ast_adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0))
return -1; return -1;
if (app) { if (app) {
res = ast_readstring(chan, resp, 1, 1200, 1200, ""); if ((res = ast_readstring(chan, resp, 1, 1200, 1200, "")) < 0)
if (res < 0)
return -1; return -1;
if (res) { if (res) {
ast_debug(1, "No response from CPE about version. Assuming not there.\n"); ast_debug(1, "No response from CPE about version. Assuming not there.\n");
@@ -1017,19 +974,17 @@ static int _ast_adsi_load_session(struct ast_channel *chan, unsigned char *app,
static int _ast_adsi_unload_session(struct ast_channel *chan) static int _ast_adsi_unload_session(struct ast_channel *chan)
{ {
unsigned char dsp[256]; unsigned char dsp[256] = "";
int bytes; int bytes = 0;
memset(dsp, 0, sizeof(dsp));
/* Connect to session */ /* Connect to session */
bytes = 0;
bytes += ast_adsi_disconnect_session(dsp + bytes); bytes += ast_adsi_disconnect_session(dsp + bytes);
bytes += ast_adsi_voice_mode(dsp + bytes, 0); bytes += ast_adsi_voice_mode(dsp + bytes, 0);
/* Prepare key setup messages */ /* Prepare key setup messages */
if (ast_adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0)) if (ast_adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0))
return -1; return -1;
return 0; return 0;
} }
@@ -1049,14 +1004,14 @@ static void init_state(void)
{ {
int x; int x;
for (x=0;x<ADSI_MAX_INTRO;x++) for (x = 0; x < ADSI_MAX_INTRO; x++)
aligns[x] = ADSI_JUST_CENT; aligns[x] = ADSI_JUST_CENT;
ast_copy_string(intro[0], "Welcome to the", sizeof(intro[0])); ast_copy_string(intro[0], "Welcome to the", sizeof(intro[0]));
ast_copy_string(intro[1], "Asterisk", sizeof(intro[1])); ast_copy_string(intro[1], "Asterisk", sizeof(intro[1]));
ast_copy_string(intro[2], "Open Source PBX", sizeof(intro[2])); ast_copy_string(intro[2], "Open Source PBX", sizeof(intro[2]));
total = 3; total = 3;
speeds = 0; speeds = 0;
for (x=3;x<ADSI_MAX_INTRO;x++) for (x = 3; x < ADSI_MAX_INTRO; x++)
intro[x][0] = '\0'; intro[x][0] = '\0';
memset(speeddial, 0, sizeof(speeddial)); memset(speeddial, 0, sizeof(speeddial));
alignment = ADSI_JUST_CENT; alignment = ADSI_JUST_CENT;
@@ -1064,49 +1019,52 @@ static void init_state(void)
static void adsi_load(void) static void adsi_load(void)
{ {
int x; int x = 0;
struct ast_config *conf; struct ast_config *conf = NULL;
struct ast_variable *v; struct ast_variable *v;
struct ast_flags config_flags = { 0 }; struct ast_flags config_flags = { 0 };
char *name, *sname; char *name, *sname;
init_state(); init_state();
conf = ast_config_load("adsi.conf", config_flags);
if (conf) { if (!(conf = ast_config_load("adsi.conf", config_flags)))
x=0; return;
for (v = ast_variable_browse(conf, "intro"); v; v = v->next) {
if (!strcasecmp(v->name, "alignment")) for (v = ast_variable_browse(conf, "intro"); v; v = v->next) {
alignment = str2align(v->value); if (!strcasecmp(v->name, "alignment"))
else if (!strcasecmp(v->name, "greeting")) { alignment = str2align(v->value);
if (x < ADSI_MAX_INTRO) { else if (!strcasecmp(v->name, "greeting")) {
aligns[x] = alignment; if (x < ADSI_MAX_INTRO) {
ast_copy_string(intro[x], v->value, sizeof(intro[x])); aligns[x] = alignment;
x++; ast_copy_string(intro[x], v->value, sizeof(intro[x]));
}
} else if (!strcasecmp(v->name, "maxretries")) {
if (atoi(v->value) > 0)
maxretries = atoi(v->value);
}
}
if (x)
total = x;
x = 0;
for (v = ast_variable_browse(conf, "speeddial"); v; v = v->next) {
char *stringp = v->value;
name = strsep(&stringp, ",");
sname = strsep(&stringp, ",");
if (!sname)
sname = name;
if (x < ADSI_MAX_SPEED_DIAL) {
ast_copy_string(speeddial[x][0], v->name, sizeof(speeddial[x][0]));
ast_copy_string(speeddial[x][1], name, 18);
ast_copy_string(speeddial[x][2], sname, 7);
x++; x++;
} }
} else if (!strcasecmp(v->name, "maxretries")) {
if (atoi(v->value) > 0)
maxretries = atoi(v->value);
} }
if (x)
speeds = x;
ast_config_destroy(conf);
} }
if (x)
total = x;
x = 0;
for (v = ast_variable_browse(conf, "speeddial"); v; v = v->next) {
char *stringp = v->value;
name = strsep(&stringp, ",");
sname = strsep(&stringp, ",");
if (!sname)
sname = name;
if (x < ADSI_MAX_SPEED_DIAL) {
ast_copy_string(speeddial[x][0], v->name, sizeof(speeddial[x][0]));
ast_copy_string(speeddial[x][1], name, 18);
ast_copy_string(speeddial[x][2], sname, 7);
x++;
}
}
if (x)
speeds = x;
ast_config_destroy(conf);
return;
} }
static int reload(void) static int reload(void)