mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Maj: NuSOAP 0.7.3
This commit is contained in:
parent
c8db07011a
commit
9fc889c86a
|
|
@ -17,8 +17,9 @@ FPDF 1.53 Public domain Yes PDF gene
|
|||
FPDF_TPL 1.1.2 Apache Software License 2.0 No GPL3 only PDF templates management
|
||||
FPDI 1.2.1 Apache Software License 2.0 No GPL3 only PDF templates management
|
||||
FPDI_Protection 1.0.2 Apache Software License 2.0 No GPL3 only PDF encryption (8 files)
|
||||
GeoIP x.x Yes GeoIP Maxmind conversion
|
||||
MagPieRss 0.72 GPL 2.0 Yes Load RSS
|
||||
NuSoap 0.6.5 LGPL 2.1 Yes Interfaces with third tools
|
||||
NuSoap 0.7.3 LGPL 2.1 Yes Interfaces with third tools
|
||||
PHP_WriteExcel 0.3.0 LGPL 2.1 Yes Excel files generation
|
||||
PHP_ExcelReader 2.21 MIT License Yes Parse and retrieve information from XLS files
|
||||
Prototype 1.6.0.3 MIT License Yes Ajax library
|
||||
|
|
@ -28,7 +29,6 @@ SimpleMail 1.2 GPL Yes SMTP lib
|
|||
Smarty 2.6.26 LGPL 2.1 Yes Templates engine used by some pages
|
||||
SMTPs 1.15 GPL Yes SMTPS library
|
||||
VCard 2.0 GPL 2.0 Yes Fonctions vcard
|
||||
GeoIP x.x Yes GeoIP Maxmind conversion
|
||||
|
||||
For licenses compatibility informations:
|
||||
http://www.fsf.org/licensing/licenses/index_html
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -1,86 +1,90 @@
|
|||
<?php
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Contains information for a SOAP fault.
|
||||
* Mainly used for returning faults from deployed functions
|
||||
* in a server instance.
|
||||
* @author Dietrich Ayala <dietrich@ganx4.com>
|
||||
* @version $Id$
|
||||
* @access public
|
||||
*/
|
||||
class soap_fault extends nusoap_base {
|
||||
/**
|
||||
* The fault code (client|server)
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $faultcode;
|
||||
/**
|
||||
* The fault actor
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $faultactor;
|
||||
/**
|
||||
* The fault string, a description of the fault
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $faultstring;
|
||||
/**
|
||||
* The fault detail, typically a string or array of string
|
||||
* @var mixed
|
||||
* @access private
|
||||
*/
|
||||
var $faultdetail;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param string $faultcode (client | server)
|
||||
* @param string $faultactor only used when msg routed between multiple actors
|
||||
* @param string $faultstring human readable error message
|
||||
* @param mixed $faultdetail detail, typically a string or array of string
|
||||
*/
|
||||
function soap_fault($faultcode,$faultactor='',$faultstring='',$faultdetail=''){
|
||||
parent::nusoap_base();
|
||||
$this->faultcode = $faultcode;
|
||||
$this->faultactor = $faultactor;
|
||||
$this->faultstring = $faultstring;
|
||||
$this->faultdetail = $faultdetail;
|
||||
}
|
||||
|
||||
/**
|
||||
* serialize a fault
|
||||
*
|
||||
* @return string The serialization of the fault instance.
|
||||
* @access public
|
||||
*/
|
||||
function serialize(){
|
||||
$ns_string = '';
|
||||
foreach($this->namespaces as $k => $v){
|
||||
$ns_string .= "\n xmlns:$k=\"$v\"";
|
||||
}
|
||||
$return_msg =
|
||||
'<?xml version="1.0" encoding="'.$this->soap_defencoding.'"?>'.
|
||||
'<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"'.$ns_string.">\n".
|
||||
'<SOAP-ENV:Body>'.
|
||||
'<SOAP-ENV:Fault>'.
|
||||
$this->serialize_val($this->faultcode, 'faultcode').
|
||||
$this->serialize_val($this->faultactor, 'faultactor').
|
||||
$this->serialize_val($this->faultstring, 'faultstring').
|
||||
$this->serialize_val($this->faultdetail, 'detail').
|
||||
'</SOAP-ENV:Fault>'.
|
||||
'</SOAP-ENV:Body>'.
|
||||
'</SOAP-ENV:Envelope>';
|
||||
return $return_msg;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Contains information for a SOAP fault.
|
||||
* Mainly used for returning faults from deployed functions
|
||||
* in a server instance.
|
||||
* @author Dietrich Ayala <dietrich@ganx4.com>
|
||||
* @version $Id$
|
||||
* @access public
|
||||
*/
|
||||
class nusoap_fault extends nusoap_base {
|
||||
/**
|
||||
* The fault code (client|server)
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $faultcode;
|
||||
/**
|
||||
* The fault actor
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $faultactor;
|
||||
/**
|
||||
* The fault string, a description of the fault
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $faultstring;
|
||||
/**
|
||||
* The fault detail, typically a string or array of string
|
||||
* @var mixed
|
||||
* @access private
|
||||
*/
|
||||
var $faultdetail;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param string $faultcode (SOAP-ENV:Client | SOAP-ENV:Server)
|
||||
* @param string $faultactor only used when msg routed between multiple actors
|
||||
* @param string $faultstring human readable error message
|
||||
* @param mixed $faultdetail detail, typically a string or array of string
|
||||
*/
|
||||
function nusoap_fault($faultcode,$faultactor='',$faultstring='',$faultdetail=''){
|
||||
parent::nusoap_base();
|
||||
$this->faultcode = $faultcode;
|
||||
$this->faultactor = $faultactor;
|
||||
$this->faultstring = $faultstring;
|
||||
$this->faultdetail = $faultdetail;
|
||||
}
|
||||
|
||||
/**
|
||||
* serialize a fault
|
||||
*
|
||||
* @return string The serialization of the fault instance.
|
||||
* @access public
|
||||
*/
|
||||
function serialize(){
|
||||
$ns_string = '';
|
||||
foreach($this->namespaces as $k => $v){
|
||||
$ns_string .= "\n xmlns:$k=\"$v\"";
|
||||
}
|
||||
$return_msg =
|
||||
'<?xml version="1.0" encoding="'.$this->soap_defencoding.'"?>'.
|
||||
'<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"'.$ns_string.">\n".
|
||||
'<SOAP-ENV:Body>'.
|
||||
'<SOAP-ENV:Fault>'.
|
||||
$this->serialize_val($this->faultcode, 'faultcode').
|
||||
$this->serialize_val($this->faultactor, 'faultactor').
|
||||
$this->serialize_val($this->faultstring, 'faultstring').
|
||||
$this->serialize_val($this->faultdetail, 'detail').
|
||||
'</SOAP-ENV:Fault>'.
|
||||
'</SOAP-ENV:Body>'.
|
||||
'</SOAP-ENV:Envelope>';
|
||||
return $return_msg;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Backward compatibility
|
||||
*/
|
||||
class soap_fault extends nusoap_fault {
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -1,107 +1,107 @@
|
|||
<?php
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* For creating serializable abstractions of native PHP types. This class
|
||||
* allows element name/namespace, XSD type, and XML attributes to be
|
||||
* associated with a value. This is extremely useful when WSDL is not
|
||||
* used, but is also useful when WSDL is used with polymorphic types, including
|
||||
* xsd:anyType and user-defined types.
|
||||
*
|
||||
* @author Dietrich Ayala <dietrich@ganx4.com>
|
||||
* @version $Id$
|
||||
* @access public
|
||||
*/
|
||||
class soapval extends nusoap_base {
|
||||
/**
|
||||
* The XML element name
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $name;
|
||||
/**
|
||||
* The XML type name (string or false)
|
||||
*
|
||||
* @var mixed
|
||||
* @access private
|
||||
*/
|
||||
var $type;
|
||||
/**
|
||||
* The PHP value
|
||||
*
|
||||
* @var mixed
|
||||
* @access private
|
||||
*/
|
||||
var $value;
|
||||
/**
|
||||
* The XML element namespace (string or false)
|
||||
*
|
||||
* @var mixed
|
||||
* @access private
|
||||
*/
|
||||
var $element_ns;
|
||||
/**
|
||||
* The XML type namespace (string or false)
|
||||
*
|
||||
* @var mixed
|
||||
* @access private
|
||||
*/
|
||||
var $type_ns;
|
||||
/**
|
||||
* The XML element attributes (array or false)
|
||||
*
|
||||
* @var mixed
|
||||
* @access private
|
||||
*/
|
||||
var $attributes;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param string $name optional name
|
||||
* @param mixed $type optional type name
|
||||
* @param mixed $value optional value
|
||||
* @param mixed $element_ns optional namespace of value
|
||||
* @param mixed $type_ns optional namespace of type
|
||||
* @param mixed $attributes associative array of attributes to add to element serialization
|
||||
* @access public
|
||||
*/
|
||||
function soapval($name='soapval',$type=false,$value=-1,$element_ns=false,$type_ns=false,$attributes=false) {
|
||||
parent::nusoap_base();
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
$this->value = $value;
|
||||
$this->element_ns = $element_ns;
|
||||
$this->type_ns = $type_ns;
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* return serialized value
|
||||
*
|
||||
* @param string $use The WSDL use value (encoded|literal)
|
||||
* @return string XML data
|
||||
* @access public
|
||||
*/
|
||||
function serialize($use='encoded') {
|
||||
return $this->serialize_val($this->value,$this->name,$this->type,$this->element_ns,$this->type_ns,$this->attributes,$use);
|
||||
}
|
||||
|
||||
/**
|
||||
* decodes a soapval object into a PHP native type
|
||||
*
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
function decode(){
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* For creating serializable abstractions of native PHP types. This class
|
||||
* allows element name/namespace, XSD type, and XML attributes to be
|
||||
* associated with a value. This is extremely useful when WSDL is not
|
||||
* used, but is also useful when WSDL is used with polymorphic types, including
|
||||
* xsd:anyType and user-defined types.
|
||||
*
|
||||
* @author Dietrich Ayala <dietrich@ganx4.com>
|
||||
* @version $Id$
|
||||
* @access public
|
||||
*/
|
||||
class soapval extends nusoap_base {
|
||||
/**
|
||||
* The XML element name
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $name;
|
||||
/**
|
||||
* The XML type name (string or false)
|
||||
*
|
||||
* @var mixed
|
||||
* @access private
|
||||
*/
|
||||
var $type;
|
||||
/**
|
||||
* The PHP value
|
||||
*
|
||||
* @var mixed
|
||||
* @access private
|
||||
*/
|
||||
var $value;
|
||||
/**
|
||||
* The XML element namespace (string or false)
|
||||
*
|
||||
* @var mixed
|
||||
* @access private
|
||||
*/
|
||||
var $element_ns;
|
||||
/**
|
||||
* The XML type namespace (string or false)
|
||||
*
|
||||
* @var mixed
|
||||
* @access private
|
||||
*/
|
||||
var $type_ns;
|
||||
/**
|
||||
* The XML element attributes (array or false)
|
||||
*
|
||||
* @var mixed
|
||||
* @access private
|
||||
*/
|
||||
var $attributes;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param string $name optional name
|
||||
* @param mixed $type optional type name
|
||||
* @param mixed $value optional value
|
||||
* @param mixed $element_ns optional namespace of value
|
||||
* @param mixed $type_ns optional namespace of type
|
||||
* @param mixed $attributes associative array of attributes to add to element serialization
|
||||
* @access public
|
||||
*/
|
||||
function soapval($name='soapval',$type=false,$value=-1,$element_ns=false,$type_ns=false,$attributes=false) {
|
||||
parent::nusoap_base();
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
$this->value = $value;
|
||||
$this->element_ns = $element_ns;
|
||||
$this->type_ns = $type_ns;
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* return serialized value
|
||||
*
|
||||
* @param string $use The WSDL use value (encoded|literal)
|
||||
* @return string XML data
|
||||
* @access public
|
||||
*/
|
||||
function serialize($use='encoded') {
|
||||
return $this->serialize_val($this->value, $this->name, $this->type, $this->element_ns, $this->type_ns, $this->attributes, $use, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* decodes a soapval object into a PHP native type
|
||||
*
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
function decode(){
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -1,184 +1,209 @@
|
|||
<?php
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* caches instances of the wsdl class
|
||||
*
|
||||
* @author Scott Nichol <snichol@computer.org>
|
||||
* @author Ingo Fischer <ingo@apollon.de>
|
||||
* @version $Id$
|
||||
* @access public
|
||||
*/
|
||||
class wsdlcache {
|
||||
/**
|
||||
* @var resource
|
||||
* @access private
|
||||
*/
|
||||
var $fplock;
|
||||
/**
|
||||
* @var integer
|
||||
* @access private
|
||||
*/
|
||||
var $cache_lifetime;
|
||||
/**
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $cache_dir;
|
||||
/**
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $debug_str = '';
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param string $cache_dir directory for cache-files
|
||||
* @param integer $cache_lifetime lifetime for caching-files in seconds or 0 for unlimited
|
||||
* @access public
|
||||
*/
|
||||
function wsdlcache($cache_dir='.', $cache_lifetime=0) {
|
||||
$this->fplock = array();
|
||||
$this->cache_dir = $cache_dir != '' ? $cache_dir : '.';
|
||||
$this->cache_lifetime = $cache_lifetime;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates the filename used to cache a wsdl instance
|
||||
*
|
||||
* @param string $wsdl The URL of the wsdl instance
|
||||
* @return string The filename used to cache the instance
|
||||
* @access private
|
||||
*/
|
||||
function createFilename($wsdl) {
|
||||
return $this->cache_dir.'/wsdlcache-' . md5($wsdl);
|
||||
}
|
||||
|
||||
/**
|
||||
* adds debug data to the class level debug string
|
||||
*
|
||||
* @param string $string debug data
|
||||
* @access private
|
||||
*/
|
||||
function debug($string){
|
||||
$this->debug_str .= get_class($this).": $string\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* gets a wsdl instance from the cache
|
||||
*
|
||||
* @param string $wsdl The URL of the wsdl instance
|
||||
* @return object wsdl The cached wsdl instance, null if the instance is not in the cache
|
||||
* @access public
|
||||
*/
|
||||
function get($wsdl) {
|
||||
$filename = $this->createFilename($wsdl);
|
||||
if ($this->obtainMutex($filename, "r")) {
|
||||
// check for expired WSDL that must be removed from the cache
|
||||
if ($this->cache_lifetime > 0) {
|
||||
if (file_exists($filename) && (time() - filemtime($filename) > $this->cache_lifetime)) {
|
||||
unlink($filename);
|
||||
$this->debug("Expired $wsdl ($filename) from cache");
|
||||
$this->releaseMutex($filename);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// see what there is to return
|
||||
$fp = @fopen($filename, "r");
|
||||
if ($fp) {
|
||||
$s = implode("", @file($filename));
|
||||
fclose($fp);
|
||||
$this->debug("Got $wsdl ($filename) from cache");
|
||||
} else {
|
||||
$s = null;
|
||||
$this->debug("$wsdl ($filename) not in cache");
|
||||
}
|
||||
$this->releaseMutex($filename);
|
||||
return (!is_null($s)) ? unserialize($s) : null;
|
||||
} else {
|
||||
$this->debug("Unable to obtain mutex for $filename in get");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* obtains the local mutex
|
||||
*
|
||||
* @param string $filename The Filename of the Cache to lock
|
||||
* @param string $mode The open-mode ("r" or "w") or the file - affects lock-mode
|
||||
* @return boolean Lock successfully obtained ?!
|
||||
* @access private
|
||||
*/
|
||||
function obtainMutex($filename, $mode) {
|
||||
if (isset($this->fplock[md5($filename)])) {
|
||||
$this->debug("Lock for $filename already exists");
|
||||
return false;
|
||||
}
|
||||
$this->fplock[md5($filename)] = fopen($filename.".lock", "w");
|
||||
if ($mode == "r") {
|
||||
return flock($this->fplock[md5($filename)], LOCK_SH);
|
||||
} else {
|
||||
return flock($this->fplock[md5($filename)], LOCK_EX);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* adds a wsdl instance to the cache
|
||||
*
|
||||
* @param object wsdl $wsdl_instance The wsdl instance to add
|
||||
* @return boolean WSDL successfully cached
|
||||
* @access public
|
||||
*/
|
||||
function put($wsdl_instance) {
|
||||
$filename = $this->createFilename($wsdl_instance->wsdl);
|
||||
$s = serialize($wsdl_instance);
|
||||
if ($this->obtainMutex($filename, "w")) {
|
||||
$fp = fopen($filename, "w");
|
||||
fputs($fp, $s);
|
||||
fclose($fp);
|
||||
$this->debug("Put $wsdl_instance->wsdl ($filename) in cache");
|
||||
$this->releaseMutex($filename);
|
||||
return true;
|
||||
} else {
|
||||
$this->debug("Unable to obtain mutex for $filename in put");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* releases the local mutex
|
||||
*
|
||||
* @param string $filename The Filename of the Cache to lock
|
||||
* @return boolean Lock successfully released
|
||||
* @access private
|
||||
*/
|
||||
function releaseMutex($filename) {
|
||||
$ret = flock($this->fplock[md5($filename)], LOCK_UN);
|
||||
fclose($this->fplock[md5($filename)]);
|
||||
unset($this->fplock[md5($filename)]);
|
||||
if (! $ret) {
|
||||
$this->debug("Not able to release lock for $filename");
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* removes a wsdl instance from the cache
|
||||
*
|
||||
* @param string $wsdl The URL of the wsdl instance
|
||||
* @return boolean Whether there was an instance to remove
|
||||
* @access public
|
||||
*/
|
||||
function remove($wsdl) {
|
||||
$filename = $this->createFilename($wsdl);
|
||||
// ignore errors obtaining mutex
|
||||
$this->obtainMutex($filename, "w");
|
||||
$ret = unlink($filename);
|
||||
$this->debug("Removed ($ret) $wsdl ($filename) from cache");
|
||||
$this->releaseMutex($filename);
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
/*
|
||||
The NuSOAP project home is:
|
||||
http://sourceforge.net/projects/nusoap/
|
||||
|
||||
The primary support for NuSOAP is the mailing list:
|
||||
nusoap-general@lists.sourceforge.net
|
||||
*/
|
||||
|
||||
/**
|
||||
* caches instances of the wsdl class
|
||||
*
|
||||
* @author Scott Nichol <snichol@users.sourceforge.net>
|
||||
* @author Ingo Fischer <ingo@apollon.de>
|
||||
* @version $Id$
|
||||
* @access public
|
||||
*/
|
||||
class nusoap_wsdlcache {
|
||||
/**
|
||||
* @var resource
|
||||
* @access private
|
||||
*/
|
||||
var $fplock;
|
||||
/**
|
||||
* @var integer
|
||||
* @access private
|
||||
*/
|
||||
var $cache_lifetime;
|
||||
/**
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $cache_dir;
|
||||
/**
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $debug_str = '';
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param string $cache_dir directory for cache-files
|
||||
* @param integer $cache_lifetime lifetime for caching-files in seconds or 0 for unlimited
|
||||
* @access public
|
||||
*/
|
||||
function nusoap_wsdlcache($cache_dir='.', $cache_lifetime=0) {
|
||||
$this->fplock = array();
|
||||
$this->cache_dir = $cache_dir != '' ? $cache_dir : '.';
|
||||
$this->cache_lifetime = $cache_lifetime;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates the filename used to cache a wsdl instance
|
||||
*
|
||||
* @param string $wsdl The URL of the wsdl instance
|
||||
* @return string The filename used to cache the instance
|
||||
* @access private
|
||||
*/
|
||||
function createFilename($wsdl) {
|
||||
return $this->cache_dir.'/wsdlcache-' . md5($wsdl);
|
||||
}
|
||||
|
||||
/**
|
||||
* adds debug data to the class level debug string
|
||||
*
|
||||
* @param string $string debug data
|
||||
* @access private
|
||||
*/
|
||||
function debug($string){
|
||||
$this->debug_str .= get_class($this).": $string\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* gets a wsdl instance from the cache
|
||||
*
|
||||
* @param string $wsdl The URL of the wsdl instance
|
||||
* @return object wsdl The cached wsdl instance, null if the instance is not in the cache
|
||||
* @access public
|
||||
*/
|
||||
function get($wsdl) {
|
||||
$filename = $this->createFilename($wsdl);
|
||||
if ($this->obtainMutex($filename, "r")) {
|
||||
// check for expired WSDL that must be removed from the cache
|
||||
if ($this->cache_lifetime > 0) {
|
||||
if (file_exists($filename) && (time() - filemtime($filename) > $this->cache_lifetime)) {
|
||||
unlink($filename);
|
||||
$this->debug("Expired $wsdl ($filename) from cache");
|
||||
$this->releaseMutex($filename);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// see what there is to return
|
||||
if (!file_exists($filename)) {
|
||||
$this->debug("$wsdl ($filename) not in cache (1)");
|
||||
$this->releaseMutex($filename);
|
||||
return null;
|
||||
}
|
||||
$fp = @fopen($filename, "r");
|
||||
if ($fp) {
|
||||
$s = implode("", @file($filename));
|
||||
fclose($fp);
|
||||
$this->debug("Got $wsdl ($filename) from cache");
|
||||
} else {
|
||||
$s = null;
|
||||
$this->debug("$wsdl ($filename) not in cache (2)");
|
||||
}
|
||||
$this->releaseMutex($filename);
|
||||
return (!is_null($s)) ? unserialize($s) : null;
|
||||
} else {
|
||||
$this->debug("Unable to obtain mutex for $filename in get");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* obtains the local mutex
|
||||
*
|
||||
* @param string $filename The Filename of the Cache to lock
|
||||
* @param string $mode The open-mode ("r" or "w") or the file - affects lock-mode
|
||||
* @return boolean Lock successfully obtained ?!
|
||||
* @access private
|
||||
*/
|
||||
function obtainMutex($filename, $mode) {
|
||||
if (isset($this->fplock[md5($filename)])) {
|
||||
$this->debug("Lock for $filename already exists");
|
||||
return false;
|
||||
}
|
||||
$this->fplock[md5($filename)] = fopen($filename.".lock", "w");
|
||||
if ($mode == "r") {
|
||||
return flock($this->fplock[md5($filename)], LOCK_SH);
|
||||
} else {
|
||||
return flock($this->fplock[md5($filename)], LOCK_EX);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* adds a wsdl instance to the cache
|
||||
*
|
||||
* @param object wsdl $wsdl_instance The wsdl instance to add
|
||||
* @return boolean WSDL successfully cached
|
||||
* @access public
|
||||
*/
|
||||
function put($wsdl_instance) {
|
||||
$filename = $this->createFilename($wsdl_instance->wsdl);
|
||||
$s = serialize($wsdl_instance);
|
||||
if ($this->obtainMutex($filename, "w")) {
|
||||
$fp = fopen($filename, "w");
|
||||
if (! $fp) {
|
||||
$this->debug("Cannot write $wsdl_instance->wsdl ($filename) in cache");
|
||||
$this->releaseMutex($filename);
|
||||
return false;
|
||||
}
|
||||
fputs($fp, $s);
|
||||
fclose($fp);
|
||||
$this->debug("Put $wsdl_instance->wsdl ($filename) in cache");
|
||||
$this->releaseMutex($filename);
|
||||
return true;
|
||||
} else {
|
||||
$this->debug("Unable to obtain mutex for $filename in put");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* releases the local mutex
|
||||
*
|
||||
* @param string $filename The Filename of the Cache to lock
|
||||
* @return boolean Lock successfully released
|
||||
* @access private
|
||||
*/
|
||||
function releaseMutex($filename) {
|
||||
$ret = flock($this->fplock[md5($filename)], LOCK_UN);
|
||||
fclose($this->fplock[md5($filename)]);
|
||||
unset($this->fplock[md5($filename)]);
|
||||
if (! $ret) {
|
||||
$this->debug("Not able to release lock for $filename");
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* removes a wsdl instance from the cache
|
||||
*
|
||||
* @param string $wsdl The URL of the wsdl instance
|
||||
* @return boolean Whether there was an instance to remove
|
||||
* @access public
|
||||
*/
|
||||
function remove($wsdl) {
|
||||
$filename = $this->createFilename($wsdl);
|
||||
if (!file_exists($filename)) {
|
||||
$this->debug("$wsdl ($filename) not in cache to be removed");
|
||||
return false;
|
||||
}
|
||||
// ignore errors obtaining mutex
|
||||
$this->obtainMutex($filename, "w");
|
||||
$ret = unlink($filename);
|
||||
$this->debug("Removed ($ret) $wsdl ($filename) from cache");
|
||||
$this->releaseMutex($filename);
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For backward compatibility
|
||||
*/
|
||||
class wsdlcache extends nusoap_wsdlcache {
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -1,478 +1,501 @@
|
|||
<?php
|
||||
/*
|
||||
$Id$
|
||||
|
||||
NuSOAP - Web Services Toolkit for PHP
|
||||
|
||||
Copyright (c) 2002 NuSphere Corporation
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
If you have any questions or comments, please email:
|
||||
|
||||
Dietrich Ayala
|
||||
dietrich@ganx4.com
|
||||
http://dietrich.ganx4.com/nusoap
|
||||
|
||||
NuSphere Corporation
|
||||
http://www.nusphere.com
|
||||
|
||||
*/
|
||||
|
||||
/*require_once('nusoap.php');*/
|
||||
/* PEAR Mail_MIME library */
|
||||
require_once('Mail/mimeDecode.php');
|
||||
require_once('Mail/mimePart.php');
|
||||
|
||||
/**
|
||||
* soapclientmime client supporting MIME attachments defined at
|
||||
* http://www.w3.org/TR/SOAP-attachments. It depends on the PEAR Mail_MIME library.
|
||||
*
|
||||
* @author Scott Nichol <snichol@sourceforge.net>
|
||||
* @author Thanks to Guillaume and Henning Reich for posting great attachment code to the mail list
|
||||
* @version $Id$
|
||||
* @access public
|
||||
*/
|
||||
class soapclientmime extends soapclient {
|
||||
/**
|
||||
* @var array Each array element in the return is an associative array with keys
|
||||
* data, filename, contenttype, cid
|
||||
* @access private
|
||||
*/
|
||||
var $requestAttachments = array();
|
||||
/**
|
||||
* @var array Each array element in the return is an associative array with keys
|
||||
* data, filename, contenttype, cid
|
||||
* @access private
|
||||
*/
|
||||
var $responseAttachments;
|
||||
/**
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $mimeContentType;
|
||||
|
||||
/**
|
||||
* adds a MIME attachment to the current request.
|
||||
*
|
||||
* If the $data parameter contains an empty string, this method will read
|
||||
* the contents of the file named by the $filename parameter.
|
||||
*
|
||||
* If the $cid parameter is false, this method will generate the cid.
|
||||
*
|
||||
* @param string $data The data of the attachment
|
||||
* @param string $filename The filename of the attachment (default is empty string)
|
||||
* @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream)
|
||||
* @param string $cid The content-id (cid) of the attachment (default is false)
|
||||
* @return string The content-id (cid) of the attachment
|
||||
* @access public
|
||||
*/
|
||||
function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) {
|
||||
if (! $cid) {
|
||||
$cid = md5(uniqid(time()));
|
||||
}
|
||||
|
||||
$info['data'] = $data;
|
||||
$info['filename'] = $filename;
|
||||
$info['contenttype'] = $contenttype;
|
||||
$info['cid'] = $cid;
|
||||
|
||||
$this->requestAttachments[] = $info;
|
||||
|
||||
return $cid;
|
||||
}
|
||||
|
||||
/**
|
||||
* clears the MIME attachments for the current request.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function clearAttachments() {
|
||||
$this->requestAttachments = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the MIME attachments from the current response.
|
||||
*
|
||||
* Each array element in the return is an associative array with keys
|
||||
* data, filename, contenttype, cid. These keys correspond to the parameters
|
||||
* for addAttachment.
|
||||
*
|
||||
* @return array The attachments.
|
||||
* @access public
|
||||
*/
|
||||
function getAttachments() {
|
||||
return $this->responseAttachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the HTTP body for the current request.
|
||||
*
|
||||
* @param string $soapmsg The SOAP payload
|
||||
* @return string The HTTP body, which includes the SOAP payload
|
||||
* @access private
|
||||
*/
|
||||
function getHTTPBody($soapmsg) {
|
||||
if (count($this->requestAttachments) > 0) {
|
||||
$params['content_type'] = 'multipart/related; type=text/xml';
|
||||
$mimeMessage =& new Mail_mimePart('', $params);
|
||||
unset($params);
|
||||
|
||||
$params['content_type'] = 'text/xml';
|
||||
$params['encoding'] = '8bit';
|
||||
$params['charset'] = $this->soap_defencoding;
|
||||
$mimeMessage->addSubpart($soapmsg, $params);
|
||||
|
||||
foreach ($this->requestAttachments as $att) {
|
||||
unset($params);
|
||||
|
||||
$params['content_type'] = $att['contenttype'];
|
||||
$params['encoding'] = 'base64';
|
||||
$params['disposition'] = 'attachment';
|
||||
$params['dfilename'] = $att['filename'];
|
||||
$params['cid'] = $att['cid'];
|
||||
|
||||
if ($att['data'] == '' && $att['filename'] <> '') {
|
||||
if ($fd = fopen($att['filename'], 'rb')) {
|
||||
$data = fread($fd, filesize($att['filename']));
|
||||
fclose($fd);
|
||||
} else {
|
||||
$data = '';
|
||||
}
|
||||
$mimeMessage->addSubpart($data, $params);
|
||||
} else {
|
||||
$mimeMessage->addSubpart($att['data'], $params);
|
||||
}
|
||||
}
|
||||
|
||||
$output = $mimeMessage->encode();
|
||||
$mimeHeaders = $output['headers'];
|
||||
|
||||
foreach ($mimeHeaders as $k => $v) {
|
||||
$this->debug("MIME header $k: $v");
|
||||
if (strtolower($k) == 'content-type') {
|
||||
// PHP header() seems to strip leading whitespace starting
|
||||
// the second line, so force everything to one line
|
||||
$this->mimeContentType = str_replace("\r\n", " ", $v);
|
||||
}
|
||||
}
|
||||
|
||||
return $output['body'];
|
||||
}
|
||||
|
||||
return parent::getHTTPBody($soapmsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the HTTP content type for the current request.
|
||||
*
|
||||
* Note: getHTTPBody must be called before this.
|
||||
*
|
||||
* @return string the HTTP content type for the current request.
|
||||
* @access private
|
||||
*/
|
||||
function getHTTPContentType() {
|
||||
if (count($this->requestAttachments) > 0) {
|
||||
return $this->mimeContentType;
|
||||
}
|
||||
return parent::getHTTPContentType();
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the HTTP content type charset for the current request.
|
||||
* returns false for non-text content types.
|
||||
*
|
||||
* Note: getHTTPBody must be called before this.
|
||||
*
|
||||
* @return string the HTTP content type charset for the current request.
|
||||
* @access private
|
||||
*/
|
||||
function getHTTPContentTypeCharset() {
|
||||
if (count($this->requestAttachments) > 0) {
|
||||
return false;
|
||||
}
|
||||
return parent::getHTTPContentTypeCharset();
|
||||
}
|
||||
|
||||
/**
|
||||
* processes SOAP message returned from server
|
||||
*
|
||||
* @param array $headers The HTTP headers
|
||||
* @param string $data unprocessed response data from server
|
||||
* @return mixed value of the message, decoded into a PHP type
|
||||
* @access private
|
||||
*/
|
||||
function parseResponse($headers, $data) {
|
||||
$this->debug('Entering parseResponse() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']);
|
||||
$this->responseAttachments = array();
|
||||
if (strstr($headers['content-type'], 'multipart/related')) {
|
||||
$this->debug('Decode multipart/related');
|
||||
$input = '';
|
||||
foreach ($headers as $k => $v) {
|
||||
$input .= "$k: $v\r\n";
|
||||
}
|
||||
$params['input'] = $input . "\r\n" . $data;
|
||||
$params['include_bodies'] = true;
|
||||
$params['decode_bodies'] = true;
|
||||
$params['decode_headers'] = true;
|
||||
|
||||
$structure = Mail_mimeDecode::decode($params);
|
||||
|
||||
foreach ($structure->parts as $part) {
|
||||
if (!isset($part->disposition)) {
|
||||
$this->debug('Have root part of type ' . $part->headers['content-type']);
|
||||
$return = parent::parseResponse($part->headers, $part->body);
|
||||
} else {
|
||||
$this->debug('Have an attachment of type ' . $part->headers['content-type']);
|
||||
$info['data'] = $part->body;
|
||||
$info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : '';
|
||||
$info['contenttype'] = $part->headers['content-type'];
|
||||
$info['cid'] = $part->headers['content-id'];
|
||||
$this->responseAttachments[] = $info;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($return)) {
|
||||
return $return;
|
||||
}
|
||||
|
||||
$this->setError('No root part found in multipart/related content');
|
||||
return;
|
||||
}
|
||||
$this->debug('Not multipart/related');
|
||||
return parent::parseResponse($headers, $data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* nusoapservermime server supporting MIME attachments defined at
|
||||
* http://www.w3.org/TR/SOAP-attachments. It depends on the PEAR Mail_MIME library.
|
||||
*
|
||||
* @author Scott Nichol <snichol@sourceforge.net>
|
||||
* @author Thanks to Guillaume and Henning Reich for posting great attachment code to the mail list
|
||||
* @version $Id$
|
||||
* @access public
|
||||
*/
|
||||
class nusoapservermime extends soap_server {
|
||||
/**
|
||||
* @var array Each array element in the return is an associative array with keys
|
||||
* data, filename, contenttype, cid
|
||||
* @access private
|
||||
*/
|
||||
var $requestAttachments = array();
|
||||
/**
|
||||
* @var array Each array element in the return is an associative array with keys
|
||||
* data, filename, contenttype, cid
|
||||
* @access private
|
||||
*/
|
||||
var $responseAttachments;
|
||||
/**
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $mimeContentType;
|
||||
|
||||
/**
|
||||
* adds a MIME attachment to the current response.
|
||||
*
|
||||
* If the $data parameter contains an empty string, this method will read
|
||||
* the contents of the file named by the $filename parameter.
|
||||
*
|
||||
* If the $cid parameter is false, this method will generate the cid.
|
||||
*
|
||||
* @param string $data The data of the attachment
|
||||
* @param string $filename The filename of the attachment (default is empty string)
|
||||
* @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream)
|
||||
* @param string $cid The content-id (cid) of the attachment (default is false)
|
||||
* @return string The content-id (cid) of the attachment
|
||||
* @access public
|
||||
*/
|
||||
function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) {
|
||||
if (! $cid) {
|
||||
$cid = md5(uniqid(time()));
|
||||
}
|
||||
|
||||
$info['data'] = $data;
|
||||
$info['filename'] = $filename;
|
||||
$info['contenttype'] = $contenttype;
|
||||
$info['cid'] = $cid;
|
||||
|
||||
$this->responseAttachments[] = $info;
|
||||
|
||||
return $cid;
|
||||
}
|
||||
|
||||
/**
|
||||
* clears the MIME attachments for the current response.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function clearAttachments() {
|
||||
$this->responseAttachments = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the MIME attachments from the current request.
|
||||
*
|
||||
* Each array element in the return is an associative array with keys
|
||||
* data, filename, contenttype, cid. These keys correspond to the parameters
|
||||
* for addAttachment.
|
||||
*
|
||||
* @return array The attachments.
|
||||
* @access public
|
||||
*/
|
||||
function getAttachments() {
|
||||
return $this->requestAttachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the HTTP body for the current response.
|
||||
*
|
||||
* @param string $soapmsg The SOAP payload
|
||||
* @return string The HTTP body, which includes the SOAP payload
|
||||
* @access private
|
||||
*/
|
||||
function getHTTPBody($soapmsg) {
|
||||
if (count($this->responseAttachments) > 0) {
|
||||
$params['content_type'] = 'multipart/related; type=text/xml';
|
||||
$mimeMessage =& new Mail_mimePart('', $params);
|
||||
unset($params);
|
||||
|
||||
$params['content_type'] = 'text/xml';
|
||||
$params['encoding'] = '8bit';
|
||||
$params['charset'] = $this->soap_defencoding;
|
||||
$mimeMessage->addSubpart($soapmsg, $params);
|
||||
|
||||
foreach ($this->responseAttachments as $att) {
|
||||
unset($params);
|
||||
|
||||
$params['content_type'] = $att['contenttype'];
|
||||
$params['encoding'] = 'base64';
|
||||
$params['disposition'] = 'attachment';
|
||||
$params['dfilename'] = $att['filename'];
|
||||
$params['cid'] = $att['cid'];
|
||||
|
||||
if ($att['data'] == '' && $att['filename'] <> '') {
|
||||
if ($fd = fopen($att['filename'], 'rb')) {
|
||||
$data = fread($fd, filesize($att['filename']));
|
||||
fclose($fd);
|
||||
} else {
|
||||
$data = '';
|
||||
}
|
||||
$mimeMessage->addSubpart($data, $params);
|
||||
} else {
|
||||
$mimeMessage->addSubpart($att['data'], $params);
|
||||
}
|
||||
}
|
||||
|
||||
$output = $mimeMessage->encode();
|
||||
$mimeHeaders = $output['headers'];
|
||||
|
||||
foreach ($mimeHeaders as $k => $v) {
|
||||
$this->debug("MIME header $k: $v");
|
||||
if (strtolower($k) == 'content-type') {
|
||||
// PHP header() seems to strip leading whitespace starting
|
||||
// the second line, so force everything to one line
|
||||
$this->mimeContentType = str_replace("\r\n", " ", $v);
|
||||
}
|
||||
}
|
||||
|
||||
return $output['body'];
|
||||
}
|
||||
|
||||
return parent::getHTTPBody($soapmsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the HTTP content type for the current response.
|
||||
*
|
||||
* Note: getHTTPBody must be called before this.
|
||||
*
|
||||
* @return string the HTTP content type for the current response.
|
||||
* @access private
|
||||
*/
|
||||
function getHTTPContentType() {
|
||||
if (count($this->responseAttachments) > 0) {
|
||||
return $this->mimeContentType;
|
||||
}
|
||||
return parent::getHTTPContentType();
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the HTTP content type charset for the current response.
|
||||
* returns false for non-text content types.
|
||||
*
|
||||
* Note: getHTTPBody must be called before this.
|
||||
*
|
||||
* @return string the HTTP content type charset for the current response.
|
||||
* @access private
|
||||
*/
|
||||
function getHTTPContentTypeCharset() {
|
||||
if (count($this->responseAttachments) > 0) {
|
||||
return false;
|
||||
}
|
||||
return parent::getHTTPContentTypeCharset();
|
||||
}
|
||||
|
||||
/**
|
||||
* processes SOAP message received from client
|
||||
*
|
||||
* @param array $headers The HTTP headers
|
||||
* @param string $data unprocessed request data from client
|
||||
* @return mixed value of the message, decoded into a PHP type
|
||||
* @access private
|
||||
*/
|
||||
function parseRequest($headers, $data) {
|
||||
$this->debug('Entering parseRequest() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']);
|
||||
$this->requestAttachments = array();
|
||||
if (strstr($headers['content-type'], 'multipart/related')) {
|
||||
$this->debug('Decode multipart/related');
|
||||
$input = '';
|
||||
foreach ($headers as $k => $v) {
|
||||
$input .= "$k: $v\r\n";
|
||||
}
|
||||
$params['input'] = $input . "\r\n" . $data;
|
||||
$params['include_bodies'] = true;
|
||||
$params['decode_bodies'] = true;
|
||||
$params['decode_headers'] = true;
|
||||
|
||||
$structure = Mail_mimeDecode::decode($params);
|
||||
|
||||
foreach ($structure->parts as $part) {
|
||||
if (!isset($part->disposition)) {
|
||||
$this->debug('Have root part of type ' . $part->headers['content-type']);
|
||||
$return = parent::parseRequest($part->headers, $part->body);
|
||||
} else {
|
||||
$this->debug('Have an attachment of type ' . $part->headers['content-type']);
|
||||
$info['data'] = $part->body;
|
||||
$info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : '';
|
||||
$info['contenttype'] = $part->headers['content-type'];
|
||||
$info['cid'] = $part->headers['content-id'];
|
||||
$this->requestAttachments[] = $info;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($return)) {
|
||||
return $return;
|
||||
}
|
||||
|
||||
$this->setError('No root part found in multipart/related content');
|
||||
return;
|
||||
}
|
||||
$this->debug('Not multipart/related');
|
||||
return parent::parseRequest($headers, $data);
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
/*
|
||||
$Id$
|
||||
|
||||
NuSOAP - Web Services Toolkit for PHP
|
||||
|
||||
Copyright (c) 2002 NuSphere Corporation
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
The NuSOAP project home is:
|
||||
http://sourceforge.net/projects/nusoap/
|
||||
|
||||
The primary support for NuSOAP is the mailing list:
|
||||
nusoap-general@lists.sourceforge.net
|
||||
|
||||
If you have any questions or comments, please email:
|
||||
|
||||
Dietrich Ayala
|
||||
dietrich@ganx4.com
|
||||
http://dietrich.ganx4.com/nusoap
|
||||
|
||||
NuSphere Corporation
|
||||
http://www.nusphere.com
|
||||
|
||||
*/
|
||||
|
||||
/*require_once('nusoap.php');*/
|
||||
/* PEAR Mail_MIME library */
|
||||
require_once('Mail/mimeDecode.php');
|
||||
require_once('Mail/mimePart.php');
|
||||
|
||||
/**
|
||||
* nusoap_client_mime client supporting MIME attachments defined at
|
||||
* http://www.w3.org/TR/SOAP-attachments. It depends on the PEAR Mail_MIME library.
|
||||
*
|
||||
* @author Scott Nichol <snichol@users.sourceforge.net>
|
||||
* @author Thanks to Guillaume and Henning Reich for posting great attachment code to the mail list
|
||||
* @version $Id$
|
||||
* @access public
|
||||
*/
|
||||
class nusoap_client_mime extends nusoap_client {
|
||||
/**
|
||||
* @var array Each array element in the return is an associative array with keys
|
||||
* data, filename, contenttype, cid
|
||||
* @access private
|
||||
*/
|
||||
var $requestAttachments = array();
|
||||
/**
|
||||
* @var array Each array element in the return is an associative array with keys
|
||||
* data, filename, contenttype, cid
|
||||
* @access private
|
||||
*/
|
||||
var $responseAttachments;
|
||||
/**
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $mimeContentType;
|
||||
|
||||
/**
|
||||
* adds a MIME attachment to the current request.
|
||||
*
|
||||
* If the $data parameter contains an empty string, this method will read
|
||||
* the contents of the file named by the $filename parameter.
|
||||
*
|
||||
* If the $cid parameter is false, this method will generate the cid.
|
||||
*
|
||||
* @param string $data The data of the attachment
|
||||
* @param string $filename The filename of the attachment (default is empty string)
|
||||
* @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream)
|
||||
* @param string $cid The content-id (cid) of the attachment (default is false)
|
||||
* @return string The content-id (cid) of the attachment
|
||||
* @access public
|
||||
*/
|
||||
function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) {
|
||||
if (! $cid) {
|
||||
$cid = md5(uniqid(time()));
|
||||
}
|
||||
|
||||
$info['data'] = $data;
|
||||
$info['filename'] = $filename;
|
||||
$info['contenttype'] = $contenttype;
|
||||
$info['cid'] = $cid;
|
||||
|
||||
$this->requestAttachments[] = $info;
|
||||
|
||||
return $cid;
|
||||
}
|
||||
|
||||
/**
|
||||
* clears the MIME attachments for the current request.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function clearAttachments() {
|
||||
$this->requestAttachments = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the MIME attachments from the current response.
|
||||
*
|
||||
* Each array element in the return is an associative array with keys
|
||||
* data, filename, contenttype, cid. These keys correspond to the parameters
|
||||
* for addAttachment.
|
||||
*
|
||||
* @return array The attachments.
|
||||
* @access public
|
||||
*/
|
||||
function getAttachments() {
|
||||
return $this->responseAttachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the HTTP body for the current request.
|
||||
*
|
||||
* @param string $soapmsg The SOAP payload
|
||||
* @return string The HTTP body, which includes the SOAP payload
|
||||
* @access private
|
||||
*/
|
||||
function getHTTPBody($soapmsg) {
|
||||
if (count($this->requestAttachments) > 0) {
|
||||
$params['content_type'] = 'multipart/related; type="text/xml"';
|
||||
$mimeMessage =& new Mail_mimePart('', $params);
|
||||
unset($params);
|
||||
|
||||
$params['content_type'] = 'text/xml';
|
||||
$params['encoding'] = '8bit';
|
||||
$params['charset'] = $this->soap_defencoding;
|
||||
$mimeMessage->addSubpart($soapmsg, $params);
|
||||
|
||||
foreach ($this->requestAttachments as $att) {
|
||||
unset($params);
|
||||
|
||||
$params['content_type'] = $att['contenttype'];
|
||||
$params['encoding'] = 'base64';
|
||||
$params['disposition'] = 'attachment';
|
||||
$params['dfilename'] = $att['filename'];
|
||||
$params['cid'] = $att['cid'];
|
||||
|
||||
if ($att['data'] == '' && $att['filename'] <> '') {
|
||||
if ($fd = fopen($att['filename'], 'rb')) {
|
||||
$data = fread($fd, filesize($att['filename']));
|
||||
fclose($fd);
|
||||
} else {
|
||||
$data = '';
|
||||
}
|
||||
$mimeMessage->addSubpart($data, $params);
|
||||
} else {
|
||||
$mimeMessage->addSubpart($att['data'], $params);
|
||||
}
|
||||
}
|
||||
|
||||
$output = $mimeMessage->encode();
|
||||
$mimeHeaders = $output['headers'];
|
||||
|
||||
foreach ($mimeHeaders as $k => $v) {
|
||||
$this->debug("MIME header $k: $v");
|
||||
if (strtolower($k) == 'content-type') {
|
||||
// PHP header() seems to strip leading whitespace starting
|
||||
// the second line, so force everything to one line
|
||||
$this->mimeContentType = str_replace("\r\n", " ", $v);
|
||||
}
|
||||
}
|
||||
|
||||
return $output['body'];
|
||||
}
|
||||
|
||||
return parent::getHTTPBody($soapmsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the HTTP content type for the current request.
|
||||
*
|
||||
* Note: getHTTPBody must be called before this.
|
||||
*
|
||||
* @return string the HTTP content type for the current request.
|
||||
* @access private
|
||||
*/
|
||||
function getHTTPContentType() {
|
||||
if (count($this->requestAttachments) > 0) {
|
||||
return $this->mimeContentType;
|
||||
}
|
||||
return parent::getHTTPContentType();
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the HTTP content type charset for the current request.
|
||||
* returns false for non-text content types.
|
||||
*
|
||||
* Note: getHTTPBody must be called before this.
|
||||
*
|
||||
* @return string the HTTP content type charset for the current request.
|
||||
* @access private
|
||||
*/
|
||||
function getHTTPContentTypeCharset() {
|
||||
if (count($this->requestAttachments) > 0) {
|
||||
return false;
|
||||
}
|
||||
return parent::getHTTPContentTypeCharset();
|
||||
}
|
||||
|
||||
/**
|
||||
* processes SOAP message returned from server
|
||||
*
|
||||
* @param array $headers The HTTP headers
|
||||
* @param string $data unprocessed response data from server
|
||||
* @return mixed value of the message, decoded into a PHP type
|
||||
* @access private
|
||||
*/
|
||||
function parseResponse($headers, $data) {
|
||||
$this->debug('Entering parseResponse() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']);
|
||||
$this->responseAttachments = array();
|
||||
if (strstr($headers['content-type'], 'multipart/related')) {
|
||||
$this->debug('Decode multipart/related');
|
||||
$input = '';
|
||||
foreach ($headers as $k => $v) {
|
||||
$input .= "$k: $v\r\n";
|
||||
}
|
||||
$params['input'] = $input . "\r\n" . $data;
|
||||
$params['include_bodies'] = true;
|
||||
$params['decode_bodies'] = true;
|
||||
$params['decode_headers'] = true;
|
||||
|
||||
$structure = Mail_mimeDecode::decode($params);
|
||||
|
||||
foreach ($structure->parts as $part) {
|
||||
if (!isset($part->disposition) && (strstr($part->headers['content-type'], 'text/xml'))) {
|
||||
$this->debug('Have root part of type ' . $part->headers['content-type']);
|
||||
$root = $part->body;
|
||||
$return = parent::parseResponse($part->headers, $part->body);
|
||||
} else {
|
||||
$this->debug('Have an attachment of type ' . $part->headers['content-type']);
|
||||
$info['data'] = $part->body;
|
||||
$info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : '';
|
||||
$info['contenttype'] = $part->headers['content-type'];
|
||||
$info['cid'] = $part->headers['content-id'];
|
||||
$this->responseAttachments[] = $info;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($return)) {
|
||||
$this->responseData = $root;
|
||||
return $return;
|
||||
}
|
||||
|
||||
$this->setError('No root part found in multipart/related content');
|
||||
return '';
|
||||
}
|
||||
$this->debug('Not multipart/related');
|
||||
return parent::parseResponse($headers, $data);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* For backwards compatiblity, define soapclientmime unless the PHP SOAP extension is loaded.
|
||||
*/
|
||||
if (!extension_loaded('soap')) {
|
||||
class soapclientmime extends nusoap_client_mime {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* nusoap_server_mime server supporting MIME attachments defined at
|
||||
* http://www.w3.org/TR/SOAP-attachments. It depends on the PEAR Mail_MIME library.
|
||||
*
|
||||
* @author Scott Nichol <snichol@users.sourceforge.net>
|
||||
* @author Thanks to Guillaume and Henning Reich for posting great attachment code to the mail list
|
||||
* @version $Id$
|
||||
* @access public
|
||||
*/
|
||||
class nusoap_server_mime extends nusoap_server {
|
||||
/**
|
||||
* @var array Each array element in the return is an associative array with keys
|
||||
* data, filename, contenttype, cid
|
||||
* @access private
|
||||
*/
|
||||
var $requestAttachments = array();
|
||||
/**
|
||||
* @var array Each array element in the return is an associative array with keys
|
||||
* data, filename, contenttype, cid
|
||||
* @access private
|
||||
*/
|
||||
var $responseAttachments;
|
||||
/**
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $mimeContentType;
|
||||
|
||||
/**
|
||||
* adds a MIME attachment to the current response.
|
||||
*
|
||||
* If the $data parameter contains an empty string, this method will read
|
||||
* the contents of the file named by the $filename parameter.
|
||||
*
|
||||
* If the $cid parameter is false, this method will generate the cid.
|
||||
*
|
||||
* @param string $data The data of the attachment
|
||||
* @param string $filename The filename of the attachment (default is empty string)
|
||||
* @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream)
|
||||
* @param string $cid The content-id (cid) of the attachment (default is false)
|
||||
* @return string The content-id (cid) of the attachment
|
||||
* @access public
|
||||
*/
|
||||
function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) {
|
||||
if (! $cid) {
|
||||
$cid = md5(uniqid(time()));
|
||||
}
|
||||
|
||||
$info['data'] = $data;
|
||||
$info['filename'] = $filename;
|
||||
$info['contenttype'] = $contenttype;
|
||||
$info['cid'] = $cid;
|
||||
|
||||
$this->responseAttachments[] = $info;
|
||||
|
||||
return $cid;
|
||||
}
|
||||
|
||||
/**
|
||||
* clears the MIME attachments for the current response.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function clearAttachments() {
|
||||
$this->responseAttachments = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the MIME attachments from the current request.
|
||||
*
|
||||
* Each array element in the return is an associative array with keys
|
||||
* data, filename, contenttype, cid. These keys correspond to the parameters
|
||||
* for addAttachment.
|
||||
*
|
||||
* @return array The attachments.
|
||||
* @access public
|
||||
*/
|
||||
function getAttachments() {
|
||||
return $this->requestAttachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the HTTP body for the current response.
|
||||
*
|
||||
* @param string $soapmsg The SOAP payload
|
||||
* @return string The HTTP body, which includes the SOAP payload
|
||||
* @access private
|
||||
*/
|
||||
function getHTTPBody($soapmsg) {
|
||||
if (count($this->responseAttachments) > 0) {
|
||||
$params['content_type'] = 'multipart/related; type="text/xml"';
|
||||
$mimeMessage =& new Mail_mimePart('', $params);
|
||||
unset($params);
|
||||
|
||||
$params['content_type'] = 'text/xml';
|
||||
$params['encoding'] = '8bit';
|
||||
$params['charset'] = $this->soap_defencoding;
|
||||
$mimeMessage->addSubpart($soapmsg, $params);
|
||||
|
||||
foreach ($this->responseAttachments as $att) {
|
||||
unset($params);
|
||||
|
||||
$params['content_type'] = $att['contenttype'];
|
||||
$params['encoding'] = 'base64';
|
||||
$params['disposition'] = 'attachment';
|
||||
$params['dfilename'] = $att['filename'];
|
||||
$params['cid'] = $att['cid'];
|
||||
|
||||
if ($att['data'] == '' && $att['filename'] <> '') {
|
||||
if ($fd = fopen($att['filename'], 'rb')) {
|
||||
$data = fread($fd, filesize($att['filename']));
|
||||
fclose($fd);
|
||||
} else {
|
||||
$data = '';
|
||||
}
|
||||
$mimeMessage->addSubpart($data, $params);
|
||||
} else {
|
||||
$mimeMessage->addSubpart($att['data'], $params);
|
||||
}
|
||||
}
|
||||
|
||||
$output = $mimeMessage->encode();
|
||||
$mimeHeaders = $output['headers'];
|
||||
|
||||
foreach ($mimeHeaders as $k => $v) {
|
||||
$this->debug("MIME header $k: $v");
|
||||
if (strtolower($k) == 'content-type') {
|
||||
// PHP header() seems to strip leading whitespace starting
|
||||
// the second line, so force everything to one line
|
||||
$this->mimeContentType = str_replace("\r\n", " ", $v);
|
||||
}
|
||||
}
|
||||
|
||||
return $output['body'];
|
||||
}
|
||||
|
||||
return parent::getHTTPBody($soapmsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the HTTP content type for the current response.
|
||||
*
|
||||
* Note: getHTTPBody must be called before this.
|
||||
*
|
||||
* @return string the HTTP content type for the current response.
|
||||
* @access private
|
||||
*/
|
||||
function getHTTPContentType() {
|
||||
if (count($this->responseAttachments) > 0) {
|
||||
return $this->mimeContentType;
|
||||
}
|
||||
return parent::getHTTPContentType();
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the HTTP content type charset for the current response.
|
||||
* returns false for non-text content types.
|
||||
*
|
||||
* Note: getHTTPBody must be called before this.
|
||||
*
|
||||
* @return string the HTTP content type charset for the current response.
|
||||
* @access private
|
||||
*/
|
||||
function getHTTPContentTypeCharset() {
|
||||
if (count($this->responseAttachments) > 0) {
|
||||
return false;
|
||||
}
|
||||
return parent::getHTTPContentTypeCharset();
|
||||
}
|
||||
|
||||
/**
|
||||
* processes SOAP message received from client
|
||||
*
|
||||
* @param array $headers The HTTP headers
|
||||
* @param string $data unprocessed request data from client
|
||||
* @return mixed value of the message, decoded into a PHP type
|
||||
* @access private
|
||||
*/
|
||||
function parseRequest($headers, $data) {
|
||||
$this->debug('Entering parseRequest() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']);
|
||||
$this->requestAttachments = array();
|
||||
if (strstr($headers['content-type'], 'multipart/related')) {
|
||||
$this->debug('Decode multipart/related');
|
||||
$input = '';
|
||||
foreach ($headers as $k => $v) {
|
||||
$input .= "$k: $v\r\n";
|
||||
}
|
||||
$params['input'] = $input . "\r\n" . $data;
|
||||
$params['include_bodies'] = true;
|
||||
$params['decode_bodies'] = true;
|
||||
$params['decode_headers'] = true;
|
||||
|
||||
$structure = Mail_mimeDecode::decode($params);
|
||||
|
||||
foreach ($structure->parts as $part) {
|
||||
if (!isset($part->disposition) && (strstr($part->headers['content-type'], 'text/xml'))) {
|
||||
$this->debug('Have root part of type ' . $part->headers['content-type']);
|
||||
$return = parent::parseRequest($part->headers, $part->body);
|
||||
} else {
|
||||
$this->debug('Have an attachment of type ' . $part->headers['content-type']);
|
||||
$info['data'] = $part->body;
|
||||
$info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : '';
|
||||
$info['contenttype'] = $part->headers['content-type'];
|
||||
$info['cid'] = $part->headers['content-id'];
|
||||
$this->requestAttachments[] = $info;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($return)) {
|
||||
return $return;
|
||||
}
|
||||
|
||||
$this->setError('No root part found in multipart/related content');
|
||||
return;
|
||||
}
|
||||
$this->debug('Not multipart/related');
|
||||
return parent::parseRequest($headers, $data);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* For backwards compatiblity
|
||||
*/
|
||||
class nusoapservermime extends nusoap_server_mime {
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user