/** * Sends an RPC request to the server and returns the result. * * @param string $request The raw request string. * * @return string The XML encoded response from the server. */ function getResponse($request) { $backendparms = array('debug_dir' => Horde::getTempDir() . '/sync', 'debug_files' => true, 'log_level' => 'DEBUG'); /* Create the backend. */ $GLOBALS['backend'] = Horde_SyncMl_Backend::factory('Horde', $backendparms); /* Handle request. */ $h = new Horde_SyncMl_ContentHandler(); $response = $h->process($request, $this->getResponseContentType(), Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/rpc.php', true, -1)); /* Close the backend. */ $GLOBALS['backend']->close(); return $response; }
$this->state->authenticated = true; } public function addEntry($databaseURI, $content, $contentType, $cuid) { echo "Adding {$cuid} of {$contentType} to {$databaseURI}:\n{$content}\n"; } public function replaceEntry($databaseURI, $content, $contentType, $cuid) { echo "Replacing {$cuid} of {$contentType} in {$databaseURI}:\n{$content}\n"; } public function deleteEntry($databaseURI, $cuid) { echo "Deleting {$cuid} from {$databaseURI}\n"; } } if (!isset($argc)) { die("argv/argc has to be enabled.\n"); } if ($argc != 2) { die('Usage: ' . basename($argv[0]) . " syncml_client_nn.[wb]xml\n"); } $backend = new Backend(array()); $sync = new Horde_SyncMl_ContentHandler(); $sync->debug = true; $sync->process(file_get_contents($argv[1]), strpos($argv[1], '.wbxml') ? 'application/vnd.syncml+wbxml' : 'application/vnd.syncml'); $output = $sync->getOutput(); if (function_exists('tidy_repair_string')) { $output = tidy_repair_string($output, array('indent' => true, 'input-xml' => true, 'output-xml' => true)); } echo $output, "\n"; @session_destroy();
/** * Simulates a call to the SyncML server by sending data to the server. * Returns the result received from the server. */ function getResponse($data) { if (!empty($GLOBALS['url'])) { /* Call externally using curl. */ $tmpfile = tempnam('tmp', 'syncmltest'); $fh = fopen($tmpfile, 'w'); fwrite($fh, $data); fclose($fh); $output = shell_exec(sprintf('curl -s -H "Content-Type: application/vnd.syncml+xml" --data-binary @%s "%s"', $tmpfile, $GLOBALS['url'])); unlink($tmpfile); return $output; } /* Create and setup the test backend */ $GLOBALS['backend'] = Horde_SyncMl_Backend::factory($GLOBALS['syncml_backend_driver'], $GLOBALS['syncml_backend_parms']); $h = new Horde_SyncMl_ContentHandler(); $response = $h->process($data, 'application/vnd.syncml+xml'); $GLOBALS['backend']->close(); return $response; }