grim/purple-spasm

Parents 9f4a141b8eee
Children 99c8b92f6aaf
A ton of work, fixed reusing oauth tokens and started the chat login
--- a/Makefile Fri May 12 00:58:27 2017 -0500
+++ b/Makefile Tue May 16 21:22:43 2017 -0500
@@ -10,6 +10,7 @@
spasm.c \
spasm-account.c \
spasm-auth.c \
+ spasm-chat.c \
spasm-rest.c \
spasm-user.c
@@ -17,6 +18,7 @@
spasm.h \
spasm-account.h \
spasm-auth.h \
+ spasm-chat.h \
spasm-const.h \
spasm-rest.h \
spasm-user.h
--- a/spasm-account.c Fri May 12 00:58:27 2017 -0500
+++ b/spasm-account.c Tue May 16 21:22:43 2017 -0500
@@ -26,6 +26,11 @@
PurpleAccount *account;
PurpleConnection *connection;
+ GCancellable *cancellable;
+ GSocketClient *socket_client;
+ GSocketConnection *socket_connection;
+ GOutputStream *output_stream;
+
SoupSession *session;
gchar *access_token;
@@ -59,7 +64,6 @@
SoupLogger *logger = soup_logger_new(SOUP_LOGGER_LOG_BODY, -1);
soup_session_add_feature(sa->session, SOUP_SESSION_FEATURE(logger));
-
return sa;
}
@@ -69,6 +73,8 @@
g_free(sa->access_token);
+ g_object_unref(G_OBJECT(sa->socket_connection));
+ g_object_unref(G_OBJECT(sa->output_stream));
g_object_unref(G_OBJECT(sa->session));
g_free(sa);
@@ -88,6 +94,39 @@
return sa->connection;
}
+void
+purple_spasm_account_set_socket_connection(
+ PurpleSpasmAccount *sa,
+ GSocketConnection *socket_connection)
+{
+ g_return_if_fail(sa);
+
+ if(sa->socket_connection)
+ g_object_unref(G_OBJECT(sa->socket_connection));
+
+ sa->socket_connection = socket_connection;
+}
+
+void
+purple_spasm_account_set_output_stream(
+ PurpleSpasmAccount *sa,
+ GOutputStream *output_stream)
+{
+ g_return_if_fail(sa);
+
+ if(sa->output_stream)
+ g_object_unref(G_OBJECT(sa->output_stream));
+
+ sa->output_stream = output_stream;
+}
+
+GCancellable *
+purple_spasm_account_get_cancellable(const PurpleSpasmAccount *sa) {
+ g_return_val_if_fail(sa, NULL);
+
+ return sa->cancellable;
+}
+
SoupSession *
purple_spasm_account_get_session(const PurpleSpasmAccount *sa) {
g_return_val_if_fail(sa, NULL);
--- a/spasm-account.h Fri May 12 00:58:27 2017 -0500
+++ b/spasm-account.h Tue May 16 21:22:43 2017 -0500
@@ -41,6 +41,11 @@
PurpleAccount *purple_spasm_account_get_account(const PurpleSpasmAccount *sa);
PurpleConnection *purple_spasm_account_get_connection(const PurpleSpasmAccount *sa);
+void purple_spasm_account_set_socket_connection(PurpleSpasmAccount *sa, GSocketConnection *socket_connection);
+void purple_spasm_account_set_output_stream(PurpleSpasmAccount *sa, GOutputStream *output_stream);
+
+GCancellable *purple_spasm_account_get_cancellable(const PurpleSpasmAccount *sa);
+
SoupSession *purple_spasm_account_get_session(const PurpleSpasmAccount *sa);
void purple_spasm_account_set_access_token(PurpleSpasmAccount *sa, const gchar *access_token);
--- a/spasm-auth.c Fri May 12 00:58:27 2017 -0500
+++ b/spasm-auth.c Tue May 16 21:22:43 2017 -0500
@@ -24,6 +24,7 @@
#include "spasm-account.h"
#include "spasm-auth.h"
+#include "spasm-chat.h"
#include "spasm-const.h"
#include "spasm-user.h"
@@ -71,7 +72,7 @@
return;
}
- purple_connection_set_state(connection, PURPLE_CONNECTED);
+ purple_spasm_chat_login(sa);
}
static void
@@ -174,6 +175,7 @@
/* 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);
} else {
_purple_spasm_oauth_login(sa);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/spasm-chat.c Tue May 16 21:22:43 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 "spasm-chat.h"
+#include "spasm-const.h"
+
+#include "debug.h"
+
+static void
+_purple_spasm_chat_login_cb(GObject *obj, GAsyncResult *res, gpointer data) {
+ GCancellable *cancellable = NULL;
+ GError *error = NULL;
+ GOutputStream *output = NULL;
+ GSocketConnection *socket_connection = NULL;
+ PurpleConnection *purple_connection = NULL;
+ PurpleSpasmAccount *sa = (PurpleSpasmAccount *)data;
+ gboolean auth_success = FALSE;
+
+ cancellable = purple_spasm_account_get_cancellable(sa);
+ purple_connection = purple_spasm_account_get_connection(sa);
+
+ socket_connection = g_socket_client_connect_to_host_finish(
+ G_SOCKET_CLIENT(obj),
+ res,
+ &error
+ );
+
+ if(socket_connection == NULL) {
+ if(error) {
+ g_prefix_error(&error, "failed to connect: ");
+
+ purple_connection_error(purple_connection, error->message);
+
+ g_error_free(error);
+ } else {
+ purple_connection_error(purple_connection, "unknown error");
+ }
+
+ return;
+ }
+
+ purple_spasm_account_set_socket_connection(sa, socket_connection);
+
+ output = g_io_stream_get_output_stream(G_IO_STREAM(socket_connection));
+
+ /* now do the login */
+ auth_success = g_output_stream_printf(
+ output,
+ NULL,
+ cancellable,
+ &error,
+ "PASS oauth:%s",
+ purple_spasm_account_get_access_token(sa)
+ );
+ if(!auth_success) {
+ if(error) {
+ g_prefix_error(&error, "failed to connect: ");
+
+ purple_connection_error(purple_connection, error->message);
+
+ g_error_free(error);
+ } else {
+ purple_connection_error(purple_connection, "unknown error");
+ }
+
+ return;
+ }
+
+ /* now try to use our nick */
+
+}
+
+void
+purple_spasm_chat_login(PurpleSpasmAccount *sa) {
+ GSocketClient *socket_client = NULL;
+
+ purple_debug_info("spasm", "attempting to login to the chat server\n");
+
+ socket_client = g_socket_client_new();
+
+ g_socket_client_connect_to_host_async(
+ socket_client,
+ PURPLE_SPASM_CHAT_HOSTNAME,
+ PURPLE_SPASM_CHAT_PORT,
+ purple_spasm_account_get_cancellable(sa),
+ _purple_spasm_chat_login_cb,
+ sa
+ );
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/spasm-chat.h Tue May 16 21:22:43 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_CHAT
+#define PURPLE_SPASM_CHAT
+
+#include <glib.h>
+
+#include "spasm-account.h"
+
+G_BEGIN_DECLS
+
+void purple_spasm_chat_login(PurpleSpasmAccount *sa);
+
+G_END_DECLS
+
+#endif /* PURPLE_SPASM_CHAT */
--- a/spasm-const.h Fri May 12 00:58:27 2017 -0500
+++ b/spasm-const.h Tue May 16 21:22:43 2017 -0500
@@ -21,9 +21,14 @@
#define PURPLE_SPASM_CONSTS_H
#define PURPLE_SPASM_PLUGIN_ID "prpl-grim-spasm"
+
+#define PURPLE_SPASM_CHAT_HOSTNAME "irc.chat.twitch.tv"
+#define PURPLE_SPASM_CHAT_PORT 6667
+
#define PURPLE_SPASM_BASE_URL "https://api.twitch.tv/kraken/"
#define PURPLE_SPASM_WEBSOCKET_URL "wss://pubsub-edge.twitch.tv"
#define PURPLE_SPASM_CONTENT_TYPE "application/vnd.twitchtv.v5+json"
+
#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"
--- a/spasm-rest.c Fri May 12 00:58:27 2017 -0500
+++ b/spasm-rest.c Tue May 16 21:22:43 2017 -0500
@@ -176,7 +176,7 @@
soup_session_send_async(
session,
msg,
- NULL,
+ purple_spasm_account_get_cancellable(sa),
_purple_spasm_request_cb,
cb
);
--- a/spasm-user.h Fri May 12 00:58:27 2017 -0500
+++ b/spasm-user.h Tue May 16 21:22:43 2017 -0500
@@ -22,8 +22,6 @@
#include <glib.h>
-#include <json-glib/json-glib.h>
-
#include "spasm-account.h"
#include "spasm-rest.h"