From 4743fe3c6090a8e409ba7e26fbae53ef6e4d1892 Mon Sep 17 00:00:00 2001 From: steckbrief Date: Mon, 9 Jan 2017 20:42:43 +0100 Subject: initial commit --- xmpp.util.php | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 xmpp.util.php (limited to 'xmpp.util.php') diff --git a/xmpp.util.php b/xmpp.util.php new file mode 100644 index 0000000..5bde0c0 --- /dev/null +++ b/xmpp.util.php @@ -0,0 +1,69 @@ + $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); + } +} \ No newline at end of file -- cgit v1.2.3