An old tool of mine that handles several url mime types, allowing to redirect urls to commands line tools.

Currently supported are telnet:, ssh: and ftp:. Now you should be able to click telnet://towel.blinkenlights.nl on a webpage or in Vision :)
TODO: Jamfile; handle ":port" in urls.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20037 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol 2007-02-02 06:29:42 +00:00
parent f70737c108
commit 50575d9edb
4 changed files with 378 additions and 0 deletions

122
src/bin/urlwrapper/makefile Normal file
View File

@ -0,0 +1,122 @@
## BeOS Generic Makefile v2.2 ##
## Fill in this file to specify the project being created, and the referenced
## makefile-engine will do all of the hard work for you. This handles both
## Intel and PowerPC builds of the BeOS.
## Application Specific Settings ---------------------------------------------
# specify the name of the binary
NAME= urlwrapper
# specify the type of binary
# APP: Application
# SHARED: Shared library or add-on
# STATIC: Static library archive
# DRIVER: Kernel Driver
TYPE= APP
# add support for new Pe and Eddie features
# to fill in generic makefile
#%{
# @src->@
# specify the source files to use
# full paths or paths relative to the makefile can be included
# all files, regardless of directory, will have their object
# files created in the common object directory.
# Note that this means this makefile will not work correctly
# if two source files with the same name (source.c or source.cpp)
# are included from different directories. Also note that spaces
# in folder names do not work well with this makefile.
SRCS= urlwrapper.cpp
# specify the resource files to use
# full path or a relative path to the resource file can be used.
RSRCS= urlwrapper-res.rsrc
#RDEFS= urlwrapper-res.rdef
# @<-src@
#%}
# end support for Pe and Eddie
# specify additional libraries to link against
# there are two acceptable forms of library specifications
# - if your library follows the naming pattern of:
# libXXX.so or libXXX.a you can simply specify XXX
# library: libbe.so entry: be
#
# - if your library does not follow the standard library
# naming scheme you need to specify the path to the library
# and it's name
# library: my_lib.a entry: my_lib.a or path/my_lib.a
LIBS= be
# specify additional paths to directories following the standard
# libXXX.so or libXXX.a naming scheme. You can specify full paths
# or paths relative to the makefile. The paths included may not
# be recursive, so include all of the paths where libraries can
# be found. Directories where source files are found are
# automatically included.
LIBPATHS=
# additional paths to look for system headers
# thes use the form: #include <header>
# source file directories are NOT auto-included here
SYSTEM_INCLUDE_PATHS =
# additional paths to look for local headers
# thes use the form: #include "header"
# source file directories are automatically included
LOCAL_INCLUDE_PATHS =
# specify the level of optimization that you desire
# NONE, SOME, FULL
OPTIMIZE=
# specify any preprocessor symbols to be defined. The symbols will not
# have their values set automatically; you must supply the value (if any)
# to use. For example, setting DEFINES to "DEBUG=1" will cause the
# compiler option "-DDEBUG=1" to be used. Setting DEFINES to "DEBUG"
# would pass "-DDEBUG" on the compiler's command line.
DEFINES=
# specify special warning levels
# if unspecified default warnings will be used
# NONE = supress all warnings
# ALL = enable all warnings
WARNINGS =
# specify whether image symbols will be created
# so that stack crawls in the debugger are meaningful
# if TRUE symbols will be created
SYMBOLS =
# specify debug settings
# if TRUE will allow application to be run from a source-level
# debugger. Note that this will disable all optimzation.
DEBUGGER =
# specify additional compiler flags for all files
COMPILER_FLAGS =
# specify additional linker flags
LINKER_FLAGS =
# specify the version of this particular item
# (for example, -app 3 4 0 d 0 -short 340 -long "340 "`echo -n -e '\302\251'`"1999 GNU GPL")
# This may also be specified in a resource.
APP_VERSION =
# (for TYPE == DRIVER only) Specify desired location of driver in the /dev
# hierarchy. Used by the driverinstall rule. E.g., DRIVER_PATH = video/usb will
# instruct the driverinstall rule to place a symlink to your driver's binary in
# ~/add-ons/kernel/drivers/dev/video/usb, so that your driver will appear at
# /dev/video/usb when loaded. Default is "misc".
DRIVER_PATH =
## include the makefile-engine
include $(BUILDHOME)/etc/makefile-engine

View File

@ -0,0 +1,37 @@
resource(1, "BEOS:APP_SIG") #'MIMS' "application/x-vnd.mmu_man.telnetwrapper";
resource(1, "BEOS:FILE_TYPES") message
{
"types" = "application/x-vnd.Be.URL.telnet",
"types" = "application/x-vnd.Be.URL.ssh",
"types" = "application/x-vnd.Be-URL.ftp"
};
resource(1, "BEOS:APP_VERSION") #'APPV' array
{
$"0000000000000000010000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000"
};
resource(1, "BEOS:APP_FLAGS") #'APPF' $"04000000";

Binary file not shown.

View File

@ -0,0 +1,219 @@
#include <Application.h>
#include <AppFileInfo.h>
#include <Mime.h>
#include <Message.h>
#include <TypeConstants.h>
#include <Roster.h>
#include <String.h>
#include <stdio.h>
#include <unistd.h>
#define PROTO "telnet"
class TWApp : public BApplication
{
public:
TWApp();
~TWApp();
status_t SplitUrlHostUserPass(const char *url, BString &host, BString &user, BString &pass);
virtual void ArgvReceived(int32 argc, char **argv);
virtual void ReadyToRun(void);
private:
};
const char *app_mime = "application/x-vnd.mmu_man.telnetwrapper";
//const char *url_mime = "application/x-vnd.Be.URL.telnet";
const char *url_mime = B_URL_TELNET;
const char *terminal_sig = "application/x-vnd.Be-SHEL";
TWApp::TWApp() : BApplication(app_mime)
{
BMimeType mt(url_mime);
if (mt.InitCheck())
return;
if (!mt.IsInstalled()) {
mt.Install();
}
#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
}
TWApp::~TWApp()
{
}
// XXX: handle ":port" as well
status_t TWApp::SplitUrlHostUserPass(const char *url, BString &host, BString &user, BString &pass)
{
host = url;
if (host.FindFirst("@") > -1) {
printf("%s -- %s\n", host.String(), user.String());
host.MoveInto(user, 0, host.FindFirst("@"));
host.Remove(0, 1);
if (user.FindFirst(":") > -1) {
user.MoveInto(pass, user.FindFirst(":"), user.Length());
pass.Remove(0, 1);
return 3;
}
printf("%s -- %s\n", host.String(), user.String());
return 2;
}
return 1;
}
void TWApp::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)
return;
char *args[] = { "/bin/sh", "-c", NULL, NULL};
BString host;
BString user;
BString pass;
BString url(argv[1]);
// XXX: should factorize that
if (url.FindFirst("telnet:") == 0) {
url.RemoveFirst("telnet:");
if (url.FindFirst("//") == 0)
url.RemoveFirst("//");
const char *failc = " || read -p 'Press any key'";
BString cmd("telnet ");
SplitUrlHostUserPass(url.String(), host, user, pass);
printf("HOST='%s'\n", host.String());
printf("USER='%s'\n", user.String());
printf("PASS='%s'\n", pass.String());
if (user.Length())
cmd << "-l " << user << " ";
cmd << host;
printf("CMD='%s'\n", cmd.String());
cmd << failc;
args[2] = (char *)cmd.String();
be_roster->Launch(terminal_sig, 3, args);
return;
}
if (url.FindFirst("ssh:") == 0) {
url.RemoveFirst("ssh:");
if (url.FindFirst("//") == 0)
url.RemoveFirst("//");
const char *failc = " || read -p 'Press any key'";
BString cmd("ssh ");
SplitUrlHostUserPass(url.String(), host, user, pass);
printf("HOST='%s'\n", host.String());
printf("USER='%s'\n", user.String());
printf("PASS='%s'\n", pass.String());
if (user.Length())
cmd << "-l " << user << " ";
cmd << host;
printf("CMD='%s'\n", cmd.String());
cmd << failc;
args[2] = (char *)cmd.String();
be_roster->Launch(terminal_sig, 3, args);
// XXX: handle errors
return;
}
if (url.FindFirst("ftp:") == 0) {
url.RemoveFirst("ftp:");
if (url.FindFirst("//") == 0)
url.RemoveFirst("//");
const char *failc = " || read -p 'Press any key'";
BString cmd("ftp ");
/*
SplitUrlHostUserPass(url.String(), host, user, pass);
printf("HOST='%s'\n", host.String());
printf("USER='%s'\n", user.String());
printf("PASS='%s'\n", pass.String());
if (user.Length())
cmd << "-l " << user << " ";
cmd << host;
*/
cmd << url;
printf("CMD='%s'\n", cmd.String());
cmd << failc;
args[2] = (char *)cmd.String();
be_roster->Launch(terminal_sig, 3, args);
// XXX: handle errors
return;
}
if (url.FindFirst("sftp:") == 0) {
url.RemoveFirst("sftp:");
if (url.FindFirst("//") == 0)
url.RemoveFirst("//");
const char *failc = " || read -p 'Press any key'";
BString cmd("sftp ");
/*
SplitUrlHostUserPass(url.String(), host, user, pass);
printf("HOST='%s'\n", host.String());
printf("USER='%s'\n", user.String());
printf("PASS='%s'\n", pass.String());
if (user.Length())
cmd << "-l " << user << " ";
cmd << host;
*/
cmd << url;
printf("CMD='%s'\n", cmd.String());
cmd << failc;
args[2] = (char *)cmd.String();
be_roster->Launch(terminal_sig, 3, args);
// XXX: handle errors
return;
}
// finger:user@host
// vnc: ?
// irc: ?
//
// file: -> Tracker ?
// svn: ?
// cvs: ?
// mms: -> VLC
// rtsp: -> VLC
// rtp: -> VLC
}
void TWApp::ReadyToRun(void)
{
Quit();
}
int main(int argc, char **argv)
{
TWApp app;
if (be_app)
app.Run();
return 0;
}