Changeset 8a90001 for protocols


Ignore:
Timestamp:
2008-07-22T12:37:49Z (16 years ago)
Author:
ulim <a.sporto+bee@…>
Branches:
master
Children:
4ac647d
Parents:
9afeefa
Message:

Added an account setting 'proxy'.

Note that this is only used for sending. The default <local>;<auto> means let
the receiver try a direct connection first and then the proxy discovered from
the server (if any). If you know you're firewalled you can remove the <local>.
If you want to provide your own proxy try something like
"<local>;JID,HOST,PORT". E.g.
"<local>;proxy.somewhere.org,123.123.123.123,7777".

Location:
protocols/jabber
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/jabber.c

    r9afeefa r8a90001  
    6262        s = set_add( &acc->set, "xmlconsole", "false", set_eval_bool, acc );
    6363        s->flags |= ACC_SET_OFFLINE_ONLY;
     64
     65        s = set_add( &acc->set, "proxy", "<local>;<auto>", NULL, acc );
    6466}
    6567
  • protocols/jabber/s5bytestream.c

    r9afeefa r8a90001  
    362362        tf->ft->free = jabber_bs_free_transfer;
    363363
    364         jabber_bs_recv_handshake( bt, 0, 0 );
     364        jabber_bs_recv_handshake( bt, -1, 0 );
    365365
    366366        return XT_HANDLED;
     
    381381        int gret;
    382382
    383         if ( ( fd != 0 ) && !jabber_bs_poll( bt, fd, &revents ) )
     383        if ( ( fd != -1 ) && !jabber_bs_poll( bt, fd, &revents ) )
    384384                return FALSE;
    385385       
     
    554554        {
    555555                bt->sh = shlist->next->data;
    556                 return jabber_bs_recv_handshake( bt, 0, 0 );
     556                return jabber_bs_recv_handshake( bt, -1, 0 );
    557557        }
    558558
     
    620620        struct jabber_transfer *tf = bt->tf;
    621621
    622         if( fd != 0 ) /* called via event thread */
     622        if( fd != -1 ) /* called via event thread */
    623623        {
    624624                tf->watch_in = 0;
     
    666666        }
    667667       
    668         jabber_bs_recv_read( tf->streamhandle, 0 , 0 );
     668        jabber_bs_recv_read( tf->streamhandle, -1 , 0 );
    669669
    670670        return TRUE;
     
    776776                /* using a proxy, abort listen */
    777777
    778                 if ( tf->watch_in )
     778                if( tf->watch_in )
    779779                {
    780780                        b_event_remove( tf->watch_in );
     
    782782                }
    783783               
    784                 closesocket( tf->fd );
    785                 tf->fd = 0;
     784                if( tf->fd != -1 ) {
     785                        closesocket( tf->fd );
     786                        tf->fd = -1;
     787                }
    786788
    787789                if ( bt->connect_timeout )
     
    798800                        {
    799801                                bt->sh = sh;
    800                                 jabber_bs_recv_handshake( bt, 0, 0 );
     802                                jabber_bs_recv_handshake( bt, -1, 0 );
    801803                                return XT_HANDLED;
    802804                        }
     
    872874}
    873875
     876jabber_streamhost_t *jabber_si_parse_proxy( struct im_connection *ic, char *proxy )
     877{
     878        char *host, *port, *jid;
     879        jabber_streamhost_t *sh;
     880
     881        if( ( ( host = strchr( proxy, ',' ) ) == 0 ) ||
     882             ( ( port = strchr( host+1, ',' ) ) == 0 ) ) {
     883                imcb_log( ic, "Error parsing proxy setting: \"%s\" (ignored)", proxy );
     884                return NULL;
     885        }
     886       
     887        jid = proxy;
     888        *host++ = '\0';
     889        *port++ = '\0';
     890
     891        sh = g_new0( jabber_streamhost_t, 1 );
     892        sh->jid = g_strdup( jid );
     893        sh->host = g_strdup( host );
     894        strcpy( sh->port, port );
     895
     896        return sh;
     897}
     898
     899void jabber_si_set_proxies( struct bs_transfer *bt )
     900{
     901        struct jabber_transfer *tf = bt->tf;
     902        struct jabber_data *jd = tf->ic->proto_data;
     903        char *proxysetting = g_strdup ( set_getstr( &tf->ic->acc->set, "proxy" ) );
     904        char *proxy,*next;
     905        char port[6];
     906        char host[INET6_ADDRSTRLEN];
     907        jabber_streamhost_t *sh, *sh2;
     908        GSList *streamhosts = jd->streamhosts;
     909
     910        proxy = proxysetting;
     911        while ( proxy && ( *proxy!='\0' ) ) {
     912                if( ( next = strchr( proxy, ';' ) ) )
     913                        *next++ = '\0';
     914               
     915                if( ( strcmp( proxy, "<local>" ) == 0 ) && jabber_bs_send_listen( bt, &tf->saddr, host, port ) ) {
     916                        sh = g_new0( jabber_streamhost_t, 1 );
     917                        sh->jid = g_strdup( tf->ini_jid );
     918                        sh->host = g_strdup( host );
     919                        strcpy( sh->port, port );
     920                        bt->streamhosts = g_slist_append( bt->streamhosts, sh );
     921
     922                        bt->tf->watch_in = b_input_add( tf->fd, GAIM_INPUT_READ, jabber_bs_send_handshake, bt );
     923                        bt->connect_timeout = b_timeout_add( JABBER_BS_LISTEN_TIMEOUT * 1000, jabber_bs_connect_timeout, bt );
     924                } else if( strcmp( proxy, "<auto>" ) == 0 ) {
     925                        while ( streamhosts ) {
     926                                sh = g_new0( jabber_streamhost_t, 1 );
     927                                sh2 = streamhosts->data;
     928                                sh->jid = g_strdup( sh2->jid );
     929                                sh->host = g_strdup( sh2->host );
     930                                strcpy( sh->port, sh2->port );
     931                                bt->streamhosts = g_slist_append( bt->streamhosts, sh );
     932                                streamhosts = g_slist_next( streamhosts );
     933                        }
     934                } else if( ( sh = jabber_si_parse_proxy( tf->ic, proxy ) ) )
     935                        bt->streamhosts = g_slist_append( bt->streamhosts, sh );
     936                proxy = next;
     937        }
     938}
     939
    874940/*
    875941 * Starts a bytestream.
     
    877943gboolean jabber_bs_send_start( struct jabber_transfer *tf )
    878944{
    879         char host[INET6_ADDRSTRLEN];
    880945        struct bs_transfer *bt;
    881946        sha1_state_t sha;
     
    883948        unsigned char hash[20];
    884949        int i,ret;
    885         struct jabber_data *jd = tf->ic->proto_data;
    886         jabber_streamhost_t sh;
    887         GSList *streamhosts = jd->streamhosts;
    888950
    889951        /* SHA1( SID + Initiator JID + Target JID ) is given to the streamhost which it will match against the initiator's value */
     
    905967        tf->ft->canceled = jabber_bs_canceled;
    906968
    907         if ( !jabber_bs_send_listen( bt, &tf->saddr, sh.host = host, sh.port ) )
    908                 return FALSE;
    909 
    910         bt->tf->watch_in = b_input_add( tf->fd, GAIM_INPUT_READ, jabber_bs_send_handshake, bt );
    911         bt->connect_timeout = b_timeout_add( JABBER_BS_LISTEN_TIMEOUT * 1000, jabber_bs_connect_timeout, bt );
    912 
    913         sh.jid = tf->ini_jid;
    914 
    915         /* temporarily add listen address to streamhosts, send the request and remove it */
    916         streamhosts = g_slist_prepend( streamhosts, &sh );
    917         ret = jabber_bs_send_request( tf, streamhosts);
    918         streamhosts = g_slist_remove( streamhosts, &sh );
     969        jabber_si_set_proxies( bt );
     970
     971        ret = jabber_bs_send_request( tf, bt->streamhosts);
    919972
    920973        return ret;
  • protocols/jabber/si.c

    r9afeefa r8a90001  
    3939        jd->filetransfers = g_slist_remove( jd->filetransfers, tf );
    4040
    41         if( tf->fd )
     41        if( tf->fd != -1 )
    4242        {
    4343                close( tf->fd );
    44                 tf->fd = 0;
     44                tf->fd = -1;
    4545        }
    4646
     
    129129
    130130        if( tf->bud->features && jd->have_streamhosts==1 ) {
     131                tf->disco_timeout = 0;
    131132                jabber_si_transfer_start( tf );
    132                 tf->disco_timeout = 0;
    133133                return FALSE;
    134134        }
     
    139139       
    140140        if( !tf->bud->features && jd->have_streamhosts!=1 )
    141                 imcb_file_canceled( tf->ft, "Couldn't get buddy's features or the server's" );
     141                imcb_log( tf->ic, "Couldn't get buddy's features nor discover all services of the server" );
    142142        else if( !tf->bud->features )
    143                 imcb_file_canceled( tf->ft, "Couldn't get buddy's features" );
     143                imcb_log( tf->ic, "Couldn't get buddy's features" );
    144144        else
    145                 imcb_file_canceled( tf->ft, "Couldn't get server's features" );
     145                imcb_log( tf->ic, "Couldn't discover some of the server's services" );
    146146       
    147147        tf->disco_timeout = 0;
     148        jabber_si_transfer_start( tf );
    148149        return FALSE;
    149150}
     
    173174        tf->ic = ic;
    174175        tf->ft = ft;
     176        tf->fd = -1;
    175177        tf->ft->data = tf;
    176178        tf->ft->free = jabber_si_free_transfer;
     
    186188                jabber_iq_query_features( ic, bud->full_jid );
    187189
    188         if( jd->have_streamhosts!=1 ) {
     190        /* If <auto> is not set don't check for proxies */
     191        if( ( jd->have_streamhosts!=1 ) && ( jd->streamhosts==NULL ) &&
     192            ( strstr( set_getstr( &ic->acc->set, "proxy" ), "<auto>" ) != NULL ) ) {
    189193                jd->have_streamhosts = 0;
    190194                jabber_iq_query_server( ic, server, XMLNS_DISCO_ITEMS );
    191         }
     195        } else if ( jd->streamhosts!=NULL )
     196                jd->have_streamhosts = 1;
    192197
    193198        /* if we had to do a query, wait for the result.
     
    309314        tf->ic = ic;
    310315        tf->ft = ft;
     316        tf->fd = -1;
    311317        tf->ft->data = tf;
    312318        tf->ft->accept = jabber_si_answer_request;
Note: See TracChangeset for help on using the changeset viewer.