comparison libpurple/media.c @ 26050:ae3d25465d0f

Run an asynchronous DNS lookup for the STUN server IP (to set as a property to the nice transmitter for media). Also update the IP when the preference changes and when NetworkManager support is present, when NM reports connected. TODO: add code to run DNS lookup on Win32 when the network connection is ready
author Marcus Lundblad <ml@update.uu.se>
date Sat, 17 Jan 2009 01:38:44 +0000
parents f09107a80608
children b68a88fb7458
comparison
equal deleted inserted replaced
26049:6eeb500ce9a2 26050:ae3d25465d0f
30 30
31 #include "connection.h" 31 #include "connection.h"
32 #include "media.h" 32 #include "media.h"
33 #include "marshallers.h" 33 #include "marshallers.h"
34 #include "mediamanager.h" 34 #include "mediamanager.h"
35 #include "network.h"
35 36
36 #include "debug.h" 37 #include "debug.h"
37 38
38 #ifdef USE_VV 39 #ifdef USE_VV
39 40
1547 gst_element_set_state(stream->sink, GST_STATE_PLAYING); 1548 gst_element_set_state(stream->sink, GST_STATE_PLAYING);
1548 1549
1549 g_timeout_add(0, (GSourceFunc)purple_media_connected_cb, stream); 1550 g_timeout_add(0, (GSourceFunc)purple_media_connected_cb, stream);
1550 } 1551 }
1551 1552
1552 static gchar *
1553 purple_media_get_stun_pref_ip()
1554 {
1555 const gchar *stun_pref =
1556 purple_prefs_get_string("/purple/network/stun_server");
1557 struct hostent *host;
1558
1559 if ((host = gethostbyname(stun_pref)) && host->h_addr) {
1560 gchar *stun_ip = g_strdup_printf("%hhu.%hhu.%hhu.%hhu",
1561 host->h_addr[0], host->h_addr[1],
1562 host->h_addr[2], host->h_addr[3]);
1563 purple_debug_info("media", "IP address for %s found: %s\n",
1564 stun_pref, stun_ip);
1565 return stun_ip;
1566 } else {
1567 purple_debug_info("media", "Unable to resolve %s IP address\n",
1568 stun_pref);
1569 return NULL;
1570 }
1571 }
1572
1573 static gboolean 1553 static gboolean
1574 purple_media_add_stream_internal(PurpleMedia *media, const gchar *sess_id, 1554 purple_media_add_stream_internal(PurpleMedia *media, const gchar *sess_id,
1575 const gchar *who, FsMediaType type, 1555 const gchar *who, FsMediaType type,
1576 FsStreamDirection type_direction, 1556 FsStreamDirection type_direction,
1577 const gchar *transmitter, 1557 const gchar *transmitter,
1651 1631
1652 stream = purple_media_get_stream(media, sess_id, who); 1632 stream = purple_media_get_stream(media, sess_id, who);
1653 1633
1654 if (!stream) { 1634 if (!stream) {
1655 GError *err = NULL; 1635 GError *err = NULL;
1656 gchar *stun_ip = NULL;
1657 FsStream *fsstream = NULL; 1636 FsStream *fsstream = NULL;
1658 1637 const gchar *stun_ip = purple_network_get_stun_ip();
1659 if ((stun_ip = purple_media_get_stun_pref_ip())) { 1638
1639
1640 if (stun_ip) {
1660 GParameter *param = g_new0(GParameter, num_params+1); 1641 GParameter *param = g_new0(GParameter, num_params+1);
1661 memcpy(param, params, sizeof(GParameter) * num_params); 1642 memcpy(param, params, sizeof(GParameter) * num_params);
1662 1643
1644 purple_debug_info("media",
1645 "setting property stun-ip on new stream: %s\n", stun_ip);
1646
1663 param[num_params].name = "stun-ip"; 1647 param[num_params].name = "stun-ip";
1664 g_value_init(&param[num_params].value, G_TYPE_STRING); 1648 g_value_init(&param[num_params].value, G_TYPE_STRING);
1665 g_value_take_string(&param[num_params].value, stun_ip); 1649 g_value_set_string(&param[num_params].value, stun_ip);
1666 1650
1667 fsstream = fs_session_new_stream(session->session, 1651 fsstream = fs_session_new_stream(session->session,
1668 participant, type_direction, 1652 participant, type_direction,
1669 transmitter, num_params+1, param, &err); 1653 transmitter, num_params+1, param, &err);
1670 g_free(param); 1654 g_free(param);
1671 g_free(stun_ip);
1672 } else { 1655 } else {
1673 fsstream = fs_session_new_stream(session->session, 1656 fsstream = fs_session_new_stream(session->session,
1674 participant, type_direction, 1657 participant, type_direction,
1675 transmitter, num_params, params, &err); 1658 transmitter, num_params, params, &err);
1676 } 1659 }