You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ha...@apache.org on 2006/01/11 11:37:05 UTC

svn commit: r367997 - in /webservices/axis/trunk/c: include/axis/client/Stub.hpp src/cbindings/client/StubC.cpp src/engine/client/Stub.cpp src/transport/SOAPTransport.h src/transport/axis3/HTTPTransport.cpp src/transport/axis3/HTTPTransport.hpp

Author: hawkeye
Date: Wed Jan 11 02:36:55 2006
New Revision: 367997

URL: http://svn.apache.org/viewcvs?rev=367997&view=rev
Log:
Added new Cookie function. Can now delete and add Cookies using transport properties API.

Modified:
    webservices/axis/trunk/c/include/axis/client/Stub.hpp
    webservices/axis/trunk/c/src/cbindings/client/StubC.cpp
    webservices/axis/trunk/c/src/engine/client/Stub.cpp
    webservices/axis/trunk/c/src/transport/SOAPTransport.h
    webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.cpp
    webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.hpp

Modified: webservices/axis/trunk/c/include/axis/client/Stub.hpp
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/include/axis/client/Stub.hpp?rev=367997&r1=367996&r2=367997&view=diff
==============================================================================
--- webservices/axis/trunk/c/include/axis/client/Stub.hpp (original)
+++ webservices/axis/trunk/c/include/axis/client/Stub.hpp Wed Jan 11 02:36:55 2006
@@ -83,133 +83,6 @@
 
     void AXISCALL setEndPoint(const char *pcEndPointURI);
 
-  /**
-    * @deprecated To fix spelling mistake.
-    *
-    * Set transport property.
-    *
-    * Handling the semantics of the headers is up to the user.
-    * The user has to make sure that the key:value paires passed to this method 
-    * would make sense at transport level.
-    * The Stub class does not validate the key value paires to see if the properties
-    * make sense to the undelying transport.
-    * 
-    * Some example transport properties:
-    * <BR>  For HTTP: "Accept-Language: da, en-gb;q=0.8, en;q=0.7"
-    * <BR>  For SMTP: "Reply-To: user@apache.org" 
-    * 
-    * @param pcKey Header name e.g. "Accept-Language". 
-    *              Note that the key is not tested for uniqueness.
-    *              One can set several values to the same key and they all will
-    *              appear in the outgoing transport header.
-    *              e.g. If the method is called twise with (k,v1) and (k,v2) 
-    *              both k:v1 and k:v2 will appear in transport header as 
-    *              seperate properties.
-    * @param pcValue Header value e.g. "da, en-gb;q=0.8, en;q=0.7"
-    */
-    void AXISCALL setTrasportProperty(const char *pcKey, const char *pcValue) {};
-
-  /**
-    * @deprecated To fix spelling mistake.
-    *
-    * Iterator initiatior for transport property keys
-    *
-    * This method must be called first to initiate access to the list of 
-    * transport property keys.
-    *
-    * @return First transport property key. If there are no transport 
-    * properties set, returns NULL.
-    */
-    const char* getFirstTrasportPropertyKey() {return NULL;};
-
-
-  /**
-    * @deprecated To fix spelling mistake.
-    *  
-    * Iterator for transport property keys
-    *
-    * getFirstTransportPropertyKey() method must have been called at least once
-    * before this method is called. If not behaviour is undefined.
-    *
-    * This method advances the iterator by one position.
-    * Repeated calls always retuen the next value.
-    *
-    * @return Next transport property key. If there are no transport 
-    * properties set or if iterator is at the end of the list, returns NULL.
-    */
-    const char* getNextTrasportPropertyKey() {return NULL;};
-
-  /**
-    * @deprecated To fix spelling mistake.
-    *  
-    * Accessor for transport property keys.
-    *
-    * This method gives access to the key corresponding to the transport key
-    * currently being pointed by transport property key iterator.
-    *
-    * getFirstTransportPropertyKey() method must have been called at least once
-    * before this method is called. If not behaviour is undefined.
-    *
-    * This method does not advance the iterator.
-    * Repeated calls always retuen the same key unless 
-    * getNextTransportPropertyKey() is called in between.
-    *
-    * @return Current transport property key. If there are no transport 
-    * properties set or if iterator is at the end of the list, returns NULL.
-    */
-    const char* getCurrentTrasportPropertyKey() {return NULL;};
-    
-  /**
-    * @deprecated To fix spelling mistake.
-    *  
-    * Accessor for transport property values.
-    *
-    * This method gives access to the value corresponding to the transport key
-    * currently being pointed by transport property key iterator.
-    * As keys and values are treated as paires, access to the value field is 
-    * based on the access to the key field.
-    *
-    * getFirstTransportPropertyKey() method must have been called at least once
-    * before this method is called. If not behaviour is undefined.
-    *
-    * This method does not advance the iterator.
-    * Repeated calls always retuen the same value unless 
-    * getNextTransportPropertyKey() is called in between.
-    *
-    * @return Current transport property value. If there are no transport 
-    * properties set or if iterator is at the end of the list, returns NULL.
-    */
-    const char* getCurrentTrasportPropertyValue() {return NULL;};
-
-  /**
-    * @deprecated To fix spelling mistake.
-    *  
-    * Deletes the transport property key:value pair currently pointed to by 
-    * the iterator.
-    */
-    void deleteCurrentTrasportProperty(){};
-
-  /**
-    * @deprecated To fix spelling mistake.
-    *  
-    * Deletes the given occerance of the transport property key:value pair
-    * corresponding to the given key.
-    *
-    * This method does not advance the iterator in line with the deletes done.
-    * In case you want to access the transport properties after using this
-    * method, it is advisable to reinitialize the iterator using
-    * getFirstTransportPropertyKey();
-    * However you can use this method despite where the iterator is 
-    * pointing currently.
-    *
-    * @param pcKey Key of the transport property key:value pair to be deleted
-    *              If the given key is not set currently, nothing will happen.
-    * @param uiOccurance Which occerance of the key to be deleted, because 
-    *                    there can be multiple values for the same key. 
-    *                    Default is to delete the first occurance.
-    *                    Count starts from 1.
-    */
-    void deleteTrasportProperty(char* pcKey, unsigned int uiOccurance = 1){};
 
   /**
     * Set transport property.
@@ -222,15 +95,17 @@
     *
     * Some example transport properties:
     * <BR>  For HTTP: "Accept-Language: da, en-gb;q=0.8, en;q=0.7"
+    * <BR>  For HTTP: "Cookie: sessiontoken=123345456;"
     * <BR>  For SMTP: "Reply-To: user@apache.org"
     *
     * @param pcKey Header name e.g. "Accept-Language".
     *              Note that the key is not tested for uniqueness.
     *              One can set several values to the same key and they all will
-    *              appear in the outgoing transport header.
+    *              appear in the outgoing transport header. 
     *              e.g. If the method is called twise with (k,v1) and (k,v2)
     *              both k:v1 and k:v2 will appear in transport header as
     *              seperate properties.
+    *              The exception to this is "Cookie" where multiple cookie values will only result in one "Cookie:" header being sent as is correct for HTTP.
     * @param pcValue Header value e.g. "da, en-gb;q=0.8, en;q=0.7"
     */
     void AXISCALL setTransportProperty(const char *pcKey, const char *pcValue);
@@ -251,12 +126,16 @@
     * Iterator initiatior for transport property keys
     *
     * This method must be called first to initiate access to the list of 
-    * transport property keys.
+    * transport property keys. If you initialise e.g. response then ensure
+    * that you call this method for outgoing message too if you want the
+    * outgoing message in future calls.
+    * 
     *
+    * @param response  whether the response or outgoing message is being used.
     * @return First transport property key. If there are no transport 
     * properties set, returns NULL.
     */
-    const char* getFirstTransportPropertyKey();
+    const char* getFirstTransportPropertyKey(bool response=true);
 
 
   /**
@@ -268,10 +147,11 @@
     * This method advances the iterator by one position.
     * Repeated calls always retuen the next value.
     *
+    * @param whether the response or outgoing message should be used
     * @return Next transport property key. If there are no transport 
     * properties set or if iterator is at the end of the list, returns NULL.
     */
-    const char* getNextTransportPropertyKey();
+    const char* getNextTransportPropertyKey(bool response=true);
 
   /**
     * Accessor for transport property keys.
@@ -296,26 +176,29 @@
     *
     * This method gives access to the value corresponding to the transport key
     * currently being pointed by transport property key iterator.
-    * As keys and values are treated as paires, access to the value field is 
+    * As keys and values are treated as pairs, access to the value field is 
     * based on the access to the key field.
     *
     * getFirstTransportPropertyKey() method must have been called at least once
-    * before this method is called. If not behaviour is undefined.
-    *
+    * before this method is called. It must be called with the same "response"
+    * value as used here. If not behaviour is undefined. 
+    * 
     * This method does not advance the iterator.
     * Repeated calls always retuen the same value unless 
     * getNextTransportPropertyKey() is called in between.
     *
+    * @param whether the response or outgoing message should be used
     * @return Current transport property value. If there are no transport 
     * properties set or if iterator is at the end of the list, returns NULL.
     */
-    const char* getCurrentTransportPropertyValue();
+    const char* getCurrentTransportPropertyValue(bool response=true);
 
   /**
     * Deletes the transport property key:value pair currently pointed to by 
     * the iterator.
+    * @param true if it's the response property or false for the request
     */
-    void deleteCurrentTransportProperty();
+    void deleteCurrentTransportProperty(bool response=true);
 
   /**
     * Deletes the given occerance of the transport property key:value pair
@@ -327,6 +210,9 @@
     * getFirstTransportPropertyKey();
     * However you can use this method despite where the iterator is 
     * pointing currently.
+    * 
+    * NOTE: This method is used to delete individual cookies e.g. deleteTransportProperty("myCookie") will delete the cookie "myCookie" only.
+    * This method can also be used to delete all Cookies by doing deleteTransportProperty("Cookie").
     *
     * @param pcKey Key of the transport property key:value pair to be deleted
     *              If the given key is not set currently, nothing will happen.

Modified: webservices/axis/trunk/c/src/cbindings/client/StubC.cpp
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/src/cbindings/client/StubC.cpp?rev=367997&r1=367996&r2=367997&view=diff
==============================================================================
--- webservices/axis/trunk/c/src/cbindings/client/StubC.cpp (original)
+++ webservices/axis/trunk/c/src/cbindings/client/StubC.cpp Wed Jan 11 02:36:55 2006
@@ -64,14 +64,14 @@
 	return s->getTransportProperty(key, (bool)(response !=0 ));
 }
 
-AXISC_STORAGE_CLASS_INFO const char * axiscGetFirstTransportPropertyKey(AXISCHANDLE stub) {
+AXISC_STORAGE_CLASS_INFO const char * axiscGetFirstTransportPropertyKey(AXISCHANDLE stub, AxiscBool response) {
 	Stub *s = (Stub*)stub;
-	return s->getFirstTransportPropertyKey();
+	return s->getFirstTransportPropertyKey( (bool)(response!=0));
 }
 
-AXISC_STORAGE_CLASS_INFO const char * axiscGetNextTransportPropertyKey(AXISCHANDLE stub) {
+AXISC_STORAGE_CLASS_INFO const char * axiscGetNextTransportPropertyKey(AXISCHANDLE stub, AxiscBool response) {
 	Stub *s = (Stub*)stub;
-	return s->getNextTransportPropertyKey();
+	return s->getNextTransportPropertyKey((bool)(response!=0));
 }
 
 AXISC_STORAGE_CLASS_INFO const char * axiscGetCurrentTransportPropertyKey(AXISCHANDLE stub) {
@@ -79,14 +79,14 @@
 	return s->getCurrentTransportPropertyKey();
 }
 
-AXISC_STORAGE_CLASS_INFO const char * axiscGetCurrentTransportPropertyValue(AXISCHANDLE stub) {
+AXISC_STORAGE_CLASS_INFO const char * axiscGetCurrentTransportPropertyValue(AXISCHANDLE stub, AxiscBool response) {
 	Stub *s = (Stub*)stub;
-	return s->getCurrentTransportPropertyValue();
+	return s->getCurrentTransportPropertyValue((bool)(response!=0));
 }
 
-AXISC_STORAGE_CLASS_INFO void axiscDeleteCurrentTransportProperty(AXISCHANDLE stub) {
+AXISC_STORAGE_CLASS_INFO void axiscDeleteCurrentTransportProperty(AXISCHANDLE stub, AxiscBool response) {
 	Stub *s = (Stub*)stub;
-	s->deleteCurrentTransportProperty();
+	s->deleteCurrentTransportProperty((bool)(response!=0));
 }
 
 AXISC_STORAGE_CLASS_INFO void axiscDeleteTransportProperty(AXISCHANDLE stub, char * pcKey, 

Modified: webservices/axis/trunk/c/src/engine/client/Stub.cpp
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/src/engine/client/Stub.cpp?rev=367997&r1=367996&r2=367997&view=diff
==============================================================================
--- webservices/axis/trunk/c/src/engine/client/Stub.cpp (original)
+++ webservices/axis/trunk/c/src/engine/client/Stub.cpp Wed Jan 11 02:36:55 2006
@@ -150,19 +150,19 @@
 }
 
 const char *
-Stub::getFirstTransportPropertyKey ()
+Stub::getFirstTransportPropertyKey (bool response)
 {
     if (m_pTransport)
-	return m_pTransport->getFirstTransportPropertyKey ();
+	return m_pTransport->getFirstTransportPropertyKey (response);
     else
 	return NULL;
 }
 
 const char *
-Stub::getNextTransportPropertyKey ()
+Stub::getNextTransportPropertyKey (bool response)
 {
     if (m_pTransport)
-	return m_pTransport->getNextTransportPropertyKey ();
+	return m_pTransport->getNextTransportPropertyKey (response);
     else
 	return NULL;
 }
@@ -177,19 +177,19 @@
 }
 
 const char *
-Stub::getCurrentTransportPropertyValue ()
+Stub::getCurrentTransportPropertyValue (bool response)
 {
     if (m_pTransport)
-	return m_pTransport->getCurrentTransportPropertyValue ();
+	return m_pTransport->getCurrentTransportPropertyValue (response);
     else
 	return NULL;
 }
 
 void
-Stub::deleteCurrentTransportProperty ()
+Stub::deleteCurrentTransportProperty (bool response)
 {
     if (m_pTransport)
-	m_pTransport->deleteCurrentTransportProperty ();
+	m_pTransport->deleteCurrentTransportProperty (response);
 }
 
 void

Modified: webservices/axis/trunk/c/src/transport/SOAPTransport.h
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/src/transport/SOAPTransport.h?rev=367997&r1=367996&r2=367997&view=diff
==============================================================================
--- webservices/axis/trunk/c/src/transport/SOAPTransport.h (original)
+++ webservices/axis/trunk/c/src/transport/SOAPTransport.h Wed Jan 11 02:36:55 2006
@@ -257,12 +257,15 @@
      * @brief Gets any transport property in the arrived message
      *
      * @param pcKey The key of the transport property to get.
-	 * @param response gets a property from the response message when true and
-	 *                 from the send message when false
+   * @param response gets a property from the response message when true and
+     *                 from the send message when false
      * @return Value of the transport property if available. Returns null
      *         if unavailable.
+     * NOTE: If there are multiple properties with the same name then only the first one in the message
+     * will be returned - please use getTransportProperties if you want all properties.
      */
     virtual const char* getTransportProperty(const char* pcKey, bool response=true)=0;
+
     /**
      * Sets a SOAP attachment to be sent with outgoing message. This
      * attachment is usually the base64 or hex encoded character buffer
@@ -401,11 +404,12 @@
     *
     * This method must be called first to initiate access to the list of 
     * transport property keys.
-    *
+    * 
+    * @param response - whether this is the response headers or not
     * @return First transport property key. If there are no transport 
     * properties set, returns NULL.
     */
-    virtual const char* getFirstTransportPropertyKey() { return 0; };
+    virtual const char* getFirstTransportPropertyKey(bool response=true) { return 0; };
 
   /**
     * Iterator for transport property keys
@@ -416,10 +420,11 @@
     * This method advances the iterator by one position.
     * Repeated calls always retuen the next value.
     *
+    * @param response get the response message property or the sent message property
     * @return Next transport property key. If there are no transport 
     * properties set or if iterator is at the end of the list, returns NULL.
     */
-    virtual const char* getNextTransportPropertyKey() { return 0; };
+    virtual const char* getNextTransportPropertyKey(bool response=true) { return 0; };
 
   /**
     * Accessor for transport property keys.
@@ -454,16 +459,18 @@
     * Repeated calls always retuen the same value unless 
     * getNextTransportPropertyKey() is called in between.
     *
+    * @param response whether to get the property value from the response or outgoing message
     * @return Current transport property value. If there are no transport 
     * properties set or if iterator is at the end of the list, returns NULL.
     */
-    virtual const char* getCurrentTransportPropertyValue() { return 0; };
+    virtual const char* getCurrentTransportPropertyValue(bool response=true) { return 0; };
 
   /**
     * Deletes the transport property key:value pair currently pointed to by 
     * the iterator.
+    * @param response whether to delete the response property or request property.
     */
-    virtual void deleteCurrentTransportProperty() {};
+    virtual void deleteCurrentTransportProperty(bool response=true) {};
 
   /**
     * Deletes the given occerance of the transport property key:value pair

Modified: webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.cpp
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.cpp?rev=367997&r1=367996&r2=367997&view=diff
==============================================================================
--- webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.cpp (original)
+++ webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.cpp Wed Jan 11 02:36:55 2006
@@ -29,7 +29,8 @@
 #include "../../platforms/PlatformAutoSense.hpp"
 
 #include <stdio.h>
-#include <iostream>
+// You can uncommment thisl line if you want any debug putting to stdio but PLEASE ensure you comment it out again before releasing.
+// #include <iostream>
 
 // =================================================================
 // In order to parse the HTTP protocol data on an ebcdic system, we
@@ -90,6 +91,7 @@
     m_pChannelFactory = new ChannelFactory();
     m_bMimeTrue = false;
     m_viCurrentHeader = m_vHTTPHeaders.begin();
+    m_viCurrentResponseHeader = m_vResponseHTTPHeaders.begin();
 	m_pszRxBuffer = new char [BUF_SIZE];
 #ifdef WIN32
 	m_lChannelTimeout = 10;
@@ -338,11 +340,16 @@
     // Empty the bytes to send string.
 	m_strBytesToSend = "";
 	m_strHeaderBytesToSend = "";
+ 
+    // Also empty the response headers as there aren't any yet until the response comes back !
+    m_vResponseHTTPHeaders.clear();
+    // TODO: Possible memory leak here - does the clear op clean out the memory too?
+    
 
 	return TRANSPORT_FINISHED;
 }
 
-/* HTTPTransport::getHTTPHeaders() Called to retreive the current HTTP header
+/* HTTPTransport::getHTTPHeaders() Called to retrieve the current HTTP header
  * information block that will preceed the SOAP message.
  *
  * @return const char* Pointer to a NULL terminated character string containing
@@ -389,31 +396,58 @@
 	if (!foundCT)
 		m_strHeaderBytesToSend += AXIS_CONTENT_TYPE ": text/xml; charset=UTF-8\r\n";
 
-    // Set other HTTP headers
+    // Set other HTTP headers but not cookies as they are put in afterwards.
     for (unsigned int i = 0; i < m_vHTTPHeaders.size (); i++)
     {
-		m_strHeaderBytesToSend += m_vHTTPHeaders[i].first;
-		m_strHeaderBytesToSend += ": ";
-		m_strHeaderBytesToSend += m_vHTTPHeaders[i].second;
-		m_strHeaderBytesToSend += "\r\n";
+        if( strcmp(m_vHTTPHeaders[i].first.c_str(), "Cookie")!=0)
+        {
+          m_strHeaderBytesToSend += m_vHTTPHeaders[i].first;
+		  m_strHeaderBytesToSend += ": ";
+		  m_strHeaderBytesToSend += m_vHTTPHeaders[i].second;
+		  m_strHeaderBytesToSend += "\r\n";
+        }
     }
 
     // Set cookies
     if (m_bMaintainSession && (m_vCookies.size () > 0))
     {
-		m_strHeaderBytesToSend += "Cookie";
-		m_strHeaderBytesToSend += ": ";
-
-        for (unsigned int var = 0; var < m_vCookies.size(); var++) 
+        string cookieHeader="";
+        
+        // Add in all the cookies ar the last one because that shouldn't have a ';' on it
+        for (unsigned int var = 0; var < m_vCookies.size()-1; var++) 
         {
-            m_strHeaderBytesToSend += m_vCookies[var].first;
-            m_strHeaderBytesToSend += "=";
-            m_strHeaderBytesToSend += m_vCookies[var].second;
-            m_strHeaderBytesToSend += ";";
+            cookieHeader += m_vCookies[var].first;
+            cookieHeader += "=";
+            cookieHeader += m_vCookies[var].second;
+            cookieHeader += ";";
         }
-        // remove the last ';'
-        m_strHeaderBytesToSend = m_strHeaderBytesToSend.substr(0, m_strHeaderBytesToSend.length()-1);
+        // add on the last cookie
+        cookieHeader += m_vCookies[m_vCookies.size()-1].first;
+        cookieHeader += "=";
+        cookieHeader += m_vCookies[m_vCookies.size()-1].second;
+        
+        
+        m_strHeaderBytesToSend += "Cookie: ";
+        m_strHeaderBytesToSend += cookieHeader;
         m_strHeaderBytesToSend += "\r\n";
+        
+        // Now add this header in to the list of sent headers
+        // if it's not already been set ! If it has been then override it
+        bool b_keyFound=false;
+        for (unsigned int i = 0; i < m_vHTTPHeaders.size(); i++)
+        {
+            if (m_vHTTPHeaders[i].first == (string)"Cookie")
+            {
+                m_vHTTPHeaders[i].second = (string) cookieHeader;
+                b_keyFound = true;
+
+                break;
+            }
+        }
+        if(!b_keyFound)
+        {
+            m_vHTTPHeaders.push_back( std::make_pair( (string) "Cookie", (string) cookieHeader));
+        }
     }
 
     m_strHeaderBytesToSend += "\r\n";
@@ -748,6 +782,7 @@
 
     bool b_KeyFound = false;
 
+    // Check for well known headers that we add on in every iteration
     if( strcmp( pcKey, "SOAPAction") == 0 || strcmp( pcKey, "Content-Length") == 0)
     {
 		std::string strKeyToFind = std::string( pcKey);
@@ -757,19 +792,24 @@
 		    if (m_vHTTPHeaders[i].first == strKeyToFind)
 			{
 				m_vHTTPHeaders[i].second = (string) pcValue;
-
 				b_KeyFound = true;
 
 				break;
 		    }
 		}
     }
+    else
+    {
+        if(strcmp(pcKey, "Cookie")==0)
+        {
+        return addCookie(pcValue);
+        }
+    }
 
     if( !b_KeyFound)
     {
-		m_vHTTPHeaders.push_back( std::make_pair( (string) pcKey, (string) pcValue));
+  		m_vHTTPHeaders.push_back( std::make_pair( (string) pcKey, (string) pcValue));
     }
-
 	return AXIS_SUCCESS;
 }
 
@@ -1330,38 +1370,77 @@
     return NULL;
 }
 
-const char * HTTPTransport::getFirstTransportPropertyKey()
+const char * HTTPTransport::getFirstTransportPropertyKey(bool response)
 {
-    m_viCurrentHeader = m_vHTTPHeaders.begin ();
-
-    if( m_viCurrentHeader == m_vHTTPHeaders.end())
-	{
-		return NULL;
-	}
+    if(response)
+    {
+        m_viCurrentResponseHeader = m_vResponseHTTPHeaders.begin ();
+    
+        if( m_viCurrentResponseHeader == m_vResponseHTTPHeaders.end())
+        {
+         return NULL;
+        }
+        else
+        {
+         return (*m_viCurrentResponseHeader).first.c_str();
+        }
+    }
     else
-	{
-		return (*m_viCurrentHeader).first.c_str();
-	}
+    {
+        m_viCurrentHeader = m_vHTTPHeaders.begin ();
+    
+        if( m_viCurrentHeader == m_vHTTPHeaders.end())
+    	{
+    		return NULL;
+    	}
+        else
+    	{
+    		return (*m_viCurrentHeader).first.c_str();
+    	}
+    }
 }
 
-const char * HTTPTransport::getNextTransportPropertyKey()
+const char * HTTPTransport::getNextTransportPropertyKey(bool response)
 {
-    //already at the end?
-    if( m_viCurrentHeader == m_vHTTPHeaders.end())
-	{
-		return NULL;
-	}
+    if(response)
+    {
+        //already at the end?
+        if( m_viCurrentResponseHeader == m_vResponseHTTPHeaders.end())
+        {
+            return NULL;
+        }
 
-    m_viCurrentHeader++;
+        m_viCurrentResponseHeader++;
 
-    if( m_viCurrentHeader == m_vHTTPHeaders.end())
-	{
-		return NULL;
-	}
+        if( m_viCurrentResponseHeader == m_vResponseHTTPHeaders.end())
+        {
+            return NULL;
+        }
+        else
+        {
+            return (*m_viCurrentResponseHeader).first.c_str();
+        }
+    }
     else
-	{
-		return (*m_viCurrentHeader).first.c_str();
-	}
+    {
+    
+        //already at the end?
+        if( m_viCurrentHeader == m_vResponseHTTPHeaders.end())
+    	{
+    		return NULL;
+    	}
+    
+        m_viCurrentHeader++;
+    
+        if( m_viCurrentHeader == m_vHTTPHeaders.end())
+    	{
+    		return NULL;
+    	}
+        else
+    	{
+    		return (*m_viCurrentHeader).first.c_str();
+    	}
+    }
 }
 
 const char * HTTPTransport::getCurrentTransportPropertyKey()
@@ -1376,8 +1455,22 @@
 	}
 }
 
-const char * HTTPTransport::getCurrentTransportPropertyValue()
+const char * HTTPTransport::getCurrentTransportPropertyValue(bool response)
 {
+ if(response)
+ {
+    if( m_viCurrentResponseHeader == m_vResponseHTTPHeaders.end())
+    {
+     return NULL;
+  }
+    else
+   {
+     return (*m_viCurrentResponseHeader).second.c_str();
+   }
+    
+ }
+ else
+ {
     if( m_viCurrentHeader == m_vHTTPHeaders.end())
 	{
 		return NULL;
@@ -1386,14 +1479,27 @@
 	{
 		return (*m_viCurrentHeader).second.c_str();
 	}
+ }
 }
 
-void HTTPTransport::deleteCurrentTransportProperty()
+void HTTPTransport::deleteCurrentTransportProperty(bool response)
 {
-    if( m_viCurrentHeader != m_vHTTPHeaders.end())
+    // response=true by default
+    std::vector < std::pair < std::string, std::string > >* headers = &m_vResponseHTTPHeaders;
+    vector <std::pair < std::string, std::string > >::iterator* currentHeader = &m_viCurrentResponseHeader;
+    if(!response)
     {
-		m_vHTTPHeaders.erase( m_viCurrentHeader);
+        headers = &m_vHTTPHeaders;
+        currentHeader = &m_viCurrentHeader;
     }
+    if( *currentHeader != headers->end())
+    {
+       headers->erase( *currentHeader);
+    }
+//    if( m_viCurrentHeader != m_vHTTPHeaders.end())
+//    {
+//		m_vHTTPHeaders.erase( m_viCurrentHeader);
+//    }
 }
 
 void HTTPTransport::deleteTransportProperty (char *pcKey, unsigned int uiOccurance)
@@ -1401,7 +1507,7 @@
     vector < std::pair < std::string,
 	std::string > >::iterator currentHeader = m_vHTTPHeaders.begin();
     unsigned int uiCount = 1;
-
+    bool found=false;
     while( currentHeader != m_vHTTPHeaders.end() && uiCount <= uiOccurance)
     {
 		if( strcmp( pcKey, (*currentHeader).first.c_str()) == 0)
@@ -1409,6 +1515,12 @@
 			if( uiCount == uiOccurance)
 			{
 				m_vHTTPHeaders.erase( currentHeader);
+                // if this is the special case of cookies then delete them all
+                if(strcmp(pcKey, "Cookie")==0)
+                {
+                 removeAllCookies();
+                }
+                found=true;
 				break;
 			}
 	    
@@ -1417,6 +1529,11 @@
 	
 		currentHeader++;
     }
+    // if the property has not been found then it might be a cookie
+    if(!found)
+    {
+        removeCookie(pcKey);
+    }
 }
 
 void HTTPTransport::setMaintainSession( bool bSession)
@@ -1710,17 +1827,40 @@
 	return bTransportInProgress;
 }
 
-bool HTTPTransport::addCookie(const string name, const string value)
+int HTTPTransport::addCookie(const string name, const string value)
 {
- m_vCookies.push_back( std::make_pair( name, value));
- return true;
+    // trim the name
+    string theName(name);
+    trim(theName);
+    // Make sure that the cookie is not duplicated.
+    // This cookie might be replacing one that's already there
+    bool b_keyFound=false;
+    for (unsigned int i = 0; i < m_vCookies.size(); i++)
+    {
+        if (m_vCookies[i].first == theName)
+        {
+            m_vCookies[i].second = (string) value;
+            b_keyFound = true;
+
+            break;
+        }
+     }
+ 
+ 
+    if(!b_keyFound)
+    {
+     // cookie has not already been found
+     m_vCookies.push_back( std::make_pair( theName, value));
+    }
+    return true;
 }
-bool HTTPTransport::addCookie(const string nameValuePair)
+int HTTPTransport::addCookie(const string nameValuePair)
 {
     // Spec syntax : Set-Cookie: NAME=VALUE; expires=DATE; path=PATH; domain=DOMAIN_NAME; secure
     // This code assumes it to be : Set-Cookie: NAME=VALUE; Anything_else
     // And discards stuff after first ';'
     // This is the same assumption used in Axis Java
+    
     unsigned long ulKeyEndsAt = nameValuePair.find( ";");
            
     string nameValue;
@@ -1733,6 +1873,31 @@
     return addCookie(nameValue.substr(0, nameEndsAt), nameValue.substr(nameEndsAt+1));
 }
 
+int HTTPTransport::removeCookie(const string name)
+{
+     vector < std::pair < std::string,
+     std::string > >::iterator currentCookie = m_vCookies.begin();
+
+    while( currentCookie != m_vCookies.end())
+    {
+        if( strcmp( name.c_str(), (*currentCookie).first.c_str()) == 0)
+        {
+            m_vCookies.erase( currentCookie);
+            return AXIS_SUCCESS;
+        }
+        currentCookie++;
+    }
+    
+    return AXIS_FAIL;
+}
+
+int HTTPTransport::removeAllCookies()
+{
+    m_vCookies.clear();
+    // we also need to remove it from the header properties that we send.
+    // This is done from the deleteTransportMethod before this one is called.
+    return AXIS_SUCCESS;
+}
 int HTTPTransport::peekChunkLength( std::string& strNextChunk)
 {
 	if( strNextChunk.length() == 0)
@@ -1757,3 +1922,21 @@
 // Convert the hex string into the length of the chunk.
 	return axtoi( (char *) strNextChunk.substr( 0, iEndOfChunkSize).c_str());
 }
+void HTTPTransport::trim(string& str)
+{
+    string::size_type pos = str.find_last_not_of(' ');
+    if(pos != string::npos) 
+    {
+        str.erase(pos + 1);
+        pos = str.find_first_not_of(' ');
+        if(pos != string::npos) 
+        {
+            str.erase(0, pos);
+        }
+    }
+    else 
+    {
+        str.erase(str.begin(), str.end());
+    }
+}
+

Modified: webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.hpp
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.hpp?rev=367997&r1=367996&r2=367997&view=diff
==============================================================================
--- webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.hpp (original)
+++ webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.hpp Wed Jan 11 02:36:55 2006
@@ -94,11 +94,11 @@
     void					setHTTPMethod( const char *);
     const char *			getHTTPHeaders();
     void					setSocket( unsigned int);
-    const char *			getFirstTransportPropertyKey();
-    const char *			getNextTransportPropertyKey();
+    const char *			getFirstTransportPropertyKey(bool response);
+    const char *			getNextTransportPropertyKey(bool response);
     const char *			getCurrentTransportPropertyKey();
-    const char *			getCurrentTransportPropertyValue();
-    void					deleteCurrentTransportProperty();
+    const char *			getCurrentTransportPropertyValue(bool response);
+    void					deleteCurrentTransportProperty(bool response=true);
     void					deleteTransportProperty( char* pcKey, unsigned int uiOccurance = 1);
     virtual void			setMaintainSession( bool bSession);
 
@@ -127,16 +127,35 @@
      * 
      * @param name name of the cookie
      * @param value value of the cookie
-     * @return true if the cookie was added succesfully. False otherwise
+     * @return AXIS_SUCCESS if the cookie was added succesfully. False otherwise
      */
-    bool                    addCookie(const string name, const string Value);
+    int                    addCookie(const string name, const string Value);
     
     /**
      * Adds the name value pair to the cookie list
      * @param nameValuepair in the format name=value
-     * @return true if the cookie was added succesfully false otherwise.
+     * @return AXIS_SUCCESS if the cookie was added succesfully false otherwise.
      */
-    bool addCookie(const string nameValuePair);
+    int addCookie(const string nameValuePair);
+    
+    /**
+     * removes the known cookie
+     * @param name - the name of the cookie to be removed
+     * @return AXIS_SUCCESS if the cookie and was there and was removed AXIS_FAIL otherwise
+     */
+     int removeCookie(const string name);
+     
+     /**
+      * If the user passes "Cookie" into deleteTransportProperty() then we remove all cookies
+      * This is a convenient internal method to do that.
+      * @return AXIS_SUCCESS if all cookies were removed or AXIS_FAIL otherwise
+      */
+     int removeAllCookies();
+     /**
+      * Utility function - Removes whitespace from around the given string
+      */            
+     void trim(string& str);
+     
     
   /**
     * Keeps track of if we need to reopen connection.
@@ -162,9 +181,14 @@
     std::vector < std::pair < std::string, std::string > >m_vHTTPHeaders;
     
   /**
-    * Transport header iterator
+    * Transport header iterator for the request headers
     */
     vector <std::pair < std::string, std::string > >::iterator m_viCurrentHeader;
+
+  /**
+    * Transport header iterator for the reply headers
+    */
+    vector <std::pair < std::string, std::string > >::iterator m_viCurrentResponseHeader;
     
   /**
     * HTTP protocol (1.1 or 1.0). Default is HTTP/1.1