[ http://issues.apache.org/jira/browse/XERCESC-1472?page=all ]
     
Alberto Massari resolved XERCESC-1472:
--------------------------------------

    Resolution: Fixed

A modified patch (to match the current coding style, fix the memory leaks and 
to remove the line feeds that Base64 adds to the data it encodes) has been 
committed. Please verify.

> Add Basic Authentication to NetAccessors/Socket
> -----------------------------------------------
>
>          Key: XERCESC-1472
>          URL: http://issues.apache.org/jira/browse/XERCESC-1472
>      Project: Xerces-C++
>         Type: Improvement
>   Components: Utilities
>     Versions: 2.6.0
>  Environment: Redhat Advanced Server 3
>     Reporter: Chris Knight
>     Priority: Minor

>
> Below is a patch to util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp that 
> sends a basic authentication header if the XMLURL has the username and 
> password defined.
> ---diff below---
> *** util/NetAccessors/Socket/UnixHTTPURLInputStream.cpp 2004-09-08 
> 06:56:35.000000000 -0700
> --- /home/xdb/UnixHTTPURLInputStream.cpp        2005-08-05 14:21:01.000000000 
> -0700
> ***************
> *** 127,132 ****
> --- 127,133 ----
>  #include <xercesc/util/TransService.hpp>
>  #include <xercesc/util/TranscodingException.hpp>
>  #include <xercesc/util/PlatformUtils.hpp>
> + #include <xercesc/util/Base64.hpp>
>  XERCES_CPP_NAMESPACE_BEGIN
> ***************
> *** 211,216 ****
> --- 212,219 ----
>      const XMLCh*        path = urlSource.getPath();
>      const XMLCh*        fragment = urlSource.getFragment();
>      const XMLCh*        query = urlSource.getQuery();                       
> +     const XMLCh*      username = urlSource.getUser();
> +     const XMLCh*      password = urlSource.getPassword();
>      //
>      //  Convert the hostName to the platform's code page for gethostbyname 
> and
> ***************
> *** 371,376 ****
> --- 374,399 ----
>      }
>      strcat(fBuffer, CRLF);
> +     if (username && password)
> +     {
> +       unsigned int    len = XMLString::stringLen(username) + 
> XMLString::stringLen(password) + 1;
> +         char* userPass = (char *)fMemoryManager->allocate((len + 1) * 
> sizeof(*userPass));
> +       char* encodedData;
> +
> +       userPass[0] = '\0';
> +       strcat(userPass, XMLString::transcode(username, fMemoryManager));
> +       strcat(userPass, ":");
> +       strcat(userPass, XMLString::transcode(password, fMemoryManager));
> +       encodedData = (char *)Base64::encode((XMLByte *)userPass, 
> strlen(userPass), &len, fMemoryManager);
> +
> +       if (encodedData)
> +       {
> +           char *authorization = (char 
> *)fMemoryManager->allocate((strlen("Authorization: Basic ") + len + 3) * 
> sizeof(*authorization));
> +           sprintf(authorization, "Authorization: Basic %s", encodedData);
> +           strcat(fBuffer, authorization);
> +       }
> +     }
> +
>      if(httpInfo!=0 && httpInfo->fHeaders!=0)
>          strncat(fBuffer,httpInfo->fHeaders,httpInfo->fHeadersLen);

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to