diff --git a/lib/api.php b/lib/api.php index fd2c621f38..515bab6714 100644 --- a/lib/api.php +++ b/lib/api.php @@ -43,7 +43,8 @@ class OC_API { $name = str_replace(array('/', '{', '}'), '_', $name); if(!isset(self::$actions[$name])){ OC::$router->create($name, $url.'.{_format}') - ->defaults(array('_format'=>'xml')) + ->defaults(array('_format' => 'xml')) + ->requirements(array('_format' => 'xml|json')) ->action('OC_API', 'call'); self::$actions[$name] = array(); } @@ -55,7 +56,7 @@ class OC_API { * @param array $parameters */ public static function call($parameters){ - $name = $parameters['_name']; + $name = $parameters['_route']; // Loop through registered actions foreach(self::$actions[$name] as $action){ $app = $action['app']; @@ -107,8 +108,14 @@ class OC_API { * @param int|array $response the response * @param string $format the format xml|json */ - private function respond($response, $format='json'){ - // TODO respond in the correct format + private static function respond($response, $format='json'){ + if ($format == 'json') { + echo json_encode($response); + } else if ($format == 'xml') { + // TODO array to xml + } else { + var_dump($format, $response); + } } -} \ No newline at end of file +} diff --git a/lib/app.php b/lib/app.php index 60bd0ef476..7863153d9b 100644 --- a/lib/app.php +++ b/lib/app.php @@ -145,7 +145,7 @@ class OC_App{ * @param string $appid the id of the app to check * @return bool */ - public function isShipped($appid){ + public static function isShipped($appid){ $info = self::getAppInfo($appid); if(isset($info['shipped']) && $info['shipped']=='true'){ return true; diff --git a/lib/ocs.php b/lib/ocs.php index d7a7951fab..780fd4a658 100644 --- a/lib/ocs.php +++ b/lib/ocs.php @@ -251,6 +251,24 @@ class OC_OCS { exit(); } + public static function notFound() { + if($_SERVER['REQUEST_METHOD'] == 'GET') { + $method='get'; + }elseif($_SERVER['REQUEST_METHOD'] == 'PUT') { + $method='put'; + parse_str(file_get_contents("php://input"),$put_vars); + }elseif($_SERVER['REQUEST_METHOD'] == 'POST') { + $method='post'; + }else{ + echo('internal server error: method not supported'); + exit(); + } + $format = self::readData($method, 'format', 'text', ''); + $txt='Invalid query, please check the syntax. API specifications are here: http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n"; + $txt.=OC_OCS::getDebugOutput(); + echo(OC_OCS::generateXml($format,'failed',999,$txt)); + } + /** * generated some debug information to make it easier to find faild API calls * @return debug data string diff --git a/ocs/v1.php b/ocs/v1.php index ab0dc80f4b..4580221e60 100644 --- a/ocs/v1.php +++ b/ocs/v1.php @@ -22,5 +22,13 @@ */ require_once('../lib/base.php'); -@ob_clean(); -OC_OCS::handle(); +use Symfony\Component\Routing\Exception\ResourceNotFoundException; + +OC::$router->useCollection('ocs'); +OC::$router->loadRoutes(); + +try { + OC::$router->match($_SERVER['PATH_INFO']); +} catch (ResourceNotFoundException $e) { + OC_OCS::notFound(); +}