From 2a6a9a8cefcf68f48d95e124db0c1b7edc9fe356 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Thu, 6 Feb 2014 16:30:58 +0100 Subject: polish documentation based on scrutinizer patches --- lib/private/api.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/private/api.php') diff --git a/lib/private/api.php b/lib/private/api.php index c713368125c..3f96196e6df 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -328,6 +328,9 @@ class OC_API { } } + /** + * @param XMLWriter $writer + */ private static function toXML($array, $writer) { foreach($array as $k => $v) { if ($k[0] === '@') { -- cgit v1.2.3 From 0d90b90d9402cbcab4037efc913728cdeb4eadbd Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Fri, 7 Mar 2014 20:00:34 +0100 Subject: we first shall check if the current session is valid - otherwise the session-id will be regenerated on login via basic auth --- lib/private/api.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'lib/private/api.php') diff --git a/lib/private/api.php b/lib/private/api.php index 3f96196e6df..e9d31242e3a 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -270,7 +270,19 @@ class OC_API { * @return string|false (username, or false on failure) */ private static function loginUser(){ - // basic auth + + // 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'] : ''; $return = OC_User::login($authUser, $authPw); @@ -283,17 +295,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; } -- cgit v1.2.3 From 25f523680ac1ed46470ea40277e578fd35ec02a7 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Fri, 7 Mar 2014 20:06:06 +0100 Subject: fixing ident --- lib/private/api.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'lib/private/api.php') diff --git a/lib/private/api.php b/lib/private/api.php index e9d31242e3a..1537cc11dd0 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -271,18 +271,18 @@ class OC_API { */ 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) { + // 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()); + // initialize the user's filesystem + \OC_Util::setUpFS(\OC_User::getUser()); - return OC_User::getUser(); - } + return OC_User::getUser(); + } - // basic auth + // basic auth $authUser = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : ''; $authPw = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : ''; $return = OC_User::login($authUser, $authPw); -- cgit v1.2.3 From 26793e1f943012937776324698855108dd5352ba Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 10 Mar 2014 14:06:47 +0100 Subject: switch OC::getRouter usages to OC::$server->getRouter --- lib/base.php | 10 +--------- lib/private/api.php | 4 ++-- lib/private/urlgenerator.php | 2 +- ocs/v1.php | 2 +- 4 files changed, 5 insertions(+), 13 deletions(-) (limited to 'lib/private/api.php') diff --git a/lib/base.php b/lib/base.php index d49dd958310..4bc6c4329c4 100644 --- a/lib/base.php +++ b/lib/base.php @@ -382,14 +382,6 @@ class OC { return OC_Config::getValue('session_lifetime', 60 * 60 * 24); } - /** - * @return \OCP\Route\IRouter - */ - public static function getRouter() { - return self::$server->getRouter(); - } - - public static function loadAppClassPaths() { foreach (OC_APP::getEnabledApps() as $app) { $file = OC_App::getAppPath($app) . '/appinfo/classpath.php'; @@ -714,7 +706,7 @@ class OC { OC_App::loadApps(); } self::checkSingleUserMode(); - OC::getRouter()->match(OC_Request::getRawPathInfo()); + OC::$server->getRouter()->match(OC_Request::getRawPathInfo()); return; } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { //header('HTTP/1.0 404 Not Found'); diff --git a/lib/private/api.php b/lib/private/api.php index 3f96196e6df..cde24f78a55 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) diff --git a/lib/private/urlgenerator.php b/lib/private/urlgenerator.php index 60da34f2d6e..44b46ef6700 100644 --- a/lib/private/urlgenerator.php +++ b/lib/private/urlgenerator.php @@ -39,7 +39,7 @@ class URLGenerator implements IURLGenerator { * Returns a url to the given app and file. */ public function linkToRoute($route, $parameters = array()) { - $urlLinkTo = \OC::getRouter()->generate($route, $parameters); + $urlLinkTo = \OC::$server->getRouter()->generate($route, $parameters); return $urlLinkTo; } diff --git a/ocs/v1.php b/ocs/v1.php index 1c7d1c89768..3da72e65f1c 100644 --- a/ocs/v1.php +++ b/ocs/v1.php @@ -26,7 +26,7 @@ use Symfony\Component\Routing\Exception\ResourceNotFoundException; use Symfony\Component\Routing\Exception\MethodNotAllowedException; try { - OC::getRouter()->match('/ocs'.OC_Request::getRawPathInfo()); + OC::$server->getRouter()->match('/ocs'.OC_Request::getRawPathInfo()); } catch (ResourceNotFoundException $e) { OC_OCS::notFound(); } catch (MethodNotAllowedException $e) { -- cgit v1.2.3 From 743addd1e317c760e8b1e4ad7dc149476e4ad282 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Wed, 12 Mar 2014 00:35:19 +0100 Subject: set content-type on ocs exceptions --- lib/private/api.php | 33 ++++++++++++++++++++++++++++++--- ocs/v1.php | 3 +++ 2 files changed, 33 insertions(+), 3 deletions(-) (limited to 'lib/private/api.php') diff --git a/lib/private/api.php b/lib/private/api.php index 1537cc11dd0..ccaccda97be 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -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(); } @@ -350,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 setOcsContentType() { + $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'); + } + + } diff --git a/ocs/v1.php b/ocs/v1.php index 1c7d1c89768..9d84f482ef7 100644 --- a/ocs/v1.php +++ b/ocs/v1.php @@ -28,8 +28,11 @@ use Symfony\Component\Routing\Exception\MethodNotAllowedException; try { OC::getRouter()->match('/ocs'.OC_Request::getRawPathInfo()); } catch (ResourceNotFoundException $e) { + OC_API::setContentType(); OC_OCS::notFound(); } catch (MethodNotAllowedException $e) { + setOcsContentType(); + OC_API::setContentType(); OC_Response::setStatus(405); } -- cgit v1.2.3 From 88f6dd7db1b3dc4cb68d3526a35108d196a5e5cb Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Wed, 12 Mar 2014 10:00:22 +0100 Subject: fixing method names --- lib/private/api.php | 2 +- ocs/v1.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/private/api.php') diff --git a/lib/private/api.php b/lib/private/api.php index ccaccda97be..e8e54e375e9 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -361,7 +361,7 @@ class OC_API { /** * Based on the requested format the response content type is set */ - public static function setOcsContentType() { + public static function setContentType() { $format = \OC_API::requestedFormat(); if ($format === 'xml') { header('Content-type: text/xml; charset=UTF-8'); diff --git a/ocs/v1.php b/ocs/v1.php index 9d84f482ef7..4cbc857bbcf 100644 --- a/ocs/v1.php +++ b/ocs/v1.php @@ -31,7 +31,6 @@ try { OC_API::setContentType(); OC_OCS::notFound(); } catch (MethodNotAllowedException $e) { - setOcsContentType(); OC_API::setContentType(); OC_Response::setStatus(405); } -- cgit v1.2.3