From a5330a8e41fab3b82f43d3e0d454f7abfa7b9174 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 2 Jul 2014 23:24:57 +0200 Subject: [PATCH] Remove private support kit BUrl Use the public BUrl from the network kit instead. --- 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/support/Jamfile | 1 - src/kits/support/Url.cpp | 279 ------------------------ 8 files changed, 53 insertions(+), 387 deletions(-) delete mode 100644 headers/private/support/Url.h delete mode 100644 src/kits/support/Url.cpp diff --git a/headers/private/support/Url.h b/headers/private/support/Url.h deleted file mode 100644 index f7ba3e49a9..0000000000 --- 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 - - -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 b84414c029..d7062bc001 100644 --- a/src/apps/haikudepot/PackageInfoView.cpp +++ b/src/apps/haikudepot/PackageInfoView.cpp @@ -24,8 +24,7 @@ #include #include #include - -#include +#include #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 fea13676c0..9f67550ab3 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 c068706b36..bc38a93afc 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 648573c40b..252fb65355 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 389549d9d3..9fea225f4a 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("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 08f41fa590..43007f4a3a 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 bfe9965f5a..0000000000 --- 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@free.fr - * Jonas Sundström, jonas@kirilla.com - */ - -/*! Url class for parsing an URL and opening it with its preferred handler. */ - - -#include -#include -#include -#include - -#include - - -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("BUrlInvokedApplication"), - const_cast(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