grim/purple-spasm

Parents fb6230d70ac7
Children 1f592ea4eaf0
Get this working again with pidgin3 only, we're not going to support pidgin2
--- a/meson.build Mon Nov 12 14:35:10 2018 -0600
+++ b/meson.build Mon Sep 30 22:55:04 2019 -0500
@@ -8,6 +8,7 @@
'spasm.c',
'spasm-account.c',
'spasm-chat.c',
+ 'spasm-protocol.c',
'spasm-rest.c',
'spasm-user.c',
]
@@ -20,17 +21,17 @@
language : 'c'
)
-PURPLE = dependency('purple', version: '>=2.0.0')
JSON_GLIB = dependency('json-glib-1.0')
SOUP = dependency('libsoup-2.4')
+PURPLE3 = dependency('purple-3', version: '>=3.0.0')
shared_library(
- meson.project_name(),
+ meson.project_name() + '3',
SOURCES,
name_prefix: '',
- dependencies: [PURPLE, JSON_GLIB, SOUP],
+ dependencies: [PURPLE3, JSON_GLIB, SOUP],
install: true,
- install_dir: PURPLE.get_pkgconfig_variable('plugindir'),
+ install_dir: join_paths(get_option('libdir'), 'purple3'),
)
subdir('icons')
--- a/spasm-account.c Mon Nov 12 14:35:10 2018 -0600
+++ b/spasm-account.c Mon Sep 30 22:55:04 2019 -0500
@@ -17,8 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "debug.h"
-#include "request.h"
+#include <purple.h>
#include "spasm.h"
#include "spasm-account.h"
@@ -172,7 +171,11 @@
g_error_free(error);
- purple_connection_error(connection, err_msg);
+ purple_connection_error(
+ connection,
+ PURPLE_CONNECTION_ERROR_OTHER_ERROR,
+ err_msg
+ );
g_free(err_msg);
@@ -193,7 +196,7 @@
purple_account_set_remember_password(account, TRUE);
_purple_spasm_account_set_access_token(sa, access_token);
- purple_account_set_password(account, access_token);
+ purple_account_set_password(account, access_token, NULL, NULL);
connection = purple_spasm_account_get_connection(sa);
purple_connection_update_progress(connection, "Verifying", 2, 3);
@@ -207,6 +210,7 @@
purple_connection_error(
purple_spasm_account_get_connection(sa),
+ PURPLE_CONNECTION_ERROR_OTHER_ERROR,
"User cancelled authorization"
);
@@ -217,6 +221,7 @@
_purple_spasm_oauth_login(PurpleSpasmAccount *sa) {
PurpleAccount *account = NULL;
PurpleConnection *connection = NULL;
+ PurpleRequestCommonParameters *cpar = NULL;
gchar *state = NULL, *uri = NULL;
const gchar *username = NULL;
@@ -246,6 +251,8 @@
purple_notify_uri(connection, uri);
g_free(uri);
+ cpar = purple_request_cpar_from_account(account);
+
purple_request_input(
connection,
"Access Token",
@@ -257,9 +264,7 @@
NULL,
"OK", G_CALLBACK(_purple_spasm_access_token_input_cb),
"Cancel", G_CALLBACK(_purple_spasm_access_token_cancel_cb),
- account,
- NULL,
- NULL,
+ cpar,
sa
);
}
@@ -293,7 +298,7 @@
g_return_val_if_fail(sa, NULL);
if(sa->session) {
- return g_object_ref(G_OBJECT(sa->session));
+ return SOUP_SESSION(g_object_ref(sa->session));
}
return NULL;
@@ -376,21 +381,12 @@
return sa->twitter_connected;
}
-void
-purple_spasm_account_login(PurpleAccount *account) {
- PurpleConnection *pc = NULL;
- PurpleSpasmAccount *sa = NULL;
- const gchar *password = NULL;
-
- pc = purple_account_get_connection(account);
+static void
+spasm_account_login_got_password(PurpleAccount *account, const gchar *password,
+ GError *error, gpointer data)
+{
+ PurpleSpasmAccount *sa = PURPLE_SPASM_ACCOUNT(data);
- sa = purple_spasm_account_new(account, pc);
- purple_connection_set_protocol_data(pc, sa);
-
- purple_connection_set_state(pc, PURPLE_CONNECTING);
-
- /* try to load the password */
- password = purple_account_get_password(account);
if(password != NULL) {
_purple_spasm_account_set_access_token(sa, password);
purple_spasm_get_user(sa, _purple_spasm_login_test_cb, NULL);
@@ -399,3 +395,19 @@
}
}
+void
+purple_spasm_account_login(PurpleAccount *account) {
+ PurpleConnection *pc = NULL;
+ PurpleSpasmAccount *sa = NULL;
+
+ pc = purple_account_get_connection(account);
+
+ sa = purple_spasm_account_new(account, pc);
+ purple_connection_set_protocol_data(pc, sa);
+
+ purple_connection_set_state(pc, PURPLE_CONNECTION_CONNECTING);
+
+ /* try to load the password */
+ purple_account_get_password(account, spasm_account_login_got_password, sa);
+}
+
--- a/spasm-account.h Mon Nov 12 14:35:10 2018 -0600
+++ b/spasm-account.h Mon Sep 30 22:55:04 2019 -0500
@@ -1,6 +1,6 @@
/*
* PurpleSpasm - A Twitch Protocol Plugin
- * Copyright (C) 2017 Gary Kramlich <grim@reaperworld.com>
+ * Copyright (C) 2017-2019 Gary Kramlich <grim@reaperworld.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -26,8 +26,7 @@
#include <libsoup/soup.h>
-#include "account.h"
-#include "connection.h"
+#include <purple.h>
#define PURPLE_SPASM_ACCOUNT(obj) ((PurpleSpasmAccount *)(obj))
--- a/spasm-chat.c Mon Nov 12 14:35:10 2018 -0600
+++ b/spasm-chat.c Mon Sep 30 22:55:04 2019 -0500
@@ -1,6 +1,6 @@
/*
* PurpleSpasm - A Twitch Protocol Plugin
- * Copyright (C) 2017 Gary Kramlich <grim@reaperworld.com>
+ * Copyright (C) 2017-2019 Gary Kramlich <grim@reaperworld.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -22,8 +22,7 @@
#include <stdarg.h>
-#include "debug.h"
-#include "util.h"
+#include <purple.h>
/******************************************************************************
* Structs
@@ -70,11 +69,19 @@
PurpleConnection *purple_connection = purple_spasm_account_get_connection(chat->sa);
if(error) {
- purple_connection_error(purple_connection, error->message);
+ purple_connection_error(
+ purple_connection,
+ PURPLE_CONNECTION_ERROR_OTHER_ERROR,
+ error->message
+ );
g_error_free(error);
} else {
- purple_connection_error(purple_connection, "unknown error");
+ purple_connection_error(
+ purple_connection,
+ PURPLE_CONNECTION_ERROR_OTHER_ERROR,
+ "unknown error"
+ );
}
return;
@@ -124,12 +131,15 @@
"spasm lost connection with server : %s",
error->message
);
+
+ g_error_free(error);
} else {
error_msg = g_strdup_printf("spasm server closed connection");
}
purple_connection_error(
purple_spasm_account_get_connection(chat->sa),
+ PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
error_msg
);
@@ -179,11 +189,19 @@
if(error) {
g_prefix_error(&error, "failed to connect: ");
- purple_connection_error(purple_connection, error->message);
+ purple_connection_error(
+ purple_connection,
+ PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
+ error->message
+ );
g_error_free(error);
} else {
- purple_connection_error(purple_connection, "unknown error");
+ purple_connection_error(
+ purple_connection,
+ PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
+ "unknown error"
+ );
}
return;
@@ -205,7 +223,7 @@
purple_spasm_account_get_name(chat->sa)
);
- purple_connection_set_state(purple_connection, PURPLE_CONNECTED);
+ purple_connection_set_state(purple_connection, PURPLE_CONNECTION_CONNECTED);
chat->input_stream = g_data_input_stream_new(
g_io_stream_get_input_stream(G_IO_STREAM(chat->socket_connection))
@@ -256,14 +274,7 @@
GList *
purple_spasm_chat_service_info(PurpleConnection *connection) {
- struct proto_chat_entry *pce;
-
- pce = g_new0(struct proto_chat_entry, 1);
- pce->label = "_Channel:";
- pce->identifier = "channel";
- pce->required = TRUE;
-
- return g_list_append(NULL, pce);
+ return NULL;
}
GHashTable *
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/spasm-protocol.c Mon Sep 30 22:55:04 2019 -0500
@@ -0,0 +1,87 @@
+/*
+ * PurpleSpasm - A Twitch Protocol Plugin
+ * Copyright (C) 2017-2019 Gary Kramlich <grim@reaperworld.com>
+ *
+ * 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 02110-1301, USA.
+ */
+
+#include "spasm-protocol.h"
+#include "spasm-account.h"
+
+/******************************************************************************
+ * PurpleProtocol implementation
+ *****************************************************************************/
+static const gchar *
+spasm_protocol_list_icon(PurpleAccount *account, PurpleBuddy *buddy) {
+ return "spasm";
+}
+
+static void
+spasm_protocol_close(PurpleConnection *connection) {
+}
+
+static GList *
+spasm_protocol_get_status_types(PurpleAccount *account) {
+ GList *types = NULL;
+ PurpleStatusType *status;
+
+ status = purple_status_type_new_full(PURPLE_STATUS_AVAILABLE, "online", "Online", TRUE, TRUE, FALSE);
+ types = g_list_append(types, status);
+
+ status = purple_status_type_new_full(PURPLE_STATUS_OFFLINE, NULL, "Offline", TRUE, TRUE, FALSE);
+ types = g_list_append(types, status);
+
+ return types;
+}
+
+/******************************************************************************
+ * GObject Implementation
+ *****************************************************************************/
+G_DEFINE_DYNAMIC_TYPE(
+ SpasmProtocol,
+ spasm_protocol,
+ PURPLE_TYPE_PROTOCOL
+)
+
+static void
+spasm_protocol_init(SpasmProtocol *protocol) {
+ PurpleProtocol *prpl = PURPLE_PROTOCOL(protocol);
+
+ prpl->id = "prpl-grim-spasm";
+ prpl->name = "Twitch";
+ prpl->options = OPT_PROTO_NO_PASSWORD;
+}
+
+static void
+spasm_protocol_class_init(SpasmProtocolClass *klass) {
+ PurpleProtocolClass *protocol_class = PURPLE_PROTOCOL_CLASS(klass);
+
+ protocol_class->login = purple_spasm_account_login;
+ protocol_class->list_icon = spasm_protocol_list_icon;
+ protocol_class->close = spasm_protocol_close;
+ protocol_class->status_types = spasm_protocol_get_status_types;
+}
+
+static void
+spasm_protocol_class_finalize(SpasmProtocolClass *klass) {
+}
+
+/******************************************************************************
+ * API
+ *****************************************************************************/
+void
+spasm_protocol_register(GTypeModule *module) {
+ spasm_protocol_register_type(module);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/spasm-protocol.h Mon Sep 30 22:55:04 2019 -0500
@@ -0,0 +1,55 @@
+/*
+ * PurpleSpasm - A Twitch Protocol Plugin
+ * Copyright (C) 2017-2019 Gary Kramlich <grim@reaperworld.com>
+ *
+ * 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 02110-1301, USA.
+ */
+
+#ifndef SPASM_PROTOCOL_H
+#define SPASM_PROTOCOL_H
+
+#include <purple.h>
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define SPASM_TYPE_PROTOCOL (spasm_protocol_get_type())
+#define SPASM_PROTOCOL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SPASM_TYPE_PROTOCOL, SpasmProtocol))
+#define SPASM_PROTOCOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SPASM_TYPE_PROTOCOL, SpasmProtocolClass))
+
+typedef struct _SpasmProtocol SpasmProtocol;
+typedef struct _SpasmProtocolClass SpasmProtocolClass;
+
+struct _SpasmProtocol {
+ /*< private >*/
+ PurpleProtocol parent;
+
+ gpointer reserved[4];
+};
+
+struct _SpasmProtocolClass {
+ /*< private >*/
+ PurpleProtocolClass parent;
+
+ gpointer reserved[4];
+};
+
+GType spasm_protocol_get_type(void);
+void spasm_protocol_register(GTypeModule *module);
+
+G_END_DECLS
+
+#endif
--- a/spasm-rest.c Mon Nov 12 14:35:10 2018 -0600
+++ b/spasm-rest.c Mon Sep 30 22:55:04 2019 -0500
@@ -19,7 +19,7 @@
#include <libsoup/soup.h>
-#include "debug.h"
+#include <purple.h>
#include "spasm.h"
#include "spasm-const.h"
--- a/spasm-user.c Mon Nov 12 14:35:10 2018 -0600
+++ b/spasm-user.c Mon Sep 30 22:55:04 2019 -0500
@@ -19,7 +19,7 @@
#include <json-glib/json-glib.h>
-#include "debug.h"
+#include <purple.h>
#include "spasm-user.h"
#include "spasm-rest.h"
--- a/spasm.c Mon Nov 12 14:35:10 2018 -0600
+++ b/spasm.c Mon Sep 30 22:55:04 2019 -0500
@@ -21,58 +21,25 @@
#define PURPLE_PLUGINS
-#include "account.h"
-#include "blist.h"
-#include "connection.h"
-#include "debug.h"
-#include "notify.h"
-#include "plugin.h"
-#include "prpl.h"
-#include "request.h"
-#include "status.h"
-#include "version.h"
+#include <purple.h>
#include "spasm-account.h"
#include "spasm-const.h"
+#include "spasm-protocol.h"
/******************************************************************************
- * Helpers
+ * Globals
*****************************************************************************/
+static PurpleProtocol *spasm = NULL;
+
/******************************************************************************
* Implementations
*****************************************************************************/
-static const gchar *
-_purple_spasm_list_icon(PurpleAccount *account, PurpleBuddy *buddy) {
- return "spasm";
-}
-
-static void
-_purple_spasm_close(PurpleConnection *connection) {
-
-}
-
-static GList *
-_purple_spasm_get_status_types(PurpleAccount *account) {
- GList *types = NULL;
- PurpleStatusType *status;
-
- status = purple_status_type_new_full(PURPLE_STATUS_AVAILABLE, "online", "Online", TRUE, TRUE, FALSE);
- types = g_list_append(types, status);
-
- status = purple_status_type_new_full(PURPLE_STATUS_OFFLINE, NULL, "Offline", TRUE, TRUE, FALSE);
- types = g_list_append(types, status);
-
- return types;
-}
-
-static void
-_purple_spasm_set_status(PurpleAccount *account, PurpleStatus *status) {
-
-}
/******************************************************************************
* Plugin Stuff
*****************************************************************************/
+#if 0
static PurplePluginProtocolInfo prpl_info = {
.struct_size = sizeof(PurplePluginProtocolInfo),
@@ -94,27 +61,47 @@
.chat_send = purple_spasm_chat_service_send,
.set_chat_topic = purple_spasm_chat_service_set_topic,
};
+#endif
-static PurplePluginInfo info = {
- .magic = PURPLE_PLUGIN_MAGIC,
- .major_version = PURPLE_MAJOR_VERSION,
- .minor_version = PURPLE_MINOR_VERSION,
- .type = PURPLE_PLUGIN_PROTOCOL,
- .priority = PURPLE_PRIORITY_DEFAULT,
+/******************************************************************************
+ * GPlugin Interface
+ *****************************************************************************/
+G_MODULE_EXPORT GPluginPluginInfo *
+gplugin_query(GError **error) {
+ const gchar * const authors [] = { "Gary Kramlich <grim@reaperworld.com>", NULL };
- .id = PURPLE_SPASM_PLUGIN_ID,
- .name = "Twitch",
- .version = PLUGIN_VERSION,
- .extra_info = &prpl_info,
+ return GPLUGIN_PLUGIN_INFO(purple_plugin_info_new(
+ "id", PURPLE_SPASM_PLUGIN_ID,
+ "name", "Twitch",
+ "version", PLUGIN_VERSION,
+ "abi-version", PURPLE_ABI_VERSION,
+ "flags", PURPLE_PLUGIN_INFO_FLAGS_INTERNAL | PURPLE_PLUGIN_INFO_FLAGS_AUTO_LOAD,
- .summary = "Twitch.tv Protocol Plugin",
- .description = "Implements the Twitch.tv chat protocol",
- .author = "Gary Kramlich <grim@reaperworld.com>",
- .homepage = "https://bitbucket.org/rw_grim/purple-spasm",
-};
-
-static void
-_purple_spasm_init(PurplePlugin *plugin) {
+ "summary", "Twitch.tv Protocol Plugin",
+ "description", "Implements the Twitch.tv chat protocol",
+ "authors", authors,
+ "website", "https://bitbucket.org/rw_grim/purple-spasm",
+
+ NULL
+ ));
}
-PURPLE_INIT_PLUGIN(purple_spasm, _purple_spasm_init, info);
+G_MODULE_EXPORT gboolean
+gplugin_load(GPluginPlugin *plugin, GError **error) {
+ spasm_protocol_register(G_TYPE_MODULE(plugin));
+
+ spasm = purple_protocols_add(SPASM_TYPE_PROTOCOL, error);
+ if(spasm == NULL) {
+ g_warning("instance was null");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+G_MODULE_EXPORT gboolean
+gplugin_unload(GPluginPlugin *plugin, GError **error) {
+ spasm = NULL;
+
+ return TRUE;
+}