From: Daniel Danzberger Date: Fri, 17 Jan 2025 00:14:41 +0000 (+0100) Subject: baresip: add uci config section for accounts X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=refs%2Fpull%2F892%2Fhead;p=feed%2Ftelephony.git baresip: add uci config section for accounts Adds a new UCI config section that allows the user to define accounts from which the init script will create the /etc/baresip/accounts file. Using UCI has the big benefit, that changes in the config can be recognized by reload_config which will restart baresip automatically. Example /etc/config/baresip: -- config baresip main option enable 1 option options '' config account option user '+49123456789' option password '' option server 'tel.t-online.de' option transport 'tls' option mediaenc 'srtp' config account option user '12' option password '7282ce22eee6d91193a1d5014398356x' option server '172.27.0.97' option transport 'udp' option append 'answerdelay=0;rwait=90;mwi=no' option ignore 1 -- The basic account options user,password,server,mediaenc and tansport can be set directly. All other custom baresip account options can be append to the account string using the 'append' option. Signed-off-by: Daniel Danzberger --- diff --git a/net/baresip/Makefile b/net/baresip/Makefile index 66a0a4d..17411ea 100644 --- a/net/baresip/Makefile +++ b/net/baresip/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=baresip PKG_VERSION:=3.16.0 -PKG_RELEASE:=2 +PKG_RELEASE:=3 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=https://codeload.github.com/baresip/baresip/tar.gz/v$(PKG_VERSION)? @@ -142,7 +142,6 @@ define Package/baresip/install endef define Package/baresip/conffiles -/etc/baresip/accounts /etc/baresip/config /etc/baresip/contacts endef diff --git a/net/baresip/files/baresip.defaults b/net/baresip/files/baresip.defaults index 7c1cd25..579943d 100644 --- a/net/baresip/files/baresip.defaults +++ b/net/baresip/files/baresip.defaults @@ -5,6 +5,23 @@ if [ ! -f "$CFGFILE" ]; then config baresip main option enable 0 option options '' + +config account + option user '+49123456789' + option password '' + option server 'tel.t-online.de' + option transport 'tls' + option mediaenc 'srtp' + option ignore 1 + +config account + option user '12' + option password '7282ce22eee6d91193a1d5014398356x' + option server '172.27.0.97' + option transport 'udp' + option mediaenc '' + option append 'answerdelay=0;rwait=90;mwi=no' + option ignore 1 EOF fi diff --git a/net/baresip/files/baresip.init b/net/baresip/files/baresip.init index 4416e1e..17efa67 100644 --- a/net/baresip/files/baresip.init +++ b/net/baresip/files/baresip.init @@ -4,6 +4,31 @@ START=92 USE_PROCD=1 PROG=/usr/bin/baresip +ACCOUNTS= + +add_account() +{ + local user password server transport append ignore mediaenc + local acc + + uci_validate_section baresip account "${1}" \ + 'ignore:bool:0' \ + 'user:string' \ + 'password:string' \ + 'server:string' \ + 'transport:string:udp' \ + 'mediaenc:string' \ + 'append:string' + + [ "$ignore" = "0" ] || return + + acc="" + [ -n "$mediaenc" ] && acc="${acc};mediaenc=${mediaenc}" + [ -n "$password" ] && acc="${acc};auth_pass=${password}" + [ -n "$append" ] && acc="${acc};${append}" + + ACCOUNTS="${ACCOUNTS}${acc}\n" +} start_service() { @@ -15,6 +40,10 @@ start_service() [ "$enable" = "0" ] && return + config_load baresip + config_foreach add_account account + printf "$ACCOUNTS" > /etc/baresip/accounts + procd_open_instance procd_set_param command $PROG -f /etc/baresip $options procd_set_param user baresip @@ -26,3 +55,8 @@ service_triggers() { procd_add_reload_trigger baresip } + +reload_service() +{ + /etc/init.d/baresip restart +}