adium.1-4: 386bee22: Plucked f01c542dc4811778ea9ae719b9b621ef...

evands at pidgin.im evands at pidgin.im
Wed Nov 17 20:16:24 EST 2010


----------------------------------------------------------------------
Revision: 386bee22d25dcb2fcab450b02a46e48bf7d1757d
Parent:   241c0dfb30b8d26fef38047807a31e939fb9423e
Author:   evands at pidgin.im
Date:     11/17/10 20:12:55
Branch:   im.pidgin.adium.1-4
URL: http://d.pidgin.im/viewmtn/revision/info/386bee22d25dcb2fcab450b02a46e48bf7d1757d

Changelog: 

Plucked f01c542dc4811778ea9ae719b9b621eff9c6350b to add ability to add jabber mechs externally.
Removed fbapi.* from our libpurple build.

Changes against parent 241c0dfb30b8d26fef38047807a31e939fb9423e

  dropped  libpurple/protocols/jabber/fbapi.c
  dropped  libpurple/protocols/jabber/fbapi.h
  patched  libpurple/protocols/jabber/Makefile.am
  patched  libpurple/protocols/jabber/auth.c
  patched  libpurple/protocols/jabber/auth.h

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/Makefile.am	476bea6906d6274c395997cc38eeff26468f1e52
+++ libpurple/protocols/jabber/Makefile.am	c61d5f58244d8155f0ca868f79dce7088b0fb1d0
@@ -27,8 +27,6 @@ JABBERSOURCES = \
 			  data.h \
 			  disco.c \
 			  disco.h \
-			  fbapi.c \
-			  fbapi.h \
 			  google/gmail.c \
 			  google/gmail.h \
 			  google/google.c \
============================================================
--- libpurple/protocols/jabber/auth.c	a5c6eb8d3129570cf362d5d4ef1ac5957ceea139
+++ libpurple/protocols/jabber/auth.c	bec1a5293c6078d9a9cef298a53403f114b3e034
@@ -502,23 +502,30 @@ static gint compare_mech(gconstpointer a
 	return 0;
 }
 
+void jabber_auth_add_mech(JabberSaslMech *mech)
+{
+	auth_mechs = g_slist_insert_sorted(auth_mechs, mech, compare_mech);
+}
+
+void jabber_auth_remove_mech(JabberSaslMech *mech)
+{
+	auth_mechs = g_slist_remove(auth_mechs, mech);
+}
+
 void jabber_auth_init(void)
 {
 	JabberSaslMech **tmp;
 	gint count, i;
 
-	auth_mechs = g_slist_insert_sorted(auth_mechs, jabber_auth_get_plain_mech(), compare_mech);
-	auth_mechs = g_slist_insert_sorted(auth_mechs, jabber_auth_get_digest_md5_mech(), compare_mech);
+	jabber_auth_add_mech(jabber_auth_get_plain_mech());
+	jabber_auth_add_mech(jabber_auth_get_digest_md5_mech());
 #ifdef HAVE_CYRUS_SASL
-	auth_mechs = g_slist_insert_sorted(auth_mechs, jabber_auth_get_cyrus_mech(), compare_mech);
+	jabber_auth_add_mech(jabber_auth_get_cyrus_mech());
 #endif
 
-	/* Facebook */
-	auth_mechs = g_slist_insert_sorted(auth_mechs, jabber_auth_get_fb_mech(), compare_mech);
-
 	tmp = jabber_auth_get_scram_mechs(&count);
 	for (i = 0; i < count; ++i)
-		auth_mechs = g_slist_insert_sorted(auth_mechs, tmp[i], compare_mech);
+		jabber_auth_add_mech(tmp[i]);
 }
 
 void jabber_auth_uninit(void)
============================================================
--- libpurple/protocols/jabber/auth.h	8ed6e72b0ded4367703f0a7c095d61ceae4a5ece
+++ libpurple/protocols/jabber/auth.h	af67b277a074a6c9f7ad0527733a1ee9cfe07f6e
@@ -57,8 +57,10 @@ JabberSaslMech *jabber_auth_get_cyrus_me
 #ifdef HAVE_CYRUS_SASL
 JabberSaslMech *jabber_auth_get_cyrus_mech(void);
 #endif
-JabberSaslMech *jabber_auth_get_fb_mech(void);
 
+void jabber_auth_add_mech(JabberSaslMech *);
+void jabber_auth_remove_mech(JabberSaslMech *);
+
 void jabber_auth_init(void);
 void jabber_auth_uninit(void);
 
============================================================
--- libpurple/protocols/jabber/fbapi.c	0542e3b2cf3e85c89d308bc6589382a74ef0e542
+++ /dev/null	
@@ -1,377 +0,0 @@
-/*
- * This is the property of its developers.  See the COPYRIGHT file
- * for more details.
- *
- * 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 3 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, see <http://www.gnu.org/licenses/>.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif /* HAVE_CONFIG_H */
-
-#include <sys/time.h>
-
-#include "internal.h"
-#include "cipher.h"
-#include "debug.h"
-#include "util.h"
-
-#include "fbapi.h"
-
-#define API_URL "http://api.facebook.com/restserver.php"
-#define API_SECRET "INSERT_SECRET_HERE"
-#define MAX_CONNECTION_ATTEMPTS 3
-
-struct _PurpleFbApiCall {
-	gchar *request;
-	PurpleUtilFetchUrlData *url_data;
-	PurpleFbApiCallback callback;
-	gpointer user_data;
-	GDestroyNotify user_data_destroy_func;
-	unsigned int attempt_number;
-};
-
-static GSList *apicalls = NULL;
-
-/*
- * Try to strip characters that are not valid XML.  The string is
- * changed in-place.  This was needed because of this bug:
- * http://bugs.developers.facebook.com/show_bug.cgi?id=2840
- * That bug has been fixed, so it's possible this isn't necessary
- * anymore.
- *
- * This page lists which characters are valid:
- * http://www.w3.org/TR/2008/REC-xml-20081126/#charsets
- *
- * Valid XML characters are:
- * #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
- *
- * Invalid XML characters are:
- * [#x0-#x8] | #xB | #xC | [#xE-#x1F] | [#xD800-#xDFFF] | #xFFFE | #xFFFF
- * | [#x110000-#xFFFFFFFF]
- *
- * Note: We could maybe use purple_utf8_strip_unprintables() for this (that
- *       function was added after we had already started using this), but
- *       we know this function works and changing it is scary.
- */
-static void purple_fbapi_xml_salvage(char *str)
-{
-	gchar *tmp;
-	gunichar unichar;
-
-	for (tmp = str; tmp[0] != '\0'; tmp = g_utf8_next_char(tmp))
-	{
-		unichar = g_utf8_get_char(tmp);
-		if ((unichar >= 0x1 && unichar <= 0x8)
-				|| unichar == 0xb
-				|| unichar == 0xc
-				|| (unichar >= 0xe && unichar <= 0x1f)
-				|| (unichar >= 0xd800 && unichar <= 0xdfff)
-				|| unichar == 0xfffe
-				|| unichar == 0xffff
-				|| unichar >= 0x110000)
-		{
-			/* This character is not valid XML so replace it with question marks */
-			purple_debug_error("fbapi", "Replacing invalid "
-					"XML character %08x with question marks\n",
-					unichar);
-
-			tmp[0] = '?';
-			if (unichar & 0x0000ff00)
-				tmp[1] = '?';
-			if (unichar & 0x00ff0000)
-				tmp[2] = '?';
-			if (unichar & 0xff000000)
-				tmp[3] = '?';
-		}
-	}
-}
-
-static void purple_fbapi_request_fetch_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message)
-{
-	PurpleFbApiCall *apicall;
-	xmlnode *response;
-	PurpleConnectionError error = PURPLE_CONNECTION_ERROR_OTHER_ERROR;
-	char *error_message2 = NULL;
-
-	apicall = user_data;
-
-	if (error_message != NULL) {
-		/* Request failed */
-
-		if (apicall->attempt_number < MAX_CONNECTION_ATTEMPTS) {
-			/* Retry! */
-			apicall->url_data = purple_util_fetch_url_request(API_URL,
-					TRUE, NULL, FALSE, apicall->request, FALSE,
-					purple_fbapi_request_fetch_cb, apicall);
-			apicall->attempt_number++;
-			return;
-		}
-
-		response = NULL;
-		error_message2 = g_strdup(error_message);
-		error = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
-	} else if (url_text != NULL && len > 0) {
-		/* Parse the response as XML */
-		response = xmlnode_from_str(url_text, len);
-
-		if (response == NULL)
-		{
-			gchar *salvaged;
-
-			if (g_utf8_validate(url_text, len, NULL)) {
-				salvaged = g_strdup(url_text);
-			} else {
-				/* Facebook responded with invalid UTF-8.  Bastards. */
-				purple_debug_error("fbapi", "Response is not valid UTF-8\n");
-				salvaged = purple_utf8_salvage(url_text);
-			}
-
-			purple_fbapi_xml_salvage(salvaged);
-			response = xmlnode_from_str(salvaged, -1);
-			g_free(salvaged);
-		}
-
-		if (response == NULL) {
-			purple_debug_error("fbapi", "Could not parse response as XML: %*s\n",
-			(int)len, url_text);
-			error_message2 = g_strdup(_("Invalid response from server"));
-		} else if (g_str_equal(response->name, "error_response")) {
-			/*
-			 * The response is an error message, in the standard format
-			 * for errors from API calls.
-			 */
-			xmlnode *tmp;
-			char *tmpstr;
-
-			tmp = xmlnode_get_child(response, "error_code");
-			if (tmp != NULL) {
-				tmpstr = xmlnode_get_data_unescaped(tmp);
-				if (tmpstr != NULL && strcmp(tmpstr, "293") == 0) {
-					error_message2 = g_strdup(_("Need chat permission"));
-					error = PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED;
-				}
-				g_free(tmpstr);
-			}
-			if (error_message2 == NULL) {
-				error = PURPLE_CONNECTION_ERROR_OTHER_ERROR;
-				tmp = xmlnode_get_child(response, "error_msg");
-				if (tmp != NULL)
-					error_message2 = xmlnode_get_data_unescaped(tmp);
-			}
-			if (error_message2 == NULL)
-				error_message2 = g_strdup(_("Unknown"));
-		} else {
-			error_message2 = NULL;
-		}
-	} else {
-		/* Response body was empty */
-		response = NULL;
-		error_message2 = NULL;
-	}
-
-	if (apicall->attempt_number > 1 || error_message2 != NULL)
-		purple_debug_error("fbapi", "Request '%s' %s after %u attempts: %s\n",
-				apicall->request,
-				error_message == NULL ? "succeeded" : "failed",
-				apicall->attempt_number, error_message2);
-
-	/*
-	 * The request either succeeded or failed the maximum number of
-	 * times.  In either case, pass control off to the callback
-	 * function and let them decide what to do.
-	 */
-	apicall->callback(apicall, apicall->user_data, response, error, error_message2);
-	apicall->url_data = NULL;
-	purple_fbapi_request_destroy(apicall);
-
-	xmlnode_free(response);
-	g_free(error_message2);
-}
-
-static gboolean concat_params(gpointer key, gpointer value, gpointer data)
-{
-	GString *tmp;
-
-	tmp = data;
-	g_string_append_printf(tmp, "%s=%s", (const char *)key, (const char *)value);
-
-	return FALSE;
-}
-
-/**
- * @return A Newly allocated base16 encoded version of the md5
- *         signature calculated using the algorithm described on the
- *         Facebook developer wiki.  This string must be g_free'd.
- */
-static char *generate_signature(const char *api_secret, const GTree *params)
-{
-	GString *tmp;
-	unsigned char hashval[16];
-
-	tmp = g_string_new(NULL);
-	g_tree_foreach((GTree *)params, concat_params, tmp);
-	g_string_append(tmp, api_secret);
-
-	purple_cipher_digest_region("md5", (const unsigned char *)tmp->str,
-			tmp->len, sizeof(hashval), hashval, NULL);
-	g_string_free(tmp, TRUE);
-
-	return purple_base16_encode(hashval, sizeof(hashval));
-}
-
-static gboolean append_params_to_body(gpointer key, gpointer value, gpointer data)
-{
-	GString *body;
-
-	body = data;
-
-	if (body->len > 0)
-		g_string_append_c(body, '&');
-
-	g_string_append(body, purple_url_encode(key));
-	g_string_append_c(body, '=');
-	g_string_append(body, purple_url_encode(value));
-
-	return FALSE;
-}
-
-static GString *purple_fbapi_construct_request_vargs(PurpleAccount *account, const char *method, va_list args)
-{
-	GTree *params;
-	const char *api_key, *api_secret;
-	const char *key, *value;
-	char call_id[21];
-	char *signature;
-	GString *body;
-
-	/* Read all paramters into a sorted tree */
-	params = g_tree_new((GCompareFunc)strcmp);
-	while ((key = va_arg(args, const char *)) != NULL)
-	{
-		value = va_arg(args, const char *);
-		g_tree_insert(params, (char *)key, (char *)value);
-
-		/* If we have a session_key then we need a call_id */
-		if (g_str_equal(key, "session_key")) {
-			struct timeval tv;
-			if (gettimeofday(&tv, NULL) != 0) {
-				time_t now;
-				purple_debug_error("fbapi",
-						"Error calling gettimeofday(): %s\n",
-						g_strerror(errno));
-				now = time(NULL);
-				strftime(call_id, sizeof(call_id), "%s000000", localtime(&now));
-			} else {
-				char tmp[22];
-				strftime(tmp, sizeof(tmp), "%s", localtime(&tv.tv_sec));
-				sprintf(call_id, "%s%06lu", tmp, tv.tv_usec);
-			}
-			g_tree_insert(params, "call_id", call_id);
-		}
-	}
-
-	api_key = purple_account_get_string(account, "fb_api_key", PURPLE_FBAPI_KEY);
-	api_secret = purple_account_get_string(account, "fb_api_secret", API_SECRET);
-
-	/* Add the method and api_key parameters to the list */
-	g_tree_insert(params, "method", (char *)method);
-	g_tree_insert(params, "api_key", (char *)api_key);
-
-	/* Add the signature parameter to the list */
-	signature = generate_signature((char *)api_secret, params);
-	g_tree_insert(params, "sig", signature);
-
-	/* Construct the body of the HTTP POST request */
-	body = g_string_new(NULL);
-	g_tree_foreach(params, append_params_to_body, body);
-	g_tree_destroy(params);
-	g_free(signature);
-
-	return body;
-}
-
-GString *purple_fbapi_construct_request(PurpleAccount *account, const char *method, ...)
-{
-	va_list args;
-	GString *body;
-
-	va_start(args, method);
-	body = purple_fbapi_construct_request_vargs(account, method, args);
-	va_end(args);
-
-	return body;
-}
-
-PurpleFbApiCall *purple_fbapi_request_vargs(PurpleAccount *account, PurpleFbApiCallback callback, gpointer user_data, GDestroyNotify user_data_destroy_func, const char *method, va_list args)
-{
-	GString *body;
-	PurpleFbApiCall *apicall;
-
-	body = purple_fbapi_construct_request_vargs(account, method, args);
-
-	/* Construct an HTTP POST request */
-	apicall = g_new(PurpleFbApiCall, 1);
-	apicall->callback = callback;
-	apicall->user_data = user_data;
-	apicall->user_data_destroy_func = user_data_destroy_func;
-	apicall->attempt_number = 1;
-
-	apicall->request = g_strdup_printf("POST /restserver.php HTTP/1.0\r\n"
-			"Connection: close\r\n"
-			"Accept: */*\r\n"
-			"Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n"
-			"Content-Length: %zu\r\n\r\n%s", body->len, body->str);
-	g_string_free(body, TRUE);
-
-	apicall->url_data = purple_util_fetch_url_request(API_URL,
-			TRUE, NULL, FALSE, apicall->request, FALSE,
-			purple_fbapi_request_fetch_cb, apicall);
-
-	apicalls = g_slist_prepend(apicalls, apicall);
-
-	return apicall;
-}
-
-PurpleFbApiCall *purple_fbapi_request(PurpleAccount *account, PurpleFbApiCallback callback, gpointer user_data, GDestroyNotify user_data_destroy_func, const char *method, ...)
-{
-	va_list args;
-	PurpleFbApiCall *apicall;
-
-	va_start(args, method);
-	apicall = purple_fbapi_request_vargs(account, callback, user_data, user_data_destroy_func, method, args);
-	va_end(args);
-
-	return apicall;
-}
-
-void purple_fbapi_request_destroy(PurpleFbApiCall *apicall)
-{
-	apicalls = g_slist_remove(apicalls, apicall);
-
-	if (apicall->url_data != NULL)
-		purple_util_fetch_url_cancel(apicall->url_data);
-
-	if (apicall->user_data != NULL && apicall->user_data_destroy_func != NULL)
-		apicall->user_data_destroy_func(apicall->user_data);
-
-	g_free(apicall->request);
-	g_free(apicall);
-}
-
-void purple_fbapi_uninit(void)
-{
-	while (apicalls != NULL)
-		purple_fbapi_request_destroy(apicalls->data);
-}
============================================================
--- libpurple/protocols/jabber/fbapi.h	577175234144e0463a77f0a69f7ff2d8cb5c49c4
+++ /dev/null	
@@ -1,106 +0,0 @@
-/*
- * libfacebook
- *
- * libfacebook is the property of its developers.  See the COPYRIGHT file
- * for more details.
- *
- * 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 3 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, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef FBAPI_H
-#define FBAPI_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <glib.h>
-
-#include "connection.h"
-
-#define PURPLE_FBAPI_KEY "INSERT_KEY_HERE"
-
-typedef struct _PurpleFbApiCall PurpleFbApiCall;
-
-/**
- * This is the callback function when a response is received to an API
- * request.  The response will always be parsed as XML.
- *
- * error_message will be set if the physical TCP connection failed, or
- * if the API call returned <error_response> as the top level node in
- * the document.
- *
- * error will be set if and only if error_message is set.
- *
- * response will be null if error_message is non-null or if the
- * response was not valid XML.  So if error_message == NULL &&
- * response == NULL then you know the body was malformed XML.
- */
-typedef void (*PurpleFbApiCallback)(PurpleFbApiCall *apicall, gpointer user_data, const xmlnode *response, PurpleConnectionError error, const gchar *error_message);
-
-/**
- * Construct the body of a Facebook API request.
- *
- * @param account PurpleAccount of the user
- * @param method The API method to call.  For example, auth.getSession or
- *        events.get.
- * @param attrs key/value pairs of request arguments.  The list must be
- *        terminated with a NULL.  It should not contain the method,
- *        api_key, call_id, or sig parameters--these will be appended
- *        for you.
- */
-GString *purple_fbapi_construct_request(PurpleAccount *account, const char *method, ...) G_GNUC_NULL_TERMINATED;
-
-/**
- * @param account PurpleAccount of the user
- * @param args key/value pairs that will be POSTed to the API URL.  The
- *        list must be terminated with a NULL.  It should not contain
- *        the method, api_key, call_id, or sig parameters--these will be
- *        appended for you.
- * @see purple_fbapi_request
- */
-PurpleFbApiCall *purple_fbapi_request_vargs(PurpleAccount *account, PurpleFbApiCallback callback, gpointer user_data, GDestroyNotify user_data_destroy_func, const char *method, va_list args);
-
-/**
- * @param account PurpleAccount of the user
- * @param callback The callback function that should be called when we
- *        receive a response from the server.
- * @param user_data Optional data to pass to the callback function.
- * @param user_data_destroy_func An option function to be called and
- *        passed user_data to free it after this request has finished
- *        or been canceled.
- * @param method The API method to call.  For example, auth.getSession or
- *        events.get.
- * @param attrs key/value pairs that will be POSTed to the API URL.  The
- *        list must be terminated with a NULL.  It should not contain
- *        the method, api_key, call_id, or sig parameters--these will be
- *        appended for you.
- */
-PurpleFbApiCall *purple_fbapi_request(PurpleAccount *account, PurpleFbApiCallback callback, gpointer user_data, GDestroyNotify user_data_destroy_func, const char *method, ...) G_GNUC_NULL_TERMINATED;
-
-/*
- * Destroy a single pending API request.
- */
-void purple_fbapi_request_destroy(PurpleFbApiCall *apicall);
-
-/**
- * Destroy all pending API requests.
- */
-void purple_fbapi_uninit(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* FBAPI_H */


More information about the Commits mailing list