/pidgin/main: 7e3ea8475aad: Get rid of useless form of purple_ne...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Wed Apr 17 12:56:12 EDT 2013


Changeset: 7e3ea8475aadbad42291395db80769325fce47a5
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-04-17 18:56 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/7e3ea8475aad

Description:

Get rid of useless form of purple_network_ip_atoi

diffstat:

 ChangeLog.API                            |   1 +
 libpurple/network.c                      |  42 ++++++++++++++-----------------
 libpurple/network.h                      |  14 ----------
 libpurple/plugins/perl/common/Network.xs |   4 ---
 libpurple/protocols/oscar/peer.c         |  38 +++++++++++++++++++++++++++-
 5 files changed, 56 insertions(+), 43 deletions(-)

diffs (175 lines):

diff --git a/ChangeLog.API b/ChangeLog.API
--- a/ChangeLog.API
+++ b/ChangeLog.API
@@ -196,6 +196,7 @@ version 3.0.0 (??/??/????):
 		* purple_network_listen_map_external
 		* purple_network_listen_range_family. Use purple_network_listen,
 		  instead.
+		* purple_network_ip_atoi
 		* purple_notify_searchresults_column_get_title
 		* purple_notify_searchresults_get_columns_count
 		* purple_notify_searchresults_get_rows_count
diff --git a/libpurple/network.c b/libpurple/network.c
--- a/libpurple/network.c
+++ b/libpurple/network.c
@@ -121,28 +121,6 @@ static gchar *turn_ip = NULL;
 static GHashTable *upnp_port_mappings = NULL;
 static GHashTable *nat_pmp_port_mappings = NULL;
 
-const unsigned char *
-purple_network_ip_atoi(const char *ip)
-{
-	static unsigned char ret[4];
-	gchar *delimiter = ".";
-	gchar **split;
-	int i;
-
-	g_return_val_if_fail(ip != NULL, NULL);
-
-	split = g_strsplit(ip, delimiter, 4);
-	for (i = 0; split[i] != NULL; i++)
-		ret[i] = atoi(split[i]);
-	g_strfreev(split);
-
-	/* i should always be 4 */
-	if (i != 4)
-		return NULL;
-
-	return ret;
-}
-
 void
 purple_network_set_public_ip(const char *ip)
 {
@@ -287,6 +265,24 @@ purple_network_get_all_local_system_ips(
 #endif /* HAVE_GETIFADDRS && HAVE_INET_NTOP */
 }
 
+/**
+ * Checks, if specified hostname is valid ipv4 address.
+ *
+ * @param hostname The hostname to be verified.
+ * @return TRUE, if the hostname is valid.
+ */
+static gboolean
+purple_network_is_ipv4(const gchar *hostname)
+{
+	g_return_val_if_fail(hostname != NULL, FALSE);
+
+	/* We don't accept ipv6 here. */
+	if (strchr(hostname, ':') != NULL)
+		return FALSE;
+
+	return g_hostname_is_ip_address(hostname);
+}
+
 const char *
 purple_network_get_my_ip(int fd)
 {
@@ -297,7 +293,7 @@ purple_network_get_my_ip(int fd)
 	if (!purple_prefs_get_bool("/purple/network/auto_ip")) {
 		ip = purple_network_get_public_ip();
 		/* Make sure the IP address entered by the user is valid */
-		if ((ip != NULL) && (purple_network_ip_atoi(ip) != NULL))
+		if ((ip != NULL) && (purple_network_is_ipv4(ip)))
 			return ip;
 	} else {
 		/* Check if STUN discovery was already done */
diff --git a/libpurple/network.h b/libpurple/network.h
--- a/libpurple/network.h
+++ b/libpurple/network.h
@@ -40,20 +40,6 @@ typedef struct _PurpleNetworkListenData 
 typedef void (*PurpleNetworkListenCallback) (int listenfd, gpointer data);
 
 /**
- * Converts a dot-decimal IP address to an array of unsigned
- * chars.  For example, converts 192.168.0.1 to a 4 byte
- * array containing 192, 168, 0 and 1.
- *
- * @param ip An IP address in dot-decimal notiation.
- * @return An array of 4 bytes containing an IP addresses
- *         equivalent to the given parameter, or NULL if
- *         the given IP address is invalid.  This value
- *         is statically allocated and should not be
- *         freed.
- */
-const unsigned char *purple_network_ip_atoi(const char *ip);
-
-/**
  * Sets the IP address of the local system in preferences.  This
  * is the IP address that should be used for incoming connections
  * (file transfer, direct IM, etc.) and should therefore be
diff --git a/libpurple/plugins/perl/common/Network.xs b/libpurple/plugins/perl/common/Network.xs
--- a/libpurple/plugins/perl/common/Network.xs
+++ b/libpurple/plugins/perl/common/Network.xs
@@ -18,10 +18,6 @@ purple_network_get_port_from_fd(fd)
 const char *
 purple_network_get_public_ip()
 
-const unsigned char *
-purple_network_ip_atoi(ip)
-	const char *ip
-
 Purple::NetworkListenData
 purple_network_listen(port, socket_family, socket_type, map_external, cb, cb_data)
 	unsigned short port
diff --git a/libpurple/protocols/oscar/peer.c b/libpurple/protocols/oscar/peer.c
--- a/libpurple/protocols/oscar/peer.c
+++ b/libpurple/protocols/oscar/peer.c
@@ -642,6 +642,40 @@ peer_connection_listen_cb(gpointer data,
 }
 
 /**
+ * Converts a dot-decimal IP address to an array of unsigned
+ * chars.  For example, converts 192.168.0.1 to a 4 byte
+ * array containing 192, 168, 0 and 1.
+ *
+ * @param ip An IP address in dot-decimal notiation.
+ * @return An array of 4 bytes containing an IP addresses
+ *         equivalent to the given parameter, or NULL if
+ *         the given IP address is invalid.  This value
+ *         is statically allocated and should not be
+ *         freed.
+ */
+static const unsigned char *
+peer_ip_atoi(const char *ip)
+{
+	static unsigned char ret[4];
+	gchar *delimiter = ".";
+	gchar **split;
+	int i;
+
+	g_return_val_if_fail(ip != NULL, NULL);
+
+	split = g_strsplit(ip, delimiter, 4);
+	for (i = 0; split[i] != NULL; i++)
+		ret[i] = atoi(split[i]);
+	g_strfreev(split);
+
+	/* i should always be 4 */
+	if (i != 4)
+		return NULL;
+
+	return ret;
+}
+
+/**
  * We've just opened a listener socket, so we send the remote
  * user an ICBM and ask them to connect to us.
  */
@@ -692,13 +726,13 @@ peer_connection_establish_listener_cb(in
 	else
 		listener_ip = purple_network_get_my_ip(bos_conn->fd);
 
-	ip_atoi = purple_network_ip_atoi(listener_ip);
+	ip_atoi = peer_ip_atoi(listener_ip);
 	if (ip_atoi == NULL) {
 		/* Could not convert IP to 4 byte array--weird, but this does
 		   happen for some users (#4829, Adium #15839).  Maybe they're
 		   connecting with IPv6...?  Maybe through a proxy? */
 		purple_debug_error("oscar", "Can't ask peer to connect to us "
-				"because purple_network_ip_atoi(%s) returned NULL. "
+				"because peer_ip_atoi(%s) returned NULL. "
 				"fd=%d. is_ssl=%d\n",
 				listener_ip ? listener_ip : "(null)",
 				bos_conn->gsc ? bos_conn->gsc->fd : bos_conn->fd,



More information about the Commits mailing list