pidgin.vv: 5740223b: Added support to generate relayed candid...
malu at pidgin.im
malu at pidgin.im
Thu Jan 22 18:11:55 EST 2009
-----------------------------------------------------------------
Revision: 5740223b7b01ab4a58b2fb0d8de5f4ab6353ba78
Ancestor: dbdaaaddab537cc355d8d4d4f3de68b2f7d562d0
Author: malu at pidgin.im
Date: 2009-01-22T23:04:52
Branch: im.pidgin.pidgin.vv
URL: http://d.pidgin.im/viewmtn/revision/info/5740223b7b01ab4a58b2fb0d8de5f4ab6353ba78
Modified files:
libpurple/media.c libpurple/network.c libpurple/network.h
pidgin/gtkprefs.c pidgin/gtkprefs.h
ChangeLog:
Added support to generate relayed candidates (TURN).
Added prefs setting for relay server in Pidgin
-------------- next part --------------
============================================================
--- libpurple/media.c 230d96a2a84621cc3ec08eb186108d2e784f25ca
+++ libpurple/media.c 99cf6ccdfc053a9feaef4161563d26f01855f855
@@ -1622,23 +1622,70 @@ purple_media_add_stream_internal(PurpleM
GError *err = NULL;
FsStream *fsstream = NULL;
const gchar *stun_ip = purple_network_get_stun_ip();
+ const gchar *turn_ip = purple_network_get_turn_ip();
-
- if (stun_ip) {
- GParameter *param = g_new0(GParameter, num_params+1);
+ if (stun_ip || turn_ip) {
+ guint new_num_params =
+ stun_ip && turn_ip ? num_params + 2 : num_params + 1;
+ guint next_param_index = num_params;
+ GParameter *param = g_new0(GParameter, new_num_params);
memcpy(param, params, sizeof(GParameter) * num_params);
- purple_debug_info("media",
- "setting property stun-ip on new stream: %s\n", stun_ip);
+ if (stun_ip) {
+ purple_debug_info("media",
+ "setting property stun-ip on new stream: %s\n", stun_ip);
- param[num_params].name = "stun-ip";
- g_value_init(¶m[num_params].value, G_TYPE_STRING);
- g_value_set_string(¶m[num_params].value, stun_ip);
+ param[next_param_index].name = "stun-ip";
+ g_value_init(¶m[next_param_index].value, G_TYPE_STRING);
+ g_value_set_string(¶m[next_param_index].value, stun_ip);
+ next_param_index++;
+ }
+
+ if (turn_ip) {
+ GValueArray *relay_info = g_value_array_new(0);
+ GValue value = {0};
+ gint turn_port =
+ purple_prefs_get_int("/purple/network/turn_port");
+ const gchar *username =
+ purple_prefs_get_string("/purple/network/turn_username");
+ const gchar *password =
+ purple_prefs_get_string("/purple/network/turn_password");
+ GstStructure *turn_setup = gst_structure_new("relay-info",
+ "ip", G_TYPE_STRING, turn_ip,
+ "port", G_TYPE_UINT, turn_port,
+ "username", G_TYPE_STRING, username,
+ "password", G_TYPE_STRING, password,
+ NULL);
+ if (turn_setup) {
+ g_value_init(&value, GST_TYPE_STRUCTURE);
+ gst_value_set_structure(&value, turn_setup);
+ relay_info = g_value_array_append(relay_info, &value);
+ gst_structure_free(turn_setup);
+
+ purple_debug_info("media",
+ "setting property relay-info on new stream\n");
+ param[next_param_index].name = "relay-info";
+ g_value_init(¶m[next_param_index].value,
+ G_TYPE_VALUE_ARRAY);
+ g_value_set_boxed(¶m[next_param_index].value,
+ relay_info);
+ g_value_array_free(relay_info);
+ } else {
+ purple_debug_error("media", "Error relay info");
+ g_object_unref(participant);
+ g_hash_table_remove(media->priv->participants, who);
+ purple_media_remove_session(media, session);
+ g_free(session);
+ return FALSE;
+ }
+
+ }
+
fsstream = fs_session_new_stream(session->session,
participant, type_direction &
FS_DIRECTION_RECV, transmitter,
- num_params+1, param, &err);
+ new_num_params, param, &err);
g_free(param);
} else {
fsstream = fs_session_new_stream(session->session,
============================================================
--- libpurple/network.c 63ec98a8d7e5fbcc1031d2b07acf8bd365946f9a
+++ libpurple/network.c 717ca0e2cc94afe0a0312fc689d86da48f8eb29c
@@ -93,8 +93,9 @@ static NMState nm_get_network_state(void
static NMState nm_get_network_state(void);
#endif
-/* Cached IP address for STUN server */
+/* Cached IP addresses for STUN and TURN servers (set globally in prefs) */
static gchar *stun_ip = NULL;
+static gchar *turn_ip = NULL;
const unsigned char *
purple_network_ip_atoi(const char *ip)
@@ -694,6 +695,8 @@ nm_update_state(NMState state)
offline */
purple_network_set_stun_server(
purple_prefs_get_string("/purple/network/stun_server"));
+ purple_network_set_turn_server(
+ purple_prefs_get_string("/purple/network/turn_server"));
if (ui_ops != NULL && ui_ops->network_connected != NULL)
ui_ops->network_connected();
@@ -757,11 +760,13 @@ static void
#endif
static void
-purple_network_stun_lookup_cb(GSList *hosts, gpointer data,
+purple_network_ip_lookup_cb(GSList *hosts, gpointer data,
const char *error_message)
{
+ const gchar **ip = (const gchar **) data;
+
if (error_message) {
- purple_debug_error("network", "lookup of STUN server IP failed: %s\n",
+ purple_debug_error("network", "lookup of IP address failed: %s\n",
error_message);
g_slist_free(hosts);
return;
@@ -780,8 +785,8 @@ purple_network_stun_lookup_cb(GSList *ho
dst, sizeof(dst));
}
- stun_ip = g_strdup(dst);
- purple_debug_info("network", "set STUN IP: %s\n", stun_ip);
+ *ip = g_strdup(dst);
+ purple_debug_info("network", "set IP address: %s\n", *ip);
}
g_slist_free(hosts);
@@ -793,8 +798,8 @@ purple_network_set_stun_server(const gch
if (stun_server && stun_server[0] != '\0') {
if (purple_network_is_available()) {
purple_debug_info("network", "running DNS query for STUN server\n");
- purple_dnsquery_a(stun_server, 3478, purple_network_stun_lookup_cb,
- NULL);
+ purple_dnsquery_a(stun_server, 3478, purple_network_ip_lookup_cb,
+ &stun_ip);
} else {
purple_debug_info("network",
"network is unavailable, don't try to update STUN IP");
@@ -805,12 +810,38 @@ purple_network_set_stun_server(const gch
}
}
+void
+purple_network_set_turn_server(const gchar *turn_server)
+{
+ if (turn_server && turn_server[0] != '\0') {
+ if (purple_network_is_available()) {
+ purple_debug_info("network", "running DNS query for TURN server\n");
+ purple_dnsquery_a(turn_server,
+ purple_prefs_get_int("/purple/network/turn_port"),
+ purple_network_ip_lookup_cb, &turn_ip);
+ } else {
+ purple_debug_info("network",
+ "network is unavailable, don't try to update TURN IP");
+ }
+ } else if (turn_ip) {
+ g_free(turn_ip);
+ turn_ip = NULL;
+ }
+}
+
+
const gchar *
purple_network_get_stun_ip(void)
{
return stun_ip;
}
+const gchar *
+purple_network_get_turn_ip(void)
+{
+ return turn_ip;
+}
+
void *
purple_network_get_handle(void)
{
@@ -843,6 +874,10 @@ purple_network_init(void)
purple_prefs_add_none ("/purple/network");
purple_prefs_add_string("/purple/network/stun_server", "");
+ purple_prefs_add_string("/purple/network/turn_server", "");
+ purple_prefs_add_int ("/purple/network/turn_port", 3478);
+ purple_prefs_add_string("/purple/network/turn_username", "");
+ purple_prefs_add_string("/purple/network/turn_password", "");
purple_prefs_add_bool ("/purple/network/auto_ip", TRUE);
purple_prefs_add_string("/purple/network/public_ip", "");
purple_prefs_add_bool ("/purple/network/map_ports", TRUE);
@@ -884,6 +919,8 @@ purple_network_init(void)
purple_network_set_stun_server(
purple_prefs_get_string("/purple/network/stun_server"));
+ purple_network_set_turn_server(
+ purple_prefs_get_string("/purple/network/turn_server"));
}
void
============================================================
--- libpurple/network.h 1946d83757ae2f4c622fef1482b5901f924b5971
+++ libpurple/network.h ae1c38514de10c51279501e2109a264d69cdd2a5
@@ -215,7 +215,7 @@ void *purple_network_get_handle(void);
void *purple_network_get_handle(void);
/**
- * Update the STUN server name
+ * Update the STUN server IP given the host name
* Will result in a DNS query being executed asynchronous
*
* @param stun_server The host name of the STUN server to set
@@ -229,7 +229,23 @@ const gchar *purple_network_get_stun_ip(
*/
const gchar *purple_network_get_stun_ip(void);
+/**
+ * Update the TURN server IP given the host name
+ * Will result in a DNS query being executed asynchronous
+ *
+ * @param stun_server The host name of the STUN server to set
+ */
+void purple_network_set_turn_server(const gchar *stun_server);
+
/**
+ * Get the IP address of the STUN server as a string representation
+ *
+ * @return the IP address
+ */
+const gchar *purple_network_get_turn_ip(void);
+
+
+/**
* Initializes the network subsystem.
*/
void purple_network_init(void);
============================================================
--- pidgin/gtkprefs.c 1a6dd0515df8adabd4578ce5c7260b93ff4fa9ac
+++ pidgin/gtkprefs.c 2da82c7c0272830a497ea3782919ef851ca850b1
@@ -137,6 +137,26 @@ pidgin_prefs_labeled_entry(GtkWidget *pa
return pidgin_add_widget_to_vbox(GTK_BOX(page), title, sg, entry, TRUE, NULL);
}
+GtkWidget *
+pidgin_prefs_labeled_password(GtkWidget *page, const gchar *title,
+ const char *key, GtkSizeGroup *sg)
+{
+ GtkWidget *entry;
+ const gchar *value;
+
+ value = purple_prefs_get_string(key);
+
+ entry = gtk_entry_new();
+ gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
+ gtk_entry_set_text(GTK_ENTRY(entry), value);
+ g_signal_connect(G_OBJECT(entry), "changed",
+ G_CALLBACK(entry_set), (char*)key);
+ gtk_widget_show(entry);
+
+ return pidgin_add_widget_to_vbox(GTK_BOX(page), title, sg, entry, TRUE, NULL);
+}
+
+
static void
dropdown_set(GObject *w, const char *key)
{
@@ -1153,6 +1173,17 @@ static gboolean network_stun_server_chan
return FALSE;
}
+static gboolean network_turn_server_changed_cb(GtkWidget *widget,
+ GdkEventFocus *event, gpointer data)
+{
+ GtkEntry *entry = GTK_ENTRY(widget);
+ purple_prefs_set_string("/purple/network/turn_server",
+ gtk_entry_get_text(entry));
+ purple_network_set_turn_server(gtk_entry_get_text(entry));
+
+ return FALSE;
+}
+
static void
proxy_changed_cb(const char *name, PurplePrefType type,
gconstpointer value, gpointer data)
@@ -1314,6 +1345,43 @@ network_page(void)
g_signal_connect(G_OBJECT(ports_checkbox), "clicked",
G_CALLBACK(pidgin_toggle_sensitive), spin_button);
+ vbox = pidgin_make_frame(ret, _("Relay Server (TURN)"));
+
+ /* TURN server */
+ hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BOX_SPACE);
+ sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+ label = gtk_label_new_with_mnemonic(_("_Server:"));
+ gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
+ gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
+
+ entry = gtk_entry_new();
+ gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry);
+ g_signal_connect(G_OBJECT(entry), "focus-out-event",
+ G_CALLBACK(network_turn_server_changed_cb), NULL);
+ gtk_entry_set_text(GTK_ENTRY(entry),
+ purple_prefs_get_string("/purple/network/turn_server"));
+ gtk_misc_set_alignment(GTK_MISC(entry), 0, 0.5);
+ gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0);
+
+ gtk_size_group_add_widget(GTK_SIZE_GROUP(sg), label);
+ gtk_size_group_add_widget(GTK_SIZE_GROUP(sg), entry);
+
+ sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+ spin_button = pidgin_prefs_labeled_spin_button(hbox, _("_Port:"),
+ "/purple/network/turn_port", 0, 65535, sg);
+ gtk_container_add(GTK_CONTAINER(vbox), hbox);
+
+ hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BOX_SPACE);
+ sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+ entry = pidgin_prefs_labeled_entry(hbox, "_User name:",
+ "/purple/network/turn_username", sg);
+
+ sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+ entry = pidgin_prefs_labeled_password(hbox, "_Password:",
+ "/purple/network/turn_password", sg);
+ gtk_container_add(GTK_CONTAINER(vbox), hbox);
+
+
if (purple_running_gnome()) {
vbox = pidgin_make_frame(ret, _("Proxy Server & Browser"));
prefs_proxy_frame = gtk_vbox_new(FALSE, 0);
============================================================
--- pidgin/gtkprefs.h 8c8cb77cb9834b0f2457d0133fd9b9a4f1043916
+++ pidgin/gtkprefs.h c5fa09270c711c748507fba2400b62735b3581c1
@@ -82,6 +82,22 @@ GtkWidget *pidgin_prefs_labeled_entry(Gt
const char *key, GtkSizeGroup *sg);
/**
+ * Add a new entry representing a password (string) preference
+ * The entry will use a password-style text entry (the text is substituded)
+ *
+ * @param page The page to which the entry will be added
+ * @param title The text to be displayed as the entry label
+ * @param key The key of the string pref that will be represented by the entry
+ * @param sg If not NULL, the size group to which the entry will be added
+ *
+ * @return An hbox containing both the label and the entry. Can be used to set
+ * the widgets to sensitive or insensitive based on the value of a
+ * checkbox.
+ */
+GtkWidget *pidgin_prefs_labeled_password(GtkWidget *page, const gchar *title,
+ const char *key, GtkSizeGroup *sg);
+
+/**
* Add a new dropdown representing a preference of the specified type
*
* @param page The page to which the dropdown will be added
More information about the Commits
mailing list