aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2012-07-30 21:03:41 +0200
committerBart Visscher <bartv@thisnet.nl>2012-07-30 21:19:02 +0200
commit7a24f0cd8d28e60360127da19e40bff4b2e04168 (patch)
tree43ebd6c9e00679536c565d69e561f631d352ad34
parent180bd69dbb21dc6e53533a7d93972445b2ff922e (diff)
downloadnextcloud-server-7a24f0cd8d28e60360127da19e40bff4b2e04168.tar.gz
nextcloud-server-7a24f0cd8d28e60360127da19e40bff4b2e04168.zip
Make calling ocs/v1.php/config work
-rw-r--r--lib/api.php17
-rw-r--r--lib/app.php2
-rw-r--r--lib/ocs.php18
-rw-r--r--ocs/v1.php12
4 files changed, 41 insertions, 8 deletions
diff --git a/lib/api.php b/lib/api.php
index fd2c621f389..515bab6714e 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 60bd0ef476b..7863153d9b9 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 d7a7951fab5..780fd4a6581 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 ab0dc80f4ba..4580221e600 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();
+}