Esempio n. 1
0
 /**
  * SOAP_Transport_SMTP Constructor
  *
  * @param string $url  mailto: address.
  *
  * @access public
  */
 function SOAP_Transport_SMTP($url, $encoding = 'US-ASCII')
 {
     parent::SOAP_Base('SMTP');
     $this->encoding = $encoding;
     $this->urlparts = @parse_url($url);
     $this->url = $url;
 }
Esempio n. 2
0
 /**
  * SOAP_Transport_HTTP Constructor
  *
  * @access public
  *
  * @param string $url       HTTP url to SOAP endpoint.
  * @param string $encoding  Encoding to use.
  */
 function SOAP_Transport_HTTP($url, $encoding = SOAP_DEFAULT_ENCODING)
 {
     parent::SOAP_Base('HTTP');
     $this->urlparts = @parse_url($url);
     $this->url = $url;
     $this->encoding = $encoding;
 }
Esempio n. 3
0
 /**
  * SOAP_Client::call
  *
  * the namespace parameter is overloaded to accept an array of
  * options that can contain data necessary for various transports
  * if it is used as an array, it MAY contain a namespace value and a
  * soapaction value.  If it is overloaded, the soapaction parameter is
  * ignored and MUST be placed in the options array.  This is done
  * to provide backwards compatibility with current clients, but
  * may be removed in the future.
  *
  * @param string method
  * @param array  params
  * @param array options (hash with namespace, soapaction, timeout, from, subject, etc.)
  *
  * The options parameter can have a variety of values added.  The currently supported
  * values are:
  *   namespace
  *   soapaction
  *   timeout (http socket timeout)
  *   from (smtp)
  *   transfer-encoding (smtp, sets the Content-Transfer-Encoding header)
  *   subject (smtp, subject header)
  *   headers (smtp, array-hash of extra smtp headers)
  *
  * @return array of results
  * @access public
  */
 function &call($method, &$params, $namespace = false, $soapAction = false)
 {
     $this->headersIn = null;
     $this->__last_request = null;
     $this->__last_response = null;
     $this->wire = null;
     $this->xml = null;
     $soap_data =& $this->__generate($method, $params, $namespace, $soapAction);
     if (PEAR::isError($soap_data)) {
         return $this->_raiseSoapFault($soap_data);
     }
     // __generate may have changed the endpoint if the wsdl has more
     // than one service, so we need to see if we need to generate
     // a new transport to hook to a different URI.  Since the transport
     // protocol can also change, we need to get an entirely new object,
     // though this could probably be optimized.
     if (!$this->_soap_transport || $this->_endpoint != $this->_soap_transport->url) {
         $this->_soap_transport =& SOAP_Transport::getTransport($this->_endpoint);
         if (PEAR::isError($this->_soap_transport)) {
             $fault =& $this->_soap_transport;
             $this->_soap_transport = null;
             return $this->_raiseSoapFault($fault);
         }
     }
     $this->_soap_transport->encoding = $this->_encoding;
     // Send the message.
     $transport_options = array_merge_recursive($this->__proxy_params, $this->__options);
     $this->xml =& $this->_soap_transport->send($soap_data, $transport_options);
     // Save the wire information for debugging.
     if ($this->__options['trace'] > 0) {
         $this->__last_request =& $this->_soap_transport->outgoing_payload;
         $this->__last_response =& $this->_soap_transport->incoming_payload;
         $this->wire =& $this->__get_wire();
     }
     if ($this->_soap_transport->fault) {
         return $this->_raiseSoapFault($this->xml);
     }
     $this->__attachments =& $this->_soap_transport->attachments;
     $this->__result_encoding = $this->_soap_transport->result_encoding;
     if (isset($this->__options['result']) && $this->__options['result'] != 'parse') {
         return $this->xml;
     }
     return $this->__parse($this->xml, $this->__result_encoding, $this->__attachments);
 }
Esempio n. 4
0
 function service(&$data, $gateway = '', $endpoint = '', $send_response = true, $dump = false)
 {
     $this->endpoint = $endpoint;
     $response = '';
     $useEncoding = 'Mime';
     $options = array();
     if (!$gateway) {
         $gateway = $this->gateway;
     }
     /* We have a full set of headers, need to find the first blank
      * line. */
     $this->_parseEmail($data);
     if ($this->fault) {
         $response = $this->fault->message();
     }
     if ($this->headers['content-type'] == 'application/dime') {
         $useEncoding = 'DIME';
     }
     /* Call the HTTP Server. */
     if (!$response) {
         $soap_transport =& SOAP_Transport::getTransport($gateway, $this->xml_encoding);
         if ($soap_transport->fault) {
             $response = $soap_transport->fault->message();
         }
     }
     /* Send the message. */
     if (!$response) {
         $options['soapaction'] = $this->headers['soapaction'];
         $options['headers']['Content-Type'] = $this->headers['content-type'];
         $response = $soap_transport->send($data, $options);
         if (isset($this->headers['mime-version'])) {
             $options['headers']['MIME-Version'] = $this->headers['mime-version'];
         }
         if ($soap_transport->fault) {
             $response = $soap_transport->fault->message();
         } else {
             foreach ($soap_transport->transport->attachments as $cid => $body) {
                 $this->attachments[] = array('body' => $body, 'cid' => $cid, 'encoding' => 'base64');
             }
             if (count($this->_attachments)) {
                 if ($useEncoding == 'Mime') {
                     $soap_msg = $this->_makeMimeMessage($response);
                     $options['headers']['MIME-Version'] = '1.0';
                 } else {
                     /* Default is DIME. */
                     $soap_msg = $this->_makeDIMEMessage($response);
                     $options['headers']['Content-Type'] = 'application/dime';
                 }
                 if (PEAR::isError($soap_msg)) {
                     return $this->_raiseSoapFault($soap_msg);
                 }
                 if (is_array($soap_msg)) {
                     $response = $soap_msg['body'];
                     if (count($soap_msg['headers'])) {
                         if (isset($options['headers'])) {
                             $options['headers'] = array_merge($options['headers'], $soap_msg['headers']);
                         } else {
                             $options['headers'] = $soap_msg['headers'];
                         }
                     }
                 }
             }
         }
     }
     if ($this->send_response) {
         if ($this->dump || $dump) {
             print $response;
         } else {
             $from = array_key_exists('reply-to', $this->headers) ? $this->headers['reply-to'] : $this->headers['from'];
             $soap_transport =& SOAP_Transport::getTransport('mailto:' . $from, $this->response_encoding);
             $from = $this->endpoint ? $this->endpoint : $this->headers['to'];
             $headers = array('In-Reply-To' => $this->headers['message-id']);
             $options = array('from' => $from, 'subject' => $this->headers['subject'], 'headers' => $headers);
             $soap_transport->send($response, $options);
         }
     }
 }
Esempio n. 5
0
 function service(&$data, $endpoint = '', $send_response = true, $dump = false)
 {
     $this->endpoint = $endpoint;
     $attachments = array();
     $headers = array();
     /* If neither matches, we'll just try it anyway. */
     if (stristr($data, 'Content-Type: application/dime')) {
         $this->_decodeDIMEMessage($data, $this->headers, $attachments);
         $useEncoding = 'DIME';
     } elseif (stristr($data, 'MIME-Version:')) {
         /* This is a mime message, let's decode it. */
         $this->_decodeMimeMessage($data, $this->headers, $attachments);
         $useEncoding = 'Mime';
     } else {
         /* The old fallback, but decodeMimeMessage handles things fine. */
         $this->_parseEmail($data);
     }
     /* Get the character encoding of the incoming request treat incoming
      * data as UTF-8 if no encoding set. */
     if (!$this->_getContentEncoding($this->headers['content-type'])) {
         $this->xml_encoding = SOAP_DEFAULT_ENCODING;
         /* An encoding we don't understand, return a fault. */
         $this->_raiseSoapFault('Unsupported encoding, use one of ISO-8859-1, US-ASCII, UTF-8', '', '', 'Server');
         $response = $this->getFaultMessage();
     }
     if ($this->soapfault) {
         $response = $this->soapfault->message();
     } else {
         $soap_msg = $this->parseRequest($data, $attachments);
         /* Handle Mime or DIME encoding. */
         /* TODO: DIME Encoding should move to the transport, do it here
          * for now and for ease of getting it done. */
         if (count($this->_attachments)) {
             if ($useEncoding == 'Mime') {
                 $soap_msg = $this->_makeMimeMessage($soap_msg);
             } else {
                 /* Default is DIME. */
                 $soap_msg = $this->_makeDIMEMessage($soap_msg);
                 $soap_msg['headers']['Content-Type'] = 'application/dime';
             }
             if (PEAR::isError($soap_msg)) {
                 return $this->raiseSoapFault($soap_msg);
             }
         }
         if (is_array($soap_msg)) {
             $response = $soap_msg['body'];
             if (count($soap_msg['headers'])) {
                 $headers = $soap_msg['headers'];
             }
         } else {
             $response = $soap_msg;
         }
     }
     if ($this->send_response) {
         if ($dump) {
             print $response;
         } else {
             $from = array_key_exists('reply-to', $this->headers) ? $this->headers['reply-to'] : $this->headers['from'];
             $soap_transport =& SOAP_Transport::getTransport('mailto:' . $from, $this->response_encoding);
             $from = $this->endpoint ? $this->endpoint : $this->headers['to'];
             $headers['In-Reply-To'] = $this->headers['message-id'];
             $options = array('from' => $from, 'subject' => $this->headers['subject'], 'headers' => $headers);
             $soap_transport->send($response, $options);
         }
     }
 }
Esempio n. 6
0
 /**
  * SOAP_Client::call
  *
  * @param string method
  * @param array  params
  * @param string namespace  (not required if using wsdl)
  * @param string soapAction   (not required if using wsdl)
  *
  * @return array of results
  * @access public
  */
 function call($method, $params = array(), $namespace = false, $soapAction = false)
 {
     $this->fault = null;
     if ($this->endpointType == 'wsdl') {
         $this->setSchemaVersion($this->wsdl->xsd);
         // get portName
         if (!$this->portName) {
             $this->portName = $this->wsdl->getPortName($method);
             if (PEAR::isError($this->portName)) {
                 return $this->raiseSoapFault($this->portName);
             }
         }
         $namespace = $this->wsdl->getNamespace($this->portName, $method);
         // get endpoint
         $this->endpoint = $this->wsdl->getEndpoint($this->portName);
         if (PEAR::isError($this->endpoint)) {
             return $this->raiseSoapFault($this->endpoint);
         }
         $this->debug("endpoint: {$this->endpoint}");
         $this->debug("portName: {$this->portName}");
         // get operation data
         $opData = $this->wsdl->getOperationData($this->portName, $method);
         if (PEAR::isError($opData)) {
             return $this->raiseSoapFault($opData);
         }
         $soapAction = $opData['soapAction'];
         // set input params
         $nparams = array();
         if (count($opData['input']['parts']) > 0) {
             $i = 0;
             reset($params);
             foreach ($opData['input']['parts'] as $name => $type) {
                 if (isset($params[$name])) {
                     $nparams[$name] = $params[$name];
                 } else {
                     // XXX assuming it's an array, not a hash
                     // XXX this is pretty pethetic, but "fixes" a problem where
                     // paremeter names do not match correctly
                     $nparams[$name] = current($params);
                     next($params);
                 }
                 if (gettype($nparams[$name]) != 'object' && get_class($nparams[$name]) != 'soap_value') {
                     // type is a qname likely, split it apart, and get the type namespace from wsdl
                     $qname = new QName($type);
                     if ($qname->ns) {
                         $type_namespace = $this->wsdl->namespaces[$qname->ns];
                     } else {
                         $type_namespace = NULL;
                     }
                     $type = $qname->name;
                     $nparams[$name] = new SOAP_Value($name, $type, $nparams[$name], $namespace, $type_namespace, $this->wsdl);
                 }
             }
         }
         $params = $nparams;
     }
     $this->debug("soapAction: {$soapAction}");
     $this->debug("namespace: {$namespace}");
     // make message
     $soapmsg = new SOAP_Message($method, $params, $namespace, NULL, $this->wsdl);
     if ($soapmsg->fault) {
         return $this->raiseSoapFault($soapmsg->fault);
     }
     // serialize the message
     $soap_data = $soapmsg->serialize();
     $this->debug("soap_data " . $soap_data);
     if (PEAR::isError($soap_data)) {
         return $this->raiseSoapFault($soap_data);
     }
     $this->debug('<xmp>' . $soap_data . '</xmp>');
     // instantiate client
     $dbg = "calling server at '{$this->endpoint}'...";
     $soap_transport = new SOAP_Transport($this->endpoint, $this->debug_flag);
     if ($soap_transport->fault) {
         return $this->raiseSoapFault($soap_transport->fault);
     }
     $this->debug($dbg . 'instantiated client successfully');
     $this->debug("endpoint: {$this->endpoint}<br>\n");
     // send
     $dbg = "sending msg w/ soapaction '{$soapAction}'...";
     // send the message
     $this->response = $soap_transport->send($soap_data, $soapAction);
     if ($soap_transport->fault) {
         return $this->raiseSoapFault($this->response);
     }
     // parse the response
     $return = $soapmsg->parseResponse($this->response);
     $this->debug($soap_transport->debug_data);
     $this->debug($dbg . 'sent message successfully and got a(n) ' . gettype($return) . ' back');
     // check for valid response
     if (PEAR::isError($return)) {
         return $this->raiseSoapFault($return);
     } else {
         if (strcasecmp(get_class($return), 'SOAP_Value') != 0) {
             return $this->raiseSoapFault("didn't get SOAP_Value object back from client");
         }
     }
     // decode to native php datatype
     $returnArray = $return->decode();
     // fault?
     if (PEAR::isError($returnArray)) {
         return $this->raiseSoapFault($returnArray);
     }
     if (is_array($returnArray)) {
         if (isset($returnArray['faultcode']) || isset($returnArray['SOAP-ENV:faultcode'])) {
             foreach ($returnArray as $k => $v) {
                 if (stristr($k, 'faultcode')) {
                     $this->faultcode = $v;
                 }
                 if (stristr($k, 'faultstring')) {
                     $this->faultstring = $v;
                 }
                 if (stristr($k, 'faultdetail')) {
                     $this->faultdetail = $v;
                 }
                 if (stristr($k, 'faultactor')) {
                     $this->faultactor = $v;
                 }
             }
             return $this->raiseSoapFault($this->faultstring, $this->faultdetail, $this->faultactor, $this->faultcode);
         }
         // return array of return values
         if (count($returnArray) == 1) {
             return array_shift($returnArray);
         }
         return $returnArray;
     }
     return $returnArray;
 }
Esempio n. 7
0
 function service(&$data, $endpoint = '', $send_response = TRUE, $dump = FALSE)
 {
     $this->endpoint = $endpoint;
     $attachments = array();
     $headers = array();
     # if neither matches, we'll just try it anyway
     if (stristr($data, 'Content-Type: application/dime')) {
         $this->_decodeDIMEMessage($data, $this->headers, $attachments);
         $useEncoding = 'DIME';
     } else {
         if (stristr($data, 'MIME-Version:')) {
             // this is a mime message, lets decode it.
             #$data = 'Content-Type: '.stripslashes($_SERVER['CONTENT_TYPE'])."\r\n\r\n".$data;
             $this->_decodeMimeMessage($data, $this->headers, $attachments);
             $useEncoding = 'Mime';
         } else {
             // the old fallback, but decodeMimeMessage handles things fine.
             $this->_parseEmail($data);
         }
     }
     // get the character encoding of the incoming request
     // treat incoming data as UTF-8 if no encoding set
     if (!$response && !$this->_getContentEncoding($this->headers['content-type'])) {
         $this->xml_encoding = SOAP_DEFAULT_ENCODING;
         // an encoding we don't understand, return a fault
         $this->_raiseSoapFault('Unsupported encoding, use one of ISO-8859-1, US-ASCII, UTF-8', '', '', 'Server');
         $response = $this->getFaultMessage();
     }
     if ($this->soapfault) {
         $response = $this->soapfault->message();
     } else {
         $soap_msg = $this->parseRequest($data, $attachments);
         // handle Mime or DIME encoding
         // XXX DIME Encoding should move to the transport, do it here for now
         // and for ease of getting it done
         if (count($this->__attachments)) {
             if ($useEncoding == 'Mime') {
                 $soap_msg = $this->_makeMimeMessage($soap_msg);
             } else {
                 // default is dime
                 $soap_msg = $this->_makeDIMEMessage($soap_msg);
                 $header['Content-Type'] = 'application/dime';
             }
             if (PEAR::isError($soap_msg)) {
                 return $this->raiseSoapFault($soap_msg);
             }
         }
         if (is_array($soap_msg)) {
             $response = $soap_msg['body'];
             if (count($soap_msg['headers'])) {
                 $headers = $soap_msg['headers'];
             }
         } else {
             $response = $soap_msg;
         }
     }
     if ($this->send_response) {
         if ($dump) {
             print $response;
         } else {
             $from = array_key_exists('reply-to', $this->headers) ? $this->headers['reply-to'] : $this->headers['from'];
             # XXX what if no from?????
             $soap_transport =& SOAP_Transport::getTransport('mailto:' . $from, $this->response_encoding);
             $from = $this->endpoint ? $this->endpoint : $this->headers['to'];
             $headers['In-Reply-To'] = $this->headers['message-id'];
             $options = array('from' => $from, 'subject' => $this->headers['subject'], 'headers' => $headers);
             $soap_transport->send($response, $options);
         }
     }
 }
Esempio n. 8
0
 /**
  * Calls a method on the SOAP endpoint.
  *
  * The namespace parameter is overloaded to accept an array of options
  * that can contain data necessary for various transports if it is used as
  * an array, it MAY contain a namespace value and a soapaction value.  If
  * it is overloaded, the soapaction parameter is ignored and MUST be
  * placed in the options array.  This is done to provide backwards
  * compatibility with current clients, but may be removed in the future.
  * The currently supported values are:<pre>
  *   namespace
  *   soapaction
  *   timeout (HTTP socket timeout)
  *   transfer-encoding (SMTP, Content-Transfer-Encoding: header)
  *   from (SMTP, From: header)
  *   subject (SMTP, Subject: header)
  *   headers (SMTP, hash of extra SMTP headers)
  * </pre>
  *
  * @access public
  *
  * @param string $method           The method to call.
  * @param array $params            The method parameters.
  * @param string|array $namespace  Namespace or hash with options.
  * @param string $soapAction
  *
  * @return mixed  The method result or a SOAP_Fault on error.
  */
 function &call($method, &$params, $namespace = false, $soapAction = false)
 {
     $this->headersIn = null;
     $this->__last_request = null;
     $this->__last_response = null;
     $this->wire = null;
     $this->xml = null;
     $soap_data =& $this->__generate($method, $params, $namespace, $soapAction);
     if (PEAR::isError($soap_data)) {
         $fault =& $this->_raiseSoapFault($soap_data);
         return $fault;
     }
     // __generate() may have changed the endpoint if the WSDL has more
     // than one service, so we need to see if we need to generate a new
     // transport to hook to a different URI.  Since the transport protocol
     // can also change, we need to get an entirely new object.  This could
     // probably be optimized.
     if (!$this->_soap_transport || $this->_endpoint != $this->_soap_transport->url) {
         $this->_soap_transport =& SOAP_Transport::getTransport($this->_endpoint);
         if (PEAR::isError($this->_soap_transport)) {
             $fault =& $this->_soap_transport;
             $this->_soap_transport = null;
             $fault =& $this->_raiseSoapFault($fault);
             return $fault;
         }
     }
     $this->_soap_transport->encoding = $this->_encoding;
     // Send the message.
     $transport_options = array_merge_recursive($this->__proxy_params, $this->__options);
     /*
     echo "<pre>";
     print_r($soap_data);
     exit;
     */
     /*
     xdebug_break();
     file_put_contents('/var/www/html/test_files/soap.txt', $soap_data);
     		echo "<pre>";
     echo htmlentities($soap_data);
     		//print_r($soap_data);
     		exit;
     */
     //file_put_contents('/var/www/html/ddservice/data/soap_templiga_allkiri_htmlescaped.ddoc.txt', $soap_data);
     $this->xml = $this->_soap_transport->send($soap_data, $transport_options);
     // Save the wire information for debugging.
     if ($this->__options['trace'] > 0) {
         $this->__last_request =& $this->_soap_transport->outgoing_payload;
         $this->__last_response =& $this->_soap_transport->incoming_payload;
         $this->wire = $this->__get_wire();
     }
     if ($this->_soap_transport->fault) {
         $fault =& $this->_raiseSoapFault($this->xml);
         return $fault;
     }
     $this->__attachments =& $this->_soap_transport->attachments;
     $this->__result_encoding = $this->_soap_transport->result_encoding;
     if (isset($this->__options['result']) && $this->__options['result'] != 'parse') {
         return $this->xml;
     }
     $result =& $this->__parse($this->xml, $this->__result_encoding, $this->__attachments);
     return $result;
 }