Exemplo n.º 1
0
void
CServerApp::parseArgs(int argc, const char* const* argv)
{
	// asserts values, sets defaults, and parses args
	int i;
	CApp::parseArgs(argc, argv, i);

	// no non-option arguments are allowed
	if (i != argc) {
		LOG((CLOG_PRINT "%s: unrecognized option `%s'" BYE,
			args().m_pname, argv[i], args().m_pname));
		m_bye(kExitArgs);
	}

	// set log filter
	if (!CLOG->setFilter(args().m_logFilter)) {
		LOG((CLOG_PRINT "%s: unrecognized log level `%s'" BYE,
			args().m_pname, args().m_logFilter, args().m_pname));
		m_bye(kExitArgs);
	}

	// identify system
	LOG((CLOG_INFO "%s Server on %s %s", kAppVersion, ARCH->getOSName().c_str(), ARCH->getPlatformName().c_str()));

	loggingFilterWarning();
}
Exemplo n.º 2
0
void
ClientApp::parseArgs(int argc, const char* const* argv)
{
	ArgParser argParser(this);
	bool result = argParser.parseClientArgs(args(), argc, argv);

	if (!result || args().m_shouldExit) {
		m_bye(kExitArgs);
	}
	else {
		// save server address
		if (!args().m_synergyAddress.empty()) {
			try {
				*m_serverAddress = NetworkAddress(args().m_synergyAddress, kDefaultPort);
				m_serverAddress->resolve();
			}
			catch (XSocketAddress& e) {
				// allow an address that we can't look up if we're restartable.
				// we'll try to resolve the address each time we connect to the
				// server.  a bad port will never get better.  patch by Brent
				// Priddy.
				if (!args().m_restartable || e.getError() == XSocketAddress::kBadPort) {
					LOG((CLOG_PRINT "%s: %s" BYE,
						args().m_pname, e.what(), args().m_pname));
					m_bye(kExitFailed);
				}
			}
		}
	}
}
Exemplo n.º 3
0
void
CApp::parseArgs(int argc, const char* const* argv, int& i)
{
	// about these use of assert() here:
	// previously an /analyze warning was displayed if we only used assert and
	// did not return on failure. however, this warning does not appear to show
	// any more (could be because new compiler args have been added).
	// the asserts are programmer benefit only; the os should never pass 0 args,
	// because the first is always the binary name. the only way assert would
	// evaluate to true, is if this parse function were implemented incorrectly,
	// which is unlikely because it's old code and has a specific use.
	// we should avoid using anything other than assert here, because it will
	// look like important code, which it's not really.
	assert(argsBase().m_pname != NULL);
	assert(argv != NULL);
	assert(argc >= 1);


	// set defaults
	argsBase().m_name = ARCH->getHostName();
    LOG((CLOG_INFO "CApp::parseArgs call"));
	// parse options
	for (i = 1; i < argc; ++i) {

		if (parseArg(argc, argv, i)) {
			continue;
		}

		else if (isArg(i, argc, argv, "--", NULL)) {
			// remaining arguments are not options
			++i;
			break;
		}

		else if (argv[i][0] == '-') {
			std::cerr << "Unrecognized option: " << argv[i] << std::endl;
			m_bye(kExitArgs);
		}

		else {
			// this and remaining arguments are not options
			break;
		}
	}

#if SYSAPI_WIN32
	// suggest that user installs as a windows service. when launched as
	// service, process should automatically detect that it should run in
	// daemon mode.
	if (argsBase().m_daemon) {
		LOG((CLOG_ERR
			"The --daemon argument is not supported on Windows. "
			"Instead, install %s as a service (--service install).",
			argsBase().m_pname));
		m_bye(kExitArgs);
	}
#endif
}
Exemplo n.º 4
0
void
CClientApp::parseArgs(int argc, const char* const* argv)
{
    // asserts values, sets defaults, and parses args
    int i;
    CApp::parseArgs(argc, argv, i);

    // exactly one non-option argument (server-address)
    if (i == argc) {
        LOG((CLOG_PRINT "%s: a server address or name is required" BYE,
             args().m_pname, args().m_pname));
        m_bye(kExitArgs);
    }
    if (i + 1 != argc) {
        LOG((CLOG_PRINT "%s: unrecognized option `%s'" BYE,
             args().m_pname, argv[i], args().m_pname));
        m_bye(kExitArgs);
    }

    // save server address
    try {
        *args().m_serverAddress = CNetworkAddress(argv[i], kDefaultPort);
        args().m_serverAddress->resolve();
    }
    catch (XSocketAddress& e) {
        // allow an address that we can't look up if we're restartable.
        // we'll try to resolve the address each time we connect to the
        // server.  a bad port will never get better.  patch by Brent
        // Priddy.
        if (!args().m_restartable || e.getError() == XSocketAddress::kBadPort) {
            LOG((CLOG_PRINT "%s: %s" BYE,
                 args().m_pname, e.what(), args().m_pname));
            m_bye(kExitFailed);
        }
    }

    // set log filter
    if (!CLOG->setFilter(args().m_logFilter)) {
        LOG((CLOG_PRINT "%s: unrecognized log level `%s'" BYE,
             args().m_pname, args().m_logFilter, args().m_pname));
        m_bye(kExitArgs);
    }

    // identify system
    LOG((CLOG_INFO "%s Client on %s %s", kAppVersion, ARCH->getOSName().c_str(), ARCH->getPlatformName().c_str()));

    loggingFilterWarning();
}
Exemplo n.º 5
0
void
CServerApp::startNode()
{
	// start the server.  if this return false then we've failed and
	// we shouldn't retry.
	LOG((CLOG_DEBUG1 "starting server"));
	if (!startServer()) {
		m_bye(kExitFailed);
	}
}
Exemplo n.º 6
0
void 
ClientApp::startNode()
{
	// start the client.  if this return false then we've failed and
	// we shouldn't retry.
	LOG((CLOG_DEBUG1 "starting client"));
	if (!startClient()) {
		m_bye(kExitFailed);
	}
}
Exemplo n.º 7
0
void
CServerApp::parseArgs(int argc, const char* const* argv)
{
	CArgParser argParser(this);
	bool result = argParser.parseServerArgs(args(), argc, argv);

	if (!result || args().m_shouldExit) {
		m_bye(kExitArgs);
	}
	else {
		if (!args().m_synergyAddress.empty()) {
			try {
				*m_synergyAddress = CNetworkAddress(args().m_synergyAddress, 
					kDefaultPort);
				m_synergyAddress->resolve();
			}
			catch (XSocketAddress& e) {
				LOG((CLOG_PRINT "%s: %s" BYE,
					args().m_pname, e.what(), args().m_pname));
				m_bye(kExitArgs);
			}
		}
	}
}
Exemplo n.º 8
0
void 
CClientApp::startNode()
{
	if (args().m_enableVnc) {
		m_vncThread = new CThread(new TMethodJob<CClientApp>(
			this, &CClientApp::vncThread, NULL));
	}

	// start the client.  if this return false then we've failed and
	// we shouldn't retry.
	LOG((CLOG_DEBUG1 "starting client"));
	if (!startClient()) {
		m_bye(kExitFailed);
	}
}
Exemplo n.º 9
0
void
CServerApp::loadConfig()
{
	bool loaded = false;

	// load the config file, if specified
	if (!args().m_configFile.empty()) {
		loaded = loadConfig(args().m_configFile);
	}

	// load the default configuration if no explicit file given
	else {
		// get the user's home directory
		CString path = ARCH->getUserDirectory();
		if (!path.empty()) {
			// complete path
			path = ARCH->concatPath(path, USR_CONFIG_NAME);

			// now try loading the user's configuration
			if (loadConfig(path)) {
				loaded            = true;
				args().m_configFile = path;
			}
		}
		if (!loaded) {
			// try the system-wide config file
			path = ARCH->getSystemDirectory();
			if (!path.empty()) {
				path = ARCH->concatPath(path, SYS_CONFIG_NAME);
				if (loadConfig(path)) {
					loaded            = true;
					args().m_configFile = path;
				}
			}
		}
	}

	if (!loaded) {
		LOG((CLOG_PRINT "%s: no configuration available", args().m_pname));
		m_bye(kExitConfig);
	}
}
Exemplo n.º 10
0
void 
App::initApp(int argc, const char** argv)
{
    // parse command line
    parseArgs(argc, argv);

#if WINAPI_XWINDOWS
    // for use on linux, tell the core process what user id it should run as.
    // this is a simple way to allow the core process to talk to X. this avoids
    // the "WARNING: primary screen unavailable: unable to open screen" error.
    // a better way would be to use xauth cookie and dbus to get access to X.
    if (argsBase().m_runAsUid >= 0) {
        if (setuid(argsBase().m_runAsUid) == 0) {
            LOG((CLOG_DEBUG "process uid was set to: %d", argsBase().m_runAsUid));
        }
        else {
            LOG((CLOG_WARN "failed to set process uid to: %d", argsBase().m_runAsUid));
        }
    }
#endif
    
    ARCH->setProfileDirectory(argsBase().m_profileDirectory);
    ARCH->setPluginDirectory(argsBase().m_pluginDirectory);

    // set log filter
    if (!CLOG->setFilter(argsBase().m_logFilter)) {
        LOG((CLOG_PRINT "%s: unrecognized log level `%s'" BYE,
            argsBase().m_pname, argsBase().m_logFilter, argsBase().m_pname));
        m_bye(kExitArgs);
    }
    loggingFilterWarning();
    
    if (argsBase().m_enableDragDrop) {
        LOG((CLOG_INFO "drag and drop enabled"));
    }

    // setup file logging after parsing args
    setupFileLogging();

    // load configuration
    loadConfig();
}
Exemplo n.º 11
0
bool
CApp::isArg(
	int argi, int argc, const char* const* argv,
	const char* name1, const char* name2,
	int minRequiredParameters)
{
	if ((name1 != NULL && strcmp(argv[argi], name1) == 0) ||
		(name2 != NULL && strcmp(argv[argi], name2) == 0)) {
			// match.  check args left.
			if (argi + minRequiredParameters >= argc) {
				LOG((CLOG_PRINT "%s: missing arguments for `%s'" BYE,
					argsBase().m_pname, argv[argi], argsBase().m_pname));
				m_bye(kExitArgs);
			}
			return true;
	}

	// no match
	return false;
}
Exemplo n.º 12
0
void 
App::initApp(int argc, const char** argv)
{
	// parse command line
	parseArgs(argc, argv);
	
	ARCH->setProfileDirectory(argsBase().m_profileDirectory);
	ARCH->setPluginDirectory(argsBase().m_pluginDirectory);

	// set log filter
	if (!CLOG->setFilter(argsBase().m_logFilter)) {
		LOG((CLOG_PRINT "%s: unrecognized log level `%s'" BYE,
			argsBase().m_pname, argsBase().m_logFilter, argsBase().m_pname));
		m_bye(kExitArgs);
	}
	loggingFilterWarning();
	
	if (argsBase().m_enableDragDrop) {
		LOG((CLOG_INFO "drag and drop enabled"));
	}

	// setup file logging after parsing args
	setupFileLogging();

	// load configuration
	loadConfig();

	if (!argsBase().m_disableTray) {

		// create a log buffer so we can show the latest message
		// as a tray icon tooltip
		BufferedLogOutputter* logBuffer = new BufferedLogOutputter(1000);
		CLOG->insert(logBuffer, true);

		// make the task bar receiver.  the user can control this app
		// through the task bar.
		m_taskBarReceiver = m_createTaskBarReceiver(logBuffer, m_events);
	}
}
Exemplo n.º 13
0
bool
CServerApp::parseArg(const int& argc, const char* const* argv, int& i)
{
	if (CApp::parseArg(argc, argv, i)) {
		// found common arg
		return true;
	}

	else if (isArg(i, argc, argv, "-a", "--address", 1)) {
		// save listen address
		try {
			*args().m_synergyAddress = CNetworkAddress(argv[i + 1],
				kDefaultPort);
			args().m_synergyAddress->resolve();
		}
		catch (XSocketAddress& e) {
			LOG((CLOG_PRINT "%s: %s" BYE,
				args().m_pname, e.what(), args().m_pname));
			m_bye(kExitArgs);
		}
		++i;
	}

	else if (isArg(i, argc, argv, "-c", "--config", 1)) {
		// save configuration file path
		args().m_configFile = argv[++i];
	}

	else {
		// option not supported here
		return false;
	}

	// argument was valid
	return true;
}
Exemplo n.º 14
0
bool
CApp::parseArg(const int& argc, const char* const* argv, int& i)
{
    LOG((CLOG_INFO "CApp::parseArg call"));
    LOG((CLOG_INFO "CARCH->parseArg("));
	if (ARCH->parseArg(argc, argv, i)) {
		// handled by platform util
		return true;
	}

    else if (isArg(i,argc,argv, "-hw", "--helloworld",1)) {
        // custom common argument
        std::cout<<"custom argument: "<<argv[++i]<<"\n";
        m_bye(kExitArgs);
    }
	else if (isArg(i, argc, argv, "-d", "--debug", 1)) {
		// change logging level
		argsBase().m_logFilter = argv[++i];
	}

	else if (isArg(i, argc, argv, "-l", "--log", 1)) {
		argsBase().m_logFile = argv[++i];
	}

	else if (isArg(i, argc, argv, "-f", "--no-daemon")) {
		// not a daemon
		argsBase().m_daemon = false;
	}

	else if (isArg(i, argc, argv, NULL, "--daemon")) {
		// daemonize
		argsBase().m_daemon = true;
	}

	else if (isArg(i, argc, argv, "-n", "--name", 1)) {
		// save screen name
		argsBase().m_name = argv[++i];
	}

	else if (isArg(i, argc, argv, "-1", "--no-restart")) {
		// don't try to restart
		argsBase().m_restartable = false;
	}

	else if (isArg(i, argc, argv, NULL, "--restart")) {
		// try to restart
		argsBase().m_restartable = true;
	}

	else if (isArg(i, argc, argv, "-z", NULL)) {
		argsBase().m_backend = true;
	}

	else if (isArg(i, argc, argv, NULL, "--no-hooks")) {
		argsBase().m_noHooks = true;
	}

	else if (isArg(i, argc, argv, "-h", "--help")) {
		help();
		m_bye(kExitSuccess);
	}

	else if (isArg(i, argc, argv, NULL, "--version")) {
		version();
		m_bye(kExitSuccess);
	}

	else {
		// option not supported here
		return false;
	}

	return true;
}
Exemplo n.º 15
0
bool
CApp::parseArg(const int& argc, const char* const* argv, int& i)
{
	if (ARCH->parseArg(argc, argv, i)) {
		// handled by platform util
		return true;
	}
	
	else if (isArg(i, argc, argv, "-d", "--debug", 1)) {
		// change logging level
		argsBase().m_logFilter = argv[++i];
	}

	else if (isArg(i, argc, argv, "-l", "--log", 1)) {
		argsBase().m_logFile = argv[++i];
	}

	else if (isArg(i, argc, argv, "-f", "--no-daemon")) {
		// not a daemon
		argsBase().m_daemon = false;
	}

	else if (isArg(i, argc, argv, NULL, "--daemon")) {
		// daemonize
		argsBase().m_daemon = true;
	}

	else if (isArg(i, argc, argv, "-n", "--name", 1)) {
		// save screen name
		argsBase().m_name = argv[++i];
	}

	else if (isArg(i, argc, argv, "-1", "--no-restart")) {
		// don't try to restart
		argsBase().m_restartable = false;
	}

	else if (isArg(i, argc, argv, NULL, "--restart")) {
		// try to restart
		argsBase().m_restartable = true;
	}

	else if (isArg(i, argc, argv, "-z", NULL)) {
		argsBase().m_backend = true;
	}

	else if (isArg(i, argc, argv, NULL, "--no-hooks")) {
		argsBase().m_noHooks = true;
	}

	else if (isArg(i, argc, argv, "-h", "--help")) {
		help();
		m_bye(kExitSuccess);
	}

	else if (isArg(i, argc, argv, NULL, "--version")) {
		version();
		m_bye(kExitSuccess);
	}
	
	else if (isArg(i, argc, argv, NULL, "--no-tray")) {
		argsBase().m_disableTray = true;
	}

	else {
		// option not supported here
		return false;
	}

	return true;
}
Exemplo n.º 16
0
bool
CApp::parseArg(const int& argc, const char* const* argv, int& i)
{
	if (appUtil().parseArg(argc, argv, i)) {
		// handled by platform util
		return true;
	}
	
	else if (isArg(i, argc, argv, "-d", "--debug", 1)) {
		// change logging level
		argsBase().m_logFilter = argv[++i];
	}

	else if (isArg(i, argc, argv, "-l", "--log", 1)) {
		argsBase().m_logFile = argv[++i];
	}

	else if (isArg(i, argc, argv, "-f", "--no-daemon")) {
		// not a daemon
		argsBase().m_daemon = false;
	}

	else if (isArg(i, argc, argv, NULL, "--daemon")) {
		// daemonize
		argsBase().m_daemon = true;
	}

	else if (isArg(i, argc, argv, "-n", "--name", 1)) {
		// save screen name
		argsBase().m_name = argv[++i];
	}

	else if (isArg(i, argc, argv, "-1", "--no-restart")) {
		// don't try to restart
		argsBase().m_restartable = false;
	}

	else if (isArg(i, argc, argv, NULL, "--restart")) {
		// try to restart
		argsBase().m_restartable = true;
	}

	else if (isArg(i, argc, argv, "-z", NULL)) {
		argsBase().m_backend = true;
	}

	else if (isArg(i, argc, argv, NULL, "--no-hooks")) {
		argsBase().m_noHooks = true;
	}

	else if (isArg(i, argc, argv, "-h", "--help")) {
		help();
		m_bye(kExitSuccess);
	}

	else if (isArg(i, argc, argv, NULL, "--version")) {
		version();
		m_bye(kExitSuccess);
	}

	else if (isArg(i, argc, argv, "-u", "--usb-list")) {
		// enumerate compatible usb devices list
		std::cout << CUSBAddress::getConnectedCompatibleDeviceNames();
		m_bye(kExitSuccess);
	}
	
	else if (isArg(i, argc, argv, NULL, "--no-tray")) {
		argsBase().m_disableTray = true;
	}

	else if (isArg(i, argc, argv, NULL, "--ipc")) {
		argsBase().m_enableIpc = true;
	}

	else if (isArg(i, argc, argv, NULL, "--server")) {
		// HACK: stop error happening when using portable (synergyp) 
	}

	else if (isArg(i, argc, argv, NULL, "--client")) {
		// HACK: stop error happening when using portable (synergyp) 
	}

	else if (isArg(i, argc, argv, NULL, "--crypto-pass")) {
		argsBase().m_crypto.m_pass = argv[++i];
	}

	else if (isArg(i, argc, argv, NULL, "--crypto-mode")) {
		argsBase().m_crypto.setMode(argv[++i]);
	}

#if VNC_SUPPORT
	else if (isArg(i, argc, argv, NULL, "--vnc")) {
		argsBase().m_enableVnc = true;
	}
#endif

	else {
		// option not supported here
		return false;
	}

	return true;
}