Sample parse input

This commit is contained in:
Victor Dubiniuk 2013-07-20 18:25:25 +03:00 committed by Tobias Hintze
parent 76ed6452d9
commit fe7a2124bd

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @license * @license
* Copyright (C) 2013 KO GmbH <copyright@kogmbh.com> * Copyright (C) 2013 KO GmbH <copyright@kogmbh.com>
@ -33,14 +34,11 @@
* @source: http://www.webodf.org/ * @source: http://www.webodf.org/
* @source: http://gitorious.org/webodf/webodf/ * @source: http://gitorious.org/webodf/webodf/
*/ */
// OCP\JSON::checkLoggedIn(); // OCP\JSON::checkLoggedIn();
// OCP\JSON::checkAppEnabled('office'); // OCP\JSON::checkAppEnabled('office');
// session_write_close(); // session_write_close();
$postBody = file_get_contents('php://input'); function bogusSession($i){
function bogusSession($i) {
$bs = array(); $bs = array();
$bs["denomination"] = "[$i] bogus session"; $bs["denomination"] = "[$i] bogus session";
$bs["id"] = "$i"; $bs["id"] = "$i";
@ -51,16 +49,23 @@ function bogusSession($i) {
return $bs; return $bs;
} }
$command = isset($_POST['command']) ? $_POST['command'] : '';
header('Content-Type: application/json'); header('Content-Type: application/json');
if (preg_match('/^session-list/', $postBody) === 1) { // session-list
$bogusSessionList = array(); switch ($command){
$bogusSessionList["session_list"] = array(bogusSession(0), bogusSession(1)); case 'session-list':
print json_encode($bogusSessionList, JSON_PRETTY_PRINT)."\n"; $bogusSessionList = array();
} else if (preg_match('/^join-session:/', $postBody) === 1) { // join $bogusSessionList["session_list"] = array(bogusSession(0), bogusSession(1));
print "true"; print json_encode($bogusSessionList, JSON_PRETTY_PRINT) . "\n";
} else if (preg_match('/^sync-ops:/', $postBody) === 1) { // sync break;
// completely bogus case 'join-session':
print '{"result":"newOps","ops":[],"headSeq":-1}'; print "true";
} else { break;
print "unknown command"; // TODO send HTTP 400 response case 'sync-ops':
// completely bogus
print '{"result":"newOps","ops":[],"headSeq":-1}';
break;
default:
print "unknown command"; // TODO send HTTP 400 response
} }