Bugzilla
Quick Search
Browse
Advanced Search
Reports
Quick Search Help
Documentation
New Account
Log In
Login with GitHub
Remember
Forgot Password
Mozilla Home
Privacy
Cookies
Legal
Attachment 8824354 Details for
Bug 41489
[patch]
patch for basic
file_41489.txt (text/plain), 4.77 KB, created by
for nothing
(
hide
)
Description:
patch for basic
Filename:
MIME Type:
Creator:
for nothing
Size:
4.77 KB
patch
obsolete
>diff -r a14094edbad7 netwerk/protocol/http/nsHttpBasicAuth.cpp >--- a/netwerk/protocol/http/nsHttpBasicAuth.cpp Thu Jan 05 17:30:35 2017 -0800 >+++ b/netwerk/protocol/http/nsHttpBasicAuth.cpp Fri Jan 06 15:34:30 2017 +0600 >@@ -5,16 +5,17 @@ > > // HttpLog.h should generally be included first > #include "HttpLog.h" > > #include "nsHttpBasicAuth.h" > #include "plbase64.h" > #include "plstr.h" > #include "nsString.h" >+#include "mozilla/Tokenizer.h" > > namespace mozilla { > namespace net { > > //----------------------------------------------------------------------------- > // nsHttpBasicAuth <public> > //----------------------------------------------------------------------------- > >@@ -82,22 +83,36 @@ nsHttpBasicAuth::GenerateCredentials(nsI > NS_ENSURE_ARG_POINTER(creds); > > *aFlags = 0; > > // we only know how to deal with Basic auth for http. > bool isBasicAuth = !PL_strncasecmp(challenge, "basic", 5); > NS_ENSURE_TRUE(isBasicAuth, NS_ERROR_UNEXPECTED); > >- // we work with ASCII around here > nsAutoCString userpass; >- LossyCopyUTF16toASCII(user, userpass); >- userpass.Append(':'); // always send a ':' (see bug 129565) >- if (password) >+ uint16_t charset; >+ nsresult rv = ParseCharset(challenge, &charset); >+ NS_ENSURE_SUCCESS(rv, rv); >+ if (charset) { >+ if (charset & CHARSET_UTF8) { >+ CopyUTF16toUTF8(user, userpass); >+ userpass.Append(':'); >+ if (password) { >+ AppendUTF16toUTF8(password, userpass); >+ } >+ } else { >+ return NS_ERROR_UNEXPECTED; >+ } >+ } else { >+ LossyCopyUTF16toASCII(user, userpass); >+ userpass.Append(':'); // always send a ':' (see bug 129565) >+ if (password) > LossyAppendUTF16toASCII(password, userpass); >+ } > > // plbase64.h provides this worst-case output buffer size calculation. > // use calloc, since PL_Base64Encode does not null terminate. > *creds = (char *) calloc(6 + ((userpass.Length() + 2)/3)*4 + 1, 1); > if (!*creds) > return NS_ERROR_OUT_OF_MEMORY; > > memcpy(*creds, "Basic ", 6); >@@ -107,10 +122,60 @@ nsHttpBasicAuth::GenerateCredentials(nsI > > NS_IMETHODIMP > nsHttpBasicAuth::GetAuthFlags(uint32_t *flags) > { > *flags = REQUEST_BASED | REUSABLE_CREDENTIALS | REUSABLE_CHALLENGE; > return NS_OK; > } > >+NS_IMETHODIMP >+nsHttpBasicAuth::ParseCharset(const char *challenge, uint16_t * charset) >+{ >+ const char *ch = challenge + 5; >+ *charset = CHARSET_NOT_SET; >+ Tokenizer p(ch); >+ Tokenizer::Token t; >+ nsAutoCString name; >+ nsAutoCString value; >+ while (p.Next(t)) { >+ p.Rollback(); >+ while (p.CheckChar(',') || p.CheckWhite()); >+ if (!p.Next(t) || t.Type() == Tokenizer::TOKEN_EOF) { >+ break; >+ } >+ p.Rollback(); >+ p.Record(); >+ while (p.Next(t) && !t.Equals(Tokenizer::Token::Char('=')) && >+ t.Type() != Tokenizer::TOKEN_WS); >+ if (p.HasFailed()) { >+ return NS_ERROR_INVALID_ARG; >+ } >+ p.Claim(name); >+ p.Rollback(); >+ p.SkipWhites(); >+ if (!p.CheckChar('=')) { >+ return NS_ERROR_INVALID_ARG; >+ } >+ p.SkipWhites(); >+ bool quoted = p.CheckChar('"'); >+ if (quoted) { >+ if (!p.ReadUntil(Tokenizer::Token::Char('"'), value)) { >+ return NS_ERROR_INVALID_ARG; >+ } >+ } else { >+ p.Record(); >+ while (p.Next(t) && !t.Equals(Tokenizer::Token::Char(',')) && >+ t.Type() != Tokenizer::TOKEN_WS); >+ p.Claim(value); >+ } >+ if (name.EqualsLiteral("charset")) { >+ *charset = CHARSET_SPECIFIED; >+ if (value.LowerCaseEqualsLiteral("utf-8")) { >+ *charset |= CHARSET_UTF8; >+ } >+ } >+ } >+ return NS_OK; >+} >+ > } // namespace net > } // namespace mozilla >diff -r a14094edbad7 netwerk/protocol/http/nsHttpBasicAuth.h >--- a/netwerk/protocol/http/nsHttpBasicAuth.h Thu Jan 05 17:30:35 2017 -0800 >+++ b/netwerk/protocol/http/nsHttpBasicAuth.h Fri Jan 06 15:34:30 2017 +0600 >@@ -5,28 +5,33 @@ > > #ifndef nsBasicAuth_h__ > #define nsBasicAuth_h__ > > #include "nsIHttpAuthenticator.h" > > namespace mozilla { namespace net { > >+#define CHARSET_NOT_SET 0x00 >+#define CHARSET_SPECIFIED 0x01 >+#define CHARSET_UTF8 0x02 >+ > //----------------------------------------------------------------------------- > // The nsHttpBasicAuth class produces HTTP Basic-auth responses for a username/ > // (optional)password pair, BASE64("user:pass"). > //----------------------------------------------------------------------------- > > class nsHttpBasicAuth : public nsIHttpAuthenticator > { > public: > NS_DECL_ISUPPORTS > NS_DECL_NSIHTTPAUTHENTICATOR > > nsHttpBasicAuth(); > private: > virtual ~nsHttpBasicAuth(); >+ NS_IMETHODIMP ParseCharset(const char *challenge, uint16_t * charset); > }; > > } // namespace net > } // namespace mozilla > > #endif // !nsHttpBasicAuth_h__
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
Actions:
View
|
Diff
|
Review
Attachments on
bug 41489
:
315810
|
315813
|
420886
|
521605
|
734492
|
740318
|
8587817
|
8589323
|
8714628
|
8717027
|
8750616
|
8750619
|
8821682
|
8821683
|
8822552
|
8822553
|
8824314
|
8824354
|
8824634
|
8848140
|
8848141
|
8848143
|
8848144