Ignore:
Timestamp:
2007-03-31T05:40:45Z (17 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
aef4828
Parents:
fa29d093
Message:

s/gaim_connection/im_connection/ and some other minor API changes. The rest
will come tomorrow. It compiles, I'll leave the real testing up to someone
else. ;-)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/io.c

    rfa29d093 r0da65d5  
    2626
    2727static gboolean jabber_write_callback( gpointer data, gint fd, b_input_condition cond );
    28 static gboolean jabber_write_queue( struct gaim_connection *gc );
    29 
    30 int jabber_write_packet( struct gaim_connection *gc, struct xt_node *node )
     28static gboolean jabber_write_queue( struct im_connection *ic );
     29
     30int jabber_write_packet( struct im_connection *ic, struct xt_node *node )
    3131{
    3232        char *buf;
     
    3434       
    3535        buf = xt_to_string( node );
    36         st = jabber_write( gc, buf, strlen( buf ) );
     36        st = jabber_write( ic, buf, strlen( buf ) );
    3737        g_free( buf );
    3838       
     
    4040}
    4141
    42 int jabber_write( struct gaim_connection *gc, char *buf, int len )
    43 {
    44         struct jabber_data *jd = gc->proto_data;
     42int jabber_write( struct im_connection *ic, char *buf, int len )
     43{
     44        struct jabber_data *jd = ic->proto_data;
    4545        gboolean ret;
    4646       
     
    5454                   it via the event handler. If not, add the handler. (In
    5555                   most cases it probably won't be necessary.) */
    56                 if( ( ret = jabber_write_queue( gc ) ) && jd->tx_len > 0 )
    57                         jd->w_inpa = b_input_add( jd->fd, GAIM_INPUT_WRITE, jabber_write_callback, gc );
     56                if( ( ret = jabber_write_queue( ic ) ) && jd->tx_len > 0 )
     57                        jd->w_inpa = b_input_add( jd->fd, GAIM_INPUT_WRITE, jabber_write_callback, ic );
    5858        }
    5959        else
     
    8585static gboolean jabber_write_callback( gpointer data, gint fd, b_input_condition cond )
    8686{
    87         struct jabber_data *jd = ((struct gaim_connection *)data)->proto_data;
     87        struct jabber_data *jd = ((struct im_connection *)data)->proto_data;
    8888       
    8989        return jd->fd != -1 &&
     
    9292}
    9393
    94 static gboolean jabber_write_queue( struct gaim_connection *gc )
    95 {
    96         struct jabber_data *jd = gc->proto_data;
     94static gboolean jabber_write_queue( struct im_connection *ic )
     95{
     96        struct jabber_data *jd = ic->proto_data;
    9797        int st;
    9898       
     
    117117                jd->fd = -1;
    118118               
    119                 hide_login_progress_error( gc, "Short write() to server" );
    120                 signoff( gc );
     119                hide_login_progress_error( ic, "Short write() to server" );
     120                signoff( ic );
    121121                return FALSE;
    122122        }
     
    142142static gboolean jabber_read_callback( gpointer data, gint fd, b_input_condition cond )
    143143{
    144         struct gaim_connection *gc = data;
    145         struct jabber_data *jd = gc->proto_data;
     144        struct im_connection *ic = data;
     145        struct jabber_data *jd = ic->proto_data;
    146146        char buf[512];
    147147        int st;
     
    160160                if( xt_feed( jd->xt, buf, st ) < 0 )
    161161                {
    162                         hide_login_progress_error( gc, "XML stream error" );
    163                         signoff( gc );
     162                        hide_login_progress_error( ic, "XML stream error" );
     163                        signoff( ic );
    164164                        return FALSE;
    165165                }
     
    176176                {
    177177                        jd->flags &= ~JFLAG_STREAM_RESTART;
    178                         jabber_start_stream( gc );
     178                        jabber_start_stream( ic );
    179179                }
    180180               
     
    196196                                   this is an old server that can't do SASL
    197197                                   authentication. */
    198                                 if( !sasl_supported( gc ) )
     198                                if( !sasl_supported( ic ) )
    199199                                {
    200200                                        /* If there's no version= tag, we suppose
    201201                                           this server does NOT implement: XMPP 1.0,
    202202                                           SASL and TLS. */
    203                                         if( set_getbool( &gc->acc->set, "tls" ) )
     203                                        if( set_getbool( &ic->acc->set, "tls" ) )
    204204                                        {
    205                                                 hide_login_progress( gc, "TLS is turned on for this "
     205                                                hide_login_progress( ic, "TLS is turned on for this "
    206206                                                          "account, but is not supported by this server" );
    207                                                 signoff( gc );
     207                                                signoff( ic );
    208208                                                return FALSE;
    209209                                        }
    210210                                        else
    211211                                        {
    212                                                 return jabber_init_iq_auth( gc );
     212                                                return jabber_init_iq_auth( ic );
    213213                                        }
    214214                                }
     
    216216                        else
    217217                        {
    218                                 hide_login_progress( gc, "XML stream error" );
    219                                 signoff( gc );
     218                                hide_login_progress( ic, "XML stream error" );
     219                                signoff( ic );
    220220                                return FALSE;
    221221                        }
     
    227227                jd->fd = -1;
    228228               
    229                 hide_login_progress_error( gc, "Error while reading from server" );
    230                 signoff( gc );
     229                hide_login_progress_error( ic, "Error while reading from server" );
     230                signoff( ic );
    231231                return FALSE;
    232232        }
     
    238238gboolean jabber_connected_plain( gpointer data, gint source, b_input_condition cond )
    239239{
    240         struct gaim_connection *gc = data;
     240        struct im_connection *ic = data;
    241241       
    242242        if( source == -1 )
    243243        {
    244                 hide_login_progress( gc, "Could not connect to server" );
    245                 signoff( gc );
     244                hide_login_progress( ic, "Could not connect to server" );
     245                signoff( ic );
    246246                return FALSE;
    247247        }
    248248       
    249         set_login_progress( gc, 1, "Connected to server, logging in" );
    250        
    251         return jabber_start_stream( gc );
     249        set_login_progress( ic, 1, "Connected to server, logging in" );
     250       
     251        return jabber_start_stream( ic );
    252252}
    253253
    254254gboolean jabber_connected_ssl( gpointer data, void *source, b_input_condition cond )
    255255{
    256         struct gaim_connection *gc = data;
    257         struct jabber_data *jd = gc->proto_data;
     256        struct im_connection *ic = data;
     257        struct jabber_data *jd = ic->proto_data;
    258258       
    259259        if( source == NULL )
     
    263263                jd->ssl = NULL;
    264264               
    265                 hide_login_progress( gc, "Could not connect to server" );
    266                 signoff( gc );
     265                hide_login_progress( ic, "Could not connect to server" );
     266                signoff( ic );
    267267                return FALSE;
    268268        }
    269269       
    270         set_login_progress( gc, 1, "Connected to server, logging in" );
    271        
    272         return jabber_start_stream( gc );
     270        set_login_progress( ic, 1, "Connected to server, logging in" );
     271       
     272        return jabber_start_stream( ic );
    273273}
    274274
     
    281281static xt_status jabber_pkt_features( struct xt_node *node, gpointer data )
    282282{
    283         struct gaim_connection *gc = data;
    284         struct jabber_data *jd = gc->proto_data;
     283        struct im_connection *ic = data;
     284        struct jabber_data *jd = ic->proto_data;
    285285        struct xt_node *c, *reply;
    286286        int trytls;
    287287       
    288         trytls = g_strcasecmp( set_getstr( &gc->acc->set, "tls" ), "try" ) == 0;
     288        trytls = g_strcasecmp( set_getstr( &ic->acc->set, "tls" ), "try" ) == 0;
    289289        c = xt_find_node( node->children, "starttls" );
    290290        if( c && !jd->ssl )
     
    295295                c = xt_find_node( c->children, "required" );
    296296               
    297                 if( c && ( !trytls && !set_getbool( &gc->acc->set, "tls" ) ) )
    298                 {
    299                         hide_login_progress( gc, "Server requires TLS connections, but TLS is turned off for this account" );
    300                         signoff( gc );
     297                if( c && ( !trytls && !set_getbool( &ic->acc->set, "tls" ) ) )
     298                {
     299                        hide_login_progress( ic, "Server requires TLS connections, but TLS is turned off for this account" );
     300                        signoff( ic );
    301301                       
    302302                        return XT_ABORT;
     
    304304               
    305305                /* Only run this if the tls setting is set to true or try: */
    306                 if( ( trytls || set_getbool( &gc->acc->set, "tls" ) ) )
     306                if( ( trytls || set_getbool( &ic->acc->set, "tls" ) ) )
    307307                {
    308308                        reply = xt_new_node( "starttls", NULL, NULL );
    309309                        xt_add_attr( reply, "xmlns", XMLNS_TLS );
    310                         if( !jabber_write_packet( gc, reply ) )
     310                        if( !jabber_write_packet( ic, reply ) )
    311311                        {
    312312                                xt_free_node( reply );
     
    325325                   using SSL/TLS. */
    326326               
    327                 if( !trytls && set_getbool( &gc->acc->set, "tls" ) )
    328                 {
    329                         hide_login_progress( gc, "TLS is turned on for this account, but is not supported by this server" );
    330                         signoff( gc );
     327                if( !trytls && set_getbool( &ic->acc->set, "tls" ) )
     328                {
     329                        hide_login_progress( ic, "TLS is turned on for this account, but is not supported by this server" );
     330                        signoff( ic );
    331331                       
    332332                        return XT_ABORT;
     
    346346           other way. jabber.com doesn't seem to do SASL while it pretends
    347347           to be XMPP 1.0 compliant! */
    348         else if( !( jd->flags & JFLAG_AUTHENTICATED ) && sasl_supported( gc ) )
    349         {
    350                 if( !jabber_init_iq_auth( gc ) )
     348        else if( !( jd->flags & JFLAG_AUTHENTICATED ) && sasl_supported( ic ) )
     349        {
     350                if( !jabber_init_iq_auth( ic ) )
    351351                        return XT_ABORT;
    352352        }
     
    354354        if( ( c = xt_find_node( node->children, "bind" ) ) )
    355355        {
    356                 reply = xt_new_node( "bind", NULL, xt_new_node( "resource", set_getstr( &gc->acc->set, "resource" ), NULL ) );
     356                reply = xt_new_node( "bind", NULL, xt_new_node( "resource", set_getstr( &ic->acc->set, "resource" ), NULL ) );
    357357                xt_add_attr( reply, "xmlns", XMLNS_BIND );
    358358                reply = jabber_make_packet( "iq", "set", NULL, reply );
    359                 jabber_cache_add( gc, reply, jabber_pkt_bind_sess );
    360                
    361                 if( !jabber_write_packet( gc, reply ) )
     359                jabber_cache_add( ic, reply, jabber_pkt_bind_sess );
     360               
     361                if( !jabber_write_packet( ic, reply ) )
    362362                        return XT_ABORT;
    363363               
     
    370370                xt_add_attr( reply, "xmlns", XMLNS_SESSION );
    371371                reply = jabber_make_packet( "iq", "set", NULL, reply );
    372                 jabber_cache_add( gc, reply, jabber_pkt_bind_sess );
    373                
    374                 if( !jabber_write_packet( gc, reply ) )
     372                jabber_cache_add( ic, reply, jabber_pkt_bind_sess );
     373               
     374                if( !jabber_write_packet( ic, reply ) )
    375375                        return XT_ABORT;
    376376               
     
    383383        if( jd->flags & JFLAG_AUTHENTICATED && ( jd->flags & ( JFLAG_WAIT_BIND | JFLAG_WAIT_SESSION ) ) == 0 )
    384384        {
    385                 if( !jabber_get_roster( gc ) )
     385                if( !jabber_get_roster( ic ) )
    386386                        return XT_ABORT;
    387387        }
     
    392392static xt_status jabber_pkt_proceed_tls( struct xt_node *node, gpointer data )
    393393{
    394         struct gaim_connection *gc = data;
    395         struct jabber_data *jd = gc->proto_data;
     394        struct im_connection *ic = data;
     395        struct jabber_data *jd = ic->proto_data;
    396396        char *xmlns;
    397397       
     
    417417        jd->w_inpa = jd->r_inpa = 0;
    418418       
    419         set_login_progress( gc, 1, "Converting stream to TLS" );
    420        
    421         jd->ssl = ssl_starttls( jd->fd, jabber_connected_ssl, gc );
     419        set_login_progress( ic, 1, "Converting stream to TLS" );
     420       
     421        jd->ssl = ssl_starttls( jd->fd, jabber_connected_ssl, ic );
    422422       
    423423        return XT_HANDLED;
     
    426426static xt_status jabber_pkt_stream_error( struct xt_node *node, gpointer data )
    427427{
    428         struct gaim_connection *gc = data;
     428        struct im_connection *ic = data;
    429429        struct xt_node *c;
    430430        char *s, *type = NULL, *text = NULL;
     
    452452        if( type == NULL )
    453453        {
    454                 hide_login_progress_error( gc, "Unknown stream error reported by server" );
    455                 signoff( gc );
     454                hide_login_progress_error( ic, "Unknown stream error reported by server" );
     455                signoff( ic );
    456456                return XT_ABORT;
    457457        }
     
    462462        if( strcmp( type, "conflict" ) == 0 )
    463463        {
    464                 hide_login_progress( gc, "Account and resource used from a different location" );
    465                 gc->wants_to_die = TRUE;
     464                hide_login_progress( ic, "Account and resource used from a different location" );
     465                ic->wants_to_die = TRUE;
    466466        }
    467467        else
    468468        {
    469469                s = g_strdup_printf( "Stream error: %s%s%s", type, text ? ": " : "", text ? text : "" );
    470                 hide_login_progress_error( gc, s );
     470                hide_login_progress_error( ic, s );
    471471                g_free( s );
    472472        }
    473473       
    474         signoff( gc );
     474        signoff( ic );
    475475       
    476476        return XT_ABORT;
     
    500500};
    501501
    502 gboolean jabber_start_stream( struct gaim_connection *gc )
    503 {
    504         struct jabber_data *jd = gc->proto_data;
     502gboolean jabber_start_stream( struct im_connection *ic )
     503{
     504        struct jabber_data *jd = ic->proto_data;
    505505        int st;
    506506        char *greet;
     
    509509           from the server too. */
    510510        xt_free( jd->xt );      /* In case we're RE-starting. */
    511         jd->xt = xt_new( gc );
     511        jd->xt = xt_new( ic );
    512512        jd->xt->handlers = (struct xt_handler_entry*) jabber_handlers;
    513513       
    514514        if( jd->r_inpa <= 0 )
    515                 jd->r_inpa = b_input_add( jd->fd, GAIM_INPUT_READ, jabber_read_callback, gc );
     515                jd->r_inpa = b_input_add( jd->fd, GAIM_INPUT_READ, jabber_read_callback, ic );
    516516       
    517517        greet = g_strdup_printf( "<?xml version='1.0' ?>"
     
    519519                                  "xmlns:stream=\"http://etherx.jabber.org/streams\" version=\"1.0\">", jd->server );
    520520       
    521         st = jabber_write( gc, greet, strlen( greet ) );
     521        st = jabber_write( ic, greet, strlen( greet ) );
    522522       
    523523        g_free( greet );
     
    526526}
    527527
    528 void jabber_end_stream( struct gaim_connection *gc )
    529 {
    530         struct jabber_data *jd = gc->proto_data;
     528void jabber_end_stream( struct im_connection *ic )
     529{
     530        struct jabber_data *jd = ic->proto_data;
    531531       
    532532        /* Let's only do this if the queue is currently empty, otherwise it'd
     
    538538                int st = 1;
    539539               
    540                 if( gc->flags & OPT_LOGGED_IN )
     540                if( ic->flags & OPT_LOGGED_IN )
    541541                {
    542542                        node = jabber_make_packet( "presence", "unavailable", NULL, NULL );
    543                         st = jabber_write_packet( gc, node );
     543                        st = jabber_write_packet( ic, node );
    544544                        xt_free_node( node );
    545545                }
    546546               
    547547                if( st )
    548                         jabber_write( gc, eos, strlen( eos ) );
    549         }
    550 }
     548                        jabber_write( ic, eos, strlen( eos ) );
     549        }
     550}
Note: See TracChangeset for help on using the changeset viewer.