Compare commits

...

4 Commits

Author SHA1 Message Date
Andreas Eversberg 7389e8413e PJSIP: Allow SIP uri scheme "tel:" in addition to "sip:" / "sips:"
Change-Id: Id157c4d6acf0c96b70021305907aa3e5185af8a7
2024-05-13 10:53:52 +02:00
Andreas Eversberg 8456b90904 PJSIP: Add functions to change TCP transport on the fly
Related: SY#6888
Change-Id: I41dbbd89187fcfc26198ad9dbe19b89b99ee9c32
2024-05-07 15:29:51 +02:00
Pau Espin ab1be367de PATCH: 0000-remove-third-party.patch 2024-04-26 17:43:38 +02:00
Pau Espin 8a766a7b04 PATCH: 0000-configure-ssl-library-path.patch 2024-04-26 17:43:01 +02:00
9 changed files with 200 additions and 114 deletions

View File

@ -9164,7 +9164,11 @@ else $as_nop
if test "x$with_ssl" != "xno" -a "x$with_ssl" != "x"; then
CFLAGS="$CFLAGS -I$with_ssl/include"
CPPFLAGS="$CPPFLAGS -I$with_ssl/include"
LDFLAGS="$LDFLAGS -L$with_ssl/lib"
if test -d $with_ssl/lib; then
LDFLAGS="$LDFLAGS -L$with_ssl/lib"
else
LDFLAGS="$LDFLAGS -L$with_ssl"
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: Using SSL prefix... $with_ssl" >&5
printf "%s\n" "Using SSL prefix... $with_ssl" >&6; }
fi

View File

@ -1947,7 +1947,11 @@ AC_ARG_ENABLE(ssl,
if test "x$with_ssl" != "xno" -a "x$with_ssl" != "x"; then
CFLAGS="$CFLAGS -I$with_ssl/include"
CPPFLAGS="$CPPFLAGS -I$with_ssl/include"
LDFLAGS="$LDFLAGS -L$with_ssl/lib"
if test -d $with_ssl/lib; then
LDFLAGS="$LDFLAGS -L$with_ssl/lib"
else
LDFLAGS="$LDFLAGS -L$with_ssl"
fi
AC_MSG_RESULT([Using SSL prefix... $with_ssl])
fi

View File

@ -1,4 +1,3 @@
export PJDIR := @ac_pjdir@
include $(PJDIR)/version.mak
export PJ_DIR := $(PJDIR)
@ -42,21 +41,6 @@ export APP_THIRD_PARTY_EXT :=
export APP_THIRD_PARTY_LIBS :=
export APP_THIRD_PARTY_LIB_FILES :=
ifneq (@ac_no_srtp@,1)
ifneq (@ac_external_srtp@,0)
# External SRTP library
APP_THIRD_PARTY_EXT += -l@ac_external_srtp_lib@
else
APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libsrtp-$(LIB_SUFFIX)
ifeq ($(PJ_SHARED_LIBRARIES),)
APP_THIRD_PARTY_LIBS += -lsrtp-$(TARGET_NAME)
else
APP_THIRD_PARTY_LIBS += -lsrtp
APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libsrtp.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/third_party/lib/libsrtp.$(SHLIB_SUFFIX)
endif
endif
endif
ifeq (@ac_pjmedia_resample@,libresample)
APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libresample-$(LIB_SUFFIX)
ifeq ($(PJ_SHARED_LIBRARIES),)
@ -73,102 +57,6 @@ APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libresample.$(SHLIB_SUFFI
endif
endif
ifneq (@ac_no_gsm_codec@,1)
ifeq (@ac_external_gsm@,1)
# External GSM library
APP_THIRD_PARTY_EXT += -lgsm
else
APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libgsmcodec-$(LIB_SUFFIX)
ifeq ($(PJ_SHARED_LIBRARIES),)
APP_THIRD_PARTY_LIBS += -lgsmcodec-$(TARGET_NAME)
else
APP_THIRD_PARTY_LIBS += -lgsmcodec
APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libgsmcodec.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/third_party/lib/libgsmcodec.$(SHLIB_SUFFIX)
endif
endif
endif
ifneq (@ac_no_speex_codec@,1)
ifeq (@ac_external_speex@,1)
APP_THIRD_PARTY_EXT += -lspeex -lspeexdsp
else
APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libspeex-$(LIB_SUFFIX)
ifeq ($(PJ_SHARED_LIBRARIES),)
APP_THIRD_PARTY_LIBS += -lspeex-$(TARGET_NAME)
else
APP_THIRD_PARTY_LIBS += -lspeex
APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libspeex.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/third_party/lib/libspeex.$(SHLIB_SUFFIX)
endif
endif
endif
ifneq (@ac_no_ilbc_codec@,1)
APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libilbccodec-$(LIB_SUFFIX)
ifeq ($(PJ_SHARED_LIBRARIES),)
APP_THIRD_PARTY_LIBS += -lilbccodec-$(TARGET_NAME)
else
APP_THIRD_PARTY_LIBS += -lilbccodec
APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libilbccodec.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/third_party/lib/libilbccodec.$(SHLIB_SUFFIX)
endif
endif
ifneq (@ac_no_g7221_codec@,1)
APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libg7221codec-$(LIB_SUFFIX)
ifeq ($(PJ_SHARED_LIBRARIES),)
APP_THIRD_PARTY_LIBS += -lg7221codec-$(TARGET_NAME)
else
APP_THIRD_PARTY_LIBS += -lg7221codec
APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libg7221codec.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/third_party/lib/libg7221codec.$(SHLIB_SUFFIX)
endif
endif
ifeq (@ac_external_pa@,1)
# External PA
APP_THIRD_PARTY_EXT += -lportaudio
endif
ifneq (@ac_no_yuv@,1)
ifeq (@ac_external_yuv@,1)
APP_THIRD_PARTY_EXT += -lyuv
else
APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libyuv-$(LIB_SUFFIX)
ifeq ($(PJ_SHARED_LIBRARIES),)
APP_THIRD_PARTY_LIBS += -lyuv-$(TARGET_NAME)
else
APP_THIRD_PARTY_LIBS += -lyuv
APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libyuv.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/third_party/lib/libyuv.$(SHLIB_SUFFIX)
endif
endif
endif
ifneq (@ac_no_webrtc@,1)
ifeq (@ac_external_webrtc@,1)
APP_THIRD_PARTY_EXT += -lwebrtc
else
APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libwebrtc-$(LIB_SUFFIX)
ifeq ($(PJ_SHARED_LIBRARIES),)
APP_THIRD_PARTY_LIBS += -lwebrtc-$(TARGET_NAME)
else
APP_THIRD_PARTY_LIBS += -lwebrtc
APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libwebrtc.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/third_party/lib/libwebrtc.$(SHLIB_SUFFIX)
endif
endif
endif
ifneq (@ac_no_webrtc_aec3@,1)
ifeq (@ac_external_webrtc_aec3@,1)
APP_THIRD_PARTY_EXT += -lwebrtc-aec3
else
APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libwebrtc-aec3-$(LIB_SUFFIX)
ifeq ($(PJ_SHARED_LIBRARIES),)
APP_THIRD_PARTY_LIBS += -lwebrtc-aec3-$(TARGET_NAME)
else
APP_THIRD_PARTY_LIBS += -lwebrtc-aec3
APP_THIRD_PARTY_LIB_FILES += $(PJ_DIR)/third_party/lib/libwebrtc-aec3.$(SHLIB_SUFFIX).$(PJ_VERSION_MAJOR) $(PJ_DIR)/third_party/lib/libwebrtc.$(SHLIB_SUFFIX)
endif
endif
endif
# Additional flags
@ac_build_mak_vars@

View File

@ -585,6 +585,7 @@ PJ_DECL(pj_status_t) pj_activesock_start_connect(pj_activesock_t *asock,
const pj_sockaddr_t *remaddr,
int addr_len);
PJ_DEF(pj_ioqueue_t) *pj_activesock_get_ioqueue(pj_activesock_t *asock);
#endif /* PJ_HAS_TCP */

View File

@ -980,5 +980,10 @@ static void ioqueue_on_connect_complete(pj_ioqueue_key_t *key,
}
}
PJ_DEF(pj_ioqueue_t) *pj_activesock_get_ioqueue(pj_activesock_t *asock)
{
return asock->ioqueue;
}
#endif /* PJ_HAS_TCP */

View File

@ -935,6 +935,12 @@ struct pjsip_transport
*/
pj_status_t (*destroy)(pjsip_transport *transport);
pj_status_t (*create_new_sock)(struct pjsip_transport *base,
pj_sockaddr *local_addr);
pj_status_t (*connect_new_sock)(struct pjsip_transport *base,
pj_sockaddr *local_addr,
pj_sockaddr *remote_addr);
/*
* Application may extend this structure..
*/

View File

@ -388,6 +388,13 @@ PJ_DECL(pjsip_sip_uri*) pjsip_sip_uri_create( pj_pool_t *pool,
PJ_DECL(void) pjsip_sip_uri_set_secure( pjsip_sip_uri *uri,
pj_bool_t secure );
/**
* Change the SIP URI scheme to tel.
* This would not change anything except the scheme.
* @param uri The URI
*/
PJ_DECL(void) pjsip_sip_uri_set_tel( pjsip_sip_uri *uri );
/**
* Initialize SIP URL (all fields are set to NULL or zero).
* @param url The URL.

View File

@ -105,6 +105,7 @@ struct tcp_transport
pj_sock_t sock;
pj_activesock_t *asock;
pj_bool_t has_pending_connect;
pj_sock_t new_sock;
/* Keep-alive timer. */
pj_timer_entry ka_timer;
@ -607,6 +608,13 @@ static void tcp_keep_alive_timer(pj_timer_heap_t *th, pj_timer_entry *e);
/* Clean up TCP resources */
static void tcp_on_destroy(void *arg);
/* Change transport addresses */
static pj_status_t tcp_create_new_sock(struct pjsip_transport *base,
pj_sockaddr *local_addr);
static pj_status_t tcp_connect_new_sock(struct pjsip_transport *base,
pj_sockaddr *local_addr,
pj_sockaddr *remote_addr);
/*
* Common function to create TCP transport, called when pending accept() and
* pending connect() complete.
@ -642,6 +650,7 @@ static pj_status_t tcp_create( struct tcp_listener *listener,
tcp = PJ_POOL_ZALLOC_T(pool, struct tcp_transport);
tcp->is_server = is_server;
tcp->sock = sock;
tcp->new_sock = PJ_INVALID_SOCKET;
/*tcp->listener = listener;*/
pj_list_init(&tcp->delayed_list);
tcp->base.pool = pool;
@ -685,6 +694,9 @@ static pj_status_t tcp_create( struct tcp_listener *listener,
tcp->base.destroy = &tcp_destroy_transport;
tcp->base.factory = &listener->factory;
tcp->base.initial_timeout = listener->initial_timeout;
tcp->base.create_new_sock = tcp_create_new_sock;
tcp->base.connect_new_sock = tcp_connect_new_sock;
/* Create group lock */
status = pj_grp_lock_create_w_handler(pool, NULL, tcp, &tcp_on_destroy,
@ -859,6 +871,10 @@ static pj_status_t tcp_destroy(pjsip_transport *transport,
tcp->sock = PJ_INVALID_SOCKET;
}
if (tcp->new_sock != PJ_INVALID_SOCKET)
pj_sock_close(tcp->new_sock);
if (tcp->grp_lock) {
pj_grp_lock_t *grp_lock = tcp->grp_lock;
tcp->grp_lock = NULL;
@ -1766,5 +1782,136 @@ PJ_DEF(pj_status_t) pjsip_tcp_transport_restart(pjsip_tpfactory *factory,
return status;
}
static pj_status_t tcp_create_new_sock(struct pjsip_transport *base,
pj_sockaddr *local_addr)
{
struct tcp_transport *tcp = (struct tcp_transport*) base;
struct tcp_listener *listener = (struct tcp_listener *)base->factory;
int af = pjsip_transport_type_get_af(listener->factory.type);
pj_sock_t new_sock;
pj_status_t status;
pj_sockaddr addr;
/* Close old socket */
if (tcp->new_sock != PJ_INVALID_SOCKET) {
pj_sock_close(tcp->new_sock);
tcp->new_sock = PJ_INVALID_SOCKET;
}
/* Create new socket */
status = pj_sock_socket(af,
pj_SOCK_STREAM() | pj_SOCK_CLOEXEC(),
0, &new_sock);
if (status != PJ_SUCCESS)
return status;
if (!local_addr) {
local_addr = &addr;
pj_bzero(&addr, sizeof(*local_addr));
pj_sockaddr_cp(&addr, &listener->bound_addr);
pj_sockaddr_set_port(&addr, 0);
}
/* Apply QoS, if specified */
status = pj_sock_apply_qos2(new_sock, listener->qos_type,
&listener->qos_params,
2, listener->factory.obj_name,
"outgoing SIP TCP socket");
/* Apply socket options, if specified */
if (listener->sockopt_params.cnt) {
status = pj_sock_setsockopt_params(new_sock, &listener->sockopt_params);
if (status != PJ_SUCCESS) {
PJ_PERROR(4, (listener->factory.obj_name, status,
"Warning: error applying socket options"));
}
}
if (1) {
int enabled = 1;
status = pj_sock_setsockopt(new_sock, pj_SOL_SOCKET(), pj_SO_REUSEADDR(),
&enabled, sizeof(enabled));
if (status != PJ_SUCCESS) {
PJ_PERROR(4, (listener->factory.obj_name, status,
"Warning: error applying SO_REUSEADDR"));
}
}
/* Bind new socket */
status = pj_sock_bind(new_sock, local_addr,
pj_sockaddr_get_len(local_addr));
if (status != PJ_SUCCESS) {
pj_sock_close(new_sock);
return status;
}
/* Store and return */
tcp->new_sock = new_sock;
return PJ_SUCCESS;
}
/* Change transport addresses */
static pj_status_t tcp_connect_new_sock(struct pjsip_transport *base,
pj_sockaddr *local_addr,
pj_sockaddr *remote_addr)
{
struct tcp_transport *tcp = (struct tcp_transport*) base;
pj_activesock_t *asock = tcp->asock;
pj_activesock_t *new_asock;
pj_activesock_cfg asock_cfg;
pj_activesock_cb tcp_callback;
pj_status_t status;
int addr_len;
PJ_ASSERT_RETURN(tcp->new_sock != PJ_INVALID_SOCKET, PJ_EINVAL);
/* Get the local addess */
addr_len = sizeof(*local_addr);
status = pj_sock_getsockname(tcp->new_sock, &local_addr, &addr_len);
if (status != PJ_SUCCESS) {
pj_activesock_close(new_asock);
return status;
}
/* Create active socket */
pj_activesock_cfg_default(&asock_cfg);
asock_cfg.async_cnt = 1;
asock_cfg.grp_lock = tcp->grp_lock;
pj_bzero(&tcp_callback, sizeof(tcp_callback));
tcp_callback.on_data_read = &on_data_read;
tcp_callback.on_data_sent = &on_data_sent;
tcp_callback.on_connect_complete = &on_connect_complete;
status = pj_activesock_create(tcp->base.pool, tcp->new_sock, pj_SOCK_STREAM(), &asock_cfg,
pj_activesock_get_ioqueue(asock), &tcp_callback, tcp, &new_asock);
if (status != PJ_SUCCESS) {
pj_sock_close(tcp->new_sock);
tcp->new_sock = PJ_INVALID_SOCKET;
return status;
}
/* Start asynchronous connect() operation */
status = pj_activesock_start_connect(new_asock, tcp->base.pool, remote_addr, pj_sockaddr_get_len(remote_addr));
if (status != PJ_SUCCESS && status != PJ_EPENDING) {
pj_activesock_close(new_asock);
return status;
}
/* Close old socket and assign the new one. */
pj_activesock_close(tcp->asock);
tcp->sock = tcp->new_sock;
tcp->new_sock = PJ_INVALID_SOCKET;
tcp->asock = new_asock;
/* Check if socket is already connected. */
tcp->has_pending_connect = PJ_TRUE;
if (status == PJ_SUCCESS) {
on_connect_complete(tcp->asock, PJ_SUCCESS);
}
return PJ_SUCCESS;
}
#endif /* PJ_HAS_TCP */

View File

@ -144,12 +144,14 @@ PJ_DEF(pj_ssize_t) pjsip_param_print_on( const pjsip_param *param_list,
static const pj_str_t *pjsip_url_get_scheme( const pjsip_sip_uri* );
static const pj_str_t *pjsips_url_get_scheme( const pjsip_sip_uri* );
static const pj_str_t *pjtel_url_get_scheme( const pjsip_sip_uri* );
static const pj_str_t *pjsip_name_addr_get_scheme( const pjsip_name_addr * );
static void *pjsip_get_uri( pjsip_uri *uri );
static void *pjsip_name_addr_get_uri( pjsip_name_addr *name );
static pj_str_t sip_str = { "sip", 3 };
static pj_str_t sips_str = { "sips", 4 };
static pj_str_t tel_str = { "tel", 3 };
static pjsip_name_addr* pjsip_name_addr_clone( pj_pool_t *pool,
const pjsip_name_addr *rhs);
@ -195,6 +197,15 @@ static pjsip_uri_vptr sips_url_vptr =
(P_CLONE) &pjsip_url_clone
};
static pjsip_uri_vptr tel_url_vptr =
{
(P_GET_SCHEME) &pjtel_url_get_scheme,
(P_GET_URI) &pjsip_get_uri,
(P_PRINT_URI) &pjsip_url_print,
(P_CMP_URI) &pjsip_url_compare,
(P_CLONE) &pjsip_url_clone
};
static pjsip_uri_vptr name_addr_vptr =
{
(P_GET_SCHEME) &pjsip_name_addr_get_scheme,
@ -216,6 +227,12 @@ static const pj_str_t *pjsips_url_get_scheme(const pjsip_sip_uri *url)
return &sips_str;
}
static const pj_str_t *pjtel_url_get_scheme(const pjsip_sip_uri *url)
{
PJ_UNUSED_ARG(url);
return &tel_str;
}
static void *pjsip_get_uri( pjsip_uri *uri )
{
return uri;
@ -232,6 +249,11 @@ PJ_DEF(void) pjsip_sip_uri_set_secure( pjsip_sip_uri *url,
url->vptr = secure ? &sips_url_vptr : &sip_url_vptr;
}
PJ_DEF(void) pjsip_sip_uri_set_tel( pjsip_sip_uri *url )
{
url->vptr = &tel_url_vptr;
}
PJ_DEF(void) pjsip_sip_uri_init(pjsip_sip_uri *url, pj_bool_t secure)
{
pj_bzero(url, sizeof(*url));
@ -527,6 +549,8 @@ static pjsip_sip_uri* pjsip_url_clone(pj_pool_t *pool, const pjsip_sip_uri *rhs)
return NULL;
pjsip_sip_uri_init(url, IS_SIPS(rhs));
if (PJSIP_URI_SCHEME_IS_TEL(rhs))
pjsip_sip_uri_set_tel(url);
pjsip_sip_uri_assign(pool, url, rhs);
return url;
}