Add NeoNet Yabasic networking FFI library, fix fcitx5 service and WM context menus, install yabasic-doc and mandoc
This commit is contained in:
1 parent
fb3723fab4
commit
726500085a
33 files changed
+2617
-69
No files matched your search
@@ -1,11 +1,12 @@
|
||||
# Bananarchy NeoUI SDK reference (`SDK.md`)
|
||||
# Bananarchy NeoUI and NeoNet SDK reference (`SDK.md`)
|
||||
|
||||
**NeoUI** (`libneoui.so` + `/usr/include/neoui.h`) is the native `240x320` QVGA graphical user interface SDK for **Bananarchy Linux**.
|
||||
**NeoUI** (`libneoui.so` + `/usr/include/neoui.h`) is the native `240x320` QVGA graphical user interface SDK for **Bananarchy Linux**, paired with **NeoNet** (`neonet.yab`), a `libcurl` + POSIX socket C FFI networking library for Yabasic.
|
||||
|
||||
It encapsulates all low-level X11 (`Xlib`), `Xft`, `Pango`, `libjpeg-turbo`, `libpng`, `.Xresources` / `~/.xthemes/*.xth` live theme resolution, offscreen `Pixmap` double buffering, standardized OS shell widgets, FIFO IPC, softkey chord handling (`Left+Right` softkey -> `xdrawer`), and multi-tap T9 keypad input behind:
|
||||
They encapsulate all low-level X11 (`Xlib`), `Xft`, `Pango`, `libjpeg-turbo`, `libpng`, `.Xresources` / `~/.xthemes/*.xth` live theme resolution, offscreen `Pixmap` double buffering, standardized OS shell widgets, FIFO IPC, softkey chord handling (`Left+Right` softkey -> `xdrawer`), multi-tap T9 keypad input, and HTTP/HTTPS/TCP/TLS/UDP networking behind:
|
||||
1. A **C-compatible FFI (`neoui_*`)** designed for both C programs and foreign-function interfaces (such as **Yabasic** `frnfn_call` / `frnfn_call$`, LuaJIT FFI, Janet, Python `ctypes`, etc.).
|
||||
2. A **C++20 SDK (`namespace bananarchy`)** providing `ThemeSpec`, `PluginTheme`, `NeoWindow`, and direct Pango/Xft/image helpers used across all 14 built-in Bananarchy DWM plugins.
|
||||
3. A **Yabasic wrapper library (`neoui.yab`)** preinstalled in `/home/user/Projects/neoui.yab` (and symlinked at `/usr/lib/neoui.yab`), paired with a full showcase application (`/home/user/Projects/neoui_demo.yab`).
|
||||
3. A **Yabasic UI wrapper library (`neoui.yab`)** preinstalled in `/home/user/Projects/neoui.yab` (and symlinked at `/usr/lib/neoui.yab`), paired with a full showcase application (`/home/user/Projects/neoui_demo.yab`).
|
||||
4. A **Yabasic networking wrapper library (`neonet.yab`)** preinstalled in `/home/user/Projects/neonet.yab` (and symlinked at `/usr/lib/neonet.yab`), wrapping `libcurl.so.4` and musl `libc` via `libffi` for one-line HTTP/HTTPS requests with custom headers as well as raw TCP, TLS, and UDP socket data exchange, paired with a combined NeoNet + NeoUI demo application (`/home/user/Projects/neonet_demo.yab`).
|
||||
|
||||
---
|
||||
|
||||
@@ -15,9 +16,12 @@ It encapsulates all low-level X11 (`Xlib`), `Xft`, `Pango`, `libjpeg-turbo`, `li
|
||||
| :--- | :--- | :--- |
|
||||
| `/usr/lib/libneoui.so` | `src/neoui/neoui.cpp` | Shared library (`armv7` hard-float) implementing the C FFI and C++20 SDK |
|
||||
| `/usr/include/neoui.h` | `src/neoui/neoui.h` | Unified C99 and C++20 header file |
|
||||
| `/home/user/Projects/neoui.yab` | `overlay/rootfs/home/user/Projects/neoui.yab` | Yabasic native C FFI wrapper module (`import neoui`) |
|
||||
| `/home/user/Projects/neoui.yab` | `overlay/rootfs/home/user/Projects/neoui.yab` | Yabasic native C FFI wrapper module for NeoUI (`import neoui`) |
|
||||
| `/usr/lib/neoui.yab` | `overlay/rootfs/usr/lib/neoui.yab` | Symlink to `/home/user/Projects/neoui.yab` so `import neoui` works from any working directory |
|
||||
| `/home/user/Projects/neoui_demo.yab` | `overlay/rootfs/home/user/Projects/neoui_demo.yab` | Interactive 3-tab Yabasic showcase demonstrating all NeoUI widgets, multi-tap input, custom drawing, modals, and live theme reload |
|
||||
| `/home/user/Projects/neonet.yab` | `overlay/rootfs/home/user/Projects/neonet.yab` | Yabasic native `libcurl` + socket FFI wrapper module for NeoNet (`import neonet`) |
|
||||
| `/usr/lib/neonet.yab` | `overlay/rootfs/usr/lib/neonet.yab` | Symlink to `/home/user/Projects/neonet.yab` so `import neonet` works from any working directory |
|
||||
| `/home/user/Projects/neonet_demo.yab` | `overlay/rootfs/home/user/Projects/neonet_demo.yab` | Interactive 3-tab Yabasic showcase combining NeoNet and NeoUI (`1:HTTP/S`, `2:Sockets`, `3:Tools`) |
|
||||
|
||||
### Key design principles
|
||||
- **Zero-flicker offscreen double buffering**: every NeoUI window (`240x296` at `X=0, Y=24`, directly below the 24px `dwm` top status bar) renders into an offscreen X11 `Pixmap` during `neoui_begin_frame()` .. `neoui_end_frame()` and copies the completed frame to the visible window in a single `XCopyArea` call.
|
||||
@@ -526,3 +530,127 @@ wend
|
||||
|
||||
neoui_shutdown()
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 6. NeoNet networking SDK reference for Yabasic (`neonet.yab`)
|
||||
|
||||
**NeoNet** (`/home/user/Projects/neonet.yab`, symlinked at `/usr/lib/neonet.yab`) is the native networking library for Yabasic on Bananarchy Linux. It wraps `/usr/lib/libcurl.so.4` (`OpenSSL`, `nghttp2`, `zlib`, `brotli`, `zstd`, `c-ares`) and musl `libc` (`open_memstream`, `getaddrinfo`, `socket`, `connect`, `send`, `recv`, `poll`) via Yabasic's native `libffi` interface (`frnfn_call`, `frnfn_call$`, and `frnbf_*`).
|
||||
|
||||
### 6.1 Importing `neonet.yab` and running the demo
|
||||
Because `/usr/lib/neonet.yab` is symlinked to `/home/user/Projects/neonet.yab`, any Yabasic program can import both `neoui` and `neonet`:
|
||||
```yabasic
|
||||
import neoui
|
||||
import neonet
|
||||
```
|
||||
- **From the file manager (`xfiles`)**: navigate to `/home/user/Projects/`, highlight `neonet_demo.yab`, and press **Center `OK` (`Return`)**.
|
||||
- **From a terminal or SSH**:
|
||||
```bash
|
||||
DISPLAY=:0 yabasic ~/Projects/neonet_demo.yab
|
||||
```
|
||||
|
||||
### 6.2 Module constants (`neonet.*`)
|
||||
|
||||
| Yabasic constant | Value | Description |
|
||||
| :--- | :--- | :--- |
|
||||
| `neonet.PROTO_TCP` | `1` | Raw TCP socket via `libcurl` (`CURLOPT_CONNECT_ONLY`) |
|
||||
| `neonet.PROTO_TLS` | `2` | TLS-encrypted socket via `libcurl` (`CURLOPT_CONNECT_ONLY` with ALPN disabled for raw TLS protocols) |
|
||||
| `neonet.PROTO_UDP` | `3` | Connectionless UDP datagram socket via musl `libc` (`SOCK_DGRAM`) |
|
||||
| `neonet.CURLE_OK` | `0` | Operation succeeded |
|
||||
| `neonet.CURLE_COULDNT_RESOLVE_HOST` | `6` | DNS resolution failed |
|
||||
| `neonet.CURLE_COULDNT_CONNECT` | `7` | TCP/UDP connection refused or unreachable |
|
||||
| `neonet.CURLE_OPERATION_TIMEDOUT` | `28` | Transfer or socket operation timed out |
|
||||
| `neonet.CURLE_SSL_CONNECT_ERROR` | `35` | TLS handshake failed |
|
||||
| `neonet.CURLE_PEER_FAILED_VERIFICATION` | `60` | Remote TLS certificate verification failed |
|
||||
| `neonet.CURLE_AGAIN` | `81` | Non-blocking socket would block |
|
||||
|
||||
### 6.3 Exported Yabasic functions in `neonet.yab`
|
||||
|
||||
#### 1. Lifecycle, version, and configuration
|
||||
- `neonet_init()`: initializes `libcurl` (`curl_global_init`) and resets the socket table; returns `1` on success (`0` on error). Automatically called on first use if omitted.
|
||||
- `neonet_cleanup()`: closes all active sockets, clears queued custom headers, and calls `curl_global_cleanup()`.
|
||||
- `neonet_version$()`: returns the `libcurl` and TLS/compression runtime version string (e.g. `"libcurl/8.23.0 OpenSSL/3.5.9 ..."`).
|
||||
- `neonet_strerror$(curl_code)`: returns the human-readable error message for `curl_code`.
|
||||
- `neonet_set_timeout(timeout_ms)`: sets the overall transfer timeout in milliseconds (default `15000`).
|
||||
- `neonet_set_connect_timeout(connect_timeout_ms)`: sets the connection timeout in milliseconds (default `8000`).
|
||||
- `neonet_set_user_agent(ua$)`: sets the default `User-Agent` header (default `"Bananarchy-NeoNet/1.0 (libcurl)"`).
|
||||
- `neonet_set_follow_redirects(enabled)`: enables (`1`, default) or disables (`0`) automatic HTTP `3xx` redirect following.
|
||||
- `neonet_set_max_redirects(max_redirs)`: sets the maximum number of redirects to follow (default `10`).
|
||||
- `neonet_set_insecure(insecure)`: when `1`, disables TLS peer and hostname certificate checks (`CURLOPT_SSL_VERIFYPEER = 0`, `CURLOPT_SSL_VERIFYHOST = 0`); when `0` (default), enforces strict verification.
|
||||
- `neonet_set_proxy(proxy_url$)`: sets an HTTP or SOCKS proxy URL (e.g. `"socks5h://127.0.0.1:9050"`, or `""` to disable).
|
||||
- `neonet_set_basic_auth(user_pwd$)`: sets HTTP Basic authentication credentials (`"user:password"`, or `""` to disable).
|
||||
|
||||
#### 2. Custom request headers and URL encoding
|
||||
- `neonet_clear_headers()`: clears all persistent custom HTTP headers added via `neonet_add_header()`.
|
||||
- `neonet_add_header(header_line$)`: appends a persistent custom header (e.g. `"Authorization: Bearer my_token"` or `"X-Api-Key: 12345"`) sent with subsequent HTTP/HTTPS requests.
|
||||
- `neonet_url_encode$(text$)`: percent-encodes `text$` via `curl_easy_escape`.
|
||||
- `neonet_url_decode$(text$)`: decodes percent-encoded `text$` via `curl_easy_unescape`.
|
||||
|
||||
#### 3. HTTP and HTTPS request functions
|
||||
*(Inline `headers$` arguments accept `""` for none, or multiple headers separated by `|` or `\n`, e.g. `"Accept: application/json|X-Client: Bananarchy"`, which are merged with any persistent headers from `neonet_add_header()`.)*
|
||||
- `neonet_get$(url$)`: performs an HTTP/HTTPS `GET` request and returns the response body string.
|
||||
- `neonet_get_ex$(url$, headers$)`: performs an HTTP/HTTPS `GET` request with inline custom headers and returns the response body string.
|
||||
- `neonet_post$(url$, body$, content_type$, headers$)`: performs an HTTP/HTTPS `POST` request with `body$`, optional `content_type$` (e.g. `"application/json"`), and optional `headers$`, returning the response body string.
|
||||
- `neonet_put$(url$, body$, content_type$, headers$)`: performs an HTTP/HTTPS `PUT` request and returns the response body string.
|
||||
- `neonet_patch$(url$, body$, content_type$, headers$)`: performs an HTTP/HTTPS `PATCH` request and returns the response body string.
|
||||
- `neonet_delete$(url$, headers$)`: performs an HTTP/HTTPS `DELETE` request and returns the response body string.
|
||||
- `neonet_head(url$, headers$)`: performs an HTTP/HTTPS `HEAD` request (`CURLOPT_NOBODY = 1`) and returns the HTTP status code (`200`, `404`, etc.), populating `neonet_response_headers$()`.
|
||||
- `neonet_request$(method$, url$, body$, headers$)`: general-purpose HTTP/HTTPS request for any verb (`"GET"`, `"POST"`, `"PUT"`, `"PATCH"`, `"DELETE"`, `"HEAD"`, `"OPTIONS"`), request body, and custom headers.
|
||||
- `neonet_download(url$, dest_path$, headers$)`: downloads `url$` directly to `dest_path$` on disk; returns `1` on HTTP `2xx`/`3xx` success or `0` on error.
|
||||
|
||||
#### 4. HTTP response metadata and header inspection
|
||||
- `neonet_status()`: returns the HTTP status code from the last transfer (e.g. `200`, `201`, `404`, `500`, or `0` on transport failure).
|
||||
- `neonet_last_code()`: returns the `CURLcode` from the last operation (`0` = `CURLE_OK`).
|
||||
- `neonet_error$()`: returns `""` on success, or the human-readable error string on failure.
|
||||
- `neonet_body$()`: returns the last response body string.
|
||||
- `neonet_body_len()`: returns the byte length of the last response body.
|
||||
- `neonet_response_headers$()`: returns the raw HTTP response header block from the last transfer.
|
||||
- `neonet_header$(name$)`: performs a case-insensitive lookup of a response header from the last transfer (e.g. `neonet_header$("content-type")`, `neonet_header$("server")`, `neonet_header$("date")`).
|
||||
- `neonet_content_type$()`: returns `CURLINFO_CONTENT_TYPE` from `libcurl`.
|
||||
- `neonet_effective_url$()`: returns the final effective URL after redirects (`CURLINFO_EFFECTIVE_URL`).
|
||||
- `neonet_primary_ip$()`: returns the remote server IP address (`CURLINFO_PRIMARY_IP`).
|
||||
|
||||
#### 5. TCP, TLS, and UDP socket data exchange
|
||||
- **Session-based socket functions**:
|
||||
- `neonet_connect(proto, host$, port)`: opens a socket with protocol `neonet.PROTO_TCP`, `neonet.PROTO_TLS`, or `neonet.PROTO_UDP` to `host$:port`; returns a socket handle `sock_id >= 0` on success or `-1` on error.
|
||||
- `neonet_tcp_connect(host$, port)`: shorthand for `neonet_connect(neonet.PROTO_TCP, host$, port)`.
|
||||
- `neonet_tls_connect(host$, port)`: shorthand for `neonet_connect(neonet.PROTO_TLS, host$, port)`.
|
||||
- `neonet_udp_open(host$, port)`: shorthand for `neonet_connect(neonet.PROTO_UDP, host$, port)`.
|
||||
- `neonet_send(sock_id, data$)`: sends string `data$` over `sock_id`; returns the number of bytes sent (`>= 0`) or `-1` on error.
|
||||
- `neonet_send_bytes(sock_id, frn_buf$, byte_len)`: sends `byte_len` raw bytes from a Yabasic foreign buffer (`frnbf_alloc$`) over `sock_id`; returns bytes sent or `-1` on error.
|
||||
- `neonet_recv$(sock_id, max_bytes, timeout_ms)`: waits up to `timeout_ms` and reads up to `max_bytes` bytes as a string (`neonet_last_len()` returns the byte count).
|
||||
- `neonet_recv_all$(sock_id, max_bytes, timeout_ms)`: reads chunks from a TCP/TLS stream until EOF, `max_bytes`, or idle timeout, and returns the combined string.
|
||||
- `neonet_recv_bytes(sock_id, frn_buf$, max_bytes, timeout_ms)`: waits up to `timeout_ms` and reads up to `max_bytes` raw bytes into foreign buffer `frn_buf$`, returning the number of bytes read (`> 0`), `0` on EOF/timeout, or `-1` on error.
|
||||
- `neonet_last_len()`: returns the byte count transferred by the most recent socket or HTTP operation.
|
||||
- `neonet_close(sock_id)`: closes socket `sock_id` and releases its slot.
|
||||
- **One-shot socket exchange and DNS helpers**:
|
||||
- `neonet_tcp_exchange$(host$, port, payload$, timeout_ms)`: connects via TCP, sends `payload$`, reads the response, closes the socket, and returns the response string.
|
||||
- `neonet_tls_exchange$(host$, port, payload$, timeout_ms)`: connects via TLS, sends `payload$`, reads the response, closes the socket, and returns the response string.
|
||||
- `neonet_udp_exchange$(host$, port, payload$, timeout_ms)`: sends a UDP datagram `payload$` to `host$:port`, waits up to `timeout_ms` for a reply datagram, closes the socket, and returns the reply string.
|
||||
- `neonet_system_dns$()`: returns the primary `nameserver` IP address from `/etc/resolv.conf` (fallback `"1.1.1.1"`).
|
||||
- `neonet_udp_dns_a$(dns_server$, domain$, timeout_ms)`: sends a binary RFC 1035 UDP DNS A-record query to `dns_server$:53` (or the system DNS if `dns_server$ = ""`) and returns the resolved IPv4 address string.
|
||||
|
||||
### 6.4 Minimal Yabasic NeoNet + NeoUI example
|
||||
```yabasic
|
||||
#!/usr/bin/yabasic
|
||||
import neoui
|
||||
import neonet
|
||||
|
||||
r = neonet_init()
|
||||
|
||||
// 1. HTTPS GET with custom headers
|
||||
body$ = neonet_get_ex$("https://example.com/", "X-Bananarchy: NeoNet-1.0|Accept: text/html")
|
||||
print "HTTP status: ", neonet_status(), " (", neonet_body_len(), " bytes from ", neonet_primary_ip$(), ")"
|
||||
print "Server header: ", neonet_header$("server")
|
||||
|
||||
// 2. One-shot TCP WHOIS query (port 43)
|
||||
whois$ = neonet_tcp_exchange$("whois.iana.org", 43, "example.com" + chr$(13) + chr$(10), 4000)
|
||||
print "WHOIS bytes: ", neonet_last_len()
|
||||
|
||||
// 3. Binary UDP DNS A-record lookup (port 53)
|
||||
ip$ = neonet_udp_dns_a$("", "example.com", 3000)
|
||||
print "UDP DNS resolved example.com -> ", ip$
|
||||
|
||||
r = neonet_cleanup()
|
||||
```
|
||||
|
||||
Reference in new issue
Block a user