ASR_BASE

Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/external/management/net/siproxd/Makefile b/external/management/net/siproxd/Makefile
new file mode 100644
index 0000000..8f36a23
--- /dev/null
+++ b/external/management/net/siproxd/Makefile
@@ -0,0 +1,122 @@
+#
+# Copyright (C) 2014-2018 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=siproxd
+PKG_VERSION:=0.8.3
+PKG_RELEASE:=4
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=@SF/siproxd
+PKG_HASH:=9a6d7a6bb6fff162775b1e1fb7018de9c69642cbf8626185dc6ffceeeba07736
+
+PKG_FIXUP:=autoreconf
+PKG_INSTALL:=1
+PKG_BUILD_PARALLEL:=1
+
+PKG_CONFIG_DEPENDS:=CONFIG_SIPROXD_MAX_CLIENTS
+
+PKG_LICENSE:=GPL-2.0+
+PKG_LICENSE_FILES:=COPYING
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/siproxd/Default
+  SECTION:=net
+  CATEGORY:=Network
+  SUBMENU:=Telephony
+  URL:=http://siproxd.sourceforge.net/
+endef
+
+define Package/siproxd
+  $(call Package/siproxd/Default)
+  DEPENDS:=+libltdl +libpthread +libosip2
+  TITLE:=SIP (Session Initiation Protocol) proxy
+  MENU:=1
+endef
+
+define Package/siproxd/description
+ Siproxd is a proxy/masquerading daemon for the SIP protocol. Refer to https://openwrt.org/docs/guide-user/services/voip/siproxd for configuration details and examples.
+endef
+
+define Package/siproxd/conffiles
+/etc/config/siproxd
+endef
+
+define Package/siproxd/config
+	config SIPROXD_MAX_CLIENTS
+		int "Max supported clients"
+		default 32
+		depends on PACKAGE_siproxd
+		help
+		  Default 32 is sufficient for home environments. Larger values
+		  consume more memory (e.g. RSS of 17 MB with upstream default 512).
+endef
+
+CONFIGURE_ARGS+= \
+	--with-libosip-prefix="$(STAGING_DIR)/usr" \
+	--without-included-ltdl \
+	--disable-doc
+
+MAKE_FLAGS+= \
+	SUBDIRS="src scripts contrib"
+
+TARGET_CFLAGS+= \
+	-Wno-unused-const-variable
+
+URLMAP:=$(CONFIG_SIPROXD_MAX_CLIENTS)
+RTPPROXY:=$(shell expr $(URLMAP) \* 2)
+
+define Build/Configure
+	$(call Build/Configure/Default)
+	$(ESED) 's;^(#define[[:space:]]+URLMAP_SIZE).*$$$$;\1 $(URLMAP);' \
+		-e 's;^(#define[[:space:]]+RTPPROXY_SIZE).*$$$$;\1 $(RTPPROXY);' \
+		$(PKG_BUILD_DIR)/src/siproxd.h
+endef
+
+define Package/siproxd/install
+	$(INSTALL_DIR) $(1)/usr/sbin
+	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/siproxd $(1)/usr/sbin
+	$(INSTALL_DIR) $(1)/etc/config
+	$(INSTALL_CONF) ./files/siproxd.config $(1)/etc/config/siproxd
+	$(INSTALL_DIR) $(1)/etc/init.d
+	$(INSTALL_BIN) ./files/siproxd.init $(1)/etc/init.d/siproxd
+endef
+
+define BuildPlugin
+  define Package/siproxd-mod-$(subst _,-,$(1))
+    $$(call Package/siproxd/Default)
+    TITLE:= siproxd $(1) plugin
+    DEPENDS:=siproxd $(2)
+  endef
+
+  define Package/siproxd-mod-$(subst _,-,$(1))/install
+	$(INSTALL_DIR) $$(1)/usr/lib/siproxd
+	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/lib/siproxd/plugin_$(1).so \
+		$$(1)/usr/lib/siproxd
+  endef
+
+  $$(eval $$(call BuildPackage,siproxd-mod-$(subst _,-,$(1))))
+endef
+
+$(eval $(call BuildPackage,siproxd))
+$(eval $(call BuildPlugin,blacklist,+libsqlite3))
+$(eval $(call BuildPlugin,codecfilter))
+$(eval $(call BuildPlugin,defaulttarget))
+$(eval $(call BuildPlugin,demo))
+$(eval $(call BuildPlugin,fix_bogus_via))
+$(eval $(call BuildPlugin,fix_DTAG))
+$(eval $(call BuildPlugin,fix_fbox_anoncall))
+$(eval $(call BuildPlugin,logcall))
+$(eval $(call BuildPlugin,prefix))
+$(eval $(call BuildPlugin,regex))
+$(eval $(call BuildPlugin,shortdial))
+$(eval $(call BuildPlugin,stats))
+$(eval $(call BuildPlugin,stripheader))
+$(eval $(call BuildPlugin,stun))
+$(eval $(call BuildPlugin,siptrunk))
diff --git a/external/management/net/siproxd/files/siproxd.config b/external/management/net/siproxd/files/siproxd.config
new file mode 100644
index 0000000..49b16ad
--- /dev/null
+++ b/external/management/net/siproxd/files/siproxd.config
@@ -0,0 +1,25 @@
+config siproxd general
+	# Custom options allow using OpenWRT network names, and defaults should
+	# work out-of-the-box. If your SIP devices do not REGISTER externally,
+	# you may also need to open firewall ports: tcp/udp 5060, udp 7070-7089.
+	option interface_inbound lan
+	option interface_outbound wan
+
+# All other documented siproxd configuration directives are supported. Use
+# a UCI 'option' for single-instance directives, and UCI 'list' entries for
+# directives that allow multiple instances, per the examples below.
+
+	# Define low-level network devices, overriding interface_in/outbound:
+#	option if_inbound eth0
+#	option if_outbound ppp0
+
+	# Enable DEBUG logging for configuration messages:
+#	option debug_level 0x00000100
+#	option silence_log 0
+
+	# Load two plugins: one that logs SIP call details to syslog, and one
+	# that strips out G.729, GSM codecs:
+#	list load_plugin 'plugin_logcall.so'
+#	list load_plugin 'plugin_codecfilter.so'
+#	list plugin_codecfilter_blacklist G729
+#	list plugin_codecfilter_blacklist GSM
diff --git a/external/management/net/siproxd/files/siproxd.init b/external/management/net/siproxd/files/siproxd.init
new file mode 100644
index 0000000..dd932bd
--- /dev/null
+++ b/external/management/net/siproxd/files/siproxd.init
@@ -0,0 +1,170 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2008 Alina Friedrichsen
+# Copyright (C) 2011 OpenWrt.org
+
+START=50
+
+USE_PROCD=1
+
+PROG="/usr/sbin/siproxd"
+CONF_DIR="/var/etc/siproxd"
+REG_DIR="/var/lib/siproxd"
+PID_DIR="/var/run/siproxd"
+PLUGIN_DIR="/usr/lib/siproxd/"
+SIPROXD_UID="nobody"
+SIPROXD_GID="nogroup"
+
+# Some options need special handling or conflict with procd/jail setup.
+append CONF_SKIP "interface_inbound interface_outbound chrootjail"
+append CONF_SKIP "daemonize user plugindir registration_file pid_file"
+
+
+# Check if a UCI option is set, or else apply a provided default.
+
+default_conf() {
+	local opt="$1"
+	local default="$2"
+	local val
+
+	config_get "$opt" "$sec" "$opt"
+	eval "val=\"\${$opt}\""
+
+	[ -z "$val" ] || return 0
+	[ -n "$default" ] || return 0
+	config_set "$sec" "$opt" "$default"
+	append_conf "$opt" = "$default"
+}
+
+append_conf() {
+	echo $* >> "$CONF_DIR/siproxd-$sec.conf"
+}
+
+# Use user-friendly network names (e.g. "wan", "lan") from options
+# 'interface_inbound' and 'interface_outbound', but use standard siproxd
+# parameters 'if_inbound' and 'if_outbound' if explicitly set.
+
+setup_networks() {
+	local sec="$1"
+	local _int_inbound _int_outbound
+	local _dev_inbound _dev_outbound
+
+	config_get _int_inbound "$sec" interface_inbound
+	config_get _int_outbound "$sec" interface_outbound
+
+	. /lib/functions/network.sh
+	network_get_physdev _dev_inbound $_int_inbound
+	network_get_physdev _dev_outbound $_int_outbound
+
+	default_conf if_inbound $_dev_inbound
+	default_conf if_outbound $_dev_outbound
+}
+
+# Apply default values to key options if unset in user's UCI config.
+
+apply_defaults() {
+	local sec="$1"
+
+	default_conf sip_listen_port 5060
+	default_conf autosave_registrations 300
+	default_conf rtp_port_low 7070
+	default_conf rtp_port_high 7089
+	default_conf rtp_timeout 300
+	default_conf rtp_dscp 46
+	default_conf tcp_timeout 600
+	default_conf tcp_keepalive 20
+	default_conf default_expires 600
+	default_conf daemonize 0
+	default_conf user "$SIPROXD_UID"
+	default_conf registration_file "$REG_DIR/siproxd-$sec.reg"
+	default_conf plugindir "$PLUGIN_DIR"
+}
+
+# Handle activities at start of a new 'siproxd' section.
+# Initialize section processing and save section name.
+
+section_start() {
+	local sec="$1"
+
+	rm -f "$CONF_DIR/siproxd-$sec.conf"
+	append_conf "# config auto-generated from /etc/config/siproxd"
+}
+
+# Handle activities at close of a 'siproxd' section.
+# Parse OpenWRT interface names (e.g. "wan"), apply defaults and
+# set up procd jail.
+
+section_end() {
+	local sec="$1"
+
+	local conf_file="$CONF_DIR/siproxd-$sec.conf"
+	local pid_file="$PID_DIR/siproxd-$sec.pid"
+	local reg_file plugin_dir
+
+	setup_networks "$sec"
+	apply_defaults "$sec"
+
+	config_get plugin_dir "$sec" plugindir
+	config_get reg_file "$sec" registration_file
+
+	procd_open_instance "$sec"
+	procd_set_param command "$PROG" --config "$conf_file"
+	procd_set_param pidfile "$pid_file"
+	procd_set_param respawn
+	procd_add_jail siproxd log
+	procd_add_jail_mount /etc/passwd /etc/group /etc/TZ /dev/null
+	procd_add_jail_mount "$conf_file"
+	[ -d "$plugin_dir" ] && procd_add_jail_mount "$plugin_dir"
+	# Ensure registration file exists for jail
+	[ -f "$reg_file" ] || touch "$reg_file"
+	chown "$SIPROXD_UID:$SIPROXD_GID" "$reg_file"
+	procd_add_jail_mount_rw "$reg_file"
+	procd_close_instance
+}
+
+# Setup callbacks for parsing siproxd sections, options, and lists.
+# This avoids hardcoding all supported siproxd configuration parameters.
+
+siproxd_cb() {
+	config_cb() {
+		# Section change: close any previous section.
+		[ -n "$cur_sec" ] && section_end "$cur_sec"
+
+		case "$1" in
+			# New 'siproxd' section: begin processing.
+			"siproxd")
+				cur_sec="$2"
+				section_start "$cur_sec"
+			;;
+			# Config end or unknown section: ignore.
+			*)
+				cur_sec=""
+			;;
+		esac
+	}
+
+	option_cb() {
+		local sec="$cur_sec"
+
+		[ -z "$sec" ] && return
+		list_contains CONF_SKIP "$1" && return
+		[ -n "$2" ] && append_conf "$1" = "$2"
+	}
+
+	list_cb() {
+		option_cb "$@"
+	}
+}
+
+service_triggers()
+{
+	procd_add_reload_trigger "siproxd"
+}
+
+start_service() {
+	mkdir -p "$CONF_DIR" "$REG_DIR" "$PID_DIR"
+	chmod 755 "$CONF_DIR" "$REG_DIR" "$PID_DIR"
+	chown "$SIPROXD_UID:$SIPROXD_GID" "$REG_DIR"
+
+	siproxd_cb
+	config_load 'siproxd'
+}