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 @@
@@ -17,6 +18,7 @@
--- 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 @@
PurpleConnection *connection;
+ GCancellable *cancellable; + GSocketClient *socket_client; + GSocketConnection *socket_connection; + GOutputStream *output_stream; @@ -59,7 +64,6 @@
SoupLogger *logger = soup_logger_new(SOUP_LOGGER_LOG_BODY, -1);
soup_session_add_feature(sa->session, SOUP_SESSION_FEATURE(logger));
@@ -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));
@@ -88,6 +94,39 @@
+purple_spasm_account_set_socket_connection( + PurpleSpasmAccount *sa, + GSocketConnection *socket_connection) + if(sa->socket_connection) + g_object_unref(G_OBJECT(sa->socket_connection)); + sa->socket_connection = socket_connection; +purple_spasm_account_set_output_stream( + PurpleSpasmAccount *sa, + GOutputStream *output_stream) + g_object_unref(G_OBJECT(sa->output_stream)); + sa->output_stream = output_stream; +purple_spasm_account_get_cancellable(const PurpleSpasmAccount *sa) { + g_return_val_if_fail(sa, NULL); + return sa->cancellable; 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"
@@ -71,7 +72,7 @@
- purple_connection_set_state(connection, PURPLE_CONNECTED);
+ purple_spasm_chat_login(sa); @@ -174,6 +175,7 @@
/* try to load the password */
password = purple_account_get_password(account);
+ purple_spasm_account_set_access_token(sa, password); purple_spasm_get_user(sa, _purple_spasm_login_test_cb, NULL);
_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-const.h" +_purple_spasm_chat_login_cb(GObject *obj, GAsyncResult *res, gpointer data) { + GCancellable *cancellable = 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( + if(socket_connection == NULL) { + g_prefix_error(&error, "failed to connect: "); + purple_connection_error(purple_connection, error->message); + purple_connection_error(purple_connection, "unknown error"); + purple_spasm_account_set_socket_connection(sa, socket_connection); + output = g_io_stream_get_output_stream(G_IO_STREAM(socket_connection)); + auth_success = g_output_stream_printf( + purple_spasm_account_get_access_token(sa) + g_prefix_error(&error, "failed to connect: "); + purple_connection_error(purple_connection, error->message); + purple_connection_error(purple_connection, "unknown error"); + /* now try to use our nick */ +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( + PURPLE_SPASM_CHAT_HOSTNAME, + PURPLE_SPASM_CHAT_PORT, + purple_spasm_account_get_cancellable(sa), + _purple_spasm_chat_login_cb, --- /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 "spasm-account.h" +void purple_spasm_chat_login(PurpleSpasmAccount *sa); +#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 @@
+ purple_spasm_account_get_cancellable(sa), _purple_spasm_request_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 <json-glib/json-glib.h>
#include "spasm-account.h"