/pidgin/main: 4d2e2182f901: Adding new API for fetch_url with bi...
Youness Alaoui <[email protected]>
| Newsgroups | gmane.comp.gnome.gaim.cvs |
|---|---|
| Message-ID | <[email protected]> |
Changeset: 4d2e2182f9010107f402320dc37b059b4e2f5470 Author: Youness Alaoui <[email protected]> Date: 2016-06-14 17:48 -0400 Branch: release-2.x.y URL: https://hg.pidgin.im/pidgin/main/rev/4d2e2182f901 Description: Adding new API for fetch_url with binary request. The current fetch API uses 'strlen' to check the length of the request. This is changed to use a request_len argument which allows for POST requests to be sent with binary data. diffstat: libpurple/util.c | 18 ++++++++++++++++-- libpurple/util.h | 26 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diffs (92 lines): diff --git a/libpurple/util.c b/libpurple/util.c --- a/libpurple/util.c +++ b/libpurple/util.c @@ -60,6 +60,7 @@ struct _PurpleUtilFetchUrlData char *user_agent; gboolean http11; char *request; + gsize request_len; gsize request_written; gboolean include_headers; @@ -4082,6 +4083,7 @@ url_fetch_send_cb(gpointer data, gint so g_string_append(request_str, "\r\n"); gfud->request = g_string_free(request_str, FALSE); + gfud->request_len = strlen(gfud->request); } if(purple_debug_is_unsafe()) @@ -4089,7 +4091,7 @@ url_fetch_send_cb(gpointer data, gint so else purple_debug_misc("util", "request constructed\n"); - total_len = strlen(gfud->request); + total_len = gfud->request_len; if (gfud->is_ssl) len = purple_ssl_write(gfud->ssl_connection, gfud->request + gfud->request_written, @@ -4196,6 +4198,17 @@ purple_util_fetch_url_request_len_with_a const char *request, gboolean include_headers, gssize max_len, PurpleUtilFetchUrlCallback callback, void *user_data) { + return purple_util_fetch_url_request_data_len_with_account(account, url, full, + user_agent, http11, request, request ? strlen (request) : 0, include_headers, max_len, callback, + user_data); +} + +PurpleUtilFetchUrlData * +purple_util_fetch_url_request_data_len_with_account(PurpleAccount *account, + const char *url, gboolean full, const char *user_agent, gboolean http11, + const char *request, gsize request_len, gboolean include_headers, gssize max_len, + PurpleUtilFetchUrlCallback callback, void *user_data) +{ PurpleUtilFetchUrlData *gfud; g_return_val_if_fail(url != NULL, NULL); @@ -4216,7 +4229,8 @@ purple_util_fetch_url_request_len_with_a gfud->user_agent = g_strdup(user_agent); gfud->http11 = http11; gfud->full = full; - gfud->request = g_strdup(request); + gfud->request = request_len ? g_memdup(request, request_len) : NULL; + gfud->request_len = request_len; gfud->include_headers = include_headers; gfud->fd = -1; if (max_len <= 0) { diff --git a/libpurple/util.h b/libpurple/util.h --- a/libpurple/util.h +++ b/libpurple/util.h @@ -1209,6 +1209,32 @@ PurpleUtilFetchUrlData *purple_util_fetc PurpleUtilFetchUrlCallback callback, gpointer data); /** + * Fetches the data from a URL, and passes it to a callback function. + * + * @param account The account for which the request is needed, or NULL. + * @param url The URL. + * @param full TRUE if this is the full URL, or FALSE if it's a + * partial URL. + * @param user_agent The user agent field to use, or NULL. + * @param http11 TRUE if HTTP/1.1 should be used to download the file. + * @param request A HTTP request to send to the server instead of the + * standard GET + * @param request_len + * Then length of the request being sent + * @param include_headers + * If TRUE, include the HTTP headers in the response. + * @param max_len The maximum number of bytes to retrieve, or a negative + * number to use the default max of 512 KiB. + * @param callback The callback function. + * @param data The user data to pass to the callback function. + * @deprecated In 3.0.0, we'll rename this to "purple_util_fetch_url_request" and get rid of the old one + */ +PurpleUtilFetchUrlData * +purple_util_fetch_url_request_data_len_with_account(PurpleAccount *account, + const char *url, gboolean full, const char *user_agent, gboolean http11, + const char *request, gsize request_len, gboolean include_headers, gssize max_len, + PurpleUtilFetchUrlCallback callback, void *user_data); +/** * Cancel a pending URL request started with either * purple_util_fetch_url_request() or purple_util_fetch_url(). * _______________________________________________ Commits mailing list [email protected] https://pidgin.im/cgi-bin/mailman/listinfo/commits