From a564fd0a7a60990fc8bd31ffabb9a33cf9a42f32 Mon Sep 17 00:00:00 2001 From: steckbrief Date: Thu, 4 May 2017 16:23:36 +0200 Subject: storage-backend: Added json interface to list transferred files --- storage-backend/lib/functions.filetransfer.inc.php | 45 +++++++++++++- storage-backend/lib/xmpp.util.inc.php | 69 ++++++++++++++++++++++ 2 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 storage-backend/lib/xmpp.util.inc.php (limited to 'storage-backend/lib') diff --git a/storage-backend/lib/functions.filetransfer.inc.php b/storage-backend/lib/functions.filetransfer.inc.php index 679cef1..607d30f 100644 --- a/storage-backend/lib/functions.filetransfer.inc.php +++ b/storage-backend/lib/functions.filetransfer.inc.php @@ -16,8 +16,49 @@ function getUploadFilePath($slotUUID, $config, $filename = NULL) { } function loadSlotParameters($slotUUID, $config) { - $slotParameters = require(getSlotFilePath($slotUUID, $config)); + $slotFilePath = getSlotFilePath($slotUUID, $config); + $slotParameters = require($slotFilePath); $slotParameters['filename'] = $slotParameters['filename']; + $slotParameters['creation_time'] = filemtime($slotFilePath); return $slotParameters; -} \ No newline at end of file +} + +function readSlots($jid) { + global $config; + + $jid = getBareJid($jid); + $slots = array(); + + if ($handle = opendir($config['slot_registry_dir'])) { + while (false !== ($entry = readdir($handle))) { + if ($entry != "." && $entry != ".." && $entry != ".htaccess") { + $slotUUID = $entry; + $params = loadSlotParameters($slotUUID, $config); + $senderBareJid = getBareJid($params['user_jid']); + $recipientBareJid = (array_key_exists('receipient_jid', $params)) ? getBareJid($params['receipient_jid']) : ''; + if ($senderBareJid == $jid || $recipientBareJid == $jid) { + $filePath = getUploadFilePath($slotUUID, $config, $params['filename']); + $file = []; + $fileExists = file_exists($filePath); + $file['url'] = ""; + $file['sent_time'] = $params['creation_time']; + if ($fileExists) { + $file['url'] = $config['base_url_get'].$slotUUID.'/'.$params['filename']; + } + $file['fileinfo'] = []; + $file['fileinfo']['filename'] = $params['filename']; + $file['fileinfo']['filesize'] = $params['filesize']; + $file['fileinfo']['content_type'] = $params['content_type']; + $file['sender_jid'] = $senderBareJid; + $file['recipient_jid'] = $recipientBareJid; + if (null == $file['receipient_jid']) { + $file['receipient_jid'] = ""; + } + $slots[] = $file; + } + } + } + } + return $slots; +} diff --git a/storage-backend/lib/xmpp.util.inc.php b/storage-backend/lib/xmpp.util.inc.php new file mode 100644 index 0000000..cdc90fb --- /dev/null +++ b/storage-backend/lib/xmpp.util.inc.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); + } +} -- cgit v1.2.3