pidgin/pidgin

Make purple_network_get_my_ip_from_gio return non-const.

2019-11-03, Elliott Sales de Andrade
bc2b94f2595a
Parents 0a2d6cf5cbba
Children 3acd6bb854c4
Make purple_network_get_my_ip_from_gio return non-const.
--- a/libpurple/network.c Sat Nov 02 04:03:11 2019 -0400
+++ b/libpurple/network.c Sun Nov 03 16:26:09 2019 -0500
@@ -150,14 +150,12 @@
return "0.0.0.0";
}
-static const char *
+static gchar *
purple_network_get_local_system_ip_from_gio(GSocketConnection *sockconn)
{
GSocketAddress *addr;
GInetSocketAddress *inetsockaddr;
- static char ip[16];
-
- strcpy(ip, "0.0.0.0");
+ gchar *ip;
addr = g_socket_connection_get_local_address(sockconn, NULL);
if ((inetsockaddr = G_INET_SOCKET_ADDRESS(addr)) != NULL) {
@@ -165,14 +163,14 @@
g_inet_socket_address_get_address(inetsockaddr);
if (g_inet_address_get_family(inetaddr) == G_SOCKET_FAMILY_IPV4 &&
!g_inet_address_get_is_loopback(inetaddr)) {
- gchar *tmp = g_inet_address_to_string(inetaddr);
- g_snprintf(ip, 16, "%s", tmp);
- g_free(tmp);
+ ip = g_inet_address_to_string(inetaddr);
+ g_object_unref(addr);
+ return ip;
}
}
g_object_unref(addr);
- return ip;
+ return g_strdup("0.0.0.0");
}
GList *
@@ -311,10 +309,10 @@
return purple_network_get_local_system_ip(fd);
}
-const char *
+gchar *
purple_network_get_my_ip_from_gio(GSocketConnection *sockconn)
{
- const char *ip = NULL;
+ const gchar *ip = NULL;
PurpleStunNatDiscovery *stun;
/* Check if the user specified an IP manually */
@@ -322,25 +320,25 @@
ip = purple_network_get_public_ip();
/* Make sure the IP address entered by the user is valid */
if ((ip != NULL) && (purple_network_is_ipv4(ip))) {
- return ip;
+ return g_strdup(ip);
}
} else {
/* Check if STUN discovery was already done */
stun = purple_stun_discover(NULL);
if ((stun != NULL) && (stun->status == PURPLE_STUN_STATUS_DISCOVERED)) {
- return stun->publicip;
+ return g_strdup(stun->publicip);
}
/* Attempt to get the IP from a NAT device using UPnP */
ip = purple_upnp_get_public_ip();
if (ip != NULL) {
- return ip;
+ return g_strdup(ip);
}
/* Attempt to get the IP from a NAT device using NAT-PMP */
ip = purple_pmp_get_public_ip();
if (ip != NULL) {
- return ip;
+ return g_strdup(ip);
}
}
--- a/libpurple/network.h Sat Nov 02 04:03:11 2019 -0400
+++ b/libpurple/network.h Sun Nov 03 16:26:09 2019 -0500
@@ -126,13 +126,9 @@
* IP address returned by purple_network_get_local_system_ip_from_gio()
* is returned.
*
- * Note: The returned string is a pointer to a static buffer. If this
- * function is called twice, it may be important to make a copy
- * of the returned string.
- *
* Returns: The local IP address to be used.
*/
-const char *purple_network_get_my_ip_from_gio(GSocketConnection *sockconn);
+gchar *purple_network_get_my_ip_from_gio(GSocketConnection *sockconn);
/**
* purple_network_listen:
--- a/libpurple/protocols/jabber/si.c Sat Nov 02 04:03:11 2019 -0400
+++ b/libpurple/protocols/jabber/si.c Sun Nov 03 16:26:09 2019 -0500
@@ -429,7 +429,7 @@
char buffer[42]; /* 40 for DST.ADDR + 2 bytes for port number*/
int len;
char *dstaddr, *hash;
- const char *host;
+ gchar *host;
purple_debug_info("jabber", "in jabber_si_xfer_bytestreams_send_read_again_cb\n");
@@ -528,6 +528,8 @@
jabber_si_xfer_bytestreams_send_read_again_resp_cb, xfer));
jabber_si_xfer_bytestreams_send_read_again_resp_cb(xfer, source,
PURPLE_INPUT_WRITE);
+
+ g_free(host);
}
static void
@@ -858,7 +860,7 @@
gchar *jid;
GList *local_ips =
purple_network_get_all_local_system_ips();
- const char *public_ip;
+ gchar *public_ip;
gboolean has_public_ip = FALSE;
jsx->local_streamhost_fd = sock;
@@ -895,6 +897,7 @@
}
g_free(jid);
+ g_free(public_ip);
/* The listener for the local proxy */
purple_xfer_set_watcher(xfer, purple_input_add(sock, PURPLE_INPUT_READ,