Hopefully fixed indentation in BUrl header. Made data members in BUrl private. Added some class methods. Adapted urlwrapper to use the BUrl class. Removed a few obvious comments and some code that was defined away. Turned off debugging. Stripped App suffix from class name. No intentional changes to the core functionality of urlwrapper.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30739 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -12,34 +12,43 @@ namespace Support {
|
|||||||
|
|
||||||
class BUrl : public BString {
|
class BUrl : public BString {
|
||||||
public:
|
public:
|
||||||
BUrl(const char *url);
|
BUrl(const char *url);
|
||||||
~BUrl();
|
~BUrl();
|
||||||
|
|
||||||
status_t ParseAndSplit();
|
status_t InitCheck() const;
|
||||||
status_t InitCheck() const;
|
|
||||||
|
|
||||||
bool HasHost() const;
|
bool HasPreferredApplication() const;
|
||||||
bool HasPort() const;
|
BString PreferredApplication() const;
|
||||||
bool HasUser() const;
|
status_t OpenWithPreferredApplication(bool onProblemAskUser = true) const;
|
||||||
bool HasPass() const;
|
|
||||||
bool HasPath() const;
|
|
||||||
|
|
||||||
BString Proto() const;
|
bool HasHost() const;
|
||||||
BString Full() const;
|
bool HasPort() const;
|
||||||
BString Host() const;
|
bool HasUser() const;
|
||||||
BString Port() const;
|
bool HasPass() const;
|
||||||
BString User() const;
|
bool HasPath() const;
|
||||||
BString Pass() const;
|
|
||||||
|
BString Proto() const;
|
||||||
|
BString Full() const;
|
||||||
|
BString Host() const;
|
||||||
|
BString Port() const;
|
||||||
|
BString User() const;
|
||||||
|
BString Pass() const;
|
||||||
|
BString Path() const;
|
||||||
|
|
||||||
|
status_t UnurlString(BString &string);
|
||||||
|
|
||||||
BString proto;
|
|
||||||
BString full;
|
|
||||||
BString host;
|
|
||||||
BString port;
|
|
||||||
BString user;
|
|
||||||
BString pass;
|
|
||||||
BString path;
|
|
||||||
private:
|
private:
|
||||||
status_t fStatus;
|
status_t _ParseAndSplit();
|
||||||
|
BString _UrlMimeType() const;
|
||||||
|
|
||||||
|
BString proto;
|
||||||
|
BString full;
|
||||||
|
BString host;
|
||||||
|
BString port;
|
||||||
|
BString user;
|
||||||
|
BString pass;
|
||||||
|
BString path;
|
||||||
|
status_t fStatus;
|
||||||
};
|
};
|
||||||
|
|
||||||
}; // namespace Support
|
}; // namespace Support
|
||||||
|
|||||||
+94
-143
@@ -4,30 +4,23 @@
|
|||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* François Revol, [email protected]
|
* François Revol, [email protected]
|
||||||
|
* Jonas Sundström, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* urlwrapper: wraps URL mime types around command line apps
|
* urlwrapper: wraps URL mime types around command line apps
|
||||||
* or other apps that don't handle them directly.
|
* or other apps that don't handle them directly.
|
||||||
*/
|
*/
|
||||||
#define DEBUG 1
|
#define DEBUG 0
|
||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <AppFileInfo.h>
|
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
#include <Mime.h>
|
#include <NodeInfo.h>
|
||||||
#include <Message.h>
|
|
||||||
#include <TypeConstants.h>
|
|
||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <Url.h>
|
#include <Url.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
/* compile-time configuration */
|
|
||||||
#include "urlwrapper.h"
|
#include "urlwrapper.h"
|
||||||
|
|
||||||
const char *kAppSig = APP_SIGNATURE;
|
const char *kAppSig = APP_SIGNATURE;
|
||||||
@@ -52,81 +45,32 @@ const char *kVLCSig = "application/x-vnd.videolan-vlc";
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
class UrlWrapperApp : public BApplication
|
class UrlWrapper : public BApplication
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UrlWrapperApp();
|
UrlWrapper();
|
||||||
~UrlWrapperApp();
|
~UrlWrapper();
|
||||||
status_t SplitUrl(const char *url, BString &host, BString &port, BString &user, BString &pass, BString &path);
|
|
||||||
status_t UnurlString(BString &s);
|
|
||||||
status_t Warn(const char *url);
|
|
||||||
virtual void RefsReceived(BMessage *msg);
|
|
||||||
virtual void ArgvReceived(int32 argc, char **argv);
|
|
||||||
virtual void ReadyToRun(void);
|
|
||||||
private:
|
|
||||||
|
|
||||||
|
virtual void RefsReceived(BMessage *msg);
|
||||||
|
virtual void ArgvReceived(int32 argc, char **argv);
|
||||||
|
virtual void ReadyToRun(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
status_t _Warn(const char *url);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
status_t UrlWrapperApp::SplitUrl(const char *url, BString &host, BString &port, BString &user, BString &pass, BString &path)
|
UrlWrapper::UrlWrapper() : BApplication(kAppSig)
|
||||||
{
|
|
||||||
BPrivate::Support::BUrl u(url);
|
|
||||||
if (u.InitCheck() < 0)
|
|
||||||
return u.InitCheck();
|
|
||||||
host = u.host;
|
|
||||||
port = u.port;
|
|
||||||
user = u.user;
|
|
||||||
pass = u.pass;
|
|
||||||
path = u.path;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
UrlWrapperApp::UrlWrapperApp() : BApplication(kAppSig)
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
BMimeType mt(B_URL_TELNET);
|
|
||||||
if (mt.InitCheck())
|
|
||||||
return;
|
|
||||||
if (!mt.IsInstalled()) {
|
|
||||||
mt.Install();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if 0
|
|
||||||
BAppFileInfo afi;
|
|
||||||
if (!afi.Supports(&mt)) {
|
|
||||||
//printf("adding support for telnet url\n");
|
|
||||||
BMessage typemsg;
|
|
||||||
typemsg.AddString("types", url_mime);
|
|
||||||
afi.SetSupportedTypes(&typemsg, true);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
UrlWrapperApp::~UrlWrapperApp()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
UrlWrapper::~UrlWrapper()
|
||||||
status_t UrlWrapperApp::UnurlString(BString &s)
|
|
||||||
{
|
{
|
||||||
// TODO: check for %00 and bail out!
|
|
||||||
int32 length = s.Length();
|
|
||||||
int i;
|
|
||||||
for (i = 0; s[i] && i < length - 2; i++) {
|
|
||||||
if (s[i] == '%' && isxdigit(s[i+1]) && isxdigit(s[i+2])) {
|
|
||||||
int c;
|
|
||||||
sscanf(s.String() + i + 1, "%02x", &c);
|
|
||||||
s.Remove(i, 3);
|
|
||||||
s.Insert((char)c, 1, i);
|
|
||||||
length -= 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t UrlWrapperApp::Warn(const char *url)
|
|
||||||
|
status_t UrlWrapper::_Warn(const char *url)
|
||||||
{
|
{
|
||||||
BString message("An application has requested the system to open the following url: \n");
|
BString message("An application has requested the system to open the following url: \n");
|
||||||
message << "\n" << url << "\n\n";
|
message << "\n" << url << "\n\n";
|
||||||
@@ -140,7 +84,8 @@ status_t UrlWrapperApp::Warn(const char *url)
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UrlWrapperApp::RefsReceived(BMessage *msg)
|
|
||||||
|
void UrlWrapper::RefsReceived(BMessage *msg)
|
||||||
{
|
{
|
||||||
char buff[B_PATH_NAME_LENGTH];
|
char buff[B_PATH_NAME_LENGTH];
|
||||||
int32 index = 0;
|
int32 index = 0;
|
||||||
@@ -206,13 +151,9 @@ void UrlWrapperApp::RefsReceived(BMessage *msg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UrlWrapperApp::ArgvReceived(int32 argc, char **argv)
|
|
||||||
|
void UrlWrapper::ArgvReceived(int32 argc, char **argv)
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
for (int i = 1; i < argc; i++) {
|
|
||||||
//printf("argv[%d]=%s\n", i, argv[i]);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (argc <= 1)
|
if (argc <= 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -220,28 +161,36 @@ void UrlWrapperApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
const char *pausec = " ; read -p 'Press any key'";
|
const char *pausec = " ; read -p 'Press any key'";
|
||||||
char *args[] = { "/bin/sh", "-c", NULL, NULL};
|
char *args[] = { "/bin/sh", "-c", NULL, NULL};
|
||||||
|
|
||||||
BPrivate::Support::BUrl u(argv[1]);
|
BPrivate::Support::BUrl url(argv[1]);
|
||||||
BString url = u.Full();
|
|
||||||
if (u.InitCheck() < 0) {
|
BString full = url.Full();
|
||||||
fprintf(stderr, "malformed url: '%s'\n", u.String());
|
BString proto = url.Proto();
|
||||||
|
BString host = url.Host();
|
||||||
|
BString port = url.Port();
|
||||||
|
BString user = url.User();
|
||||||
|
BString pass = url.Pass();
|
||||||
|
BString path = url.Path();
|
||||||
|
|
||||||
|
if (url.InitCheck() < 0) {
|
||||||
|
fprintf(stderr, "malformed url: '%s'\n", url.String());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: debug
|
// XXX: debug
|
||||||
PRINT(("PROTO='%s'\n", u.proto.String()));
|
PRINT(("PROTO='%s'\n", proto.String()));
|
||||||
PRINT(("HOST='%s'\n", u.host.String()));
|
PRINT(("HOST='%s'\n", host.String()));
|
||||||
PRINT(("PORT='%s'\n", u.port.String()));
|
PRINT(("PORT='%s'\n", port.String()));
|
||||||
PRINT(("USER='%s'\n", u.user.String()));
|
PRINT(("USER='%s'\n", user.String()));
|
||||||
PRINT(("PASS='%s'\n", u.pass.String()));
|
PRINT(("PASS='%s'\n", pass.String()));
|
||||||
PRINT(("PATH='%s'\n", u.path.String()));
|
PRINT(("PATH='%s'\n", path.String()));
|
||||||
|
|
||||||
if (u.proto == "telnet") {
|
if (proto == "telnet") {
|
||||||
BString cmd("telnet ");
|
BString cmd("telnet ");
|
||||||
if (u.HasUser())
|
if (url.HasUser())
|
||||||
cmd << "-l " << u.user << " ";
|
cmd << "-l " << user << " ";
|
||||||
cmd << u.host;
|
cmd << host;
|
||||||
if (u.HasPort())
|
if (url.HasPort())
|
||||||
cmd << " " << u.port;
|
cmd << " " << port;
|
||||||
PRINT(("CMD='%s'\n", cmd.String()));
|
PRINT(("CMD='%s'\n", cmd.String()));
|
||||||
cmd << failc;
|
cmd << failc;
|
||||||
args[2] = (char *)cmd.String();
|
args[2] = (char *)cmd.String();
|
||||||
@@ -250,14 +199,14 @@ void UrlWrapperApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// see draft: http://tools.ietf.org/wg/secsh/draft-ietf-secsh-scp-sftp-ssh-uri/
|
// see draft: http://tools.ietf.org/wg/secsh/draft-ietf-secsh-scp-sftp-ssh-uri/
|
||||||
if (u.proto == "ssh") {
|
if (proto == "ssh") {
|
||||||
BString cmd("ssh ");
|
BString cmd("ssh ");
|
||||||
|
|
||||||
if (u.HasUser())
|
if (url.HasUser())
|
||||||
cmd << "-l " << u.user << " ";
|
cmd << "-l " << user << " ";
|
||||||
if (u.HasPort())
|
if (url.HasPort())
|
||||||
cmd << "-oPort=" << u.port << " ";
|
cmd << "-oPort=" << port << " ";
|
||||||
cmd << u.host;
|
cmd << host;
|
||||||
PRINT(("CMD='%s'\n", cmd.String()));
|
PRINT(("CMD='%s'\n", cmd.String()));
|
||||||
cmd << failc;
|
cmd << failc;
|
||||||
args[2] = (char *)cmd.String();
|
args[2] = (char *)cmd.String();
|
||||||
@@ -266,7 +215,7 @@ void UrlWrapperApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (u.proto == "ftp") {
|
if (proto == "ftp") {
|
||||||
BString cmd("ftp ");
|
BString cmd("ftp ");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -274,7 +223,7 @@ void UrlWrapperApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
cmd << "-l " << user << " ";
|
cmd << "-l " << user << " ";
|
||||||
cmd << host;
|
cmd << host;
|
||||||
*/
|
*/
|
||||||
cmd << u.full;
|
cmd << full;
|
||||||
PRINT(("CMD='%s'\n", cmd.String()));
|
PRINT(("CMD='%s'\n", cmd.String()));
|
||||||
cmd << failc;
|
cmd << failc;
|
||||||
args[2] = (char *)cmd.String();
|
args[2] = (char *)cmd.String();
|
||||||
@@ -283,17 +232,17 @@ void UrlWrapperApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (u.proto == "sftp") {
|
if (proto == "sftp") {
|
||||||
BString cmd("sftp ");
|
BString cmd("sftp ");
|
||||||
|
|
||||||
//cmd << url;
|
//cmd << url;
|
||||||
if (u.HasPort())
|
if (url.HasPort())
|
||||||
cmd << "-oPort=" << u.port << " ";
|
cmd << "-oPort=" << port << " ";
|
||||||
if (u.HasUser())
|
if (url.HasUser())
|
||||||
cmd << u.user << "@";
|
cmd << user << "@";
|
||||||
cmd << u.host;
|
cmd << host;
|
||||||
if (u.HasPath())
|
if (url.HasPath())
|
||||||
cmd << ":" << u.path;
|
cmd << ":" << path;
|
||||||
PRINT(("CMD='%s'\n", cmd.String()));
|
PRINT(("CMD='%s'\n", cmd.String()));
|
||||||
cmd << failc;
|
cmd << failc;
|
||||||
args[2] = (char *)cmd.String();
|
args[2] = (char *)cmd.String();
|
||||||
@@ -302,14 +251,14 @@ void UrlWrapperApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (u.proto == "finger") {
|
if (proto == "finger") {
|
||||||
BString cmd("/bin/finger ");
|
BString cmd("/bin/finger ");
|
||||||
|
|
||||||
if (u.HasUser())
|
if (url.HasUser())
|
||||||
cmd << u.user;
|
cmd << user;
|
||||||
if (u.HasHost() == 0)
|
if (url.HasHost() == 0)
|
||||||
u.host = "127.0.0.1";
|
host = "127.0.0.1";
|
||||||
cmd << "@" << u.host;
|
cmd << "@" << host;
|
||||||
PRINT(("CMD='%s'\n", cmd.String()));
|
PRINT(("CMD='%s'\n", cmd.String()));
|
||||||
cmd << pausec;
|
cmd << pausec;
|
||||||
args[2] = (char *)cmd.String();
|
args[2] = (char *)cmd.String();
|
||||||
@@ -319,13 +268,13 @@ void UrlWrapperApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HANDLE_HTTP_WGET
|
#ifdef HANDLE_HTTP_WGET
|
||||||
if (u.proto == "http") {
|
if (proto == "http") {
|
||||||
BString cmd("/bin/wget ");
|
BString cmd("/bin/wget ");
|
||||||
|
|
||||||
//cmd << url;
|
//cmd << url;
|
||||||
if (u.HasUser())
|
if (url.HasUser())
|
||||||
cmd << u.user << "@";
|
cmd << user << "@";
|
||||||
cmd << u.full;
|
cmd << full;
|
||||||
PRINT(("CMD='%s'\n", cmd.String()));
|
PRINT(("CMD='%s'\n", cmd.String()));
|
||||||
cmd << pausec;
|
cmd << pausec;
|
||||||
args[2] = (char *)cmd.String();
|
args[2] = (char *)cmd.String();
|
||||||
@@ -336,11 +285,11 @@ void UrlWrapperApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HANDLE_FILE
|
#ifdef HANDLE_FILE
|
||||||
if (u.proto == "file") {
|
if (proto == "file") {
|
||||||
BMessage m(B_REFS_RECEIVED);
|
BMessage m(B_REFS_RECEIVED);
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
UnurlString(u.path);
|
url.UnurlString(path);
|
||||||
if (get_ref_for_path(u.path.String(), &ref) < B_OK)
|
if (get_ref_for_path(path.String(), &ref) < B_OK)
|
||||||
return;
|
return;
|
||||||
m.AddRef("refs", &ref);
|
m.AddRef("refs", &ref);
|
||||||
be_roster->Launch(kTrackerSig, &m);
|
be_roster->Launch(kTrackerSig, &m);
|
||||||
@@ -350,7 +299,7 @@ void UrlWrapperApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
|
|
||||||
#ifdef HANDLE_QUERY
|
#ifdef HANDLE_QUERY
|
||||||
// XXX:TODO: split options
|
// XXX:TODO: split options
|
||||||
if (u.proto == "query") {
|
if (proto == "query") {
|
||||||
// mktemp ?
|
// mktemp ?
|
||||||
BString qname("/tmp/query-url-temp-");
|
BString qname("/tmp/query-url-temp-");
|
||||||
qname << getpid() << "-" << system_time();
|
qname << getpid() << "-" << system_time();
|
||||||
@@ -360,14 +309,14 @@ void UrlWrapperApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
BString s;
|
BString s;
|
||||||
int32 v;
|
int32 v;
|
||||||
|
|
||||||
UnurlString(u.full);
|
url.UnurlString(full);
|
||||||
// TODO: handle options (list of attrs in the column, ...)
|
// TODO: handle options (list of attrs in the column, ...)
|
||||||
|
|
||||||
v = 'qybF'; // QuerY By Formula XXX: any #define for that ?
|
v = 'qybF'; // QuerY By Formula XXX: any #define for that ?
|
||||||
query.WriteAttr("_trk/qryinitmode", B_INT32_TYPE, 0LL, &v, sizeof(v));
|
query.WriteAttr("_trk/qryinitmode", B_INT32_TYPE, 0LL, &v, sizeof(v));
|
||||||
s = "TextControl";
|
s = "TextControl";
|
||||||
query.WriteAttr("_trk/focusedView", B_STRING_TYPE, 0LL, s.String(), s.Length()+1);
|
query.WriteAttr("_trk/focusedView", B_STRING_TYPE, 0LL, s.String(), s.Length()+1);
|
||||||
s = u.full;
|
s = full;
|
||||||
PRINT(("QUERY='%s'\n", s.String()));
|
PRINT(("QUERY='%s'\n", s.String()));
|
||||||
query.WriteAttr("_trk/qryinitstr", B_STRING_TYPE, 0LL, s.String(), s.Length()+1);
|
query.WriteAttr("_trk/qryinitstr", B_STRING_TYPE, 0LL, s.String(), s.Length()+1);
|
||||||
query.WriteAttr("_trk/qrystr", B_STRING_TYPE, 0LL, s.String(), s.Length()+1);
|
query.WriteAttr("_trk/qrystr", B_STRING_TYPE, 0LL, s.String(), s.Length()+1);
|
||||||
@@ -384,9 +333,9 @@ void UrlWrapperApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HANDLE_SH
|
#ifdef HANDLE_SH
|
||||||
if (u.proto == "sh") {
|
if (proto == "sh") {
|
||||||
BString cmd(u.Full());
|
BString cmd(full);
|
||||||
if (Warn(u.String()) != B_OK)
|
if (_Warn(url.String()) != B_OK)
|
||||||
return;
|
return;
|
||||||
PRINT(("CMD='%s'\n", cmd.String()));
|
PRINT(("CMD='%s'\n", cmd.String()));
|
||||||
cmd << pausec;
|
cmd << pausec;
|
||||||
@@ -398,23 +347,23 @@ void UrlWrapperApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HANDLE_BESHARE
|
#ifdef HANDLE_BESHARE
|
||||||
if (u.proto == "beshare") {
|
if (proto == "beshare") {
|
||||||
team_id team;
|
team_id team;
|
||||||
BMessenger msgr(kBeShareSig);
|
BMessenger msgr(kBeShareSig);
|
||||||
// if no instance is running, or we want a specific server, start it.
|
// if no instance is running, or we want a specific server, start it.
|
||||||
if (!msgr.IsValid() || u.HasHost()) {
|
if (!msgr.IsValid() || url.HasHost()) {
|
||||||
be_roster->Launch(kBeShareSig, (BMessage *)NULL, &team);
|
be_roster->Launch(kBeShareSig, (BMessage *)NULL, &team);
|
||||||
msgr = BMessenger(NULL, team);
|
msgr = BMessenger(NULL, team);
|
||||||
}
|
}
|
||||||
if (u.HasHost()) {
|
if (url.HasHost()) {
|
||||||
BMessage mserver('serv');
|
BMessage mserver('serv');
|
||||||
mserver.AddString("server", u.host);
|
mserver.AddString("server", host);
|
||||||
msgr.SendMessage(&mserver);
|
msgr.SendMessage(&mserver);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (u.HasPath()) {
|
if (url.HasPath()) {
|
||||||
BMessage mquery('quer');
|
BMessage mquery('quer');
|
||||||
mquery.AddString("query", u.path);
|
mquery.AddString("query", path);
|
||||||
msgr.SendMessage(&mquery);
|
msgr.SendMessage(&mquery);
|
||||||
}
|
}
|
||||||
// TODO: handle errors
|
// TODO: handle errors
|
||||||
@@ -423,14 +372,14 @@ void UrlWrapperApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HANDLE_IM
|
#ifdef HANDLE_IM
|
||||||
if (u.proto == "icq" || u.proto == "msn") {
|
if (proto == "icq" || proto == "msn") {
|
||||||
// TODO
|
// TODO
|
||||||
team_id team;
|
team_id team;
|
||||||
be_roster->Launch(kIMSig, (BMessage *)NULL, &team);
|
be_roster->Launch(kIMSig, (BMessage *)NULL, &team);
|
||||||
BMessenger msgr(NULL, team);
|
BMessenger msgr(NULL, team);
|
||||||
if (u.HasHost()) {
|
if (url.HasHost()) {
|
||||||
BMessage mserver(B_REFS_RECEIVED);
|
BMessage mserver(B_REFS_RECEIVED);
|
||||||
mserver.AddString("server", u.host);
|
mserver.AddString("server", host);
|
||||||
msgr.SendMessage(&httpmserver);
|
msgr.SendMessage(&httpmserver);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -440,8 +389,8 @@ void UrlWrapperApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HANDLE_VLC
|
#ifdef HANDLE_VLC
|
||||||
if (u.proto == "mms" || u.proto == "rtp" || u.proto == "rtsp") {
|
if (proto == "mms" || proto == "rtp" || proto == "rtsp") {
|
||||||
args[0] = (char *)u.String();
|
args[0] = (char *)url.String();
|
||||||
be_roster->Launch(kVLCSig, 1, args);
|
be_roster->Launch(kVLCSig, 1, args);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -468,14 +417,16 @@ void UrlWrapperApp::ArgvReceived(int32 argc, char **argv)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UrlWrapperApp::ReadyToRun(void)
|
|
||||||
|
void UrlWrapper::ReadyToRun(void)
|
||||||
{
|
{
|
||||||
Quit();
|
Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
UrlWrapperApp app;
|
UrlWrapper app;
|
||||||
if (be_app)
|
if (be_app)
|
||||||
app.Run();
|
app.Run();
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -6,19 +6,11 @@
|
|||||||
* François Revol, [email protected]
|
* François Revol, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* urlwrapper: compile-time configuration of supported protocols.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define APP_SIGNATURE "application/x-vnd.Haiku-urlwrapper"
|
#define APP_SIGNATURE "application/x-vnd.Haiku-urlwrapper"
|
||||||
|
|
||||||
/*
|
|
||||||
* comment out to disable handling a specific protocol
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/* NetPositive Bookmark file type */
|
/* NetPositive Bookmark file type */
|
||||||
#define HANDLE_BOOKMARK_FILES
|
#define HANDLE_BOOKMARK_FILES
|
||||||
|
|
||||||
/* M$IE .url files */
|
/* M$IE .url files */
|
||||||
#define HANDLE_URL_FILES
|
#define HANDLE_URL_FILES
|
||||||
|
|
||||||
@@ -52,3 +44,4 @@
|
|||||||
/* audio: redirects SoundPlay-urls for shoutcast streams */
|
/* audio: redirects SoundPlay-urls for shoutcast streams */
|
||||||
/* UNIMPLEMENTED */
|
/* UNIMPLEMENTED */
|
||||||
//#define HANDLE_AUDIO
|
//#define HANDLE_AUDIO
|
||||||
|
|
||||||
|
|||||||
+113
-3
@@ -9,8 +9,18 @@
|
|||||||
|
|
||||||
/*! Url class for parsing an URL and opening it with its preferred handler. */
|
/*! Url class for parsing an URL and opening it with its preferred handler. */
|
||||||
|
|
||||||
|
#define DEBUG 0
|
||||||
|
|
||||||
#include "Url.h"
|
#include <ctype.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <Debug.h>
|
||||||
|
#include <MimeType.h>
|
||||||
|
#include <Roster.h>
|
||||||
|
#include <StorageDefs.h>
|
||||||
|
|
||||||
|
#include <Url.h>
|
||||||
|
|
||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
namespace Support {
|
namespace Support {
|
||||||
@@ -18,7 +28,7 @@ namespace Support {
|
|||||||
BUrl::BUrl(const char *url)
|
BUrl::BUrl(const char *url)
|
||||||
: BString(url)
|
: BString(url)
|
||||||
{
|
{
|
||||||
fStatus = ParseAndSplit();
|
fStatus = _ParseAndSplit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -34,8 +44,71 @@ BUrl::InitCheck() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
status_t
|
||||||
BUrl::ParseAndSplit()
|
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!
|
||||||
|
fprintf(stderr, "URL too long");
|
||||||
|
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) {
|
||||||
|
fprintf(stderr, "Opening URL failed: %s\n", strerror(status));
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BUrl::_ParseAndSplit()
|
||||||
{
|
{
|
||||||
// proto:[//]user:pass@host:port/path
|
// proto:[//]user:pass@host:port/path
|
||||||
|
|
||||||
@@ -107,6 +180,16 @@ BUrl::ParseAndSplit()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BString
|
||||||
|
BUrl::_UrlMimeType() const
|
||||||
|
{
|
||||||
|
BString mime;
|
||||||
|
mime << "application/x-vnd.Be.URL." << proto;
|
||||||
|
|
||||||
|
return BString(mime);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BUrl::HasHost() const
|
BUrl::HasHost() const
|
||||||
{
|
{
|
||||||
@@ -184,6 +267,33 @@ BUrl::Pass() const
|
|||||||
return BString(pass);
|
return BString(pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BString
|
||||||
|
BUrl::Path() const
|
||||||
|
{
|
||||||
|
return BString(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BUrl::UnurlString(BString &string)
|
||||||
|
{
|
||||||
|
// TODO: check for %00 and bail out!
|
||||||
|
int32 length = string.Length();
|
||||||
|
int i;
|
||||||
|
for (i = 0; string[i] && i < length - 2; i++) {
|
||||||
|
if (string[i] == '%' && isxdigit(string[i+1]) && isxdigit(string[i+2])) {
|
||||||
|
int c;
|
||||||
|
sscanf(string.String() + i + 1, "%02x", &c);
|
||||||
|
string.Remove(i, 3);
|
||||||
|
string.Insert((char)c, 1, i);
|
||||||
|
length -= 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
}; // namespace Support
|
}; // namespace Support
|
||||||
}; // namespace BPrivate
|
}; // namespace BPrivate
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user