Ignore:
Timestamp:
2006-09-20T19:42:27Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
70f6aab8
Parents:
f06894d
Message:

It can send a valid (pre-XMPP) login packet. Lots of work to do, still...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/iq.c

    rf06894d r21167d2  
    2424#include "jabber.h"
    2525
     26/*
     27<iq xmlns="jabber:client" id="BeeX00000001" type="result"><query
     28xmlns="jabber:iq:auth"><username>wilmer</username><resource/><password/><digest/>
     29<sequence>499</sequence><token>450D1FFD</token></query></iq>
     30*/
     31
    2632xt_status jabber_pkt_iq( struct xt_node *node, gpointer data )
    2733{
    28         char *from = xt_find_attr( node, "from" );
     34        struct gaim_connection *gc = data;
     35        struct jabber_data *jd = gc->proto_data;
     36        struct xt_node *query, *reply = NULL;
     37        char *s;
     38        int st;
    2939       
    30         printf( "Received IQ from %s:\n", from );
    31         xt_print( node );
     40        query = xt_find_node( node->children, "query" );
     41       
     42        if( !query )
     43                return XT_HANDLED;      /* Ignore it for now, don't know what's best... */
     44       
     45        if( ( s = xt_find_attr( query, "xmlns" ) ) && strcmp( s, "jabber:iq:auth" ) == 0 )
     46        {
     47                /* Time to authenticate ourselves! */
     48                reply = xt_new_node( "query", NULL, NULL );
     49                xt_add_attr( reply, "xmlns", "jabber:iq:auth" );
     50                xt_add_child( reply, xt_new_node( "username", jd->username, NULL ) );
     51                xt_add_child( reply, xt_new_node( "resource", set_getstr( &gc->acc->set, "resource" ), NULL ) );
     52               
     53                if( xt_find_node( query->children, "digest" ) && ( s = xt_find_attr( jd->xt->root, "id" ) ) )
     54                {
     55                        /* We can do digest authentication, it seems, and of
     56                           course we prefer that. */
     57                        SHA_CTX sha;
     58                        char hash_hex[40];
     59                        unsigned char hash[20];
     60                        int i;
     61                       
     62                        shaInit( &sha );
     63                        shaUpdate( &sha, (unsigned char*) s, strlen( s ) );
     64                        shaUpdate( &sha, (unsigned char*) gc->acc->pass, strlen( gc->acc->pass ) );
     65                        shaFinal( &sha, hash );
     66                       
     67                        for( i = 0; i < 20; i ++ )
     68                                sprintf( hash_hex + i * 2, "%02x", hash[i] );
     69                       
     70                        xt_add_child( reply, xt_new_node( "digest", hash_hex, NULL ) );
     71                }
     72                else if( xt_find_node( query->children, "password" ) )
     73                {
     74                        /* We'll have to stick with plaintext. Let's hope we're using SSL/TLS... */
     75                        xt_add_child( reply, xt_new_node( "password", gc->acc->pass, NULL ) );
     76                }
     77                else
     78                {
     79                        xt_free_node( reply );
     80                       
     81                        hide_login_progress_error( gc, "Can't find suitable authentication method" );
     82                        signoff( gc );
     83                        return XT_ABORT;
     84                }
     85               
     86                reply = jabber_make_packet( "iq", "set", NULL, reply );
     87                st = jabber_write_packet( gc, reply );
     88                xt_free_node( reply );
     89               
     90                return st ? XT_HANDLED : XT_ABORT;
     91        }
    3292       
    3393        return XT_HANDLED;
    3494}
    3595
     96int jabber_start_auth( struct gaim_connection *gc )
     97{
     98        struct jabber_data *jd = gc->proto_data;
     99        struct xt_node *node;
     100        int st;
     101       
     102        node = xt_new_node( "query", NULL, xt_new_node( "username", jd->username, NULL ) );
     103        xt_add_attr( node, "xmlns", "jabber:iq:auth" );
     104        node = jabber_make_packet( "iq", "get", NULL, node );
     105       
     106        st = jabber_write_packet( gc, node );
     107       
     108        xt_free_node( node );
     109        return st;
     110}
Note: See TracChangeset for help on using the changeset viewer.