diff options
-rwxr-xr-x | configure | 8 | ||||
-rw-r--r-- | lib/misc.c | 57 | ||||
-rw-r--r-- | lib/misc.h | 10 | ||||
-rw-r--r-- | protocols/jabber/jabber.c | 20 | ||||
-rw-r--r-- | protocols/jabber/presence.c | 7 |
5 files changed, 97 insertions, 5 deletions
@@ -318,6 +318,14 @@ fi; echo 'SSL_CLIENT=ssl_'$ssl'.o' >> Makefile.settings +for i in /lib /usr/lib /usr/local/lib; do + if [ -e $i/libresolv.a ]; then + echo '#define HAVE_RESOLV_A' >> config.h + echo 'EFLAGS+='$i'/libresolv.a' >> Makefile.settings + break + fi +done + STORAGES="text xml" if [ "$ldap" = "auto" ]; then @@ -39,6 +39,11 @@ #include <glib.h> #include <time.h> +#ifdef HAVE_RESOLV_A +#include <arpa/nameser.h> +#include <resolv.h> +#endif + void strip_linefeed(gchar *text) { int i, j; @@ -487,3 +492,55 @@ int bool2int( char *value ) return 0; } + +struct ns_srv_reply *srv_lookup( char *service, char *protocol, char *domain ) +{ + struct ns_srv_reply *reply = NULL; +#ifdef HAVE_RESOLV_A + char name[1024]; + unsigned char querybuf[1024]; + const unsigned char *buf; + ns_msg nsh; + ns_rr rr; + int i, len, size; + + g_snprintf( name, sizeof( name ), "_%s._%s.%s", service, protocol, domain ); + + if( ( size = res_query( name, ns_c_in, ns_t_srv, querybuf, sizeof( querybuf ) ) ) <= 0 ) + return NULL; + + if( ns_initparse( querybuf, size, &nsh ) != 0 ) + return NULL; + + if( ns_parserr( &nsh, ns_s_an, 0, &rr ) != 0 ) + return NULL; + + size = ns_rr_rdlen( rr ); + buf = ns_rr_rdata( rr ); + + len = 0; + for( i = 6; i < size && buf[i]; i += buf[i] + 1 ) + len += buf[i] + 1; + + if( i > size ) + return NULL; + + reply = g_malloc( sizeof( struct ns_srv_reply ) + len ); + memcpy( reply->name, buf + 7, len ); + + for( i = buf[6]; i < len && buf[7+i]; i += buf[7+i] + 1 ) + reply->name[i] = '.'; + + if( i > len ) + { + g_free( reply ); + return NULL; + } + + reply->prio = ( buf[0] << 8 ) | buf[1]; + reply->weight = ( buf[2] << 8 ) | buf[3]; + reply->port = ( buf[4] << 8 ) | buf[5]; +#endif + + return reply; +} @@ -29,6 +29,14 @@ #include <gmodule.h> #include <time.h> +struct ns_srv_reply +{ + int prio; + int weight; + int port; + char name[]; +}; + G_MODULE_EXPORT void strip_linefeed( gchar *text ); G_MODULE_EXPORT char *add_cr( char *text ); G_MODULE_EXPORT char *strip_newlines(char *source); @@ -53,4 +61,6 @@ G_MODULE_EXPORT void random_bytes( unsigned char *buf, int count ); G_MODULE_EXPORT int is_bool( char *value ); G_MODULE_EXPORT int bool2int( char *value ); +G_MODULE_EXPORT struct ns_srv_reply *srv_lookup( char *service, char *protocol, char *domain ); + #endif diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c index 706d31c3..2c0f7945 100644 --- a/protocols/jabber/jabber.c +++ b/protocols/jabber/jabber.c @@ -58,6 +58,8 @@ static void jabber_login( account_t *acc ) { struct gaim_connection *gc = new_gaim_conn( acc ); struct jabber_data *jd = g_new0( struct jabber_data, 1 ); + struct ns_srv_reply *srv = NULL; + char *connect_to; jd->gc = gc; gc->proto_data = jd; @@ -78,15 +80,29 @@ static void jabber_login( account_t *acc ) jd->node_cache = xt_new_node( "cache", NULL, NULL ); + /* Figure out the hostname to connect to. */ + if( acc->server ) + connect_to = acc->server; + else if( ( srv = srv_lookup( "xmpp-client", "tcp", jd->server ) ) || + ( srv = srv_lookup( "jabber-client", "tcp", jd->server ) ) ) + connect_to = srv->name; + else + connect_to = jd->server; + + /* For non-SSL connections we can try to use the port # from the SRV + reply, but let's not do that when using SSL, SSL usually runs on + non-standard ports... */ if( set_getbool( &acc->set, "ssl" ) ) { - jd->ssl = ssl_connect( acc->server ? acc->server : jd->server, set_getint( &acc->set, "port" ), jabber_connected_ssl, gc ); + jd->ssl = ssl_connect( connect_to, set_getint( &acc->set, "port" ), jabber_connected_ssl, gc ); jd->fd = ssl_getfd( jd->ssl ); } else { - jd->fd = proxy_connect( acc->server ? acc->server : jd->server, set_getint( &acc->set, "port" ), jabber_connected_plain, gc ); + jd->fd = proxy_connect( connect_to, srv ? srv->port : set_getint( &acc->set, "port" ), jabber_connected_plain, gc ); } + + g_free( srv ); } static void jabber_close( struct gaim_connection *gc ) diff --git a/protocols/jabber/presence.c b/protocols/jabber/presence.c index 57301270..5bef498d 100644 --- a/protocols/jabber/presence.c +++ b/protocols/jabber/presence.c @@ -37,6 +37,9 @@ xt_status jabber_pkt_presence( struct xt_node *node, gpointer data ) if( s ) *s = 0; + /* Will implement better parsing of away states/msgs when we + finally do those API changes. Which will probably be after + merging this module into the main tree. */ if( type == NULL ) serv_got_update( gc, from, 1, 0, 0, 0, 0, 0 ); else if( strcmp( type, "unavailable" ) == 0 ) @@ -83,13 +86,11 @@ int presence_send_update( struct gaim_connection *gc ) int st; node = jabber_make_packet( "presence", NULL, NULL, NULL ); + xt_add_child( node, xt_new_node( "priority", set_getstr( &gc->acc->set, "priority" ), NULL ) ); if( show && *show ) xt_add_child( node, xt_new_node( "show", show, NULL ) ); if( status ) xt_add_child( node, xt_new_node( "status", status, NULL ) ); - /* if( set_getint( &gc->acc->set, "priority" ) != 0 ) */ - /* Let's just send this every time... */ - xt_add_child( node, xt_new_node( "priority", set_getstr( &gc->acc->set, "priority" ), NULL ) ); st = jabber_write_packet( gc, node ); |