]> source.dussan.org Git - nextcloud-server.git/commitdiff
Merge master into ocs_api, fix conflicts.
authorTom Needham <needham.thomas@gmail.com>
Fri, 14 Dec 2012 15:15:05 +0000 (15:15 +0000)
committerTom Needham <needham.thomas@gmail.com>
Fri, 14 Dec 2012 15:15:05 +0000 (15:15 +0000)
1  2 
lib/app.php
lib/ocs.php
lib/router.php
ocs/v1.php

diff --cc lib/app.php
index 3d2ceb1729f8302554bfc90419c00246d5448857,5d4fbbd9c2322420004b0282cb18a95b65f9c8d0..ccd0958cd01a45878702c75ca52c5b665483f6e9
mode 100644,100755..100644
diff --cc lib/ocs.php
index 001965d45e3356e486f0c14f61176783d630506f,1a0abf0e367173576eee93afaa0bb935752608e1..879aaa7668739be87f3d2e50df6f5358be914872
@@@ -82,11 -92,171 +85,12 @@@ class OC_OCS 
                        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));
  
 -              $router = new OC_Router();
 -              $router->useCollection('root');
 -              // CONFIG
 -              $router->create('config', '/config.{format}')
 -                      ->defaults(array('format' => $format))
 -                      ->action('OC_OCS', 'apiConfig')
 -                      ->requirements(array('format'=>'xml|json'));
 -
 -              // PERSON
 -              $router->create('person_check', '/person/check.{format}')
 -                      ->post()
 -                      ->defaults(array('format' => $format))
 -                      ->action(function ($parameters) {
 -                                      $format = $parameters['format'];
 -                                      $login = OC_OCS::readData('post', 'login', 'text');
 -                                      $passwd = OC_OCS::readData('post', 'password', 'text');
 -                                      OC_OCS::personCheck($format, $login, $passwd);
 -                              })
 -                      ->requirements(array('format'=>'xml|json'));
 -
 -              // ACTIVITY
 -              // activityget - GET ACTIVITY   page,pagesize als urlparameter
 -              $router->create('activity_get', '/activity.{format}')
 -                      ->defaults(array('format' => $format))
 -                      ->action(function ($parameters) {
 -                                      $format = $parameters['format'];
 -                                      $page = OC_OCS::readData('get', 'page', 'int', 0);
 -                                      $pagesize = OC_OCS::readData('get', 'pagesize', 'int', 10);
 -                                      if($pagesize<1 or $pagesize>100) $pagesize=10;
 -                                      OC_OCS::activityGet($format, $page, $pagesize);
 -                              })
 -                      ->requirements(array('format'=>'xml|json'));
 -              // activityput - POST ACTIVITY
 -              $router->create('activity_put', '/activity.{format}')
 -                      ->post()
 -                      ->defaults(array('format' => $format))
 -                      ->action(function ($parameters) {
 -                                      $format = $parameters['format'];
 -                                      $message = OC_OCS::readData('post', 'message', 'text');
 -                                      OC_OCS::activityPut($format, $message);
 -                              })
 -                      ->requirements(array('format'=>'xml|json'));
 -
 -              // PRIVATEDATA
 -              // get - GET DATA
 -              $router->create('privatedata_get',
 -                                '/privatedata/getattribute/{app}/{key}.{format}')
 -                      ->defaults(array('app' => '', 'key' => '', 'format' => $format))
 -                      ->action(function ($parameters) {
 -                                      $format = $parameters['format'];
 -                                      $app = addslashes(strip_tags($parameters['app']));
 -                                      $key = addslashes(strip_tags($parameters['key']));
 -                                      OC_OCS::privateDataGet($format, $app, $key);
 -                              })
 -                      ->requirements(array('format'=>'xml|json'));
 -              // set - POST DATA
 -              $router->create('privatedata_set',
 -                                '/privatedata/setattribute/{app}/{key}.{format}')
 -                      ->post()
 -                      ->defaults(array('format' => $format))
 -                      ->action(function ($parameters) {
 -                                      $format = $parameters['format'];
 -                                      $app = addslashes(strip_tags($parameters['app']));
 -                                      $key = addslashes(strip_tags($parameters['key']));
 -                                      $value=OC_OCS::readData('post', 'value', 'text');
 -                                      OC_OCS::privateDataSet($format, $app, $key, $value);
 -                              })
 -                      ->requirements(array('format'=>'xml|json'));
 -              // delete - POST DATA
 -              $router->create('privatedata_delete',
 -                                '/privatedata/deleteattribute/{app}/{key}.{format}')
 -                      ->post()
 -                      ->defaults(array('format' => $format))
 -                      ->action(function ($parameters) {
 -                                      $format = $parameters['format'];
 -                                      $app = addslashes(strip_tags($parameters['app']));
 -                                      $key = addslashes(strip_tags($parameters['key']));
 -                                      OC_OCS::privateDataDelete($format, $app, $key);
 -                              })
 -                      ->requirements(array('format'=>'xml|json'));
 -
 -              // CLOUD
 -              // systemWebApps
 -              $router->create('system_webapps',
 -                                '/cloud/system/webapps.{format}')
 -                      ->defaults(array('format' => $format))
 -                      ->action(function ($parameters) {
 -                                      $format = $parameters['format'];
 -                                      OC_OCS::systemwebapps($format);
 -                              })
 -                      ->requirements(array('format'=>'xml|json'));
 -
 -              // quotaget
 -              $router->create('quota_get',
 -                                '/cloud/user/{user}.{format}')
 -                      ->defaults(array('format' => $format))
 -                      ->action(function ($parameters) {
 -                                      $format = $parameters['format'];
 -                                      $user = $parameters['user'];
 -                                      OC_OCS::quotaGet($format, $user);
 -                              })
 -                      ->requirements(array('format'=>'xml|json'));
 -              // quotaset
 -              $router->create('quota_set',
 -                                '/cloud/user/{user}.{format}')
 -                      ->post()
 -                      ->defaults(array('format' => $format))
 -                      ->action(function ($parameters) {
 -                                      $format = $parameters['format'];
 -                                      $user = $parameters['user'];
 -                                      $quota = self::readData('post', 'quota', 'int');
 -                                      OC_OCS::quotaSet($format, $user, $quota);
 -                              })
 -                      ->requirements(array('format'=>'xml|json'));
 -
 -              // keygetpublic
 -              $router->create('keygetpublic',
 -                                '/cloud/user/{user}/publickey.{format}')
 -                      ->defaults(array('format' => $format))
 -                      ->action(function ($parameters) {
 -                                      $format = $parameters['format'];
 -                                      $user = $parameters['user'];
 -                                      OC_OCS::publicKeyGet($format, $user);
 -                              })
 -                      ->requirements(array('format'=>'xml|json'));
 -
 -              // keygetprivate
 -              $router->create('keygetpublic',
 -                                '/cloud/user/{user}/privatekey.{format}')
 -                      ->defaults(array('format' => $format))
 -                      ->action(function ($parameters) {
 -                                      $format = $parameters['format'];
 -                                      $user = $parameters['user'];
 -                                      OC_OCS::privateKeyGet($format, $user);
 -                              })
 -                      ->requirements(array('format'=>'xml|json'));
 -
 -
 -// add more calls here
 -// please document all the call in the draft spec
 -// http://www.freedesktop.org/wiki/Specifications/open-collaboration-services-1.7#CLOUD
 -
 -// TODO:
 -// users
 -// groups
 -// bookmarks
 -// sharing
 -// versioning
 -// news (rss)
 -              try {
 -                      $router->match($_SERVER['PATH_INFO']);
 -              } catch (ResourceNotFoundException $e) {
 -                      $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));
 -              } catch (MethodNotAllowedException $e) {
 -                      OC_Response::setStatus(405);
 -              }
 -              exit();
        }
  
        /**
                return $result;
        }
  
 -      /**
 -      * set private data referenced by $key to $value
 -      * @param string $user
 -      * @param string $app
 -      * @param string $key
 -      * @param string $value
 -      * @return bool
 -      */
 -      public static function setData($user, $app, $key, $value) {
 -              return OC_Preferences::setValue($user, $app, $key, $value);
 -      }
 -
 -      /**
 -      * delete private data referenced by $key
 -      * @param string $user
 -      * @param string $app
 -      * @param string $key
 -      * @return string xml/json
 -      */
 -      public static function deleteData($user, $app, $key) {
 -              return OC_Preferences::deleteKey($user, $app, $key);
 -      }
 -
 -
 -        // CLOUD API #############################################
 -
 -        /**
 -        * get a list of installed web apps
 -        * @param string $format
 -        * @return string xml/json
 -        */
 -        private static function systemWebApps($format) {
 -                $login=OC_OCS::checkpassword();
 -              $apps=OC_App::getEnabledApps();
 -              $values=array();
 -              foreach($apps as $app) {
 -                      $info=OC_App::getAppInfo($app);
 -                      if(isset($info['standalone'])) {
 -                              $newvalue=array('name'=>$info['name'], 'url'=>OC_Helper::linkToAbsolute($app, ''), 'icon'=>'');
 -                              $values[]=$newvalue;
 -                      }
 -
 -              }
 -              $txt=OC_OCS::generatexml($format, 'ok', 100, '', $values, 'cloud', '', 2, 0, 0);
 -              echo($txt);
 -
 -        }
 -
 -
 -        /**
 -        * get the quota of a user
 -        * @param string $format
 -        * @param string $user
 -        * @return string xml/json
 -        */
 -        private static function quotaGet($format, $user) {
 -                $login=OC_OCS::checkpassword();
 -              if(OC_Group::inGroup($login, 'admin') or ($login==$user)) {
 -
 -                      if(OC_User::userExists($user)) {
 -                              // calculate the disc space
 -                              $user_dir = '/'.$user.'/files';
 -                              OC_Filesystem::init($user_dir);
 -                              $rootInfo=OC_FileCache::get('');
 -                              $sharedInfo=OC_FileCache::get('/Shared');
 -                              $used=$rootInfo['size']-$sharedInfo['size'];
 -                              $free=OC_Filesystem::free_space();
 -                              $total=$free+$used;
 -                              if($total==0) $total=1;  // prevent division by zero
 -                              $relative=round(($used/$total)*10000)/100;
 -
 -                              $xml=array();
 -                              $xml['quota']=$total;
 -                              $xml['free']=$free;
 -                              $xml['used']=$used;
 -                              $xml['relative']=$relative;
 -
 -                              $txt=OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'cloud', '', 1, 0, 0);
 -                              echo($txt);
 -                      }else{
 -                              echo self::generateXml('', 'fail', 300, 'User does not exist');
 -                      }
 -              }else{
 -                      echo self::generateXml('', 'fail', 300, 'You don´t have permission to access this ressource.');
 -              }
 -        }
 -
--        /**
--        * set the quota of a user
--        * @param string $format
--        * @param string $user
--        * @param string $quota
--        * @return string xml/json
--        */
-         private static function quotaSet($format,$user,$quota) {
 -        private static function quotaSet($format, $user, $quota) {
--                $login=OC_OCS::checkpassword();
--                if(OC_Group::inGroup($login, 'admin')) {
--
--                      // todo
--                      // not yet implemented
--                      // add logic here
--                      error_log('OCS call: user:'.$user.' quota:'.$quota);
--
--                        $xml=array();
--                        $txt=OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'cloud', '', 1, 0, 0);
--                        echo($txt);
 -                }else{
 -                        echo self::generateXml('', 'fail', 300, 'You don´t have permission to access this ressource.');
 -                }
 -        }
 -
 -        /**
 -        * get the public key of a user
 -        * @param string $format
 -        * @param string $user
 -        * @return string xml/json
 -        */
 -        private static function publicKeyGet($format, $user) {
 -                $login=OC_OCS::checkpassword();
 -
 -              if(OC_User::userExists($user)) {
 -                      // calculate the disc space
 -                      $txt='this is the public key of '.$user;
 -                      echo($txt);
 -              }else{
 -                      echo self::generateXml('', 'fail', 300, 'User does not exist');
 -              }
 -      }
 -
 -        /**
 -        * get the private key of a user
 -        * @param string $format
 -        * @param string $user
 -        * @return string xml/json
 -        */
 -        private static function privateKeyGet($format, $user) {
 -                $login=OC_OCS::checkpassword();
 -                if(OC_Group::inGroup($login, 'admin') or ($login==$user)) {
 -
 -                        if(OC_User::userExists($user)) {
 -                                // calculate the disc space
 -                                $txt='this is the private key of '.$user;
 -                                echo($txt);
 -                        }else{
 -                                echo self::generateXml('', 'fail', 300, 'User does not exist');
 -                        }
--                }else{
--                        echo self::generateXml('', 'fail', 300, 'You don´t have permission to access this ressource.');
--                }
--        }
 -
--
  }
diff --cc lib/router.php
index 12cd55df4144202a7b4d8169d99d760defb84b0a,8cb8fd4f33b3e68664ba8f228f2ff5228c7388de..27e14c38abf0aef0773017232af51236bb6ee984
@@@ -21,21 -58,15 +58,33 @@@ class OC_Router 
         * loads the api routes
         */
        public function loadRoutes() {
++
 +              // TODO cache
 +              $this->root = $this->getCollection('root');
 +              foreach(OC_APP::getEnabledApps() as $app){
 +                      $file = OC_App::getAppPath($app).'/appinfo/routes.php';
 +                      if(file_exists($file)){
 +                              $this->useCollection($app);
 +                              require_once($file);
 +                              $collection = $this->getCollection($app);
 +                              $this->root->addCollection($collection, '/apps/'.$app);
 +                      }
 +              }
 +              // include ocs routes
 +              require_once(OC::$SERVERROOT.'/ocs/routes.php');
 +              $collection = $this->getCollection('ocs');
 +              $this->root->addCollection($collection, '/ocs');
++
+               foreach($this->getRoutingFiles() as $app => $file) {
+                       $this->useCollection($app);
+                       require_once $file;
+                       $collection = $this->getCollection($app);
+                       $this->root->addCollection($collection, '/apps/'.$app);
+               }
+               $this->useCollection('root');
+               require_once 'settings/routes.php';
+               require_once 'core/routes.php';
++
        }
  
        protected function getCollection($name) {
diff --cc ocs/v1.php
index ac1312afb678cce836d1b1f5da1ccd27faec4ac2,1652b0bedbe223138f1a59ca57ca037626e5c196..af83a56ff147715f7ebd1378ade420ccee4b60f2
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *  
- * You should have received a copy of the GNU Affero General Public 
+ *
+ * You should have received a copy of the GNU Affero General Public
  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
- * 
+ *
  */
  
 -require_once '../lib/base.php';
 -@ob_clean();
 -OC_OCS::handle();
 +require_once('../lib/base.php');
 +use Symfony\Component\Routing\Exception\ResourceNotFoundException;
 +use Symfony\Component\Routing\Exception\MethodNotAllowedException;
 +
 +try {
 +      OC::getRouter()->match('/ocs'.$_SERVER['PATH_INFO']);
 +} catch (ResourceNotFoundException $e) {
 +      OC_OCS::notFound();
 +} catch (MethodNotAllowedException $e) {
 +      OC_Response::setStatus(405);
 +}
 +