• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

webservice/soap/lib/nusoapmime.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003 $Id: nusoapmime.php 6577 2005-01-27 16:22:48Z smeyer $
00004 
00005 NuSOAP - Web Services Toolkit for PHP
00006 
00007 Copyright (c) 2002 NuSphere Corporation
00008 
00009 This library is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU Lesser General Public
00011 License as published by the Free Software Foundation; either
00012 version 2.1 of the License, or (at your option) any later version.
00013 
00014 This library is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public
00020 License along with this library; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00023 If you have any questions or comments, please email:
00024 
00025 Dietrich Ayala
00026 dietrich@ganx4.com
00027 http://dietrich.ganx4.com/nusoap
00028 
00029 NuSphere Corporation
00030 http://www.nusphere.com
00031 
00032 */
00033 
00034 /*require_once('nusoap.php');*/
00035 /* PEAR Mail_MIME library */
00036 require_once('Mail/mimeDecode.php');
00037 require_once('Mail/mimePart.php');
00038 
00049 class soapclientmime extends soap_client {
00050         var $requestAttachments = array();
00051         var $responseAttachments;
00052         var $mimeContentType;
00053         
00069         function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) {
00070                 if (! $cid) {
00071                         $cid = md5(uniqid(time()));
00072                 }
00073 
00074                 $info['data'] = $data;
00075                 $info['filename'] = $filename;
00076                 $info['contenttype'] = $contenttype;
00077                 $info['cid'] = $cid;
00078                 
00079                 $this->requestAttachments[] = $info;
00080 
00081                 return $cid;
00082         }
00083 
00089         function clearAttachments() {
00090                 $this->requestAttachments = array();
00091         }
00092 
00103         function getAttachments() {
00104                 return $this->responseAttachments;
00105         }
00106 
00114         function getHTTPBody($soapmsg) {
00115                 if (count($this->requestAttachments) > 0) {
00116                         $params['content_type'] = 'multipart/related';
00117                         $mimeMessage =& new Mail_mimePart('', $params);
00118                         unset($params);
00119 
00120                         $params['content_type'] = 'text/xml';
00121                         $params['encoding']     = '8bit';
00122                         $params['charset']      = $this->soap_defencoding;
00123                         $mimeMessage->addSubpart($soapmsg, $params);
00124                         
00125                         foreach ($this->requestAttachments as $att) {
00126                                 unset($params);
00127 
00128                                 $params['content_type'] = $att['contenttype'];
00129                                 $params['encoding']     = 'base64';
00130                                 $params['disposition']  = 'attachment';
00131                                 $params['dfilename']    = $att['filename'];
00132                                 $params['cid']          = $att['cid'];
00133 
00134                                 if ($att['data'] == '' && $att['filename'] <> '') {
00135                                         if ($fd = fopen($att['filename'], 'rb')) {
00136                                                 $data = fread($fd, filesize($att['filename']));
00137                                                 fclose($fd);
00138                                         } else {
00139                                                 $data = '';
00140                                         }
00141                                         $mimeMessage->addSubpart($data, $params);
00142                                 } else {
00143                                         $mimeMessage->addSubpart($att['data'], $params);
00144                                 }
00145                         }
00146 
00147                         $output = $mimeMessage->encode();
00148                         $mimeHeaders = $output['headers'];
00149         
00150                         foreach ($mimeHeaders as $k => $v) {
00151                                 $this->debug("MIME header $k: $v");
00152                                 if (strtolower($k) == 'content-type') {
00153                                         // PHP header() seems to strip leading whitespace starting
00154                                         // the second line, so force everything to one line
00155                                         $this->mimeContentType = str_replace("\r\n", " ", $v);
00156                                 }
00157                         }
00158         
00159                         return $output['body'];
00160                 }
00161 
00162                 return parent::getHTTPBody($soapmsg);
00163         }
00164         
00173         function getHTTPContentType() {
00174                 if (count($this->requestAttachments) > 0) {
00175                         return $this->mimeContentType;
00176                 }
00177                 return parent::getHTTPContentType();
00178         }
00179         
00189         function getHTTPContentTypeCharset() {
00190                 if (count($this->requestAttachments) > 0) {
00191                         return false;
00192                 }
00193                 return parent::getHTTPContentTypeCharset();
00194         }
00195 
00204     function parseResponse($headers, $data) {
00205                 $this->debug('Entering parseResponse() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']);
00206                 $this->responseAttachments = array();
00207                 if (strstr($headers['content-type'], 'multipart/related')) {
00208                         $this->debug('Decode multipart/related');
00209                         $input = '';
00210                         foreach ($headers as $k => $v) {
00211                                 $input .= "$k: $v\r\n";
00212                         }
00213                         $params['input'] = $input . "\r\n" . $data;
00214                         $params['include_bodies'] = true;
00215                         $params['decode_bodies'] = true;
00216                         $params['decode_headers'] = true;
00217                         
00218                         $structure = Mail_mimeDecode::decode($params);
00219 
00220                         foreach ($structure->parts as $part) {
00221                                 if (!isset($part->disposition)) {
00222                                         $this->debug('Have root part of type ' . $part->headers['content-type']);
00223                                         $return = parent::parseResponse($part->headers, $part->body);
00224                                 } else {
00225                                         $this->debug('Have an attachment of type ' . $part->headers['content-type']);
00226                                         $info['data'] = $part->body;
00227                                         $info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : '';
00228                                         $info['contenttype'] = $part->headers['content-type'];
00229                                         $info['cid'] = $part->headers['content-id'];
00230                                         $this->responseAttachments[] = $info;
00231                                 }
00232                         }
00233                 
00234                         if (isset($return)) {
00235                                 return $return;
00236                         }
00237                         
00238                         $this->setError('No root part found in multipart/related content');
00239                         return;
00240                 }
00241                 $this->debug('Not multipart/related');
00242                 return parent::parseResponse($headers, $data);
00243         }
00244 }
00245 ?>

Generated on Fri Dec 13 2013 08:00:21 for ILIAS Release_3_3_x_branch .rev 46803 by  doxygen 1.7.1