00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 include_once( "lib/ezsoap/classes/ezsoapresponse.php" );
00076 include_once( "lib/ezutils/classes/ezdebug.php" );
00077
00078 class eZSOAPClient
00079 {
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 function eZSOAPClient( $server, $path = '/', $port = 80, $useSSL = null )
00090 {
00091 $this->Login = "";
00092 $this->Password = "";
00093 $this->Server = $server;
00094 $this->Path = $path;
00095 $this->Port = $port;
00096 if ( is_numeric( $port ) )
00097 {
00098 $this->Port = $port;
00099 }
00100 elseif ( strtolower( $port ) == 'ssl' )
00101 {
00102 $this->UseSSL = true;
00103 $this->Port = 443;
00104 }
00105 else
00106 {
00107 $this->Port = 80;
00108 }
00109
00110 if ( $useSSL === true )
00111 {
00112 $this->UseSSL = true;
00113 }
00114 else if ( $useSSL === false )
00115 {
00116 $this->UseSSL = false;
00117 }
00118 }
00119
00120
00121
00122
00123 function send( $request )
00124 {
00125 if ( !$this->UseSSL || !in_array( "curl", get_loaded_extensions() ) )
00126 {
00127 if ( $this->Timeout != 0 )
00128 {
00129 $fp = fsockopen( $this->Server,
00130 $this->Port,
00131 $this->errorNumber,
00132 $this->errorString,
00133 $this->Timeout );
00134 }
00135 else
00136 {
00137 $fp = fsockopen( $this->Server,
00138 $this->Port,
00139 $this->errorNumber,
00140 $this->errorString );
00141 }
00142
00143 if ( $fp == 0 )
00144 {
00145 $this->ErrorString = '<b>Error:</b> eZSOAPClient::send() : Unable to open connection to ' . $this->Server . '.';
00146 return 0;
00147 }
00148
00149 $payload = $request->payload();
00150
00151 $authentification = "";
00152 if ( ( $this->login() != "" ) )
00153 {
00154 $authentification = "Authorization: Basic " . base64_encode( $this->login() . ":" . $this->password() ) . "\r\n" ;
00155 }
00156
00157 $HTTPRequest = "POST " . $this->Path . " HTTP/1.0\r\n" .
00158 "User-Agent: eZ soap client\r\n" .
00159 "Host: " . $this->Server . "\r\n" .
00160 $authentification .
00161 "Content-Type: text/xml\r\n" .
00162 "SOAPAction: \"" . $request->namespace() . '/' . $request->name() . "\"\r\n" .
00163 "Content-Length: " . strlen( $payload ) . "\r\n\r\n" .
00164 $payload;
00165
00166 if ( !fputs( $fp, $HTTPRequest, strlen( $HTTPRequest ) ) )
00167 {
00168 $this->ErrorString = "<b>Error:</b> could not send the SOAP request. Could not write to the socket.";
00169 $response = 0;
00170 return $response;
00171 }
00172
00173 $rawResponse = "";
00174
00175 while ( $data = fread( $fp, 32768 ) )
00176 {
00177 $rawResponse .= $data;
00178 }
00179
00180
00181 fclose( $fp );
00182 }
00183 else
00184 {
00185 if ( get_class( $request ) == "ezsoaprequest" )
00186 {
00187 $URL = "https://" . $this->Server . ":" . $this->Port . $this->Path;
00188 $ch = curl_init ( $URL );
00189 if ( $this->Timeout != 0 )
00190 {
00191 curl_setopt( $ch, CURLOPT_TIMEOUT, $this->TimeOut );
00192 }
00193 $payload = $request->payload();
00194
00195 if ( $ch != 0 )
00196 {
00197 $HTTPCall = "POST " . $this->Path . " HTTP/1.0\r\n" .
00198 "User-Agent: eZ soap client\r\n" .
00199 "Host: " . $this->Server . "\r\n" .
00200 "Content-Type: text/xml\r\n" .
00201 "SOAPAction: \"" . $request->namespace() . '/' . $request->name() . "\"\r\n" .
00202 "Content-Length: " . strlen( $payload ) . "\r\n";
00203 if ( $this->login() != '' )
00204 {
00205 $HTTPCall .= "Authorization: Basic " . base64_encode( $this->login() . ":" . $this->Password() ) . "\r\n";
00206 }
00207 $HTTPCall .= "\r\n" . $payload;
00208
00209 curl_setopt( $ch, CURLOPT_URL, $URL );
00210 curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
00211 curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 1 );
00212 curl_setopt( $ch, CURLOPT_HEADER, 1 );
00213 curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
00214 curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, $HTTPCall );
00215 unset( $rawResponse );
00216
00217 if ( $ch != 0 )
00218 {
00219 $rawResponse = curl_exec( $ch );
00220 }
00221 if ( !$rawResponse )
00222 {
00223 $this->ErrorString = "<b>Error:</b> could not send the XML-SOAP with SSL call. Could not write to the socket.";
00224 $response = 0;
00225 return $response;
00226 }
00227 }
00228
00229 curl_close( $ch );
00230 }
00231 }
00232 $response = new eZSOAPResponse();
00233 $response->decodeStream( $request, $rawResponse );
00234 return $response;
00235 }
00236
00237
00238
00239
00240
00241
00242 function setTimeout( $timeout )
00243 {
00244 $this->Timeout = $timeout;
00245 }
00246
00247
00248
00249
00250 function setLogin( $login )
00251 {
00252 $this->Login = $login;
00253 }
00254
00255
00256
00257
00258 function login()
00259 {
00260 return $this->Login;
00261 }
00262
00263
00264
00265
00266 function setPassword( $password )
00267 {
00268 $this->Password = $password;
00269 }
00270
00271
00272
00273
00274 function password()
00275 {
00276 return $this->Password;
00277 }
00278
00279
00280 var $Server;
00281
00282 var $Path;
00283
00284 var $Port;
00285
00286 var $Timeout = 0;
00287
00288 var $Login;
00289
00290 var $Password;
00291 var $UseSSL;
00292 }
00293
00294 ?>