From 23ce20908bb775edc9b51a9246a1d0806167743d Mon Sep 17 00:00:00 2001 From: Fabrice Bellet Date: Wed, 13 Jan 2016 15:20:09 +0100 Subject: [PATCH] wocky-jingle-info: use relay information from environment variables We fallback to relay information from environment variables when not using jingle google transport: WOCKY_TURN_USERNAME WOCKY_TURN_PASSWORD WOCKY_TURN_SERVER WOCKY_TURN_UDP_PORT --- wocky/wocky-jingle-info.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++ wocky/wocky-jingle-info.h | 5 ++++ 2 files changed, 66 insertions(+) diff --git a/wocky/wocky-jingle-info.c b/wocky/wocky-jingle-info.c index 94b189e..4f68a0d 100644 --- a/wocky/wocky-jingle-info.c +++ b/wocky/wocky-jingle-info.c @@ -728,3 +728,64 @@ wocky_jingle_info_create_google_relay_session ( components, priv->relay_server, priv->relay_http_port, priv->relay_token, callback, user_data); } + +void +wocky_jingle_info_create_relay_session ( + WockyJingleInfo *self, + guint components, + WockyJingleInfoRelaySessionCb callback, + gpointer user_data) +{ + GPtrArray *relays = g_ptr_array_sized_new (components); + const gchar *relay_ip = g_getenv ("WOCKY_TURN_SERVER"); + const gchar *relay_udp_port = g_getenv ("WOCKY_TURN_UDP_PORT"); + const gchar *username = g_getenv ("WOCKY_TURN_USERNAME"); + const gchar *password = g_getenv ("WOCKY_TURN_PASSWORD"); + guint i; + guint64 portll; + guint port; + + if (relay_ip == NULL) + { + DEBUG ("No relay.ip found"); + return; + } + else if (relay_udp_port == NULL) + { + DEBUG ("No relay port found"); + return; + } + else if (username == NULL) + { + DEBUG ("No username found"); + return; + } + else if (password == NULL) + { + DEBUG ("No password found"); + return; + } + else + { + portll = g_ascii_strtoull (relay_udp_port, NULL, 10); + + if (portll == 0 || portll > G_MAXUINT16) + { + DEBUG ("failed to parse relay port '%s' for %u", relay_udp_port, + WOCKY_JINGLE_RELAY_TYPE_UDP); + return; + } + port = (guint) portll; + + for (i = 0; i < components; i++) { + DEBUG ("type=%u ip=%s port=%u username=%s password=%s component=%u", + WOCKY_JINGLE_RELAY_TYPE_UDP, relay_ip, port, username, password, + i + 1); + g_ptr_array_add (relays, + wocky_jingle_relay_new (WOCKY_JINGLE_RELAY_TYPE_UDP, + relay_ip, port, username, password, i + 1)); + } + callback (relays, user_data); + return; + } +} diff --git a/wocky/wocky-jingle-info.h b/wocky/wocky-jingle-info.h index 41d2e21..6fc0260 100644 --- a/wocky/wocky-jingle-info.h +++ b/wocky/wocky-jingle-info.h @@ -102,6 +102,11 @@ void wocky_jingle_info_create_google_relay_session ( guint components, WockyJingleInfoRelaySessionCb callback, gpointer user_data); +void wocky_jingle_info_create_relay_session ( + WockyJingleInfo *self, + guint components, + WockyJingleInfoRelaySessionCb callback, + gpointer user_data); void wocky_jingle_info_set_test_mode (void); -- 2.5.0