mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2025-01-06 03:25:31 +00:00
sip: allow specifying local port and use IPv6
This commit is contained in:
parent
37b9fe1c30
commit
1836c7c915
4 changed files with 51 additions and 17 deletions
|
@ -72,6 +72,7 @@ struct _CallsSipOrigin
|
|||
gchar *transport_protocol;
|
||||
const gchar *protocol_prefix;
|
||||
gint port;
|
||||
gint local_port;
|
||||
|
||||
GList *calls;
|
||||
GHashTable *call_handles;
|
||||
|
@ -97,6 +98,7 @@ enum {
|
|||
PROP_ACC_DIRECT,
|
||||
PROP_ACC_AUTO_CONNECT,
|
||||
PROP_SIP_CONTEXT,
|
||||
PROP_SIP_LOCAL_PORT,
|
||||
PROP_ACC_STATE,
|
||||
PROP_CALLS,
|
||||
PROP_LAST_PROP,
|
||||
|
@ -421,6 +423,8 @@ setup_nua (CallsSipOrigin *self)
|
|||
g_autofree gchar *address = NULL;
|
||||
nua_t *nua;
|
||||
gboolean use_sips;
|
||||
g_autofree gchar * sip_url = NULL;
|
||||
g_autofree gchar * sips_url = NULL;
|
||||
|
||||
g_return_val_if_fail (CALLS_IS_SIP_ORIGIN (self), NULL);
|
||||
|
||||
|
@ -428,14 +432,20 @@ setup_nua (CallsSipOrigin *self)
|
|||
|
||||
use_sips = check_sips (address);
|
||||
|
||||
// TODO URLs must be changed to accomodate IPv6 use case (later, not important right now)
|
||||
// Note: This is why using hostname does not work! (do we need two nua contexts for ipv4 and ipv6?)
|
||||
if (self->local_port > 0) {
|
||||
sip_url = g_strdup_printf ("sip:*:%d", self->local_port);
|
||||
sips_url = g_strdup_printf ("sips:*:%d", self->local_port);
|
||||
} else {
|
||||
sip_url = g_strdup ("sip:*:*");
|
||||
sips_url = g_strdup_printf ("sips:*:*");
|
||||
}
|
||||
|
||||
nua = nua_create (self->ctx->root,
|
||||
sip_callback,
|
||||
self,
|
||||
NUTAG_USER_AGENT ("sofia-test/0.0.1"),
|
||||
NUTAG_URL ("sip:0.0.0.0:5060"),
|
||||
TAG_IF (use_sips, NUTAG_SIPS_URL ("sips:0.0.0.0:5060")),
|
||||
NUTAG_URL (sip_url),
|
||||
TAG_IF (use_sips, NUTAG_SIPS_URL (sips_url)),
|
||||
NUTAG_M_USERNAME (self->user),
|
||||
SIPTAG_FROM_STR (address),
|
||||
NUTAG_ENABLEINVITE (1),
|
||||
|
@ -786,6 +796,10 @@ calls_sip_origin_set_property (GObject *object,
|
|||
self->auto_connect = g_value_get_boolean (value);
|
||||
break;
|
||||
|
||||
case PROP_SIP_LOCAL_PORT:
|
||||
self->local_port = g_value_get_int (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
|
@ -834,6 +848,10 @@ calls_sip_origin_get_property (GObject *object,
|
|||
g_value_set_boolean (value, self->auto_connect);
|
||||
break;
|
||||
|
||||
case PROP_SIP_LOCAL_PORT:
|
||||
g_value_set_int (value, self->local_port);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
|
@ -974,6 +992,14 @@ calls_sip_origin_class_init (CallsSipOriginClass *klass)
|
|||
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
|
||||
g_object_class_install_property (object_class, PROP_SIP_CONTEXT, props[PROP_SIP_CONTEXT]);
|
||||
|
||||
props[PROP_SIP_LOCAL_PORT] =
|
||||
g_param_spec_int ("local-port",
|
||||
"Local port",
|
||||
"The local port to which the SIP stack binds to",
|
||||
1025, 65535, 5060,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
|
||||
g_object_class_install_property (object_class, PROP_SIP_LOCAL_PORT, props[PROP_SIP_LOCAL_PORT]);
|
||||
|
||||
props[PROP_ACC_STATE] =
|
||||
g_param_spec_enum ("account-state",
|
||||
"Account state",
|
||||
|
@ -1052,6 +1078,7 @@ calls_sip_origin_new (const gchar *name,
|
|||
const gchar *password,
|
||||
const gchar *host,
|
||||
gint port,
|
||||
gint local_port,
|
||||
const gchar *protocol,
|
||||
gboolean direct_connection,
|
||||
gboolean auto_connect)
|
||||
|
@ -1066,6 +1093,7 @@ calls_sip_origin_new (const gchar *name,
|
|||
"password", password,
|
||||
"host", host,
|
||||
"port", port,
|
||||
"local-port", local_port,
|
||||
"protocol", protocol,
|
||||
"direct-connection", direct_connection,
|
||||
"auto-connect", auto_connect,
|
||||
|
@ -1076,6 +1104,7 @@ calls_sip_origin_new (const gchar *name,
|
|||
return origin;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
calls_sip_origin_go_online (CallsSipOrigin *self,
|
||||
gboolean online)
|
||||
|
|
|
@ -37,11 +37,12 @@ G_DECLARE_FINAL_TYPE (CallsSipOrigin, calls_sip_origin, CALLS, SIP_ORIGIN, GObje
|
|||
|
||||
CallsSipOrigin *calls_sip_origin_new (const gchar *name,
|
||||
CallsSipContext *sip_context,
|
||||
const gchar *user,
|
||||
const gchar *password,
|
||||
const gchar *host,
|
||||
gint port,
|
||||
const gchar *protocol,
|
||||
const gchar *user,
|
||||
const gchar *password,
|
||||
const gchar *host,
|
||||
gint port,
|
||||
gint local_port,
|
||||
const gchar *protocol,
|
||||
gboolean direct_connection,
|
||||
gboolean auto_connect);
|
||||
void calls_sip_origin_create_inbound (CallsSipOrigin *self,
|
||||
|
|
|
@ -111,6 +111,7 @@ calls_sip_provider_load_accounts (CallsSipProvider *self)
|
|||
g_autofree gchar *host = NULL;
|
||||
g_autofree gchar *protocol = NULL;
|
||||
gint port = 0;
|
||||
gint local_port = 0;
|
||||
gboolean direct_connection =
|
||||
g_key_file_get_boolean (key_file, groups[i], "Direct", NULL);
|
||||
gboolean auto_connect = TRUE;
|
||||
|
@ -118,8 +119,10 @@ calls_sip_provider_load_accounts (CallsSipProvider *self)
|
|||
if (g_key_file_has_key (key_file, groups[i], "AutoConnect", NULL))
|
||||
auto_connect = g_key_file_get_boolean (key_file, groups[i], "AutoConnect", NULL);
|
||||
|
||||
if (direct_connection)
|
||||
if (direct_connection) {
|
||||
local_port = 5060;
|
||||
goto skip;
|
||||
}
|
||||
|
||||
if (!check_required_keys (key_file, groups[i])) {
|
||||
g_warning ("Not all required keys found in section %s of file `%s'",
|
||||
|
@ -132,6 +135,7 @@ calls_sip_provider_load_accounts (CallsSipProvider *self)
|
|||
host = g_key_file_get_string (key_file, groups[i], "Host", NULL);
|
||||
protocol = g_key_file_get_string (key_file, groups[i], "Protocol", NULL);
|
||||
port = g_key_file_get_integer (key_file, groups[i], "Port", NULL);
|
||||
local_port = g_key_file_get_integer (key_file, groups[i], "LocalPort", NULL);
|
||||
|
||||
skip:
|
||||
if (protocol == NULL)
|
||||
|
@ -144,15 +148,12 @@ calls_sip_provider_load_accounts (CallsSipProvider *self)
|
|||
else
|
||||
port = 5060;
|
||||
}
|
||||
|
||||
g_debug ("Adding origin for SIP account %s", groups[i]);
|
||||
|
||||
calls_sip_provider_add_origin (self,
|
||||
groups[i],
|
||||
user,
|
||||
password,
|
||||
host,
|
||||
port,
|
||||
|
||||
calls_sip_provider_add_origin (self, groups[i],
|
||||
user, password,
|
||||
host, port, local_port,
|
||||
protocol,
|
||||
direct_connection,
|
||||
auto_connect);
|
||||
|
@ -380,6 +381,7 @@ calls_sip_provider_add_origin (CallsSipProvider *self,
|
|||
const gchar *password,
|
||||
const gchar *host,
|
||||
gint port,
|
||||
gint local_port,
|
||||
const gchar *protocol,
|
||||
gboolean direct_connection,
|
||||
gboolean auto_connect)
|
||||
|
@ -394,6 +396,7 @@ calls_sip_provider_add_origin (CallsSipProvider *self,
|
|||
password,
|
||||
host,
|
||||
port,
|
||||
local_port,
|
||||
protocol,
|
||||
direct_connection,
|
||||
auto_connect);
|
||||
|
|
|
@ -41,6 +41,7 @@ void calls_sip_provider_add_origin (CallsSipProvider *s
|
|||
const gchar *password,
|
||||
const gchar *host,
|
||||
gint port,
|
||||
gint local_port,
|
||||
const gchar *protocol,
|
||||
gboolean direct_connection,
|
||||
gboolean auto_connect);
|
||||
|
|
Loading…
Reference in a new issue