--- a/libpurple/protocols/gg/meson.build Thu Feb 25 20:44:26 2021 -0600
+++ b/libpurple/protocols/gg/meson.build Fri Feb 26 00:12:08 2021 -0600
@@ -45,8 +45,6 @@
- 'oauth/oauth-parameter.c',
- 'oauth/oauth-parameter.h',
--- a/libpurple/protocols/gg/oauth/oauth-parameter.c Thu Feb 25 20:44:26 2021 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,161 +0,0 @@
- * Purple is the legal property of its developers, whose names are too numerous
- * to list here. Please refer to the COPYRIGHT file distributed with this
- * Code adapted from libgadu (C) 2008 Wojtek Kaniewski <wojtekka@irc.pl>
- * (http://toxygen.net/libgadu/) during Google Summer of Code 2012
- * by Tomek Wasilczyk (http://www.wasilczyk.pl).
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
-#include "oauth-parameter.h"
-struct gg_oauth_parameter {
- struct gg_oauth_parameter *next;
-int gg_oauth_parameter_set(gg_oauth_parameter_t **list, const char *key, const char *value)
- gg_oauth_parameter_t *p, *new_p;
- new_key = g_strdup(key);
- new_value = g_strdup(value);
- if (new_value == NULL) {
- new_p = g_new0(gg_oauth_parameter_t, 1);
- memset(new_p, 0, sizeof(gg_oauth_parameter_t));
- new_p->value = new_value;
- while (p != NULL && p->next != NULL)
-char *gg_oauth_parameter_join(gg_oauth_parameter_t *list, int header)
- gg_oauth_parameter_t *p;
- len += strlen("OAuth ");
- for (p = list; p; p = p->next) {
- len += (header) ? 3 : 1;
- escaped = g_uri_escape_string(p->value, NULL, FALSE);
- len += strlen(escaped);
- res = g_malloc(len + 1);
- for (p = list; p; p = p->next) {
- escaped = g_uri_escape_string(p->value, NULL, FALSE);
- out += strlen(escaped);
- strcpy(out++, (header) ? "," : "&");
-void gg_oauth_parameter_free(gg_oauth_parameter_t *list)
- gg_oauth_parameter_t *next;
--- a/libpurple/protocols/gg/oauth/oauth-parameter.h Thu Feb 25 20:44:26 2021 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
- * Purple is the legal property of its developers, whose names are too numerous
- * to list here. Please refer to the COPYRIGHT file distributed with this
- * Code adapted from libgadu (C) 2008 Wojtek Kaniewski <wojtekka@irc.pl>
- * (http://toxygen.net/libgadu/) during Google Summer of Code 2012
- * by Tomek Wasilczyk (http://www.wasilczyk.pl).
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
-#ifndef _GGP_OAUTH_PARAMETER_H
-#define _GGP_OAUTH_PARAMETER_H
-typedef struct gg_oauth_parameter gg_oauth_parameter_t;
-int gg_oauth_parameter_set(gg_oauth_parameter_t **list, const char *key, const char *value);
-char *gg_oauth_parameter_join(gg_oauth_parameter_t *list, int header);
-void gg_oauth_parameter_free(gg_oauth_parameter_t *list);
-#endif /* _GGP_OAUTH_PARAMETER_H */
--- a/libpurple/protocols/gg/oauth/oauth.c Thu Feb 25 20:44:26 2021 -0600
+++ b/libpurple/protocols/gg/oauth/oauth.c Fri Feb 26 00:12:08 2021 -0600
@@ -25,8 +25,6 @@
-#include "oauth-parameter.h"
@@ -34,6 +32,8 @@
char *gg_oauth_static_nonce; /* dla unit testów */
char *gg_oauth_static_timestamp; /* dla unit testów */
+static char *gg_oauth_generate_request(gboolean header, ...) G_GNUC_NULL_TERMINATED; static void gg_oauth_generate_nonce(char *buf, int len)
const char charset[] = "0123456789";
@@ -49,6 +49,46 @@
+/* Returns a comma separated header value if header is true, + * or a url-encoded request otherwise +gg_oauth_generate_request(gboolean header, ...) + GString *res = g_string_new(NULL); + gboolean truncate = FALSE; + res = g_string_append(res, "OAuth "); + va_start(params, header); + while((key = va_arg(params, const gchar *))) { + const gchar *value = va_arg(params, const gchar *); + gchar *escaped = g_uri_escape_string(value, NULL, FALSE); + g_string_append_printf(res, "%s=\"%s\",", key, escaped); + g_string_append_printf(res, "%s=%s&", key, escaped); + /* remove trailing separator */ + res = g_string_truncate(res, res->len - 1); + return g_string_free(res, FALSE); static gchar *gg_hmac_sha1(const char *key, const char *message)
@@ -99,7 +139,6 @@
char *request, *signature, *res;
char nonce[80], timestamp[16];
- gg_oauth_parameter_t *params = NULL;
if (gg_oauth_static_nonce == NULL)
gg_oauth_generate_nonce(nonce, sizeof(nonce));
@@ -115,38 +154,32 @@
timestamp[sizeof(timestamp) - 1] = 0;
- gg_oauth_parameter_set(¶ms, "oauth_consumer_key", consumer_key);
- gg_oauth_parameter_set(¶ms, "oauth_nonce", nonce);
- gg_oauth_parameter_set(¶ms, "oauth_signature_method", "HMAC-SHA1");
- gg_oauth_parameter_set(¶ms, "oauth_timestamp", timestamp);
- gg_oauth_parameter_set(¶ms, "oauth_token", token);
- gg_oauth_parameter_set(¶ms, "oauth_version", "1.0");
- request = gg_oauth_parameter_join(params, 0);
+ request = gg_oauth_generate_request(FALSE, + "oauth_consumer_key", consumer_key, + "oauth_signature_method", "HMAC-SHA1", + "oauth_timestamp", timestamp, + "oauth_version", "1.0", signature = gg_oauth_generate_signature(method, url, request, consumer_secret, token_secret);
- gg_oauth_parameter_free(params);
- gg_oauth_parameter_set(¶ms, "oauth_version", "1.0");
- gg_oauth_parameter_set(¶ms, "oauth_nonce", nonce);
- gg_oauth_parameter_set(¶ms, "oauth_timestamp", timestamp);
- gg_oauth_parameter_set(¶ms, "oauth_consumer_key", consumer_key);
- gg_oauth_parameter_set(¶ms, "oauth_token", token);
- gg_oauth_parameter_set(¶ms, "oauth_signature_method", "HMAC-SHA1");
- gg_oauth_parameter_set(¶ms, "oauth_signature", signature);
+ res = gg_oauth_generate_request(TRUE, + "oauth_version", "1.0", + "oauth_timestamp", timestamp, + "oauth_consumer_key", consumer_key, + "oauth_signature_method", "HMAC-SHA1", + "oauth_signature", signature, - res = gg_oauth_parameter_join(params, 1);
- gg_oauth_parameter_free(params);