From 67b6ccc6c4df5f545ec298731ed43fa0ad61971f Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Wed, 24 Feb 2010 11:46:38 +0000 Subject: [PATCH] Adding initial (empty) bvncrelay tool. It doesn't yet do anything. --- po/POTFILES.in | 1 + src/barry.h | 1 + tools/Makefile.am | 4 ++ tools/bvncrelay.cc | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 180 insertions(+) create mode 100644 tools/bvncrelay.cc diff --git a/po/POTFILES.in b/po/POTFILES.in index 16eadf1b..fe873af0 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -88,4 +88,5 @@ tools/btool.cc tools/bfuse.cc tools/upldif.cc tools/bjavaloader.cc +tools/bvncrelay.cc diff --git a/src/barry.h b/src/barry.h index c09af50b..4506cf30 100644 --- a/src/barry.h +++ b/src/barry.h @@ -65,6 +65,7 @@ #include "m_ipmodem.h" #include "m_serial.h" #include "m_javaloader.h" +#include "m_vnc_server.h" #include "m_jvmdebug.h" #include "version.h" #include "log.h" diff --git a/tools/Makefile.am b/tools/Makefile.am index 18cddd29..c65d783b 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -17,6 +17,7 @@ bin_PROGRAMS = \ btool \ bidentify \ bjavaloader \ + bvncrelay \ bjvmdebug \ bdptest \ bjdwp \ @@ -61,6 +62,9 @@ bidentify_LDADD = ../src/libbarry.la $(LIBUSB_LIBS) -lpthread $(LTLIBINTL) bjavaloader_SOURCES = bjavaloader.cc bjavaloader_LDADD = ../src/libbarry.la $(LIBUSB_LIBS) -lpthread $(LTLIBINTL) +bvncrelay_SOURCES = bvncrelay.cc +bvncrelay_LDADD = ../src/libbarry.la $(LIBUSB_LIBS) -lpthread + bjvmdebug_SOURCES = bjvmdebug.cc bjvmdebug_LDADD = ../src/libbarry.la $(LIBUSB_LIBS) -lpthread $(LTLIBINTL) diff --git a/tools/bvncrelay.cc b/tools/bvncrelay.cc new file mode 100644 index 00000000..f50c0aa7 --- /dev/null +++ b/tools/bvncrelay.cc @@ -0,0 +1,174 @@ +/// +/// \file bvncrelay.cc +/// +/// + +/* + Copyright (C) 2010, RealVNC Ltd. + + Some parts are inspired from bjavaloader.cc + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License in the COPYING file at the + root directory of this project for more details. +*/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "i18n.h" + +using namespace std; +using namespace Barry; + +void Usage() +{ + int major, minor; + const char *Version = Barry::Version(major, minor); + + cerr + << "bvncrelay - Command line USB Blackberry VNC Relay\n" + << " Copyright 2010, RealVNC Ltd.\n" + << " Using: " << Version << "\n" + << "\n" + << " -h This help\n" + << " -s List sibling in module list\n" + << " -p pin PIN of device to talk with\n" + << " If only one device is plugged in, this flag is optional\n" + << " -P pass Simplistic method to specify device password\n" + << " -v Dump protocol data during operation\n" + << "\n" + << "commands\n" + << endl; +} + + +int main(int argc, char *argv[]) +{ + INIT_I18N(PACKAGE); + + cout.sync_with_stdio(true); // leave this on, since libusb uses + // stdio for debug messages + + try { + + uint32_t pin = 0; + bool list_siblings = false, + data_dump = false; + string password; + vector params; + string busname; + string devname; + string iconvCharset; + Usb::EndpointPair epOverride; + + // process command line options + for(;;) { + int cmd = getopt(argc, argv, "hsp:P:v"); + if( cmd == -1 ) + break; + + switch( cmd ) + { + case 'p': // Blackberry PIN + pin = strtoul(optarg, NULL, 16); + break; + + case 'P': // Device password + password = optarg; + break; + + case 's': // turn on listing of sibling modules + list_siblings = true; + break; + + case 'v': // data dump on + data_dump = true; + break; + + case 'h': // help + default: + Usage(); + return 0; + } + } + + argc -= optind; + argv += optind; + + if( argc < 1 ) { + cerr << "missing command" << endl; + Usage(); + return 1; + } + + // Fetch command from remaining arguments + string cmd = argv[0]; + argc --; + argv ++; + + // Put the remaining arguments into an array + for (; argc > 0; argc --, argv ++) { + params.push_back(string(argv[0])); + } + + // Initialize the barry library. Must be called before + // anything else. + Barry::Init(data_dump); + + // Probe the USB bus for Blackberry devices and display. + // If user has specified a PIN, search for it in the + // available device list here as well + Barry::Probe probe; + int activeDevice = probe.FindActive(pin); + if( activeDevice == -1 ) { + cerr << "No device selected, or PIN not found" << endl; + return 1; + } + + // Create our controller object + Barry::Controller con(probe.Get(activeDevice)); + Barry::Mode::VNCServer vncrelay(con); + + // + // execute each mode that was turned on + // + vncrelay.Open(password.c_str()); + + // TODO - actually implement command + + } + catch( Usb::Error &ue) { + std::cout << endl; // flush any normal output first + std::cerr << "Usb::Error caught: " << ue.what() << endl; + return 1; + } + catch( Barry::Error &se ) { + std::cout << endl; + std::cerr << "Barry::Error caught: " << se.what() << endl; + return 1; + } + catch( std::exception &e ) { + std::cout << endl; + std::cerr << "std::exception caught: " << e.what() << endl; + return 1; + } + + return 0; +} + -- 2.11.4.GIT