pidgin: 9bc55bda: Add purple_ipv6_address_is_valid; guess ...
darkrain42 at pidgin.im
darkrain42 at pidgin.im
Sat Jul 11 03:50:22 EDT 2009
-----------------------------------------------------------------
Revision: 9bc55bda447e59bff67f0dbfd1b01348cb78f5ee
Ancestor: 44c590b1181e9696060cd9841854cfc0ad43ab8f
Author: darkrain42 at pidgin.im
Date: 2009-07-11T07:32:27
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/9bc55bda447e59bff67f0dbfd1b01348cb78f5ee
Modified files:
ChangeLog.API libpurple/tests/test_util.c libpurple/util.c
libpurple/util.h
ChangeLog:
Add purple_ipv6_address_is_valid; guess what it does?
-------------- next part --------------
============================================================
--- ChangeLog.API cbca419293b3d27756518fd4b559e0544ca11671
+++ ChangeLog.API e4dc3d0a702ea0a60c87f31f107eb70e50d40fc9
@@ -37,6 +37,8 @@ version 2.6.0 (??/??/2009):
* purple_debug_set_verbose
* purple_global_proxy_set_info
* purple_group_destroy
+ * purple_ipv4_address_is_valid
+ * purple_ipv6_address_is_valid
* purple_log_get_activity_score
* purple_markup_is_rtl
* purple_markup_escape_text
@@ -82,6 +84,7 @@ version 2.6.0 (??/??/2009):
* buddy-added and buddy-removed blist signals
* purple_buddy_get_local_alias
* purple_notify_user_info_remove_entry
+ * purple_ip_address_is_valid
* purple_status_type_set_primary_attr
* purple_status_type_add_attr
* purple_status_type_add_attrs
============================================================
--- libpurple/tests/test_util.c 7fdae89fabada1aa7d1304d2bea5eb9d392db094
+++ libpurple/tests/test_util.c 82dde90a04c833705fa85b4570a6d870f57eeaa3
@@ -80,6 +80,25 @@ END_TEST
}
END_TEST
+START_TEST(test_util_ipv6_is_valid)
+{
+ fail_unless(purple_ipv6_address_is_valid("2001:0db8:85a3:0000:0000:8a2e:0370:7334"));
+ fail_unless(purple_ipv6_address_is_valid("2001:db8:85a3:0:0:8a2e:370:7334"));
+ fail_unless(purple_ipv6_address_is_valid("2001:db8:85a3::8a2e:370:7334"));
+ fail_unless(purple_ipv6_address_is_valid("2001:0db8:0:0::1428:57ab"));
+ fail_unless(purple_ipv6_address_is_valid("::1"));
+ fail_unless(purple_ipv6_address_is_valid("1::"));
+ fail_unless(purple_ipv6_address_is_valid("1::1"));
+ fail_unless(purple_ipv6_address_is_valid("::"));
+ fail_if(purple_ipv6_address_is_valid(""));
+ fail_if(purple_ipv6_address_is_valid(":"));
+ fail_if(purple_ipv6_address_is_valid("1.2.3.4"));
+ fail_if(purple_ipv6_address_is_valid("2001::FFD3::57ab"));
+ fail_if(purple_ipv6_address_is_valid("200000000::1"));
+ fail_if(purple_ipv6_address_is_valid("QWERTY::1"));
+}
+END_TEST
+
START_TEST(test_util_str_to_time)
{
fail_unless(377182200 == purple_str_to_time("19811214T12:50:00", TRUE, NULL, NULL, NULL));
@@ -132,6 +151,10 @@ util_suite(void)
tcase_add_test(tc, test_util_email_is_valid);
suite_add_tcase(s, tc);
+ tc = tcase_create("IPv6");
+ tcase_add_test(tc, test_util_ipv6_is_valid);
+ suite_add_tcase(s, tc);
+
tc = tcase_create("Time");
tcase_add_test(tc, test_util_str_to_time);
suite_add_tcase(s, tc);
============================================================
--- libpurple/util.c e57a49e4a8e9a280210227b4f6acf94b4d73a1cd
+++ libpurple/util.c 54c997de15ae828078b7a84bd07f74204b49e823
@@ -4446,6 +4446,7 @@ purple_email_is_valid(const char *addres
return ((c - domain) > 3 ? TRUE : FALSE);
}
+/* TODO 3.0.0: Rename this to purple_ipv4_address_is_valid */
gboolean
purple_ip_address_is_valid(const char *ip)
{
@@ -4460,6 +4461,51 @@ purple_ip_address_is_valid(const char *i
return TRUE;
}
+gboolean
+purple_ipv6_address_is_valid(const gchar *ip)
+{
+ const gchar *c;
+ gboolean double_colon = FALSE;
+ gint chunks = 1;
+ gint in = 0;
+
+ g_return_val_if_fail(ip != NULL, FALSE);
+
+ if (*ip == '\0')
+ return FALSE;
+
+ for (c = ip; *c; ++c) {
+ if ((*c >= '0' && *c <= '9') ||
+ (*c >= 'a' && *c <= 'f') ||
+ (*c >= 'A' && *c <= 'F')) {
+ if (++in > 4)
+ /* Only four hex digits per chunk */
+ return FALSE;
+ continue;
+ } else if (*c == ':') {
+ /* The start of a new chunk */
+ ++chunks;
+ in = 0;
+ if (*(c + 1) == ':') {
+ /*
+ * '::' indicates a consecutive series of chunks full
+ * of zeroes. There can be only one of these per address.
+ */
+ if (double_colon)
+ return FALSE;
+ double_colon = TRUE;
+ }
+ } else
+ return FALSE;
+ }
+
+ /*
+ * Either we saw a '::' and there were fewer than 8 chunks -or-
+ * we didn't see a '::' and saw exactly 8 chunks.
+ */
+ return (double_colon && chunks < 8) || (!double_colon && chunks == 8);
+}
+
/* Stolen from gnome_uri_list_extract_uris */
GList *
purple_uri_list_extract_uris(const gchar *uri_list)
============================================================
--- libpurple/util.h eddc855c19a4af8ba460f76e2042aef97c1df57a
+++ libpurple/util.h 15314a02d4888bf6c4fffdbfc4b79989a276b84e
@@ -1203,10 +1203,33 @@ gboolean purple_email_is_valid(const cha
* @param ip The IP address to validate.
*
* @return True if the IP address is syntactically correct.
+ * @deprecated This function will be replaced with one that validates
+ * as either IPv4 or IPv6 in 3.0.0. If you don't want this,
+ * behavior, use one of the more specific functions.
*/
gboolean purple_ip_address_is_valid(const char *ip);
/**
+ * Checks if the given IP address is a syntactically valid IPv4 address.
+ *
+ * @param ip The IP address to validate.
+ *
+ * @return True if the IP address is syntactically correct.
+ * @since 2.6.0
+ */
+gboolean purple_ipv4_address_is_valid(const char *ip);
+
+/**
+ * Checks if the given IP address is a syntactically valid IPv6 address.
+ *
+ * @param ip The IP address to validate.
+ *
+ * @return True if the IP address is syntactically correct.
+ * @since 2.6.0
+ */
+gboolean purple_ipv6_address_is_valid(const char *ip);
+
+/**
* This function extracts a list of URIs from the a "text/uri-list"
* string. It was "borrowed" from gnome_uri_list_extract_uris
*
More information about the Commits
mailing list