id
int64
0
755k
file_name
stringlengths
3
109
file_path
stringlengths
13
185
content
stringlengths
31
9.38M
size
int64
31
9.38M
language
stringclasses
1 value
extension
stringclasses
11 values
total_lines
int64
1
340k
avg_line_length
float64
2.18
149k
max_line_length
int64
7
2.22M
alphanum_fraction
float64
0
1
repo_name
stringlengths
6
65
repo_stars
int64
100
47.3k
repo_forks
int64
0
12k
repo_open_issues
int64
0
3.4k
repo_license
stringclasses
9 values
repo_extraction_date
stringclasses
92 values
exact_duplicates_redpajama
bool
2 classes
near_duplicates_redpajama
bool
2 classes
exact_duplicates_githubcode
bool
2 classes
exact_duplicates_stackv2
bool
1 class
exact_duplicates_stackv1
bool
2 classes
near_duplicates_githubcode
bool
2 classes
near_duplicates_stackv1
bool
2 classes
near_duplicates_stackv2
bool
1 class
14,091
MockIpcServer.h
deskflow_deskflow/src/test/mock/ipc/MockIpcServer.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2015-2016 Symless Ltd. * * 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/Arch.h" #include "ipc/IpcMessage.h" #include "ipc/IpcServer.h" #include <gmock/gmock.h> using ::testing::_; using ::testing::Invoke; class IEventQueue; class MockIpcServer : public IpcServer { public: MockIpcServer() : m_sendCond(ARCH->newCondVar()), m_sendMutex(ARCH->newMutex()) { } ~MockIpcServer() { if (m_sendCond != NULL) { ARCH->closeCondVar(m_sendCond); } if (m_sendMutex != NULL) { ARCH->closeMutex(m_sendMutex); } } MOCK_METHOD(void, listen, (), (override)); MOCK_METHOD(void, send, (const IpcMessage &, IpcClientType), (override)); MOCK_METHOD(bool, hasClients, (IpcClientType), (const, override)); void delegateToFake() { ON_CALL(*this, send(_, _)).WillByDefault(Invoke(this, &MockIpcServer::mockSend)); } void waitForSend() { ARCH->waitCondVar(m_sendCond, m_sendMutex, 5); } private: void mockSend(const IpcMessage &, IpcClientType) { ArchMutexLock lock(m_sendMutex); ARCH->broadcastCondVar(m_sendCond); } ArchCond m_sendCond; ArchMutex m_sendMutex; };
1,782
C++
.h
59
27.305085
85
0.719883
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,092
MockStream.h
deskflow_deskflow/src/test/mock/io/MockStream.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2011 Nick Bolton * * 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 "io/IStream.h" #include <gmock/gmock.h> class IEventQueue; namespace { class MockStream : public deskflow::IStream { public: MockStream() { } MOCK_METHOD(void, close, (), (override)); MOCK_METHOD(UInt32, read, (void *, UInt32), (override)); MOCK_METHOD(void, write, (const void *, UInt32), (override)); MOCK_METHOD(void, flush, (), (override)); MOCK_METHOD(void, shutdownInput, (), (override)); MOCK_METHOD(void, shutdownOutput, (), (override)); MOCK_METHOD(Event::Type, getInputReadyEvent, ()); MOCK_METHOD(Event::Type, getOutputErrorEvent, ()); MOCK_METHOD(Event::Type, getInputShutdownEvent, ()); MOCK_METHOD(Event::Type, getOutputShutdownEvent, ()); MOCK_METHOD(void *, getEventTarget, (), (const, override)); MOCK_METHOD(bool, isReady, (), (const, override)); MOCK_METHOD(UInt32, getSize, (), (const, override)); }; } // namespace
1,622
C++
.h
43
35.44186
72
0.725191
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,093
ExitTimeout.h
deskflow_deskflow/src/test/shared/ExitTimeout.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2024 Symless Ltd. * * 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 <string_view> #include <thread> namespace deskflow::test { /** * @brief Exits the program after a specified timeout, unless destroyed. * * The `std::thread` class is used instead of `std::jthread` as Apple Clang has * no `std::jthread` support: https://en.cppreference.com/w/cpp/compiler_support * * TODO: Switch to regular Clang instead of Apple Clang: * https://symless.atlassian.net/browse/S1-1754 */ class ExitTimeout { public: ExitTimeout(const int minutes, const std::string_view &name); ~ExitTimeout(); void run() const; private: bool m_running = true; int m_minutes = 0; std::string_view m_name; std::unique_ptr<std::thread> m_thread; }; } // namespace deskflow::test
1,412
C++
.h
42
31.595238
80
0.746334
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,094
TestEventQueue.h
deskflow_deskflow/src/test/shared/TestEventQueue.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2013-2016 Symless Ltd. * * 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 "base/EventQueue.h" class EventQueueTimer; class TestEventQueue : public EventQueue { public: TestEventQueue() : m_pQuitTimeoutTimer(nullptr) { } void handleQuitTimeout(const Event &, void *vclient); void raiseQuitEvent(); void initQuitTimeout(double timeout); void cleanupQuitTimeout(); private: void timeoutThread(void *); private: EventQueueTimer *m_pQuitTimeoutTimer; };
1,113
C++
.h
34
30.558824
72
0.771455
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,095
undef_x11_macros.h
deskflow_deskflow/src/test/shared/undef_x11_macros.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2024 Symless Ltd. * * 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/>. */ /** * This header fixes conflicts between X11 and Google Test. * * It should be included after headers of code under test (that use X11) * and before including Google Test headers. */ #undef None // NOSONAR #undef Bool // NOSONAR
923
C++
.h
24
36.541667
72
0.755853
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,096
TestQtFullApp.h
deskflow_deskflow/src/test/shared/gui/TestQtFullApp.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2024 Symless Ltd. * * 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 <QApplication> static int argc = 0; // NOLINT NOSONAR static char **argv = nullptr; // NOLINT NOSONAR /** * Prefer using `TestQtCoreApp` instead. */ class TestQtFullApp : public QApplication { public: explicit TestQtFullApp() : QApplication(argc, argv) { #if defined(Q_OS_WIN) #error "this object causes windows ci to freeze" #endif } };
1,067
C++
.h
33
30.515152
72
0.748544
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,097
TestQtCoreApp.h
deskflow_deskflow/src/test/shared/gui/TestQtCoreApp.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2024 Symless Ltd. * * 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 <QCoreApplication> static int argc = 0; // NOLINT NOSONAR static char **argv = nullptr; // NOLINT NOSONAR class TestQtCoreApp : public QCoreApplication { public: explicit TestQtCoreApp() : QCoreApplication(argc, argv) { } };
952
C++
.h
27
33.333333
72
0.753529
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,098
AppConfigMock.h
deskflow_deskflow/src/test/shared/gui/mocks/AppConfigMock.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2024 Symless Ltd. * * 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 "gui/config/IAppConfig.h" #include "gui/config/ElevateMode.h" #include <gmock/gmock.h> class AppConfigMock : public deskflow::gui::IAppConfig { using ProcessMode = deskflow::gui::ProcessMode; public: AppConfigMock() { ON_CALL(*this, screenName()).WillByDefault(testing::ReturnRef(m_stub)); ON_CALL(*this, networkInterface()).WillByDefault(testing::ReturnRef(m_stub)); ON_CALL(*this, logLevelText()).WillByDefault(testing::Return(m_stub)); ON_CALL(*this, logFilename()).WillByDefault(testing::ReturnRef(m_stub)); } // // Getters // MOCK_METHOD(deskflow::gui::IConfigScopes &, scopes, (), (const, override)); MOCK_METHOD(QString, tlsCertPath, (), (const, override)); MOCK_METHOD(int, tlsKeyLength, (), (const, override)); MOCK_METHOD(bool, tlsEnabled, (), (const, override)); MOCK_METHOD(ProcessMode, processMode, (), (const, override)); MOCK_METHOD(ElevateMode, elevateMode, (), (const, override)); MOCK_METHOD(QString, logLevelText, (), (const, override)); MOCK_METHOD(const QString &, screenName, (), (const, override)); MOCK_METHOD(bool, preventSleep, (), (const, override)); MOCK_METHOD(bool, logToFile, (), (const, override)); MOCK_METHOD(const QString &, logFilename, (), (const, override)); MOCK_METHOD(QString, coreServerName, (), (const, override)); MOCK_METHOD(QString, coreClientName, (), (const, override)); MOCK_METHOD(bool, invertConnection, (), (const, override)); MOCK_METHOD(void, persistLogDir, (), (const, override)); MOCK_METHOD(bool, languageSync, (), (const, override)); MOCK_METHOD(bool, invertScrollDirection, (), (const, override)); MOCK_METHOD(int, port, (), (const, override)); MOCK_METHOD(bool, useExternalConfig, (), (const, override)); MOCK_METHOD(const QString &, configFile, (), (const, override)); MOCK_METHOD(const QString &, networkInterface, (), (const, override)); MOCK_METHOD(const QString &, serverHostname, (), (const, override)); MOCK_METHOD(int, logLevel, (), (const, override)); MOCK_METHOD(bool, autoHide, (), (const, override)); MOCK_METHOD(bool, enableService, (), (const, override)); MOCK_METHOD(bool, closeToTray, (), (const, override)); MOCK_METHOD(bool, isActiveScopeSystem, (), (const, override)); MOCK_METHOD(bool, isActiveScopeWritable, (), (const, override)); MOCK_METHOD(bool, clientGroupChecked, (), (const, override)); // // Setters // MOCK_METHOD(void, setLoadFromSystemScope, (bool loadFromSystemScope), (override)); MOCK_METHOD(void, setScreenName, (const QString &screenName), (override)); MOCK_METHOD(void, setPort, (int port), (override)); MOCK_METHOD(void, setNetworkInterface, (const QString &networkInterface), (override)); MOCK_METHOD(void, setLogLevel, (int logLevel), (override)); MOCK_METHOD(void, setLogToFile, (bool logToFile), (override)); MOCK_METHOD(void, setLogFilename, (const QString &logFilename), (override)); MOCK_METHOD(void, setElevateMode, (ElevateMode elevateMode), (override)); MOCK_METHOD(void, setAutoHide, (bool autoHide), (override)); MOCK_METHOD(void, setPreventSleep, (bool preventSleep), (override)); MOCK_METHOD(void, setTlsCertPath, (const QString &tlsCertPath), (override)); MOCK_METHOD(void, setTlsKeyLength, (int tlsKeyLength), (override)); MOCK_METHOD(void, setTlsEnabled, (bool tlsEnabled), (override)); MOCK_METHOD(void, setLanguageSync, (bool languageSync), (override)); MOCK_METHOD(void, setInvertScrollDirection, (bool invertScrollDirection), (override)); MOCK_METHOD(void, setEnableService, (bool enableService), (override)); MOCK_METHOD(void, setCloseToTray, (bool closeToTray), (override)); MOCK_METHOD(void, setInvertConnection, (bool invertConnection), (override)); private: const QString m_stub = "stub"; };
4,471
C++
.h
87
48.54023
88
0.726316
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,099
ServerConfigMock.h
deskflow_deskflow/src/test/shared/gui/mocks/ServerConfigMock.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2024 Symless Ltd. * * 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 "gui/config/IServerConfig.h" #include <gmock/gmock.h> class ServerConfigMock : public deskflow::gui::IServerConfig { public: ServerConfigMock() { ON_CALL(*this, screens()).WillByDefault(testing::ReturnRef(m_screensStub)); } MOCK_METHOD(bool, isFull, (), (const, override)); MOCK_METHOD(bool, screenExists, (const QString &screenName), (const, override)); MOCK_METHOD(bool, save, (const QString &fileName), (const, override)); MOCK_METHOD(void, save, (QFile & file), (const, override)); MOCK_METHOD(bool, enableDragAndDrop, (), (const, override)); MOCK_METHOD(const ScreenList &, screens, (), (const, override)); private: ScreenList m_screensStub; };
1,388
C++
.h
35
37.371429
82
0.743133
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,100
MSWindowsServerTaskBarReceiver.h
deskflow_deskflow/src/cmd/deskflows/MSWindowsServerTaskBarReceiver.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2003 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 "deskflow/ServerTaskBarReceiver.h" #define WIN32_LEAN_AND_MEAN #include <Windows.h> class BufferedLogOutputter; class IEventQueue; //! Implementation of ServerTaskBarReceiver for Microsoft Windows class MSWindowsServerTaskBarReceiver : public ServerTaskBarReceiver { public: MSWindowsServerTaskBarReceiver(HINSTANCE, const BufferedLogOutputter *, IEventQueue *events); virtual ~MSWindowsServerTaskBarReceiver(); // IArchTaskBarReceiver overrides virtual void showStatus(); virtual void runMenu(int x, int y); virtual void primaryAction(); virtual const Icon getIcon() const; void cleanup(); protected: void copyLog() const; // ServerTaskBarReceiver overrides virtual void onStatusChanged(); private: HICON loadIcon(UINT); void deleteIcon(HICON); void createWindow(); void destroyWindow(); BOOL dlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); static BOOL CALLBACK staticDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); private: HINSTANCE m_appInstance; HWND m_window; HMENU m_menu; HICON m_icon[kMaxState]; const BufferedLogOutputter *m_logBuffer; IEventQueue *m_events; static const UINT s_stateToIconID[]; };
1,945
C++
.h
55
32.981818
95
0.78541
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
true
false
false
false
false
false
false
14,101
OSXServerTaskBarReceiver.h
deskflow_deskflow/src/cmd/deskflows/OSXServerTaskBarReceiver.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2004 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 "deskflow/ServerTaskBarReceiver.h" class BufferedLogOutputter; //! Implementation of ServerTaskBarReceiver for OS X class OSXServerTaskBarReceiver : public ServerTaskBarReceiver { public: OSXServerTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events); virtual ~OSXServerTaskBarReceiver(); // IArchTaskBarReceiver overrides virtual void showStatus(); virtual void runMenu(int x, int y); virtual void primaryAction(); virtual const Icon getIcon() const; };
1,239
C++
.h
32
36.625
78
0.785358
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
true
false
false
false
false
false
false
14,102
XWindowsServerTaskBarReceiver.h
deskflow_deskflow/src/cmd/deskflows/XWindowsServerTaskBarReceiver.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2003 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 "deskflow/ServerTaskBarReceiver.h" class BufferedLogOutputter; class IEventQueue; //! Implementation of ServerTaskBarReceiver for X Windows class CXWindowsServerTaskBarReceiver : public ServerTaskBarReceiver { public: CXWindowsServerTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events); CXWindowsServerTaskBarReceiver(const CXWindowsServerTaskBarReceiver &) = delete; CXWindowsServerTaskBarReceiver(CXWindowsServerTaskBarReceiver &&) = delete; virtual ~CXWindowsServerTaskBarReceiver(); CXWindowsServerTaskBarReceiver &operator=(const CXWindowsServerTaskBarReceiver &) = delete; CXWindowsServerTaskBarReceiver &operator=(const CXWindowsServerTaskBarReceiver &&) = delete; // IArchTaskBarReceiver overrides virtual void showStatus(); virtual void runMenu(int x, int y); virtual void primaryAction(); virtual const Icon getIcon() const; };
1,632
C++
.h
37
41.918919
94
0.804279
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
true
false
false
false
false
false
false
14,103
resource.h
deskflow_deskflow/src/cmd/deskflows/resource.h
//{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. // Used by server .rc file // #define IDS_FAILED 1 #define IDS_INIT_FAILED 2 #define IDS_UNCAUGHT_EXCEPTION 3 #define IDI_DESKFLOW 101 #define IDI_TASKBAR_NOT_RUNNING 102 #define IDI_TASKBAR_NOT_WORKING 103 #define IDI_TASKBAR_NOT_CONNECTED 104 #define IDI_TASKBAR_CONNECTED 105 #define IDR_TASKBAR 107 #define IDD_TASKBAR_STATUS 108 #define IDC_TASKBAR_STATUS_STATUS 1000 #define IDC_TASKBAR_STATUS_CLIENTS 1001 #define IDC_TASKBAR_QUIT 40003 #define IDC_TASKBAR_STATUS 40004 #define IDC_TASKBAR_LOG 40005 #define IDC_RELOAD_CONFIG 40006 #define IDC_FORCE_RECONNECT 40007 #define IDC_TASKBAR_SHOW_LOG 40008 #define IDC_TASKBAR_LOG_LEVEL_ERROR 40009 #define IDC_TASKBAR_LOG_LEVEL_WARNING 40010 #define IDC_TASKBAR_LOG_LEVEL_NOTE 40011 #define IDC_TASKBAR_LOG_LEVEL_INFO 40012 #define IDC_TASKBAR_LOG_LEVEL_DEBUG 40013 #define IDC_TASKBAR_LOG_LEVEL_DEBUG1 40014 #define IDC_TASKBAR_LOG_LEVEL_DEBUG2 40015 #define ID_DESKFLOW_RELOADSYSTEM 40016 #define ID_DESKFLOW_RESETSERVER 40017 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 109 #define _APS_NEXT_COMMAND_VALUE 40018 #define _APS_NEXT_CONTROL_VALUE 1003 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif
1,312
C++
.h
41
30.97561
47
0.82126
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,104
OSXClientTaskBarReceiver.h
deskflow_deskflow/src/cmd/deskflowc/OSXClientTaskBarReceiver.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2004 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 "deskflow/ClientTaskBarReceiver.h" class BufferedLogOutputter; class IEventQueue; //! Implementation of ClientTaskBarReceiver for OS X class OSXClientTaskBarReceiver : public ClientTaskBarReceiver { public: OSXClientTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events); virtual ~OSXClientTaskBarReceiver(); // IArchTaskBarReceiver overrides virtual void showStatus(); virtual void runMenu(int x, int y); virtual void primaryAction(); virtual const Icon getIcon() const; };
1,258
C++
.h
33
36.060606
78
0.786885
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
true
false
false
false
false
false
false
14,105
XWindowsClientTaskBarReceiver.h
deskflow_deskflow/src/cmd/deskflowc/XWindowsClientTaskBarReceiver.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2003 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 "deskflow/ClientTaskBarReceiver.h" class BufferedLogOutputter; class IEventQueue; //! Implementation of ClientTaskBarReceiver for X Windows class CXWindowsClientTaskBarReceiver : public ClientTaskBarReceiver { public: CXWindowsClientTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events); CXWindowsClientTaskBarReceiver(const CXWindowsClientTaskBarReceiver &) = delete; CXWindowsClientTaskBarReceiver(CXWindowsClientTaskBarReceiver &&) = delete; virtual ~CXWindowsClientTaskBarReceiver(); CXWindowsClientTaskBarReceiver &operator=(const CXWindowsClientTaskBarReceiver &) = delete; CXWindowsClientTaskBarReceiver &operator=(CXWindowsClientTaskBarReceiver &&) = delete; // IArchTaskBarReceiver overrides virtual void showStatus(); virtual void runMenu(int x, int y); virtual void primaryAction(); virtual const Icon getIcon() const; };
1,626
C++
.h
37
41.756757
93
0.804169
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
true
false
false
false
false
false
false
14,106
MSWindowsClientTaskBarReceiver.h
deskflow_deskflow/src/cmd/deskflowc/MSWindowsClientTaskBarReceiver.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2003 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 "deskflow/ClientTaskBarReceiver.h" #define WIN32_LEAN_AND_MEAN #include <Windows.h> class BufferedLogOutputter; class IEventQueue; //! Implementation of ClientTaskBarReceiver for Microsoft Windows class MSWindowsClientTaskBarReceiver : public ClientTaskBarReceiver { public: MSWindowsClientTaskBarReceiver(HINSTANCE, const BufferedLogOutputter *, IEventQueue *events); virtual ~MSWindowsClientTaskBarReceiver(); // IArchTaskBarReceiver overrides virtual void showStatus(); virtual void runMenu(int x, int y); virtual void primaryAction(); virtual const Icon getIcon() const; void cleanup(); protected: void copyLog() const; // ClientTaskBarReceiver overrides virtual void onStatusChanged(); private: HICON loadIcon(UINT); void deleteIcon(HICON); void createWindow(); void destroyWindow(); BOOL dlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); static BOOL CALLBACK staticDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); private: HINSTANCE m_appInstance; HWND m_window; HMENU m_menu; HICON m_icon[kMaxState]; const BufferedLogOutputter *m_logBuffer; static const UINT s_stateToIconID[]; };
1,920
C++
.h
54
33.185185
95
0.785868
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
true
false
false
false
false
false
false
14,107
resource.h
deskflow_deskflow/src/cmd/deskflowc/resource.h
//{{NO_DEPENDENCIES}} // Microsoft Developer Studio generated include file. // Used by deskflowc.rc // #define IDS_FAILED 1 #define IDS_INIT_FAILED 2 #define IDS_UNCAUGHT_EXCEPTION 3 #define IDI_DESKFLOW 101 #define IDI_TASKBAR_NOT_RUNNING 102 #define IDI_TASKBAR_NOT_WORKING 103 #define IDI_TASKBAR_NOT_CONNECTED 104 #define IDI_TASKBAR_CONNECTED 105 #define IDR_TASKBAR 107 #define IDD_TASKBAR_STATUS 108 #define IDC_TASKBAR_STATUS_STATUS 1000 #define IDC_TASKBAR_QUIT 40001 #define IDC_TASKBAR_STATUS 40002 #define IDC_TASKBAR_LOG 40003 #define IDC_TASKBAR_SHOW_LOG 40004 #define IDC_TASKBAR_LOG_LEVEL_ERROR 40009 #define IDC_TASKBAR_LOG_LEVEL_WARNING 40010 #define IDC_TASKBAR_LOG_LEVEL_NOTE 40011 #define IDC_TASKBAR_LOG_LEVEL_INFO 40012 #define IDC_TASKBAR_LOG_LEVEL_DEBUG 40013 #define IDC_TASKBAR_LOG_LEVEL_DEBUG1 40014 #define IDC_TASKBAR_LOG_LEVEL_DEBUG2 40015 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 109 #define _APS_NEXT_COMMAND_VALUE 40016 #define _APS_NEXT_CONTROL_VALUE 1001 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif
1,132
C++
.h
36
30.416667
53
0.820091
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,108
TrayIcon.h
deskflow_deskflow/src/gui/src/TrayIcon.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2021 Symless Ltd. * * 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 <QMenu> #include <QObject> #include <QSystemTrayIcon> #include <QTimer> #include <functional> #include <memory> namespace deskflow::gui { class TrayIcon : public QObject { Q_OBJECT public: explicit TrayIcon() = default; void create(std::vector<QAction *> const &actions); void setIcon(const QIcon &icon); signals: void activated(QSystemTrayIcon::ActivationReason reason); private: void showRetryLoop(); std::unique_ptr<QSystemTrayIcon> m_pTrayIcon; std::unique_ptr<QMenu> m_pTrayIconMenu; std::function<void()> m_init; std::function<void(const QIcon &icon)> m_setIcon; QIcon m_icon; }; } // namespace deskflow::gui
1,354
C++
.h
42
30.142857
72
0.760553
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,109
Hotkey.h
deskflow_deskflow/src/gui/src/Hotkey.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) * * 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 <QList> #include <QString> #include <QTextStream> #include "Action.h" #include "KeySequence.h" class HotkeyDialog; class ServerConfigDialog; class QSettings; class Hotkey { friend class HotkeyDialog; friend class ServerConfigDialog; friend QTextStream &operator<<(QTextStream &outStream, const Hotkey &hotkey); public: Hotkey(); public: QString text() const; const KeySequence &keySequence() const { return m_KeySequence; } const ActionList &actions() const { return m_Actions; } void loadSettings(QSettings &settings); void saveSettings(QSettings &settings) const; bool operator==(const Hotkey &hk) const; protected: KeySequence &keySequence() { return m_KeySequence; } void setKeySequence(const KeySequence &seq) { m_KeySequence = seq; } ActionList &actions() { return m_Actions; } private: KeySequence m_KeySequence; ActionList m_Actions; }; typedef QList<Hotkey> HotkeyList; QTextStream &operator<<(QTextStream &outStream, const Hotkey &hotkey);
1,793
C++
.h
65
25.076923
79
0.758741
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,110
DataDownloader.h
deskflow_deskflow/src/gui/src/DataDownloader.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2014-2016 Symless Ltd. * * 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 <QByteArray> #include <QNetworkAccessManager> #include <QNetworkReply> #include <QNetworkRequest> #include <QObject> class DataDownloader : public QObject { Q_OBJECT public: explicit DataDownloader(QObject *parent = 0); virtual ~DataDownloader(); QByteArray data() const; void cancel(); void download(QUrl url); bool isFinished() const { return m_IsFinished; } signals: void isComplete(); private slots: void complete(QNetworkReply *reply); private: QNetworkAccessManager m_NetworkManager; QByteArray m_Data; QNetworkReply *m_pReply; bool m_IsFinished; };
1,311
C++
.h
45
26.866667
72
0.767886
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,111
KeySequence.h
deskflow_deskflow/src/gui/src/KeySequence.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) * * 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 <QList> #include <QString> class QSettings; class KeySequence { public: KeySequence(); public: QString toString() const; bool appendKey(int modifiers, int key); bool appendMouseButton(int button); bool isMouseButton() const; bool valid() const { return m_IsValid; } int modifiers() const { return m_Modifiers; } void saveSettings(QSettings &settings) const; void loadSettings(QSettings &settings); const QList<int> &sequence() const { return m_Sequence; } bool operator==(const KeySequence &ks) const; private: void setValid(bool b) { m_IsValid = b; } void setModifiers(int i) { m_Modifiers = i; } QList<int> &sequence() { return m_Sequence; } private: QList<int> m_Sequence; int m_Modifiers; bool m_IsValid; static QString keyToString(int key); };
1,603
C++
.h
64
22.34375
72
0.732026
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,112
ScreenSetupModel.h
deskflow_deskflow/src/gui/src/ScreenSetupModel.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2012 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) * * 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 <QAbstractTableModel> #include <QList> #include <QString> #include <QStringList> #include "gui/config/ScreenList.h" class ScreenSetupView; class ServerConfigDialog; class ScreenSetupModel : public QAbstractTableModel { Q_OBJECT friend class ScreenSetupView; friend class ServerConfigDialog; public: ScreenSetupModel(ScreenList &screens, int numColumns, int numRows); public: static const QString &mimeType() { return m_MimeType; } QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; int rowCount() const { return m_NumRows; } int columnCount() const { return m_NumColumns; } int rowCount(const QModelIndex &) const { return rowCount(); } int columnCount(const QModelIndex &) const { return columnCount(); } Qt::DropActions supportedDropActions() const; Qt::ItemFlags flags(const QModelIndex &index) const; QStringList mimeTypes() const; QMimeData *mimeData(const QModelIndexList &indexes) const; bool isFull() const; signals: void screensChanged(); protected: bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); const Screen &screen(const QModelIndex &index) const { return screen(index.column(), index.row()); } Screen &screen(const QModelIndex &index) { return screen(index.column(), index.row()); } const Screen &screen(int column, int row) const { return m_Screens[row * m_NumColumns + column]; } Screen &screen(int column, int row) { return m_Screens[row * m_NumColumns + column]; } void addScreen(const Screen &newScreen); private: ScreenList &m_Screens; const int m_NumColumns; const int m_NumRows; static const QString m_MimeType; };
2,518
C++
.h
86
26.511628
114
0.749174
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
true
false
false
false
false
false
false
14,113
MainWindow.h
deskflow_deskflow/src/gui/src/MainWindow.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) * * 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 <QMainWindow> #include <QMutex> #include <QProcess> #include <QSettings> #include <QSystemTrayIcon> #include <QThread> #include "ServerConfig.h" #include "TrayIcon.h" #include "common/ipc.h" #include "gui/VersionChecker.h" #include "gui/config/AppConfig.h" #include "gui/config/ConfigScopes.h" #include "gui/config/ServerConfigDialogState.h" #include "gui/core/ClientConnection.h" #include "gui/core/CoreProcess.h" #include "gui/core/ServerConnection.h" #include "gui/core/WaylandWarnings.h" #include "gui/tls/TlsUtility.h" class QAction; class QMenu; class QLineEdit; class QGroupBox; class QPushButton; class QTextEdit; class QComboBox; class QTabWidget; class QCheckBox; class QRadioButton; class QMessageBox; class QAbstractButton; class DeskflowApplication; class SetupWizard; namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { using CoreMode = deskflow::gui::CoreProcess::Mode; using CoreProcess = deskflow::gui::CoreProcess; Q_OBJECT friend class DeskflowApplication; friend class SetupWizard; friend class SettingsDialog; public: enum class LogLevel { Error, Info }; public: explicit MainWindow(deskflow::gui::ConfigScopes &configScopes, AppConfig &appConfig); ~MainWindow() override; void setVisible(bool visible) override; CoreMode coreMode() const { return m_CoreProcess.mode(); } QString address() const; void open(); ServerConfig &serverConfig() { return m_ServerConfig; } void autoAddScreen(const QString name); signals: void created(); void shown(); public slots: void onAppAboutToQuit(); private slots: // // Manual slots // void onCreated(); void onShown(); void onConfigScopesSaving(); void onAppConfigTlsChanged(); void onAppConfigScreenNameChanged(); void onAppConfigInvertConnection(); void onCoreProcessStarting(); void onCoreProcessError(CoreProcess::Error error); void onCoreConnectionStateChanged(CoreProcess::ConnectionState state); void onCoreProcessStateChanged(CoreProcess::ProcessState state); void onCoreProcessSecureSocket(bool enabled); void onVersionCheckerUpdateFound(const QString &version); void onTrayIconActivated(QSystemTrayIcon::ActivationReason reason); void onWindowSaveTimerTimeout(); void onServerConnectionConfigureClient(const QString &clientName); // // Auto-connect slots // void on_m_pButtonApply_clicked(); void on_m_pLabelComputerName_linkActivated(const QString &link); void on_m_pLabelFingerprint_linkActivated(const QString &link); void on_m_pButtonConnect_clicked(); void on_m_pButtonConnectToClient_clicked(); void on_m_pRadioGroupServer_clicked(bool); void on_m_pRadioGroupClient_clicked(bool); void on_m_pButtonConfigureServer_clicked(); bool on_m_pActionSave_triggered(); void on_m_pActionAbout_triggered(); void on_m_pActionHelp_triggered() const; void on_m_pActionSettings_triggered(); void on_m_pActionStartCore_triggered(); void on_m_pActionStopCore_triggered(); void on_m_pActionTestFatalError_triggered() const; void on_m_pActionTestCriticalError_triggered() const; void on_m_pActionClearSettings_triggered(); void on_m_pLineEditHostname_returnPressed(); void on_m_pLineEditClientIp_returnPressed(); void on_m_pLineEditHostname_textChanged(const QString &text); void on_m_pLineEditClientIp_textChanged(const QString &text); private: std::unique_ptr<Ui::MainWindow> ui; AppConfig &appConfig() { return m_AppConfig; } AppConfig const &appConfig() const { return m_AppConfig; } void createMenuBar(); void createStatusBar(); void createTrayIcon(); void applyConfig(); void applyCloseToTray() const; void setIcon(); bool checkForApp(int which, QString &app); void setStatus(const QString &status); void sendIpcMessage(IpcMessageType type, const char *buffer, bool showErrors); void updateFromLogLine(const QString &line); QString getIPAddresses() const; void enableServer(bool enable); void enableClient(bool enable); void checkConnected(const QString &line); void checkFingerprint(const QString &line); QString getTimeStamp() const; void showEvent(QShowEvent *) override; void closeEvent(QCloseEvent *event) override; void secureSocket(bool secureSocket); void windowStateChanged(); void connectSlots(); void updateWindowTitle(); void handleLogLine(const QString &line); void updateLocalFingerprint(); void updateScreenName(); void saveSettings(); QString configFilename(); void showConfigureServer(const QString &message); void showConfigureServer() { showConfigureServer(""); } void restoreWindow(); void saveWindow(); void setupControls(); void resizeEvent(QResizeEvent *event) override; void moveEvent(QMoveEvent *event) override; void showFirstConnectedMessage(); void updateStatus(); void showAndActivate(); VersionChecker m_VersionChecker; deskflow::gui::TrayIcon m_TrayIcon; QMenuBar *m_pMenuBar = nullptr; QMenu *m_pMenuFile = nullptr; QMenu *m_pMenuEdit = nullptr; QMenu *m_pMenuWindow = nullptr; QMenu *m_pMenuHelp = nullptr; QAbstractButton *m_pCancelButton = nullptr; bool m_SecureSocket = false; bool m_SaveWindow = false; bool m_Quitting = false; deskflow::gui::config::ServerConfigDialogState m_ServerConfigDialogState; bool m_SaveOnExit = true; deskflow::gui::core::WaylandWarnings m_WaylandWarnings; deskflow::gui::ConfigScopes &m_ConfigScopes; AppConfig &m_AppConfig; ServerConfig m_ServerConfig; deskflow::gui::CoreProcess m_CoreProcess; deskflow::gui::ServerConnection m_ServerConnection; deskflow::gui::ClientConnection m_ClientConnection; deskflow::gui::TlsUtility m_TlsUtility; QTimer m_WindowSaveTimer; };
6,494
C++
.h
203
29.35468
87
0.782172
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,114
Action.h
deskflow_deskflow/src/gui/src/Action.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) * * 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 "KeySequence.h" #include <QList> #include <QString> #include <QStringList> class ActionDialog; class QSettings; class QTextStream; class Action { friend class ActionDialog; friend QTextStream &operator<<(QTextStream &outStream, const Action &action); public: enum ActionType { keyDown, keyUp, keystroke, switchToScreen, switchInDirection, lockCursorToScreen, restartAllConnections, mouseDown, mouseUp, mousebutton, }; enum SwitchDirection { switchLeft, switchRight, switchUp, switchDown }; enum LockCursorMode { lockCursorToggle, lockCursonOn, lockCursorOff }; public: Action(); public: QString text() const; const KeySequence &keySequence() const { return m_KeySequence; } void loadSettings(QSettings &settings); void saveSettings(QSettings &settings) const; int type() const { return m_Type; } const QStringList &typeScreenNames() const { return m_TypeScreenNames; } const QString &switchScreenName() const { return m_SwitchScreenName; } int switchDirection() const { return m_SwitchDirection; } int lockCursorMode() const { return m_LockCursorMode; } bool activeOnRelease() const { return m_ActiveOnRelease; } bool haveScreens() const { return m_HasScreens; } bool restartServer() const { return m_restartServer; } bool operator==(const Action &a) const; protected: KeySequence &keySequence() { return m_KeySequence; } void setKeySequence(const KeySequence &seq) { m_KeySequence = seq; } void setType(int t) { m_Type = t; } QStringList &typeScreenNames() { return m_TypeScreenNames; } void setSwitchScreenName(const QString &n) { m_SwitchScreenName = n; } void setSwitchDirection(int d) { m_SwitchDirection = d; } void setLockCursorMode(int m) { m_LockCursorMode = m; } void setActiveOnRelease(bool b) { m_ActiveOnRelease = b; } void setHaveScreens(bool b) { m_HasScreens = b; } void setRestartServer(bool b) { m_restartServer = b; } private: KeySequence m_KeySequence; int m_Type; QStringList m_TypeScreenNames; QString m_SwitchScreenName; int m_SwitchDirection; int m_LockCursorMode; bool m_ActiveOnRelease; bool m_HasScreens; bool m_restartServer; static const char *m_ActionTypeNames[]; static const char *m_SwitchDirectionNames[]; static const char *m_LockCursorModeNames[]; }; typedef QList<Action> ActionList; QTextStream &operator<<(QTextStream &outStream, const Action &action);
3,380
C++
.h
156
18.461538
79
0.729907
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
true
false
false
false
false
false
false
14,115
QUtility.h
deskflow_deskflow/src/gui/src/QUtility.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2013-2016 Symless Ltd. * * 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 "ProcessorArch.h" #include <QComboBox> #include <QCryptographicHash> #include <QNetworkInterface> #include <QVariant> void setIndexFromItemData(QComboBox *comboBox, const QVariant &itemData); QString hash(const QString &string); qProcessorArch getProcessorArch();
981
C++
.h
25
37.48
73
0.782563
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
true
false
false
false
false
false
false
14,116
ProcessorArch.h
deskflow_deskflow/src/gui/src/ProcessorArch.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2015-2016 Symless Ltd. * * 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 enum qProcessorArch { kProcessorArchWin32, kProcessorArchWin64, kProcessorArchMac32, kProcessorArchMac64, kProcessorArchLinux32, kProcessorArchLinux64, kProcessorArchUnknown };
897
C++
.h
27
31.074074
72
0.78341
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,117
SetupWizard.h
deskflow_deskflow/src/gui/src/SetupWizard.h
/* * Deskflow -- mouse and keyboard sharing utility * * SPDX-FileCopyrightText: Copyright (C) 2024 Chris Rizzitello <sithlord48@gmail.com> * SPDX-FileCopyrightText: Copyright (C) 2012 Symless Ltd. * SPDX-License-Identifier: GPL-2.0 */ #pragma once #include <QDialog> class AppConfig; class QLabel; class QLineEdit; class SetupWizard : public QDialog { Q_OBJECT public: explicit SetupWizard(AppConfig &appConfig); ~SetupWizard() = default; protected: void accept() override; void reject() override; private: void nameChanged(const QString &error); AppConfig &m_appConfig; QLabel *m_lblError = nullptr; QLineEdit *m_lineName = nullptr; QPushButton *m_btnApply = nullptr; };
706
C++
.h
28
23
85
0.767164
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,118
ServerConfig.h
deskflow_deskflow/src/gui/src/ServerConfig.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2012 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) * * 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 "Hotkey.h" #include "gui/config/IServerConfig.h" #include "gui/config/ScreenConfig.h" #include "gui/config/ScreenList.h" #include <QList> const auto kDefaultColumns = 5; const auto kDefaultRows = 3; class QTextStream; class QSettings; class QString; class QFile; class ServerConfigDialog; class MainWindow; class AppConfig; namespace synergy::gui { enum class ServerProtocol { kSynergy, kBarrier }; // The default protocol was decided by a community vote. const auto kDefaultProtocol = ServerProtocol::kBarrier; } // namespace synergy::gui class ServerConfig : public ScreenConfig, public deskflow::gui::IServerConfig { using QSettingsProxy = deskflow::gui::proxy::QSettingsProxy; using ServerProtocol = synergy::gui::ServerProtocol; friend class ServerConfigDialog; friend QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config); public: ServerConfig(AppConfig &appConfig, MainWindow &mainWindow, int columns = kDefaultColumns, int rows = kDefaultRows); ~ServerConfig() override = default; bool operator==(const ServerConfig &sc) const; // // Overrides // const ScreenList &screens() const override { return m_Screens; } bool enableDragAndDrop() const override { return m_EnableDragAndDrop; } // // New methods // int numColumns() const { return m_Columns; } int numRows() const { return m_Rows; } bool hasHeartbeat() const { return m_HasHeartbeat; } int heartbeat() const { return m_Heartbeat; } ServerProtocol protocol() const { return m_Protocol; } bool relativeMouseMoves() const { return m_RelativeMouseMoves; } bool win32KeepForeground() const { return m_Win32KeepForeground; } bool hasSwitchDelay() const { return m_HasSwitchDelay; } int switchDelay() const { return m_SwitchDelay; } bool hasSwitchDoubleTap() const { return m_HasSwitchDoubleTap; } int switchDoubleTap() const { return m_SwitchDoubleTap; } bool switchCorner(int c) const { return m_SwitchCorners[c]; } int switchCornerSize() const { return m_SwitchCornerSize; } const QList<bool> &switchCorners() const { return m_SwitchCorners; } const HotkeyList &hotkeys() const { return m_Hotkeys; } bool disableLockToScreen() const { return m_DisableLockToScreen; } bool clipboardSharing() const { return m_ClipboardSharing; } size_t clipboardSharingSize() const { return m_ClipboardSharingSize; } static size_t defaultClipboardSharingSize(); // // Overrides // bool save(const QString &fileName) const override; bool screenExists(const QString &screenName) const override; void save(QFile &file) const override; bool isFull() const override; // // New methods // void commit(); int numScreens() const; int autoAddScreen(const QString name); const QString &getServerName() const; void updateServerName(); const QString &configFile() const; bool useExternalConfig() const; void addClient(const QString &clientName); QString getClientAddress() const; void setClientAddress(const QString &address); private: void recall(); void setupScreens(); QSettingsProxy &settings(); ScreenList &screens() { return m_Screens; } void setScreens(const ScreenList &screens) { m_Screens = screens; } void addScreen(const Screen &screen) { m_Screens.append(screen); } void setNumColumns(int n) { m_Columns = n; } void setNumRows(int n) { m_Rows = n; } void haveHeartbeat(bool on) { m_HasHeartbeat = on; } void setHeartbeat(int val) { m_Heartbeat = val; } void setProtocol(ServerProtocol val) { m_Protocol = val; } void setRelativeMouseMoves(bool on) { m_RelativeMouseMoves = on; } void setWin32KeepForeground(bool on) { m_Win32KeepForeground = on; } void haveSwitchDelay(bool on) { m_HasSwitchDelay = on; } void setSwitchDelay(int val) { m_SwitchDelay = val; } void haveSwitchDoubleTap(bool on) { m_HasSwitchDoubleTap = on; } void setSwitchDoubleTap(int val) { m_SwitchDoubleTap = val; } void setSwitchCorner(int c, bool on) { m_SwitchCorners[c] = on; } void setSwitchCornerSize(int val) { m_SwitchCornerSize = val; } void setEnableDragAndDrop(bool on) { m_EnableDragAndDrop = on; } void setDisableLockToScreen(bool on) { m_DisableLockToScreen = on; } void setClipboardSharing(bool on) { m_ClipboardSharing = on; } void setConfigFile(const QString &configFile); void setUseExternalConfig(bool useExternalConfig); size_t setClipboardSharingSize(size_t size); QList<bool> &switchCorners() { return m_SwitchCorners; } HotkeyList &hotkeys() { return m_Hotkeys; } int adjacentScreenIndex(int idx, int deltaColumn, int deltaRow) const; bool findScreenName(const QString &name, int &index); bool fixNoServer(const QString &name, int &index); int showAddClientDialog(const QString &clientName); void addToFirstEmptyGrid(const QString &clientName); private: bool m_HasHeartbeat = false; int m_Heartbeat = 0; ServerProtocol m_Protocol = synergy::gui::kDefaultProtocol; bool m_RelativeMouseMoves = false; bool m_Win32KeepForeground = false; bool m_HasSwitchDelay = false; int m_SwitchDelay = 0; bool m_HasSwitchDoubleTap = false; int m_SwitchDoubleTap = 0; int m_SwitchCornerSize = 0; bool m_EnableDragAndDrop = false; bool m_DisableLockToScreen = false; bool m_ClipboardSharing = true; QString m_ClientAddress = ""; QList<bool> m_SwitchCorners; HotkeyList m_Hotkeys; AppConfig *m_pAppConfig; MainWindow *m_pMainWindow; ScreenList m_Screens; int m_Columns; int m_Rows; size_t m_ClipboardSharingSize; }; QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config); enum { kAutoAddScreenOk, kAutoAddScreenManualServer, kAutoAddScreenManualClient, kAutoAddScreenIgnore };
6,771
C++
.h
286
20.597902
117
0.737428
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,119
AppDelegate.h
deskflow_deskflow/src/gui/src/AppDelegate.h
#pragma once #ifdef __cplusplus extern "C" { #endif #import <Cocoa/Cocoa.h> #if OSX_DEPLOYMENT_TARGET >= 1014 #import <UserNotifications/UNUserNotificationCenter.h> @interface AppDelegate : NSObject <NSApplicationDelegate, NSUserNotificationCenterDelegate, UNUserNotificationCenterDelegate> #else @interface AppDelegate : NSObject <NSApplicationDelegate, NSUserNotificationCenterDelegate> #endif @end #ifdef __cplusplus } #endif
442
C++
.h
17
24.235294
108
0.831754
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,120
SettingsDialog.h
deskflow_deskflow/src/gui/src/dialogs/SettingsDialog.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2012 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) * * 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 <QDialog> #include "gui/config/AppConfig.h" #include "gui/config/IServerConfig.h" #include "gui/core/CoreProcess.h" #include "gui/tls/TlsUtility.h" #include "gui/validators/ValidationError.h" namespace Ui { class SettingsDialog; } class SettingsDialog : public QDialog { using IServerConfig = deskflow::gui::IServerConfig; using CoreProcess = deskflow::gui::CoreProcess; Q_OBJECT public: void extracted(); SettingsDialog( QWidget *parent, AppConfig &appConfig, const IServerConfig &serverConfig, const CoreProcess &coreProcess ); ~SettingsDialog() override; signals: void shown(); private slots: void on_m_pCheckBoxEnableTls_clicked(bool checked); void on_m_pCheckBoxLogToFile_stateChanged(int); void on_m_pButtonBrowseLog_clicked(); void on_m_pRadioSystemScope_toggled(bool checked); void on_m_pPushButtonTlsCertPath_clicked(); void on_m_pPushButtonTlsRegenCert_clicked(); void on_m_pCheckBoxServiceEnabled_toggled(bool checked); private: void accept() override; void reject() override; void showEvent(QShowEvent *event) override; bool isClientMode() const; void updateTlsControls(); void updateTlsControlsEnabled(); void showReadOnlyMessage(); /// @brief Load all settings. void loadFromConfig(); /// @brief Enables or disables the TLS regenerate button. void updateTlsRegenerateButton(); /// @brief Updates the key length value based on the loaded file. void updateKeyLengthOnFile(const QString &path); /// @brief Enables controls when they should be. void updateControls(); validators::ValidationError *m_pScreenNameError; /// @brief Stores settings scope at start of settings dialog /// This is necessary to restore state if user changes /// the scope and doesn't save changes bool m_wasOriginallySystemScope = false; std::unique_ptr<Ui::SettingsDialog> ui; AppConfig &m_appConfig; const IServerConfig &m_serverConfig; const CoreProcess &m_coreProcess; deskflow::gui::TlsUtility m_tlsUtility; };
2,759
C++
.h
75
34.213333
110
0.773613
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,121
ServerConfigDialog.h
deskflow_deskflow/src/gui/src/dialogs/ServerConfigDialog.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) * * 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 "ScreenSetupModel.h" #include "ServerConfig.h" #include "gui/config/AppConfig.h" #include <QDialog> namespace Ui { class ServerConfigDialog; } class ServerConfigDialog : public QDialog { Q_OBJECT public: ServerConfigDialog(QWidget *parent, ServerConfig &config, AppConfig &appConfig); ~ServerConfigDialog(); bool addClient(const QString &clientName); public slots: void accept() override; void reject() override; void message(const QString &message) { m_Message = message; } protected slots: void on_m_pButtonNewHotkey_clicked(); void on_m_pListHotkeys_itemSelectionChanged(); void on_m_pButtonEditHotkey_clicked(); void on_m_pButtonRemoveHotkey_clicked(); void on_m_pButtonNewAction_clicked(); void on_m_pListActions_itemSelectionChanged(); void on_m_pButtonEditAction_clicked(); void on_m_pButtonRemoveAction_clicked(); void on_m_pCheckBoxEnableClipboard_stateChanged(int state); void on_m_pButtonAddComputer_clicked(); void onScreenRemoved(); void on_m_pCheckBoxUseExternalConfig_toggled(bool checked = false); bool on_m_pButtonBrowseConfigFile_clicked(); protected: bool addComputer(const QString &clientName, bool doSilent); ServerConfig &serverConfig() { return m_ServerConfig; } void setOriginalServerConfig(const ServerConfig &s) { m_OriginalServerConfig = s; } ScreenSetupModel &model() { return m_ScreenSetupModel; } AppConfig &appConfig() { return m_appConfig; } private: std::unique_ptr<Ui::ServerConfigDialog> ui; ServerConfig &m_OriginalServerConfig; ServerConfig m_ServerConfig; bool m_OriginalServerConfigIsExternal; QString m_OriginalServerConfigUsesExternalFile; ScreenSetupModel m_ScreenSetupModel; QString m_Message; AppConfig &m_appConfig; private slots: void onChange(); };
2,577
C++
.h
83
28.409639
82
0.775584
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,122
HotkeyDialog.h
deskflow_deskflow/src/gui/src/dialogs/HotkeyDialog.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) * * 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 "Hotkey.h" #include <QDialog> class KeySequenceWidget; namespace Ui { class HotkeyDialog; } class HotkeyDialog : public QDialog { Q_OBJECT public: HotkeyDialog(QWidget *parent, Hotkey &hotkey); ~HotkeyDialog() override; public: const Hotkey &hotkey() const { return m_Hotkey; } protected slots: void accept() override; protected: const KeySequenceWidget *sequenceWidget() const; Hotkey &hotkey() { return m_Hotkey; } private: std::unique_ptr<Ui::HotkeyDialog> ui; Hotkey &m_Hotkey; };
1,291
C++
.h
47
25.170213
72
0.754258
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,123
ScreenSettingsDialog.h
deskflow_deskflow/src/gui/src/dialogs/ScreenSettingsDialog.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2012 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) * * 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 <QDialog> class QWidget; class QString; class Screen; class ScreenList; namespace Ui { class ScreenSettingsDialog; } class ScreenSettingsDialog : public QDialog { Q_OBJECT public: ScreenSettingsDialog(QWidget *parent, Screen *pScreen = nullptr, const ScreenList *pScreens = nullptr); ~ScreenSettingsDialog() override; public slots: void accept() override; private slots: void on_m_pButtonAddAlias_clicked(); void on_m_pButtonRemoveAlias_clicked(); void on_m_pLineEditAlias_textChanged(const QString &text); void on_m_pListAliases_itemSelectionChanged(); private: std::unique_ptr<Ui::ScreenSettingsDialog> ui_; Screen *m_pScreen; };
1,418
C++
.h
43
30.906977
105
0.776557
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,124
ActionDialog.h
deskflow_deskflow/src/gui/src/dialogs/ActionDialog.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) * * 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 <QDialog> class Hotkey; class Action; class QRadioButton; class QButtonGroup; class ServerConfig; class KeySequenceWidget; namespace Ui { class ActionDialog; } class ActionDialog : public QDialog { Q_OBJECT public: ActionDialog(QWidget *parent, ServerConfig &config, Hotkey &hotkey, Action &action); ~ActionDialog() override; protected slots: void accept() override; void on_m_pKeySequenceWidgetHotkey_keySequenceChanged(); protected: const KeySequenceWidget *sequenceWidget() const; const ServerConfig &serverConfig() const { return m_ServerConfig; } private: std::unique_ptr<Ui::ActionDialog> ui; const ServerConfig &m_ServerConfig; Hotkey &m_Hotkey; Action &m_Action; QButtonGroup *m_pButtonGroupType; };
1,511
C++
.h
50
28.06
86
0.776706
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,125
AboutDialog.h
deskflow_deskflow/src/gui/src/dialogs/AboutDialog.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2024 Chris Rizzitello <sithlord48@gmail.com> * Copyright (C) 2012 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) * * 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 <QDialog> class AboutDialog : public QDialog { Q_OBJECT public: explicit AboutDialog(QWidget *parent = nullptr); ~AboutDialog() = default; private: inline static const auto s_lightCopy = QStringLiteral(":/icons/64x64/copy-light.png"); inline static const auto s_darkCopy = QStringLiteral(":/icons/64x64/copy-dark.png"); inline static const auto s_lightLogo = QStringLiteral(":/image/logo-light.png"); inline static const auto s_darkLogo = QStringLiteral(":/image/logo-dark.png"); inline static const auto s_awesomeDevs = QStringList{ // Chris is the ultimate creator, and the one who started it all in 2001. QStringLiteral("Chris Schoeneman"), // Richard and Adam developed CosmoSynergy, the 90's predecessor project. QStringLiteral("Richard Lee"), QStringLiteral("Adam Feder"), // Nick continued the legacy in 2009 started by Chris. QStringLiteral("Nick Bolton"), // Volker wrote the first version of the GUI (QSynergy) in 2008. QStringLiteral("Volker Lanz"), // Re-ignited the project in 2008 and rebuilt the community. QStringLiteral("Sorin Sb√¢rnea"), // Contributors of bug fixes in the early days. QStringLiteral("Ryan Breen"), QStringLiteral("Guido Poschta"), QStringLiteral("Bertrand Landry Hetu"), QStringLiteral("Tom Chadwick"), QStringLiteral("Brent Priddy"), QStringLiteral("Jason Axelson"), QStringLiteral("Jake Petroules"), // Implemented Wayland support (libei and libportal). QStringLiteral("Peter Hutterer"), QStringLiteral("Olivier Fourdan"), // Symless employees (in order of joining). QStringLiteral("Kyle Bloom"), QStringLiteral("Daun Chung"), QStringLiteral("Serhii Hadzhylov"), QStringLiteral("Oleksandr Lysytsia"), QStringLiteral("Olena Kutytska"), QStringLiteral("Owen Phillips"), QStringLiteral("Daniel Evenson"), // Prominent Deskflow development community members QStringLiteral("Chris Rizzitello"), }; };
2,874
C++
.h
66
38.924242
88
0.724249
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,126
AddClientDialog.h
deskflow_deskflow/src/gui/src/dialogs/AddClientDialog.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2014-2016 Symless Ltd. * * 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 <QDialog> class QPushButton; class QLabel; namespace Ui { class AddClientDialog; } enum { kAddClientRight, kAddClientLeft, kAddClientUp, kAddClientDown, kAddClientOther, kAddClientIgnore }; class AddClientDialog : public QDialog { Q_OBJECT public: AddClientDialog(const QString &clientName, QWidget *parent = 0); ~AddClientDialog() override; int addResult() { return m_AddResult; } private slots: void handleButtonLeft(); void handleButtonUp(); void handleButtonRight(); void handleButtonDown(); void handleButtonAdvanced(); private: std::unique_ptr<Ui::AddClientDialog> ui; QPushButton *m_pButtonLeft; QPushButton *m_pButtonUp; QPushButton *m_pButtonRight; QPushButton *m_pButtonDown; QLabel *m_pLabelCenter; int m_AddResult; };
1,504
C++
.h
57
24.052632
72
0.77121
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,127
ScreenSetupView.h
deskflow_deskflow/src/gui/src/widgets/ScreenSetupView.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2012 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) * * 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 <QFlags> #include <QTableView> #include "gui/config/Screen.h" class QWidget; class QMouseEvent; class QResizeEvent; class QDragEnterEvent; class ScreenSetupModel; class ScreenSetupView : public QTableView { Q_OBJECT public: ScreenSetupView(QWidget *parent); public: void setModel(QAbstractItemModel *model) override; ScreenSetupModel *model() const; protected: void mouseDoubleClickEvent(QMouseEvent *) override; void setTableSize(); void resizeEvent(QResizeEvent *) override; void dragEnterEvent(QDragEnterEvent *event) override; void dragMoveEvent(QDragMoveEvent *event) override; void startDrag(Qt::DropActions supportedActions) override; void initViewItemOption(QStyleOptionViewItem *option) const override; void scrollTo(const QModelIndex &, ScrollHint) override { } };
1,567
C++
.h
46
31.934783
72
0.789161
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,128
KeySequenceWidget.h
deskflow_deskflow/src/gui/src/widgets/KeySequenceWidget.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) * * 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 <QPushButton> #include "KeySequence.h" class KeySequenceWidget : public QPushButton { Q_OBJECT public: KeySequenceWidget(QWidget *parent, const KeySequence &seq = KeySequence()); signals: void keySequenceChanged(); public: const QString &mousePrefix() const { return m_MousePrefix; } const QString &mousePostfix() const { return m_MousePostfix; } const QString &keyPrefix() const { return m_KeyPrefix; } const QString &keyPostfix() const { return m_KeyPostfix; } void setMousePrefix(const QString &s) { m_MousePrefix = s; } void setMousePostfix(const QString &s) { m_MousePostfix = s; } void setKeyPrefix(const QString &s) { m_KeyPrefix = s; } void setKeyPostfix(const QString &s) { m_KeyPostfix = s; } const KeySequence &keySequence() const { return m_KeySequence; } const KeySequence &backupSequence() const { return m_BackupSequence; } void setKeySequence(const KeySequence &seq); bool valid() const { return keySequence().valid(); } protected: void mousePressEvent(QMouseEvent *); void keyPressEvent(QKeyEvent *); bool event(QEvent *event); void appendToSequence(int key); void updateOutput(); void startRecording(); void stopRecording(); KeySequence &keySequence() { return m_KeySequence; } KeySequence &backupSequence() { return m_BackupSequence; } private: enum Status { Stopped, Recording }; void setStatus(Status s) { m_Status = s; } Status status() const { return m_Status; } private: KeySequence m_KeySequence; KeySequence m_BackupSequence; Status m_Status; QString m_MousePrefix; QString m_MousePostfix; QString m_KeyPrefix; QString m_KeyPostfix; };
2,535
C++
.h
112
19.598214
77
0.727084
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
true
false
false
false
false
false
false
14,129
ServerStateLabel.h
deskflow_deskflow/src/gui/src/widgets/ServerStateLabel.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2021 Symless Ltd. * * 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 <QLabel> #include <QStringList> namespace deskflow::gui::widgets { class ServerStateLabel : public QLabel { public: explicit ServerStateLabel(QWidget *parent = nullptr); void updateServerState(const QString &line); private: QStringList m_clients; void updateState(); }; } // namespace deskflow::gui::widgets
1,031
C++
.h
30
32.366667
72
0.769618
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,130
TrashScreenWidget.h
deskflow_deskflow/src/gui/src/widgets/TrashScreenWidget.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2008 Volker Lanz (vl@fidra.de) * * 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 <QLabel> class QWidget; class QDragEnterEvent; class QDropEvent; class TrashScreenWidget : public QLabel { Q_OBJECT public: TrashScreenWidget(QWidget *parent) : QLabel(parent) { } public: void dragEnterEvent(QDragEnterEvent *event); void dropEvent(QDropEvent *event); signals: void screenRemoved(); };
1,083
C++
.h
35
28.914286
72
0.768714
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,131
ClientStateLabel.h
deskflow_deskflow/src/gui/src/widgets/ClientStateLabel.h
/* * Deskflow -- mouse and keyboard sharing utility * Copyright (C) 2021 Symless Ltd. * * 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 <QLabel> namespace deskflow::gui::widgets { class ClientStateLabel : public QLabel { public: explicit ClientStateLabel(QWidget *parent = nullptr); void updateClientState(const QString &line); }; } // namespace deskflow::gui::widgets
950
C++
.h
26
34.615385
72
0.768226
deskflow/deskflow
10,364
3,653
93
GPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,134
VersionHelper.cpp
snowie2000_mactype/VersionHelper.cpp
#include "VersionHelper.h" ////////////////////////////////////////////////////////////////////// // Konstruktion/Destruktion ////////////////////////////////////////////////////////////////////// CVersionHelper::CVersionHelper() { } CVersionHelper::~CVersionHelper() { } /***********************************************************************************/ /* */ /* Class: CVersionHelper */ /* Method: GetVersionInfo */ /* */ /* Parameters: */ /* ----------- */ /* HMODULE hLib */ /* Handle to the module that contains the resource (EXE or DLL) */ /* A value of NULL specifies the current applications resources */ /* */ /* CString csEntry */ /* Specifies the name of the resource. For more information, */ /* see the Remarks section. */ /* */ /* Return Values: */ /* -------------- */ /* If the function succeeds, the return value is a string containing the value */ /* of the specified resource. */ /* If the function fails, the returned string is empty. To get extended error */ /* information, call GetLastError. */ /* */ /* Remarks: */ /* -------- */ /* Since the Win32 API resource information is encoded in Unicode, this method */ /* also strips the strings from Unicode. */ /* */ /* The following valid values for csEntry, as specified by Microsoft are: */ /* CompanyName, FileDescription, FileVersion, InternalName, LegalCopyright, */ /* OriginalFilename, ProductName, ProductVersion, Comments, LegalTrademarks, */ /* PrivateBuild, SpecialBuild */ /* */ /* Opening the rc-file as "text" or with a text-editor allows you to add further */ /* entries to your version information structure and it is retrievable using */ /* this same method. */ /* */ /***********************************************************************************/ wstring CVersionHelper::GetVersionInfo(HMODULE hLib, wstring csEntry) { wstring csRet; if (hLib == NULL) return TEXT(""); HRSRC hVersion = FindResource(hLib, MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION); if (hVersion != NULL) { HGLOBAL hGlobal = LoadResource(hLib, hVersion); if (hGlobal != NULL) { LPVOID versionInfo = LockResource(hGlobal); if (versionInfo != NULL) { char *pchVI = (char*)versionInfo; int dwSize = SizeofResource(hLib, hVersion); if (IsBadReadPtr(versionInfo, dwSize)) dwSize -= 4; char *pchVIcopy = new char[dwSize * 2 + 4]; memcpy(pchVIcopy, pchVI, (int)(dwSize * 2 + 4)); DWORD vLen, langD; BOOL retVal; LPVOID retbuf = NULL; static TCHAR fileEntry[256]; wsprintf(fileEntry, TEXT("\\VarFileInfo\\Translation")); retVal = VerQueryValue(pchVIcopy, fileEntry, &retbuf, (UINT *)&vLen); if (retVal && vLen == 4) { memcpy(&langD, retbuf, 4); wsprintf(fileEntry, TEXT("\\StringFileInfo\\%02X%02X%02X%02X\\%s"), (langD & 0xff00) >> 8, langD & 0xff, (langD & 0xff000000) >> 24, (langD & 0xff0000) >> 16, csEntry); } else wsprintf(fileEntry, TEXT("\\StringFileInfo\\%04X04B0\\%s"), GetUserDefaultLangID(), csEntry); if (VerQueryValue(pchVIcopy, fileEntry, &retbuf, (UINT *)&vLen)) csRet = (TCHAR*)retbuf; delete pchVIcopy; } } UnlockResource(hGlobal); FreeResource(hGlobal); } return csRet; } /***********************************************************************************/ /* */ /* Class: CGlobalFunctions */ /* Method: FormatVersion */ /* */ /* Parameters: */ /* ----------- */ /* CString cs */ /* Specifies a version number such as "FileVersion" or */ /* "ProductVersion" in the format "m, n, o, p" */ /* (e.g. "1, 2, 3, a") */ /* */ /* Return Values: */ /* -------------- */ /* If the function succeeds, the return value is a string containing the version */ /* in the format "m.nop" (e.g. "1.23a") */ /* */ /* If the function fails, the returned string is empty. */ /* */ /***********************************************************************************/ wstring CVersionHelper::FormatVersion(wstring cs) { wstring csRet; if (!cs.length()) { rtrim(cs); int iPos = cs.find(','); if (iPos == -1) return TEXT(""); ltrim(cs); rtrim(cs); csRet.Format(TEXT("%s."), cs.copy(iPos)); while (1) { cs = cs.Mid(iPos + 1); ltrim(cs); iPos = cs.find(','); if (iPos == -1) { csRet += cs; break; } csRet += cs.Left(iPos); } } return csRet; } /***********************************************************************************/ /* */ /* Class: CGlobalFunctions */ /* Method: GetFileVersionX */ /* */ /* Parameters: */ /* ----------- */ /* */ /* Return Values: */ /* -------------- */ /* If the function succeeds, the return value is a wstring containing the */ /* "FileVersion" in the format "m.nop" (e.g. "1.23a") */ /* */ /* If the function fails, the returned wstring is empty. */ /* */ /***********************************************************************************/ wstring CVersionHelper::GetFileVersionX() { if (!m_csFileVersion.length()) { wstring csVersion = FormatVersion(GetVersionInfo(NULL, TEXT("FileVersion"))); m_csFileVersion.Format(TEXT("Version %s (Build %s)"), csVersion, GetVersionInfo(NULL, TEXT("SpecialBuild"))); } return m_csFileVersion; } /***********************************************************************************/ /* */ /* Class: CGlobalFunctions */ /* Method: GetFileVersionX */ /* */ /* Parameters: */ /* ----------- */ /* */ /* Return Values: */ /* -------------- */ /* If the function succeeds, the return value is a string containing the */ /* "ProductVersion" in the format "m.nop" (e.g. "1.23a") */ /* */ /* If the function fails, the returned string is empty. */ /* */ /***********************************************************************************/ wstring CVersionHelper::GetProductVersionX() { if (!m_csProductVersion.length()) m_csProductVersion = FormatVersion(GetVersionInfo(NULL, TEXT("ProductVersion"))); return m_csProductVersion; }
10,537
C++
.cpp
186
53.268817
112
0.307633
snowie2000/mactype
9,859
437
273
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,137
hash_list.cpp
snowie2000_mactype/hash_list.cpp
#include "hash_list.h" #include <cwctype> #include <algorithm> void CHashedStringList::Add(TCHAR * String, TCHAR * Value) { std::wstring buff = String; if (!m_bCaseSense) std::transform(buff.begin(), buff.end(), buff.begin(), ::towlower); strmap::iterator it = stringmap.find(buff); if (it == stringmap.end()) { stringmap[buff] = _wcsdup(Value); } } void CHashedStringList::Delete(TCHAR * String) { std::wstring buff = String; if (!m_bCaseSense) std::transform(buff.begin(), buff.end(), buff.begin(), ::towlower); stringmap.erase(buff); } TCHAR * CHashedStringList::Find(TCHAR * String) { TCHAR* b = _wcsdup(String); if (!m_bCaseSense) b = _wcslwr(b); std::wstring buff = b; free(b); strmap::iterator it = stringmap.find(buff); if (it != stringmap.end()) return it->second; else return NULL; }
825
C++
.cpp
33
23.060606
69
0.696701
snowie2000/mactype
9,859
437
273
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,146
run.cpp
snowie2000_mactype/run.cpp
// dll injection #define _CRT_SECURE_NO_DEPRECATE 1 #define WINVER 0x500 #define _WIN32_WINNT 0x500 #define _WIN32_IE 0x601 #define WIN32_LEAN_AND_MEAN 1 #define UNICODE 1 #define _UNICODE 1 #include <Windows.h> #include <ShellApi.h> #include <ComDef.h> #include <ShlObj.h> #include <ShLwApi.h> #include <tchar.h> #include "array.h" #include <strsafe.h> // _vsnwprintf用 #include <wchar.h> #include <stdarg.h> #define _CRTDBG_MAP_ALLOC #include <cstdlib> #include <malloc.h> #include <crtdbg.h> #define for if(0);else for #ifndef _countof #define _countof(array) (sizeof(array) / sizeof((array)[0])) #endif #pragma comment(linker, "/subsystem:windows,5.0") #pragma comment(lib, "Kernel32.lib") #pragma comment(lib, "User32.lib") #pragma comment(lib, "Shell32.lib") #pragma comment(lib, "ShLwApi.lib") #pragma comment(lib, "Ole32.lib") #define IDS_USAGE 101 #define IDS_DLL 102 #define IDC_EXEC 103 static void showmsg(LPCSTR msg) { MessageBoxA(NULL, msg, "MacType ERROR", MB_OK | MB_ICONSTOP); } static void errmsg(UINT id, DWORD code) { char buffer[512]; char format[128]; LoadStringA(GetModuleHandleA(NULL), id, format, 128); wnsprintfA(buffer, 512, format, code); showmsg(buffer); } inline HRESULT HresultFromLastError() { DWORD dwErr = GetLastError(); return HRESULT_FROM_WIN32(dwErr); } #include "detours.h" #ifdef _M_IX86 #pragma comment (lib, "detours.lib") const auto MacTypeDll = L"MacType.dll"; const auto MacTypeDllA = "MacType.dll"; #else #pragma comment (lib, "detours64.lib") const auto MacTypeDll = L"MacType64.dll"; const auto MacTypeDllA = "MacType64.dll"; #endif HINSTANCE hinstDLL; #include <stddef.h> #define GetDLLInstance() (hinstDLL) #define _GDIPP_EXE #define _GDIPP_RUN_CPP //#include "supinfo.h" //#define OLD_PSDK #ifdef OLD_PSDK extern "C" { HRESULT WINAPI _SHILCreateFromPath(LPCWSTR pszPath, LPITEMIDLIST* ppidl, DWORD* rgflnOut) { if (!pszPath || !ppidl) { return E_INVALIDARG; } LPSHELLFOLDER psf; HRESULT hr = ::SHGetDesktopFolder(&psf); if (hr != NOERROR) { return hr; } ULONG chEaten; LPOLESTR lpszDisplayName = ::StrDupW(pszPath); hr = psf->ParseDisplayName(NULL, NULL, lpszDisplayName, &chEaten, ppidl, rgflnOut); ::LocalFree(lpszDisplayName); psf->Release(); return hr; } void WINAPI _SHFree(void* pv) { if (!pv) { return; } LPMALLOC pMalloc = NULL; if (::SHGetMalloc(&pMalloc) == NOERROR) { pMalloc->Free(pv); pMalloc->Release(); } } } #else #define _SHILCreateFromPath SHILCreateFromPath #define _SHFree SHFree #endif bool isX64PE(const TCHAR* file_path) { HANDLE hFile = CreateFile(file_path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { showmsg("Error opening file"); return false; } IMAGE_DOS_HEADER dosHeader; DWORD bytesRead; if (!ReadFile(hFile, &dosHeader, sizeof(IMAGE_DOS_HEADER), &bytesRead, NULL)) { showmsg("Error reading file"); CloseHandle(hFile); return false; } // Check if it's a PE file if (dosHeader.e_magic != IMAGE_DOS_SIGNATURE) { showmsg("Not a PE file"); CloseHandle(hFile); return false; } IMAGE_NT_HEADERS ntHeaders; // Seek to the PE header offset SetFilePointer(hFile, dosHeader.e_lfanew, NULL, FILE_BEGIN); if (!ReadFile(hFile, &ntHeaders, sizeof(IMAGE_NT_HEADERS), &bytesRead, NULL)) { showmsg("Error reading PE header"); CloseHandle(hFile); return false; } if (ntHeaders.FileHeader.Machine == IMAGE_FILE_MACHINE_I386) { CloseHandle(hFile); return false; } else if (ntHeaders.FileHeader.Machine == IMAGE_FILE_MACHINE_AMD64) { CloseHandle(hFile); return true; } else { CloseHandle(hFile); return false; } } // 1つ目の引数だけファイルとして扱い、実行する。 // // コマンドは こんな感じで連結されます。 // exe linkpath linkarg cmdarg2 cmdarg3 cmdarg4 ... // static HRESULT HookAndExecute(int show) { int argc = 0; LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc); if (!argv) { return HresultFromLastError(); } if (argc <= 1) { char buffer[256]; LoadStringA(GetModuleHandleA(NULL), IDS_USAGE, buffer, 256); MessageBoxA(NULL, buffer , "MacType", MB_OK | MB_ICONINFORMATION); LocalFree(argv); return S_OK; } int i; size_t length = 1; for (i = 1; i < argc; i++) { length += wcslen(argv[i]) + 3; } LPWSTR cmdline = (WCHAR*)calloc(sizeof(WCHAR), length); if (!cmdline) { LocalFree(argv); return E_OUTOFMEMORY; } LPWSTR p = cmdline; *p = L'\0'; for (i = 1; i < argc; i++) { const bool dq = !!wcschr(argv[i], L' '); if (dq) { *p++ = '"'; length--; } StringCchCopyExW(p, length, argv[i], &p, &length, STRSAFE_NO_TRUNCATION); if (dq) { *p++ = '"'; length--; } *p++ = L' '; length--; } *CharPrevW(cmdline, p) = L'\0'; // now we got the full cmdline for external exetuble. let's check if we can hook into it #ifdef _M_IX86 if (isX64PE(argv[1])) { ShellExecute(NULL, NULL, L"macloader64.exe", cmdline, NULL, SW_SHOW); return S_OK; } #else if (!isX64PE(argv[1])) { ShellExecute(NULL, NULL, L"macloader.exe", cmdline, NULL, SW_SHOW); return S_OK; } #endif WCHAR file[MAX_PATH], dir[MAX_PATH]; GetCurrentDirectoryW(_countof(dir), dir); StringCchCopyW(file, _countof(file), argv[1]); if (PathIsRelativeW(file)) { PathCombineW(file, dir, file); } else { WCHAR gdippDir[MAX_PATH]; GetModuleFileNameW(NULL, gdippDir, _countof(gdippDir)); PathRemoveFileSpec(gdippDir); // カレントディレクトリがgdi++.exeの置かれているディレクトリと同じだったら、 // 起動しようとしているEXEのフルパスから抜き出したディレクトリ名をカレント // ディレクトリとして起動する。(カレントディレクトリがEXEと同じ場所である // 前提で作られているアプリ対策) if (wcscmp(dir, gdippDir) == 0) { StringCchCopyW(dir, _countof(dir), argv[1]); PathRemoveFileSpec(dir); } } #ifdef _DEBUG if ((GetAsyncKeyState(VK_CONTROL) & 0x8000) && MessageBoxW(NULL, cmdline, NULL, MB_YESNO) != IDYES) { free(cmdline); return NOERROR; } #endif PROCESS_INFORMATION processInfo; STARTUPINFO startupInfo = { 0 }; startupInfo.cb = sizeof(startupInfo); // get current directory and append mactype dll char path[MAX_PATH] = { 0 }; if (GetModuleFileNameA(NULL, path, _countof(path))) { PathRemoveFileSpecA(path); strcat(path, "\\"); } strcat(path, MacTypeDllA); auto ret = DetourCreateProcessWithDllEx(NULL, cmdline, NULL, NULL, false, 0, NULL, dir, &startupInfo, &processInfo, path, NULL); free(cmdline); LocalFree(argv); argv = NULL; return ret ? S_OK : E_ACCESSDENIED; } int WINAPI wWinMain(HINSTANCE ins, HINSTANCE prev, LPWSTR cmd, int show) { _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF); OleInitialize(NULL); WCHAR path[MAX_PATH]; if (GetModuleFileNameW(NULL, path, _countof(path))) { PathRemoveFileSpec(path); wcscat(path, L"\\"); wcscat(path, MacTypeDll); //DONT_RESOLVE_DLL_REFERENCESを指定すると依存関係の解決や //DllMainの呼び出しが行われない hinstDLL = LoadLibraryExW(path, NULL, DONT_RESOLVE_DLL_REFERENCES); } if (!hinstDLL) { errmsg(IDS_DLL, HresultFromLastError()); } else { PathRemoveFileSpecW(path); SetCurrentDirectoryW(path); HRESULT hr = HookAndExecute(show); if (hr != S_OK) { errmsg(IDC_EXEC, hr); } } OleUninitialize(); return 0; } //EOF
7,497
C++
.cpp
274
23.773723
129
0.716571
snowie2000/mactype
9,859
437
273
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,151
undocAPI.h
snowie2000_mactype/undocAPI.h
#pragma once typedef struct _UNICODE_STRING2 { USHORT Length; USHORT MaximumLength; PWSTR Buffer; } UNICODE_STRING2; typedef UNICODE_STRING2 *PUNICODE_STRING2; typedef const UNICODE_STRING2 *PCUNICODE_STRING2; const DWORD GT_DEVICE_TO_WORLD = 0x0402; const DWORD GT_WORLD_TO_DEVICE = 0x0204; const DWORD GT_WORLD_TO_PAGE = 0x0203; const DWORD GT_PAGE_TO_DEVICE = 0x0304; typedef int(__stdcall * TGetTextFA)(HDC, int, LPWSTR); typedef BOOL (__stdcall *PFNCreateProcessInternalW) ( HANDLE hToken, LPCTSTR lpApplicationName, LPTSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCTSTR lpCurrentDirectory, LPSTARTUPINFO lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation , PHANDLE hNewToken ); typedef BOOL (WINAPI *PFNCreateProcessW)( __in_opt LPCWSTR lpApplicationName, __inout_opt LPWSTR lpCommandLine, __in_opt LPSECURITY_ATTRIBUTES lpProcessAttributes, __in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes, __in BOOL bInheritHandles, __in DWORD dwCreationFlags, __in_opt LPVOID lpEnvironment, __in_opt LPCWSTR lpCurrentDirectory, __in LPSTARTUPINFOW lpStartupInfo, __out LPPROCESS_INFORMATION lpProcessInformation ); typedef BOOL (WINAPI *PFNCreateProcessA)( __in_opt LPCSTR lpApplicationName, __inout_opt LPSTR lpCommandLine, __in_opt LPSECURITY_ATTRIBUTES lpProcessAttributes, __in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes, __in BOOL bInheritHandles, __in DWORD dwCreationFlags, __in_opt LPVOID lpEnvironment, __in_opt LPCSTR lpCurrentDirectory, __in LPSTARTUPINFOA lpStartupInfo, __out LPPROCESS_INFORMATION lpProcessInformation ); typedef BOOL (WINAPI *PFNIsWow64Process)(HANDLE hProcess, PBOOL Wow64Process ); typedef int (WINAPI * TGdiGetCodePage)(HDC); typedef BOOL (WINAPI * TGetTransform)(HDC, DWORD, XFORM*); typedef BOOL (WINAPI * PFNGetFontResourceInfo)(LPCWSTR, DWORD*, VOID*, DWORD); typedef LONG (WINAPI * PFNLdrLoadDll)( IN PWCHAR PathToFile OPTIONAL, IN ULONG Flags OPTIONAL, IN UNICODE_STRING2* ModuleFileName, OUT HANDLE* ModuleHandle ); typedef BOOL(WINAPI * PFNSetProcessMitigationPolicy)( _In_ PROCESS_MITIGATION_POLICY MitigationPolicy, _In_ PVOID lpBuffer, _In_ SIZE_T dwLength); static TGetTransform GetTransform = (TGetTransform)GetProcAddress(LoadLibrary(_T("gdi32.dll")), "GetTransform"); /*********************************************************************** * GetTransform (GDI32.@) + * + * Undocumented + * + * Returns one of the co-ordinate space transforms + * + * PARAMS + * hdc [I] Device context. + * which [I] Which xform to return: + * 0x203 World -> Page transform (that set by SetWorldTransform). + * 0x304 Page -> Device transform (the mapping mode transform). + * 0x204 World -> Device transform (the combination of the above two). + * 0x402 Device -> World transform (the inversion of the above). + * xform [O] The xform. + * ************************************************************************/ static TGdiGetCodePage GdiGetCodePage = (TGdiGetCodePage)GetProcAddress(LoadLibrary(_T("gdi32.dll")),"GdiGetCodePage"); static TGetTextFA GetTextFaceAliasW= (TGetTextFA)GetProcAddress(LoadLibrary(_T("gdi32.dll")),"GetTextFaceAliasW"); static PFNCreateProcessInternalW CreateProcessInternalW_KernelBase = (PFNCreateProcessInternalW)GetProcAddress(GetModuleHandle(_T("kernelbase.dll")),"CreateProcessInternalW"); static PFNCreateProcessInternalW CreateProcessInternalW = CreateProcessInternalW_KernelBase ? CreateProcessInternalW_KernelBase:(PFNCreateProcessInternalW)GetProcAddress(GetModuleHandle(_T("kernel32.dll")),"CreateProcessInternalW"); //static PFNIsWow64Process IsWow64Process=(PFNIsWow64Process)GetProcAddress(LoadLibrary(L"Kernel32.dll"), "IsWow64Process"); static PFNGetFontResourceInfo GetFontResourceInfo=(PFNGetFontResourceInfo)GetProcAddress(LoadLibrary(L"gdi32.dll"), "GetFontResourceInfoW");
4,526
C++
.h
92
44.086957
233
0.677587
snowie2000/mactype
9,859
437
273
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,153
ivs_otft.h
snowie2000_mactype/ivs_otft.h
OTFT_DEF_BEGIN(0) /* E0100 */ OTFT_DEF(0x5026, 2) /* jp90 */ OTFT_DEF(0x50C5, 2) /* jp90 */ OTFT_DEF(0x5132, 2) /* jp90 */ OTFT_DEF(0x514E, 2) /* jp90 */ OTFT_DEF(0x5154, 1) /* jp78 */ OTFT_DEF(0x5195, 1) /* jp78 */ OTFT_DEF(0x51A4, 2) /* jp90 */ OTFT_DEF(0x53A9, 2) /* jp90 */ OTFT_DEF(0x53C9, 2) /* jp90 */ OTFT_DEF(0x53DB, 2) /* jp90 */ OTFT_DEF(0x53DF, 2) /* jp90 */ OTFT_DEF(0x54AC, 2) /* jp90 */ OTFT_DEF(0x54E8, 2) /* jp90 */ OTFT_DEF(0x55B0, 2) /* jp90 */ OTFT_DEF(0x5632, 2) /* jp90 */ OTFT_DEF(0x5642, 2) /* jp90 */ OTFT_DEF(0x564C, 2) /* jp90 */ OTFT_DEF(0x56C0, 2) /* jp90 */ OTFT_DEF(0x5835, 2) /* jp90 */ OTFT_DEF(0x5906, 2) /* jp90 */ OTFT_DEF(0x5A29, 2) /* jp90 */ OTFT_DEF(0x5C51, 2) /* jp90 */ OTFT_DEF(0x5C60, 2) /* jp90 */ OTFT_DEF(0x5DF7, 2) /* jp90 */ OTFT_DEF(0x5DFD, 1) /* jp78 */ OTFT_DEF(0x5E96, 2) /* jp90 */ OTFT_DEF(0x5EDF, 2) /* jp90 */ OTFT_DEF(0x5EFB, 2) /* jp90 */ OTFT_DEF(0x5F98, 2) /* jp90 */ OTFT_DEF(0x5FBD, 2) /* jp90 */ OTFT_DEF(0x6062, 2) /* jp90 */ OTFT_DEF(0x609E, 2) /* jp90 */ OTFT_DEF(0x6108, 2) /* jp90 */ OTFT_DEF(0x6241, 2) /* jp90 */ OTFT_DEF(0x633A, 2) /* jp90 */ OTFT_DEF(0x633D, 2) /* jp90 */ OTFT_DEF(0x6357, 2) /* jp90 */ OTFT_DEF(0x6372, 2) /* jp90 */ OTFT_DEF(0x63C3, 2) /* jp90 */ OTFT_DEF(0x646F, 2) /* jp90 */ OTFT_DEF(0x647A, 2) /* jp90 */ OTFT_DEF(0x64B0, 2) /* jp90 */ OTFT_DEF(0x64E2, 2) /* jp90 */ OTFT_DEF(0x65A7, 2) /* jp90 */ OTFT_DEF(0x6666, 2) /* jp90 */ OTFT_DEF(0x66B5, 2) /* jp90 */ OTFT_DEF(0x6753, 2) /* jp90 */ OTFT_DEF(0x6756, 2) /* jp90 */ OTFT_DEF(0x6897, 2) /* jp90 */ OTFT_DEF(0x6962, 2) /* jp90 */ OTFT_DEF(0x696F, 2) /* jp90 */ OTFT_DEF(0x698A, 2) /* jp90 */ OTFT_DEF(0x6994, 2) /* jp90 */ OTFT_DEF(0x69CC, 2) /* jp90 */ OTFT_DEF(0x6A0B, 2) /* jp90 */ OTFT_DEF(0x6A3D, 2) /* jp90 */ OTFT_DEF(0x6A9C, 1) /* jp78 */ OTFT_DEF(0x6ADB, 1) /* jp78 */ OTFT_DEF(0x6B4E, 2) /* jp90 */ OTFT_DEF(0x6C72, 2) /* jp90 */ OTFT_DEF(0x6DEB, 2) /* jp90 */ OTFT_DEF(0x6E1A, 1) /* jp78 */ OTFT_DEF(0x6EA2, 2) /* jp90 */ OTFT_DEF(0x6EBA, 2) /* jp90 */ OTFT_DEF(0x6F23, 1) /* jp78 */ OTFT_DEF(0x6F51, 1) /* jp78 */ OTFT_DEF(0x7015, 2) /* jp90 */ OTFT_DEF(0x701E, 2) /* jp90 */ OTFT_DEF(0x7026, 2) /* jp90 */ OTFT_DEF(0x7058, 2) /* jp90 */ OTFT_DEF(0x7078, 2) /* jp90 */ OTFT_DEF(0x707C, 2) /* jp90 */ OTFT_DEF(0x7149, 1) /* jp78 */ OTFT_DEF(0x714E, 2) /* jp90 */ OTFT_DEF(0x7152, 2) /* jp90 */ OTFT_DEF(0x717D, 2) /* jp90 */ OTFT_DEF(0x7228, 1) /* jp78 */ OTFT_DEF(0x723A, 2) /* jp90 */ OTFT_DEF(0x724C, 2) /* jp90 */ OTFT_DEF(0x7259, 2) /* jp90 */ OTFT_DEF(0x72E1, 2) /* jp90 */ OTFT_DEF(0x7337, 2) /* jp90 */ OTFT_DEF(0x7422, 1) /* jp78 */ OTFT_DEF(0x7511, 2) /* jp90 */ OTFT_DEF(0x7515, 2) /* jp90 */ OTFT_DEF(0x7526, 2) /* jp90 */ OTFT_DEF(0x75BC, 2) /* jp90 */ OTFT_DEF(0x77A5, 2) /* jp90 */ OTFT_DEF(0x783A, 1) /* jp78 */ OTFT_DEF(0x792A, 1) /* jp78 */ OTFT_DEF(0x7941, 2) /* jp90 */ OTFT_DEF(0x7947, 2) /* jp90 */ OTFT_DEF(0x79B0, 2) /* jp90 */ OTFT_DEF(0x79B1, 1) /* jp78 */ OTFT_DEF(0x79E4, 2) /* jp90 */ OTFT_DEF(0x7A17, 2) /* jp90 */ OTFT_DEF(0x7A7F, 2) /* jp90 */ OTFT_DEF(0x7AC8, 2) /* jp90 */ OTFT_DEF(0x7B08, 2) /* jp90 */ OTFT_DEF(0x7B75, 2) /* jp90 */ OTFT_DEF(0x7BAD, 2) /* jp90 */ OTFT_DEF(0x7BB8, 2) /* jp90 */ OTFT_DEF(0x7BC7, 2) /* jp90 */ OTFT_DEF(0x7BDD, 2) /* jp90 */ OTFT_DEF(0x7C3E, 2) /* jp90 */ OTFT_DEF(0x7C7E, 2) /* jp90 */ OTFT_DEF(0x7C82, 2) /* jp90 */ OTFT_DEF(0x7FEB, 2) /* jp90 */ OTFT_DEF(0x7FF0, 2) /* jp90 */ OTFT_DEF(0x8171, 2) /* jp90 */ OTFT_DEF(0x817F, 2) /* jp90 */ OTFT_DEF(0x8258, 2) /* jp90 */ OTFT_DEF(0x8292, 2) /* jp90 */ OTFT_DEF(0x82A6, 2) /* jp90 */ OTFT_DEF(0x8328, 2) /* jp90 */ OTFT_DEF(0x845B, 2) /* jp90 */ OTFT_DEF(0x84EC, 2) /* jp90 */ OTFT_DEF(0x84EE, 1) /* jp78 */ OTFT_DEF(0x8511, 2) /* jp90 */ OTFT_DEF(0x853D, 2) /* jp90 */ OTFT_DEF(0x85A9, 2) /* jp90 */ OTFT_DEF(0x85AF, 2) /* jp90 */ OTFT_DEF(0x85F7, 2) /* jp90 */ OTFT_DEF(0x8654, 2) /* jp90 */ OTFT_DEF(0x86F8, 2) /* jp90 */ OTFT_DEF(0x8703, 2) /* jp90 */ OTFT_DEF(0x8755, 2) /* jp90 */ OTFT_DEF(0x8805, 2) /* jp90 */ OTFT_DEF(0x8956, 2) /* jp90 */ OTFT_DEF(0x8A0A, 2) /* jp90 */ OTFT_DEF(0x8A1D, 2) /* jp90 */ OTFT_DEF(0x8A3B, 2) /* jp90 */ OTFT_DEF(0x8A6E, 2) /* jp90 */ OTFT_DEF(0x8AB9, 2) /* jp90 */ OTFT_DEF(0x8AFA, 2) /* jp90 */ OTFT_DEF(0x8B0E, 2) /* jp90 */ OTFT_DEF(0x8B2C, 2) /* jp90 */ OTFT_DEF(0x8B7F, 2) /* jp90 */ OTFT_DEF(0x8C79, 2) /* jp90 */ OTFT_DEF(0x8CED, 2) /* jp90 */ OTFT_DEF(0x8FBB, 2) /* jp90 */ OTFT_DEF(0x8FBF, 2) /* jp90 */ OTFT_DEF(0x8FC2, 2) /* jp90 */ OTFT_DEF(0x8FC4, 2) /* jp90 */ OTFT_DEF(0x8FE6, 2) /* jp90 */ OTFT_DEF(0x9017, 2) /* jp90 */ OTFT_DEF(0x9019, 2) /* jp90 */ OTFT_DEF(0x9022, 2) /* jp90 */ OTFT_DEF(0x903C, 2) /* jp90 */ OTFT_DEF(0x9041, 2) /* jp90 */ OTFT_DEF(0x905C, 2) /* jp90 */ OTFT_DEF(0x9061, 2) /* jp90 */ OTFT_DEF(0x9087, 1) /* jp78 */ OTFT_DEF(0x912D, 2) /* jp90 */ OTFT_DEF(0x914B, 2) /* jp90 */ OTFT_DEF(0x91B1, 1) /* jp78 */ OTFT_DEF(0x91DC, 2) /* jp90 */ OTFT_DEF(0x9306, 2) /* jp90 */ OTFT_DEF(0x9375, 2) /* jp90 */ OTFT_DEF(0x939A, 2) /* jp90 */ OTFT_DEF(0x9453, 2) /* jp90 */ OTFT_DEF(0x9699, 2) /* jp90 */ OTFT_DEF(0x9771, 2) /* jp90 */ OTFT_DEF(0x9784, 2) /* jp90 */ OTFT_DEF(0x9798, 2) /* jp90 */ OTFT_DEF(0x97AD, 2) /* jp90 */ OTFT_DEF(0x983B, 1) /* jp78 */ OTFT_DEF(0x98F4, 2) /* jp90 */ OTFT_DEF(0x9905, 2) /* jp90 */ OTFT_DEF(0x990C, 2) /* jp90 */ OTFT_DEF(0x9910, 2) /* jp90 */ OTFT_DEF(0x9957, 2) /* jp90 */ OTFT_DEF(0x99C1, 2) /* jp90 */ OTFT_DEF(0x9A19, 2) /* jp90 */ OTFT_DEF(0x9A4A, 2) /* jp90 */ OTFT_DEF(0x9BAB, 2) /* jp90 */ OTFT_DEF(0x9BD6, 2) /* jp90 */ OTFT_DEF(0x9C2F, 2) /* jp90 */ OTFT_DEF(0x9C52, 2) /* jp90 */ OTFT_DEF(0x9D09, 2) /* jp90 */ OTFT_DEF(0x9D60, 2) /* jp90 */ OTFT_DEF_END(181) OTFT_DEF_BEGIN(181) /* E0101 */ OTFT_DEF(0x5026, 3) /* jp04 */ OTFT_DEF(0x50C5, 3) /* jp04 */ OTFT_DEF(0x5132, 3) /* jp04 */ OTFT_DEF(0x514E, 3) /* jp04 */ OTFT_DEF(0x5189, 1) /* jp78 */ OTFT_DEF(0x51A4, 1) /* jp78 */ OTFT_DEF(0x51CB, 1) /* jp78 */ OTFT_DEF(0x5275, 1) /* jp78 */ OTFT_DEF(0x537F, 2) /* jp90 */ OTFT_DEF(0x53A9, 1) /* jp78 */ OTFT_DEF(0x53C9, 3) /* jp04 */ OTFT_DEF(0x53DB, 3) /* jp04 */ OTFT_DEF(0x53DF, 3) /* jp04 */ OTFT_DEF(0x54AC, 3) /* jp04 */ OTFT_DEF(0x54E8, 3) /* jp04 */ OTFT_DEF(0x5533, 1) /* jp78 */ OTFT_DEF(0x5539, 1) /* jp78 */ OTFT_DEF(0x5544, 1) /* jp78 */ OTFT_DEF(0x559D, 1) /* jp78 */ OTFT_DEF(0x55B0, 3) /* jp04 */ OTFT_DEF(0x5632, 3) /* jp04 */ OTFT_DEF(0x5642, 3) /* jp04 */ OTFT_DEF(0x564C, 3) /* jp04 */ OTFT_DEF(0x5678, 1) /* jp78 */ OTFT_DEF(0x56A5, 1) /* jp78 */ OTFT_DEF(0x56C0, 3) /* jp04 */ OTFT_DEF(0x580B, 1) /* jp78 */ OTFT_DEF(0x5835, 3) /* jp04 */ OTFT_DEF(0x5858, 1) /* jp78 */ OTFT_DEF(0x585A, 1) /* jp78 */ OTFT_DEF(0x5906, 3) /* jp04 */ OTFT_DEF(0x5A29, 3) /* jp04 */ OTFT_DEF(0x5A9B, 1) /* jp78 */ OTFT_DEF(0x5ABE, 1) /* jp78 */ OTFT_DEF(0x5ACC, 1) /* jp78 */ OTFT_DEF(0x5C51, 3) /* jp04 */ OTFT_DEF(0x5C60, 1) /* jp78 */ OTFT_DEF(0x5DF7, 3) /* jp04 */ OTFT_DEF(0x5E96, 3) /* jp04 */ OTFT_DEF(0x5EDF, 3) /* jp04 */ OTFT_DEF(0x5EE0, 1) /* jp78 */ OTFT_DEF(0x5EFB, 3) /* jp04 */ OTFT_DEF(0x5F98, 3) /* jp04 */ OTFT_DEF(0x5FBD, 3) /* jp04 */ OTFT_DEF(0x6062, 1) /* jp78 */ OTFT_DEF(0x6097, 1) /* jp78 */ OTFT_DEF(0x609E, 3) /* jp04 */ OTFT_DEF(0x6108, 3) /* jp04 */ OTFT_DEF(0x6167, 1) /* jp78 */ OTFT_DEF(0x61F2, 2) /* jp90 */ OTFT_DEF(0x6241, 3) /* jp04 */ OTFT_DEF(0x6248, 1) /* jp78 */ OTFT_DEF(0x6249, 1) /* jp78 */ OTFT_DEF(0x62D0, 1) /* jp78 */ OTFT_DEF(0x633A, 3) /* jp04 */ OTFT_DEF(0x633D, 3) /* jp04 */ OTFT_DEF(0x6357, 3) /* jp04 */ OTFT_DEF(0x6369, 1) /* jp78 */ OTFT_DEF(0x6372, 3) /* jp04 */ OTFT_DEF(0x63C3, 3) /* jp04 */ OTFT_DEF(0x6406, 1) /* jp78 */ OTFT_DEF(0x646F, 3) /* jp04 */ OTFT_DEF(0x647A, 3) /* jp04 */ OTFT_DEF(0x64B0, 3) /* jp04 */ OTFT_DEF(0x64E2, 3) /* jp04 */ OTFT_DEF(0x6583, 1) /* jp78 */ OTFT_DEF(0x65A7, 3) /* jp04 */ OTFT_DEF(0x6666, 3) /* jp04 */ OTFT_DEF(0x66B5, 3) /* jp04 */ OTFT_DEF(0x66D9, 1) /* jp78 */ OTFT_DEF(0x6753, 1) /* jp78 */ OTFT_DEF(0x6756, 3) /* jp04 */ OTFT_DEF(0x67A6, 1) /* jp78 */ OTFT_DEF(0x67CA, 1) /* jp78 */ OTFT_DEF(0x6813, 1) /* jp78 */ OTFT_DEF(0x6897, 3) /* jp04 */ OTFT_DEF(0x689B, 1) /* jp78 */ OTFT_DEF(0x68A2, 1) /* jp78 */ OTFT_DEF(0x68DA, 1) /* jp78 */ OTFT_DEF(0x6962, 3) /* jp04 */ OTFT_DEF(0x696F, 3) /* jp04 */ OTFT_DEF(0x698A, 3) /* jp04 */ OTFT_DEF(0x6994, 3) /* jp04 */ OTFT_DEF(0x69CC, 3) /* jp04 */ OTFT_DEF(0x6A0B, 3) /* jp04 */ OTFT_DEF(0x6A3D, 3) /* jp04 */ OTFT_DEF(0x6ADB, 2) /* jp90 */ OTFT_DEF(0x6B1D, 1) /* jp78 */ OTFT_DEF(0x6B4E, 3) /* jp04 */ OTFT_DEF(0x6C72, 3) /* jp04 */ OTFT_DEF(0x6CE1, 1) /* jp78 */ OTFT_DEF(0x6DEB, 3) /* jp04 */ OTFT_DEF(0x6E6E, 1) /* jp78 */ OTFT_DEF(0x6E9D, 1) /* jp78 */ OTFT_DEF(0x6EA2, 3) /* jp04 */ OTFT_DEF(0x6EBA, 1) /* jp78 */ OTFT_DEF(0x6F23, 2) /* jp90 */ OTFT_DEF(0x6FEF, 1) /* jp78 */ OTFT_DEF(0x7015, 3) /* jp04 */ OTFT_DEF(0x701E, 3) /* jp04 */ OTFT_DEF(0x7026, 3) /* jp04 */ OTFT_DEF(0x7058, 3) /* jp04 */ OTFT_DEF(0x7078, 3) /* jp04 */ OTFT_DEF(0x707C, 3) /* jp04 */ OTFT_DEF(0x7149, 2) /* jp90 */ OTFT_DEF(0x714E, 3) /* jp04 */ OTFT_DEF(0x7152, 3) /* jp04 */ OTFT_DEF(0x717D, 1) /* jp78 */ OTFT_DEF(0x7194, 1) /* jp78 */ OTFT_DEF(0x723A, 3) /* jp04 */ OTFT_DEF(0x724C, 3) /* jp04 */ OTFT_DEF(0x7259, 3) /* jp04 */ OTFT_DEF(0x72E1, 3) /* jp04 */ OTFT_DEF(0x7337, 1) /* jp78 */ OTFT_DEF(0x73CA, 1) /* jp78 */ OTFT_DEF(0x73CE, 1) /* jp78 */ OTFT_DEF(0x7504, 1) /* jp78 */ OTFT_DEF(0x750D, 1) /* jp78 */ OTFT_DEF(0x7511, 1) /* jp78 */ OTFT_DEF(0x7515, 1) /* jp78 */ OTFT_DEF(0x7526, 3) /* jp04 */ OTFT_DEF(0x75BC, 3) /* jp04 */ OTFT_DEF(0x7626, 1) /* jp78 */ OTFT_DEF(0x7652, 1) /* jp78 */ OTFT_DEF(0x7693, 1) /* jp78 */ OTFT_DEF(0x77A5, 3) /* jp04 */ OTFT_DEF(0x787C, 1) /* jp78 */ OTFT_DEF(0x7941, 3) /* jp04 */ OTFT_DEF(0x7947, 3) /* jp04 */ OTFT_DEF(0x79B0, 3) /* jp04 */ OTFT_DEF(0x79E4, 3) /* jp04 */ OTFT_DEF(0x7A17, 3) /* jp04 */ OTFT_DEF(0x7A31, 1) /* jp78 */ OTFT_DEF(0x7A7F, 3) /* jp04 */ OTFT_DEF(0x7AC8, 3) /* jp04 */ OTFT_DEF(0x7B75, 3) /* jp04 */ OTFT_DEF(0x7B99, 1) /* jp78 */ OTFT_DEF(0x7BAD, 3) /* jp04 */ OTFT_DEF(0x7BB8, 3) /* jp04 */ OTFT_DEF(0x7BC7, 3) /* jp04 */ OTFT_DEF(0x7BDD, 3) /* jp04 */ OTFT_DEF(0x7C7E, 1) /* jp78 */ OTFT_DEF(0x7C82, 3) /* jp04 */ OTFT_DEF(0x7C90, 1) /* jp78 */ OTFT_DEF(0x7CAE, 1) /* jp78 */ OTFT_DEF(0x7D9B, 1) /* jp78 */ OTFT_DEF(0x7D9F, 1) /* jp78 */ OTFT_DEF(0x7DAE, 1) /* jp78 */ OTFT_DEF(0x7FD4, 1) /* jp78 */ OTFT_DEF(0x7FE0, 1) /* jp78 */ OTFT_DEF(0x7FEB, 3) /* jp04 */ OTFT_DEF(0x7FF0, 3) /* jp04 */ OTFT_DEF(0x8000, 1) /* jp78 */ OTFT_DEF(0x8171, 3) /* jp04 */ OTFT_DEF(0x817F, 3) /* jp04 */ OTFT_DEF(0x822E, 1) /* jp78 */ OTFT_DEF(0x8258, 3) /* jp04 */ OTFT_DEF(0x828D, 1) /* jp78 */ OTFT_DEF(0x8292, 3) /* jp04 */ OTFT_DEF(0x82A6, 3) /* jp04 */ OTFT_DEF(0x82D2, 1) /* jp78 */ OTFT_DEF(0x8323, 1) /* jp78 */ OTFT_DEF(0x8328, 3) /* jp04 */ OTFT_DEF(0x8375, 1) /* jp78 */ OTFT_DEF(0x83DF, 1) /* jp78 */ OTFT_DEF(0x845B, 3) /* jp04 */ OTFT_DEF(0x84EC, 3) /* jp04 */ OTFT_DEF(0x8511, 3) /* jp04 */ OTFT_DEF(0x8517, 1) /* jp78 */ OTFT_DEF(0x853D, 3) /* jp04 */ OTFT_DEF(0x85A9, 3) /* jp04 */ OTFT_DEF(0x85AF, 3) /* jp04 */ OTFT_DEF(0x85F7, 3) /* jp04 */ OTFT_DEF(0x8612, 2) /* jp90 */ OTFT_DEF(0x8654, 3) /* jp04 */ OTFT_DEF(0x86F8, 3) /* jp04 */ OTFT_DEF(0x8703, 3) /* jp04 */ OTFT_DEF(0x8755, 3) /* jp04 */ OTFT_DEF(0x8782, 1) /* jp78 */ OTFT_DEF(0x87D2, 1) /* jp78 */ OTFT_DEF(0x890A, 1) /* jp78 */ OTFT_DEF(0x8956, 3) /* jp04 */ OTFT_DEF(0x89AF, 1) /* jp78 */ OTFT_DEF(0x8A0A, 3) /* jp04 */ OTFT_DEF(0x8A3B, 3) /* jp04 */ OTFT_DEF(0x8A6E, 3) /* jp04 */ OTFT_DEF(0x8AB9, 3) /* jp04 */ OTFT_DEF(0x8ADE, 1) /* jp78 */ OTFT_DEF(0x8AFA, 3) /* jp04 */ OTFT_DEF(0x8B0E, 3) /* jp04 */ OTFT_DEF(0x8B2C, 3) /* jp04 */ OTFT_DEF(0x8B41, 1) /* jp78 */ OTFT_DEF(0x8B7F, 3) /* jp04 */ OTFT_DEF(0x8C79, 3) /* jp04 */ OTFT_DEF(0x8CED, 3) /* jp04 */ OTFT_DEF(0x8DDA, 1) /* jp78 */ OTFT_DEF(0x8E09, 1) /* jp78 */ OTFT_DEF(0x8F13, 1) /* jp78 */ OTFT_DEF(0x8FBF, 3) /* jp04 */ OTFT_DEF(0x8FC2, 3) /* jp04 */ OTFT_DEF(0x8FC4, 3) /* jp04 */ OTFT_DEF(0x8FE6, 3) /* jp04 */ OTFT_DEF(0x8FE9, 1) /* jp78 */ OTFT_DEF(0x8FEA, 1) /* jp78 */ OTFT_DEF(0x9017, 3) /* jp04 */ OTFT_DEF(0x9019, 3) /* jp04 */ OTFT_DEF(0x901D, 1) /* jp78 */ OTFT_DEF(0x903C, 3) /* jp04 */ OTFT_DEF(0x9041, 1) /* jp78 */ OTFT_DEF(0x9058, 1) /* jp78 */ OTFT_DEF(0x905C, 3) /* jp04 */ OTFT_DEF(0x9061, 3) /* jp04 */ OTFT_DEF(0x906E, 1) /* jp78 */ OTFT_DEF(0x907C, 1) /* jp78 */ OTFT_DEF(0x90A3, 1) /* jp78 */ OTFT_DEF(0x912D, 3) /* jp04 */ OTFT_DEF(0x914B, 3) /* jp04 */ OTFT_DEF(0x91C1, 1) /* jp78 */ OTFT_DEF(0x91C7, 1) /* jp78 */ OTFT_DEF(0x91DC, 3) /* jp04 */ OTFT_DEF(0x9306, 3) /* jp04 */ OTFT_DEF(0x9375, 3) /* jp04 */ OTFT_DEF(0x939A, 3) /* jp04 */ OTFT_DEF(0x9453, 3) /* jp04 */ OTFT_DEF(0x9699, 3) /* jp04 */ OTFT_DEF(0x9724, 1) /* jp78 */ OTFT_DEF(0x9760, 1) /* jp78 */ OTFT_DEF(0x976D, 1) /* jp78 */ OTFT_DEF(0x9771, 1) /* jp78 */ OTFT_DEF(0x9774, 1) /* jp78 */ OTFT_DEF(0x9784, 3) /* jp04 */ OTFT_DEF(0x9798, 3) /* jp04 */ OTFT_DEF(0x97AD, 3) /* jp04 */ OTFT_DEF(0x9813, 1) /* jp78 */ OTFT_DEF(0x9824, 1) /* jp78 */ OTFT_DEF(0x98F4, 3) /* jp04 */ OTFT_DEF(0x9905, 3) /* jp04 */ OTFT_DEF(0x990C, 1) /* jp78 */ OTFT_DEF(0x9910, 3) /* jp04 */ OTFT_DEF(0x9957, 3) /* jp04 */ OTFT_DEF(0x99C1, 3) /* jp04 */ OTFT_DEF(0x9A19, 3) /* jp04 */ OTFT_DEF(0x9A4A, 3) /* jp04 */ OTFT_DEF(0x9B2E, 1) /* jp78 */ OTFT_DEF(0x9B97, 1) /* jp78 */ OTFT_DEF(0x9BAB, 3) /* jp04 */ OTFT_DEF(0x9BD6, 3) /* jp04 */ OTFT_DEF(0x9BF2, 1) /* jp78 */ OTFT_DEF(0x9C2F, 3) /* jp04 */ OTFT_DEF(0x9C48, 1) /* jp78 */ OTFT_DEF(0x9C52, 3) /* jp04 */ OTFT_DEF(0x9D07, 1) /* jp78 */ OTFT_DEF(0x9D09, 3) /* jp04 */ OTFT_DEF(0x9D60, 3) /* jp04 */ OTFT_DEF(0x9EAA, 1) /* jp78 */ OTFT_DEF(0x9EDB, 1) /* jp78 */ OTFT_DEF(0x9F9C, 1) /* jp78 */ OTFT_DEF(0x9F9D, 1) /* jp78 */ OTFT_DEF_END(258) OTFT_DEF_BEGIN(439) /* E0102 */ OTFT_DEF(0x537F, 3) /* jp04 */ OTFT_DEF(0x6062, 3) /* jp04 */ OTFT_DEF(0x717D, 3) /* jp04 */ OTFT_DEF(0x7337, 3) /* jp04 */ OTFT_DEF(0x7515, 3) /* jp04 */ OTFT_DEF(0x7B08, 3) /* jp04 */ OTFT_DEF(0x7C3E, 3) /* jp04 */ OTFT_DEF(0x7C7E, 3) /* jp04 */ OTFT_DEF(0x8612, 3) /* jp04 */ OTFT_DEF(0x8805, 3) /* jp04 */ OTFT_DEF(0x8A1D, 3) /* jp04 */ OTFT_DEF(0x9041, 3) /* jp04 */ OTFT_DEF(0x9771, 3) /* jp04 */ OTFT_DEF_END(13) OTFT_DEF_BEGIN(452) /* E0103 */ OTFT_DEF(0x61F2, 3) /* jp04 */ OTFT_DEF(0x7511, 3) /* jp04 */ OTFT_DEF(0x990C, 3) /* jp04 */ OTFT_DEF_END(3) OTFT_DEF_BEGIN(455) /* E0104 */ OTFT_DEF_END(0) OTFT_DEF_BEGIN(455) /* E0105 */ OTFT_DEF(0x53A9, 3) /* jp04 */ OTFT_DEF_END(1)
14,883
C++
.h
468
29.826923
31
0.582518
snowie2000/mactype
9,859
437
273
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,154
ft2vert.h
snowie2000_mactype/ft2vert.h
#ifdef __cplusplus extern "C"{ #endif /* store GSUB feature vert/vrt2 */ struct ft2vert_st *ft2vert_init(FT_Face face); void ft2vert_final(FT_Face face, struct ft2vert_st *vert); /* convert horizontal glyph index to vertical glyph index */ FT_UInt ft2vert_get_gid(const struct ft2vert_st *ft2vert, const FT_UInt gid); FT_UInt ft2_subst_uvs(const FT_Face face, const FT_UInt gid, const FT_UInt vsindex, const FT_UInt baseChar); #ifdef __cplusplus } #endif
461
C++
.h
13
34
108
0.767494
snowie2000/mactype
9,859
437
273
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,155
stdint.h
snowie2000_mactype/stdint.h
/* stdint.h Integer types - c99 7.18 */ /* * C/C++ Run Time Library - Version 13.0 * * Copyright (c) 2002, 2007 by CodeGear * All Rights Reserved. * */ #ifndef __STDINT_H #define __STDINT_H /* 7.18.1.1 Exact-width integer types */ typedef __int8 int8_t; typedef __int16 int16_t; typedef __int32 int32_t; typedef __int64 int64_t; typedef unsigned __int8 uint8_t; typedef unsigned __int16 uint16_t; typedef unsigned __int32 uint32_t; typedef unsigned __int64 uint64_t; /* 7.18.1.2 Minimum-width integer types */ typedef __int8 int_least8_t; typedef __int16 int_least16_t; typedef __int32 int_least32_t; typedef __int64 int_least64_t; typedef unsigned __int8 uint_least8_t; typedef unsigned __int16 uint_least16_t; typedef unsigned __int32 uint_least32_t; typedef unsigned __int64 uint_least64_t; /* 7.18.1.3 Fastest minimum-width integer types */ typedef __int8 int_fast8_t; typedef __int16 int_fast16_t; typedef __int32 int_fast32_t; typedef __int64 int_fast64_t; typedef unsigned __int8 uint_fast8_t; typedef unsigned __int16 uint_fast16_t; typedef unsigned __int32 uint_fast32_t; typedef unsigned __int64 uint_fast64_t; /* 7.18.1.4 Integer types capable of holding object pointers */ typedef int32_t intptr_t; typedef uint32_t uintptr_t; /* 7.18.1.5 Greatest-width integer types */ typedef int64_t intmax_t; typedef uint64_t uintmax_t; /* 7.18.2.1 Limits of exact-width integer types */ #define INT8_MIN ((int8_t) -128) #define INT16_MIN ((int16_t) -32768) #define INT32_MIN ((int32_t) -2147483647L - 1) #define INT64_MIN ((int64_t) -9223372036854775807LL - 1) #define INT8_MAX ((int8_t) 127) #define INT16_MAX ((int16_t) 32767) #define INT32_MAX ((int32_t) 2147483647L) #define INT64_MAX ((int64_t) 9223372036854775807LL) #define UINT8_MAX ((uint8_t) 255) #define UINT16_MAX ((uint16_t) 65535) #define UINT32_MAX ((uint32_t) 4294967295UL) #define UINT64_MAX ((uint64_t) 18446744073709551615ULL) /* 7.18.2.2 Limits of minimum-width integer types */ #define INT_LEAST8_MIN ((int_least8_t) -128) #define INT_LEAST16_MIN ((int_least16_t) -32768) #define INT_LEAST32_MIN ((int_least32_t) -2147483647L - 1) #define INT_LEAST64_MIN ((int_least64_t) -9223372036854775807LL - 1) #define INT_LEAST8_MAX ((int_least8_t) 127) #define INT_LEAST16_MAX ((int_least16_t) 32767) #define INT_LEAST32_MAX ((int_least32_t) 2147483647L) #define INT_LEAST64_MAX ((int_least64_t) 9223372036854775807LL) #define UINT_LEAST8_MAX ((uint_least8_t) 255) #define UINT_LEAST16_MAX ((uint_least16_t) 65535) #define UINT_LEAST32_MAX ((uint_least32_t) 4294967295UL) #define UINT_LEAST64_MAX ((uint_least64_t) 18446744073709551615ULL) /* 7.18.2.3 Limits of fastest minimum-width integer types */ #define INT_FAST8_MIN ((int_fast8_t) -128) #define INT_FAST16_MIN ((int_fast16_t) -32768) #define INT_FAST32_MIN ((int_fast32_t) -2147483647L - 1) #define INT_FAST64_MIN ((int_fast64_t) -9223372036854775807LL - 1) #define INT_FAST8_MAX ((int_fast8_t) 127) #define INT_FAST16_MAX ((int_fast16_t) 32767) #define INT_FAST32_MAX ((int_fast32_t) 2147483647L) #define INT_FAST64_MAX ((int_fast64_t) 9223372036854775807LL) #define UINT_FAST8_MAX ((uint_fast8_t) 255) #define UINT_FAST16_MAX ((uint_fast16_t) 65535) #define UINT_FAST32_MAX ((uint_fast32_t) 4294967295UL) #define UINT_FAST64_MAX ((uint_fast64_t) 18446744073709551615ULL) /* 7.18.2.4 Limits of integer types capable of holding object pointers */ #define INTPTR_MIN ((intptr_t) -2147483647L - 1) #define INTPTR_MAX ((intptr_t) 2147483647L) #define UINTPTR_MAX ((intptr_t) 4294967295UL) /* 7.18.2.5 Limits of greatest-width integer types */ #define INTMAX_MIN ((intmax_t) -9223372036854775807LL - 1) #define INTMAX_MAX ((intmax_t) 9223372036854775807LL) #define UINTMAX_MAX ((uintmax_t) 18446744073709551615ULL) /* 7.18.3 Limits of other integer types */ #define PTRDIFF_MIN ((int32_t) -2147483647L - 1) #define PTRDIFF_MAX ((int32_t) 2147483647L) #ifdef __STDC_LIMIT_MACROS #define SIG_ATOMIC_MIN INT32_MIN #define SIG_ATOMIC_MAX INT32_MAX #endif #define SIZE_MAX UINT32_MAX #ifdef __STDC_CONSTANT_MACROS #define WCHAR_MIN 0 #define WCHAR_MAX UINT16_MAX #define WINT_MIN 0 #define WINT_MAX UINT16_MAX #endif /* 7.18.4.1 Macros for minimum-width integer constants */ #define INT8_C(x) ((int8_t) x) #define INT16_C(x) ((int16_t) x) #define INT32_C(x) ((int32_t) x) #define INT64_C(x) ((int64_t) x) #define UINT8_C(x) ((uint8_t) x) #define UINT16_C(x) ((uint16_t) x) #define UINT32_C(x) ((uint32_t) x) #define UINT64_C(x) ((uint64_t) x) /* 7.18.4.2 Macros for greatest-width integer constants */ #define INTMAX_C(x) ((intmax_t) x) #define UINTMAX_C(x) ((uintmax_t) x) #endif /* __STDINT_H */
4,704
C++
.h
119
37.865546
73
0.73965
snowie2000/mactype
9,859
437
273
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,157
directwrite.h
snowie2000_mactype/directwrite.h
#include "common.h" #include <VersionHelpers.h> #pragma once #ifdef EASYHOOK #include "easyhook.h" #define HOOK_MANUALLY HOOK_DEFINE #define HOOK_DEFINE(rettype, name, argtype, arglist) \ extern rettype(WINAPI * ORIG_##name) argtype; \ extern HOOK_TRACE_INFO HOOK_##name; #include "hooklist.h" #undef HOOK_DEFINE #undef HOOK_MANUALLY #define HOOK_MANUALLY(rettype, name, argtype, arglist) \ extern LONG hook_demand_##name(bool bForce = false); #define HOOK_DEFINE(rettype, name, argtype, arglist) ; #include "hooklist.h" #undef HOOK_DEFINE #undef HOOK_MANUALLY #else #define HOOK_MANUALLY HOOK_DEFINE #define HOOK_DEFINE(rettype, name, argtype, arglist) \ extern rettype(WINAPI * ORIG_##name) argtype; \ extern BOOL IsHooked_##name; #include "hooklist.h" #undef HOOK_DEFINE #undef HOOK_MANUALLY #define HOOK_MANUALLY(rettype, name, argtype, arglist) \ extern LONG hook_demand_##name(bool bForce = false); #define HOOK_DEFINE(rettype, name, argtype, arglist) ; #include "hooklist.h" #undef HOOK_DEFINE #undef HOOK_MANUALLY #endif
1,084
C++
.h
33
30.242424
57
0.75
snowie2000/mactype
9,859
437
273
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,159
hookCounter.h
snowie2000_mactype/hookCounter.h
#pragma once #include <atomic> #include <thread> #include <chrono> class HCounter { static std::atomic<int> ref; public: HCounter() { ++this->ref; } ~HCounter() { --this->ref; } static bool wait(int nCount) { while (--nCount && HCounter::ref.load()) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); } return !HCounter::ref; } };
389
C++
.h
20
16.05
62
0.631579
snowie2000/mactype
9,859
437
273
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,163
ownedcs.h
snowie2000_mactype/ownedcs.h
#include <windows.h> typedef struct _OWNED_CRITIAL_SECTION { int nOwner, nRequests, nRecursiveCount; HANDLE hEvent; CRITICAL_SECTION threadLock; }OWNED_CRITIAL_SECTION, *POWNED_CRITIAL_SECTION; //用于自定义临界区 void WINAPI InitializeOwnedCritialSection(POWNED_CRITIAL_SECTION cs); void WINAPI DeleteOwnedCritialSection(POWNED_CRITIAL_SECTION cs); void WINAPI EnterOwnedCritialSection(POWNED_CRITIAL_SECTION cs, WORD Owner); void WINAPI LeaveOwnedCritialSection(POWNED_CRITIAL_SECTION cs, WORD Owner);
518
C++
.h
12
40.25
76
0.844262
snowie2000/mactype
9,859
437
273
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,164
colorinvert.h
snowie2000_mactype/colorinvert.h
#pragma once //formula: (x+482)^2+(y+481)^2=880^2 unsigned char InvertTable[260] = { 255,255,254,253,253,252,251,251,250,249,249,248,247,247,246,245,245,244,243,242,242,241,240,240,239,238,238,237,236,235,235,234,233,233,232,231,230,230,229,228,227,227,226,225,224,224,223,222,221,221,220,219,218,218,217,216,215,215,214,213,212,211,211,210,209,208,208,207,206,205,204,204,203,202,201,200,199,199,198,197,196,195,195,194,193,192,191,190,189,189,188,187,186,185,184,183,183,182,181,180,179,178,177,176,176,175,174,173,172,171,170,169,168,167,166,166,165,164,163,162,161,160,159,158,157,156,155,154,153,152,151,150,149,148,147,146,145,144,143,143,142,141,140,138,137,136,135,134,133,132,131,130,129,128,127,126,125,124,123,122,121,120,119,118,117,115,114,113,112,111,110,109,108,107,106,104,103,102,101,100,99,98,96,95,94,93,92,91,90,88,87,86,85,84,82,81,80,79,78,76,75,74,73,71,70,69,68,66,65,64,63,61,60,59,58,56,55,54,52,51,50,48,47,46,44,43,42,40,39,38,36,35,33,32,31,29,28,26,25,24,22,21,19,18,16,15,13,12,10,9,7,6,4,3,1,0,0,0,0,0};
1,039
C++
.h
3
344.333333
986
0.720077
snowie2000/mactype
9,859
437
273
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,166
easyhook.h
snowie2000_mactype/easyhook.h
/* EasyHook - The reinvention of Windows API hooking Copyright (C) 2009 Christoph Husse This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Please visit http://www.codeplex.com/easyhook for more information about the project and latest updates. */ #ifndef _EASYHOOK_H_ #define _EASYHOOK_H_ #ifdef DRIVER #include <ntddk.h> #include <ntstrsafe.h> typedef int BOOL; typedef void* HMODULE; #else // #define NTDDI_VERSION NTDDI_WIN2KSP4 // #define _WIN32_WINNT 0x500 #define _WIN32_IE_ _WIN32_IE_WIN2KSP4 #include <windows.h> #include <winnt.h> #include <winternl.h> #endif #ifdef __cplusplus extern "C"{ #endif #ifdef EASYHOOK_EXPORTS #define EASYHOOK_API __declspec(dllexport) __stdcall #define DRIVER_SHARED_API(type, decl) EXTERN_C type EASYHOOK_API decl #else #ifndef DRIVER #ifdef STATIC_LIB #define EASYHOOK_API __stdcall #else #define EASYHOOK_API __declspec(dllimport) __stdcall #endif #define DRIVER_SHARED_API(type, decl) EXTERN_C type EASYHOOK_API decl #else #define EASYHOOK_API __stdcall #define DRIVER_SHARED_API(type, decl) typedef type EASYHOOK_API PROC_##decl; EXTERN_C type EASYHOOK_API decl #endif #endif /* This is the typical sign that a defined method is exported... Methods marked with this attribute need special attention during parameter validation and documentation. */ #define EASYHOOK_NT_EXPORT EXTERN_C NTSTATUS EASYHOOK_API #define EASYHOOK_BOOL_EXPORT EXTERN_C BOOL EASYHOOK_API #define MAX_HOOK_COUNT 128 #define MAX_ACE_COUNT 128 #define MAX_THREAD_COUNT 128 #define MAX_PASSTHRU_SIZE 1024 * 64 typedef struct _HOOK_ACL_ { ULONG Count; BOOL IsExclusive; ULONG Entries[MAX_ACE_COUNT]; }HOOK_ACL; typedef struct _LOCAL_HOOK_INFO_* PLOCAL_HOOK_INFO; typedef struct _HOOK_TRACE_INFO_ { PLOCAL_HOOK_INFO Link; }HOOK_TRACE_INFO, *TRACED_HOOK_HANDLE; typedef struct _LOCAL_HOOK_INFO_ { PLOCAL_HOOK_INFO Next; ULONG NativeSize; UCHAR* TargetProc; ULONGLONG TargetBackup; ULONGLONG TargetBackup_x64; ULONGLONG HookCopy; ULONG EntrySize; UCHAR* Trampoline; ULONG HLSIndex; ULONG HLSIdent; void* Callback; HOOK_ACL LocalACL; ULONG Signature; TRACED_HOOK_HANDLE Tracking; void* RandomValue; // fixed void* HookIntro; // fixed UCHAR* OldProc; // fixed UCHAR* HookProc; // fixed void* HookOutro; // fixed int* IsExecutedPtr; // fixed }LOCAL_HOOK_INFO, *PLOCAL_HOOK_INFO; DRIVER_SHARED_API(NTSTATUS, RtlGetLastError()); DRIVER_SHARED_API(PWCHAR, RtlGetLastErrorString()); DRIVER_SHARED_API(NTSTATUS, LhInstallHook( void* InEntryPoint, void* InHookProc, void* InCallback, TRACED_HOOK_HANDLE OutHandle)); DRIVER_SHARED_API(NTSTATUS, LhUninstallAllHooks()); DRIVER_SHARED_API(NTSTATUS, LhUninstallHook(TRACED_HOOK_HANDLE InHandle)); DRIVER_SHARED_API(NTSTATUS, LhWaitForPendingRemovals()); #ifdef STATIC_LIB BOOL APIENTRY EasyHookDllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved); #endif /* Setup the ACLs after hook installation. Please note that every hook starts suspended. You will have to set a proper ACL to make it active! */ #ifdef DRIVER DRIVER_SHARED_API(NTSTATUS, LhSetInclusiveACL( ULONG* InProcessIdList, ULONG InProcessCount, TRACED_HOOK_HANDLE InHandle)); DRIVER_SHARED_API(NTSTATUS, LhSetExclusiveACL( ULONG* InProcessIdList, ULONG InProcessCount, TRACED_HOOK_HANDLE InHandle)); DRIVER_SHARED_API(NTSTATUS, LhSetGlobalInclusiveACL( ULONG* InProcessIdList, ULONG InProcessCount)); DRIVER_SHARED_API(NTSTATUS, LhSetGlobalExclusiveACL( ULONG* InProcessIdList, ULONG InProcessCount)); DRIVER_SHARED_API(NTSTATUS, LhIsProcessIntercepted( TRACED_HOOK_HANDLE InHook, ULONG InProcessID, BOOL* OutResult)); #else EASYHOOK_NT_EXPORT LhSetInclusiveACL( ULONG* InThreadIdList, ULONG InThreadCount, TRACED_HOOK_HANDLE InHandle); EASYHOOK_NT_EXPORT LhSetExclusiveACL( ULONG* InThreadIdList, ULONG InThreadCount, TRACED_HOOK_HANDLE InHandle); EASYHOOK_NT_EXPORT LhSetGlobalInclusiveACL( ULONG* InThreadIdList, ULONG InThreadCount); EASYHOOK_NT_EXPORT LhSetGlobalExclusiveACL( ULONG* InThreadIdList, ULONG InThreadCount); EASYHOOK_NT_EXPORT LhIsThreadIntercepted( TRACED_HOOK_HANDLE InHook, ULONG InThreadID, BOOL* OutResult); #endif // !DRIVER /* The following barrier methods are meant to be used in hook handlers only! They will all fail with STATUS_NOT_SUPPORTED if called outside a valid hook handler... */ DRIVER_SHARED_API(NTSTATUS, LhBarrierGetCallback(PVOID* OutValue)); DRIVER_SHARED_API(NTSTATUS, LhBarrierGetReturnAddress(PVOID* OutValue)); DRIVER_SHARED_API(NTSTATUS, LhBarrierGetAddressOfReturnAddress(PVOID** OutValue)); DRIVER_SHARED_API(NTSTATUS, LhBarrierBeginStackTrace(PVOID* OutBackup)); DRIVER_SHARED_API(NTSTATUS, LhBarrierEndStackTrace(PVOID InBackup)); typedef struct _MODULE_INFORMATION_* PMODULE_INFORMATION; typedef struct _MODULE_INFORMATION_ { PMODULE_INFORMATION Next; UCHAR* BaseAddress; ULONG ImageSize; CHAR Path[256]; PCHAR ModuleName; }MODULE_INFORMATION; EASYHOOK_NT_EXPORT LhUpdateModuleInformation(); DRIVER_SHARED_API(NTSTATUS, LhBarrierPointerToModule( PVOID InPointer, MODULE_INFORMATION* OutModule)); DRIVER_SHARED_API(NTSTATUS, LhEnumModules( HMODULE* OutModuleArray, ULONG InMaxModuleCount, ULONG* OutModuleCount)); DRIVER_SHARED_API(NTSTATUS, LhBarrierGetCallingModule(MODULE_INFORMATION* OutModule)); DRIVER_SHARED_API(NTSTATUS, LhBarrierCallStackTrace( PVOID* OutMethodArray, ULONG InMaxMethodCount, ULONG* OutMethodCount)); #ifdef DRIVER #define DRIVER_EXPORT(proc) PROC_##proc * proc #define EASYHOOK_INTERFACE_v_1 0x0001 #define EASYHOOK_WIN32_DEVICE_NAME L"\\\\.\\EasyHook" #define EASYHOOK_DEVICE_NAME L"\\Device\\EasyHook" #define EASYHOOK_DOS_DEVICE_NAME L"\\DosDevices\\EasyHook" #define FILE_DEVICE_EASYHOOK 0x893F typedef struct _EASYHOOK_INTERFACE_API_v_1_ { DRIVER_EXPORT(RtlGetLastError); DRIVER_EXPORT(RtlGetLastErrorString); DRIVER_EXPORT(LhInstallHook); DRIVER_EXPORT(LhUninstallHook); DRIVER_EXPORT(LhWaitForPendingRemovals); DRIVER_EXPORT(LhBarrierGetCallback); DRIVER_EXPORT(LhBarrierGetReturnAddress); DRIVER_EXPORT(LhBarrierGetAddressOfReturnAddress); DRIVER_EXPORT(LhBarrierBeginStackTrace); DRIVER_EXPORT(LhBarrierEndStackTrace); DRIVER_EXPORT(LhBarrierPointerToModule); DRIVER_EXPORT(LhBarrierGetCallingModule); DRIVER_EXPORT(LhBarrierCallStackTrace); DRIVER_EXPORT(LhSetGlobalExclusiveACL); DRIVER_EXPORT(LhSetGlobalInclusiveACL); DRIVER_EXPORT(LhSetExclusiveACL); DRIVER_EXPORT(LhSetInclusiveACL); DRIVER_EXPORT(LhIsProcessIntercepted); }EASYHOOK_INTERFACE_API_v_1, *PEASYHOOK_INTERFACE_API_v_1; typedef struct _EASYHOOK_DEVICE_EXTENSION_ { ULONG MaxVersion; // enumeration of APIs EASYHOOK_INTERFACE_API_v_1 API_v_1; }EASYHOOK_DEVICE_EXTENSION, *PEASYHOOK_DEVICE_EXTENSION; static NTSTATUS EasyHookQueryInterface( ULONG InInterfaceVersion, PVOID OutInterface, PFILE_OBJECT* OutEasyHookDrv) { /* Description: Provides a convenient way to load the desired EasyHook interface. The method will only work if the EasyHook support driver is loaded, of course. If you don't need the interface anymore, you have to release the file object with ObDereferenceObject(). Parameters: - InInterfaceVersion The desired interface version. Any future EasyHook driver will ALWAYS be backward compatible. This is the reason why I provide such a flexible interface mechanism. - OutInterface A pointer to the interface structure to be filled with data. If you specify EASYHOOK_INTERFACE_v_1 as InInterfaceVersion, you will have to provide a pointer to a EASYHOOK_INTERFACE_API_v_1 structure, for example... - OutEasyHookDrv A reference to the EasyHook driver. Make sure that you dereference it if you don't need the interface any longer! As long as you keep this handle, the EasyHook driver CAN'T be unloaded... */ UNICODE_STRING DeviceName; PDEVICE_OBJECT hEasyHookDrv = NULL; NTSTATUS NtStatus = STATUS_INTERNAL_ERROR; EASYHOOK_DEVICE_EXTENSION* DevExt; /* Open log file... */ RtlInitUnicodeString(&DeviceName, EASYHOOK_DEVICE_NAME); if(!NT_SUCCESS(NtStatus = IoGetDeviceObjectPointer(&DeviceName, FILE_READ_DATA, OutEasyHookDrv, &hEasyHookDrv))) return NtStatus; __try { DevExt = (EASYHOOK_DEVICE_EXTENSION*)hEasyHookDrv->DeviceExtension; if(DevExt->MaxVersion < InInterfaceVersion) return STATUS_NOT_SUPPORTED; switch(InInterfaceVersion) { case EASYHOOK_INTERFACE_v_1: memcpy(OutInterface, &DevExt->API_v_1, sizeof(DevExt->API_v_1)); break; default: return STATUS_INVALID_PARAMETER_1; } return STATUS_SUCCESS; } __except(EXCEPTION_EXECUTE_HANDLER) { ObDereferenceObject(*OutEasyHookDrv); return NtStatus; } } #endif // DRIVER #ifndef DRIVER /* Debug helper API. */ EASYHOOK_BOOL_EXPORT DbgIsAvailable(); EASYHOOK_BOOL_EXPORT DbgIsEnabled(); EASYHOOK_NT_EXPORT DbgAttachDebugger(); EASYHOOK_NT_EXPORT DbgDetachDebugger(); EASYHOOK_NT_EXPORT DbgGetThreadIdByHandle( HANDLE InThreadHandle, ULONG* OutThreadId); EASYHOOK_NT_EXPORT DbgGetProcessIdByHandle( HANDLE InProcessHandle, ULONG* OutProcessId); EASYHOOK_NT_EXPORT DbgHandleToObjectName( HANDLE InNamedHandle, UNICODE_STRING* OutNameBuffer, ULONG InBufferSize, ULONG* OutRequiredSize); /* Injection support API. */ typedef struct _REMOTE_ENTRY_INFO_ { ULONG HostPID; UCHAR* UserData; ULONG UserDataSize; }REMOTE_ENTRY_INFO; typedef void __stdcall REMOTE_ENTRY_POINT(REMOTE_ENTRY_INFO* InRemoteInfo); #define EASYHOOK_INJECT_DEFAULT 0x00000000 #define EASYHOOK_INJECT_STEALTH 0x10000000 // (experimental) #define EASYHOOK_INJECT_NET_DEFIBRILLATOR 0x20000000 // USE THIS ONLY IN UNMANAGED CODE AND ONLY WITH CreateAndInject() FOR MANAGED PROCESSES!! EASYHOOK_NT_EXPORT RhCreateStealthRemoteThread( ULONG InTargetPID, LPTHREAD_START_ROUTINE InRemoteRoutine, PVOID InRemoteParam, HANDLE* OutRemoteThread); EASYHOOK_NT_EXPORT RhInjectLibrary( ULONG InTargetPID, ULONG InWakeUpTID, ULONG InInjectionOptions, WCHAR* InLibraryPath_x86, WCHAR* InLibraryPath_x64, PVOID InPassThruBuffer, ULONG InPassThruSize); EASYHOOK_NT_EXPORT RhCreateAndInject( WCHAR* InEXEPath, WCHAR* InCommandLine, ULONG InProcessCreationFlags, ULONG InInjectionOptions, WCHAR* InLibraryPath_x86, WCHAR* InLibraryPath_x64, PVOID InPassThruBuffer, ULONG InPassThruSize, ULONG* OutProcessId); EASYHOOK_BOOL_EXPORT RhIsX64System(); EASYHOOK_NT_EXPORT RhIsX64Process( ULONG InProcessId, BOOL* OutResult); EASYHOOK_BOOL_EXPORT RhIsAdministrator(); EASYHOOK_NT_EXPORT RhWakeUpProcess(); EASYHOOK_NT_EXPORT RhInstallSupportDriver(); EASYHOOK_NT_EXPORT RhInstallDriver( WCHAR* InDriverPath, WCHAR* InDriverName); typedef struct _GACUTIL_INFO_* HGACUTIL; #endif // !DRIVER #ifdef __cplusplus }; #endif #endif
12,326
C++
.h
345
32.086957
144
0.751074
snowie2000/mactype
9,859
437
273
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
true
false
false
false
false
false
false
14,169
wow64layer.h
snowie2000_mactype/wow64layer.h
/* #ifndef CONTEXT_i386 #define CONTEXT_i386 0x00010000 // this assumes that i386 and #define CONTEXT_i486 0x00010000 // i486 have identical context records #endif #define WOW64_CS32 0x23*/ #include <Windows.h> BOOL XP_GetThreadWow64Context( __in HANDLE Thread, __in_opt HANDLE Process, __inout PWOW64_CONTEXT Ctx32 ) { THREAD_BASIC_INFORMATION ThreadInfo; PWOW64_CONTEXT RemoteCtx; CONTEXT Ctx64; SIZE_T Transferred; ULONG ContextFlags; BOOLEAN CloseProcess; ULONG LastError; CloseProcess = FALSE; Ctx64.ContextFlags = CONTEXT_ALL; // // Determine whether the thread is running in 64-bit mode or not. If it is // running in 64-bit mode then we'll get the saved 32-bit context out of // the pointer in the 64-bit TEB's TLS slot. // // If, however, the thread is running in 32-bit mode, then we'll need to be // converting the 32-bit halves of the 64-bit registers into the // appropriate fields of the WOW64_CONTEXT structure. // if (!GetThreadContext( Thread, &Ctx64)) return FALSE; if (Ctx64.SegCs != WOW64_CS32) { wprintf(L" -- Target is in 64-bit mode, returning saved 32-bit context\n"); // // The thread is running in 64-bit mode. We'll need to find the base // address of the thread's TEB and from there, read the remote TLS // slots and then the actual WOW64_CONTEXT structure residing within // the target. // // Also, if the caller didn't supply a process handle, then we'll // attempt to open one now using the thread's associated process ID in // the THREAD_BASIC_INFORMATION structure. This is the typical // behavior of the Wow64 implementation of GetThreadContext. // if (!NT_SUCCESS(NtQueryInformationThread( Thread, ThreadBasicInformation, &ThreadInfo, sizeof( THREAD_BASIC_INFORMATION ), 0 ))) { SetLastError( ERROR_INVALID_HANDLE ); return FALSE; } // // If we don't have a process handle then we'll need to be opening one // ourselves for the VM read operation. // if (!Process) { Process = OpenProcess( PROCESS_VM_READ, FALSE, HandleToUlong(ThreadInfo.ClientId.UniqueProcess) ); if (!Process) return FALSE; CloseProcess = TRUE; } // // Fetch the second TLS slot. Wow64 assumes (hardcoded) that the // second TLS slot is the WOW64_CONTEXT. This is a bit sloppy, but it // works out as there's not a 64-bit kernel32.dll loaded in a Wow64 // process, so there won't be anyone calling TlsAlloc anyway. // if (!ReadProcessMemory( Process, &((PTEB)ThreadInfo.TebBaseAddress)->TlsSlots[ 1 ], &RemoteCtx, sizeof( PWOW64_CONTEXT ), &Transferred)) { if (CloseProcess) { LastError = GetLastError(); CloseHandle( Process ); SetLastError( LastError ); } return FALSE; } if (Transferred != sizeof( PWOW64_CONTEXT )) { if (CloseProcess) CloseHandle( Process ); SetLastError( ERROR_PARTIAL_COPY ); return FALSE; } // // Now that we've got the PWOW64_CONTEXT pointer, let's read the memory // where the actual context is stored. // // Note that this is unreliable if the remote thread is still running // when we make the call. // // // TODO: Pay attention to the caller's requested context flags and // filter the returned context appropriately. // if (!ReadProcessMemory( Process, (PUCHAR)(RemoteCtx) + sizeof( ULONG ), Ctx32, sizeof( WOW64_CONTEXT ), &Transferred )) { if (CloseProcess) { LastError = GetLastError(); CloseHandle( Process ); SetLastError( LastError ); } return FALSE; } if (Transferred != sizeof( WOW64_CONTEXT )) { if (CloseProcess) CloseHandle( Process ); SetLastError( ERROR_PARTIAL_COPY ); return FALSE; } // // All done. // } else { wprintf(L" -- Target is in 32-bit mode, truncating 64-bit registers\n"); // // The requested thread is executing 32-bit instructions and is not in // the Wow64 layer (e.g. a system call). This means that the 64-bit // thread context is actually reflective of the Wow64 context, except // that we need to convert from an x64 context strucuture to the // WOW64_CONTEXT structure (the high halves of registers are discarded // here). // ContextFlags = Ctx32->ContextFlags | CONTEXT_i386; ZeroMemory( Ctx32, sizeof( WOW64_CONTEXT ) ); Ctx32->ContextFlags = ContextFlags; if (ContextFlags & CONTEXT_CONTROL) { Ctx32->Eip = (ULONG)Ctx64.Rip; Ctx32->EFlags = (ULONG)Ctx64.EFlags; Ctx32->Esp = (ULONG)Ctx64.Rsp; Ctx32->Ebp = (ULONG)Ctx64.Rbp; } if (ContextFlags & CONTEXT_INTEGER) { Ctx32->Eax = (ULONG)Ctx64.Rax; Ctx32->Ebx = (ULONG)Ctx64.Rbx; Ctx32->Ecx = (ULONG)Ctx64.Rcx; Ctx32->Edx = (ULONG)Ctx64.Rdx; Ctx32->Edi = (ULONG)Ctx64.Rdi; Ctx32->Esi = (ULONG)Ctx64.Rsi; } // // TODO: Convert other registers, pay attention to the caller's // requested context flags. For example, floating point registers // would need to be handled here if support for them is desired. // // // All done. // } if (CloseProcess) CloseHandle( Process ); return TRUE; }
5,303
C++
.h
187
24.877005
77
0.680528
snowie2000/mactype
9,859
437
273
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,172
hooklist.h
snowie2000_mactype/hooklist.h
HOOK_DEFINE(int, GetObjectW, (__in HANDLE h, __in int c, __out_bcount_opt(c) LPVOID pv), (h, c, pv)) HOOK_DEFINE(int, GetObjectA, (__in HANDLE h, __in int c, __out_bcount_opt(c) LPVOID pv), (h, c, pv)) HOOK_DEFINE(int, GetTextFaceAliasW, (HDC hdc, int nLen, LPWSTR lpAliasW), (hdc, nLen, lpAliasW)) HOOK_DEFINE(BOOL, DeleteObject, ( HGDIOBJ hObject),(hObject)) HOOK_DEFINE(int, GetTextFaceW, ( __in HDC hdc, __in int c, __out_ecount_part_opt(c, return) LPWSTR lpName), (hdc, c, lpName)) HOOK_DEFINE(int, GetTextFaceA, ( __in HDC hdc, __in int c, __out_ecount_part_opt(c, return) LPSTR lpName), (hdc, c, lpName)) HOOK_DEFINE(DWORD, GetGlyphOutlineW, ( __in HDC hdc, \ __in UINT uChar, \ __in UINT fuFormat, \ __out LPGLYPHMETRICS lpgm, \ __in DWORD cjBuffer, \ __out_bcount_opt(cjBuffer) LPVOID pvBuffer, \ __in CONST MAT2 *lpmat2 \ ), (hdc, uChar, fuFormat, lpgm, cjBuffer, pvBuffer, lpmat2)) HOOK_DEFINE(DWORD, GetGlyphOutlineA, (__in HDC hdc, \ __in UINT uChar, \ __in UINT fuFormat, \ __out LPGLYPHMETRICS lpgm, \ __in DWORD cjBuffer, \ __out_bcount_opt(cjBuffer) LPVOID pvBuffer, \ __in CONST MAT2 *lpmat2), \ (hdc, uChar, fuFormat, lpgm, cjBuffer, pvBuffer, lpmat2)) // DrawTextA,W // DrawTextExA,W // TabbedTextOutA,W // TextOutA,W // ExtTextOutA // は内部で ExtTextOutWを呼んでるから ExtTextOutW だけ実装すればOK。←XPの場合 // Windows 2000 でも動くようにその他のAPIもフックを掛けておく。 HOOK_MANUALLY(HFONT, CreateFontIndirectW, (CONST LOGFONTW *lplf), (lplf)) HOOK_MANUALLY(HFONT, CreateFontIndirectExW, (CONST ENUMLOGFONTEXDV *penumlfex), (penumlfex)) // HOOK_DEFINE(BOOL, GetCharWidthW, (HDC hdc, UINT iFirstChar, UINT iLastChar, LPINT lpBuffer)) // HOOK_DEFINE(BOOL, GetCharWidth32W, (HDC hdc, UINT iFirstChar, UINT iLastChar, LPINT lpBuffer)) HOOK_DEFINE(BOOL, TextOutA, (HDC hdc, int nXStart, int nYStart, LPCSTR lpString, int cbString), (hdc, nXStart, nYStart, lpString, cbString)) HOOK_DEFINE(BOOL, TextOutW, (HDC hdc, int nXStart, int nYStart, LPCWSTR lpString, int cbString), (hdc, nXStart, nYStart, lpString, cbString)) HOOK_DEFINE(BOOL, ExtTextOutA, (HDC hdc, int nXStart, int nYStart, UINT fuOptions, CONST RECT *lprc, LPCSTR lpString, UINT cbString, CONST INT *lpDx), (hdc, nXStart, nYStart, fuOptions, lprc, lpString, cbString, lpDx)) HOOK_DEFINE(BOOL, ExtTextOutW, (HDC hdc, int nXStart, int nYStart, UINT fuOptions, CONST RECT *lprc, LPCWSTR lpString, UINT cbString, CONST INT *lpDx), (hdc, nXStart, nYStart, fuOptions, lprc, lpString, cbString, lpDx)) HOOK_DEFINE(BOOL, RemoveFontResourceExW, (__in LPCWSTR name, __in DWORD fl, __reserved PVOID pdv), (name, fl, pdv)) //HOOK_DEFINE(BOOL, RemoveFontResourceW, (__in LPCWSTR lpFileName)) HOOK_DEFINE(HGDIOBJ, GetStockObject, (__in int i), (i)) HOOK_DEFINE(BOOL, BeginPath, (HDC hdc), (hdc)) HOOK_DEFINE(BOOL, EndPath, (HDC hdc), (hdc)) HOOK_DEFINE(BOOL, AbortPath, (HDC hdc), (hdc)); HOOK_DEFINE(DWORD, GetFontData, (_In_ HDC hdc, _In_ DWORD dwTable, _In_ DWORD dwOffset, _Out_writes_bytes_to_opt_(cjBuffer, return) PVOID pvBuffer, _In_ DWORD cjBuffer ), (hdc, dwTable, dwOffset, pvBuffer, cjBuffer)); HOOK_MANUALLY(HRESULT, BitmapRenderTarget_DrawGlyphRun, ( IDWriteBitmapRenderTarget* This, FLOAT baselineOriginX, FLOAT baselineOriginY, DWRITE_MEASURING_MODE measuringMode, DWRITE_GLYPH_RUN const* glyphRun, IDWriteRenderingParams* renderingParams, COLORREF textColor, RECT* blackBoxRect), (This, baselineOriginX, baselineOriginY, measuringMode, glyphRun, renderingParams, textColor, blackBoxRect)) /* HOOK_MANUALLY(void, SetTextAntialiasMode, ( ID2D1RenderTarget* self, D2D1_TEXT_ANTIALIAS_MODE textAntialiasMode)) HOOK_MANUALLY(void, SetTextRenderingParams, ( ID2D1RenderTarget* self, __in_opt IDWriteRenderingParams *textRenderingParams ))*/ HOOK_MANUALLY(HRESULT, DWriteCreateFactory, ( __in DWRITE_FACTORY_TYPE factoryType, __in REFIID iid, __out IUnknown **factory), (factoryType, iid, factory)) HOOK_MANUALLY(HRESULT, D2D1CreateDevice, ( IDXGIDevice* dxgiDevice, CONST D2D1_CREATION_PROPERTIES* creationProperties, ID2D1Device** d2dDevice), (dxgiDevice, creationProperties, d2dDevice)) HOOK_MANUALLY(HRESULT, D2D1CreateDeviceContext, ( IDXGISurface* dxgiSurface, CONST D2D1_CREATION_PROPERTIES* creationProperties, ID2D1DeviceContext** d2dDeviceContext), (dxgiSurface, creationProperties, d2dDeviceContext)) HOOK_MANUALLY(HRESULT, D2D1CreateFactory, ( D2D1_FACTORY_TYPE factoryType, REFIID riid, const D2D1_FACTORY_OPTIONS* pFactoryOptions, void** ppIFactory), (factoryType, riid, pFactoryOptions, ppIFactory)) HOOK_MANUALLY(HRESULT, GetGdiInterop, ( IDWriteFactory* This, IDWriteGdiInterop** gdiInterop ), (This, gdiInterop)) HOOK_MANUALLY(HRESULT, CreateGlyphRunAnalysis, ( IDWriteFactory* This, DWRITE_GLYPH_RUN const* glyphRun, FLOAT pixelsPerDip, DWRITE_MATRIX const* transform, DWRITE_RENDERING_MODE renderingMode, DWRITE_MEASURING_MODE measuringMode, FLOAT baselineOriginX, FLOAT baselineOriginY, IDWriteGlyphRunAnalysis** glyphRunAnalysis ), (This, glyphRun, pixelsPerDip, transform, renderingMode, measuringMode, baselineOriginX, baselineOriginY, glyphRunAnalysis)) HOOK_MANUALLY(HRESULT, CreateGlyphRunAnalysis2, ( IDWriteFactory2* This, DWRITE_GLYPH_RUN const* glyphRun, DWRITE_MATRIX const* transform, DWRITE_RENDERING_MODE renderingMode, DWRITE_MEASURING_MODE measuringMode, DWRITE_GRID_FIT_MODE gridFitMode, DWRITE_TEXT_ANTIALIAS_MODE antialiasMode, FLOAT baselineOriginX, FLOAT baselineOriginY, IDWriteGlyphRunAnalysis** glyphRunAnalysis ), (This, glyphRun, transform, renderingMode, measuringMode, gridFitMode, antialiasMode, baselineOriginX, baselineOriginY, glyphRunAnalysis)) HOOK_MANUALLY(HRESULT, CreateGlyphRunAnalysis3, ( IDWriteFactory3* This, DWRITE_GLYPH_RUN const* glyphRun, DWRITE_MATRIX const* transform, DWRITE_RENDERING_MODE1 renderingMode, DWRITE_MEASURING_MODE measuringMode, DWRITE_GRID_FIT_MODE gridFitMode, DWRITE_TEXT_ANTIALIAS_MODE antialiasMode, FLOAT baselineOriginX, FLOAT baselineOriginY, IDWriteGlyphRunAnalysis** glyphRunAnalysis ), (This, glyphRun, transform, renderingMode, measuringMode, gridFitMode, antialiasMode, baselineOriginX, baselineOriginY, glyphRunAnalysis)) HOOK_MANUALLY(HRESULT, GetAlphaBlendParams, ( IDWriteGlyphRunAnalysis* This, IDWriteRenderingParams* renderingParams, FLOAT* blendGamma, FLOAT* blendEnhancedContrast, FLOAT* blendClearTypeLevel ), (This, renderingParams, blendGamma, blendEnhancedContrast, blendClearTypeLevel)) HOOK_MANUALLY(HRESULT, CreateDeviceContext, ( ID2D1Device* This, D2D1_DEVICE_CONTEXT_OPTIONS options, ID2D1DeviceContext** deviceContext ), (This, options, deviceContext)) HOOK_MANUALLY(HRESULT, CreateDeviceContext2, ( ID2D1Device1* This, D2D1_DEVICE_CONTEXT_OPTIONS options, ID2D1DeviceContext1** deviceContext ), (This, options, deviceContext)) HOOK_MANUALLY(HRESULT, CreateDeviceContext3, ( ID2D1Device2* This, D2D1_DEVICE_CONTEXT_OPTIONS options, ID2D1DeviceContext2** deviceContext ), (This, options, deviceContext)) HOOK_MANUALLY(HRESULT, CreateDeviceContext4, ( ID2D1Device3* This, D2D1_DEVICE_CONTEXT_OPTIONS options, ID2D1DeviceContext3** deviceContext ), (This, options, deviceContext)) HOOK_MANUALLY(HRESULT, CreateDeviceContext5, ( ID2D1Device4* This, D2D1_DEVICE_CONTEXT_OPTIONS options, ID2D1DeviceContext4** deviceContext ), (This, options, deviceContext)) HOOK_MANUALLY(HRESULT, CreateDeviceContext6, ( ID2D1Device5* This, D2D1_DEVICE_CONTEXT_OPTIONS options, ID2D1DeviceContext5** deviceContext ), (This, options, deviceContext)) HOOK_MANUALLY(HRESULT, CreateDeviceContext7, ( ID2D1Device6* This, D2D1_DEVICE_CONTEXT_OPTIONS options, ID2D1DeviceContext6** deviceContext ), (This, options, deviceContext)) HOOK_MANUALLY(HRESULT, CreateTextFormat, ( IDWriteFactory* self, __in_z WCHAR const* fontFamilyName, __maybenull IDWriteFontCollection* fontCollection, DWRITE_FONT_WEIGHT fontWeight, DWRITE_FONT_STYLE fontStyle, DWRITE_FONT_STRETCH fontStretch, FLOAT fontSize, __in_z WCHAR const* localeName, __out IDWriteTextFormat** textFormat), (self, fontFamilyName, fontCollection, fontWeight, fontStyle, fontStretch, fontSize, localeName, textFormat)) HOOK_MANUALLY(HRESULT, CreateFontFace, ( IDWriteFont* self, __out IDWriteFontFace** fontFace ), (self, fontFace)) HOOK_MANUALLY(HRESULT, DWriteFontFaceReference_CreateFontFace, ( IDWriteFontFaceReference* self, __out IDWriteFontFace3** fontFace ), (self, fontFace)) HOOK_MANUALLY(HRESULT, DWriteFontFaceReference_CreateFontFaceWithSimulations, ( IDWriteFontFaceReference* self, DWRITE_FONT_SIMULATIONS fontFaceSimulationFlags, __out IDWriteFontFace3** fontFace ), (self, fontFaceSimulationFlags, fontFace)) HOOK_MANUALLY(HRESULT, CreateBitmapRenderTarget, ( IDWriteGdiInterop* This, HDC hdc, UINT32 width, UINT32 height, IDWriteBitmapRenderTarget** renderTarget ), (This, hdc, width, height, renderTarget)) HOOK_MANUALLY(HRESULT, CreateCompatibleRenderTarget, ( ID2D1RenderTarget* This, CONST D2D1_SIZE_F* desiredSize, CONST D2D1_SIZE_U* desiredPixelSize, CONST D2D1_PIXEL_FORMAT* desiredFormat, D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS options, ID2D1BitmapRenderTarget** bitmapRenderTarget ), (This, desiredSize, desiredPixelSize, desiredFormat, options, bitmapRenderTarget)) HOOK_MANUALLY(void, D2D1RenderTarget_SetTextAntialiasMode, ( ID2D1RenderTarget* This, D2D1_TEXT_ANTIALIAS_MODE textAntialiasMode), (This, textAntialiasMode)); HOOK_MANUALLY(void, D2D1DeviceContext_SetTextAntialiasMode, ( ID2D1DeviceContext* This, D2D1_TEXT_ANTIALIAS_MODE textAntialiasMode), (This, textAntialiasMode)); HOOK_MANUALLY(void, D2D1RenderTarget_SetTextRenderingParams, ( ID2D1RenderTarget* This, _In_opt_ IDWriteRenderingParams* textRenderingParams), (This, textRenderingParams)); HOOK_MANUALLY(void, D2D1DeviceContext_SetTextRenderingParams, ( ID2D1DeviceContext* This, _In_opt_ IDWriteRenderingParams* textRenderingParams), (This, textRenderingParams)); /* HOOK_MANUALLY(GpStatus, GdipDrawString, ( GpGraphics *graphics, GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font, GDIPCONST RectF *layoutRect, GDIPCONST GpStringFormat *stringFormat, GDIPCONST GpBrush *brush ))*/ HOOK_MANUALLY(HRESULT, CreateWicBitmapRenderTarget, ( ID2D1Factory* This, IWICBitmap* target, const D2D1_RENDER_TARGET_PROPERTIES* renderTargetProperties, ID2D1RenderTarget** renderTarget), (This, target, renderTargetProperties, renderTarget)); HOOK_MANUALLY(HRESULT, CreateHwndRenderTarget, ( ID2D1Factory* This, const D2D1_RENDER_TARGET_PROPERTIES* renderTargetProperties, const D2D1_HWND_RENDER_TARGET_PROPERTIES* hwndRenderTargetProperties, ID2D1HwndRenderTarget** hwndRenderTarget), (This, renderTargetProperties, hwndRenderTargetProperties, hwndRenderTarget)); HOOK_MANUALLY(HRESULT, CreateDxgiSurfaceRenderTarget, ( ID2D1Factory* This, IDXGISurface* dxgiSurface, const D2D1_RENDER_TARGET_PROPERTIES* renderTargetProperties, ID2D1RenderTarget** renderTarget), (This, dxgiSurface, renderTargetProperties, renderTarget)); HOOK_MANUALLY(HRESULT, CreateDCRenderTarget, ( ID2D1Factory* This, const D2D1_RENDER_TARGET_PROPERTIES* renderTargetProperties, ID2D1DCRenderTarget** dcRenderTarget), (This, renderTargetProperties, dcRenderTarget)); HOOK_MANUALLY(HRESULT, CreateDevice1, ( ID2D1Factory1* This, IDXGIDevice* dxgiDevice, ID2D1Device** d2dDevice), (This, dxgiDevice, d2dDevice)); HOOK_MANUALLY(HRESULT, CreateDevice2, ( ID2D1Factory2* This, IDXGIDevice* dxgiDevice, ID2D1Device1** d2dDevice1 ), (This, dxgiDevice, d2dDevice1)); HOOK_MANUALLY(HRESULT, CreateDevice3, ( ID2D1Factory3* This, IDXGIDevice* dxgiDevice, ID2D1Device2** d2dDevice2 ), (This, dxgiDevice, d2dDevice2)); HOOK_MANUALLY(HRESULT, CreateDevice4, ( ID2D1Factory4* This, IDXGIDevice* dxgiDevice, ID2D1Device3** d2dDevice3 ), (This, dxgiDevice, d2dDevice3)); HOOK_MANUALLY(HRESULT, CreateDevice5, ( ID2D1Factory5* This, IDXGIDevice* dxgiDevice, ID2D1Device4** d2dDevice4 ), (This, dxgiDevice, d2dDevice4)); HOOK_MANUALLY(HRESULT, CreateDevice6, ( ID2D1Factory6* This, IDXGIDevice* dxgiDevice, ID2D1Device5** d2dDevice5 ), (This, dxgiDevice, d2dDevice5)); HOOK_MANUALLY(HRESULT, CreateDevice7, ( ID2D1Factory7* This, IDXGIDevice* dxgiDevice, ID2D1Device6** d2dDevice6 ), (This, dxgiDevice, d2dDevice6)); HOOK_MANUALLY(BOOL, MySetProcessMitigationPolicy, ( _In_ PROCESS_MITIGATION_POLICY MitigationPolicy, _In_ PVOID lpBuffer, _In_ SIZE_T dwLength ), (MitigationPolicy, lpBuffer, dwLength)); HOOK_MANUALLY(void, D2D1RenderTarget_DrawGlyphRun1, ( ID2D1DeviceContext *This, D2D1_POINT_2F baselineOrigin, CONST DWRITE_GLYPH_RUN *glyphRun, CONST DWRITE_GLYPH_RUN_DESCRIPTION *glyphRunDescription, ID2D1Brush *foregroundBrush, DWRITE_MEASURING_MODE measuringMode), (This, baselineOrigin, glyphRun, glyphRunDescription, foregroundBrush, measuringMode)); HOOK_MANUALLY(void, D2D1RenderTarget1_DrawGlyphRun1, ( ID2D1DeviceContext *This, D2D1_POINT_2F baselineOrigin, CONST DWRITE_GLYPH_RUN *glyphRun, CONST DWRITE_GLYPH_RUN_DESCRIPTION *glyphRunDescription, ID2D1Brush *foregroundBrush, DWRITE_MEASURING_MODE measuringMode), (This, baselineOrigin, glyphRun, glyphRunDescription, foregroundBrush, measuringMode)); HOOK_MANUALLY(void, D2D1DeviceContext_DrawGlyphRun1, ( ID2D1DeviceContext *This, D2D1_POINT_2F baselineOrigin, CONST DWRITE_GLYPH_RUN *glyphRun, CONST DWRITE_GLYPH_RUN_DESCRIPTION *glyphRunDescription, ID2D1Brush *foregroundBrush, DWRITE_MEASURING_MODE measuringMode), (This, baselineOrigin, glyphRun, glyphRunDescription, foregroundBrush, measuringMode)); HOOK_MANUALLY(void, D2D1RenderTarget_DrawGlyphRun, ( ID2D1RenderTarget* This, D2D1_POINT_2F baselineOrigin, CONST DWRITE_GLYPH_RUN *glyphRun, ID2D1Brush *foregroundBrush, DWRITE_MEASURING_MODE measuringMode ), (This, baselineOrigin, glyphRun, foregroundBrush, measuringMode)); HOOK_MANUALLY(void, D2D1RenderTarget1_DrawGlyphRun, ( ID2D1RenderTarget* This, D2D1_POINT_2F baselineOrigin, CONST DWRITE_GLYPH_RUN *glyphRun, ID2D1Brush *foregroundBrush, DWRITE_MEASURING_MODE measuringMode ), (This, baselineOrigin, glyphRun, foregroundBrush, measuringMode)); HOOK_MANUALLY(void, D2D1DeviceContext_DrawGlyphRun, ( ID2D1DeviceContext* This, D2D1_POINT_2F baselineOrigin, CONST DWRITE_GLYPH_RUN *glyphRun, ID2D1Brush *foregroundBrush, DWRITE_MEASURING_MODE measuringMode ), (This, baselineOrigin, glyphRun, foregroundBrush, measuringMode)); HOOK_MANUALLY(void, D2D1RenderTarget_DrawText, ( ID2D1RenderTarget* This, CONST WCHAR *string, UINT32 stringLength, IDWriteTextFormat *textFormat, CONST D2D1_RECT_F *layoutRect, ID2D1Brush *defaultForegroundBrush, D2D1_DRAW_TEXT_OPTIONS options, DWRITE_MEASURING_MODE measuringMode), (This, string, stringLength, textFormat, layoutRect, defaultForegroundBrush, options, measuringMode)); HOOK_MANUALLY(void, D2D1DeviceContext_DrawText, ( ID2D1DeviceContext* This, CONST WCHAR *string, UINT32 stringLength, IDWriteTextFormat *textFormat, CONST D2D1_RECT_F *layoutRect, ID2D1Brush *defaultForegroundBrush, D2D1_DRAW_TEXT_OPTIONS options, DWRITE_MEASURING_MODE measuringMode), (This, string, stringLength, textFormat, layoutRect, defaultForegroundBrush, options, measuringMode)); HOOK_MANUALLY(void, D2D1RenderTarget_DrawTextLayout, ( ID2D1RenderTarget* This, D2D1_POINT_2F origin, IDWriteTextLayout *textLayout, ID2D1Brush *defaultForegroundBrush, D2D1_DRAW_TEXT_OPTIONS options ), (This, origin, textLayout, defaultForegroundBrush, options)); //EOF
16,744
C++
.h
356
41.994382
153
0.75334
snowie2000/mactype
9,859
437
273
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,173
gdiPlusFlat2.h
snowie2000_mactype/gdiPlusFlat2.h
#ifndef _GDIPLUSFLAT_H #define _GDIPLUSFLAT_H #include <Windows.h> #include "GdiPlusTypes2.h" #include <GdiPlusEnums.h> #include <GdiplusGpStubs.h> #include <GdiPlusPixelFormats.h> #define GDIPCONST const #define WINGDIPAPI __stdcall typedef Status GpStatus; typedef GpStatus (WINGDIPAPI* GdipDrawString)( GpGraphics *graphics, GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font, GDIPCONST RectF *layoutRect, GDIPCONST GpStringFormat *stringFormat, GDIPCONST GpBrush *brush );//绘制文字的函数 typedef GpStatus (WINGDIPAPI* GdipGetLogFontW)(GpFont * font, GpGraphics *graphics, LOGFONTW * logfontW);//从GPFont获取Logfont typedef GpStatus (WINGDIPAPI* GdipGetDC)(GpGraphics* graphics, HDC * hdc); //从GPGraphic获取HDC typedef GpStatus (WINGDIPAPI* GdipReleaseDC)(GpGraphics* graphics, HDC hdc); typedef GpStatus (WINGDIPAPI* GdipGetStringFormatAlign)(GDIPCONST GpStringFormat *format, StringAlignment *align); typedef GpStatus (WINGDIPAPI* GdipGetStringFormatTrimming)( GDIPCONST GpStringFormat *format, StringTrimming *trimming ); //获取字符串的缩略方式。当字符串长度超过矩形长度时,将使用设置的方式删除中间的部分文字。 //转换成GDI后应使用DrawText来模拟。 typedef GpStatus (WINGDIPAPI* GdipGetStringFormatHotkeyPrefix)(GDIPCONST GpStringFormat *format, INT *hotkeyPrefix); //获取&符号的显示方式,隐藏,显示下划线或者不处理&。由DrawText模拟。 typedef GpStatus (WINGDIPAPI* GdipGetBrushType)(GpBrush *brush, GpBrushType *type); typedef GpStatus (WINGDIPAPI* GdipGetSolidFillColor)(GpSolidFill *brush, ARGB *color); //获取单色Brush的颜色 extern GdipDrawString pfnGdipDrawString ; extern GdipGetBrushType pfnGdipGetBrushType ; extern GdipGetDC pfnGdipGetDC ; extern GdipGetLogFontW pfnGdipGetLogFontW ; extern GdipGetSolidFillColor pfnGdipGetSolidFillColor ; extern GdipGetStringFormatAlign pfnGdipGetStringFormatAlign ; extern GdipGetStringFormatHotkeyPrefix pfnGdipGetStringFormatHotkeyPrefix ; extern GdipGetStringFormatTrimming pfnGdipGetStringFormatTrimming ; extern GdipReleaseDC pfnGdipReleaseDC ; bool InitGdiplusFuncs(); #endif
2,325
C++
.h
53
37
93
0.789781
snowie2000/mactype
9,859
437
273
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,174
ftref.h
snowie2000_mactype/ftref.h
#include <freetype/ftglyph.h> #include <Windows.h> #ifdef __cplusplus extern "C"{ #endif typedef struct { FT_Glyph ft_glyph; int refcount; }FT_Referenced_GlyphRec, *FT_Referenced_Glyph; typedef struct { FT_BitmapGlyph ft_glyph; int refcount; }FT_Referenced_BitmapGlyphRec, *FT_Referenced_BitmapGlyph; FT_Error FT_Glyph_Ref_Copy( FT_Referenced_Glyph source, FT_Referenced_Glyph *target ); void FT_Done_Ref_Glyph( FT_Referenced_Glyph *glyph ); void FT_Glyph_To_Ref_Glyph( FT_Glyph source, FT_Referenced_Glyph *target); FT_Referenced_Glyph New_FT_Ref_Glyph(); #ifdef __cplusplus } #endif
600
C++
.h
22
25.681818
87
0.776614
snowie2000/mactype
9,859
437
273
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,175
ft2build.h
snowie2000_mactype/ft2build.h
/***************************************************************************/ /* */ /* ft2build.h */ /* */ /* FreeType 2 build and setup macros. */ /* (Generic version) */ /* */ /* Copyright 1996-2001, 2006 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ /* modified, and distributed under the terms of the FreeType project */ /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ /* this file you indicate that you have read the license and */ /* understand and accept it fully. */ /* */ /***************************************************************************/ /*************************************************************************/ /* */ /* This file corresponds to the default `ft2build.h' file for */ /* FreeType 2. It uses the `freetype' include root. */ /* */ /* Note that specific platforms might use a different configuration. */ /* See builds/unix/ft2unix.h for an example. */ /* */ /*************************************************************************/ #ifndef __FT2_BUILD_GENERIC_H__ #define __FT2_BUILD_GENERIC_H__ #include <config/ftheader.h> #endif /* __FT2_BUILD_GENERIC_H__ */ /* END */
2,176
C++
.h
31
68.354839
77
0.284043
snowie2000/mactype
9,859
437
273
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
true
true
false
false
false
false
false
false
14,176
VersionHelper.h
snowie2000_mactype/VersionHelper.h
#pragma once #include <xstring> #include <windows.h> #include <algorithm> #include <cctype> using namespace std; class CVersionHelper { public: CVersionHelper(); virtual ~CVersionHelper(); public: wstring GetFileVersionX(); wstring GetProductVersionX(); wstring GetVersionInfo(HMODULE hLib, wstring csEntry); wstring FormatVersion(wstring cs); private: wstring m_csFileVersion; wstring m_csProductVersion; }; // cited: https://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring // trim from start (in place) static inline void ltrim(std::wstring &s) { s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) { return !std::isspace(ch); })); } // trim from end (in place) static inline void rtrim(std::wstring &s) { s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) { return !std::isspace(ch); }).base(), s.end()); }
909
C++
.h
33
24.69697
90
0.706837
snowie2000/mactype
9,859
437
273
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,178
hash_list.h
snowie2000_mactype/hash_list.h
//#include "stdint.h" #include "malloc.h" #include "string.h" #include "windows.h" #include <map> #include <string> typedef std::map<std::wstring, LPTSTR> strmap; class CHashedStringList { public: void Add(TCHAR * String, TCHAR * Value); void Delete(TCHAR * String); TCHAR * Find(TCHAR * String); CHashedStringList() : m_bCaseSense(false){} CHashedStringList(BOOL bCaseSensative) : m_bCaseSense(bCaseSensative){} ~CHashedStringList(){ strmap::iterator it = stringmap.begin(); while (it != stringmap.end()) { free(it->second); ++it; } } protected: private: strmap stringmap; BOOL m_bCaseSense; };
619
C++
.h
27
21.074074
72
0.730508
snowie2000/mactype
9,859
437
273
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,186
optimize.h
snowie2000_mactype/optimize/optimize.h
#include "memcpy_amd.h" #pragma comment (lib, "optimize/release/mem_amd.lib") #undef ZeroMemory #undef memzero #undef memset #undef memcpy #define ZeroMemory memzero_optimized #define memzero memzero_optimized #define memset memset_optimized #define memcpy memcpy_optimized //#ifndef _DEBUG //#endif
303
C++
.h
12
24
53
0.822917
snowie2000/mactype
9,859
437
273
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,187
memcpy_amd.h
snowie2000_mactype/optimize/memcpy_amd.h
/****************************************************************************** Copyright (c) 2001 Advanced Micro Devices, Inc. LIMITATION OF LIABILITY: THE MATERIALS ARE PROVIDED *AS IS* WITHOUT ANY EXPRESS OR IMPLIED WARRANTY OF ANY KIND INCLUDING WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT OF THIRD-PARTY INTELLECTUAL PROPERTY, OR FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT SHALL AMD OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, LOSS OF INFORMATION) ARISING OUT OF THE USE OF OR INABILITY TO USE THE MATERIALS, EVEN IF AMD HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. BECAUSE SOME JURISDICTIONS PROHIBIT THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, THE ABOVE LIMITATION MAY NOT APPLY TO YOU. AMD does not assume any responsibility for any errors which may appear in the Materials nor any responsibility to support or update the Materials. AMD retains the right to make changes to its test specifications at any time, without notice. NO SUPPORT OBLIGATION: AMD is not obligated to furnish, support, or make any further information, software, technical information, know-how, or show-how available to you. So that all may benefit from your experience, please report any problems or suggestions about this software to 3dsdk.support@amd.com AMD Developer Technologies, M/S 585 Advanced Micro Devices, Inc. 5900 E. Ben White Blvd. Austin, TX 78741 3dsdk.support@amd.com ******************************************************************************/ #pragma once #include <stddef.h> void* _stdcall memcpy_optimized(void *dest, const void *src, size_t n); void* _stdcall memset_optimized(void *dest, int c, size_t n); void _stdcall memzero_optimized(void *dest, size_t n); unsigned long get_cpu_type();
1,888
C++
.h
32
56.9375
82
0.73402
snowie2000/mactype
9,859
437
273
GPL-3.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,197
unittest_curve_encoding.cpp
zeromq_libzmq/unittests/unittest_curve_encoding.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include "../tests/testutil_unity.hpp" // TODO: remove this ugly hack #ifdef close #undef close #endif #include <curve_mechanism_base.hpp> #include <msg.hpp> #include <random.hpp> #include <unity.h> #include <vector> void setUp () { } void tearDown () { } void test_roundtrip (zmq::msg_t *msg_) { #ifdef ZMQ_HAVE_CURVE const std::vector<uint8_t> original (static_cast<uint8_t *> (msg_->data ()), static_cast<uint8_t *> (msg_->data ()) + msg_->size ()); zmq::curve_encoding_t encoding_client ("CurveZMQMESSAGEC", "CurveZMQMESSAGES", false); zmq::curve_encoding_t encoding_server ("CurveZMQMESSAGES", "CurveZMQMESSAGEC", false); uint8_t client_public[32]; uint8_t client_secret[32]; TEST_ASSERT_SUCCESS_ERRNO ( crypto_box_keypair (client_public, client_secret)); uint8_t server_public[32]; uint8_t server_secret[32]; TEST_ASSERT_SUCCESS_ERRNO ( crypto_box_keypair (server_public, server_secret)); TEST_ASSERT_SUCCESS_ERRNO ( crypto_box_beforenm (encoding_client.get_writable_precom_buffer (), server_public, client_secret)); TEST_ASSERT_SUCCESS_ERRNO ( crypto_box_beforenm (encoding_server.get_writable_precom_buffer (), client_public, server_secret)); TEST_ASSERT_SUCCESS_ERRNO (encoding_client.encode (msg_)); // TODO: This is hacky... encoding_server.set_peer_nonce (0); int error_event_code; TEST_ASSERT_SUCCESS_ERRNO ( encoding_server.decode (msg_, &error_event_code)); TEST_ASSERT_EQUAL_INT (original.size (), msg_->size ()); if (!original.empty ()) { TEST_ASSERT_EQUAL_UINT8_ARRAY (&original[0], msg_->data (), original.size ()); } #else LIBZMQ_UNUSED (msg_); #endif } void test_roundtrip_empty () { #ifndef ZMQ_HAVE_CURVE TEST_IGNORE_MESSAGE ("CURVE support is disabled"); #endif zmq::msg_t msg; msg.init (); test_roundtrip (&msg); msg.close (); } void test_roundtrip_small () { #ifndef ZMQ_HAVE_CURVE TEST_IGNORE_MESSAGE ("CURVE support is disabled"); #endif zmq::msg_t msg; msg.init_size (32); memcpy (msg.data (), "0123456789ABCDEF0123456789ABCDEF", 32); test_roundtrip (&msg); msg.close (); } void test_roundtrip_large () { #ifndef ZMQ_HAVE_CURVE TEST_IGNORE_MESSAGE ("CURVE support is disabled"); #endif zmq::msg_t msg; msg.init_size (2048); for (size_t pos = 0; pos < 2048; pos += 32) { memcpy (static_cast<char *> (msg.data ()) + pos, "0123456789ABCDEF0123456789ABCDEF", 32); } test_roundtrip (&msg); msg.close (); } void test_roundtrip_empty_more () { #ifndef ZMQ_HAVE_CURVE TEST_IGNORE_MESSAGE ("CURVE support is disabled"); #endif zmq::msg_t msg; msg.init (); msg.set_flags (zmq::msg_t::more); test_roundtrip (&msg); TEST_ASSERT_TRUE (msg.flags () & zmq::msg_t::more); msg.close (); } int main () { setup_test_environment (); zmq::random_open (); UNITY_BEGIN (); RUN_TEST (test_roundtrip_empty); RUN_TEST (test_roundtrip_small); RUN_TEST (test_roundtrip_large); RUN_TEST (test_roundtrip_empty_more); zmq::random_close (); return UNITY_END (); }
3,474
C++
.cpp
115
24.217391
80
0.616957
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
true
false
14,204
test_stream_timeout.cpp
zeromq_libzmq/tests/test_stream_timeout.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include "testutil.hpp" #include "testutil_monitoring.hpp" #include "testutil_unity.hpp" #include <stdlib.h> #include <string.h> SETUP_TEARDOWN_TESTCONTEXT static void test_stream_handshake_timeout_accept () { char my_endpoint[MAX_SOCKET_STRING]; // We use this socket in raw mode, to make a connection and send nothing void *stream = test_context_socket (ZMQ_STREAM); int zero = 0; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (stream, ZMQ_LINGER, &zero, sizeof (zero))); // We'll be using this socket to test TCP stream handshake timeout void *dealer = test_context_socket (ZMQ_DEALER); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (dealer, ZMQ_LINGER, &zero, sizeof (zero))); int val, tenth = 100; size_t vsize = sizeof (val); // check for the expected default handshake timeout value - 30 sec TEST_ASSERT_SUCCESS_ERRNO ( zmq_getsockopt (dealer, ZMQ_HANDSHAKE_IVL, &val, &vsize)); TEST_ASSERT_EQUAL (sizeof (val), vsize); TEST_ASSERT_EQUAL_INT (30000, val); // make handshake timeout faster - 1/10 sec TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (dealer, ZMQ_HANDSHAKE_IVL, &tenth, sizeof (tenth))); vsize = sizeof (val); // make sure zmq_setsockopt changed the value TEST_ASSERT_SUCCESS_ERRNO ( zmq_getsockopt (dealer, ZMQ_HANDSHAKE_IVL, &val, &vsize)); TEST_ASSERT_EQUAL (sizeof (val), vsize); TEST_ASSERT_EQUAL_INT (tenth, val); // Create and connect a socket for collecting monitor events on dealer void *dealer_mon = test_context_socket (ZMQ_PAIR); TEST_ASSERT_SUCCESS_ERRNO (zmq_socket_monitor ( dealer, "inproc://monitor-dealer", ZMQ_EVENT_CONNECTED | ZMQ_EVENT_DISCONNECTED | ZMQ_EVENT_ACCEPTED)); // Connect to the inproc endpoint so we'll get events TEST_ASSERT_SUCCESS_ERRNO ( zmq_connect (dealer_mon, "inproc://monitor-dealer")); // bind dealer socket to accept connection from non-sending stream socket bind_loopback_ipv4 (dealer, my_endpoint, sizeof my_endpoint); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (stream, my_endpoint)); // we should get ZMQ_EVENT_ACCEPTED and then ZMQ_EVENT_DISCONNECTED int event = get_monitor_event (dealer_mon, NULL, NULL); TEST_ASSERT_EQUAL_INT (ZMQ_EVENT_ACCEPTED, event); event = get_monitor_event (dealer_mon, NULL, NULL); TEST_ASSERT_EQUAL_INT (ZMQ_EVENT_DISCONNECTED, event); test_context_socket_close (dealer); test_context_socket_close (dealer_mon); test_context_socket_close (stream); } static void test_stream_handshake_timeout_connect () { char my_endpoint[MAX_SOCKET_STRING]; // We use this socket in raw mode, to accept a connection and send nothing void *stream = test_context_socket (ZMQ_STREAM); int zero = 0; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (stream, ZMQ_LINGER, &zero, sizeof (zero))); bind_loopback_ipv4 (stream, my_endpoint, sizeof my_endpoint); // We'll be using this socket to test TCP stream handshake timeout void *dealer = test_context_socket (ZMQ_DEALER); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (dealer, ZMQ_LINGER, &zero, sizeof (zero))); int val, tenth = 100; size_t vsize = sizeof (val); // check for the expected default handshake timeout value - 30 sec TEST_ASSERT_SUCCESS_ERRNO ( zmq_getsockopt (dealer, ZMQ_HANDSHAKE_IVL, &val, &vsize)); TEST_ASSERT_EQUAL (sizeof (val), vsize); TEST_ASSERT_EQUAL_INT (30000, val); // make handshake timeout faster - 1/10 sec TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (dealer, ZMQ_HANDSHAKE_IVL, &tenth, sizeof (tenth))); vsize = sizeof (val); // make sure zmq_setsockopt changed the value TEST_ASSERT_SUCCESS_ERRNO ( zmq_getsockopt (dealer, ZMQ_HANDSHAKE_IVL, &val, &vsize)); TEST_ASSERT_EQUAL (sizeof (val), vsize); TEST_ASSERT_EQUAL_INT (tenth, val); // Create and connect a socket for collecting monitor events on dealer void *dealer_mon = test_context_socket (ZMQ_PAIR); TEST_ASSERT_SUCCESS_ERRNO (zmq_socket_monitor ( dealer, "inproc://monitor-dealer", ZMQ_EVENT_CONNECTED | ZMQ_EVENT_DISCONNECTED | ZMQ_EVENT_ACCEPTED)); // Connect to the inproc endpoint so we'll get events TEST_ASSERT_SUCCESS_ERRNO ( zmq_connect (dealer_mon, "inproc://monitor-dealer")); // connect dealer socket to non-sending stream socket TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (dealer, my_endpoint)); // we should get ZMQ_EVENT_CONNECTED and then ZMQ_EVENT_DISCONNECTED int event = get_monitor_event (dealer_mon, NULL, NULL); TEST_ASSERT_EQUAL_INT (ZMQ_EVENT_CONNECTED, event); event = get_monitor_event (dealer_mon, NULL, NULL); TEST_ASSERT_EQUAL_INT (ZMQ_EVENT_DISCONNECTED, event); test_context_socket_close (dealer); test_context_socket_close (dealer_mon); test_context_socket_close (stream); } int main () { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_stream_handshake_timeout_accept); RUN_TEST (test_stream_handshake_timeout_connect); return UNITY_END (); }
5,166
C++
.cpp
111
41.567568
79
0.701353
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
true
false
true
false
14,205
test_busy_poll.cpp
zeromq_libzmq/tests/test_busy_poll.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include "testutil.hpp" #include "testutil_unity.hpp" SETUP_TEARDOWN_TESTCONTEXT void test_busy_poll () { // Create a socket void *socket = test_context_socket (ZMQ_DEALER); // set socket ZMQ_BUSY_POLL options int busy_poll = 1; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (socket, ZMQ_BUSY_POLL, &busy_poll, sizeof (int))); // bind socket TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (socket, "tcp://127.0.0.1:*")); // Clean up. test_context_socket_close (socket); } int main () { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_busy_poll); return UNITY_END (); }
673
C++
.cpp
24
24.333333
72
0.658879
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
true
false
true
false
14,209
test_connect_fuzzer.cpp
zeromq_libzmq/tests/test_connect_fuzzer.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #ifdef ZMQ_USE_FUZZING_ENGINE #include <fuzzer/FuzzedDataProvider.h> #endif #include <string> #include "testutil.hpp" #include "testutil_unity.hpp" // Test that zmq_connect can handle malformed strings extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) { setup_test_context (); std::string my_endpoint (reinterpret_cast<const char *> (data), size); void *socket = test_context_socket (ZMQ_PUB); zmq_connect (socket, my_endpoint.c_str ()); test_context_socket_close_zero_linger (socket); teardown_test_context (); return 0; } #ifndef ZMQ_USE_FUZZING_ENGINE void test_connect_fuzzer () { uint8_t **data; size_t *len, num_cases = 0; if (fuzzer_corpus_encode ( "tests/libzmq-fuzz-corpora/test_connect_fuzzer_seed_corpus", &data, &len, &num_cases) != 0) exit (77); while (num_cases-- > 0) { TEST_ASSERT_SUCCESS_ERRNO ( LLVMFuzzerTestOneInput (data[num_cases], len[num_cases])); free (data[num_cases]); } free (data); free (len); } int main (int argc, char **argv) { LIBZMQ_UNUSED (argc); LIBZMQ_UNUSED (argv); setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_connect_fuzzer); return UNITY_END (); } #endif
1,326
C++
.cpp
46
24.456522
77
0.660616
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
true
false
14,212
test_pair_ipc.cpp
zeromq_libzmq/tests/test_pair_ipc.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include "testutil.hpp" #include "testutil_unity.hpp" #include <string> SETUP_TEARDOWN_TESTCONTEXT void test_roundtrip () { char my_endpoint[256]; void *sb = test_context_socket (ZMQ_PAIR); bind_loopback_ipc (sb, my_endpoint, sizeof my_endpoint); void *sc = test_context_socket (ZMQ_PAIR); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint)); bounce (sb, sc); test_context_socket_close (sc); test_context_socket_close (sb); } static const char prefix[] = "ipc://"; void test_endpoint_too_long () { std::string endpoint_too_long; endpoint_too_long.append (prefix); for (size_t i = 0; i < 108; ++i) { endpoint_too_long.append ("a"); } void *sb = test_context_socket (ZMQ_PAIR); // TODO ENAMETOOLONG is not listed in the errors returned by zmq_bind, // should this be EINVAL? TEST_ASSERT_FAILURE_ERRNO (ENAMETOOLONG, zmq_bind (sb, endpoint_too_long.data ())); test_context_socket_close (sb); } int main (void) { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_roundtrip); RUN_TEST (test_endpoint_too_long); return UNITY_END (); }
1,224
C++
.cpp
39
26.74359
74
0.65641
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
true
false
true
false
14,216
test_security_gssapi.cpp
zeromq_libzmq/tests/test_security_gssapi.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include "testutil.hpp" #include "testutil_monitoring.hpp" #include "testutil_unity.hpp" #include <stdlib.h> #include <string.h> // This test requires a KRB5 environment with the following // service principal (substitute your host.domain and REALM): // // zmqtest2/host.domain@REALM (host.domain should be host running test) // // Export keys for this principal to a keytab file and set the environment // variables KRB5_KTNAME and KRB5_CLIENT_KTNAME to FILE:/path/to/your/keytab. // The test will use it both for client and server roles. // // The test is derived in large part from test_security_curve.cpp const char *name = "zmqtest2"; static volatile int zap_deny_all = 0; // -------------------------------------------------------------------------- // This methods receives and validates ZAP requests (allowing or denying // each client connection). // N.B. on failure, each crypto type in keytab will be tried static void zap_handler (void *handler_) { // Process ZAP requests forever while (true) { char *version = s_recv (handler_); if (!version) break; // Terminating char *sequence = s_recv (handler_); char *domain = s_recv (handler_); char *address = s_recv (handler_); char *routing_id = s_recv (handler_); char *mechanism = s_recv (handler_); char *principal = s_recv (handler_); TEST_ASSERT_EQUAL_STRING ("1.0", version); TEST_ASSERT_EQUAL_STRING ("GSSAPI", mechanism); send_string_expect_success (handler_, version, ZMQ_SNDMORE); send_string_expect_success (handler_, sequence, ZMQ_SNDMORE); if (!zap_deny_all) { send_string_expect_success (handler_, "200", ZMQ_SNDMORE); send_string_expect_success (handler_, "OK", ZMQ_SNDMORE); send_string_expect_success (handler_, "anonymous", ZMQ_SNDMORE); send_string_expect_success (handler_, "", 0); //fprintf (stderr, "ALLOW %s\n", principal); } else { send_string_expect_success (handler_, "400", ZMQ_SNDMORE); send_string_expect_success (handler_, "Denied", ZMQ_SNDMORE); send_string_expect_success (handler_, "", ZMQ_SNDMORE); send_string_expect_success (handler_, "", 0); //fprintf (stderr, "DENY %s\n", principal); } free (version); free (sequence); free (domain); free (address); free (routing_id); free (mechanism); free (principal); } zmq_close (handler_); } static char my_endpoint[MAX_SOCKET_STRING]; static void *zap_thread; static void *server; static void *server_mon; void check_krb_available () { if (!getenv ("KRB5_KTNAME") || !getenv ("KRB5_CLIENT_KTNAME")) { TEST_IGNORE_MESSAGE ("KRB5 environment unavailable, skipping test"); } } void setUp () { setup_test_context (); zap_thread = 0; server = NULL; server_mon = NULL; check_krb_available (); // Spawn ZAP handler // We create and bind ZAP socket in main thread to avoid case // where child thread does not start up fast enough. void *handler = zmq_socket (get_test_context (), ZMQ_REP); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (handler, "inproc://zeromq.zap.01")); zap_thread = zmq_threadstart (&zap_handler, handler); // Server socket will accept connections server = test_context_socket (ZMQ_DEALER); int as_server = 1; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (server, ZMQ_GSSAPI_SERVER, &as_server, sizeof (int))); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (server, ZMQ_GSSAPI_PRINCIPAL, name, strlen (name) + 1)); int name_type = ZMQ_GSSAPI_NT_HOSTBASED; TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt ( server, ZMQ_GSSAPI_PRINCIPAL_NAMETYPE, &name_type, sizeof (name_type))); bind_loopback_ipv4 (server, my_endpoint, sizeof my_endpoint); // Monitor handshake events on the server TEST_ASSERT_SUCCESS_ERRNO (zmq_socket_monitor ( server, "inproc://monitor-server", ZMQ_EVENT_HANDSHAKE_SUCCEEDED | ZMQ_EVENT_HANDSHAKE_FAILED_AUTH | ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL)); // Create socket for collecting monitor events server_mon = test_context_socket (ZMQ_PAIR); // Connect it to the inproc endpoints so they'll get events TEST_ASSERT_SUCCESS_ERRNO ( zmq_connect (server_mon, "inproc://monitor-server")); } void tearDown () { // Shutdown if (server_mon) test_context_socket_close_zero_linger (server_mon); if (server) test_context_socket_close (server); teardown_test_context (); // Wait until ZAP handler terminates if (zap_thread) zmq_threadclose (zap_thread); } void test_valid_creds () { void *client = test_context_socket (ZMQ_DEALER); TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt ( client, ZMQ_GSSAPI_SERVICE_PRINCIPAL, name, strlen (name) + 1)); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (client, ZMQ_GSSAPI_PRINCIPAL, name, strlen (name) + 1)); int name_type = ZMQ_GSSAPI_NT_HOSTBASED; TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt ( client, ZMQ_GSSAPI_PRINCIPAL_NAMETYPE, &name_type, sizeof (name_type))); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client, my_endpoint)); bounce (server, client); test_context_socket_close (client); int event = get_monitor_event (server_mon, NULL, NULL); TEST_ASSERT_EQUAL_INT (ZMQ_EVENT_HANDSHAKE_SUCCEEDED, event); } // Check security with valid but unauthorized credentials // Note: ZAP may see multiple requests - after a failure, client will // fall back to other crypto types for principal, if available. void test_unauth_creds () { void *client = test_context_socket (ZMQ_DEALER); TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt ( client, ZMQ_GSSAPI_SERVICE_PRINCIPAL, name, strlen (name) + 1)); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (client, ZMQ_GSSAPI_PRINCIPAL, name, strlen (name) + 1)); int name_type = ZMQ_GSSAPI_NT_HOSTBASED; TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt ( client, ZMQ_GSSAPI_PRINCIPAL_NAMETYPE, &name_type, sizeof (name_type))); zap_deny_all = 1; TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client, my_endpoint)); expect_bounce_fail (server, client); test_context_socket_close_zero_linger (client); int event = get_monitor_event (server_mon, NULL, NULL); TEST_ASSERT_EQUAL_INT (ZMQ_EVENT_HANDSHAKE_FAILED_AUTH, event); } // Check GSSAPI security with NULL client credentials // This must be caught by the gssapi_server class, not passed to ZAP void test_null_creds () { void *client = test_context_socket (ZMQ_DEALER); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client, my_endpoint)); expect_bounce_fail (server, client); test_context_socket_close_zero_linger (client); int error = 0; int event = get_monitor_event (server_mon, &error, NULL); TEST_ASSERT_EQUAL_INT (ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, event); TEST_ASSERT_EQUAL_INT (ZMQ_PROTOCOL_ERROR_ZMTP_MECHANISM_MISMATCH, error); } // Check GSSAPI security with PLAIN client credentials // This must be caught by the curve_server class, not passed to ZAP void test_plain_creds () { void *client = test_context_socket (ZMQ_DEALER); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (client, ZMQ_PLAIN_USERNAME, "admin", 5)); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (client, ZMQ_PLAIN_PASSWORD, "password", 8)); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client, my_endpoint)); expect_bounce_fail (server, client); test_context_socket_close_zero_linger (client); } // Unauthenticated messages from a vanilla socket shouldn't be received void test_vanilla_socket () { fd_t s = connect_socket (my_endpoint); // send anonymous ZMTP/1.0 greeting send (s, "\x01\x00", 2, 0); // send sneaky message that shouldn't be received send (s, "\x08\x00sneaky\0", 9, 0); int timeout = 250; zmq_setsockopt (server, ZMQ_RCVTIMEO, &timeout, sizeof (timeout)); char *buf = s_recv (server); if (buf != NULL) { printf ("Received unauthenticated message: %s\n", buf); TEST_ASSERT_NULL (buf); } close (s); } int main (void) { // Avoid entanglements with user's credential cache setenv ("KRB5CCNAME", "MEMORY", 1); setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_valid_creds); RUN_TEST (test_null_creds); RUN_TEST (test_plain_creds); RUN_TEST (test_vanilla_socket); RUN_TEST (test_unauth_creds); return UNITY_END (); }
8,662
C++
.cpp
211
35.995261
78
0.670469
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
true
false
14,221
test_peer.cpp
zeromq_libzmq/tests/test_peer.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include "testutil.hpp" #include "testutil_unity.hpp" SETUP_TEARDOWN_TESTCONTEXT void test_peer () { size_t len = MAX_SOCKET_STRING; char my_endpoint[MAX_SOCKET_STRING]; void *peer1 = test_context_socket (ZMQ_PEER); bind_loopback (peer1, false, my_endpoint, len); void *peer2 = test_context_socket (ZMQ_PEER); uint32_t peer1_routing_id = zmq_connect_peer (peer2, my_endpoint); TEST_ASSERT_NOT_EQUAL (0, peer1_routing_id); { zmq_msg_t msg; TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init_size (&msg, 1)); char *data = static_cast<char *> (zmq_msg_data (&msg)); data[0] = 1; TEST_ASSERT_SUCCESS_ERRNO ( zmq_msg_set_routing_id (&msg, peer1_routing_id)); int rc = zmq_msg_send (&msg, peer2, 0); TEST_ASSERT_EQUAL_INT (1, rc); } uint32_t peer2_routing_id; { zmq_msg_t msg; TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg)); int rc = TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, peer1, 0)); TEST_ASSERT_EQUAL_INT (1, rc); peer2_routing_id = zmq_msg_routing_id (&msg); TEST_ASSERT_NOT_EQUAL (0, peer2_routing_id); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg)); } { zmq_msg_t msg; TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init_size (&msg, 1)); char *data = static_cast<char *> (zmq_msg_data (&msg)); data[0] = 2; TEST_ASSERT_SUCCESS_ERRNO ( zmq_msg_set_routing_id (&msg, peer2_routing_id)); int rc = zmq_msg_send (&msg, peer1, 0); TEST_ASSERT_EQUAL_INT (1, rc); } { zmq_msg_t msg; TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg)); int rc = zmq_msg_recv (&msg, peer2, 0); TEST_ASSERT_EQUAL_INT (1, rc); uint32_t routing_id = zmq_msg_routing_id (&msg); TEST_ASSERT_EQUAL_UINT32 (peer1_routing_id, routing_id); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg)); } test_context_socket_close (peer1); test_context_socket_close (peer2); } int main (void) { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_peer); return UNITY_END (); }
2,213
C++
.cpp
62
28.951613
75
0.605078
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
true
false
true
false
14,222
test_mock_pub_sub.cpp
zeromq_libzmq/tests/test_mock_pub_sub.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include "testutil.hpp" #include "testutil_unity.hpp" #include <stdlib.h> #include <string.h> SETUP_TEARDOWN_TESTCONTEXT // Read one event off the monitor socket; return value and address // by reference, if not null, and event number by value. Returns -1 // in case of error. static int get_monitor_event (void *monitor_) { for (int i = 0; i < 2; i++) { // First frame in message contains event number and value zmq_msg_t msg; TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg)); if (zmq_msg_recv (&msg, monitor_, ZMQ_DONTWAIT) == -1) { msleep (SETTLE_TIME); continue; // Interrupted, presumably } TEST_ASSERT_TRUE (zmq_msg_more (&msg)); uint8_t *data = static_cast<uint8_t *> (zmq_msg_data (&msg)); uint16_t event = *reinterpret_cast<uint16_t *> (data); // Second frame in message contains event address TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg)); if (zmq_msg_recv (&msg, monitor_, 0) == -1) { return -1; // Interrupted, presumably } TEST_ASSERT_FALSE (zmq_msg_more (&msg)); return event; } return -1; } static void recv_with_retry (fd_t fd_, char *buffer_, int bytes_) { int received = 0; while (true) { int rc = TEST_ASSERT_SUCCESS_RAW_ERRNO ( recv (fd_, buffer_ + received, bytes_ - received, 0)); TEST_ASSERT_GREATER_THAN_INT (0, rc); received += rc; TEST_ASSERT_LESS_OR_EQUAL_INT (bytes_, received); if (received == bytes_) break; } } static void mock_handshake (fd_t fd_, bool sub_command, bool mock_pub) { char buffer[128]; memset (buffer, 0, sizeof (buffer)); memcpy (buffer, zmtp_greeting_null, sizeof (zmtp_greeting_null)); // Mock ZMTP 3.1 which uses commands if (sub_command) { buffer[11] = 1; } int rc = TEST_ASSERT_SUCCESS_RAW_ERRNO (send (fd_, buffer, 64, 0)); TEST_ASSERT_EQUAL_INT (64, rc); recv_with_retry (fd_, buffer, 64); if (!mock_pub) { rc = TEST_ASSERT_SUCCESS_RAW_ERRNO (send ( fd_, (const char *) zmtp_ready_sub, sizeof (zmtp_ready_sub), 0)); TEST_ASSERT_EQUAL_INT (sizeof (zmtp_ready_sub), rc); } else { rc = TEST_ASSERT_SUCCESS_RAW_ERRNO (send ( fd_, (const char *) zmtp_ready_xpub, sizeof (zmtp_ready_xpub), 0)); TEST_ASSERT_EQUAL_INT (sizeof (zmtp_ready_xpub), rc); } // greeting - XPUB has one extra byte memset (buffer, 0, sizeof (buffer)); recv_with_retry (fd_, buffer, mock_pub ? sizeof (zmtp_ready_sub) : sizeof (zmtp_ready_xpub)); } static void prep_server_socket (void **server_out_, void **mon_out_, char *endpoint_, size_t ep_length_, int socket_type) { // We'll be using this socket in raw mode void *server = test_context_socket (socket_type); int value = 0; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (server, ZMQ_LINGER, &value, sizeof (value))); bind_loopback_ipv4 (server, endpoint_, ep_length_); // Create and connect a socket for collecting monitor events on xpub void *server_mon = test_context_socket (ZMQ_PAIR); TEST_ASSERT_SUCCESS_ERRNO (zmq_socket_monitor ( server, "inproc://monitor-dealer", ZMQ_EVENT_CONNECTED | ZMQ_EVENT_DISCONNECTED | ZMQ_EVENT_ACCEPTED)); // Connect to the inproc endpoint so we'll get events TEST_ASSERT_SUCCESS_ERRNO ( zmq_connect (server_mon, "inproc://monitor-dealer")); *server_out_ = server; *mon_out_ = server_mon; } static void test_mock_pub_sub (bool sub_command_, bool mock_pub_) { int rc; char my_endpoint[MAX_SOCKET_STRING]; void *server, *server_mon; prep_server_socket (&server, &server_mon, my_endpoint, MAX_SOCKET_STRING, mock_pub_ ? ZMQ_SUB : ZMQ_XPUB); fd_t s = connect_socket (my_endpoint); // Mock a ZMTP 3 client so we can forcibly try sub commands mock_handshake (s, sub_command_, mock_pub_); // By now everything should report as connected rc = get_monitor_event (server_mon); TEST_ASSERT_EQUAL_INT (ZMQ_EVENT_ACCEPTED, rc); char buffer[32]; memset (buffer, 0, sizeof (buffer)); if (mock_pub_) { rc = zmq_setsockopt (server, ZMQ_SUBSCRIBE, "A", 1); TEST_ASSERT_EQUAL_INT (0, rc); // SUB binds, let its state machine run // Because zeromq attach the pipe after the handshake, we need more time here before we can run the state-machine msleep (1); zmq_recv (server, buffer, 16, ZMQ_DONTWAIT); if (sub_command_) { recv_with_retry (s, buffer, 13); TEST_ASSERT_EQUAL_INT (0, memcmp (buffer, "\4\xb\x9SUBSCRIBEA", 13)); } else { recv_with_retry (s, buffer, 4); TEST_ASSERT_EQUAL_INT (0, memcmp (buffer, "\0\2\1A", 4)); } memcpy (buffer, "\0\4ALOL", 6); rc = TEST_ASSERT_SUCCESS_RAW_ERRNO (send (s, buffer, 6, 0)); TEST_ASSERT_EQUAL_INT (6, rc); memset (buffer, 0, sizeof (buffer)); rc = zmq_recv (server, buffer, 4, 0); TEST_ASSERT_EQUAL_INT (4, rc); TEST_ASSERT_EQUAL_INT (0, memcmp (buffer, "ALOL", 4)); } else { if (sub_command_) { const uint8_t sub[13] = {4, 11, 9, 'S', 'U', 'B', 'S', 'C', 'R', 'I', 'B', 'E', 'A'}; rc = TEST_ASSERT_SUCCESS_RAW_ERRNO ( send (s, (const char *) sub, 13, 0)); TEST_ASSERT_EQUAL_INT (13, rc); } else { const uint8_t sub[4] = {0, 2, 1, 'A'}; rc = TEST_ASSERT_SUCCESS_RAW_ERRNO ( send (s, (const char *) sub, 4, 0)); TEST_ASSERT_EQUAL_INT (4, rc); } rc = zmq_recv (server, buffer, 2, 0); TEST_ASSERT_EQUAL_INT (2, rc); TEST_ASSERT_EQUAL_INT (0, memcmp (buffer, "\1A", 2)); rc = zmq_send (server, "ALOL", 4, 0); TEST_ASSERT_EQUAL_INT (4, rc); memset (buffer, 0, sizeof (buffer)); recv_with_retry (s, buffer, 6); TEST_ASSERT_EQUAL_INT (0, memcmp (buffer, "\0\4ALOL", 6)); } close (s); test_context_socket_close (server); test_context_socket_close (server_mon); } void test_mock_sub_command () { test_mock_pub_sub (true, false); } void test_mock_sub_legacy () { test_mock_pub_sub (false, false); } void test_mock_pub_command () { test_mock_pub_sub (true, true); } void test_mock_pub_legacy () { test_mock_pub_sub (false, true); } int main (void) { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_mock_sub_command); RUN_TEST (test_mock_sub_legacy); RUN_TEST (test_mock_pub_command); RUN_TEST (test_mock_pub_legacy); return UNITY_END (); }
7,055
C++
.cpp
184
30.690217
122
0.580697
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
true
false
true
false
14,235
test_z85_decode_fuzzer.cpp
zeromq_libzmq/tests/test_z85_decode_fuzzer.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #ifdef ZMQ_USE_FUZZING_ENGINE #include <fuzzer/FuzzedDataProvider.h> #endif #include <string> #include <stdlib.h> #include "testutil.hpp" #include "testutil_unity.hpp" extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) { uint8_t *secret_key; if (size < 5) return 0; // As per API definition, input must be divisible by 5, so truncate it if it's not size -= size % 5; // As per API definition, the destination must be at least 0.8 times the input data TEST_ASSERT_NOT_NULL (secret_key = (uint8_t *) malloc (size * 4 / 5)); std::string z85_secret_key (reinterpret_cast<const char *> (data), size); zmq_z85_decode (secret_key, z85_secret_key.c_str ()); free (secret_key); return 0; } #ifndef ZMQ_USE_FUZZING_ENGINE void test_z85_decode_fuzzer () { uint8_t **data; size_t *len, num_cases = 0; if (fuzzer_corpus_encode ( "tests/libzmq-fuzz-corpora/test_z85_decode_fuzzer_seed_corpus", &data, &len, &num_cases) != 0) exit (77); while (num_cases-- > 0) { TEST_ASSERT_SUCCESS_ERRNO ( LLVMFuzzerTestOneInput (data[num_cases], len[num_cases])); free (data[num_cases]); } free (data); free (len); } int main (int argc, char **argv) { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_z85_decode_fuzzer); return UNITY_END (); } #endif
1,461
C++
.cpp
48
25.916667
87
0.647353
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
true
false
true
false
14,238
test_pair_vmci.cpp
zeromq_libzmq/tests/test_pair_vmci.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include <string> #include <sstream> #include <vmci_sockets.h> #include "testutil.hpp" #include "testutil_unity.hpp" SETUP_TEARDOWN_TESTCONTEXT void test_pair_vmci () { unsigned int cid = VMCISock_GetLocalCID (); if (cid == VMADDR_CID_ANY) TEST_IGNORE_MESSAGE ("VMCI environment unavailable, skipping test"); std::stringstream s; s << "vmci://" << cid << ":" << 5560; std::string endpoint = s.str (); void *sb = test_context_socket (ZMQ_PAIR); int rc = zmq_bind (sb, endpoint.c_str ()); if (rc < 0 && (errno == EAFNOSUPPORT || errno == EPROTONOSUPPORT)) TEST_IGNORE_MESSAGE ("VMCI not supported"); TEST_ASSERT_SUCCESS_ERRNO (rc); void *sc = test_context_socket (ZMQ_PAIR); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, endpoint.c_str ())); bounce (sb, sc); test_context_socket_close_zero_linger (sc); test_context_socket_close_zero_linger (sb); } int main (void) { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_pair_vmci); return UNITY_END (); }
1,093
C++
.cpp
33
29.151515
76
0.657143
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,243
test_socket_options_fuzzer.cpp
zeromq_libzmq/tests/test_socket_options_fuzzer.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #ifdef ZMQ_USE_FUZZING_ENGINE #include <fuzzer/FuzzedDataProvider.h> #endif #include "testutil.hpp" #include "testutil_unity.hpp" #ifdef ZMQ_DISCONNECT_MSG #define LAST_OPTION ZMQ_DISCONNECT_MSG #else #define LAST_OPTION ZMQ_BINDTODEVICE #endif extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) { int option; void *ctx = zmq_ctx_new (); TEST_ASSERT_NOT_NULL (ctx); void *server = zmq_socket (ctx, ZMQ_XPUB); TEST_ASSERT_NOT_NULL (server); if (!size) return 0; for (option = ZMQ_AFFINITY; option <= LAST_OPTION; ++option) { uint8_t out[8192]; size_t out_size = 8192; zmq_setsockopt (server, option, data, size); zmq_getsockopt (server, option, out, &out_size); } zmq_close (server); zmq_ctx_term (ctx); return 0; } #ifndef ZMQ_USE_FUZZING_ENGINE void test_socket_options_fuzzer () { uint8_t **data; size_t *len, num_cases = 0; if (fuzzer_corpus_encode ( "tests/libzmq-fuzz-corpora/test_socket_options_fuzzer_seed_corpus", &data, &len, &num_cases) != 0) exit (77); while (num_cases-- > 0) { TEST_ASSERT_SUCCESS_ERRNO ( LLVMFuzzerTestOneInput (data[num_cases], len[num_cases])); free (data[num_cases]); } free (data); free (len); } int main (int argc, char **argv) { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_socket_options_fuzzer); return UNITY_END (); } #endif
1,543
C++
.cpp
56
22.892857
77
0.644701
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
true
false
true
false
14,250
test_connect_curve_fuzzer.cpp
zeromq_libzmq/tests/test_connect_curve_fuzzer.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #ifdef ZMQ_USE_FUZZING_ENGINE #include <fuzzer/FuzzedDataProvider.h> #endif #include "testutil.hpp" #include "testutil_security.hpp" // Test that the ZMTP engine handles invalid handshake when connecting // https://rfc.zeromq.org/spec/37/ // https://rfc.zeromq.org/spec/26/ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) { const char *fixed_client_public = "{{k*81)yMWEF{/BxdMd[5RL^qRFxBgoL<8m.D^KD"; const char *fixed_client_secret = "N?Gmik8R[2ACw{b7*[-$S6[4}aO#?DB?#=<OQPc7"; const char *fixed_server_public = "3.9-xXwy{g*w72TP*3iB9IJJRxlBH<ufTAvPd2>C"; setup_test_context (); char my_endpoint[MAX_SOCKET_STRING]; fd_t server = bind_socket_resolve_port ("127.0.0.1", "0", my_endpoint); curve_client_data_t curve_client_data = { fixed_server_public, fixed_client_public, fixed_client_secret}; void *client_mon; void *client = create_and_connect_client ( my_endpoint, socket_config_curve_client, &curve_client_data, &client_mon); fd_t server_accept = TEST_ASSERT_SUCCESS_RAW_ERRNO (accept (server, NULL, NULL)); // If there is not enough data for a full greeting, just send what we can // Otherwise send greeting first, as expected by the protocol uint8_t buf[512]; if (size >= 64) { send (server_accept, (void *) data, 64, MSG_NOSIGNAL); data += 64; size -= 64; } recv (server_accept, buf, 64, 0); // Then expect HELLO and send WELCOME if there's enough data if (size >= 170) { recv (server_accept, buf, 202, 0); send (server_accept, (void *) data, 170, MSG_NOSIGNAL); data += 170; size -= 170; } // Then expect INITIATE and send READY if there's enough data if (size >= 72) { recv (server_accept, buf, 512, 0); send (server_accept, (void *) data, 72, MSG_NOSIGNAL); data += 72; size -= 72; } msleep (250); for (ssize_t sent = 0; size > 0 && (sent != -1 || errno == EINTR); size -= sent > 0 ? sent : 0, data += sent > 0 ? sent : 0) sent = send (server_accept, (const char *) data, size, MSG_NOSIGNAL); recv (server_accept, buf, 512, MSG_DONTWAIT); msleep (250); zmq_msg_t msg; zmq_msg_init (&msg); while (-1 != zmq_msg_recv (&msg, client, ZMQ_DONTWAIT)) { zmq_msg_close (&msg); zmq_msg_init (&msg); } close (server_accept); close (server); test_context_socket_close_zero_linger (client); test_context_socket_close_zero_linger (client_mon); teardown_test_context (); return 0; } #ifndef ZMQ_USE_FUZZING_ENGINE void test_connect_curve_fuzzer () { uint8_t **data; size_t *len, num_cases = 0; if (fuzzer_corpus_encode ( "tests/libzmq-fuzz-corpora/test_connect_curve_fuzzer_seed_corpus", &data, &len, &num_cases) != 0) exit (77); while (num_cases-- > 0) { TEST_ASSERT_SUCCESS_ERRNO ( LLVMFuzzerTestOneInput (data[num_cases], len[num_cases])); free (data[num_cases]); } free (data); free (len); } int main (int argc, char **argv) { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_connect_curve_fuzzer); return UNITY_END (); } #endif
3,330
C++
.cpp
95
29.589474
80
0.625233
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
true
false
true
false
14,253
test_pubsub.cpp
zeromq_libzmq/tests/test_pubsub.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include "testutil.hpp" #include "testutil_unity.hpp" SETUP_TEARDOWN_TESTCONTEXT void test (const char *address) { // Create a publisher void *publisher = test_context_socket (ZMQ_PUB); char my_endpoint[MAX_SOCKET_STRING]; // Bind publisher test_bind (publisher, address, my_endpoint, MAX_SOCKET_STRING); // Create a subscriber void *subscriber = test_context_socket (ZMQ_SUB); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (subscriber, my_endpoint)); // Subscribe to all messages. TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE, "", 0)); // Wait a bit till the subscription gets to the publisher msleep (SETTLE_TIME); // Send an empty message send_string_expect_success (publisher, "test", 0); // Receive the message in the subscriber recv_string_expect_success (subscriber, "test", 0); // Clean up. test_context_socket_close (publisher); test_context_socket_close (subscriber); } void test_norm () { #if defined ZMQ_HAVE_NORM test ("norm://224.1.2.3:5556"); #else TEST_IGNORE_MESSAGE ("libzmq without NORM, ignoring test"); #endif } int main () { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_norm); return UNITY_END (); }
1,319
C++
.cpp
42
27.571429
70
0.689082
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
true
false
true
false
14,256
test_hiccup_msg.cpp
zeromq_libzmq/tests/test_hiccup_msg.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include "testutil.hpp" #include "testutil_unity.hpp" SETUP_TEARDOWN_TESTCONTEXT void test () { char address[MAX_SOCKET_STRING]; size_t addr_length = sizeof (address); // Create a server void *server = test_context_socket (ZMQ_SERVER); // bind server TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (server, "tcp://127.0.0.1:*")); TEST_ASSERT_SUCCESS_ERRNO ( zmq_getsockopt (server, ZMQ_LAST_ENDPOINT, address, &addr_length)); // Create a client void *client = test_context_socket (ZMQ_CLIENT); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (client, ZMQ_HELLO_MSG, "HELLO", 5)); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (client, ZMQ_HICCUP_MSG, "HICCUP", 6)); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client, address)); // Receive the hello message from client recv_string_expect_success (server, "HELLO", 0); // Kill the server test_context_socket_close (server); // Receive the hiccup message recv_string_expect_success (client, "HICCUP", 0); // Clean up. test_context_socket_close (client); } int main () { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test); return UNITY_END (); }
1,248
C++
.cpp
37
29.324324
73
0.671393
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
true
false
true
false
14,261
test_bind_ws_fuzzer.cpp
zeromq_libzmq/tests/test_bind_ws_fuzzer.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #ifdef ZMQ_USE_FUZZING_ENGINE #include <fuzzer/FuzzedDataProvider.h> #endif #include "testutil.hpp" #include "testutil_unity.hpp" // Test that the ZMTP WebSocket engine handles invalid handshake when connecting // https://rfc.zeromq.org/spec/45/ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) { setup_test_context (); char my_endpoint[MAX_SOCKET_STRING]; size_t my_endpoint_size = sizeof (my_endpoint); void *server = test_context_socket (ZMQ_DEALER); // As per API by default there's no limit to the size of a message, // but the sanitizer allocator will barf over a gig or so int64_t max_msg_size = 64 * 1024 * 1024; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (server, ZMQ_MAXMSGSIZE, &max_msg_size, sizeof (int64_t))); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (server, "ws://127.0.0.1:*")); TEST_ASSERT_SUCCESS_ERRNO (zmq_getsockopt (server, ZMQ_LAST_ENDPOINT, my_endpoint, &my_endpoint_size)); // Remove trailing / my_endpoint[my_endpoint_size - 2] = '\0'; fd_t client = connect_socket (my_endpoint, AF_INET, IPPROTO_WS); void *client_good = test_context_socket (ZMQ_DEALER); my_endpoint[my_endpoint_size - 2] = '/'; TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client_good, my_endpoint)); // If there is not enough data for a full handshake, just send what we can // Otherwise send websocket handshake first, as expected by the protocol uint8_t buf[256]; if (size >= 192) { send (client, (void *) data, 192, MSG_NOSIGNAL); data += 192; size -= 192; } recv (client, buf, 256, MSG_DONTWAIT); msleep (250); for (ssize_t sent = 0; size > 0 && (sent != -1 || errno == EINTR); size -= sent > 0 ? sent : 0, data += sent > 0 ? sent : 0) sent = send (client, (const char *) data, size, MSG_NOSIGNAL); msleep (250); recv (client, buf, 256, MSG_DONTWAIT); zmq_msg_t msg; zmq_msg_init (&msg); while (-1 != zmq_msg_recv (&msg, server, ZMQ_DONTWAIT)) { zmq_msg_close (&msg); zmq_msg_init (&msg); } send_string_expect_success (client_good, "abc", 0); recv_string_expect_success (server, "abc", 0); close (client); test_context_socket_close_zero_linger (client_good); test_context_socket_close_zero_linger (server); teardown_test_context (); return 0; } #ifndef ZMQ_USE_FUZZING_ENGINE void test_bind_ws_fuzzer () { uint8_t **data; size_t *len, num_cases = 0; if (fuzzer_corpus_encode ( "tests/libzmq-fuzz-corpora/test_bind_ws_fuzzer_seed_corpus", &data, &len, &num_cases) != 0) exit (77); while (num_cases-- > 0) { TEST_ASSERT_SUCCESS_ERRNO ( LLVMFuzzerTestOneInput (data[num_cases], len[num_cases])); free (data[num_cases]); } free (data); free (len); } int main (int argc, char **argv) { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_bind_ws_fuzzer); return UNITY_END (); } #endif
3,123
C++
.cpp
83
32.060241
80
0.631736
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
true
false
true
false
14,263
test_wss_transport.cpp
zeromq_libzmq/tests/test_wss_transport.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include <string.h> #include "testutil.hpp" #include "testutil_unity.hpp" SETUP_TEARDOWN_TESTCONTEXT #ifdef ZMQ_WSS_CERT_PEM const char *key = "-----BEGIN PRIVATE KEY-----\n" "MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQDnzizmqK1e0iRR\n" "lY75z9q3TWVBzFYX00Rl18GT2liW6AYzOB/qa55EhjTf4snhC2FaUoosu4MYRdvo\n" "8qBOpFvnQDScJ6o06LyrWyL15kkBYEsTkjmDEXe/TxUVE2IBb991m1F91SIEjK5m\n" "NRH2aRjrN5mL9f8+Crrv96Y4sxGCDkqwOarViFbDYFxdYa7WrvZImpknrmM5KPyg\n" "PtU9gqnlIgAU9bPTGUJGdQeQ+AWKOgw6unV8IiKEX8jyHBoKiAqTspRCCV9yDOKx\n" "eVUGgkcAMpeSv8HVboNbfof8DI+eT8EtYNsWW4dINgiYYEGZIhy74X2dKria6hCc\n" "AYdS+/90nf0RAyymniDtgTGrMIXFmjlYpLngqfAo+zzl21dGh3VnRUFbTak8CH4g\n" "wYIefJFerwJP1im5jAiULWHaiOOk2r5fHdxbBLebqcaWBRSGGNE9cj4bj/qYuHAf\n" "VrNW5+CN3j0h5ss/f8lOoDbbrb6GtSJfI16fuQZd2hW84u38EuVd1/mzbVMv7Bip\n" "yzjbEAcOgn0Mk89zZewooz8Sxr2e1R47/5CCHJodUFqc5hmcnOqRd7YmpM68bS7V\n" "KbnOY3w9Llw6tkXMitmtUs7IiKZ1ViXA3UzMSumvEJKMqOnfNEUH9pkqYe2lVbay\n" "1HSk/hz7AkprVPMlqlF12x/794fg9wIDAQABAoICAHI10UWsYg9P9nkD+Tf4Q0kB\n" "JxyuMtT2UMLk9QmGERP5KeTeiEsVzxrwDOkqclEhLEw2UsILeWHiOaGiuX1F2cos\n" "hj9SA7ih2yOKecUyO1IkQZlY+GEtoBRwQHDr5ePTXQQzDIm1E1eugNb22uzPh2mN\n" "MWgWQjYtT0GggRN6luu/YulE4Hjo/eaxeZDA6kX4WnwXP9KfR2AIY8AIdUQjNtYg\n" "VG3/SSR/U3onexzgNsqOIyxkZjJNFzilgPpZAjOiJ6Px3r5So+Yrlx3eLBhS4+yj\n" "AK9bL4ObOblAtHtpLPHRVdqn2ApB+nuHs+BvvKJYflPLm/pt7BrXrGtRDX3Dj27T\n" "sXPZTBsPmFr8vqlbgIYNCiY3uQonsAO95o0Y0Dx6oVFlzL1ajP49KmUye+p/wEHc\n" "1XfYD8DxfU+ECEZk1/DvmKIPc4cZr2U1i9RBVRiKFd4NFIGYylLihuYhB9FZEyWQ\n" "p0TwM3DFs7PwIQNPE6mGKtjgdgBGkY4AGfCxQzdp1mM+I2700OIx0EHAbxm5JMQm\n" "NQKtBWliiz7+DLK/NWrDVS8N8tdkZVpHUK6ahvJbYG8oDqX0me6Bmk+0SaQJujis\n" "fOPFRNGanr0X97+fqMJnDeOfXAcYurXBm81IkGilUF+2a0wWhS7PGhOT4dcLKRU8\n" "tcmIZRJDWWyv2uQGg2yhAoIBAQD5sM7SX/ZuQ44HHmjQP59//vxCoZYqcPtf+52z\n" "kCpRnbbzFh/uTLRBvQ5NjZp7XOpZ/3y05JnarYChjCuVjG5+SJO7UQ0pl5N7LL0r\n" "3YGSRkfBGE05AiccyitonQssnJ4GVGfkt+1l9kVn4aMN9YkgoWc68vFzHY9CfIjS\n" "3d7QM89vGJBmBCpLG9WC0R24VNH6mfnM0MANwFlYFk9a2cKWueNjMidtHaNgry7A\n" "lWKn7jEUizkb5kNiVoFC+9qYx16unR1U2K4eRJoOhOLNWPaPuGX219iMvQ+CHs2T\n" "ZA72qj0d29t2wS8RmFXAIRNDuc7MkPh3iTF4jdRt57/pU1WPAoIBAQDtqavyOx/h\n" "kilyGjALfca68iQscWuVmWCVzFFfeGvFN4IXSxgM38xmtSEhAILVf7ozv/QNJsxv\n" "9l1xGkY+FaoFTSxglMw0iO4fZwNp2GuEy57jFzJuJyzE4FiueNb5dzoZnGnXxJIS\n" "bnprZgR42aaYAU0PzPwrqyc3PXv2J4tn6O8Mt53JO4bN+/XomD4oQBOhM0iLuS7t\n" "xTUQnsaHr1QglSIGQf4XOmXTO0+dE5uhFXkKP0Frq4MtoJUdEiWNzOdzwzxAZJTL\n" "v8dPOQud9yxKxwRg2rroasKgyRgE6GHqKSRhggiMwVOFzeMxPLJ2oeWmpRZXiMoH\n" "dkiCnPh7DBoZAoIBAGSuUJcvrrSDdO+V6XmfTfdUn+9WLLDsYdAwK0TOauICEFUw\n" "pKt4Lm8bhnrrEFGSA8VKacSfMRKmR2nclW5188/j//3WDtKolgVi4tyfMrICuMg5\n" "vlmwbokDVEGYoXrZpDa1Ljdhms40YYQjzZXBXgvUSUXR1F4wmyWaBanRYRje61PG\n" "ueMI5uzmSk+3dp5vRUQhdkKKIgbpep00Ucc2a2pPhkrnXFJ5UvmXaeip0+AXAZ9h\n" "DCQd0yoB65lQ6LIWIi2SmNMvk/YMf3o/Rxy6NKF7H1JLcrw9N9WmCgrWm9oGhyJV\n" "Fsdp2krj/B++tn/mmmaORkIdBd+wgOnYOuAghC0CggEBAK6KtLgyieh9Eqk06GIY\n" "HlJ/sOde6Pc2bIO3SW/HHcb6TDVVNjWGSzSHA+yb1np70sFc0RyziOMVWWzOMhY4\n" "jORV2CiaPxq6Eb/IRO6APf6KGIeJKsVRSgTRCvAf2SnfUTEr+WO4ftrAfnHPu6sR\n" "ldL+6ZyYG/7qNOPR6O9P/YbzwFRjqaL3b7ppuCD5ZnTjEkeKRVYwS3HeKmmpYf6W\n" "Wj+PpyxXXQesIMowPfkLRHnaLknDSQWNMcrZq4ltIV1xxe3zzZUxCUJV90eMiqaZ\n" "t9K3NNT47tnwRj4VUemQzRBO5OQjvqm49eFH4vnvLNYJcoKfrbfdwxoV2YzrQWYE\n" "7kkCggEBAKzLviuI6eoaPwgKeR2wrFBbrucnY4yqkVIFzFRpjM6azzMArYVpslZW\n" "DTdmi/2QCd9altVAT20Yvml8YqrFszpINV1DqBIfHtQPEy9oKrhFW92rhuJQo/aX\n" "1yILvzmyzLdpQG6zLm7TD7mEkumiT9F3ObeoVnAOllEwUrNAfDPPclRHGowJs6Ya\n" "wv50Idk62v7gnXny9OyFN3kUq6dtwItYqmalfKKGXhTi49mEWX39SSZSt+a15oKM\n" "21fKHdqiG/AXST7n8IlBGRzyW9TqTnmVC5zj7esmqfRT0eno399hl0LOZgJoa4dx\n" "lMwbKi/uEdrUT3ei3nAxnuQolXgClZk=\n" "-----END PRIVATE KEY-----"; const char *cert = "-----BEGIN CERTIFICATE-----\n" "MIIFkTCCA3mgAwIBAgIUWazS3jRxgV/9TgdybZ9ch7nYsQIwDQYJKoZIhvcNAQEL\n" "BQAwVzELMAkGA1UEBhMCWFgxFTATBgNVBAcMDERlZmF1bHQgQ2l0eTEcMBoGA1UE\n" "CgwTRGVmYXVsdCBDb21wYW55IEx0ZDETMBEGA1UEAwwKemVyb21xLm9yZzAgFw0x\n" "OTExMTAwODMzMThaGA8yMTE5MTAxNzA4MzMxOFowVzELMAkGA1UEBhMCWFgxFTAT\n" "BgNVBAcMDERlZmF1bHQgQ2l0eTEcMBoGA1UECgwTRGVmYXVsdCBDb21wYW55IEx0\n" "ZDETMBEGA1UEAwwKemVyb21xLm9yZzCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCC\n" "AgoCggIBAOfOLOaorV7SJFGVjvnP2rdNZUHMVhfTRGXXwZPaWJboBjM4H+prnkSG\n" "NN/iyeELYVpSiiy7gxhF2+jyoE6kW+dANJwnqjTovKtbIvXmSQFgSxOSOYMRd79P\n" "FRUTYgFv33WbUX3VIgSMrmY1EfZpGOs3mYv1/z4Kuu/3pjizEYIOSrA5qtWIVsNg\n" "XF1hrtau9kiamSeuYzko/KA+1T2CqeUiABT1s9MZQkZ1B5D4BYo6DDq6dXwiIoRf\n" "yPIcGgqICpOylEIJX3IM4rF5VQaCRwAyl5K/wdVug1t+h/wMj55PwS1g2xZbh0g2\n" "CJhgQZkiHLvhfZ0quJrqEJwBh1L7/3Sd/REDLKaeIO2BMaswhcWaOVikueCp8Cj7\n" "POXbV0aHdWdFQVtNqTwIfiDBgh58kV6vAk/WKbmMCJQtYdqI46Tavl8d3FsEt5up\n" "xpYFFIYY0T1yPhuP+pi4cB9Ws1bn4I3ePSHmyz9/yU6gNtutvoa1Il8jXp+5Bl3a\n" "Fbzi7fwS5V3X+bNtUy/sGKnLONsQBw6CfQyTz3Nl7CijPxLGvZ7VHjv/kIIcmh1Q\n" "WpzmGZyc6pF3tiakzrxtLtUpuc5jfD0uXDq2RcyK2a1SzsiIpnVWJcDdTMxK6a8Q\n" "koyo6d80RQf2mSph7aVVtrLUdKT+HPsCSmtU8yWqUXXbH/v3h+D3AgMBAAGjUzBR\n" "MB0GA1UdDgQWBBTVHR+4lBIBcr2rEEMdideTAkwDZDAfBgNVHSMEGDAWgBTVHR+4\n" "lBIBcr2rEEMdideTAkwDZDAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUA\n" "A4ICAQB9M5p9z92UhVXg2baUj9QBN2YFGAeveFRpZ9Y/wktEssTqMKkc+39UtfJS\n" "UclZnzMEhLyTieNqf+8GCgLLI0YSTIJpWwzvQBcXPoo+8IcexANvxR22KZrE51y4\n" "/YfCKh8Q0ZbG8oc5Br8YHwipzGcmWjWtznfMpuaELezv/r381QV1Sbmpw2a0jvwp\n" "uA/bc+4IZ9yvrhC9KkOUnivnCV71U2Wy8zOvrBEJicuGOc+lbWJRKyjbMDi1IybG\n" "VnemtkQEyXFh6f1h8AdaN+Xj7qXX/YKmNk20Siu4qDNo8nozVpOL2DHjoKLa4N2c\n" "ULG3kXScxVxWqCuPVNeypV2TZ9uSVFeKK/VJ5iGvFeifDsqVVo6WC4Pdz0WYes8H\n" "3VqEPSwmNJ1FswLpYpGgCEFnkGRPFFB5dmwr0fuubkgaJPatxrImFac+nukfqZ8N\n" "x/d4t72u1yIs0HnrkAj96ZIUXH5jFGPXbD8eGO0hzw+wbY9KRLXGBBl2B4EAaBdt\n" "Cmp8R8xus3FGDZ5RVftZvTQO2CiTC4yn9Wab/ADDwcXDs6ntHctx4xQpm0tLqMoz\n" "BTH8+ftqyzklar35gJluD84oh1kynEojrPkUvb75NlzxikBSF3pRrOx30Myy7DBx\n" "rhUIqDFxqlYFx9InEzHlvI7cWWdMNqAmSxpz4SXMrd/7PJG+Ag==\n" "-----END CERTIFICATE-----"; void test_roundtrip () { char connect_address[MAX_SOCKET_STRING + sizeof ("/roundtrip") - 1]; size_t addr_length = sizeof (connect_address); void *sb = test_context_socket (ZMQ_REP); zmq_setsockopt (sb, ZMQ_WSS_CERT_PEM, cert, strlen (cert)); zmq_setsockopt (sb, ZMQ_WSS_KEY_PEM, key, strlen (key)); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "wss://*:*/roundtrip")); TEST_ASSERT_SUCCESS_ERRNO ( zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, connect_address, &addr_length)); strcat (connect_address, "/roundtrip"); void *sc = test_context_socket (ZMQ_REQ); zmq_setsockopt (sc, ZMQ_WSS_TRUST_PEM, cert, strlen (cert)); zmq_setsockopt (sc, ZMQ_WSS_HOSTNAME, "zeromq.org", strlen ("zeromq.org")); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, connect_address)); bounce (sb, sc); test_context_socket_close (sc); test_context_socket_close (sb); } int main () { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_roundtrip); return UNITY_END (); } #else int main () { printf ("WSS unavailable, skipping test\n"); return 77; } #endif
7,090
C++
.cpp
125
53.576
79
0.855787
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
true
false
14,268
test_reconnect_options.cpp
zeromq_libzmq/tests/test_reconnect_options.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include <assert.h> #include "testutil.hpp" #include "testutil_unity.hpp" #include "testutil_monitoring.hpp" #include <unity.h> // test behavior with (mostly) default values void reconnect_default () { // setup pub socket void *pub = test_context_socket (ZMQ_PUB); // Bind pub socket TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (pub, ENDPOINT_0)); // setup sub socket void *sub = test_context_socket (ZMQ_SUB); // Monitor all events on sub TEST_ASSERT_SUCCESS_ERRNO ( zmq_socket_monitor (sub, "inproc://monitor-sub", ZMQ_EVENT_ALL)); // Create socket for collecting monitor events void *sub_mon = test_context_socket (ZMQ_PAIR); // Connect so they'll get events TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub_mon, "inproc://monitor-sub")); // set reconnect interval so only a single reconnect is tried int interval = 60 * 1000; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (sub, ZMQ_RECONNECT_IVL, &interval, sizeof (interval))); // connect to pub TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub, ENDPOINT_0)); // confirm that we get following events expect_monitor_event (sub_mon, ZMQ_EVENT_CONNECT_DELAYED); expect_monitor_event (sub_mon, ZMQ_EVENT_CONNECTED); expect_monitor_event (sub_mon, ZMQ_EVENT_HANDSHAKE_SUCCEEDED); // close the pub socket test_context_socket_close_zero_linger (pub); // confirm that we get following events expect_monitor_event (sub_mon, ZMQ_EVENT_DISCONNECTED); expect_monitor_event (sub_mon, ZMQ_EVENT_CONNECT_RETRIED); // ZMQ_EVENT_CONNECT_RETRIED should be last event, because of timeout set above int event; char *event_address; int rc = get_monitor_event_with_timeout (sub_mon, &event, &event_address, 2 * 1000); assert (rc == -1); LIBZMQ_UNUSED (rc); // Close sub // TODO why does this use zero_linger? test_context_socket_close_zero_linger (sub); // Close monitor // TODO why does this use zero_linger? test_context_socket_close_zero_linger (sub_mon); } // test successful reconnect void reconnect_success () { // setup pub socket void *pub = test_context_socket (ZMQ_PUB); // Bind pub socket TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (pub, ENDPOINT_0)); // setup sub socket void *sub = test_context_socket (ZMQ_SUB); // Monitor all events on sub TEST_ASSERT_SUCCESS_ERRNO ( zmq_socket_monitor (sub, "inproc://monitor-sub", ZMQ_EVENT_ALL)); // Create socket for collecting monitor events void *sub_mon = test_context_socket (ZMQ_PAIR); // Connect so they'll get events TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub_mon, "inproc://monitor-sub")); // set reconnect interval so only a single reconnect is tried int interval = 1 * 1000; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (sub, ZMQ_RECONNECT_IVL, &interval, sizeof (interval))); // connect to pub TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub, ENDPOINT_0)); // confirm that we get following events expect_monitor_event (sub_mon, ZMQ_EVENT_CONNECT_DELAYED); expect_monitor_event (sub_mon, ZMQ_EVENT_CONNECTED); expect_monitor_event (sub_mon, ZMQ_EVENT_HANDSHAKE_SUCCEEDED); // close the pub socket test_context_socket_close_zero_linger (pub); // confirm that we get following events expect_monitor_event (sub_mon, ZMQ_EVENT_DISCONNECTED); expect_monitor_event (sub_mon, ZMQ_EVENT_CONNECT_RETRIED); // ZMQ_EVENT_CONNECT_RETRIED should be last event, because of timeout set above int event; char *event_address; int rc = get_monitor_event_with_timeout (sub_mon, &event, &event_address, SETTLE_TIME); assert (rc == -1); LIBZMQ_UNUSED (rc); // Now re-bind pub socket and wait for re-connect pub = test_context_socket (ZMQ_PUB); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (pub, ENDPOINT_0)); msleep (SETTLE_TIME); // confirm that we get following events expect_monitor_event (sub_mon, ZMQ_EVENT_CONNECT_DELAYED); expect_monitor_event (sub_mon, ZMQ_EVENT_CONNECTED); expect_monitor_event (sub_mon, ZMQ_EVENT_HANDSHAKE_SUCCEEDED); // ZMQ_EVENT_HANDSHAKE_SUCCEEDED should be last event rc = get_monitor_event_with_timeout (sub_mon, &event, &event_address, SETTLE_TIME); assert (rc == -1); // Close sub // TODO why does this use zero_linger? test_context_socket_close_zero_linger (sub); test_context_socket_close_zero_linger (pub); // Close monitor // TODO why does this use zero_linger? test_context_socket_close_zero_linger (sub_mon); } #ifdef ZMQ_BUILD_DRAFT_API // test stopping reconnect on connection refused void reconnect_stop_on_refused () { // setup pub socket void *pub = test_context_socket (ZMQ_PUB); // Bind pub socket TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (pub, ENDPOINT_0)); // setup sub socket void *sub = test_context_socket (ZMQ_SUB); // Monitor all events on sub TEST_ASSERT_SUCCESS_ERRNO ( zmq_socket_monitor (sub, "inproc://monitor-sub", ZMQ_EVENT_ALL)); // Create socket for collecting monitor events void *sub_mon = test_context_socket (ZMQ_PAIR); // Connect so they'll get events TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub_mon, "inproc://monitor-sub")); // set option to stop reconnecting on error int stopReconnectOnError = ZMQ_RECONNECT_STOP_CONN_REFUSED; TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (sub, ZMQ_RECONNECT_STOP, &stopReconnectOnError, sizeof (stopReconnectOnError))); // connect to pub TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub, ENDPOINT_0)); // confirm that we get following events expect_monitor_event (sub_mon, ZMQ_EVENT_CONNECT_DELAYED); expect_monitor_event (sub_mon, ZMQ_EVENT_CONNECTED); expect_monitor_event (sub_mon, ZMQ_EVENT_HANDSHAKE_SUCCEEDED); // close the pub socket test_context_socket_close_zero_linger (pub); // confirm that we get following events expect_monitor_event (sub_mon, ZMQ_EVENT_DISCONNECTED); expect_monitor_event (sub_mon, ZMQ_EVENT_CONNECT_RETRIED); expect_monitor_event (sub_mon, ZMQ_EVENT_CONNECT_DELAYED); expect_monitor_event (sub_mon, ZMQ_EVENT_CLOSED); // ZMQ_EVENT_CLOSED should be last event, because of ZMQ_RECONNECT_STOP set above int event = 0; char *event_address; int rc = get_monitor_event_with_timeout (sub_mon, &event, &event_address, 2 * 1000); int limit = 0; while ((rc != -1) && (++limit < 1000)) { print_unexpected_event_stderr (event, rc, 0, -1); rc = get_monitor_event_with_timeout (sub_mon, &event, &event_address, 2 * 1000); } // Close sub // TODO why does this use zero_linger? test_context_socket_close_zero_linger (sub); // Close monitor // TODO why does this use zero_linger? test_context_socket_close_zero_linger (sub_mon); } #endif #ifdef ZMQ_BUILD_DRAFT_API // test stopping reconnect on connection refused void reconnect_stop_on_handshake_failed () { char bind_address[MAX_SOCKET_STRING]; size_t addr_length = sizeof (bind_address); void *dummy = test_context_socket (ZMQ_STREAM); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (dummy, "tcp://127.0.0.1:0")); TEST_ASSERT_SUCCESS_ERRNO ( zmq_getsockopt (dummy, ZMQ_LAST_ENDPOINT, bind_address, &addr_length)); // setup sub socket void *sub = test_context_socket (ZMQ_SUB); // Monitor all events on sub TEST_ASSERT_SUCCESS_ERRNO ( zmq_socket_monitor (sub, "inproc://monitor-sub", ZMQ_EVENT_ALL)); // Create socket for collecting monitor events void *sub_mon = test_context_socket (ZMQ_PAIR); // Connect so they'll get events TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub_mon, "inproc://monitor-sub")); // set handshake interval (i.e., timeout) to a more reasonable value int handshakeInterval = 1000; TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt ( sub, ZMQ_HANDSHAKE_IVL, &handshakeInterval, sizeof (handshakeInterval))); // set option to stop reconnecting on failed handshake int stopReconnectOnError = ZMQ_RECONNECT_STOP_HANDSHAKE_FAILED; TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (sub, ZMQ_RECONNECT_STOP, &stopReconnectOnError, sizeof (stopReconnectOnError))); // connect to dummy stream socket above TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub, bind_address)); #if 1 // ZMQ_EVENT_DISCONNECTED should be last event, because of ZMQ_RECONNECT_STOP set above expect_monitor_event (sub_mon, ZMQ_EVENT_CONNECT_DELAYED); expect_monitor_event (sub_mon, ZMQ_EVENT_CONNECTED); expect_monitor_event (sub_mon, ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL); expect_monitor_event (sub_mon, ZMQ_EVENT_DISCONNECTED); #else print_events (sub_mon, 2 * 1000, 1000); #endif // Close sub // TODO why does this use zero_linger? test_context_socket_close_zero_linger (sub); test_context_socket_close_zero_linger (dummy); // Close monitor // TODO why does this use zero_linger? test_context_socket_close_zero_linger (sub_mon); } #endif #if defined(ZMQ_BUILD_DRAFT_API) && defined(ZMQ_HAVE_IPC) // test stopping reconnect after disconnect void reconnect_stop_after_disconnect () { // Setup sub socket void *sub = test_context_socket (ZMQ_SUB); // Monitor all events on sub TEST_ASSERT_SUCCESS_ERRNO ( zmq_socket_monitor (sub, "inproc://monitor-sub", ZMQ_EVENT_ALL)); // Create socket for collecting monitor events void *sub_mon = test_context_socket (ZMQ_PAIR); // Connect so they'll get events TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub_mon, "inproc://monitor-sub")); // Set option to stop reconnecting after disconnect int stopReconnectAfterDisconnect = ZMQ_RECONNECT_STOP_AFTER_DISCONNECT; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (sub, ZMQ_RECONNECT_STOP, &stopReconnectAfterDisconnect, sizeof (stopReconnectAfterDisconnect))); // Connect to a dummy that cannot be connected TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub, "ipc://@dummy")); // Confirm that connect failed and reconnect expect_monitor_event (sub_mon, ZMQ_EVENT_CLOSED); expect_monitor_event (sub_mon, ZMQ_EVENT_CONNECT_RETRIED); // Disconnect the sub socket TEST_ASSERT_SUCCESS_ERRNO (zmq_disconnect (sub, "ipc://@dummy")); // Confirm that connect failed and will not reconnect expect_monitor_event (sub_mon, ZMQ_EVENT_CLOSED); // Close sub test_context_socket_close_zero_linger (sub); // Close monitor test_context_socket_close_zero_linger (sub_mon); } #endif void setUp () { setup_test_context (); } void tearDown () { teardown_test_context (); } int main (void) { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (reconnect_default); RUN_TEST (reconnect_success); #ifdef ZMQ_BUILD_DRAFT_API RUN_TEST (reconnect_stop_on_refused); RUN_TEST (reconnect_stop_on_handshake_failed); #endif #if defined(ZMQ_BUILD_DRAFT_API) && defined(ZMQ_HAVE_IPC) RUN_TEST (reconnect_stop_after_disconnect); #endif return UNITY_END (); }
11,566
C++
.cpp
267
37.28839
91
0.675407
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
true
false
14,270
test_connect_ws_fuzzer.cpp
zeromq_libzmq/tests/test_connect_ws_fuzzer.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #ifdef ZMQ_USE_FUZZING_ENGINE #include <fuzzer/FuzzedDataProvider.h> #endif #include "testutil.hpp" #include "testutil_unity.hpp" // Test that the ZMTP WebSocket engine handles invalid handshake when connecting // https://rfc.zeromq.org/spec/45/ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) { setup_test_context (); char my_endpoint[MAX_SOCKET_STRING]; fd_t server = bind_socket_resolve_port ("127.0.0.1", "0", my_endpoint, AF_INET, IPPROTO_WS); void *client = test_context_socket (ZMQ_PULL); // As per API by default there's no limit to the size of a message, // but the sanitizer allocator will barf over a gig or so int64_t max_msg_size = 64 * 1024 * 1024; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (client, ZMQ_MAXMSGSIZE, &max_msg_size, sizeof (int64_t))); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client, my_endpoint)); fd_t server_accept = TEST_ASSERT_SUCCESS_RAW_ERRNO (accept (server, NULL, NULL)); // If there is not enough data for a full handshake, just send what we can // Otherwise send websocket handshake first, as expected by the protocol uint8_t buf[256]; recv (server_accept, buf, 256, 0); if (size >= 166) { send (server_accept, (void *) data, 166, MSG_NOSIGNAL); data += 166; size -= 166; } recv (server_accept, buf, 256, MSG_DONTWAIT); // Then send the READY command if (size >= 29) { send (server_accept, (void *) data, 29, MSG_NOSIGNAL); data += 29; size -= 29; } msleep (250); for (ssize_t sent = 0; size > 0 && (sent != -1 || errno == EINTR); size -= sent > 0 ? sent : 0, data += sent > 0 ? sent : 0) sent = send (server_accept, (const char *) data, size, MSG_NOSIGNAL); msleep (250); zmq_msg_t msg; zmq_msg_init (&msg); while (-1 != zmq_msg_recv (&msg, client, ZMQ_DONTWAIT)) { zmq_msg_close (&msg); zmq_msg_init (&msg); } close (server_accept); close (server); test_context_socket_close_zero_linger (client); teardown_test_context (); return 0; } #ifndef ZMQ_USE_FUZZING_ENGINE void test_connect_ws_fuzzer () { uint8_t **data; size_t *len, num_cases = 0; if (fuzzer_corpus_encode ( "tests/libzmq-fuzz-corpora/test_connect_ws_fuzzer_seed_corpus", &data, &len, &num_cases) != 0) exit (77); while (num_cases-- > 0) { TEST_ASSERT_SUCCESS_ERRNO ( LLVMFuzzerTestOneInput (data[num_cases], len[num_cases])); free (data[num_cases]); } free (data); free (len); } int main (int argc, char **argv) { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_connect_ws_fuzzer); return UNITY_END (); } #endif
2,884
C++
.cpp
82
29.45122
80
0.619167
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
true
false
true
false
14,274
test_bind_curve_fuzzer.cpp
zeromq_libzmq/tests/test_bind_curve_fuzzer.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #ifdef ZMQ_USE_FUZZING_ENGINE #include <fuzzer/FuzzedDataProvider.h> #endif #include <string.h> #include "testutil.hpp" #include "testutil_security.hpp" // Test that the ZMTP engine handles invalid handshake when binding // https://rfc.zeromq.org/spec/37/ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) { const char *fixed_client_public = "{{k*81)yMWEF{/BxdMd[5RL^qRFxBgoL<8m.D^KD"; const char *fixed_client_secret = "N?Gmik8R[2ACw{b7*[-$S6[4}aO#?DB?#=<OQPc7"; const char *fixed_server_public = "3.9-xXwy{g*w72TP*3iB9IJJRxlBH<ufTAvPd2>C"; const char *fixed_server_secret = "T}t5GLq%&Qm1)y3ywu-}pY3KEA//{^Ut!M1ut+B4"; void *handler; void *zap_thread; void *server; void *server_mon; char my_endpoint[MAX_SOCKET_STRING]; setup_test_context (); memcpy (valid_client_public, fixed_client_public, 41); setup_context_and_server_side ( &handler, &zap_thread, &server, &server_mon, my_endpoint, &zap_handler, &socket_config_curve_server, (void *) fixed_server_secret); fd_t client = connect_socket (my_endpoint); // If there is not enough data for a full greeting, just send what we can // Otherwise send greeting first, as expected by the protocol uint8_t buf[512]; if (size >= 64) { send (client, (void *) data, 64, MSG_NOSIGNAL); data += 64; size -= 64; } recv (client, buf, 64, 0); // Then send HELLO and expect WELCOME if there's enough data if (size >= 202) { send (client, (void *) data, 202, MSG_NOSIGNAL); data += 202; size -= 202; recv (client, buf, 170, MSG_DONTWAIT); } // Then send READY and expect INITIATE if there's enough data if (size >= 301) { send (client, (void *) data, 301, MSG_NOSIGNAL); data += 301; size -= 301; recv (client, buf, 512, MSG_DONTWAIT); } msleep (250); for (ssize_t sent = 0; size > 0 && (sent != -1 || errno == EINTR); size -= sent > 0 ? sent : 0, data += sent > 0 ? sent : 0) sent = send (client, (const char *) data, size, MSG_NOSIGNAL); msleep (250); // Drain the queue, if any zmq_msg_t msg; zmq_msg_init (&msg); while (-1 != zmq_msg_recv (&msg, server, ZMQ_DONTWAIT)) { zmq_msg_close (&msg); zmq_msg_init (&msg); } // A well-behaved client should work while the malformed data from the other // is being received curve_client_data_t curve_client_data = { fixed_server_public, fixed_client_public, fixed_client_secret}; void *client_mon; void *client_good = create_and_connect_client ( my_endpoint, socket_config_curve_client, &curve_client_data, &client_mon); bounce (server, client_good); close (client); test_context_socket_close_zero_linger (client_good); test_context_socket_close_zero_linger (client_mon); shutdown_context_and_server_side (zap_thread, server, server_mon, handler); teardown_test_context (); return 0; } #ifndef ZMQ_USE_FUZZING_ENGINE void test_bind_curve_fuzzer () { uint8_t **data; size_t *len, num_cases = 0; if (fuzzer_corpus_encode ( "tests/libzmq-fuzz-corpora/test_bind_curve_fuzzer_seed_corpus", &data, &len, &num_cases) != 0) exit (77); while (num_cases-- > 0) { TEST_ASSERT_SUCCESS_ERRNO ( LLVMFuzzerTestOneInput (data[num_cases], len[num_cases])); free (data[num_cases]); } free (data); free (len); } int main (int argc, char **argv) { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_bind_curve_fuzzer); return UNITY_END (); } #endif
3,755
C++
.cpp
106
29.971698
81
0.631608
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
true
false
true
false
14,278
test_reqrep_vmci.cpp
zeromq_libzmq/tests/test_reqrep_vmci.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include <string> #include <sstream> #include <vmci_sockets.h> #include "testutil.hpp" #include "testutil_unity.hpp" SETUP_TEARDOWN_TESTCONTEXT void test_reqrep_vmci () { unsigned int cid = VMCISock_GetLocalCID (); if (cid == VMADDR_CID_ANY) TEST_IGNORE_MESSAGE ("VMCI environment unavailable, skipping test"); std::stringstream s; s << "vmci://" << cid << ":" << 5560; std::string endpoint = s.str (); void *sb = test_context_socket (ZMQ_DEALER); int rc = zmq_bind (sb, endpoint.c_str ()); if (rc < 0 && (errno == EAFNOSUPPORT || errno == EPROTONOSUPPORT)) TEST_IGNORE_MESSAGE ("VMCI not supported"); TEST_ASSERT_SUCCESS_ERRNO (rc); void *sc = test_context_socket (ZMQ_DEALER); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, endpoint.c_str ())); bounce (sb, sc); test_context_socket_close_zero_linger (sc); test_context_socket_close_zero_linger (sb); } int main (void) { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_reqrep_vmci); return UNITY_END (); }
1,101
C++
.cpp
33
29.393939
76
0.659735
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,280
test_ws_transport.cpp
zeromq_libzmq/tests/test_ws_transport.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include <string.h> #include "testutil.hpp" #include "testutil_unity.hpp" SETUP_TEARDOWN_TESTCONTEXT void test_roundtrip () { char bind_address[MAX_SOCKET_STRING]; char connect_address[MAX_SOCKET_STRING]; size_t addr_length = sizeof (connect_address); void *sb = test_context_socket (ZMQ_REP); void *sc = test_context_socket (ZMQ_REQ); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ws://*:*/roundtrip")); TEST_ASSERT_SUCCESS_ERRNO ( zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, bind_address, &addr_length)); // Windows can't connect to 0.0.0.0 snprintf (connect_address, MAX_SOCKET_STRING * sizeof (char), "ws://127.0.0.1%s", strrchr (bind_address, ':')); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, connect_address)); bounce (sb, sc); TEST_ASSERT_SUCCESS_ERRNO (zmq_disconnect (sc, connect_address)); TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (sb, bind_address)); test_context_socket_close (sc); test_context_socket_close (sb); } void test_roundtrip_without_path () { char connect_address[MAX_SOCKET_STRING]; size_t addr_length = sizeof (connect_address); void *sb = test_context_socket (ZMQ_REP); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ws://127.0.0.1:*")); TEST_ASSERT_SUCCESS_ERRNO ( zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, connect_address, &addr_length)); void *sc = test_context_socket (ZMQ_REQ); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, connect_address)); bounce (sb, sc); test_context_socket_close (sc); test_context_socket_close (sb); } void test_heartbeat () { char connect_address[MAX_SOCKET_STRING]; size_t addr_length = sizeof (connect_address); void *sb = test_context_socket (ZMQ_REP); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ws://127.0.0.1:*/heartbeat")); TEST_ASSERT_SUCCESS_ERRNO ( zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, connect_address, &addr_length)); void *sc = test_context_socket (ZMQ_REQ); // Setting heartbeat settings int ivl = 10; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (sc, ZMQ_HEARTBEAT_IVL, &ivl, sizeof (ivl))); // Disable reconnect, to make sure the ping-pong actually work ivl = -1; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (sc, ZMQ_RECONNECT_IVL, &ivl, sizeof (ivl))); // Connect to server TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, connect_address)); // Make sure some ping and pong going through msleep (100); bounce (sb, sc); test_context_socket_close (sc); test_context_socket_close (sb); } void test_short_message () { char connect_address[MAX_SOCKET_STRING]; size_t addr_length = sizeof (connect_address); void *sb = test_context_socket (ZMQ_REP); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ws://127.0.0.1:*/short")); TEST_ASSERT_SUCCESS_ERRNO ( zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, connect_address, &addr_length)); void *sc = test_context_socket (ZMQ_REQ); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, connect_address)); zmq_msg_t msg; TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init_size (&msg, 255)); for (unsigned char i = 0; i < 255; ++i) ((unsigned char *) zmq_msg_data (&msg))[i] = i; int rc = zmq_msg_send (&msg, sc, 0); TEST_ASSERT_EQUAL_INT (255, rc); rc = zmq_msg_recv (&msg, sb, 0); TEST_ASSERT_EQUAL_INT (255, rc); for (unsigned char i = 0; i < 255; ++i) TEST_ASSERT_EQUAL_INT (i, ((unsigned char *) zmq_msg_data (&msg))[i]); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg)); test_context_socket_close (sc); test_context_socket_close (sb); } void test_large_message () { char connect_address[MAX_SOCKET_STRING]; size_t addr_length = sizeof (connect_address); void *sb = test_context_socket (ZMQ_REP); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ws://127.0.0.1:*/large")); TEST_ASSERT_SUCCESS_ERRNO ( zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, connect_address, &addr_length)); void *sc = test_context_socket (ZMQ_REQ); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, connect_address)); zmq_msg_t msg; TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init_size (&msg, 65536)); for (int i = 0; i < 65536; ++i) ((unsigned char *) zmq_msg_data (&msg))[i] = i % 255; int rc = zmq_msg_send (&msg, sc, 0); TEST_ASSERT_EQUAL_INT (65536, rc); rc = zmq_msg_recv (&msg, sb, 0); TEST_ASSERT_EQUAL_INT (65536, rc); for (int i = 0; i < 65536; ++i) TEST_ASSERT_EQUAL_INT (i % 255, ((unsigned char *) zmq_msg_data (&msg))[i]); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg)); test_context_socket_close (sc); test_context_socket_close (sb); } void test_curve () { char connect_address[MAX_SOCKET_STRING]; size_t addr_length = sizeof (connect_address); char client_public[41]; char client_secret[41]; char server_public[41]; char server_secret[41]; TEST_ASSERT_SUCCESS_ERRNO ( zmq_curve_keypair (server_public, server_secret)); TEST_ASSERT_SUCCESS_ERRNO ( zmq_curve_keypair (client_public, client_secret)); void *server = test_context_socket (ZMQ_REP); int as_server = 1; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (server, ZMQ_CURVE_SERVER, &as_server, sizeof (int))); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (server, ZMQ_CURVE_SECRETKEY, server_secret, 41)); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (server, "ws://127.0.0.1:*/roundtrip")); TEST_ASSERT_SUCCESS_ERRNO (zmq_getsockopt (server, ZMQ_LAST_ENDPOINT, connect_address, &addr_length)); void *client = test_context_socket (ZMQ_REQ); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (client, ZMQ_CURVE_SERVERKEY, server_public, 41)); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (client, ZMQ_CURVE_PUBLICKEY, client_public, 41)); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (client, ZMQ_CURVE_SECRETKEY, client_secret, 41)); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client, connect_address)); bounce (server, client); test_context_socket_close (client); test_context_socket_close (server); } void test_mask_shared_msg () { char connect_address[MAX_SOCKET_STRING]; size_t addr_length = sizeof (connect_address); void *sb = test_context_socket (ZMQ_DEALER); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ws://127.0.0.1:*/mask-shared")); TEST_ASSERT_SUCCESS_ERRNO ( zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, connect_address, &addr_length)); void *sc = test_context_socket (ZMQ_DEALER); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, connect_address)); zmq_msg_t msg; zmq_msg_init_size ( &msg, 255); // Message have to be long enough so it won't fit inside msg unsigned char *data = (unsigned char *) zmq_msg_data (&msg); for (int i = 0; i < 255; i++) data[i] = i; // Taking a copy to make the msg shared zmq_msg_t copy; zmq_msg_init (&copy); zmq_msg_copy (&copy, &msg); // Sending the shared msg int rc = zmq_msg_send (&msg, sc, 0); TEST_ASSERT_EQUAL_INT (255, rc); // Recv the msg and check that it was masked correctly rc = zmq_msg_recv (&msg, sb, 0); TEST_ASSERT_EQUAL_INT (255, rc); data = (unsigned char *) zmq_msg_data (&msg); for (int i = 0; i < 255; i++) TEST_ASSERT_EQUAL_INT (i, data[i]); // Testing that copy was not masked data = (unsigned char *) zmq_msg_data (&copy); for (int i = 0; i < 255; i++) TEST_ASSERT_EQUAL_INT (i, data[i]); // Constant msg cannot be masked as well, as it is constant rc = zmq_send_const (sc, "HELLO", 5, 0); TEST_ASSERT_EQUAL_INT (5, rc); recv_string_expect_success (sb, "HELLO", 0); zmq_msg_close (&copy); zmq_msg_close (&msg); test_context_socket_close (sc); test_context_socket_close (sb); } void test_pub_sub () { char connect_address[MAX_SOCKET_STRING]; size_t addr_length = sizeof (connect_address); void *sb = test_context_socket (ZMQ_XPUB); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ws://127.0.0.1:*")); TEST_ASSERT_SUCCESS_ERRNO ( zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, connect_address, &addr_length)); void *sc = test_context_socket (ZMQ_SUB); TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (sc, ZMQ_SUBSCRIBE, "A", 1)); TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (sc, ZMQ_SUBSCRIBE, "B", 1)); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, connect_address)); recv_string_expect_success (sb, "\1A", 0); recv_string_expect_success (sb, "\1B", 0); send_string_expect_success (sb, "A", 0); send_string_expect_success (sb, "B", 0); recv_string_expect_success (sc, "A", 0); recv_string_expect_success (sc, "B", 0); test_context_socket_close (sc); test_context_socket_close (sb); } int main () { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_roundtrip_without_path); RUN_TEST (test_roundtrip); RUN_TEST (test_short_message); RUN_TEST (test_large_message); RUN_TEST (test_heartbeat); RUN_TEST (test_mask_shared_msg); RUN_TEST (test_pub_sub); if (zmq_has ("curve")) RUN_TEST (test_curve); return UNITY_END (); }
9,320
C++
.cpp
224
36.21875
80
0.650715
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
true
false
14,286
test_zmq_ppoll_signals.cpp
zeromq_libzmq/tests/test_zmq_ppoll_signals.cpp
/* SPDX-License-Identifier: MPL-2.0 */ // author: E. G. Patrick Bos, Netherlands eScience Center, 2021 #include "testutil.hpp" #include "testutil_unity.hpp" #include <string.h> // memset // types.h and wait.h for waitpid: #include <sys/types.h> #include <sys/wait.h> static bool sigterm_received = false; void handle_sigterm (int /*signum*/) { sigterm_received = true; } void recv_string_expect_success_or_eagain (void *socket_, const char *str_, int flags_) { const size_t len = str_ ? strlen (str_) : 0; char buffer[255]; TEST_ASSERT_LESS_OR_EQUAL_MESSAGE (sizeof (buffer), len, "recv_string_expect_success cannot be " "used for strings longer than 255 " "characters"); const int rc = zmq_recv (socket_, buffer, sizeof (buffer), flags_); if (rc < 0) { if (errno == EAGAIN) { printf ("got EAGAIN\n"); return; } else { TEST_ASSERT_SUCCESS_ERRNO (rc); } } else { TEST_ASSERT_EQUAL_INT ((int) len, rc); if (str_) TEST_ASSERT_EQUAL_STRING_LEN (str_, buffer, len); } } void test_ppoll_signals () { #ifdef ZMQ_HAVE_PPOLL size_t len = MAX_SOCKET_STRING; char my_endpoint[MAX_SOCKET_STRING]; pid_t child_pid; /* Get a random TCP port first */ setup_test_context (); void *sb = test_context_socket (ZMQ_REP); bind_loopback (sb, 0, my_endpoint, len); test_context_socket_close (sb); teardown_test_context (); do { child_pid = fork (); } while (child_pid == -1); // retry if fork fails if (child_pid > 0) { // parent setup_test_context (); void *socket = test_context_socket (ZMQ_REQ); // to make sure we don't hang when the child has already exited at the end, we set a receive timeout of five seconds int recv_timeout = 5000; TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt ( socket, ZMQ_RCVTIMEO, &recv_timeout, sizeof (recv_timeout))); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (socket, my_endpoint)); // bind is on the master process to avoid zombie children to hold on to binds // first send a test message to check whether the signal mask is setup in the child process send_string_expect_success (socket, "breaker breaker", 0); recv_string_expect_success (socket, "one-niner", 0); // then send the signal kill (child_pid, SIGTERM); // for good measure, and to make sure everything went as expected, close off with another handshake, which will trigger the second poll call on the other side send_string_expect_success (socket, "breaker breaker", 0); // in case the 1 second sleep was not enough on the child side, we are also fine with an EAGAIN here recv_string_expect_success_or_eagain (socket, "one-niner", 0); // finish test_context_socket_close (socket); teardown_test_context (); // wait for child int status = 0; pid_t pid; do { pid = waitpid (child_pid, &status, 0); } while (-1 == pid && EINTR == errno); // retry on interrupted system call if (0 != status) { if (WIFEXITED (status)) { printf ("exited, status=%d\n", WEXITSTATUS (status)); } else if (WIFSIGNALED (status)) { printf ("killed by signal %d\n", WTERMSIG (status)); } else if (WIFSTOPPED (status)) { printf ("stopped by signal %d\n", WSTOPSIG (status)); } else if (WIFCONTINUED (status)) { printf ("continued\n"); } } if (-1 == pid) { printf ("waitpid returned -1, with errno %s\n", strerror (errno)); } } else { // child setup_test_context (); // set up signal mask and install handler for SIGTERM sigset_t sigmask, sigmask_without_sigterm; sigemptyset (&sigmask); sigaddset (&sigmask, SIGTERM); sigprocmask (SIG_BLOCK, &sigmask, &sigmask_without_sigterm); struct sigaction sa; memset (&sa, '\0', sizeof (sa)); sa.sa_handler = handle_sigterm; TEST_ASSERT_SUCCESS_ERRNO (sigaction (SIGTERM, &sa, NULL)); void *socket = test_context_socket (ZMQ_REP); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (socket, my_endpoint)); zmq_pollitem_t pollitems[] = { {socket, 0, ZMQ_POLLIN, 0}, }; // first receive test message and send back handshake recv_string_expect_success (socket, "breaker breaker", 0); send_string_expect_success (socket, "one-niner", 0); // now start ppolling, which should exit with EINTR because of the SIGTERM TEST_ASSERT_FAILURE_ERRNO ( EINTR, zmq_ppoll (pollitems, 1, -1, &sigmask_without_sigterm)); TEST_ASSERT_TRUE (sigterm_received); // poll again for the final handshake TEST_ASSERT_SUCCESS_ERRNO ( zmq_ppoll (pollitems, 1, -1, &sigmask_without_sigterm)); TEST_ASSERT_BITS_HIGH (ZMQ_POLLIN, pollitems[0].revents); // receive and send back handshake recv_string_expect_success (socket, "breaker breaker", 0); send_string_expect_success (socket, "one-niner", 0); // finish // wait before closing socket, so that parent has time to receive sleep (1); test_context_socket_close (socket); teardown_test_context (); _Exit (0); } #else TEST_IGNORE_MESSAGE ("libzmq without zmq_ppoll, ignoring test"); #endif // ZMQ_HAVE_PPOLL } // We note that using zmq_poll instead of zmq_ppoll in the test above, while // also not using the sigmask, will fail most of the time, because it is // impossible to predict during which call the signal will be handled. Of // course, every call could be surrounded with an EINTR check and a subsequent // check of sigterm_received's value, but even then a race condition can occur, // see the explanation given here: https://250bpm.com/blog:12/ int main () { UNITY_BEGIN (); RUN_TEST (test_ppoll_signals); return UNITY_END (); }
6,333
C++
.cpp
147
34.503401
166
0.605519
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,290
test_pubsub_topics_count.cpp
zeromq_libzmq/tests/test_pubsub_topics_count.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include "testutil.hpp" #include "testutil_unity.hpp" #include <string.h> SETUP_TEARDOWN_TESTCONTEXT void settle_subscriptions (void *skt) { // To kick the application thread, do a dummy getsockopt - users here // should use the monitor and the other sockets in a poll. unsigned long int dummy; size_t dummy_size = sizeof (dummy); msleep (SETTLE_TIME); zmq_getsockopt (skt, ZMQ_EVENTS, &dummy, &dummy_size); } int get_subscription_count (void *skt) { int num_subs = 0; size_t num_subs_len = sizeof (num_subs); settle_subscriptions (skt); TEST_ASSERT_SUCCESS_ERRNO ( zmq_getsockopt (skt, ZMQ_TOPICS_COUNT, &num_subs, &num_subs_len)); return num_subs; } void test_independent_topic_prefixes () { // Create a publisher void *publisher = test_context_socket (ZMQ_PUB); char my_endpoint[MAX_SOCKET_STRING]; // Bind publisher test_bind (publisher, "inproc://soname", my_endpoint, MAX_SOCKET_STRING); // Create a subscriber void *subscriber = test_context_socket (ZMQ_SUB); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (subscriber, my_endpoint)); // Subscribe to 3 topics TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt ( subscriber, ZMQ_SUBSCRIBE, "topicprefix1", strlen ("topicprefix1"))); TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt ( subscriber, ZMQ_SUBSCRIBE, "topicprefix2", strlen ("topicprefix2"))); TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt ( subscriber, ZMQ_SUBSCRIBE, "topicprefix3", strlen ("topicprefix3"))); TEST_ASSERT_EQUAL_INT (get_subscription_count (subscriber), 3); TEST_ASSERT_EQUAL_INT (get_subscription_count (publisher), 3); // Remove first subscription and check subscriptions went 3 -> 2 TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt ( subscriber, ZMQ_UNSUBSCRIBE, "topicprefix3", strlen ("topicprefix3"))); TEST_ASSERT_EQUAL_INT (get_subscription_count (subscriber), 2); TEST_ASSERT_EQUAL_INT (get_subscription_count (publisher), 2); // Remove other 2 subscriptions and check we're back to 0 subscriptions TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt ( subscriber, ZMQ_UNSUBSCRIBE, "topicprefix1", strlen ("topicprefix1"))); TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt ( subscriber, ZMQ_UNSUBSCRIBE, "topicprefix2", strlen ("topicprefix2"))); TEST_ASSERT_EQUAL_INT (get_subscription_count (subscriber), 0); TEST_ASSERT_EQUAL_INT (get_subscription_count (publisher), 0); // Clean up. test_context_socket_close (publisher); test_context_socket_close (subscriber); } void test_nested_topic_prefixes () { // Create a publisher void *publisher = test_context_socket (ZMQ_PUB); char my_endpoint[MAX_SOCKET_STRING]; // Bind publisher test_bind (publisher, "inproc://soname", my_endpoint, MAX_SOCKET_STRING); // Create a subscriber void *subscriber = test_context_socket (ZMQ_SUB); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (subscriber, my_endpoint)); // Subscribe to 3 (nested) topics TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE, "a", strlen ("a"))); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE, "ab", strlen ("ab"))); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE, "abc", strlen ("abc"))); // Even if the subscriptions are nested one into the other, the number of subscriptions // received on the subscriber/publisher socket will be 3: TEST_ASSERT_EQUAL_INT (get_subscription_count (subscriber), 3); TEST_ASSERT_EQUAL_INT (get_subscription_count (publisher), 3); // Subscribe to other 3 (nested) topics TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE, "xyz", strlen ("xyz"))); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE, "xy", strlen ("xy"))); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE, "x", strlen ("x"))); TEST_ASSERT_EQUAL_INT (get_subscription_count (subscriber), 6); TEST_ASSERT_EQUAL_INT (get_subscription_count (publisher), 6); // Clean up. test_context_socket_close (publisher); test_context_socket_close (subscriber); } int main () { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_independent_topic_prefixes); RUN_TEST (test_nested_topic_prefixes); return UNITY_END (); }
4,455
C++
.cpp
100
39.85
91
0.700993
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,302
test_use_fd.cpp
zeromq_libzmq/tests/test_use_fd.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include "testutil.hpp" #include "testutil_unity.hpp" #include <stdlib.h> #include <string.h> #include <unistd.h> SETUP_TEARDOWN_TESTCONTEXT #if !defined(ZMQ_HAVE_WINDOWS) void pre_allocate_sock_tcp (void *socket_, char *my_endpoint_) { fd_t s = bind_socket_resolve_port ("127.0.0.1", "0", my_endpoint_); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (socket_, ZMQ_USE_FD, &s, sizeof (s))); } typedef void (*pre_allocate_sock_fun_t) (void *, char *); void setup_socket_pair (pre_allocate_sock_fun_t pre_allocate_sock_fun_, int bind_socket_type_, int connect_socket_type_, void **out_sb_, void **out_sc_) { *out_sb_ = test_context_socket (bind_socket_type_); char my_endpoint[MAX_SOCKET_STRING]; pre_allocate_sock_fun_ (*out_sb_, my_endpoint); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (*out_sb_, my_endpoint)); *out_sc_ = test_context_socket (connect_socket_type_); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (*out_sc_, my_endpoint)); } void test_socket_pair (pre_allocate_sock_fun_t pre_allocate_sock_fun_, int bind_socket_type_, int connect_socket_type_) { void *sb, *sc; setup_socket_pair (pre_allocate_sock_fun_, bind_socket_type_, connect_socket_type_, &sb, &sc); bounce (sb, sc); test_context_socket_close (sc); test_context_socket_close (sb); } void test_req_rep (pre_allocate_sock_fun_t pre_allocate_sock_fun_) { test_socket_pair (pre_allocate_sock_fun_, ZMQ_REP, ZMQ_REQ); } void test_pair (pre_allocate_sock_fun_t pre_allocate_sock_fun_) { test_socket_pair (pre_allocate_sock_fun_, ZMQ_PAIR, ZMQ_PAIR); } void test_client_server (pre_allocate_sock_fun_t pre_allocate_sock_fun_) { #if defined(ZMQ_SERVER) && defined(ZMQ_CLIENT) void *sb, *sc; setup_socket_pair (pre_allocate_sock_fun_, ZMQ_SERVER, ZMQ_CLIENT, &sb, &sc); zmq_msg_t msg; TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init_size (&msg, 1)); char *data = static_cast<char *> (zmq_msg_data (&msg)); data[0] = 1; int rc = zmq_msg_send (&msg, sc, ZMQ_SNDMORE); // TODO which error code is expected? TEST_ASSERT_EQUAL_INT (-1, rc); rc = zmq_msg_send (&msg, sc, 0); TEST_ASSERT_EQUAL_INT (1, rc); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg)); rc = zmq_msg_recv (&msg, sb, 0); TEST_ASSERT_EQUAL_INT (1, rc); uint32_t routing_id = zmq_msg_routing_id (&msg); TEST_ASSERT_NOT_EQUAL (0, routing_id); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg)); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init_size (&msg, 1)); data = static_cast<char *> (zmq_msg_data (&msg)); data[0] = 2; TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_set_routing_id (&msg, routing_id)); rc = zmq_msg_send (&msg, sb, ZMQ_SNDMORE); // TODO which error code is expected? TEST_ASSERT_EQUAL_INT (-1, rc); rc = zmq_msg_send (&msg, sb, 0); TEST_ASSERT_EQUAL_INT (1, rc); rc = zmq_msg_recv (&msg, sc, 0); TEST_ASSERT_EQUAL_INT (1, rc); routing_id = zmq_msg_routing_id (&msg); TEST_ASSERT_EQUAL_INT (0, routing_id); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg)); test_context_socket_close (sc); test_context_socket_close (sb); #endif } void test_req_rep_tcp () { test_req_rep (pre_allocate_sock_tcp); } void test_pair_tcp () { test_pair (pre_allocate_sock_tcp); } void test_client_server_tcp () { #if defined(ZMQ_SERVER) && defined(ZMQ_CLIENT) test_client_server (pre_allocate_sock_tcp); #endif } char ipc_endpoint[MAX_SOCKET_STRING] = ""; void pre_allocate_sock_ipc (void *sb_, char *my_endpoint_) { fd_t s = bind_socket_resolve_port ("", "", my_endpoint_, AF_UNIX, 0); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (sb_, ZMQ_USE_FD, &s, sizeof (s))); strcpy (ipc_endpoint, strchr (my_endpoint_, '/') + 2); } void test_req_rep_ipc () { test_req_rep (pre_allocate_sock_ipc); TEST_ASSERT_SUCCESS_ERRNO (unlink (ipc_endpoint)); } void test_pair_ipc () { test_pair (pre_allocate_sock_ipc); TEST_ASSERT_SUCCESS_ERRNO (unlink (ipc_endpoint)); } void test_client_server_ipc () { #if defined(ZMQ_SERVER) && defined(ZMQ_CLIENT) test_client_server (pre_allocate_sock_ipc); TEST_ASSERT_SUCCESS_ERRNO (unlink (ipc_endpoint)); #endif } int main () { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_req_rep_tcp); RUN_TEST (test_pair_tcp); RUN_TEST (test_client_server_tcp); RUN_TEST (test_req_rep_ipc); RUN_TEST (test_pair_ipc); RUN_TEST (test_client_server_ipc); return UNITY_END (); } #else int main () { return 0; } #endif
4,775
C++
.cpp
143
28.699301
75
0.641361
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
true
false
true
false
14,308
test_bind_fuzzer.cpp
zeromq_libzmq/tests/test_bind_fuzzer.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #ifdef ZMQ_USE_FUZZING_ENGINE #include <fuzzer/FuzzedDataProvider.h> #endif #include <string> #include "testutil.hpp" #include "testutil_unity.hpp" #ifndef PATH_MAX #define PATH_MAX 1024 #endif // Test that zmq_bind can handle malformed strings extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) { // This test might create socket files, so move to /tmp to avoid clobbering // the working directory with random filenames char *pwd = (char *) malloc (PATH_MAX + 1); TEST_ASSERT_NOT_NULL (pwd); TEST_ASSERT_NOT_NULL (getcwd (pwd, PATH_MAX + 1)); TEST_ASSERT_SUCCESS_ERRNO (chdir ("/tmp")); setup_test_context (); std::string my_endpoint (reinterpret_cast<const char *> (data), size); void *socket = test_context_socket (ZMQ_PUB); zmq_bind (socket, my_endpoint.c_str ()); test_context_socket_close_zero_linger (socket); teardown_test_context (); TEST_ASSERT_SUCCESS_ERRNO (chdir (pwd)); free (pwd); return 0; } #ifndef ZMQ_USE_FUZZING_ENGINE void test_bind_fuzzer () { uint8_t **data; size_t *len, num_cases = 0; if (fuzzer_corpus_encode ( "tests/libzmq-fuzz-corpora/test_bind_fuzzer_seed_corpus", &data, &len, &num_cases) != 0) exit (77); while (num_cases-- > 0) { TEST_ASSERT_SUCCESS_ERRNO ( LLVMFuzzerTestOneInput (data[num_cases], len[num_cases])); free (data[num_cases]); } free (data); free (len); } int main (int argc, char **argv) { LIBZMQ_UNUSED (argc); LIBZMQ_UNUSED (argv); setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_bind_fuzzer); return UNITY_END (); } #endif
1,736
C++
.cpp
57
26.140351
80
0.660457
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
true
false
14,310
test_connect_stream_fuzzer.cpp
zeromq_libzmq/tests/test_connect_stream_fuzzer.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #ifdef ZMQ_USE_FUZZING_ENGINE #include <fuzzer/FuzzedDataProvider.h> #endif #include "testutil.hpp" #include "testutil_unity.hpp" // Test that the ZMTP engine handles invalid handshake when connecting // https://rfc.zeromq.org/spec/37/ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) { setup_test_context (); char my_endpoint[MAX_SOCKET_STRING]; fd_t server = bind_socket_resolve_port ("127.0.0.1", "0", my_endpoint); void *client = test_context_socket (ZMQ_STREAM); // As per API by default there's no limit to the size of a message, // but the sanitizer allocator will barf over a gig or so int64_t max_msg_size = 64 * 1024 * 1024; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (client, ZMQ_MAXMSGSIZE, &max_msg_size, sizeof (int64_t))); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client, my_endpoint)); fd_t server_accept = TEST_ASSERT_SUCCESS_RAW_ERRNO (accept (server, NULL, NULL)); // If there is not enough data for a full greeting, just send what we can // Otherwise send greeting first, as expected by the protocol uint8_t buf[64]; if (size >= 64) { send (server_accept, (void *) data, 64, MSG_NOSIGNAL); data += 64; size -= 64; } recv (server_accept, buf, 64, MSG_DONTWAIT); msleep (250); for (ssize_t sent = 0; size > 0 && (sent != -1 || errno == EINTR); size -= sent > 0 ? sent : 0, data += sent > 0 ? sent : 0) sent = send (server_accept, (const char *) data, size, MSG_NOSIGNAL); msleep (250); zmq_msg_t msg; zmq_msg_init (&msg); while (-1 != zmq_msg_recv (&msg, client, ZMQ_DONTWAIT)) { zmq_msg_close (&msg); zmq_msg_init (&msg); } close (server_accept); close (server); test_context_socket_close_zero_linger (client); teardown_test_context (); return 0; } #ifndef ZMQ_USE_FUZZING_ENGINE void test_connect_null_fuzzer () { uint8_t **data; size_t *len, num_cases = 0; if (fuzzer_corpus_encode ( "tests/libzmq-fuzz-corpora/test_connect_null_fuzzer_seed_corpus", &data, &len, &num_cases) != 0) exit (77); while (num_cases-- > 0) { TEST_ASSERT_SUCCESS_ERRNO ( LLVMFuzzerTestOneInput (data[num_cases], len[num_cases])); free (data[num_cases]); } free (data); free (len); } int main (int argc, char **argv) { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_connect_null_fuzzer); return UNITY_END (); } #endif
2,593
C++
.cpp
74
29.945946
80
0.634838
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
true
false
true
false
14,311
test_xsub_verbose.cpp
zeromq_libzmq/tests/test_xsub_verbose.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include "testutil.hpp" #include "testutil_unity.hpp" SETUP_TEARDOWN_TESTCONTEXT const uint8_t unsubscribe_a_msg[] = {0, 'A'}; const uint8_t subscribe_a_msg[] = {1, 'A'}; const char test_endpoint[] = "inproc://soname"; void test_xsub_verbose_unsubscribe () { void *pub = test_context_socket (ZMQ_XPUB); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (pub, test_endpoint)); void *sub = test_context_socket (ZMQ_XSUB); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub, test_endpoint)); // set option ZMQ_XPUB_VERBOSER to get all messages int xbup_verboser = 1; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (pub, ZMQ_XPUB_VERBOSER, &xbup_verboser, sizeof (int))); // unsubscribe from topic A, does not exist yet send_array_expect_success (sub, unsubscribe_a_msg, 0); // does not exist, so it will be filtered out by XSUB TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_recv (pub, NULL, 0, ZMQ_DONTWAIT)); // subscribe to topic A send_array_expect_success (sub, subscribe_a_msg, 0); // receive subscription from subscriber recv_array_expect_success (pub, subscribe_a_msg, 0); // subscribe again to topic A send_array_expect_success (sub, subscribe_a_msg, 0); // receive subscription from subscriber recv_array_expect_success (pub, subscribe_a_msg, 0); // unsubscribe from topic A send_array_expect_success (sub, unsubscribe_a_msg, 0); // The first unsubscribe will be filtered out TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_recv (pub, NULL, 0, ZMQ_DONTWAIT)); // unsubscribe again from topic A send_array_expect_success (sub, unsubscribe_a_msg, 0); // receive unsubscription from subscriber recv_array_expect_success (pub, unsubscribe_a_msg, 0); // set option ZMQ_XSUB_VERBOSE_UNSUBSCRIBE to get duplicate unsubscribes int xsub_verbose = 1; TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt ( sub, ZMQ_XSUB_VERBOSE_UNSUBSCRIBE, &xsub_verbose, sizeof (int))); // unsubscribe from topic A, does not exist yet send_array_expect_success (sub, unsubscribe_a_msg, 0); // does not exist, but with ZMQ_XSUB_VERBOSE_UNSUBSCRIBE set it will be forwarded anyway recv_array_expect_success (pub, unsubscribe_a_msg, 0); // subscribe to topic A send_array_expect_success (sub, subscribe_a_msg, 0); // receive subscription from subscriber recv_array_expect_success (pub, subscribe_a_msg, 0); // subscribe again to topic A send_array_expect_success (sub, subscribe_a_msg, 0); // receive subscription from subscriber recv_array_expect_success (pub, subscribe_a_msg, 0); // unsubscribe from topic A send_array_expect_success (sub, unsubscribe_a_msg, 0); // receive unsubscription from subscriber recv_array_expect_success (pub, unsubscribe_a_msg, 0); // unsubscribe again from topic A send_array_expect_success (sub, unsubscribe_a_msg, 0); // receive unsubscription from subscriber recv_array_expect_success (pub, unsubscribe_a_msg, 0); // Clean up. test_context_socket_close (pub); test_context_socket_close (sub); } int main () { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_xsub_verbose_unsubscribe); return UNITY_END (); }
3,290
C++
.cpp
72
40.916667
92
0.704959
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,319
test_tcp_accept_filter.cpp
zeromq_libzmq/tests/test_tcp_accept_filter.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include "testutil.hpp" #include "testutil_unity.hpp" #include <cstring> SETUP_TEARDOWN_TESTCONTEXT void test_reconnect_ivl_against_pair_socket (const char *my_endpoint_, void *sb_) { void *sc = test_context_socket (ZMQ_PAIR); int interval = -1; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (sc, ZMQ_RECONNECT_IVL, &interval, sizeof (int))); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint_)); bounce (sb_, sc); TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (sb_, my_endpoint_)); expect_bounce_fail (sb_, sc); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb_, my_endpoint_)); expect_bounce_fail (sb_, sc); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint_)); bounce (sb_, sc); test_context_socket_close (sc); } void test_reconnect_ivl_tcp (bind_function_t bind_function_) { char my_endpoint[MAX_SOCKET_STRING]; void *sb = test_context_socket (ZMQ_PAIR); bind_function_ (sb, my_endpoint, sizeof my_endpoint); test_reconnect_ivl_against_pair_socket (my_endpoint, sb); test_context_socket_close (sb); } void test_bad_filter_string (const char *const filter_) { void *socket = test_context_socket (ZMQ_PAIR); TEST_ASSERT_FAILURE_ERRNO (EINVAL, zmq_setsockopt (socket, ZMQ_TCP_ACCEPT_FILTER, filter_, strlen (filter_))); test_context_socket_close (socket); } #define TEST_BAD_FILTER_STRING(case, filter) \ void test_bad_filter_string_##case () \ { \ test_bad_filter_string (filter); \ } TEST_BAD_FILTER_STRING (foo, "foo") TEST_BAD_FILTER_STRING (zeros_foo, "0.0.0.0foo") TEST_BAD_FILTER_STRING (zeros_foo_mask, "0.0.0.0/foo") TEST_BAD_FILTER_STRING (zeros_empty_mask, "0.0.0.0/") TEST_BAD_FILTER_STRING (zeros_negative_mask, "0.0.0.0/-1") TEST_BAD_FILTER_STRING (zeros_too_large_mask, "0.0.0.0/33") void test_clear () { void *bind_socket = test_context_socket (ZMQ_PAIR); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (bind_socket, ZMQ_TCP_ACCEPT_FILTER, NULL, 0)); #if 0 // XXX Shouldn't this work as well? const char empty_filter[] = ""; TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt ( socket, ZMQ_TCP_ACCEPT_FILTER, empty_filter, strlen (empty_filter))); #endif char endpoint[MAX_SOCKET_STRING]; bind_loopback_ipv4 (bind_socket, endpoint, sizeof (endpoint)); void *connect_socket = test_context_socket (ZMQ_PAIR); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connect_socket, endpoint)); bounce (bind_socket, connect_socket); test_context_socket_close (connect_socket); test_context_socket_close (bind_socket); } const char non_matching_filter[] = "127.0.0.255/32"; void test_set_non_matching_and_clear () { void *bind_socket = test_context_socket (ZMQ_PAIR); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (bind_socket, ZMQ_TCP_ACCEPT_FILTER, non_matching_filter, strlen (non_matching_filter))); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (bind_socket, ZMQ_TCP_ACCEPT_FILTER, NULL, 0)); char endpoint[MAX_SOCKET_STRING]; bind_loopback_ipv4 (bind_socket, endpoint, sizeof (endpoint)); void *connect_socket = test_context_socket (ZMQ_PAIR); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connect_socket, endpoint)); bounce (bind_socket, connect_socket); test_context_socket_close (connect_socket); test_context_socket_close (bind_socket); } void test_set_matching (const char *const filter_) { void *bind_socket = test_context_socket (ZMQ_PAIR); TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt ( bind_socket, ZMQ_TCP_ACCEPT_FILTER, filter_, strlen (filter_))); char endpoint[MAX_SOCKET_STRING]; bind_loopback_ipv4 (bind_socket, endpoint, sizeof (endpoint)); void *connect_socket = test_context_socket (ZMQ_PAIR); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connect_socket, endpoint)); bounce (bind_socket, connect_socket); test_context_socket_close (connect_socket); test_context_socket_close (bind_socket); } void test_set_matching_1 () { test_set_matching ("127.0.0.1/32"); } void test_set_matching_2 () { test_set_matching ("0.0.0.0/0"); } void test_set_non_matching () { void *bind_socket = test_context_socket (ZMQ_PAIR); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (bind_socket, ZMQ_TCP_ACCEPT_FILTER, non_matching_filter, strlen (non_matching_filter))); char endpoint[MAX_SOCKET_STRING]; bind_loopback_ipv4 (bind_socket, endpoint, sizeof (endpoint)); void *connect_socket = test_context_socket (ZMQ_PAIR); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (connect_socket, endpoint)); expect_bounce_fail (bind_socket, connect_socket); test_context_socket_close_zero_linger (connect_socket); test_context_socket_close_zero_linger (bind_socket); } int main () { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_bad_filter_string_foo); RUN_TEST (test_bad_filter_string_zeros_foo); RUN_TEST (test_bad_filter_string_zeros_foo_mask); RUN_TEST (test_bad_filter_string_zeros_empty_mask); RUN_TEST (test_bad_filter_string_zeros_negative_mask); RUN_TEST (test_bad_filter_string_zeros_too_large_mask); RUN_TEST (test_clear); RUN_TEST (test_set_non_matching_and_clear); RUN_TEST (test_set_matching_1); RUN_TEST (test_set_matching_2); RUN_TEST (test_set_non_matching); return UNITY_END (); }
5,752
C++
.cpp
137
36.70073
80
0.659594
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
true
false
14,325
test_msg_init.cpp
zeromq_libzmq/tests/test_msg_init.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include "testutil.hpp" #include "testutil_unity.hpp" #include <string.h> SETUP_TEARDOWN_TESTCONTEXT void test_msg_init () { zmq_msg_t msg; TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg)); TEST_ASSERT_EQUAL_INT (0, zmq_msg_size (&msg)); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg)); } void test_msg_init_size () { const char *data = "foobar"; zmq_msg_t msg; TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init_size (&msg, 6)); TEST_ASSERT_EQUAL_INT (6, zmq_msg_size (&msg)); memcpy (zmq_msg_data (&msg), data, 6); TEST_ASSERT_EQUAL_STRING_LEN (data, zmq_msg_data (&msg), 6); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg)); zmq_msg_t msg2; TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init_size (&msg2, 0)); TEST_ASSERT_EQUAL_INT (0, zmq_msg_size (&msg2)); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg2)); } void test_msg_init_buffer () { const char *data = "foobar"; zmq_msg_t msg; TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init_buffer (&msg, data, 6)); TEST_ASSERT_EQUAL_INT (6, zmq_msg_size (&msg)); TEST_ASSERT (data != zmq_msg_data (&msg)); TEST_ASSERT_EQUAL_STRING_LEN (data, zmq_msg_data (&msg), 6); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg)); zmq_msg_t msg2; TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init_buffer (&msg2, NULL, 0)); TEST_ASSERT_EQUAL_INT (0, zmq_msg_size (&msg2)); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg2)); } int main (void) { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_msg_init); RUN_TEST (test_msg_init_size); RUN_TEST (test_msg_init_buffer); return UNITY_END (); }
1,670
C++
.cpp
49
30.265306
69
0.656114
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
true
false
true
false
14,330
test_proxy_steerable.cpp
zeromq_libzmq/tests/test_proxy_steerable.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include "testutil.hpp" #include "testutil_unity.hpp" #include <stdlib.h> #include <string.h> #include <inttypes.h> #define CONTENT_SIZE 13 #define CONTENT_SIZE_MAX 32 #define ROUTING_ID_SIZE 10 #define ROUTING_ID_SIZE_MAX 32 #define QT_WORKERS 3 #define QT_CLIENTS 3 #define is_verbose 0 #define TEST_SLEEP_MS 500 const char *proxy_control_address = "inproc://proxy_control"; struct thread_data { int id; }; void *g_clients_pkts_out = NULL; void *g_workers_pkts_out = NULL; void *control_context = NULL; // worker control, not proxy control int g_proxy_control_socktype = ZMQ_PAIR; //or ZMQ_PAIR, ZMQ_SUB (without statistics) void setUp () { setup_test_context (); } // Asynchronous client-to-server (DEALER to ROUTER) - pure libzmq // // While this example runs in a single process, that is to make // it easier to start and stop the example. Each task may have its own // context and conceptually acts as a separate process. To have this // behaviour, it is necessary to replace the inproc transport of the // control socket by a tcp transport. // This is our client task // It connects to the server, and then sends a request once per second // It collects responses as they arrive, and it prints them out. We will // run several client tasks in parallel, each with a different random ID. static void client_task (void *db_) { const thread_data *const databag = static_cast<const thread_data *> (db_); // Endpoint socket gets random port to avoid test failing when port in use void *endpoint = zmq_socket (get_test_context (), ZMQ_PAIR); TEST_ASSERT_NOT_NULL (endpoint); int linger = 0; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (endpoint, ZMQ_LINGER, &linger, sizeof (linger))); char endpoint_source[256]; snprintf (endpoint_source, 256 * sizeof (char), "inproc://endpoint%d", databag->id); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (endpoint, endpoint_source)); char *my_endpoint = s_recv (endpoint); TEST_ASSERT_NOT_NULL (my_endpoint); void *client = zmq_socket (get_test_context (), ZMQ_DEALER); TEST_ASSERT_NOT_NULL (client); // Control socket receives terminate command from main over inproc void *control = zmq_socket (control_context, ZMQ_SUB); TEST_ASSERT_NOT_NULL (control); TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (control, ZMQ_SUBSCRIBE, "", 0)); linger = 0; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (control, ZMQ_LINGER, &linger, sizeof (linger))); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (control, "inproc://control")); char content[CONTENT_SIZE_MAX] = {}; // Set random routing id to make tracing easier char routing_id[ROUTING_ID_SIZE] = {}; snprintf (routing_id, ROUTING_ID_SIZE * sizeof (char), "%04X-%04X", rand () % 0xFFFF, rand () % 0xFFFF); TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt ( client, ZMQ_ROUTING_ID, routing_id, ROUTING_ID_SIZE)); // includes '\0' as an helper for printf linger = 0; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (client, ZMQ_LINGER, &linger, sizeof (linger))); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client, my_endpoint)); zmq_pollitem_t items[] = {{client, 0, ZMQ_POLLIN, 0}, {control, 0, ZMQ_POLLIN, 0}}; int request_nbr = 0; bool run = true; bool enable_send = false; while (run) { // Tick once per 200 ms, pulling in arriving messages int centitick; for (centitick = 0; centitick < 20; centitick++) { zmq_poll (items, 2, 10); if (items[0].revents & ZMQ_POLLIN) { int rcvmore; size_t sz = sizeof (rcvmore); int rc = TEST_ASSERT_SUCCESS_ERRNO ( zmq_recv (client, content, CONTENT_SIZE_MAX, 0)); TEST_ASSERT_EQUAL_INT (CONTENT_SIZE, rc); if (is_verbose) printf ( "client receive - routing_id = %s content = %s\n", routing_id, content); // Check that message is still the same TEST_ASSERT_EQUAL_STRING_LEN ("request #", content, 9); TEST_ASSERT_SUCCESS_ERRNO ( zmq_getsockopt (client, ZMQ_RCVMORE, &rcvmore, &sz)); TEST_ASSERT_FALSE (rcvmore); } if (items[1].revents & ZMQ_POLLIN) { int rc = zmq_recv (control, content, CONTENT_SIZE_MAX, 0); if (rc > 0) { content[rc] = 0; // NULL-terminate the command string if (is_verbose) printf ( "client receive - routing_id = %s command = %s\n", routing_id, content); if (memcmp (content, "TERMINATE", 9) == 0) { run = false; } else if (memcmp (content, "STOP", 4) == 0) { enable_send = false; } else if (memcmp (content, "START", 5) == 0) { enable_send = true; } break; } } } if (enable_send) { snprintf (content, CONTENT_SIZE_MAX * sizeof (char), "request #%03d", ++request_nbr); // CONTENT_SIZE if (is_verbose) printf ("client send - routing_id = %s request #%03d\n", routing_id, request_nbr); zmq_atomic_counter_inc (g_clients_pkts_out); TEST_ASSERT_EQUAL_INT (CONTENT_SIZE, zmq_send (client, content, CONTENT_SIZE, 0)); } } TEST_ASSERT_SUCCESS_ERRNO (zmq_close (client)); TEST_ASSERT_SUCCESS_ERRNO (zmq_close (control)); TEST_ASSERT_SUCCESS_ERRNO (zmq_close (endpoint)); free (my_endpoint); } // This is our server task. // It uses the multithreaded server model to deal requests out to a pool // of workers and route replies back to clients. One worker can handle // one request at a time but one client can talk to multiple workers at // once. static void server_worker (void * /*unused_*/); void server_task (void * /*unused_*/) { // Frontend socket talks to clients over TCP char my_endpoint[MAX_SOCKET_STRING]; void *frontend = zmq_socket (get_test_context (), ZMQ_ROUTER); TEST_ASSERT_NOT_NULL (frontend); int linger = 0; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (frontend, ZMQ_LINGER, &linger, sizeof (linger))); bind_loopback_ipv4 (frontend, my_endpoint, sizeof my_endpoint); // Backend socket talks to workers over inproc void *backend = zmq_socket (get_test_context (), ZMQ_DEALER); TEST_ASSERT_NOT_NULL (backend); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (backend, ZMQ_LINGER, &linger, sizeof (linger))); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (backend, "inproc://backend")); // Launch pool of worker threads, precise number is not critical int thread_nbr; void *threads[QT_WORKERS]; for (thread_nbr = 0; thread_nbr < QT_WORKERS; thread_nbr++) threads[thread_nbr] = zmq_threadstart (&server_worker, NULL); // Endpoint socket sends random port to avoid test failing when port in use void *endpoint_receivers[QT_CLIENTS]; char endpoint_source[256]; for (int i = 0; i < QT_CLIENTS; ++i) { endpoint_receivers[i] = zmq_socket (get_test_context (), ZMQ_PAIR); TEST_ASSERT_NOT_NULL (endpoint_receivers[i]); TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt ( endpoint_receivers[i], ZMQ_LINGER, &linger, sizeof (linger))); snprintf (endpoint_source, 256 * sizeof (char), "inproc://endpoint%d", i); TEST_ASSERT_SUCCESS_ERRNO ( zmq_bind (endpoint_receivers[i], endpoint_source)); } for (int i = 0; i < QT_CLIENTS; ++i) { send_string_expect_success (endpoint_receivers[i], my_endpoint, 0); } // Proxy control socket void *proxy_control = zmq_socket (get_test_context (), g_proxy_control_socktype); TEST_ASSERT_NOT_NULL (proxy_control); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (proxy_control, proxy_control_address)); if (g_proxy_control_socktype == ZMQ_SUB) { TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (proxy_control, ZMQ_SUBSCRIBE, "", 0)); } // Connect backend to frontend via a steerable proxy int rc = zmq_proxy_steerable (frontend, backend, NULL, proxy_control); TEST_ASSERT_EQUAL_INT (0, rc); for (thread_nbr = 0; thread_nbr < QT_WORKERS; thread_nbr++) { zmq_threadclose (threads[thread_nbr]); } TEST_ASSERT_SUCCESS_ERRNO (zmq_close (frontend)); TEST_ASSERT_SUCCESS_ERRNO (zmq_close (backend)); TEST_ASSERT_SUCCESS_ERRNO (zmq_close (proxy_control)); for (int i = 0; i < QT_CLIENTS; ++i) { TEST_ASSERT_SUCCESS_ERRNO (zmq_close (endpoint_receivers[i])); } } // Each worker task works on one request at a time and sends a random number // of replies back, with random delays between replies: // The comments in the first column, if suppressed, makes it a poller version static void server_worker (void * /*unused_*/) { void *worker = zmq_socket (get_test_context (), ZMQ_DEALER); TEST_ASSERT_NOT_NULL (worker); int linger = 0; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (worker, ZMQ_LINGER, &linger, sizeof (linger))); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (worker, "inproc://backend")); // Control socket receives terminate command from main over inproc void *control = zmq_socket (control_context, ZMQ_SUB); TEST_ASSERT_NOT_NULL (control); TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (control, ZMQ_SUBSCRIBE, "", 0)); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (control, ZMQ_LINGER, &linger, sizeof (linger))); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (control, "inproc://control")); char content[CONTENT_SIZE_MAX] = {}; // bigger than what we need to check that char routing_id[ROUTING_ID_SIZE_MAX] = {}; // the size received is the size sent zmq_pollitem_t items[] = {{control, 0, ZMQ_POLLIN, 0}, {worker, 0, ZMQ_POLLIN, 0}}; bool keep_sending = true; while (true) { zmq_poll (items, 2, 100); if (items[0].revents & ZMQ_POLLIN) { //Commands over the worker control socket int rc = zmq_recv (control, content, CONTENT_SIZE_MAX, 0); if (rc > 0) { content[rc] = 0; // NULL-terminate the command string if (is_verbose) printf ("server_worker receives command = %s\n", content); if (memcmp (content, "TERMINATE", 9) == 0) break; if (memcmp (content, "STOP", 4) == 0) keep_sending = false; } } if (items[1].revents & ZMQ_POLLIN) { // The DEALER socket gives us the reply envelope and message int rc = zmq_recv (worker, routing_id, ROUTING_ID_SIZE_MAX, 0); if (rc != ROUTING_ID_SIZE) { continue; } routing_id[rc] = 0; //null terminate rc = zmq_recv (worker, content, CONTENT_SIZE_MAX, 0); TEST_ASSERT_EQUAL_INT (CONTENT_SIZE, rc); content[rc] = 0; //null terminate if (is_verbose) printf ("server receive - routing_id = %s content = %s\n", routing_id, content); // Send 0..4 replies back if (keep_sending) { int reply, replies = rand () % 5; for (reply = 0; reply < replies; reply++) { // Sleep for some fraction of a second msleep (rand () % 10 + 1); // Send message from server to client if (is_verbose) printf ("server send - routing_id = %s reply\n", routing_id); zmq_atomic_counter_inc (g_workers_pkts_out); rc = zmq_send (worker, routing_id, ROUTING_ID_SIZE, ZMQ_SNDMORE); TEST_ASSERT_EQUAL_INT (ROUTING_ID_SIZE, rc); rc = zmq_send (worker, content, CONTENT_SIZE, 0); TEST_ASSERT_EQUAL_INT (CONTENT_SIZE, rc); } } } } TEST_ASSERT_SUCCESS_ERRNO (zmq_close (worker)); TEST_ASSERT_SUCCESS_ERRNO (zmq_close (control)); } // If STATISTICS is received, the proxy will reply on the control socket // sending a multipart message with 8 frames, each with an unsigned integer // 64-bit wide that provide in the following order: // // - 0/frn: number of messages received by the frontend socket // // - 1/frb: number of bytes received by the frontend socket // // - 2/fsn: number of messages sent out the frontend socket // // - 3/fsb: number of bytes sent out the frontend socket // // - 4/brn: number of messages received by the backend socket // // - 5/brb: number of bytes received by the backend socket // // - 6/bsn: number of messages sent out the backend socket // // - 7/bsb: number of bytes sent out the backend socket uint64_t read_stat_value (void *proxy_control) { zmq_msg_t stats_msg; TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&stats_msg)); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&stats_msg, proxy_control, 0)); TEST_ASSERT_EQUAL_INT (sizeof (uint64_t), zmq_msg_size (&stats_msg)); uint64_t val = *(uint64_t *) zmq_msg_data (&stats_msg); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&stats_msg)); return val; } //return total bytes proxied, so we can test PAUSE/RESUME uint64_t statistics (void *proxy_control, const char *runctx) { if (is_verbose) { printf ("steer: sending STATISTICS - %s\n", runctx); } TEST_ASSERT_SUCCESS_ERRNO (zmq_send (proxy_control, "STATISTICS", 10, 0)); uint64_t total_bytes_proxied = 0; for (int count = 0; count < 8; ++count) { uint64_t val = read_stat_value (proxy_control); if (is_verbose) { if (count == 0) { printf ("stats: client pkts out: %d worker pkts out: %d { ", zmq_atomic_counter_value (g_clients_pkts_out), zmq_atomic_counter_value (g_workers_pkts_out)); } printf ("%" PRIu64 " ", val); if (count == 7) { printf ("}\n"); } } switch (count) { case 3: //bytes sent on frontend case 7: //bytes sent on backend total_bytes_proxied += val; } } int rcvmore; size_t sz = sizeof (rcvmore); zmq_getsockopt (proxy_control, ZMQ_RCVMORE, &rcvmore, &sz); TEST_ASSERT_EQUAL_INT (rcvmore, 0); return total_bytes_proxied; } // The main thread simply starts several clients and a server, and then // waits for the server to finish. void steer (void *proxy_control, const char *command, const char *runctx) { if (is_verbose) { printf ("steer: sending %s - %s\n", command, runctx); } TEST_ASSERT_SUCCESS_ERRNO ( zmq_send (proxy_control, command, strlen (command), 0)); if (g_proxy_control_socktype == ZMQ_REP) { //expect an empty reply from REP for commands that need no response zmq_msg_t stats_msg; TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&stats_msg)); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&stats_msg, proxy_control, 0)); TEST_ASSERT_EQUAL_INT (zmq_msg_size (&stats_msg), 0); TEST_ASSERT (!zmq_msg_get (&stats_msg, ZMQ_MORE)); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&stats_msg)); } } void test_proxy_steerable () { int linger = 0; void *threads[QT_CLIENTS + 1]; g_clients_pkts_out = zmq_atomic_counter_new (); g_workers_pkts_out = zmq_atomic_counter_new (); control_context = zmq_ctx_new (); TEST_ASSERT_NOT_NULL (control_context); // Worker control socket receives terminate command from main over inproc void *control = zmq_socket (control_context, ZMQ_PUB); linger = 0; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (control, ZMQ_LINGER, &linger, sizeof (linger))); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (control, "inproc://control")); struct thread_data databags[QT_CLIENTS + 1]; for (int i = 0; i < QT_CLIENTS; i++) { databags[i].id = i; threads[i] = zmq_threadstart (&client_task, &databags[i]); } threads[QT_CLIENTS] = zmq_threadstart (&server_task, NULL); msleep (TEST_SLEEP_MS); // setup time // Proxy control socket int control_socktype = ZMQ_PAIR; switch (g_proxy_control_socktype) { case ZMQ_REP: control_socktype = ZMQ_REQ; break; case ZMQ_SUB: control_socktype = ZMQ_PUB; break; default: break; } void *proxy_control = zmq_socket (get_test_context (), control_socktype); TEST_ASSERT_NOT_NULL (proxy_control); linger = 0; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (proxy_control, ZMQ_LINGER, &linger, sizeof (linger))); TEST_ASSERT_SUCCESS_ERRNO ( zmq_connect (proxy_control, proxy_control_address)); TEST_ASSERT ( statistics (proxy_control, "should be all 0s before clients start") == 0); send_string_expect_success (control, "START", 0); msleep (TEST_SLEEP_MS); // Run for some time TEST_ASSERT (statistics (proxy_control, "started clients") > 0); steer (proxy_control, "PAUSE", "pausing proxying after 500ms"); uint64_t bytes = statistics (proxy_control, "post-pause"); msleep (TEST_SLEEP_MS); // Paused for some time //check no more bytes have been proxied while paused TEST_ASSERT (statistics (proxy_control, "post-pause") == bytes); steer (proxy_control, "RESUME", "resuming proxying after another 500ms"); msleep (TEST_SLEEP_MS); // Resumed for a while TEST_ASSERT (statistics (proxy_control, "ran for a while") > bytes); if (is_verbose) printf ("stopping all clients and server workers\n"); send_string_expect_success (control, "STOP", 0); statistics (proxy_control, "stopped clients and workers"); msleep (TEST_SLEEP_MS); // Wait for all clients and workers to STOP if (is_verbose) printf ("shutting down all clients and server workers\n"); send_string_expect_success (control, "TERMINATE", 0); msleep (TEST_SLEEP_MS); statistics (proxy_control, "terminate clients and server workers"); msleep (TEST_SLEEP_MS); // Wait for all clients and workers to terminate steer (proxy_control, "TERMINATE", "terminate proxy"); for (int i = 0; i < QT_CLIENTS + 1; i++) zmq_threadclose (threads[i]); TEST_ASSERT_SUCCESS_ERRNO (zmq_close (control)); TEST_ASSERT_SUCCESS_ERRNO (zmq_ctx_destroy (control_context)); TEST_ASSERT_SUCCESS_ERRNO (zmq_close (proxy_control)); teardown_test_context (); } int main (void) { setup_test_environment (360); UNITY_BEGIN (); RUN_TEST (test_proxy_steerable); return UNITY_END (); }
19,284
C++
.cpp
438
35.984018
80
0.614844
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,334
test_bind_null_fuzzer.cpp
zeromq_libzmq/tests/test_bind_null_fuzzer.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #ifdef ZMQ_USE_FUZZING_ENGINE #include <fuzzer/FuzzedDataProvider.h> #endif #include "testutil.hpp" #include "testutil_unity.hpp" // Test that the ZMTP engine handles invalid handshake when binding // https://rfc.zeromq.org/spec/37/ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) { setup_test_context (); char my_endpoint[MAX_SOCKET_STRING]; void *server = test_context_socket (ZMQ_PUB); // As per API by default there's no limit to the size of a message, // but the sanitizer allocator will barf over a gig or so int64_t max_msg_size = 64 * 1024 * 1024; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (server, ZMQ_MAXMSGSIZE, &max_msg_size, sizeof (int64_t))); bind_loopback_ipv4 (server, my_endpoint, sizeof (my_endpoint)); fd_t client = connect_socket (my_endpoint); void *client_good = test_context_socket (ZMQ_SUB); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (client_good, ZMQ_SUBSCRIBE, "", 0)); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client_good, my_endpoint)); // If there is not enough data for a full greeting, just send what we can // Otherwise send greeting first, as expected by the protocol uint8_t buf[64]; if (size >= 64) { send (client, (void *) data, 64, MSG_NOSIGNAL); data += 64; size -= 64; } recv (client, buf, 64, 0); msleep (250); for (ssize_t sent = 0; size > 0 && (sent != -1 || errno == EINTR); size -= sent > 0 ? sent : 0, data += sent > 0 ? sent : 0) sent = send (client, (const char *) data, size, MSG_NOSIGNAL); msleep (250); TEST_ASSERT_EQUAL_INT (6, zmq_send_const (server, "HELLO", 6, 0)); TEST_ASSERT_EQUAL_INT (6, zmq_recv (client_good, buf, 6, 0)); close (client); test_context_socket_close_zero_linger (client_good); test_context_socket_close_zero_linger (server); teardown_test_context (); return 0; } #ifndef ZMQ_USE_FUZZING_ENGINE void test_bind_null_fuzzer () { uint8_t **data; size_t *len, num_cases = 0; if (fuzzer_corpus_encode ( "tests/libzmq-fuzz-corpora/test_bind_null_fuzzer_seed_corpus", &data, &len, &num_cases) != 0) exit (77); while (num_cases-- > 0) { TEST_ASSERT_SUCCESS_ERRNO ( LLVMFuzzerTestOneInput (data[num_cases], len[num_cases])); free (data[num_cases]); } free (data); free (len); } int main (int argc, char **argv) { LIBZMQ_UNUSED (argc); LIBZMQ_UNUSED (argv); setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_bind_null_fuzzer); return UNITY_END (); } #endif
2,691
C++
.cpp
74
31.405405
80
0.643104
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
true
false
14,338
test_bind_stream_fuzzer.cpp
zeromq_libzmq/tests/test_bind_stream_fuzzer.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #ifdef ZMQ_USE_FUZZING_ENGINE #include <fuzzer/FuzzedDataProvider.h> #endif #include "testutil.hpp" #include "testutil_unity.hpp" // Test that the ZMTP engine handles invalid handshake when binding // https://rfc.zeromq.org/spec/37/ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) { setup_test_context (); char my_endpoint[MAX_SOCKET_STRING]; void *server = test_context_socket (ZMQ_STREAM); // As per API by default there's no limit to the size of a message, // but the sanitizer allocator will barf over a gig or so int64_t max_msg_size = 64 * 1024 * 1024; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (server, ZMQ_MAXMSGSIZE, &max_msg_size, sizeof (int64_t))); bind_loopback_ipv4 (server, my_endpoint, sizeof (my_endpoint)); fd_t client = connect_socket (my_endpoint); // If there is not enough data for a full greeting, just send what we can // Otherwise send greeting first, as expected by the protocol uint8_t buf[64]; if (size >= 64) { send (client, (void *) data, 64, MSG_NOSIGNAL); data += 64; size -= 64; } recv (client, buf, 64, MSG_DONTWAIT); msleep (250); for (ssize_t sent = 0; size > 0 && (sent != -1 || errno == EINTR); size -= sent > 0 ? sent : 0, data += sent > 0 ? sent : 0) sent = send (client, (const char *) data, size, MSG_NOSIGNAL); msleep (250); zmq_msg_t msg; zmq_msg_init (&msg); while (-1 != zmq_msg_recv (&msg, server, ZMQ_DONTWAIT)) { zmq_msg_close (&msg); zmq_msg_init (&msg); } void *client_good = test_context_socket (ZMQ_DEALER); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client_good, my_endpoint)); TEST_ASSERT_EQUAL_INT (6, zmq_send_const (client_good, "HELLO", 6, 0)); zmq_msg_t routing_id; TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&routing_id)); TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&routing_id, server, 0)); TEST_ASSERT_TRUE (zmq_msg_more (&routing_id)); char const *peer_address = zmq_msg_gets (&routing_id, "Peer-Address"); zmq_msg_close (&routing_id); TEST_ASSERT_NOT_NULL (peer_address); TEST_ASSERT_EQUAL_STRING ("127.0.0.1", peer_address); TEST_ASSERT_EQUAL_INT ( 0, TEST_ASSERT_SUCCESS_ERRNO (zmq_recv (server, buf, 64, 0))); zmq_msg_init (&msg); while (-1 != zmq_msg_recv (&msg, server, ZMQ_DONTWAIT)) { zmq_msg_close (&msg); zmq_msg_init (&msg); } close (client); test_context_socket_close_zero_linger (client_good); test_context_socket_close_zero_linger (server); teardown_test_context (); return 0; } #ifndef ZMQ_USE_FUZZING_ENGINE void test_bind_stream_fuzzer () { uint8_t **data; size_t *len, num_cases = 0; if (fuzzer_corpus_encode ( "tests/libzmq-fuzz-corpora/test_bind_stream_fuzzer_seed_corpus", &data, &len, &num_cases) != 0) exit (77); while (num_cases-- > 0) { TEST_ASSERT_SUCCESS_ERRNO ( LLVMFuzzerTestOneInput (data[num_cases], len[num_cases])); free (data[num_cases]); } free (data); free (len); } int main (int argc, char **argv) { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_bind_stream_fuzzer); return UNITY_END (); } #endif
3,346
C++
.cpp
90
32.022222
80
0.637149
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
true
false
true
false
14,340
test_disconnect_msg.cpp
zeromq_libzmq/tests/test_disconnect_msg.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include "testutil.hpp" #include "testutil_unity.hpp" SETUP_TEARDOWN_TESTCONTEXT void test (const char *address) { // Create a server void *server = test_context_socket (ZMQ_SERVER); // set server socket options TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (server, ZMQ_DISCONNECT_MSG, "D", 1)); // bind server TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (server, address)); // Create a client void *client = test_context_socket (ZMQ_CLIENT); TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (client, ZMQ_HELLO_MSG, "H", 1)); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client, address)); // Receive the hello message from client recv_string_expect_success (server, "H", 0); // Kill the client test_context_socket_close (client); // Receive the disconnect message recv_string_expect_success (server, "D", 0); // Clean up. test_context_socket_close (server); } void test_tcp () { test ("tcp://127.0.0.1:5569"); } void test_inproc () { test ("inproc://disconnect-msg"); } void test_inproc_disconnect () { const char *address = "inproc://disconnect-msg"; // Create a server void *server = test_context_socket (ZMQ_SERVER); // set server socket options TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (server, ZMQ_DISCONNECT_MSG, "D", 1)); // bind server TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (server, address)); // Create a client void *client = test_context_socket (ZMQ_CLIENT); TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (client, ZMQ_HELLO_MSG, "H", 1)); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client, address)); // Receive the hello message from client recv_string_expect_success (server, "H", 0); // disconnect the client TEST_ASSERT_SUCCESS_ERRNO (zmq_disconnect (client, address)); // Receive the disconnect message recv_string_expect_success (server, "D", 0); // Clean up. test_context_socket_close (client); test_context_socket_close (server); } int main () { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_tcp); RUN_TEST (test_inproc); RUN_TEST (test_inproc_disconnect); return UNITY_END (); }
2,252
C++
.cpp
67
29.328358
79
0.673762
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
true
false
true
false
14,343
test_connect_null_fuzzer.cpp
zeromq_libzmq/tests/test_connect_null_fuzzer.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #ifdef ZMQ_USE_FUZZING_ENGINE #include <fuzzer/FuzzedDataProvider.h> #endif #include "testutil.hpp" #include "testutil_unity.hpp" // Test that the ZMTP engine handles invalid handshake when connecting // https://rfc.zeromq.org/spec/37/ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) { setup_test_context (); char my_endpoint[MAX_SOCKET_STRING]; fd_t server = bind_socket_resolve_port ("127.0.0.1", "0", my_endpoint); void *client = test_context_socket (ZMQ_SUB); // As per API by default there's no limit to the size of a message, // but the sanitizer allocator will barf over a gig or so int64_t max_msg_size = 64 * 1024 * 1024; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (client, ZMQ_MAXMSGSIZE, &max_msg_size, sizeof (int64_t))); TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (client, ZMQ_SUBSCRIBE, "", 0)); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client, my_endpoint)); fd_t server_accept = TEST_ASSERT_SUCCESS_RAW_ERRNO (accept (server, NULL, NULL)); // If there is not enough data for a full greeting, just send what we can // Otherwise send greeting first, as expected by the protocol uint8_t buf[64]; if (size >= 64) { send (server_accept, (void *) data, 64, MSG_NOSIGNAL); data += 64; size -= 64; } recv (server_accept, buf, 64, 0); msleep (250); for (ssize_t sent = 0; size > 0 && (sent != -1 || errno == EINTR); size -= sent > 0 ? sent : 0, data += sent > 0 ? sent : 0) sent = send (server_accept, (const char *) data, size, MSG_NOSIGNAL); msleep (250); zmq_msg_t msg; zmq_msg_init (&msg); while (-1 != zmq_msg_recv (&msg, client, ZMQ_DONTWAIT)) { zmq_msg_close (&msg); zmq_msg_init (&msg); } close (server_accept); close (server); test_context_socket_close_zero_linger (client); teardown_test_context (); return 0; } #ifndef ZMQ_USE_FUZZING_ENGINE void test_connect_null_fuzzer () { uint8_t **data; size_t *len, num_cases = 0; if (fuzzer_corpus_encode ( "tests/libzmq-fuzz-corpora/test_connect_null_fuzzer_seed_corpus", &data, &len, &num_cases) != 0) exit (77); while (num_cases-- > 0) { TEST_ASSERT_SUCCESS_ERRNO ( LLVMFuzzerTestOneInput (data[num_cases], len[num_cases])); free (data[num_cases]); } free (data); free (len); } int main (int argc, char **argv) { LIBZMQ_UNUSED (argc); LIBZMQ_UNUSED (argv); setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_connect_null_fuzzer); return UNITY_END (); } #endif
2,711
C++
.cpp
77
30.103896
80
0.635078
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
true
false
14,344
test_xpub_topic.cpp
zeromq_libzmq/tests/test_xpub_topic.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include "testutil.hpp" #include "testutil_unity.hpp" SETUP_TEARDOWN_TESTCONTEXT const char bind_address[] = "tcp://127.0.0.1:*"; char connect_address[MAX_SOCKET_STRING]; // 245 chars + 10 chars for subscribe command = 255 chars const char short_topic[] = "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDE"; // 246 chars + 10 chars for subscribe command = 256 chars const char long_topic[] = "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEF"; template <size_t SIZE> void test_subscribe_cancel (void *xpub, void *sub, const char (&topic)[SIZE]) { // Ignore '\0' terminating the topic string. const size_t topic_len = SIZE - 1; // Subscribe for topic TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (sub, ZMQ_SUBSCRIBE, topic, topic_len)); // Allow receiving more than the expected number of bytes char buffer[topic_len + 5]; // Receive subscription int rc = TEST_ASSERT_SUCCESS_ERRNO (zmq_recv (xpub, buffer, sizeof (buffer), 0)); TEST_ASSERT_EQUAL_INT (topic_len + 1, rc); TEST_ASSERT_EQUAL_UINT8 (1, buffer[0]); TEST_ASSERT_EQUAL_UINT8_ARRAY (topic, buffer + 1, topic_len); // Unsubscribe from topic TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (sub, ZMQ_UNSUBSCRIBE, topic, topic_len)); // Receive unsubscription rc = TEST_ASSERT_SUCCESS_ERRNO (zmq_recv (xpub, buffer, sizeof (buffer), 0)); TEST_ASSERT_EQUAL_INT (topic_len + 1, rc); TEST_ASSERT_EQUAL_UINT8 (0, buffer[0]); TEST_ASSERT_EQUAL_UINT8_ARRAY (topic, buffer + 1, topic_len); } void test_xpub_subscribe_long_topic () { void *xpub = test_context_socket (ZMQ_XPUB); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (xpub, bind_address)); size_t len = MAX_SOCKET_STRING; TEST_ASSERT_SUCCESS_ERRNO ( zmq_getsockopt (xpub, ZMQ_LAST_ENDPOINT, connect_address, &len)); void *sub = test_context_socket (ZMQ_SUB); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub, connect_address)); test_subscribe_cancel (xpub, sub, short_topic); test_subscribe_cancel (xpub, sub, long_topic); // Clean up. test_context_socket_close (xpub); test_context_socket_close (sub); } int main () { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_xpub_subscribe_long_topic); return UNITY_END (); }
2,763
C++
.cpp
66
37.878788
78
0.735624
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
14,345
test_hello_msg.cpp
zeromq_libzmq/tests/test_hello_msg.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include "testutil.hpp" #include "testutil_unity.hpp" SETUP_TEARDOWN_TESTCONTEXT void test (const char *address) { // Create a router void *router = test_context_socket (ZMQ_ROUTER); char my_endpoint[MAX_SOCKET_STRING]; // set router socket options TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (router, ZMQ_HELLO_MSG, "H", 1)); // bind router test_bind (router, address, my_endpoint, MAX_SOCKET_STRING); // Create a dealer void *dealer = test_context_socket (ZMQ_DEALER); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (dealer, my_endpoint)); // Receive the hello message recv_string_expect_success (dealer, "H", 0); // Clean up. test_context_socket_close (dealer); test_context_socket_close (router); } void test_tcp () { test ("tcp://127.0.0.1:*"); } void test_inproc () { test ("inproc://hello-msg"); } void test_inproc_late_bind () { char address[] = "inproc://late-hello-msg"; // Create a server void *server = test_context_socket (ZMQ_SERVER); // set server socket options TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (server, ZMQ_HELLO_MSG, "W", 1)); // Create a dealer void *client = test_context_socket (ZMQ_CLIENT); TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (client, ZMQ_HELLO_MSG, "H", 1)); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client, address)); // bind server after the dealer TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (server, address)); // Receive the welcome message from server recv_string_expect_success (client, "W", 0); // Receive the hello message from client recv_string_expect_success (server, "H", 0); // Clean up. test_context_socket_close (client); test_context_socket_close (server); } int main () { setup_test_environment (); UNITY_BEGIN (); RUN_TEST (test_tcp); RUN_TEST (test_inproc); RUN_TEST (test_inproc_late_bind); return UNITY_END (); }
1,988
C++
.cpp
60
29.066667
79
0.671908
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
true
false
true
false
14,347
v3_1_encoder.cpp
zeromq_libzmq/src/v3_1_encoder.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include "precompiled.hpp" #include "v2_protocol.hpp" #include "v3_1_encoder.hpp" #include "msg.hpp" #include "likely.hpp" #include "wire.hpp" #include <limits.h> zmq::v3_1_encoder_t::v3_1_encoder_t (size_t bufsize_) : encoder_base_t<v3_1_encoder_t> (bufsize_) { // Write 0 bytes to the batch and go to message_ready state. next_step (NULL, 0, &v3_1_encoder_t::message_ready, true); } zmq::v3_1_encoder_t::~v3_1_encoder_t () { } void zmq::v3_1_encoder_t::message_ready () { // Encode flags. size_t size = in_progress ()->size (); size_t header_size = 2; // flags byte + size byte unsigned char &protocol_flags = _tmp_buf[0]; protocol_flags = 0; if (in_progress ()->flags () & msg_t::more) protocol_flags |= v2_protocol_t::more_flag; if (in_progress ()->flags () & msg_t::command || in_progress ()->is_subscribe () || in_progress ()->is_cancel ()) { protocol_flags |= v2_protocol_t::command_flag; if (in_progress ()->is_subscribe ()) size += zmq::msg_t::sub_cmd_name_size; else if (in_progress ()->is_cancel ()) size += zmq::msg_t::cancel_cmd_name_size; } // Calculate large_flag after command_flag. Subscribe or cancel commands // increase the message size. if (size > UCHAR_MAX) protocol_flags |= v2_protocol_t::large_flag; // Encode the message length. For messages less then 256 bytes, // the length is encoded as 8-bit unsigned integer. For larger // messages, 64-bit unsigned integer in network byte order is used. if (unlikely (size > UCHAR_MAX)) { put_uint64 (_tmp_buf + 1, size); header_size = 9; // flags byte + size 8 bytes } else { _tmp_buf[1] = static_cast<uint8_t> (size); } // Encode the sub/cancel command string. This is done in the encoder as // opposed to when the subscribe message is created to allow different // protocol behaviour on the wire in the v3.1 and legacy encoders. // It results in the work being done multiple times in case the sub // is sending the subscription/cancel to multiple pubs, but it cannot // be avoided. This processing can be moved to xsub once support for // ZMTP < 3.1 is dropped. if (in_progress ()->is_subscribe ()) { memcpy (_tmp_buf + header_size, zmq::sub_cmd_name, zmq::msg_t::sub_cmd_name_size); header_size += zmq::msg_t::sub_cmd_name_size; } else if (in_progress ()->is_cancel ()) { memcpy (_tmp_buf + header_size, zmq::cancel_cmd_name, zmq::msg_t::cancel_cmd_name_size); header_size += zmq::msg_t::cancel_cmd_name_size; } next_step (_tmp_buf, header_size, &v3_1_encoder_t::size_ready, false); } void zmq::v3_1_encoder_t::size_ready () { // Write message body into the buffer. next_step (in_progress ()->data (), in_progress ()->size (), &v3_1_encoder_t::message_ready, true); }
3,006
C++
.cpp
71
36.887324
77
0.628503
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
true
false
14,351
ws_listener.cpp
zeromq_libzmq/src/ws_listener.cpp
/* SPDX-License-Identifier: MPL-2.0 */ #include "precompiled.hpp" #include <new> #include <string> #include <stdio.h> #include "ws_listener.hpp" #include "io_thread.hpp" #include "config.hpp" #include "err.hpp" #include "ip.hpp" #include "tcp.hpp" #include "socket_base.hpp" #include "address.hpp" #include "ws_engine.hpp" #include "session_base.hpp" #ifdef ZMQ_HAVE_WSS #include "wss_engine.hpp" #include "wss_address.hpp" #endif #ifndef ZMQ_HAVE_WINDOWS #include <unistd.h> #include <sys/socket.h> #include <arpa/inet.h> #include <netinet/tcp.h> #include <netinet/in.h> #include <netdb.h> #include <fcntl.h> #ifdef ZMQ_HAVE_VXWORKS #include <sockLib.h> #endif #endif #ifdef ZMQ_HAVE_OPENVMS #include <ioctl.h> #endif zmq::ws_listener_t::ws_listener_t (io_thread_t *io_thread_, socket_base_t *socket_, const options_t &options_, bool wss_) : stream_listener_base_t (io_thread_, socket_, options_), _wss (wss_) { #ifdef ZMQ_HAVE_WSS if (_wss) { int rc = gnutls_certificate_allocate_credentials (&_tls_cred); zmq_assert (rc == GNUTLS_E_SUCCESS); gnutls_datum_t cert = {(unsigned char *) options_.wss_cert_pem.c_str (), (unsigned int) options_.wss_cert_pem.length ()}; gnutls_datum_t key = {(unsigned char *) options_.wss_key_pem.c_str (), (unsigned int) options_.wss_key_pem.length ()}; rc = gnutls_certificate_set_x509_key_mem (_tls_cred, &cert, &key, GNUTLS_X509_FMT_PEM); zmq_assert (rc == GNUTLS_E_SUCCESS); } #endif } zmq::ws_listener_t::~ws_listener_t () { #ifdef ZMQ_HAVE_WSS if (_wss) gnutls_certificate_free_credentials (_tls_cred); #endif } void zmq::ws_listener_t::in_event () { const fd_t fd = accept (); // If connection was reset by the peer in the meantime, just ignore it. // TODO: Handle specific errors like ENFILE/EMFILE etc. if (fd == retired_fd) { _socket->event_accept_failed ( make_unconnected_bind_endpoint_pair (_endpoint), zmq_errno ()); return; } int rc = tune_tcp_socket (fd); rc = rc | tune_tcp_maxrt (fd, options.tcp_maxrt); if (rc != 0) { _socket->event_accept_failed ( make_unconnected_bind_endpoint_pair (_endpoint), zmq_errno ()); return; } // Create the engine object for this connection. create_engine (fd); } std::string zmq::ws_listener_t::get_socket_name (zmq::fd_t fd_, socket_end_t socket_end_) const { std::string socket_name; #ifdef ZMQ_HAVE_WSS if (_wss) socket_name = zmq::get_socket_name<wss_address_t> (fd_, socket_end_); else #endif socket_name = zmq::get_socket_name<ws_address_t> (fd_, socket_end_); return socket_name + _address.path (); } int zmq::ws_listener_t::create_socket (const char *addr_) { tcp_address_t address; _s = tcp_open_socket (addr_, options, true, true, &address); if (_s == retired_fd) { return -1; } // TODO why is this only done for the listener? make_socket_noninheritable (_s); // Allow reusing of the address. int flag = 1; int rc; #ifdef ZMQ_HAVE_WINDOWS // TODO this was changed for Windows from SO_REUSEADDRE to // SE_EXCLUSIVEADDRUSE by 0ab65324195ad70205514d465b03d851a6de051c, // so the comment above is no longer correct; also, now the settings are // different between listener and connecter with a src address. // is this intentional? rc = setsockopt (_s, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, reinterpret_cast<const char *> (&flag), sizeof (int)); wsa_assert (rc != SOCKET_ERROR); #elif defined ZMQ_HAVE_VXWORKS rc = setsockopt (_s, SOL_SOCKET, SO_REUSEADDR, (char *) &flag, sizeof (int)); errno_assert (rc == 0); #else rc = setsockopt (_s, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof (int)); errno_assert (rc == 0); #endif // Bind the socket to the network interface and port. #if defined ZMQ_HAVE_VXWORKS rc = bind (_s, (sockaddr *) _address.addr (), _address.addrlen ()); #else rc = bind (_s, address.addr (), address.addrlen ()); #endif #ifdef ZMQ_HAVE_WINDOWS if (rc == SOCKET_ERROR) { errno = wsa_error_to_errno (WSAGetLastError ()); goto error; } #else if (rc != 0) goto error; #endif // Listen for incoming connections. rc = listen (_s, options.backlog); #ifdef ZMQ_HAVE_WINDOWS if (rc == SOCKET_ERROR) { errno = wsa_error_to_errno (WSAGetLastError ()); goto error; } #else if (rc != 0) goto error; #endif return 0; error: const int err = errno; close (); errno = err; return -1; } int zmq::ws_listener_t::set_local_address (const char *addr_) { if (options.use_fd != -1) { // in this case, the addr_ passed is not used and ignored, since the // socket was already created by the application _s = options.use_fd; } else { const int rc = _address.resolve (addr_, true, options.ipv6); if (rc != 0) return -1; // remove the path, otherwise resolving the port will fail with wildcard const char *delim = strrchr (addr_, '/'); std::string host_address; if (delim) { host_address = std::string (addr_, delim - addr_); } else { host_address = addr_; } if (create_socket (host_address.c_str ()) == -1) return -1; } _endpoint = get_socket_name (_s, socket_end_local); _socket->event_listening (make_unconnected_bind_endpoint_pair (_endpoint), _s); return 0; } zmq::fd_t zmq::ws_listener_t::accept () { // The situation where connection cannot be accepted due to insufficient // resources is considered valid and treated by ignoring the connection. // Accept one connection and deal with different failure modes. zmq_assert (_s != retired_fd); struct sockaddr_storage ss; memset (&ss, 0, sizeof (ss)); #if defined ZMQ_HAVE_HPUX || defined ZMQ_HAVE_VXWORKS int ss_len = sizeof (ss); #else socklen_t ss_len = sizeof (ss); #endif #if defined ZMQ_HAVE_SOCK_CLOEXEC && defined HAVE_ACCEPT4 fd_t sock = ::accept4 (_s, reinterpret_cast<struct sockaddr *> (&ss), &ss_len, SOCK_CLOEXEC); #else const fd_t sock = ::accept (_s, reinterpret_cast<struct sockaddr *> (&ss), &ss_len); #endif if (sock == retired_fd) { #if defined ZMQ_HAVE_WINDOWS const int last_error = WSAGetLastError (); wsa_assert (last_error == WSAEWOULDBLOCK || last_error == WSAECONNRESET || last_error == WSAEMFILE || last_error == WSAENOBUFS); #elif defined ZMQ_HAVE_ANDROID errno_assert (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR || errno == ECONNABORTED || errno == EPROTO || errno == ENOBUFS || errno == ENOMEM || errno == EMFILE || errno == ENFILE || errno == EINVAL); #else errno_assert (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR || errno == ECONNABORTED || errno == EPROTO || errno == ENOBUFS || errno == ENOMEM || errno == EMFILE || errno == ENFILE); #endif return retired_fd; } make_socket_noninheritable (sock); if (zmq::set_nosigpipe (sock)) { #ifdef ZMQ_HAVE_WINDOWS const int rc = closesocket (sock); wsa_assert (rc != SOCKET_ERROR); #else int rc = ::close (sock); errno_assert (rc == 0); #endif return retired_fd; } // Set the IP Type-Of-Service priority for this client socket if (options.tos != 0) set_ip_type_of_service (sock, options.tos); // Set the protocol-defined priority for this client socket if (options.priority != 0) set_socket_priority (sock, options.priority); return sock; } void zmq::ws_listener_t::create_engine (fd_t fd_) { const endpoint_uri_pair_t endpoint_pair ( get_socket_name (fd_, socket_end_local), get_socket_name (fd_, socket_end_remote), endpoint_type_bind); i_engine *engine = NULL; if (_wss) #ifdef ZMQ_HAVE_WSS engine = new (std::nothrow) wss_engine_t (fd_, options, endpoint_pair, _address, false, _tls_cred, std::string ()); #else zmq_assert (false); #endif else engine = new (std::nothrow) ws_engine_t (fd_, options, endpoint_pair, _address, false); alloc_assert (engine); // Choose I/O thread to run connecter in. Given that we are already // running in an I/O thread, there must be at least one available. io_thread_t *io_thread = choose_io_thread (options.affinity); zmq_assert (io_thread); // Create and launch a session object. session_base_t *session = session_base_t::create (io_thread, false, _socket, options, NULL); errno_assert (session); session->inc_seqnum (); launch_child (session); send_attach (session, engine, false); _socket->event_accepted (endpoint_pair, fd_); }
9,364
C++
.cpp
269
28.446097
81
0.608859
zeromq/libzmq
9,642
2,351
329
MPL-2.0
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
false
false
false
false
true
false
true
false