diff --git a/.gitignore b/.gitignore index f153ad6f7b..25c5511823 100644 --- a/.gitignore +++ b/.gitignore @@ -99,6 +99,7 @@ TAGS /build/Makefile /build/Makefile.in /build/modmake.rules +/build/print_git_revision /libs/curl/lib/ca-bundle.h /libs/esl/fs_cli diff --git a/.version.in b/.version.in deleted file mode 100644 index 449460b02e..0000000000 --- a/.version.in +++ /dev/null @@ -1 +0,0 @@ -@SWITCH_VERSION_REVISION@ diff --git a/Freeswitch.2010.sln b/Freeswitch.2010.sln index 954ce1cc1b..cd22423f5b 100644 --- a/Freeswitch.2010.sln +++ b/Freeswitch.2010.sln @@ -527,6 +527,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_gsmopen", "src\mod\endp EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libzrtp", "libs\libzrtp\projects\win\libzrtp.2010.vcxproj", "{C13CC324-0032-4492-9A30-310A6BD64FF5}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_redis", "src\mod\applications\mod_redis\mod_redis.2010.vcxproj", "{886B5E9D-F2C2-4AF2-98C8-EF98C4C770E6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution All|Win32 = All|Win32 @@ -3593,6 +3595,19 @@ Global {C13CC324-0032-4492-9A30-310A6BD64FF5}.Release|x64.Build.0 = Release|x64 {C13CC324-0032-4492-9A30-310A6BD64FF5}.Release|x64 Setup.ActiveCfg = Release|Win32 {C13CC324-0032-4492-9A30-310A6BD64FF5}.Release|x86 Setup.ActiveCfg = Release|Win32 + {886B5E9D-F2C2-4AF2-98C8-EF98C4C770E6}.All|Win32.ActiveCfg = Release|x64 + {886B5E9D-F2C2-4AF2-98C8-EF98C4C770E6}.All|x64.ActiveCfg = Release|x64 + {886B5E9D-F2C2-4AF2-98C8-EF98C4C770E6}.All|x64.Build.0 = Release|x64 + {886B5E9D-F2C2-4AF2-98C8-EF98C4C770E6}.All|x64 Setup.ActiveCfg = Release|x64 + {886B5E9D-F2C2-4AF2-98C8-EF98C4C770E6}.All|x86 Setup.ActiveCfg = Release|x64 + {886B5E9D-F2C2-4AF2-98C8-EF98C4C770E6}.Debug|Win32.ActiveCfg = Debug|Win32 + {886B5E9D-F2C2-4AF2-98C8-EF98C4C770E6}.Debug|x64.ActiveCfg = Debug|x64 + {886B5E9D-F2C2-4AF2-98C8-EF98C4C770E6}.Debug|x64 Setup.ActiveCfg = Debug|x64 + {886B5E9D-F2C2-4AF2-98C8-EF98C4C770E6}.Debug|x86 Setup.ActiveCfg = Debug|x64 + {886B5E9D-F2C2-4AF2-98C8-EF98C4C770E6}.Release|Win32.ActiveCfg = Release|Win32 + {886B5E9D-F2C2-4AF2-98C8-EF98C4C770E6}.Release|x64.ActiveCfg = Release|x64 + {886B5E9D-F2C2-4AF2-98C8-EF98C4C770E6}.Release|x64 Setup.ActiveCfg = Release|x64 + {886B5E9D-F2C2-4AF2-98C8-EF98C4C770E6}.Release|x86 Setup.ActiveCfg = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -3648,6 +3663,7 @@ Global {4748FF56-CA85-4809-97D6-A94C0FAC1D77} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} {60C542EE-6882-4EA2-8C21-5AB6DB1BA73F} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} {2469B306-B027-4FF2-8815-C9C1EA2CAE79} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} + {886B5E9D-F2C2-4AF2-98C8-EF98C4C770E6} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78} {07113B25-D3AF-4E04-BA77-4CD1171F022C} = {C5F182F9-754A-4EC5-B50F-76ED02BE13F4} {A27CCA23-1541-4337-81A4-F0A6413078A0} = {C5F182F9-754A-4EC5-B50F-76ED02BE13F4} {E7BC026C-7CC5-45A3-BC7C-3B88EEF01F24} = {C5F182F9-754A-4EC5-B50F-76ED02BE13F4} diff --git a/Makefile.am b/Makefile.am index 12dc3fa05a..99d3c2dd92 100644 --- a/Makefile.am +++ b/Makefile.am @@ -415,29 +415,16 @@ $(OUR_MODULES): $(switch_builddir)/modules.conf libfreeswitch.la $(switch_builddir)/quiet_libtool: $(switch_builddir)/libtool @cat libtool | sed -e 's|$$show "$$command"|if test -z "$$suppress_output" ; then $$show "Compiling $$srcfile ..." ; fi|' > $(switch_builddir)/quiet_libtool -src/include/switch_version.h: src/include/switch_version.h.in .version $(libfreeswitch_la_SOURCES) $(library_include_HEADERS) - @have_version=1 ; \ - force=0 ; \ - grep -- "@SWITCH_VERSION_REVISION@" src/include/switch_version.h.in > /dev/null || have_version=0 ; \ - test ! -f src/include/switch_version.h || grep -- "@SWITCH_VERSION_REVISION@" src/include/switch_version.h > /dev/null && force=1 ; \ - if test $$have_version = 1 ; then \ - cat src/include/switch_version.h.in > src/include/switch_version.h ; \ - touch .version ; \ - else \ - if [ -d .git ] ; then \ - version=`git log --pretty=format:"%h %ci" -1 HEAD | head -1 | sed -e 's|:|-|g' || echo hacked` ; \ - if [ "x$$version" = "xhacked" ] ; then \ - version="hacked-`date -u +%Y%m%dT%H%M%SZ`" ; \ - else \ - version="git-$$version" ; \ - fi ;\ - fi ; \ - oldversion=`cat .version 2>/dev/null || echo "0"` ; \ - if test "$$oldversion" != "$$version" || test $$force = 1 ; then \ - cat src/include/switch_version.h.in | sed "s/@SWITCH_VERSION_REVISION@/$$version/g" > src/include/switch_version.h ; \ - echo $$version > .version ; \ - fi ; \ - fi ; +build/print_git_revision: build/print_git_revision.c + $(CC) -o $@ $< + +src/include/switch_version.h: src/include/switch_version.h.in Makefile build/print_git_revision $(libfreeswitch_la_SOURCES) $(library_include_HEADERS) + @cat $< > $@; \ + if [ -d .git ] && [ -n "$$(which git)" ]; then \ + xver="$$(./build/print_git_revision)"; \ + sed -e "/#define *SWITCH_VERSION_REVISION/{s/\"\([^\"]*\)\"/\"\1$$xver\"/;}" \ + $< > $@; \ + fi; ## ## Dependency targets @@ -544,7 +531,6 @@ is-scm: update: is-scm @if test -d .git ; then \ - test ! -f .version || rm -f .version ; \ echo "Pulling updates..." ; \ git pull ; \ else \ diff --git a/build/modules.conf.in b/build/modules.conf.in index 534c1f0ec2..fdb631927a 100644 --- a/build/modules.conf.in +++ b/build/modules.conf.in @@ -58,12 +58,12 @@ codecs/mod_bv codecs/mod_g723_1 codecs/mod_g729 codecs/mod_h26x -codecs/mod_ilbc +#codecs/mod_ilbc #codecs/mod_isac #codecs/mod_opus #codecs/mod_sangoma_codec #codecs/mod_silk -codecs/mod_siren +#codecs/mod_siren codecs/mod_speex dialplans/mod_dialplan_asterisk #dialplans/mod_dialplan_directory diff --git a/build/print_git_revision.c b/build/print_git_revision.c new file mode 100644 index 0000000000..6b11646c8e --- /dev/null +++ b/build/print_git_revision.c @@ -0,0 +1,63 @@ +/* -*- mode:c; indent-tabs-mode:nil; c-basic-offset:2 -*- + * Author: Travis Cross + */ + +#include +#include +#include +#include +#include +#include + +static int sys(char *buf, int buflen, char *cmd) { + int i, p[2]; + if (pipe(p)) return 255; + if (!(i=fork())) { + close(p[0]); + dup2(p[1],1); + close(p[1]); + execlp("sh","sh","-c",cmd,NULL); + } else { + int s, x=0; + close(p[1]); + waitpid(i,&s,0); + if (!(WIFEXITED(s))) return 255; + if (WEXITSTATUS(s)) return WEXITSTATUS(s); + if (buf) { + while (buflen>1 && (x=read(p[0],buf,buflen-1))>0) buf+=x,buflen-=x; + close(p[0]); + if (x<0) return 255; + *buf=0; + } else close(p[0]); + } + return 0; +} + +static int sys1(char *buf, int buflen, char *cmd) { + int r; char *c; + if ((r=sys(buf,buflen,cmd))) return r; + if ((c=strstr(buf,"\n"))) *c=0; + return 0; +} + +int main(int argc, char **argv) { + char xver[256], xdate[256], xfdate[256], xcommit[256]; + time_t xdate_t; struct tm *xdate_tm; + if ((sys1(xdate,sizeof(xdate),"git log -n1 --format='%ct' HEAD"))) return 1; + xdate_t=(time_t)atoi(xdate); + if (!(xdate_tm=gmtime(&xdate_t))) return 1; + strftime(xfdate,sizeof(xfdate),"%Y%m%dT%H%M%SZ",xdate_tm); + if ((sys1(xcommit,sizeof(xcommit),"git rev-list -n1 --abbrev=10 --abbrev-commit HEAD"))) + return 1; + snprintf(xver,sizeof(xver),"+git~%s~%s",xfdate,xcommit); + if ((sys(NULL,0,"git diff-index --quiet HEAD"))) { + char buf[256], now[256]; time_t now_t=time(NULL); struct tm *now_tm; + if (!(now_tm=gmtime(&now_t))) return 1; + strftime(now,sizeof(now),"%Y%m%dT%H%M%SZ",now_tm); + snprintf(buf,sizeof(buf),"%s+unclean~%s",xver,now); + strncpy(xver,buf,sizeof(xver)); + } + printf("%s\n",xver); + return 0; +} + diff --git a/conf/insideout/sip_profiles/external.xml b/conf/insideout/sip_profiles/external.xml index f021a4c3c6..22fd155434 100644 --- a/conf/insideout/sip_profiles/external.xml +++ b/conf/insideout/sip_profiles/external.xml @@ -48,7 +48,7 @@ - + diff --git a/conf/insideout/sip_profiles/internal-ipv6.xml b/conf/insideout/sip_profiles/internal-ipv6.xml index b9907a78ad..525554f4b8 100644 --- a/conf/insideout/sip_profiles/internal-ipv6.xml +++ b/conf/insideout/sip_profiles/internal-ipv6.xml @@ -69,7 +69,7 @@ - + diff --git a/conf/insideout/sip_profiles/internal.xml b/conf/insideout/sip_profiles/internal.xml index e406cd5e72..666f7de5ab 100644 --- a/conf/insideout/sip_profiles/internal.xml +++ b/conf/insideout/sip_profiles/internal.xml @@ -104,7 +104,7 @@ - + diff --git a/conf/sbc/sbc_profiles/external.xml b/conf/sbc/sbc_profiles/external.xml index 0f15159f58..7bf024658b 100644 --- a/conf/sbc/sbc_profiles/external.xml +++ b/conf/sbc/sbc_profiles/external.xml @@ -49,7 +49,7 @@ - + diff --git a/conf/sbc/sbc_profiles/internal-ipv6.xml b/conf/sbc/sbc_profiles/internal-ipv6.xml index b9907a78ad..525554f4b8 100644 --- a/conf/sbc/sbc_profiles/internal-ipv6.xml +++ b/conf/sbc/sbc_profiles/internal-ipv6.xml @@ -69,7 +69,7 @@ - + diff --git a/conf/sbc/sbc_profiles/internal.xml b/conf/sbc/sbc_profiles/internal.xml index 3081052c88..d4b2efd37b 100644 --- a/conf/sbc/sbc_profiles/internal.xml +++ b/conf/sbc/sbc_profiles/internal.xml @@ -110,7 +110,7 @@ - + diff --git a/conf/vanilla/sip_profiles/external.xml b/conf/vanilla/sip_profiles/external.xml index 4f18e84be7..5070c87913 100644 --- a/conf/vanilla/sip_profiles/external.xml +++ b/conf/vanilla/sip_profiles/external.xml @@ -57,7 +57,7 @@ - + diff --git a/conf/vanilla/sip_profiles/internal-ipv6.xml b/conf/vanilla/sip_profiles/internal-ipv6.xml index 18274faa4f..62b9708e8b 100644 --- a/conf/vanilla/sip_profiles/internal-ipv6.xml +++ b/conf/vanilla/sip_profiles/internal-ipv6.xml @@ -70,7 +70,7 @@ - + diff --git a/conf/vanilla/sip_profiles/internal.xml b/conf/vanilla/sip_profiles/internal.xml index 0f4cabe32d..7d37da863e 100644 --- a/conf/vanilla/sip_profiles/internal.xml +++ b/conf/vanilla/sip_profiles/internal.xml @@ -222,7 +222,7 @@ - + diff --git a/configure.in b/configure.in index 5dbe6d9e12..514a9151e4 100644 --- a/configure.in +++ b/configure.in @@ -10,7 +10,6 @@ AC_SUBST(SWITCH_VERSION_MICRO, [0]) AC_SUBST(SWITCH_VERSION_REVISION, [-rc2]) AC_CONFIG_FILES([src/include/switch_version.h.in:src/include/switch_version.h.template]) -AC_CONFIG_FILES([.version:.version.in]) AC_CONFIG_AUX_DIR(build/config) AM_INIT_AUTOMAKE(libfreeswitch,0.1) @@ -925,7 +924,7 @@ then # # python distutils found, get settings from python directly # - PYTHON_CFLAGS="`$PYTHON -c 'from distutils import sysconfig; flags = [[\"-I\" + sysconfig.get_python_inc(0), \"-I\" + sysconfig.get_python_inc(1), \" \".join(sysconfig.get_config_var(\"CFLAGS\").split())]]; print(\" \".join(flags));'`" + PYTHON_CFLAGS="`$PYTHON -c 'from distutils import sysconfig; flags = [[\"-I\" + sysconfig.get_python_inc(0), \"-I\" + sysconfig.get_python_inc(1), \" \".join(sysconfig.get_config_var(\"CFLAGS\").split())]]; print(\" \".join(flags));' | sed -e 's/-arch i386//g;s/-arch x86_64//g'`" PYTHON_LDFLAGS="`$PYTHON -c 'from distutils import sysconfig; libs = sysconfig.get_config_var(\"LIBS\").split() + sysconfig.get_config_var(\"SYSLIBS\").split(); libs.append(\"-lpython\"+sysconfig.get_config_var(\"VERSION\")); print(\" \".join(libs));'`" PYTHON_LIB="`$PYTHON -c 'from distutils import sysconfig; print(\"python\" + sysconfig.get_config_var(\"VERSION\"));'`" PYTHON_LIBDIR="`$PYTHON -c 'from distutils import sysconfig; print(sysconfig.get_config_var(\"LIBDIR\"));'`" @@ -993,7 +992,6 @@ AC_CONFIG_FILES([Makefile src/Makefile src/mod/Makefile src/mod/applications/mod_expr/Makefile - src/mod/applications/mod_fax/Makefile src/mod/applications/mod_spandsp/Makefile src/mod/applications/mod_osp/Makefile src/mod/applications/mod_stress/Makefile diff --git a/debian/bootstrap.sh b/debian/bootstrap.sh index deed9f5c07..a724948577 100755 --- a/debian/bootstrap.sh +++ b/debian/bootstrap.sh @@ -31,6 +31,7 @@ avoid_mods=( endpoints/mod_reference endpoints/mod_unicall formats/mod_shout + languages/mod_managed languages/mod_spidermonkey sdk/autotools xml_int/mod_xml_ldap diff --git a/debian/util.sh b/debian/util.sh index de1496a950..3f4fea312d 100755 --- a/debian/util.sh +++ b/debian/util.sh @@ -234,9 +234,11 @@ EOF build_debs () { { set -e - local OPTIND OPTARG debug_hook=false hookdir="" - while getopts 'd' o "$@"; do + local OPTIND OPTARG debug_hook=false hookdir="" cow_build_opts="" + while getopts 'Bbd' o "$@"; do case "$o" in + B) cow_build_opts="--debbuildopts '-B'";; + b) cow_build_opts="--debbuildopts '-b'";; d) debug_hook=true;; esac done @@ -274,9 +276,10 @@ build_debs () { fi cow --build $dsc \ --hookdir "$hookdir" \ - --buildresult ../ + --buildresult ../ \ + $cow_build_opts } 1>&2 - echo ${dsc}_${arch}.changes + echo ${dsc%.dsc}_${arch}.changes } build_all () { @@ -304,38 +307,96 @@ build_all () { mkdir -p ../log > ../log/changes echo; echo; echo; echo + trap 'echo "Killing children...">&2; for x in $(jobs -p); do kill $x; done' EXIT if [ "${orig:0:2}" = ".." ]; then for distro in $distros; do echo "Creating $distro dsc..." >&2 local dsc="$(create_dsc $dsc_opts $distro $orig 2>../log/$distro | tail -n1)" echo "Done creating $distro dsc." >&2 if [ "${dsc:0:2}" = ".." ]; then + local lopts="-b" for arch in $archs; do { echo "Building $distro-$arch debs..." >&2 - local changes="$(build_debs $deb_opts $distro $dsc $arch 2>../log/$distro-$arch | tail -n1)" + local changes="$(build_debs $lopts $deb_opts $distro $dsc $arch 2>../log/$distro-$arch | tail -n1)" echo "Done building $distro-$arch debs." >&2 if [ "${changes:0:2}" = ".." ]; then echo "$changes" >> ../log/changes fi } & $par || wait + lopts="-B" done fi done ! $par || wait fi + trap - EXIT cat ../log/changes } -while getopts 'd' o "$@"; do +usage () { + cat >&2 < + + -B Binary architecture-dependent build + -b Binary-only build + -d Enable cowbuilder debug hook + + create-dbg-pkgs + + create-dsc + + -m [ quicktest ] + Choose custom list of modules to build + -s [ paranoid | reckless ] + Set FS bootstrap/build -j flags + + create-orig + + -b Bundle downloaded libraries in source package + -n Nightly build + -v Set version + -z Set compression level + +EOF + exit 1 +} + +while getopts 'dh' o "$@"; do case "$o" in d) set -vx;; + h) usage;; esac done shift $(($OPTIND-1)) -cmd="$1" +cmd="$1"; [ -n "$cmd" ] || usage shift case "$cmd" in archive-orig) archive_orig "$@" ;; @@ -344,5 +405,6 @@ case "$cmd" in create-dbg-pkgs) create_dbg_pkgs ;; create-dsc) create_dsc "$@" ;; create-orig) create_orig "$@" ;; + *) usage ;; esac diff --git a/libs/.gitignore b/libs/.gitignore index e39b1f4bf1..48bfc1f814 100644 --- a/libs/.gitignore +++ b/libs/.gitignore @@ -225,6 +225,7 @@ missing /ldns/doc/ldns_manpages /ldns/include/ /ldns/ldns/config.h +/ldns/ldns/ldns /ldns/ldns/net.h /ldns/ldns/util.h /ldns/lib diff --git a/libs/libzrtp/include/zrtp_types.h b/libs/libzrtp/include/zrtp_types.h index a38d118591..c5c7654d68 100644 --- a/libs/libzrtp/include/zrtp_types.h +++ b/libs/libzrtp/include/zrtp_types.h @@ -527,7 +527,12 @@ typedef struct zrtp_stream_mescache_t zrtp_retry_task_t errorack_task; zrtp_retry_task_t sasrelay_task; - zrtp_string16_t signaling_hash; + /*! + * Hash pre-image of the remote party Hello retrieved from Signaling. When + * user calls zrtp_signaling_hash_set() libzrtp stores hash value in this + * variable and checks all incoming Hello-s to prevent DOS attacks. + */ + zrtp_string64_t signaling_hash; } zrtp_stream_mescache_t; @@ -722,14 +727,7 @@ struct zrtp_stream_t * crypto sources and performs traffic encryption/decryption. */ zrtp_protocol_t *protocol; - - /*! - * Hash pre-image of the remote party Hello retrieved from Signaling. When - * user calls zrtp_signaling_hash_set() libzrtp stores hash value in this - * variable and checks all incoming Hellos to prevent DOS attacks. - */ - zrtp_string128_t signaling_hash; - + /*!< Holder for RTP/ZRTP media stream options. */ zrtp_media_context_t media_ctx; diff --git a/libs/libzrtp/include/zrtp_version.h b/libs/libzrtp/include/zrtp_version.h index 5afc3b76af..e666e42cb9 100644 --- a/libs/libzrtp/include/zrtp_version.h +++ b/libs/libzrtp/include/zrtp_version.h @@ -12,8 +12,8 @@ #define LIBZRTP_VERSION_MAJOR 1 -#define LIBZRTP_VERSION_MINOR 13 -#define LIBZRTP_VERSION_BUILD 604 -#define LIBZRTP_VERSION_STR "v1.13 604" +#define LIBZRTP_VERSION_MINOR 15 +#define LIBZRTP_VERSION_BUILD 607 +#define LIBZRTP_VERSION_STR "v1.15 607" #endif /*__ZRTP_VERSION_H__*/ diff --git a/libs/libzrtp/projects/gnu/configure.in b/libs/libzrtp/projects/gnu/configure.in index d25d41771a..7d97319a76 100644 --- a/libs/libzrtp/projects/gnu/configure.in +++ b/libs/libzrtp/projects/gnu/configure.in @@ -32,7 +32,7 @@ case $target_os in esac -AM_INIT_AUTOMAKE([libzrtp], [1.14]) +AM_INIT_AUTOMAKE([libzrtp], [1.15]) AX_PREFIX_CONFIG_H(../../include/zrtp_config_unix.h,ZRTP,config/config.h) CFLAGS="$CFLAGS -Wno-unused-parameter -fno-strict-aliasing -fPIC -DZRTP_AUTOMAKE=1" diff --git a/libs/libzrtp/src/zrtp.c b/libs/libzrtp/src/zrtp.c index d0002a7d3d..c69b5e9692 100644 --- a/libs/libzrtp/src/zrtp.c +++ b/libs/libzrtp/src/zrtp.c @@ -418,8 +418,6 @@ zrtp_status_t zrtp_stream_attach(zrtp_session_t *session, zrtp_stream_t** stream return zrtp_status_alloc_fail; } - ZSTR_SET_EMPTY(new_stream->signaling_hash); - /* * Initialize the private data stream with default initial values */ @@ -437,6 +435,8 @@ zrtp_status_t zrtp_stream_attach(zrtp_session_t *session, zrtp_stream_t** stream ZSTR_SET_EMPTY(new_stream->cc.zrtp_key); ZSTR_SET_EMPTY(new_stream->cc.peer_zrtp_key); + ZSTR_SET_EMPTY(new_stream->messages.signaling_hash); + new_stream->dh_cc.initialized_with = ZRTP_COMP_UNKN; bnBegin(&new_stream->dh_cc.peer_pv); ZSTR_SET_EMPTY(new_stream->dh_cc.dhss); @@ -638,8 +638,8 @@ zrtp_status_t zrtp_signaling_hash_set( zrtp_stream_t* ctx, ctx->messages.signaling_hash.length = ZRTP_MESSAGE_HASH_SIZE; { - char buff[66]; - ZRTP_LOG(3, (_ZTU_,"SIGNALLING HAS was ADDED for the comparing. ID=%u\n", ctx->id)); + char buff[64]; + ZRTP_LOG(3, (_ZTU_,"SIGNALLING HAS was ADDED for the comparision. ID=%u\n", ctx->id)); ZRTP_LOG(3, (_ZTU_,"Hash=%s.\n", hex2str(hash_buff, hash_buff_length, buff, sizeof(buff)))); } diff --git a/libs/libzrtp/src/zrtp_pbx.c b/libs/libzrtp/src/zrtp_pbx.c index 3567d4a47b..cc25c46b3e 100644 --- a/libs/libzrtp/src/zrtp_pbx.c +++ b/libs/libzrtp/src/zrtp_pbx.c @@ -128,13 +128,15 @@ zrtp_status_t _zrtp_machine_process_sasrelay(zrtp_stream_t *stream, zrtp_rtp_inf zrtp_status_t s = zrtp_status_fail; zrtp_string128_t hmac = ZSTR_INIT_EMPTY(hmac); char zerosashash[32]; + unsigned sas_scheme_did_change = 0; + unsigned sas_hash_did_change = 0; /* (padding + sig_len + flags) + SAS scheme and SAS hash */ const uint8_t encrypted_body_size = (2 + 1 + 1) + 4 + 32; zrtp_memset(zerosashash, 0, sizeof(zerosashash)); - /* Check if the remote endpoint is assiggneed to relay the SAS values */ + /* Check if the remote endpoint is assigned to relay the SAS values */ if (!stream->peer_mitm_flag) { ZRTP_LOG(2,(_ZTU_, ZRTP_RELAYED_SAS_FROM_NONMITM_STR)); return zrtp_status_fail; @@ -157,7 +159,7 @@ zrtp_status_t _zrtp_machine_process_sasrelay(zrtp_stream_t *stream, zrtp_rtp_inf return zrtp_status_fail; } - ZRTP_LOG(3,(_ZTU_, "\tHMAC value for the SASRELAY is correct - decryptiong...\n")); + ZRTP_LOG(3,(_ZTU_, "\tHMAC value for the SASRELAY is correct - decrypting...\n")); /* Then we need to decrypt Confirm body */ do @@ -217,9 +219,14 @@ zrtp_status_t _zrtp_machine_process_sasrelay(zrtp_stream_t *stream, zrtp_rtp_inf _zrtp_machine_enter_initiatingerror(stream, zrtp_error_invalid_packet, 1); return zrtp_status_fail; } - session->sasscheme = zrtp_comp_find(ZRTP_CC_SAS, rendering_id, session->zrtp ); - ZRTP_LOG(3,(_ZTU_,"\tSasrelay: New Rendering scheme %.4s.\n", session->sasscheme->base.type)); + /* Check is SAS rendering did change */ + if (rendering_id != session->sasscheme->base.id) { + session->sasscheme = zrtp_comp_find(ZRTP_CC_SAS, rendering_id, session->zrtp ); + + sas_scheme_did_change = 1; + ZRTP_LOG(3,(_ZTU_,"\tSasrelay: Rendering scheme was updated to %.4s.\n", session->sasscheme->base.type)); + } if (session->secrets.matches & ZRTP_BIT_PBX) { if ( ( ((uint32_t) *sasrelay->sas_scheme) != (uint32_t)0x0L ) && @@ -231,7 +238,8 @@ zrtp_status_t _zrtp_machine_process_sasrelay(zrtp_stream_t *stream, zrtp_rtp_inf zrtp_memcpy(session->sasbin.buffer, sasrelay->sashash, session->sasbin.length); stream->mitm_mode = ZRTP_MITM_MODE_RECONFIRM_CLIENT; - ZRTP_LOG(3,(_ZTU_,"\tSasRelay: SAS value was updated bin=%s.\n", + sas_hash_did_change = 1; + ZRTP_LOG(3,(_ZTU_,"\tSasRelay: SAS value was updated to bin=%s.\n", hex2str(buff, sizeof(buff), session->sasbin.buffer, session->sasbin.length))); } } else if (0 != zrtp_memcmp(sasrelay->sashash, zerosashash, sizeof(sasrelay->sashash))) { @@ -242,16 +250,24 @@ zrtp_status_t _zrtp_machine_process_sasrelay(zrtp_stream_t *stream, zrtp_rtp_inf ZRTP_LOG(1,(_ZTU_, "\rERROR! For SasRelay Other secret doesn't match. ID=%u\n", stream->id)); } - s = session->sasscheme->compute(session->sasscheme, stream, session->hash, 1); - if (zrtp_status_ok != s) { - _zrtp_machine_enter_initiatingerror(stream, zrtp_error_software, 1); - return s; - } - ZRTP_LOG(3,(_ZTU_,"\tSasRelay: Updated SAS is <%s> <%s>.\n", session->sas1.buffer, session->sas2.buffer)); + /* Generate new SAS if hash or rendering scheme did change. + * Note: latest libzrtp may send "empty" SasRelay with the same SAS rendering + * scheme and empty Hello hash for consistency reasons, we should ignore + * such packets. + */ + if (sas_scheme_did_change || sas_hash_did_change) { + s = session->sasscheme->compute(session->sasscheme, stream, session->hash, 1); + if (zrtp_status_ok != s) { + _zrtp_machine_enter_initiatingerror(stream, zrtp_error_software, 1); + return s; + } - if (session->zrtp->cb.event_cb.on_zrtp_protocol_event) { - session->zrtp->cb.event_cb.on_zrtp_protocol_event(stream, ZRTP_EVENT_LOCAL_SAS_UPDATED); + ZRTP_LOG(3,(_ZTU_,"\tSasRelay: Updated SAS is <%s> <%s>.\n", session->sas1.buffer, session->sas2.buffer)); + + if (session->zrtp->cb.event_cb.on_zrtp_protocol_event) { + session->zrtp->cb.event_cb.on_zrtp_protocol_event(stream, ZRTP_EVENT_LOCAL_SAS_UPDATED); + } } return zrtp_status_ok; @@ -492,7 +508,7 @@ zrtp_status_t zrtp_update_remote_options( zrtp_stream_t* stream, return zrtp_status_bad_param; } - /* Don't allow to transfer the SAS if the library wasn't initalized as MiTM endpoint */ + /* Don't allow to transfer the SAS if the library wasn't initialized as MiTM endpoint */ if (!stream->zrtp->is_mitm) { ZRTP_LOG(3,(_ZTU_,"\tERROR! The endpoint can't transfer SAS values to other endpoints" " without introducing itself by M-flag in Hello. see zrtp_init().\n")); diff --git a/libs/libzrtp/src/zrtp_utils.c b/libs/libzrtp/src/zrtp_utils.c index 7b61aac146..45b5290d85 100644 --- a/libs/libzrtp/src/zrtp_utils.c +++ b/libs/libzrtp/src/zrtp_utils.c @@ -488,7 +488,7 @@ zrtp_status_t _zrtp_packet_preparse( zrtp_stream_t* stream, (const char*) info->message, zrtp_ntoh16(((zrtp_packet_Hello_t*) info->message)->hdr.length)*4, ZSTR_GV(hash_str) ); - if (!zrtp_memcmp(stream->messages.signaling_hash.buffer, hash_str.buffer, ZRTP_MESSAGE_HASH_SIZE)) { + if (zrtp_memcmp(stream->messages.signaling_hash.buffer, hash_str.buffer, ZRTP_MESSAGE_HASH_SIZE)) { if (stream->zrtp->cb.event_cb.on_zrtp_security_event) { stream->zrtp->cb.event_cb.on_zrtp_security_event(stream, ZRTP_EVENT_WRONG_SIGNALING_HASH); } diff --git a/libs/sofia-sip/.update b/libs/sofia-sip/.update index ade22984f2..cfded9d9e2 100644 --- a/libs/sofia-sip/.update +++ b/libs/sofia-sip/.update @@ -1 +1 @@ -Thu May 3 16:30:20 CDT 2012 +Sat Jun 9 03:24:47 UTC 2012 diff --git a/libs/sofia-sip/libsofia-sip-ua/tport/sofia-sip/tport_tag.h b/libs/sofia-sip/libsofia-sip-ua/tport/sofia-sip/tport_tag.h index 6745cff1af..3abbbcbac4 100644 --- a/libs/sofia-sip/libsofia-sip-ua/tport/sofia-sip/tport_tag.h +++ b/libs/sofia-sip/libsofia-sip-ua/tport/sofia-sip/tport_tag.h @@ -198,6 +198,12 @@ enum tport_tls_verify_policy { TPTLS_VERIFY_SUBJECTS_ALL = 0xF, }; +TPORT_DLL extern tag_typedef_t tptag_tls_timeout; +#define TPTAG_TLS_TIMEOUT(x) tptag_tls_timeout, tag_uint_v((x)) + +TPORT_DLL extern tag_typedef_t tptag_tls_timeout_ref; +#define TPTAG_TLS_TIMEOUT_REF(x) tptag_tls_timeout_ref, tag_uint_vr(&(x)) + TPORT_DLL extern tag_typedef_t tptag_tls_passphrase; #define TPTAG_TLS_PASSPHRASE(x) tptag_tls_passphrase, tag_str_v(x) diff --git a/libs/sofia-sip/libsofia-sip-ua/tport/tport_tag.c b/libs/sofia-sip/libsofia-sip-ua/tport/tport_tag.c index c10958a41f..495eaaf997 100644 --- a/libs/sofia-sip/libsofia-sip-ua/tport/tport_tag.c +++ b/libs/sofia-sip/libsofia-sip-ua/tport/tport_tag.c @@ -280,6 +280,19 @@ tag_typedef_t tptag_compartment = PTRTAG_TYPEDEF(compartment); */ tag_typedef_t tptag_tls_version = UINTTAG_TYPEDEF(tls_version); +/**@def TPTAG_TLS_TIMEOUT(x) + * + * Sets the maximum TLS session lifetime in seconds. + * + * The default value is 300 seconds. + * + * Use with tport_tbind(), nua_create(), nta_agent_create(), + * nta_agent_add_tport(), nth_engine_create(), or initial nth_site_create(). + * + * @NEW_UNRELEASED. + */ +tag_typedef_t tptag_tls_timeout = UINTTAG_TYPEDEF(tls_timeout); + /**@def TPTAG_TLS_VERIFY_PEER(x) * @par Depreciated: * Alias for TPTAG_TLS_VERIFY_POLICY(TPTLS_VERIFY_IN|TPTLS_VERIFY_OUT) diff --git a/libs/sofia-sip/libsofia-sip-ua/tport/tport_tls.c b/libs/sofia-sip/libsofia-sip-ua/tport/tport_tls.c index 2fffbde110..2facb30d0d 100644 --- a/libs/sofia-sip/libsofia-sip-ua/tport/tport_tls.c +++ b/libs/sofia-sip/libsofia-sip-ua/tport/tport_tls.c @@ -311,6 +311,8 @@ int tls_init_context(tls_t *tls, tls_issues_t const *ti) return -1; } + SSL_CTX_set_timeout(tls->ctx, ti->timeout); + /* Set callback if we have a passphrase */ if (ti->passphrase != NULL) { SSL_CTX_set_default_passwd_cb(tls->ctx, passwd_cb); diff --git a/libs/sofia-sip/libsofia-sip-ua/tport/tport_tls.h b/libs/sofia-sip/libsofia-sip-ua/tport/tport_tls.h index dbf6517196..702dcc9040 100644 --- a/libs/sofia-sip/libsofia-sip-ua/tport/tport_tls.h +++ b/libs/sofia-sip/libsofia-sip-ua/tport/tport_tls.h @@ -65,6 +65,7 @@ typedef struct tls_issues_s { */ int version; /* For tls1, version is 1. When ssl3/ssl2 is * used, it is 0. */ + unsigned timeout; /* Maximum session lifetime in seconds */ } tls_issues_t; typedef struct tport_tls_s { diff --git a/libs/sofia-sip/libsofia-sip-ua/tport/tport_type_tls.c b/libs/sofia-sip/libsofia-sip-ua/tport/tport_type_tls.c index 24f5d1b0fb..cd2ac9a9b6 100644 --- a/libs/sofia-sip/libsofia-sip-ua/tport/tport_type_tls.c +++ b/libs/sofia-sip/libsofia-sip-ua/tport/tport_type_tls.c @@ -181,6 +181,7 @@ static int tport_tls_init_master(tport_primary_t *pri, char *tbf = NULL; char const *path = NULL; unsigned tls_version = 1; + unsigned tls_timeout = 300; unsigned tls_verify = 0; char const *passphrase = NULL; unsigned tls_policy = TPTLS_VERIFY_NONE; @@ -198,6 +199,7 @@ static int tport_tls_init_master(tport_primary_t *pri, tl_gets(tags, TPTAG_CERTIFICATE_REF(path), TPTAG_TLS_VERSION_REF(tls_version), + TPTAG_TLS_TIMEOUT_REF(tls_timeout), TPTAG_TLS_VERIFY_PEER_REF(tls_verify), TPTAG_TLS_PASSPHRASE_REF(passphrase), TPTAG_TLS_VERIFY_POLICY_REF(tls_policy), @@ -224,6 +226,7 @@ static int tport_tls_init_master(tport_primary_t *pri, ti.cert = ti.key; ti.CAfile = su_sprintf(autohome, "%s/%s", path, "cafile.pem"); ti.version = tls_version; + ti.timeout = tls_timeout; ti.CApath = su_strdup(autohome, path); SU_DEBUG_9(("%s(%p): tls key = %s\n", __func__, (void *)pri, ti.key)); diff --git a/libs/win32/util.vbs b/libs/win32/util.vbs index 29a7be5715..cbaf96a7b0 100644 --- a/libs/win32/util.vbs +++ b/libs/win32/util.vbs @@ -271,36 +271,38 @@ Sub CreateVersion(tmpFolder, VersionDir, includebase, includedest) strVerRev = FindVersionStringInConfigure(VersionDir & "configure.in", "SWITCH_VERSION_REVISION") 'Set version to the one reported by configure.in - if strVerRev <> "" Then + If strVerRev <> "" Then VERSION = strVerRev End If Dim sLastFile Const ForReading = 1 - 'Try To read revision from git, if it's found, use this instead of strVerRev found above - If FSO.FolderExists(VersionDir & ".git") Then - VersionCmd="git log --format=" & quote & "%%h %%ci" & quote & " -1 HEAD" - Set MyFile = FSO.CreateTextFile(tmpFolder & "tmpVersion.Bat", True) - MyFile.WriteLine("@" & "cd " & quote & VersionDir & quote) - MyFile.WriteLine("@" & VersionCmd) - MyFile.Close - Set oExec = WshShell.Exec("cmd /C " & quote & tmpFolder & "tmpVersion.Bat" & quote) - Do - strFromProc = Trim(OExec.StdOut.ReadLine()) - VERSION="git-" & strFromProc - Loop While Not OExec.StdOut.atEndOfStream - sLastVersion = "" - Set sLastFile = FSO.OpenTextFile(tmpFolder & "lastversion", ForReading, true, OpenAsASCII) - If Not sLastFile.atEndOfStream Then - sLastVersion = sLastFile.ReadLine() + 'Try To read revision from git, if it was not found in "configure.in" already + If strVerRev = "" Then + If FSO.FolderExists(VersionDir & ".git") Then + VersionCmd="git log --format=" & quote & "%%h %%ci" & quote & " -1 HEAD" + Set MyFile = FSO.CreateTextFile(tmpFolder & "tmpVersion.Bat", True) + MyFile.WriteLine("@" & "cd " & quote & VersionDir & quote) + MyFile.WriteLine("@" & VersionCmd) + MyFile.Close + Set oExec = WshShell.Exec("cmd /C " & quote & tmpFolder & "tmpVersion.Bat" & quote) + Do + strFromProc = Trim(OExec.StdOut.ReadLine()) + VERSION="git-" & strFromProc + Loop While Not OExec.StdOut.atEndOfStream + sLastVersion = "" + Set sLastFile = FSO.OpenTextFile(tmpFolder & "lastversion", ForReading, true, OpenAsASCII) + If Not sLastFile.atEndOfStream Then + sLastVersion = sLastFile.ReadLine() + End If + sLastFile.Close + VERSION = Replace(VERSION, ":", "-") End If - sLastFile.Close - VERSION = Replace(VERSION, ":", "-") End If If VERSION = "" Then - VERSION = "UNKNOWN" + VERSION = "-UNKNOWN" End If If VERSION <> sLastVersion Then diff --git a/scripts/ci/debsrcbuilder.sh b/scripts/ci/debsrcbuilder.sh index e64093d120..1b81566fe8 100755 --- a/scripts/ci/debsrcbuilder.sh +++ b/scripts/ci/debsrcbuilder.sh @@ -28,6 +28,7 @@ mkdir -p $ddir git clone . $bdir cd $bdir set_fs_ver "$gver" "$gmajor" "$gminor" "$gmicro" "$grev" +echo "$gver" > .version cd libs getlib () { f="${1##*/}" diff --git a/scripts/ci/src_tarball.sh b/scripts/ci/src_tarball.sh index 0cab5f5d58..1c79f2fca1 100755 --- a/scripts/ci/src_tarball.sh +++ b/scripts/ci/src_tarball.sh @@ -22,6 +22,7 @@ cp -r . $dst_dir cd $dst_dir set_fs_ver "$gver" "$gmajor" "$gminor" "$gmicro" "$grev" +echo "$gver" > .version gnuize cd .. ls diff --git a/scripts/perl/cnam.cgi b/scripts/perl/cnam.cgi new file mode 100755 index 0000000000..d7acaa9b49 --- /dev/null +++ b/scripts/perl/cnam.cgi @@ -0,0 +1,63 @@ +#!/usr/bin/perl +# +# OpenCNAM front end because they only take 10 digits and can't filter 11 on their side. +# + +use Data::Dumper; +use CGI qw/:standard/; +use LWP::UserAgent; +use SDBM_File; +use Fcntl; + +my %params = map { $_ => get_data( $_ ) } param; + +$ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 }); + +sub get_data { + my $name = shift; + my @values = param( $name ); + return @values > 1 + ? \@values + : $values[0]; +} + +print "Content-Type: text/plain\n\n"; + +tie (my %cache, 'SDBM_File', 'cnam.dbm', O_RDWR|O_CREAT, 0640) || die $!; + +my $number = $params{number}; + + +if($number =~ m/1?\d{10}/) { + + + if($number =~ m/^1(\d{10})$/) { + $number = $1; + } + + if($cache{"$number"}) { + print $cache{"$number"}; + untie %cache; + exit; + } + + my $url = "https://api.opencnam.com/v1/phone/$number?format=text"; + + + my $res = $ua->get( $url ); + + if ($res->is_success) { + my $content = $res->decoded_content; + if ($content =~ m/^Invalid/) { + # API shouldn't return this crap. + print "UNKNOWN"; + } else { + # Cache the entry. + $cache{"$number"} = $content; + # print the entry. + print $content; + } + } +} + +untie %cache; diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 9803c6708b..05d6e0aa48 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -2300,10 +2300,12 @@ SWITCH_DECLARE(uint32_t) switch_default_ptime(const char *name, uint32_t number) \param [in] network_ip \param [in] network_port \param [in] network_proto - one of tls, tcp, udp + \param [in] metadata - generic metadata supplied by module \param [out] err - Error if it exists */ SWITCH_DECLARE(switch_status_t) switch_core_add_registration(const char *user, const char *realm, const char *token, const char *url, uint32_t expires, - const char *network_ip, const char *network_port, const char *network_proto); + const char *network_ip, const char *network_port, const char *network_proto, + const char *metadata); /*! \brief Delete user registration \param [in] user diff --git a/src/include/switch_cpp.h b/src/include/switch_cpp.h index 44e85185a6..83adac6867 100644 --- a/src/include/switch_cpp.h +++ b/src/include/switch_cpp.h @@ -186,7 +186,7 @@ SWITCH_DECLARE(bool) email(char *to, char *from, char *headers = NULL, char *bod switch_event_node_t *enodes[SWITCH_EVENT_ALL + 1]; uint32_t node_index; - SWITCH_DECLARE_CONSTRUCTOR EventConsumer(const char *event_name = NULL, const char *subclass_name = ""); + SWITCH_DECLARE_CONSTRUCTOR EventConsumer(const char *event_name = NULL, const char *subclass_name = "", int len = 5000); SWITCH_DECLARE_CONSTRUCTOR ~ EventConsumer(); SWITCH_DECLARE(int) bind(const char *event_name, const char *subclass_name = ""); SWITCH_DECLARE(Event *) pop(int block = 0, int timeout = 0); diff --git a/src/include/switch_version.h.cmake b/src/include/switch_version.h.cmake index 6e36b0b1da..7cec6489b3 100644 --- a/src/include/switch_version.h.cmake +++ b/src/include/switch_version.h.cmake @@ -41,7 +41,7 @@ extern "C" { #define SWITCH_VERSION_MINOR "@freeswitch_MINOR_VERSION@" #define SWITCH_VERSION_MICRO "@freeswitch_PATCH_LEVEL@" #define SWITCH_VERSION_REVISION "@Project_WC_REVISION@" -#define SWITCH_VERSION_FULL SWITCH_VERSION_MAJOR "." SWITCH_VERSION_MINOR "." SWITCH_VERSION_MICRO " (" SWITCH_VERSION_REVISION ")" +#define SWITCH_VERSION_FULL SWITCH_VERSION_MAJOR "." SWITCH_VERSION_MINOR "." SWITCH_VERSION_MICRO SWITCH_VERSION_REVISION #ifdef __cplusplus } diff --git a/src/include/switch_version.h.template b/src/include/switch_version.h.template index 2f75d75266..e0c13811d8 100644 --- a/src/include/switch_version.h.template +++ b/src/include/switch_version.h.template @@ -41,7 +41,7 @@ extern "C" { #define SWITCH_VERSION_MINOR "@SWITCH_VERSION_MINOR@" #define SWITCH_VERSION_MICRO "@SWITCH_VERSION_MICRO@" #define SWITCH_VERSION_REVISION "@SWITCH_VERSION_REVISION@" -#define SWITCH_VERSION_FULL SWITCH_VERSION_MAJOR "." SWITCH_VERSION_MINOR "." SWITCH_VERSION_MICRO " (" SWITCH_VERSION_REVISION ")" +#define SWITCH_VERSION_FULL SWITCH_VERSION_MAJOR "." SWITCH_VERSION_MINOR "." SWITCH_VERSION_MICRO SWITCH_VERSION_REVISION #ifdef __cplusplus } diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index 8b4be69b2c..f46b8d935f 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -48,9 +48,23 @@ typedef struct conference_cdr_node_s { char *record_path; switch_time_t join_time; switch_time_t leave_time; + uint32_t flags; struct conference_cdr_node_s *next; } conference_cdr_node_t; +typedef enum { + CDRR_LOCKED = 1, + CDRR_PIN, + CDRR_MAXMEMBERS +} cdr_reject_reason_t; + +typedef struct conference_cdr_reject_s { + switch_caller_profile_t *cp; + switch_time_t reject_time; + cdr_reject_reason_t reason; + struct conference_cdr_reject_s *next; +} conference_cdr_reject_t; + typedef enum { @@ -175,7 +189,8 @@ typedef enum { CFLAG_EXIT_SOUND = (1 << 12), CFLAG_ENTER_SOUND = (1 << 13), CFLAG_VIDEO_BRIDGE = (1 << 14), - CFLAG_AUDIO_ALWAYS = (1 << 15) + CFLAG_AUDIO_ALWAYS = (1 << 15), + CFLAG_ENDCONF_FORCED = (1 << 16) } conf_flag_t; typedef enum { @@ -332,6 +347,7 @@ typedef struct conference_obj { uint32_t originating; switch_call_cause_t cancel_cause; conference_cdr_node_t *cdr_nodes; + conference_cdr_reject_t *cdr_rejected; switch_time_t start_time; switch_time_t end_time; char *log_dir; @@ -505,6 +521,7 @@ static switch_status_t conference_add_event_member_data(conference_member_t *mem static void conference_cdr_del(conference_member_t *member) { member->cdr_node->leave_time = switch_epoch_time_now(NULL); + member->cdr_node->flags = member->flags; } static void conference_cdr_add(conference_member_t *member) @@ -533,10 +550,30 @@ static void conference_cdr_add(conference_member_t *member) member->cdr_node->cp = switch_caller_profile_dup(member->conference->pool, cp); } +static void conference_cdr_rejected(conference_obj_t *conference, switch_channel_t *channel, cdr_reject_reason_t reason) +{ + conference_cdr_reject_t *rp; + switch_caller_profile_t *cp; + + rp = switch_core_alloc(conference->pool, sizeof(*rp)); + + rp->next = conference->cdr_rejected; + conference->cdr_rejected = rp; + rp->reason = reason; + rp->reject_time = switch_epoch_time_now(NULL); + + if (!(cp = switch_channel_get_caller_profile(channel))) { + return; + } + + rp->cp = switch_caller_profile_dup(conference->pool, cp); +} + static void conference_cdr_render(conference_obj_t *conference) { - switch_xml_t cdr, x_ptr, x_member, x_members, x_conference, x_cp; + switch_xml_t cdr, x_ptr, x_member, x_members, x_conference, x_cp, x_flags, x_tag, x_rejected, x_attempt; conference_cdr_node_t *np; + conference_cdr_reject_t *rp; int cdr_off = 0, conf_off = 0; char str[512]; char *path, *xml_text; @@ -544,7 +581,7 @@ static void conference_cdr_render(conference_obj_t *conference) if (zstr(conference->log_dir)) return; - if (!conference->cdr_nodes) return; + if (!conference->cdr_nodes && !conference->cdr_rejected) return; if (!(cdr = switch_xml_new("cdr"))) { abort(); @@ -583,18 +620,20 @@ static void conference_cdr_render(conference_obj_t *conference) if (!(x_ptr = switch_xml_add_child_d(x_conference, "end_time", conf_off++))) { abort(); } + switch_xml_set_attr_d(x_ptr, "endconf_forced", switch_test_flag(conference, CFLAG_ENDCONF_FORCED) ? "true" : "false"); switch_xml_set_attr_d(x_ptr, "type", "UNIX-epoch"); switch_snprintf(str, sizeof(str), "%ld", (long)conference->end_time); switch_xml_set_txt_d(x_ptr, str); + if (!(x_members = switch_xml_add_child_d(x_conference, "members", conf_off++))) { abort(); } - for (np = conference->cdr_nodes; np; np = np->next) { int member_off = 0; + int flag_off = 0; if (!(x_member = switch_xml_add_child_d(x_members, "member", conf_off++))) { @@ -619,6 +658,18 @@ static void conference_cdr_render(conference_obj_t *conference) switch_xml_set_txt_d(x_ptr, str); if (np->cp) { + x_flags = switch_xml_add_child_d(x_member, "flags", member_off++); + switch_assert(x_flags); + + x_tag = switch_xml_add_child_d(x_flags, "is_moderator", flag_off++); + switch_xml_set_txt_d(x_tag, switch_test_flag(np, MFLAG_MOD) ? "true" : "false"); + + x_tag = switch_xml_add_child_d(x_flags, "end_conference", flag_off++); + switch_xml_set_txt_d(x_tag, switch_test_flag(np, MFLAG_ENDCONF) ? "true" : "false"); + + x_tag = switch_xml_add_child_d(x_flags, "was_kicked", flag_off++); + switch_xml_set_txt_d(x_tag, switch_test_flag(np, MFLAG_KICKED) ? "true" : "false"); + if (!(x_cp = switch_xml_add_child_d(x_member, "caller_profile", member_off++))) { abort(); } @@ -631,8 +682,47 @@ static void conference_cdr_render(conference_obj_t *conference) } switch_xml_set_txt_d(x_ptr, np->record_path); } + + } + if (!(x_rejected = switch_xml_add_child_d(x_conference, "rejected", conf_off++))) { + abort(); + } + + for (rp = conference->cdr_rejected; rp; rp = rp->next) { + int attempt_off = 0; + int tag_off = 0; + + if (!(x_attempt = switch_xml_add_child_d(x_rejected, "attempt", attempt_off++))) { + abort(); + } + + if (!(x_ptr = switch_xml_add_child_d(x_attempt, "reason", tag_off++))) { + abort(); + } + if (rp->reason == CDRR_LOCKED) { + switch_xml_set_txt_d(x_ptr, "conference_locked"); + } else if (rp->reason == CDRR_MAXMEMBERS) { + switch_xml_set_txt_d(x_ptr, "max_members_reached"); + } else if (rp->reason == CDRR_PIN) { + switch_xml_set_txt_d(x_ptr, "invalid_pin"); + } + + if (!(x_ptr = switch_xml_add_child_d(x_attempt, "reject_time", tag_off++))) { + abort(); + } + switch_xml_set_attr_d(x_ptr, "type", "UNIX-epoch"); + switch_snprintf(str, sizeof(str), "%ld", (long) rp->reject_time); + switch_xml_set_txt_d(x_ptr, str); + + if (rp->cp) { + if (!(x_cp = switch_xml_add_child_d(x_attempt, "caller_profile", attempt_off++))) { + abort(); + } + switch_ivr_set_xml_profile_data(x_cp, rp->cp, 0); + } + } xml_text = switch_xml_toxml(cdr, SWITCH_TRUE); @@ -1343,7 +1433,14 @@ static void *SWITCH_THREAD_FUNC conference_video_thread_run(switch_thread_t *thr want_refresh = 0; for (imember = conference->members; imember; imember = imember->next) { - switch_channel_t *ichannel = switch_core_session_get_channel(imember->session); + switch_core_session_t *isession = imember->session; + switch_channel_t *ichannel; + + if (!isession || !switch_core_session_read_lock(isession)) { + continue; + } + + ichannel = switch_core_session_get_channel(imember->session); if (switch_channel_test_flag(ichannel, CF_VIDEO_REFRESH_REQ)) { want_refresh++; @@ -1354,6 +1451,8 @@ static void *SWITCH_THREAD_FUNC conference_video_thread_run(switch_thread_t *thr has_vid++; switch_core_session_write_video_frame(imember->session, vid_frame, SWITCH_IO_FLAG_NONE, 0); } + + switch_core_session_rwunlock(isession); } if (want_refresh) { @@ -1835,7 +1934,7 @@ static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t *thread, v switch_epoch_time_now(NULL) - conference->endconf_time > conference->endconf_grace_time) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Conference %s: endconf grace time exceeded (%u)\n", conference->name, conference->endconf_grace_time); - switch_set_flag(conference, CFLAG_DESTRUCT); + switch_set_flag(conference, CFLAG_DESTRUCT | CFLAG_ENDCONF_FORCED); } switch_mutex_unlock(conference->mutex); @@ -4595,6 +4694,7 @@ static void conference_xlist(conference_obj_t *conference, switch_xml_t x_confer x_member = switch_xml_add_child_d(x_members, "member", moff++); switch_assert(x_member); + switch_xml_set_attr_d(x_member, "type", "caller"); switch_snprintf(i, sizeof(i), "%d", member->id); @@ -6616,6 +6716,7 @@ SWITCH_STANDARD_APP(conference_function) } if (!pin_valid) { + conference_cdr_rejected(conference, channel, CDRR_PIN); goto done; } } @@ -6627,6 +6728,7 @@ SWITCH_STANDARD_APP(conference_function) /* don't allow more callers if the conference is locked, unless we invited them */ if (switch_test_flag(conference, CFLAG_LOCKED) && enforce_security) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Conference %s is locked.\n", conf_name); + conference_cdr_rejected(conference, channel, CDRR_LOCKED); if (conference->locked_sound) { /* Answer the channel */ switch_channel_answer(channel); @@ -6641,6 +6743,7 @@ SWITCH_STANDARD_APP(conference_function) */ if ((conference->max_members > 0) && (conference->count >= conference->max_members)) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Conference %s is full.\n", conf_name); + conference_cdr_rejected(conference, channel, CDRR_MAXMEMBERS); if (conference->maxmember_sound) { /* Answer the channel */ switch_channel_answer(channel); diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 009088e9f9..12cab2cf66 100755 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -30,7 +30,7 @@ * Bret McDanel * Luke Dashjr (OpenMethods, LLC) * Cesar Cepeda - * Chris Rienzo + * Christopher M. Rienzo * * mod_dptools.c -- Raw Audio File Streaming Application Module * diff --git a/src/mod/applications/mod_fax/Makefile.am b/src/mod/applications/mod_fax/Makefile.am deleted file mode 100644 index c71c5b9da5..0000000000 --- a/src/mod/applications/mod_fax/Makefile.am +++ /dev/null @@ -1,24 +0,0 @@ -include $(top_srcdir)/build/modmake.rulesam -MODNAME=mod_fax - -TIFF_DIR=$(switch_srcdir)/libs/tiff-3.8.2 -TIFF_BUILDDIR=$(switch_builddir)/libs/tiff-3.8.2 -TIFF_LA=$(TIFF_BUILDDIR)/libtiff/libtiff.la - -SPANDSP_DIR=$(switch_srcdir)/libs/spandsp -SPANDSP_BUILDDIR=$(switch_builddir)/libs/spandsp -SPANDSP_LA=$(SPANDSP_BUILDDIR)/src/libspandsp.la - -mod_LTLIBRARIES = mod_fax.la -mod_fax_la_SOURCES = mod_fax.c udptl.c -mod_fax_la_CFLAGS = $(AM_CFLAGS) -I$(SPANDSP_DIR)/src -I$(TIFF_DIR)/libtiff -I$(SPANDSP_BUILDDIR)/src -I$(TIFF_BUILDDIR)/libtiff -I. -mod_fax_la_LIBADD = $(switch_builddir)/libfreeswitch.la $(SPANDSP_LA) $(TIFF_LA) -mod_fax_la_LDFLAGS = -avoid-version -module -no-undefined -shared -ljpeg - -$(SPANDSP_LA): $(TIFF_LA) $(SPANDSP_DIR) $(SPANDSP_DIR)/.update - cd $(SPANDSP_BUILDDIR) && $(MAKE) -j1 - $(TOUCH_TARGET) - -$(TIFF_LA): $(TIFF_DIR) $(TIFF_DIR)/.update - cd $(TIFF_BUILDDIR) && $(MAKE) -j1 - $(TOUCH_TARGET) diff --git a/src/mod/applications/mod_fax/mod_fax.c b/src/mod/applications/mod_fax/mod_fax.c deleted file mode 100644 index 7eac2520b3..0000000000 --- a/src/mod/applications/mod_fax/mod_fax.c +++ /dev/null @@ -1,1945 +0,0 @@ -/* - * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005-2012, Anthony Minessale II - * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is FreeSWITCH mod_fax. - * - * The Initial Developer of the Original Code is - * Massimo Cetra - * - * Portions created by the Initial Developer are Copyright (C) - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Brian West - * Anthony Minessale II - * Steve Underwood - * Antonio Gallo - * mod_fax.c -- Fax applications provided by SpanDSP - * - */ - -#include -#ifdef WIN32 -#define FAX_INVALID_SOCKET INVALID_HANDLE_VALUE -typedef HANDLE zap_socket_t; -#else -#define FAX_INVALID_SOCKET -1 -typedef int zap_socket_t; -#endif - -#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES -#include -#include - -#include "udptl.h" - -#define LOCAL_FAX_MAX_DATAGRAM 400 -#define MAX_FEC_ENTRIES 4 -#define MAX_FEC_SPAN 4 - -/***************************************************************************** - OUR DEFINES AND STRUCTS -*****************************************************************************/ - -typedef enum { - FUNCTION_TX, - FUNCTION_RX, - FUNCTION_GW -} application_mode_t; - -typedef enum { - T38_MODE, - AUDIO_MODE, - T38_GATEWAY_MODE -} transport_mode_t; - -typedef enum { - T38_MODE_UNKNOWN = 0, - T38_MODE_NEGOTIATED = 1, - T38_MODE_REQUESTED = 2, - T38_MODE_REFUSED = -1, -} t38_mode_t; - -/* The global stuff */ -static struct { - switch_memory_pool_t *pool; - switch_mutex_t *mutex; - - uint32_t total_sessions; - - short int use_ecm; - short int verbose; - short int disable_v17; - short int enable_t38; - short int enable_t38_request; - short int enable_t38_insist; - char ident[20]; - char header[50]; - char *prepend_string; - char *spool; -} globals; - -struct pvt_s { - switch_core_session_t *session; - - application_mode_t app_mode; - - fax_state_t *fax_state; - t38_terminal_state_t *t38_state; - t38_gateway_state_t *t38_gateway_state; - t38_core_state_t *t38_core; - - udptl_state_t *udptl_state; - - char *filename; - char *ident; - char *header; - - int use_ecm; - int disable_v17; - int verbose; - int caller; - - int tx_page_start; - int tx_page_end; - - int done; - - t38_mode_t t38_mode; - - struct pvt_s *next; -}; - -typedef struct pvt_s pvt_t; - -static void launch_timer_thread(void); - -static struct { - pvt_t *head; - switch_mutex_t *mutex; - switch_thread_t *thread; - int thread_running; -} t38_state_list; - -static int add_pvt(pvt_t *pvt) -{ - int r = 0; - uint32_t sanity = 50; - - switch_mutex_lock(t38_state_list.mutex); - if (!t38_state_list.thread_running) { - - launch_timer_thread(); - - while(--sanity && !t38_state_list.thread_running) { - switch_yield(10000); - } - } - switch_mutex_unlock(t38_state_list.mutex); - - if (t38_state_list.thread_running) { - switch_mutex_lock(t38_state_list.mutex); - pvt->next = t38_state_list.head; - t38_state_list.head = pvt; - switch_mutex_unlock(t38_state_list.mutex); - } - - return r; - -} - - -static int del_pvt(pvt_t *del_pvt) -{ - pvt_t *p, *l = NULL; - int r = 0; - - if (!t38_state_list.thread_running) goto end; - - switch_mutex_lock(t38_state_list.mutex); - for (p = t38_state_list.head; p; p = p->next) { - if (p == del_pvt) { - if (l) { - l->next = p->next; - } else { - t38_state_list.head = p->next; - } - p->next = NULL; - r = 1; - goto end; - } - - l = p; - } - - end: - - switch_mutex_unlock(t38_state_list.mutex); - - return r; - -} - -static void *SWITCH_THREAD_FUNC timer_thread_run(switch_thread_t *thread, void *obj) -{ - switch_timer_t timer = { 0 }; - pvt_t *pvt; - int samples = 240; - int ms = 30; - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "timer thread started.\n"); - - if (switch_core_timer_init(&timer, "soft", ms, samples, NULL) != SWITCH_STATUS_SUCCESS) { - return NULL; - } - - t38_state_list.thread_running = 1; - - while(t38_state_list.thread_running) { - - switch_mutex_lock(t38_state_list.mutex); - - if (!t38_state_list.head) { - switch_mutex_unlock(t38_state_list.mutex); - goto end; - } - - for (pvt = t38_state_list.head; pvt; pvt = pvt->next) { - if (pvt->udptl_state) { - t38_terminal_send_timeout(pvt->t38_state, samples); - } - } - - switch_mutex_unlock(t38_state_list.mutex); - - switch_core_timer_next(&timer); - } - - end: - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "timer thread ended.\n"); - - t38_state_list.thread_running = 0; - switch_core_timer_destroy(&timer); - - return NULL; -} - -static void launch_timer_thread(void) -{ - - switch_threadattr_t *thd_attr = NULL; - - switch_threadattr_create(&thd_attr, globals.pool); - switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); - switch_thread_create(&t38_state_list.thread, thd_attr, timer_thread_run, NULL, globals.pool); -} - - -/***************************************************************************** - LOGGING AND HELPER FUNCTIONS -*****************************************************************************/ - -static void counter_increment(void) -{ - switch_mutex_lock(globals.mutex); - globals.total_sessions++; - switch_mutex_unlock(globals.mutex); -} - -static void spanfax_log_message(int level, const char *msg) -{ - int fs_log_level; - - switch (level) { - case SPAN_LOG_NONE: - return; - case SPAN_LOG_ERROR: - case SPAN_LOG_PROTOCOL_ERROR: - fs_log_level = SWITCH_LOG_ERROR; - break; - case SPAN_LOG_WARNING: - case SPAN_LOG_PROTOCOL_WARNING: - fs_log_level = SWITCH_LOG_WARNING; - break; - case SPAN_LOG_FLOW: - case SPAN_LOG_FLOW_2: - case SPAN_LOG_FLOW_3: - default: /* SPAN_LOG_DEBUG, SPAN_LOG_DEBUG_2, SPAN_LOG_DEBUG_3 */ - fs_log_level = SWITCH_LOG_DEBUG; - break; - } - - if (!zstr(msg)) { - switch_log_printf(SWITCH_CHANNEL_LOG, fs_log_level, "%s", msg); - } -} - -/* - * Called at the end of the document - */ -static void phase_e_handler(t30_state_t *s, void *user_data, int result) -{ - t30_stats_t t; - const char *local_ident; - const char *far_ident; - switch_core_session_t *session; - switch_channel_t *channel; - pvt_t *pvt; - char *tmp; - - pvt = (pvt_t *) user_data; - switch_assert(pvt); - - session = pvt->session; - switch_assert(session); - - channel = switch_core_session_get_channel(session); - switch_assert(channel); - - t30_get_transfer_statistics(s, &t); - local_ident = switch_str_nil(t30_get_tx_ident(s)); - far_ident = switch_str_nil(t30_get_rx_ident(s)); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "==============================================================================\n"); - - if (result == T30_ERR_OK) { - if (pvt->app_mode == FUNCTION_TX) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Fax successfully sent.\n"); - } else if (pvt->app_mode == FUNCTION_RX) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Fax successfully received.\n"); - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Fax successfully managed. How ?\n"); - } - switch_channel_set_variable(channel, "fax_success", "1"); - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Fax processing not successful - result (%d) %s.\n", result, - t30_completion_code_to_str(result)); - switch_channel_set_variable(channel, "fax_success", "0"); - } - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Remote station id: %s\n", far_ident); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Local station id: %s\n", local_ident); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Pages transferred: %i\n", - pvt->app_mode == FUNCTION_TX ? t.pages_tx : t.pages_rx); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Total fax pages: %i\n", t.pages_in_file); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Image resolution: %ix%i\n", t.x_resolution, t.y_resolution); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Transfer Rate: %i\n", t.bit_rate); - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "ECM status %s\n", (t.error_correcting_mode) ? "on" : "off"); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "remote country: %s\n", switch_str_nil(t30_get_rx_country(s))); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "remote vendor: %s\n", switch_str_nil(t30_get_rx_vendor(s))); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "remote model: %s\n", switch_str_nil(t30_get_rx_model(s))); - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "==============================================================================\n"); - - /* - Set our channel variables - */ - - tmp = switch_mprintf("%i", result); - if (tmp) { - switch_channel_set_variable(channel, "fax_result_code", tmp); - switch_safe_free(tmp); - } - - switch_channel_set_variable(channel, "fax_result_text", t30_completion_code_to_str(result)); - - switch_channel_set_variable(channel, "fax_ecm_used", (t.error_correcting_mode) ? "on" : "off"); - switch_channel_set_variable(channel, "fax_local_station_id", local_ident); - switch_channel_set_variable(channel, "fax_remote_station_id", far_ident); - - tmp = switch_mprintf("%i", pvt->app_mode == FUNCTION_TX ? t.pages_tx : t.pages_rx); - if (tmp) { - switch_channel_set_variable(channel, "fax_document_transferred_pages", tmp); - switch_safe_free(tmp); - } - - tmp = switch_mprintf("%i", t.pages_in_file); - if (tmp) { - switch_channel_set_variable(channel, "fax_document_total_pages", tmp); - switch_safe_free(tmp); - } - - tmp = switch_mprintf("%ix%i", t.x_resolution, t.y_resolution); - if (tmp) { - switch_channel_set_variable(channel, "fax_image_resolution", tmp); - switch_safe_free(tmp); - } - - tmp = switch_mprintf("%d", t.image_size); - if (tmp) { - switch_channel_set_variable(channel, "fax_image_size", tmp); - switch_safe_free(tmp); - } - - tmp = switch_mprintf("%d", t.bad_rows); - if (tmp) { - switch_channel_set_variable(channel, "fax_bad_rows", tmp); - switch_safe_free(tmp); - } - - tmp = switch_mprintf("%i", t.bit_rate); - if (tmp) { - switch_channel_set_variable(channel, "fax_transfer_rate", tmp); - switch_safe_free(tmp); - } - - /* switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); */ - - pvt->done = 1; - - /* - TODO Fire events - */ -} - -static int t38_tx_packet_handler(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count) -{ - switch_frame_t out_frame = { 0 }; - switch_core_session_t *session; - switch_channel_t *channel; - pvt_t *pvt; - uint8_t pkt[LOCAL_FAX_MAX_DATAGRAM]; - int x; - int r = 0; - - pvt = (pvt_t *) user_data; - session = pvt->session; - channel = switch_core_session_get_channel(session); - - /* we need to build a real packet here and make write_frame.packet and write_frame.packetlen point to it */ - out_frame.flags = SFF_UDPTL_PACKET | SFF_PROXY_PACKET; - out_frame.packet = pkt; - out_frame.packetlen = udptl_build_packet(pvt->udptl_state, pkt, buf, len); - - //switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "WRITE %d udptl bytes\n", out_frame.packetlen); - - for (x = 0; x < count; x++) { - if (switch_core_session_write_frame(session, &out_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { - r = -1; - break; - } - } - - return r; -} - -static switch_status_t spanfax_init(pvt_t *pvt, transport_mode_t trans_mode) -{ - - switch_core_session_t *session; - switch_channel_t *channel; - fax_state_t *fax; - t38_terminal_state_t *t38; - t30_state_t *t30; - - - session = (switch_core_session_t *) pvt->session; - switch_assert(session); - - channel = switch_core_session_get_channel(session); - switch_assert(channel); - - - switch (trans_mode) { - case AUDIO_MODE: - if (pvt->fax_state == NULL) { - pvt->fax_state = (fax_state_t *) switch_core_session_alloc(pvt->session, sizeof(fax_state_t)); - } - if (pvt->fax_state == NULL) { - return SWITCH_STATUS_FALSE; - } - - fax = pvt->fax_state; - t30 = fax_get_t30_state(fax); - - memset(fax, 0, sizeof(fax_state_t)); - if (fax_init(fax, pvt->caller) == NULL) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot initialize my fax structs\n"); - return SWITCH_STATUS_FALSE; - } - - fax_set_transmit_on_idle(fax, TRUE); - - span_log_set_message_handler(&fax->logging, spanfax_log_message); - span_log_set_message_handler(&t30->logging, spanfax_log_message); - - if (pvt->verbose) { - span_log_set_level(&fax->logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); - span_log_set_level(&t30->logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); - } - break; - case T38_MODE: - if (pvt->t38_state == NULL) { - pvt->t38_state = (t38_terminal_state_t *) switch_core_session_alloc(pvt->session, sizeof(t38_terminal_state_t)); - } - if (pvt->t38_state == NULL) { - return SWITCH_STATUS_FALSE; - } - if (pvt->udptl_state == NULL) { - pvt->udptl_state = (udptl_state_t *) switch_core_session_alloc(pvt->session, sizeof(udptl_state_t)); - } - if (pvt->udptl_state == NULL) { - t38_terminal_free(pvt->t38_state); - pvt->t38_state = NULL; - return SWITCH_STATUS_FALSE; - } - - /* add to timer thread processing */ - add_pvt(pvt); - - t38 = pvt->t38_state; - t30 = t38_terminal_get_t30_state(t38); - - memset(t38, 0, sizeof(t38_terminal_state_t)); - - if (t38_terminal_init(t38, pvt->caller, t38_tx_packet_handler, pvt) == NULL) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot initialize my T.38 structs\n"); - return SWITCH_STATUS_FALSE; - } - - pvt->t38_core = t38_terminal_get_t38_core_state(pvt->t38_state); - - if (udptl_init(pvt->udptl_state, UDPTL_ERROR_CORRECTION_REDUNDANCY, 3, 3, - (udptl_rx_packet_handler_t *) t38_core_rx_ifp_packet, (void *) pvt->t38_core) == NULL) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot initialize my UDPTL structs\n"); - return SWITCH_STATUS_FALSE; - } - - span_log_set_message_handler(&t38->logging, spanfax_log_message); - span_log_set_message_handler(&t30->logging, spanfax_log_message); - - if (pvt->verbose) { - span_log_set_level(&t38->logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); - span_log_set_level(&t30->logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); - } - break; - case T38_GATEWAY_MODE: - if (pvt->t38_gateway_state == NULL) { - pvt->t38_gateway_state = (t38_gateway_state_t *) switch_core_session_alloc(pvt->session, sizeof(t38_gateway_state_t)); - } - - if (pvt->udptl_state == NULL) { - pvt->udptl_state = (udptl_state_t *) switch_core_session_alloc(pvt->session, sizeof(udptl_state_t)); - } - - if (t38_gateway_init(pvt->t38_gateway_state, t38_tx_packet_handler, pvt) == NULL) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot initialize my T.38 structs\n"); - t38_gateway_free(pvt->t38_gateway_state); - pvt->t38_gateway_state = NULL; - - return SWITCH_STATUS_FALSE; - } - - pvt->t38_core = t38_gateway_get_t38_core_state(pvt->t38_gateway_state); - - if (udptl_init(pvt->udptl_state, UDPTL_ERROR_CORRECTION_REDUNDANCY, 3, 3, - (udptl_rx_packet_handler_t *) t38_core_rx_ifp_packet, (void *) pvt->t38_core) == NULL) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot initialize my UDPTL structs\n"); - t38_gateway_free(pvt->t38_gateway_state); - udptl_release(pvt->udptl_state); - pvt->udptl_state = NULL; - return SWITCH_STATUS_FALSE; - } - - t38_gateway_set_transmit_on_idle(pvt->t38_gateway_state, TRUE); - - if (switch_true(switch_channel_get_variable(channel, "fax_v17_disabled"))) { - t38_gateway_set_supported_modems(pvt->t38_gateway_state, T30_SUPPORT_V29 | T30_SUPPORT_V27TER); - } else { - t38_gateway_set_supported_modems(pvt->t38_gateway_state, T30_SUPPORT_V17 | T30_SUPPORT_V29 | T30_SUPPORT_V27TER); - } - - t38_gateway_set_ecm_capability(pvt->t38_gateway_state, pvt->use_ecm); - switch_channel_set_variable(channel, "fax_ecm_requested", pvt->use_ecm ? "true" : "false"); - - if (switch_true(switch_channel_get_variable(channel, "FAX_DISABLE_ECM"))) { - t38_gateway_set_ecm_capability(pvt->t38_gateway_state, FALSE); - } else { - t38_gateway_set_ecm_capability(pvt->t38_gateway_state, TRUE); - } - - - span_log_set_message_handler(&pvt->t38_gateway_state->logging, spanfax_log_message); - span_log_set_message_handler(&pvt->t38_core->logging, spanfax_log_message); - - if (pvt->verbose) { - span_log_set_level(&pvt->t38_gateway_state->logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); - span_log_set_level(&pvt->t38_core->logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); - } - - t38_set_t38_version(pvt->t38_core, 0); - t38_gateway_set_ecm_capability(pvt->t38_gateway_state, 1); - - return SWITCH_STATUS_SUCCESS; - - default: - assert(0); /* What? */ - return SWITCH_STATUS_SUCCESS; - } /* Switch trans mode */ - - /* All the things which are common to audio and T.38 FAX setup */ - t30_set_tx_ident(t30, pvt->ident); - t30_set_tx_page_header_info(t30, pvt->header); - - t30_set_phase_e_handler(t30, phase_e_handler, pvt); - - t30_set_supported_image_sizes(t30, - T30_SUPPORT_US_LETTER_LENGTH | T30_SUPPORT_US_LEGAL_LENGTH | T30_SUPPORT_UNLIMITED_LENGTH - | T30_SUPPORT_215MM_WIDTH | T30_SUPPORT_255MM_WIDTH | T30_SUPPORT_303MM_WIDTH); - t30_set_supported_resolutions(t30, - T30_SUPPORT_STANDARD_RESOLUTION | T30_SUPPORT_FINE_RESOLUTION | T30_SUPPORT_SUPERFINE_RESOLUTION - | T30_SUPPORT_R8_RESOLUTION | T30_SUPPORT_R16_RESOLUTION); - - if (pvt->disable_v17) { - t30_set_supported_modems(t30, T30_SUPPORT_V29 | T30_SUPPORT_V27TER); - switch_channel_set_variable(channel, "fax_v17_disabled", "1"); - } else { - t30_set_supported_modems(t30, T30_SUPPORT_V29 | T30_SUPPORT_V27TER | T30_SUPPORT_V17); - switch_channel_set_variable(channel, "fax_v17_disabled", "0"); - } - - if (pvt->use_ecm) { - t30_set_supported_compressions(t30, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION); - t30_set_ecm_capability(t30, TRUE); - switch_channel_set_variable(channel, "fax_ecm_requested", "1"); - } else { - t30_set_supported_compressions(t30, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION); - switch_channel_set_variable(channel, "fax_ecm_requested", "0"); - } - - if (pvt->app_mode == FUNCTION_TX) { - t30_set_tx_file(t30, pvt->filename, pvt->tx_page_start, pvt->tx_page_end); - } else { - t30_set_rx_file(t30, pvt->filename, -1); - } - switch_channel_set_variable(channel, "fax_filename", pvt->filename); - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t spanfax_destroy(pvt_t *pvt) -{ - int terminate; - t30_state_t *t30; - - if (!pvt) return SWITCH_STATUS_FALSE; - - if (pvt->fax_state) { - if (pvt->t38_state) { - terminate = 0; - } else { - terminate = 1; - } - - t30 = fax_get_t30_state(pvt->fax_state); - if (terminate && t30) { - t30_terminate(t30); - } - - fax_release(pvt->fax_state); - } - - if (pvt->t38_state) { - - /* remove from timer thread processing */ - del_pvt(pvt); - - if (pvt->t38_state) { - terminate = 1; - } else { - terminate = 0; - } - - t30 = t38_terminal_get_t30_state(pvt->t38_state); - - if (terminate && t30) { - t30_terminate(t30); - } - - t38_terminal_release(pvt->t38_state); - } - - if (pvt->t38_gateway_state) { - t38_gateway_release(pvt->t38_gateway_state); - } - - if (pvt->udptl_state) { - udptl_release(pvt->udptl_state); - } - return SWITCH_STATUS_SUCCESS; -} - -static t38_mode_t configure_t38(pvt_t *pvt) -{ - switch_core_session_t *session = pvt->session; - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_t38_options_t *t38_options = switch_channel_get_private(channel, "t38_options"); - int method = 2; - - if (!t38_options || !pvt || !pvt->t38_core) { - pvt->t38_mode = T38_MODE_REFUSED; - return pvt->t38_mode; - } - - t38_set_t38_version(pvt->t38_core, t38_options->T38FaxVersion); - t38_set_max_buffer_size(pvt->t38_core, t38_options->T38FaxMaxBuffer); - t38_set_fastest_image_data_rate(pvt->t38_core, t38_options->T38MaxBitRate); - t38_set_fill_bit_removal(pvt->t38_core, t38_options->T38FaxFillBitRemoval); - t38_set_mmr_transcoding(pvt->t38_core, t38_options->T38FaxTranscodingMMR); - t38_set_jbig_transcoding(pvt->t38_core, t38_options->T38FaxTranscodingJBIG); - t38_set_max_datagram_size(pvt->t38_core, t38_options->T38FaxMaxDatagram); - - if (t38_options->T38FaxRateManagement) { - if (!strcasecmp(t38_options->T38FaxRateManagement, "transferredTCF")) { - method = 2; - } else { - method = 1; - } - } - - t38_set_data_rate_management_method(pvt->t38_core, method); - - - //t38_set_data_transport_protocol(pvt->t38_core, int data_transport_protocol); - //t38_set_redundancy_control(pvt->t38_core, int category, int setting); - - return pvt->t38_mode; -} - -static t38_mode_t negotiate_t38(pvt_t *pvt) -{ - switch_core_session_t *session = pvt->session; - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_core_session_message_t msg = { 0 }; - switch_t38_options_t *t38_options = switch_channel_get_private(channel, "t38_options"); - int enabled = 0, insist = 0; - const char *v; - - pvt->t38_mode = T38_MODE_REFUSED; - - if (pvt->app_mode == FUNCTION_GW) { - enabled = 1; - } else if ((v = switch_channel_get_variable(channel, "fax_enable_t38"))) { - enabled = switch_true(v); - } else { - enabled = globals.enable_t38; - } - - if (!(enabled && t38_options)) { - /* if there is no t38_options the endpoint will refuse the transition */ - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s NO T38 options detected.\n", switch_channel_get_name(channel)); - switch_channel_set_private(channel, "t38_options", NULL); - } else { - pvt->t38_mode = T38_MODE_NEGOTIATED; - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxVersion = %d\n", t38_options->T38FaxVersion); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38MaxBitRate = %d\n", t38_options->T38MaxBitRate); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxFillBitRemoval = %d\n", t38_options->T38FaxFillBitRemoval); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxTranscodingMMR = %d\n", t38_options->T38FaxTranscodingMMR); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxTranscodingJBIG = %d\n", t38_options->T38FaxTranscodingJBIG); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxRateManagement = '%s'\n", t38_options->T38FaxRateManagement); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxMaxBuffer = %d\n", t38_options->T38FaxMaxBuffer); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxMaxDatagram = %d\n", t38_options->T38FaxMaxDatagram); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxUdpEC = '%s'\n", t38_options->T38FaxUdpEC); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38VendorInfo = '%s'\n", switch_str_nil(t38_options->T38VendorInfo)); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "ip = '%s'\n", t38_options->remote_ip ? t38_options->remote_ip : "Not specified"); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "port = %d\n", t38_options->remote_port); - - /* Time to practice our negotiating skills, by editing the t38_options */ - - if (t38_options->T38FaxVersion > 3) { - t38_options->T38FaxVersion = 3; - } - t38_options->T38MaxBitRate = (pvt->disable_v17) ? 9600 : 14400; - t38_options->T38FaxFillBitRemoval = 1; - t38_options->T38FaxTranscodingMMR = 0; - t38_options->T38FaxTranscodingJBIG = 0; - t38_options->T38FaxRateManagement = "transferredTCF"; - t38_options->T38FaxMaxBuffer = 2000; - t38_options->T38FaxMaxDatagram = LOCAL_FAX_MAX_DATAGRAM; - if (strcasecmp(t38_options->T38FaxUdpEC, "t38UDPRedundancy") == 0 - || - strcasecmp(t38_options->T38FaxUdpEC, "t38UDPFEC") == 0) { - t38_options->T38FaxUdpEC = "t38UDPRedundancy"; - } else { - t38_options->T38FaxUdpEC = NULL; - } - t38_options->T38VendorInfo = "0 0 0"; - } - - if ((v = switch_channel_get_variable(channel, "fax_enable_t38_insist"))) { - insist = switch_true(v); - } else { - insist = globals.enable_t38_insist; - } - - /* This will send the options back in a response */ - msg.from = __FILE__; - msg.message_id = SWITCH_MESSAGE_INDICATE_T38_DESCRIPTION; - msg.numeric_arg = insist; - switch_core_session_receive_message(session, &msg); - - return pvt->t38_mode; -} - - - -static t38_mode_t request_t38(pvt_t *pvt) -{ - switch_core_session_t *session = pvt->session; - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_core_session_message_t msg = { 0 }; - switch_t38_options_t *t38_options = NULL; - int enabled = 0, insist = 0; - const char *v; - - pvt->t38_mode = T38_MODE_UNKNOWN; - - if (pvt->app_mode == FUNCTION_GW) { - enabled = 1; - } else if ((v = switch_channel_get_variable(channel, "fax_enable_t38"))) { - enabled = switch_true(v); - } else { - enabled = globals.enable_t38; - } - - if (enabled) { - if ((v = switch_channel_get_variable(channel, "fax_enable_t38_request"))) { - enabled = switch_true(v); - } else { - enabled = globals.enable_t38_request; - } - } - - - if ((v = switch_channel_get_variable(channel, "fax_enable_t38_insist"))) { - insist = switch_true(v); - } else { - insist = globals.enable_t38_insist; - } - - if (enabled) { - t38_options = switch_core_session_alloc(session, sizeof(*t38_options)); - - t38_options->T38MaxBitRate = (pvt->disable_v17) ? 9600 : 14400; - t38_options->T38FaxVersion = 0; - t38_options->T38FaxFillBitRemoval = 1; - t38_options->T38FaxTranscodingMMR = 0; - t38_options->T38FaxTranscodingJBIG = 0; - t38_options->T38FaxRateManagement = "transferredTCF"; - t38_options->T38FaxMaxBuffer = 2000; - t38_options->T38FaxMaxDatagram = LOCAL_FAX_MAX_DATAGRAM; - t38_options->T38FaxUdpEC = "t38UDPRedundancy"; - t38_options->T38VendorInfo = "0 0 0"; - - switch_channel_set_private(channel, "t38_options", t38_options); - pvt->t38_mode = T38_MODE_REQUESTED; - - /* This will send a request for t.38 mode */ - msg.from = __FILE__; - msg.message_id = SWITCH_MESSAGE_INDICATE_REQUEST_IMAGE_MEDIA; - msg.numeric_arg = insist; - switch_core_session_receive_message(session, &msg); - } - - return pvt->t38_mode; -} - -/***************************************************************************** - MAIN FAX PROCESSING -*****************************************************************************/ - -static pvt_t *pvt_init(switch_core_session_t *session, application_mode_t app_mode) -{ - switch_channel_t *channel; - pvt_t *pvt = NULL; - const char *tmp; - - /* Make sure we have a valid channel when starting the FAX application */ - channel = switch_core_session_get_channel(session); - switch_assert(channel != NULL); - - if (!switch_channel_media_ready(channel)) { - switch_channel_answer(channel); - } - - /* Allocate our structs */ - pvt = switch_core_session_alloc(session, sizeof(pvt_t)); - pvt->session = session; - - pvt->app_mode = app_mode; - - pvt->tx_page_start = -1; - pvt->tx_page_end = -1; - - - switch(pvt->app_mode) { - - case FUNCTION_TX: - pvt->caller = 1; - break; - case FUNCTION_RX: - pvt->caller = 0; - break; - case FUNCTION_GW: - break; - } - - /* Retrieving our settings from the channel variables */ - - if ((tmp = switch_channel_get_variable(channel, "fax_use_ecm"))) { - pvt->use_ecm = switch_true(tmp); - } else { - pvt->use_ecm = globals.use_ecm; - } - - if ((tmp = switch_channel_get_variable(channel, "fax_disable_v17"))) { - pvt->disable_v17 = switch_true(tmp); - } else { - pvt->disable_v17 = globals.disable_v17; - } - - if ((tmp = switch_channel_get_variable(channel, "fax_verbose"))) { - pvt->verbose = switch_true(tmp); - } else { - pvt->verbose = globals.verbose; - } - - if ((tmp = switch_channel_get_variable(channel, "fax_force_caller"))) { - if (switch_true(tmp)) { - pvt->caller = 1; - } else { - pvt->caller = 0; - } - } - - if ((tmp = switch_channel_get_variable(channel, "fax_ident"))) { - pvt->ident = switch_core_session_strdup(session, tmp); - } else { - pvt->ident = switch_core_session_strdup(session, globals.ident); - } - - if ((tmp = switch_channel_get_variable(channel, "fax_header"))) { - pvt->header = switch_core_session_strdup(session, tmp); - } else { - pvt->header = switch_core_session_strdup(session, globals.header); - } - - if (pvt->app_mode == FUNCTION_TX) { - if ((tmp = switch_channel_get_variable(channel, "fax_start_page"))) { - pvt->tx_page_start = atoi(tmp); - } - - if ((tmp = switch_channel_get_variable(channel, "fax_end_page"))) { - pvt->tx_page_end = atoi(tmp); - } - - if (pvt->tx_page_end < -1) { - pvt->tx_page_end = -1; - } - - if (pvt->tx_page_start < -1) { - pvt->tx_page_start = -1; - } - - if ((pvt->tx_page_end < pvt->tx_page_start) && (pvt->tx_page_end != -1)) { - pvt->tx_page_end = pvt->tx_page_start; - } - } - - return pvt; -} - -void process_fax(switch_core_session_t *session, const char *data, application_mode_t app_mode) -{ - pvt_t *pvt; - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_codec_t read_codec = { 0 }; - switch_codec_t write_codec = { 0 }; - switch_frame_t *read_frame = { 0 }; - switch_frame_t write_frame = { 0 }; - switch_codec_implementation_t read_impl = { 0 }; - int16_t *buf = NULL; - - switch_core_session_get_read_impl(session, &read_impl); - - counter_increment(); - - - pvt = pvt_init(session, app_mode); - - - buf = switch_core_session_alloc(session, SWITCH_RECOMMENDED_BUFFER_SIZE); - - if (!zstr(data)) { - pvt->filename = switch_core_session_strdup(session, data); - if (pvt->app_mode == FUNCTION_TX) { - if ((switch_file_exists(pvt->filename, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot send inexistant fax file [%s]\n", - switch_str_nil(pvt->filename)); - goto done; - } - } - } else { - if (pvt->app_mode == FUNCTION_TX) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Fax TX filename not set.\n"); - goto done; - } else if (pvt->app_mode == FUNCTION_RX) { - char *fname; - const char *prefix; - switch_time_t time; - - time = switch_time_now(); - - if (!(prefix = switch_channel_get_variable(channel, "fax_prefix"))) { - prefix = globals.prepend_string; - } - - fname = switch_mprintf("%s/%s-%ld-%ld.tif", globals.spool, prefix, globals.total_sessions, time); - if (fname) { - pvt->filename = switch_core_session_strdup(session, fname); - switch_safe_free(fname); - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot automatically set fax RX destination file\n"); - goto done; - } - } else { - assert(0); /* UH ?? */ - } - } - - /* - *** Initialize the SpanDSP elements *** - - Note: we could analyze if a fax was already detected in previous stages - and if so, when T.38 will be supported, send a reinvite in T38_MODE, - bypassing AUDIO_MODE. - */ - - if ((spanfax_init(pvt, AUDIO_MODE) != SWITCH_STATUS_SUCCESS)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot initialize Fax engine\n"); - return; - } - - /* - Note: Disable echocan on the channel, remember to call app "disable_ec" in the dialplan - before invoking fax applications - */ - - /* - Note: we are disabling the Jitterbuffer, here, before we answer. - If you have set it to something else and the channel is pre-answered, - it will have no effect. Make sure that if you want more reliable - faxes, it is disabled. - */ - switch_channel_set_variable(channel, "jitterbuffer_msec", "0"); - - - /* We store the original channel codec before switching both - * legs of the calls to a linear 16 bit codec that is the one - * used internally by spandsp and FS will do the transcoding - * from G.711 or any other original codec - */ - if (switch_core_codec_init(&read_codec, - "L16", - NULL, - read_impl.samples_per_second, - read_impl.microseconds_per_packet / 1000, - 1, - SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, - NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Raw read codec activation Success L16 %u\n", - read_codec.implementation->microseconds_per_packet); - switch_core_session_set_read_codec(session, &read_codec); - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Raw read codec activation Failed L16\n"); - goto done; - } - - if (switch_core_codec_init(&write_codec, - "L16", - NULL, - read_impl.samples_per_second, - read_impl.microseconds_per_packet / 1000, - 1, - SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, - NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Raw write codec activation Success L16\n"); - write_frame.codec = &write_codec; - write_frame.data = buf; - write_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE; - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Raw write codec activation Failed L16\n"); - goto done; - } - - switch_ivr_sleep(session, 250, SWITCH_TRUE, NULL); - - - /* If you have the means, I highly recommend picking one up. ...*/ - request_t38(pvt); - - - while (switch_channel_ready(channel)) { - int tx = 0; - switch_status_t status; - - /* - if we are in T.38 mode, we should: 1- initialize the ptv->t38_state stuff, if not done - and then set some callbacks when reading frames. - The only thing we need, then, in this loop, is: - - read a frame without blocking - - eventually feed that frame in spandsp, - - call t38_terminal_send_timeout(), sleep for a while - - The T.38 stuff can be placed here (and the audio stuff can be skipped) - */ - - /* read new audio frame from the channel */ - status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); - - if (!SWITCH_READ_ACCEPTABLE(status) || pvt->done) { - /* Our duty is over */ - goto done; - } - - switch (pvt->t38_mode) { - case T38_MODE_REQUESTED: - { - if (switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) { - switch_core_session_message_t msg = { 0 }; - pvt->t38_mode = T38_MODE_NEGOTIATED; - spanfax_init(pvt, T38_MODE); - configure_t38(pvt); - - /* This will change the rtp stack to udptl mode */ - msg.from = __FILE__; - msg.message_id = SWITCH_MESSAGE_INDICATE_UDPTL_MODE; - switch_core_session_receive_message(session, &msg); - } - continue; - } - break; - case T38_MODE_UNKNOWN: - { - if (switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) { - if (negotiate_t38(pvt) == T38_MODE_NEGOTIATED) { - /* is is safe to call this again, it was already called above in AUDIO_MODE */ - /* but this is the only way to set up the t38 stuff */ - spanfax_init(pvt, T38_MODE); - continue; - } - } - } - break; - case T38_MODE_NEGOTIATED: - { - /* do what we need to do when we are in t38 mode */ - if (switch_test_flag(read_frame, SFF_CNG)) { - /* dunno what to do, most likely you will not get too many of these since we turn off the timer in udptl mode */ - continue; - } - - if (switch_test_flag(read_frame, SFF_UDPTL_PACKET)) { - /* now we know we can cast frame->packet to a udptl structure */ - //switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "READ %d udptl bytes\n", read_frame->packetlen); - - udptl_rx_packet(pvt->udptl_state, read_frame->packet, read_frame->packetlen); - - - } - } - continue; - default: - break; - } - - /* Skip CNG frames (auto-generated by FreeSWITCH, usually) */ - if (switch_test_flag(read_frame, SFF_CNG)) { - /* We have no real signal data for the FAX software, but we have a space in time if we have a CNG indication. - Do a fill-in operation in the FAX machine, to keep things rolling along. */ - if (fax_rx_fillin(pvt->fax_state, read_frame->samples)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "fax_rx_fillin reported an error\n"); - goto done; - } - } else { - /* Pass the new incoming audio frame to the fax_rx function */ - if (fax_rx(pvt->fax_state, (int16_t *) read_frame->data, read_frame->samples)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "fax_rx reported an error\n"); - goto done; - } - } - - if ((tx = fax_tx(pvt->fax_state, buf, write_codec.implementation->samples_per_packet)) < 0) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "fax_tx reported an error\n"); - goto done; - } - - if (!tx) { - /* switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "No audio samples to send\n"); */ - continue; - } else { - /* Set our write_frame data */ - write_frame.datalen = tx * sizeof(int16_t); - write_frame.samples = tx; - } - - if (switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { - goto done; - } - - } - - done: - /* Destroy the SpanDSP structures */ - spanfax_destroy(pvt); - - /* restore the original codecs over the channel */ - - switch_core_session_set_read_codec(session, NULL); - - if (switch_core_codec_ready(&read_codec)) { - switch_core_codec_destroy(&read_codec); - } - - if (switch_core_codec_ready(&write_codec)) { - switch_core_codec_destroy(&write_codec); - } -} - -/* ************************************************************************** - CONFIGURATION - ************************************************************************* */ - -void load_configuration(switch_bool_t reload) -{ - switch_xml_t xml = NULL, x_lists = NULL, x_list = NULL, cfg = NULL; - - if ((xml = switch_xml_open_cfg("fax.conf", &cfg, NULL))) { - if ((x_lists = switch_xml_child(cfg, "settings"))) { - for (x_list = switch_xml_child(x_lists, "param"); x_list; x_list = x_list->next) { - const char *name = switch_xml_attr(x_list, "name"); - const char *value = switch_xml_attr(x_list, "value"); - - if (zstr(name)) { - continue; - } - - if (zstr(value)) { - continue; - } - - if (!strcmp(name, "use-ecm")) { - if (switch_true(value)) - globals.use_ecm = 1; - else - globals.use_ecm = 0; - } else if (!strcmp(name, "verbose")) { - if (switch_true(value)) - globals.verbose = 1; - else - globals.verbose = 0; - } else if (!strcmp(name, "disable-v17")) { - if (switch_true(value)) - globals.disable_v17 = 1; - else - globals.disable_v17 = 0; - } else if (!strcmp(name, "enable-t38")) { - if (switch_true(value)) { - globals.enable_t38= 1; - } else { - globals.enable_t38 = 0; - } - } else if (!strcmp(name, "enable-t38-request")) { - if (switch_true(value)) { - globals.enable_t38_request = 1; - } else { - globals.enable_t38_request = 0; - } - } else if (!strcmp(name, "ident")) { - strncpy(globals.ident, value, sizeof(globals.ident) - 1); - } else if (!strcmp(name, "header")) { - strncpy(globals.header, value, sizeof(globals.header) - 1); - } else if (!strcmp(name, "spool-dir")) { - globals.spool = switch_core_strdup(globals.pool, value); - } else if (!strcmp(name, "file-prefix")) { - globals.prepend_string = switch_core_strdup(globals.pool, value); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unknown parameter %s\n", name); - } - - } - } - - switch_xml_free(xml); - } -} - -static void event_handler(switch_event_t *event) -{ - load_configuration(1); -} - - - - - - -typedef struct { - switch_core_session_t *session; - dtmf_rx_state_t *dtmf_detect; -} switch_inband_dtmf_t; - -static switch_bool_t inband_dtmf_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type) -{ - switch_inband_dtmf_t *pvt = (switch_inband_dtmf_t *) user_data; - switch_frame_t *frame = NULL; - char digit_str[80]; - switch_channel_t *channel = switch_core_session_get_channel(pvt->session); - - switch (type) { - case SWITCH_ABC_TYPE_INIT: - pvt->dtmf_detect = dtmf_rx_init(NULL, NULL, NULL); - break; - case SWITCH_ABC_TYPE_CLOSE: - if (pvt->dtmf_detect) { - dtmf_rx_free(pvt->dtmf_detect); - } - break; - case SWITCH_ABC_TYPE_READ_REPLACE: - if ((frame = switch_core_media_bug_get_read_replace_frame(bug))) { - dtmf_rx(pvt->dtmf_detect, frame->data, frame->samples); - dtmf_rx_get(pvt->dtmf_detect, digit_str, sizeof(digit_str)); - if (digit_str[0]) { - char *p = digit_str; - while (p && *p) { - switch_dtmf_t dtmf = {0}; - dtmf.digit = *p; - dtmf.duration = switch_core_default_dtmf_duration(0); - switch_channel_queue_dtmf(channel, &dtmf); - p++; - } - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(bug)), SWITCH_LOG_DEBUG, "DTMF DETECTED: [%s]\n", - digit_str); - } - switch_core_media_bug_set_read_replace_frame(bug, frame); - } - break; - case SWITCH_ABC_TYPE_WRITE: - default: - break; - } - - return SWITCH_TRUE; -} - -switch_status_t spandsp_stop_inband_dtmf_session(switch_core_session_t *session) -{ - switch_media_bug_t *bug; - switch_channel_t *channel = switch_core_session_get_channel(session); - - if ((bug = switch_channel_get_private(channel, "dtmf"))) { - switch_channel_set_private(channel, "dtmf", NULL); - switch_core_media_bug_remove(session, &bug); - return SWITCH_STATUS_SUCCESS; - } - return SWITCH_STATUS_FALSE; -} - -switch_status_t spandsp_inband_dtmf_session(switch_core_session_t *session) -{ - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_media_bug_t *bug; - switch_status_t status; - switch_inband_dtmf_t *pvt; - switch_codec_implementation_t read_impl = { 0 }; - - switch_core_session_get_read_impl(session, &read_impl); - - if (!(pvt = switch_core_session_alloc(session, sizeof(*pvt)))) { - return SWITCH_STATUS_MEMERR; - } - - - pvt->session = session; - - - if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) { - return SWITCH_STATUS_FALSE; - } - - if ((status = switch_core_media_bug_add(session, "spandsp_dtmf_detect", NULL, - inband_dtmf_callback, pvt, 0, SMBF_READ_REPLACE, &bug)) != SWITCH_STATUS_SUCCESS) { - return status; - } - - switch_channel_set_private(channel, "dtmf", bug); - - return SWITCH_STATUS_SUCCESS; -} - -/* ************************************************************************** - FREESWITCH MODULE DEFINITIONS - ************************************************************************* */ - -#define SPANFAX_RX_USAGE "" -#define SPANFAX_TX_USAGE "" - -SWITCH_MODULE_LOAD_FUNCTION(mod_fax_init); -SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fax_shutdown); -SWITCH_MODULE_DEFINITION(mod_fax, mod_fax_init, mod_fax_shutdown, NULL); - -static switch_event_node_t *NODE = NULL; - -SWITCH_STANDARD_APP(spanfax_tx_function) -{ - process_fax(session, data, FUNCTION_TX); -} - -SWITCH_STANDARD_APP(spanfax_rx_function) -{ - process_fax(session, data, FUNCTION_RX); -} - - -SWITCH_STANDARD_APP(dtmf_session_function) -{ - spandsp_inband_dtmf_session(session); -} - -SWITCH_STANDARD_APP(stop_dtmf_session_function) -{ - spandsp_stop_inband_dtmf_session(session); -} - -static const switch_state_handler_table_t t38_gateway_state_handlers; - -static switch_status_t t38_gateway_on_soft_execute(switch_core_session_t *session) -{ - switch_core_session_t *other_session; - - switch_channel_t *other_channel, *channel = switch_core_session_get_channel(session); - pvt_t *pvt; - const char *peer_uuid = switch_channel_get_variable(channel, "t38_peer"); - switch_core_session_message_t msg = { 0 }; - switch_status_t status; - switch_frame_t *read_frame = { 0 }; - - if (!(other_session = switch_core_session_locate(peer_uuid))) { - switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s Cannot locate channel with uuid %s", - switch_channel_get_name(channel), peer_uuid); - goto end; - } - - other_channel = switch_core_session_get_channel(other_session); - - pvt = pvt_init(session, FUNCTION_GW); - request_t38(pvt); - - msg.message_id = SWITCH_MESSAGE_INDICATE_BRIDGE; - msg.from = __FILE__; - msg.string_arg = peer_uuid; - switch_core_session_receive_message(session, &msg); - - while (switch_channel_ready(channel) && switch_channel_up(other_channel) && !switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) { - status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); - - if (!SWITCH_READ_ACCEPTABLE(status) || pvt->done) { - /* Our duty is over */ - goto end_unlock; - } - - if (switch_test_flag(read_frame, SFF_CNG)) { - continue; - } - - if (switch_core_session_write_frame(other_session, read_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { - goto end_unlock; - } - } - - if (!(switch_channel_ready(channel) && switch_channel_up(other_channel))) { - goto end_unlock; - } - - if (!switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) { - switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s Could not negotiate T38\n", switch_channel_get_name(channel)); - goto end_unlock; - } - - if (pvt->t38_mode == T38_MODE_REQUESTED) { - spanfax_init(pvt, T38_GATEWAY_MODE); - configure_t38(pvt); - pvt->t38_mode = T38_MODE_NEGOTIATED; - } else { - if (negotiate_t38(pvt) != T38_MODE_NEGOTIATED) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s Could not negotiate T38\n", switch_channel_get_name(channel)); - switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); - goto end_unlock; - } - - spanfax_init(pvt, T38_GATEWAY_MODE); - } - - /* This will change the rtp stack to udptl mode */ - msg.from = __FILE__; - msg.message_id = SWITCH_MESSAGE_INDICATE_UDPTL_MODE; - switch_core_session_receive_message(session, &msg); - - - /* wake up the audio side */ - switch_channel_set_private(channel, "_t38_pvt", pvt); - switch_channel_set_app_flag_key("T38", other_channel, CF_APP_T38); - - - while (switch_channel_ready(channel) && switch_channel_up(other_channel)) { - - status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); - - if (!SWITCH_READ_ACCEPTABLE(status) || pvt->done) { - /* Our duty is over */ - goto end_unlock; - } - - if (switch_test_flag(read_frame, SFF_CNG)) { - continue; - } - - if (switch_test_flag(read_frame, SFF_UDPTL_PACKET)) { - udptl_rx_packet(pvt->udptl_state, read_frame->packet, read_frame->packetlen); - } - } - - end_unlock: - - - msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE; - msg.from = __FILE__; - msg.string_arg = peer_uuid; - switch_core_session_receive_message(session, &msg); - - switch_channel_hangup(other_channel, SWITCH_CAUSE_NORMAL_CLEARING); - switch_core_session_rwunlock(other_session); - - end: - - switch_channel_clear_state_handler(channel, &t38_gateway_state_handlers); - switch_channel_set_variable(channel, "t38_peer", NULL); - - switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t t38_gateway_on_consume_media(switch_core_session_t *session) -{ - switch_core_session_t *other_session; - switch_channel_t *other_channel, *channel = switch_core_session_get_channel(session); - const char *peer_uuid = switch_channel_get_variable(channel, "t38_peer"); - pvt_t *pvt = NULL; - switch_codec_t read_codec = { 0 }; - switch_codec_t write_codec = { 0 }; - switch_frame_t *read_frame = { 0 }; - switch_frame_t write_frame = { 0 }; - switch_codec_implementation_t read_impl = { 0 }; - int16_t *buf = NULL; - switch_status_t status; - switch_size_t tx; - const char *t38_trace = switch_channel_get_variable(channel, "t38_trace"); - char *trace_read, *trace_write; - zap_socket_t read_fd = FAX_INVALID_SOCKET, write_fd = FAX_INVALID_SOCKET; - switch_core_session_message_t msg = { 0 }; - switch_event_t *event; - - switch_core_session_get_read_impl(session, &read_impl); - - buf = switch_core_session_alloc(session, SWITCH_RECOMMENDED_BUFFER_SIZE); - - if (!(other_session = switch_core_session_locate(peer_uuid))) { - switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); - goto end; - } - - other_channel = switch_core_session_get_channel(other_session); - - msg.message_id = SWITCH_MESSAGE_INDICATE_BRIDGE; - msg.from = __FILE__; - msg.string_arg = peer_uuid; - switch_core_session_receive_message(session, &msg); - - if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_BRIDGE) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(channel, event); - switch_event_fire(&event); - } - - while (switch_channel_ready(channel) && switch_channel_up(other_channel) && !switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) { - status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); - - if (!SWITCH_READ_ACCEPTABLE(status)) { - /* Our duty is over */ - goto end_unlock; - } - - if (switch_test_flag(read_frame, SFF_CNG)) { - continue; - } - - if (switch_core_session_write_frame(other_session, read_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { - goto end_unlock; - } - } - - if (!(switch_channel_ready(channel) && switch_channel_up(other_channel))) { - goto end_unlock; - } - - if (!switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) { - switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); - goto end_unlock; - } - - if (!(pvt = switch_channel_get_private(other_channel, "_t38_pvt"))) { - switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); - goto end_unlock; - } - - if (switch_core_codec_init(&read_codec, - "L16", - NULL, - read_impl.samples_per_second, - read_impl.microseconds_per_packet / 1000, - 1, - SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, - NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Raw read codec activation Success L16 %u\n", - read_codec.implementation->microseconds_per_packet); - switch_core_session_set_read_codec(session, &read_codec); - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Raw read codec activation Failed L16\n"); - goto end_unlock; - } - - if (switch_core_codec_init(&write_codec, - "L16", - NULL, - read_impl.samples_per_second, - read_impl.microseconds_per_packet / 1000, - 1, - SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, - NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Raw write codec activation Success L16\n"); - write_frame.codec = &write_codec; - write_frame.data = buf; - write_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE; - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Raw write codec activation Failed L16\n"); - goto end_unlock; - } - - switch_ivr_sleep(session, 0, SWITCH_TRUE, NULL); - - if (switch_true(t38_trace)) { - trace_read = switch_core_session_sprintf(session, "%s%s%s_read.raw", SWITCH_GLOBAL_dirs.temp_dir, - SWITCH_PATH_SEPARATOR, switch_core_session_get_uuid(session)); - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Tracing inbound audio to %s\n", trace_read); - switch_channel_set_variable(channel, "t38_trace_read", trace_read); - - trace_write = switch_core_session_sprintf(session, "%s%s%s_write.raw", SWITCH_GLOBAL_dirs.temp_dir, - SWITCH_PATH_SEPARATOR, switch_core_session_get_uuid(session)); - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Tracing outbound audio to %s\n", trace_write); - switch_channel_set_variable(channel, "t38_trace_read", trace_write); - - - if ((write_fd = open(trace_read, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) != FAX_INVALID_SOCKET) { - if ((read_fd = open(trace_write, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) == FAX_INVALID_SOCKET) { - close(write_fd); - write_fd = FAX_INVALID_SOCKET; - } - } - } - - while (switch_channel_ready(channel) && switch_channel_up(other_channel)) { - status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); - - if (!SWITCH_READ_ACCEPTABLE(status) || pvt->done) { - /* Our duty is over */ - goto end_unlock; - } - - - /* Skip CNG frames (auto-generated by FreeSWITCH, usually) */ - if (!switch_test_flag(read_frame, SFF_CNG)) { - - if (read_fd != FAX_INVALID_SOCKET) { - int w = write(read_fd, read_frame->data, read_frame->datalen); - if (w <= 0) { - close(read_fd); - read_fd = FAX_INVALID_SOCKET; - } - } - if (t38_gateway_rx(pvt->t38_gateway_state, (int16_t *) read_frame->data, read_frame->samples)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "fax_rx reported an error\n"); - goto end_unlock; - } - } - - if ((tx = t38_gateway_tx(pvt->t38_gateway_state, buf, write_codec.implementation->samples_per_packet)) < 0) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "fax_tx reported an error\n"); - goto end_unlock; - } - - if (!tx) { - /* switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "No audio samples to send\n"); */ - continue; - } else { - /* Set our write_frame data */ - write_frame.datalen = tx * sizeof(int16_t); - write_frame.samples = tx; - } - - if (write_fd != FAX_INVALID_SOCKET) { - int w = write(write_fd, write_frame.data, write_frame.datalen); - if (w <= 0) { - close(write_fd); - write_fd = FAX_INVALID_SOCKET; - } - } - - if (switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { - goto end_unlock; - } - } - - end_unlock: - - msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE; - msg.from = __FILE__; - msg.string_arg = peer_uuid; - switch_core_session_receive_message(session, &msg); - - - if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_UNBRIDGE) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(channel, event); - switch_event_fire(&event); - } - - if (read_fd != FAX_INVALID_SOCKET) { - close(read_fd); - read_fd = FAX_INVALID_SOCKET; - } - - if (write_fd != FAX_INVALID_SOCKET) { - close(write_fd); - write_fd = FAX_INVALID_SOCKET; - } - - - switch_channel_hangup(other_channel, SWITCH_CAUSE_NORMAL_CLEARING); - switch_core_session_rwunlock(other_session); - - switch_core_session_set_read_codec(session, NULL); - - if (switch_core_codec_ready(&read_codec)) { - switch_core_codec_destroy(&read_codec); - } - - if (switch_core_codec_ready(&write_codec)) { - switch_core_codec_destroy(&write_codec); - } - - - end: - - switch_channel_clear_state_handler(channel, &t38_gateway_state_handlers); - switch_channel_set_variable(channel, "t38_peer", NULL); - switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); - - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t t38_gateway_on_reset(switch_core_session_t *session) -{ - switch_channel_t *channel = switch_core_session_get_channel(session); - - switch_channel_set_variable(channel, "rtp_autoflush_during_bridge", "false"); - - switch_channel_clear_flag(channel, CF_REDIRECT); - - if (switch_channel_test_app_flag(channel, CF_APP_TAGGED)) { - switch_channel_clear_app_flag(channel, CF_APP_TAGGED); - switch_channel_set_state(channel, CS_CONSUME_MEDIA); - } else { - switch_channel_set_state(channel, CS_SOFT_EXECUTE); - } - - return SWITCH_STATUS_SUCCESS; -} - -static const switch_state_handler_table_t t38_gateway_state_handlers = { - /*.on_init */ NULL, - /*.on_routing */ NULL, - /*.on_execute */ NULL, - /*.on_hangup */ NULL, - /*.on_exchange_media */ NULL, - /*.on_soft_execute */ t38_gateway_on_soft_execute, - /*.on_consume_media */ t38_gateway_on_consume_media, - /*.on_hibernate */ NULL, - /*.on_reset */ t38_gateway_on_reset, - /*.on_park */ NULL, - /*.on_reporting */ NULL, - /*.on_destroy */ NULL, - SSH_FLAG_STICKY -}; - -static switch_bool_t t38_gateway_start(switch_core_session_t *session, const char *app, const char *data) -{ - switch_channel_t *other_channel = NULL, *channel = switch_core_session_get_channel(session); - switch_core_session_t *other_session = NULL; - int peer = app && !strcasecmp(app, "peer"); - - if (switch_core_session_get_partner(session, &other_session) == SWITCH_STATUS_SUCCESS) { - other_channel = switch_core_session_get_channel(other_session); - - switch_channel_set_variable(channel, "t38_peer", switch_core_session_get_uuid(other_session)); - switch_channel_set_variable(other_channel, "t38_peer", switch_core_session_get_uuid(session)); - - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s starting gateway mode to %s\n", - switch_channel_get_name(peer ? channel : other_channel), - switch_channel_get_name(peer ? other_channel : channel)); - - - switch_channel_clear_state_handler(channel, NULL); - switch_channel_clear_state_handler(other_channel, NULL); - - switch_channel_add_state_handler(channel, &t38_gateway_state_handlers); - switch_channel_add_state_handler(other_channel, &t38_gateway_state_handlers); - - switch_channel_set_app_flag(peer ? channel : other_channel, CF_APP_TAGGED); - switch_channel_clear_app_flag(peer ? other_channel : channel, CF_APP_TAGGED); - - switch_channel_set_flag(channel, CF_REDIRECT); - switch_channel_set_state(channel, CS_RESET); - - switch_channel_set_flag(other_channel, CF_REDIRECT); - switch_channel_set_state(other_channel, CS_RESET); - - switch_core_session_rwunlock(other_session); - - } - - return SWITCH_FALSE; -} - - -SWITCH_STANDARD_APP(t38_gateway_function) -{ - switch_channel_t *channel = switch_core_session_get_channel(session); - time_t timeout = switch_epoch_time_now(NULL) + 20; - const char *var; - - if (zstr(data) || strcasecmp(data, "self")) { - data = "peer"; - } - - switch_channel_set_variable(channel, "t38_leg", data); - - if ((var = switch_channel_get_variable(channel, "t38_gateway_detect_timeout"))) { - long to = atol(var); - if (to > -1) { - timeout = (time_t) (switch_epoch_time_now(NULL) + to); - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s invalid timeout value.\n", switch_channel_get_name(channel)); - } - } - - switch_ivr_tone_detect_session(session, "t38", "1100.0", "rw", timeout, 1, data, NULL, t38_gateway_start); -} - - -SWITCH_MODULE_LOAD_FUNCTION(mod_fax_init) -{ - switch_application_interface_t *app_interface; - - *module_interface = switch_loadable_module_create_module_interface(pool, modname); - - SWITCH_ADD_APP(app_interface, "t38_gateway", "Convert to T38 Gateway if tones are heard", "Convert to T38 Gateway if tones are heard", - t38_gateway_function, "", SAF_MEDIA_TAP); - - SWITCH_ADD_APP(app_interface, "rxfax", "FAX Receive Application", "FAX Receive Application", spanfax_rx_function, SPANFAX_RX_USAGE, - SAF_SUPPORT_NOMEDIA); - SWITCH_ADD_APP(app_interface, "txfax", "FAX Transmit Application", "FAX Transmit Application", spanfax_tx_function, SPANFAX_TX_USAGE, - SAF_SUPPORT_NOMEDIA); - - SWITCH_ADD_APP(app_interface, "spandsp_stop_dtmf", "stop inband dtmf", "Stop detecting inband dtmf.", stop_dtmf_session_function, "", SAF_NONE); - SWITCH_ADD_APP(app_interface, "spandsp_start_dtmf", "Detect dtmf", "Detect inband dtmf on the session", dtmf_session_function, "", SAF_MEDIA_TAP); - - memset(&globals, 0, sizeof(globals)); - memset(&t38_state_list, 0, sizeof(t38_state_list)); - switch_core_new_memory_pool(&globals.pool); - switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, globals.pool); - switch_mutex_init(&t38_state_list.mutex, SWITCH_MUTEX_NESTED, globals.pool); - - globals.enable_t38 = 1; - globals.total_sessions = 0; - globals.verbose = 1; - globals.use_ecm = 1; - globals.disable_v17 = 0; - globals.prepend_string = switch_core_strdup(globals.pool, "fax"); - globals.spool = switch_core_strdup(globals.pool, "/tmp"); - strncpy(globals.ident, "SpanDSP Fax Ident", sizeof(globals.ident) - 1); - strncpy(globals.header, "SpanDSP Fax Header", sizeof(globals.header) - 1); - - load_configuration(0); - - if ((switch_event_bind_removable(modname, SWITCH_EVENT_RELOADXML, NULL, event_handler, NULL, &NODE) != SWITCH_STATUS_SUCCESS)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind our reloadxml handler!\n"); - /* Not such severe to prevent loading */ - } - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "mod_fax loaded, using spandsp library version [%s]\n", SPANDSP_RELEASE_DATETIME_STRING); - - return SWITCH_STATUS_SUCCESS; -} - -SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fax_shutdown) -{ - switch_memory_pool_t *pool = globals.pool; - - switch_event_unbind(&NODE); - - switch_core_destroy_memory_pool(&pool); - memset(&globals, 0, sizeof(globals)); - - return SWITCH_STATUS_UNLOAD; -} - -/* For Emacs: - * Local Variables: - * mode:c - * indent-tabs-mode:nil - * tab-width:4 - * c-basic-offset:4 - * End: - * For VIM: - * vim:set softtabstop=4 shiftwidth=4 tabstop=4: - */ diff --git a/src/mod/applications/mod_fax/udptl.c b/src/mod/applications/mod_fax/udptl.c deleted file mode 100644 index a2651513f0..0000000000 --- a/src/mod/applications/mod_fax/udptl.c +++ /dev/null @@ -1,563 +0,0 @@ -//#define UDPTL_DEBUG -/* - * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2009, Steve Underwood - * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * Contributor(s): - * - * Steve Underwood - * - * udptl.c -- UDPTL handling for T.38 - * - */ - -#include -#include -#include -#include -#include - -#include "udptl.h" - -#define FALSE 0 -#define TRUE (!FALSE) - -static int decode_length(const uint8_t *buf, int limit, int *len, int *pvalue) -{ - if (*len >= limit) - return -1; - if ((buf[*len] & 0x80) == 0) { - *pvalue = buf[(*len)++]; - return 0; - } - if ((buf[*len] & 0x40) == 0) { - if (*len >= limit - 1) - return -1; - *pvalue = (buf[(*len)++] & 0x3F) << 8; - *pvalue |= buf[(*len)++]; - return 0; - } - *pvalue = (buf[(*len)++] & 0x3F) << 14; - /* Indicate we have a fragment */ - return 1; -} - -/*- End of function --------------------------------------------------------*/ - -static int decode_open_type(const uint8_t *buf, int limit, int *len, const uint8_t ** p_object, int *p_num_octets) -{ - int octet_cnt; - int octet_idx; - int stat; - int i; - const uint8_t **pbuf; - - for (octet_idx = 0, *p_num_octets = 0;; octet_idx += octet_cnt) { - if ((stat = decode_length(buf, limit, len, &octet_cnt)) < 0) - return -1; - if (octet_cnt > 0) { - *p_num_octets += octet_cnt; - - pbuf = &p_object[octet_idx]; - i = 0; - /* Make sure the buffer contains at least the number of bits requested */ - if ((*len + octet_cnt) > limit) - return -1; - - *pbuf = &buf[*len]; - *len += octet_cnt; - } - if (stat == 0) - break; - } - return 0; -} - -/*- End of function --------------------------------------------------------*/ - -static int encode_length(uint8_t *buf, int *len, int value) -{ - int multiplier; - - if (value < 0x80) { - /* 1 octet */ - buf[(*len)++] = value; - return value; - } - if (value < 0x4000) { - /* 2 octets */ - /* Set the first bit of the first octet */ - buf[(*len)++] = ((0x8000 | value) >> 8) & 0xFF; - buf[(*len)++] = value & 0xFF; - return value; - } - /* Fragmentation */ - multiplier = (value < 0x10000) ? (value >> 14) : 4; - /* Set the first 2 bits of the octet */ - buf[(*len)++] = 0xC0 | multiplier; - return multiplier << 14; -} - -/*- End of function --------------------------------------------------------*/ - -static int encode_open_type(uint8_t *buf, int *len, const uint8_t *data, int num_octets) -{ - int enclen; - int octet_idx; - uint8_t zero_byte; - - /* If open type is of zero length, add a single zero byte (10.1) */ - if (num_octets == 0) { - zero_byte = 0; - data = &zero_byte; - num_octets = 1; - } - /* Encode the open type */ - for (octet_idx = 0;; num_octets -= enclen, octet_idx += enclen) { - if ((enclen = encode_length(buf, len, num_octets)) < 0) - return -1; - if (enclen > 0) { - memcpy(&buf[*len], &data[octet_idx], enclen); - *len += enclen; - } - if (enclen >= num_octets) - break; - } - - return 0; -} - -/*- End of function --------------------------------------------------------*/ - -int udptl_rx_packet(udptl_state_t *s, const uint8_t buf[], int len) -{ - int stat; - int stat2; - int i; - int j; - int k; - int l; - int m; - int x; - int limit; - int which; - int ptr; - int count; - int total_count; - int seq_no; - const uint8_t *msg; - const uint8_t *data; - int msg_len; - int repaired[16]; - const uint8_t *bufs[16]; - int lengths[16]; - int span; - int entries; - - ptr = 0; - /* Decode seq_number */ - if (ptr + 2 > len) - return -1; - seq_no = (buf[0] << 8) | buf[1]; - ptr += 2; - /* Break out the primary packet */ - if ((stat = decode_open_type(buf, len, &ptr, &msg, &msg_len)) != 0) - return -1; - /* Decode error_recovery */ - if (ptr + 1 > len) - return -1; - /* Our buffers cannot tolerate overlength packets */ - if (msg_len > LOCAL_FAX_MAX_DATAGRAM) - return -1; - /* Update any missed slots in the buffer */ - for (i = s->rx_seq_no; seq_no > i; i++) { - x = i & UDPTL_BUF_MASK; - s->rx[x].buf_len = -1; - s->rx[x].fec_len[0] = 0; - s->rx[x].fec_span = 0; - s->rx[x].fec_entries = 0; - } - /* Save the new packet. Pure redundancy mode won't use this, but some systems will switch - into FEC mode after sending some redundant packets. */ - x = seq_no & UDPTL_BUF_MASK; - memcpy(s->rx[x].buf, msg, msg_len); - s->rx[x].buf_len = msg_len; - s->rx[x].fec_len[0] = 0; - s->rx[x].fec_span = 0; - s->rx[x].fec_entries = 0; - if ((buf[ptr++] & 0x80) == 0) { - /* Secondary packet mode for error recovery */ - /* We might have the packet we want, but we need to check through - the redundant stuff, and verify the integrity of the UDPTL. - This greatly reduces our chances of accepting garbage. */ - total_count = 0; - do { - if ((stat2 = decode_length(buf, len, &ptr, &count)) < 0) - return -1; - for (i = 0; i < count; i++) { - if ((stat = decode_open_type(buf, len, &ptr, &bufs[total_count + i], &lengths[total_count + i])) != 0) - return -1; - } - total_count += count; - } - while (stat2 > 0); - /* We should now be exactly at the end of the packet. If not, this is a fault. */ - if (ptr != len) - return -1; - if (seq_no > s->rx_seq_no) { - /* We received a later packet than we expected, so we need to check if we can fill in the gap from the - secondary packets. */ - /* Step through in reverse order, so we go oldest to newest */ - for (i = total_count; i > 0; i--) { - if (seq_no - i >= s->rx_seq_no) { - /* This one wasn't seen before */ - /* Decode the secondary packet */ -#if defined(UDPTL_DEBUG) - fprintf(stderr, "Secondary %d, len %d\n", seq_no - i, lengths[i - 1]); -#endif - /* Save the new packet. Redundancy mode won't use this, but some systems will switch into - FEC mode after sending some redundant packets, and this may then be important. */ - x = (seq_no - i) & UDPTL_BUF_MASK; - memcpy(s->rx[x].buf, bufs[i - 1], lengths[i - 1]); - s->rx[x].buf_len = lengths[i - 1]; - s->rx[x].fec_len[0] = 0; - s->rx[x].fec_span = 0; - s->rx[x].fec_entries = 0; - if (s->rx_packet_handler(s->user_data, bufs[i - 1], lengths[i - 1], seq_no - i) < 0) - fprintf(stderr, "Bad IFP\n"); - } - } - } - } else { - /* FEC mode for error recovery */ - - /* Decode the FEC packets */ - /* The span is defined as an unconstrained integer, but will never be more - than a small value. */ - if (ptr + 2 > len) - return -1; - if (buf[ptr++] != 1) - return -1; - span = buf[ptr++]; - - x = seq_no & UDPTL_BUF_MASK; - - s->rx[x].fec_span = span; - - memset(repaired, 0, sizeof(repaired)); - repaired[x] = TRUE; - - /* The number of entries is defined as a length, but will only ever be a small - value. Treat it as such. */ - if (ptr + 1 > len) - return -1; - entries = buf[ptr++]; - s->rx[x].fec_entries = entries; - - /* Decode the elements */ - for (i = 0; i < entries; i++) { - if ((stat = decode_open_type(buf, len, &ptr, &data, &s->rx[x].fec_len[i])) != 0) - return -1; - if (s->rx[x].fec_len[i] > LOCAL_FAX_MAX_DATAGRAM) - return -1; - - /* Save the new FEC data */ - memcpy(s->rx[x].fec[i], data, s->rx[x].fec_len[i]); -#if 0 - fprintf(stderr, "FEC: "); - for (j = 0; j < s->rx[x].fec_len[i]; j++) - fprintf(stderr, "%02X ", data[j]); - fprintf(stderr, "\n"); -#endif - } - /* We should now be exactly at the end of the packet. If not, this is a fault. */ - if (ptr != len) - return -1; - /* See if we can reconstruct anything which is missing */ - /* TODO: this does not comprehensively hunt back and repair everything that is possible */ - for (l = x; l != ((x - (16 - span * entries)) & UDPTL_BUF_MASK); l = (l - 1) & UDPTL_BUF_MASK) { - if (s->rx[l].fec_len[0] <= 0) - continue; - for (m = 0; m < s->rx[l].fec_entries; m++) { - limit = (l + m) & UDPTL_BUF_MASK; - for (which = -1, k = (limit - s->rx[l].fec_span * s->rx[l].fec_entries) & UDPTL_BUF_MASK; k != limit; - k = (k + s->rx[l].fec_entries) & UDPTL_BUF_MASK) { - if (s->rx[k].buf_len <= 0) - which = (which == -1) ? k : -2; - } - if (which >= 0) { - /* Repairable */ - for (j = 0; j < s->rx[l].fec_len[m]; j++) { - s->rx[which].buf[j] = s->rx[l].fec[m][j]; - for (k = (limit - s->rx[l].fec_span * s->rx[l].fec_entries) & UDPTL_BUF_MASK; k != limit; - k = (k + s->rx[l].fec_entries) & UDPTL_BUF_MASK) - s->rx[which].buf[j] ^= (s->rx[k].buf_len > j) ? s->rx[k].buf[j] : 0; - } - s->rx[which].buf_len = s->rx[l].fec_len[m]; - repaired[which] = TRUE; - } - } - } - /* Now play any new packets forwards in time */ - for (l = (x + 1) & UDPTL_BUF_MASK, j = seq_no - UDPTL_BUF_MASK; l != x; l = (l + 1) & UDPTL_BUF_MASK, j++) { - if (repaired[l]) { -#if defined(UDPTL_DEBUG) - fprintf(stderr, "Fixed packet %d, len %d\n", j, l); -#endif - if (s->rx_packet_handler(s->user_data, s->rx[l].buf, s->rx[l].buf_len, j) < 0) - fprintf(stderr, "Bad IFP\n"); - } - } - } - /* If packets are received out of sequence, we may have already processed this packet from the error - recovery information in a packet already received. */ - if (seq_no >= s->rx_seq_no) { - /* Decode the primary packet */ -#if defined(UDPTL_DEBUG) - fprintf(stderr, "Primary packet %d, len %d\n", seq_no, msg_len); -#endif - if (s->rx_packet_handler(s->user_data, msg, msg_len, seq_no) < 0) - fprintf(stderr, "Bad IFP\n"); - } - - s->rx_seq_no = (seq_no + 1) & 0xFFFF; - return 0; -} - -/*- End of function --------------------------------------------------------*/ - -int udptl_build_packet(udptl_state_t *s, uint8_t buf[], const uint8_t msg[], int msg_len) -{ - uint8_t fec[LOCAL_FAX_MAX_DATAGRAM]; - int i; - int j; - int seq; - int entry; - int entries; - int span; - int m; - int len; - int limit; - int high_tide; - - /* UDPTL cannot cope with zero length messages, and our buffering for redundancy limits their - maximum length. */ - if (msg_len < 1 || msg_len > LOCAL_FAX_MAX_DATAGRAM) - return -1; - seq = s->tx_seq_no & 0xFFFF; - - /* Map the sequence number to an entry in the circular buffer */ - entry = seq & UDPTL_BUF_MASK; - - /* We save the message in a circular buffer, for generating FEC or - redundancy sets later on. */ - s->tx[entry].buf_len = msg_len; - memcpy(s->tx[entry].buf, msg, msg_len); - - /* Build the UDPTL packet */ - - len = 0; - /* Encode the sequence number */ - buf[len++] = (seq >> 8) & 0xFF; - buf[len++] = seq & 0xFF; - - /* Encode the primary packet */ - if (encode_open_type(buf, &len, msg, msg_len) < 0) - return -1; - - /* Encode the appropriate type of error recovery information */ - switch (s->error_correction_scheme) { - case UDPTL_ERROR_CORRECTION_NONE: - /* Encode the error recovery type */ - buf[len++] = 0x00; - /* The number of entries will always be zero, so it is pointless allowing - for the fragmented case here. */ - if (encode_length(buf, &len, 0) < 0) - return -1; - break; - case UDPTL_ERROR_CORRECTION_REDUNDANCY: - /* Encode the error recovery type */ - buf[len++] = 0x00; - if (s->tx_seq_no > s->error_correction_entries) - entries = s->error_correction_entries; - else - entries = s->tx_seq_no; - /* The number of entries will always be small, so it is pointless allowing - for the fragmented case here. */ - if (encode_length(buf, &len, entries) < 0) - return -1; - /* Encode the elements */ - for (i = 0; i < entries; i++) { - j = (entry - i - 1) & UDPTL_BUF_MASK; - if (encode_open_type(buf, &len, s->tx[j].buf, s->tx[j].buf_len) < 0) - return -1; - } - break; - case UDPTL_ERROR_CORRECTION_FEC: - span = s->error_correction_span; - entries = s->error_correction_entries; - if (seq < s->error_correction_span * s->error_correction_entries) { - /* In the initial stages, wind up the FEC smoothly */ - entries = seq / s->error_correction_span; - if (seq < s->error_correction_span) - span = 0; - } - /* Encode the error recovery type */ - buf[len++] = 0x80; - /* Span is defined as an inconstrained integer, which it dumb. It will only - ever be a small value. Treat it as such. */ - buf[len++] = 1; - buf[len++] = span; - /* The number of entries is defined as a length, but will only ever be a small - value. Treat it as such. */ - buf[len++] = entries; - for (m = 0; m < entries; m++) { - /* Make an XOR'ed entry the maximum length */ - limit = (entry + m) & UDPTL_BUF_MASK; - high_tide = 0; - for (i = (limit - span * entries) & UDPTL_BUF_MASK; i != limit; i = (i + entries) & UDPTL_BUF_MASK) { - if (high_tide < s->tx[i].buf_len) { - for (j = 0; j < high_tide; j++) - fec[j] ^= s->tx[i].buf[j]; - for (; j < s->tx[i].buf_len; j++) - fec[j] = s->tx[i].buf[j]; - high_tide = s->tx[i].buf_len; - } else { - for (j = 0; j < s->tx[i].buf_len; j++) - fec[j] ^= s->tx[i].buf[j]; - } - } - if (encode_open_type(buf, &len, fec, high_tide) < 0) - return -1; - } - break; - } - - if (s->verbose) - fprintf(stderr, "\n"); - s->tx_seq_no++; - return len; -} - -/*- End of function --------------------------------------------------------*/ - -int udptl_set_error_correction(udptl_state_t *s, int ec_scheme, int span, int entries) -{ - switch (ec_scheme) { - case UDPTL_ERROR_CORRECTION_FEC: - case UDPTL_ERROR_CORRECTION_REDUNDANCY: - case UDPTL_ERROR_CORRECTION_NONE: - s->error_correction_scheme = ec_scheme; - break; - case -1: - /* Just don't change the scheme */ - break; - default: - return -1; - } - if (span >= 0) - s->error_correction_span = span; - if (entries >= 0) - s->error_correction_entries = entries; - return 0; -} - -/*- End of function --------------------------------------------------------*/ - -int udptl_get_error_correction(udptl_state_t *s, int *ec_scheme, int *span, int *entries) -{ - if (ec_scheme) - *ec_scheme = s->error_correction_scheme; - if (span) - *span = s->error_correction_span; - if (entries) - *entries = s->error_correction_entries; - return 0; -} - -/*- End of function --------------------------------------------------------*/ - -int udptl_set_local_max_datagram(udptl_state_t *s, int max_datagram) -{ - s->local_max_datagram_size = max_datagram; - return 0; -} - -/*- End of function --------------------------------------------------------*/ - -int udptl_get_local_max_datagram(udptl_state_t *s) -{ - return s->local_max_datagram_size; -} - -/*- End of function --------------------------------------------------------*/ - -int udptl_set_far_max_datagram(udptl_state_t *s, int max_datagram) -{ - s->far_max_datagram_size = max_datagram; - return 0; -} - -/*- End of function --------------------------------------------------------*/ - -int udptl_get_far_max_datagram(udptl_state_t *s) -{ - return s->far_max_datagram_size; -} - -/*- End of function --------------------------------------------------------*/ - -udptl_state_t *udptl_init(udptl_state_t *s, int ec_scheme, int span, int entries, udptl_rx_packet_handler_t rx_packet_handler, void *user_data) -{ - int i; - - if (rx_packet_handler == NULL) - return NULL; - - if (s == NULL) { - if ((s = (udptl_state_t *) malloc(sizeof(*s))) == NULL) - return NULL; - } - memset(s, 0, sizeof(*s)); - - s->error_correction_scheme = ec_scheme; - s->error_correction_span = span; - s->error_correction_entries = entries; - - s->far_max_datagram_size = LOCAL_FAX_MAX_DATAGRAM; - s->local_max_datagram_size = LOCAL_FAX_MAX_DATAGRAM; - - memset(&s->rx, 0, sizeof(s->rx)); - memset(&s->tx, 0, sizeof(s->tx)); - for (i = 0; i <= UDPTL_BUF_MASK; i++) { - s->rx[i].buf_len = -1; - s->tx[i].buf_len = -1; - } - - s->rx_packet_handler = rx_packet_handler; - s->user_data = user_data; - - return s; -} - -/*- End of function --------------------------------------------------------*/ - -int udptl_release(udptl_state_t *s) -{ - return 0; -} - -/*- End of function --------------------------------------------------------*/ -/*- End of file ------------------------------------------------------------*/ diff --git a/src/mod/applications/mod_fax/udptl.h b/src/mod/applications/mod_fax/udptl.h deleted file mode 100644 index 39740353d1..0000000000 --- a/src/mod/applications/mod_fax/udptl.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2009, Steve Underwood - * - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * Contributor(s): - * - * Steve Underwood - * - * udptl.h -- UDPTL handling for T.38 - * - */ - -#if !defined(FREESWITCH_UDPTL_H) -#define FREESWITCH_UDPTL_H - -#define LOCAL_FAX_MAX_DATAGRAM 400 -#define LOCAL_FAX_MAX_FEC_PACKETS 5 - -#define UDPTL_BUF_MASK 15 - -typedef int (udptl_rx_packet_handler_t) (void *user_data, const uint8_t msg[], int len, int seq_no); - -typedef struct { - int buf_len; - uint8_t buf[LOCAL_FAX_MAX_DATAGRAM]; -} udptl_fec_tx_buffer_t; - -typedef struct { - int buf_len; - uint8_t buf[LOCAL_FAX_MAX_DATAGRAM]; - int fec_len[LOCAL_FAX_MAX_FEC_PACKETS]; - uint8_t fec[LOCAL_FAX_MAX_FEC_PACKETS][LOCAL_FAX_MAX_DATAGRAM]; - int fec_span; - int fec_entries; -} udptl_fec_rx_buffer_t; - -struct udptl_state_s { - udptl_rx_packet_handler_t *rx_packet_handler; - void *user_data; - - /*! This option indicates the error correction scheme used in transmitted UDPTL - packets. */ - int error_correction_scheme; - - /*! This option indicates the number of error correction entries transmitted in - UDPTL packets. */ - int error_correction_entries; - - /*! This option indicates the span of the error correction entries in transmitted - UDPTL packets (FEC only). */ - int error_correction_span; - - /*! This option indicates the maximum size of a datagram that can be accepted by - the remote device. */ - int far_max_datagram_size; - - /*! This option indicates the maximum size of a datagram that we are prepared to - accept. */ - int local_max_datagram_size; - - int verbose; - - int tx_seq_no; - int rx_seq_no; - int rx_expected_seq_no; - - udptl_fec_tx_buffer_t tx[UDPTL_BUF_MASK + 1]; - udptl_fec_rx_buffer_t rx[UDPTL_BUF_MASK + 1]; -}; - -enum { - UDPTL_ERROR_CORRECTION_NONE, - UDPTL_ERROR_CORRECTION_FEC, - UDPTL_ERROR_CORRECTION_REDUNDANCY -}; - -typedef struct udptl_state_s udptl_state_t; - -#if defined(__cplusplus) -extern "C" { -#endif - -/*! \brief Process an arriving UDPTL packet. - \param s The UDPTL context. - \param buf The UDPTL packet buffer. - \param len The length of the packet. - \return 0 for OK. */ - int udptl_rx_packet(udptl_state_t *s, const uint8_t buf[], int len); - -/*! \brief Construct a UDPTL packet, ready for transmission. - \param s The UDPTL context. - \param buf The UDPTL packet buffer. - \param msg The primary packet. - \param len The length of the primary packet. - \return The length of the constructed UDPTL packet. */ - int udptl_build_packet(udptl_state_t *s, uint8_t buf[], const uint8_t msg[], int msg_len); - -/*! \brief Change the error correction settings of a UDPTL context. - \param s The UDPTL context. - \param ec_scheme One of the optional error correction schemes. - \param span The packet span over which error correction should be applied. - \param entries The number of error correction entries to include in packets. - \return 0 for OK. */ - int udptl_set_error_correction(udptl_state_t *s, int ec_scheme, int span, int entries); - -/*! \brief Check the error correction settings of a UDPTL context. - \param s The UDPTL context. - \param ec_scheme One of the optional error correction schemes. - \param span The packet span over which error correction is being applied. - \param entries The number of error correction being included in packets. - \return 0 for OK. */ - int udptl_get_error_correction(udptl_state_t *s, int *ec_scheme, int *span, int *entries); - - int udptl_set_local_max_datagram(udptl_state_t *s, int max_datagram); - - int udptl_get_local_max_datagram(udptl_state_t *s); - - int udptl_set_far_max_datagram(udptl_state_t *s, int max_datagram); - - int udptl_get_far_max_datagram(udptl_state_t *s); - -/*! \brief Initialise a UDPTL context. - \param s The UDPTL context. - \param ec_scheme One of the optional error correction schemes. - \param span The packet span over which error correction should be applied. - \param entries The number of error correction entries to include in packets. - \param rx_packet_handler The callback function, used to report arriving IFP packets. - \param user_data An opaque pointer supplied to rx_packet_handler. - \return A pointer to the UDPTL context, or NULL if there was a problem. */ - udptl_state_t *udptl_init(udptl_state_t *s, int ec_scheme, int span, int entries, udptl_rx_packet_handler_t rx_packet_handler, void *user_data); - -/*! \brief Release a UDPTL context. - \param s The UDPTL context. - \return 0 for OK. */ - int udptl_release(udptl_state_t *s); - -#if defined(__cplusplus) -} -#endif -#endif -/*- End of file ------------------------------------------------------------*/ diff --git a/src/mod/applications/mod_http_cache/mod_http_cache.c b/src/mod/applications/mod_http_cache/mod_http_cache.c index 1e40ce2e15..4e9e892976 100644 --- a/src/mod/applications/mod_http_cache/mod_http_cache.c +++ b/src/mod/applications/mod_http_cache/mod_http_cache.c @@ -23,7 +23,10 @@ * * Contributor(s): * - * Chris Rienzo + * Christopher M. Rienzo + * Darren Schreiber + * + * Maintainer: Christopher M. Rienzo * * mod_http_cache.c -- HTTP GET with caching * -- designed for downloading audio files from a webserver for playback @@ -188,12 +191,29 @@ static void url_cache_clear(url_cache_t *cache, switch_core_session_t *session); static switch_status_t http_put(url_cache_t *cache, switch_core_session_t *session, const char *url, const char *filename) { switch_status_t status = SWITCH_STATUS_SUCCESS; + + switch_curl_slist_t *headers = NULL; /* optional linked-list of HTTP headers */ + char *ext; /* file extension, used for MIME type identification */ + const char *mime_type = "application/octet-stream"; + char *buf; + CURL *curl_handle = NULL; long httpRes = 0; struct stat file_info = {0}; FILE *file_to_put = NULL; int fd; - + + /* guess what type of mime content this is going to be */ + if ((ext = strrchr(filename, '.'))) { + ext++; + if (!(mime_type = switch_core_mime_ext2type(ext))) { + mime_type = "application/octet-stream"; + } + } + + buf = switch_mprintf("Content-Type: %s", mime_type); + headers = switch_curl_slist_append(headers, buf); + /* open file and get the file size */ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "opening %s for upload to %s\n", filename, url); fd = open(filename, O_RDONLY); @@ -224,6 +244,7 @@ static switch_status_t http_put(url_cache_t *cache, switch_core_session_t *sessi switch_curl_easy_setopt(curl_handle, CURLOPT_UPLOAD, 1); switch_curl_easy_setopt(curl_handle, CURLOPT_PUT, 1); switch_curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1); + switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers); switch_curl_easy_setopt(curl_handle, CURLOPT_URL, url); switch_curl_easy_setopt(curl_handle, CURLOPT_READDATA, file_to_put); switch_curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size); @@ -258,6 +279,12 @@ done: fclose(file_to_put); } + if (headers) { + switch_curl_slist_free_all(headers); + } + + switch_safe_free(buf); + return status; } diff --git a/src/mod/applications/mod_redis/credis.c b/src/mod/applications/mod_redis/credis.c index bb71904005..d25756fc3a 100644 --- a/src/mod/applications/mod_redis/credis.c +++ b/src/mod/applications/mod_redis/credis.c @@ -32,6 +32,11 @@ #include #include #include +#ifdef _MSC_VER +#include +#include +#define snprintf _snprintf +#else #include #include #include @@ -39,6 +44,7 @@ #include #include #include +#endif #include #include #include @@ -550,6 +556,7 @@ REDIS credis_connect(const char *host, int port, int timeout) int fd, yes = 1; struct sockaddr_in sa; REDIS rhnd; + int valid = 0; if ((rhnd = cr_new()) == NULL) return NULL; @@ -566,7 +573,16 @@ REDIS credis_connect(const char *host, int port, int timeout) sa.sin_family = AF_INET; sa.sin_port = htons(port); - if (inet_aton(host, &sa.sin_addr) == 0) { +#ifdef WIN32 + sa.sin_addr.S_un.S_addr = inet_addr(host); + if (sa.sin_addr.S_un.S_addr != 0) { + valid = 1; + } +#else + valid = inet_aton(host, &sa.sin_addr); +#endif + + if (valid == 0) { struct hostent *he = gethostbyname(host); if (he == NULL) goto error; diff --git a/src/mod/applications/mod_fax/mod_fax.2008.vcproj b/src/mod/applications/mod_redis/mod_redis.2008.vcproj similarity index 75% rename from src/mod/applications/mod_fax/mod_fax.2008.vcproj rename to src/mod/applications/mod_redis/mod_redis.2008.vcproj index dd10ca8a93..5afc296984 100644 --- a/src/mod/applications/mod_fax/mod_fax.2008.vcproj +++ b/src/mod/applications/mod_redis/mod_redis.2008.vcproj @@ -2,9 +2,9 @@ @@ -23,7 +23,7 @@ Name="Debug|Win32" ConfigurationType="2" InheritedPropertySheets="..\..\..\..\w32\module_debug.vsprops" - CharacterSet="0" + CharacterSet="2" > @@ -84,9 +82,11 @@ @@ -213,9 +209,11 @@ diff --git a/src/mod/applications/mod_redis/mod_redis.2010.vcxproj b/src/mod/applications/mod_redis/mod_redis.2010.vcxproj new file mode 100644 index 0000000000..d5cef0ccbb --- /dev/null +++ b/src/mod/applications/mod_redis/mod_redis.2010.vcxproj @@ -0,0 +1,123 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + mod_redis + {886B5E9D-F2C2-4AF2-98C8-EF98C4C770E6} + mod_redis + Win32Proj + + + + DynamicLibrary + MultiByte + + + DynamicLibrary + MultiByte + + + DynamicLibrary + MultiByte + + + DynamicLibrary + MultiByte + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + + + + + false + + + + + + + X64 + + + + false + + + MachineX64 + + + + + + false + + + + + + + X64 + + + + false + + + MachineX64 + + + + + + + + + {202d7a4e-760d-4d0e-afa1-d7459ced30ff} + false + + + + + + + + + \ No newline at end of file diff --git a/src/mod/applications/mod_spandsp/mod_spandsp.c b/src/mod/applications/mod_spandsp/mod_spandsp.c index c210e02c0e..8cfe9d1e24 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp.c @@ -29,7 +29,7 @@ * Brian West * Steve Underwood * Antonio Gallo - * Christopher M. Rienzo + * Christopher M. Rienzo * mod_spandsp.c -- Module implementing spandsp fax, dsp, and codec functionality * */ diff --git a/src/mod/applications/mod_spandsp/mod_spandsp_dsp.c b/src/mod/applications/mod_spandsp/mod_spandsp_dsp.c index 144d02ef8d..cc4d4964e2 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp_dsp.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp_dsp.c @@ -28,7 +28,7 @@ * Anthony Minessale II * Steve Underwood * Antonio Gallo - * Christopher M. Rienzo + * Christopher M. Rienzo * mod_spandsp_dsp.c -- dsp applications provided by SpanDSP * */ diff --git a/src/mod/applications/mod_voicemail/mod_voicemail.c b/src/mod/applications/mod_voicemail/mod_voicemail.c index 0bbea275d5..d3438aacfc 100644 --- a/src/mod/applications/mod_voicemail/mod_voicemail.c +++ b/src/mod/applications/mod_voicemail/mod_voicemail.c @@ -3489,7 +3489,7 @@ static switch_status_t voicemail_leave_main(switch_core_session_t *session, vm_p switch_safe_free(file_path); - if (switch_channel_ready(channel)) { + if (switch_channel_ready(channel) && vm_enabled) { status = switch_ivr_phrase_macro(session, VM_GOODBYE_MACRO, NULL, NULL, NULL); } diff --git a/src/mod/asr_tts/mod_unimrcp/mod_unimrcp.c b/src/mod/asr_tts/mod_unimrcp/mod_unimrcp.c index 80fa3f2001..aaf8f8764a 100644 --- a/src/mod/asr_tts/mod_unimrcp/mod_unimrcp.c +++ b/src/mod/asr_tts/mod_unimrcp/mod_unimrcp.c @@ -17,7 +17,7 @@ * The Original Code is FreeSWITCH mod_unimrcp * * The Initial Developer of the Original Code is - * Christopher M. Rienzo + * Christopher M. Rienzo * * Portions created by the Initial Developer are Copyright (C) * the Initial Developer. All Rights Reserved. @@ -25,9 +25,11 @@ * Contributor(s): * * Brian West - * Christopher M. Rienzo + * Christopher M. Rienzo * Luke Dashjr (OpenMethods, LLC) * + * Maintainer: Christopher M. Rienzo + * * mod_unimrcp.c -- UniMRCP module (MRCP client) * */ diff --git a/src/mod/codecs/mod_speex/mod_speex.c b/src/mod/codecs/mod_speex/mod_speex.c index ab9a044b53..8416686373 100644 --- a/src/mod/codecs/mod_speex/mod_speex.c +++ b/src/mod/codecs/mod_speex/mod_speex.c @@ -24,7 +24,7 @@ * Contributor(s): * * Anthony Minessale II - * Chris Rienzo + * Christopher M. Rienzo * * * mod_speex.c -- Speex Codec Module diff --git a/src/mod/endpoints/mod_gsmopen/alsa_nogsmlib_nocplusplus/mod_gsmopen/gsmopen.h b/src/mod/endpoints/mod_gsmopen/alsa_nogsmlib_nocplusplus/mod_gsmopen/gsmopen.h index 03c14283b4..01388575b0 100644 --- a/src/mod/endpoints/mod_gsmopen/alsa_nogsmlib_nocplusplus/mod_gsmopen/gsmopen.h +++ b/src/mod/endpoints/mod_gsmopen/alsa_nogsmlib_nocplusplus/mod_gsmopen/gsmopen.h @@ -132,7 +132,7 @@ //#define SAMPLES_PER_FRAME SAMPLERATE_GSMOPEN/50 #ifndef GSMOPEN_SVN_VERSION -#define GSMOPEN_SVN_VERSION SWITCH_VERSION_REVISION +#define GSMOPEN_SVN_VERSION SWITCH_VERSION_FULL #endif /* GSMOPEN_SVN_VERSION */ typedef enum { diff --git a/src/mod/endpoints/mod_gsmopen/gsmopen.h b/src/mod/endpoints/mod_gsmopen/gsmopen.h index 2b4c619783..b5404ae6a9 100644 --- a/src/mod/endpoints/mod_gsmopen/gsmopen.h +++ b/src/mod/endpoints/mod_gsmopen/gsmopen.h @@ -1,6 +1,6 @@ /* * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005/2012, Anthony Minessale II + * Copyright (C) 2005-2011, Anthony Minessale II * * Version: MPL 1.1 * @@ -23,17 +23,15 @@ * * This module (mod_gsmopen) has been contributed by: * - * Giovanni Maruzzelli (gmaruzz@gmail.com) + * Giovanni Maruzzelli * + * Maintainer: Giovanni Maruzzelli * - * Further Contributors: - * - * - * - * mod_gsmopen.c -- GSM compatible Endpoint Module + * mod_gsmopen.cpp -- GSM Modem compatible Endpoint Module * */ + #define __STDC_LIMIT_MACROS #ifdef WIN32 @@ -115,7 +113,7 @@ #endif #ifndef GSMOPEN_SVN_VERSION -#define GSMOPEN_SVN_VERSION SWITCH_VERSION_REVISION +#define GSMOPEN_SVN_VERSION SWITCH_VERSION_FULL #endif /* GSMOPEN_SVN_VERSION */ #include "ctb-0.16/ctb.h" diff --git a/src/mod/endpoints/mod_gsmopen/gsmopen_protocol.cpp b/src/mod/endpoints/mod_gsmopen/gsmopen_protocol.cpp index 391dade93a..ffa4e3d014 100644 --- a/src/mod/endpoints/mod_gsmopen/gsmopen_protocol.cpp +++ b/src/mod/endpoints/mod_gsmopen/gsmopen_protocol.cpp @@ -1,3 +1,39 @@ +/* + * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * Copyright (C) 2005-2011, Anthony Minessale II + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * + * The Initial Developer of the Original Code is + * Anthony Minessale II + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * This module (mod_gsmopen) has been contributed by: + * + * Giovanni Maruzzelli + * + * Maintainer: Giovanni Maruzzelli + * + * gsmopen_protocol.cpp -- Low Level Interface for mod_gamopen + * + */ + + + + #include "gsmopen.h" #ifdef WIN32 #include "win_iconv.c" diff --git a/src/mod/endpoints/mod_gsmopen/mod_gsmopen.cpp b/src/mod/endpoints/mod_gsmopen/mod_gsmopen.cpp index f48d299e0a..837d20ed30 100644 --- a/src/mod/endpoints/mod_gsmopen/mod_gsmopen.cpp +++ b/src/mod/endpoints/mod_gsmopen/mod_gsmopen.cpp @@ -1,6 +1,6 @@ /* * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005/2012, Anthony Minessale II + * Copyright (C) 2005-2011, Anthony Minessale II * * Version: MPL 1.1 * @@ -23,14 +23,11 @@ * * This module (mod_gsmopen) has been contributed by: * - * Giovanni Maruzzelli (gmaruzz@gmail.com) + * Giovanni Maruzzelli * + * Maintainer: Giovanni Maruzzelli * - * Further Contributors: - * - * - * - * mod_gsmopen.c -- GSM compatible Endpoint Module + * mod_gsmopen.cpp -- GSM Modem compatible Endpoint Module * */ diff --git a/src/mod/endpoints/mod_skinny/skinny_server.c b/src/mod/endpoints/mod_skinny/skinny_server.c index 0957739455..95f7e6c83e 100644 --- a/src/mod/endpoints/mod_skinny/skinny_server.c +++ b/src/mod/endpoints/mod_skinny/skinny_server.c @@ -1007,6 +1007,7 @@ switch_status_t skinny_handle_register(listener_t *listener, skinny_message_t *r const char *value = switch_xml_attr_soft(xbutton, "value"); if(type == SKINNY_BUTTON_LINE) { const char *caller_name = switch_xml_attr_soft(xbutton, "caller-name"); + const char *reg_metadata = switch_xml_attr_soft(xbutton, "registration-metadata"); uint32_t ring_on_idle = atoi(switch_xml_attr_soft(xbutton, "ring-on-idle")); uint32_t ring_on_active = atoi(switch_xml_attr_soft(xbutton, "ring-on-active")); uint32_t busy_trigger = atoi(switch_xml_attr_soft(xbutton, "busy-trigger")); @@ -1030,7 +1031,7 @@ switch_status_t skinny_handle_register(listener_t *listener, skinny_message_t *r switch_safe_free(sql); token = switch_mprintf("skinny/%q/%q/%q:%d", profile->name, value, request->data.reg.device_name, request->data.reg.instance); url = switch_mprintf("skinny/%q/%q", profile->name, value); - switch_core_add_registration(value, profile->domain, token, url, 0, network_ip, network_port_c, "tcp"); + switch_core_add_registration(value, profile->domain, token, url, 0, network_ip, network_port_c, "tcp", reg_metadata); switch_safe_free(token); switch_safe_free(url); } diff --git a/src/mod/endpoints/mod_skypopen/mod_skypopen.c b/src/mod/endpoints/mod_skypopen/mod_skypopen.c index 25539fa81e..ce89211b83 100644 --- a/src/mod/endpoints/mod_skypopen/mod_skypopen.c +++ b/src/mod/endpoints/mod_skypopen/mod_skypopen.c @@ -1,6 +1,6 @@ /* * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005-2012, Anthony Minessale II + * Copyright (C) 2005-2011, Anthony Minessale II * * Version: MPL 1.1 * @@ -21,19 +21,17 @@ * Portions created by the Initial Developer are Copyright (C) * the Initial Developer. All Rights Reserved. * - * This module (mod_skypopen) has been contributed by: - * - * Giovanni Maruzzelli (gmaruzz@gmail.com) - * - * - * Further Contributors: + * This module (mod_gsmopen) has been contributed by: * + * Giovanni Maruzzelli * + * Maintainer: Giovanni Maruzzelli * * mod_skypopen.c -- Skype compatible Endpoint Module * */ + #include "skypopen.h" #define SKYPE_CHAT_PROTO "skype" diff --git a/src/mod/endpoints/mod_skypopen/oss/main.c b/src/mod/endpoints/mod_skypopen/oss/main.c index d92d2dc863..897978a2b7 100644 --- a/src/mod/endpoints/mod_skypopen/oss/main.c +++ b/src/mod/endpoints/mod_skypopen/oss/main.c @@ -29,7 +29,6 @@ #include #include -#include /* cli(), *_flags */ #include /* copy_*_user */ #include diff --git a/src/mod/endpoints/mod_skypopen/oss/skypopen.h b/src/mod/endpoints/mod_skypopen/oss/skypopen.h index dca1f8870d..29e32feeca 100644 --- a/src/mod/endpoints/mod_skypopen/oss/skypopen.h +++ b/src/mod/endpoints/mod_skypopen/oss/skypopen.h @@ -21,6 +21,12 @@ #include #include /* needed for the _IOW etc stuff used later */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0) +#include /* cli(), *_flags */ +#else +#include /* cli(), *_flags */ +#endif //LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0) + #if LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 18) #define CENTOS_5 diff --git a/src/mod/endpoints/mod_skypopen/skypopen.h b/src/mod/endpoints/mod_skypopen/skypopen.h index d2dd51bd37..d5f01f85e6 100644 --- a/src/mod/endpoints/mod_skypopen/skypopen.h +++ b/src/mod/endpoints/mod_skypopen/skypopen.h @@ -1,6 +1,6 @@ /* * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005/2012, Anthony Minessale II + * Copyright (C) 2005-2011, Anthony Minessale II * * Version: MPL 1.1 * @@ -21,18 +21,17 @@ * Portions created by the Initial Developer are Copyright (C) * the Initial Developer. All Rights Reserved. * - * This module (mod_skypopen) has been contributed by: + * This module (mod_gsmopen) has been contributed by: * - * Giovanni Maruzzelli (gmaruzz@gmail.com) - * - * - * Further Contributors: + * Giovanni Maruzzelli * + * Maintainer: Giovanni Maruzzelli * * mod_skypopen.c -- Skype compatible Endpoint Module * */ + #include #include @@ -86,7 +85,7 @@ #endif #ifndef SKYPOPEN_SVN_VERSION -#define SKYPOPEN_SVN_VERSION SWITCH_VERSION_REVISION +#define SKYPOPEN_SVN_VERSION SWITCH_VERSION_FULL #endif /* SKYPOPEN_SVN_VERSION */ typedef enum { diff --git a/src/mod/endpoints/mod_skypopen/skypopen_protocol.c b/src/mod/endpoints/mod_skypopen/skypopen_protocol.c index 5aa113c3bf..2126955452 100644 --- a/src/mod/endpoints/mod_skypopen/skypopen_protocol.c +++ b/src/mod/endpoints/mod_skypopen/skypopen_protocol.c @@ -1,3 +1,37 @@ +/* + * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * Copyright (C) 2005-2011, Anthony Minessale II + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * + * The Initial Developer of the Original Code is + * Anthony Minessale II + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * This module (mod_gsmopen) has been contributed by: + * + * Giovanni Maruzzelli + * + * Maintainer: Giovanni Maruzzelli + * + * skypopen_protocol.c -- Low Level Interface for mod_skypopen + * + */ + + #include "skypopen.h" #ifdef ASTERISK diff --git a/src/mod/endpoints/mod_sofia/conf/sofia.conf.xml b/src/mod/endpoints/mod_sofia/conf/sofia.conf.xml index 30d8063a67..39c53d56d4 100644 --- a/src/mod/endpoints/mod_sofia/conf/sofia.conf.xml +++ b/src/mod/endpoints/mod_sofia/conf/sofia.conf.xml @@ -242,6 +242,8 @@ + + - + diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 2b44018665..0f80cda54b 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -1587,6 +1587,8 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi case SWITCH_MESSAGE_INDICATE_BRIDGE: { + + switch_channel_set_variable(channel, SOFIA_REPLACES_HEADER, NULL); sofia_glue_tech_track(tech_pvt->profile, session); sofia_set_flag(tech_pvt, TFLAG_SIMPLIFY); @@ -2337,151 +2339,165 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi break; case SWITCH_MESSAGE_INDICATE_RESPOND: - if (msg->numeric_arg || msg->string_arg) { - int code = msg->numeric_arg; - const char *reason = NULL; + { + int status = 0; - if (code) { - reason = msg->string_arg; - } else { - if (!zstr(msg->string_arg)) { - if ((code = atoi(msg->string_arg))) { - if ((reason = strchr(msg->string_arg, ' '))) { - reason++; - } - } - } + if (tech_pvt->nh && tech_pvt->nh->nh_ds && tech_pvt->nh->nh_ds->ds_sr && nua_server_request_is_pending(tech_pvt->nh->nh_ds->ds_sr)) { + status = tech_pvt->nh->nh_ds->ds_sr->sr_status; } - if (!code) { - code = 488; - } - - if (!switch_channel_test_flag(channel, CF_ANSWERED) && code >= 300) { - if (sofia_test_flag(tech_pvt, TFLAG_BYE)) { - goto end_lock; - } - } - - if (zstr(reason) && code != 407 && code != 302) { - reason = sip_status_phrase(code); - if (zstr(reason)) { - reason = "Because"; - } - } - - if (code == 407 && !msg->numeric_arg) { - const char *to_uri = switch_channel_get_variable(channel, "sip_to_uri"); - const char *to_host = reason; - - if (zstr(to_host)) { - to_host = switch_channel_get_variable(channel, "sip_to_host"); - } - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Challenging call %s\n", to_uri); - sofia_reg_auth_challenge(tech_pvt->profile, tech_pvt->nh, NULL, REG_INVITE, to_host, 0); - switch_channel_hangup(channel, SWITCH_CAUSE_USER_CHALLENGE); - } else if (code == 484 && msg->numeric_arg) { - const char *to = switch_channel_get_variable(channel, "sip_to_uri"); - const char *max_forwards = switch_channel_get_variable(channel, SWITCH_MAX_FORWARDS_VARIABLE); - char *cid = generate_pai_str(tech_pvt); - char *to_uri = NULL; - - if (to) { - char *p; - to_uri = switch_core_session_sprintf(session, "sip:%s", to); - if ((p = strstr(to_uri, ":5060"))) { - *p = '\0'; - } - } - - if (!switch_channel_test_flag(channel, CF_ANSWERED) && !sofia_test_flag(tech_pvt, TFLAG_BYE)) { - char *extra_headers = sofia_glue_get_extra_headers(channel, SOFIA_SIP_RESPONSE_HEADER_PREFIX); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Overlap Dial with %d %s\n", code, reason); - - nua_respond(tech_pvt->nh, code, su_strdup(nua_handle_home(tech_pvt->nh), reason), TAG_IF(to_uri, SIPTAG_CONTACT_STR(to_uri)), - SIPTAG_SUPPORTED_STR(NULL), SIPTAG_ACCEPT_STR(NULL), - TAG_IF(cid, SIPTAG_HEADER_STR(cid)), - TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), - TAG_IF(!zstr(max_forwards), SIPTAG_MAX_FORWARDS_STR(max_forwards)), TAG_END()); - - sofia_set_flag_locked(tech_pvt, TFLAG_BYE); - switch_safe_free(extra_headers); - } - } else if (code == 302 && !zstr(msg->string_arg)) { - char *p; - - if ((p = strchr(msg->string_arg, ' '))) { - *p = '\0'; - msg->string_arg = p; - } - - msg->message_id = SWITCH_MESSAGE_INDICATE_REDIRECT; - switch_core_session_receive_message(session, msg); + if (status == 0 || status > 199 || tech_pvt->nh->nh_destroyed) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s Cannot call respond on handle at status %d\n", + switch_channel_get_name(channel), status); goto end_lock; - } else { - if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) { - char *extra_headers = sofia_glue_get_extra_headers(channel, SOFIA_SIP_PROGRESS_HEADER_PREFIX); - char *sdp = (char *) msg->pointer_arg; - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Responding with %d [%s]\n", code, reason); - sofia_clear_flag(tech_pvt, TFLAG_REINVITED); - - if (!zstr((sdp))) { - if (!strcasecmp(sdp, "t38")) { - switch_t38_options_t *t38_options = switch_channel_get_private(tech_pvt->channel, "t38_options"); - if (t38_options) { - sofia_glue_set_image_sdp(tech_pvt, t38_options, 0); - if (switch_rtp_ready(tech_pvt->rtp_session)) { - sofia_clear_flag(tech_pvt, TFLAG_NOTIMER_DURING_BRIDGE); - switch_rtp_udptl_mode(tech_pvt->rtp_session); - } - } - } else { - sofia_glue_tech_set_local_sdp(tech_pvt, sdp, SWITCH_TRUE); - } - - if (switch_channel_test_flag(channel, CF_PROXY_MEDIA)) { - sofia_glue_tech_patch_sdp(tech_pvt); - sofia_glue_tech_proxy_remote_addr(tech_pvt, NULL); - } - if (sofia_use_soa(tech_pvt)) { - nua_respond(tech_pvt->nh, code, su_strdup(nua_handle_home(tech_pvt->nh), reason), SIPTAG_CONTACT_STR(tech_pvt->reply_contact), - SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), - SOATAG_REUSE_REJECTED(1), - SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), - TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END()); - } else { - nua_respond(tech_pvt->nh, code, su_strdup(nua_handle_home(tech_pvt->nh), reason), SIPTAG_CONTACT_STR(tech_pvt->reply_contact), - NUTAG_MEDIA_ENABLE(0), - SIPTAG_CONTENT_TYPE_STR("application/sdp"), - SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str), - TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END()); - } - if (sofia_test_pflag(tech_pvt->profile, PFLAG_3PCC_PROXY) && sofia_test_flag(tech_pvt, TFLAG_3PCC)) { - /* Unlock the session signal to allow the ack to make it in */ - // Maybe we should timeout? - switch_mutex_unlock(tech_pvt->sofia_mutex); - - while (switch_channel_ready(channel) && !sofia_test_flag(tech_pvt, TFLAG_3PCC_HAS_ACK)) { - switch_cond_next(); - } - - /* Regain lock on sofia */ - switch_mutex_lock(tech_pvt->sofia_mutex); - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "3PCC-PROXY, Done waiting for ACK\n"); - sofia_clear_flag(tech_pvt, TFLAG_3PCC); - sofia_clear_flag(tech_pvt, TFLAG_3PCC_HAS_ACK); - switch_core_session_pass_indication(session, SWITCH_MESSAGE_INDICATE_ANSWER); - } - } else { - nua_respond(tech_pvt->nh, code, su_strdup(nua_handle_home(tech_pvt->nh), reason), SIPTAG_CONTACT_STR(tech_pvt->reply_contact), - TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END()); - } - switch_safe_free(extra_headers); - } } + if (msg->numeric_arg || msg->string_arg) { + int code = msg->numeric_arg; + const char *reason = NULL; + + if (code) { + reason = msg->string_arg; + } else { + if (!zstr(msg->string_arg)) { + if ((code = atoi(msg->string_arg))) { + if ((reason = strchr(msg->string_arg, ' '))) { + reason++; + } + } + } + } + + if (!code) { + code = 488; + } + + if (!switch_channel_test_flag(channel, CF_ANSWERED) && code >= 300) { + if (sofia_test_flag(tech_pvt, TFLAG_BYE)) { + goto end_lock; + } + } + + if (zstr(reason) && code != 407 && code != 302) { + reason = sip_status_phrase(code); + if (zstr(reason)) { + reason = "Because"; + } + } + + if (code == 407 && !msg->numeric_arg) { + const char *to_uri = switch_channel_get_variable(channel, "sip_to_uri"); + const char *to_host = reason; + + if (zstr(to_host)) { + to_host = switch_channel_get_variable(channel, "sip_to_host"); + } + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Challenging call %s\n", to_uri); + sofia_reg_auth_challenge(tech_pvt->profile, tech_pvt->nh, NULL, REG_INVITE, to_host, 0); + switch_channel_hangup(channel, SWITCH_CAUSE_USER_CHALLENGE); + } else if (code == 484 && msg->numeric_arg) { + const char *to = switch_channel_get_variable(channel, "sip_to_uri"); + const char *max_forwards = switch_channel_get_variable(channel, SWITCH_MAX_FORWARDS_VARIABLE); + char *cid = generate_pai_str(tech_pvt); + char *to_uri = NULL; + + if (to) { + char *p; + to_uri = switch_core_session_sprintf(session, "sip:%s", to); + if ((p = strstr(to_uri, ":5060"))) { + *p = '\0'; + } + } + + if (!switch_channel_test_flag(channel, CF_ANSWERED) && !sofia_test_flag(tech_pvt, TFLAG_BYE)) { + char *extra_headers = sofia_glue_get_extra_headers(channel, SOFIA_SIP_RESPONSE_HEADER_PREFIX); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Overlap Dial with %d %s\n", code, reason); + + nua_respond(tech_pvt->nh, code, su_strdup(nua_handle_home(tech_pvt->nh), reason), TAG_IF(to_uri, SIPTAG_CONTACT_STR(to_uri)), + SIPTAG_SUPPORTED_STR(NULL), SIPTAG_ACCEPT_STR(NULL), + TAG_IF(cid, SIPTAG_HEADER_STR(cid)), + TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), + TAG_IF(!zstr(max_forwards), SIPTAG_MAX_FORWARDS_STR(max_forwards)), TAG_END()); + + sofia_set_flag_locked(tech_pvt, TFLAG_BYE); + switch_safe_free(extra_headers); + } + } else if (code == 302 && !zstr(msg->string_arg)) { + char *p; + + if ((p = strchr(msg->string_arg, ' '))) { + *p = '\0'; + msg->string_arg = p; + } + + msg->message_id = SWITCH_MESSAGE_INDICATE_REDIRECT; + switch_core_session_receive_message(session, msg); + goto end_lock; + } else { + if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) { + char *extra_headers = sofia_glue_get_extra_headers(channel, SOFIA_SIP_PROGRESS_HEADER_PREFIX); + char *sdp = (char *) msg->pointer_arg; + + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Responding with %d [%s]\n", code, reason); + sofia_clear_flag(tech_pvt, TFLAG_REINVITED); + + if (!zstr((sdp))) { + if (!strcasecmp(sdp, "t38")) { + switch_t38_options_t *t38_options = switch_channel_get_private(tech_pvt->channel, "t38_options"); + if (t38_options) { + sofia_glue_set_image_sdp(tech_pvt, t38_options, 0); + if (switch_rtp_ready(tech_pvt->rtp_session)) { + sofia_clear_flag(tech_pvt, TFLAG_NOTIMER_DURING_BRIDGE); + switch_rtp_udptl_mode(tech_pvt->rtp_session); + } + } + } else { + sofia_glue_tech_set_local_sdp(tech_pvt, sdp, SWITCH_TRUE); + } + + if (switch_channel_test_flag(channel, CF_PROXY_MEDIA)) { + sofia_glue_tech_patch_sdp(tech_pvt); + sofia_glue_tech_proxy_remote_addr(tech_pvt, NULL); + } + if (sofia_use_soa(tech_pvt)) { + nua_respond(tech_pvt->nh, code, su_strdup(nua_handle_home(tech_pvt->nh), reason), SIPTAG_CONTACT_STR(tech_pvt->reply_contact), + SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), + SOATAG_REUSE_REJECTED(1), + SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), + TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END()); + } else { + nua_respond(tech_pvt->nh, code, su_strdup(nua_handle_home(tech_pvt->nh), reason), SIPTAG_CONTACT_STR(tech_pvt->reply_contact), + NUTAG_MEDIA_ENABLE(0), + SIPTAG_CONTENT_TYPE_STR("application/sdp"), + SIPTAG_PAYLOAD_STR(tech_pvt->local_sdp_str), + TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END()); + } + if (sofia_test_pflag(tech_pvt->profile, PFLAG_3PCC_PROXY) && sofia_test_flag(tech_pvt, TFLAG_3PCC)) { + /* Unlock the session signal to allow the ack to make it in */ + // Maybe we should timeout? + switch_mutex_unlock(tech_pvt->sofia_mutex); + + while (switch_channel_ready(channel) && !sofia_test_flag(tech_pvt, TFLAG_3PCC_HAS_ACK)) { + switch_cond_next(); + } + + /* Regain lock on sofia */ + switch_mutex_lock(tech_pvt->sofia_mutex); + + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "3PCC-PROXY, Done waiting for ACK\n"); + sofia_clear_flag(tech_pvt, TFLAG_3PCC); + sofia_clear_flag(tech_pvt, TFLAG_3PCC_HAS_ACK); + switch_core_session_pass_indication(session, SWITCH_MESSAGE_INDICATE_ANSWER); + } + } else { + nua_respond(tech_pvt->nh, code, su_strdup(nua_handle_home(tech_pvt->nh), reason), SIPTAG_CONTACT_STR(tech_pvt->reply_contact), + TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END()); + } + switch_safe_free(extra_headers); + } + } + + } } break; case SWITCH_MESSAGE_INDICATE_RINGING: @@ -4919,6 +4935,8 @@ static void general_event_handler(switch_event_t *event) const char *body = switch_event_get_body(event); const char *to_uri = switch_event_get_header(event, "to-uri"); const char *from_uri = switch_event_get_header(event, "from-uri"); + const char *extra_headers = switch_event_get_header(event, "extra-headers"); + sofia_profile_t *profile; @@ -4977,7 +4995,8 @@ static void general_event_handler(switch_event_t *event) nua_notify(nh, NUTAG_NEWSUB(1), SIPTAG_SUBSCRIPTION_STATE_STR("terminated;reason=noresource"), TAG_IF(dst->route_uri, NUTAG_PROXY(dst->route_uri)), TAG_IF(dst->route, SIPTAG_ROUTE_STR(dst->route)), - SIPTAG_EVENT_STR(es), TAG_IF(ct, SIPTAG_CONTENT_TYPE_STR(ct)), TAG_IF(!zstr(body), SIPTAG_PAYLOAD_STR(body)), TAG_END()); + SIPTAG_EVENT_STR(es), TAG_IF(ct, SIPTAG_CONTENT_TYPE_STR(ct)), TAG_IF(!zstr(body), SIPTAG_PAYLOAD_STR(body)), + TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END()); switch_safe_free(route_uri); diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 67d513cf27..cc4b08c822 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -28,6 +28,7 @@ * Paul D. Tinsley * Bret McDanel * Marcel Barbulescu + * Raymond Chandler * * * mod_sofia.h -- SOFIA SIP Endpoint @@ -92,7 +93,7 @@ typedef struct private_object private_object_t; #define MULTICAST_EVENT "multicast::event" #define SOFIA_REPLACES_HEADER "_sofia_replaces_" -#define SOFIA_USER_AGENT "FreeSWITCH-mod_sofia/" SWITCH_VERSION_MAJOR "." SWITCH_VERSION_MINOR "." SWITCH_VERSION_MICRO "-" SWITCH_VERSION_REVISION +#define SOFIA_USER_AGENT "FreeSWITCH-mod_sofia/" SWITCH_VERSION_FULL #define SOFIA_CHAT_PROTO "sip" #define SOFIA_MULTIPART_PREFIX "sip_mp_" #define SOFIA_MULTIPART_PREFIX_T "~sip_mp_" @@ -517,7 +518,8 @@ struct sofia_gateway { typedef enum { PRES_TYPE_NONE = 0, PRES_TYPE_FULL = 1, - PRES_TYPE_PASSIVE = 2 + PRES_TYPE_PASSIVE = 2, + PRES_TYPE_PNP = 3 } sofia_presence_type_t; typedef enum { @@ -586,12 +588,15 @@ struct sofia_profile { char *rtcp_audio_interval_msec; char *rtcp_video_interval_msec; char *jb_msec; + char *pnp_prov_url; + char *pnp_notify_profile; sofia_cid_type_t cid_type; sofia_dtmf_t dtmf_type; int auto_restart; switch_port_t sip_port; switch_port_t tls_sip_port; int tls_version; + unsigned int tls_timeout; char *inbound_codec_string; char *outbound_codec_string; int running; @@ -1111,7 +1116,7 @@ switch_status_t reconfig_sofia(sofia_profile_t *profile); void sofia_glue_del_gateway(sofia_gateway_t *gp); void sofia_glue_gateway_list(sofia_profile_t *profile, switch_stream_handle_t *stream, int up); void sofia_glue_del_every_gateway(sofia_profile_t *profile); -void sofia_reg_send_reboot(sofia_profile_t *profile, const char *user, const char *host, const char *contact, const char *user_agent, +void sofia_reg_send_reboot(sofia_profile_t *profile, const char *callid, const char *user, const char *host, const char *contact, const char *user_agent, const char *network_ip); void sofia_glue_restart_all_profiles(void); int sofia_glue_toggle_hold(private_object_t *tech_pvt, int sendonly); diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index dc4fcfb0f0..bcc1acbc73 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -2071,6 +2071,8 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void TPTAG_TLS_VERIFY_SUBJECTS(profile->tls_verify_in_subjects)), TAG_IF(sofia_test_pflag(profile, PFLAG_TLS), TPTAG_TLS_VERSION(profile->tls_version)), + TAG_IF(sofia_test_pflag(profile, PFLAG_TLS) && profile->tls_timeout, + TPTAG_TLS_TIMEOUT(profile->tls_timeout)), TAG_IF(!strchr(profile->sipip, ':'), NTATAG_UDP_MTU(65535)), TAG_IF(sofia_test_pflag(profile, PFLAG_DISABLE_SRV), @@ -2138,6 +2140,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void TAG_IF(profile->pres_type, NUTAG_ALLOW_EVENTS("include-session-description")), TAG_IF(profile->pres_type, NUTAG_ALLOW_EVENTS("presence.winfo")), TAG_IF(profile->pres_type, NUTAG_ALLOW_EVENTS("message-summary")), + TAG_IF(profile->pres_type == PRES_TYPE_PNP, NUTAG_ALLOW_EVENTS("ua-profile")), NUTAG_ALLOW_EVENTS("refer"), SIPTAG_SUPPORTED_STR(supported), SIPTAG_USER_AGENT_STR(profile->user_agent), TAG_END()); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set params for %s\n", profile->name); @@ -2251,7 +2254,11 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void sofia_clear_pflag_locked(profile, PFLAG_SHUTDOWN); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Waiting for worker thread\n"); - switch_thread_join(&st, worker_thread); + if ( worker_thread ) { + switch_thread_join(&st, worker_thread); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERROR: Sofia worker thead failed to start\n"); + } sanity = 4; while (profile->inuse) { @@ -3929,6 +3936,7 @@ switch_status_t config_sofia(int reload, char *profile_name) profile->sip_force_expires = 0; profile->sip_expires_max_deviation = 0; profile->tls_version = 0; + profile->tls_timeout = 300; profile->mflags = MFLAG_REFER | MFLAG_REGISTER; profile->server_rport_level = 1; profile->client_rport_level = 1; @@ -4417,10 +4425,16 @@ switch_status_t config_sofia(int reload, char *profile_name) } else if (!strcasecmp(val, "bypass-media-after-att-xfer")) { profile->media_options |= MEDIA_OPT_BYPASS_AFTER_ATT_XFER; } + } else if (!strcasecmp(var, "pnp-provision-url")) { + profile->pnp_prov_url = switch_core_strdup(profile->pool, val); + } else if (!strcasecmp(var, "pnp-notify-profile")) { + profile->pnp_notify_profile = switch_core_strdup(profile->pool, val); } else if (!strcasecmp(var, "manage-presence")) { if (!strcasecmp(val, "passive")) { profile->pres_type = PRES_TYPE_PASSIVE; + } else if (!strcasecmp(val, "pnp")) { + profile->pres_type = PRES_TYPE_PNP; } else if (switch_true(val)) { profile->pres_type = PRES_TYPE_FULL; } @@ -4743,6 +4757,9 @@ switch_status_t config_sofia(int reload, char *profile_name) } else { profile->tls_version = 0; } + } else if (!strcasecmp(var, "tls-timeout")) { + int v = atoi(val); + profile->tls_timeout = v > 0 ? (unsigned int)v : 300; } else if (!strcasecmp(var, "timer-T1")) { int v = atoi(val); if (v > 0) { @@ -4813,7 +4830,8 @@ switch_status_t config_sofia(int reload, char *profile_name) } } - if (sofia_test_flag(profile, TFLAG_ZRTP_PASSTHRU)) { + if (sofia_test_flag(profile, TFLAG_ZRTP_PASSTHRU) && !sofia_test_flag(profile, TFLAG_LATE_NEGOTIATION)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "ZRTP passthrough implictly enables inbound-late-negotiation\n"); sofia_set_flag(profile, TFLAG_LATE_NEGOTIATION); } @@ -4874,6 +4892,23 @@ switch_status_t config_sofia(int reload, char *profile_name) profile->sipdomain = switch_core_strdup(profile->pool, profile->sipip); } + if (profile->pres_type == PRES_TYPE_PNP) { + if (!profile->pnp_prov_url) { + profile->pnp_prov_url = switch_core_sprintf(profile->pool, "http://%s/provision/", mod_sofia_globals.guess_ip); + } + + if (!profile->pnp_notify_profile) { + profile->pnp_notify_profile = switch_core_strdup(profile->pool, mod_sofia_globals.guess_ip); + } + + if (!profile->extsipip) { + profile->extsipip = switch_core_strdup(profile->pool, mod_sofia_globals.guess_ip); + } + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "we're configured to provision to [%s] on profile [%s]\n", + profile->pnp_prov_url, profile->pnp_notify_profile); + } + config_sofia_profile_urls(profile); if (sofia_test_pflag(profile, PFLAG_TLS) && !profile->tls_cert_dir) { @@ -5815,7 +5850,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, tech_pvt->remote_sdp_str = switch_core_session_strdup(session, r_sdp); switch_channel_set_variable(channel, SWITCH_R_SDP_VARIABLE, r_sdp); - if (sofia_test_flag(tech_pvt, TFLAG_LATE_NEGOTIATION) && (parser = sdp_parse(NULL, r_sdp, (int) strlen(r_sdp), 0))) { + if ((sofia_test_flag(tech_pvt, TFLAG_LATE_NEGOTIATION) || switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) && (parser = sdp_parse(NULL, r_sdp, (int) strlen(r_sdp), 0))) { if ((sdp = sdp_session(parser))) { sofia_glue_set_r_sdp_codec_string(session, sofia_glue_get_codec_string(tech_pvt), sdp); } @@ -6797,6 +6832,9 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t nua_respond(nh, SIP_202_ACCEPTED, NUTAG_WITH_THIS_MSG(de->data->e_msg), SIPTAG_EXPIRES_STR("60"), TAG_END()); + + switch_channel_set_variable(tech_pvt->channel, SOFIA_REPLACES_HEADER, NULL); + if (sip->sip_referred_by) { full_ref_by = sip_header_as_string(home, (void *) sip->sip_referred_by); } @@ -7641,6 +7679,11 @@ void sofia_handle_sip_i_reinvite(switch_core_session_t *session, tagi_t tags[]) { char *call_info = NULL; + switch_channel_t *channel = NULL; + + if (session) { + channel = switch_core_session_get_channel(session); + } if (session && profile && sip && sofia_test_pflag(profile, PFLAG_TRACK_CALLS)) { switch_channel_t *channel = switch_core_session_get_channel(session); @@ -7665,7 +7708,6 @@ void sofia_handle_sip_i_reinvite(switch_core_session_t *session, } if (sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE)) { - switch_channel_t *channel = switch_core_session_get_channel(session); if (channel && sip->sip_call_info) { char *p; if ((call_info = sip_header_as_string(nua_handle_home(nh), (void *) sip->sip_call_info))) { @@ -7679,6 +7721,14 @@ void sofia_handle_sip_i_reinvite(switch_core_session_t *session, } } } + + if (channel) { + if (sip->sip_payload && sip->sip_payload->pl_data) { + switch_channel_set_variable(channel, "sip_reinvite_sdp", sip->sip_payload->pl_data); + } + switch_channel_execute_on(channel, "execute_on_sip_reinvite"); + } + } void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index cb091daf8e..b08d7efc17 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -350,7 +350,7 @@ static void generate_m(private_object_t *tech_pvt, char *buf, size_t buflen, tech_pvt->local_sdp_audio_zrtp_hash); } - if (sr) { + if (!zstr(sr)) { switch_snprintf(buf + strlen(buf), buflen - strlen(buf), "a=%s\n", sr); } } @@ -375,7 +375,7 @@ void sofia_glue_check_dtmf_type(private_object_t *tech_pvt) void sofia_glue_set_local_sdp(private_object_t *tech_pvt, const char *ip, switch_port_t port, const char *sr, int force) { - char buf[2048]; + char buf[65536]; int ptime = 0; uint32_t rate = 0; uint32_t v_port; @@ -434,7 +434,7 @@ void sofia_glue_set_local_sdp(private_object_t *tech_pvt, const char *ip, switch verbose_sdp = 1; } - if (!force && !ip && !sr + if (!force && !ip && zstr(sr) && (switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MODE) || switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MEDIA))) { return; } @@ -465,7 +465,7 @@ void sofia_glue_set_local_sdp(private_object_t *tech_pvt, const char *ip, switch sofia_glue_sdp_map(b_sdp, &map, &ptmap); } - if (!sr) { + if (zstr(sr)) { if ((var_val = switch_channel_get_variable(tech_pvt->channel, "media_audio_mode"))) { sr = var_val; } else { @@ -485,7 +485,9 @@ void sofia_glue_set_local_sdp(private_object_t *tech_pvt, const char *ip, switch if ((tech_pvt->profile->ndlb & PFLAG_NDLB_SENDRECV_IN_SESSION) || ((var_val = switch_channel_get_variable(tech_pvt->channel, "ndlb_sendrecv_in_session")) && switch_true(var_val))) { - switch_snprintf(srbuf, sizeof(srbuf), "a=%s\n", sr); + if (!zstr(sr)) { + switch_snprintf(srbuf, sizeof(srbuf), "a=%s\n", sr); + } sr = NULL; } @@ -554,7 +556,7 @@ void sofia_glue_set_local_sdp(private_object_t *tech_pvt, const char *ip, switch tech_pvt->local_sdp_audio_zrtp_hash); } - if (sr) { + if (!zstr(sr)) { switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=%s\n", sr); } @@ -619,7 +621,7 @@ void sofia_glue_set_local_sdp(private_object_t *tech_pvt, const char *ip, switch cur_ptime = this_ptime; if ((!zstr(tech_pvt->local_crypto_key) && sofia_test_flag(tech_pvt, TFLAG_SECURE))) { - generate_m(tech_pvt, buf, sizeof(buf), port, cur_ptime, append_audio, sr, use_cng, cng_type, map, verbose_sdp, 1); + generate_m(tech_pvt, bp, sizeof(buf) - strlen(buf), port, cur_ptime, append_audio, sr, use_cng, cng_type, map, verbose_sdp, 1); bp = (buf + strlen(buf)); /* asterisk can't handle AVP and SAVP in sep streams, way to blow off the spec....*/ @@ -776,19 +778,23 @@ void sofia_glue_set_local_sdp(private_object_t *tech_pvt, const char *ip, switch const char *sofia_glue_get_codec_string(private_object_t *tech_pvt) { - const char *codec_string = NULL, *preferred = NULL, *fallback = NULL; - - if (switch_channel_direction(tech_pvt->channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { - preferred = tech_pvt->profile->outbound_codec_string; - fallback = tech_pvt->profile->inbound_codec_string; - } else { - preferred = tech_pvt->profile->inbound_codec_string; - fallback = tech_pvt->profile->outbound_codec_string; + const char *preferred = NULL, *fallback = NULL; + + if (!(preferred = switch_channel_get_variable(tech_pvt->channel, "absolute_codec_string"))) { + preferred = switch_channel_get_variable(tech_pvt->channel, "codec_string"); + } + + if (!preferred) { + if (switch_channel_direction(tech_pvt->channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { + preferred = tech_pvt->profile->outbound_codec_string; + fallback = tech_pvt->profile->inbound_codec_string; + } else { + preferred = tech_pvt->profile->inbound_codec_string; + fallback = tech_pvt->profile->outbound_codec_string; + } } - codec_string = !zstr(preferred) ? preferred : fallback; - - return codec_string; + return !zstr(preferred) ? preferred : fallback; } void sofia_glue_tech_prepare_codecs(private_object_t *tech_pvt) @@ -2087,7 +2093,9 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) } - rep = switch_channel_get_variable(channel, SOFIA_REPLACES_HEADER); + if ((rep = switch_channel_get_variable(channel, SOFIA_REPLACES_HEADER))) { + switch_channel_set_variable(channel, SOFIA_REPLACES_HEADER, NULL); + } switch_assert(tech_pvt != NULL); @@ -2590,6 +2598,11 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) tech_pvt->session_refresher = nua_no_refresher; } + if (tech_pvt->local_sdp_str) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, + "Local SDP:\n%s\n", tech_pvt->local_sdp_str); + } + if (sofia_use_soa(tech_pvt)) { nua_invite(tech_pvt->nh, NUTAG_AUTOANSWER(0), @@ -3856,10 +3869,21 @@ static void add_audio_codec(sdp_rtpmap_t *map, int ptime, char *buf, switch_size void sofia_glue_pass_zrtp_hash2(switch_core_session_t *aleg_session, switch_core_session_t *bleg_session) { - switch_channel_t *aleg_channel = switch_core_session_get_channel(aleg_session); - private_object_t *aleg_tech_pvt = switch_core_session_get_private(aleg_session); - switch_channel_t *bleg_channel = switch_core_session_get_channel(bleg_session); - private_object_t *bleg_tech_pvt = switch_core_session_get_private(bleg_session); + switch_channel_t *aleg_channel; + private_object_t *aleg_tech_pvt; + switch_channel_t *bleg_channel; + private_object_t *bleg_tech_pvt; + + if (!switch_core_session_compare(aleg_session, bleg_session)) { + /* since this digs into channel internals its only compatible with sofia sessions*/ + return; + } + + aleg_channel = switch_core_session_get_channel(aleg_session); + aleg_tech_pvt = switch_core_session_get_private(aleg_session); + bleg_channel = switch_core_session_get_channel(bleg_session); + bleg_tech_pvt = switch_core_session_get_private(bleg_session); + switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(aleg_channel), SWITCH_LOG_DEBUG, "Deciding whether to pass zrtp-hash between a-leg and b-leg\n"); if (!(switch_channel_test_flag(aleg_tech_pvt->channel, CF_ZRTP_PASSTHRU_REQ))) { switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(aleg_channel), SWITCH_LOG_DEBUG, "CF_ZRTP_PASSTHRU_REQ not set on a-leg, so not propagating zrtp-hash\n"); @@ -4155,6 +4179,7 @@ int sofia_glue_toggle_hold(private_object_t *tech_pvt, int sendonly) int changed = 0; if (sofia_test_flag(tech_pvt, TFLAG_SLA_BARGE) || sofia_test_flag(tech_pvt, TFLAG_SLA_BARGING)) { + switch_channel_mark_hold(tech_pvt->channel, sendonly); return 0; } @@ -4697,10 +4722,6 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s goto done; } - if (switch_channel_test_app_flag_key("T38", tech_pvt->channel, CF_APP_T38)) { - sofia_set_flag(tech_pvt, TFLAG_NOREPLY); - } - if (switch_true(switch_channel_get_variable(channel, "refuse_t38"))) { switch_channel_clear_app_flag_key("T38", tech_pvt->channel, CF_APP_T38); match = 0; @@ -4709,6 +4730,11 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s const char *var = switch_channel_get_variable(channel, "t38_passthru"); int pass = sofia_test_pflag(tech_pvt->profile, PFLAG_T38_PASSTHRU); + + if (switch_channel_test_app_flag_key("T38", tech_pvt->channel, CF_APP_T38)) { + sofia_set_flag(tech_pvt, TFLAG_NOREPLY); + } + if (var) { if (!(pass = switch_true(var))) { if (!strcasecmp(var, "once")) { diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index 23ae017531..16539aeef4 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -27,6 +27,7 @@ * Ken Rice * Paul D. Tinsley * Bret McDanel + * Raymond Chandler * * * sofia_presence.c -- SOFIA SIP Endpoint (presence code) @@ -537,16 +538,16 @@ static void actual_sofia_presence_mwi_event_handler(switch_event_t *event) sql = switch_mprintf("select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from," "full_via,expires,user_agent,accept,profile_name,network_ip" ",'%q',full_to,network_ip,network_port from sip_subscriptions " - "where hostname='%q' and profile_name='%q' and event='message-summary' " + "where hostname='%q' and event='message-summary' " "and sub_to_user='%q' and (sub_to_host='%q' or presence_hosts like '%%%q%%')", - stream.data, mod_sofia_globals.hostname, profile->name, user, host, host); + stream.data, mod_sofia_globals.hostname, user, host, host); } else if (sub_call_id) { sql = switch_mprintf("select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from," "full_via,expires,user_agent,accept,profile_name,network_ip" ",'%q',full_to,network_ip,network_port from sip_subscriptions where " - "hostname='%q' and profile_name='%q' and event='message-summary' " + "hostname='%q' and event='message-summary' " "and sub_to_user='%q' and (sub_to_host='%q' or presence_hosts like '%%%q%%') and call_id='%q'", - stream.data, mod_sofia_globals.hostname, profile->name, user, host, host, sub_call_id); + stream.data, mod_sofia_globals.hostname, user, host, host, sub_call_id); } @@ -559,12 +560,12 @@ static void actual_sofia_presence_mwi_event_handler(switch_event_t *event) if (for_everyone) { sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,network_ip,'%q',call_id " - "from sip_registrations where hostname='%q' and profile_name='%q' and mwi_user='%q' and mwi_host='%q'", - stream.data, mod_sofia_globals.hostname, profile->name, user, host); + "from sip_registrations where hostname='%q' and mwi_user='%q' and mwi_host='%q'", + stream.data, mod_sofia_globals.hostname, user, host); } else if (call_id) { sql = switch_mprintf("select sip_user,sip_host,contact,profile_name,network_ip,'%q',call_id " - "from sip_registrations where hostname='%q' and profile_name='%q' and call_id='%q'", - stream.data, mod_sofia_globals.hostname, profile->name, call_id); + "from sip_registrations where hostname='%q' and call_id='%q'", + stream.data, mod_sofia_globals.hostname, call_id); } if (sql) { @@ -3273,7 +3274,9 @@ void sofia_presence_handle_sip_i_subscribe(int status, int sent_reply = 0; sip_contact_t const *contact; const char *ipv6; - const char *contact_user; + const char *contact_user = NULL; + const char *contact_host = NULL; + const char *contact_port = NULL; sofia_nat_parse_t np = { { 0 } }; int found_proto = 0; char to_tag[13] = ""; @@ -3295,8 +3298,11 @@ void sofia_presence_handle_sip_i_subscribe(int status, switch_stun_random_string(to_tag, 12, NULL); - //contact_host = sip->sip_contact->m_url->url_host; - contact_user = sip->sip_contact->m_url->url_user; + if ( sip->sip_contact && sip->sip_contact->m_url ) { + contact_host = sip->sip_contact->m_url->url_host; + contact_port = sip->sip_contact->m_url->url_port; + contact_user = sip->sip_contact->m_url->url_user; + } //tl_gets(tags, NUTAG_SUBSTATE_REF(sub_state), TAG_END()); @@ -3645,6 +3651,38 @@ void sofia_presence_handle_sip_i_subscribe(int status, } } + if ( sip->sip_event && sip->sip_event->o_type && !strcasecmp(sip->sip_event->o_type, "ua-profile") && contact_host ) { + switch_event_t *params; + char *uri = NULL; + char *extra_headers = NULL; + + if ( contact_port ) { + uri = switch_mprintf("sip:%s:%s", contact_host, contact_port); + } else { + uri = switch_mprintf("sip:%s", contact_host); + } + + if ( uri ) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "sending pnp NOTIFY to %s\n", uri); + + /* Grandstream REALLY uses a header called Message Body */ + extra_headers = switch_mprintf("MessageBody: %s\r\n", profile->pnp_prov_url); + + switch_event_create(¶ms, SWITCH_EVENT_NOTIFY); + switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "profile", profile->pnp_notify_profile); + switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "event-string", sip->sip_event->o_type); + switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "to-uri", uri); + switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "from-uri", uri); + switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "extra-headers", extra_headers); + switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "content-type", "application/url"); + switch_event_add_body(params, "%s", profile->pnp_prov_url); + switch_event_fire(¶ms); + + switch_safe_free(uri); + switch_safe_free(extra_headers); + } + } + end: if (strcasecmp(event, "call-info") && strcasecmp(event, "line-seize")) { diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index e358c8f228..84367a23f3 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -572,7 +572,7 @@ int sofia_reg_nat_callback(void *pArg, int argc, char **argv, char **columnNames } -void sofia_reg_send_reboot(sofia_profile_t *profile, const char *user, const char *host, const char *contact, const char *user_agent, +void sofia_reg_send_reboot(sofia_profile_t *profile, const char *callid, const char *user, const char *host, const char *contact, const char *user_agent, const char *network_ip) { const char *event = "check-sync"; @@ -587,7 +587,7 @@ void sofia_reg_send_reboot(sofia_profile_t *profile, const char *user, const cha event = "reboot"; } - sofia_glue_send_notify(profile, user, host, event, contenttype, body, contact, network_ip, NULL); + sofia_glue_send_notify(profile, user, host, event, contenttype, body, contact, network_ip, callid); } int sofia_sla_dialog_del_callback(void *pArg, int argc, char **argv, char **columnNames) @@ -608,7 +608,7 @@ int sofia_reg_del_callback(void *pArg, int argc, char **argv, char **columnNames sofia_profile_t *profile = (sofia_profile_t *) pArg; if (argc > 12 && atoi(argv[12]) == 1) { - sofia_reg_send_reboot(profile, argv[1], argv[2], argv[3], argv[7], argv[11]); + sofia_reg_send_reboot(profile, argv[0], argv[1], argv[2], argv[3], argv[7], argv[11]); } if (argc >= 3) { @@ -787,7 +787,7 @@ int sofia_reg_check_callback(void *pArg, int argc, char **argv, char **columnNam { sofia_profile_t *profile = (sofia_profile_t *) pArg; - sofia_reg_send_reboot(profile, argv[1], argv[2], argv[3], argv[7], argv[11]); + sofia_reg_send_reboot(profile, argv[0], argv[1], argv[2], argv[3], argv[7], argv[11]); return 0; } @@ -1028,6 +1028,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand sip_contact_t const *contact = NULL; char *sql; switch_event_t *s_event; + const char *reg_meta = NULL; const char *to_user = NULL; const char *to_host = NULL; char *mwi_account = NULL; @@ -1485,6 +1486,10 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand to_user = var; } + if (v_event && *v_event && (var = switch_event_get_header(*v_event, "registration_metadata"))) { + reg_meta = var; + } + if (v_event && *v_event && (mwi_account = switch_event_get_header(*v_event, "mwi-account"))) { dup_mwi_account = strdup(mwi_account); switch_assert(dup_mwi_account != NULL); @@ -1559,7 +1564,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand url = switch_mprintf("sofia/%q/sip:%q", profile->name, sofia_glue_strip_proto(contact)); switch_core_add_registration(to_user, reg_host, call_id, url, (long) switch_epoch_time_now(NULL) + (long) exptime + 60, - network_ip, network_port_c, is_tls ? "tls" : is_tcp ? "tcp" : "udp"); + network_ip, network_port_c, is_tls ? "tls" : is_tcp ? "tcp" : "udp", reg_meta); switch_safe_free(url); switch_safe_free(contact); @@ -2119,6 +2124,10 @@ void sofia_reg_handle_sip_r_challenge(int status, switch_event_add_header_string(locate_params, SWITCH_STACK_BOTTOM, "action", "reverse-auth-lookup"); + if ( sip->sip_call_id ) { + switch_event_add_header_string(locate_params, SWITCH_STACK_BOTTOM, "sip_call_id", sip->sip_call_id->i_id); + } + if (switch_xml_locate_user_merged("id", sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host, NULL, &x_user, locate_params) == SWITCH_STATUS_SUCCESS) { if ((x_params = switch_xml_child(x_user, "params"))) { diff --git a/src/mod/event_handlers/mod_cdr_mongodb/mod_cdr_mongodb.c b/src/mod/event_handlers/mod_cdr_mongodb/mod_cdr_mongodb.c index 4c8aded61c..35ab4cba2f 100644 --- a/src/mod/event_handlers/mod_cdr_mongodb/mod_cdr_mongodb.c +++ b/src/mod/event_handlers/mod_cdr_mongodb/mod_cdr_mongodb.c @@ -145,7 +145,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) for (ap = app_log; ap; ap = ap->next) { bson_append_start_object(&cdr, "application"); bson_append_string(&cdr, "app_name", ap->app); - bson_append_string(&cdr, "app_data", ap->arg); + bson_append_string(&cdr, "app_data", switch_str_nil(ap->arg)); bson_append_long(&cdr, "app_stamp", ap->stamp); bson_append_finish_object(&cdr); /* application */ } @@ -186,7 +186,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) bson_append_bool(&cdr, "last_executed", 1); } bson_append_string(&cdr, "app_name", ap->application_name); - bson_append_string(&cdr, "app_data", ap->application_data); + bson_append_string(&cdr, "app_data", switch_str_nil(ap->application_data)); bson_append_finish_object(&cdr); } @@ -215,7 +215,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) bson_append_bool(&cdr, "last_executed", 1); } bson_append_string(&cdr, "app_name", ap->application_name); - bson_append_string(&cdr, "app_data", ap->application_data); + bson_append_string(&cdr, "app_data", switch_str_nil(ap->application_data)); bson_append_finish_object(&cdr); } diff --git a/src/mod/event_handlers/mod_erlang_event/handle_msg.c b/src/mod/event_handlers/mod_erlang_event/handle_msg.c index 46e9e67e85..e6d0d7a5f9 100644 --- a/src/mod/event_handlers/mod_erlang_event/handle_msg.c +++ b/src/mod/event_handlers/mod_erlang_event/handle_msg.c @@ -28,6 +28,7 @@ * Rob Charlton * Darren Schreiber * Mike Jerris + * Tamas Cseke * * * handle_msg.c -- handle messages received from erlang nodes @@ -286,6 +287,8 @@ static switch_status_t handle_msg_event(listener_t *listener, int arity, ei_x_bu switch_set_flag_locked(listener, LFLAG_EVENTS); } + switch_thread_rwlock_wrlock(listener->event_rwlock); + for (i = 1; i < arity; i++) { if (!ei_decode_atom(buf->buff, &buf->index, atom)) { @@ -311,6 +314,8 @@ static switch_status_t handle_msg_event(listener_t *listener, int arity, ei_x_bu switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "enable event %s\n", atom); } } + switch_thread_rwlock_unlock(listener->event_rwlock); + ei_x_encode_atom(rbuf, "ok"); } return SWITCH_STATUS_SUCCESS; @@ -332,6 +337,8 @@ static switch_status_t handle_msg_session_event(listener_t *listener, erlang_msg switch_event_types_t type; int i = 0; + switch_thread_rwlock_wrlock(session->event_rwlock); + for (i = 1; i < arity; i++) { if (!ei_decode_atom(buf->buff, &buf->index, atom)) { @@ -357,6 +364,9 @@ static switch_status_t handle_msg_session_event(listener_t *listener, erlang_msg switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "enable event %s for session %s\n", atom, session->uuid_str); } } + + switch_thread_rwlock_unlock(session->event_rwlock); + ei_x_encode_atom(rbuf, "ok"); } else { ei_x_encode_tuple_header(rbuf, 2); @@ -380,10 +390,13 @@ static switch_status_t handle_msg_nixevent(listener_t *listener, int arity, ei_x int i = 0; switch_event_types_t type; + switch_thread_rwlock_wrlock(listener->event_rwlock); + for (i = 1; i < arity; i++) { if (!ei_decode_atom(buf->buff, &buf->index, atom)) { if (custom) { + switch_core_hash_delete(listener->event_hash, atom); } else if (switch_name_event(atom, &type) == SWITCH_STATUS_SUCCESS) { uint32_t x = 0; @@ -406,6 +419,8 @@ static switch_status_t handle_msg_nixevent(listener_t *listener, int arity, ei_x } } } + + switch_thread_rwlock_unlock(listener->event_rwlock); ei_x_encode_atom(rbuf, "ok"); } return SWITCH_STATUS_SUCCESS; @@ -426,6 +441,8 @@ static switch_status_t handle_msg_session_nixevent(listener_t *listener, erlang_ int i = 0; switch_event_types_t type; + switch_thread_rwlock_wrlock(session->event_rwlock); + for (i = 1; i < arity; i++) { if (!ei_decode_atom(buf->buff, &buf->index, atom)) { @@ -452,6 +469,8 @@ static switch_status_t handle_msg_session_nixevent(listener_t *listener, erlang_ } } } + switch_thread_rwlock_unlock(session->event_rwlock); + ei_x_encode_atom(rbuf, "ok"); } else { /* no session for this pid */ ei_x_encode_tuple_header(rbuf, 2); @@ -481,7 +500,7 @@ static switch_status_t handle_msg_setevent(listener_t *listener, erlang_msg *msg int i = 0; /* clear any previous event registrations */ - for( x = 0; x <= SWITCH_EVENT_ALL; x++){ + for(x = 0; x <= SWITCH_EVENT_ALL; x++) { event_list[x] = 0; } @@ -515,10 +534,11 @@ static switch_status_t handle_msg_setevent(listener_t *listener, erlang_msg *msg } } /* update the event subscriptions with the new ones */ + switch_thread_rwlock_wrlock(listener->event_rwlock); memcpy(listener->event_list, event_list, sizeof(uint8_t) * (SWITCH_EVENT_ALL + 1)); - /* wipe the old hash, and point the pointer at the new one */ switch_core_hash_destroy(&listener->event_hash); listener->event_hash = event_hash; + switch_thread_rwlock_unlock(listener->event_rwlock); /* TODO - we should flush any non-matching events from the queue */ ei_x_encode_atom(rbuf, "ok"); @@ -573,11 +593,15 @@ static switch_status_t handle_msg_session_setevent(listener_t *listener, erlang_ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "enable event %s for session %s\n", atom, session->uuid_str); } } + /* update the event subscriptions with the new ones */ + switch_thread_rwlock_wrlock(session->event_rwlock); memcpy(session->event_list, event_list, sizeof(uint8_t) * (SWITCH_EVENT_ALL + 1)); /* wipe the old hash, and point the pointer at the new one */ switch_core_hash_destroy(&session->event_hash); session->event_hash = event_hash; + switch_thread_rwlock_unlock(session->event_rwlock); + /* TODO - we should flush any non-matching events from the queue */ ei_x_encode_atom(rbuf, "ok"); } else { /* no session for this pid */ @@ -601,13 +625,13 @@ static switch_status_t handle_msg_api(listener_t *listener, erlang_msg * msg, in fail = SWITCH_TRUE; } - ei_get_type(buf->buff, &buf->index, &type, &size); + ei_get_type(buf->buff, &buf->index, &type, &size); if ((size > (sizeof(api_cmd) - 1)) || ei_decode_atom(buf->buff, &buf->index, api_cmd)) { fail = SWITCH_TRUE; } - ei_get_type(buf->buff, &buf->index, &type, &size); + ei_get_type(buf->buff, &buf->index, &type, &size); arg = malloc(size + 1); if (ei_decode_string(buf->buff, &buf->index, arg)) { @@ -706,29 +730,29 @@ static switch_status_t handle_msg_sendevent(listener_t *listener, int arity, ei_ while (!ei_decode_tuple_header(buf->buff, &buf->index, &arity) && arity == 2) { i++; - ei_get_type(buf->buff, &buf->index, &type, &size); + ei_get_type(buf->buff, &buf->index, &type, &size); if ((size > (sizeof(key) - 1)) || ei_decode_string(buf->buff, &buf->index, key)) { fail = SWITCH_TRUE; break; } - ei_get_type(buf->buff, &buf->index, &type, &size); - value = malloc(size + 1); + ei_get_type(buf->buff, &buf->index, &type, &size); + value = malloc(size + 1); if (ei_decode_string(buf->buff, &buf->index, value)) { fail = SWITCH_TRUE; break; } - if (!fail && !strcmp(key, "body")) { - switch_safe_free(event->body); - event->body = value; - } else if (!fail) { - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM | SWITCH_STACK_NODUP, key, value); - } - - /* Do not free malloc here! The above commands utilize the raw allocated memory and skip any copying/duplication. Faster. */ + if (!fail && !strcmp(key, "body")) { + switch_safe_free(event->body); + event->body = value; + } else if (!fail) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM | SWITCH_STACK_NODUP, key, value); + } + + /* Do not free malloc here! The above commands utilize the raw allocated memory and skip any copying/duplication. Faster. */ } if (headerlength != i || fail) { @@ -763,30 +787,30 @@ static switch_status_t handle_msg_sendmsg(listener_t *listener, int arity, ei_x_ char key[1024]; char *value; - int type; - int size; + int type; + int size; int i = 0; switch_bool_t fail = SWITCH_FALSE; while (!ei_decode_tuple_header(buf->buff, &buf->index, &arity) && arity == 2) { i++; - ei_get_type(buf->buff, &buf->index, &type, &size); + ei_get_type(buf->buff, &buf->index, &type, &size); if ((size > (sizeof(key) - 1)) || ei_decode_string(buf->buff, &buf->index, key)) { fail = SWITCH_TRUE; break; } - - ei_get_type(buf->buff, &buf->index, &type, &size); - value = malloc(size + 1); + + ei_get_type(buf->buff, &buf->index, &type, &size); + value = malloc(size + 1); if (ei_decode_string(buf->buff, &buf->index, value)) { - fail = SWITCH_TRUE; + fail = SWITCH_TRUE; break; } if (!fail) { - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM | SWITCH_STACK_NODUP, key, value); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM | SWITCH_STACK_NODUP, key, value); } } @@ -794,6 +818,7 @@ static switch_status_t handle_msg_sendmsg(listener_t *listener, int arity, ei_x_ ei_x_encode_tuple_header(rbuf, 2); ei_x_encode_atom(rbuf, "error"); ei_x_encode_atom(rbuf, "badarg"); + switch_event_destroy(&event); } else { if (switch_core_session_queue_private_event(session, &event, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) { ei_x_encode_atom(rbuf, "ok"); @@ -801,6 +826,7 @@ static switch_status_t handle_msg_sendmsg(listener_t *listener, int arity, ei_x_ ei_x_encode_tuple_header(rbuf, 2); ei_x_encode_atom(rbuf, "error"); ei_x_encode_atom(rbuf, "badmem"); + switch_event_destroy(&event); } } @@ -1020,12 +1046,15 @@ static switch_status_t handle_msg_atom(listener_t *listener, erlang_msg * msg, e if (switch_test_flag(listener, LFLAG_EVENTS)) { uint8_t x = 0; switch_clear_flag_locked(listener, LFLAG_EVENTS); + + switch_thread_rwlock_wrlock(listener->event_rwlock); for (x = 0; x <= SWITCH_EVENT_ALL; x++) { listener->event_list[x] = 0; } - /* wipe the hash */ - switch_core_hash_destroy(&listener->event_hash); - switch_core_hash_init(&listener->event_hash, listener->pool); + + switch_core_hash_delete_multi(listener->event_hash, NULL, NULL); + + switch_thread_rwlock_unlock(listener->event_rwlock); ei_x_encode_atom(rbuf, "ok"); } else { ei_x_encode_tuple_header(rbuf, 2); @@ -1040,12 +1069,15 @@ static switch_status_t handle_msg_atom(listener_t *listener, erlang_msg * msg, e /*purge the event queue */ while (switch_queue_trypop(session->event_queue, &pop) == SWITCH_STATUS_SUCCESS); + + switch_thread_rwlock_wrlock(session->event_rwlock); for (x = 0; x <= SWITCH_EVENT_ALL; x++) { session->event_list[x] = 0; } /* wipe the hash */ - switch_core_hash_destroy(&session->event_hash); - switch_core_hash_init(&session->event_hash, session->pool); + switch_core_hash_delete_multi(session->event_hash, NULL, NULL); + switch_thread_rwlock_unlock(session->event_rwlock); + ei_x_encode_atom(rbuf, "ok"); } else { ei_x_encode_tuple_header(rbuf, 2); @@ -1076,13 +1108,14 @@ static switch_status_t handle_msg_atom(listener_t *listener, erlang_msg * msg, e static switch_status_t handle_ref_tuple(listener_t *listener, erlang_msg * msg, ei_x_buff * buf, ei_x_buff * rbuf) { erlang_ref ref; - erlang_pid *pid; + erlang_pid pid; char hash[100]; int arity; const void *key; void *val; session_elem_t *se; switch_hash_index_t *iter; + int found = 0; ei_decode_tuple_header(buf->buff, &buf->index, &arity); @@ -1091,15 +1124,7 @@ static switch_status_t handle_ref_tuple(listener_t *listener, erlang_msg * msg, return SWITCH_STATUS_FALSE; } - if (!(pid = malloc(sizeof(erlang_pid)))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error\n"); - ei_x_encode_tuple_header(rbuf, 2); - ei_x_encode_atom(rbuf, "error"); - ei_x_encode_atom(rbuf, "badmem"); - return SWITCH_STATUS_SUCCESS; - } - - if (ei_decode_pid(buf->buff, &buf->index, pid)) { + if (ei_decode_pid(buf->buff, &buf->index, &pid)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid pid in a reference/pid tuple\n"); return SWITCH_STATUS_FALSE; } @@ -1113,32 +1138,32 @@ static switch_status_t handle_ref_tuple(listener_t *listener, erlang_msg * msg, switch_hash_this(iter, &key, NULL, &val); se = (session_elem_t*)val; if (se->spawn_reply && !strncmp(se->spawn_reply->hash, hash, 100)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "found matching session for %s : %s\n", hash, se->uuid_str); - switch_mutex_lock(se->spawn_reply->mutex); - if (se->spawn_reply->state == reply_not_ready) { - switch_thread_cond_wait(se->spawn_reply->ready_or_found, se->spawn_reply->mutex); - } - if (se->spawn_reply->state == reply_waiting) { - se->spawn_reply->pid = pid; - switch_thread_cond_signal(se->spawn_reply->ready_or_found); - ei_x_encode_atom(rbuf, "ok"); - switch_thread_rwlock_unlock(listener->session_rwlock); - switch_mutex_unlock(se->spawn_reply->mutex); - return SWITCH_STATUS_SUCCESS; - } + switch_mutex_lock(se->spawn_reply->mutex); + + se->spawn_reply->pid = switch_core_alloc(se->pool, sizeof(erlang_pid)); + switch_assert(se->spawn_reply->pid != NULL); + memcpy(se->spawn_reply->pid, &pid, sizeof(erlang_pid)); + switch_thread_cond_signal(se->spawn_reply->ready_or_found); + switch_mutex_unlock(se->spawn_reply->mutex); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "get_pid came in too late for %s; %s\n", hash, se->uuid_str); + + found++; + break; } } switch_thread_rwlock_unlock(listener->session_rwlock); - ei_x_encode_tuple_header(rbuf, 2); - ei_x_encode_atom(rbuf, "error"); - ei_x_encode_atom(rbuf, "notfound"); - - switch_safe_free(pid); /* don't need it */ + if (found) { + ei_x_encode_atom(rbuf, "ok"); + } else { + ei_x_encode_tuple_header(rbuf, 2); + ei_x_encode_atom(rbuf, "error"); + ei_x_encode_atom(rbuf, "notfound"); + } return SWITCH_STATUS_SUCCESS; } @@ -1240,6 +1265,7 @@ int handle_msg(listener_t *listener, erlang_msg * msg, ei_x_buff * buf, ei_x_buf buf->index = 0; ei_decode_version(buf->buff, &buf->index, &version); ei_get_type(buf->buff, &buf->index, &type, &size); + switch (type) { case ERL_SMALL_TUPLE_EXT: case ERL_LARGE_TUPLE_EXT: @@ -1288,11 +1314,8 @@ int handle_msg(listener_t *listener, erlang_msg * msg, ei_x_buff * buf, ei_x_buf #ifdef EI_DEBUG ei_x_print_msg(rbuf, &msg->from, 1); #endif + return SWITCH_STATUS_SUCCESS != ret; - if (SWITCH_STATUS_SUCCESS == ret) - return 0; - else /* SWITCH_STATUS_TERM */ - return 1; } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Empty reply, supressing\n"); return 0; diff --git a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c index 12cf01a650..b8e13b2a5c 100644 --- a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c +++ b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c @@ -26,6 +26,7 @@ * Anthony Minessale II * Andrew Thompson * Rob Charlton + * Tamas Cseke * * * mod_erlang_event.c -- Erlang Event Handler derived from mod_event_socket @@ -44,6 +45,7 @@ SWITCH_MODULE_DEFINITION(mod_erlang_event, mod_erlang_event_load, mod_erlang_eve static switch_memory_pool_t *module_pool = NULL; static void remove_listener(listener_t *listener); +static void destroy_listener(listener_t *listener); static switch_status_t state_handler(switch_core_session_t *session); SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_pref_ip, prefs.ip); @@ -53,12 +55,15 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_pref_nodename, prefs.nodename); static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj); static void launch_listener_thread(listener_t *listener); +session_elem_t *find_session_elem_by_uuid(listener_t *listener, const char *uuid); + static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_level_t level) { listener_t *l; switch_thread_rwlock_rdlock(globals.listener_rwlock); for (l = listen_list.listeners; l; l = l->next) { + if (switch_test_flag(l, LFLAG_LOG) && l->level >= node->level) { switch_log_node_t *dnode = switch_log_node_dup(node); @@ -79,6 +84,7 @@ static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_l l->lost_logs++; } } + } switch_thread_rwlock_unlock(globals.listener_rwlock); @@ -131,12 +137,11 @@ static void send_event_to_attached_sessions(listener_t *listener, switch_event_t return; } - switch_thread_rwlock_rdlock(listener->session_rwlock); - s = (session_elem_t*)switch_core_hash_find(listener->sessions, uuid); - switch_thread_rwlock_unlock(listener->session_rwlock); - - if (s) { + if ((s = (session_elem_t*)find_session_elem_by_uuid(listener, uuid))) { int send = 0; + + switch_thread_rwlock_rdlock(s->event_rwlock); + if (s->event_list[SWITCH_EVENT_ALL]) { send = 1; } else if ((s->event_list[event->event_id])) { @@ -145,6 +150,8 @@ static void send_event_to_attached_sessions(listener_t *listener, switch_event_t } } + switch_thread_rwlock_unlock(s->event_rwlock); + if (send) { switch_log_printf(SWITCH_CHANNEL_UUID_LOG(s->uuid_str), SWITCH_LOG_DEBUG, "Sending event %s to attached session %s\n", switch_event_name(event->event_id), s->uuid_str); @@ -161,7 +168,9 @@ static void send_event_to_attached_sessions(listener_t *listener, switch_event_t switch_log_printf(SWITCH_CHANNEL_UUID_LOG(s->uuid_str), SWITCH_LOG_DEBUG, "Ignoring event %s for attached session %s\n", switch_event_name(event->event_id), s->uuid_str); } + switch_thread_rwlock_unlock(s->rwlock); } + } static void event_handler(switch_event_t *event) @@ -175,9 +184,10 @@ static void event_handler(switch_event_t *event) return; } + switch_thread_rwlock_rdlock(globals.listener_rwlock); + lp = listen_list.listeners; - switch_thread_rwlock_rdlock(globals.listener_rwlock); while (lp) { uint8_t send = 0; @@ -194,6 +204,8 @@ static void event_handler(switch_event_t *event) continue; } + switch_thread_rwlock_rdlock(l->event_rwlock); + if (l->event_list[SWITCH_EVENT_ALL]) { send = 1; } else if ((l->event_list[event->event_id])) { @@ -202,6 +214,7 @@ static void event_handler(switch_event_t *event) } } + switch_thread_rwlock_unlock(l->event_rwlock); if (send) { if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) { @@ -251,7 +264,7 @@ static void close_socket(int *sock) static void add_listener(listener_t *listener) { - /* add me to the listeners so I get events */ + /* add me to the listeners so I get events */ switch_thread_rwlock_wrlock(globals.listener_rwlock); listener->next = listen_list.listeners; listen_list.listeners = listener; @@ -277,7 +290,7 @@ static void remove_listener(listener_t *listener) switch_thread_rwlock_unlock(globals.listener_rwlock); } -/* Search for a listener already talking to the specified node */ +/* Search for a listener already talking to the specified node and lock for reading*/ static listener_t *find_listener(char *nodename) { listener_t *l = NULL; @@ -285,6 +298,7 @@ static listener_t *find_listener(char *nodename) switch_thread_rwlock_rdlock(globals.listener_rwlock); for (l = listen_list.listeners; l; l = l->next) { if (!strncmp(nodename, l->peer_nodename, MAXNODELEN)) { + switch_thread_rwlock_rdlock(l->rwlock); break; } } @@ -303,28 +317,42 @@ static void add_session_elem_to_listener(listener_t *listener, session_elem_t *s static void remove_session_elem_from_listener(listener_t *listener, session_elem_t *session_element) { + switch_thread_rwlock_wrlock(listener->session_rwlock); switch_core_hash_delete(listener->sessions, session_element->uuid_str); + switch_thread_rwlock_unlock(listener->session_rwlock); } static void destroy_session_elem(session_elem_t *session_element) { switch_core_session_t *session; + /* wait for readers */ + switch_thread_rwlock_wrlock(session_element->rwlock); + switch_thread_rwlock_unlock(session_element->rwlock); + if ((session = switch_core_session_locate(session_element->uuid_str))) { - switch_channel_clear_flag(switch_core_session_get_channel(session), CF_CONTROLLED); + switch_channel_t *channel = switch_core_session_get_channel(session); + + switch_channel_set_private(channel, "_erlang_session_", NULL); + switch_channel_clear_flag(channel, CF_CONTROLLED); switch_core_session_rwunlock(session); } switch_core_destroy_memory_pool(&session_element->pool); - /*switch_safe_free(s); */ } -static void remove_session_elem_from_listener_locked(listener_t *listener, session_elem_t *session_element) +session_elem_t *find_session_elem_by_uuid(listener_t *listener, const char *uuid) { - switch_thread_rwlock_wrlock(listener->session_rwlock); - remove_session_elem_from_listener(listener, session_element); - switch_thread_rwlock_unlock(listener->session_rwlock); -} + session_elem_t *session = NULL; + + switch_thread_rwlock_rdlock(listener->session_rwlock); + if ((session = (session_elem_t*)switch_core_hash_find(listener->sessions, uuid))) { + switch_thread_rwlock_rdlock(session->rwlock); + } + switch_thread_rwlock_unlock(listener->session_rwlock); + + return session; + } session_elem_t *find_session_elem_by_pid(listener_t *listener, erlang_pid *pid) { @@ -336,15 +364,16 @@ session_elem_t *find_session_elem_by_pid(listener_t *listener, erlang_pid *pid) switch_thread_rwlock_rdlock(listener->session_rwlock); for (iter = switch_hash_first(NULL, listener->sessions); iter; iter = switch_hash_next(iter)) { switch_hash_this(iter, &key, NULL, &val); - session = (session_elem_t*)val; - if (session->process.type == ERLANG_PID && !ei_compare_pids(pid, &session->process.pid)) { - switch_thread_rwlock_unlock(listener->session_rwlock); - return session; + + if (((session_elem_t*)val)->process.type == ERLANG_PID && !ei_compare_pids(pid, &((session_elem_t*)val)->process.pid)) { + session = (session_elem_t*)val; + switch_thread_rwlock_rdlock(session->rwlock); + break; } } switch_thread_rwlock_unlock(listener->session_rwlock); - return NULL; + return session; } @@ -362,6 +391,7 @@ static switch_xml_t erlang_fetch(const char *sectionstr, const char *tag_name, c switch_xml_t xml = NULL; ei_x_buff *rep; ei_x_buff buf; + ei_x_new_with_version(&buf); switch_uuid_get(&uuid); @@ -403,6 +433,7 @@ static switch_xml_t erlang_fetch(const char *sectionstr, const char *tag_name, c /* Create a new fetch object. */ p = malloc(sizeof(*p)); switch_thread_cond_create(&p->ready_or_found, module_pool); + /* TODO module pool */ switch_mutex_init(&p->mutex, SWITCH_MUTEX_UNNESTED, module_pool); p->state = reply_not_ready; p->reply = NULL; @@ -430,8 +461,7 @@ static switch_xml_t erlang_fetch(const char *sectionstr, const char *tag_name, c /* Tell the threads to be ready, and wait five seconds for a reply. */ switch_mutex_lock(p->mutex); //p->state = reply_waiting; - switch_thread_cond_timedwait(p->ready_or_found, - p->mutex, 5000000); + switch_thread_cond_timedwait(p->ready_or_found, p->mutex, 5000000); if (!p->reply) { p->state = reply_timeout; switch_mutex_unlock(p->mutex); @@ -508,6 +538,7 @@ static switch_status_t notify_new_session(listener_t *listener, session_elem_t * if (!(session = switch_core_session_locate(session_element->uuid_str))) { switch_log_printf(SWITCH_CHANNEL_UUID_LOG(session_element->uuid_str), SWITCH_LOG_WARNING, "Can't locate session %s\n", session_element->uuid_str); + switch_event_destroy(&call_event); return SWITCH_STATUS_FALSE; } @@ -516,6 +547,7 @@ static switch_status_t notify_new_session(listener_t *listener, session_elem_t * switch_caller_profile_event_set_data(switch_channel_get_caller_profile(channel), "Channel", call_event); switch_channel_event_set_data(channel, call_event); switch_core_session_rwunlock(session); + /* TODO reply? sure? */ switch_event_add_header_string(call_event, SWITCH_STACK_BOTTOM, "Content-Type", "command/reply"); switch_event_add_header_string(call_event, SWITCH_STACK_BOTTOM, "Reply-Text", "+OK\n"); @@ -551,6 +583,7 @@ static switch_status_t check_attached_sessions(listener_t *listener) /* event used to track sessions to remove */ switch_event_t *event = NULL; switch_event_header_t *header = NULL; + switch_event_create_subclass(&event, SWITCH_EVENT_CLONE, NULL); switch_assert(event); /* check up on all the attached sessions - @@ -558,6 +591,8 @@ static switch_status_t check_attached_sessions(listener_t *listener) if they have pending events in their queues then send them if the session has finished then clean it up */ + + /* TODO try to minimize critical section */ switch_thread_rwlock_rdlock(listener->session_rwlock); for (iter = switch_hash_first(NULL, listener->sessions); iter; iter = switch_hash_next(iter)) { switch_hash_this(iter, &key, NULL, &value); @@ -574,7 +609,7 @@ static switch_status_t check_attached_sessions(listener_t *listener) switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "delete", (const char *) key); continue; } - switch_set_flag(sp, LFLAG_OUTBOUND_INIT); + switch_set_flag_locked(sp, LFLAG_OUTBOUND_INIT); } if (switch_test_flag(sp, LFLAG_SESSION_COMPLETE)) { @@ -640,18 +675,16 @@ static switch_status_t check_attached_sessions(listener_t *listener) } } switch_thread_rwlock_unlock(listener->session_rwlock); - /* release the read lock and get a write lock */ - switch_thread_rwlock_wrlock(listener->session_rwlock); + /* do the deferred remove */ for (header = event->headers; header; header = header->next) { - if ((sp = (session_elem_t*)switch_core_hash_find(listener->sessions, header->value))) { + if ((sp = (session_elem_t*)find_session_elem_by_uuid(listener, header->value))) { remove_session_elem_from_listener(listener, sp); + switch_thread_rwlock_unlock(sp->rwlock); destroy_session_elem(sp); } } - switch_thread_rwlock_unlock(listener->session_rwlock); - /* remove the temporary event */ switch_event_destroy(&event); @@ -749,29 +782,32 @@ static void handle_exit(listener_t *listener, erlang_pid * pid) session_elem_t *s; remove_binding(NULL, pid); /* TODO - why don't we pass the listener as the first argument? */ - if ((s = find_session_elem_by_pid(listener, pid))) { - if (s->channel_state < CS_HANGUP) { - switch_core_session_t *session; - switch_log_printf(SWITCH_CHANNEL_UUID_LOG(s->uuid_str), SWITCH_LOG_WARNING, "Outbound session for %s exited unexpectedly!\n", s->uuid_str); - if ((session = switch_core_session_locate(s->uuid_str))) { - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_channel_set_private(channel, "_erlang_session_", NULL); - switch_channel_set_private(channel, "_erlang_listener_", NULL); - switch_core_event_hook_remove_state_change(session, state_handler); - switch_core_session_rwunlock(session); + if ((s = find_session_elem_by_pid(listener, pid))) { + switch_core_session_t *session = NULL; + + if ((session = switch_core_session_locate(s->uuid_str))) { + switch_channel_t *channel = switch_core_session_get_channel(session); + + if (switch_channel_get_state(channel) < CS_HANGUP) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Outbound session exited unexpectedly %s!\n", s->uuid_str); } - /* TODO - if a spawned process that was handling an outbound call fails.. what do we do with the call? */ + + switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); + switch_core_session_rwunlock(session); } - remove_session_elem_from_listener_locked(listener, s); - destroy_session_elem(s); + + switch_thread_rwlock_unlock(s->rwlock); + } + if (listener->log_process.type == ERLANG_PID && !ei_compare_pids(&listener->log_process.pid, pid)) { void *pop; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Log handler process for node %s exited\n", pid->node); /*purge the log queue */ + /* TODO don't we want to clear flag first? */ while (switch_queue_trypop(listener->log_queue, &pop) == SWITCH_STATUS_SUCCESS) { switch_log_node_t *dnode = (switch_log_node_t *) pop; switch_log_node_free(&dnode); @@ -787,6 +823,7 @@ static void handle_exit(listener_t *listener, erlang_pid * pid) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Event handler process for node %s exited\n", pid->node); /*purge the event queue */ + /* TODO don't we want to clear flag first? */ while (switch_queue_trypop(listener->event_queue, &pop) == SWITCH_STATUS_SUCCESS) { switch_event_t *pevent = (switch_event_t *) pop; switch_event_destroy(&pevent); @@ -795,12 +832,13 @@ static void handle_exit(listener_t *listener, erlang_pid * pid) if (switch_test_flag(listener, LFLAG_EVENTS)) { uint8_t x = 0; switch_clear_flag_locked(listener, LFLAG_EVENTS); + + switch_thread_rwlock_wrlock(listener->event_rwlock); for (x = 0; x <= SWITCH_EVENT_ALL; x++) { listener->event_list[x] = 0; } - /* wipe the hash */ - switch_core_hash_destroy(&listener->event_hash); - switch_core_hash_init(&listener->event_hash, listener->pool); + switch_core_hash_delete_multi(listener->event_hash, NULL, NULL); + switch_thread_rwlock_unlock(listener->event_rwlock); } } } @@ -865,6 +903,7 @@ static void listener_main_loop(listener_t *listener) case ERL_EXIT: switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "erl_exit from %s <%d.%d.%d>\n", msg.from.node, msg.from.creation, msg.from.num, msg.from.serial); + handle_exit(listener, &msg.from); break; default: @@ -874,7 +913,7 @@ static void listener_main_loop(listener_t *listener) break; case ERL_ERROR: if (erl_errno != ETIMEDOUT && erl_errno != EAGAIN) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "erl_error\n"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "erl_error: status=%d, erl_errno=%d errno=%d\n", status, erl_errno, errno); } break; default: @@ -892,6 +931,11 @@ static void listener_main_loop(listener_t *listener) return; } } + if (prefs.done) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "shutting down listener\n"); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "listener exit: status=%d, erl_errno=%d errno=%d\n", status, erl_errno, errno); + } } static switch_bool_t check_inbound_acl(listener_t *listener) @@ -941,10 +985,6 @@ static switch_bool_t check_inbound_acl(listener_t *listener) static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj) { listener_t *listener = (listener_t *) obj; - session_elem_t *s; - const void *key; - void *value; - switch_hash_index_t *iter; switch_mutex_lock(globals.listener_count_mutex); prefs.threads++; @@ -963,38 +1003,10 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj) listener_main_loop(listener); } - /* clean up */ - remove_listener(listener); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Session complete, waiting for children\n"); - - switch_thread_rwlock_wrlock(listener->rwlock); - - if (listener->sockfd) { - close_socket(&listener->sockfd); - } - - switch_thread_rwlock_unlock(listener->rwlock); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connection Closed\n"); - switch_core_hash_destroy(&listener->event_hash); - /* remove any bindings for this connection */ - remove_binding(listener, NULL); - - /* clean up all the attached sessions */ - switch_thread_rwlock_wrlock(listener->session_rwlock); - for (iter = switch_hash_first(NULL, listener->sessions); iter; iter = switch_hash_next(iter)) { - switch_hash_this(iter, &key, NULL, &value); - s = (session_elem_t*)value; - destroy_session_elem(s); - } - switch_thread_rwlock_unlock(listener->session_rwlock); - - if (listener->pool) { - switch_memory_pool_t *pool = listener->pool; - switch_core_destroy_memory_pool(&pool); - } + remove_listener(listener); + destroy_listener(listener); switch_mutex_lock(globals.listener_count_mutex); prefs.threads--; @@ -1156,43 +1168,46 @@ static int config(void) return 0; } - static listener_t *new_listener(struct ei_cnode_s *ec, int clientfd) { - switch_memory_pool_t *listener_pool = NULL; + switch_memory_pool_t *pool = NULL; listener_t *listener = NULL; - if (switch_core_new_memory_pool(&listener_pool) != SWITCH_STATUS_SUCCESS) { + if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "OH OH no pool\n"); return NULL; } - if (!(listener = switch_core_alloc(listener_pool, sizeof(*listener)))) { + if (!(listener = switch_core_alloc(pool, sizeof(*listener)))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error\n"); + switch_core_destroy_memory_pool(&pool); return NULL; } memset(listener, 0, sizeof(*listener)); - switch_thread_rwlock_create(&listener->rwlock, listener_pool); - switch_queue_create(&listener->event_queue, SWITCH_CORE_QUEUE_LEN, listener_pool); - switch_queue_create(&listener->log_queue, SWITCH_CORE_QUEUE_LEN, listener_pool); + switch_queue_create(&listener->event_queue, SWITCH_CORE_QUEUE_LEN, pool); + switch_queue_create(&listener->log_queue, SWITCH_CORE_QUEUE_LEN, pool); listener->sockfd = clientfd; - listener->pool = listener_pool; - listener_pool = NULL; + listener->pool = pool; listener->ec = switch_core_alloc(listener->pool, sizeof(ei_cnode)); memcpy(listener->ec, ec, sizeof(ei_cnode)); listener->level = SWITCH_LOG_DEBUG; switch_mutex_init(&listener->flag_mutex, SWITCH_MUTEX_NESTED, listener->pool); switch_mutex_init(&listener->sock_mutex, SWITCH_MUTEX_NESTED, listener->pool); + + switch_thread_rwlock_create(&listener->rwlock, pool); + switch_thread_rwlock_create(&listener->event_rwlock, pool); switch_thread_rwlock_create(&listener->session_rwlock, listener->pool); + switch_core_hash_init(&listener->event_hash, listener->pool); switch_core_hash_init(&listener->sessions, listener->pool); return listener; } -static listener_t *new_outbound_listener(char *node) + +static listener_t *new_outbound_listener_locked(char *node) { listener_t *listener = NULL; struct ei_cnode_s ec; @@ -1206,27 +1221,67 @@ static listener_t *new_outbound_listener(char *node) #endif if ((clientfd = ei_connect(&ec, node)) < 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error connecting to node %s (erl_errno=%d, errno=%d)!\n", node, erl_errno, errno); + return NULL; } listener = new_listener(&ec, clientfd); listener->peer_nodename = switch_core_strdup(listener->pool, node); } + + switch_thread_rwlock_rdlock(listener->rwlock); + return listener; } +void destroy_listener(listener_t * listener) +{ + session_elem_t *s = NULL; + const void *key; + void *value; + switch_hash_index_t *iter; + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Session complete, waiting for children\n"); + switch_thread_rwlock_wrlock(listener->rwlock); + + if (listener->sockfd) { + close_socket(&listener->sockfd); + } + + switch_core_hash_destroy(&listener->event_hash); + + /* remove any bindings for this connection */ + remove_binding(listener, NULL); + + /* clean up all the attached sessions */ + switch_thread_rwlock_wrlock(listener->session_rwlock); + for (iter = switch_hash_first(NULL, listener->sessions); iter; iter = switch_hash_next(iter)) { + switch_hash_this(iter, &key, NULL, &value); + s = (session_elem_t*)value; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Orphaning call %s\n", s->uuid_str); + destroy_session_elem(s); + } + switch_thread_rwlock_unlock(listener->session_rwlock); + switch_thread_rwlock_unlock(listener->rwlock); + + if (listener->pool) { + switch_memory_pool_t *pool = listener->pool; + switch_core_destroy_memory_pool(&pool); + } + +} + static switch_status_t state_handler(switch_core_session_t *session) { switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_state_t state = switch_channel_get_state(channel); session_elem_t *session_element = switch_channel_get_private(channel, "_erlang_session_"); - /*listener_t* listener = switch_channel_get_private(channel, "_erlang_listener_"); */ if (session_element) { session_element->channel_state = state; if (state == CS_DESTROY) { /* indicate that once all the events in the event queue are done * we can throw this away */ - switch_set_flag(session_element, LFLAG_SESSION_COMPLETE); + switch_set_flag_locked(session_element, LFLAG_SESSION_COMPLETE); } } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "unable to update channel state for %s to %s\n", switch_core_session_get_uuid(session), @@ -1266,10 +1321,12 @@ session_elem_t *session_elem_create(listener_t *listener, switch_core_session_t session_element->event_list[x] = 0; } + switch_thread_rwlock_create(&session_element->rwlock, session_element->pool); + switch_thread_rwlock_create(&session_element->event_rwlock, session_element->pool); + session_element->event_list[SWITCH_EVENT_ALL] = 1; /* defaults to everything */ switch_channel_set_private(channel, "_erlang_session_", session_element); - switch_channel_set_private(channel, "_erlang_listener_", listener); switch_core_event_hook_add_state_change(session, state_handler); @@ -1298,6 +1355,7 @@ session_elem_t *attach_call_to_pid(listener_t *listener, erlang_pid * pid, switc memcpy(&session_element->process.pid, pid, sizeof(erlang_pid)); /* attach the session to the listener */ add_session_elem_to_listener(listener, session_element); + /* TODO link before added to listener? */ ei_link(listener, ei_self(listener->ec), pid); return session_element; @@ -1308,30 +1366,27 @@ session_elem_t *attach_call_to_spawned_process(listener_t *listener, char *modul /* create a session list element */ session_elem_t *session_element = session_elem_create(listener, session); char hash[100]; - //void *p = NULL; spawn_reply_t *p; erlang_ref ref; - switch_set_flag(session_element, LFLAG_WAITING_FOR_PID); - - /* attach the session to the listener */ - add_session_elem_to_listener(listener, session_element); ei_init_ref(listener->ec, &ref); ei_hash_ref(&ref, hash); - /* insert the waiting marker */ p = switch_core_alloc(session_element->pool, sizeof(*p)); switch_thread_cond_create(&p->ready_or_found, session_element->pool); switch_mutex_init(&p->mutex, SWITCH_MUTEX_UNNESTED, session_element->pool); - p->state = reply_not_ready; - p->hash = hash; + p->hash = switch_core_strdup(session_element->pool, hash); p->pid = NULL; session_element->spawn_reply = p; - switch_mutex_lock(p->mutex); - p->state = reply_waiting; + /* insert the waiting marker */ + switch_set_flag(session_element, LFLAG_WAITING_FOR_PID); + + /* attach the session to the listener */ + add_session_elem_to_listener(listener, session_element); + if (!strcmp(function, "!")) { /* send a message to request a pid */ @@ -1361,13 +1416,12 @@ session_elem_t *attach_call_to_spawned_process(listener_t *listener, char *modul */ } - switch_thread_cond_timedwait(p->ready_or_found, - p->mutex, 5000000); + switch_thread_cond_timedwait(p->ready_or_found, p->mutex, 5000000); if (!p->pid) { - p->state = reply_timeout; + switch_channel_t *channel = switch_core_session_get_channel(session); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Timed out when waiting for outbound pid %s %s\n", hash, session_element->uuid_str); - remove_session_elem_from_listener_locked(listener, session_element); - destroy_session_elem(session_element); + switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); return NULL; } @@ -1377,13 +1431,10 @@ session_elem_t *attach_call_to_spawned_process(listener_t *listener, char *modul memcpy(&session_element->process.pid, p->pid, sizeof(erlang_pid)); session_element->spawn_reply = NULL; - switch_clear_flag(session_element, LFLAG_OUTBOUND_INIT); - switch_clear_flag(session_element, LFLAG_WAITING_FOR_PID); + switch_clear_flag_locked(session_element, LFLAG_WAITING_FOR_PID); ei_link(listener, ei_self(listener->ec), &session_element->process.pid); - switch_safe_free(p->pid); - return session_element; } @@ -1414,7 +1465,6 @@ SWITCH_STANDARD_APP(erlang_outbound_function) char *argv[80] = { 0 }, *argv2[80] = { 0 }; char *mydata, *myarg; char uuid[SWITCH_UUID_FORMATTED_LENGTH + 1]; - switch_bool_t new_session = SWITCH_FALSE; session_elem_t *session_element = NULL; /* process app arguments */ @@ -1460,17 +1510,15 @@ SWITCH_STANDARD_APP(erlang_outbound_function) /* if there is no listener, then create one */ if (!listener) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Creating new listener for session\n"); - new_session = SWITCH_TRUE; - listener = new_outbound_listener(node); + if ((listener = new_outbound_listener_locked(node))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Launching new listener\n"); + launch_listener_thread(listener); + } } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Using existing listener for session\n"); } if (listener) { - if (new_session == SWITCH_TRUE) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Launching new listener\n"); - launch_listener_thread(listener); - } if (module && function) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Creating new spawned session for listener\n"); @@ -1480,11 +1528,16 @@ SWITCH_STANDARD_APP(erlang_outbound_function) session_element = attach_call_to_registered_process(listener, reg_name, session); } + switch_thread_rwlock_unlock(listener->rwlock); + if (session_element) { switch_ivr_park(session, NULL); } + } else { + switch_thread_rwlock_unlock(globals.listener_rwlock); } + switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid), SWITCH_LOG_DEBUG, "exit erlang_outbound_function\n"); } @@ -1523,13 +1576,15 @@ SWITCH_STANDARD_APP(erlang_sendmsg_function) listener = find_listener(node); if (!listener) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Creating new listener for sendmsg %s\n", node); - listener = new_outbound_listener(node); + listener = new_outbound_listener_locked(node); } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Using existing listener for sendmsg to %s\n", node); } if (listener) { ei_reg_send(listener->ec, listener->sockfd, reg_name, buf.buff, buf.index); + + switch_thread_rwlock_unlock(listener->rwlock); } } @@ -1598,11 +1653,11 @@ SWITCH_STANDARD_API(erlang_cmd) stream->write_function(stream, "Outbound session for %s in state %s\n", sp->uuid_str, switch_channel_state_name(sp->channel_state)); } + switch_thread_rwlock_unlock(l->session_rwlock); if (empty) { stream->write_function(stream, "No active sessions for %s\n", argv[1]); } - switch_thread_rwlock_unlock(l->session_rwlock); break; } } diff --git a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h index 1721d496fb..c1730b5dba 100644 --- a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h +++ b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h @@ -39,7 +39,8 @@ typedef enum { } session_flag_t; typedef enum { - ERLANG_PID = 0, + NONE = 0, + ERLANG_PID, ERLANG_REG_PROCESS } process_type; @@ -70,7 +71,6 @@ struct spawn_reply_struct { switch_thread_cond_t *ready_or_found; switch_mutex_t *mutex; - enum reply_state state; erlang_pid *pid; char *hash; }; @@ -82,6 +82,8 @@ struct session_elem { uint32_t flags; struct erlang_process process; switch_queue_t *event_queue; + switch_thread_rwlock_t *rwlock; + switch_thread_rwlock_t *event_rwlock; switch_channel_state_t channel_state; switch_memory_pool_t *pool; uint8_t event_list[SWITCH_EVENT_ALL + 1]; @@ -128,6 +130,7 @@ struct listener { uint8_t event_list[SWITCH_EVENT_ALL + 1]; switch_hash_t *event_hash; switch_thread_rwlock_t *rwlock; + switch_thread_rwlock_t *event_rwlock; switch_thread_rwlock_t *session_rwlock; //session_elem_t *session_list; switch_hash_t *sessions; diff --git a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c index d71a6fa70e..c2862d8ab2 100644 --- a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c +++ b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c @@ -1185,7 +1185,7 @@ static switch_status_t read_packet(listener_t *listener, switch_event_t **event, } count++; if (count == 1) { - switch_event_create(event, SWITCH_EVENT_SOCKET_DATA); + switch_event_create(event, SWITCH_EVENT_CLONE); switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "Command", mbuf); } else if (cur) { char *var, *val; diff --git a/src/mod/languages/mod_java/src/org/freeswitch/swig/EventConsumer.java b/src/mod/languages/mod_java/src/org/freeswitch/swig/EventConsumer.java index 4fecb81e00..07c051c074 100644 --- a/src/mod/languages/mod_java/src/org/freeswitch/swig/EventConsumer.java +++ b/src/mod/languages/mod_java/src/org/freeswitch/swig/EventConsumer.java @@ -91,8 +91,8 @@ public class EventConsumer { return new SWIGTYPE_p_uint32_t(freeswitchJNI.EventConsumer_node_index_get(swigCPtr, this), true); } - public EventConsumer(String event_name, String subclass_name) { - this(freeswitchJNI.new_EventConsumer(event_name, subclass_name), true); + public EventConsumer(String event_name, String subclass_name, int len) { + this(freeswitchJNI.new_EventConsumer(event_name, subclass_name, len), true); } public int bind(String event_name, String subclass_name) { diff --git a/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java b/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java index b574831098..40f856cb41 100644 --- a/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java +++ b/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java @@ -81,7 +81,7 @@ class freeswitchJNI { public final static native long EventConsumer_enodes_get(long jarg1, EventConsumer jarg1_); public final static native void EventConsumer_node_index_set(long jarg1, EventConsumer jarg1_, long jarg2); public final static native long EventConsumer_node_index_get(long jarg1, EventConsumer jarg1_); - public final static native long new_EventConsumer(String jarg1, String jarg2); + public final static native long new_EventConsumer(String jarg1, String jarg2, int jarg3); public final static native void delete_EventConsumer(long jarg1); public final static native int EventConsumer_bind(long jarg1, EventConsumer jarg1_, String jarg2, String jarg3); public final static native long EventConsumer_pop(long jarg1, EventConsumer jarg1_, int jarg2, int jarg3); diff --git a/src/mod/languages/mod_java/switch_swig_wrap.cpp b/src/mod/languages/mod_java/switch_swig_wrap.cpp index c34420ea96..93499b61ab 100644 --- a/src/mod/languages/mod_java/switch_swig_wrap.cpp +++ b/src/mod/languages/mod_java/switch_swig_wrap.cpp @@ -1587,10 +1587,11 @@ SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_EventConsumer_1n } -SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_new_1EventConsumer(JNIEnv *jenv, jclass jcls, jstring jarg1, jstring jarg2) { +SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_new_1EventConsumer(JNIEnv *jenv, jclass jcls, jstring jarg1, jstring jarg2, jint jarg3) { jlong jresult = 0 ; char *arg1 = (char *) NULL ; char *arg2 = (char *) "" ; + int arg3 = (int) 5000 ; EventConsumer *result = 0 ; (void)jenv; @@ -1605,7 +1606,8 @@ SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_new_1EventConsum arg2 = (char *)jenv->GetStringUTFChars(jarg2, 0); if (!arg2) return 0; } - result = (EventConsumer *)new EventConsumer((char const *)arg1,(char const *)arg2); + arg3 = (int)jarg3; + result = (EventConsumer *)new EventConsumer((char const *)arg1,(char const *)arg2,arg3); *(EventConsumer **)&jresult = result; if (arg1) jenv->ReleaseStringUTFChars(jarg1, (const char *)arg1); if (arg2) jenv->ReleaseStringUTFChars(jarg2, (const char *)arg2); diff --git a/src/mod/languages/mod_lua/mod_lua_wrap.cpp b/src/mod/languages/mod_lua/mod_lua_wrap.cpp index 3019c81083..679b852a81 100644 --- a/src/mod/languages/mod_lua/mod_lua_wrap.cpp +++ b/src/mod/languages/mod_lua/mod_lua_wrap.cpp @@ -3705,18 +3705,23 @@ static int _wrap_new_EventConsumer(lua_State* L) { int SWIG_arg = -1; char *arg1 = (char *) NULL ; char *arg2 = (char *) "" ; + int arg3 = (int) 5000 ; EventConsumer *result = 0 ; - SWIG_check_num_args("EventConsumer",0,2) + SWIG_check_num_args("EventConsumer",0,3) if(lua_gettop(L)>=1 && !lua_isstring(L,1)) SWIG_fail_arg("EventConsumer",1,"char const *"); if(lua_gettop(L)>=2 && !lua_isstring(L,2)) SWIG_fail_arg("EventConsumer",2,"char const *"); + if(lua_gettop(L)>=3 && !lua_isnumber(L,3)) SWIG_fail_arg("EventConsumer",3,"int"); if(lua_gettop(L)>=1){ arg1 = (char *)lua_tostring(L, 1); } if(lua_gettop(L)>=2){ arg2 = (char *)lua_tostring(L, 2); } - result = (EventConsumer *)new EventConsumer((char const *)arg1,(char const *)arg2); + if(lua_gettop(L)>=3){ + arg3 = (int)lua_tonumber(L, 3); + } + result = (EventConsumer *)new EventConsumer((char const *)arg1,(char const *)arg2,arg3); SWIG_arg=0; SWIG_NewPointerObj(L,result,SWIGTYPE_p_EventConsumer,1); SWIG_arg++; return SWIG_arg; diff --git a/src/mod/languages/mod_managed/freeswitch_wrap.2010.cxx b/src/mod/languages/mod_managed/freeswitch_wrap.2010.cxx index 65b4eedf3c..a11d584f49 100644 --- a/src/mod/languages/mod_managed/freeswitch_wrap.2010.cxx +++ b/src/mod/languages/mod_managed/freeswitch_wrap.2010.cxx @@ -1550,6 +1550,16 @@ SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_SIGNAL_BOND_VARIABLE_get() { } +SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_ORIGINATE_SIGNAL_BOND_VARIABLE_get() { + char * jresult ; + char *result = 0 ; + + result = (char *)("originate_signal_bond"); + jresult = SWIG_csharp_string_callback((const char *)result); + return jresult; +} + + SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_ORIGINATOR_VARIABLE_get() { char * jresult ; char *result = 0 ; @@ -11108,7 +11118,7 @@ SWIGEXPORT unsigned long SWIGSTDCALL CSharp_switch_default_ptime(char * jarg1, u } -SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_add_registration(char * jarg1, char * jarg2, char * jarg3, char * jarg4, unsigned long jarg5, char * jarg6, char * jarg7, char * jarg8) { +SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_add_registration(char * jarg1, char * jarg2, char * jarg3, char * jarg4, unsigned long jarg5, char * jarg6, char * jarg7, char * jarg8, char * jarg9) { int jresult ; char *arg1 = (char *) 0 ; char *arg2 = (char *) 0 ; @@ -11118,6 +11128,7 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_add_registration(char * jarg1, cha char *arg6 = (char *) 0 ; char *arg7 = (char *) 0 ; char *arg8 = (char *) 0 ; + char *arg9 = (char *) 0 ; switch_status_t result; arg1 = (char *)jarg1; @@ -11128,7 +11139,8 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_add_registration(char * jarg1, cha arg6 = (char *)jarg6; arg7 = (char *)jarg7; arg8 = (char *)jarg8; - result = (switch_status_t)switch_core_add_registration((char const *)arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4,arg5,(char const *)arg6,(char const *)arg7,(char const *)arg8); + arg9 = (char *)jarg9; + result = (switch_status_t)switch_core_add_registration((char const *)arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4,arg5,(char const *)arg6,(char const *)arg7,(char const *)arg8,(char const *)arg9); jresult = result; return jresult; } @@ -25772,6 +25784,18 @@ SWIGEXPORT void SWIGSTDCALL CSharp_switch_channel_transfer_to_extension(void * j } +SWIGEXPORT char * SWIGSTDCALL CSharp_switch_channel_get_partner_uuid(void * jarg1) { + char * jresult ; + switch_channel_t *arg1 = (switch_channel_t *) 0 ; + char *result = 0 ; + + arg1 = (switch_channel_t *)jarg1; + result = (char *)switch_channel_get_partner_uuid(arg1); + jresult = SWIG_csharp_string_callback((const char *)result); + return jresult; +} + + SWIGEXPORT int SWIGSTDCALL CSharp_switch_buffer_create(void * jarg1, void * jarg2, void * jarg3) { int jresult ; switch_memory_pool_t *arg1 = (switch_memory_pool_t *) 0 ; diff --git a/src/mod/languages/mod_managed/freeswitch_wrap.cxx b/src/mod/languages/mod_managed/freeswitch_wrap.cxx index 33feeaee11..46fcf757e6 100644 --- a/src/mod/languages/mod_managed/freeswitch_wrap.cxx +++ b/src/mod/languages/mod_managed/freeswitch_wrap.cxx @@ -1663,6 +1663,17 @@ SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_SIGNAL_BOND_VARIABLE_get() { } +SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_ORIGINATE_SIGNAL_BOND_VARIABLE_get() { + char * jresult ; + char *result = 0 ; + + result = (char *) "originate_signal_bond"; + + jresult = SWIG_csharp_string_callback((const char *)result); + return jresult; +} + + SWIGEXPORT char * SWIGSTDCALL CSharp_SWITCH_ORIGINATOR_VARIABLE_get() { char * jresult ; char *result = 0 ; @@ -11427,7 +11438,7 @@ SWIGEXPORT unsigned long SWIGSTDCALL CSharp_switch_default_ptime(char * jarg1, u } -SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_add_registration(char * jarg1, char * jarg2, char * jarg3, char * jarg4, unsigned long jarg5, char * jarg6, char * jarg7, char * jarg8) { +SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_add_registration(char * jarg1, char * jarg2, char * jarg3, char * jarg4, unsigned long jarg5, char * jarg6, char * jarg7, char * jarg8, char * jarg9) { int jresult ; char *arg1 = (char *) 0 ; char *arg2 = (char *) 0 ; @@ -11437,6 +11448,7 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_add_registration(char * jarg1, cha char *arg6 = (char *) 0 ; char *arg7 = (char *) 0 ; char *arg8 = (char *) 0 ; + char *arg9 = (char *) 0 ; switch_status_t result; arg1 = (char *)jarg1; @@ -11447,7 +11459,8 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_core_add_registration(char * jarg1, cha arg6 = (char *)jarg6; arg7 = (char *)jarg7; arg8 = (char *)jarg8; - result = (switch_status_t)switch_core_add_registration((char const *)arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4,arg5,(char const *)arg6,(char const *)arg7,(char const *)arg8); + arg9 = (char *)jarg9; + result = (switch_status_t)switch_core_add_registration((char const *)arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4,arg5,(char const *)arg6,(char const *)arg7,(char const *)arg8,(char const *)arg9); jresult = result; return jresult; } @@ -26470,6 +26483,18 @@ SWIGEXPORT void SWIGSTDCALL CSharp_switch_channel_transfer_to_extension(void * j } +SWIGEXPORT char * SWIGSTDCALL CSharp_switch_channel_get_partner_uuid(void * jarg1) { + char * jresult ; + switch_channel_t *arg1 = (switch_channel_t *) 0 ; + char *result = 0 ; + + arg1 = (switch_channel_t *)jarg1; + result = (char *)switch_channel_get_partner_uuid(arg1); + jresult = SWIG_csharp_string_callback((const char *)result); + return jresult; +} + + SWIGEXPORT int SWIGSTDCALL CSharp_switch_buffer_create(void * jarg1, void * jarg2, void * jarg3) { int jresult ; switch_memory_pool_t *arg1 = (switch_memory_pool_t *) 0 ; @@ -36454,15 +36479,17 @@ SWIGEXPORT unsigned long SWIGSTDCALL CSharp_EventConsumer_node_index_get(void * } -SWIGEXPORT void * SWIGSTDCALL CSharp_new_EventConsumer(char * jarg1, char * jarg2) { +SWIGEXPORT void * SWIGSTDCALL CSharp_new_EventConsumer(char * jarg1, char * jarg2, int jarg3) { void * jresult ; char *arg1 = (char *) NULL ; char *arg2 = (char *) "" ; + int arg3 = (int) 5000 ; EventConsumer *result = 0 ; arg1 = (char *)jarg1; arg2 = (char *)jarg2; - result = (EventConsumer *)new EventConsumer((char const *)arg1,(char const *)arg2); + arg3 = (int)jarg3; + result = (EventConsumer *)new EventConsumer((char const *)arg1,(char const *)arg2,arg3); jresult = (void *)result; return jresult; } diff --git a/src/mod/languages/mod_managed/managed/swig.2010.cs b/src/mod/languages/mod_managed/managed/swig.2010.cs index 0654085a50..3a1cc13d6b 100644 --- a/src/mod/languages/mod_managed/managed/swig.2010.cs +++ b/src/mod/languages/mod_managed/managed/swig.2010.cs @@ -2671,8 +2671,8 @@ public class freeswitch { return ret; } - public static switch_status_t switch_core_add_registration(string user, string realm, string token, string url, uint expires, string network_ip, string network_port, string network_proto) { - switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_core_add_registration(user, realm, token, url, expires, network_ip, network_port, network_proto); + public static switch_status_t switch_core_add_registration(string user, string realm, string token, string url, uint expires, string network_ip, string network_port, string network_proto, string metadata) { + switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_core_add_registration(user, realm, token, url, expires, network_ip, network_port, network_proto, metadata); return ret; } @@ -4118,6 +4118,11 @@ public class freeswitch { freeswitchPINVOKE.switch_channel_transfer_to_extension(SWIGTYPE_p_switch_channel.getCPtr(channel), switch_caller_extension.getCPtr(caller_extension)); } + public static string switch_channel_get_partner_uuid(SWIGTYPE_p_switch_channel channel) { + string ret = freeswitchPINVOKE.switch_channel_get_partner_uuid(SWIGTYPE_p_switch_channel.getCPtr(channel)); + return ret; + } + public static switch_status_t switch_buffer_create(SWIGTYPE_p_apr_pool_t pool, SWIGTYPE_p_p_switch_buffer buffer, SWIGTYPE_p_switch_size_t max_len) { switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_buffer_create(SWIGTYPE_p_apr_pool_t.getCPtr(pool), SWIGTYPE_p_p_switch_buffer.getCPtr(buffer), SWIGTYPE_p_switch_size_t.getCPtr(max_len)); if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve(); @@ -6130,6 +6135,7 @@ public class freeswitch { public static readonly string SWITCH_LAST_BRIDGE_VARIABLE = freeswitchPINVOKE.SWITCH_LAST_BRIDGE_VARIABLE_get(); public static readonly string SWITCH_SIGNAL_BRIDGE_VARIABLE = freeswitchPINVOKE.SWITCH_SIGNAL_BRIDGE_VARIABLE_get(); public static readonly string SWITCH_SIGNAL_BOND_VARIABLE = freeswitchPINVOKE.SWITCH_SIGNAL_BOND_VARIABLE_get(); + public static readonly string SWITCH_ORIGINATE_SIGNAL_BOND_VARIABLE = freeswitchPINVOKE.SWITCH_ORIGINATE_SIGNAL_BOND_VARIABLE_get(); public static readonly string SWITCH_ORIGINATOR_VARIABLE = freeswitchPINVOKE.SWITCH_ORIGINATOR_VARIABLE_get(); public static readonly string SWITCH_ORIGINATOR_CODEC_VARIABLE = freeswitchPINVOKE.SWITCH_ORIGINATOR_CODEC_VARIABLE_get(); public static readonly string SWITCH_ORIGINATOR_VIDEO_CODEC_VARIABLE = freeswitchPINVOKE.SWITCH_ORIGINATOR_VIDEO_CODEC_VARIABLE_get(); @@ -6780,6 +6786,9 @@ class freeswitchPINVOKE { [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_SIGNAL_BOND_VARIABLE_get")] public static extern string SWITCH_SIGNAL_BOND_VARIABLE_get(); + [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_ORIGINATE_SIGNAL_BOND_VARIABLE_get")] + public static extern string SWITCH_ORIGINATE_SIGNAL_BOND_VARIABLE_get(); + [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_ORIGINATOR_VARIABLE_get")] public static extern string SWITCH_ORIGINATOR_VARIABLE_get(); @@ -9094,7 +9103,7 @@ class freeswitchPINVOKE { public static extern uint switch_default_ptime(string jarg1, uint jarg2); [DllImport("mod_managed", EntryPoint="CSharp_switch_core_add_registration")] - public static extern int switch_core_add_registration(string jarg1, string jarg2, string jarg3, string jarg4, uint jarg5, string jarg6, string jarg7, string jarg8); + public static extern int switch_core_add_registration(string jarg1, string jarg2, string jarg3, string jarg4, uint jarg5, string jarg6, string jarg7, string jarg8, string jarg9); [DllImport("mod_managed", EntryPoint="CSharp_switch_core_del_registration")] public static extern int switch_core_del_registration(string jarg1, string jarg2, string jarg3); @@ -12705,6 +12714,9 @@ class freeswitchPINVOKE { [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_transfer_to_extension")] public static extern void switch_channel_transfer_to_extension(HandleRef jarg1, HandleRef jarg2); + [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_get_partner_uuid")] + public static extern string switch_channel_get_partner_uuid(HandleRef jarg1); + [DllImport("mod_managed", EntryPoint="CSharp_switch_buffer_create")] public static extern int switch_buffer_create(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3); diff --git a/src/mod/languages/mod_managed/managed/swig.cs b/src/mod/languages/mod_managed/managed/swig.cs index 62dea3d5c5..e2b486669d 100644 --- a/src/mod/languages/mod_managed/managed/swig.cs +++ b/src/mod/languages/mod_managed/managed/swig.cs @@ -709,7 +709,7 @@ public class EventConsumer : IDisposable { } } - public EventConsumer(string event_name, string subclass_name) : this(freeswitchPINVOKE.new_EventConsumer(event_name, subclass_name), true) { + public EventConsumer(string event_name, string subclass_name, int len) : this(freeswitchPINVOKE.new_EventConsumer(event_name, subclass_name, len), true) { } public int bind(string event_name, string subclass_name) { @@ -2659,8 +2659,8 @@ public class freeswitch { return ret; } - public static switch_status_t switch_core_add_registration(string user, string realm, string token, string url, uint expires, string network_ip, string network_port, string network_proto) { - switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_core_add_registration(user, realm, token, url, expires, network_ip, network_port, network_proto); + public static switch_status_t switch_core_add_registration(string user, string realm, string token, string url, uint expires, string network_ip, string network_port, string network_proto, string metadata) { + switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_core_add_registration(user, realm, token, url, expires, network_ip, network_port, network_proto, metadata); return ret; } @@ -4106,6 +4106,11 @@ public class freeswitch { freeswitchPINVOKE.switch_channel_transfer_to_extension(SWIGTYPE_p_switch_channel.getCPtr(channel), switch_caller_extension.getCPtr(caller_extension)); } + public static string switch_channel_get_partner_uuid(SWIGTYPE_p_switch_channel channel) { + string ret = freeswitchPINVOKE.switch_channel_get_partner_uuid(SWIGTYPE_p_switch_channel.getCPtr(channel)); + return ret; + } + public static switch_status_t switch_buffer_create(SWIGTYPE_p_apr_pool_t pool, SWIGTYPE_p_p_switch_buffer buffer, SWIGTYPE_p_switch_size_t max_len) { switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_buffer_create(SWIGTYPE_p_apr_pool_t.getCPtr(pool), SWIGTYPE_p_p_switch_buffer.getCPtr(buffer), SWIGTYPE_p_switch_size_t.getCPtr(max_len)); if (freeswitchPINVOKE.SWIGPendingException.Pending) throw freeswitchPINVOKE.SWIGPendingException.Retrieve(); @@ -6118,6 +6123,7 @@ public class freeswitch { public static readonly string SWITCH_LAST_BRIDGE_VARIABLE = freeswitchPINVOKE.SWITCH_LAST_BRIDGE_VARIABLE_get(); public static readonly string SWITCH_SIGNAL_BRIDGE_VARIABLE = freeswitchPINVOKE.SWITCH_SIGNAL_BRIDGE_VARIABLE_get(); public static readonly string SWITCH_SIGNAL_BOND_VARIABLE = freeswitchPINVOKE.SWITCH_SIGNAL_BOND_VARIABLE_get(); + public static readonly string SWITCH_ORIGINATE_SIGNAL_BOND_VARIABLE = freeswitchPINVOKE.SWITCH_ORIGINATE_SIGNAL_BOND_VARIABLE_get(); public static readonly string SWITCH_ORIGINATOR_VARIABLE = freeswitchPINVOKE.SWITCH_ORIGINATOR_VARIABLE_get(); public static readonly string SWITCH_ORIGINATOR_CODEC_VARIABLE = freeswitchPINVOKE.SWITCH_ORIGINATOR_CODEC_VARIABLE_get(); public static readonly string SWITCH_ORIGINATOR_VIDEO_CODEC_VARIABLE = freeswitchPINVOKE.SWITCH_ORIGINATOR_VIDEO_CODEC_VARIABLE_get(); @@ -6764,6 +6770,9 @@ class freeswitchPINVOKE { [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_SIGNAL_BOND_VARIABLE_get")] public static extern string SWITCH_SIGNAL_BOND_VARIABLE_get(); + [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_ORIGINATE_SIGNAL_BOND_VARIABLE_get")] + public static extern string SWITCH_ORIGINATE_SIGNAL_BOND_VARIABLE_get(); + [DllImport("mod_managed", EntryPoint="CSharp_SWITCH_ORIGINATOR_VARIABLE_get")] public static extern string SWITCH_ORIGINATOR_VARIABLE_get(); @@ -9078,7 +9087,7 @@ class freeswitchPINVOKE { public static extern uint switch_default_ptime(string jarg1, uint jarg2); [DllImport("mod_managed", EntryPoint="CSharp_switch_core_add_registration")] - public static extern int switch_core_add_registration(string jarg1, string jarg2, string jarg3, string jarg4, uint jarg5, string jarg6, string jarg7, string jarg8); + public static extern int switch_core_add_registration(string jarg1, string jarg2, string jarg3, string jarg4, uint jarg5, string jarg6, string jarg7, string jarg8, string jarg9); [DllImport("mod_managed", EntryPoint="CSharp_switch_core_del_registration")] public static extern int switch_core_del_registration(string jarg1, string jarg2, string jarg3); @@ -12689,6 +12698,9 @@ class freeswitchPINVOKE { [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_transfer_to_extension")] public static extern void switch_channel_transfer_to_extension(HandleRef jarg1, HandleRef jarg2); + [DllImport("mod_managed", EntryPoint="CSharp_switch_channel_get_partner_uuid")] + public static extern string switch_channel_get_partner_uuid(HandleRef jarg1); + [DllImport("mod_managed", EntryPoint="CSharp_switch_buffer_create")] public static extern int switch_buffer_create(HandleRef jarg1, HandleRef jarg2, HandleRef jarg3); @@ -14904,7 +14916,7 @@ class freeswitchPINVOKE { public static extern uint EventConsumer_node_index_get(HandleRef jarg1); [DllImport("mod_managed", EntryPoint="CSharp_new_EventConsumer")] - public static extern IntPtr new_EventConsumer(string jarg1, string jarg2); + public static extern IntPtr new_EventConsumer(string jarg1, string jarg2, int jarg3); [DllImport("mod_managed", EntryPoint="CSharp_delete_EventConsumer")] public static extern void delete_EventConsumer(HandleRef jarg1); diff --git a/src/mod/languages/mod_perl/mod_perl_wrap.cpp b/src/mod/languages/mod_perl/mod_perl_wrap.cpp index a3855445a4..dd4b385299 100644 --- a/src/mod/languages/mod_perl/mod_perl_wrap.cpp +++ b/src/mod/languages/mod_perl/mod_perl_wrap.cpp @@ -4675,6 +4675,7 @@ XS(_wrap_new_EventConsumer) { { char *arg1 = (char *) NULL ; char *arg2 = (char *) "" ; + int arg3 = (int) 5000 ; EventConsumer *result = 0 ; int res1 ; char *buf1 = 0 ; @@ -4682,11 +4683,13 @@ XS(_wrap_new_EventConsumer) { int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; + int val3 ; + int ecode3 = 0 ; int argvi = 0; dXSARGS; - if ((items < 0) || (items > 2)) { - SWIG_croak("Usage: new_EventConsumer(event_name,subclass_name);"); + if ((items < 0) || (items > 3)) { + SWIG_croak("Usage: new_EventConsumer(event_name,subclass_name,len);"); } if (items > 0) { res1 = SWIG_AsCharPtrAndSize(ST(0), &buf1, NULL, &alloc1); @@ -4702,14 +4705,23 @@ XS(_wrap_new_EventConsumer) { } arg2 = reinterpret_cast< char * >(buf2); } - result = (EventConsumer *)new EventConsumer((char const *)arg1,(char const *)arg2); + if (items > 2) { + ecode3 = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(2), &val3); + if (!SWIG_IsOK(ecode3)) { + SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "new_EventConsumer" "', argument " "3"" of type '" "int""'"); + } + arg3 = static_cast< int >(val3); + } + result = (EventConsumer *)new EventConsumer((char const *)arg1,(char const *)arg2,arg3); ST(argvi) = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_EventConsumer, SWIG_OWNER | SWIG_SHADOW); argvi++ ; if (alloc1 == SWIG_NEWOBJ) delete[] buf1; if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + XSRETURN(argvi); fail: if (alloc1 == SWIG_NEWOBJ) delete[] buf1; if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + SWIG_croak_null(); } } diff --git a/src/mod/languages/mod_python/mod_python_wrap.cpp b/src/mod/languages/mod_python/mod_python_wrap.cpp index c45da0b464..d2098edd1c 100644 --- a/src/mod/languages/mod_python/mod_python_wrap.cpp +++ b/src/mod/languages/mod_python/mod_python_wrap.cpp @@ -5406,6 +5406,7 @@ SWIGINTERN PyObject *_wrap_new_EventConsumer(PyObject *SWIGUNUSEDPARM(self), PyO PyObject *resultobj = 0; char *arg1 = (char *) NULL ; char *arg2 = (char *) "" ; + int arg3 = (int) 5000 ; EventConsumer *result = 0 ; int res1 ; char *buf1 = 0 ; @@ -5413,10 +5414,13 @@ SWIGINTERN PyObject *_wrap_new_EventConsumer(PyObject *SWIGUNUSEDPARM(self), PyO int res2 ; char *buf2 = 0 ; int alloc2 = 0 ; + int val3 ; + int ecode3 = 0 ; PyObject * obj0 = 0 ; PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; - if (!PyArg_ParseTuple(args,(char *)"|OO:new_EventConsumer",&obj0,&obj1)) SWIG_fail; + if (!PyArg_ParseTuple(args,(char *)"|OOO:new_EventConsumer",&obj0,&obj1,&obj2)) SWIG_fail; if (obj0) { res1 = SWIG_AsCharPtrAndSize(obj0, &buf1, NULL, &alloc1); if (!SWIG_IsOK(res1)) { @@ -5431,7 +5435,14 @@ SWIGINTERN PyObject *_wrap_new_EventConsumer(PyObject *SWIGUNUSEDPARM(self), PyO } arg2 = reinterpret_cast< char * >(buf2); } - result = (EventConsumer *)new EventConsumer((char const *)arg1,(char const *)arg2); + if (obj2) { + ecode3 = SWIG_AsVal_int(obj2, &val3); + if (!SWIG_IsOK(ecode3)) { + SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "new_EventConsumer" "', argument " "3"" of type '" "int""'"); + } + arg3 = static_cast< int >(val3); + } + result = (EventConsumer *)new EventConsumer((char const *)arg1,(char const *)arg2,arg3); resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_EventConsumer, SWIG_POINTER_NEW | 0 ); if (alloc1 == SWIG_NEWOBJ) delete[] buf1; if (alloc2 == SWIG_NEWOBJ) delete[] buf2; diff --git a/src/mod/timers/mod_posix_timer/mod_posix_timer.c b/src/mod/timers/mod_posix_timer/mod_posix_timer.c index 04d694b5f7..1b10e89043 100644 --- a/src/mod/timers/mod_posix_timer/mod_posix_timer.c +++ b/src/mod/timers/mod_posix_timer/mod_posix_timer.c @@ -22,9 +22,11 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): - * Chris Rienzo + * Christopher M. Rienzo * Timo Teräs (based on mod_timerfd.c) * + * Maintainer: Christopher M. Rienzo + * * mod_posix_timer.c -- soft timer implemented with POSIX timers (timer_create/timer_settime/timer_getoverrun) * */ @@ -44,7 +46,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_posix_timer_shutdown); SWITCH_MODULE_RUNTIME_FUNCTION(mod_posix_timer_runtime); SWITCH_MODULE_DEFINITION(mod_posix_timer, mod_posix_timer_load, mod_posix_timer_shutdown, mod_posix_timer_runtime); -#define SIG SIGRTMAX +#define SIG (SIGRTMAX - 1) #define MAX_INTERVAL 2000 /* ms */ #define TIMERS_PER_INTERVAL 4 #define MAX_ACTIVE_TIMERS 256 /* one byte */ @@ -111,7 +113,9 @@ static void timer_signal_handler(int sig, siginfo_t *si, void *cu) if (val >= 0 && val <= MAX_ACTIVE_TIMERS) { uint8_t active_id = (uint8_t)val; /* notify runtime thread that timer identified by active_id has ticked */ - write(globals.timer_tick_pipe[1], &active_id, 1); + if (write(globals.timer_tick_pipe[1], &active_id, 1) == -1) { + /* don't actually care about this error- this is only to make the compiler happy */ + } } } } diff --git a/src/mod/timers/mod_posix_timer/test/main.c b/src/mod/timers/mod_posix_timer/test/main.c index 44f3a34aea..9dfff6c778 100644 --- a/src/mod/timers/mod_posix_timer/test/main.c +++ b/src/mod/timers/mod_posix_timer/test/main.c @@ -115,7 +115,7 @@ static void *module_thread(void *dummy) /** * Load mod_posix_timer and start the runtime thread */ -static void load_module() +static int load_module() { fail_count = 0; warn_count = 0; @@ -124,9 +124,11 @@ static void load_module() session_count = 0; last_reported_session_count = 0; shutdown = 0; - mod_posix_timer_load(&mod, &pool); + if (mod_posix_timer_load(&mod, &pool) != SWITCH_STATUS_SUCCESS) { + return -1; + } timer_if = mod->timer; - pthread_create(&module_runtime_thread_id, NULL, module_thread, NULL); + return pthread_create(&module_runtime_thread_id, NULL, module_thread, NULL); } /** @@ -444,12 +446,14 @@ int main (int argc, char **argv) struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); srand48(ts.tv_nsec); - load_module(); + if (load_module() == -1) { + return -1; + } //test_timer(20, 5.0f, .2f, 1000); //test_timer_session(intervals, interval_weights, 4, 2 * 86400.0f, 90, 2000, 30.0, 5.0f); while(1) { /* stop periodically to trigger timer shutdown */ - test_timer_session(intervals, interval_weights, 1, 60, 150, 3000, 30.0, 5.0f); + test_timer_session(intervals, interval_weights, 1, 60, 150, 190 /* 3000 */, 30.0, 5.0f); } //test_timer(1000, 5.0f, 1); //test_timer(20, 5.0f, .2f, 1000); diff --git a/src/switch.c b/src/switch.c index 189eea40cf..3903a15604 100644 --- a/src/switch.c +++ b/src/switch.c @@ -102,7 +102,6 @@ static void handle_SIGCHLD(int sig) pid = wait(&status); if (pid > 0) { - printf("ASS %d\n", pid); system_ready = -1; } diff --git a/src/switch_apr.c b/src/switch_apr.c index 426bed59f5..5936c7223e 100644 --- a/src/switch_apr.c +++ b/src/switch_apr.c @@ -1169,6 +1169,11 @@ SWITCH_DECLARE(switch_status_t) switch_thread_exit(switch_thread_t *thd, switch_ */ SWITCH_DECLARE(switch_status_t) switch_thread_join(switch_status_t *retval, switch_thread_t *thd) { + if ( !thd ) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERROR: Attempting to join thread that does not exist\n"); + return SWITCH_STATUS_FALSE; + } + return apr_thread_join((apr_status_t *) retval, (apr_thread_t *) thd); } diff --git a/src/switch_channel.c b/src/switch_channel.c index 138123f3eb..94c9a35cfe 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -1928,6 +1928,8 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_running_state( if (state == CS_ROUTING) { switch_channel_event_set_data(channel, event); } else { + const char *v; + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-State", switch_channel_state_name(state)); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Call-State", switch_channel_callstate2str(channel->callstate)); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-State-Number", "%d", state); @@ -1951,6 +1953,21 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_running_state( } else { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Answer-State", "ringing"); } + + + if ((v = switch_channel_get_variable(channel, "presence_id"))) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Presence-ID", v); + } + + if ((v = switch_channel_get_variable(channel, "presence_data"))) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Presence-Data", v); + } + + if ((v = switch_channel_get_variable(channel, "presence_data_cols"))) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Presence-Data-Cols", v); + switch_event_add_presence_data_cols(channel, event, "PD-"); + } + } switch_event_fire(&event); } diff --git a/src/switch_core.c b/src/switch_core.c index 8f1543e028..d706563f83 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -1577,16 +1577,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc static void handle_SIGCHLD(int sig) { int status = 0; - int pid = 0; - - if (sig) {}; - - pid = wait(&status); - - if (pid > 0) { - printf("ASS %d\n", pid); - } + wait(&status); return; } #endif diff --git a/src/switch_core_asr.c b/src/switch_core_asr.c index 4db889929c..e10928f29d 100644 --- a/src/switch_core_asr.c +++ b/src/switch_core_asr.c @@ -26,7 +26,7 @@ * Anthony Minessale II * Michael Jerris * Paul D. Tinsley - * Christopher M. Rienzo + * Christopher M. Rienzo * Luke Dashjr (OpenMethods, LLC) * * diff --git a/src/switch_core_codec.c b/src/switch_core_codec.c index e7fa3f3fe7..1a529501ad 100644 --- a/src/switch_core_codec.c +++ b/src/switch_core_codec.c @@ -26,7 +26,7 @@ * Anthony Minessale II * Michael Jerris * Paul D. Tinsley - * Chris Rienzo + * Christopher M. Rienzo * * * switch_core_codec.c -- Main Core Library (codec functions) diff --git a/src/switch_core_speech.c b/src/switch_core_speech.c index f0e97f8b28..b75c9f843b 100644 --- a/src/switch_core_speech.c +++ b/src/switch_core_speech.c @@ -26,7 +26,7 @@ * Anthony Minessale II * Michael Jerris * Paul D. Tinsley - * Christopher M. Rienzo + * Christopher M. Rienzo * * * switch_core_speech.c -- Main Core Library (speech functions) diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index 85d38160ed..ee726500ac 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -1193,7 +1193,7 @@ static char *parse_presence_data_cols(switch_event_t *event) for (i = 0; i < col_count; i++) { const char *val = NULL; - switch_snprintfv(col_name, sizeof(col_name), "variable_%q", cols[i]); + switch_snprintfv(col_name, sizeof(col_name), "PD-%q", cols[i]); val = switch_event_get_header_nil(event, col_name); if (zstr(val)) { stream.write_function(&stream, "%q=NULL,", cols[i]); @@ -1403,10 +1403,23 @@ static void core_event_handler(switch_event_t *event) switch (state_i) { case CS_NEW: - case CS_HANGUP: case CS_DESTROY: case CS_REPORTING: break; + case CS_EXECUTE: + if ((extra_cols = parse_presence_data_cols(event))) { + new_sql() = switch_mprintf("update channels set state='%s',%s where uuid='%q'", + switch_event_get_header_nil(event, "channel-state"), + extra_cols, + switch_event_get_header_nil(event, "unique-id")); + free(extra_cols); + + } else { + new_sql() = switch_mprintf("update channels set state='%s' where uuid='%s'", + switch_event_get_header_nil(event, "channel-state"), + switch_event_get_header_nil(event, "unique-id")); + } + break; case CS_ROUTING: if ((extra_cols = parse_presence_data_cols(event))) { new_sql() = switch_mprintf("update channels set state='%s',cid_name='%q',cid_num='%q',callee_name='%q',callee_num='%q'," @@ -1713,7 +1726,8 @@ static char create_registrations_sql[] = " network_ip VARCHAR(256),\n" " network_port VARCHAR(256),\n" " network_proto VARCHAR(256),\n" - " hostname VARCHAR(256)\n" + " hostname VARCHAR(256),\n" + " metadata VARCHAR(256)\n" ");\n"; @@ -1843,7 +1857,8 @@ static char basic_calls_sql[] = SWITCH_DECLARE(switch_status_t) switch_core_add_registration(const char *user, const char *realm, const char *token, const char *url, uint32_t expires, - const char *network_ip, const char *network_port, const char *network_proto) + const char *network_ip, const char *network_port, const char *network_proto, + const char *metadata) { char *sql; @@ -1860,19 +1875,35 @@ SWITCH_DECLARE(switch_status_t) switch_core_add_registration(const char *user, c } switch_queue_push(sql_manager.sql_queue[0], sql); - - sql = switch_mprintf("insert into registrations (reg_user,realm,token,url,expires,network_ip,network_port,network_proto,hostname) " - "values ('%q','%q','%q','%q',%ld,'%q','%q','%q','%q')", - switch_str_nil(user), - switch_str_nil(realm), - switch_str_nil(token), - switch_str_nil(url), - expires, - switch_str_nil(network_ip), - switch_str_nil(network_port), - switch_str_nil(network_proto), - switch_core_get_switchname() - ); + + if ( !zstr(metadata) ) { + sql = switch_mprintf("insert into registrations (reg_user,realm,token,url,expires,network_ip,network_port,network_proto,hostname,metadata) " + "values ('%q','%q','%q','%q',%ld,'%q','%q','%q','%q','%q')", + switch_str_nil(user), + switch_str_nil(realm), + switch_str_nil(token), + switch_str_nil(url), + expires, + switch_str_nil(network_ip), + switch_str_nil(network_port), + switch_str_nil(network_proto), + switch_core_get_switchname(), + metadata + ); + } else { + sql = switch_mprintf("insert into registrations (reg_user,realm,token,url,expires,network_ip,network_port,network_proto,hostname) " + "values ('%q','%q','%q','%q',%ld,'%q','%q','%q','%q')", + switch_str_nil(user), + switch_str_nil(realm), + switch_str_nil(token), + switch_str_nil(url), + expires, + switch_str_nil(network_ip), + switch_str_nil(network_port), + switch_str_nil(network_proto), + switch_core_get_switchname() + ); + } switch_queue_push(sql_manager.sql_queue[0], sql); @@ -2007,6 +2038,8 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_ switch_cache_db_test_reactive(dbh, "delete from registrations where reg_user='' or network_proto='tcp' or network_proto='tls'", "DROP TABLE registrations", create_registrations_sql); + switch_cache_db_test_reactive(dbh, "select metadata from registrations", NULL, "ALTER TABLE registrations ADD COLUMN metadata VARCHAR(256)"); + switch (dbh->type) { case SCDB_TYPE_ODBC: diff --git a/src/switch_cpp.cpp b/src/switch_cpp.cpp index 5408edb828..0f7a52066b 100644 --- a/src/switch_cpp.cpp +++ b/src/switch_cpp.cpp @@ -50,11 +50,11 @@ static void event_handler(switch_event_t *event) } -SWITCH_DECLARE_CONSTRUCTOR EventConsumer::EventConsumer(const char *event_name, const char *subclass_name) +SWITCH_DECLARE_CONSTRUCTOR EventConsumer::EventConsumer(const char *event_name, const char *subclass_name, int len) { switch_core_new_memory_pool(&pool); - switch_queue_create(&events, 5000, pool); + switch_queue_create(&events, len, pool); node_index = 0; if (!zstr(event_name)) { diff --git a/src/switch_ivr.c b/src/switch_ivr.c index 08d1fcd5a4..8f50fe1257 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -2976,7 +2976,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_say_string(switch_core_session_t *ses } } - if ((si = switch_loadable_module_get_say_interface(module_name))) { + if ((si = switch_loadable_module_get_say_interface(module_name)) && si->say_string_function) { /* should go back and proto all the say mods to const.... */ switch_say_args_t say_args = {0}; diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index 37da4f0486..c684c8f14c 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -27,7 +27,7 @@ * Michael Jerris * Bret McDanel * Luke Dashjr (OpenMethods, LLC) - * Chris Rienzo + * Christopher M. Rienzo * * switch_ivr_async.c -- IVR Library (async operations) * diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c index c18da450a6..72d0ab0393 100644 --- a/src/switch_ivr_originate.c +++ b/src/switch_ivr_originate.c @@ -384,8 +384,10 @@ static void inherit_codec(switch_channel_t *caller_channel, switch_core_session_ { const char *var = switch_channel_get_variable(caller_channel, "inherit_codec"); switch_channel_t *channel = switch_core_session_get_channel(session); - - if (switch_true(var)) { + + if (!zstr(var) && !strcasecmp(var, "passthru")) { + switch_channel_set_variable(caller_channel, "absolute_codec_string", switch_channel_get_variable(channel, "ep_codec_string")); + } else if (switch_true(var)) { switch_codec_implementation_t impl = { 0 }; switch_codec_implementation_t video_impl = { 0 }; char tmp[128] = ""; diff --git a/src/switch_json.c b/src/switch_json.c index 83b34704e6..4bef601f8e 100644 --- a/src/switch_json.c +++ b/src/switch_json.c @@ -50,10 +50,11 @@ static char* cJSON_strdup(const char* str) { size_t len; char* copy; + const char *s = str ? str : ""; - len = strlen(str) + 1; + len = strlen(s) + 1; if (!(copy = (char*)cJSON_malloc(len))) return 0; - memcpy(copy,str,len); + memcpy(copy,s,len); return copy; } diff --git a/src/switch_time.c b/src/switch_time.c index 381d2dc5ad..d4f5454d3b 100644 --- a/src/switch_time.c +++ b/src/switch_time.c @@ -941,7 +941,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime) runtime.timestamp = ts; current_ms += (runtime.microseconds_per_tick / 1000); - tick += (runtime.microseconds_per_tick / 1000); + tick++; if (time_sync < runtime.time_sync) { time_sync++; /* Only step once for each loop, we want to make sure to keep this thread safe */