Skip to content

Commit

Permalink
Further development of V.150.1
Browse files Browse the repository at this point in the history
Inroduction of SSLFax, using the code submitted by Lee Howard. This needs
further testing, but should be complete.
  • Loading branch information
coppice-git committed Sep 24, 2023
1 parent a601194 commit df1282e
Show file tree
Hide file tree
Showing 23 changed files with 2,780 additions and 270 deletions.
17 changes: 16 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ AC_ARG_ENABLE(neon, [ --enable-neon Enable NEON support])
AC_ARG_ENABLE(fixed_point, [ --enable-fixed-point Enable fixed point support])
AC_ARG_ENABLE(v32bis, [ --enable-v32bis Enable V.32bis support])
AC_ARG_ENABLE(v34, [ --enable-v34 Enable V.34 support])
AC_ARG_ENABLE(sslfax, [ --enable-sslfax Enable SSL Fax support])

# The following is for MSVC, where we may be using a local copy of libtiff, built alongside spandsp
AC_ARG_ENABLE(builtin_tiff,
Expand Down Expand Up @@ -559,6 +560,11 @@ AC_CHECK_LIB([tiff], [TIFFCreateCustomDirectory], [
AC_CHECK_HEADERS([jpeglib.h])
AC_CHECK_LIB([jpeg], [jpeg_start_compress], [JPEG_LIBS="-ljpeg"], AC_MSG_ERROR("Cannot build without libjpeg (does your system require a libjpeg-devel or libjpeg-turbo-devel package?)"))

AC_CHECK_LIB([ssl], [TLS_client_method], [
AC_DEFINE([SPANDSP_SUPPORT_FLEXSSL], [1], [Support flexible OpenSSL methods])
SPANDSP_SUPPORT_FLEXSSL="#define SPANDSP_SUPPORT_FLEXSSL 1"
], [SPANDSP_SUPPORT_TIFF_FX="#undef SPANDSP_SUPPORT_FLEXSSL"], -lm)

LIBS="$LIBS $TIFF_LIBS $JPEG_LIBS"

TESTLIBS="$SIMLIBS $TESTLIBS"
Expand All @@ -577,6 +583,13 @@ else
SPANDSP_SUPPORT_V34="#undef SPANDSP_SUPPORT_V34"
fi

if test "$enable_sslfax" = "yes" ; then
AC_DEFINE([SPANDSP_SUPPORT_SSLFAX], [1], [Support SSL Fax])
SPANDSP_SUPPORT_SSLFAX="#define SPANDSP_SUPPORT_SSLFAX 1"
else
SPANDSP_SUPPORT_SSLFAX="#undef SPANDSP_SUPPORT_SSLFAX"
fi

AM_CONDITIONAL([COND_DOC], [test "$enable_doc" = yes])
AM_CONDITIONAL([COND_TESTS], [test "$enable_tests" = yes])
AM_CONDITIONAL([COND_MMX], [test "$enable_mmx" = yes])
Expand All @@ -591,6 +604,7 @@ AM_CONDITIONAL([COND_AVX2], [test "$enable_avx2" = yes])
AM_CONDITIONAL([COND_NEON], [test "$enable_neon" = yes])
AM_CONDITIONAL([COND_V32BIS], [test "$enable_v32bis" = yes])
AM_CONDITIONAL([COND_V34], [test "$enable_v34" = yes])
AM_CONDITIONAL([COND_SSLFAX], [test "$enable_sslfax" = yes])

AC_SUBST(SPANDSP_LT_CURRENT)
AC_SUBST(SPANDSP_LT_REVISION)
Expand All @@ -604,10 +618,11 @@ AC_SUBST(TESTLIBS)
AC_SUBST(SPANDSP_USE_FIXED_POINT)
AC_SUBST(SPANDSP_MISALIGNED_ACCESS_FAILS)
AC_SUBST(SPANDSP_USE_EXPORT_CAPABILITY)
AC_SUBST(SPANDSP_SUPPORT_SSLFAX)
AC_SUBST(SPANDSP_SUPPORT_T43)
AC_SUBST(SPANDSP_SUPPORT_TIFF_FX)
AC_SUBST(SPANDSP_SUPPORT_V32BIS)
AC_SUBST(SPANDSP_SUPPORT_V34)
AC_SUBST(SPANDSP_SUPPORT_TIFF_FX)
AC_SUBST(INSERT_INTTYPES_HEADER)
AC_SUBST(INSERT_STDINT_HEADER)
AC_SUBST(INSERT_TGMATH_HEADER)
Expand Down
6 changes: 3 additions & 3 deletions m4/ax_c99_features.m4
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ AC_LINK_IFELSE(
typedef struct {
int k;
char buffer [] ;
} MY_STRUCT ;
char buffer[];
} MY_STRUCT;
]],
[[MY_STRUCT *p = calloc (1, sizeof (MY_STRUCT) + 42);]])],
[[MY_STRUCT *p = calloc(1, sizeof(MY_STRUCT) + 42);]])],
[ac_cv_c99_flexible_array=yes],
[ac_cv_c99_flexible_array=no])
Expand Down
4 changes: 4 additions & 0 deletions spandsp-sim/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
AM_CFLAGS = $(COMP_VENDOR_CFLAGS)
AM_LDFLAGS = $(COMP_VENDOR_LDFLAGS)

if COND_SSLFAX
LIBS += -L$(top_builddir)/src -lspandsp -lssl $(SIMLIBS)
else
LIBS += -L$(top_builddir)/src -lspandsp $(SIMLIBS)
endif

MAINTAINERCLEANFILES = Makefile.in

Expand Down
11 changes: 9 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ MOSTLYCLEANFILES = ${DISTCLEANFILES}
MAINTAINERCLEANFILES = ${DISTCLEANFILES}

EXTRA_DIST = floating_fudge.h \
libspandsp.2012.vcxproj \
filter_tools.c \
libspandsp.2012.vcxproj \
make_at_dictionary.c \
make_cielab_luts.c \
make_math_fixed_tables.c \
Expand Down Expand Up @@ -81,6 +81,10 @@ V34_SOURCES = v34rx.c \
v34_logging.c
endif

if COND_SSLFAX
SSLFAX_SOURCES = ssl_fax.c
endif

libspandsp_la_SOURCES = ademco_contactid.c \
adsi.c \
alloc.c \
Expand Down Expand Up @@ -179,7 +183,8 @@ libspandsp_la_SOURCES = ademco_contactid.c \
vector_float.c \
vector_int.c \
$(V32BIS_SOURCES) \
$(V34_SOURCES)
$(V34_SOURCES) \
$(SSLFAX_SOURCES)

libspandsp_la_LDFLAGS = -version-info @SPANDSP_LT_CURRENT@:@SPANDSP_LT_REVISION@:@SPANDSP_LT_AGE@ $(COMP_VENDOR_LDFLAGS)

Expand Down Expand Up @@ -234,6 +239,7 @@ nobase_include_HEADERS = spandsp/ademco_contactid.h \
spandsp/stdbool.h \
spandsp/sig_tone.h \
spandsp/silence_gen.h \
spandsp/ssl_fax.h \
spandsp/sprt.h \
spandsp/super_tone_rx.h \
spandsp/super_tone_tx.h \
Expand Down Expand Up @@ -316,6 +322,7 @@ nobase_include_HEADERS = spandsp/ademco_contactid.h \
spandsp/private/schedule.h \
spandsp/private/sig_tone.h \
spandsp/private/silence_gen.h \
spandsp/private/ssl_fax.h \
spandsp/private/sprt.h \
spandsp/private/super_tone_rx.h \
spandsp/private/super_tone_tx.h \
Expand Down
44 changes: 44 additions & 0 deletions src/fax.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#include "spandsp/complex.h"
#include "spandsp/tone_detect.h"
#include "spandsp/tone_generate.h"
#include "spandsp/ssl_fax.h"
#include "spandsp/async.h"
#include "spandsp/hdlc.h"
#include "spandsp/silence_gen.h"
Expand Down Expand Up @@ -102,6 +103,7 @@
#include "spandsp/fax.h"

#include "spandsp/private/logging.h"
#include "spandsp/private/ssl_fax.h"
#include "spandsp/private/silence_gen.h"
#include "spandsp/private/power_meter.h"
#include "spandsp/private/fsk.h"
Expand Down Expand Up @@ -250,13 +252,41 @@ SPAN_DECLARE(int) fax_tx(fax_state_t *s, int16_t *amp, int max_len)
}
/*- End of function --------------------------------------------------------*/

#if defined(SPANDSP_SUPPORT_SSLFAX)
static int fax_get_phase(void *user_data)
{
t30_state_t *s = user_data;

return s->phase;
}
/*- End of function --------------------------------------------------------*/
#endif

static void fax_set_rx_type(void *user_data, int type, int bit_rate, int short_train, int use_hdlc)
{
fax_state_t *s;
fax_modems_state_t *t;

s = (fax_state_t *) user_data;
t = &s->modems;
#if defined(SPANDSP_SUPPORT_SSLFAX)
if (s->t30.sslfax.server && type != T30_MODEM_DONE)
{
span_log(&s->logging, SPAN_LOG_FLOW, "Set fallback rx type %d%s\n", type, use_hdlc ? " (HDLC)" : "");
fax_modems_set_rx_handler(t, (span_rx_handler_t) &sslfax_rx, &s->t30.sslfax, (span_rx_fillin_handler_t) NULL, &s->t30.sslfax);
sslfax_setup(&s->t30.sslfax, &s->t30, t30_non_ecm_put, t30_non_ecm_get, t30_hdlc_accept, hdlc_underflow_handler, s->t30.sslfax.tx_use_hdlc, use_hdlc, fax_get_phase);
t->rx_bit_rate = bit_rate;
t->current_rx_type = type;
if (use_hdlc)
{
t30_hdlc_accept(&s->t30, NULL, SIG_STATUS_CARRIER_UP, true);
t30_hdlc_accept(&s->t30, NULL, SIG_STATUS_FRAMING_OK, true);
}
/*endif*/
return;
}
/*endif*/
#endif
span_log(&s->logging, SPAN_LOG_FLOW, "Set rx type %s (%d)\n", t30_modem_to_str(type), type);
if (t->current_rx_type == type)
return;
Expand Down Expand Up @@ -298,6 +328,20 @@ static void fax_set_tx_type(void *user_data, int type, int bit_rate, int short_t

s = (fax_state_t *) user_data;
t = &s->modems;
#if defined(SPANDSP_SUPPORT_SSLFAX)
if (s->t30.sslfax.server && type != T30_MODEM_DONE)
{
span_log(&s->logging, SPAN_LOG_FLOW, "Set fallback tx type %d%s\n", type, use_hdlc ? " (HDLC)" : "");
fax_modems_set_tx_handler(t, (span_tx_handler_t) &sslfax_tx, &s->t30.sslfax);
fax_modems_set_next_tx_handler(t, (span_tx_handler_t) &sslfax_tx, &s->t30.sslfax);
sslfax_setup(&s->t30.sslfax, &s->t30, t30_non_ecm_put, t30_non_ecm_get, t30_hdlc_accept, hdlc_underflow_handler, use_hdlc, s->t30.sslfax.rx_use_hdlc, fax_get_phase);
t->transmit = true;
t->tx_bit_rate = bit_rate;
t->current_tx_type = type;
return;
}
/*endif*/
#endif
span_log(&s->logging, SPAN_LOG_FLOW, "Set tx type %s (%d)\n", t30_modem_to_str(type), type);
if (t->current_tx_type == type)
return;
Expand Down
1 change: 1 addition & 0 deletions src/spandsp.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
#include <spandsp/v42bis.h>
#include <spandsp/v18.h>
#include <spandsp/timezone.h>
#include <spandsp/ssl_fax.h>
#include <spandsp/t4_rx.h>
#include <spandsp/t4_tx.h>
#include <spandsp/image_translate.h>
Expand Down
1 change: 1 addition & 0 deletions src/spandsp/expose.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
#include <spandsp/private/data_modems.h>
#include <spandsp/private/fax_modems.h>
#include <spandsp/private/timezone.h>
#include <spandsp/private/ssl_fax.h>
#include <spandsp/private/image_translate.h>
#include <spandsp/private/t4_t6_decode.h>
#include <spandsp/private/t4_t6_encode.h>
Expand Down
123 changes: 123 additions & 0 deletions src/spandsp/private/ssl_fax.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* The code in this file was derived from sources taken from (1) HylaFAX+ on
* 13 June 2022. That source states that it was derived from (2) GitHub user,
* "mrwicks", on 9 Oct 2018. That source, itself, was derived from work by
* "Amlendra" published at Aticleworld on 21 May 2017 (3). That work, then,
* references programs (4) Copyright (c) 2000 Sean Walton and Macmillan
* Publishers (The "Linux Socket Programming" book) and are licensed under
* the GPL.
*
* 1. https://hylafax.sourceforge.net
* 2. https://github.com/mrwicks/miscellaneous/tree/master/tls_1.2_example
* 3. https://aticleworld.com/ssl-server-client-using-openssl-in-c/
* 4. http://www.cs.utah.edu/~swalton/listings/sockets/programs/
*
* It is, therefore, presumed that this work is either under the* public
* domain or is licensed under the GPL. A copy of the GPL is as follows...
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
//#ifndef __sslfax_H
//#define __sslfax_H
//
//#include <errno.h>
//#include <unistd.h>
//#include <string.h>
//#include <arpa/inet.h>
//#include <sys/socket.h>
//#include <sys/types.h>
//#include <netinet/in.h>
//#include <resolv.h>
//#include <stdio.h>
//#include <netdb.h>
//#include <openssl/ssl.h>
//#include <openssl/err.h>
//
//#include "Str.h"
//
//struct SSLFaxProcess {
// SSL_CTX *ctx;
// SSL *ssl;
// int server;
// int client;
// fxStr emsg; // error message
//};
//
//struct SSLFax {
//public:
// int getAddressFamily(fxStr& address);
// SSLFaxProcess null();
// SSLFaxProcess startServer(fxStr info, fxStr pemFile);
// SSLFaxProcess startClient(fxStr info, fxStr passcode, const uint8_t *bitrev, long ms);
// void acceptClient(SSLFaxProcess& sfp, fxStr passcode, int modemFd, long ms);
// bool acceptClient1(SSLFaxProcess& sfp, long ms, bool sustain = false);
// void acceptClient2(SSLFaxProcess& sfp, fxStr passcode, int modemFd, long ms, bool sustain = false);
// void cleanup(SSLFaxProcess& sfp, bool sustain = false);
// int pending(SSLFaxProcess& sfp);
// int read(SSLFaxProcess& sfp, void *buf, size_t count, int modemFd, long ms, bool sustain = false, bool carryon = false);
// int write(SSLFaxProcess& sfp, const uint8_t *buf, unsigned int count, const uint8_t *bitrev, int modemFd, long ms, bool eod, bool sustain = false);
//};
//
//#endif

/*! \file */

#if !defined(_SPANDSP_PRIVATE_SSLFAX_H_)
#define _SPANDSP_PRIVATE_SSLFAX_H_

#include <openssl/ssl.h>
#include <openssl/err.h>

/*!
SSL Fax connection descriptor. This defines the state of a single
instance of an SSL Fax connection.
*/
struct sslfax_state_s
{
/*! \brief The remote SSL Fax URL, if known, else NULL. */
char* url;
SSL_CTX *ctx;
SSL *ssl;
int server;
int client;
int rcp_count;
int ecm_ones;
int ecm_bitpos;
uint8_t ecm_byte;
bool doread;
int signal;
bool do_underflow;
bool cleanup;

get_byte_func_t get_phase;

/*! \brief A user specified opaque pointer passed to the put, get, and hdlc routines. */
void *msg_user_data;
/*! \brief The callback function used to get bytes to be transmitted. */
get_msg_func_t get_msg;
/*! \brief The callback function used to put bytes received. */
put_msg_func_t put_msg;
/*! \brief The callback function used to accept HDLC frames. */
hdlc_frame_handler_t hdlc_accept;
/*! \brief The callback function used for HDLC underflow indication. */
hdlc_underflow_handler_t hdlc_tx_underflow;
/*! \brief Whether or not the data represents HDLC or not. */
bool tx_use_hdlc;
bool rx_use_hdlc;

/*! \brief Error and flow logging control */
logging_state_t logging;
};

#endif
/*- End of file ------------------------------------------------------------*/
5 changes: 5 additions & 0 deletions src/spandsp/private/t30.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ struct t30_state_s
deciding whether to continue error correction when PPRs keep repeating. */
int ecm_progress;

#if defined(SPANDSP_SUPPORT_SSLFAX)
/*! \brief SSL Fax context. */
sslfax_state_t sslfax;
#endif

/*! \brief The number of RTP events */
int rtp_events;
/*! \brief The number of RTN events */
Expand Down
Loading

0 comments on commit df1282e

Please sign in to comment.