From fe7a2124bd547440c8df3f1d3cbe5aaafacfe828 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Sat, 20 Jul 2013 18:25:25 +0300 Subject: [PATCH] Sample parse input --- ajax/otpoll.php | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/ajax/otpoll.php b/ajax/otpoll.php index 85df8110..86a991da 100644 --- a/ajax/otpoll.php +++ b/ajax/otpoll.php @@ -1,4 +1,5 @@ @@ -33,14 +34,11 @@ * @source: http://www.webodf.org/ * @source: http://gitorious.org/webodf/webodf/ */ - // OCP\JSON::checkLoggedIn(); // OCP\JSON::checkAppEnabled('office'); // session_write_close(); -$postBody = file_get_contents('php://input'); - -function bogusSession($i) { +function bogusSession($i){ $bs = array(); $bs["denomination"] = "[$i] bogus session"; $bs["id"] = "$i"; @@ -51,16 +49,23 @@ function bogusSession($i) { return $bs; } +$command = isset($_POST['command']) ? $_POST['command'] : ''; + header('Content-Type: application/json'); -if (preg_match('/^session-list/', $postBody) === 1) { // session-list - $bogusSessionList = array(); - $bogusSessionList["session_list"] = array(bogusSession(0), bogusSession(1)); - print json_encode($bogusSessionList, JSON_PRETTY_PRINT)."\n"; -} else if (preg_match('/^join-session:/', $postBody) === 1) { // join - print "true"; -} else if (preg_match('/^sync-ops:/', $postBody) === 1) { // sync - // completely bogus - print '{"result":"newOps","ops":[],"headSeq":-1}'; -} else { - print "unknown command"; // TODO send HTTP 400 response + +switch ($command){ + case 'session-list': + $bogusSessionList = array(); + $bogusSessionList["session_list"] = array(bogusSession(0), bogusSession(1)); + print json_encode($bogusSessionList, JSON_PRETTY_PRINT) . "\n"; + break; + case 'join-session': + print "true"; + break; + case 'sync-ops': + // completely bogus + print '{"result":"newOps","ops":[],"headSeq":-1}'; + break; + default: + print "unknown command"; // TODO send HTTP 400 response }