Giter VIP home page Giter VIP logo

re's Introduction

baresip README

Baresip Logo

Baresip is a portable and modular SIP User-Agent with audio and video support.
Copyright (c) 2010 - 2024 Alfred E. Heggestad and Contributors
Distributed under BSD license

Build Lint OpenSSL and LibreSSL Valgrind

Features:

  • Call features:

    • Unlimited number of SIP accounts
    • Unlimited number of calls
    • Unattended call transfer
    • Auto answer
    • Call hold and resume
    • Microphone mute
    • Call waiting
    • Call recording
    • Peer to peer calls
    • Video calls
    • Instant Messaging
    • Custom ring tones
    • Repeat last call (redial)
    • Message Waiting Indication (MWI)
    • Address book with presence
    • Conferencing
  • Signaling:

    • SIP protocol support
    • SIP outbound protocol for NAT-traversal
    • SIP Re-invite
    • SIP Routes
    • SIP early media support
    • DNS NAPTR/SRV support
    • Multiple accounts support
    • DTMF support (RTP, SIP INFO)
    • Multicast sending & receiving
  • Security:

    • Signalling encryption (TLS)
    • Audio and video encryption (Secure RTP)
    • DTLS-SRTP key exchange protocol
    • ZRTP key exchange protocol
    • SDES key exchange protocol
  • Audio:

    • Low latency audio pipeline
    • High definition audio codecs
    • Audio device configuration
    • Audio filter plugins
    • Internal audio resampler for fixed sampling rates
    • Linear 16 bit wave format support for ringtones
    • Packet loss concealment (PLC)
    • Configurable ringtone playback device
    • Automatic gain control (AGC) and Noise reducation
    • Acoustic echo control (AEC)
    • Configurable audio sample format (Signed 16-bit, 24-bit, Float etc)
    • EBU ACIP (Audio Contribution over IP) Profile
  • Audio-codecs:

    • AAC
    • aptX
    • AMR narrowband, AMR wideband
    • Codec2
    • G.711
    • G.722
    • G.726
    • L16
    • MPA
    • Opus
  • Audio-drivers:

    • Advanced Linux Sound Architecture (ALSA) audio-driver
    • PulseAudio POSIX OSes audio-driver
    • Android OpenSLES audio-driver
    • Gstreamer playbin input audio-driver
    • JACK Audio Connection Kit audio-driver
    • MacOSX/iOS coreaudio/audiounit audio-driver
    • Portaudio audio-driver
    • Windows winwave audio-driver
  • Video:

    • Support for H.264, H.265, VP8, VP9, AV1 Video
    • Configurable resolution/framerate/bitrate
    • Configurable video input/output
    • Support for asymmetric video
    • Configurable video pixel format
    • Hardware acceleration for video encoder/decoder
  • Video-codecs:

    • AV1
    • H.264
    • H.265
    • VP8
    • VP9
  • Video-drivers:

    • iOS avcapture video-source
    • FFmpeg/libav libavformat/avdevice input
    • Direct Show video-source
    • MacOSX AVCapture video-source
    • Linux V4L/V4L2 video-source
    • X11 grabber video-source
    • DirectFB video-output
    • SDL2 video-output
    • X11 video-output
  • NAT-traversal:

    • STUN support
    • TURN server support
    • ICE support
    • NATPMP support
    • PCP (Port Control Protocol) support
  • Networking:

    • multihoming, IPv4/IPv6
    • automatic network roaming
  • Management:

    • Embedded web-server with HTTP interface
    • Command-line console over UDP/TCP
    • Command line interface (CLI)
    • Simple configuration files
    • MQTT (Message Queue Telemetry Transport) module
  • Profiles:

    • EBU ACIP (Audio Contribution over IP) Profile

Building

baresip is using CMake, and the following packages must be installed before building:

See Wiki: Install Stable Release or Wiki: Install GIT Version for a full guide.

Build with debug enabled

$ cmake -B build
$ cmake --build build -j
$ cmake --install build

Build with release

$ cmake -B build -DCMAKE_BUILD_TYPE=Release 
$ cmake --build build -j

Build with selected modules

$ cmake -B build -DMODULES="menu;account;g711"
$ cmake --build build -j

Build with custom app modules

$ cmake -B build -DAPP_MODULES_DIR=../baresip-apps/modules -DAPP_MODULES="auloop;vidloop"
$ cmake --build build -j

Build with clang compiler

$ cmake -B build -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
$ cmake --build build -j

Build static

$ cmake -B build -DSTATIC=ON
$ cmake --build build -j

Modules will be built if external dependencies are installed. After building you can start baresip like this:

$ build/baresip

The config files in $HOME/.baresip are automatically generated the first time you run baresip.

Build documentation

The API documentation can be build using doxygen.

$ doxygen mk/Doxyfile

By default the documentation is written to ../baresip-dox, if you want to change the destination directory you can change the OUTPUT_DIRECTORY in mk/Doxyfile.

Examples

  • Configuration examples are available in the examples directory.
  • Documentation on configuring baresip can be found in the Wiki.

License

The baresip project is using the 3-clause BSD license.

Contributing

Patches can be sent via Github Pull-Requests or to the Baresip mailing-list.

Design goals:

  • Minimalistic and modular VoIP client
  • SIP, SDP, RTP/RTCP, STUN/TURN/ICE
  • IPv4 and IPv6 support
  • RFC-compliancy
  • Robust, fast, low footprint
  • Portable C99 and C11 source code

Modular Plugin Architecture:

aac           Advanced Audio Coding (AAC) audio codec
account       Account loader
alsa          ALSA audio driver
amr           Adaptive Multi-Rate (AMR) audio codec
aptx          Audio Processing Technology codec (aptX)
aubridge      Audio bridge module
auconv        Audio sample format converter
audiounit     AudioUnit audio driver for MacOSX/iOS
aufile        Audio module for using a WAV-file as audio input
auresamp      Audio resampler
ausine        Audio sine wave input module
av1           AV1 video codec
avcapture     Video source using iOS AVFoundation video capture
avcodec       Video codec using FFmpeg/libav libavcodec
avfilter      Video filter using FFmpeg libavfilter
avformat      Video source using FFmpeg/libav libavformat
codec2        Codec2 low bit rate speech codec
cons          UDP/TCP console UI driver
contact       Contacts module
coreaudio     Apple macOS Coreaudio driver
ctrl_dbus     Control interface using DBUS
ctrl_tcp      TCP control interface using JSON payload
debug_cmd     Debug commands
directfb      DirectFB video display module
dshow         Windows DirectShow video source
dtls_srtp     DTLS-SRTP end-to-end encryption
ebuacip       EBU ACIP (Audio Contribution over IP) Profile
echo          Echo server module
evdev         Linux input driver
fakevideo     Fake video input/output driver
g711          G.711 audio codec
g722          G.722 audio codec
g7221         G.722.1 audio codec
g726          G.726 audio codec
gst           Gstreamer audio source
gtk           GTK+ 3 menu-based UI
gzrtp         ZRTP module using GNU ZRTP C++ library
httpd         HTTP webserver UI-module
httpreq       HTTP request module
ice           ICE protocol for NAT Traversal
jack          JACK Audio Connection Kit audio-driver
l16           L16 audio codec
menu          Interactive menu
mixausrc      Mixes another audio source into audio stream
mixminus      Mixes N-1 audio streams for conferencing
mpa           MPA Speech and Audio Codec
mqtt          MQTT (Message Queue Telemetry Transport) module
mwi           Message Waiting Indication
natpmp        NAT Port Mapping Protocol (NAT-PMP) module
netroam       Detects and applies changes of the local network addresses
opensles      OpenSLES audio driver
opus          OPUS Interactive audio codec
opus_multistream    OPUS multistream audio codec
pcp           Port Control Protocol (PCP) module
plc           Packet Loss Concealment (PLC) using spandsp
portaudio     Portaudio driver
pulse         Pulseaudio driver
presence      Presence module
rtcpsummary   RTCP summary module
sdl           Simple DirectMedia Layer 2.0 (SDL) video output driver
selfview      Video selfview module
serreg        Serial registration
snapshot      Save video-stream as PNG images
sndfile       Audio dumper using libsndfile
sndio         Audio driver for OpenBSD
srtp          Secure RTP encryption (SDES) using libre SRTP-stack
stdio         Standard input/output UI driver
stun          Session Traversal Utilities for NAT (STUN) module
swscale       Video scaling using libswscale
syslog        Syslog module
turn          Obtaining Relay Addresses from STUN (TURN) module
uuid          UUID generator and loader
v4l2          Video4Linux2 video source
vidbridge     Video bridge module
vidinfo       Video info overlay module
vp8           VP8 video codec
vp9           VP9 video codec
vumeter       Display audio levels in console
webrtc_aec    Acoustic Echo Cancellation (AEC) using WebRTC SDK
webrtc_aecm   Acoustic Echo Cancellation (AEC) mobile using WebRTC SDK
wincons       Console input driver for Windows
winwave       Audio driver for Windows
x11           X11 video output driver

IETF RFC/I-Ds:

  • RFC 2250 RTP Payload Format for the mpa Speech and Audio Codec

  • RFC 3016 RTP Payload Format for MPEG-4 Audio/Visual Streams

  • RFC 3262 Reliability of Provisional Responses for SIP

  • RFC 3311 SIP UPDATE Method

  • RFC 3428 SIP Extension for Instant Messaging

  • RFC 3711 The Secure Real-time Transport Protocol (SRTP)

  • RFC 3640 RTP Payload Format for Transport of MPEG-4 Elementary Streams

  • RFC 3856 A Presence Event Package for SIP

  • RFC 3863 Presence Information Data Format (PIDF)

  • RFC 3891 The SIP "Replaces" Header

  • RFC 4145 TCP-Based Media Transport in SDP

  • RFC 4240 Basic Network Media Services with SIP (partly)

  • RFC 4347 Datagram Transport Layer Security

  • RFC 4568 SDP Security Descriptions for Media Streams

  • RFC 4572 Connection-Oriented Media Transport over TLS Protocol in SDP

  • RFC 4574 The SDP Label Attribute

  • RFC 4585 Extended RTP Profile for RTCP-Based Feedback (RTP/AVPF)

  • RFC 4587 RTP Payload Format for H.261 Video Streams

  • RFC 4796 The SDP Content Attribute

  • RFC 4867 RTP Payload Format for the AMR and AMR-WB Audio Codecs

  • RFC 4961 Symmetric RTP / RTP Control Protocol (RTCP)

  • RFC 5285 A General Mechanism for RTP Header Extensions

  • RFC 5373 Requesting Answering Modes for SIP

  • RFC 5506 Support for Reduced-Size RTCP

  • RFC 5576 Source-Specific Media Attributes in SDP

  • RFC 5577 RTP Payload Format for ITU-T Recommendation G.722.1

  • RFC 5626 Managing Client-Initiated Connections in SIP

  • RFC 5627 Obtaining and Using GRUUs in SIP

  • RFC 5761 Multiplexing RTP Data and Control Packets on a Single Port

  • RFC 5763 Framework for Establishing a SRTP Security Context Using DTLS

  • RFC 5764 DTLS Extension to Establish Keys for SRTP

  • RFC 5888 The SDP Grouping Framework

  • RFC 6157 IPv6 Transition in SIP

  • RFC 6184 RTP Payload Format for H.264 Video

  • RFC 6263 App. Mechanism for Keeping Alive NAT Associated with RTP / RTCP

  • RFC 6416 RTP Payload Format for MPEG-4 Audio/Visual Streams

  • RFC 6464 A RTP Header Extension for Client-to-Mixer Audio Level Indication

  • RFC 6716 Definition of the Opus Audio Codec

  • RFC 6886 NAT Port Mapping Protocol (NAT-PMP)

  • RFC 7064 URI Scheme for STUN Protocol

  • RFC 7065 TURN Uniform Resource Identifiers

  • RFC 7310 RTP Payload Format for Standard apt-X and Enhanced apt-X Codecs

  • RFC 7587 RTP Payload Format for the Opus Speech and Audio Codec

  • RFC 7741 RTP Payload Format for VP8 Video

  • RFC 7742 WebRTC Video Processing and Codec Requirements

  • RFC 7798 RTP Payload Format for High Efficiency Video Coding (HEVC)

  • RFC 8285 A General Mechanism for RTP Header Extensions

  • RFC 8843 Negotiating Media Multiplexing Using SDP

  • draft-ietf-payload-vp9-16

Supported platforms:

  • Android (6.0 or later)
  • Apple macOS (10.12+)
  • Apple iOS 9.0 or later
  • Linux (kernel 3.0 or later, and glibc 2.5.x or later)
  • OpenBSD
  • Windows 10 or later (mingw and VS2019)

Supported versions of C Standard library

  • Android bionic
  • BSD libc
  • GNU C Library (glibc)
  • Musl
  • Windows C Run-Time Libraries (CRT)
  • uClibc

Supported compilers:

  • gcc 4.9 or later
  • MSVC 2019
  • clang 3.x or later

Supported versions of OpenSSL

  • OpenSSL version 1.1.1
  • OpenSSL version 3.x.x
  • LibreSSL version 3.x

Related projects

References

re's People

Contributors

akscf avatar alfredh avatar chubercoffee avatar cspiel1 avatar czarkoff avatar fancycode avatar fauernigg avatar fippo avatar i-mpossible avatar jimying avatar jobo-zt avatar johnjuuljensen avatar juha-h avatar jurjen-van-dijk avatar kuleshov-aleksei avatar landryb avatar larsimmisch avatar lastique avatar lgrahl avatar matthew-morrison avatar maximilianfridrich avatar pitti98 avatar richaas avatar robert-scheck avatar sreimers avatar vanrein avatar viordash avatar widgetii avatar wolf-so avatar ydroneaud avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

re's Issues

valid c99/c11 code ?

#include <re.h>


int main(void)
{
	libre_init();

	struct mbuf *mb = mbuf_alloc(512);

	(void)mb;
}
alfredh@debian:~/git/re$ make test
  CC      test.o
test.c: In function ‘main’:
test.c:8:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
    8 |  struct mbuf *mb = mbuf_alloc(512);
      |  ^~~~~~
  LD      test

packaging/CMakeLists.txt:3: Lines should be <= 80 characters long [linelength]

alfredh@debian:~/git/re$ ~/.local/bin/cmakelint packaging/CMakeLists.txt 
packaging/CMakeLists.txt:3: Lines should be <= 80 characters long [linelength]
Total Errors: 1

I am wondering why this error it not picked up by cmakelint in .github/workflows ?

proposed fix:

diff --git a/packaging/CMakeLists.txt b/packaging/CMakeLists.txt
index 10eb858..0a402e4 100644
--- a/packaging/CMakeLists.txt
+++ b/packaging/CMakeLists.txt
@@ -1,6 +1,6 @@
 set(CPACK_PACKAGE_NAME libre)
 set(CPACK_PACKAGE_VENDOR baresip)
-set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Generic library for real-time communications with async IO support")
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Library for Real-Time Communications")
 set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
 set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
 set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})

mk/re.mk:137: Unknown compiler cc\; supported compilers: gcc, clang

$ unset CC
$ make clean
mk/re.mk:137: Unknown compiler cc\; supported compilers: gcc, clang
mk/re.mk:427: Could not detect ARCH

This override of CC seems to be needed on Ubuntu 21.10.

ifeq ($(CC),cc)
       CC := gcc
endif

of commit 3de1984.

$ cc --version|head -n 1
cc (Ubuntu 11.2.0-7ubuntu2) 11.2.0

cc is an allowed alias/sym link for gcc.

re macros conflict with macros within the iOS SDK

Two macros (that I am aware of), LIST_INIT and LIST_FOREACH conflict with macros within sys/queue.h in the iOS SDK. re can't be built with these due to multiple definitions and they need to be altered in some way before they can build.

SIP BYE not possible - Protocol mix during a SIP dialog

Setup

Instance A sets UDP as default transport protocol via sip_transp_set_default().
Instance B sets TLS as default.

Start a dialog by INVITE from A to B.
Call termination by BYE from B to A.

Issue

The BYE is sent via TLS to port 5060. Then A is not able to process the TLS/SIP BYE at port 5060.

Questions

  • (A) Is a protocol mix during a SIP dialog allowed? The RFC-3261 (SIP) does nothing state about the transport protocol in Section 12.2 "Requests within a Dialog".
  • (B) Is it allowed to force the transport protocol of following SIP request to the transport protocol of the first SIP transaction in a SIP dialog?

Background

  • We shortly added a default SIP transport protocol setting. This currently is used for each SIP request if no ;transport= parameter is given.
  • Without this setting the default is UDP, like it was before this setting was added.

Possible Solution

Currently already e.g. the port number of the dialog route is used as target port number for the BYE. Should we also store the transport protocol in the sip_dialog and use this for following SIP requests during a dialog?

Broken SOVERSION

It seems like #221 introduced a breakage of the SOVERSION:

  • libre.so.2..
  • libre.so.2
  • libre.so

This shouldn't be libre.so.2.., but libre.so.2.0.0, I guess. Makefile:67 is where things start to break, because of no longer existent variables.

IPV6 in get_resolv_dns not handled correctly

I had an issue with the name server table being empty on some locations. It turned out that wifi routers with IPV6 addresses made get_resolv_dns in libre fail.

for (i=0; i<min(*n, (uint32_t)state.nscount) && !err; i++) {
		struct sockaddr_in *addr = &state.nsaddr_list[i];
		err |= sa_set_sa(&nsv[i], (struct sockaddr *)addr);
	}

When it goes through the list, an IPV6 address would have addr 0, and sa_set_sa will return an error. It will jump out, leaving the number of servers 0.

I made this fix and now it is working for me:

	err = 0;
#ifdef OPENBSD
	for (i=0; i<min(*n, (uint32_t)state.nscount) && !err; i++) {
		struct sockaddr_in *addr = &state.nsaddr_list[i];
		err |= sa_set_sa(&nsv[i], (struct sockaddr *)addr);
	}
#else
	union res_sockaddr_union *addr_union = mem_alloc(state.nscount * sizeof(union res_sockaddr_union), NULL);
	int servers = res_getservers(&state, addr_union,  state.nscount);
	
	for (i = 0; i < min(*n, (uint32_t)servers) && !err; i++) {
		if (addr_union[i].sin.sin_family == AF_INET) {
			err |= sa_set_sa(&nsv[i], (struct sockaddr *)&addr_union[i].sin);
		} else if (addr_union[i].sin6.sin6_family == AF_INET6) {
			err |= sa_set_sa(&nsv[i], (struct sockaddr *)&addr_union[i].sin6);
		} else {
			(void)re_fprintf(stderr, "Undefined family.\n");
		}
	}
	
	mem_deref(addr_union);
#endif

Is this a known issue? Or is something in my setup wrong that it was happening?

#error missing MD5 backend

Hi all, I want to install baresip on a raspberry pi but getting errors while building libre:

CC      build-arm6/md5/wrap.o
src/md5/wrap.c: In function ‘md5’:
src/md5/wrap.c:39:2: error: #error missing MD5 backend
 39 | #error missing MD5 backend
    |  ^~~~~
src/md5/wrap.c:25:25: warning: unused parameter ‘d’ [-Wunused-parameter]
 25 | void md5(const uint8_t *d, size_t n, uint8_t *md)
    |          ~~~~~~~~~~~~~~~^
src/md5/wrap.c:25:35: warning: unused parameter ‘n’ [-Wunused-parameter]
 25 | void md5(const uint8_t *d, size_t n, uint8_t *md)
    |                            ~~~~~~~^
src/md5/wrap.c:25:47: warning: unused parameter ‘md’ [-Wunused-parameter]
 25 | void md5(const uint8_t *d, size_t n, uint8_t *md)
    |                                      ~~~~~~~~~^~
make: *** [Makefile:124: build-arm6/md5/wrap.o] Error 1

path is missing from 'struct uri'

While testing websocket transport using Alfred's re patch, I noticed that path component is missing from struct uri:

struct uri {
	struct pl scheme;    /**< URI scheme e.g. "sip:" "sips:"    */
	struct pl user;      /**< Username                          */
	struct pl password;  /**< Optional password                 */
	struct pl host;      /**< Hostname or IP-address            */
	int af;              /**< Address family of host IP-address */
	uint16_t port;       /**< Port number                       */
	struct pl params;    /**< Optional URI-parameters           */
	struct pl headers;   /**< Optional URI-headers              */
};

Path is needed when websocket connection to SIP proxy is established via a normal web server acting as websocket proxy. In Apache, for example, websocket proxy function can be configured like this:

<VirtualHost _default_:443>
...
	<LocationMatch /wss/>
	        ProxyPass ws://192.168.43.83:7998/
	</LocationMatch>
</VirtualHost>

In baresip, the corresponding outbound proxy would then be configured like this:

;outbound="sip:192.168.43.83:443/wss/;transport=wss"

Path /wss/ in the URI is needed for the location match.

As a starter, would it be OK to add path to struct uri:

struct pl path;    /**< Optional URI-path        */

and then modify sip_addr_decode to set its value?

baresip was able to register via web server proxy when I hard coded path /wss/ to ws_connect_send:

        /* TODO: how to select ports of outbound SIP/WS proxy ?
	 * TODO: http url path "test" is temp, add config
	 */

	/* Use port if specified, otherwise use default HTTP/HTTPS ports */
	if (sa_port(dst)) {
		if (re_snprintf(ws_uri, sizeof(ws_uri),
				"%s://%J/wss/", prefix, dst) < 0) {
			err = ENOMEM;
			goto out;
		}
	}

But that was just a test. I would like to have real support for path in outbound URI.

Any suggestions? What does the second TODO in the above mean?

Enable REGISTER to swisscom servers

This patch enables REGISTER to swisscom servers. Otherwise, "500 CSCF Server Internal Error 11030230307".

`
--- src/sip/auth-orig.c 2021-03-22 11:59:52.121286939 +0100
+++ src/sip/auth.c 2021-03-22 17:35:05.637109236 +0100
@@ -270,6 +270,7 @@

	++realm->nc;
  •   err |= mbuf_write_str(mb, ", algorithm=MD5");
      err |= mbuf_write_str(mb, "\r\n");
      if (err)
      	break;
    

`

Clearly a problem with swisscom ("If the algorithm directive's value is "MD5" or unspecified..." on https://en.wikipedia.org/wiki/Digest_access_authentication), but let's play nice.

Update: Apparently, the "insert code" function is broken here, so to summarize: I've added ", algorithm=MD5" to the "Authorization" REGISTER response header. As I'm unsure how to make commits here, could the maintainer kindly add this to the main source?

Undeclaried identifier for AI_V4MAPPED

Hello,

I have a build failure on git main:

 CC      build-i586/sa/sa.o
src/sa/sa.c:72:20: error: use of undeclared identifier 'AI_V4MAPPED'
        hints.ai_flags  = AI_V4MAPPED | AI_ADDRCONFIG | AI_NUMERICHOST;
                          ^
1 error generated.
gmake: *** [Makefile:117: build-i586/sa/sa.o] Error 1
$ cc -v
OpenBSD clang version 11.1.0
Target: i386-unknown-openbsd6.9
Thread model: posix
InstalledDir: /usr/bin
$ gmake -v
GNU Make 4.3
Built for i386-unknown-openbsd6.9

I build with gmake CC=clang on my OpenBSD i386 machine running a snapshot from yesterday.

Maybe this commit broke it?

14cbecf

Question about Include Guards

Is there a specific reason why there is an include guard in re.h only?

Part of the include tree:

  • re.h
    • re_async.h (unguarded)
    • re_main.h (unguarded)
      • re_async.h (unguarded. Second time included) => Possible redefinitions?!

Isn't this kind of erroneous?

odict_entry union segfaults

Problem

https://github.com/baresip/baresip/blob/master/modules/mqtt/subscribe.c#L77:

	debug("mqtt: handle_command:  cmd='%s', token='%s'\n",
	      oe_cmd->u.str,
	      oe_tok ? oe_tok->u.str : "");

If odict_entry type is a not string this produces a segfault, because struct odict_entry u is a union and for example could be a integer value instead of a pointer.

struct odict_entry {
	struct le le, he;
	char *key;
	union {
		struct odict *odict;   /* ODICT_OBJECT / ODICT_ARRAY */
		char *str;             /* ODICT_STRING */
		int64_t integer;       /* ODICT_INT    */
		double dbl;            /* ODICT_DOUBLE */
		bool boolean;          /* ODICT_BOOL   */
	} u;
	enum odict_type type;
};

Its very easy to crash baresip mqtt with:

/baresip/01/command/ {"command":"example","params":null,"token":11}

Solution 1 - struct instead of union

struct odict_entry {
	struct le le, he;
	char *key;
	struct {
		struct odict *odict;   /* ODICT_OBJECT / ODICT_ARRAY */
		char *str;             /* ODICT_STRING */
		int64_t integer;       /* ODICT_INT    */
		double dbl;            /* ODICT_DOUBLE */
		bool boolean;          /* ODICT_BOOL   */
	} u;
	enum odict_type type;
};

Pros

  • We can add optional type conversions (like string to int with atoi) if possible.
  • It's backwards compatible

Cons

  • Higher memory usage (+32 Bytes per entry)
  • Slower?

Solution 2 - Hide odict_entry struct

If we hide the struct odict_entry, direct access with e->u.str is not possible anymore.
We can add safe getters like these:

/* Odict entry Helpers */
const char *odict_entry_str(const struct odict_entry *e);
int64_t odict_entry_int(const struct odict_entry *e);
bool odict_entry_bool(const struct odict_entry *e);

or use const char *odict_string(const struct odict *o, const char *key);

Pros

  • We can enforce strict type handling

Cons

  • Not backwards compatible (breaks API)

Solution 3 - Has to be handled by implementation

Instead of handling this in libre and preventing misuse, we can fix all direct accesses to u.str and other types with strict type checks before access.

Pros

  • backwards compatible ;-)

Cons

  • It`s easy to overlook the union type and a simple json int instead of string
    can result in a segfault.

@alfredh do you have a preference or another solution?

error: unknown type name 'thrd_t

I just tried to my Android app using the latest main branches of re/rem/baresip. libbaresip build succeesed without errors, but build of the app failed like this:

In file included from /usr/src/baresip-studio/app/src/main/cpp/vidisp.c:5:
In file included from /usr/src/baresip-studio/distribution.video/re/include/re.h:59:
/usr/src/baresip-studio/distribution.video/re/include/re_thread.h:69:17: error: unknown type name 'thrd_t'

Line 5 of vidisp.c has:

#include <re.h>

Am I missing some new include or something?

Coverity CID 250884

*** CID 250884:  Insecure data handling  (TAINTED_SCALAR)
/src/rtp/fb.c: 102 in rtcp_rtpfb_twcc_decode()
96     	msg->chunks = mbuf_alloc_ref(mb);
97     	if (!msg->chunks)
98     		return ENOMEM;
99     
100     	msg->chunks->end = msg->chunks->pos;
101     	sz = 0;
>>>     CID 250884:  Insecure data handling  (TAINTED_SCALAR)
>>>     Using tainted variable "i" as a loop boundary.
102     	for (size_t i = msg->count; i > 0;) {
103     		uint16_t chunk;
104     
105     		if (mbuf_get_left(mb) < 2)
106     			return EBADMSG;
107     		chunk  = ntohs(mbuf_read_u16(mb));

I think this is a false positive, since there is the msg->count == 0 check and if (mbuf_get_left(mb) < 2) so a tainted/invalid msg->count value should no problem. But maybe I am miss something, @alfredh @fippo can you review too?

This seem the root cause for the tainting:

3. var_assign: Assigning: msg->count = ntohs(mbuf_read_u16(mb)), which taints msg->count.
 88        msg->count = ntohs(mbuf_read_u16(mb));
4. lower_bounds: Casting narrower unsigned msg->count to wider signed type int effectively tests its lower bound.

btrace: the backtrace does not include the function names

Already applied this PR: #177 and got this back trace without function names while examine a memory leak.

mem: Memory leaks (1):
  0x55682b64a248: nrefs=1  size=776     [60 e1 09 67 6e 7f 00 00 00 00 00 00 00 00 00 00 ] [`..gn...........]
/usr/local/lib/libre.so.1(+0x73b32) [0x7f6e6712db32] 
/usr/local/lib/libre.so.1(mem_alloc+0x84) [0x7f6e6712dbea] 
/usr/local/lib/libre.so.1(mem_zalloc+0x27) [0x7f6e6712dd24] 
[0x7f6e6709b027] 
[0x7f6e63f381fb] 
[0x7f6e63f38824] 
[0x7f6e63f36643] 
[0x7f6e63f36a73] 
[0x7f6e63f36b7d] 
/usr/local/lib/libre.so.1(+0x5f927) [0x7f6e67119927] 

Build host:

  • linux
  • gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)

Android build error "typedef redefinition with different types" on NDK 23

Hello sir,
Good day.
I would like to raise this issue I have encountered upon building baresip on android, there seems to be no problem on my previous environment NDK version 15c. However, upgrading the NDK to 23 results in the following error.

/libs/re/include/re_types.h:51:18: error: typedef redefinition with different types ('long' vs '__kernel_ssize_t' (aka 'int'))
  typedef long     ssize_t;
                   
/Library/Android/sdk/ndk/23.0.7599858/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/sys/types.h:128:26: note: previous definition is here
  typedef __kernel_ssize_t ssize_t;

the same error goes to typedef int32_t __socklen_t

checking on re_type.h and NDK sys/types.h the difference is on the Macro definition

_SSIZE_T_DEFINED _
used in Android NDK

__ssize_t_defined
used in re_type.h

Workaround the issue would be to change re_type.h macro to be the same as android ndk macro which is _SSIZE_T_DEFINED _

Tested these modification with baresip on Android NDK 23

//re_types.h
......
#ifndef _SSIZE_T_DEFINED_
typedef long     ssize_t;
#define _SSIZE_T_DEFINED_
#endif

#if !defined(__LP64__)
typedef int32_t __socklen_t;
#else
typedef uint32_t socklen_t;
#endif
#endif

Thank you.

Earl

First `re_thread_init()` always fails with `EALREADY`

The check at this line:

if (re) {

always succeeds for the first re_thread_init call because re_init that is called from re_once sets the TLS pointer to the newly created re instance.

Suggestion: drop re_global and don't set TLS in re_init. Reformulate re_init to work as a factory function for creating a re context without setting it anywhere. Make the caller (e.g. re_thread_init) set it to TLS.

RTCP: remove session member on timeout

Hello!

I have a long-running call with sip re-invites (persistent "nailed-up connection"). Each re-invite adds rtcp member to rtcp_sess->members list.
Currently MAX_MEMBERS is capped to 8 members. After exceeding this limit I get this warining: "could not add member".
Unfortunately cisco telephony is set up without sending RTCP BYE packet. Thats why members count is always increases. Increasing MAX_MEMBERS just delays this warning.

RFC 3550 (6.3.5) indicates that rtcp member can be removed from members list after some time (tc - MTd, where tc - is current time, M - timeout multiplier, Td - calculated interval for a receiver).

As I noticed, re does not have rtcp timeout mechanism. If I'm wrong, please correct me.

Do you know how this problem can be solved? I can implement rtcp member deletion by rtcp timeout and make a PR if you agree

re build failure - hmac.c:74:31: error: invalid application of 'sizeof' to an incomplete type 'HMAC_CTX'

Hi,

Getting build failure with re. The file being referenced is ~5 years old.

  CC      build-i586/hmac/openssl/hmac.o
src/hmac/openssl/hmac.c:30:3: warning: implicit declaration of function 'HMAC_CTX_cleanup' is invalid in C99 [-Wimplicit-function-declaration]
                HMAC_CTX_cleanup(hmac->ctx);
                ^
src/hmac/openssl/hmac.c:74:31: error: invalid application of 'sizeof' to an incomplete type 'HMAC_CTX' (aka 'struct hmac_ctx_st')
        hmac->ctx = mem_zalloc(sizeof(*hmac->ctx), NULL);
                                     ^~~~~~~~~~~~
/usr/include/openssl/ossl_typ.h:114:16: note: forward declaration of 'struct hmac_ctx_st'
typedef struct hmac_ctx_st HMAC_CTX;
               ^
src/hmac/openssl/hmac.c:80:2: warning: implicit declaration of function 'HMAC_CTX_init' is invalid in C99 [-Wimplicit-function-declaration]
        HMAC_CTX_init(hmac->ctx);
        ^
2 warnings and 1 error generated.
gmake: *** [Makefile:122: build-i586/hmac/openssl/hmac.o] Error 1

build warnings when HAVE_INET6 is off

Debian 11:

alfredh@debian:~/git/re$ make HAVE_INET6= HAVE_INET6_IGNORE_DEPRECATED=1 1>/dev/null
src/http/client.c: In function ‘http_client_set_laddr6’:
src/http/client.c:1111:46: warning: unused parameter ‘cli’ [-Wunused-parameter]
 1111 | void http_client_set_laddr6(struct http_cli *cli, const struct sa *addr)
      |                             ~~~~~~~~~~~~~~~~~^~~
src/http/client.c:1111:68: warning: unused parameter ‘addr’ [-Wunused-parameter]
 1111 | void http_client_set_laddr6(struct http_cli *cli, const struct sa *addr)
      |                                                   ~~~~~~~~~~~~~~~~~^~~~
src/dns/client.c: In function ‘dnsc_alloc’:
src/dns/client.c:859:19: warning: unused variable ‘laddr6’ [-Wunused-variable]
  859 |  struct sa laddr, laddr6;
      |                   ^~~~~~
src/sa/sa.c: In function ‘sa_set_scopeid’:
src/sa/sa.c:696:45: warning: unused parameter ‘scopeid’ [-Wunused-parameter]
  696 | void sa_set_scopeid(struct sa *sa, uint32_t scopeid)
      |                                    ~~~~~~~~~^~~~~~~

it would be nice if building with this option gave zero warnings ...

shim: compile error with _Generic and MSVC 2019

The compiler used is running on Windows 10.
The compiler is from MSVC 2019 but not the latest version within that package.

\src\shim\shim.c(50): warning C4013: '_Generic' undefined; assuming extern returning int
\src\shim\shim.c(50): error C2275: 'uint16_t': illegal use of this type as an expression

The compiler does not understand the keyword _Generic. It would be good to make the code
compile also for compilers that does not understand _Generic.

Timer is locked and does not work

Hi!
The timer does not run if it is started between the re_thread_enter() and re_thread_leave() functions.
Code to reproduce the issue, baresip-webrtc application, calling the CalledFromOtherThread method from another thread:

struct tmr tmr = {};

static void timeout_handler(void *arg) {
	void * tag = arg;
	printf("                          ********timeout_handler, tag:%p, t:%lu\n", tag, tmr_jiffies());
}

static void CalledFromOtherThread(void * tag) {
	printf("                          ---test 0, tag:%p, t:%lu\n", tag, tmr_jiffies());
	tmr_init(&tmr);
	printf("                          ---test 1, tag:%p, t:%lu\n", tag, tmr_jiffies());
	re_thread_enter();
	printf("                          ---test 2, tag:%p, t:%lu\n", tag, tmr_jiffies());

	tmr_start(&tmr, 100, timeout_handler, tag);

	printf("                          ---test 3, tag:%p, t:%lu\n", tag, tmr_jiffies());
	re_thread_leave();
	printf("                          ---test 4, tag:%p, t:%lu\n", tag, tmr_jiffies());
	sys_msleep(2000);
	printf("                          ---test 5, tag:%p, t:%lu\n", tag, tmr_jiffies());
}

static void *test_task(void *argument) {
	sys_msleep(1000);

	printf("                          --------from task, tag:%p, t:%lu\n", argument, tmr_jiffies());
	CalledFromOtherThread(argument);
	pthread_exit(NULL);
}

log output:

demo: listening on:
    http://192.168.2.156:9000/
    https://192.168.2.156:9001/
                          --------from main, tag:0x10ca1, t:700865909
                          ---test 0, tag:0x10ca1, t:700865909
                          ---test 1, tag:0x10ca1, t:700865909
                          ---test 2, tag:0x10ca1, t:700865909
                          ---test 3, tag:0x10ca1, t:700865909
                          ---test 4, tag:0x10ca1, t:700865909
                          ---test 5, tag:0x10ca1, t:700867911
                          ********timeout_handler, tag:0x10ca1, t:700867915
                          --------from task, tag:0x42, t:700868914
                          ---test 0, tag:0x42, t:700868914
                          ---test 1, tag:0x42, t:700868914
                          ---test 2, tag:0x42, t:700868914
                          ---test 3, tag:0x42, t:700868914
                          ---test 4, tag:0x42, t:700868914
                          ---test 5, tag:0x42, t:700870916
                          ********timeout_handler, tag:0x42, t:700877708
demo: request: met=POST, path=/connect, prm=
demo: create session

As you can see from the logs, ********timeout_handler, tag:0x42, t:700877708 happened after 7 seconds, those only after I made a request to http://192.168.2.156:9000/ in the browser. As I understand poll in re/src/main/main.c:736 received an event and then my timer fired.

I came across this error while trying to test baresip-webrtc with another session initiation protocol. And I found out that repeated peerconnection_new, which is called from another thread, does not trigger peerconnection_gather_handler. Since dns query uses data from query_cache and query_handler is then called via a timer.

Is this a real problem with the timer? Or am I not using baresip correctly with multiple threads?

backtrace_symbols openbsd current

re now builds fine, but baresip still has issues.

 LD      baresip
ld: error: ../re/libre.so: undefined reference to backtrace_symbols [--no-allow-shlib-undefined]
ld: error: ../re/libre.so: undefined reference to backtrace [--no-allow-shlib-undefined]
clang: error: linker command failed with exit code 1 (use -v to see invocation)
gmake: *** [Makefile:319: baresip] Error 1

Originally posted by @jungle-boogie in #201 (comment)

Compile failure on OpenBSD i386

Hi,

From the latest commit, I'm getting a build failure on my OpenBSD i386 machine.
Would it be necessary to bisect this?

  CC      build-i586/net/sockopt.o
  CC      build-i586/net/posix/pif.o
  CC      build-i586/net/bsd/brt.o
  CC      build-i586/net/ifaddrs.o
  CC      build-i586/tcp/tcp.o
  CC      build-i586/tcp/tcp_high.o
  CC      build-i586/tls/openssl/tls.o
  CC      build-i586/tls/openssl/tls_tcp.o
src/tls/openssl/tls_tcp.c:382:10: error: use of undeclared identifier 'EKEYREJECTED'
                return EKEYREJECTED;
                       ^
1 error generated.
gmake: *** [Makefile:108: build-i586/tls/openssl/tls_tcp.o] Error 1

gmake info:

$ gmake -v
GNU Make 4.3
Built for i386-unknown-openbsd6.9

cc info:

$ cc -v
OpenBSD clang version 11.1.0
Target: i386-unknown-openbsd6.9
Thread model: posix
InstalledDir: /usr/bin
$ openssl version
LibreSSL 3.4.0

OS version:

$ sysctl kern.version
kern.version=OpenBSD 6.9-current (GENERIC.MP) #22: Tue May 18 11:04:43 MDT 2021
    [email protected]:/usr/src/sys/arch/i386/compile/GENERIC.MP

Thanks!

gcov ci error

is there a problem with CI and GCOV ?

(WARNING) Unrecognized GCOV output for /home/runner/work/re/re/src/mbuf/mbuf.c
[8](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:8)
	  branch  2 taken -2 (fallthrough)
[9](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:9)
	This is indicative of a gcov output parse error.
[10](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:10)
	Please report this to the gcovr developers
[11](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:11)
	at <https://github.com/gcovr/gcovr/issues>.
[12](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:12)
(WARNING) Exception during parsing:
[13](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:13)
	UnknownLineType: branch  2 taken -2 (fallthrough)
[14](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:14)
(ERROR) Exiting because of parse errors.
[15](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:15)
	You can run gcovr with --gcov-ignore-parse-errors
[16](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:16)
	to continue anyway.
[17](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:17)
Traceback (most recent call last):
[18](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:18)
  File "/home/runner/.local/lib/python3.8/site-packages/gcovr/workers.py", line 77, in worker
[19](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:19)
    work(*args, **kwargs)
[20](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:20)
  File "/home/runner/.local/lib/python3.8/site-packages/gcovr/gcov.py", line 317, in process_datafile
[21](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:21)
    done = run_gcov_and_process_files(
[22](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:22)
  File "/home/runner/.local/lib/python3.8/site-packages/gcovr/gcov.py", line 490, in run_gcov_and_process_files
[23](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:23)
    process_gcov_data(fname, covdata, abs_filename, options)
[24](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:24)
  File "/home/runner/.local/lib/python3.8/site-packages/gcovr/gcov.py", line 145, in process_gcov_data
[25](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:25)
    coverage = parse_coverage(
[26](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:26)
  File "/home/runner/.local/lib/python3.8/site-packages/gcovr/gcov_parser.py", line 370, in parse_coverage
[27](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:27)
    _report_lines_with_errors(lines_with_errors, context)
[28](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:28)
  File "/home/runner/.local/lib/python3.8/site-packages/gcovr/gcov_parser.py", line 509, in _report_lines_with_errors
[29](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:29)
    raise errors[0]  # guaranteed to have at least one exception
[30](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:30)
  File "/home/runner/.local/lib/python3.8/site-packages/gcovr/gcov_parser.py", line 322, in parse_coverage
[31](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:31)
    tokenized_lines.append((_parse_line(raw_line), raw_line))
[32](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:32)
  File "/home/runner/.local/lib/python3.8/site-packages/gcovr/gcov_parser.py", line 777, in _parse_line
[33](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:33)
    raise UnknownLineType(line)
[34](https://github.com/baresip/re/runs/6439790475?check_suite_focus=true#step:9:34)
gcovr.gcov_parser.UnknownLineType: branch  2 taken -2 (fallthrough)

sipsess coverity warning

** CID 274764:  Null pointer dereferences  (REVERSE_INULL)
/src/sipsess/connect.c: 91 in invite_resp_handler()


________________________________________________________________________________________________________
*** CID 274764:  Null pointer dereferences  (REVERSE_INULL)
/src/sipsess/connect.c: 91 in invite_resp_handler()
85     	if (msg->scode < 200) {
86     		sess->progrh(msg, sess->arg);
87     
88     		if (sip_msg_hdr_has_value(msg, SIP_HDR_REQUIRE, "100rel")
89     				&& sess->rel100_supported) {
90     
>>>     CID 274764:  Null pointer dereferences  (REVERSE_INULL)
>>>     Null-checking "msg" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
91     			if (msg && mbuf_get_left(msg->mb)) {
92     				if (sess->sent_offer) {
93     					sess->awaiting_answer = false;
94     					err = sess->answerh(msg, sess->arg);
95     					if (err)
96     						goto out;

** CID 274763:  Control flow issues  (DEADCODE)
/src/sipsess/accept.c: 113 in sipsess_accept()


________________________________________________________________________________________________________
*** CID 274763:  Control flow issues  (DEADCODE)
/src/sipsess/accept.c: 113 in sipsess_accept()
107     	}
108     	else if (scode >= 200) {
109     		err = sipsess_reply_2xx(sess, msg, scode, reason, desc,
110     					fmt, &ap);
111     	}
112     	else {
>>>     CID 274763:  Control flow issues  (DEADCODE)
>>>     Execution cannot reach this statement: "struct sip_contact contact;".
113     		struct sip_contact contact;
114     
115     		sip_contact_set(&contact, sess->cuser, &msg->dst, msg->tp);
116     
117     		err = sip_treplyf(&sess->st, NULL, sess->sip,
118     				  msg, true, scode, reason,

@cspiel1 @maximilianfridrich can you check this?

ns: sa_set: ... (Invalid argument) messages during startup

Hello. I'm attempting to configure baresip v1.1.0 on my OpenBSD-current system. The last time I used baresip was a few years ago, and I don't recall seeing the following messages (or something similar) printed while starting up the program.

ns: sa_set: 10.0.0.1 # resolvd: em0 (Invalid argument)
ns: sa_set: fd00:10::1 # resolvd: em0 (Invalid argument)

Earlier this year, OpenBSD introduced resolvd(8) [1], and as a result, the nameserver entries in /etc/resolv.conf are now formatted by resolvd as follows:

nameserver 10.0.0.1 # resolvd: em0
nameserver fd00:10::1 # resolvd: em0

I wasn't able to confirm this on my own, so I just wanted to check if the addition of "# resolvd: em0" to the nameserver entries is possibly causing this message/issue.

[1] https://man.openbsd.org/resolvd

merge from alfredh/re

hi @sreimers and @juha-h

I have some commits in alfredh/re that can be merged to baresip/re

this mainly includes:

  1. sip trace
  2. ice fixes

could you please merge and review from my repo ?

this can be done with the following commands:

$ git remote add alfredh https://github.com/alfredh/re.git
$ git fetch alfredh
$ git merge alfredh/master

thanks.

src/trace/trace.c:72:24: error: implicit declaration of function ‘pthread_self’

compiling latest version with no pthread gives error:

$ make HAVE_PTHREAD=

src/trace/trace.c: In function ‘get_thread_id’:
src/trace/trace.c:72:24: error: implicit declaration of function ‘pthread_self’ [-Werror=implicit-function-declaration]
   72 |  return (unsigned long)pthread_self();
      |                        ^~~~~~~~~~~~
src/trace/trace.c:72:24: error: nested extern declaration of ‘pthread_self’ [-Werror=nested-externs]
cc1: all warnings being treated as errors
make: *** [Makefile:122: build-x86_64/trace/trace.o] Error 1
Build step 'Execute shell' marked build as failure
Finished: FAILURE

Atomic API - missing symbol for GCC 4.3.5

Hello everyone,

we are using libre / baresip for quite a while now and are very happy with it. BareSIP is a very powerful SIP client. But recently we ran into quite a tricky situation. The projects libre and baresip have minimum requirements on the compiler version and C standard which is absolutely understandable. Unfortunately we are using (we have to use) a very old compiler => bfin-linux-uclibc-g++ (ADI-2014R1-RC2) 4.3.5

During compilation of baresip we get the following compiling errors

LD baresip
build-blackfin/src/audio.o: In function stop_tx': src/audio.c:266: undefined reference to ___sync_val_compare_and_swap_1'
src/audio.c:267: undefined reference to ___sync_val_compare_and_swap_1' build-blackfin/src/audio.o: In function start_source':
src/audio.c:1576: undefined reference to ___sync_val_compare_and_swap_1' src/audio.c:1577: undefined reference to ___sync_val_compare_and_swap_1'
src/audio.c:1582: undefined reference to ___sync_val_compare_and_swap_1' build-blackfin/src/audio.o:src/audio.c:1195: more undefined references to ___sync_val_compare_and_swap_1' follow
collect2: ld returned 1 exit status
Makefile:325: recipe for target 'baresip' failed

It seems (I think) the reason are the recently more used atomic functions from re_atomic.h. There is a commit that makes me believe that we have a chance to make baresip compiling again, even with our dinosaur-compiler.

commit 84113e940e1e6f4598812c8104126de6d3069894 (origin/commend56)
Author: Andrey Semashev [email protected]
Date: Thu Aug 4 15:49:43 2022 +0300

atomic: Added support for gcc __sync intrinsics.

This adds support for older gcc versions that didn't support
__atomic intrinsics.

Do you have any advice for us? Unfortunately updating the compiler is no option :'(

using re timers properly when multithreaded

"tmr_start" adds a tmr element to the global tmr list.

list_insert_before(tmrl, le, &tmr->le, tmr);

Is it safe to call tmr_start from a thread different to the libre main thread?

What happens, if the thread adding an element to the timer list is interrupted by the libre main thread. Could it crash or have other impacts?
Is there a way to lock the tmr list during modification?

make failed

CC build-x86_64/main/openssl.o
src/main/openssl.c: In function ‘openssl_init’:
src/main/openssl.c:30:2: warning: implicit declaration of function ‘OPENSSL_init_ssl’ [-Wimplicit-function-declaration]
err = OPENSSL_init_ssl(OPENSSL_INIT_SSL_DEFAULT, NULL);
^
src/main/openssl.c:30:2: warning: nested extern declaration of ‘OPENSSL_init_ssl’ [-Wnested-externs]
src/main/openssl.c:30:25: error: ‘OPENSSL_INIT_SSL_DEFAULT’ undeclared (first use in this function)
err = OPENSSL_init_ssl(OPENSSL_INIT_SSL_DEFAULT, NULL);
^
src/main/openssl.c:30:25: note: each undeclared identifier is reported only once for each function it appears in
make: *** [build-x86_64/main/openssl.o] Error 1

Is this the new home of re?

Hi. Homebrew maintainer here (Homebrew is a package manager for macOS and Linux).

We were wondering what is the difference / link between this repo and https://github.com/creytiv/re?
The same holds for rem.

Is the creytiv repo not actively maintained, so you are now the "official" upstream? Or is this a fork that goes in a different direction (which means that a new release on https://github.com/creytiv/re might conflict with what you are shipping here).

For reference: https://github.com/Homebrew/homebrew-core/pull/91871/files#r774099932

win32 warnings

hi @sreimers

here are some more win32 warnings with cmake:

ninja: warning: multiple rules generate re.lib. builds involving this target will not be correct; continuing anyway [-w dupbuild=warn]

um\qos2.h(39): warning C4142: 'QOS_FLOWID': benign redefinition of type
src\udp\udp.c(35): note: see declaration of 'QOS_FLOWID'
um\qos2.h(39): warning C4142: 'PQOS_FLOWID': benign redefinition of type
src\udp\udp.c(35): note: see declaration of 'PQOS_FLOWID'

Upstream .so name versioning?

(Basically the same as at creytiv/re#249, but it seems that this is the new home of re)

As of writing, there doesn't seem to be proper upstream .so name versioning in re. Yes, I'm aware there is something like LIB_SUFFIX=.so.0, but this unfortunately has nothing to do with proper .so name versioning, as the SONAME is still libre.so rather libre.so.0. Yes, even this can be worked around by passing some arguments like SH_LFLAGS="-shared -Wl,-soname,libre.so.0", but this still doesn't let downstreams know whether the old and the new version are ABI compatible or not, thus this should be IMHO really handled by upstream.

Quoting from section "SONAME handling" from https://docs.fedoraproject.org/en-US/packaging-guidelines/#_downstream_so_name_versioning:

The SONAME field is written to the shared object by linker, using (at least in case of ld) the -soname SONAME flags. This can be passed as an option to gcc like this:

$ gcc $CFLAGS -Wl,-soname,libfoo.so.0.n -o libfoo.so.0.n

If you want to check if the SONAME field is set and what value it has, use the objdump command (from binutils):

$ objdump -p /path/to/libfoo.so.0.n | grep 'SONAME'

Please note that this issue is also meant as very kind try to convince you as upstream to start versioning your .so library (as our Fedora Packaging Guidelines request).

OpenSSL v3.0.x Support - fixing deprecation warnings

For OpenSSL v3 we have to fix many deprecation warnings, since we use some low level APIs:

https://wiki.openssl.org/index.php/OpenSSL_3.0#Main_Changes_in_OpenSSL_3.0_from_OpenSSL_1.1.1

CC      build-x86_64/stun/ctrans.o                                                                                                                        
src/websock/websock.c:374:2: warning: 'SHA1_Init' is deprecated [-Wdeprecated-declarations]                                                                 
        SHA1_Init(&ctx);                                                                                                                                    
        ^                                                                                                                                                   
.././include/openssl/sha.h:49:1: note: 'SHA1_Init' has been explicitly marked deprecated here                                                               
OSSL_DEPRECATEDIN_3_0 int SHA1_Init(SHA_CTX *c);                                                                                                            
^                                                                                                                                                           
.././include/openssl/macros.h:182:49: note: expanded from macro 'OSSL_DEPRECATEDIN_3_0'                                                                     
#   define OSSL_DEPRECATEDIN_3_0                OSSL_DEPRECATED(3.0)                                                                                        
                                                ^                                                                                                           
.././include/openssl/macros.h:62:52: note: expanded from macro 'OSSL_DEPRECATED'                                                                            
#     define OSSL_DEPRECATED(since) __attribute__((deprecated))                                                                                             
                                                   ^                                                                                                        
src/websock/websock.c:375:2: warning: 'SHA1_Update' is deprecated [-Wdeprecated-declarations]                                                               
        SHA1_Update(&ctx, key->p, key->l);                                                                                                                  
        ^                                                                                                                                                   
.././include/openssl/sha.h:50:1: note: 'SHA1_Update' has been explicitly marked deprecated here                                                             
OSSL_DEPRECATEDIN_3_0 int SHA1_Update(SHA_CTX *c, const void *data, size_t len);                                                                            
^                                                                                                                                                           
.././include/openssl/macros.h:182:49: note: expanded from macro 'OSSL_DEPRECATEDIN_3_0'                                                                     
#   define OSSL_DEPRECATEDIN_3_0                OSSL_DEPRECATED(3.0)                                                                                        
                                                ^                                                                                                           
.././include/openssl/macros.h:62:52: note: expanded from macro 'OSSL_DEPRECATED'                                                                            
#     define OSSL_DEPRECATED(since) __attribute__((deprecated))                                                                                             
                                                   ^                                                                                                        
src/websock/websock.c:376:2: warning: 'SHA1_Update' is deprecated [-Wdeprecated-declarations]                                                               
        SHA1_Update(&ctx, magic, sizeof(magic)-1);                                                                                                          
        ^                                                                                                                                                   
.././include/openssl/sha.h:50:1: note: 'SHA1_Update' has been explicitly marked deprecated here                                                             
OSSL_DEPRECATEDIN_3_0 int SHA1_Update(SHA_CTX *c, const void *data, size_t len);                                                                            
^                                                                                                                                                           
.././include/openssl/macros.h:182:49: note: expanded from macro 'OSSL_DEPRECATEDIN_3_0'                                                                     
#   define OSSL_DEPRECATEDIN_3_0                OSSL_DEPRECATED(3.0)                                                                                        
                                                ^                                                                                                           
.././include/openssl/macros.h:62:52: note: expanded from macro 'OSSL_DEPRECATED'                                                                            
#     define OSSL_DEPRECATED(since) __attribute__((deprecated))                                                                                             
                                                   ^
src/websock/websock.c:377:2: warning: 'SHA1_Final' is deprecated [-Wdeprecated-declarations]
        SHA1_Final(digest, &ctx);
        ^
.././include/openssl/sha.h:51:1: note: 'SHA1_Final' has been explicitly marked deprecated here
OSSL_DEPRECATEDIN_3_0 int SHA1_Final(unsigned char *md, SHA_CTX *c);
^
.././include/openssl/macros.h:182:49: note: expanded from macro 'OSSL_DEPRECATEDIN_3_0'
#   define OSSL_DEPRECATEDIN_3_0                OSSL_DEPRECATED(3.0)
                                                ^
.././include/openssl/macros.h:62:52: note: expanded from macro 'OSSL_DEPRECATED'
#     define OSSL_DEPRECATED(since) __attribute__((deprecated))
                                                   ^
  CC      build-x86_64/stun/dnsdisc.o

...

retest: valgrind Conditional jump or move depends on uninitialised value(s)

using retest 32c2d48f88d6227def94fb5d7bd7f7d7ed2a747a

valgrind --leak-check=full --show-reachable=yes --error-exitcode=42 ./retest -r
==353180== Memcheck, a memory error detector
==353180== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==353180== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==353180== Command: ./retest -r
==353180== 
regular tests:       retest: libre version 2.0.1-dev13 (x86_64/linux)
using async polling method 'epoll'
==353180== Conditional jump or move depends on uninitialised value(s)
==353180==    at 0x48BA0AE: jbuf_put (jbuf.c:504)
==353180==    by 0x1292AD: test_jbuf (jbuf.c:52)
==353180==    by 0x14579F: test_unit (test.c:442)
==353180==    by 0x145F2A: test_reg (test.c:660)
==353180==    by 0x12E5DB: main (main.c:234)
==353180== 
==353180== Conditional jump or move depends on uninitialised value(s)
==353180==    at 0x48BA0AE: jbuf_put (jbuf.c:504)
==353180==    by 0x12938D: test_jbuf (jbuf.c:67)
==353180==    by 0x14579F: test_unit (test.c:442)
==353180==    by 0x145F2A: test_reg (test.c:660)
==353180==    by 0x12E5DB: main (main.c:234)
==353180== 
==353180== Conditional jump or move depends on uninitialised value(s)
==353180==    at 0x48BA0AE: jbuf_put (jbuf.c:504)
==353180==    by 0x1293BD: test_jbuf (jbuf.c:71)
==353180==    by 0x14579F: test_unit (test.c:442)
==353180==    by 0x145F2A: test_reg (test.c:660)
==353180==    by 0x12E5DB: main (main.c:234)
==353180== 
==353180== Conditional jump or move depends on uninitialised value(s)
==353180==    at 0x48BA0AE: jbuf_put (jbuf.c:504)
==353180==    by 0x129514: test_jbuf (jbuf.c:95)
==353180==    by 0x14579F: test_unit (test.c:442)
==353180==    by 0x145F2A: test_reg (test.c:660)
==353180==    by 0x12E5DB: main (main.c:234)
==353180== 
==353180== Conditional jump or move depends on uninitialised value(s)
==353180==    at 0x48BA0AE: jbuf_put (jbuf.c:504)
==353180==    by 0x129544: test_jbuf (jbuf.c:99)
==353180==    by 0x14579F: test_unit (test.c:442)
==353180==    by 0x145F2A: test_reg (test.c:660)
==353180==    by 0x12E5DB: main (main.c:234)
==353180== 
==353180== Conditional jump or move depends on uninitialised value(s)
==353180==    at 0x48BA0AE: jbuf_put (jbuf.c:504)
==353180==    by 0x129574: test_jbuf (jbuf.c:103)
==353180==    by 0x14579F: test_unit (test.c:442)
==353180==    by 0x145F2A: test_reg (test.c:660)
==353180==    by 0x12E5DB: main (main.c:234)
==353180== 
==353180== Conditional jump or move depends on uninitialised value(s)
==353180==    at 0x483BC98: strlen (vg_replace_strmem.c:459)
==353180==    by 0x48CF826: str_len (str.c:167)
==353180==    by 0x13C134: test_sip_auth_encode (sipauth.c:72)
==353180==    by 0x13C201: test_sip_auth (sipauth.c:90)
==353180==    by 0x14579F: test_unit (test.c:442)
==353180==    by 0x145F2A: test_reg (test.c:660)
==353180==    by 0x12E5DB: main (main.c:234)
==353180== 
==353180== 
==353180== HEAP SUMMARY:
==353180==     in use at exit: 0 bytes in 0 blocks
==353180==   total heap usage: 39,392 allocs, 39,392 frees, 9,039,957 bytes allocated
==353180== 
==353180== All heap blocks were freed -- no leaks are possible
==353180== 
==353180== Use --track-origins=yes to see where uninitialised values come from
==353180== For lists of detected and suppressed errors, rerun with: -s
==353180== ERROR SUMMARY: 11 errors from 7 contexts (suppressed: 0 from 0)
Build step 'Execute shell' marked build as failure
Finished: FAILURE

build failure with gcc 4.3.5

  CC      build-blackfin/dns/client.o
src/dns/client.c: In function 'async_getaddrinfo':
src/dns/client.c:785: error: storage size of 'hints' isn't known
src/dns/client.c:794: error: 'AI_ADDRCONFIG' undeclared (first use in this function)

With reverted 6729125 re builds again.

Sip over Websocket

Hi, i'm try to connect a server with sip over websocket, but in the register return the next error --> Invalid argument

i dont know if i skip initialize any struct.


#define USER    "user"
#define PASS    "pass"
#define DOMAIN  "domain.com"
#define URI     "sip:" USER "@" DOMAIN

const char *registrar  = "sip:[ip]:443";

static struct sipreg *reg;
static struct sip *sip;
static struct sipsess_sock *sess_sock;
static struct sip_auth **sip_auth =NULL;

/*!
 * Authentication handler
 */
static int auth_handler(char **user, char **pass, const char *realm, void *arg)
{

    int err = 0;
    (void)realm;
    (void)arg;

    err |= str_dup(user, USER);
    err |= str_dup(pass, PASS);


    return err;
}



static void resp_handler(int err, const struct sip_msg *msg, void *arg)
{
    LOGI("<<-- Response handler.\n");
    LOGI("Argument from sip_drequestf : %s\n", (char*)arg);
    //LOGI("Response code: %d\n", msg->scode);
    if (err){
        LOGI("Error in reposponse handler: %s\n", strerror(err));
        return;
    }
    LOGI("----- response received ----\n");
    LOGI("%s", msg->mb->buf);
    LOGI("----------------------------\n");
    re_cancel();
}


/*!
 * Exit handler
 */
static void exit_handler(void *arg)
{
    (void)arg;

    /* stop libre main loop */
    re_cancel();
}

/*!
 * Signal handler
 */
static void signal_handler(int sig)
{
    LOGI("terminating on signal %d...\n", sig);

    /* terminate registration */
    reg = mem_deref(reg);

    /* wait for pending transactions to finish */
    sip_close(sip, false);
}



void sip_ws( ){
    struct sa nsv[16];
    struct dnsc *dnsc = NULL;
    struct sa laddr;
    uint32_t nsc;
    int err = 0;
    struct re_printf *pf;


    /* enable coredumps to aid debugging */
    (void)sys_coredump_set(true);

    /* initialize libre state */
    err = libre_init();
    if (err) {
        LOGI("re init failed: %s\n", strerror(err));
        goto exit;
    }

    nsc = ARRAY_SIZE(nsv);



    /* create SIP stack instance */
    err = sip_alloc(&sip, NULL, 32, 32, 32,
                    "PandaTalk2" VERSION " (" ARCH "/" OS ")",
                    exit_handler, NULL);
    LOGI("Create SIP stack instance.\n");

    if (err) {
        LOGI( "ERROR  SIP ALLOC: [%d] %s\n", err, strerror(err));
        goto exit;
    }


    /* fetch local IP address */
    err = net_default_source_addr_get(AF_INET, &laddr);
    LOGI("Fetch local IP address.\n");

    if (err) {
        LOGI( "ERROR EN LOCAL IP ADDRESS: [%d] %s\n", err, strerror(err));
        goto exit;
    }



    sa_set_port(&laddr, 0);
    LOGI("Set port.\n");

    bool server = false ;


    /* add supported SIP transports */
    err |= sip_transp_add_websock(sip, SIP_TRANSP_WSS, &laddr, false,"");

    if (err) {
        LOGI( "ERROR EN SIP CON WEBSOCKET PORT: [%d] %s\n", err, strerror(err));
        goto exit;
    }

    LOGI("Add WSS SIP transport.\n");




// this function return error


    /* register UA */

    err = sipreg_register(&reg, sip, registrar, URI, URI, URI, 60,
                          USER, 0, 0, 0, auth_handler, NULL,
                          0, resp_handler, NULL, NULL,NULL);


    if (err) {
        LOGI( "register error: [%d] %s\n", err, strerror(err));
        goto exit;
    }

    LOGI("registering <%s>...\n", URI);

    /* main loop */
    err = re_main(signal_handler);

    LOGI( "ERROR MAIN LOOP : [%d] %s\n", err, strerror(err));

    exit:
        mem_deref(sess_sock);
        mem_deref(sip);
        mem_deref(dnsc);

        libre_close();

        tmr_debug();
        mem_debug();

}

Thanks for the help.

incompatible or wrong C11 Threads return value handling

Hi,
the problem is the following code:

if (err) {

You assume that the success code is zero, which is not the case in FreeBSD implementation for example:
https://github.com/freebsd/freebsd-src/blob/3c9ad9398fcdf5f49114fde978b7c837b7ebbc8d/lib/libstdthreads/threads.h#L68

In the standard the value of thrd_success is unspecified:
https://en.cppreference.com/w/c/thread/thrd_errors
So I think return value of all functions related to threads.h must be explicitly compared with members of the enum

Note that the specific line of code in libre source code might be not the only one existed in all 3 projects (re/rem/baresip).
Multiple places where return values get checked might be affected.

Regards,
Denis.

Disable automatic following of redirect

Currently all incoming 3xx responses are handled internally and followed through. I would like to be able to have some control over whether redirection (3xx) is automatically followed or not, based on what is in the 3xx message.

Would you accept a PR for a new API for re_sipsess.h as follows:

int sipsess_follow_redirects(struct sipsess *sess, bool enable);

This would set a bool flag on the session such that in invite_resp_handler can chose not to follow the redirect and just terminate the call with the 3xx message available to the client. I would call it immediately after sipsess_connect. Existing clients that do not call this new function will behave as before.

expected behavior of TCP keepalive

Hi,
I have some systems where, apparently randomly (after many hours, usually) and without other network failures, the connection is lost and is re-established only when a re-register happens after the configured regint time. This leaves some minutes when the the system is not reachable.

The account:

"user" <sip:[email protected];transport=tcp>;auth_user=user;auth_pass=password;answermode=manual;audio_codecs=PCMA,PCMU;regint=600;pubint=300;video_codecs=h264;outbound="sip:sip.example.net;transport=tcp";sipnat=outbound

As you can see I'm using sipnat outbound.

In this case, looking at the code, I assument it should enable a TCP keepalive that if I've understood correctly, will publish a \r\n every 120 seconds (TCP_KEEPALIVE_INTVAL) and wait 10 seconds before closing a non-working connection:

int sip_keepalive_tcp(struct sip_keepalive *ka, struct sip_conn *conn,

However, from a tcpdump I do not see any '\r\n' lines sent at any interval.

Should I look for something else? Is this a feature that requires server-side support? (we are currently using FlexiSIP)

Thanks for your help!

src/net/bsd/brt.c:12:10: fatal error: 'net/route.h' file not found

Hello,

I am trying to build baresip for iOS, using the repository https://github.com/baresip/baresip-ios

Unfortunatelly, the make contrib command fails with the following issue:

src/net/bsd/brt.c:12:10: fatal error: 'net/route.h' file not found
#include <net/route.h>
         ^~~~~~~~~~~~~
1 error generated.
make[1]: *** [/Users/runner/work/1/s/build/aarch64/libre/net/bsd/brt.o] Error 1
make: *** [libre] Error 2
##[error]Bash exited with code '2'.

The file "src/net/bsd/brt.c" is in the re library.

In order to build the baresip-ios library, I use a pipeline which is running on macOS 11.

Do you know how to fix this issue? Is something missing on my pipeline?

Thank you for your help

Build error on openbsd arm64 (raspberry pi)

Build re library on raspberry pi3 (install openbsd)

build with Makefile/make error:

gmake: gcc: No such file or directory
mk/re.mk:137: Unknown compiler gcc\; supported compilers: gcc, clang
gmake: gcc: No such file or directory
gmake: gcc: No such file or directory
mk/re.mk:427: Could not detect ARCH
  CC      build-/sip/addr.o
gmake: gcc: No such file or directory
gmake: *** [Makefile:119: build-/sip/addr.o] Error 127

build with cmake error:

/home/pi/tmp/re/src/sys/sleep.c:35:18: error: variable has incomplete type 'struct timeval'
                struct timeval tv;
                               ^
/home/pi/tmp/re/src/sys/sleep.c:35:10: note: forward declaration of 'struct timeval'
                struct timeval tv;
                       ^
/home/pi/tmp/re/src/sys/sleep.c:40:9: warning: implicit declaration of function 'select' is invalid in C99 [-Wimplicit-function-declaration]
                (void)select(0, NULL, NULL, NULL, &tv);
                      ^
1 warning and 1 error generated.
*** Error 1 in target 'CMakeFiles/re.dir/src/sys/sleep.c.o'
*** Error 1 in . (CMakeFiles/re.dir/build.make:1644 'CMakeFiles/re.dir/src/sys/sleep.c.o': /usr/bin/cc -DARCH=\"aarch64\" -DHAVE_ARC4RANDOM ...)
*** Error 2 in . (CMakeFiles/Makefile2:139 'CMakeFiles/re.dir/all')

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.