PageRenderTime 78ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/gforge/plugins/wiki/www/lib/nusoap/nusoap.php

https://github.com/neymanna/fusionforge
PHP | 4085 lines | 2653 code | 201 blank | 1231 comment | 681 complexity | d3d06aa82a6c877f6c88618c587b313d MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * NuSOAP - Web Services Toolkit for PHP
  4. *
  5. * @author: Dietrich Ayala
  6. */
  7. /*
  8. Copyright (c) 2002 NuSphere Corporation
  9. This library is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU Lesser General Public
  11. License as published by the Free Software Foundation; either
  12. version 2.1 of the License, or (at your option) any later version.
  13. This library is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. Lesser General Public License for more details.
  17. You should have received a copy of the GNU Lesser General Public
  18. License along with this library; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. If you have any questions or comments, please email:
  21. Dietrich Ayala
  22. dietrich@ganx4.com
  23. http://dietrich.ganx4.com/nusoap
  24. NuSphere Corporation
  25. http://www.nusphere.com
  26. */
  27. /* load classes
  28. // necessary classes
  29. require_once('class.nusoapclient.php');
  30. require_once('class.soap_val.php');
  31. require_once('class.soap_parser.php');
  32. require_once('class.soap_fault.php');
  33. // transport classes
  34. require_once('class.soap_transport_http.php');
  35. // optional add-on classes
  36. require_once('class.xmlschema.php');
  37. require_once('class.wsdl.php');
  38. // server class
  39. require_once('class.soap_server.php');*/
  40. /**
  41. *
  42. * nusoap_base
  43. *
  44. * @author Dietrich Ayala <dietrich@ganx4.com>
  45. * @version v 0.6.3
  46. * @access public
  47. */
  48. class nusoap_base {
  49. var $title = 'NuSOAP';
  50. var $version = '0.6.3';
  51. var $error_str = false;
  52. var $debug_str = '';
  53. // toggles automatic encoding of special characters
  54. var $charencoding = true;
  55. /**
  56. * set schema version
  57. *
  58. * @var XMLSchemaVersion
  59. * @access public
  60. */
  61. var $XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema';
  62. /**
  63. * set default encoding
  64. *
  65. * @var soap_defencoding
  66. * @access public
  67. */
  68. //var $soap_defencoding = 'UTF-8';
  69. var $soap_defencoding = 'ISO-8859-1';
  70. /**
  71. * load namespace uris into an array of uri => prefix
  72. *
  73. * @var namespaces
  74. * @access public
  75. */
  76. var $namespaces = array(
  77. 'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/',
  78. 'xsd' => 'http://www.w3.org/2001/XMLSchema',
  79. 'xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
  80. 'SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/',
  81. 'si' => 'http://soapinterop.org/xsd');
  82. /**
  83. * load types into typemap array
  84. * is this legacy yet?
  85. * no, this is used by the xmlschema class to verify type => namespace mappings.
  86. * @var typemap
  87. * @access public
  88. */
  89. var $typemap =
  90. array(
  91. 'http://www.w3.org/2001/XMLSchema' =>
  92. array(
  93. 'string'=>'string','boolean'=>'boolean','float'=>'double','double'=>'double','decimal'=>'double',
  94. 'duration'=>'','dateTime'=>'string','time'=>'string','date'=>'string','gYearMonth'=>'',
  95. 'gYear'=>'','gMonthDay'=>'','gDay'=>'','gMonth'=>'','hexBinary'=>'string','base64Binary'=>'string',
  96. // derived datatypes
  97. 'normalizedString'=>'string','token'=>'string','language'=>'','NMTOKEN'=>'','NMTOKENS'=>'','Name'=>'','NCName'=>'','ID'=>'',
  98. 'IDREF'=>'','IDREFS'=>'','ENTITY'=>'','ENTITIES'=>'','integer'=>'integer','nonPositiveInteger'=>'integer',
  99. 'negativeInteger'=>'integer','long'=>'integer','int'=>'integer','short'=>'integer','byte'=>'integer','nonNegativeInteger'=>'integer',
  100. 'unsignedLong'=>'','unsignedInt'=>'','unsignedShort'=>'','unsignedByte'=>'','positiveInteger'=>''),
  101. 'http://www.w3.org/1999/XMLSchema' =>
  102. array(
  103. 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
  104. 'float'=>'double','dateTime'=>'string',
  105. 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
  106. 'http://soapinterop.org/xsd' => array('SOAPStruct'=>'struct'),
  107. 'http://schemas.xmlsoap.org/soap/encoding/' => array('base64'=>'string','array'=>'array','Array'=>'array'),
  108. 'http://xml.apache.org/xml-soap' => array('Map')
  109. );
  110. /**
  111. * entities to convert
  112. *
  113. * @var xmlEntities
  114. * @access public
  115. */
  116. var $xmlEntities = array('quot' => '"','amp' => '&',
  117. 'lt' => '<','gt' => '>','apos' => "'");
  118. /**
  119. * adds debug data to the class level debug string
  120. *
  121. * @param string $string debug data
  122. * @access private
  123. */
  124. function debug($string){
  125. $this->debug_str .= get_class($this).": $string\n";
  126. }
  127. /**
  128. * returns error string if present
  129. *
  130. * @return boolean $string error string
  131. * @access public
  132. */
  133. function getError(){
  134. if($this->error_str != ''){
  135. return $this->error_str;
  136. }
  137. return false;
  138. }
  139. /**
  140. * sets error string
  141. *
  142. * @return boolean $string error string
  143. * @access private
  144. */
  145. function setError($str){
  146. $this->error_str = $str;
  147. }
  148. /**
  149. * serializes PHP values in accordance w/ section 5. Type information is
  150. * not serialized if $use == 'literal'.
  151. *
  152. * @return string
  153. * @access public
  154. */
  155. function serialize_val($val,$name=false,$type=false,$name_ns=false,
  156. $type_ns=false,$attributes=false,$use='encoded') {
  157. if(is_object($val) && strtolower(get_class($val)) == 'soapval'){
  158. return $val->serialize($use);
  159. }
  160. $this->debug( "in serialize_val: $val, $name, $type, $name_ns, $type_ns, $attributes, $use");
  161. // if no name, use item
  162. $name = (!$name|| is_numeric($name)) ? 'soapVal' : $name;
  163. // if name has ns, add ns prefix to name
  164. $xmlns = '';
  165. if($name_ns){
  166. $prefix = 'nu'.rand(1000,9999);
  167. $name = $prefix.':'.$name;
  168. $xmlns .= " xmlns:$prefix=\"$name_ns\"";
  169. }
  170. // if type is prefixed, create type prefix
  171. if($type_ns != '' && $type_ns == $this->namespaces['xsd']){
  172. // need to fix this. shouldn't default to xsd if no ns specified
  173. // w/o checking against typemap
  174. $type_prefix = 'xsd';
  175. } elseif($type_ns){
  176. $type_prefix = 'ns'.rand(1000,9999);
  177. $xmlns .= " xmlns:$type_prefix=\"$type_ns\"";
  178. }
  179. // serialize attributes if present
  180. if($attributes){
  181. foreach($attributes as $k => $v){
  182. $atts .= " $k=\"$v\"";
  183. }
  184. }
  185. // serialize if an xsd built-in primitive type
  186. if ($type != '' && isset($this->typemap[$this->XMLSchemaVersion][$type])){
  187. if ($use == 'literal') {
  188. return "<$name$xmlns>$val</$name>";
  189. } else {
  190. return "<$name$xmlns xsi:type=\"xsd:$type\">$val</$name>";
  191. }
  192. }
  193. // detect type and serialize
  194. $xml = '';
  195. $atts = '';
  196. switch(true) {
  197. case ($type == '' && is_null($val)):
  198. if ($use == 'literal') {
  199. // TODO: depends on nillable
  200. $xml .= "<$name$xmlns/>";
  201. } else {
  202. $xml .= "<$name$xmlns xsi:type=\"xsd:nil\"/>";
  203. }
  204. break;
  205. case (is_bool($val) || $type == 'boolean'):
  206. if(!$val){
  207. $val = 0;
  208. }
  209. if ($use == 'literal') {
  210. $xml .= "<$name$xmlns $atts>$val</$name>";
  211. } else {
  212. $xml .= "<$name$xmlns xsi:type=\"xsd:boolean\"$atts>$val</$name>";
  213. }
  214. break;
  215. case (is_int($val) || is_long($val) || $type == 'int'):
  216. if ($use == 'literal') {
  217. $xml .= "<$name$xmlns $atts>$val</$name>";
  218. } else {
  219. $xml .= "<$name$xmlns xsi:type=\"xsd:int\"$atts>$val</$name>";
  220. }
  221. break;
  222. case (is_float($val)|| is_double($val) || $type == 'float'):
  223. if ($use == 'literal') {
  224. $xml .= "<$name$xmlns $atts>$val</$name>";
  225. } else {
  226. $xml .= "<$name$xmlns xsi:type=\"xsd:float\"$atts>$val</$name>";
  227. }
  228. break;
  229. case (is_string($val) || $type == 'string'):
  230. if($this->charencoding){
  231. $val = htmlspecialchars($val, ENT_QUOTES);
  232. }
  233. if ($use == 'literal') {
  234. $xml .= "<$name$xmlns $atts>$val</$name>";
  235. } else {
  236. $xml .= "<$name$xmlns xsi:type=\"xsd:string\"$atts>$val</$name>";
  237. }
  238. break;
  239. case is_object($val):
  240. $name = strtolower(get_class($val));
  241. foreach(get_object_vars($val) as $k => $v){
  242. $pXml = isset($pXml) ? $pXml.$this->serialize_val($v,$k,false,false,false,false,$use) : $this->serialize_val($v,$k,false,false,false,false,$use);
  243. }
  244. $xml .= '<'.$name.'>'.$pXml.'</'.$name.'>';
  245. break;
  246. break;
  247. case (is_array($val) || $type):
  248. // detect if struct or array
  249. $keyList = array_keys($val);
  250. $valueType = 'arraySimple';
  251. foreach($keyList as $keyListValue){
  252. if(!is_int($keyListValue)){
  253. $valueType = 'arrayStruct';
  254. break;
  255. }
  256. }
  257. if($valueType=='arraySimple' || ereg('^ArrayOf',$type)){
  258. $i = 0;
  259. if(is_array($val) && count($val)> 0){
  260. foreach($val as $v){
  261. if(is_object($v) && strtolower(get_class($v)) == 'soapval'){
  262. $tt = $v->type;
  263. } else {
  264. $tt = gettype($v);
  265. }
  266. $array_types[$tt] = 1;
  267. $xml .= $this->serialize_val($v,'item',false,false,false,false,$use);
  268. if(is_array($v) && is_numeric(key($v))){
  269. $i += sizeof($v);
  270. } else {
  271. ++$i;
  272. }
  273. }
  274. if(count($array_types) > 1){
  275. $array_typename = 'xsd:ur-type';
  276. } elseif(isset($tt) && isset($this->typemap[$this->XMLSchemaVersion][$tt])) {
  277. $array_typename = 'xsd:'.$tt;
  278. } elseif($tt == 'array' || $tt == 'Array'){
  279. $array_typename = 'SOAP-ENC:Array';
  280. } else {
  281. $array_typename = $tt;
  282. }
  283. if(isset($array_types['array'])){
  284. $array_type = $i.",".$i;
  285. } else {
  286. $array_type = $i;
  287. }
  288. if ($use == 'literal') {
  289. $xml = "<$name $atts>".$xml."</$name>";
  290. } else {
  291. $xml = "<$name xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"".$array_typename."[$array_type]\"$atts>".$xml."</$name>";
  292. }
  293. // empty array
  294. } else {
  295. if ($use == 'literal') {
  296. $xml = "<$name $atts>".$xml."</$name>";;
  297. } else {
  298. $xml = "<$name xsi:type=\"SOAP-ENC:Array\" $atts>".$xml."</$name>";;
  299. }
  300. }
  301. } else {
  302. // got a struct
  303. if(isset($type) && isset($type_prefix)){
  304. $type_str = " xsi:type=\"$type_prefix:$type\"";
  305. } else {
  306. $type_str = '';
  307. }
  308. if ($use == 'literal') {
  309. $xml .= "<$name$xmlns $atts>";
  310. } else {
  311. $xml .= "<$name$xmlns$type_str$atts>";
  312. }
  313. foreach($val as $k => $v){
  314. $xml .= $this->serialize_val($v,$k,false,false,false,false,$use);
  315. }
  316. $xml .= "</$name>";
  317. }
  318. break;
  319. default:
  320. $xml .= 'not detected, got '.gettype($val).' for '.$val;
  321. break;
  322. }
  323. return $xml;
  324. }
  325. /**
  326. * serialize message
  327. *
  328. * @param string body
  329. * @param string headers
  330. * @param array namespaces
  331. * @param string style
  332. * @return string message
  333. * @access public
  334. */
  335. function serializeEnvelope($body,$headers=false,$namespaces=array(),$style='rpc'){
  336. // serialize namespaces
  337. $ns_string = '';
  338. foreach(array_merge($this->namespaces,$namespaces) as $k => $v){
  339. $ns_string .= " xmlns:$k=\"$v\"";
  340. }
  341. if($style == 'rpc') {
  342. $ns_string = ' SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"' . $ns_string;
  343. }
  344. // serialize headers
  345. if($headers){
  346. $headers = "<SOAP-ENV:Header>".$headers."</SOAP-ENV:Header>";
  347. }
  348. // serialize envelope
  349. return
  350. '<?xml version="1.0" encoding="'.$this->soap_defencoding .'"?'.">".
  351. '<SOAP-ENV:Envelope'.$ns_string.">".
  352. $headers.
  353. "<SOAP-ENV:Body>".
  354. $body.
  355. "</SOAP-ENV:Body>".
  356. "</SOAP-ENV:Envelope>";
  357. }
  358. function formatDump($str){
  359. $str = htmlspecialchars($str);
  360. return nl2br($str);
  361. }
  362. /**
  363. * returns the local part of a prefixed string
  364. * returns the original string, if not prefixed
  365. *
  366. * @param string
  367. * @return string
  368. * @access public
  369. */
  370. function getLocalPart($str){
  371. if($sstr = strrchr($str,':')){
  372. // get unqualified name
  373. return substr( $sstr, 1 );
  374. } else {
  375. return $str;
  376. }
  377. }
  378. /**
  379. * returns the prefix part of a prefixed string
  380. * returns false, if not prefixed
  381. *
  382. * @param string
  383. * @return mixed
  384. * @access public
  385. */
  386. function getPrefix($str){
  387. if($pos = strrpos($str,':')){
  388. // get prefix
  389. return substr($str,0,$pos);
  390. }
  391. return false;
  392. }
  393. function varDump($data) {
  394. ob_start();
  395. var_dump($data);
  396. $ret_val = ob_get_contents();
  397. ob_end_clean();
  398. return $ret_val;
  399. }
  400. }
  401. // XML Schema Datatype Helper Functions
  402. //xsd:dateTime helpers
  403. /**
  404. * convert unix timestamp to ISO 8601 compliant date string
  405. *
  406. * @param string $timestamp Unix time stamp
  407. * @access public
  408. */
  409. function timestamp_to_iso8601($timestamp,$utc=true){
  410. $datestr = date('Y-m-d\TH:i:sO',$timestamp);
  411. if($utc){
  412. $eregStr =
  413. '([0-9]{4})-'. // centuries & years CCYY-
  414. '([0-9]{2})-'. // months MM-
  415. '([0-9]{2})'. // days DD
  416. 'T'. // separator T
  417. '([0-9]{2}):'. // hours hh:
  418. '([0-9]{2}):'. // minutes mm:
  419. '([0-9]{2})(\.[0-9]*)?'. // seconds ss.ss...
  420. '(Z|[+\-][0-9]{2}:?[0-9]{2})?'; // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
  421. if(ereg($eregStr,$datestr,$regs)){
  422. return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ',$regs[1],$regs[2],$regs[3],$regs[4],$regs[5],$regs[6]);
  423. }
  424. return false;
  425. } else {
  426. return $datestr;
  427. }
  428. }
  429. /**
  430. * convert ISO 8601 compliant date string to unix timestamp
  431. *
  432. * @param string $datestr ISO 8601 compliant date string
  433. * @access public
  434. */
  435. function iso8601_to_timestamp($datestr){
  436. $eregStr =
  437. '([0-9]{4})-'. // centuries & years CCYY-
  438. '([0-9]{2})-'. // months MM-
  439. '([0-9]{2})'. // days DD
  440. 'T'. // separator T
  441. '([0-9]{2}):'. // hours hh:
  442. '([0-9]{2}):'. // minutes mm:
  443. '([0-9]{2})(\.[0-9]+)?'. // seconds ss.ss...
  444. '(Z|[+\-][0-9]{2}:?[0-9]{2})?'; // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
  445. if(ereg($eregStr,$datestr,$regs)){
  446. // not utc
  447. if($regs[8] != 'Z'){
  448. $op = substr($regs[8],0,1);
  449. $h = substr($regs[8],1,2);
  450. $m = substr($regs[8],strlen($regs[8])-2,2);
  451. if($op == '-'){
  452. $regs[4] = $regs[4] + $h;
  453. $regs[5] = $regs[5] + $m;
  454. } elseif($op == '+'){
  455. $regs[4] = $regs[4] - $h;
  456. $regs[5] = $regs[5] - $m;
  457. }
  458. }
  459. return strtotime("$regs[1]-$regs[2]-$regs[3] $regs[4]:$regs[5]:$regs[6]Z");
  460. } else {
  461. return false;
  462. }
  463. }
  464. ?><?php
  465. /**
  466. * soap_fault class, allows for creation of faults
  467. * mainly used for returning faults from deployed functions
  468. * in a server instance.
  469. * @author Dietrich Ayala <dietrich@ganx4.com>
  470. * @version v 0.6.3
  471. * @access public
  472. */
  473. class soap_fault extends nusoap_base {
  474. var $faultcode;
  475. var $faultactor;
  476. var $faultstring;
  477. var $faultdetail;
  478. /**
  479. * constructor
  480. *
  481. * @param string $faultcode (client | server)
  482. * @param string $faultactor only used when msg routed between multiple actors
  483. * @param string $faultstring human readable error message
  484. * @param string $faultdetail
  485. */
  486. function soap_fault($faultcode,$faultactor='',$faultstring='',$faultdetail=''){
  487. $this->faultcode = $faultcode;
  488. $this->faultactor = $faultactor;
  489. $this->faultstring = $faultstring;
  490. $this->faultdetail = $faultdetail;
  491. }
  492. /**
  493. * serialize a fault
  494. *
  495. * @access public
  496. */
  497. function serialize(){
  498. $ns_string = '';
  499. foreach($this->namespaces as $k => $v){
  500. $ns_string .= "\n xmlns:$k=\"$v\"";
  501. }
  502. $return_msg =
  503. '<?xml version="1.0"?'.">\n".
  504. '<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"'.$ns_string.">\n".
  505. '<SOAP-ENV:Body>'.
  506. '<SOAP-ENV:Fault>'.
  507. '<faultcode>'.$this->faultcode.'</faultcode>'.
  508. '<faultactor>'.$this->faultactor.'</faultactor>'.
  509. '<faultstring>'.$this->faultstring.'</faultstring>'.
  510. '<detail>'.$this->serialize_val($this->faultdetail).'</detail>'.
  511. '</SOAP-ENV:Fault>'.
  512. '</SOAP-ENV:Body>'.
  513. '</SOAP-ENV:Envelope>';
  514. return $return_msg;
  515. }
  516. }
  517. ?><?php
  518. /**
  519. * parses an XML Schema, allows access to it's data, other utility methods
  520. * no validation... yet.
  521. * very experimental and limited. As is discussed on XML-DEV, I'm one of the people
  522. * that just doesn't have time to read the spec(s) thoroughly, and just have a couple of trusty
  523. * tutorials I refer to :)
  524. *
  525. * @author Dietrich Ayala <dietrich@ganx4.com>
  526. * @version v 0.6.3
  527. * @access public
  528. */
  529. class XMLSchema extends nusoap_base {
  530. // files
  531. var $schema = '';
  532. var $xml = '';
  533. // define internal arrays of bindings, ports, operations, messages, etc.
  534. var $complexTypes = array();
  535. // target namespace
  536. var $schemaTargetNamespace = '';
  537. // parser vars
  538. var $parser;
  539. var $position;
  540. var $depth = 0;
  541. var $depth_array = array();
  542. /**
  543. * constructor
  544. *
  545. * @param string $schema schema document URI
  546. * @param string $xml xml document URI
  547. * @access public
  548. */
  549. function XMLSchema($schema='',$xml=''){
  550. $this->debug('xmlschema class instantiated, inside constructor');
  551. // files
  552. $this->schema = $schema;
  553. $this->xml = $xml;
  554. // parse schema file
  555. if($schema != ''){
  556. $this->debug('initial schema file: '.$schema);
  557. $this->parseFile($schema);
  558. }
  559. // parse xml file
  560. if($xml != ''){
  561. $this->debug('initial xml file: '.$xml);
  562. $this->parseFile($xml);
  563. }
  564. }
  565. /**
  566. * parse an XML file
  567. *
  568. * @param string $xml, path/URL to XML file
  569. * @param string $type, (schema | xml)
  570. * @return boolean
  571. * @access public
  572. */
  573. function parseFile($xml,$type){
  574. // parse xml file
  575. if($xml != ""){
  576. $this->debug('parsing $xml');
  577. $xmlStr = @join("",@file($xml));
  578. if($xmlStr == ""){
  579. $this->setError('No file at the specified URL: '.$xml);
  580. return false;
  581. } else {
  582. $this->parseString($xmlStr,$type);
  583. return true;
  584. }
  585. }
  586. return false;
  587. }
  588. /**
  589. * parse an XML string
  590. *
  591. * @param string $xml path or URL
  592. * @param string $type, (schema|xml)
  593. * @access private
  594. */
  595. function parseString($xml,$type){
  596. // parse xml string
  597. if($xml != ""){
  598. // Create an XML parser.
  599. $this->parser = xml_parser_create();
  600. // Set the options for parsing the XML data.
  601. xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
  602. // Set the object for the parser.
  603. xml_set_object($this->parser, $this);
  604. // Set the element handlers for the parser.
  605. if($type == "schema"){
  606. xml_set_element_handler($this->parser, 'schemaStartElement','schemaEndElement');
  607. xml_set_character_data_handler($this->parser,'schemaCharacterData');
  608. } elseif($type == "xml"){
  609. xml_set_element_handler($this->parser, 'xmlStartElement','xmlEndElement');
  610. xml_set_character_data_handler($this->parser,'xmlCharacterData');
  611. }
  612. // Parse the XML file.
  613. if(!xml_parse($this->parser,$xml,true)){
  614. // Display an error message.
  615. $errstr = sprintf('XML error on line %d: %s',
  616. xml_get_current_line_number($this->parser),
  617. xml_error_string(xml_get_error_code($this->parser))
  618. );
  619. $this->debug('XML parse error: '.$errstr);
  620. $this->setError('Parser error: '.$errstr);
  621. }
  622. xml_parser_free($this->parser);
  623. } else{
  624. $this->debug('no xml passed to parseString()!!');
  625. $this->setError('no xml passed to parseString()!!');
  626. }
  627. }
  628. /**
  629. * start-element handler
  630. *
  631. * @param string $parser XML parser object
  632. * @param string $name element name
  633. * @param string $attrs associative array of attributes
  634. * @access private
  635. */
  636. function schemaStartElement($parser, $name, $attrs) {
  637. // position in the total number of elements, starting from 0
  638. $pos = $this->position++;
  639. $depth = $this->depth++;
  640. // set self as current value for this depth
  641. $this->depth_array[$depth] = $pos;
  642. // get element prefix
  643. if($prefix = $this->getPrefix($name)){
  644. // get unqualified name
  645. $name = $this->getLocalPart($name);
  646. } else {
  647. $prefix = '';
  648. }
  649. // loop thru attributes, expanding, and registering namespace declarations
  650. if(count($attrs) > 0){
  651. foreach($attrs as $k => $v){
  652. // if ns declarations, add to class level array of valid namespaces
  653. if(ereg("^xmlns",$k)){
  654. //$this->xdebug("$k: $v");
  655. //$this->xdebug('ns_prefix: '.$this->getPrefix($k));
  656. if($ns_prefix = substr(strrchr($k,':'),1)){
  657. $this->namespaces[$ns_prefix] = $v;
  658. } else {
  659. $this->namespaces['ns'.(count($this->namespaces)+1)] = $v;
  660. }
  661. if($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema'){
  662. $this->XMLSchemaVersion = $v;
  663. $this->namespaces['xsi'] = $v.'-instance';
  664. }
  665. }
  666. }
  667. foreach($attrs as $k => $v) {
  668. // expand each attribute
  669. $k = strpos($k,':') ? $this->expandQname($k) : $k;
  670. $v = strpos($v,':') ? $this->expandQname($v) : $v;
  671. $eAttrs[$k] = $v;
  672. }
  673. $attrs = $eAttrs;
  674. } else {
  675. $attrs = array();
  676. }
  677. // find status, register data
  678. switch($name) {
  679. case ('all'|'choice'|'sequence'):
  680. //$this->complexTypes[$this->currentComplexType]['compositor'] = 'all';
  681. $this->complexTypes[$this->currentComplexType]['compositor'] = $name;
  682. if($name == 'all') {
  683. $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
  684. }
  685. break;
  686. case 'attribute':
  687. //$this->xdebug("parsing attribute $attrs[name] $attrs[ref] of value: ".$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']);
  688. if(isset($attrs['name'])){
  689. $this->attributes[$attrs['name']] = $attrs;
  690. $aname = $attrs['name'];
  691. } elseif(isset($attrs['ref']) && $attrs['ref'] == 'http://schemas.xmlsoap.org/soap/encoding/:arrayType'){
  692. $aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
  693. } elseif(isset($attrs['ref'])){
  694. $aname = $attrs['ref'];
  695. $this->attributes[$attrs['ref']] = $attrs;
  696. }
  697. if(isset($this->currentComplexType)){
  698. $this->complexTypes[$this->currentComplexType]['attrs'][$aname] = $attrs;
  699. } elseif(isset($this->currentElement)){
  700. $this->elements[$this->currentElement]['attrs'][$aname] = $attrs;
  701. }
  702. // arrayType attribute
  703. if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || $this->getLocalPart($aname) == 'arrayType'){
  704. $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
  705. $prefix = $this->getPrefix($aname);
  706. if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])){
  707. $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
  708. } else {
  709. $v = '';
  710. }
  711. if(strpos($v,'[,]')){
  712. $this->complexTypes[$this->currentComplexType]['multidimensional'] = true;
  713. }
  714. $v = substr($v,0,strpos($v,'[')); // clip the []
  715. if(!strpos($v,':') && isset($this->typemap[$this->XMLSchemaVersion][$v])){
  716. $v = $this->XMLSchemaVersion.':'.$v;
  717. }
  718. $this->complexTypes[$this->currentComplexType]['arrayType'] = $v;
  719. }
  720. break;
  721. case 'complexType':
  722. if(isset($attrs['name'])){
  723. $this->currentElement = false;
  724. $this->currentComplexType = $attrs['name'];
  725. $this->complexTypes[$this->currentComplexType] = $attrs;
  726. $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType';
  727. if(isset($attrs['base']) && ereg(':Array$',$attrs['base'])){
  728. $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
  729. } else {
  730. $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
  731. }
  732. $this->xdebug('processing complexType '.$attrs['name']);
  733. }
  734. break;
  735. case 'element':
  736. if(isset($attrs['type'])){
  737. $this->xdebug("processing element ".$attrs['name']);
  738. $this->currentElement = $attrs['name'];
  739. $this->elements[ $attrs['name'] ] = $attrs;
  740. $this->elements[ $attrs['name'] ]['typeClass'] = 'element';
  741. $ename = $attrs['name'];
  742. } elseif(isset($attrs['ref'])){
  743. $ename = $attrs['ref'];
  744. } else {
  745. $this->xdebug('adding complexType '.$attrs['name']);
  746. $this->currentComplexType = $attrs['name'];
  747. $this->complexTypes[ $attrs['name'] ] = $attrs;
  748. $this->complexTypes[ $attrs['name'] ]['element'] = 1;
  749. $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
  750. }
  751. if(isset($ename) && $this->currentComplexType){
  752. $this->complexTypes[$this->currentComplexType]['elements'][$ename] = $attrs;
  753. }
  754. break;
  755. case 'restriction':
  756. $this->xdebug("in restriction for ct: $this->currentComplexType and ce: $this->currentElement");
  757. if($this->currentElement){
  758. $this->elements[$this->currentElement]['type'] = $attrs['base'];
  759. } elseif($this->currentComplexType){
  760. $this->complexTypes[$this->currentComplexType]['restrictionBase'] = $attrs['base'];
  761. if(strstr($attrs['base'],':') == ':Array'){
  762. $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
  763. }
  764. }
  765. break;
  766. case 'schema':
  767. $this->schema = $attrs;
  768. $this->schema['schemaVersion'] = $this->getNamespaceFromPrefix($prefix);
  769. break;
  770. case 'simpleType':
  771. $this->currentElement = $attrs['name'];
  772. $this->elements[ $attrs['name'] ] = $attrs;
  773. $this->elements[ $attrs['name'] ]['typeClass'] = 'element';
  774. break;
  775. }
  776. }
  777. /**
  778. * end-element handler
  779. *
  780. * @param string $parser XML parser object
  781. * @param string $name element name
  782. * @access private
  783. */
  784. function schemaEndElement($parser, $name) {
  785. // position of current element is equal to the last value left in depth_array for my depth
  786. if(isset($this->depth_array[$this->depth])){
  787. $pos = $this->depth_array[$this->depth];
  788. }
  789. // bring depth down a notch
  790. $this->depth--;
  791. // move on...
  792. if($name == 'complexType'){
  793. $this->currentComplexType = false;
  794. $this->currentElement = false;
  795. }
  796. if($name == 'element'){
  797. $this->currentElement = false;
  798. }
  799. }
  800. /**
  801. * element content handler
  802. *
  803. * @param string $parser XML parser object
  804. * @param string $data element content
  805. * @access private
  806. */
  807. function schemaCharacterData($parser, $data){
  808. $pos = $this->depth_array[$this->depth];
  809. $this->message[$pos]['cdata'] .= $data;
  810. }
  811. /**
  812. * serialize the schema
  813. *
  814. * @access public
  815. */
  816. function serializeSchema(){
  817. $schemaPrefix = $this->getPrefixFromNamespace($this->XMLSchemaVersion);
  818. $xml = '';
  819. // complex types
  820. foreach($this->complexTypes as $typeName => $attrs){
  821. $contentStr = '';
  822. // serialize child elements
  823. if(count($attrs['elements']) > 0){
  824. foreach($attrs['elements'] as $element => $eParts){
  825. if(isset($eParts['ref'])){
  826. $contentStr .= "<element ref=\"$element\"/>";
  827. } else {
  828. $contentStr .= "<element name=\"$element\" type=\"$eParts[type]\"/>";
  829. }
  830. }
  831. }
  832. // attributes
  833. if(count($attrs['attrs']) >= 1){
  834. foreach($attrs['attrs'] as $attr => $aParts){
  835. $contentStr .= '<attribute ref="'.$aParts['ref'].'"';
  836. if(isset($aParts['wsdl:arrayType'])){
  837. $contentStr .= ' wsdl:arrayType="'.$aParts['wsdl:arrayType'].'"';
  838. }
  839. $contentStr .= '/>';
  840. }
  841. }
  842. // if restriction
  843. if( isset($attrs['restrictionBase']) && $attrs['restrictionBase'] != ''){
  844. $contentStr = "<$schemaPrefix:restriction base=\"".$attrs['restrictionBase']."\">".$contentStr."</$schemaPrefix:restriction>";
  845. }
  846. // "all" compositor obviates complex/simple content
  847. if(isset($attrs['compositor']) && $attrs['compositor'] == 'all'){
  848. $contentStr = "<$schemaPrefix:$attrs[compositor]>".$contentStr."</$schemaPrefix:$attrs[compositor]>";
  849. }
  850. // complex or simple content
  851. elseif( count($attrs['elements']) > 0 || count($attrs['attrs']) > 0){
  852. $contentStr = "<$schemaPrefix:complexContent>".$contentStr."</$schemaPrefix:complexContent>";
  853. }
  854. // compositors
  855. if(isset($attrs['compositor']) && $attrs['compositor'] != '' && $attrs['compositor'] != 'all'){
  856. $contentStr = "<$schemaPrefix:$attrs[compositor]>".$contentStr."</$schemaPrefix:$attrs[compositor]>";
  857. }
  858. // finalize complex type
  859. if($contentStr != ''){
  860. $contentStr = "<$schemaPrefix:complexType name=\"$typeName\">".$contentStr."</$schemaPrefix:complexType>";
  861. } else {
  862. $contentStr = "<$schemaPrefix:complexType name=\"$typeName\"/>";
  863. }
  864. $xml .= $contentStr;
  865. }
  866. // elements
  867. if(isset($this->elements) && count($this->elements) > 0){
  868. foreach($this->elements as $element => $eParts){
  869. $xml .= "<$schemaPrefix:element name=\"$element\" type=\"".$eParts['type']."\"/>";
  870. }
  871. }
  872. // attributes
  873. if(isset($this->attributes) && count($this->attributes) > 0){
  874. foreach($this->attributes as $attr => $aParts){
  875. $xml .= "<$schemaPrefix:attribute name=\"$attr\" type=\"".$aParts['type']."\"/>";
  876. }
  877. }
  878. // finish 'er up
  879. $xml = "<$schemaPrefix:schema xmlns=\"$this->XMLSchemaVersion\" targetNamespace=\"$this->schemaTargetNamespace\">".$xml."</$schemaPrefix:schema>";
  880. return $xml;
  881. }
  882. /**
  883. * expands a qualified name
  884. *
  885. * @param string $string qname
  886. * @return string expanded qname
  887. * @access private
  888. */
  889. function expandQname($qname){
  890. // get element prefix
  891. if(strpos($qname,':') && !ereg('^http://',$qname)){
  892. // get unqualified name
  893. $name = substr(strstr($qname,':'),1);
  894. // get ns prefix
  895. $prefix = substr($qname,0,strpos($qname,':'));
  896. if(isset($this->namespaces[$prefix])){
  897. return $this->namespaces[$prefix].':'.$name;
  898. } else {
  899. return $qname;
  900. }
  901. } else {
  902. return $qname;
  903. }
  904. }
  905. /**
  906. * adds debug data to the clas level debug string
  907. *
  908. * @param string $string debug data
  909. * @access private
  910. */
  911. function xdebug($string){
  912. $this->debug(' xmlschema: '.$string);
  913. }
  914. /**
  915. * get the PHP type of a user defined type in the schema
  916. * PHP type is kind of a misnomer since it actually returns 'struct' for assoc. arrays
  917. * returns false if no type exists, or not w/ the given namespace
  918. * else returns a string that is either a native php type, or 'struct'
  919. *
  920. * @param string $type, name of defined type
  921. * @param string $ns, namespace of type
  922. * @return mixed
  923. * @access public
  924. */
  925. function getPHPType($type,$ns){
  926. global $typemap;
  927. if(isset($typemap[$ns][$type])){
  928. //print "found type '$type' and ns $ns in typemap<br>";
  929. return $typemap[$ns][$type];
  930. } elseif(isset($this->complexTypes[$type])){
  931. //print "getting type '$type' and ns $ns from complexTypes array<br>";
  932. return $this->complexTypes[$type]['phpType'];
  933. }
  934. return false;
  935. }
  936. /**
  937. * returns the local part of a prefixed string
  938. * returns the original string, if not prefixed
  939. *
  940. * @param string
  941. * @return string
  942. * @access public
  943. */
  944. function getLocalPart($str){
  945. if($sstr = strrchr($str,':')){
  946. // get unqualified name
  947. return substr( $sstr, 1 );
  948. } else {
  949. return $str;
  950. }
  951. }
  952. /**
  953. * returns the prefix part of a prefixed string
  954. * returns false, if not prefixed
  955. *
  956. * @param string
  957. * @return mixed
  958. * @access public
  959. */
  960. function getPrefix($str){
  961. if($pos = strrpos($str,':')){
  962. // get prefix
  963. return substr($str,0,$pos);
  964. }
  965. return false;
  966. }
  967. /**
  968. * pass it a prefix, it returns a namespace
  969. * returns false if no namespace registered with the given prefix
  970. *
  971. * @param string
  972. * @return mixed
  973. * @access public
  974. */
  975. function getNamespaceFromPrefix($prefix){
  976. if(isset($this->namespaces[$prefix])){
  977. return $this->namespaces[$prefix];
  978. }
  979. //$this->setError("No namespace registered for prefix '$prefix'");
  980. return false;
  981. }
  982. /**
  983. * returns the prefix for a given namespace (or prefix)
  984. * or false if no prefixes registered for the given namespace
  985. *
  986. * @param string
  987. * @return mixed
  988. * @access public
  989. */
  990. function getPrefixFromNamespace($ns){
  991. foreach($this->namespaces as $p => $n){
  992. if($ns == $n || $ns == $p){
  993. $this->usedNamespaces[$p] = $n;
  994. return $p;
  995. }
  996. }
  997. return false;
  998. }
  999. /**
  1000. * returns an array of information about a given type
  1001. * returns false if no type exists by the given name
  1002. *
  1003. * typeDef = array(
  1004. * 'elements' => array(), // refs to elements array
  1005. * 'restrictionBase' => '',
  1006. * 'phpType' => '',
  1007. * 'order' => '(sequence|all)',
  1008. * 'attrs' => array() // refs to attributes array
  1009. * )
  1010. *
  1011. * @param string
  1012. * @return mixed
  1013. * @access public
  1014. */
  1015. function getTypeDef($type){
  1016. if(isset($this->complexTypes[$type])){
  1017. return $this->complexTypes[$type];
  1018. } elseif(isset($this->elements[$type])){
  1019. return $this->elements[$type];
  1020. } elseif(isset($this->attributes[$type])){
  1021. return $this->attributes[$type];
  1022. }
  1023. return false;
  1024. }
  1025. /**
  1026. * returns a sample serialization of a given type, or false if no type by the given name
  1027. *
  1028. * @param string $type, name of type
  1029. * @return mixed
  1030. * @access public
  1031. */
  1032. function serializeTypeDef($type){
  1033. //print "in sTD() for type $type<br>";
  1034. if($typeDef = $this->getTypeDef($type)){
  1035. $str .= '<'.$type;
  1036. if(is_array($typeDef['attrs'])){
  1037. foreach($attrs as $attName => $data){
  1038. $str .= " $attName=\"{type = ".$data['type']."}\"";
  1039. }
  1040. }
  1041. $str .= " xmlns=\"".$this->schema['targetNamespace']."\"";
  1042. if(count($typeDef['elements']) > 0){
  1043. $str .= ">";
  1044. foreach($typeDef['elements'] as $element => $eData){
  1045. $str .= $this->serializeTypeDef($element);
  1046. }
  1047. $str .= "</$type>";
  1048. } elseif($typeDef['typeClass'] == 'element') {
  1049. $str .= "></$type>";
  1050. } else {
  1051. $str .= "/>";
  1052. }
  1053. return $str;
  1054. }
  1055. return false;
  1056. }
  1057. /**
  1058. * returns HTML form elements that allow a user
  1059. * to enter values for creating an instance of the given type.
  1060. *
  1061. * @param string $name, name for type instance
  1062. * @param string $type, name of type
  1063. * @return string
  1064. * @access public
  1065. */
  1066. function typeToForm($name,$type){
  1067. // get typedef
  1068. if($typeDef = $this->getTypeDef($type)){
  1069. // if struct
  1070. if($typeDef['phpType'] == 'struct'){
  1071. $buffer .= '<table>';
  1072. foreach($typeDef['elements'] as $child => $childDef){
  1073. $buffer .= "<tr><td align='right'>$childDef[name] (type: ".$this->getLocalPart($childDef['type'])."):</td>".
  1074. "<td><input type='text' name='parameters[".$name."][$childDef[name]]'></td></tr>";
  1075. }
  1076. $buffer .= '</table>';
  1077. // if array
  1078. } elseif($typeDef['phpType'] == 'array'){
  1079. $buffer .= '<table>';
  1080. for($i=0;$i < 3; $i++){
  1081. $buffer .= "<tr><td align='right'>array item (type: $typeDef[arrayType]):</td>".
  1082. "<td><input type='text' name='parameters[".$name."][]'></td></tr>";
  1083. }
  1084. $buffer .= '</table>';
  1085. // if scalar
  1086. } else {
  1087. $buffer .= "<input type='text' name='parameters[$name]'>";
  1088. }
  1089. } else {
  1090. $buffer .= "<input type='text' name='parameters[$name]'>";
  1091. }
  1092. return $buffer;
  1093. }
  1094. /**
  1095. * adds an XML Schema complex type to the WSDL types
  1096. *
  1097. * example: array
  1098. *
  1099. * addType(
  1100. * 'ArrayOfstring',
  1101. * 'complexType',
  1102. * 'array',
  1103. * '',
  1104. * 'SOAP-ENC:Array',
  1105. * array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]'),
  1106. * 'xsd:string'
  1107. * );
  1108. *
  1109. * example: PHP associative array ( SOAP Struct )
  1110. *
  1111. * addType(
  1112. * 'SOAPStruct',
  1113. * 'complexType',
  1114. * 'struct',
  1115. * 'all',
  1116. * array('myVar'=> array('name'=>'myVar','type'=>'string')
  1117. * );
  1118. *
  1119. * @param name
  1120. * @param typeClass (complexType|simpleType|attribute)
  1121. * @param phpType: currently supported are array and struct (php assoc array)
  1122. * @param compositor (all|sequence|choice)
  1123. * @param restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
  1124. * @param elements = array ( name = array(name=>'',type=>'') )
  1125. * @param attrs = array(
  1126. * array(
  1127. * 'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType",
  1128. * "http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]"
  1129. * )
  1130. * )
  1131. * @param arrayType: namespace:name (http://www.w3.org/2001/XMLSchema:string)
  1132. *
  1133. */
  1134. function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType=''){
  1135. $this->complexTypes[$name] = array(
  1136. 'name' => $name,
  1137. 'typeClass' => $typeClass,
  1138. 'phpType' => $phpType,
  1139. 'compositor'=> $compositor,
  1140. 'restrictionBase' => $restrictionBase,
  1141. 'elements' => $elements,
  1142. 'attrs' => $attrs,
  1143. 'arrayType' => $arrayType
  1144. );
  1145. }
  1146. }
  1147. ?><?php
  1148. /**
  1149. * for creating serializable abstractions of native PHP types
  1150. * NOTE: this is only really used when WSDL is not available.
  1151. *
  1152. * @author Dietrich Ayala <dietrich@ganx4.com>
  1153. * @version v 0.6.3
  1154. * @access public
  1155. */
  1156. class soapval extends nusoap_base {
  1157. /**
  1158. * constructor
  1159. *
  1160. * @param string $name optional name
  1161. * @param string $type optional type name
  1162. * @param mixed $value optional value
  1163. * @param string $namespace optional namespace of value
  1164. * @param string $type_namespace optional namespace of type
  1165. * @param array $attributes associative array of attributes to add to element serialization
  1166. * @access public
  1167. */
  1168. function soapval($name='soapval',$type=false,$value=-1,$element_ns=false,$type_ns=false,$attributes=false) {
  1169. $this->name = $name;
  1170. $this->value = $value;
  1171. $this->type = $type;
  1172. $this->element_ns = $element_ns;
  1173. $this->type_ns = $type_ns;
  1174. $this->attributes = $attributes;
  1175. }
  1176. /**
  1177. * return serialized value
  1178. *
  1179. * @return string XML data
  1180. * @access private
  1181. */
  1182. function serialize($use='encoded') {
  1183. return $this->serialize_val($this->value,$this->name,$this->type,$this->element_ns,$this->type_ns,$this->attributes,$use);
  1184. }
  1185. /**
  1186. * decodes a soapval object into a PHP native type
  1187. *
  1188. * @param object $soapval optional SOAPx4 soapval object, else uses self
  1189. * @return mixed
  1190. * @access public
  1191. */
  1192. function decode(){
  1193. return $this->value;
  1194. }
  1195. }
  1196. ?><?php
  1197. /**
  1198. * transport class for sending/receiving data via HTTP and HTTPS
  1199. * NOTE: PHP must be compiled with the CURL extension for HTTPS support
  1200. *
  1201. * @author Dietrich Ayala <dietrich@ganx4.com>
  1202. * @version v 0.6.3
  1203. * @access public
  1204. */
  1205. class soap_transport_http extends nusoap_base {
  1206. var $username = '';
  1207. var $password = '';
  1208. var $url = '';
  1209. var $proxyhost = '';
  1210. var $proxyport = '';
  1211. var $scheme = '';
  1212. var $request_method = 'POST';
  1213. var $protocol_version = '1.0';
  1214. var $encoding = '';
  1215. var $outgoing_headers = array();
  1216. var $incoming_headers = array();
  1217. var $outgoing_payload = '';
  1218. var $incoming_payload = '';
  1219. var $useSOAPAction = true;
  1220. /**
  1221. * constructor
  1222. */
  1223. function soap_transport_http($url){
  1224. $this->url = $url;
  1225. $u = parse_url($url);
  1226. foreach($u as $k => $v){
  1227. $this->debug("$k = $v");
  1228. $this->$k = $v;
  1229. }
  1230. if(isset($u['query']) && $u['query'] != ''){
  1231. $this->path .= '?' . $u['query'];
  1232. }
  1233. if(!isset($u['port']) && $u['scheme'] == 'http'){
  1234. $this->port = 80;
  1235. }
  1236. }
  1237. function connect($timeout){
  1238. // proxy
  1239. if($this->proxyhost != '' && $this->proxyport != ''){
  1240. $host = $this->proxyhost;
  1241. $port = $this->proxyport;
  1242. $this->debug("using http proxy: $host, $port");
  1243. } else {
  1244. $host = $this->host;
  1245. $port = $this->port;
  1246. }
  1247. // ssl
  1248. if($this->scheme == 'https'){
  1249. $host = 'ssl://'.$host;
  1250. $port = 443;
  1251. }
  1252. $this->debug("connection params: $host, $port");
  1253. // timeout
  1254. if($timeout > 0){
  1255. $fp = fsockopen($host, $port, $this->errno, $this->error_str, $timeout);
  1256. } else {
  1257. $fp = fsockopen($host, $port, $this->errno, $this->error_str);
  1258. }
  1259. // test pointer
  1260. if(!$fp) {
  1261. $this->debug('Couldn\'t open socket connection to server '.$this->url.', Error: '.$this->error_str);
  1262. $this->setError('Couldn\'t open socket connection to server: '.$this->url.', Error: '.$this->error_str);
  1263. return false;
  1264. }
  1265. return $fp;
  1266. }
  1267. /**
  1268. * send the SOAP message via HTTP
  1269. *
  1270. * @param string $data message data
  1271. * @param integer $timeout set timeout in seconds
  1272. * @return string data
  1273. * @access public
  1274. */
  1275. function send($data, $timeout=0) {
  1276. $this->debug('entered send() with data of length: '.strlen($data));
  1277. // get connnection
  1278. if(!$fp = $this->connect($timeout)){
  1279. return false;
  1280. }
  1281. $this->debug('socket connected');
  1282. // start building outgoing payload:
  1283. // swap url for path if going through a proxy
  1284. if($this->proxyhost != '' && $this->proxyport != ''){
  1285. $this->outgoing_payload = "$this->request_method $this->url ".strtoupper($this->scheme)."/$this->protocol_version\r\n";
  1286. } else {
  1287. $this->outgoing_payload = "$this->request_method $this->path ".strtoupper($this->scheme)."/$this->protocol_version\r\n";
  1288. }
  1289. // make payload
  1290. $this->outgoing_payload .=
  1291. "User-Agent: $this->title/$this->version\r\n".
  1292. "Host: ".$this->host."\r\n";
  1293. // http auth
  1294. $credentials = '';
  1295. if($this->username != '') {
  1296. $this->debug('setting http auth credentials');
  1297. $this->outgoing_payload .= 'Authorization: Basic '.base64_encode("$this->username:$this->password")."\r\n";
  1298. }
  1299. // set content type
  1300. $this->outgoing_payload .= 'Content-Type: text/xml; charset='.$this->soap_defencoding."\r\nContent-Length: ".strlen($data)."\r\n";
  1301. // http encoding
  1302. if($this->encoding != '' && function_exists('gzdeflate')){
  1303. $this->outgoing_payload .= "Accept-Encoding: $this->encoding\r\n".
  1304. "Connection: close\r\n";
  1305. set_magic_quotes_runtime(0);
  1306. }
  1307. // set soapaction
  1308. if($this->useSOAPAction){
  1309. $this->outgoing_payload .= "SOAPAction: \"$this->soapaction\""."\r\n";
  1310. }
  1311. $this->outgoing_payload .= "\r\n";
  1312. // add data
  1313. $this->outgoing_payload .= $data;
  1314. // send payload
  1315. if(!fputs($fp, $this->outgoing_payload, strlen($this->outgoing_payload))) {
  1316. $this->setError('couldn\'t write message data to socket');

Large files files are truncated, but you can click here to view the full file