--- a/libpurple/soupcompat.h Tue Dec 14 01:57:01 2021 -0600 +++ b/libpurple/soupcompat.h Tue Dec 14 01:58:31 2021 -0600 @@ -51,6 +51,43 @@ return msg->status_code; } +static inline SoupMessage * +soup_message_new_from_encoded_form(const gchar *method, + const gchar *uri_string, + gchar *encoded_form) +{ + SoupMessage *msg = NULL; + SoupURI *uri; + + g_return_val_if_fail(method != NULL, NULL); + g_return_val_if_fail(uri_string != NULL, NULL); + g_return_val_if_fail(encoded_form != NULL, NULL); + + uri = soup_uri_new(uri_string); + if (!uri || !uri->host) { + g_free(encoded_form); + soup_uri_free(uri); + return NULL; + } + + if (strcmp(method, "GET") == 0) { + g_free(uri->query); + uri->query = encoded_form; + msg = soup_message_new_from_uri(method, uri); + } else if (strcmp (method, "POST") == 0 || strcmp (method, "PUT") == 0) { + msg = soup_message_new_from_uri(method, uri); + soup_message_body_append_take(msg->request_body, + (guchar *)encoded_form, + strlen(encoded_form)); + } else { + g_free(encoded_form); + } + + soup_uri_free(uri); + + return msg; +} + #endif /* SOUP_MAJOR_VERSION < 3 */ #endif /* PURPLE_SOUPCOMPAT_H */