1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2024-05-18 02:59:27 +00:00

Merge branch 'sip/dont_pass_sip_url_for_sips' into 'main'

sip: Don't listen for SIP messages when using SIPS and always include the transport parameter in SIP URLs

Closes #454

See merge request GNOME/calls!694
This commit is contained in:
Evangelos Ribeiro Tzaras 2024-04-18 12:46:14 +00:00
commit af34a1323d
2 changed files with 32 additions and 47 deletions

View file

@ -29,16 +29,18 @@
#define G_LOG_DOMAIN "CallsSipOrigin"
#include "calls-config.h"
#include "calls-account.h"
#include "calls-message-source.h"
#include "calls-network-watch.h"
#include "calls-origin.h"
#include "calls-sip-call.h"
#include "calls-sip-enums.h"
#include "calls-sip-media-manager.h"
#include "calls-sip-origin.h"
#include "calls-sip-util.h"
#include "calls-sip-media-manager.h"
#include "calls-network-watch.h"
#include "calls-config.h"
#include "calls-util.h"
#include "enum-types.h"
#include <glib/gi18n.h>
@ -951,11 +953,11 @@ setup_nua (CallsSipOrigin *self)
const char *ipv4_bind = "0.0.0.0";
const char *uuid = NULL;
g_autofree char *urn_uuid = NULL;
g_autofree char *sip_url = NULL;
g_autofree char *sips_url = NULL;
g_autofree char *url = NULL;
g_autofree char *protocol_lower = NULL;
g_autofree char *from_str = NULL;
if (!sip_test_env || sip_test_env[0] == '\0') {
if (!STR_IS_NULL_OR_EMPTY (sip_test_env)) {
CallsNetworkWatch *nw = calls_network_watch_get_default ();
if (nw) {
ipv4_bind = calls_network_watch_get_ipv4 (nw);
@ -967,6 +969,7 @@ setup_nua (CallsSipOrigin *self)
urn_uuid = g_strdup_printf ("urn:uuid:%s", uuid);
self->protocol_prefix = get_protocol_prefix (self->transport_protocol);
protocol_lower = g_ascii_strdown (self->transport_protocol, -1);
self->address = g_strconcat (self->user, "@", self->host, NULL);
from_str = g_strconcat (self->protocol_prefix, ":", self->address, NULL);
@ -976,37 +979,24 @@ setup_nua (CallsSipOrigin *self)
use_sips = check_sips (from_str);
use_ipv6 = check_ipv6 (self->host);
if (self->local_port > 0) {
sip_url = g_strdup_printf ("sip:%s:%d",
use_ipv6 ? ipv6_bind : ipv4_bind,
self->local_port);
sips_url = g_strdup_printf ("sips:%s:%d",
use_ipv6 ? ipv6_bind : ipv4_bind,
self->local_port);
} else {
sip_url = g_strdup_printf ("sip:%s:*",
use_ipv6 ? ipv6_bind : ipv4_bind);
sips_url = g_strdup_printf ("sips:%s:*",
use_ipv6 ? ipv6_bind : ipv4_bind);
}
/** For TLS nua_create() will error if NUTAG_URL includes ";transport=tls"
* In that case NUTAG_SIPS_URL should be used and NUTAG_URL should be as usual
* Since UDP is the default we only need to append the suffix in the TCP case
*/
if (g_ascii_strcasecmp (self->transport_protocol, "TCP") == 0) {
char *temp = sip_url;
sip_url = g_strdup_printf ("%s;transport=%s", temp, self->transport_protocol);
g_free (temp);
}
if (self->local_port > 0)
url = g_strdup_printf ("%s:%s:%d;transport=%s",
self->protocol_prefix,
use_ipv6 ? ipv6_bind : ipv4_bind,
self->local_port,
protocol_lower);
else
url = g_strdup_printf ("%s:%s:*;transport=%s",
self->protocol_prefix,
use_ipv6 ? ipv6_bind : ipv4_bind,
protocol_lower);
nua = nua_create (self->ctx->root,
sip_callback,
self,
NUTAG_USER_AGENT (APP_DATA_NAME),
NUTAG_URL (sip_url),
TAG_IF (use_sips, NUTAG_SIPS_URL (sips_url)),
TAG_IF (!use_sips, NUTAG_URL (url)),
TAG_IF (use_sips, NUTAG_SIPS_URL (url)),
SIPTAG_FROM_STR (from_str),
NUTAG_ALLOW ("INVITE, ACK, BYE, CANCEL, OPTIONS, UPDATE"),
NUTAG_SUPPORTED ("replaces, gruu, outbound"),
@ -1039,7 +1029,6 @@ static CallsSipHandles *
setup_sip_handles (CallsSipOrigin *self)
{
CallsSipHandles *oper;
g_autofree char *registrar_url = NULL;
g_assert (CALLS_IS_SIP_ORIGIN (self));
@ -1282,16 +1271,10 @@ supports_protocol (CallsOrigin *origin,
self = CALLS_SIP_ORIGIN (origin);
if (g_strcmp0 (protocol, "sip") == 0)
return TRUE;
if (g_strcmp0 (protocol, "sips") == 0)
return g_strcmp0 (self->protocol_prefix, "sips") == 0;
if (g_strcmp0 (protocol, "tel") == 0)
return self->can_tel;
return FALSE;
return g_ascii_strcasecmp (protocol, self->protocol_prefix) == 0;
}
@ -1300,7 +1283,7 @@ update_name (CallsSipOrigin *self)
{
g_assert (CALLS_IS_SIP_ORIGIN (self));
if (self->display_name && self->display_name[0] != '\0')
if (!STR_IS_NULL_OR_EMPTY (self->display_name))
self->name = self->display_name;
else
self->name = self->user;

View file

@ -43,11 +43,11 @@ check_sips (const char *addr)
const gchar *
get_protocol_prefix (const char *protocol)
{
if (g_strcmp0 (protocol, "UDP") == 0 ||
g_strcmp0 (protocol, "TCP") == 0)
if (g_ascii_strcasecmp (protocol, "UDP") == 0 ||
g_ascii_strcasecmp (protocol, "TCP") == 0)
return "sip";
if (g_strcmp0 (protocol, "TLS") == 0)
if (g_ascii_strcasecmp (protocol, "TLS") == 0)
return "sips";
return NULL;
@ -57,7 +57,9 @@ get_protocol_prefix (const char *protocol)
gboolean
protocol_is_valid (const char *protocol)
{
return g_strcmp0 (protocol, "UDP") == 0 ||
g_strcmp0 (protocol, "TCP") == 0 ||
g_strcmp0 (protocol, "TLS") == 0;
g_return_val_if_fail (protocol, FALSE);
return g_ascii_strcasecmp (protocol, "UDP") == 0 ||
g_ascii_strcasecmp (protocol, "TCP") == 0 ||
g_ascii_strcasecmp (protocol, "TLS") == 0;
}