grim/purple-spasm

A ton of work, fixed reusing oauth tokens and started the chat login
/*
* 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
);
}