aboutsummaryrefslogtreecommitdiffstats
path: root/managing-ui/lib/xmpp/xmpp.util.php
blob: 5bde0c02224a229bdef9906130c772fbb6dd6613 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/*
 * xmpp jid util functions.
 */
 
function getJidDomain($jid) {
    if (null == $jid) {
        return null;
    }
    
    $atIndex = strpos($jid, '@');
    $slashIndex = strpos($jid, '/');
    
    if ($slashIndex !== false) {
        if ($slashIndex > $atIndex) {// 'local@domain.foo/resource' and 'local@domain.foo/res@otherres' case
            return substr($jid, $atIndex + 1, $slashIndex - $atIndex + 1);
        } else {// 'domain.foo/res@otherres' case
            return substr($jid, 0, $slashIndex);
        }
    } else {
        return substr($jid, $atIndex + 1);
    }
}

function getJidLocalPart($jid) {
    if ($jid == null) {
        return null;
    }

    $atIndex = strpos($jid, '@');
    if ($atIndex === false || $atIndex == 0) {
        return "";
    }
    
    $slashIndex = strpos($jid, '/');
    if ($slashIndex !== false && $slashIndex < $atIndex) {
        return "";
    } else {
        return substr($jid, 0, $atIndex);
    }
}

function getBareJid($jid) {
    if ($jid == null) {
        return null;
    }
    
    $slashIndex = strpos($jid, '/');
    if ($slashIndex === false) {
        return $jid;
    } else if ($slashIndex == 0) {
        return "";
    } else {
        return substr($jid, 0, $slashIndex);
    }
}

function getResource($jid) {
    if ($jid == null) {
        return null;
    }

    $slashIndex = strpos($jid, '/');
    if ($slashIndex + 1 > strlen($jid) || $slashIndex === false) {
        return "";
    } else {
        return substr($jid, $slashIndex + 1);
    }
}