summaryrefslogtreecommitdiff
path: root/res/res_adsi.c
diff options
context:
space:
mode:
authorTilghman Lesher <tilghman@meg.abyt.es>2010-07-14 20:48:59 +0000
committerTilghman Lesher <tilghman@meg.abyt.es>2010-07-14 20:48:59 +0000
commit832d1296c61477eb5c5848b64cf48b36e636bfb0 (patch)
tree2b34378f0a47d89598b41b610afdfbe6643fad16 /res/res_adsi.c
parent8e7d01d48418786d3f0abc232a2d12de7362e50e (diff)
Remove the old stub files, preferring the optional_api method.
(closes issue #17475) Reported by: tilghman Review: https://reviewboard.asterisk.org/r/695/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@276490 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_adsi.c')
-rw-r--r--res/res_adsi.c374
1 files changed, 201 insertions, 173 deletions
diff --git a/res/res_adsi.c b/res/res_adsi.c
index 001763758..b7e832750 100644
--- a/res/res_adsi.c
+++ b/res/res_adsi.c
@@ -20,9 +20,9 @@
/*! \file
*
- * \brief ADSI support
+ * \brief ADSI support
*
- * \author Mark Spencer <markster@digium.com>
+ * \author Mark Spencer <markster@digium.com>
*
* \note this module is required by app_voicemail and app_getcpeid
* \todo Move app_getcpeid into this module
@@ -37,7 +37,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include <time.h>
#include <math.h>
-#include "asterisk/adsi.h"
#include "asterisk/ulaw.h"
#include "asterisk/alaw.h"
#include "asterisk/callerid.h"
@@ -47,6 +46,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/config.h"
#include "asterisk/file.h"
+#define AST_API_MODULE
+#include "asterisk/adsi.h"
+
#define DEFAULT_ADSI_MAX_RETRIES 3
#define ADSI_MAX_INTRO 20
@@ -73,20 +75,22 @@ static int adsi_generate(unsigned char *buf, int msgtype, unsigned char *msg, in
/* Initial carrier (imaginary) */
float cr = 1.0, ci = 0.0, scont = 0.0;
- if (msglen > 255)
+ if (msglen > 255) {
msglen = 255;
+ }
/* If first message, Send 150ms of MARK's */
if (msgnum == 1) {
- for (x = 0; x < 150; x++) /* was 150 */
+ for (x = 0; x < 150; x++) { /* was 150 */
PUT_CLID_MARKMS;
+ }
}
/* Put message type */
PUT_CLID(msgtype);
sum = msgtype;
- /* Put message length (plus one for the message number) */
+ /* Put message length (plus one for the message number) */
PUT_CLID(msglen + 1);
sum += msglen + 1;
@@ -106,8 +110,9 @@ static int adsi_generate(unsigned char *buf, int msgtype, unsigned char *msg, in
#if 0
if (last) {
/* Put trailing marks */
- for (x = 0; x < 50; x++)
+ for (x = 0; x < 50; x++) {
PUT_CLID_MARKMS;
+ }
}
#endif
return bytes;
@@ -128,10 +133,11 @@ static int adsi_careful_send(struct ast_channel *chan, unsigned char *buf, int l
amt = len;
/* Send remainder if provided */
- if (amt > *remain)
+ if (amt > *remain) {
amt = *remain;
- else
+ } else {
*remain = *remain - amt;
+ }
outf.frametype = AST_FRAME_VOICE;
outf.subclass.codec = AST_FORMAT_ULAW;
outf.data.ptr = buf;
@@ -146,32 +152,35 @@ static int adsi_careful_send(struct ast_channel *chan, unsigned char *buf, int l
len -= amt;
}
- while(len) {
+ while (len) {
amt = len;
/* If we don't get anything at all back in a second, forget
about it */
- if (ast_waitfor(chan, 1000) < 1)
+ if (ast_waitfor(chan, 1000) < 1) {
return -1;
+ }
/* Detect hangup */
- if (!(inf = ast_read(chan)))
+ if (!(inf = ast_read(chan))) {
return -1;
+ }
/* Drop any frames that are not voice */
if (inf->frametype != AST_FRAME_VOICE) {
ast_frfree(inf);
continue;
}
-
+
if (inf->subclass.codec != 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)
+ if (amt > inf->datalen) {
amt = inf->datalen;
- else if (remain)
+ } else if (remain) {
*remain = inf->datalen - amt;
+ }
outf.frametype = AST_FRAME_VOICE;
outf.subclass.codec = AST_FORMAT_ULAW;
outf.data.ptr = buf;
@@ -204,23 +213,25 @@ static int __adsi_transmit_messages(struct ast_channel *chan, unsigned char **ms
return -1;
}
- while(retries < maxretries) {
+ while (retries < maxretries) {
if (!(chan->adsicpe & ADSI_FLAG_DATAMODE)) {
/* Generate CAS (no SAS) */
ast_gen_cas(buf, 0, 680, AST_FORMAT_ULAW);
-
+
/* 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");
+ }
/* Wait For DTMF result */
waittime = 500;
- for(;;) {
+ for (;;) {
if (((res = ast_waitfor(chan, waittime)) < 1)) {
/* Didn't get back DTMF A in time */
ast_debug(1, "No ADSI CPE detected (%d)\n", res);
- if (!chan->adsicpe)
+ if (!chan->adsicpe) {
chan->adsicpe = AST_ADSI_UNAVAILABLE;
+ }
errno = ENOSYS;
return -1;
}
@@ -232,16 +243,19 @@ static int __adsi_transmit_messages(struct ast_channel *chan, unsigned char **ms
if (f->frametype == AST_FRAME_DTMF) {
if (f->subclass.integer == 'A') {
/* Okay, this is an ADSI CPE. Note this for future reference, too */
- if (!chan->adsicpe)
+ if (!chan->adsicpe) {
chan->adsicpe = AST_ADSI_AVAILABLE;
+ }
break;
} else {
- if (f->subclass.integer == 'D')
+ if (f->subclass.integer == 'D') {
ast_debug(1, "Off-hook capable CPE only, not ADSI\n");
- else
+ } else {
ast_log(LOG_WARNING, "Unknown ADSI response '%c'\n", f->subclass.integer);
- if (!chan->adsicpe)
+ }
+ if (!chan->adsicpe) {
chan->adsicpe = AST_ADSI_UNAVAILABLE;
+ }
errno = ENOSYS;
ast_frfree(f);
return -1;
@@ -266,36 +280,39 @@ static int __adsi_transmit_messages(struct ast_channel *chan, unsigned char **ms
return -1;
}
ast_debug(1, "Message %d, of %d input bytes, %d output bytes\n", x + 1, msglen[x], res);
- pos += res;
+ pos += res;
x++;
}
rem = 0;
- res = adsi_careful_send(chan, buf, pos, &rem);
- if (!def)
+ res = adsi_careful_send(chan, buf, pos, &rem);
+ if (!def) {
ast_channel_undefer_dtmf(chan);
- if (res)
+ }
+ if (res) {
return -1;
+ }
ast_debug(1, "Sent total spill of %d bytes\n", pos);
memset(ack, 0, sizeof(ack));
/* Get real result and check for hangup */
- if ((res = ast_readstring(chan, ack, 2, 1000, 1000, "")) < 0)
+ if ((res = ast_readstring(chan, ack, 2, 1000, 1000, "")) < 0) {
return -1;
+ }
if (ack[0] == 'D') {
ast_debug(1, "Acked up to message %d\n", atoi(ack + 1)); start += atoi(ack + 1);
- if (start >= x)
+ if (start >= x) {
break;
- else {
+ } else {
retries++;
ast_debug(1, "Retransmitting (%d), from %d\n", retries, start + 1);
}
} else {
retries++;
ast_log(LOG_WARNING, "Unexpected response to ack: %s (retry %d)\n", ack, retries);
- }
+ }
}
if (retries >= maxretries) {
ast_log(LOG_WARNING, "Maximum ADSI Retries (%d) exceeded\n", maxretries);
@@ -303,10 +320,9 @@ static int __adsi_transmit_messages(struct ast_channel *chan, unsigned char **ms
return -1;
}
return 0;
-
}
-static int _ast_adsi_begin_download(struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version)
+int AST_OPTIONAL_API_NAME(ast_adsi_begin_download)(struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version)
{
int bytes = 0;
unsigned char buf[256];
@@ -315,30 +331,34 @@ static int _ast_adsi_begin_download(struct ast_channel *chan, char *service, uns
/* Setup the resident soft key stuff, a piece at a time */
/* Upload what scripts we can for voicemail ahead of time */
bytes += ast_adsi_download_connect(buf + bytes, service, fdn, sec, version);
- if (ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DOWNLOAD, 0))
+ if (ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DOWNLOAD, 0)) {
return -1;
- if (ast_readstring(chan, ack, 1, 10000, 10000, ""))
+ }
+ if (ast_readstring(chan, ack, 1, 10000, 10000, "")) {
return -1;
- if (ack[0] == 'B')
+ }
+ if (ack[0] == 'B') {
return 0;
+ }
ast_debug(1, "Download was denied by CPE\n");
return -1;
}
-static int _ast_adsi_end_download(struct ast_channel *chan)
+int AST_OPTIONAL_API_NAME(ast_adsi_end_download)(struct ast_channel *chan)
{
int bytes = 0;
unsigned char buf[256];
- /* Setup the resident soft key stuff, a piece at a time */
- /* Upload what scripts we can for voicemail ahead of time */
- bytes += ast_adsi_download_disconnect(buf + bytes);
- if (ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DOWNLOAD, 0))
+ /* Setup the resident soft key stuff, a piece at a time */
+ /* Upload what scripts we can for voicemail ahead of time */
+ bytes += ast_adsi_download_disconnect(buf + bytes);
+ if (ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DOWNLOAD, 0)) {
return -1;
+ }
return 0;
}
-static int _ast_adsi_transmit_message_full(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype, int dowait)
+int AST_OPTIONAL_API_NAME(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 };
int msglens[5], msgtypes[5], newdatamode = (chan->adsicpe & ADSI_FLAG_DATAMODE), res, x, writeformat = chan->writeformat, readformat = chan->readformat, waitforswitch = 0;
@@ -349,7 +369,7 @@ static int _ast_adsi_transmit_message_full(struct ast_channel *chan, unsigned ch
waitforswitch++;
newdatamode = ADSI_FLAG_DATAMODE;
}
-
+
if (msg[x] == ADSI_SWITCH_TO_VOICE) {
ast_debug(1, "Switch to voice is sent!\n");
waitforswitch++;
@@ -376,8 +396,9 @@ static int _ast_adsi_transmit_message_full(struct ast_channel *chan, unsigned ch
if (ast_set_read_format(chan, AST_FORMAT_ULAW)) {
ast_log(LOG_WARNING, "Unable to set read format to ULAW\n");
if (writeformat) {
- if (ast_set_write_format(chan, writeformat))
+ if (ast_set_write_format(chan, writeformat)) {
ast_log(LOG_WARNING, "Unable to restore write format to %d\n", writeformat);
+ }
}
return -1;
}
@@ -385,26 +406,30 @@ static int _ast_adsi_transmit_message_full(struct ast_channel *chan, unsigned ch
if (dowait) {
ast_debug(1, "Wait for switch is '%d'\n", waitforswitch);
- while (waitforswitch-- && ((res = ast_waitfordigit(chan, 1000)) > 0)) {
- res = 0;
+ while (waitforswitch-- && ((res = ast_waitfordigit(chan, 1000)) > 0)) {
+ res = 0;
ast_debug(1, "Waiting for 'B'...\n");
}
}
-
- if (!res)
+
+ if (!res) {
chan->adsicpe = (chan->adsicpe & ~ADSI_FLAG_DATAMODE) | newdatamode;
+ }
- if (writeformat)
+ if (writeformat) {
ast_set_write_format(chan, writeformat);
- if (readformat)
+ }
+ if (readformat) {
ast_set_read_format(chan, readformat);
+ }
- if (!res)
+ if (!res) {
res = ast_safe_sleep(chan, 100 );
+ }
return res;
}
-static int _ast_adsi_transmit_message(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype)
+int AST_OPTIONAL_API_NAME(ast_adsi_transmit_message)(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype)
{
return ast_adsi_transmit_message_full(chan, msg, msglen, msgtype, 1);
}
@@ -420,13 +445,14 @@ static inline int ccopy(unsigned char *dst, const unsigned char *src, int max)
return x;
}
-static int _ast_adsi_load_soft_key(unsigned char *buf, int key, const char *llabel, const char *slabel, char *ret, int data)
+int AST_OPTIONAL_API_NAME(ast_adsi_load_soft_key)(unsigned char *buf, int key, const char *llabel, const char *slabel, char *ret, int data)
{
int bytes = 0;
/* Abort if invalid key specified */
- if ((key < 2) || (key > 33))
+ if ((key < 2) || (key > 33)) {
return -1;
+ }
buf[bytes++] = ADSI_LOAD_SOFTKEY;
/* Reserve for length */
@@ -448,8 +474,9 @@ static int _ast_adsi_load_soft_key(unsigned char *buf, int key, const char *llab
if (ret) {
/* Place delimiter */
buf[bytes++] = 0xff;
- if (data)
+ if (data) {
buf[bytes++] = ADSI_SWITCH_TO_DATA2;
+ }
/* Carefully copy return string */
bytes += ccopy(buf + bytes, (const unsigned char *)ret, 20);
@@ -457,10 +484,9 @@ static int _ast_adsi_load_soft_key(unsigned char *buf, int key, const char *llab
/* Replace parameter length */
buf[1] = bytes - 2;
return bytes;
-
}
-static int _ast_adsi_connect_session(unsigned char *buf, unsigned char *fdn, int ver)
+int AST_OPTIONAL_API_NAME(ast_adsi_connect_session)(unsigned char *buf, unsigned char *fdn, int ver)
{
int bytes = 0, x;
@@ -471,10 +497,12 @@ static int _ast_adsi_connect_session(unsigned char *buf, unsigned char *fdn, int
bytes++;
if (fdn) {
- for (x = 0; x < 4; x++)
+ for (x = 0; x < 4; x++) {
buf[bytes++] = fdn[x];
- if (ver > -1)
+ }
+ if (ver > -1) {
buf[bytes++] = ver & 0xff;
+ }
}
buf[1] = bytes - 2;
@@ -482,7 +510,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)
+int AST_OPTIONAL_API_NAME(ast_adsi_download_connect)(unsigned char *buf, char *service, unsigned char *fdn, unsigned char *sec, int ver)
{
int bytes = 0, x;
@@ -497,12 +525,14 @@ static int _ast_adsi_download_connect(unsigned char *buf, char *service, unsign
/* Delimiter */
buf[bytes++] = 0xff;
-
- for (x = 0; x < 4; x++)
+
+ for (x = 0; x < 4; x++) {
buf[bytes++] = fdn[x];
+ }
- for (x = 0; x < 4; x++)
+ for (x = 0; x < 4; x++) {
buf[bytes++] = sec[x];
+ }
buf[bytes++] = ver & 0xff;
@@ -512,7 +542,7 @@ static int _ast_adsi_download_connect(unsigned char *buf, char *service, unsign
}
-static int _ast_adsi_disconnect_session(unsigned char *buf)
+int AST_OPTIONAL_API_NAME(ast_adsi_disconnect_session)(unsigned char *buf)
{
int bytes = 0;
@@ -527,7 +557,7 @@ static int _ast_adsi_disconnect_session(unsigned char *buf)
}
-static int _ast_adsi_query_cpeid(unsigned char *buf)
+int AST_OPTIONAL_API_NAME(ast_adsi_query_cpeid)(unsigned char *buf)
{
int bytes = 0;
buf[bytes++] = ADSI_QUERY_CPEID;
@@ -537,7 +567,7 @@ static int _ast_adsi_query_cpeid(unsigned char *buf)
return bytes;
}
-static int _ast_adsi_query_cpeinfo(unsigned char *buf)
+int AST_OPTIONAL_API_NAME(ast_adsi_query_cpeinfo)(unsigned char *buf)
{
int bytes = 0;
buf[bytes++] = ADSI_QUERY_CONFIG;
@@ -547,27 +577,30 @@ static int _ast_adsi_query_cpeinfo(unsigned char *buf)
return bytes;
}
-static int _ast_adsi_read_encoded_dtmf(struct ast_channel *chan, unsigned char *buf, int maxlen)
+int AST_OPTIONAL_API_NAME(ast_adsi_read_encoded_dtmf)(struct ast_channel *chan, unsigned char *buf, int maxlen)
{
int bytes = 0, res, gotstar = 0, pos = 0;
unsigned char current = 0;
memset(buf, 0, sizeof(buf));
- while(bytes <= maxlen) {
+ while (bytes <= maxlen) {
/* Wait up to a second for a digit */
- if (!(res = ast_waitfordigit(chan, 1000)))
+ if (!(res = ast_waitfordigit(chan, 1000))) {
break;
+ }
if (res == '*') {
- gotstar = 1;
+ gotstar = 1;
continue;
}
/* Ignore anything other than a digit */
- if ((res < '0') || (res > '9'))
+ if ((res < '0') || (res > '9')) {
continue;
+ }
res -= '0';
- if (gotstar)
+ if (gotstar) {
res += 9;
+ }
if (pos) {
pos = 0;
buf[bytes++] = (res << 4) | current;
@@ -581,7 +614,7 @@ static int _ast_adsi_read_encoded_dtmf(struct ast_channel *chan, unsigned char *
return bytes;
}
-static int _ast_adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, int voice)
+int AST_OPTIONAL_API_NAME(ast_adsi_get_cpeid)(struct ast_channel *chan, unsigned char *cpeid, int voice)
{
unsigned char buf[256] = "";
int bytes = 0, res;
@@ -612,7 +645,7 @@ static int _ast_adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, i
return res;
}
-static int _ast_adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *height, int *buttons, int voice)
+int AST_OPTIONAL_API_NAME(ast_adsi_get_cpeinfo)(struct ast_channel *chan, int *width, int *height, int *buttons, int voice)
{
unsigned char buf[256] = "";
int bytes = 0, res;
@@ -625,43 +658,49 @@ 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);
/* Get width */
- if ((res = ast_readstring(chan, (char *)buf, 2, 1000, 500, "")) < 0)
+ if ((res = ast_readstring(chan, (char *) buf, 2, 1000, 500, "")) < 0) {
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);
res = 0;
} else {
res = 1;
}
- if (width)
- *width = atoi((char *)buf);
+ if (width) {
+ *width = atoi((char *) buf);
+ }
/* Get height */
memset(buf, 0, sizeof(buf));
if (res) {
- if ((res = ast_readstring(chan, (char *)buf, 2, 1000, 500, "")) < 0)
+ if ((res = ast_readstring(chan, (char *) buf, 2, 1000, 500, "")) < 0) {
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);
res = 0;
} else {
res = 1;
- }
- if (height)
- *height= atoi((char *)buf);
+ }
+ if (height) {
+ *height = atoi((char *) buf);
+ }
}
/* Get buttons */
memset(buf, 0, sizeof(buf));
if (res) {
- if ((res = ast_readstring(chan, (char *)buf, 1, 1000, 500, "")) < 0)
+ if ((res = ast_readstring(chan, (char *) buf, 1, 1000, 500, "")) < 0) {
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);
res = 0;
} else {
res = 1;
- }
- if (buttons)
- *buttons = atoi((char *)buf);
+ }
+ if (buttons) {
+ *buttons = atoi((char *) buf);
+ }
}
if (voice) {
bytes = 0;
@@ -673,7 +712,7 @@ static int _ast_adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *heig
return res;
}
-static int _ast_adsi_data_mode(unsigned char *buf)
+int AST_OPTIONAL_API_NAME(ast_adsi_data_mode)(unsigned char *buf)
{
int bytes = 0;
@@ -688,7 +727,7 @@ static int _ast_adsi_data_mode(unsigned char *buf)
}
-static int _ast_adsi_clear_soft_keys(unsigned char *buf)
+int AST_OPTIONAL_API_NAME(ast_adsi_clear_soft_keys)(unsigned char *buf)
{
int bytes = 0;
@@ -703,7 +742,7 @@ static int _ast_adsi_clear_soft_keys(unsigned char *buf)
}
-static int _ast_adsi_clear_screen(unsigned char *buf)
+int AST_OPTIONAL_API_NAME(ast_adsi_clear_screen)(unsigned char *buf)
{
int bytes = 0;
@@ -718,7 +757,7 @@ static int _ast_adsi_clear_screen(unsigned char *buf)
}
-static int _ast_adsi_voice_mode(unsigned char *buf, int when)
+int AST_OPTIONAL_API_NAME(ast_adsi_voice_mode)(unsigned char *buf, int when)
{
int bytes = 0;
@@ -735,16 +774,17 @@ static int _ast_adsi_voice_mode(unsigned char *buf, int when)
}
-static int _ast_adsi_available(struct ast_channel *chan)
+int AST_OPTIONAL_API_NAME(ast_adsi_available)(struct ast_channel *chan)
{
int cpe = chan->adsicpe & 0xff;
if ((cpe == AST_ADSI_AVAILABLE) ||
- (cpe == AST_ADSI_UNKNOWN))
+ (cpe == AST_ADSI_UNKNOWN)) {
return 1;
+ }
return 0;
}
-static int _ast_adsi_download_disconnect(unsigned char *buf)
+int AST_OPTIONAL_API_NAME(ast_adsi_download_disconnect)(unsigned char *buf)
{
int bytes = 0;
@@ -759,7 +799,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,
+int AST_OPTIONAL_API_NAME(ast_adsi_display)(unsigned char *buf, int page, int line, int just, int wrap,
char *col1, char *col2)
{
int bytes = 0;
@@ -772,11 +812,12 @@ static int _ast_adsi_display(unsigned char *buf, int page, int line, int just, i
if (line > 33) return -1;
}
- if (line < 1)
+ if (line < 1) {
return -1;
+ }
/* Parameter type */
buf[bytes++] = ADSI_LOAD_VIRTUAL_DISP;
-
+
/* Reserve space for size */
bytes++;
@@ -794,18 +835,18 @@ static int _ast_adsi_display(unsigned char *buf, int page, int line, int just, i
/* Delimiter */
buf[bytes++] = 0xff;
-
+
/* Secondary column */
bytes += ccopy(buf + bytes, (unsigned char *)col2, 20);
/* Update length */
buf[1] = bytes - 2;
-
+
return bytes;
}
-static int _ast_adsi_input_control(unsigned char *buf, int page, int line, int display, int format, int just)
+int AST_OPTIONAL_API_NAME(ast_adsi_input_control)(unsigned char *buf, int page, int line, int display, int format, int just)
{
int bytes = 0;
@@ -815,39 +856,40 @@ static int _ast_adsi_input_control(unsigned char *buf, int page, int line, int d
if (line > 33) return -1;
}
- if (line < 1)
+ if (line < 1) {
return -1;
+ }
buf[bytes++] = ADSI_INPUT_CONTROL;
bytes++;
buf[bytes++] = ((page & 1) << 7) | (line & 0x3f);
buf[bytes++] = ((display & 1) << 7) | ((just & 0x3) << 4) | (format & 0x7);
-
+
buf[1] = bytes - 2;
return bytes;
-
}
-static int _ast_adsi_input_format(unsigned char *buf, int num, int dir, int wrap, char *format1, char *format2)
+int AST_OPTIONAL_API_NAME(ast_adsi_input_format)(unsigned char *buf, int num, int dir, int wrap, char *format1, char *format2)
{
int bytes = 0;
- if (!strlen((char *)format1))
+ if (ast_strlen_zero((char *) format1)) {
return -1;
+ }
buf[bytes++] = ADSI_INPUT_FORMAT;
bytes++;
buf[bytes++] = ((dir & 1) << 7) | ((wrap & 1) << 6) | (num & 0x7);
- bytes += ccopy(buf + bytes, (unsigned char *)format1, 20);
+ bytes += ccopy(buf + bytes, (unsigned char *) format1, 20);
buf[bytes++] = 0xff;
- if (format2 && strlen((char *)format2)) {
- bytes += ccopy(buf + bytes, (unsigned char *)format2, 20);
+ if (!ast_strlen_zero(format2)) {
+ bytes += ccopy(buf + bytes, (unsigned char *) format2, 20);
}
buf[1] = bytes - 2;
return bytes;
}
-static int _ast_adsi_set_keys(unsigned char *buf, unsigned char *keys)
+int AST_OPTIONAL_API_NAME(ast_adsi_set_keys)(unsigned char *buf, unsigned char *keys)
{
int bytes = 0, x;
@@ -856,13 +898,14 @@ static int _ast_adsi_set_keys(unsigned char *buf, unsigned char *keys)
/* Space for size */
bytes++;
/* 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[1] = bytes - 2;
return bytes;
}
-static int _ast_adsi_set_line(unsigned char *buf, int page, int line)
+int AST_OPTIONAL_API_NAME(ast_adsi_set_line)(unsigned char *buf, int page, int line)
{
int bytes = 0;
@@ -874,11 +917,12 @@ static int _ast_adsi_set_line(unsigned char *buf, int page, int line)
if (line > 33) return -1;
}
- if (line < 1)
+ if (line < 1) {
return -1;
+ }
/* Parameter type */
buf[bytes++] = ADSI_LINE_CONTROL;
-
+
/* Reserve space for size */
bytes++;
@@ -887,13 +931,12 @@ static int _ast_adsi_set_line(unsigned char *buf, int page, int line)
buf[1] = bytes - 2;
return bytes;
-
-};
+}
static int total = 0;
static int speeds = 0;
-static int _ast_adsi_channel_restore(struct ast_channel *chan)
+int AST_OPTIONAL_API_NAME(ast_adsi_channel_restore)(struct ast_channel *chan)
{
unsigned char dsp[256] = "", keyd[6] = "";
int bytes, x;
@@ -905,8 +948,9 @@ static int _ast_adsi_channel_restore(struct ast_channel *chan)
/* Prepare key setup messages */
if (speeds) {
- for (x = 0; x < speeds; x++)
+ for (x = 0; x < speeds; x++) {
keyd[x] = ADSI_SPEED_DIAL + x;
+ }
bytes += ast_adsi_set_keys(dsp + bytes, keyd);
}
ast_adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0);
@@ -914,24 +958,27 @@ static int _ast_adsi_channel_restore(struct ast_channel *chan)
}
-static int _ast_adsi_print(struct ast_channel *chan, char **lines, int *alignments, int voice)
+int AST_OPTIONAL_API_NAME(ast_adsi_print)(struct ast_channel *chan, char **lines, int *alignments, int voice)
{
unsigned char buf[4096];
int bytes = 0, res, x;
- for(x = 0; lines[x]; x++)
+ for (x = 0; lines[x]; x++) {
bytes += ast_adsi_display(buf + bytes, ADSI_INFO_PAGE, x+1, alignments[x], 0, lines[x], "");
+ }
bytes += ast_adsi_set_line(buf + bytes, ADSI_INFO_PAGE, 1);
- if (voice)
+ if (voice) {
bytes += ast_adsi_voice_mode(buf + bytes, 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 */
ast_waitfordigit(chan, 1000);
+ }
return res;
}
-static int _ast_adsi_load_session(struct ast_channel *chan, unsigned char *app, int ver, int data)
+int AST_OPTIONAL_API_NAME(ast_adsi_load_session)(struct ast_channel *chan, unsigned char *app, int ver, int data)
{
unsigned char dsp[256] = "";
int bytes = 0, res;
@@ -940,15 +987,18 @@ static int _ast_adsi_load_session(struct ast_channel *chan, unsigned char *app,
/* Connect to session */
bytes += ast_adsi_connect_session(dsp + bytes, app, ver);
- if (data)
+ if (data) {
bytes += ast_adsi_data_mode(dsp + bytes);
+ }
/* 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;
+ }
if (app) {
- if ((res = ast_readstring(chan, resp, 1, 1200, 1200, "")) < 0)
+ if ((res = ast_readstring(chan, resp, 1, 1200, 1200, "")) < 0) {
return -1;
+ }
if (res) {
ast_debug(1, "No response from CPE about version. Assuming not there.\n");
return 0;
@@ -967,7 +1017,7 @@ static int _ast_adsi_load_session(struct ast_channel *chan, unsigned char *app,
}
-static int _ast_adsi_unload_session(struct ast_channel *chan)
+int AST_OPTIONAL_API_NAME(ast_adsi_unload_session)(struct ast_channel *chan)
{
unsigned char dsp[256] = "";
int bytes = 0;
@@ -977,37 +1027,41 @@ static int _ast_adsi_unload_session(struct ast_channel *chan)
bytes += ast_adsi_voice_mode(dsp + bytes, 0);
/* 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 0;
}
static int str2align(const char *s)
{
- if (!strncasecmp(s, "l", 1))
+ if (!strncasecmp(s, "l", 1)) {
return ADSI_JUST_LEFT;
- else if (!strncasecmp(s, "r", 1))
+ } else if (!strncasecmp(s, "r", 1)) {
return ADSI_JUST_RIGHT;
- else if (!strncasecmp(s, "i", 1))
+ } else if (!strncasecmp(s, "i", 1)) {
return ADSI_JUST_IND;
- else
+ } else {
return ADSI_JUST_CENT;
+ }
}
static void init_state(void)
{
int x;
- for (x = 0; x < ADSI_MAX_INTRO; x++)
+ for (x = 0; x < ADSI_MAX_INTRO; x++) {
aligns[x] = ADSI_JUST_CENT;
+ }
ast_copy_string(intro[0], "Welcome to the", sizeof(intro[0]));
ast_copy_string(intro[1], "Asterisk", sizeof(intro[1]));
ast_copy_string(intro[2], "Open Source PBX", sizeof(intro[2]));
total = 3;
speeds = 0;
- for (x = 3; x < ADSI_MAX_INTRO; x++)
+ for (x = 3; x < ADSI_MAX_INTRO; x++) {
intro[x][0] = '\0';
+ }
memset(speeddial, 0, sizeof(speeddial));
alignment = ADSI_JUST_CENT;
}
@@ -1026,22 +1080,24 @@ static void adsi_load(int reload)
return;
}
for (v = ast_variable_browse(conf, "intro"); v; v = v->next) {
- if (!strcasecmp(v->name, "alignment"))
+ if (!strcasecmp(v->name, "alignment")) {
alignment = str2align(v->value);
- else if (!strcasecmp(v->name, "greeting")) {
+ } else if (!strcasecmp(v->name, "greeting")) {
if (x < ADSI_MAX_INTRO) {
aligns[x] = alignment;
ast_copy_string(intro[x], v->value, sizeof(intro[x]));
x++;
}
} else if (!strcasecmp(v->name, "maxretries")) {
- if (atoi(v->value) > 0)
+ if (atoi(v->value) > 0) {
maxretries = atoi(v->value);
+ }
}
}
- if (x)
+ if (x) {
total = x;
-
+ }
+
x = 0;
for (v = ast_variable_browse(conf, "speeddial"); v; v = v->next) {
char buf[3 * SPEEDDIAL_MAX_LEN];
@@ -1049,8 +1105,9 @@ static void adsi_load(int reload)
ast_copy_string(buf, v->value, sizeof(buf));
name = strsep(&stringp, ",");
sname = strsep(&stringp, ",");
- if (!sname)
+ 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);
@@ -1058,8 +1115,9 @@ static void adsi_load(int reload)
x++;
}
}
- if (x)
+ if (x) {
speeds = x;
+ }
ast_config_destroy(conf);
return;
@@ -1074,36 +1132,6 @@ static int reload(void)
static int load_module(void)
{
adsi_load(0);
-
- ast_adsi_begin_download = _ast_adsi_begin_download;
- ast_adsi_end_download = _ast_adsi_end_download;
- ast_adsi_channel_restore = _ast_adsi_channel_restore;
- ast_adsi_print = _ast_adsi_print;
- ast_adsi_load_session = _ast_adsi_load_session;
- ast_adsi_unload_session = _ast_adsi_unload_session;
- ast_adsi_transmit_message = _ast_adsi_transmit_message;
- ast_adsi_transmit_message_full = _ast_adsi_transmit_message_full;
- ast_adsi_read_encoded_dtmf = _ast_adsi_read_encoded_dtmf;
- ast_adsi_connect_session = _ast_adsi_connect_session;
- ast_adsi_query_cpeid = _ast_adsi_query_cpeid;
- ast_adsi_query_cpeinfo = _ast_adsi_query_cpeinfo;
- ast_adsi_get_cpeid = _ast_adsi_get_cpeid;
- ast_adsi_get_cpeinfo = _ast_adsi_get_cpeinfo;
- ast_adsi_download_connect = _ast_adsi_download_connect;
- ast_adsi_disconnect_session = _ast_adsi_disconnect_session;
- ast_adsi_download_disconnect = _ast_adsi_download_disconnect;
- ast_adsi_data_mode = _ast_adsi_data_mode;
- ast_adsi_clear_soft_keys = _ast_adsi_clear_soft_keys;
- ast_adsi_clear_screen = _ast_adsi_clear_screen;
- ast_adsi_voice_mode = _ast_adsi_voice_mode;
- ast_adsi_available = _ast_adsi_available;
- ast_adsi_display = _ast_adsi_display;
- ast_adsi_set_line = _ast_adsi_set_line;
- ast_adsi_load_soft_key = _ast_adsi_load_soft_key;
- ast_adsi_set_keys = _ast_adsi_set_keys;
- ast_adsi_input_control = _ast_adsi_input_control;
- ast_adsi_input_format = _ast_adsi_input_format;
-
return AST_MODULE_LOAD_SUCCESS;
}
@@ -1113,7 +1141,7 @@ static int unload_module(void)
return -1;
}
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "ADSI Resource",
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "ADSI Resource",
.load = load_module,
.unload = unload_module,
.reload = reload,