You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ra...@apache.org on 2005/05/06 10:22:09 UTC

cvs commit: ws-axis/c/vc/server/apache1_3 Apache1_3Module.dsp

rangika     2005/05/06 01:22:09

  Modified:    c/src/server/apache ApacheTransport.cpp ApacheTransport.h
               c/vc/server/apache1_3 Apache1_3Module.dsp
  Added:       c/src/server/apache AttachmentHelper.cpp AttachmentHelper.h
  Log:
  Added attachments to Apache1.3
  
  Revision  Changes    Path
  1.9       +32 -0     ws-axis/c/src/server/apache/ApacheTransport.cpp
  
  Index: ApacheTransport.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/server/apache/ApacheTransport.cpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ApacheTransport.cpp	7 Mar 2005 03:26:37 -0000	1.8
  +++ ApacheTransport.cpp	6 May 2005 08:22:08 -0000	1.9
  @@ -166,6 +166,18 @@
       len_read = ap_get_client_block ((request_rec*) m_pContext, pBuffer, *piSize);
       ap_reset_timeout ((request_rec*) m_pContext);
       *piSize = len_read;
  +
  +    	if (strstr(pBuffer, "Content-Id")) {
  +		pAttachmentHelper = new AttachmentHelper();
  +		char *pAttachBuffer = (char*)malloc(1000);
  +		char *mimeBoundary = (char*)malloc(1000);		
  +
  +		pAttachmentHelper->extract_Attachment(pBuffer);		
  +		pAttachmentHelper->extract_SOAPMimeHeaders(pBuffer);	
  +		pAttachmentHelper->extract_Soap(pBuffer);
  +				
  +	}
  +
       if (len_read < nBufSize)
       {
           pBuffer[len_read] = '\0';
  @@ -301,3 +313,23 @@
               return AXIS_HTTP_UNSUPPORTED;
       }
   }
  +
  +ISoapAttachment*  ApacheTransport::getAttachment(const char* pcAttachmentid)
  +{		
  +	ISoapAttachment* pAttch = pAttachmentHelper->getAttachment(pcAttachmentid);
  +	return pAttch;
  +//	return NULL;
  +};
  +
  +char* ApacheTransport::getIncomingSOAPMimeHeaders()
  +{
  +	return pAttachmentHelper->getIncomingSOAPMimeHeaders();
  +//	return NULL;
  +}
  +
  +ISoapAttachment**  ApacheTransport::getAllAttachments(int *pAttchArraySize)
  +{		
  +	ISoapAttachment** pAttachments = pAttachmentHelper->getAllAttachments(pAttchArraySize);
  +	return pAttachments;
  +//	return NULL;
  +};
  \ No newline at end of file
  
  
  
  1.15      +8 -4      ws-axis/c/src/server/apache/ApacheTransport.h
  
  Index: ApacheTransport.h
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/server/apache/ApacheTransport.h,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ApacheTransport.h	5 May 2005 15:46:57 -0000	1.14
  +++ ApacheTransport.h	6 May 2005 08:22:08 -0000	1.15
  @@ -45,6 +45,8 @@
   
   #include "../../transport/SOAPTransport.h"
   #include <string.h>
  +#include "AttachmentHelper.h"
  +#include <axis/ISoapAttachment.hpp>
   
   AXIS_CPP_NAMESPACE_USE
   
  @@ -64,19 +66,20 @@
       const char* getTransportProperty(AXIS_TRANSPORT_INFORMATION_TYPE eType);
       int setTransportProperty(const char* pcKey, const char* pcValue);
       const char* getTransportProperty(const char* pcKey, bool response=true);
  -	void setAttachment(const char* pcAttachmentid, const char* pcAttachment){};
  +    void setAttachment(const char* pcAttachmentid, const char* pcAttachment){};
  +	
   	
   	/**
   	 * fixing build breaks: Start
   	 */
   	
   	// hawkeye: This should return something ? Asking on mailing list what !
  -	char* getIncomingSOAPMimeHeaders(){return NULL;}
  +	char* getIncomingSOAPMimeHeaders();
   	
   	// hawkeyeThis used to return "value" but now fails because of the changed signature
   	// What should it be ?
  -	ISoapAttachment* getAttachment(const char* pcAttachmentid){return NULL;};
  -    ISoapAttachment** getAllAttachments(int *pAttchArraySize){return NULL;};
  +	ISoapAttachment* getAttachment(const char* pcAttachmentid);
  +    ISoapAttachment** getAllAttachments(int *pAttchArraySize);
   
   	/** 
   	 * end of fixing build breaks
  @@ -99,6 +102,7 @@
       void setTimeout(const long lSeconds) {};
   
   private:
  +    AttachmentHelper* pAttachmentHelper;
   	void* m_pContext;
       bool m_bHeadersSent;
   #ifndef CHUNCKED_DATA_SUPPORTED
  
  
  
  1.1                  ws-axis/c/src/server/apache/AttachmentHelper.cpp
  
  Index: AttachmentHelper.cpp
  ===================================================================
  // Copyright 2003-2004 The Apache Software Foundation.
  // 
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  // 
  //        http://www.apache.org/licenses/LICENSE-2.0
  // 
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  // AttachmentHelper.cpp: implementation of the AttachmentHelper class.
  //
  //////////////////////////////////////////////////////////////////////
  
  #include "AttachmentHelper.h"
  #include "../../common/AxisUtils.h"
  #include <string>
  
  using namespace std;
  
  //////////////////////////////////////////////////////////////////////
  // Construction/Destruction
  //////////////////////////////////////////////////////////////////////
  
  AXIS_CPP_NAMESPACE_USE
  
  AttachmentHelper::AttachmentHelper()
  {
  }
  
  AttachmentHelper::~AttachmentHelper()
  {
  }
  
  void AttachmentHelper::extract_Attachment(char *pBuffer)
  {		
  	string Soap_Message = pBuffer;
  	int boundary1 = Soap_Message.find("</soapenv:Envelope>");
  	int boundary2 = boundary1 + strlen("</soapenv:Envelope>") + 2;
  	int boundary3 = Soap_Message.find("Content-Type:", boundary2);
  	int length = (boundary3-2) - boundary2;
  	string boundary = Soap_Message.substr(boundary2, length);
  	bool blnContinue = true;
  	bool blnFirstTime = true;
  	int end = 0;
  	int x =0;
  
  	while (blnContinue)
      {
          SoapAttachment* pSoapAttachment= new SoapAttachment();
  		int start =0;
  
  	if (blnFirstTime) {
  			start = Soap_Message.find("Content-Type", boundary3);
  			blnFirstTime = false;                 
  
   		} else {
  			start = Soap_Message.find("Content-Type", end);
  		}
  
  		if (start == string::npos)
  			break;		
  		int start2 = Soap_Message.find(">", start+strlen("Content-Type"));
  		int headerLength = (start2+1)  - start;
  		string header = Soap_Message.substr (start, headerLength);
  		end = Soap_Message.find(boundary, start);
  		int length2 = (end- 4) - (start2+5) ;
  		
  		string attachment = Soap_Message.substr(start2+5, length2);
  		const char* attach = attachment.c_str ();
  
          int iEncodingType= -1;
                	
          const char * strContentType1 ="Content-Type";
  		extract_info(header,strContentType1,pSoapAttachment, iEncodingType);
  		const char * strContentType2 ="Content-Transfer-Encoding";
  		extract_info(header,strContentType2,pSoapAttachment, iEncodingType);
  		const char * strContentType3 ="Content-Id";
  		extract_info(header,strContentType3,pSoapAttachment, iEncodingType);		
  
          /*Extracting and adding the attch body*/
  
          if (iEncodingType==AXIS_BASE64) {
              xsd__base64Binary*  base64_attachment = new xsd__base64Binary();
              base64_attachment = AxisUtils::decodeFromBase64Binary(attach);		
  		    pSoapAttachment->addBody(base64_attachment);
          } else if (iEncodingType==AXIS_BINARY) {
              //if it is binary            
               char* binaryBody = new char[attachment.length() + 1];
               strcpy(binaryBody, attachment.c_str());
               pSoapAttachment->addBody(binaryBody);
  
          }
  
  		x++;
  	}
  }
  
  void AttachmentHelper::extract_Soap(char *pBuffer)
  {   
     string  s = pBuffer;
     int i = s.find("<soapenv");
     int z = s.find("</soapenv:Envelope>");
     int length_soap = strlen("</soapenv:Envelope>");
     int length = (z - i) + length_soap;
     string extracted_message = s.substr(i,length);	
     strcpy(pBuffer, extracted_message.c_str());		
  }
  
  void AttachmentHelper::extract_SOAPMimeHeaders(char *pBuffer)
  {
  	string Soap_Message = pBuffer;
  	int mime_Boundary = Soap_Message.find("Content", 0);
  	int mime_Headers = Soap_Message.find (">", mime_Boundary);
  	int mime_Length = (mime_Headers +1) - mime_Boundary;
  	string mime_Part = Soap_Message.substr(mime_Boundary, mime_Length);
  	pMime = (char*)malloc(mime_Part.size());
  	strcpy(pMime, mime_Part.c_str ());
  }
  
  void AttachmentHelper::extract_info(string header, const char *label, SoapAttachment *pSoapAttachment, int& iEncodingType)
  {
    int ContentTypeLabel = header.find(label);    
    int startValue = ContentTypeLabel+strlen(label);
    if (strcmp(label,"Content-Id")==0) 
    {
  	 int endValue = header.find (">" , startValue);
  	 int lengthId = (endValue) - (startValue + 3);
  	 string ContentValue = header.substr (startValue+3, lengthId);
  	 pSoapAttachment->addHeader(label,ContentValue.c_str());
  	 mymap[ContentValue.c_str()] = pSoapAttachment;
    }
    else 
    {
      int endValue = header.find ("Content-", startValue);
      int length = endValue - (startValue + 2);
      string ContentValue = header.substr (startValue + 2, length-2);
  
      if (strcmp(label, "Content-Transfer-Encoding") ==0) {
          if(strcmp (ContentValue.c_str(), "base64")==0) {
              iEncodingType = AXIS_BASE64;
          } else if(strcmp (ContentValue.c_str(), "binary")==0) {
              iEncodingType = AXIS_BINARY;
          }
      }
  
      pSoapAttachment->addHeader(label,ContentValue.c_str());
      }
  }
  
  ISoapAttachment* AttachmentHelper::getAttachment(const char *pcAttchId)
  {
  	if (mymap.find(pcAttchId) == mymap.end())
  		return NULL;
  	else
  	    return mymap[pcAttchId];	
  }
  
  char* AttachmentHelper::getIncomingSOAPMimeHeaders()
  {
  	return pMime;
  }
  
  ISoapAttachment** AttachmentHelper::getAllAttachments(int *pAttchArraySize)
  {
  	
  	ISoapAttachment** attachArray = (ISoapAttachment**)new SoapAttachment*[mymap.size()];
      //SoapAttachment** attachArray = new SoapAttachment*[mymap.size()];
      map<const string, ISoapAttachment*>::iterator itCurrMap= mymap.begin();
  
       int i = 0;
      while(itCurrMap != mymap.end())
      {        
          
          attachArray[i] = (*itCurrMap).second;
  
          itCurrMap++; 
          i++;
      }      
  
      *pAttchArraySize = i;
  
      return attachArray;
     
       //return mymap;	
  }
  
  
  1.1                  ws-axis/c/src/server/apache/AttachmentHelper.h
  
  Index: AttachmentHelper.h
  ===================================================================
  // Copyright 2003-2004 The Apache Software Foundation.
  // (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved
  // 
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  // 
  //        http://www.apache.org/licenses/LICENSE-2.0
  // 
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  // AttachmentHelper.h: interface for the AttachmentHelper class.
  //
  //////////////////////////////////////////////////////////////////////
  
  #if !defined(AFX_ATTACHMENTHELPER_H__F133843A_6A8F_4443_9DCC_850C7DEEFB7E__INCLUDED_)
  #define AFX_ATTACHMENTHELPER_H__F133843A_6A8F_4443_9DCC_850C7DEEFB7E__INCLUDED_
  
  #if _MSC_VER > 1000
  #pragma once
  #endif // _MSC_VER > 1000
  
  #ifdef strtoul
  #undef strtoul
  #endif
  #define strtoul strtoul
  
  #pragma warning( disable : 4786 )
  
  #include <string>
  #include <map>
  #include <axis/ISoapAttachment.hpp>
  #include "../../soap/SoapAttachment.hpp"
  
  using namespace std;
  AXIS_CPP_NAMESPACE_USE
  
  /*
  struct ltstr
  {
           //bool operator()(const string* s1, const string* s2) const
  		 bool operator()(const char* s1, const char* s2) const
           {
            //return strcmp(s1->c_str() , s2->c_str()) < 0;
  		  return strcmp(s1 , s2) < 0;
           }
  };
  */
  
  class AttachmentHelper  
  {
  private:
  	map<const string, ISoapAttachment*> mymap;
  	char* pMime;
  public:
  	char* getIncomingSOAPMimeHeaders();
  	ISoapAttachment* getAttachment (const char* pcAttchId);
      ISoapAttachment** getAllAttachments(int *pAttchArraySize);
  	void extract_info(string header,const char* label,SoapAttachment* pSoapAttachment, int& iEncodingType);
  	void extract_SOAPMimeHeaders(char* pBuffer);
  	void extract_Soap (char* pBuffer);
  	void extract_Attachment (char* pBuffer);
  	AttachmentHelper();
  	virtual ~AttachmentHelper();
  };
  
  #endif // !defined(AFX_ATTACHMENTHELPER_H__F133843A_6A8F_4443_9DCC_850C7DEEFB7E__INCLUDED_)
  
  
  
  1.11      +8 -0      ws-axis/c/vc/server/apache1_3/Apache1_3Module.dsp
  
  Index: Apache1_3Module.dsp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/vc/server/apache1_3/Apache1_3Module.dsp,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Apache1_3Module.dsp	15 Nov 2004 06:17:23 -0000	1.10
  +++ Apache1_3Module.dsp	6 May 2005 08:22:09 -0000	1.11
  @@ -103,6 +103,10 @@
   # End Source File
   # Begin Source File
   
  +SOURCE=..\..\..\src\server\apache\AttachmentHelper.cpp
  +# End Source File
  +# Begin Source File
  +
   SOURCE=..\..\..\src\server\apache\mod_axis.cpp
   # End Source File
   # End Group
  @@ -113,6 +117,10 @@
   
   SOURCE=..\..\..\src\server\apache\ApacheTransport.h
   # End Source File
  +# Begin Source File
  +
  +SOURCE=..\..\..\src\server\apache\AttachmentHelper.h
  +# End Source File
   # End Group
   # Begin Group "Resource Files"