# HG changeset patch # User Andreas Monitzer # Date 1182470735 0 # Node ID ca0b86f3dbd2d81a0895c7d3458e94fce0ae99d2 # Parent 108f3b42976f8a7b7ba9eb8a3dae9439dd09c2b1 Implemented a callback for a successful registration, supplying the username and password to the application when available, in the way explained by Sean. diff -r 108f3b42976f -r ca0b86f3dbd2 libpurple/account.c --- a/libpurple/account.c Wed Jun 20 10:18:52 2007 +0000 +++ b/libpurple/account.c Fri Jun 22 00:05:35 2007 +0000 @@ -913,6 +913,15 @@ } void +purple_account_set_register_callback(PurpleAccount *account, PurpleAccountRegistrationCb cb, void *user_data) +{ + g_return_if_fail(account != NULL); + + account->registration_cb = cb; + account->registration_cb_user_data = user_data; +} + +void purple_account_register(PurpleAccount *account) { g_return_if_fail(account != NULL); diff -r 108f3b42976f -r ca0b86f3dbd2 libpurple/account.h --- a/libpurple/account.h Wed Jun 20 10:18:52 2007 +0000 +++ b/libpurple/account.h Fri Jun 22 00:05:35 2007 +0000 @@ -36,6 +36,7 @@ typedef gboolean (*PurpleFilterAccountFunc)(PurpleAccount *account); typedef void (*PurpleAccountRequestAuthorizationCb)(void *); +typedef void (*PurpleAccountRegistrationCb)(PurpleAccount *account, gboolean succeeded, const char *username, const char *password, void *user_data); #include "connection.h" #include "log.h" @@ -106,6 +107,8 @@ PurpleLog *system_log; /**< The system log */ void *ui_data; /**< The UI can put data here. */ + PurpleAccountRegistrationCb registration_cb; + void *registration_cb_user_data; }; #ifdef __cplusplus @@ -142,6 +145,15 @@ void purple_account_connect(PurpleAccount *account); /** + * Sets the callback for successful registration. + * + * @param account The account for which this callback should be used + * @param cb The callback + * @param user_data The user data passed to the callback + */ +void purple_account_set_register_callback(PurpleAccount *account, PurpleAccountRegistrationCb cb, void *user_data); + +/** * Registers an account. * * @param account The account to register. diff -r 108f3b42976f -r ca0b86f3dbd2 libpurple/protocols/jabber/jabber.c --- a/libpurple/protocols/jabber/jabber.c Wed Jun 20 10:18:52 2007 +0000 +++ b/libpurple/protocols/jabber/jabber.c Fri Jun 22 00:05:35 2007 +0000 @@ -642,14 +642,26 @@ static void jabber_registration_result_cb(JabberStream *js, xmlnode *packet, gpointer data) { + PurpleAccount *account = purple_connection_get_account(js->gc); const char *type = xmlnode_get_attrib(packet, "type"); char *buf; char *to = data; if(!strcmp(type, "result")) { - if(js->registration) + if(js->registration) { buf = g_strdup_printf(_("Registration of %s@%s successful"), js->user->node, js->user->domain); + if(account->registration_cb) { + char *jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain); + (account->registration_cb)(account, TRUE, jid, js->password, account->registration_cb_user_data); + g_free(jid); + /* the password shouldn't be kept around longer than necessary */ + if(js->password) { + g_free(js->password); + js->password = NULL; + } + } + } else buf = g_strdup_printf(_("Registration to %s successful"), to); @@ -665,6 +677,16 @@ purple_notify_error(NULL, _("Registration Failed"), _("Registration Failed"), msg); g_free(msg); + if(account->registration_cb) { + char *jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain); + (account->registration_cb)(account, FALSE, NULL, NULL, account->registration_cb_user_data); + g_free(jid); + /* the password shouldn't be kept around longer than necessary */ + if(js->password) { + g_free(js->password); + js->password = NULL; + } + } } g_free(to); if(js->registration) @@ -733,6 +755,11 @@ g_free(cbdata->js->user->node); cbdata->js->user->node = g_strdup(value); } + if(cbdata->js->registration && !strcmp(id, "password")) { + if(cbdata->js->password) + g_free(cbdata->js->password); + cbdata->js->password = g_strdup(value); + } } } @@ -752,8 +779,12 @@ static void jabber_register_cancel_cb(JabberRegisterCBData *cbdata, PurpleRequestFields *fields) { - if(cbdata->js->registration) + PurpleAccount *account = purple_connection_get_account(cbdata->js->gc); + if(cbdata->js->registration) { + if(account->registration_cb) + (account->registration_cb)(account, FALSE, NULL, NULL, account->registration_cb_user_data); jabber_connection_schedule_close(cbdata->js); + } g_free(cbdata->who); g_free(cbdata); } @@ -776,6 +807,7 @@ void jabber_register_parse(JabberStream *js, xmlnode *packet) { + PurpleAccount *account = purple_connection_get_account(js->gc); const char *type; const char *from = xmlnode_get_attrib(packet, "from"); PurpleRequestFields *fields; @@ -797,8 +829,11 @@ if(js->registration && xmlnode_get_child(query, "registered")) { purple_notify_error(NULL, _("Already Registered"), _("Already Registered"), NULL); - if(js->registration) + if(js->registration) { + if(account->registration_cb) + (account->registration_cb)(account, FALSE, NULL, NULL, account->registration_cb_user_data); jabber_connection_schedule_close(js); + } return; } @@ -817,6 +852,8 @@ g_free(href); if(js->registration) { js->gc->wants_to_die = TRUE; + if(account->registration_cb) /* succeeded, but we have no login info */ + (account->registration_cb)(account, TRUE, NULL, NULL, account->registration_cb_user_data); jabber_connection_schedule_close(js); } return; @@ -1097,6 +1134,8 @@ #endif if(js->serverFQDN) g_free(js->serverFQDN); + if(js->password) + g_free(js->password); g_free(js->server_name); g_free(js->gmail_last_time); g_free(js->gmail_last_tid); diff -r 108f3b42976f -r ca0b86f3dbd2 libpurple/protocols/jabber/jabber.h --- a/libpurple/protocols/jabber/jabber.h Wed Jun 20 10:18:52 2007 +0000 +++ b/libpurple/protocols/jabber/jabber.h Fri Jun 22 00:05:35 2007 +0000 @@ -154,6 +154,9 @@ #endif char *serverFQDN; + /* don't expect this to be filled in */ + char *password; + /* does the local server support PEP? */ gboolean pep;