Produced by Araxis Merge on 3/13/2019 2:49:52 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | C:\AraxisMergeCompare\Pri_un\DSM\Direct_VLER-Libraries\application\third_party | nusoap.php | Tue Mar 12 21:52:50 2019 UTC |
| 2 | C:\AraxisMergeCompare\Pri_re\DSM-scrubbed\Direct_VLER-Libraries\application\third_party | nusoap.php | Wed Mar 13 19:04:56 2019 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 5 | 13252 |
| Changed | 4 | 8 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * $Id: nus oap.php,v 1.123 2010 /04/26 20: 15:08 snic hol Exp $ | |
| 5 | * | |
| 6 | * NuSOAP - Web Servi ces Toolki t for PHP | |
| 7 | * | |
| 8 | * Copyrigh t (c) 2002 NuSphere Corporatio n | |
| 9 | * | |
| 10 | * This lib rary is fr ee softwar e; you can redistrib ute it and /or modify it under the terms of the GNU Lesser Ge neral Publ ic License as publis hed by the Free Soft ware Found ation; eit her versio n 2.1 of t he License , | |
| 11 | * or (at y our option ) any late r version. | |
| 12 | * | |
| 13 | * This lib rary is di stributed in the hop e that it will be us eful, but WITHOUT AN Y WARRANTY ; without even the i mplied war ranty of M ERCHANTABI LITY or FI TNESS FOR A PARTICUL AR PURPOSE . See the GNU | |
| 14 | * Lesser G eneral Pub lic Licens e for more details. | |
| 15 | * | |
| 16 | * You shou ld have re ceived a c opy of the GNU Lesse r General Public Lic ense along with this library; if not, wr ite to the Free Soft ware Found ation, Inc ., 59 Temp le Place, Suite 330, Boston, M A 02111-1 307 USA | |
| 17 | * | |
| 18 | * The NuSO AP project home is: http://sou rceforge.n et/project s/nusoap/ | |
| 19 | * | |
| 20 | * The prim ary suppor t for NuSO AP is the Help forum on the pr oject home page. | |
| 21 | * | |
| 22 | * If you h ave any qu estions or comments, please em ail: | |
| 23 | * | |
| 24 | * Dietrich Ayala | |
| 25 | * dietrich @ganx4.com | |
| 26 | * http://d ietrich.ga nx4.com/nu soap | |
| 27 | * | |
| 28 | * NuSphere Corporati on | |
| 29 | * http://w ww.nuspher e.com | |
| 30 | * | |
| 31 | * @package third-par ty | |
| 32 | * @subpack age nusoap | |
| 33 | */ | |
| 34 | ||
| 35 | /* | |
| 36 | * So me of the standards implmented in whole or part by NuSOAP: | |
| 37 | * | |
| 38 | * SO AP 1.1 (ht tp://www.w 3.org/TR/2 000/NOTE-S OAP-200005 08/) | |
| 39 | * WS DL 1.1 (ht tp://www.w 3.org/TR/2 001/NOTE-w sdl-200103 15) | |
| 40 | * SO AP Message s With Att achments ( http://www .w3.org/TR /SOAP-atta chments) | |
| 41 | * XM L 1.0 (htt p://www.w3 .org/TR/20 06/REC-xml -20060816/ ) | |
| 42 | * Na mespaces i n XML 1.0 (http://ww w.w3.org/T R/2006/REC -xml-names -20060816/ ) | |
| 43 | * XM L Schema 1 .0 (http:/ /www.w3.or g/TR/xmlsc hema-0/) | |
| 44 | * RF C 2045 Mul tipurpose Internet M ail Extens ions (MIME ) Part One : Format o f Internet Message B odies | |
| 45 | * RF C 2068 Hyp ertext Tra nsfer Prot ocol -- HT TP/1.1 | |
| 46 | * RF C 2617 HTT P Authenti cation: Ba sic and Di gest Acces s Authenti cation | |
| 47 | */ | |
| 48 | ||
| 49 | // class v ariable em ulation | |
| 50 | // cf. htt p://www.we bkreator.c om/php/tec hniques/ph p-static-c lass-varia bles.html | |
| 51 | $GLOBALS[' _transient ']['static ']['nusoap _base']['g lobalDebug Level'] = 9; | |
| 52 | ||
| 53 | /** | |
| 54 | * nusoap_b ase | |
| 55 | * | |
| 56 | * @author Dietrich Ayala <di etrich@gan x4.com> | |
| 57 | * @author Scott Ni chol <snic hol@users. sourceforg e.net> | |
| 58 | * @version $Id: nus oap.php,v 1.123 2010 /04/26 20: 15:08 snic hol Exp $ | |
| 59 | * @access public | |
| 60 | * @package third-par ty | |
| 61 | * @subpack age nusoap | |
| 62 | */ | |
| 63 | class nuso ap_base { | |
| 64 | /* * | |
| 65 | * Identific ation for HTTP heade rs. | |
| 66 | * | |
| 67 | * @var stri ng | |
| 68 | * @access p rivate | |
| 69 | * / | |
| 70 | va r $title = 'NuSOAP'; | |
| 71 | /* * | |
| 72 | * Version f or HTTP he aders. | |
| 73 | * | |
| 74 | * @var stri ng | |
| 75 | * @access p rivate | |
| 76 | * / | |
| 77 | va r $version = '0.9.5' ; | |
| 78 | /* * | |
| 79 | * CVS revis ion for HT TP headers . | |
| 80 | * | |
| 81 | * @var stri ng | |
| 82 | * @access p rivate | |
| 83 | * / | |
| 84 | va r $revisio n = '$Revi sion: 1.12 3 $'; | |
| 85 | /** | |
| 86 | * Cur rent error string (m anipulated by getErr or/setErro r) | |
| 87 | * | |
| 88 | * @var stri ng | |
| 89 | * @access p rivate | |
| 90 | * / | |
| 91 | va r $error_s tr = ''; | |
| 92 | /** | |
| 93 | * Cur rent debug string (m anipulated by debug/ appendDebu g/clearDeb ug/getDebu g/getDebug AsXMLComme nt) | |
| 94 | * | |
| 95 | * @var stri ng | |
| 96 | * @access p rivate | |
| 97 | * / | |
| 98 | var $d ebug_str = ''; | |
| 99 | /** | |
| 100 | * toggles a utomatic e ncoding of special c haracters as entitie s | |
| 101 | * (should a lways be t rue, I thi nk) | |
| 102 | * | |
| 103 | * @var bool ean | |
| 104 | * @access p rivate | |
| 105 | * / | |
| 106 | va r $charenc oding = tr ue; | |
| 107 | /* * | |
| 108 | * the debug level for this inst ance | |
| 109 | * | |
| 110 | * @var inte ger | |
| 111 | * @access p rivate | |
| 112 | * / | |
| 113 | va r $debugLe vel; | |
| 114 | ||
| 115 | /** | |
| 116 | * set schema version | |
| 117 | * | |
| 118 | * @var string | |
| 119 | * @access public | |
| 120 | */ | |
| 121 | va r $XMLSche maVersion = 'http:// www.w3.org /2001/XMLS chema'; | |
| 122 | ||
| 123 | /** | |
| 124 | * charset en coding for outgoing messages | |
| 125 | * | |
| 126 | * @var string | |
| 127 | * @access public | |
| 128 | */ | |
| 129 | var $s oap_defenc oding = 'I SO-8859-1' ; | |
| 130 | // var $soap_ defencodin g = 'UTF-8 '; | |
| 131 | ||
| 132 | /* * | |
| 133 | * namespaces in an arr ay of pref ix => uri | |
| 134 | * | |
| 135 | * this is "s eeded" by a set of c onstants, but it may be altere d by code | |
| 136 | * | |
| 137 | * @var array | |
| 138 | * @access public | |
| 139 | */ | |
| 140 | va r $namespa ces = arra y( | |
| 141 | 'SOA P-ENV' => 'http://sc hemas.xmls oap.org/so ap/envelop e/', | |
| 142 | 'xsd ' => 'http ://www.w3. org/2001/X MLSchema', | |
| 143 | 'xsi ' => 'http ://www.w3. org/2001/X MLSchema-i nstance', | |
| 144 | 'SOA P-ENC' => 'http://sc hemas.xmls oap.org/so ap/encodin g/' | |
| 145 | ); | |
| 146 | ||
| 147 | /* * | |
| 148 | * namespaces used in t he current context, e.g. durin g serializ ation | |
| 149 | * | |
| 150 | * @var array | |
| 151 | * @access private | |
| 152 | */ | |
| 153 | va r $usedNam espaces = array(); | |
| 154 | ||
| 155 | /* * | |
| 156 | * XML Schema types in an array o f uri => ( array of x ml type => php type) | |
| 157 | * is this le gacy yet? | |
| 158 | * no, this i s used by the nusoap _xmlschema class to verify typ e => names pace mappi ngs. | |
| 159 | * @var array | |
| 160 | * @access public | |
| 161 | */ | |
| 162 | va r $typemap = array( | |
| 163 | 'h ttp://www. w3.org/200 1/XMLSchem a' => arra y( | |
| 164 | 'str ing'=>'str ing','bool ean'=>'boo lean','flo at'=>'doub le','doubl e'=>'doubl e','decima l'=>'doubl e', | |
| 165 | 'dur ation'=>'' ,'dateTime '=>'string ','time'=> 'string',' date'=>'st ring','gYe arMonth'=> '', | |
| 166 | 'gYe ar'=>'','g MonthDay'= >'','gDay' =>'','gMon th'=>'','h exBinary'= >'string', 'base64Bin ary'=>'str ing', | |
| 167 | // a bstract "a ny" types | |
| 168 | 'any Type'=>'st ring','any SimpleType '=>'string ', | |
| 169 | // d erived dat atypes | |
| 170 | 'nor malizedStr ing'=>'str ing','toke n'=>'strin g','langua ge'=>'','N MTOKEN'=>' ','NMTOKEN S'=>'','Na me'=>'','N CName'=>'' ,'ID'=>'', | |
| 171 | 'IDR EF'=>'','I DREFS'=>'' ,'ENTITY'= >'','ENTIT IES'=>'',' integer'=> 'integer', 'nonPositi veInteger' =>'integer ', | |
| 172 | 'neg ativeInteg er'=>'inte ger','long '=>'intege r','int'=> 'integer', 'short'=>' integer',' byte'=>'in teger','no nNegativeI nteger'=>' integer', | |
| 173 | 'uns ignedLong' =>'','unsi gnedInt'=> '','unsign edShort'=> '','unsign edByte'=>' ','positiv eInteger'= >''), | |
| 174 | 'h ttp://www. w3.org/200 0/10/XMLSc hema' => a rray( | |
| 175 | 'i4' =>'','int' =>'integer ','boolean '=>'boolea n','string '=>'string ','double' =>'double' , | |
| 176 | 'flo at'=>'doub le','dateT ime'=>'str ing', | |
| 177 | 'tim eInstant'= >'string', 'base64Bin ary'=>'str ing','base 64'=>'stri ng','ur-ty pe'=>'arra y'), | |
| 178 | 'h ttp://www. w3.org/199 9/XMLSchem a' => arra y( | |
| 179 | 'i4' =>'','int' =>'integer ','boolean '=>'boolea n','string '=>'string ','double' =>'double' , | |
| 180 | 'flo at'=>'doub le','dateT ime'=>'str ing', | |
| 181 | 'tim eInstant'= >'string', 'base64Bin ary'=>'str ing','base 64'=>'stri ng','ur-ty pe'=>'arra y'), | |
| 182 | 'h ttp://soap interop.or g/xsd' => array('SOA PStruct'=> 'struct'), | |
| 183 | 'h ttp://sche mas.xmlsoa p.org/soap /encoding/ ' => array ('base64'= >'string', 'array'=>' array','Ar ray'=>'arr ay'), | |
| 184 | 'http: //xml.apac he.org/xml -soap' => array('Map ') | |
| 185 | ); | |
| 186 | ||
| 187 | /* * | |
| 188 | * constructo r | |
| 189 | * | |
| 190 | * @access public | |
| 191 | */ | |
| 192 | fu nction nus oap_base() { | |
| 193 | $thi s->debugLe vel = $GLO BALS['_tra nsient'][' static'][' nusoap_bas e']['globa lDebugLeve l']; | |
| 194 | } | |
| 195 | ||
| 196 | /* * | |
| 197 | * gets the g lobal debu g level, w hich appli es to futu re instanc es | |
| 198 | * | |
| 199 | * @return intege r Debug le vel 0-9, w here 0 tur ns off | |
| 200 | * @access public | |
| 201 | */ | |
| 202 | fu nction get GlobalDebu gLevel() { | |
| 203 | retu rn $GLOBAL S['_transi ent']['sta tic']['nus oap_base'] ['globalDe bugLevel'] ; | |
| 204 | } | |
| 205 | ||
| 206 | /* * | |
| 207 | * sets the g lobal debu g level, w hich appli es to futu re instanc es | |
| 208 | * | |
| 209 | * @param int $level Debug leve l 0-9, whe re 0 turns off | |
| 210 | * @access public | |
| 211 | */ | |
| 212 | fu nction set GlobalDebu gLevel($le vel) { | |
| 213 | $GLO BALS['_tra nsient'][' static'][' nusoap_bas e']['globa lDebugLeve l'] = $lev el; | |
| 214 | } | |
| 215 | ||
| 216 | /* * | |
| 217 | * gets the d ebug level for this instance | |
| 218 | * | |
| 219 | * @return int Debug le vel 0-9, w here 0 tur ns off | |
| 220 | * @access public | |
| 221 | */ | |
| 222 | fu nction get DebugLevel () { | |
| 223 | retu rn $this-> debugLevel ; | |
| 224 | } | |
| 225 | ||
| 226 | /* * | |
| 227 | * sets the d ebug level for this instance | |
| 228 | * | |
| 229 | * @param int $level Debug leve l 0-9, whe re 0 turns off | |
| 230 | * @access public | |
| 231 | */ | |
| 232 | fu nction set DebugLevel ($level) { | |
| 233 | $thi s->debugLe vel = $lev el; | |
| 234 | } | |
| 235 | ||
| 236 | /* * | |
| 237 | * adds debug data to t he instanc e debug st ring with formatting | |
| 238 | * | |
| 239 | * @param string $st ring debug data | |
| 240 | * @access private | |
| 241 | */ | |
| 242 | fu nction deb ug($string ){ | |
| 243 | if ( $this->deb ugLevel > 0) { | |
| 244 | $this- >appendDeb ug($this-> getmicroti me().' '.g et_class($ this).": $ string\n") ; | |
| 245 | } | |
| 246 | } | |
| 247 | ||
| 248 | /* * | |
| 249 | * adds debug data to t he instanc e debug st ring witho ut formatt ing | |
| 250 | * | |
| 251 | * @param string $st ring debug data | |
| 252 | * @access public | |
| 253 | */ | |
| 254 | fu nction app endDebug($ string){ | |
| 255 | if ( $this->deb ugLevel > 0) { | |
| 256 | // it would be n ice to use a memory stream her e to use | |
| 257 | // mem ory more e fficiently | |
| 258 | $this- >debug_str .= $strin g; | |
| 259 | } | |
| 260 | } | |
| 261 | ||
| 262 | /* * | |
| 263 | * clears the current d ebug data for this i nstance | |
| 264 | * | |
| 265 | * @access public | |
| 266 | */ | |
| 267 | fu nction cle arDebug() { | |
| 268 | // i t would be nice to u se a memor y stream h ere to use | |
| 269 | // m emory more efficient ly | |
| 270 | $thi s->debug_s tr = ''; | |
| 271 | } | |
| 272 | ||
| 273 | /* * | |
| 274 | * gets the c urrent deb ug data fo r this ins tance | |
| 275 | * | |
| 276 | * @return debug data | |
| 277 | * @access public | |
| 278 | */ | |
| 279 | fu nction &ge tDebug() { | |
| 280 | // i t would be nice to u se a memor y stream h ere to use | |
| 281 | // m emory more efficient ly | |
| 282 | retu rn $this-> debug_str; | |
| 283 | } | |
| 284 | ||
| 285 | /* * | |
| 286 | * gets the c urrent deb ug data fo r this ins tance as a n XML comm ent | |
| 287 | * this may c hange the contents o f the debu g data | |
| 288 | * | |
| 289 | * @return debug data as an XML comment | |
| 290 | * @access public | |
| 291 | */ | |
| 292 | fu nction &ge tDebugAsXM LComment() { | |
| 293 | // i t would be nice to u se a memor y stream h ere to use | |
| 294 | // m emory more efficient ly | |
| 295 | whil e (strpos( $this->deb ug_str, '- -')) { | |
| 296 | $this- >debug_str = str_rep lace('--', '- -', $t his->debug _str); | |
| 297 | } | |
| 298 | $ret = "<!--\n " . $this- >debug_str . "\n-->" ; | |
| 299 | re turn $ret; | |
| 300 | } | |
| 301 | ||
| 302 | /* * | |
| 303 | * expands en tities, e. g. changes '<' to '& lt;'. | |
| 304 | * | |
| 305 | * @param string $val The string in which to expand entities. | |
| 306 | * @access privat e | |
| 307 | */ | |
| 308 | fu nction exp andEntitie s($val) { | |
| 309 | if ( $this->cha rencoding) { | |
| 310 | $val = str_rep lace('&', '&', $ val); | |
| 311 | $val = str_rep lace("'", ''', $val); | |
| 312 | $val = str_rep lace('"', '"', $val); | |
| 313 | $val = str_rep lace('<', '<', $v al); | |
| 314 | $val = str_rep lace('>', '>', $v al); | |
| 315 | } | |
| 316 | return $ val; | |
| 317 | } | |
| 318 | ||
| 319 | /* * | |
| 320 | * returns er ror string if presen t | |
| 321 | * | |
| 322 | * @return mixed erro r string o r false | |
| 323 | * @access public | |
| 324 | */ | |
| 325 | fu nction get Error(){ | |
| 326 | if($ this->erro r_str != ' '){ | |
| 327 | return $this->er ror_str; | |
| 328 | } | |
| 329 | retu rn false; | |
| 330 | } | |
| 331 | ||
| 332 | /* * | |
| 333 | * sets error string | |
| 334 | * | |
| 335 | * @return boolean $s tring erro r string | |
| 336 | * @access private | |
| 337 | */ | |
| 338 | fu nction set Error($str ){ | |
| 339 | $thi s->error_s tr = $str; | |
| 340 | } | |
| 341 | ||
| 342 | /* * | |
| 343 | * detect if array is a simple ar ray or a s truct (ass ociative a rray) | |
| 344 | * | |
| 345 | * @param mixed $val The PHP ar ray | |
| 346 | * @return string (arraySi mple|array Struct) | |
| 347 | * @access privat e | |
| 348 | */ | |
| 349 | fu nction isA rraySimple OrStruct($ val) { | |
| 350 | $k eyList = a rray_keys( $val); | |
| 351 | fore ach ($keyL ist as $ke yListValue ) { | |
| 352 | if (!i s_int($key ListValue) ) { | |
| 353 | return ' arrayStruc t'; | |
| 354 | } | |
| 355 | } | |
| 356 | retu rn 'arrayS imple'; | |
| 357 | } | |
| 358 | ||
| 359 | /* * | |
| 360 | * serializes PHP value s in accor dance w/ s ection 5. Type infor mation is | |
| 361 | * not serial ized if $u se == 'lit eral'. | |
| 362 | * | |
| 363 | * @param mixed $val The value to seriali ze | |
| 364 | * @param string $name The name ( local part ) of the X ML element | |
| 365 | * @param string $type The XML sc hema type (local par t) for the element | |
| 366 | * @param string $name_ns Th e namespac e for the name of th e XML elem ent | |
| 367 | * @param string $type_ns Th e namespac e for the type of th e element | |
| 368 | * @param array $attribu tes Th e attribut es to seri alize as n ame=>value pairs | |
| 369 | * @param string $use The WSDL " use" (enco ded|litera l) | |
| 370 | * @param boolea n $soapval Wh ether this is called from soap val. | |
| 371 | * @return string The seri alized ele ment, poss ibly with child elem ents | |
| 372 | * @acc ess publ ic | |
| 373 | */ | |
| 374 | fu nction ser ialize_val ($val,$nam e=false,$t ype=false, $name_ns=f alse,$type _ns=false, $attribute s=false,$u se='encode d',$soapva l=false) { | |
| 375 | $thi s->debug(" in seriali ze_val: na me=$name, type=$type , name_ns= $name_ns, type_ns=$t ype_ns, us e=$use, so apval=$soa pval"); | |
| 376 | $thi s->appendD ebug('valu e=' . $thi s->varDump ($val)); | |
| 377 | $thi s->appendD ebug('attr ibutes=' . $this->va rDump($att ributes)); | |
| 378 | ||
| 379 | if (is_objec t($val) && get_class ($val) == 'soapval' && (! $soa pval)) { | |
| 380 | $thi s->debug(" serialize_ val: seria lize soapv al"); | |
| 381 | $xml = $val->s erialize($ use); | |
| 382 | $this- >appendDeb ug($val->g etDebug()) ; | |
| 383 | $val-> clearDebug (); | |
| 384 | $this- >debug("se rialize_va l of soapv al returni ng $xml"); | |
| 385 | return $xml; | |
| 386 | } | |
| 387 | // f orce valid name if n ecessary | |
| 388 | if ( is_numeric ($name)) { | |
| 389 | $name = '__numer ic_' . $na me; | |
| 390 | } el seif (! $n ame) { | |
| 391 | $name = 'noname' ; | |
| 392 | } | |
| 393 | // i f name has ns, add n s prefix t o name | |
| 394 | $xml ns = ''; | |
| 395 | if ($name_ns) { | |
| 396 | //chan ged to use crypto_ra nd from ra nd for sec urity scan s - VLER E J VAD-1523 | |
| 397 | $prefi x = 'nu'.c rypto_rand (1000,9999 ,false); | |
| 398 | $name = $prefix. ':'.$name; | |
| 399 | $xmlns .= " xmln s:$prefix= \"$name_ns \""; | |
| 400 | } | |
| 401 | // i f type is prefixed, create typ e prefix | |
| 402 | if($ type_ns != '' && $ty pe_ns == $ this->name spaces['xs d']){ | |
| 403 | // nee d to fix t his. shoul dn't defau lt to xsd if no ns s pecified | |
| 404 | // w/o che cking agai nst typema p | |
| 405 | $type_ prefix = ' xsd'; | |
| 406 | } el seif($type _ns){ | |
| 407 | //chan ged to use crypto_ra nd from ra nd for sec urity scan s - VLER E J VAD-1523 | |
| 408 | $type_ prefix = ' ns'.crypto _rand(1000 ,9999,fals e); | |
| 409 | $xmlns .= " xmln s:$type_pr efix=\"$ty pe_ns\""; | |
| 410 | } | |
| 411 | // s erialize a ttributes if present | |
| 412 | $att s = ''; | |
| 413 | if($ attributes ){ | |
| 414 | foreac h($attribu tes as $k => $v){ | |
| 415 | $atts .= " $k=\"". $this->exp andEntitie s($v).'"'; | |
| 416 | } | |
| 417 | } | |
| 418 | // s erialize n ull value | |
| 419 | if ( is_null($v al)) { | |
| 420 | $thi s->debug(" serialize_ val: seria lize null" ); | |
| 421 | if ($u se == 'lit eral') { | |
| 422 | // TODO: depends o n minOccur s | |
| 423 | $xml = " <$name$xml ns$atts/>" ; | |
| 424 | $this->d ebug("seri alize_val returning $xml"); | |
| 425 | return $xml; | |
| 426 | } el se { | |
| 427 | if (isse t($type) & & isset($t ype_prefix )) { | |
| 428 | $type_str = " xsi:ty pe=\"$type _prefix:$t ype\""; | |
| 429 | } else { | |
| 430 | $type_str = ''; | |
| 431 | } | |
| 432 | $xml = " <$name$xml ns$type_st r$atts xsi :nil=\"tru e\"/>"; | |
| 433 | $this->d ebug("seri alize_val returning $xml"); | |
| 434 | return $xml; | |
| 435 | } | |
| 436 | } | |
| 437 | // serialize if an xsd built-in primitive type | |
| 438 | if ($type != '' && isse t($this->t ypemap[$th is->XMLSch emaVersion ][$type])) { | |
| 439 | $thi s->debug(" serialize_ val: seria lize xsd b uilt-in pr imitive ty pe"); | |
| 440 | if ( is_bool($v al)) { | |
| 441 | if ($t ype == 'bo olean') { | |
| 442 | $val = $ val ? 'tru e' : 'fals e'; | |
| 443 | } else if (! $val ) { | |
| 444 | $val = 0 ; | |
| 445 | } | |
| 446 | } else if (is_st ring($val) ) { | |
| 447 | $val = $ this->expa ndEntities ($val); | |
| 448 | } | |
| 449 | if ($u se == 'lit eral') { | |
| 450 | $xml = " <$name$xml ns$atts>$v al</$name> "; | |
| 451 | $this->d ebug("seri alize_val returning $xml"); | |
| 452 | return $xml; | |
| 453 | } el se { | |
| 454 | $xml = " <$name$xml ns xsi:typ e=\"xsd:$t ype\"$atts >$val</$na me>"; | |
| 455 | $this->d ebug("seri alize_val returning $xml"); | |
| 456 | return $xml; | |
| 457 | } | |
| 458 | } | |
| 459 | // d etect type and seria lize | |
| 460 | $xml = ''; | |
| 461 | swit ch(true) { | |
| 462 | case ( is_bool($v al) || $ty pe == 'boo lean'): | |
| 463 | $this->d ebug("seri alize_val: serialize boolean") ; | |
| 464 | if ($t ype == 'bo olean') { | |
| 465 | $val = $ val ? 'tru e' : 'fals e'; | |
| 466 | } else if (! $val ) { | |
| 467 | $val = 0 ; | |
| 468 | } | |
| 469 | if ($use == 'liter al') { | |
| 470 | $xml .= "< $name$xmln s$atts>$va l</$name>" ; | |
| 471 | } else { | |
| 472 | $xml .= "< $name$xmln s xsi:type =\"xsd:boo lean\"$att s>$val</$n ame>"; | |
| 473 | } | |
| 474 | break; | |
| 475 | case ( is_int($va l) || is_l ong($val) || $type = = 'int'): | |
| 476 | $this->d ebug("seri alize_val: serialize int"); | |
| 477 | if ($use == 'liter al') { | |
| 478 | $xml .= "< $name$xmln s$atts>$va l</$name>" ; | |
| 479 | } else { | |
| 480 | $xml .= "< $name$xmln s xsi:type =\"xsd:int \"$atts>$v al</$name> "; | |
| 481 | } | |
| 482 | break; | |
| 483 | case ( is_float($ val)|| is_ double($va l) || $typ e == 'floa t'): | |
| 484 | $this->d ebug("seri alize_val: serialize float"); | |
| 485 | if ($use == 'liter al') { | |
| 486 | $xml .= "< $name$xmln s$atts>$va l</$name>" ; | |
| 487 | } else { | |
| 488 | $xml .= "< $name$xmln s xsi:type =\"xsd:flo at\"$atts> $val</$nam e>"; | |
| 489 | } | |
| 490 | break; | |
| 491 | case ( is_string( $val) || $ type == 's tring'): | |
| 492 | $this->d ebug("seri alize_val: serialize string"); | |
| 493 | $val = $ this->expa ndEntities ($val); | |
| 494 | if ($use == 'liter al') { | |
| 495 | $xml .= "< $name$xmln s$atts>$va l</$name>" ; | |
| 496 | } else { | |
| 497 | $xml .= "< $name$xmln s xsi:type =\"xsd:str ing\"$atts >$val</$na me>"; | |
| 498 | } | |
| 499 | break; | |
| 500 | case i s_object($ val): | |
| 501 | $this->d ebug("seri alize_val: serialize object"); | |
| 502 | if (ge t_class($v al) == 'so apval') { | |
| 503 | $this->d ebug("seri alize_val: serialize soapval o bject"); | |
| 504 | $pXml = $val->seri alize($use ); | |
| 505 | $this->app endDebug($ val->getDe bug()); | |
| 506 | $val->clea rDebug(); | |
| 507 | } else { | |
| 508 | if (! $nam e) { | |
| 509 | $n ame = get_ class($val ); | |
| 510 | $t his->debug ("In seria lize_val, used class name $nam e as eleme nt name"); | |
| 511 | } else { | |
| 512 | $t his->debug ("In seria lize_val, do not ove rride name $name for element n ame for cl ass " . ge t_class($v al)); | |
| 513 | } | |
| 514 | foreach(ge t_object_v ars($val) as $k => $ v){ | |
| 515 | $p Xml = isse t($pXml) ? $pXml.$th is->serial ize_val($v ,$k,false, false,fals e,false,$u se) : $thi s->seriali ze_val($v, $k,false,f alse,false ,false,$us e); | |
| 516 | } | |
| 517 | } | |
| 518 | if(isset ($type) && isset($ty pe_prefix) ){ | |
| 519 | $type_str = " xsi:ty pe=\"$type _prefix:$t ype\""; | |
| 520 | } else { | |
| 521 | $type_str = ''; | |
| 522 | } | |
| 523 | if ($use == 'liter al') { | |
| 524 | $xml .= "< $name$xmln s$atts>$pX ml</$name> "; | |
| 525 | } else { | |
| 526 | $xml .= "< $name$xmln s$type_str $atts>$pXm l</$name>" ; | |
| 527 | } | |
| 528 | break; | |
| 529 | break; | |
| 530 | case ( is_array($ val) || $t ype): | |
| 531 | // detec t if struc t or array | |
| 532 | $valueTy pe = $this ->isArrayS impleOrStr uct($val); | |
| 533 | if($ valueType= ='arraySim ple' || pr eg_match(' /^ArrayOf/ ',$type)){ | |
| 534 | $this->deb ug("serial ize_val: s erialize a rray"); | |
| 535 | $i = 0; | |
| 536 | if(is_arra y($val) && count($va l)> 0){ | |
| 537 | fo reach($val as $v){ | |
| 538 | if(is_ob ject($v) & & get_clas s($v) == 'soapval') { | |
| 539 | $tt_ns = $v->typ e_ns; | |
| 540 | $tt = $v->type; | |
| 541 | } el seif (is_a rray($v)) { | |
| 542 | $tt = $this->isA rraySimple OrStruct($ v); | |
| 543 | } el se { | |
| 544 | $tt = gettype($v ); | |
| 545 | } | |
| 546 | $arr ay_types[$ tt] = 1; | |
| 547 | // T ODO: for l iteral, th e name sho uld be $na me | |
| 548 | $xml .= $this- >serialize _val($v,'i tem',false ,false,fal se,false,$ use); | |
| 549 | ++$i ; | |
| 550 | } | |
| 551 | if (count($ar ray_types) > 1){ | |
| 552 | $arr ay_typenam e = 'xsd:a nyType'; | |
| 553 | } elseif(iss et($tt) && isset($th is->typema p[$this->X MLSchemaVe rsion][$tt ])) { | |
| 554 | if ( $tt == 'in teger') { | |
| 555 | $tt = 'int'; | |
| 556 | } | |
| 557 | $arr ay_typenam e = 'xsd:' .$tt; | |
| 558 | } elseif(iss et($tt) && $tt == 'a rraySimple '){ | |
| 559 | $arr ay_typenam e = 'SOAP- ENC:Array' ; | |
| 560 | } elseif(iss et($tt) && $tt == 'a rrayStruct '){ | |
| 561 | $arr ay_typenam e = 'unnam ed_struct_ use_soapva l'; | |
| 562 | } else { | |
| 563 | // i f type is prefixed, create typ e prefix | |
| 564 | if ( $tt_ns != '' && $tt_ ns == $thi s->namespa ces['xsd'] ){ | |
| 565 | $arra y_typename = 'xsd:' . $tt; | |
| 566 | } el seif ($tt_ ns) { | |
| 567 | //chan ged to use crypto_ra nd from ra nd for sec urity scan s - VLER EJ VAD-152 3 | |
| 568 | $tt_pr efix = 'ns ' . crypto _rand(1000 , 9999,fal se); | |
| 569 | $array _typename = "$tt_pre fix:$tt"; | |
| 570 | $xmlns .= " xmln s:$tt_pref ix=\"$tt_n s\""; | |
| 571 | } el se { | |
| 572 | $array _typename = $tt; | |
| 573 | } | |
| 574 | } | |
| 575 | $a rray_type = $i; | |
| 576 | if ($use == 'literal') { | |
| 577 | $typ e_str = '' ; | |
| 578 | } else if (i sset($type ) && isset ($type_pre fix)) { | |
| 579 | $typ e_str = " xsi:type=\ "$type_pre fix:$type\ ""; | |
| 580 | } else { | |
| 581 | $typ e_str = " xsi:type=\ "SOAP-ENC: Array\" SO AP-ENC:arr ayType=\"" .$array_ty pename."[$ array_type ]\""; | |
| 582 | } | |
| 583 | // empty a rray | |
| 584 | } else { | |
| 585 | if ($use == 'literal') { | |
| 586 | $typ e_str = '' ; | |
| 587 | } else if (i sset($type ) && isset ($type_pre fix)) { | |
| 588 | $typ e_str = " xsi:type=\ "$type_pre fix:$type\ ""; | |
| 589 | } else { | |
| 590 | $typ e_str = " xsi:type=\ "SOAP-ENC: Array\" SO AP-ENC:arr ayType=\"x sd:anyType [0]\""; | |
| 591 | } | |
| 592 | } | |
| 593 | // TODO: f or array i n literal, there is no wrapper here | |
| 594 | $xml = "<$ name$xmlns $type_str$ atts>".$xm l."</$name >"; | |
| 595 | } else { | |
| 596 | // got a s truct | |
| 597 | $this->deb ug("serial ize_val: s erialize s truct"); | |
| 598 | if(isset($ type) && i sset($type _prefix)){ | |
| 599 | $t ype_str = " xsi:type =\"$type_p refix:$typ e\""; | |
| 600 | } else { | |
| 601 | $t ype_str = ''; | |
| 602 | } | |
| 603 | if ($use = = 'literal ') { | |
| 604 | $x ml .= "<$n ame$xmlns$ atts>"; | |
| 605 | } else { | |
| 606 | $x ml .= "<$n ame$xmlns$ type_str$a tts>"; | |
| 607 | } | |
| 608 | foreach($v al as $k = > $v){ | |
| 609 | // Apache Ma p | |
| 610 | if ($type == 'Map' && $type_ns = = 'http:// xml.apache .org/xml-s oap') { | |
| 611 | $xml .= '<item >'; | |
| 612 | $xml .= $this- >serialize _val($k,'k ey',false, false,fals e,false,$u se); | |
| 613 | $xml .= $this- >serialize _val($v,'v alue',fals e,false,fa lse,false, $use); | |
| 614 | $xml .= '</ite m>'; | |
| 615 | } else { | |
| 616 | $xml .= $this- >serialize _val($v,$k ,false,fal se,false,f alse,$use) ; | |
| 617 | } | |
| 618 | } | |
| 619 | $xml .= "< /$name>"; | |
| 620 | } | |
| 621 | break; | |
| 622 | defaul t: | |
| 623 | $this->d ebug("seri alize_val: serialize unknown") ; | |
| 624 | $xml .= 'not detec ted, got ' .gettype($ val).' for '.$val; | |
| 625 | break; | |
| 626 | } | |
| 627 | $thi s->debug(" serialize_ val return ing $xml") ; | |
| 628 | retu rn $xml; | |
| 629 | } | |
| 630 | ||
| 631 | /** | |
| 632 | * seri alizes a m essage | |
| 633 | * | |
| 634 | * @par am string $body the XML of the SOAP body | |
| 635 | * @par am mixed $ headers op tional str ing of XML with SOAP header co ntent, or array of s oapval obj ects for S OAP header s, or asso ciative ar ray | |
| 636 | * @par am array $ namespaces optional the namesp aces used in generat ing the bo dy and hea ders | |
| 637 | * @par am string $style opt ional (rpc |document) | |
| 638 | * @par am string $use optio nal (encod ed|literal ) | |
| 639 | * @par am string $encodingS tyle optio nal (usual ly 'http:/ /schemas.x mlsoap.org /soap/enco ding/' for encoded) | |
| 640 | * @ret urn string the messa ge | |
| 641 | * @acc ess public | |
| 642 | */ | |
| 643 | functi on seriali zeEnvelope ($body,$he aders=fals e,$namespa ces=array( ),$style=' rpc',$use= 'encoded', $encodingS tyle='http ://schemas .xmlsoap.o rg/soap/en coding/'){ | |
| 644 | // TOD O: add an option to automatica lly run ut f8_encode on $body a nd $header s | |
| 645 | // if $this->soa p_defencod ing is UTF -8. Not d oing this automatica lly allows | |
| 646 | // one to send a rbitrary U TF-8 chara cters, not just char acters tha t map to I SO-8859-1 | |
| 647 | ||
| 648 | $t his->debug ("In seria lizeEnvelo pe length= " . strlen ($body) . " body (ma x 1000 cha racters)=" . substr( $body, 0, 1000) . " style=$sty le use=$us e encoding Style=$enc odingStyle "); | |
| 649 | $t his->debug ("headers: "); | |
| 650 | $t his->appen dDebug($th is->varDum p($headers )); | |
| 651 | $t his->debug ("namespac es:"); | |
| 652 | $t his->appen dDebug($th is->varDum p($namespa ces)); | |
| 653 | ||
| 654 | // serialize namespace s | |
| 655 | $ns_st ring = ''; | |
| 656 | fo reach(arra y_merge($t his->names paces,$nam espaces) a s $k => $v ){ | |
| 657 | $ns_ string .= " xmlns:$k =\"$v\""; | |
| 658 | } | |
| 659 | if ($encoding Style) { | |
| 660 | $ns_ string = " SOAP-ENV: encodingSt yle=\"$enc odingStyle \"$ns_stri ng"; | |
| 661 | } | |
| 662 | ||
| 663 | // serialize headers | |
| 664 | if ($headers) { | |
| 665 | if ( is_array($ headers)) { | |
| 666 | $xml = ''; | |
| 667 | foreac h ($header s as $k => $v) { | |
| 668 | if (is_o bject($v) && get_cla ss($v) == 'soapval') { | |
| 669 | $xml .= $t his->seria lize_val($ v, false, false, fal se, false, false, $u se); | |
| 670 | } else { | |
| 671 | $xml .= $t his->seria lize_val($ v, $k, fal se, false, false, fa lse, $use) ; | |
| 672 | } | |
| 673 | } | |
| 674 | $heade rs = $xml; | |
| 675 | $this- >debug("In serialize Envelope, serialized array of headers to $headers" ); | |
| 676 | } | |
| 677 | $hea ders = "<S OAP-ENV:He ader>".$he aders."</S OAP-ENV:He ader>"; | |
| 678 | } | |
| 679 | // serialize envelope | |
| 680 | re turn | |
| 681 | '< ?xml versi on="1.0" e ncoding="' .$this->so ap_defenco ding .'"?' .">". | |
| 682 | '< SOAP-ENV:E nvelope'.$ ns_string. ">". | |
| 683 | $h eaders. | |
| 684 | "< SOAP-ENV:B ody>". | |
| 685 | $bod y. | |
| 686 | "< /SOAP-ENV: Body>". | |
| 687 | "< /SOAP-ENV: Envelope>" ; | |
| 688 | } | |
| 689 | ||
| 690 | /* * | |
| 691 | * contracts (changes n amespace t o prefix) a qualifie d name | |
| 692 | * | |
| 693 | * @param string $qn ame qname | |
| 694 | * @return string contracte d qname | |
| 695 | * @access private | |
| 696 | */ | |
| 697 | fu nction con tractQname ($qname){ | |
| 698 | // g et element namespace | |
| 699 | //$t his->xdebu g("Contrac t $qname") ; | |
| 700 | if ( strrpos($q name, ':') ) { | |
| 701 | // get unqualifi ed name | |
| 702 | $name = substr($ qname, str rpos($qnam e, ':') + 1); | |
| 703 | // get ns | |
| 704 | $ns = substr($qn ame, 0, st rrpos($qna me, ':')); | |
| 705 | $p = $ this->getP refixFromN amespace($ ns); | |
| 706 | if ($p ) { | |
| 707 | return $ p . ':' . $name; | |
| 708 | } | |
| 709 | return $qname; | |
| 710 | } el se { | |
| 711 | return $qname; | |
| 712 | } | |
| 713 | } | |
| 714 | ||
| 715 | /* * | |
| 716 | * expands (c hanges pre fix to nam espace) a qualified name | |
| 717 | * | |
| 718 | * @param string $qn ame qname | |
| 719 | * @return string expanded qname | |
| 720 | * @access private | |
| 721 | */ | |
| 722 | fu nction exp andQname($ qname){ | |
| 723 | // g et element prefix | |
| 724 | if(s trpos($qna me,':') && !preg_mat ch('/^http :\/\//',$q name)){ | |
| 725 | // get unqualifi ed name | |
| 726 | $name = substr(s trstr($qna me,':'),1) ; | |
| 727 | // get ns prefix | |
| 728 | $prefi x = substr ($qname,0, strpos($qn ame,':')); | |
| 729 | if(iss et($this-> namespaces [$prefix]) ){ | |
| 730 | return $ this->name spaces[$pr efix].':'. $name; | |
| 731 | } else { | |
| 732 | return $ qname; | |
| 733 | } | |
| 734 | } el se { | |
| 735 | return $qname; | |
| 736 | } | |
| 737 | } | |
| 738 | ||
| 739 | /** | |
| 740 | * retu rns the lo cal part o f a prefix ed string | |
| 741 | * retu rns the or iginal str ing, if no t prefixed | |
| 742 | * | |
| 743 | * @par am string $str The p refixed st ring | |
| 744 | * @ret urn string The local part | |
| 745 | * @acc ess public | |
| 746 | */ | |
| 747 | fu nction get LocalPart( $str){ | |
| 748 | if($ sstr = str rchr($str, ':')){ | |
| 749 | // get unqualifi ed name | |
| 750 | return substr( $ sstr, 1 ); | |
| 751 | } el se { | |
| 752 | return $str; | |
| 753 | } | |
| 754 | } | |
| 755 | ||
| 756 | /* * | |
| 757 | * retu rns the pr efix part of a prefi xed string | |
| 758 | * retu rns false, if not pr efixed | |
| 759 | * | |
| 760 | * @par am string $str The p refixed st ring | |
| 761 | * @ret urn mixed The prefix or false if there i s no prefi x | |
| 762 | * @acc ess public | |
| 763 | */ | |
| 764 | fu nction get Prefix($st r){ | |
| 765 | if($ pos = strr pos($str,' :')){ | |
| 766 | // get prefix | |
| 767 | return substr($s tr,0,$pos) ; | |
| 768 | } | |
| 769 | retu rn false; | |
| 770 | } | |
| 771 | ||
| 772 | /* * | |
| 773 | * pass it a pref ix, it ret urns a nam espace | |
| 774 | * | |
| 775 | * @par am string $prefix Th e prefix | |
| 776 | * @ret urn mixed The namesp ace, false if no nam espace has the speci fied prefi x | |
| 777 | * @acc ess public | |
| 778 | */ | |
| 779 | fu nction get NamespaceF romPrefix( $prefix){ | |
| 780 | if ( isset($thi s->namespa ces[$prefi x])) { | |
| 781 | return $this->na mespaces[$ prefix]; | |
| 782 | } | |
| 783 | //$t his->setEr ror("No na mespace re gistered f or prefix '$prefix'" ); | |
| 784 | retu rn false; | |
| 785 | } | |
| 786 | ||
| 787 | /* * | |
| 788 | * retu rns the pr efix for a given nam espace (or prefix) | |
| 789 | * or f alse if no prefixes registered for the g iven names pace | |
| 790 | * | |
| 791 | * @par am string $ns The na mespace | |
| 792 | * @ret urn mixed The prefix , false if the names pace has n o prefixes | |
| 793 | * @acc ess public | |
| 794 | */ | |
| 795 | fu nction get PrefixFrom Namespace( $ns) { | |
| 796 | fore ach ($this ->namespac es as $p = > $n) { | |
| 797 | if ($n s == $n || $ns == $p ) { | |
| 798 | $t his->usedN amespaces[ $p] = $n; | |
| 799 | return $ p; | |
| 800 | } | |
| 801 | } | |
| 802 | retu rn false; | |
| 803 | } | |
| 804 | ||
| 805 | /* * | |
| 806 | * retu rns the ti me in ODBC canonical form with microseco nds | |
| 807 | * | |
| 808 | * @ret urn string The time in ODBC ca nonical fo rm with mi croseconds | |
| 809 | * @acc ess public | |
| 810 | */ | |
| 811 | fu nction get microtime( ) { | |
| 812 | if ( function_e xists('get timeofday' )) { | |
| 813 | $tod = gettimeof day(); | |
| 814 | $sec = $tod['sec ']; | |
| 815 | $usec = $tod['us ec']; | |
| 816 | } el se { | |
| 817 | $sec = time(); | |
| 818 | $usec = 0; | |
| 819 | } | |
| 820 | retu rn strftim e('%Y-%m-% d %H:%M:%S ', $sec) . '.' . spr intf('%06d ', $usec); | |
| 821 | } | |
| 822 | ||
| 823 | /* * | |
| 824 | * Returns a string wi th the out put of var _dump | |
| 825 | * | |
| 826 | * @param mi xed $data The variab le to var_ dump | |
| 827 | * @return s tring The output of var_dump | |
| 828 | * @access p ublic | |
| 829 | * / | |
| 830 | functi on varDump ($data) { | |
| 831 | ob_s tart(); | |
| 832 | ||
| 833 | //wh ile there is a scena rio where we may wan t this for debug, th is is comm ented out unless act ively need ed for deb ugging to prevent se curity con cerns -- V LER ATB | |
| 834 | ||
| 835 | //no te - the c ombination of ob_sta rt + ob_ge t_contents () means t hat the ou tput of va r_dump wil l be store d in $ret_ val and NO T output t o the scre en. | |
| 836 | //th ere's no a ctual need to commen t this out , though i t doesn't hurt. -- VLER MG 20 15/04/06 | |
| 837 | ||
| 838 | //va r_dump($da ta); | |
| 839 | ||
| 840 | //$r et_val = o b_get_cont ents(); | |
| 841 | $ret _val = 'Un comment va r_dump to enable det ailed debu gging, dis abled for security r easons.'; | |
| 842 | ob_e nd_clean() ; | |
| 843 | retu rn $ret_va l; | |
| 844 | } | |
| 845 | ||
| 846 | /* * | |
| 847 | * represents the objec t as a str ing | |
| 848 | * | |
| 849 | * @return string | |
| 850 | * @access public | |
| 851 | */ | |
| 852 | fu nction __t oString() { | |
| 853 | retu rn $this-> varDump($t his); | |
| 854 | } | |
| 855 | } | |
| 856 | ||
| 857 | // XML Sch ema Dataty pe Helper Functions | |
| 858 | ||
| 859 | //xsd:date Time helpe rs | |
| 860 | ||
| 861 | /** | |
| 862 | * convert unix times tamp to IS O 8601 com pliant dat e string | |
| 863 | * | |
| 864 | * @param int $tim estamp Uni x time sta mp | |
| 865 | * @param bool ean $utc W hether the time stam p is UTC o r local | |
| 866 | * @return mixe d ISO 8601 date stri ng or fals e | |
| 867 | * @access public | |
| 868 | */ | |
| 869 | function t imestamp_t o_iso8601( $timestamp ,$utc=true ){ | |
| 870 | $d atestr = d ate('Y-m-d \TH:i:sO', $timestamp ); | |
| 871 | $p os = strrp os($datest r, "+"); | |
| 872 | if ($pos === FALSE) { | |
| 873 | $pos = strrpos ($datestr, "-"); | |
| 874 | } | |
| 875 | if ($pos !== FALSE) { | |
| 876 | if ( strlen($da testr) == $pos + 5) { | |
| 877 | $dates tr = subst r($datestr , 0, $pos + 3) . ':' . substr( $datestr, -2); | |
| 878 | } | |
| 879 | } | |
| 880 | if ($utc){ | |
| 881 | $pat tern = '/' . | |
| 882 | '([0 -9]{4})-'. // centu ries & yea rs CCYY- | |
| 883 | '([0 -9]{2})-'. // month s MM- | |
| 884 | '([0 -9]{2})'. // days DD | |
| 885 | 'T'. // separat or T | |
| 886 | '([0 -9]{2}):'. // hours hh: | |
| 887 | '([0 -9]{2}):'. // minut es mm: | |
| 888 | '([0 -9]{2})(\. [0-9]*)?'. // second s ss.ss... | |
| 889 | '(Z| [+\-][0-9] {2}:?[0-9] {2})?'. // Z to indi cate UTC, -/+HH:MM:S S.SS... fo r local tz 's | |
| 890 | '/'; | |
| 891 | ||
| 892 | if(p reg_match( $pattern,$ datestr,$r egs)){ | |
| 893 | return sprintf(' %04d-%02d- %02dT%02d: %02d:%02dZ ',$regs[1] ,$regs[2], $regs[3],$ regs[4],$r egs[5],$re gs[6]); | |
| 894 | } | |
| 895 | retu rn false; | |
| 896 | } else { | |
| 897 | retu rn $datest r; | |
| 898 | } | |
| 899 | } | |
| 900 | ||
| 901 | /** | |
| 902 | ||
| 903 | * convert ISO 8601 c ompliant d ate string to unix t imestamp | |
| 904 | * | |
| 905 | * @param string $ datestr IS O 8601 com pliant dat e string | |
| 906 | * @return mixe d Unix tim estamp (in t) or fals e | |
| 907 | * @access public | |
| 908 | */ | |
| 909 | function i so8601_to_ timestamp( $datestr){ | |
| 910 | $p attern = ' /'. | |
| 911 | '( [0-9]{4})- '. // cen turies & y ears CCYY- | |
| 912 | '( [0-9]{2})- '. // mon ths MM- | |
| 913 | '( [0-9]{2})' . // day s DD | |
| 914 | 'T '. // separ ator T | |
| 915 | '( [0-9]{2}): '. // hou rs hh: | |
| 916 | '( [0-9]{2}): '. // min utes mm: | |
| 917 | '( [0-9]{2})( \.[0-9]+)? '. // seco nds ss.ss. .. | |
| 918 | '( Z|[+\-][0- 9]{2}:?[0- 9]{2})?'. // Z to in dicate UTC , -/+HH:MM :SS.SS... for local tz's | |
| 919 | '/ '; | |
| 920 | if (preg_matc h($pattern ,$datestr, $regs)){ | |
| 921 | // n ot utc | |
| 922 | if($ regs[8] != 'Z'){ | |
| 923 | $op = substr($re gs[8],0,1) ; | |
| 924 | $h = s ubstr($reg s[8],1,2); | |
| 925 | $m = s ubstr($reg s[8],strle n($regs[8] )-2,2); | |
| 926 | if($op == '-'){ | |
| 927 | $regs[4] = $regs[4 ] + $h; | |
| 928 | $regs[5] = $regs[5 ] + $m; | |
| 929 | } else if($op == '+'){ | |
| 930 | $regs[4] = $regs[4 ] - $h; | |
| 931 | $regs[5] = $regs[5 ] - $m; | |
| 932 | } | |
| 933 | } | |
| 934 | retu rn gmmktim e($regs[4] , $regs[5] , $regs[6] , $regs[2] , $regs[3] , $regs[1] ); | |
| 935 | } else { | |
| 936 | retu rn false; | |
| 937 | } | |
| 938 | } | |
| 939 | ||
| 940 | /** | |
| 941 | * Contains informati on for a S OAP fault. | |
| 942 | * Mainly u sed for re turning fa ults from deployed f unctions | |
| 943 | * in a ser ver instan ce. | |
| 944 | * @author Dietrich Ayala <di etrich@gan x4.com> | |
| 945 | * @version $Id: nus oap.php,v 1.123 2010 /04/26 20: 15:08 snic hol Exp $ | |
| 946 | * @access public | |
| 947 | * @package third-par ty | |
| 948 | * @subpack age nusoap | |
| 949 | */ | |
| 950 | class nuso ap_fault e xtends nus oap_base { | |
| 951 | /* * | |
| 952 | * The fault code (cli ent|server ) | |
| 953 | * @var stri ng | |
| 954 | * @access p rivate | |
| 955 | * / | |
| 956 | va r $faultco de; | |
| 957 | /* * | |
| 958 | * The fault actor | |
| 959 | * @var stri ng | |
| 960 | * @access p rivate | |
| 961 | * / | |
| 962 | va r $faultac tor; | |
| 963 | /* * | |
| 964 | * The fault string, a descripti on of the fault | |
| 965 | * @var stri ng | |
| 966 | * @access p rivate | |
| 967 | * / | |
| 968 | va r $faultst ring; | |
| 969 | /* * | |
| 970 | * The fault detail, t ypically a string or array of string | |
| 971 | * @var mixe d | |
| 972 | * @access p rivate | |
| 973 | * / | |
| 974 | va r $faultde tail; | |
| 975 | ||
| 976 | /* * | |
| 977 | * constructo r | |
| 978 | * | |
| 979 | * @par am string $faultcode (SOAP-ENV :Client | SOAP-ENV:S erver) | |
| 980 | * @par am string $faultacto r only use d when msg routed be tween mult iple actor s | |
| 981 | * @par am string $faultstri ng human r eadable er ror messag e | |
| 982 | * @par am mixed $ faultdetai l detail, typically a string o r array of string | |
| 983 | */ | |
| 984 | fu nction nus oap_fault( $faultcode ,$faultact or='',$fau ltstring=' ',$faultde tail=''){ | |
| 985 | pare nt::nusoap _base(); | |
| 986 | $thi s->faultco de = $faul tcode; | |
| 987 | $thi s->faultac tor = $fau ltactor; | |
| 988 | $thi s->faultst ring = $fa ultstring; | |
| 989 | $thi s->faultde tail = $fa ultdetail; | |
| 990 | } | |
| 991 | ||
| 992 | /* * | |
| 993 | * serialize a fault | |
| 994 | * | |
| 995 | * @return string The seri alization of the fau lt instanc e. | |
| 996 | * @access public | |
| 997 | */ | |
| 998 | fu nction ser ialize(){ | |
| 999 | $ns_ string = ' '; | |
| 1000 | fore ach($this- >namespace s as $k => $v){ | |
| 1001 | $ns_st ring .= "\ n xmlns:$ k=\"$v\""; | |
| 1002 | } | |
| 1003 | $ret urn_msg = | |
| 1004 | '<?xml version=" 1.0" encod ing="'.$th is->soap_d efencoding .'"?>'. | |
| 1005 | '<SOAP -ENV:Envel ope SOAP-E NV:encodin gStyle="ht tp://schem as.xmlsoap .org/soap/ encoding/" '.$ns_stri ng.">\n". | |
| 1006 | '<SOAP-E NV:Body>'. | |
| 1007 | '<SOAP-E NV:Fault>' . | |
| 1008 | $this->ser ialize_val ($this->fa ultcode, ' faultcode' ). | |
| 1009 | $this->ser ialize_val ($this->fa ultactor, 'faultacto r'). | |
| 1010 | $this->ser ialize_val ($this->fa ultstring, 'faultstr ing'). | |
| 1011 | $this->ser ialize_val ($this->fa ultdetail, 'detail') . | |
| 1012 | '</SOAP- ENV:Fault> '. | |
| 1013 | '</SOAP- ENV:Body>' . | |
| 1014 | '</SOA P-ENV:Enve lope>'; | |
| 1015 | retu rn $return _msg; | |
| 1016 | } | |
| 1017 | } | |
| 1018 | ||
| 1019 | /** | |
| 1020 | * Backward compatibi lity | |
| 1021 | * @package third-par ty | |
| 1022 | * @subpack age nusoap | |
| 1023 | */ | |
| 1024 | class soap _fault ext ends nusoa p_fault { | |
| 1025 | } | |
| 1026 | ||
| 1027 | /** | |
| 1028 | * parses a n XML Sche ma, allows access to it's data , other ut ility meth ods. | |
| 1029 | * imperfec t, no vali dation... yet, but q uite funct ional. | |
| 1030 | * | |
| 1031 | * @author Dietrich Ayala <di etrich@gan x4.com> | |
| 1032 | * @author Scott Ni chol <snic hol@users. sourceforg e.net> | |
| 1033 | * @version $Id: nus oap.php,v 1.123 2010 /04/26 20: 15:08 snic hol Exp $ | |
| 1034 | * @access public | |
| 1035 | * @package third-par ty | |
| 1036 | * @subpack age nusoap | |
| 1037 | */ | |
| 1038 | class nuso ap_xmlsche ma extends nusoap_ba se { | |
| 1039 | ||
| 1040 | // files | |
| 1041 | va r $schema = ''; | |
| 1042 | va r $xml = ' '; | |
| 1043 | // namespace s | |
| 1044 | va r $enclosi ngNamespac es; | |
| 1045 | // schema in fo | |
| 1046 | va r $schemaI nfo = arra y(); | |
| 1047 | va r $schemaT argetNames pace = ''; | |
| 1048 | // types, el ements, at tributes d efined by the schema | |
| 1049 | va r $attribu tes = arra y(); | |
| 1050 | va r $complex Types = ar ray(); | |
| 1051 | va r $complex TypeStack = array(); | |
| 1052 | va r $current ComplexTyp e = null; | |
| 1053 | va r $element s = array( ); | |
| 1054 | va r $element Stack = ar ray(); | |
| 1055 | va r $current Element = null; | |
| 1056 | va r $simpleT ypes = arr ay(); | |
| 1057 | va r $simpleT ypeStack = array(); | |
| 1058 | va r $current SimpleType = null; | |
| 1059 | // imports | |
| 1060 | va r $imports = array() ; | |
| 1061 | // parser va rs | |
| 1062 | va r $parser; | |
| 1063 | va r $positio n = 0; | |
| 1064 | va r $depth = 0; | |
| 1065 | va r $depth_a rray = arr ay(); | |
| 1066 | va r $message = array() ; | |
| 1067 | va r $default Namespace = array(); | |
| 1068 | ||
| 1069 | /* * | |
| 1070 | * constructo r | |
| 1071 | * | |
| 1072 | * @param string $sc hema schem a document URI | |
| 1073 | * @param string $xm l xml docu ment URI | |
| 1074 | * @param string $namespac es namespa ces define d in enclo sing XML | |
| 1075 | * @access public | |
| 1076 | */ | |
| 1077 | fu nction nus oap_xmlsch ema($schem a='',$xml= '',$namesp aces=array ()){ | |
| 1078 | pare nt::nusoap _base(); | |
| 1079 | $thi s->debug(' nusoap_xml schema cla ss instant iated, ins ide constr uctor'); | |
| 1080 | // f iles | |
| 1081 | $thi s->schema = $schema; | |
| 1082 | $thi s->xml = $ xml; | |
| 1083 | ||
| 1084 | // n amespaces | |
| 1085 | $thi s->enclosi ngNamespac es = $name spaces; | |
| 1086 | $thi s->namespa ces = arra y_merge($t his->names paces, $na mespaces); | |
| 1087 | ||
| 1088 | // p arse schem a file | |
| 1089 | if($ schema != ''){ | |
| 1090 | $this- >debug('in itial sche ma file: ' .$schema); | |
| 1091 | $this- >parseFile ($schema, 'schema'); | |
| 1092 | } | |
| 1093 | ||
| 1094 | // p arse xml f ile | |
| 1095 | if($ xml != '') { | |
| 1096 | $this- >debug('in itial xml file: '.$x ml); | |
| 1097 | $this- >parseFile ($xml, 'xm l'); | |
| 1098 | } | |
| 1099 | ||
| 1100 | } | |
| 1101 | ||
| 1102 | /** | |
| 1103 | * pars e an XML f ile | |
| 1104 | * | |
| 1105 | * @par am string $xml path/ URL to XML file | |
| 1106 | * @par am string $type (sch ema | xml) | |
| 1107 | * @return bo olean | |
| 1108 | * @acc ess public | |
| 1109 | */ | |
| 1110 | fu nction par seFile($xm l,$type){ | |
| 1111 | // p arse xml f ile | |
| 1112 | if($ xml != "") { | |
| 1113 | $xmlSt r = @join( "",@file($ xml)); | |
| 1114 | if($xm lStr == "" ){ | |
| 1115 | $msg = ' Error read ing XML fr om '.$xml; | |
| 1116 | $this->s etError($m sg); | |
| 1117 | $this->d ebug($msg) ; | |
| 1118 | return false; | |
| 1119 | } else { | |
| 1120 | $this->d ebug("pars ing $xml") ; | |
| 1121 | $this->p arseString ($xmlStr,$ type); | |
| 1122 | $this->d ebug("done parsing $ xml"); | |
| 1123 | return true; | |
| 1124 | } | |
| 1125 | } | |
| 1126 | retu rn false; | |
| 1127 | } | |
| 1128 | ||
| 1129 | /* * | |
| 1130 | * parse an X ML string | |
| 1131 | * | |
| 1132 | * @param string $xm l path or URL | |
| 1133 | * @par am stri ng $type ( schema|xml ) | |
| 1134 | * @access private | |
| 1135 | */ | |
| 1136 | fu nction par seString($ xml,$type) { | |
| 1137 | ||
| 1138 | if(e mpty($xml) ){ | |
| 1139 | $this- >debug('no xml passe d to parse String()!! '); | |
| 1140 | $this- >setError( 'no xml pa ssed to pa rseString( )!!'); | |
| 1141 | return ; | |
| 1142 | } | |
| 1143 | ||
| 1144 | // p arse xml s tring | |
| 1145 | ||
| 1146 | //Fo rtify scan s don't li ke the XML parsing, and we sho uldn't eve r hit this code, so I'm commen ting it ou t. | |
| 1147 | //If we need t his later, we'll nee d to come up with a justificat ion as to why it's n ot a secur ity flaw ( or improve it in som e way) -- VLER MG 20 15/04/07 V AD-1497 | |
| 1148 | trig ger_error( "The parse String has currently been disa bled in nu soap_xmlsc hema due t o security concerns. If you're seeing th is message , it's tim e to come up with a better sec urity solu tion.", E_ USER_NOTIC E); | |
| 1149 | /* // C reate an X ML parser. | |
| 1150 | $thi s->parser = xml_pars er_create( ); | |
| 1151 | // S et the opt ions for p arsing the XML data. | |
| 1152 | xml_ parser_set _option($t his->parse r, XML_OPT ION_CASE_F OLDING, 0) ; | |
| 1153 | ||
| 1154 | // S et the obj ect for th e parser. | |
| 1155 | xml_ set_object ($this->pa rser, $thi s); | |
| 1156 | ||
| 1157 | // S et the ele ment handl ers for th e parser. | |
| 1158 | if($ type == "s chema"){ | |
| 1159 | xml_se t_element_ handler($t his->parse r, 'schema StartEleme nt','schem aEndElemen t'); | |
| 1160 | xml_se t_characte r_data_han dler($this ->parser,' schemaChar acterData' ); | |
| 1161 | } el seif($type == "xml") { | |
| 1162 | xml_se t_element_ handler($t his->parse r, 'xmlSta rtElement' ,'xmlEndEl ement'); | |
| 1163 | xml_se t_characte r_data_han dler($this ->parser,' xmlCharact erData'); | |
| 1164 | } | |
| 1165 | ||
| 1166 | // P arse the X ML file. | |
| 1167 | if(! xml_parse( $this->par ser,$xml,t rue)){ | |
| 1168 | // D isplay an error mess age. | |
| 1169 | $errst r = sprint f('XML err or parsing XML schem a on line %d: %s', | |
| 1170 | xml_ge t_current_ line_numbe r($this->p arser), | |
| 1171 | xml_er ror_string (xml_get_e rror_code( $this->par ser)) | |
| 1172 | ); | |
| 1173 | $this- >debug($er rstr); | |
| 1174 | $this- >debug("XM L payload: \n" . $xml ); | |
| 1175 | $this- >setError( $errstr); | |
| 1176 | } | |
| 1177 | ||
| 1178 | xml_ parser_fre e($this->p arser); */ | |
| 1179 | } | |
| 1180 | ||
| 1181 | /* * | |
| 1182 | * gets a ty pe name fo r an unnam ed type | |
| 1183 | * | |
| 1184 | * @param string Element name | |
| 1185 | * @return string A type n ame for an unnamed t ype | |
| 1186 | * @access privat e | |
| 1187 | * / | |
| 1188 | fu nction Cre ateTypeNam e($ename) { | |
| 1189 | $sco pe = ''; | |
| 1190 | for ($i = 0; $ i < count( $this->com plexTypeSt ack); $i++ ) { | |
| 1191 | $scope .= $this- >complexTy peStack[$i ] . '_'; | |
| 1192 | } | |
| 1193 | retu rn $scope . $ename . '_Contain edType'; | |
| 1194 | } | |
| 1195 | ||
| 1196 | /* * | |
| 1197 | * start-elem ent handle r | |
| 1198 | * | |
| 1199 | * @param string $pa rser XML p arser obje ct | |
| 1200 | * @param string $na me element name | |
| 1201 | * @param string $at trs associ ative arra y of attri butes | |
| 1202 | * @access private | |
| 1203 | */ | |
| 1204 | fu nction sch emaStartEl ement($par ser, $name , $attrs) { | |
| 1205 | ||
| 1206 | // p osition in the total number of elements, starting from 0 | |
| 1207 | $pos = $this-> position++ ; | |
| 1208 | $dep th = $this ->depth++; | |
| 1209 | // s et self as current v alue for t his depth | |
| 1210 | $thi s->depth_a rray[$dept h] = $pos; | |
| 1211 | $thi s->message [$pos] = a rray('cdat a' => ''); | |
| 1212 | if ( $depth > 0 ) { | |
| 1213 | $this- >defaultNa mespace[$p os] = $thi s->default Namespace[ $this->dep th_array[$ depth - 1] ]; | |
| 1214 | } el se { | |
| 1215 | $this- >defaultNa mespace[$p os] = fals e; | |
| 1216 | } | |
| 1217 | ||
| 1218 | // g et element prefix | |
| 1219 | if($ prefix = $ this->getP refix($nam e)){ | |
| 1220 | // get unqualifi ed name | |
| 1221 | $name = $this->g etLocalPar t($name); | |
| 1222 | } el se { | |
| 1223 | $pre fix = ''; | |
| 1224 | } | |
| 1225 | ||
| 1226 | // loop thru attribute s, expandi ng, and re gistering namespace declaratio ns | |
| 1227 | if (count($at trs) > 0){ | |
| 1228 | fore ach($attrs as $k => $v){ | |
| 1229 | // i f ns decla rations, a dd to clas s level ar ray of val id namespa ces | |
| 1230 | if(preg_ match('/^x mlns/',$k) ){ | |
| 1231 | //$thi s->xdebug( "$k: $v"); | |
| 1232 | //$thi s->xdebug( 'ns_prefix : '.$this- >getPrefix ($k)); | |
| 1233 | if($ns _prefix = substr(str rchr($k,': '),1)){ | |
| 1234 | //$this- >xdebug("A dd namespa ce[$ns_pre fix] = $v" ); | |
| 1235 | $t his->names paces[$ns_ prefix] = $v; | |
| 1236 | } else { | |
| 1237 | $t his->defau ltNamespac e[$pos] = $v; | |
| 1238 | if (! $this- >getPrefix FromNamesp ace($v)) { | |
| 1239 | $thi s->namespa ces['ns'.( count($thi s->namespa ces)+1)] = $v; | |
| 1240 | } | |
| 1241 | } | |
| 1242 | if($v == ' http://www .w3.org/20 01/XMLSche ma' || $v == 'http:/ /www.w3.or g/1999/XML Schema' || $v == 'ht tp://www.w 3.org/2000 /10/XMLSch ema'){ | |
| 1243 | $t his->XMLSc hemaVersio n = $v; | |
| 1244 | $t his->names paces['xsi '] = $v.'- instance'; | |
| 1245 | } | |
| 1246 | } | |
| 1247 | } | |
| 1248 | fore ach($attrs as $k => $v){ | |
| 1249 | // e xpand each attribute | |
| 1250 | $k = strpos($k ,':') ? $t his->expan dQname($k) : $k; | |
| 1251 | $v = strpos($v ,':') ? $t his->expan dQname($v) : $v; | |
| 1252 | $eAttr s[$k] = $v ; | |
| 1253 | } | |
| 1254 | $att rs = $eAtt rs; | |
| 1255 | } else { | |
| 1256 | $att rs = array (); | |
| 1257 | } | |
| 1258 | // f ind status , register data | |
| 1259 | swit ch($name){ | |
| 1260 | case ' all': // ( optional) compositor content f or a compl exType | |
| 1261 | case ' choice': | |
| 1262 | case ' group': | |
| 1263 | case ' sequence': | |
| 1264 | $this->c omplexType s[$this->c urrentComp lexType][' compositor '] = $name ; | |
| 1265 | break; | |
| 1266 | case ' attribute' : // complexTy pe attribu te | |
| 1267 | $thi s->xdebug( "parsing a ttribute:" ); | |
| 1268 | $thi s->appendD ebug($this ->varDump( $attrs)); | |
| 1269 | if (!iss et($attrs[ 'form'])) { | |
| 1270 | // TODO: h andle glob als | |
| 1271 | $attrs['fo rm'] = $th is->schema Info['attr ibuteFormD efault']; | |
| 1272 | } | |
| 1273 | if ( isset($att rs['http:/ /schemas.x mlsoap.org /wsdl/:arr ayType'])) { | |
| 1274 | $v = $attr s['http:// schemas.xm lsoap.org/ wsdl/:arra yType']; | |
| 1275 | if (!strpo s($v, ':') ) { | |
| 1276 | // no namesp ace in arr ayType att ribute val ue... | |
| 1277 | if ($this->d efaultName space[$pos ]) { | |
| 1278 | // . ..so use t he default | |
| 1279 | $att rs['http:/ /schemas.x mlsoap.org /wsdl/:arr ayType'] = $this->de faultNames pace[$pos] . ':' . $ attrs['htt p://schema s.xmlsoap. org/wsdl/: arrayType' ]; | |
| 1280 | } | |
| 1281 | } | |
| 1282 | } | |
| 1283 | if(i sset($attr s['name']) ){ | |
| 1284 | $this->att ributes[$a ttrs['name ']] = $att rs; | |
| 1285 | $aname = $ attrs['nam e']; | |
| 1286 | } elseif (isset($at trs['ref'] ) && $attr s['ref'] = = 'http:// schemas.xm lsoap.org/ soap/encod ing/:array Type'){ | |
| 1287 | if (isset( $attrs['ht tp://schem as.xmlsoap .org/wsdl/ :arrayType '])) { | |
| 1288 | $aname = $attrs['h ttp://sche mas.xmlsoa p.org/wsdl /:arrayTyp e']; | |
| 1289 | } else { | |
| 1290 | $aname = ''; | |
| 1291 | } | |
| 1292 | } elseif (isset($at trs['ref'] )){ | |
| 1293 | $aname = $ attrs['ref ']; | |
| 1294 | $this->att ributes[$a ttrs['ref' ]] = $attr s; | |
| 1295 | } | |
| 1296 | ||
| 1297 | if($this ->currentC omplexType ){ // Thi s should * always* be | |
| 1298 | $this->com plexTypes[ $this->cur rentComple xType]['at trs'][$ana me] = $att rs; | |
| 1299 | } | |
| 1300 | // array Type attri bute | |
| 1301 | if(isset ($attrs['h ttp://sche mas.xmlsoa p.org/wsdl /:arrayTyp e']) || $t his->getLo calPart($a name) == ' arrayType' ){ | |
| 1302 | $this->com plexTypes[ $this->cur rentComple xType]['ph pType'] = 'array'; | |
| 1303 | $prefi x = $this- >getPrefix ($aname); | |
| 1304 | if(isset($ attrs['htt p://schema s.xmlsoap. org/wsdl/: arrayType' ])){ | |
| 1305 | $v = $attrs[ 'http://sc hemas.xmls oap.org/ws dl/:arrayT ype']; | |
| 1306 | } else { | |
| 1307 | $v = ''; | |
| 1308 | } | |
| 1309 | if(strpos( $v,'[,]')) { | |
| 1310 | $this- >complexTy pes[$this- >currentCo mplexType] ['multidim ensional'] = true; | |
| 1311 | } | |
| 1312 | $v = subst r($v,0,str pos($v,'[' )); // cli p the [] | |
| 1313 | if(!strpos ($v,':') & & isset($t his->typem ap[$this-> XMLSchemaV ersion][$v ])){ | |
| 1314 | $v = $ this->XMLS chemaVersi on.':'.$v; | |
| 1315 | } | |
| 1316 | $this->com plexTypes[ $this->cur rentComple xType]['ar rayType'] = $v; | |
| 1317 | } | |
| 1318 | break; | |
| 1319 | case ' complexCon tent': // (optional ) content for a comp lexType | |
| 1320 | $this->x debug("do nothing fo r element $name"); | |
| 1321 | break; | |
| 1322 | case ' complexTyp e': | |
| 1323 | array_pu sh($this-> complexTyp eStack, $t his->curre ntComplexT ype); | |
| 1324 | if(isset ($attrs['n ame'])){ | |
| 1325 | // TODO: w hat is the scope of named comp lexTypes t hat appear | |
| 1326 | // n ested with in other c complexTy pes? | |
| 1327 | $this->xde bug('proce ssing name d complexT ype '.$att rs['name'] ); | |
| 1328 | //$this->c urrentElem ent = fals e; | |
| 1329 | $this->cur rentComple xType = $a ttrs['name ']; | |
| 1330 | $this->com plexTypes[ $this->cur rentComple xType] = $ attrs; | |
| 1331 | $this->com plexTypes[ $this->cur rentComple xType]['ty peClass'] = 'complex Type'; | |
| 1332 | // This is for const ructs like | |
| 1333 | // <comple xType name ="ListOfSt ring" base ="soap:Arr ay"> | |
| 1334 | // <s equence> | |
| 1335 | // <element name="str ing" type= "xsd:strin g" | |
| 1336 | // minO ccurs="0" maxOccurs= "unbounded " /> | |
| 1337 | // </ sequence> | |
| 1338 | // </comp lexType> | |
| 1339 | if(isset($ attrs['bas e']) && pr eg_match(' /:Array$/' ,$attrs['b ase'])){ | |
| 1340 | $t his->xdebu g('complex Type is un usual arra y'); | |
| 1341 | $t his->compl exTypes[$t his->curre ntComplexT ype]['phpT ype'] = 'a rray'; | |
| 1342 | } else { | |
| 1343 | $t his->compl exTypes[$t his->curre ntComplexT ype]['phpT ype'] = 's truct'; | |
| 1344 | } | |
| 1345 | } else { | |
| 1346 | $name = $t his->Creat eTypeName( $this->cur rentElemen t); | |
| 1347 | $this->xde bug('proce ssing unna med comple xType for element ' . $this->c urrentElem ent . ' na med ' . $n ame); | |
| 1348 | $this->cur rentComple xType = $n ame; | |
| 1349 | //$this->c urrentElem ent = fals e; | |
| 1350 | $this->com plexTypes[ $this->cur rentComple xType] = $ attrs; | |
| 1351 | $this->com plexTypes[ $this->cur rentComple xType]['ty peClass'] = 'complex Type'; | |
| 1352 | // This is for const ructs like | |
| 1353 | // <comple xType name ="ListOfSt ring" base ="soap:Arr ay"> | |
| 1354 | // <s equence> | |
| 1355 | // <element name="str ing" type= "xsd:strin g" | |
| 1356 | // minO ccurs="0" maxOccurs= "unbounded " /> | |
| 1357 | // </ sequence> | |
| 1358 | // </comp lexType> | |
| 1359 | if(isset($ attrs['bas e']) && pr eg_match(' /:Array$/' ,$attrs['b ase'])){ | |
| 1360 | $t his->xdebu g('complex Type is un usual arra y'); | |
| 1361 | $t his->compl exTypes[$t his->curre ntComplexT ype]['phpT ype'] = 'a rray'; | |
| 1362 | } else { | |
| 1363 | $t his->compl exTypes[$t his->curre ntComplexT ype]['phpT ype'] = 's truct'; | |
| 1364 | } | |
| 1365 | } | |
| 1366 | $this->c omplexType s[$this->c urrentComp lexType][' simpleCont ent'] = 'f alse'; | |
| 1367 | break; | |
| 1368 | case ' element': | |
| 1369 | array_pu sh($this-> elementSta ck, $this- >currentEl ement); | |
| 1370 | if (!iss et($attrs[ 'form'])) { | |
| 1371 | if ($this- >currentCo mplexType) { | |
| 1372 | $a ttrs['form '] = $this ->schemaIn fo['elemen tFormDefau lt']; | |
| 1373 | } else { | |
| 1374 | // global | |
| 1375 | $a ttrs['form '] = 'qual ified'; | |
| 1376 | } | |
| 1377 | } | |
| 1378 | if(isset ($attrs['t ype'])){ | |
| 1379 | $this->xde bug("proce ssing type d element ".$attrs[' name']." o f type ".$ attrs['typ e']); | |
| 1380 | if (! $thi s->getPref ix($attrs[ 'type'])) { | |
| 1381 | if ($this->d efaultName space[$pos ]) { | |
| 1382 | $att rs['type'] = $this-> defaultNam espace[$po s] . ':' . $attrs['t ype']; | |
| 1383 | $thi s->xdebug( 'used defa ult namesp ace to mak e type ' . $attrs['t ype']); | |
| 1384 | } | |
| 1385 | } | |
| 1386 | // This is for const ructs like | |
| 1387 | // <comple xType name ="ListOfSt ring" base ="soap:Arr ay"> | |
| 1388 | // <s equence> | |
| 1389 | // <element name="str ing" type= "xsd:strin g" | |
| 1390 | // minO ccurs="0" maxOccurs= "unbounded " /> | |
| 1391 | // </ sequence> | |
| 1392 | // </comp lexType> | |
| 1393 | if ($this- >currentCo mplexType && $this-> complexTyp es[$this-> currentCom plexType][ 'phpType'] == 'array ') { | |
| 1394 | $t his->xdebu g('arrayTy pe for unu sual array is ' . $a ttrs['type ']); | |
| 1395 | $t his->compl exTypes[$t his->curre ntComplexT ype]['arra yType'] = $attrs['ty pe']; | |
| 1396 | } | |
| 1397 | $this->cur rentElemen t = $attrs ['name']; | |
| 1398 | $ename = $ attrs['nam e']; | |
| 1399 | } elseif (isset($at trs['ref'] )){ | |
| 1400 | $this->xde bug("proce ssing elem ent as ref to ".$att rs['ref']) ; | |
| 1401 | $this->cur rentElemen t = "ref t o ".$attrs ['ref']; | |
| 1402 | $ename = $ this->getL ocalPart($ attrs['ref ']); | |
| 1403 | } else { | |
| 1404 | $type = $t his->Creat eTypeName( $this->cur rentComple xType . '_ ' . $attrs ['name']); | |
| 1405 | $this->xde bug("proce ssing unty ped elemen t " . $att rs['name'] . ' type ' . $type) ; | |
| 1406 | $this->cur rentElemen t = $attrs ['name']; | |
| 1407 | $attrs['ty pe'] = $th is->schema TargetName space . ': ' . $type; | |
| 1408 | $ename = $ attrs['nam e']; | |
| 1409 | } | |
| 1410 | if (isse t($ename) && $this-> currentCom plexType) { | |
| 1411 | $this->xde bug("add e lement $en ame to com plexType $ this->curr entComplex Type"); | |
| 1412 | $this->com plexTypes[ $this->cur rentComple xType]['el ements'][$ ename] = $ attrs; | |
| 1413 | } elseif (!isset($ attrs['ref '])) { | |
| 1414 | $this->xde bug("add e lement $en ame to ele ments arra y"); | |
| 1415 | $this->ele ments[ $at trs['name' ] ] = $att rs; | |
| 1416 | $this->ele ments[ $at trs['name' ] ]['typeC lass'] = ' element'; | |
| 1417 | } | |
| 1418 | break; | |
| 1419 | case ' enumeratio n': // rest riction va lue list m ember | |
| 1420 | $this->x debug('enu meration ' . $attrs[ 'value']); | |
| 1421 | if ($thi s->current SimpleType ) { | |
| 1422 | $this->sim pleTypes[$ this->curr entSimpleT ype]['enum eration'][ ] = $attrs ['value']; | |
| 1423 | } elseif ($this->c urrentComp lexType) { | |
| 1424 | $this->com plexTypes[ $this->cur rentComple xType]['en umeration' ][] = $att rs['value' ]; | |
| 1425 | } | |
| 1426 | break; | |
| 1427 | case ' extension' : // simpleCon tent or co mplexConte nt type ex tension | |
| 1428 | $this->x debug('ext ension ' . $attrs['b ase']); | |
| 1429 | if ($thi s->current ComplexTyp e) { | |
| 1430 | $ns = $thi s->getPref ix($attrs[ 'base']); | |
| 1431 | if ($ns == '') { | |
| 1432 | $t his->compl exTypes[$t his->curre ntComplexT ype]['exte nsionBase' ] = $this- >schemaTar getNamespa ce . ':' . $attrs['b ase']; | |
| 1433 | } else { | |
| 1434 | $t his->compl exTypes[$t his->curre ntComplexT ype]['exte nsionBase' ] = $attrs ['base']; | |
| 1435 | } | |
| 1436 | } else { | |
| 1437 | $this->xde bug('no cu rrent comp lexType to set exten sionBase') ; | |
| 1438 | } | |
| 1439 | break; | |
| 1440 | case ' import': | |
| 1441 | if (isset($a ttrs['sche maLocation '])) { | |
| 1442 | $this->xde bug('impor t namespac e ' . $att rs['namesp ace'] . ' from ' . $ attrs['sch emaLocatio n']); | |
| 1443 | $this->imp orts[$attr s['namespa ce']][] = array('loc ation' => $attrs['sc hemaLocati on'], 'loa ded' => fa lse); | |
| 1444 | } else { | |
| 1445 | $this->xde bug('impor t namespac e ' . $att rs['namesp ace']); | |
| 1446 | $this->imp orts[$attr s['namespa ce']][] = array('loc ation' => '', 'loade d' => true ); | |
| 1447 | if (! $thi s->getPref ixFromName space($att rs['namesp ace'])) { | |
| 1448 | $t his->names paces['ns' .(count($t his->names paces)+1)] = $attrs[ 'namespace ']; | |
| 1449 | } | |
| 1450 | } | |
| 1451 | break; | |
| 1452 | case ' include': | |
| 1453 | if (isset($a ttrs['sche maLocation '])) { | |
| 1454 | $this->xde bug('inclu de into na mespace ' . $this->s chemaTarge tNamespace . ' from ' . $attrs ['schemaLo cation']); | |
| 1455 | $this->imp orts[$this ->schemaTa rgetNamesp ace][] = a rray('loca tion' => $ attrs['sch emaLocatio n'], 'load ed' => fal se); | |
| 1456 | } else { | |
| 1457 | $this->xde bug('ignor ing invali d XML Sche ma constru ct: includ e without schemaLoca tion attri bute'); | |
| 1458 | } | |
| 1459 | break; | |
| 1460 | case ' list': // simpleT ype value list | |
| 1461 | $this->x debug("do nothing fo r element $name"); | |
| 1462 | break; | |
| 1463 | case ' restrictio n': // simpleTyp e, simpleC ontent or complexCon tent value restricti on | |
| 1464 | $this->x debug('res triction ' . $attrs[ 'base']); | |
| 1465 | if($this ->currentS impleType) { | |
| 1466 | $this->sim pleTypes[$ this->curr entSimpleT ype]['type '] = $attr s['base']; | |
| 1467 | } elseif ($this->cu rrentCompl exType){ | |
| 1468 | $this->com plexTypes[ $this->cur rentComple xType]['re strictionB ase'] = $a ttrs['base ']; | |
| 1469 | if(strstr( $attrs['ba se'],':') == ':Array '){ | |
| 1470 | $t his->compl exTypes[$t his->curre ntComplexT ype]['phpT ype'] = 'a rray'; | |
| 1471 | } | |
| 1472 | } | |
| 1473 | break; | |
| 1474 | case ' schema': | |
| 1475 | $this->s chemaInfo = $attrs; | |
| 1476 | $this->s chemaInfo[ 'schemaVer sion'] = $ this->getN amespaceFr omPrefix($ prefix); | |
| 1477 | if (isse t($attrs[' targetName space'])) { | |
| 1478 | $this->sch emaTargetN amespace = $attrs['t argetNames pace']; | |
| 1479 | } | |
| 1480 | if (!iss et($attrs[ 'elementFo rmDefault' ])) { | |
| 1481 | $this->sch emaInfo['e lementForm Default'] = 'unquali fied'; | |
| 1482 | } | |
| 1483 | if (!iss et($attrs[ 'attribute FormDefaul t'])) { | |
| 1484 | $this->sch emaInfo['a ttributeFo rmDefault' ] = 'unqua lified'; | |
| 1485 | } | |
| 1486 | break; | |
| 1487 | case ' simpleCont ent': // (optional ) content for a comp lexType | |
| 1488 | if ($thi s->current ComplexTyp e) { // This should *al ways* be | |
| 1489 | $this->com plexTypes[ $this->cur rentComple xType]['si mpleConten t'] = 'tru e'; | |
| 1490 | } else { | |
| 1491 | $this->xde bug("do no thing for element $n ame becaus e there is no curren t complexT ype"); | |
| 1492 | } | |
| 1493 | break; | |
| 1494 | case ' simpleType ': | |
| 1495 | array_pu sh($this-> simpleType Stack, $th is->curren tSimpleTyp e); | |
| 1496 | if(isset ($attrs['n ame'])){ | |
| 1497 | $this->xde bug("proce ssing simp leType for name " . $attrs['na me']); | |
| 1498 | $this->cur rentSimple Type = $at trs['name' ]; | |
| 1499 | $this->sim pleTypes[ $attrs['na me'] ] = $ attrs; | |
| 1500 | $this->sim pleTypes[ $attrs['na me'] ]['ty peClass'] = 'simpleT ype'; | |
| 1501 | $this->sim pleTypes[ $attrs['na me'] ]['ph pType'] = 'scalar'; | |
| 1502 | } else { | |
| 1503 | $name = $t his->Creat eTypeName( $this->cur rentComple xType . '_ ' . $this- >currentEl ement); | |
| 1504 | $this->xde bug('proce ssing unna med simple Type for e lement ' . $this->cu rrentEleme nt . ' nam ed ' . $na me); | |
| 1505 | $this->cur rentSimple Type = $na me; | |
| 1506 | //$this->c urrentElem ent = fals e; | |
| 1507 | $this->sim pleTypes[$ this->curr entSimpleT ype] = $at trs; | |
| 1508 | $this->sim pleTypes[$ this->curr entSimpleT ype]['phpT ype'] = 's calar'; | |
| 1509 | } | |
| 1510 | break; | |
| 1511 | case ' union': // simpleT ype type l ist | |
| 1512 | $this->x debug("do nothing fo r element $name"); | |
| 1513 | break; | |
| 1514 | defaul t: | |
| 1515 | $this->x debug("do not have a ny logic t o process element $n ame"); | |
| 1516 | } | |
| 1517 | } | |
| 1518 | ||
| 1519 | /* * | |
| 1520 | * end-elemen t handler | |
| 1521 | * | |
| 1522 | * @param string $pa rser XML p arser obje ct | |
| 1523 | * @param string $na me element name | |
| 1524 | * @access private | |
| 1525 | */ | |
| 1526 | fu nction sch emaEndElem ent($parse r, $name) { | |
| 1527 | // b ring depth down a no tch | |
| 1528 | $thi s->depth-- ; | |
| 1529 | // p osition of current e lement is equal to t he last va lue left i n depth_ar ray for my depth | |
| 1530 | if(i sset($this ->depth_ar ray[$this- >depth])){ | |
| 1531 | $pos = $this-> depth_arra y[$this->d epth]; | |
| 1532 | } | |
| 1533 | // g et element prefix | |
| 1534 | if ( $prefix = $this->get Prefix($na me)){ | |
| 1535 | // get unqualifi ed name | |
| 1536 | $name = $this->g etLocalPar t($name); | |
| 1537 | } el se { | |
| 1538 | $pre fix = ''; | |
| 1539 | } | |
| 1540 | // m ove on... | |
| 1541 | if($ name == 'c omplexType '){ | |
| 1542 | $this- >xdebug('d one proces sing compl exType ' . ($this->c urrentComp lexType ? $this->cur rentComple xType : '( unknown)') ); | |
| 1543 | $this- >xdebug($t his->varDu mp($this-> complexTyp es[$this-> currentCom plexType]) ); | |
| 1544 | $this- >currentCo mplexType = array_po p($this->c omplexType Stack); | |
| 1545 | //$thi s->current Element = false; | |
| 1546 | } | |
| 1547 | if($ name == 'e lement'){ | |
| 1548 | $this- >xdebug('d one proces sing eleme nt ' . ($t his->curre ntElement ? $this->c urrentElem ent : '(un known)')); | |
| 1549 | $this- >currentEl ement = ar ray_pop($t his->eleme ntStack); | |
| 1550 | } | |
| 1551 | if($ name == 's impleType' ){ | |
| 1552 | $this- >xdebug('d one proces sing simpl eType ' . ($this->cu rrentSimpl eType ? $t his->curre ntSimpleTy pe : '(unk nown)')); | |
| 1553 | $this- >xdebug($t his->varDu mp($this-> simpleType s[$this->c urrentSimp leType])); | |
| 1554 | $this- >currentSi mpleType = array_pop ($this->si mpleTypeSt ack); | |
| 1555 | } | |
| 1556 | } | |
| 1557 | ||
| 1558 | /* * | |
| 1559 | * element co ntent hand ler | |
| 1560 | * | |
| 1561 | * @param string $pa rser XML p arser obje ct | |
| 1562 | * @param string $da ta element content | |
| 1563 | * @access private | |
| 1564 | */ | |
| 1565 | fu nction sch emaCharact erData($pa rser, $dat a){ | |
| 1566 | $pos = $this-> depth_arra y[$this->d epth - 1]; | |
| 1567 | $thi s->message [$pos]['cd ata'] .= $ data; | |
| 1568 | } | |
| 1569 | ||
| 1570 | /* * | |
| 1571 | * serialize the schema | |
| 1572 | * | |
| 1573 | * @access public | |
| 1574 | */ | |
| 1575 | fu nction ser ializeSche ma(){ | |
| 1576 | ||
| 1577 | $sch emaPrefix = $this->g etPrefixFr omNamespac e($this->X MLSchemaVe rsion); | |
| 1578 | $xml = ''; | |
| 1579 | // i mports | |
| 1580 | if ( sizeof($th is->import s) > 0) { | |
| 1581 | foreac h($this->i mports as $ns => $li st) { | |
| 1582 | foreach ($list as $ii) { | |
| 1583 | if ($ii['l ocation'] != '') { | |
| 1584 | $x ml .= " <$ schemaPref ix:import location=\ "" . $ii[' location'] . '" name space="' . $ns . "\" />\n"; | |
| 1585 | } else { | |
| 1586 | $x ml .= " <$ schemaPref ix:import namespace= \"" . $ns . "\" />\n "; | |
| 1587 | } | |
| 1588 | } | |
| 1589 | } | |
| 1590 | } | |
| 1591 | // c omplex typ es | |
| 1592 | fore ach($this- >complexTy pes as $ty peName => $attrs){ | |
| 1593 | $conte ntStr = '' ; | |
| 1594 | // ser ialize chi ld element s | |
| 1595 | if(iss et($attrs[ 'elements' ]) && (cou nt($attrs[ 'elements' ]) > 0)){ | |
| 1596 | foreach( $attrs['el ements'] a s $element => $ePart s){ | |
| 1597 | if(isset($ eParts['re f'])){ | |
| 1598 | $c ontentStr .= " <$s chemaPrefi x:element ref=\"$ele ment\"/>\n "; | |
| 1599 | } else { | |
| 1600 | $c ontentStr .= " <$s chemaPrefi x:element name=\"$el ement\" ty pe=\"" . $ this->cont ractQName( $eParts['t ype']) . " \""; | |
| 1601 | fo reach ($eP arts as $a Name => $a Value) { | |
| 1602 | // h andle, e.g ., abstrac t, default , form, mi nOccurs, m axOccurs, nillable | |
| 1603 | if ( $aName != 'name' && $aName != 'type') { | |
| 1604 | $conte ntStr .= " $aName=\" $aValue\"" ; | |
| 1605 | } | |
| 1606 | } | |
| 1607 | $c ontentStr .= "/>\n"; | |
| 1608 | } | |
| 1609 | } | |
| 1610 | // compo sitor wrap s elements | |
| 1611 | if (isse t($attrs[' compositor ']) && ($a ttrs['comp ositor'] ! = '')) { | |
| 1612 | $contentSt r = " <$s chemaPrefi x:$attrs[c ompositor] >\n".$cont entStr." </$schemaP refix:$att rs[composi tor]>\n"; | |
| 1613 | } | |
| 1614 | } | |
| 1615 | // att ributes | |
| 1616 | if(iss et($attrs[ 'attrs']) && (count( $attrs['at trs']) >= 1)){ | |
| 1617 | foreach( $attrs['at trs'] as $ attr => $a Parts){ | |
| 1618 | $contentSt r .= " <$schemaPr efix:attri bute"; | |
| 1619 | foreach ($ aParts as $a => $v) { | |
| 1620 | if ($a == 'r ef' || $a == 'type') { | |
| 1621 | $con tentStr .= " $a=\"". $this->con tractQName ($v).'"'; | |
| 1622 | } elseif ($a == 'http: //schemas. xmlsoap.or g/wsdl/:ar rayType') { | |
| 1623 | $thi s->usedNam espaces['w sdl'] = $t his->names paces['wsd l']; | |
| 1624 | $con tentStr .= ' wsdl:ar rayType="' .$this->co ntractQNam e($v).'"'; | |
| 1625 | } else { | |
| 1626 | $con tentStr .= " $a=\"$v \""; | |
| 1627 | } | |
| 1628 | } | |
| 1629 | $contentSt r .= "/>\n "; | |
| 1630 | } | |
| 1631 | } | |
| 1632 | // if restrictio n | |
| 1633 | if (is set($attrs ['restrict ionBase']) && $attrs ['restrict ionBase'] != ''){ | |
| 1634 | $content Str = " <$schemaPr efix:restr iction bas e=\"".$thi s->contrac tQName($at trs['restr ictionBase '])."\">\n ".$content Str." </ $schemaPre fix:restri ction>\n"; | |
| 1635 | // compl ex or simp le content | |
| 1636 | if ((iss et($attrs[ 'elements' ]) && coun t($attrs[' elements'] ) > 0) || (isset($at trs['attrs ']) && cou nt($attrs[ 'attrs']) > 0)){ | |
| 1637 | $contentSt r = " <$s chemaPrefi x:complexC ontent>\n" .$contentS tr." </$s chemaPrefi x:complexC ontent>\n" ; | |
| 1638 | } | |
| 1639 | } | |
| 1640 | // fin alize comp lex type | |
| 1641 | if($co ntentStr ! = ''){ | |
| 1642 | $content Str = " <$ schemaPref ix:complex Type name= \"$typeNam e\">\n".$c ontentStr. " </$schem aPrefix:co mplexType> \n"; | |
| 1643 | } else { | |
| 1644 | $content Str = " <$ schemaPref ix:complex Type name= \"$typeNam e\"/>\n"; | |
| 1645 | } | |
| 1646 | $xml . = $content Str; | |
| 1647 | } | |
| 1648 | // s imple type s | |
| 1649 | if(i sset($this ->simpleTy pes) && co unt($this- >simpleTyp es) > 0){ | |
| 1650 | foreac h($this->s impleTypes as $typeN ame => $eP arts){ | |
| 1651 | $xml .= " <$schema Prefix:sim pleType na me=\"$type Name\">\n <$schemaP refix:rest riction ba se=\"".$th is->contra ctQName($e Parts['typ e'])."\">\ n"; | |
| 1652 | if (isse t($eParts[ 'enumerati on'])) { | |
| 1653 | foreach ($ eParts['en umeration' ] as $e) { | |
| 1654 | $x ml .= " < $schemaPre fix:enumer ation valu e=\"$e\"/> \n"; | |
| 1655 | } | |
| 1656 | } | |
| 1657 | $xml .= " </$sche maPrefix:r estriction >\n </$sch emaPrefix: simpleType >"; | |
| 1658 | } | |
| 1659 | } | |
| 1660 | // e lements | |
| 1661 | if(i sset($this ->elements ) && count ($this->el ements) > 0){ | |
| 1662 | foreac h($this->e lements as $element => $eParts ){ | |
| 1663 | $xml .= " <$schema Prefix:ele ment name= \"$element \" type=\" ".$this->c ontractQNa me($eParts ['type']). "\"/>\n"; | |
| 1664 | } | |
| 1665 | } | |
| 1666 | // a ttributes | |
| 1667 | if(i sset($this ->attribut es) && cou nt($this-> attributes ) > 0){ | |
| 1668 | foreac h($this->a ttributes as $attr = > $aParts) { | |
| 1669 | $xml .= " <$schema Prefix:att ribute nam e=\"$attr\ " type=\"" .$this->co ntractQNam e($aParts[ 'type'])." \"\n/>"; | |
| 1670 | } | |
| 1671 | } | |
| 1672 | // f inish 'er up | |
| 1673 | $att r = ''; | |
| 1674 | fore ach ($this ->schemaIn fo as $k = > $v) { | |
| 1675 | if ($k == 'eleme ntFormDefa ult' || $k == 'attri buteFormDe fault') { | |
| 1676 | $attr .= " $k=\"$v \""; | |
| 1677 | } | |
| 1678 | } | |
| 1679 | $el = "<$schem aPrefix:sc hema$attr targetName space=\"$t his->schem aTargetNam espace\"\n "; | |
| 1680 | fore ach (array _diff($thi s->usedNam espaces, $ this->encl osingNames paces) as $nsp => $n s) { | |
| 1681 | $el .= " xmlns:$ nsp=\"$ns\ ""; | |
| 1682 | } | |
| 1683 | $xml = $el . " >\n".$xml. "</$schema Prefix:sch ema>\n"; | |
| 1684 | retu rn $xml; | |
| 1685 | } | |
| 1686 | ||
| 1687 | /* * | |
| 1688 | * adds debug data to t he clas le vel debug string | |
| 1689 | * | |
| 1690 | * @param string $st ring debug data | |
| 1691 | * @access private | |
| 1692 | */ | |
| 1693 | fu nction xde bug($strin g){ | |
| 1694 | $thi s->debug(' <' . $this ->schemaTa rgetNamesp ace . '> ' .$string); | |
| 1695 | } | |
| 1696 | ||
| 1697 | /* * | |
| 1698 | * retu rns an ass ociative a rray of in formation about a gi ven type | |
| 1699 | * retu rns false if no type exists by the given name | |
| 1700 | * | |
| 1701 | * For a complexT ype typeDe f = array( | |
| 1702 | * 'res trictionBa se' => '', | |
| 1703 | * 'php Type' => ' ', | |
| 1704 | * 'com positor' = > '(sequen ce|all)', | |
| 1705 | * 'ele ments' => array(), / / refs to elements a rray | |
| 1706 | * 'att rs' => arr ay() // re fs to attr ibutes arr ay | |
| 1707 | * ... and so on (see addCo mplexType) | |
| 1708 | * ) | |
| 1709 | * | |
| 1710 | * For simp leType or element, t he array h as differe nt keys. | |
| 1711 | * | |
| 1712 | * @par am string $type | |
| 1713 | * @ret urn mixed | |
| 1714 | * @acc ess public | |
| 1715 | * @see addComple xType | |
| 1716 | * @see addSimple Type | |
| 1717 | * @see addElemen t | |
| 1718 | */ | |
| 1719 | fu nction get TypeDef($t ype){ | |
| 1720 | //$t his->debug ("in getTy peDef for type $type "); | |
| 1721 | if ( substr($ty pe, -1) == '^') { | |
| 1722 | $is_el ement = 1; | |
| 1723 | $type = substr($ type, 0, - 1); | |
| 1724 | } el se { | |
| 1725 | $is_el ement = 0; | |
| 1726 | } | |
| 1727 | ||
| 1728 | if(( ! $is_elem ent) && is set($this- >complexTy pes[$type] )){ | |
| 1729 | $this- >xdebug("i n getTypeD ef, found complexTyp e $type"); | |
| 1730 | return $this->co mplexTypes [$type]; | |
| 1731 | } el seif((! $i s_element) && isset( $this->sim pleTypes[$ type])){ | |
| 1732 | $this- >xdebug("i n getTypeD ef, found simpleType $type"); | |
| 1733 | if (!i sset($this ->simpleTy pes[$type] ['phpType' ])) { | |
| 1734 | // get i nfo for ty pe to tack onto the simple typ e | |
| 1735 | // TODO: can this ever reall y apply (i .e. what i s a simple Type reall y?) | |
| 1736 | $uqType = substr($ this->simp leTypes[$t ype]['type '], strrpo s($this->s impleTypes [$type]['t ype'], ':' ) + 1); | |
| 1737 | $ns = su bstr($this ->simpleTy pes[$type] ['type'], 0, strrpos ($this->si mpleTypes[ $type]['ty pe'], ':') ); | |
| 1738 | $etype = $this->ge tTypeDef($ uqType); | |
| 1739 | if ($ety pe) { | |
| 1740 | $this->xde bug("in ge tTypeDef, found type for simpl eType $typ e:"); | |
| 1741 | $this->xde bug($this- >varDump($ etype)); | |
| 1742 | if (isset( $etype['ph pType'])) { | |
| 1743 | $t his->simpl eTypes[$ty pe]['phpTy pe'] = $et ype['phpTy pe']; | |
| 1744 | } | |
| 1745 | if (isset( $etype['el ements'])) { | |
| 1746 | $t his->simpl eTypes[$ty pe]['eleme nts'] = $e type['elem ents']; | |
| 1747 | } | |
| 1748 | } | |
| 1749 | } | |
| 1750 | return $this->si mpleTypes[ $type]; | |
| 1751 | } el seif(isset ($this->el ements[$ty pe])){ | |
| 1752 | $this- >xdebug("i n getTypeD ef, found element $t ype"); | |
| 1753 | if (!i sset($this ->elements [$type]['p hpType'])) { | |
| 1754 | // get i nfo for ty pe to tack onto the element | |
| 1755 | $uqType = substr($ this->elem ents[$type ]['type'], strrpos($ this->elem ents[$type ]['type'], ':') + 1) ; | |
| 1756 | $ns = su bstr($this ->elements [$type]['t ype'], 0, strrpos($t his->eleme nts[$type] ['type'], ':')); | |
| 1757 | $etype = $this->ge tTypeDef($ uqType); | |
| 1758 | if ($ety pe) { | |
| 1759 | $this->xde bug("in ge tTypeDef, found type for eleme nt $type:" ); | |
| 1760 | $this->xde bug($this- >varDump($ etype)); | |
| 1761 | if (isset( $etype['ph pType'])) { | |
| 1762 | $t his->eleme nts[$type] ['phpType' ] = $etype ['phpType' ]; | |
| 1763 | } | |
| 1764 | if (isset( $etype['el ements'])) { | |
| 1765 | $t his->eleme nts[$type] ['elements '] = $etyp e['element s']; | |
| 1766 | } | |
| 1767 | if (isset( $etype['ex tensionBas e'])) { | |
| 1768 | $t his->eleme nts[$type] ['extensio nBase'] = $etype['ex tensionBas e']; | |
| 1769 | } | |
| 1770 | } elseif ($ns == ' http://www .w3.org/20 01/XMLSche ma') { | |
| 1771 | $this->xde bug("in ge tTypeDef, element $t ype is an XSD type") ; | |
| 1772 | $this->ele ments[$typ e]['phpTyp e'] = 'sca lar'; | |
| 1773 | } | |
| 1774 | } | |
| 1775 | return $this->el ements[$ty pe]; | |
| 1776 | } el seif(isset ($this->at tributes[$ type])){ | |
| 1777 | $this- >xdebug("i n getTypeD ef, found attribute $type"); | |
| 1778 | return $this->at tributes[$ type]; | |
| 1779 | } el seif (preg _match('/_ ContainedT ype$/', $t ype)) { | |
| 1780 | $this- >xdebug("i n getTypeD ef, have a n untyped element $t ype"); | |
| 1781 | $typeD ef['typeCl ass'] = 's impleType' ; | |
| 1782 | $typeD ef['phpTyp e'] = 'sca lar'; | |
| 1783 | $typeD ef['type'] = 'http:/ /www.w3.or g/2001/XML Schema:str ing'; | |
| 1784 | return $typeDef; | |
| 1785 | } | |
| 1786 | $thi s->xdebug( "in getTyp eDef, did not find $ type"); | |
| 1787 | retu rn false; | |
| 1788 | } | |
| 1789 | ||
| 1790 | /* * | |
| 1791 | * adds a com plex type to the sch ema | |
| 1792 | * | |
| 1793 | * example: a rray | |
| 1794 | * | |
| 1795 | * addType( | |
| 1796 | * 'Arr ayOfstring ', | |
| 1797 | * 'com plexType', | |
| 1798 | * 'arr ay', | |
| 1799 | * '', | |
| 1800 | * 'SOA P-ENC:Arra y', | |
| 1801 | * arra y('ref'=>' SOAP-ENC:a rrayType', 'wsdl:arra yType'=>'s tring[]'), | |
| 1802 | * 'xsd :string' | |
| 1803 | * ); | |
| 1804 | * | |
| 1805 | * example: P HP associa tive array ( SOAP St ruct ) | |
| 1806 | * | |
| 1807 | * addType( | |
| 1808 | * 'SOA PStruct', | |
| 1809 | * 'com plexType', | |
| 1810 | * 'str uct', | |
| 1811 | * 'all ', | |
| 1812 | * arra y('myVar'= > array('n ame'=>'myV ar','type' =>'string' ) | |
| 1813 | * ); | |
| 1814 | * | |
| 1815 | * @param nam e | |
| 1816 | * @param typ eClass (co mplexType| simpleType |attribute ) | |
| 1817 | * @param php Type: curr ently supp orted are array and struct (ph p assoc ar ray) | |
| 1818 | * @param com positor (a ll|sequenc e|choice) | |
| 1819 | * @param res trictionBa se namespa ce:name (h ttp://sche mas.xmlsoa p.org/soap /encoding/ :Array) | |
| 1820 | * @param ele ments = ar ray ( name = array(n ame=>'',ty pe=>'') ) | |
| 1821 | * @param att rs = array ( | |
| 1822 | * arra y( | |
| 1823 | * 'ref' => "http:/ /schemas.x mlsoap.org /soap/enco ding/:arra yType", | |
| 1824 | * "http: //schemas. xmlsoap.or g/wsdl/:ar rayType" = > "string[ ]" | |
| 1825 | * ) | |
| 1826 | * ) | |
| 1827 | * @param arr ayType: na mespace:na me (http:/ /www.w3.or g/2001/XML Schema:str ing) | |
| 1828 | * @access pu blic | |
| 1829 | * @see getTy peDef | |
| 1830 | */ | |
| 1831 | fu nction add ComplexTyp e($name,$t ypeClass=' complexTyp e',$phpTyp e='array', $composito r='',$rest rictionBas e='',$elem ents=array (),$attrs= array(),$a rrayType=' '){ | |
| 1832 | $thi s->complex Types[$nam e] = array ( | |
| 1833 | 'name' => $name , | |
| 1834 | 'typeCla ss' => $ty peClass, | |
| 1835 | 'phpType ' => $ph pType, | |
| 1836 | 'com positor'=> $composit or, | |
| 1837 | 'restric tionBase' => $restri ctionBase, | |
| 1838 | 'ele ments' => $elem ents, | |
| 1839 | 'attrs' => $attr s, | |
| 1840 | 'arrayTy pe' => $ar rayType | |
| 1841 | ); | |
| 1842 | ||
| 1843 | $thi s->xdebug( "addComple xType $nam e:"); | |
| 1844 | $thi s->appendD ebug($this ->varDump( $this->com plexTypes[ $name])); | |
| 1845 | } | |
| 1846 | ||
| 1847 | /* * | |
| 1848 | * adds a sim ple type t o the sche ma | |
| 1849 | * | |
| 1850 | * @param str ing $name | |
| 1851 | * @param str ing $restr ictionBase namespace :name (htt p://schema s.xmlsoap. org/soap/e ncoding/:A rray) | |
| 1852 | * @param str ing $typeC lass (shou ld always be simpleT ype) | |
| 1853 | * @param str ing $phpTy pe (should always be scalar) | |
| 1854 | * @param arr ay $enumer ation arra y of value s | |
| 1855 | * @access pu blic | |
| 1856 | * @see nusoa p_xmlschem a | |
| 1857 | * @see getTy peDef | |
| 1858 | */ | |
| 1859 | fu nction add SimpleType ($name, $r estriction Base='', $ typeClass= 'simpleTyp e', $phpTy pe='scalar ', $enumer ation=arra y()) { | |
| 1860 | $thi s->simpleT ypes[$name ] = array( | |
| 1861 | 'name' => $name, | |
| 1862 | 'typeCla ss' => $type Class, | |
| 1863 | 'phpType ' => $phpT ype, | |
| 1864 | 'type' => $restri ctionBase, | |
| 1865 | 'enumera tion' => $enum eration | |
| 1866 | ); | |
| 1867 | ||
| 1868 | $thi s->xdebug( "addSimple Type $name :"); | |
| 1869 | $thi s->appendD ebug($this ->varDump( $this->sim pleTypes[$ name])); | |
| 1870 | } | |
| 1871 | ||
| 1872 | /* * | |
| 1873 | * adds an el ement to t he schema | |
| 1874 | * | |
| 1875 | * @param arr ay $attrs attributes that must include n ame and ty pe | |
| 1876 | * @see nusoa p_xmlschem a | |
| 1877 | * @access pu blic | |
| 1878 | */ | |
| 1879 | fu nction add Element($a ttrs) { | |
| 1880 | if ( ! $this->g etPrefix($ attrs['typ e'])) { | |
| 1881 | $attrs ['type'] = $this->sc hemaTarget Namespace . ':' . $a ttrs['type ']; | |
| 1882 | } | |
| 1883 | $thi s->element s[ $attrs[ 'name'] ] = $attrs; | |
| 1884 | $thi s->element s[ $attrs[ 'name'] ][ 'typeClass '] = 'elem ent'; | |
| 1885 | ||
| 1886 | $thi s->xdebug( "addElemen t " . $att rs['name'] ); | |
| 1887 | $thi s->appendD ebug($this ->varDump( $this->ele ments[ $at trs['name' ] ])); | |
| 1888 | } | |
| 1889 | } | |
| 1890 | ||
| 1891 | ||
| 1892 | /** | |
| 1893 | * transpor t class fo r sending/ receiving data via H TTP and HT TPS | |
| 1894 | * NOTE: PH P must be compiled w ith the CU RL extensi on for HTT PS support | |
| 1895 | * | |
| 1896 | * @author Dietrich Ayala <di etrich@gan x4.com> | |
| 1897 | * @author Scott Ni chol <snic hol@users. sourceforg e.net> | |
| 1898 | * @version $Id: nus oap.php,v 1.123 2010 /04/26 20: 15:08 snic hol Exp $ | |
| 1899 | * @access public | |
| 1900 | * @package third-par ty | |
| 1901 | * @subpack age nusoap | |
| 1902 | */ | |
| 1903 | class soap _transport _http exte nds nusoap _base { | |
| 1904 | ||
| 1905 | va r $url = ' '; | |
| 1906 | va r $uri = ' '; | |
| 1907 | va r $digest_ uri = ''; | |
| 1908 | va r $scheme = ''; | |
| 1909 | va r $host = ''; | |
| 1910 | va r $port = ''; | |
| 1911 | va r $path = ''; | |
| 1912 | va r $request _method = 'POST'; | |
| 1913 | va r $protoco l_version = '1.0'; | |
| 1914 | va r $encodin g = ''; | |
| 1915 | va r $outgoin g_headers = array(); | |
| 1916 | va r $incomin g_headers = array(); | |
| 1917 | va r $incomin g_cookies = array(); | |
| 1918 | va r $outgoin g_payload = ''; | |
| 1919 | va r $incomin g_payload = ''; | |
| 1920 | va r $respons e_status_l ine; // HTTP re sponse sta tus line | |
| 1921 | va r $useSOAP Action = t rue; | |
| 1922 | va r $persist entConnect ion = fals e; | |
| 1923 | va r $ch = fa lse; // cURL handle | |
| 1924 | va r $ch_opti ons = arra y(); // cURL cu stom optio ns | |
| 1925 | va r $use_cur l = false; // force c URL use | |
| 1926 | va r $proxy = null; // proxy inf ormation ( associativ e array) | |
| 1927 | va r $usernam e = ''; | |
| 1928 | va r $passwor d = ''; | |
| 1929 | va r $authtyp e = ''; | |
| 1930 | va r $digestR equest = a rray(); | |
| 1931 | va r $certReq uest = arr ay(); // keys mu st be cain fofile (op tional), s slcertfile , sslkeyfi le, passph rase, cert password ( optional), verifypee r (optiona l), verify host (opti onal) | |
| 1932 | // cai nfofile: c ertificate authority file, e.g . '$pathTo PemFiles/r ootca.pem' | |
| 1933 | // ssl certfile: SSL certif icate file , e.g. '$p athToPemFi les/mycert .pem' | |
| 1934 | // ssl keyfile: S SL key fil e, e.g. '$ pathToPemF iles/mykey .pem' | |
| 1935 | // pas sphrase: S SL key pas sword/pass phrase | |
| 1936 | // cer tpassword: SSL certi ficate pas sword | |
| 1937 | // ver ifypeer: d efault is 1 | |
| 1938 | // ver ifyhost: d efault is 1 | |
| 1939 | ||
| 1940 | /* * | |
| 1941 | * constructo r | |
| 1942 | * | |
| 1943 | * @param str ing $url T he URL to which to c onnect | |
| 1944 | * @param arr ay $curl_o ptions Use r-specifie d cURL opt ions | |
| 1945 | * @param boo lean $use_ curl Wheth er to try to force c URL use | |
| 1946 | * @access pu blic | |
| 1947 | */ | |
| 1948 | fu nction soa p_transpor t_http($ur l, $curl_o ptions = N ULL, $use_ curl = fal se){ | |
| 1949 | pare nt::nusoap _base(); | |
| 1950 | $thi s->debug(" ctor url=$ url use_cu rl=$use_cu rl curl_op tions:"); | |
| 1951 | $thi s->appendD ebug($this ->varDump( $curl_opti ons)); | |
| 1952 | $thi s->setURL( $url); | |
| 1953 | if ( is_array($ curl_optio ns)) { | |
| 1954 | $this- >ch_option s = $curl_ options; | |
| 1955 | } | |
| 1956 | $thi s->use_cur l = $use_c url; | |
| 1957 | preg _match('/\ $Revisio' . 'n: ([^ ]+)/', $th is->revisi on, $rev); | |
| 1958 | $thi s->setHead er('User-A gent', $th is->title. '/'.$this- >version.' ('.$rev[1 ].')'); | |
| 1959 | } | |
| 1960 | ||
| 1961 | /* * | |
| 1962 | * sets a cUR L option | |
| 1963 | * | |
| 1964 | * @param mixed $option Th e cURL opt ion (alway s integer? ) | |
| 1965 | * @param mixed $value The cURL opti on value | |
| 1966 | * @access private | |
| 1967 | */ | |
| 1968 | fu nction set CurlOption ($option, $value) { | |
| 1969 | $thi s->debug(" setCurlOpt ion option =$option, value="); | |
| 1970 | $thi s->appendD ebug($this ->varDump( $value)); | |
| 1971 | curl _setopt($t his->ch, $ option, $v alue); | |
| 1972 | } | |
| 1973 | ||
| 1974 | /* * | |
| 1975 | * sets an HT TP header | |
| 1976 | * | |
| 1977 | * @param str ing $name The name o f the head er | |
| 1978 | * @param str ing $value The value of the he ader | |
| 1979 | * @access pr ivate | |
| 1980 | */ | |
| 1981 | fu nction set Header($na me, $value ) { | |
| 1982 | $thi s->outgoin g_headers[ $name] = $ value; | |
| 1983 | $thi s->debug(" set header $name: $v alue"); | |
| 1984 | } | |
| 1985 | ||
| 1986 | /* * | |
| 1987 | * unsets an HTTP heade r | |
| 1988 | * | |
| 1989 | * @param str ing $name The name o f the head er | |
| 1990 | * @access pr ivate | |
| 1991 | */ | |
| 1992 | fu nction uns etHeader($ name) { | |
| 1993 | if ( isset($thi s->outgoin g_headers[ $name])) { | |
| 1994 | $this- >debug("un set header $name"); | |
| 1995 | unset( $this->out going_head ers[$name] ); | |
| 1996 | } | |
| 1997 | } | |
| 1998 | ||
| 1999 | /* * | |
| 2000 | * sets the U RL to whic h to conne ct | |
| 2001 | * | |
| 2002 | * @param str ing $url T he URL to which to c onnect | |
| 2003 | * @access pr ivate | |
| 2004 | */ | |
| 2005 | fu nction set URL($url) { | |
| 2006 | $thi s->url = $ url; | |
| 2007 | ||
| 2008 | $u = parse_url ($url); | |
| 2009 | fore ach($u as $k => $v){ | |
| 2010 | $this- >debug("pa rsed URL $ k = $v"); | |
| 2011 | $this- >$k = $v; | |
| 2012 | } | |
| 2013 | ||
| 2014 | // a dd any GET params to path | |
| 2015 | if(i sset($u['q uery']) && $u['query '] != ''){ | |
| 2016 | $this->p ath .= '?' . $u['que ry']; | |
| 2017 | } | |
| 2018 | ||
| 2019 | // s et default port | |
| 2020 | if(! isset($u[' port'])){ | |
| 2021 | if($u[ 'scheme'] == 'https' ){ | |
| 2022 | $this->p ort = 443; | |
| 2023 | } else { | |
| 2024 | $this->p ort = 80; | |
| 2025 | } | |
| 2026 | } | |
| 2027 | ||
| 2028 | $thi s->uri = $ this->path ; | |
| 2029 | $thi s->digest_ uri = $thi s->uri; | |
| 2030 | ||
| 2031 | // b uild heade rs | |
| 2032 | if ( !isset($u[ 'port'])) { | |
| 2033 | $this- >setHeader ('Host', $ this->host ); | |
| 2034 | } el se { | |
| 2035 | $this- >setHeader ('Host', $ this->host .':'.$this ->port); | |
| 2036 | } | |
| 2037 | ||
| 2038 | if ( isset($u[' user']) && $u['user' ] != '') { | |
| 2039 | $this- >setCreden tials(urld ecode($u[' user']), i sset($u['p ass']) ? u rldecode($ u['pass']) : ''); | |
| 2040 | } | |
| 2041 | } | |
| 2042 | ||
| 2043 | /* * | |
| 2044 | * gets the I /O method to use | |
| 2045 | * | |
| 2046 | * @return string I/O meth od to use (socket|cu rl|unknown ) | |
| 2047 | * @access privat e | |
| 2048 | */ | |
| 2049 | fu nction io_ method() { | |
| 2050 | if ( $this->use _curl || ( $this->sch eme == 'ht tps') || ( $this->sch eme == 'ht tp' && $th is->authty pe == 'ntl m') || ($t his->schem e == 'http ' && is_ar ray($this- >proxy) && $this->pr oxy['autht ype'] == ' ntlm')) | |
| 2051 | return 'curl'; | |
| 2052 | if ( ($this->sc heme == 'h ttp' || $t his->schem e == 'ssl' ) && $this ->authtype != 'ntlm' && (!is_a rray($this ->proxy) | | $this->p roxy['auth type'] != 'ntlm')) | |
| 2053 | return 'socket'; | |
| 2054 | retu rn 'unknow n'; | |
| 2055 | } | |
| 2056 | ||
| 2057 | /* * | |
| 2058 | * establish an HTTP co nnection | |
| 2059 | * | |
| 2060 | * @param integer $t imeout set connectio n timeout in seconds | |
| 2061 | * @param intege r $respons e_timeout set respon se timeout in second s | |
| 2062 | * @return boolea n true if connected, false if not | |
| 2063 | * @access private | |
| 2064 | */ | |
| 2065 | fu nction con nect($conn ection_tim eout=0,$re sponse_tim eout=30){ | |
| 2066 | // F or PHP 4.3 with Open SSL, chang e https sc heme to ss l, then tr eat like | |
| 2067 | // " regular" s ocket. | |
| 2068 | // T ODO: disab led for no w because OpenSSL mu st be *com piled* in (not just | |
| 2069 | // loade d), and un til PHP5 s tream_get_ wrappers i s not avai lable. | |
| 2070 | // if ( $this->sch eme == 'ht tps') { | |
| 2071 | // if (ve rsion_comp are(phpver sion(), '4 .3.0') >= 0) { | |
| 2072 | // if (exte nsion_load ed('openss l')) { | |
| 2073 | // $this->sch eme = 'ssl '; | |
| 2074 | // $this->deb ug('Using SSL over O penSSL'); | |
| 2075 | // } | |
| 2076 | // } | |
| 2077 | // } | |
| 2078 | $thi s->debug(" connect co nnection_t imeout $co nnection_t imeout, re sponse_tim eout $resp onse_timeo ut, scheme $this->sc heme, host $this->ho st, port $ this->port "); | |
| 2079 | if ($this- >io_method () == 'soc ket') { | |
| 2080 | if ( !is_array( $this->pro xy)) { | |
| 2081 | $host = $this->h ost; | |
| 2082 | $port = $this->p ort; | |
| 2083 | } el se { | |
| 2084 | $host = $this->p roxy['host ']; | |
| 2085 | $port = $this->p roxy['port ']; | |
| 2086 | } | |
| 2087 | ||
| 2088 | // u se persist ent connec tion | |
| 2089 | if($ this->pers istentConn ection && isset($thi s->fp) && is_resourc e($this->f p)){ | |
| 2090 | if (!f eof($this- >fp)) { | |
| 2091 | $this->d ebug('Re-u se persist ent connec tion'); | |
| 2092 | return t rue; | |
| 2093 | } | |
| 2094 | fclose ($this->fp ); | |
| 2095 | $this- >debug('Cl osed persi stent conn ection at EOF'); | |
| 2096 | } | |
| 2097 | ||
| 2098 | // m unge host if using O penSSL | |
| 2099 | if ( $this->sch eme == 'ss l') { | |
| 2100 | $host = 'ssl://' . $host; | |
| 2101 | } | |
| 2102 | $thi s->debug(' calling fs ockopen wi th host ' . $host . ' connecti on_timeout ' . $conn ection_tim eout); | |
| 2103 | ||
| 2104 | // o pen socket | |
| 2105 | if($ connection _timeout > 0){ | |
| 2106 | $this- >fp = @fso ckopen( $h ost, $this ->port, $t his->errno , $this->e rror_str, $connectio n_timeout) ; | |
| 2107 | } el se { | |
| 2108 | $this- >fp = @fso ckopen( $h ost, $this ->port, $t his->errno , $this->e rror_str); | |
| 2109 | } | |
| 2110 | ||
| 2111 | // t est pointe r | |
| 2112 | if(! $this->fp) { | |
| 2113 | $msg = 'Couldn\' t open soc ket connec tion to se rver ' . $ this->url; | |
| 2114 | if ($t his->errno ) { | |
| 2115 | $msg .= ', Error ( '.$this->e rrno.'): ' .$this->er ror_str; | |
| 2116 | } else { | |
| 2117 | $msg .= ' prior to connect() . This is often a p roblem loo king up th e host nam e.'; | |
| 2118 | } | |
| 2119 | $this- >debug($ms g); | |
| 2120 | $this- >setError( $msg); | |
| 2121 | return false; | |
| 2122 | } | |
| 2123 | ||
| 2124 | // s et respons e timeout | |
| 2125 | $thi s->debug(' set respon se timeout to ' . $r esponse_ti meout); | |
| 2126 | sock et_set_tim eout( $thi s->fp, $re sponse_tim eout); | |
| 2127 | ||
| 2128 | $thi s->debug(' socket con nected'); | |
| 2129 | retu rn true; | |
| 2130 | } else if ($this->io _method() == 'curl') { | |
| 2131 | if ( !extension _loaded('c url')) { | |
| 2132 | // $this- >setError( 'cURL Exte nsion, or OpenSSL ex tension w/ PHP versi on >= 4.3 is require d for HTTP S'); | |
| 2133 | $this- >setError( 'The PHP c URL Extens ion is req uired for HTTPS or N LTM. You will need to re-buil d or updat e your PHP to includ e cURL or change php .ini to lo ad the PHP cURL exte nsion.'); | |
| 2134 | return false; | |
| 2135 | } | |
| 2136 | // A void warni ngs when P HP does no t have the se options | |
| 2137 | if ( defined('C URLOPT_CON NECTIONTIM EOUT')) | |
| 2138 | $CURLO PT_CONNECT IONTIMEOUT = CURLOPT _CONNECTIO NTIMEOUT; | |
| 2139 | else | |
| 2140 | $CURLO PT_CONNECT IONTIMEOUT = 78; | |
| 2141 | if ( defined('C URLOPT_HTT PAUTH')) | |
| 2142 | $CURLO PT_HTTPAUT H = CURLOP T_HTTPAUTH ; | |
| 2143 | else | |
| 2144 | $CURLO PT_HTTPAUT H = 107; | |
| 2145 | if ( defined('C URLOPT_PRO XYAUTH')) | |
| 2146 | $CURLO PT_PROXYAU TH = CURLO PT_PROXYAU TH; | |
| 2147 | else | |
| 2148 | $CURLO PT_PROXYAU TH = 111; | |
| 2149 | if ( defined('C URLAUTH_BA SIC')) | |
| 2150 | $CURLA UTH_BASIC = CURLAUTH _BASIC; | |
| 2151 | else | |
| 2152 | $CURLA UTH_BASIC = 1; | |
| 2153 | if ( defined('C URLAUTH_DI GEST')) | |
| 2154 | $CURLA UTH_DIGEST = CURLAUT H_DIGEST; | |
| 2155 | else | |
| 2156 | $CURLA UTH_DIGEST = 2; | |
| 2157 | if ( defined('C URLAUTH_NT LM')) | |
| 2158 | $CURLA UTH_NTLM = CURLAUTH_ NTLM; | |
| 2159 | else | |
| 2160 | $CURLA UTH_NTLM = 8; | |
| 2161 | ||
| 2162 | $thi s->debug(' connect us ing cURL') ; | |
| 2163 | // i nit CURL | |
| 2164 | $thi s->ch = cu rl_init(); | |
| 2165 | // s et url | |
| 2166 | $hos tURL = ($t his->port != '') ? " $this->sch eme://$thi s->host:$t his->port" : "$this- >scheme:// $this->hos t"; | |
| 2167 | // a dd path | |
| 2168 | $hos tURL .= $t his->path; | |
| 2169 | $thi s->setCurl Option(CUR LOPT_URL, $hostURL); | |
| 2170 | // f ollow loca tion heade rs (re-dir ects) | |
| 2171 | if ( ini_get('s afe_mode') || ini_ge t('open_ba sedir')) { | |
| 2172 | $this- >debug('sa fe_mode or open_base dir set, s o do not s et CURLOPT _FOLLOWLOC ATION'); | |
| 2173 | $this- >debug('sa fe_mode = '); | |
| 2174 | $this- >appendDeb ug($this-> varDump(in i_get('saf e_mode'))) ; | |
| 2175 | $this- >debug('op en_basedir = '); | |
| 2176 | $this- >appendDeb ug($this-> varDump(in i_get('ope n_basedir' ))); | |
| 2177 | } el se { | |
| 2178 | $this- >setCurlOp tion(CURLO PT_FOLLOWL OCATION, 1 ); | |
| 2179 | } | |
| 2180 | // a sk for hea ders in th e response output | |
| 2181 | $thi s->setCurl Option(CUR LOPT_HEADE R, 1); | |
| 2182 | // a sk for the response output as the return value | |
| 2183 | $thi s->setCurl Option(CUR LOPT_RETUR NTRANSFER, 1); | |
| 2184 | // e ncode | |
| 2185 | // W e manage t his oursel ves throug h headers and encodi ng | |
| 2186 | // if(f unction_ex ists('gzun compress') ){ | |
| 2187 | // $this- >setCurlOp tion(CURLO PT_ENCODIN G, 'deflat e'); | |
| 2188 | // } | |
| 2189 | // p ersistent connection | |
| 2190 | if ( $this->per sistentCon nection) { | |
| 2191 | // I b elieve the following comment i s now bogu s, having applied to | |
| 2192 | // the code when it used C URLOPT_CUS TOMREQUEST to send t he request . | |
| 2193 | // The way we se nd data, w e cannot u se persist ent connec tions, sin ce | |
| 2194 | // the re will be some "jun k" at the end of our request. | |
| 2195 | //$thi s->setCurl Option(CUR L_HTTP_VER SION_1_1, true); | |
| 2196 | $this- >persisten tConnectio n = false; | |
| 2197 | $this- >setHeader ('Connecti on', 'clos e'); | |
| 2198 | } | |
| 2199 | // s et timeout s | |
| 2200 | if ( $connectio n_timeout != 0) { | |
| 2201 | $this- >setCurlOp tion($CURL OPT_CONNEC TIONTIMEOU T, $connec tion_timeo ut); | |
| 2202 | } | |
| 2203 | if ( $response_ timeout != 0) { | |
| 2204 | $this- >setCurlOp tion(CURLO PT_TIMEOUT , $respons e_timeout) ; | |
| 2205 | } | |
| 2206 | ||
| 2207 | if ( $this->sch eme == 'ht tps') { | |
| 2208 | $this- >debug('se t cURL SSL verify op tions'); | |
| 2209 | // rec ent versio ns of cURL turn on p eer/host c hecking by default, | |
| 2210 | // whi le PHP bin aries are not compil ed with a default lo cation for the | |
| 2211 | // CA cert bundl e, so disa ble peer/h ost checki ng. | |
| 2212 | //$thi s->setCurl Option(CUR LOPT_CAINF O, 'f:\php -4.3.2-win 32\extensi ons\curl-c a-bundle.c rt'); | |
| 2213 | $this- >setCurlOp tion(CURLO PT_SSL_VER IFYPEER, 0 ); | |
| 2214 | $this- >setCurlOp tion(CURLO PT_SSL_VER IFYHOST, 0 ); | |
| 2215 | ||
| 2216 | // sup port clien t certific ates (than ks Tobias Boes, Doug Anarino, Eryan Ario bowo) | |
| 2217 | if ($t his->autht ype == 'ce rtificate' ) { | |
| 2218 | $this->d ebug('set cURL certi ficate opt ions'); | |
| 2219 | if (isse t($this->c ertRequest ['cainfofi le'])) { | |
| 2220 | $this->set CurlOption (CURLOPT_C AINFO, $th is->certRe quest['cai nfofile']) ; | |
| 2221 | } | |
| 2222 | if (isse t($this->c ertRequest ['verifype er'])) { | |
| 2223 | $this->set CurlOption (CURLOPT_S SL_VERIFYP EER, $this ->certRequ est['verif ypeer']); | |
| 2224 | } else { | |
| 2225 | $this->set CurlOption (CURLOPT_S SL_VERIFYP EER, 1); | |
| 2226 | } | |
| 2227 | if (isse t($this->c ertRequest ['verifyho st'])) { | |
| 2228 | $this->set CurlOption (CURLOPT_S SL_VERIFYH OST, $this ->certRequ est['verif yhost']); | |
| 2229 | } else { | |
| 2230 | $this->set CurlOption (CURLOPT_S SL_VERIFYH OST, 1); | |
| 2231 | } | |
| 2232 | if (isse t($this->c ertRequest ['sslcertf ile'])) { | |
| 2233 | $this->set CurlOption (CURLOPT_S SLCERT, $t his->certR equest['ss lcertfile' ]); | |
| 2234 | } | |
| 2235 | if (isse t($this->c ertRequest ['sslkeyfi le'])) { | |
| 2236 | $this->set CurlOption (CURLOPT_S SLKEY, $th is->certRe quest['ssl keyfile']) ; | |
| 2237 | } | |
| 2238 | if (isse t($this->c ertRequest ['passphra se'])) { | |
| 2239 | $this->set CurlOption (CURLOPT_S SLKEYPASSW D, $this-> certReques t['passphr ase']); | |
| 2240 | } | |
| 2241 | if (isse t($this->c ertRequest ['certpass word'])) { | |
| 2242 | $this->set CurlOption (CURLOPT_S SLCERTPASS WD, $this- >certReque st['certpa ssword']); | |
| 2243 | } | |
| 2244 | } | |
| 2245 | } | |
| 2246 | if ( $this->aut htype && ( $this->aut htype != ' certificat e')) { | |
| 2247 | if ($t his->usern ame) { | |
| 2248 | $this->d ebug('set cURL usern ame/passwo rd'); | |
| 2249 | $this->s etCurlOpti on(CURLOPT _USERPWD, "$this->us ername:$th is->passwo rd"); | |
| 2250 | } | |
| 2251 | if ($t his->autht ype == 'ba sic') { | |
| 2252 | $this->d ebug('set cURL for B asic authe ntication' ); | |
| 2253 | $this->s etCurlOpti on($CURLOP T_HTTPAUTH , $CURLAUT H_BASIC); | |
| 2254 | } | |
| 2255 | if ($t his->autht ype == 'di gest') { | |
| 2256 | $this->d ebug('set cURL for d igest auth entication '); | |
| 2257 | $this->s etCurlOpti on($CURLOP T_HTTPAUTH , $CURLAUT H_DIGEST); | |
| 2258 | } | |
| 2259 | if ($t his->autht ype == 'nt lm') { | |
| 2260 | $this->d ebug('set cURL for N TLM authen tication') ; | |
| 2261 | $this->s etCurlOpti on($CURLOP T_HTTPAUTH , $CURLAUT H_NTLM); | |
| 2262 | } | |
| 2263 | } | |
| 2264 | if ( is_array($ this->prox y)) { | |
| 2265 | $this- >debug('se t cURL pro xy options '); | |
| 2266 | if ($t his->proxy ['port'] ! = '') { | |
| 2267 | $this->s etCurlOpti on(CURLOPT _PROXY, $t his->proxy ['host'].' :'.$this-> proxy['por t']); | |
| 2268 | } else { | |
| 2269 | $this->s etCurlOpti on(CURLOPT _PROXY, $t his->proxy ['host']); | |
| 2270 | } | |
| 2271 | if ($t his->proxy ['username '] || $thi s->proxy[' password'] ) { | |
| 2272 | $this->d ebug('set cURL proxy authentic ation opti ons'); | |
| 2273 | $this->s etCurlOpti on(CURLOPT _PROXYUSER PWD, $this ->proxy['u sername']. ':'.$this- >proxy['pa ssword']); | |
| 2274 | if ($thi s->proxy[' authtype'] == 'basic ') { | |
| 2275 | $this->set CurlOption ($CURLOPT_ PROXYAUTH, $CURLAUTH _BASIC); | |
| 2276 | } | |
| 2277 | if ($thi s->proxy[' authtype'] == 'ntlm' ) { | |
| 2278 | $this->set CurlOption ($CURLOPT_ PROXYAUTH, $CURLAUTH _NTLM); | |
| 2279 | } | |
| 2280 | } | |
| 2281 | } | |
| 2282 | $thi s->debug(' cURL conne ction set up'); | |
| 2283 | retu rn true; | |
| 2284 | } else { | |
| 2285 | $thi s->setErro r('Unknown scheme ' . $this->s cheme); | |
| 2286 | $thi s->debug(' Unknown sc heme ' . $ this->sche me); | |
| 2287 | retu rn false; | |
| 2288 | } | |
| 2289 | } | |
| 2290 | ||
| 2291 | /* * | |
| 2292 | * sends the SOAP reque st and get s the SOAP response via HTTP[S ] | |
| 2293 | * | |
| 2294 | * @param string $da ta message data | |
| 2295 | * @param integer $t imeout set connectio n timeout in seconds | |
| 2296 | * @param intege r $respons e_timeout set respon se timeout in second s | |
| 2297 | * @param array $cookies c ookies to send | |
| 2298 | * @return string data | |
| 2299 | * @access public | |
| 2300 | */ | |
| 2301 | fu nction sen d($data, $ timeout=0, $response _timeout=3 0, $cookie s=NULL) { | |
| 2302 | ||
| 2303 | $thi s->debug(' entered se nd() with data of le ngth: '.st rlen($data )); | |
| 2304 | ||
| 2305 | $thi s->tryagai n = true; | |
| 2306 | $tri es = 0; | |
| 2307 | whil e ($this-> tryagain) { | |
| 2308 | $this- >tryagain = false; | |
| 2309 | if ($t ries++ < 2 ) { | |
| 2310 | // make connnectio n | |
| 2311 | if (!$th is->connec t($timeout , $respons e_timeout) ){ | |
| 2312 | return fal se; | |
| 2313 | } | |
| 2314 | ||
| 2315 | // send request | |
| 2316 | if (!$th is->sendRe quest($dat a, $cookie s)){ | |
| 2317 | return fal se; | |
| 2318 | } | |
| 2319 | ||
| 2320 | // get r esponse | |
| 2321 | $respdat a = $this- >getRespon se(); | |
| 2322 | } else { | |
| 2323 | $this->s etError("T oo many tr ies to get an OK res ponse ($th is->respon se_status_ line)"); | |
| 2324 | } | |
| 2325 | } | |
| 2326 | $thi s->debug(' end of sen d()'); | |
| 2327 | retu rn $respda ta; | |
| 2328 | } | |
| 2329 | ||
| 2330 | ||
| 2331 | /* * | |
| 2332 | * sends the SOAP reque st and get s the SOAP response via HTTPS using CURL | |
| 2333 | * | |
| 2334 | * @param string $da ta message data | |
| 2335 | * @param integer $t imeout set connectio n timeout in seconds | |
| 2336 | * @param intege r $respons e_timeout set respon se timeout in second s | |
| 2337 | * @param array $cookies c ookies to send | |
| 2338 | * @return string data | |
| 2339 | * @access public | |
| 2340 | * @deprecate d | |
| 2341 | */ | |
| 2342 | fu nction sen dHTTPS($da ta, $timeo ut=0, $res ponse_time out=30, $c ookies) { | |
| 2343 | retu rn $this-> send($data , $timeout , $respons e_timeout, $cookies) ; | |
| 2344 | } | |
| 2345 | ||
| 2346 | /* * | |
| 2347 | * if authent icating, s et user cr edentials here | |
| 2348 | * | |
| 2349 | * @param string $us ername | |
| 2350 | * @param string $pa ssword | |
| 2351 | * @param string $authtype (basic|di gest|certi ficate|ntl m) | |
| 2352 | * @param array $digestReq uest (keys must be n once, nc, realm, qop ) | |
| 2353 | * @param array $certReque st (keys m ust be cai nfofile (o ptional), sslcertfil e, sslkeyf ile, passp hrase, cer tpassword (optional) , verifype er (option al), verif yhost (opt ional): se e correspo nding opti ons in cUR L docs) | |
| 2354 | * @access public | |
| 2355 | */ | |
| 2356 | fu nction set Credential s($usernam e, $passwo rd, $autht ype = 'bas ic', $dige stRequest = array(), $certRequ est = arra y()) { | |
| 2357 | $this->deb ug("setCre dentials u sername= AI authtype=$ authtype d igestReque st="); | |
| 2358 | $thi s->appendD ebug($this ->varDump( $digestReq uest)); | |
| 2359 | $thi s->debug(" certReques t="); | |
| 2360 | $thi s->appendD ebug($this ->varDump( $certReque st)); | |
| 2361 | // c f. RFC 261 7 | |
| 2362 | if ( $authtype == 'basic' ) { | |
| 2363 | $this- >setHeader ('Authoriz ation', 'B asic '.bas e64_encode (str_repla ce(':','', $username) .':'.$pass word)); | |
| 2364 | } el seif ($aut htype == ' digest') { | |
| 2365 | if (is set($diges tRequest[' nonce'])) { | |
| 2366 | $digestR equest['nc '] = isset ($digestRe quest['nc' ]) ? $dige stRequest[ 'nc']++ : 1; | |
| 2367 | ||
| 2368 | // calcu late the D igest hash es (calcul ate code b ased on di gest imple mentation found at: http://www .rassoc.co m/gregr/we blog/stori es/2002/07 /09/webSer vicesSecur ityHttpDig estAuthent icationWit houtActive Directory. html) | |
| 2369 | ||
| 2370 | // A1 = unq(userna me-value) ":" unq(re alm-value) ":" passw d | |
| 2371 | $A1 = $u sername. ' :' . (isse t($digestR equest['re alm']) ? $ digestRequ est['realm '] : '') . ':' . $pa ssword; | |
| 2372 | ||
| 2373 | // H(A1) = MD5(A1) | |
| 2374 | $HA1 = m d5($A1); | |
| 2375 | ||
| 2376 | // A2 = Method ":" digest-ur i-value | |
| 2377 | $A2 = $t his->reque st_method . ':' . $t his->diges t_uri; | |
| 2378 | ||
| 2379 | // H(A2) | |
| 2380 | $HA2 = md5($A2); | |
| 2381 | ||
| 2382 | // KD(se cret, data ) = H(conc at(secret, ":", data )) | |
| 2383 | // if qo p == auth: | |
| 2384 | // reque st-digest = <"> < K D ( H(A1), unq(n once-value ) | |
| 2385 | // ":" nc -value | |
| 2386 | // ":" un q(cnonce-v alue) | |
| 2387 | // ":" un q(qop-valu e) | |
| 2388 | // ":" H( A2) | |
| 2389 | // ) <"> | |
| 2390 | // if qo p is missi ng, | |
| 2391 | // reque st-digest = <"> < K D ( H(A1), unq(nonce -value) ": " H(A2) ) > <"> | |
| 2392 | ||
| 2393 | $unhashe dDigest = ''; | |
| 2394 | $nonce = isset($di gestReques t['nonce'] ) ? $diges tRequest[' nonce'] : ''; | |
| 2395 | $cnonce = $nonce; | |
| 2396 | if ($dig estRequest ['qop'] != '') { | |
| 2397 | $unhashedD igest = $H A1 . ':' . $nonce . ':' . spri ntf("%08d" , $digestR equest['nc ']) . ':' . $cnonce . ':' . $d igestReque st['qop'] . ':' . $H A2; | |
| 2398 | } else { | |
| 2399 | $unhashedD igest = $H A1 . ':' . $nonce . ':' . $HA2 ; | |
| 2400 | } | |
| 2401 | ||
| 2402 | $hashedD igest = md 5($unhashe dDigest); | |
| 2403 | ||
| 2404 | $opaque = ''; | |
| 2405 | if (isse t($digestR equest['op aque'])) { | |
| 2406 | $opaque = ', opaque= "' . $dige stRequest[ 'opaque'] . '"'; | |
| 2407 | } | |
| 2408 | ||
| 2409 | $this->set Header('Au thorizatio n', 'Diges t username =" AI ' . $usern ame . '", realm="' . $digestRe quest['rea lm'] . '", nonce="' . $nonce . '", uri=" ' . $this- >digest_ur i . $opaqu e . '", cn once="' . $cnonce . '", nc=' . sprintf(" %08x", $di gestReques t['nc']) . ', qop="' . $digest Request['q op'] . '", response= "' . $hash edDigest . '"'); | |
| 2410 | } | |
| 2411 | } el seif ($aut htype == ' certificat e') { | |
| 2412 | $this- >certReque st = $cert Request; | |
| 2413 | $this- >debug('Au thorizatio n header n ot set for certifica te'); | |
| 2414 | } el seif ($aut htype == ' ntlm') { | |
| 2415 | // do nothing | |
| 2416 | $this- >debug('Au thorizatio n header n ot set for ntlm'); | |
| 2417 | } | |
| 2418 | $thi s->usernam e = $usern ame; | |
| 2419 | $thi s->passwor d = $passw ord; | |
| 2420 | $thi s->authtyp e = $autht ype; | |
| 2421 | $thi s->digestR equest = $ digestRequ est; | |
| 2422 | } | |
| 2423 | ||
| 2424 | /* * | |
| 2425 | * set the so apaction v alue | |
| 2426 | * | |
| 2427 | * @param string $so apaction | |
| 2428 | * @access public | |
| 2429 | */ | |
| 2430 | fu nction set SOAPAction ($soapacti on) { | |
| 2431 | $thi s->setHead er('SOAPAc tion', '"' . $soapac tion . '"' ); | |
| 2432 | } | |
| 2433 | ||
| 2434 | /* * | |
| 2435 | * use http e ncoding | |
| 2436 | * | |
| 2437 | * @param string $en c encoding style. su pported va lues: gzip , deflate, or both | |
| 2438 | * @access public | |
| 2439 | */ | |
| 2440 | fu nction set Encoding($ enc='gzip, deflate') { | |
| 2441 | if ( function_e xists('gzd eflate')) { | |
| 2442 | $this- >protocol_ version = '1.1'; | |
| 2443 | $this- >setHeader ('Accept-E ncoding', $enc); | |
| 2444 | if (!i sset($this ->outgoing _headers[' Connection '])) { | |
| 2445 | $this->s etHeader(' Connection ', 'close' ); | |
| 2446 | $this->p ersistentC onnection = false; | |
| 2447 | } | |
| 2448 | // dep recated as of PHP 5. 3.0 | |
| 2449 | //set_ magic_quot es_runtime (0); | |
| 2450 | $this- >encoding = $enc; | |
| 2451 | } | |
| 2452 | } | |
| 2453 | ||
| 2454 | /* * | |
| 2455 | * set proxy info here | |
| 2456 | * | |
| 2457 | * @param string $pr oxyhost us e an empty string to remove pr oxy | |
| 2458 | * @param string $pr oxyport | |
| 2459 | * @param string $proxyuse rname | |
| 2460 | * @param string $proxypas sword | |
| 2461 | * @param string $proxyaut htype (bas ic|ntlm) | |
| 2462 | * @access public | |
| 2463 | */ | |
| 2464 | fu nction set Proxy($pro xyhost, $p roxyport, $proxyuser name = '', $proxypas sword = '' , $proxyau thtype = ' basic') { | |
| 2465 | if ( $proxyhost ) { | |
| 2466 | $this- >proxy = a rray( | |
| 2467 | 'host' = > $proxyho st, | |
| 2468 | 'port' = > $proxypo rt, | |
| 2469 | 'usernam e' => $pro xyusername , | |
| 2470 | 'passwor d' => $pro xypassword , | |
| 2471 | 'authtyp e' => $pro xyauthtype | |
| 2472 | ); | |
| 2473 | if ($p roxyuserna me != '' & & $proxypa ssword != '' && $pro xyauthtype = 'basic' ) { | |
| 2474 | $this->s etHeader(' Proxy-Auth orization' , ' Basic '.base64_e ncode($pro xyusername .':'.$prox ypassword) ); | |
| 2475 | } | |
| 2476 | } el se { | |
| 2477 | $this- >debug('re move proxy '); | |
| 2478 | $proxy = null; | |
| 2479 | unsetH eader('Pro xy-Authori zation'); | |
| 2480 | } | |
| 2481 | } | |
| 2482 | ||
| 2483 | ||
| 2484 | /* * | |
| 2485 | * Test if t he given s tring star ts with a header tha t is to be skipped. | |
| 2486 | * Skippable headers r esult from chunked t ransfer an d proxy re quests. | |
| 2487 | * | |
| 2488 | * @param string $data The string to check. | |
| 2489 | * @returns boolea n Whether a skippabl e header w as found. | |
| 2490 | * @access privat e | |
| 2491 | * / | |
| 2492 | fu nction isS kippableCu rlHeader(& $data) { | |
| 2493 | $ski pHeaders = array( 'HTTP/1.1 100', | |
| 2494 | 'HTTP/ 1.0 301', | |
| 2495 | 'HTTP/ 1.1 301', | |
| 2496 | 'HTTP/ 1.0 302', | |
| 2497 | 'HTTP/ 1.1 302', | |
| 2498 | 'HTTP/ 1.0 401', | |
| 2499 | 'HTTP/ 1.1 401', | |
| 2500 | 'HTTP/ 1.0 200 Co nnection e stablished '); | |
| 2501 | fore ach ($skip Headers as $hd) { | |
| 2502 | $prefi x = substr ($data, 0, strlen($h d)); | |
| 2503 | if ($p refix == $ hd) return true; | |
| 2504 | } | |
| 2505 | ||
| 2506 | retu rn false; | |
| 2507 | } | |
| 2508 | ||
| 2509 | /* * | |
| 2510 | * Writes th e payload, including HTTP head ers, to $t his->outgo ing_payloa d. | |
| 2511 | * | |
| 2512 | * @param string $data HTT P body | |
| 2513 | * @param string $cookie_s tr data fo r HTTP Coo kie header | |
| 2514 | * @return void | |
| 2515 | * @access privat e | |
| 2516 | * / | |
| 2517 | fu nction bui ldPayload( $data, $co okie_str = '') { | |
| 2518 | // N ote: for c URL connec tions, $th is->outgoi ng_payload is ignore d, | |
| 2519 | // a s is the C ontent-Len gth header , but thes e are stil l created as | |
| 2520 | // d ebugging g uides. | |
| 2521 | ||
| 2522 | // a dd content -length he ader | |
| 2523 | if ( $this->req uest_metho d != 'GET' ) { | |
| 2524 | $this- >setHeader ('Content- Length', s trlen($dat a)); | |
| 2525 | } | |
| 2526 | ||
| 2527 | // s tart build ing outgoi ng payload : | |
| 2528 | if ( $this->pro xy) { | |
| 2529 | $uri = $this->ur l; | |
| 2530 | } el se { | |
| 2531 | $uri = $this->ur i; | |
| 2532 | } | |
| 2533 | $req = "$this- >request_m ethod $uri HTTP/$thi s->protoco l_version" ; | |
| 2534 | $thi s->debug(" HTTP reque st: $req") ; | |
| 2535 | $thi s->outgoin g_payload = "$req\r\ n"; | |
| 2536 | ||
| 2537 | // l oop thru h eaders, se rializing | |
| 2538 | fore ach($this- >outgoing_ headers as $k => $v) { | |
| 2539 | $hdr = $k.': '.$ v; | |
| 2540 | $this- >debug("HT TP header: $hdr"); | |
| 2541 | $this- >outgoing_ payload .= "$hdr\r\n "; | |
| 2542 | } | |
| 2543 | ||
| 2544 | // a dd any coo kies | |
| 2545 | if ( $cookie_st r != '') { | |
| 2546 | $hdr = 'Cookie: '.$cookie_ str; | |
| 2547 | $this- >debug("HT TP header: $hdr"); | |
| 2548 | $this- >outgoing_ payload .= "$hdr\r\n "; | |
| 2549 | } | |
| 2550 | ||
| 2551 | // h eader/body separator | |
| 2552 | $thi s->outgoin g_payload .= "\r\n"; | |
| 2553 | ||
| 2554 | // a dd data | |
| 2555 | $thi s->outgoin g_payload .= $data; | |
| 2556 | } | |
| 2557 | ||
| 2558 | /* * | |
| 2559 | * sends the SOAP reque st via HTT P[S] | |
| 2560 | * | |
| 2561 | * @param string $da ta message data | |
| 2562 | * @param array $cookies c ookies to send | |
| 2563 | * @return boolea n true if OK, false if problem | |
| 2564 | * @access private | |
| 2565 | */ | |
| 2566 | fu nction sen dRequest($ data, $coo kies = NUL L) { | |
| 2567 | // b uild cooki e string | |
| 2568 | $coo kie_str = $this->get CookiesFor Request($c ookies, (( $this->sch eme == 'ss l') || ($t his->schem e == 'http s'))); | |
| 2569 | ||
| 2570 | // b uild paylo ad | |
| 2571 | $thi s->buildPa yload($dat a, $cookie _str); | |
| 2572 | ||
| 2573 | if ($this- >io_method () == 'soc ket') { | |
| 2574 | // s end payloa d | |
| 2575 | if(! fputs($thi s->fp, $th is->outgoi ng_payload , strlen($ this->outg oing_paylo ad))) { | |
| 2576 | $this- >setError( 'couldn\'t write mes sage data to socket' ); | |
| 2577 | $this- >debug('co uldn\'t wr ite messag e data to socket'); | |
| 2578 | return false; | |
| 2579 | } | |
| 2580 | $thi s->debug(' wrote data to socket , length = ' . strle n($this->o utgoing_pa yload)); | |
| 2581 | retu rn true; | |
| 2582 | } else if ($this->io _method() == 'curl') { | |
| 2583 | // s et payload | |
| 2584 | // c URL does s ay this sh ould only be the ver b, and in fact it | |
| 2585 | // t urns out t hat the UR I and HTTP version a re appende d to this, which | |
| 2586 | // s ome server s refuse t o work wit h (so we n o longer u se this me thod!) | |
| 2587 | //$t his->setCu rlOption(C URLOPT_CUS TOMREQUEST , $this->o utgoing_pa yload); | |
| 2588 | $cur l_headers = array(); | |
| 2589 | fore ach($this- >outgoing_ headers as $k => $v) { | |
| 2590 | if ($k == 'Conne ction' || $k == 'Con tent-Lengt h' || $k = = 'Host' | | $k == 'A uthorizati on' || $k == 'Proxy- Authorizat ion') { | |
| 2591 | $this->d ebug("Skip cURL head er $k: $v" ); | |
| 2592 | } else { | |
| 2593 | $curl_he aders[] = "$k: $v"; | |
| 2594 | } | |
| 2595 | } | |
| 2596 | if ( $cookie_st r != '') { | |
| 2597 | $curl_ headers[] = 'Cookie: ' . $cook ie_str; | |
| 2598 | } | |
| 2599 | $thi s->setCurl Option(CUR LOPT_HTTPH EADER, $cu rl_headers ); | |
| 2600 | $thi s->debug(' set cURL H TTP header s'); | |
| 2601 | if ( $this->req uest_metho d == "POST ") { | |
| 2602 | $this- >setCurlOp tion(CURLO PT_POST, 1 ); | |
| 2603 | $this- >setCurlOp tion(CURLO PT_POSTFIE LDS, $data ); | |
| 2604 | $this- >debug('se t cURL POS T data'); | |
| 2605 | } el se { | |
| 2606 | } | |
| 2607 | // i nsert cust om user-se t cURL opt ions | |
| 2608 | fore ach ($this ->ch_optio ns as $key => $val) { | |
| 2609 | $this- >setCurlOp tion($key, $val); | |
| 2610 | } | |
| 2611 | ||
| 2612 | $thi s->debug(' set cURL p ayload'); | |
| 2613 | retu rn true; | |
| 2614 | } | |
| 2615 | } | |
| 2616 | ||
| 2617 | /* * | |
| 2618 | * gets the S OAP respon se via HTT P[S] | |
| 2619 | * | |
| 2620 | * @return string the respo nse (also sets membe r variable s like inc oming_payl oad) | |
| 2621 | * @access private | |
| 2622 | */ | |
| 2623 | fu nction get Response() { | |
| 2624 | $thi s->incomin g_payload = ''; | |
| 2625 | ||
| 2626 | if ($this- >io_method () == 'soc ket') { | |
| 2627 | // loop until head ers have b een retrie ved | |
| 2628 | $data = ''; | |
| 2629 | while (! isset($lb) ){ | |
| 2630 | ||
| 2631 | // We might EOF during hea der read. | |
| 2632 | if(feo f($this->f p)) { | |
| 2633 | $this->i ncoming_pa yload = $d ata; | |
| 2634 | $this->d ebug('foun d no heade rs before EOF after length ' . strlen($d ata)); | |
| 2635 | $this->d ebug("rece ived befor e EOF:\n" . $data); | |
| 2636 | $this->s etError('s erver fail ed to send headers') ; | |
| 2637 | return f alse; | |
| 2638 | } | |
| 2639 | ||
| 2640 | $tmp = fgets($th is->fp, 25 6); | |
| 2641 | $tmple n = strlen ($tmp); | |
| 2642 | $this- >debug("re ad line of $tmplen b ytes: " . trim($tmp) ); | |
| 2643 | ||
| 2644 | if ($t mplen == 0 ) { | |
| 2645 | $this->i ncoming_pa yload = $d ata; | |
| 2646 | $this->d ebug('sock et read of headers t imed out a fter lengt h ' . strl en($data)) ; | |
| 2647 | $this->d ebug("read before ti meout: " . $data); | |
| 2648 | $this->s etError('s ocket read of header s timed ou t'); | |
| 2649 | return f alse; | |
| 2650 | } | |
| 2651 | ||
| 2652 | $data .= $tmp; | |
| 2653 | $pos = strpos($d ata,"\r\n\ r\n"); | |
| 2654 | if($po s > 1){ | |
| 2655 | $lb = "\ r\n"; | |
| 2656 | } else { | |
| 2657 | $pos = s trpos($dat a,"\n\n"); | |
| 2658 | if($pos > 1){ | |
| 2659 | $lb = "\n" ; | |
| 2660 | } | |
| 2661 | } | |
| 2662 | // rem ove 100 he aders | |
| 2663 | if (is set($lb) & & preg_mat ch('/^HTTP \/1.1 100/ ',$data)) { | |
| 2664 | unset($l b); | |
| 2665 | $data = ''; | |
| 2666 | }// | |
| 2667 | } | |
| 2668 | // s tore heade r data | |
| 2669 | $thi s->incomin g_payload .= $data; | |
| 2670 | $thi s->debug(' found end of headers after len gth ' . st rlen($data )); | |
| 2671 | // p rocess hea ders | |
| 2672 | $hea der_data = trim(subs tr($data,0 ,$pos)); | |
| 2673 | $hea der_array = explode( $lb,$heade r_data); | |
| 2674 | $thi s->incomin g_headers = array(); | |
| 2675 | $thi s->incomin g_cookies = array(); | |
| 2676 | fore ach($heade r_array as $header_l ine){ | |
| 2677 | $arr = explode(' :',$header _line, 2); | |
| 2678 | if(cou nt($arr) > 1){ | |
| 2679 | $header_ name = str tolower(tr im($arr[0] )); | |
| 2680 | $this->i ncoming_he aders[$hea der_name] = trim($ar r[1]); | |
| 2681 | if ($hea der_name = = 'set-coo kie') { | |
| 2682 | // TODO: a llow multi ple cookie s from par seCookie | |
| 2683 | $cookie = $this->par seCookie(t rim($arr[1 ])); | |
| 2684 | if ($cooki e) { | |
| 2685 | $t his->incom ing_cookie s[] = $coo kie; | |
| 2686 | $t his->debug ('found co okie: ' . $cookie['n ame'] . ' = ' . $coo kie['value ']); | |
| 2687 | } else { | |
| 2688 | $t his->debug ('did not find cooki e in ' . t rim($arr[1 ])); | |
| 2689 | } | |
| 2690 | } | |
| 2691 | } else if (isset ($header_n ame)) { | |
| 2692 | // appen d continua tion line to previou s header | |
| 2693 | $this->i ncoming_he aders[$hea der_name] .= $lb . ' ' . $head er_line; | |
| 2694 | } | |
| 2695 | } | |
| 2696 | ||
| 2697 | // l oop until msg has be en receive d | |
| 2698 | if ( isset($thi s->incomin g_headers[ 'transfer- encoding'] ) && strto lower($thi s->incomin g_headers[ 'transfer- encoding'] ) == 'chun ked') { | |
| 2699 | $conte nt_length = 2147483 647; // i gnore any content-le ngth heade r | |
| 2700 | $chunk ed = true; | |
| 2701 | $this- >debug("wa nt to read chunked c ontent"); | |
| 2702 | } el seif (isse t($this->i ncoming_he aders['con tent-lengt h'])) { | |
| 2703 | $conte nt_length = $this->i ncoming_he aders['con tent-lengt h']; | |
| 2704 | $chunk ed = false ; | |
| 2705 | $this- >debug("wa nt to read content o f length $ content_le ngth"); | |
| 2706 | } el se { | |
| 2707 | $conte nt_length = 2147483 647; | |
| 2708 | $chunk ed = false ; | |
| 2709 | $this- >debug("wa nt to read content t o EOF"); | |
| 2710 | } | |
| 2711 | $dat a = ''; | |
| 2712 | do { | |
| 2713 | if ($c hunked) { | |
| 2714 | $tmp = f gets($this ->fp, 256) ; | |
| 2715 | $tmplen = strlen($ tmp); | |
| 2716 | $this->d ebug("read chunk lin e of $tmpl en bytes") ; | |
| 2717 | if ($tmp len == 0) { | |
| 2718 | $this->inc oming_payl oad = $dat a; | |
| 2719 | $this->deb ug('socket read of c hunk lengt h timed ou t after le ngth ' . s trlen($dat a)); | |
| 2720 | $this->deb ug("read b efore time out:\n" . $data); | |
| 2721 | $this->set Error('soc ket read o f chunk le ngth timed out'); | |
| 2722 | return fal se; | |
| 2723 | } | |
| 2724 | $content _length = hexdec(tri m($tmp)); | |
| 2725 | $this->d ebug("chun k length $ content_le ngth"); | |
| 2726 | } | |
| 2727 | $strle n = 0; | |
| 2728 | while (($s trlen < $c ontent_len gth) && (! feof($this ->fp))) { | |
| 2729 | $readl en = min(8 192, $cont ent_length - $strlen ); | |
| 2730 | $tmp = f read($this ->fp, $rea dlen); | |
| 2731 | $tmplen = strlen($ tmp); | |
| 2732 | $this->d ebug("read buffer of $tmplen b ytes"); | |
| 2733 | if (($tm plen == 0) && (!feof ($this->fp ))) { | |
| 2734 | $this->inc oming_payl oad = $dat a; | |
| 2735 | $this->deb ug('socket read of b ody timed out after length ' . strlen($d ata)); | |
| 2736 | $this->deb ug("read b efore time out:\n" . $data); | |
| 2737 | $this->set Error('soc ket read o f body tim ed out'); | |
| 2738 | return fal se; | |
| 2739 | } | |
| 2740 | $strlen += $tmplen ; | |
| 2741 | $data .= $tmp; | |
| 2742 | } | |
| 2743 | if ($c hunked && ($content_ length > 0 )) { | |
| 2744 | $tmp = f gets($this ->fp, 256) ; | |
| 2745 | $tmplen = strlen($ tmp); | |
| 2746 | $this->d ebug("read chunk ter minator of $tmplen b ytes"); | |
| 2747 | if ($tmp len == 0) { | |
| 2748 | $this->inc oming_payl oad = $dat a; | |
| 2749 | $this->deb ug('socket read of c hunk termi nator time d out afte r length ' . strlen( $data)); | |
| 2750 | $this->deb ug("read b efore time out:\n" . $data); | |
| 2751 | $this->set Error('soc ket read o f chunk te rminator t imed out') ; | |
| 2752 | return fal se; | |
| 2753 | } | |
| 2754 | } | |
| 2755 | } wh ile ($chun ked && ($c ontent_len gth > 0) & & (!feof($ this->fp)) ); | |
| 2756 | if ( feof($this ->fp)) { | |
| 2757 | $this- >debug('re ad to EOF' ); | |
| 2758 | } | |
| 2759 | $thi s->debug(' read body of length ' . strlen ($data)); | |
| 2760 | $thi s->incomin g_payload .= $data; | |
| 2761 | $thi s->debug(' received a total of '.strlen($ this->inco ming_paylo ad).' byte s of data from serve r'); | |
| 2762 | ||
| 2763 | // c lose filep ointer | |
| 2764 | if( | |
| 2765 | (isset ($this->in coming_hea ders['conn ection']) && strtolo wer($this- >incoming_ headers['c onnection' ]) == 'clo se') || | |
| 2766 | (! $th is->persis tentConnec tion) || f eof($this- >fp)){ | |
| 2767 | fclose ($this->fp ); | |
| 2768 | $this- >fp = fals e; | |
| 2769 | $this- >debug('cl osed socke t'); | |
| 2770 | } | |
| 2771 | ||
| 2772 | // c onnection was closed unexpecte dly | |
| 2773 | if($ this->inco ming_paylo ad == ''){ | |
| 2774 | $this- >setError( 'no respon se from se rver'); | |
| 2775 | return false; | |
| 2776 | } | |
| 2777 | ||
| 2778 | } else if ($this->io _method() == 'curl') { | |
| 2779 | // s end and re ceive | |
| 2780 | $thi s->debug(' send and r eceive wit h cURL'); | |
| 2781 | $thi s->incomin g_payload = curl_exe c($this->c h); | |
| 2782 | $dat a = $this- >incoming_ payload; | |
| 2783 | ||
| 2784 | $c Err = curl _error($th is->ch); | |
| 2785 | if ( $cErr != ' ') { | |
| 2786 | $err = 'cURL E RROR: '.cu rl_errno($ this->ch). ': '.$cErr .'<br>'; | |
| 2787 | // T ODO: there is a PHP bug that c an cause t his to SEG V for CURL INFO_CONTE NT_TYPE | |
| 2788 | foreac h(curl_get info($this ->ch) as $ k => $v){ | |
| 2789 | $err .= "$k: $v<br >"; | |
| 2790 | } | |
| 2791 | $this- >debug($er r); | |
| 2792 | $this- >setError( $err); | |
| 2793 | curl_c lose($this ->ch); | |
| 2794 | retu rn false; | |
| 2795 | } el se { | |
| 2796 | //echo '<pre>'; | |
| 2797 | //var_ dump(curl_ getinfo($t his->ch)); | |
| 2798 | //echo '</pre>'; | |
| 2799 | } | |
| 2800 | // c lose curl | |
| 2801 | $thi s->debug(' No cURL er ror, closi ng cURL'); | |
| 2802 | curl _close($th is->ch); | |
| 2803 | ||
| 2804 | // t ry removin g skippabl e headers | |
| 2805 | $sav edata = $d ata; | |
| 2806 | whil e ($this-> isSkippabl eCurlHeade r($data)) { | |
| 2807 | $this- >debug("Fo und HTTP h eader to s kip"); | |
| 2808 | if ($p os = strpo s($data,"\ r\n\r\n")) { | |
| 2809 | $data = ltrim(subs tr($data,$ pos)); | |
| 2810 | } else if($pos = strpos($da ta,"\n\n") ) { | |
| 2811 | $data = ltrim(subs tr($data,$ pos)); | |
| 2812 | } | |
| 2813 | } | |
| 2814 | ||
| 2815 | if ( $data == ' ') { | |
| 2816 | // hav e nothing left; just remove 10 0 header(s ) | |
| 2817 | $data = $savedat a; | |
| 2818 | while (preg_matc h('/^HTTP\ /1.1 100/' ,$data)) { | |
| 2819 | if ($pos = strpos( $data,"\r\ n\r\n")) { | |
| 2820 | $data = lt rim(substr ($data,$po s)); | |
| 2821 | } elseif ($pos = st rpos($data ,"\n\n") ) { | |
| 2822 | $data = lt rim(substr ($data,$po s)); | |
| 2823 | } | |
| 2824 | } | |
| 2825 | } | |
| 2826 | ||
| 2827 | // s eparate co ntent from HTTP head ers | |
| 2828 | if ( $pos = str pos($data, "\r\n\r\n" )) { | |
| 2829 | $lb = "\r\n"; | |
| 2830 | } el seif( $pos = strpos( $data,"\n\ n")) { | |
| 2831 | $lb = "\n"; | |
| 2832 | } el se { | |
| 2833 | $this- >debug('no proper se paration o f headers and docume nt'); | |
| 2834 | $this- >setError( 'no proper separatio n of heade rs and doc ument'); | |
| 2835 | return false; | |
| 2836 | } | |
| 2837 | $hea der_data = trim(subs tr($data,0 ,$pos)); | |
| 2838 | $hea der_array = explode( $lb,$heade r_data); | |
| 2839 | $dat a = ltrim( substr($da ta,$pos)); | |
| 2840 | $thi s->debug(' found prop er separat ion of hea ders and d ocument'); | |
| 2841 | $thi s->debug(' cleaned da ta, string len: '.str len($data) ); | |
| 2842 | // c lean heade rs | |
| 2843 | fore ach ($head er_array a s $header_ line) { | |
| 2844 | $arr = explode(' :',$header _line,2); | |
| 2845 | if(cou nt($arr) > 1){ | |
| 2846 | $header_ name = str tolower(tr im($arr[0] )); | |
| 2847 | $this->i ncoming_he aders[$hea der_name] = trim($ar r[1]); | |
| 2848 | if ($hea der_name = = 'set-coo kie') { | |
| 2849 | // TODO: a llow multi ple cookie s from par seCookie | |
| 2850 | $cookie = $this->par seCookie(t rim($arr[1 ])); | |
| 2851 | if ($cooki e) { | |
| 2852 | $t his->incom ing_cookie s[] = $coo kie; | |
| 2853 | $t his->debug ('found co okie: ' . $cookie['n ame'] . ' = ' . $coo kie['value ']); | |
| 2854 | } else { | |
| 2855 | $t his->debug ('did not find cooki e in ' . t rim($arr[1 ])); | |
| 2856 | } | |
| 2857 | } | |
| 2858 | } else if (isset ($header_n ame)) { | |
| 2859 | // appen d continua tion line to previou s header | |
| 2860 | $this->i ncoming_he aders[$hea der_name] .= $lb . ' ' . $head er_line; | |
| 2861 | } | |
| 2862 | } | |
| 2863 | } | |
| 2864 | ||
| 2865 | $thi s->respons e_status_l ine = $hea der_array[ 0]; | |
| 2866 | $arr = explode (' ', $thi s->respons e_status_l ine, 3); | |
| 2867 | $htt p_version = $arr[0]; | |
| 2868 | $htt p_status = intval($a rr[1]); | |
| 2869 | $htt p_reason = count($ar r) > 2 ? $ arr[2] : ' '; | |
| 2870 | ||
| 2871 | // s ee if we n eed to res end the re quest with http dige st authent ication | |
| 2872 | if ( isset($thi s->incomin g_headers[ 'location' ]) && ($ht tp_status == 301 || $http_stat us == 302) ) { | |
| 2873 | $this- >debug("Go t $http_st atus $http _reason wi th Locatio n: " . $th is->incomi ng_headers ['location ']); | |
| 2874 | $this- >setURL($t his->incom ing_header s['locatio n']); | |
| 2875 | $this- >tryagain = true; | |
| 2876 | return false; | |
| 2877 | } | |
| 2878 | ||
| 2879 | // s ee if we n eed to res end the re quest with http dige st authent ication | |
| 2880 | if ( isset($thi s->incomin g_headers[ 'www-authe nticate']) && $http_ status == 401) { | |
| 2881 | $this- >debug("Go t 401 $htt p_reason w ith WWW-Au thenticate : " . $thi s->incomin g_headers[ 'www-authe nticate']) ; | |
| 2882 | if (st rstr($this ->incoming _headers[' www-authen ticate'], "Digest ") ) { | |
| 2883 | $this->d ebug('Serv er wants d igest auth entication '); | |
| 2884 | // remov e "Digest " from our elements | |
| 2885 | $digestS tring = st r_replace( 'Digest ', '', $this ->incoming _headers[' www-authen ticate']); | |
| 2886 | ||
| 2887 | // parse elements into array | |
| 2888 | $digestE lements = explode(', ', $digest String); | |
| 2889 | foreach ($digestEl ements as $val) { | |
| 2890 | $tempEleme nt = explo de('=', tr im($val), 2); | |
| 2891 | $digestReq uest[$temp Element[0] ] = str_re place("\"" , '', $tem pElement[1 ]); | |
| 2892 | } | |
| 2893 | ||
| 2894 | // shoul d have (at least) qo p, realm, nonce | |
| 2895 | if (isse t($digestR equest['no nce'])) { | |
| 2896 | $this->set Credential s($this->u sername, $ this->pass word, 'dig est', $dig estRequest ); | |
| 2897 | $this->try again = tr ue; | |
| 2898 | return fal se; | |
| 2899 | } | |
| 2900 | } | |
| 2901 | $this- >debug('HT TP authent ication fa iled'); | |
| 2902 | $this- >setError( 'HTTP auth entication failed'); | |
| 2903 | return false; | |
| 2904 | } | |
| 2905 | ||
| 2906 | if ( | |
| 2907 | ($http _status >= 300 && $h ttp_status <= 307) | | | |
| 2908 | ($http _status >= 400 && $h ttp_status <= 417) | | | |
| 2909 | ($http _status >= 501 && $h ttp_status <= 505) | |
| 2910 | ) { | |
| 2911 | $this- >setError( "Unsupport ed HTTP re sponse sta tus $http_ status $ht tp_reason (soapclien t->respons e has cont ents of th e response )"); | |
| 2912 | return false; | |
| 2913 | } | |
| 2914 | ||
| 2915 | // d ecode cont ent-encodi ng | |
| 2916 | if(i sset($this ->incoming _headers[' content-en coding']) && $this-> incoming_h eaders['co ntent-enco ding'] != ''){ | |
| 2917 | if(str tolower($t his->incom ing_header s['content -encoding' ]) == 'def late' || s trtolower( $this->inc oming_head ers['conte nt-encodin g']) == 'g zip'){ | |
| 2918 | // if decoding w orks, use it. else a ssume data wasn't gz encoded | |
| 2919 | if(fun ction_exis ts('gzinfl ate')){ | |
| 2920 | //$timer-> setMarker( 'starting decoding o f gzip/def lated cont ent'); | |
| 2921 | // IIS 5 r equires gz inflate in stead of g zuncompres s (similar to IE 5 a nd gzdefla te v. gzco mpress) | |
| 2922 | // this me ans there are no Zli b headers, although there shou ld be | |
| 2923 | $this->deb ug('The gz inflate fu nction exi sts'); | |
| 2924 | $datalen = strlen($d ata); | |
| 2925 | if ($this- >incoming_ headers['c ontent-enc oding'] == 'deflate' ) { | |
| 2926 | if ($degzdat a = @gzinf late($data )) { | |
| 2927 | $d ata = $deg zdata; | |
| 2928 | $t his->debug ('The payl oad has be en inflate d to ' . s trlen($dat a) . ' byt es'); | |
| 2929 | if (strlen($ data) < $d atalen) { | |
| 2930 | // t est for th e case tha t the payl oad has be en compres sed twice | |
| 2931 | $thi s->debug(' The inflat ed payload is smalle r than the gzipped o ne; try ag ain'); | |
| 2932 | if ($d egzdata = @gzinflate ($data)) { | |
| 2933 | $data = $degzdat a; | |
| 2934 | $this- >debug('Th e payload has been i nflated ag ain to ' . strlen($d ata) . ' b ytes'); | |
| 2935 | } | |
| 2936 | } | |
| 2937 | } else { | |
| 2938 | $t his->debug ('Error us ing gzinfl ate to inf late the p ayload'); | |
| 2939 | $t his->setEr ror('Error using gzi nflate to inflate th e payload' ); | |
| 2940 | } | |
| 2941 | } elseif ( $this->inc oming_head ers['conte nt-encodin g'] == 'gz ip') { | |
| 2942 | if ($degzdat a = @gzinf late(subst r($data, 1 0))) { // do our best | |
| 2943 | $dat a = $degzd ata; | |
| 2944 | $t his->debug ('The payl oad has be en un-gzip ped to ' . strlen($d ata) . ' b ytes'); | |
| 2945 | if (strlen($ data) < $d atalen) { | |
| 2946 | // t est for th e case tha t the payl oad has be en compres sed twice | |
| 2947 | $thi s->debug(' The un-gzi pped paylo ad is smal ler than t he gzipped one; try again'); | |
| 2948 | if ($d egzdata = @gzinflate (substr($d ata, 10))) { | |
| 2949 | $data = $degzdat a; | |
| 2950 | $this- >debug('Th e payload has been u n-gzipped again to ' . strlen( $data) . ' bytes'); | |
| 2951 | } | |
| 2952 | } | |
| 2953 | } else { | |
| 2954 | $t his->debug ('Error us ing gzinfl ate to un- gzip the p ayload'); | |
| 2955 | $thi s->setErro r('Error u sing gzinf late to un -gzip the payload'); | |
| 2956 | } | |
| 2957 | } | |
| 2958 | //$timer-> setMarker( 'finished decoding o f gzip/def lated cont ent'); | |
| 2959 | //print "< xmp>\nde-i nflated:\n ---------- -----\n$da ta\n------ -------\n< /xmp>"; | |
| 2960 | // set dec oded paylo ad | |
| 2961 | $this->inc oming_payl oad = $hea der_data.$ lb.$lb.$da ta; | |
| 2962 | } else { | |
| 2963 | $this->deb ug('The se rver sent compressed data. You r php inst all must h ave the Zl ib extensi on compile d in to su pport this .'); | |
| 2964 | $this->set Error('The server se nt compres sed data. Your php i nstall mus t have the Zlib exte nsion comp iled in to support t his.'); | |
| 2965 | } | |
| 2966 | } else { | |
| 2967 | $this->d ebug('Unsu pported Co ntent-Enco ding ' . $ this->inco ming_heade rs['conten t-encoding ']); | |
| 2968 | $this->s etError('U nsupported Content-E ncoding ' . $this->i ncoming_he aders['con tent-encod ing']); | |
| 2969 | } | |
| 2970 | } el se { | |
| 2971 | $this- >debug('No Content-E ncoding he ader'); | |
| 2972 | } | |
| 2973 | ||
| 2974 | if(s trlen($dat a) == 0){ | |
| 2975 | $this- >debug('no data afte r headers! '); | |
| 2976 | $this- >setError( 'no data p resent aft er HTTP he aders'); | |
| 2977 | return false; | |
| 2978 | } | |
| 2979 | ||
| 2980 | retu rn $data; | |
| 2981 | } | |
| 2982 | ||
| 2983 | /* * | |
| 2984 | * sets the content-ty pe for the SOAP mess age to be sent | |
| 2985 | * | |
| 2986 | * @param string $type the content t ype, MIME style | |
| 2987 | * @param mixed $charset c haracter s et used fo r encoding (or false ) | |
| 2988 | * @access public | |
| 2989 | * / | |
| 2990 | fu nction set ContentTyp e($type, $ charset = false) { | |
| 2991 | $thi s->setHead er('Conten t-Type', $ type . ($c harset ? ' ; charset= ' . $chars et : '')); | |
| 2992 | } | |
| 2993 | ||
| 2994 | /* * | |
| 2995 | * specifies that an H TTP persis tent conne ction shou ld be used | |
| 2996 | * | |
| 2997 | * @return boolea n whether the reques t was hono red by thi s method. | |
| 2998 | * @access public | |
| 2999 | * / | |
| 3000 | fu nction use Persistent Connection (){ | |
| 3001 | if ( isset($thi s->outgoin g_headers[ 'Accept-En coding'])) { | |
| 3002 | return false; | |
| 3003 | } | |
| 3004 | $thi s->protoco l_version = '1.1'; | |
| 3005 | $thi s->persist entConnect ion = true ; | |
| 3006 | $thi s->setHead er('Connec tion', 'Ke ep-Alive') ; | |
| 3007 | retu rn true; | |
| 3008 | } | |
| 3009 | ||
| 3010 | /* * | |
| 3011 | * parse an incoming C ookie into it's part s | |
| 3012 | * | |
| 3013 | * @param string $cookie_s tr content of cookie | |
| 3014 | * @return array with data of that co okie | |
| 3015 | * @access privat e | |
| 3016 | * / | |
| 3017 | /* | |
| 3018 | * TODO: all ow a Set-C ookie stri ng to be p arsed into multiple cookies | |
| 3019 | * / | |
| 3020 | fu nction par seCookie($ cookie_str ) { | |
| 3021 | $coo kie_str = str_replac e('; ', '; ', $cookie _str) . '; '; | |
| 3022 | $dat a = preg_s plit('/;/' , $cookie_ str); | |
| 3023 | $val ue_str = $ data[0]; | |
| 3024 | ||
| 3025 | $coo kie_param = 'domain= '; | |
| 3026 | $sta rt = strpo s($cookie_ str, $cook ie_param); | |
| 3027 | if ( $start > 0 ) { | |
| 3028 | $domai n = substr ($cookie_s tr, $start + strlen( $cookie_pa ram)); | |
| 3029 | $domai n = substr ($domain, 0, strpos( $domain, ' ;')); | |
| 3030 | } el se { | |
| 3031 | $domai n = ''; | |
| 3032 | } | |
| 3033 | ||
| 3034 | $coo kie_param = 'expires ='; | |
| 3035 | $sta rt = strpo s($cookie_ str, $cook ie_param); | |
| 3036 | if ( $start > 0 ) { | |
| 3037 | $expir es = subst r($cookie_ str, $star t + strlen ($cookie_p aram)); | |
| 3038 | $expir es = subst r($expires , 0, strpo s($expires , ';')); | |
| 3039 | } el se { | |
| 3040 | $expir es = ''; | |
| 3041 | } | |
| 3042 | ||
| 3043 | $coo kie_param = 'path='; | |
| 3044 | $sta rt = strpo s($cookie_ str, $cook ie_param); | |
| 3045 | if ( $start > 0 ) { | |
| 3046 | $path = substr($ cookie_str , $start + strlen($c ookie_para m)); | |
| 3047 | $path = substr($ path, 0, s trpos($pat h, ';')); | |
| 3048 | } el se { | |
| 3049 | $path = '/'; | |
| 3050 | } | |
| 3051 | ||
| 3052 | $coo kie_param = ';secure ;'; | |
| 3053 | if ( strpos($co okie_str, $cookie_pa ram) !== F ALSE) { | |
| 3054 | $secur e = true; | |
| 3055 | } el se { | |
| 3056 | $secur e = false; | |
| 3057 | } | |
| 3058 | ||
| 3059 | $sep _pos = str pos($value _str, '=') ; | |
| 3060 | ||
| 3061 | if ( $sep_pos) { | |
| 3062 | $name = substr($ value_str, 0, $sep_p os); | |
| 3063 | $value = substr( $value_str , $sep_pos + 1); | |
| 3064 | $cooki e= array( 'name' => $name, | |
| 3065 | 'value' => $value, | |
| 3066 | 'dom ain' => $d omain, | |
| 3067 | 'pat h' => $pat h, | |
| 3068 | 'exp ires' => $ expires, | |
| 3069 | 'sec ure' => $s ecure | |
| 3070 | ); | |
| 3071 | return $cookie; | |
| 3072 | } | |
| 3073 | retu rn false; | |
| 3074 | } | |
| 3075 | ||
| 3076 | /* * | |
| 3077 | * sort out cookies fo r the curr ent reques t | |
| 3078 | * | |
| 3079 | * @param array $cookies a rray with all cookie s | |
| 3080 | * @param boolea n $secure is the sen d-content secure or not? | |
| 3081 | * @return string for Cooki e-HTTP-Hea der | |
| 3082 | * @access privat e | |
| 3083 | * / | |
| 3084 | fu nction get CookiesFor Request($c ookies, $s ecure=fals e) { | |
| 3085 | $coo kie_str = ''; | |
| 3086 | if ( (! is_null ($cookies) ) && (is_a rray($cook ies))) { | |
| 3087 | foreac h ($cookie s as $cook ie) { | |
| 3088 | if (! is _array($co okie)) { | |
| 3089 | continue; | |
| 3090 | } | |
| 3091 | $this- >debug("ch eck cookie for valid ity: ".$co okie['name '].'='.$co okie['valu e']); | |
| 3092 | if ((iss et($cookie ['expires' ])) && (! empty($coo kie['expir es']))) { | |
| 3093 | if (strtot ime($cooki e['expires ']) <= tim e()) { | |
| 3094 | $t his->debug ('cookie h as expired '); | |
| 3095 | co ntinue; | |
| 3096 | } | |
| 3097 | } | |
| 3098 | if ((iss et($cookie ['domain'] )) && (! e mpty($cook ie['domain ']))) { | |
| 3099 | $domain = preg_quote ($cookie[' domain']); | |
| 3100 | if (! preg _match("'. *$domain$' i", $this- >host)) { | |
| 3101 | $t his->debug ('cookie h as differe nt domain' ); | |
| 3102 | co ntinue; | |
| 3103 | } | |
| 3104 | } | |
| 3105 | if ((iss et($cookie ['path'])) && (! emp ty($cookie ['path'])) ) { | |
| 3106 | $path = pr eg_quote($ cookie['pa th']); | |
| 3107 | if (! preg _match("'^ $path.*'i" , $this->p ath)) { | |
| 3108 | $t his->debug ('cookie i s for a di fferent pa th'); | |
| 3109 | co ntinue; | |
| 3110 | } | |
| 3111 | } | |
| 3112 | if ((! $ secure) && (isset($c ookie['sec ure'])) && ($cookie[ 'secure']) ) { | |
| 3113 | $this->deb ug('cookie is secure , transpor t is not') ; | |
| 3114 | continue; | |
| 3115 | } | |
| 3116 | $cookie_ str .= $co okie['name '] . '=' . $cookie[' value'] . '; '; | |
| 3117 | $this- >debug('ad d cookie t o Cookie-S tring: ' . $cookie[' name'] . ' =' . $cook ie['value' ]); | |
| 3118 | } | |
| 3119 | } | |
| 3120 | retu rn $cookie _str; | |
| 3121 | } | |
| 3122 | } | |
| 3123 | ||
| 3124 | ||
| 3125 | ||
| 3126 | /** | |
| 3127 | * parses a WSDL file , allows a ccess to i t's data, other util ity method s. | |
| 3128 | * also bui lds WSDL s tructures programmat ically. | |
| 3129 | * | |
| 3130 | * @author Dietrich Ayala <di etrich@gan x4.com> | |
| 3131 | * @author Scott Ni chol <snic hol@users. sourceforg e.net> | |
| 3132 | * @version $Id: nus oap.php,v 1.123 2010 /04/26 20: 15:08 snic hol Exp $ | |
| 3133 | * @access public | |
| 3134 | * @package third-par ty | |
| 3135 | * @subpack age nusoap | |
| 3136 | */ | |
| 3137 | class wsdl extends n usoap_base { | |
| 3138 | // URL or fi lename of the root o f this WSD L | |
| 3139 | var $w sdl; | |
| 3140 | // def ine intern al arrays of binding s, ports, operations , messages , etc. | |
| 3141 | var $s chemas = a rray(); | |
| 3142 | var $c urrentSche ma; | |
| 3143 | var $m essage = a rray(); | |
| 3144 | var $c omplexType s = array( ); | |
| 3145 | var $m essages = array(); | |
| 3146 | var $c urrentMess age; | |
| 3147 | var $c urrentOper ation; | |
| 3148 | var $p ortTypes = array(); | |
| 3149 | var $c urrentPort Type; | |
| 3150 | var $b indings = array(); | |
| 3151 | var $c urrentBind ing; | |
| 3152 | var $p orts = arr ay(); | |
| 3153 | var $c urrentPort ; | |
| 3154 | var $o pData = ar ray(); | |
| 3155 | var $s tatus = '' ; | |
| 3156 | var $d ocumentati on = false ; | |
| 3157 | var $e ndpoint = ''; | |
| 3158 | // arr ay of wsdl docs to i mport | |
| 3159 | var $i mport = ar ray(); | |
| 3160 | // par ser vars | |
| 3161 | var $p arser; | |
| 3162 | var $p osition = 0; | |
| 3163 | var $d epth = 0; | |
| 3164 | var $d epth_array = array() ; | |
| 3165 | // for getti ng wsdl | |
| 3166 | va r $proxyho st = ''; | |
| 3167 | var $p roxyport = ''; | |
| 3168 | va r $proxyus ername = ' '; | |
| 3169 | va r $proxypa ssword = ' '; | |
| 3170 | va r $timeout = 0; | |
| 3171 | va r $respons e_timeout = 30; | |
| 3172 | va r $curl_op tions = ar ray(); // User-sp ecified cU RL options | |
| 3173 | va r $use_cur l = false; // whether t o always t ry to use cURL | |
| 3174 | // for HTTP authentica tion | |
| 3175 | va r $usernam e = ''; // U sername fo r HTTP aut henticatio n | |
| 3176 | va r $passwor d = ''; // P assword fo r HTTP aut henticatio n | |
| 3177 | va r $authtyp e = ''; // T ype of HTT P authenti cation | |
| 3178 | va r $certReq uest = arr ay(); // Certifica te for HTT P SSL auth entication | |
| 3179 | ||
| 3180 | /** | |
| 3181 | * con structor | |
| 3182 | * | |
| 3183 | * @pa ram string $wsdl WSD L document URL | |
| 3184 | * @param st ring $prox yhost | |
| 3185 | * @param st ring $prox yport | |
| 3186 | * @param st ring $prox yusername | |
| 3187 | * @param st ring $prox ypassword | |
| 3188 | * @param in teger $tim eout set t he connect ion timeou t | |
| 3189 | * @param in teger $res ponse_time out set th e response timeout | |
| 3190 | * @param ar ray $curl_ options us er-specifi ed cURL op tions | |
| 3191 | * @param bo olean $use _curl try to use cUR L | |
| 3192 | * @ac cess publi c | |
| 3193 | */ | |
| 3194 | functi on wsdl($w sdl = '',$ proxyhost= false,$pro xyport=fal se,$proxyu sername=fa lse,$proxy password=f alse,$time out=0,$res ponse_time out=30,$cu rl_options =null,$use _curl=fals e){ | |
| 3195 | pare nt::nusoap _base(); | |
| 3196 | $thi s->debug(" ctor wsdl= $wsdl time out=$timeo ut respons e_timeout= $response_ timeout"); | |
| 3197 | $t his->proxy host = $pr oxyhost; | |
| 3198 | $t his->proxy port = $pr oxyport; | |
| 3199 | $thi s->proxyus ername = $ proxyusern ame; | |
| 3200 | $thi s->proxypa ssword = $ proxypassw ord; | |
| 3201 | $thi s->timeout = $timeou t; | |
| 3202 | $thi s->respons e_timeout = $respons e_timeout; | |
| 3203 | if ( is_array($ curl_optio ns)) | |
| 3204 | $this- >curl_opti ons = $cur l_options; | |
| 3205 | $thi s->use_cur l = $use_c url; | |
| 3206 | $thi s->fetchWS DL($wsdl); | |
| 3207 | } | |
| 3208 | ||
| 3209 | /* * | |
| 3210 | * fetches t he WSDL do cument and parses it | |
| 3211 | * | |
| 3212 | * @access p ublic | |
| 3213 | * / | |
| 3214 | fu nction fet chWSDL($ws dl) { | |
| 3215 | $thi s->debug(" parse and process WS DL path=$w sdl"); | |
| 3216 | $thi s->wsdl = $wsdl; | |
| 3217 | // parse wsd l file | |
| 3218 | if ($this->w sdl != "") { | |
| 3219 | $this->p arseWSDL($ this->wsdl ); | |
| 3220 | } | |
| 3221 | // imports | |
| 3222 | // TODO: han dle import s more pro perly, gra bbing them in-line a nd nesting them | |
| 3223 | $i mported_ur ls = array (); | |
| 3224 | $i mported = 1; | |
| 3225 | wh ile ($impo rted > 0) { | |
| 3226 | $imp orted = 0; | |
| 3227 | // S chema impo rts | |
| 3228 | fore ach ($this ->schemas as $ns => $list) { | |
| 3229 | foreac h ($list a s $xs) { | |
| 3230 | $wsdlparts = parse_u rl($this-> wsdl); // this is bogusly s imple! | |
| 3231 | fo reach ($xs ->imports as $ns2 => $list2) { | |
| 3232 | for ($ii = 0; $ii < count($l ist2); $ii ++) { | |
| 3233 | if (! $lis t2[$ii]['l oaded']) { | |
| 3234 | $t his->schem as[$ns]->i mports[$ns 2][$ii]['l oaded'] = true; | |
| 3235 | $u rl = $list 2[$ii]['lo cation']; | |
| 3236 | if ($u rl != '') { | |
| 3237 | $urlpart s = parse_ url($url); | |
| 3238 | if (!iss et($urlpar ts['host'] )) { | |
| 3239 | $url = $ws dlparts['s cheme'] . '://' . $w sdlparts[' host'] . ( isset($wsd lparts['po rt']) ? ': ' .$wsdlpa rts['port' ] : '') . | |
| 3240 | subs tr($wsdlpa rts['path' ],0,strrpo s($wsdlpar ts['path'] ,'/') + 1) .$urlpart s['path']; | |
| 3241 | } | |
| 3242 | if (! in _array($ur l, $import ed_urls)) { | |
| 3243 | $this- >parseWSDL ($url); | |
| 3244 | $impor ted++; | |
| 3245 | $impor ted_urls[] = $url; | |
| 3246 | } | |
| 3247 | } else { | |
| 3248 | $this->d ebug("Unex pected sce nario: emp ty URL for unloaded import"); | |
| 3249 | } | |
| 3250 | } | |
| 3251 | } | |
| 3252 | } | |
| 3253 | } | |
| 3254 | } | |
| 3255 | // W SDL import s | |
| 3256 | $wsdlp arts = par se_url($th is->wsdl); // thi s is bogus ly simple! | |
| 3257 | foreach ($this->im port as $n s => $list ) { | |
| 3258 | for ($ii = 0; $ii < coun t($list); $ii++) { | |
| 3259 | if (! $list[$ii] ['loaded'] ) { | |
| 3260 | $this->i mport[$ns] [$ii]['loa ded'] = tr ue; | |
| 3261 | $url = $ list[$ii][ 'location' ]; | |
| 3262 | if ($url != '') { | |
| 3263 | $url parts = pa rse_url($u rl); | |
| 3264 | if ( !isset($ur lparts['ho st'])) { | |
| 3265 | $url = $wsdlpart s['scheme' ] . '://' . $wsdlpar ts['host'] . (isset( $wsdlparts ['port']) ? ':' . $w sdlparts[' port'] : ' ') . | |
| 3266 | substr($ws dlparts['p ath'],0,st rrpos($wsd lparts['pa th'],'/') + 1) .$url parts['pat h']; | |
| 3267 | } | |
| 3268 | if ( ! in_array ($url, $im ported_url s)) { | |
| 3269 | $t his->parse WSDL($url) ; | |
| 3270 | $i mported++; | |
| 3271 | $i mported_ur ls[] = $ur l; | |
| 3272 | } | |
| 3273 | } else { | |
| 3274 | $thi s->debug(" Unexpected scenario: empty URL for unloa ded import "); | |
| 3275 | } | |
| 3276 | } | |
| 3277 | } | |
| 3278 | } | |
| 3279 | } | |
| 3280 | // add new d ata to ope ration dat a | |
| 3281 | fo reach($thi s->binding s as $bind ing => $bi ndingData) { | |
| 3282 | if (isse t($binding Data['oper ations']) && is_arra y($binding Data['oper ations'])) { | |
| 3283 | fore ach($bindi ngData['op erations'] as $opera tion => $d ata) { | |
| 3284 | $this->deb ug('post-p arse data gathering for ' . $o peration); | |
| 3285 | $this->bin dings[$bin ding]['ope rations'][ $operation ]['input'] = | |
| 3286 | is set($this- >bindings[ $binding][ 'operation s'][$opera tion]['inp ut']) ? | |
| 3287 | ar ray_merge( $this->bin dings[$bin ding]['ope rations'][ $operation ]['input'] , $this->p ortTypes[ $bindingDa ta['portTy pe'] ][$op eration][' input']) : | |
| 3288 | $t his->portT ypes[ $bin dingData[' portType'] ][$operat ion]['inpu t']; | |
| 3289 | $this->bin dings[$bin ding]['ope rations'][ $operation ]['output' ] = | |
| 3290 | is set($this- >bindings[ $binding][ 'operation s'][$opera tion]['out put']) ? | |
| 3291 | ar ray_merge( $this->bin dings[$bin ding]['ope rations'][ $operation ]['output' ], $this-> portTypes[ $bindingD ata['portT ype'] ][$o peration][ 'output']) : | |
| 3292 | $t his->portT ypes[ $bin dingData[' portType'] ][$operat ion]['outp ut']; | |
| 3293 | if(isset($ this->mess ages[ $thi s->binding s[$binding ]['operati ons'][$ope ration]['i nput']['me ssage'] ]) ){ | |
| 3294 | $t his->bindi ngs[$bindi ng]['opera tions'][$o peration][ 'input'][' parts'] = $this->mes sages[ $th is->bindin gs[$bindin g]['operat ions'][$op eration][' input']['m essage'] ] ; | |
| 3295 | } | |
| 3296 | if(isset($ this->mess ages[ $thi s->binding s[$binding ]['operati ons'][$ope ration]['o utput']['m essage'] ] )){ | |
| 3297 | $this->b indings[$b inding]['o perations' ][$operati on]['outpu t']['parts '] = $this ->messages [ $this->b indings[$b inding]['o perations' ][$operati on]['outpu t']['messa ge'] ]; | |
| 3298 | } | |
| 3299 | // Set ope ration sty le if nece ssary, but do not ov erride one already p rovided | |
| 3300 | if (isset( $bindingDa ta['style' ]) && !iss et($this-> bindings[$ binding][' operations '][$operat ion]['styl e'])) { | |
| 3301 | $this- >bindings[ $binding][ 'operation s'][$opera tion]['sty le'] = $bi ndingData[ 'style']; | |
| 3302 | } | |
| 3303 | $this->bin dings[$bin ding]['ope rations'][ $operation ]['transpo rt'] = iss et($bindin gData['tra nsport']) ? $binding Data['tran sport'] : ''; | |
| 3304 | $this->bin dings[$bin ding]['ope rations'][ $operation ]['documen tation'] = isset($th is->portTy pes[ $bind ingData['p ortType'] ][$operati on]['docum entation'] ) ? $this- >portTypes [ $binding Data['port Type'] ][$ operation] ['document ation'] : ''; | |
| 3305 | $this->bin dings[$bin ding]['ope rations'][ $operation ]['endpoin t'] = isse t($binding Data['endp oint']) ? $bindingDa ta['endpoi nt'] : ''; | |
| 3306 | } | |
| 3307 | } | |
| 3308 | } | |
| 3309 | } | |
| 3310 | ||
| 3311 | /** | |
| 3312 | * par ses the ws dl documen t | |
| 3313 | * | |
| 3314 | * @pa ram string $wsdl pat h or URL | |
| 3315 | * @ac cess priva te | |
| 3316 | */ | |
| 3317 | functi on parseWS DL($wsdl = '') { | |
| 3318 | $thi s->debug(" parse WSDL at path=$ wsdl"); | |
| 3319 | ||
| 3320 | if ($wsdl == '') { | |
| 3321 | $this->d ebug('no w sdl passed to parseW SDL()!!'); | |
| 3322 | $this->s etError('n o wsdl pas sed to par seWSDL()!! '); | |
| 3323 | return f alse; | |
| 3324 | } | |
| 3325 | ||
| 3326 | // parse $ws dl for url format | |
| 3327 | $w sdl_props = parse_ur l($wsdl); | |
| 3328 | ||
| 3329 | if (isset($w sdl_props[ 'scheme']) && ($wsdl _props['sc heme'] == 'http' || $wsdl_prop s['scheme' ] == 'http s')) { | |
| 3330 | $this->d ebug('gett ing WSDL h ttp(s) URL ' . $wsdl ); | |
| 3331 | // g et wsdl | |
| 3332 | $tr = new soap _transport _http($wsd l, $this-> curl_optio ns, $this- >use_curl) ; | |
| 3333 | $tr->r equest_met hod = 'GET '; | |
| 3334 | $tr->u seSOAPActi on = false ; | |
| 3335 | if($th is->proxyh ost && $th is->proxyp ort){ | |
| 3336 | $tr->set Proxy($thi s->proxyho st,$this-> proxyport, $this->pro xyusername ,$this->pr oxypasswor d); | |
| 3337 | } | |
| 3338 | if ($t his->autht ype != '') { | |
| 3339 | $tr->set Credential s($this->u sername, $ this->pass word, $thi s->authtyp e, array() , $this->c ertRequest ); | |
| 3340 | } | |
| 3341 | $tr->s etEncoding ('gzip, de flate'); | |
| 3342 | $wsdl_ string = $ tr->send(' ', $this-> timeout, $ this->resp onse_timeo ut); | |
| 3343 | //$thi s->debug(" WSDL reque st\n" . $t r->outgoin g_payload) ; | |
| 3344 | //$thi s->debug(" WSDL respo nse\n" . $ tr->incomi ng_payload ); | |
| 3345 | $this- >appendDeb ug($tr->ge tDebug()); | |
| 3346 | // cat ch errors | |
| 3347 | if($er r = $tr->g etError() ){ | |
| 3348 | $errstr = 'Getting ' . $wsdl . ' - HTT P ERROR: ' .$err; | |
| 3349 | $this->d ebug($errs tr); | |
| 3350 | $this->set Error($err str); | |
| 3351 | unset($t r); | |
| 3352 | return fal se; | |
| 3353 | } | |
| 3354 | unset( $tr); | |
| 3355 | $this- >debug("go t WSDL URL "); | |
| 3356 | } else { | |
| 3357 | // $wsdl is not ht tp(s), so treat it a s a file U RL or plai n file pat h | |
| 3358 | if ( isset($wsd l_props['s cheme']) & & ($wsdl_p rops['sche me'] == 'f ile') && i sset($wsdl _props['pa th'])) { | |
| 3359 | $path = isset($w sdl_props[ 'host']) ? ($wsdl_pr ops['host' ] . ':' . $wsdl_prop s['path']) : $wsdl_p rops['path ']; | |
| 3360 | } el se { | |
| 3361 | $path = $wsdl; | |
| 3362 | } | |
| 3363 | $this->d ebug('gett ing WSDL f ile ' . $p ath); | |
| 3364 | if ($fp = @fopen($ path, 'r') ) { | |
| 3365 | $wsd l_string = ''; | |
| 3366 | whil e ($data = fread($fp , 32768)) { | |
| 3367 | $wsdl_stri ng .= $dat a; | |
| 3368 | } | |
| 3369 | fclo se($fp); | |
| 3370 | } else { | |
| 3371 | $err str = "Bad path to W SDL file $ path"; | |
| 3372 | $thi s->debug($ errstr); | |
| 3373 | $thi s->setErro r($errstr) ; | |
| 3374 | retu rn false; | |
| 3375 | } | |
| 3376 | } | |
| 3377 | $t his->debug ('Parse WS DL'); | |
| 3378 | // end new c ode added | |
| 3379 | // Create an XML parse r. | |
| 3380 | $t his->parse r = xml_pa rser_creat e(); | |
| 3381 | // Set the o ptions for parsing t he XML dat a. | |
| 3382 | // xml_parse r_set_opti on($parser , XML_OPTI ON_SKIP_WH ITE, 1); | |
| 3383 | xm l_parser_s et_option( $this->par ser, XML_O PTION_CASE _FOLDING, 0); | |
| 3384 | // Set the o bject for the parser . | |
| 3385 | xm l_set_obje ct($this-> parser, $t his); | |
| 3386 | // Set the e lement han dlers for the parser . | |
| 3387 | xm l_set_elem ent_handle r($this->p arser, 'st art_elemen t', 'end_e lement'); | |
| 3388 | xm l_set_char acter_data _handler($ this->pars er, 'chara cter_data' ); | |
| 3389 | // Parse the XML file. | |
| 3390 | if (!xml_par se($this-> parser, $w sdl_string , true)) { | |
| 3391 | // Displ ay an erro r message. | |
| 3392 | $errstr = sprintf( | |
| 3393 | 'XML err or parsing WSDL from %s on lin e %d: %s', | |
| 3394 | $wsdl, | |
| 3395 | xml_ get_curren t_line_num ber($this- >parser), | |
| 3396 | xml_ error_stri ng(xml_get _error_cod e($this->p arser)) | |
| 3397 | ); | |
| 3398 | $this->d ebug($errs tr); | |
| 3399 | $this- >debug("XM L payload: \n" . $wsd l_string); | |
| 3400 | $this->s etError($e rrstr); | |
| 3401 | return f alse; | |
| 3402 | } | |
| 3403 | // f ree the pa rser | |
| 3404 | xm l_parser_f ree($this- >parser); | |
| 3405 | $t his->debug ('Parsing WSDL done' ); | |
| 3406 | // c atch wsdl parse erro rs | |
| 3407 | if($ this->getE rror()){ | |
| 3408 | return false; | |
| 3409 | } | |
| 3410 | re turn true; | |
| 3411 | } | |
| 3412 | ||
| 3413 | /** | |
| 3414 | * sta rt-element handler | |
| 3415 | * | |
| 3416 | * @pa ram string $parser X ML parser object | |
| 3417 | * @pa ram string $name ele ment name | |
| 3418 | * @pa ram string $attrs as sociative array of a ttributes | |
| 3419 | * @ac cess priva te | |
| 3420 | */ | |
| 3421 | functi on start_e lement($pa rser, $nam e, $attrs) | |
| 3422 | { | |
| 3423 | if ($this->s tatus == ' schema') { | |
| 3424 | $this->c urrentSche ma->schema StartEleme nt($parser , $name, $ attrs); | |
| 3425 | $this->a ppendDebug ($this->cu rrentSchem a->getDebu g()); | |
| 3426 | $this->c urrentSche ma->clearD ebug(); | |
| 3427 | } elseif (pr eg_match(' /schema$/' , $name)) { | |
| 3428 | $thi s->debug(' Parsing WS DL schema' ); | |
| 3429 | // $this ->debug("s tartElemen t for $nam e ($attrs[ name]). st atus = $th is->status (".$this- >getLocalP art($name) .")"); | |
| 3430 | $this->s tatus = 's chema'; | |
| 3431 | $this->c urrentSche ma = new n usoap_xmls chema('', '', $this- >namespace s); | |
| 3432 | $this->c urrentSche ma->schema StartEleme nt($parser , $name, $ attrs); | |
| 3433 | $this->a ppendDebug ($this->cu rrentSchem a->getDebu g()); | |
| 3434 | $this->c urrentSche ma->clearD ebug(); | |
| 3435 | } else { | |
| 3436 | // posit ion in the total num ber of ele ments, sta rting from 0 | |
| 3437 | $pos = $ this->posi tion++; | |
| 3438 | $depth = $this->de pth++; | |
| 3439 | // set s elf as cur rent value for this depth | |
| 3440 | $this->d epth_array [$depth] = $pos; | |
| 3441 | $this->m essage[$po s] = array ('cdata' = > ''); | |
| 3442 | // proce ss attribu tes | |
| 3443 | if (coun t($attrs) > 0) { | |
| 3444 | // regis ter namesp ace declar ations | |
| 3445 | fore ach($attrs as $k => $v) { | |
| 3446 | if (preg_m atch('/^xm lns/',$k)) { | |
| 3447 | if ($n s_prefix = substr(st rrchr($k, ':'), 1)) { | |
| 3448 | $t his->names paces[$ns_ prefix] = $v; | |
| 3449 | } else { | |
| 3450 | $t his->names paces['ns' . (count( $this->nam espaces) + 1)] = $v; | |
| 3451 | } | |
| 3452 | if ($v == 'http: //www.w3.o rg/2001/XM LSchema' | | $v == 'h ttp://www. w3.org/199 9/XMLSchem a' || $v = = 'http:// www.w3.org /2000/10/X MLSchema') { | |
| 3453 | $t his->XMLSc hemaVersio n = $v; | |
| 3454 | $t his->names paces['xsi '] = $v . '-instance '; | |
| 3455 | } | |
| 3456 | } | |
| 3457 | } | |
| 3458 | // e xpand each attribute prefix to its names pace | |
| 3459 | fore ach($attrs as $k => $v) { | |
| 3460 | $k = strpo s($k, ':') ? $this-> expandQnam e($k) : $k ; | |
| 3461 | if ($k != 'location' && $k != 'soapActio n' && $k ! = 'namespa ce') { | |
| 3462 | $v = s trpos($v, ':') ? $th is->expand Qname($v) : $v; | |
| 3463 | } | |
| 3464 | $eAttrs[$k ] = $v; | |
| 3465 | } | |
| 3466 | $att rs = $eAtt rs; | |
| 3467 | } else { | |
| 3468 | $att rs = array (); | |
| 3469 | } | |
| 3470 | // get e lement pre fix, names pace and n ame | |
| 3471 | if (preg _match('/: /', $name) ) { | |
| 3472 | // g et ns pref ix | |
| 3473 | $pre fix = subs tr($name, 0, strpos( $name, ':' )); | |
| 3474 | // g et ns | |
| 3475 | $nam espace = i sset($this ->namespac es[$prefix ]) ? $this ->namespac es[$prefix ] : ''; | |
| 3476 | // g et unquali fied name | |
| 3477 | $nam e = substr (strstr($n ame, ':'), 1); | |
| 3478 | } | |
| 3479 | // pro cess attri butes, exp anding any prefixes to namespa ces | |
| 3480 | // find status, re gister dat a | |
| 3481 | switch ( $this->sta tus) { | |
| 3482 | case 'message' : | |
| 3483 | if ($name == 'part') { | |
| 3484 | if ( isset($att rs['type'] )) { | |
| 3485 | $thi s->debug(" msg " . $t his->curre ntMessage . ": found part (wit h type) $a ttrs[name] : " . impl ode(',', $ attrs)); | |
| 3486 | $thi s->message s[$this->c urrentMess age][$attr s['name']] = $attrs[ 'type']; | |
| 3487 | } | |
| 3488 | if ( isset($att rs['elemen t'])) { | |
| 3489 | $thi s->debug(" msg " . $t his->curre ntMessage . ": found part (wit h element) $attrs[na me]: " . i mplode(',' , $attrs)) ; | |
| 3490 | $this->mes sages[$thi s->current Message][$ attrs['nam e']] = $at trs['eleme nt'] . '^' ; | |
| 3491 | } | |
| 3492 | } | |
| 3493 | break; | |
| 3494 | ca se 'portTy pe': | |
| 3495 | switch ( $name) { | |
| 3496 | case 'operatio n': | |
| 3497 | $this->cur rentPortOp eration = $attrs['na me']; | |
| 3498 | $this->deb ug("portTy pe $this-> currentPor tType oper ation: $th is->curren tPortOpera tion"); | |
| 3499 | if (isset( $attrs['pa rameterOrd er'])) { | |
| 3500 | $t his->portT ypes[$this ->currentP ortType][$ attrs['nam e']]['para meterOrder '] = $attr s['paramet erOrder']; | |
| 3501 | } | |
| 3502 | br eak; | |
| 3503 | case ' documentat ion': | |
| 3504 | $t his->docum entation = true; | |
| 3505 | br eak; | |
| 3506 | // mer ge input/o utput data | |
| 3507 | defaul t: | |
| 3508 | $m = isset($ attrs['mes sage']) ? $this->get LocalPart( $attrs['me ssage']) : ''; | |
| 3509 | $t his->portT ypes[$this ->currentP ortType][$ this->curr entPortOpe ration][$n ame]['mess age'] = $m ; | |
| 3510 | br eak; | |
| 3511 | } | |
| 3512 | break; | |
| 3513 | case 'bi nding': | |
| 3514 | swit ch ($name) { | |
| 3515 | case 'bind ing': | |
| 3516 | // get ns prefix | |
| 3517 | if (is set($attrs ['style']) ) { | |
| 3518 | $this- >bindings[ $this->cur rentBindin g]['prefix '] = $pref ix; | |
| 3519 | } | |
| 3520 | $t his->bindi ngs[$this- >currentBi nding] = a rray_merge ($this->bi ndings[$th is->curren tBinding], $attrs); | |
| 3521 | br eak; | |
| 3522 | ca se 'header ': | |
| 3523 | $this->b indings[$t his->curre ntBinding] ['operatio ns'][$this ->currentO peration][ $this->opS tatus]['he aders'][] = $attrs; | |
| 3524 | break; | |
| 3525 | ca se 'operat ion': | |
| 3526 | if (isse t($attrs[' soapAction '])) { | |
| 3527 | $thi s->binding s[$this->c urrentBind ing]['oper ations'][$ this->curr entOperati on]['soapA ction'] = $attrs['so apAction'] ; | |
| 3528 | } | |
| 3529 | if (isse t($attrs[' style'])) { | |
| 3530 | $thi s->binding s[$this->c urrentBind ing]['oper ations'][$ this->curr entOperati on]['style '] = $attr s['style'] ; | |
| 3531 | } | |
| 3532 | if (isse t($attrs[' name'])) { | |
| 3533 | $thi s->current Operation = $attrs[' name']; | |
| 3534 | $thi s->debug(" current bi nding oper ation: $th is->curren tOperation "); | |
| 3535 | $thi s->binding s[$this->c urrentBind ing]['oper ations'][$ this->curr entOperati on]['name' ] = $attrs ['name']; | |
| 3536 | $thi s->binding s[$this->c urrentBind ing]['oper ations'][$ this->curr entOperati on]['bindi ng'] = $th is->curren tBinding; | |
| 3537 | $thi s->binding s[$this->c urrentBind ing]['oper ations'][$ this->curr entOperati on]['endpo int'] = is set($this- >bindings[ $this->cur rentBindin g]['endpoi nt']) ? $t his->bindi ngs[$this- >currentBi nding]['en dpoint'] : ''; | |
| 3538 | } | |
| 3539 | break; | |
| 3540 | ca se 'input' : | |
| 3541 | $this->o pStatus = 'input'; | |
| 3542 | break; | |
| 3543 | ca se 'output ': | |
| 3544 | $this->o pStatus = 'output'; | |
| 3545 | break; | |
| 3546 | ca se 'body': | |
| 3547 | if (isse t($this->b indings[$t his->curre ntBinding] ['operatio ns'][$this ->currentO peration][ $this->opS tatus])) { | |
| 3548 | $thi s->binding s[$this->c urrentBind ing]['oper ations'][$ this->curr entOperati on][$this- >opStatus] = array_m erge($this ->bindings [$this->cu rrentBindi ng]['opera tions'][$t his->curre ntOperatio n][$this-> opStatus], $attrs); | |
| 3549 | } else { | |
| 3550 | $thi s->binding s[$this->c urrentBind ing]['oper ations'][$ this->curr entOperati on][$this- >opStatus] = $attrs; | |
| 3551 | } | |
| 3552 | break; | |
| 3553 | } | |
| 3554 | break; | |
| 3555 | case 'se rvice': | |
| 3556 | switch ($n ame) { | |
| 3557 | case ' port': | |
| 3558 | $t his->curre ntPort = $ attrs['nam e']; | |
| 3559 | $t his->debug ('current port: ' . $this->cur rentPort); | |
| 3560 | $t his->ports [$this->cu rrentPort] ['binding' ] = $this- >getLocalP art($attrs ['binding' ]); | |
| 3561 | ||
| 3562 | br eak; | |
| 3563 | case ' address': | |
| 3564 | $t his->ports [$this->cu rrentPort] ['location '] = $attr s['locatio n']; | |
| 3565 | $t his->ports [$this->cu rrentPort] ['bindingT ype'] = $n amespace; | |
| 3566 | $t his->bindi ngs[ $this ->ports[$t his->curre ntPort]['b inding'] ] ['bindingT ype'] = $n amespace; | |
| 3567 | $t his->bindi ngs[ $this ->ports[$t his->curre ntPort]['b inding'] ] ['endpoint '] = $attr s['locatio n']; | |
| 3568 | br eak; | |
| 3569 | } | |
| 3570 | break; | |
| 3571 | } | |
| 3572 | // s et status | |
| 3573 | swit ch ($name) { | |
| 3574 | case ' import': | |
| 3575 | if (isset($a ttrs['loca tion'])) { | |
| 3576 | $this->imp ort[$attrs ['namespac e']][] = a rray('loca tion' => $ attrs['loc ation'], ' loaded' => false); | |
| 3577 | $this->deb ug('parsin g import ' . $attrs[ 'namespace ']. ' - ' . $attrs[' location'] . ' (' . count($thi s->import[ $attrs['na mespace']] ).')'); | |
| 3578 | } else { | |
| 3579 | $this->imp ort[$attrs ['namespac e']][] = a rray('loca tion' => ' ', 'loaded ' => true) ; | |
| 3580 | if (! $thi s->getPref ixFromName space($att rs['namesp ace'])) { | |
| 3581 | $t his->names paces['ns' .(count($t his->names paces)+1)] = $attrs[ 'namespace ']; | |
| 3582 | } | |
| 3583 | $this->deb ug('parsin g import ' . $attrs[ 'namespace ']. ' - [n o location ] (' . cou nt($this-> import[$at trs['names pace']]).' )'); | |
| 3584 | } | |
| 3585 | break; | |
| 3586 | //wait for schem a | |
| 3587 | //case 'types': | |
| 3588 | // $this->s tatus = 's chema'; | |
| 3589 | // break; | |
| 3590 | case ' message': | |
| 3591 | $this->s tatus = 'm essage'; | |
| 3592 | $this->m essages[$a ttrs['name ']] = arra y(); | |
| 3593 | $this->c urrentMess age = $att rs['name'] ; | |
| 3594 | break; | |
| 3595 | case ' portType': | |
| 3596 | $this->s tatus = 'p ortType'; | |
| 3597 | $this->p ortTypes[$ attrs['nam e']] = arr ay(); | |
| 3598 | $this->c urrentPort Type = $at trs['name' ]; | |
| 3599 | break; | |
| 3600 | case " binding": | |
| 3601 | if (isse t($attrs[' name'])) { | |
| 3602 | // get b inding nam e | |
| 3603 | if (strpos ($attrs['n ame'], ':' )) { | |
| 3604 | $this->cur rentBindin g = $this- >getLocalP art($attrs ['name']); | |
| 3605 | } else { | |
| 3606 | $this->cur rentBindin g = $attrs ['name']; | |
| 3607 | } | |
| 3608 | $this->sta tus = 'bin ding'; | |
| 3609 | $this->bin dings[$thi s->current Binding][' portType'] = $this-> getLocalPa rt($attrs[ 'type']); | |
| 3610 | $this->deb ug("curren t binding: $this->cu rrentBindi ng of port Type: " . $attrs['ty pe']); | |
| 3611 | } | |
| 3612 | break; | |
| 3613 | case ' service': | |
| 3614 | $this->s erviceName = $attrs[ 'name']; | |
| 3615 | $this->s tatus = 's ervice'; | |
| 3616 | $this->d ebug('curr ent servic e: ' . $th is->servic eName); | |
| 3617 | break; | |
| 3618 | case ' definition s': | |
| 3619 | foreach ($attrs as $name => $value) { | |
| 3620 | $this->wsd l_info[$na me] = $val ue; | |
| 3621 | } | |
| 3622 | break; | |
| 3623 | } | |
| 3624 | } | |
| 3625 | } | |
| 3626 | ||
| 3627 | /* * | |
| 3628 | * end-elemen t handler | |
| 3629 | * | |
| 3630 | * @param str ing $parse r XML pars er object | |
| 3631 | * @param str ing $name element na me | |
| 3632 | * @access pr ivate | |
| 3633 | */ | |
| 3634 | fu nction end _element($ parser, $n ame){ | |
| 3635 | // u nset schem a status | |
| 3636 | ||
| 3637 | if ( /*preg_mat ch('/types $/', $name ) ||*/ pre g_match('/ schema$/', $name)) { | |
| 3638 | $this- >status = ""; | |
| 3639 | $this- >appendDeb ug($this-> currentSch ema->getDe bug()); | |
| 3640 | $this- >currentSc hema->clea rDebug(); | |
| 3641 | $this- >schemas[$ this->curr entSchema- >schemaTar getNamespa ce][] = $t his->curre ntSchema; | |
| 3642 | $thi s->debug(' Parsing WS DL schema done'); | |
| 3643 | } | |
| 3644 | if ( $this->sta tus == 'sc hema') { | |
| 3645 | $this- >currentSc hema->sche maEndEleme nt($parser , $name); | |
| 3646 | } el se { | |
| 3647 | // bri ng depth d own a notc h | |
| 3648 | $this- >depth--; | |
| 3649 | } | |
| 3650 | // e nd documen tation | |
| 3651 | if ( $this->doc umentation ) { | |
| 3652 | //TODO : track th e node to which docu mentation should be assigned; it can be a part, me ssage, etc . | |
| 3653 | //$thi s->portTyp es[$this-> currentPor tType][$th is->curren tPortOpera tion]['doc umentation '] = $this ->document ation; | |
| 3654 | $this- >documenta tion = fal se; | |
| 3655 | } | |
| 3656 | } | |
| 3657 | ||
| 3658 | /* * | |
| 3659 | * element c ontent han dler | |
| 3660 | * | |
| 3661 | * @param st ring $pars er XML par ser object | |
| 3662 | * @param st ring $data element c ontent | |
| 3663 | * @access p rivate | |
| 3664 | * / | |
| 3665 | fu nction cha racter_dat a($parser, $data) | |
| 3666 | { | |
| 3667 | $pos = isset($ this->dept h_array[$t his->depth ]) ? $this ->depth_ar ray[$this- >depth] : 0; | |
| 3668 | if ( isset($thi s->message [$pos]['cd ata'])) { | |
| 3669 | $this- >message[$ pos]['cdat a'] .= $da ta; | |
| 3670 | } | |
| 3671 | if ( $this->doc umentation ) { | |
| 3672 | $this- >documenta tion .= $d ata; | |
| 3673 | } | |
| 3674 | } | |
| 3675 | ||
| 3676 | /* * | |
| 3677 | * if authent icating, s et user cr edentials here | |
| 3678 | * | |
| 3679 | * @param string $us ername | |
| 3680 | * @param string $pa ssword | |
| 3681 | * @param string $authtype (basic|di gest|certi ficate|ntl m) | |
| 3682 | * @param array $certReque st (keys m ust be cai nfofile (o ptional), sslcertfil e, sslkeyf ile, passp hrase, cer tpassword (optional) , verifype er (option al), verif yhost (opt ional): se e correspo nding opti ons in cUR L docs) | |
| 3683 | * @access public | |
| 3684 | */ | |
| 3685 | fu nction set Credential s($usernam e, $passwo rd, $autht ype = 'bas ic', $cert Request = array()) { | |
| 3686 | $this->deb ug("setCre dentials u sername= AI authtype=$ authtype c ertRequest ="); | |
| 3687 | $thi s->appendD ebug($this ->varDump( $certReque st)); | |
| 3688 | $thi s->usernam e = $usern ame; | |
| 3689 | $thi s->passwor d = $passw ord; | |
| 3690 | $thi s->authtyp e = $autht ype; | |
| 3691 | $thi s->certReq uest = $ce rtRequest; | |
| 3692 | } | |
| 3693 | ||
| 3694 | fu nction get BindingDat a($binding ) | |
| 3695 | { | |
| 3696 | if ( is_array($ this->bind ings[$bind ing])) { | |
| 3697 | return $this->bi ndings[$bi nding]; | |
| 3698 | } | |
| 3699 | } | |
| 3700 | ||
| 3701 | /* * | |
| 3702 | * returns a n assoc ar ray of ope ration nam es => oper ation data | |
| 3703 | * | |
| 3704 | * @param st ring $port Name WSDL port name | |
| 3705 | * @param st ring $bind ingType eg : soap, sm tp, dime ( only soap and soap12 are curre ntly suppo rted) | |
| 3706 | * @return a rray | |
| 3707 | * @access p ublic | |
| 3708 | * / | |
| 3709 | fu nction get Operations ($portName = '', $bi ndingType = 'soap') { | |
| 3710 | $ops = array() ; | |
| 3711 | if ( $bindingTy pe == 'soa p') { | |
| 3712 | $bindi ngType = ' http://sch emas.xmlso ap.org/wsd l/soap/'; | |
| 3713 | } el seif ($bin dingType = = 'soap12' ) { | |
| 3714 | $bindi ngType = ' http://sch emas.xmlso ap.org/wsd l/soap12/' ; | |
| 3715 | } el se { | |
| 3716 | $this- >debug("ge tOperation s bindingT ype $bindi ngType may not be su pported"); | |
| 3717 | } | |
| 3718 | $thi s->debug(" getOperati ons for po rt '$portN ame' bindi ngType $bi ndingType" ); | |
| 3719 | // l oop thru p orts | |
| 3720 | fore ach($this- >ports as $port => $ portData) { | |
| 3721 | $this- >debug("ge tOperation s checking port $por t bindingT ype " . $p ortData['b indingType ']); | |
| 3722 | if ($p ortName == '' || $po rt == $por tName) { | |
| 3723 | // bindi ng type of port matc hes parame ter | |
| 3724 | if ($por tData['bin dingType'] == $bindi ngType) { | |
| 3725 | $this->deb ug("getOpe rations fo und port $ port bindi ngType $bi ndingType" ); | |
| 3726 | //$this->d ebug("port data: " . $this->va rDump($por tData)); | |
| 3727 | //$this->d ebug("bind ings: " . $this->var Dump($this ->bindings [ $portDat a['binding '] ])); | |
| 3728 | // merge b indings | |
| 3729 | if (isset( $this->bin dings[ $po rtData['bi nding'] ][ 'operation s'])) { | |
| 3730 | $o ps = array _merge ($o ps, $this- >bindings[ $portData ['binding' ] ]['opera tions']); | |
| 3731 | } | |
| 3732 | } | |
| 3733 | } | |
| 3734 | } | |
| 3735 | if ( count($ops ) == 0) { | |
| 3736 | $this- >debug("ge tOperation s found no operation s for port '$portNam e' binding Type $bind ingType"); | |
| 3737 | } | |
| 3738 | retu rn $ops; | |
| 3739 | } | |
| 3740 | ||
| 3741 | /* * | |
| 3742 | * returns a n associat ive array of data ne cessary fo r calling an operati on | |
| 3743 | * | |
| 3744 | * @param st ring $oper ation name of operat ion | |
| 3745 | * @param st ring $bind ingType ty pe of bind ing eg: so ap, soap12 | |
| 3746 | * @return a rray | |
| 3747 | * @access p ublic | |
| 3748 | * / | |
| 3749 | fu nction get OperationD ata($opera tion, $bin dingType = 'soap') | |
| 3750 | { | |
| 3751 | if ( $bindingTy pe == 'soa p') { | |
| 3752 | $bindi ngType = ' http://sch emas.xmlso ap.org/wsd l/soap/'; | |
| 3753 | } el seif ($bin dingType = = 'soap12' ) { | |
| 3754 | $bindi ngType = ' http://sch emas.xmlso ap.org/wsd l/soap12/' ; | |
| 3755 | } | |
| 3756 | // l oop thru p orts | |
| 3757 | fore ach($this- >ports as $port => $ portData) { | |
| 3758 | // bin ding type of port ma tches para meter | |
| 3759 | if ($p ortData['b indingType '] == $bin dingType) { | |
| 3760 | // get b inding | |
| 3761 | //foreac h($this->b indings[ $ portData[' binding'] ]['operati ons'] as $ bOperation => $opDat a) { | |
| 3762 | foreach( array_keys ($this->bi ndings[ $p ortData['b inding'] ] ['operatio ns']) as $ bOperation ) { | |
| 3763 | // note th at we coul d/should a lso check the namesp ace here | |
| 3764 | if ($opera tion == $b Operation) { | |
| 3765 | $o pData = $t his->bindi ngs[ $port Data['bind ing'] ]['o perations' ][$operati on]; | |
| 3766 | return $opData; | |
| 3767 | } | |
| 3768 | } | |
| 3769 | } | |
| 3770 | } | |
| 3771 | } | |
| 3772 | ||
| 3773 | /* * | |
| 3774 | * returns a n associat ive array of data ne cessary fo r calling an operati on | |
| 3775 | * | |
| 3776 | * @param st ring $soap Action soa pAction fo r operatio n | |
| 3777 | * @param st ring $bind ingType ty pe of bind ing eg: so ap, soap12 | |
| 3778 | * @return a rray | |
| 3779 | * @access p ublic | |
| 3780 | * / | |
| 3781 | fu nction get OperationD ataForSoap Action($so apAction, $bindingTy pe = 'soap ') { | |
| 3782 | if ( $bindingTy pe == 'soa p') { | |
| 3783 | $bindi ngType = ' http://sch emas.xmlso ap.org/wsd l/soap/'; | |
| 3784 | } el seif ($bin dingType = = 'soap12' ) { | |
| 3785 | $bindi ngType = ' http://sch emas.xmlso ap.org/wsd l/soap12/' ; | |
| 3786 | } | |
| 3787 | // l oop thru p orts | |
| 3788 | fore ach($this- >ports as $port => $ portData) { | |
| 3789 | // bin ding type of port ma tches para meter | |
| 3790 | if ($p ortData['b indingType '] == $bin dingType) { | |
| 3791 | // loop through op erations f or the bin ding | |
| 3792 | foreach ($this->bi ndings[ $p ortData['b inding'] ] ['operatio ns'] as $b Operation => $opData ) { | |
| 3793 | if ($opDat a['soapAct ion'] == $ soapAction ) { | |
| 3794 | return $opData; | |
| 3795 | } | |
| 3796 | } | |
| 3797 | } | |
| 3798 | } | |
| 3799 | } | |
| 3800 | ||
| 3801 | /* * | |
| 3802 | * retu rns an arr ay of info rmation ab out a give n type | |
| 3803 | * retu rns false if no type exists by the given name | |
| 3804 | * | |
| 3805 | * typ eDef = arr ay( | |
| 3806 | * 'el ements' => array(), // refs to elements array | |
| 3807 | * 'res trictionBa se' => '', | |
| 3808 | * 'php Type' => ' ', | |
| 3809 | * 'ord er' => '(s equence|al l)', | |
| 3810 | * 'att rs' => arr ay() // re fs to attr ibutes arr ay | |
| 3811 | * ) | |
| 3812 | * | |
| 3813 | * @par am string $type the type | |
| 3814 | * @par am string $ns namesp ace (not p refix) of the type | |
| 3815 | * @ret urn mixed | |
| 3816 | * @acc ess public | |
| 3817 | * @see nusoap_xm lschema | |
| 3818 | */ | |
| 3819 | fu nction get TypeDef($t ype, $ns) { | |
| 3820 | $thi s->debug(" in getType Def: type= $type, ns= $ns"); | |
| 3821 | if ( (! $ns) && isset($th is->namesp aces['tns' ])) { | |
| 3822 | $ns = $this->nam espaces['t ns']; | |
| 3823 | $this- >debug("in getTypeDe f: type na mespace fo rced to $n s"); | |
| 3824 | } | |
| 3825 | if ( !isset($th is->schema s[$ns])) { | |
| 3826 | foreac h ($this-> schemas as $ns0 => $ schema0) { | |
| 3827 | if (strc asecmp($ns , $ns0) == 0) { | |
| 3828 | $this->deb ug("in get TypeDef: r eplacing s chema name space $ns with $ns0" ); | |
| 3829 | $ns = $ns0 ; | |
| 3830 | break; | |
| 3831 | } | |
| 3832 | } | |
| 3833 | } | |
| 3834 | if ( isset($thi s->schemas [$ns])) { | |
| 3835 | $this- >debug("in getTypeDe f: have sc hema for n amespace $ ns"); | |
| 3836 | for ($ i = 0; $i < count($t his->schem as[$ns]); $i++) { | |
| 3837 | $xs = &$ this->sche mas[$ns][$ i]; | |
| 3838 | $t = $xs ->getTypeD ef($type); | |
| 3839 | $this->a ppendDebug ($xs->getD ebug()); | |
| 3840 | $xs->cle arDebug(); | |
| 3841 | if ($t) { | |
| 3842 | $this->deb ug("in get TypeDef: f ound type $type"); | |
| 3843 | if (!isset ($t['phpTy pe'])) { | |
| 3844 | // get info for type t o tack ont o the elem ent | |
| 3845 | $u qType = su bstr($t['t ype'], str rpos($t['t ype'], ':' ) + 1); | |
| 3846 | $n s = substr ($t['type' ], 0, strr pos($t['ty pe'], ':') ); | |
| 3847 | $e type = $th is->getTyp eDef($uqTy pe, $ns); | |
| 3848 | if ($etype) { | |
| 3849 | $thi s->debug(" found type for [elem ent] $type :"); | |
| 3850 | $thi s->debug($ this->varD ump($etype )); | |
| 3851 | if ( isset($ety pe['phpTyp e'])) { | |
| 3852 | $t['ph pType'] = $etype['ph pType']; | |
| 3853 | } | |
| 3854 | if ( isset($ety pe['elemen ts'])) { | |
| 3855 | $t['el ements'] = $etype['e lements']; | |
| 3856 | } | |
| 3857 | if ( isset($ety pe['attrs' ])) { | |
| 3858 | $t['at trs'] = $e type['attr s']; | |
| 3859 | } | |
| 3860 | } else { | |
| 3861 | $thi s->debug(" did not fi nd type fo r [element ] $type"); | |
| 3862 | } | |
| 3863 | } | |
| 3864 | return $t; | |
| 3865 | } | |
| 3866 | } | |
| 3867 | $this- >debug("in getTypeDe f: did not find type $type"); | |
| 3868 | } el se { | |
| 3869 | $this- >debug("in getTypeDe f: do not have schem a for name space $ns" ); | |
| 3870 | } | |
| 3871 | retu rn false; | |
| 3872 | } | |
| 3873 | ||
| 3874 | /** | |
| 3875 | * prin ts html de scription of service s | |
| 3876 | * | |
| 3877 | * @acc ess privat e | |
| 3878 | */ | |
| 3879 | functi on webDesc ription(){ | |
| 3880 | gl obal $HTTP _SERVER_VA RS; | |
| 3881 | ||
| 3882 | if ( isset($_SE RVER)) { | |
| 3883 | $PHP_S ELF = $_SE RVER['PHP_ SELF']; | |
| 3884 | } el seif (isse t($HTTP_SE RVER_VARS) ) { | |
| 3885 | $PHP_S ELF = $HTT P_SERVER_V ARS['PHP_S ELF']; | |
| 3886 | } el se { | |
| 3887 | $this- >setError( "Neither _ SERVER nor HTTP_SERV ER_VARS is available "); | |
| 3888 | } | |
| 3889 | ||
| 3890 | $b = ' | |
| 3891 | <htm l><head><t itle>NuSOA P: '.$this ->serviceN ame.'</tit le> | |
| 3892 | <sty le type="t ext/css"> | |
| 3893 | body { font-famil y: arial; color: #00 0000; back ground-col or: #fffff f; margin: 0px 0px 0 px 0px; } | |
| 3894 | p { font-famil y: arial; color: #00 0000; marg in-top: 0p x; margin- bottom: 12 px; } | |
| 3895 | pre { back ground-col or: silver ; padding: 5px; font -family: C ourier New ; font-siz e: x-small ; color: # 000000;} | |
| 3896 | ul { margin-top : 10px; ma rgin-left: 20px; } | |
| 3897 | li { list-style -type: non e; margin- top: 10px; color: #0 00000; } | |
| 3898 | .content{ | |
| 3899 | margin -left: 0px ; padding- bottom: 2e m; } | |
| 3900 | .nav { | |
| 3901 | paddin g-top: 10p x; padding -bottom: 1 0px; paddi ng-left: 1 5px; font- size: .70e m; | |
| 3902 | margin -top: 10px ; margin-l eft: 0px; color: #00 0000; | |
| 3903 | backgr ound-color : #ccccff; width: 20 %; margin- left: 20px ; margin-t op: 20px; } | |
| 3904 | .title { | |
| 3905 | font-f amily: ari al; font-s ize: 26px; color: #f fffff; | |
| 3906 | backgr ound-color : #999999; width: 10 0%; | |
| 3907 | margin -left: 0px ; margin-r ight: 0px; | |
| 3908 | paddin g-top: 10p x; padding -bottom: 1 0px;} | |
| 3909 | .hidden { | |
| 3910 | positi on: absolu te; visibi lity: hidd en; z-inde x: 200; le ft: 250px; top: 100p x; | |
| 3911 | font-f amily: ari al; overfl ow: hidden ; width: 6 00; | |
| 3912 | paddin g: 20px; f ont-size: 10px; back ground-col or: #99999 9; | |
| 3913 | layer- background -color:#FF FFFF; } | |
| 3914 | a,a:active { color: charcoal; font-weig ht: bold; } | |
| 3915 | a:visited { color: #666666; font-weigh t: bold; } | |
| 3916 | a:hover { color: cc3300; f ont-weight : bold; } | |
| 3917 | </st yle> | |
| 3918 | <scr ipt langua ge="JavaSc ript" type ="text/jav ascript"> | |
| 3919 | <!-- | |
| 3920 | // P OP-UP CAPT IONS... | |
| 3921 | func tion lib_b wcheck(){ //Browserc heck (need ed) | |
| 3922 | this.ver=n avigator.a ppVersion | |
| 3923 | this.agent =navigator .userAgent | |
| 3924 | this.dom=d ocument.ge tElementBy Id?1:0 | |
| 3925 | this.opera 5=this.age nt.indexOf ("Opera 5" )>-1 | |
| 3926 | this.ie5=( this.ver.i ndexOf("MS IE 5")>-1 && this.do m && !this .opera5)?1 :0; | |
| 3927 | this.ie6=( this.ver.i ndexOf("MS IE 6")>-1 && this.do m && !this .opera5)?1 :0; | |
| 3928 | this.ie4=( document.a ll && !thi s.dom && ! this.opera 5)?1:0; | |
| 3929 | this.ie=th is.ie4||th is.ie5||th is.ie6 | |
| 3930 | this.mac=t his.agent. indexOf("M ac")>-1 | |
| 3931 | this.ns6=( this.dom & & parseInt (this.ver) >= 5) ?1: 0; | |
| 3932 | this.ns4=( document.l ayers && ! this.dom)? 1:0; | |
| 3933 | this.bw=(t his.ie6 || this.ie5 || this.ie 4 || this. ns4 || thi s.ns6 || t his.opera5 ) | |
| 3934 | return thi s | |
| 3935 | } | |
| 3936 | var bw = new l ib_bwcheck () | |
| 3937 | //Ma kes crossb rowser obj ect. | |
| 3938 | func tion makeO bj(obj){ | |
| 3939 | this.evnt= bw.dom? do cument.get ElementByI d(obj):bw. ie4?docume nt.all[obj ]:bw.ns4?d ocument.la yers[obj]: 0; | |
| 3940 | if(!this.e vnt) retur n false | |
| 3941 | this.css=b w.dom||bw. ie4?this.e vnt.style: bw.ns4?thi s.evnt:0; | |
| 3942 | this.wref= bw.dom||bw .ie4?this. evnt:bw.ns 4?this.css .document: 0; | |
| 3943 | this.write It=b_write It; | |
| 3944 | return thi s | |
| 3945 | } | |
| 3946 | // A unit of m easure tha t will be added when setting t he positio n of a lay er. | |
| 3947 | //va r px = bw. ns4||windo w.opera?"" :"px"; | |
| 3948 | func tion b_wri teIt(text) { | |
| 3949 | if (bw.ns4 ){this.wre f.write(te xt);this.w ref.close( )} | |
| 3950 | else this. wref.inner HTML = tex t | |
| 3951 | } | |
| 3952 | //Sh ows the me ssages | |
| 3953 | var oDesc; | |
| 3954 | func tion popup (divid){ | |
| 3955 | if(oDesc = new makeO bj(divid)) { | |
| 3956 | oDesc. css.visibi lity = "vi sible" | |
| 3957 | } | |
| 3958 | } | |
| 3959 | func tion popou t(){ // Hi des messag e | |
| 3960 | if(oDesc) oDesc.css. visibility = "hidden " | |
| 3961 | } | |
| 3962 | //-- > | |
| 3963 | </sc ript> | |
| 3964 | </he ad> | |
| 3965 | <bod y> | |
| 3966 | <div class=con tent> | |
| 3967 | <br><b r> | |
| 3968 | <div c lass=title >'.$this-> serviceNam e.'</div> | |
| 3969 | <div c lass=nav> | |
| 3970 | <p>View the <a hre f="'.$PHP_ SELF.'?wsd l">WSDL</a > for the service. | |
| 3971 | Click on an operat ion name t o view it& apos;s det ails.</p> | |
| 3972 | <ul>'; | |
| 3973 | foreach( $this->get Operations () as $op => $data){ | |
| 3974 | $b . = "<li><a href='#' o nclick=\"p opout();po pup('$op') \">$op</a> </li>"; | |
| 3975 | // c reate hidd en div | |
| 3976 | $b . = "<div id ='$op' cla ss='hidden '> | |
| 3977 | <a h ref='#' on click='pop out()'><fo nt color=' #ffffff'>C lose</font ></a><br>< br>"; | |
| 3978 | fore ach($data as $donnie => $marie ){ // loop through o pdata | |
| 3979 | if ($donnie = = 'input' || $donnie == 'outpu t'){ // sh ow input/o utput data | |
| 3980 | $b .= "< font color ='white'>" .ucfirst($ donnie).': </font><br >'; | |
| 3981 | foreach( $marie as $captain = > $tenille ){ // loop through d ata | |
| 3982 | if($ca ptain == ' parts'){ / / loop thr u parts | |
| 3983 | $b .= "  ; $ca ptain:<br> "; | |
| 3984 | //if (is_array( $tenille)) { | |
| 3985 | foreach( $tenille a s $joanie => $chachi ){ | |
| 3986 | $b .= "  ; &nb sp; $ joanie: $c hachi<br>" ; | |
| 3987 | } | |
| 3988 | //} | |
| 3989 | } else { | |
| 3990 | $b .= "  ; $ca ptain: $te nille<br>" ; | |
| 3991 | } | |
| 3992 | } | |
| 3993 | } else { | |
| 3994 | $b .= "< font color ='white'>" .ucfirst($ donnie).": </font> $m arie<br>"; | |
| 3995 | } | |
| 3996 | } | |
| 3997 | $b .= '</d iv>'; | |
| 3998 | } | |
| 3999 | $b .= ' | |
| 4000 | <ul> | |
| 4001 | </div> | |
| 4002 | </di v></body>< /html>'; | |
| 4003 | retu rn $b; | |
| 4004 | } | |
| 4005 | ||
| 4006 | /* * | |
| 4007 | * serialize the parsed wsdl | |
| 4008 | * | |
| 4009 | * @param mix ed $debug whether to put debug =1 in endp oint URL | |
| 4010 | * @return st ring seria lization o f WSDL | |
| 4011 | * @access pu blic | |
| 4012 | */ | |
| 4013 | fu nction ser ialize($de bug = 0) | |
| 4014 | { | |
| 4015 | $xml = '<?xml version="1 .0" encodi ng="ISO-88 59-1"?>'; | |
| 4016 | $xml .= "\n<de finitions" ; | |
| 4017 | fore ach($this- >namespace s as $k => $v) { | |
| 4018 | $xml . = " xmlns: $k=\"$v\"" ; | |
| 4019 | } | |
| 4020 | // 1 0.9.02 - a dd poulter fix for w sdl and tn s declarat ions | |
| 4021 | if ( isset($thi s->namespa ces['wsdl' ])) { | |
| 4022 | $xml . = " xmlns= \"" . $thi s->namespa ces['wsdl' ] . "\""; | |
| 4023 | } | |
| 4024 | if ( isset($thi s->namespa ces['tns'] )) { | |
| 4025 | $xml . = " target Namespace= \"" . $thi s->namespa ces['tns'] . "\""; | |
| 4026 | } | |
| 4027 | $xml .= '>'; | |
| 4028 | // i mports | |
| 4029 | if ( sizeof($th is->import ) > 0) { | |
| 4030 | foreac h($this->i mport as $ ns => $lis t) { | |
| 4031 | foreach ($list as $ii) { | |
| 4032 | if ($ii['l ocation'] != '') { | |
| 4033 | $x ml .= '<im port locat ion="' . $ ii['locati on'] . '" namespace= "' . $ns . '" />'; | |
| 4034 | } else { | |
| 4035 | $x ml .= '<im port names pace="' . $ns . '" / >'; | |
| 4036 | } | |
| 4037 | } | |
| 4038 | } | |
| 4039 | } | |
| 4040 | // t ypes | |
| 4041 | if ( count($thi s->schemas )>=1) { | |
| 4042 | $xml . = "\n<type s>\n"; | |
| 4043 | foreac h ($this-> schemas as $ns => $l ist) { | |
| 4044 | foreach ($list as $xs) { | |
| 4045 | $xml .= $x s->seriali zeSchema() ; | |
| 4046 | } | |
| 4047 | } | |
| 4048 | $xml . = '</types >'; | |
| 4049 | } | |
| 4050 | // m essages | |
| 4051 | if ( count($thi s->message s) >= 1) { | |
| 4052 | foreac h($this->m essages as $msgName => $msgPar ts) { | |
| 4053 | $xml .= "\n<messag e name=\"" . $msgNam e . '">'; | |
| 4054 | if(is_ar ray($msgPa rts)){ | |
| 4055 | foreach($m sgParts as $partName => $partT ype) { | |
| 4056 | if (strpos($ partType, ':')) { | |
| 4057 | $typePre fix = $thi s->getPref ixFromName space($thi s->getPref ix($partTy pe)); | |
| 4058 | } elseif (is set($this- >typemap[$ this->name spaces['xs d']][$part Type])) { | |
| 4059 | $typePre fix = 'xsd '; | |
| 4060 | } else { | |
| 4061 | foreach( $this->typ emap as $n s => $type s) { | |
| 4062 | if ( isset($typ es[$partTy pe])) { | |
| 4063 | $typePrefi x = $this- >getPrefix FromNamesp ace($ns); | |
| 4064 | } | |
| 4065 | } | |
| 4066 | if (!iss et($typePr efix)) { | |
| 4067 | die( "$partType has no na mespace!") ; | |
| 4068 | } | |
| 4069 | } | |
| 4070 | $n s = $this- >getNamesp aceFromPre fix($typeP refix); | |
| 4071 | $l ocalPart = $this->ge tLocalPart ($partType ); | |
| 4072 | $t ypeDef = $ this->getT ypeDef($lo calPart, $ ns); | |
| 4073 | if ($typeDef ['typeClas s'] == 'el ement') { | |
| 4074 | $ele mentortype = 'elemen t'; | |
| 4075 | if ( substr($lo calPart, - 1) == '^') { | |
| 4076 | $local Part = sub str($local Part, 0, - 1); | |
| 4077 | } | |
| 4078 | } else { | |
| 4079 | $ele mentortype = 'type'; | |
| 4080 | } | |
| 4081 | $x ml .= "\n" . ' <par t name="' . $partNam e . '" ' . $elemento rtype . '= "' . $type Prefix . ' :' . $loca lPart . '" />'; | |
| 4082 | } | |
| 4083 | } | |
| 4084 | $xml .= '</message >'; | |
| 4085 | } | |
| 4086 | } | |
| 4087 | // b indings & porttypes | |
| 4088 | if ( count($thi s->binding s) >= 1) { | |
| 4089 | $bindi ng_xml = ' '; | |
| 4090 | $portT ype_xml = ''; | |
| 4091 | foreac h($this->b indings as $bindingN ame => $at trs) { | |
| 4092 | $binding _xml .= "\ n<binding name=\"" . $bindingN ame . '" t ype="tns:' . $attrs[ 'portType' ] . '">'; | |
| 4093 | $binding _xml .= "\ n" . ' <s oap:bindin g style="' . $attrs[ 'style'] . '" transp ort="' . $ attrs['tra nsport'] . '"/>'; | |
| 4094 | $portTyp e_xml .= " \n<portTyp e name=\"" . $attrs[ 'portType' ] . '">'; | |
| 4095 | foreach( $attrs['op erations'] as $opNam e => $opPa rts) { | |
| 4096 | $binding_x ml .= "\n" . ' <ope ration nam e="' . $op Name . '"> '; | |
| 4097 | $binding_x ml .= "\n" . ' <s oap:operat ion soapAc tion="' . $opParts[' soapAction '] . '" st yle="'. $o pParts['st yle'] . '" />'; | |
| 4098 | if (isset( $opParts[' input']['e ncodingSty le']) && $ opParts['i nput']['en codingStyl e'] != '') { | |
| 4099 | $e nc_style = ' encodin gStyle="' . $opParts ['input'][ 'encodingS tyle'] . ' "'; | |
| 4100 | } else { | |
| 4101 | $e nc_style = ''; | |
| 4102 | } | |
| 4103 | $binding_x ml .= "\n" . ' <i nput><soap :body use= "' . $opPa rts['input ']['use'] . '" names pace="' . $opParts[' input']['n amespace'] . '"' . $ enc_style . '/></inp ut>'; | |
| 4104 | if (isset( $opParts[' output'][' encodingSt yle']) && $opParts[' output'][' encodingSt yle'] != ' ') { | |
| 4105 | $e nc_style = ' encodin gStyle="' . $opParts ['output'] ['encoding Style'] . '"'; | |
| 4106 | } else { | |
| 4107 | $e nc_style = ''; | |
| 4108 | } | |
| 4109 | $binding_x ml .= "\n" . ' <o utput><soa p:body use ="' . $opP arts['outp ut']['use' ] . '" nam espace="' . $opParts ['output'] ['namespac e'] . '"' . $enc_sty le . '/></ output>'; | |
| 4110 | $binding_x ml .= "\n" . ' </op eration>'; | |
| 4111 | $portType_ xml .= "\n " . ' <op eration na me="' . $o pParts['na me'] . '"' ; | |
| 4112 | if (isset( $opParts[' parameterO rder'])) { | |
| 4113 | $portT ype_xml .= ' paramet erOrder="' . $opPart s['paramet erOrder'] . '"'; | |
| 4114 | } | |
| 4115 | $portType_ xml .= '>' ; | |
| 4116 | if(isset($ opParts['d ocumentati on']) && $ opParts['d ocumentati on'] != '' ) { | |
| 4117 | $p ortType_xm l .= "\n" . ' <do cumentatio n>' . html specialcha rs($opPart s['documen tation']) . '</docum entation>' ; | |
| 4118 | } | |
| 4119 | $portType_ xml .= "\n " . ' < input mess age="tns:' . $opPart s['input'] ['message' ] . '"/>'; | |
| 4120 | $portType_ xml .= "\n " . ' < output mes sage="tns: ' . $opPar ts['output ']['messag e'] . '"/> '; | |
| 4121 | $portType_ xml .= "\n " . ' </o peration>' ; | |
| 4122 | } | |
| 4123 | $portTyp e_xml .= " \n" . '</p ortType>'; | |
| 4124 | $binding _xml .= "\ n" . '</bi nding>'; | |
| 4125 | } | |
| 4126 | $xml . = $portTyp e_xml . $b inding_xml ; | |
| 4127 | } | |
| 4128 | // s ervices | |
| 4129 | $xml .= "\n<se rvice name =\"" . $th is->servic eName . '" >'; | |
| 4130 | if ( count($thi s->ports) >= 1) { | |
| 4131 | foreac h($this->p orts as $p Name => $a ttrs) { | |
| 4132 | $xml .= "\n" . ' <port name ="' . $pNa me . '" bi nding="tns :' . $attr s['binding '] . '">'; | |
| 4133 | $xml .= "\n" . ' <soap:ad dress loca tion="' . $attrs['lo cation'] . ($debug ? '?debug=1 ' : '') . '"/>'; | |
| 4134 | $xml .= "\n" . ' </port>'; | |
| 4135 | } | |
| 4136 | } | |
| 4137 | $xml .= "\n" . '</servic e>'; | |
| 4138 | retu rn $xml . "\n</defin itions>"; | |
| 4139 | } | |
| 4140 | ||
| 4141 | /* * | |
| 4142 | * determine whether a set of pa rameters a re unwrapp ed | |
| 4143 | * when they are expec t to be wr apped, Mic rosoft-sty le. | |
| 4144 | * | |
| 4145 | * @param st ring $type the type (element n ame) of th e wrapper | |
| 4146 | * @param ar ray $param eters the parameter values for the SOAP call | |
| 4147 | * @return b oolean whe ther they parameters are unwra pped (and should be wrapped) | |
| 4148 | * @access p rivate | |
| 4149 | * / | |
| 4150 | fu nction par ametersMat chWrapped( $type, &$p arameters) { | |
| 4151 | $thi s->debug(" in paramet ersMatchWr apped type =$type, pa rameters=" ); | |
| 4152 | $thi s->appendD ebug($this ->varDump( $parameter s)); | |
| 4153 | ||
| 4154 | // s plit type into names pace:unqua lified-typ e | |
| 4155 | if ( strpos($ty pe, ':')) { | |
| 4156 | $uqTyp e = substr ($type, st rrpos($typ e, ':') + 1); | |
| 4157 | $ns = substr($ty pe, 0, str rpos($type , ':')); | |
| 4158 | $this- >debug("in parameter sMatchWrap ped: got a prefixed type: $uqT ype, $ns") ; | |
| 4159 | if ($t his->getNa mespaceFro mPrefix($n s)) { | |
| 4160 | $ns = $t his->getNa mespaceFro mPrefix($n s); | |
| 4161 | $this->d ebug("in p arametersM atchWrappe d: expande d prefixed type: $uq Type, $ns" ); | |
| 4162 | } | |
| 4163 | } el se { | |
| 4164 | // TOD O: should the type b e compared to types in XSD, an d the name space | |
| 4165 | // set to XSD if the type matches? | |
| 4166 | $this- >debug("in parameter sMatchWrap ped: No na mespace fo r type $ty pe"); | |
| 4167 | $ns = ''; | |
| 4168 | $uqTyp e = $type; | |
| 4169 | } | |
| 4170 | ||
| 4171 | // g et the typ e informat ion | |
| 4172 | if ( !$typeDef = $this->g etTypeDef( $uqType, $ ns)) { | |
| 4173 | $this- >debug("in parameter sMatchWrap ped: $type ($uqType) is not a supported type."); | |
| 4174 | return false; | |
| 4175 | } | |
| 4176 | $thi s->debug(" in paramet ersMatchWr apped: fou nd typeDef ="); | |
| 4177 | $thi s->appendD ebug($this ->varDump( $typeDef)) ; | |
| 4178 | if ( substr($uq Type, -1) == '^') { | |
| 4179 | $uqTyp e = substr ($uqType, 0, -1); | |
| 4180 | } | |
| 4181 | $php Type = $ty peDef['php Type']; | |
| 4182 | $arr ayType = ( isset($typ eDef['arra yType']) ? $typeDef[ 'arrayType '] : ''); | |
| 4183 | $thi s->debug(" in paramet ersMatchWr apped: uqT ype: $uqTy pe, ns: $n s, phptype : $phpType , arrayTyp e: $arrayT ype"); | |
| 4184 | ||
| 4185 | // w e expect a complexTy pe or elem ent of com plexType | |
| 4186 | if ( $phpType ! = 'struct' ) { | |
| 4187 | $this- >debug("in parameter sMatchWrap ped: not a struct"); | |
| 4188 | return false; | |
| 4189 | } | |
| 4190 | ||
| 4191 | // s ee whether the param eter names match the elements | |
| 4192 | if ( isset($typ eDef['elem ents']) && is_array( $typeDef[' elements'] )) { | |
| 4193 | $eleme nts = 0; | |
| 4194 | $match es = 0; | |
| 4195 | foreac h ($typeDe f['element s'] as $na me => $att rs) { | |
| 4196 | if (isse t($paramet ers[$name] )) { | |
| 4197 | $this->deb ug("in par ametersMat chWrapped: have para meter name d $name"); | |
| 4198 | $matches++ ; | |
| 4199 | } else { | |
| 4200 | $this->deb ug("in par ametersMat chWrapped: do not ha ve paramet er named $ name"); | |
| 4201 | } | |
| 4202 | $element s++; | |
| 4203 | } | |
| 4204 | ||
| 4205 | $this- >debug("in parameter sMatchWrap ped: $matc hes parame ter names match $ele ments wrap ped parame ter names" ); | |
| 4206 | if ($m atches == 0) { | |
| 4207 | return f alse; | |
| 4208 | } | |
| 4209 | return true; | |
| 4210 | } | |
| 4211 | ||
| 4212 | // s ince there are no el ements for the type, if the us er passed no | |
| 4213 | // p arameters, the param eters matc h wrapped. | |
| 4214 | $thi s->debug(" in paramet ersMatchWr apped: no elements t ype $ns:$u qType"); | |
| 4215 | retu rn count($ parameters ) == 0; | |
| 4216 | } | |
| 4217 | ||
| 4218 | /* * | |
| 4219 | * serialize PHP value s accordin g to a WSD L message definition | |
| 4220 | * contrary to the met hod name, this is no t limited to RPC | |
| 4221 | * | |
| 4222 | * TODO | |
| 4223 | * - multi-r ef seriali zation | |
| 4224 | * - validat e PHP valu es against type defi nitions, r eturn erro rs if inva lid | |
| 4225 | * | |
| 4226 | * @param st ring $oper ation oper ation name | |
| 4227 | * @param st ring $dire ction (inp ut|output) | |
| 4228 | * @param mi xed $param eters para meter valu e(s) | |
| 4229 | * @param st ring $bind ingType (s oap|soap12 ) | |
| 4230 | * @return m ixed param eters seri alized as XML or fal se on erro r (e.g. op eration no t found) | |
| 4231 | * @access p ublic | |
| 4232 | * / | |
| 4233 | fu nction ser ializeRPCP arameters( $operation , $directi on, $param eters, $bi ndingType = 'soap') { | |
| 4234 | $thi s->debug(" in seriali zeRPCParam eters: ope ration=$op eration, d irection=$ direction, XMLSchema Version=$t his->XMLSc hemaVersio n, binding Type=$bind ingType"); | |
| 4235 | $thi s->appendD ebug('para meters=' . $this->va rDump($par ameters)); | |
| 4236 | ||
| 4237 | if ( $direction != 'input ' && $dire ction != ' output') { | |
| 4238 | $this- >debug('Th e value of the \$dir ection arg ument need s to be ei ther "inpu t" or "out put"'); | |
| 4239 | $this- >setError( 'The value of the \$ direction argument n eeds to be either "i nput" or " output"'); | |
| 4240 | return false; | |
| 4241 | } | |
| 4242 | if ( !$opData = $this->ge tOperation Data($oper ation, $bi ndingType) ) { | |
| 4243 | $this- >debug('Un able to re trieve WSD L data for operation : ' . $ope ration . ' bindingTy pe: ' . $b indingType ); | |
| 4244 | $this- >setError( 'Unable to retrieve WSDL data for operat ion: ' . $ operation . ' bindin gType: ' . $bindingT ype); | |
| 4245 | return false; | |
| 4246 | } | |
| 4247 | $thi s->debug(' in seriali zeRPCParam eters: opD ata:'); | |
| 4248 | $thi s->appendD ebug($this ->varDump( $opData)); | |
| 4249 | ||
| 4250 | // G et encodin g style fo r output a nd set to current | |
| 4251 | $enc odingStyle = 'http:/ /schemas.x mlsoap.org /soap/enco ding/'; | |
| 4252 | if(( $direction == 'input ') && isse t($opData[ 'output'][ 'encodingS tyle']) && ($opData[ 'output'][ 'encodingS tyle'] != $encodingS tyle)) { | |
| 4253 | $encod ingStyle = $opData[' output'][' encodingSt yle']; | |
| 4254 | $enc_s tyle = $en codingStyl e; | |
| 4255 | } | |
| 4256 | ||
| 4257 | // s et input p arams | |
| 4258 | $xml = ''; | |
| 4259 | if ( isset($opD ata[$direc tion]['par ts']) && s izeof($opD ata[$direc tion]['par ts']) > 0) { | |
| 4260 | $parts = &$opDat a[$directi on]['parts ']; | |
| 4261 | $part_ count = si zeof($part s); | |
| 4262 | $style = $opData ['style']; | |
| 4263 | $use = $opData[$ direction] ['use']; | |
| 4264 | $this- >debug("ha ve $part_c ount part( s) to seri alize usin g $style/$ use"); | |
| 4265 | if (is _array($pa rameters)) { | |
| 4266 | $paramet ersArrayTy pe = $this ->isArrayS impleOrStr uct($param eters); | |
| 4267 | $paramet er_count = count($pa rameters); | |
| 4268 | $this->d ebug("have $paramete r_count pa rameter(s) provided as $parame tersArrayT ype to ser ialize"); | |
| 4269 | // check for Micro soft-style wrapped p arameters | |
| 4270 | if ($sty le == 'doc ument' && $use == 'l iteral' && $part_cou nt == 1 && isset($pa rts['param eters'])) { | |
| 4271 | $this->deb ug('check whether th e caller h as wrapped the param eters'); | |
| 4272 | if ($direc tion == 'o utput' && $parameter sArrayType == 'array Simple' && $paramete r_count == 1) { | |
| 4273 | // TODO: con sider chec king here for double -wrapping, when | |
| 4274 | // service f unction wr aps, then NuSOAP wra ps again | |
| 4275 | $t his->debug ("change s imple arra y to assoc iative wit h 'paramet ers' eleme nt"); | |
| 4276 | $p arameters[ 'parameter s'] = $par ameters[0] ; | |
| 4277 | un set($param eters[0]); | |
| 4278 | } | |
| 4279 | if (($para metersArra yType == ' arrayStruc t' || $par ameter_cou nt == 0) & & !isset($ parameters ['paramete rs'])) { | |
| 4280 | $t his->debug ('check wh ether call er\'s para meters mat ch the wra pped ones' ); | |
| 4281 | if ($this->p arametersM atchWrappe d($parts[' parameters '], $param eters)) { | |
| 4282 | $thi s->debug(' wrap the p arameters for the ca ller'); | |
| 4283 | $par ameters = array('par ameters' = > $paramet ers); | |
| 4284 | $par ameter_cou nt = 1; | |
| 4285 | } | |
| 4286 | } | |
| 4287 | } | |
| 4288 | foreach ($parts as $name => $type) { | |
| 4289 | $this->deb ug("serial izing part $name of type $type "); | |
| 4290 | // Track e ncoding st yle | |
| 4291 | if (isset( $opData[$d irection][ 'encodingS tyle']) && $encoding Style != $ opData[$di rection][' encodingSt yle']) { | |
| 4292 | $e ncodingSty le = $opDa ta[$direct ion]['enco dingStyle' ]; | |
| 4293 | $e nc_style = $encoding Style; | |
| 4294 | } else { | |
| 4295 | $e nc_style = false; | |
| 4296 | } | |
| 4297 | // NOTE: a dd error h andling he re | |
| 4298 | // if seri alizeType returns fa lse, then catch glob al error a nd fault | |
| 4299 | if ($param etersArray Type == 'a rraySimple ') { | |
| 4300 | $p = array_s hift($para meters); | |
| 4301 | $t his->debug ('calling serializeT ype w/inde xed param' ); | |
| 4302 | $x ml .= $thi s->seriali zeType($na me, $type, $p, $use, $enc_styl e); | |
| 4303 | } elseif ( isset($par ameters[$n ame])) { | |
| 4304 | $t his->debug ('calling serializeT ype w/name d param'); | |
| 4305 | $x ml .= $thi s->seriali zeType($na me, $type, $paramete rs[$name], $use, $en c_style); | |
| 4306 | } else { | |
| 4307 | // TODO: onl y send nil lable | |
| 4308 | $t his->debug ('calling serializeT ype w/null param'); | |
| 4309 | $x ml .= $thi s->seriali zeType($na me, $type, null, $us e, $enc_st yle); | |
| 4310 | } | |
| 4311 | } | |
| 4312 | } else { | |
| 4313 | $this->d ebug('no p arameters passed.'); | |
| 4314 | } | |
| 4315 | } | |
| 4316 | $thi s->debug(" serializeR PCParamete rs returni ng: $xml") ; | |
| 4317 | retu rn $xml; | |
| 4318 | } | |
| 4319 | ||
| 4320 | /* * | |
| 4321 | * serialize s a PHP va lue accord ing a give n type def inition | |
| 4322 | * | |
| 4323 | * @param st ring $name name of v alue (part or elemen t) | |
| 4324 | * @param st ring $type XML schem a type of value (typ e or eleme nt) | |
| 4325 | * @param mi xed $value a native PHP value (parameter value) | |
| 4326 | * @param st ring $use use for pa rt (encode d|literal) | |
| 4327 | * @param st ring $enco dingStyle SOAP encod ing style for the va lue (if di fferent th an the enc losing sty le) | |
| 4328 | * @param bo olean $unq ualified a kludge fo r what sho uld be XML namespace form hand ling | |
| 4329 | * @return s tring valu e serializ ed as an X ML string | |
| 4330 | * @access p rivate | |
| 4331 | * / | |
| 4332 | fu nction ser ializeType ($name, $t ype, $valu e, $use='e ncoded', $ encodingSt yle=false, $unqualif ied=false) | |
| 4333 | { | |
| 4334 | $thi s->debug(" in seriali zeType: na me=$name, type=$type , use=$use , encoding Style=$enc odingStyle , unqualif ied=" . ($ unqualifie d ? "unqua lified" : "qualified ")); | |
| 4335 | $thi s->appendD ebug("valu e=" . $thi s->varDump ($value)); | |
| 4336 | if($ use == 'en coded' && $encodingS tyle) { | |
| 4337 | $encod ingStyle = ' SOAP-EN V:encoding Style="' . $encoding Style . '" '; | |
| 4338 | } | |
| 4339 | ||
| 4340 | // i f a soapva l has been supplied, let its t ype overri de the WSD L | |
| 4341 | if (is_objec t($value) && get_cla ss($value) == 'soapv al') { | |
| 4342 | if ( $value->ty pe_ns) { | |
| 4343 | $type = $value-> type_ns . ':' . $val ue->type; | |
| 4344 | $force Type = tru e; | |
| 4345 | $this- >debug("in serialize Type: soap val overri des type t o $type"); | |
| 4346 | } el seif ($val ue->type) { | |
| 4347 | $type = $value-> type; | |
| 4348 | $force Type = tru e; | |
| 4349 | $this- >debug("in serialize Type: soap val overri des type t o $type"); | |
| 4350 | } el se { | |
| 4351 | $force Type = fal se; | |
| 4352 | $this- >debug("in serialize Type: soap val does n ot overrid e type"); | |
| 4353 | } | |
| 4354 | $att rs = $valu e->attribu tes; | |
| 4355 | $val ue = $valu e->value; | |
| 4356 | $thi s->debug(" in seriali zeType: so apval over rides valu e to $valu e"); | |
| 4357 | if ( $attrs) { | |
| 4358 | if (!i s_array($v alue)) { | |
| 4359 | $value[' !'] = $val ue; | |
| 4360 | } | |
| 4361 | foreac h ($attrs as $n => $ v) { | |
| 4362 | $value[' !' . $n] = $v; | |
| 4363 | } | |
| 4364 | $this- >debug("in serialize Type: soap val provid es attribu tes"); | |
| 4365 | } | |
| 4366 | } else { | |
| 4367 | $for ceType = f alse; | |
| 4368 | } | |
| 4369 | ||
| 4370 | $xml = ''; | |
| 4371 | if ( strpos($ty pe, ':')) { | |
| 4372 | $uqTyp e = substr ($type, st rrpos($typ e, ':') + 1); | |
| 4373 | $ns = substr($ty pe, 0, str rpos($type , ':')); | |
| 4374 | $this- >debug("in serialize Type: got a prefixed type: $uq Type, $ns" ); | |
| 4375 | if ($t his->getNa mespaceFro mPrefix($n s)) { | |
| 4376 | $ns = $t his->getNa mespaceFro mPrefix($n s); | |
| 4377 | $this->d ebug("in s erializeTy pe: expand ed prefixe d type: $u qType, $ns "); | |
| 4378 | } | |
| 4379 | ||
| 4380 | if($ns == $this- >XMLSchema Version || $ns == 'h ttp://sche mas.xmlsoa p.org/soap /encoding/ '){ | |
| 4381 | $this->d ebug('in s erializeTy pe: type n amespace i ndicates X ML Schema or SOAP En coding typ e'); | |
| 4382 | if ($unq ualified & & $use == 'literal') { | |
| 4383 | $elementNS = " xmlns =\"\""; | |
| 4384 | } else { | |
| 4385 | $elementNS = ''; | |
| 4386 | } | |
| 4387 | if (is_n ull($value )) { | |
| 4388 | if ($use = = 'literal ') { | |
| 4389 | // TODO: dep ends on mi nOccurs | |
| 4390 | $x ml = "<$na me$element NS/>"; | |
| 4391 | } else { | |
| 4392 | // TODO: dep ends on ni llable, wh ich should be checke d before c alling thi s method | |
| 4393 | $x ml = "<$na me$element NS xsi:nil =\"true\" xsi:type=\ "" . $this ->getPrefi xFromNames pace($ns) . ":$uqTyp e\"/>"; | |
| 4394 | } | |
| 4395 | $this->deb ug("in ser ializeType : returnin g: $xml"); | |
| 4396 | return $xm l; | |
| 4397 | } | |
| 4398 | if ($uqT ype == 'Ar ray') { | |
| 4399 | // JBoss/A xis does t his someti mes | |
| 4400 | return $th is->serial ize_val($v alue, $nam e, false, false, fal se, false, $use); | |
| 4401 | } | |
| 4402 | if ($u qType == ' boolean') { | |
| 4403 | if ((is_ string($va lue) && $v alue == 'f alse') || (! $value) ) { | |
| 4404 | $v alue = 'fa lse'; | |
| 4405 | } else { | |
| 4406 | $v alue = 'tr ue'; | |
| 4407 | } | |
| 4408 | } | |
| 4409 | if ($uqT ype == 'st ring' && g ettype($va lue) == 's tring') { | |
| 4410 | $value = $ this->expa ndEntities ($value); | |
| 4411 | } | |
| 4412 | if (($uq Type == 'l ong' || $u qType == ' unsignedLo ng') && ge ttype($val ue) == 'do uble') { | |
| 4413 | $value = s printf("%. 0lf", $val ue); | |
| 4414 | } | |
| 4415 | // it's a scalar | |
| 4416 | // TODO: what abou t null/nil values? | |
| 4417 | // check type isn' t a custom type exte nding xmls chema name space | |
| 4418 | if (!$th is->getTyp eDef($uqTy pe, $ns)) { | |
| 4419 | if ($use = = 'literal ') { | |
| 4420 | if ($forceTy pe) { | |
| 4421 | $xml = "<$name $elementNS xsi:type= \"" . $thi s->getPref ixFromName space($ns) . ":$uqTy pe\">$valu e</$name>" ; | |
| 4422 | } else { | |
| 4423 | $xml = "<$name $elementNS >$value</$ name>"; | |
| 4424 | } | |
| 4425 | } else { | |
| 4426 | $x ml = "<$na me$element NS xsi:typ e=\"" . $t his->getPr efixFromNa mespace($n s) . ":$uq Type\"$enc odingStyle >$value</$ name>"; | |
| 4427 | } | |
| 4428 | $this->deb ug("in ser ializeType : returnin g: $xml"); | |
| 4429 | return $xm l; | |
| 4430 | } | |
| 4431 | $this->d ebug('cust om type ex tends XML Schema or SOAP Encod ing namesp ace (yuck) '); | |
| 4432 | } else if ($ns = = 'http:// xml.apache .org/xml-s oap') { | |
| 4433 | $this->d ebug('in s erializeTy pe: appear s to be Ap ache SOAP type'); | |
| 4434 | if ($uqT ype == 'Ma p') { | |
| 4435 | $tt_prefix = $this-> getPrefixF romNamespa ce('http:/ /xml.apach e.org/xml- soap'); | |
| 4436 | if (! $tt_ prefix) { | |
| 4437 | $t his->debug ('in seria lizeType: Add namesp ace for Ap ache SOAP type'); | |
| 4438 | // changed to use crypt o_rand fro m rand for security scans - V LER EJ VAD -1523 | |
| 4439 | $t t_prefix = 'ns' . cr ypto_rand( 1000, 9999 ,false); | |
| 4440 | $t his->names paces[$tt_ prefix] = 'http://xm l.apache.o rg/xml-soa p'; | |
| 4441 | // force thi s to be ad ded to use dNamespace s | |
| 4442 | $t t_prefix = $this->ge tPrefixFro mNamespace ('http://x ml.apache. org/xml-so ap'); | |
| 4443 | } | |
| 4444 | $contents = ''; | |
| 4445 | foreach($v alue as $k => $v) { | |
| 4446 | $t his->debug ("serializ ing map el ement: key $k, value $v"); | |
| 4447 | $c ontents .= '<item>'; | |
| 4448 | $c ontents .= $this->se rialize_va l($k,'key' ,false,fal se,false,f alse,$use) ; | |
| 4449 | $c ontents .= $this->se rialize_va l($v,'valu e',false,f alse,false ,false,$us e); | |
| 4450 | $c ontents .= '</item>' ; | |
| 4451 | } | |
| 4452 | if ($use = = 'literal ') { | |
| 4453 | if ($forceTy pe) { | |
| 4454 | $xml = "<$name xsi:type= \"" . $tt_ prefix . " :$uqType\" >$contents </$name>"; | |
| 4455 | } else { | |
| 4456 | $xml = "<$name >$contents </$name>"; | |
| 4457 | } | |
| 4458 | } else { | |
| 4459 | $x ml = "<$na me xsi:typ e=\"" . $t t_prefix . ":$uqType \"$encodin gStyle>$co ntents</$n ame>"; | |
| 4460 | } | |
| 4461 | $this->deb ug("in ser ializeType : returnin g: $xml"); | |
| 4462 | return $xm l; | |
| 4463 | } | |
| 4464 | $this->d ebug('in s erializeTy pe: Apache SOAP type , but only support M ap'); | |
| 4465 | } | |
| 4466 | } el se { | |
| 4467 | // TOD O: should the type b e compared to types in XSD, an d the name space | |
| 4468 | // set to XSD if the type matches? | |
| 4469 | $this- >debug("in serialize Type: No n amespace f or type $t ype"); | |
| 4470 | $ns = ''; | |
| 4471 | $uqTyp e = $type; | |
| 4472 | } | |
| 4473 | if(! $typeDef = $this->ge tTypeDef($ uqType, $n s)){ | |
| 4474 | $this- >setError( "$type ($u qType) is not a supp orted type ."); | |
| 4475 | $this- >debug("in serialize Type: $typ e ($uqType ) is not a supported type."); | |
| 4476 | return false; | |
| 4477 | } el se { | |
| 4478 | $this- >debug("in serialize Type: foun d typeDef" ); | |
| 4479 | $this- >appendDeb ug('typeDe f=' . $thi s->varDump ($typeDef) ); | |
| 4480 | if (su bstr($uqTy pe, -1) == '^') { | |
| 4481 | $uqType = substr($ uqType, 0, -1); | |
| 4482 | } | |
| 4483 | } | |
| 4484 | if ( !isset($ty peDef['php Type'])) { | |
| 4485 | $this- >setError( "$type ($u qType) has no phpTyp e."); | |
| 4486 | $this- >debug("in serialize Type: $typ e ($uqType ) has no p hpType."); | |
| 4487 | return false; | |
| 4488 | } | |
| 4489 | $php Type = $ty peDef['php Type']; | |
| 4490 | $thi s->debug(" in seriali zeType: uq Type: $uqT ype, ns: $ ns, phptyp e: $phpTyp e, arrayTy pe: " . (i sset($type Def['array Type']) ? $typeDef[' arrayType' ] : '') ); | |
| 4491 | // i f php type == struct , map valu e to the < all> eleme nt names | |
| 4492 | if ( $phpType = = 'struct' ) { | |
| 4493 | if (is set($typeD ef['typeCl ass']) && $typeDef[' typeClass' ] == 'elem ent') { | |
| 4494 | $element Name = $uq Type; | |
| 4495 | if (isse t($typeDef ['form']) && ($typeD ef['form'] == 'quali fied')) { | |
| 4496 | $elementNS = " xmlns =\"$ns\""; | |
| 4497 | } else { | |
| 4498 | $elementNS = " xmlns =\"\""; | |
| 4499 | } | |
| 4500 | } else { | |
| 4501 | $element Name = $na me; | |
| 4502 | if ($unq ualified) { | |
| 4503 | $elementNS = " xmlns =\"\""; | |
| 4504 | } else { | |
| 4505 | $elementNS = ''; | |
| 4506 | } | |
| 4507 | } | |
| 4508 | if (is _null($val ue)) { | |
| 4509 | if ($use == 'liter al') { | |
| 4510 | // TODO: d epends on minOccurs and nillab le | |
| 4511 | $xml = "<$ elementNam e$elementN S/>"; | |
| 4512 | } else { | |
| 4513 | $xml = "<$ elementNam e$elementN S xsi:nil= \"true\" x si:type=\" " . $this- >getPrefix FromNamesp ace($ns) . ":$uqType \"/>"; | |
| 4514 | } | |
| 4515 | $this->d ebug("in s erializeTy pe: return ing: $xml" ); | |
| 4516 | return $ xml; | |
| 4517 | } | |
| 4518 | if (is _object($v alue)) { | |
| 4519 | $value = get_objec t_vars($va lue); | |
| 4520 | } | |
| 4521 | if (is _array($va lue)) { | |
| 4522 | $element Attrs = $t his->seria lizeComple xTypeAttri butes($typ eDef, $val ue, $ns, $ uqType); | |
| 4523 | if ($use == 'liter al') { | |
| 4524 | if ($force Type) { | |
| 4525 | $x ml = "<$el ementName$ elementNS$ elementAtt rs xsi:typ e=\"" . $t his->getPr efixFromNa mespace($n s) . ":$uq Type\">"; | |
| 4526 | } else { | |
| 4527 | $x ml = "<$el ementName$ elementNS$ elementAtt rs>"; | |
| 4528 | } | |
| 4529 | } else { | |
| 4530 | $xml = "<$ elementNam e$elementN S$elementA ttrs xsi:t ype=\"" . $this->get PrefixFrom Namespace( $ns) . ":$ uqType\"$e ncodingSty le>"; | |
| 4531 | } | |
| 4532 | ||
| 4533 | if (isse t($typeDef ['simpleCo ntent']) & & $typeDef ['simpleCo ntent'] == 'true') { | |
| 4534 | if (isset( $value['!' ])) { | |
| 4535 | $x ml .= $val ue['!']; | |
| 4536 | $t his->debug ("in seria lizeType: serialized simpleCon tent for t ype $type" ); | |
| 4537 | } else { | |
| 4538 | $t his->debug ("in seria lizeType: no simpleC ontent to serialize for type $ type"); | |
| 4539 | } | |
| 4540 | } else { | |
| 4541 | // complex Content | |
| 4542 | $xml .= $t his->seria lizeComple xTypeEleme nts($typeD ef, $value , $ns, $uq Type, $use , $encodin gStyle); | |
| 4543 | } | |
| 4544 | $xml .= "</$elemen tName>"; | |
| 4545 | } else { | |
| 4546 | $this->d ebug("in s erializeTy pe: phpTyp e is struc t, but val ue is not an array") ; | |
| 4547 | $this->s etError("p hpType is struct, bu t value is not an ar ray: see d ebug outpu t for deta ils"); | |
| 4548 | $xml = ' '; | |
| 4549 | } | |
| 4550 | } el seif ($php Type == 'a rray') { | |
| 4551 | if (is set($typeD ef['form'] ) && ($typ eDef['form '] == 'qua lified')) { | |
| 4552 | $element NS = " xml ns=\"$ns\" "; | |
| 4553 | } else { | |
| 4554 | if ($unq ualified) { | |
| 4555 | $elementNS = " xmlns =\"\""; | |
| 4556 | } else { | |
| 4557 | $elementNS = ''; | |
| 4558 | } | |
| 4559 | } | |
| 4560 | if (is _null($val ue)) { | |
| 4561 | if ($use == 'liter al') { | |
| 4562 | // TODO: d epends on minOccurs | |
| 4563 | $xml = "<$ name$eleme ntNS/>"; | |
| 4564 | } else { | |
| 4565 | $xml = "<$ name$eleme ntNS xsi:n il=\"true\ " xsi:type =\"" . | |
| 4566 | $t his->getPr efixFromNa mespace('h ttp://sche mas.xmlsoa p.org/soap /encoding/ ') . | |
| 4567 | ": Array\" " . | |
| 4568 | $t his->getPr efixFromNa mespace('h ttp://sche mas.xmlsoa p.org/soap /encoding/ ') . | |
| 4569 | ': arrayType= "' . | |
| 4570 | $t his->getPr efixFromNa mespace($t his->getPr efix($type Def['array Type'])) . | |
| 4571 | ': ' . | |
| 4572 | $t his->getLo calPart($t ypeDef['ar rayType']) ."[0]\"/>" ; | |
| 4573 | } | |
| 4574 | $this->d ebug("in s erializeTy pe: return ing: $xml" ); | |
| 4575 | return $ xml; | |
| 4576 | } | |
| 4577 | if (is set($typeD ef['multid imensional '])) { | |
| 4578 | $nv = ar ray(); | |
| 4579 | foreach( $value as $v) { | |
| 4580 | $cols = ', ' . sizeof ($v); | |
| 4581 | $nv = arra y_merge($n v, $v); | |
| 4582 | } | |
| 4583 | $value = $nv; | |
| 4584 | } else { | |
| 4585 | $cols = ''; | |
| 4586 | } | |
| 4587 | if (is _array($va lue) && si zeof($valu e) >= 1) { | |
| 4588 | $rows = sizeof($va lue); | |
| 4589 | $content s = ''; | |
| 4590 | foreach( $value as $k => $v) { | |
| 4591 | $this->deb ug("serial izing arra y element: $k, $v of type: $ty peDef[arra yType]"); | |
| 4592 | //if (strp os($typeDe f['arrayTy pe'], ':') ) { | |
| 4593 | if (!in_ar ray($typeD ef['arrayT ype'],$thi s->typemap ['http://w ww.w3.org/ 2001/XMLSc hema'])) { | |
| 4594 | $conte nts .= $th is->serial izeType('i tem', $typ eDef['arra yType'], $ v, $use); | |
| 4595 | } else { | |
| 4596 | $conte nts .= $th is->serial ize_val($v , 'item', $typeDef[' arrayType' ], null, $ this->XMLS chemaVersi on, false, $use); | |
| 4597 | } | |
| 4598 | } | |
| 4599 | } else { | |
| 4600 | $rows = 0; | |
| 4601 | $content s = null; | |
| 4602 | } | |
| 4603 | // TOD O: for now , an empty value wil l be seria lized as a zero elem ent | |
| 4604 | // arr ay. Revis it this wh en coding the handli ng of null /nil value s. | |
| 4605 | if ($u se == 'lit eral') { | |
| 4606 | $xml = " <$name$ele mentNS>" | |
| 4607 | .$contents | |
| 4608 | ."</$name> "; | |
| 4609 | } else { | |
| 4610 | $xml = " <$name$ele mentNS xsi :type=\"". $this->get PrefixFrom Namespace( 'http://sc hemas.xmls oap.org/so ap/encodin g/').':Arr ay" '. | |
| 4611 | $this->get PrefixFrom Namespace( 'http://sc hemas.xmls oap.org/so ap/encodin g/') | |
| 4612 | .':arrayTy pe="' | |
| 4613 | .$this->ge tPrefixFro mNamespace ($this->ge tPrefix($t ypeDef['ar rayType']) ) | |
| 4614 | .":".$this ->getLocal Part($type Def['array Type'])."[ $rows$cols ]\">" | |
| 4615 | .$contents | |
| 4616 | ."</$name> "; | |
| 4617 | } | |
| 4618 | } el seif ($php Type == 's calar') { | |
| 4619 | if (is set($typeD ef['form'] ) && ($typ eDef['form '] == 'qua lified')) { | |
| 4620 | $element NS = " xml ns=\"$ns\" "; | |
| 4621 | } else { | |
| 4622 | if ($unq ualified) { | |
| 4623 | $elementNS = " xmlns =\"\""; | |
| 4624 | } else { | |
| 4625 | $elementNS = ''; | |
| 4626 | } | |
| 4627 | } | |
| 4628 | if ($u se == 'lit eral') { | |
| 4629 | if ($for ceType) { | |
| 4630 | $xml = "<$ name$eleme ntNS xsi:t ype=\"" . $this->get PrefixFrom Namespace( $ns) . ":$ uqType\">$ value</$na me>"; | |
| 4631 | } else { | |
| 4632 | $xml = "<$ name$eleme ntNS>$valu e</$name>" ; | |
| 4633 | } | |
| 4634 | } else { | |
| 4635 | $xml = " <$name$ele mentNS xsi :type=\"" . $this->g etPrefixFr omNamespac e($ns) . " :$uqType\" $encodingS tyle>$valu e</$name>" ; | |
| 4636 | } | |
| 4637 | } | |
| 4638 | $thi s->debug(" in seriali zeType: re turning: $ xml"); | |
| 4639 | retu rn $xml; | |
| 4640 | } | |
| 4641 | ||
| 4642 | /* * | |
| 4643 | * serialize s the attr ibutes for a complex Type | |
| 4644 | * | |
| 4645 | * @param ar ray $typeD ef our int ernal repr esentation of an XML schema ty pe (or ele ment) | |
| 4646 | * @param mi xed $value a native PHP value (parameter value) | |
| 4647 | * @param st ring $ns t he namespa ce of the type | |
| 4648 | * @param st ring $uqTy pe the loc al part of the type | |
| 4649 | * @return s tring valu e serializ ed as an X ML string | |
| 4650 | * @access p rivate | |
| 4651 | * / | |
| 4652 | fu nction ser ializeComp lexTypeAtt ributes($t ypeDef, $v alue, $ns, $uqType) { | |
| 4653 | $thi s->debug(" serializeC omplexType Attributes for XML S chema type $ns:$uqTy pe"); | |
| 4654 | $xml = ''; | |
| 4655 | if ( isset($typ eDef['exte nsionBase' ])) { | |
| 4656 | $nsx = $this->ge tPrefix($t ypeDef['ex tensionBas e']); | |
| 4657 | $uqTyp ex = $this ->getLocal Part($type Def['exten sionBase'] ); | |
| 4658 | if ($t his->getNa mespaceFro mPrefix($n sx)) { | |
| 4659 | $nsx = $ this->getN amespaceFr omPrefix($ nsx); | |
| 4660 | } | |
| 4661 | if ($t ypeDefx = $this->get TypeDef($u qTypex, $n sx)) { | |
| 4662 | $this->d ebug("seri alize attr ibutes for extension base $nsx :$uqTypex" ); | |
| 4663 | $xml .= $this->ser ializeComp lexTypeAtt ributes($t ypeDefx, $ value, $ns x, $uqType x); | |
| 4664 | } else { | |
| 4665 | $this->d ebug("exte nsion base $nsx:$uqT ypex is no t a suppor ted type") ; | |
| 4666 | } | |
| 4667 | } | |
| 4668 | if ( isset($typ eDef['attr s']) && is _array($ty peDef['att rs'])) { | |
| 4669 | $this- >debug("se rialize at tributes f or XML Sch ema type $ ns:$uqType "); | |
| 4670 | if (is _array($va lue)) { | |
| 4671 | $xvalue = $value; | |
| 4672 | } else if (is_obj ect($value )) { | |
| 4673 | $xvalue = get_obje ct_vars($v alue); | |
| 4674 | } else { | |
| 4675 | $this->d ebug("valu e is neith er an arra y nor an o bject for XML Schema type $ns: $uqType"); | |
| 4676 | $xvalue = array(); | |
| 4677 | } | |
| 4678 | foreac h ($typeDe f['attrs'] as $aName => $attrs ) { | |
| 4679 | if (isse t($xvalue[ '!' . $aNa me])) { | |
| 4680 | $xname = ' !' . $aNam e; | |
| 4681 | $this->deb ug("value provided f or attribu te $aName with key $ xname"); | |
| 4682 | } elseif (isset($x value[$aNa me])) { | |
| 4683 | $xname = $ aName; | |
| 4684 | $this->deb ug("value provided f or attribu te $aName with key $ xname"); | |
| 4685 | } elseif (isset($a ttrs['defa ult'])) { | |
| 4686 | $xname = ' !' . $aNam e; | |
| 4687 | $xvalue[$x name] = $a ttrs['defa ult']; | |
| 4688 | $this->deb ug('use de fault valu e of ' . $ xvalue[$aN ame] . ' f or attribu te ' . $aN ame); | |
| 4689 | } else { | |
| 4690 | $xname = ' '; | |
| 4691 | $this->deb ug("no val ue provide d for attr ibute $aNa me"); | |
| 4692 | } | |
| 4693 | if ($xna me) { | |
| 4694 | $xml .= " $aName=\" " . $this- >expandEnt ities($xva lue[$xname ]) . "\""; | |
| 4695 | } | |
| 4696 | } | |
| 4697 | } el se { | |
| 4698 | $this- >debug("no attribute s to seria lize for X ML Schema type $ns:$ uqType"); | |
| 4699 | } | |
| 4700 | retu rn $xml; | |
| 4701 | } | |
| 4702 | ||
| 4703 | /* * | |
| 4704 | * serialize s the elem ents for a complexTy pe | |
| 4705 | * | |
| 4706 | * @param ar ray $typeD ef our int ernal repr esentation of an XML schema ty pe (or ele ment) | |
| 4707 | * @param mi xed $value a native PHP value (parameter value) | |
| 4708 | * @param st ring $ns t he namespa ce of the type | |
| 4709 | * @param st ring $uqTy pe the loc al part of the type | |
| 4710 | * @param st ring $use use for pa rt (encode d|literal) | |
| 4711 | * @param st ring $enco dingStyle SOAP encod ing style for the va lue (if di fferent th an the enc losing sty le) | |
| 4712 | * @return s tring valu e serializ ed as an X ML string | |
| 4713 | * @access p rivate | |
| 4714 | * / | |
| 4715 | fu nction ser ializeComp lexTypeEle ments($typ eDef, $val ue, $ns, $ uqType, $u se='encode d', $encod ingStyle=f alse) { | |
| 4716 | $thi s->debug(" in seriali zeComplexT ypeElement s for XML Schema typ e $ns:$uqT ype"); | |
| 4717 | $xml = ''; | |
| 4718 | if ( isset($typ eDef['exte nsionBase' ])) { | |
| 4719 | $nsx = $this->ge tPrefix($t ypeDef['ex tensionBas e']); | |
| 4720 | $uqTyp ex = $this ->getLocal Part($type Def['exten sionBase'] ); | |
| 4721 | if ($t his->getNa mespaceFro mPrefix($n sx)) { | |
| 4722 | $nsx = $ this->getN amespaceFr omPrefix($ nsx); | |
| 4723 | } | |
| 4724 | if ($t ypeDefx = $this->get TypeDef($u qTypex, $n sx)) { | |
| 4725 | $this->d ebug("seri alize elem ents for e xtension b ase $nsx:$ uqTypex"); | |
| 4726 | $xml .= $this->ser ializeComp lexTypeEle ments($typ eDefx, $va lue, $nsx, $uqTypex, $use, $en codingStyl e); | |
| 4727 | } else { | |
| 4728 | $this->d ebug("exte nsion base $nsx:$uqT ypex is no t a suppor ted type") ; | |
| 4729 | } | |
| 4730 | } | |
| 4731 | if ( isset($typ eDef['elem ents']) && is_array( $typeDef[' elements'] )) { | |
| 4732 | $this- >debug("in serialize ComplexTyp eElements, serialize elements for XML Sc hema type $ns:$uqTyp e"); | |
| 4733 | if (is _array($va lue)) { | |
| 4734 | $xvalue = $value; | |
| 4735 | } else if (is_obj ect($value )) { | |
| 4736 | $xvalue = get_obje ct_vars($v alue); | |
| 4737 | } else { | |
| 4738 | $this->d ebug("valu e is neith er an arra y nor an o bject for XML Schema type $ns: $uqType"); | |
| 4739 | $xvalue = array(); | |
| 4740 | } | |
| 4741 | // tog gle whethe r all elem ents are p resent - i deally sho uld valida te against schema | |
| 4742 | if (co unt($typeD ef['elemen ts']) != c ount($xval ue)){ | |
| 4743 | $optiona ls = true; | |
| 4744 | } | |
| 4745 | foreac h ($typeDe f['element s'] as $eN ame => $at trs) { | |
| 4746 | if (!iss et($xvalue [$eName])) { | |
| 4747 | if (isset( $attrs['de fault'])) { | |
| 4748 | $x value[$eNa me] = $att rs['defaul t']; | |
| 4749 | $t his->debug ('use defa ult value of ' . $xv alue[$eNam e] . ' for element ' . $eName) ; | |
| 4750 | } | |
| 4751 | } | |
| 4752 | // if us er took ad vantage of a minOccu rs=0, then only seri alize name d paramete rs | |
| 4753 | if (isse t($optiona ls) | |
| 4754 | && ( !isset($xv alue[$eNam e])) | |
| 4755 | && ( (!iss et($attrs[ 'nillable' ])) || $at trs['nilla ble'] != ' true') | |
| 4756 | ){ | |
| 4757 | if (isset( $attrs['mi nOccurs']) && $attrs ['minOccur s'] <> '0' ) { | |
| 4758 | $t his->debug ("apparent error: no value pro vided for element $e Name with minOccurs= " . $attrs ['minOccur s']); | |
| 4759 | } | |
| 4760 | // do noth ing | |
| 4761 | $this->deb ug("no val ue provide d for comp lexType el ement $eNa me and ele ment is no t nillable , so seria lize nothi ng"); | |
| 4762 | } else { | |
| 4763 | // get val ue | |
| 4764 | if (isset( $xvalue[$e Name])) { | |
| 4765 | $v = $ xvalue[$eN ame]; | |
| 4766 | } else { | |
| 4767 | $v = n ull; | |
| 4768 | } | |
| 4769 | if (isset( $attrs['fo rm'])) { | |
| 4770 | $u nqualified = ($attrs ['form'] = = 'unquali fied'); | |
| 4771 | } else { | |
| 4772 | $u nqualified = false; | |
| 4773 | } | |
| 4774 | if (isset( $attrs['ma xOccurs']) && ($attr s['maxOccu rs'] == 'u nbounded' || $attrs[ 'maxOccurs '] > 1) && isset($v) && is_arr ay($v) && $this->isA rraySimple OrStruct($ v) == 'arr aySimple') { | |
| 4775 | $v v = $v; | |
| 4776 | fo reach ($vv as $k => $v) { | |
| 4777 | if ( isset($att rs['type'] ) || isset ($attrs['r ef'])) { | |
| 4778 | // ser ialize sch ema-define d type | |
| 4779 | $xml .= $t his->seria lizeType($ eName, iss et($attrs[ 'type']) ? $attrs['t ype'] : $a ttrs['ref' ], $v, $us e, $encodi ngStyle, $ unqualifie d); | |
| 4780 | } el se { | |
| 4781 | // ser ialize gen eric type (can this ever reall y happen?) | |
| 4782 | $this->deb ug("callin g serializ e_val() fo r $v, $eNa me, false, false, fa lse, false , $use"); | |
| 4783 | $xml .= $t his->seria lize_val($ v, $eName, false, fa lse, false , false, $ use); | |
| 4784 | } | |
| 4785 | } | |
| 4786 | } else { | |
| 4787 | if (is_null( $v) && iss et($attrs[ 'minOccurs ']) && $at trs['minOc curs'] == '0') { | |
| 4788 | // d o nothing | |
| 4789 | } elseif (is _null($v) && isset($ attrs['nil lable']) & & $attrs[' nillable'] == 'true' ) { | |
| 4790 | // T ODO: seria lize a nil correctly , but for now serial ize schema -defined t ype | |
| 4791 | $xml .= $this->ser ializeType ($eName, i sset($attr s['type']) ? $attrs[ 'type'] : $attrs['re f'], $v, $ use, $enco dingStyle, $unqualif ied); | |
| 4792 | } elseif (is set($attrs ['type']) || isset($ attrs['ref '])) { | |
| 4793 | // s erialize s chema-defi ned type | |
| 4794 | $xml .= $this->ser ializeType ($eName, i sset($attr s['type']) ? $attrs[ 'type'] : $attrs['re f'], $v, $ use, $enco dingStyle, $unqualif ied); | |
| 4795 | } else { | |
| 4796 | // s erialize g eneric typ e (can thi s ever rea lly happen ?) | |
| 4797 | $this->d ebug("call ing serial ize_val() for $v, $e Name, fals e, false, false, fal se, $use") ; | |
| 4798 | $xml .= $this->ser ialize_val ($v, $eNam e, false, false, fal se, false, $use); | |
| 4799 | } | |
| 4800 | } | |
| 4801 | } | |
| 4802 | } | |
| 4803 | } el se { | |
| 4804 | $this- >debug("no elements to seriali ze for XML Schema ty pe $ns:$uq Type"); | |
| 4805 | } | |
| 4806 | retu rn $xml; | |
| 4807 | } | |
| 4808 | ||
| 4809 | /* * | |
| 4810 | * adds an XM L Schema c omplex typ e to the W SDL types | |
| 4811 | * | |
| 4812 | * @param str ing $name | |
| 4813 | * @param str ing $typeC lass (comp lexType|si mpleType|a ttribute) | |
| 4814 | * @param str ing $phpTy pe current ly support ed are arr ay and str uct (php a ssoc array ) | |
| 4815 | * @param str ing $compo sitor (all |sequence| choice) | |
| 4816 | * @param str ing $restr ictionBase namespace :name (htt p://schema s.xmlsoap. org/soap/e ncoding/:A rray) | |
| 4817 | * @param arr ay $elemen ts e.g. ar ray ( name => array( name=>'',t ype=>'') ) | |
| 4818 | * @param arr ay $attrs e.g. array (array('re f'=>'SOAP- ENC:arrayT ype','wsdl :arrayType '=>'xsd:st ring[]')) | |
| 4819 | * @param str ing $array Type as na mespace:na me (xsd:st ring) | |
| 4820 | * @see nusoa p_xmlschem a | |
| 4821 | * @access pu blic | |
| 4822 | */ | |
| 4823 | fu nction add ComplexTyp e($name,$t ypeClass=' complexTyp e',$phpTyp e='array', $composito r='',$rest rictionBas e='',$elem ents=array (),$attrs= array(),$a rrayType=' ') { | |
| 4824 | if ( count($ele ments) > 0 ) { | |
| 4825 | $eElem ents = arr ay(); | |
| 4826 | fore ach($eleme nts as $n => $e){ | |
| 4827 | // expand each eleme nt | |
| 4828 | $ee = arra y(); | |
| 4829 | foreach ($ e as $k => $v) { | |
| 4830 | $k = strpos( $k,':') ? $this->exp andQname($ k) : $k; | |
| 4831 | $v = strpos( $v,':') ? $this->exp andQname($ v) : $v; | |
| 4832 | $e e[$k] = $v ; | |
| 4833 | } | |
| 4834 | $eElem ents[$n] = $ee; | |
| 4835 | } | |
| 4836 | $ele ments = $e Elements; | |
| 4837 | } | |
| 4838 | ||
| 4839 | if ( count($att rs) > 0) { | |
| 4840 | fore ach($attrs as $n => $a){ | |
| 4841 | // expand each attri bute | |
| 4842 | foreach ($ a as $k => $v) { | |
| 4843 | $k = strpos( $k,':') ? $this->exp andQname($ k) : $k; | |
| 4844 | $v = strpos( $v,':') ? $this->exp andQname($ v) : $v; | |
| 4845 | $a a[$k] = $v ; | |
| 4846 | } | |
| 4847 | $eAttr s[$n] = $a a; | |
| 4848 | } | |
| 4849 | $att rs = $eAtt rs; | |
| 4850 | } | |
| 4851 | ||
| 4852 | $res trictionBa se = strpo s($restric tionBase,' :') ? $thi s->expandQ name($rest rictionBas e) : $rest rictionBas e; | |
| 4853 | $arr ayType = s trpos($arr ayType,':' ) ? $this- >expandQna me($arrayT ype) : $ar rayType; | |
| 4854 | ||
| 4855 | $typ ens = isse t($this->n amespaces[ 'types']) ? $this->n amespaces[ 'types'] : $this->na mespaces[' tns']; | |
| 4856 | $thi s->schemas [$typens][ 0]->addCom plexType($ name,$type Class,$php Type,$comp ositor,$re strictionB ase,$eleme nts,$attrs ,$arrayTyp e); | |
| 4857 | } | |
| 4858 | ||
| 4859 | /* * | |
| 4860 | * adds an XM L Schema s imple type to the WS DL types | |
| 4861 | * | |
| 4862 | * @param str ing $name | |
| 4863 | * @param str ing $restr ictionBase namespace :name (htt p://schema s.xmlsoap. org/soap/e ncoding/:A rray) | |
| 4864 | * @param str ing $typeC lass (shou ld always be simpleT ype) | |
| 4865 | * @param str ing $phpTy pe (should always be scalar) | |
| 4866 | * @param arr ay $enumer ation arra y of value s | |
| 4867 | * @see nusoa p_xmlschem a | |
| 4868 | * @access pu blic | |
| 4869 | */ | |
| 4870 | fu nction add SimpleType ($name, $r estriction Base='', $ typeClass= 'simpleTyp e', $phpTy pe='scalar ', $enumer ation=arra y()) { | |
| 4871 | $res trictionBa se = strpo s($restric tionBase,' :') ? $thi s->expandQ name($rest rictionBas e) : $rest rictionBas e; | |
| 4872 | ||
| 4873 | $typ ens = isse t($this->n amespaces[ 'types']) ? $this->n amespaces[ 'types'] : $this->na mespaces[' tns']; | |
| 4874 | $thi s->schemas [$typens][ 0]->addSim pleType($n ame, $rest rictionBas e, $typeCl ass, $phpT ype, $enum eration); | |
| 4875 | } | |
| 4876 | ||
| 4877 | /* * | |
| 4878 | * adds an el ement to t he WSDL ty pes | |
| 4879 | * | |
| 4880 | * @param arr ay $attrs attributes that must include n ame and ty pe | |
| 4881 | * @see nusoa p_xmlschem a | |
| 4882 | * @access pu blic | |
| 4883 | */ | |
| 4884 | fu nction add Element($a ttrs) { | |
| 4885 | $typ ens = isse t($this->n amespaces[ 'types']) ? $this->n amespaces[ 'types'] : $this->na mespaces[' tns']; | |
| 4886 | $thi s->schemas [$typens][ 0]->addEle ment($attr s); | |
| 4887 | } | |
| 4888 | ||
| 4889 | /* * | |
| 4890 | * register a n operatio n with the server | |
| 4891 | * | |
| 4892 | * @param str ing $name operation (method) n ame | |
| 4893 | * @param arr ay $in ass oc array o f input va lues: key = param na me, value = param ty pe | |
| 4894 | * @param arr ay $out as soc array of output values: ke y = param name, valu e = param type | |
| 4895 | * @param str ing $names pace optio nal The na mespace fo r the oper ation | |
| 4896 | * @param str ing $soapa ction opti onal The s oapaction for the op eration | |
| 4897 | * @param str ing $style (rpc|docu ment) opti onal The s tyle for t he operati on Note: w hen 'docum ent' is sp ecified, p arameter a nd return wrappers a re created for you a utomatical ly | |
| 4898 | * @param str ing $use ( encoded|li teral) opt ional The use for th e paramete rs (cannot mix right now) | |
| 4899 | * @param str ing $docum entation o ptional Th e descript ion to inc lude in th e WSDL | |
| 4900 | * @param str ing $encod ingStyle o ptional (u sually 'ht tp://schem as.xmlsoap .org/soap/ encoding/' for encod ed) | |
| 4901 | * @access pu blic | |
| 4902 | */ | |
| 4903 | fu nction add Operation( $name, $in = false, $out = fal se, $names pace = fal se, $soapa ction = fa lse, $styl e = 'rpc', $use = 'e ncoded', $ documentat ion = '', $encodingS tyle = '') { | |
| 4904 | if ( $use == 'e ncoded' && $encoding Style == ' ') { | |
| 4905 | $encod ingStyle = 'http://s chemas.xml soap.org/s oap/encodi ng/'; | |
| 4906 | } | |
| 4907 | ||
| 4908 | if ( $style == 'document' ) { | |
| 4909 | $eleme nts = arra y(); | |
| 4910 | foreac h ($in as $n => $t) { | |
| 4911 | $element s[$n] = ar ray('name' => $n, 't ype' => $t , 'form' = > 'unquali fied'); | |
| 4912 | } | |
| 4913 | $this- >addComple xType($nam e . 'Reque stType', ' complexTyp e', 'struc t', 'all', '', $elem ents); | |
| 4914 | $this- >addElemen t(array('n ame' => $n ame, 'type ' => $name . 'Reques tType')); | |
| 4915 | $in = array('par ameters' = > 'tns:' . $name . ' ^'); | |
| 4916 | ||
| 4917 | $eleme nts = arra y(); | |
| 4918 | foreac h ($out as $n => $t) { | |
| 4919 | $element s[$n] = ar ray('name' => $n, 't ype' => $t , 'form' = > 'unquali fied'); | |
| 4920 | } | |
| 4921 | $this- >addComple xType($nam e . 'Respo nseType', 'complexTy pe', 'stru ct', 'all' , '', $ele ments); | |
| 4922 | $this- >addElemen t(array('n ame' => $n ame . 'Res ponse', 't ype' => $n ame . 'Res ponseType' , 'form' = > 'qualifi ed')); | |
| 4923 | $out = array('pa rameters' => 'tns:' . $name . 'Response' . '^'); | |
| 4924 | } | |
| 4925 | ||
| 4926 | // g et binding | |
| 4927 | $thi s->binding s[ $this-> serviceNam e . 'Bindi ng' ]['ope rations'][ $name] = | |
| 4928 | arra y( | |
| 4929 | 'nam e' => $nam e, | |
| 4930 | 'bin ding' => $ this->serv iceName . 'Binding', | |
| 4931 | 'end point' => $this->end point, | |
| 4932 | 'soa pAction' = > $soapact ion, | |
| 4933 | 'sty le' => $st yle, | |
| 4934 | 'inp ut' => arr ay( | |
| 4935 | 'use' => $use, | |
| 4936 | 'names pace' => $ namespace, | |
| 4937 | 'encod ingStyle' => $encodi ngStyle, | |
| 4938 | 'messa ge' => $na me . 'Requ est', | |
| 4939 | 'parts ' => $in), | |
| 4940 | 'out put' => ar ray( | |
| 4941 | 'use' => $use, | |
| 4942 | 'names pace' => $ namespace, | |
| 4943 | 'encod ingStyle' => $encodi ngStyle, | |
| 4944 | 'messa ge' => $na me . 'Resp onse', | |
| 4945 | 'parts ' => $out) , | |
| 4946 | 'nam espace' => $namespac e, | |
| 4947 | 'tra nsport' => 'http://s chemas.xml soap.org/s oap/http', | |
| 4948 | 'doc umentation ' => $docu mentation) ; | |
| 4949 | // a dd portTyp es | |
| 4950 | // a dd message s | |
| 4951 | if($ in) | |
| 4952 | { | |
| 4953 | foreac h($in as $ pName => $ pType) | |
| 4954 | { | |
| 4955 | if(strpo s($pType,' :')) { | |
| 4956 | $pType = $ this->getN amespaceFr omPrefix($ this->getP refix($pTy pe)).":".$ this->getL ocalPart($ pType); | |
| 4957 | } | |
| 4958 | $this->m essages[$n ame.'Reque st'][$pNam e] = $pTyp e; | |
| 4959 | } | |
| 4960 | } el se { | |
| 4961 | $this->m essages[$n ame.'Reque st']= '0'; | |
| 4962 | } | |
| 4963 | if($ out) | |
| 4964 | { | |
| 4965 | foreac h($out as $pName => $pType) | |
| 4966 | { | |
| 4967 | if(strpo s($pType,' :')) { | |
| 4968 | $pType = $ this->getN amespaceFr omPrefix($ this->getP refix($pTy pe)).":".$ this->getL ocalPart($ pType); | |
| 4969 | } | |
| 4970 | $this->m essages[$n ame.'Respo nse'][$pNa me] = $pTy pe; | |
| 4971 | } | |
| 4972 | } el se { | |
| 4973 | $this->m essages[$n ame.'Respo nse']= '0' ; | |
| 4974 | } | |
| 4975 | retu rn true; | |
| 4976 | } | |
| 4977 | } | |
| 4978 | ||
| 4979 | ||
| 4980 | /** | |
| 4981 | * | |
| 4982 | * nusoap_p arser clas s parses S OAP XML me ssages int o native P HP values | |
| 4983 | * | |
| 4984 | * @author Dietrich Ayala <di etrich@gan x4.com> | |
| 4985 | * @author Scott Ni chol <snic hol@users. sourceforg e.net> | |
| 4986 | * @version $Id: nus oap.php,v 1.123 2010 /04/26 20: 15:08 snic hol Exp $ | |
| 4987 | * @access public | |
| 4988 | * @package third-par ty | |
| 4989 | * @subpack age nusoap | |
| 4990 | */ | |
| 4991 | class nuso ap_parser extends nu soap_base { | |
| 4992 | ||
| 4993 | va r $xml = ' '; | |
| 4994 | va r $xml_enc oding = '' ; | |
| 4995 | va r $method = ''; | |
| 4996 | va r $root_st ruct = ''; | |
| 4997 | va r $root_st ruct_name = ''; | |
| 4998 | va r $root_st ruct_names pace = ''; | |
| 4999 | va r $root_he ader = ''; | |
| 5000 | var $d ocument = ''; // incomin g SOAP bod y (text) | |
| 5001 | // determine s where in the messa ge we are (envelope, header,bod y,method) | |
| 5002 | va r $status = ''; | |
| 5003 | va r $positio n = 0; | |
| 5004 | va r $depth = 0; | |
| 5005 | va r $default _namespace = ''; | |
| 5006 | va r $namespa ces = arra y(); | |
| 5007 | va r $message = array() ; | |
| 5008 | var $p arent = '' ; | |
| 5009 | va r $fault = false; | |
| 5010 | va r $fault_c ode = ''; | |
| 5011 | va r $fault_s tr = ''; | |
| 5012 | va r $fault_d etail = '' ; | |
| 5013 | va r $depth_a rray = arr ay(); | |
| 5014 | va r $debug_f lag = true ; | |
| 5015 | va r $soapres ponse = NU LL; // parsed SOAP Body | |
| 5016 | va r $soaphea der = NULL ; // parsed SOAP Heade r | |
| 5017 | va r $respons eHeaders = ''; // incomin g SOAP hea ders (text ) | |
| 5018 | va r $body_po sition = 0 ; | |
| 5019 | // for multi ref parsin g: | |
| 5020 | // array of id => pos | |
| 5021 | va r $ids = a rray(); | |
| 5022 | // array of id => href s => pos | |
| 5023 | va r $multire fs = array (); | |
| 5024 | // toggle fo r auto-dec oding elem ent conten t | |
| 5025 | va r $decode_ utf8 = tru e; | |
| 5026 | ||
| 5027 | /* * | |
| 5028 | * constructo r that act ually does the parsi ng | |
| 5029 | * | |
| 5030 | * @param string $xm l SOAP mes sage | |
| 5031 | * @param string $en coding cha racter enc oding sche me of mess age | |
| 5032 | * @param string $me thod metho d for whic h XML is p arsed (unu sed?) | |
| 5033 | * @param string $de code_utf8 whether to decode UT F-8 to ISO -8859-1 | |
| 5034 | * @access public | |
| 5035 | */ | |
| 5036 | fu nction nus oap_parser ($xml,$enc oding='UTF -8',$metho d='',$deco de_utf8=tr ue){ | |
| 5037 | pare nt::nusoap _base(); | |
| 5038 | $thi s->xml = $ xml; | |
| 5039 | $thi s->xml_enc oding = $e ncoding; | |
| 5040 | $thi s->method = $method; | |
| 5041 | $thi s->decode_ utf8 = $de code_utf8; | |
| 5042 | ||
| 5043 | // C heck wheth er content has been read. | |
| 5044 | if(! empty($xml )){ | |
| 5045 | // Che ck XML enc oding | |
| 5046 | $pos_x ml = strpo s($xml, '< ?xml'); | |
| 5047 | if ($p os_xml !== FALSE) { | |
| 5048 | $xml_dec l = substr ($xml, $po s_xml, str pos($xml, '?>', $pos _xml + 2) - $pos_xml + 1); | |
| 5049 | if (preg _match("/e ncoding=[\ "']([^\"'] *)[\"']/", $xml_decl , $res)) { | |
| 5050 | $xml_encod ing = $res [1]; | |
| 5051 | if (strtou pper($xml_ encoding) != $encodi ng) { | |
| 5052 | $e rr = "Char set from H TTP Conten t-Type '" . $encodin g . "' doe s not matc h encoding from XML declaratio n '" . $xm l_encoding . "'"; | |
| 5053 | $t his->debug ($err); | |
| 5054 | if ($encodin g != 'ISO- 8859-1' || strtouppe r($xml_enc oding) != 'UTF-8') { | |
| 5055 | $thi s->setErro r($err); | |
| 5056 | retu rn; | |
| 5057 | } | |
| 5058 | // when HTTP says ISO- 8859-1 (th e default) and XML s ays UTF-8 (the typic al), assum e the othe r endpoint is just s loppy and proceed | |
| 5059 | } else { | |
| 5060 | $t his->debug ('Charset from HTTP Content-Ty pe matches encoding from XML d eclaration '); | |
| 5061 | } | |
| 5062 | } else { | |
| 5063 | $this->deb ug('No enc oding spec ified in X ML declara tion'); | |
| 5064 | } | |
| 5065 | } else { | |
| 5066 | $this->d ebug('No X ML declara tion'); | |
| 5067 | } | |
| 5068 | $this- >debug('En tering nus oap_parser (), length ='.strlen( $xml).', e ncoding='. $encoding) ; | |
| 5069 | // Cre ate an XML parser - why not xm l_parser_c reate_ns? | |
| 5070 | $this- >parser = xml_parser _create($t his->xml_e ncoding); | |
| 5071 | // Set the optio ns for par sing the X ML data. | |
| 5072 | //xml_ parser_set _option($p arser, XML _OPTION_SK IP_WHITE, 1); | |
| 5073 | xml_pa rser_set_o ption($thi s->parser, XML_OPTIO N_CASE_FOL DING, 0); | |
| 5074 | xml_pa rser_set_o ption($thi s->parser, XML_OPTIO N_TARGET_E NCODING, $ this->xml_ encoding); | |
| 5075 | // Set the objec t for the parser. | |
| 5076 | xml_se t_object($ this->pars er, $this) ; | |
| 5077 | // Set the eleme nt handler s for the parser. | |
| 5078 | xml_se t_element_ handler($t his->parse r, 'start_ element',' end_elemen t'); | |
| 5079 | xml_se t_characte r_data_han dler($this ->parser,' character_ data'); | |
| 5080 | ||
| 5081 | // Par se the XML file. | |
| 5082 | if(!xm l_parse($t his->parse r,$xml,tru e)){ | |
| 5083 | // Display a n error me ssage. | |
| 5084 | $e rr = sprin tf('XML er ror parsin g SOAP pay load on li ne %d: %s' , | |
| 5085 | xm l_get_curr ent_line_n umber($thi s->parser) , | |
| 5086 | xm l_error_st ring(xml_g et_error_c ode($this- >parser))) ; | |
| 5087 | $this->d ebug($err) ; | |
| 5088 | $this->d ebug("XML payload:\n " . $xml); | |
| 5089 | $this->s etError($e rr); | |
| 5090 | } else { | |
| 5091 | $this->d ebug('in n usoap_pars er ctor, m essage:'); | |
| 5092 | $this->a ppendDebug ($this->va rDump($thi s->message )); | |
| 5093 | $this->d ebug('pars ed success fully, fou nd root st ruct: '.$t his->root_ struct.' o f name '.$ this->root _struct_na me); | |
| 5094 | // get f inal value | |
| 5095 | $this->s oaprespons e = $this- >message[$ this->root _struct][' result']; | |
| 5096 | // get h eader valu e | |
| 5097 | if($this ->root_hea der != '' && isset($ this->mess age[$this- >root_head er]['resul t'])){ | |
| 5098 | $this->soa pheader = $this->mes sage[$this ->root_hea der]['resu lt']; | |
| 5099 | } | |
| 5100 | // resol ve hrefs/i ds | |
| 5101 | if(sizeo f($this->m ultirefs) > 0){ | |
| 5102 | foreach($t his->multi refs as $i d => $href s){ | |
| 5103 | $t his->debug ('resolvin g multiref s for id: '.$id); | |
| 5104 | // Changed to make sure that ther e's an ent ry for $id before ca lling on i t - VLER ATB VAD-16 52 | |
| 5105 | if (!empty($t his->ids[$ id])) { | |
| 5106 | $idV al = $this ->buildVal ($this->id s[$id]); | |
| 5107 | if ( is_array($ idVal) && isset($idV al['!id']) ) { | |
| 5108 | unset( $idVal['!i d']); | |
| 5109 | } | |
| 5110 | fore ach($hrefs as $refPo s => $ref) { | |
| 5111 | $this- >debug('re solving hr ef at pos '.$refPos) ; | |
| 5112 | $this- >multirefs [$id][$ref Pos] = $id Val; | |
| 5113 | } | |
| 5114 | } | |
| 5115 | } | |
| 5116 | } | |
| 5117 | } | |
| 5118 | xml_pa rser_free( $this->par ser); | |
| 5119 | } el se { | |
| 5120 | $this- >debug('xm l was empt y, didn\'t parse!'); | |
| 5121 | $this- >setError( 'xml was e mpty, didn \'t parse! '); | |
| 5122 | } | |
| 5123 | } | |
| 5124 | ||
| 5125 | /* * | |
| 5126 | * start-elem ent handle r | |
| 5127 | * | |
| 5128 | * @param resource $ parser XML parser ob ject | |
| 5129 | * @param string $na me element name | |
| 5130 | * @param array $att rs associa tive array of attrib utes | |
| 5131 | * @access private | |
| 5132 | */ | |
| 5133 | fu nction sta rt_element ($parser, $name, $at trs) { | |
| 5134 | // p osition in a total n umber of e lements, s tarting fr om 0 | |
| 5135 | // u pdate clas s level po s | |
| 5136 | $pos = $this-> position++ ; | |
| 5137 | // a nd set min e | |
| 5138 | $thi s->message [$pos] = a rray('pos' => $pos,' children'= >'','cdata '=>''); | |
| 5139 | // d epth = how many leve ls removed from root ? | |
| 5140 | // s et mine as current g lobal dept h and incr ement glob al depth v alue | |
| 5141 | $thi s->message [$pos]['de pth'] = $t his->depth ++; | |
| 5142 | ||
| 5143 | // e lse add se lf as chil d to whoev er the cur rent paren t is | |
| 5144 | if($ pos != 0){ | |
| 5145 | $this- >message[$ this->pare nt]['child ren'] .= ' |'.$pos; | |
| 5146 | } | |
| 5147 | // s et my pare nt | |
| 5148 | $thi s->message [$pos]['pa rent'] = $ this->pare nt; | |
| 5149 | // s et self as current p arent | |
| 5150 | $thi s->parent = $pos; | |
| 5151 | // s et self as current v alue for t his depth | |
| 5152 | $thi s->depth_a rray[$this ->depth] = $pos; | |
| 5153 | // g et element prefix | |
| 5154 | if(s trpos($nam e,':')){ | |
| 5155 | // get ns prefix | |
| 5156 | $prefi x = substr ($name,0,s trpos($nam e,':')); | |
| 5157 | // get unqualifi ed name | |
| 5158 | $name = substr(s trstr($nam e,':'),1); | |
| 5159 | } | |
| 5160 | // s et status | |
| 5161 | if ( $name == ' Envelope' && $this-> status == '') { | |
| 5162 | $this- >status = 'envelope' ; | |
| 5163 | } el seif ($nam e == 'Head er' && $th is->status == 'envel ope') { | |
| 5164 | $this- >root_head er = $pos; | |
| 5165 | $this- >status = 'header'; | |
| 5166 | } el seif ($nam e == 'Body ' && $this ->status = = 'envelop e'){ | |
| 5167 | $this- >status = 'body'; | |
| 5168 | $this- >body_posi tion = $po s; | |
| 5169 | // s et method | |
| 5170 | } el seif($this ->status = = 'body' & & $pos == ($this->bo dy_positio n+1)) { | |
| 5171 | $this- >status = 'method'; | |
| 5172 | $this- >root_stru ct_name = $name; | |
| 5173 | $this- >root_stru ct = $pos; | |
| 5174 | $this- >message[$ pos]['type '] = 'stru ct'; | |
| 5175 | $this- >debug("fo und root s truct $thi s->root_st ruct_name, pos $this ->root_str uct"); | |
| 5176 | } | |
| 5177 | // s et my stat us | |
| 5178 | $thi s->message [$pos]['st atus'] = $ this->stat us; | |
| 5179 | // s et name | |
| 5180 | $thi s->message [$pos]['na me'] = htm lspecialch ars($name) ; | |
| 5181 | // s et attrs | |
| 5182 | $thi s->message [$pos]['at trs'] = $a ttrs; | |
| 5183 | ||
| 5184 | // l oop throug h atts, lo gging ns a nd type de clarations | |
| 5185 | $a ttstr = '' ; | |
| 5186 | fore ach($attrs as $key = > $value){ | |
| 5187 | $key _prefix = $this->get Prefix($ke y); | |
| 5188 | $key_l ocalpart = $this->ge tLocalPart ($key); | |
| 5189 | // if ns declara tions, add to class level arra y of valid namespace s | |
| 5190 | if($key_ prefix == 'xmlns'){ | |
| 5191 | if(preg_ match('/^h ttp:\/\/ww w.w3.org\/ [0-9]{4}\/ XMLSchema$ /',$value) ){ | |
| 5192 | $this->XML SchemaVers ion = $val ue; | |
| 5193 | $this->nam espaces['x sd'] = $th is->XMLSch emaVersion ; | |
| 5194 | $this->nam espaces['x si'] = $th is->XMLSch emaVersion .'-instanc e'; | |
| 5195 | } | |
| 5196 | $thi s->namespa ces[$key_l ocalpart] = $value; | |
| 5197 | // set m ethod name space | |
| 5198 | if($name == $this- >root_stru ct_name){ | |
| 5199 | $this->met hodNamespa ce = $valu e; | |
| 5200 | } | |
| 5201 | // if it's a typ e declarat ion, set t ype | |
| 5202 | } elseif($ke y_localpar t == 'type '){ | |
| 5203 | if (is set($this- >message[$ pos]['type ']) && $th is->messag e[$pos]['t ype'] == ' array') { | |
| 5204 | // do no thing: alr eady proce ssed array Type | |
| 5205 | } else { | |
| 5206 | $value _prefix = $this->get Prefix($va lue); | |
| 5207 | $value _localpart = $this-> getLocalPa rt($value) ; | |
| 5208 | $this->mes sage[$pos] ['type'] = $value_lo calpart; | |
| 5209 | $this->mes sage[$pos] ['typePref ix'] = $va lue_prefix ; | |
| 5210 | if(iss et($this-> namespaces [$value_pr efix])){ | |
| 5211 | $this->m essage[$po s]['type_n amespace'] = $this-> namespaces [$value_pr efix]; | |
| 5212 | } else if(isset( $attrs['xm lns:'.$val ue_prefix] )) { | |
| 5213 | $t his->messa ge[$pos][' type_names pace'] = $ attrs['xml ns:'.$valu e_prefix]; | |
| 5214 | } | |
| 5215 | // should do somethi ng here wi th the nam espace of specified type? | |
| 5216 | } | |
| 5217 | } else if($key_lo calpart == 'arrayTyp e'){ | |
| 5218 | $this->m essage[$po s]['type'] = 'array' ; | |
| 5219 | /* do ar rayType er eg here | |
| 5220 | [1] a rrayTypeVa lue ::= atype asize | |
| 5221 | [2] a type :: = QName rank* | |
| 5222 | [3] r ank ::= '[' (' ,')* ']' | |
| 5223 | [4] a size :: = '[' l ength~ ']' | |
| 5224 | [5] l ength : := next Dimension* Digit+ | |
| 5225 | [6] n extDimensi on ::= Digit+ ',' | |
| 5226 | */ | |
| 5227 | $expr = '/([A-Za-z 0-9_]+):([ A-Za-z]+[A -Za-z0-9_] +)\[([0-9] +),?([0-9] *)\]/'; | |
| 5228 | if(preg_ match($exp r,$value,$ regs)){ | |
| 5229 | $this->mes sage[$pos] ['typePref ix'] = $re gs[1]; | |
| 5230 | $this->mes sage[$pos] ['arrayTyp ePrefix'] = $regs[1] ; | |
| 5231 | if (is set($this- >namespace s[$regs[1] ])) { | |
| 5232 | $this->m essage[$po s]['arrayT ypeNamespa ce'] = $th is->namesp aces[$regs [1]]; | |
| 5233 | } else if (isset ($attrs['x mlns:'.$re gs[1]])) { | |
| 5234 | $t his->messa ge[$pos][' arrayTypeN amespace'] = $attrs[ 'xmlns:'.$ regs[1]]; | |
| 5235 | } | |
| 5236 | $this->mes sage[$pos] ['arrayTyp e'] = $reg s[2]; | |
| 5237 | $this->mes sage[$pos] ['arraySiz e'] = $reg s[3]; | |
| 5238 | $this->mes sage[$pos] ['arrayCol s'] = $reg s[4]; | |
| 5239 | } | |
| 5240 | // spe cifies nil value (or not) | |
| 5241 | } else if ($key_l ocalpart = = 'nil'){ | |
| 5242 | $this->m essage[$po s]['nil'] = ($value == 'true' || $value == '1'); | |
| 5243 | // som e other at tribute | |
| 5244 | } else if ($key ! = 'href' & & $key != 'xmlns' && $key_loca lpart != ' encodingSt yle' && $k ey_localpa rt != 'roo t') { | |
| 5245 | $this->m essage[$po s]['xattrs ']['!' . $ key] = $va lue; | |
| 5246 | } | |
| 5247 | ||
| 5248 | if ($k ey == 'xml ns') { | |
| 5249 | $this->d efault_nam espace = $ value; | |
| 5250 | } | |
| 5251 | // log id | |
| 5252 | if($ke y == 'id') { | |
| 5253 | $this->i ds[$value] = $pos; | |
| 5254 | } | |
| 5255 | // roo t | |
| 5256 | if($ke y_localpar t == 'root ' && $valu e == 1){ | |
| 5257 | $this->s tatus = 'm ethod'; | |
| 5258 | $this->r oot_struct _name = $n ame; | |
| 5259 | $this->r oot_struct = $pos; | |
| 5260 | $this->d ebug("foun d root str uct $this- >root_stru ct_name, p os $pos"); | |
| 5261 | } | |
| 5262 | // for d oclit | |
| 5263 | $attstr .= " $key= \"$value\" "; | |
| 5264 | } | |
| 5265 | // get names pace - mus t be done after name space atts are proce ssed | |
| 5266 | if(i sset($pref ix)){ | |
| 5267 | $this- >message[$ pos]['name space'] = $this->nam espaces[$p refix]; | |
| 5268 | $this- >default_n amespace = $this->na mespaces[$ prefix]; | |
| 5269 | } el se { | |
| 5270 | $this- >message[$ pos]['name space'] = $this->def ault_names pace; | |
| 5271 | } | |
| 5272 | if ($this->st atus == 'h eader'){ | |
| 5273 | if ( $this->roo t_header ! = $pos) { | |
| 5274 | $this- >responseH eaders .= "<" . (iss et($prefix ) ? $prefi x . ':' : '') . "$na me$attstr> "; | |
| 5275 | } | |
| 5276 | } elseif($th is->root_s truct_name != ''){ | |
| 5277 | $thi s->documen t .= "<" . (isset($p refix) ? $ prefix . ' :' : '') . "$name$at tstr>"; | |
| 5278 | } | |
| 5279 | } | |
| 5280 | ||
| 5281 | /* * | |
| 5282 | * end-elemen t handler | |
| 5283 | * | |
| 5284 | * @param resource $ parser XML parser ob ject | |
| 5285 | * @param string $na me element name | |
| 5286 | * @access private | |
| 5287 | */ | |
| 5288 | fu nction end _element($ parser, $n ame) { | |
| 5289 | // p osition of current e lement is equal to t he last va lue left i n depth_ar ray for my depth | |
| 5290 | $pos = $this-> depth_arra y[$this->d epth--]; | |
| 5291 | ||
| 5292 | // get eleme nt prefix | |
| 5293 | if(s trpos($nam e,':')){ | |
| 5294 | // get ns prefix | |
| 5295 | $prefi x = substr ($name,0,s trpos($nam e,':')); | |
| 5296 | // get unqualifi ed name | |
| 5297 | $name = substr(s trstr($nam e,':'),1); | |
| 5298 | } | |
| 5299 | ||
| 5300 | // b uild to na tive type | |
| 5301 | if(i sset($this ->body_pos ition) && $pos > $th is->body_p osition){ | |
| 5302 | // dea l w/ multi refs | |
| 5303 | if(iss et($this-> message[$p os]['attrs ']['href'] )){ | |
| 5304 | // get i d | |
| 5305 | $id = su bstr($this ->message[ $pos]['att rs']['href '],1); | |
| 5306 | // add p laceholder to href a rray | |
| 5307 | $this->m ultirefs[$ id][$pos] = 'placeho lder'; | |
| 5308 | // add s et a refer ence to it as the re sult value | |
| 5309 | $this->m essage[$po s]['result '] =& $thi s->multire fs[$id][$p os]; | |
| 5310 | // build complexTy pe values | |
| 5311 | } else if($this-> message[$p os]['child ren'] != ' '){ | |
| 5312 | // if re sult has a lready bee n generate d (struct/ array) | |
| 5313 | if(!isse t($this->m essage[$po s]['result '])){ | |
| 5314 | $this->mes sage[$pos] ['result'] = $this-> buildVal($ pos); | |
| 5315 | } | |
| 5316 | // bui ld complex Type value s of attri butes and possibly s impleConte nt | |
| 5317 | } else if (isset( $this->mes sage[$pos] ['xattrs'] )) { | |
| 5318 | if (isse t($this->m essage[$po s]['nil']) && $this- >message[$ pos]['nil' ]) { | |
| 5319 | $this->mes sage[$pos] ['xattrs'] ['!'] = nu ll; | |
| 5320 | } elseif (isset($t his->messa ge[$pos][' cdata']) & & trim($th is->messag e[$pos]['c data']) != '') { | |
| 5321 | if (is set($this- >message[$ pos]['type '])) { | |
| 5322 | $t his->messa ge[$pos][' xattrs'][' !'] = $thi s->decodeS imple($thi s->message [$pos]['cd ata'], $th is->messag e[$pos]['t ype'], iss et($this-> message[$p os]['type_ namespace' ]) ? $this ->message[ $pos]['typ e_namespac e'] : ''); | |
| 5323 | } else { | |
| 5324 | $p arent = $t his->messa ge[$pos][' parent']; | |
| 5325 | if (isset($t his->messa ge[$parent ]['type']) && ($this ->message[ $parent][' type'] == 'array') & & isset($t his->messa ge[$parent ]['arrayTy pe'])) { | |
| 5326 | $thi s->message [$pos]['xa ttrs']['!' ] = $this- >decodeSim ple($this- >message[$ pos]['cdat a'], $this ->message[ $parent][' arrayType' ], isset($ this->mess age[$paren t]['arrayT ypeNamespa ce']) ? $t his->messa ge[$parent ]['arrayTy peNamespac e'] : ''); | |
| 5327 | } else { | |
| 5328 | $thi s->message [$pos]['xa ttrs']['!' ] = $this- >message[$ pos]['cdat a']; | |
| 5329 | } | |
| 5330 | } | |
| 5331 | } | |
| 5332 | $this->m essage[$po s]['result '] = $this ->message[ $pos]['xat trs']; | |
| 5333 | // set value of simpleType (or nil c omplexType ) | |
| 5334 | } else { | |
| 5335 | //$t his->debug ('adding d ata for sc alar value '.$this-> message[$p os]['name' ].' of val ue '.$this ->message[ $pos]['cda ta']); | |
| 5336 | if (isse t($this->m essage[$po s]['nil']) && $this- >message[$ pos]['nil' ]) { | |
| 5337 | $this->mes sage[$pos] ['xattrs'] ['!'] = nu ll; | |
| 5338 | } elseif (isset($t his->messa ge[$pos][' type'])) { | |
| 5339 | $this->mes sage[$pos] ['result'] = $this-> decodeSimp le($this-> message[$p os]['cdata '], $this- >message[$ pos]['type '], isset( $this->mes sage[$pos] ['type_nam espace']) ? $this->m essage[$po s]['type_n amespace'] : ''); | |
| 5340 | } else { | |
| 5341 | $parent = $this->mes sage[$pos] ['parent'] ; | |
| 5342 | if (isset( $this->mes sage[$pare nt]['type' ]) && ($th is->messag e[$parent] ['type'] = = 'array') && isset( $this->mes sage[$pare nt]['array Type'])) { | |
| 5343 | $t his->messa ge[$pos][' result'] = $this->de codeSimple ($this->me ssage[$pos ]['cdata'] , $this->m essage[$pa rent]['arr ayType'], isset($thi s->message [$parent][ 'arrayType Namespace' ]) ? $this ->message[ $parent][' arrayTypeN amespace'] : ''); | |
| 5344 | } else { | |
| 5345 | $t his->messa ge[$pos][' result'] = $this->me ssage[$pos ]['cdata'] ; | |
| 5346 | } | |
| 5347 | } | |
| 5348 | ||
| 5349 | /* add v alue to pa rent's res ult, if pa rent is st ruct/array | |
| 5350 | $parent = $this->m essage[$po s]['parent ']; | |
| 5351 | if($this ->message[ $parent][' type'] != 'map'){ | |
| 5352 | if(strtolo wer($this- >message[$ parent]['t ype']) == 'array'){ | |
| 5353 | $t his->messa ge[$parent ]['result' ][] = $thi s->message [$pos]['re sult']; | |
| 5354 | } else { | |
| 5355 | $t his->messa ge[$parent ]['result' ][$this->m essage[$po s]['name'] ] = $this- >message[$ pos]['resu lt']; | |
| 5356 | } | |
| 5357 | } | |
| 5358 | */ | |
| 5359 | } | |
| 5360 | } | |
| 5361 | ||
| 5362 | // for docli t | |
| 5363 | if ($this->st atus == 'h eader'){ | |
| 5364 | if ( $this->roo t_header ! = $pos) { | |
| 5365 | $this- >responseH eaders .= "</" . (is set($prefi x) ? $pref ix . ':' : '') . "$n ame>"; | |
| 5366 | } | |
| 5367 | } elseif($po s >= $this ->root_str uct){ | |
| 5368 | $thi s->documen t .= "</" . (isset($ prefix) ? $prefix . ':' : '') . "$name>" ; | |
| 5369 | } | |
| 5370 | // s witch stat us | |
| 5371 | if ( $pos == $t his->root_ struct){ | |
| 5372 | $this- >status = 'body'; | |
| 5373 | $this- >root_stru ct_namespa ce = $this ->message[ $pos]['nam espace']; | |
| 5374 | } el seif ($pos == $this- >root_head er) { | |
| 5375 | $this- >status = 'envelope' ; | |
| 5376 | } el seif ($nam e == 'Body ' && $this ->status = = 'body') { | |
| 5377 | $this- >status = 'envelope' ; | |
| 5378 | } el seif ($nam e == 'Head er' && $th is->status == 'heade r') { // w ill never happen | |
| 5379 | $this- >status = 'envelope' ; | |
| 5380 | } el seif ($nam e == 'Enve lope' && $ this->stat us == 'env elope') { | |
| 5381 | $this- >status = ''; | |
| 5382 | } | |
| 5383 | // s et parent back to my parent | |
| 5384 | $thi s->parent = $this->m essage[$po s]['parent ']; | |
| 5385 | } | |
| 5386 | ||
| 5387 | /* * | |
| 5388 | * element co ntent hand ler | |
| 5389 | * | |
| 5390 | * @param resource $ parser XML parser ob ject | |
| 5391 | * @param string $da ta element content | |
| 5392 | * @access private | |
| 5393 | */ | |
| 5394 | fu nction cha racter_dat a($parser, $data){ | |
| 5395 | $pos = $this-> depth_arra y[$this->d epth]; | |
| 5396 | if ( $this->xml _encoding= ='UTF-8'){ | |
| 5397 | // TOD O: add an option to disable th is for fol ks who wan t | |
| 5398 | // raw UTF-8 tha t, e.g., m ight not m ap to iso- 8859-1 | |
| 5399 | // TOD O: this ca n also be handled wi th xml_par ser_set_op tion($this ->parser, XML_OPTION _TARGET_EN CODING, "I SO-8859-1" ); | |
| 5400 | if($th is->decode _utf8){ | |
| 5401 | $data = utf8_decod e($data); | |
| 5402 | } | |
| 5403 | } | |
| 5404 | $t his->messa ge[$pos][' cdata'] .= $data; | |
| 5405 | // for docli t | |
| 5406 | if ($this->st atus == 'h eader'){ | |
| 5407 | $thi s->respons eHeaders . = $data; | |
| 5408 | } else { | |
| 5409 | $thi s->documen t .= $data ; | |
| 5410 | } | |
| 5411 | } | |
| 5412 | ||
| 5413 | /* * | |
| 5414 | * get the pa rsed SOAP Body (NULL if there was none) | |
| 5415 | * | |
| 5416 | * @return mixed | |
| 5417 | * @access public | |
| 5418 | */ | |
| 5419 | fu nction get _soapbody( ){ | |
| 5420 | retu rn $this-> soaprespon se; | |
| 5421 | } | |
| 5422 | ||
| 5423 | /* * | |
| 5424 | * get the pa rsed SOAP Header (NU LL if ther e was none ) | |
| 5425 | * | |
| 5426 | * @return mixed | |
| 5427 | * @access public | |
| 5428 | */ | |
| 5429 | fu nction get _soapheade r(){ | |
| 5430 | retu rn $this-> soapheader ; | |
| 5431 | } | |
| 5432 | ||
| 5433 | /* * | |
| 5434 | * get the un parsed SOA P Header | |
| 5435 | * | |
| 5436 | * @return string XML or em pty if no Header | |
| 5437 | * @access public | |
| 5438 | */ | |
| 5439 | fu nction get Headers(){ | |
| 5440 | return $ this->resp onseHeader s; | |
| 5441 | } | |
| 5442 | ||
| 5443 | /* * | |
| 5444 | * decodes si mple types into PHP variables | |
| 5445 | * | |
| 5446 | * @param string $va lue value to decode | |
| 5447 | * @param string $ty pe XML typ e to decod e | |
| 5448 | * @param string $ty pens XML t ype namesp ace to dec ode | |
| 5449 | * @return mixed PHP value | |
| 5450 | * @access private | |
| 5451 | */ | |
| 5452 | fu nction dec odeSimple( $value, $t ype, $type ns) { | |
| 5453 | // T ODO: use t he namespa ce! | |
| 5454 | if ( (!isset($t ype)) || $ type == 's tring' || $type == ' long' || $ type == 'u nsignedLon g') { | |
| 5455 | return (string) $value; | |
| 5456 | } | |
| 5457 | if ( $type == ' int' || $t ype == 'in teger' || $type == ' short' || $type == ' byte') { | |
| 5458 | return (int) $va lue; | |
| 5459 | } | |
| 5460 | if ( $type == ' float' || $type == ' double' || $type == 'decimal') { | |
| 5461 | return (double) $value; | |
| 5462 | } | |
| 5463 | if ( $type == ' boolean') { | |
| 5464 | if (st rtolower($ value) == 'false' || strtolowe r($value) == 'f') { | |
| 5465 | return f alse; | |
| 5466 | } | |
| 5467 | return (boolean) $value; | |
| 5468 | } | |
| 5469 | if ( $type == ' base64' || $type == 'base64Bin ary') { | |
| 5470 | $this- >debug('De code base6 4 value'); | |
| 5471 | return base64_de code($valu e); | |
| 5472 | } | |
| 5473 | // o bscure num eric types | |
| 5474 | if ( $type == ' nonPositiv eInteger' || $type = = 'negativ eInteger' | |
| 5475 | || $ty pe == 'non NegativeIn teger' || $type == ' positiveIn teger' | |
| 5476 | || $ty pe == 'uns ignedInt' | |
| 5477 | || $ty pe == 'uns ignedShort ' || $type == 'unsig nedByte') { | |
| 5478 | return (int) $va lue; | |
| 5479 | } | |
| 5480 | // b ogus: pars er treats array with no elemen ts as a si mple type | |
| 5481 | if ( $type == ' array') { | |
| 5482 | return array(); | |
| 5483 | } | |
| 5484 | // e verything else | |
| 5485 | retu rn (string ) $value; | |
| 5486 | } | |
| 5487 | ||
| 5488 | /* * | |
| 5489 | * builds res ponse stru ctures for compound values (ar rays/struc ts) | |
| 5490 | * and scalar s | |
| 5491 | * | |
| 5492 | * @param integer $p os positio n in node tree | |
| 5493 | * @return mixed PHP valu e | |
| 5494 | * @access private | |
| 5495 | */ | |
| 5496 | fu nction bui ldVal($pos ){ | |
| 5497 | if(! isset($thi s->message [$pos]['ty pe'])){ | |
| 5498 | $this- >message[$ pos]['type '] = ''; | |
| 5499 | } | |
| 5500 | $thi s->debug(' in buildVa l() for '. ((!empty( $this->mes sage[$pos] ['name'])) ? $this-> message[$p os]['name' ] : 'empty value') . "(pos $pos ) of type ". ((!empt y($this->m essage[$po s]['type'] )) ? $this ->message[ $pos]['typ e'] : 'emp ty value') ); | |
| 5501 | // i f there ar e children ... | |
| 5502 | //Ch anged to u se empty() instead o f checking against ' ' -- VLER ATB VAD-16 52 | |
| 5503 | if(! empty($thi s->message [$pos]['ch ildren'])) { | |
| 5504 | $this- >debug('in buildVal, there are children' ); | |
| 5505 | $child ren = expl ode('|',$t his->messa ge[$pos][' children'] ); | |
| 5506 | array_ shift($chi ldren); // knock off empty | |
| 5507 | // md array | |
| 5508 | if(iss et($this-> message[$p os]['array Cols']) && $this->me ssage[$pos ]['arrayCo ls'] != '' ){ | |
| 5509 | $r=0 ; // rowco unt | |
| 5510 | $c=0 ; // colco unt | |
| 5511 | fore ach($child ren as $ch ild_pos){ | |
| 5512 | $this->deb ug("in bui ldVal, got an MD arr ay element : $r, $c") ; | |
| 5513 | $params[$r ][] = $thi s->message [$child_po s]['result ']; | |
| 5514 | $c++ ; | |
| 5515 | if($ c == $this ->message[ $pos]['arr ayCols']){ | |
| 5516 | $c = 0; | |
| 5517 | $r ++; | |
| 5518 | } | |
| 5519 | } | |
| 5520 | // array | |
| 5521 | } else if($this-> message[$p os]['type' ] == 'arra y' || $thi s->message [$pos]['ty pe'] == 'A rray'){ | |
| 5522 | $thi s->debug(' in buildVa l, adding array '.$t his->messa ge[$pos][' name']); | |
| 5523 | fore ach($child ren as $ch ild_pos){ | |
| 5524 | $param s[] = &$th is->messag e[$child_p os]['resul t']; | |
| 5525 | } | |
| 5526 | // apach e Map type : java has htable | |
| 5527 | } elseif ($this->me ssage[$pos ]['type'] == 'Map' & & $this->m essage[$po s]['type_n amespace'] == 'http: //xml.apac he.org/xml -soap'){ | |
| 5528 | $thi s->debug(' in buildVa l, Java Ma p '.$this- >message[$ pos]['name ']); | |
| 5529 | fore ach($child ren as $ch ild_pos){ | |
| 5530 | $kv = explode("| ",$this->m essage[$ch ild_pos][' children'] ); | |
| 5531 | $param s[$this->m essage[$kv [1]]['resu lt']] = &$ this->mess age[$kv[2] ]['result' ]; | |
| 5532 | } | |
| 5533 | // gener ic compoun d type | |
| 5534 | //} else if($this-> message[$p os]['type' ] == 'SOAP Struct' || $this->me ssage[$pos ]['type'] == 'struct ') { | |
| 5535 | } else { | |
| 5536 | // Apa che Vector type: tre at as an a rray | |
| 5537 | $thi s->debug(' in buildVa l, adding Java Vecto r or gener ic compoun d type '.$ this->mess age[$pos][ 'name']); | |
| 5538 | if ($thi s->message [$pos]['ty pe'] == 'V ector' && $this->mes sage[$pos] ['type_nam espace'] = = 'http:// xml.apache .org/xml-s oap') { | |
| 5539 | $notstruct = 1; | |
| 5540 | } else { | |
| 5541 | $notstruct = 0; | |
| 5542 | } | |
| 5543 | // | |
| 5544 | fore ach($child ren as $ch ild_pos){ | |
| 5545 | if($no tstruct){ | |
| 5546 | $params[ ] = &$this ->message[ $child_pos ]['result' ]; | |
| 5547 | } else { | |
| 5548 | if (isse t($params[ $this->mes sage[$chil d_pos]['na me']])) { | |
| 5549 | // de-seri alize repe ated eleme nt name in to an arra y | |
| 5550 | if ((!is_a rray($para ms[$this-> message[$c hild_pos][ 'name']])) || (!isse t($params[ $this->mes sage[$chil d_pos]['na me']][0])) ) { | |
| 5551 | $p arams[$thi s->message [$child_po s]['name'] ] = array( $params[$t his->messa ge[$child_ pos]['name ']]); | |
| 5552 | } | |
| 5553 | $params[$t his->messa ge[$child_ pos]['name ']][] = &$ this->mess age[$child _pos]['res ult']; | |
| 5554 | } else { | |
| 5555 | $p arams[$thi s->message [$child_po s]['name'] ] = &$this ->message[ $child_pos ]['result' ]; | |
| 5556 | } | |
| 5557 | } | |
| 5558 | } | |
| 5559 | } | |
| 5560 | if (is set($this- >message[$ pos]['xatt rs'])) { | |
| 5561 | $thi s->debug(' in buildVa l, handlin g attribut es'); | |
| 5562 | foreach ($this->me ssage[$pos ]['xattrs' ] as $n => $v) { | |
| 5563 | $params[$n ] = $v; | |
| 5564 | } | |
| 5565 | } | |
| 5566 | // han dle simple Content | |
| 5567 | if (is set($this- >message[$ pos]['cdat a']) && tr im($this-> message[$p os]['cdata ']) != '') { | |
| 5568 | $thi s->debug(' in buildVa l, handlin g simpleCo ntent'); | |
| 5569 | if ( isset($thi s->message [$pos]['ty pe'])) { | |
| 5570 | $params['! '] = $this ->decodeSi mple($this ->message[ $pos]['cda ta'], $thi s->message [$pos]['ty pe'], isse t($this->m essage[$po s]['type_n amespace'] ) ? $this- >message[$ pos]['type _namespace '] : ''); | |
| 5571 | } else { | |
| 5572 | $parent = $this->mes sage[$pos] ['parent'] ; | |
| 5573 | if (isset( $this->mes sage[$pare nt]['type' ]) && ($th is->messag e[$parent] ['type'] = = 'array') && isset( $this->mes sage[$pare nt]['array Type'])) { | |
| 5574 | $p arams['!'] = $this-> decodeSimp le($this-> message[$p os]['cdata '], $this- >message[$ parent]['a rrayType'] , isset($t his->messa ge[$parent ]['arrayTy peNamespac e']) ? $th is->messag e[$parent] ['arrayTyp eNamespace '] : ''); | |
| 5575 | } else { | |
| 5576 | $p arams['!'] = $this-> message[$p os]['cdata ']; | |
| 5577 | } | |
| 5578 | } | |
| 5579 | } | |
| 5580 | $ret = is_array( $params) ? $params : array(); | |
| 5581 | $this- >debug('in buildVal, return:') ; | |
| 5582 | $this- >appendDeb ug($this-> varDump($r et)); | |
| 5583 | return $ret; | |
| 5584 | } el se { | |
| 5585 | $thi s->debug(' in buildVa l, no chil dren, buil ding scala r'); | |
| 5586 | $cdata = isset($ this->mess age[$pos][ 'cdata']) ? $this->m essage[$po s]['cdata' ] : ''; | |
| 5587 | if ( isset($thi s->message [$pos]['ty pe'])) { | |
| 5588 | $ret = $ this->deco deSimple($ cdata, $th is->messag e[$pos]['t ype'], iss et($this-> message[$p os]['type_ namespace' ]) ? $this ->message[ $pos]['typ e_namespac e'] : ''); | |
| 5589 | $this->d ebug("in b uildVal, r eturn: $re t"); | |
| 5590 | return $ ret; | |
| 5591 | } | |
| 5592 | $paren t = $this- >message[$ pos]['pare nt']; | |
| 5593 | if (is set($this- >message[$ parent]['t ype']) && ($this->me ssage[$par ent]['type '] == 'arr ay') && is set($this- >message[$ parent]['a rrayType'] )) { | |
| 5594 | $ret = $ this->deco deSimple($ cdata, $th is->messag e[$parent] ['arrayTyp e'], isset ($this->me ssage[$par ent]['arra yTypeNames pace']) ? $this->mes sage[$pare nt]['array TypeNamesp ace'] : '' ); | |
| 5595 | $this->d ebug("in b uildVal, r eturn: $re t"); | |
| 5596 | return $ ret; | |
| 5597 | } | |
| 5598 | $ret = $this-> message[$p os]['cdata ']; | |
| 5599 | $this- >debug("in buildVal, return: $ ret"); | |
| 5600 | retu rn $ret; | |
| 5601 | } | |
| 5602 | } | |
| 5603 | } | |
| 5604 | ||
| 5605 | ||
| 5606 | /** | |
| 5607 | * | |
| 5608 | * [nu]soap client hig her level class for easy usage . | |
| 5609 | * | |
| 5610 | * usage: | |
| 5611 | * | |
| 5612 | * // insta ntiate cli ent with s erver info | |
| 5613 | * $soapcli ent = new nusoap_cli ent( strin g path [ , mixed wsdl ] ); | |
| 5614 | * | |
| 5615 | * // call method, ge t results | |
| 5616 | * echo $so apclient-> call( stri ng methodn ame [ ,arr ay paramet ers] ); | |
| 5617 | * | |
| 5618 | * // bye b ye client | |
| 5619 | * unset($s oapclient) ; | |
| 5620 | * | |
| 5621 | * @author Dietrich Ayala <di etrich@gan x4.com> | |
| 5622 | * @author Scott Ni chol <snic hol@users. sourceforg e.net> | |
| 5623 | * @version $Id: nus oap.php,v 1.123 2010 /04/26 20: 15:08 snic hol Exp $ | |
| 5624 | * @access public | |
| 5625 | * @package third-par ty | |
| 5626 | * @subpack age nusoap | |
| 5627 | */ | |
| 5628 | class nuso ap_client extends nu soap_base { | |
| 5629 | ||
| 5630 | va r $usernam e = ''; // U sername fo r HTTP aut henticatio n | |
| 5631 | va r $passwor d = ''; // P assword fo r HTTP aut henticatio n | |
| 5632 | va r $authtyp e = ''; // T ype of HTT P authenti cation | |
| 5633 | va r $certReq uest = arr ay(); // Certifica te for HTT P SSL auth entication | |
| 5634 | va r $request Headers = false; // SOAP he aders in r equest (te xt) | |
| 5635 | va r $respons eHeaders = ''; // SOAP head ers from r esponse (i ncomplete namespace resolution ) (text) | |
| 5636 | va r $respons eHeader = NULL; // SOAP Head er from re sponse (pa rsed) | |
| 5637 | va r $documen t = ''; // S OAP body r esponse po rtion (inc omplete na mespace re solution) (text) | |
| 5638 | va r $endpoin t; | |
| 5639 | va r $forceEn dpoint = ' '; // overrides WSDL endp oint | |
| 5640 | var $p roxyhost = ''; | |
| 5641 | var $p roxyport = ''; | |
| 5642 | va r $proxyus ername = ' '; | |
| 5643 | va r $proxypa ssword = ' '; | |
| 5644 | va r $portNam e = ''; // p ort name t o use in W SDL | |
| 5645 | var $x ml_encodin g = ''; // character set encod ing of inc oming (res ponse) mes sages | |
| 5646 | va r $http_en coding = f alse; | |
| 5647 | va r $timeout = 0; // H TTP connec tion timeo ut | |
| 5648 | va r $respons e_timeout = 30; // HTTP resp onse timeo ut | |
| 5649 | va r $endpoin tType = '' ; // soap|wsdl , empty fo r WSDL ini tializatio n error | |
| 5650 | va r $persist entConnect ion = fals e; | |
| 5651 | va r $default RpcParams = false; // This is no longer used | |
| 5652 | va r $request = ''; // H TTP reques t | |
| 5653 | va r $respons e = ''; // H TTP respon se | |
| 5654 | va r $respons eData = '' ; // SOAP payl oad of res ponse | |
| 5655 | va r $cookies = array() ; // Cookies f rom respon se or for request | |
| 5656 | var $d ecode_utf8 = true; // toggles whether t he parser decodes el ement cont ent w/ utf 8_decode() | |
| 5657 | va r $operati ons = arra y(); // WSDL oper ations, em pty for WS DL initial ization er ror | |
| 5658 | va r $curl_op tions = ar ray(); // User-sp ecified cU RL options | |
| 5659 | va r $binding Type = ''; // WSDL oper ation bind ing type | |
| 5660 | va r $use_cur l = false; // whether t o always t ry to use cURL | |
| 5661 | ||
| 5662 | /* | |
| 5663 | * fault rel ated varia bles | |
| 5664 | * / | |
| 5665 | /* * | |
| 5666 | * @var fault | |
| 5667 | * @access public | |
| 5668 | * / | |
| 5669 | va r $fault; | |
| 5670 | /* * | |
| 5671 | * @var faultcode | |
| 5672 | * @access public | |
| 5673 | * / | |
| 5674 | va r $faultco de; | |
| 5675 | /* * | |
| 5676 | * @var faultstri ng | |
| 5677 | * @access public | |
| 5678 | * / | |
| 5679 | va r $faultst ring; | |
| 5680 | /* * | |
| 5681 | * @var faultdeta il | |
| 5682 | * @access public | |
| 5683 | * / | |
| 5684 | va r $faultde tail; | |
| 5685 | ||
| 5686 | /* * | |
| 5687 | * constructo r | |
| 5688 | * | |
| 5689 | * @param mixed $end point SOAP server or WSDL URL (string), or wsdl in stance (ob ject) | |
| 5690 | * @param mixed $wsd l optional , set to ' wsdl' or t rue if usi ng WSDL | |
| 5691 | * @param string $pr oxyhost op tional | |
| 5692 | * @param string $pr oxyport op tional | |
| 5693 | * @param string $proxyuse rname opti onal | |
| 5694 | * @param string $proxypas sword opti onal | |
| 5695 | * @param intege r $timeout set the c onnection timeout | |
| 5696 | * @param intege r $respons e_timeout set the re sponse tim eout | |
| 5697 | * @param string $portName optional portName i n WSDL doc ument | |
| 5698 | * @access public | |
| 5699 | */ | |
| 5700 | fu nction nus oap_client ($endpoint ,$wsdl = f alse,$prox yhost = fa lse,$proxy port = fal se,$proxyu sername = false, $pr oxypasswor d = false, $timeout = 0, $resp onse_timeo ut = 30, $ portName = ''){ | |
| 5701 | pare nt::nusoap _base(); | |
| 5702 | $thi s->endpoin t = $endpo int; | |
| 5703 | $thi s->proxyho st = $prox yhost; | |
| 5704 | $thi s->proxypo rt = $prox yport; | |
| 5705 | $thi s->proxyus ername = $ proxyusern ame; | |
| 5706 | $thi s->proxypa ssword = $ proxypassw ord; | |
| 5707 | $thi s->timeout = $timeou t; | |
| 5708 | $thi s->respons e_timeout = $respons e_timeout; | |
| 5709 | $thi s->portNam e = $portN ame; | |
| 5710 | ||
| 5711 | $thi s->debug(" ctor wsdl= $wsdl time out=$timeo ut respons e_timeout= $response_ timeout"); | |
| 5712 | $thi s->appendD ebug('endp oint=' . $ this->varD ump($endpo int)); | |
| 5713 | ||
| 5714 | // m ake values | |
| 5715 | if($ wsdl){ | |
| 5716 | if (is _object($e ndpoint) & & (get_cla ss($endpoi nt) == 'ws dl')) { | |
| 5717 | $this->w sdl = $end point; | |
| 5718 | $this->e ndpoint = $this->wsd l->wsdl; | |
| 5719 | $this->w sdlFile = $this->end point; | |
| 5720 | $this->d ebug('exis ting wsdl instance c reated fro m ' . $thi s->endpoin t); | |
| 5721 | $this->c heckWSDL() ; | |
| 5722 | } else { | |
| 5723 | $this->w sdlFile = $this->end point; | |
| 5724 | $this->w sdl = null ; | |
| 5725 | $this->d ebug('will use lazy evaluation of wsdl f rom ' . $t his->endpo int); | |
| 5726 | } | |
| 5727 | $this- >endpointT ype = 'wsd l'; | |
| 5728 | } el se { | |
| 5729 | $this- >debug("in stantiate SOAP with endpoint a t $endpoin t"); | |
| 5730 | $this- >endpointT ype = 'soa p'; | |
| 5731 | } | |
| 5732 | } | |
| 5733 | ||
| 5734 | /* * | |
| 5735 | * calls meth od, return s PHP nati ve type | |
| 5736 | * | |
| 5737 | * @param string $op eration SO AP server URL or pat h | |
| 5738 | * @param mixed $par ams An arr ay, associ ative or s imple, of the parame ters | |
| 5739 | * for the method call, or a string t hat is the XML | |
| 5740 | * for the call. For rpc s tyle, this call will | |
| 5741 | * wrap the XML i n a tag na med after the method , as | |
| 5742 | * well as the SO AP Envelop e and Body . For doc ument | |
| 5743 | * styl e, this wi ll only wr ap with th e Envelope and Body. | |
| 5744 | * IMPO RTANT: whe n using an array wit h document style, | |
| 5745 | * in w hich case there | |
| 5746 | * is rea lly one pa rameter, t he root of the fragm ent | |
| 5747 | * used i n the call , which en closes wha t programm ers | |
| 5748 | * normal ly think o f paramete rs. A par ameter arr ay | |
| 5749 | * *must* include t he wrapper . | |
| 5750 | * @param string $namespac e optional method na mespace (W SDL can ov erride) | |
| 5751 | * @param string $soapActi on optiona l SOAPActi on value ( WSDL can o verride) | |
| 5752 | * @param mixed $headers o ptional st ring of XM L with SOA P header c ontent, or array of soapval ob jects for SOAP heade rs, or ass ociative a rray | |
| 5753 | * @param boolea n $rpcPara ms optiona l (no long er used) | |
| 5754 | * @param string $style o ptional (r pc|documen t) the sty le to use when seria lizing par ameters (W SDL can ov erride) | |
| 5755 | * @param string $use opt ional (enc oded|liter al) the us e when ser ializing p arameters (WSDL can override) | |
| 5756 | * @return mixed response from SOAP call, nor mally an a ssociative array mir roring the structure of the XM L response , false fo r certain fatal erro rs | |
| 5757 | * @access public | |
| 5758 | */ | |
| 5759 | fu nction cal l($operati on,$params =array(),$ namespace= 'http://te mpuri.org' ,$soapActi on='',$hea ders=false ,$rpcParam s=null,$st yle='rpc', $use='enco ded'){ | |
| 5760 | $thi s->operati on = $oper ation; | |
| 5761 | $thi s->fault = false; | |
| 5762 | $thi s->setErro r(''); | |
| 5763 | $thi s->request = ''; | |
| 5764 | $thi s->respons e = ''; | |
| 5765 | $thi s->respons eData = '' ; | |
| 5766 | $thi s->faultst ring = ''; | |
| 5767 | $thi s->faultco de = ''; | |
| 5768 | $thi s->opData = array(); | |
| 5769 | ||
| 5770 | $thi s->debug(" call: oper ation=$ope ration, na mespace=$n amespace, soapAction =$soapActi on, rpcPar ams=$rpcPa rams, styl e=$style, use=$use, endpointTy pe=$this-> endpointTy pe"); | |
| 5771 | $thi s->appendD ebug('para ms=' . $th is->varDum p($params) ); | |
| 5772 | $thi s->appendD ebug('head ers=' . $t his->varDu mp($header s)); | |
| 5773 | if ( $headers) { | |
| 5774 | $this- >requestHe aders = $h eaders; | |
| 5775 | } | |
| 5776 | if ( $this->end pointType == 'wsdl' && is_null ($this->ws dl)) { | |
| 5777 | $this- >loadWSDL( ); | |
| 5778 | if ($t his->getEr ror()) | |
| 5779 | return f alse; | |
| 5780 | } | |
| 5781 | // s erialize p arameters | |
| 5782 | if($ this->endp ointType = = 'wsdl' & & $opData = $this->g etOperatio nData($ope ration)){ | |
| 5783 | // use WSDL for operation | |
| 5784 | $this- >opData = $opData; | |
| 5785 | $this- >debug("fo und operat ion"); | |
| 5786 | $this- >appendDeb ug('opData =' . $this ->varDump( $opData)); | |
| 5787 | if (is set($opDat a['soapAct ion'])) { | |
| 5788 | $soapAct ion = $opD ata['soapA ction']; | |
| 5789 | } | |
| 5790 | if (! $this->for ceEndpoint ) { | |
| 5791 | $this->e ndpoint = $opData['e ndpoint']; | |
| 5792 | } else { | |
| 5793 | $this->e ndpoint = $this->for ceEndpoint ; | |
| 5794 | } | |
| 5795 | $names pace = iss et($opData ['input'][ 'namespace ']) ? $opD ata['input ']['namesp ace'] : $namespa ce; | |
| 5796 | $style = $opData ['style']; | |
| 5797 | $use = $opData[' input']['u se']; | |
| 5798 | // add ns to ns array | |
| 5799 | if($na mespace != '' && !is set($this- >wsdl->nam espaces[$n amespace]) ){ | |
| 5800 | //change d to use c rypto_rand from rand for secur ity scans - VLER EJ VAD-1523 | |
| 5801 | $nsPrefi x = 'ns' . crypto_ra nd(1000, 9 999,false) ; | |
| 5802 | $this->w sdl->names paces[$nsP refix] = $ namespace; | |
| 5803 | } | |
| 5804 | $nsPrefi x = $this- >wsdl->get PrefixFrom Namespace( $namespace ); | |
| 5805 | // ser ialize pay load | |
| 5806 | if (is _string($p arams)) { | |
| 5807 | $this->d ebug("seri alizing pa ram string for WSDL operation $operation "); | |
| 5808 | $payload = $params ; | |
| 5809 | } else if (is_arr ay($params )) { | |
| 5810 | $this->d ebug("seri alizing pa ram array for WSDL o peration $ operation" ); | |
| 5811 | $payload = $this-> wsdl->seri alizeRPCPa rameters($ operation, 'input',$p arams,$thi s->binding Type); | |
| 5812 | } else { | |
| 5813 | $this->d ebug('para ms must be array or string'); | |
| 5814 | $this->s etError('p arams must be array or string' ); | |
| 5815 | return f alse; | |
| 5816 | } | |
| 5817 | $usedNam espaces = $this->wsd l->usedNam espaces; | |
| 5818 | if (is set($opDat a['input'] ['encoding Style'])) { | |
| 5819 | $encodin gStyle = $ opData['in put']['enc odingStyle ']; | |
| 5820 | } else { | |
| 5821 | $encodin gStyle = ' '; | |
| 5822 | } | |
| 5823 | $this- >appendDeb ug($this-> wsdl->getD ebug()); | |
| 5824 | $this- >wsdl->cle arDebug(); | |
| 5825 | if ($e rrstr = $t his->wsdl- >getError( )) { | |
| 5826 | $this->d ebug('got wsdl error : '.$errst r); | |
| 5827 | $this->s etError('w sdl error: '.$errstr ); | |
| 5828 | return f alse; | |
| 5829 | } | |
| 5830 | } el seif($this ->endpoint Type == 'w sdl') { | |
| 5831 | // ope ration not in WSDL | |
| 5832 | $this- >appendDeb ug($this-> wsdl->getD ebug()); | |
| 5833 | $this- >wsdl->cle arDebug(); | |
| 5834 | $this- >setError( 'operation '.$operat ion.' not present in WSDL.'); | |
| 5835 | $this- >debug("op eration '$ operation' not prese nt in WSDL ."); | |
| 5836 | return false; | |
| 5837 | } el se { | |
| 5838 | // no WSDL | |
| 5839 | //$thi s->namespa ces['ns1'] = $namesp ace; | |
| 5840 | //chan ged to use crypto_ra nd from ra nd for sec urity scan s - VLER EJ VAD-152 3 | |
| 5841 | $nsPre fix = 'ns' . crypto_ rand(1000, 9999,fals e); | |
| 5842 | // ser ialize | |
| 5843 | $paylo ad = ''; | |
| 5844 | if (is _string($p arams)) { | |
| 5845 | $this->d ebug("seri alizing pa ram string for opera tion $oper ation"); | |
| 5846 | $payload = $params ; | |
| 5847 | } else if (is_arr ay($params )) { | |
| 5848 | $this->d ebug("seri alizing pa ram array for operat ion $opera tion"); | |
| 5849 | foreach( $params as $k => $v) { | |
| 5850 | $payload . = $this->s erialize_v al($v,$k,f alse,false ,false,fal se,$use); | |
| 5851 | } | |
| 5852 | } else { | |
| 5853 | $this->d ebug('para ms must be array or string'); | |
| 5854 | $this->s etError('p arams must be array or string' ); | |
| 5855 | return f alse; | |
| 5856 | } | |
| 5857 | $usedN amespaces = array(); | |
| 5858 | if ($u se == 'enc oded') { | |
| 5859 | $encodin gStyle = ' http://sch emas.xmlso ap.org/soa p/encoding /'; | |
| 5860 | } else { | |
| 5861 | $encodin gStyle = ' '; | |
| 5862 | } | |
| 5863 | } | |
| 5864 | // w rap RPC ca lls with m ethod elem ent | |
| 5865 | if ( $style == 'rpc') { | |
| 5866 | if ($u se == 'lit eral') { | |
| 5867 | $this->d ebug("wrap ping RPC r equest wit h literal method ele ment"); | |
| 5868 | if ($nam espace) { | |
| 5869 | // http:// www.ws-i.o rg/Profile s/BasicPro file-1.1-2 004-08-24. html R2735 says rpc/ literal ac cessor ele ments shou ld not be in a names pace | |
| 5870 | $payload = "<$nsPref ix:$operat ion xmlns: $nsPrefix= \"$namespa ce\">" . | |
| 5871 | $paylo ad . | |
| 5872 | "</$ns Prefix:$op eration>"; | |
| 5873 | } else { | |
| 5874 | $payload = "<$operat ion>" . $p ayload . " </$operati on>"; | |
| 5875 | } | |
| 5876 | } else { | |
| 5877 | $this->d ebug("wrap ping RPC r equest wit h encoded method ele ment"); | |
| 5878 | if ($nam espace) { | |
| 5879 | $payload = "<$nsPref ix:$operat ion xmlns: $nsPrefix= \"$namespa ce\">" . | |
| 5880 | $paylo ad . | |
| 5881 | "</$ns Prefix:$op eration>"; | |
| 5882 | } else { | |
| 5883 | $payload = "<$operat ion>" . | |
| 5884 | $paylo ad . | |
| 5885 | "</$op eration>"; | |
| 5886 | } | |
| 5887 | } | |
| 5888 | } | |
| 5889 | // s erialize e nvelope | |
| 5890 | $soa pmsg = $th is->serial izeEnvelop e($payload ,$this->re questHeade rs,$usedNa mespaces,$ style,$use ,$encoding Style); | |
| 5891 | $thi s->debug(" endpoint=$ this->endp oint, soap Action=$so apAction, namespace= $namespace , style=$s tyle, use= $use, enco dingStyle= $encodingS tyle"); | |
| 5892 | $thi s->debug(' SOAP messa ge length= ' . strlen ($soapmsg) . ' conte nts (max 1 000 bytes) =' . subst r($soapmsg , 0, 1000) ); | |
| 5893 | // s end | |
| 5894 | $ret urn = $thi s->send($t his->getHT TPBody($so apmsg),$so apAction,$ this->time out,$this- >response_ timeout); | |
| 5895 | if($ errstr = $ this->getE rror()){ | |
| 5896 | $this- >debug('Er ror: '.$er rstr); | |
| 5897 | return false; | |
| 5898 | } el se { | |
| 5899 | $this- >return = $return; | |
| 5900 | $this- >debug('se nt message successfu lly and go t a(n) '.g ettype($re turn)); | |
| 5901 | $thi s->appendD ebug('retu rn=' . $th is->varDum p($return) ); | |
| 5902 | ||
| 5903 | // fau lt? | |
| 5904 | if(is_ array($ret urn) && is set($retur n['faultco de'])){ | |
| 5905 | $this->d ebug('got fault'); | |
| 5906 | $this->s etError($r eturn['fau ltcode'].' : '.$retur n['faultst ring']); | |
| 5907 | $this->f ault = tru e; | |
| 5908 | foreach( $return as $k => $v) { | |
| 5909 | $this->$k = $v; | |
| 5910 | $this->deb ug("$k = $ v<br>"); | |
| 5911 | } | |
| 5912 | return $ return; | |
| 5913 | } else if ($style == 'docum ent') { | |
| 5914 | // NOTE: if the re sponse is defined to have mult iple parts (i.e. unw rapped), | |
| 5915 | // we ar e only goi ng to retu rn the fir st part he re...sorry about tha t | |
| 5916 | return $ return; | |
| 5917 | } else { | |
| 5918 | // array of return values | |
| 5919 | if(is_ar ray($retur n)){ | |
| 5920 | // multipl e 'out' pa rameters, which we r eturn wrap ped up | |
| 5921 | // in the array | |
| 5922 | if(sizeof( $return) > 1){ | |
| 5923 | re turn $retu rn; | |
| 5924 | } | |
| 5925 | // single 'out' para meter (nor mally the return val ue) | |
| 5926 | $return = array_shif t($return) ; | |
| 5927 | $this->deb ug('return shifted v alue: '); | |
| 5928 | $this->app endDebug($ this->varD ump($retur n)); | |
| 5929 | return $ return; | |
| 5930 | // nothi ng returne d (ie, ech oVoid) | |
| 5931 | } else { | |
| 5932 | return ""; | |
| 5933 | } | |
| 5934 | } | |
| 5935 | } | |
| 5936 | } | |
| 5937 | ||
| 5938 | /* * | |
| 5939 | * check WSDL passed as an instan ce or pull ed from an endpoint | |
| 5940 | * | |
| 5941 | * @access private | |
| 5942 | */ | |
| 5943 | fu nction che ckWSDL() { | |
| 5944 | $thi s->appendD ebug($this ->wsdl->ge tDebug()); | |
| 5945 | $thi s->wsdl->c learDebug( ); | |
| 5946 | $thi s->debug(' checkWSDL' ); | |
| 5947 | // c atch error s | |
| 5948 | if ( $errstr = $this->wsd l->getErro r()) { | |
| 5949 | $this- >appendDeb ug($this-> wsdl->getD ebug()); | |
| 5950 | $this- >wsdl->cle arDebug(); | |
| 5951 | $this- >debug('go t wsdl err or: '.$err str); | |
| 5952 | $this- >setError( 'wsdl erro r: '.$errs tr); | |
| 5953 | } el seif ($thi s->operati ons = $thi s->wsdl->g etOperatio ns($this-> portName, 'soap')) { | |
| 5954 | $this- >appendDeb ug($this-> wsdl->getD ebug()); | |
| 5955 | $this- >wsdl->cle arDebug(); | |
| 5956 | $this- >bindingTy pe = 'soap '; | |
| 5957 | $this- >debug('go t '.count( $this->ope rations).' operation s from wsd l '.$this- >wsdlFile. ' for bind ing type ' .$this->bi ndingType) ; | |
| 5958 | } el seif ($thi s->operati ons = $thi s->wsdl->g etOperatio ns($this-> portName, 'soap12')) { | |
| 5959 | $this- >appendDeb ug($this-> wsdl->getD ebug()); | |
| 5960 | $this- >wsdl->cle arDebug(); | |
| 5961 | $this- >bindingTy pe = 'soap 12'; | |
| 5962 | $this- >debug('go t '.count( $this->ope rations).' operation s from wsd l '.$this- >wsdlFile. ' for bind ing type ' .$this->bi ndingType) ; | |
| 5963 | $this- >debug('** ********** **** WARNI NG: SOAP 1 .2 BINDING ********* ********') ; | |
| 5964 | } el se { | |
| 5965 | $this- >appendDeb ug($this-> wsdl->getD ebug()); | |
| 5966 | $this- >wsdl->cle arDebug(); | |
| 5967 | $this- >debug('ge tOperation s returned false'); | |
| 5968 | $this- >setError( 'no operat ions defin ed in the WSDL docum ent!'); | |
| 5969 | } | |
| 5970 | } | |
| 5971 | ||
| 5972 | /* * | |
| 5973 | * instantia te wsdl ob ject and p arse wsdl file | |
| 5974 | * | |
| 5975 | * @access public | |
| 5976 | * / | |
| 5977 | fu nction loa dWSDL() { | |
| 5978 | $thi s->debug(' instantiat ing wsdl c lass with doc: '.$th is->wsdlFi le); | |
| 5979 | $thi s->wsdl = new wsdl(' ',$this->p roxyhost,$ this->prox yport,$thi s->proxyus ername,$th is->proxyp assword,$t his->timeo ut,$this-> response_t imeout,$th is->curl_o ptions,$th is->use_cu rl); | |
| 5980 | $thi s->wsdl->s etCredenti als($this- >username, $this->pa ssword, $t his->autht ype, $this ->certRequ est); | |
| 5981 | $thi s->wsdl->f etchWSDL($ this->wsdl File); | |
| 5982 | $thi s->checkWS DL(); | |
| 5983 | } | |
| 5984 | ||
| 5985 | /* * | |
| 5986 | * get availa ble data p ertaining to an oper ation | |
| 5987 | * | |
| 5988 | * @param string $op eration op eration na me | |
| 5989 | * @return array array of d ata pertai ning to th e operatio n | |
| 5990 | * @access public | |
| 5991 | */ | |
| 5992 | fu nction get OperationD ata($opera tion){ | |
| 5993 | if ( $this->end pointType == 'wsdl' && is_null ($this->ws dl)) { | |
| 5994 | $this- >loadWSDL( ); | |
| 5995 | if ($t his->getEr ror()) | |
| 5996 | return f alse; | |
| 5997 | } | |
| 5998 | if(i sset($this ->operatio ns[$operat ion])){ | |
| 5999 | return $this->op erations[$ operation] ; | |
| 6000 | } | |
| 6001 | $thi s->debug(" No data fo r operatio n: $operat ion"); | |
| 6002 | } | |
| 6003 | ||
| 6004 | /** | |
| 6005 | * send the SOAP message | |
| 6006 | * | |
| 6007 | * Note : if the o peration h as multipl e return v alues | |
| 6008 | * the return val ue of this method wi ll be an a rray | |
| 6009 | * of t hose value s. | |
| 6010 | * | |
| 6011 | * @param string $ms g a SOAPx4 soapmsg o bject | |
| 6012 | * @param string $so apaction S OAPAction value | |
| 6013 | * @param integer $t imeout set connectio n timeout in seconds | |
| 6014 | * @param intege r $respons e_timeout set respon se timeout in second s | |
| 6015 | * @return mixed native PHP types. | |
| 6016 | * @access private | |
| 6017 | */ | |
| 6018 | fu nction sen d($msg, $s oapaction = '', $tim eout=0, $r esponse_ti meout=30) { | |
| 6019 | $thi s->checkCo okies(); | |
| 6020 | //de termine en dpoint | |
| 6021 | if ( $this->for ceEndpoint ) { | |
| 6022 | $this- >endpoint = $this->f orceEndpoi nt; | |
| 6023 | } | |
| 6024 | // d etect tran sport | |
| 6025 | swit ch(true){ | |
| 6026 | // htt p(s) | |
| 6027 | case p reg_match( '/^http/', $this->end point): | |
| 6028 | $this->d ebug('tran sporting v ia HTTP'); | |
| 6029 | if($this ->persiste ntConnecti on == true && is_obj ect($this- >persisten tConnectio n)){ | |
| 6030 | $http =& $ this->pers istentConn ection; | |
| 6031 | } else { | |
| 6032 | $http = ne w soap_tra nsport_htt p($this->e ndpoint, $ this->curl _options, $this->use _curl); | |
| 6033 | if ($this- >persisten tConnectio n) { | |
| 6034 | $h ttp->usePe rsistentCo nnection() ; | |
| 6035 | } | |
| 6036 | } | |
| 6037 | $http->s etContentT ype($this- >getHTTPCo ntentType( ), $this-> getHTTPCon tentTypeCh arset()); | |
| 6038 | $http->s etSOAPActi on($soapac tion); | |
| 6039 | if($this ->proxyhos t && $this ->proxypor t){ | |
| 6040 | $http->set Proxy($thi s->proxyho st,$this-> proxyport, $this->pro xyusername ,$this->pr oxypasswor d); | |
| 6041 | } | |
| 6042 | if($ this->auth type != '' ) { | |
| 6043 | $http->set Credential s($this->u sername, $ this->pass word, $thi s->authtyp e, array() , $this->c ertRequest ); | |
| 6044 | } | |
| 6045 | if($this ->http_enc oding != ' '){ | |
| 6046 | $http->set Encoding($ this->http _encoding) ; | |
| 6047 | } | |
| 6048 | $this->d ebug('send ing messag e, length= '.strlen($ msg)); | |
| 6049 | if(preg_ match('/^h ttp:/',$th is->endpoi nt)){ | |
| 6050 | $this->res ponseData = $http->s end($msg,$ timeout,$r esponse_ti meout,$thi s->cookies ); | |
| 6051 | } elseif (preg_matc h('/^https /',$this-> endpoint)) { | |
| 6052 | $this->res ponseData = $http->s endHTTPS($ msg,$timeo ut,$respon se_timeout ,$this->co okies); | |
| 6053 | } else { | |
| 6054 | $this->set Error('no http/s in endpoint u rl'); | |
| 6055 | } | |
| 6056 | $this->r equest = $ http->outg oing_paylo ad; | |
| 6057 | $this->r esponse = $http->inc oming_payl oad; | |
| 6058 | $this->a ppendDebug ($http->ge tDebug()); | |
| 6059 | $this->U pdateCooki es($http-> incoming_c ookies); | |
| 6060 | ||
| 6061 | // save transport object if using pers istent con nections | |
| 6062 | if ($thi s->persist entConnect ion) { | |
| 6063 | $http->cle arDebug(); | |
| 6064 | if (!is_ob ject($this ->persiste ntConnecti on)) { | |
| 6065 | $t his->persi stentConne ction = $h ttp; | |
| 6066 | } | |
| 6067 | } | |
| 6068 | ||
| 6069 | if($err = $http->g etError()) { | |
| 6070 | $this->set Error('HTT P Error: ' .$err); | |
| 6071 | return fal se; | |
| 6072 | } elseif ($this->ge tError()){ | |
| 6073 | return fal se; | |
| 6074 | } else { | |
| 6075 | $this->deb ug('got re sponse, le ngth='. st rlen($this ->response Data).' ty pe='.$http ->incoming _headers[' content-ty pe']); | |
| 6076 | return $th is->parseR esponse($h ttp->incom ing_header s, $this-> responseDa ta); | |
| 6077 | } | |
| 6078 | break; | |
| 6079 | defaul t: | |
| 6080 | $this->s etError('n o transpor t found, o r selected transport is not ye t supporte d!'); | |
| 6081 | return false; | |
| 6082 | break; | |
| 6083 | } | |
| 6084 | } | |
| 6085 | ||
| 6086 | /* * | |
| 6087 | * processes SOAP messa ge returne d from ser ver | |
| 6088 | * | |
| 6089 | * @param array $headers Th e HTTP hea ders | |
| 6090 | * @param string $data un processed response d ata from s erver | |
| 6091 | * @return mixed value of the messa ge, decode d into a P HP type | |
| 6092 | * @access private | |
| 6093 | */ | |
| 6094 | functi on parseRe sponse($he aders, $da ta) { | |
| 6095 | $thi s->debug(' Entering p arseRespon se() for d ata of len gth ' . st rlen($data ) . ' head ers:'); | |
| 6096 | $thi s->appendD ebug($this ->varDump( $headers)) ; | |
| 6097 | if (!isset($ headers['c ontent-typ e'])) { | |
| 6098 | $this- >setError( 'Response not of typ e text/xml (no conte nt-type he ader)'); | |
| 6099 | return false; | |
| 6100 | } | |
| 6101 | /* Re vising thi s accordin g to Stack Overflow r ecommendat ion to all ow applica tion/soap+ xml conten t types: h ttp://stac koverflow. com/questi ons/945922 /nusoap-ho w-to-chang e-content- type-of-re quest -- V LER MG | |
| 6102 | if ( !strstr($h eaders['co ntent-type '], 'text/ xml')) { | |
| 6103 | $this- >setError( 'Request n ot of type text/xml' ); | |
| 6104 | return false; | |
| 6105 | } */ | |
| 6106 | if ( !strstr($h eaders['co ntent-type '], 'text/ xml') && ! strstr($he aders['con tent-type' ], 'applic ation/soap +xml') ) { | |
| 6107 | $this- >setError( 'Response not of typ e text/xml : ' . $hea ders['cont ent-type'] ); | |
| 6108 | return false; | |
| 6109 | } | |
| 6110 | /* End rev ision */ | |
| 6111 | if ( strpos($he aders['con tent-type' ], '=')) { | |
| 6112 | /* REVISIN G this to allow for content ty pe declara tions wher e the type =text/xml comes afte r the char set -- V LER MG*/ | |
| 6113 | # $enc = str_repla ce('"', '' , substr(s trstr($hea ders["cont ent-type"] , '='), 1) ); | |
| 6114 | ||
| 6115 | $enc = str_repla ce('"', '' , strtoupp er($header s['content -type'])); //normali ze content type by r emove quot es, capita lizing | |
| 6116 | ||
| 6117 | //redu ce the $en c down to just the e ncoding st atement (c harset=utf -8) in cas e it has a ny additio nal conten t type ite ms like ty pe=text/xm l | |
| 6118 | if(str ing_contai ns(';', $e nc)){ | |
| 6119 | $pieces = array_ma p('trim', explode('; ', $enc)); | |
| 6120 | foreach( $pieces as $piece){ | |
| 6121 | if(string_ contains(' CHARSET', $piece) || in_array( $piece, ar ray('ISO-8 859-1','US -ASCII','U TF-8'))){ | |
| 6122 | $e nc = $piec e; | |
| 6123 | br eak; | |
| 6124 | } | |
| 6125 | } | |
| 6126 | } | |
| 6127 | ||
| 6128 | //if $ enc includ es the 'ch arset=' de claration, strip thi s down to just the a ctual enco ding | |
| 6129 | if(str ing_contai ns('=', $e nc)) | |
| 6130 | $enc = s ubstr(strs tr($enc, ' ='), true) ; | |
| 6131 | ||
| 6132 | /* END REV ISION */ | |
| 6133 | $this- >debug('Go t response encoding (edited): ' . $enc); | |
| 6134 | if(pre g_match('/ ^(ISO-8859 -1|US-ASCI I|UTF-8)$/ i',$enc)){ | |
| 6135 | $this->x ml_encodin g = strtou pper($enc) ; | |
| 6136 | } else { | |
| 6137 | $this->x ml_encodin g = 'US-AS CII'; | |
| 6138 | } | |
| 6139 | } el se { | |
| 6140 | // sho uld be US- ASCII for HTTP 1.0 o r ISO-8859 -1 for HTT P 1.1 | |
| 6141 | $this- >xml_encod ing = 'ISO -8859-1'; | |
| 6142 | } | |
| 6143 | $thi s->debug(' Use encodi ng: ' . $t his->xml_e ncoding . ' when cre ating nuso ap_parser' ); | |
| 6144 | if(e mpty($this ->operatio n)) { | |
| 6145 | $this- >operation = ""; | |
| 6146 | } | |
| 6147 | $par ser = new nusoap_par ser($data, $this->xml _encoding, $this->ope ration,$th is->decode _utf8); | |
| 6148 | // a dd parser debug data to our de bug | |
| 6149 | $thi s->appendD ebug($pars er->getDeb ug()); | |
| 6150 | // i f parse er rors | |
| 6151 | if($ errstr = $ parser->ge tError()){ | |
| 6152 | $this- >setError( $errstr); | |
| 6153 | // des troy the p arser obje ct | |
| 6154 | unset( $parser); | |
| 6155 | return false; | |
| 6156 | } el se { | |
| 6157 | // get SOAP head ers | |
| 6158 | $this- >responseH eaders = $ parser->ge tHeaders() ; | |
| 6159 | // get SOAP head ers | |
| 6160 | $this- >responseH eader = $p arser->get _soapheade r(); | |
| 6161 | // get decoded m essage | |
| 6162 | $retur n = $parse r->get_soa pbody(); | |
| 6163 | // add d ocument fo r doclit s upport | |
| 6164 | $this->d ocument = $parser->d ocument; | |
| 6165 | // des troy the p arser obje ct | |
| 6166 | unset( $parser); | |
| 6167 | // ret urn decode message | |
| 6168 | return $return; | |
| 6169 | } | |
| 6170 | } | |
| 6171 | ||
| 6172 | /* * | |
| 6173 | * sets user- specified cURL optio ns | |
| 6174 | * | |
| 6175 | * @param mixed $option Th e cURL opt ion (alway s integer? ) | |
| 6176 | * @param mixed $value The cURL opti on value | |
| 6177 | * @access public | |
| 6178 | */ | |
| 6179 | fu nction set CurlOption ($option, $value) { | |
| 6180 | $thi s->debug(" setCurlOpt ion option =$option, value="); | |
| 6181 | $thi s->appendD ebug($this ->varDump( $value)); | |
| 6182 | $thi s->curl_op tions[$opt ion] = $va lue; | |
| 6183 | } | |
| 6184 | ||
| 6185 | /* * | |
| 6186 | * sets the S OAP endpoi nt, which can overri de WSDL | |
| 6187 | * | |
| 6188 | * @param string $endpoint The endpo int URL to use, or e mpty strin g or false to preven t override | |
| 6189 | * @access public | |
| 6190 | */ | |
| 6191 | fu nction set Endpoint($ endpoint) { | |
| 6192 | $thi s->debug(" setEndpoin t(\"$endpo int\")"); | |
| 6193 | $thi s->forceEn dpoint = $ endpoint; | |
| 6194 | } | |
| 6195 | ||
| 6196 | /* * | |
| 6197 | * set the SO AP headers | |
| 6198 | * | |
| 6199 | * @param mixed $headers S tring of X ML with SO AP header content, o r array of soapval o bjects for SOAP head ers | |
| 6200 | * @access public | |
| 6201 | */ | |
| 6202 | fu nction set Headers($h eaders){ | |
| 6203 | $thi s->debug(" setHeaders headers=" ); | |
| 6204 | $thi s->appendD ebug($this ->varDump( $headers)) ; | |
| 6205 | $thi s->request Headers = $headers; | |
| 6206 | } | |
| 6207 | ||
| 6208 | /* * | |
| 6209 | * get the SO AP respons e headers (namespace resolutio n incomple te) | |
| 6210 | * | |
| 6211 | * @return string | |
| 6212 | * @access public | |
| 6213 | */ | |
| 6214 | fu nction get Headers(){ | |
| 6215 | retu rn $this-> responseHe aders; | |
| 6216 | } | |
| 6217 | ||
| 6218 | /* * | |
| 6219 | * get the SO AP respons e Header ( parsed) | |
| 6220 | * | |
| 6221 | * @return mixed | |
| 6222 | * @access public | |
| 6223 | */ | |
| 6224 | fu nction get Header(){ | |
| 6225 | retu rn $this-> responseHe ader; | |
| 6226 | } | |
| 6227 | ||
| 6228 | /* * | |
| 6229 | * set proxy info here | |
| 6230 | * | |
| 6231 | * @param string $pr oxyhost | |
| 6232 | * @param string $pr oxyport | |
| 6233 | * @param string $proxyuse rname | |
| 6234 | * @param string $proxypas sword | |
| 6235 | * @access public | |
| 6236 | */ | |
| 6237 | fu nction set HTTPProxy( $proxyhost , $proxypo rt, $proxy username = '', $prox ypassword = '') { | |
| 6238 | $thi s->proxyho st = $prox yhost; | |
| 6239 | $thi s->proxypo rt = $prox yport; | |
| 6240 | $thi s->proxyus ername = $ proxyusern ame; | |
| 6241 | $thi s->proxypa ssword = $ proxypassw ord; | |
| 6242 | } | |
| 6243 | ||
| 6244 | /* * | |
| 6245 | * if authent icating, s et user cr edentials here | |
| 6246 | * | |
| 6247 | * @param string $us ername | |
| 6248 | * @param string $pa ssword | |
| 6249 | * @param string $authtype (basic|di gest|certi ficate|ntl m) | |
| 6250 | * @param array $certReque st (keys m ust be cai nfofile (o ptional), sslcertfil e, sslkeyf ile, passp hrase, ver ifypeer (o ptional), verifyhost (optional ): see cor responding options i n cURL doc s) | |
| 6251 | * @access public | |
| 6252 | */ | |
| 6253 | fu nction set Credential s($usernam e, $passwo rd, $autht ype = 'bas ic', $cert Request = array()) { | |
| 6254 | $this->deb ug("setCre dentials u sername= AI authtype=$ authtype c ertRequest ="); | |
| 6255 | $thi s->appendD ebug($this ->varDump( $certReque st)); | |
| 6256 | $thi s->usernam e = $usern ame; | |
| 6257 | $thi s->passwor d = $passw ord; | |
| 6258 | $thi s->authtyp e = $autht ype; | |
| 6259 | $thi s->certReq uest = $ce rtRequest; | |
| 6260 | } | |
| 6261 | ||
| 6262 | /* * | |
| 6263 | * use HTTP e ncoding | |
| 6264 | * | |
| 6265 | * @param string $en c HTTP enc oding | |
| 6266 | * @access public | |
| 6267 | */ | |
| 6268 | fu nction set HTTPEncodi ng($enc='g zip, defla te'){ | |
| 6269 | $thi s->debug(" setHTTPEnc oding(\"$e nc\")"); | |
| 6270 | $thi s->http_en coding = $ enc; | |
| 6271 | } | |
| 6272 | ||
| 6273 | /* * | |
| 6274 | * Set whethe r to try t o use cURL connectio ns if poss ible | |
| 6275 | * | |
| 6276 | * @param boolea n $use Whe ther to tr y to use c URL | |
| 6277 | * @access public | |
| 6278 | */ | |
| 6279 | fu nction set UseCURL($u se) { | |
| 6280 | $thi s->debug(" setUseCURL ($use)"); | |
| 6281 | $thi s->use_cur l = $use; | |
| 6282 | } | |
| 6283 | ||
| 6284 | /* * | |
| 6285 | * use HTTP p ersistent connection s if possi ble | |
| 6286 | * | |
| 6287 | * @access public | |
| 6288 | */ | |
| 6289 | fu nction use HTTPPersis tentConnec tion(){ | |
| 6290 | $thi s->debug(" useHTTPPer sistentCon nection"); | |
| 6291 | $thi s->persist entConnect ion = true ; | |
| 6292 | } | |
| 6293 | ||
| 6294 | /* * | |
| 6295 | * dynamicall y creates an instanc e of a pro xy class, | |
| 6296 | * allowing u ser to dir ectly call methods f rom wsdl | |
| 6297 | * | |
| 6298 | * @return object soa p_proxy ob ject | |
| 6299 | * @access public | |
| 6300 | */ | |
| 6301 | fu nction get Proxy() { | |
| 6302 | //al tered from rand to u se openssl to help w ith securi ty scans -- VLER EJ VAD-1523 | |
| 6303 | $r = hexdec(bi n2hex(open ssl_random _pseudo_by tes(4))); | |
| 6304 | $eva lStr = $th is->_getPr oxyClassCo de($r); | |
| 6305 | //$t his->debug ("proxy cl ass: $eval Str"); | |
| 6306 | if ( $this->get Error()) { | |
| 6307 | $this- >debug("Er ror from _ getProxyCl assCode, s o return N ULL"); | |
| 6308 | return null; | |
| 6309 | } | |
| 6310 | // e val the cl ass | |
| 6311 | eval ($evalStr) ; | |
| 6312 | // i nstantiate proxy obj ect | |
| 6313 | eval ("\$proxy = new nuso ap_proxy_$ r('');"); | |
| 6314 | // t ransfer cu rrent wsdl data to t he proxy t hereby avo iding pars ing the ws dl twice | |
| 6315 | $pro xy->endpoi ntType = ' wsdl'; | |
| 6316 | $pro xy->wsdlFi le = $this ->wsdlFile ; | |
| 6317 | $pro xy->wsdl = $this->ws dl; | |
| 6318 | $pro xy->operat ions = $th is->operat ions; | |
| 6319 | $pro xy->defaul tRpcParams = $this-> defaultRpc Params; | |
| 6320 | // t ransfer ot her state | |
| 6321 | $pro xy->soap_d efencoding = $this-> soap_defen coding; | |
| 6322 | $pro xy->userna me = $this ->username ; | |
| 6323 | $pro xy->passwo rd = $this ->password ; | |
| 6324 | $pro xy->authty pe = $this ->authtype ; | |
| 6325 | $pro xy->certRe quest = $t his->certR equest; | |
| 6326 | $pro xy->reques tHeaders = $this->re questHeade rs; | |
| 6327 | $pro xy->endpoi nt = $this ->endpoint ; | |
| 6328 | $pro xy->forceE ndpoint = $this->for ceEndpoint ; | |
| 6329 | $pro xy->proxyh ost = $thi s->proxyho st; | |
| 6330 | $pro xy->proxyp ort = $thi s->proxypo rt; | |
| 6331 | $pro xy->proxyu sername = $this->pro xyusername ; | |
| 6332 | $pro xy->proxyp assword = $this->pro xypassword ; | |
| 6333 | $pro xy->http_e ncoding = $this->htt p_encoding ; | |
| 6334 | $pro xy->timeou t = $this- >timeout; | |
| 6335 | $pro xy->respon se_timeout = $this-> response_t imeout; | |
| 6336 | $pro xy->persis tentConnec tion = &$t his->persi stentConne ction; | |
| 6337 | $pro xy->decode _utf8 = $t his->decod e_utf8; | |
| 6338 | $pro xy->curl_o ptions = $ this->curl _options; | |
| 6339 | $pro xy->bindin gType = $t his->bindi ngType; | |
| 6340 | $pro xy->use_cu rl = $this ->use_curl ; | |
| 6341 | retu rn $proxy; | |
| 6342 | } | |
| 6343 | ||
| 6344 | /* * | |
| 6345 | * dynamicall y creates proxy clas s code | |
| 6346 | * | |
| 6347 | * @return string PHP /NuSOAP co de for the proxy cla ss | |
| 6348 | * @access private | |
| 6349 | */ | |
| 6350 | fu nction _ge tProxyClas sCode($r) { | |
| 6351 | $thi s->debug(" in getProx y endpoint Type=$this ->endpoint Type"); | |
| 6352 | $thi s->appendD ebug("wsdl =" . $this ->varDump( $this->wsd l)); | |
| 6353 | if ( $this->end pointType != 'wsdl') { | |
| 6354 | $evalS tr = 'A pr oxy can on ly be crea ted for a WSDL clien t'; | |
| 6355 | $this- >setError( $evalStr); | |
| 6356 | $evalS tr = "echo \"$evalSt r\";"; | |
| 6357 | return $evalStr; | |
| 6358 | } | |
| 6359 | if ( $this->end pointType == 'wsdl' && is_null ($this->ws dl)) { | |
| 6360 | $this- >loadWSDL( ); | |
| 6361 | if ($t his->getEr ror()) { | |
| 6362 | return " echo \"" . $this->ge tError() . "\";"; | |
| 6363 | } | |
| 6364 | } | |
| 6365 | $eva lStr = ''; | |
| 6366 | fore ach ($this ->operatio ns as $ope ration => $opData) { | |
| 6367 | if ($o peration ! = '') { | |
| 6368 | // creat e param st ring and p aram comme nt string | |
| 6369 | if (size of($opData ['input'][ 'parts']) > 0) { | |
| 6370 | $paramStr = ''; | |
| 6371 | $paramArra yStr = ''; | |
| 6372 | $paramComm entStr = ' '; | |
| 6373 | foreach ($ opData['in put']['par ts'] as $n ame => $ty pe) { | |
| 6374 | $p aramStr .= "\$$name, "; | |
| 6375 | $p aramArrayS tr .= "'$n ame' => \$ $name, "; | |
| 6376 | $p aramCommen tStr .= "$ type \$$na me, "; | |
| 6377 | } | |
| 6378 | $paramStr = substr($ paramStr, 0, strlen( $paramStr) -2); | |
| 6379 | $paramArra yStr = sub str($param ArrayStr, 0, strlen( $paramArra yStr)-2); | |
| 6380 | $paramComm entStr = s ubstr($par amCommentS tr, 0, str len($param CommentStr )-2); | |
| 6381 | } else { | |
| 6382 | $paramStr = ''; | |
| 6383 | $paramArra yStr = ''; | |
| 6384 | $paramComm entStr = ' void'; | |
| 6385 | } | |
| 6386 | $opData[ 'namespace '] = !isse t($opData[ 'namespace ']) ? 'htt p://testur i.com' : $ opData['na mespace']; | |
| 6387 | $evalStr .= "// $p aramCommen tStr | |
| 6388 | fu nction " . str_repla ce('.', '_ _', $opera tion) . "( $paramStr) { | |
| 6389 | \$pa rams = arr ay($paramA rrayStr); | |
| 6390 | retu rn \$this- >call('$op eration', \$params, '".$opData ['namespac e']."', '" .(isset($o pData['soa pAction']) ? $opData ['soapActi on'] : '') ."'); | |
| 6391 | } | |
| 6392 | "; | |
| 6393 | unset($p aramStr); | |
| 6394 | unset($p aramCommen tStr); | |
| 6395 | } | |
| 6396 | } | |
| 6397 | $eva lStr = 'cl ass nusoap _proxy_'.$ r.' extend s nusoap_c lient { | |
| 6398 | '. $evalStr.' | |
| 6399 | }'; | |
| 6400 | retu rn $evalSt r; | |
| 6401 | } | |
| 6402 | ||
| 6403 | /* * | |
| 6404 | * dynamicall y creates proxy clas s code | |
| 6405 | * | |
| 6406 | * @return string PHP /NuSOAP co de for the proxy cla ss | |
| 6407 | * @access public | |
| 6408 | */ | |
| 6409 | fu nction get ProxyClass Code() { | |
| 6410 | //al tered from rand to u se openssl to help w ith securi ty scans - - VLER MG | |
| 6411 | $r = hexdec(bi n2hex(open ssl_random _pseudo_by tes(4))); | |
| 6412 | retu rn $this-> _getProxyC lassCode($ r); | |
| 6413 | } | |
| 6414 | ||
| 6415 | /* * | |
| 6416 | * gets the H TTP body f or the cur rent reque st. | |
| 6417 | * | |
| 6418 | * @param str ing $soapm sg The SOA P payload | |
| 6419 | * @return st ring The H TTP body, which incl udes the S OAP payloa d | |
| 6420 | * @access pr ivate | |
| 6421 | */ | |
| 6422 | fu nction get HTTPBody($ soapmsg) { | |
| 6423 | retu rn $soapms g; | |
| 6424 | } | |
| 6425 | ||
| 6426 | /* * | |
| 6427 | * gets the H TTP conten t type for the curre nt request . | |
| 6428 | * | |
| 6429 | * Note: getH TTPBody mu st be call ed before this. | |
| 6430 | * | |
| 6431 | * @return st ring the H TTP conten t type for the curre nt request . | |
| 6432 | * @access pr ivate | |
| 6433 | */ | |
| 6434 | fu nction get HTTPConten tType() { | |
| 6435 | retu rn 'text/x ml'; | |
| 6436 | } | |
| 6437 | ||
| 6438 | /* * | |
| 6439 | * gets the H TTP conten t type cha rset for t he current request. | |
| 6440 | * returns fa lse for no n-text con tent types . | |
| 6441 | * | |
| 6442 | * Note: getH TTPBody mu st be call ed before this. | |
| 6443 | * | |
| 6444 | * @return st ring the H TTP conten t type cha rset for t he current request. | |
| 6445 | * @access pr ivate | |
| 6446 | */ | |
| 6447 | fu nction get HTTPConten tTypeChars et() { | |
| 6448 | retu rn $this-> soap_defen coding; | |
| 6449 | } | |
| 6450 | ||
| 6451 | /* | |
| 6452 | * whether or not parse r should d ecode utf8 element c ontent | |
| 6453 | * | |
| 6454 | * @ret urn alwa ys returns true | |
| 6455 | * @acc ess publ ic | |
| 6456 | */ | |
| 6457 | functi on decodeU TF8($bool) { | |
| 6458 | $thi s->decode_ utf8 = $bo ol; | |
| 6459 | retu rn true; | |
| 6460 | } | |
| 6461 | ||
| 6462 | /* * | |
| 6463 | * adds a ne w Cookie i nto $this- >cookies a rray | |
| 6464 | * | |
| 6465 | * @param string $name Coo kie Name | |
| 6466 | * @param string $value Co okie Value | |
| 6467 | * @return boolea n if cooki e-set was successful returns t rue, else false | |
| 6468 | * @access public | |
| 6469 | * / | |
| 6470 | fu nction set Cookie($na me, $value ) { | |
| 6471 | if ( strlen($na me) == 0) { | |
| 6472 | return false; | |
| 6473 | } | |
| 6474 | $thi s->cookies [] = array ('name' => $name, 'v alue' => $ value); | |
| 6475 | retu rn true; | |
| 6476 | } | |
| 6477 | ||
| 6478 | /* * | |
| 6479 | * gets all Cookies | |
| 6480 | * | |
| 6481 | * @return array wit h all inte rnal cooki es | |
| 6482 | * @access public | |
| 6483 | * / | |
| 6484 | fu nction get Cookies() { | |
| 6485 | retu rn $this-> cookies; | |
| 6486 | } | |
| 6487 | ||
| 6488 | /* * | |
| 6489 | * checks al l Cookies and delete those whi ch are exp ired | |
| 6490 | * | |
| 6491 | * @return boolean a lways retu rn true | |
| 6492 | * @access private | |
| 6493 | * / | |
| 6494 | fu nction che ckCookies( ) { | |
| 6495 | if ( sizeof($th is->cookie s) == 0) { | |
| 6496 | return true; | |
| 6497 | } | |
| 6498 | $thi s->debug(' checkCooki e: check ' . sizeof( $this->coo kies) . ' cookies'); | |
| 6499 | $cur r_cookies = $this->c ookies; | |
| 6500 | $thi s->cookies = array() ; | |
| 6501 | fore ach ($curr _cookies a s $cookie) { | |
| 6502 | if (! is_array($ cookie)) { | |
| 6503 | $this->d ebug('Remo ve cookie that is no t an array '); | |
| 6504 | continue ; | |
| 6505 | } | |
| 6506 | if ((i sset($cook ie['expire s'])) && ( ! empty($c ookie['exp ires']))) { | |
| 6507 | if (strt otime($coo kie['expir es']) > ti me()) { | |
| 6508 | $this->coo kies[] = $ cookie; | |
| 6509 | } else { | |
| 6510 | $this->deb ug('Remove expired c ookie ' . $cookie['n ame']); | |
| 6511 | } | |
| 6512 | } else { | |
| 6513 | $this->c ookies[] = $cookie; | |
| 6514 | } | |
| 6515 | } | |
| 6516 | $thi s->debug(' checkCooki e: '.sizeo f($this->c ookies).' cookies le ft in arra y'); | |
| 6517 | retu rn true; | |
| 6518 | } | |
| 6519 | ||
| 6520 | /* * | |
| 6521 | * updates t he current cookies w ith a new set | |
| 6522 | * | |
| 6523 | * @param array $cookies n ew cookies with whic h to updat e current ones | |
| 6524 | * @return boolea n always r eturn true | |
| 6525 | * @access privat e | |
| 6526 | * / | |
| 6527 | fu nction Upd ateCookies ($cookies) { | |
| 6528 | if ( sizeof($th is->cookie s) == 0) { | |
| 6529 | // no existing c ookies: ta ke whateve r is new | |
| 6530 | if (si zeof($cook ies) > 0) { | |
| 6531 | $this->d ebug('Sett ing new co okie(s)'); | |
| 6532 | $this->c ookies = $ cookies; | |
| 6533 | } | |
| 6534 | return true; | |
| 6535 | } | |
| 6536 | if ( sizeof($co okies) == 0) { | |
| 6537 | // no new cookie s: keep wh at we've g ot | |
| 6538 | return true; | |
| 6539 | } | |
| 6540 | // m erge | |
| 6541 | fore ach ($cook ies as $ne wCookie) { | |
| 6542 | if (!i s_array($n ewCookie)) { | |
| 6543 | continue ; | |
| 6544 | } | |
| 6545 | if ((! isset($new Cookie['na me'])) || (!isset($n ewCookie[' value']))) { | |
| 6546 | continue ; | |
| 6547 | } | |
| 6548 | $newNa me = $newC ookie['nam e']; | |
| 6549 | ||
| 6550 | $found = false; | |
| 6551 | for ($ i = 0; $i < count($t his->cooki es); $i++) { | |
| 6552 | $cookie = $this->c ookies[$i] ; | |
| 6553 | if (!is_ array($coo kie)) { | |
| 6554 | continue; | |
| 6555 | } | |
| 6556 | if (!iss et($cookie ['name'])) { | |
| 6557 | continue; | |
| 6558 | } | |
| 6559 | if ($new Name != $c ookie['nam e']) { | |
| 6560 | continue; | |
| 6561 | } | |
| 6562 | $newDoma in = isset ($newCooki e['domain' ]) ? $newC ookie['dom ain'] : 'N ODOMAIN'; | |
| 6563 | $domain = isset($c ookie['dom ain']) ? $ cookie['do main'] : ' NODOMAIN'; | |
| 6564 | if ($new Domain != $domain) { | |
| 6565 | continue; | |
| 6566 | } | |
| 6567 | $newPath = isset($ newCookie[ 'path']) ? $newCooki e['path'] : 'NOPATH' ; | |
| 6568 | $path = isset($coo kie['path' ]) ? $cook ie['path'] : 'NOPATH '; | |
| 6569 | if ($new Path != $p ath) { | |
| 6570 | continue; | |
| 6571 | } | |
| 6572 | $this->c ookies[$i] = $newCoo kie; | |
| 6573 | $found = true; | |
| 6574 | $this->d ebug('Upda te cookie ' . $newNa me . '=' . $newCooki e['value'] ); | |
| 6575 | break; | |
| 6576 | } | |
| 6577 | if (! $found) { | |
| 6578 | $this->d ebug('Add cookie ' . $newName . '=' . $n ewCookie[' value']); | |
| 6579 | $this->c ookies[] = $newCooki e; | |
| 6580 | } | |
| 6581 | } | |
| 6582 | retu rn true; | |
| 6583 | } | |
| 6584 | ||
| 6585 | ||
| 6586 | /* * | |
| 6587 | * Creates a secure ra ndom integ er between min and m ax. repla ces rand. | |
| 6588 | * | |
| 6589 | * @author E lan Jaffee (VLER) <j affee_elan @bah.com> | |
| 6590 | * @param int $m in min val ue for the random nu mber | |
| 6591 | * @param int $m ax max val ue for the random nu mber | |
| 6592 | * @param boolea n $pedanti c are you strict abo ut removin g bias (re quired for security) | |
| 6593 | * @return int ra ndom numbe r | |
| 6594 | * / | |
| 6595 | fu nction cry pto_rand($ min,$max,$ pedantic=t rue) { | |
| 6596 | $dif f = $max - $min; | |
| 6597 | if ( $diff <= 0 ) return $ min; // no t so rando m... | |
| 6598 | $ran ge = $diff + 1; // b ecause $ma x is inclu sive | |
| 6599 | $bit s = ceil(l og(($range ),2)); | |
| 6600 | $byt es = ceil( $bits/8.0) ; | |
| 6601 | $bit s_max = 1 << $bits; | |
| 6602 | // e .g. if $ra nge = 3000 (bin: 101 110111000) | |
| 6603 | // +--------+ --------+ | |
| 6604 | // |....1011| 10111000| | |
| 6605 | // +--------+ --------+ | |
| 6606 | // bits=12, b ytes=2, bi ts_max=2^1 2=4096 | |
| 6607 | $num = 0; | |
| 6608 | do { | |
| 6609 | $num = hexdec(bi n2hex(open ssl_random _pseudo_by tes($bytes ))) % $bit s_max; | |
| 6610 | if ($n um >= $ran ge) { | |
| 6611 | if ($pedanti c) continu e; // star t over ins tead of ac cepting bi as | |
| 6612 | // else | |
| 6613 | $n um = $num % $range; // less s ecure. Le ads to bia s | |
| 6614 | } | |
| 6615 | break; | |
| 6616 | } wh ile(true); | |
| 6617 | retu rn $num + $min; | |
| 6618 | } | |
| 6619 | } | |
| 6620 | ||
| 6621 | if (!exten sion_loade d('soap')) { | |
| 6622 | /* * | |
| 6623 | * For backwa rds compat iblity, de fine soapc lient unle ss the PHP SOAP exte nsion is l oaded. | |
| 6624 | * @package t hird-party | |
| 6625 | * @subpackag e nusoap | |
| 6626 | */ | |
| 6627 | cl ass soapcl ient exten ds nusoap_ client { | |
| 6628 | } | |
| 6629 | } | |
| 6630 | ?> |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.