From: Ignacio Casal Quinteiro Date: Fri, 22 May 2020 14:20:09 +0000 (+0200) Subject: signin: do not use a weird opaque structure X-Git-Tag: v1.4~8^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=7324af67a3dee22d90bfd1d65c2df0bfe1799248;p=pidgin-chime.git signin: do not use a weird opaque structure We can save the data inside the object itself if required. --- diff --git a/chime/chime-connection.c b/chime/chime-connection.c index 9117fda..1899015 100644 --- a/chime/chime-connection.c +++ b/chime/chime-connection.c @@ -239,7 +239,7 @@ chime_connection_class_init(ChimeConnectionClass *klass) signals[AUTHENTICATE] = g_signal_new ("authenticate", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_BOOLEAN); + 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_BOOLEAN); signals[CONNECTED] = g_signal_new ("connected", diff --git a/chime/chime-connection.h b/chime/chime-connection.h index b56a825..33d24c0 100644 --- a/chime/chime-connection.h +++ b/chime/chime-connection.h @@ -88,7 +88,7 @@ void chime_connection_set_session_token (ChimeConnection * void chime_connection_signin (ChimeConnection *self); -void chime_connection_authenticate (gpointer opaque, +void chime_connection_authenticate (ChimeConnection *self, const gchar *username, const gchar *password); void chime_connection_log_out_async (ChimeConnection *self, diff --git a/chime/chime-signin.c b/chime/chime-signin.c index a5586d5..7ed1142 100644 --- a/chime/chime-signin.c +++ b/chime/chime-signin.c @@ -137,6 +137,7 @@ static void free_signin(struct signin *s) soup_session_abort(s->session); g_object_unref(s->session); g_object_unref(s->connection); + g_free(s); } static void fail(struct signin *state, GError *error) @@ -661,7 +662,7 @@ static void amazon_signin_result_cb(SoupSession *session, SoupMessage *msg, gpoi amazon_prepare_signin_form(state, dom, msg); if (state->form) { if (state->form->email_name && state->form->password_name) - g_signal_emit_by_name(state->connection, "authenticate", state, FALSE); + g_signal_emit_by_name(state->connection, "authenticate", FALSE); else fail_bad_response(state, _("Unexpected Amazon sign-in form during retry")); } else { @@ -677,7 +678,7 @@ static void amazon_send_credentials(struct signin *state, const gchar *password) SoupMessage *msg; if (!(password && *password)) { - g_signal_emit_by_name(state->connection, "authenticate", state, FALSE); + g_signal_emit_by_name(state->connection, "authenticate", FALSE); return; } @@ -707,7 +708,7 @@ static void amazon_signin_cb(SoupSession *session, SoupMessage *msg, gpointer da if (!(state->form && state->form->email_name && state->form->password_name)) fail_bad_response(state, _("Could not find Amazon sign in form")); else - g_signal_emit_by_name(state->connection, "authenticate", state, FALSE); + g_signal_emit_by_name(state->connection, "authenticate", FALSE); free_dom(dom); } @@ -728,7 +729,7 @@ static void wd_credentials_response_cb(SoupSession *session, SoupMessage *msg, g } if (!ok) { if (count > 3 && !g_strcmp0(response[3], "AuthenticationFailedException")) - g_signal_emit_by_name(state->connection, "authenticate", state, TRUE); + g_signal_emit_by_name(state->connection, "authenticate", TRUE); else fail_bad_response(state, _("Unexpected corporate authentication failure")); goto out; @@ -785,7 +786,7 @@ static void gwt_region_cb(SoupSession *session, SoupMessage *msg, gpointer data) goto out; } - g_signal_emit_by_name(state->connection, "authenticate", state, TRUE); + g_signal_emit_by_name(state->connection, "authenticate", TRUE); out: g_strfreev(response); } @@ -1019,6 +1020,8 @@ void chime_connection_signin(ChimeConnection *self) "libchime " PACKAGE_VERSION " ", NULL); + g_object_set_data(G_OBJECT(state->connection), "signin-state", state); + g_object_get(self, "account-email", &state->email, NULL); if (!(state->email && *state->email)) { chime_debug("The ChimeConnection object does not indicate an account name\n"); @@ -1050,10 +1053,10 @@ void chime_connection_signin(ChimeConnection *self) * If the credentials are NULL, it is interpreted as an error and the sign-in * procedure is canceled. */ -void chime_connection_authenticate(gpointer opaque, const gchar *user, const gchar *password) +void chime_connection_authenticate(ChimeConnection *self, const gchar *user, const gchar *password) { - struct signin *state = opaque; - g_assert(opaque != NULL); + struct signin *state = g_object_get_data(G_OBJECT(self), "signin-state"); + g_assert(state != NULL); if (state->region && user && *user && password && *password) wd_send_credentials(state, user, password); diff --git a/prpl/authenticate.c b/prpl/authenticate.c index 4b644cb..2fc61b7 100644 --- a/prpl/authenticate.c +++ b/prpl/authenticate.c @@ -30,7 +30,7 @@ struct auth_data { PurpleConnection *conn; - gpointer state; + ChimeConnection *cxn; gboolean user_required; gchar *username; gchar *password; @@ -38,7 +38,7 @@ struct auth_data { static void send_credentials(struct auth_data *data) { - chime_connection_authenticate(data->state, data->username, data->password); + chime_connection_authenticate(data->cxn, data->username, data->password); g_free(data->username); g_free(data->password); g_free(data); @@ -118,11 +118,11 @@ static void request_username_with_input(struct auth_data *data) request_password_with_input(data, NULL); } -void purple_request_credentials(PurpleConnection *conn, gpointer state, gboolean user_required) +void purple_request_credentials(PurpleConnection *conn, ChimeConnection *cxn, gboolean user_required) { struct auth_data *data = g_new0(struct auth_data, 1); data->conn = conn; - data->state = state; + data->cxn = cxn; data->user_required = user_required; if (purple_request_get_ui_ops()->request_fields) request_credentials_with_fields(data); diff --git a/prpl/chime.c b/prpl/chime.c index 5ecfc8a..f7f329a 100644 --- a/prpl/chime.c +++ b/prpl/chime.c @@ -91,9 +91,9 @@ static void chime_purple_set_idle(PurpleConnection *conn, int idle_time) NULL); } -static void on_chime_authenticate(ChimeConnection *cxn, gpointer state, gboolean user_required, PurpleConnection *conn) +static void on_chime_authenticate(ChimeConnection *cxn, gboolean user_required, PurpleConnection *conn) { - purple_request_credentials(conn, state, user_required); + purple_request_credentials(conn, cxn, user_required); } static void on_chime_connected(ChimeConnection *cxn, const gchar *display_name, PurpleConnection *conn) diff --git a/prpl/chime.h b/prpl/chime.h index e86e8ed..48fd63b 100644 --- a/prpl/chime.h +++ b/prpl/chime.h @@ -56,7 +56,7 @@ struct purple_chime { #define PURPLE_CHIME_CXN(conn) (CHIME_CONNECTION(((struct purple_chime *)purple_connection_get_protocol_data(conn))->cxn)) /* authenticate.c */ -void purple_request_credentials(PurpleConnection *conn, gpointer state, gboolean user_required); +void purple_request_credentials(PurpleConnection *conn, ChimeConnection *cxn, gboolean user_required); /* chime.c */ /* BEWARE: msg_id is allocated, msg_time is const. I am going to hate myself