hrev47461 adds 10 changesets to branch 'master' old head: 4260c146011e619214c297093a713bdb5fa81a51 new head: b04949711d8c74533fb3ef57bfdb738686c70a9e overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=b049497+%5E4260c14 ---------------------------------------------------------------------------- 739f15e: Revert "Revert "DynamicBuffer: implement BDataIO"" This reverts commit 747b401e875f19d83508cc39176f4c263182c515. 7616c39: DynamicBuffer: dos2unix 6926863: DynamicBuffer::Write(): Fix return type and semantics 25d3431: DynamicBuffer::Read(): Small optimization (skip 0 case) c99f294: BNetBuffer: Restore semantics after DynamicBuffer -> BDataIO 2573655: Revert "Revert "HttpRequest: support gzip and deflate compression."" This reverts commit 256080b112e417fc4fd2f3f9fcb23485e1b23b42. With the following changes: * Adjusted to the BZlibCompressionAlgorithm API. * Add some error handling. 72f6b78: BUrl: Add missing functionality from support kit BUrl a5330a8: Remove private support kit BUrl Use the public BUrl from the network kit instead. c666db8: BZlibCompressionAlgorithm: Missing NULL check b049497: BUrl::IsValid(): Replace with a slightly better dummy impl [ Ingo Weinhold <ingo_weinhold@xxxxxx> ] ---------------------------------------------------------------------------- 16 files changed, 294 insertions(+), 470 deletions(-) headers/os/net/Url.h | 8 + headers/private/net/DynamicBuffer.h | 125 +++++----- headers/private/support/Url.h | 58 ----- src/apps/haikudepot/PackageInfoView.cpp | 5 +- src/bin/Jamfile | 11 +- src/bin/checkitout.cpp | 30 +-- src/bin/open.cpp | 2 +- src/bin/urlwrapper.cpp | 54 ++--- src/kits/network/libnetapi/DynamicBuffer.cpp | 19 +- src/kits/network/libnetapi/HttpRequest.cpp | 66 ++++- src/kits/network/libnetapi/Jamfile | 2 +- src/kits/network/libnetapi/NetBuffer.cpp | 14 +- src/kits/network/libnetapi/Url.cpp | 87 ++++++- src/kits/support/Jamfile | 1 - src/kits/support/Url.cpp | 279 ---------------------- src/kits/support/ZlibCompressionAlgorithm.cpp | 3 +- ############################################################################ Commit: 739f15e1445aa59cc010bd8f343c5c6595836a0e URL: http://cgit.haiku-os.org/haiku/commit/?id=739f15e Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Wed Jul 2 19:29:53 2014 UTC Revert "Revert "DynamicBuffer: implement BDataIO"" This reverts commit 747b401e875f19d83508cc39176f4c263182c515. ---------------------------------------------------------------------------- diff --git a/headers/private/net/DynamicBuffer.h b/headers/private/net/DynamicBuffer.h index 183f88b..58a49d9 100644 --- a/headers/private/net/DynamicBuffer.h +++ b/headers/private/net/DynamicBuffer.h @@ -1,5 +1,5 @@ /* - * Copyright 2009, Haiku, Inc. All Rights Reserved. + * Copyright 2009-2014, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -9,10 +9,11 @@ #ifndef _DYNAMIC_BUFFER_H #define _DYNAMIC_BUFFER_H +#include <DataIO.h> #include <SupportDefs.h> -class DynamicBuffer { +class DynamicBuffer : public BDataIO { public: DynamicBuffer(size_t initialSize = 0); ~DynamicBuffer(); @@ -25,11 +26,11 @@ public: // Insert data at the end of the buffer. The buffer will be increased to // accomodate the data if needed. - status_t Insert(const void* data, size_t size); + status_t Write(const void* data, size_t size); // Remove data from the start of the buffer. Move the buffer start // pointer to point to the data following it. - status_t Remove(void* data, size_t size); + ssize_t Read(void* data, size_t size); // Return a pointer to the underlying buffer. Note this will not // necessarily be a pointer to the start of the allocated memory as the diff --git a/src/kits/network/libnetapi/DynamicBuffer.cpp b/src/kits/network/libnetapi/DynamicBuffer.cpp index 1c63eca..75f4a46 100644 --- a/src/kits/network/libnetapi/DynamicBuffer.cpp +++ b/src/kits/network/libnetapi/DynamicBuffer.cpp @@ -68,7 +68,7 @@ DynamicBuffer::InitCheck() const status_t -DynamicBuffer::Insert(const void* data, size_t size) +DynamicBuffer::Write(const void* data, size_t size) { if (fInit != B_OK) return fInit; @@ -84,14 +84,14 @@ DynamicBuffer::Insert(const void* data, size_t size) } -status_t -DynamicBuffer::Remove(void* data, size_t size) +ssize_t +DynamicBuffer::Read(void* data, size_t size) { if (fInit != B_OK) return fInit; - if (fDataStart + size > fDataEnd) - return B_BUFFER_OVERFLOW; + if (size > Size()) + size = Size(); memcpy(data, fBuffer + fDataStart, size); fDataStart += size; @@ -99,7 +99,7 @@ DynamicBuffer::Remove(void* data, size_t size) if (fDataStart == fDataEnd) fDataStart = fDataEnd = 0; - return B_OK; + return size; } diff --git a/src/kits/network/libnetapi/NetBuffer.cpp b/src/kits/network/libnetapi/NetBuffer.cpp index d2a0911..c1ccb2b 100644 --- a/src/kits/network/libnetapi/NetBuffer.cpp +++ b/src/kits/network/libnetapi/NetBuffer.cpp @@ -54,7 +54,7 @@ BNetBuffer::BNetBuffer(BMessage* archive) : &bufferSize) == B_OK) { fImpl = new (std::nothrow) DynamicBuffer(bufferSize); if (fImpl != NULL) { - status_t result = fImpl->Insert(bufferPtr, bufferSize); + status_t result = fImpl->Write(bufferPtr, bufferSize); if (result == B_OK) fInit = fImpl->InitCheck(); else @@ -185,7 +185,7 @@ BNetBuffer::AppendString(const char* data) status_t BNetBuffer::AppendData(const void* data, size_t size) { - return fImpl->Insert(data, size); + return fImpl->Write(data, size); } @@ -332,7 +332,7 @@ BNetBuffer::RemoveString(char* data, size_t size) status_t BNetBuffer::RemoveData(void* data, size_t size) { - return fImpl->Remove(data, size); + return fImpl->Read(data, size); } ############################################################################ Commit: 7616c39db662d3f7a8bb6b0fedb5e6e46102018a URL: http://cgit.haiku-os.org/haiku/commit/?id=7616c39 Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Wed Jul 2 19:31:57 2014 UTC DynamicBuffer: dos2unix ---------------------------------------------------------------------------- diff --git a/headers/private/net/DynamicBuffer.h b/headers/private/net/DynamicBuffer.h index 58a49d9..e24809f 100644 --- a/headers/private/net/DynamicBuffer.h +++ b/headers/private/net/DynamicBuffer.h @@ -1,63 +1,63 @@ -/* - * Copyright 2009-2014, Haiku, Inc. All Rights Reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * Bruno Albuquerque, bga@xxxxxxxxxxxxx - */ - -#ifndef _DYNAMIC_BUFFER_H -#define _DYNAMIC_BUFFER_H - -#include <DataIO.h> -#include <SupportDefs.h> - - -class DynamicBuffer : public BDataIO { -public: - DynamicBuffer(size_t initialSize = 0); - ~DynamicBuffer(); - - DynamicBuffer(const DynamicBuffer& buffer); - - // InitCheck() should be called to guarantee the object initialization - // didn't fail. If it does not return B_OK, the initialization failed. - status_t InitCheck() const; - - // Insert data at the end of the buffer. The buffer will be increased to - // accomodate the data if needed. - status_t Write(const void* data, size_t size); - - // Remove data from the start of the buffer. Move the buffer start - // pointer to point to the data following it. - ssize_t Read(void* data, size_t size); - - // Return a pointer to the underlying buffer. Note this will not - // necessarily be a pointer to the start of the allocated memory as the - // initial data may be positioned at an offset inside the buffer. In other - // words, this returns a pointer to the start of data inside the buffer. - unsigned char* Data() const; - - // Returns the actual buffer size. This is the amount of memory allocated - // for the buffer. - size_t Size() const; - - // Number of bytes of data still present in the buffer that can be - // extracted through calls to Remove(). - size_t BytesRemaining() const; - - // Dump some buffer statistics to stdout. - void PrintToStream(); - -private: - status_t _GrowToFit(size_t size, bool exact = false); - - unsigned char* fBuffer; - size_t fBufferSize; - size_t fDataStart; - size_t fDataEnd; - - status_t fInit; -}; - -#endif // _DYNAMIC_BUFFER_H +/* + * Copyright 2009-2014, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Bruno Albuquerque, bga@xxxxxxxxxxxxx + */ + +#ifndef _DYNAMIC_BUFFER_H +#define _DYNAMIC_BUFFER_H + +#include <DataIO.h> +#include <SupportDefs.h> + + +class DynamicBuffer : public BDataIO { +public: + DynamicBuffer(size_t initialSize = 0); + ~DynamicBuffer(); + + DynamicBuffer(const DynamicBuffer& buffer); + + // InitCheck() should be called to guarantee the object initialization + // didn't fail. If it does not return B_OK, the initialization failed. + status_t InitCheck() const; + + // Insert data at the end of the buffer. The buffer will be increased to + // accomodate the data if needed. + status_t Write(const void* data, size_t size); + + // Remove data from the start of the buffer. Move the buffer start + // pointer to point to the data following it. + ssize_t Read(void* data, size_t size); + + // Return a pointer to the underlying buffer. Note this will not + // necessarily be a pointer to the start of the allocated memory as the + // initial data may be positioned at an offset inside the buffer. In other + // words, this returns a pointer to the start of data inside the buffer. + unsigned char* Data() const; + + // Returns the actual buffer size. This is the amount of memory allocated + // for the buffer. + size_t Size() const; + + // Number of bytes of data still present in the buffer that can be + // extracted through calls to Remove(). + size_t BytesRemaining() const; + + // Dump some buffer statistics to stdout. + void PrintToStream(); + +private: + status_t _GrowToFit(size_t size, bool exact = false); + + unsigned char* fBuffer; + size_t fBufferSize; + size_t fDataStart; + size_t fDataEnd; + + status_t fInit; +}; + +#endif // _DYNAMIC_BUFFER_H ############################################################################ Commit: 6926863e37809cef86079d7003dc69dba39ffa93 URL: http://cgit.haiku-os.org/haiku/commit/?id=6926863 Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Wed Jul 2 19:54:54 2014 UTC DynamicBuffer::Write(): Fix return type and semantics ---------------------------------------------------------------------------- diff --git a/headers/private/net/DynamicBuffer.h b/headers/private/net/DynamicBuffer.h index e24809f..ddbd3c0 100644 --- a/headers/private/net/DynamicBuffer.h +++ b/headers/private/net/DynamicBuffer.h @@ -26,11 +26,11 @@ public: // Insert data at the end of the buffer. The buffer will be increased to // accomodate the data if needed. - status_t Write(const void* data, size_t size); + virtual ssize_t Write(const void* data, size_t size); // Remove data from the start of the buffer. Move the buffer start // pointer to point to the data following it. - ssize_t Read(void* data, size_t size); + virtual ssize_t Read(void* data, size_t size); // Return a pointer to the underlying buffer. Note this will not // necessarily be a pointer to the start of the allocated memory as the diff --git a/src/kits/network/libnetapi/DynamicBuffer.cpp b/src/kits/network/libnetapi/DynamicBuffer.cpp index 75f4a46..4aee60b 100644 --- a/src/kits/network/libnetapi/DynamicBuffer.cpp +++ b/src/kits/network/libnetapi/DynamicBuffer.cpp @@ -67,7 +67,7 @@ DynamicBuffer::InitCheck() const } -status_t +ssize_t DynamicBuffer::Write(const void* data, size_t size) { if (fInit != B_OK) @@ -80,7 +80,7 @@ DynamicBuffer::Write(const void* data, size_t size) memcpy(fBuffer + fDataEnd, data, size); fDataEnd += size; - return B_OK; + return (ssize_t)size; } ############################################################################ Commit: 25d34313d0c467b45748a535c888aa54ff864aa7 URL: http://cgit.haiku-os.org/haiku/commit/?id=25d3431 Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Wed Jul 2 19:55:34 2014 UTC DynamicBuffer::Read(): Small optimization (skip 0 case) ---------------------------------------------------------------------------- diff --git a/src/kits/network/libnetapi/DynamicBuffer.cpp b/src/kits/network/libnetapi/DynamicBuffer.cpp index 4aee60b..b64fd80 100644 --- a/src/kits/network/libnetapi/DynamicBuffer.cpp +++ b/src/kits/network/libnetapi/DynamicBuffer.cpp @@ -11,6 +11,8 @@ #include <stdio.h> #include <string.h> +#include <algorithm> + #include <Errors.h> #include <SupportDefs.h> @@ -90,8 +92,9 @@ DynamicBuffer::Read(void* data, size_t size) if (fInit != B_OK) return fInit; - if (size > Size()) - size = Size(); + size = std::min(size, Size()); + if (size == 0) + return 0; memcpy(data, fBuffer + fDataStart, size); fDataStart += size; ############################################################################ Commit: c99f294eb0a3a4de8b8d45dd301a4c6730aac2b3 URL: http://cgit.haiku-os.org/haiku/commit/?id=c99f294 Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Wed Jul 2 19:57:51 2014 UTC BNetBuffer: Restore semantics after DynamicBuffer -> BDataIO ---------------------------------------------------------------------------- diff --git a/src/kits/network/libnetapi/NetBuffer.cpp b/src/kits/network/libnetapi/NetBuffer.cpp index c1ccb2b..b0b8d95 100644 --- a/src/kits/network/libnetapi/NetBuffer.cpp +++ b/src/kits/network/libnetapi/NetBuffer.cpp @@ -54,8 +54,8 @@ BNetBuffer::BNetBuffer(BMessage* archive) : &bufferSize) == B_OK) { fImpl = new (std::nothrow) DynamicBuffer(bufferSize); if (fImpl != NULL) { - status_t result = fImpl->Write(bufferPtr, bufferSize); - if (result == B_OK) + ssize_t result = fImpl->Write(bufferPtr, bufferSize); + if (result >= 0) fInit = fImpl->InitCheck(); else fInit = result; @@ -185,7 +185,10 @@ BNetBuffer::AppendString(const char* data) status_t BNetBuffer::AppendData(const void* data, size_t size) { - return fImpl->Write(data, size); + ssize_t bytesWritten = fImpl->Write(data, size); + if (bytesWritten < 0) + return (status_t)bytesWritten; + return (size_t)bytesWritten == size ? B_OK : B_ERROR; } @@ -332,7 +335,10 @@ BNetBuffer::RemoveString(char* data, size_t size) status_t BNetBuffer::RemoveData(void* data, size_t size) { - return fImpl->Read(data, size); + ssize_t bytesRead = fImpl->Read(data, size); + if (bytesRead < 0) + return (status_t)bytesRead; + return (size_t)bytesRead == size ? B_OK : B_BUFFER_OVERFLOW; } ############################################################################ Commit: 2573655b7962928c847ecc4690d73f0f5b6afb19 URL: http://cgit.haiku-os.org/haiku/commit/?id=2573655 Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Wed Jul 2 20:00:43 2014 UTC Revert "Revert "HttpRequest: support gzip and deflate compression."" This reverts commit 256080b112e417fc4fd2f3f9fcb23485e1b23b42. With the following changes: * Adjusted to the BZlibCompressionAlgorithm API. * Add some error handling. ---------------------------------------------------------------------------- diff --git a/src/kits/network/libnetapi/HttpRequest.cpp b/src/kits/network/libnetapi/HttpRequest.cpp index 4f3ac8e..cc4d678 100644 --- a/src/kits/network/libnetapi/HttpRequest.cpp +++ b/src/kits/network/libnetapi/HttpRequest.cpp @@ -1,10 +1,11 @@ /* - * Copyright 2010-2013 Haiku Inc. All rights reserved. + * Copyright 2010-2014 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Christophe Huriaux, c.huriaux@xxxxxxxxx * Niels Sascha Reedijk, niels.reedijk@xxxxxxxxx + * Adrien Destugues, pulkomandy@xxxxxxxxxxxxx */ @@ -17,11 +18,14 @@ #include <deque> #include <new> +#include <AutoDeleter.h> #include <Debug.h> +#include <DynamicBuffer.h> #include <File.h> #include <Socket.h> #include <SecureSocket.h> #include <StackOrHeapArray.h> +#include <ZlibCompressionAlgorithm.h> static const int32 kHttpBufferSize = 4096; @@ -434,6 +438,8 @@ BHttpRequest::_ResolveHostName() else port = fSSL ? 443 : 80; + // FIXME stop forcing AF_INET, when BNetworkAddress stops giving IPv6 + // addresses when there isn't an IPv6 link available. fRemoteAddr = BNetworkAddress(AF_INET, fUrl.Host(), port); if (fRemoteAddr.InitCheck() != B_OK) @@ -570,13 +576,18 @@ BHttpRequest::_MakeRequest() bool receiveEnd = false; bool parseEnd = false; bool readByChunks = false; + bool decompress = false; status_t readError = B_OK; ssize_t bytesRead = 0; ssize_t bytesReceived = 0; ssize_t bytesTotal = 0; + off_t bytesUnpacked = 0; char* inputTempBuffer = new(std::nothrow) char[kHttpBufferSize]; ssize_t inputTempSize = kHttpBufferSize; ssize_t chunkSize = -1; + DynamicBuffer decompressorStorage; + BDataIO* decompressingStream; + ObjectDeleter<BDataIO> decompressingStreamDeleter; while (!fQuit && !(receiveEnd && parseEnd)) { if (!receiveEnd) { @@ -625,6 +636,19 @@ BHttpRequest::_MakeRequest() if (BString(fHeaders["Transfer-Encoding"]) == "chunked") readByChunks = true; + BString contentEncoding(fHeaders["Content-Encoding"]); + if (contentEncoding == "gzip" + || contentEncoding == "deflate") { + decompress = true; + readError = BZlibCompressionAlgorithm() + .CreateDecompressingOutputStream(&decompressorStorage, + NULL, decompressingStream); + if (readError != B_OK) + break; + + decompressingStreamDeleter.SetTo(decompressingStream); + } + int32 index = fHeaders.HasHeader("Content-Length"); if (index != B_ERROR) bytesTotal = atoi(fHeaders.HeaderAt(index).Value()); @@ -711,14 +735,46 @@ BHttpRequest::_MakeRequest() bytesReceived += bytesRead; if (fListener != NULL) { - fListener->DataReceived(this, inputTempBuffer, - bytesReceived - bytesRead, bytesRead); + if (decompress) { + readError = decompressingStream->WriteExactly( + inputTempBuffer, bytesRead); + if (readError != B_OK) + break; + + ssize_t size = decompressorStorage.Size(); + BStackOrHeapArray<char, 4096> buffer(size); + size = decompressorStorage.Read(buffer, size); + if (size > 0) { + fListener->DataReceived(this, buffer, bytesUnpacked, + size); + bytesUnpacked += size; + } + } else { + fListener->DataReceived(this, inputTempBuffer, + bytesReceived - bytesRead, bytesRead); + } fListener->DownloadProgress(this, bytesReceived, bytesTotal); } - if (bytesTotal > 0 && bytesReceived >= bytesTotal) + if (bytesTotal > 0 && bytesReceived >= bytesTotal) { receiveEnd = true; + + if (decompress) { + readError = decompressingStream->Flush(); + if (readError != B_OK) + break; + + ssize_t size = decompressorStorage.Size(); + BStackOrHeapArray<char, 4096> buffer(size); + size = decompressorStorage.Read(buffer, size); + if (fListener != NULL && size > 0) { + fListener->DataReceived(this, buffer, + bytesUnpacked, size); + bytesUnpacked += size; + } + } + } } } @@ -848,7 +904,7 @@ BHttpRequest::_SendHeaders() fOutputHeaders.AddHeader("Host", Url().Host()); fOutputHeaders.AddHeader("Accept", "*/*"); - fOutputHeaders.AddHeader("Accept-Encoding", "identity"); + fOutputHeaders.AddHeader("Accept-Encoding", "gzip,deflate"); // Allow the remote server to send dynamic content by chunks // rather than waiting for the full content to be generated and // sending us data. diff --git a/src/kits/network/libnetapi/Jamfile b/src/kits/network/libnetapi/Jamfile index 39c7908..ad74ae7 100644 --- a/src/kits/network/libnetapi/Jamfile +++ b/src/kits/network/libnetapi/Jamfile @@ -1,6 +1,6 @@ SubDir HAIKU_TOP src kits network libnetapi ; -UsePrivateHeaders app net shared ; +UsePrivateHeaders app net shared support ; UseHeaders [ FDirName $(HAIKU_TOP) src libs compat freebsd_network compat ] : true ; ############################################################################ Commit: 72f6b787cf52b57d38d1ac77052d18096e4d4b65 URL: http://cgit.haiku-os.org/haiku/commit/?id=72f6b78 Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Wed Jul 2 21:23:26 2014 UTC BUrl: Add missing functionality from support kit BUrl ---------------------------------------------------------------------------- diff --git a/headers/os/net/Url.h b/headers/os/net/Url.h index 0363989..c4600ce 100644 --- a/headers/os/net/Url.h +++ b/headers/os/net/Url.h @@ -71,6 +71,12 @@ public: static BString UrlDecode(const BString& url, bool strict = false); + // utility functionality + bool HasPreferredApplication() const; + BString PreferredApplication() const; + status_t OpenWithPreferredApplication( + bool onProblemAskUser = true) const; + // BArchivable members virtual status_t Archive(BMessage* into, bool deep = true) const; @@ -104,6 +110,8 @@ private: static bool _IsGenDelim(char c); static bool _IsSubDelim(char c); + BString _UrlMimeType() const; + private: mutable BString fUrlString; mutable BString fAuthority; diff --git a/src/kits/network/libnetapi/Url.cpp b/src/kits/network/libnetapi/Url.cpp index fb1d499..783e723 100644 --- a/src/kits/network/libnetapi/Url.cpp +++ b/src/kits/network/libnetapi/Url.cpp @@ -14,6 +14,9 @@ #include <cstdlib> #include <new> +#include <MimeType.h> +#include <Roster.h> + #include <RegExp.h> @@ -573,6 +576,76 @@ BUrl::UrlDecode(bool strict) } +// #pragma mark - utility functionality + + +bool +BUrl::HasPreferredApplication() const +{ + BString appSignature = PreferredApplication(); + BMimeType mime(appSignature.String()); + + if (appSignature.IFindFirst("application/") == 0 + && mime.IsValid()) + return true; + + return false; +} + + +BString +BUrl::PreferredApplication() const +{ + BString appSignature; + BMimeType mime(_UrlMimeType().String()); + mime.GetPreferredApp(appSignature.LockBuffer(B_MIME_TYPE_LENGTH)); + appSignature.UnlockBuffer(); + + return BString(appSignature); +} + + +status_t +BUrl::OpenWithPreferredApplication(bool onProblemAskUser) const +{ + if (!IsValid()) + return B_BAD_VALUE; + + BString urlString = UrlString(); + if (urlString.Length() > B_PATH_NAME_LENGTH) { + // TODO: BAlert + // if (onProblemAskUser) + // BAlert ... Too long URL! +#if DEBUG + fprintf(stderr, "URL too long"); +#endif + return B_NAME_TOO_LONG; + } + + char* argv[] = { + const_cast<char*>("BUrlInvokedApplication"), + const_cast<char*>(urlString.String()), + NULL + }; + +#if DEBUG + if (HasPreferredApplication()) + printf("HasPreferredApplication() == true\n"); + else + printf("HasPreferredApplication() == false\n"); +#endif + + status_t status = be_roster->Launch(_UrlMimeType().String(), 1, argv+1); + if (status != B_OK) { +#if DEBUG + fprintf(stderr, "Opening URL failed: %s\n", strerror(status)); +#endif + } + + return status; +} + + // #pragma mark Url encoding/decoding of string @@ -982,3 +1055,13 @@ BUrl::_IsSubDelim(char c) || c == ')' || c == '*' || c == '+' || c == ',' || c == ';' || c == '='; } + + +BString +BUrl::_UrlMimeType() const +{ + BString mime; + mime << "application/x-vnd.Be.URL." << fProtocol; + + return BString(mime); +} ############################################################################ Commit: a5330a8e41fab3b82f43d3e0d454f7abfa7b9174 URL: http://cgit.haiku-os.org/haiku/commit/?id=a5330a8 Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Wed Jul 2 21:24:57 2014 UTC Remove private support kit BUrl Use the public BUrl from the network kit instead. ---------------------------------------------------------------------------- diff --git a/headers/private/support/Url.h b/headers/private/support/Url.h deleted file mode 100644 index f7ba3e4..0000000 --- a/headers/private/support/Url.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2007-2009 Haiku Inc. All rights reserved. - * Distributed under the terms of the MIT License. - */ -#ifndef _URL_H -#define _URL_H - -#include <String.h> - - -namespace BPrivate { -namespace Support { - -class BUrl : public BString { -public: - BUrl(const char* url); - ~BUrl(); - - status_t InitCheck() const; - - bool HasPreferredApplication() const; - BString PreferredApplication() const; - status_t OpenWithPreferredApplication( - bool onProblemAskUser = true) const; - - bool HasHost() const; - bool HasPort() const; - bool HasUser() const; - bool HasPass() const; - bool HasPath() const; - - const BString& Proto() const; - const BString& Full() const; - const BString& Host() const; - const BString& Port() const; - const BString& User() const; - const BString& Pass() const; - const BString& Path() const; - -private: - status_t _ParseAndSplit(); - BString _UrlMimeType() const; - - BString fProto; - BString fFull; - BString fHost; - BString fPort; - BString fUser; - BString fPass; - BString fPath; - status_t fStatus; -}; - -} // namespace Support -} // namespace BPrivate - -#endif // _URL_H - diff --git a/src/apps/haikudepot/PackageInfoView.cpp b/src/apps/haikudepot/PackageInfoView.cpp index b84414c..d7062bc 100644 --- a/src/apps/haikudepot/PackageInfoView.cpp +++ b/src/apps/haikudepot/PackageInfoView.cpp @@ -24,8 +24,7 @@ #include <SpaceLayoutItem.h> #include <StatusBar.h> #include <StringView.h> - -#include <support/Url.h> +#include <Url.h> #include "BitmapButton.h" #include "BitmapView.h" @@ -930,7 +929,7 @@ public: case MSG_VISIT_PUBLISHER_WEBSITE: { - BPrivate::Support::BUrl url(fWebsiteLinkView->Text()); + BUrl url(fWebsiteLinkView->Text()); url.OpenWithPreferredApplication(); break; } diff --git a/src/bin/Jamfile b/src/bin/Jamfile index fea1367..9f67550 100644 --- a/src/bin/Jamfile +++ b/src/bin/Jamfile @@ -93,7 +93,6 @@ StdBinCommands message.cpp modifiers.cpp mvattr.cpp - open.cpp play.cpp query.cpp quit.cpp @@ -130,6 +129,12 @@ StdBinCommands ramdisk.cpp : libshared.a be $(TARGET_LIBSUPC++) : $(haiku-utils_rsrc) ; +# standard commands that need libbe.so, libbnetapi.solibsupc++.so +StdBinCommands + open.cpp + urlwrapper.cpp + : be bnetapi $(TARGET_LIBSUPC++) : $(haiku-utils_rsrc) ; + # commands that need libbe.so and the stub catalog StdBinCommands clockconfig.cpp @@ -221,10 +226,10 @@ StdBinCommands : be libbluetooth.so $(TARGET_LIBSUPC++) : $(haiku-utils_rsrc) ; -# standard commands that need libbe.so, libtracker.so +# standard commands that need libbe.so, libbnetapi.so, libtracker.so StdBinCommands checkitout.cpp - : be tracker $(TARGET_LIBSUPC++) : $(haiku-utils_rsrc) ; + : be bnetapi tracker $(TARGET_LIBSUPC++) : $(haiku-utils_rsrc) ; #standard commands that need libbe.so, libtracker.so and the stub catalog StdBinCommands diff --git a/src/bin/checkitout.cpp b/src/bin/checkitout.cpp index c068706..bc38a93 100644 --- a/src/bin/checkitout.cpp +++ b/src/bin/checkitout.cpp @@ -119,19 +119,19 @@ CheckItOut::ArgvReceived(int32 argc, char** argv) return; } - BPrivate::Support::BUrl url(argv[1]); + BUrl url(argv[1]); fUrlString = url; - BString full = url.Full(); - BString proto = url.Proto(); + BString full = BUrl(url).SetProtocol(BString()).UrlString(); + BString proto = url.Protocol(); BString host = url.Host(); - BString port = url.Port(); - BString user = url.User(); - BString pass = url.Pass(); + BString port = BString() << url.Port(); + BString user = url.UserInfo(); + BString pass = url.Password(); BString path = url.Path(); - if (url.InitCheck() < 0) { - fprintf(stderr, "malformed url: '%s'\n", url.String()); + if (!url.IsValid()) { + fprintf(stderr, "malformed url: '%s'\n", url.UrlString().String()); return; } @@ -158,15 +158,15 @@ CheckItOut::_DoCheckItOut(entry_ref *ref, const char *name) const char* pausec = " ; read -p 'Press any key'"; char* args[] = { (char *)"/bin/sh", (char *)"-c", NULL, NULL}; - BPrivate::Support::BUrl url(fUrlString.String()); - BString full = url.Full(); - BString proto = url.Proto(); + BUrl url(fUrlString); + BString full = BUrl(url).SetProtocol(BString()).UrlString(); + BString proto = url.Protocol(); BString host = url.Host(); - BString port = url.Port(); - BString user = url.User(); - BString pass = url.Pass(); + BString port = BString() << url.Port(); + BString user = url.UserInfo(); + BString pass = url.Password(); BString path = url.Path(); - PRINT(("url %s\n", url.String())); + PRINT(("url %s\n", url.UrlString().String())); BPath refPath(ref); if (proto == "git") { diff --git a/src/bin/open.cpp b/src/bin/open.cpp index 648573c..252fb65 100644 --- a/src/bin/open.cpp +++ b/src/bin/open.cpp @@ -96,7 +96,7 @@ main(int argc, char** argv) result = B_OK; } else if (strchr(*argv, ':')) { // try to open it as an URI - BPrivate::Support::BUrl url(*argv); + BUrl url(*argv); if (url.OpenWithPreferredApplication() == B_OK) continue; diff --git a/src/bin/urlwrapper.cpp b/src/bin/urlwrapper.cpp index 389549d..9fea225 100644 --- a/src/bin/urlwrapper.cpp +++ b/src/bin/urlwrapper.cpp @@ -117,10 +117,10 @@ UrlWrapper::RefsReceived(BMessage* msg) } } if (url.Length()) { - BPrivate::Support::BUrl u(url.String()); - args[1] = (char*)u.String(); + BUrl u(url.String()); + args[1] = (char*)u.UrlString().String(); mimetype = kURLHandlerSigBase; - mimetype += u.Proto(); + mimetype += u.Protocol(); err = be_roster->Launch(mimetype.String(), 1, args + 1); if (err != B_OK && err != B_ALREADY_RUNNING) err = be_roster->Launch(kAppSig, 1, args + 1); @@ -185,10 +185,10 @@ UrlWrapper::RefsReceived(BMessage* msg) } } if (url.Length()) { - BPrivate::Support::BUrl u(url.String()); - args[1] = (char*)u.String(); + BUrl u(url.String()); + args[1] = (char*)u.UrlString().String(); mimetype = kURLHandlerSigBase; - mimetype += u.Proto(); + mimetype += u.Protocol(); err = be_roster->Launch(mimetype.String(), 1, args + 1); if (err != B_OK && err != B_ALREADY_RUNNING) err = be_roster->Launch(kAppSig, 1, args + 1); @@ -199,10 +199,10 @@ UrlWrapper::RefsReceived(BMessage* msg) // NetPositive Bookmark or any file with a META:url attribute if (f.ReadAttr("META:url", B_STRING_TYPE, 0LL, buff, B_PATH_NAME_LENGTH) > 0) { - BPrivate::Support::BUrl u(buff); - args[1] = (char*)u.String(); + BUrl u(buff); + args[1] = (char*)u.UrlString().String(); mimetype = kURLHandlerSigBase; - mimetype += u.Proto(); + mimetype += u.Protocol(); err = be_roster->Launch(mimetype.String(), 1, args + 1); if (err != B_OK && err != B_ALREADY_RUNNING) err = be_roster->Launch(kAppSig, 1, args + 1); @@ -224,18 +224,18 @@ UrlWrapper::ArgvReceived(int32 argc, char** argv) char* args[] = { (char *)"/bin/sh", (char *)"-c", NULL, NULL}; status_t err; - BPrivate::Support::BUrl url(argv[1]); + BUrl url(argv[1]); - BString full = url.Full(); - BString proto = url.Proto(); + BString full = BUrl(url).SetProtocol(BString()).UrlString(); + BString proto = url.Protocol(); BString host = url.Host(); - BString port = url.Port(); - BString user = url.User(); - BString pass = url.Pass(); + BString port = BString() << url.Port(); + BString user = url.UserInfo(); + BString pass = url.Password(); BString path = url.Path(); - if (url.InitCheck() < 0) { - fprintf(stderr, "malformed url: '%s'\n", url.String()); + if (!url.IsValid()) { + fprintf(stderr, "malformed url: '%s'\n", url.UrlString().String()); return; } @@ -266,7 +266,7 @@ UrlWrapper::ArgvReceived(int32 argc, char** argv) if (proto == "telnet") { BString cmd("telnet "); - if (url.HasUser()) + if (url.HasUserInfo()) cmd << "-l " << user << " "; cmd << host; if (url.HasPort()) @@ -283,7 +283,7 @@ UrlWrapper::ArgvReceived(int32 argc, char** argv) if (proto == "ssh") { BString cmd("ssh "); - if (url.HasUser()) + if (url.HasUserInfo()) cmd << "-l " << user << " "; if (url.HasPort()) cmd << "-oPort=" << port << " "; @@ -320,7 +320,7 @@ UrlWrapper::ArgvReceived(int32 argc, char** argv) //cmd << url; if (url.HasPort()) cmd << "-oPort=" << port << " "; - if (url.HasUser()) + if (url.HasUserInfo()) cmd << user << "@"; cmd << host; if (url.HasPath()) @@ -336,7 +336,7 @@ UrlWrapper::ArgvReceived(int32 argc, char** argv) if (proto == "finger") { BString cmd("/bin/finger "); - if (url.HasUser()) + if (url.HasUserInfo()) cmd << user; if (url.HasHost() == 0) host = "127.0.0.1"; @@ -354,7 +354,7 @@ UrlWrapper::ArgvReceived(int32 argc, char** argv) //cmd << url; cmd << proto << "://"; - if (url.HasUser()) + if (url.HasUserInfo()) cmd << user << "@"; cmd << full; PRINT(("CMD='%s'\n", cmd.String())); @@ -414,7 +414,7 @@ UrlWrapper::ArgvReceived(int32 argc, char** argv) if (proto == "sh") { BString cmd(full); - if (_Warn(url.String()) != B_OK) + if (_Warn(url.UrlString()) != B_OK) return; PRINT(("CMD='%s'\n", cmd.String())); cmd << pausec; @@ -463,7 +463,7 @@ UrlWrapper::ArgvReceived(int32 argc, char** argv) } if (proto == "mms" || proto == "rtp" || proto == "rtsp") { - args[0] = (char*)url.String(); + args[0] = (char*)url.UrlString().String(); be_roster->Launch(kVLCSig, 1, args); return; } @@ -509,12 +509,12 @@ UrlWrapper::ArgvReceived(int32 argc, char** argv) BString mimetype; url << full; - BPrivate::Support::BUrl u(url.String()); + BUrl u(url.String()); args[0] = const_cast<char*>("urlwrapper"); //XXX - args[1] = (char*)u.String(); + args[1] = (char*)u.UrlString().String(); args[2] = NULL; mimetype = kURLHandlerSigBase; - mimetype += u.Proto(); + mimetype += u.Protocol(); err = be_roster->Launch(mimetype.String(), 1, args + 1); if (err != B_OK && err != B_ALREADY_RUNNING) diff --git a/src/kits/support/Jamfile b/src/kits/support/Jamfile index 08f41fa..43007f4 100644 --- a/src/kits/support/Jamfile +++ b/src/kits/support/Jamfile @@ -35,7 +35,6 @@ for architectureObject in [ MultiArchSubDirSetup ] { StopWatch.cpp String.cpp StringList.cpp - Url.cpp Uuid.cpp ZlibCompressionAlgorithm.cpp ; diff --git a/src/kits/support/Url.cpp b/src/kits/support/Url.cpp deleted file mode 100644 index bfe9965..0000000 --- a/src/kits/support/Url.cpp +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright 2007-2009 Haiku, Inc. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * François Revol, revol@xxxxxxx - * Jonas Sundström, jonas@xxxxxxxxxxx - */ - -/*! Url class for parsing an URL and opening it with its preferred handler. */ - - -#include <Debug.h> -#include <MimeType.h> -#include <Roster.h> -#include <StorageDefs.h> - -#include <Url.h> - - -namespace BPrivate { -namespace Support { - -BUrl::BUrl(const char* url) - : BString(url) -{ - fStatus = _ParseAndSplit(); -} - - -BUrl::~BUrl() -{ -} - - -status_t -BUrl::InitCheck() const -{ - return fStatus; -} - - -bool -BUrl::HasPreferredApplication() const -{ - BString appSignature = PreferredApplication(); - BMimeType mime(appSignature.String()); - - if (appSignature.IFindFirst("application/") == 0 - && mime.IsValid()) - return true; - - return false; -} - - -BString -BUrl::PreferredApplication() const -{ - BString appSignature; - BMimeType mime(_UrlMimeType().String()); - mime.GetPreferredApp(appSignature.LockBuffer(B_MIME_TYPE_LENGTH)); - appSignature.UnlockBuffer(); - - return BString(appSignature); -} - - -status_t -BUrl::OpenWithPreferredApplication(bool onProblemAskUser) const -{ - status_t status = InitCheck(); - if (status != B_OK) - return status; - - if (Length() > B_PATH_NAME_LENGTH) { - // TODO: BAlert - // if (onProblemAskUser) - // BAlert ... Too long URL! -#if DEBUG - fprintf(stderr, "URL too long"); -#endif - return B_NAME_TOO_LONG; - } - - char* argv[] = { - const_cast<char*>("BUrlInvokedApplication"), - const_cast<char*>(String()), - NULL - }; - -#if DEBUG - if (HasPreferredApplication()) - printf("HasPreferredApplication() == true\n"); - else - printf("HasPreferredApplication() == false\n"); -#endif - - status = be_roster->Launch(_UrlMimeType().String(), 1, argv+1); - if (status != B_OK) { -#if DEBUG - fprintf(stderr, "Opening URL failed: %s\n", strerror(status)); -#endif - } - - return status; -} - - -status_t -BUrl::_ParseAndSplit() -{ - // proto:[//]user:pass@host:port/path - - int32 v; - BString left; - - v = FindFirst(":"); - if (v < 0) - return B_BAD_VALUE; - - // TODO: proto and host should be lowercased. - // see http://en.wikipedia.org/wiki/URL_normalization - - CopyInto(fProto, 0, v); - CopyInto(left, v + 1, Length() - v); - // TODO: RFC1738 says the // part should indicate the uri follows the - // u:p@h:p/path convention, so it should be used to check for special cases. - if (left.FindFirst("//") == 0) - left.RemoveFirst("//"); - fFull = left; - - // path part - // actually some apps handle file://[host]/path - // but I have no idea what proto it implies... - // or maybe it's just to emphasize on "localhost". - v = left.FindFirst("/"); - if (v == 0 || fProto == "file") { - fPath = left; - return B_OK; - } - // some protos actually implies path if it's the only component - if ((v < 0) && (fProto == "beshare" || fProto == "irc")) { - fPath = left; - return B_OK; - } - - if (v > -1) { - left.MoveInto(fPath, v+1, left.Length()-v); - left.Remove(v, 1); - } - - // user:pass@host - v = left.FindFirst("@"); - if (v > -1) { - left.MoveInto(fUser, 0, v); - left.Remove(0, 1); - v = fUser.FindFirst(":"); - if (v > -1) { - fUser.MoveInto(fPass, v, fUser.Length() - v); - fPass.Remove(0, 1); - } - } else if (fProto == "finger") { - // single component implies user - // see also: http://www.subir.com/lynx/lynx_help/lynx_url_support.html - fUser = left; - return B_OK; - } - - // host:port - v = left.FindFirst(":"); - if (v > -1) { - left.MoveInto(fPort, v + 1, left.Length() - v); - left.Remove(v, 1); - } - - // not much left... - fHost = left; - - return B_OK; -} - - -BString -BUrl::_UrlMimeType() const -{ - BString mime; - mime << "application/x-vnd.Be.URL." << fProto; - - return BString(mime); -} - - -bool -BUrl::HasHost() const -{ - return fHost.Length(); -} - - -bool -BUrl::HasPort() const -{ - return fPort.Length(); -} - - -bool -BUrl::HasUser() const -{ - return fUser.Length(); -} - - -bool -BUrl::HasPass() const -{ - return fPass.Length(); -} - - -bool -BUrl::HasPath() const -{ - return fPath.Length(); -} - - -const BString& -BUrl::Proto() const -{ - return fProto; -} - - -const BString& -BUrl::Full() const -{ - // RFC1738's "sheme-part" - return fFull; -} - - -const BString& -BUrl::Host() const -{ - return fHost; -} - - -const BString& -BUrl::Port() const -{ - return fPort; -} - - -const BString& -BUrl::User() const -{ - return fUser; -} - - -const BString& -BUrl::Pass() const -{ - return fPass; -} - - -const BString& -BUrl::Path() const -{ - return fPath; -} - -} // namespace Support -} // namespace BPrivate ############################################################################ Commit: c666db88ef91c7213689f75a52fc1e4bda680f07 URL: http://cgit.haiku-os.org/haiku/commit/?id=c666db8 Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Thu Jul 3 11:28:59 2014 UTC BZlibCompressionAlgorithm: Missing NULL check ---------------------------------------------------------------------------- diff --git a/src/kits/support/ZlibCompressionAlgorithm.cpp b/src/kits/support/ZlibCompressionAlgorithm.cpp index 9aaaf26..f49a781 100644 --- a/src/kits/support/ZlibCompressionAlgorithm.cpp +++ b/src/kits/support/ZlibCompressionAlgorithm.cpp @@ -221,7 +221,8 @@ struct BZlibCompressionAlgorithm::Stream : BaseClass { status_t Init(const typename Strategy::Parameters* parameters) { - status_t error = this->BaseClass::Init(parameters->BufferSize()); + status_t error = this->BaseClass::Init( + parameters != NULL ? parameters->BufferSize() : kDefaultBufferSize); if (error != B_OK) return error; ############################################################################ Revision: hrev47461 Commit: b04949711d8c74533fb3ef57bfdb738686c70a9e URL: http://cgit.haiku-os.org/haiku/commit/?id=b049497 Author: Ingo Weinhold <ingo_weinhold@xxxxxx> Date: Thu Jul 3 12:34:45 2014 UTC BUrl::IsValid(): Replace with a slightly better dummy impl ---------------------------------------------------------------------------- diff --git a/src/kits/network/libnetapi/Url.cpp b/src/kits/network/libnetapi/Url.cpp index 783e723..0acc611 100644 --- a/src/kits/network/libnetapi/Url.cpp +++ b/src/kits/network/libnetapi/Url.cpp @@ -476,8 +476,8 @@ BUrl::Fragment() const bool BUrl::IsValid() const { - // TODO - return false; + // TODO: Implement for real! + return fHasProtocol && (fHasHost || fHasPath); }