[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/phpgwapi/inc/ -> class.soap_client.inc.php (source)

   1  <?php
   2  /*
   3  
   4      SOAPx4
   5      by Dietrich Ayala (C) 2001 dietrich@ganx4.com
   6  
   7      This project began based on code from the 2 projects below,
   8      and still contains some original code. The licenses of both must be respected.
   9  
  10      XML-RPC for PHP
  11      originally by Edd Dumbill (C) 1999-2000
  12  
  13      SOAP for PHP
  14      by Victor Zou (C) 2000-2001 <victor@gigaideas.com.cn>
  15  
  16  */
  17  
  18      /*  changelog:
  19      2001-07-04
  20      - abstract type system to support either 1999 or 2001 schema (arg, typing still needs much
  21      solidification.)
  22      - implemented proxy support, based on sample code from miles lott <milos@speakeasy.net>
  23      - much general cleanup of code & cleaned out what was left of original xml-rpc/gigaideas code
  24      - implemented a transport argument into send() that allows you to specify different transports
  25      (assuming you have implemented the function, and added it to the conditional statement in send()
  26      - abstracted the determination of charset in Content-type header
  27      2001-07-5
  28      - fixed more weird type/namespace issues
  29      */
  30  
  31      // $path can be a complete endpoint url, with the other parameters left blank:
  32      // $soap_client = new soap_client("http://path/to/soap/server");
  33  
  34    /* $Id: class.soap_client.inc.php 20295 2006-02-15 12:31:25Z  $ */
  35  
  36      class soap_client
  37      {
  38  		 function soap_client($path,$server=False,$port=False)
  39           {
  40              $this->port = 80;
  41              $this->path = $path;
  42              $this->server = $server;
  43              $this->errno;
  44              $this->errstring;
  45              $this->debug_flag = True;
  46              $this->debug_str = '';
  47              $this->username = '';
  48              $this->password = '';
  49              $this->action = '';
  50              $this->incoming_payload = '';
  51              $this->outgoing_payload = '';
  52              $this->response = '';
  53              $this->action = '';
  54  
  55              // endpoint mangling
  56              if(ereg("^http://",$path))
  57              {
  58                  $path = str_replace('http://','',$path);
  59                  $this->path = strstr($path,'/');
  60                  $this->debug("path = $this->path");
  61                  if(ereg(':',$path))
  62                  {
  63                      $this->server = substr($path,0,strpos($path,':'));
  64                      $this->port = substr(strstr($path,':'),1);
  65                      $this->port = substr($this->port,0,strpos($this->port,'/'));
  66                  }
  67                  else
  68                  {
  69                      $this->server = substr($path,0,strpos($path,'/'));
  70                  }
  71              }
  72              if($port)
  73              {
  74                  $this->port = $port;
  75              }
  76          }
  77  
  78  		function setCredentials($u, $p)
  79          {
  80              $this->username = $u;
  81              $this->password = $p;
  82          }
  83  
  84  		function send($msg, $action, $timeout=0, $ssl=False)
  85          {
  86              // where msg is an soapmsg
  87              $msg->debug_flag = $this->debug_flag;
  88              $this->action = $action;
  89              if($ssl)
  90              {
  91                  return $this->ssl_sendPayloadHTTP10(
  92                      $msg,
  93                      $this->server,
  94                      $this->port,
  95                      $timeout,
  96                      $this->username,
  97                      $this->password
  98                  );
  99              }
 100              else
 101              {
 102                  return $this->sendPayloadHTTP10(
 103                      $msg,
 104                      $this->server,
 105                      $this->port,
 106                      $timeout,
 107                      $this->username,
 108                      $this->password
 109                  );
 110              }
 111          }
 112  
 113  		function sendPayloadHTTP10($msg, $server, $port, $timeout=0, $username='', $password='')
 114          {    
 115              if($timeout > 0)
 116              {
 117                  $fp = fsockopen($server, $port,&$this->errno, &$this->errstr, $timeout);
 118              }
 119              else
 120              {
 121                  $fp = fsockopen($server, $port,&$this->errno, &$this->errstr);
 122              }
 123              if (!$fp)
 124              {
 125                  $this->debug("Couldn't open socket connection to server!");
 126                  $this->debug("Server: $this->server"); 
 127                  return 0;
 128              }
 129  
 130              // thanks to Grant Rauscher <grant7@firstworld.net> for this
 131              $credentials = '';
 132              if ($username != '')
 133              {
 134                  $credentials = "Authorization: Basic " . base64_encode($username . ":" . $password) . "\r\n";
 135              }
 136  
 137              $soap_data = $msg->serialize();
 138              $this->outgoing_payload = 'POST '
 139                  . $this->path
 140                  . " HTTP/1.0\r\n"
 141                  . 'User-Agent: eGroupware/' . $cliversion . '(PHP) ' . "\r\n"
 142                  . 'X-EGW-Server: ' . $this->server . "\r\n"
 143                  . 'X-EGW-Version: ' . $GLOBALS['egw_info']['server']['versions']['phpgwapi'] . "\r\n"
 144                  . 'Host: '.$this->server . "\r\n"
 145                  . $credentials
 146                  . "Content-Type: text/xml\r\nContent-Length: " . strlen($soap_data) . "\r\n"
 147                  . 'SOAPAction: "' . $this->action . '"' . "\r\n\r\n"
 148                  . $soap_data;
 149              // send
 150              if(!fputs($fp, $this->outgoing_payload, strlen($this->outgoing_payload)))
 151              {
 152                  $this->debug('Write error');
 153              }
 154  
 155              // get reponse
 156              while($data = fread($fp, 32768))
 157              {
 158                  $incoming_payload .= $data;
 159              }
 160  
 161              fclose($fp);
 162              $this->incoming_payload = $incoming_payload;
 163              // $response is a soapmsg object
 164              $this->response = $msg->parseResponse($incoming_payload);
 165              $this->debug($msg->debug_str);
 166              return $this->response;
 167          }
 168  
 169  		function ssl_sendPayloadHTTP10($msg, $server, $port, $timeout=0,$username='', $password='')
 170          {
 171              if(!function_exists(curl_init))
 172              {
 173                  $this->errstr = 'No curl functions available - use of ssl is invalid';
 174                  return False;
 175              }
 176              /* curl Method borrowed from:
 177                http://sourceforge.net/tracker/index.php?func=detail&aid=427359&group_id=23199&atid=377731
 178              */
 179  
 180              // thanks to Grant Rauscher <grant7@firstworld.net>
 181              // for this
 182              $credentials = '';
 183              if ($username!='')
 184              {
 185                  $credentials = "Authorization: Basic " . base64_encode($username . ':' . $password) . "\r\n";
 186              }
 187  
 188              $soap_data = $msg->serialize();
 189              $this->outgoing_payload = 'POST '
 190                  . $this->path
 191                  . " HTTP/1.0\r\n"
 192                  . 'User-Agent: eGroupware/' . $cliversion . '(PHP) ' . "\r\n"
 193                  . 'X-EGW-Server: ' . $this->server . "\r\n"
 194                  . 'X-EGW-Version: ' . $GLOBALS['egw_info']['server']['versions']['phpgwapi'] . "\r\n"
 195                  . 'Host: ' . $this->server . "\r\n"
 196                  . $credentials
 197                  . "Content-Type: text/xml\r\nContent-Length: " . strlen($soap_data) . "\r\n"
 198                  . 'SOAPAction: "' . $this->action . '"' . "\r\n\r\n"
 199                  . $soap_data;
 200  
 201              // send
 202              $ch = curl_init();
 203              curl_setopt($ch, CURLOPT_URL,$this->server);
 204              curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 205              curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->outgoing_payload);
 206              curl_setopt($ch, CURLOPT_HEADER, 0);
 207              $incoming_payload = curl_exec($ch);
 208              curl_close($ch);
 209  
 210              $this->incoming_payload = $incoming_payload;
 211              // $response is a soapmsg object
 212              $this->response = $msg->parseResponse($incoming_payload);
 213              $this->debug($msg->debug_str);
 214              return $this->response;
 215          }
 216  
 217  		function debug($string)
 218          {
 219              if($this->debug_flag)
 220              {
 221                  $this->debug_str .= "$string\n";
 222              }
 223          }
 224      } // end class soap_client
 225  ?>


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7