# HG changeset patch # User Evan Schoenberg # Date 1170268291 0 # Node ID cb3800fabd76cac43e1885d170e2a628bc127966 # Parent 7c20c9ab7985e9a3792e771444e9bdae168df184 The accounts request API now keeps track of a returned ui_handle for authorization requests, which can be closed on demand individually or all-at-once by account. When a connection is destroyed, its associated requests are closed. diff -r 7c20c9ab7985 -r cb3800fabd76 libpurple/account.c --- a/libpurple/account.c Wed Jan 31 05:47:22 2007 +0000 +++ b/libpurple/account.c Wed Jan 31 18:31:31 2007 +0000 @@ -57,6 +57,13 @@ } GaimAccountSetting; +typedef struct +{ + GaimAccountRequestType type; + GaimAccount *account; + void *ui_handle; + +} GaimAccountRequestInfo; static GaimAccountUiOps *account_ui_ops = NULL; @@ -64,6 +71,7 @@ static guint save_timer = 0; static gboolean accounts_loaded = FALSE; +static GList *handles = NULL; /********************************************************************* * Writing to disk * @@ -1053,21 +1061,82 @@ ui_ops->request_add(account, remote_user, id, alias, message); } -void +static void +gaim_account_request_close_info(GaimAccountRequestInfo *info) +{ + GaimAccountUiOps *ops; + + ops = gaim_accounts_get_ui_ops(); + + if (ops != NULL && ops->close_account_request != NULL) + ops->close_account_request(info->ui_handle); + + g_free(info); +} + +void +gaim_account_request_close_with_account(GaimAccount *account) +{ + GList *l, *l_next; + + g_return_if_fail(account != NULL); + + for (l = handles; l != NULL; l = l_next) { + GaimAccountRequestInfo *info = l->data; + + l_next = l->next; + + if (info->account == account) { + handles = g_list_remove(handles, info); + gaim_account_request_close_info(info); + } + } +} + +void +gaim_account_request_close(void *ui_handle) +{ + GList *l, *l_next; + + g_return_if_fail(ui_handle != NULL); + + for (l = handles; l != NULL; l = l_next) { + GaimAccountRequestInfo *info = l->data; + + l_next = l->next; + + if (info->ui_handle == ui_handle) { + handles = g_list_remove(handles, info); + gaim_account_request_close_info(info); + } + } +} + +void * gaim_account_request_authorization(GaimAccount *account, const char *remote_user, const char *id, const char *alias, const char *message, gboolean on_list, GCallback auth_cb, GCallback deny_cb, void *user_data) { - GaimAccountUiOps *ui_ops; - - g_return_if_fail(account != NULL); - g_return_if_fail(remote_user != NULL); - - ui_ops = gaim_accounts_get_ui_ops(); - - if (ui_ops != NULL && ui_ops->request_authorize != NULL) - ui_ops->request_authorize(account, remote_user, id, alias, message, on_list, auth_cb, deny_cb, user_data); - + GaimAccountUiOps *ui_ops; + GaimAccountRequestInfo *info; + + g_return_val_if_fail(account != NULL, NULL); + g_return_val_if_fail(remote_user != NULL, NULL); + + ui_ops = gaim_accounts_get_ui_ops(); + + if (ui_ops != NULL && ui_ops->request_authorize != NULL) { + info = g_new0(GaimAccountRequestInfo, 1); + info->type = GAIM_ACCOUNT_REQUEST_AUTHORIZATION; + info->account = account; + info->ui_handle = ui_ops->request_authorize(account, remote_user, id, alias, message, + on_list, auth_cb, deny_cb, user_data); + + handles = g_list_append(handles, info); + return info->ui_handle; + } + + return NULL; } static void diff -r 7c20c9ab7985 -r cb3800fabd76 libpurple/account.h --- a/libpurple/account.h Wed Jan 31 05:47:22 2007 +0000 +++ b/libpurple/account.h Wed Jan 31 18:31:31 2007 +0000 @@ -42,6 +42,14 @@ #include "prpl.h" #include "status.h" +/** + * Account request types. + */ +typedef enum +{ + GAIM_ACCOUNT_REQUEST_AUTHORIZATION = 0 /* Account authorization request */ +} GaimAccountRequestType; + struct _GaimAccountUiOps { /* A buddy we already have added us to their buddy list. */ @@ -53,9 +61,10 @@ void (*request_add)(GaimAccount *account, const char *remote_user, const char *id, const char *alias, const char *message); - void (*request_authorize)(GaimAccount *account, const char *remote_user, const char *id, + void *(*request_authorize)(GaimAccount *account, const char *remote_user, const char *id, const char *alias, const char *message, gboolean on_list, GCallback authorize_cb, GCallback deny_cb, void *user_data); + void (*close_account_request)(void *ui_handle); }; struct _GaimAccount @@ -192,12 +201,28 @@ * @param auth_cb The callback called when the local user accepts * @param deny_cb The callback called when the local user rejects * @param user_data Data to be passed back to the above callbacks + * + * @return A UI-specific handle. */ -void gaim_account_request_authorization(GaimAccount *account, const char *remote_user, +void *gaim_account_request_authorization(GaimAccount *account, const char *remote_user, const char *id, const char *alias, const char *message, gboolean on_list, GCallback auth_cb, GCallback deny_cb, void *user_data); /** + * Close account requests registered for the given GaimAccount + * + * @param handle The account for which requests should be closed + */ +void gaim_account_request_close_with_account(GaimAccount *account); + +/** + * Close the account request for the given ui handle + * + * @param handle The ui specific handle for which requests should be closed + */ +void gaim_account_request_close(void *ui_handle); + +/** * Requests information from the user to change the account's password. * * @param account The account to change the password on. diff -r 7c20c9ab7985 -r cb3800fabd76 libpurple/connection.c --- a/libpurple/connection.c Wed Jan 31 05:47:22 2007 +0000 +++ b/libpurple/connection.c Wed Jan 31 18:31:31 2007 +0000 @@ -225,6 +225,7 @@ } #endif + gaim_account_request_close_with_account(account); gaim_request_close_with_handle(gc); gaim_notify_close_with_handle(gc); diff -r 7c20c9ab7985 -r cb3800fabd76 pidgin/gtkaccount.c --- a/pidgin/gtkaccount.c Wed Jan 31 05:47:22 2007 +0000 +++ b/pidgin/gtkaccount.c Wed Jan 31 18:31:31 2007 +0000 @@ -2478,7 +2478,7 @@ g_free(aa); } -static void +static void * gaim_gtk_accounts_request_authorization(GaimAccount *account, const char *remote_user, const char *id, const char *alias, const char *message, gboolean on_list, GCallback auth_cb, GCallback deny_cb, void *user_data) @@ -2528,6 +2528,14 @@ gaim_gtk_blist_add_alert(alert); g_free(buffer); + + return NULL; +} + +static void +gaim_gtk_accounts_request_close(void *ui_handle) +{ + } static GaimAccountUiOps ui_ops = @@ -2535,7 +2543,8 @@ gaim_gtk_accounts_notify_added, NULL, gaim_gtk_accounts_request_add, - gaim_gtk_accounts_request_authorization + gaim_gtk_accounts_request_authorization, + gaim_gtk_accounts_request_close }; GaimAccountUiOps *