grim/purple-spasm

Parents 132557e864b0
Children 255ea8d6611e
Initial revision, basic oauth flow is in but super happy pathed!
--- a/.hgignore Thu Apr 27 22:24:08 2017 -0500
+++ b/.hgignore Thu May 04 23:13:55 2017 -0500
@@ -2,3 +2,5 @@
*.dll
*.o
*.so
+*.sublime-workspace
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile Thu May 04 23:13:55 2017 -0500
@@ -0,0 +1,19 @@
+#!/usr/bin/make -f
+
+PIDGIN_TREE_TOP ?= ../pidgin-2.12.0
+WIN32_DEV_TOP ?= $(PIDGIN_TREE_TOP)/../win32-dev
+
+PLUGIN_NAME := purple-spasm
+PLUGIN_VERSION := 0.0.1
+PLUGIN_CFLAGS := \
+ $(shell pkg-config --cflags json-glib-1.0)
+PLUGIN_LIBRARIES := \
+ $(shell pkg-config --libs json-glib-1.0)
+PLUGIN_SOURCES := \
+ spasm.c \
+ spasm-auth.c
+PLUGIN_HEADERS := \
+ spasm-account.h \
+ spasm-auth.h \
+ spasm-const.h
+include libpurple.mk
--- a/helloworld.c Thu Apr 27 22:24:08 2017 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,66 +0,0 @@
-/*
- * HelloWorld - A hello world libpurple plugin
- * Copyright (C) 2006 John Bailey <rekkanoryo@rekkanoryo.org>
- *
- * 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 <glib.h>
-
-#define PURPLE_PLUGINS
-
-#include "notify.h"
-#include "plugin.h"
-#include "version.h"
-
-static gboolean
-plugin_load(PurplePlugin *plugin) {
- purple_notify_message(
- plugin,
- PURPLE_NOTIFY_MSG_INFO,
- "Hello World!",
- "This is the Hello World! plugin :)",
- NULL,
- NULL,
- NULL
- );
-
- return TRUE;
-}
-
-static PurplePluginInfo info = {
- .magic = PURPLE_PLUGIN_MAGIC,
- .major_version = PURPLE_MAJOR_VERSION,
- .minor_version = PURPLE_MINOR_VERSION,
- .type = PURPLE_PLUGIN_STANDARD,
- .priority = PURPLE_PRIORITY_DEFAULT,
-
- .id = "core-hello_world",
- .name = "Hello World!",
- .version = PLUGIN_VERSION,
-
- .summary = "Hello World Plugin",
- .description = "Hello World Plugin",
- .author = "My Name <email@helloworld.tld>",
- .homepage = "http://helloworld.tld",
-
- .load = plugin_load
-};
-
-static void
-init_plugin(PurplePlugin *plugin) {
-}
-
-PURPLE_INIT_PLUGIN(hello_world, init_plugin, info);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/purple-spasm.sublime-project Thu May 04 23:13:55 2017 -0500
@@ -0,0 +1,8 @@
+{
+ "folders":
+ [
+ {
+ "path": "."
+ }
+ ]
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/spasm-account.h Thu May 04 23:13:55 2017 -0500
@@ -0,0 +1,34 @@
+/*
+ * PurpleSpasm - A Twitch Protocol Plugin
+ * Copyright (C) 2017 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 PURPLE_SPASM_ACCOUNT_H
+#define PURPLE_SPASM_ACCOUNT_H
+
+#include <glib.h>
+
+#include "account.h"
+#include "connection.h"
+
+typedef struct {
+ PurpleAccount *account;
+ PurpleConnection *connection;
+ gchar *access_token;
+} SpasmAccount;
+
+#endif /* PURPLE_SPASM_ACCOUNT_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/spasm-auth.c Thu May 04 23:13:55 2017 -0500
@@ -0,0 +1,105 @@
+/*
+ * PurpleSpasm - A Twitch Protocol Plugin
+ * Copyright (C) 2017 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 "request.h"
+
+#include "spasm-account.h"
+#include "spasm-auth.h"
+#include "spasm-const.h"
+
+/******************************************************************************
+ * Helpers
+ *****************************************************************************/
+static void
+purple_spasm_access_token_input_cb(gpointer data, const gchar *access_token) {
+ SpasmAccount *sa = data;
+
+ g_free(sa->access_token);
+ sa->access_token = (access_token) ? g_strdup(access_token) : NULL;
+
+ purple_account_set_remember_password(sa->account, TRUE);
+ purple_account_set_password(sa->account, sa->access_token);
+
+ purple_connection_set_state(sa->connection, PURPLE_CONNECTED);
+}
+
+static void
+purple_spasm_access_token_cancel_cb(gpointer data) {
+ SpasmAccount *sa = data;
+ purple_connection_error(
+ sa->connection,
+ "User cancelled authorization"
+ );
+}
+
+/******************************************************************************
+ * API
+ *****************************************************************************/
+void
+purple_spasm_login(PurpleAccount *account) {
+ PurpleConnection *pc = NULL;
+ SpasmAccount *sa = NULL;
+ gchar *state = NULL, *uri = NULL;
+ const gchar *username = NULL;
+
+ pc = purple_account_get_connection(account);
+ username = purple_account_get_username(account);
+
+ sa = g_new0(SpasmAccount, 1);
+ purple_connection_set_protocol_data(pc, sa);
+
+ sa->account = account;
+ sa->connection = pc;
+
+ purple_connection_set_state(pc, PURPLE_CONNECTING);
+
+ state = g_strdup_printf("%s,%s", PURPLE_SPASM_PLUGIN_ID, username);
+
+ uri = g_strdup_printf(
+ PURPLE_SPASM_OAUTH2_URI,
+ PURPLE_SPASM_OAUTH2_CLIENT_ID,
+ PURPLE_SPASM_OAUTH2_REDIRECT_URI,
+ PURPLE_SPASM_OAUTH2_SCOPES,
+ state
+ );
+ g_free(state);
+
+ purple_connection_update_progress(sa->connection, "Authenticating", 1, 2);
+
+ /* send off the oauth implicit request */
+ purple_notify_uri(pc, uri);
+ g_free(uri);
+
+ purple_request_input(
+ pc,
+ "Access Token",
+ "Enter the access token from https://pidgin.im/oauth.html which should have opened in your web browser",
+ NULL,
+ "access token",
+ FALSE,
+ TRUE,
+ NULL,
+ "OK", G_CALLBACK(purple_spasm_access_token_input_cb),
+ "Cancel", G_CALLBACK(purple_spasm_access_token_cancel_cb),
+ sa->account,
+ NULL,
+ NULL,
+ sa
+ );
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/spasm-auth.h Thu May 04 23:13:55 2017 -0500
@@ -0,0 +1,33 @@
+/*
+ * PurpleSpasm - A Twitch Protocol Plugin
+ * Copyright (C) 2017 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 PURPLE_SPASM_AUTH_H
+#define PURPLE_SPASM_AUTH_H
+
+#include <glib.h>
+
+#include "account.h"
+
+G_BEGIN_DECLS
+
+void purple_spasm_login(PurpleAccount *account);
+
+G_END_DECLS
+
+#endif /* PURPLE_SPASM_AUTH_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/spasm-const.h Thu May 04 23:13:55 2017 -0500
@@ -0,0 +1,34 @@
+/*
+ * PurpleSpasm - A Twitch Protocol Plugin
+ * Copyright (C) 2017 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 PURPLE_SPASM_CONSTS_H
+#define PURPLE_SPASM_CONSTS_H
+
+#define PURPLE_SPASM_PLUGIN_ID "prpl-grim-spasm"
+#define PURPLE_SPASM_OAUTH2_CLIENT_ID "w7le4wyxwbipv6kf5qmqogwkqskl12"
+#define PURPLE_SPASM_OAUTH2_SCOPES "user_read chat_login"
+#define PURPLE_SPASM_OAUTH2_REDIRECT_URI "https://pidgin.im/oauth.html"
+#define PURPLE_SPASM_OAUTH2_URI "https://api.twitch.tv/kraken/oauth2/authorize?" \
+ "response_type=token&" \
+ "client_id=%s&" \
+ "redirect_uri=%s&" \
+ "scope=%s&" \
+ "state=%s"
+
+#endif /* PURPLE_SPASM_CONSTS_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/spasm.c Thu May 04 23:13:55 2017 -0500
@@ -0,0 +1,112 @@
+/*
+ * PurpleSpasm - A Twitch Protocol Plugin
+ * Copyright (C) 2017 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 <glib.h>
+
+#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 "spasm-account.h"
+#include "spasm-auth.h"
+#include "spasm-const.h"
+
+/******************************************************************************
+ * Helpers
+ *****************************************************************************/
+/******************************************************************************
+ * Implementations
+ *****************************************************************************/
+static const gchar *
+purple_spasm_list_icon(PurpleAccount *account, PurpleBuddy *buddy) {
+ return NULL;
+}
+
+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
+ *****************************************************************************/
+static PurplePluginProtocolInfo prpl_info = {
+ .struct_size = sizeof(PurplePluginProtocolInfo),
+
+ .options = OPT_PROTO_NO_PASSWORD,
+
+ .login = purple_spasm_login,
+ .close = purple_spasm_close,
+ .list_icon = purple_spasm_list_icon,
+
+ .status_types = purple_spasm_get_status_types,
+ .set_status = purple_spasm_set_status,
+};
+
+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,
+
+ .id = PURPLE_SPASM_PLUGIN_ID,
+ .name = "Twitch",
+ .version = PLUGIN_VERSION,
+ .extra_info = &prpl_info,
+
+ .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
+init_plugin(PurplePlugin *plugin) {
+}
+
+PURPLE_INIT_PLUGIN(purple_spasm, init_plugin, info);