aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/arch
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2018-06-04 21:05:54 -0400
committerLibravatarUnit 193 <unit193@ubuntu.com>2018-06-04 21:05:54 -0400
commit4d1efbbd1aa971401202bb1bd436742c57170980 (patch)
treea3eb68d768223982546ee6bf35bd533b1e0905bc /src/lib/arch
parent5f6625ebd476340745d578b08620dbe4d27d1a9b (diff)
parent4a8bfd06e73d7f051f0b39e19e57616c7bbb8ad1 (diff)
Update upstream source from tag 'upstream/2.1.1+dfsg'
Update to upstream version '2.1.1+dfsg' with Debian dir fae8a5463c58b9ee303cb04f24606a56a5a08fba
Diffstat (limited to 'src/lib/arch')
-rw-r--r--src/lib/arch/Arch.h3
-rw-r--r--src/lib/arch/IArchFile.h105
-rw-r--r--src/lib/arch/unix/ArchFileUnix.cpp163
-rw-r--r--src/lib/arch/unix/ArchFileUnix.h47
-rw-r--r--src/lib/arch/unix/ArchNetworkBSD.cpp9
-rw-r--r--src/lib/arch/win32/ArchFileWindows.cpp203
-rw-r--r--src/lib/arch/win32/ArchFileWindows.h47
-rw-r--r--src/lib/arch/win32/ArchNetworkWinsock.cpp12
8 files changed, 13 insertions, 576 deletions
diff --git a/src/lib/arch/Arch.h b/src/lib/arch/Arch.h
index 42a73c2..c062d6f 100644
--- a/src/lib/arch/Arch.h
+++ b/src/lib/arch/Arch.h
@@ -40,7 +40,6 @@
#if SYSAPI_WIN32
# include "arch/win32/ArchConsoleWindows.h"
# include "arch/win32/ArchDaemonWindows.h"
-# include "arch/win32/ArchFileWindows.h"
# include "arch/win32/ArchLogWindows.h"
# include "arch/win32/ArchMiscWindows.h"
# include "arch/win32/ArchMultithreadWindows.h"
@@ -54,7 +53,6 @@
#elif SYSAPI_UNIX
# include "arch/unix/ArchConsoleUnix.h"
# include "arch/unix/ArchDaemonUnix.h"
-# include "arch/unix/ArchFileUnix.h"
# include "arch/unix/ArchLogUnix.h"
# if HAVE_PTHREAD
# include "arch/unix/ArchMultithreadPosix.h"
@@ -86,7 +84,6 @@ typically at the beginning of \c main().
*/
class Arch : public ARCH_CONSOLE,
public ARCH_DAEMON,
- public ARCH_FILE,
public ARCH_LOG,
public ARCH_MULTITHREAD,
public ARCH_NETWORK,
diff --git a/src/lib/arch/IArchFile.h b/src/lib/arch/IArchFile.h
deleted file mode 100644
index 5fdd288..0000000
--- a/src/lib/arch/IArchFile.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * barrier -- mouse and keyboard sharing utility
- * Copyright (C) 2012-2016 Symless Ltd.
- * Copyright (C) 2002 Chris Schoeneman
- *
- * This package is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * found in the file LICENSE that should have accompanied this file.
- *
- * This package 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 for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#pragma once
-
-#include "common/IInterface.h"
-#include "common/stdstring.h"
-#include "base/String.h"
-
-//! Interface for architecture dependent file system operations
-/*!
-This interface defines the file system operations required by
-barrier. Each architecture must implement this interface.
-*/
-class IArchFile : public IInterface {
-public:
- //! @name manipulators
- //@{
-
- //! Extract base name
- /*!
- Find the base name in the given \c pathname.
- */
- virtual const char* getBasename(const char* pathname) = 0;
-
- //! Get user's home directory
- /*!
- Returns the user's home directory. Returns the empty string if
- this cannot be determined.
- */
- virtual std::string getUserDirectory() = 0;
-
- //! Get system directory
- /*!
- Returns the ussystem configuration file directory.
- */
- virtual std::string getSystemDirectory() = 0;
-
- //! Get installed directory
- /*!
- Returns the directory in which Barrier is installed.
- */
- virtual std::string getInstalledDirectory() = 0;
-
- //! Get log directory
- /*!
- Returns the log file directory.
- */
- virtual std::string getLogDirectory() = 0;
-
- //! Get plugins directory
- /*!
- Returns the plugin files directory. If no plugin directory is set,
- this will return the plugin folder within the user's profile.
- */
- virtual std::string getPluginDirectory() = 0;
-
- //! Get user's profile directory
- /*!
- Returns the user's profile directory. If no profile directory is set,
- this will return the user's profile according to the operating system,
- which will depend on which user launched the program.
- */
- virtual std::string getProfileDirectory() = 0;
-
- //! Concatenate path components
- /*!
- Concatenate pathname components with a directory separator
- between them. This should not check if the resulting path
- is longer than allowed by the system; we'll rely on the
- system calls to tell us that.
- */
- virtual std::string concatPath(
- const std::string& prefix,
- const std::string& suffix) = 0;
-
- //@}
- //! Set the user's profile directory
- /*
- Returns the user's profile directory.
- */
- virtual void setProfileDirectory(const String& s) = 0;
-
- //@}
- //! Set the user's plugin directory
- /*
- Returns the user's plugin directory.
- */
- virtual void setPluginDirectory(const String& s) = 0;
-};
diff --git a/src/lib/arch/unix/ArchFileUnix.cpp b/src/lib/arch/unix/ArchFileUnix.cpp
deleted file mode 100644
index d9ae8b2..0000000
--- a/src/lib/arch/unix/ArchFileUnix.cpp
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * barrier -- mouse and keyboard sharing utility
- * Copyright (C) 2012-2016 Symless Ltd.
- * Copyright (C) 2002 Chris Schoeneman
- *
- * This package is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * found in the file LICENSE that should have accompanied this file.
- *
- * This package 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 for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "arch/unix/ArchFileUnix.h"
-
-#include <stdio.h>
-#include <unistd.h>
-#include <pwd.h>
-#include <sys/types.h>
-#include <cstring>
-
-//
-// ArchFileUnix
-//
-
-ArchFileUnix::ArchFileUnix()
-{
- // do nothing
-}
-
-ArchFileUnix::~ArchFileUnix()
-{
- // do nothing
-}
-
-const char*
-ArchFileUnix::getBasename(const char* pathname)
-{
- if (pathname == NULL) {
- return NULL;
- }
-
- const char* basename = strrchr(pathname, '/');
- if (basename != NULL) {
- return basename + 1;
- }
- else {
- return pathname;
- }
-}
-
-std::string
-ArchFileUnix::getUserDirectory()
-{
- char* buffer = NULL;
- std::string dir;
-#if HAVE_GETPWUID_R
- struct passwd pwent;
- struct passwd* pwentp;
-#if defined(_SC_GETPW_R_SIZE_MAX)
- long size = sysconf(_SC_GETPW_R_SIZE_MAX);
- if (size == -1) {
- size = BUFSIZ;
- }
-#else
- long size = BUFSIZ;
-#endif
- buffer = new char[size];
- getpwuid_r(getuid(), &pwent, buffer, size, &pwentp);
-#else
- struct passwd* pwentp = getpwuid(getuid());
-#endif
- if (pwentp != NULL && pwentp->pw_dir != NULL) {
- dir = pwentp->pw_dir;
- }
- delete[] buffer;
- return dir;
-}
-
-std::string
-ArchFileUnix::getSystemDirectory()
-{
- return "/etc";
-}
-
-std::string
-ArchFileUnix::getInstalledDirectory()
-{
-#if WINAPI_XWINDOWS
- return "/usr/bin";
-#else
- return "/Applications/Barrier.app/Contents/MacOS";
-#endif
-}
-
-std::string
-ArchFileUnix::getLogDirectory()
-{
- return "/var/log";
-}
-
-std::string
-ArchFileUnix::getPluginDirectory()
-{
- if (!m_pluginDirectory.empty()) {
- return m_pluginDirectory;
- }
-
-#if WINAPI_XWINDOWS
- return getProfileDirectory().append("/plugins");
-#else
- return getProfileDirectory().append("/Plugins");
-#endif
-}
-
-std::string
-ArchFileUnix::getProfileDirectory()
-{
- String dir;
- if (!m_profileDirectory.empty()) {
- dir = m_profileDirectory;
- }
- else {
-#if WINAPI_XWINDOWS
- dir = getUserDirectory().append("/.barrier");
-#else
- dir = getUserDirectory().append("/Library/Application Support/Barrier");
-#endif
- }
- return dir;
-
-}
-
-std::string
-ArchFileUnix::concatPath(const std::string& prefix,
- const std::string& suffix)
-{
- std::string path;
- path.reserve(prefix.size() + 1 + suffix.size());
- path += prefix;
- if (path.size() == 0 || path[path.size() - 1] != '/') {
- path += '/';
- }
- path += suffix;
- return path;
-}
-
-void
-ArchFileUnix::setProfileDirectory(const String& s)
-{
- m_profileDirectory = s;
-}
-
-void
-ArchFileUnix::setPluginDirectory(const String& s)
-{
- m_pluginDirectory = s;
-}
diff --git a/src/lib/arch/unix/ArchFileUnix.h b/src/lib/arch/unix/ArchFileUnix.h
deleted file mode 100644
index 86dea0c..0000000
--- a/src/lib/arch/unix/ArchFileUnix.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * barrier -- mouse and keyboard sharing utility
- * Copyright (C) 2012-2016 Symless Ltd.
- * Copyright (C) 2002 Chris Schoeneman
- *
- * This package is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * found in the file LICENSE that should have accompanied this file.
- *
- * This package 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 for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#pragma once
-
-#include "arch/IArchFile.h"
-
-#define ARCH_FILE ArchFileUnix
-
-//! Unix implementation of IArchFile
-class ArchFileUnix : public IArchFile {
-public:
- ArchFileUnix();
- virtual ~ArchFileUnix();
-
- // IArchFile overrides
- virtual const char* getBasename(const char* pathname);
- virtual std::string getUserDirectory();
- virtual std::string getSystemDirectory();
- virtual std::string getInstalledDirectory();
- virtual std::string getLogDirectory();
- virtual std::string getPluginDirectory();
- virtual std::string getProfileDirectory();
- virtual std::string concatPath(const std::string& prefix,
- const std::string& suffix);
- virtual void setProfileDirectory(const String& s);
- virtual void setPluginDirectory(const String& s);
-
-private:
- String m_profileDirectory;
- String m_pluginDirectory;
-};
diff --git a/src/lib/arch/unix/ArchNetworkBSD.cpp b/src/lib/arch/unix/ArchNetworkBSD.cpp
index 149218c..2a9259c 100644
--- a/src/lib/arch/unix/ArchNetworkBSD.cpp
+++ b/src/lib/arch/unix/ArchNetworkBSD.cpp
@@ -113,6 +113,11 @@ ArchNetworkBSD::newSocket(EAddressFamily family, ESocketType type)
}
try {
setBlockingOnSocket(fd, false);
+ if (family == kINET6) {
+ int flag = 0;
+ if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &flag, sizeof(flag)) != 0)
+ throwError(errno);
+ }
}
catch (...) {
close(fd);
@@ -647,8 +652,8 @@ ArchNetworkBSD::newAnyAddr(EAddressFamily family)
switch (family) {
case kINET: {
auto* ipAddr = TYPED_ADDR(struct sockaddr_in, addr);
+ memset(ipAddr, 0, sizeof(struct sockaddr_in));
ipAddr->sin_family = AF_INET;
- ipAddr->sin_port = 0;
ipAddr->sin_addr.s_addr = INADDR_ANY;
addr->m_len = (socklen_t)sizeof(struct sockaddr_in);
break;
@@ -656,8 +661,8 @@ ArchNetworkBSD::newAnyAddr(EAddressFamily family)
case kINET6: {
auto* ipAddr = TYPED_ADDR(struct sockaddr_in6, addr);
+ memset(ipAddr, 0, sizeof(struct sockaddr_in6));
ipAddr->sin6_family = AF_INET6;
- ipAddr->sin6_port = 0;
memcpy(&ipAddr->sin6_addr, &in6addr_any, sizeof(in6addr_any));
addr->m_len = (socklen_t)sizeof(struct sockaddr_in6);
break;
diff --git a/src/lib/arch/win32/ArchFileWindows.cpp b/src/lib/arch/win32/ArchFileWindows.cpp
deleted file mode 100644
index 53b4b59..0000000
--- a/src/lib/arch/win32/ArchFileWindows.cpp
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * barrier -- mouse and keyboard sharing utility
- * Copyright (C) 2012-2016 Symless Ltd.
- * Copyright (C) 2002 Chris Schoeneman
- *
- * This package is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * found in the file LICENSE that should have accompanied this file.
- *
- * This package 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 for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "arch/win32/ArchFileWindows.h"
-
-#define WIN32_LEAN_AND_MEAN
-#include <Windows.h>
-#include <shlobj.h>
-#include <tchar.h>
-#include <string.h>
-
-//
-// ArchFileWindows
-//
-
-ArchFileWindows::ArchFileWindows()
-{
- // do nothing
-}
-
-ArchFileWindows::~ArchFileWindows()
-{
- // do nothing
-}
-
-const char*
-ArchFileWindows::getBasename(const char* pathname)
-{
- if (pathname == NULL) {
- return NULL;
- }
-
- // check for last slash
- const char* basename = strrchr(pathname, '/');
- if (basename != NULL) {
- ++basename;
- }
- else {
- basename = pathname;
- }
-
- // check for last backslash
- const char* basename2 = strrchr(pathname, '\\');
- if (basename2 != NULL && basename2 > basename) {
- basename = basename2 + 1;
- }
-
- return basename;
-}
-
-std::string
-ArchFileWindows::getUserDirectory()
-{
- // try %HOMEPATH%
- TCHAR dir[MAX_PATH];
- DWORD size = sizeof(dir) / sizeof(TCHAR);
- DWORD result = GetEnvironmentVariable(_T("HOMEPATH"), dir, size);
- if (result != 0 && result <= size) {
- // sanity check -- if dir doesn't appear to start with a
- // drive letter and isn't a UNC name then don't use it
- // FIXME -- allow UNC names
- if (dir[0] != '\0' && (dir[1] == ':' ||
- ((dir[0] == '\\' || dir[0] == '/') &&
- (dir[1] == '\\' || dir[1] == '/')))) {
- return dir;
- }
- }
-
- // get the location of the personal files. that's as close to
- // a home directory as we're likely to find.
- ITEMIDLIST* idl;
- if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &idl))) {
- TCHAR* path = NULL;
- if (SHGetPathFromIDList(idl, dir)) {
- DWORD attr = GetFileAttributes(dir);
- if (attr != 0xffffffff && (attr & FILE_ATTRIBUTE_DIRECTORY) != 0)
- path = dir;
- }
-
- IMalloc* shalloc;
- if (SUCCEEDED(SHGetMalloc(&shalloc))) {
- shalloc->Free(idl);
- shalloc->Release();
- }
-
- if (path != NULL) {
- return path;
- }
- }
-
- // use root of C drive as a default
- return "C:";
-}
-
-std::string
-ArchFileWindows::getSystemDirectory()
-{
- // get windows directory
- char dir[MAX_PATH];
- if (GetWindowsDirectory(dir, sizeof(dir)) != 0) {
- return dir;
- }
- else {
- // can't get it. use C:\ as a default.
- return "C:";
- }
-}
-
-std::string
-ArchFileWindows::getInstalledDirectory()
-{
- char fileNameBuffer[MAX_PATH];
- GetModuleFileName(NULL, fileNameBuffer, MAX_PATH);
- std::string fileName(fileNameBuffer);
- size_t lastSlash = fileName.find_last_of("\\");
- fileName = fileName.substr(0, lastSlash);
-
- return fileName;
-}
-
-std::string
-ArchFileWindows::getLogDirectory()
-{
- return getInstalledDirectory();
-}
-
-std::string
-ArchFileWindows::getPluginDirectory()
-{
- if (!m_pluginDirectory.empty()) {
- return m_pluginDirectory;
- }
-
- std::string dir = getProfileDirectory();
- dir.append("\\Plugins");
- return dir;
-}
-
-std::string
-ArchFileWindows::getProfileDirectory()
-{
- String dir;
- if (!m_profileDirectory.empty()) {
- dir = m_profileDirectory;
- }
- else {
- TCHAR result[MAX_PATH];
- if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, result))) {
- dir = result;
- }
- else {
- dir = getUserDirectory();
- }
- }
-
- // HACK: append program name, this seems wrong.
- dir.append("\\Barrier");
-
- return dir;
-}
-
-std::string
-ArchFileWindows::concatPath(const std::string& prefix,
- const std::string& suffix)
-{
- std::string path;
- path.reserve(prefix.size() + 1 + suffix.size());
- path += prefix;
- if (path.size() == 0 ||
- (path[path.size() - 1] != '\\' &&
- path[path.size() - 1] != '/')) {
- path += '\\';
- }
- path += suffix;
- return path;
-}
-
-void
-ArchFileWindows::setProfileDirectory(const String& s)
-{
- m_profileDirectory = s;
-}
-
-void
-ArchFileWindows::setPluginDirectory(const String& s)
-{
- m_pluginDirectory = s;
-}
diff --git a/src/lib/arch/win32/ArchFileWindows.h b/src/lib/arch/win32/ArchFileWindows.h
deleted file mode 100644
index 4747b9c..0000000
--- a/src/lib/arch/win32/ArchFileWindows.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * barrier -- mouse and keyboard sharing utility
- * Copyright (C) 2012-2016 Symless Ltd.
- * Copyright (C) 2002 Chris Schoeneman
- *
- * This package is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * found in the file LICENSE that should have accompanied this file.
- *
- * This package 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 for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#pragma once
-
-#include "arch/IArchFile.h"
-
-#define ARCH_FILE ArchFileWindows
-
-//! Win32 implementation of IArchFile
-class ArchFileWindows : public IArchFile {
-public:
- ArchFileWindows();
- virtual ~ArchFileWindows();
-
- // IArchFile overrides
- virtual const char* getBasename(const char* pathname);
- virtual std::string getUserDirectory();
- virtual std::string getSystemDirectory();
- virtual std::string getInstalledDirectory();
- virtual std::string getLogDirectory();
- virtual std::string getPluginDirectory();
- virtual std::string getProfileDirectory();
- virtual std::string concatPath(const std::string& prefix,
- const std::string& suffix);
- virtual void setProfileDirectory(const String& s);
- virtual void setPluginDirectory(const String& s);
-
-private:
- String m_profileDirectory;
- String m_pluginDirectory;
-};
diff --git a/src/lib/arch/win32/ArchNetworkWinsock.cpp b/src/lib/arch/win32/ArchNetworkWinsock.cpp
index 722c4c5..4bc61d8 100644
--- a/src/lib/arch/win32/ArchNetworkWinsock.cpp
+++ b/src/lib/arch/win32/ArchNetworkWinsock.cpp
@@ -213,10 +213,10 @@ ArchNetworkWinsock::newSocket(EAddressFamily family, ESocketType type)
}
try {
setBlockingOnSocket(fd, false);
- BOOL flag = 0;
- int size = sizeof(flag);
- if (setsockopt_winsock(fd, IPPROTO_IPV6, IPV6_V6ONLY, &flag, size) == SOCKET_ERROR) {
- throwError(getsockerror_winsock());
+ if (family == kINET6) {
+ int flag = 0;
+ if (setsockopt_winsock(fd, IPPROTO_IPV6, IPV6_V6ONLY, &flag, sizeof(flag)) == SOCKET_ERROR)
+ throwError(getsockerror_winsock());
}
}
catch (...) {
@@ -685,8 +685,8 @@ ArchNetworkWinsock::newAnyAddr(EAddressFamily family)
case kINET: {
addr = ArchNetAddressImpl::alloc(sizeof(struct sockaddr_in));
auto* ipAddr = TYPED_ADDR(struct sockaddr_in, addr);
+ memset(ipAddr, 0, sizeof(struct sockaddr_in));
ipAddr->sin_family = AF_INET;
- ipAddr->sin_port = 0;
ipAddr->sin_addr.s_addr = INADDR_ANY;
break;
}
@@ -694,8 +694,8 @@ ArchNetworkWinsock::newAnyAddr(EAddressFamily family)
case kINET6: {
addr = ArchNetAddressImpl::alloc(sizeof(struct sockaddr_in6));
auto* ipAddr = TYPED_ADDR(struct sockaddr_in6, addr);
+ memset(ipAddr, 0, sizeof(struct sockaddr_in6));
ipAddr->sin6_family = AF_INET6;
- ipAddr->sin6_port = 0;
memcpy(&ipAddr->sin6_addr, &in6addr_any, sizeof(in6addr_any));
break;
}