aboutsummaryrefslogtreecommitdiffstats
path: root/net/asterisk-bristuff
diff options
context:
space:
mode:
authorsobomax <sobomax@FreeBSD.org>2005-07-11 19:11:36 +0800
committersobomax <sobomax@FreeBSD.org>2005-07-11 19:11:36 +0800
commit4ebd5dda6a1dc4a7a0cbb296a8e1360dea7b4cbb (patch)
tree37820bc92a5517645869e2e6a240266e9132532d /net/asterisk-bristuff
parent4200448368be3859d00a317d5d03453b3bef5c1a (diff)
downloadfreebsd-ports-gnome-4ebd5dda6a1dc4a7a0cbb296a8e1360dea7b4cbb.tar.gz
freebsd-ports-gnome-4ebd5dda6a1dc4a7a0cbb296a8e1360dea7b4cbb.tar.zst
freebsd-ports-gnome-4ebd5dda6a1dc4a7a0cbb296a8e1360dea7b4cbb.zip
Add support for faxes based on spandsp port.
Diffstat (limited to 'net/asterisk-bristuff')
-rw-r--r--net/asterisk-bristuff/Makefile10
-rw-r--r--net/asterisk-bristuff/files/patch-apps::Makefile28
-rw-r--r--net/asterisk-bristuff/files/patch-apps::app_rxfax.c370
-rw-r--r--net/asterisk-bristuff/files/patch-apps::app_txfax.c292
-rw-r--r--net/asterisk-bristuff/pkg-plist2
5 files changed, 693 insertions, 9 deletions
diff --git a/net/asterisk-bristuff/Makefile b/net/asterisk-bristuff/Makefile
index 9de27aaa038a..4c0d18d05948 100644
--- a/net/asterisk-bristuff/Makefile
+++ b/net/asterisk-bristuff/Makefile
@@ -7,7 +7,7 @@
PORTNAME= asterisk
PORTVERSION= 1.0.7
-PORTREVISION= 7
+PORTREVISION= 8
CATEGORIES= net
MASTER_SITES= ftp://ftp.asterisk.org/pub/telephony/asterisk/ \
ftp://ftp.asterisk.org/pub/telephony/asterisk/old-releases/
@@ -74,6 +74,14 @@ PLIST_SUB+= WITH_ZAPTEL=""
USE_MYSQL= yes
.endif
+.if !defined(WITHOUT_FAX)
+MAKE_ENV+= WITH_FAX=1
+LIB_DEPENDS+= spandsp.0:${PORTSDIR}/comms/spandsp
+PLIST_SUB+= WITH_FAX=""
+.else
+PLIST_SUB+= WITH_FAX="@comment "
+.endif
+
post-patch:
${CP} ${FILESDIR}/chan_oss.c ${WRKSRC}/channels
${REINPLACE_CMD} -e 's|/var/lib|${PREFIX}/share|g' ${WRKSRC}/configs/musiconhold.conf.sample
diff --git a/net/asterisk-bristuff/files/patch-apps::Makefile b/net/asterisk-bristuff/files/patch-apps::Makefile
index 00b77dfe2434..44f8495864c4 100644
--- a/net/asterisk-bristuff/files/patch-apps::Makefile
+++ b/net/asterisk-bristuff/files/patch-apps::Makefile
@@ -1,9 +1,6 @@
-
-$FreeBSD$
-
---- apps/Makefile.orig Sat Sep 25 00:32:56 2004
-+++ apps/Makefile Sun Oct 10 16:20:06 2004
-@@ -40,7 +40,7 @@
+--- apps/Makefile.orig Wed Jun 22 14:40:11 2005
++++ apps/Makefile Wed Jun 22 14:43:45 2005
+@@ -40,9 +40,13 @@
#APPS+=app_rpt.so
APPS+=$(shell if [ -f /usr/include/linux/zaptel.h ]; then echo "app_zapras.so app_meetme.so app_flash.so app_zapbarge.so app_zapscan.so" ; fi)
@@ -11,8 +8,14 @@ $FreeBSD$
+APPS+=$(shell if [ -f $(LOCALBASE)/include/zaptel.h ]; then echo "app_zapras.so app_meetme.so app_flash.so app_zapbarge.so app_zapscan.so" ; fi)
APPS+=$(shell if [ -f /usr/include/osp/osp.h ]; then echo "app_osplookup.so" ; fi)
++ifdef WITH_FAX
++APPS+=$(shell if [ -f $(LOCALBASE)/include/spandsp.h ]; then echo "app_rxfax.so app_txfax.so" ; fi)
++endif
++
CFLAGS+=-fPIC
-@@ -65,12 +65,12 @@
+
+ ifeq ($(USE_POSTGRES_VM_INTERFACE),1)
+@@ -65,12 +69,12 @@
$(CC) $(SOLINK) -o $@ $< -ltonezone
install: all
@@ -27,9 +30,18 @@ $FreeBSD$
else
ifeq ($(USE_POSTGRES_VM_INTERFACE),1)
$(CC) $(SOLINK) -o $@ $(MLFLAGS) $< -lpq
-@@ -80,16 +80,16 @@
+@@ -79,17 +83,25 @@
+ endif
endif
++ifdef WITH_FAX
++app_rxfax.so : app_rxfax.o
++ $(CC) $(SOLINK) -o $@ $< -L$(LOCALBASE)/lib -lspandsp -ltiff
++
++app_txfax.so : app_txfax.o
++ $(CC) $(SOLINK) -o $@ $< -L$(LOCALBASE)/lib -lspandsp -ltiff
++endif
++
app_sql_postgres.o: app_sql_postgres.c
- $(CC) -pipe -I/usr/local/pgsql/include $(CFLAGS) -c -o app_sql_postgres.o app_sql_postgres.c
+ $(CC) -I$(LOCALBASE)/include/pgsql $(CFLAGS) -c -o app_sql_postgres.o app_sql_postgres.c
diff --git a/net/asterisk-bristuff/files/patch-apps::app_rxfax.c b/net/asterisk-bristuff/files/patch-apps::app_rxfax.c
new file mode 100644
index 000000000000..c8f4e3e296dc
--- /dev/null
+++ b/net/asterisk-bristuff/files/patch-apps::app_rxfax.c
@@ -0,0 +1,370 @@
+--- apps/app_rxfax.c.orig Fri Jun 17 21:13:01 2005
++++ apps/app_rxfax.c Fri Jun 17 21:04:12 2005
+@@ -0,0 +1,367 @@
++/*
++ * Asterisk -- A telephony toolkit for Linux.
++ *
++ * Trivial application to receive a TIFF FAX file
++ *
++ * Copyright (C) 2003, Steve Underwood
++ *
++ * Steve Underwood <steveu@coppice.org>
++ *
++ * This program is free software, distributed under the terms of
++ * the GNU General Public License
++ */
++
++#include <asterisk/lock.h>
++#include <asterisk/file.h>
++#include <asterisk/logger.h>
++#include <asterisk/channel.h>
++#include <asterisk/pbx.h>
++#include <asterisk/module.h>
++#include <asterisk/translate.h>
++#include <asterisk/dsp.h>
++#include <asterisk/manager.h>
++#include <string.h>
++#include <stdlib.h>
++#include <stdint.h>
++#include <pthread.h>
++#include <errno.h>
++#include <math.h>
++#include <tiffio.h>
++
++#include <spandsp.h>
++
++static char *tdesc = "Trivial FAX Receive Application";
++
++static char *app = "RxFAX";
++
++static char *synopsis = "Receive a FAX to a file";
++
++static char *descrip =
++" RxFAX(filename[|caller][|debug]): Receives a FAX from the channel into the\n"
++"given filename. If the file exists it will be overwritten. The file\n"
++"should be in TIFF/F format.\n"
++"The \"caller\" option makes the application behave as a calling machine,\n"
++"rather than the answering machine. The default behaviour is to behave as\n"
++"an answering machine.\n"
++"Uses LOCALSTATIONID to identify itself to the remote end.\n"
++" LOCALHEADERINFO to generate a header line on each page.\n"
++"Sets REMOTESTATIONID to the sender CSID.\n"
++" FAXPAGES to the number of pages received.\n"
++" FAXBITRATE to the transmition rate.\n"
++" FAXRESOLUTION to the resolution.\n"
++"Returns -1 when the user hangs up.\n"
++"Returns 0 otherwise.\n";
++
++STANDARD_LOCAL_USER;
++
++LOCAL_USER_DECL;
++
++#define MAX_BLOCK_SIZE 240
++
++static void t30_flush(t30_state_t *s, int which)
++{
++ //TODO:
++}
++/*- End of function --------------------------------------------------------*/
++
++static void phase_e_handler(t30_state_t *s, void *user_data, int result)
++{
++ struct ast_channel *chan;
++ t30_stats_t t;
++ char local_ident[21];
++ char far_ident[21];
++ char buf[11];
++
++ chan = (struct ast_channel *) user_data;
++ if (result)
++ {
++ fax_get_transfer_statistics(s, &t);
++ fax_get_far_ident(s, far_ident);
++ fax_get_local_ident(s, local_ident);
++ ast_log(LOG_DEBUG, "==============================================================================\n");
++ ast_log(LOG_DEBUG, "Fax successfully received.\n");
++ ast_log(LOG_DEBUG, "Remote station id: %s\n", far_ident);
++ ast_log(LOG_DEBUG, "Local station id: %s\n", local_ident);
++ ast_log(LOG_DEBUG, "Pages transferred: %i\n", t.pages_transferred);
++ ast_log(LOG_DEBUG, "Image resolution: %i x %i\n", t.column_resolution, t.row_resolution);
++ ast_log(LOG_DEBUG, "Transfer Rate: %i\n", t.bit_rate);
++ ast_log(LOG_DEBUG, "==============================================================================\n");
++ manager_event(EVENT_FLAG_CALL,
++ "FaxReceived", "Channel: %s\nExten: %s\nCallerID: %s\nRemoteStationID: %s\nLocalStationID: %s\nPagesTransferred: %i\nResolution: %i\nTransferRate: %i\nFileName: %s\n",
++ chan->name,
++ chan->exten,
++#if (ASTERISK_VERSION_NUM <= 011000)
++ chan->callerid,
++#else
++ (chan->cid.cid_num) ? chan->cid.cid_num : "",
++#endif
++ far_ident,
++ local_ident,
++ t.pages_transferred,
++ t.row_resolution,
++ t.bit_rate,
++ s->rx_file);
++ pbx_builtin_setvar_helper(chan, "REMOTESTATIONID", far_ident);
++ snprintf(buf, sizeof(buf), "%i", t.pages_transferred);
++ pbx_builtin_setvar_helper(chan, "FAXPAGES", buf);
++ snprintf(buf, sizeof(buf), "%i", t.row_resolution);
++ pbx_builtin_setvar_helper(chan, "FAXRESOLUTION", buf);
++ snprintf(buf, sizeof(buf), "%i", t.bit_rate);
++ pbx_builtin_setvar_helper(chan, "FAXBITRATE", buf);
++ }
++ else
++ {
++ ast_log(LOG_DEBUG, "==============================================================================\n");
++ ast_log(LOG_DEBUG, "Fax receive not successful.\n");
++ ast_log(LOG_DEBUG, "==============================================================================\n");
++ }
++}
++/*- End of function --------------------------------------------------------*/
++
++static void phase_d_handler(t30_state_t *s, void *user_data, int result)
++{
++ struct ast_channel *chan;
++ t30_stats_t t;
++
++ chan = (struct ast_channel *) user_data;
++ if (result)
++ {
++ fax_get_transfer_statistics(s, &t);
++ ast_log(LOG_DEBUG, "==============================================================================\n");
++ ast_log(LOG_DEBUG, "Pages transferred: %i\n", t.pages_transferred);
++ ast_log(LOG_DEBUG, "Image size: %i x %i\n", t.columns, t.rows);
++ ast_log(LOG_DEBUG, "Image resolution %i x %i\n", t.column_resolution, t.row_resolution);
++ ast_log(LOG_DEBUG, "Transfer Rate: %i\n", t.bit_rate);
++ ast_log(LOG_DEBUG, "Bad rows %i\n", t.bad_rows);
++ ast_log(LOG_DEBUG, "Longest bad row run %i\n", t.longest_bad_row_run);
++ ast_log(LOG_DEBUG, "Compression type %i\n", t.encoding);
++ ast_log(LOG_DEBUG, "Image size (bytes) %i\n", t.image_size);
++ ast_log(LOG_DEBUG, "==============================================================================\n");
++ }
++}
++/*- End of function --------------------------------------------------------*/
++
++static int rxfax_exec(struct ast_channel *chan, void *data)
++{
++ int res = 0;
++ char template_file[256];
++ char target_file[256];
++ char *s;
++ char *t;
++ char *v;
++ char *x;
++ int option;
++ int len;
++ int i;
++ t30_state_t fax;
++ int calling_party;
++ int verbose;
++ int samples;
++
++ struct localuser *u;
++ struct ast_frame *inf = NULL;
++ struct ast_frame outf;
++
++ int original_read_fmt;
++ int original_write_fmt;
++
++ uint8_t __buf[sizeof(uint16_t)*MAX_BLOCK_SIZE + 2*AST_FRIENDLY_OFFSET];
++ uint8_t *buf = __buf + AST_FRIENDLY_OFFSET;
++
++ if (chan == NULL)
++ {
++ ast_log(LOG_WARNING, "Fax receive channel is NULL. Giving up.\n");
++ return -1;
++ }
++
++ /* The next few lines of code parse out the filename and header from the input string */
++ if (data == NULL)
++ {
++ /* No data implies no filename or anything is present */
++ ast_log(LOG_WARNING, "Rxfax requires an argument (filename)\n");
++ return -1;
++ }
++
++ calling_party = FALSE;
++ verbose = FALSE;
++ target_file[0] = '\0';
++
++ for (option = 0, v = s = data; v; option++, s++)
++ {
++ t = s;
++ v = strchr(s, '|');
++ s = (v) ? v : s + strlen(s);
++ strncpy(buf, t, s - t);
++ buf[s - t] = '\0';
++ if (option == 0)
++ {
++ /* The first option is always the file name */
++ len = s - t;
++ if (len > 255)
++ len = 255;
++ strncpy(target_file, t, len);
++ target_file[len] = '\0';
++ /* Allow the use of %d in the file name for a wild card of sorts, to
++ create a new file with the specified name scheme */
++ if ((x = strchr(target_file, '%')) && x[1] == 'd')
++ {
++ strcpy(template_file, target_file);
++ i = 0;
++ do
++ {
++ snprintf(target_file, 256, template_file, 1);
++ i++;
++ }
++ while (ast_fileexists(target_file, "", chan->language) != -1);
++ }
++ }
++ else if (strncmp("caller", t, s - t) == 0)
++ {
++ calling_party = TRUE;
++ }
++ else if (strncmp("debug", t, s - t) == 0)
++ {
++ verbose = TRUE;
++ }
++ }
++
++ /* Done parsing */
++
++ LOCAL_USER_ADD(u);
++
++ if (chan->_state != AST_STATE_UP)
++ {
++ /* Shouldn't need this, but checking to see if channel is already answered
++ * Theoretically asterisk should already have answered before running the app */
++ res = ast_answer(chan);
++ }
++
++ if (!res)
++ {
++ original_read_fmt = chan->readformat;
++ if (original_read_fmt != AST_FORMAT_SLINEAR)
++ {
++ res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
++ if (res < 0)
++ {
++ ast_log(LOG_WARNING, "Unable to set to linear read mode, giving up\n");
++ return -1;
++ }
++ }
++ original_write_fmt = chan->writeformat;
++ if (original_write_fmt != AST_FORMAT_SLINEAR)
++ {
++ res = ast_set_write_format(chan, AST_FORMAT_SLINEAR);
++ if (res < 0)
++ {
++ ast_log(LOG_WARNING, "Unable to set to linear write mode, giving up\n");
++ res = ast_set_read_format(chan, original_read_fmt);
++ if (res)
++ ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", chan->name);
++ return -1;
++ }
++ }
++ fax_init(&fax, calling_party, NULL);
++ fax.verbose = verbose;
++ x = pbx_builtin_getvar_helper(chan, "LOCALSTATIONID");
++ if (x && x[0])
++ fax_set_local_ident(&fax, x);
++ x = pbx_builtin_getvar_helper(chan, "LOCALHEADERINFO");
++ if (x && x[0])
++ fax_set_header_info(&fax, x);
++ fax_set_rx_file(&fax, target_file);
++ //fax_set_phase_b_handler(&fax, phase_b_handler, chan);
++ fax_set_phase_d_handler(&fax, phase_d_handler, chan);
++ fax_set_phase_e_handler(&fax, phase_e_handler, chan);
++ while (ast_waitfor(chan, -1) > -1)
++ {
++ inf = ast_read(chan);
++ if (inf == NULL)
++ {
++ res = -1;
++ break;
++ }
++ if (inf->frametype == AST_FRAME_VOICE)
++ {
++ if (fax_rx_process(&fax, inf->data, inf->samples))
++ break;
++ samples = (inf->samples <= MAX_BLOCK_SIZE) ? inf->samples : MAX_BLOCK_SIZE;
++ len = fax_tx_process(&fax, (int16_t *) &buf[AST_FRIENDLY_OFFSET], samples);
++ if (len)
++ {
++ memset(&outf, 0, sizeof(outf));
++ outf.frametype = AST_FRAME_VOICE;
++ outf.subclass = AST_FORMAT_SLINEAR;
++ outf.datalen = len*sizeof(int16_t);
++ outf.samples = len;
++ outf.data = &buf[AST_FRIENDLY_OFFSET];
++ outf.offset = AST_FRIENDLY_OFFSET;
++ outf.src = "RxFAX";
++ if (ast_write(chan, &outf) < 0)
++ {
++ ast_log(LOG_WARNING, "Unable to write frame to channel; %s\n", strerror(errno));
++ break;
++ }
++ }
++ }
++ ast_frfree(inf);
++ }
++ if (inf == NULL)
++ {
++ ast_log(LOG_DEBUG, "Got hangup\n");
++ res = -1;
++ }
++ if (original_read_fmt != AST_FORMAT_SLINEAR)
++ {
++ res = ast_set_read_format(chan, original_read_fmt);
++ if (res)
++ ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", chan->name);
++ }
++ if (original_write_fmt != AST_FORMAT_SLINEAR)
++ {
++ res = ast_set_write_format(chan, original_write_fmt);
++ if (res)
++ ast_log(LOG_WARNING, "Unable to restore write format on '%s'\n", chan->name);
++ }
++ }
++ else
++ {
++ ast_log(LOG_WARNING, "Could not answer channel '%s'\n", chan->name);
++ }
++ LOCAL_USER_REMOVE(u);
++ return res;
++}
++/*- End of function --------------------------------------------------------*/
++
++int unload_module(void)
++{
++ STANDARD_HANGUP_LOCALUSERS;
++ return ast_unregister_application(app);
++}
++/*- End of function --------------------------------------------------------*/
++
++int load_module(void)
++{
++ return ast_register_application(app, rxfax_exec, synopsis, descrip);
++}
++
++char *description(void)
++{
++ return tdesc;
++}
++/*- End of function --------------------------------------------------------*/
++
++int usecount(void)
++{
++ int res;
++ STANDARD_USECOUNT(res);
++ return res;
++}
++/*- End of function --------------------------------------------------------*/
++
++char *key(void)
++{
++ return ASTERISK_GPL_KEY;
++}
++/*- End of function --------------------------------------------------------*/
++/*- End of file ------------------------------------------------------------*/
diff --git a/net/asterisk-bristuff/files/patch-apps::app_txfax.c b/net/asterisk-bristuff/files/patch-apps::app_txfax.c
new file mode 100644
index 000000000000..52bcc3fdde23
--- /dev/null
+++ b/net/asterisk-bristuff/files/patch-apps::app_txfax.c
@@ -0,0 +1,292 @@
+--- apps/app_txfax.c.orig Fri Jun 17 21:13:05 2005
++++ apps/app_txfax.c Fri Jun 17 21:00:43 2005
+@@ -0,0 +1,289 @@
++/*
++ * Asterisk -- A telephony toolkit for Linux.
++ *
++ * Trivial application to send a TIFF file as a FAX
++ *
++ * Copyright (C) 2003, Steve Underwood
++ *
++ * Steve Underwood <steveu@coppice.org>
++ *
++ * This program is free software, distributed under the terms of
++ * the GNU General Public License
++ */
++
++#include <asterisk/lock.h>
++#include <asterisk/file.h>
++#include <asterisk/logger.h>
++#include <asterisk/channel.h>
++#include <asterisk/pbx.h>
++#include <asterisk/module.h>
++#include <asterisk/translate.h>
++#include <string.h>
++#include <stdlib.h>
++#include <stdint.h>
++#include <pthread.h>
++#include <errno.h>
++#include <tiffio.h>
++
++#include <spandsp.h>
++
++static char *tdesc = "Trivial FAX Transmit Application";
++
++static char *app = "TxFAX";
++
++static char *synopsis = "Send a FAX file";
++
++static char *descrip =
++" TxFAX(filename[|caller][|debug]): Send a given TIFF file to the channel as a FAX.\n"
++"The \"caller\" option makes the application behave as a calling machine,\n"
++"rather than the answering machine. The default behaviour is to behave as\n"
++"an answering machine.\n"
++"Uses LOCALSTATIONID to identify itself to the remote end.\n"
++" LOCALHEADERINFO to generate a header line on each page.\n"
++"Sets REMOTESTATIONID to the receiver CSID.\n"
++"Returns -1 when the user hangs up, or if the file does not exist.\n"
++"Returns 0 otherwise.\n";
++
++STANDARD_LOCAL_USER;
++
++LOCAL_USER_DECL;
++
++#define MAX_BLOCK_SIZE 240
++
++static void t30_flush(t30_state_t *s, int which)
++{
++ //TODO:
++}
++/*- End of function --------------------------------------------------------*/
++
++static void phase_e_handler(t30_state_t *s, void *user_data, int result)
++{
++ struct ast_channel *chan;
++ char far_ident[21];
++
++ chan = (struct ast_channel *) user_data;
++ if (result)
++ {
++ fax_get_far_ident(s, far_ident);
++ pbx_builtin_setvar_helper(chan, "REMOTESTATIONID", far_ident);
++ }
++ else
++ {
++ ast_log(LOG_DEBUG, "==============================================================================\n");
++ ast_log(LOG_DEBUG, "Fax send not successful.\n");
++ ast_log(LOG_DEBUG, "==============================================================================\n");
++ }
++}
++/*- End of function --------------------------------------------------------*/
++
++static int txfax_exec(struct ast_channel *chan, void *data)
++{
++ int res = 0;
++ char source_file[256];
++ char *x;
++ char *s;
++ char *t;
++ char *v;
++ int option;
++ int len;
++ t30_state_t fax;
++ int calling_party;
++ int verbose;
++ int samples;
++
++ struct localuser *u;
++ struct ast_frame *inf = NULL;
++ struct ast_frame outf;
++
++ int original_read_fmt;
++ int original_write_fmt;
++
++ uint8_t __buf[sizeof(uint16_t)*MAX_BLOCK_SIZE + 2*AST_FRIENDLY_OFFSET];
++ uint8_t *buf = __buf + AST_FRIENDLY_OFFSET;
++
++ if (chan == NULL)
++ {
++ ast_log(LOG_WARNING, "Fax transmit channel is NULL. Giving up.\n");
++ return -1;
++ }
++
++ /* The next few lines of code parse out the filename and header from the input string */
++ if (data == NULL)
++ {
++ /* No data implies no filename or anything is present */
++ ast_log(LOG_WARNING, "Txfax requires an argument (filename)\n");
++ return -1;
++ }
++
++ calling_party = FALSE;
++ verbose = FALSE;
++ source_file[0] = '\0';
++
++ for (option = 0, v = s = data; v; option++, s++)
++ {
++ t = s;
++ v = strchr(s, '|');
++ s = (v) ? v : s + strlen(s);
++ strncpy(buf, t, s - t);
++ buf[s - t] = '\0';
++ if (option == 0)
++ {
++ /* The first option is always the file name */
++ len = s - t;
++ if (len > 255)
++ len = 255;
++ strncpy(source_file, t, len);
++ source_file[len] = '\0';
++ }
++ else if (strncmp("caller", t, s - t) == 0)
++ {
++ calling_party = TRUE;
++ }
++ else if (strncmp("debug", t, s - t) == 0)
++ {
++ verbose = TRUE;
++ }
++ }
++
++ /* Done parsing */
++
++ LOCAL_USER_ADD(u);
++
++ if (chan->_state != AST_STATE_UP)
++ {
++ /* Shouldn't need this, but checking to see if channel is already answered
++ * Theoretically asterisk should already have answered before running the app */
++ res = ast_answer(chan);
++ }
++
++ if (!res)
++ {
++ original_read_fmt = chan->readformat;
++ if (original_read_fmt != AST_FORMAT_SLINEAR)
++ {
++ res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
++ if (res < 0)
++ {
++ ast_log(LOG_WARNING, "Unable to set to linear read mode, giving up\n");
++ return -1;
++ }
++ }
++ original_write_fmt = chan->writeformat;
++ if (original_write_fmt != AST_FORMAT_SLINEAR)
++ {
++ res = ast_set_write_format(chan, AST_FORMAT_SLINEAR);
++ if (res < 0)
++ {
++ ast_log(LOG_WARNING, "Unable to set to linear write mode, giving up\n");
++ res = ast_set_read_format(chan, original_read_fmt);
++ if (res)
++ ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", chan->name);
++ return -1;
++ }
++ }
++ fax_init(&fax, calling_party, NULL);
++ fax.verbose = verbose;
++
++ x = pbx_builtin_getvar_helper(chan, "LOCALSTATIONID");
++ if (x && x[0])
++ fax_set_local_ident(&fax, x);
++ x = pbx_builtin_getvar_helper(chan, "LOCALHEADERINFO");
++ if (x && x[0])
++ fax_set_header_info(&fax, x);
++ fax_set_tx_file(&fax, source_file);
++ //fax_set_phase_b_handler(&fax, phase_b_handler, chan);
++ //fax_set_phase_d_handler(&fax, phase_d_handler, chan);
++ fax_set_phase_e_handler(&fax, phase_e_handler, chan);
++ while (ast_waitfor(chan, -1) > -1)
++ {
++ inf = ast_read(chan);
++ if (inf == NULL)
++ {
++ res = -1;
++ break;
++ }
++ if (inf->frametype == AST_FRAME_VOICE)
++ {
++ if (fax_rx_process(&fax, inf->data, inf->samples))
++ break;
++ samples = (inf->samples <= MAX_BLOCK_SIZE) ? inf->samples : MAX_BLOCK_SIZE;
++ len = fax_tx_process(&fax, (int16_t *) &buf[AST_FRIENDLY_OFFSET], samples);
++ if (len)
++ {
++ memset(&outf, 0, sizeof(outf));
++ outf.frametype = AST_FRAME_VOICE;
++ outf.subclass = AST_FORMAT_SLINEAR;
++ outf.datalen = len*sizeof(int16_t);
++ outf.samples = len;
++ outf.data = &buf[AST_FRIENDLY_OFFSET];
++ outf.offset = AST_FRIENDLY_OFFSET;
++ if (ast_write(chan, &outf) < 0)
++ {
++ ast_log(LOG_WARNING, "Unable to write frame to channel; %s\n", strerror(errno));
++ break;
++ }
++ }
++ }
++ ast_frfree(inf);
++ }
++ if (inf == NULL)
++ {
++ ast_log(LOG_DEBUG, "Got hangup\n");
++ res = -1;
++ }
++ if (original_read_fmt != AST_FORMAT_SLINEAR)
++ {
++ res = ast_set_read_format(chan, original_read_fmt);
++ if (res)
++ ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", chan->name);
++ }
++ if (original_write_fmt != AST_FORMAT_SLINEAR)
++ {
++ res = ast_set_write_format(chan, original_write_fmt);
++ if (res)
++ ast_log(LOG_WARNING, "Unable to restore write format on '%s'\n", chan->name);
++ }
++ }
++ else
++ {
++ ast_log(LOG_WARNING, "Could not answer channel '%s'\n", chan->name);
++ }
++ LOCAL_USER_REMOVE(u);
++ return res;
++}
++/*- End of function --------------------------------------------------------*/
++
++int unload_module(void)
++{
++ STANDARD_HANGUP_LOCALUSERS;
++ return ast_unregister_application(app);
++}
++/*- End of function --------------------------------------------------------*/
++
++int load_module(void)
++{
++ return ast_register_application(app, txfax_exec, synopsis, descrip);
++}
++/*- End of function --------------------------------------------------------*/
++
++char *description(void)
++{
++ return tdesc;
++}
++/*- End of function --------------------------------------------------------*/
++
++int usecount(void)
++{
++ int res;
++
++ STANDARD_USECOUNT(res);
++ return res;
++}
++/*- End of function --------------------------------------------------------*/
++
++char *key(void)
++{
++ return ASTERISK_GPL_KEY;
++}
++/*- End of function --------------------------------------------------------*/
++/*- End of file ------------------------------------------------------------*/
diff --git a/net/asterisk-bristuff/pkg-plist b/net/asterisk-bristuff/pkg-plist
index 551e80632c6e..7da453842b34 100644
--- a/net/asterisk-bristuff/pkg-plist
+++ b/net/asterisk-bristuff/pkg-plist
@@ -221,6 +221,7 @@ lib/asterisk/modules/app_queue.so
lib/asterisk/modules/app_random.so
lib/asterisk/modules/app_read.so
lib/asterisk/modules/app_record.so
+%%WITH_FAX%%lib/asterisk/modules/app_rxfax.so
lib/asterisk/modules/app_sayunixtime.so
lib/asterisk/modules/app_segfault.so
lib/asterisk/modules/app_senddtmf.so
@@ -238,6 +239,7 @@ lib/asterisk/modules/app_talkdetect.so
lib/asterisk/modules/app_test.so
lib/asterisk/modules/app_transfer.so
lib/asterisk/modules/app_txtcidname.so
+%%WITH_FAX%%lib/asterisk/modules/app_txfax.so
lib/asterisk/modules/app_url.so
lib/asterisk/modules/app_userevent.so
lib/asterisk/modules/app_verbose.so