pidgin/pidgin

Rewrite fb_http_urlcmp using SoupURI.

2019-10-12, Elliott Sales de Andrade
07bc15fd4417
Parents 3096c5fab4cb
Children d59a2f6c170f
Rewrite fb_http_urlcmp using SoupURI.
--- a/libpurple/protocols/facebook/http.c Thu Oct 10 05:31:23 2019 -0400
+++ b/libpurple/protocols/facebook/http.c Sat Oct 12 04:38:00 2019 -0400
@@ -294,25 +294,9 @@
gboolean
fb_http_urlcmp(const gchar *url1, const gchar *url2, gboolean protocol)
{
- const gchar *str1;
- const gchar *str2;
+ SoupURI *uri1;
+ SoupURI *uri2;
gboolean ret = TRUE;
- gint int1;
- gint int2;
- guint i;
- PurpleHttpURL *purl1;
- PurpleHttpURL *purl2;
-
- static const gchar * (*funcs[]) (const PurpleHttpURL *url) = {
- /* Always first so it can be skipped */
- purple_http_url_get_protocol,
-
- purple_http_url_get_fragment,
- purple_http_url_get_host,
- purple_http_url_get_password,
- purple_http_url_get_path,
- purple_http_url_get_username
- };
if ((url1 == NULL) || (url2 == NULL)) {
return url1 == url2;
@@ -322,39 +306,28 @@
return TRUE;
}
- purl1 = purple_http_url_parse(url1);
+ uri1 = soup_uri_new(url1);
- if (purl1 == NULL) {
+ if (uri1 == NULL) {
return g_ascii_strcasecmp(url1, url2) == 0;
}
- purl2 = purple_http_url_parse(url2);
+ uri2 = soup_uri_new(url2);
- if (purl2 == NULL) {
- purple_http_url_free(purl1);
+ if (uri2 == NULL) {
+ soup_uri_free(uri1);
return g_ascii_strcasecmp(url1, url2) == 0;
}
- for (i = protocol ? 0 : 1; i < G_N_ELEMENTS(funcs); i++) {
- str1 = funcs[i](purl1);
- str2 = funcs[i](purl2);
-
- if (!purple_strequal(str1, str2)) {
- ret = FALSE;
- break;
- }
+ if (!protocol) {
+ /* Force the same scheme (and same port). */
+ soup_uri_set_scheme(uri1, SOUP_URI_SCHEME_HTTPS);
+ soup_uri_set_scheme(uri2, SOUP_URI_SCHEME_HTTPS);
}
- if (ret && protocol) {
- int1 = purple_http_url_get_port(purl1);
- int2 = purple_http_url_get_port(purl2);
+ ret = soup_uri_equal(uri1, uri2);
- if (int1 != int2) {
- ret = FALSE;
- }
- }
-
- purple_http_url_free(purl1);
- purple_http_url_free(purl2);
+ soup_uri_free(uri1);
+ soup_uri_free(uri2);
return ret;
}