Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/api.php')
-rw-r--r--lib/private/api.php63
1 files changed, 47 insertions, 16 deletions
diff --git a/lib/private/api.php b/lib/private/api.php
index c713368125c..b3b5eb1067b 100644
--- a/lib/private/api.php
+++ b/lib/private/api.php
@@ -65,8 +65,8 @@ class OC_API {
$name = strtolower($method).$url;
$name = str_replace(array('/', '{', '}'), '_', $name);
if(!isset(self::$actions[$name])) {
- OC::getRouter()->useCollection('ocs');
- OC::getRouter()->create($name, $url)
+ OC::$server->getRouter()->useCollection('ocs');
+ OC::$server->getRouter()->create($name, $url)
->method($method)
->defaults($defaults)
->requirements($requirements)
@@ -116,9 +116,7 @@ class OC_API {
);
}
$response = self::mergeResponses($responses);
- $formats = array('json', 'xml');
-
- $format = !empty($_GET['format']) && in_array($_GET['format'], $formats) ? $_GET['format'] : 'xml';
+ $format = self::requestedFormat();
if (self::$logoutRequired) {
OC_User::logout();
}
@@ -270,6 +268,18 @@ class OC_API {
* @return string|false (username, or false on failure)
*/
private static function loginUser(){
+
+ // reuse existing login
+ $loggedIn = OC_User::isLoggedIn();
+ $ocsApiRequest = isset($_SERVER['HTTP_OCS_APIREQUEST']) ? $_SERVER['HTTP_OCS_APIREQUEST'] === 'true' : false;
+ if ($loggedIn === true && $ocsApiRequest) {
+
+ // initialize the user's filesystem
+ \OC_Util::setUpFS(\OC_User::getUser());
+
+ return OC_User::getUser();
+ }
+
// basic auth
$authUser = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '';
$authPw = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '';
@@ -283,17 +293,6 @@ class OC_API {
return $authUser;
}
- // reuse existing login
- $loggedIn = OC_User::isLoggedIn();
- $ocsApiRequest = isset($_SERVER['HTTP_OCS_APIREQUEST']) ? $_SERVER['HTTP_OCS_APIREQUEST'] === 'true' : false;
- if ($loggedIn === true && $ocsApiRequest) {
-
- // initialize the user's filesystem
- \OC_Util::setUpFS(\OC_User::getUser());
-
- return OC_User::getUser();
- }
-
return false;
}
@@ -328,6 +327,9 @@ class OC_API {
}
}
+ /**
+ * @param XMLWriter $writer
+ */
private static function toXML($array, $writer) {
foreach($array as $k => $v) {
if ($k[0] === '@') {
@@ -346,4 +348,33 @@ class OC_API {
}
}
+ /**
+ * @return string
+ */
+ public static function requestedFormat() {
+ $formats = array('json', 'xml');
+
+ $format = !empty($_GET['format']) && in_array($_GET['format'], $formats) ? $_GET['format'] : 'xml';
+ return $format;
+ }
+
+ /**
+ * Based on the requested format the response content type is set
+ */
+ public static function setContentType() {
+ $format = \OC_API::requestedFormat();
+ if ($format === 'xml') {
+ header('Content-type: text/xml; charset=UTF-8');
+ return;
+ }
+
+ if ($format === 'json') {
+ header('Content-Type: application/json; charset=utf-8');
+ return;
+ }
+
+ header('Content-Type: application/octet-stream; charset=utf-8');
+ }
+
+
}