From 78839568813e768d3a92f4f9ee950b1b5343f5f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Sat, 10 Apr 2010 23:54:22 +0000 Subject: [PATCH] - try to handle .webloc internet shortcut files from OSX, - build uri scheme mimetype from the actual protocol specifier in the url, - fallback to calling ourselves if no prefered app is set. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36124 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/bin/urlwrapper.cpp | 102 +++++++++++++++++++++++++++++++++++++--- src/bin/urlwrapper.rdef | 1 + 2 files changed, 96 insertions(+), 7 deletions(-) diff --git a/src/bin/urlwrapper.cpp b/src/bin/urlwrapper.cpp index 832ebdfff0..4feea967a4 100644 --- a/src/bin/urlwrapper.cpp +++ b/src/bin/urlwrapper.cpp @@ -34,6 +34,8 @@ const char* kBeShareSig = "application/x-vnd.Sugoi-BeShare"; const char* kIMSig = "application/x-vnd.m_eiman.sample_im_client"; const char* kVLCSig = "application/x-vnd.videolan-vlc"; +const char* kURLHandlerSigBase = "application/x-vnd.Be.URL."; + UrlWrapper::UrlWrapper() : BApplication(kAppSig) { @@ -77,20 +79,25 @@ UrlWrapper::RefsReceived(BMessage* msg) BFile f(&ref, B_READ_ONLY); BNodeInfo ni(&f); BString mimetype; + BString extension(ref.name); + extension.Remove(0, extension.FindLast('.') + 1); +printf("e:%s\n", extension.String()); if (f.InitCheck() == B_OK && ni.InitCheck() == B_OK) { ni.GetType(mimetype.LockBuffer(B_MIME_TYPE_LENGTH)); mimetype.UnlockBuffer(); // Internet Explorer Shortcut - if (mimetype == "text/x-url") { + if (mimetype == "text/x-url" || extension == "url") { // http://filext.com/file-extension/URL // http://www.cyanwerks.com/file-format-url.html off_t size; if (f.GetSize(&size) < B_OK) continue; - BString contents, url; + BString contents; + BString url; if (f.ReadAt(0LL, contents.LockBuffer(size), size) < B_OK) continue; + contents.UnlockBuffer(); while (contents.Length()) { BString line; int32 cr = contents.FindFirst('\n'); @@ -108,9 +115,85 @@ UrlWrapper::RefsReceived(BMessage* msg) } } if (url.Length()) { - args[1] = (char*)url.String(); - err = be_roster->Launch("application/x-vnd.Be.URL.http", 1, - args+1); + BPrivate::Support::BUrl u(url.String()); + args[1] = (char*)u.String(); + mimetype = kURLHandlerSigBase; + mimetype += u.Proto(); + err = be_roster->Launch(mimetype.String(), 1, args+1); + if (err < B_OK) + err = be_roster->Launch(kAppSig, 1, args+1); + continue; + } + } + if (mimetype == "text/x-webloc" || extension == "webloc") { + // OSX url shortcuts + // XML file + resource fork + off_t size; + if (f.GetSize(&size) < B_OK) + continue; + BString contents; + BString url; + if (f.ReadAt(0LL, contents.LockBuffer(size), size) < B_OK) + continue; + contents.UnlockBuffer(); + int state = 0; + while (contents.Length()) { + BString line; + int32 cr = contents.FindFirst('\n'); + if (cr < 0) + cr = contents.Length(); + //contents.MoveInto(line, 0, cr); + contents.CopyInto(line, 0, cr); + contents.Remove(0, cr+1); + line.RemoveAll("\r"); + if (!line.Length()) + continue; + int32 s, e; + switch (state) { + case 0: + if (!line.ICompare("", 6)) + state = 3; + break; + case 3: + if (line.IFindFirst("URL") > -1) + state = 4; + break; + case 4: + if ((s = line.IFindFirst("")) > -1 && (e = line.IFindFirst("")) > s) { + state = 5; + s += 8; + line.MoveInto(url, s, e - s); + break; + } else + state = 3; + break; + + break; + default: + break; + } + if (state == 5) { + break; + } + } + if (url.Length()) { + BPrivate::Support::BUrl u(url.String()); + args[1] = (char*)u.String(); + mimetype = kURLHandlerSigBase; + mimetype += u.Proto(); + printf("sig:'%s'\n", mimetype.String()); + printf("url:'%s'\n", u.String()); + err = be_roster->Launch(mimetype.String(), 1, args+1); + if (err < B_OK) + err = be_roster->Launch(kAppSig, 1, args+1); continue; } } @@ -118,8 +201,13 @@ 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) { - err = be_roster->Launch("application/x-vnd.Be.URL.http", 1, - args+1); + BPrivate::Support::BUrl u(buff); + args[1] = (char*)u.String(); + mimetype = kURLHandlerSigBase; + mimetype += u.Proto(); + err = be_roster->Launch(mimetype.String(), 1, args+1); + if (err < B_OK) + err = be_roster->Launch(kAppSig, 1, args+1); continue; } } diff --git a/src/bin/urlwrapper.rdef b/src/bin/urlwrapper.rdef index f74f5b6e10..f432fa88d0 100644 --- a/src/bin/urlwrapper.rdef +++ b/src/bin/urlwrapper.rdef @@ -6,6 +6,7 @@ resource(1, "BEOS:FILE_TYPES") message { "types" = "application/x-vnd.Be-bookmark", "types" = "text/x-url", + "types" = "text/x-webloc", "types" = "application/x-vnd.Be.URL.file", "types" = "application/x-vnd.Be.URL.http", "types" = "application/x-vnd.Be.URL.query",