Changeset 3b3cd693 for protocols


Ignore:
Timestamp:
2006-10-20T19:58:09Z (17 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
35f6677
Parents:
dfa41a4
Message:

Added backwards compatibility with the old "account add" syntax for Jabber
accounts. Very ugly code, so it won't stay long. ;-)

Plus checking of the ssl_connect() return value, because of course it can
return NULL too... Have to add general *_connect() error checking to
jabber_login() soon!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/jabber.c

    rdfa41a4 r3b3cd693  
    6262        struct jabber_data *jd = g_new0( struct jabber_data, 1 );
    6363        struct ns_srv_reply *srv = NULL;
    64         char *connect_to;
     64        char *connect_to, *s;
    6565       
    6666        jd->gc = gc;
     
    8181        jd->server ++;
    8282       
     83        if( ( s = strchr( jd->server, '/' ) ) )
     84        {
     85                *s = 0;
     86                set_setstr( &acc->set, "resource", s + 1 );
     87               
     88                /* Also remove the /resource from the original variable so we
     89                   won't have to do this again every time. */
     90                s = strchr( acc->user, '/' );
     91                *s = 0;
     92        }
     93       
     94        /* This code isn't really pretty. Backwards compatibility never is... */
     95        s = acc->server;
     96        while( s )
     97        {
     98                static int had_port = 0;
     99               
     100                if( strncmp( s, "ssl", 3 ) == 0 )
     101                {
     102                        set_setstr( &acc->set, "ssl", "true" );
     103                       
     104                        /* Flush this part so that (if this was the first
     105                           part of the server string) acc->server gets
     106                           flushed. We don't want to have to do this another
     107                           time. :-) */
     108                        *s = 0;
     109                        s ++;
     110                       
     111                        /* Only set this if the user didn't specify a custom
     112                           port number already... */
     113                        if( !had_port )
     114                                set_setint( &acc->set, "port", 5223 );
     115                }
     116                else if( isdigit( *s ) )
     117                {
     118                        int i;
     119                       
     120                        /* The first character is a digit. It could be an
     121                           IP address though. Only accept this as a port#
     122                           if there are only digits. */
     123                        for( i = 0; isdigit( s[i] ); i ++ );
     124                       
     125                        /* If the first non-digit character is a colon or
     126                           the end of the string, save the port number
     127                           where it should be. */
     128                        if( s[i] == ':' || s[i] == 0 )
     129                        {
     130                                sscanf( s, "%d", &i );
     131                                set_setint( &acc->set, "port", i );
     132                               
     133                                /* See above. */
     134                                *s = 0;
     135                                s ++;
     136                        }
     137                       
     138                        had_port = 1;
     139                }
     140               
     141                s = strchr( s, ':' );
     142                if( s )
     143                {
     144                        *s = 0;
     145                        s ++;
     146                }
     147        }
     148       
    83149        jd->node_cache = g_hash_table_new_full( g_str_hash, g_str_equal, NULL, jabber_cache_entry_free );
    84150        jd->buddies = g_hash_table_new( g_str_hash, g_str_equal );
    85151       
    86152        /* Figure out the hostname to connect to. */
    87         if( acc->server )
     153        if( acc->server && *acc->server )
    88154                connect_to = acc->server;
    89155        else if( ( srv = srv_lookup( "xmpp-client", "tcp", jd->server ) ) ||
     
    99165        {
    100166                jd->ssl = ssl_connect( connect_to, set_getint( &acc->set, "port" ), jabber_connected_ssl, gc );
    101                 jd->fd = ssl_getfd( jd->ssl );
     167                jd->fd = jd->ssl ? ssl_getfd( jd->ssl ) : -1;
    102168        }
    103169        else
Note: See TracChangeset for help on using the changeset viewer.