| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * This file contains the code for the TCP SOAP server. |
|---|
| 4 | * |
|---|
| 5 | * PHP versions 4 and 5 |
|---|
| 6 | * |
|---|
| 7 | * LICENSE: This source file is subject to version 2.02 of the PHP license, |
|---|
| 8 | * that is bundled with this package in the file LICENSE, and is available at |
|---|
| 9 | * through the world-wide-web at http://www.php.net/license/2_02.txt. If you |
|---|
| 10 | * did not receive a copy of the PHP license and are unable to obtain it |
|---|
| 11 | * through the world-wide-web, please send a note to [email protected] so we can |
|---|
| 12 | * mail you a copy immediately. |
|---|
| 13 | * |
|---|
| 14 | * @category Web Services |
|---|
| 15 | * @package SOAP |
|---|
| 16 | * @author Shane Caraveo <[email protected]> Port to PEAR and more |
|---|
| 17 | * @copyright 2003-2005 The PHP Group |
|---|
| 18 | * @license http://www.php.net/license/2_02.txt PHP License 2.02 |
|---|
| 19 | * @link http://pear.php.net/package/SOAP |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | require_once 'SOAP/Server.php'; |
|---|
| 23 | |
|---|
| 24 | require_once 'SOAP/Server/TCP/Handler.php'; |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | /** |
|---|
| 28 | * SOAP Server Class that implements a TCP SOAP Server. |
|---|
| 29 | * http://www.pocketsoap.com/specs/smtpbinding/ |
|---|
| 30 | * |
|---|
| 31 | * This class overrides the default HTTP server, providing the ability to |
|---|
| 32 | * accept socket connections and execute SOAP calls. |
|---|
| 33 | * |
|---|
| 34 | * TODO: |
|---|
| 35 | * use Net_Socket |
|---|
| 36 | * implement some security scheme |
|---|
| 37 | * implement support for attachments |
|---|
| 38 | * |
|---|
| 39 | * @access public |
|---|
| 40 | * @package SOAP |
|---|
| 41 | * @author Shane Caraveo <[email protected]> |
|---|
| 42 | */ |
|---|
| 43 | class SOAP_Server_TCP extends SOAP_Server { |
|---|
| 44 | |
|---|
| 45 | var $headers = array(); |
|---|
| 46 | var $localaddr; |
|---|
| 47 | var $port; |
|---|
| 48 | var $type; |
|---|
| 49 | |
|---|
| 50 | function SOAP_Server_TCP($localaddr = '127.0.0.1', $port = 10000, |
|---|
| 51 | $type = 'sequential') |
|---|
| 52 | { |
|---|
| 53 | parent::SOAP_Server(); |
|---|
| 54 | $this->localaddr = $localaddr; |
|---|
| 55 | $this->port = $port; |
|---|
| 56 | $this->type = $type; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | function run($idleTimeout = null) |
|---|
| 60 | { |
|---|
| 61 | $server = &Net_Server::create($this->type, $this->localaddr, |
|---|
| 62 | $this->port); |
|---|
| 63 | if (PEAR::isError($server)) { |
|---|
| 64 | echo $server->getMessage()."\n"; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | $handler = &new SOAP_Server_TCP_Handler; |
|---|
| 68 | $handler->setSOAPServer($this); |
|---|
| 69 | |
|---|
| 70 | // hand over the object that handles server events |
|---|
| 71 | $server->setCallbackObject($handler); |
|---|
| 72 | $server->readEndCharacter = '</SOAP-ENV:Envelope>'; |
|---|
| 73 | $server->setIdleTimeout($idleTimeout); |
|---|
| 74 | |
|---|
| 75 | // start the server |
|---|
| 76 | $server->start(); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | function service(&$data) |
|---|
| 80 | { |
|---|
| 81 | /* TODO: we need to handle attachments somehow. */ |
|---|
| 82 | $response = $this->parseRequest($data); |
|---|
| 83 | if ($this->fault) { |
|---|
| 84 | $response = $this->fault->message($this->response_encoding); |
|---|
| 85 | } |
|---|
| 86 | return $response; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | function onStart() |
|---|
| 90 | { |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | function onIdle() |
|---|
| 94 | { |
|---|
| 95 | } |
|---|
| 96 | } |
|---|