Ignore:
Timestamp:
Aug 4, 2009, 9:04:56 PM (15 years ago)
Author:
Alejandro R. Sedeño <asedeno@mit.edu>
Branches:
master, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
3ff3d86
Parents:
6bc35b4
Message:
Loosen up JID resolution

1) Fall back to substring matching if the existing resolution fails
to find any matches.

2) Allow optional loosening of full JID matching and use it for
jwrite_guess(). If we can't find the right full JID, we can now fall
back to matching the bare JID.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm

    r57ba9f1 r06f5ef8  
    13041304sub resolveConnectedJID {
    13051305    my $givenJIDStr = shift;
     1306    my $loose = shift || 0;
    13061307    my $givenJID    = new Net::Jabber::JID;
    13071308    $givenJID->SetJID($givenJIDStr);
     
    13111312        # Specified account exists
    13121313        return $givenJIDStr if ($conn->jidExists($givenJIDStr) );
     1314        return resolveConnectedJID($givenJID->GetJID('base')) if $loose;
    13131315        die("Invalid account: $givenJIDStr");
    13141316    }
     
    13161318    # Disambiguate.
    13171319    else {
    1318         my $matchingJID = "";
    1319         my $errStr =
    1320           "Ambiguous account reference. Please specify a resource.\n";
    1321         my $ambiguous = 0;
     1320        my $JIDMatchingJID = "";
     1321        my $strMatchingJID = "";
     1322        my $JIDMatches = "";
     1323        my $strMatches = "";
     1324        my $JIDAmbiguous = 0;
     1325        my $strAmbiguous = 0;
    13221326
    13231327        foreach my $jid ( $conn->getJIDs() ) {
     
    13251329            $cJID->SetJID($jid);
    13261330            if ( $givenJIDStr eq $cJID->GetJID('base') ) {
    1327                 $ambiguous = 1 if ( $matchingJID ne "" );
    1328                 $matchingJID = $jid;
    1329                 $errStr .= "\t$jid\n";
     1331                $JIDAmbiguous = 1 if ( $JIDMatchingJID ne "" );
     1332                $JIDMatchingJID = $jid;
     1333                $JIDMatches .= "\t$jid\n";
    13301334            }
     1335            if ( $cJID->GetJID('base') =~ /$givenJIDStr/ ) {
     1336                $strAmbiguous = 1 if ( $strMatchingJID ne "" );
     1337                $strMatchingJID = $jid;
     1338                $strMatches .= "\t$jid\n";
     1339            }
    13311340        }
    13321341
    13331342        # Need further disambiguation.
    1334         if ($ambiguous) {
    1335             die($errStr);
     1343        if ($JIDAmbiguous) {
     1344            my $errStr =
     1345                "Ambiguous account reference. Please specify a resource.\n";
     1346            die($errStr.$JIDMatches);
     1347        }
     1348
     1349        # It's this one.
     1350        elsif ($JIDMatchingJID ne "") {
     1351            return $JIDMatchingJID;
     1352        }
     1353
     1354        # Further resolution by substring.
     1355        elsif ($strAmbiguous) {
     1356            my $errStr =
     1357                "Ambiguous account reference. Please be more specific.\n";
     1358            die($errStr.$strMatches);
     1359        }
     1360
     1361        # It's this one, by substring.
     1362        elsif ($strMatchingJID ne "") {
     1363            return $strMatchingJID;
    13361364        }
    13371365
    13381366        # Not one of ours.
    1339         elsif ( $matchingJID eq "" ) {
     1367        else {
    13401368            die("Invalid account: $givenJIDStr");
    13411369        }
    13421370
    1343         # It's this one.
    1344         else {
    1345             return $matchingJID;
    1346         }
    13471371    }
    13481372    return "";
     
    13871411    my @matches;
    13881412    if($from) {
    1389         $from_jid = resolveConnectedJID($from);
     1413        $from_jid = resolveConnectedJID($from, 1);
    13901414        die("Unable to resolve account $from") unless $from_jid;
    13911415        $to_jid = resolveDestJID($to, $from_jid);
Note: See TracChangeset for help on using the changeset viewer.