p1_sip-1.0.1/0000755000175000017500000000000012650734252013270 5ustar debalancedebalancep1_sip-1.0.1/configure.ac0000644000175000017500000000105212650734252015554 0ustar debalancedebalanceAC_PREREQ(2.59c) AC_PACKAGE_VERSION(0.1.0) AC_PACKAGE_NAME(esip) AC_INIT(esip, 0.1.0, [], esip) # Checks for programs. AC_PROG_CC AC_PROG_MAKE_SET if test "x$GCC" = "xyes"; then CFLAGS="$CFLAGS -Wall" fi # Checks for typedefs, structures, and compiler characteristics. AC_C_CONST # Checks for library functions. AC_FUNC_MALLOC AC_HEADER_STDC # Checks Erlang runtime and compiler AC_ERLANG_NEED_ERL AC_ERLANG_NEED_ERLC # Checks and sets ERLANG_ROOT_DIR and ERLANG_LIB_DIR variable # AC_ERLANG_SUBST_ROOT_DIR # AC_ERLANG_SUBST_LIB_DIR AC_OUTPUT p1_sip-1.0.1/rebar.config0000644000175000017500000000065612650734252015561 0ustar debalancedebalance{erl_opts, [{i, "include"}, {i, "deps/p1_stun/include"}, {i, "../p1_stun/include"}]}. {deps, [{p1_stun, ".*", {git, "https://github.com/processone/stun", {tag, "0.9.1"}}}, {p1_tls, ".*", {git, "https://github.com/processone/tls", {tag, "1.0.0"}}}, {p1_utils, ".*", {git, "https://github.com/processone/p1_utils", {tag, "1.0.3"}}}]}. %% Local Variables: %% mode: erlang %% End: %% vim: set filetype=erlang tabstop=8: p1_sip-1.0.1/include/0000755000175000017500000000000012650734252014713 5ustar debalancedebalancep1_sip-1.0.1/include/esip.hrl0000644000175000017500000000316512650734252016367 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% %%% Copyright (C) 2002-2016 ProcessOne, SARL. All Rights Reserved. %%% %%% Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 %%% %%% Unless required by applicable law or agreed to in writing, software %%% distributed under the License is distributed on an "AS IS" BASIS, %%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %%% See the License for the specific language governing permissions and %%% limitations under the License. %%% %%%---------------------------------------------------------------------- -record(sip, {type, version = {2,0}, method, hdrs = [], body = <<>>, uri, status, reason}). -record(uri, {scheme = <<"sip">>, user = <<>>, password = <<>>, host = <<>>, port = undefined, params = [], hdrs = []}). -record(via, {proto = <<"SIP">>, version = {2,0}, transport, host, port = undefined, params = []}). -record(dialog_id, {'call-id', remote_tag, local_tag}). -record(sip_socket, {type :: udp | tcp | tls, sock :: inet:socket() | p1_tls:tls_socket(), addr :: {inet:ip_address(), inet:port_number()}, peer :: {inet:ip_address(), inet:port_number()}, pid :: pid()}). p1_sip-1.0.1/include/esip_lib.hrl0000644000175000017500000000256512650734252017220 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% %%% Copyright (C) 2002-2016 ProcessOne, SARL. All Rights Reserved. %%% %%% Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 %%% %%% Unless required by applicable law or agreed to in writing, software %%% distributed under the License is distributed on an "AS IS" BASIS, %%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %%% See the License for the specific language governing permissions and %%% limitations under the License. %%% %%%---------------------------------------------------------------------- -record(trid, {owner, type}). -record(dialog, {secure, route_set, remote_target, remote_seq_num, local_seq_num, 'call-id', local_tag, remote_tag, remote_uri, local_uri, state}). -define(ERROR_MSG(Format, Args), error_logger:error_msg("(~p:~p:~p) " ++ Format, [self(), ?MODULE, ?LINE | Args])). -define(INFO_MSG(Format, Args), error_logger:info_msg("(~p:~p:~p) " ++ Format, [self(), ?MODULE, ?LINE | Args])). p1_sip-1.0.1/configure0000755000175000017500000037143712650734252015216 0ustar debalancedebalance#! /bin/sh # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.67 for esip 0.1.0. # # # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, # 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software # Foundation, Inc. # # # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi as_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in #( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # IFS # We need space, tab and new line, in precisely that order. Quoting is # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which # is contrary to our usage. Disable this feature. alias -g '\${1+\"\$@\"}'='\"\$@\"' setopt NO_GLOB_SUBST else case \`(set -o) 2>/dev/null\` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi " as_required="as_fn_return () { (exit \$1); } as_fn_success () { as_fn_return 0; } as_fn_failure () { as_fn_return 1; } as_fn_ret_success () { return 0; } as_fn_ret_failure () { return 1; } exitcode=0 as_fn_success || { exitcode=1; echo as_fn_success failed.; } as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : else exitcode=1; echo positional parameters were not saved. fi test x\$exitcode = x0 || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1 test \$(( 1 + 1 )) = 2 || exit 1" if (eval "$as_required") 2>/dev/null; then : as_have_required=yes else as_have_required=no fi if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR as_found=false for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. as_found=: case $as_dir in #( /*) for as_base in sh bash ksh sh5; do # Try only shells that exist, to save several forks. as_shell=$as_dir/$as_base if { test -f "$as_shell" || test -f "$as_shell.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : CONFIG_SHELL=$as_shell as_have_required=yes if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : break 2 fi fi done;; esac as_found=false done $as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : CONFIG_SHELL=$SHELL as_have_required=yes fi; } IFS=$as_save_IFS if test "x$CONFIG_SHELL" != x; then : # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV export CONFIG_SHELL exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"} fi if test x$as_have_required = xno; then : $as_echo "$0: This script requires a shell more modern than all" $as_echo "$0: the shells that I found on your system." if test x${ZSH_VERSION+set} = xset ; then $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" $as_echo "$0: be upgraded to zsh 4.3.4 or later." else $as_echo "$0: Please tell bug-autoconf@gnu.org about your system, $0: including any error possibly output before this $0: message. Then install a modern shell, or manually run $0: the script under such a shell if you do have one." fi exit 1 fi fi fi SHELL=${CONFIG_SHELL-/bin/sh} export SHELL # Unset more variables known to interfere with behavior of common tools. CLICOLOR_FORCE= GREP_OPTIONS= unset CLICOLOR_FORCE GREP_OPTIONS ## --------------------- ## ## M4sh Shell Functions. ## ## --------------------- ## # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits as_lineno_1=$LINENO as_lineno_1a=$LINENO as_lineno_2=$LINENO as_lineno_2a=$LINENO eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) sed -n ' p /[$]LINENO/= ' <$as_myself | sed ' s/[$]LINENO.*/&-/ t lineno b :lineno N :loop s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ t loop s/-\n.*// ' >$as_me.lineno && chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). . "./$as_me.lineno" # Exit status is that of the last command. exit } ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -p'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -p' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -p' fi else as_ln_s='cp -p' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi if test -x / >/dev/null 2>&1; then as_test_x='test -x' else if ls -dL / >/dev/null 2>&1; then as_ls_L_option=L else as_ls_L_option= fi as_test_x=' eval sh -c '\'' if test -d "$1"; then test -d "$1/."; else case $1 in #( -*)set "./$1";; esac; case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( ???[sx]*):;;*)false;;esac;fi '\'' sh ' fi as_executable_p=$as_test_x # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" test -n "$DJDIR" || exec 7<&0 &1 # Name of the host. # hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, # so uname gets run too. ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` # # Initializations. # ac_default_prefix=/usr/local ac_clean_files= ac_config_libobj_dir=. LIBOBJS= cross_compiling=no subdirs= MFLAGS= MAKEFLAGS= # Identity of this package. PACKAGE_NAME='esip' PACKAGE_TARNAME='esip' PACKAGE_VERSION='0.1.0' PACKAGE_STRING='esip 0.1.0' PACKAGE_BUGREPORT='' PACKAGE_URL='' # Factoring default headers for most tests. ac_includes_default="\ #include #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef HAVE_SYS_STAT_H # include #endif #ifdef STDC_HEADERS # include # include #else # ifdef HAVE_STDLIB_H # include # endif #endif #ifdef HAVE_STRING_H # if !defined STDC_HEADERS && defined HAVE_MEMORY_H # include # endif # include #endif #ifdef HAVE_STRINGS_H # include #endif #ifdef HAVE_INTTYPES_H # include #endif #ifdef HAVE_STDINT_H # include #endif #ifdef HAVE_UNISTD_H # include #endif" ac_subst_vars='LTLIBOBJS ERLCFLAGS ERLC ERL LIBOBJS EGREP GREP CPP SET_MAKE OBJEXT EXEEXT ac_ct_CC CPPFLAGS LDFLAGS CFLAGS CC target_alias host_alias build_alias LIBS ECHO_T ECHO_N ECHO_C DEFS mandir localedir libdir psdir pdfdir dvidir htmldir infodir docdir oldincludedir includedir localstatedir sharedstatedir sysconfdir datadir datarootdir libexecdir sbindir bindir program_transform_name prefix exec_prefix PACKAGE_URL PACKAGE_BUGREPORT PACKAGE_STRING PACKAGE_VERSION PACKAGE_TARNAME PACKAGE_NAME PATH_SEPARATOR SHELL' ac_subst_files='' ac_user_opts=' enable_option_checking ' ac_precious_vars='build_alias host_alias target_alias CC CFLAGS LDFLAGS LIBS CPPFLAGS CPP ERL ERLC ERLCFLAGS' # Initialize some variables set by options. ac_init_help= ac_init_version=false ac_unrecognized_opts= ac_unrecognized_sep= # The variables have the same names as the options, with # dashes changed to underlines. cache_file=/dev/null exec_prefix=NONE no_create= no_recursion= prefix=NONE program_prefix=NONE program_suffix=NONE program_transform_name=s,x,x, silent= site= srcdir= verbose= x_includes=NONE x_libraries=NONE # Installation directory options. # These are left unexpanded so users can "make install exec_prefix=/foo" # and all the variables that are supposed to be based on exec_prefix # by default will actually change. # Use braces instead of parens because sh, perl, etc. also accept them. # (The list follows the same order as the GNU Coding Standards.) bindir='${exec_prefix}/bin' sbindir='${exec_prefix}/sbin' libexecdir='${exec_prefix}/libexec' datarootdir='${prefix}/share' datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' infodir='${datarootdir}/info' htmldir='${docdir}' dvidir='${docdir}' pdfdir='${docdir}' psdir='${docdir}' libdir='${exec_prefix}/lib' localedir='${datarootdir}/locale' mandir='${datarootdir}/man' ac_prev= ac_dashdash= for ac_option do # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then eval $ac_prev=\$ac_option ac_prev= continue fi case $ac_option in *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; *=) ac_optarg= ;; *) ac_optarg=yes ;; esac # Accept the important Cygnus configure options, so we can diagnose typos. case $ac_dashdash$ac_option in --) ac_dashdash=yes ;; -bindir | --bindir | --bindi | --bind | --bin | --bi) ac_prev=bindir ;; -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) bindir=$ac_optarg ;; -build | --build | --buil | --bui | --bu) ac_prev=build_alias ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) build_alias=$ac_optarg ;; -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) cache_file=$ac_optarg ;; --config-cache | -C) cache_file=config.cache ;; -datadir | --datadir | --datadi | --datad) ac_prev=datadir ;; -datadir=* | --datadir=* | --datadi=* | --datad=*) datadir=$ac_optarg ;; -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ | --dataroo | --dataro | --datar) ac_prev=datarootdir ;; -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) datarootdir=$ac_optarg ;; -disable-* | --disable-*) ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=no ;; -docdir | --docdir | --docdi | --doc | --do) ac_prev=docdir ;; -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) docdir=$ac_optarg ;; -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) ac_prev=dvidir ;; -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) dvidir=$ac_optarg ;; -enable-* | --enable-*) ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=\$ac_optarg ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ | --exec | --exe | --ex) ac_prev=exec_prefix ;; -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ | --exec=* | --exe=* | --ex=*) exec_prefix=$ac_optarg ;; -gas | --gas | --ga | --g) # Obsolete; use --with-gas. with_gas=yes ;; -help | --help | --hel | --he | -h) ac_init_help=long ;; -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) ac_init_help=recursive ;; -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) ac_init_help=short ;; -host | --host | --hos | --ho) ac_prev=host_alias ;; -host=* | --host=* | --hos=* | --ho=*) host_alias=$ac_optarg ;; -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) ac_prev=htmldir ;; -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ | --ht=*) htmldir=$ac_optarg ;; -includedir | --includedir | --includedi | --included | --include \ | --includ | --inclu | --incl | --inc) ac_prev=includedir ;; -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ | --includ=* | --inclu=* | --incl=* | --inc=*) includedir=$ac_optarg ;; -infodir | --infodir | --infodi | --infod | --info | --inf) ac_prev=infodir ;; -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) infodir=$ac_optarg ;; -libdir | --libdir | --libdi | --libd) ac_prev=libdir ;; -libdir=* | --libdir=* | --libdi=* | --libd=*) libdir=$ac_optarg ;; -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ | --libexe | --libex | --libe) ac_prev=libexecdir ;; -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ | --libexe=* | --libex=* | --libe=*) libexecdir=$ac_optarg ;; -localedir | --localedir | --localedi | --localed | --locale) ac_prev=localedir ;; -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) localedir=$ac_optarg ;; -localstatedir | --localstatedir | --localstatedi | --localstated \ | --localstate | --localstat | --localsta | --localst | --locals) ac_prev=localstatedir ;; -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) localstatedir=$ac_optarg ;; -mandir | --mandir | --mandi | --mand | --man | --ma | --m) ac_prev=mandir ;; -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) mandir=$ac_optarg ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ | --no-cr | --no-c | -n) no_create=yes ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) no_recursion=yes ;; -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ | --oldin | --oldi | --old | --ol | --o) ac_prev=oldincludedir ;; -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) oldincludedir=$ac_optarg ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) ac_prev=prefix ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) prefix=$ac_optarg ;; -program-prefix | --program-prefix | --program-prefi | --program-pref \ | --program-pre | --program-pr | --program-p) ac_prev=program_prefix ;; -program-prefix=* | --program-prefix=* | --program-prefi=* \ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) program_prefix=$ac_optarg ;; -program-suffix | --program-suffix | --program-suffi | --program-suff \ | --program-suf | --program-su | --program-s) ac_prev=program_suffix ;; -program-suffix=* | --program-suffix=* | --program-suffi=* \ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) program_suffix=$ac_optarg ;; -program-transform-name | --program-transform-name \ | --program-transform-nam | --program-transform-na \ | --program-transform-n | --program-transform- \ | --program-transform | --program-transfor \ | --program-transfo | --program-transf \ | --program-trans | --program-tran \ | --progr-tra | --program-tr | --program-t) ac_prev=program_transform_name ;; -program-transform-name=* | --program-transform-name=* \ | --program-transform-nam=* | --program-transform-na=* \ | --program-transform-n=* | --program-transform-=* \ | --program-transform=* | --program-transfor=* \ | --program-transfo=* | --program-transf=* \ | --program-trans=* | --program-tran=* \ | --progr-tra=* | --program-tr=* | --program-t=*) program_transform_name=$ac_optarg ;; -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) ac_prev=pdfdir ;; -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) pdfdir=$ac_optarg ;; -psdir | --psdir | --psdi | --psd | --ps) ac_prev=psdir ;; -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) psdir=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) sbindir=$ac_optarg ;; -sharedstatedir | --sharedstatedir | --sharedstatedi \ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ | --sharedst | --shareds | --shared | --share | --shar \ | --sha | --sh) ac_prev=sharedstatedir ;; -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ | --sha=* | --sh=*) sharedstatedir=$ac_optarg ;; -site | --site | --sit) ac_prev=site ;; -site=* | --site=* | --sit=*) site=$ac_optarg ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) srcdir=$ac_optarg ;; -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ | --syscon | --sysco | --sysc | --sys | --sy) ac_prev=sysconfdir ;; -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) sysconfdir=$ac_optarg ;; -target | --target | --targe | --targ | --tar | --ta | --t) ac_prev=target_alias ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) target_alias=$ac_optarg ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; -version | --version | --versio | --versi | --vers | -V) ac_init_version=: ;; -with-* | --with-*) ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=\$ac_optarg ;; -without-* | --without-*) ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=no ;; --x) # Obsolete; use --with-x. with_x=yes ;; -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ | --x-incl | --x-inc | --x-in | --x-i) ac_prev=x_includes ;; -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) x_includes=$ac_optarg ;; -x-libraries | --x-libraries | --x-librarie | --x-librari \ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) ac_prev=x_libraries ;; -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) x_libraries=$ac_optarg ;; -*) as_fn_error $? "unrecognized option: \`$ac_option' Try \`$0 --help' for more information" ;; *=*) ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` # Reject names that are not valid shell variable names. case $ac_envvar in #( '' | [0-9]* | *[!_$as_cr_alnum]* ) as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; esac eval $ac_envvar=\$ac_optarg export $ac_envvar ;; *) # FIXME: should be removed in autoconf 3.0. $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} ;; esac done if test -n "$ac_prev"; then ac_option=--`echo $ac_prev | sed 's/_/-/g'` as_fn_error $? "missing argument to $ac_option" fi if test -n "$ac_unrecognized_opts"; then case $enable_option_checking in no) ;; fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; esac fi # Check all directory arguments for consistency. for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ libdir localedir mandir do eval ac_val=\$$ac_var # Remove trailing slashes. case $ac_val in */ ) ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` eval $ac_var=\$ac_val;; esac # Be sure to have absolute directory names. case $ac_val in [\\/$]* | ?:[\\/]* ) continue;; NONE | '' ) case $ac_var in *prefix ) continue;; esac;; esac as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" done # There might be people who depend on the old broken behavior: `$host' # used to hold the argument of --host etc. # FIXME: To remove some day. build=$build_alias host=$host_alias target=$target_alias # FIXME: To remove some day. if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe $as_echo "$as_me: WARNING: if you wanted to set the --build type, don't use --host. If a cross compiler is detected then cross compile mode will be used" >&2 elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi fi ac_tool_prefix= test -n "$host_alias" && ac_tool_prefix=$host_alias- test "$silent" = yes && exec 6>/dev/null ac_pwd=`pwd` && test -n "$ac_pwd" && ac_ls_di=`ls -di .` && ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || as_fn_error $? "working directory cannot be determined" test "X$ac_ls_di" = "X$ac_pwd_ls_di" || as_fn_error $? "pwd does not report name of working directory" # Find the source files, if location was not specified. if test -z "$srcdir"; then ac_srcdir_defaulted=yes # Try the directory containing this script, then the parent directory. ac_confdir=`$as_dirname -- "$as_myself" || $as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_myself" : 'X\(//\)[^/]' \| \ X"$as_myself" : 'X\(//\)$' \| \ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_myself" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` srcdir=$ac_confdir if test ! -r "$srcdir/$ac_unique_file"; then srcdir=.. fi else ac_srcdir_defaulted=no fi if test ! -r "$srcdir/$ac_unique_file"; then test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" fi ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" ac_abs_confdir=`( cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" pwd)` # When building in place, set srcdir=. if test "$ac_abs_confdir" = "$ac_pwd"; then srcdir=. fi # Remove unnecessary trailing slashes from srcdir. # Double slashes in file names in object file debugging info # mess up M-x gdb in Emacs. case $srcdir in */) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; esac for ac_var in $ac_precious_vars; do eval ac_env_${ac_var}_set=\${${ac_var}+set} eval ac_env_${ac_var}_value=\$${ac_var} eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} eval ac_cv_env_${ac_var}_value=\$${ac_var} done # # Report the --help message. # if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF \`configure' configures esip 0.1.0 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print \`checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for \`--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or \`..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [$ac_default_prefix] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, \`make install' will install all the files in \`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify an installation prefix other than \`$ac_default_prefix' using \`--prefix', for instance \`--prefix=\$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/esip] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] _ACEOF cat <<\_ACEOF _ACEOF fi if test -n "$ac_init_help"; then case $ac_init_help in short | recursive ) echo "Configuration of esip 0.1.0:";; esac cat <<\_ACEOF Some influential environment variables: CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L if you have libraries in a nonstandard directory LIBS libraries to pass to the linker, e.g. -l CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory CPP C preprocessor ERL Erlang/OTP interpreter command [autodetected] ERLC Erlang/OTP compiler command [autodetected] ERLCFLAGS Erlang/OTP compiler flags [none] Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. Report bugs to the package provider. _ACEOF ac_status=$? fi if test "$ac_init_help" = "recursive"; then # If there are subdirs, report their specific --help. for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue test -d "$ac_dir" || { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || continue ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix cd "$ac_dir" || { ac_status=$?; continue; } # Check for guested configure. if test -f "$ac_srcdir/configure.gnu"; then echo && $SHELL "$ac_srcdir/configure.gnu" --help=recursive elif test -f "$ac_srcdir/configure"; then echo && $SHELL "$ac_srcdir/configure" --help=recursive else $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi || ac_status=$? cd "$ac_pwd" || { ac_status=$?; break; } done fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF esip configure 0.1.0 generated by GNU Autoconf 2.67 Copyright (C) 2010 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF exit fi ## ------------------------ ## ## Autoconf initialization. ## ## ------------------------ ## # ac_fn_c_try_compile LINENO # -------------------------- # Try to compile conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack rm -f conftest.$ac_objext if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err } && test -s conftest.$ac_objext; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} as_fn_set_status $ac_retval } # ac_fn_c_try_compile # ac_fn_c_try_cpp LINENO # ---------------------- # Try to preprocess conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_cpp () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if { { ac_try="$ac_cpp conftest.$ac_ext" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } > conftest.i && { test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || test ! -s conftest.err }; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} as_fn_set_status $ac_retval } # ac_fn_c_try_cpp # ac_fn_c_try_run LINENO # ---------------------- # Try to link conftest.$ac_ext, and return whether this succeeded. Assumes # that executables *can* be run. ac_fn_c_try_run () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then : ac_retval=0 else $as_echo "$as_me: program exited with status $ac_status" >&5 $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=$ac_status fi rm -rf conftest.dSYM conftest_ipa8_conftest.oo eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} as_fn_set_status $ac_retval } # ac_fn_c_try_run # ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists, giving a warning if it cannot be compiled using # the include files in INCLUDES and setting the cache variable VAR # accordingly. ac_fn_c_check_header_mongrel () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if eval "test \"\${$3+set}\"" = set; then : { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval "test \"\${$3+set}\"" = set; then : $as_echo_n "(cached) " >&6 fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } else # Is the header compilable? { $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5 $as_echo_n "checking $2 usability... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_header_compiler=yes else ac_header_compiler=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5 $as_echo "$ac_header_compiler" >&6; } # Is the header present? { $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5 $as_echo_n "checking $2 presence... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include <$2> _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : ac_header_preproc=yes else ac_header_preproc=no fi rm -f conftest.err conftest.i conftest.$ac_ext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5 $as_echo "$ac_header_preproc" >&6; } # So? What about this header? case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #(( yes:no: ) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5 $as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 $as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} ;; no:yes:* ) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5 $as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5 $as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5 $as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5 $as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 $as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} ;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval "test \"\${$3+set}\"" = set; then : $as_echo_n "(cached) " >&6 else eval "$3=\$ac_header_compiler" fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } fi eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} } # ac_fn_c_check_header_mongrel # ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists and can be compiled using the include files in # INCLUDES, setting the cache variable VAR accordingly. ac_fn_c_check_header_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval "test \"\${$3+set}\"" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF if ac_fn_c_try_compile "$LINENO"; then : eval "$3=yes" else eval "$3=no" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} } # ac_fn_c_check_header_compile cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by esip $as_me 0.1.0, which was generated by GNU Autoconf 2.67. Invocation command line was $ $0 $@ _ACEOF exec 5>>config.log { cat <<_ASUNAME ## --------- ## ## Platform. ## ## --------- ## hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` uname -m = `(uname -m) 2>/dev/null || echo unknown` uname -r = `(uname -r) 2>/dev/null || echo unknown` uname -s = `(uname -s) 2>/dev/null || echo unknown` uname -v = `(uname -v) 2>/dev/null || echo unknown` /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` /bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` /bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` /usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` /bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` /bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` _ASUNAME as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. $as_echo "PATH: $as_dir" done IFS=$as_save_IFS } >&5 cat >&5 <<_ACEOF ## ----------- ## ## Core tests. ## ## ----------- ## _ACEOF # Keep a trace of the command line. # Strip out --no-create and --no-recursion so they do not pile up. # Strip out --silent because we don't want to record it for future runs. # Also quote any args containing shell meta-characters. # Make two passes to allow for proper duplicate-argument suppression. ac_configure_args= ac_configure_args0= ac_configure_args1= ac_must_keep_next=false for ac_pass in 1 2 do for ac_arg do case $ac_arg in -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) continue ;; *\'*) ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac case $ac_pass in 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; 2) as_fn_append ac_configure_args1 " '$ac_arg'" if test $ac_must_keep_next = true; then ac_must_keep_next=false # Got value, back to normal. else case $ac_arg in *=* | --config-cache | -C | -disable-* | --disable-* \ | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ | -with-* | --with-* | -without-* | --without-* | --x) case "$ac_configure_args0 " in "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; esac ;; -* ) ac_must_keep_next=true ;; esac fi as_fn_append ac_configure_args " '$ac_arg'" ;; esac done done { ac_configure_args0=; unset ac_configure_args0;} { ac_configure_args1=; unset ac_configure_args1;} # When interrupted or exit'd, cleanup temporary files, and complete # config.log. We remove comments because anyway the quotes in there # would cause problems or look ugly. # WARNING: Use '\'' to represent an apostrophe within the trap. # WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. trap 'exit_status=$? # Save into config.log some information that might help in debugging. { echo $as_echo "## ---------------- ## ## Cache variables. ## ## ---------------- ##" echo # The following way of writing the cache mishandles newlines in values, ( for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( *${as_nl}ac_space=\ *) sed -n \ "s/'\''/'\''\\\\'\'''\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" ;; #( *) sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) echo $as_echo "## ----------------- ## ## Output variables. ## ## ----------------- ##" echo for ac_var in $ac_subst_vars do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo if test -n "$ac_subst_files"; then $as_echo "## ------------------- ## ## File substitutions. ## ## ------------------- ##" echo for ac_var in $ac_subst_files do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo fi if test -s confdefs.h; then $as_echo "## ----------- ## ## confdefs.h. ## ## ----------- ##" echo cat confdefs.h echo fi test "$ac_signal" != 0 && $as_echo "$as_me: caught signal $ac_signal" $as_echo "$as_me: exit $exit_status" } >&5 rm -f core *.core core.conftest.* && rm -f -r conftest* confdefs* conf$$* $ac_clean_files && exit $exit_status ' 0 for ac_signal in 1 2 13 15; do trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal done ac_signal=0 # confdefs.h avoids OS command line length limits that DEFS can exceed. rm -f -r conftest* confdefs.h $as_echo "/* confdefs.h */" > confdefs.h # Predefined preprocessor variables. cat >>confdefs.h <<_ACEOF #define PACKAGE_NAME "$PACKAGE_NAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_TARNAME "$PACKAGE_TARNAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_VERSION "$PACKAGE_VERSION" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_STRING "$PACKAGE_STRING" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_URL "$PACKAGE_URL" _ACEOF # Let the site file select an alternate cache file if it wants to. # Prefer an explicitly selected file to automatically selected ones. ac_site_file1=NONE ac_site_file2=NONE if test -n "$CONFIG_SITE"; then # We do not want a PATH search for config.site. case $CONFIG_SITE in #(( -*) ac_site_file1=./$CONFIG_SITE;; */*) ac_site_file1=$CONFIG_SITE;; *) ac_site_file1=./$CONFIG_SITE;; esac elif test "x$prefix" != xNONE; then ac_site_file1=$prefix/share/config.site ac_site_file2=$prefix/etc/config.site else ac_site_file1=$ac_default_prefix/share/config.site ac_site_file2=$ac_default_prefix/etc/config.site fi for ac_site_file in "$ac_site_file1" "$ac_site_file2" do test "x$ac_site_file" = xNONE && continue if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 $as_echo "$as_me: loading site script $ac_site_file" >&6;} sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" \ || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "failed to load site script $ac_site_file See \`config.log' for more details" "$LINENO" 5 ; } fi done if test -r "$cache_file"; then # Some versions of bash will fail to source /dev/null (special files # actually), so we avoid doing that. DJGPP emulates it as a regular file. if test /dev/null != "$cache_file" && test -f "$cache_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 $as_echo "$as_me: loading cache $cache_file" >&6;} case $cache_file in [\\/]* | ?:[\\/]* ) . "$cache_file";; *) . "./$cache_file";; esac fi else { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 $as_echo "$as_me: creating cache $cache_file" >&6;} >$cache_file fi # Check that the precious variables saved in the cache have kept the same # value. ac_cache_corrupted=false for ac_var in $ac_precious_vars; do eval ac_old_set=\$ac_cv_env_${ac_var}_set eval ac_new_set=\$ac_env_${ac_var}_set eval ac_old_val=\$ac_cv_env_${ac_var}_value eval ac_new_val=\$ac_env_${ac_var}_value case $ac_old_set,$ac_new_set in set,) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} ac_cache_corrupted=: ;; ,set) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} ac_cache_corrupted=: ;; ,);; *) if test "x$ac_old_val" != "x$ac_new_val"; then # differences in whitespace do not lead to failure. ac_old_val_w=`echo x $ac_old_val` ac_new_val_w=`echo x $ac_new_val` if test "$ac_old_val_w" != "$ac_new_val_w"; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 $as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} ac_cache_corrupted=: else { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 $as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} eval $ac_var=\$ac_old_val fi { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 $as_echo "$as_me: former value: \`$ac_old_val'" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 $as_echo "$as_me: current value: \`$ac_new_val'" >&2;} fi;; esac # Pass precious variables to config.status. if test "$ac_new_set" = set; then case $ac_new_val in *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; *) ac_arg=$ac_var=$ac_new_val ;; esac case " $ac_configure_args " in *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. *) as_fn_append ac_configure_args " '$ac_arg'" ;; esac fi done if $ac_cache_corrupted; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 $as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 fi ## -------------------- ## ## Main body of script. ## ## -------------------- ## ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu # Checks for programs. ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. set dummy ${ac_tool_prefix}gcc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_CC+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_CC"; then ac_ct_CC=$CC # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_ac_ct_CC+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 $as_echo "$ac_ct_CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi else CC="$ac_cv_prog_CC" fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. set dummy ${ac_tool_prefix}cc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_CC+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="${ac_tool_prefix}cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi fi if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_CC+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else ac_prog_rejected=no as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue fi ac_cv_prog_CC="cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS if test $ac_prog_rejected = yes; then # We found a bogon in the path, so make sure we never use it. set dummy $ac_cv_prog_CC shift if test $# != 0; then # We chose a different compiler from the bogus one. # However, it has the same basename, so the bogon will be chosen # first if we set CC to just the basename; use the full file name. shift ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" fi fi fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then for ac_prog in cl.exe do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_CC+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$CC" && break done fi if test -z "$CC"; then ac_ct_CC=$CC for ac_prog in cl.exe do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_prog_ac_ct_CC+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_prog_ac_ct_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 $as_echo "$ac_ct_CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$ac_ct_CC" && break done if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi fi fi test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "no acceptable C compiler found in \$PATH See \`config.log' for more details" "$LINENO" 5 ; } # Provide some information about the compiler. $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 set X $ac_compile ac_compiler=$2 for ac_option in --version -v -V -qversion; do { { ac_try="$ac_compiler $ac_option >&5" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compiler $ac_option >&5") 2>conftest.err ac_status=$? if test -s conftest.err; then sed '10a\ ... rest of stderr output deleted ... 10q' conftest.err >conftest.er1 cat conftest.er1 >&5 fi rm -f conftest.er1 conftest.err $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" # Try to create an executable without -o first, disregard a.out. # It will help us diagnose broken compilers, and finding out an intuition # of exeext. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 $as_echo_n "checking whether the C compiler works... " >&6; } ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` # The possible output files: ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" ac_rmfiles= for ac_file in $ac_files do case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; * ) ac_rmfiles="$ac_rmfiles $ac_file";; esac done rm -f $ac_rmfiles if { { ac_try="$ac_link_default" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link_default") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. # So ignore a value of `no', otherwise this would lead to `EXEEXT = no' # in a Makefile. We should not override ac_cv_exeext if it was cached, # so that the user can short-circuit this test for compilers unknown to # Autoconf. for ac_file in $ac_files '' do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; [ab].out ) # We found the default executable, but exeext='' is most # certainly right. break;; *.* ) if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; then :; else ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` fi # We set ac_cv_exeext here because the later test for it is not # safe: cross compilers may not add the suffix if given an `-o' # argument, so we may need to know it at that point already. # Even if this section looks crufty: it has the advantage of # actually working. break;; * ) break;; esac done test "$ac_cv_exeext" = no && ac_cv_exeext= else ac_file='' fi if test -z "$ac_file"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "C compiler cannot create executables See \`config.log' for more details" "$LINENO" 5 ; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 $as_echo_n "checking for C compiler default output file name... " >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 $as_echo "$ac_file" >&6; } ac_exeext=$ac_cv_exeext rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 $as_echo_n "checking for suffix of executables... " >&6; } if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : # If both `conftest.exe' and `conftest' are `present' (well, observable) # catch `conftest.exe'. For instance with Cygwin, `ls conftest' will # work properly (i.e., refer to `conftest.exe'), while it won't with # `rm'. for ac_file in conftest.exe conftest conftest.*; do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` break;; * ) break;; esac done else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of executables: cannot compile and link See \`config.log' for more details" "$LINENO" 5 ; } fi rm -f conftest conftest$ac_cv_exeext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 $as_echo "$ac_cv_exeext" >&6; } rm -f conftest.$ac_ext EXEEXT=$ac_cv_exeext ac_exeext=$EXEEXT cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { FILE *f = fopen ("conftest.out", "w"); return ferror (f) || fclose (f) != 0; ; return 0; } _ACEOF ac_clean_files="$ac_clean_files conftest.out" # Check that the compiler produces executables we can run. If not, either # the compiler is broken, or we cross compile. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 $as_echo_n "checking whether we are cross compiling... " >&6; } if test "$cross_compiling" != yes; then { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if { ac_try='./conftest$ac_cv_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then cross_compiling=no else if test "$cross_compiling" = maybe; then cross_compiling=yes else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot run C compiled programs. If you meant to cross compile, use \`--host'. See \`config.log' for more details" "$LINENO" 5 ; } fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 $as_echo "$cross_compiling" >&6; } rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 $as_echo_n "checking for suffix of object files... " >&6; } if test "${ac_cv_objext+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF rm -f conftest.o conftest.obj if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : for ac_file in conftest.o conftest.obj conftest.*; do test -f "$ac_file" || continue; case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` break;; esac done else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of object files: cannot compile See \`config.log' for more details" "$LINENO" 5 ; } fi rm -f conftest.$ac_cv_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 $as_echo "$ac_cv_objext" >&6; } OBJEXT=$ac_cv_objext ac_objext=$OBJEXT { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 $as_echo_n "checking whether we are using the GNU C compiler... " >&6; } if test "${ac_cv_c_compiler_gnu+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { #ifndef __GNUC__ choke me #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_compiler_gnu=yes else ac_compiler_gnu=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_cv_c_compiler_gnu=$ac_compiler_gnu fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 $as_echo "$ac_cv_c_compiler_gnu" >&6; } if test $ac_compiler_gnu = yes; then GCC=yes else GCC= fi ac_test_CFLAGS=${CFLAGS+set} ac_save_CFLAGS=$CFLAGS { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 $as_echo_n "checking whether $CC accepts -g... " >&6; } if test "${ac_cv_prog_cc_g+set}" = set; then : $as_echo_n "(cached) " >&6 else ac_save_c_werror_flag=$ac_c_werror_flag ac_c_werror_flag=yes ac_cv_prog_cc_g=no CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes else CFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : else ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_c_werror_flag=$ac_save_c_werror_flag fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 $as_echo "$ac_cv_prog_cc_g" >&6; } if test "$ac_test_CFLAGS" = set; then CFLAGS=$ac_save_CFLAGS elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then CFLAGS="-g -O2" else CFLAGS="-g" fi else if test "$GCC" = yes; then CFLAGS="-O2" else CFLAGS= fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 $as_echo_n "checking for $CC option to accept ISO C89... " >&6; } if test "${ac_cv_prog_cc_c89+set}" = set; then : $as_echo_n "(cached) " >&6 else ac_cv_prog_cc_c89=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include #include /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ struct buf { int x; }; FILE * (*rcsopen) (struct buf *, struct stat *, int); static char *e (p, i) char **p; int i; { return p[i]; } static char *f (char * (*g) (char **, int), char **p, ...) { char *s; va_list v; va_start (v,p); s = g (p, va_arg (v,int)); va_end (v); return s; } /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has function prototypes and stuff, but not '\xHH' hex character constants. These don't provoke an error unfortunately, instead are silently treated as 'x'. The following induces an error, until -std is added to get proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an array size at least. It's necessary to write '\x00'==0 to get something that's true only with -std. */ int osf4_cc_array ['\x00' == 0 ? 1 : -1]; /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters inside strings and character constants. */ #define FOO(x) 'x' int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; int test (int i, double x); struct s1 {int (*f) (int a);}; struct s2 {int (*f) (double a);}; int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); int argc; char **argv; int main () { return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; ; return 0; } _ACEOF for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" do CC="$ac_save_CC $ac_arg" if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_c89=$ac_arg fi rm -f core conftest.err conftest.$ac_objext test "x$ac_cv_prog_cc_c89" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC fi # AC_CACHE_VAL case "x$ac_cv_prog_cc_c89" in x) { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 $as_echo "none needed" >&6; } ;; xno) { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 $as_echo "unsupported" >&6; } ;; *) CC="$CC $ac_cv_prog_cc_c89" { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 $as_echo "$ac_cv_prog_cc_c89" >&6; } ;; esac if test "x$ac_cv_prog_cc_c89" != xno; then : fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 $as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } set x ${MAKE-make} ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` if eval "test \"\${ac_cv_prog_make_${ac_make}_set+set}\"" = set; then : $as_echo_n "(cached) " >&6 else cat >conftest.make <<\_ACEOF SHELL = /bin/sh all: @echo '@@@%%%=$(MAKE)=@@@%%%' _ACEOF # GNU make sometimes prints "make[1]: Entering ...", which would confuse us. case `${MAKE-make} -f conftest.make 2>/dev/null` in *@@@%%%=?*=@@@%%%*) eval ac_cv_prog_make_${ac_make}_set=yes;; *) eval ac_cv_prog_make_${ac_make}_set=no;; esac rm -f conftest.make fi if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } SET_MAKE= else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } SET_MAKE="MAKE=${MAKE-make}" fi if test "x$GCC" = "xyes"; then CFLAGS="$CFLAGS -Wall" fi # Checks for typedefs, structures, and compiler characteristics. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5 $as_echo_n "checking for an ANSI C-conforming const... " >&6; } if test "${ac_cv_c_const+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { /* FIXME: Include the comments suggested by Paul. */ #ifndef __cplusplus /* Ultrix mips cc rejects this. */ typedef int charset[2]; const charset cs; /* SunOS 4.1.1 cc rejects this. */ char const *const *pcpcc; char **ppc; /* NEC SVR4.0.2 mips cc rejects this. */ struct point {int x, y;}; static struct point const zero = {0,0}; /* AIX XL C 1.02.0.0 rejects this. It does not let you subtract one const X* pointer from another in an arm of an if-expression whose if-part is not a constant expression */ const char *g = "string"; pcpcc = &g + (g ? g-g : 0); /* HPUX 7.0 cc rejects these. */ ++pcpcc; ppc = (char**) pcpcc; pcpcc = (char const *const *) ppc; { /* SCO 3.2v4 cc rejects this. */ char *t; char const *s = 0 ? (char *) 0 : (char const *) 0; *t++ = 0; if (s) return 0; } { /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */ int x[] = {25, 17}; const int *foo = &x[0]; ++foo; } { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */ typedef const int *iptr; iptr p = 0; ++p; } { /* AIX XL C 1.02.0.0 rejects this saying "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */ struct s { int j; const int *ap[3]; }; struct s *b; b->j = 5; } { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */ const int foo = 10; if (!foo) return 0; } return !cs[0] && !zero.x; #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_c_const=yes else ac_cv_c_const=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5 $as_echo "$ac_cv_c_const" >&6; } if test $ac_cv_c_const = no; then $as_echo "#define const /**/" >>confdefs.h fi # Checks for library functions. ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 $as_echo_n "checking how to run the C preprocessor... " >&6; } # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= fi if test -z "$CPP"; then if test "${ac_cv_prog_CPP+set}" = set; then : $as_echo_n "(cached) " >&6 else # Double quotes because CPP needs to be expanded for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" do ac_preproc_ok=false for ac_c_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. # Prefer to if __STDC__ is defined, since # exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __STDC__ # include #else # include #endif Syntax error _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : else # Broken: fails on valid input. continue fi rm -f conftest.err conftest.i conftest.$ac_ext # OK, works on sane cases. Now check whether nonexistent headers # can be detected and how. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : # Broken: success on invalid input. continue else # Passes both tests. ac_preproc_ok=: break fi rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext if $ac_preproc_ok; then : break fi done ac_cv_prog_CPP=$CPP fi CPP=$ac_cv_prog_CPP else ac_cv_prog_CPP=$CPP fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 $as_echo "$CPP" >&6; } ac_preproc_ok=false for ac_c_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. # Prefer to if __STDC__ is defined, since # exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __STDC__ # include #else # include #endif Syntax error _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : else # Broken: fails on valid input. continue fi rm -f conftest.err conftest.i conftest.$ac_ext # OK, works on sane cases. Now check whether nonexistent headers # can be detected and how. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : # Broken: success on invalid input. continue else # Passes both tests. ac_preproc_ok=: break fi rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext if $ac_preproc_ok; then : else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "C preprocessor \"$CPP\" fails sanity check See \`config.log' for more details" "$LINENO" 5 ; } fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu { $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 $as_echo_n "checking for grep that handles long lines and -e... " >&6; } if test "${ac_cv_path_GREP+set}" = set; then : $as_echo_n "(cached) " >&6 else if test -z "$GREP"; then ac_path_GREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in grep ggrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue # Check for GNU ac_path_GREP and select it if it is found. # Check for GNU $ac_path_GREP case `"$ac_path_GREP" --version 2>&1` in *GNU*) ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; *) ac_count=0 $as_echo_n 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" $as_echo 'GREP' >> "conftest.nl" "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_GREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_GREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_GREP"; then as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_GREP=$GREP fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 $as_echo "$ac_cv_path_GREP" >&6; } GREP="$ac_cv_path_GREP" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 $as_echo_n "checking for egrep... " >&6; } if test "${ac_cv_path_EGREP+set}" = set; then : $as_echo_n "(cached) " >&6 else if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 then ac_cv_path_EGREP="$GREP -E" else if test -z "$EGREP"; then ac_path_EGREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in egrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue # Check for GNU ac_path_EGREP and select it if it is found. # Check for GNU $ac_path_EGREP case `"$ac_path_EGREP" --version 2>&1` in *GNU*) ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; *) ac_count=0 $as_echo_n 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" $as_echo 'EGREP' >> "conftest.nl" "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_EGREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_EGREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_EGREP"; then as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_EGREP=$EGREP fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 $as_echo "$ac_cv_path_EGREP" >&6; } EGREP="$ac_cv_path_EGREP" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 $as_echo_n "checking for ANSI C header files... " >&6; } if test "${ac_cv_header_stdc+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include #include int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_header_stdc=yes else ac_cv_header_stdc=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "memchr" >/dev/null 2>&1; then : else ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "free" >/dev/null 2>&1; then : else ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. if test "$cross_compiling" = yes; then : : else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #if ((' ' & 0x0FF) == 0x020) # define ISLOWER(c) ('a' <= (c) && (c) <= 'z') # define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) #else # define ISLOWER(c) \ (('a' <= (c) && (c) <= 'i') \ || ('j' <= (c) && (c) <= 'r') \ || ('s' <= (c) && (c) <= 'z')) # define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) #endif #define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) int main () { int i; for (i = 0; i < 256; i++) if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) return 2; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : else ac_cv_header_stdc=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 $as_echo "$ac_cv_header_stdc" >&6; } if test $ac_cv_header_stdc = yes; then $as_echo "#define STDC_HEADERS 1" >>confdefs.h fi # On IRIX 5.3, sys/types and inttypes.h are conflicting. for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ inttypes.h stdint.h unistd.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default " if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 _ACEOF fi done for ac_header in stdlib.h do : ac_fn_c_check_header_mongrel "$LINENO" "stdlib.h" "ac_cv_header_stdlib_h" "$ac_includes_default" if test "x$ac_cv_header_stdlib_h" = x""yes; then : cat >>confdefs.h <<_ACEOF #define HAVE_STDLIB_H 1 _ACEOF fi done { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU libc compatible malloc" >&5 $as_echo_n "checking for GNU libc compatible malloc... " >&6; } if test "${ac_cv_func_malloc_0_nonnull+set}" = set; then : $as_echo_n "(cached) " >&6 else if test "$cross_compiling" = yes; then : ac_cv_func_malloc_0_nonnull=no else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #if defined STDC_HEADERS || defined HAVE_STDLIB_H # include #else char *malloc (); #endif int main () { return ! malloc (0); ; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : ac_cv_func_malloc_0_nonnull=yes else ac_cv_func_malloc_0_nonnull=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_malloc_0_nonnull" >&5 $as_echo "$ac_cv_func_malloc_0_nonnull" >&6; } if test $ac_cv_func_malloc_0_nonnull = yes; then : $as_echo "#define HAVE_MALLOC 1" >>confdefs.h else $as_echo "#define HAVE_MALLOC 0" >>confdefs.h case " $LIBOBJS " in *" malloc.$ac_objext "* ) ;; *) LIBOBJS="$LIBOBJS malloc.$ac_objext" ;; esac $as_echo "#define malloc rpl_malloc" >>confdefs.h fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 $as_echo_n "checking for ANSI C header files... " >&6; } if test "${ac_cv_header_stdc+set}" = set; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include #include int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_header_stdc=yes else ac_cv_header_stdc=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "memchr" >/dev/null 2>&1; then : else ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "free" >/dev/null 2>&1; then : else ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. if test "$cross_compiling" = yes; then : : else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #if ((' ' & 0x0FF) == 0x020) # define ISLOWER(c) ('a' <= (c) && (c) <= 'z') # define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) #else # define ISLOWER(c) \ (('a' <= (c) && (c) <= 'i') \ || ('j' <= (c) && (c) <= 'r') \ || ('s' <= (c) && (c) <= 'z')) # define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) #endif #define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) int main () { int i; for (i = 0; i < 256; i++) if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) return 2; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : else ac_cv_header_stdc=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 $as_echo "$ac_cv_header_stdc" >&6; } if test $ac_cv_header_stdc = yes; then $as_echo "#define STDC_HEADERS 1" >>confdefs.h fi # Checks Erlang runtime and compiler if test -n "$ERL"; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for erl" >&5 $as_echo_n "checking for erl... " >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ERL" >&5 $as_echo "$ERL" >&6; } else if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}erl", so it can be a program name with args. set dummy ${ac_tool_prefix}erl; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_path_ERL+set}" = set; then : $as_echo_n "(cached) " >&6 else case $ERL in [\\/]* | ?:[\\/]*) ac_cv_path_ERL="$ERL" # Let the user override the test with a path. ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_ERL="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS ;; esac fi ERL=$ac_cv_path_ERL if test -n "$ERL"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ERL" >&5 $as_echo "$ERL" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_path_ERL"; then ac_pt_ERL=$ERL # Extract the first word of "erl", so it can be a program name with args. set dummy erl; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_path_ac_pt_ERL+set}" = set; then : $as_echo_n "(cached) " >&6 else case $ac_pt_ERL in [\\/]* | ?:[\\/]*) ac_cv_path_ac_pt_ERL="$ac_pt_ERL" # Let the user override the test with a path. ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_ac_pt_ERL="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS ;; esac fi ac_pt_ERL=$ac_cv_path_ac_pt_ERL if test -n "$ac_pt_ERL"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_ERL" >&5 $as_echo "$ac_pt_ERL" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_pt_ERL" = x; then ERL="not found" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac ERL=$ac_pt_ERL fi else ERL="$ac_cv_path_ERL" fi fi if test "$ERL" = "not found"; then as_fn_error $? "Erlang/OTP interpreter (erl) not found but required" "$LINENO" 5 fi if test -n "$ERLC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for erlc" >&5 $as_echo_n "checking for erlc... " >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ERLC" >&5 $as_echo "$ERLC" >&6; } else if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}erlc", so it can be a program name with args. set dummy ${ac_tool_prefix}erlc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_path_ERLC+set}" = set; then : $as_echo_n "(cached) " >&6 else case $ERLC in [\\/]* | ?:[\\/]*) ac_cv_path_ERLC="$ERLC" # Let the user override the test with a path. ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_ERLC="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS ;; esac fi ERLC=$ac_cv_path_ERLC if test -n "$ERLC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ERLC" >&5 $as_echo "$ERLC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_path_ERLC"; then ac_pt_ERLC=$ERLC # Extract the first word of "erlc", so it can be a program name with args. set dummy erlc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if test "${ac_cv_path_ac_pt_ERLC+set}" = set; then : $as_echo_n "(cached) " >&6 else case $ac_pt_ERLC in [\\/]* | ?:[\\/]*) ac_cv_path_ac_pt_ERLC="$ac_pt_ERLC" # Let the user override the test with a path. ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then ac_cv_path_ac_pt_ERLC="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS ;; esac fi ac_pt_ERLC=$ac_cv_path_ac_pt_ERLC if test -n "$ac_pt_ERLC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_ERLC" >&5 $as_echo "$ac_pt_ERLC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_pt_ERLC" = x; then ERLC="not found" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac ERLC=$ac_pt_ERLC fi else ERLC="$ac_cv_path_ERLC" fi fi if test "$ERLC" = "not found"; then as_fn_error $? "Erlang/OTP compiler (erlc) not found but required" "$LINENO" 5 fi # Checks and sets ERLANG_ROOT_DIR and ERLANG_LIB_DIR variable # AC_ERLANG_SUBST_ROOT_DIR # AC_ERLANG_SUBST_LIB_DIR cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure # scripts and configure runs, see configure's option --config-cache. # It is not useful on other systems. If it contains results you don't # want to keep, you may remove or edit it. # # config.status only pays attention to the cache file if you give it # the --recheck option to rerun configure. # # `ac_cv_env_foo' variables (set or unset) will be overridden when # loading this file, other *unset* `ac_cv_foo' will be assigned the # following values. _ACEOF # The following way of writing the cache mishandles newlines in values, # but we know of no workaround that is simple, portable, and efficient. # So, we kill variables containing newlines. # Ultrix sh set writes to stderr and can't be redirected directly, # and sets the high bit in the cache file unless we assign to the vars. ( for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space=' '; set) 2>&1` in #( *${as_nl}ac_space=\ *) # `set' does not quote correctly, so add quotes: double-quote # substitution turns \\\\ into \\, and sed turns \\ into \. sed -n \ "s/'/'\\\\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" ;; #( *) # `set' quotes correctly as required by POSIX, so do not add quotes. sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) | sed ' /^ac_cv_env_/b end t clear :clear s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ t end s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ :end' >>confcache if diff "$cache_file" confcache >/dev/null 2>&1; then :; else if test -w "$cache_file"; then test "x$cache_file" != "x/dev/null" && { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 $as_echo "$as_me: updating cache $cache_file" >&6;} cat confcache >$cache_file else { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 $as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} fi fi rm -f confcache test "x$prefix" = xNONE && prefix=$ac_default_prefix # Let make expand exec_prefix. test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' # Transform confdefs.h into DEFS. # Protect against shell expansion while executing Makefile rules. # Protect against Makefile macro expansion. # # If the first sed substitution is executed (which looks for macros that # take arguments), then branch to the quote section. Otherwise, # look for a macro that doesn't take arguments. ac_script=' :mline /\\$/{ N s,\\\n,, b mline } t clear :clear s/^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*([^)]*)\)[ ]*\(.*\)/-D\1=\2/g t quote s/^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)/-D\1=\2/g t quote b any :quote s/[ `~#$^&*(){}\\|;'\''"<>?]/\\&/g s/\[/\\&/g s/\]/\\&/g s/\$/$$/g H :any ${ g s/^\n// s/\n/ /g p } ' DEFS=`sed -n "$ac_script" confdefs.h` ac_libobjs= ac_ltlibobjs= U= for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue # 1. Remove the extension, and $U if already installed. ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' ac_i=`$as_echo "$ac_i" | sed "$ac_script"` # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR # will be set to the directory where LIBOBJS objects are built. as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' done LIBOBJS=$ac_libobjs LTLIBOBJS=$ac_ltlibobjs : ${CONFIG_STATUS=./config.status} ac_write_fail=0 ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files $CONFIG_STATUS" { $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 $as_echo "$as_me: creating $CONFIG_STATUS" >&6;} as_write_fail=0 cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 #! $SHELL # Generated by $as_me. # Run this file to recreate the current configuration. # Compiler output produced by configure, useful for debugging # configure, is in config.log if it exists. debug=false ac_cs_recheck=false ac_cs_silent=false SHELL=\${CONFIG_SHELL-$SHELL} export SHELL _ASEOF cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi as_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in #( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # IFS # We need space, tab and new line, in precisely that order. Quoting is # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -p'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -p' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -p' fi else as_ln_s='cp -p' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi if test -x / >/dev/null 2>&1; then as_test_x='test -x' else if ls -dL / >/dev/null 2>&1; then as_ls_L_option=L else as_ls_L_option= fi as_test_x=' eval sh -c '\'' if test -d "$1"; then test -d "$1/."; else case $1 in #( -*)set "./$1";; esac; case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( ???[sx]*):;;*)false;;esac;fi '\'' sh ' fi as_executable_p=$as_test_x # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" exec 6>&1 ## ----------------------------------- ## ## Main body of $CONFIG_STATUS script. ## ## ----------------------------------- ## _ASEOF test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Save the log message, to keep $0 and so on meaningful, and to # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" This file was extended by esip $as_me 0.1.0, which was generated by GNU Autoconf 2.67. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS CONFIG_LINKS = $CONFIG_LINKS CONFIG_COMMANDS = $CONFIG_COMMANDS $ $0 $@ on `(hostname || uname -n) 2>/dev/null | sed 1q` " _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 # Files that config.status was made for. _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 ac_cs_usage="\ \`$as_me' instantiates files and other configuration actions from templates according to the current configuration. Unless the files and actions are specified as TAGs, all are instantiated by default. Usage: $0 [OPTION]... [TAG]... -h, --help print this help, then exit -V, --version print version number and configuration settings, then exit --config print configuration, then exit -q, --quiet, --silent do not print progress messages -d, --debug don't remove temporary files --recheck update $as_me by reconfiguring in the same conditions Report bugs to the package provider." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ esip config.status 0.1.0 configured by $0, generated by GNU Autoconf 2.67, with options \\"\$ac_cs_config\\" Copyright (C) 2010 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." ac_pwd='$ac_pwd' srcdir='$srcdir' test -n "\$AWK" || AWK=awk _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # The default lists apply if the user does not specify any file. ac_need_defaults=: while test $# != 0 do case $1 in --*=?*) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` ac_shift=: ;; --*=) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg= ac_shift=: ;; *) ac_option=$1 ac_optarg=$2 ac_shift=shift ;; esac case $ac_option in # Handling of the options. -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) ac_cs_recheck=: ;; --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) $as_echo "$ac_cs_version"; exit ;; --config | --confi | --conf | --con | --co | --c ) $as_echo "$ac_cs_config"; exit ;; --debug | --debu | --deb | --de | --d | -d ) debug=: ;; --he | --h | --help | --hel | -h ) $as_echo "$ac_cs_usage"; exit ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil | --si | --s) ac_cs_silent=: ;; # This is an error. -*) as_fn_error $? "unrecognized option: \`$1' Try \`$0 --help' for more information." ;; *) as_fn_append ac_config_targets " $1" ac_need_defaults=false ;; esac shift done ac_configure_extra_args= if $ac_cs_silent; then exec 6>/dev/null ac_configure_extra_args="$ac_configure_extra_args --silent" fi _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' export CONFIG_SHELL exec "\$@" fi _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 exec 5>>config.log { echo sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX ## Running $as_me. ## _ASBOX $as_echo "$ac_log" } >&5 _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Handling of arguments. for ac_config_target in $ac_config_targets do case $ac_config_target in *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5 ;; esac done as_fn_exit 0 _ACEOF ac_clean_files=$ac_clean_files_save test $ac_write_fail = 0 || as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5 # configure is writing to config.log, and then calls config.status. # config.status does its own redirection, appending to config.log. # Unfortunately, on DOS this fails, as config.log is still kept open # by configure, so config.status won't be able to write to it; its # output is simply discarded. So we exec the FD to /dev/null, # effectively closing config.log, so it can be properly (re)opened and # appended to by config.status. When coming back to configure, we # need to make the FD available again. if test "$no_create" != yes; then ac_cs_success=: ac_config_status_args= test "$silent" = yes && ac_config_status_args="$ac_config_status_args --quiet" exec 5>/dev/null $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false exec 5>>config.log # Use ||, not &&, to avoid exiting from the if with $? = 1, which # would make configure fail if this is the last instruction. $ac_cs_success || as_fn_exit 1 fi if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi p1_sip-1.0.1/README.md0000644000175000017500000000006512650734252014550 0ustar debalancedebalance# p1_sip ProcessOne SIP server component in Erlang. p1_sip-1.0.1/Makefile0000644000175000017500000000314012650734252014726 0ustar debalancedebalanceREBAR=./rebar all: src src: $(REBAR) compile clean: $(REBAR) clean test: all $(REBAR) -v skip_deps=true eunit deps := $(wildcard deps/*/ebin) dialyzer/erlang.plt: @mkdir -p dialyzer @dialyzer --build_plt --output_plt dialyzer/erlang.plt \ -o dialyzer/erlang.log --apps kernel stdlib erts; \ status=$$? ; if [ $$status -ne 2 ]; then exit $$status; else exit 0; fi dialyzer/deps.plt: @mkdir -p dialyzer @dialyzer --build_plt --output_plt dialyzer/deps.plt \ -o dialyzer/deps.log $(deps); \ status=$$? ; if [ $$status -ne 2 ]; then exit $$status; else exit 0; fi dialyzer/esip.plt: @mkdir -p dialyzer @dialyzer --build_plt --output_plt dialyzer/esip.plt \ -o dialyzer/ejabberd.log ebin; \ status=$$? ; if [ $$status -ne 2 ]; then exit $$status; else exit 0; fi erlang_plt: dialyzer/erlang.plt @dialyzer --plt dialyzer/erlang.plt --check_plt -o dialyzer/erlang.log; \ status=$$? ; if [ $$status -ne 2 ]; then exit $$status; else exit 0; fi deps_plt: dialyzer/deps.plt @dialyzer --plt dialyzer/deps.plt --check_plt -o dialyzer/deps.log; \ status=$$? ; if [ $$status -ne 2 ]; then exit $$status; else exit 0; fi esip_plt: dialyzer/esip.plt @dialyzer --plt dialyzer/esip.plt --check_plt -o dialyzer/ejabberd.log; \ status=$$? ; if [ $$status -ne 2 ]; then exit $$status; else exit 0; fi dialyzer: erlang_plt deps_plt esip_plt @dialyzer --plts dialyzer/*.plt --no_check_plt \ --get_warnings -o dialyzer/error.log ebin; \ status=$$? ; if [ $$status -ne 2 ]; then exit $$status; else exit 0; fi check-syntax: gcc -o nul -S ${CHK_SOURCES} .PHONY: clean src test all dialyzer erlang_plt deps_plt esip_plt p1_sip-1.0.1/tests/0000755000175000017500000000000012650734252014432 5ustar debalancedebalancep1_sip-1.0.1/tests/rfc4475/0000755000175000017500000000000012650734252015530 5ustar debalancedebalancep1_sip-1.0.1/tests/rfc4475/scalar02.dat0000644000175000017500000000073412650734252017635 0ustar debalancedebalanceREGISTER sip:example.com SIP/2.0 Via: SIP/2.0/TCP host129.example.com;branch=z9hG4bK342sdfoi3 To: From: ;tag=239232jh3 CSeq: 36893488147419103232 REGISTER Call-ID: scalar02.23o0pd9vanlq3wnrlnewofjas9ui32 Max-Forwards: 300 Expires: 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 Contact: ;expires=280297596632815 Content-Length: 0 p1_sip-1.0.1/tests/rfc4475/badbranch.dat0000644000175000017500000000040612650734252020126 0ustar debalancedebalanceOPTIONS sip:user@example.com SIP/2.0 To: sip:user@example.com From: sip:caller@example.org;tag=33242 Max-Forwards: 3 Via: SIP/2.0/UDP 192.0.2.1;branch=z9hG4bK Accept: application/sdp Call-ID: badbranch.sadonfo23i420jv0as0derf3j3n CSeq: 8 OPTIONS l: 0 p1_sip-1.0.1/tests/rfc4475/cparam02.dat0000644000175000017500000000046712650734252017636 0ustar debalancedebalanceREGISTER sip:example.com SIP/2.0 Via: SIP/2.0/UDP saturn.example.com:5060;branch=z9hG4bKkdjuw Max-Forwards: 70 From: sip:watson@example.com;tag=838293 To: sip:watson@example.com Call-ID: cparam02.70710@saturn.example.com CSeq: 3 REGISTER Contact: l: 0 p1_sip-1.0.1/tests/rfc4475/insuf.dat0000644000175000017500000000046012650734252017346 0ustar debalancedebalanceINVITE sip:user@example.com SIP/2.0 CSeq: 193942 INVITE Via: SIP/2.0/UDP 192.0.2.95;branch=z9hG4bKkdj.insuf Content-Type: application/sdp l: 152 v=0 o=mhandley 29739 7272939 IN IP4 192.0.2.95 s=- c=IN IP4 192.0.2.95 t=0 0 m=audio 49217 RTP/AVP 0 12 m=video 3227 RTP/AVP 31 a=rtpmap:31 LPC p1_sip-1.0.1/tests/rfc4475/ncl.dat0000644000175000017500000000074612650734252017005 0ustar debalancedebalanceINVITE sip:user@example.com SIP/2.0 Max-Forwards: 254 To: sip:j.user@example.com From: sip:caller@example.net;tag=32394234 Call-ID: ncl.0ha0isndaksdj2193423r542w35 CSeq: 0 INVITE Via: SIP/2.0/UDP 192.0.2.53;branch=z9hG4bKkdjuw Contact: Content-Type: application/sdp Content-Length: -999 v=0 o=mhandley 29739 7272939 IN IP4 192.0.2.53 s=- c=IN IP4 192.0.2.53 t=0 0 m=audio 49217 RTP/AVP 0 12 m=video 3227 RTP/AVP 31 a=rtpmap:31 LPC p1_sip-1.0.1/tests/rfc4475/mcl01.dat0000644000175000017500000000057612650734252017146 0ustar debalancedebalanceOPTIONS sip:user@example.com SIP/2.0 Via: SIP/2.0/UDP host5.example.net;branch=z9hG4bK293423 To: sip:user@example.com From: sip:other@example.net;tag=3923942 Call-ID: mcl01.fhn2323orihawfdoa3o4r52o3irsdf CSeq: 15932 OPTIONS Content-Length: 13 Max-Forwards: 60 Content-Length: 5 Content-Type: text/plain There's no way to know how many octets are supposed to be here. p1_sip-1.0.1/tests/rfc4475/escruri.dat0000644000175000017500000000104612650734252017677 0ustar debalancedebalanceINVITE sip:user@example.com?Route=%3Csip:example.com%3E SIP/2.0 To: sip:user@example.com From: sip:caller@example.net;tag=341518 Max-Forwards: 7 Contact: Call-ID: escruri.23940-asdfhj-aje3br-234q098w-fawerh2q-h4n5 CSeq: 149209342 INVITE Via: SIP/2.0/UDP host-of-the-hour.example.com;branch=z9hG4bKkdjuw Content-Type: application/sdp Content-Length: 150 v=0 o=mhandley 29739 7272939 IN IP4 192.0.2.1 s=- c=IN IP4 192.0.2.1 t=0 0 m=audio 49217 RTP/AVP 0 12 m=video 3227 RTP/AVP 31 a=rtpmap:31 LPC p1_sip-1.0.1/tests/rfc4475/novelsc.dat0000644000175000017500000000042512650734252017674 0ustar debalancedebalanceOPTIONS soap.beep://192.0.2.103:3002 SIP/2.0 To: sip:user@example.com From: sip:caller@example.net;tag=384 Max-Forwards: 3 Call-ID: novelsc.asdfasser0q239nwsdfasdkl34 CSeq: 3923423 OPTIONS Via: SIP/2.0/TCP host9.example.com;branch=z9hG4bKkdjuw39234 Content-Length: 0 p1_sip-1.0.1/tests/rfc4475/intmeth.dat0000644000175000017500000000120112650734252017664 0ustar debalancedebalance!interesting-Method0123456789_*+`.%indeed'~ sip:1_unusual.URI~(to-be!sure)&isn't+it$/crazy?,/;;*:&it+has=1,weird!*pas$wo~d_too.(doesn't-it)@example.com SIP/2.0 Via: SIP/2.0/TCP host1.example.com;branch=z9hG4bK-.!%66*_+`'~ To: "BEL:\ NUL:\ DEL:\" From: token1~` token2'+_ token3*%!.- ;fromParam''~+*_!.-%="работающий";tag=_token~1'+`*%!-. Call-ID: intmeth.word%ZK-!.*_+'@word`~)(><:\/"][?}{ CSeq: 139122385 !interesting-Method0123456789_*+`.%indeed'~ Max-Forwards: 255 extensionHeader-!.%*+_`'~:大åœé›» Content-Length: 0 p1_sip-1.0.1/tests/rfc4475/esc02.dat0000644000175000017500000000066712650734252017147 0ustar debalancedebalanceRE%47IST%45R sip:registrar.example.com SIP/2.0 To: "%Z%45" From: "%Z%45" ;tag=f232jadfj23 Call-ID: esc02.asdfnqwo34rq23i34jrjasdcnl23nrlknsdf Via: SIP/2.0/TCP host.example.com;branch=z9hG4bK209%fzsnel234 CSeq: 29344 RE%47IST%45R Max-Forwards: 70 Contact: C%6Fntact: Contact: l: 0 p1_sip-1.0.1/tests/rfc4475/badinv01.dat0000644000175000017500000000073012650734252017626 0ustar debalancedebalanceINVITE sip:user@example.com SIP/2.0 To: sip:j.user@example.com From: sip:caller@example.net;tag=134161461246 Max-Forwards: 7 Call-ID: badinv01.0ha0isndaksdjasdf3234nas CSeq: 8 INVITE Via: SIP/2.0/UDP 192.0.2.15;;,;,, Contact: "Joe" ;;;; Content-Length: 152 Content-Type: application/sdp v=0 o=mhandley 29739 7272939 IN IP4 192.0.2.15 s=- c=IN IP4 192.0.2.15 t=0 0 m=audio 49217 RTP/AVP 0 12 m=video 3227 RTP/AVP 31 a=rtpmap:31 LPC p1_sip-1.0.1/tests/rfc4475/transports.dat0000644000175000017500000000076712650734252020453 0ustar debalancedebalanceOPTIONS sip:user@example.com SIP/2.0 To: sip:user@example.com From: ;tag=323 Max-Forwards: 70 Call-ID: transports.kijh4akdnaqjkwendsasfdj Accept: application/sdp CSeq: 60 OPTIONS Via: SIP/2.0/UDP t1.example.com;branch=z9hG4bKkdjuw Via: SIP/2.0/SCTP t2.example.com;branch=z9hG4bKklasjdhf Via: SIP/2.0/TLS t3.example.com;branch=z9hG4bK2980unddj Via: SIP/2.0/UNKNOWN t4.example.com;branch=z9hG4bKasd0f3en Via: SIP/2.0/TCP t5.example.com;branch=z9hG4bK0a9idfnee l: 0 p1_sip-1.0.1/tests/rfc4475/baddate.dat0000644000175000017500000000102412650734252017603 0ustar debalancedebalanceINVITE sip:user@example.com SIP/2.0 To: sip:user@example.com From: sip:caller@example.net;tag=2234923 Max-Forwards: 70 Call-ID: baddate.239423mnsadf3j23lj42--sedfnm234 CSeq: 1392934 INVITE Via: SIP/2.0/UDP host.example.com;branch=z9hG4bKkdjuw Date: Fri, 01 Jan 2010 16:00:00 EST Contact: Content-Type: application/sdp Content-Length: 150 v=0 o=mhandley 29739 7272939 IN IP4 192.0.2.5 s=- c=IN IP4 192.0.2.5 t=0 0 m=audio 49217 RTP/AVP 0 12 m=video 3227 RTP/AVP 31 a=rtpmap:31 LPC p1_sip-1.0.1/tests/rfc4475/semiuri.dat0000644000175000017500000000057412650734252017705 0ustar debalancedebalanceOPTIONS sip:user;par=u%40example.net@example.com SIP/2.0 To: sip:j_user@example.com From: sip:caller@example.org;tag=33242 Max-Forwards: 3 Call-ID: semiuri.0ha0isndaksdj CSeq: 8 OPTIONS Accept: application/sdp, application/pkcs7-mime, multipart/mixed, multipart/signed, message/sip, message/sipfrag Via: SIP/2.0/UDP 192.0.2.1;branch=z9hG4bKkdjuw l: 0 p1_sip-1.0.1/tests/rfc4475/bigcode.dat0000644000175000017500000000051412650734252017616 0ustar debalancedebalanceSIP/2.0 4294967301 better not break the receiver Via: SIP/2.0/UDP 192.0.2.105;branch=z9hG4bK2398ndaoe Call-ID: bigcode.asdof3uj203asdnf3429uasdhfas3ehjasdfas9i CSeq: 353494 INVITE From: ;tag=39ansfi3 To: ;tag=902jndnke3 Content-Length: 0 Contact: p1_sip-1.0.1/tests/rfc4475/quotbal.dat0000644000175000017500000000074512650734252017677 0ustar debalancedebalanceINVITE sip:user@example.com SIP/2.0 To: "Mr. J. User From: sip:caller@example.net;tag=93334 Max-Forwards: 10 Call-ID: quotbal.aksdj Contact: CSeq: 8 INVITE Via: SIP/2.0/UDP 192.0.2.59:5050;branch=z9hG4bKkdjuw39234 Content-Type: application/sdp Content-Length: 152 v=0 o=mhandley 29739 7272939 IN IP4 192.0.2.15 s=- c=IN IP4 192.0.2.15 t=0 0 m=audio 49217 RTP/AVP 0 12 m=video 3227 RTP/AVP 31 a=rtpmap:31 LPC p1_sip-1.0.1/tests/rfc4475/unkscm.dat0000644000175000017500000000044312650734252017523 0ustar debalancedebalanceOPTIONS nobodyKnowsThisScheme:totallyopaquecontent SIP/2.0 To: sip:user@example.com From: sip:caller@example.net;tag=384 Max-Forwards: 3 Call-ID: unkscm.nasdfasser0q239nwsdfasdkl34 CSeq: 3923423 OPTIONS Via: SIP/2.0/TCP host9.example.com;branch=z9hG4bKkdjuw39234 Content-Length: 0 p1_sip-1.0.1/tests/rfc4475/escnull.dat0000644000175000017500000000054712650734252017675 0ustar debalancedebalanceREGISTER sip:example.com SIP/2.0 To: sip:null-%00-null@example.com From: sip:null-%00-null@example.com;tag=839923423 Max-Forwards: 70 Call-ID: escnull.39203ndfvkjdasfkq3w4otrq0adsfdfnavd CSeq: 14398234 REGISTER Via: SIP/2.0/UDP host5.example.com;branch=z9hG4bKkdjuw Contact: Contact: L:0 p1_sip-1.0.1/tests/rfc4475/inv2543.dat0000644000175000017500000000067512650734252017344 0ustar debalancedebalanceINVITE sip:UserB@example.com SIP/2.0 Via: SIP/2.0/UDP iftgw.example.com From: Record-Route: To: sip:+16505552222@ss1.example.net;user=phone Call-ID: inv2543.1717@ift.client.example.com CSeq: 56 INVITE Content-Type: application/sdp v=0 o=mhandley 29739 7272939 IN IP4 192.0.2.5 s=- c=IN IP4 192.0.2.5 t=0 0 m=audio 49217 RTP/AVP 0 p1_sip-1.0.1/tests/rfc4475/mismatch01.dat0000644000175000017500000000035412650734252020172 0ustar debalancedebalanceOPTIONS sip:user@example.com SIP/2.0 To: sip:j.user@example.com From: sip:caller@example.net;tag=34525 Max-Forwards: 6 Call-ID: mismatch01.dj0234sxdfl3 CSeq: 8 INVITE Via: SIP/2.0/UDP host.example.com;branch=z9hG4bKkdjuw l: 0 p1_sip-1.0.1/tests/rfc4475/unreason.dat0000644000175000017500000000101612650734252020052 0ustar debalancedebalanceSIP/2.0 200 = 2**3 * 5**2 но Ñто девÑноÑто девÑть - проÑтое Via: SIP/2.0/UDP 192.0.2.198;branch=z9hG4bK1324923 Call-ID: unreason.1234ksdfak3j2erwedfsASdf CSeq: 35 INVITE From: sip:user@example.com;tag=11141343 To: sip:user@example.edu;tag=2229 Content-Length: 154 Content-Type: application/sdp Contact: v=0 o=mhandley 29739 7272939 IN IP4 192.0.2.198 s=- c=IN IP4 192.0.2.198 t=0 0 m=audio 49217 RTP/AVP 0 12 m=video 3227 RTP/AVP 31 a=rtpmap:31 LPC p1_sip-1.0.1/tests/rfc4475/lwsruri.dat0000644000175000017500000000103512650734252017730 0ustar debalancedebalanceINVITE sip:user@example.com; lr SIP/2.0 To: sip:user@example.com;tag=3xfe-9921883-z9f From: sip:caller@example.net;tag=231413434 Max-Forwards: 5 Call-ID: lwsruri.asdfasdoeoi2323-asdfwrn23-asd834rk423 CSeq: 2130706432 INVITE Via: SIP/2.0/UDP 192.0.2.1:5060;branch=z9hG4bKkdjuw2395 Contact: Content-Type: application/sdp Content-Length: 159 v=0 o=mhandley 29739 7272939 IN IP4 192.0.2.1 s=- c=IN IP4 192.0.2.1 t=3149328700 0 m=audio 49217 RTP/AVP 0 12 m=video 3227 RTP/AVP 31 a=rtpmap:31 LPC p1_sip-1.0.1/tests/rfc4475/mismatch02.dat0000644000175000017500000000070112650734252020167 0ustar debalancedebalanceNEWMETHOD sip:user@example.com SIP/2.0 To: sip:j.user@example.com From: sip:caller@example.net;tag=34525 Max-Forwards: 6 Call-ID: mismatch02.dj0234sxdfl3 CSeq: 8 INVITE Contact: Via: SIP/2.0/UDP host.example.net;branch=z9hG4bKkdjuw Content-Type: application/sdp l: 138 v=0 o=mhandley 29739 7272939 IN IP4 192.0.2.1 c=IN IP4 192.0.2.1 m=audio 49217 RTP/AVP 0 12 m=video 3227 RTP/AVP 31 a=rtpmap:31 LPC p1_sip-1.0.1/tests/rfc4475/baddn.dat0000644000175000017500000000051312650734252017271 0ustar debalancedebalanceOPTIONS sip:t.watson@example.org SIP/2.0 Via: SIP/2.0/UDP c.example.com:5060;branch=z9hG4bKkdjuw Max-Forwards: 70 From: Bell, Alexander ;tag=43 To: Watson, Thomas Call-ID: baddn.31415@c.example.com Accept: application/sdp CSeq: 3923239 OPTIONS l: 0 p1_sip-1.0.1/tests/rfc4475/clerr.dat0000644000175000017500000000076212650734252017336 0ustar debalancedebalanceINVITE sip:user@example.com SIP/2.0 Max-Forwards: 80 To: sip:j.user@example.com From: sip:caller@example.net;tag=93942939o2 Contact: Call-ID: clerr.0ha0isndaksdjweiafasdk3 CSeq: 8 INVITE Via: SIP/2.0/UDP host5.example.com;branch=z9hG4bK-39234-23523 Content-Type: application/sdp Content-Length: 9999 v=0 o=mhandley 29739 7272939 IN IP4 192.0.2.155 s=- c=IN IP4 192.0.2.155 t=0 0 m=audio 49217 RTP/AVP 0 12 m=video 3227 RTP/AVP 31 a=rtpmap:31 LPC p1_sip-1.0.1/tests/rfc4475/multi01.dat0000644000175000017500000000120312650734252017511 0ustar debalancedebalanceINVITE sip:user@company.com SIP/2.0 Contact: Via: SIP/2.0/UDP 192.0.2.25;branch=z9hG4bKkdjuw Max-Forwards: 70 CSeq: 5 INVITE Call-ID: multi01.98asdh@192.0.2.1 CSeq: 59 INVITE Call-ID: multi01.98asdh@192.0.2.2 From: sip:caller@example.com;tag=3413415 To: sip:user@example.com To: sip:other@example.net From: sip:caller@example.net;tag=2923420123 Content-Type: application/sdp l: 154 Contact: Max-Forwards: 5 v=0 o=mhandley 29739 7272939 IN IP4 192.0.2.25 s=- c=IN IP4 192.0.2.25 t=0 0 m=audio 49217 RTP/AVP 0 12 m=video 3227 RTP/AVP 31 a=rtpmap:31 LPC p1_sip-1.0.1/tests/rfc4475/lwsstart.dat0000644000175000017500000000077212650734252020113 0ustar debalancedebalanceINVITE sip:user@example.com SIP/2.0 Max-Forwards: 8 To: sip:user@example.com From: sip:caller@example.net;tag=8814 Call-ID: lwsstart.dfknq234oi243099adsdfnawe3@example.com CSeq: 1893884 INVITE Via: SIP/2.0/UDP host1.example.com;branch=z9hG4bKkdjuw3923 Contact: Content-Type: application/sdp Content-Length: 150 v=0 o=mhandley 29739 7272939 IN IP4 192.0.2.1 s=- c=IN IP4 192.0.2.1 t=0 0 m=audio 49217 RTP/AVP 0 12 m=video 3227 RTP/AVP 31 a=rtpmap:31 LPC p1_sip-1.0.1/tests/rfc4475/regaut01.dat0000644000175000017500000000046012650734252017652 0ustar debalancedebalanceREGISTER sip:example.com SIP/2.0 To: sip:j.user@example.com From: sip:j.user@example.com;tag=87321hj23128 Max-Forwards: 8 Call-ID: regaut01.0ha0isndaksdj CSeq: 9338 REGISTER Via: SIP/2.0/TCP 192.0.2.253;branch=z9hG4bKkdjuw Authorization: NoOneKnowsThisScheme opaque-data=here Content-Length:0 p1_sip-1.0.1/tests/rfc4475/invut.dat0000644000175000017500000000060712650734252017372 0ustar debalancedebalanceINVITE sip:user@example.com SIP/2.0 Contact: To: sip:j.user@example.com From: sip:caller@example.net;tag=8392034 Max-Forwards: 70 Call-ID: invut.0ha0isndaksdjadsfij34n23d CSeq: 235448 INVITE Via: SIP/2.0/UDP somehost.example.com;branch=z9hG4bKkdjuw Content-Type: application/unknownformat Content-Length: 40 p1_sip-1.0.1/tests/rfc4475/badvers.dat0000644000175000017500000000044312650734252017651 0ustar debalancedebalanceOPTIONS sip:t.watson@example.org SIP/7.0 Via: SIP/7.0/UDP c.example.com;branch=z9hG4bKkdjuw Max-Forwards: 70 From: A. Bell ;tag=qweoiqpe To: T. Watson Call-ID: badvers.31417@c.example.com CSeq: 1 OPTIONS l: 0 p1_sip-1.0.1/tests/rfc4475/bext01.dat0000644000175000017500000000057512650734252017334 0ustar debalancedebalanceOPTIONS sip:user@example.com SIP/2.0 To: sip:j_user@example.com From: sip:caller@example.net;tag=242etr Max-Forwards: 6 Call-ID: bext01.0ha0isndaksdj Require: nothingSupportsThis, nothingSupportsThisEither Proxy-Require: noProxiesSupportThis, norDoAnyProxiesSupportThis CSeq: 8 OPTIONS Via: SIP/2.0/TLS fold-and-staple.example.com;branch=z9hG4bKkdjuw Content-Length: 0 p1_sip-1.0.1/tests/rfc4475/bcast.dat0000644000175000017500000000100412650734252017311 0ustar debalancedebalanceSIP/2.0 200 OK Via: SIP/2.0/UDP 192.0.2.198;branch=z9hG4bK1324923 Via: SIP/2.0/UDP 255.255.255.255;branch=z9hG4bK1saber23 Call-ID: bcast.0384840201234ksdfak3j2erwedfsASdf CSeq: 35 INVITE From: sip:user@example.com;tag=11141343 To: sip:user@example.edu;tag=2229 Content-Length: 154 Content-Type: application/sdp Contact: v=0 o=mhandley 29739 7272939 IN IP4 192.0.2.198 s=- c=IN IP4 192.0.2.198 t=0 0 m=audio 49217 RTP/AVP 0 12 m=video 3227 RTP/AVP 31 a=rtpmap:31 LPC p1_sip-1.0.1/tests/rfc4475/dblreq.dat0000644000175000017500000000135612650734252017500 0ustar debalancedebalanceREGISTER sip:example.com SIP/2.0 To: sip:j.user@example.com From: sip:j.user@example.com;tag=43251j3j324 Max-Forwards: 8 I: dblreq.0ha0isndaksdj99sdfafnl3lk233412 Contact: sip:j.user@host.example.com CSeq: 8 REGISTER Via: SIP/2.0/UDP 192.0.2.125;branch=z9hG4bKkdjuw23492 Content-Length: 0 INVITE sip:joe@example.com SIP/2.0 t: sip:joe@example.com From: sip:caller@example.net;tag=141334 Max-Forwards: 8 Call-ID: dblreq.0ha0isnda977644900765@192.0.2.15 CSeq: 8 INVITE Via: SIP/2.0/UDP 192.0.2.15;branch=z9hG4bKkdjuw380234 Content-Type: application/sdp Content-Length: 150 v=0 o=mhandley 29739 7272939 IN IP4 192.0.2.15 s=- c=IN IP4 192.0.2.15 t=0 0 m=audio 49217 RTP/AVP 0 12 m =video 3227 RTP/AVP 31 a=rtpmap:31 LPC p1_sip-1.0.1/tests/rfc4475/lwsdisp.dat0000644000175000017500000000037712650734252017716 0ustar debalancedebalanceOPTIONS sip:user@example.com SIP/2.0 To: sip:user@example.com From: caller;tag=323 Max-Forwards: 70 Call-ID: lwsdisp.1234abcd@funky.example.com CSeq: 60 OPTIONS Via: SIP/2.0/UDP funky.example.com;branch=z9hG4bKkdjuw l: 0 p1_sip-1.0.1/tests/rfc4475/unksm2.dat0000644000175000017500000000043212650734252017440 0ustar debalancedebalanceREGISTER sip:example.com SIP/2.0 To: isbn:2983792873 From: ;tag=3234233 Call-ID: unksm2.daksdj@hyphenated-host.example.com CSeq: 234902 REGISTER Max-Forwards: 70 Via: SIP/2.0/UDP 192.0.2.21:5060;branch=z9hG4bKkdjuw Contact: l: 0 p1_sip-1.0.1/tests/rfc4475/trws.dat0000644000175000017500000000050712650734252017223 0ustar debalancedebalanceOPTIONS sip:remote-target@example.com SIP/2.0 Via: SIP/2.0/TCP host1.examle.com;branch=z9hG4bK299342093 To: From: ;tag=329429089 Call-ID: trws.oicu34958239neffasdhr2345r Accept: application/sdp CSeq: 238923 OPTIONS Max-Forwards: 70 Content-Length: 0 p1_sip-1.0.1/tests/rfc4475/noreason.dat0000644000175000017500000000042212650734252020044 0ustar debalancedebalanceSIP/2.0 100 Via: SIP/2.0/UDP 192.0.2.105;branch=z9hG4bK2398ndaoe Call-ID: noreason.asndj203insdf99223ndf CSeq: 35 INVITE From: ;tag=39ansfi3 To: ;tag=902jndnke3 Content-Length: 0 Contact: p1_sip-1.0.1/tests/rfc4475/scalarlg.dat0000644000175000017500000000060112650734252020007 0ustar debalancedebalanceSIP/2.0 503 Service Unavailable Via: SIP/2.0/TCP host129.example.com;branch=z9hG4bKzzxdiwo34sw;received=192.0.2.129 To: From: ;tag=2easdjfejw CSeq: 9292394834772304023312 OPTIONS Call-ID: scalarlg.noase0of0234hn2qofoaf0232aewf2394r Retry-After: 949302838503028349304023988 Warning: 1812 overture "In Progress" Content-Length: 0 p1_sip-1.0.1/tests/rfc4475/wsinv.dat0000644000175000017500000000175112650734252017374 0ustar debalancedebalanceINVITE sip:vivekg@chair-dnrc.example.com;unknownparam SIP/2.0 TO : sip:vivekg@chair-dnrc.example.com ; tag = 1918181833n from : "J Rosenberg \\\"" ; tag = 98asjd8 MaX-fOrWaRdS: 0068 Call-ID: wsinv.ndaksdj@192.0.2.1 Content-Length : 150 cseq: 0009 INVITE Via : SIP / 2.0 /UDP 192.0.2.2;branch=390skdjuw s : NewFangledHeader: newfangled value continued newfangled value UnknownHeaderWithUnusualValue: ;;,,;;,; Content-Type: application/sdp Route: v: SIP / 2.0 / TCP spindle.example.com ; branch = z9hG4bK9ikj8 , SIP / 2.0 / UDP 192.168.255.111 ; branch= z9hG4bK30239 m:"Quoted string \"\"" ; newparam = newvalue ; secondparam ; q = 0.33 v=0 o=mhandley 29739 7272939 IN IP4 192.0.2.3 s=- c=IN IP4 192.0.2.4 t=0 0 m=audio 49217 RTP/AVP 0 12 m=video 3227 RTP/AVP 31 a=rtpmap:31 LPC p1_sip-1.0.1/tests/rfc4475/sdp01.dat0000644000175000017500000000075612650734252017161 0ustar debalancedebalanceINVITE sip:user@example.com SIP/2.0 To: sip:j_user@example.com Contact: From: sip:caller@example.net;tag=234 Max-Forwards: 5 Call-ID: sdp01.ndaksdj9342dasdd Accept: text/nobodyKnowsThis CSeq: 8 INVITE Via: SIP/2.0/UDP 192.0.2.15;branch=z9hG4bKkdjuw Content-Length: 150 Content-Type: application/sdp v=0 o=mhandley 29739 7272939 IN IP4 192.0.2.5 s=- c=IN IP4 192.0.2.5 t=0 0 m=audio 49217 RTP/AVP 0 12 m=video 3227 RTP/AVP 31 a=rtpmap:31 LPC p1_sip-1.0.1/tests/rfc4475/test.dat0000644000175000017500000000047612650734252017210 0ustar debalancedebalanceINVITE sip:alan@jasomi.com TO : alan@jasomi.com From: ralph@example.com MaX-fOrWaRdS: 0068 Call-ID: test.0ha0isndaksdj@192.0.2.1 Xyzzy-2: this is the number ten : 10 Xyzzy-3: INVITE Xyzzy: 10000000000 Meaning: foo bar spam Foobar roobar Content-Length: 18 Content-Type: application/sdp v=0 testing=123 p1_sip-1.0.1/tests/rfc4475/badaspec.dat0000644000175000017500000000053212650734252017764 0ustar debalancedebalanceOPTIONS sip:user@example.org SIP/2.0 Via: SIP/2.0/UDP host4.example.com:5060;branch=z9hG4bKkdju43234 Max-Forwards: 70 From: "Bell, Alexander" ;tag=433423 To: "Watson, Thomas" < sip:t.watson@example.org > Call-ID: badaspec.sdf0234n2nds0a099u23h3hnnw009cdkne3 Accept: application/sdp CSeq: 3923239 OPTIONS l: 0 p1_sip-1.0.1/tests/rfc4475/esc01.dat0000644000175000017500000000103712650734252017136 0ustar debalancedebalanceINVITE sip:sips%3Auser%40example.com@example.net SIP/2.0 To: sip:%75se%72@example.com From: ;tag=938 Max-Forwards: 87 i: esc01.239409asdfakjkn23onasd0-3234 CSeq: 234234 INVITE Via: SIP/2.0/UDP host5.example.net;branch=z9hG4bKkdjuw C: application/sdp Contact: Content-Length: 150 v=0 o=mhandley 29739 7272939 IN IP4 192.0.2.1 s=- c=IN IP4 192.0.2.1 t=0 0 m=audio 49217 RTP/AVP 0 12 m=video 3227 RTP/AVP 31 a=rtpmap:31 LPC p1_sip-1.0.1/tests/rfc4475/regbadct.dat0000644000175000017500000000046312650734252020000 0ustar debalancedebalanceREGISTER sip:example.com SIP/2.0 To: sip:user@example.com From: sip:user@example.com;tag=998332 Max-Forwards: 70 Call-ID: regbadct.k345asrl3fdbv@10.0.0.1 CSeq: 1 REGISTER Via: SIP/2.0/UDP 135.180.130.133:5060;branch=z9hG4bKkdjuw Contact: sip:user@example.com?Route=%3Csip:sip.example.com%3E l: 0 p1_sip-1.0.1/tests/rfc4475/zeromf.dat0000644000175000017500000000042012650734252017520 0ustar debalancedebalanceOPTIONS sip:user@example.com SIP/2.0 To: sip:user@example.com From: sip:caller@example.net;tag=3ghsd41 Call-ID: zeromf.jfasdlfnm2o2l43r5u0asdfas CSeq: 39234321 OPTIONS Via: SIP/2.0/UDP host1.example.com;branch=z9hG4bKkdjuw2349i Max-Forwards: 0 Content-Length: 0 p1_sip-1.0.1/tests/rfc4475/regescrt.dat0000644000175000017500000000045612650734252020045 0ustar debalancedebalanceREGISTER sip:example.com SIP/2.0 To: sip:user@example.com From: sip:user@example.com;tag=8 Max-Forwards: 70 Call-ID: regescrt.k345asrl3fdbv@192.0.2.1 CSeq: 14398234 REGISTER Via: SIP/2.0/UDP host5.example.com;branch=z9hG4bKkdjuw M: L:0 p1_sip-1.0.1/tests/rfc4475/ltgtruri.dat0000644000175000017500000000070412650734252020077 0ustar debalancedebalanceINVITE SIP/2.0 To: sip:user@example.com From: sip:caller@example.net;tag=39291 Max-Forwards: 23 Call-ID: ltgtruri.1@192.0.2.5 CSeq: 1 INVITE Via: SIP/2.0/UDP 192.0.2.5 Contact: Content-Type: application/sdp Content-Length: 159 v=0 o=mhandley 29739 7272939 IN IP4 192.0.2.5 s=- c=IN IP4 192.0.2.5 t=3149328700 0 m=audio 49217 RTP/AVP 0 12 m=video 3227 RTP/AVP 31 a=rtpmap:31 LPC p1_sip-1.0.1/tests/rfc4475/mpart01.dat0000644000175000017500000000241212650734252017505 0ustar debalancedebalanceMESSAGE sip:kumiko@example.org SIP/2.0 Via: SIP/2.0/UDP 127.0.0.1:5070;branch=z9hG4bK-d87543-4dade06d0bdb11ee-1--d87543-;rport Max-Forwards: 70 Route: Identity: r5mwreLuyDRYBi/0TiPwEsY3rEVsk/G2WxhgTV1PF7hHuLIK0YWVKZhKv9Mj8UeXqkMVbnVq37CD+813gvYjcBUaZngQmXc9WNZSDNGCzA+fWl9MEUHWIZo1CeJebdY/XlgKeTa0Olvq0rt70Q5jiSfbqMJmQFteeivUhkMWYUA= Contact: To: From: ;tag=2fb0dcc9 Call-ID: 3d9485ad0c49859b@Zmx1ZmZ5LW1hYy0xNi5sb2NhbA.. CSeq: 1 MESSAGE Content-Transfer-Encoding: binary Content-Type: multipart/mixed;boundary=7a9cbec02ceef655 Date: Sat, 15 Oct 2005 04:44:56 GMT User-Agent: SIPimp.org/0.2.5 (curses) Content-Length: 553 --7a9cbec02ceef655 Content-Type: text/plain Content-Transfer-Encoding: binary Hello --7a9cbec02ceef655 Content-Type: application/octet-stream Content-Transfer-Encoding: binary 0‚R *†H†÷  ‚C0‚?1 0+0  *†H†÷ 1‚ 0‚0|0p1 0 UUS10U California10USan Jose10 U sipit1)0'U  Sipit Test Certificate Authority•q30+0  *†H†÷ €ŽôfùHðR-Òå—Ž•ªéòþ fYqb’èÚ*¨Ø5 hÎÿ®<½+ÿuÝÕdŽY=ÖG(òb ÷éAtž3 ší«Û“Ñ B.{r‰ÒœÀÉ®.ûÇÀÏù/;~OÀ'áTm䶪:»>fÌË]ÖÆKƒƒœ¸æÿ-”Oå{e¼™Ð --7a9cbec02ceef655-- p1_sip-1.0.1/tests/rfc4475/cparam01.dat0000644000175000017500000000050112650734252017622 0ustar debalancedebalanceREGISTER sip:example.com SIP/2.0 Via: SIP/2.0/UDP saturn.example.com:5060;branch=z9hG4bKkdjuw Max-Forwards: 70 From: sip:watson@example.com;tag=DkfVgjkrtMwaerKKpe To: sip:watson@example.com Call-ID: cparam01.70710@saturn.example.com CSeq: 2 REGISTER Contact: sip:+19725552222@gw1.example.net;unknownparam l: 0 p1_sip-1.0.1/tests/rfc4475/longreq.dat0000644000175000017500000000667312650734252017705 0ustar debalancedebalanceINVITE sip:user@example.com SIP/2.0 To: "I have a user name of extremeextremeextremeextremeextremeextremeextremeextremeextremeextreme proportion" F: sip:amazinglylongcallernameamazinglylongcallernameamazinglylongcallernameamazinglylongcallernameamazinglylongcallername@example.net;tag=12982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982982424;unknownheaderparamnamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamenamename=unknowheaderparamvaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevaluevalue;unknownValuelessparamnameparamnameparamnameparamnameparamnameparamnameparamnameparamnameparamnameparamname Call-ID: longreq.onereallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallylongcallid CSeq: 3882340 INVITE Unknown-LongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLong-Name: unknown-longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong-value; unknown-longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong-parameter-name = unknown-longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong-parameter-value Via: SIP/2.0/TCP sip33.example.com v: SIP/2.0/TCP sip32.example.com V: SIP/2.0/TCP sip31.example.com Via: SIP/2.0/TCP sip30.example.com ViA: SIP/2.0/TCP sip29.example.com VIa: SIP/2.0/TCP sip28.example.com VIA: SIP/2.0/TCP sip27.example.com via: SIP/2.0/TCP sip26.example.com viA: SIP/2.0/TCP sip25.example.com vIa: SIP/2.0/TCP sip24.example.com vIA: SIP/2.0/TCP sip23.example.com V : SIP/2.0/TCP sip22.example.com v : SIP/2.0/TCP sip21.example.com V : SIP/2.0/TCP sip20.example.com v : SIP/2.0/TCP sip19.example.com Via : SIP/2.0/TCP sip18.example.com Via : SIP/2.0/TCP sip17.example.com Via: SIP/2.0/TCP sip16.example.com Via: SIP/2.0/TCP sip15.example.com Via: SIP/2.0/TCP sip14.example.com Via: SIP/2.0/TCP sip13.example.com Via: SIP/2.0/TCP sip12.example.com Via: SIP/2.0/TCP sip11.example.com Via: SIP/2.0/TCP sip10.example.com Via: SIP/2.0/TCP sip9.example.com Via: SIP/2.0/TCP sip8.example.com Via: SIP/2.0/TCP sip7.example.com Via: SIP/2.0/TCP sip6.example.com Via: SIP/2.0/TCP sip5.example.com Via: SIP/2.0/TCP sip4.example.com Via: SIP/2.0/TCP sip3.example.com Via: SIP/2.0/TCP sip2.example.com Via: SIP/2.0/TCP sip1.example.com Via: SIP/2.0/TCP host.example.com;received=192.0.2.5;branch=verylonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglongbranchvalue Max-Forwards: 70 Contact: Content-Type: application/sdp l: 150 v=0 o=mhandley 29739 7272939 IN IP4 192.0.2.1 s=- c=IN IP4 192.0.2.1 t=0 0 m=audio 49217 RTP/AVP 0 12 m=video 3227 RTP/AVP 31 a=rtpmap:31 LPC p1_sip-1.0.1/tests/rfc5118/0000755000175000017500000000000012650734252015523 5ustar debalancedebalancep1_sip-1.0.1/tests/rfc5118/ipv4-mapped-ipv60000644000175000017500000000117412650734252020461 0ustar debalancedebalanceINVITE sip:user@example.com SIP/2.0 To: sip:user@example.com From: sip:user@east.example.com;tag=81x2 Via: SIP/2.0/UDP [::ffff:192.0.2.10]:19823;branch=z9hG4bKbh19 Via: SIP/2.0/UDP [::ffff:192.0.2.2];branch=z9hG4bKas3-111 Call-ID: SSG9559905523997077@hlau_4100 Contact: "T. desk phone" CSeq: 612 INVITE Max-Forwards: 70 Content-Type: application/sdp Content-Length: 236 v=0 o=assistant 971731711378798081 0 IN IP6 ::ffff:192.0.2.2 s=Call me soon, please! c=IN IP6 ::ffff:192.0.2.2 t=3338481189 3370017201 m=audio 6000 RTP/AVP 2 a=rtpmap:2 G726-32/8000 m=video 6024 RTP/AVP 107 a=rtpmap:107 H263-1998/90000 p1_sip-1.0.1/tests/rfc5118/via-received-param-no-delim0000644000175000017500000000046312650734252022614 0ustar debalancedebalanceOPTIONS sip:[2001:db8::10] SIP/2.0 To: sip:user@example.com From: sip:user@example.com;tag=81x2 Via: SIP/2.0/UDP [2001:db8::9:1];received=2001:db8::9:255;branch=z9hG4bKas3 Call-ID: SSG95523997077@hlau_4100 Max-Forwards: 70 Contact: "Caller" CSeq: 921 OPTIONS Content-Length: 0 p1_sip-1.0.1/tests/rfc5118/ipv6-correct-abnf-2-colons0000644000175000017500000000041612650734252022330 0ustar debalancedebalanceOPTIONS sip:user@[2001:db8::192.0.2.1] SIP/2.0 To: sip:user@[2001:db8::192.0.2.1] From: sip:user@example.com;tag=810x2 Via: SIP/2.0/UDP lab1.east.example.com;branch=z9hG4bKas3-111 Call-ID: G9559905523997077@hlau_4100 CSeq: 689 OPTIONS Max-Forwards: 70 Content-Length: 0 p1_sip-1.0.1/tests/rfc5118/ipv6-bad0000644000175000017500000000044312650734252017057 0ustar debalancedebalanceREGISTER sip:2001:db8::10 SIP/2.0 To: sip:user@example.com From: sip:user@example.com;tag=81x2 Via: SIP/2.0/UDP [2001:db8::9:1];branch=z9hG4bKas3-111 Call-ID: SSG9559905523997077@hlau_4100 Max-Forwards: 70 Contact: "Caller" CSeq: 98176 REGISTER Content-Length: 0 p1_sip-1.0.1/tests/rfc5118/via-received-param-with-delim0000644000175000017500000000042212650734252023146 0ustar debalancedebalanceBYE sip:[2001:db8::10] SIP/2.0 To: sip:user@example.com;tag=bd76ya From: sip:user@example.com;tag=81x2 Via: SIP/2.0/UDP [2001:db8::9:1];received=[2001:db8::9:255];branch=z9hG4bKas3-111 Call-ID: SSG9559905523997077@hlau_4100 Max-Forwards: 70 CSeq: 321 BYE Content-Length: 0 p1_sip-1.0.1/tests/rfc5118/mult-ip-in-header0000644000175000017500000000060212650734252020665 0ustar debalancedebalanceBYE sip:user@host.example.net SIP/2.0 Via: SIP/2.0/UDP [2001:db8::9:1]:6050;branch=z9hG4bKas3-111 Via: SIP/2.0/UDP 192.0.2.1;branch=z9hG4bKjhja8781hjuaij65144 Via: SIP/2.0/TCP [2001:db8::9:255];branch=z9hG4bK451jj;received=192.0.2.200 Call-ID: 997077@lau_4100 Max-Forwards: 70 CSeq: 89187 BYE To: sip:user@example.net;tag=9817--94 From: sip:user@example.com;tag=81x2 Content-Length: 0 p1_sip-1.0.1/tests/rfc5118/port-unambiguous0000644000175000017500000000045212650734252020767 0ustar debalancedebalanceREGISTER sip:[2001:db8::10]:5070 SIP/2.0 To: sip:user@example.com From: sip:user@example.com;tag=81x2 Via: SIP/2.0/UDP [2001:db8::9:1];branch=z9hG4bKas3-111 Call-ID: SSG9559905523997077@hlau_4100 Contact: "Caller" Max-Forwards: 70 CSeq: 98176 REGISTER Content-Length: 0 p1_sip-1.0.1/tests/rfc5118/ipv6-bug-abnf-3-colons0000644000175000017500000000042012650734252021440 0ustar debalancedebalanceOPTIONS sip:user@[2001:db8:::192.0.2.1] SIP/2.0 To: sip:user@[2001:db8:::192.0.2.1] From: sip:user@example.com;tag=810x2 Via: SIP/2.0/UDP lab1.east.example.com;branch=z9hG4bKas3-111 Call-ID: G9559905523997077@hlau_4100 CSeq: 689 OPTIONS Max-Forwards: 70 Content-Length: 0 p1_sip-1.0.1/tests/rfc5118/port-ambiguous0000644000175000017500000000045212650734252020424 0ustar debalancedebalanceREGISTER sip:[2001:db8::10:5070] SIP/2.0 To: sip:user@example.com From: sip:user@example.com;tag=81x2 Via: SIP/2.0/UDP [2001:db8::9:1];branch=z9hG4bKas3-111 Call-ID: SSG9559905523997077@hlau_4100 Contact: "Caller" Max-Forwards: 70 CSeq: 98176 REGISTER Content-Length: 0 p1_sip-1.0.1/tests/rfc5118/ipv6-in-sdp0000644000175000017500000000107212650734252017522 0ustar debalancedebalanceINVITE sip:user@[2001:db8::10] SIP/2.0 To: sip:user@[2001:db8::10] From: sip:user@example.com;tag=81x2 Via: SIP/2.0/UDP [2001:db8::20];branch=z9hG4bKas3-111 Call-ID: SSG9559905523997077@hlau_4100 Contact: "Caller" CSeq: 8612 INVITE Max-Forwards: 70 Content-Type: application/sdp Content-Length: 268 v=0 o=assistant 971731711378798081 0 IN IP6 2001:db8::20 s=Live video feed for today's meeting c=IN IP6 2001:db8::20 t=3338481189 3370017201 m=audio 6000 RTP/AVP 2 a=rtpmap:2 G726-32/8000 m=video 6024 RTP/AVP 107 a=rtpmap:107 H263-1998/90000 p1_sip-1.0.1/tests/rfc5118/mult-ip-in-sdp0000644000175000017500000000077612650734252020237 0ustar debalancedebalanceINVITE sip:user@[2001:db8::10] SIP/2.0 To: sip:user@[2001:db8::10] From: sip:user@example.com;tag=81x2 Via: SIP/2.0/UDP [2001:db8::9:1];branch=z9hG4bKas3-111 Call-ID: SSG9559905523997077@hlau_4100 Contact: "Caller" Max-Forwards: 70 CSeq: 8912 INVITE Content-Type: application/sdp Content-Length: 181 v=0 o=bob 280744730 28977631 IN IP4 host.example.com s= t=0 0 m=audio 22334 RTP/AVP 0 c=IN IP4 192.0.2.1 m=video 6024 RTP/AVP 107 c=IN IP6 2001:db8::1 a=rtpmap:107 H263-1998/90000 p1_sip-1.0.1/tests/rfc5118/ipv6-good0000644000175000017500000000044512650734252017263 0ustar debalancedebalanceREGISTER sip:[2001:db8::10] SIP/2.0 To: sip:user@example.com From: sip:user@example.com;tag=81x2 Via: SIP/2.0/UDP [2001:db8::9:1];branch=z9hG4bKas3-111 Call-ID: SSG9559905523997077@hlau_4100 Max-Forwards: 70 Contact: "Caller" CSeq: 98176 REGISTER Content-Length: 0 p1_sip-1.0.1/src/0000755000175000017500000000000012650734252014057 5ustar debalancedebalancep1_sip-1.0.1/src/esip_app.erl0000644000175000017500000000320712650734252016365 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% File : esip_app.erl %%% Author : Evgeniy Khramtsov %%% Purpose : SIP application %%% Created : 14 Jul 2009 by Evgeniy Khramtsov %%% %%% %%% Copyright (C) 2002-2016 ProcessOne, SARL. All Rights Reserved. %%% %%% Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 %%% %%% Unless required by applicable law or agreed to in writing, software %%% distributed under the License is distributed on an "AS IS" BASIS, %%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %%% See the License for the specific language governing permissions and %%% limitations under the License. %%% %%%---------------------------------------------------------------------- -module(esip_app). -behaviour(application). %% Application callbacks -export([start/2, stop/1]). %%==================================================================== %% Application callbacks %%==================================================================== start(_Type, _StartArgs) -> esip_codec:start(), case esip_sup:start_link() of {ok, Pid} -> case esip_socket:start_pool() of ok -> {ok, Pid}; Err -> Err end; Error -> Error end. stop(_State) -> ok. %%==================================================================== %% Internal functions %%==================================================================== p1_sip-1.0.1/src/esip_client_transaction.erl0000644000175000017500000002371112650734252021472 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% File : esip_client_transaction.erl %%% Author : Evgeniy Khramtsov %%% Purpose : %%% Created : 20 Dec 2010 by Evgeniy Khramtsov %%% %%% %%% Copyright (C) 2002-2016 ProcessOne, SARL. All Rights Reserved. %%% %%% Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 %%% %%% Unless required by applicable law or agreed to in writing, software %%% distributed under the License is distributed on an "AS IS" BASIS, %%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %%% See the License for the specific language governing permissions and %%% limitations under the License. %%% %%%---------------------------------------------------------------------- -module(esip_client_transaction). -behaviour(gen_fsm). %% API -export([start_link/4, start/3, start/4, stop/1, route/2, cancel/2]). %% gen_fsm callbacks -export([init/1, handle_event/3, handle_sync_event/4, handle_info/3, terminate/3, code_change/4]). %% gen_fsm states -export([trying/2, proceeding/2, accepted/2, completed/2]). -include("esip.hrl"). -include("esip_lib.hrl"). -define(MAX_TRANSACTION_LIFETIME, timer:minutes(5)). -record(state, {req, tu, sock, branch, cancelled = false}). %%%=================================================================== %%% API %%%=================================================================== start_link(SIPSocket, Request, TU, Opts) -> gen_fsm:start_link(?MODULE, [SIPSocket, Request, TU, Opts], []). start(SIPSocket, Request, TU) -> start(SIPSocket, Request, TU, []). start(SIPSocket, Request, TU, Opts) -> case esip_tmp_sup:start_child( esip_client_transaction_sup, ?MODULE, gen_fsm, [SIPSocket, Request, TU, Opts]) of {ok, Pid} -> {ok, make_trid(Pid)}; {error, _} = Err -> Err end. route(Pid, R) -> gen_fsm:send_event(Pid, R). cancel(Pid, TU) -> gen_fsm:send_event(Pid, {cancel, TU}). stop(Pid) -> gen_fsm:send_all_state_event(Pid, stop). %%%=================================================================== %%% gen_fsm callbacks %%%=================================================================== init([SIPSocket, Request, TU, _Opts]) -> gen_fsm:send_event(self(), Request), erlang:send_after(?MAX_TRANSACTION_LIFETIME, self(), timeout), {ok, trying, #state{tu = TU, sock = SIPSocket}}. trying(#sip{type = request, hdrs = Hdrs, method = Method} = Request, #state{sock = #sip_socket{type = Type}} = State) -> Branch = esip:get_branch(Hdrs), esip_transaction:insert(Branch, Method, client, self()), T1 = esip:timer1(), if Type == udp, Method == <<"INVITE">> -> gen_fsm:send_event_after(T1, {timer_A, T1}); Type == udp -> gen_fsm:send_event_after(T1, {timer_E, T1}); true -> ok end, if Method == <<"INVITE">> -> gen_fsm:send_event_after(64*T1, timer_B); true -> gen_fsm:send_event_after(64*T1, timer_F) end, NewState = State#state{branch = Branch, req = Request}, case send(NewState, Request) of ok -> {next_state, trying, NewState}; _ -> {stop, normal, NewState} end; trying({timer_A, T}, State) -> gen_fsm:send_event_after(2*T, {timer_A, 2*T}), case send(State, State#state.req) of ok -> {next_state, trying, State}; _ -> {stop, normal, State} end; trying({timer_E, T}, State) -> T4 = esip:timer4(), case 2*T < T4 of true -> gen_fsm:send_event_after(2*T, {timer_E, 2*T}); false -> gen_fsm:send_event_after(T4, {timer_E, T4}) end, case send(State, State#state.req) of ok -> {next_state, trying, State}; _ -> {stop, normal, State} end; trying(Timer, State) when Timer == timer_B; Timer == timer_F -> pass_to_transaction_user(State, {error, timeout}), {stop, normal, State}; trying(#sip{type = response} = Resp, State) -> case State#state.cancelled of {true, TU} -> gen_fsm:send_event(self(), {cancel, TU}); _ -> ok end, proceeding(Resp, State); trying({cancel, TU}, State) -> {next_state, trying, State#state{cancelled = {true, TU}}}; trying(_Event, State) -> {next_state, trying, State}. proceeding(#sip{type = response, status = Status} = Resp, State) when Status < 200 -> pass_to_transaction_user(State, Resp), {next_state, proceeding, State}; proceeding(#sip{type = response, status = Status} = Resp, #state{req = #sip{method = <<"INVITE">>}} = State) when Status < 300 -> pass_to_transaction_user(State, Resp), gen_fsm:send_event_after(64*esip:timer1(), timer_M), {next_state, accepted, State}; proceeding(#sip{type = response, status = Status} = Resp, #state{req = #sip{method = <<"INVITE">>}} = State) when Status >= 300 -> pass_to_transaction_user(State, Resp), if (State#state.sock)#sip_socket.type == udp -> gen_fsm:send_event_after(64*esip:timer1(), timer_D), case send_ack(State, Resp) of ok -> {next_state, completed, State}; _ -> {stop, normal, State} end; true -> send_ack(State, Resp), {stop, normal, State} end; proceeding(#sip{type = response} = Resp, State) -> pass_to_transaction_user(State, Resp), if (State#state.sock)#sip_socket.type == udp -> gen_fsm:send_event_after(esip:timer4(), timer_K), {next_state, completed, State}; true -> {stop, normal, State} end; proceeding({timer_E, T}, State) -> gen_fsm:send_event_after(esip:timer2(), {timer_E, T}), case send(State, State#state.req) of ok -> {next_state, proceeding, State}; _ -> {stop, normal, State} end; proceeding(timer_F, State) -> pass_to_transaction_user(State, {error, timeout}), {stop, normal, State}; proceeding({cancel, TU}, #state{req = #sip{hdrs = Hdrs} = Req} = State) -> Hdrs1 = esip:filter_hdrs(['call-id', 'to', 'from', 'cseq', 'max-forwards', 'route'], Hdrs), [Via|_] = esip:get_hdrs('via', Hdrs), Hdrs2 = case esip:get_config_value(software) of undefined -> [{'via', [Via]}|Hdrs1]; UA -> [{'via', [Via]},{'user-agent', UA}|Hdrs1] end, CancelReq = #sip{type = request, method = <<"CANCEL">>, uri = Req#sip.uri, hdrs = Hdrs2}, esip_client_transaction:start(State#state.sock, CancelReq, TU), {next_state, proceeding, State}; proceeding(_Event, State) -> {next_state, proceeding, State}. accepted(timer_M, State) -> {stop, normal, State}; accepted(#sip{type = response, status = Status} = Resp, State) when Status >= 200, Status < 300 -> pass_to_transaction_user(State, Resp), {next_state, accepted, State}; accepted(_Event, State) -> {next_state, accepted, State}. completed(timer_D, State) -> {stop, normal, State}; completed(timer_K, State) -> {stop, normal, State}; completed(#sip{type = response, status = Status} = Resp, State) when Status >= 300 -> case send_ack(State, Resp) of ok -> {next_state, completed, State}; _ -> {stop, normal, State} end; completed(_Event, State) -> {next_state, completed, State}. handle_event(stop, _StateName, State) -> {stop, normal, State}; handle_event(_Event, StateName, State) -> {next_state, StateName, State}. handle_sync_event(_Event, _From, StateName, State) -> Reply = ok, {reply, Reply, StateName, State}. handle_info(timeout, _StateName, State) -> pass_to_transaction_user(State, {error, timeout}), {stop, normal, State}; handle_info(_Info, StateName, State) -> {next_state, StateName, State}. terminate(_Reason, _StateName, #state{req = Req, branch = Branch}) -> if Req /= undefined -> catch esip_transaction:delete(Branch, Req#sip.method, client); true -> ok end. code_change(_OldVsn, StateName, State, _Extra) -> {ok, StateName, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== pass_to_transaction_user(#state{tu = TU, sock = Sock}, Resp) -> TrID = make_trid(), case TU of F when is_function(F) -> esip:callback(F, [Resp, Sock, TrID]); {M, F, A} -> esip:callback(M, F, [Resp, Sock, TrID | A]); _ -> TU end. send_ack(#state{req = #sip{uri = URI, hdrs = Hdrs, method = <<"INVITE">>}} = State, Resp) -> Hdrs1 = esip:filter_hdrs(['call-id', 'from', 'cseq', 'route', 'max-forwards', 'authorization', 'proxy-authorization'], Hdrs), To = esip:get_hdr('to', Resp#sip.hdrs), [Via|_] = esip:get_hdrs('via', Hdrs), Hdrs2 = case esip:get_config_value(software) of undefined -> [{'via', [Via]},{'to', To}|Hdrs1]; Software -> [{'via', [Via]},{'to', To},{'user-agent', Software}|Hdrs1] end, ACK = #sip{type = request, uri = URI, method = <<"ACK">>, hdrs = Hdrs2}, send(State, ACK); send_ack(_, _) -> ok. send(State, Resp) -> case esip_transport:send(State#state.sock, Resp) of ok -> ok; {error, _} = Err -> pass_to_transaction_user(State, Err), Err end. make_trid() -> make_trid(self()). make_trid(Pid) -> #trid{owner = Pid, type = client}. p1_sip-1.0.1/src/esip_server_transaction.erl0000644000175000017500000003177312650734252021531 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% File : esip_server_transaction.erl %%% Author : Evgeniy Khramtsov %%% Purpose : Server transaction layer. See RFC3261 and friends. %%% Created : 15 Jul 2009 by Evgeniy Khramtsov %%% %%% %%% Copyright (C) 2002-2016 ProcessOne, SARL. All Rights Reserved. %%% %%% Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 %%% %%% Unless required by applicable law or agreed to in writing, software %%% distributed under the License is distributed on an "AS IS" BASIS, %%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %%% See the License for the specific language governing permissions and %%% limitations under the License. %%% %%%---------------------------------------------------------------------- -module(esip_server_transaction). -behaviour(gen_fsm). %% API -export([start_link/2, start/2, stop/1, route/2]). %% gen_fsm callbacks -export([init/1, handle_event/3, handle_sync_event/4, handle_info/3, terminate/3, code_change/4]). %% gen_fsm states -export([trying/2, proceeding/2, accepted/2, completed/2, confirmed/2]). -include("esip.hrl"). -include("esip_lib.hrl"). -define(MAX_TRANSACTION_LIFETIME, timer:minutes(5)). -record(state, {sock, branch, method, resp, tu}). %%==================================================================== %% API %%==================================================================== start_link(SIPSocket, Request) -> gen_fsm:start_link(?MODULE, [SIPSocket, Request], []). start(SIPSocket, Request) -> case esip_tmp_sup:start_child(esip_server_transaction_sup, ?MODULE, gen_fsm, [SIPSocket, Request]) of {ok, Pid} -> {ok, make_trid(Pid)}; Err -> Err end. route(Pid, R) -> gen_fsm:send_event(Pid, R). stop(Pid) -> gen_fsm:send_all_state_event(Pid, stop). %%==================================================================== %% gen_fsm callbacks %%==================================================================== init([SIPSock, Request]) -> Branch = esip:get_branch(Request#sip.hdrs), State = #state{sock = SIPSock, branch = Branch}, gen_fsm:send_event(self(), Request), erlang:send_after(?MAX_TRANSACTION_LIFETIME, self(), timeout), esip_transaction:insert(Branch, Request#sip.method, server, self()), {ok, trying, State}. trying(#sip{method = <<"CANCEL">> = Method, type = request} = Req, State) -> Resp = esip:make_response(Req, #sip{type = response, status = 200}, esip:make_tag()), proceeding(Resp, State#state{method = Method}); trying(#sip{type = request, method = Method} = Req, State) -> case find_transaction_user(Req, State#state.sock) of {dialog, TU} -> NewState = State#state{tu = TU, method = Method}, case pass_to_transaction_user(NewState, Req) of #sip{type = response} = Resp -> proceeding(Resp, NewState); wait -> maybe_send_trying(Req), {next_state, proceeding, NewState}; NewTU -> case is_transaction_user(NewTU) of true -> maybe_send_trying(Req), {next_state, proceeding, NewState#state{tu = NewTU}}; false -> Resp = esip:make_response( Req, #sip{status = 500, type = response}, esip:make_tag()), proceeding(Resp, State#state{method = Method}) end end; #sip{type = response} = Resp -> proceeding(Resp, State#state{method = Method}); cseq_out_of_order -> Resp = esip:make_response( Req, #sip{status = 500, type = response, reason = <<"CSeq is Out of Order">>}, esip:make_tag()), proceeding(Resp, State#state{method = Method}); wait -> maybe_send_trying(Req), {next_state, proceeding, State#state{method = Method}}; TU -> case is_transaction_user(TU) of true -> maybe_send_trying(Req), {next_state, proceeding, State#state{tu = TU, method = Method}}; false -> Resp = esip:make_response( Req, #sip{status = 500, type = response}, esip:make_tag()), proceeding(Resp, State#state{method = Method}) end end; trying(_Event, State) -> {next_state, trying, State}. proceeding({trying, TryingResp}, #state{resp = undefined} = State) -> %% TU didn't respond in 200 ms case send(State, TryingResp) of ok -> {next_state, proceeding, State}; _ -> {stop, normal, State} end; proceeding(#sip{type = response, status = Status} = Resp, State) when Status < 200 -> update_remote_seqnum(Resp, State), case send(State, Resp) of ok -> {next_state, proceeding, State#state{resp = Resp}}; _ -> {stop, normal, State} end; proceeding(#sip{type = response, status = Status} = Resp, #state{method = <<"INVITE">>} = State) when Status < 300 -> update_remote_seqnum(Resp, State), gen_fsm:send_event_after(64*esip:timer1(), timer_L), case send(State, Resp) of ok -> {next_state, accepted, State#state{resp = Resp}}; _ -> {stop, normal, State} end; proceeding(#sip{type = response, status = Status} = Resp, #state{method = <<"INVITE">>} = State) when Status >= 300 -> update_remote_seqnum(Resp, State), T1 = esip:timer1(), if (State#state.sock)#sip_socket.type == udp -> gen_fsm:send_event_after(T1, {timer_G, T1}); true -> ok end, gen_fsm:send_event_after(64*T1, timer_H), case send(State, Resp) of ok -> {next_state, completed, State#state{resp = Resp}}; _ -> {stop, normal, State} end; proceeding(#sip{type = response, status = Status} = Resp, State) when Status >= 200 -> update_remote_seqnum(Resp, State), if (State#state.sock)#sip_socket.type == udp -> gen_fsm:send_event_after(64*esip:timer1(), timer_J), case send(State, Resp) of ok -> {next_state, completed, State#state{resp = Resp}}; _ -> {stop, normal, State} end; true -> send(State, Resp), {stop, normal, State} end; proceeding(#sip{type = request, method = <<"CANCEL">>} = Req, State) -> if State#state.method == <<"INVITE">> -> case pass_to_transaction_user(State, Req) of #sip{type = response} = Resp -> proceeding(Resp#sip{method = <<"INVITE">>}, State); _ -> {next_state, proceeding, State} end; true -> {next_state, proceeding, State} end; proceeding(#sip{type = request, method = Method} = Req, #state{method = Method, resp = Resp} = State) -> if Resp /= undefined -> case send(State, Resp) of ok -> {next_state, proceeding, State}; _ -> {stop, normal, State} end; Method == <<"INVITE">> -> Trying = esip:make_response(Req, #sip{type = response, status = 100}), case send(State, Trying) of ok -> {next_state, proceeding, State}; _ -> {stop, normal, State} end; true -> {next_state, proceeding, State} end; proceeding(_Event, State) -> {next_state, proceeding, State}. accepted(#sip{type = request, method = <<"ACK">>} = Req, State) -> pass_to_transaction_user(State, Req), {next_state, accepted, State}; accepted(#sip{type = response, status = Status} = Resp, State) when Status >= 200, Status < 300 -> send(State, Resp), {next_state, accepted, State}; accepted(timer_L, State) -> {stop, normal, State}; accepted(_Event, State) -> {next_state, accepted, State}. completed(#sip{type = request, method = <<"ACK">>}, #state{method = <<"INVITE">>} = State) -> if (State#state.sock)#sip_socket.type == udp -> gen_fsm:send_event_after(esip:timer4(), timer_I), {next_state, confirmed, State}; true -> {stop, normal, State} end; completed(#sip{type = request, method = Method}, #state{method = Method, resp = Resp} = State) -> case send(State, Resp) of ok -> {next_state, completed, State}; _ -> {stop, normal, State} end; completed(timer_H, State) -> pass_to_transaction_user(State, {error, timeout}), {stop, normal, State}; completed({timer_G, T}, State) -> T2 = esip:timer2(), case 2*T < T2 of true -> gen_fsm:send_event_after(2*T, {timer_G, 2*T}); false -> gen_fsm:send_event_after(T2, {timer_G, T2}) end, case send(State, State#state.resp) of ok -> {next_state, completed, State}; _ -> {stop, normal, State} end; completed(timer_J, State) -> {stop, normal, State}; completed(_Event, State) -> {next_state, completed, State}. confirmed(timer_I, State) -> {stop, normal, State}; confirmed(_Event, State) -> {next_state, confirmed, State}. handle_event(stop, _StateName, State) -> {stop, normal, State}; handle_event(_Event, StateName, State) -> {next_state, StateName, State}. handle_sync_event(_Event, _From, StateName, State) -> {reply, ok, StateName, State}. handle_info(timeout, _StateName, State) -> pass_to_transaction_user(State, {error, timeout}), {stop, normal, State}; handle_info(_Info, StateName, State) -> {next_state, StateName, State}. terminate(_Reason, _StateName, #state{branch = Branch, method = Method}) -> esip_transaction:delete(Branch, Method, server). code_change(_OldVsn, StateName, State, _Extra) -> {ok, StateName, State}. %%-------------------------------------------------------------------- %% Internal functions %%-------------------------------------------------------------------- is_transaction_user(TU) when is_function(TU) -> true; is_transaction_user({M, F, A}) when is_atom(M), is_atom(F), is_list(A) -> true; is_transaction_user(_) -> false. pass_to_transaction_user(#state{tu = TU, sock = Sock}, Req) -> TrID = make_trid(), case TU of F when is_function(F) -> esip:callback(F, [Req, Sock, TrID]); {M, F, A} -> esip:callback(M, F, [Req, Sock, TrID | A]); #sip{type = response} = Resp -> Resp; _ -> TU end. find_transaction_user(#sip{method = Method} = Req, SIPSock) -> TrID = make_trid(), case esip_dialog:id(uas, Req) of #dialog_id{local_tag = Tag} = DialogID when Tag /= <<>> -> case esip_dialog:lookup(DialogID) of {ok, TU, _Dialog} when Method == <<"OPTIONS">> -> {dialog, TU}; {ok, TU, #dialog{remote_seq_num = RemoteSeqNum}} -> CSeq = esip:get_hdr('cseq', Req#sip.hdrs), if is_integer(RemoteSeqNum), RemoteSeqNum > CSeq -> cseq_out_of_order; true -> {dialog, TU} end; _ -> esip:callback(request, [Req, SIPSock, TrID]) end; _ -> esip:callback(request, [Req, SIPSock, TrID]) end. send(State, Resp) -> case esip_transport:send(State#state.sock, Resp) of ok -> ok; Err -> pass_to_transaction_user(State, Err), Err end. maybe_send_trying(#sip{method = <<"INVITE">>} = Req) -> Trying = esip:make_response(Req, #sip{type = response, status = 100}), gen_fsm:send_event_after(200, {trying, Trying}); maybe_send_trying(_) -> ok. update_remote_seqnum(#sip{status = S}, _State) when S == 100; S >= 300 -> ok; update_remote_seqnum(_Resp, #state{method = <<"OPTIONS">>}) -> ok; update_remote_seqnum(#sip{hdrs = Hdrs} = Resp, _State) -> DialogID = esip_dialog:id(uas, Resp), CSeq = esip:get_hdr('cseq', Hdrs), esip_dialog:update_remote_seqnum(DialogID, CSeq). make_trid() -> make_trid(self()). make_trid(Pid) -> #trid{owner = Pid, type = server}. p1_sip-1.0.1/src/esip.erl0000644000175000017500000006233712650734252015536 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% File : sip.erl %%% Author : Evgeniy Khramtsov %%% Purpose : Main SIP instance %%% Created : 14 Jul 2009 by Evgeniy Khramtsov %%% %%% %%% Copyright (C) 2002-2016 ProcessOne, SARL. All Rights Reserved. %%% %%% Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 %%% %%% Unless required by applicable law or agreed to in writing, software %%% distributed under the License is distributed on an "AS IS" BASIS, %%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %%% See the License for the specific language governing permissions and %%% limitations under the License. %%% %%%---------------------------------------------------------------------- -module(esip). -behaviour(gen_server). %% API -export([start_link/0, start/0, stop/0]). -export([add_hdr/3, add_listener/3, callback/1, callback/2, callback/3, cancel/1, cancel/2, check_auth/4, close_dialog/1, connect/1, connect/2, decode/1, decode_uri/1, decode_uri_field/1, del_listener/2, dialog_id/2, encode/1, encode_uri/1, encode_uri_field/1, error_status/1, escape/1, filter_hdrs/2, get_branch/1, get_config/0, get_config_value/1, get_hdr/2, get_hdr/3, get_hdrs/2, get_node_by_tag/1, get_param/2, get_param/3, get_so_path/0, has_param/2, hex_encode/1, make_auth/6, make_branch/0, make_branch/1, make_callid/0, make_cseq/0, make_hdrs/0, make_hexstr/1, make_response/2, make_response/3, make_tag/0, match/2, mod/0, open_dialog/4, quote/1, reason/1, reply/2, request/2, request/3, request/4, rm_hdr/2, send/2, set_config_value/2, set_hdr/3, set_param/3, split_hdrs/2, stop_transaction/1, timer1/0, timer2/0, timer4/0, to_lower/1, unescape/1, unquote/1, warning/1]). %% gen_server callbacks -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -include("esip.hrl"). -include("esip_lib.hrl"). -record(state, {node_id}). -callback request(#sip{}, #sip_socket{}) -> #sip{} | ok | drop. -callback request(#sip{}, #sip_socket{}, #trid{}) -> #sip{} | wait | {module(), atom(), list()} | function() | {error, any()}. -callback response(#sip{}, #sip_socket{}) -> any(). -callback message_in(ping | #sip{}, #sip_socket{}) -> pang | pong | drop | ok | #sip{}. -callback message_out(#sip{}, #sip_socket{}) -> #sip{} | ok | drop. -callback locate(#sip{}) -> #uri{} | #via{} | ok. -callback data_in(iodata(), #sip_socket{}) -> any(). -callback data_out(iodata(), #sip_socket{}) -> any(). %%==================================================================== %% API %%==================================================================== start() -> application:start(esip). stop() -> application:stop(esip). start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). get_so_path() -> EbinDir = filename:dirname(code:which(?MODULE)), AppDir = filename:dirname(EbinDir), filename:join([AppDir, "priv", "lib"]). add_listener(Port, Transport, Opts) -> esip_listener:add_listener(Port, Transport, Opts). del_listener(Port, Transport) -> esip_listener:del_listener(Port, Transport). connect(SIPMsg) -> connect(SIPMsg, []). connect(SIPMsg, Opts) -> esip_transport:connect(SIPMsg, Opts). request(SIPSocket, Request) -> request(SIPSocket, Request, undefined). request(SIPSocket, Request, TU) -> request(SIPSocket, Request, TU, []). request(SIPSocket, Request, TU, Opts) -> esip_transaction:request(SIPSocket, Request, TU, Opts). reply(RequestOrTrID, Response) -> esip_transaction:reply(RequestOrTrID, Response). cancel(RequestOrTrID) -> cancel(RequestOrTrID, undefined). cancel(RequestOrTrID, TU) -> esip_transaction:cancel(RequestOrTrID, TU). send(SIPSocket, ReqOrResp) -> esip_transport:send(SIPSocket, ReqOrResp). stop_transaction(TrID) -> esip_transaction:stop(TrID). make_tag() -> {NodeID, N} = gen_server:call(?MODULE, make_tag), iolist_to_binary([NodeID, $-, int_to_list(N)]). make_branch() -> N = gen_server:call(?MODULE, make_branch), iolist_to_binary(["z9hG4bK-", int_to_list(N)]). make_branch(Hdrs) -> case get_hdrs('via', Hdrs) of [] -> make_branch(); [Via|_] -> TopBranch = to_lower(get_param(<<"branch">>, Via#via.params)), Cookie = atom_to_list(erlang:get_cookie()), ID = hex_encode(erlang:md5([TopBranch, Cookie])), iolist_to_binary(["z9hG4bK-", ID]) end. make_callid() -> N = gen_server:call(?MODULE, make_callid), iolist_to_binary([int_to_list(N)]). make_cseq() -> gen_server:call(?MODULE, make_cseq). make_hdrs() -> Hdrs = [{'cseq', make_cseq()}, {'max-forwards', get_config_value(max_forwards)}, {'call-id', make_callid()}], case get_config_value(software) of undefined -> Hdrs; Software -> [{'user-agent', Software}|Hdrs] end. dialog_id(Type, SIPMsg) -> esip_dialog:id(Type, SIPMsg). open_dialog(Request, ResponseOrTag, TypeOrState, TU) -> esip_dialog:open(Request, ResponseOrTag, TypeOrState, TU). close_dialog(DialogID) -> esip_dialog:close(DialogID). decode(Data) -> esip_codec:decode(Data). decode_uri(Data) -> esip_codec:decode_uri(Data). decode_uri_field(Data) -> esip_codec:decode_uri_field(Data). encode(R) -> esip_codec:encode(R). encode_uri(URI) -> esip_codec:encode_uri(URI). encode_uri_field(URI) -> esip_codec:encode_uri_field(URI). match(Arg1, Arg2) -> esip_codec:match(Arg1, Arg2). rm_hdr(Hdr, Hdrs) -> rm_key(Hdr, Hdrs). add_hdr(Hdr, Val, Hdrs) -> add_key(Hdr, Val, Hdrs). set_hdr(Hdr, Val, Hdrs) -> set_key(Hdr, Val, Hdrs). get_hdr(Hdr, Hdrs) -> get_key(Hdr, Hdrs, undefined). get_hdr(Hdr, Hdrs, Default) -> get_key(Hdr, Hdrs, Default). get_hdrs(Hdr, Hdrs) -> get_keys(Hdr, Hdrs). filter_hdrs(HdrList, Hdrs) -> filter_keys(HdrList, Hdrs). split_hdrs(HdrOrHdrList, Hdrs) -> split_keys(HdrOrHdrList, Hdrs). set_param(Param, Val, Params) -> set_key(Param, Val, Params). get_param(Param, Params) -> get_key(Param, Params, <<>>). get_param(Param, Params, Default) -> get_key(Param, Params, Default). has_param(Param, Params) -> has_key(Param, Params). get_branch(Hdrs) -> [Via|_] = get_hdr('via', Hdrs), get_param(<<"branch">>, Via#via.params). escape(Bin) -> esip_codec:escape(Bin). unescape(Bin) -> esip_codec:unescape(Bin). -compile({inline, [{is_equal, 2}, {member, 2}, {keysearch, 2}]}). is_equal(K1, K2) when is_binary(K1), is_binary(K2) -> esip_codec:strcasecmp(K1, K2); is_equal(K1, K2) -> K1 == K2. member(X, Xs) -> if is_atom(X) -> %% lists:member/2 is BIF, so works faster lists:member(X, Xs); true -> member1(X, Xs) end. member1(X, [Y|T]) -> case is_equal(X, Y) of true -> true; _ -> member1(X, T) end; member1(_X, []) -> false. keysearch(K, Ks) -> if is_atom(K) -> %% lists:keysearch/3 is a BIF, so works faster case lists:keysearch(K, 1, Ks) of {value, {_, Val}} -> {ok, Val}; _ -> error end; true -> keysearch1(K, Ks) end. keysearch1(_K, []) -> error; keysearch1(K, [{K1, V}|T]) -> case is_equal(K, K1) of true -> {ok, V}; false -> keysearch1(K, T) end. rm_key(Key, Keys) -> lists:filter( fun({K, _}) -> not is_equal(Key, K) end, Keys). set_key(Key, Val, Keys) -> Res = lists:foldl( fun({K, V}, Acc) -> case is_equal(K, Key) of true -> Acc; false -> [{K, V}|Acc] end end, [], Keys), lists:reverse([{Key, Val}|Res]). get_key(Key, Keys, Default) -> case keysearch(Key, Keys) of {ok, Val} -> Val; _ -> Default end. has_key(Key, Keys) -> case get_key(Key, Keys, undefined) of undefined -> false; _ -> true end. add_key(Key, Val, Keys) -> case lists:foldl( fun({K, V}, {S, Acc}) -> case S == false andalso is_equal(K, Key) of true -> {true, [{K, V}, {Key, Val}|Acc]}; false -> {S, [{K, V}|Acc]} end end, {false, []}, Keys) of {true, Res} -> lists:reverse(Res); {false, Res} -> lists:reverse([{Key, Val}|Res]) end. get_keys(Key, Keys) -> lists:flatmap( fun({K, V}) -> case is_equal(K, Key) of true when is_list(V) -> V; true -> [V]; false -> [] end end, Keys). filter_keys(KeyList, Keys) -> lists:filter( fun({Key, _}) -> member(Key, KeyList) end, Keys). split_keys(KeyList, Keys) when is_list(KeyList) -> lists:partition( fun({Key, _}) -> member(Key, KeyList) end, Keys); split_keys(Key, Keys) -> lists:foldr( fun({K, V}, {H, T}) -> case is_equal(K, Key) of true when is_list(V) -> {V++H, T}; true -> {[V|H], T}; false -> {H, [{K, V}|T]} end end, {[], []}, Keys). make_response(Req, Resp) -> make_response(Req, Resp, <<>>). make_response(#sip{hdrs = ReqHdrs, method = Method, type = request}, #sip{status = Status, hdrs = RespHdrs, method = RespMethod, type = response} = Resp, Tag) -> NeedHdrs = if Status == 100 -> filter_hdrs(['via', 'from', 'call-id', 'cseq', 'max-forwards', 'to', 'timestamp'], ReqHdrs); Status > 100, Status < 300 -> filter_hdrs(['via', 'record-route', 'from', 'call-id', 'cseq', 'max-forwards', 'to'], ReqHdrs); true -> filter_hdrs(['via', 'from', 'call-id', 'cseq', 'max-forwards', 'to'], ReqHdrs) end, NewNeedHdrs = if Status > 100 -> {ToName, ToURI, ToParams} = get_hdr('to', NeedHdrs), case has_param(<<"tag">>, ToParams) of false -> NewTo = {ToName, ToURI, [{<<"tag">>, Tag}|ToParams]}, set_hdr('to', NewTo, NeedHdrs); true -> NeedHdrs end; true -> NeedHdrs end, NewMethod = if RespMethod /= undefined -> RespMethod; true -> Method end, ResultHdrs = case get_config_value(software) of undefined -> NewNeedHdrs ++ RespHdrs; Software -> NewNeedHdrs ++ [{'server', Software}|RespHdrs] end, Resp#sip{method = NewMethod, hdrs = ResultHdrs}. make_auth({Type, Params}, Method, Body, OrigURI, Username, Password) -> Nonce = esip:get_param(<<"nonce">>, Params), QOPs = esip:get_param(<<"qop">>, Params), Algo = case esip:get_param(<<"algorithm">>, Params) of <<>> -> <<"MD5">>; Algo1 -> Algo1 end, Realm = esip:get_param(<<"realm">>, Params), OpaqueParam = case esip:get_param(<<"opaque">>, Params) of <<>> -> []; Opaque -> [{<<"opaque">>, Opaque}] end, CNonce = make_hexstr(20), NC = <<"00000001">>, %% TODO URI = if is_binary(OrigURI) -> OrigURI; is_record(OrigURI, uri) -> iolist_to_binary(esip_codec:encode_uri(OrigURI)) end, QOPList = esip_codec:split(unquote(QOPs), $,), QOP = case lists:member(<<"auth">>, QOPList) of true -> <<"auth">>; false -> case lists:member(<<"auth-int">>, QOPList) of true -> <<"auth-int">>; false -> <<>> end end, Response = compute_digest(Nonce, CNonce, NC, QOP, Algo, Realm, URI, Method, Body, Username, Password), {Type, [{<<"username">>, quote(Username)}, {<<"realm">>, Realm}, {<<"nonce">>, Nonce}, {<<"uri">>, quote(URI)}, {<<"response">>, quote(Response)}, {<<"algorithm">>, Algo} | if QOP /= <<>> -> [{<<"cnonce">>, quote(CNonce)}, {<<"nc">>, NC}, {<<"qop">>, QOP}]; true -> [] end] ++ OpaqueParam}. check_auth({Type, Params}, Method, Body, Password) -> case to_lower(Type) of <<"digest">> -> NewMethod = case Method of <<"ACK">> -> <<"INVITE">>; _ -> Method end, Nonce = esip:get_param(<<"nonce">>, Params), NC = esip:get_param(<<"nc">>, Params), CNonce = esip:get_param(<<"cnonce">>, Params), QOP = esip:get_param(<<"qop">>, Params), Algo = esip:get_param(<<"algorithm">>, Params), Username = esip:get_param(<<"username">>, Params), Realm = esip:get_param(<<"realm">>, Params), URI = esip:get_param(<<"uri">>, Params), Response = unquote(esip:get_param(<<"response">>, Params)), Response == compute_digest(Nonce, CNonce, NC, QOP, Algo, Realm, URI, NewMethod, Body, Username, Password); _ -> false end. make_hexstr(N) -> hex_encode(crypto:rand_bytes(N)). hex_encode(Data) -> << <<(esip_codec:to_hex(X))/binary>> || <> <= Data >>. to_lower(Bin) -> esip_codec:to_lower(Bin). get_config() -> ets:tab2list(esip_config). get_config_value(Key) -> case ets:lookup(esip_config, Key) of [{_, Val}] -> Val; _ -> undefined end. mod() -> get_config_value(module). set_config_value(Key, Val) -> ets:insert(esip_config, {Key, Val}). callback({M, F, A}) -> callback(M, F, A). callback(F, Args) when is_function(F) -> case catch apply(F, Args) of {'EXIT', _} = Err -> ?ERROR_MSG("failed to process callback:~n" "** Function: ~p~n" "** Args: ~p~n" "** Reason: ~p", [F, Args, Err]), {error, internal_server_error}; Result -> Result end; callback(F, Args) -> callback(get_config_value(module), F, Args). callback(Mod, Fun, Args) -> case catch apply(Mod, Fun, Args) of {'EXIT', _} = Err -> ?ERROR_MSG("failed to process callback:~n" "** Function: ~p:~p/~p~n" "** Args: ~p~n" "** Reason: ~p", [Mod, Fun, length(Args), Args, Err]), {error, internal_server_error}; Result -> Result end. %% Basic Timers timer1() -> get_config_value(timer1). timer2() -> get_config_value(timer2). timer4() -> get_config_value(timer4). error_status({error, Err}) -> error_status(Err); error_status(timeout) -> {408, reason(408)}; error_status(no_contact_header) -> {400, <<"Missed Contact header">>}; error_status(too_many_transactions) -> {500, <<"Too Many Transactions">>}; error_status(unsupported_uri_scheme) -> {416, reason(416)}; error_status(unsupported_transport) -> {503, "Unsupported Transport"}; error_status(Err) when is_atom(Err) -> case inet:format_error(Err) of "unknown POSIX error" -> {500, reason(500)}; [H|T] when H >= $a, H =< $z -> {503, list_to_binary([H - $ |T])}; Txt -> {503, Txt} end; error_status(_) -> {500, reason(500)}. get_node_by_tag(Tag) -> case esip_codec:split(Tag, $-, 1) of [NodeID, _] -> get_node_by_id(NodeID); _ -> node() end. get_node_by_id(NodeID) when is_binary(NodeID) -> case catch erlang:binary_to_existing_atom(NodeID, utf8) of {'EXIT', _} -> node(); Res -> get_node_by_id(Res) end; get_node_by_id(NodeID) -> case global:whereis_name(NodeID) of Pid when is_pid(Pid) -> node(Pid); _ -> node() end. %% From http://www.iana.org/assignments/sip-parameters reason(100) -> <<"Trying">>; reason(180) -> <<"Ringing">>; reason(181) -> <<"Call Is Being Forwarded">>; reason(182) -> <<"Queued">>; reason(183) -> <<"Session Progress">>; reason(200) -> <<"OK">>; reason(202) -> <<"Accepted">>; reason(204) -> <<"No Notification">>; reason(300) -> <<"Multiple Choices">>; reason(301) -> <<"Moved Permanently">>; reason(302) -> <<"Moved Temporarily">>; reason(305) -> <<"Use Proxy">>; reason(380) -> <<"Alternative Service">>; reason(400) -> <<"Bad Request">>; reason(401) -> <<"Unauthorized">>; reason(402) -> <<"Payment Required">>; reason(403) -> <<"Forbidden">>; reason(404) -> <<"Not Found">>; reason(405) -> <<"Method Not Allowed">>; reason(406) -> <<"Not Acceptable">>; reason(407) -> <<"Proxy Authentication Required">>; reason(408) -> <<"Request Timeout">>; reason(410) -> <<"Gone">>; reason(412) -> <<"Conditional Request Failed">>; reason(413) -> <<"Request Entity Too Large">>; reason(414) -> <<"Request-URI Too Long">>; reason(415) -> <<"Unsupported Media Type">>; reason(416) -> <<"Unsupported URI Scheme">>; reason(417) -> <<"Unknown Resource-Priority">>; reason(420) -> <<"Bad Extension">>; reason(421) -> <<"Extension Required">>; reason(422) -> <<"Session Interval Too Small">>; reason(423) -> <<"Interval Too Brief">>; reason(428) -> <<"Use Identity Header">>; reason(429) -> <<"Provide Referrer Identity">>; reason(430) -> <<"Flow Failed">>; reason(433) -> <<"Anonymity Disallowed">>; reason(436) -> <<"Bad Identity-Info">>; reason(437) -> <<"Unsupported Certificate">>; reason(438) -> <<"Invalid Identity Header">>; reason(439) -> <<"First Hop Lacks Outbound Support">>; reason(440) -> <<"Max-Breadth Exceeded">>; reason(469) -> <<"Bad Info Package">>; reason(470) -> <<"Consent Needed">>; reason(480) -> <<"Temporarily Unavailable">>; reason(481) -> <<"Call/Transaction Does Not Exist">>; reason(482) -> <<"Loop Detected">>; reason(483) -> <<"Too Many Hops">>; reason(484) -> <<"Address Incomplete">>; reason(485) -> <<"Ambiguous">>; reason(486) -> <<"Busy Here">>; reason(487) -> <<"Request Terminated">>; reason(488) -> <<"Not Acceptable Here">>; reason(489) -> <<"Bad Event">>; reason(491) -> <<"Request Pending">>; reason(493) -> <<"Undecipherable">>; reason(494) -> <<"Security Agreement Required">>; reason(500) -> <<"Server Internal Error">>; reason(501) -> <<"Not Implemented">>; reason(502) -> <<"Bad Gateway">>; reason(503) -> <<"Service Unavailable">>; reason(504) -> <<"Server Time-out">>; reason(505) -> <<"Version Not Supported">>; reason(513) -> <<"Message Too Large">>; reason(580) -> <<"Precondition Failure">>; reason(600) -> <<"Busy Everywhere">>; reason(603) -> <<"Decline">>; reason(604) -> <<"Does Not Exist Anywhere">>; reason(606) -> <<"Not Acceptable">>; reason(Status) when Status > 100, Status < 200 -> <<"Session Progress">>; reason(Status) when Status > 200, Status < 300 -> <<"Accepted">>; reason(Status) when Status > 300, Status < 400 -> <<"Multiple Choices">>; reason(Status) when Status > 400, Status < 500 -> <<"Bad Request">>; reason(Status) when Status > 500, Status < 600 -> <<"Server Internal Error">>; reason(Status) when Status > 600, Status < 700 -> <<"Busy Everywhere">>. warning(300) -> <<"\"Incompatible network protocol\"">>; warning(301) -> <<"\"Incompatible network address formats\"">>; warning(302) -> <<"\"Incompatible transport protocol\"">>; warning(303) -> <<"\"Incompatible bandwidth units\"">>; warning(304) -> <<"\"Media type not available\"">>; warning(305) -> <<"\"Incompatible media format\"">>; warning(306) -> <<"\"Attribute not understood\"">>; warning(307) -> <<"\"Session description parameter not understood\"">>; warning(330) -> <<"\"Multicast not available\"">>; warning(331) -> <<"\"Unicast not available\"">>; warning(370) -> <<"\"Insufficient bandwidth\"">>; warning(380) -> <<"\"SIPS Not Allowed\"">>; warning(381) -> <<"\"SIPS Required\"">>; warning(399) -> <<"\"Miscellaneous warning\"">>; warning(Code) when Code > 300, Code < 400 -> <<"\"\"">>. %%==================================================================== %% gen_server callbacks %%==================================================================== init([]) -> {A, B, C} = now(), random:seed(A, B, C), ets:new(esip_config, [named_table, public]), set_config([]), NodeID = list_to_binary(integer_to_list(random:uniform(1 bsl 32))), register_node(NodeID), {ok, #state{node_id = NodeID}}. handle_call(make_tag, _From, State) -> {reply, {State#state.node_id, random:uniform(1 bsl 32)}, State}; handle_call(make_branch, _From, State) -> {reply, random:uniform(1 bsl 48), State}; handle_call(make_callid, _From, State) -> {reply, random:uniform(1 bsl 48), State}; handle_call(make_cseq, _From, State) -> {reply, random:uniform(1 bsl 10), State}; handle_call(stop, _From, State) -> {stop, normal, State}; handle_call(_Request, _From, State) -> {reply, bad_request, State}. handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> ?ERROR_MSG("got unexpected info: ~p", [_Info]), {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%-------------------------------------------------------------------- %% Internal functions %%-------------------------------------------------------------------- default_config() -> Software = case catch application:get_key(esip, vsn) of {ok, [_|_] = Ver} -> list_to_binary(["esip/", Ver]); _ -> <<"esip">> end, [{max_forwards, 70}, {timer1, 500}, {timer2, 4000}, {timer4, 5000}, {software, Software}, {max_msg_size, 128*1024}]. set_config(Opts) -> lists:foreach( fun({Key, Value}) -> ets:insert(esip_config, {Key, Value}); (_) -> ok end, default_config() ++ Opts). int_to_list(N) -> erlang:integer_to_list(N). register_node(NodeID) -> global:register_name(erlang:binary_to_atom(NodeID, utf8), self()). unquote(<<$", Rest/binary>>) -> case size(Rest) - 1 of Size when Size > 0 -> <> = Rest, Result; _ -> <<>> end; unquote(Val) -> Val. quote(Val) -> <<$", Val/binary, $">>. md5_digest(Data) -> hex_encode(erlang:md5(Data)). compute_digest(Nonce, CNonce, NC, QOP, Algo, Realm, URI, Method, Body, Username, Password) -> AlgoL = to_lower(Algo), QOPL = to_lower(QOP), A1 = if AlgoL == <<"md5">>; AlgoL == <<>> -> [unquote(Username), $:, unquote(Realm), $:, Password]; true -> [md5_digest([unquote(Username), $:, unquote(Realm), $:, Password]), $:, unquote(Nonce), $:, unquote(CNonce)] end, A2 = if QOPL == <<"auth">>; QOPL == <<>> -> [Method, $:, unquote(URI)]; true -> [Method, $:, unquote(URI), $:, md5_digest(Body)] end, if QOPL == <<"auth">>; QOPL == <<"auth-int">> -> md5_digest( [md5_digest(A1), $:, unquote(Nonce), $:, NC, $:, unquote(CNonce), $:, unquote(QOP), $:, md5_digest(A2)]); true -> md5_digest( [md5_digest(A1), $:, unquote(Nonce), $:, md5_digest(A2)]) end. p1_sip-1.0.1/src/esip_udp_sup.erl0000644000175000017500000000336412650734252017270 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% File : esip_udp_sup.erl %%% Author : Evgeniy Khramtsov %%% Purpose : %%% Created : 25 Apr 2014 by Evgeniy Khramtsov %%% %%% %%% Copyright (C) 2002-2016 ProcessOne, SARL. All Rights Reserved. %%% %%% Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 %%% %%% Unless required by applicable law or agreed to in writing, software %%% distributed under the License is distributed on an "AS IS" BASIS, %%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %%% See the License for the specific language governing permissions and %%% limitations under the License. %%% %%%---------------------------------------------------------------------- -module(esip_udp_sup). -behaviour(supervisor). %% API -export([start_link/0]). %% Supervisor callbacks -export([init/1]). %%%=================================================================== %%% API functions %%%=================================================================== start_link() -> supervisor:start_link({local, ?MODULE}, ?MODULE, []). %%%=================================================================== %%% Supervisor callbacks %%%=================================================================== init([]) -> PoolSize = esip_socket:get_pool_size(), {ok, {{one_for_one, PoolSize * 10, 1}, []}}. %%%=================================================================== %%% Internal functions %%%=================================================================== p1_sip-1.0.1/src/esip_transaction.erl0000644000175000017500000002050712650734252020134 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% File : esip_transaction.erl %%% Author : Evgeniy Khramtsov %%% Purpose : Route client/server transactions %%% Created : 15 Jul 2009 by Evgeniy Khramtsov %%% %%% %%% Copyright (C) 2002-2016 ProcessOne, SARL. All Rights Reserved. %%% %%% Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 %%% %%% Unless required by applicable law or agreed to in writing, software %%% distributed under the License is distributed on an "AS IS" BASIS, %%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %%% See the License for the specific language governing permissions and %%% limitations under the License. %%% %%%---------------------------------------------------------------------- -module(esip_transaction). -behaviour(gen_server). %% API -export([start_link/0, process/2, reply/2, cancel/2, request/3, request/4, insert/4, delete/3, stop/1]). %% gen_server callbacks -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -include("esip.hrl"). -include("esip_lib.hrl"). -record(state, {}). %%==================================================================== %% API %%==================================================================== start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). process(SIPSock, #sip{method = Method, hdrs = Hdrs, type = request} = Req) -> Branch = esip:get_branch(Hdrs), case lookup(transaction_key(Branch, Method, server)) of {ok, Pid} -> esip_server_transaction:route(Pid, Req); error when Method == <<"ACK">> -> case esip_dialog:lookup(esip_dialog:id(uas, Req)) of {ok, Core, _} -> pass_to_core(Core, Req, SIPSock); _Err -> esip:callback(request, [Req, SIPSock]) end; error when Method == <<"CANCEL">> -> case lookup({esip:to_lower(Branch), server}) of {ok, Pid} -> esip_server_transaction:route(Pid, Req), start_server_transaction(SIPSock, Req); error -> case esip:callback(request, [Req, SIPSock]) of #sip{type = response} = Resp -> esip_transport:send(SIPSock, Resp); drop -> ok; _ -> Resp = esip:make_response( Req, #sip{type = response, status = 481}, esip:make_tag()), esip_transport:send(SIPSock, Resp) end end; error -> start_server_transaction(SIPSock, Req) end; process(SIPSock, #sip{method = Method, hdrs = Hdrs, type = response} = Resp) -> Branch = esip:get_branch(Hdrs), case lookup(transaction_key(Branch, Method, client)) of {ok, Pid} -> esip_client_transaction:route(Pid, Resp); _ -> esip:callback(response, [Resp, SIPSock]) end. reply(#trid{owner = Pid, type = server}, #sip{type = response} = Resp) -> esip_server_transaction:route(Pid, Resp); reply(#sip{method = Method, type = request, hdrs = Hdrs}, #sip{type = response} = Resp) -> Branch = esip:get_branch(Hdrs), case lookup(transaction_key(Branch, Method, server)) of {ok, Pid} -> esip_server_transaction:route(Pid, Resp); error -> ok end; reply(_, _) -> ok. request(SIPSock, Req, TU) -> request(SIPSock, Req, TU, []). request(SIPSock, #sip{type = request} = Req, TU, Opts) -> start_client_transaction(SIPSock, Req, TU, Opts). cancel(#sip{method = Method, type = request, hdrs = Hdrs}, TU) -> Branch = esip:get_branch(Hdrs), case lookup(transaction_key(Branch, Method, client)) of {ok, Pid} -> esip_client_transaction:cancel(Pid, TU); error -> ok end; cancel(#trid{type = client, owner = Pid}, TU) -> esip_client_transaction:cancel(Pid, TU). stop(#trid{owner = Pid, type = client}) -> esip_client_transaction:stop(Pid); stop(#trid{owner = Pid, type = server}) -> esip_server_transaction:stop(Pid). insert(Branch, Method, Type, Pid) -> ets:update_counter(?MODULE, {transaction_number, Type}, 1), ets:insert(?MODULE, {transaction_key(Branch, Method, Type), Pid}). delete(Branch, Method, Type) -> ets:update_counter(?MODULE, {transaction_number, Type}, -1), ets:delete(?MODULE, transaction_key(Branch, Method, Type)). %%==================================================================== %% gen_server callbacks %%==================================================================== init([]) -> ets:new(?MODULE, [public, named_table]), ets:insert(?MODULE, {{transaction_number, client}, 0}), ets:insert(?MODULE, {{transaction_number, server}, 0}), ets:insert(?MODULE, {{last_error_report, client}, {0, 0, 0}}), ets:insert(?MODULE, {{last_error_report, server}, {0, 0, 0}}), {ok, #state{}}. handle_call(_Request, _From, State) -> {reply, bad_request, State}. handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%-------------------------------------------------------------------- %% Internal functions %%-------------------------------------------------------------------- lookup(TransactionKey) -> case ets:lookup(?MODULE, TransactionKey) of [{_, Pid}] -> {ok, Pid}; _ -> error end. transaction_key(Branch, <<"CANCEL">>, Type) -> {esip:to_lower(Branch), cancel, Type}; transaction_key(Branch, _Method, Type) -> {esip:to_lower(Branch), Type}. pass_to_core(Core, Req, SIPSock) -> case Core of F when is_function(F) -> F(Req, SIPSock, undefined); {M, F, A} -> apply(M, F, [Req, SIPSock, undefined | A]) end. start_server_transaction(SIPSock, Req) -> MaxTransactions = esip:get_config_value(max_server_transactions), case ets:lookup(?MODULE, {transaction_number, server}) of [{_, N}] when N >= MaxTransactions -> maybe_report_error(server, N), {Status, Reason} = esip:error_status({error, too_many_transactions}), esip_transport:send(SIPSock, esip:make_response( Req, #sip{type = response, status = Status, reason = Reason}, esip:make_tag())); _ -> case esip_server_transaction:start(SIPSock, Req) of {ok, _} -> ok; Err -> {Status, Reason} = esip:error_status(Err), esip_transport:send(SIPSock, esip:make_response( Req, #sip{type = response, status = Status, reason = Reason}, esip:make_tag())) end end. start_client_transaction(SIPSock, Req, TU, Opts) -> MaxTransactions = esip:get_config_value(max_client_transactions), case ets:lookup(?MODULE, {transaction_number, client}) of [{_, N}] when N >= MaxTransactions -> maybe_report_error(client, N), {error, too_many_transactions}; _ -> esip_client_transaction:start(SIPSock, Req, TU, Opts) end. maybe_report_error(Type, N) -> case ets:lookup(?MODULE, {last_error_report, Type}) of [{_, Now}] -> case timer:now_diff(now(), Now) of T when T > 60000000 -> ets:insert(?MODULE, {{last_error_report, Type}, now()}), ?ERROR_MSG("too many ~s transactions: ~p", [Type, N]); _ -> ok end; _ -> ok end. p1_sip-1.0.1/src/esip_transport.erl0000644000175000017500000004744112650734252017651 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% File : esip_transport.erl %%% Author : Evgeniy Khramtsov %%% Purpose : Transport layer %%% Created : 14 Jul 2009 by Evgeniy Khramtsov %%% %%% %%% Copyright (C) 2002-2016 ProcessOne, SARL. All Rights Reserved. %%% %%% Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 %%% %%% Unless required by applicable law or agreed to in writing, software %%% distributed under the License is distributed on an "AS IS" BASIS, %%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %%% See the License for the specific language governing permissions and %%% limitations under the License. %%% %%%---------------------------------------------------------------------- -module(esip_transport). %% API -export([recv/2, send/2, start_link/0, register_socket/4, unregister_socket/4, register_udp_listener/1, unregister_udp_listener/1, connect/1, connect/2, register_route/3, unregister_route/3, via_transport_to_atom/1]). -behaviour(gen_server). %% gen_server callbacks -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -include("esip.hrl"). -include("esip_lib.hrl"). -include_lib("kernel/include/inet.hrl"). -record(route, {transport, host, port}). -record(state, {}). %%==================================================================== %% API %%==================================================================== start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). recv(SIPSock, #sip{type = request} = Req) -> case prepare_request(SIPSock, Req) of #sip{} = NewReq -> case esip:callback(message_in, [NewReq, SIPSock]) of drop -> ok; #sip{type = request} = NewReq1 -> esip_transaction:process(SIPSock, NewReq1); #sip{type = response} = Resp -> send(SIPSock, Resp); _ -> esip_transaction:process(SIPSock, NewReq) end; _ -> ok end; recv(SIPSock, #sip{type = response} = Resp) -> case esip:callback(message_in, [Resp, SIPSock]) of drop -> ok; #sip{type = response} = NewResp -> esip_transaction:process(SIPSock, NewResp); _ -> esip_transaction:process(SIPSock, Resp) end. send(SIPSock, Msg) -> NewMsg = case esip:callback(message_out, [Msg, SIPSock]) of drop -> ok; Msg1 = #sip{} -> Msg1; _ -> Msg end, do_send(SIPSock, NewMsg). connect(SIPMsg) -> connect(SIPMsg, []). connect(#sip{type = request, uri = URI, hdrs = Hdrs} = Req, Opts) -> NewURI = case esip:callback(locate, [Req]) of U = #uri{} -> U; _ -> case esip:get_hdrs('route', Hdrs) of [{_, RouteURI, _}|_] -> RouteURI; _ -> URI end end, do_connect(NewURI, Opts); connect(#sip{type = response, hdrs = Hdrs} = Resp, Opts) -> NewVia = case esip:callback(locate, [Resp]) of Via = #via{} -> Via; _ -> [Via|_] = esip:get_hdrs('via', Hdrs), Via end, do_connect(NewVia, Opts). do_connect(URIorVia, Opts) -> case resolve(URIorVia) of {ok, AddrsPorts, Transport} -> case lookup_socket(AddrsPorts, Transport, get_certfile(Opts)) of {ok, Sock} -> {ok, Sock}; _ -> case Transport of tcp -> esip_socket:connect(AddrsPorts, Opts); tls -> esip_socket:connect(AddrsPorts, [tls|Opts]); udp -> case get_udp_listener() of {ok, UDPSock} -> esip_socket:connect(AddrsPorts, UDPSock); _ -> {error, eprotonosupport} end; _ -> {error, eprotonosupport} end end; Err -> Err end. via_transport_to_atom(<<"TLS">>) -> tls; via_transport_to_atom(<<"TCP">>) -> tcp; via_transport_to_atom(<<"UDP">>) -> udp; via_transport_to_atom(_) -> unknown. register_socket(Addr, tls, Sock, CertFile) -> ets:insert(esip_socket, {{Addr, tls, CertFile}, Sock}); register_socket(Addr, Transport, Sock, _CertFile) -> ets:insert(esip_socket, {{Addr, Transport}, Sock}). unregister_socket(Addr, tls, Sock, CertFile) -> ets:delete_object(esip_socket, {{Addr, tls, CertFile}, Sock}); unregister_socket(Addr, Transport, Sock, _CertFile) -> ets:delete_object(esip_socket, {{Addr, Transport}, Sock}). lookup_socket([Addr|Rest], Transport, CertFile) -> case lookup_socket(Addr, Transport, CertFile) of {ok, Sock} -> {ok, Sock}; _ -> lookup_socket(Rest, Transport, CertFile) end; lookup_socket([], _, _) -> error; lookup_socket(Addr, tls, CertFile) -> case ets:lookup(esip_socket, {Addr, tls, CertFile}) of [{_, Sock}|_] -> {ok, Sock}; _ -> error end; lookup_socket(Addr, Transport, _CertFile) -> case ets:lookup(esip_socket, {Addr, Transport}) of [{_, Sock}|_] -> {ok, Sock}; _ -> error end. register_udp_listener(SIPSock) -> ets:insert(esip_socket, {udp, SIPSock}). unregister_udp_listener(SIPSock) -> ets:delete_object(esip_socket, {udp, SIPSock}). get_udp_listener() -> case ets:lookup(esip_socket, udp) of [{_, SIPSock}|_] -> {ok, SIPSock}; _ -> error end. register_route(Transport, Host, Port) -> ets:insert(esip_route, #route{transport = Transport, host = Host, port = Port}). unregister_route(Transport, Host, Port) -> ets:delete_object(esip_route, #route{transport = Transport, host = Host, port = Port}). get_all_routes() -> ets:tab2list(esip_route). supported_transports() -> supported_transports(all). supported_transports(Type) -> lists:flatmap( fun(#route{transport = Transport}) -> case Transport of tls when Type == tls -> [Transport]; _ when Type == tls -> []; _ -> [Transport] end end, get_all_routes()). supported_uri_schemes() -> case supported_transports(tls) of [] -> [<<"sip">>]; _ -> [<<"sips">>, <<"sip">>] end. %%==================================================================== %% gen_server callbacks %%==================================================================== init([]) -> ets:new(esip_socket, [public, named_table, bag]), ets:new(esip_route, [public, named_table, bag, {keypos, #route.transport}]), {ok, #state{}}. handle_call(_Request, _From, State) -> {reply, bad_request, State}. handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%==================================================================== %% Internal functions %%==================================================================== prepare_request(#sip_socket{peer = {Addr, Port}, type = SockType}, #sip{hdrs = Hdrs} = Request) -> case esip:split_hdrs('via', Hdrs) of {[#via{params = Params, host = Host} = Via|Vias], RestHdrs} -> case is_valid_via(Via, SockType) andalso is_valid_hdrs(RestHdrs) of true -> Params1 = case host_to_ip(Host) of {ok, Addr} -> Params; _ -> esip:set_param(<<"received">>, ip_to_host(Addr), Params) end, Params2 = case esip:get_param(<<"rport">>, Params1, false) of <<>> -> esip:set_param(<<"rport">>, list_to_binary( integer_to_list(Port)), Params1); _ -> Params1 end, NewVia = {'via', [Via#via{params = Params2}|Vias]}, NewRestHdrs = case esip:get_hdr('max-forwards', RestHdrs) of undefined -> MF = esip:get_config_value(max_forwards), [{'max-forwards', MF}|RestHdrs]; _ -> RestHdrs end, Request#sip{hdrs = [NewVia|NewRestHdrs]}; false -> error end; _ -> error end. is_valid_hdrs(Hdrs) -> try From = esip:get_hdr('from', Hdrs), To = esip:get_hdr('to', Hdrs), CSeq = esip:get_hdr('cseq', Hdrs), CallID = esip:get_hdr('call-id', Hdrs), has_from(From) and has_to(To) and (CSeq /= undefined) and (CallID /= undefined) catch _:_ -> false end. is_valid_via(#via{transport = _Transport, params = Params}, _SockType) -> case esip:get_param(<<"branch">>, Params) of <<>> -> false; _ -> true end. has_from({_, #uri{}, _}) -> true; has_from(_) -> false. has_to({_, #uri{}, _}) -> true; has_to(_) -> false. do_send(SIPSock, Msg) -> case catch esip_codec:encode(Msg) of {'EXIT', _} = Err -> ?ERROR_MSG("failed to encode:~n" "** Packet: ~p~n** Reason: ~p", [Msg, Err]); Data -> esip:callback(data_out, [Data, SIPSock]), esip_socket:send(SIPSock, Data) end. host_to_ip(Host) when is_binary(Host) -> host_to_ip(binary_to_list(Host)); host_to_ip(Host) -> case Host of "[" -> {error, einval}; "[" ++ Rest -> inet_parse:ipv6_address(string:substr(Rest, 1, length(Rest)-1)); _ -> inet_parse:address(Host) end. ip_to_host({0,0,0,0,0,16#ffff,X,Y}) -> <> = <>, ip_to_host({A, B, C, D}); ip_to_host({_, _, _, _} = Addr) -> list_to_binary(inet_parse:ntoa(Addr)); ip_to_host(IPv6Addr) -> iolist_to_binary( [$[, esip_codec:to_lower(list_to_binary(inet_parse:ntoa(IPv6Addr))), $]]). srv_prefix(tls) -> "_sips._tcp."; srv_prefix(tcp) -> "_sip._tcp."; srv_prefix(udp) -> "_sip._udp.". default_port(tls) -> 5061; default_port(_) -> 5060. resolve(#uri{scheme = Scheme} = URI) -> case lists:member(Scheme, supported_uri_schemes()) of true -> SupportedTransports = case Scheme of <<"sips">> -> supported_transports(tls); _ -> supported_transports() end, case SupportedTransports of [] -> {error, unsupported_transport}; _ -> do_resolve(URI, SupportedTransports) end; false -> {error, unsupported_uri_scheme} end; resolve(#via{transport = ViaTransport} = Via) -> Transport = via_transport_to_atom(ViaTransport), case lists:member(Transport, supported_transports()) of true -> do_resolve(Via, Transport); false -> {error, unsupported_transport} end. do_resolve(#uri{host = Host, port = Port, params = Params}, SupportedTransports) -> case esip:to_lower(esip:get_param(<<"transport">>, Params)) of <<>> -> [FallbackTransport|_] = lists:sort(fun sort_transport/2, SupportedTransports), case host_to_ip(Host) of {ok, Addr} -> select_host_port(Addr, Port, FallbackTransport); _ when is_integer(Port) -> select_host_port(Host, Port, FallbackTransport); _ -> case naptr_srv_lookup(Host, SupportedTransports) of {ok, _, _} = Res -> Res; _Err -> select_host_port(Host, Port, FallbackTransport) end end; TransportBinary -> Transport = (catch erlang:binary_to_existing_atom( TransportBinary, utf8)), case lists:member(Transport, SupportedTransports) of true -> case host_to_ip(Host) of {ok, Addr} -> select_host_port(Addr, Port, Transport); _ when is_integer(Port) -> select_host_port(Host, Port, Transport); _ -> case srv_lookup(Host, [Transport]) of {ok, _, _} = Res -> Res; _Err -> select_host_port(Host, Port, Transport) end end; false -> {error, unsupported_transport} end end; do_resolve(#via{transport = ViaTransport, host = Host, port = Port, params = Params}, Transport) -> NewPort = if ViaTransport == <<"UDP">> -> case esip:get_param(<<"rport">>, Params) of <<>> -> Port; RPort -> case esip_codec:to_integer(RPort, 1, 65535) of {ok, PortInt} -> PortInt; _ -> Port end end; true -> Port end, NewHost = case esip:get_param(<<"received">>, Params) of <<>> -> Host; Host1 -> Host1 end, case host_to_ip(NewHost) of {ok, Addr} -> select_host_port(Addr, NewPort, Transport); _ when is_integer(NewPort) -> select_host_port(NewHost, NewPort, Transport); _ -> case srv_lookup(NewHost, [Transport]) of {ok, _, _} = Res -> Res; _Err -> select_host_port(NewHost, NewPort, Transport) end end. select_host_port(Addr, Port, Transport) when is_tuple(Addr) -> NewPort = if is_integer(Port) -> Port; true -> default_port(Transport) end, {ok, [{Addr, NewPort}], Transport}; select_host_port(Host, Port, Transport) when is_integer(Port) -> case a_lookup(Host) of {error, _} = Err -> Err; {ok, Addrs} -> {ok, [{Addr, Port} || Addr <- Addrs], Transport} end; select_host_port(Host, Port, Transport) -> NewPort = if is_integer(Port) -> Port; true -> default_port(Transport) end, case a_lookup(Host) of {ok, Addrs} -> {ok, [{Addr, NewPort} || Addr <- Addrs], Transport}; Err -> Err end. naptr_srv_lookup(Host, Transports) when is_binary(Host) -> naptr_srv_lookup(binary_to_list(Host), Transports); naptr_srv_lookup(Host, Transports) -> case naptr_lookup(Host) of {error, _Err} -> srv_lookup(Host, Transports); SRVHosts -> case lists:filter( fun({_, T}) -> lists:member(T, Transports) end, SRVHosts) of [{SRVHost, Transport}|_] -> case srv_lookup(SRVHost) of {error, _} = Err -> Err; AddrsPorts -> {ok, AddrsPorts, Transport} end; _ -> srv_lookup(Host, Transports) end end. srv_lookup(Host, Transports) when is_binary(Host) -> srv_lookup(binary_to_list(Host), Transports); srv_lookup(Host, Transports) -> lists:foldl( fun(_Transport, {ok, _, _} = Acc) -> Acc; (Transport, Err) -> SRVHost = srv_prefix(Transport) ++ Host, case srv_lookup(SRVHost) of {error, _} = Err -> Err; AddrsPorts -> {ok, AddrsPorts, Transport} end end, {error, nxdomain}, Transports). naptr_lookup(Host) when is_binary(Host) -> naptr_lookup(binary_to_list(Host)); naptr_lookup(Host) -> case inet_res:getbyname(Host, naptr) of {ok, #hostent{h_addr_list = Addrs}} -> L = lists:flatmap( fun({_Order, _Pref, "s", Service, _Regexp, SRVHost}) -> case Service of "sips+d2t" -> [{SRVHost, tls}]; "sip+d2t" -> [{SRVHost, tcp}]; "sip+d2u" -> [{SRVHost, udp}]; _ -> [] end; (_) -> [] end, Addrs), lists:reverse( lists:sort( fun({_, T1}, {_, T2}) -> sort_transport(T1, T2) end, L)); Err -> Err end. srv_lookup(Host) when is_binary(Host) -> srv_lookup(binary_to_list(Host)); srv_lookup(Host) -> case inet_res:getbyname(Host, srv) of {ok, #hostent{h_addr_list = Rs}} -> case lists:flatmap( fun({_, _, Port, HostName}) -> case a_lookup(HostName) of {ok, Addrs} -> [{Addr, Port} || Addr <- Addrs]; _ -> [] end end, lists:keysort(1, Rs)) of [] -> {error, nxdomain}; Res -> Res end; Err -> Err end. a_lookup(Host) when is_binary(Host) -> a_lookup(binary_to_list(Host)); a_lookup(Host) -> case inet_res:getbyname(Host, a) of {ok, #hostent{h_addr_list = Addrs}} -> {ok, Addrs}; Err -> case inet_res:getbyname(Host, aaaa) of {ok, #hostent{h_addr_list = Addrs}} -> {ok, Addrs}; Err -> Err end end. sort_transport(udp, udp) -> true; sort_transport(udp, tcp) -> true; sort_transport(udp, tls) -> true; sort_transport(tcp, udp) -> false; sort_transport(tcp, tcp) -> true; sort_transport(tcp, tls) -> true; sort_transport(tls, udp) -> false; sort_transport(tls, tcp) -> false; sort_transport(tls, tls) -> true. get_certfile(Opts) -> case catch iolist_to_binary(proplists:get_value(certfile, Opts)) of Filename when is_binary(Filename), Filename /= <<"">> -> Filename; _ -> undefined end. p1_sip-1.0.1/src/esip.app.src0000644000175000017500000000236212650734252016312 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% File : esip.app.src %%% Author : Evgeniy Khramtsov %%% Purpose : Application package description %%% Created : 4 Apr 2013 by Evgeniy Khramtsov %%% %%% %%% Copyright (C) 2002-2016 ProcessOne, SARL. All Rights Reserved. %%% %%% Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 %%% %%% Unless required by applicable law or agreed to in writing, software %%% distributed under the License is distributed on an "AS IS" BASIS, %%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %%% See the License for the specific language governing permissions and %%% limitations under the License. %%% %%%---------------------------------------------------------------------- {application, esip, [{description, "esip"}, {vsn, "1.0.1"}, {modules, []}, {registered, []}, {applications, [kernel, stdlib]}, {env, []}, {mod, {esip_app, []}}]}. %% Local Variables: %% mode: erlang %% End: %% vim: set filetype=erlang tabstop=8: p1_sip-1.0.1/src/esip_dialog.erl0000644000175000017500000002576612650734252017062 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% File : esip_dialog.erl %%% Author : Evgeniy Khramtsov %%% Purpose : %%% Created : 29 Dec 2010 by Evgeniy Khramtsov %%% %%% %%% Copyright (C) 2002-2016 ProcessOne, SARL. All Rights Reserved. %%% %%% Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 %%% %%% Unless required by applicable law or agreed to in writing, software %%% distributed under the License is distributed on an "AS IS" BASIS, %%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %%% See the License for the specific language governing permissions and %%% limitations under the License. %%% %%%---------------------------------------------------------------------- -module(esip_dialog). -behaviour(gen_server). %% API -export([start_link/0, open/4, id/2, close/1, lookup/1, prepare_request/2, update_remote_seqnum/2, update_local_seqnum/2]). %% gen_server callbacks -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -include("esip.hrl"). -include("esip_lib.hrl"). -record(state, {}). %%%=================================================================== %%% API %%%=================================================================== start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). id(Type, #sip{hdrs = Hdrs}) -> CallID = esip:to_lower(esip:get_hdr('call-id', Hdrs)), {_, _, ToParams} = esip:get_hdr('to', Hdrs), {_, _, FromParams} = esip:get_hdr('from', Hdrs), ToTag = esip:to_lower(esip:get_param(<<"tag">>, ToParams)), FromTag = esip:to_lower(esip:get_param(<<"tag">>, FromParams)), case Type of uac -> #dialog_id{'call-id' = CallID, remote_tag = ToTag, local_tag = FromTag}; uas -> #dialog_id{'call-id' = CallID, remote_tag = FromTag, local_tag = ToTag} end. open(Req, #sip{type = response, hdrs = RespHdrs, status = Status}, uas, TU) -> {_, _, ToParams} = esip:get_hdr('to', RespHdrs), LocalTag = esip:get_param(<<"tag">>, ToParams), open(Req, LocalTag, state(Status), TU); open(#sip{type = request, uri = URI, hdrs = ReqHdrs}, #sip{type = response, hdrs = RespHdrs, status = Status}, uac, TU) -> case esip:get_hdr('contact', RespHdrs) of [{_, RemoteTarget, _}|_] -> [#via{transport = Transport}|_] = esip:get_hdr('via', ReqHdrs), Secure = (esip_transport:via_transport_to_atom(Transport) == tls) and (URI#uri.scheme == <<"sips">>), RouteSet = lists:foldl( fun({_, U, _}, Acc) -> [U|Acc] end, [], esip:get_hdrs('record-route', RespHdrs)), LocalSeqNum = esip:get_hdr('cseq', ReqHdrs), CallID = esip:get_hdr('call-id', ReqHdrs), {_, LocalURI, FromParams} = esip:get_hdr('from', ReqHdrs), {_, RemoteURI, ToParams} = esip:get_hdr('to', RespHdrs), LocalTag = esip:get_param(<<"tag">>, FromParams), RemoteTag = esip:get_param(<<"tag">>, ToParams), Dialog = #dialog{secure = Secure, route_set = RouteSet, remote_target = RemoteTarget, local_seq_num = LocalSeqNum, 'call-id' = CallID, local_tag = LocalTag, remote_tag = RemoteTag, remote_uri = RemoteURI, local_uri = LocalURI, state = state(Status)}, DialogID = #dialog_id{'call-id' = esip:to_lower(CallID), remote_tag = esip:to_lower(RemoteTag), local_tag = esip:to_lower(LocalTag)}, case call({open, DialogID, Dialog, TU}) of ok -> {ok, DialogID}; Err -> Err end; _ -> {error, no_contact_header} end; open(#sip{type = request, uri = URI, hdrs = Hdrs}, LocalTag, State, TU) -> case esip:get_hdr('contact', Hdrs) of [{_, RemoteTarget, _}|_] -> [#via{transport = Transport}|_] = esip:get_hdr('via', Hdrs), Secure = (esip_transport:via_transport_to_atom(Transport) == tls) and (URI#uri.scheme == <<"sips">>), RouteSet = [U || {_, U, _} <- esip:get_hdrs('record-route', Hdrs)], RemoteSeqNum = esip:get_hdr('cseq', Hdrs), CallID = esip:get_hdr('call-id', Hdrs), {_, RemoteURI, FromParams} = esip:get_hdr('from', Hdrs), {_, LocalURI, _} = esip:get_hdr('to', Hdrs), RemoteTag = esip:get_param(<<"tag">>, FromParams), Dialog = #dialog{secure = Secure, route_set = RouteSet, remote_target = RemoteTarget, remote_seq_num = RemoteSeqNum, 'call-id' = CallID, local_tag = LocalTag, remote_tag = RemoteTag, remote_uri = RemoteURI, local_uri = LocalURI, state = State}, DialogID = #dialog_id{'call-id' = esip:to_lower(CallID), remote_tag = esip:to_lower(RemoteTag), local_tag = esip:to_lower(LocalTag)}, case call({open, DialogID, Dialog, TU}) of ok -> {ok, DialogID}; Err -> Err end; _ -> {error, no_contact_header} end. prepare_request(DialogID, #sip{type = request, method = Method, hdrs = Hdrs} = Req) -> case lookup(DialogID) of {ok, _TU, #dialog{secure = _Secure, route_set = RouteSet, local_seq_num = LocalSeqNum, remote_target = RemoteTarget, 'call-id' = CallID, remote_uri = RemoteURI, local_uri = LocalURI}} -> ToParams = if DialogID#dialog_id.remote_tag /= <<>> -> [{<<"tag">>, DialogID#dialog_id.remote_tag}]; true -> [] end, FromParams = if DialogID#dialog_id.local_tag /= <<>> -> [{<<"tag">>, DialogID#dialog_id.local_tag}]; true -> [] end, To = {<<>>, RemoteURI, ToParams}, From = {<<>>, LocalURI, FromParams}, CSeq = if is_integer(LocalSeqNum) -> if Method /= <<"CANCEL">>, Method /= <<"ACK">> -> LocalSeqNum + 1; true -> LocalSeqNum end; true -> esip:make_cseq() end, update_local_seqnum(DialogID, CSeq), {RequestURI, Routes} = case RouteSet of [] -> {RemoteTarget, []}; [#uri{params = Params} = URI|URIs] -> case esip:has_param(<<"lr">>, Params) of true -> {RemoteTarget, [{'route', [{<<>>, U, []}]} || U <- RouteSet]}; false -> {URI, [{'route', [{<<>>, U, []}]} || U <- URIs ++ [RemoteTarget]]} end end, {_, NewHdrs} = esip:split_hdrs(['from', 'to', 'cseq', 'route', 'call-id'], Hdrs), Req#sip{uri = RequestURI, hdrs = Routes ++ [{'to', To}, {'from', From}, {'cseq', CSeq}, {'call-id', CallID}|NewHdrs]}; _ -> Req end. update_remote_seqnum(DialogID, CSeq) -> gen_server:cast(?MODULE, {update_seqnum, remote, DialogID, CSeq}). update_local_seqnum(DialogID, CSeq) -> gen_server:cast(?MODULE, {update_seqnum, local, DialogID, CSeq}). close(DialogID) -> call({close, DialogID}). lookup(DialogID) -> call({lookup, DialogID}). call(Msg) -> case catch gen_server:call(?MODULE, Msg, 5000) of {'EXIT', _} = Err -> ?ERROR_MSG("failed to comlete dialog operation:~n" "** Msg: ~p~n" "** Err: ~p", [Msg, Err]), {error, internal_server_error}; Res -> Res end. %%%=================================================================== %%% gen_server callbacks %%%=================================================================== init([]) -> ets:new(esip_dialog, [named_table, public]), {ok, #state{}}. handle_call({open, DialogID, Dialog, TU}, _From, State) -> ets:insert(esip_dialog, {DialogID, TU, Dialog}), {reply, ok, State}; handle_call({close, DialogID}, _From, State) -> ets:delete(esip_dialog, DialogID), {reply, ok, State}; handle_call({lookup, DialogID}, _From, State) -> case ets:lookup(esip_dialog, DialogID) of [{_, TU, Dialog}] -> {reply, {ok, TU, Dialog}, State}; _ -> {reply, {error, enoent}, State} end; handle_call(_Request, _From, State) -> Reply = ok, {reply, Reply, State}. handle_cast({update_seqnum, Type, DialogID, CSeq}, State) -> case ets:lookup(esip_dialog, DialogID) of [{_, TU, Dialog}] -> NewDialog = case Type of remote -> Dialog#dialog{remote_seq_num = CSeq}; local -> Dialog#dialog{local_seq_num = CSeq} end, ets:insert(esip_dialog, {DialogID, TU, NewDialog}), {noreply, State}; _ -> {noreply, State} end; handle_cast(_Msg, State) -> {noreply, State}. handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== state(Status) when Status < 200 -> early; state(_) -> confirmed. p1_sip-1.0.1/src/esip_tmp_sup.erl0000644000175000017500000000353312650734252017276 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% File : esip_tmp_sup.erl %%% Author : Evgeniy Khramtsov %%% Purpose : A pattern for simple_one_for_one supervisor %%% Created : 15 Jul 2009 by Evgeniy Khramtsov %%% %%% %%% Copyright (C) 2002-2016 ProcessOne, SARL. All Rights Reserved. %%% %%% Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 %%% %%% Unless required by applicable law or agreed to in writing, software %%% distributed under the License is distributed on an "AS IS" BASIS, %%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %%% See the License for the specific language governing permissions and %%% limitations under the License. %%% %%%---------------------------------------------------------------------- -module(esip_tmp_sup). %% API -export([start_link/2, init/1, start_child/4]). %%==================================================================== %% API %%==================================================================== start_link(Name, Module) -> supervisor:start_link({local, Name}, ?MODULE, Module). -ifndef(NO_TMP_SUP). start_child(Supervisor, _Module, _Behaviour, Opts) -> supervisor:start_child(Supervisor, Opts). -else. start_child(_Supervisor, Module, Behaviour, Opts) -> Behaviour:start(Module, Opts, []). -endif. init(Module) -> {ok, {{simple_one_for_one, 10, 1}, [{undefined, {Module, start_link, []}, temporary, brutal_kill, worker, [Module]}]}}. %%==================================================================== %% Internal functions %%==================================================================== p1_sip-1.0.1/src/esip_socket.erl0000644000175000017500000004011012650734252017067 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% File : esip_socket.erl %%% Author : Evgeniy Khramtsov %%% Purpose : %%% Created : 6 Jan 2011 by Evgeniy Khramtsov %%% %%% %%% Copyright (C) 2002-2016 ProcessOne, SARL. All Rights Reserved. %%% %%% Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 %%% %%% Unless required by applicable law or agreed to in writing, software %%% distributed under the License is distributed on an "AS IS" BASIS, %%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %%% See the License for the specific language governing permissions and %%% limitations under the License. %%% %%%---------------------------------------------------------------------- -module(esip_socket). -define(GEN_SERVER, p1_server). -behaviour(?GEN_SERVER). %% API -export([start_link/0, start_link/1, start_link/2, start/0, start/2, connect/1, connect/2, send/2, socket_type/0, udp_recv/5, udp_init/2, start_pool/0, get_pool_size/0, tcp_init/2, sockname/1, close/1]). %% gen_server callbacks -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -include("esip.hrl"). -include("esip_lib.hrl"). -include("stun.hrl"). -define(TCP_SEND_TIMEOUT, 15000). -define(CONNECT_TIMEOUT, 20000). -type addr() :: {inet:ip_address(), inet:port_number()}. -record(state, {type = udp :: udp | tcp | tls, addr :: addr(), peer :: addr(), sock :: port(), buf = <<>> :: binary(), max_size :: non_neg_integer(), msg :: #sip{}, wait_size :: non_neg_integer(), certfile :: iodata()}). %%%=================================================================== %%% API %%%=================================================================== %% @doc Start TCP client to connect start_link() -> ?GEN_SERVER:start_link(?MODULE, [], [{max_queue, 5000}]). %% @doc Start UDP worker start_link(I) -> ?GEN_SERVER:start_link({local, get_proc(I)}, ?MODULE, [], [{max_queue, 5000}]). %% @doc Start TCP acceptor start_link(Sock, Opts) -> ?GEN_SERVER:start_link(?MODULE, [Sock, Opts], [{max_queue, 5000}]). %% @doc Start TCP client to connect, the callback start() -> supervisor:start_child(esip_tcp_sup, []). socket_type() -> raw. start({gen_tcp, Sock}, Opts) -> supervisor:start_child(esip_tcp_sup, [Sock, Opts]). %% @doc TCP connect connect(Addrs) -> connect(Addrs, []). %% @doc first is UDP connect, second is TCP connect([AddrPort|_Addrs], #sip_socket{} = Sock) -> {ok, Sock#sip_socket{peer = AddrPort}}; connect(Addrs, Opts) when is_list(Opts) -> case start() of {ok, Pid} -> ?GEN_SERVER:call(Pid, {connect, Addrs, Opts}, 60000); Err -> Err end. send(#sip_socket{pid = Pid} = SIPSocket, Data) when node(Pid) /= node() -> Msg = {send, SIPSocket, Data}, case erlang:send(Pid, Msg, [noconnect, nosuspend]) of nosuspend -> {error, closed}; noconnect -> {error, closed}; _ -> ok end; send(#sip_socket{type = tls, sock = Sock}, Data) -> p1_tls:send(Sock, Data); send(#sip_socket{type = tcp, sock = Sock}, Data) -> gen_tcp:send(Sock, Data); send(#sip_socket{type = udp, sock = Sock, peer = {Addr, Port}}, Data) -> NewAddr = case Addr of {A, B, C, D} -> case inet:sockname(Sock) of {ok, {{_, _, _, _, _, _, _, _}, _}} -> {0, 0, 0, 0, 0, 16#ffff, (A bsl 8) bor B, (C bsl 8) bor D}; _ -> Addr end; {0, 0, 0, 0, 0, 16#ffff, X, Y} -> case inet:sockname(Sock) of {ok, {{_, _, _, _}, _}} -> <> = <>, {A, B, C, D}; _ -> Addr end; _ -> Addr end, gen_udp:send(Sock, NewAddr, Port, Data). close(#sip_socket{pid = Pid} = SIPSocket) when node(Pid) /= node() -> case erlang:send(Pid, {close, SIPSocket}, [noconnect, nosuspend]) of nosuspend -> {error, closed}; noconnect -> {error, closed}; _ -> ok end; close(#sip_socket{type = tls, sock = Sock}) -> p1_tls:close(Sock); close(#sip_socket{type = tcp, sock = Sock}) -> gen_tcp:close(Sock); close(#sip_socket{type = udp, sock = Sock}) -> gen_udp:close(Sock). tcp_init(ListenSock, Opts) -> {ok, {IP, Port}} = inet:sockname(ListenSock), ViaHost = get_via_host(IP), Transport = case proplists:get_bool(tls, Opts) of false -> tcp; true -> tls end, esip_transport:register_route(Transport, ViaHost, Port), Opts. udp_init(Sock, Opts) -> {ok, {IP, Port}} = inet:sockname(Sock), ViaHost = get_via_host(IP), esip_transport:register_route(udp, ViaHost, Port), lists:foreach( fun(I) -> Pid = get_proc(I), Pid ! {init, Sock, self()} end, lists:seq(1, get_pool_size())), Opts. udp_recv(Sock, Addr, Port, Data, Opts) -> Pid = get_proc_by_hash({Addr, Port}), Pid ! {udp, Sock, Addr, Port, Data}, Opts. start_pool() -> try lists:foreach( fun(I) -> Spec = {get_proc(I), {?MODULE, start_link, [I]}, permanent, brutal_kill, worker, [?MODULE]}, {ok, _} = supervisor:start_child(esip_udp_sup, Spec) end, lists:seq(1, get_pool_size())) catch error:{badmatch, {error, _} = Err} -> ?ERROR_MSG("failed to start UDP pool: ~p", [Err]), Err end. sockname(#sip_socket{type = tls, sock = Sock}) -> p1_tls:sockname(Sock); sockname(#sip_socket{sock = Sock}) -> inet:sockname(Sock). %%%=================================================================== %%% gen_server callbacks %%%=================================================================== init([]) -> MaxSize = esip:get_config_value(max_msg_size), {ok, #state{max_size = MaxSize}}; init([Sock, Opts]) -> case inet:peername(Sock) of {ok, PeerAddr} -> case inet:sockname(Sock) of {ok, MyAddr} -> Transport = get_transport(Opts), CertFile = get_certfile(Opts), case maybe_starttls(Sock, Transport, CertFile, {PeerAddr, MyAddr}, server) of {ok, NewSock} -> inet:setopts(Sock, [{active, once}]), MaxSize = esip:get_config_value(max_msg_size), {ok, #state{max_size = MaxSize, sock = NewSock, peer = PeerAddr, addr = MyAddr, certfile = CertFile, type = Transport}}; {error, Err} -> {stop, Err} end; {error, _Err} -> {stop, normal} end; {error, _Err} -> {stop, normal} end. handle_call({connect, Addrs, Opts}, _From, State) -> Type = get_transport(Opts), CertFile = get_certfile(Opts), case do_connect(Addrs, ?CONNECT_TIMEOUT div (length(Addrs) + 1)) of {ok, MyAddr, Peer, Sock} -> case maybe_starttls(Sock, Type, CertFile, {MyAddr, Peer}, client) of {ok, NewSock} -> inet:setopts(Sock, [{active, once}]), NewState = State#state{type = Type, sock = NewSock, certfile = CertFile, addr = MyAddr, peer = Peer}, SIPSock = make_sip_socket(NewState), esip_transport:register_socket(Peer, Type, SIPSock, CertFile), {reply, {ok, SIPSock}, NewState}; {error, _} = Err -> {stop, normal, Err, State} end; {error, _} = Err -> {stop, normal, Err, State} end; handle_call(_Request, _From, State) -> Reply = ok, {reply, Reply, State}. handle_cast(_Msg, State) -> {noreply, State}. handle_info({udp, UDPSock, IP, Port, Data}, State) -> SIPSock = #sip_socket{type = udp, sock = UDPSock, addr = State#state.addr, pid = self(), peer = {IP, Port}}, esip:callback(data_in, [Data, SIPSock]), datagram_transport_recv(SIPSock, Data), {noreply, State}; handle_info({init, UDPSock, Owner}, State) -> {ok, MyAddr} = inet:sockname(UDPSock), SIPSock = #sip_socket{type = udp, sock = UDPSock, addr = MyAddr, pid = Owner}, esip_transport:register_udp_listener(SIPSock), {noreply, State#state{addr = MyAddr}}; handle_info({tcp, Sock, Data}, #state{type = tcp} = State) -> inet:setopts(Sock, [{active, once}]), esip:callback(data_in, [Data, make_sip_socket(State)]), process_data(State, Data); handle_info({tcp, _Sock, TLSData}, #state{type = tls} = State) -> p1_tls:setopts(State#state.sock, [{active, once}]), case p1_tls:recv_data(State#state.sock, TLSData) of {ok, Data} -> esip:callback(data_in, [Data, make_sip_socket(State)]), process_data(State, Data); _Err -> {stop, normal, State} end; handle_info({send, SIPSocket, Data}, State) -> send(SIPSocket, Data), {noreply, State}; handle_info({close, SIPSocket}, State) -> close(SIPSocket), {noreply, State}; handle_info({tcp_closed, _Sock}, State) -> {stop, normal, State}; handle_info({tcp_error, _Sock, _Reason}, State) -> {stop, normal, State}; handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, #state{peer = Peer, type = Type, certfile = CertFile} = State) -> SIPSock = make_sip_socket(State), esip_transport:unregister_socket(Peer, Type, SIPSock, CertFile). code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== do_connect([{Addr, Port}|Addrs], ConnectTimeout) -> case gen_tcp:connect(Addr, Port, connect_opts(), ConnectTimeout) of {ok, Sock} -> case inet:sockname(Sock) of {error, _} = Err -> fail_or_proceed(Err, Addrs, ConnectTimeout); {ok, MyAddr} -> {ok, MyAddr, {Addr, Port}, Sock} end; Err -> fail_or_proceed(Err, Addrs, ConnectTimeout) end. fail_or_proceed(Err, [], _ConnectTimeout) -> Err; fail_or_proceed(_Err, Addrs, ConnectTimeout) -> do_connect(Addrs, ConnectTimeout). make_sip_socket(#state{type = Type, addr = MyAddr, peer = Peer, sock = Sock}) -> #sip_socket{type = Type, addr = MyAddr, sock = Sock, peer = Peer, pid = self()}. process_data(#state{buf = Buf, max_size = MaxSize, msg = undefined} = State, Data) -> case process_crlf(<>, State) of {ok, NewBuf} -> case catch esip_codec:decode(NewBuf, stream) of {ok, Msg, Tail} -> case esip:get_hdr('content-length', Msg#sip.hdrs) of N when is_integer(N), N >= 0, N =< MaxSize -> process_data(State#state{buf = <<>>, msg = Msg, wait_size = N}, Tail); _ -> {stop, normal, State} end; more when size(NewBuf) < MaxSize -> {noreply, State#state{buf = NewBuf}}; _ -> {stop, normal, State} end; {error, _} -> {stop, normal, State} end; process_data(#state{buf = Buf, max_size = MaxSize, msg = Msg, wait_size = WaitSize} = State, Data) -> NewBuf = <>, case NewBuf of <> -> NewState = State#state{buf = Tail, msg = undefined}, stream_transport_recv(NewState, Msg#sip{body = Body}), process_data(NewState, <<>>); _ when size(NewBuf) < MaxSize -> {noreply, State#state{buf = NewBuf}}; _ -> {stop, normal, State} end. stream_transport_recv(State, Msg) -> SIPSock = make_sip_socket(State), case catch esip_transport:recv(SIPSock, Msg) of {'EXIT', Reason} -> ?ERROR_MSG("transport layer failed:~n" "** Packet: ~p~n** Reason: ~p", [Msg, Reason]); _ -> ok end. process_crlf(<<"\r\n\r\n", Data/binary>>, State) -> SIPSock = make_sip_socket(State), SendRes = case esip:callback(message_in, [ping, SIPSock]) of drop -> ok; pang -> {error, closed}; _ -> DataOut = <<"\r\n">>, esip:callback(data_out, [DataOut, SIPSock]), send(SIPSock, DataOut) end, case SendRes of ok -> process_crlf(Data, State); {error, Why} -> {error, Why} end; process_crlf(Data, _State) -> {ok, Data}. datagram_transport_recv(SIPSock, <<_:32, ?STUN_MAGIC:32, _/binary>> = Data) -> case stun_codec:decode(Data, datagram) of {ok, Msg} -> case esip:callback(message_in, [ping, SIPSock]) of drop -> ok; pang -> Resp = prepare_stun_response(Msg), ErrMsg = Resp#stun{class = error, 'ERROR-CODE' = {400, <<"Flow Failed">>}}, send_stun_response(SIPSock, ErrMsg); _ -> Resp = prepare_stun_response(Msg), send_stun_response(SIPSock, Resp#stun{'XOR-MAPPED-ADDRESS' = SIPSock#sip_socket.peer}) end; _ -> ok end; datagram_transport_recv(SIPSock, Data) -> case catch esip_codec:decode(Data) of {ok, #sip{hdrs = Hdrs, body = Body} = Msg} -> case esip:get_hdr('content-length', Hdrs) of N when is_integer(N), N >= 0 -> case Body of <<_:N/binary>> -> do_transport_recv(SIPSock, Msg); <> -> do_transport_recv(SIPSock, Msg#sip{body = Body1}); _ -> ok end; _ -> do_transport_recv(SIPSock, Msg) end; Err -> Err end. do_transport_recv(SIPSock, Msg) -> case catch esip_transport:recv(SIPSock, Msg) of {'EXIT', Reason} -> ?ERROR_MSG("transport layer failed:~n" "** Packet: ~p~n** Reason: ~p", [Msg, Reason]); _ -> ok end. connect_opts() -> [binary, {active, false}, {packet, 0}, {send_timeout, ?TCP_SEND_TIMEOUT}, {send_timeout_close, true}]. get_pool_size() -> 100. get_proc_by_hash(Source) -> N = erlang:phash2(Source, get_pool_size()) + 1, get_proc(N). get_proc(N) -> list_to_atom("esip_udp_" ++ integer_to_list(N)). get_via_host(IP) -> case lists:sum(tuple_to_list(IP)) of 0 -> undefined; _ -> iolist_to_binary(inet_parse:ntoa(IP)) end. get_transport(Opts) -> case proplists:get_bool(tls, Opts) of false -> tcp; true -> tls end. get_certfile(Opts) -> case catch iolist_to_binary(proplists:get_value(certfile, Opts)) of Filename when is_binary(Filename), Filename /= <<"">> -> Filename; _ -> undefined end. maybe_starttls(_Sock, tls, undefined, FromTo, server) -> {{FromIP, FromPort}, {ToIP, ToPort}} = FromTo, ?ERROR_MSG("failed to start TLS connection ~s:~p -> ~s:~p: " "option 'certfile' is not set", [inet_parse:ntoa(FromIP), FromPort, inet_parse:ntoa(ToIP), ToPort]), {error, eprotonosupport}; maybe_starttls(Sock, tls, CertFile, _FromTo, Role) -> Opts1 = case Role of client -> [connect]; server -> [] end, Opts2 = case CertFile of undefined -> Opts1; _ -> [{certfile, CertFile}|Opts1] end, case p1_tls:tcp_to_tls(Sock, Opts2) of {ok, NewSock} when Role == client -> case p1_tls:recv_data(NewSock, <<"">>) of {ok, <<"">>} -> {ok, NewSock}; {error, _} = Err -> Err end; {ok, NewSock} when Role == server -> {ok, NewSock}; {error, _} = Err -> Err end; maybe_starttls(Sock, _Transport, _CertFile, _FromTo, _Role) -> {ok, Sock}. prepare_stun_response(Msg) -> Software = esip:get_config_value(software), #stun{method = Msg#stun.method, magic = Msg#stun.magic, trid = Msg#stun.trid, 'SOFTWARE' = Software}. send_stun_response(SIPSock, Msg) -> DataOut = stun_codec:encode(Msg), esip:callback(data_out, [DataOut, SIPSock]), send(SIPSock, DataOut). p1_sip-1.0.1/src/esip_codec.erl0000644000175000017500000013641412650734252016671 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% File : esip_codec.erl %%% Author : Evgeniy Khramtsov %%% Purpose : %%% Created : 20 Dec 2010 by Evgeniy Khramtsov %%% %%% %%% Copyright (C) 2002-2016 ProcessOne, SARL. All Rights Reserved. %%% %%% Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 %%% %%% Unless required by applicable law or agreed to in writing, software %%% distributed under the License is distributed on an "AS IS" BASIS, %%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %%% See the License for the specific language governing permissions and %%% limitations under the License. %%% %%%---------------------------------------------------------------------- -module(esip_codec). %% API -export([start/0, decode/1, decode/2, decode_uri_field/1, decode_uri/1, split/1, split/2, split/3, encode_uri_field/1, encode_uri/1, encode/1, to_lower/1, to_integer/3, str/2, escape/1, unescape/1, match/2, strcasecmp/2, to_hex/1]). %% Test -export([test/0, test_loop/0, test_loop/3, test_loop/4]). -include("esip.hrl"). -include("esip_lib.hrl"). %%%=================================================================== %%% API %%%=================================================================== -ifdef(USE_NIF). start() -> case catch erlang:load_nif(atom_to_list(?MODULE), 0) of ok -> ok; _Err -> SOPath = filename:join(esip:get_so_path(), atom_to_list(?MODULE)), case catch erlang:load_nif(SOPath, 0) of ok -> ok; Err -> ?ERROR_MSG("unable to load ~s NIF: ~p", [?MODULE, Err]) end end. -else. start() -> ok. -endif. decode(Data) -> decode(Data, datagram). decode(Data, stream) -> case str(Data, <<"\r\n\r\n">>) of nomatch -> more; _ -> do_decode(Data, stream) end; decode(Data, datagram) -> do_decode(Data, datagram). do_decode(Data, Type) -> case str(Data, <<"\r\n">>) of nomatch -> more; Pos -> <> = Data, case decode_start_line(Head) of {error, _Reason} = Err -> Err; StartLine -> do_decode(Tail, StartLine, Type) end end. do_decode(Tail, StartLine, Type) -> Method = case StartLine of {response, _, _, _} -> <<>>; {request, _, M, _} -> M end, case decode_hdrs(Tail, {Method, []}) of {ok, CSeqMethod, Hdrs, Body} -> Msg = case StartLine of {response, Ver, Status, Reason} -> #sip{type = response, method = CSeqMethod, version = Ver, status = Status, reason = Reason, hdrs = Hdrs}; {request, Ver, Method, URI} -> #sip{type = request, version = Ver, method = Method, uri = URI, hdrs = Hdrs} end, case Type of datagram -> {ok, Msg#sip{body = Body}}; _ -> {ok, Msg, Body} end; Err -> Err end. decode_uri(Data) -> decode_uri(Data, #uri{}). decode_uri_field(Data) -> lists:reverse(decode_uri_field(Data, [])). decode_via(ViaData) -> lists:flatmap( fun(<<>>) -> []; (Data) -> case split(Data, $/, 3) of [Proto, <>, Tail] -> case split(Tail, wsp, 1) of [Transport, Tail1] -> case decode_uri_host(Tail1, #uri{}) of #uri{host = Host, port = Port, params = Params} -> [#via{proto = Proto, version = {Maj-48, Min-48}, transport = to_upper(Transport), host = Host, port = Port, params = Params}]; error -> [] end; _ -> [] end; _ -> [] end end, split(ViaData, $,)). decode_uri_field(Data, Acc) -> case split(strip_wsp(Data), $<, 1) of [Name, Tail1] -> case split(Tail1, $>, 1) of [Head, Tail2] -> case split(Tail2, $,, 1) of [Params, Rest] -> FParams = decode_params(Params), case decode_uri(Head) of error -> error; U -> decode_uri_field( Rest, [{Name, U, FParams}|Acc]) end; [Params] -> FParams = decode_params(Params), case decode_uri(Head) of error -> error; U -> [{Name, U, FParams}|Acc] end end; [Head] -> case decode_uri(Head) of error -> error; U -> [{Name, U, []}|Acc] end end; [URI] -> case split(URI, $;, 1) of [_] -> case decode_uri(URI) of error -> error; U -> [{<<>>, U, []}|Acc] end; [Head, Params] -> case decode_uri(Head) of error -> error; U -> [{<<>>, U, decode_params(Params)}|Acc] end end; _ -> error end. decode_uri(Data, URI) -> case split(Data, $:, 1) of [Scheme, UserHost] -> case split(UserHost, $@, 1) of [UserPass, HostPort] -> case split(UserPass, $:, 1) of [User, Password] -> decode_uri_host(HostPort, URI#uri{scheme = Scheme, user = User, password = Password}); _ -> decode_uri_host(HostPort, URI#uri{scheme = Scheme, user = UserPass}) end; [HostPort] -> decode_uri_host(HostPort, URI#uri{scheme = Scheme}) end; _ -> error end. decode_uri_host(Data, URI) -> case split(Data, $;, 1) of [_] -> case split(Data, $?, 1) of [HostPort, Tail] -> Headers = decode_param_hdrs(Tail), Params = []; [HostPort] -> Headers = Params = [] end; [HostPort, Tail] -> case split(Tail, $?, 1) of [Ps, Hs] -> Headers = decode_param_hdrs(Hs), Params = decode_params(Ps); [Ps] -> Headers = [], Params = decode_params(Ps) end end, case split(HostPort, $:, 1) of [Host, Port] -> case to_integer(Port, 0, 65535) of {ok, PortInt} -> URI#uri{host = to_lower(Host), port = PortInt, params = Params, hdrs = Headers}; _ -> error end; [Host] -> URI#uri{host = to_lower(Host), params = Params, hdrs = Headers} end. encode_uri(#uri{scheme = Scheme, user = User, password = Password, host = Host, port = Port, params = Params, hdrs = Hdrs}) -> EncParams = encode_params(Params), EncHdrs = case Hdrs of [_|_] -> [$?, join_params(Hdrs, "&")]; _ -> "" end, HostPort = if Port >= 0, Port < 65536 -> [Host, $:, integer_to_list(Port)]; true -> Host end, UserPassHostPort = if User /= <<>>, Password /= <<>> -> [User, $:, Password, $@, HostPort]; User /= <<>> -> [User, $@, HostPort]; true -> HostPort end, list_to_binary([Scheme, $:, UserPassHostPort, EncParams, EncHdrs]). encode_uri_field({Name, URI, FieldParams}) -> NewName = if Name /= <<>> -> [Name, $ ]; true -> <<>> end, [NewName, $<, encode_uri(URI), $>, encode_params(FieldParams)]. encode(#sip{type = Type, version = {Maj, Min}, method = Method, hdrs = Hdrs, body = Body, uri = URI, status = Status, reason = Reason}) -> StartLine = if Type == request -> [Method, $ , encode_uri(URI), $ , "SIP/", Maj+48, $., Min+48]; Type == response -> Reason1 = if Reason == undefined; Reason == <<>> -> esip:reason(Status); true -> Reason end, ["SIP/", Maj+48, $., Min+48, $ , integer_to_list(Status), $ , Reason1] end, Size = erlang:iolist_size(Body), NewHdrs = esip:set_hdr('content-length', Size, Hdrs), [StartLine, "\r\n", encode_hdrs(NewHdrs, Method), "\r\n", Body]. encode_via(#via{proto = Proto, version = {Maj,Min}, transport = Transport, host = Host, port = Port, params = Params}) -> EncParams = encode_params(Params), HostPort = if Port >= 0, Port < 65536 -> [Host, $:, integer_to_list(Port)]; true -> Host end, [Proto, $/, Maj+48, $., Min+48, $/, Transport, $ , HostPort, EncParams]. escape(Bin) -> list_to_binary( [case S of $; -> escape_chr(S); $/ -> escape_chr(S); $? -> escape_chr(S); $: -> escape_chr(S); $@ -> escape_chr(S); $& -> escape_chr(S); $= -> escape_chr(S); $+ -> escape_chr(S); $$ -> escape_chr(S); $, -> escape_chr(S); $< -> escape_chr(S); $> -> escape_chr(S); $# -> escape_chr(S); $% -> escape_chr(S); $" -> escape_chr(S); ${ -> escape_chr(S); $} -> escape_chr(S); $| -> escape_chr(S); $\\ -> escape_chr(S); $^ -> escape_chr(S); $[ -> escape_chr(S); $] -> escape_chr(S); $` -> escape_chr(S); _ when S > 16#20, S < 16#7f -> S; _ -> escape_chr(S) end || S <- binary_to_list(Bin)]). unescape(Bin) -> list_to_binary(unescape1(binary_to_list(Bin))). unescape1([$%, A, B|T]) -> case catch erlang:list_to_integer([A,B], 16) of {'EXIT', _} -> [$%|unescape1([A,B|T])]; Int -> [Int|unescape1(T)] end; unescape1([C|T]) -> [C|unescape1(T)]; unescape1([]) -> []. to_hex(X) -> Hi = case X div 16 of N1 when N1 < 10 -> $0 + N1; N1 -> $W + N1 end, Lo = case X rem 16 of N2 when N2 < 10 -> $0 + N2; N2 -> $W + N2 end, <>. %% TODO: implement URI comparison according to the RFC match(U1, U2) -> U1 == U2. %%%=================================================================== %%% Internal functions %%%=================================================================== decode_start_line(Data) -> case split(Data, wsp, 1) of [<<"SIP/", Maj, ".", Min>>, Rest] -> case split(Rest, wsp, 1) of [Code, Reason] -> case to_integer(Code, 100, 699) of {ok, N} -> {response, {Maj-48, Min-48}, N, Reason}; _ -> {error, bad_start_line_status} end; _ -> {error, bad_start_line} end; [Method, Rest] -> case split(Rest, wsp, 1) of [Head, <<"SIP/", Maj, ".", Min>>] -> case decode_uri(Head) of error -> {error, bad_start_line_uri}; URI -> {request, {Maj-48, Min-48}, Method, URI} end; _ -> {error, bad_start_line} end; _ -> {error, bad_start_line} end. decode_hdrs(Data, {Method, Acc}) -> case erlang:decode_packet(httph_bin, Data, []) of {ok, {http_header, _, Name, _, Value}, Rest} -> LName = if is_atom(Name) -> Name; true -> to_lower(Name) end, case catch decode_hdr(LName, Value) of {'EXIT', _} -> HdrName = if is_atom(Name) -> atom_to_binary1(Name); true -> Name end, decode_hdrs(Rest, {Method, [{HdrName, Value}|Acc]}); {cseq, CSeq, M} -> decode_hdrs(Rest, {M, [{'cseq', CSeq}|Acc]}); Result -> decode_hdrs(Rest, {Method, [Result|Acc]}) end; {ok, http_eoh, Body} -> {ok, Method, prepare_hdrs(Acc), Body}; {more, _} -> {more, Data, {Method, Acc}}; _ -> {error, bad_header} end. decode_hdr('Accept', Val) -> {'accept', decode_params_list(Val)}; decode_hdr(<<"accept-contact">>, Val) -> {'accept-contact', decode_params_list(Val)}; decode_hdr('Accept-Encoding', Val) -> {'accept-encoding', decode_params_list(Val)}; decode_hdr('Accept-Language', Val) -> {'accept-language', decode_params_list(Val)}; decode_hdr(<<"accept-resource-priority">>, Val) -> {'accept-resource-priority', split(Val, $,)}; decode_hdr(<<"alert-info">>, Val) -> %%TODO {'alert-info', Val}; decode_hdr('Allow', Val) -> {'allow', split(Val, $,)}; decode_hdr(<<"allow-events">>, Val) -> {'allow-events', decode_params_list(Val)}; decode_hdr(<<"answer-mode">>, Val) -> {'answer-mode', decode_type_params(Val)}; decode_hdr(<<"authentication-info">>, Val) -> {'authentication-info', decode_params(Val, $,)}; decode_hdr('Authorization', Val) -> {'authorization', decode_auth(Val)}; decode_hdr(<<"call-id">>, Val) -> {'call-id', Val}; decode_hdr(<<"call-info">>, Val) -> %%TODO {'call-info', Val}; decode_hdr(<<"contact">>, <<"*">>) -> {'contact', <<"*">>}; decode_hdr(<<"contact">>, Val) -> {'contact', [_|_] = decode_uri_field(Val)}; decode_hdr(<<"content-disposition">>, Val) -> {'content-disposition', decode_type_params(Val)}; decode_hdr('Content-Encoding', Val) -> {'content-encoding', split(Val, $,)}; decode_hdr('Content-Language', Val) -> {'content-language', split(Val, $,)}; decode_hdr('Content-Length', Val) -> {ok, N} = to_integer(Val, 0, unlimited), {'content-length', N}; decode_hdr('Content-Type', Val) -> {'content-type', decode_type_params(Val)}; decode_hdr(<<"cseq">>, Val) -> [CSeq, Method] = split(Val, wsp, 1), {ok, N} = to_integer(CSeq, 0, unlimited), {'cseq', N, Method}; decode_hdr('Date', Val) -> {_, _} = Date = httpd_util:convert_request_date(binary_to_list(Val)), {'date', Date}; decode_hdr(<<"error-info">>, Val) -> %%TODO {'error-info', Val}; decode_hdr(<<"event">>, Val) -> {'event', decode_type_params(Val)}; decode_hdr('Expires', Val) -> {ok, N} = to_integer(Val, 0, unlimited), {'expires', N}; decode_hdr(<<"flow-timer">>, Val) -> {ok, N} = to_integer(Val, 0, unlimited), {'flow-timer', N}; decode_hdr('From', Val) -> [URI|_] = decode_uri_field(Val), {'from', URI}; decode_hdr(<<"history-info">>, Val) -> {'history-info', [_|_] = decode_uri_field(Val)}; decode_hdr(<<"identity">>, Val) -> {'identity', Val}; decode_hdr(<<"identity-info">>, Val) -> %%TODO {'identity-info', Val}; decode_hdr(<<"info-package">>, Val) -> {'info-package', decode_params_list(Val)}; decode_hdr(<<"in-reply-to">>, Val) -> {'in-reply-to', split(Val, $,)}; decode_hdr(<<"join">>, Val) -> {'join', decode_params_list(Val)}; decode_hdr(<<"max-breadth">>, Val) -> {ok, N} = to_integer(Val, 0, unlimited), {'max-breadth', N}; decode_hdr('Max-Forwards', Val) -> {ok, N} = to_integer(Val, 0, unlimited), {'max-forwards', N}; decode_hdr(<<"mime-version">>, Val) -> <> = Val, {'mime-version', {Maj-48, Min-48}}; decode_hdr(<<"min-expires">>, Val) -> {ok, N} = to_integer(Val, 0, unlimited), {'min-expires', N}; decode_hdr(<<"min-se">>, Val) -> {Delta, Params} = decode_type_params(Val), {ok, N} = to_integer(Delta, 0, unlimited), {'min-se', {N, Params}}; decode_hdr(<<"organization">>, Val) -> {'organization', Val}; %% decode_hdr(<<"p-access-network-info">>, Val) -> %% {'p-access-network-info', decode_type_params(Val)}; %% decode_hdr(<<"p-answer-state">>, Val) -> %% {'p-answer-state', decode_type_params(Val)}; %% decode_hdr(<<"p-asserted-identity">>, Val) -> %% {'p-asserted-identity', [_|_] = decode_uri_field(Val)}; %% decode_hdr(<<"p-asserted-service">>, Val) -> %% {'p-asserted-service', split(Val, $,)}; %% decode_hdr(<<"p-associated-uri">>, Val) -> %% {'p-associated-uri', [_|_] = decode_uri_field(Val)}; %% decode_hdr(<<"p-called-party-id">>, Val) -> %% [URI|_] = decode_uri_field(Val), %% {'p-called-party-id', URI}; %% decode_hdr(<<"p-charging-function-addresses">>, Val) -> %% {'p-charging-function-addresses', decode_params(Val)}; %% decode_hdr(<<"p-charging-vector">>, Val) -> %% {'p-charging-vector', decode_params(Val)}; %% decode_hdr(<<"p-dcs-billing-info">>, Val) -> %% {'p-dcs-billing-info', decode_type_params(Val)}; %% decode_hdr(<<"p-dcs-laes">>, Val) -> %% {'p-dcs-laes', decode_type_params(Val)}; %% decode_hdr(<<"p-dcs-osps">>, Val) -> %% {'p-dcs-osps', Val}; %% decode_hdr(<<"p-dcs-redirect">>, Val) -> %% [URI|_] = decode_uri_field(Val), %% {'p-dcs-redirect', URI}; %% decode_hdr(<<"p-dcs-trace-party-id">>, Val) -> %% [URI|_] = decode_uri_field(Val), %% {'p-dcs-trace-party-id', URI}; %% decode_hdr(<<"p-early-media">>, Val) -> %% {'p-early-media', split(Val, $,)}; %% decode_hdr(<<"p-media-authorization">>, Val) -> %% {'p-media-authorization', split(Val, $,)}; %% decode_hdr(<<"p-preferred-identity">>, Val) -> %% {'p-preferred-identity', [_|_] = decode_uri_field(Val)}; %% decode_hdr(<<"p-preferred-service">>, Val) -> %% {'p-preferred-service', split(Val, $,)}; %% decode_hdr(<<"p-profile-key">>, Val) -> %% [URI|_] = decode_uri_field(Val), %% {'p-profile-key', URI}; %% decode_hdr(<<"p-refused-uri-list">>, Val) -> %% {'p-refused-uri-list', [_|_] = decode_uri_field(Val)}; %% decode_hdr(<<"p-served-user">>, Val) -> %% [URI|_] = decode_uri_field(Val), %% {'p-served-user', URI}; %% decode_hdr(<<"p-user-database">>, Val) -> %% %% TODO %% {'p-user-database', Val}; %% decode_hdr(<<"p-visited-network-id">>, Val) -> %% {'p-visited-network-id', split(Val, $,)}; decode_hdr(<<"path">>, Val) -> {'path', [_|_] = decode_uri_field(Val)}; decode_hdr(<<"permission-missing">>, Val) -> {'permission-missing', [_|_] = decode_uri_field(Val)}; decode_hdr(<<"priority">>, Val) -> {'priority', Val}; decode_hdr(<<"privacy">>, Val) -> {'privacy', split(Val, $;)}; decode_hdr(<<"priv-answer-mode">>, Val) -> {'priv-answer-mode', split(Val, $,)}; decode_hdr('Proxy-Authenticate', Val) -> {'proxy-authenticate', decode_auth(Val)}; decode_hdr('Proxy-Authorization', Val) -> {'proxy-authorization', decode_auth(Val)}; decode_hdr(<<"proxy-require">>, Val) -> {'proxy-require', split(Val, $,)}; decode_hdr(<<"rack">>, Val) -> [Num, CSeq, Method] = split(Val), {ok, NumInt} = to_integer(Num, 0, unlimited), {ok, CSeqInt} = to_integer(CSeq, 0, unlimited), {'rack', {NumInt, CSeqInt, Method}}; decode_hdr(<<"reason">>, Val) -> {'reason', decode_params_list(Val)}; decode_hdr(<<"record-route">>, Val) -> {'record-route', [_|_] = decode_uri_field(Val)}; decode_hdr(<<"recv-info">>, Val) -> {'recv-info', decode_params_list(Val)}; decode_hdr(<<"refer-sub">>, Val) -> {Type, Params} = decode_type_params(Val), case Type of <<"false">> -> {'refer-sub', {false, Params}}; <<"true">> -> {'refer-sub', {true, Params}} end; decode_hdr(<<"refer-to">>, Val) -> [URI] = decode_uri_field(Val), {'refer-to', URI}; decode_hdr(<<"referred-by">>, Val) -> [URI] = decode_uri_field(Val), {'referred-by', URI}; decode_hdr(<<"reject-contact">>, Val) -> {'reject-contact', decode_params_list(Val)}; decode_hdr(<<"replaces">>, Val) -> {'replaces', decode_type_params(Val)}; decode_hdr(<<"reply-to">>, Val) -> [URI] = decode_uri_field(Val), {'reply-to', URI}; decode_hdr(<<"request-disposition">>, Val) -> {'request-disposition', split(Val, $,)}; decode_hdr(<<"require">>, Val) -> {'require', split(Val, $,)}; decode_hdr(<<"resource-priority">>, Val) -> {'resource-priority', split(Val, $,)}; decode_hdr('Retry-After', Val) -> {Delta, Params} = decode_type_params(Val), {ok, N} = to_integer(Delta, 0, unlimited), {'retry-after', {N, Params}}; decode_hdr(<<"route">>, Val) -> {'route', [_|_] = decode_uri_field(Val)}; decode_hdr(<<"rseq">>, Val) -> {ok, N} = to_integer(Val, 0, unlimited), {'rseq', N}; decode_hdr(<<"security-client">>, Val) -> {'security-client', decode_params_list(Val)}; decode_hdr(<<"security-server">>, Val) -> {'security-server', decode_params_list(Val)}; decode_hdr(<<"security-verify">>, Val) -> {'security-verify', decode_params_list(Val)}; decode_hdr('Server', Val) -> {'server', Val}; decode_hdr(<<"service-route">>, Val) -> {'service-route', [_|_] = decode_uri_field(Val)}; decode_hdr(<<"session-expires">>, Val) -> {Delta, Params} = decode_type_params(Val), {ok, N} = to_integer(Delta, 0, unlimited), {'session-expires', {N, Params}}; decode_hdr(<<"sip-etag">>, Val) -> {'sip-etag', Val}; decode_hdr(<<"sip-if-match">>, Val) -> {'sip-if-match', Val}; decode_hdr(<<"subject">>, Val) -> {'subject', Val}; decode_hdr(<<"subscription-state">>, Val) -> {'subscription-state', decode_type_params(Val)}; decode_hdr(<<"supported">>, Val) -> {'supported', split(Val, $,)}; decode_hdr(<<"suppress-if-match">>, Val) -> {'suppress-if-match', Val}; decode_hdr(<<"target-dialog">>, Val) -> {'target-dialog', decode_type_params(Val)}; decode_hdr(<<"timestamp">>, Val) -> {N, M} = case split(Val, wsp) of [N1, N2] -> {N1, N2}; [N1] -> {N1, <<"0">>} end, {ok, Num1} = to_float(N, 0, unlimited), {ok, Num2} = to_float(M, 0, unlimited), {'timestamp', {Num1, Num2}}; decode_hdr(<<"to">>, Val) -> [URI] = decode_uri_field(Val), {'to', URI}; decode_hdr(<<"trigger-consent">>, Val) -> %%TODO {'trigger-consent', Val}; decode_hdr(<<"unsupported">>, Val) -> {'unsupported', split(Val, $,)}; decode_hdr('User-Agent', Val) -> {'user-agent', Val}; decode_hdr('Via', Val) -> {'via', decode_via(Val)}; decode_hdr('Warning', Val) -> R = lists:map( fun(S) -> [Code, Agent, Txt] = split(S, wsp, 2), {ok, N} = to_integer(Code, 100, 699), {N, Agent, Txt} end, split(Val, $,)), {'warning', R}; decode_hdr('Www-Authenticate', Val) -> {'www-authenticate', decode_auth(Val)}; decode_hdr(<<"a">>, Val) -> decode_hdr(<<"accept-contact">>, Val); decode_hdr(<<"u">>, Val) -> decode_hdr(<<"allow-events">>, Val); decode_hdr(<<"i">>, Val) -> decode_hdr(<<"call-id">>, Val); decode_hdr(<<"m">>, Val) -> decode_hdr(<<"contact">>, Val); decode_hdr(<<"e">>, Val) -> decode_hdr('Content-Encoding', Val); decode_hdr(<<"l">>, Val) -> decode_hdr('Content-Length', Val); decode_hdr(<<"c">>, Val) -> decode_hdr('Content-Type', Val); decode_hdr(<<"o">>, Val) -> decode_hdr(<<"event">>, Val); decode_hdr(<<"f">>, Val) -> decode_hdr('From', Val); decode_hdr(<<"y">>, Val) -> decode_hdr(<<"identity">>, Val); decode_hdr(<<"n">>, Val) -> decode_hdr(<<"identity-info">>, Val); decode_hdr(<<"r">>, Val) -> decode_hdr(<<"refer-to">>, Val); decode_hdr(<<"b">>, Val) -> decode_hdr(<<"referred-by">>, Val); decode_hdr(<<"j">>, Val) -> decode_hdr(<<"reject-contact">>, Val); decode_hdr(<<"d">>, Val) -> decode_hdr(<<"request-disposition">>, Val); decode_hdr(<<"x">>, Val) -> decode_hdr(<<"session-expires">>, Val); decode_hdr(<<"s">>, Val) -> decode_hdr(<<"subject">>, Val); decode_hdr(<<"k">>, Val) -> decode_hdr(<<"supported">>, Val); decode_hdr(<<"t">>, Val) -> decode_hdr(<<"to">>, Val); decode_hdr(<<"v">>, Val) -> decode_hdr('Via', Val). encode_hdrs(Hdrs, Method) -> lists:map( fun({K, V}) -> [encode_hdr(K, V, Method), $\r, $\n] end, Hdrs). encode_hdr('accept', Val, _) -> [<<"Accept: ">>, encode_params_list(Val)]; encode_hdr('accept-contact', Val, _) -> [<<"Accept-Contact: ">>, encode_params_list(Val)]; encode_hdr('accept-encoding', Val, _) -> [<<"Accept-Encoding: ">>, encode_params_list(Val)]; encode_hdr('accept-language', Val, _) -> [<<"Accept-Language: ">>, encode_params_list(Val)]; encode_hdr('accept-resource-priority', Val, _) -> [<<"Accept-Resource-Priority: ">>, join(Val, ", ")]; encode_hdr('alert-info', Val, _) -> %%TODO [<<"Alert-Info: ">>, Val]; encode_hdr('allow', Val, _) -> [<<"Allow: ">>, join(Val, ", ")]; encode_hdr('allow-events', Val, _) -> [<<"Allow-Events: ">>, encode_params_list(Val)]; encode_hdr('answer-mode', Val, _) -> [<<"Answer-Mode: ">>, encode_type_params(Val)]; encode_hdr('authentication-info', Val, _) -> [<<"Authentication-Info: ">>, join_params(Val, ", ")]; encode_hdr('authorization', {Head, Tail}, _) -> [<<"Authorization: ">>, Head, $ , join_params(Tail, ", ")]; encode_hdr('call-id', Val, _) -> [<<"Call-ID: ">>, Val]; encode_hdr('call-info', Val, _) -> %%TODO [<<"Call-Info: ">>, Val]; encode_hdr('contact', <<"*">>, _) -> [<<"Contact: *">>]; encode_hdr('contact', Val, _) -> [<<"Contact: ">>, join([encode_uri_field(U) || U <- Val], ", ")]; encode_hdr('content-disposition', Val, _) -> [<<"Content-Disposition: ">>, encode_type_params(Val)]; encode_hdr('content-encoding', Val, _) -> [<<"Content-Encoding: ">>, join(Val, ", ")]; encode_hdr('content-language', Val, _) -> [<<"Content-Language: ">>, join(Val, ", ")]; encode_hdr('content-length', Val, _) -> [<<"Content-Length: ">>, integer_to_list(Val)]; encode_hdr('content-type', Val, _) -> [<<"Content-Type: ">>, encode_type_params(Val)]; encode_hdr('cseq', Val, Method) -> [<<"CSeq: ">>, integer_to_list(Val), $ , Method]; encode_hdr('date', {{YYYY,MM,DD},{Hour,Min,Sec}}, _) -> DayNumber = calendar:day_of_the_week({YYYY,MM,DD}), Val = io_lib:format("~s, ~2.2.0w ~3.s ~4.4.0w ~2.2.0w:~2.2.0w:~2.2.0w GMT", [day(DayNumber),DD,month(MM),YYYY,Hour,Min,Sec]), [<<"Date: ">>, Val]; encode_hdr('error-info', Val, _) -> %%TODO [<<"Error-Info: ">>, Val]; encode_hdr('event', Val, _) -> [<<"Event: ">>, encode_type_params(Val)]; encode_hdr('expires', Val, _) -> [<<"Expires: ">>, integer_to_list(Val)]; encode_hdr('flow-timer', Val, _) -> [<<"Flow-Timer: ">>, integer_to_list(Val)]; encode_hdr('from', Val, _) -> [<<"From: ">>, encode_uri_field(Val)]; encode_hdr('history-info', Val, _) -> [<<"History-Info: ">>, join([encode_uri_field(U) || U <- Val], ", ")]; encode_hdr('identity', Val, _) -> [<<"Identity: ">>, Val]; encode_hdr('identity-info', Val, _) -> %%TODO [<<"Identity-Info: ">>, Val]; encode_hdr('info-package', Val, _) -> [<<"Info-Package: ">>, encode_params_list(Val)]; encode_hdr('in-reply-to', Val, _) -> [<<"In-Reply-To: ">>, join(Val, ", ")]; encode_hdr('join', Val, _) -> [<<"Join: ">>, encode_params_list(Val)]; encode_hdr('max-breadth', Val, _) -> [<<"Max-Breadth: ">>, integer_to_list(Val)]; encode_hdr('max-forwards', Val, _) -> [<<"Max-Forwards: ">>, integer_to_list(Val)]; encode_hdr('mime-version', {Maj, Min}, _) -> [<<"MIME-Version: ">>, Maj+48, $., Min+48]; encode_hdr('min-expires', Val, _) -> [<<"Min-Expires: ">>, integer_to_list(Val)]; encode_hdr('min-se', {Delta, Params}, _) -> [<<"Min-SE: ">>, encode_type_params({integer_to_list(Delta), Params})]; encode_hdr('organization', Val, _) -> [<<"Organization: ">>, Val]; encode_hdr('path', Val, _) -> [<<"Path: ">>, join([encode_uri_field(U) || U <- Val], ", ")]; encode_hdr('permission-missing', Val, _) -> [<<"Permission-Missing: ">>, join([encode_uri_field(U) || U <- Val], ", ")]; encode_hdr('priority', Val, _) -> [<<"Priority: ">>, Val]; encode_hdr('privacy', Val, _) -> [<<"Privacy: ">>, join(Val, "; ")]; encode_hdr('priv-answer-mode', Val, _) -> [<<"Priv-Answer-Mode: ">>, join(Val, ", ")]; encode_hdr('proxy-authenticate', {Head, Tail}, _) -> [<<"Proxy-Authenticate: ">>, Head, $ , join_params(Tail, ", ")]; encode_hdr('proxy-authorization', {Head, Tail}, _) -> [<<"Proxy-Authorization: ">>, Head, $ , join_params(Tail, ", ")]; encode_hdr('proxy-require', Val, _) -> [<<"Proxy-Require: ">>, join(Val, ", ")]; encode_hdr('rack', {Num, CSeq, Method}, _) -> [<<"RAck: ">>, integer_to_list(Num), $ , integer_to_list(CSeq), $ , Method]; encode_hdr('reason', Val, _) -> [<<"Reason: ">>, encode_params_list(Val)]; encode_hdr('record-route', Val, _) -> [<<"Record-Route: ">>, join([encode_uri_field(U) || U <- Val], ", ")]; encode_hdr('recv-info', Val, _) -> [<<"Recv-Info: ">>, encode_params_list(Val)]; encode_hdr('refer-sub', {Head, Tail}, _) -> [<<"Refer-Sub: ">>, encode_type_params({atom_to_list(Head), Tail})]; encode_hdr('refer-to', Val, _) -> [<<"Refer-To: ">>, encode_uri_field(Val)]; encode_hdr('referred-by', Val, _) -> [<<"Referred-By: ">>, encode_uri_field(Val)]; encode_hdr('reject-contact', Val, _) -> [<<"Reject-Contact: ">>, encode_params_list(Val)]; encode_hdr('replaces', Val, _) -> [<<"Replaces: ">>, encode_type_params(Val)]; encode_hdr('reply-to', Val, _) -> [<<"Reply-To: ">>, encode_uri_field(Val)]; encode_hdr('request-disposition', Val, _) -> [<<"Request-Disposition: ">>, join(Val, ", ")]; encode_hdr('require', Val, _) -> [<<"Require: ">>, join(Val, ", ")]; encode_hdr('resource-priority', Val, _) -> [<<"Resource-Priority: ">>, join(Val, ", ")]; encode_hdr('retry-after', {Delta, Params}, _) -> [<<"Retry-After: ">>, encode_type_params({integer_to_list(Delta), Params})]; encode_hdr('route', Val, _) -> [<<"Route: ">>, join([encode_uri_field(U) || U <- Val], ", ")]; encode_hdr('rseq', Val, _) -> [<<"RSeq: ">>, integer_to_list(Val)]; encode_hdr('security-client', Val, _) -> [<<"Security-Client: ">>, encode_params_list(Val)]; encode_hdr('security-server', Val, _) -> [<<"Security-Server: ">>, encode_params_list(Val)]; encode_hdr('security-verify', Val, _) -> [<<"Security-Verify: ">>, encode_params_list(Val)]; encode_hdr('server', Val, _) -> [<<"Server: ">>, Val]; encode_hdr('service-route', Val, _) -> [<<"Service-Route: ">>, join([encode_uri_field(U) || U <- Val], ", ")]; encode_hdr('session-expires', {Delta, Params}, _) -> [<<"Session-Expires: ">>, encode_type_params({integer_to_list(Delta), Params})]; encode_hdr('sip-etag', Val, _) -> [<<"SIP-ETag: ">>, Val]; encode_hdr('sip-if-match', Val, _) -> [<<"SIP-If-Match: ">>, Val]; encode_hdr('subject', Val, _) -> [<<"Subject: ">>, Val]; encode_hdr('subscription-state', Val, _) -> [<<"Subscription-State: ">>, encode_type_params(Val)]; encode_hdr('supported', Val, _) -> [<<"Supported: ">>, join(Val, ", ")]; encode_hdr('suppress-if-match', Val, _) -> [<<"Suppress-If-Match: ">>, Val]; encode_hdr('target-dialog', Val, _) -> [<<"Target-Dialog: ">>, encode_type_params(Val)]; encode_hdr('timestamp', {N1, N2}, _) -> [<<"Timestamp: ">>, number_to_list(N1), $ , number_to_list(N2)]; encode_hdr('to', Val, _) -> [<<"To: ">>, encode_uri_field(Val)]; encode_hdr('trigger-consent', Val, _) -> %%TODO [<<"Trigger-Consent: ">>, Val]; encode_hdr('unsupported', Val, _) -> [<<"Unsupported: ">>, join(Val, ", ")]; encode_hdr('user-agent', Val, _) -> [<<"User-Agent: ">>, Val]; encode_hdr('via', Val, _) -> join([[<<"Via: ">>, encode_via(V)] || V <- Val], "\r\n"); encode_hdr('warning', Val, _) -> L = [[integer_to_list(C), $ , A, $ , T] || {C, A, T} <- Val], [<<"Warning: ">>, join(L, ", ")]; encode_hdr('www-authenticate', {Head, Tail}, _) -> [<<"WWW-Authenticate: ">>, Head, $ , join_params(Tail, ", ")]; encode_hdr(Key, Val, _) when is_binary(Key), is_binary(Val) -> [Key, ": ", Val]; encode_hdr(Key, Val, _) -> erlang:error({bad_header, Key, Val}). prepare_hdrs(Hdrs) -> lists:reverse(Hdrs). join_params(Params, Sep) -> join(lists:map( fun({Key, Val}) when Key /= <<>>, Val /= <<>> -> [Key, $=, Val]; ({Key, _}) when Key /= <<>> -> [Key]; (_) -> <<>> end, Params), Sep). encode_params(Params) -> lists:map( fun({Key, Val}) when Key /= <<>>, Val /= <<>> -> [$;, Key, $=, Val]; ({Key, _}) when Key /= <<>> -> [$;, Key]; (_) -> <<>> end, Params). decode_param_hdrs(Data) -> decode_params(Data, $&). decode_params(Data) -> decode_params(Data, $;). decode_params(Data, Sep) -> lists:flatmap( fun(<<>>) -> []; (S) -> case split(S, $=) of [Key, Val] -> [{strip_wsp(Key, right), strip_wsp(Val, left)}]; _ -> [{S, <<>>}] end end, split(Data, Sep)). decode_params_list(Data) -> lists:flatmap( fun(<<>>) -> []; (S) -> [decode_type_params(S)] end, split(Data, $,)). decode_type_params(Data) -> case split(Data, $;, 1) of [Type, Params] -> {strip_wsp(Type, right), decode_params(Params)}; [Type] -> {strip_wsp(Type, right), []} end. encode_params_list(L) -> join([encode_type_params(TP) || TP <- L], ", "). encode_type_params({Type, Params}) -> [Type, encode_params(Params)]. decode_auth(Data) -> [Head, Tail] = split(Data, wsp, 1), {strip_wsp(Head, right), decode_params(strip_wsp(Tail, left), $,)}. strip_wsp(Data) -> strip_wsp(Data, both). strip_wsp(Data, left) -> strip_wsp_left(Data); strip_wsp(Data, right) -> strip_wsp_right(Data); strip_wsp(Data, both) -> strip_wsp_left(strip_wsp_right(Data)). strip_wsp_left(<<$\r, Rest/binary>>) -> strip_wsp_left(Rest); strip_wsp_left(<<$\n, Rest/binary>>) -> strip_wsp_left(Rest); strip_wsp_left(<<$\t, Rest/binary>>) -> strip_wsp_left(Rest); strip_wsp_left(<<$ , Rest/binary>>) -> strip_wsp_left(Rest); strip_wsp_left(Str) -> Str. strip_wsp_right(Data) -> reverse(strip_wsp_left(reverse(Data))). split(Bin) -> split(Bin, wsp). split(Bin, Chr) -> split(Bin, Chr, -1). split(Bin, Chr, N) -> lists:reverse(split(Bin, <<>>, [], Chr, out, N, undefined)). split(Bin, <<>>, Acc, Chr, _, 0, _) -> add_to_acc(Bin, Acc, Chr); split(<>, Buf, Acc, Chr, in, N, PrevChr) -> if C == $", PrevChr /= $\\ -> %% Leaving quoted string split(Rest, <>, Acc, Chr, out, N, C); true -> %% Ignore any other characters split(Rest, <>, Acc, Chr, in, N, C) end; split(<>, Buf, Acc, Chr, out, N, _) -> if C == $" -> %% Entering quoted string split(Rest, <>, Acc, Chr, in, N, C); C == Chr -> split(Rest, <<>>, add_to_acc(Buf, Acc, Chr), Chr, out, N-1, C); (Chr == wsp) and ((C == $\r) or (C == $\n) or (C == $\t) or (C == $ )) -> split(Rest, <<>>, add_to_acc(Buf, Acc, Chr), Chr, out, N-1, C); true -> split(Rest, <>, Acc, Chr, out, N, C) end; split(<<>>, _, Acc, _, in, _, _) -> Acc; split(<<>>, Buf, Acc, Chr, _, _, _) -> add_to_acc(Buf, Acc, Chr). add_to_acc(Buf, Acc, Chr) -> case strip_wsp(Buf) of <<>> when Chr == wsp -> Acc; NewBuf -> [NewBuf|Acc] end. reverse(Bin) -> list_to_binary(lists:reverse(binary_to_list(Bin))). to_lower(Bin) -> list_to_binary(string:to_lower(binary_to_list(Bin))). to_upper(Bin) -> list_to_binary(string:to_upper(binary_to_list(Bin))). strcasecmp(Bin1, Bin2) -> to_lower(Bin1) == to_lower(Bin2). to_integer(Bin, Min, Max) -> case catch list_to_integer(binary_to_list(Bin)) of N when N >= Min, N =< Max -> {ok, N}; _ -> error end. to_float(Bin, Min, Max) -> S = binary_to_list(Bin), case catch list_to_integer(S) of N when N >= Min, N =< Max -> {ok, N}; {'EXIT', _} -> case catch erlang:list_to_float(S) of N when N >= Min, N =< Max -> {ok, N}; _ -> error end; _ -> error end. atom_to_binary1(Atom) -> list_to_binary(string:to_lower(atom_to_list(Atom))). number_to_list(N) -> if is_float(N) -> io_lib:format("~.g", [N]); is_integer(N) -> integer_to_list(N) end. str(Bin, Sep) -> case string:str(binary_to_list(Bin), binary_to_list(Sep)) of 0 -> nomatch; N -> N-1 end. join([], _Sep) -> []; join([H|T], Sep) -> [H, [[Sep, X] || X <- T]]. escape_chr(Chr) -> [$%, to_hex(Chr)]. %% day day(1) -> "Mon"; day(2) -> "Tue"; day(3) -> "Wed"; day(4) -> "Thu"; day(5) -> "Fri"; day(6) -> "Sat"; day(7) -> "Sun". %% month month(1) -> "Jan"; month(2) -> "Feb"; month(3) -> "Mar"; month(4) -> "Apr"; month(5) -> "May"; month(6) -> "Jun"; month(7) -> "Jul"; month(8) -> "Aug"; month(9) -> "Sep"; month(10) -> "Oct"; month(11) -> "Nov"; month(12) -> "Dec". -define(MSG1, <<"OPTIONS sip:xram@zinid.ru:5090 SIP/2.0\r\n" "Via: SIP/2.0/UDP 192.168.1.1:9;branch=z9hG4bK.697350a0\r\n" "From: sip:sipsak@192.168.1.1:9;tag=721d6a76\r\n" "To: sip:xram@zinid.ru:5090\r\n" "Call-ID: 1914530422@192.168.1.1\r\n" "CSeq: 413528 OPTIONS\r\n" "Contact: sip:sipsak@192.168.1.1:9\r\n" "Content-Length: 0\r\n" "User-Agent: sipsak 0.9.6\r\n" "Max-Forwards: 70\r\n\r\n">>). -define(MSG, <<"INVITE sips:B@example.com SIP/2.0\r\n" "Accept: application/dialog-info+xml\r\n" "Accept-Contact: *;methods=\"BYE\";class=\"business\";q=1.0\r\n" "Accept-Encoding: gzip\r\n" "Accept-Language: da, en-gb;q=0.8, en;q=0.7\r\n" "Accept-Resource-Priority: dsn.flash-override, dsn.flash\r\n" "Alert-Info: \r\n" "Allow: INVITE, ACK, OPTIONS, CANCEL, BYE\r\n" "Allow-Events: spirits-INDPs\r\n" "Answer-Mode: Manual\r\n" "Authentication-Info: nextnonce=\"47364c23432d2e131a5fb210812c\"\r\n" "Authorization: Digest username=\"bob\", realm=\"atlanta.example.com\"," " nonce=\"ea9c8e88df84f1cec4341ae6cbe5a359\", opaque=\"\"," " uri=\"sips:ss2.biloxi.example.com\"," " response=\"dfe56131d1958046689d83306477ecc\"\r\n" "Call-ID: a84b4c76e66710\r\n" "Call-Info: ;purpose=icon," " ;purpose=info\r\n" "Contact: \r\n" "Content-Disposition: session;handling=optional\r\n" "Content-Encoding: gzip\r\n" "Content-Language: fr\r\n" "Content-Length: 8\r\n" "Content-Type: multipart/signed; gzip=true\r\n" "CSeq: 314159 INVITE\r\n" "Date: Thu, 21 Feb 2002 13:02:03 GMT\r\n" "Error-Info: \r\n" "Event: refer\r\n" "Expires: 7200\r\n" "Flow-Timer: 126\r\n" "From: Anonymous ;tag=1928301774\r\n" "History-Info:;index=1;foo=bar\r\n" "Identity: \r\n" " \"sv5CTo05KqpSmtHt3dcEiO/1CWTSZtnG3iV+1nmurLXV/HmtyNS7Ltrg9dlxkWzo\r\n" " eU7d7OV8HweTTDobV3itTmgPwCFjaEmMyEI3d7SyN21yNDo2ER/Ovgtw0Lu5csIp\r\n" " pPqOg1uXndzHbG7mR6Rl9BnUhHufVRbp51Mn3w0gfUs=\"\r\n" "Identity-Info: ;alg=rsa-sha1\r\n" "Info-Package: package\r\n" "In-Reply-To: 70710@saturn.bell-tel.com, 17320@saturn.bell-tel.com\r\n" "Join: 12345600@atlanta.example.com;from-tag=1234567;to-tag=23431\r\n" "Max-Breadth: 69\r\n" "Max-Forwards: 70\r\n" "MIME-Version: 1.0\r\n" "Min-Expires: 60\r\n" "Min-SE: 3600;lr=true\r\n" "Organization: Boxes by Bob\r\n" %% "P-Access-Network-Info: blah\r\n" %% "P-Answer-State: blah\r\n" "P-Asserted-Identity: \"Cullen Jennings\" \r\n" %% "P-Asserted-Service: blah\r\n" %% "P-Associated-URI: blah\r\n" "P-Called-Party-ID: sip:user1-business@example.com\r\n" "P-Charging-Function-Addresses: ccf=192.1.1.1; ccf=192.1.1.2\r\n" "P-Charging-Vector: icid-value=1234bc9876e;\r\n" " icid-generated-at=192.0.6.8; orig-ioi=home1.net\r\n" %% "P-DCS-Trace-Party-ID: blah\r\n" %% "P-DCS-OSPS: blah\r\n" %% "P-DCS-Billing-Info: blah\r\n" %% "P-DCS-LAES: blah\r\n" %% "P-DCS-Redirect: blah\r\n" %% "P-Early-Media: blah\r\n" %% "P-Media-Authorization: blah\r\n" "P-Preferred-Identity: \"Cullen Jennings\" \r\n" %% "P-Preferred-Service: blah\r\n" "P-Profile-Key: \r\n" %% "P-Refused-URI-List: blah\r\n" %% "P-Served-User: blah\r\n" "P-User-Database: \r\n" "P-Visited-Network-ID: other.net, \"Visited network number 1\"\r\n" "Path: ,\r\n" "Permission-Missing: sip:C@example.com\r\n" "Priority: emergency\r\n" "Privacy: id\r\n" "Priv-Answer-Mode: Auto\r\n" "Proxy-Authenticate: Digest realm=\"atlanta.example.com\", qop=\"auth\",\r\n" " nonce=\"f84f1cec41e6cbe5aea9c8e88d359\",\r\n" " opaque=\"\", stale=FALSE, algorithm=MD5\r\n" "Proxy-Authorization: Digest username=\"alice\",\r\n" " realm=\"atlanta.example.com\",\r\n" " nonce=\"wf84f1ceczx41ae6cbe5aea9c8e88d359\", opaque=\"\",\r\n" " uri=\"sip:bob@biloxi.example.com\",\r\n" " response=\"42ce3cef44b22f50c6a6071bc8\"\r\n" "Proxy-Require: sec-agree\r\n" "RAck: 776656 1 INVITE\r\n" "Reason: SIP ;cause=200 ;text=\"Call completed elsewhere\"\r\n" "Record-Route: xram \r\n" "Recv-Info: \r\n" "Refer-Sub: false\r\n" "Refer-To: \r\n" "Referred-By: \r\n" " ;cid=\"20398823.2UWQFN309shb3@referrer.example\"\r\n" "Reject-Contact: *;actor=\"msg-taker\";video\r\n" "Replaces: 425928@bobster.example.org;to-tag=7743;from-tag=6472\r\n" "Reply-To: Bob \r\n" "Request-Disposition: proxy, recurse, parallel\r\n" "Require: 100rel\r\n" "Resource-Priority: wps.3, dsn.flash\r\n" "Retry-After: 18000;duration=3600\r\n" "Route: ,\r\n" " \r\n" "RSeq: 988789\r\n" "Security-Client: digest;q=0.1,ipsec-ike\r\n" "Security-Server: ipsec-ike;q=0.1\r\n" "Security-Verify: tls;q=0.2\r\n" "Server: HomeServer v2\r\n" "Service-Route: ,\r\n" " \r\n" "Session-Expires: 4000;refresher=uac\r\n" "SIP-ETag: dx200xyz\r\n" "SIP-If-Match: dx200xyz\r\n" "Subject: A tornado is heading our way!\r\n" "Subscription-State: active;expires=60\r\n" "Supported: replaces, 100rel\r\n" "Suppress-If-Match: *\r\n" "Target-Dialog: fa77as7dad8-sd98ajzz@host.example.com\r\n" " ;local-tag=kkaz-;remote-tag=6544\r\n" "Timestamp: 54 0.35\r\n" "To: Bob ;tag=8321234356\r\n" "Trigger-Consent: sip:123@relay.example.com\r\n" " ;target-uri=\"sip:friends@relay.example.com\"\r\n" "Unsupported: 100rel\r\n" "User-Agent: Softphone Beta1.5\r\n" "Via: SIP/2.0/UDP atlanta.com:5060;branch=z9hG4bKnashds8\r\n" "Warning: 301 isi.edu \"Incompatible network address type 'E.164'\"\r\n" "WWW-Authenticate: Digest realm=\"atlanta.example.com\", qop=\"auth\",\r\n" " nonce=\"84f1c1ae6cbe5ua9c8e88dfa3ecm3459\",\r\n" " opaque=\"\", stale=FALSE, algorithm=MD5\r\n" "\r\nSIP body">>). test() -> io:format("~p~n", [decode(?MSG)]). test_loop() -> N = 10000, eprof:start(), _P = spawn(?MODULE, test_loop, [self(), ?MSG, N]), %%eprof:start_profiling([_P]), receive {ok, T} -> ok end, eprof:stop_profiling(), eprof:analyze(), io:format("~n== Estimate: ~p~n", [T div N]). test_loop(P, Msg, N) -> test_loop(P, Msg, N, now()). test_loop(P, _, 0, T) -> P ! {ok, timer:now_diff(now(), T)}; test_loop(P, Msg, N, T) -> decode(Msg), test_loop(P, Msg, N-1, T). p1_sip-1.0.1/src/esip_listener.erl0000644000175000017500000001534312650734252017436 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% File : esip_listener.erl %%% Author : Evgeniy Khramtsov %%% Purpose : %%% Created : 9 Jan 2011 by Evgeniy Khramtsov %%% %%% %%% Copyright (C) 2002-2016 ProcessOne, SARL. All Rights Reserved. %%% %%% Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 %%% %%% Unless required by applicable law or agreed to in writing, software %%% distributed under the License is distributed on an "AS IS" BASIS, %%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %%% See the License for the specific language governing permissions and %%% limitations under the License. %%% %%%---------------------------------------------------------------------- -module(esip_listener). -behaviour(gen_server). %% API -export([start_link/0, add_listener/3, del_listener/2, start_listener/4]). %% gen_server callbacks -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -include("esip_lib.hrl"). -define(TCP_SEND_TIMEOUT, 10000). -record(state, {listeners = dict:new()}). %%%=================================================================== %%% API %%%=================================================================== start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). add_listener(Port, Transport, Opts) -> gen_server:call(?MODULE, {add_listener, Port, Transport, Opts}). del_listener(Port, Transport) -> gen_server:call(?MODULE, {del_listener, Port, Transport}). %%%=================================================================== %%% gen_server callbacks %%%=================================================================== init([]) -> {ok, #state{}}. handle_call({add_listener, Port, Transport, Opts}, _From, State) -> case dict:find({Port, Transport}, State#state.listeners) of {ok, _} -> Err = {error, already_started}, {reply, Err, State}; error -> {Pid, MRef} = spawn_monitor(?MODULE, start_listener, [Port, Transport, Opts, self()]), receive {'DOWN', MRef, _Type, _Object, Info} -> Res = {error, Info}, format_listener_error(Port, Transport, Opts, Res), {reply, Res, State}; {Pid, Reply} -> case Reply of {error, _} = Err -> format_listener_error(Port, Transport, Opts, Err), {reply, Reply, State}; ok -> Listeners = dict:store( {Port, Transport}, {MRef, Pid, Opts}, State#state.listeners), {reply, ok, State#state{listeners = Listeners}} end end end; handle_call({del_listener, Port, Transport}, _From, State) -> case dict:find({Port, Transport}, State#state.listeners) of {ok, {MRef, Pid, _Opts}} -> catch erlang:demonitor(MRef, [flush]), catch exit(Pid, kill), Listeners = dict:erase({Port, Transport}, State#state.listeners), {reply, ok, State#state{listeners = Listeners}}; error -> {reply, {error, notfound}, State} end; handle_call(_Request, _From, State) -> Reply = ok, {reply, Reply, State}. handle_cast(_Msg, State) -> {noreply, State}. handle_info({'DOWN', MRef, _Type, _Pid, Info}, State) -> Listeners = dict:filter( fun({Port, Transport}, {Ref, _, _}) when Ref == MRef -> ?ERROR_MSG("listener on ~p/~p failed: ~p", [Port, Transport, Info]), false; (_, _) -> true end, State#state.listeners), {noreply, State#state{listeners = Listeners}}; handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== start_listener(Port, Transport, Opts, Owner) when Transport == tcp; Transport == tls -> OptsWithTLS = case Transport of tls -> [tls|Opts]; tcp -> Opts end, case gen_tcp:listen(Port, [binary, {packet, 0}, {active, false}, {reuseaddr, true}, {nodelay, true}, {keepalive, true}, {send_timeout, ?TCP_SEND_TIMEOUT}, {send_timeout_close, true}]) of {ok, ListenSocket} -> Owner ! {self(), ok}, OptsWithTLS1 = esip_socket:tcp_init(ListenSocket, OptsWithTLS), accept(ListenSocket, OptsWithTLS1); Err -> Owner ! {self(), Err} end; start_listener(Port, udp, Opts, Owner) -> case gen_udp:open(Port, [binary, {active, false}, {reuseaddr, true}]) of {ok, Socket} -> Owner ! {self(), ok}, Opts1 = esip_socket:udp_init(Socket, Opts), udp_recv(Socket, Opts1); Err -> Owner ! {self(), Err} end. accept(ListenSocket, Opts) -> case gen_tcp:accept(ListenSocket) of {ok, Socket} -> case {inet:peername(Socket), inet:sockname(Socket)} of {{ok, {PeerAddr, PeerPort}}, {ok, {Addr, Port}}} -> ?INFO_MSG("accepted connection: ~s:~p -> ~s:~p", [inet_parse:ntoa(PeerAddr), PeerPort, inet_parse:ntoa(Addr), Port]), case esip_socket:start({gen_tcp, Socket}, Opts) of {ok, Pid} -> gen_tcp:controlling_process(Socket, Pid); Err -> Err end; Err -> ?ERROR_MSG("unable to fetch peername: ~p", [Err]), Err end, accept(ListenSocket, Opts); Err -> Err end. udp_recv(Socket, Opts) -> case gen_udp:recv(Socket, 0) of {ok, {Addr, Port, Packet}} -> case catch esip_socket:udp_recv(Socket, Addr, Port, Packet, Opts) of {'EXIT', Reason} -> ?ERROR_MSG("failed to process UDP packet:~n" "** Source: {~p, ~p}~n" "** Reason: ~p~n** Packet: ~p", [Addr, Port, Reason, Packet]), udp_recv(Socket, Opts); NewOpts -> udp_recv(Socket, NewOpts) end; {error, Reason} -> ?ERROR_MSG("unexpected UDP error: ~s", [inet:format_error(Reason)]), erlang:error(Reason) end. format_listener_error(Port, Transport, Opts, Err) -> ?ERROR_MSG("failed to start listener:~n" "** Port: ~p~n" "** Transport: ~p~n" "** Options: ~p~n" "** Reason: ~p", [Port, Transport, Opts, Err]). p1_sip-1.0.1/src/esip_sup.erl0000644000175000017500000000627212650734252016421 0ustar debalancedebalance%%%---------------------------------------------------------------------- %%% File : esip_sup.erl %%% Author : Evgeniy Khramtsov %%% Purpose : SIP supervisor %%% Created : 14 Jul 2009 by Evgeniy Khramtsov %%% %%% %%% Copyright (C) 2002-2016 ProcessOne, SARL. All Rights Reserved. %%% %%% Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 %%% %%% Unless required by applicable law or agreed to in writing, software %%% distributed under the License is distributed on an "AS IS" BASIS, %%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %%% See the License for the specific language governing permissions and %%% limitations under the License. %%% %%%---------------------------------------------------------------------- -module(esip_sup). -behaviour(supervisor). %% API -export([start_link/0]). %% Supervisor callbacks -export([init/1]). -define(SERVER, ?MODULE). %%==================================================================== %% API functions %%==================================================================== start_link() -> supervisor:start_link({local, ?SERVER}, ?MODULE, []). %%==================================================================== %% Supervisor callbacks %%==================================================================== init([]) -> ESIP = {esip, {esip, start_link, []}, permanent, 2000, worker, [esip]}, Listener = {esip_listener, {esip_listener, start_link, []}, permanent, 2000, worker, [esip_listener]}, Dialog = {esip_dialog, {esip_dialog, start_link, []}, permanent, 2000, worker, [esip_dialog]}, Transaction = {esip_transaction, {esip_transaction, start_link, []}, permanent, 2000, worker, [esip_transaction]}, Transport = {esip_transport, {esip_transport, start_link, []}, permanent, 2000, worker, [esip_transport]}, ServerTransactionSup = {esip_server_transaction_sup, {esip_tmp_sup, start_link, [esip_server_transaction_sup, esip_server_transaction]}, permanent, infinity, supervisor, [esip_tmp_sup]}, ClientTransactionSup = {esip_client_transaction_sup, {esip_tmp_sup, start_link, [esip_client_transaction_sup, esip_client_transaction]}, permanent, infinity, supervisor, [esip_tmp_sup]}, TCPConnectionSup = {esip_tcp_sup, {esip_tmp_sup, start_link, [esip_tcp_sup, esip_socket]}, permanent, infinity, supervisor, [esip_tmp_sup]}, UDPConnectionSup = {esip_udp_sup, {esip_udp_sup, start_link, []}, permanent, infinity, supervisor, [esip_udp_sup]}, {ok,{{one_for_one,10,1}, [ESIP, Listener, Dialog, ServerTransactionSup, ClientTransactionSup, Transaction, Transport, TCPConnectionSup, UDPConnectionSup]}}. %%==================================================================== %% Internal functions %%==================================================================== p1_sip-1.0.1/LICENSE.txt0000644000175000017500000000110312650734252015106 0ustar debalancedebalanceCopyright 2002-2016 ProcessOne SARL Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. p1_sip-1.0.1/ebin/0000755000175000017500000000000012650734252014205 5ustar debalancedebalancep1_sip-1.0.1/ebin/examples/0000755000175000017500000000000012650734252016023 5ustar debalancedebalancep1_sip-1.0.1/c_src/0000755000175000017500000000000012650734252014361 5ustar debalancedebalancep1_sip-1.0.1/c_src/esip_codec.c0000644000175000017500000002455612650734252016636 0ustar debalancedebalance/* * Copyright (C) 2002-2016 ProcessOne, SARL. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #include #include #include #include #ifdef NIF_OLD #define ENIF_ALLOC(SIZE) enif_alloc(env, SIZE) #define ENIF_FREE(PTR) enif_free(env, PTR) #define ENIF_REALLOC(PTR, SIZE) enif_realloc(env, PTR, SIZE) #define ENIF_ALLOC_BINARY(SIZE, BIN) enif_alloc_binary(env, SIZE, BIN) #define ENIF_COMPARE(TERM1, TERM2) enif_compare(env, TERM1, TERM2) #else #define ENIF_ALLOC(SIZE) enif_alloc(SIZE) #define ENIF_FREE(PTR) enif_free(PTR) #define ENIF_REALLOC(PTR, SIZE) enif_realloc(PTR, SIZE) #define ENIF_ALLOC_BINARY(SIZE, BIN) enif_alloc_binary(SIZE, BIN) #define ENIF_COMPARE(TERM1, TERM2) enif_compare(TERM1, TERM2) #endif #define BUF_LIMIT 64 #define WSP 256 #define OUT 0 #define IN 1 static ERL_NIF_TERM atom_wsp; static ERL_NIF_TERM atom_true; static ERL_NIF_TERM atom_false; struct buf { int limit; int len; unsigned char *b; }; struct list { ERL_NIF_TERM term; struct list *next; }; static int load(ErlNifEnv* env, void** priv, ERL_NIF_TERM load_info) { atom_wsp = enif_make_atom(env, "wsp"); atom_true = enif_make_atom(env, "true"); atom_false = enif_make_atom(env, "false"); return 0; } static struct buf *init_buf(ErlNifEnv* env) { struct buf *rbuf = ENIF_ALLOC(sizeof(struct buf)); rbuf->limit = BUF_LIMIT; rbuf->len = 0; rbuf->b = ENIF_ALLOC(rbuf->limit); return rbuf; } static void destroy_buf(ErlNifEnv* env, struct buf *rbuf) { if (rbuf) { if (rbuf->b) { ENIF_FREE(rbuf->b); }; ENIF_FREE(rbuf); }; } inline void resize_buf(ErlNifEnv* env, struct buf *rbuf, int len_to_add) { int new_len = rbuf->len + len_to_add; if (new_len >= rbuf->limit) { rbuf->limit = ((new_len / BUF_LIMIT) + 1) * BUF_LIMIT; rbuf->b = ENIF_REALLOC(rbuf->b, rbuf->limit); }; } static void buf_add_char(ErlNifEnv* env, struct buf *rbuf, unsigned char c) { resize_buf(env, rbuf, 1); (rbuf->b)[rbuf->len] = c; rbuf->len += 1; } static void buf_add_str(ErlNifEnv* env, struct buf *rbuf, char *data, int len) { resize_buf(env, rbuf, len); memcpy(rbuf->b + rbuf->len, data, len); rbuf->len += len; } static ERL_NIF_TERM to_lower(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { ErlNifBinary input, output; int i; if (argc == 1) { if (enif_inspect_iolist_as_binary(env, argv[0], &input)) { if (ENIF_ALLOC_BINARY(input.size, &output)) { if (input.size > 0) { for (i=0; i 0) { for (i=0; i 0) { for (i=0; i 0) { while (i 0) { i = input.size - 1; while (i>=0) { c = input.data[i]; if (!isspace(c)) break; i--; }; if (ENIF_ALLOC_BINARY(i+1, &output)) { memcpy(output.data, input.data, i+1); return enif_make_binary(env, &output); }; } else { return enif_make_binary(env, &input); }; }; }; return enif_make_badarg(env); } static ERL_NIF_TERM strip_wsp(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { ErlNifBinary input, output; int start = 0, end; unsigned char c; if (argc == 1) { if (enif_inspect_iolist_as_binary(env, argv[0], &input)) { while (start < input.size) { c = input.data[start]; if (!isspace(c)) break; start++; }; end = input.size - 1; while (end >= start) { c = input.data[end]; if (!isspace(c)) break; end--; }; if (ENIF_ALLOC_BINARY(end - start + 1, &output)) { memcpy(output.data, input.data + start, end - start + 1); return enif_make_binary(env, &output); }; }; }; return enif_make_badarg(env); } static ERL_NIF_TERM str(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { ErlNifBinary input, sep; unsigned i = 0, j; if (argc == 2) { if (enif_inspect_iolist_as_binary(env, argv[0], &input) && enif_inspect_iolist_as_binary(env, argv[1], &sep)) { if (sep.size > 0) { while (i= sep.size) { j = 0; while (jlen) { c = buf->b[start]; if (!isspace(c)) break; start++; }; end = buf->len - 1; while (end >= start) { c = buf->b[end]; if (!isspace(c)) break; end--; }; if (end < start && chr == WSP) { destroy_buf(env, buf); return acc; } else { struct list *new_acc = ENIF_ALLOC(sizeof(struct list)); ENIF_ALLOC_BINARY(end - start + 1, &output); memcpy(output.data, buf->b + start, end - start + 1); destroy_buf(env, buf); new_acc->next = acc; new_acc->term = enif_make_binary(env, &output); return new_acc; }; } static ERL_NIF_TERM do_split(ErlNifEnv* env, ErlNifBinary *input, unsigned pos, unsigned chr, struct buf *buf, struct list *acc, unsigned state, unsigned prev_chr, signed iter) { struct list *new_acc; unsigned c; ERL_NIF_TERM result; if (pos < input->size && iter != 0) { c = input->data[pos]; if (state == IN) { /* We are in quoted string here */ buf_add_char(env, buf, c); if (c == '"' && prev_chr != '\\') { /* Leaving quoted string */ return do_split(env, input, pos+1, chr, buf, acc, OUT, c, iter); } else { /* Ignore any other characters */ return do_split(env, input, pos+1, chr, buf, acc, IN, c, iter); }; } else { if (c == '"') { /* Entering quoted string */ buf_add_char(env, buf, c); return do_split(env, input, pos+1, chr, buf, acc, IN, c, iter); }; if (c == chr || (chr == WSP && (isspace(c)))) { acc = add_to_acc(env, buf, acc, chr); return do_split(env, input, pos+1, chr, init_buf(env), acc, OUT, c, iter-1); }; buf_add_char(env, buf, c); return do_split(env, input, pos+1, chr, buf, acc, OUT, c, iter); }; } else { if (state == IN) { destroy_buf(env, buf); } else { if (iter == 0) { buf_add_str(env, buf, (char *)input->data + pos, input->size - pos); }; acc = add_to_acc(env, buf, acc, chr); }; result = enif_make_list(env, 0, NULL); while (acc) { result = enif_make_list_cell(env, acc->term, result); new_acc = acc->next; ENIF_FREE(acc); acc = new_acc; }; return result; }; } static ERL_NIF_TERM split(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { ErlNifBinary input; unsigned chr; signed iter; if (argc == 3) { if (enif_inspect_iolist_as_binary(env, argv[0], &input) && enif_get_int(env, argv[2], &iter)) { if (enif_get_uint(env, argv[1], &chr)) { if (chr >= 0 && chr <= 255) { return do_split(env, &input, 0, chr, init_buf(env), NULL, OUT, 0, iter); }; } else { if (!ENIF_COMPARE(argv[1], atom_wsp)) { chr = WSP; return do_split(env, &input, 0, chr, init_buf(env), NULL, OUT, 0, iter); }; }; }; }; return enif_make_badarg(env); } static ErlNifFunc nif_funcs[] = { {"to_lower", 1, to_lower}, {"to_upper", 1, to_upper}, {"reverse", 1, reverse}, {"strip_wsp", 1, strip_wsp}, {"strip_wsp_left", 1, strip_wsp_left}, {"strip_wsp_right", 1, strip_wsp_right}, {"str", 2, str}, {"strcasecmp", 2, strcasecmp_erl}, {"split", 3, split} }; ERL_NIF_INIT(esip_codec, nif_funcs, load, NULL, NULL, NULL)