You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by bl...@apache.org on 2004/08/02 13:07:45 UTC

cvs commit: xml-security/c/src/utils/winutils XSECSOAPRequestorSimpleWin32.cpp

blautenb    2004/08/02 04:07:45

  Modified:    c/src/utils/winutils XSECSOAPRequestorSimpleWin32.cpp
  Log:
  Fix handling of HTTP response without Content-Length + fix buffer over run when the request message is large
  
  Revision  Changes    Path
  1.6       +48 -2     xml-security/c/src/utils/winutils/XSECSOAPRequestorSimpleWin32.cpp
  
  Index: XSECSOAPRequestorSimpleWin32.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/utils/winutils/XSECSOAPRequestorSimpleWin32.cpp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XSECSOAPRequestorSimpleWin32.cpp	17 Jun 2004 11:47:38 -0000	1.5
  +++ XSECSOAPRequestorSimpleWin32.cpp	2 Aug 2004 11:07:45 -0000	1.6
  @@ -214,7 +214,7 @@
       strcat(fBuffer, "\r\n");
   
   	// Now the content
  -	strcat(fBuffer, content);
  +//	strcat(fBuffer, content);
   
       // Send the http request
       int lent = (int) strlen(fBuffer);
  @@ -227,6 +227,16 @@
   							"Error reported writing to socket");
       }
   
  +	// Now the content
  +    lent = (int) strlen(content);
  +    aLent = 0;
  +    if ((aLent = XSECBinHTTPURIInputStream::send((unsigned short) s, 
  +		content, lent, 0)) != lent)
  +    {
  +        // Call WSAGetLastError() to get the error number.
  +        throw XSECException(XSECException::HTTPURIInputStreamError,
  +							"Error reported writing to socket");
  +    }
   
       //
       // get the response, check the http header for errors from the server.
  @@ -354,6 +364,41 @@
   	/* Now find out how long the return is */
   
   	p = strstr(fBuffer, "Content-Length:");
  +	int responseLength;
  +
  +	if (p == NULL) {
  +		// Need to work it out from the amount of data returned
  +		responseLength = -1;
  +	}
  +	else {
  +
  +		p = strchr(p, ' ');
  +		p++;
  +
  +		responseLength = atoi(p);
  +	}
  +
  +	safeBuffer responseBuffer;
  +	lent = fBufferEnd - fBufferPos;
  +	responseBuffer.sbMemcpyIn(fBufferPos, lent);
  +
  +	while (responseLength == -1 || lent < responseLength) {
  +		aLent = XSECBinHTTPURIInputStream::recv((unsigned short)s, fBuffer, sizeof(fBuffer)-1, 0);
  +		if (aLent > 0) {
  +			responseBuffer.sbMemcpyIn(lent, fBuffer, aLent);
  +			lent += aLent;
  +		}
  +		else {
  +			responseLength = 0;
  +		}
  +	}
  +
  +	return parseAndUnwrap(responseBuffer.rawCharBuffer(), lent);
  +
  +
  +# if 0
  +
  +	p = strstr(fBuffer, "Content-Length:");
   	if (p == NULL) {
           throw XSECException(XSECException::HTTPURIInputStreamError,
   							"Content-Length required in SOAP HTTP Response");
  @@ -376,6 +421,7 @@
   	}
   	
       return parseAndUnwrap(responseBuffer, responseLength);
  +#endif
   }