Back to index

d-push  2.0
requestprocessor.php
Go to the documentation of this file.
00001 <?php
00002 /***********************************************
00003 * File      :   requestprocessor.php
00004 * Project   :   Z-Push
00005 * Descr     :   This file provides/loads the handlers
00006 *               for the different commands.
00007 *               The request handlers are optimised
00008 *               so that as little as possible
00009 *               data is kept-in-memory, and all
00010 *               output data is directly streamed
00011 *               to the client, while also streaming
00012 *               input data from the client.
00013 *
00014 * Created   :   12.08.2011
00015 *
00016 * Copyright 2007 - 2011 Zarafa Deutschland GmbH
00017 *
00018 * This program is free software: you can redistribute it and/or modify
00019 * it under the terms of the GNU Affero General Public License, version 3,
00020 * as published by the Free Software Foundation with the following additional
00021 * term according to sec. 7:
00022 *
00023 * According to sec. 7 of the GNU Affero General Public License, version 3,
00024 * the terms of the AGPL are supplemented with the following terms:
00025 *
00026 * "Zarafa" is a registered trademark of Zarafa B.V.
00027 * "Z-Push" is a registered trademark of Zarafa Deutschland GmbH
00028 * The licensing of the Program under the AGPL does not imply a trademark license.
00029 * Therefore any rights, title and interest in our trademarks remain entirely with us.
00030 *
00031 * However, if you propagate an unmodified version of the Program you are
00032 * allowed to use the term "Z-Push" to indicate that you distribute the Program.
00033 * Furthermore you may use our trademarks where it is necessary to indicate
00034 * the intended purpose of a product or service provided you use it in accordance
00035 * with honest practices in industrial or commercial matters.
00036 * If you want to propagate modified versions of the Program under the name "Z-Push",
00037 * you may only do so if you have a written permission by Zarafa Deutschland GmbH
00038 * (to acquire a permission please contact Zarafa at trademark@zarafa.com).
00039 *
00040 * This program is distributed in the hope that it will be useful,
00041 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00042 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00043 * GNU Affero General Public License for more details.
00044 *
00045 * You should have received a copy of the GNU Affero General Public License
00046 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00047 *
00048 * Consult LICENSE file for details
00049 ************************************************/
00050 
00051 abstract class RequestProcessor {
00052     static protected $backend;
00053     static protected $deviceManager;
00054     static protected $topCollector;
00055     static protected $decoder;
00056     static protected $encoder;
00057     static protected $userIsAuthenticated;
00058 
00072     static public function Authenticate() {
00073         self::$userIsAuthenticated = false;
00074 
00075         $backend = ZPush::GetBackend();
00076         if($backend->Logon(Request::GetAuthUser(), Request::GetAuthDomain(), Request::GetAuthPassword()) == false)
00077             throw new AuthenticationRequiredException("Access denied. Username or password incorrect");
00078 
00079         // mark this request as "authenticated"
00080         self::$userIsAuthenticated = true;
00081 
00082         // check Auth-User's permissions on GETUser's store
00083         if($backend->Setup(Request::GetGETUser(), true) == false)
00084             throw new AuthenticationRequiredException(sprintf("Not enough privileges of '%s' to setup for user '%s': Permission denied", Request::GetAuthUser(), Request::GetGETUser()));
00085     }
00086 
00093     static public function isUserAuthenticated() {
00094         if (!isset(self::$userIsAuthenticated))
00095             return false;
00096         return self::$userIsAuthenticated;
00097     }
00098 
00105     static public function Initialize() {
00106         self::$backend = ZPush::GetBackend();
00107         self::$deviceManager = ZPush::GetDeviceManager();
00108         self::$topCollector = ZPush::GetTopCollector();
00109 
00110         if (!ZPush::CommandNeedsPlainInput(Request::GetCommandCode()))
00111             self::$decoder = new WBXMLDecoder(Request::GetInputStream());
00112 
00113         self::$encoder = new WBXMLEncoder(Request::GetOutputStream());
00114     }
00115 
00122     static public function HandleRequest() {
00123         $handler = ZPush::GetRequestHandlerForCommand(Request::GetCommandCode());
00124 
00125         // TODO handle WBXML exceptions here and print stack
00126         return $handler->Handle(Request::GetCommandCode());
00127     }
00128 
00137     abstract public function Handle($commandCode);
00138 }
00139 ?>