summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Zabaluev <mikhail.zabaluev@nokia.com>2011-02-14 18:13:28 +0200
committerMikhail Zabaluev <mikhail.zabaluev@nokia.com>2011-02-14 18:13:28 +0200
commitf772fd727eb15fe90f4ae298c4f1dfbfa82b7445 (patch)
tree950c11045f4a9b1b7342994cd7e5109dd37be264
parentcfebf09323a44f2bc892f5eb48905466a2325afc (diff)
Smarter behavior of connection parameters 'discover-stun' and 'stun-server'
'discover-stun' is no longer ignored if 'stun-server' is set. If 'discover-stun' is set to true, 'stun-server' is now ignored. If 'discover-stun' is not set, 'stun-server' is used if that is set, otherwise 'discover-stun' defaults to true. Fixes: fd.o #34227
-rw-r--r--src/sip-connection-manager.c45
-rw-r--r--src/sip-connection.c6
2 files changed, 39 insertions, 12 deletions
diff --git a/src/sip-connection-manager.c b/src/sip-connection-manager.c
index 7a33481..80e6adc 100644
--- a/src/sip-connection-manager.c
+++ b/src/sip-connection-manager.c
@@ -171,9 +171,10 @@ static const TpCMParamSpec tpsip_params[] = {
{ "keepalive-interval", DBUS_TYPE_UINT32_AS_STRING, G_TYPE_UINT,
TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT, GUINT_TO_POINTER(0),
G_STRUCT_OFFSET (TpsipConnParams, keepalive_interval) },
- /* Use SRV DNS lookup to discover STUN server */
+ /* Use SRV DNS lookup to discover STUN server
+ * (defaults to true unless stun-server is set) */
{ "discover-stun", DBUS_TYPE_BOOLEAN_AS_STRING, G_TYPE_BOOLEAN,
- TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT, GUINT_TO_POINTER(TRUE),
+ 0, NULL,
G_STRUCT_OFFSET (TpsipConnParams, discover_stun) },
/* STUN server */
{ "stun-server", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING,
@@ -417,6 +418,7 @@ tpsip_connection_manager_new_connection (TpBaseConnectionManager *base,
TpsipConnParams *params = (TpsipConnParams *)parsed_params;
gchar *proxy = NULL;
TpsipConnectionKeepaliveMechanism keepalive_mechanism;
+ gboolean have_stun_server;
if (strcmp (proto, "sip")) {
g_set_error (error, TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED,
@@ -493,14 +495,39 @@ tpsip_connection_manager_new_connection (TpBaseConnectionManager *base,
SET_PROPERTY_IF_PARAM_SET ("discover-binding", TPSIP_CONN_PARAM_DISCOVER_BINDING,
params->discover_binding);
- SET_PROPERTY_IF_PARAM_SET ("discover-stun", TPSIP_CONN_PARAM_DISCOVER_STUN,
- params->discover_stun);
-
- SET_PROPERTY_IF_PARAM_SET ("stun-server", TPSIP_CONN_PARAM_STUN_SERVER,
- params->stun_server);
+ have_stun_server = tp_intset_is_member (params_present,
+ TPSIP_CONN_PARAM_STUN_SERVER);
+ if (tp_intset_is_member (params_present, TPSIP_CONN_PARAM_DISCOVER_STUN))
+ {
+ /* 'discover-stun' given, if false regard the STUN server */
+ g_object_set (connection, "discover-stun", params->discover_stun, NULL);
+
+ if (!params->discover_stun && have_stun_server)
+ {
+ g_object_set (connection,
+ "stun-server", params->stun_server,
+ NULL);
+ }
+ }
+ else if (have_stun_server)
+ {
+ /* 'discover-stun' not specified, STUN server given -> no discovery */
+ g_object_set (connection,
+ "discover-stun", FALSE,
+ "stun-server", params->stun_server,
+ NULL);
+ }
+ else
+ {
+ /* 'discover-stun' not specified, no STUN server -> default to true */
+ g_object_set (connection, "discover-stun", TRUE, NULL);
+ }
- SET_PROPERTY_IF_PARAM_SET ("stun-port", TPSIP_CONN_PARAM_STUN_PORT,
- params->stun_port);
+ if (have_stun_server)
+ {
+ SET_PROPERTY_IF_PARAM_SET ("stun-port", TPSIP_CONN_PARAM_STUN_PORT,
+ params->stun_port);
+ }
SET_PROPERTY_IF_PARAM_SET ("immutable-streams", TPSIP_CONN_PARAM_IMMUTABLE_STREAMS,
params->immutable_streams);
diff --git a/src/sip-connection.c b/src/sip-connection.c
index 2218dfd..b1d674d 100644
--- a/src/sip-connection.c
+++ b/src/sip-connection.c
@@ -943,10 +943,10 @@ tpsip_connection_start_connecting (TpBaseConnection *base,
tpsip_conn_update_nua_keepalive_interval (self);
tpsip_conn_update_nua_contact_features (self);
- if (priv->stun_host != NULL)
- tpsip_conn_resolv_stun_server (self, priv->stun_host);
- else if (priv->discover_stun)
+ if (priv->discover_stun)
tpsip_conn_discover_stun_server (self);
+ else if (priv->stun_host != NULL)
+ tpsip_conn_resolv_stun_server (self, priv->stun_host);
DEBUG("initialized a Sofia-SIP NUA at address %p", priv->sofia_nua);