app_swift-1.6.2.patch v2010011101 While attempting to compile app_swift 1.6.2 (temporarily available at http://jeremy.kister.net/code/app_swift-1.6.2.tar.gz) I ran into lots of problems. This patch fixes 3 issues and creates 1 enhancement: * running "make" gives 'AST_MODULE' undeclared (first use in this function) * running "make" gives error: incompatible types in assignment * DTMF detection broken if you are interrupting the cepstral playback * DTMF detection could only handle a number up to 2147483647 (which can't handle 90% of the phone numbers out there) This patch has been tested on asterisk 1.6.1.12-18 and 1.6.2.8 ##################################################################### the details: ##################################################################### pbx1> make gcc -I/opt/swift/include -g -Wall -D_REENTRANT -D_GNU_SOURCE -fPIC -c -o app_swift.o app_swift.c app_swift.c: In function 'engine': app_swift.c:396: error: incompatible types in assignment app_swift.c: In function 'load_module': app_swift.c:540: error: 'AST_MODULE' undeclared (first use in this function) app_swift.c:540: error: (Each undeclared identifier is reported only once app_swift.c:540: error: for each function it appears in.) make: *** [app_swift.o] Error 1 so i moved AST_MODULE but still got the pointer error: pbx1> make gcc -I/opt/swift/include -g -Wall -D_REENTRANT -D_GNU_SOURCE -fPIC -c -o app_swift.o app_swift.c app_swift.c: In function 'engine': app_swift.c:398: error: incompatible types in assignment make: *** [app_swift.o] Error 1 After a quick email to Darren, he told me what else to fix. Then, I realized that DTMF detection was not functioning properly during barge-in of cepstral playback. After an unanswered email to Darren, numerous posts to asterisk-users (not just from me), and finding lots of other unhappy users via search engine, I fixed that too. See: http://lists.digium.com/pipermail/asterisk-users/2010-January/243144.html Along with the DTMF detection, I changed the routines to deal with large numbers - such as a phone number. The previous code used 'signed int' which made the biggest number possible 2147483647 (which can't deal with most 10 digit phone numbers). to install: # remember to: echo /opt/swift/lib >> /etc/ld.so.conf # remember to: ldconfig wget http://jeremy.kister.net/code/app_swift-1.6.2.patch tar -zxvf app_swift-1.6.2.tar.gz cd app_swift-1.6.2 patch app_swift.c < ../app_swift-1.6.2.patch make make install ###################################################################### --- app_swift-1.6.2.orig/app_swift.c 2008-07-09 13:42:10.000000000 -0400 +++ app_swift-1.6.2/app_swift.c 2010-01-11 06:12:20.000000000 -0500 @@ -27,7 +27,7 @@ ***/ #include "asterisk.h" -ASTERISK_FILE_VERSION(__FILE__, "$Revision: 1.6.2 $") +ASTERISK_FILE_VERSION(__FILE__, "$Revision: 1.6.2.2010011101 $") #include #include @@ -71,10 +71,12 @@ const int framesize = 160 * 4; const int samplerate = 8000; // We do uLAW +#define AST_MODULE "app_swift" #define SWIFT_CONFIG_FILE "swift.conf" static unsigned int cfg_buffer_size; static int cfg_goto_exten; static char cfg_voice[20]; +static char dtmf_conversion[100]; // Data shared between is and the swift generating process struct stuff { @@ -225,12 +227,13 @@ return *res; } -static int listen_for_dtmf(struct ast_channel *chan, int timeout, int max_digits) +static char* listen_for_dtmf(struct ast_channel *chan, int timeout, int max_digits) { - char *dtmf_conversion = (char *) malloc(100); char cnv[2]; - int dtmf, res; + int dtmf, n; int i = 0, loop = 0; + for (n=0; n<101; n++) + dtmf_conversion[n] = '\0'; /* because jkister doesnt know how to clear variables */ while (i < max_digits && loop == 0) { @@ -249,16 +252,15 @@ } } - res = strtol(dtmf_conversion, NULL, 0); - - return res; + return dtmf_conversion; } static int engine(struct ast_channel *chan, void *data) { int res = 0, argc = 0, max_digits = 0, timeout = 0, alreadyran = 0; - int ms, len, old_writeformat, availatend, rc; - char *argv[3], *parse = NULL, *text = NULL, results[20], tmp_exten[2]; + int ms, len, old_writeformat, availatend; + char *dstring; + char *argv[3], *parse = NULL, *text = NULL, tmp_exten[2]; struct ast_module_user *u; struct ast_frame *f; struct myframe { @@ -393,7 +395,7 @@ myf.f.subclass = AST_FORMAT_ULAW; myf.f.datalen = len; myf.f.samples = len; - myf.f.data = myf.frdata; + myf.f.data.ptr = myf.frdata; myf.f.mallocd = 0; myf.f.offset = AST_FRIENDLY_OFFSET; myf.f.src = __PRETTY_FUNCTION__; @@ -431,7 +433,7 @@ ps->immediate_exit = 1; ASTOBJ_UNLOCK(ps); - } else if (f->frametype == AST_FRAME_DTMF && timeout > 0 && max_digits > 0) { + } else if (f->frametype == AST_FRAME_DTMF_BEGIN && timeout > 0 && max_digits > 0) { alreadyran = 1; res = 0; @@ -440,19 +442,13 @@ ps->immediate_exit = 1; ASTOBJ_UNLOCK(ps); - if (max_digits > 1) { - rc = listen_for_dtmf(chan, timeout, max_digits - 1); - } - - if (rc) { - sprintf(results, "%c%d", f->subclass, rc); - } else { - sprintf(results, "%c", f->subclass); + dstring = listen_for_dtmf(chan, timeout, max_digits); + if (ast_strlen_zero(dstring)) { + ast_log(LOG_NOTICE, "No DTMF\n"); /* can we ever get here? */ + }else{ + ast_log(LOG_NOTICE, "DTMF = %s\n", dstring); + pbx_builtin_setvar_helper(chan, "SWIFT_DTMF", dstring); } - - ast_log(LOG_NOTICE, "DTMF = %s\n", results); - pbx_builtin_setvar_helper(chan, "SWIFT_DTMF", results); - ast_frfree(f); } else { // ignore other frametypes @@ -473,19 +469,18 @@ } if (alreadyran == 0 && timeout > 0 && max_digits > 0) { - rc = listen_for_dtmf(chan, timeout, max_digits); - if (rc) { - sprintf(results, "%d", rc); - ast_log(LOG_NOTICE, "DTMF = %s\n", results); - pbx_builtin_setvar_helper(chan, "SWIFT_DTMF", results); - } else { + dstring = listen_for_dtmf(chan, timeout, max_digits); + if (ast_strlen_zero(dstring)) { ast_log(LOG_NOTICE, "No DTMF\n"); + } else { + ast_log(LOG_NOTICE, "DTMF = %s\n", dstring); + pbx_builtin_setvar_helper(chan, "SWIFT_DTMF", dstring); } } - if (max_digits == 1 && rc) { + if (max_digits == 1 && (!ast_strlen_zero(dstring))) { if (cfg_goto_exten) { - if (ast_exists_extension (chan, chan->context, results, 1, chan->cid.cid_num)) { + if (ast_exists_extension (chan, chan->context, dstring, 1, chan->cid.cid_num)) { strncpy(chan->exten, tmp_exten, sizeof(chan->exten) - 1); chan->priority = 0; } @@ -571,6 +566,4 @@ return tdesc; } -#define AST_MODULE "app_swift" - AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Cepstral Swift TTS Application");