Changeset 36e9f62


Ignore:
Timestamp:
2006-10-07T17:46:28Z (17 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
038d17f
Parents:
090f1cb
Message:

Added SRV lookups to automatically find out the correct server for a
domain.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • configure

    r090f1cb r36e9f62  
    318318
    319319echo 'SSL_CLIENT=ssl_'$ssl'.o' >> Makefile.settings
     320
     321for i in /lib /usr/lib /usr/local/lib; do
     322        if [ -e $i/libresolv.a ]; then
     323                echo '#define HAVE_RESOLV_A' >> config.h
     324                echo 'EFLAGS+='$i'/libresolv.a' >> Makefile.settings
     325                break
     326        fi
     327done
    320328
    321329STORAGES="text xml"
  • lib/misc.c

    r090f1cb r36e9f62  
    3939#include <glib.h>
    4040#include <time.h>
     41
     42#ifdef HAVE_RESOLV_A
     43#include <arpa/nameser.h>
     44#include <resolv.h>
     45#endif
    4146
    4247void strip_linefeed(gchar *text)
     
    488493        return 0;
    489494}
     495
     496struct ns_srv_reply *srv_lookup( char *service, char *protocol, char *domain )
     497{       
     498        struct ns_srv_reply *reply = NULL;
     499#ifdef HAVE_RESOLV_A
     500        char name[1024];
     501        unsigned char querybuf[1024];
     502        const unsigned char *buf;
     503        ns_msg nsh;
     504        ns_rr rr;
     505        int i, len, size;
     506       
     507        g_snprintf( name, sizeof( name ), "_%s._%s.%s", service, protocol, domain );
     508       
     509        if( ( size = res_query( name, ns_c_in, ns_t_srv, querybuf, sizeof( querybuf ) ) ) <= 0 )
     510                return NULL;
     511       
     512        if( ns_initparse( querybuf, size, &nsh ) != 0 )
     513                return NULL;
     514       
     515        if( ns_parserr( &nsh, ns_s_an, 0, &rr ) != 0 )
     516                return NULL;
     517       
     518        size = ns_rr_rdlen( rr );
     519        buf = ns_rr_rdata( rr );
     520       
     521        len = 0;
     522        for( i = 6; i < size && buf[i]; i += buf[i] + 1 )
     523                len += buf[i] + 1;
     524       
     525        if( i > size )
     526                return NULL;
     527       
     528        reply = g_malloc( sizeof( struct ns_srv_reply ) + len );
     529        memcpy( reply->name, buf + 7, len );
     530       
     531        for( i = buf[6]; i < len && buf[7+i]; i += buf[7+i] + 1 )
     532                reply->name[i] = '.';
     533       
     534        if( i > len )
     535        {
     536                g_free( reply );
     537                return NULL;
     538        }
     539       
     540        reply->prio = ( buf[0] << 8 ) | buf[1];
     541        reply->weight = ( buf[2] << 8 ) | buf[3];
     542        reply->port = ( buf[4] << 8 ) | buf[5];
     543#endif
     544       
     545        return reply;
     546}
  • lib/misc.h

    r090f1cb r36e9f62  
    3030#include <time.h>
    3131
     32struct ns_srv_reply
     33{
     34        int prio;
     35        int weight;
     36        int port;
     37        char name[];
     38};
     39
    3240G_MODULE_EXPORT void strip_linefeed( gchar *text );
    3341G_MODULE_EXPORT char *add_cr( char *text );
     
    5462G_MODULE_EXPORT int bool2int( char *value );
    5563
     64G_MODULE_EXPORT struct ns_srv_reply *srv_lookup( char *service, char *protocol, char *domain );
     65
    5666#endif
  • protocols/jabber/jabber.c

    r090f1cb r36e9f62  
    5959        struct gaim_connection *gc = new_gaim_conn( acc );
    6060        struct jabber_data *jd = g_new0( struct jabber_data, 1 );
     61        struct ns_srv_reply *srv = NULL;
     62        char *connect_to;
    6163       
    6264        jd->gc = gc;
     
    7981        jd->node_cache = xt_new_node( "cache", NULL, NULL );
    8082       
     83        /* Figure out the hostname to connect to. */
     84        if( acc->server )
     85                connect_to = acc->server;
     86        else if( ( srv = srv_lookup( "xmpp-client", "tcp", jd->server ) ) ||
     87                 ( srv = srv_lookup( "jabber-client", "tcp", jd->server ) ) )
     88                connect_to = srv->name;
     89        else
     90                connect_to = jd->server;
     91       
     92        /* For non-SSL connections we can try to use the port # from the SRV
     93           reply, but let's not do that when using SSL, SSL usually runs on
     94           non-standard ports... */
    8195        if( set_getbool( &acc->set, "ssl" ) )
    8296        {
    83                 jd->ssl = ssl_connect( acc->server ? acc->server : jd->server, set_getint( &acc->set, "port" ), jabber_connected_ssl, gc );
     97                jd->ssl = ssl_connect( connect_to, set_getint( &acc->set, "port" ), jabber_connected_ssl, gc );
    8498                jd->fd = ssl_getfd( jd->ssl );
    8599        }
    86100        else
    87101        {
    88                 jd->fd = proxy_connect( acc->server ? acc->server : jd->server, set_getint( &acc->set, "port" ), jabber_connected_plain, gc );
    89         }
     102                jd->fd = proxy_connect( connect_to, srv ? srv->port : set_getint( &acc->set, "port" ), jabber_connected_plain, gc );
     103        }
     104       
     105        g_free( srv );
    90106}
    91107
  • protocols/jabber/presence.c

    r090f1cb r36e9f62  
    3838                *s = 0;
    3939       
     40        /* Will implement better parsing of away states/msgs when we
     41           finally do those API changes. Which will probably be after
     42           merging this module into the main tree. */
    4043        if( type == NULL )
    4144                serv_got_update( gc, from, 1, 0, 0, 0, 0, 0 );
     
    8487       
    8588        node = jabber_make_packet( "presence", NULL, NULL, NULL );
     89        xt_add_child( node, xt_new_node( "priority", set_getstr( &gc->acc->set, "priority" ), NULL ) );
    8690        if( show && *show )
    8791                xt_add_child( node, xt_new_node( "show", show, NULL ) );
    8892        if( status )
    8993                xt_add_child( node, xt_new_node( "status", status, NULL ) );
    90         /* if( set_getint( &gc->acc->set, "priority" ) != 0 ) */
    91         /* Let's just send this every time... */
    92                 xt_add_child( node, xt_new_node( "priority", set_getstr( &gc->acc->set, "priority" ), NULL ) );
    9394       
    9495        st = jabber_write_packet( gc, node );
Note: See TracChangeset for help on using the changeset viewer.