summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-04-20 09:43:19 +0200
committerMorris Jobke <hey@morrisjobke.de>2015-04-20 09:43:19 +0200
commit9cb260d310de5bed546531eff5fbf0b7518f0f2f (patch)
tree04295e7bb0d18986e701a86640dc8216ca56ffea /lib
parent75bf03a6051d69d9d242f55f4ee77a3696dc68fe (diff)
parentf6807337a8f576b92a2586efc00173229fd681c9 (diff)
downloadnextcloud-server-9cb260d310de5bed546531eff5fbf0b7518f0f2f.tar.gz
nextcloud-server-9cb260d310de5bed546531eff5fbf0b7518f0f2f.zip
Merge pull request #15717 from owncloud/issue/15716-fixing-ocp-api-namespace-usage
Fixing OCS API namespace usage
Diffstat (limited to 'lib')
-rw-r--r--lib/private/api.php36
-rw-r--r--lib/public/api.php22
2 files changed, 46 insertions, 12 deletions
diff --git a/lib/private/api.php b/lib/private/api.php
index 119cdb7d1a3..dd50162f03e 100644
--- a/lib/private/api.php
+++ b/lib/private/api.php
@@ -34,17 +34,33 @@ class OC_API {
/**
* API authentication levels
*/
+
+ /** @deprecated Use \OCP\API::GUEST_AUTH instead */
const GUEST_AUTH = 0;
+
+ /** @deprecated Use \OCP\API::USER_AUTH instead */
const USER_AUTH = 1;
+
+ /** @deprecated Use \OCP\API::SUBADMIN_AUTH instead */
const SUBADMIN_AUTH = 2;
+
+ /** @deprecated Use \OCP\API::ADMIN_AUTH instead */
const ADMIN_AUTH = 3;
/**
* API Response Codes
*/
+
+ /** @deprecated Use \OCP\API::RESPOND_UNAUTHORISED instead */
const RESPOND_UNAUTHORISED = 997;
+
+ /** @deprecated Use \OCP\API::RESPOND_SERVER_ERROR instead */
const RESPOND_SERVER_ERROR = 996;
+
+ /** @deprecated Use \OCP\API::RESPOND_NOT_FOUND instead */
const RESPOND_NOT_FOUND = 998;
+
+ /** @deprecated Use \OCP\API::RESPOND_UNKNOWN_ERROR instead */
const RESPOND_UNKNOWN_ERROR = 999;
/**
@@ -65,7 +81,7 @@ class OC_API {
* @param array $requirements
*/
public static function register($method, $url, $action, $app,
- $authLevel = OC_API::USER_AUTH,
+ $authLevel = \OCP\API::USER_AUTH,
$defaults = array(),
$requirements = array()) {
$name = strtolower($method).$url;
@@ -106,7 +122,7 @@ class OC_API {
if(!self::isAuthorised($action)) {
$responses[] = array(
'app' => $action['app'],
- 'response' => new OC_OCS_Result(null, OC_API::RESPOND_UNAUTHORISED, 'Unauthorised'),
+ 'response' => new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED, 'Unauthorised'),
'shipped' => OC_App::isShipped($action['app']),
);
continue;
@@ -114,7 +130,7 @@ class OC_API {
if(!is_callable($action['action'])) {
$responses[] = array(
'app' => $action['app'],
- 'response' => new OC_OCS_Result(null, OC_API::RESPOND_NOT_FOUND, 'Api method not found'),
+ 'response' => new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, 'Api method not found'),
'shipped' => OC_App::isShipped($action['app']),
);
continue;
@@ -172,7 +188,7 @@ class OC_API {
// Which shipped response do we use if they all failed?
// They may have failed for different reasons (different status codes)
// Which response code should we return?
- // Maybe any that are not OC_API::RESPOND_SERVER_ERROR
+ // Maybe any that are not \OCP\API::RESPOND_SERVER_ERROR
// Merge failed responses if more than one
$data = array();
foreach($shipped['failed'] as $failure) {
@@ -235,15 +251,15 @@ class OC_API {
private static function isAuthorised($action) {
$level = $action['authlevel'];
switch($level) {
- case OC_API::GUEST_AUTH:
+ case \OCP\API::GUEST_AUTH:
// Anyone can access
return true;
break;
- case OC_API::USER_AUTH:
+ case \OCP\API::USER_AUTH:
// User required
return self::loginUser();
break;
- case OC_API::SUBADMIN_AUTH:
+ case \OCP\API::SUBADMIN_AUTH:
// Check for subadmin
$user = self::loginUser();
if(!$user) {
@@ -258,7 +274,7 @@ class OC_API {
}
}
break;
- case OC_API::ADMIN_AUTH:
+ case \OCP\API::ADMIN_AUTH:
// Check for admin
$user = self::loginUser();
if(!$user) {
@@ -325,7 +341,7 @@ class OC_API {
*/
public static function respond($result, $format='xml') {
// Send 401 headers if unauthorised
- if($result->getStatusCode() === self::RESPOND_UNAUTHORISED) {
+ if($result->getStatusCode() === \OCP\API::RESPOND_UNAUTHORISED) {
header('WWW-Authenticate: Basic realm="Authorisation Required"');
header('HTTP/1.0 401 Unauthorized');
}
@@ -384,7 +400,7 @@ class OC_API {
* Based on the requested format the response content type is set
*/
public static function setContentType() {
- $format = \OC_API::requestedFormat();
+ $format = self::requestedFormat();
if ($format === 'xml') {
header('Content-type: text/xml; charset=UTF-8');
return;
diff --git a/lib/public/api.php b/lib/public/api.php
index 7ef6902634c..6b920b6cf52 100644
--- a/lib/public/api.php
+++ b/lib/public/api.php
@@ -38,17 +38,35 @@ namespace OCP;
class API {
/**
+ * API authentication levels
+ * @since 8.1.0
+ */
+ const GUEST_AUTH = 0;
+ const USER_AUTH = 1;
+ const SUBADMIN_AUTH = 2;
+ const ADMIN_AUTH = 3;
+
+ /**
+ * API Response Codes
+ * @since 8.1.0
+ */
+ const RESPOND_UNAUTHORISED = 997;
+ const RESPOND_SERVER_ERROR = 996;
+ const RESPOND_NOT_FOUND = 998;
+ const RESPOND_UNKNOWN_ERROR = 999;
+
+ /**
* registers an api call
* @param string $method the http method
* @param string $url the url to match
* @param callable $action the function to run
* @param string $app the id of the app registering the call
- * @param int $authLevel the level of authentication required for the call (See OC_API constants)
+ * @param int $authLevel the level of authentication required for the call (See `self::*_AUTH` constants)
* @param array $defaults
* @param array $requirements
* @since 5.0.0
*/
- public static function register($method, $url, $action, $app, $authLevel = OC_API::USER_AUTH,
+ public static function register($method, $url, $action, $app, $authLevel = self::USER_AUTH,
$defaults = array(), $requirements = array()){
\OC_API::register($method, $url, $action, $app, $authLevel, $defaults, $requirements);
}