# HG changeset patch # User Paul Aurich # Date 1247298465 0 # Node ID ef48fb87d8d208f0ae34212d5f7430de799f4baa # Parent 2dff07ddcc838525d1c5b47f65c6d8f4f0b7ba58# Parent e90fa379fcec26fb40e26ccc3b354a815129ed69 merge of '834ee1803fbad0f4960a66592ac43641f23124c6' and 'a743f7b2086257b37f218802f4ae61803cf5ff01' diff -r 2dff07ddcc83 -r ef48fb87d8d2 ChangeLog.API --- a/ChangeLog.API Sat Jul 11 07:02:33 2009 +0000 +++ b/ChangeLog.API Sat Jul 11 07:47:45 2009 +0000 @@ -37,6 +37,8 @@ * 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 @@ * 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 diff -r 2dff07ddcc83 -r ef48fb87d8d2 libpurple/protocols/jabber/chat.c --- a/libpurple/protocols/jabber/chat.c Sat Jul 11 07:02:33 2009 +0000 +++ b/libpurple/protocols/jabber/chat.c Sat Jul 11 07:47:45 2009 +0000 @@ -235,7 +235,7 @@ purple_serv_got_join_chat_failed(gc, data); g_free(buf); return; - } else if(!jabber_nameprep_validate(server)) { + } else if(!jabber_domain_validate(server)) { char *buf = g_strdup_printf(_("%s is not a valid server name"), server); purple_notify_error(gc, _("Invalid Server Name"), _("Invalid Server Name"), buf); diff -r 2dff07ddcc83 -r ef48fb87d8d2 libpurple/protocols/jabber/jutil.c --- a/libpurple/protocols/jabber/jutil.c Sat Jul 11 07:02:33 2009 +0000 +++ b/libpurple/protocols/jabber/jutil.c Sat Jul 11 07:47:45 2009 +0000 @@ -54,7 +54,7 @@ return TRUE; } -gboolean jabber_nameprep_validate(const char *str) +gboolean jabber_domain_validate(const char *str) { const char *c; @@ -64,11 +64,24 @@ if(strlen(str) > 1023) return FALSE; - /* - * TODO: An IPv6 address of the form [2001:470:1f05:d58::2] is also - * a valid XMPP domain portion. - */ c = str; + + if (*c == '[') { + /* Check if str is a valid IPv6 identifier */ + const gchar *end_bracket = strstr(c, "]"); + gboolean valid = FALSE; + + if (!end_bracket || *(end_bracket + 1) != '\0') + return FALSE; + + /* Ugly, but in-place */ + *(gchar *)end_bracket = '\0'; + valid = purple_ipv6_address_is_valid(c + 1); + *(gchar *)end_bracket = ']'; + + return valid; + } + while(c && *c) { gunichar ch = g_utf8_get_char(c); /* The list of characters allowed in domain names is pretty small */ @@ -271,7 +284,7 @@ /* and finally the jabber nodeprep */ if(!jabber_nodeprep_validate(jid->node) || - !jabber_nameprep_validate(jid->domain) || + !jabber_domain_validate(jid->domain) || !jabber_resourceprep_validate(jid->resource)) { jabber_id_free(jid); return NULL; diff -r 2dff07ddcc83 -r ef48fb87d8d2 libpurple/protocols/jabber/jutil.h --- a/libpurple/protocols/jabber/jutil.h Sat Jul 11 07:02:33 2009 +0000 +++ b/libpurple/protocols/jabber/jutil.h Sat Jul 11 07:47:45 2009 +0000 @@ -45,8 +45,7 @@ gboolean jabber_is_own_account(JabberStream *js, const char *jid); gboolean jabber_nodeprep_validate(const char *); -/* TODO: This needs to be named jabber_domain_validate and handle IPv6/IDNA. */ -gboolean jabber_nameprep_validate(const char *); +gboolean jabber_domain_validate(const char *); gboolean jabber_resourceprep_validate(const char *); PurpleConversation *jabber_find_unnormalized_conv(const char *name, PurpleAccount *account); diff -r 2dff07ddcc83 -r ef48fb87d8d2 libpurple/protocols/yahoo/yahoo_aliases.c --- a/libpurple/protocols/yahoo/yahoo_aliases.c Sat Jul 11 07:02:33 2009 +0000 +++ b/libpurple/protocols/yahoo/yahoo_aliases.c Sat Jul 11 07:47:45 2009 +0000 @@ -424,7 +424,7 @@ "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n" "Cookie: T=%s; path=/; domain=.yahoo.com; Y=%s;\r\n" "Host: %s\r\n" - "Content-Length: %" G_GSIZE_FORMAT "\r\n" + "Content-Length: %d\r\n" "Cache-Control: no-cache\r\n\r\n" "%s\r\n\r\n", webpage, diff -r 2dff07ddcc83 -r ef48fb87d8d2 libpurple/tests/test_jabber_jutil.c --- a/libpurple/tests/test_jabber_jutil.c Sat Jul 11 07:02:33 2009 +0000 +++ b/libpurple/tests/test_jabber_jutil.c Sat Jul 11 07:47:45 2009 +0000 @@ -100,11 +100,9 @@ assert_valid_jid("mark.doliner@わいど.org"); assert_valid_jid("nick@まつ.おおかみ.net"); assert_valid_jid("paul@10.0.42.230/s"); -#if 0 -/* Uncomment these when jabber_domain_validate supports IPv6 addresses */ assert_valid_jid("paul@[::1]"); /* IPv6 */ assert_valid_jid("paul@[2001:470:1f05:d58::2]"); -#endif + assert_valid_jid("paul@[2001:470:1f05:d58::2]/foo"); assert_invalid_jid("@gmail.com"); assert_invalid_jid("@@gmail.com"); @@ -117,6 +115,8 @@ assert_invalid_jid("mark.doliner@gmail_stuff.org"); assert_invalid_jid("mark.doliner@gmail[stuff.org"); assert_invalid_jid("mark.doliner@gmail\\stuff.org"); + assert_invalid_jid("paul@[::1]124"); + assert_invalid_jid("paul@2[::1]124/as"); } END_TEST diff -r 2dff07ddcc83 -r ef48fb87d8d2 libpurple/tests/test_util.c --- a/libpurple/tests/test_util.c Sat Jul 11 07:02:33 2009 +0000 +++ b/libpurple/tests/test_util.c Sat Jul 11 07:47:45 2009 +0000 @@ -80,6 +80,25 @@ } 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 @@ 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); diff -r 2dff07ddcc83 -r ef48fb87d8d2 libpurple/util.c --- a/libpurple/util.c Sat Jul 11 07:02:33 2009 +0000 +++ b/libpurple/util.c Sat Jul 11 07:47:45 2009 +0000 @@ -4446,6 +4446,7 @@ 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 @@ 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) diff -r 2dff07ddcc83 -r ef48fb87d8d2 libpurple/util.h --- a/libpurple/util.h Sat Jul 11 07:02:33 2009 +0000 +++ b/libpurple/util.h Sat Jul 11 07:47:45 2009 +0000 @@ -1203,10 +1203,33 @@ * @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 *