mirror of
https://github.com/D-Modem/gui.git
synced 2026-11-28 14:19:58 -08:00
Build the Windows app for Linux and macOS over clang-retro MFC's Win32 layer
First pass: TCP and SSH. With -DDMODEM_GUI_WINPORT=ON and CLANG_RETRO_MFC set to a clang-retro MFC checkout, winport/ builds libwinport.a with the MFC Makefile, converts app.rc with res2cpp.py, and links the same Win32 sources (now listed once, in windows/sources.cmake) as dmodem-win32. The layer does not have serial ports, pipes or audio yet: winport/include and winport/src/stubs.cpp supply stand-ins that fail, to remove when the layer gets these functions. DMODEM_WINPORT blocks in the app: the settings in ~/.config/D-Modem, TCP as the default line, ~/.ssh and '/' for SSH, Unicode marks in the path view (no Wingdings), and group boxes put under the other controls (the layer's hit test stops at HTTRANSPARENT). CI builds it on Linux and macOS, and on Linux starts it in Xvfb against a test modem on the TCP port (winport/test/smoke.sh). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B82eRRhKGCaYUyYtH7Boap
This commit is contained in:
21 files changed
+837
-21
No files matched your search
@@ -1,4 +1,5 @@
|
||||
# Builds and tests the three apps and the library they share
|
||||
# Builds and tests the three apps and the library they share, and the
|
||||
# Windows app for Linux and macOS (winport/)
|
||||
name: Build
|
||||
|
||||
on:
|
||||
@@ -119,6 +120,57 @@ jobs:
|
||||
name: dmodem-windows
|
||||
path: build/win7/windows/dmodem.exe
|
||||
|
||||
# The Windows app for Linux and macOS (winport/), over the portable
|
||||
# Win32 layer of clang-retro MFC. First pass: TCP and SSH only.
|
||||
winport-linux:
|
||||
name: Windows app on Linux (clang-retro MFC's Win32 layer)
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
repository: clang-retro/mfc
|
||||
path: mfc
|
||||
- name: Packages
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y --no-install-recommends \
|
||||
cmake ninja-build clang llvm libx11-dev xvfb xauth
|
||||
- name: Build
|
||||
run: |
|
||||
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo \
|
||||
-DDMODEM_GUI_LINUX=OFF -DDMODEM_GUI_WINPORT=ON -DCLANG_RETRO_MFC="$PWD/mfc" \
|
||||
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
|
||||
cmake --build build --target dmodem-win32
|
||||
- name: Smoke test (Xvfb)
|
||||
run: xvfb-run -a winport/test/smoke.sh build/winport/dmodem-win32
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: dmodem-win32-linux
|
||||
path: build/winport/dmodem-win32
|
||||
|
||||
winport-macos:
|
||||
name: Windows app on macOS (clang-retro MFC's Win32 layer)
|
||||
runs-on: macos-15
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
repository: clang-retro/mfc
|
||||
path: mfc
|
||||
- name: Packages
|
||||
run: brew install llvm
|
||||
- name: Build
|
||||
run: |
|
||||
cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo \
|
||||
-DDMODEM_GUI_WINPORT=ON -DCLANG_RETRO_MFC="$PWD/mfc" \
|
||||
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
|
||||
cmake --build build --target dmodem-win32 -j"$(sysctl -n hw.ncpu)"
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: dmodem-win32-macos
|
||||
path: build/winport/dmodem-win32
|
||||
|
||||
macos:
|
||||
name: macOS (SwiftUI)
|
||||
runs-on: macos-15
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
# Linux app (GTK 4 and libadwaita) when its libraries are there, or the
|
||||
# Windows app with clang-retro (cmake/clang-retro.cmake), MinGW or MSVC.
|
||||
# The macOS app (macos/) builds with Xcode and takes the core from here.
|
||||
# With DMODEM_GUI_WINPORT, the Windows app also builds for Linux and
|
||||
# macOS, over clang-retro MFC's portable Win32 layer (winport/).
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(dmodem-gui VERSION 1.0.0 LANGUAGES C)
|
||||
|
||||
@@ -10,6 +12,8 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
|
||||
option(DMODEM_GUI_LINUX "Build the GTK 4 app (linux/)" ON)
|
||||
option(DMODEM_GUI_SSH "Build libdmodemssh (libssh) for the Remote page" ON)
|
||||
option(DMODEM_GUI_WINPORT "Build the Windows app for Linux or macOS (winport/)" OFF)
|
||||
set(CLANG_RETRO_MFC "" CACHE PATH "A clang-retro MFC checkout, for DMODEM_GUI_WINPORT")
|
||||
|
||||
add_subdirectory(core)
|
||||
enable_testing()
|
||||
@@ -20,6 +24,8 @@ endif()
|
||||
|
||||
if(WIN32)
|
||||
add_subdirectory(windows)
|
||||
elseif(DMODEM_GUI_WINPORT)
|
||||
add_subdirectory(winport)
|
||||
endif()
|
||||
|
||||
if(DMODEM_GUI_LINUX AND UNIX AND NOT APPLE)
|
||||
|
||||
@@ -25,6 +25,7 @@ libdmodemctl. Thus they operate in the same way.
|
||||
- **Call Stats**: the rate, modulation, error control and line figures of the last call (AT#UD, ATI11)
|
||||
- **Line settings**: a SIP account, a USB modem, or a modem that already runs (dmodemd, or a hardware modem such as the MultiTech MT9234MU)
|
||||
- **Windows 95 and later**: plain Win32, built with [clang-retro](https://clang-retro.github.io/). On Windows 9x, the app connects to a modem through TCP or a COM port
|
||||
- **The Windows app on Linux and macOS** (first pass): the same Win32 code, built over the portable Win32 layer of [clang-retro MFC](https://github.com/clang-retro/mfc). At this time, it connects to a modem through TCP only, and the Phone page cannot play or record sound. Refer to "The Windows app on Linux and macOS" in [Design](docs/design.md)
|
||||
|
||||
| | Windows | macOS | Linux |
|
||||
| --- | --- | --- | --- |
|
||||
@@ -65,6 +66,13 @@ The app is in `windows/dmodem.exe` of the build directory. MSVC
|
||||
macOS: first use `cmake -S . -B build -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DCMAKE_OSX_DEPLOYMENT_TARGET=13.0 && cmake --build build`
|
||||
(this builds libssh, for SSH). Then use `brew install xcodegen && cd macos && xcodegen && open DModem.xcodeproj`.
|
||||
|
||||
The Windows app on Linux or macOS: get [clang-retro MFC](https://github.com/clang-retro/mfc),
|
||||
clang and `llvm-rc` (on macOS, `brew install llvm`). Then:
|
||||
|
||||
cmake -S . -B build -DDMODEM_GUI_WINPORT=ON -DCLANG_RETRO_MFC=/path/to/mfc \
|
||||
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
|
||||
cmake --build build --target dmodem-win32 && ./build/winport/dmodem-win32
|
||||
|
||||
The first CMake build downloads libssh and mbedTLS for SSH. This always
|
||||
occurs on Windows and macOS. Use `-DDMODEM_GUI_SSH=OFF` for a build with
|
||||
no SSH. On Linux, it occurs if the libssh of the system
|
||||
@@ -76,7 +84,7 @@ D-Modem 1.0.
|
||||
|
||||
## Documentation
|
||||
|
||||
- [Design](docs/design.md): how the apps are built, what they share, hardware modems (the MultiTech MT9234MU), and the Windows 9x notes
|
||||
- [Design](docs/design.md): how the apps are built, what they share, hardware modems (the MultiTech MT9234MU), the Windows 9x notes, and the Windows app on Linux and macOS
|
||||
- [libdmodemctl](core/include/dmodemctl.h): the API of the library
|
||||
- [Documentation style](docs/STYLE.md): the rules for ASD-STE100 Simplified Technical English
|
||||
|
||||
|
||||
@@ -328,3 +328,46 @@ Windows 95 to Windows 11:
|
||||
dmodemd itself needs Windows 7 or later. On Windows 9x and NT 4, the app
|
||||
uses a COM port by default. It can also connect to a dmodemd on another
|
||||
machine through TCP.
|
||||
|
||||
## The Windows app on Linux and macOS
|
||||
|
||||
The Windows app also builds for Linux and macOS. This is a first pass.
|
||||
clang-retro MFC has a portable Win32 layer (`port/`, `libwinport.a`). The
|
||||
layer supplies the Win32 API on X11, Wayland and Cocoa. The app links
|
||||
with this layer and not with Windows. Its source code is the same as on
|
||||
Windows.
|
||||
|
||||
- Use `-DDMODEM_GUI_WINPORT=ON` and set `CLANG_RETRO_MFC` to a checkout of
|
||||
clang-retro MFC. Use clang. `winport/CMakeLists.txt` builds
|
||||
`libwinport.a` with the Makefile of MFC. It converts `app.rc` to C++
|
||||
with `port/tools/res2cpp.py` (this needs `llvm-rc`). The app is
|
||||
`winport/dmodem-win32` in the build directory.
|
||||
- `DMODEM_WINPORT` is defined for this build. The app uses it in these
|
||||
locations only:
|
||||
- The settings file is `~/.config/D-Modem/dmodem.ini`.
|
||||
- The line is TCP by default (`127.0.0.1:2323`, a dmodemd that runs).
|
||||
The app does not start dmodemd on these systems yet.
|
||||
- SSH uses `~/.ssh` and `/` in paths.
|
||||
- The path view on the Settings page draws its pictures from Unicode
|
||||
(DejaVu Sans), because these systems do not have Wingdings.
|
||||
- The group boxes go under the other controls. The hit test of the
|
||||
layer stops at a window that answers `HTTRANSPARENT`, and does not
|
||||
try the windows under it. Windows tries them. Thus without this
|
||||
change, a click on a control in a group box goes to the page.
|
||||
- The layer does not have these functions yet. `winport/include` and
|
||||
`winport/src/stubs.cpp` supply stand-ins for them:
|
||||
|
||||
| Function | The stand-in |
|
||||
| --- | --- |
|
||||
| `waveOut*`, `waveIn*` (`mmsystem.h`), `acm*` (`msacm.h`) | Returns `MMSYSERR_NODRIVER`. The Phone page cannot play or record. |
|
||||
| `GetCommState`, `SetCommState`, `SetCommTimeouts` (COM ports) | Returns `FALSE` (`ERROR_NOT_SUPPORTED`). Do not use a COM port. |
|
||||
| `CreatePipe`, `PeekNamedPipe` | Returns `FALSE`. The app cannot start dmodemd. |
|
||||
| `GetEnvironmentStrings`, `GetUserName`, `Beep` | Uses `environ`, `$USER` and `MessageBeep`. |
|
||||
| `ListView_*`, `TabCtrl_*` (`commctrl.h`), `winsock.h` | Macros and an include of `winsock2.h`. |
|
||||
|
||||
When the layer gets these functions, remove the stand-ins (and the
|
||||
group box change). Each stand-in is in `winport/` only, or in a
|
||||
`DMODEM_WINPORT` block.
|
||||
- CI builds the app on Linux and macOS. On Linux, it starts the app in
|
||||
Xvfb with `winport/test/smoke.sh`. The test makes sure that the app
|
||||
stays up and sends AT commands to a test modem through TCP.
|
||||
+2
-13
@@ -2,19 +2,8 @@
|
||||
# cmake/clang-retro.cmake). ANSI, for the same code to build with all.
|
||||
enable_language(CXX)
|
||||
enable_language(RC)
|
||||
add_executable(dmodem WIN32
|
||||
src/main.cpp
|
||||
src/link.cpp
|
||||
src/pages.cpp
|
||||
src/term.cpp
|
||||
src/settings.cpp
|
||||
src/pathview.cpp
|
||||
src/config.cpp
|
||||
src/voice.cpp
|
||||
src/audio.cpp
|
||||
src/termview.cpp
|
||||
src/remote.cpp
|
||||
res/app.rc)
|
||||
include(sources.cmake)
|
||||
add_executable(dmodem WIN32 ${DMODEM_WIN_SOURCES} res/app.rc)
|
||||
target_include_directories(dmodem PRIVATE src)
|
||||
target_link_libraries(dmodem PRIVATE dmodemctl comctl32 wsock32 comdlg32 gdi32 winmm msacm32)
|
||||
# the Remote page's SSH: libdmodemssh (libssh, built in)
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
# The sources of the Windows app, for windows/ and winport/ (the same
|
||||
# app on Linux and macOS)
|
||||
set(DMODEM_WIN_SOURCES
|
||||
main.cpp
|
||||
link.cpp
|
||||
pages.cpp
|
||||
term.cpp
|
||||
settings.cpp
|
||||
pathview.cpp
|
||||
config.cpp
|
||||
voice.cpp
|
||||
audio.cpp
|
||||
termview.cpp
|
||||
remote.cpp)
|
||||
list(TRANSFORM DMODEM_WIN_SOURCES PREPEND "${CMAKE_CURRENT_LIST_DIR}/src/")
|
||||
@@ -44,6 +44,17 @@
|
||||
#define _strnicmp strncasecmp
|
||||
#endif
|
||||
|
||||
/* the separator of paths that libssh and the C library see: Windows', or
|
||||
POSIX on Linux and macOS (winport/); and the name of the folder that
|
||||
holds .ssh */
|
||||
#ifdef DMODEM_WINPORT
|
||||
#define DIR_SEP "/"
|
||||
#define PROFILE_NAME "home folder"
|
||||
#else
|
||||
#define DIR_SEP "\\"
|
||||
#define PROFILE_NAME "profile"
|
||||
#endif
|
||||
|
||||
/* (older headers, Open Watcom's among them, without the 64-bit names) */
|
||||
#ifndef GWLP_USERDATA
|
||||
#define GWLP_USERDATA GWL_USERDATA
|
||||
|
||||
@@ -21,6 +21,19 @@
|
||||
void app_data_dir(char *out, int n)
|
||||
{
|
||||
char dir[MAX_PATH];
|
||||
#ifdef DMODEM_WINPORT
|
||||
/* (Linux and macOS, winport/: ~/.config/D-Modem) */
|
||||
const char *home = getenv("HOME");
|
||||
if (home && strlen(home) < sizeof(dir) - 20) {
|
||||
_snprintf(dir, sizeof(dir), "%s/.config", home);
|
||||
CreateDirectory(dir, NULL);
|
||||
strcat(dir, "/D-Modem");
|
||||
CreateDirectory(dir, NULL);
|
||||
_snprintf(out, n, "%s", dir);
|
||||
out[n - 1] = '\0';
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
DWORD k = GetEnvironmentVariable("APPDATA", dir, sizeof(dir));
|
||||
if (k > 0 && k < sizeof(dir) - 10) {
|
||||
strcat(dir, "\\D-Modem");
|
||||
@@ -78,7 +91,14 @@ void config_load(Config *c)
|
||||
v.dwOSVersionInfoSize = sizeof(v);
|
||||
GetVersionEx(&v);
|
||||
bool old = v.dwPlatformId != VER_PLATFORM_WIN32_NT || v.dwMajorVersion < 6;
|
||||
#ifdef DMODEM_WINPORT
|
||||
/* (Linux and macOS, winport/: no COM ports or dmodemd started by the
|
||||
app yet, so a dmodemd that runs, through TCP) */
|
||||
(void)old;
|
||||
c->line = get_i(ini, "line", LINE_TCP);
|
||||
#else
|
||||
c->line = get_i(ini, "line", old ? LINE_COM : LINE_DMODEMD);
|
||||
#endif
|
||||
get(ini, "sip-user", "", c->sip_user, sizeof(c->sip_user));
|
||||
get(ini, "sip-password", "", c->sip_password, sizeof(c->sip_password));
|
||||
get(ini, "sip-server", "", c->sip_server, sizeof(c->sip_server));
|
||||
|
||||
@@ -173,6 +173,23 @@ void app_event(const dmc_event *ev)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DMODEM_WINPORT
|
||||
/* (Linux and macOS, winport/: the layer's hit test stops at a group box,
|
||||
which answers HTTRANSPARENT, and does not try the controls under it.
|
||||
Windows tries them. Until the layer does too, put the group boxes
|
||||
under the other controls.) */
|
||||
static BOOL CALLBACK lower_group_box(HWND c, LPARAM lp)
|
||||
{
|
||||
char cls[16];
|
||||
(void)lp;
|
||||
if (GetClassName(c, cls, sizeof(cls)) && !lstrcmpi(cls, "BUTTON") &&
|
||||
(GetWindowLong(c, GWL_STYLE) & BS_TYPEMASK) == BS_GROUPBOX)
|
||||
SetWindowPos(c, HWND_BOTTOM, 0, 0, 0, 0,
|
||||
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void show_page(int i)
|
||||
{
|
||||
for (int p = 0; p < PAGES; p++)
|
||||
@@ -245,6 +262,10 @@ static LRESULT CALLBACK main_proc(HWND w, UINT m, WPARAM wp, LPARAM lp)
|
||||
for (int p = 0; p < PAGES; p++)
|
||||
SetWindowPos(app.pages[p], HWND_TOP, 0, 0, 0, 0,
|
||||
SWP_NOMOVE | SWP_NOSIZE);
|
||||
#ifdef DMODEM_WINPORT
|
||||
for (int p = 0; p < PAGES; p++)
|
||||
EnumChildWindows(app.pages[p], lower_group_box, 0);
|
||||
#endif
|
||||
show_page(PAGE_MODEM);
|
||||
SetTimer(w, TIMER_PUMP, 50, NULL);
|
||||
app_state();
|
||||
|
||||
@@ -53,6 +53,21 @@ static const char *mark(int kind, bool *wingdings)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DMODEM_WINPORT
|
||||
/* (Linux and macOS, winport/: no Wingdings there; the same pictures from
|
||||
Unicode, in a font that the system has) */
|
||||
static const wchar_t *mark_w(const char *m)
|
||||
{
|
||||
switch (m[0]) {
|
||||
case ':': return L"\x2328"; /* a keyboard */
|
||||
case ';': return L"\x25A3"; /* a box */
|
||||
case ')': return L"\x260E"; /* a telephone */
|
||||
case '*': return L"\x2709"; /* an envelope */
|
||||
default: return L"\x260F"; /* a telephone, white */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void line(HDC dc, int st, int x0, int x1, int y)
|
||||
{
|
||||
bool dashed = st == DMC_STEP_SETUP || st == DMC_STEP_OFF;
|
||||
@@ -118,6 +133,12 @@ static void paint(HWND w)
|
||||
RECT g = { cx - r, cy - r, cx + r, cy + r };
|
||||
SelectObject(dc, wd ? glyph_font : app.font);
|
||||
SetTextColor(dc, state_color(st));
|
||||
#ifdef DMODEM_WINPORT
|
||||
if (wd)
|
||||
DrawTextW(dc, mark_w(m), -1, &g, DT_CENTER | DT_VCENTER |
|
||||
DT_SINGLELINE | DT_NOPREFIX);
|
||||
else
|
||||
#endif
|
||||
DrawText(dc, m, -1, &g, DT_CENTER | DT_VCENTER | DT_SINGLELINE |
|
||||
DT_NOPREFIX);
|
||||
RECT tt = { x, cy + r + 4, x + cw, cy + r + 4 + th };
|
||||
@@ -164,8 +185,12 @@ HWND pathview_new(HWND parent)
|
||||
LOGFONT lf;
|
||||
memset(&lf, 0, sizeof(lf));
|
||||
lf.lfHeight = -20;
|
||||
#ifdef DMODEM_WINPORT
|
||||
strcpy(lf.lfFaceName, "DejaVu Sans");
|
||||
#else
|
||||
lf.lfCharSet = SYMBOL_CHARSET;
|
||||
strcpy(lf.lfFaceName, "Wingdings");
|
||||
#endif
|
||||
glyph_font = CreateFontIndirect(&lf);
|
||||
}
|
||||
path = dmc_path_new();
|
||||
|
||||
+13
-6
@@ -617,7 +617,8 @@ static void ssh_hostkey(const char *key, int known)
|
||||
_snprintf(m, sizeof(m),
|
||||
"\r\n\x1b[1;31mThe server's host key has changed (it is now %.*s %s).\r\n"
|
||||
"Someone may be in the middle; or the server has a new key. If that is\r\n"
|
||||
"expected, remove its old line from .ssh\\known_hosts in your profile.\x1b[0m\r\n",
|
||||
"expected, remove its old line from .ssh" DIR_SEP "known_hosts in your "
|
||||
PROFILE_NAME ".\x1b[0m\r\n",
|
||||
tl, key, fp);
|
||||
m[sizeof(m) - 1] = '\0';
|
||||
show_line(m);
|
||||
@@ -627,7 +628,7 @@ static void ssh_hostkey(const char *key, int known)
|
||||
Ssh *c = ssh;
|
||||
_snprintf(m, sizeof(m), "This server is not known yet. Its key's fingerprint is\n\n"
|
||||
"%.*s %s\n\nIf it's the one you expect, it will be added to "
|
||||
".ssh\\known_hosts in your profile.\n\nConnect?", tl, key, fp);
|
||||
".ssh" DIR_SEP "known_hosts in your " PROFILE_NAME ".\n\nConnect?", tl, key, fp);
|
||||
m[sizeof(m) - 1] = '\0';
|
||||
int r = MessageBox(app.main, m, "Connect to a new server?",
|
||||
MB_YESNO | MB_ICONQUESTION);
|
||||
@@ -886,8 +887,14 @@ static bool start_ssh(const char *host, int port, const char *user)
|
||||
/* the profile's .ssh folder (made if it isn't there) into out */
|
||||
static void ssh_dir(char *out, int n)
|
||||
{
|
||||
#ifdef DMODEM_WINPORT
|
||||
/* (Linux and macOS, winport/: OpenSSH's own ~/.ssh, as a POSIX path
|
||||
for libssh) */
|
||||
const char *home = getenv("HOME");
|
||||
#else
|
||||
const char *home = getenv("USERPROFILE");
|
||||
_snprintf(out, n, "%s\\.ssh", home ? home : ".");
|
||||
#endif
|
||||
_snprintf(out, n, "%s" DIR_SEP ".ssh", home ? home : ".");
|
||||
out[n - 1] = '\0';
|
||||
CreateDirectory(out, NULL);
|
||||
}
|
||||
@@ -958,7 +965,7 @@ static bool import_ppk(HWND d, const char *ppk, char *out, int n)
|
||||
/* (.ssh\<its name>, a name not yet taken) */
|
||||
char dir[MAX_PATH], base[MAX_PATH], path[MAX_PATH], pubpath[MAX_PATH + 8];
|
||||
ssh_dir(dir, sizeof(dir));
|
||||
const char *slash = strrchr(ppk, '\\');
|
||||
const char *slash = strrchr(ppk, DIR_SEP[0]);
|
||||
lstrcpyn(base, slash ? slash + 1 : ppk, sizeof(base));
|
||||
char *dot = strrchr(base, '.');
|
||||
if (dot && !lstrcmpi(dot, ".ppk"))
|
||||
@@ -967,9 +974,9 @@ static bool import_ppk(HWND d, const char *ppk, char *out, int n)
|
||||
lstrcpy(base, "putty-key");
|
||||
for (int i = 1; i < 100; i++) {
|
||||
if (i == 1)
|
||||
_snprintf(path, sizeof(path), "%s\\%s", dir, base);
|
||||
_snprintf(path, sizeof(path), "%s" DIR_SEP "%s", dir, base);
|
||||
else
|
||||
_snprintf(path, sizeof(path), "%s\\%s-%d", dir, base, i);
|
||||
_snprintf(path, sizeof(path), "%s" DIR_SEP "%s-%d", dir, base, i);
|
||||
path[sizeof(path) - 1] = '\0';
|
||||
_snprintf(pubpath, sizeof(pubpath), "%s.pub", path);
|
||||
pubpath[sizeof(pubpath) - 1] = '\0';
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
# The Windows app (windows/) for Linux and macOS, over the portable Win32
|
||||
# layer of clang-retro MFC (libwinport, in port/ of that project).
|
||||
#
|
||||
# cmake -B build -DDMODEM_GUI_WINPORT=ON -DCLANG_RETRO_MFC=/path/to/mfc \
|
||||
# -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
|
||||
#
|
||||
# This is a first pass. The layer does not have serial ports, pipes or
|
||||
# audio (waveOut, waveIn and ACM) yet. The files in include/ and
|
||||
# src/stubs.cpp supply stand-ins: these functions fail, so the app uses
|
||||
# the TCP and SSH links only. When the layer gets these functions,
|
||||
# remove the stand-ins.
|
||||
enable_language(CXX)
|
||||
|
||||
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
message(FATAL_ERROR "DMODEM_GUI_WINPORT: use clang++ (libwinport is built with clang)")
|
||||
endif()
|
||||
if(NOT CLANG_RETRO_MFC OR NOT EXISTS "${CLANG_RETRO_MFC}/port/include/windows.h")
|
||||
message(FATAL_ERROR "DMODEM_GUI_WINPORT: set CLANG_RETRO_MFC to a clang-retro MFC checkout")
|
||||
endif()
|
||||
find_package(Python3 REQUIRED COMPONENTS Interpreter)
|
||||
# (Homebrew's LLVM has llvm-rc; Xcode does not)
|
||||
find_program(DMODEM_LLVM_RC NAMES llvm-rc llvm-rc-20 llvm-rc-19 llvm-rc-18
|
||||
HINTS /opt/homebrew/opt/llvm/bin /usr/local/opt/llvm/bin REQUIRED)
|
||||
|
||||
# The target triple of the layer's Makefile
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)$")
|
||||
set(_arch_linux aarch64)
|
||||
set(_arch_apple arm64)
|
||||
else()
|
||||
set(_arch_linux x86_64)
|
||||
set(_arch_apple x86_64)
|
||||
endif()
|
||||
if(APPLE)
|
||||
set(WINPORT_TARGET "${_arch_apple}-apple-macos11")
|
||||
else()
|
||||
set(WINPORT_TARGET "${_arch_linux}-linux-gnu")
|
||||
endif()
|
||||
|
||||
# libwinport.a, built by the MFC Makefile into our build directory
|
||||
set(WINPORT_OUT "${CMAKE_CURRENT_BINARY_DIR}/mfc")
|
||||
set(WINPORT_LIB "${WINPORT_OUT}/libwinport.a")
|
||||
file(GLOB _winport_deps CONFIGURE_DEPENDS
|
||||
"${CLANG_RETRO_MFC}/port/src/*" "${CLANG_RETRO_MFC}/port/include/*.h")
|
||||
include(ProcessorCount)
|
||||
ProcessorCount(_ncpu)
|
||||
if(_ncpu EQUAL 0)
|
||||
set(_ncpu 1)
|
||||
endif()
|
||||
add_custom_command(OUTPUT "${WINPORT_LIB}"
|
||||
COMMAND make -C "${CLANG_RETRO_MFC}" -j${_ncpu}
|
||||
TARGET=${WINPORT_TARGET} STDLIB= OUT=${WINPORT_OUT}
|
||||
CXX=${CMAKE_CXX_COMPILER} AR=${CMAKE_AR} "${WINPORT_LIB}"
|
||||
DEPENDS ${_winport_deps}
|
||||
COMMENT "Building libwinport.a (${WINPORT_TARGET})"
|
||||
VERBATIM)
|
||||
add_custom_target(winport_lib DEPENDS "${WINPORT_LIB}")
|
||||
add_library(winport STATIC IMPORTED GLOBAL)
|
||||
set_target_properties(winport PROPERTIES IMPORTED_LOCATION "${WINPORT_LIB}")
|
||||
add_dependencies(winport winport_lib)
|
||||
|
||||
# The resources: app.rc as C++ (res2cpp.py compiles it with llvm-rc)
|
||||
set(_win "${PROJECT_SOURCE_DIR}/windows")
|
||||
set(APP_RES_CPP "${CMAKE_CURRENT_BINARY_DIR}/app-res.cpp")
|
||||
add_custom_command(OUTPUT "${APP_RES_CPP}"
|
||||
COMMAND ${CMAKE_COMMAND} -E env RC=${DMODEM_LLVM_RC} CXX=${CMAKE_CXX_COMPILER}
|
||||
${Python3_EXECUTABLE} "${CLANG_RETRO_MFC}/port/tools/res2cpp.py"
|
||||
-I "${_win}/src" -I "${_win}/res" "${_win}/res/app.rc" -o "${APP_RES_CPP}"
|
||||
DEPENDS "${_win}/res/app.rc" "${_win}/res/app.manifest" "${_win}/res/dmodem.ico"
|
||||
"${_win}/src/resource.h"
|
||||
COMMENT "Converting app.rc to C++"
|
||||
VERBATIM)
|
||||
|
||||
include("${_win}/sources.cmake")
|
||||
add_executable(dmodem-win32
|
||||
${DMODEM_WIN_SOURCES}
|
||||
src/stubs.cpp
|
||||
"${APP_RES_CPP}")
|
||||
set_target_properties(dmodem-win32 PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
|
||||
# Our stand-in headers come first, then the layer's headers.
|
||||
target_include_directories(dmodem-win32 BEFORE PRIVATE
|
||||
include "${CLANG_RETRO_MFC}/port/include" "${_win}/src" "${_win}/res")
|
||||
target_compile_definitions(dmodem-win32 PRIVATE DMODEM_WINPORT)
|
||||
target_compile_options(dmodem-win32 PRIVATE -Wall -Wno-unused-parameter)
|
||||
target_link_libraries(dmodem-win32 PRIVATE dmodemctl winport)
|
||||
if(TARGET dmodemssh)
|
||||
target_link_libraries(dmodem-win32 PRIVATE dmodemssh)
|
||||
target_compile_definitions(dmodem-win32 PRIVATE DMODEM_HAVE_SSH)
|
||||
endif()
|
||||
if(APPLE)
|
||||
target_link_libraries(dmodem-win32 PRIVATE "-framework Cocoa" pthread)
|
||||
else()
|
||||
target_link_libraries(dmodem-win32 PRIVATE dl pthread)
|
||||
endif()
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright (C) 2026 D-Modem Authors
|
||||
*
|
||||
* commctrl.h - the common controls of the Win32 layer (clang-retro MFC's
|
||||
* port/), with the helper macros of the SDK that the app
|
||||
* uses and the layer does not have yet. (<objidl.h> first:
|
||||
* the layer's commctrl.h needs LPSTREAM, which its
|
||||
* <windows.h> gives only without WIN32_LEAN_AND_MEAN.)
|
||||
*/
|
||||
#ifndef DMODEM_WINPORT_COMMCTRL_H
|
||||
#define DMODEM_WINPORT_COMMCTRL_H
|
||||
#include <windows.h>
|
||||
#include <objidl.h>
|
||||
#include_next <commctrl.h>
|
||||
|
||||
#ifndef ListView_InsertColumn
|
||||
#define ListView_InsertColumn(w, i, c) \
|
||||
(int)SendMessage((w), LVM_INSERTCOLUMN, (WPARAM)(int)(i), (LPARAM)(c))
|
||||
#endif
|
||||
#ifndef ListView_InsertItem
|
||||
#define ListView_InsertItem(w, item) \
|
||||
(int)SendMessage((w), LVM_INSERTITEM, 0, (LPARAM)(item))
|
||||
#endif
|
||||
#ifndef ListView_GetItem
|
||||
#define ListView_GetItem(w, item) \
|
||||
(BOOL)SendMessage((w), LVM_GETITEM, 0, (LPARAM)(item))
|
||||
#endif
|
||||
#ifndef ListView_DeleteAllItems
|
||||
#define ListView_DeleteAllItems(w) \
|
||||
(BOOL)SendMessage((w), LVM_DELETEALLITEMS, 0, 0)
|
||||
#endif
|
||||
#ifndef ListView_GetNextItem
|
||||
#define ListView_GetNextItem(w, i, flags) \
|
||||
(int)SendMessage((w), LVM_GETNEXTITEM, (WPARAM)(int)(i), \
|
||||
MAKELPARAM((flags), 0))
|
||||
#endif
|
||||
#ifndef ListView_SetExtendedListViewStyle
|
||||
#define ListView_SetExtendedListViewStyle(w, ex) \
|
||||
(DWORD)SendMessage((w), LVM_SETEXTENDEDLISTVIEWSTYLE, 0, (LPARAM)(ex))
|
||||
#endif
|
||||
#ifndef ListView_SetItemText
|
||||
#define ListView_SetItemText(w, i, sub, text) \
|
||||
do { \
|
||||
LV_ITEM lvi_; \
|
||||
lvi_.iSubItem = (sub); \
|
||||
lvi_.pszText = (text); \
|
||||
SendMessage((w), LVM_SETITEMTEXT, (WPARAM)(i), \
|
||||
(LPARAM)&lvi_); \
|
||||
} while (0)
|
||||
#endif
|
||||
#ifndef TabCtrl_InsertItem
|
||||
#define TabCtrl_InsertItem(w, i, item) \
|
||||
(int)SendMessage((w), TCM_INSERTITEM, (WPARAM)(int)(i), (LPARAM)(item))
|
||||
#endif
|
||||
#ifndef TabCtrl_GetCurSel
|
||||
#define TabCtrl_GetCurSel(w) (int)SendMessage((w), TCM_GETCURSEL, 0, 0)
|
||||
#endif
|
||||
#ifndef TabCtrl_AdjustRect
|
||||
#define TabCtrl_AdjustRect(w, larger, rc) \
|
||||
(void)SendMessage((w), TCM_ADJUSTRECT, (WPARAM)(BOOL)(larger), (LPARAM)(rc))
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright (C) 2026 D-Modem Authors
|
||||
*
|
||||
* mmreg.h - the MP3 format of the ACM, as the app's audio.cpp names it
|
||||
*/
|
||||
#ifndef DMODEM_WINPORT_MMREG_H
|
||||
#define DMODEM_WINPORT_MMREG_H
|
||||
#include <mmsystem.h>
|
||||
|
||||
#define WAVE_FORMAT_MPEGLAYER3 0x0055
|
||||
#define MPEGLAYER3_WFX_EXTRA_BYTES 12
|
||||
#define MPEGLAYER3_ID_MPEG 1
|
||||
#define MPEGLAYER3_FLAG_PADDING_OFF 0x00000002
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct mpeglayer3waveformat_tag {
|
||||
WAVEFORMATEX wfx;
|
||||
WORD wID;
|
||||
DWORD fdwFlags;
|
||||
WORD nBlockSize;
|
||||
WORD nFramesPerBlock;
|
||||
WORD nCodecDelay;
|
||||
} MPEGLAYER3WAVEFORMAT, *LPMPEGLAYER3WAVEFORMAT;
|
||||
#pragma pack(pop)
|
||||
#endif
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright (C) 2026 D-Modem Authors
|
||||
*
|
||||
* mmsystem.h - the part of the multimedia API that the app's sound
|
||||
* (audio.cpp, voice.cpp) uses, which the Win32 layer does not
|
||||
* have. First pass: the functions are in src/stubs.cpp and
|
||||
* answer MMSYSERR_NODRIVER (no sound device).
|
||||
*/
|
||||
#ifndef DMODEM_WINPORT_MMSYSTEM_H
|
||||
#define DMODEM_WINPORT_MMSYSTEM_H
|
||||
#include <windows.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef UINT MMRESULT;
|
||||
typedef struct dmodem_hwaveout *HWAVEOUT;
|
||||
typedef struct dmodem_hwavein *HWAVEIN;
|
||||
|
||||
#define MMSYSERR_NOERROR 0
|
||||
#define MMSYSERR_ERROR 1
|
||||
#define MMSYSERR_BADDEVICEID 2
|
||||
#define MMSYSERR_NODRIVER 6
|
||||
#define WAVE_MAPPER ((UINT)-1)
|
||||
#define CALLBACK_WINDOW 0x00010000L
|
||||
#define MM_WOM_DONE 0x3BD
|
||||
#define MM_WIM_DATA 0x3C0
|
||||
#define WHDR_DONE 0x00000001
|
||||
#define WHDR_PREPARED 0x00000002
|
||||
#define WAVE_FORMAT_PCM 1
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct tWAVEFORMATEX {
|
||||
WORD wFormatTag;
|
||||
WORD nChannels;
|
||||
DWORD nSamplesPerSec;
|
||||
DWORD nAvgBytesPerSec;
|
||||
WORD nBlockAlign;
|
||||
WORD wBitsPerSample;
|
||||
WORD cbSize;
|
||||
} WAVEFORMATEX, *PWAVEFORMATEX, *LPWAVEFORMATEX;
|
||||
#pragma pack(pop)
|
||||
typedef const WAVEFORMATEX *LPCWAVEFORMATEX;
|
||||
|
||||
typedef struct wavehdr_tag {
|
||||
LPSTR lpData;
|
||||
DWORD dwBufferLength;
|
||||
DWORD dwBytesRecorded;
|
||||
DWORD_PTR dwUser;
|
||||
DWORD dwFlags;
|
||||
DWORD dwLoops;
|
||||
struct wavehdr_tag *lpNext;
|
||||
DWORD_PTR reserved;
|
||||
} WAVEHDR, *PWAVEHDR, *LPWAVEHDR;
|
||||
|
||||
MMRESULT WINAPI waveOutOpen(HWAVEOUT *, UINT, LPCWAVEFORMATEX, DWORD_PTR,
|
||||
DWORD_PTR, DWORD);
|
||||
MMRESULT WINAPI waveOutClose(HWAVEOUT);
|
||||
MMRESULT WINAPI waveOutPrepareHeader(HWAVEOUT, LPWAVEHDR, UINT);
|
||||
MMRESULT WINAPI waveOutUnprepareHeader(HWAVEOUT, LPWAVEHDR, UINT);
|
||||
MMRESULT WINAPI waveOutWrite(HWAVEOUT, LPWAVEHDR, UINT);
|
||||
MMRESULT WINAPI waveOutReset(HWAVEOUT);
|
||||
MMRESULT WINAPI waveInOpen(HWAVEIN *, UINT, LPCWAVEFORMATEX, DWORD_PTR,
|
||||
DWORD_PTR, DWORD);
|
||||
MMRESULT WINAPI waveInClose(HWAVEIN);
|
||||
MMRESULT WINAPI waveInPrepareHeader(HWAVEIN, LPWAVEHDR, UINT);
|
||||
MMRESULT WINAPI waveInUnprepareHeader(HWAVEIN, LPWAVEHDR, UINT);
|
||||
MMRESULT WINAPI waveInAddBuffer(HWAVEIN, LPWAVEHDR, UINT);
|
||||
MMRESULT WINAPI waveInStart(HWAVEIN);
|
||||
MMRESULT WINAPI waveInReset(HWAVEIN);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright (C) 2026 D-Modem Authors
|
||||
*
|
||||
* msacm.h - the Audio Compression Manager calls that the app's audio.cpp
|
||||
* uses (greetings in MP3 and compressed WAVs). First pass: the
|
||||
* functions are in src/stubs.cpp and answer MMSYSERR_NODRIVER,
|
||||
* so the app reads only the files that libdmodemctl decodes.
|
||||
*/
|
||||
#ifndef DMODEM_WINPORT_MSACM_H
|
||||
#define DMODEM_WINPORT_MSACM_H
|
||||
#include <mmsystem.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct dmodem_hacmstream *HACMSTREAM;
|
||||
typedef HACMSTREAM *LPHACMSTREAM;
|
||||
typedef struct dmodem_hacmdriver *HACMDRIVER;
|
||||
|
||||
#define ACM_FORMATSUGGESTF_WFORMATTAG 0x00010000L
|
||||
#define ACM_FORMATSUGGESTF_NCHANNELS 0x00020000L
|
||||
#define ACM_FORMATSUGGESTF_NSAMPLESPERSEC 0x00040000L
|
||||
#define ACM_FORMATSUGGESTF_WBITSPERSAMPLE 0x00080000L
|
||||
#define ACM_STREAMOPENF_NONREALTIME 0x00000004L
|
||||
#define ACM_STREAMSIZEF_SOURCE 0x00000000L
|
||||
#define ACM_STREAMCONVERTF_BLOCKALIGN 0x00000004
|
||||
#define ACM_STREAMCONVERTF_START 0x00000010
|
||||
#define ACM_STREAMCONVERTF_END 0x00000020
|
||||
|
||||
typedef struct tACMSTREAMHEADER {
|
||||
DWORD cbStruct;
|
||||
DWORD fdwStatus;
|
||||
DWORD_PTR dwUser;
|
||||
LPBYTE pbSrc;
|
||||
DWORD cbSrcLength;
|
||||
DWORD cbSrcLengthUsed;
|
||||
DWORD_PTR dwSrcUser;
|
||||
LPBYTE pbDst;
|
||||
DWORD cbDstLength;
|
||||
DWORD cbDstLengthUsed;
|
||||
DWORD_PTR dwDstUser;
|
||||
DWORD dwReservedDriver[10];
|
||||
} ACMSTREAMHEADER, *LPACMSTREAMHEADER;
|
||||
|
||||
MMRESULT WINAPI acmFormatSuggest(HACMDRIVER, LPWAVEFORMATEX, LPWAVEFORMATEX,
|
||||
DWORD, DWORD);
|
||||
MMRESULT WINAPI acmStreamOpen(LPHACMSTREAM, HACMDRIVER, LPWAVEFORMATEX,
|
||||
LPWAVEFORMATEX, LPVOID, DWORD_PTR, DWORD_PTR,
|
||||
DWORD);
|
||||
MMRESULT WINAPI acmStreamClose(HACMSTREAM, DWORD);
|
||||
MMRESULT WINAPI acmStreamSize(HACMSTREAM, DWORD, LPDWORD, DWORD);
|
||||
MMRESULT WINAPI acmStreamPrepareHeader(HACMSTREAM, LPACMSTREAMHEADER, DWORD);
|
||||
MMRESULT WINAPI acmStreamUnprepareHeader(HACMSTREAM, LPACMSTREAMHEADER,
|
||||
DWORD);
|
||||
MMRESULT WINAPI acmStreamConvert(HACMSTREAM, LPACMSTREAMHEADER, DWORD);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright (C) 2026 D-Modem Authors
|
||||
*
|
||||
* windows.h - the Win32 layer of clang-retro MFC (port/), and the calls of
|
||||
* the app that it does not have yet: serial ports, anonymous
|
||||
* pipes, the environment block, the user name, Beep and
|
||||
* the declaration of WinMain.
|
||||
* First pass: src/stubs.cpp has them. The serial and pipe
|
||||
* calls fail, so the app reaches a modem through TCP only.
|
||||
*/
|
||||
#ifndef DMODEM_WINPORT_WINDOWS_H
|
||||
#define DMODEM_WINPORT_WINDOWS_H
|
||||
#include_next <windows.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* (the SDK's winbase.h declares it, with C linkage; the layer's crt0
|
||||
calls it) */
|
||||
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
|
||||
|
||||
/* serial ports */
|
||||
#define CBR_115200 115200
|
||||
#define NOPARITY 0
|
||||
#define ONESTOPBIT 0
|
||||
#define DTR_CONTROL_ENABLE 0x01
|
||||
#define RTS_CONTROL_HANDSHAKE 0x02
|
||||
|
||||
typedef struct _DCB {
|
||||
DWORD DCBlength;
|
||||
DWORD BaudRate;
|
||||
DWORD fBinary : 1;
|
||||
DWORD fParity : 1;
|
||||
DWORD fOutxCtsFlow : 1;
|
||||
DWORD fOutxDsrFlow : 1;
|
||||
DWORD fDtrControl : 2;
|
||||
DWORD fDsrSensitivity : 1;
|
||||
DWORD fTXContinueOnXoff : 1;
|
||||
DWORD fOutX : 1;
|
||||
DWORD fInX : 1;
|
||||
DWORD fErrorChar : 1;
|
||||
DWORD fNull : 1;
|
||||
DWORD fRtsControl : 2;
|
||||
DWORD fAbortOnError : 1;
|
||||
DWORD fDummy2 : 17;
|
||||
WORD wReserved;
|
||||
WORD XonLim;
|
||||
WORD XoffLim;
|
||||
BYTE ByteSize;
|
||||
BYTE Parity;
|
||||
BYTE StopBits;
|
||||
char XonChar;
|
||||
char XoffChar;
|
||||
char ErrorChar;
|
||||
char EofChar;
|
||||
char EvtChar;
|
||||
WORD wReserved1;
|
||||
} DCB, *LPDCB;
|
||||
|
||||
typedef struct _COMMTIMEOUTS {
|
||||
DWORD ReadIntervalTimeout;
|
||||
DWORD ReadTotalTimeoutMultiplier;
|
||||
DWORD ReadTotalTimeoutConstant;
|
||||
DWORD WriteTotalTimeoutMultiplier;
|
||||
DWORD WriteTotalTimeoutConstant;
|
||||
} COMMTIMEOUTS, *LPCOMMTIMEOUTS;
|
||||
|
||||
BOOL WINAPI GetCommState(HANDLE, LPDCB);
|
||||
BOOL WINAPI SetCommState(HANDLE, LPDCB);
|
||||
BOOL WINAPI SetCommTimeouts(HANDLE, LPCOMMTIMEOUTS);
|
||||
|
||||
/* anonymous pipes */
|
||||
BOOL WINAPI CreatePipe(PHANDLE, PHANDLE, LPSECURITY_ATTRIBUTES, DWORD);
|
||||
BOOL WINAPI PeekNamedPipe(HANDLE, LPVOID, DWORD, LPDWORD, LPDWORD, LPDWORD);
|
||||
|
||||
/* the environment, the user, the speaker */
|
||||
LPSTR WINAPI dmodem_GetEnvironmentStringsA(void);
|
||||
BOOL WINAPI dmodem_FreeEnvironmentStringsA(LPSTR);
|
||||
#define GetEnvironmentStrings dmodem_GetEnvironmentStringsA
|
||||
#define FreeEnvironmentStrings dmodem_FreeEnvironmentStringsA
|
||||
BOOL WINAPI GetUserNameA(LPSTR, LPDWORD);
|
||||
#ifndef UNICODE
|
||||
#define GetUserName GetUserNameA
|
||||
#endif
|
||||
BOOL WINAPI Beep(DWORD, DWORD);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,3 @@
|
||||
/* winsock.h - Winsock 1.1: the Win32 layer has the Winsock 2 header,
|
||||
which has each function of 1.1 */
|
||||
#include <winsock2.h>
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright (C) 2026 D-Modem Authors
|
||||
*
|
||||
* stubs.cpp - the Win32 calls of the app that the Win32 layer of
|
||||
* clang-retro MFC does not have yet (include/). First pass:
|
||||
* the sound, ACM, serial and pipe calls fail, so the app
|
||||
* operates through TCP (a dmodemd that already runs) and
|
||||
* SSH, Telnet and rlogin. Remove each one when the layer
|
||||
* has it.
|
||||
*/
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
#include <msacm.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern char **environ;
|
||||
|
||||
extern "C" {
|
||||
|
||||
/* sound: no device */
|
||||
MMRESULT WINAPI waveOutOpen(HWAVEOUT *, UINT, LPCWAVEFORMATEX, DWORD_PTR,
|
||||
DWORD_PTR, DWORD) { return MMSYSERR_NODRIVER; }
|
||||
MMRESULT WINAPI waveOutClose(HWAVEOUT) { return MMSYSERR_NODRIVER; }
|
||||
MMRESULT WINAPI waveOutPrepareHeader(HWAVEOUT, LPWAVEHDR, UINT) { return MMSYSERR_NODRIVER; }
|
||||
MMRESULT WINAPI waveOutUnprepareHeader(HWAVEOUT, LPWAVEHDR, UINT) { return MMSYSERR_NODRIVER; }
|
||||
MMRESULT WINAPI waveOutWrite(HWAVEOUT, LPWAVEHDR, UINT) { return MMSYSERR_NODRIVER; }
|
||||
MMRESULT WINAPI waveOutReset(HWAVEOUT) { return MMSYSERR_NODRIVER; }
|
||||
MMRESULT WINAPI waveInOpen(HWAVEIN *, UINT, LPCWAVEFORMATEX, DWORD_PTR,
|
||||
DWORD_PTR, DWORD) { return MMSYSERR_NODRIVER; }
|
||||
MMRESULT WINAPI waveInClose(HWAVEIN) { return MMSYSERR_NODRIVER; }
|
||||
MMRESULT WINAPI waveInPrepareHeader(HWAVEIN, LPWAVEHDR, UINT) { return MMSYSERR_NODRIVER; }
|
||||
MMRESULT WINAPI waveInUnprepareHeader(HWAVEIN, LPWAVEHDR, UINT) { return MMSYSERR_NODRIVER; }
|
||||
MMRESULT WINAPI waveInAddBuffer(HWAVEIN, LPWAVEHDR, UINT) { return MMSYSERR_NODRIVER; }
|
||||
MMRESULT WINAPI waveInStart(HWAVEIN) { return MMSYSERR_NODRIVER; }
|
||||
MMRESULT WINAPI waveInReset(HWAVEIN) { return MMSYSERR_NODRIVER; }
|
||||
|
||||
/* ACM: no codecs */
|
||||
MMRESULT WINAPI acmFormatSuggest(HACMDRIVER, LPWAVEFORMATEX, LPWAVEFORMATEX,
|
||||
DWORD, DWORD) { return MMSYSERR_NODRIVER; }
|
||||
MMRESULT WINAPI acmStreamOpen(LPHACMSTREAM, HACMDRIVER, LPWAVEFORMATEX,
|
||||
LPWAVEFORMATEX, LPVOID, DWORD_PTR, DWORD_PTR,
|
||||
DWORD) { return MMSYSERR_NODRIVER; }
|
||||
MMRESULT WINAPI acmStreamClose(HACMSTREAM, DWORD) { return MMSYSERR_NODRIVER; }
|
||||
MMRESULT WINAPI acmStreamSize(HACMSTREAM, DWORD, LPDWORD, DWORD) { return MMSYSERR_NODRIVER; }
|
||||
MMRESULT WINAPI acmStreamPrepareHeader(HACMSTREAM, LPACMSTREAMHEADER, DWORD) { return MMSYSERR_NODRIVER; }
|
||||
MMRESULT WINAPI acmStreamUnprepareHeader(HACMSTREAM, LPACMSTREAMHEADER, DWORD) { return MMSYSERR_NODRIVER; }
|
||||
MMRESULT WINAPI acmStreamConvert(HACMSTREAM, LPACMSTREAMHEADER, DWORD) { return MMSYSERR_NODRIVER; }
|
||||
|
||||
/* serial ports: none */
|
||||
BOOL WINAPI GetCommState(HANDLE, LPDCB)
|
||||
{
|
||||
SetLastError(ERROR_NOT_SUPPORTED);
|
||||
return FALSE;
|
||||
}
|
||||
BOOL WINAPI SetCommState(HANDLE, LPDCB)
|
||||
{
|
||||
SetLastError(ERROR_NOT_SUPPORTED);
|
||||
return FALSE;
|
||||
}
|
||||
BOOL WINAPI SetCommTimeouts(HANDLE, LPCOMMTIMEOUTS)
|
||||
{
|
||||
SetLastError(ERROR_NOT_SUPPORTED);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* anonymous pipes: none (no dmodemd started by the app) */
|
||||
BOOL WINAPI CreatePipe(PHANDLE, PHANDLE, LPSECURITY_ATTRIBUTES, DWORD)
|
||||
{
|
||||
SetLastError(ERROR_NOT_SUPPORTED);
|
||||
return FALSE;
|
||||
}
|
||||
BOOL WINAPI PeekNamedPipe(HANDLE, LPVOID, DWORD, LPDWORD, LPDWORD, LPDWORD)
|
||||
{
|
||||
SetLastError(ERROR_NOT_SUPPORTED);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* the environment block of Windows (NAME=VALUE\0 ... \0) from environ */
|
||||
LPSTR WINAPI dmodem_GetEnvironmentStringsA(void)
|
||||
{
|
||||
size_t n = 1;
|
||||
for (char **e = environ; *e; e++)
|
||||
n += strlen(*e) + 1;
|
||||
char *block = (char *)malloc(n), *p = block;
|
||||
if (!block)
|
||||
return NULL;
|
||||
for (char **e = environ; *e; e++) {
|
||||
size_t l = strlen(*e) + 1;
|
||||
memcpy(p, *e, l);
|
||||
p += l;
|
||||
}
|
||||
*p = '\0';
|
||||
return block;
|
||||
}
|
||||
BOOL WINAPI dmodem_FreeEnvironmentStringsA(LPSTR block)
|
||||
{
|
||||
free(block);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WINAPI GetUserNameA(LPSTR name, LPDWORD n)
|
||||
{
|
||||
const char *u = getenv("USER");
|
||||
if (!u)
|
||||
u = getlogin();
|
||||
if (!u || strlen(u) + 1 > *n) {
|
||||
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
||||
return FALSE;
|
||||
}
|
||||
strcpy(name, u);
|
||||
*n = (DWORD)strlen(u) + 1;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* (no speaker: the terminal's bell is MessageBeep) */
|
||||
BOOL WINAPI Beep(DWORD, DWORD)
|
||||
{
|
||||
MessageBeep(MB_OK);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
# A modem for the smoke test: it listens on 127.0.0.1:PORT like
|
||||
# dmodemd's TCP port, writes each line it gets to LOG, answers AT
|
||||
# commands with OK and ATD with CONNECT, and after CONNECT sends back
|
||||
# the data it gets.
|
||||
#
|
||||
# fake_modem.py PORT LOG
|
||||
import socket
|
||||
import sys
|
||||
import threading
|
||||
|
||||
port, log_path = int(sys.argv[1]), sys.argv[2]
|
||||
log = open(log_path, "a", buffering=1)
|
||||
|
||||
|
||||
def serve(c):
|
||||
buf, online = b"", False
|
||||
while True:
|
||||
d = c.recv(1024)
|
||||
if not d:
|
||||
return
|
||||
if online:
|
||||
c.sendall(d)
|
||||
continue
|
||||
buf += d
|
||||
while b"\r" in buf:
|
||||
line, buf = buf.split(b"\r", 1)
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
log.write(line.decode("ascii", "replace") + "\n")
|
||||
if line.upper().startswith(b"ATD"):
|
||||
c.sendall(b"\r\nCONNECT 33600\r\n")
|
||||
online = True
|
||||
else:
|
||||
c.sendall(b"\r\nOK\r\n")
|
||||
|
||||
|
||||
s = socket.socket()
|
||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
s.bind(("127.0.0.1", port))
|
||||
s.listen(5)
|
||||
while True:
|
||||
c, _ = s.accept()
|
||||
threading.Thread(target=serve, args=(c,), daemon=True).start()
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
# The smoke test of the Linux build (winport/): starts the app on an X
|
||||
# display with an empty home folder, and makes sure that it stays up and
|
||||
# sends its first AT commands to a test modem on the TCP port that it
|
||||
# uses by default (127.0.0.1:2323).
|
||||
#
|
||||
# DISPLAY=:99 winport/test/smoke.sh build/winport/dmodem-win32
|
||||
set -eu
|
||||
app=$1
|
||||
here=$(cd "$(dirname "$0")" && pwd)
|
||||
tmp=$(mktemp -d)
|
||||
trap 'kill $modem $pid 2>/dev/null || true; rm -rf "$tmp"' EXIT
|
||||
|
||||
python3 "$here/fake_modem.py" 2323 "$tmp/modem.log" &
|
||||
modem=$!
|
||||
sleep 1
|
||||
HOME="$tmp/home" WINPORT_BACKEND=x11 "$app" &
|
||||
pid=$!
|
||||
|
||||
i=0
|
||||
while [ $i -lt 20 ]; do
|
||||
sleep 1
|
||||
kill -0 $pid 2>/dev/null || { echo "FAIL: the app stopped"; exit 1; }
|
||||
grep -q '^AT' "$tmp/modem.log" 2>/dev/null && break
|
||||
i=$((i + 1))
|
||||
done
|
||||
grep -q '^AT' "$tmp/modem.log" || { echo "FAIL: no AT commands on the TCP port"; exit 1; }
|
||||
sleep 2
|
||||
kill -0 $pid 2>/dev/null || { echo "FAIL: the app stopped"; exit 1; }
|
||||
echo "The modem got:"
|
||||
cat "$tmp/modem.log"
|
||||
echo "PASS"
|
||||
Reference in new issue
Block a user