aboutsummaryrefslogtreecommitdiffstats
path: root/storage-backend/lib
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2016-09-30 16:03:18 +0200
committersteckbrief <steckbrief@chefmail.de>2016-09-30 16:03:18 +0200
commit509128be585b7108ef77f807d49ce5ffe1a57853 (patch)
tree97439b75d0f8a1f1d045f75277c0b2f35456c23c /storage-backend/lib
parent7ce02c25b1a1e0ed915be4a9bc781744328d92ee (diff)
Implements FS#236: Save receipient jid
Diffstat (limited to 'storage-backend/lib')
-rw-r--r--storage-backend/lib/functions.common.inc.php18
-rw-r--r--storage-backend/lib/functions.filetransfer.inc.php23
-rw-r--r--storage-backend/lib/functions.http.inc.php64
3 files changed, 105 insertions, 0 deletions
diff --git a/storage-backend/lib/functions.common.inc.php b/storage-backend/lib/functions.common.inc.php
new file mode 100644
index 0000000..b47268e
--- /dev/null
+++ b/storage-backend/lib/functions.common.inc.php
@@ -0,0 +1,18 @@
+<?php
+/*
+ * This file contains functions commonly used.
+ */
+
+/**
+ * Copied from http://rogerstringer.com/2013/11/15/generate-uuids-php/
+ */
+function generate_uuid() {
+ return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
+ mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
+ mt_rand( 0, 0xffff ),
+ mt_rand( 0, 0x0fff ) | 0x4000,
+ mt_rand( 0, 0x3fff ) | 0x8000,
+ mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
+ );
+}
+?> \ No newline at end of file
diff --git a/storage-backend/lib/functions.filetransfer.inc.php b/storage-backend/lib/functions.filetransfer.inc.php
new file mode 100644
index 0000000..679cef1
--- /dev/null
+++ b/storage-backend/lib/functions.filetransfer.inc.php
@@ -0,0 +1,23 @@
+<?php
+/*
+ * This file contains the functions for the storage-backend.
+ */
+
+function getSlotFilePath($slotUUID, $config) {
+ return $config['slot_registry_dir'].$slotUUID;
+}
+
+function getUploadFilePath($slotUUID, $config, $filename = NULL) {
+ $path = $config['storage_base_path'].$slotUUID;
+ if (!is_null($filename)) {
+ $path .= '/'.$filename;
+ }
+ return $path;
+}
+
+function loadSlotParameters($slotUUID, $config) {
+ $slotParameters = require(getSlotFilePath($slotUUID, $config));
+ $slotParameters['filename'] = $slotParameters['filename'];
+
+ return $slotParameters;
+} \ No newline at end of file
diff --git a/storage-backend/lib/functions.http.inc.php b/storage-backend/lib/functions.http.inc.php
new file mode 100644
index 0000000..c508b20
--- /dev/null
+++ b/storage-backend/lib/functions.http.inc.php
@@ -0,0 +1,64 @@
+<?php
+/*
+ *
+ * This file contains functions to be used to
+ * extract information based on http request information.
+ *
+ */
+
+/**
+ * Inspired by https://github.com/owncloud/core/blob/master/lib/private/appframework/http/request.php#L523
+ */
+function getServerProtocol() {
+ if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
+ if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], ',') !== false) {
+ $parts = explode(',', $_SERVER['HTTP_X_FORWARDED_PROTO']);
+ $proto = strtolower(trim($parts[0]));
+ } else {
+ $proto = strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']);
+ }
+ // Verify that the protocol is always HTTP or HTTPS
+ // default to http if an invalid value is provided
+ return $proto === 'https' ? 'https' : 'http';
+ }
+ if (isset($_SERVER['HTTPS'])
+ && $_SERVER['HTTPS'] !== null
+ && $_SERVER['HTTPS'] !== 'off'
+ && $_SERVER['HTTPS'] !== '') {
+ return 'https';
+ }
+ return 'http';
+}
+
+function getRequestHostname() {
+ if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
+ return strtolower($_SERVER['HTTP_X_FORWARDED_HOST']);
+ }
+ return strtolower($_SERVER['HTTP_HOST']);
+}
+
+function getRequestUriWithoutFilename() {
+ return strtolower(substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/') + 1));
+}
+
+function sendHttpReturnCodeAndJson($code, $data) {
+ if (!is_array($data)) {
+ $data = ['msg' => $data];
+ }
+ header('Content-Type: application/json');
+ sendHttpReturnCodeAndMessage($code, json_encode($data));
+}
+
+function sendHttpReturnCodeAndMessage($code, $text = '') {
+ http_response_code($code);
+ exit($text);
+}
+
+function getOptionalPostParameter($parameterName, $default = NULL) {
+ $parameter = $_POST[$parameterName];
+ if (!isset($parameter) || is_null($parameter) || empty($parameter)) {
+ $parameter = $default;
+ }
+ return $parameter;
+}
+?> \ No newline at end of file