From 836f84100dfc125b6e48e6177f8f724302f522e4 Mon Sep 17 00:00:00 2001 From: Brian West Date: Mon, 22 Jun 2009 18:53:49 +0000 Subject: [PATCH] FSSCRIPTS-17 and FSSCRIPTS-16 git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13896 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- scripts/s25vmail/README | 21 ++++ scripts/s25vmail/README.park | 72 +++++++++++++ scripts/s25vmail/s25park.js | 178 ++++++++++++++++++++++++++++++++ scripts/s25vmail/s25vmail.js | 53 +++++++++- scripts/s25vmail/s25vmail_mwi.c | 36 ++++++- 5 files changed, 352 insertions(+), 8 deletions(-) create mode 100644 scripts/s25vmail/README.park create mode 100644 scripts/s25vmail/s25park.js diff --git a/scripts/s25vmail/README b/scripts/s25vmail/README index 05b511e44e..040bf5ae23 100644 --- a/scripts/s25vmail/README +++ b/scripts/s25vmail/README @@ -40,3 +40,24 @@ Configuration fragments look something like: Tested using FreeSWITCH SVN 10428 running on FreeBSD 6.3 with a Sangoma A200DX Analog Series w/ Echo Cancellation ports card containing 2 FXO modules. + +Note that the PBX is * very * sensitive to how long it takes +for the line to be hung up after it sends the DTMF hangup +command. Failure to apply the following patch will cause +the PBX to occasionally believe that some vmail lines were +off hook for too long and are therfore out of service. + +Index: src/zap_io.c +=================================================================== +--- src/zap_io.c (revision 745) ++++ src/zap_io.c (working copy) +@@ -1728,7 +1728,8 @@ + zchan->dtmf_hangup_buf[zchan->span->dtmf_hangup_len - 1] = *p; + if (!strcmp(zchan->dtmf_hangup_buf, zchan->span->dtmf_hangup)) { + zap_log(ZAP_LOG_DEBUG, "DTMF hangup detected.\n"); +- zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_HANGUP); ++ zchan->caller_data.hangup_cause = ZAP_CAUSE_NORMAL_CLEARING; ++ zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); + break; + } + } diff --git a/scripts/s25vmail/README.park b/scripts/s25vmail/README.park new file mode 100644 index 0000000000..a6f1519803 --- /dev/null +++ b/scripts/s25vmail/README.park @@ -0,0 +1,72 @@ +This directory contains software for configuring FreeSWITCH +to provide AT&T (aka Lucent aka Avaya) System 25 PBX compatible +park and pickup park functions. Specifically: + + a) Putting a call on hold and then dialing *5 will park the + call on your phone. + + b) Dialing *8 followed by an extension will pickup a call parked + on that extension. + +as a bonus: + + c) Doing a blind transfer of a call to *5 will park the call + on your phone. + + d) Doing a blind transfer of a call to *5 followed by an extension + will park the call on that extension. + + e) Dialing *8 without an extension will prompt for an extension. + +s25park.js goes into the FreeSWITCH scripts directory. + +Configuration fragments look something like: + + conf/dialplan/default.xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +The system25 park and pickup dialplan patterns are designed +to only consider four digit extensions for local parking. +"system25_pickup_from_extension" recognizes three digit +extensions as being parked on a foreign PBX ... modify +as appropriate for your installation. + +Be aware that the default dialplan contains an extension +called "group-intercept" which needs to be commented out +in order for "system25_pickup" to work since they both +match *8. + +Tested using FreeSWITCH SVN 13769 running on FreeBSD 6.4. diff --git a/scripts/s25vmail/s25park.js b/scripts/s25vmail/s25park.js new file mode 100644 index 0000000000..a6be33c967 --- /dev/null +++ b/scripts/s25vmail/s25park.js @@ -0,0 +1,178 @@ +/* + * File: s25park.js + * Purpose: Implement AT&T System 25 PBX style parking. + * Machine: OS: + * Author: John Wehle Date: June 9, 2009 + */ + +/* + * Copyright (c) 2009 Feith Systems and Software, Inc. + * All Rights Reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +/* RE to sanity check that the caller id is a valid extension */ +var extRE = /^[0-9]{3,4}$/g; + + +var dtmf_digits; + +function on_dtmf (session, type, obj, arg) + { + + if (type == "dtmf") { + dtmf_digits += obj.digit; + return false; + } + + return true; + } + + +function normalize_channel_name (name, direction, ip_addr) + { + var re = /^sofia\//g; + var length = name.search (re); + var new_name = name; + + if (length == -1) + return new_name; + + if (direction == "inbound") { + re = /@.*$/g; + + new_name = name.replace (re, "@" + ip_addr); + } + else if (direction == "outbound") { + re = /\/sip:(.*@[^:]*):.*$/g; + + new_name = name.replace (re, "/$1"); + } + + return new_name; + } + + +session.answer (); + +session.execute ("sleep", "1000"); + +/* + * Figure out the normalized form of the requester's channel name. + */ + +var requester_channel_name = normalize_channel_name ( + session.getVariable ("channel_name"), "inbound", + session.getVariable ("network_addr")); + +/* + * Find the uuid for a call on the requester's phone. + */ + +var channels = apiExecute ("show", "channels as xml"); +var re = /\s+$/g; +var length = channels.search (re); + +if (length == -1) + length = channels.length; + +channels = channels.substring (0, length); + +var xchannels = new XML (channels); +var our_uuid = session.getVariable ("uuid"); +var requester_uuid = ""; + +for each (var channel in xchannels.row) { + if (channel.uuid.toString () == our_uuid) + continue; + + var channel_name = normalize_channel_name (channel.name.toString (), + channel.direction.toString (), channel.ip_addr.toString ()); + + if (channel_name == requester_channel_name) { + requester_uuid = channel.uuid.toString (); + break; + } + } + +if (requester_uuid == "") { + session.sayPhrase ("voicemail_invalid_extension", "#", "", on_dtmf, ""); + session.hangup (); + exit (); + } + +/* + * Find the peer uuid. + */ + +var udump = apiExecute ("uuid_dump", requester_uuid + " xml"); +var re = /\s+$/g; +var length = udump.search (re); + +if (length == -1) + length = udump.length; + +udump = udump.substring (0, length); + +var xudump = new XML (udump); +var uuid = xudump.headers['Other-Leg-Unique-ID'].toString (); + +if (uuid == "") { + session.sayPhrase ("voicemail_invalid_extension", "#", "", on_dtmf, ""); + session.hangup (); + exit (); + } + +var requester_id_number = session.getVariable ("caller_id_number"); + +if (requester_id_number.search (extRE) == -1) { + session.sayPhrase ("voicemail_invalid_extension", "#", "", on_dtmf, ""); + session.hangup (); + exit (); + } + +apiExecute ("uuid_setvar", uuid + " hangup_after_bridge false"); +apiExecute ("uuid_transfer", uuid + " *5" + requester_id_number + " XML default"); + +/* + * Provide confirmation beeps followed by some silence. + */ + +var confirmation = "tone_stream://L=3;%(100,100,350,440)"; + +session.execute ("playback", confirmation); + +var i; + +for (i = 0; session.ready () && i < 100; i++) + session.execute("sleep", "100"); + +exit (); diff --git a/scripts/s25vmail/s25vmail.js b/scripts/s25vmail/s25vmail.js index 0ef17606d9..5c4e8643f6 100644 --- a/scripts/s25vmail/s25vmail.js +++ b/scripts/s25vmail/s25vmail.js @@ -4,10 +4,40 @@ * Machine: OS: * Author: John Wehle Date: June 24, 2008 * + * The message waiting indicator is handled by a separate program. + */ + +/* * Copyright (c) 2008 Feith Systems and Software, Inc. * All Rights Reserved - * - * The message waiting indicator is handled by a separate program. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -33,6 +63,7 @@ function on_dtmf (session, type, obj, arg) function prompt_for_id () { + var dto; var id; var index; var repeat; @@ -53,7 +84,10 @@ function prompt_for_id () id = dtmf_digits; if (id.indexOf ('#') == -1) { - dtmf_digits = session.getDigits (5, '#', digitTimeOut, + dto = digitTimeOut; + if (dtmf_digits.length != 0) + dto = interDigitTimeOut; + dtmf_digits = session.getDigits (5, '#', dto, interDigitTimeOut, absoluteTimeOut); id += dtmf_digits; id += '#'; @@ -87,7 +121,14 @@ start = session.getDigits (1, '', digitTimeOut, interDigitTimeOut, absoluteTimeOut); if (start != "#") { - console_log ("err", "Invalid VMAIL start code from PBX\n"); + var destination_number = session.getVariable ("destination_number"); + + console_log ("err", destination_number + " received an invalid VMAIL start code from PBX\n"); + if (session.ready ()) + session.sayPhrase ("voicemail_goodbye", "#", "", on_dtmf, ""); + else + console_log ("err", "Possibly due to early hangup from PBX\n"); + session.hangup (); exit(); } @@ -121,7 +162,7 @@ switch (mode) { from = prompt_for_id (); if (! session.ready ()) { - session.hangup(); + session.hangup (); exit(); } @@ -182,6 +223,8 @@ switch (mode) { console_log ("err", "Invalid VMAIL PDC from PBX\n"); break; } + + console_log ("err", "PBX reports problem with VMAIL PDC " + to + "\n"); break; // Unknown diff --git a/scripts/s25vmail/s25vmail_mwi.c b/scripts/s25vmail/s25vmail_mwi.c index 34b52ea7f3..d9c6798d7c 100644 --- a/scripts/s25vmail/s25vmail_mwi.c +++ b/scripts/s25vmail/s25vmail_mwi.c @@ -4,9 +4,6 @@ * Machine: OS: * Author: John Wehle Date: July 24, 2008 * - * Copyright (c) 2008 Feith Systems and Software, Inc. - * All Rights Reserved - * * Tested using a Zyxel U90e configured using: * * at OK at&f OK at&d3&y2q2 OK ats0=0s2=255s15.7=0s18=4s35.1=0 OK @@ -21,6 +18,39 @@ * ring message off */ +/* + * Copyright (c) 2008 Feith Systems and Software, Inc. + * All Rights Reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of the original author; nor the names of any contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #include #include