Show
Ignore:
Timestamp:
02/11/09 21:57:06 (13 months ago)
Author:
ykerherve
Message:

Finished resource conflit handling per RFC 3920
this introduced a medium change in the way DJabberd
do JID registration. Now, register_jid takes a bare_jid and
a resource instead of a fulljid so that we can generate a
resource in case of conflict as RECOMMENDED. XEP 0078 behaviour
is kept unchanged though.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/DJabberd/lib/DJabberd/IQ.pm

    r849 r851  
    496496    my $digest   = $get->("digest"); 
    497497 
    498     return unless $username =~ /^\w+$/; 
     498    # "Both the username and the resource are REQUIRED for client 
     499    # authentication" Section 3.1 of XEP 0078 
     500    return unless $username && $username =~ /^\w+$/; 
     501    return unless $resource; 
    499502 
    500503    my $vhost = $conn->vhost; 
     
    518521 
    519522        # register 
    520         my $jid = DJabberd::JID->new("$authjid/$resource"); 
     523        my $jid = DJabberd::JID->new("$authjid"); 
    521524 
    522525        unless ($jid) { 
     
    527530        my $regcb = DJabberd::Callback->new({ 
    528531            registered => sub { 
    529                 $conn->set_bound_jid($jid); 
     532                (undef, my $fulljid) = @_; 
     533                $conn->set_bound_jid($fulljid); 
    530534                $DJabberd::Stats::counter{'auth_success'}++; 
    531535                $iq->send_result; 
     
    540544        }); 
    541545 
    542         $vhost->register_jid($jid, $conn, $regcb); 
     546        $vhost->register_jid($jid, $resource, $conn, $regcb); 
    543547    }; 
    544548 
     
    627631    }; 
    628632 
    629     my $resource = $get->("resource") 
    630                  || Digest::SHA1::sha1_hex(rand() . rand() . rand()); 
     633    my $resource = $get->("resource") || DJabberd::JID->rand_resource; 
    631634 
    632635    my $vhost = $conn->vhost; 
     
    669672 
    670673    # register 
    671     my $jid = DJabberd::JID->new("$authjid/$resource"); 
     674    my $jid = DJabberd::JID->new($authjid); 
    672675 
    673676    unless ($jid) { 
     
    678681    my $regcb = DJabberd::Callback->new({ 
    679682        registered => sub { 
    680             $conn->set_bound_jid($jid); 
     683            (undef, my $fulljid) = @_; 
     684            $conn->set_bound_jid($fulljid); 
    681685            $DJabberd::Stats::counter{'auth_success'}++; 
    682686            my $xml = <<EOX; 
    683 <iq id='$id' type='result'> 
     687<iq id='$fulljid' type='result'> 
    684688    <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'> 
    685         <jid>$jid</jid> 
     689        <jid>$fulljid</jid> 
    686690    </bind> 
    687691</iq> 
     
    699703    }); 
    700704 
    701     $vhost->register_jid($jid, $conn, $regcb); 
     705    $vhost->register_jid($jid, $resource, $conn, $regcb); 
    702706    return 1; 
    703707}