]> www.infradead.org Git - pidgin-chime.git/commitdiff
signin: do not use a weird opaque structure
authorIgnacio Casal Quinteiro <qignacio@amazon.com>
Fri, 22 May 2020 14:20:09 +0000 (16:20 +0200)
committerIgnacio Casal Quinteiro <qignacio@amazon.com>
Fri, 22 May 2020 15:30:23 +0000 (17:30 +0200)
We can save the data inside the object itself if required.

chime/chime-connection.c
chime/chime-connection.h
chime/chime-signin.c
prpl/authenticate.c
prpl/chime.c
prpl/chime.h

index 9117fda92c3e6043a395b1a12778a22aa15117de..1899015583502152c2e95a55f6f105afd1111282 100644 (file)
@@ -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",
index b56a825a61456c025a1300691a6f1fabe63f01ff..33d24c022e486f4dea8c9e48732d158b2db068f0 100644 (file)
@@ -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,
index a5586d5f9109c90d4bbf7b2543020ea2de2fe6e0..7ed1142c3d83a9500ef3a8c5364d780985195378 100644 (file)
@@ -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);
index 4b644cb0bdd00075cddf4ae7a88353222ab1c876..2fc61b72699804c05363bccaae28b05ea6fcf4f0 100644 (file)
@@ -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);
index 5ecfc8a5fbd1853121136f83537c481eeb1e5f64..f7f329aa289b1219efde93f87e0905f6469fcd73 100644 (file)
@@ -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)
index e86e8ed63f1546c49efe72fd36433204f4b9dcb4..48fd63b806e8ecf15ac229477aa1cce793d9a9bf 100644 (file)
@@ -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