|
|
|
|
@ -42,12 +42,12 @@ class OC_API { |
|
|
|
|
private static function init() { |
|
|
|
|
self::$server = new OC_OAuth_Server(new OC_OAuth_Store()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* api actions |
|
|
|
|
*/ |
|
|
|
|
protected static $actions = array(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* registers an api call |
|
|
|
|
* @param string $method the http method |
|
|
|
|
@ -58,7 +58,7 @@ class OC_API { |
|
|
|
|
* @param array $defaults |
|
|
|
|
* @param array $requirements |
|
|
|
|
*/ |
|
|
|
|
public static function register($method, $url, $action, $app, |
|
|
|
|
public static function register($method, $url, $action, $app, |
|
|
|
|
$authLevel = OC_API::USER_AUTH, |
|
|
|
|
$defaults = array(), |
|
|
|
|
$requirements = array()) { |
|
|
|
|
@ -73,7 +73,7 @@ class OC_API { |
|
|
|
|
} |
|
|
|
|
self::$actions[$name] = array('app' => $app, 'action' => $action, 'authlevel' => $authLevel); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* handles an api call |
|
|
|
|
* @param array $parameters |
|
|
|
|
@ -92,7 +92,7 @@ class OC_API { |
|
|
|
|
$response = call_user_func(self::$actions[$name]['action'], $parameters); |
|
|
|
|
} else { |
|
|
|
|
$response = new OC_OCS_Result(null, 998, 'Api method not found'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$response = new OC_OCS_Result(null, 997, 'Unauthorised'); |
|
|
|
|
} |
|
|
|
|
@ -103,7 +103,7 @@ class OC_API { |
|
|
|
|
// logout the user to be stateless |
|
|
|
|
OC_User::logout(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* authenticate the api call |
|
|
|
|
* @param array $action the action details as supplied to OC_API::register() |
|
|
|
|
@ -148,18 +148,18 @@ class OC_API { |
|
|
|
|
return false; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* http basic auth |
|
|
|
|
* @return string|false (username, or false on failure) |
|
|
|
|
*/ |
|
|
|
|
private static function loginUser(){ |
|
|
|
|
private static function loginUser(){ |
|
|
|
|
$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) ? $authUser : false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* respond to a call |
|
|
|
|
* @param int|array $result the result from the api method |
|
|
|
|
@ -195,5 +195,5 @@ class OC_API { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|