/usr/share/php/SOAP/Transport/TCP.php is in php-soap 0.13.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | <?php
/**
* This file contains the code for a TCP transport layer.
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 2.02 of the PHP license,
* that is bundled with this package in the file LICENSE, and is available at
* through the world-wide-web at http://www.php.net/license/2_02.txt. If you
* did not receive a copy of the PHP license and are unable to obtain it
* through the world-wide-web, please send a note to license@php.net so we can
* mail you a copy immediately.
*
* @category Web Services
* @package SOAP
* @author Shane Hanna <iordy_at_iordy_dot_com>
* @author Jan Schneider <jan@horde.org>
* @copyright 2003-2006 The PHP Group
* @license http://www.php.net/license/2_02.txt PHP License 2.02
* @link http://pear.php.net/package/SOAP
*/
require_once 'SOAP/Transport.php';
/**
* TCP transport for SOAP.
*
* @todo use Net_Socket; implement some security scheme; implement support
* for attachments
* @access public
* @package SOAP
* @author Shane Hanna <iordy_at_iordy_dot_com>
* @author Jan Schneider <jan@horde.org>
*/
class SOAP_Transport_TCP extends SOAP_Transport
{
/**
* Socket.
*/
var $socket = null;
/**
* Constructor.
*
* @param string $url HTTP url to SOAP endpoint.
*
* @access public
*/
function SOAP_Transport_TCP($url, $encoding = SOAP_DEFAULT_ENCODING)
{
parent::SOAP_Base_Object('TCP');
$this->urlparts = @parse_url($url);
$this->url = $url;
$this->encoding = $encoding;
}
function _socket_ping()
{
// XXX how do we restart after socket_shutdown?
//if (!$this->socket) {
// Create socket resource.
$this->socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($this->socket < 0) {
return 0;
}
// Connect.
$result = socket_connect($this->socket, $this->urlparts['host'],
$this->urlparts['port']);
if ($result < 0) {
return 0;
}
//}
return 1;
}
/**
* Sends and receives SOAP data.
*
* @access public
*
* @param string Outgoing SOAP data.
* @param array Options.
*
* @return string|SOAP_Fault
*/
function send($msg, $options = array())
{
$this->fault = null;
$this->incoming_payload = '';
$this->outgoing_payload = $msg;
if (!$this->_validateUrl()) {
return $this->fault;
}
// Check for TCP scheme.
if (strcasecmp($this->urlparts['scheme'], 'TCP') == 0) {
// Check connection.
if (!$this->_socket_ping()) {
return $this->_raiseSoapFault('Error connecting to ' . $this->url . '; reason: ' . socket_strerror(socket_last_error($this->socket)));
}
// Write to the socket.
if (!@socket_write($this->socket, $this->outgoing_payload,
strlen($this->outgoing_payload))) {
return $this->_raiseSoapFault('Error sending data to ' . $this->url . '; reason: ' . socket_strerror(socket_last_error($this->socket)));
}
// Shutdown writing.
if(!socket_shutdown($this->socket, 1)) {
return $this->_raiseSoapFault('Cannot change socket mode to read.');
}
// Read everything we can.
while ($buf = @socket_read($this->socket, 1024, PHP_BINARY_READ)) {
$this->incoming_payload .= $buf;
}
// Return payload or die.
if ($this->incoming_payload) {
return $this->incoming_payload;
}
return $this->_raiseSoapFault('Error reveiving data from ' . $this->url);
}
return $this->_raiseSoapFault('Invalid url scheme ' . $this->url);
}
/**
* Validates the url data passed to the constructor.
*
* @return boolean
* @access private
*/
function _validateUrl()
{
if (!is_array($this->urlparts) ) {
$this->_raiseSoapFault("Unable to parse URL $this->url");
return false;
}
if (!isset($this->urlparts['host'])) {
$this->_raiseSoapFault("No host in URL $this->url");
return false;
}
if (!isset($this->urlparts['path']) || !$this->urlparts['path']) {
$this->urlparts['path'] = '/';
}
return true;
}
}
|