• Main Page
  • Related Pages
  • Modules
  • 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 9095 2005-11-08 13:17:14Z 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 
00053 class soapclientmime extends soap_client {
00054         var $requestAttachments = array();
00055         var $responseAttachments;
00056         var $mimeContentType;
00057         
00073         function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) {
00074                 if (! $cid) {
00075                         $cid = md5(uniqid(time()));
00076                 }
00077 
00078                 $info['data'] = $data;
00079                 $info['filename'] = $filename;
00080                 $info['contenttype'] = $contenttype;
00081                 $info['cid'] = $cid;
00082                 
00083                 $this->requestAttachments[] = $info;
00084 
00085                 return $cid;
00086         }
00087 
00093         function clearAttachments() {
00094                 $this->requestAttachments = array();
00095         }
00096 
00107         function getAttachments() {
00108                 return $this->responseAttachments;
00109         }
00110 
00118         function getHTTPBody($soapmsg) {
00119                 if (count($this->requestAttachments) > 0) {
00120                         $params['content_type'] = 'multipart/related';
00121                         $mimeMessage =& new Mail_mimePart('', $params);
00122                         unset($params);
00123 
00124                         $params['content_type'] = 'text/xml';
00125                         $params['encoding']     = '8bit';
00126                         $params['charset']      = $this->soap_defencoding;
00127                         $mimeMessage->addSubpart($soapmsg, $params);
00128                         
00129                         foreach ($this->requestAttachments as $att) {
00130                                 unset($params);
00131 
00132                                 $params['content_type'] = $att['contenttype'];
00133                                 $params['encoding']     = 'base64';
00134                                 $params['disposition']  = 'attachment';
00135                                 $params['dfilename']    = $att['filename'];
00136                                 $params['cid']          = $att['cid'];
00137 
00138                                 if ($att['data'] == '' && $att['filename'] <> '') {
00139                                         if ($fd = fopen($att['filename'], 'rb')) {
00140                                                 $data = fread($fd, filesize($att['filename']));
00141                                                 fclose($fd);
00142                                         } else {
00143                                                 $data = '';
00144                                         }
00145                                         $mimeMessage->addSubpart($data, $params);
00146                                 } else {
00147                                         $mimeMessage->addSubpart($att['data'], $params);
00148                                 }
00149                         }
00150 
00151                         $output = $mimeMessage->encode();
00152                         $mimeHeaders = $output['headers'];
00153         
00154                         foreach ($mimeHeaders as $k => $v) {
00155                                 $this->debug("MIME header $k: $v");
00156                                 if (strtolower($k) == 'content-type') {
00157                                         // PHP header() seems to strip leading whitespace starting
00158                                         // the second line, so force everything to one line
00159                                         $this->mimeContentType = str_replace("\r\n", " ", $v);
00160                                 }
00161                         }
00162         
00163                         return $output['body'];
00164                 }
00165 
00166                 return parent::getHTTPBody($soapmsg);
00167         }
00168         
00177         function getHTTPContentType() {
00178                 if (count($this->requestAttachments) > 0) {
00179                         return $this->mimeContentType;
00180                 }
00181                 return parent::getHTTPContentType();
00182         }
00183         
00193         function getHTTPContentTypeCharset() {
00194                 if (count($this->requestAttachments) > 0) {
00195                         return false;
00196                 }
00197                 return parent::getHTTPContentTypeCharset();
00198         }
00199 
00208     function parseResponse($headers, $data) {
00209                 $this->debug('Entering parseResponse() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']);
00210                 $this->responseAttachments = array();
00211                 if (strstr($headers['content-type'], 'multipart/related')) {
00212                         $this->debug('Decode multipart/related');
00213                         $input = '';
00214                         foreach ($headers as $k => $v) {
00215                                 $input .= "$k: $v\r\n";
00216                         }
00217                         $params['input'] = $input . "\r\n" . $data;
00218                         $params['include_bodies'] = true;
00219                         $params['decode_bodies'] = true;
00220                         $params['decode_headers'] = true;
00221                         
00222                         $structure = Mail_mimeDecode::decode($params);
00223 
00224                         foreach ($structure->parts as $part) {
00225                                 if (!isset($part->disposition)) {
00226                                         $this->debug('Have root part of type ' . $part->headers['content-type']);
00227                                         $return = parent::parseResponse($part->headers, $part->body);
00228                                 } else {
00229                                         $this->debug('Have an attachment of type ' . $part->headers['content-type']);
00230                                         $info['data'] = $part->body;
00231                                         $info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : '';
00232                                         $info['contenttype'] = $part->headers['content-type'];
00233                                         $info['cid'] = $part->headers['content-id'];
00234                                         $this->responseAttachments[] = $info;
00235                                 }
00236                         }
00237                 
00238                         if (isset($return)) {
00239                                 return $return;
00240                         }
00241                         
00242                         $this->setError('No root part found in multipart/related content');
00243                         return;
00244                 }
00245                 $this->debug('Not multipart/related');
00246                 return parent::parseResponse($headers, $data);
00247         }
00248 }
00249 ?>

Generated on Fri Dec 13 2013 13:52:17 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1