Author: amassari
Date: Mon Aug 8 12:36:55 2005
New Revision: 230862
URL: http://svn.apache.org/viewcvs?rev=230862&view=rev
Log:
Enable basic authentication (thanks to Chris Knight)
Modified:
xerces/c/branches/xerces-2.7/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp
xerces/c/branches/xerces-2.7/src/xercesc/util/NetAccessors/WinSock/BinHTTPURLInputStream.cpp
Modified:
xerces/c/branches/xerces-2.7/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp
URL:
http://svn.apache.org/viewcvs/xerces/c/branches/xerces-2.7/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp?rev=230862&r1=230861&r2=230862&view=diff
==============================================================================
---
xerces/c/branches/xerces-2.7/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp
(original)
+++
xerces/c/branches/xerces-2.7/src/xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp
Mon Aug 8 12:36:55 2005
@@ -41,6 +41,7 @@
#include <xercesc/util/TransService.hpp>
#include <xercesc/util/TranscodingException.hpp>
#include <xercesc/util/PlatformUtils.hpp>
+#include <xercesc/util/Base64.hpp>
XERCES_CPP_NAMESPACE_BEGIN
@@ -105,6 +106,12 @@
chColon, chNull
};
+ const char AUTHORIZATION[] =
+ {
+ chLatin_A, chLatin_u, chLatin_t, chLatin_h, chLatin_o, chLatin_r,
chLatin_i, chLatin_z, chLatin_a, chLatin_t,
+ chLatin_i, chLatin_o, chLatin_n, chColon, chSpace, chLatin_B,
chLatin_a, chLatin_s, chLatin_i, chLatin_c, chSpace, chNull
+ };
+
const char resp200 [] =
{
chSpace, chDigit_2, chDigit_0, chDigit_0, chSpace, chNull
@@ -288,6 +295,36 @@
strcat(fBuffer,portAsASCII);
}
strcat(fBuffer, CRLF);
+
+ const XMLCh* username = urlSource.getUser();
+ const XMLCh* password = urlSource.getPassword();
+ if (username && password)
+ {
+ XMLBuffer userPass(256, fMemoryManager);
+ userPass.append(username);
+ userPass.append(chColon);
+ userPass.append(password);
+ char* userPassAsCharStar =
XMLString::transcode(userPass.getRawBuffer(), fMemoryManager);
+ ArrayJanitor<char> janBuf(userPassAsCharStar, fMemoryManager);
+
+ unsigned int len;
+ XMLByte* encodedData = Base64::encode((XMLByte *)userPassAsCharStar,
strlen(userPassAsCharStar), &len, fMemoryManager);
+
+ if (encodedData)
+ {
+ // HTTP doesn't want the 0x0A separating the data in chunks of 76
chars per line
+ XMLByte* authData =
(XMLByte*)fMemoryManager->allocate((len+1)*sizeof(XMLByte));
+ ArrayJanitor<XMLByte> janBuf(authData, fMemoryManager);
+ XMLByte* cursor=authData;
+ for(unsigned int i=0;i<len;i++)
+ if(encodedData[i]!=chLF)
+ *cursor++=encodedData[i];
+ *cursor++=0;
+ strcat(fBuffer, AUTHORIZATION);
+ strcat(fBuffer, (char*)authData);
+ strcat(fBuffer, CRLF);
+ }
+ }
if(httpInfo!=0 && httpInfo->fHeaders!=0)
strncat(fBuffer,httpInfo->fHeaders,httpInfo->fHeadersLen);
Modified:
xerces/c/branches/xerces-2.7/src/xercesc/util/NetAccessors/WinSock/BinHTTPURLInputStream.cpp
URL:
http://svn.apache.org/viewcvs/xerces/c/branches/xerces-2.7/src/xercesc/util/NetAccessors/WinSock/BinHTTPURLInputStream.cpp?rev=230862&r1=230861&r2=230862&view=diff
==============================================================================
---
xerces/c/branches/xerces-2.7/src/xercesc/util/NetAccessors/WinSock/BinHTTPURLInputStream.cpp
(original)
+++
xerces/c/branches/xerces-2.7/src/xercesc/util/NetAccessors/WinSock/BinHTTPURLInputStream.cpp
Mon Aug 8 12:36:55 2005
@@ -35,6 +35,7 @@
#include <xercesc/util/XMLExceptMsgs.hpp>
#include <xercesc/util/Janitor.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
+#include <xercesc/util/Base64.hpp>
XERCES_CPP_NAMESPACE_BEGIN
@@ -326,6 +327,36 @@
_itoa(portNumber, fBuffer+i, 10);
}
strcat(fBuffer, "\r\n");
+
+ const XMLCh* username = urlSource.getUser();
+ const XMLCh* password = urlSource.getPassword();
+ if (username && password)
+ {
+ XMLBuffer userPass(256, fMemoryManager);
+ userPass.append(username);
+ userPass.append(chColon);
+ userPass.append(password);
+ char* userPassAsCharStar =
XMLString::transcode(userPass.getRawBuffer(), fMemoryManager);
+ ArrayJanitor<char> janBuf(userPassAsCharStar, fMemoryManager);
+
+ unsigned int len;
+ XMLByte* encodedData = Base64::encode((XMLByte *)userPassAsCharStar,
strlen(userPassAsCharStar), &len, fMemoryManager);
+
+ if (encodedData)
+ {
+ // HTTP doesn't want the 0x0A separating the data in chunks of 76
chars per line
+ XMLByte* authData =
(XMLByte*)fMemoryManager->allocate((len+1)*sizeof(XMLByte));
+ ArrayJanitor<XMLByte> janBuf(authData, fMemoryManager);
+ XMLByte* cursor=authData;
+ for(unsigned int i=0;i<len;i++)
+ if(encodedData[i]!=chLF)
+ *cursor++=encodedData[i];
+ *cursor++=0;
+ strcat(fBuffer, "Authorization: Basic ");
+ strcat(fBuffer, (char*)authData);
+ strcat(fBuffer, "\r\n");
+ }
+ }
if(httpInfo!=0 && httpInfo->fHeaders!=0)
strncat(fBuffer,httpInfo->fHeaders,httpInfo->fHeadersLen);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]