@@ -16,189 +16,189 @@ |
||
16 | 16 | * @access public |
17 | 17 | */ |
18 | 18 | class nusoap_wsdlcache { |
19 | - /** |
|
20 | - * @var resource |
|
21 | - * @access private |
|
22 | - */ |
|
23 | - var $fplock; |
|
24 | - /** |
|
25 | - * @var integer |
|
26 | - * @access private |
|
27 | - */ |
|
28 | - var $cache_lifetime; |
|
29 | - /** |
|
30 | - * @var string |
|
31 | - * @access private |
|
32 | - */ |
|
33 | - var $cache_dir; |
|
34 | - /** |
|
35 | - * @var string |
|
36 | - * @access public |
|
37 | - */ |
|
38 | - var $debug_str = ''; |
|
19 | + /** |
|
20 | + * @var resource |
|
21 | + * @access private |
|
22 | + */ |
|
23 | + var $fplock; |
|
24 | + /** |
|
25 | + * @var integer |
|
26 | + * @access private |
|
27 | + */ |
|
28 | + var $cache_lifetime; |
|
29 | + /** |
|
30 | + * @var string |
|
31 | + * @access private |
|
32 | + */ |
|
33 | + var $cache_dir; |
|
34 | + /** |
|
35 | + * @var string |
|
36 | + * @access public |
|
37 | + */ |
|
38 | + var $debug_str = ''; |
|
39 | 39 | |
40 | - /** |
|
41 | - * constructor |
|
42 | - * |
|
43 | - * @param string $cache_dir directory for cache-files |
|
44 | - * @param integer $cache_lifetime lifetime for caching-files in seconds or 0 for unlimited |
|
45 | - * @access public |
|
46 | - */ |
|
47 | - function nusoap_wsdlcache($cache_dir='.', $cache_lifetime=0) { |
|
48 | - $this->fplock = array(); |
|
49 | - $this->cache_dir = $cache_dir != '' ? $cache_dir : '.'; |
|
50 | - $this->cache_lifetime = $cache_lifetime; |
|
51 | - } |
|
40 | + /** |
|
41 | + * constructor |
|
42 | + * |
|
43 | + * @param string $cache_dir directory for cache-files |
|
44 | + * @param integer $cache_lifetime lifetime for caching-files in seconds or 0 for unlimited |
|
45 | + * @access public |
|
46 | + */ |
|
47 | + function nusoap_wsdlcache($cache_dir='.', $cache_lifetime=0) { |
|
48 | + $this->fplock = array(); |
|
49 | + $this->cache_dir = $cache_dir != '' ? $cache_dir : '.'; |
|
50 | + $this->cache_lifetime = $cache_lifetime; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * creates the filename used to cache a wsdl instance |
|
55 | - * |
|
56 | - * @param string $wsdl The URL of the wsdl instance |
|
57 | - * @return string The filename used to cache the instance |
|
58 | - * @access private |
|
59 | - */ |
|
60 | - function createFilename($wsdl) { |
|
61 | - return $this->cache_dir.'/wsdlcache-' . md5($wsdl); |
|
62 | - } |
|
53 | + /** |
|
54 | + * creates the filename used to cache a wsdl instance |
|
55 | + * |
|
56 | + * @param string $wsdl The URL of the wsdl instance |
|
57 | + * @return string The filename used to cache the instance |
|
58 | + * @access private |
|
59 | + */ |
|
60 | + function createFilename($wsdl) { |
|
61 | + return $this->cache_dir.'/wsdlcache-' . md5($wsdl); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * adds debug data to the class level debug string |
|
66 | - * |
|
67 | - * @param string $string debug data |
|
68 | - * @access private |
|
69 | - */ |
|
70 | - function debug($string){ |
|
71 | - $this->debug_str .= get_class($this).": $string\n"; |
|
72 | - } |
|
64 | + /** |
|
65 | + * adds debug data to the class level debug string |
|
66 | + * |
|
67 | + * @param string $string debug data |
|
68 | + * @access private |
|
69 | + */ |
|
70 | + function debug($string){ |
|
71 | + $this->debug_str .= get_class($this).": $string\n"; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * gets a wsdl instance from the cache |
|
76 | - * |
|
77 | - * @param string $wsdl The URL of the wsdl instance |
|
78 | - * @return object wsdl The cached wsdl instance, null if the instance is not in the cache |
|
79 | - * @access public |
|
80 | - */ |
|
81 | - function get($wsdl) { |
|
82 | - $filename = $this->createFilename($wsdl); |
|
83 | - if ($this->obtainMutex($filename, "r")) { |
|
84 | - // check for expired WSDL that must be removed from the cache |
|
85 | - if ($this->cache_lifetime > 0) { |
|
86 | - if (file_exists($filename) && (time() - filemtime($filename) > $this->cache_lifetime)) { |
|
87 | - unlink($filename); |
|
88 | - $this->debug("Expired $wsdl ($filename) from cache"); |
|
89 | - $this->releaseMutex($filename); |
|
90 | - return null; |
|
91 | - } |
|
92 | - } |
|
93 | - // see what there is to return |
|
94 | - if (!file_exists($filename)) { |
|
95 | - $this->debug("$wsdl ($filename) not in cache (1)"); |
|
96 | - $this->releaseMutex($filename); |
|
97 | - return null; |
|
98 | - } |
|
99 | - $fp = @fopen($filename, "r"); |
|
100 | - if ($fp) { |
|
101 | - $s = implode("", @file($filename)); |
|
102 | - fclose($fp); |
|
103 | - $this->debug("Got $wsdl ($filename) from cache"); |
|
104 | - } else { |
|
105 | - $s = null; |
|
106 | - $this->debug("$wsdl ($filename) not in cache (2)"); |
|
107 | - } |
|
108 | - $this->releaseMutex($filename); |
|
109 | - return (!is_null($s)) ? unserialize($s) : null; |
|
110 | - } else { |
|
111 | - $this->debug("Unable to obtain mutex for $filename in get"); |
|
112 | - } |
|
113 | - return null; |
|
114 | - } |
|
74 | + /** |
|
75 | + * gets a wsdl instance from the cache |
|
76 | + * |
|
77 | + * @param string $wsdl The URL of the wsdl instance |
|
78 | + * @return object wsdl The cached wsdl instance, null if the instance is not in the cache |
|
79 | + * @access public |
|
80 | + */ |
|
81 | + function get($wsdl) { |
|
82 | + $filename = $this->createFilename($wsdl); |
|
83 | + if ($this->obtainMutex($filename, "r")) { |
|
84 | + // check for expired WSDL that must be removed from the cache |
|
85 | + if ($this->cache_lifetime > 0) { |
|
86 | + if (file_exists($filename) && (time() - filemtime($filename) > $this->cache_lifetime)) { |
|
87 | + unlink($filename); |
|
88 | + $this->debug("Expired $wsdl ($filename) from cache"); |
|
89 | + $this->releaseMutex($filename); |
|
90 | + return null; |
|
91 | + } |
|
92 | + } |
|
93 | + // see what there is to return |
|
94 | + if (!file_exists($filename)) { |
|
95 | + $this->debug("$wsdl ($filename) not in cache (1)"); |
|
96 | + $this->releaseMutex($filename); |
|
97 | + return null; |
|
98 | + } |
|
99 | + $fp = @fopen($filename, "r"); |
|
100 | + if ($fp) { |
|
101 | + $s = implode("", @file($filename)); |
|
102 | + fclose($fp); |
|
103 | + $this->debug("Got $wsdl ($filename) from cache"); |
|
104 | + } else { |
|
105 | + $s = null; |
|
106 | + $this->debug("$wsdl ($filename) not in cache (2)"); |
|
107 | + } |
|
108 | + $this->releaseMutex($filename); |
|
109 | + return (!is_null($s)) ? unserialize($s) : null; |
|
110 | + } else { |
|
111 | + $this->debug("Unable to obtain mutex for $filename in get"); |
|
112 | + } |
|
113 | + return null; |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * obtains the local mutex |
|
118 | - * |
|
119 | - * @param string $filename The Filename of the Cache to lock |
|
120 | - * @param string $mode The open-mode ("r" or "w") or the file - affects lock-mode |
|
121 | - * @return boolean Lock successfully obtained ?! |
|
122 | - * @access private |
|
123 | - */ |
|
124 | - function obtainMutex($filename, $mode) { |
|
125 | - if (isset($this->fplock[md5($filename)])) { |
|
126 | - $this->debug("Lock for $filename already exists"); |
|
127 | - return false; |
|
128 | - } |
|
129 | - $this->fplock[md5($filename)] = fopen($filename.".lock", "w"); |
|
130 | - if ($mode == "r") { |
|
131 | - return flock($this->fplock[md5($filename)], LOCK_SH); |
|
132 | - } else { |
|
133 | - return flock($this->fplock[md5($filename)], LOCK_EX); |
|
134 | - } |
|
135 | - } |
|
116 | + /** |
|
117 | + * obtains the local mutex |
|
118 | + * |
|
119 | + * @param string $filename The Filename of the Cache to lock |
|
120 | + * @param string $mode The open-mode ("r" or "w") or the file - affects lock-mode |
|
121 | + * @return boolean Lock successfully obtained ?! |
|
122 | + * @access private |
|
123 | + */ |
|
124 | + function obtainMutex($filename, $mode) { |
|
125 | + if (isset($this->fplock[md5($filename)])) { |
|
126 | + $this->debug("Lock for $filename already exists"); |
|
127 | + return false; |
|
128 | + } |
|
129 | + $this->fplock[md5($filename)] = fopen($filename.".lock", "w"); |
|
130 | + if ($mode == "r") { |
|
131 | + return flock($this->fplock[md5($filename)], LOCK_SH); |
|
132 | + } else { |
|
133 | + return flock($this->fplock[md5($filename)], LOCK_EX); |
|
134 | + } |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * adds a wsdl instance to the cache |
|
139 | - * |
|
140 | - * @param object wsdl $wsdl_instance The wsdl instance to add |
|
141 | - * @return boolean WSDL successfully cached |
|
142 | - * @access public |
|
143 | - */ |
|
144 | - function put($wsdl_instance) { |
|
145 | - $filename = $this->createFilename($wsdl_instance->wsdl); |
|
146 | - $s = serialize($wsdl_instance); |
|
147 | - if ($this->obtainMutex($filename, "w")) { |
|
148 | - $fp = fopen($filename, "w"); |
|
149 | - if (! $fp) { |
|
150 | - $this->debug("Cannot write $wsdl_instance->wsdl ($filename) in cache"); |
|
151 | - $this->releaseMutex($filename); |
|
152 | - return false; |
|
153 | - } |
|
154 | - fputs($fp, $s); |
|
155 | - fclose($fp); |
|
156 | - $this->debug("Put $wsdl_instance->wsdl ($filename) in cache"); |
|
157 | - $this->releaseMutex($filename); |
|
158 | - return true; |
|
159 | - } else { |
|
160 | - $this->debug("Unable to obtain mutex for $filename in put"); |
|
161 | - } |
|
162 | - return false; |
|
163 | - } |
|
137 | + /** |
|
138 | + * adds a wsdl instance to the cache |
|
139 | + * |
|
140 | + * @param object wsdl $wsdl_instance The wsdl instance to add |
|
141 | + * @return boolean WSDL successfully cached |
|
142 | + * @access public |
|
143 | + */ |
|
144 | + function put($wsdl_instance) { |
|
145 | + $filename = $this->createFilename($wsdl_instance->wsdl); |
|
146 | + $s = serialize($wsdl_instance); |
|
147 | + if ($this->obtainMutex($filename, "w")) { |
|
148 | + $fp = fopen($filename, "w"); |
|
149 | + if (! $fp) { |
|
150 | + $this->debug("Cannot write $wsdl_instance->wsdl ($filename) in cache"); |
|
151 | + $this->releaseMutex($filename); |
|
152 | + return false; |
|
153 | + } |
|
154 | + fputs($fp, $s); |
|
155 | + fclose($fp); |
|
156 | + $this->debug("Put $wsdl_instance->wsdl ($filename) in cache"); |
|
157 | + $this->releaseMutex($filename); |
|
158 | + return true; |
|
159 | + } else { |
|
160 | + $this->debug("Unable to obtain mutex for $filename in put"); |
|
161 | + } |
|
162 | + return false; |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * releases the local mutex |
|
167 | - * |
|
168 | - * @param string $filename The Filename of the Cache to lock |
|
169 | - * @return boolean Lock successfully released |
|
170 | - * @access private |
|
171 | - */ |
|
172 | - function releaseMutex($filename) { |
|
173 | - $ret = flock($this->fplock[md5($filename)], LOCK_UN); |
|
174 | - fclose($this->fplock[md5($filename)]); |
|
175 | - unset($this->fplock[md5($filename)]); |
|
176 | - if (! $ret) { |
|
177 | - $this->debug("Not able to release lock for $filename"); |
|
178 | - } |
|
179 | - return $ret; |
|
180 | - } |
|
165 | + /** |
|
166 | + * releases the local mutex |
|
167 | + * |
|
168 | + * @param string $filename The Filename of the Cache to lock |
|
169 | + * @return boolean Lock successfully released |
|
170 | + * @access private |
|
171 | + */ |
|
172 | + function releaseMutex($filename) { |
|
173 | + $ret = flock($this->fplock[md5($filename)], LOCK_UN); |
|
174 | + fclose($this->fplock[md5($filename)]); |
|
175 | + unset($this->fplock[md5($filename)]); |
|
176 | + if (! $ret) { |
|
177 | + $this->debug("Not able to release lock for $filename"); |
|
178 | + } |
|
179 | + return $ret; |
|
180 | + } |
|
181 | 181 | |
182 | - /** |
|
183 | - * removes a wsdl instance from the cache |
|
184 | - * |
|
185 | - * @param string $wsdl The URL of the wsdl instance |
|
186 | - * @return boolean Whether there was an instance to remove |
|
187 | - * @access public |
|
188 | - */ |
|
189 | - function remove($wsdl) { |
|
190 | - $filename = $this->createFilename($wsdl); |
|
191 | - if (!file_exists($filename)) { |
|
192 | - $this->debug("$wsdl ($filename) not in cache to be removed"); |
|
193 | - return false; |
|
194 | - } |
|
195 | - // ignore errors obtaining mutex |
|
196 | - $this->obtainMutex($filename, "w"); |
|
197 | - $ret = unlink($filename); |
|
198 | - $this->debug("Removed ($ret) $wsdl ($filename) from cache"); |
|
199 | - $this->releaseMutex($filename); |
|
200 | - return $ret; |
|
201 | - } |
|
182 | + /** |
|
183 | + * removes a wsdl instance from the cache |
|
184 | + * |
|
185 | + * @param string $wsdl The URL of the wsdl instance |
|
186 | + * @return boolean Whether there was an instance to remove |
|
187 | + * @access public |
|
188 | + */ |
|
189 | + function remove($wsdl) { |
|
190 | + $filename = $this->createFilename($wsdl); |
|
191 | + if (!file_exists($filename)) { |
|
192 | + $this->debug("$wsdl ($filename) not in cache to be removed"); |
|
193 | + return false; |
|
194 | + } |
|
195 | + // ignore errors obtaining mutex |
|
196 | + $this->obtainMutex($filename, "w"); |
|
197 | + $ret = unlink($filename); |
|
198 | + $this->debug("Removed ($ret) $wsdl ($filename) from cache"); |
|
199 | + $this->releaseMutex($filename); |
|
200 | + return $ret; |
|
201 | + } |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -15,90 +15,90 @@ |
||
15 | 15 | * @access public |
16 | 16 | */ |
17 | 17 | class soapval extends nusoap_base { |
18 | - /** |
|
19 | - * The XML element name |
|
20 | - * |
|
21 | - * @var string |
|
22 | - * @access private |
|
23 | - */ |
|
24 | - var $name; |
|
25 | - /** |
|
26 | - * The XML type name (string or false) |
|
27 | - * |
|
28 | - * @var mixed |
|
29 | - * @access private |
|
30 | - */ |
|
31 | - var $type; |
|
32 | - /** |
|
33 | - * The PHP value |
|
34 | - * |
|
35 | - * @var mixed |
|
36 | - * @access private |
|
37 | - */ |
|
38 | - var $value; |
|
39 | - /** |
|
40 | - * The XML element namespace (string or false) |
|
41 | - * |
|
42 | - * @var mixed |
|
43 | - * @access private |
|
44 | - */ |
|
45 | - var $element_ns; |
|
46 | - /** |
|
47 | - * The XML type namespace (string or false) |
|
48 | - * |
|
49 | - * @var mixed |
|
50 | - * @access private |
|
51 | - */ |
|
52 | - var $type_ns; |
|
53 | - /** |
|
54 | - * The XML element attributes (array or false) |
|
55 | - * |
|
56 | - * @var mixed |
|
57 | - * @access private |
|
58 | - */ |
|
59 | - var $attributes; |
|
18 | + /** |
|
19 | + * The XML element name |
|
20 | + * |
|
21 | + * @var string |
|
22 | + * @access private |
|
23 | + */ |
|
24 | + var $name; |
|
25 | + /** |
|
26 | + * The XML type name (string or false) |
|
27 | + * |
|
28 | + * @var mixed |
|
29 | + * @access private |
|
30 | + */ |
|
31 | + var $type; |
|
32 | + /** |
|
33 | + * The PHP value |
|
34 | + * |
|
35 | + * @var mixed |
|
36 | + * @access private |
|
37 | + */ |
|
38 | + var $value; |
|
39 | + /** |
|
40 | + * The XML element namespace (string or false) |
|
41 | + * |
|
42 | + * @var mixed |
|
43 | + * @access private |
|
44 | + */ |
|
45 | + var $element_ns; |
|
46 | + /** |
|
47 | + * The XML type namespace (string or false) |
|
48 | + * |
|
49 | + * @var mixed |
|
50 | + * @access private |
|
51 | + */ |
|
52 | + var $type_ns; |
|
53 | + /** |
|
54 | + * The XML element attributes (array or false) |
|
55 | + * |
|
56 | + * @var mixed |
|
57 | + * @access private |
|
58 | + */ |
|
59 | + var $attributes; |
|
60 | 60 | |
61 | - /** |
|
62 | - * constructor |
|
63 | - * |
|
64 | - * @param string $name optional name |
|
65 | - * @param mixed $type optional type name |
|
66 | - * @param mixed $value optional value |
|
67 | - * @param mixed $element_ns optional namespace of value |
|
68 | - * @param mixed $type_ns optional namespace of type |
|
69 | - * @param mixed $attributes associative array of attributes to add to element serialization |
|
70 | - * @access public |
|
71 | - */ |
|
72 | - function soapval($name='soapval',$type=false,$value=-1,$element_ns=false,$type_ns=false,$attributes=false) { |
|
73 | - parent::nusoap_base(); |
|
74 | - $this->name = $name; |
|
75 | - $this->type = $type; |
|
76 | - $this->value = $value; |
|
77 | - $this->element_ns = $element_ns; |
|
78 | - $this->type_ns = $type_ns; |
|
79 | - $this->attributes = $attributes; |
|
61 | + /** |
|
62 | + * constructor |
|
63 | + * |
|
64 | + * @param string $name optional name |
|
65 | + * @param mixed $type optional type name |
|
66 | + * @param mixed $value optional value |
|
67 | + * @param mixed $element_ns optional namespace of value |
|
68 | + * @param mixed $type_ns optional namespace of type |
|
69 | + * @param mixed $attributes associative array of attributes to add to element serialization |
|
70 | + * @access public |
|
71 | + */ |
|
72 | + function soapval($name='soapval',$type=false,$value=-1,$element_ns=false,$type_ns=false,$attributes=false) { |
|
73 | + parent::nusoap_base(); |
|
74 | + $this->name = $name; |
|
75 | + $this->type = $type; |
|
76 | + $this->value = $value; |
|
77 | + $this->element_ns = $element_ns; |
|
78 | + $this->type_ns = $type_ns; |
|
79 | + $this->attributes = $attributes; |
|
80 | 80 | } |
81 | 81 | |
82 | - /** |
|
83 | - * return serialized value |
|
84 | - * |
|
85 | - * @param string $use The WSDL use value (encoded|literal) |
|
86 | - * @return string XML data |
|
87 | - * @access public |
|
88 | - */ |
|
89 | - function serialize($use='encoded') { |
|
90 | - return $this->serialize_val($this->value, $this->name, $this->type, $this->element_ns, $this->type_ns, $this->attributes, $use, true); |
|
82 | + /** |
|
83 | + * return serialized value |
|
84 | + * |
|
85 | + * @param string $use The WSDL use value (encoded|literal) |
|
86 | + * @return string XML data |
|
87 | + * @access public |
|
88 | + */ |
|
89 | + function serialize($use='encoded') { |
|
90 | + return $this->serialize_val($this->value, $this->name, $this->type, $this->element_ns, $this->type_ns, $this->attributes, $use, true); |
|
91 | 91 | } |
92 | 92 | |
93 | - /** |
|
94 | - * decodes a soapval object into a PHP native type |
|
95 | - * |
|
96 | - * @return mixed |
|
97 | - * @access public |
|
98 | - */ |
|
99 | - function decode(){ |
|
100 | - return $this->value; |
|
101 | - } |
|
93 | + /** |
|
94 | + * decodes a soapval object into a PHP native type |
|
95 | + * |
|
96 | + * @return mixed |
|
97 | + * @access public |
|
98 | + */ |
|
99 | + function decode(){ |
|
100 | + return $this->value; |
|
101 | + } |
|
102 | 102 | } |
103 | 103 | |
104 | 104 |
@@ -14,171 +14,171 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class soap_transport_http extends nusoap_base { |
16 | 16 | |
17 | - var $url = ''; |
|
18 | - var $uri = ''; |
|
19 | - var $digest_uri = ''; |
|
20 | - var $scheme = ''; |
|
21 | - var $host = ''; |
|
22 | - var $port = ''; |
|
23 | - var $path = ''; |
|
24 | - var $request_method = 'POST'; |
|
25 | - var $protocol_version = '1.0'; |
|
26 | - var $encoding = ''; |
|
27 | - var $outgoing_headers = array(); |
|
28 | - var $incoming_headers = array(); |
|
29 | - var $incoming_cookies = array(); |
|
30 | - var $outgoing_payload = ''; |
|
31 | - var $incoming_payload = ''; |
|
32 | - var $response_status_line; // HTTP response status line |
|
33 | - var $useSOAPAction = true; |
|
34 | - var $persistentConnection = false; |
|
35 | - var $ch = false; // cURL handle |
|
36 | - var $ch_options = array(); // cURL custom options |
|
37 | - var $use_curl = false; // force cURL use |
|
38 | - var $proxy = null; // proxy information (associative array) |
|
39 | - var $username = ''; |
|
40 | - var $password = ''; |
|
41 | - var $authtype = ''; |
|
42 | - var $digestRequest = array(); |
|
43 | - var $certRequest = array(); // keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional) |
|
44 | - // cainfofile: certificate authority file, e.g. '$pathToPemFiles/rootca.pem' |
|
45 | - // sslcertfile: SSL certificate file, e.g. '$pathToPemFiles/mycert.pem' |
|
46 | - // sslkeyfile: SSL key file, e.g. '$pathToPemFiles/mykey.pem' |
|
47 | - // passphrase: SSL key password/passphrase |
|
48 | - // certpassword: SSL certificate password |
|
49 | - // verifypeer: default is 1 |
|
50 | - // verifyhost: default is 1 |
|
17 | + var $url = ''; |
|
18 | + var $uri = ''; |
|
19 | + var $digest_uri = ''; |
|
20 | + var $scheme = ''; |
|
21 | + var $host = ''; |
|
22 | + var $port = ''; |
|
23 | + var $path = ''; |
|
24 | + var $request_method = 'POST'; |
|
25 | + var $protocol_version = '1.0'; |
|
26 | + var $encoding = ''; |
|
27 | + var $outgoing_headers = array(); |
|
28 | + var $incoming_headers = array(); |
|
29 | + var $incoming_cookies = array(); |
|
30 | + var $outgoing_payload = ''; |
|
31 | + var $incoming_payload = ''; |
|
32 | + var $response_status_line; // HTTP response status line |
|
33 | + var $useSOAPAction = true; |
|
34 | + var $persistentConnection = false; |
|
35 | + var $ch = false; // cURL handle |
|
36 | + var $ch_options = array(); // cURL custom options |
|
37 | + var $use_curl = false; // force cURL use |
|
38 | + var $proxy = null; // proxy information (associative array) |
|
39 | + var $username = ''; |
|
40 | + var $password = ''; |
|
41 | + var $authtype = ''; |
|
42 | + var $digestRequest = array(); |
|
43 | + var $certRequest = array(); // keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional) |
|
44 | + // cainfofile: certificate authority file, e.g. '$pathToPemFiles/rootca.pem' |
|
45 | + // sslcertfile: SSL certificate file, e.g. '$pathToPemFiles/mycert.pem' |
|
46 | + // sslkeyfile: SSL key file, e.g. '$pathToPemFiles/mykey.pem' |
|
47 | + // passphrase: SSL key password/passphrase |
|
48 | + // certpassword: SSL certificate password |
|
49 | + // verifypeer: default is 1 |
|
50 | + // verifyhost: default is 1 |
|
51 | 51 | |
52 | - /** |
|
53 | - * constructor |
|
54 | - * |
|
55 | - * @param string $url The URL to which to connect |
|
56 | - * @param array $curl_options User-specified cURL options |
|
57 | - * @param boolean $use_curl Whether to try to force cURL use |
|
58 | - * @access public |
|
59 | - */ |
|
60 | - function soap_transport_http($url, $curl_options = NULL, $use_curl = false){ |
|
61 | - parent::nusoap_base(); |
|
62 | - $this->debug("ctor url=$url use_curl=$use_curl curl_options:"); |
|
63 | - $this->appendDebug($this->varDump($curl_options)); |
|
64 | - $this->setURL($url); |
|
65 | - if (is_array($curl_options)) { |
|
66 | - $this->ch_options = $curl_options; |
|
67 | - } |
|
68 | - $this->use_curl = $use_curl; |
|
69 | - preg_match('/\$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev); |
|
70 | - $this->setHeader('User-Agent', $this->title.'/'.$this->version.' ('.$rev[1].')'); |
|
71 | - } |
|
52 | + /** |
|
53 | + * constructor |
|
54 | + * |
|
55 | + * @param string $url The URL to which to connect |
|
56 | + * @param array $curl_options User-specified cURL options |
|
57 | + * @param boolean $use_curl Whether to try to force cURL use |
|
58 | + * @access public |
|
59 | + */ |
|
60 | + function soap_transport_http($url, $curl_options = NULL, $use_curl = false){ |
|
61 | + parent::nusoap_base(); |
|
62 | + $this->debug("ctor url=$url use_curl=$use_curl curl_options:"); |
|
63 | + $this->appendDebug($this->varDump($curl_options)); |
|
64 | + $this->setURL($url); |
|
65 | + if (is_array($curl_options)) { |
|
66 | + $this->ch_options = $curl_options; |
|
67 | + } |
|
68 | + $this->use_curl = $use_curl; |
|
69 | + preg_match('/\$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev); |
|
70 | + $this->setHeader('User-Agent', $this->title.'/'.$this->version.' ('.$rev[1].')'); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * sets a cURL option |
|
75 | - * |
|
76 | - * @param mixed $option The cURL option (always integer?) |
|
77 | - * @param mixed $value The cURL option value |
|
78 | - * @access private |
|
79 | - */ |
|
80 | - function setCurlOption($option, $value) { |
|
81 | - $this->debug("setCurlOption option=$option, value="); |
|
82 | - $this->appendDebug($this->varDump($value)); |
|
83 | - curl_setopt($this->ch, $option, $value); |
|
84 | - } |
|
73 | + /** |
|
74 | + * sets a cURL option |
|
75 | + * |
|
76 | + * @param mixed $option The cURL option (always integer?) |
|
77 | + * @param mixed $value The cURL option value |
|
78 | + * @access private |
|
79 | + */ |
|
80 | + function setCurlOption($option, $value) { |
|
81 | + $this->debug("setCurlOption option=$option, value="); |
|
82 | + $this->appendDebug($this->varDump($value)); |
|
83 | + curl_setopt($this->ch, $option, $value); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * sets an HTTP header |
|
88 | - * |
|
89 | - * @param string $name The name of the header |
|
90 | - * @param string $value The value of the header |
|
91 | - * @access private |
|
92 | - */ |
|
93 | - function setHeader($name, $value) { |
|
94 | - $this->outgoing_headers[$name] = $value; |
|
95 | - $this->debug("set header $name: $value"); |
|
96 | - } |
|
86 | + /** |
|
87 | + * sets an HTTP header |
|
88 | + * |
|
89 | + * @param string $name The name of the header |
|
90 | + * @param string $value The value of the header |
|
91 | + * @access private |
|
92 | + */ |
|
93 | + function setHeader($name, $value) { |
|
94 | + $this->outgoing_headers[$name] = $value; |
|
95 | + $this->debug("set header $name: $value"); |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * unsets an HTTP header |
|
100 | - * |
|
101 | - * @param string $name The name of the header |
|
102 | - * @access private |
|
103 | - */ |
|
104 | - function unsetHeader($name) { |
|
105 | - if (isset($this->outgoing_headers[$name])) { |
|
106 | - $this->debug("unset header $name"); |
|
107 | - unset($this->outgoing_headers[$name]); |
|
108 | - } |
|
109 | - } |
|
98 | + /** |
|
99 | + * unsets an HTTP header |
|
100 | + * |
|
101 | + * @param string $name The name of the header |
|
102 | + * @access private |
|
103 | + */ |
|
104 | + function unsetHeader($name) { |
|
105 | + if (isset($this->outgoing_headers[$name])) { |
|
106 | + $this->debug("unset header $name"); |
|
107 | + unset($this->outgoing_headers[$name]); |
|
108 | + } |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * sets the URL to which to connect |
|
113 | - * |
|
114 | - * @param string $url The URL to which to connect |
|
115 | - * @access private |
|
116 | - */ |
|
117 | - function setURL($url) { |
|
118 | - $this->url = $url; |
|
111 | + /** |
|
112 | + * sets the URL to which to connect |
|
113 | + * |
|
114 | + * @param string $url The URL to which to connect |
|
115 | + * @access private |
|
116 | + */ |
|
117 | + function setURL($url) { |
|
118 | + $this->url = $url; |
|
119 | 119 | |
120 | - $u = parse_url($url); |
|
121 | - foreach($u as $k => $v){ |
|
122 | - $this->debug("parsed URL $k = $v"); |
|
123 | - $this->$k = $v; |
|
124 | - } |
|
120 | + $u = parse_url($url); |
|
121 | + foreach($u as $k => $v){ |
|
122 | + $this->debug("parsed URL $k = $v"); |
|
123 | + $this->$k = $v; |
|
124 | + } |
|
125 | 125 | |
126 | - // add any GET params to path |
|
127 | - if(isset($u['query']) && $u['query'] != ''){ |
|
126 | + // add any GET params to path |
|
127 | + if(isset($u['query']) && $u['query'] != ''){ |
|
128 | 128 | $this->path .= '?' . $u['query']; |
129 | - } |
|
129 | + } |
|
130 | 130 | |
131 | - // set default port |
|
132 | - if(!isset($u['port'])){ |
|
133 | - if($u['scheme'] == 'https'){ |
|
134 | - $this->port = 443; |
|
135 | - } else { |
|
136 | - $this->port = 80; |
|
137 | - } |
|
138 | - } |
|
131 | + // set default port |
|
132 | + if(!isset($u['port'])){ |
|
133 | + if($u['scheme'] == 'https'){ |
|
134 | + $this->port = 443; |
|
135 | + } else { |
|
136 | + $this->port = 80; |
|
137 | + } |
|
138 | + } |
|
139 | 139 | |
140 | - $this->uri = $this->path; |
|
141 | - $this->digest_uri = $this->uri; |
|
140 | + $this->uri = $this->path; |
|
141 | + $this->digest_uri = $this->uri; |
|
142 | 142 | |
143 | - // build headers |
|
144 | - if (!isset($u['port'])) { |
|
145 | - $this->setHeader('Host', $this->host); |
|
146 | - } else { |
|
147 | - $this->setHeader('Host', $this->host.':'.$this->port); |
|
148 | - } |
|
143 | + // build headers |
|
144 | + if (!isset($u['port'])) { |
|
145 | + $this->setHeader('Host', $this->host); |
|
146 | + } else { |
|
147 | + $this->setHeader('Host', $this->host.':'.$this->port); |
|
148 | + } |
|
149 | 149 | |
150 | - if (isset($u['user']) && $u['user'] != '') { |
|
151 | - $this->setCredentials(urldecode($u['user']), isset($u['pass']) ? urldecode($u['pass']) : ''); |
|
152 | - } |
|
153 | - } |
|
150 | + if (isset($u['user']) && $u['user'] != '') { |
|
151 | + $this->setCredentials(urldecode($u['user']), isset($u['pass']) ? urldecode($u['pass']) : ''); |
|
152 | + } |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * gets the I/O method to use |
|
157 | - * |
|
158 | - * @return string I/O method to use (socket|curl|unknown) |
|
159 | - * @access private |
|
160 | - */ |
|
161 | - function io_method() { |
|
162 | - if ($this->use_curl || ($this->scheme == 'https') || ($this->scheme == 'http' && $this->authtype == 'ntlm') || ($this->scheme == 'http' && is_array($this->proxy) && $this->proxy['authtype'] == 'ntlm')) |
|
163 | - return 'curl'; |
|
164 | - if (($this->scheme == 'http' || $this->scheme == 'ssl') && $this->authtype != 'ntlm' && (!is_array($this->proxy) || $this->proxy['authtype'] != 'ntlm')) |
|
165 | - return 'socket'; |
|
166 | - return 'unknown'; |
|
167 | - } |
|
155 | + /** |
|
156 | + * gets the I/O method to use |
|
157 | + * |
|
158 | + * @return string I/O method to use (socket|curl|unknown) |
|
159 | + * @access private |
|
160 | + */ |
|
161 | + function io_method() { |
|
162 | + if ($this->use_curl || ($this->scheme == 'https') || ($this->scheme == 'http' && $this->authtype == 'ntlm') || ($this->scheme == 'http' && is_array($this->proxy) && $this->proxy['authtype'] == 'ntlm')) |
|
163 | + return 'curl'; |
|
164 | + if (($this->scheme == 'http' || $this->scheme == 'ssl') && $this->authtype != 'ntlm' && (!is_array($this->proxy) || $this->proxy['authtype'] != 'ntlm')) |
|
165 | + return 'socket'; |
|
166 | + return 'unknown'; |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * establish an HTTP connection |
|
171 | - * |
|
172 | - * @param integer $timeout set connection timeout in seconds |
|
173 | - * @param integer $response_timeout set response timeout in seconds |
|
174 | - * @return boolean true if connected, false if not |
|
175 | - * @access private |
|
176 | - */ |
|
177 | - function connect($connection_timeout=0,$response_timeout=30){ |
|
178 | - // For PHP 4.3 with OpenSSL, change https scheme to ssl, then treat like |
|
179 | - // "regular" socket. |
|
180 | - // TODO: disabled for now because OpenSSL must be *compiled* in (not just |
|
181 | - // loaded), and until PHP5 stream_get_wrappers is not available. |
|
169 | + /** |
|
170 | + * establish an HTTP connection |
|
171 | + * |
|
172 | + * @param integer $timeout set connection timeout in seconds |
|
173 | + * @param integer $response_timeout set response timeout in seconds |
|
174 | + * @return boolean true if connected, false if not |
|
175 | + * @access private |
|
176 | + */ |
|
177 | + function connect($connection_timeout=0,$response_timeout=30){ |
|
178 | + // For PHP 4.3 with OpenSSL, change https scheme to ssl, then treat like |
|
179 | + // "regular" socket. |
|
180 | + // TODO: disabled for now because OpenSSL must be *compiled* in (not just |
|
181 | + // loaded), and until PHP5 stream_get_wrappers is not available. |
|
182 | 182 | // if ($this->scheme == 'https') { |
183 | 183 | // if (version_compare(phpversion(), '4.3.0') >= 0) { |
184 | 184 | // if (extension_loaded('openssl')) { |
@@ -187,1120 +187,1120 @@ discard block |
||
187 | 187 | // } |
188 | 188 | // } |
189 | 189 | // } |
190 | - $this->debug("connect connection_timeout $connection_timeout, response_timeout $response_timeout, scheme $this->scheme, host $this->host, port $this->port"); |
|
191 | - if ($this->io_method() == 'socket') { |
|
192 | - if (!is_array($this->proxy)) { |
|
193 | - $host = $this->host; |
|
194 | - $port = $this->port; |
|
195 | - } else { |
|
196 | - $host = $this->proxy['host']; |
|
197 | - $port = $this->proxy['port']; |
|
198 | - } |
|
190 | + $this->debug("connect connection_timeout $connection_timeout, response_timeout $response_timeout, scheme $this->scheme, host $this->host, port $this->port"); |
|
191 | + if ($this->io_method() == 'socket') { |
|
192 | + if (!is_array($this->proxy)) { |
|
193 | + $host = $this->host; |
|
194 | + $port = $this->port; |
|
195 | + } else { |
|
196 | + $host = $this->proxy['host']; |
|
197 | + $port = $this->proxy['port']; |
|
198 | + } |
|
199 | 199 | |
200 | - // use persistent connection |
|
201 | - if($this->persistentConnection && isset($this->fp) && is_resource($this->fp)){ |
|
202 | - if (!feof($this->fp)) { |
|
203 | - $this->debug('Re-use persistent connection'); |
|
204 | - return true; |
|
205 | - } |
|
206 | - fclose($this->fp); |
|
207 | - $this->debug('Closed persistent connection at EOF'); |
|
208 | - } |
|
200 | + // use persistent connection |
|
201 | + if($this->persistentConnection && isset($this->fp) && is_resource($this->fp)){ |
|
202 | + if (!feof($this->fp)) { |
|
203 | + $this->debug('Re-use persistent connection'); |
|
204 | + return true; |
|
205 | + } |
|
206 | + fclose($this->fp); |
|
207 | + $this->debug('Closed persistent connection at EOF'); |
|
208 | + } |
|
209 | 209 | |
210 | - // munge host if using OpenSSL |
|
211 | - if ($this->scheme == 'ssl') { |
|
212 | - $host = 'ssl://' . $host; |
|
213 | - } |
|
214 | - $this->debug('calling fsockopen with host ' . $host . ' connection_timeout ' . $connection_timeout); |
|
210 | + // munge host if using OpenSSL |
|
211 | + if ($this->scheme == 'ssl') { |
|
212 | + $host = 'ssl://' . $host; |
|
213 | + } |
|
214 | + $this->debug('calling fsockopen with host ' . $host . ' connection_timeout ' . $connection_timeout); |
|
215 | 215 | |
216 | - // open socket |
|
217 | - if($connection_timeout > 0){ |
|
218 | - $this->fp = @fsockopen( $host, $this->port, $this->errno, $this->error_str, $connection_timeout); |
|
219 | - } else { |
|
220 | - $this->fp = @fsockopen( $host, $this->port, $this->errno, $this->error_str); |
|
221 | - } |
|
216 | + // open socket |
|
217 | + if($connection_timeout > 0){ |
|
218 | + $this->fp = @fsockopen( $host, $this->port, $this->errno, $this->error_str, $connection_timeout); |
|
219 | + } else { |
|
220 | + $this->fp = @fsockopen( $host, $this->port, $this->errno, $this->error_str); |
|
221 | + } |
|
222 | 222 | |
223 | - // test pointer |
|
224 | - if(!$this->fp) { |
|
225 | - $msg = 'Couldn\'t open socket connection to server ' . $this->url; |
|
226 | - if ($this->errno) { |
|
227 | - $msg .= ', Error ('.$this->errno.'): '.$this->error_str; |
|
228 | - } else { |
|
229 | - $msg .= ' prior to connect(). This is often a problem looking up the host name.'; |
|
230 | - } |
|
231 | - $this->debug($msg); |
|
232 | - $this->setError($msg); |
|
233 | - return false; |
|
234 | - } |
|
223 | + // test pointer |
|
224 | + if(!$this->fp) { |
|
225 | + $msg = 'Couldn\'t open socket connection to server ' . $this->url; |
|
226 | + if ($this->errno) { |
|
227 | + $msg .= ', Error ('.$this->errno.'): '.$this->error_str; |
|
228 | + } else { |
|
229 | + $msg .= ' prior to connect(). This is often a problem looking up the host name.'; |
|
230 | + } |
|
231 | + $this->debug($msg); |
|
232 | + $this->setError($msg); |
|
233 | + return false; |
|
234 | + } |
|
235 | 235 | |
236 | - // set response timeout |
|
237 | - $this->debug('set response timeout to ' . $response_timeout); |
|
238 | - socket_set_timeout( $this->fp, $response_timeout); |
|
236 | + // set response timeout |
|
237 | + $this->debug('set response timeout to ' . $response_timeout); |
|
238 | + socket_set_timeout( $this->fp, $response_timeout); |
|
239 | 239 | |
240 | - $this->debug('socket connected'); |
|
241 | - return true; |
|
242 | - } else if ($this->io_method() == 'curl') { |
|
243 | - if (!extension_loaded('curl')) { |
|
240 | + $this->debug('socket connected'); |
|
241 | + return true; |
|
242 | + } else if ($this->io_method() == 'curl') { |
|
243 | + if (!extension_loaded('curl')) { |
|
244 | 244 | // $this->setError('cURL Extension, or OpenSSL extension w/ PHP version >= 4.3 is required for HTTPS'); |
245 | - $this->setError('The PHP cURL Extension is required for HTTPS or NLTM. You will need to re-build or update your PHP to include cURL or change php.ini to load the PHP cURL extension.'); |
|
246 | - return false; |
|
247 | - } |
|
248 | - // Avoid warnings when PHP does not have these options |
|
249 | - if (defined('CURLOPT_CONNECTIONTIMEOUT')) |
|
250 | - $CURLOPT_CONNECTIONTIMEOUT = CURLOPT_CONNECTIONTIMEOUT; |
|
251 | - else |
|
252 | - $CURLOPT_CONNECTIONTIMEOUT = 78; |
|
253 | - if (defined('CURLOPT_HTTPAUTH')) |
|
254 | - $CURLOPT_HTTPAUTH = CURLOPT_HTTPAUTH; |
|
255 | - else |
|
256 | - $CURLOPT_HTTPAUTH = 107; |
|
257 | - if (defined('CURLOPT_PROXYAUTH')) |
|
258 | - $CURLOPT_PROXYAUTH = CURLOPT_PROXYAUTH; |
|
259 | - else |
|
260 | - $CURLOPT_PROXYAUTH = 111; |
|
261 | - if (defined('CURLAUTH_BASIC')) |
|
262 | - $CURLAUTH_BASIC = CURLAUTH_BASIC; |
|
263 | - else |
|
264 | - $CURLAUTH_BASIC = 1; |
|
265 | - if (defined('CURLAUTH_DIGEST')) |
|
266 | - $CURLAUTH_DIGEST = CURLAUTH_DIGEST; |
|
267 | - else |
|
268 | - $CURLAUTH_DIGEST = 2; |
|
269 | - if (defined('CURLAUTH_NTLM')) |
|
270 | - $CURLAUTH_NTLM = CURLAUTH_NTLM; |
|
271 | - else |
|
272 | - $CURLAUTH_NTLM = 8; |
|
245 | + $this->setError('The PHP cURL Extension is required for HTTPS or NLTM. You will need to re-build or update your PHP to include cURL or change php.ini to load the PHP cURL extension.'); |
|
246 | + return false; |
|
247 | + } |
|
248 | + // Avoid warnings when PHP does not have these options |
|
249 | + if (defined('CURLOPT_CONNECTIONTIMEOUT')) |
|
250 | + $CURLOPT_CONNECTIONTIMEOUT = CURLOPT_CONNECTIONTIMEOUT; |
|
251 | + else |
|
252 | + $CURLOPT_CONNECTIONTIMEOUT = 78; |
|
253 | + if (defined('CURLOPT_HTTPAUTH')) |
|
254 | + $CURLOPT_HTTPAUTH = CURLOPT_HTTPAUTH; |
|
255 | + else |
|
256 | + $CURLOPT_HTTPAUTH = 107; |
|
257 | + if (defined('CURLOPT_PROXYAUTH')) |
|
258 | + $CURLOPT_PROXYAUTH = CURLOPT_PROXYAUTH; |
|
259 | + else |
|
260 | + $CURLOPT_PROXYAUTH = 111; |
|
261 | + if (defined('CURLAUTH_BASIC')) |
|
262 | + $CURLAUTH_BASIC = CURLAUTH_BASIC; |
|
263 | + else |
|
264 | + $CURLAUTH_BASIC = 1; |
|
265 | + if (defined('CURLAUTH_DIGEST')) |
|
266 | + $CURLAUTH_DIGEST = CURLAUTH_DIGEST; |
|
267 | + else |
|
268 | + $CURLAUTH_DIGEST = 2; |
|
269 | + if (defined('CURLAUTH_NTLM')) |
|
270 | + $CURLAUTH_NTLM = CURLAUTH_NTLM; |
|
271 | + else |
|
272 | + $CURLAUTH_NTLM = 8; |
|
273 | 273 | |
274 | - $this->debug('connect using cURL'); |
|
275 | - // init CURL |
|
276 | - $this->ch = curl_init(); |
|
277 | - // set url |
|
278 | - $hostURL = ($this->port != '') ? "$this->scheme://$this->host:$this->port" : "$this->scheme://$this->host"; |
|
279 | - // add path |
|
280 | - $hostURL .= $this->path; |
|
281 | - $this->setCurlOption(CURLOPT_URL, $hostURL); |
|
282 | - // follow location headers (re-directs) |
|
283 | - if (ini_get('safe_mode') || ini_get('open_basedir')) { |
|
284 | - $this->debug('safe_mode or open_basedir set, so do not set CURLOPT_FOLLOWLOCATION'); |
|
285 | - $this->debug('safe_mode = '); |
|
286 | - $this->appendDebug($this->varDump(ini_get('safe_mode'))); |
|
287 | - $this->debug('open_basedir = '); |
|
288 | - $this->appendDebug($this->varDump(ini_get('open_basedir'))); |
|
289 | - } else { |
|
290 | - $this->setCurlOption(CURLOPT_FOLLOWLOCATION, 1); |
|
291 | - } |
|
292 | - // ask for headers in the response output |
|
293 | - $this->setCurlOption(CURLOPT_HEADER, 1); |
|
294 | - // ask for the response output as the return value |
|
295 | - $this->setCurlOption(CURLOPT_RETURNTRANSFER, 1); |
|
296 | - // encode |
|
297 | - // We manage this ourselves through headers and encoding |
|
274 | + $this->debug('connect using cURL'); |
|
275 | + // init CURL |
|
276 | + $this->ch = curl_init(); |
|
277 | + // set url |
|
278 | + $hostURL = ($this->port != '') ? "$this->scheme://$this->host:$this->port" : "$this->scheme://$this->host"; |
|
279 | + // add path |
|
280 | + $hostURL .= $this->path; |
|
281 | + $this->setCurlOption(CURLOPT_URL, $hostURL); |
|
282 | + // follow location headers (re-directs) |
|
283 | + if (ini_get('safe_mode') || ini_get('open_basedir')) { |
|
284 | + $this->debug('safe_mode or open_basedir set, so do not set CURLOPT_FOLLOWLOCATION'); |
|
285 | + $this->debug('safe_mode = '); |
|
286 | + $this->appendDebug($this->varDump(ini_get('safe_mode'))); |
|
287 | + $this->debug('open_basedir = '); |
|
288 | + $this->appendDebug($this->varDump(ini_get('open_basedir'))); |
|
289 | + } else { |
|
290 | + $this->setCurlOption(CURLOPT_FOLLOWLOCATION, 1); |
|
291 | + } |
|
292 | + // ask for headers in the response output |
|
293 | + $this->setCurlOption(CURLOPT_HEADER, 1); |
|
294 | + // ask for the response output as the return value |
|
295 | + $this->setCurlOption(CURLOPT_RETURNTRANSFER, 1); |
|
296 | + // encode |
|
297 | + // We manage this ourselves through headers and encoding |
|
298 | 298 | // if(function_exists('gzuncompress')){ |
299 | 299 | // $this->setCurlOption(CURLOPT_ENCODING, 'deflate'); |
300 | 300 | // } |
301 | - // persistent connection |
|
302 | - if ($this->persistentConnection) { |
|
303 | - // I believe the following comment is now bogus, having applied to |
|
304 | - // the code when it used CURLOPT_CUSTOMREQUEST to send the request. |
|
305 | - // The way we send data, we cannot use persistent connections, since |
|
306 | - // there will be some "junk" at the end of our request. |
|
307 | - //$this->setCurlOption(CURL_HTTP_VERSION_1_1, true); |
|
308 | - $this->persistentConnection = false; |
|
309 | - $this->setHeader('Connection', 'close'); |
|
310 | - } |
|
311 | - // set timeouts |
|
312 | - if ($connection_timeout != 0) { |
|
313 | - $this->setCurlOption($CURLOPT_CONNECTIONTIMEOUT, $connection_timeout); |
|
314 | - } |
|
315 | - if ($response_timeout != 0) { |
|
316 | - $this->setCurlOption(CURLOPT_TIMEOUT, $response_timeout); |
|
317 | - } |
|
301 | + // persistent connection |
|
302 | + if ($this->persistentConnection) { |
|
303 | + // I believe the following comment is now bogus, having applied to |
|
304 | + // the code when it used CURLOPT_CUSTOMREQUEST to send the request. |
|
305 | + // The way we send data, we cannot use persistent connections, since |
|
306 | + // there will be some "junk" at the end of our request. |
|
307 | + //$this->setCurlOption(CURL_HTTP_VERSION_1_1, true); |
|
308 | + $this->persistentConnection = false; |
|
309 | + $this->setHeader('Connection', 'close'); |
|
310 | + } |
|
311 | + // set timeouts |
|
312 | + if ($connection_timeout != 0) { |
|
313 | + $this->setCurlOption($CURLOPT_CONNECTIONTIMEOUT, $connection_timeout); |
|
314 | + } |
|
315 | + if ($response_timeout != 0) { |
|
316 | + $this->setCurlOption(CURLOPT_TIMEOUT, $response_timeout); |
|
317 | + } |
|
318 | 318 | |
319 | - if ($this->scheme == 'https') { |
|
320 | - $this->debug('set cURL SSL verify options'); |
|
321 | - // recent versions of cURL turn on peer/host checking by default, |
|
322 | - // while PHP binaries are not compiled with a default location for the |
|
323 | - // CA cert bundle, so disable peer/host checking. |
|
324 | - //$this->setCurlOption(CURLOPT_CAINFO, 'f:\php-4.3.2-win32\extensions\curl-ca-bundle.crt'); |
|
325 | - $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 0); |
|
326 | - $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 0); |
|
319 | + if ($this->scheme == 'https') { |
|
320 | + $this->debug('set cURL SSL verify options'); |
|
321 | + // recent versions of cURL turn on peer/host checking by default, |
|
322 | + // while PHP binaries are not compiled with a default location for the |
|
323 | + // CA cert bundle, so disable peer/host checking. |
|
324 | + //$this->setCurlOption(CURLOPT_CAINFO, 'f:\php-4.3.2-win32\extensions\curl-ca-bundle.crt'); |
|
325 | + $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 0); |
|
326 | + $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 0); |
|
327 | 327 | |
328 | - // support client certificates (thanks Tobias Boes, Doug Anarino, Eryan Ariobowo) |
|
329 | - if ($this->authtype == 'certificate') { |
|
330 | - $this->debug('set cURL certificate options'); |
|
331 | - if (isset($this->certRequest['cainfofile'])) { |
|
332 | - $this->setCurlOption(CURLOPT_CAINFO, $this->certRequest['cainfofile']); |
|
333 | - } |
|
334 | - if (isset($this->certRequest['verifypeer'])) { |
|
335 | - $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, $this->certRequest['verifypeer']); |
|
336 | - } else { |
|
337 | - $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 1); |
|
338 | - } |
|
339 | - if (isset($this->certRequest['verifyhost'])) { |
|
340 | - $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, $this->certRequest['verifyhost']); |
|
341 | - } else { |
|
342 | - $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 1); |
|
343 | - } |
|
344 | - if (isset($this->certRequest['sslcertfile'])) { |
|
345 | - $this->setCurlOption(CURLOPT_SSLCERT, $this->certRequest['sslcertfile']); |
|
346 | - } |
|
347 | - if (isset($this->certRequest['sslkeyfile'])) { |
|
348 | - $this->setCurlOption(CURLOPT_SSLKEY, $this->certRequest['sslkeyfile']); |
|
349 | - } |
|
350 | - if (isset($this->certRequest['passphrase'])) { |
|
351 | - $this->setCurlOption(CURLOPT_SSLKEYPASSWD, $this->certRequest['passphrase']); |
|
352 | - } |
|
353 | - if (isset($this->certRequest['certpassword'])) { |
|
354 | - $this->setCurlOption(CURLOPT_SSLCERTPASSWD, $this->certRequest['certpassword']); |
|
355 | - } |
|
356 | - } |
|
357 | - } |
|
358 | - if ($this->authtype && ($this->authtype != 'certificate')) { |
|
359 | - if ($this->username) { |
|
360 | - $this->debug('set cURL username/password'); |
|
361 | - $this->setCurlOption(CURLOPT_USERPWD, "$this->username:$this->password"); |
|
362 | - } |
|
363 | - if ($this->authtype == 'basic') { |
|
364 | - $this->debug('set cURL for Basic authentication'); |
|
365 | - $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_BASIC); |
|
366 | - } |
|
367 | - if ($this->authtype == 'digest') { |
|
368 | - $this->debug('set cURL for digest authentication'); |
|
369 | - $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_DIGEST); |
|
370 | - } |
|
371 | - if ($this->authtype == 'ntlm') { |
|
372 | - $this->debug('set cURL for NTLM authentication'); |
|
373 | - $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_NTLM); |
|
374 | - } |
|
375 | - } |
|
376 | - if (is_array($this->proxy)) { |
|
377 | - $this->debug('set cURL proxy options'); |
|
378 | - if ($this->proxy['port'] != '') { |
|
379 | - $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host'].':'.$this->proxy['port']); |
|
380 | - } else { |
|
381 | - $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host']); |
|
382 | - } |
|
383 | - if ($this->proxy['username'] || $this->proxy['password']) { |
|
384 | - $this->debug('set cURL proxy authentication options'); |
|
385 | - $this->setCurlOption(CURLOPT_PROXYUSERPWD, $this->proxy['username'].':'.$this->proxy['password']); |
|
386 | - if ($this->proxy['authtype'] == 'basic') { |
|
387 | - $this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_BASIC); |
|
388 | - } |
|
389 | - if ($this->proxy['authtype'] == 'ntlm') { |
|
390 | - $this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_NTLM); |
|
391 | - } |
|
392 | - } |
|
393 | - } |
|
394 | - $this->debug('cURL connection set up'); |
|
395 | - return true; |
|
396 | - } else { |
|
397 | - $this->setError('Unknown scheme ' . $this->scheme); |
|
398 | - $this->debug('Unknown scheme ' . $this->scheme); |
|
399 | - return false; |
|
400 | - } |
|
401 | - } |
|
328 | + // support client certificates (thanks Tobias Boes, Doug Anarino, Eryan Ariobowo) |
|
329 | + if ($this->authtype == 'certificate') { |
|
330 | + $this->debug('set cURL certificate options'); |
|
331 | + if (isset($this->certRequest['cainfofile'])) { |
|
332 | + $this->setCurlOption(CURLOPT_CAINFO, $this->certRequest['cainfofile']); |
|
333 | + } |
|
334 | + if (isset($this->certRequest['verifypeer'])) { |
|
335 | + $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, $this->certRequest['verifypeer']); |
|
336 | + } else { |
|
337 | + $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 1); |
|
338 | + } |
|
339 | + if (isset($this->certRequest['verifyhost'])) { |
|
340 | + $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, $this->certRequest['verifyhost']); |
|
341 | + } else { |
|
342 | + $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 1); |
|
343 | + } |
|
344 | + if (isset($this->certRequest['sslcertfile'])) { |
|
345 | + $this->setCurlOption(CURLOPT_SSLCERT, $this->certRequest['sslcertfile']); |
|
346 | + } |
|
347 | + if (isset($this->certRequest['sslkeyfile'])) { |
|
348 | + $this->setCurlOption(CURLOPT_SSLKEY, $this->certRequest['sslkeyfile']); |
|
349 | + } |
|
350 | + if (isset($this->certRequest['passphrase'])) { |
|
351 | + $this->setCurlOption(CURLOPT_SSLKEYPASSWD, $this->certRequest['passphrase']); |
|
352 | + } |
|
353 | + if (isset($this->certRequest['certpassword'])) { |
|
354 | + $this->setCurlOption(CURLOPT_SSLCERTPASSWD, $this->certRequest['certpassword']); |
|
355 | + } |
|
356 | + } |
|
357 | + } |
|
358 | + if ($this->authtype && ($this->authtype != 'certificate')) { |
|
359 | + if ($this->username) { |
|
360 | + $this->debug('set cURL username/password'); |
|
361 | + $this->setCurlOption(CURLOPT_USERPWD, "$this->username:$this->password"); |
|
362 | + } |
|
363 | + if ($this->authtype == 'basic') { |
|
364 | + $this->debug('set cURL for Basic authentication'); |
|
365 | + $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_BASIC); |
|
366 | + } |
|
367 | + if ($this->authtype == 'digest') { |
|
368 | + $this->debug('set cURL for digest authentication'); |
|
369 | + $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_DIGEST); |
|
370 | + } |
|
371 | + if ($this->authtype == 'ntlm') { |
|
372 | + $this->debug('set cURL for NTLM authentication'); |
|
373 | + $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_NTLM); |
|
374 | + } |
|
375 | + } |
|
376 | + if (is_array($this->proxy)) { |
|
377 | + $this->debug('set cURL proxy options'); |
|
378 | + if ($this->proxy['port'] != '') { |
|
379 | + $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host'].':'.$this->proxy['port']); |
|
380 | + } else { |
|
381 | + $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host']); |
|
382 | + } |
|
383 | + if ($this->proxy['username'] || $this->proxy['password']) { |
|
384 | + $this->debug('set cURL proxy authentication options'); |
|
385 | + $this->setCurlOption(CURLOPT_PROXYUSERPWD, $this->proxy['username'].':'.$this->proxy['password']); |
|
386 | + if ($this->proxy['authtype'] == 'basic') { |
|
387 | + $this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_BASIC); |
|
388 | + } |
|
389 | + if ($this->proxy['authtype'] == 'ntlm') { |
|
390 | + $this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_NTLM); |
|
391 | + } |
|
392 | + } |
|
393 | + } |
|
394 | + $this->debug('cURL connection set up'); |
|
395 | + return true; |
|
396 | + } else { |
|
397 | + $this->setError('Unknown scheme ' . $this->scheme); |
|
398 | + $this->debug('Unknown scheme ' . $this->scheme); |
|
399 | + return false; |
|
400 | + } |
|
401 | + } |
|
402 | 402 | |
403 | - /** |
|
404 | - * sends the SOAP request and gets the SOAP response via HTTP[S] |
|
405 | - * |
|
406 | - * @param string $data message data |
|
407 | - * @param integer $timeout set connection timeout in seconds |
|
408 | - * @param integer $response_timeout set response timeout in seconds |
|
409 | - * @param array $cookies cookies to send |
|
410 | - * @return string data |
|
411 | - * @access public |
|
412 | - */ |
|
413 | - function send($data, $timeout=0, $response_timeout=30, $cookies=NULL) { |
|
403 | + /** |
|
404 | + * sends the SOAP request and gets the SOAP response via HTTP[S] |
|
405 | + * |
|
406 | + * @param string $data message data |
|
407 | + * @param integer $timeout set connection timeout in seconds |
|
408 | + * @param integer $response_timeout set response timeout in seconds |
|
409 | + * @param array $cookies cookies to send |
|
410 | + * @return string data |
|
411 | + * @access public |
|
412 | + */ |
|
413 | + function send($data, $timeout=0, $response_timeout=30, $cookies=NULL) { |
|
414 | 414 | |
415 | - $this->debug('entered send() with data of length: '.strlen($data)); |
|
415 | + $this->debug('entered send() with data of length: '.strlen($data)); |
|
416 | 416 | |
417 | - $this->tryagain = true; |
|
418 | - $tries = 0; |
|
419 | - while ($this->tryagain) { |
|
420 | - $this->tryagain = false; |
|
421 | - if ($tries++ < 2) { |
|
422 | - // make connnection |
|
423 | - if (!$this->connect($timeout, $response_timeout)){ |
|
424 | - return false; |
|
425 | - } |
|
417 | + $this->tryagain = true; |
|
418 | + $tries = 0; |
|
419 | + while ($this->tryagain) { |
|
420 | + $this->tryagain = false; |
|
421 | + if ($tries++ < 2) { |
|
422 | + // make connnection |
|
423 | + if (!$this->connect($timeout, $response_timeout)){ |
|
424 | + return false; |
|
425 | + } |
|
426 | 426 | |
427 | - // send request |
|
428 | - if (!$this->sendRequest($data, $cookies)){ |
|
429 | - return false; |
|
430 | - } |
|
427 | + // send request |
|
428 | + if (!$this->sendRequest($data, $cookies)){ |
|
429 | + return false; |
|
430 | + } |
|
431 | 431 | |
432 | - // get response |
|
433 | - $respdata = $this->getResponse(); |
|
434 | - } else { |
|
435 | - $this->setError("Too many tries to get an OK response ($this->response_status_line)"); |
|
436 | - } |
|
437 | - } |
|
438 | - $this->debug('end of send()'); |
|
439 | - return $respdata; |
|
440 | - } |
|
432 | + // get response |
|
433 | + $respdata = $this->getResponse(); |
|
434 | + } else { |
|
435 | + $this->setError("Too many tries to get an OK response ($this->response_status_line)"); |
|
436 | + } |
|
437 | + } |
|
438 | + $this->debug('end of send()'); |
|
439 | + return $respdata; |
|
440 | + } |
|
441 | 441 | |
442 | 442 | |
443 | - /** |
|
444 | - * sends the SOAP request and gets the SOAP response via HTTPS using CURL |
|
445 | - * |
|
446 | - * @param string $data message data |
|
447 | - * @param integer $timeout set connection timeout in seconds |
|
448 | - * @param integer $response_timeout set response timeout in seconds |
|
449 | - * @param array $cookies cookies to send |
|
450 | - * @return string data |
|
451 | - * @access public |
|
452 | - * @deprecated |
|
453 | - */ |
|
454 | - function sendHTTPS($data, $timeout=0, $response_timeout=30, $cookies) { |
|
455 | - return $this->send($data, $timeout, $response_timeout, $cookies); |
|
456 | - } |
|
443 | + /** |
|
444 | + * sends the SOAP request and gets the SOAP response via HTTPS using CURL |
|
445 | + * |
|
446 | + * @param string $data message data |
|
447 | + * @param integer $timeout set connection timeout in seconds |
|
448 | + * @param integer $response_timeout set response timeout in seconds |
|
449 | + * @param array $cookies cookies to send |
|
450 | + * @return string data |
|
451 | + * @access public |
|
452 | + * @deprecated |
|
453 | + */ |
|
454 | + function sendHTTPS($data, $timeout=0, $response_timeout=30, $cookies) { |
|
455 | + return $this->send($data, $timeout, $response_timeout, $cookies); |
|
456 | + } |
|
457 | 457 | |
458 | - /** |
|
459 | - * if authenticating, set user credentials here |
|
460 | - * |
|
461 | - * @param string $username |
|
462 | - * @param string $password |
|
463 | - * @param string $authtype (basic|digest|certificate|ntlm) |
|
464 | - * @param array $digestRequest (keys must be nonce, nc, realm, qop) |
|
465 | - * @param array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs) |
|
466 | - * @access public |
|
467 | - */ |
|
468 | - function setCredentials($username, $password, $authtype = 'basic', $digestRequest = array(), $certRequest = array()) { |
|
469 | - $this->debug("setCredentials username=$username authtype=$authtype digestRequest="); |
|
470 | - $this->appendDebug($this->varDump($digestRequest)); |
|
471 | - $this->debug("certRequest="); |
|
472 | - $this->appendDebug($this->varDump($certRequest)); |
|
473 | - // cf. RFC 2617 |
|
474 | - if ($authtype == 'basic') { |
|
475 | - $this->setHeader('Authorization', 'Basic '.base64_encode(str_replace(':','',$username).':'.$password)); |
|
476 | - } elseif ($authtype == 'digest') { |
|
477 | - if (isset($digestRequest['nonce'])) { |
|
478 | - $digestRequest['nc'] = isset($digestRequest['nc']) ? $digestRequest['nc']++ : 1; |
|
458 | + /** |
|
459 | + * if authenticating, set user credentials here |
|
460 | + * |
|
461 | + * @param string $username |
|
462 | + * @param string $password |
|
463 | + * @param string $authtype (basic|digest|certificate|ntlm) |
|
464 | + * @param array $digestRequest (keys must be nonce, nc, realm, qop) |
|
465 | + * @param array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs) |
|
466 | + * @access public |
|
467 | + */ |
|
468 | + function setCredentials($username, $password, $authtype = 'basic', $digestRequest = array(), $certRequest = array()) { |
|
469 | + $this->debug("setCredentials username=$username authtype=$authtype digestRequest="); |
|
470 | + $this->appendDebug($this->varDump($digestRequest)); |
|
471 | + $this->debug("certRequest="); |
|
472 | + $this->appendDebug($this->varDump($certRequest)); |
|
473 | + // cf. RFC 2617 |
|
474 | + if ($authtype == 'basic') { |
|
475 | + $this->setHeader('Authorization', 'Basic '.base64_encode(str_replace(':','',$username).':'.$password)); |
|
476 | + } elseif ($authtype == 'digest') { |
|
477 | + if (isset($digestRequest['nonce'])) { |
|
478 | + $digestRequest['nc'] = isset($digestRequest['nc']) ? $digestRequest['nc']++ : 1; |
|
479 | 479 | |
480 | - // calculate the Digest hashes (calculate code based on digest implementation found at: http://www.rassoc.com/gregr/weblog/stories/2002/07/09/webServicesSecurityHttpDigestAuthenticationWithoutActiveDirectory.html) |
|
480 | + // calculate the Digest hashes (calculate code based on digest implementation found at: http://www.rassoc.com/gregr/weblog/stories/2002/07/09/webServicesSecurityHttpDigestAuthenticationWithoutActiveDirectory.html) |
|
481 | 481 | |
482 | - // A1 = unq(username-value) ":" unq(realm-value) ":" passwd |
|
483 | - $A1 = $username. ':' . (isset($digestRequest['realm']) ? $digestRequest['realm'] : '') . ':' . $password; |
|
482 | + // A1 = unq(username-value) ":" unq(realm-value) ":" passwd |
|
483 | + $A1 = $username. ':' . (isset($digestRequest['realm']) ? $digestRequest['realm'] : '') . ':' . $password; |
|
484 | 484 | |
485 | - // H(A1) = MD5(A1) |
|
486 | - $HA1 = md5($A1); |
|
485 | + // H(A1) = MD5(A1) |
|
486 | + $HA1 = md5($A1); |
|
487 | 487 | |
488 | - // A2 = Method ":" digest-uri-value |
|
489 | - $A2 = $this->request_method . ':' . $this->digest_uri; |
|
488 | + // A2 = Method ":" digest-uri-value |
|
489 | + $A2 = $this->request_method . ':' . $this->digest_uri; |
|
490 | 490 | |
491 | - // H(A2) |
|
492 | - $HA2 = md5($A2); |
|
491 | + // H(A2) |
|
492 | + $HA2 = md5($A2); |
|
493 | 493 | |
494 | - // KD(secret, data) = H(concat(secret, ":", data)) |
|
495 | - // if qop == auth: |
|
496 | - // request-digest = <"> < KD ( H(A1), unq(nonce-value) |
|
497 | - // ":" nc-value |
|
498 | - // ":" unq(cnonce-value) |
|
499 | - // ":" unq(qop-value) |
|
500 | - // ":" H(A2) |
|
501 | - // ) <"> |
|
502 | - // if qop is missing, |
|
503 | - // request-digest = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) ) > <"> |
|
494 | + // KD(secret, data) = H(concat(secret, ":", data)) |
|
495 | + // if qop == auth: |
|
496 | + // request-digest = <"> < KD ( H(A1), unq(nonce-value) |
|
497 | + // ":" nc-value |
|
498 | + // ":" unq(cnonce-value) |
|
499 | + // ":" unq(qop-value) |
|
500 | + // ":" H(A2) |
|
501 | + // ) <"> |
|
502 | + // if qop is missing, |
|
503 | + // request-digest = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) ) > <"> |
|
504 | 504 | |
505 | - $unhashedDigest = ''; |
|
506 | - $nonce = isset($digestRequest['nonce']) ? $digestRequest['nonce'] : ''; |
|
507 | - $cnonce = $nonce; |
|
508 | - if ($digestRequest['qop'] != '') { |
|
509 | - $unhashedDigest = $HA1 . ':' . $nonce . ':' . sprintf("%08d", $digestRequest['nc']) . ':' . $cnonce . ':' . $digestRequest['qop'] . ':' . $HA2; |
|
510 | - } else { |
|
511 | - $unhashedDigest = $HA1 . ':' . $nonce . ':' . $HA2; |
|
512 | - } |
|
505 | + $unhashedDigest = ''; |
|
506 | + $nonce = isset($digestRequest['nonce']) ? $digestRequest['nonce'] : ''; |
|
507 | + $cnonce = $nonce; |
|
508 | + if ($digestRequest['qop'] != '') { |
|
509 | + $unhashedDigest = $HA1 . ':' . $nonce . ':' . sprintf("%08d", $digestRequest['nc']) . ':' . $cnonce . ':' . $digestRequest['qop'] . ':' . $HA2; |
|
510 | + } else { |
|
511 | + $unhashedDigest = $HA1 . ':' . $nonce . ':' . $HA2; |
|
512 | + } |
|
513 | 513 | |
514 | - $hashedDigest = md5($unhashedDigest); |
|
514 | + $hashedDigest = md5($unhashedDigest); |
|
515 | 515 | |
516 | - $opaque = ''; |
|
517 | - if (isset($digestRequest['opaque'])) { |
|
518 | - $opaque = ', opaque="' . $digestRequest['opaque'] . '"'; |
|
519 | - } |
|
516 | + $opaque = ''; |
|
517 | + if (isset($digestRequest['opaque'])) { |
|
518 | + $opaque = ', opaque="' . $digestRequest['opaque'] . '"'; |
|
519 | + } |
|
520 | 520 | |
521 | - $this->setHeader('Authorization', 'Digest username="' . $username . '", realm="' . $digestRequest['realm'] . '", nonce="' . $nonce . '", uri="' . $this->digest_uri . $opaque . '", cnonce="' . $cnonce . '", nc=' . sprintf("%08x", $digestRequest['nc']) . ', qop="' . $digestRequest['qop'] . '", response="' . $hashedDigest . '"'); |
|
522 | - } |
|
523 | - } elseif ($authtype == 'certificate') { |
|
524 | - $this->certRequest = $certRequest; |
|
525 | - $this->debug('Authorization header not set for certificate'); |
|
526 | - } elseif ($authtype == 'ntlm') { |
|
527 | - // do nothing |
|
528 | - $this->debug('Authorization header not set for ntlm'); |
|
529 | - } |
|
530 | - $this->username = $username; |
|
531 | - $this->password = $password; |
|
532 | - $this->authtype = $authtype; |
|
533 | - $this->digestRequest = $digestRequest; |
|
534 | - } |
|
521 | + $this->setHeader('Authorization', 'Digest username="' . $username . '", realm="' . $digestRequest['realm'] . '", nonce="' . $nonce . '", uri="' . $this->digest_uri . $opaque . '", cnonce="' . $cnonce . '", nc=' . sprintf("%08x", $digestRequest['nc']) . ', qop="' . $digestRequest['qop'] . '", response="' . $hashedDigest . '"'); |
|
522 | + } |
|
523 | + } elseif ($authtype == 'certificate') { |
|
524 | + $this->certRequest = $certRequest; |
|
525 | + $this->debug('Authorization header not set for certificate'); |
|
526 | + } elseif ($authtype == 'ntlm') { |
|
527 | + // do nothing |
|
528 | + $this->debug('Authorization header not set for ntlm'); |
|
529 | + } |
|
530 | + $this->username = $username; |
|
531 | + $this->password = $password; |
|
532 | + $this->authtype = $authtype; |
|
533 | + $this->digestRequest = $digestRequest; |
|
534 | + } |
|
535 | 535 | |
536 | - /** |
|
537 | - * set the soapaction value |
|
538 | - * |
|
539 | - * @param string $soapaction |
|
540 | - * @access public |
|
541 | - */ |
|
542 | - function setSOAPAction($soapaction) { |
|
543 | - $this->setHeader('SOAPAction', '"' . $soapaction . '"'); |
|
544 | - } |
|
536 | + /** |
|
537 | + * set the soapaction value |
|
538 | + * |
|
539 | + * @param string $soapaction |
|
540 | + * @access public |
|
541 | + */ |
|
542 | + function setSOAPAction($soapaction) { |
|
543 | + $this->setHeader('SOAPAction', '"' . $soapaction . '"'); |
|
544 | + } |
|
545 | 545 | |
546 | - /** |
|
547 | - * use http encoding |
|
548 | - * |
|
549 | - * @param string $enc encoding style. supported values: gzip, deflate, or both |
|
550 | - * @access public |
|
551 | - */ |
|
552 | - function setEncoding($enc='gzip, deflate') { |
|
553 | - if (function_exists('gzdeflate')) { |
|
554 | - $this->protocol_version = '1.1'; |
|
555 | - $this->setHeader('Accept-Encoding', $enc); |
|
556 | - if (!isset($this->outgoing_headers['Connection'])) { |
|
557 | - $this->setHeader('Connection', 'close'); |
|
558 | - $this->persistentConnection = false; |
|
559 | - } |
|
560 | - // deprecated as of PHP 5.3.0 |
|
561 | - //set_magic_quotes_runtime(0); |
|
562 | - $this->encoding = $enc; |
|
563 | - } |
|
564 | - } |
|
546 | + /** |
|
547 | + * use http encoding |
|
548 | + * |
|
549 | + * @param string $enc encoding style. supported values: gzip, deflate, or both |
|
550 | + * @access public |
|
551 | + */ |
|
552 | + function setEncoding($enc='gzip, deflate') { |
|
553 | + if (function_exists('gzdeflate')) { |
|
554 | + $this->protocol_version = '1.1'; |
|
555 | + $this->setHeader('Accept-Encoding', $enc); |
|
556 | + if (!isset($this->outgoing_headers['Connection'])) { |
|
557 | + $this->setHeader('Connection', 'close'); |
|
558 | + $this->persistentConnection = false; |
|
559 | + } |
|
560 | + // deprecated as of PHP 5.3.0 |
|
561 | + //set_magic_quotes_runtime(0); |
|
562 | + $this->encoding = $enc; |
|
563 | + } |
|
564 | + } |
|
565 | 565 | |
566 | - /** |
|
567 | - * set proxy info here |
|
568 | - * |
|
569 | - * @param string $proxyhost use an empty string to remove proxy |
|
570 | - * @param string $proxyport |
|
571 | - * @param string $proxyusername |
|
572 | - * @param string $proxypassword |
|
573 | - * @param string $proxyauthtype (basic|ntlm) |
|
574 | - * @access public |
|
575 | - */ |
|
576 | - function setProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '', $proxyauthtype = 'basic') { |
|
577 | - if ($proxyhost) { |
|
578 | - $this->proxy = array( |
|
579 | - 'host' => $proxyhost, |
|
580 | - 'port' => $proxyport, |
|
581 | - 'username' => $proxyusername, |
|
582 | - 'password' => $proxypassword, |
|
583 | - 'authtype' => $proxyauthtype |
|
584 | - ); |
|
585 | - if ($proxyusername != '' && $proxypassword != '' && $proxyauthtype = 'basic') { |
|
586 | - $this->setHeader('Proxy-Authorization', ' Basic '.base64_encode($proxyusername.':'.$proxypassword)); |
|
587 | - } |
|
588 | - } else { |
|
589 | - $this->debug('remove proxy'); |
|
590 | - $proxy = null; |
|
591 | - unsetHeader('Proxy-Authorization'); |
|
592 | - } |
|
593 | - } |
|
566 | + /** |
|
567 | + * set proxy info here |
|
568 | + * |
|
569 | + * @param string $proxyhost use an empty string to remove proxy |
|
570 | + * @param string $proxyport |
|
571 | + * @param string $proxyusername |
|
572 | + * @param string $proxypassword |
|
573 | + * @param string $proxyauthtype (basic|ntlm) |
|
574 | + * @access public |
|
575 | + */ |
|
576 | + function setProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '', $proxyauthtype = 'basic') { |
|
577 | + if ($proxyhost) { |
|
578 | + $this->proxy = array( |
|
579 | + 'host' => $proxyhost, |
|
580 | + 'port' => $proxyport, |
|
581 | + 'username' => $proxyusername, |
|
582 | + 'password' => $proxypassword, |
|
583 | + 'authtype' => $proxyauthtype |
|
584 | + ); |
|
585 | + if ($proxyusername != '' && $proxypassword != '' && $proxyauthtype = 'basic') { |
|
586 | + $this->setHeader('Proxy-Authorization', ' Basic '.base64_encode($proxyusername.':'.$proxypassword)); |
|
587 | + } |
|
588 | + } else { |
|
589 | + $this->debug('remove proxy'); |
|
590 | + $proxy = null; |
|
591 | + unsetHeader('Proxy-Authorization'); |
|
592 | + } |
|
593 | + } |
|
594 | 594 | |
595 | 595 | |
596 | - /** |
|
597 | - * Test if the given string starts with a header that is to be skipped. |
|
598 | - * Skippable headers result from chunked transfer and proxy requests. |
|
599 | - * |
|
600 | - * @param string $data The string to check. |
|
601 | - * @returns boolean Whether a skippable header was found. |
|
602 | - * @access private |
|
603 | - */ |
|
604 | - function isSkippableCurlHeader(&$data) { |
|
605 | - $skipHeaders = array( 'HTTP/1.1 100', |
|
606 | - 'HTTP/1.0 301', |
|
607 | - 'HTTP/1.1 301', |
|
608 | - 'HTTP/1.0 302', |
|
609 | - 'HTTP/1.1 302', |
|
610 | - 'HTTP/1.0 401', |
|
611 | - 'HTTP/1.1 401', |
|
612 | - 'HTTP/1.0 200 Connection established'); |
|
613 | - foreach ($skipHeaders as $hd) { |
|
614 | - $prefix = substr($data, 0, strlen($hd)); |
|
615 | - if ($prefix == $hd) return true; |
|
616 | - } |
|
596 | + /** |
|
597 | + * Test if the given string starts with a header that is to be skipped. |
|
598 | + * Skippable headers result from chunked transfer and proxy requests. |
|
599 | + * |
|
600 | + * @param string $data The string to check. |
|
601 | + * @returns boolean Whether a skippable header was found. |
|
602 | + * @access private |
|
603 | + */ |
|
604 | + function isSkippableCurlHeader(&$data) { |
|
605 | + $skipHeaders = array( 'HTTP/1.1 100', |
|
606 | + 'HTTP/1.0 301', |
|
607 | + 'HTTP/1.1 301', |
|
608 | + 'HTTP/1.0 302', |
|
609 | + 'HTTP/1.1 302', |
|
610 | + 'HTTP/1.0 401', |
|
611 | + 'HTTP/1.1 401', |
|
612 | + 'HTTP/1.0 200 Connection established'); |
|
613 | + foreach ($skipHeaders as $hd) { |
|
614 | + $prefix = substr($data, 0, strlen($hd)); |
|
615 | + if ($prefix == $hd) return true; |
|
616 | + } |
|
617 | 617 | |
618 | - return false; |
|
619 | - } |
|
618 | + return false; |
|
619 | + } |
|
620 | 620 | |
621 | - /** |
|
622 | - * decode a string that is encoded w/ "chunked' transfer encoding |
|
623 | - * as defined in RFC2068 19.4.6 |
|
624 | - * |
|
625 | - * @param string $buffer |
|
626 | - * @param string $lb |
|
627 | - * @returns string |
|
628 | - * @access public |
|
629 | - * @deprecated |
|
630 | - */ |
|
631 | - function decodeChunked($buffer, $lb){ |
|
632 | - // length := 0 |
|
633 | - $length = 0; |
|
634 | - $new = ''; |
|
621 | + /** |
|
622 | + * decode a string that is encoded w/ "chunked' transfer encoding |
|
623 | + * as defined in RFC2068 19.4.6 |
|
624 | + * |
|
625 | + * @param string $buffer |
|
626 | + * @param string $lb |
|
627 | + * @returns string |
|
628 | + * @access public |
|
629 | + * @deprecated |
|
630 | + */ |
|
631 | + function decodeChunked($buffer, $lb){ |
|
632 | + // length := 0 |
|
633 | + $length = 0; |
|
634 | + $new = ''; |
|
635 | 635 | |
636 | - // read chunk-size, chunk-extension (if any) and CRLF |
|
637 | - // get the position of the linebreak |
|
638 | - $chunkend = strpos($buffer, $lb); |
|
639 | - if ($chunkend == FALSE) { |
|
640 | - $this->debug('no linebreak found in decodeChunked'); |
|
641 | - return $new; |
|
642 | - } |
|
643 | - $temp = substr($buffer,0,$chunkend); |
|
644 | - $chunk_size = hexdec( trim($temp) ); |
|
645 | - $chunkstart = $chunkend + strlen($lb); |
|
646 | - // while (chunk-size > 0) { |
|
647 | - while ($chunk_size > 0) { |
|
648 | - $this->debug("chunkstart: $chunkstart chunk_size: $chunk_size"); |
|
649 | - $chunkend = strpos( $buffer, $lb, $chunkstart + $chunk_size); |
|
636 | + // read chunk-size, chunk-extension (if any) and CRLF |
|
637 | + // get the position of the linebreak |
|
638 | + $chunkend = strpos($buffer, $lb); |
|
639 | + if ($chunkend == FALSE) { |
|
640 | + $this->debug('no linebreak found in decodeChunked'); |
|
641 | + return $new; |
|
642 | + } |
|
643 | + $temp = substr($buffer,0,$chunkend); |
|
644 | + $chunk_size = hexdec( trim($temp) ); |
|
645 | + $chunkstart = $chunkend + strlen($lb); |
|
646 | + // while (chunk-size > 0) { |
|
647 | + while ($chunk_size > 0) { |
|
648 | + $this->debug("chunkstart: $chunkstart chunk_size: $chunk_size"); |
|
649 | + $chunkend = strpos( $buffer, $lb, $chunkstart + $chunk_size); |
|
650 | 650 | |
651 | - // Just in case we got a broken connection |
|
652 | - if ($chunkend == FALSE) { |
|
653 | - $chunk = substr($buffer,$chunkstart); |
|
654 | - // append chunk-data to entity-body |
|
655 | - $new .= $chunk; |
|
656 | - $length += strlen($chunk); |
|
657 | - break; |
|
658 | - } |
|
651 | + // Just in case we got a broken connection |
|
652 | + if ($chunkend == FALSE) { |
|
653 | + $chunk = substr($buffer,$chunkstart); |
|
654 | + // append chunk-data to entity-body |
|
655 | + $new .= $chunk; |
|
656 | + $length += strlen($chunk); |
|
657 | + break; |
|
658 | + } |
|
659 | 659 | |
660 | - // read chunk-data and CRLF |
|
661 | - $chunk = substr($buffer,$chunkstart,$chunkend-$chunkstart); |
|
662 | - // append chunk-data to entity-body |
|
663 | - $new .= $chunk; |
|
664 | - // length := length + chunk-size |
|
665 | - $length += strlen($chunk); |
|
666 | - // read chunk-size and CRLF |
|
667 | - $chunkstart = $chunkend + strlen($lb); |
|
660 | + // read chunk-data and CRLF |
|
661 | + $chunk = substr($buffer,$chunkstart,$chunkend-$chunkstart); |
|
662 | + // append chunk-data to entity-body |
|
663 | + $new .= $chunk; |
|
664 | + // length := length + chunk-size |
|
665 | + $length += strlen($chunk); |
|
666 | + // read chunk-size and CRLF |
|
667 | + $chunkstart = $chunkend + strlen($lb); |
|
668 | 668 | |
669 | - $chunkend = strpos($buffer, $lb, $chunkstart) + strlen($lb); |
|
670 | - if ($chunkend == FALSE) { |
|
671 | - break; //Just in case we got a broken connection |
|
672 | - } |
|
673 | - $temp = substr($buffer,$chunkstart,$chunkend-$chunkstart); |
|
674 | - $chunk_size = hexdec( trim($temp) ); |
|
675 | - $chunkstart = $chunkend; |
|
676 | - } |
|
677 | - return $new; |
|
678 | - } |
|
669 | + $chunkend = strpos($buffer, $lb, $chunkstart) + strlen($lb); |
|
670 | + if ($chunkend == FALSE) { |
|
671 | + break; //Just in case we got a broken connection |
|
672 | + } |
|
673 | + $temp = substr($buffer,$chunkstart,$chunkend-$chunkstart); |
|
674 | + $chunk_size = hexdec( trim($temp) ); |
|
675 | + $chunkstart = $chunkend; |
|
676 | + } |
|
677 | + return $new; |
|
678 | + } |
|
679 | 679 | |
680 | - /** |
|
681 | - * Writes the payload, including HTTP headers, to $this->outgoing_payload. |
|
682 | - * |
|
683 | - * @param string $data HTTP body |
|
684 | - * @param string $cookie_str data for HTTP Cookie header |
|
685 | - * @return void |
|
686 | - * @access private |
|
687 | - */ |
|
688 | - function buildPayload($data, $cookie_str = '') { |
|
689 | - // Note: for cURL connections, $this->outgoing_payload is ignored, |
|
690 | - // as is the Content-Length header, but these are still created as |
|
691 | - // debugging guides. |
|
680 | + /** |
|
681 | + * Writes the payload, including HTTP headers, to $this->outgoing_payload. |
|
682 | + * |
|
683 | + * @param string $data HTTP body |
|
684 | + * @param string $cookie_str data for HTTP Cookie header |
|
685 | + * @return void |
|
686 | + * @access private |
|
687 | + */ |
|
688 | + function buildPayload($data, $cookie_str = '') { |
|
689 | + // Note: for cURL connections, $this->outgoing_payload is ignored, |
|
690 | + // as is the Content-Length header, but these are still created as |
|
691 | + // debugging guides. |
|
692 | 692 | |
693 | - // add content-length header |
|
694 | - if ($this->request_method != 'GET') { |
|
695 | - $this->setHeader('Content-Length', strlen($data)); |
|
696 | - } |
|
693 | + // add content-length header |
|
694 | + if ($this->request_method != 'GET') { |
|
695 | + $this->setHeader('Content-Length', strlen($data)); |
|
696 | + } |
|
697 | 697 | |
698 | - // start building outgoing payload: |
|
699 | - if ($this->proxy) { |
|
700 | - $uri = $this->url; |
|
701 | - } else { |
|
702 | - $uri = $this->uri; |
|
703 | - } |
|
704 | - $req = "$this->request_method $uri HTTP/$this->protocol_version"; |
|
705 | - $this->debug("HTTP request: $req"); |
|
706 | - $this->outgoing_payload = "$req\r\n"; |
|
698 | + // start building outgoing payload: |
|
699 | + if ($this->proxy) { |
|
700 | + $uri = $this->url; |
|
701 | + } else { |
|
702 | + $uri = $this->uri; |
|
703 | + } |
|
704 | + $req = "$this->request_method $uri HTTP/$this->protocol_version"; |
|
705 | + $this->debug("HTTP request: $req"); |
|
706 | + $this->outgoing_payload = "$req\r\n"; |
|
707 | 707 | |
708 | - // loop thru headers, serializing |
|
709 | - foreach($this->outgoing_headers as $k => $v){ |
|
710 | - $hdr = $k.': '.$v; |
|
711 | - $this->debug("HTTP header: $hdr"); |
|
712 | - $this->outgoing_payload .= "$hdr\r\n"; |
|
713 | - } |
|
708 | + // loop thru headers, serializing |
|
709 | + foreach($this->outgoing_headers as $k => $v){ |
|
710 | + $hdr = $k.': '.$v; |
|
711 | + $this->debug("HTTP header: $hdr"); |
|
712 | + $this->outgoing_payload .= "$hdr\r\n"; |
|
713 | + } |
|
714 | 714 | |
715 | - // add any cookies |
|
716 | - if ($cookie_str != '') { |
|
717 | - $hdr = 'Cookie: '.$cookie_str; |
|
718 | - $this->debug("HTTP header: $hdr"); |
|
719 | - $this->outgoing_payload .= "$hdr\r\n"; |
|
720 | - } |
|
715 | + // add any cookies |
|
716 | + if ($cookie_str != '') { |
|
717 | + $hdr = 'Cookie: '.$cookie_str; |
|
718 | + $this->debug("HTTP header: $hdr"); |
|
719 | + $this->outgoing_payload .= "$hdr\r\n"; |
|
720 | + } |
|
721 | 721 | |
722 | - // header/body separator |
|
723 | - $this->outgoing_payload .= "\r\n"; |
|
722 | + // header/body separator |
|
723 | + $this->outgoing_payload .= "\r\n"; |
|
724 | 724 | |
725 | - // add data |
|
726 | - $this->outgoing_payload .= $data; |
|
727 | - } |
|
725 | + // add data |
|
726 | + $this->outgoing_payload .= $data; |
|
727 | + } |
|
728 | 728 | |
729 | - /** |
|
730 | - * sends the SOAP request via HTTP[S] |
|
731 | - * |
|
732 | - * @param string $data message data |
|
733 | - * @param array $cookies cookies to send |
|
734 | - * @return boolean true if OK, false if problem |
|
735 | - * @access private |
|
736 | - */ |
|
737 | - function sendRequest($data, $cookies = NULL) { |
|
738 | - // build cookie string |
|
739 | - $cookie_str = $this->getCookiesForRequest($cookies, (($this->scheme == 'ssl') || ($this->scheme == 'https'))); |
|
729 | + /** |
|
730 | + * sends the SOAP request via HTTP[S] |
|
731 | + * |
|
732 | + * @param string $data message data |
|
733 | + * @param array $cookies cookies to send |
|
734 | + * @return boolean true if OK, false if problem |
|
735 | + * @access private |
|
736 | + */ |
|
737 | + function sendRequest($data, $cookies = NULL) { |
|
738 | + // build cookie string |
|
739 | + $cookie_str = $this->getCookiesForRequest($cookies, (($this->scheme == 'ssl') || ($this->scheme == 'https'))); |
|
740 | 740 | |
741 | - // build payload |
|
742 | - $this->buildPayload($data, $cookie_str); |
|
741 | + // build payload |
|
742 | + $this->buildPayload($data, $cookie_str); |
|
743 | 743 | |
744 | - if ($this->io_method() == 'socket') { |
|
745 | - // send payload |
|
746 | - if(!fputs($this->fp, $this->outgoing_payload, strlen($this->outgoing_payload))) { |
|
747 | - $this->setError('couldn\'t write message data to socket'); |
|
748 | - $this->debug('couldn\'t write message data to socket'); |
|
749 | - return false; |
|
750 | - } |
|
751 | - $this->debug('wrote data to socket, length = ' . strlen($this->outgoing_payload)); |
|
752 | - return true; |
|
753 | - } else if ($this->io_method() == 'curl') { |
|
754 | - // set payload |
|
755 | - // cURL does say this should only be the verb, and in fact it |
|
756 | - // turns out that the URI and HTTP version are appended to this, which |
|
757 | - // some servers refuse to work with (so we no longer use this method!) |
|
758 | - //$this->setCurlOption(CURLOPT_CUSTOMREQUEST, $this->outgoing_payload); |
|
759 | - $curl_headers = array(); |
|
760 | - foreach($this->outgoing_headers as $k => $v){ |
|
761 | - if ($k == 'Connection' || $k == 'Content-Length' || $k == 'Host' || $k == 'Authorization' || $k == 'Proxy-Authorization') { |
|
762 | - $this->debug("Skip cURL header $k: $v"); |
|
763 | - } else { |
|
764 | - $curl_headers[] = "$k: $v"; |
|
765 | - } |
|
766 | - } |
|
767 | - if ($cookie_str != '') { |
|
768 | - $curl_headers[] = 'Cookie: ' . $cookie_str; |
|
769 | - } |
|
770 | - $this->setCurlOption(CURLOPT_HTTPHEADER, $curl_headers); |
|
771 | - $this->debug('set cURL HTTP headers'); |
|
772 | - if ($this->request_method == "POST") { |
|
773 | - $this->setCurlOption(CURLOPT_POST, 1); |
|
774 | - $this->setCurlOption(CURLOPT_POSTFIELDS, $data); |
|
775 | - $this->debug('set cURL POST data'); |
|
776 | - } else { |
|
777 | - } |
|
778 | - // insert custom user-set cURL options |
|
779 | - foreach ($this->ch_options as $key => $val) { |
|
780 | - $this->setCurlOption($key, $val); |
|
781 | - } |
|
744 | + if ($this->io_method() == 'socket') { |
|
745 | + // send payload |
|
746 | + if(!fputs($this->fp, $this->outgoing_payload, strlen($this->outgoing_payload))) { |
|
747 | + $this->setError('couldn\'t write message data to socket'); |
|
748 | + $this->debug('couldn\'t write message data to socket'); |
|
749 | + return false; |
|
750 | + } |
|
751 | + $this->debug('wrote data to socket, length = ' . strlen($this->outgoing_payload)); |
|
752 | + return true; |
|
753 | + } else if ($this->io_method() == 'curl') { |
|
754 | + // set payload |
|
755 | + // cURL does say this should only be the verb, and in fact it |
|
756 | + // turns out that the URI and HTTP version are appended to this, which |
|
757 | + // some servers refuse to work with (so we no longer use this method!) |
|
758 | + //$this->setCurlOption(CURLOPT_CUSTOMREQUEST, $this->outgoing_payload); |
|
759 | + $curl_headers = array(); |
|
760 | + foreach($this->outgoing_headers as $k => $v){ |
|
761 | + if ($k == 'Connection' || $k == 'Content-Length' || $k == 'Host' || $k == 'Authorization' || $k == 'Proxy-Authorization') { |
|
762 | + $this->debug("Skip cURL header $k: $v"); |
|
763 | + } else { |
|
764 | + $curl_headers[] = "$k: $v"; |
|
765 | + } |
|
766 | + } |
|
767 | + if ($cookie_str != '') { |
|
768 | + $curl_headers[] = 'Cookie: ' . $cookie_str; |
|
769 | + } |
|
770 | + $this->setCurlOption(CURLOPT_HTTPHEADER, $curl_headers); |
|
771 | + $this->debug('set cURL HTTP headers'); |
|
772 | + if ($this->request_method == "POST") { |
|
773 | + $this->setCurlOption(CURLOPT_POST, 1); |
|
774 | + $this->setCurlOption(CURLOPT_POSTFIELDS, $data); |
|
775 | + $this->debug('set cURL POST data'); |
|
776 | + } else { |
|
777 | + } |
|
778 | + // insert custom user-set cURL options |
|
779 | + foreach ($this->ch_options as $key => $val) { |
|
780 | + $this->setCurlOption($key, $val); |
|
781 | + } |
|
782 | 782 | |
783 | - $this->debug('set cURL payload'); |
|
784 | - return true; |
|
785 | - } |
|
786 | - } |
|
783 | + $this->debug('set cURL payload'); |
|
784 | + return true; |
|
785 | + } |
|
786 | + } |
|
787 | 787 | |
788 | - /** |
|
789 | - * gets the SOAP response via HTTP[S] |
|
790 | - * |
|
791 | - * @return string the response (also sets member variables like incoming_payload) |
|
792 | - * @access private |
|
793 | - */ |
|
794 | - function getResponse(){ |
|
795 | - $this->incoming_payload = ''; |
|
788 | + /** |
|
789 | + * gets the SOAP response via HTTP[S] |
|
790 | + * |
|
791 | + * @return string the response (also sets member variables like incoming_payload) |
|
792 | + * @access private |
|
793 | + */ |
|
794 | + function getResponse(){ |
|
795 | + $this->incoming_payload = ''; |
|
796 | 796 | |
797 | - if ($this->io_method() == 'socket') { |
|
798 | - // loop until headers have been retrieved |
|
799 | - $data = ''; |
|
800 | - while (!isset($lb)){ |
|
797 | + if ($this->io_method() == 'socket') { |
|
798 | + // loop until headers have been retrieved |
|
799 | + $data = ''; |
|
800 | + while (!isset($lb)){ |
|
801 | 801 | |
802 | - // We might EOF during header read. |
|
803 | - if(feof($this->fp)) { |
|
804 | - $this->incoming_payload = $data; |
|
805 | - $this->debug('found no headers before EOF after length ' . strlen($data)); |
|
806 | - $this->debug("received before EOF:\n" . $data); |
|
807 | - $this->setError('server failed to send headers'); |
|
808 | - return false; |
|
809 | - } |
|
802 | + // We might EOF during header read. |
|
803 | + if(feof($this->fp)) { |
|
804 | + $this->incoming_payload = $data; |
|
805 | + $this->debug('found no headers before EOF after length ' . strlen($data)); |
|
806 | + $this->debug("received before EOF:\n" . $data); |
|
807 | + $this->setError('server failed to send headers'); |
|
808 | + return false; |
|
809 | + } |
|
810 | 810 | |
811 | - $tmp = fgets($this->fp, 256); |
|
812 | - $tmplen = strlen($tmp); |
|
813 | - $this->debug("read line of $tmplen bytes: " . trim($tmp)); |
|
811 | + $tmp = fgets($this->fp, 256); |
|
812 | + $tmplen = strlen($tmp); |
|
813 | + $this->debug("read line of $tmplen bytes: " . trim($tmp)); |
|
814 | 814 | |
815 | - if ($tmplen == 0) { |
|
816 | - $this->incoming_payload = $data; |
|
817 | - $this->debug('socket read of headers timed out after length ' . strlen($data)); |
|
818 | - $this->debug("read before timeout: " . $data); |
|
819 | - $this->setError('socket read of headers timed out'); |
|
820 | - return false; |
|
821 | - } |
|
815 | + if ($tmplen == 0) { |
|
816 | + $this->incoming_payload = $data; |
|
817 | + $this->debug('socket read of headers timed out after length ' . strlen($data)); |
|
818 | + $this->debug("read before timeout: " . $data); |
|
819 | + $this->setError('socket read of headers timed out'); |
|
820 | + return false; |
|
821 | + } |
|
822 | 822 | |
823 | - $data .= $tmp; |
|
824 | - $pos = strpos($data,"\r\n\r\n"); |
|
825 | - if($pos > 1){ |
|
826 | - $lb = "\r\n"; |
|
827 | - } else { |
|
828 | - $pos = strpos($data,"\n\n"); |
|
829 | - if($pos > 1){ |
|
830 | - $lb = "\n"; |
|
831 | - } |
|
832 | - } |
|
833 | - // remove 100 headers |
|
834 | - if (isset($lb) && preg_match('/^HTTP\/1.1 100/',$data)) { |
|
835 | - unset($lb); |
|
836 | - $data = ''; |
|
837 | - }// |
|
838 | - } |
|
839 | - // store header data |
|
840 | - $this->incoming_payload .= $data; |
|
841 | - $this->debug('found end of headers after length ' . strlen($data)); |
|
842 | - // process headers |
|
843 | - $header_data = trim(substr($data,0,$pos)); |
|
844 | - $header_array = explode($lb,$header_data); |
|
845 | - $this->incoming_headers = array(); |
|
846 | - $this->incoming_cookies = array(); |
|
847 | - foreach($header_array as $header_line){ |
|
848 | - $arr = explode(':',$header_line, 2); |
|
849 | - if(count($arr) > 1){ |
|
850 | - $header_name = strtolower(trim($arr[0])); |
|
851 | - $this->incoming_headers[$header_name] = trim($arr[1]); |
|
852 | - if ($header_name == 'set-cookie') { |
|
853 | - // TODO: allow multiple cookies from parseCookie |
|
854 | - $cookie = $this->parseCookie(trim($arr[1])); |
|
855 | - if ($cookie) { |
|
856 | - $this->incoming_cookies[] = $cookie; |
|
857 | - $this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']); |
|
858 | - } else { |
|
859 | - $this->debug('did not find cookie in ' . trim($arr[1])); |
|
860 | - } |
|
861 | - } |
|
862 | - } else if (isset($header_name)) { |
|
863 | - // append continuation line to previous header |
|
864 | - $this->incoming_headers[$header_name] .= $lb . ' ' . $header_line; |
|
865 | - } |
|
866 | - } |
|
823 | + $data .= $tmp; |
|
824 | + $pos = strpos($data,"\r\n\r\n"); |
|
825 | + if($pos > 1){ |
|
826 | + $lb = "\r\n"; |
|
827 | + } else { |
|
828 | + $pos = strpos($data,"\n\n"); |
|
829 | + if($pos > 1){ |
|
830 | + $lb = "\n"; |
|
831 | + } |
|
832 | + } |
|
833 | + // remove 100 headers |
|
834 | + if (isset($lb) && preg_match('/^HTTP\/1.1 100/',$data)) { |
|
835 | + unset($lb); |
|
836 | + $data = ''; |
|
837 | + }// |
|
838 | + } |
|
839 | + // store header data |
|
840 | + $this->incoming_payload .= $data; |
|
841 | + $this->debug('found end of headers after length ' . strlen($data)); |
|
842 | + // process headers |
|
843 | + $header_data = trim(substr($data,0,$pos)); |
|
844 | + $header_array = explode($lb,$header_data); |
|
845 | + $this->incoming_headers = array(); |
|
846 | + $this->incoming_cookies = array(); |
|
847 | + foreach($header_array as $header_line){ |
|
848 | + $arr = explode(':',$header_line, 2); |
|
849 | + if(count($arr) > 1){ |
|
850 | + $header_name = strtolower(trim($arr[0])); |
|
851 | + $this->incoming_headers[$header_name] = trim($arr[1]); |
|
852 | + if ($header_name == 'set-cookie') { |
|
853 | + // TODO: allow multiple cookies from parseCookie |
|
854 | + $cookie = $this->parseCookie(trim($arr[1])); |
|
855 | + if ($cookie) { |
|
856 | + $this->incoming_cookies[] = $cookie; |
|
857 | + $this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']); |
|
858 | + } else { |
|
859 | + $this->debug('did not find cookie in ' . trim($arr[1])); |
|
860 | + } |
|
861 | + } |
|
862 | + } else if (isset($header_name)) { |
|
863 | + // append continuation line to previous header |
|
864 | + $this->incoming_headers[$header_name] .= $lb . ' ' . $header_line; |
|
865 | + } |
|
866 | + } |
|
867 | 867 | |
868 | - // loop until msg has been received |
|
869 | - if (isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked') { |
|
870 | - $content_length = 2147483647; // ignore any content-length header |
|
871 | - $chunked = true; |
|
872 | - $this->debug("want to read chunked content"); |
|
873 | - } elseif (isset($this->incoming_headers['content-length'])) { |
|
874 | - $content_length = $this->incoming_headers['content-length']; |
|
875 | - $chunked = false; |
|
876 | - $this->debug("want to read content of length $content_length"); |
|
877 | - } else { |
|
878 | - $content_length = 2147483647; |
|
879 | - $chunked = false; |
|
880 | - $this->debug("want to read content to EOF"); |
|
881 | - } |
|
882 | - $data = ''; |
|
883 | - do { |
|
884 | - if ($chunked) { |
|
885 | - $tmp = fgets($this->fp, 256); |
|
886 | - $tmplen = strlen($tmp); |
|
887 | - $this->debug("read chunk line of $tmplen bytes"); |
|
888 | - if ($tmplen == 0) { |
|
889 | - $this->incoming_payload = $data; |
|
890 | - $this->debug('socket read of chunk length timed out after length ' . strlen($data)); |
|
891 | - $this->debug("read before timeout:\n" . $data); |
|
892 | - $this->setError('socket read of chunk length timed out'); |
|
893 | - return false; |
|
894 | - } |
|
895 | - $content_length = hexdec(trim($tmp)); |
|
896 | - $this->debug("chunk length $content_length"); |
|
897 | - } |
|
898 | - $strlen = 0; |
|
899 | - while (($strlen < $content_length) && (!feof($this->fp))) { |
|
900 | - $readlen = min(8192, $content_length - $strlen); |
|
901 | - $tmp = fread($this->fp, $readlen); |
|
902 | - $tmplen = strlen($tmp); |
|
903 | - $this->debug("read buffer of $tmplen bytes"); |
|
904 | - if (($tmplen == 0) && (!feof($this->fp))) { |
|
905 | - $this->incoming_payload = $data; |
|
906 | - $this->debug('socket read of body timed out after length ' . strlen($data)); |
|
907 | - $this->debug("read before timeout:\n" . $data); |
|
908 | - $this->setError('socket read of body timed out'); |
|
909 | - return false; |
|
910 | - } |
|
911 | - $strlen += $tmplen; |
|
912 | - $data .= $tmp; |
|
913 | - } |
|
914 | - if ($chunked && ($content_length > 0)) { |
|
915 | - $tmp = fgets($this->fp, 256); |
|
916 | - $tmplen = strlen($tmp); |
|
917 | - $this->debug("read chunk terminator of $tmplen bytes"); |
|
918 | - if ($tmplen == 0) { |
|
919 | - $this->incoming_payload = $data; |
|
920 | - $this->debug('socket read of chunk terminator timed out after length ' . strlen($data)); |
|
921 | - $this->debug("read before timeout:\n" . $data); |
|
922 | - $this->setError('socket read of chunk terminator timed out'); |
|
923 | - return false; |
|
924 | - } |
|
925 | - } |
|
926 | - } while ($chunked && ($content_length > 0) && (!feof($this->fp))); |
|
927 | - if (feof($this->fp)) { |
|
928 | - $this->debug('read to EOF'); |
|
929 | - } |
|
930 | - $this->debug('read body of length ' . strlen($data)); |
|
931 | - $this->incoming_payload .= $data; |
|
932 | - $this->debug('received a total of '.strlen($this->incoming_payload).' bytes of data from server'); |
|
868 | + // loop until msg has been received |
|
869 | + if (isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked') { |
|
870 | + $content_length = 2147483647; // ignore any content-length header |
|
871 | + $chunked = true; |
|
872 | + $this->debug("want to read chunked content"); |
|
873 | + } elseif (isset($this->incoming_headers['content-length'])) { |
|
874 | + $content_length = $this->incoming_headers['content-length']; |
|
875 | + $chunked = false; |
|
876 | + $this->debug("want to read content of length $content_length"); |
|
877 | + } else { |
|
878 | + $content_length = 2147483647; |
|
879 | + $chunked = false; |
|
880 | + $this->debug("want to read content to EOF"); |
|
881 | + } |
|
882 | + $data = ''; |
|
883 | + do { |
|
884 | + if ($chunked) { |
|
885 | + $tmp = fgets($this->fp, 256); |
|
886 | + $tmplen = strlen($tmp); |
|
887 | + $this->debug("read chunk line of $tmplen bytes"); |
|
888 | + if ($tmplen == 0) { |
|
889 | + $this->incoming_payload = $data; |
|
890 | + $this->debug('socket read of chunk length timed out after length ' . strlen($data)); |
|
891 | + $this->debug("read before timeout:\n" . $data); |
|
892 | + $this->setError('socket read of chunk length timed out'); |
|
893 | + return false; |
|
894 | + } |
|
895 | + $content_length = hexdec(trim($tmp)); |
|
896 | + $this->debug("chunk length $content_length"); |
|
897 | + } |
|
898 | + $strlen = 0; |
|
899 | + while (($strlen < $content_length) && (!feof($this->fp))) { |
|
900 | + $readlen = min(8192, $content_length - $strlen); |
|
901 | + $tmp = fread($this->fp, $readlen); |
|
902 | + $tmplen = strlen($tmp); |
|
903 | + $this->debug("read buffer of $tmplen bytes"); |
|
904 | + if (($tmplen == 0) && (!feof($this->fp))) { |
|
905 | + $this->incoming_payload = $data; |
|
906 | + $this->debug('socket read of body timed out after length ' . strlen($data)); |
|
907 | + $this->debug("read before timeout:\n" . $data); |
|
908 | + $this->setError('socket read of body timed out'); |
|
909 | + return false; |
|
910 | + } |
|
911 | + $strlen += $tmplen; |
|
912 | + $data .= $tmp; |
|
913 | + } |
|
914 | + if ($chunked && ($content_length > 0)) { |
|
915 | + $tmp = fgets($this->fp, 256); |
|
916 | + $tmplen = strlen($tmp); |
|
917 | + $this->debug("read chunk terminator of $tmplen bytes"); |
|
918 | + if ($tmplen == 0) { |
|
919 | + $this->incoming_payload = $data; |
|
920 | + $this->debug('socket read of chunk terminator timed out after length ' . strlen($data)); |
|
921 | + $this->debug("read before timeout:\n" . $data); |
|
922 | + $this->setError('socket read of chunk terminator timed out'); |
|
923 | + return false; |
|
924 | + } |
|
925 | + } |
|
926 | + } while ($chunked && ($content_length > 0) && (!feof($this->fp))); |
|
927 | + if (feof($this->fp)) { |
|
928 | + $this->debug('read to EOF'); |
|
929 | + } |
|
930 | + $this->debug('read body of length ' . strlen($data)); |
|
931 | + $this->incoming_payload .= $data; |
|
932 | + $this->debug('received a total of '.strlen($this->incoming_payload).' bytes of data from server'); |
|
933 | 933 | |
934 | - // close filepointer |
|
935 | - if( |
|
936 | - (isset($this->incoming_headers['connection']) && strtolower($this->incoming_headers['connection']) == 'close') || |
|
937 | - (! $this->persistentConnection) || feof($this->fp)){ |
|
938 | - fclose($this->fp); |
|
939 | - $this->fp = false; |
|
940 | - $this->debug('closed socket'); |
|
941 | - } |
|
934 | + // close filepointer |
|
935 | + if( |
|
936 | + (isset($this->incoming_headers['connection']) && strtolower($this->incoming_headers['connection']) == 'close') || |
|
937 | + (! $this->persistentConnection) || feof($this->fp)){ |
|
938 | + fclose($this->fp); |
|
939 | + $this->fp = false; |
|
940 | + $this->debug('closed socket'); |
|
941 | + } |
|
942 | 942 | |
943 | - // connection was closed unexpectedly |
|
944 | - if($this->incoming_payload == ''){ |
|
945 | - $this->setError('no response from server'); |
|
946 | - return false; |
|
947 | - } |
|
943 | + // connection was closed unexpectedly |
|
944 | + if($this->incoming_payload == ''){ |
|
945 | + $this->setError('no response from server'); |
|
946 | + return false; |
|
947 | + } |
|
948 | 948 | |
949 | - // decode transfer-encoding |
|
949 | + // decode transfer-encoding |
|
950 | 950 | // if(isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked'){ |
951 | 951 | // if(!$data = $this->decodeChunked($data, $lb)){ |
952 | 952 | // $this->setError('Decoding of chunked data failed'); |
953 | 953 | // return false; |
954 | 954 | // } |
955 | - //print "<pre>\nde-chunked:\n---------------\n$data\n\n---------------\n</pre>"; |
|
956 | - // set decoded payload |
|
955 | + //print "<pre>\nde-chunked:\n---------------\n$data\n\n---------------\n</pre>"; |
|
956 | + // set decoded payload |
|
957 | 957 | // $this->incoming_payload = $header_data.$lb.$lb.$data; |
958 | 958 | // } |
959 | 959 | |
960 | - } else if ($this->io_method() == 'curl') { |
|
961 | - // send and receive |
|
962 | - $this->debug('send and receive with cURL'); |
|
963 | - $this->incoming_payload = curl_exec($this->ch); |
|
964 | - $data = $this->incoming_payload; |
|
960 | + } else if ($this->io_method() == 'curl') { |
|
961 | + // send and receive |
|
962 | + $this->debug('send and receive with cURL'); |
|
963 | + $this->incoming_payload = curl_exec($this->ch); |
|
964 | + $data = $this->incoming_payload; |
|
965 | 965 | |
966 | 966 | $cErr = curl_error($this->ch); |
967 | - if ($cErr != '') { |
|
968 | - $err = 'cURL ERROR: '.curl_errno($this->ch).': '.$cErr.'<br>'; |
|
969 | - // TODO: there is a PHP bug that can cause this to SEGV for CURLINFO_CONTENT_TYPE |
|
970 | - foreach(curl_getinfo($this->ch) as $k => $v){ |
|
971 | - $err .= "$k: $v<br>"; |
|
972 | - } |
|
973 | - $this->debug($err); |
|
974 | - $this->setError($err); |
|
975 | - curl_close($this->ch); |
|
976 | - return false; |
|
977 | - } else { |
|
978 | - //echo '<pre>'; |
|
979 | - //var_dump(curl_getinfo($this->ch)); |
|
980 | - //echo '</pre>'; |
|
981 | - } |
|
982 | - // close curl |
|
983 | - $this->debug('No cURL error, closing cURL'); |
|
984 | - curl_close($this->ch); |
|
967 | + if ($cErr != '') { |
|
968 | + $err = 'cURL ERROR: '.curl_errno($this->ch).': '.$cErr.'<br>'; |
|
969 | + // TODO: there is a PHP bug that can cause this to SEGV for CURLINFO_CONTENT_TYPE |
|
970 | + foreach(curl_getinfo($this->ch) as $k => $v){ |
|
971 | + $err .= "$k: $v<br>"; |
|
972 | + } |
|
973 | + $this->debug($err); |
|
974 | + $this->setError($err); |
|
975 | + curl_close($this->ch); |
|
976 | + return false; |
|
977 | + } else { |
|
978 | + //echo '<pre>'; |
|
979 | + //var_dump(curl_getinfo($this->ch)); |
|
980 | + //echo '</pre>'; |
|
981 | + } |
|
982 | + // close curl |
|
983 | + $this->debug('No cURL error, closing cURL'); |
|
984 | + curl_close($this->ch); |
|
985 | 985 | |
986 | - // try removing skippable headers |
|
987 | - $savedata = $data; |
|
988 | - while ($this->isSkippableCurlHeader($data)) { |
|
989 | - $this->debug("Found HTTP header to skip"); |
|
990 | - if ($pos = strpos($data,"\r\n\r\n")) { |
|
991 | - $data = ltrim(substr($data,$pos)); |
|
992 | - } elseif($pos = strpos($data,"\n\n") ) { |
|
993 | - $data = ltrim(substr($data,$pos)); |
|
994 | - } |
|
995 | - } |
|
986 | + // try removing skippable headers |
|
987 | + $savedata = $data; |
|
988 | + while ($this->isSkippableCurlHeader($data)) { |
|
989 | + $this->debug("Found HTTP header to skip"); |
|
990 | + if ($pos = strpos($data,"\r\n\r\n")) { |
|
991 | + $data = ltrim(substr($data,$pos)); |
|
992 | + } elseif($pos = strpos($data,"\n\n") ) { |
|
993 | + $data = ltrim(substr($data,$pos)); |
|
994 | + } |
|
995 | + } |
|
996 | 996 | |
997 | - if ($data == '') { |
|
998 | - // have nothing left; just remove 100 header(s) |
|
999 | - $data = $savedata; |
|
1000 | - while (preg_match('/^HTTP\/1.1 100/',$data)) { |
|
1001 | - if ($pos = strpos($data,"\r\n\r\n")) { |
|
1002 | - $data = ltrim(substr($data,$pos)); |
|
1003 | - } elseif($pos = strpos($data,"\n\n") ) { |
|
1004 | - $data = ltrim(substr($data,$pos)); |
|
1005 | - } |
|
1006 | - } |
|
1007 | - } |
|
997 | + if ($data == '') { |
|
998 | + // have nothing left; just remove 100 header(s) |
|
999 | + $data = $savedata; |
|
1000 | + while (preg_match('/^HTTP\/1.1 100/',$data)) { |
|
1001 | + if ($pos = strpos($data,"\r\n\r\n")) { |
|
1002 | + $data = ltrim(substr($data,$pos)); |
|
1003 | + } elseif($pos = strpos($data,"\n\n") ) { |
|
1004 | + $data = ltrim(substr($data,$pos)); |
|
1005 | + } |
|
1006 | + } |
|
1007 | + } |
|
1008 | 1008 | |
1009 | - // separate content from HTTP headers |
|
1010 | - if ($pos = strpos($data,"\r\n\r\n")) { |
|
1011 | - $lb = "\r\n"; |
|
1012 | - } elseif( $pos = strpos($data,"\n\n")) { |
|
1013 | - $lb = "\n"; |
|
1014 | - } else { |
|
1015 | - $this->debug('no proper separation of headers and document'); |
|
1016 | - $this->setError('no proper separation of headers and document'); |
|
1017 | - return false; |
|
1018 | - } |
|
1019 | - $header_data = trim(substr($data,0,$pos)); |
|
1020 | - $header_array = explode($lb,$header_data); |
|
1021 | - $data = ltrim(substr($data,$pos)); |
|
1022 | - $this->debug('found proper separation of headers and document'); |
|
1023 | - $this->debug('cleaned data, stringlen: '.strlen($data)); |
|
1024 | - // clean headers |
|
1025 | - foreach ($header_array as $header_line) { |
|
1026 | - $arr = explode(':',$header_line,2); |
|
1027 | - if(count($arr) > 1){ |
|
1028 | - $header_name = strtolower(trim($arr[0])); |
|
1029 | - $this->incoming_headers[$header_name] = trim($arr[1]); |
|
1030 | - if ($header_name == 'set-cookie') { |
|
1031 | - // TODO: allow multiple cookies from parseCookie |
|
1032 | - $cookie = $this->parseCookie(trim($arr[1])); |
|
1033 | - if ($cookie) { |
|
1034 | - $this->incoming_cookies[] = $cookie; |
|
1035 | - $this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']); |
|
1036 | - } else { |
|
1037 | - $this->debug('did not find cookie in ' . trim($arr[1])); |
|
1038 | - } |
|
1039 | - } |
|
1040 | - } else if (isset($header_name)) { |
|
1041 | - // append continuation line to previous header |
|
1042 | - $this->incoming_headers[$header_name] .= $lb . ' ' . $header_line; |
|
1043 | - } |
|
1044 | - } |
|
1045 | - } |
|
1009 | + // separate content from HTTP headers |
|
1010 | + if ($pos = strpos($data,"\r\n\r\n")) { |
|
1011 | + $lb = "\r\n"; |
|
1012 | + } elseif( $pos = strpos($data,"\n\n")) { |
|
1013 | + $lb = "\n"; |
|
1014 | + } else { |
|
1015 | + $this->debug('no proper separation of headers and document'); |
|
1016 | + $this->setError('no proper separation of headers and document'); |
|
1017 | + return false; |
|
1018 | + } |
|
1019 | + $header_data = trim(substr($data,0,$pos)); |
|
1020 | + $header_array = explode($lb,$header_data); |
|
1021 | + $data = ltrim(substr($data,$pos)); |
|
1022 | + $this->debug('found proper separation of headers and document'); |
|
1023 | + $this->debug('cleaned data, stringlen: '.strlen($data)); |
|
1024 | + // clean headers |
|
1025 | + foreach ($header_array as $header_line) { |
|
1026 | + $arr = explode(':',$header_line,2); |
|
1027 | + if(count($arr) > 1){ |
|
1028 | + $header_name = strtolower(trim($arr[0])); |
|
1029 | + $this->incoming_headers[$header_name] = trim($arr[1]); |
|
1030 | + if ($header_name == 'set-cookie') { |
|
1031 | + // TODO: allow multiple cookies from parseCookie |
|
1032 | + $cookie = $this->parseCookie(trim($arr[1])); |
|
1033 | + if ($cookie) { |
|
1034 | + $this->incoming_cookies[] = $cookie; |
|
1035 | + $this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']); |
|
1036 | + } else { |
|
1037 | + $this->debug('did not find cookie in ' . trim($arr[1])); |
|
1038 | + } |
|
1039 | + } |
|
1040 | + } else if (isset($header_name)) { |
|
1041 | + // append continuation line to previous header |
|
1042 | + $this->incoming_headers[$header_name] .= $lb . ' ' . $header_line; |
|
1043 | + } |
|
1044 | + } |
|
1045 | + } |
|
1046 | 1046 | |
1047 | - $this->response_status_line = $header_array[0]; |
|
1048 | - $arr = explode(' ', $this->response_status_line, 3); |
|
1049 | - $http_version = $arr[0]; |
|
1050 | - $http_status = intval($arr[1]); |
|
1051 | - $http_reason = count($arr) > 2 ? $arr[2] : ''; |
|
1047 | + $this->response_status_line = $header_array[0]; |
|
1048 | + $arr = explode(' ', $this->response_status_line, 3); |
|
1049 | + $http_version = $arr[0]; |
|
1050 | + $http_status = intval($arr[1]); |
|
1051 | + $http_reason = count($arr) > 2 ? $arr[2] : ''; |
|
1052 | 1052 | |
1053 | - // see if we need to resend the request with http digest authentication |
|
1054 | - if (isset($this->incoming_headers['location']) && ($http_status == 301 || $http_status == 302)) { |
|
1055 | - $this->debug("Got $http_status $http_reason with Location: " . $this->incoming_headers['location']); |
|
1056 | - $this->setURL($this->incoming_headers['location']); |
|
1057 | - $this->tryagain = true; |
|
1058 | - return false; |
|
1059 | - } |
|
1053 | + // see if we need to resend the request with http digest authentication |
|
1054 | + if (isset($this->incoming_headers['location']) && ($http_status == 301 || $http_status == 302)) { |
|
1055 | + $this->debug("Got $http_status $http_reason with Location: " . $this->incoming_headers['location']); |
|
1056 | + $this->setURL($this->incoming_headers['location']); |
|
1057 | + $this->tryagain = true; |
|
1058 | + return false; |
|
1059 | + } |
|
1060 | 1060 | |
1061 | - // see if we need to resend the request with http digest authentication |
|
1062 | - if (isset($this->incoming_headers['www-authenticate']) && $http_status == 401) { |
|
1063 | - $this->debug("Got 401 $http_reason with WWW-Authenticate: " . $this->incoming_headers['www-authenticate']); |
|
1064 | - if (strstr($this->incoming_headers['www-authenticate'], "Digest ")) { |
|
1065 | - $this->debug('Server wants digest authentication'); |
|
1066 | - // remove "Digest " from our elements |
|
1067 | - $digestString = str_replace('Digest ', '', $this->incoming_headers['www-authenticate']); |
|
1061 | + // see if we need to resend the request with http digest authentication |
|
1062 | + if (isset($this->incoming_headers['www-authenticate']) && $http_status == 401) { |
|
1063 | + $this->debug("Got 401 $http_reason with WWW-Authenticate: " . $this->incoming_headers['www-authenticate']); |
|
1064 | + if (strstr($this->incoming_headers['www-authenticate'], "Digest ")) { |
|
1065 | + $this->debug('Server wants digest authentication'); |
|
1066 | + // remove "Digest " from our elements |
|
1067 | + $digestString = str_replace('Digest ', '', $this->incoming_headers['www-authenticate']); |
|
1068 | 1068 | |
1069 | - // parse elements into array |
|
1070 | - $digestElements = explode(',', $digestString); |
|
1071 | - foreach ($digestElements as $val) { |
|
1072 | - $tempElement = explode('=', trim($val), 2); |
|
1073 | - $digestRequest[$tempElement[0]] = str_replace("\"", '', $tempElement[1]); |
|
1074 | - } |
|
1069 | + // parse elements into array |
|
1070 | + $digestElements = explode(',', $digestString); |
|
1071 | + foreach ($digestElements as $val) { |
|
1072 | + $tempElement = explode('=', trim($val), 2); |
|
1073 | + $digestRequest[$tempElement[0]] = str_replace("\"", '', $tempElement[1]); |
|
1074 | + } |
|
1075 | 1075 | |
1076 | - // should have (at least) qop, realm, nonce |
|
1077 | - if (isset($digestRequest['nonce'])) { |
|
1078 | - $this->setCredentials($this->username, $this->password, 'digest', $digestRequest); |
|
1079 | - $this->tryagain = true; |
|
1080 | - return false; |
|
1081 | - } |
|
1082 | - } |
|
1083 | - $this->debug('HTTP authentication failed'); |
|
1084 | - $this->setError('HTTP authentication failed'); |
|
1085 | - return false; |
|
1086 | - } |
|
1076 | + // should have (at least) qop, realm, nonce |
|
1077 | + if (isset($digestRequest['nonce'])) { |
|
1078 | + $this->setCredentials($this->username, $this->password, 'digest', $digestRequest); |
|
1079 | + $this->tryagain = true; |
|
1080 | + return false; |
|
1081 | + } |
|
1082 | + } |
|
1083 | + $this->debug('HTTP authentication failed'); |
|
1084 | + $this->setError('HTTP authentication failed'); |
|
1085 | + return false; |
|
1086 | + } |
|
1087 | 1087 | |
1088 | - if ( |
|
1089 | - ($http_status >= 300 && $http_status <= 307) || |
|
1090 | - ($http_status >= 400 && $http_status <= 417) || |
|
1091 | - ($http_status >= 501 && $http_status <= 505) |
|
1092 | - ) { |
|
1093 | - $this->setError("Unsupported HTTP response status $http_status $http_reason (soapclient->response has contents of the response)"); |
|
1094 | - return false; |
|
1095 | - } |
|
1088 | + if ( |
|
1089 | + ($http_status >= 300 && $http_status <= 307) || |
|
1090 | + ($http_status >= 400 && $http_status <= 417) || |
|
1091 | + ($http_status >= 501 && $http_status <= 505) |
|
1092 | + ) { |
|
1093 | + $this->setError("Unsupported HTTP response status $http_status $http_reason (soapclient->response has contents of the response)"); |
|
1094 | + return false; |
|
1095 | + } |
|
1096 | 1096 | |
1097 | - // decode content-encoding |
|
1098 | - if(isset($this->incoming_headers['content-encoding']) && $this->incoming_headers['content-encoding'] != ''){ |
|
1099 | - if(strtolower($this->incoming_headers['content-encoding']) == 'deflate' || strtolower($this->incoming_headers['content-encoding']) == 'gzip'){ |
|
1100 | - // if decoding works, use it. else assume data wasn't gzencoded |
|
1101 | - if(function_exists('gzinflate')){ |
|
1102 | - //$timer->setMarker('starting decoding of gzip/deflated content'); |
|
1103 | - // IIS 5 requires gzinflate instead of gzuncompress (similar to IE 5 and gzdeflate v. gzcompress) |
|
1104 | - // this means there are no Zlib headers, although there should be |
|
1105 | - $this->debug('The gzinflate function exists'); |
|
1106 | - $datalen = strlen($data); |
|
1107 | - if ($this->incoming_headers['content-encoding'] == 'deflate') { |
|
1108 | - if ($degzdata = @gzinflate($data)) { |
|
1109 | - $data = $degzdata; |
|
1110 | - $this->debug('The payload has been inflated to ' . strlen($data) . ' bytes'); |
|
1111 | - if (strlen($data) < $datalen) { |
|
1112 | - // test for the case that the payload has been compressed twice |
|
1113 | - $this->debug('The inflated payload is smaller than the gzipped one; try again'); |
|
1114 | - if ($degzdata = @gzinflate($data)) { |
|
1115 | - $data = $degzdata; |
|
1116 | - $this->debug('The payload has been inflated again to ' . strlen($data) . ' bytes'); |
|
1117 | - } |
|
1118 | - } |
|
1119 | - } else { |
|
1120 | - $this->debug('Error using gzinflate to inflate the payload'); |
|
1121 | - $this->setError('Error using gzinflate to inflate the payload'); |
|
1122 | - } |
|
1123 | - } elseif ($this->incoming_headers['content-encoding'] == 'gzip') { |
|
1124 | - if ($degzdata = @gzinflate(substr($data, 10))) { // do our best |
|
1125 | - $data = $degzdata; |
|
1126 | - $this->debug('The payload has been un-gzipped to ' . strlen($data) . ' bytes'); |
|
1127 | - if (strlen($data) < $datalen) { |
|
1128 | - // test for the case that the payload has been compressed twice |
|
1129 | - $this->debug('The un-gzipped payload is smaller than the gzipped one; try again'); |
|
1130 | - if ($degzdata = @gzinflate(substr($data, 10))) { |
|
1131 | - $data = $degzdata; |
|
1132 | - $this->debug('The payload has been un-gzipped again to ' . strlen($data) . ' bytes'); |
|
1133 | - } |
|
1134 | - } |
|
1135 | - } else { |
|
1136 | - $this->debug('Error using gzinflate to un-gzip the payload'); |
|
1137 | - $this->setError('Error using gzinflate to un-gzip the payload'); |
|
1138 | - } |
|
1139 | - } |
|
1140 | - //$timer->setMarker('finished decoding of gzip/deflated content'); |
|
1141 | - //print "<xmp>\nde-inflated:\n---------------\n$data\n-------------\n</xmp>"; |
|
1142 | - // set decoded payload |
|
1143 | - $this->incoming_payload = $header_data.$lb.$lb.$data; |
|
1144 | - } else { |
|
1145 | - $this->debug('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.'); |
|
1146 | - $this->setError('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.'); |
|
1147 | - } |
|
1148 | - } else { |
|
1149 | - $this->debug('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']); |
|
1150 | - $this->setError('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']); |
|
1151 | - } |
|
1152 | - } else { |
|
1153 | - $this->debug('No Content-Encoding header'); |
|
1154 | - } |
|
1097 | + // decode content-encoding |
|
1098 | + if(isset($this->incoming_headers['content-encoding']) && $this->incoming_headers['content-encoding'] != ''){ |
|
1099 | + if(strtolower($this->incoming_headers['content-encoding']) == 'deflate' || strtolower($this->incoming_headers['content-encoding']) == 'gzip'){ |
|
1100 | + // if decoding works, use it. else assume data wasn't gzencoded |
|
1101 | + if(function_exists('gzinflate')){ |
|
1102 | + //$timer->setMarker('starting decoding of gzip/deflated content'); |
|
1103 | + // IIS 5 requires gzinflate instead of gzuncompress (similar to IE 5 and gzdeflate v. gzcompress) |
|
1104 | + // this means there are no Zlib headers, although there should be |
|
1105 | + $this->debug('The gzinflate function exists'); |
|
1106 | + $datalen = strlen($data); |
|
1107 | + if ($this->incoming_headers['content-encoding'] == 'deflate') { |
|
1108 | + if ($degzdata = @gzinflate($data)) { |
|
1109 | + $data = $degzdata; |
|
1110 | + $this->debug('The payload has been inflated to ' . strlen($data) . ' bytes'); |
|
1111 | + if (strlen($data) < $datalen) { |
|
1112 | + // test for the case that the payload has been compressed twice |
|
1113 | + $this->debug('The inflated payload is smaller than the gzipped one; try again'); |
|
1114 | + if ($degzdata = @gzinflate($data)) { |
|
1115 | + $data = $degzdata; |
|
1116 | + $this->debug('The payload has been inflated again to ' . strlen($data) . ' bytes'); |
|
1117 | + } |
|
1118 | + } |
|
1119 | + } else { |
|
1120 | + $this->debug('Error using gzinflate to inflate the payload'); |
|
1121 | + $this->setError('Error using gzinflate to inflate the payload'); |
|
1122 | + } |
|
1123 | + } elseif ($this->incoming_headers['content-encoding'] == 'gzip') { |
|
1124 | + if ($degzdata = @gzinflate(substr($data, 10))) { // do our best |
|
1125 | + $data = $degzdata; |
|
1126 | + $this->debug('The payload has been un-gzipped to ' . strlen($data) . ' bytes'); |
|
1127 | + if (strlen($data) < $datalen) { |
|
1128 | + // test for the case that the payload has been compressed twice |
|
1129 | + $this->debug('The un-gzipped payload is smaller than the gzipped one; try again'); |
|
1130 | + if ($degzdata = @gzinflate(substr($data, 10))) { |
|
1131 | + $data = $degzdata; |
|
1132 | + $this->debug('The payload has been un-gzipped again to ' . strlen($data) . ' bytes'); |
|
1133 | + } |
|
1134 | + } |
|
1135 | + } else { |
|
1136 | + $this->debug('Error using gzinflate to un-gzip the payload'); |
|
1137 | + $this->setError('Error using gzinflate to un-gzip the payload'); |
|
1138 | + } |
|
1139 | + } |
|
1140 | + //$timer->setMarker('finished decoding of gzip/deflated content'); |
|
1141 | + //print "<xmp>\nde-inflated:\n---------------\n$data\n-------------\n</xmp>"; |
|
1142 | + // set decoded payload |
|
1143 | + $this->incoming_payload = $header_data.$lb.$lb.$data; |
|
1144 | + } else { |
|
1145 | + $this->debug('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.'); |
|
1146 | + $this->setError('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.'); |
|
1147 | + } |
|
1148 | + } else { |
|
1149 | + $this->debug('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']); |
|
1150 | + $this->setError('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']); |
|
1151 | + } |
|
1152 | + } else { |
|
1153 | + $this->debug('No Content-Encoding header'); |
|
1154 | + } |
|
1155 | 1155 | |
1156 | - if(strlen($data) == 0){ |
|
1157 | - $this->debug('no data after headers!'); |
|
1158 | - $this->setError('no data present after HTTP headers'); |
|
1159 | - return false; |
|
1160 | - } |
|
1156 | + if(strlen($data) == 0){ |
|
1157 | + $this->debug('no data after headers!'); |
|
1158 | + $this->setError('no data present after HTTP headers'); |
|
1159 | + return false; |
|
1160 | + } |
|
1161 | 1161 | |
1162 | - return $data; |
|
1163 | - } |
|
1162 | + return $data; |
|
1163 | + } |
|
1164 | 1164 | |
1165 | - /** |
|
1166 | - * sets the content-type for the SOAP message to be sent |
|
1167 | - * |
|
1168 | - * @param string $type the content type, MIME style |
|
1169 | - * @param mixed $charset character set used for encoding (or false) |
|
1170 | - * @access public |
|
1171 | - */ |
|
1172 | - function setContentType($type, $charset = false) { |
|
1173 | - $this->setHeader('Content-Type', $type . ($charset ? '; charset=' . $charset : '')); |
|
1174 | - } |
|
1165 | + /** |
|
1166 | + * sets the content-type for the SOAP message to be sent |
|
1167 | + * |
|
1168 | + * @param string $type the content type, MIME style |
|
1169 | + * @param mixed $charset character set used for encoding (or false) |
|
1170 | + * @access public |
|
1171 | + */ |
|
1172 | + function setContentType($type, $charset = false) { |
|
1173 | + $this->setHeader('Content-Type', $type . ($charset ? '; charset=' . $charset : '')); |
|
1174 | + } |
|
1175 | 1175 | |
1176 | - /** |
|
1177 | - * specifies that an HTTP persistent connection should be used |
|
1178 | - * |
|
1179 | - * @return boolean whether the request was honored by this method. |
|
1180 | - * @access public |
|
1181 | - */ |
|
1182 | - function usePersistentConnection(){ |
|
1183 | - if (isset($this->outgoing_headers['Accept-Encoding'])) { |
|
1184 | - return false; |
|
1185 | - } |
|
1186 | - $this->protocol_version = '1.1'; |
|
1187 | - $this->persistentConnection = true; |
|
1188 | - $this->setHeader('Connection', 'Keep-Alive'); |
|
1189 | - return true; |
|
1190 | - } |
|
1176 | + /** |
|
1177 | + * specifies that an HTTP persistent connection should be used |
|
1178 | + * |
|
1179 | + * @return boolean whether the request was honored by this method. |
|
1180 | + * @access public |
|
1181 | + */ |
|
1182 | + function usePersistentConnection(){ |
|
1183 | + if (isset($this->outgoing_headers['Accept-Encoding'])) { |
|
1184 | + return false; |
|
1185 | + } |
|
1186 | + $this->protocol_version = '1.1'; |
|
1187 | + $this->persistentConnection = true; |
|
1188 | + $this->setHeader('Connection', 'Keep-Alive'); |
|
1189 | + return true; |
|
1190 | + } |
|
1191 | 1191 | |
1192 | - /** |
|
1193 | - * parse an incoming Cookie into it's parts |
|
1194 | - * |
|
1195 | - * @param string $cookie_str content of cookie |
|
1196 | - * @return array with data of that cookie |
|
1197 | - * @access private |
|
1198 | - */ |
|
1199 | - /* |
|
1192 | + /** |
|
1193 | + * parse an incoming Cookie into it's parts |
|
1194 | + * |
|
1195 | + * @param string $cookie_str content of cookie |
|
1196 | + * @return array with data of that cookie |
|
1197 | + * @access private |
|
1198 | + */ |
|
1199 | + /* |
|
1200 | 1200 | * TODO: allow a Set-Cookie string to be parsed into multiple cookies |
1201 | 1201 | */ |
1202 | - function parseCookie($cookie_str) { |
|
1203 | - $cookie_str = str_replace('; ', ';', $cookie_str) . ';'; |
|
1204 | - $data = preg_split('/;/', $cookie_str); |
|
1205 | - $value_str = $data[0]; |
|
1202 | + function parseCookie($cookie_str) { |
|
1203 | + $cookie_str = str_replace('; ', ';', $cookie_str) . ';'; |
|
1204 | + $data = preg_split('/;/', $cookie_str); |
|
1205 | + $value_str = $data[0]; |
|
1206 | 1206 | |
1207 | - $cookie_param = 'domain='; |
|
1208 | - $start = strpos($cookie_str, $cookie_param); |
|
1209 | - if ($start > 0) { |
|
1210 | - $domain = substr($cookie_str, $start + strlen($cookie_param)); |
|
1211 | - $domain = substr($domain, 0, strpos($domain, ';')); |
|
1212 | - } else { |
|
1213 | - $domain = ''; |
|
1214 | - } |
|
1207 | + $cookie_param = 'domain='; |
|
1208 | + $start = strpos($cookie_str, $cookie_param); |
|
1209 | + if ($start > 0) { |
|
1210 | + $domain = substr($cookie_str, $start + strlen($cookie_param)); |
|
1211 | + $domain = substr($domain, 0, strpos($domain, ';')); |
|
1212 | + } else { |
|
1213 | + $domain = ''; |
|
1214 | + } |
|
1215 | 1215 | |
1216 | - $cookie_param = 'expires='; |
|
1217 | - $start = strpos($cookie_str, $cookie_param); |
|
1218 | - if ($start > 0) { |
|
1219 | - $expires = substr($cookie_str, $start + strlen($cookie_param)); |
|
1220 | - $expires = substr($expires, 0, strpos($expires, ';')); |
|
1221 | - } else { |
|
1222 | - $expires = ''; |
|
1223 | - } |
|
1216 | + $cookie_param = 'expires='; |
|
1217 | + $start = strpos($cookie_str, $cookie_param); |
|
1218 | + if ($start > 0) { |
|
1219 | + $expires = substr($cookie_str, $start + strlen($cookie_param)); |
|
1220 | + $expires = substr($expires, 0, strpos($expires, ';')); |
|
1221 | + } else { |
|
1222 | + $expires = ''; |
|
1223 | + } |
|
1224 | 1224 | |
1225 | - $cookie_param = 'path='; |
|
1226 | - $start = strpos($cookie_str, $cookie_param); |
|
1227 | - if ( $start > 0 ) { |
|
1228 | - $path = substr($cookie_str, $start + strlen($cookie_param)); |
|
1229 | - $path = substr($path, 0, strpos($path, ';')); |
|
1230 | - } else { |
|
1231 | - $path = '/'; |
|
1232 | - } |
|
1225 | + $cookie_param = 'path='; |
|
1226 | + $start = strpos($cookie_str, $cookie_param); |
|
1227 | + if ( $start > 0 ) { |
|
1228 | + $path = substr($cookie_str, $start + strlen($cookie_param)); |
|
1229 | + $path = substr($path, 0, strpos($path, ';')); |
|
1230 | + } else { |
|
1231 | + $path = '/'; |
|
1232 | + } |
|
1233 | 1233 | |
1234 | - $cookie_param = ';secure;'; |
|
1235 | - if (strpos($cookie_str, $cookie_param) !== FALSE) { |
|
1236 | - $secure = true; |
|
1237 | - } else { |
|
1238 | - $secure = false; |
|
1239 | - } |
|
1234 | + $cookie_param = ';secure;'; |
|
1235 | + if (strpos($cookie_str, $cookie_param) !== FALSE) { |
|
1236 | + $secure = true; |
|
1237 | + } else { |
|
1238 | + $secure = false; |
|
1239 | + } |
|
1240 | 1240 | |
1241 | - $sep_pos = strpos($value_str, '='); |
|
1241 | + $sep_pos = strpos($value_str, '='); |
|
1242 | 1242 | |
1243 | - if ($sep_pos) { |
|
1244 | - $name = substr($value_str, 0, $sep_pos); |
|
1245 | - $value = substr($value_str, $sep_pos + 1); |
|
1246 | - $cookie= array( 'name' => $name, |
|
1247 | - 'value' => $value, |
|
1248 | - 'domain' => $domain, |
|
1249 | - 'path' => $path, |
|
1250 | - 'expires' => $expires, |
|
1251 | - 'secure' => $secure |
|
1252 | - ); |
|
1253 | - return $cookie; |
|
1254 | - } |
|
1255 | - return false; |
|
1256 | - } |
|
1243 | + if ($sep_pos) { |
|
1244 | + $name = substr($value_str, 0, $sep_pos); |
|
1245 | + $value = substr($value_str, $sep_pos + 1); |
|
1246 | + $cookie= array( 'name' => $name, |
|
1247 | + 'value' => $value, |
|
1248 | + 'domain' => $domain, |
|
1249 | + 'path' => $path, |
|
1250 | + 'expires' => $expires, |
|
1251 | + 'secure' => $secure |
|
1252 | + ); |
|
1253 | + return $cookie; |
|
1254 | + } |
|
1255 | + return false; |
|
1256 | + } |
|
1257 | 1257 | |
1258 | - /** |
|
1259 | - * sort out cookies for the current request |
|
1260 | - * |
|
1261 | - * @param array $cookies array with all cookies |
|
1262 | - * @param boolean $secure is the send-content secure or not? |
|
1263 | - * @return string for Cookie-HTTP-Header |
|
1264 | - * @access private |
|
1265 | - */ |
|
1266 | - function getCookiesForRequest($cookies, $secure=false) { |
|
1267 | - $cookie_str = ''; |
|
1268 | - if ((! is_null($cookies)) && (is_array($cookies))) { |
|
1269 | - foreach ($cookies as $cookie) { |
|
1270 | - if (! is_array($cookie)) { |
|
1271 | - continue; |
|
1272 | - } |
|
1273 | - $this->debug("check cookie for validity: ".$cookie['name'].'='.$cookie['value']); |
|
1274 | - if ((isset($cookie['expires'])) && (! empty($cookie['expires']))) { |
|
1275 | - if (strtotime($cookie['expires']) <= time()) { |
|
1276 | - $this->debug('cookie has expired'); |
|
1277 | - continue; |
|
1278 | - } |
|
1279 | - } |
|
1280 | - if ((isset($cookie['domain'])) && (! empty($cookie['domain']))) { |
|
1281 | - $domain = preg_quote($cookie['domain']); |
|
1282 | - if (! preg_match("'.*$domain$'i", $this->host)) { |
|
1283 | - $this->debug('cookie has different domain'); |
|
1284 | - continue; |
|
1285 | - } |
|
1286 | - } |
|
1287 | - if ((isset($cookie['path'])) && (! empty($cookie['path']))) { |
|
1288 | - $path = preg_quote($cookie['path']); |
|
1289 | - if (! preg_match("'^$path.*'i", $this->path)) { |
|
1290 | - $this->debug('cookie is for a different path'); |
|
1291 | - continue; |
|
1292 | - } |
|
1293 | - } |
|
1294 | - if ((! $secure) && (isset($cookie['secure'])) && ($cookie['secure'])) { |
|
1295 | - $this->debug('cookie is secure, transport is not'); |
|
1296 | - continue; |
|
1297 | - } |
|
1298 | - $cookie_str .= $cookie['name'] . '=' . $cookie['value'] . '; '; |
|
1299 | - $this->debug('add cookie to Cookie-String: ' . $cookie['name'] . '=' . $cookie['value']); |
|
1300 | - } |
|
1301 | - } |
|
1302 | - return $cookie_str; |
|
1303 | - } |
|
1258 | + /** |
|
1259 | + * sort out cookies for the current request |
|
1260 | + * |
|
1261 | + * @param array $cookies array with all cookies |
|
1262 | + * @param boolean $secure is the send-content secure or not? |
|
1263 | + * @return string for Cookie-HTTP-Header |
|
1264 | + * @access private |
|
1265 | + */ |
|
1266 | + function getCookiesForRequest($cookies, $secure=false) { |
|
1267 | + $cookie_str = ''; |
|
1268 | + if ((! is_null($cookies)) && (is_array($cookies))) { |
|
1269 | + foreach ($cookies as $cookie) { |
|
1270 | + if (! is_array($cookie)) { |
|
1271 | + continue; |
|
1272 | + } |
|
1273 | + $this->debug("check cookie for validity: ".$cookie['name'].'='.$cookie['value']); |
|
1274 | + if ((isset($cookie['expires'])) && (! empty($cookie['expires']))) { |
|
1275 | + if (strtotime($cookie['expires']) <= time()) { |
|
1276 | + $this->debug('cookie has expired'); |
|
1277 | + continue; |
|
1278 | + } |
|
1279 | + } |
|
1280 | + if ((isset($cookie['domain'])) && (! empty($cookie['domain']))) { |
|
1281 | + $domain = preg_quote($cookie['domain']); |
|
1282 | + if (! preg_match("'.*$domain$'i", $this->host)) { |
|
1283 | + $this->debug('cookie has different domain'); |
|
1284 | + continue; |
|
1285 | + } |
|
1286 | + } |
|
1287 | + if ((isset($cookie['path'])) && (! empty($cookie['path']))) { |
|
1288 | + $path = preg_quote($cookie['path']); |
|
1289 | + if (! preg_match("'^$path.*'i", $this->path)) { |
|
1290 | + $this->debug('cookie is for a different path'); |
|
1291 | + continue; |
|
1292 | + } |
|
1293 | + } |
|
1294 | + if ((! $secure) && (isset($cookie['secure'])) && ($cookie['secure'])) { |
|
1295 | + $this->debug('cookie is secure, transport is not'); |
|
1296 | + continue; |
|
1297 | + } |
|
1298 | + $cookie_str .= $cookie['name'] . '=' . $cookie['value'] . '; '; |
|
1299 | + $this->debug('add cookie to Cookie-String: ' . $cookie['name'] . '=' . $cookie['value']); |
|
1300 | + } |
|
1301 | + } |
|
1302 | + return $cookie_str; |
|
1303 | + } |
|
1304 | 1304 | } |
1305 | 1305 | |
1306 | 1306 |
@@ -52,224 +52,224 @@ discard block |
||
52 | 52 | * @access public |
53 | 53 | */ |
54 | 54 | class nusoap_client_mime extends nusoap_client { |
55 | - /** |
|
56 | - * @var array Each array element in the return is an associative array with keys |
|
57 | - * data, filename, contenttype, cid |
|
58 | - * @access private |
|
59 | - */ |
|
60 | - var $requestAttachments = array(); |
|
61 | - /** |
|
62 | - * @var array Each array element in the return is an associative array with keys |
|
63 | - * data, filename, contenttype, cid |
|
64 | - * @access private |
|
65 | - */ |
|
66 | - var $responseAttachments; |
|
67 | - /** |
|
68 | - * @var string |
|
69 | - * @access private |
|
70 | - */ |
|
71 | - var $mimeContentType; |
|
55 | + /** |
|
56 | + * @var array Each array element in the return is an associative array with keys |
|
57 | + * data, filename, contenttype, cid |
|
58 | + * @access private |
|
59 | + */ |
|
60 | + var $requestAttachments = array(); |
|
61 | + /** |
|
62 | + * @var array Each array element in the return is an associative array with keys |
|
63 | + * data, filename, contenttype, cid |
|
64 | + * @access private |
|
65 | + */ |
|
66 | + var $responseAttachments; |
|
67 | + /** |
|
68 | + * @var string |
|
69 | + * @access private |
|
70 | + */ |
|
71 | + var $mimeContentType; |
|
72 | 72 | |
73 | - /** |
|
74 | - * adds a MIME attachment to the current request. |
|
75 | - * |
|
76 | - * If the $data parameter contains an empty string, this method will read |
|
77 | - * the contents of the file named by the $filename parameter. |
|
78 | - * |
|
79 | - * If the $cid parameter is false, this method will generate the cid. |
|
80 | - * |
|
81 | - * @param string $data The data of the attachment |
|
82 | - * @param string $filename The filename of the attachment (default is empty string) |
|
83 | - * @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream) |
|
84 | - * @param string $cid The content-id (cid) of the attachment (default is false) |
|
85 | - * @return string The content-id (cid) of the attachment |
|
86 | - * @access public |
|
87 | - */ |
|
88 | - function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) { |
|
89 | - if (! $cid) { |
|
90 | - $cid = md5(uniqid(time())); |
|
91 | - } |
|
92 | - |
|
93 | - $info['data'] = $data; |
|
94 | - $info['filename'] = $filename; |
|
95 | - $info['contenttype'] = $contenttype; |
|
96 | - $info['cid'] = $cid; |
|
73 | + /** |
|
74 | + * adds a MIME attachment to the current request. |
|
75 | + * |
|
76 | + * If the $data parameter contains an empty string, this method will read |
|
77 | + * the contents of the file named by the $filename parameter. |
|
78 | + * |
|
79 | + * If the $cid parameter is false, this method will generate the cid. |
|
80 | + * |
|
81 | + * @param string $data The data of the attachment |
|
82 | + * @param string $filename The filename of the attachment (default is empty string) |
|
83 | + * @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream) |
|
84 | + * @param string $cid The content-id (cid) of the attachment (default is false) |
|
85 | + * @return string The content-id (cid) of the attachment |
|
86 | + * @access public |
|
87 | + */ |
|
88 | + function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) { |
|
89 | + if (! $cid) { |
|
90 | + $cid = md5(uniqid(time())); |
|
91 | + } |
|
92 | + |
|
93 | + $info['data'] = $data; |
|
94 | + $info['filename'] = $filename; |
|
95 | + $info['contenttype'] = $contenttype; |
|
96 | + $info['cid'] = $cid; |
|
97 | 97 | |
98 | - $this->requestAttachments[] = $info; |
|
99 | - |
|
100 | - return $cid; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * clears the MIME attachments for the current request. |
|
105 | - * |
|
106 | - * @access public |
|
107 | - */ |
|
108 | - function clearAttachments() { |
|
109 | - $this->requestAttachments = array(); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * gets the MIME attachments from the current response. |
|
114 | - * |
|
115 | - * Each array element in the return is an associative array with keys |
|
116 | - * data, filename, contenttype, cid. These keys correspond to the parameters |
|
117 | - * for addAttachment. |
|
118 | - * |
|
119 | - * @return array The attachments. |
|
120 | - * @access public |
|
121 | - */ |
|
122 | - function getAttachments() { |
|
123 | - return $this->responseAttachments; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * gets the HTTP body for the current request. |
|
128 | - * |
|
129 | - * @param string $soapmsg The SOAP payload |
|
130 | - * @return string The HTTP body, which includes the SOAP payload |
|
131 | - * @access private |
|
132 | - */ |
|
133 | - function getHTTPBody($soapmsg) { |
|
134 | - if (count($this->requestAttachments) > 0) { |
|
135 | - $params['content_type'] = 'multipart/related; type="text/xml"'; |
|
136 | - $mimeMessage = new Mail_mimePart('', $params); |
|
137 | - unset($params); |
|
138 | - |
|
139 | - $params['content_type'] = 'text/xml'; |
|
140 | - $params['encoding'] = '8bit'; |
|
141 | - $params['charset'] = $this->soap_defencoding; |
|
142 | - $mimeMessage->addSubpart($soapmsg, $params); |
|
98 | + $this->requestAttachments[] = $info; |
|
99 | + |
|
100 | + return $cid; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * clears the MIME attachments for the current request. |
|
105 | + * |
|
106 | + * @access public |
|
107 | + */ |
|
108 | + function clearAttachments() { |
|
109 | + $this->requestAttachments = array(); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * gets the MIME attachments from the current response. |
|
114 | + * |
|
115 | + * Each array element in the return is an associative array with keys |
|
116 | + * data, filename, contenttype, cid. These keys correspond to the parameters |
|
117 | + * for addAttachment. |
|
118 | + * |
|
119 | + * @return array The attachments. |
|
120 | + * @access public |
|
121 | + */ |
|
122 | + function getAttachments() { |
|
123 | + return $this->responseAttachments; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * gets the HTTP body for the current request. |
|
128 | + * |
|
129 | + * @param string $soapmsg The SOAP payload |
|
130 | + * @return string The HTTP body, which includes the SOAP payload |
|
131 | + * @access private |
|
132 | + */ |
|
133 | + function getHTTPBody($soapmsg) { |
|
134 | + if (count($this->requestAttachments) > 0) { |
|
135 | + $params['content_type'] = 'multipart/related; type="text/xml"'; |
|
136 | + $mimeMessage = new Mail_mimePart('', $params); |
|
137 | + unset($params); |
|
138 | + |
|
139 | + $params['content_type'] = 'text/xml'; |
|
140 | + $params['encoding'] = '8bit'; |
|
141 | + $params['charset'] = $this->soap_defencoding; |
|
142 | + $mimeMessage->addSubpart($soapmsg, $params); |
|
143 | 143 | |
144 | - foreach ($this->requestAttachments as $att) { |
|
145 | - unset($params); |
|
146 | - |
|
147 | - $params['content_type'] = $att['contenttype']; |
|
148 | - $params['encoding'] = 'base64'; |
|
149 | - $params['disposition'] = 'attachment'; |
|
150 | - $params['dfilename'] = $att['filename']; |
|
151 | - $params['cid'] = $att['cid']; |
|
152 | - |
|
153 | - if ($att['data'] == '' && $att['filename'] <> '') { |
|
154 | - if ($fd = fopen($att['filename'], 'rb')) { |
|
155 | - $data = fread($fd, filesize($att['filename'])); |
|
156 | - fclose($fd); |
|
157 | - } else { |
|
158 | - $data = ''; |
|
159 | - } |
|
160 | - $mimeMessage->addSubpart($data, $params); |
|
161 | - } else { |
|
162 | - $mimeMessage->addSubpart($att['data'], $params); |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - $output = $mimeMessage->encode(); |
|
167 | - $mimeHeaders = $output['headers']; |
|
144 | + foreach ($this->requestAttachments as $att) { |
|
145 | + unset($params); |
|
146 | + |
|
147 | + $params['content_type'] = $att['contenttype']; |
|
148 | + $params['encoding'] = 'base64'; |
|
149 | + $params['disposition'] = 'attachment'; |
|
150 | + $params['dfilename'] = $att['filename']; |
|
151 | + $params['cid'] = $att['cid']; |
|
152 | + |
|
153 | + if ($att['data'] == '' && $att['filename'] <> '') { |
|
154 | + if ($fd = fopen($att['filename'], 'rb')) { |
|
155 | + $data = fread($fd, filesize($att['filename'])); |
|
156 | + fclose($fd); |
|
157 | + } else { |
|
158 | + $data = ''; |
|
159 | + } |
|
160 | + $mimeMessage->addSubpart($data, $params); |
|
161 | + } else { |
|
162 | + $mimeMessage->addSubpart($att['data'], $params); |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + $output = $mimeMessage->encode(); |
|
167 | + $mimeHeaders = $output['headers']; |
|
168 | 168 | |
169 | - foreach ($mimeHeaders as $k => $v) { |
|
170 | - $this->debug("MIME header $k: $v"); |
|
171 | - if (strtolower($k) == 'content-type') { |
|
172 | - // PHP header() seems to strip leading whitespace starting |
|
173 | - // the second line, so force everything to one line |
|
174 | - $this->mimeContentType = str_replace("\r\n", " ", $v); |
|
175 | - } |
|
176 | - } |
|
169 | + foreach ($mimeHeaders as $k => $v) { |
|
170 | + $this->debug("MIME header $k: $v"); |
|
171 | + if (strtolower($k) == 'content-type') { |
|
172 | + // PHP header() seems to strip leading whitespace starting |
|
173 | + // the second line, so force everything to one line |
|
174 | + $this->mimeContentType = str_replace("\r\n", " ", $v); |
|
175 | + } |
|
176 | + } |
|
177 | 177 | |
178 | - return $output['body']; |
|
179 | - } |
|
178 | + return $output['body']; |
|
179 | + } |
|
180 | 180 | |
181 | - return parent::getHTTPBody($soapmsg); |
|
182 | - } |
|
181 | + return parent::getHTTPBody($soapmsg); |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * gets the HTTP content type for the current request. |
|
186 | - * |
|
187 | - * Note: getHTTPBody must be called before this. |
|
188 | - * |
|
189 | - * @return string the HTTP content type for the current request. |
|
190 | - * @access private |
|
191 | - */ |
|
192 | - function getHTTPContentType() { |
|
193 | - if (count($this->requestAttachments) > 0) { |
|
194 | - return $this->mimeContentType; |
|
195 | - } |
|
196 | - return parent::getHTTPContentType(); |
|
197 | - } |
|
184 | + /** |
|
185 | + * gets the HTTP content type for the current request. |
|
186 | + * |
|
187 | + * Note: getHTTPBody must be called before this. |
|
188 | + * |
|
189 | + * @return string the HTTP content type for the current request. |
|
190 | + * @access private |
|
191 | + */ |
|
192 | + function getHTTPContentType() { |
|
193 | + if (count($this->requestAttachments) > 0) { |
|
194 | + return $this->mimeContentType; |
|
195 | + } |
|
196 | + return parent::getHTTPContentType(); |
|
197 | + } |
|
198 | 198 | |
199 | - /** |
|
200 | - * gets the HTTP content type charset for the current request. |
|
201 | - * returns false for non-text content types. |
|
202 | - * |
|
203 | - * Note: getHTTPBody must be called before this. |
|
204 | - * |
|
205 | - * @return string the HTTP content type charset for the current request. |
|
206 | - * @access private |
|
207 | - */ |
|
208 | - function getHTTPContentTypeCharset() { |
|
209 | - if (count($this->requestAttachments) > 0) { |
|
210 | - return false; |
|
211 | - } |
|
212 | - return parent::getHTTPContentTypeCharset(); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * processes SOAP message returned from server |
|
217 | - * |
|
218 | - * @param array $headers The HTTP headers |
|
219 | - * @param string $data unprocessed response data from server |
|
220 | - * @return mixed value of the message, decoded into a PHP type |
|
221 | - * @access private |
|
222 | - */ |
|
199 | + /** |
|
200 | + * gets the HTTP content type charset for the current request. |
|
201 | + * returns false for non-text content types. |
|
202 | + * |
|
203 | + * Note: getHTTPBody must be called before this. |
|
204 | + * |
|
205 | + * @return string the HTTP content type charset for the current request. |
|
206 | + * @access private |
|
207 | + */ |
|
208 | + function getHTTPContentTypeCharset() { |
|
209 | + if (count($this->requestAttachments) > 0) { |
|
210 | + return false; |
|
211 | + } |
|
212 | + return parent::getHTTPContentTypeCharset(); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * processes SOAP message returned from server |
|
217 | + * |
|
218 | + * @param array $headers The HTTP headers |
|
219 | + * @param string $data unprocessed response data from server |
|
220 | + * @return mixed value of the message, decoded into a PHP type |
|
221 | + * @access private |
|
222 | + */ |
|
223 | 223 | function parseResponse($headers, $data) { |
224 | - $this->debug('Entering parseResponse() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']); |
|
225 | - $this->responseAttachments = array(); |
|
226 | - if (strstr($headers['content-type'], 'multipart/related')) { |
|
227 | - $this->debug('Decode multipart/related'); |
|
228 | - $input = ''; |
|
229 | - foreach ($headers as $k => $v) { |
|
230 | - $input .= "$k: $v\r\n"; |
|
231 | - } |
|
232 | - $params['input'] = $input . "\r\n" . $data; |
|
233 | - $params['include_bodies'] = true; |
|
234 | - $params['decode_bodies'] = true; |
|
235 | - $params['decode_headers'] = true; |
|
224 | + $this->debug('Entering parseResponse() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']); |
|
225 | + $this->responseAttachments = array(); |
|
226 | + if (strstr($headers['content-type'], 'multipart/related')) { |
|
227 | + $this->debug('Decode multipart/related'); |
|
228 | + $input = ''; |
|
229 | + foreach ($headers as $k => $v) { |
|
230 | + $input .= "$k: $v\r\n"; |
|
231 | + } |
|
232 | + $params['input'] = $input . "\r\n" . $data; |
|
233 | + $params['include_bodies'] = true; |
|
234 | + $params['decode_bodies'] = true; |
|
235 | + $params['decode_headers'] = true; |
|
236 | 236 | |
237 | - $structure = Mail_mimeDecode::decode($params); |
|
238 | - |
|
239 | - foreach ($structure->parts as $part) { |
|
240 | - if (!isset($part->disposition) && (strstr($part->headers['content-type'], 'text/xml'))) { |
|
241 | - $this->debug('Have root part of type ' . $part->headers['content-type']); |
|
242 | - $root = $part->body; |
|
243 | - $return = parent::parseResponse($part->headers, $part->body); |
|
244 | - } else { |
|
245 | - $this->debug('Have an attachment of type ' . $part->headers['content-type']); |
|
246 | - $info['data'] = $part->body; |
|
247 | - $info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : ''; |
|
248 | - $info['contenttype'] = $part->headers['content-type']; |
|
249 | - $info['cid'] = $part->headers['content-id']; |
|
250 | - $this->responseAttachments[] = $info; |
|
251 | - } |
|
252 | - } |
|
237 | + $structure = Mail_mimeDecode::decode($params); |
|
238 | + |
|
239 | + foreach ($structure->parts as $part) { |
|
240 | + if (!isset($part->disposition) && (strstr($part->headers['content-type'], 'text/xml'))) { |
|
241 | + $this->debug('Have root part of type ' . $part->headers['content-type']); |
|
242 | + $root = $part->body; |
|
243 | + $return = parent::parseResponse($part->headers, $part->body); |
|
244 | + } else { |
|
245 | + $this->debug('Have an attachment of type ' . $part->headers['content-type']); |
|
246 | + $info['data'] = $part->body; |
|
247 | + $info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : ''; |
|
248 | + $info['contenttype'] = $part->headers['content-type']; |
|
249 | + $info['cid'] = $part->headers['content-id']; |
|
250 | + $this->responseAttachments[] = $info; |
|
251 | + } |
|
252 | + } |
|
253 | 253 | |
254 | - if (isset($return)) { |
|
255 | - $this->responseData = $root; |
|
256 | - return $return; |
|
257 | - } |
|
254 | + if (isset($return)) { |
|
255 | + $this->responseData = $root; |
|
256 | + return $return; |
|
257 | + } |
|
258 | 258 | |
259 | - $this->setError('No root part found in multipart/related content'); |
|
260 | - return ''; |
|
261 | - } |
|
262 | - $this->debug('Not multipart/related'); |
|
263 | - return parent::parseResponse($headers, $data); |
|
264 | - } |
|
259 | + $this->setError('No root part found in multipart/related content'); |
|
260 | + return ''; |
|
261 | + } |
|
262 | + $this->debug('Not multipart/related'); |
|
263 | + return parent::parseResponse($headers, $data); |
|
264 | + } |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /* |
268 | 268 | * For backwards compatiblity, define soapclientmime unless the PHP SOAP extension is loaded. |
269 | 269 | */ |
270 | 270 | if (!extension_loaded('soap')) { |
271 | - class soapclientmime extends nusoap_client_mime { |
|
272 | - } |
|
271 | + class soapclientmime extends nusoap_client_mime { |
|
272 | + } |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
@@ -282,214 +282,214 @@ discard block |
||
282 | 282 | * @access public |
283 | 283 | */ |
284 | 284 | class nusoap_server_mime extends nusoap_server { |
285 | - /** |
|
286 | - * @var array Each array element in the return is an associative array with keys |
|
287 | - * data, filename, contenttype, cid |
|
288 | - * @access private |
|
289 | - */ |
|
290 | - var $requestAttachments = array(); |
|
291 | - /** |
|
292 | - * @var array Each array element in the return is an associative array with keys |
|
293 | - * data, filename, contenttype, cid |
|
294 | - * @access private |
|
295 | - */ |
|
296 | - var $responseAttachments; |
|
297 | - /** |
|
298 | - * @var string |
|
299 | - * @access private |
|
300 | - */ |
|
301 | - var $mimeContentType; |
|
285 | + /** |
|
286 | + * @var array Each array element in the return is an associative array with keys |
|
287 | + * data, filename, contenttype, cid |
|
288 | + * @access private |
|
289 | + */ |
|
290 | + var $requestAttachments = array(); |
|
291 | + /** |
|
292 | + * @var array Each array element in the return is an associative array with keys |
|
293 | + * data, filename, contenttype, cid |
|
294 | + * @access private |
|
295 | + */ |
|
296 | + var $responseAttachments; |
|
297 | + /** |
|
298 | + * @var string |
|
299 | + * @access private |
|
300 | + */ |
|
301 | + var $mimeContentType; |
|
302 | 302 | |
303 | - /** |
|
304 | - * adds a MIME attachment to the current response. |
|
305 | - * |
|
306 | - * If the $data parameter contains an empty string, this method will read |
|
307 | - * the contents of the file named by the $filename parameter. |
|
308 | - * |
|
309 | - * If the $cid parameter is false, this method will generate the cid. |
|
310 | - * |
|
311 | - * @param string $data The data of the attachment |
|
312 | - * @param string $filename The filename of the attachment (default is empty string) |
|
313 | - * @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream) |
|
314 | - * @param string $cid The content-id (cid) of the attachment (default is false) |
|
315 | - * @return string The content-id (cid) of the attachment |
|
316 | - * @access public |
|
317 | - */ |
|
318 | - function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) { |
|
319 | - if (! $cid) { |
|
320 | - $cid = md5(uniqid(time())); |
|
321 | - } |
|
322 | - |
|
323 | - $info['data'] = $data; |
|
324 | - $info['filename'] = $filename; |
|
325 | - $info['contenttype'] = $contenttype; |
|
326 | - $info['cid'] = $cid; |
|
303 | + /** |
|
304 | + * adds a MIME attachment to the current response. |
|
305 | + * |
|
306 | + * If the $data parameter contains an empty string, this method will read |
|
307 | + * the contents of the file named by the $filename parameter. |
|
308 | + * |
|
309 | + * If the $cid parameter is false, this method will generate the cid. |
|
310 | + * |
|
311 | + * @param string $data The data of the attachment |
|
312 | + * @param string $filename The filename of the attachment (default is empty string) |
|
313 | + * @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream) |
|
314 | + * @param string $cid The content-id (cid) of the attachment (default is false) |
|
315 | + * @return string The content-id (cid) of the attachment |
|
316 | + * @access public |
|
317 | + */ |
|
318 | + function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) { |
|
319 | + if (! $cid) { |
|
320 | + $cid = md5(uniqid(time())); |
|
321 | + } |
|
322 | + |
|
323 | + $info['data'] = $data; |
|
324 | + $info['filename'] = $filename; |
|
325 | + $info['contenttype'] = $contenttype; |
|
326 | + $info['cid'] = $cid; |
|
327 | 327 | |
328 | - $this->responseAttachments[] = $info; |
|
329 | - |
|
330 | - return $cid; |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * clears the MIME attachments for the current response. |
|
335 | - * |
|
336 | - * @access public |
|
337 | - */ |
|
338 | - function clearAttachments() { |
|
339 | - $this->responseAttachments = array(); |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * gets the MIME attachments from the current request. |
|
344 | - * |
|
345 | - * Each array element in the return is an associative array with keys |
|
346 | - * data, filename, contenttype, cid. These keys correspond to the parameters |
|
347 | - * for addAttachment. |
|
348 | - * |
|
349 | - * @return array The attachments. |
|
350 | - * @access public |
|
351 | - */ |
|
352 | - function getAttachments() { |
|
353 | - return $this->requestAttachments; |
|
354 | - } |
|
355 | - |
|
356 | - /** |
|
357 | - * gets the HTTP body for the current response. |
|
358 | - * |
|
359 | - * @param string $soapmsg The SOAP payload |
|
360 | - * @return string The HTTP body, which includes the SOAP payload |
|
361 | - * @access private |
|
362 | - */ |
|
363 | - function getHTTPBody($soapmsg) { |
|
364 | - if (count($this->responseAttachments) > 0) { |
|
365 | - $params['content_type'] = 'multipart/related; type="text/xml"'; |
|
366 | - $mimeMessage = new Mail_mimePart('', $params); |
|
367 | - unset($params); |
|
368 | - |
|
369 | - $params['content_type'] = 'text/xml'; |
|
370 | - $params['encoding'] = '8bit'; |
|
371 | - $params['charset'] = $this->soap_defencoding; |
|
372 | - $mimeMessage->addSubpart($soapmsg, $params); |
|
328 | + $this->responseAttachments[] = $info; |
|
329 | + |
|
330 | + return $cid; |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * clears the MIME attachments for the current response. |
|
335 | + * |
|
336 | + * @access public |
|
337 | + */ |
|
338 | + function clearAttachments() { |
|
339 | + $this->responseAttachments = array(); |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * gets the MIME attachments from the current request. |
|
344 | + * |
|
345 | + * Each array element in the return is an associative array with keys |
|
346 | + * data, filename, contenttype, cid. These keys correspond to the parameters |
|
347 | + * for addAttachment. |
|
348 | + * |
|
349 | + * @return array The attachments. |
|
350 | + * @access public |
|
351 | + */ |
|
352 | + function getAttachments() { |
|
353 | + return $this->requestAttachments; |
|
354 | + } |
|
355 | + |
|
356 | + /** |
|
357 | + * gets the HTTP body for the current response. |
|
358 | + * |
|
359 | + * @param string $soapmsg The SOAP payload |
|
360 | + * @return string The HTTP body, which includes the SOAP payload |
|
361 | + * @access private |
|
362 | + */ |
|
363 | + function getHTTPBody($soapmsg) { |
|
364 | + if (count($this->responseAttachments) > 0) { |
|
365 | + $params['content_type'] = 'multipart/related; type="text/xml"'; |
|
366 | + $mimeMessage = new Mail_mimePart('', $params); |
|
367 | + unset($params); |
|
368 | + |
|
369 | + $params['content_type'] = 'text/xml'; |
|
370 | + $params['encoding'] = '8bit'; |
|
371 | + $params['charset'] = $this->soap_defencoding; |
|
372 | + $mimeMessage->addSubpart($soapmsg, $params); |
|
373 | 373 | |
374 | - foreach ($this->responseAttachments as $att) { |
|
375 | - unset($params); |
|
376 | - |
|
377 | - $params['content_type'] = $att['contenttype']; |
|
378 | - $params['encoding'] = 'base64'; |
|
379 | - $params['disposition'] = 'attachment'; |
|
380 | - $params['dfilename'] = $att['filename']; |
|
381 | - $params['cid'] = $att['cid']; |
|
382 | - |
|
383 | - if ($att['data'] == '' && $att['filename'] <> '') { |
|
384 | - if ($fd = fopen($att['filename'], 'rb')) { |
|
385 | - $data = fread($fd, filesize($att['filename'])); |
|
386 | - fclose($fd); |
|
387 | - } else { |
|
388 | - $data = ''; |
|
389 | - } |
|
390 | - $mimeMessage->addSubpart($data, $params); |
|
391 | - } else { |
|
392 | - $mimeMessage->addSubpart($att['data'], $params); |
|
393 | - } |
|
394 | - } |
|
395 | - |
|
396 | - $output = $mimeMessage->encode(); |
|
397 | - $mimeHeaders = $output['headers']; |
|
374 | + foreach ($this->responseAttachments as $att) { |
|
375 | + unset($params); |
|
376 | + |
|
377 | + $params['content_type'] = $att['contenttype']; |
|
378 | + $params['encoding'] = 'base64'; |
|
379 | + $params['disposition'] = 'attachment'; |
|
380 | + $params['dfilename'] = $att['filename']; |
|
381 | + $params['cid'] = $att['cid']; |
|
382 | + |
|
383 | + if ($att['data'] == '' && $att['filename'] <> '') { |
|
384 | + if ($fd = fopen($att['filename'], 'rb')) { |
|
385 | + $data = fread($fd, filesize($att['filename'])); |
|
386 | + fclose($fd); |
|
387 | + } else { |
|
388 | + $data = ''; |
|
389 | + } |
|
390 | + $mimeMessage->addSubpart($data, $params); |
|
391 | + } else { |
|
392 | + $mimeMessage->addSubpart($att['data'], $params); |
|
393 | + } |
|
394 | + } |
|
395 | + |
|
396 | + $output = $mimeMessage->encode(); |
|
397 | + $mimeHeaders = $output['headers']; |
|
398 | 398 | |
399 | - foreach ($mimeHeaders as $k => $v) { |
|
400 | - $this->debug("MIME header $k: $v"); |
|
401 | - if (strtolower($k) == 'content-type') { |
|
402 | - // PHP header() seems to strip leading whitespace starting |
|
403 | - // the second line, so force everything to one line |
|
404 | - $this->mimeContentType = str_replace("\r\n", " ", $v); |
|
405 | - } |
|
406 | - } |
|
399 | + foreach ($mimeHeaders as $k => $v) { |
|
400 | + $this->debug("MIME header $k: $v"); |
|
401 | + if (strtolower($k) == 'content-type') { |
|
402 | + // PHP header() seems to strip leading whitespace starting |
|
403 | + // the second line, so force everything to one line |
|
404 | + $this->mimeContentType = str_replace("\r\n", " ", $v); |
|
405 | + } |
|
406 | + } |
|
407 | 407 | |
408 | - return $output['body']; |
|
409 | - } |
|
408 | + return $output['body']; |
|
409 | + } |
|
410 | 410 | |
411 | - return parent::getHTTPBody($soapmsg); |
|
412 | - } |
|
411 | + return parent::getHTTPBody($soapmsg); |
|
412 | + } |
|
413 | 413 | |
414 | - /** |
|
415 | - * gets the HTTP content type for the current response. |
|
416 | - * |
|
417 | - * Note: getHTTPBody must be called before this. |
|
418 | - * |
|
419 | - * @return string the HTTP content type for the current response. |
|
420 | - * @access private |
|
421 | - */ |
|
422 | - function getHTTPContentType() { |
|
423 | - if (count($this->responseAttachments) > 0) { |
|
424 | - return $this->mimeContentType; |
|
425 | - } |
|
426 | - return parent::getHTTPContentType(); |
|
427 | - } |
|
414 | + /** |
|
415 | + * gets the HTTP content type for the current response. |
|
416 | + * |
|
417 | + * Note: getHTTPBody must be called before this. |
|
418 | + * |
|
419 | + * @return string the HTTP content type for the current response. |
|
420 | + * @access private |
|
421 | + */ |
|
422 | + function getHTTPContentType() { |
|
423 | + if (count($this->responseAttachments) > 0) { |
|
424 | + return $this->mimeContentType; |
|
425 | + } |
|
426 | + return parent::getHTTPContentType(); |
|
427 | + } |
|
428 | 428 | |
429 | - /** |
|
430 | - * gets the HTTP content type charset for the current response. |
|
431 | - * returns false for non-text content types. |
|
432 | - * |
|
433 | - * Note: getHTTPBody must be called before this. |
|
434 | - * |
|
435 | - * @return string the HTTP content type charset for the current response. |
|
436 | - * @access private |
|
437 | - */ |
|
438 | - function getHTTPContentTypeCharset() { |
|
439 | - if (count($this->responseAttachments) > 0) { |
|
440 | - return false; |
|
441 | - } |
|
442 | - return parent::getHTTPContentTypeCharset(); |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * processes SOAP message received from client |
|
447 | - * |
|
448 | - * @param array $headers The HTTP headers |
|
449 | - * @param string $data unprocessed request data from client |
|
450 | - * @return mixed value of the message, decoded into a PHP type |
|
451 | - * @access private |
|
452 | - */ |
|
429 | + /** |
|
430 | + * gets the HTTP content type charset for the current response. |
|
431 | + * returns false for non-text content types. |
|
432 | + * |
|
433 | + * Note: getHTTPBody must be called before this. |
|
434 | + * |
|
435 | + * @return string the HTTP content type charset for the current response. |
|
436 | + * @access private |
|
437 | + */ |
|
438 | + function getHTTPContentTypeCharset() { |
|
439 | + if (count($this->responseAttachments) > 0) { |
|
440 | + return false; |
|
441 | + } |
|
442 | + return parent::getHTTPContentTypeCharset(); |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * processes SOAP message received from client |
|
447 | + * |
|
448 | + * @param array $headers The HTTP headers |
|
449 | + * @param string $data unprocessed request data from client |
|
450 | + * @return mixed value of the message, decoded into a PHP type |
|
451 | + * @access private |
|
452 | + */ |
|
453 | 453 | function parseRequest($headers, $data) { |
454 | - $this->debug('Entering parseRequest() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']); |
|
455 | - $this->requestAttachments = array(); |
|
456 | - if (strstr($headers['content-type'], 'multipart/related')) { |
|
457 | - $this->debug('Decode multipart/related'); |
|
458 | - $input = ''; |
|
459 | - foreach ($headers as $k => $v) { |
|
460 | - $input .= "$k: $v\r\n"; |
|
461 | - } |
|
462 | - $params['input'] = $input . "\r\n" . $data; |
|
463 | - $params['include_bodies'] = true; |
|
464 | - $params['decode_bodies'] = true; |
|
465 | - $params['decode_headers'] = true; |
|
454 | + $this->debug('Entering parseRequest() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']); |
|
455 | + $this->requestAttachments = array(); |
|
456 | + if (strstr($headers['content-type'], 'multipart/related')) { |
|
457 | + $this->debug('Decode multipart/related'); |
|
458 | + $input = ''; |
|
459 | + foreach ($headers as $k => $v) { |
|
460 | + $input .= "$k: $v\r\n"; |
|
461 | + } |
|
462 | + $params['input'] = $input . "\r\n" . $data; |
|
463 | + $params['include_bodies'] = true; |
|
464 | + $params['decode_bodies'] = true; |
|
465 | + $params['decode_headers'] = true; |
|
466 | 466 | |
467 | - $structure = Mail_mimeDecode::decode($params); |
|
468 | - |
|
469 | - foreach ($structure->parts as $part) { |
|
470 | - if (!isset($part->disposition) && (strstr($part->headers['content-type'], 'text/xml'))) { |
|
471 | - $this->debug('Have root part of type ' . $part->headers['content-type']); |
|
472 | - $return = parent::parseRequest($part->headers, $part->body); |
|
473 | - } else { |
|
474 | - $this->debug('Have an attachment of type ' . $part->headers['content-type']); |
|
475 | - $info['data'] = $part->body; |
|
476 | - $info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : ''; |
|
477 | - $info['contenttype'] = $part->headers['content-type']; |
|
478 | - $info['cid'] = $part->headers['content-id']; |
|
479 | - $this->requestAttachments[] = $info; |
|
480 | - } |
|
481 | - } |
|
467 | + $structure = Mail_mimeDecode::decode($params); |
|
468 | + |
|
469 | + foreach ($structure->parts as $part) { |
|
470 | + if (!isset($part->disposition) && (strstr($part->headers['content-type'], 'text/xml'))) { |
|
471 | + $this->debug('Have root part of type ' . $part->headers['content-type']); |
|
472 | + $return = parent::parseRequest($part->headers, $part->body); |
|
473 | + } else { |
|
474 | + $this->debug('Have an attachment of type ' . $part->headers['content-type']); |
|
475 | + $info['data'] = $part->body; |
|
476 | + $info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : ''; |
|
477 | + $info['contenttype'] = $part->headers['content-type']; |
|
478 | + $info['cid'] = $part->headers['content-id']; |
|
479 | + $this->requestAttachments[] = $info; |
|
480 | + } |
|
481 | + } |
|
482 | 482 | |
483 | - if (isset($return)) { |
|
484 | - return $return; |
|
485 | - } |
|
483 | + if (isset($return)) { |
|
484 | + return $return; |
|
485 | + } |
|
486 | 486 | |
487 | - $this->setError('No root part found in multipart/related content'); |
|
488 | - return; |
|
489 | - } |
|
490 | - $this->debug('Not multipart/related'); |
|
491 | - return parent::parseRequest($headers, $data); |
|
492 | - } |
|
487 | + $this->setError('No root part found in multipart/related content'); |
|
488 | + return; |
|
489 | + } |
|
490 | + $this->debug('Not multipart/related'); |
|
491 | + return parent::parseRequest($headers, $data); |
|
492 | + } |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | /* |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * @access public |
14 | 14 | */ |
15 | 15 | class wsdl extends nusoap_base { |
16 | - // URL or filename of the root of this WSDL |
|
16 | + // URL or filename of the root of this WSDL |
|
17 | 17 | var $wsdl; |
18 | 18 | // define internal arrays of bindings, ports, operations, messages, etc. |
19 | 19 | var $schemas = array(); |
@@ -40,142 +40,142 @@ discard block |
||
40 | 40 | var $position = 0; |
41 | 41 | var $depth = 0; |
42 | 42 | var $depth_array = array(); |
43 | - // for getting wsdl |
|
44 | - var $proxyhost = ''; |
|
43 | + // for getting wsdl |
|
44 | + var $proxyhost = ''; |
|
45 | 45 | var $proxyport = ''; |
46 | - var $proxyusername = ''; |
|
47 | - var $proxypassword = ''; |
|
48 | - var $timeout = 0; |
|
49 | - var $response_timeout = 30; |
|
50 | - var $curl_options = array(); // User-specified cURL options |
|
51 | - var $use_curl = false; // whether to always try to use cURL |
|
52 | - // for HTTP authentication |
|
53 | - var $username = ''; // Username for HTTP authentication |
|
54 | - var $password = ''; // Password for HTTP authentication |
|
55 | - var $authtype = ''; // Type of HTTP authentication |
|
56 | - var $certRequest = array(); // Certificate for HTTP SSL authentication |
|
46 | + var $proxyusername = ''; |
|
47 | + var $proxypassword = ''; |
|
48 | + var $timeout = 0; |
|
49 | + var $response_timeout = 30; |
|
50 | + var $curl_options = array(); // User-specified cURL options |
|
51 | + var $use_curl = false; // whether to always try to use cURL |
|
52 | + // for HTTP authentication |
|
53 | + var $username = ''; // Username for HTTP authentication |
|
54 | + var $password = ''; // Password for HTTP authentication |
|
55 | + var $authtype = ''; // Type of HTTP authentication |
|
56 | + var $certRequest = array(); // Certificate for HTTP SSL authentication |
|
57 | 57 | |
58 | 58 | /** |
59 | 59 | * constructor |
60 | 60 | * |
61 | 61 | * @param string $wsdl WSDL document URL |
62 | - * @param string $proxyhost |
|
63 | - * @param string $proxyport |
|
64 | - * @param string $proxyusername |
|
65 | - * @param string $proxypassword |
|
66 | - * @param integer $timeout set the connection timeout |
|
67 | - * @param integer $response_timeout set the response timeout |
|
68 | - * @param array $curl_options user-specified cURL options |
|
69 | - * @param boolean $use_curl try to use cURL |
|
62 | + * @param string $proxyhost |
|
63 | + * @param string $proxyport |
|
64 | + * @param string $proxyusername |
|
65 | + * @param string $proxypassword |
|
66 | + * @param integer $timeout set the connection timeout |
|
67 | + * @param integer $response_timeout set the response timeout |
|
68 | + * @param array $curl_options user-specified cURL options |
|
69 | + * @param boolean $use_curl try to use cURL |
|
70 | 70 | * @access public |
71 | 71 | */ |
72 | 72 | function wsdl($wsdl = '',$proxyhost=false,$proxyport=false,$proxyusername=false,$proxypassword=false,$timeout=0,$response_timeout=30,$curl_options=null,$use_curl=false){ |
73 | - parent::nusoap_base(); |
|
74 | - $this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout"); |
|
73 | + parent::nusoap_base(); |
|
74 | + $this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout"); |
|
75 | 75 | $this->proxyhost = $proxyhost; |
76 | 76 | $this->proxyport = $proxyport; |
77 | - $this->proxyusername = $proxyusername; |
|
78 | - $this->proxypassword = $proxypassword; |
|
79 | - $this->timeout = $timeout; |
|
80 | - $this->response_timeout = $response_timeout; |
|
81 | - if (is_array($curl_options)) |
|
82 | - $this->curl_options = $curl_options; |
|
83 | - $this->use_curl = $use_curl; |
|
84 | - $this->fetchWSDL($wsdl); |
|
77 | + $this->proxyusername = $proxyusername; |
|
78 | + $this->proxypassword = $proxypassword; |
|
79 | + $this->timeout = $timeout; |
|
80 | + $this->response_timeout = $response_timeout; |
|
81 | + if (is_array($curl_options)) |
|
82 | + $this->curl_options = $curl_options; |
|
83 | + $this->use_curl = $use_curl; |
|
84 | + $this->fetchWSDL($wsdl); |
|
85 | 85 | } |
86 | 86 | |
87 | - /** |
|
88 | - * fetches the WSDL document and parses it |
|
89 | - * |
|
90 | - * @access public |
|
91 | - */ |
|
92 | - function fetchWSDL($wsdl) { |
|
93 | - $this->debug("parse and process WSDL path=$wsdl"); |
|
94 | - $this->wsdl = $wsdl; |
|
87 | + /** |
|
88 | + * fetches the WSDL document and parses it |
|
89 | + * |
|
90 | + * @access public |
|
91 | + */ |
|
92 | + function fetchWSDL($wsdl) { |
|
93 | + $this->debug("parse and process WSDL path=$wsdl"); |
|
94 | + $this->wsdl = $wsdl; |
|
95 | 95 | // parse wsdl file |
96 | 96 | if ($this->wsdl != "") { |
97 | 97 | $this->parseWSDL($this->wsdl); |
98 | 98 | } |
99 | 99 | // imports |
100 | 100 | // TODO: handle imports more properly, grabbing them in-line and nesting them |
101 | - $imported_urls = array(); |
|
102 | - $imported = 1; |
|
103 | - while ($imported > 0) { |
|
104 | - $imported = 0; |
|
105 | - // Schema imports |
|
106 | - foreach ($this->schemas as $ns => $list) { |
|
107 | - foreach ($list as $xs) { |
|
108 | - $wsdlparts = parse_url($this->wsdl); // this is bogusly simple! |
|
109 | - foreach ($xs->imports as $ns2 => $list2) { |
|
110 | - for ($ii = 0; $ii < count($list2); $ii++) { |
|
111 | - if (! $list2[$ii]['loaded']) { |
|
112 | - $this->schemas[$ns]->imports[$ns2][$ii]['loaded'] = true; |
|
113 | - $url = $list2[$ii]['location']; |
|
114 | - if ($url != '') { |
|
115 | - $urlparts = parse_url($url); |
|
116 | - if (!isset($urlparts['host'])) { |
|
117 | - $url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' .$wsdlparts['port'] : '') . |
|
118 | - substr($wsdlparts['path'],0,strrpos($wsdlparts['path'],'/') + 1) .$urlparts['path']; |
|
119 | - } |
|
120 | - if (! in_array($url, $imported_urls)) { |
|
121 | - $this->parseWSDL($url); |
|
122 | - $imported++; |
|
123 | - $imported_urls[] = $url; |
|
124 | - } |
|
125 | - } else { |
|
126 | - $this->debug("Unexpected scenario: empty URL for unloaded import"); |
|
127 | - } |
|
128 | - } |
|
129 | - } |
|
130 | - } |
|
131 | - } |
|
132 | - } |
|
133 | - // WSDL imports |
|
134 | - $wsdlparts = parse_url($this->wsdl); // this is bogusly simple! |
|
101 | + $imported_urls = array(); |
|
102 | + $imported = 1; |
|
103 | + while ($imported > 0) { |
|
104 | + $imported = 0; |
|
105 | + // Schema imports |
|
106 | + foreach ($this->schemas as $ns => $list) { |
|
107 | + foreach ($list as $xs) { |
|
108 | + $wsdlparts = parse_url($this->wsdl); // this is bogusly simple! |
|
109 | + foreach ($xs->imports as $ns2 => $list2) { |
|
110 | + for ($ii = 0; $ii < count($list2); $ii++) { |
|
111 | + if (! $list2[$ii]['loaded']) { |
|
112 | + $this->schemas[$ns]->imports[$ns2][$ii]['loaded'] = true; |
|
113 | + $url = $list2[$ii]['location']; |
|
114 | + if ($url != '') { |
|
115 | + $urlparts = parse_url($url); |
|
116 | + if (!isset($urlparts['host'])) { |
|
117 | + $url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' .$wsdlparts['port'] : '') . |
|
118 | + substr($wsdlparts['path'],0,strrpos($wsdlparts['path'],'/') + 1) .$urlparts['path']; |
|
119 | + } |
|
120 | + if (! in_array($url, $imported_urls)) { |
|
121 | + $this->parseWSDL($url); |
|
122 | + $imported++; |
|
123 | + $imported_urls[] = $url; |
|
124 | + } |
|
125 | + } else { |
|
126 | + $this->debug("Unexpected scenario: empty URL for unloaded import"); |
|
127 | + } |
|
128 | + } |
|
129 | + } |
|
130 | + } |
|
131 | + } |
|
132 | + } |
|
133 | + // WSDL imports |
|
134 | + $wsdlparts = parse_url($this->wsdl); // this is bogusly simple! |
|
135 | 135 | foreach ($this->import as $ns => $list) { |
136 | 136 | for ($ii = 0; $ii < count($list); $ii++) { |
137 | - if (! $list[$ii]['loaded']) { |
|
138 | - $this->import[$ns][$ii]['loaded'] = true; |
|
139 | - $url = $list[$ii]['location']; |
|
140 | - if ($url != '') { |
|
141 | - $urlparts = parse_url($url); |
|
142 | - if (!isset($urlparts['host'])) { |
|
143 | - $url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' . $wsdlparts['port'] : '') . |
|
144 | - substr($wsdlparts['path'],0,strrpos($wsdlparts['path'],'/') + 1) .$urlparts['path']; |
|
145 | - } |
|
146 | - if (! in_array($url, $imported_urls)) { |
|
147 | - $this->parseWSDL($url); |
|
148 | - $imported++; |
|
149 | - $imported_urls[] = $url; |
|
150 | - } |
|
151 | - } else { |
|
152 | - $this->debug("Unexpected scenario: empty URL for unloaded import"); |
|
153 | - } |
|
154 | - } |
|
155 | - } |
|
137 | + if (! $list[$ii]['loaded']) { |
|
138 | + $this->import[$ns][$ii]['loaded'] = true; |
|
139 | + $url = $list[$ii]['location']; |
|
140 | + if ($url != '') { |
|
141 | + $urlparts = parse_url($url); |
|
142 | + if (!isset($urlparts['host'])) { |
|
143 | + $url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' . $wsdlparts['port'] : '') . |
|
144 | + substr($wsdlparts['path'],0,strrpos($wsdlparts['path'],'/') + 1) .$urlparts['path']; |
|
145 | + } |
|
146 | + if (! in_array($url, $imported_urls)) { |
|
147 | + $this->parseWSDL($url); |
|
148 | + $imported++; |
|
149 | + $imported_urls[] = $url; |
|
150 | + } |
|
151 | + } else { |
|
152 | + $this->debug("Unexpected scenario: empty URL for unloaded import"); |
|
153 | + } |
|
154 | + } |
|
155 | + } |
|
156 | 156 | } |
157 | - } |
|
157 | + } |
|
158 | 158 | // add new data to operation data |
159 | 159 | foreach($this->bindings as $binding => $bindingData) { |
160 | 160 | if (isset($bindingData['operations']) && is_array($bindingData['operations'])) { |
161 | 161 | foreach($bindingData['operations'] as $operation => $data) { |
162 | 162 | $this->debug('post-parse data gathering for ' . $operation); |
163 | 163 | $this->bindings[$binding]['operations'][$operation]['input'] = |
164 | - isset($this->bindings[$binding]['operations'][$operation]['input']) ? |
|
165 | - array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[ $bindingData['portType'] ][$operation]['input']) : |
|
166 | - $this->portTypes[ $bindingData['portType'] ][$operation]['input']; |
|
164 | + isset($this->bindings[$binding]['operations'][$operation]['input']) ? |
|
165 | + array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[ $bindingData['portType'] ][$operation]['input']) : |
|
166 | + $this->portTypes[ $bindingData['portType'] ][$operation]['input']; |
|
167 | 167 | $this->bindings[$binding]['operations'][$operation]['output'] = |
168 | - isset($this->bindings[$binding]['operations'][$operation]['output']) ? |
|
169 | - array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[ $bindingData['portType'] ][$operation]['output']) : |
|
170 | - $this->portTypes[ $bindingData['portType'] ][$operation]['output']; |
|
168 | + isset($this->bindings[$binding]['operations'][$operation]['output']) ? |
|
169 | + array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[ $bindingData['portType'] ][$operation]['output']) : |
|
170 | + $this->portTypes[ $bindingData['portType'] ][$operation]['output']; |
|
171 | 171 | if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ])){ |
172 | - $this->bindings[$binding]['operations'][$operation]['input']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ]; |
|
173 | - } |
|
174 | - if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ])){ |
|
175 | - $this->bindings[$binding]['operations'][$operation]['output']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ]; |
|
172 | + $this->bindings[$binding]['operations'][$operation]['input']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ]; |
|
173 | + } |
|
174 | + if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ])){ |
|
175 | + $this->bindings[$binding]['operations'][$operation]['output']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ]; |
|
176 | 176 | } |
177 | 177 | // Set operation style if necessary, but do not override one already provided |
178 | - if (isset($bindingData['style']) && !isset($this->bindings[$binding]['operations'][$operation]['style'])) { |
|
178 | + if (isset($bindingData['style']) && !isset($this->bindings[$binding]['operations'][$operation]['style'])) { |
|
179 | 179 | $this->bindings[$binding]['operations'][$operation]['style'] = $bindingData['style']; |
180 | 180 | } |
181 | 181 | $this->bindings[$binding]['operations'][$operation]['transport'] = isset($bindingData['transport']) ? $bindingData['transport'] : ''; |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | } |
185 | 185 | } |
186 | 186 | } |
187 | - } |
|
187 | + } |
|
188 | 188 | |
189 | 189 | /** |
190 | 190 | * parses the wsdl document |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | * @access private |
194 | 194 | */ |
195 | 195 | function parseWSDL($wsdl = '') { |
196 | - $this->debug("parse WSDL at path=$wsdl"); |
|
196 | + $this->debug("parse WSDL at path=$wsdl"); |
|
197 | 197 | |
198 | 198 | if ($wsdl == '') { |
199 | 199 | $this->debug('no wsdl passed to parseWSDL()!!'); |
@@ -206,38 +206,38 @@ discard block |
||
206 | 206 | |
207 | 207 | if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'http' || $wsdl_props['scheme'] == 'https')) { |
208 | 208 | $this->debug('getting WSDL http(s) URL ' . $wsdl); |
209 | - // get wsdl |
|
210 | - $tr = new soap_transport_http($wsdl, $this->curl_options, $this->use_curl); |
|
211 | - $tr->request_method = 'GET'; |
|
212 | - $tr->useSOAPAction = false; |
|
213 | - if($this->proxyhost && $this->proxyport){ |
|
214 | - $tr->setProxy($this->proxyhost,$this->proxyport,$this->proxyusername,$this->proxypassword); |
|
215 | - } |
|
216 | - if ($this->authtype != '') { |
|
217 | - $tr->setCredentials($this->username, $this->password, $this->authtype, array(), $this->certRequest); |
|
218 | - } |
|
219 | - $tr->setEncoding('gzip, deflate'); |
|
220 | - $wsdl_string = $tr->send('', $this->timeout, $this->response_timeout); |
|
221 | - //$this->debug("WSDL request\n" . $tr->outgoing_payload); |
|
222 | - //$this->debug("WSDL response\n" . $tr->incoming_payload); |
|
223 | - $this->appendDebug($tr->getDebug()); |
|
224 | - // catch errors |
|
225 | - if($err = $tr->getError() ){ |
|
226 | - $errstr = 'Getting ' . $wsdl . ' - HTTP ERROR: '.$err; |
|
227 | - $this->debug($errstr); |
|
228 | - $this->setError($errstr); |
|
229 | - unset($tr); |
|
230 | - return false; |
|
231 | - } |
|
232 | - unset($tr); |
|
233 | - $this->debug("got WSDL URL"); |
|
209 | + // get wsdl |
|
210 | + $tr = new soap_transport_http($wsdl, $this->curl_options, $this->use_curl); |
|
211 | + $tr->request_method = 'GET'; |
|
212 | + $tr->useSOAPAction = false; |
|
213 | + if($this->proxyhost && $this->proxyport){ |
|
214 | + $tr->setProxy($this->proxyhost,$this->proxyport,$this->proxyusername,$this->proxypassword); |
|
215 | + } |
|
216 | + if ($this->authtype != '') { |
|
217 | + $tr->setCredentials($this->username, $this->password, $this->authtype, array(), $this->certRequest); |
|
218 | + } |
|
219 | + $tr->setEncoding('gzip, deflate'); |
|
220 | + $wsdl_string = $tr->send('', $this->timeout, $this->response_timeout); |
|
221 | + //$this->debug("WSDL request\n" . $tr->outgoing_payload); |
|
222 | + //$this->debug("WSDL response\n" . $tr->incoming_payload); |
|
223 | + $this->appendDebug($tr->getDebug()); |
|
224 | + // catch errors |
|
225 | + if($err = $tr->getError() ){ |
|
226 | + $errstr = 'Getting ' . $wsdl . ' - HTTP ERROR: '.$err; |
|
227 | + $this->debug($errstr); |
|
228 | + $this->setError($errstr); |
|
229 | + unset($tr); |
|
230 | + return false; |
|
231 | + } |
|
232 | + unset($tr); |
|
233 | + $this->debug("got WSDL URL"); |
|
234 | 234 | } else { |
235 | 235 | // $wsdl is not http(s), so treat it as a file URL or plain file path |
236 | - if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'file') && isset($wsdl_props['path'])) { |
|
237 | - $path = isset($wsdl_props['host']) ? ($wsdl_props['host'] . ':' . $wsdl_props['path']) : $wsdl_props['path']; |
|
238 | - } else { |
|
239 | - $path = $wsdl; |
|
240 | - } |
|
236 | + if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'file') && isset($wsdl_props['path'])) { |
|
237 | + $path = isset($wsdl_props['host']) ? ($wsdl_props['host'] . ':' . $wsdl_props['path']) : $wsdl_props['path']; |
|
238 | + } else { |
|
239 | + $path = $wsdl; |
|
240 | + } |
|
241 | 241 | $this->debug('getting WSDL file ' . $path); |
242 | 242 | if ($fp = @fopen($path, 'r')) { |
243 | 243 | $wsdl_string = ''; |
@@ -246,8 +246,8 @@ discard block |
||
246 | 246 | } |
247 | 247 | fclose($fp); |
248 | 248 | } else { |
249 | - $errstr = "Bad path to WSDL file $path"; |
|
250 | - $this->debug($errstr); |
|
249 | + $errstr = "Bad path to WSDL file $path"; |
|
250 | + $this->debug($errstr); |
|
251 | 251 | $this->setError($errstr); |
252 | 252 | return false; |
253 | 253 | } |
@@ -268,23 +268,23 @@ discard block |
||
268 | 268 | if (!xml_parse($this->parser, $wsdl_string, true)) { |
269 | 269 | // Display an error message. |
270 | 270 | $errstr = sprintf( |
271 | - 'XML error parsing WSDL from %s on line %d: %s', |
|
272 | - $wsdl, |
|
271 | + 'XML error parsing WSDL from %s on line %d: %s', |
|
272 | + $wsdl, |
|
273 | 273 | xml_get_current_line_number($this->parser), |
274 | 274 | xml_error_string(xml_get_error_code($this->parser)) |
275 | 275 | ); |
276 | 276 | $this->debug($errstr); |
277 | - $this->debug("XML payload:\n" . $wsdl_string); |
|
277 | + $this->debug("XML payload:\n" . $wsdl_string); |
|
278 | 278 | $this->setError($errstr); |
279 | 279 | return false; |
280 | 280 | } |
281 | - // free the parser |
|
281 | + // free the parser |
|
282 | 282 | xml_parser_free($this->parser); |
283 | 283 | $this->debug('Parsing WSDL done'); |
284 | - // catch wsdl parse errors |
|
285 | - if($this->getError()){ |
|
286 | - return false; |
|
287 | - } |
|
284 | + // catch wsdl parse errors |
|
285 | + if($this->getError()){ |
|
286 | + return false; |
|
287 | + } |
|
288 | 288 | return true; |
289 | 289 | } |
290 | 290 | |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | $this->appendDebug($this->currentSchema->getDebug()); |
304 | 304 | $this->currentSchema->clearDebug(); |
305 | 305 | } elseif (preg_match('/schema$/', $name)) { |
306 | - $this->debug('Parsing WSDL schema'); |
|
306 | + $this->debug('Parsing WSDL schema'); |
|
307 | 307 | // $this->debug("startElement for $name ($attrs[name]). status = $this->status (".$this->getLocalPart($name).")"); |
308 | 308 | $this->status = 'schema'; |
309 | 309 | $this->currentSchema = new nusoap_xmlschema('', '', $this->namespaces); |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | $this->message[$pos] = array('cdata' => ''); |
320 | 320 | // process attributes |
321 | 321 | if (count($attrs) > 0) { |
322 | - // register namespace declarations |
|
322 | + // register namespace declarations |
|
323 | 323 | foreach($attrs as $k => $v) { |
324 | 324 | if (preg_match('/^xmlns/',$k)) { |
325 | 325 | if ($ns_prefix = substr(strrchr($k, ':'), 1)) { |
@@ -354,417 +354,417 @@ discard block |
||
354 | 354 | // get unqualified name |
355 | 355 | $name = substr(strstr($name, ':'), 1); |
356 | 356 | } |
357 | - // process attributes, expanding any prefixes to namespaces |
|
357 | + // process attributes, expanding any prefixes to namespaces |
|
358 | 358 | // find status, register data |
359 | 359 | switch ($this->status) { |
360 | 360 | case 'message': |
361 | 361 | if ($name == 'part') { |
362 | - if (isset($attrs['type'])) { |
|
363 | - $this->debug("msg " . $this->currentMessage . ": found part (with type) $attrs[name]: " . implode(',', $attrs)); |
|
364 | - $this->messages[$this->currentMessage][$attrs['name']] = $attrs['type']; |
|
365 | - } |
|
366 | - if (isset($attrs['element'])) { |
|
367 | - $this->debug("msg " . $this->currentMessage . ": found part (with element) $attrs[name]: " . implode(',', $attrs)); |
|
368 | - $this->messages[$this->currentMessage][$attrs['name']] = $attrs['element'] . '^'; |
|
369 | - } |
|
370 | - } |
|
371 | - break; |
|
372 | - case 'portType': |
|
373 | - switch ($name) { |
|
374 | - case 'operation': |
|
375 | - $this->currentPortOperation = $attrs['name']; |
|
376 | - $this->debug("portType $this->currentPortType operation: $this->currentPortOperation"); |
|
377 | - if (isset($attrs['parameterOrder'])) { |
|
378 | - $this->portTypes[$this->currentPortType][$attrs['name']]['parameterOrder'] = $attrs['parameterOrder']; |
|
379 | - } |
|
380 | - break; |
|
381 | - case 'documentation': |
|
382 | - $this->documentation = true; |
|
383 | - break; |
|
384 | - // merge input/output data |
|
385 | - default: |
|
386 | - $m = isset($attrs['message']) ? $this->getLocalPart($attrs['message']) : ''; |
|
387 | - $this->portTypes[$this->currentPortType][$this->currentPortOperation][$name]['message'] = $m; |
|
388 | - break; |
|
389 | - } |
|
390 | - break; |
|
391 | - case 'binding': |
|
392 | - switch ($name) { |
|
393 | - case 'binding': |
|
394 | - // get ns prefix |
|
395 | - if (isset($attrs['style'])) { |
|
396 | - $this->bindings[$this->currentBinding]['prefix'] = $prefix; |
|
397 | - } |
|
398 | - $this->bindings[$this->currentBinding] = array_merge($this->bindings[$this->currentBinding], $attrs); |
|
399 | - break; |
|
400 | - case 'header': |
|
401 | - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus]['headers'][] = $attrs; |
|
402 | - break; |
|
403 | - case 'operation': |
|
404 | - if (isset($attrs['soapAction'])) { |
|
405 | - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['soapAction'] = $attrs['soapAction']; |
|
406 | - } |
|
407 | - if (isset($attrs['style'])) { |
|
408 | - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['style'] = $attrs['style']; |
|
409 | - } |
|
410 | - if (isset($attrs['name'])) { |
|
411 | - $this->currentOperation = $attrs['name']; |
|
412 | - $this->debug("current binding operation: $this->currentOperation"); |
|
413 | - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['name'] = $attrs['name']; |
|
414 | - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['binding'] = $this->currentBinding; |
|
415 | - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['endpoint'] = isset($this->bindings[$this->currentBinding]['endpoint']) ? $this->bindings[$this->currentBinding]['endpoint'] : ''; |
|
416 | - } |
|
417 | - break; |
|
418 | - case 'input': |
|
419 | - $this->opStatus = 'input'; |
|
420 | - break; |
|
421 | - case 'output': |
|
422 | - $this->opStatus = 'output'; |
|
423 | - break; |
|
424 | - case 'body': |
|
425 | - if (isset($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus])) { |
|
426 | - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = array_merge($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus], $attrs); |
|
427 | - } else { |
|
428 | - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = $attrs; |
|
429 | - } |
|
430 | - break; |
|
431 | - } |
|
432 | - break; |
|
433 | - case 'service': |
|
434 | - switch ($name) { |
|
435 | - case 'port': |
|
436 | - $this->currentPort = $attrs['name']; |
|
437 | - $this->debug('current port: ' . $this->currentPort); |
|
438 | - $this->ports[$this->currentPort]['binding'] = $this->getLocalPart($attrs['binding']); |
|
362 | + if (isset($attrs['type'])) { |
|
363 | + $this->debug("msg " . $this->currentMessage . ": found part (with type) $attrs[name]: " . implode(',', $attrs)); |
|
364 | + $this->messages[$this->currentMessage][$attrs['name']] = $attrs['type']; |
|
365 | + } |
|
366 | + if (isset($attrs['element'])) { |
|
367 | + $this->debug("msg " . $this->currentMessage . ": found part (with element) $attrs[name]: " . implode(',', $attrs)); |
|
368 | + $this->messages[$this->currentMessage][$attrs['name']] = $attrs['element'] . '^'; |
|
369 | + } |
|
370 | + } |
|
371 | + break; |
|
372 | + case 'portType': |
|
373 | + switch ($name) { |
|
374 | + case 'operation': |
|
375 | + $this->currentPortOperation = $attrs['name']; |
|
376 | + $this->debug("portType $this->currentPortType operation: $this->currentPortOperation"); |
|
377 | + if (isset($attrs['parameterOrder'])) { |
|
378 | + $this->portTypes[$this->currentPortType][$attrs['name']]['parameterOrder'] = $attrs['parameterOrder']; |
|
379 | + } |
|
380 | + break; |
|
381 | + case 'documentation': |
|
382 | + $this->documentation = true; |
|
383 | + break; |
|
384 | + // merge input/output data |
|
385 | + default: |
|
386 | + $m = isset($attrs['message']) ? $this->getLocalPart($attrs['message']) : ''; |
|
387 | + $this->portTypes[$this->currentPortType][$this->currentPortOperation][$name]['message'] = $m; |
|
388 | + break; |
|
389 | + } |
|
390 | + break; |
|
391 | + case 'binding': |
|
392 | + switch ($name) { |
|
393 | + case 'binding': |
|
394 | + // get ns prefix |
|
395 | + if (isset($attrs['style'])) { |
|
396 | + $this->bindings[$this->currentBinding]['prefix'] = $prefix; |
|
397 | + } |
|
398 | + $this->bindings[$this->currentBinding] = array_merge($this->bindings[$this->currentBinding], $attrs); |
|
399 | + break; |
|
400 | + case 'header': |
|
401 | + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus]['headers'][] = $attrs; |
|
402 | + break; |
|
403 | + case 'operation': |
|
404 | + if (isset($attrs['soapAction'])) { |
|
405 | + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['soapAction'] = $attrs['soapAction']; |
|
406 | + } |
|
407 | + if (isset($attrs['style'])) { |
|
408 | + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['style'] = $attrs['style']; |
|
409 | + } |
|
410 | + if (isset($attrs['name'])) { |
|
411 | + $this->currentOperation = $attrs['name']; |
|
412 | + $this->debug("current binding operation: $this->currentOperation"); |
|
413 | + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['name'] = $attrs['name']; |
|
414 | + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['binding'] = $this->currentBinding; |
|
415 | + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['endpoint'] = isset($this->bindings[$this->currentBinding]['endpoint']) ? $this->bindings[$this->currentBinding]['endpoint'] : ''; |
|
416 | + } |
|
417 | + break; |
|
418 | + case 'input': |
|
419 | + $this->opStatus = 'input'; |
|
420 | + break; |
|
421 | + case 'output': |
|
422 | + $this->opStatus = 'output'; |
|
423 | + break; |
|
424 | + case 'body': |
|
425 | + if (isset($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus])) { |
|
426 | + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = array_merge($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus], $attrs); |
|
427 | + } else { |
|
428 | + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = $attrs; |
|
429 | + } |
|
430 | + break; |
|
431 | + } |
|
432 | + break; |
|
433 | + case 'service': |
|
434 | + switch ($name) { |
|
435 | + case 'port': |
|
436 | + $this->currentPort = $attrs['name']; |
|
437 | + $this->debug('current port: ' . $this->currentPort); |
|
438 | + $this->ports[$this->currentPort]['binding'] = $this->getLocalPart($attrs['binding']); |
|
439 | 439 | |
440 | - break; |
|
441 | - case 'address': |
|
442 | - $this->ports[$this->currentPort]['location'] = $attrs['location']; |
|
443 | - $this->ports[$this->currentPort]['bindingType'] = $namespace; |
|
444 | - $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['bindingType'] = $namespace; |
|
445 | - $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['endpoint'] = $attrs['location']; |
|
446 | - break; |
|
447 | - } |
|
448 | - break; |
|
449 | - } |
|
450 | - // set status |
|
451 | - switch ($name) { |
|
452 | - case 'import': |
|
453 | - if (isset($attrs['location'])) { |
|
440 | + break; |
|
441 | + case 'address': |
|
442 | + $this->ports[$this->currentPort]['location'] = $attrs['location']; |
|
443 | + $this->ports[$this->currentPort]['bindingType'] = $namespace; |
|
444 | + $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['bindingType'] = $namespace; |
|
445 | + $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['endpoint'] = $attrs['location']; |
|
446 | + break; |
|
447 | + } |
|
448 | + break; |
|
449 | + } |
|
450 | + // set status |
|
451 | + switch ($name) { |
|
452 | + case 'import': |
|
453 | + if (isset($attrs['location'])) { |
|
454 | 454 | $this->import[$attrs['namespace']][] = array('location' => $attrs['location'], 'loaded' => false); |
455 | 455 | $this->debug('parsing import ' . $attrs['namespace']. ' - ' . $attrs['location'] . ' (' . count($this->import[$attrs['namespace']]).')'); |
456 | - } else { |
|
456 | + } else { |
|
457 | 457 | $this->import[$attrs['namespace']][] = array('location' => '', 'loaded' => true); |
458 | - if (! $this->getPrefixFromNamespace($attrs['namespace'])) { |
|
459 | - $this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace']; |
|
460 | - } |
|
458 | + if (! $this->getPrefixFromNamespace($attrs['namespace'])) { |
|
459 | + $this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace']; |
|
460 | + } |
|
461 | 461 | $this->debug('parsing import ' . $attrs['namespace']. ' - [no location] (' . count($this->import[$attrs['namespace']]).')'); |
462 | - } |
|
463 | - break; |
|
464 | - //wait for schema |
|
465 | - //case 'types': |
|
466 | - // $this->status = 'schema'; |
|
467 | - // break; |
|
468 | - case 'message': |
|
469 | - $this->status = 'message'; |
|
470 | - $this->messages[$attrs['name']] = array(); |
|
471 | - $this->currentMessage = $attrs['name']; |
|
472 | - break; |
|
473 | - case 'portType': |
|
474 | - $this->status = 'portType'; |
|
475 | - $this->portTypes[$attrs['name']] = array(); |
|
476 | - $this->currentPortType = $attrs['name']; |
|
477 | - break; |
|
478 | - case "binding": |
|
479 | - if (isset($attrs['name'])) { |
|
480 | - // get binding name |
|
481 | - if (strpos($attrs['name'], ':')) { |
|
482 | - $this->currentBinding = $this->getLocalPart($attrs['name']); |
|
483 | - } else { |
|
484 | - $this->currentBinding = $attrs['name']; |
|
485 | - } |
|
486 | - $this->status = 'binding'; |
|
487 | - $this->bindings[$this->currentBinding]['portType'] = $this->getLocalPart($attrs['type']); |
|
488 | - $this->debug("current binding: $this->currentBinding of portType: " . $attrs['type']); |
|
489 | - } |
|
490 | - break; |
|
491 | - case 'service': |
|
492 | - $this->serviceName = $attrs['name']; |
|
493 | - $this->status = 'service'; |
|
494 | - $this->debug('current service: ' . $this->serviceName); |
|
495 | - break; |
|
496 | - case 'definitions': |
|
497 | - foreach ($attrs as $name => $value) { |
|
498 | - $this->wsdl_info[$name] = $value; |
|
499 | - } |
|
500 | - break; |
|
501 | - } |
|
502 | - } |
|
503 | - } |
|
462 | + } |
|
463 | + break; |
|
464 | + //wait for schema |
|
465 | + //case 'types': |
|
466 | + // $this->status = 'schema'; |
|
467 | + // break; |
|
468 | + case 'message': |
|
469 | + $this->status = 'message'; |
|
470 | + $this->messages[$attrs['name']] = array(); |
|
471 | + $this->currentMessage = $attrs['name']; |
|
472 | + break; |
|
473 | + case 'portType': |
|
474 | + $this->status = 'portType'; |
|
475 | + $this->portTypes[$attrs['name']] = array(); |
|
476 | + $this->currentPortType = $attrs['name']; |
|
477 | + break; |
|
478 | + case "binding": |
|
479 | + if (isset($attrs['name'])) { |
|
480 | + // get binding name |
|
481 | + if (strpos($attrs['name'], ':')) { |
|
482 | + $this->currentBinding = $this->getLocalPart($attrs['name']); |
|
483 | + } else { |
|
484 | + $this->currentBinding = $attrs['name']; |
|
485 | + } |
|
486 | + $this->status = 'binding'; |
|
487 | + $this->bindings[$this->currentBinding]['portType'] = $this->getLocalPart($attrs['type']); |
|
488 | + $this->debug("current binding: $this->currentBinding of portType: " . $attrs['type']); |
|
489 | + } |
|
490 | + break; |
|
491 | + case 'service': |
|
492 | + $this->serviceName = $attrs['name']; |
|
493 | + $this->status = 'service'; |
|
494 | + $this->debug('current service: ' . $this->serviceName); |
|
495 | + break; |
|
496 | + case 'definitions': |
|
497 | + foreach ($attrs as $name => $value) { |
|
498 | + $this->wsdl_info[$name] = $value; |
|
499 | + } |
|
500 | + break; |
|
501 | + } |
|
502 | + } |
|
503 | + } |
|
504 | 504 | |
505 | - /** |
|
506 | - * end-element handler |
|
507 | - * |
|
508 | - * @param string $parser XML parser object |
|
509 | - * @param string $name element name |
|
510 | - * @access private |
|
511 | - */ |
|
512 | - function end_element($parser, $name){ |
|
513 | - // unset schema status |
|
514 | - if (/*preg_match('/types$/', $name) ||*/ preg_match('/schema$/', $name)) { |
|
515 | - $this->status = ""; |
|
505 | + /** |
|
506 | + * end-element handler |
|
507 | + * |
|
508 | + * @param string $parser XML parser object |
|
509 | + * @param string $name element name |
|
510 | + * @access private |
|
511 | + */ |
|
512 | + function end_element($parser, $name){ |
|
513 | + // unset schema status |
|
514 | + if (/*preg_match('/types$/', $name) ||*/ preg_match('/schema$/', $name)) { |
|
515 | + $this->status = ""; |
|
516 | 516 | $this->appendDebug($this->currentSchema->getDebug()); |
517 | 517 | $this->currentSchema->clearDebug(); |
518 | - $this->schemas[$this->currentSchema->schemaTargetNamespace][] = $this->currentSchema; |
|
519 | - $this->debug('Parsing WSDL schema done'); |
|
520 | - } |
|
521 | - if ($this->status == 'schema') { |
|
522 | - $this->currentSchema->schemaEndElement($parser, $name); |
|
523 | - } else { |
|
524 | - // bring depth down a notch |
|
525 | - $this->depth--; |
|
526 | - } |
|
527 | - // end documentation |
|
528 | - if ($this->documentation) { |
|
529 | - //TODO: track the node to which documentation should be assigned; it can be a part, message, etc. |
|
530 | - //$this->portTypes[$this->currentPortType][$this->currentPortOperation]['documentation'] = $this->documentation; |
|
531 | - $this->documentation = false; |
|
532 | - } |
|
533 | - } |
|
518 | + $this->schemas[$this->currentSchema->schemaTargetNamespace][] = $this->currentSchema; |
|
519 | + $this->debug('Parsing WSDL schema done'); |
|
520 | + } |
|
521 | + if ($this->status == 'schema') { |
|
522 | + $this->currentSchema->schemaEndElement($parser, $name); |
|
523 | + } else { |
|
524 | + // bring depth down a notch |
|
525 | + $this->depth--; |
|
526 | + } |
|
527 | + // end documentation |
|
528 | + if ($this->documentation) { |
|
529 | + //TODO: track the node to which documentation should be assigned; it can be a part, message, etc. |
|
530 | + //$this->portTypes[$this->currentPortType][$this->currentPortOperation]['documentation'] = $this->documentation; |
|
531 | + $this->documentation = false; |
|
532 | + } |
|
533 | + } |
|
534 | 534 | |
535 | - /** |
|
536 | - * element content handler |
|
537 | - * |
|
538 | - * @param string $parser XML parser object |
|
539 | - * @param string $data element content |
|
540 | - * @access private |
|
541 | - */ |
|
542 | - function character_data($parser, $data) |
|
543 | - { |
|
544 | - $pos = isset($this->depth_array[$this->depth]) ? $this->depth_array[$this->depth] : 0; |
|
545 | - if (isset($this->message[$pos]['cdata'])) { |
|
546 | - $this->message[$pos]['cdata'] .= $data; |
|
547 | - } |
|
548 | - if ($this->documentation) { |
|
549 | - $this->documentation .= $data; |
|
550 | - } |
|
551 | - } |
|
535 | + /** |
|
536 | + * element content handler |
|
537 | + * |
|
538 | + * @param string $parser XML parser object |
|
539 | + * @param string $data element content |
|
540 | + * @access private |
|
541 | + */ |
|
542 | + function character_data($parser, $data) |
|
543 | + { |
|
544 | + $pos = isset($this->depth_array[$this->depth]) ? $this->depth_array[$this->depth] : 0; |
|
545 | + if (isset($this->message[$pos]['cdata'])) { |
|
546 | + $this->message[$pos]['cdata'] .= $data; |
|
547 | + } |
|
548 | + if ($this->documentation) { |
|
549 | + $this->documentation .= $data; |
|
550 | + } |
|
551 | + } |
|
552 | 552 | |
553 | - /** |
|
554 | - * if authenticating, set user credentials here |
|
555 | - * |
|
556 | - * @param string $username |
|
557 | - * @param string $password |
|
558 | - * @param string $authtype (basic|digest|certificate|ntlm) |
|
559 | - * @param array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs) |
|
560 | - * @access public |
|
561 | - */ |
|
562 | - function setCredentials($username, $password, $authtype = 'basic', $certRequest = array()) { |
|
563 | - $this->debug("setCredentials username=$username authtype=$authtype certRequest="); |
|
564 | - $this->appendDebug($this->varDump($certRequest)); |
|
565 | - $this->username = $username; |
|
566 | - $this->password = $password; |
|
567 | - $this->authtype = $authtype; |
|
568 | - $this->certRequest = $certRequest; |
|
569 | - } |
|
553 | + /** |
|
554 | + * if authenticating, set user credentials here |
|
555 | + * |
|
556 | + * @param string $username |
|
557 | + * @param string $password |
|
558 | + * @param string $authtype (basic|digest|certificate|ntlm) |
|
559 | + * @param array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs) |
|
560 | + * @access public |
|
561 | + */ |
|
562 | + function setCredentials($username, $password, $authtype = 'basic', $certRequest = array()) { |
|
563 | + $this->debug("setCredentials username=$username authtype=$authtype certRequest="); |
|
564 | + $this->appendDebug($this->varDump($certRequest)); |
|
565 | + $this->username = $username; |
|
566 | + $this->password = $password; |
|
567 | + $this->authtype = $authtype; |
|
568 | + $this->certRequest = $certRequest; |
|
569 | + } |
|
570 | 570 | |
571 | - function getBindingData($binding) |
|
572 | - { |
|
573 | - if (is_array($this->bindings[$binding])) { |
|
574 | - return $this->bindings[$binding]; |
|
575 | - } |
|
576 | - } |
|
571 | + function getBindingData($binding) |
|
572 | + { |
|
573 | + if (is_array($this->bindings[$binding])) { |
|
574 | + return $this->bindings[$binding]; |
|
575 | + } |
|
576 | + } |
|
577 | 577 | |
578 | - /** |
|
579 | - * returns an assoc array of operation names => operation data |
|
580 | - * |
|
581 | - * @param string $portName WSDL port name |
|
582 | - * @param string $bindingType eg: soap, smtp, dime (only soap and soap12 are currently supported) |
|
583 | - * @return array |
|
584 | - * @access public |
|
585 | - */ |
|
586 | - function getOperations($portName = '', $bindingType = 'soap') { |
|
587 | - $ops = array(); |
|
588 | - if ($bindingType == 'soap') { |
|
589 | - $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/'; |
|
590 | - } elseif ($bindingType == 'soap12') { |
|
591 | - $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/'; |
|
592 | - } else { |
|
593 | - $this->debug("getOperations bindingType $bindingType may not be supported"); |
|
594 | - } |
|
595 | - $this->debug("getOperations for port '$portName' bindingType $bindingType"); |
|
596 | - // loop thru ports |
|
597 | - foreach($this->ports as $port => $portData) { |
|
598 | - $this->debug("getOperations checking port $port bindingType " . $portData['bindingType']); |
|
599 | - if ($portName == '' || $port == $portName) { |
|
600 | - // binding type of port matches parameter |
|
601 | - if ($portData['bindingType'] == $bindingType) { |
|
602 | - $this->debug("getOperations found port $port bindingType $bindingType"); |
|
603 | - //$this->debug("port data: " . $this->varDump($portData)); |
|
604 | - //$this->debug("bindings: " . $this->varDump($this->bindings[ $portData['binding'] ])); |
|
605 | - // merge bindings |
|
606 | - if (isset($this->bindings[ $portData['binding'] ]['operations'])) { |
|
607 | - $ops = array_merge ($ops, $this->bindings[ $portData['binding'] ]['operations']); |
|
608 | - } |
|
609 | - } |
|
610 | - } |
|
611 | - } |
|
612 | - if (count($ops) == 0) { |
|
613 | - $this->debug("getOperations found no operations for port '$portName' bindingType $bindingType"); |
|
614 | - } |
|
615 | - return $ops; |
|
616 | - } |
|
578 | + /** |
|
579 | + * returns an assoc array of operation names => operation data |
|
580 | + * |
|
581 | + * @param string $portName WSDL port name |
|
582 | + * @param string $bindingType eg: soap, smtp, dime (only soap and soap12 are currently supported) |
|
583 | + * @return array |
|
584 | + * @access public |
|
585 | + */ |
|
586 | + function getOperations($portName = '', $bindingType = 'soap') { |
|
587 | + $ops = array(); |
|
588 | + if ($bindingType == 'soap') { |
|
589 | + $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/'; |
|
590 | + } elseif ($bindingType == 'soap12') { |
|
591 | + $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/'; |
|
592 | + } else { |
|
593 | + $this->debug("getOperations bindingType $bindingType may not be supported"); |
|
594 | + } |
|
595 | + $this->debug("getOperations for port '$portName' bindingType $bindingType"); |
|
596 | + // loop thru ports |
|
597 | + foreach($this->ports as $port => $portData) { |
|
598 | + $this->debug("getOperations checking port $port bindingType " . $portData['bindingType']); |
|
599 | + if ($portName == '' || $port == $portName) { |
|
600 | + // binding type of port matches parameter |
|
601 | + if ($portData['bindingType'] == $bindingType) { |
|
602 | + $this->debug("getOperations found port $port bindingType $bindingType"); |
|
603 | + //$this->debug("port data: " . $this->varDump($portData)); |
|
604 | + //$this->debug("bindings: " . $this->varDump($this->bindings[ $portData['binding'] ])); |
|
605 | + // merge bindings |
|
606 | + if (isset($this->bindings[ $portData['binding'] ]['operations'])) { |
|
607 | + $ops = array_merge ($ops, $this->bindings[ $portData['binding'] ]['operations']); |
|
608 | + } |
|
609 | + } |
|
610 | + } |
|
611 | + } |
|
612 | + if (count($ops) == 0) { |
|
613 | + $this->debug("getOperations found no operations for port '$portName' bindingType $bindingType"); |
|
614 | + } |
|
615 | + return $ops; |
|
616 | + } |
|
617 | 617 | |
618 | - /** |
|
619 | - * returns an associative array of data necessary for calling an operation |
|
620 | - * |
|
621 | - * @param string $operation name of operation |
|
622 | - * @param string $bindingType type of binding eg: soap, soap12 |
|
623 | - * @return array |
|
624 | - * @access public |
|
625 | - */ |
|
626 | - function getOperationData($operation, $bindingType = 'soap') |
|
627 | - { |
|
628 | - if ($bindingType == 'soap') { |
|
629 | - $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/'; |
|
630 | - } elseif ($bindingType == 'soap12') { |
|
631 | - $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/'; |
|
632 | - } |
|
633 | - // loop thru ports |
|
634 | - foreach($this->ports as $port => $portData) { |
|
635 | - // binding type of port matches parameter |
|
636 | - if ($portData['bindingType'] == $bindingType) { |
|
637 | - // get binding |
|
638 | - //foreach($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) { |
|
639 | - foreach(array_keys($this->bindings[ $portData['binding'] ]['operations']) as $bOperation) { |
|
640 | - // note that we could/should also check the namespace here |
|
641 | - if ($operation == $bOperation) { |
|
642 | - $opData = $this->bindings[ $portData['binding'] ]['operations'][$operation]; |
|
643 | - return $opData; |
|
644 | - } |
|
645 | - } |
|
646 | - } |
|
647 | - } |
|
648 | - } |
|
618 | + /** |
|
619 | + * returns an associative array of data necessary for calling an operation |
|
620 | + * |
|
621 | + * @param string $operation name of operation |
|
622 | + * @param string $bindingType type of binding eg: soap, soap12 |
|
623 | + * @return array |
|
624 | + * @access public |
|
625 | + */ |
|
626 | + function getOperationData($operation, $bindingType = 'soap') |
|
627 | + { |
|
628 | + if ($bindingType == 'soap') { |
|
629 | + $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/'; |
|
630 | + } elseif ($bindingType == 'soap12') { |
|
631 | + $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/'; |
|
632 | + } |
|
633 | + // loop thru ports |
|
634 | + foreach($this->ports as $port => $portData) { |
|
635 | + // binding type of port matches parameter |
|
636 | + if ($portData['bindingType'] == $bindingType) { |
|
637 | + // get binding |
|
638 | + //foreach($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) { |
|
639 | + foreach(array_keys($this->bindings[ $portData['binding'] ]['operations']) as $bOperation) { |
|
640 | + // note that we could/should also check the namespace here |
|
641 | + if ($operation == $bOperation) { |
|
642 | + $opData = $this->bindings[ $portData['binding'] ]['operations'][$operation]; |
|
643 | + return $opData; |
|
644 | + } |
|
645 | + } |
|
646 | + } |
|
647 | + } |
|
648 | + } |
|
649 | 649 | |
650 | - /** |
|
651 | - * returns an associative array of data necessary for calling an operation |
|
652 | - * |
|
653 | - * @param string $soapAction soapAction for operation |
|
654 | - * @param string $bindingType type of binding eg: soap, soap12 |
|
655 | - * @return array |
|
656 | - * @access public |
|
657 | - */ |
|
658 | - function getOperationDataForSoapAction($soapAction, $bindingType = 'soap') { |
|
659 | - if ($bindingType == 'soap') { |
|
660 | - $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/'; |
|
661 | - } elseif ($bindingType == 'soap12') { |
|
662 | - $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/'; |
|
663 | - } |
|
664 | - // loop thru ports |
|
665 | - foreach($this->ports as $port => $portData) { |
|
666 | - // binding type of port matches parameter |
|
667 | - if ($portData['bindingType'] == $bindingType) { |
|
668 | - // loop through operations for the binding |
|
669 | - foreach ($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) { |
|
670 | - if ($opData['soapAction'] == $soapAction) { |
|
671 | - return $opData; |
|
672 | - } |
|
673 | - } |
|
674 | - } |
|
675 | - } |
|
676 | - } |
|
650 | + /** |
|
651 | + * returns an associative array of data necessary for calling an operation |
|
652 | + * |
|
653 | + * @param string $soapAction soapAction for operation |
|
654 | + * @param string $bindingType type of binding eg: soap, soap12 |
|
655 | + * @return array |
|
656 | + * @access public |
|
657 | + */ |
|
658 | + function getOperationDataForSoapAction($soapAction, $bindingType = 'soap') { |
|
659 | + if ($bindingType == 'soap') { |
|
660 | + $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/'; |
|
661 | + } elseif ($bindingType == 'soap12') { |
|
662 | + $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/'; |
|
663 | + } |
|
664 | + // loop thru ports |
|
665 | + foreach($this->ports as $port => $portData) { |
|
666 | + // binding type of port matches parameter |
|
667 | + if ($portData['bindingType'] == $bindingType) { |
|
668 | + // loop through operations for the binding |
|
669 | + foreach ($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) { |
|
670 | + if ($opData['soapAction'] == $soapAction) { |
|
671 | + return $opData; |
|
672 | + } |
|
673 | + } |
|
674 | + } |
|
675 | + } |
|
676 | + } |
|
677 | 677 | |
678 | - /** |
|
679 | - * returns an array of information about a given type |
|
680 | - * returns false if no type exists by the given name |
|
681 | - * |
|
682 | - * typeDef = array( |
|
683 | - * 'elements' => array(), // refs to elements array |
|
684 | - * 'restrictionBase' => '', |
|
685 | - * 'phpType' => '', |
|
686 | - * 'order' => '(sequence|all)', |
|
687 | - * 'attrs' => array() // refs to attributes array |
|
688 | - * ) |
|
689 | - * |
|
690 | - * @param string $type the type |
|
691 | - * @param string $ns namespace (not prefix) of the type |
|
692 | - * @return mixed |
|
693 | - * @access public |
|
694 | - * @see nusoap_xmlschema |
|
695 | - */ |
|
696 | - function getTypeDef($type, $ns) { |
|
697 | - $this->debug("in getTypeDef: type=$type, ns=$ns"); |
|
698 | - if ((! $ns) && isset($this->namespaces['tns'])) { |
|
699 | - $ns = $this->namespaces['tns']; |
|
700 | - $this->debug("in getTypeDef: type namespace forced to $ns"); |
|
701 | - } |
|
702 | - if (!isset($this->schemas[$ns])) { |
|
703 | - foreach ($this->schemas as $ns0 => $schema0) { |
|
704 | - if (strcasecmp($ns, $ns0) == 0) { |
|
705 | - $this->debug("in getTypeDef: replacing schema namespace $ns with $ns0"); |
|
706 | - $ns = $ns0; |
|
707 | - break; |
|
708 | - } |
|
709 | - } |
|
710 | - } |
|
711 | - if (isset($this->schemas[$ns])) { |
|
712 | - $this->debug("in getTypeDef: have schema for namespace $ns"); |
|
713 | - for ($i = 0; $i < count($this->schemas[$ns]); $i++) { |
|
714 | - $xs = &$this->schemas[$ns][$i]; |
|
715 | - $t = $xs->getTypeDef($type); |
|
716 | - $this->appendDebug($xs->getDebug()); |
|
717 | - $xs->clearDebug(); |
|
718 | - if ($t) { |
|
719 | - $this->debug("in getTypeDef: found type $type"); |
|
720 | - if (!isset($t['phpType'])) { |
|
721 | - // get info for type to tack onto the element |
|
722 | - $uqType = substr($t['type'], strrpos($t['type'], ':') + 1); |
|
723 | - $ns = substr($t['type'], 0, strrpos($t['type'], ':')); |
|
724 | - $etype = $this->getTypeDef($uqType, $ns); |
|
725 | - if ($etype) { |
|
726 | - $this->debug("found type for [element] $type:"); |
|
727 | - $this->debug($this->varDump($etype)); |
|
728 | - if (isset($etype['phpType'])) { |
|
729 | - $t['phpType'] = $etype['phpType']; |
|
730 | - } |
|
731 | - if (isset($etype['elements'])) { |
|
732 | - $t['elements'] = $etype['elements']; |
|
733 | - } |
|
734 | - if (isset($etype['attrs'])) { |
|
735 | - $t['attrs'] = $etype['attrs']; |
|
736 | - } |
|
737 | - } else { |
|
738 | - $this->debug("did not find type for [element] $type"); |
|
739 | - } |
|
740 | - } |
|
741 | - return $t; |
|
742 | - } |
|
743 | - } |
|
744 | - $this->debug("in getTypeDef: did not find type $type"); |
|
745 | - } else { |
|
746 | - $this->debug("in getTypeDef: do not have schema for namespace $ns"); |
|
747 | - } |
|
748 | - return false; |
|
749 | - } |
|
678 | + /** |
|
679 | + * returns an array of information about a given type |
|
680 | + * returns false if no type exists by the given name |
|
681 | + * |
|
682 | + * typeDef = array( |
|
683 | + * 'elements' => array(), // refs to elements array |
|
684 | + * 'restrictionBase' => '', |
|
685 | + * 'phpType' => '', |
|
686 | + * 'order' => '(sequence|all)', |
|
687 | + * 'attrs' => array() // refs to attributes array |
|
688 | + * ) |
|
689 | + * |
|
690 | + * @param string $type the type |
|
691 | + * @param string $ns namespace (not prefix) of the type |
|
692 | + * @return mixed |
|
693 | + * @access public |
|
694 | + * @see nusoap_xmlschema |
|
695 | + */ |
|
696 | + function getTypeDef($type, $ns) { |
|
697 | + $this->debug("in getTypeDef: type=$type, ns=$ns"); |
|
698 | + if ((! $ns) && isset($this->namespaces['tns'])) { |
|
699 | + $ns = $this->namespaces['tns']; |
|
700 | + $this->debug("in getTypeDef: type namespace forced to $ns"); |
|
701 | + } |
|
702 | + if (!isset($this->schemas[$ns])) { |
|
703 | + foreach ($this->schemas as $ns0 => $schema0) { |
|
704 | + if (strcasecmp($ns, $ns0) == 0) { |
|
705 | + $this->debug("in getTypeDef: replacing schema namespace $ns with $ns0"); |
|
706 | + $ns = $ns0; |
|
707 | + break; |
|
708 | + } |
|
709 | + } |
|
710 | + } |
|
711 | + if (isset($this->schemas[$ns])) { |
|
712 | + $this->debug("in getTypeDef: have schema for namespace $ns"); |
|
713 | + for ($i = 0; $i < count($this->schemas[$ns]); $i++) { |
|
714 | + $xs = &$this->schemas[$ns][$i]; |
|
715 | + $t = $xs->getTypeDef($type); |
|
716 | + $this->appendDebug($xs->getDebug()); |
|
717 | + $xs->clearDebug(); |
|
718 | + if ($t) { |
|
719 | + $this->debug("in getTypeDef: found type $type"); |
|
720 | + if (!isset($t['phpType'])) { |
|
721 | + // get info for type to tack onto the element |
|
722 | + $uqType = substr($t['type'], strrpos($t['type'], ':') + 1); |
|
723 | + $ns = substr($t['type'], 0, strrpos($t['type'], ':')); |
|
724 | + $etype = $this->getTypeDef($uqType, $ns); |
|
725 | + if ($etype) { |
|
726 | + $this->debug("found type for [element] $type:"); |
|
727 | + $this->debug($this->varDump($etype)); |
|
728 | + if (isset($etype['phpType'])) { |
|
729 | + $t['phpType'] = $etype['phpType']; |
|
730 | + } |
|
731 | + if (isset($etype['elements'])) { |
|
732 | + $t['elements'] = $etype['elements']; |
|
733 | + } |
|
734 | + if (isset($etype['attrs'])) { |
|
735 | + $t['attrs'] = $etype['attrs']; |
|
736 | + } |
|
737 | + } else { |
|
738 | + $this->debug("did not find type for [element] $type"); |
|
739 | + } |
|
740 | + } |
|
741 | + return $t; |
|
742 | + } |
|
743 | + } |
|
744 | + $this->debug("in getTypeDef: did not find type $type"); |
|
745 | + } else { |
|
746 | + $this->debug("in getTypeDef: do not have schema for namespace $ns"); |
|
747 | + } |
|
748 | + return false; |
|
749 | + } |
|
750 | 750 | |
751 | 751 | /** |
752 | - * prints html description of services |
|
753 | - * |
|
754 | - * @access private |
|
755 | - */ |
|
752 | + * prints html description of services |
|
753 | + * |
|
754 | + * @access private |
|
755 | + */ |
|
756 | 756 | function webDescription(){ |
757 | - global $HTTP_SERVER_VARS; |
|
757 | + global $HTTP_SERVER_VARS; |
|
758 | 758 | |
759 | - if (isset($_SERVER)) { |
|
760 | - $PHP_SELF = $_SERVER['PHP_SELF']; |
|
761 | - } elseif (isset($HTTP_SERVER_VARS)) { |
|
762 | - $PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF']; |
|
763 | - } else { |
|
764 | - $this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available"); |
|
765 | - } |
|
759 | + if (isset($_SERVER)) { |
|
760 | + $PHP_SELF = $_SERVER['PHP_SELF']; |
|
761 | + } elseif (isset($HTTP_SERVER_VARS)) { |
|
762 | + $PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF']; |
|
763 | + } else { |
|
764 | + $this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available"); |
|
765 | + } |
|
766 | 766 | |
767 | - $b = ' |
|
767 | + $b = ' |
|
768 | 768 | <html><head><title>NuSOAP: '.$this->serviceName.'</title> |
769 | 769 | <style type="text/css"> |
770 | 770 | body { font-family: arial; color: #000000; background-color: #ffffff; margin: 0px 0px 0px 0px; } |
@@ -847,1092 +847,1092 @@ discard block |
||
847 | 847 | <p>View the <a href="'.$PHP_SELF.'?wsdl">WSDL</a> for the service. |
848 | 848 | Click on an operation name to view it's details.</p> |
849 | 849 | <ul>'; |
850 | - foreach($this->getOperations() as $op => $data){ |
|
851 | - $b .= "<li><a href='#' onclick=\"popout();popup('$op')\">$op</a></li>"; |
|
852 | - // create hidden div |
|
853 | - $b .= "<div id='$op' class='hidden'> |
|
850 | + foreach($this->getOperations() as $op => $data){ |
|
851 | + $b .= "<li><a href='#' onclick=\"popout();popup('$op')\">$op</a></li>"; |
|
852 | + // create hidden div |
|
853 | + $b .= "<div id='$op' class='hidden'> |
|
854 | 854 | <a href='#' onclick='popout()'><font color='#ffffff'>Close</font></a><br><br>"; |
855 | - foreach($data as $donnie => $marie){ // loop through opdata |
|
856 | - if($donnie == 'input' || $donnie == 'output'){ // show input/output data |
|
857 | - $b .= "<font color='white'>".ucfirst($donnie).':</font><br>'; |
|
858 | - foreach($marie as $captain => $tenille){ // loop through data |
|
859 | - if($captain == 'parts'){ // loop thru parts |
|
860 | - $b .= " $captain:<br>"; |
|
861 | - //if(is_array($tenille)){ |
|
862 | - foreach($tenille as $joanie => $chachi){ |
|
863 | - $b .= " $joanie: $chachi<br>"; |
|
864 | - } |
|
865 | - //} |
|
866 | - } else { |
|
867 | - $b .= " $captain: $tenille<br>"; |
|
868 | - } |
|
869 | - } |
|
870 | - } else { |
|
871 | - $b .= "<font color='white'>".ucfirst($donnie).":</font> $marie<br>"; |
|
872 | - } |
|
873 | - } |
|
874 | - $b .= '</div>'; |
|
875 | - } |
|
876 | - $b .= ' |
|
855 | + foreach($data as $donnie => $marie){ // loop through opdata |
|
856 | + if($donnie == 'input' || $donnie == 'output'){ // show input/output data |
|
857 | + $b .= "<font color='white'>".ucfirst($donnie).':</font><br>'; |
|
858 | + foreach($marie as $captain => $tenille){ // loop through data |
|
859 | + if($captain == 'parts'){ // loop thru parts |
|
860 | + $b .= " $captain:<br>"; |
|
861 | + //if(is_array($tenille)){ |
|
862 | + foreach($tenille as $joanie => $chachi){ |
|
863 | + $b .= " $joanie: $chachi<br>"; |
|
864 | + } |
|
865 | + //} |
|
866 | + } else { |
|
867 | + $b .= " $captain: $tenille<br>"; |
|
868 | + } |
|
869 | + } |
|
870 | + } else { |
|
871 | + $b .= "<font color='white'>".ucfirst($donnie).":</font> $marie<br>"; |
|
872 | + } |
|
873 | + } |
|
874 | + $b .= '</div>'; |
|
875 | + } |
|
876 | + $b .= ' |
|
877 | 877 | <ul> |
878 | 878 | </div> |
879 | 879 | </div></body></html>'; |
880 | - return $b; |
|
880 | + return $b; |
|
881 | 881 | } |
882 | 882 | |
883 | - /** |
|
884 | - * serialize the parsed wsdl |
|
885 | - * |
|
886 | - * @param mixed $debug whether to put debug=1 in endpoint URL |
|
887 | - * @return string serialization of WSDL |
|
888 | - * @access public |
|
889 | - */ |
|
890 | - function serialize($debug = 0) |
|
891 | - { |
|
892 | - $xml = '<?xml version="1.0" encoding="ISO-8859-1"?>'; |
|
893 | - $xml .= "\n<definitions"; |
|
894 | - foreach($this->namespaces as $k => $v) { |
|
895 | - $xml .= " xmlns:$k=\"$v\""; |
|
896 | - } |
|
897 | - // 10.9.02 - add poulter fix for wsdl and tns declarations |
|
898 | - if (isset($this->namespaces['wsdl'])) { |
|
899 | - $xml .= " xmlns=\"" . $this->namespaces['wsdl'] . "\""; |
|
900 | - } |
|
901 | - if (isset($this->namespaces['tns'])) { |
|
902 | - $xml .= " targetNamespace=\"" . $this->namespaces['tns'] . "\""; |
|
903 | - } |
|
904 | - $xml .= '>'; |
|
905 | - // imports |
|
906 | - if (sizeof($this->import) > 0) { |
|
907 | - foreach($this->import as $ns => $list) { |
|
908 | - foreach ($list as $ii) { |
|
909 | - if ($ii['location'] != '') { |
|
910 | - $xml .= '<import location="' . $ii['location'] . '" namespace="' . $ns . '" />'; |
|
911 | - } else { |
|
912 | - $xml .= '<import namespace="' . $ns . '" />'; |
|
913 | - } |
|
914 | - } |
|
915 | - } |
|
916 | - } |
|
917 | - // types |
|
918 | - if (count($this->schemas)>=1) { |
|
919 | - $xml .= "\n<types>\n"; |
|
920 | - foreach ($this->schemas as $ns => $list) { |
|
921 | - foreach ($list as $xs) { |
|
922 | - $xml .= $xs->serializeSchema(); |
|
923 | - } |
|
924 | - } |
|
925 | - $xml .= '</types>'; |
|
926 | - } |
|
927 | - // messages |
|
928 | - if (count($this->messages) >= 1) { |
|
929 | - foreach($this->messages as $msgName => $msgParts) { |
|
930 | - $xml .= "\n<message name=\"" . $msgName . '">'; |
|
931 | - if(is_array($msgParts)){ |
|
932 | - foreach($msgParts as $partName => $partType) { |
|
933 | - // print 'serializing '.$partType.', sv: '.$this->XMLSchemaVersion.'<br>'; |
|
934 | - if (strpos($partType, ':')) { |
|
935 | - $typePrefix = $this->getPrefixFromNamespace($this->getPrefix($partType)); |
|
936 | - } elseif (isset($this->typemap[$this->namespaces['xsd']][$partType])) { |
|
937 | - // print 'checking typemap: '.$this->XMLSchemaVersion.'<br>'; |
|
938 | - $typePrefix = 'xsd'; |
|
939 | - } else { |
|
940 | - foreach($this->typemap as $ns => $types) { |
|
941 | - if (isset($types[$partType])) { |
|
942 | - $typePrefix = $this->getPrefixFromNamespace($ns); |
|
943 | - } |
|
944 | - } |
|
945 | - if (!isset($typePrefix)) { |
|
946 | - die("$partType has no namespace!"); |
|
947 | - } |
|
948 | - } |
|
949 | - $ns = $this->getNamespaceFromPrefix($typePrefix); |
|
950 | - $localPart = $this->getLocalPart($partType); |
|
951 | - $typeDef = $this->getTypeDef($localPart, $ns); |
|
952 | - if ($typeDef['typeClass'] == 'element') { |
|
953 | - $elementortype = 'element'; |
|
954 | - if (substr($localPart, -1) == '^') { |
|
955 | - $localPart = substr($localPart, 0, -1); |
|
956 | - } |
|
957 | - } else { |
|
958 | - $elementortype = 'type'; |
|
959 | - } |
|
960 | - $xml .= "\n" . ' <part name="' . $partName . '" ' . $elementortype . '="' . $typePrefix . ':' . $localPart . '" />'; |
|
961 | - } |
|
962 | - } |
|
963 | - $xml .= '</message>'; |
|
964 | - } |
|
965 | - } |
|
966 | - // bindings & porttypes |
|
967 | - if (count($this->bindings) >= 1) { |
|
968 | - $binding_xml = ''; |
|
969 | - $portType_xml = ''; |
|
970 | - foreach($this->bindings as $bindingName => $attrs) { |
|
971 | - $binding_xml .= "\n<binding name=\"" . $bindingName . '" type="tns:' . $attrs['portType'] . '">'; |
|
972 | - $binding_xml .= "\n" . ' <soap:binding style="' . $attrs['style'] . '" transport="' . $attrs['transport'] . '"/>'; |
|
973 | - $portType_xml .= "\n<portType name=\"" . $attrs['portType'] . '">'; |
|
974 | - foreach($attrs['operations'] as $opName => $opParts) { |
|
975 | - $binding_xml .= "\n" . ' <operation name="' . $opName . '">'; |
|
976 | - $binding_xml .= "\n" . ' <soap:operation soapAction="' . $opParts['soapAction'] . '" style="'. $opParts['style'] . '"/>'; |
|
977 | - if (isset($opParts['input']['encodingStyle']) && $opParts['input']['encodingStyle'] != '') { |
|
978 | - $enc_style = ' encodingStyle="' . $opParts['input']['encodingStyle'] . '"'; |
|
979 | - } else { |
|
980 | - $enc_style = ''; |
|
981 | - } |
|
982 | - $binding_xml .= "\n" . ' <input><soap:body use="' . $opParts['input']['use'] . '" namespace="' . $opParts['input']['namespace'] . '"' . $enc_style . '/></input>'; |
|
983 | - if (isset($opParts['output']['encodingStyle']) && $opParts['output']['encodingStyle'] != '') { |
|
984 | - $enc_style = ' encodingStyle="' . $opParts['output']['encodingStyle'] . '"'; |
|
985 | - } else { |
|
986 | - $enc_style = ''; |
|
987 | - } |
|
988 | - $binding_xml .= "\n" . ' <output><soap:body use="' . $opParts['output']['use'] . '" namespace="' . $opParts['output']['namespace'] . '"' . $enc_style . '/></output>'; |
|
989 | - $binding_xml .= "\n" . ' </operation>'; |
|
990 | - $portType_xml .= "\n" . ' <operation name="' . $opParts['name'] . '"'; |
|
991 | - if (isset($opParts['parameterOrder'])) { |
|
992 | - $portType_xml .= ' parameterOrder="' . $opParts['parameterOrder'] . '"'; |
|
993 | - } |
|
994 | - $portType_xml .= '>'; |
|
995 | - if(isset($opParts['documentation']) && $opParts['documentation'] != '') { |
|
996 | - $portType_xml .= "\n" . ' <documentation>' . htmlspecialchars($opParts['documentation']) . '</documentation>'; |
|
997 | - } |
|
998 | - $portType_xml .= "\n" . ' <input message="tns:' . $opParts['input']['message'] . '"/>'; |
|
999 | - $portType_xml .= "\n" . ' <output message="tns:' . $opParts['output']['message'] . '"/>'; |
|
1000 | - $portType_xml .= "\n" . ' </operation>'; |
|
1001 | - } |
|
1002 | - $portType_xml .= "\n" . '</portType>'; |
|
1003 | - $binding_xml .= "\n" . '</binding>'; |
|
1004 | - } |
|
1005 | - $xml .= $portType_xml . $binding_xml; |
|
1006 | - } |
|
1007 | - // services |
|
1008 | - $xml .= "\n<service name=\"" . $this->serviceName . '">'; |
|
1009 | - if (count($this->ports) >= 1) { |
|
1010 | - foreach($this->ports as $pName => $attrs) { |
|
1011 | - $xml .= "\n" . ' <port name="' . $pName . '" binding="tns:' . $attrs['binding'] . '">'; |
|
1012 | - $xml .= "\n" . ' <soap:address location="' . $attrs['location'] . ($debug ? '?debug=1' : '') . '"/>'; |
|
1013 | - $xml .= "\n" . ' </port>'; |
|
1014 | - } |
|
1015 | - } |
|
1016 | - $xml .= "\n" . '</service>'; |
|
1017 | - return $xml . "\n</definitions>"; |
|
1018 | - } |
|
883 | + /** |
|
884 | + * serialize the parsed wsdl |
|
885 | + * |
|
886 | + * @param mixed $debug whether to put debug=1 in endpoint URL |
|
887 | + * @return string serialization of WSDL |
|
888 | + * @access public |
|
889 | + */ |
|
890 | + function serialize($debug = 0) |
|
891 | + { |
|
892 | + $xml = '<?xml version="1.0" encoding="ISO-8859-1"?>'; |
|
893 | + $xml .= "\n<definitions"; |
|
894 | + foreach($this->namespaces as $k => $v) { |
|
895 | + $xml .= " xmlns:$k=\"$v\""; |
|
896 | + } |
|
897 | + // 10.9.02 - add poulter fix for wsdl and tns declarations |
|
898 | + if (isset($this->namespaces['wsdl'])) { |
|
899 | + $xml .= " xmlns=\"" . $this->namespaces['wsdl'] . "\""; |
|
900 | + } |
|
901 | + if (isset($this->namespaces['tns'])) { |
|
902 | + $xml .= " targetNamespace=\"" . $this->namespaces['tns'] . "\""; |
|
903 | + } |
|
904 | + $xml .= '>'; |
|
905 | + // imports |
|
906 | + if (sizeof($this->import) > 0) { |
|
907 | + foreach($this->import as $ns => $list) { |
|
908 | + foreach ($list as $ii) { |
|
909 | + if ($ii['location'] != '') { |
|
910 | + $xml .= '<import location="' . $ii['location'] . '" namespace="' . $ns . '" />'; |
|
911 | + } else { |
|
912 | + $xml .= '<import namespace="' . $ns . '" />'; |
|
913 | + } |
|
914 | + } |
|
915 | + } |
|
916 | + } |
|
917 | + // types |
|
918 | + if (count($this->schemas)>=1) { |
|
919 | + $xml .= "\n<types>\n"; |
|
920 | + foreach ($this->schemas as $ns => $list) { |
|
921 | + foreach ($list as $xs) { |
|
922 | + $xml .= $xs->serializeSchema(); |
|
923 | + } |
|
924 | + } |
|
925 | + $xml .= '</types>'; |
|
926 | + } |
|
927 | + // messages |
|
928 | + if (count($this->messages) >= 1) { |
|
929 | + foreach($this->messages as $msgName => $msgParts) { |
|
930 | + $xml .= "\n<message name=\"" . $msgName . '">'; |
|
931 | + if(is_array($msgParts)){ |
|
932 | + foreach($msgParts as $partName => $partType) { |
|
933 | + // print 'serializing '.$partType.', sv: '.$this->XMLSchemaVersion.'<br>'; |
|
934 | + if (strpos($partType, ':')) { |
|
935 | + $typePrefix = $this->getPrefixFromNamespace($this->getPrefix($partType)); |
|
936 | + } elseif (isset($this->typemap[$this->namespaces['xsd']][$partType])) { |
|
937 | + // print 'checking typemap: '.$this->XMLSchemaVersion.'<br>'; |
|
938 | + $typePrefix = 'xsd'; |
|
939 | + } else { |
|
940 | + foreach($this->typemap as $ns => $types) { |
|
941 | + if (isset($types[$partType])) { |
|
942 | + $typePrefix = $this->getPrefixFromNamespace($ns); |
|
943 | + } |
|
944 | + } |
|
945 | + if (!isset($typePrefix)) { |
|
946 | + die("$partType has no namespace!"); |
|
947 | + } |
|
948 | + } |
|
949 | + $ns = $this->getNamespaceFromPrefix($typePrefix); |
|
950 | + $localPart = $this->getLocalPart($partType); |
|
951 | + $typeDef = $this->getTypeDef($localPart, $ns); |
|
952 | + if ($typeDef['typeClass'] == 'element') { |
|
953 | + $elementortype = 'element'; |
|
954 | + if (substr($localPart, -1) == '^') { |
|
955 | + $localPart = substr($localPart, 0, -1); |
|
956 | + } |
|
957 | + } else { |
|
958 | + $elementortype = 'type'; |
|
959 | + } |
|
960 | + $xml .= "\n" . ' <part name="' . $partName . '" ' . $elementortype . '="' . $typePrefix . ':' . $localPart . '" />'; |
|
961 | + } |
|
962 | + } |
|
963 | + $xml .= '</message>'; |
|
964 | + } |
|
965 | + } |
|
966 | + // bindings & porttypes |
|
967 | + if (count($this->bindings) >= 1) { |
|
968 | + $binding_xml = ''; |
|
969 | + $portType_xml = ''; |
|
970 | + foreach($this->bindings as $bindingName => $attrs) { |
|
971 | + $binding_xml .= "\n<binding name=\"" . $bindingName . '" type="tns:' . $attrs['portType'] . '">'; |
|
972 | + $binding_xml .= "\n" . ' <soap:binding style="' . $attrs['style'] . '" transport="' . $attrs['transport'] . '"/>'; |
|
973 | + $portType_xml .= "\n<portType name=\"" . $attrs['portType'] . '">'; |
|
974 | + foreach($attrs['operations'] as $opName => $opParts) { |
|
975 | + $binding_xml .= "\n" . ' <operation name="' . $opName . '">'; |
|
976 | + $binding_xml .= "\n" . ' <soap:operation soapAction="' . $opParts['soapAction'] . '" style="'. $opParts['style'] . '"/>'; |
|
977 | + if (isset($opParts['input']['encodingStyle']) && $opParts['input']['encodingStyle'] != '') { |
|
978 | + $enc_style = ' encodingStyle="' . $opParts['input']['encodingStyle'] . '"'; |
|
979 | + } else { |
|
980 | + $enc_style = ''; |
|
981 | + } |
|
982 | + $binding_xml .= "\n" . ' <input><soap:body use="' . $opParts['input']['use'] . '" namespace="' . $opParts['input']['namespace'] . '"' . $enc_style . '/></input>'; |
|
983 | + if (isset($opParts['output']['encodingStyle']) && $opParts['output']['encodingStyle'] != '') { |
|
984 | + $enc_style = ' encodingStyle="' . $opParts['output']['encodingStyle'] . '"'; |
|
985 | + } else { |
|
986 | + $enc_style = ''; |
|
987 | + } |
|
988 | + $binding_xml .= "\n" . ' <output><soap:body use="' . $opParts['output']['use'] . '" namespace="' . $opParts['output']['namespace'] . '"' . $enc_style . '/></output>'; |
|
989 | + $binding_xml .= "\n" . ' </operation>'; |
|
990 | + $portType_xml .= "\n" . ' <operation name="' . $opParts['name'] . '"'; |
|
991 | + if (isset($opParts['parameterOrder'])) { |
|
992 | + $portType_xml .= ' parameterOrder="' . $opParts['parameterOrder'] . '"'; |
|
993 | + } |
|
994 | + $portType_xml .= '>'; |
|
995 | + if(isset($opParts['documentation']) && $opParts['documentation'] != '') { |
|
996 | + $portType_xml .= "\n" . ' <documentation>' . htmlspecialchars($opParts['documentation']) . '</documentation>'; |
|
997 | + } |
|
998 | + $portType_xml .= "\n" . ' <input message="tns:' . $opParts['input']['message'] . '"/>'; |
|
999 | + $portType_xml .= "\n" . ' <output message="tns:' . $opParts['output']['message'] . '"/>'; |
|
1000 | + $portType_xml .= "\n" . ' </operation>'; |
|
1001 | + } |
|
1002 | + $portType_xml .= "\n" . '</portType>'; |
|
1003 | + $binding_xml .= "\n" . '</binding>'; |
|
1004 | + } |
|
1005 | + $xml .= $portType_xml . $binding_xml; |
|
1006 | + } |
|
1007 | + // services |
|
1008 | + $xml .= "\n<service name=\"" . $this->serviceName . '">'; |
|
1009 | + if (count($this->ports) >= 1) { |
|
1010 | + foreach($this->ports as $pName => $attrs) { |
|
1011 | + $xml .= "\n" . ' <port name="' . $pName . '" binding="tns:' . $attrs['binding'] . '">'; |
|
1012 | + $xml .= "\n" . ' <soap:address location="' . $attrs['location'] . ($debug ? '?debug=1' : '') . '"/>'; |
|
1013 | + $xml .= "\n" . ' </port>'; |
|
1014 | + } |
|
1015 | + } |
|
1016 | + $xml .= "\n" . '</service>'; |
|
1017 | + return $xml . "\n</definitions>"; |
|
1018 | + } |
|
1019 | 1019 | |
1020 | - /** |
|
1021 | - * determine whether a set of parameters are unwrapped |
|
1022 | - * when they are expect to be wrapped, Microsoft-style. |
|
1023 | - * |
|
1024 | - * @param string $type the type (element name) of the wrapper |
|
1025 | - * @param array $parameters the parameter values for the SOAP call |
|
1026 | - * @return boolean whether they parameters are unwrapped (and should be wrapped) |
|
1027 | - * @access private |
|
1028 | - */ |
|
1029 | - function parametersMatchWrapped($type, &$parameters) { |
|
1030 | - $this->debug("in parametersMatchWrapped type=$type, parameters="); |
|
1031 | - $this->appendDebug($this->varDump($parameters)); |
|
1020 | + /** |
|
1021 | + * determine whether a set of parameters are unwrapped |
|
1022 | + * when they are expect to be wrapped, Microsoft-style. |
|
1023 | + * |
|
1024 | + * @param string $type the type (element name) of the wrapper |
|
1025 | + * @param array $parameters the parameter values for the SOAP call |
|
1026 | + * @return boolean whether they parameters are unwrapped (and should be wrapped) |
|
1027 | + * @access private |
|
1028 | + */ |
|
1029 | + function parametersMatchWrapped($type, &$parameters) { |
|
1030 | + $this->debug("in parametersMatchWrapped type=$type, parameters="); |
|
1031 | + $this->appendDebug($this->varDump($parameters)); |
|
1032 | 1032 | |
1033 | - // split type into namespace:unqualified-type |
|
1034 | - if (strpos($type, ':')) { |
|
1035 | - $uqType = substr($type, strrpos($type, ':') + 1); |
|
1036 | - $ns = substr($type, 0, strrpos($type, ':')); |
|
1037 | - $this->debug("in parametersMatchWrapped: got a prefixed type: $uqType, $ns"); |
|
1038 | - if ($this->getNamespaceFromPrefix($ns)) { |
|
1039 | - $ns = $this->getNamespaceFromPrefix($ns); |
|
1040 | - $this->debug("in parametersMatchWrapped: expanded prefixed type: $uqType, $ns"); |
|
1041 | - } |
|
1042 | - } else { |
|
1043 | - // TODO: should the type be compared to types in XSD, and the namespace |
|
1044 | - // set to XSD if the type matches? |
|
1045 | - $this->debug("in parametersMatchWrapped: No namespace for type $type"); |
|
1046 | - $ns = ''; |
|
1047 | - $uqType = $type; |
|
1048 | - } |
|
1033 | + // split type into namespace:unqualified-type |
|
1034 | + if (strpos($type, ':')) { |
|
1035 | + $uqType = substr($type, strrpos($type, ':') + 1); |
|
1036 | + $ns = substr($type, 0, strrpos($type, ':')); |
|
1037 | + $this->debug("in parametersMatchWrapped: got a prefixed type: $uqType, $ns"); |
|
1038 | + if ($this->getNamespaceFromPrefix($ns)) { |
|
1039 | + $ns = $this->getNamespaceFromPrefix($ns); |
|
1040 | + $this->debug("in parametersMatchWrapped: expanded prefixed type: $uqType, $ns"); |
|
1041 | + } |
|
1042 | + } else { |
|
1043 | + // TODO: should the type be compared to types in XSD, and the namespace |
|
1044 | + // set to XSD if the type matches? |
|
1045 | + $this->debug("in parametersMatchWrapped: No namespace for type $type"); |
|
1046 | + $ns = ''; |
|
1047 | + $uqType = $type; |
|
1048 | + } |
|
1049 | 1049 | |
1050 | - // get the type information |
|
1051 | - if (!$typeDef = $this->getTypeDef($uqType, $ns)) { |
|
1052 | - $this->debug("in parametersMatchWrapped: $type ($uqType) is not a supported type."); |
|
1053 | - return false; |
|
1054 | - } |
|
1055 | - $this->debug("in parametersMatchWrapped: found typeDef="); |
|
1056 | - $this->appendDebug($this->varDump($typeDef)); |
|
1057 | - if (substr($uqType, -1) == '^') { |
|
1058 | - $uqType = substr($uqType, 0, -1); |
|
1059 | - } |
|
1060 | - $phpType = $typeDef['phpType']; |
|
1061 | - $arrayType = (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : ''); |
|
1062 | - $this->debug("in parametersMatchWrapped: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: $arrayType"); |
|
1050 | + // get the type information |
|
1051 | + if (!$typeDef = $this->getTypeDef($uqType, $ns)) { |
|
1052 | + $this->debug("in parametersMatchWrapped: $type ($uqType) is not a supported type."); |
|
1053 | + return false; |
|
1054 | + } |
|
1055 | + $this->debug("in parametersMatchWrapped: found typeDef="); |
|
1056 | + $this->appendDebug($this->varDump($typeDef)); |
|
1057 | + if (substr($uqType, -1) == '^') { |
|
1058 | + $uqType = substr($uqType, 0, -1); |
|
1059 | + } |
|
1060 | + $phpType = $typeDef['phpType']; |
|
1061 | + $arrayType = (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : ''); |
|
1062 | + $this->debug("in parametersMatchWrapped: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: $arrayType"); |
|
1063 | 1063 | |
1064 | - // we expect a complexType or element of complexType |
|
1065 | - if ($phpType != 'struct') { |
|
1066 | - $this->debug("in parametersMatchWrapped: not a struct"); |
|
1067 | - return false; |
|
1068 | - } |
|
1064 | + // we expect a complexType or element of complexType |
|
1065 | + if ($phpType != 'struct') { |
|
1066 | + $this->debug("in parametersMatchWrapped: not a struct"); |
|
1067 | + return false; |
|
1068 | + } |
|
1069 | 1069 | |
1070 | - // see whether the parameter names match the elements |
|
1071 | - if (isset($typeDef['elements']) && is_array($typeDef['elements'])) { |
|
1072 | - $elements = 0; |
|
1073 | - $matches = 0; |
|
1074 | - foreach ($typeDef['elements'] as $name => $attrs) { |
|
1075 | - if (isset($parameters[$name])) { |
|
1076 | - $this->debug("in parametersMatchWrapped: have parameter named $name"); |
|
1077 | - $matches++; |
|
1078 | - } else { |
|
1079 | - $this->debug("in parametersMatchWrapped: do not have parameter named $name"); |
|
1080 | - } |
|
1081 | - $elements++; |
|
1082 | - } |
|
1070 | + // see whether the parameter names match the elements |
|
1071 | + if (isset($typeDef['elements']) && is_array($typeDef['elements'])) { |
|
1072 | + $elements = 0; |
|
1073 | + $matches = 0; |
|
1074 | + foreach ($typeDef['elements'] as $name => $attrs) { |
|
1075 | + if (isset($parameters[$name])) { |
|
1076 | + $this->debug("in parametersMatchWrapped: have parameter named $name"); |
|
1077 | + $matches++; |
|
1078 | + } else { |
|
1079 | + $this->debug("in parametersMatchWrapped: do not have parameter named $name"); |
|
1080 | + } |
|
1081 | + $elements++; |
|
1082 | + } |
|
1083 | 1083 | |
1084 | - $this->debug("in parametersMatchWrapped: $matches parameter names match $elements wrapped parameter names"); |
|
1085 | - if ($matches == 0) { |
|
1086 | - return false; |
|
1087 | - } |
|
1088 | - return true; |
|
1089 | - } |
|
1084 | + $this->debug("in parametersMatchWrapped: $matches parameter names match $elements wrapped parameter names"); |
|
1085 | + if ($matches == 0) { |
|
1086 | + return false; |
|
1087 | + } |
|
1088 | + return true; |
|
1089 | + } |
|
1090 | 1090 | |
1091 | - // since there are no elements for the type, if the user passed no |
|
1092 | - // parameters, the parameters match wrapped. |
|
1093 | - $this->debug("in parametersMatchWrapped: no elements type $ns:$uqType"); |
|
1094 | - return count($parameters) == 0; |
|
1095 | - } |
|
1091 | + // since there are no elements for the type, if the user passed no |
|
1092 | + // parameters, the parameters match wrapped. |
|
1093 | + $this->debug("in parametersMatchWrapped: no elements type $ns:$uqType"); |
|
1094 | + return count($parameters) == 0; |
|
1095 | + } |
|
1096 | 1096 | |
1097 | - /** |
|
1098 | - * serialize PHP values according to a WSDL message definition |
|
1099 | - * contrary to the method name, this is not limited to RPC |
|
1100 | - * |
|
1101 | - * TODO |
|
1102 | - * - multi-ref serialization |
|
1103 | - * - validate PHP values against type definitions, return errors if invalid |
|
1104 | - * |
|
1105 | - * @param string $operation operation name |
|
1106 | - * @param string $direction (input|output) |
|
1107 | - * @param mixed $parameters parameter value(s) |
|
1108 | - * @param string $bindingType (soap|soap12) |
|
1109 | - * @return mixed parameters serialized as XML or false on error (e.g. operation not found) |
|
1110 | - * @access public |
|
1111 | - */ |
|
1112 | - function serializeRPCParameters($operation, $direction, $parameters, $bindingType = 'soap') { |
|
1113 | - $this->debug("in serializeRPCParameters: operation=$operation, direction=$direction, XMLSchemaVersion=$this->XMLSchemaVersion, bindingType=$bindingType"); |
|
1114 | - $this->appendDebug('parameters=' . $this->varDump($parameters)); |
|
1097 | + /** |
|
1098 | + * serialize PHP values according to a WSDL message definition |
|
1099 | + * contrary to the method name, this is not limited to RPC |
|
1100 | + * |
|
1101 | + * TODO |
|
1102 | + * - multi-ref serialization |
|
1103 | + * - validate PHP values against type definitions, return errors if invalid |
|
1104 | + * |
|
1105 | + * @param string $operation operation name |
|
1106 | + * @param string $direction (input|output) |
|
1107 | + * @param mixed $parameters parameter value(s) |
|
1108 | + * @param string $bindingType (soap|soap12) |
|
1109 | + * @return mixed parameters serialized as XML or false on error (e.g. operation not found) |
|
1110 | + * @access public |
|
1111 | + */ |
|
1112 | + function serializeRPCParameters($operation, $direction, $parameters, $bindingType = 'soap') { |
|
1113 | + $this->debug("in serializeRPCParameters: operation=$operation, direction=$direction, XMLSchemaVersion=$this->XMLSchemaVersion, bindingType=$bindingType"); |
|
1114 | + $this->appendDebug('parameters=' . $this->varDump($parameters)); |
|
1115 | 1115 | |
1116 | - if ($direction != 'input' && $direction != 'output') { |
|
1117 | - $this->debug('The value of the \$direction argument needs to be either "input" or "output"'); |
|
1118 | - $this->setError('The value of the \$direction argument needs to be either "input" or "output"'); |
|
1119 | - return false; |
|
1120 | - } |
|
1121 | - if (!$opData = $this->getOperationData($operation, $bindingType)) { |
|
1122 | - $this->debug('Unable to retrieve WSDL data for operation: ' . $operation . ' bindingType: ' . $bindingType); |
|
1123 | - $this->setError('Unable to retrieve WSDL data for operation: ' . $operation . ' bindingType: ' . $bindingType); |
|
1124 | - return false; |
|
1125 | - } |
|
1126 | - $this->debug('in serializeRPCParameters: opData:'); |
|
1127 | - $this->appendDebug($this->varDump($opData)); |
|
1116 | + if ($direction != 'input' && $direction != 'output') { |
|
1117 | + $this->debug('The value of the \$direction argument needs to be either "input" or "output"'); |
|
1118 | + $this->setError('The value of the \$direction argument needs to be either "input" or "output"'); |
|
1119 | + return false; |
|
1120 | + } |
|
1121 | + if (!$opData = $this->getOperationData($operation, $bindingType)) { |
|
1122 | + $this->debug('Unable to retrieve WSDL data for operation: ' . $operation . ' bindingType: ' . $bindingType); |
|
1123 | + $this->setError('Unable to retrieve WSDL data for operation: ' . $operation . ' bindingType: ' . $bindingType); |
|
1124 | + return false; |
|
1125 | + } |
|
1126 | + $this->debug('in serializeRPCParameters: opData:'); |
|
1127 | + $this->appendDebug($this->varDump($opData)); |
|
1128 | 1128 | |
1129 | - // Get encoding style for output and set to current |
|
1130 | - $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/'; |
|
1131 | - if(($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) { |
|
1132 | - $encodingStyle = $opData['output']['encodingStyle']; |
|
1133 | - $enc_style = $encodingStyle; |
|
1134 | - } |
|
1129 | + // Get encoding style for output and set to current |
|
1130 | + $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/'; |
|
1131 | + if(($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) { |
|
1132 | + $encodingStyle = $opData['output']['encodingStyle']; |
|
1133 | + $enc_style = $encodingStyle; |
|
1134 | + } |
|
1135 | 1135 | |
1136 | - // set input params |
|
1137 | - $xml = ''; |
|
1138 | - if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) { |
|
1139 | - $parts = &$opData[$direction]['parts']; |
|
1140 | - $part_count = sizeof($parts); |
|
1141 | - $style = $opData['style']; |
|
1142 | - $use = $opData[$direction]['use']; |
|
1143 | - $this->debug("have $part_count part(s) to serialize using $style/$use"); |
|
1144 | - if (is_array($parameters)) { |
|
1145 | - $parametersArrayType = $this->isArraySimpleOrStruct($parameters); |
|
1146 | - $parameter_count = count($parameters); |
|
1147 | - $this->debug("have $parameter_count parameter(s) provided as $parametersArrayType to serialize"); |
|
1148 | - // check for Microsoft-style wrapped parameters |
|
1149 | - if ($style == 'document' && $use == 'literal' && $part_count == 1 && isset($parts['parameters'])) { |
|
1150 | - $this->debug('check whether the caller has wrapped the parameters'); |
|
1151 | - if ($direction == 'output' && $parametersArrayType == 'arraySimple' && $parameter_count == 1) { |
|
1152 | - // TODO: consider checking here for double-wrapping, when |
|
1153 | - // service function wraps, then NuSOAP wraps again |
|
1154 | - $this->debug("change simple array to associative with 'parameters' element"); |
|
1155 | - $parameters['parameters'] = $parameters[0]; |
|
1156 | - unset($parameters[0]); |
|
1157 | - } |
|
1158 | - if (($parametersArrayType == 'arrayStruct' || $parameter_count == 0) && !isset($parameters['parameters'])) { |
|
1159 | - $this->debug('check whether caller\'s parameters match the wrapped ones'); |
|
1160 | - if ($this->parametersMatchWrapped($parts['parameters'], $parameters)) { |
|
1161 | - $this->debug('wrap the parameters for the caller'); |
|
1162 | - $parameters = array('parameters' => $parameters); |
|
1163 | - $parameter_count = 1; |
|
1164 | - } |
|
1165 | - } |
|
1166 | - } |
|
1167 | - foreach ($parts as $name => $type) { |
|
1168 | - $this->debug("serializing part $name of type $type"); |
|
1169 | - // Track encoding style |
|
1170 | - if (isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) { |
|
1171 | - $encodingStyle = $opData[$direction]['encodingStyle']; |
|
1172 | - $enc_style = $encodingStyle; |
|
1173 | - } else { |
|
1174 | - $enc_style = false; |
|
1175 | - } |
|
1176 | - // NOTE: add error handling here |
|
1177 | - // if serializeType returns false, then catch global error and fault |
|
1178 | - if ($parametersArrayType == 'arraySimple') { |
|
1179 | - $p = array_shift($parameters); |
|
1180 | - $this->debug('calling serializeType w/indexed param'); |
|
1181 | - $xml .= $this->serializeType($name, $type, $p, $use, $enc_style); |
|
1182 | - } elseif (isset($parameters[$name])) { |
|
1183 | - $this->debug('calling serializeType w/named param'); |
|
1184 | - $xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style); |
|
1185 | - } else { |
|
1186 | - // TODO: only send nillable |
|
1187 | - $this->debug('calling serializeType w/null param'); |
|
1188 | - $xml .= $this->serializeType($name, $type, null, $use, $enc_style); |
|
1189 | - } |
|
1190 | - } |
|
1191 | - } else { |
|
1192 | - $this->debug('no parameters passed.'); |
|
1193 | - } |
|
1194 | - } |
|
1195 | - $this->debug("serializeRPCParameters returning: $xml"); |
|
1196 | - return $xml; |
|
1197 | - } |
|
1136 | + // set input params |
|
1137 | + $xml = ''; |
|
1138 | + if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) { |
|
1139 | + $parts = &$opData[$direction]['parts']; |
|
1140 | + $part_count = sizeof($parts); |
|
1141 | + $style = $opData['style']; |
|
1142 | + $use = $opData[$direction]['use']; |
|
1143 | + $this->debug("have $part_count part(s) to serialize using $style/$use"); |
|
1144 | + if (is_array($parameters)) { |
|
1145 | + $parametersArrayType = $this->isArraySimpleOrStruct($parameters); |
|
1146 | + $parameter_count = count($parameters); |
|
1147 | + $this->debug("have $parameter_count parameter(s) provided as $parametersArrayType to serialize"); |
|
1148 | + // check for Microsoft-style wrapped parameters |
|
1149 | + if ($style == 'document' && $use == 'literal' && $part_count == 1 && isset($parts['parameters'])) { |
|
1150 | + $this->debug('check whether the caller has wrapped the parameters'); |
|
1151 | + if ($direction == 'output' && $parametersArrayType == 'arraySimple' && $parameter_count == 1) { |
|
1152 | + // TODO: consider checking here for double-wrapping, when |
|
1153 | + // service function wraps, then NuSOAP wraps again |
|
1154 | + $this->debug("change simple array to associative with 'parameters' element"); |
|
1155 | + $parameters['parameters'] = $parameters[0]; |
|
1156 | + unset($parameters[0]); |
|
1157 | + } |
|
1158 | + if (($parametersArrayType == 'arrayStruct' || $parameter_count == 0) && !isset($parameters['parameters'])) { |
|
1159 | + $this->debug('check whether caller\'s parameters match the wrapped ones'); |
|
1160 | + if ($this->parametersMatchWrapped($parts['parameters'], $parameters)) { |
|
1161 | + $this->debug('wrap the parameters for the caller'); |
|
1162 | + $parameters = array('parameters' => $parameters); |
|
1163 | + $parameter_count = 1; |
|
1164 | + } |
|
1165 | + } |
|
1166 | + } |
|
1167 | + foreach ($parts as $name => $type) { |
|
1168 | + $this->debug("serializing part $name of type $type"); |
|
1169 | + // Track encoding style |
|
1170 | + if (isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) { |
|
1171 | + $encodingStyle = $opData[$direction]['encodingStyle']; |
|
1172 | + $enc_style = $encodingStyle; |
|
1173 | + } else { |
|
1174 | + $enc_style = false; |
|
1175 | + } |
|
1176 | + // NOTE: add error handling here |
|
1177 | + // if serializeType returns false, then catch global error and fault |
|
1178 | + if ($parametersArrayType == 'arraySimple') { |
|
1179 | + $p = array_shift($parameters); |
|
1180 | + $this->debug('calling serializeType w/indexed param'); |
|
1181 | + $xml .= $this->serializeType($name, $type, $p, $use, $enc_style); |
|
1182 | + } elseif (isset($parameters[$name])) { |
|
1183 | + $this->debug('calling serializeType w/named param'); |
|
1184 | + $xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style); |
|
1185 | + } else { |
|
1186 | + // TODO: only send nillable |
|
1187 | + $this->debug('calling serializeType w/null param'); |
|
1188 | + $xml .= $this->serializeType($name, $type, null, $use, $enc_style); |
|
1189 | + } |
|
1190 | + } |
|
1191 | + } else { |
|
1192 | + $this->debug('no parameters passed.'); |
|
1193 | + } |
|
1194 | + } |
|
1195 | + $this->debug("serializeRPCParameters returning: $xml"); |
|
1196 | + return $xml; |
|
1197 | + } |
|
1198 | 1198 | |
1199 | - /** |
|
1200 | - * serialize a PHP value according to a WSDL message definition |
|
1201 | - * |
|
1202 | - * TODO |
|
1203 | - * - multi-ref serialization |
|
1204 | - * - validate PHP values against type definitions, return errors if invalid |
|
1205 | - * |
|
1206 | - * @param string $operation operation name |
|
1207 | - * @param string $direction (input|output) |
|
1208 | - * @param mixed $parameters parameter value(s) |
|
1209 | - * @return mixed parameters serialized as XML or false on error (e.g. operation not found) |
|
1210 | - * @access public |
|
1211 | - * @deprecated |
|
1212 | - */ |
|
1213 | - function serializeParameters($operation, $direction, $parameters) |
|
1214 | - { |
|
1215 | - $this->debug("in serializeParameters: operation=$operation, direction=$direction, XMLSchemaVersion=$this->XMLSchemaVersion"); |
|
1216 | - $this->appendDebug('parameters=' . $this->varDump($parameters)); |
|
1199 | + /** |
|
1200 | + * serialize a PHP value according to a WSDL message definition |
|
1201 | + * |
|
1202 | + * TODO |
|
1203 | + * - multi-ref serialization |
|
1204 | + * - validate PHP values against type definitions, return errors if invalid |
|
1205 | + * |
|
1206 | + * @param string $operation operation name |
|
1207 | + * @param string $direction (input|output) |
|
1208 | + * @param mixed $parameters parameter value(s) |
|
1209 | + * @return mixed parameters serialized as XML or false on error (e.g. operation not found) |
|
1210 | + * @access public |
|
1211 | + * @deprecated |
|
1212 | + */ |
|
1213 | + function serializeParameters($operation, $direction, $parameters) |
|
1214 | + { |
|
1215 | + $this->debug("in serializeParameters: operation=$operation, direction=$direction, XMLSchemaVersion=$this->XMLSchemaVersion"); |
|
1216 | + $this->appendDebug('parameters=' . $this->varDump($parameters)); |
|
1217 | 1217 | |
1218 | - if ($direction != 'input' && $direction != 'output') { |
|
1219 | - $this->debug('The value of the \$direction argument needs to be either "input" or "output"'); |
|
1220 | - $this->setError('The value of the \$direction argument needs to be either "input" or "output"'); |
|
1221 | - return false; |
|
1222 | - } |
|
1223 | - if (!$opData = $this->getOperationData($operation)) { |
|
1224 | - $this->debug('Unable to retrieve WSDL data for operation: ' . $operation); |
|
1225 | - $this->setError('Unable to retrieve WSDL data for operation: ' . $operation); |
|
1226 | - return false; |
|
1227 | - } |
|
1228 | - $this->debug('opData:'); |
|
1229 | - $this->appendDebug($this->varDump($opData)); |
|
1218 | + if ($direction != 'input' && $direction != 'output') { |
|
1219 | + $this->debug('The value of the \$direction argument needs to be either "input" or "output"'); |
|
1220 | + $this->setError('The value of the \$direction argument needs to be either "input" or "output"'); |
|
1221 | + return false; |
|
1222 | + } |
|
1223 | + if (!$opData = $this->getOperationData($operation)) { |
|
1224 | + $this->debug('Unable to retrieve WSDL data for operation: ' . $operation); |
|
1225 | + $this->setError('Unable to retrieve WSDL data for operation: ' . $operation); |
|
1226 | + return false; |
|
1227 | + } |
|
1228 | + $this->debug('opData:'); |
|
1229 | + $this->appendDebug($this->varDump($opData)); |
|
1230 | 1230 | |
1231 | - // Get encoding style for output and set to current |
|
1232 | - $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/'; |
|
1233 | - if(($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) { |
|
1234 | - $encodingStyle = $opData['output']['encodingStyle']; |
|
1235 | - $enc_style = $encodingStyle; |
|
1236 | - } |
|
1231 | + // Get encoding style for output and set to current |
|
1232 | + $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/'; |
|
1233 | + if(($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) { |
|
1234 | + $encodingStyle = $opData['output']['encodingStyle']; |
|
1235 | + $enc_style = $encodingStyle; |
|
1236 | + } |
|
1237 | 1237 | |
1238 | - // set input params |
|
1239 | - $xml = ''; |
|
1240 | - if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) { |
|
1238 | + // set input params |
|
1239 | + $xml = ''; |
|
1240 | + if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) { |
|
1241 | 1241 | |
1242 | - $use = $opData[$direction]['use']; |
|
1243 | - $this->debug("use=$use"); |
|
1244 | - $this->debug('got ' . count($opData[$direction]['parts']) . ' part(s)'); |
|
1245 | - if (is_array($parameters)) { |
|
1246 | - $parametersArrayType = $this->isArraySimpleOrStruct($parameters); |
|
1247 | - $this->debug('have ' . $parametersArrayType . ' parameters'); |
|
1248 | - foreach($opData[$direction]['parts'] as $name => $type) { |
|
1249 | - $this->debug('serializing part "'.$name.'" of type "'.$type.'"'); |
|
1250 | - // Track encoding style |
|
1251 | - if(isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) { |
|
1252 | - $encodingStyle = $opData[$direction]['encodingStyle']; |
|
1253 | - $enc_style = $encodingStyle; |
|
1254 | - } else { |
|
1255 | - $enc_style = false; |
|
1256 | - } |
|
1257 | - // NOTE: add error handling here |
|
1258 | - // if serializeType returns false, then catch global error and fault |
|
1259 | - if ($parametersArrayType == 'arraySimple') { |
|
1260 | - $p = array_shift($parameters); |
|
1261 | - $this->debug('calling serializeType w/indexed param'); |
|
1262 | - $xml .= $this->serializeType($name, $type, $p, $use, $enc_style); |
|
1263 | - } elseif (isset($parameters[$name])) { |
|
1264 | - $this->debug('calling serializeType w/named param'); |
|
1265 | - $xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style); |
|
1266 | - } else { |
|
1267 | - // TODO: only send nillable |
|
1268 | - $this->debug('calling serializeType w/null param'); |
|
1269 | - $xml .= $this->serializeType($name, $type, null, $use, $enc_style); |
|
1270 | - } |
|
1271 | - } |
|
1272 | - } else { |
|
1273 | - $this->debug('no parameters passed.'); |
|
1274 | - } |
|
1275 | - } |
|
1276 | - $this->debug("serializeParameters returning: $xml"); |
|
1277 | - return $xml; |
|
1278 | - } |
|
1242 | + $use = $opData[$direction]['use']; |
|
1243 | + $this->debug("use=$use"); |
|
1244 | + $this->debug('got ' . count($opData[$direction]['parts']) . ' part(s)'); |
|
1245 | + if (is_array($parameters)) { |
|
1246 | + $parametersArrayType = $this->isArraySimpleOrStruct($parameters); |
|
1247 | + $this->debug('have ' . $parametersArrayType . ' parameters'); |
|
1248 | + foreach($opData[$direction]['parts'] as $name => $type) { |
|
1249 | + $this->debug('serializing part "'.$name.'" of type "'.$type.'"'); |
|
1250 | + // Track encoding style |
|
1251 | + if(isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) { |
|
1252 | + $encodingStyle = $opData[$direction]['encodingStyle']; |
|
1253 | + $enc_style = $encodingStyle; |
|
1254 | + } else { |
|
1255 | + $enc_style = false; |
|
1256 | + } |
|
1257 | + // NOTE: add error handling here |
|
1258 | + // if serializeType returns false, then catch global error and fault |
|
1259 | + if ($parametersArrayType == 'arraySimple') { |
|
1260 | + $p = array_shift($parameters); |
|
1261 | + $this->debug('calling serializeType w/indexed param'); |
|
1262 | + $xml .= $this->serializeType($name, $type, $p, $use, $enc_style); |
|
1263 | + } elseif (isset($parameters[$name])) { |
|
1264 | + $this->debug('calling serializeType w/named param'); |
|
1265 | + $xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style); |
|
1266 | + } else { |
|
1267 | + // TODO: only send nillable |
|
1268 | + $this->debug('calling serializeType w/null param'); |
|
1269 | + $xml .= $this->serializeType($name, $type, null, $use, $enc_style); |
|
1270 | + } |
|
1271 | + } |
|
1272 | + } else { |
|
1273 | + $this->debug('no parameters passed.'); |
|
1274 | + } |
|
1275 | + } |
|
1276 | + $this->debug("serializeParameters returning: $xml"); |
|
1277 | + return $xml; |
|
1278 | + } |
|
1279 | 1279 | |
1280 | - /** |
|
1281 | - * serializes a PHP value according a given type definition |
|
1282 | - * |
|
1283 | - * @param string $name name of value (part or element) |
|
1284 | - * @param string $type XML schema type of value (type or element) |
|
1285 | - * @param mixed $value a native PHP value (parameter value) |
|
1286 | - * @param string $use use for part (encoded|literal) |
|
1287 | - * @param string $encodingStyle SOAP encoding style for the value (if different than the enclosing style) |
|
1288 | - * @param boolean $unqualified a kludge for what should be XML namespace form handling |
|
1289 | - * @return string value serialized as an XML string |
|
1290 | - * @access private |
|
1291 | - */ |
|
1292 | - function serializeType($name, $type, $value, $use='encoded', $encodingStyle=false, $unqualified=false) |
|
1293 | - { |
|
1294 | - $this->debug("in serializeType: name=$name, type=$type, use=$use, encodingStyle=$encodingStyle, unqualified=" . ($unqualified ? "unqualified" : "qualified")); |
|
1295 | - $this->appendDebug("value=" . $this->varDump($value)); |
|
1296 | - if($use == 'encoded' && $encodingStyle) { |
|
1297 | - $encodingStyle = ' SOAP-ENV:encodingStyle="' . $encodingStyle . '"'; |
|
1298 | - } |
|
1280 | + /** |
|
1281 | + * serializes a PHP value according a given type definition |
|
1282 | + * |
|
1283 | + * @param string $name name of value (part or element) |
|
1284 | + * @param string $type XML schema type of value (type or element) |
|
1285 | + * @param mixed $value a native PHP value (parameter value) |
|
1286 | + * @param string $use use for part (encoded|literal) |
|
1287 | + * @param string $encodingStyle SOAP encoding style for the value (if different than the enclosing style) |
|
1288 | + * @param boolean $unqualified a kludge for what should be XML namespace form handling |
|
1289 | + * @return string value serialized as an XML string |
|
1290 | + * @access private |
|
1291 | + */ |
|
1292 | + function serializeType($name, $type, $value, $use='encoded', $encodingStyle=false, $unqualified=false) |
|
1293 | + { |
|
1294 | + $this->debug("in serializeType: name=$name, type=$type, use=$use, encodingStyle=$encodingStyle, unqualified=" . ($unqualified ? "unqualified" : "qualified")); |
|
1295 | + $this->appendDebug("value=" . $this->varDump($value)); |
|
1296 | + if($use == 'encoded' && $encodingStyle) { |
|
1297 | + $encodingStyle = ' SOAP-ENV:encodingStyle="' . $encodingStyle . '"'; |
|
1298 | + } |
|
1299 | 1299 | |
1300 | - // if a soapval has been supplied, let its type override the WSDL |
|
1301 | - if (is_object($value) && get_class($value) == 'soapval') { |
|
1302 | - if ($value->type_ns) { |
|
1303 | - $type = $value->type_ns . ':' . $value->type; |
|
1304 | - $forceType = true; |
|
1305 | - $this->debug("in serializeType: soapval overrides type to $type"); |
|
1306 | - } elseif ($value->type) { |
|
1307 | - $type = $value->type; |
|
1308 | - $forceType = true; |
|
1309 | - $this->debug("in serializeType: soapval overrides type to $type"); |
|
1310 | - } else { |
|
1311 | - $forceType = false; |
|
1312 | - $this->debug("in serializeType: soapval does not override type"); |
|
1313 | - } |
|
1314 | - $attrs = $value->attributes; |
|
1315 | - $value = $value->value; |
|
1316 | - $this->debug("in serializeType: soapval overrides value to $value"); |
|
1317 | - if ($attrs) { |
|
1318 | - if (!is_array($value)) { |
|
1319 | - $value['!'] = $value; |
|
1320 | - } |
|
1321 | - foreach ($attrs as $n => $v) { |
|
1322 | - $value['!' . $n] = $v; |
|
1323 | - } |
|
1324 | - $this->debug("in serializeType: soapval provides attributes"); |
|
1325 | - } |
|
1300 | + // if a soapval has been supplied, let its type override the WSDL |
|
1301 | + if (is_object($value) && get_class($value) == 'soapval') { |
|
1302 | + if ($value->type_ns) { |
|
1303 | + $type = $value->type_ns . ':' . $value->type; |
|
1304 | + $forceType = true; |
|
1305 | + $this->debug("in serializeType: soapval overrides type to $type"); |
|
1306 | + } elseif ($value->type) { |
|
1307 | + $type = $value->type; |
|
1308 | + $forceType = true; |
|
1309 | + $this->debug("in serializeType: soapval overrides type to $type"); |
|
1310 | + } else { |
|
1311 | + $forceType = false; |
|
1312 | + $this->debug("in serializeType: soapval does not override type"); |
|
1313 | + } |
|
1314 | + $attrs = $value->attributes; |
|
1315 | + $value = $value->value; |
|
1316 | + $this->debug("in serializeType: soapval overrides value to $value"); |
|
1317 | + if ($attrs) { |
|
1318 | + if (!is_array($value)) { |
|
1319 | + $value['!'] = $value; |
|
1320 | + } |
|
1321 | + foreach ($attrs as $n => $v) { |
|
1322 | + $value['!' . $n] = $v; |
|
1323 | + } |
|
1324 | + $this->debug("in serializeType: soapval provides attributes"); |
|
1325 | + } |
|
1326 | 1326 | } else { |
1327 | - $forceType = false; |
|
1327 | + $forceType = false; |
|
1328 | 1328 | } |
1329 | 1329 | |
1330 | - $xml = ''; |
|
1331 | - if (strpos($type, ':')) { |
|
1332 | - $uqType = substr($type, strrpos($type, ':') + 1); |
|
1333 | - $ns = substr($type, 0, strrpos($type, ':')); |
|
1334 | - $this->debug("in serializeType: got a prefixed type: $uqType, $ns"); |
|
1335 | - if ($this->getNamespaceFromPrefix($ns)) { |
|
1336 | - $ns = $this->getNamespaceFromPrefix($ns); |
|
1337 | - $this->debug("in serializeType: expanded prefixed type: $uqType, $ns"); |
|
1338 | - } |
|
1330 | + $xml = ''; |
|
1331 | + if (strpos($type, ':')) { |
|
1332 | + $uqType = substr($type, strrpos($type, ':') + 1); |
|
1333 | + $ns = substr($type, 0, strrpos($type, ':')); |
|
1334 | + $this->debug("in serializeType: got a prefixed type: $uqType, $ns"); |
|
1335 | + if ($this->getNamespaceFromPrefix($ns)) { |
|
1336 | + $ns = $this->getNamespaceFromPrefix($ns); |
|
1337 | + $this->debug("in serializeType: expanded prefixed type: $uqType, $ns"); |
|
1338 | + } |
|
1339 | 1339 | |
1340 | - if($ns == $this->XMLSchemaVersion || $ns == 'http://schemas.xmlsoap.org/soap/encoding/'){ |
|
1341 | - $this->debug('in serializeType: type namespace indicates XML Schema or SOAP Encoding type'); |
|
1342 | - if ($unqualified && $use == 'literal') { |
|
1343 | - $elementNS = " xmlns=\"\""; |
|
1344 | - } else { |
|
1345 | - $elementNS = ''; |
|
1346 | - } |
|
1347 | - if (is_null($value)) { |
|
1348 | - if ($use == 'literal') { |
|
1349 | - // TODO: depends on minOccurs |
|
1350 | - $xml = "<$name$elementNS/>"; |
|
1351 | - } else { |
|
1352 | - // TODO: depends on nillable, which should be checked before calling this method |
|
1353 | - $xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>"; |
|
1354 | - } |
|
1355 | - $this->debug("in serializeType: returning: $xml"); |
|
1356 | - return $xml; |
|
1357 | - } |
|
1358 | - if ($uqType == 'Array') { |
|
1359 | - // JBoss/Axis does this sometimes |
|
1360 | - return $this->serialize_val($value, $name, false, false, false, false, $use); |
|
1361 | - } |
|
1362 | - if ($uqType == 'boolean') { |
|
1363 | - if ((is_string($value) && $value == 'false') || (! $value)) { |
|
1364 | - $value = 'false'; |
|
1365 | - } else { |
|
1366 | - $value = 'true'; |
|
1367 | - } |
|
1368 | - } |
|
1369 | - if ($uqType == 'string' && gettype($value) == 'string') { |
|
1370 | - $value = $this->expandEntities($value); |
|
1371 | - } |
|
1372 | - if (($uqType == 'long' || $uqType == 'unsignedLong') && gettype($value) == 'double') { |
|
1373 | - $value = sprintf("%.0lf", $value); |
|
1374 | - } |
|
1375 | - // it's a scalar |
|
1376 | - // TODO: what about null/nil values? |
|
1377 | - // check type isn't a custom type extending xmlschema namespace |
|
1378 | - if (!$this->getTypeDef($uqType, $ns)) { |
|
1379 | - if ($use == 'literal') { |
|
1380 | - if ($forceType) { |
|
1381 | - $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>"; |
|
1382 | - } else { |
|
1383 | - $xml = "<$name$elementNS>$value</$name>"; |
|
1384 | - } |
|
1385 | - } else { |
|
1386 | - $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>"; |
|
1387 | - } |
|
1388 | - $this->debug("in serializeType: returning: $xml"); |
|
1389 | - return $xml; |
|
1390 | - } |
|
1391 | - $this->debug('custom type extends XML Schema or SOAP Encoding namespace (yuck)'); |
|
1392 | - } else if ($ns == 'http://xml.apache.org/xml-soap') { |
|
1393 | - $this->debug('in serializeType: appears to be Apache SOAP type'); |
|
1394 | - if ($uqType == 'Map') { |
|
1395 | - $tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap'); |
|
1396 | - if (! $tt_prefix) { |
|
1397 | - $this->debug('in serializeType: Add namespace for Apache SOAP type'); |
|
1398 | - $tt_prefix = 'ns' . rand(1000, 9999); |
|
1399 | - $this->namespaces[$tt_prefix] = 'http://xml.apache.org/xml-soap'; |
|
1400 | - // force this to be added to usedNamespaces |
|
1401 | - $tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap'); |
|
1402 | - } |
|
1403 | - $contents = ''; |
|
1404 | - foreach($value as $k => $v) { |
|
1405 | - $this->debug("serializing map element: key $k, value $v"); |
|
1406 | - $contents .= '<item>'; |
|
1407 | - $contents .= $this->serialize_val($k,'key',false,false,false,false,$use); |
|
1408 | - $contents .= $this->serialize_val($v,'value',false,false,false,false,$use); |
|
1409 | - $contents .= '</item>'; |
|
1410 | - } |
|
1411 | - if ($use == 'literal') { |
|
1412 | - if ($forceType) { |
|
1413 | - $xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\">$contents</$name>"; |
|
1414 | - } else { |
|
1415 | - $xml = "<$name>$contents</$name>"; |
|
1416 | - } |
|
1417 | - } else { |
|
1418 | - $xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\"$encodingStyle>$contents</$name>"; |
|
1419 | - } |
|
1420 | - $this->debug("in serializeType: returning: $xml"); |
|
1421 | - return $xml; |
|
1422 | - } |
|
1423 | - $this->debug('in serializeType: Apache SOAP type, but only support Map'); |
|
1424 | - } |
|
1425 | - } else { |
|
1426 | - // TODO: should the type be compared to types in XSD, and the namespace |
|
1427 | - // set to XSD if the type matches? |
|
1428 | - $this->debug("in serializeType: No namespace for type $type"); |
|
1429 | - $ns = ''; |
|
1430 | - $uqType = $type; |
|
1431 | - } |
|
1432 | - if(!$typeDef = $this->getTypeDef($uqType, $ns)){ |
|
1433 | - $this->setError("$type ($uqType) is not a supported type."); |
|
1434 | - $this->debug("in serializeType: $type ($uqType) is not a supported type."); |
|
1435 | - return false; |
|
1436 | - } else { |
|
1437 | - $this->debug("in serializeType: found typeDef"); |
|
1438 | - $this->appendDebug('typeDef=' . $this->varDump($typeDef)); |
|
1439 | - if (substr($uqType, -1) == '^') { |
|
1440 | - $uqType = substr($uqType, 0, -1); |
|
1441 | - } |
|
1442 | - } |
|
1443 | - if (!isset($typeDef['phpType'])) { |
|
1444 | - $this->setError("$type ($uqType) has no phpType."); |
|
1445 | - $this->debug("in serializeType: $type ($uqType) has no phpType."); |
|
1446 | - return false; |
|
1447 | - } |
|
1448 | - $phpType = $typeDef['phpType']; |
|
1449 | - $this->debug("in serializeType: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: " . (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '') ); |
|
1450 | - // if php type == struct, map value to the <all> element names |
|
1451 | - if ($phpType == 'struct') { |
|
1452 | - if (isset($typeDef['typeClass']) && $typeDef['typeClass'] == 'element') { |
|
1453 | - $elementName = $uqType; |
|
1454 | - if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) { |
|
1455 | - $elementNS = " xmlns=\"$ns\""; |
|
1456 | - } else { |
|
1457 | - $elementNS = " xmlns=\"\""; |
|
1458 | - } |
|
1459 | - } else { |
|
1460 | - $elementName = $name; |
|
1461 | - if ($unqualified) { |
|
1462 | - $elementNS = " xmlns=\"\""; |
|
1463 | - } else { |
|
1464 | - $elementNS = ''; |
|
1465 | - } |
|
1466 | - } |
|
1467 | - if (is_null($value)) { |
|
1468 | - if ($use == 'literal') { |
|
1469 | - // TODO: depends on minOccurs and nillable |
|
1470 | - $xml = "<$elementName$elementNS/>"; |
|
1471 | - } else { |
|
1472 | - $xml = "<$elementName$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>"; |
|
1473 | - } |
|
1474 | - $this->debug("in serializeType: returning: $xml"); |
|
1475 | - return $xml; |
|
1476 | - } |
|
1477 | - if (is_object($value)) { |
|
1478 | - $value = get_object_vars($value); |
|
1479 | - } |
|
1480 | - if (is_array($value)) { |
|
1481 | - $elementAttrs = $this->serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType); |
|
1482 | - if ($use == 'literal') { |
|
1483 | - if ($forceType) { |
|
1484 | - $xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">"; |
|
1485 | - } else { |
|
1486 | - $xml = "<$elementName$elementNS$elementAttrs>"; |
|
1487 | - } |
|
1488 | - } else { |
|
1489 | - $xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>"; |
|
1490 | - } |
|
1340 | + if($ns == $this->XMLSchemaVersion || $ns == 'http://schemas.xmlsoap.org/soap/encoding/'){ |
|
1341 | + $this->debug('in serializeType: type namespace indicates XML Schema or SOAP Encoding type'); |
|
1342 | + if ($unqualified && $use == 'literal') { |
|
1343 | + $elementNS = " xmlns=\"\""; |
|
1344 | + } else { |
|
1345 | + $elementNS = ''; |
|
1346 | + } |
|
1347 | + if (is_null($value)) { |
|
1348 | + if ($use == 'literal') { |
|
1349 | + // TODO: depends on minOccurs |
|
1350 | + $xml = "<$name$elementNS/>"; |
|
1351 | + } else { |
|
1352 | + // TODO: depends on nillable, which should be checked before calling this method |
|
1353 | + $xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>"; |
|
1354 | + } |
|
1355 | + $this->debug("in serializeType: returning: $xml"); |
|
1356 | + return $xml; |
|
1357 | + } |
|
1358 | + if ($uqType == 'Array') { |
|
1359 | + // JBoss/Axis does this sometimes |
|
1360 | + return $this->serialize_val($value, $name, false, false, false, false, $use); |
|
1361 | + } |
|
1362 | + if ($uqType == 'boolean') { |
|
1363 | + if ((is_string($value) && $value == 'false') || (! $value)) { |
|
1364 | + $value = 'false'; |
|
1365 | + } else { |
|
1366 | + $value = 'true'; |
|
1367 | + } |
|
1368 | + } |
|
1369 | + if ($uqType == 'string' && gettype($value) == 'string') { |
|
1370 | + $value = $this->expandEntities($value); |
|
1371 | + } |
|
1372 | + if (($uqType == 'long' || $uqType == 'unsignedLong') && gettype($value) == 'double') { |
|
1373 | + $value = sprintf("%.0lf", $value); |
|
1374 | + } |
|
1375 | + // it's a scalar |
|
1376 | + // TODO: what about null/nil values? |
|
1377 | + // check type isn't a custom type extending xmlschema namespace |
|
1378 | + if (!$this->getTypeDef($uqType, $ns)) { |
|
1379 | + if ($use == 'literal') { |
|
1380 | + if ($forceType) { |
|
1381 | + $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>"; |
|
1382 | + } else { |
|
1383 | + $xml = "<$name$elementNS>$value</$name>"; |
|
1384 | + } |
|
1385 | + } else { |
|
1386 | + $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>"; |
|
1387 | + } |
|
1388 | + $this->debug("in serializeType: returning: $xml"); |
|
1389 | + return $xml; |
|
1390 | + } |
|
1391 | + $this->debug('custom type extends XML Schema or SOAP Encoding namespace (yuck)'); |
|
1392 | + } else if ($ns == 'http://xml.apache.org/xml-soap') { |
|
1393 | + $this->debug('in serializeType: appears to be Apache SOAP type'); |
|
1394 | + if ($uqType == 'Map') { |
|
1395 | + $tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap'); |
|
1396 | + if (! $tt_prefix) { |
|
1397 | + $this->debug('in serializeType: Add namespace for Apache SOAP type'); |
|
1398 | + $tt_prefix = 'ns' . rand(1000, 9999); |
|
1399 | + $this->namespaces[$tt_prefix] = 'http://xml.apache.org/xml-soap'; |
|
1400 | + // force this to be added to usedNamespaces |
|
1401 | + $tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap'); |
|
1402 | + } |
|
1403 | + $contents = ''; |
|
1404 | + foreach($value as $k => $v) { |
|
1405 | + $this->debug("serializing map element: key $k, value $v"); |
|
1406 | + $contents .= '<item>'; |
|
1407 | + $contents .= $this->serialize_val($k,'key',false,false,false,false,$use); |
|
1408 | + $contents .= $this->serialize_val($v,'value',false,false,false,false,$use); |
|
1409 | + $contents .= '</item>'; |
|
1410 | + } |
|
1411 | + if ($use == 'literal') { |
|
1412 | + if ($forceType) { |
|
1413 | + $xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\">$contents</$name>"; |
|
1414 | + } else { |
|
1415 | + $xml = "<$name>$contents</$name>"; |
|
1416 | + } |
|
1417 | + } else { |
|
1418 | + $xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\"$encodingStyle>$contents</$name>"; |
|
1419 | + } |
|
1420 | + $this->debug("in serializeType: returning: $xml"); |
|
1421 | + return $xml; |
|
1422 | + } |
|
1423 | + $this->debug('in serializeType: Apache SOAP type, but only support Map'); |
|
1424 | + } |
|
1425 | + } else { |
|
1426 | + // TODO: should the type be compared to types in XSD, and the namespace |
|
1427 | + // set to XSD if the type matches? |
|
1428 | + $this->debug("in serializeType: No namespace for type $type"); |
|
1429 | + $ns = ''; |
|
1430 | + $uqType = $type; |
|
1431 | + } |
|
1432 | + if(!$typeDef = $this->getTypeDef($uqType, $ns)){ |
|
1433 | + $this->setError("$type ($uqType) is not a supported type."); |
|
1434 | + $this->debug("in serializeType: $type ($uqType) is not a supported type."); |
|
1435 | + return false; |
|
1436 | + } else { |
|
1437 | + $this->debug("in serializeType: found typeDef"); |
|
1438 | + $this->appendDebug('typeDef=' . $this->varDump($typeDef)); |
|
1439 | + if (substr($uqType, -1) == '^') { |
|
1440 | + $uqType = substr($uqType, 0, -1); |
|
1441 | + } |
|
1442 | + } |
|
1443 | + if (!isset($typeDef['phpType'])) { |
|
1444 | + $this->setError("$type ($uqType) has no phpType."); |
|
1445 | + $this->debug("in serializeType: $type ($uqType) has no phpType."); |
|
1446 | + return false; |
|
1447 | + } |
|
1448 | + $phpType = $typeDef['phpType']; |
|
1449 | + $this->debug("in serializeType: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: " . (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '') ); |
|
1450 | + // if php type == struct, map value to the <all> element names |
|
1451 | + if ($phpType == 'struct') { |
|
1452 | + if (isset($typeDef['typeClass']) && $typeDef['typeClass'] == 'element') { |
|
1453 | + $elementName = $uqType; |
|
1454 | + if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) { |
|
1455 | + $elementNS = " xmlns=\"$ns\""; |
|
1456 | + } else { |
|
1457 | + $elementNS = " xmlns=\"\""; |
|
1458 | + } |
|
1459 | + } else { |
|
1460 | + $elementName = $name; |
|
1461 | + if ($unqualified) { |
|
1462 | + $elementNS = " xmlns=\"\""; |
|
1463 | + } else { |
|
1464 | + $elementNS = ''; |
|
1465 | + } |
|
1466 | + } |
|
1467 | + if (is_null($value)) { |
|
1468 | + if ($use == 'literal') { |
|
1469 | + // TODO: depends on minOccurs and nillable |
|
1470 | + $xml = "<$elementName$elementNS/>"; |
|
1471 | + } else { |
|
1472 | + $xml = "<$elementName$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>"; |
|
1473 | + } |
|
1474 | + $this->debug("in serializeType: returning: $xml"); |
|
1475 | + return $xml; |
|
1476 | + } |
|
1477 | + if (is_object($value)) { |
|
1478 | + $value = get_object_vars($value); |
|
1479 | + } |
|
1480 | + if (is_array($value)) { |
|
1481 | + $elementAttrs = $this->serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType); |
|
1482 | + if ($use == 'literal') { |
|
1483 | + if ($forceType) { |
|
1484 | + $xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">"; |
|
1485 | + } else { |
|
1486 | + $xml = "<$elementName$elementNS$elementAttrs>"; |
|
1487 | + } |
|
1488 | + } else { |
|
1489 | + $xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>"; |
|
1490 | + } |
|
1491 | 1491 | |
1492 | - if (isset($typeDef['simpleContent']) && $typeDef['simpleContent'] == 'true') { |
|
1493 | - if (isset($value['!'])) { |
|
1494 | - $xml .= $value['!']; |
|
1495 | - $this->debug("in serializeType: serialized simpleContent for type $type"); |
|
1496 | - } else { |
|
1497 | - $this->debug("in serializeType: no simpleContent to serialize for type $type"); |
|
1498 | - } |
|
1499 | - } else { |
|
1500 | - // complexContent |
|
1501 | - $xml .= $this->serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use, $encodingStyle); |
|
1502 | - } |
|
1503 | - $xml .= "</$elementName>"; |
|
1504 | - } else { |
|
1505 | - $this->debug("in serializeType: phpType is struct, but value is not an array"); |
|
1506 | - $this->setError("phpType is struct, but value is not an array: see debug output for details"); |
|
1507 | - $xml = ''; |
|
1508 | - } |
|
1509 | - } elseif ($phpType == 'array') { |
|
1510 | - if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) { |
|
1511 | - $elementNS = " xmlns=\"$ns\""; |
|
1512 | - } else { |
|
1513 | - if ($unqualified) { |
|
1514 | - $elementNS = " xmlns=\"\""; |
|
1515 | - } else { |
|
1516 | - $elementNS = ''; |
|
1517 | - } |
|
1518 | - } |
|
1519 | - if (is_null($value)) { |
|
1520 | - if ($use == 'literal') { |
|
1521 | - // TODO: depends on minOccurs |
|
1522 | - $xml = "<$name$elementNS/>"; |
|
1523 | - } else { |
|
1524 | - $xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" . |
|
1525 | - $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') . |
|
1526 | - ":Array\" " . |
|
1527 | - $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') . |
|
1528 | - ':arrayType="' . |
|
1529 | - $this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType'])) . |
|
1530 | - ':' . |
|
1531 | - $this->getLocalPart($typeDef['arrayType'])."[0]\"/>"; |
|
1532 | - } |
|
1533 | - $this->debug("in serializeType: returning: $xml"); |
|
1534 | - return $xml; |
|
1535 | - } |
|
1536 | - if (isset($typeDef['multidimensional'])) { |
|
1537 | - $nv = array(); |
|
1538 | - foreach($value as $v) { |
|
1539 | - $cols = ',' . sizeof($v); |
|
1540 | - $nv = array_merge($nv, $v); |
|
1541 | - } |
|
1542 | - $value = $nv; |
|
1543 | - } else { |
|
1544 | - $cols = ''; |
|
1545 | - } |
|
1546 | - if (is_array($value) && sizeof($value) >= 1) { |
|
1547 | - $rows = sizeof($value); |
|
1548 | - $contents = ''; |
|
1549 | - foreach($value as $k => $v) { |
|
1550 | - //$this->debug("serializing array element: $k, $v of type: $typeDef[arrayType]"); |
|
1551 | - //if (strpos($typeDef['arrayType'], ':') ) { |
|
1552 | - if (!in_array($typeDef['arrayType'],$this->typemap['http://www.w3.org/2001/XMLSchema'])) { |
|
1553 | - $contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use); |
|
1554 | - } else { |
|
1555 | - $contents .= $this->serialize_val($v, 'item', $typeDef['arrayType'], null, $this->XMLSchemaVersion, false, $use); |
|
1556 | - } |
|
1557 | - } |
|
1558 | - } else { |
|
1559 | - $rows = 0; |
|
1560 | - $contents = null; |
|
1561 | - } |
|
1562 | - // TODO: for now, an empty value will be serialized as a zero element |
|
1563 | - // array. Revisit this when coding the handling of null/nil values. |
|
1564 | - if ($use == 'literal') { |
|
1565 | - $xml = "<$name$elementNS>" |
|
1566 | - .$contents |
|
1567 | - ."</$name>"; |
|
1568 | - } else { |
|
1569 | - $xml = "<$name$elementNS xsi:type=\"".$this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/').':Array" '. |
|
1570 | - $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') |
|
1571 | - .':arrayType="' |
|
1572 | - .$this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType'])) |
|
1573 | - .":".$this->getLocalPart($typeDef['arrayType'])."[$rows$cols]\">" |
|
1574 | - .$contents |
|
1575 | - ."</$name>"; |
|
1576 | - } |
|
1577 | - } elseif ($phpType == 'scalar') { |
|
1578 | - if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) { |
|
1579 | - $elementNS = " xmlns=\"$ns\""; |
|
1580 | - } else { |
|
1581 | - if ($unqualified) { |
|
1582 | - $elementNS = " xmlns=\"\""; |
|
1583 | - } else { |
|
1584 | - $elementNS = ''; |
|
1585 | - } |
|
1586 | - } |
|
1587 | - if ($use == 'literal') { |
|
1588 | - if ($forceType) { |
|
1589 | - $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>"; |
|
1590 | - } else { |
|
1591 | - $xml = "<$name$elementNS>$value</$name>"; |
|
1592 | - } |
|
1593 | - } else { |
|
1594 | - $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>"; |
|
1595 | - } |
|
1596 | - } |
|
1597 | - $this->debug("in serializeType: returning: $xml"); |
|
1598 | - return $xml; |
|
1599 | - } |
|
1492 | + if (isset($typeDef['simpleContent']) && $typeDef['simpleContent'] == 'true') { |
|
1493 | + if (isset($value['!'])) { |
|
1494 | + $xml .= $value['!']; |
|
1495 | + $this->debug("in serializeType: serialized simpleContent for type $type"); |
|
1496 | + } else { |
|
1497 | + $this->debug("in serializeType: no simpleContent to serialize for type $type"); |
|
1498 | + } |
|
1499 | + } else { |
|
1500 | + // complexContent |
|
1501 | + $xml .= $this->serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use, $encodingStyle); |
|
1502 | + } |
|
1503 | + $xml .= "</$elementName>"; |
|
1504 | + } else { |
|
1505 | + $this->debug("in serializeType: phpType is struct, but value is not an array"); |
|
1506 | + $this->setError("phpType is struct, but value is not an array: see debug output for details"); |
|
1507 | + $xml = ''; |
|
1508 | + } |
|
1509 | + } elseif ($phpType == 'array') { |
|
1510 | + if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) { |
|
1511 | + $elementNS = " xmlns=\"$ns\""; |
|
1512 | + } else { |
|
1513 | + if ($unqualified) { |
|
1514 | + $elementNS = " xmlns=\"\""; |
|
1515 | + } else { |
|
1516 | + $elementNS = ''; |
|
1517 | + } |
|
1518 | + } |
|
1519 | + if (is_null($value)) { |
|
1520 | + if ($use == 'literal') { |
|
1521 | + // TODO: depends on minOccurs |
|
1522 | + $xml = "<$name$elementNS/>"; |
|
1523 | + } else { |
|
1524 | + $xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" . |
|
1525 | + $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') . |
|
1526 | + ":Array\" " . |
|
1527 | + $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') . |
|
1528 | + ':arrayType="' . |
|
1529 | + $this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType'])) . |
|
1530 | + ':' . |
|
1531 | + $this->getLocalPart($typeDef['arrayType'])."[0]\"/>"; |
|
1532 | + } |
|
1533 | + $this->debug("in serializeType: returning: $xml"); |
|
1534 | + return $xml; |
|
1535 | + } |
|
1536 | + if (isset($typeDef['multidimensional'])) { |
|
1537 | + $nv = array(); |
|
1538 | + foreach($value as $v) { |
|
1539 | + $cols = ',' . sizeof($v); |
|
1540 | + $nv = array_merge($nv, $v); |
|
1541 | + } |
|
1542 | + $value = $nv; |
|
1543 | + } else { |
|
1544 | + $cols = ''; |
|
1545 | + } |
|
1546 | + if (is_array($value) && sizeof($value) >= 1) { |
|
1547 | + $rows = sizeof($value); |
|
1548 | + $contents = ''; |
|
1549 | + foreach($value as $k => $v) { |
|
1550 | + //$this->debug("serializing array element: $k, $v of type: $typeDef[arrayType]"); |
|
1551 | + //if (strpos($typeDef['arrayType'], ':') ) { |
|
1552 | + if (!in_array($typeDef['arrayType'],$this->typemap['http://www.w3.org/2001/XMLSchema'])) { |
|
1553 | + $contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use); |
|
1554 | + } else { |
|
1555 | + $contents .= $this->serialize_val($v, 'item', $typeDef['arrayType'], null, $this->XMLSchemaVersion, false, $use); |
|
1556 | + } |
|
1557 | + } |
|
1558 | + } else { |
|
1559 | + $rows = 0; |
|
1560 | + $contents = null; |
|
1561 | + } |
|
1562 | + // TODO: for now, an empty value will be serialized as a zero element |
|
1563 | + // array. Revisit this when coding the handling of null/nil values. |
|
1564 | + if ($use == 'literal') { |
|
1565 | + $xml = "<$name$elementNS>" |
|
1566 | + .$contents |
|
1567 | + ."</$name>"; |
|
1568 | + } else { |
|
1569 | + $xml = "<$name$elementNS xsi:type=\"".$this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/').':Array" '. |
|
1570 | + $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') |
|
1571 | + .':arrayType="' |
|
1572 | + .$this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType'])) |
|
1573 | + .":".$this->getLocalPart($typeDef['arrayType'])."[$rows$cols]\">" |
|
1574 | + .$contents |
|
1575 | + ."</$name>"; |
|
1576 | + } |
|
1577 | + } elseif ($phpType == 'scalar') { |
|
1578 | + if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) { |
|
1579 | + $elementNS = " xmlns=\"$ns\""; |
|
1580 | + } else { |
|
1581 | + if ($unqualified) { |
|
1582 | + $elementNS = " xmlns=\"\""; |
|
1583 | + } else { |
|
1584 | + $elementNS = ''; |
|
1585 | + } |
|
1586 | + } |
|
1587 | + if ($use == 'literal') { |
|
1588 | + if ($forceType) { |
|
1589 | + $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>"; |
|
1590 | + } else { |
|
1591 | + $xml = "<$name$elementNS>$value</$name>"; |
|
1592 | + } |
|
1593 | + } else { |
|
1594 | + $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>"; |
|
1595 | + } |
|
1596 | + } |
|
1597 | + $this->debug("in serializeType: returning: $xml"); |
|
1598 | + return $xml; |
|
1599 | + } |
|
1600 | 1600 | |
1601 | - /** |
|
1602 | - * serializes the attributes for a complexType |
|
1603 | - * |
|
1604 | - * @param array $typeDef our internal representation of an XML schema type (or element) |
|
1605 | - * @param mixed $value a native PHP value (parameter value) |
|
1606 | - * @param string $ns the namespace of the type |
|
1607 | - * @param string $uqType the local part of the type |
|
1608 | - * @return string value serialized as an XML string |
|
1609 | - * @access private |
|
1610 | - */ |
|
1611 | - function serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType) { |
|
1612 | - $this->debug("serializeComplexTypeAttributes for XML Schema type $ns:$uqType"); |
|
1613 | - $xml = ''; |
|
1614 | - if (isset($typeDef['extensionBase'])) { |
|
1615 | - $nsx = $this->getPrefix($typeDef['extensionBase']); |
|
1616 | - $uqTypex = $this->getLocalPart($typeDef['extensionBase']); |
|
1617 | - if ($this->getNamespaceFromPrefix($nsx)) { |
|
1618 | - $nsx = $this->getNamespaceFromPrefix($nsx); |
|
1619 | - } |
|
1620 | - if ($typeDefx = $this->getTypeDef($uqTypex, $nsx)) { |
|
1621 | - $this->debug("serialize attributes for extension base $nsx:$uqTypex"); |
|
1622 | - $xml .= $this->serializeComplexTypeAttributes($typeDefx, $value, $nsx, $uqTypex); |
|
1623 | - } else { |
|
1624 | - $this->debug("extension base $nsx:$uqTypex is not a supported type"); |
|
1625 | - } |
|
1626 | - } |
|
1627 | - if (isset($typeDef['attrs']) && is_array($typeDef['attrs'])) { |
|
1628 | - $this->debug("serialize attributes for XML Schema type $ns:$uqType"); |
|
1629 | - if (is_array($value)) { |
|
1630 | - $xvalue = $value; |
|
1631 | - } elseif (is_object($value)) { |
|
1632 | - $xvalue = get_object_vars($value); |
|
1633 | - } else { |
|
1634 | - $this->debug("value is neither an array nor an object for XML Schema type $ns:$uqType"); |
|
1635 | - $xvalue = array(); |
|
1636 | - } |
|
1637 | - foreach ($typeDef['attrs'] as $aName => $attrs) { |
|
1638 | - if (isset($xvalue['!' . $aName])) { |
|
1639 | - $xname = '!' . $aName; |
|
1640 | - $this->debug("value provided for attribute $aName with key $xname"); |
|
1641 | - } elseif (isset($xvalue[$aName])) { |
|
1642 | - $xname = $aName; |
|
1643 | - $this->debug("value provided for attribute $aName with key $xname"); |
|
1644 | - } elseif (isset($attrs['default'])) { |
|
1645 | - $xname = '!' . $aName; |
|
1646 | - $xvalue[$xname] = $attrs['default']; |
|
1647 | - $this->debug('use default value of ' . $xvalue[$aName] . ' for attribute ' . $aName); |
|
1648 | - } else { |
|
1649 | - $xname = ''; |
|
1650 | - $this->debug("no value provided for attribute $aName"); |
|
1651 | - } |
|
1652 | - if ($xname) { |
|
1653 | - $xml .= " $aName=\"" . $this->expandEntities($xvalue[$xname]) . "\""; |
|
1654 | - } |
|
1655 | - } |
|
1656 | - } else { |
|
1657 | - $this->debug("no attributes to serialize for XML Schema type $ns:$uqType"); |
|
1658 | - } |
|
1659 | - return $xml; |
|
1660 | - } |
|
1601 | + /** |
|
1602 | + * serializes the attributes for a complexType |
|
1603 | + * |
|
1604 | + * @param array $typeDef our internal representation of an XML schema type (or element) |
|
1605 | + * @param mixed $value a native PHP value (parameter value) |
|
1606 | + * @param string $ns the namespace of the type |
|
1607 | + * @param string $uqType the local part of the type |
|
1608 | + * @return string value serialized as an XML string |
|
1609 | + * @access private |
|
1610 | + */ |
|
1611 | + function serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType) { |
|
1612 | + $this->debug("serializeComplexTypeAttributes for XML Schema type $ns:$uqType"); |
|
1613 | + $xml = ''; |
|
1614 | + if (isset($typeDef['extensionBase'])) { |
|
1615 | + $nsx = $this->getPrefix($typeDef['extensionBase']); |
|
1616 | + $uqTypex = $this->getLocalPart($typeDef['extensionBase']); |
|
1617 | + if ($this->getNamespaceFromPrefix($nsx)) { |
|
1618 | + $nsx = $this->getNamespaceFromPrefix($nsx); |
|
1619 | + } |
|
1620 | + if ($typeDefx = $this->getTypeDef($uqTypex, $nsx)) { |
|
1621 | + $this->debug("serialize attributes for extension base $nsx:$uqTypex"); |
|
1622 | + $xml .= $this->serializeComplexTypeAttributes($typeDefx, $value, $nsx, $uqTypex); |
|
1623 | + } else { |
|
1624 | + $this->debug("extension base $nsx:$uqTypex is not a supported type"); |
|
1625 | + } |
|
1626 | + } |
|
1627 | + if (isset($typeDef['attrs']) && is_array($typeDef['attrs'])) { |
|
1628 | + $this->debug("serialize attributes for XML Schema type $ns:$uqType"); |
|
1629 | + if (is_array($value)) { |
|
1630 | + $xvalue = $value; |
|
1631 | + } elseif (is_object($value)) { |
|
1632 | + $xvalue = get_object_vars($value); |
|
1633 | + } else { |
|
1634 | + $this->debug("value is neither an array nor an object for XML Schema type $ns:$uqType"); |
|
1635 | + $xvalue = array(); |
|
1636 | + } |
|
1637 | + foreach ($typeDef['attrs'] as $aName => $attrs) { |
|
1638 | + if (isset($xvalue['!' . $aName])) { |
|
1639 | + $xname = '!' . $aName; |
|
1640 | + $this->debug("value provided for attribute $aName with key $xname"); |
|
1641 | + } elseif (isset($xvalue[$aName])) { |
|
1642 | + $xname = $aName; |
|
1643 | + $this->debug("value provided for attribute $aName with key $xname"); |
|
1644 | + } elseif (isset($attrs['default'])) { |
|
1645 | + $xname = '!' . $aName; |
|
1646 | + $xvalue[$xname] = $attrs['default']; |
|
1647 | + $this->debug('use default value of ' . $xvalue[$aName] . ' for attribute ' . $aName); |
|
1648 | + } else { |
|
1649 | + $xname = ''; |
|
1650 | + $this->debug("no value provided for attribute $aName"); |
|
1651 | + } |
|
1652 | + if ($xname) { |
|
1653 | + $xml .= " $aName=\"" . $this->expandEntities($xvalue[$xname]) . "\""; |
|
1654 | + } |
|
1655 | + } |
|
1656 | + } else { |
|
1657 | + $this->debug("no attributes to serialize for XML Schema type $ns:$uqType"); |
|
1658 | + } |
|
1659 | + return $xml; |
|
1660 | + } |
|
1661 | 1661 | |
1662 | - /** |
|
1663 | - * serializes the elements for a complexType |
|
1664 | - * |
|
1665 | - * @param array $typeDef our internal representation of an XML schema type (or element) |
|
1666 | - * @param mixed $value a native PHP value (parameter value) |
|
1667 | - * @param string $ns the namespace of the type |
|
1668 | - * @param string $uqType the local part of the type |
|
1669 | - * @param string $use use for part (encoded|literal) |
|
1670 | - * @param string $encodingStyle SOAP encoding style for the value (if different than the enclosing style) |
|
1671 | - * @return string value serialized as an XML string |
|
1672 | - * @access private |
|
1673 | - */ |
|
1674 | - function serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use='encoded', $encodingStyle=false) { |
|
1675 | - $this->debug("in serializeComplexTypeElements for XML Schema type $ns:$uqType"); |
|
1676 | - $xml = ''; |
|
1677 | - if (isset($typeDef['extensionBase'])) { |
|
1678 | - $nsx = $this->getPrefix($typeDef['extensionBase']); |
|
1679 | - $uqTypex = $this->getLocalPart($typeDef['extensionBase']); |
|
1680 | - if ($this->getNamespaceFromPrefix($nsx)) { |
|
1681 | - $nsx = $this->getNamespaceFromPrefix($nsx); |
|
1682 | - } |
|
1683 | - if ($typeDefx = $this->getTypeDef($uqTypex, $nsx)) { |
|
1684 | - $this->debug("serialize elements for extension base $nsx:$uqTypex"); |
|
1685 | - $xml .= $this->serializeComplexTypeElements($typeDefx, $value, $nsx, $uqTypex, $use, $encodingStyle); |
|
1686 | - } else { |
|
1687 | - $this->debug("extension base $nsx:$uqTypex is not a supported type"); |
|
1688 | - } |
|
1689 | - } |
|
1690 | - if (isset($typeDef['elements']) && is_array($typeDef['elements'])) { |
|
1691 | - $this->debug("in serializeComplexTypeElements, serialize elements for XML Schema type $ns:$uqType"); |
|
1692 | - if (is_array($value)) { |
|
1693 | - $xvalue = $value; |
|
1694 | - } elseif (is_object($value)) { |
|
1695 | - $xvalue = get_object_vars($value); |
|
1696 | - } else { |
|
1697 | - $this->debug("value is neither an array nor an object for XML Schema type $ns:$uqType"); |
|
1698 | - $xvalue = array(); |
|
1699 | - } |
|
1700 | - // toggle whether all elements are present - ideally should validate against schema |
|
1701 | - if (count($typeDef['elements']) != count($xvalue)){ |
|
1702 | - $optionals = true; |
|
1703 | - } |
|
1704 | - foreach ($typeDef['elements'] as $eName => $attrs) { |
|
1705 | - if (!isset($xvalue[$eName])) { |
|
1706 | - if (isset($attrs['default'])) { |
|
1707 | - $xvalue[$eName] = $attrs['default']; |
|
1708 | - $this->debug('use default value of ' . $xvalue[$eName] . ' for element ' . $eName); |
|
1709 | - } |
|
1710 | - } |
|
1711 | - // if user took advantage of a minOccurs=0, then only serialize named parameters |
|
1712 | - if (isset($optionals) |
|
1713 | - && (!isset($xvalue[$eName])) |
|
1714 | - && ( (!isset($attrs['nillable'])) || $attrs['nillable'] != 'true') |
|
1715 | - ){ |
|
1716 | - if (isset($attrs['minOccurs']) && $attrs['minOccurs'] <> '0') { |
|
1717 | - $this->debug("apparent error: no value provided for element $eName with minOccurs=" . $attrs['minOccurs']); |
|
1718 | - } |
|
1719 | - // do nothing |
|
1720 | - $this->debug("no value provided for complexType element $eName and element is not nillable, so serialize nothing"); |
|
1721 | - } else { |
|
1722 | - // get value |
|
1723 | - if (isset($xvalue[$eName])) { |
|
1724 | - $v = $xvalue[$eName]; |
|
1725 | - } else { |
|
1726 | - $v = null; |
|
1727 | - } |
|
1728 | - if (isset($attrs['form'])) { |
|
1729 | - $unqualified = ($attrs['form'] == 'unqualified'); |
|
1730 | - } else { |
|
1731 | - $unqualified = false; |
|
1732 | - } |
|
1733 | - if (isset($attrs['maxOccurs']) && ($attrs['maxOccurs'] == 'unbounded' || $attrs['maxOccurs'] > 1) && isset($v) && is_array($v) && $this->isArraySimpleOrStruct($v) == 'arraySimple') { |
|
1734 | - $vv = $v; |
|
1735 | - foreach ($vv as $k => $v) { |
|
1736 | - if (isset($attrs['type']) || isset($attrs['ref'])) { |
|
1737 | - // serialize schema-defined type |
|
1738 | - $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified); |
|
1739 | - } else { |
|
1740 | - // serialize generic type (can this ever really happen?) |
|
1741 | - $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use"); |
|
1742 | - $xml .= $this->serialize_val($v, $eName, false, false, false, false, $use); |
|
1743 | - } |
|
1744 | - } |
|
1745 | - } else { |
|
1746 | - if (is_null($v) && isset($attrs['minOccurs']) && $attrs['minOccurs'] == '0') { |
|
1747 | - // do nothing |
|
1748 | - } elseif (is_null($v) && isset($attrs['nillable']) && $attrs['nillable'] == 'true') { |
|
1749 | - // TODO: serialize a nil correctly, but for now serialize schema-defined type |
|
1750 | - $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified); |
|
1751 | - } elseif (isset($attrs['type']) || isset($attrs['ref'])) { |
|
1752 | - // serialize schema-defined type |
|
1753 | - $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified); |
|
1754 | - } else { |
|
1755 | - // serialize generic type (can this ever really happen?) |
|
1756 | - $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use"); |
|
1757 | - $xml .= $this->serialize_val($v, $eName, false, false, false, false, $use); |
|
1758 | - } |
|
1759 | - } |
|
1760 | - } |
|
1761 | - } |
|
1762 | - } else { |
|
1763 | - $this->debug("no elements to serialize for XML Schema type $ns:$uqType"); |
|
1764 | - } |
|
1765 | - return $xml; |
|
1766 | - } |
|
1662 | + /** |
|
1663 | + * serializes the elements for a complexType |
|
1664 | + * |
|
1665 | + * @param array $typeDef our internal representation of an XML schema type (or element) |
|
1666 | + * @param mixed $value a native PHP value (parameter value) |
|
1667 | + * @param string $ns the namespace of the type |
|
1668 | + * @param string $uqType the local part of the type |
|
1669 | + * @param string $use use for part (encoded|literal) |
|
1670 | + * @param string $encodingStyle SOAP encoding style for the value (if different than the enclosing style) |
|
1671 | + * @return string value serialized as an XML string |
|
1672 | + * @access private |
|
1673 | + */ |
|
1674 | + function serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use='encoded', $encodingStyle=false) { |
|
1675 | + $this->debug("in serializeComplexTypeElements for XML Schema type $ns:$uqType"); |
|
1676 | + $xml = ''; |
|
1677 | + if (isset($typeDef['extensionBase'])) { |
|
1678 | + $nsx = $this->getPrefix($typeDef['extensionBase']); |
|
1679 | + $uqTypex = $this->getLocalPart($typeDef['extensionBase']); |
|
1680 | + if ($this->getNamespaceFromPrefix($nsx)) { |
|
1681 | + $nsx = $this->getNamespaceFromPrefix($nsx); |
|
1682 | + } |
|
1683 | + if ($typeDefx = $this->getTypeDef($uqTypex, $nsx)) { |
|
1684 | + $this->debug("serialize elements for extension base $nsx:$uqTypex"); |
|
1685 | + $xml .= $this->serializeComplexTypeElements($typeDefx, $value, $nsx, $uqTypex, $use, $encodingStyle); |
|
1686 | + } else { |
|
1687 | + $this->debug("extension base $nsx:$uqTypex is not a supported type"); |
|
1688 | + } |
|
1689 | + } |
|
1690 | + if (isset($typeDef['elements']) && is_array($typeDef['elements'])) { |
|
1691 | + $this->debug("in serializeComplexTypeElements, serialize elements for XML Schema type $ns:$uqType"); |
|
1692 | + if (is_array($value)) { |
|
1693 | + $xvalue = $value; |
|
1694 | + } elseif (is_object($value)) { |
|
1695 | + $xvalue = get_object_vars($value); |
|
1696 | + } else { |
|
1697 | + $this->debug("value is neither an array nor an object for XML Schema type $ns:$uqType"); |
|
1698 | + $xvalue = array(); |
|
1699 | + } |
|
1700 | + // toggle whether all elements are present - ideally should validate against schema |
|
1701 | + if (count($typeDef['elements']) != count($xvalue)){ |
|
1702 | + $optionals = true; |
|
1703 | + } |
|
1704 | + foreach ($typeDef['elements'] as $eName => $attrs) { |
|
1705 | + if (!isset($xvalue[$eName])) { |
|
1706 | + if (isset($attrs['default'])) { |
|
1707 | + $xvalue[$eName] = $attrs['default']; |
|
1708 | + $this->debug('use default value of ' . $xvalue[$eName] . ' for element ' . $eName); |
|
1709 | + } |
|
1710 | + } |
|
1711 | + // if user took advantage of a minOccurs=0, then only serialize named parameters |
|
1712 | + if (isset($optionals) |
|
1713 | + && (!isset($xvalue[$eName])) |
|
1714 | + && ( (!isset($attrs['nillable'])) || $attrs['nillable'] != 'true') |
|
1715 | + ){ |
|
1716 | + if (isset($attrs['minOccurs']) && $attrs['minOccurs'] <> '0') { |
|
1717 | + $this->debug("apparent error: no value provided for element $eName with minOccurs=" . $attrs['minOccurs']); |
|
1718 | + } |
|
1719 | + // do nothing |
|
1720 | + $this->debug("no value provided for complexType element $eName and element is not nillable, so serialize nothing"); |
|
1721 | + } else { |
|
1722 | + // get value |
|
1723 | + if (isset($xvalue[$eName])) { |
|
1724 | + $v = $xvalue[$eName]; |
|
1725 | + } else { |
|
1726 | + $v = null; |
|
1727 | + } |
|
1728 | + if (isset($attrs['form'])) { |
|
1729 | + $unqualified = ($attrs['form'] == 'unqualified'); |
|
1730 | + } else { |
|
1731 | + $unqualified = false; |
|
1732 | + } |
|
1733 | + if (isset($attrs['maxOccurs']) && ($attrs['maxOccurs'] == 'unbounded' || $attrs['maxOccurs'] > 1) && isset($v) && is_array($v) && $this->isArraySimpleOrStruct($v) == 'arraySimple') { |
|
1734 | + $vv = $v; |
|
1735 | + foreach ($vv as $k => $v) { |
|
1736 | + if (isset($attrs['type']) || isset($attrs['ref'])) { |
|
1737 | + // serialize schema-defined type |
|
1738 | + $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified); |
|
1739 | + } else { |
|
1740 | + // serialize generic type (can this ever really happen?) |
|
1741 | + $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use"); |
|
1742 | + $xml .= $this->serialize_val($v, $eName, false, false, false, false, $use); |
|
1743 | + } |
|
1744 | + } |
|
1745 | + } else { |
|
1746 | + if (is_null($v) && isset($attrs['minOccurs']) && $attrs['minOccurs'] == '0') { |
|
1747 | + // do nothing |
|
1748 | + } elseif (is_null($v) && isset($attrs['nillable']) && $attrs['nillable'] == 'true') { |
|
1749 | + // TODO: serialize a nil correctly, but for now serialize schema-defined type |
|
1750 | + $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified); |
|
1751 | + } elseif (isset($attrs['type']) || isset($attrs['ref'])) { |
|
1752 | + // serialize schema-defined type |
|
1753 | + $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified); |
|
1754 | + } else { |
|
1755 | + // serialize generic type (can this ever really happen?) |
|
1756 | + $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use"); |
|
1757 | + $xml .= $this->serialize_val($v, $eName, false, false, false, false, $use); |
|
1758 | + } |
|
1759 | + } |
|
1760 | + } |
|
1761 | + } |
|
1762 | + } else { |
|
1763 | + $this->debug("no elements to serialize for XML Schema type $ns:$uqType"); |
|
1764 | + } |
|
1765 | + return $xml; |
|
1766 | + } |
|
1767 | 1767 | |
1768 | - /** |
|
1769 | - * adds an XML Schema complex type to the WSDL types |
|
1770 | - * |
|
1771 | - * @param string $name |
|
1772 | - * @param string $typeClass (complexType|simpleType|attribute) |
|
1773 | - * @param string $phpType currently supported are array and struct (php assoc array) |
|
1774 | - * @param string $compositor (all|sequence|choice) |
|
1775 | - * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) |
|
1776 | - * @param array $elements e.g. array ( name => array(name=>'',type=>'') ) |
|
1777 | - * @param array $attrs e.g. array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]')) |
|
1778 | - * @param string $arrayType as namespace:name (xsd:string) |
|
1779 | - * @see nusoap_xmlschema |
|
1780 | - * @access public |
|
1781 | - */ |
|
1782 | - function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType='') { |
|
1783 | - if (count($elements) > 0) { |
|
1784 | - $eElements = array(); |
|
1785 | - foreach($elements as $n => $e){ |
|
1786 | - // expand each element |
|
1787 | - $ee = array(); |
|
1788 | - foreach ($e as $k => $v) { |
|
1789 | - $k = strpos($k,':') ? $this->expandQname($k) : $k; |
|
1790 | - $v = strpos($v,':') ? $this->expandQname($v) : $v; |
|
1791 | - $ee[$k] = $v; |
|
1792 | - } |
|
1793 | - $eElements[$n] = $ee; |
|
1794 | - } |
|
1795 | - $elements = $eElements; |
|
1796 | - } |
|
1768 | + /** |
|
1769 | + * adds an XML Schema complex type to the WSDL types |
|
1770 | + * |
|
1771 | + * @param string $name |
|
1772 | + * @param string $typeClass (complexType|simpleType|attribute) |
|
1773 | + * @param string $phpType currently supported are array and struct (php assoc array) |
|
1774 | + * @param string $compositor (all|sequence|choice) |
|
1775 | + * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) |
|
1776 | + * @param array $elements e.g. array ( name => array(name=>'',type=>'') ) |
|
1777 | + * @param array $attrs e.g. array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]')) |
|
1778 | + * @param string $arrayType as namespace:name (xsd:string) |
|
1779 | + * @see nusoap_xmlschema |
|
1780 | + * @access public |
|
1781 | + */ |
|
1782 | + function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType='') { |
|
1783 | + if (count($elements) > 0) { |
|
1784 | + $eElements = array(); |
|
1785 | + foreach($elements as $n => $e){ |
|
1786 | + // expand each element |
|
1787 | + $ee = array(); |
|
1788 | + foreach ($e as $k => $v) { |
|
1789 | + $k = strpos($k,':') ? $this->expandQname($k) : $k; |
|
1790 | + $v = strpos($v,':') ? $this->expandQname($v) : $v; |
|
1791 | + $ee[$k] = $v; |
|
1792 | + } |
|
1793 | + $eElements[$n] = $ee; |
|
1794 | + } |
|
1795 | + $elements = $eElements; |
|
1796 | + } |
|
1797 | 1797 | |
1798 | - if (count($attrs) > 0) { |
|
1799 | - foreach($attrs as $n => $a){ |
|
1800 | - // expand each attribute |
|
1801 | - foreach ($a as $k => $v) { |
|
1802 | - $k = strpos($k,':') ? $this->expandQname($k) : $k; |
|
1803 | - $v = strpos($v,':') ? $this->expandQname($v) : $v; |
|
1804 | - $aa[$k] = $v; |
|
1805 | - } |
|
1806 | - $eAttrs[$n] = $aa; |
|
1807 | - } |
|
1808 | - $attrs = $eAttrs; |
|
1809 | - } |
|
1798 | + if (count($attrs) > 0) { |
|
1799 | + foreach($attrs as $n => $a){ |
|
1800 | + // expand each attribute |
|
1801 | + foreach ($a as $k => $v) { |
|
1802 | + $k = strpos($k,':') ? $this->expandQname($k) : $k; |
|
1803 | + $v = strpos($v,':') ? $this->expandQname($v) : $v; |
|
1804 | + $aa[$k] = $v; |
|
1805 | + } |
|
1806 | + $eAttrs[$n] = $aa; |
|
1807 | + } |
|
1808 | + $attrs = $eAttrs; |
|
1809 | + } |
|
1810 | 1810 | |
1811 | - $restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase; |
|
1812 | - $arrayType = strpos($arrayType,':') ? $this->expandQname($arrayType) : $arrayType; |
|
1811 | + $restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase; |
|
1812 | + $arrayType = strpos($arrayType,':') ? $this->expandQname($arrayType) : $arrayType; |
|
1813 | 1813 | |
1814 | - $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns']; |
|
1815 | - $this->schemas[$typens][0]->addComplexType($name,$typeClass,$phpType,$compositor,$restrictionBase,$elements,$attrs,$arrayType); |
|
1816 | - } |
|
1814 | + $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns']; |
|
1815 | + $this->schemas[$typens][0]->addComplexType($name,$typeClass,$phpType,$compositor,$restrictionBase,$elements,$attrs,$arrayType); |
|
1816 | + } |
|
1817 | 1817 | |
1818 | - /** |
|
1819 | - * adds an XML Schema simple type to the WSDL types |
|
1820 | - * |
|
1821 | - * @param string $name |
|
1822 | - * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) |
|
1823 | - * @param string $typeClass (should always be simpleType) |
|
1824 | - * @param string $phpType (should always be scalar) |
|
1825 | - * @param array $enumeration array of values |
|
1826 | - * @see nusoap_xmlschema |
|
1827 | - * @access public |
|
1828 | - */ |
|
1829 | - function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) { |
|
1830 | - $restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase; |
|
1818 | + /** |
|
1819 | + * adds an XML Schema simple type to the WSDL types |
|
1820 | + * |
|
1821 | + * @param string $name |
|
1822 | + * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) |
|
1823 | + * @param string $typeClass (should always be simpleType) |
|
1824 | + * @param string $phpType (should always be scalar) |
|
1825 | + * @param array $enumeration array of values |
|
1826 | + * @see nusoap_xmlschema |
|
1827 | + * @access public |
|
1828 | + */ |
|
1829 | + function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) { |
|
1830 | + $restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase; |
|
1831 | 1831 | |
1832 | - $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns']; |
|
1833 | - $this->schemas[$typens][0]->addSimpleType($name, $restrictionBase, $typeClass, $phpType, $enumeration); |
|
1834 | - } |
|
1832 | + $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns']; |
|
1833 | + $this->schemas[$typens][0]->addSimpleType($name, $restrictionBase, $typeClass, $phpType, $enumeration); |
|
1834 | + } |
|
1835 | 1835 | |
1836 | - /** |
|
1837 | - * adds an element to the WSDL types |
|
1838 | - * |
|
1839 | - * @param array $attrs attributes that must include name and type |
|
1840 | - * @see nusoap_xmlschema |
|
1841 | - * @access public |
|
1842 | - */ |
|
1843 | - function addElement($attrs) { |
|
1844 | - $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns']; |
|
1845 | - $this->schemas[$typens][0]->addElement($attrs); |
|
1846 | - } |
|
1836 | + /** |
|
1837 | + * adds an element to the WSDL types |
|
1838 | + * |
|
1839 | + * @param array $attrs attributes that must include name and type |
|
1840 | + * @see nusoap_xmlschema |
|
1841 | + * @access public |
|
1842 | + */ |
|
1843 | + function addElement($attrs) { |
|
1844 | + $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns']; |
|
1845 | + $this->schemas[$typens][0]->addElement($attrs); |
|
1846 | + } |
|
1847 | 1847 | |
1848 | - /** |
|
1849 | - * register an operation with the server |
|
1850 | - * |
|
1851 | - * @param string $name operation (method) name |
|
1852 | - * @param array $in assoc array of input values: key = param name, value = param type |
|
1853 | - * @param array $out assoc array of output values: key = param name, value = param type |
|
1854 | - * @param string $namespace optional The namespace for the operation |
|
1855 | - * @param string $soapaction optional The soapaction for the operation |
|
1856 | - * @param string $style (rpc|document) optional The style for the operation Note: when 'document' is specified, parameter and return wrappers are created for you automatically |
|
1857 | - * @param string $use (encoded|literal) optional The use for the parameters (cannot mix right now) |
|
1858 | - * @param string $documentation optional The description to include in the WSDL |
|
1859 | - * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded) |
|
1860 | - * @access public |
|
1861 | - */ |
|
1862 | - function addOperation($name, $in = false, $out = false, $namespace = false, $soapaction = false, $style = 'rpc', $use = 'encoded', $documentation = '', $encodingStyle = ''){ |
|
1863 | - if ($use == 'encoded' && $encodingStyle == '') { |
|
1864 | - $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/'; |
|
1865 | - } |
|
1848 | + /** |
|
1849 | + * register an operation with the server |
|
1850 | + * |
|
1851 | + * @param string $name operation (method) name |
|
1852 | + * @param array $in assoc array of input values: key = param name, value = param type |
|
1853 | + * @param array $out assoc array of output values: key = param name, value = param type |
|
1854 | + * @param string $namespace optional The namespace for the operation |
|
1855 | + * @param string $soapaction optional The soapaction for the operation |
|
1856 | + * @param string $style (rpc|document) optional The style for the operation Note: when 'document' is specified, parameter and return wrappers are created for you automatically |
|
1857 | + * @param string $use (encoded|literal) optional The use for the parameters (cannot mix right now) |
|
1858 | + * @param string $documentation optional The description to include in the WSDL |
|
1859 | + * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded) |
|
1860 | + * @access public |
|
1861 | + */ |
|
1862 | + function addOperation($name, $in = false, $out = false, $namespace = false, $soapaction = false, $style = 'rpc', $use = 'encoded', $documentation = '', $encodingStyle = ''){ |
|
1863 | + if ($use == 'encoded' && $encodingStyle == '') { |
|
1864 | + $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/'; |
|
1865 | + } |
|
1866 | 1866 | |
1867 | - if ($style == 'document') { |
|
1868 | - $elements = array(); |
|
1869 | - foreach ($in as $n => $t) { |
|
1870 | - $elements[$n] = array('name' => $n, 'type' => $t, 'form' => 'unqualified'); |
|
1871 | - } |
|
1872 | - $this->addComplexType($name . 'RequestType', 'complexType', 'struct', 'all', '', $elements); |
|
1873 | - $this->addElement(array('name' => $name, 'type' => $name . 'RequestType')); |
|
1874 | - $in = array('parameters' => 'tns:' . $name . '^'); |
|
1867 | + if ($style == 'document') { |
|
1868 | + $elements = array(); |
|
1869 | + foreach ($in as $n => $t) { |
|
1870 | + $elements[$n] = array('name' => $n, 'type' => $t, 'form' => 'unqualified'); |
|
1871 | + } |
|
1872 | + $this->addComplexType($name . 'RequestType', 'complexType', 'struct', 'all', '', $elements); |
|
1873 | + $this->addElement(array('name' => $name, 'type' => $name . 'RequestType')); |
|
1874 | + $in = array('parameters' => 'tns:' . $name . '^'); |
|
1875 | 1875 | |
1876 | - $elements = array(); |
|
1877 | - foreach ($out as $n => $t) { |
|
1878 | - $elements[$n] = array('name' => $n, 'type' => $t, 'form' => 'unqualified'); |
|
1879 | - } |
|
1880 | - $this->addComplexType($name . 'ResponseType', 'complexType', 'struct', 'all', '', $elements); |
|
1881 | - $this->addElement(array('name' => $name . 'Response', 'type' => $name . 'ResponseType', 'form' => 'qualified')); |
|
1882 | - $out = array('parameters' => 'tns:' . $name . 'Response' . '^'); |
|
1883 | - } |
|
1876 | + $elements = array(); |
|
1877 | + foreach ($out as $n => $t) { |
|
1878 | + $elements[$n] = array('name' => $n, 'type' => $t, 'form' => 'unqualified'); |
|
1879 | + } |
|
1880 | + $this->addComplexType($name . 'ResponseType', 'complexType', 'struct', 'all', '', $elements); |
|
1881 | + $this->addElement(array('name' => $name . 'Response', 'type' => $name . 'ResponseType', 'form' => 'qualified')); |
|
1882 | + $out = array('parameters' => 'tns:' . $name . 'Response' . '^'); |
|
1883 | + } |
|
1884 | 1884 | |
1885 | - // get binding |
|
1886 | - $this->bindings[ $this->serviceName . 'Binding' ]['operations'][$name] = |
|
1887 | - array( |
|
1888 | - 'name' => $name, |
|
1889 | - 'binding' => $this->serviceName . 'Binding', |
|
1890 | - 'endpoint' => $this->endpoint, |
|
1891 | - 'soapAction' => $soapaction, |
|
1892 | - 'style' => $style, |
|
1893 | - 'input' => array( |
|
1894 | - 'use' => $use, |
|
1895 | - 'namespace' => $namespace, |
|
1896 | - 'encodingStyle' => $encodingStyle, |
|
1897 | - 'message' => $name . 'Request', |
|
1898 | - 'parts' => $in), |
|
1899 | - 'output' => array( |
|
1900 | - 'use' => $use, |
|
1901 | - 'namespace' => $namespace, |
|
1902 | - 'encodingStyle' => $encodingStyle, |
|
1903 | - 'message' => $name . 'Response', |
|
1904 | - 'parts' => $out), |
|
1905 | - 'namespace' => $namespace, |
|
1906 | - 'transport' => 'http://schemas.xmlsoap.org/soap/http', |
|
1907 | - 'documentation' => $documentation); |
|
1908 | - // add portTypes |
|
1909 | - // add messages |
|
1910 | - if($in) |
|
1911 | - { |
|
1912 | - foreach($in as $pName => $pType) |
|
1913 | - { |
|
1914 | - if(strpos($pType,':')) { |
|
1915 | - $pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)).":".$this->getLocalPart($pType); |
|
1916 | - } |
|
1917 | - $this->messages[$name.'Request'][$pName] = $pType; |
|
1918 | - } |
|
1919 | - } else { |
|
1885 | + // get binding |
|
1886 | + $this->bindings[ $this->serviceName . 'Binding' ]['operations'][$name] = |
|
1887 | + array( |
|
1888 | + 'name' => $name, |
|
1889 | + 'binding' => $this->serviceName . 'Binding', |
|
1890 | + 'endpoint' => $this->endpoint, |
|
1891 | + 'soapAction' => $soapaction, |
|
1892 | + 'style' => $style, |
|
1893 | + 'input' => array( |
|
1894 | + 'use' => $use, |
|
1895 | + 'namespace' => $namespace, |
|
1896 | + 'encodingStyle' => $encodingStyle, |
|
1897 | + 'message' => $name . 'Request', |
|
1898 | + 'parts' => $in), |
|
1899 | + 'output' => array( |
|
1900 | + 'use' => $use, |
|
1901 | + 'namespace' => $namespace, |
|
1902 | + 'encodingStyle' => $encodingStyle, |
|
1903 | + 'message' => $name . 'Response', |
|
1904 | + 'parts' => $out), |
|
1905 | + 'namespace' => $namespace, |
|
1906 | + 'transport' => 'http://schemas.xmlsoap.org/soap/http', |
|
1907 | + 'documentation' => $documentation); |
|
1908 | + // add portTypes |
|
1909 | + // add messages |
|
1910 | + if($in) |
|
1911 | + { |
|
1912 | + foreach($in as $pName => $pType) |
|
1913 | + { |
|
1914 | + if(strpos($pType,':')) { |
|
1915 | + $pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)).":".$this->getLocalPart($pType); |
|
1916 | + } |
|
1917 | + $this->messages[$name.'Request'][$pName] = $pType; |
|
1918 | + } |
|
1919 | + } else { |
|
1920 | 1920 | $this->messages[$name.'Request']= '0'; |
1921 | 1921 | } |
1922 | - if($out) |
|
1923 | - { |
|
1924 | - foreach($out as $pName => $pType) |
|
1925 | - { |
|
1926 | - if(strpos($pType,':')) { |
|
1927 | - $pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)).":".$this->getLocalPart($pType); |
|
1928 | - } |
|
1929 | - $this->messages[$name.'Response'][$pName] = $pType; |
|
1930 | - } |
|
1931 | - } else { |
|
1922 | + if($out) |
|
1923 | + { |
|
1924 | + foreach($out as $pName => $pType) |
|
1925 | + { |
|
1926 | + if(strpos($pType,':')) { |
|
1927 | + $pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)).":".$this->getLocalPart($pType); |
|
1928 | + } |
|
1929 | + $this->messages[$name.'Response'][$pName] = $pType; |
|
1930 | + } |
|
1931 | + } else { |
|
1932 | 1932 | $this->messages[$name.'Response']= '0'; |
1933 | 1933 | } |
1934 | - return true; |
|
1935 | - } |
|
1934 | + return true; |
|
1935 | + } |
|
1936 | 1936 | } |
1937 | 1937 | |
1938 | 1938 | ?> |
@@ -666,7 +666,7 @@ |
||
666 | 666 | $res = Database::query($sql); |
667 | 667 | $count1 = Database::fetch_object($res); |
668 | 668 | $sql = "SELECT COUNT(*) AS n FROM $user_table as u $table ". |
669 | - "WHERE LENGTH(picture_uri) > 0 $url_condition2"; |
|
669 | + "WHERE LENGTH(picture_uri) > 0 $url_condition2"; |
|
670 | 670 | $res = Database::query($sql); |
671 | 671 | $count2 = Database::fetch_object($res); |
672 | 672 | // #users without picture |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | |
19 | 19 | class OpenGraph implements Iterator |
20 | 20 | { |
21 | - /** |
|
22 | - * There are base schema's based on type, this is just |
|
23 | - * a map so that the schema can be obtained |
|
24 | - * |
|
25 | - */ |
|
21 | + /** |
|
22 | + * There are base schema's based on type, this is just |
|
23 | + * a map so that the schema can be obtained |
|
24 | + * |
|
25 | + */ |
|
26 | 26 | public static $TYPES = array( |
27 | 27 | 'activity' => array('activity', 'sport'), |
28 | 28 | 'business' => array('bar', 'company', 'cafe', 'hotel', 'restaurant'), |
@@ -34,19 +34,19 @@ discard block |
||
34 | 34 | 'website' => array('blog', 'website'), |
35 | 35 | ); |
36 | 36 | |
37 | - /** |
|
38 | - * Holds all the Open Graph values we've parsed from a page |
|
39 | - * |
|
40 | - */ |
|
37 | + /** |
|
38 | + * Holds all the Open Graph values we've parsed from a page |
|
39 | + * |
|
40 | + */ |
|
41 | 41 | private $_values = array(); |
42 | 42 | |
43 | - /** |
|
44 | - * Fetches a URI and parses it for Open Graph data, returns |
|
45 | - * false on error. |
|
46 | - * |
|
47 | - * @param $URI URI to page to parse for Open Graph data |
|
48 | - * @return OpenGraph |
|
49 | - */ |
|
43 | + /** |
|
44 | + * Fetches a URI and parses it for Open Graph data, returns |
|
45 | + * false on error. |
|
46 | + * |
|
47 | + * @param $URI URI to page to parse for Open Graph data |
|
48 | + * @return OpenGraph |
|
49 | + */ |
|
50 | 50 | static public function fetch($URI) { |
51 | 51 | $curl = curl_init($URI); |
52 | 52 | |
@@ -69,13 +69,13 @@ discard block |
||
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
72 | - /** |
|
73 | - * Parses HTML and extracts Open Graph data, this assumes |
|
74 | - * the document is at least well formed. |
|
75 | - * |
|
76 | - * @param $HTML HTML to parse |
|
77 | - * @return OpenGraph |
|
78 | - */ |
|
72 | + /** |
|
73 | + * Parses HTML and extracts Open Graph data, this assumes |
|
74 | + * the document is at least well formed. |
|
75 | + * |
|
76 | + * @param $HTML HTML to parse |
|
77 | + * @return OpenGraph |
|
78 | + */ |
|
79 | 79 | static private function _parse($HTML) { |
80 | 80 | $old_libxml_error = libxml_use_internal_errors(true); |
81 | 81 | |
@@ -140,13 +140,13 @@ discard block |
||
140 | 140 | return $page; |
141 | 141 | } |
142 | 142 | |
143 | - /** |
|
144 | - * Helper method to access attributes directly |
|
145 | - * Example: |
|
146 | - * $graph->title |
|
147 | - * |
|
148 | - * @param $key Key to fetch from the lookup |
|
149 | - */ |
|
143 | + /** |
|
144 | + * Helper method to access attributes directly |
|
145 | + * Example: |
|
146 | + * $graph->title |
|
147 | + * |
|
148 | + * @param $key Key to fetch from the lookup |
|
149 | + */ |
|
150 | 150 | public function __get($key) { |
151 | 151 | if (array_key_exists($key, $this->_values)) { |
152 | 152 | return $this->_values[$key]; |
@@ -161,29 +161,29 @@ discard block |
||
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
164 | - /** |
|
165 | - * Return all the keys found on the page |
|
166 | - * |
|
167 | - * @return array |
|
168 | - */ |
|
164 | + /** |
|
165 | + * Return all the keys found on the page |
|
166 | + * |
|
167 | + * @return array |
|
168 | + */ |
|
169 | 169 | public function keys() { |
170 | 170 | return array_keys($this->_values); |
171 | 171 | } |
172 | 172 | |
173 | - /** |
|
174 | - * Helper method to check an attribute exists |
|
175 | - * |
|
176 | - * @param $key |
|
177 | - */ |
|
173 | + /** |
|
174 | + * Helper method to check an attribute exists |
|
175 | + * |
|
176 | + * @param $key |
|
177 | + */ |
|
178 | 178 | public function __isset($key) { |
179 | 179 | return array_key_exists($key, $this->_values); |
180 | 180 | } |
181 | 181 | |
182 | - /** |
|
183 | - * Will return true if the page has location data embedded |
|
184 | - * |
|
185 | - * @return boolean Check if the page has location data |
|
186 | - */ |
|
182 | + /** |
|
183 | + * Will return true if the page has location data embedded |
|
184 | + * |
|
185 | + * @return boolean Check if the page has location data |
|
186 | + */ |
|
187 | 187 | public function hasLocation() { |
188 | 188 | if (array_key_exists('latitude', $this->_values) && array_key_exists('longitude', $this->_values)) { |
189 | 189 | return true; |
@@ -197,9 +197,9 @@ discard block |
||
197 | 197 | return $valid_address; |
198 | 198 | } |
199 | 199 | |
200 | - /** |
|
201 | - * Iterator code |
|
202 | - */ |
|
200 | + /** |
|
201 | + * Iterator code |
|
202 | + */ |
|
203 | 203 | private $_position = 0; |
204 | 204 | public function rewind() { reset($this->_values); $this->_position = 0; } |
205 | 205 | public function current() { return current($this->_values); } |
@@ -107,14 +107,14 @@ |
||
107 | 107 | return $resu; |
108 | 108 | } |
109 | 109 | |
110 | - /** |
|
111 | - * @author Sebastien Piraux <[email protected]> |
|
112 | - * @param sql : a sql query (as a string) |
|
113 | - * @return hours_array |
|
114 | - * @desc Return an assoc array. Keys are the hours, values are |
|
115 | - * the number of time this hours was found. |
|
116 | - * key 'total' return the sum of all number of time hours |
|
117 | - * appear |
|
110 | + /** |
|
111 | + * @author Sebastien Piraux <[email protected]> |
|
112 | + * @param sql : a sql query (as a string) |
|
113 | + * @return hours_array |
|
114 | + * @desc Return an assoc array. Keys are the hours, values are |
|
115 | + * the number of time this hours was found. |
|
116 | + * key 'total' return the sum of all number of time hours |
|
117 | + * appear |
|
118 | 118 | */ |
119 | 119 | public static function hoursTab($sql) |
120 | 120 | { |
@@ -5,42 +5,42 @@ |
||
5 | 5 | * @deprecated Don't use this class |
6 | 6 | */ |
7 | 7 | class Rights { |
8 | - private static $rights_cache = array(); |
|
9 | - private static $rights = array ( |
|
10 | - 'show_tabs:reports' => |
|
11 | - array ( |
|
12 | - 'type' => 'const', |
|
13 | - 'const' => 'true' ) |
|
14 | - ); |
|
8 | + private static $rights_cache = array(); |
|
9 | + private static $rights = array ( |
|
10 | + 'show_tabs:reports' => |
|
11 | + array ( |
|
12 | + 'type' => 'const', |
|
13 | + 'const' => 'true' ) |
|
14 | + ); |
|
15 | 15 | |
16 | - // warning the goal of this function is to enforce rights managment in Chamilo |
|
17 | - // thus default return value is always true |
|
18 | - public static function hasRight($handler) { |
|
19 | - if (array_key_exists($handler, self::$rights_cache)) |
|
20 | - return self::$rights_cache[$handler]; |
|
16 | + // warning the goal of this function is to enforce rights managment in Chamilo |
|
17 | + // thus default return value is always true |
|
18 | + public static function hasRight($handler) { |
|
19 | + if (array_key_exists($handler, self::$rights_cache)) |
|
20 | + return self::$rights_cache[$handler]; |
|
21 | 21 | |
22 | - if (!array_key_exists($handler, self::$rights)) |
|
23 | - return true; // handler does not exists |
|
22 | + if (!array_key_exists($handler, self::$rights)) |
|
23 | + return true; // handler does not exists |
|
24 | 24 | |
25 | - if (self::$rights[$handler]['type'] == 'sql') { |
|
26 | - $result = Database::query(self::$rights[$handler]['sql']); |
|
27 | - if (Database::num_rows($result) > 0) |
|
28 | - $result = true; |
|
29 | - else |
|
30 | - $result = false; |
|
31 | - } else if (self::$rights[$handler]['type'] == 'const') |
|
32 | - $result = self::$rights[$handler]['const']; |
|
33 | - else if (self::$rights[$handler]['type'] == 'func') |
|
34 | - $result = self::$rights[$handler]['func'](); |
|
35 | - else // handler type not implemented |
|
36 | - return true; |
|
37 | - self::$rights_cache[$handler] = $result; |
|
38 | - return $result; |
|
39 | - } |
|
25 | + if (self::$rights[$handler]['type'] == 'sql') { |
|
26 | + $result = Database::query(self::$rights[$handler]['sql']); |
|
27 | + if (Database::num_rows($result) > 0) |
|
28 | + $result = true; |
|
29 | + else |
|
30 | + $result = false; |
|
31 | + } else if (self::$rights[$handler]['type'] == 'const') |
|
32 | + $result = self::$rights[$handler]['const']; |
|
33 | + else if (self::$rights[$handler]['type'] == 'func') |
|
34 | + $result = self::$rights[$handler]['func'](); |
|
35 | + else // handler type not implemented |
|
36 | + return true; |
|
37 | + self::$rights_cache[$handler] = $result; |
|
38 | + return $result; |
|
39 | + } |
|
40 | 40 | |
41 | - public static function hasRightClosePageWithError($handler) { |
|
42 | - if (hasRight($handler) == false) |
|
43 | - die("You are not allowed here"); //FIXME |
|
44 | - } |
|
41 | + public static function hasRightClosePageWithError($handler) { |
|
42 | + if (hasRight($handler) == false) |
|
43 | + die("You are not allowed here"); //FIXME |
|
44 | + } |
|
45 | 45 | |
46 | 46 | } |