/pidgin/main: de45cb0670a5: HTTP: make purple_url_parse deprecat...
Tomasz Wasilczyk
tomkiewicz at cpw.pidgin.im
Sat Jun 22 14:20:46 EDT 2013
Changeset: de45cb0670a5590d8794fe5c36096644b1096116
Author: Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date: 2013-06-22 20:20 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/de45cb0670a5
Description:
HTTP: make purple_url_parse deprecated in favor of purple_http_url_parse
diffstat:
libpurple/http.c | 79 +++++++++++++++---
libpurple/http.h | 119 +++++++++++++++++++++++++++++
libpurple/obsolete.c | 107 ++++++++++++++++++++++++++
libpurple/obsolete.h | 15 +++
libpurple/plugins/perl/common/Util.xs | 31 -------
libpurple/protocols/jabber/bosh.c | 1 +
libpurple/protocols/jabber/oob.c | 1 +
libpurple/protocols/msn/soap.c | 1 +
libpurple/protocols/yahoo/yahoo_filexfer.c | 1 +
libpurple/protocols/yahoo/yahoochat.c | 1 +
libpurple/proxy.c | 1 +
libpurple/util.c | 108 --------------------------
libpurple/util.h | 15 ---
13 files changed, 312 insertions(+), 168 deletions(-)
diffs (truncated from 663 to 300 lines):
diff --git a/libpurple/http.c b/libpurple/http.c
--- a/libpurple/http.c
+++ b/libpurple/http.c
@@ -39,8 +39,6 @@
#define PURPLE_HTTP_REQUEST_DEFAULT_MAX_REDIRECTS 20
#define PURPLE_HTTP_REQUEST_DEFAULT_TIMEOUT 30
-typedef struct _PurpleHttpURL PurpleHttpURL;
-
typedef struct _PurpleHttpSocket PurpleHttpSocket;
typedef struct _PurpleHttpHeaders PurpleHttpHeaders;
@@ -169,12 +167,6 @@ static void purple_http_cookie_jar_parse
static gchar * purple_http_cookie_jar_gen(PurpleHttpCookieJar *cookie_jar);
gchar * purple_http_cookie_jar_dump(PurpleHttpCookieJar *cjar);
-static PurpleHttpURL * purple_http_url_parse(const char *url);
-static void purple_http_url_free(PurpleHttpURL *parsed_url);
-static void purple_http_url_relative(PurpleHttpURL *base_url,
- PurpleHttpURL *relative_url);
-static gchar * purple_http_url_print(PurpleHttpURL *parsed_url);
-
static GRegex *purple_http_re_url, *purple_http_re_url_host,
*purple_http_re_rfc1123;
@@ -1278,7 +1270,7 @@ PurpleHttpConnection * purple_http_reque
purple_debug_misc("http", "Performing new request %p.\n", hc);
hc->url = purple_http_url_parse(request->url);
- if (!hc->url || hc->url->host[0] == '\0') {
+ if (!hc->url || hc->url->host == NULL || hc->url->host[0] == '\0') {
purple_debug_error("http", "Invalid URL requested.\n");
purple_http_connection_terminate(hc);
return NULL;
@@ -2062,7 +2054,8 @@ const gchar * purple_http_response_get_h
/*** URL functions ************************************************************/
-static PurpleHttpURL * purple_http_url_parse(const char *raw_url)
+PurpleHttpURL *
+purple_http_url_parse(const char *raw_url)
{
PurpleHttpURL *url;
GMatchInfo *match_info;
@@ -2174,7 +2167,8 @@ static PurpleHttpURL * purple_http_url_p
return url;
}
-static void purple_http_url_free(PurpleHttpURL *parsed_url)
+void
+purple_http_url_free(PurpleHttpURL *parsed_url)
{
if (parsed_url == NULL)
return;
@@ -2188,8 +2182,8 @@ static void purple_http_url_free(PurpleH
g_free(parsed_url);
}
-static void purple_http_url_relative(PurpleHttpURL *base_url,
- PurpleHttpURL *relative_url)
+void
+purple_http_url_relative(PurpleHttpURL *base_url, PurpleHttpURL *relative_url)
{
g_return_if_fail(base_url != NULL);
g_return_if_fail(relative_url != NULL);
@@ -2232,7 +2226,8 @@ static void purple_http_url_relative(Pur
base_url->fragment = g_strdup(relative_url->fragment);
}
-static gchar * purple_http_url_print(PurpleHttpURL *parsed_url)
+gchar *
+purple_http_url_print(PurpleHttpURL *parsed_url)
{
GString *url = g_string_new("");
gboolean before_host_printed = FALSE, host_printed = FALSE;
@@ -2278,6 +2273,62 @@ static gchar * purple_http_url_print(Pur
return g_string_free(url, FALSE);
}
+const gchar *
+purple_http_url_get_protocol(const PurpleHttpURL *parsed_url)
+{
+ g_return_val_if_fail(parsed_url != NULL, NULL);
+
+ return parsed_url->protocol;
+}
+
+const gchar *
+purple_http_url_get_user(const PurpleHttpURL *parsed_url)
+{
+ g_return_val_if_fail(parsed_url != NULL, NULL);
+
+ return parsed_url->user;
+}
+
+const gchar *
+purple_http_url_get_password(const PurpleHttpURL *parsed_url)
+{
+ g_return_val_if_fail(parsed_url != NULL, NULL);
+
+ return parsed_url->password;
+}
+
+const gchar *
+purple_http_url_get_host(const PurpleHttpURL *parsed_url)
+{
+ g_return_val_if_fail(parsed_url != NULL, NULL);
+
+ return parsed_url->host;
+}
+
+int
+purple_http_url_get_port(const PurpleHttpURL *parsed_url)
+{
+ g_return_val_if_fail(parsed_url != NULL, 0);
+
+ return parsed_url->port;
+}
+
+const gchar *
+purple_http_url_get_path(const PurpleHttpURL *parsed_url)
+{
+ g_return_val_if_fail(parsed_url != NULL, NULL);
+
+ return parsed_url->path;
+}
+
+const gchar *
+purple_http_url_get_fragment(const PurpleHttpURL *parsed_url)
+{
+ g_return_val_if_fail(parsed_url != NULL, NULL);
+
+ return parsed_url->fragment;
+}
+
/*** HTTP Subsystem ***********************************************************/
void purple_http_init(void)
diff --git a/libpurple/http.h b/libpurple/http.h
--- a/libpurple/http.h
+++ b/libpurple/http.h
@@ -48,6 +48,11 @@ typedef struct _PurpleHttpConnection Pur
typedef struct _PurpleHttpResponse PurpleHttpResponse;
/**
+ * Parsed representation for the URL.
+ */
+typedef struct _PurpleHttpURL PurpleHttpURL;
+
+/**
* An collection of cookies, got from HTTP response or provided for HTTP
* request.
*/
@@ -216,6 +221,120 @@ void purple_http_conn_set_progress_watch
/**************************************************************************/
+/** @name URL processing API */
+/**************************************************************************/
+/*@{*/
+
+/**
+ * Parses a URL.
+ *
+ * The returned data must be freed with purple_http_url_free.
+ *
+ * @param url The URL to parse.
+ * @return The parsed url or NULL, if the URL is invalid.
+ */
+PurpleHttpURL *
+purple_http_url_parse(const char *url);
+
+/**
+ * Frees the parsed URL struct.
+ *
+ * @param parsed_url The parsed URL struct, or NULL.
+ */
+void
+purple_http_url_free(PurpleHttpURL *parsed_url);
+
+/**
+ * Converts the base URL to the absolute form of the provided relative URL.
+ *
+ * Example: "https://example.com/path/to/file.html" + "subdir/other-file.html" =
+ * "https://example.com/path/to/subdir/another-file.html"
+ *
+ * @param base_url The base URL. The result is stored here.
+ * @param relative_url The relative URL.
+ */
+void
+purple_http_url_relative(PurpleHttpURL *base_url, PurpleHttpURL *relative_url);
+
+/**
+ * Converts the URL struct to the printable form. The result may not be a valid
+ * URL (in cases, when the struct doesn't have all fields filled properly).
+ *
+ * The result must be g_free'd.
+ *
+ * @param parsed_url The URL struct.
+ * @return The printable form of the URL.
+ */
+gchar *
+purple_http_url_print(PurpleHttpURL *parsed_url);
+
+/**
+ * Gets the protocol part of URL.
+ *
+ * @param parsed_url The URL struct.
+ * @return The protocol.
+ */
+const gchar *
+purple_http_url_get_protocol(const PurpleHttpURL *parsed_url);
+
+/**
+ * Gets the username part of URL.
+ *
+ * @param parsed_url The URL struct.
+ * @return The username.
+ */
+const gchar *
+purple_http_url_get_user(const PurpleHttpURL *parsed_url);
+
+/**
+ * Gets the password part of URL.
+ *
+ * @param parsed_url The URL struct.
+ * @return The password.
+ */
+const gchar *
+purple_http_url_get_password(const PurpleHttpURL *parsed_url);
+
+/**
+ * Gets the hostname part of URL.
+ *
+ * @param parsed_url The URL struct.
+ * @return The hostname.
+ */
+const gchar *
+purple_http_url_get_host(const PurpleHttpURL *parsed_url);
+
+/**
+ * Gets the port part of URL.
+ *
+ * @param parsed_url The URL struct.
+ * @return The port number.
+ */
+int
+purple_http_url_get_port(const PurpleHttpURL *parsed_url);
+
+/**
+ * Gets the path part of URL.
+ *
+ * @param parsed_url The URL struct.
+ * @return The path.
+ */
+const gchar *
+purple_http_url_get_path(const PurpleHttpURL *parsed_url);
+
+/**
+ * Gets the fragment part of URL.
+ *
+ * @param parsed_url The URL struct.
+ * @return The fragment.
+ */
+const gchar *
+purple_http_url_get_fragment(const PurpleHttpURL *parsed_url);
+
+/*@}*/
+
+
+/**************************************************************************/
/** @name Cookie jar API */
/**************************************************************************/
/*@{*/
diff --git a/libpurple/obsolete.c b/libpurple/obsolete.c
--- a/libpurple/obsolete.c
+++ b/libpurple/obsolete.c
@@ -774,3 +774,110 @@ purple_util_fetch_url_cancel(PurpleUtilF
g_free(gfud);
}
+
+/*
+ * TODO: Should probably add a "gboolean *ret_ishttps" parameter that
+ * is set to TRUE if this URL is https, otherwise it is set to
+ * FALSE. But that change will break the API.
+ *
+ * This is important for Yahoo! web messenger login. They now
+ * force https login, and if you access the web messenger login
+ * page via http then it redirects you to the https version, but
+ * purple_util_fetch_url() ignores the "https" and attempts to
+ * fetch the URL via http again, which gets redirected again.
+ */
+gboolean
+purple_url_parse(const char *url, char **ret_host, int *ret_port,
+ char **ret_path, char **ret_user, char **ret_passwd)
+{
+ gboolean is_https = FALSE;
+ const char * scan_info;
+ char port_str[6];
More information about the Commits
mailing list