From 1460f9dfbd97a31a1ab7e247c9576984ecb23bba Mon Sep 17 00:00:00 2001 From: "yucheng.hu" Date: Wed, 30 Jan 2013 21:01:52 -0500 Subject: [PATCH] =?UTF-8?q?webservice=20=E9=85=8D=E7=BD=AE=20PHP=20?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yucheng.hu --- webservice.php | 128 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 webservice.php diff --git a/webservice.php b/webservice.php new file mode 100644 index 0000000..8348717 --- /dev/null +++ b/webservice.php @@ -0,0 +1,128 @@ +success = false; + $state->error = $error; + unset($state->result); + $output = $operationManager->encode($state); + echo $output; + + } + + function writeOutput($operationManager, $data){ + + setResponseHeaders(); + $state = new State(); + $state->success = true; + $state->result = $data; + unset($state->error); + $output = $operationManager->encode($state); + echo $output; + + } + + $operation = vtws_getParameter($_REQUEST, "operation"); + $operation = strtolower($operation); + $format = vtws_getParameter($_REQUEST, "format","json"); + $sessionId = vtws_getParameter($_REQUEST,"sessionName"); + + $sessionManager = new SessionManager(); + $operationManager = new OperationManager($adb,$operation,$format,$sessionManager); + + try{ + if(!$sessionId || strcasecmp($sessionId,"null")===0){ + $sessionId = null; + } + + $input = $operationManager->getOperationInput(); + $adoptSession = false; + if(strcasecmp($operation,"extendsession")===0){ + if(isset($input['operation'])){ + // Workaround fix for PHP 5.3.x: $_REQUEST doesn't have PHPSESSID + if(isset($_REQUEST['PHPSESSID'])) { + $sessionId = vtws_getParameter($_REQUEST,"PHPSESSID"); + } else { + // NOTE: Need to evaluate for possible security issues + $sessionId = vtws_getParameter($_COOKIE,'PHPSESSID'); + } + // END + $adoptSession = true; + }else{ + writeErrorOutput($operationManager,new WebServiceException(WebServiceErrorCode::$AUTHREQUIRED,"Authencation required")); + return; + } + } + $sid = $sessionManager->startSession($sessionId,$adoptSession); + + if(!$sessionId && !$operationManager->isPreLoginOperation()){ + writeErrorOutput($operationManager,new WebServiceException(WebServiceErrorCode::$AUTHREQUIRED,"Authencation required")); + return; + } + + if(!$sid){ + writeErrorOutput($operationManager, $sessionManager->getError()); + return; + } + + $userid = $sessionManager->get("authenticatedUserId"); + + if($userid){ + + $seed_user = new Users(); + $current_user = $seed_user->retrieveCurrentUserInfoFromFile($userid); + + }else{ + $current_user = null; + } + + $operationInput = $operationManager->sanitizeOperation($input); + $includes = $operationManager->getOperationIncludes(); + + foreach($includes as $ind=>$path){ + require_once($path); + } + $rawOutput = $operationManager->runOperation($operationInput,$current_user); + writeOutput($operationManager, $rawOutput); + }catch(WebServiceException $e){ + writeErrorOutput($operationManager,$e); + }catch(Exception $e){ + writeErrorOutput($operationManager, + new WebServiceException(WebServiceErrorCode::$INTERNALERROR,"Unknown Error while processing request")); + } +?>