Changeset 341ab62ab03143302fa354d392ba2f8e585d5300

Show
Ignore:
Timestamp:
12/02/10 15:56:26 (2 years ago)
Author:
Armin Burgmeier <armin@…>
git-author:
Benjamin Herr <ben@0x539.de> / 2010-02-09T19:50:58Z+0100
Parents:
bc626ac1b9062e23d8e3c0f757e7f0ca0199db4b
Children:
61cce2ce9c8b06819912a01dad14af78444f3b64
git-committer:
Armin Burgmeier <armin@arbur.net> / 2010-02-12T15:56:26Z+0100
Message:

auth-commands: Handle _TRY_AGAIN auth errors, etc.

2010-02-09 Benjamin Herr <ben@…>

  • code/commands/auth-commands.hpp:
  • code/commands/auth-commands.cpp: Handle _TRY_AGAIN errors, do the whole retrying thing properly.
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • ChangeLog

    rbc626ac r341ab62  
     12010-02-09  Benjamin Herr  <ben@0x539.de> 
     2 
     3        * code/commands/auth-commands.hpp: 
     4        * code/commands/auth-commands.cpp: Handle _TRY_AGAIN errors, do 
     5        the whole retrying thing properly. 
     6 
    172010-01-31  Benjamin Herr  <ben@0x539.de>, Armin Burgmeier  <armin@arbur.net> 
    28 
  • code/commands/auth-commands.cpp

    rbc626ac r341ab62  
    141141                        RetryMap::iterator i = m_retries.find(xmpp); 
    142142                        if(i == m_retries.end()) 
     143                                i = insert_retry_info(xmpp); 
     144                        RetryInfo& info(i->second); 
     145 
     146                        if(info.last_password.empty()) 
    143147                        { 
    144                                 i = m_retries.insert( 
    145                                         std::make_pair(xmpp, 
    146                                                        RetryInfo())).first; 
    147                                 i->second.retries = 0; 
    148                                 i->second.handle = g_signal_connect( 
    149                                         G_OBJECT(xmpp), 
    150                                         "notify::status", 
    151                                         G_CALLBACK(on_notify_status_static), 
    152                                         this); 
     148                                info.last_password = 
     149                                        prompt_password(m_parent, xmpp, 
     150                                                        info.retries); 
     151                                ++info.retries; 
     152 
     153                                if(info.last_password.empty()) 
     154                                        return GSASL_NO_PASSWORD; 
    153155                        } 
    154                         RetryInfo& info(i->second); 
    155  
    156                         Glib::ustring password = 
    157                                 prompt_password(m_parent, xmpp, info.retries); 
    158                         ++info.retries; 
    159  
    160                         if(password.empty()) 
    161                                 return GSASL_NO_PASSWORD; 
     156 
    162157                        gsasl_property_set(session, 
    163158                                           GSASL_PASSWORD, 
    164                                            password.c_str()); 
     159                                           info.last_password.c_str()); 
    165160                        return GSASL_OK; 
    166161                } 
     
    188183        g_assert(INF_IS_XMPP_CONNECTION(connection)); 
    189184 
     185        InfXmppConnection* xmpp = INF_XMPP_CONNECTION(connection); 
     186        RetryMap::iterator iter = m_retries.find(xmpp); 
     187        if(iter == m_retries.end()) 
     188                iter = insert_retry_info(xmpp); 
     189        Glib::ustring& last_password(iter->second.last_password); 
     190        Glib::ustring old_password; 
     191 
     192        old_password.swap(last_password); 
     193 
    190194        if(error->domain == 
    191195             g_quark_from_static_string("INF_XMPP_CONNECTION_AUTH_ERROR")) 
    192196        { 
    193                 InfXmppConnection* xmpp = INF_XMPP_CONNECTION(connection); 
    194197                const GError* sasl_error = 
    195198                        inf_xmpp_connection_get_sasl_error(xmpp); 
    196199                if(sasl_error != NULL && 
    197200                   sasl_error->domain == 
    198                      inf_authentication_detail_error_quark() && 
    199                    sasl_error->code == 
    200                      INF_AUTHENTICATION_DETAIL_ERROR_AUTHENTICATION_FAILED) 
    201                 { 
    202                         GError* my_error = NULL; 
    203                         inf_xmpp_connection_retry_sasl_authentication( 
    204                                 INF_XMPP_CONNECTION(connection), &my_error); 
    205                         if(my_error) 
    206                         { 
    207                                 show_error(my_error, m_statusbar, connection); 
    208                                 g_error_free(my_error); 
    209                         } 
     201                     inf_authentication_detail_error_quark()) 
     202                { 
     203                        handle_error_detail(xmpp, sasl_error, 
     204                                            old_password, 
     205                                            last_password); 
    210206                } 
    211207                else if(sasl_error != NULL) 
     
    218214                } 
    219215        } 
    220         else if(error->domain == inf_gsasl_error_quark() || 
    221                 error->domain == inf_authentication_detail_error_quark()) 
     216        else if(error->domain == inf_gsasl_error_quark()) 
    222217        { 
    223218                show_error(error, m_statusbar, connection); 
    224219        } 
     220} 
     221 
     222void Gobby::AuthCommands::handle_error_detail(InfXmppConnection* xmpp, 
     223                                              const GError* detail_error, 
     224                                              Glib::ustring& old_password, 
     225                                              Glib::ustring& last_password) 
     226{ 
     227        GError* error = NULL; 
     228        switch(detail_error->code) 
     229        { 
     230        case INF_AUTHENTICATION_DETAIL_ERROR_AUTHENTICATION_FAILED: 
     231                inf_xmpp_connection_retry_sasl_authentication(xmpp, &error); 
     232                break; 
     233        case INF_AUTHENTICATION_DETAIL_ERROR_TRY_AGAIN: 
     234                old_password.swap(last_password); 
     235                inf_xmpp_connection_retry_sasl_authentication(xmpp, &error); 
     236 
     237                break; 
     238        default: 
     239                show_error(detail_error, m_statusbar, 
     240                           INF_XML_CONNECTION(xmpp)); 
     241                break; 
     242        } 
     243 
     244        if(error) 
     245        { 
     246                show_error(error, m_statusbar, 
     247                           INF_XML_CONNECTION(xmpp)); 
     248                g_error_free(error); 
     249        } 
     250} 
     251 
     252Gobby::AuthCommands::RetryMap::iterator 
     253Gobby::AuthCommands::insert_retry_info(InfXmppConnection* xmpp) 
     254{ 
     255        RetryMap::iterator iter = m_retries.insert( 
     256                std::make_pair(xmpp, 
     257                               RetryInfo())).first; 
     258        iter->second.retries = 0; 
     259        iter->second.handle = g_signal_connect( 
     260                G_OBJECT(xmpp), 
     261                "notify::status", 
     262                G_CALLBACK(on_notify_status_static), 
     263                this); 
     264 
     265        return iter; 
    225266} 
    226267 
  • code/commands/auth-commands.hpp

    r6942859 r341ab62  
    8787        void browser_error_callback(InfcBrowser* browser, GError* error); 
    8888 
     89        void handle_error_detail(InfXmppConnection* xmpp, 
     90                                 const GError* detail_error, 
     91                                 Glib::ustring& old_password, 
     92                                 Glib::ustring& last_password); 
     93 
     94        struct RetryInfo { 
     95                unsigned int retries; 
     96                Glib::ustring last_password; 
     97                gulong handle; 
     98        }; 
     99 
     100        typedef std::map<InfXmppConnection*, RetryInfo> RetryMap; 
     101 
     102        RetryMap::iterator insert_retry_info(InfXmppConnection* xmpp); 
     103 
    89104        void on_notify_status(InfXmppConnection* connection); 
    90105 
     
    95110        Gsasl* m_gsasl; 
    96111 
    97         struct RetryInfo { 
    98                 unsigned int retries; 
    99                 gulong handle; 
    100         }; 
    101  
    102         typedef std::map<InfXmppConnection*, RetryInfo> RetryMap; 
    103112        RetryMap m_retries; 
    104113};