# HG changeset patch
# Node ID c43682760465
# Parent  507a61f2194a
diff --git a/libpurple/protocols/gg/meson.build b/libpurple/protocols/gg/meson.build
--- a/libpurple/protocols/gg/meson.build
+++ b/libpurple/protocols/gg/meson.build
@@ -45,8 +45,6 @@
 	'xml.h',
 	'oauth/oauth.c',
 	'oauth/oauth.h',
-	'oauth/oauth-parameter.c',
-	'oauth/oauth-parameter.h',
 	'oauth/oauth-purple.c',
 	'oauth/oauth-purple.h'
 ]
diff --git a/libpurple/protocols/gg/oauth/oauth-parameter.h b/libpurple/protocols/gg/oauth/oauth-parameter.h
deleted file mode 100644
--- a/libpurple/protocols/gg/oauth/oauth-parameter.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* purple
- *
- * 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
- * source distribution.
- *
- * 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 */
diff --git a/libpurple/protocols/gg/oauth/oauth-parameter.c b/libpurple/protocols/gg/oauth/oauth-parameter.c
deleted file mode 100644
--- a/libpurple/protocols/gg/oauth/oauth-parameter.c
+++ /dev/null
@@ -1,161 +0,0 @@
-/* purple
- *
- * 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
- * source distribution.
- *
- * 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"
-
-#include <glib.h>
-
-struct gg_oauth_parameter {
-	char *key;
-	char *value;
-	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;
-	char *new_key;
-	char *new_value;
-
-	if (value == NULL)
-		return 0;
-
-	if (list == NULL)
-		return -1;
-
-	new_key = g_strdup(key);
-
-	if (new_key == NULL)
-		return -1;
-
-	new_value = g_strdup(value);
-
-	if (new_value == NULL) {
-		g_free(new_key);
-		return -1;
-	}
-
-	new_p = g_new0(gg_oauth_parameter_t, 1);
-
-	if (new_p == NULL) {
-		g_free(new_key);
-		g_free(new_value);
-		return -1;
-	}
-
-	memset(new_p, 0, sizeof(gg_oauth_parameter_t));
-	new_p->key = new_key;
-	new_p->value = new_value;
-
-	if (*list != NULL) {
-		p = *list;
-
-		while (p != NULL && p->next != NULL)
-			p = p->next;
-
-		p->next = new_p;
-	} else {
-		*list = new_p;
-	}
-
-	return 0;
-}
-
-char *gg_oauth_parameter_join(gg_oauth_parameter_t *list, int header)
-{
-	gg_oauth_parameter_t *p;
-	int len = 0;
-	char *res, *out;
-
-	if (header)
-		len += strlen("OAuth ");
-
-	for (p = list; p; p = p->next) {
-		gchar *escaped;
-		len += strlen(p->key);
-
-		len += (header) ? 3 : 1;
-
-		escaped = g_uri_escape_string(p->value, NULL, FALSE);
-		len += strlen(escaped);
-		g_free(escaped);
-
-		if (p->next)
-			len += 1;
-	}
-
-	res = g_malloc(len + 1);
-
-	if (res == NULL)
-		return NULL;
-
-	out = res;
-
-	*out = 0;
-
-	if (header) {
-		strcpy(out, "OAuth ");
-		out += strlen(out);
-	}
-
-	for (p = list; p; p = p->next) {
-		gchar *escaped;
-		strcpy(out, p->key);
-		out += strlen(p->key);
-
-		strcpy(out++, "=");
-
-		if (header)
-			strcpy(out++, "\"");
-
-		escaped = g_uri_escape_string(p->value, NULL, FALSE);
-		strcpy(out, escaped);
-		out += strlen(escaped);
-		g_free(escaped);
-
-		if (header)
-			strcpy(out++, "\"");
-
-		if (p->next != NULL)
-			strcpy(out++, (header) ? "," : "&");
-	}
-
-	return res;
-}
-
-void gg_oauth_parameter_free(gg_oauth_parameter_t *list)
-{
-	while (list != NULL) {
-		gg_oauth_parameter_t *next;
-
-		next = list->next;
-
-		g_free(list->key);
-		g_free(list->value);
-		g_free(list);
-
-		list = next;
-	}
-}
diff --git a/libpurple/protocols/gg/oauth/oauth.c b/libpurple/protocols/gg/oauth/oauth.c
--- a/libpurple/protocols/gg/oauth/oauth.c
+++ b/libpurple/protocols/gg/oauth/oauth.c
@@ -25,7 +25,7 @@
 
 #include "oauth.h"
 
-#include "oauth-parameter.h"
+#include <purple.h>
 
 #include <time.h>
 
@@ -49,6 +49,56 @@
 	*buf = 0;
 }
 
+static GList *
+gg_oauth_parameter_set(GList *params, const char *key, const char *value)
+{
+	PurpleKeyValuePair *kvp;
+
+	if (value == NULL) {
+		return params;
+	}
+
+	kvp = purple_key_value_pair_new_full(key, g_strdup(value), g_free);
+
+	return g_list_append(params, kvp);
+}
+
+static char *
+gg_oauth_parameter_join(const GList *params, gboolean header)
+{
+	GString *res = g_string_new(NULL);
+
+	if (header) {
+		res = g_string_append(res, "OAuth ");
+	}
+
+	for (; params; params = params->next) {
+		PurpleKeyValuePair *kvp = params->data;
+		gchar *escaped;
+
+		res = g_string_append(res, kvp->key);
+		res = g_string_append_c(res, '=');
+
+		if (header) {
+			res = g_string_append_c(res, '"');
+		}
+
+		escaped = g_uri_escape_string(kvp->value, NULL, FALSE);
+		res = g_string_append(res, escaped);
+		g_free(escaped);
+
+		if (header) {
+			res = g_string_append_c(res, '"');
+		}
+
+		if (params->next != NULL) {
+			res = g_string_append_c(res, header ? ',' : '&');
+		}
+	}
+
+	return g_string_free(res, FALSE);
+}
+
 static gchar *gg_hmac_sha1(const char *key, const char *message)
 {
 	GHmac *hmac;
@@ -99,7 +149,7 @@
 {
 	char *request, *signature, *res;
 	char nonce[80], timestamp[16];
-	gg_oauth_parameter_t *params = NULL;
+	GList *params = NULL;
 
 	if (gg_oauth_static_nonce == NULL)
 		gg_oauth_generate_nonce(nonce, sizeof(nonce));
@@ -115,38 +165,38 @@
 		timestamp[sizeof(timestamp) - 1] = 0;
 	}
 
-	gg_oauth_parameter_set(&params, "oauth_consumer_key", consumer_key);
-	gg_oauth_parameter_set(&params, "oauth_nonce", nonce);
-	gg_oauth_parameter_set(&params, "oauth_signature_method", "HMAC-SHA1");
-	gg_oauth_parameter_set(&params, "oauth_timestamp", timestamp);
-	gg_oauth_parameter_set(&params, "oauth_token", token);
-	gg_oauth_parameter_set(&params, "oauth_version", "1.0");
+	params = gg_oauth_parameter_set(params, "oauth_consumer_key", consumer_key);
+	params = gg_oauth_parameter_set(params, "oauth_nonce", nonce);
+	params = gg_oauth_parameter_set(params, "oauth_signature_method", "HMAC-SHA1");
+	params = gg_oauth_parameter_set(params, "oauth_timestamp", timestamp);
+	params = gg_oauth_parameter_set(params, "oauth_token", token);
+	params = gg_oauth_parameter_set(params, "oauth_version", "1.0");
 
-	request = gg_oauth_parameter_join(params, 0);
+	request = gg_oauth_parameter_join(params, FALSE);
 
 	signature = gg_oauth_generate_signature(method, url, request, consumer_secret, token_secret);
 
 	g_free(request);
 
-	gg_oauth_parameter_free(params);
+	g_list_free_full(params, (GDestroyNotify)purple_key_value_pair_free);
 	params = NULL;
 
 	if (signature == NULL)
 		return NULL;
 
-	gg_oauth_parameter_set(&params, "oauth_version", "1.0");
-	gg_oauth_parameter_set(&params, "oauth_nonce", nonce);
-	gg_oauth_parameter_set(&params, "oauth_timestamp", timestamp);
-	gg_oauth_parameter_set(&params, "oauth_consumer_key", consumer_key);
-	gg_oauth_parameter_set(&params, "oauth_token", token);
-	gg_oauth_parameter_set(&params, "oauth_signature_method", "HMAC-SHA1");
-	gg_oauth_parameter_set(&params, "oauth_signature", signature);
+	params = gg_oauth_parameter_set(params, "oauth_version", "1.0");
+	params = gg_oauth_parameter_set(params, "oauth_nonce", nonce);
+	params = gg_oauth_parameter_set(params, "oauth_timestamp", timestamp);
+	params = gg_oauth_parameter_set(params, "oauth_consumer_key", consumer_key);
+	params = gg_oauth_parameter_set(params, "oauth_token", token);
+	params = gg_oauth_parameter_set(params, "oauth_signature_method", "HMAC-SHA1");
+	params = gg_oauth_parameter_set(params, "oauth_signature", signature);
 
 	g_free(signature);
 
-	res = gg_oauth_parameter_join(params, 1);
+	res = gg_oauth_parameter_join(params, TRUE);
 
-	gg_oauth_parameter_free(params);
+	g_list_free_full(params, (GDestroyNotify)purple_key_value_pair_free);
 
 	return res;
 }
