Compare commits
104 Commits
4d50ed111a
...
v2.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
73cc8f448a
|
|||
|
4565afe294
|
|||
|
3ad8c79de8
|
|||
|
12fc3c228a
|
|||
|
175533a5e9
|
|||
|
a9b46141a9
|
|||
|
c38cca3b92
|
|||
|
aee7540faa
|
|||
|
53ba996ec9
|
|||
|
d450c6cc5f
|
|||
|
f8ea1634c4
|
|||
|
ef257cd575
|
|||
|
69eccc7065
|
|||
|
13d2ff115b
|
|||
|
9e4692bb09
|
|||
|
1c4343058d
|
|||
|
e5156cddbf
|
|||
|
34521e61c1
|
|||
|
c22dd67fc1
|
|||
|
274d5f03e7
|
|||
|
2f19e5a733
|
|||
|
b9cdabca5d
|
|||
|
f60ca43156
|
|||
|
afe4e61f08
|
|||
|
8d9d1c60ec
|
|||
|
8c1464822b
|
|||
|
fcd1b8e011
|
|||
|
3d345987c3
|
|||
|
3e37efd9cd
|
|||
|
efb25b8aae
|
|||
|
e72793e315
|
|||
|
5a412ab6e2
|
|||
|
81bc578773
|
|||
|
100de5ac2d
|
|||
|
c157d3369f
|
|||
|
8b5ea67aff
|
|||
|
6f02af814f
|
|||
|
90859107c8
|
|||
|
0219dbd026
|
|||
|
1da4699a7a
|
|||
|
9e993c50e6
|
|||
|
b3e9218b23
|
|||
|
bc8867eb22
|
|||
|
ec33adba35
|
|||
|
6f596f1dcb
|
|||
|
abcff46dc4
|
|||
|
8d9ce92758
|
|||
|
4bb9449e47
|
|||
|
50f70f93bb
|
|||
|
3f9a365d36
|
|||
|
9932b35a10
|
|||
|
af5f209c53
|
|||
|
6bfe577f1b
|
|||
|
1079189381
|
|||
|
c58b772905
|
|||
|
26ed2dbc77
|
|||
|
4b7258cba0
|
|||
|
9dc3dd02f3
|
|||
|
a7c3ed7cc1
|
|||
|
807a8c37d9
|
|||
|
c4707e2803
|
|||
|
46d68eacce
|
|||
|
86278c154c
|
|||
|
941ee2f10c
|
|||
|
5b57e9b41b
|
|||
|
4d99690b89
|
|||
|
7c74e6615d
|
|||
|
614fd98fc1
|
|||
|
5863040f93
|
|||
|
f891e5ca63
|
|||
|
8344b09c4f
|
|||
| 1238233556 | |||
| 9c31fb69df | |||
| a51c247d69 | |||
| f26e6361f3 | |||
| 4073b7329f | |||
| 6421892ef3 | |||
| a1994865a9 | |||
| c285f3a266 | |||
| e2c34afbc6 | |||
| e2c8fb6e33 | |||
| 5c7ac9a92b | |||
| 3fee7e8051 | |||
| 09d7a10b69 | |||
| e9bcd0fa53 | |||
| 3815795d59 | |||
| fd1538251a | |||
| ffad1f15a5 | |||
| 765b741a67 | |||
| ab66a60703 | |||
| 9ee07873ea | |||
| 7ee7dc5f9b | |||
| fea801ac7a | |||
| cbdbfc3d64 | |||
| 3610f98d67 | |||
| e77495f316 | |||
| 2f841d214f | |||
| 051bbedc2f | |||
| 404aa8c9cc | |||
| 90129ee2bc | |||
| 50e7f7dca5 | |||
| 3322fe2851 | |||
| 208a8fcc7e | |||
| 2d287752d4 |
@@ -1,6 +1,11 @@
|
|||||||
# Ubuntu 18.04 LTS and OpenBSD 6.4
|
# Ubuntu 18.04 LTS and OpenBSD 6.4
|
||||||
cmake_minimum_required (VERSION 3.10)
|
cmake_minimum_required (VERSION 3.10)
|
||||||
project (xK VERSION 1.5.0
|
|
||||||
|
file (READ xK-version project_version)
|
||||||
|
configure_file (xK-version xK-version.tag COPYONLY)
|
||||||
|
string (STRIP "${project_version}" project_version)
|
||||||
|
|
||||||
|
project (xK VERSION "${project_version}"
|
||||||
DESCRIPTION "IRC daemon, bot, TUI client and its web frontend" LANGUAGES C)
|
DESCRIPTION "IRC daemon, bot, TUI client and its web frontend" LANGUAGES C)
|
||||||
|
|
||||||
# Options
|
# Options
|
||||||
@@ -18,9 +23,6 @@ if ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUCC)
|
|||||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-function")
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-function")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# Version
|
|
||||||
set (project_version "${PROJECT_VERSION}")
|
|
||||||
|
|
||||||
# Try to append commit ID if it follows a version tag. It might be nicer if
|
# Try to append commit ID if it follows a version tag. It might be nicer if
|
||||||
# we could also detect dirty worktrees but that's very hard to get right.
|
# we could also detect dirty worktrees but that's very hard to get right.
|
||||||
# If we didn't need this for CPack, we could use add_custom_command to generate
|
# If we didn't need this for CPack, we could use add_custom_command to generate
|
||||||
@@ -162,14 +164,15 @@ add_custom_target (replies DEPENDS ${PROJECT_BINARY_DIR}/xD-replies.c)
|
|||||||
|
|
||||||
add_custom_command (OUTPUT xC-proto.c
|
add_custom_command (OUTPUT xC-proto.c
|
||||||
COMMAND env LC_ALL=C awk
|
COMMAND env LC_ALL=C awk
|
||||||
-f ${PROJECT_SOURCE_DIR}/xC-gen-proto.awk
|
-f ${PROJECT_SOURCE_DIR}/liberty/tools/lxdrgen.awk
|
||||||
-f ${PROJECT_SOURCE_DIR}/xC-gen-proto-c.awk
|
-f ${PROJECT_SOURCE_DIR}/liberty/tools/lxdrgen-c.awk
|
||||||
${PROJECT_SOURCE_DIR}/xC-proto > xC-proto.c
|
-v PrefixCamel=Relay
|
||||||
|
${PROJECT_SOURCE_DIR}/xC.lxdr > xC-proto.c
|
||||||
DEPENDS
|
DEPENDS
|
||||||
${PROJECT_SOURCE_DIR}/xC-gen-proto.awk
|
${PROJECT_SOURCE_DIR}/liberty/tools/lxdrgen.awk
|
||||||
${PROJECT_SOURCE_DIR}/xC-gen-proto-c.awk
|
${PROJECT_SOURCE_DIR}/liberty/tools/lxdrgen-c.awk
|
||||||
${PROJECT_SOURCE_DIR}/xC-proto
|
${PROJECT_SOURCE_DIR}/xC.lxdr
|
||||||
COMMENT "Generating xC relay protocol code")
|
COMMENT "Generating xC relay protocol code" VERBATIM)
|
||||||
add_custom_target (xC-proto DEPENDS ${PROJECT_BINARY_DIR}/xC-proto.c)
|
add_custom_target (xC-proto DEPENDS ${PROJECT_BINARY_DIR}/xC-proto.c)
|
||||||
|
|
||||||
# Build
|
# Build
|
||||||
@@ -260,8 +263,9 @@ foreach (page xB xC xD)
|
|||||||
else ()
|
else ()
|
||||||
set (ASCIIMAN ${PROJECT_SOURCE_DIR}/liberty/tools/asciiman.awk)
|
set (ASCIIMAN ${PROJECT_SOURCE_DIR}/liberty/tools/asciiman.awk)
|
||||||
add_custom_command (OUTPUT ${page_output}
|
add_custom_command (OUTPUT ${page_output}
|
||||||
COMMAND env LC_ALL=C awk -f ${ASCIIMAN}
|
COMMAND env LC_ALL=C asciidoc-release-version=${project_version}
|
||||||
"${PROJECT_SOURCE_DIR}/${page}.adoc" > ${page_output}
|
awk -f ${ASCIIMAN} "${PROJECT_SOURCE_DIR}/${page}.adoc"
|
||||||
|
> ${page_output}
|
||||||
DEPENDS ${page}.adoc ${ASCIIMAN}
|
DEPENDS ${page}.adoc ${ASCIIMAN}
|
||||||
COMMENT "Generating man page for ${page}" VERBATIM)
|
COMMENT "Generating man page for ${page}" VERBATIM)
|
||||||
endif ()
|
endif ()
|
||||||
|
|||||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
|||||||
Copyright (c) 2014 - 2022, Přemysl Eric Janouch <p@janouch.name>
|
Copyright (c) 2014 - 2024, Přemysl Eric Janouch <p@janouch.name>
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
purpose with or without fee is hereby granted.
|
purpose with or without fee is hereby granted.
|
||||||
|
|||||||
14
NEWS
14
NEWS
@@ -1,4 +1,6 @@
|
|||||||
2.0.0 (Unreleased)
|
2.0.0 (2024-07-28) "Perfect Is the Enemy of Good"
|
||||||
|
|
||||||
|
* xD: now using SHA-256 for client certificate fingerprints
|
||||||
|
|
||||||
* xD: implemented WALLOPS, choosing to make it target even non-operators
|
* xD: implemented WALLOPS, choosing to make it target even non-operators
|
||||||
|
|
||||||
@@ -14,6 +16,8 @@
|
|||||||
|
|
||||||
* xC: replaced behaviour.save_on_quit with general.autosave
|
* xC: replaced behaviour.save_on_quit with general.autosave
|
||||||
|
|
||||||
|
* xC: the server *.command configuration option now supports multiple lines
|
||||||
|
|
||||||
* xC: improved pager integration capabilities
|
* xC: improved pager integration capabilities
|
||||||
|
|
||||||
* xC: unsolicited JOINs will no longer automatically activate the buffer
|
* xC: unsolicited JOINs will no longer automatically activate the buffer
|
||||||
@@ -29,6 +33,14 @@
|
|||||||
|
|
||||||
* Added a web frontend for xC called xP
|
* Added a web frontend for xC called xP
|
||||||
|
|
||||||
|
* Added a Win32 frontend for xC called xW
|
||||||
|
|
||||||
|
* Added a Cocoa frontend for xC called xM
|
||||||
|
|
||||||
|
* Added a Go port of xD called xS
|
||||||
|
|
||||||
|
* Added a simple notifier called xN
|
||||||
|
|
||||||
|
|
||||||
1.5.0 (2021-12-21) "The Show Must Go On"
|
1.5.0 (2021-12-21) "The Show Must Go On"
|
||||||
|
|
||||||
|
|||||||
53
README.adoc
53
README.adoc
@@ -1,9 +1,10 @@
|
|||||||
xK
|
xK
|
||||||
==
|
==
|
||||||
|
|
||||||
'xK' (chat kit) is an IRC software suite consisting of a daemon, bot, terminal
|
'xK' (chat kit) is an IRC software suite consisting of a daemon, bot, notifier,
|
||||||
client, and a web frontend for the client. It's all you're ever going to
|
terminal client, and web/Windows/macOS frontends for the client. It's all
|
||||||
need for chatting, so long as you can make do with slightly minimalist software.
|
you're ever going to need for chatting, so long as you can make do with slightly
|
||||||
|
minimalist software.
|
||||||
|
|
||||||
They're all lean on dependencies, and offer a maximally permissive licence.
|
They're all lean on dependencies, and offer a maximally permissive licence.
|
||||||
|
|
||||||
@@ -47,8 +48,17 @@ What it notably doesn't support is online changes to configuration, any limits
|
|||||||
besides the total number of connections and mode `+l`, or server linking
|
besides the total number of connections and mode `+l`, or server linking
|
||||||
(which also means no services).
|
(which also means no services).
|
||||||
|
|
||||||
This program has been https://git.janouch.name/p/haven/src/branch/master/hid[
|
xS
|
||||||
ported to Go] in a different project, and development continues over there.
|
--
|
||||||
|
The IRC daemon again, this time ported to Go, additionally supporting WEBIRC,
|
||||||
|
and thus ideal for pairing with, e.g.,
|
||||||
|
https://github.com/kiwiirc/webircgateway[].
|
||||||
|
Any further development, such as P10 or TS6 linking for IRC services,
|
||||||
|
or plugin support for arbitrary bridges, will happen here.
|
||||||
|
|
||||||
|
xN
|
||||||
|
--
|
||||||
|
The IRC notifier, should you ever need to send automated messages from a script.
|
||||||
|
|
||||||
xB
|
xB
|
||||||
--
|
--
|
||||||
@@ -63,8 +73,10 @@ that easily to any program).
|
|||||||
|
|
||||||
Packages
|
Packages
|
||||||
--------
|
--------
|
||||||
Regular releases are sporadic. git master should be stable enough. You can get
|
Regular releases are sporadic. git master should be stable enough.
|
||||||
a package with the latest development version from Archlinux's AUR.
|
You can get a package with the latest development version using Arch Linux's
|
||||||
|
https://aur.archlinux.org/packages/xk-git[AUR],
|
||||||
|
or as a https://git.janouch.name/p/nixexprs[Nix derivation].
|
||||||
|
|
||||||
Building
|
Building
|
||||||
--------
|
--------
|
||||||
@@ -130,16 +142,37 @@ For remote use, it's recommended to put 'xP' behind a reverse proxy, with TLS,
|
|||||||
and some form of HTTP authentication. Pass the external URL of the WebSocket
|
and some form of HTTP authentication. Pass the external URL of the WebSocket
|
||||||
endpoint as the third command line argument in this case.
|
endpoint as the third command line argument in this case.
|
||||||
|
|
||||||
|
xW
|
||||||
|
~~
|
||||||
|
The Win32 frontend is a separate CMake subproject that should be compiled
|
||||||
|
using MinGW-w64. To avoid having to specify the relay address each time you
|
||||||
|
run it, create a shortcut for the executable and include the address in its
|
||||||
|
_Target_ field:
|
||||||
|
|
||||||
|
C:\...\xW.exe 127.0.0.1 9000
|
||||||
|
|
||||||
|
It works reasonably well starting with Windows 7.
|
||||||
|
|
||||||
|
xM
|
||||||
|
~~
|
||||||
|
The Cocoa frontend is a separate CMake subproject that requires Xcode to build.
|
||||||
|
It is currently not that usable. The relay address can either be passed on
|
||||||
|
the command line, or preset in the _defaults_ database:
|
||||||
|
|
||||||
|
$ defaults write name.janouch.xM relayHost 127.0.0.1
|
||||||
|
$ defaults write name.janouch.xM relayPort 9000
|
||||||
|
|
||||||
Client Certificates
|
Client Certificates
|
||||||
-------------------
|
-------------------
|
||||||
'xC' will use the SASL EXTERNAL method to authenticate using the TLS client
|
'xC' will use the SASL EXTERNAL method to authenticate using the TLS client
|
||||||
certificate specified by the respective server's `tls_cert` option if you add
|
certificate specified by the respective server's `tls_cert` option if you add
|
||||||
`sasl` to the `capabilities` option and the server supports this.
|
`sasl` to the `capabilities` option and the server supports this.
|
||||||
|
|
||||||
'xD' uses SHA-1 fingerprints of TLS client certificates to authenticate users.
|
'xD' and 'xS' use SHA-256 fingerprints of TLS client certificates
|
||||||
To get the fingerprint from a certificate file in the required form, use:
|
to authenticate users. To get the fingerprint from a certificate file
|
||||||
|
in the required form, use:
|
||||||
|
|
||||||
$ openssl x509 -in public.pem -outform DER | sha1sum
|
$ openssl x509 -in public.pem -outform DER | sha256sum
|
||||||
|
|
||||||
Custom Key Bindings in xC
|
Custom Key Bindings in xC
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|||||||
2
liberty
2
liberty
Submodule liberty updated: 34460ca715...f04cc2c61e
4
test
4
test
@@ -1,5 +1,7 @@
|
|||||||
#!/usr/bin/expect -f
|
#!/usr/bin/expect -f
|
||||||
# Very basic end-to-end testing for CI
|
# Very basic end-to-end testing for CI
|
||||||
|
set tempdir [exec mktemp -d]
|
||||||
|
set ::env(XDG_CONFIG_HOME) $tempdir
|
||||||
|
|
||||||
# Run the daemon to test against
|
# Run the daemon to test against
|
||||||
system ./xD --write-default-cfg
|
system ./xD --write-default-cfg
|
||||||
@@ -27,7 +29,7 @@ expect "Option changed"
|
|||||||
send "/disconnect\n"
|
send "/disconnect\n"
|
||||||
expect "]"
|
expect "]"
|
||||||
send "/connect\n"
|
send "/connect\n"
|
||||||
expect "Connection established"
|
expect "Welcome to"
|
||||||
|
|
||||||
# Try some chatting
|
# Try some chatting
|
||||||
send "/join #test\n"
|
send "/join #test\n"
|
||||||
|
|||||||
12
test-static
12
test-static
@@ -1,8 +1,16 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# We don't use printf's percent notation with our custom logging mechanism,
|
# We don't use printf's percent notation with our custom logging mechanism,
|
||||||
# so the compiler cannot check it for us like it usually does
|
# so the compiler cannot check it for us like it usually does.
|
||||||
|
#
|
||||||
|
# In clang-query terms, the string we're interested in can be found through:
|
||||||
|
# set traversal IgnoreUnlessSpelledInSource
|
||||||
|
# set output dump
|
||||||
|
# match callExpr(callee(functionDecl(
|
||||||
|
# hasName("log_full"))),
|
||||||
|
# hasArgument(5, stringLiteral().bind("format")))
|
||||||
|
# However, the tool is too restricted to be useful in a shell script.
|
||||||
perl -n0777 - "$(dirname "$0")"/xC.c <<-'END'
|
perl -n0777 - "$(dirname "$0")"/xC.c <<-'END'
|
||||||
while (/\blog_[^ ]+\s*\([^"()]*"[^"]*%[^%][^"]*"/gm) {
|
while (/\blog_[^ ]+\s*\([^"()]*"[^"]*%\w[^"]*"/gm) {
|
||||||
my ($p, $m) = ($`, $&);
|
my ($p, $m) = ($`, $&);
|
||||||
printf "$ARGV:%d: suspicious log format string: %s...\n",
|
printf "$ARGV:%d: suspicious log format string: %s...\n",
|
||||||
(1 + $p =~ tr/\n//), ($m =~ s/\s+/ /rg);
|
(1 + $p =~ tr/\n//), ($m =~ s/\s+/ /rg);
|
||||||
|
|||||||
4
xB.c
4
xB.c
@@ -1009,7 +1009,7 @@ is_valid_plugin_name (const char *name)
|
|||||||
if (!*name)
|
if (!*name)
|
||||||
return false;
|
return false;
|
||||||
for (const char *p = name; *p; p++)
|
for (const char *p = name; *p; p++)
|
||||||
if (!isgraph (*p) || *p == '/')
|
if (!isgraph ((uint8_t) *p) || *p == '/')
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1213,7 +1213,7 @@ parse_bot_command (const char *s, const char *command, const char **following)
|
|||||||
s += command_len;
|
s += command_len;
|
||||||
|
|
||||||
// Expect a word boundary, so that we don't respond to invalid things
|
// Expect a word boundary, so that we don't respond to invalid things
|
||||||
if (isalnum (*s))
|
if (isalnum ((uint8_t) *s))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Ignore any initial spaces; the rest is the command's argument
|
// Ignore any initial spaces; the rest is the command's argument
|
||||||
|
|||||||
@@ -1,325 +0,0 @@
|
|||||||
# xC-gen-proto-c.awk: C backend for xC-gen-proto.awk.
|
|
||||||
#
|
|
||||||
# Copyright (c) 2022, Přemysl Eric Janouch <p@janouch.name>
|
|
||||||
# SPDX-License-Identifier: 0BSD
|
|
||||||
#
|
|
||||||
# Neither *_new() nor *_destroy() functions are provided, because they'd only
|
|
||||||
# be useful for top-levels, and are merely extra malloc()/free() calls.
|
|
||||||
# Users are expected to reuse buffers.
|
|
||||||
#
|
|
||||||
# Similarly, no constructors are produced--those are easy to write manually.
|
|
||||||
#
|
|
||||||
# All arrays are deserialized zero-terminated, so u8<> and i8<> can be directly
|
|
||||||
# used as C strings.
|
|
||||||
#
|
|
||||||
# All types must be able to dispose partially zero values going from the back,
|
|
||||||
# i.e., in the reverse order of deserialization.
|
|
||||||
|
|
||||||
function define_internal(name, ctype) {
|
|
||||||
Types[name] = "internal"
|
|
||||||
CodegenCType[name] = ctype
|
|
||||||
}
|
|
||||||
|
|
||||||
function define_int(shortname, ctype) {
|
|
||||||
define_internal(shortname, ctype)
|
|
||||||
CodegenSerialize[shortname] = \
|
|
||||||
"\tstr_pack_" shortname "(w, %s);\n"
|
|
||||||
CodegenDeserialize[shortname] = \
|
|
||||||
"\tif (!msg_unpacker_" shortname "(r, &%s))\n" \
|
|
||||||
"\t\treturn false;\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
function define_sint(size) { define_int("i" size, "int" size "_t") }
|
|
||||||
function define_uint(size) { define_int("u" size, "uint" size "_t") }
|
|
||||||
|
|
||||||
function codegen_begin() {
|
|
||||||
define_sint("8")
|
|
||||||
define_sint("16")
|
|
||||||
define_sint("32")
|
|
||||||
define_sint("64")
|
|
||||||
define_uint("8")
|
|
||||||
define_uint("16")
|
|
||||||
define_uint("32")
|
|
||||||
define_uint("64")
|
|
||||||
|
|
||||||
define_internal("string", "struct str")
|
|
||||||
CodegenDispose["string"] = "\tstr_free(&%s);\n"
|
|
||||||
CodegenSerialize["string"] = \
|
|
||||||
"\tif (!proto_string_serialize(&%s, w))\n" \
|
|
||||||
"\t\treturn false;\n"
|
|
||||||
CodegenDeserialize["string"] = \
|
|
||||||
"\tif (!proto_string_deserialize(&%s, r))\n" \
|
|
||||||
"\t\treturn false;\n"
|
|
||||||
|
|
||||||
define_internal("bool", "bool")
|
|
||||||
CodegenSerialize["bool"] = \
|
|
||||||
"\tstr_pack_u8(w, !!%s);\n"
|
|
||||||
CodegenDeserialize["bool"] = \
|
|
||||||
"\t{\n" \
|
|
||||||
"\t\tuint8_t v = 0;\n" \
|
|
||||||
"\t\tif (!msg_unpacker_u8(r, &v))\n" \
|
|
||||||
"\t\t\treturn false;\n" \
|
|
||||||
"\t\t%s = !!v;\n" \
|
|
||||||
"\t}\n"
|
|
||||||
|
|
||||||
print "// This file directly depends on liberty.c, but doesn't include it."
|
|
||||||
|
|
||||||
print ""
|
|
||||||
print "static bool"
|
|
||||||
print "proto_string_serialize(const struct str *s, struct str *w) {"
|
|
||||||
print "\tif (s->len > UINT32_MAX)"
|
|
||||||
print "\t\treturn false;"
|
|
||||||
print "\tstr_pack_u32(w, s->len);"
|
|
||||||
print "\tstr_append_str(w, s);"
|
|
||||||
print "\treturn true;"
|
|
||||||
print "}"
|
|
||||||
|
|
||||||
print ""
|
|
||||||
print "static bool"
|
|
||||||
print "proto_string_deserialize(struct str *s, struct msg_unpacker *r) {"
|
|
||||||
print "\tuint32_t len = 0;"
|
|
||||||
print "\tif (!msg_unpacker_u32(r, &len))"
|
|
||||||
print "\t\treturn false;"
|
|
||||||
print "\tif (msg_unpacker_get_available(r) < len)"
|
|
||||||
print "\t\treturn false;"
|
|
||||||
print "\t*s = str_make();"
|
|
||||||
print "\tstr_append_data(s, r->data + r->offset, len);"
|
|
||||||
print "\tr->offset += len;"
|
|
||||||
print "\tif (!utf8_validate (s->str, s->len))"
|
|
||||||
print "\t\treturn false;"
|
|
||||||
print "\treturn true;"
|
|
||||||
print "}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_constant(name, value) {
|
|
||||||
print ""
|
|
||||||
print "enum { " PrefixUpper name " = " value " };"
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_enum_value(name, subname, value, cg) {
|
|
||||||
append(cg, "fields",
|
|
||||||
"\t" PrefixUpper toupper(cameltosnake(name)) "_" subname \
|
|
||||||
" = " value ",\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_enum(name, cg, ctype) {
|
|
||||||
ctype = "enum " PrefixLower cameltosnake(name)
|
|
||||||
print ""
|
|
||||||
print ctype " {"
|
|
||||||
print cg["fields"] "};"
|
|
||||||
|
|
||||||
# XXX: This should also check if it isn't out-of-range for any reason,
|
|
||||||
# but our usage of sprintf() stands in the way a bit.
|
|
||||||
CodegenSerialize[name] = "\tstr_pack_i8(w, %s);\n"
|
|
||||||
CodegenDeserialize[name] = \
|
|
||||||
"\t{\n" \
|
|
||||||
"\t\tint8_t v = 0;\n" \
|
|
||||||
"\t\tif (!msg_unpacker_i8(r, &v) || !v)\n" \
|
|
||||||
"\t\t\treturn false;\n" \
|
|
||||||
"\t\t%s = v;\n" \
|
|
||||||
"\t}\n"
|
|
||||||
|
|
||||||
CodegenCType[name] = ctype
|
|
||||||
for (i in cg)
|
|
||||||
delete cg[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_struct_tag(d, cg, f) {
|
|
||||||
f = "self->" d["name"]
|
|
||||||
append(cg, "fields", "\t" CodegenCType[d["type"]] " " d["name"] ";\n")
|
|
||||||
append(cg, "dispose", sprintf(CodegenDispose[d["type"]], f))
|
|
||||||
append(cg, "serialize", sprintf(CodegenSerialize[d["type"]], f))
|
|
||||||
# Do not deserialize here, that would be out of order.
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_struct_field(d, cg, f, dispose, serialize, deserialize) {
|
|
||||||
f = "self->" d["name"]
|
|
||||||
dispose = CodegenDispose[d["type"]]
|
|
||||||
serialize = CodegenSerialize[d["type"]]
|
|
||||||
deserialize = CodegenDeserialize[d["type"]]
|
|
||||||
if (!d["isarray"]) {
|
|
||||||
append(cg, "fields", "\t" CodegenCType[d["type"]] " " d["name"] ";\n")
|
|
||||||
append(cg, "dispose", sprintf(dispose, f))
|
|
||||||
append(cg, "serialize", sprintf(serialize, f))
|
|
||||||
append(cg, "deserialize", sprintf(deserialize, f))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
append(cg, "fields",
|
|
||||||
"\t" CodegenCType["u32"] " " d["name"] "_len;\n" \
|
|
||||||
"\t" CodegenCType[d["type"]] " *" d["name"] ";\n")
|
|
||||||
|
|
||||||
if (dispose)
|
|
||||||
append(cg, "dispose", "\tif (" f ")\n" \
|
|
||||||
"\t\tfor (size_t i = 0; i < " f "_len; i++)\n" \
|
|
||||||
indent(indent(sprintf(dispose, f "[i]"))))
|
|
||||||
append(cg, "dispose", "\tfree(" f ");\n")
|
|
||||||
|
|
||||||
append(cg, "serialize", sprintf(CodegenSerialize["u32"], f "_len"))
|
|
||||||
if (d["type"] == "u8" || d["type"] == "i8") {
|
|
||||||
append(cg, "serialize",
|
|
||||||
"\tstr_append_data(w, " f ", " f "_len);\n")
|
|
||||||
} else if (serialize) {
|
|
||||||
append(cg, "serialize",
|
|
||||||
"\tfor (size_t i = 0; i < " f "_len; i++)\n" \
|
|
||||||
indent(sprintf(serialize, f "[i]")))
|
|
||||||
}
|
|
||||||
|
|
||||||
append(cg, "deserialize", sprintf(CodegenDeserialize["u32"], f "_len") \
|
|
||||||
"\tif (!(" f " = calloc(" f "_len + 1, sizeof *" f ")))\n" \
|
|
||||||
"\t\treturn false;\n")
|
|
||||||
if (d["type"] == "u8" || d["type"] == "i8") {
|
|
||||||
append(cg, "deserialize",
|
|
||||||
"\tif (msg_unpacker_get_available(r) < " f "_len)\n" \
|
|
||||||
"\t\treturn false;\n" \
|
|
||||||
"\tmemcpy(" f ", r->data + r->offset, " f "_len);\n" \
|
|
||||||
"\tr->offset += " f "_len;\n")
|
|
||||||
} else if (deserialize) {
|
|
||||||
append(cg, "deserialize",
|
|
||||||
"\tfor (size_t i = 0; i < " f "_len; i++)\n" \
|
|
||||||
indent(sprintf(deserialize, f "[i]")))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_struct(name, cg, ctype, funcname) {
|
|
||||||
ctype = "struct " PrefixLower cameltosnake(name)
|
|
||||||
print ""
|
|
||||||
print ctype " {"
|
|
||||||
print cg["fields"] "};"
|
|
||||||
|
|
||||||
if (cg["dispose"]) {
|
|
||||||
funcname = PrefixLower cameltosnake(name) "_free"
|
|
||||||
print ""
|
|
||||||
print "static void\n" funcname "(" ctype " *self) {"
|
|
||||||
print cg["dispose"] "}"
|
|
||||||
|
|
||||||
CodegenDispose[name] = "\t" funcname "(&%s);\n"
|
|
||||||
}
|
|
||||||
if (cg["serialize"]) {
|
|
||||||
funcname = PrefixLower cameltosnake(name) "_serialize"
|
|
||||||
print ""
|
|
||||||
print "static bool\n" \
|
|
||||||
funcname "(\n\t\t" ctype " *self, struct str *w) {"
|
|
||||||
print cg["serialize"] "\treturn true;"
|
|
||||||
print "}"
|
|
||||||
|
|
||||||
CodegenSerialize[name] = "\tif (!" funcname "(&%s, w))\n" \
|
|
||||||
"\t\treturn false;\n"
|
|
||||||
}
|
|
||||||
if (cg["deserialize"]) {
|
|
||||||
funcname = PrefixLower cameltosnake(name) "_deserialize"
|
|
||||||
print ""
|
|
||||||
print "static bool\n" \
|
|
||||||
funcname "(\n\t\t" ctype " *self, struct msg_unpacker *r) {"
|
|
||||||
print cg["deserialize"] "\treturn true;"
|
|
||||||
print "}"
|
|
||||||
|
|
||||||
CodegenDeserialize[name] = "\tif (!" funcname "(&%s, r))\n" \
|
|
||||||
"\t\treturn false;\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
CodegenCType[name] = ctype
|
|
||||||
for (i in cg)
|
|
||||||
delete cg[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_union_tag(d, cg) {
|
|
||||||
cg["tagtype"] = d["type"]
|
|
||||||
cg["tagname"] = d["name"]
|
|
||||||
append(cg, "fields", "\t" CodegenCType[d["type"]] " " d["name"] ";\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_union_struct( \
|
|
||||||
name, casename, cg, scg, structname, fieldname, fullcasename) {
|
|
||||||
# Don't generate obviously useless structs.
|
|
||||||
fullcasename = toupper(cameltosnake(cg["tagtype"])) "_" casename
|
|
||||||
if (!scg["dispose"] && !scg["deserialize"]) {
|
|
||||||
append(cg, "structless", "\tcase " PrefixUpper fullcasename ":\n")
|
|
||||||
for (i in scg)
|
|
||||||
delete scg[i]
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
# And thus not all generated structs are present in Types.
|
|
||||||
structname = name "_" casename
|
|
||||||
fieldname = tolower(casename)
|
|
||||||
codegen_struct(structname, scg)
|
|
||||||
|
|
||||||
append(cg, "fields", "\t" CodegenCType[structname] " " fieldname ";\n")
|
|
||||||
if (CodegenDispose[structname])
|
|
||||||
append(cg, "dispose", "\tcase " PrefixUpper fullcasename ":\n" \
|
|
||||||
indent(sprintf(CodegenDispose[structname], "self->" fieldname)) \
|
|
||||||
"\t\tbreak;\n")
|
|
||||||
|
|
||||||
# With no de/serialization code, this will simply recognize the tag.
|
|
||||||
append(cg, "serialize", "\tcase " PrefixUpper fullcasename ":\n" \
|
|
||||||
indent(sprintf(CodegenSerialize[structname], "self->" fieldname)) \
|
|
||||||
"\t\tbreak;\n")
|
|
||||||
append(cg, "deserialize", "\tcase " PrefixUpper fullcasename ":\n" \
|
|
||||||
indent(sprintf(CodegenDeserialize[structname], "self->" fieldname)) \
|
|
||||||
"\t\tbreak;\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_union(name, cg, f, ctype, funcname) {
|
|
||||||
ctype = "union " PrefixLower cameltosnake(name)
|
|
||||||
print ""
|
|
||||||
print ctype " {"
|
|
||||||
print cg["fields"] "};"
|
|
||||||
|
|
||||||
f = "self->" cg["tagname"]
|
|
||||||
if (cg["dispose"]) {
|
|
||||||
funcname = PrefixLower cameltosnake(name) "_free"
|
|
||||||
print ""
|
|
||||||
print "static void\n" funcname "(" ctype " *self) {"
|
|
||||||
print "\tswitch (" f ") {"
|
|
||||||
if (cg["structless"])
|
|
||||||
print cg["structless"] \
|
|
||||||
indent(sprintf(CodegenDispose[cg["tagtype"]], f)) "\t\tbreak;"
|
|
||||||
print cg["dispose"] "\tdefault:"
|
|
||||||
print "\t\tbreak;"
|
|
||||||
print "\t}"
|
|
||||||
print "}"
|
|
||||||
|
|
||||||
CodegenDispose[name] = "\t" funcname "(&%s);\n"
|
|
||||||
}
|
|
||||||
if (cg["serialize"]) {
|
|
||||||
funcname = PrefixLower cameltosnake(name) "_serialize"
|
|
||||||
print ""
|
|
||||||
print "static bool\n" \
|
|
||||||
funcname "(\n\t\t" ctype " *self, struct str *w) {"
|
|
||||||
print "\tswitch (" f ") {"
|
|
||||||
if (cg["structless"])
|
|
||||||
print cg["structless"] \
|
|
||||||
indent(sprintf(CodegenSerialize[cg["tagtype"]], f)) "\t\tbreak;"
|
|
||||||
print cg["serialize"] "\tdefault:"
|
|
||||||
print "\t\treturn false;"
|
|
||||||
print "\t}"
|
|
||||||
print "\treturn true;"
|
|
||||||
print "}"
|
|
||||||
|
|
||||||
CodegenSerialize[name] = "\tif (!" funcname "(&%s, w))\n" \
|
|
||||||
"\t\treturn false;\n"
|
|
||||||
}
|
|
||||||
if (cg["deserialize"]) {
|
|
||||||
funcname = PrefixLower cameltosnake(name) "_deserialize"
|
|
||||||
print ""
|
|
||||||
print "static bool\n" \
|
|
||||||
funcname "(\n\t\t" ctype " *self, struct msg_unpacker *r) {"
|
|
||||||
print sprintf(CodegenDeserialize[cg["tagtype"]], f)
|
|
||||||
print "\tswitch (" f ") {"
|
|
||||||
if (cg["structless"])
|
|
||||||
print cg["structless"] "\t\tbreak;"
|
|
||||||
print cg["deserialize"] "\tdefault:"
|
|
||||||
print "\t\treturn false;"
|
|
||||||
print "\t}"
|
|
||||||
print "\treturn true;"
|
|
||||||
print "}"
|
|
||||||
|
|
||||||
CodegenDeserialize[name] = "\tif (!" funcname "(&%s, r))\n" \
|
|
||||||
"\t\treturn false;\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
CodegenCType[name] = ctype
|
|
||||||
for (i in cg)
|
|
||||||
delete cg[i]
|
|
||||||
}
|
|
||||||
@@ -1,519 +0,0 @@
|
|||||||
# xC-gen-proto-go.awk: Go backend for xC-gen-proto.awk.
|
|
||||||
#
|
|
||||||
# Copyright (c) 2022, Přemysl Eric Janouch <p@janouch.name>
|
|
||||||
# SPDX-License-Identifier: 0BSD
|
|
||||||
#
|
|
||||||
# This backend also enables proxying to other endpoints using JSON.
|
|
||||||
|
|
||||||
function define_internal(name, gotype) {
|
|
||||||
Types[name] = "internal"
|
|
||||||
CodegenGoType[name] = gotype
|
|
||||||
}
|
|
||||||
|
|
||||||
function define_sint(size, shortname, gotype) {
|
|
||||||
shortname = "i" size
|
|
||||||
gotype = "int" size
|
|
||||||
define_internal(shortname, gotype)
|
|
||||||
|
|
||||||
CodegenAppendJSON[shortname] = \
|
|
||||||
"\tb = strconv.AppendInt(b, int64(%s), 10)\n"
|
|
||||||
if (size == 8) {
|
|
||||||
CodegenSerialize[shortname] = "\tdata = append(data, uint8(%s))\n"
|
|
||||||
CodegenDeserialize[shortname] = \
|
|
||||||
"\tif len(data) >= 1 {\n" \
|
|
||||||
"\t\t%s, data = int8(data[0]), data[1:]\n" \
|
|
||||||
"\t} else {\n" \
|
|
||||||
"\t\treturn nil, false\n" \
|
|
||||||
"\t}\n"
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
CodegenSerialize[shortname] = \
|
|
||||||
"\tdata = binary.BigEndian.AppendUint" size "(data, uint" size "(%s))\n"
|
|
||||||
CodegenDeserialize[shortname] = \
|
|
||||||
"\tif len(data) >= " (size / 8) " {\n" \
|
|
||||||
"\t\t%s = " gotype "(binary.BigEndian.Uint" size "(data))\n" \
|
|
||||||
"\t\tdata = data[" (size / 8) ":]\n" \
|
|
||||||
"\t} else {\n" \
|
|
||||||
"\t\treturn nil, false\n" \
|
|
||||||
"\t}\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
function define_uint(size, shortname, gotype) {
|
|
||||||
# Both []byte and []uint8 luckily marshal as base64-encoded JSON strings,
|
|
||||||
# so there's no need to rename the type as an exception.
|
|
||||||
shortname = "u" size
|
|
||||||
gotype = "uint" size
|
|
||||||
define_internal(shortname, gotype)
|
|
||||||
|
|
||||||
CodegenAppendJSON[shortname] = \
|
|
||||||
"\tb = strconv.AppendUint(b, uint64(%s), 10)\n"
|
|
||||||
if (size == 8) {
|
|
||||||
CodegenSerialize[shortname] = "\tdata = append(data, %s)\n"
|
|
||||||
CodegenDeserialize[shortname] = \
|
|
||||||
"\tif len(data) >= 1 {\n" \
|
|
||||||
"\t\t%s, data = data[0], data[1:]\n" \
|
|
||||||
"\t} else {\n" \
|
|
||||||
"\t\treturn nil, false\n" \
|
|
||||||
"\t}\n"
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
CodegenSerialize[shortname] = \
|
|
||||||
"\tdata = binary.BigEndian.AppendUint" size "(data, %s)\n"
|
|
||||||
CodegenDeserialize[shortname] = \
|
|
||||||
"\tif len(data) >= " (size / 8) " {\n" \
|
|
||||||
"\t\t%s = binary.BigEndian.Uint" size "(data)\n" \
|
|
||||||
"\t\tdata = data[" (size / 8) ":]\n" \
|
|
||||||
"\t} else {\n" \
|
|
||||||
"\t\treturn nil, false\n" \
|
|
||||||
"\t}\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_begin() {
|
|
||||||
define_sint("8")
|
|
||||||
define_sint("16")
|
|
||||||
define_sint("32")
|
|
||||||
define_sint("64")
|
|
||||||
define_uint("8")
|
|
||||||
define_uint("16")
|
|
||||||
define_uint("32")
|
|
||||||
define_uint("64")
|
|
||||||
|
|
||||||
define_internal("bool", "bool")
|
|
||||||
CodegenAppendJSON["bool"] = \
|
|
||||||
"\tb = strconv.AppendBool(b, %s)\n"
|
|
||||||
CodegenSerialize["bool"] = \
|
|
||||||
"\tif %s {\n" \
|
|
||||||
"\t\tdata = append(data, 1)\n" \
|
|
||||||
"\t} else {\n" \
|
|
||||||
"\t\tdata = append(data, 0)\n" \
|
|
||||||
"\t}\n"
|
|
||||||
CodegenDeserialize["bool"] = \
|
|
||||||
"\tif data, ok = protoConsumeBoolFrom(data, &%s); !ok {\n" \
|
|
||||||
"\t\treturn nil, ok\n" \
|
|
||||||
"\t}\n"
|
|
||||||
|
|
||||||
define_internal("string", "string")
|
|
||||||
CodegenSerialize["string"] = \
|
|
||||||
"\tif data, ok = protoAppendStringTo(data, %s); !ok {\n" \
|
|
||||||
"\t\treturn nil, ok\n" \
|
|
||||||
"\t}\n"
|
|
||||||
CodegenDeserialize["string"] = \
|
|
||||||
"\tif data, ok = protoConsumeStringFrom(data, &%s); !ok {\n" \
|
|
||||||
"\t\treturn nil, ok\n" \
|
|
||||||
"\t}\n"
|
|
||||||
|
|
||||||
print "package main"
|
|
||||||
print ""
|
|
||||||
print "import ("
|
|
||||||
print "\t`encoding/base64`"
|
|
||||||
print "\t`encoding/binary`"
|
|
||||||
print "\t`encoding/json`"
|
|
||||||
print "\t`errors`"
|
|
||||||
print "\t`math`"
|
|
||||||
print "\t`strconv`"
|
|
||||||
print "\t`unicode/utf8`"
|
|
||||||
print ")"
|
|
||||||
print ""
|
|
||||||
|
|
||||||
print "// protoConsumeBoolFrom tries to deserialize a boolean value"
|
|
||||||
print "// from the beginning of a byte stream. When successful,"
|
|
||||||
print "// it returns a subslice with any data that might follow."
|
|
||||||
print "func protoConsumeBoolFrom(data []byte, b *bool) ([]byte, bool) {"
|
|
||||||
print "\tif len(data) < 1 {"
|
|
||||||
print "\t\treturn nil, false"
|
|
||||||
print "\t}"
|
|
||||||
print "\tif data[0] != 0 {"
|
|
||||||
print "\t\t*b = true"
|
|
||||||
print "\t} else {"
|
|
||||||
print "\t\t*b = false"
|
|
||||||
print "\t}"
|
|
||||||
print "\treturn data[1:], true"
|
|
||||||
print "}"
|
|
||||||
print ""
|
|
||||||
|
|
||||||
print "// protoAppendStringTo tries to serialize a string value,"
|
|
||||||
print "// appending it to the end of a byte stream."
|
|
||||||
print "func protoAppendStringTo(data []byte, s string) ([]byte, bool) {"
|
|
||||||
print "\tif len(s) > math.MaxUint32 {"
|
|
||||||
print "\t\treturn nil, false"
|
|
||||||
print "\t}"
|
|
||||||
print "\tdata = binary.BigEndian.AppendUint32(data, uint32(len(s)))"
|
|
||||||
print "\treturn append(data, s...), true"
|
|
||||||
print "}"
|
|
||||||
print ""
|
|
||||||
|
|
||||||
print "// protoConsumeStringFrom tries to deserialize a string value"
|
|
||||||
print "// from the beginning of a byte stream. When successful,"
|
|
||||||
print "// it returns a subslice with any data that might follow."
|
|
||||||
print "func protoConsumeStringFrom(data []byte, s *string) ([]byte, bool) {"
|
|
||||||
print "\tif len(data) < 4 {"
|
|
||||||
print "\t\treturn nil, false"
|
|
||||||
print "\t}"
|
|
||||||
print "\tlength := binary.BigEndian.Uint32(data)"
|
|
||||||
print "\tif data = data[4:]; uint64(len(data)) < uint64(length) {"
|
|
||||||
print "\t\treturn nil, false"
|
|
||||||
print "\t}"
|
|
||||||
print "\t*s = string(data[:length])"
|
|
||||||
print "\tif !utf8.ValidString(*s) {"
|
|
||||||
print "\t\treturn nil, false"
|
|
||||||
print "\t}"
|
|
||||||
print "\treturn data[length:], true"
|
|
||||||
print "}"
|
|
||||||
print ""
|
|
||||||
|
|
||||||
print "// protoUnmarshalEnumJSON converts a JSON fragment to an integer,"
|
|
||||||
print "// ensuring that it's within the expected range of enum values."
|
|
||||||
print "func protoUnmarshalEnumJSON(data []byte) (int64, error) {"
|
|
||||||
print "\tvar n int64"
|
|
||||||
print "\tif err := json.Unmarshal(data, &n); err != nil {"
|
|
||||||
print "\t\treturn 0, err"
|
|
||||||
print "\t} else if n > math.MaxInt8 || n < math.MinInt8 {"
|
|
||||||
print "\t\treturn 0, errors.New(`integer out of range`)"
|
|
||||||
print "\t} else {"
|
|
||||||
print "\t\treturn n, nil"
|
|
||||||
print "\t}"
|
|
||||||
print "}"
|
|
||||||
print ""
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_constant(name, value) {
|
|
||||||
print "const " PrefixCamel snaketocamel(name) " = " value
|
|
||||||
print ""
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_enum_value(name, subname, value, cg, goname) {
|
|
||||||
goname = PrefixCamel name snaketocamel(subname)
|
|
||||||
append(cg, "fields",
|
|
||||||
"\t" goname " = " value "\n")
|
|
||||||
append(cg, "stringer",
|
|
||||||
"\tcase " goname ":\n" \
|
|
||||||
"\t\treturn `" snaketocamel(subname) "`\n")
|
|
||||||
append(cg, "marshal",
|
|
||||||
goname ",\n")
|
|
||||||
append(cg, "unmarshal",
|
|
||||||
"\tcase `" snaketocamel(subname) "`:\n" \
|
|
||||||
"\t\t*v = " goname "\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_enum(name, cg, gotype, fields) {
|
|
||||||
gotype = PrefixCamel name
|
|
||||||
print "type " gotype " int8"
|
|
||||||
print ""
|
|
||||||
|
|
||||||
print "const ("
|
|
||||||
print cg["fields"] ")"
|
|
||||||
print ""
|
|
||||||
|
|
||||||
print "func (v " gotype ") String() string {"
|
|
||||||
print "\tswitch v {"
|
|
||||||
print cg["stringer"] "\tdefault:"
|
|
||||||
print "\t\treturn strconv.Itoa(int(v))"
|
|
||||||
print "\t}"
|
|
||||||
print "}"
|
|
||||||
print ""
|
|
||||||
|
|
||||||
CodegenIsMarshaler[name] = 1
|
|
||||||
fields = cg["marshal"]
|
|
||||||
sub(/,\n$/, ":", fields)
|
|
||||||
gsub(/\n/, "\n\t", fields)
|
|
||||||
print "func (v " gotype ") MarshalJSON() ([]byte, error) {"
|
|
||||||
print "\tswitch v {"
|
|
||||||
print indent("case " fields)
|
|
||||||
print "\t\treturn []byte(`\"` + v.String() + `\"`), nil"
|
|
||||||
print "\t}"
|
|
||||||
print "\treturn json.Marshal(int(v))"
|
|
||||||
print "}"
|
|
||||||
print ""
|
|
||||||
|
|
||||||
print "func (v *" gotype ") UnmarshalJSON(data []byte) error {"
|
|
||||||
print "\tvar s string"
|
|
||||||
print "\tif json.Unmarshal(data, &s) == nil {"
|
|
||||||
print "\t\t// Handled below."
|
|
||||||
print "\t} else if n, err := protoUnmarshalEnumJSON(data); err != nil {"
|
|
||||||
print "\t\treturn err"
|
|
||||||
print "\t} else {"
|
|
||||||
print "\t\t*v = " gotype "(n)"
|
|
||||||
print "\t\treturn nil"
|
|
||||||
print "\t}"
|
|
||||||
print ""
|
|
||||||
print "\tswitch s {"
|
|
||||||
print cg["unmarshal"] "\tdefault:"
|
|
||||||
print "\t\treturn errors.New(`unrecognized value: ` + s)"
|
|
||||||
print "\t}"
|
|
||||||
print "\treturn nil"
|
|
||||||
print "}"
|
|
||||||
print ""
|
|
||||||
|
|
||||||
# XXX: This should also check if it isn't out-of-range for any reason,
|
|
||||||
# but our usage of sprintf() stands in the way a bit.
|
|
||||||
CodegenSerialize[name] = "\tdata = append(data, uint8(%s))\n"
|
|
||||||
CodegenDeserialize[name] = \
|
|
||||||
"\tif len(data) >= 1 {\n" \
|
|
||||||
"\t\t%s, data = " gotype "(data[0]), data[1:]\n" \
|
|
||||||
"\t} else {\n" \
|
|
||||||
"\t\treturn nil, false\n" \
|
|
||||||
"\t}\n"
|
|
||||||
|
|
||||||
CodegenGoType[name] = gotype
|
|
||||||
for (i in cg)
|
|
||||||
delete cg[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_marshal(type, f, marshal) {
|
|
||||||
if (CodegenAppendJSON[type])
|
|
||||||
return sprintf(CodegenAppendJSON[type], f)
|
|
||||||
|
|
||||||
# Complex types are json.Marshalers, there's no need to json.Marshal(&f).
|
|
||||||
if (CodegenIsMarshaler[type])
|
|
||||||
marshal = f ".MarshalJSON()"
|
|
||||||
else
|
|
||||||
marshal = "json.Marshal(" f ")"
|
|
||||||
|
|
||||||
return \
|
|
||||||
"\tif j, err := " marshal "; err != nil {\n" \
|
|
||||||
"\t\treturn nil, err\n" \
|
|
||||||
"\t} else {\n" \
|
|
||||||
"\t\tb = append(b, j...)\n" \
|
|
||||||
"\t}\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_struct_field_marshal(d, cg, camel, f, marshal) {
|
|
||||||
camel = snaketocamel(d["name"])
|
|
||||||
f = "s." camel
|
|
||||||
if (!d["isarray"]) {
|
|
||||||
append(cg, "marshal",
|
|
||||||
"\tb = append(b, `,\"" decapitalize(camel) "\":`...)\n" \
|
|
||||||
codegen_marshal(d["type"], f))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
# Note that we do not produce `null` for nil slices, unlike encoding/json.
|
|
||||||
# And arrays never get deserialized as such.
|
|
||||||
if (d["type"] == "u8") {
|
|
||||||
append(cg, "marshal",
|
|
||||||
"\tb = append(b, `,\"" decapitalize(camel) "\":\"`...)\n" \
|
|
||||||
"\tb = append(b, base64.StdEncoding.EncodeToString(" f ")...)\n" \
|
|
||||||
"\tb = append(b, '\"')\n")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
append(cg, "marshal",
|
|
||||||
"\tb = append(b, `,\"" decapitalize(camel) "\":[`...)\n" \
|
|
||||||
"\tfor i := 0; i < len(" f "); i++ {\n" \
|
|
||||||
"\t\tif i > 0 {\n" \
|
|
||||||
"\t\t\tb = append(b, ',')\n" \
|
|
||||||
"\t\t}\n" \
|
|
||||||
indent(codegen_marshal(d["type"], f "[i]")) \
|
|
||||||
"\t}\n" \
|
|
||||||
"\tb = append(b, ']')\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_struct_field(d, cg, camel, f, serialize, deserialize) {
|
|
||||||
codegen_struct_field_marshal(d, cg)
|
|
||||||
|
|
||||||
camel = snaketocamel(d["name"])
|
|
||||||
f = "s." camel
|
|
||||||
serialize = CodegenSerialize[d["type"]]
|
|
||||||
deserialize = CodegenDeserialize[d["type"]]
|
|
||||||
if (!d["isarray"]) {
|
|
||||||
append(cg, "fields", "\t" camel " " CodegenGoType[d["type"]] \
|
|
||||||
" `json:\"" decapitalize(camel) "\"`\n")
|
|
||||||
append(cg, "serialize", sprintf(serialize, f))
|
|
||||||
append(cg, "deserialize", sprintf(deserialize, f))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
append(cg, "fields", "\t" camel " []" CodegenGoType[d["type"]] \
|
|
||||||
" `json:\"" decapitalize(camel) "\"`\n")
|
|
||||||
|
|
||||||
# XXX: This should also check if it isn't out-of-range for any reason.
|
|
||||||
append(cg, "serialize",
|
|
||||||
sprintf(CodegenSerialize["u32"], "uint32(len(" f "))"))
|
|
||||||
if (d["type"] == "u8") {
|
|
||||||
append(cg, "serialize",
|
|
||||||
"\tdata = append(data, " f "...)\n")
|
|
||||||
} else {
|
|
||||||
append(cg, "serialize",
|
|
||||||
"\tfor i := 0; i < len(" f "); i++ {\n" \
|
|
||||||
indent(sprintf(serialize, f "[i]")) \
|
|
||||||
"\t}\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
append(cg, "deserialize",
|
|
||||||
"\t{\n" \
|
|
||||||
"\t\tvar length uint32\n" \
|
|
||||||
indent(sprintf(CodegenDeserialize["u32"], "length")))
|
|
||||||
if (d["type"] == "u8") {
|
|
||||||
append(cg, "deserialize",
|
|
||||||
"\t\tif uint64(len(data)) < uint64(length) {\n" \
|
|
||||||
"\t\t\treturn nil, false\n" \
|
|
||||||
"\t\t}\n" \
|
|
||||||
"\t\t" f ", data = data[:length], data[length:]\n" \
|
|
||||||
"\t}\n")
|
|
||||||
} else {
|
|
||||||
append(cg, "deserialize",
|
|
||||||
"\t\t" f " = make([]" CodegenGoType[d["type"]] ", length)\n" \
|
|
||||||
"\t}\n" \
|
|
||||||
"\tfor i := 0; i < len(" f "); i++ {\n" \
|
|
||||||
indent(sprintf(deserialize, f "[i]")) \
|
|
||||||
"\t}\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_struct_tag(d, cg, camel, f) {
|
|
||||||
codegen_struct_field_marshal(d, cg)
|
|
||||||
|
|
||||||
camel = snaketocamel(d["name"])
|
|
||||||
f = "s." camel
|
|
||||||
append(cg, "fields", "\t" camel " " CodegenGoType[d["type"]] \
|
|
||||||
" `json:\"" decapitalize(camel) "\"`\n")
|
|
||||||
append(cg, "serialize", sprintf(CodegenSerialize[d["type"]], f))
|
|
||||||
# Do not deserialize here, that is already done by the containing union.
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_struct(name, cg, gotype) {
|
|
||||||
gotype = PrefixCamel name
|
|
||||||
print "type " gotype " struct {\n" cg["fields"] "}\n"
|
|
||||||
|
|
||||||
if (cg["marshal"]) {
|
|
||||||
CodegenIsMarshaler[name] = 1
|
|
||||||
print "func (s *" gotype ") MarshalJSON() ([]byte, error) {"
|
|
||||||
print "\tb := []byte{}"
|
|
||||||
print cg["marshal"] "\tb[0] = '{'"
|
|
||||||
print "\treturn append(b, '}'), nil"
|
|
||||||
print "}"
|
|
||||||
print ""
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cg["serialize"]) {
|
|
||||||
print "func (s *" gotype ") AppendTo(data []byte) ([]byte, bool) {"
|
|
||||||
print "\tok := true"
|
|
||||||
print cg["serialize"] "\treturn data, ok"
|
|
||||||
print "}"
|
|
||||||
print ""
|
|
||||||
|
|
||||||
CodegenSerialize[name] = \
|
|
||||||
"\tif data, ok = %s.AppendTo(data); !ok {\n" \
|
|
||||||
"\t\treturn nil, ok\n" \
|
|
||||||
"\t}\n"
|
|
||||||
}
|
|
||||||
if (cg["deserialize"]) {
|
|
||||||
print "func (s *" gotype ") ConsumeFrom(data []byte) ([]byte, bool) {"
|
|
||||||
print "\tok := true"
|
|
||||||
print cg["deserialize"] "\treturn data, ok"
|
|
||||||
print "}"
|
|
||||||
print ""
|
|
||||||
|
|
||||||
CodegenDeserialize[name] = \
|
|
||||||
"\tif data, ok = %s.ConsumeFrom(data); !ok {\n" \
|
|
||||||
"\t\treturn nil, ok\n" \
|
|
||||||
"\t}\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
CodegenGoType[name] = gotype
|
|
||||||
for (i in cg)
|
|
||||||
delete cg[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_union_tag(d, cg) {
|
|
||||||
cg["tagtype"] = d["type"]
|
|
||||||
cg["tagname"] = d["name"]
|
|
||||||
# The tag is implied from the type of struct stored in the interface.
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_union_struct(name, casename, cg, scg, structname, init) {
|
|
||||||
# And thus not all generated structs are present in Types.
|
|
||||||
structname = name snaketocamel(casename)
|
|
||||||
codegen_struct(structname, scg)
|
|
||||||
|
|
||||||
init = CodegenGoType[structname] "{" snaketocamel(cg["tagname"]) \
|
|
||||||
": " decapitalize(snaketocamel(cg["tagname"])) "}"
|
|
||||||
append(cg, "unmarshal",
|
|
||||||
"\tcase " CodegenGoType[cg["tagtype"]] snaketocamel(casename) ":\n" \
|
|
||||||
"\t\ts := " init "\n" \
|
|
||||||
"\t\terr = json.Unmarshal(data, &s)\n" \
|
|
||||||
"\t\tu.Interface = &s\n")
|
|
||||||
append(cg, "serialize",
|
|
||||||
"\tcase *" CodegenGoType[structname] ":\n" \
|
|
||||||
indent(sprintf(CodegenSerialize[structname], "union")))
|
|
||||||
append(cg, "deserialize",
|
|
||||||
"\tcase " CodegenGoType[cg["tagtype"]] snaketocamel(casename) ":\n" \
|
|
||||||
"\t\ts := " init "\n" \
|
|
||||||
indent(sprintf(CodegenDeserialize[structname], "s")) \
|
|
||||||
"\t\tu.Interface = &s\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_union(name, cg, gotype, tagfield, tagvar) {
|
|
||||||
gotype = PrefixCamel name
|
|
||||||
print "type " gotype " struct {"
|
|
||||||
print "\tInterface any"
|
|
||||||
print "}"
|
|
||||||
print ""
|
|
||||||
|
|
||||||
# This cannot be a pointer method, it wouldn't work recursively.
|
|
||||||
CodegenIsMarshaler[name] = 1
|
|
||||||
print "func (u " gotype ") MarshalJSON() ([]byte, error) {"
|
|
||||||
print "\treturn u.Interface.(json.Marshaler).MarshalJSON()"
|
|
||||||
print "}"
|
|
||||||
print ""
|
|
||||||
|
|
||||||
tagfield = snaketocamel(cg["tagname"])
|
|
||||||
tagvar = decapitalize(tagfield)
|
|
||||||
print "func (u *" gotype ") UnmarshalJSON(data []byte) (err error) {"
|
|
||||||
print "\tvar t struct {"
|
|
||||||
print "\t\t" tagfield " " CodegenGoType[cg["tagtype"]] \
|
|
||||||
" `json:\"" tagvar "\"`"
|
|
||||||
print "\t}"
|
|
||||||
print "\tif err := json.Unmarshal(data, &t); err != nil {"
|
|
||||||
print "\t\treturn err"
|
|
||||||
print "\t}"
|
|
||||||
print ""
|
|
||||||
print "\tswitch " tagvar " := t." tagfield "; " tagvar " {"
|
|
||||||
print cg["unmarshal"] "\tdefault:"
|
|
||||||
print "\t\terr = errors.New(`unsupported value: ` + " tagvar ".String())"
|
|
||||||
print "\t}"
|
|
||||||
print "\treturn err"
|
|
||||||
print "}"
|
|
||||||
print ""
|
|
||||||
|
|
||||||
# XXX: Consider changing the interface into an AppendTo/ConsumeFrom one,
|
|
||||||
# that would eliminate these type case switches entirely.
|
|
||||||
# On the other hand, it would make it possible to send unsuitable structs.
|
|
||||||
print "func (u *" gotype ") AppendTo(data []byte) ([]byte, bool) {"
|
|
||||||
print "\tok := true"
|
|
||||||
print "\tswitch union := u.Interface.(type) {"
|
|
||||||
print cg["serialize"] "\tdefault:"
|
|
||||||
print "\t\treturn nil, false"
|
|
||||||
print "\t}"
|
|
||||||
print "\treturn data, ok"
|
|
||||||
print "}"
|
|
||||||
print ""
|
|
||||||
|
|
||||||
CodegenSerialize[name] = \
|
|
||||||
"\tif data, ok = %s.AppendTo(data); !ok {\n" \
|
|
||||||
"\t\treturn nil, ok\n" \
|
|
||||||
"\t}\n"
|
|
||||||
|
|
||||||
print "func (u *" gotype ") ConsumeFrom(data []byte) ([]byte, bool) {"
|
|
||||||
print "\tok := true"
|
|
||||||
print "\tvar " tagvar " " CodegenGoType[cg["tagtype"]]
|
|
||||||
print sprintf(CodegenDeserialize[cg["tagtype"]], tagvar)
|
|
||||||
print "\tswitch " tagvar " {"
|
|
||||||
print cg["deserialize"] "\tdefault:"
|
|
||||||
print "\t\treturn nil, false"
|
|
||||||
print "\t}"
|
|
||||||
print "\treturn data, ok"
|
|
||||||
print "}"
|
|
||||||
print ""
|
|
||||||
|
|
||||||
CodegenDeserialize[name] = \
|
|
||||||
"\tif data, ok = %s.ConsumeFrom(data); !ok {\n" \
|
|
||||||
"\t\treturn nil, ok\n" \
|
|
||||||
"\t}\n"
|
|
||||||
|
|
||||||
CodegenGoType[name] = gotype
|
|
||||||
for (i in cg)
|
|
||||||
delete cg[i]
|
|
||||||
}
|
|
||||||
@@ -1,223 +0,0 @@
|
|||||||
# xC-gen-proto-js.awk: Javascript backend for xC-gen-proto.awk.
|
|
||||||
#
|
|
||||||
# Copyright (c) 2022, Přemysl Eric Janouch <p@janouch.name>
|
|
||||||
# SPDX-License-Identifier: 0BSD
|
|
||||||
#
|
|
||||||
# This backend is currently for decoding the binary format only.
|
|
||||||
# (JSON is way too expensive to process and transfer.)
|
|
||||||
#
|
|
||||||
# Import the resulting script as a Javascript module.
|
|
||||||
|
|
||||||
function define_internal(name) {
|
|
||||||
Types[name] = "internal"
|
|
||||||
}
|
|
||||||
|
|
||||||
function define_sint(size, shortname) {
|
|
||||||
shortname = "i" size
|
|
||||||
define_internal(shortname)
|
|
||||||
CodegenDeserialize[shortname] = "\t%s = r." shortname "()\n"
|
|
||||||
|
|
||||||
print ""
|
|
||||||
print "\t" shortname "() {"
|
|
||||||
if (size == "64") {
|
|
||||||
# XXX: 2^53 - 1 must be enough for anyone. BigInts are a PITA.
|
|
||||||
print "\t\tconst " shortname \
|
|
||||||
" = Number(this.getBigInt" size "(this.offset))"
|
|
||||||
} else {
|
|
||||||
print "\t\tconst " shortname " = this.getInt" size "(this.offset)"
|
|
||||||
}
|
|
||||||
print "\t\tthis.offset += " (size / 8)
|
|
||||||
print "\t\treturn " shortname
|
|
||||||
print "\t}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function define_uint(size, shortname) {
|
|
||||||
shortname = "u" size
|
|
||||||
define_internal(shortname)
|
|
||||||
CodegenDeserialize[shortname] = "\t%s = r." shortname "()\n"
|
|
||||||
|
|
||||||
print ""
|
|
||||||
print "\t" shortname "() {"
|
|
||||||
if (size == "64") {
|
|
||||||
# XXX: 2^53 - 1 must be enough for anyone. BigInts are a PITA.
|
|
||||||
print "\t\tconst " shortname \
|
|
||||||
" = Number(this.getBigUint" size "(this.offset))"
|
|
||||||
} else {
|
|
||||||
print "\t\tconst " shortname " = this.getUint" size "(this.offset)"
|
|
||||||
}
|
|
||||||
print "\t\tthis.offset += " (size / 8)
|
|
||||||
print "\t\treturn " shortname
|
|
||||||
print "\t}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_begin() {
|
|
||||||
print "export class Reader extends DataView {"
|
|
||||||
print "\tconstructor() {"
|
|
||||||
print "\t\tsuper(...arguments)"
|
|
||||||
print "\t\tthis.offset = 0"
|
|
||||||
print "\t\tthis.decoder = new TextDecoder('utf-8', {fatal: true})"
|
|
||||||
print "\t}"
|
|
||||||
print ""
|
|
||||||
print "\tget empty() {"
|
|
||||||
print "\t\treturn this.byteLength <= this.offset"
|
|
||||||
print "\t}"
|
|
||||||
print ""
|
|
||||||
print "\trequire(len) {"
|
|
||||||
print "\t\tif (this.byteLength - this.offset < len)"
|
|
||||||
print "\t\t\tthrow `Premature end of data`"
|
|
||||||
print "\t\treturn this.byteOffset + this.offset"
|
|
||||||
print "\t}"
|
|
||||||
|
|
||||||
define_internal("string")
|
|
||||||
CodegenDeserialize["string"] = "\t%s = r.string()\n"
|
|
||||||
|
|
||||||
print ""
|
|
||||||
print "\tstring() {"
|
|
||||||
print "\t\tconst len = this.getUint32(this.offset)"
|
|
||||||
print "\t\tthis.offset += 4"
|
|
||||||
print "\t\tconst array = new Uint8Array("
|
|
||||||
print "\t\t\tthis.buffer, this.require(len), len)"
|
|
||||||
print "\t\tthis.offset += len"
|
|
||||||
print "\t\treturn this.decoder.decode(array)"
|
|
||||||
print "\t}"
|
|
||||||
|
|
||||||
define_internal("bool")
|
|
||||||
CodegenDeserialize["bool"] = "\t%s = r.bool()\n"
|
|
||||||
|
|
||||||
print ""
|
|
||||||
print "\tbool() {"
|
|
||||||
print "\t\tconst u8 = this.getUint8(this.offset)"
|
|
||||||
print "\t\tthis.offset += 1"
|
|
||||||
print "\t\treturn u8 != 0"
|
|
||||||
print "\t}"
|
|
||||||
|
|
||||||
define_sint("8")
|
|
||||||
define_sint("16")
|
|
||||||
define_sint("32")
|
|
||||||
define_sint("64")
|
|
||||||
define_uint("8")
|
|
||||||
define_uint("16")
|
|
||||||
define_uint("32")
|
|
||||||
define_uint("64")
|
|
||||||
|
|
||||||
print "}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_constant(name, value) {
|
|
||||||
print ""
|
|
||||||
print "export const " decapitalize(snaketocamel(name)) " = " value
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_enum_value(name, subname, value, cg) {
|
|
||||||
append(cg, "fields", "\t" snaketocamel(subname) ": " value ",\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_enum(name, cg) {
|
|
||||||
print ""
|
|
||||||
print "export const " name " = Object.freeze({"
|
|
||||||
print cg["fields"] "})"
|
|
||||||
|
|
||||||
CodegenDeserialize[name] = "\t%s = r.i8()\n"
|
|
||||||
for (i in cg)
|
|
||||||
delete cg[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_struct_field(d, cg, camel, f, deserialize) {
|
|
||||||
camel = decapitalize(snaketocamel(d["name"]))
|
|
||||||
f = "s." camel
|
|
||||||
append(cg, "fields", "\t" camel "\n")
|
|
||||||
|
|
||||||
deserialize = CodegenDeserialize[d["type"]]
|
|
||||||
if (!d["isarray"]) {
|
|
||||||
append(cg, "deserialize", sprintf(deserialize, f))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
append(cg, "deserialize",
|
|
||||||
"\t{\n" \
|
|
||||||
indent(sprintf(CodegenDeserialize["u32"], "const len")))
|
|
||||||
if (d["type"] == "u8") {
|
|
||||||
append(cg, "deserialize",
|
|
||||||
"\t\t" f " = new Uint8Array(\n" \
|
|
||||||
"\t\t\tr.buffer, r.require(len), len)\n" \
|
|
||||||
"\t\tr.offset += len\n" \
|
|
||||||
"\t}\n")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (d["type"] == "i8") {
|
|
||||||
append(cg, "deserialize",
|
|
||||||
"\t\t" f " = new Int8Array(\n" \
|
|
||||||
"\t\t\tr.buffer, r.require(len), len)\n" \
|
|
||||||
"\t\tr.offset += len\n" \
|
|
||||||
"\t}\n")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
append(cg, "deserialize",
|
|
||||||
"\t\t" f " = new Array(len)\n" \
|
|
||||||
"\t}\n" \
|
|
||||||
"\tfor (let i = 0; i < " f ".length; i++)\n" \
|
|
||||||
indent(sprintf(deserialize, f "[i]")))
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_struct_tag(d, cg) {
|
|
||||||
append(cg, "fields", "\t" decapitalize(snaketocamel(d["name"])) "\n")
|
|
||||||
# Do not deserialize here, that is already done by the containing union.
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_struct(name, cg) {
|
|
||||||
print ""
|
|
||||||
print "export class " name " {"
|
|
||||||
print cg["fields"] cg["methods"]
|
|
||||||
print "\tstatic deserialize(r) {"
|
|
||||||
print "\t\tconst s = new " name "()"
|
|
||||||
print indent(cg["deserialize"]) "\t\treturn s"
|
|
||||||
print "\t}"
|
|
||||||
print "}"
|
|
||||||
|
|
||||||
CodegenDeserialize[name] = "\t%s = " name ".deserialize(r)\n"
|
|
||||||
for (i in cg)
|
|
||||||
delete cg[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_union_tag(d, cg) {
|
|
||||||
cg["tagtype"] = d["type"]
|
|
||||||
cg["tagname"] = d["name"]
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_union_struct(name, casename, cg, scg, structname) {
|
|
||||||
append(scg, "methods",
|
|
||||||
"\n" \
|
|
||||||
"\tconstructor() {\n" \
|
|
||||||
"\t\tthis." decapitalize(snaketocamel(cg["tagname"])) \
|
|
||||||
" = " cg["tagtype"] "." snaketocamel(casename) "\n" \
|
|
||||||
"\t}\n")
|
|
||||||
|
|
||||||
# And thus not all generated structs are present in Types.
|
|
||||||
structname = name snaketocamel(casename)
|
|
||||||
codegen_struct(structname, scg)
|
|
||||||
|
|
||||||
append(cg, "deserialize",
|
|
||||||
"\tcase " cg["tagtype"] "." snaketocamel(casename) ":\n" \
|
|
||||||
"\t{\n" \
|
|
||||||
indent(sprintf(CodegenDeserialize[structname], "const s")) \
|
|
||||||
"\t\treturn s\n" \
|
|
||||||
"\t}\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
function codegen_union(name, cg, tagvar) {
|
|
||||||
tagvar = decapitalize(snaketocamel(cg["tagname"]))
|
|
||||||
|
|
||||||
print ""
|
|
||||||
print "export function deserialize" name "(r) {"
|
|
||||||
print sprintf(CodegenDeserialize[cg["tagtype"]], "const " tagvar) \
|
|
||||||
"\tswitch (" tagvar ") {"
|
|
||||||
print cg["deserialize"] "\tdefault:"
|
|
||||||
print "\t\tthrow `Unknown " cg["tagtype"] " (${tagvar})`"
|
|
||||||
print "\t}"
|
|
||||||
print "}"
|
|
||||||
|
|
||||||
CodegenDeserialize[name] = "\t%s = deserialize" name "(r)\n"
|
|
||||||
for (i in cg)
|
|
||||||
delete cg[i]
|
|
||||||
}
|
|
||||||
305
xC-gen-proto.awk
305
xC-gen-proto.awk
@@ -1,305 +0,0 @@
|
|||||||
# xC-gen-proto.awk: an XDR-derived code generator for network protocols.
|
|
||||||
#
|
|
||||||
# Copyright (c) 2022, Přemysl Eric Janouch <p@janouch.name>
|
|
||||||
# SPDX-License-Identifier: 0BSD
|
|
||||||
#
|
|
||||||
# You may read RFC 4506 for context, however it is only a source of inspiration.
|
|
||||||
# Grammar is easy to deduce from the parser.
|
|
||||||
#
|
|
||||||
# Native types: bool, u{8,16,32,64}, i{8,16,32,64}, string
|
|
||||||
#
|
|
||||||
# Don't define any new types, unless you hate yourself, then it's okay to do so.
|
|
||||||
# Backends tend to be a pain in the arse, for different reasons.
|
|
||||||
#
|
|
||||||
# All numbers are encoded in big-endian byte order.
|
|
||||||
# Booleans are one byte each.
|
|
||||||
# Strings must be valid UTF-8, use u8<> to lift that restriction.
|
|
||||||
# String and array lengths are encoded as u32.
|
|
||||||
# Enumeration values automatically start at 1, and are encoded as i8.
|
|
||||||
# Any struct or union field may be a variable-length array.
|
|
||||||
#
|
|
||||||
# Message framing is done externally, but also happens to prefix u32 lengths,
|
|
||||||
# unless this role is already filled by, e.g., WebSocket.
|
|
||||||
#
|
|
||||||
# Usage: env LC_ALL=C awk -f xC-gen-proto.awk -f xC-gen-proto-{c,go,js}.awk \
|
|
||||||
# xC-proto > xC-proto.{c,go,js} | {clang-format,gofmt,...}
|
|
||||||
|
|
||||||
# --- Utilities ----------------------------------------------------------------
|
|
||||||
|
|
||||||
function cameltosnake(s) {
|
|
||||||
while (match(s, /[[:lower:]][[:upper:]]/)) {
|
|
||||||
s = substr(s, 1, RSTART) "_" \
|
|
||||||
tolower(substr(s, RSTART + 1, RLENGTH - 1)) \
|
|
||||||
substr(s, RSTART + RLENGTH)
|
|
||||||
}
|
|
||||||
return tolower(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
function snaketocamel(s) {
|
|
||||||
s = toupper(substr(s, 1, 1)) tolower(substr(s, 2))
|
|
||||||
while (match(s, /_[[:alnum:]]/)) {
|
|
||||||
s = substr(s, 1, RSTART - 1) \
|
|
||||||
toupper(substr(s, RSTART + 1, RLENGTH - 1)) \
|
|
||||||
substr(s, RSTART + RLENGTH)
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
function decapitalize(s) {
|
|
||||||
if (match(s, /[[:upper:]][[:lower:]]/)) {
|
|
||||||
return tolower(substr(s, 1, 1)) substr(s, 2)
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
function indent(s) {
|
|
||||||
if (!s)
|
|
||||||
return s
|
|
||||||
|
|
||||||
gsub(/\n/, "\n\t", s)
|
|
||||||
sub(/\t*$/, "", s)
|
|
||||||
return "\t" s
|
|
||||||
}
|
|
||||||
|
|
||||||
function append(a, key, value) {
|
|
||||||
a[key] = a[key] value
|
|
||||||
}
|
|
||||||
|
|
||||||
# --- Parsing ------------------------------------------------------------------
|
|
||||||
|
|
||||||
function fatal(message) {
|
|
||||||
print "// " FILENAME ":" FNR ": fatal error: " message
|
|
||||||
print FILENAME ":" FNR ": fatal error: " message > "/dev/stderr"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
function skipcomment() {
|
|
||||||
do {
|
|
||||||
if (match($0, /[*][/]/)) {
|
|
||||||
$0 = substr($0, RSTART + RLENGTH)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} while (getline > 0)
|
|
||||||
fatal("unterminated block comment")
|
|
||||||
}
|
|
||||||
|
|
||||||
function nexttoken() {
|
|
||||||
do {
|
|
||||||
if (match($0, /^[[:space:]]+/)) {
|
|
||||||
$0 = substr($0, RLENGTH + 1)
|
|
||||||
} else if (match($0, /^[/][/].*/)) {
|
|
||||||
$0 = ""
|
|
||||||
} else if (match($0, /^[/][*]/)) {
|
|
||||||
$0 = substr($0, RLENGTH + 1)
|
|
||||||
skipcomment()
|
|
||||||
} else if (match($0, /^[[:alpha:]][[:alnum:]_]*/)) {
|
|
||||||
Token = substr($0, 1, RLENGTH)
|
|
||||||
$0 = substr($0, RLENGTH + 1)
|
|
||||||
return Token
|
|
||||||
} else if (match($0, /^(0[xX][0-9a-fA-F]+|[1-9][0-9]*)/)) {
|
|
||||||
Token = substr($0, 1, RLENGTH)
|
|
||||||
$0 = substr($0, RLENGTH + 1)
|
|
||||||
return Token
|
|
||||||
} else if (/./) {
|
|
||||||
Token = substr($0, 1, 1)
|
|
||||||
$0 = substr($0, 2)
|
|
||||||
return Token
|
|
||||||
}
|
|
||||||
} while (/./ || getline > 0)
|
|
||||||
Token = ""
|
|
||||||
return Token
|
|
||||||
}
|
|
||||||
|
|
||||||
function expect(v) {
|
|
||||||
if (!v)
|
|
||||||
fatal("broken expectations at `" Token "' before `" $0 "'")
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
function accept(what) {
|
|
||||||
if (Token != what)
|
|
||||||
return 0
|
|
||||||
nexttoken()
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
function identifier( v) {
|
|
||||||
if (Token !~ /^[[:alpha:]]/)
|
|
||||||
return 0
|
|
||||||
v = Token
|
|
||||||
nexttoken()
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
function number( v) {
|
|
||||||
if (Token !~ /^[0-9]/)
|
|
||||||
return 0
|
|
||||||
v = Token
|
|
||||||
nexttoken()
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
function readnumber( ident) {
|
|
||||||
ident = identifier()
|
|
||||||
if (!ident)
|
|
||||||
return expect(number())
|
|
||||||
if (!(ident in Consts))
|
|
||||||
fatal("unknown constant: " ident)
|
|
||||||
return Consts[ident]
|
|
||||||
}
|
|
||||||
|
|
||||||
function defconst( ident, num) {
|
|
||||||
if (!accept("const"))
|
|
||||||
return 0
|
|
||||||
|
|
||||||
ident = expect(identifier())
|
|
||||||
expect(accept("="))
|
|
||||||
num = readnumber()
|
|
||||||
if (ident in Consts)
|
|
||||||
fatal("constant redefined: " ident)
|
|
||||||
|
|
||||||
Consts[ident] = num
|
|
||||||
codegen_constant(ident, num)
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
function readtype( ident) {
|
|
||||||
ident = deftype()
|
|
||||||
if (ident)
|
|
||||||
return ident
|
|
||||||
|
|
||||||
ident = identifier()
|
|
||||||
if (!ident)
|
|
||||||
return 0
|
|
||||||
|
|
||||||
if (!(ident in Types))
|
|
||||||
fatal("unknown type: " ident)
|
|
||||||
return ident
|
|
||||||
}
|
|
||||||
|
|
||||||
function defenum( name, ident, value, cg) {
|
|
||||||
delete cg[0]
|
|
||||||
|
|
||||||
name = expect(identifier())
|
|
||||||
expect(accept("{"))
|
|
||||||
while (!accept("}")) {
|
|
||||||
ident = expect(identifier())
|
|
||||||
value = value + 1
|
|
||||||
if (accept("="))
|
|
||||||
value = readnumber()
|
|
||||||
if (!value)
|
|
||||||
fatal("enumeration values cannot be zero")
|
|
||||||
if (value < -128 || value > 127)
|
|
||||||
fatal("enumeration value out of range")
|
|
||||||
expect(accept(","))
|
|
||||||
append(EnumValues, name, SUBSEP ident)
|
|
||||||
if (EnumValues[name, ident]++)
|
|
||||||
fatal("duplicate enum value: " ident)
|
|
||||||
codegen_enum_value(name, ident, value, cg)
|
|
||||||
}
|
|
||||||
|
|
||||||
Types[name] = "enum"
|
|
||||||
codegen_enum(name, cg)
|
|
||||||
return name
|
|
||||||
}
|
|
||||||
|
|
||||||
function readfield(out, nonvoid) {
|
|
||||||
nonvoid = !accept("void")
|
|
||||||
if (nonvoid) {
|
|
||||||
out["type"] = expect(readtype())
|
|
||||||
out["name"] = expect(identifier())
|
|
||||||
# TODO: Consider supporting XDR's VLA length limits here.
|
|
||||||
# TODO: Consider supporting XDR's fixed-length syntax for string limits.
|
|
||||||
out["isarray"] = accept("<") && expect(accept(">"))
|
|
||||||
}
|
|
||||||
expect(accept(";"))
|
|
||||||
return nonvoid
|
|
||||||
}
|
|
||||||
|
|
||||||
function defstruct( name, d, cg) {
|
|
||||||
delete d[0]
|
|
||||||
delete cg[0]
|
|
||||||
|
|
||||||
name = expect(identifier())
|
|
||||||
expect(accept("{"))
|
|
||||||
while (!accept("}")) {
|
|
||||||
if (readfield(d))
|
|
||||||
codegen_struct_field(d, cg)
|
|
||||||
}
|
|
||||||
|
|
||||||
Types[name] = "struct"
|
|
||||||
codegen_struct(name, cg)
|
|
||||||
return name
|
|
||||||
}
|
|
||||||
|
|
||||||
function defunion( name, tag, tagtype, tagvalue, cg, scg, d, a, i, unseen) {
|
|
||||||
delete cg[0]
|
|
||||||
delete scg[0]
|
|
||||||
delete d[0]
|
|
||||||
|
|
||||||
name = expect(identifier())
|
|
||||||
expect(accept("switch"))
|
|
||||||
expect(accept("("))
|
|
||||||
tag["type"] = tagtype = expect(readtype())
|
|
||||||
tag["name"] = expect(identifier())
|
|
||||||
expect(accept(")"))
|
|
||||||
|
|
||||||
if (Types[tagtype] != "enum")
|
|
||||||
fatal("not an enum type: " tagtype)
|
|
||||||
codegen_union_tag(tag, cg)
|
|
||||||
|
|
||||||
split(EnumValues[tagtype], a, SUBSEP)
|
|
||||||
for (i in a)
|
|
||||||
unseen[a[i]]++
|
|
||||||
|
|
||||||
expect(accept("{"))
|
|
||||||
while (!accept("}")) {
|
|
||||||
if (accept("case")) {
|
|
||||||
if (tagvalue)
|
|
||||||
codegen_union_struct(name, tagvalue, cg, scg)
|
|
||||||
|
|
||||||
tagvalue = expect(identifier())
|
|
||||||
expect(accept(":"))
|
|
||||||
if (!unseen[tagvalue]--)
|
|
||||||
fatal("no such value or duplicate case: " tagtype "." tagvalue)
|
|
||||||
codegen_struct_tag(tag, scg)
|
|
||||||
} else if (tagvalue) {
|
|
||||||
if (readfield(d))
|
|
||||||
codegen_struct_field(d, scg)
|
|
||||||
} else {
|
|
||||||
fatal("union fields must fall under a case")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (tagvalue)
|
|
||||||
codegen_union_struct(name, tagvalue, cg, scg)
|
|
||||||
|
|
||||||
# What remains non-zero in unseen[2..] is simply not recognized/allowed.
|
|
||||||
Types[name] = "union"
|
|
||||||
codegen_union(name, cg)
|
|
||||||
return name
|
|
||||||
}
|
|
||||||
|
|
||||||
function deftype() {
|
|
||||||
if (accept("enum"))
|
|
||||||
return defenum()
|
|
||||||
if (accept("struct"))
|
|
||||||
return defstruct()
|
|
||||||
if (accept("union"))
|
|
||||||
return defunion()
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
BEGIN {
|
|
||||||
PrefixLower = "relay_"
|
|
||||||
PrefixUpper = "RELAY_"
|
|
||||||
PrefixCamel = "Relay"
|
|
||||||
|
|
||||||
print "// Generated by xC-gen-proto.awk. DO NOT MODIFY."
|
|
||||||
codegen_begin()
|
|
||||||
|
|
||||||
nexttoken()
|
|
||||||
while (Token != "") {
|
|
||||||
expect(defconst() || deftype())
|
|
||||||
expect(accept(";"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
268
xC.c
268
xC.c
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* xC.c: a terminal-based IRC client
|
* xC.c: a terminal-based IRC client
|
||||||
*
|
*
|
||||||
* Copyright (c) 2015 - 2022, Přemysl Eric Janouch <p@janouch.name>
|
* Copyright (c) 2015 - 2024, Přemysl Eric Janouch <p@janouch.name>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted.
|
* purpose with or without fee is hereby granted.
|
||||||
@@ -50,6 +50,7 @@ enum
|
|||||||
|
|
||||||
// fmemopen
|
// fmemopen
|
||||||
#define _POSIX_C_SOURCE 200809L
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#define _XOPEN_SOURCE 700
|
||||||
|
|
||||||
#include "common.c"
|
#include "common.c"
|
||||||
#include "xD-replies.c"
|
#include "xD-replies.c"
|
||||||
@@ -228,9 +229,13 @@ struct input_vtable
|
|||||||
/// Create a new input buffer
|
/// Create a new input buffer
|
||||||
input_buffer_t (*buffer_new) (void *input);
|
input_buffer_t (*buffer_new) (void *input);
|
||||||
/// Destroy an input buffer
|
/// Destroy an input buffer
|
||||||
void (*buffer_destroy) (void *input, input_buffer_t buffer);
|
void (*buffer_destroy) (void *input, input_buffer_t);
|
||||||
/// Switch to a different input buffer
|
/// Switch to a different input buffer
|
||||||
void (*buffer_switch) (void *input, input_buffer_t buffer);
|
void (*buffer_switch) (void *input, input_buffer_t);
|
||||||
|
/// Return all history lines in the locale encoding
|
||||||
|
struct strv (*buffer_get_history) (void *input, input_buffer_t);
|
||||||
|
/// Add a history line in the locale encoding
|
||||||
|
void (*buffer_add_history) (void *input, input_buffer_t, const char *);
|
||||||
|
|
||||||
/// Register a function that can be bound to character sequences
|
/// Register a function that can be bound to character sequences
|
||||||
void (*register_fn) (void *input,
|
void (*register_fn) (void *input,
|
||||||
@@ -259,6 +264,7 @@ struct input_vtable
|
|||||||
XX (start) XX (stop) XX (prepare) XX (destroy) \
|
XX (start) XX (stop) XX (prepare) XX (destroy) \
|
||||||
XX (hide) XX (show) XX (get_prompt) XX (set_prompt) XX (ding) \
|
XX (hide) XX (show) XX (get_prompt) XX (set_prompt) XX (ding) \
|
||||||
XX (buffer_new) XX (buffer_destroy) XX (buffer_switch) \
|
XX (buffer_new) XX (buffer_destroy) XX (buffer_switch) \
|
||||||
|
XX (buffer_get_history) XX (buffer_add_history) \
|
||||||
XX (register_fn) XX (bind) XX (bind_control) XX (bind_meta) \
|
XX (register_fn) XX (bind) XX (bind_control) XX (bind_meta) \
|
||||||
XX (get_line) XX (clear_line) XX (insert) \
|
XX (get_line) XX (clear_line) XX (insert) \
|
||||||
XX (on_tty_resized) XX (on_tty_readable)
|
XX (on_tty_resized) XX (on_tty_readable)
|
||||||
@@ -562,6 +568,7 @@ input_rl_buffer_switch (void *input, input_buffer_t input_buffer)
|
|||||||
{
|
{
|
||||||
struct input_rl *self = input;
|
struct input_rl *self = input;
|
||||||
struct input_rl_buffer *buffer = input_buffer;
|
struct input_rl_buffer *buffer = input_buffer;
|
||||||
|
|
||||||
// There could possibly be occurences of the current undo list in some
|
// There could possibly be occurences of the current undo list in some
|
||||||
// history entry. We either need to free the undo list, or move it
|
// history entry. We either need to free the undo list, or move it
|
||||||
// somewhere else to load back later, as the buffer we're switching to
|
// somewhere else to load back later, as the buffer we're switching to
|
||||||
@@ -584,6 +591,38 @@ input_rl_buffer_switch (void *input, input_buffer_t input_buffer)
|
|||||||
self->current = buffer;
|
self->current = buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct strv
|
||||||
|
input_rl_buffer_get_history (void *input, input_buffer_t input_buffer)
|
||||||
|
{
|
||||||
|
(void) input;
|
||||||
|
struct input_rl_buffer *buffer = input_buffer;
|
||||||
|
HIST_ENTRY **p =
|
||||||
|
buffer->history ? buffer->history->entries : history_list();
|
||||||
|
struct strv v = strv_make ();
|
||||||
|
while (p && *p)
|
||||||
|
strv_append (&v, (*p++)->line);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
input_rl_buffer_add_history (void *input, input_buffer_t input_buffer,
|
||||||
|
const char *line)
|
||||||
|
{
|
||||||
|
(void) input;
|
||||||
|
struct input_rl_buffer *buffer = input_buffer;
|
||||||
|
|
||||||
|
// For inactive buffers, we'd have to either alloc_history_entry(),
|
||||||
|
// construe a timestamp, and manually insert it into saved HISTORY_STATEs,
|
||||||
|
// or temporarily switch histories.
|
||||||
|
if (!buffer->history)
|
||||||
|
{
|
||||||
|
bool at_end = where_history () == history_length;
|
||||||
|
add_history (line);
|
||||||
|
if (at_end)
|
||||||
|
next_history ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
input_rl__buffer_destroy_wo_history (struct input_rl_buffer *self)
|
input_rl__buffer_destroy_wo_history (struct input_rl_buffer *self)
|
||||||
{
|
{
|
||||||
@@ -1055,10 +1094,55 @@ input_el_buffer_switch (void *input, input_buffer_t input_buffer)
|
|||||||
|
|
||||||
self->current = buffer;
|
self->current = buffer;
|
||||||
el_wset (self->editline, EL_HIST, history, buffer->history);
|
el_wset (self->editline, EL_HIST, history, buffer->history);
|
||||||
|
// We only know how to reset the history position to be at the end.
|
||||||
input_el__start_over (self);
|
input_el__start_over (self);
|
||||||
input_el__restore_buffer (self, buffer);
|
input_el__restore_buffer (self, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct strv
|
||||||
|
input_el_buffer_get_history (void *input, input_buffer_t input_buffer)
|
||||||
|
{
|
||||||
|
(void) input;
|
||||||
|
struct input_el_buffer *buffer = input_buffer;
|
||||||
|
struct strv v = strv_make ();
|
||||||
|
HistEventW ev;
|
||||||
|
if (history_w (buffer->history, &ev, H_LAST) < 0)
|
||||||
|
return v;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
size_t len = wcstombs (NULL, ev.str, 0);
|
||||||
|
if (len++ == (size_t) -1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
char *mb = xmalloc (len);
|
||||||
|
mb[wcstombs (mb, ev.str, len)] = 0;
|
||||||
|
strv_append_owned (&v, mb);
|
||||||
|
}
|
||||||
|
while (history_w (buffer->history, &ev, H_PREV) >= 0);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
input_el_buffer_add_history (void *input, input_buffer_t input_buffer,
|
||||||
|
const char *line)
|
||||||
|
{
|
||||||
|
(void) input;
|
||||||
|
struct input_el_buffer *buffer = input_buffer;
|
||||||
|
|
||||||
|
// When currently iterating history, this makes editline's internal
|
||||||
|
// history pointer wrongly point to a newer entry.
|
||||||
|
size_t len = mbstowcs (NULL, line, 0);
|
||||||
|
if (len++ != (size_t) -1)
|
||||||
|
{
|
||||||
|
wchar_t *wc = xcalloc (len, sizeof *wc);
|
||||||
|
wc[mbstowcs (wc, line, len)] = 0;
|
||||||
|
HistEventW ev;
|
||||||
|
(void) history_w (buffer->history, &ev, H_ENTER, wc);
|
||||||
|
free (wc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
input_el_buffer_destroy (void *input, input_buffer_t input_buffer)
|
input_el_buffer_destroy (void *input, input_buffer_t input_buffer)
|
||||||
{
|
{
|
||||||
@@ -2862,12 +2946,15 @@ relay_send (struct client *c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
relay_broadcast (struct app_context *ctx)
|
relay_broadcast_except (struct app_context *ctx, struct client *exception)
|
||||||
{
|
{
|
||||||
LIST_FOR_EACH (struct client, c, ctx->clients)
|
LIST_FOR_EACH (struct client, c, ctx->clients)
|
||||||
relay_send (c);
|
if (c != exception)
|
||||||
|
relay_send (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define relay_broadcast(ctx) relay_broadcast_except ((ctx), NULL)
|
||||||
|
|
||||||
static struct relay_event_message *
|
static struct relay_event_message *
|
||||||
relay_prepare (struct app_context *ctx)
|
relay_prepare (struct app_context *ctx)
|
||||||
{
|
{
|
||||||
@@ -3092,6 +3179,17 @@ relay_prepare_buffer_activate (struct app_context *ctx, struct buffer *buffer)
|
|||||||
e->buffer_name = str_from_cstr (buffer->name);
|
e->buffer_name = str_from_cstr (buffer->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
relay_prepare_buffer_input (struct app_context *ctx, struct buffer *buffer,
|
||||||
|
const char *input)
|
||||||
|
{
|
||||||
|
struct relay_event_message *m = relay_prepare (ctx);
|
||||||
|
struct relay_event_data_buffer_input *e = &m->data.buffer_input;
|
||||||
|
e->event = RELAY_EVENT_BUFFER_INPUT;
|
||||||
|
e->buffer_name = str_from_cstr (buffer->name);
|
||||||
|
e->text = str_from_cstr (input);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
relay_prepare_buffer_clear (struct app_context *ctx,
|
relay_prepare_buffer_clear (struct app_context *ctx,
|
||||||
struct buffer *buffer)
|
struct buffer *buffer)
|
||||||
@@ -4612,34 +4710,30 @@ log_formatter (struct app_context *ctx, struct buffer *buffer,
|
|||||||
&& buffer->type == BUFFER_SERVER)
|
&& buffer->type == BUFFER_SERVER)
|
||||||
|| (ctx->current_buffer->type != BUFFER_GLOBAL
|
|| (ctx->current_buffer->type != BUFFER_GLOBAL
|
||||||
&& buffer == ctx->current_buffer->server->buffer))
|
&& buffer == ctx->current_buffer->server->buffer))
|
||||||
can_leak = true;
|
can_leak = !ctx->isolate_buffers;
|
||||||
|
|
||||||
relay_prepare_buffer_line (ctx, buffer, line,
|
bool leak_to_active = buffer != ctx->current_buffer && can_leak;
|
||||||
buffer != ctx->current_buffer && !ctx->isolate_buffers && can_leak);
|
relay_prepare_buffer_line (ctx, buffer, line, leak_to_active);
|
||||||
relay_broadcast (ctx);
|
relay_broadcast (ctx);
|
||||||
|
|
||||||
bool displayed = true;
|
bool visible = (buffer == ctx->current_buffer || leak_to_active)
|
||||||
if (ctx->terminal_suspended > 0)
|
&& ctx->terminal_suspended <= 0;
|
||||||
// Another process is using the terminal
|
|
||||||
displayed = false;
|
|
||||||
else if (buffer == ctx->current_buffer)
|
|
||||||
buffer_line_display (ctx, buffer, line, false);
|
|
||||||
else if (!ctx->isolate_buffers && can_leak)
|
|
||||||
buffer_line_display (ctx, buffer, line, true);
|
|
||||||
else
|
|
||||||
displayed = false;
|
|
||||||
|
|
||||||
// Advance the unread marker in active buffers but don't create a new one
|
// Advance the unread marker but don't create a new one
|
||||||
if (!displayed
|
if (!visible || buffer->new_messages_count)
|
||||||
|| (buffer == ctx->current_buffer && buffer->new_messages_count))
|
|
||||||
{
|
{
|
||||||
buffer->new_messages_count++;
|
buffer->new_messages_count++;
|
||||||
if (flags & BUFFER_LINE_UNIMPORTANT)
|
if ((flags & BUFFER_LINE_UNIMPORTANT) || leak_to_active)
|
||||||
buffer->new_unimportant_count++;
|
buffer->new_unimportant_count++;
|
||||||
buffer->highlighted |= important;
|
|
||||||
}
|
}
|
||||||
if (!displayed)
|
|
||||||
|
if (visible)
|
||||||
|
buffer_line_display (ctx, buffer, line, leak_to_active);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buffer->highlighted |= important;
|
||||||
refresh_prompt (ctx);
|
refresh_prompt (ctx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -8223,6 +8317,8 @@ irc_try_parse_welcome_for_userhost (struct server *s, const char *m)
|
|||||||
strv_free (&v);
|
strv_free (&v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void process_input
|
||||||
|
(struct app_context *, struct buffer *, const char *);
|
||||||
static bool process_input_line
|
static bool process_input_line
|
||||||
(struct app_context *, struct buffer *, const char *, int);
|
(struct app_context *, struct buffer *, const char *, int);
|
||||||
static void on_autoaway_timer (struct app_context *ctx);
|
static void on_autoaway_timer (struct app_context *ctx);
|
||||||
@@ -8251,7 +8347,7 @@ irc_on_registered (struct server *s, const char *nickname)
|
|||||||
if (command)
|
if (command)
|
||||||
{
|
{
|
||||||
log_server_debug (s, "Executing \"#s\"", command);
|
log_server_debug (s, "Executing \"#s\"", command);
|
||||||
(void) process_input_line (s->ctx, s->buffer, command, 0);
|
(void) process_input (s->ctx, s->buffer, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t command_delay = get_config_integer (s->config, "command_delay");
|
int64_t command_delay = get_config_integer (s->config, "command_delay");
|
||||||
@@ -9345,6 +9441,9 @@ server_add (struct app_context *ctx,
|
|||||||
str_map_set (&ctx->servers, s->name, s);
|
str_map_set (&ctx->servers, s->name, s);
|
||||||
s->config = subtree;
|
s->config = subtree;
|
||||||
|
|
||||||
|
relay_prepare_server_update (ctx, s);
|
||||||
|
relay_broadcast (ctx);
|
||||||
|
|
||||||
// Add a buffer and activate it
|
// Add a buffer and activate it
|
||||||
struct buffer *buffer = s->buffer = buffer_new (ctx->input,
|
struct buffer *buffer = s->buffer = buffer_new (ctx->input,
|
||||||
BUFFER_SERVER, irc_make_buffer_name (s, NULL));
|
BUFFER_SERVER, irc_make_buffer_name (s, NULL));
|
||||||
@@ -12843,6 +12942,16 @@ handle_command_kill (struct handler_args *a)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
handle_command_away (struct handler_args *a)
|
||||||
|
{
|
||||||
|
if (*a->arguments)
|
||||||
|
irc_send (a->s, "AWAY :%s", a->arguments);
|
||||||
|
else
|
||||||
|
irc_send (a->s, "AWAY");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
handle_command_nick (struct handler_args *a)
|
handle_command_nick (struct handler_args *a)
|
||||||
{
|
{
|
||||||
@@ -12908,7 +13017,6 @@ TRIVIAL_HANDLER (who, "WHO")
|
|||||||
TRIVIAL_HANDLER (motd, "MOTD")
|
TRIVIAL_HANDLER (motd, "MOTD")
|
||||||
TRIVIAL_HANDLER (oper, "OPER")
|
TRIVIAL_HANDLER (oper, "OPER")
|
||||||
TRIVIAL_HANDLER (stats, "STATS")
|
TRIVIAL_HANDLER (stats, "STATS")
|
||||||
TRIVIAL_HANDLER (away, "AWAY")
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
@@ -15258,12 +15366,18 @@ on_pending_input (struct app_context *ctx)
|
|||||||
poller_idle_reset (&ctx->input_event);
|
poller_idle_reset (&ctx->input_event);
|
||||||
for (size_t i = 0; i < ctx->pending_input.len; i++)
|
for (size_t i = 0; i < ctx->pending_input.len; i++)
|
||||||
{
|
{
|
||||||
char *input = iconv_xstrdup
|
char *input = iconv_xstrdup (ctx->term_to_utf8,
|
||||||
(ctx->term_to_utf8, ctx->pending_input.vector[i], -1, NULL);
|
ctx->pending_input.vector[i], -1, NULL);
|
||||||
if (input)
|
if (!input)
|
||||||
process_input (ctx, ctx->current_buffer, input);
|
{
|
||||||
else
|
|
||||||
print_error ("character conversion failed for: %s", "user input");
|
print_error ("character conversion failed for: %s", "user input");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
relay_prepare_buffer_input (ctx, ctx->current_buffer, input);
|
||||||
|
relay_broadcast (ctx);
|
||||||
|
|
||||||
|
process_input (ctx, ctx->current_buffer, input);
|
||||||
free (input);
|
free (input);
|
||||||
}
|
}
|
||||||
strv_reset (&ctx->pending_input);
|
strv_reset (&ctx->pending_input);
|
||||||
@@ -15311,6 +15425,29 @@ init_poller_events (struct app_context *ctx)
|
|||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
|
static void
|
||||||
|
client_resync_buffer_input (struct client *c, struct buffer *buffer)
|
||||||
|
{
|
||||||
|
struct strv history =
|
||||||
|
CALL_ (c->ctx->input, buffer_get_history, buffer->input_data);
|
||||||
|
for (size_t i = 0; i < history.len; i++)
|
||||||
|
{
|
||||||
|
char *input = iconv_xstrdup (c->ctx->term_to_utf8,
|
||||||
|
history.vector[i], -1, NULL);
|
||||||
|
if (!input)
|
||||||
|
{
|
||||||
|
print_error ("character conversion failed for: %s",
|
||||||
|
"user input history");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
relay_prepare_buffer_input (c->ctx, buffer, input);
|
||||||
|
relay_send (c);
|
||||||
|
free (input);
|
||||||
|
}
|
||||||
|
strv_free (&history);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
client_resync (struct client *c)
|
client_resync (struct client *c)
|
||||||
{
|
{
|
||||||
@@ -15329,6 +15466,8 @@ client_resync (struct client *c)
|
|||||||
relay_prepare_buffer_stats (c->ctx, buffer);
|
relay_prepare_buffer_stats (c->ctx, buffer);
|
||||||
relay_send (c);
|
relay_send (c);
|
||||||
|
|
||||||
|
client_resync_buffer_input (c, buffer);
|
||||||
|
|
||||||
LIST_FOR_EACH (struct buffer_line, line, buffer->lines)
|
LIST_FOR_EACH (struct buffer_line, line, buffer->lines)
|
||||||
{
|
{
|
||||||
relay_prepare_buffer_line (c->ctx, buffer, line, false);
|
relay_prepare_buffer_line (c->ctx, buffer, line, false);
|
||||||
@@ -15346,7 +15485,7 @@ client_message_buffer_name (const struct relay_command_message *m)
|
|||||||
switch (m->data.command)
|
switch (m->data.command)
|
||||||
{
|
{
|
||||||
case RELAY_COMMAND_BUFFER_COMPLETE:
|
case RELAY_COMMAND_BUFFER_COMPLETE:
|
||||||
return m->data.buffer_input.buffer_name.str;
|
return m->data.buffer_complete.buffer_name.str;
|
||||||
case RELAY_COMMAND_BUFFER_ACTIVATE:
|
case RELAY_COMMAND_BUFFER_ACTIVATE:
|
||||||
return m->data.buffer_activate.buffer_name.str;
|
return m->data.buffer_activate.buffer_name.str;
|
||||||
case RELAY_COMMAND_BUFFER_INPUT:
|
case RELAY_COMMAND_BUFFER_INPUT:
|
||||||
@@ -15400,18 +15539,31 @@ out:
|
|||||||
relay_send (c);
|
relay_send (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
client_process_buffer_input
|
||||||
|
(struct client *c, struct buffer *buffer, const char *input)
|
||||||
|
{
|
||||||
|
char *mb = iconv_xstrdup (c->ctx->term_from_utf8, (char *) input, -1, NULL);
|
||||||
|
CALL_ (c->ctx->input, buffer_add_history, buffer->input_data, mb);
|
||||||
|
free (mb);
|
||||||
|
|
||||||
|
relay_prepare_buffer_input (c->ctx, buffer, input);
|
||||||
|
relay_broadcast_except (c->ctx, c);
|
||||||
|
|
||||||
|
process_input (c->ctx, buffer, input);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
client_process_buffer_log
|
client_process_buffer_log
|
||||||
(struct client *c, uint32_t seq, struct buffer *buffer)
|
(struct client *c, uint32_t seq, struct buffer *buffer)
|
||||||
{
|
{
|
||||||
struct relay_event_data_response *e = relay_prepare_response (c->ctx, seq);
|
// XXX: We log failures to the global buffer,
|
||||||
e->data.command = RELAY_COMMAND_BUFFER_LOG;
|
// so the client just receives nothing if there is no log file.
|
||||||
|
struct str log = str_make ();
|
||||||
char *path = buffer_get_log_path (buffer);
|
char *path = buffer_get_log_path (buffer);
|
||||||
FILE *fp = open_log_path (c->ctx, buffer, path);
|
FILE *fp = open_log_path (c->ctx, buffer, path);
|
||||||
if (fp)
|
if (fp)
|
||||||
{
|
{
|
||||||
struct str log = str_make ();
|
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
size_t len;
|
size_t len;
|
||||||
while ((len = fread (buf, 1, sizeof buf, fp)))
|
while ((len = fread (buf, 1, sizeof buf, fp)))
|
||||||
@@ -15419,17 +15571,15 @@ client_process_buffer_log
|
|||||||
if (ferror (fp))
|
if (ferror (fp))
|
||||||
log_global_error (c->ctx, "Failed to read `#l': #l",
|
log_global_error (c->ctx, "Failed to read `#l': #l",
|
||||||
path, strerror (errno));
|
path, strerror (errno));
|
||||||
|
|
||||||
// On overflow, it will later fail serialization.
|
|
||||||
e->data.buffer_log.log_len = MIN (UINT32_MAX, log.len);
|
|
||||||
e->data.buffer_log.log = (uint8_t *) str_steal (&log);
|
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: We log failures to the global buffer,
|
|
||||||
// so the client just receives nothing if there is no log file.
|
|
||||||
|
|
||||||
free (path);
|
free (path);
|
||||||
|
|
||||||
|
struct relay_event_data_response *e = relay_prepare_response (c->ctx, seq);
|
||||||
|
e->data.command = RELAY_COMMAND_BUFFER_LOG;
|
||||||
|
// On overflow, it will later fail serialization (frame will be too long).
|
||||||
|
e->data.buffer_log.log_len = MIN (UINT32_MAX, log.len);
|
||||||
|
e->data.buffer_log.log = (uint8_t *) str_steal (&log);
|
||||||
relay_send (c);
|
relay_send (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -15482,7 +15632,7 @@ client_process_message (struct client *c,
|
|||||||
buffer_activate (c->ctx, buffer);
|
buffer_activate (c->ctx, buffer);
|
||||||
break;
|
break;
|
||||||
case RELAY_COMMAND_BUFFER_INPUT:
|
case RELAY_COMMAND_BUFFER_INPUT:
|
||||||
process_input (c->ctx, buffer, m->data.buffer_input.text.str);
|
client_process_buffer_input (c, buffer, m->data.buffer_input.text.str);
|
||||||
break;
|
break;
|
||||||
case RELAY_COMMAND_BUFFER_TOGGLE_UNIMPORTANT:
|
case RELAY_COMMAND_BUFFER_TOGGLE_UNIMPORTANT:
|
||||||
buffer_toggle_unimportant (c->ctx, buffer);
|
buffer_toggle_unimportant (c->ctx, buffer);
|
||||||
@@ -15717,6 +15867,7 @@ relay_start (struct app_context *ctx, char *address, struct error **e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Just try the first one, disregarding IPv4/IPv6 ordering.
|
// Just try the first one, disregarding IPv4/IPv6 ordering.
|
||||||
|
// Use 0.0.0.0 or [::] to request either one specifically.
|
||||||
int fd = relay_listen_with_context (ctx, result, e);
|
int fd = relay_listen_with_context (ctx, result, e);
|
||||||
freeaddrinfo (result);
|
freeaddrinfo (result);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
@@ -15866,14 +16017,29 @@ show_logo (struct app_context *ctx)
|
|||||||
static void
|
static void
|
||||||
format_input_and_die (struct app_context *ctx)
|
format_input_and_die (struct app_context *ctx)
|
||||||
{
|
{
|
||||||
char buf[513];
|
// XXX: it might make sense to allow for redirection, using FLUSH_OPT_RAW
|
||||||
while (fgets (buf, sizeof buf, stdin))
|
struct str s = str_make ();
|
||||||
|
int c = 0;
|
||||||
|
while ((c = fgetc (stdin)) != EOF)
|
||||||
{
|
{
|
||||||
|
if (c != '\n')
|
||||||
|
{
|
||||||
|
str_append_c (&s, c);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
struct formatter f = formatter_make (ctx, NULL);
|
struct formatter f = formatter_make (ctx, NULL);
|
||||||
formatter_add (&f, "#m", buf);
|
formatter_add (&f, "#m\n", s.str);
|
||||||
formatter_flush (&f, stdout, FLUSH_OPT_NOWRAP);
|
formatter_flush (&f, stdout, FLUSH_OPT_NOWRAP);
|
||||||
formatter_free (&f);
|
formatter_free (&f);
|
||||||
|
str_reset (&s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct formatter f = formatter_make (ctx, NULL);
|
||||||
|
formatter_add (&f, "#m", s.str);
|
||||||
|
formatter_flush (&f, stdout, FLUSH_OPT_NOWRAP);
|
||||||
|
formatter_free (&f);
|
||||||
|
str_free (&s);
|
||||||
exit (EXIT_SUCCESS);
|
exit (EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -15937,7 +16103,11 @@ main (int argc, char *argv[])
|
|||||||
|
|
||||||
// The following part is a bit brittle because of interdependencies
|
// The following part is a bit brittle because of interdependencies
|
||||||
init_colors (&ctx);
|
init_colors (&ctx);
|
||||||
if (format_mode) format_input_and_die (&ctx);
|
if (format_mode)
|
||||||
|
format_input_and_die (&ctx);
|
||||||
|
if (!cur_term)
|
||||||
|
exit_fatal ("terminal initialization failed");
|
||||||
|
|
||||||
init_global_buffer (&ctx);
|
init_global_buffer (&ctx);
|
||||||
show_logo (&ctx);
|
show_logo (&ctx);
|
||||||
setup_signal_handlers ();
|
setup_signal_handlers ();
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ struct EventMessage {
|
|||||||
BUFFER_RENAME,
|
BUFFER_RENAME,
|
||||||
BUFFER_REMOVE,
|
BUFFER_REMOVE,
|
||||||
BUFFER_ACTIVATE,
|
BUFFER_ACTIVATE,
|
||||||
|
BUFFER_INPUT,
|
||||||
BUFFER_CLEAR,
|
BUFFER_CLEAR,
|
||||||
SERVER_UPDATE,
|
SERVER_UPDATE,
|
||||||
SERVER_RENAME,
|
SERVER_RENAME,
|
||||||
@@ -153,6 +154,9 @@ struct EventMessage {
|
|||||||
string buffer_name;
|
string buffer_name;
|
||||||
case BUFFER_ACTIVATE:
|
case BUFFER_ACTIVATE:
|
||||||
string buffer_name;
|
string buffer_name;
|
||||||
|
case BUFFER_INPUT:
|
||||||
|
string buffer_name;
|
||||||
|
string text;
|
||||||
case BUFFER_CLEAR:
|
case BUFFER_CLEAR:
|
||||||
string buffer_name;
|
string buffer_name;
|
||||||
|
|
||||||
@@ -2,14 +2,14 @@
|
|||||||
BEGIN {
|
BEGIN {
|
||||||
# The message catalog is a by-product
|
# The message catalog is a by-product
|
||||||
msg = "xD.msg"
|
msg = "xD.msg"
|
||||||
print "$quote \"" > msg;
|
print "$quote \"" > msg
|
||||||
print "$set 1" > msg;
|
print "$set 1" > msg
|
||||||
}
|
}
|
||||||
|
|
||||||
/^[0-9]+ *IRC_(ERR|RPL)_[A-Z]+ *".*"$/ {
|
/^[0-9]+ *IRC_(ERR|RPL)_[A-Z]+ *".*"$/ {
|
||||||
match($0, /".*"/);
|
match($0, /".*"/)
|
||||||
ids[$1] = $2;
|
ids[$1] = $2
|
||||||
texts[$2] = substr($0, RSTART, RLENGTH);
|
texts[$2] = substr($0, RSTART, RLENGTH)
|
||||||
print $1 " " texts[$2] > msg
|
print $1 " " texts[$2] > msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
8
xD.c
8
xD.c
@@ -49,7 +49,7 @@ static struct simple_config_item g_config_table[] =
|
|||||||
{ "tls_key", NULL, "Server TLS private key (PEM)" },
|
{ "tls_key", NULL, "Server TLS private key (PEM)" },
|
||||||
{ "tls_ciphers", DEFAULT_CIPHERS, "OpenSSL cipher list" },
|
{ "tls_ciphers", DEFAULT_CIPHERS, "OpenSSL cipher list" },
|
||||||
|
|
||||||
{ "operators", NULL, "IRCop TLS client cert. SHA-1 fingerprints" },
|
{ "operators", NULL, "IRCop TLS client cert. SHA-256 fingerprints" },
|
||||||
|
|
||||||
{ "max_connections", "0", "Global connection limit" },
|
{ "max_connections", "0", "Global connection limit" },
|
||||||
{ "ping_interval", "180", "Interval between PINGs (sec)" },
|
{ "ping_interval", "180", "Interval between PINGs (sec)" },
|
||||||
@@ -296,7 +296,7 @@ irc_is_valid_user_mask (const char *mask)
|
|||||||
static bool
|
static bool
|
||||||
irc_is_valid_fingerprint (const char *fp)
|
irc_is_valid_fingerprint (const char *fp)
|
||||||
{
|
{
|
||||||
return irc_regex_match ("^[a-fA-F0-9]{40}$", fp);
|
return irc_regex_match ("^[a-fA-F0-9]{64}$", fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Clients (equals users) --------------------------------------------------
|
// --- Clients (equals users) --------------------------------------------------
|
||||||
@@ -1005,8 +1005,8 @@ client_get_ssl_cert_fingerprint (struct client *c)
|
|||||||
if (i2d_X509 (peer_cert, &p) < 0)
|
if (i2d_X509 (peer_cert, &p) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
unsigned char hash[SHA_DIGEST_LENGTH];
|
unsigned char hash[SHA256_DIGEST_LENGTH];
|
||||||
SHA1 (cert, cert_len, hash);
|
SHA256 (cert, cert_len, hash);
|
||||||
|
|
||||||
struct str fingerprint = str_make ();
|
struct str fingerprint = str_make ();
|
||||||
for (size_t i = 0; i < sizeof hash; i++)
|
for (size_t i = 0; i < sizeof hash; i++)
|
||||||
|
|||||||
4
xF.svg
4
xF.svg
@@ -1,8 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<svg version="1.1" width="48" height="48" viewBox="0 0 48 48"
|
<svg version="1.1" width="48" height="48" viewBox="0 0 48 48"
|
||||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
xmlns="http://www.w3.org/2000/svg">
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
xmlns:svg="http://www.w3.org/2000/svg">
|
|
||||||
|
|
||||||
<defs>
|
<defs>
|
||||||
<linearGradient id="background" x1="0" y1="0" x2="1" y2="1">
|
<linearGradient id="background" x1="0" y1="0" x2="1" y2="1">
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.2 KiB |
1
xK-version
Normal file
1
xK-version
Normal file
@@ -0,0 +1 @@
|
|||||||
|
2.0.0
|
||||||
45
xM/CMakeLists.txt
Normal file
45
xM/CMakeLists.txt
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
# Swift language support
|
||||||
|
cmake_minimum_required (VERSION 3.15)
|
||||||
|
|
||||||
|
file (READ ../xK-version project_version)
|
||||||
|
configure_file (../xK-version xK-version.tag COPYONLY)
|
||||||
|
string (STRIP "${project_version}" project_version)
|
||||||
|
|
||||||
|
# There were two issues when building this from the main CMakeLists.txt:
|
||||||
|
# a) renaming main.swift to xM.swift requires removing top-level statements,
|
||||||
|
# b) there is a "redefinition of module 'FFI'" error.
|
||||||
|
project (xM VERSION "${project_version}"
|
||||||
|
DESCRIPTION "Cocoa frontend for xC" LANGUAGES Swift)
|
||||||
|
|
||||||
|
set (root "${PROJECT_SOURCE_DIR}/..")
|
||||||
|
add_custom_command (OUTPUT xC-proto.swift
|
||||||
|
COMMAND env LC_ALL=C awk
|
||||||
|
-f ${root}/liberty/tools/lxdrgen.awk
|
||||||
|
-f ${root}/liberty/tools/lxdrgen-swift.awk
|
||||||
|
-v PrefixCamel=Relay
|
||||||
|
${root}/xC.lxdr > xC-proto.swift
|
||||||
|
DEPENDS
|
||||||
|
${root}/liberty/tools/lxdrgen.awk
|
||||||
|
${root}/liberty/tools/lxdrgen-swift.awk
|
||||||
|
${root}/xC.lxdr
|
||||||
|
COMMENT "Generating xC relay protocol code" VERBATIM)
|
||||||
|
|
||||||
|
set (MACOSX_BUNDLE_GUI_IDENTIFIER name.janouch.${PROJECT_NAME})
|
||||||
|
set (MACOSX_BUNDLE_ICON_FILE xM.icns)
|
||||||
|
|
||||||
|
# Avoid including binary files in the repository by generating icons in code.
|
||||||
|
# sips(1) + Javascript + iconutil(1) could probably also be used.
|
||||||
|
find_program (SWIFT_EXECUTABLE swift REQUIRED)
|
||||||
|
|
||||||
|
set (icon "${PROJECT_BINARY_DIR}/${MACOSX_BUNDLE_ICON_FILE}")
|
||||||
|
add_custom_command (OUTPUT "${icon}"
|
||||||
|
COMMAND ${SWIFT_EXECUTABLE} "${PROJECT_SOURCE_DIR}/gen-icon.swift" "${icon}"
|
||||||
|
DEPENDS gen-icon.swift
|
||||||
|
COMMENT "Generating xM application icon" VERBATIM)
|
||||||
|
set_source_files_properties ("${icon}" PROPERTIES
|
||||||
|
MACOSX_PACKAGE_LOCATION Resources)
|
||||||
|
|
||||||
|
# Other requirements: macOS 10.14 for Network, and macOS 11 for Logger.
|
||||||
|
set (CMAKE_Swift_LANGUAGE_VERSION 5)
|
||||||
|
add_executable (xM MACOSX_BUNDLE
|
||||||
|
main.swift "${icon}" "${PROJECT_BINARY_DIR}/xC-proto.swift")
|
||||||
96
xM/gen-icon.swift
Normal file
96
xM/gen-icon.swift
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
// gen-icon.swift: generate a program icon for xM in the Apple icon format
|
||||||
|
//
|
||||||
|
// Copyright (c) 2023, Přemysl Eric Janouch <p@janouch.name>
|
||||||
|
// SPDX-License-Identifier: 0BSD
|
||||||
|
//
|
||||||
|
// NSGraphicsContext mostly just weirdly wraps over Quartz,
|
||||||
|
// so we do it all in Quartz directly.
|
||||||
|
import CoreGraphics
|
||||||
|
import Foundation
|
||||||
|
import ImageIO
|
||||||
|
import UniformTypeIdentifiers
|
||||||
|
|
||||||
|
// Apple uses something that's close to a "quintic superellipse" in their icons,
|
||||||
|
// but doesn't quite match. Either way, it looks better than rounded rectangles.
|
||||||
|
func addSquircle(context: CGContext, bounds: CGRect) {
|
||||||
|
context.move(to: CGPoint(x: bounds.maxX, y: bounds.midY))
|
||||||
|
for theta in stride(from: 0.0, to: .pi * 2, by: .pi / 1e4) {
|
||||||
|
let x = pow(abs(cos(theta)), 2 / 5.0) * bounds.width / 2
|
||||||
|
* CGFloat(signOf: cos(theta), magnitudeOf: 1) + bounds.midX
|
||||||
|
let y = pow(abs(sin(theta)), 2 / 5.0) * bounds.height / 2
|
||||||
|
* CGFloat(signOf: sin(theta), magnitudeOf: 1) + bounds.midY
|
||||||
|
context.addLine(to: CGPoint(x: x, y: y))
|
||||||
|
}
|
||||||
|
context.closePath()
|
||||||
|
}
|
||||||
|
|
||||||
|
func drawIcon(scale: CGFloat) -> CGImage? {
|
||||||
|
let size = CGSizeMake(1024, 1024)
|
||||||
|
|
||||||
|
let colorspace = CGColorSpaceCreateDeviceRGB()
|
||||||
|
let context = CGContext(data: nil,
|
||||||
|
width: Int(size.width * scale), height: Int(size.height * scale),
|
||||||
|
bitsPerComponent: 8, bytesPerRow: 0, space: colorspace,
|
||||||
|
bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)!
|
||||||
|
context.scaleBy(x: scale, y: scale)
|
||||||
|
|
||||||
|
let bounds = CGRectMake(100, 100, size.width - 200, size.height - 200)
|
||||||
|
addSquircle(context: context, bounds: bounds)
|
||||||
|
let squircle = context.path!
|
||||||
|
|
||||||
|
// Gradients don't draw shadows, so draw it separately.
|
||||||
|
context.saveGState()
|
||||||
|
context.setShadow(offset: CGSizeMake(0, -12).applying(context.ctm),
|
||||||
|
blur: 28 * scale, color: CGColor(gray: 0, alpha: 0.5))
|
||||||
|
context.setFillColor(CGColor(red: 1, green: 0x55p-8, blue: 0, alpha: 1))
|
||||||
|
context.fillPath()
|
||||||
|
context.restoreGState()
|
||||||
|
|
||||||
|
context.saveGState()
|
||||||
|
context.addPath(squircle)
|
||||||
|
context.clip()
|
||||||
|
context.drawLinearGradient(
|
||||||
|
CGGradient(colorsSpace: colorspace, colors: [
|
||||||
|
CGColor(red: 1, green: 0x00p-8, blue: 0, alpha: 1),
|
||||||
|
CGColor(red: 1, green: 0xaap-8, blue: 0, alpha: 1)
|
||||||
|
] as CFArray, locations: [0, 1])!,
|
||||||
|
start: CGPointMake(0, 100), end: CGPointMake(0, size.height - 100),
|
||||||
|
options: CGGradientDrawingOptions(rawValue: 0))
|
||||||
|
context.restoreGState()
|
||||||
|
|
||||||
|
context.move(to: CGPoint(x: size.width * 0.30, y: size.height * 0.30))
|
||||||
|
context.addLine(to: CGPoint(x: size.width * 0.30, y: size.height * 0.70))
|
||||||
|
context.addLine(to: CGPoint(x: size.width * 0.575, y: size.height * 0.425))
|
||||||
|
context.move(to: CGPoint(x: size.width * 0.70, y: size.height * 0.30))
|
||||||
|
context.addLine(to: CGPoint(x: size.width * 0.70, y: size.height * 0.70))
|
||||||
|
context.addLine(to: CGPoint(x: size.width * 0.425, y: size.height * 0.425))
|
||||||
|
context.setLineWidth(80)
|
||||||
|
context.setLineCap(.round)
|
||||||
|
context.setLineJoin(.round)
|
||||||
|
context.setStrokeColor(CGColor.white)
|
||||||
|
context.strokePath()
|
||||||
|
return context.makeImage()
|
||||||
|
}
|
||||||
|
|
||||||
|
if CommandLine.arguments.count != 2 {
|
||||||
|
print("Usage: \(CommandLine.arguments.first!) OUTPUT.icns")
|
||||||
|
exit(EXIT_FAILURE)
|
||||||
|
}
|
||||||
|
|
||||||
|
let filename = CommandLine.arguments[1]
|
||||||
|
|
||||||
|
let macOSSizes: Array<CGFloat> = [16, 32, 128, 256, 512]
|
||||||
|
let icns = CGImageDestinationCreateWithURL(
|
||||||
|
URL(fileURLWithPath: filename) as CFURL,
|
||||||
|
UTType.icns.identifier as CFString, macOSSizes.count * 2, nil)!
|
||||||
|
for size in macOSSizes {
|
||||||
|
CGImageDestinationAddImage(icns, drawIcon(scale: size / 1024.0)!, nil)
|
||||||
|
CGImageDestinationAddImage(icns, drawIcon(scale: size / 1024.0 * 2)!, [
|
||||||
|
kCGImagePropertyDPIWidth: 144,
|
||||||
|
kCGImagePropertyDPIHeight: 144,
|
||||||
|
] as CFDictionary)
|
||||||
|
}
|
||||||
|
if !CGImageDestinationFinalize(icns) {
|
||||||
|
print("ICNS finalization failed.")
|
||||||
|
exit(EXIT_FAILURE)
|
||||||
|
}
|
||||||
1372
xM/main.swift
Normal file
1372
xM/main.swift
Normal file
File diff suppressed because it is too large
Load Diff
3
xN/.gitignore
vendored
Normal file
3
xN/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
/xN
|
||||||
|
/xN.1
|
||||||
|
/irc.go
|
||||||
21
xN/Makefile
Normal file
21
xN/Makefile
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
.POSIX:
|
||||||
|
.SUFFIXES:
|
||||||
|
AWK = env LC_ALL=C awk
|
||||||
|
|
||||||
|
outputs = irc.go xN xN.1
|
||||||
|
all: $(outputs)
|
||||||
|
|
||||||
|
# If we want to keep module dependencies separate, we don't have many options.
|
||||||
|
# Symlinking seems to work good enough.
|
||||||
|
irc.go: ../xS/irc.go
|
||||||
|
ln -sf ../xS/irc.go $@
|
||||||
|
|
||||||
|
xN: xN.go ../xK-version irc.go
|
||||||
|
go build -ldflags "-X 'main.projectVersion=$$(cat ../xK-version)'" -o $@
|
||||||
|
xN.1: ../xK-version ../liberty/tools/asciiman.awk xN.adoc
|
||||||
|
env "asciidoc-release-version=$$(cat ../xK-version)" \
|
||||||
|
$(AWK) -f ../liberty/tools/asciiman.awk xN.adoc > $@
|
||||||
|
test: all
|
||||||
|
go test
|
||||||
|
clean:
|
||||||
|
rm -f $(outputs)
|
||||||
86
xN/xN.adoc
Normal file
86
xN/xN.adoc
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
xN(1)
|
||||||
|
=====
|
||||||
|
:doctype: manpage
|
||||||
|
:manmanual: xK Manual
|
||||||
|
:mansource: xK {release-version}
|
||||||
|
|
||||||
|
Name
|
||||||
|
----
|
||||||
|
xN - IRC notifier
|
||||||
|
|
||||||
|
Synopsis
|
||||||
|
--------
|
||||||
|
*xN* [_OPTION_]... IRC-URL...
|
||||||
|
|
||||||
|
Description
|
||||||
|
-----------
|
||||||
|
*xN* is a simple IRC notifier, sending the text it receives on its standard
|
||||||
|
input to all IRC targets specified by its command line arguments.
|
||||||
|
|
||||||
|
The input text is forced to validate as UTF-8, and it is _not_ split
|
||||||
|
automatically to comply with the maximum IRC message length.
|
||||||
|
Thus, make sure to make the lines short, or they will be trimmed by the servers.
|
||||||
|
|
||||||
|
*xN* does not attempt to appease flood detectors.
|
||||||
|
|
||||||
|
Options
|
||||||
|
-------
|
||||||
|
*-debug*::
|
||||||
|
Print incoming IRC traffic, which may help in debugging any issues.
|
||||||
|
|
||||||
|
*-version*::
|
||||||
|
Output version information and exit.
|
||||||
|
|
||||||
|
URL format
|
||||||
|
----------
|
||||||
|
*xN* accepts URLs describing IRC users and channels, roughly as specified by
|
||||||
|
the Internet Draft _draft-butcher-irc-url-04.txt_. Note, however, that close
|
||||||
|
to no validation is done on these, and you should not pass URLs from untrusted
|
||||||
|
sources, so as to avoid command or parameter injection.
|
||||||
|
|
||||||
|
Any provided username will be propagated to the nickname, username,
|
||||||
|
and realname. The default value for these is the name of your system user.
|
||||||
|
|
||||||
|
As an extension, you may use the following options:
|
||||||
|
|
||||||
|
*skipjoin*::
|
||||||
|
Do not JOIN channels before sending messages to them.
|
||||||
|
This requires channels to allow external messages
|
||||||
|
(which are disabled by channel mode *+n*).
|
||||||
|
*usenotice*::
|
||||||
|
Send a NOTICE rather than a PRIVMSG, which distinguishes automated messages,
|
||||||
|
and is more appropriate for bots.
|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------
|
||||||
|
$ uptime | xN 'irc://uptime@localhost/%23watch?skipjoin&usenotice'
|
||||||
|
|
||||||
|
Send *uptime*(1) information as an external notice to channel *#watch*
|
||||||
|
on the local server, using the standard port *6667*.
|
||||||
|
|
||||||
|
$ fortune -s | xN ircs://ohayou@irc.libera.chat/john,isuser
|
||||||
|
|
||||||
|
Greet user *john* with a fortune for this day. In compliance with _RFC 7194_,
|
||||||
|
the default TLS port is assumed to be *6697*.
|
||||||
|
|
||||||
|
$ xN 'ircs://agent:Password123@irc.cia.gov:1337/#hq?key=123456' <<EOF
|
||||||
|
The red fox trots quietly at midnight.
|
||||||
|
EOF
|
||||||
|
|
||||||
|
Connect over TLS to *irc.cia.gov* on port *1337*, use *Password123*
|
||||||
|
as the server password, register as user *agent*,
|
||||||
|
join channel *#hq* using the channel key *123456*,
|
||||||
|
and send a very secret message.
|
||||||
|
|
||||||
|
Reporting bugs
|
||||||
|
--------------
|
||||||
|
Use https://git.janouch.name/p/xK to report bugs, request features,
|
||||||
|
or submit pull requests.
|
||||||
|
|
||||||
|
See also
|
||||||
|
--------
|
||||||
|
_Uniform Resource Locator Schemes for Internet Relay Chat Entities_,
|
||||||
|
https://datatracker.ietf.org/doc/html/draft-butcher-irc-url-04[].
|
||||||
|
|
||||||
|
_Default Port for Internet Relay Chat (IRC) via TLS/SSL_,
|
||||||
|
https://datatracker.ietf.org/doc/html/rfc7194[].
|
||||||
279
xN/xN.go
Normal file
279
xN/xN.go
Normal file
@@ -0,0 +1,279 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) 2024, Přemysl Eric Janouch <p@janouch.name>
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
// purpose with or without fee is hereby granted.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||||
|
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||||
|
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||||
|
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
//
|
||||||
|
|
||||||
|
// xN is a simple IRC notifier.
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"crypto/tls"
|
||||||
|
"errors"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"os/user"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const projectName = "xN"
|
||||||
|
|
||||||
|
var projectVersion = "?"
|
||||||
|
|
||||||
|
var debugMode = false
|
||||||
|
|
||||||
|
type parameters struct {
|
||||||
|
conn net.Conn // underlying network connection
|
||||||
|
username string // nickname + username + realname
|
||||||
|
password string // server password
|
||||||
|
target string // where to send text
|
||||||
|
isuser bool // the target is a user rather than a channel
|
||||||
|
chankey string // channel key
|
||||||
|
skipjoin bool // whether to send external messages to channels
|
||||||
|
usenotice bool // whether to use NOTICE rather than PRIVMSG
|
||||||
|
message []string // lines of the message to send
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *parameters) send(command string, args ...string) error {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
buf.WriteString(command)
|
||||||
|
for i, arg := range args {
|
||||||
|
buf.WriteRune(' ')
|
||||||
|
if i+1 == len(args) {
|
||||||
|
buf.WriteRune(':')
|
||||||
|
}
|
||||||
|
buf.WriteString(arg)
|
||||||
|
}
|
||||||
|
buf.WriteString("\r\n")
|
||||||
|
_, err := p.conn.Write(buf.Bytes())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
rplWELCOME = "001"
|
||||||
|
errNICKNAMEINUSE = "433"
|
||||||
|
)
|
||||||
|
|
||||||
|
func notify(p *parameters) error {
|
||||||
|
// The intro should comfortably fit in the TCP send buffer whole.
|
||||||
|
if p.password != "" {
|
||||||
|
p.send("PASS", p.password)
|
||||||
|
}
|
||||||
|
p.send("USER", p.username, "0", "*", p.username)
|
||||||
|
p.send("NICK", p.username)
|
||||||
|
|
||||||
|
scanner, nickCounter, issue := bufio.NewScanner(p.conn), 1, ""
|
||||||
|
for scanner.Scan() {
|
||||||
|
if debugMode {
|
||||||
|
log.Println(scanner.Text())
|
||||||
|
}
|
||||||
|
|
||||||
|
m := ircParseMessage(scanner.Text())
|
||||||
|
switch m.command {
|
||||||
|
case "PING":
|
||||||
|
p.send("PONG", m.params...)
|
||||||
|
case rplWELCOME:
|
||||||
|
if !p.isuser && !p.skipjoin {
|
||||||
|
if p.chankey != "" {
|
||||||
|
p.send("JOIN", p.target, p.chankey)
|
||||||
|
} else {
|
||||||
|
p.send("JOIN", p.target)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, line := range p.message {
|
||||||
|
if p.usenotice {
|
||||||
|
p.send("NOTICE", p.target, line)
|
||||||
|
} else {
|
||||||
|
p.send("PRIVMSG", p.target, line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.send("QUIT")
|
||||||
|
case errNICKNAMEINUSE:
|
||||||
|
p.send("NICK", fmt.Sprintf("%s%d", p.username, nickCounter))
|
||||||
|
nickCounter++
|
||||||
|
default:
|
||||||
|
// Prevent hanging on unsuccessful registrations.
|
||||||
|
numeric, _ := strconv.Atoi(m.command)
|
||||||
|
if numeric >= 400 && numeric <= 599 {
|
||||||
|
if len(m.params) > 1 {
|
||||||
|
issue = strings.Join(m.params[1:], " ")
|
||||||
|
} else {
|
||||||
|
issue = strings.Join(m.params, " ")
|
||||||
|
}
|
||||||
|
p.send("QUIT")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if issue != "" {
|
||||||
|
return errors.New(issue)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parse(rawURL string, text []byte) (
|
||||||
|
p parameters, connect func() (net.Conn, error), err error) {
|
||||||
|
u, err := url.Parse(rawURL)
|
||||||
|
if err != nil {
|
||||||
|
return p, nil, err
|
||||||
|
} else if !u.IsAbs() || u.Opaque != "" {
|
||||||
|
return p, nil, errors.New("need an absolute URL")
|
||||||
|
} else if u.Path == "/" && u.Fragment != "" {
|
||||||
|
// Try to handle the common but degenerate case.
|
||||||
|
fragment := "%23" + u.Fragment
|
||||||
|
u.Fragment, u.RawFragment = "", ""
|
||||||
|
if u, err = url.Parse(u.String() + fragment); err != nil {
|
||||||
|
return p, nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Figure out registration details.
|
||||||
|
p.username = projectName
|
||||||
|
if u, _ := user.Current(); u != nil {
|
||||||
|
p.username = u.Username
|
||||||
|
}
|
||||||
|
if u.User.Username() != "" {
|
||||||
|
p.username = u.User.Username()
|
||||||
|
}
|
||||||
|
|
||||||
|
p.password, _ = u.User.Password()
|
||||||
|
|
||||||
|
// Figure out the target, which for our intents must accept messages.
|
||||||
|
path, _ := strings.CutPrefix(u.Path, "/")
|
||||||
|
elements := strings.Split(path, ",")
|
||||||
|
if path == "" || elements[0] == "" {
|
||||||
|
return p, nil, errors.New("unspecified entity")
|
||||||
|
}
|
||||||
|
|
||||||
|
// The last entity type wins.
|
||||||
|
p.target, p.isuser = elements[0], false
|
||||||
|
for _, typ := range elements[1:] {
|
||||||
|
switch typ {
|
||||||
|
case "isuser":
|
||||||
|
p.isuser = true
|
||||||
|
case "ischannel":
|
||||||
|
p.isuser = false
|
||||||
|
case "isserver":
|
||||||
|
// We do not support network names, and this is the default.
|
||||||
|
default:
|
||||||
|
return p, nil, errors.New("unsupported type: " + typ)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if p.isuser {
|
||||||
|
if i := strings.IndexAny(p.target, "!@"); i != -1 {
|
||||||
|
p.target = p.target[:i]
|
||||||
|
}
|
||||||
|
} else if !strings.HasPrefix(p.target, "#") {
|
||||||
|
// TODO(p): We should consult RPL_ISUPPORT rather than guess,
|
||||||
|
// though other prefixes are rare.
|
||||||
|
p.target = "#" + p.target
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note that the draft RFC wants these to be case-insensitive.
|
||||||
|
p.chankey = u.Query().Get("key")
|
||||||
|
// Being able to skip channel join is our own requirement and invention,
|
||||||
|
// as are notices (names taken from Travis CI configuration).
|
||||||
|
p.skipjoin = u.Query().Has("skipjoin")
|
||||||
|
p.usenotice = u.Query().Has("usenotice")
|
||||||
|
|
||||||
|
// Ensure valid LF-separated UTF-8, and split it at lines.
|
||||||
|
sanitized := strings.ReplaceAll(string([]rune(string(text))), "\r", "\n")
|
||||||
|
for _, line := range strings.Split(sanitized, "\n") {
|
||||||
|
if line != "" {
|
||||||
|
p.message = append(p.message, line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hostname, port := u.Hostname(), u.Port()
|
||||||
|
switch u.Scheme {
|
||||||
|
case "irc":
|
||||||
|
if port == "" {
|
||||||
|
port = "6667"
|
||||||
|
}
|
||||||
|
connect = func() (net.Conn, error) {
|
||||||
|
return net.Dial("tcp", net.JoinHostPort(hostname, port))
|
||||||
|
}
|
||||||
|
case "ircs":
|
||||||
|
if port == "" {
|
||||||
|
port = "6697"
|
||||||
|
}
|
||||||
|
connect = func() (net.Conn, error) {
|
||||||
|
return tls.Dial("tcp", net.JoinHostPort(hostname, port), nil)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
err = errors.New("unsupported scheme: " + u.Scheme)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// notifyByURL sends the given text to the IRC server specified by a URL.
|
||||||
|
// See draft-butcher-irc-url-04.txt for the URL scheme specification
|
||||||
|
// this function loosely follows.
|
||||||
|
func notifyByURL(rawURL string, text []byte) error {
|
||||||
|
p, connect, err := parse(rawURL, text)
|
||||||
|
if p.conn, err = connect(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer p.conn.Close()
|
||||||
|
return notify(&p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.BoolVar(&debugMode, "debug", false, "run in verbose debug mode")
|
||||||
|
version := flag.Bool("version", false, "show version and exit")
|
||||||
|
|
||||||
|
flag.Usage = func() {
|
||||||
|
f := flag.CommandLine.Output()
|
||||||
|
fmt.Fprintf(f, "Usage: %s [OPTION]... URL...\n", os.Args[0])
|
||||||
|
flag.PrintDefaults()
|
||||||
|
}
|
||||||
|
flag.Parse()
|
||||||
|
if flag.NArg() < 1 {
|
||||||
|
flag.Usage()
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
if *version {
|
||||||
|
fmt.Printf("%s %s\n", projectName, projectVersion)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
text, err := io.ReadAll(os.Stdin)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
status := 0
|
||||||
|
for _, rawURL := range flag.Args() {
|
||||||
|
if err := notifyByURL(rawURL, text); err != nil {
|
||||||
|
status = 1
|
||||||
|
|
||||||
|
var ue *url.Error
|
||||||
|
if errors.As(err, &ue) {
|
||||||
|
log.Println(err)
|
||||||
|
} else {
|
||||||
|
log.Printf("notify %q: %s\n", rawURL, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
os.Exit(status)
|
||||||
|
}
|
||||||
98
xN/xN_test.go
Normal file
98
xN/xN_test.go
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) 2024, Přemysl Eric Janouch <p@janouch.name>
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
// purpose with or without fee is hereby granted.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||||
|
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||||
|
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||||
|
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
//
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestParseURL(t *testing.T) {
|
||||||
|
for _, rawURL := range []string{
|
||||||
|
`irc:server/channel`,
|
||||||
|
`irc://server/channel,isnetwork`,
|
||||||
|
`ircs://ssl.ircnet.io`,
|
||||||
|
`ircs://ssl.ircnet.io/`,
|
||||||
|
`http://server/path`,
|
||||||
|
} {
|
||||||
|
if _, _, err := parse(rawURL, nil); err == nil {
|
||||||
|
t.Errorf("%q should not parse\n", rawURL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range []struct {
|
||||||
|
rawURL string
|
||||||
|
p parameters
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
rawURL: `irc://uptime@localhost/%23watch?skipjoin&usenotice`,
|
||||||
|
p: parameters{
|
||||||
|
username: "uptime",
|
||||||
|
target: "#watch",
|
||||||
|
skipjoin: true,
|
||||||
|
usenotice: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
rawURL: `ircs://ohayou@irc.libera.chat/john,isuser,isserver`,
|
||||||
|
p: parameters{
|
||||||
|
username: "ohayou",
|
||||||
|
target: "john",
|
||||||
|
isuser: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
rawURL: `ircs://agent:Password123@irc.cia.gov:1337/#hq?key=123456`,
|
||||||
|
p: parameters{
|
||||||
|
username: "agent",
|
||||||
|
password: "Password123",
|
||||||
|
target: "#hq",
|
||||||
|
chankey: "123456",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
p, _, err := parse(test.rawURL, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%q should parse, got: %s\n", test.rawURL, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if p.username != test.p.username {
|
||||||
|
t.Errorf("%q: username: %v ≠ %v\n",
|
||||||
|
test.rawURL, p.username, test.p.username)
|
||||||
|
}
|
||||||
|
if p.password != test.p.password {
|
||||||
|
t.Errorf("%q: password: %v ≠ %v\n",
|
||||||
|
test.rawURL, p.password, test.p.password)
|
||||||
|
}
|
||||||
|
if p.target != test.p.target {
|
||||||
|
t.Errorf("%q: target: %v ≠ %v\n",
|
||||||
|
test.rawURL, p.target, test.p.target)
|
||||||
|
}
|
||||||
|
if p.isuser != test.p.isuser {
|
||||||
|
t.Errorf("%q: isuser: %v ≠ %v\n",
|
||||||
|
test.rawURL, p.isuser, test.p.isuser)
|
||||||
|
}
|
||||||
|
if p.chankey != test.p.chankey {
|
||||||
|
t.Errorf("%q: chankey: %v ≠ %v\n",
|
||||||
|
test.rawURL, p.chankey, test.p.chankey)
|
||||||
|
}
|
||||||
|
if p.skipjoin != test.p.skipjoin {
|
||||||
|
t.Errorf("%q: skipjoin: %v ≠ %v\n",
|
||||||
|
test.rawURL, p.skipjoin, test.p.skipjoin)
|
||||||
|
}
|
||||||
|
if p.usenotice != test.p.usenotice {
|
||||||
|
t.Errorf("%q: usenotice: %v ≠ %v\n",
|
||||||
|
test.rawURL, p.usenotice, test.p.usenotice)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
13
xP/Makefile
13
xP/Makefile
@@ -1,17 +1,20 @@
|
|||||||
.POSIX:
|
.POSIX:
|
||||||
.SUFFIXES:
|
.SUFFIXES:
|
||||||
|
AWK = env LC_ALL=C awk
|
||||||
|
|
||||||
|
tools = ../liberty/tools
|
||||||
outputs = xP proto.go public/proto.js public/mithril.js
|
outputs = xP proto.go public/proto.js public/mithril.js
|
||||||
all: $(outputs) public/ircfmt.woff2
|
all: $(outputs) public/ircfmt.woff2
|
||||||
|
|
||||||
xP: xP.go proto.go
|
xP: xP.go proto.go
|
||||||
go build -o $@
|
go build -o $@
|
||||||
proto.go: ../xC-gen-proto.awk ../xC-gen-proto-go.awk ../xC-proto
|
proto.go: $(tools)/lxdrgen.awk $(tools)/lxdrgen-go.awk ../xC.lxdr
|
||||||
awk -f ../xC-gen-proto.awk -f ../xC-gen-proto-go.awk ../xC-proto > $@
|
$(AWK) -f $(tools)/lxdrgen.awk -f $(tools)/lxdrgen-go.awk \
|
||||||
public/proto.js: ../xC-gen-proto.awk ../xC-gen-proto-js.awk ../xC-proto
|
-v PrefixCamel=Relay ../xC.lxdr > $@
|
||||||
awk -f ../xC-gen-proto.awk -f ../xC-gen-proto-js.awk ../xC-proto > $@
|
public/proto.js: $(tools)/lxdrgen.awk $(tools)/lxdrgen-mjs.awk ../xC.lxdr
|
||||||
|
$(AWK) -f $(tools)/lxdrgen.awk -f $(tools)/lxdrgen-mjs.awk ../xC.lxdr > $@
|
||||||
public/ircfmt.woff2: gen-ircfmt.awk
|
public/ircfmt.woff2: gen-ircfmt.awk
|
||||||
awk -v Output=$@ -f gen-ircfmt.awk
|
$(AWK) -v Output=$@ -f gen-ircfmt.awk
|
||||||
public/mithril.js:
|
public/mithril.js:
|
||||||
curl -Lo $@ https://unpkg.com/mithril/mithril.js
|
curl -Lo $@ https://unpkg.com/mithril/mithril.js
|
||||||
clean:
|
clean:
|
||||||
|
|||||||
@@ -120,6 +120,9 @@ button:hover:active {
|
|||||||
.item.activity {
|
.item.activity {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
.item:hover {
|
||||||
|
background: #f8f8f8;
|
||||||
|
}
|
||||||
.item.current {
|
.item.current {
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
background: #eee;
|
background: #eee;
|
||||||
|
|||||||
128
xP/public/xP.js
128
xP/public/xP.js
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2022, Přemysl Eric Janouch <p@janouch.name>
|
// Copyright (c) 2022 - 2023, Přemysl Eric Janouch <p@janouch.name>
|
||||||
// SPDX-License-Identifier: 0BSD
|
// SPDX-License-Identifier: 0BSD
|
||||||
import * as Relay from './proto.js'
|
import * as Relay from './proto.js'
|
||||||
|
|
||||||
@@ -197,6 +197,14 @@ function bufferResetStats(b) {
|
|||||||
b.highlighted = false
|
b.highlighted = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bufferPopExcessLines(b) {
|
||||||
|
// Let "new" messages be, if only because pulling the log file
|
||||||
|
// is much more problematic in the web browser than in xC.
|
||||||
|
// TODO: Make the limit configurable, or extract general.backlog_limit.
|
||||||
|
const old = b.lines.length - b.newMessages - b.newUnimportantMessages
|
||||||
|
b.lines.splice(0, old - 1000)
|
||||||
|
}
|
||||||
|
|
||||||
function bufferActivate(name) {
|
function bufferActivate(name) {
|
||||||
rpc.send({command: 'BufferActivate', bufferName: name})
|
rpc.send({command: 'BufferActivate', bufferName: name})
|
||||||
}
|
}
|
||||||
@@ -288,12 +296,19 @@ rpcEventHandlers.set(Relay.Event.BufferLine, e => {
|
|||||||
b.lines.push({...line})
|
b.lines.push({...line})
|
||||||
if (!(visible || e.leakToActive) ||
|
if (!(visible || e.leakToActive) ||
|
||||||
b.newMessages || b.newUnimportantMessages) {
|
b.newMessages || b.newUnimportantMessages) {
|
||||||
if (line.isUnimportant)
|
if (line.isUnimportant || e.leakToActive)
|
||||||
b.newUnimportantMessages++
|
b.newUnimportantMessages++
|
||||||
else
|
else
|
||||||
b.newMessages++
|
b.newMessages++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX: In its unkeyed diff algorithm, Mithril.js can only efficiently
|
||||||
|
// deal with common prefixes, i.e., indefinitely growing buffers.
|
||||||
|
// But we don't want to key all children of Buffer,
|
||||||
|
// so only trim buffers while they are, or once they become invisible.
|
||||||
|
if (e.bufferName != bufferCurrent)
|
||||||
|
bufferPopExcessLines(b)
|
||||||
|
|
||||||
if (e.leakToActive) {
|
if (e.leakToActive) {
|
||||||
let bc = buffers.get(bufferCurrent)
|
let bc = buffers.get(bufferCurrent)
|
||||||
bc.lines.push({...line, leaked: true})
|
bc.lines.push({...line, leaked: true})
|
||||||
@@ -336,7 +351,7 @@ rpcEventHandlers.set(Relay.Event.BufferStats, e => {
|
|||||||
if (b === undefined)
|
if (b === undefined)
|
||||||
return
|
return
|
||||||
|
|
||||||
b.newMessages = e.newMessages,
|
b.newMessages = e.newMessages
|
||||||
b.newUnimportantMessages = e.newUnimportantMessages
|
b.newUnimportantMessages = e.newUnimportantMessages
|
||||||
b.highlighted = e.highlighted
|
b.highlighted = e.highlighted
|
||||||
})
|
})
|
||||||
@@ -344,6 +359,11 @@ rpcEventHandlers.set(Relay.Event.BufferStats, e => {
|
|||||||
rpcEventHandlers.set(Relay.Event.BufferRename, e => {
|
rpcEventHandlers.set(Relay.Event.BufferRename, e => {
|
||||||
buffers.set(e.new, buffers.get(e.bufferName))
|
buffers.set(e.new, buffers.get(e.bufferName))
|
||||||
buffers.delete(e.bufferName)
|
buffers.delete(e.bufferName)
|
||||||
|
|
||||||
|
if (e.bufferName === bufferCurrent)
|
||||||
|
bufferCurrent = e.new
|
||||||
|
if (e.bufferName === bufferLast)
|
||||||
|
bufferLast = e.new
|
||||||
})
|
})
|
||||||
|
|
||||||
rpcEventHandlers.set(Relay.Event.BufferRemove, e => {
|
rpcEventHandlers.set(Relay.Event.BufferRemove, e => {
|
||||||
@@ -354,8 +374,16 @@ rpcEventHandlers.set(Relay.Event.BufferRemove, e => {
|
|||||||
|
|
||||||
rpcEventHandlers.set(Relay.Event.BufferActivate, e => {
|
rpcEventHandlers.set(Relay.Event.BufferActivate, e => {
|
||||||
let old = buffers.get(bufferCurrent)
|
let old = buffers.get(bufferCurrent)
|
||||||
if (old !== undefined)
|
if (old !== undefined) {
|
||||||
bufferResetStats(old)
|
bufferResetStats(old)
|
||||||
|
bufferPopExcessLines(old)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initial sync: trim all buffers to our limit, just for consistency.
|
||||||
|
if (bufferCurrent === undefined) {
|
||||||
|
for (let b of buffers.values())
|
||||||
|
bufferPopExcessLines(b)
|
||||||
|
}
|
||||||
|
|
||||||
bufferLast = bufferCurrent
|
bufferLast = bufferCurrent
|
||||||
let b = buffers.get(e.bufferName)
|
let b = buffers.get(e.bufferName)
|
||||||
@@ -387,6 +415,15 @@ rpcEventHandlers.set(Relay.Event.BufferActivate, e => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
rpcEventHandlers.set(Relay.Event.BufferInput, e => {
|
||||||
|
let b = buffers.get(e.bufferName)
|
||||||
|
if (b === undefined)
|
||||||
|
return
|
||||||
|
if (b.historyAt == b.history.length)
|
||||||
|
b.historyAt++
|
||||||
|
b.history.push(e.text)
|
||||||
|
})
|
||||||
|
|
||||||
rpcEventHandlers.set(Relay.Event.BufferClear, e => {
|
rpcEventHandlers.set(Relay.Event.BufferClear, e => {
|
||||||
let b = buffers.get(e.bufferName)
|
let b = buffers.get(e.bufferName)
|
||||||
if (b !== undefined)
|
if (b !== undefined)
|
||||||
@@ -453,14 +490,23 @@ let BufferList = {
|
|||||||
classes.push('highlighted')
|
classes.push('highlighted')
|
||||||
highlighted = true
|
highlighted = true
|
||||||
}
|
}
|
||||||
return m('.item', {
|
// The role makes it selectable in VIM-like browser extensions.
|
||||||
|
return m('.item[role=tab]', {
|
||||||
onclick: event => bufferActivate(name),
|
onclick: event => bufferActivate(name),
|
||||||
|
onauxclick: event => {
|
||||||
|
if (event.button == 1)
|
||||||
|
rpc.send({
|
||||||
|
command: 'BufferInput',
|
||||||
|
bufferName: name,
|
||||||
|
text: '/buffer close',
|
||||||
|
})
|
||||||
|
},
|
||||||
class: classes.join(' '),
|
class: classes.join(' '),
|
||||||
}, displayName)
|
}, displayName)
|
||||||
})
|
})
|
||||||
|
|
||||||
updateIcon(rpc.ws === undefined ? null : highlighted)
|
updateIcon(rpc.ws === undefined ? null : highlighted)
|
||||||
return m('.list', {}, items)
|
return m('.list[role=tablist]', {}, items)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -483,7 +529,8 @@ let Content = {
|
|||||||
while ((match = re.exec(text)) !== null) {
|
while ((match = re.exec(text)) !== null) {
|
||||||
if (end < match.index)
|
if (end < match.index)
|
||||||
a.push(m('span', attrs, text.substring(end, match.index)))
|
a.push(m('span', attrs, text.substring(end, match.index)))
|
||||||
a.push(m('a[target=_blank]', {href: match[0], ...attrs}, match[0]))
|
a.push(m('a[target=_blank][rel=noreferrer]',
|
||||||
|
{href: match[0], ...attrs}, match[0]))
|
||||||
end = re.lastIndex
|
end = re.lastIndex
|
||||||
}
|
}
|
||||||
if (end < text.length)
|
if (end < text.length)
|
||||||
@@ -566,12 +613,6 @@ let Topic = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let Buffer = {
|
let Buffer = {
|
||||||
controller: new AbortController(),
|
|
||||||
|
|
||||||
onbeforeremove: vnode => {
|
|
||||||
Buffer.controller.abort()
|
|
||||||
},
|
|
||||||
|
|
||||||
onupdate: vnode => {
|
onupdate: vnode => {
|
||||||
if (bufferAutoscroll)
|
if (bufferAutoscroll)
|
||||||
vnode.dom.scrollTop = vnode.dom.scrollHeight
|
vnode.dom.scrollTop = vnode.dom.scrollHeight
|
||||||
@@ -579,8 +620,28 @@ let Buffer = {
|
|||||||
|
|
||||||
oncreate: vnode => {
|
oncreate: vnode => {
|
||||||
Buffer.onupdate(vnode)
|
Buffer.onupdate(vnode)
|
||||||
|
|
||||||
|
vnode.state.controller = new AbortController()
|
||||||
window.addEventListener('resize', event => Buffer.onupdate(vnode),
|
window.addEventListener('resize', event => Buffer.onupdate(vnode),
|
||||||
{signal: Buffer.controller.signal})
|
{signal: vnode.state.controller.signal})
|
||||||
|
|
||||||
|
Buffer.setDateChangeTimeout(vnode)
|
||||||
|
},
|
||||||
|
|
||||||
|
onremove: vnode => {
|
||||||
|
vnode.state.controller.abort()
|
||||||
|
clearTimeout(vnode.state.dateChangeTimeout)
|
||||||
|
},
|
||||||
|
|
||||||
|
setDateChangeTimeout: vnode => {
|
||||||
|
let midnight = new Date()
|
||||||
|
midnight.setHours(24, 0, 0, 0)
|
||||||
|
|
||||||
|
// Note that this doesn't handle time zone changes correctly.
|
||||||
|
vnode.state.dateChangeTimeout = setTimeout(() => {
|
||||||
|
m.redraw()
|
||||||
|
Buffer.setDateChangeTimeout(vnode)
|
||||||
|
}, midnight - new Date())
|
||||||
},
|
},
|
||||||
|
|
||||||
view: vnode => {
|
view: vnode => {
|
||||||
@@ -632,6 +693,12 @@ let Buffer = {
|
|||||||
const dom = event.target
|
const dom = event.target
|
||||||
bufferAutoscroll =
|
bufferAutoscroll =
|
||||||
dom.scrollTop + dom.clientHeight + 1 >= dom.scrollHeight
|
dom.scrollTop + dom.clientHeight + 1 >= dom.scrollHeight
|
||||||
|
|
||||||
|
let b = buffers.get(bufferCurrent)
|
||||||
|
if (b !== undefined && b.highlighted && !bufferAutoscroll) {
|
||||||
|
b.highlighted = false
|
||||||
|
m.redraw()
|
||||||
|
}
|
||||||
}}, lines)
|
}}, lines)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -647,7 +714,8 @@ let Log = {
|
|||||||
while ((match = re.exec(text)) !== null) {
|
while ((match = re.exec(text)) !== null) {
|
||||||
if (end < match.index)
|
if (end < match.index)
|
||||||
a.push(text.substring(end, match.index))
|
a.push(text.substring(end, match.index))
|
||||||
a.push(m('a[target=_blank]', {href: match[0]}, match[0]))
|
a.push(m('a[target=_blank][rel=noreferrer]',
|
||||||
|
{href: match[0]}, match[0]))
|
||||||
end = re.lastIndex
|
end = re.lastIndex
|
||||||
}
|
}
|
||||||
if (end < text.length)
|
if (end < text.length)
|
||||||
@@ -935,7 +1003,7 @@ let Input = {
|
|||||||
rpc.send({command: 'Active'})
|
rpc.send({command: 'Active'})
|
||||||
|
|
||||||
let b = buffers.get(bufferCurrent)
|
let b = buffers.get(bufferCurrent)
|
||||||
if (b === undefined)
|
if (b === undefined || event.isComposing)
|
||||||
return
|
return
|
||||||
|
|
||||||
let textarea = event.currentTarget
|
let textarea = event.currentTarget
|
||||||
@@ -981,10 +1049,23 @@ let Input = {
|
|||||||
} else if (!event.altKey && !event.ctrlKey && !event.metaKey &&
|
} else if (!event.altKey && !event.ctrlKey && !event.metaKey &&
|
||||||
!event.shiftKey) {
|
!event.shiftKey) {
|
||||||
handled = true
|
handled = true
|
||||||
switch (event.keyCode) {
|
switch (event.key) {
|
||||||
case 9: success = Input.complete(b, textarea); break
|
case 'PageUp':
|
||||||
case 13: success = Input.submit(b, textarea); break
|
Array.from(document.getElementsByClassName('buffer'))
|
||||||
default: handled = false
|
.forEach(b => b.scrollBy(0, -b.clientHeight))
|
||||||
|
break
|
||||||
|
case 'PageDown':
|
||||||
|
Array.from(document.getElementsByClassName('buffer'))
|
||||||
|
.forEach(b => b.scrollBy(0, +b.clientHeight))
|
||||||
|
break
|
||||||
|
case 'Tab':
|
||||||
|
success = Input.complete(b, textarea);
|
||||||
|
break
|
||||||
|
case 'Enter':
|
||||||
|
success = Input.submit(b, textarea);
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
handled = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!success)
|
if (!success)
|
||||||
@@ -1049,6 +1130,13 @@ let lastWasEscape = false
|
|||||||
document.addEventListener('keydown', event => {
|
document.addEventListener('keydown', event => {
|
||||||
event.escapePrefix = lastWasEscape
|
event.escapePrefix = lastWasEscape
|
||||||
if (lastWasEscape) {
|
if (lastWasEscape) {
|
||||||
|
// https://www.w3.org/TR/uievents-key/#keys-modifier
|
||||||
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1232918
|
||||||
|
if (["Alt", "AltGraph", "CapsLock", "Control", "Fn", "FnLock",
|
||||||
|
"Meta", "NumLock", "ScrollLock", "Shift", "Symbol", "SymbolLock",
|
||||||
|
"Hyper", "Super", "OS"].indexOf(event.key) != -1)
|
||||||
|
return
|
||||||
|
|
||||||
lastWasEscape = false
|
lastWasEscape = false
|
||||||
} else if (event.code == 'Escape' &&
|
} else if (event.code == 'Escape' &&
|
||||||
navigator.userAgentData?.platform === 'macOS') {
|
navigator.userAgentData?.platform === 'macOS') {
|
||||||
|
|||||||
19
xP/xP.go
19
xP/xP.go
@@ -16,6 +16,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"nhooyr.io/websocket"
|
"nhooyr.io/websocket"
|
||||||
@@ -159,13 +160,21 @@ func clientWriteError(ctx context.Context, ws *websocket.Conn, err error) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleWS(w http.ResponseWriter, r *http.Request) {
|
func handleWS(w http.ResponseWriter, r *http.Request) {
|
||||||
ws, err := websocket.Accept(w, r, &websocket.AcceptOptions{
|
opts := &websocket.AcceptOptions{
|
||||||
InsecureSkipVerify: true,
|
InsecureSkipVerify: true,
|
||||||
// Note that Safari can be broken with compression.
|
CompressionMode: websocket.CompressionContextTakeover,
|
||||||
CompressionMode: websocket.CompressionContextTakeover,
|
|
||||||
// This is for the payload; set higher to avoid overhead.
|
// This is for the payload; set higher to avoid overhead.
|
||||||
CompressionThreshold: 64 << 10,
|
CompressionThreshold: 64 << 10,
|
||||||
})
|
}
|
||||||
|
|
||||||
|
// AppleWebKit can be broken with compression.
|
||||||
|
if agent := r.UserAgent(); strings.Contains(agent, " Version/") &&
|
||||||
|
(strings.HasPrefix(agent, "Mozilla/5.0 (Macintosh; ") ||
|
||||||
|
strings.HasPrefix(agent, "Mozilla/5.0 (iPhone; ")) {
|
||||||
|
opts.CompressionMode = websocket.CompressionDisabled
|
||||||
|
}
|
||||||
|
|
||||||
|
ws, err := websocket.Accept(w, r, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Client rejected: " + err.Error())
|
log.Println("Client rejected: " + err.Error())
|
||||||
return
|
return
|
||||||
@@ -295,5 +304,5 @@ func main() {
|
|||||||
WriteTimeout: 60 * time.Second,
|
WriteTimeout: 60 * time.Second,
|
||||||
MaxHeaderBytes: 32 << 10,
|
MaxHeaderBytes: 32 << 10,
|
||||||
}
|
}
|
||||||
log.Fatal(s.ListenAndServe())
|
log.Fatalln(s.ListenAndServe())
|
||||||
}
|
}
|
||||||
|
|||||||
3
xS/.gitignore
vendored
Normal file
3
xS/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
/xS
|
||||||
|
/xS-replies.go
|
||||||
|
/xS.1
|
||||||
18
xS/Makefile
Normal file
18
xS/Makefile
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
.POSIX:
|
||||||
|
.SUFFIXES:
|
||||||
|
AWK = env LC_ALL=C awk
|
||||||
|
|
||||||
|
outputs = xS xS-replies.go xS.1
|
||||||
|
all: $(outputs)
|
||||||
|
|
||||||
|
xS: xS.go ../xK-version xS-replies.go
|
||||||
|
go build -ldflags "-X 'main.projectVersion=$$(cat ../xK-version)'" -o $@
|
||||||
|
xS-replies.go: xS-gen-replies.awk xS-replies
|
||||||
|
$(AWK) -f xS-gen-replies.awk xS-replies > $@
|
||||||
|
xS.1: ../xK-version ../liberty/tools/asciiman.awk xS.adoc
|
||||||
|
env "asciidoc-release-version=$$(cat ../xK-version)" \
|
||||||
|
$(AWK) -f ../liberty/tools/asciiman.awk xS.adoc > $@
|
||||||
|
test: all
|
||||||
|
go test
|
||||||
|
clean:
|
||||||
|
rm -f $(outputs)
|
||||||
132
xS/irc.go
Normal file
132
xS/irc.go
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ircToLower(c byte) byte {
|
||||||
|
switch c {
|
||||||
|
case '[':
|
||||||
|
return '{'
|
||||||
|
case ']':
|
||||||
|
return '}'
|
||||||
|
case '\\':
|
||||||
|
return '|'
|
||||||
|
case '~':
|
||||||
|
return '^'
|
||||||
|
}
|
||||||
|
if c >= 'A' && c <= 'Z' {
|
||||||
|
return c + ('a' - 'A')
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
func ircToUpper(c byte) byte {
|
||||||
|
switch c {
|
||||||
|
case '{':
|
||||||
|
return '['
|
||||||
|
case '}':
|
||||||
|
return ']'
|
||||||
|
case '|':
|
||||||
|
return '\\'
|
||||||
|
case '^':
|
||||||
|
return '~'
|
||||||
|
}
|
||||||
|
if c >= 'a' && c <= 'z' {
|
||||||
|
return c - ('a' - 'A')
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert identifier to a canonical form for case-insensitive comparisons.
|
||||||
|
// ircToUpper is used so that statically initialized maps can be in uppercase.
|
||||||
|
func ircToCanon(ident string) string {
|
||||||
|
var canon []byte
|
||||||
|
for _, c := range []byte(ident) {
|
||||||
|
canon = append(canon, ircToUpper(c))
|
||||||
|
}
|
||||||
|
return string(canon)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ircEqual(s1, s2 string) bool {
|
||||||
|
return ircToCanon(s1) == ircToCanon(s2)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ircFnmatch(pattern string, s string) bool {
|
||||||
|
pattern, s = ircToCanon(pattern), ircToCanon(s)
|
||||||
|
// FIXME: This should not support [] ranges and handle '/' specially.
|
||||||
|
// We could translate the pattern to a regular expression.
|
||||||
|
matched, _ := filepath.Match(pattern, s)
|
||||||
|
return matched
|
||||||
|
}
|
||||||
|
|
||||||
|
var reMsg = regexp.MustCompile(
|
||||||
|
`^(?:@([^ ]*) +)?(?::([^! ]*)(?:!([^@]*)@([^ ]*))? +)?([^ ]+)(.*)?$`)
|
||||||
|
var reArgs = regexp.MustCompile(`:.*| [^: ][^ ]*`)
|
||||||
|
|
||||||
|
type message struct {
|
||||||
|
tags map[string]string // IRC 3.2 message tags
|
||||||
|
nick string // optional nickname
|
||||||
|
user string // optional username
|
||||||
|
host string // optional hostname or IP address
|
||||||
|
command string // command name
|
||||||
|
params []string // arguments
|
||||||
|
}
|
||||||
|
|
||||||
|
func ircUnescapeMessageTag(value string) string {
|
||||||
|
var buf []byte
|
||||||
|
escape := false
|
||||||
|
for i := 0; i < len(value); i++ {
|
||||||
|
if escape {
|
||||||
|
switch value[i] {
|
||||||
|
case ':':
|
||||||
|
buf = append(buf, ';')
|
||||||
|
case 's':
|
||||||
|
buf = append(buf, ' ')
|
||||||
|
case 'r':
|
||||||
|
buf = append(buf, '\r')
|
||||||
|
case 'n':
|
||||||
|
buf = append(buf, '\n')
|
||||||
|
default:
|
||||||
|
buf = append(buf, value[i])
|
||||||
|
}
|
||||||
|
escape = false
|
||||||
|
} else if value[i] == '\\' {
|
||||||
|
escape = true
|
||||||
|
} else {
|
||||||
|
buf = append(buf, value[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return string(buf)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ircParseMessageTags(tags string, out map[string]string) {
|
||||||
|
for _, tag := range strings.Split(tags, ";") {
|
||||||
|
if tag == "" {
|
||||||
|
// Ignore empty.
|
||||||
|
} else if equal := strings.IndexByte(tag, '='); equal < 0 {
|
||||||
|
out[tag] = ""
|
||||||
|
} else {
|
||||||
|
out[tag[:equal]] = ircUnescapeMessageTag(tag[equal+1:])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ircParseMessage(line string) *message {
|
||||||
|
m := reMsg.FindStringSubmatch(line)
|
||||||
|
if m == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := message{nil, m[2], m[3], m[4], m[5], nil}
|
||||||
|
if m[1] != "" {
|
||||||
|
msg.tags = make(map[string]string)
|
||||||
|
ircParseMessageTags(m[1], msg.tags)
|
||||||
|
}
|
||||||
|
for _, x := range reArgs.FindAllString(m[6], -1) {
|
||||||
|
msg.params = append(msg.params, x[1:])
|
||||||
|
}
|
||||||
|
return &msg
|
||||||
|
}
|
||||||
20
xS/xS-gen-replies.awk
Executable file
20
xS/xS-gen-replies.awk
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/awk -f
|
||||||
|
/^[0-9]+ *(ERR|RPL)_[A-Z]+ *".*"$/ {
|
||||||
|
match($0, /".*"/)
|
||||||
|
ids[$1] = $2
|
||||||
|
texts[$2] = substr($0, RSTART, RLENGTH)
|
||||||
|
}
|
||||||
|
|
||||||
|
END {
|
||||||
|
print "package main"
|
||||||
|
print ""
|
||||||
|
print "const ("
|
||||||
|
for (i in ids)
|
||||||
|
printf("\t%s = %s\n", ids[i], i)
|
||||||
|
print ")"
|
||||||
|
print ""
|
||||||
|
print "var defaultReplies = map[int]string{"
|
||||||
|
for (i in ids)
|
||||||
|
print "\t" ids[i] ": " texts[ids[i]] ","
|
||||||
|
print "}"
|
||||||
|
}
|
||||||
87
xS/xS-replies
Normal file
87
xS/xS-replies
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
1 RPL_WELCOME ":Welcome to the Internet Relay Network %s!%s@%s"
|
||||||
|
2 RPL_YOURHOST ":Your host is %s, running version %s"
|
||||||
|
3 RPL_CREATED ":This server was created %s"
|
||||||
|
4 RPL_MYINFO "%s %s %s %s"
|
||||||
|
5 RPL_ISUPPORT "%s :are supported by this server"
|
||||||
|
211 RPL_STATSLINKINFO "%s %d %d %d %d %d %d"
|
||||||
|
212 RPL_STATSCOMMANDS "%s %d %d %d"
|
||||||
|
219 RPL_ENDOFSTATS "%c :End of STATS report"
|
||||||
|
221 RPL_UMODEIS "+%s"
|
||||||
|
242 RPL_STATSUPTIME ":Server Up %d days %d:%02d:%02d"
|
||||||
|
251 RPL_LUSERCLIENT ":There are %d users and %d services on %d servers"
|
||||||
|
252 RPL_LUSEROP "%d :operator(s) online"
|
||||||
|
253 RPL_LUSERUNKNOWN "%d :unknown connection(s)"
|
||||||
|
254 RPL_LUSERCHANNELS "%d :channels formed"
|
||||||
|
255 RPL_LUSERME ":I have %d clients and %d servers"
|
||||||
|
301 RPL_AWAY "%s :%s"
|
||||||
|
302 RPL_USERHOST ":%s"
|
||||||
|
303 RPL_ISON ":%s"
|
||||||
|
305 RPL_UNAWAY ":You are no longer marked as being away"
|
||||||
|
306 RPL_NOWAWAY ":You have been marked as being away"
|
||||||
|
311 RPL_WHOISUSER "%s %s %s * :%s"
|
||||||
|
312 RPL_WHOISSERVER "%s %s :%s"
|
||||||
|
313 RPL_WHOISOPERATOR "%s :is an IRC operator"
|
||||||
|
314 RPL_WHOWASUSER "%s %s %s * :%s"
|
||||||
|
315 RPL_ENDOFWHO "%s :End of WHO list"
|
||||||
|
317 RPL_WHOISIDLE "%s %d :seconds idle"
|
||||||
|
318 RPL_ENDOFWHOIS "%s :End of WHOIS list"
|
||||||
|
319 RPL_WHOISCHANNELS "%s :%s"
|
||||||
|
322 RPL_LIST "%s %d :%s"
|
||||||
|
323 RPL_LISTEND ":End of LIST"
|
||||||
|
324 RPL_CHANNELMODEIS "%s +%s"
|
||||||
|
329 RPL_CREATIONTIME "%s %d"
|
||||||
|
331 RPL_NOTOPIC "%s :No topic is set"
|
||||||
|
332 RPL_TOPIC "%s :%s"
|
||||||
|
333 RPL_TOPICWHOTIME "%s %s %d"
|
||||||
|
341 RPL_INVITING "%s %s"
|
||||||
|
346 RPL_INVITELIST "%s %s"
|
||||||
|
347 RPL_ENDOFINVITELIST "%s :End of channel invite list"
|
||||||
|
348 RPL_EXCEPTLIST "%s %s"
|
||||||
|
349 RPL_ENDOFEXCEPTLIST "%s :End of channel exception list"
|
||||||
|
351 RPL_VERSION "%s.%d %s :%s"
|
||||||
|
352 RPL_WHOREPLY "%s %s %s %s %s %s :%d %s"
|
||||||
|
353 RPL_NAMREPLY "%c %s :%s"
|
||||||
|
364 RPL_LINKS "%s %s :%d %s"
|
||||||
|
365 RPL_ENDOFLINKS "%s :End of LINKS list"
|
||||||
|
366 RPL_ENDOFNAMES "%s :End of NAMES list"
|
||||||
|
367 RPL_BANLIST "%s %s"
|
||||||
|
368 RPL_ENDOFBANLIST "%s :End of channel ban list"
|
||||||
|
369 RPL_ENDOFWHOWAS "%s :End of WHOWAS"
|
||||||
|
372 RPL_MOTD ":- %s"
|
||||||
|
375 RPL_MOTDSTART ":- %s Message of the day - "
|
||||||
|
376 RPL_ENDOFMOTD ":End of MOTD command"
|
||||||
|
391 RPL_TIME "%s :%s"
|
||||||
|
401 ERR_NOSUCHNICK "%s :No such nick/channel"
|
||||||
|
402 ERR_NOSUCHSERVER "%s :No such server"
|
||||||
|
403 ERR_NOSUCHCHANNEL "%s :No such channel"
|
||||||
|
404 ERR_CANNOTSENDTOCHAN "%s :Cannot send to channel"
|
||||||
|
406 ERR_WASNOSUCHNICK "%s :There was no such nickname"
|
||||||
|
409 ERR_NOORIGIN ":No origin specified"
|
||||||
|
410 ERR_INVALIDCAPCMD "%s :%s"
|
||||||
|
411 ERR_NORECIPIENT ":No recipient given (%s)"
|
||||||
|
412 ERR_NOTEXTTOSEND ":No text to send"
|
||||||
|
421 ERR_UNKNOWNCOMMAND "%s: Unknown command"
|
||||||
|
422 ERR_NOMOTD ":MOTD File is missing"
|
||||||
|
423 ERR_NOADMININFO "%s :No administrative info available"
|
||||||
|
431 ERR_NONICKNAMEGIVEN ":No nickname given"
|
||||||
|
432 ERR_ERRONEOUSNICKNAME "%s :Erroneous nickname"
|
||||||
|
433 ERR_NICKNAMEINUSE "%s :Nickname is already in use"
|
||||||
|
441 ERR_USERNOTINCHANNEL "%s %s :They aren't on that channel"
|
||||||
|
442 ERR_NOTONCHANNEL "%s :You're not on that channel"
|
||||||
|
443 ERR_USERONCHANNEL "%s %s :is already on channel"
|
||||||
|
445 ERR_SUMMONDISABLED ":SUMMON has been disabled"
|
||||||
|
446 ERR_USERSDISABLED ":USERS has been disabled"
|
||||||
|
451 ERR_NOTREGISTERED ":You have not registered"
|
||||||
|
461 ERR_NEEDMOREPARAMS "%s :Not enough parameters"
|
||||||
|
462 ERR_ALREADYREGISTERED ":Unauthorized command (already registered)"
|
||||||
|
467 ERR_KEYSET "%s :Channel key already set"
|
||||||
|
471 ERR_CHANNELISFULL "%s :Cannot join channel (+l)"
|
||||||
|
472 ERR_UNKNOWNMODE "%c :is unknown mode char to me for %s"
|
||||||
|
473 ERR_INVITEONLYCHAN "%s :Cannot join channel (+i)"
|
||||||
|
474 ERR_BANNEDFROMCHAN "%s :Cannot join channel (+b)"
|
||||||
|
475 ERR_BADCHANNELKEY "%s :Cannot join channel (+k)"
|
||||||
|
476 ERR_BADCHANMASK "%s :Bad Channel Mask"
|
||||||
|
481 ERR_NOPRIVILEGES ":Permission Denied- You're not an IRC operator"
|
||||||
|
482 ERR_CHANOPRIVSNEEDED "%s :You're not channel operator"
|
||||||
|
501 ERR_UMODEUNKNOWNFLAG ":Unknown MODE flag"
|
||||||
|
502 ERR_USERSDONTMATCH ":Cannot change mode for other users"
|
||||||
57
xS/xS.adoc
Normal file
57
xS/xS.adoc
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
xS(1)
|
||||||
|
=====
|
||||||
|
:doctype: manpage
|
||||||
|
:manmanual: xK Manual
|
||||||
|
:mansource: xK {release-version}
|
||||||
|
|
||||||
|
Name
|
||||||
|
----
|
||||||
|
xS - IRC daemon
|
||||||
|
|
||||||
|
Synopsis
|
||||||
|
--------
|
||||||
|
*xS* [_OPTION_]...
|
||||||
|
|
||||||
|
Description
|
||||||
|
-----------
|
||||||
|
*xS* is a basic IRC daemon for single-server networks, suitable for testing
|
||||||
|
and private use. When run without a configuration file, it will start listening
|
||||||
|
on the standard port 6667 and the "any" address.
|
||||||
|
|
||||||
|
Options
|
||||||
|
-------
|
||||||
|
*-debug*::
|
||||||
|
Do not daemonize, print more information on the standard error stream
|
||||||
|
to help debug various issues.
|
||||||
|
|
||||||
|
*-systemd*::
|
||||||
|
Log using the format specified in *sd-daemon*(3).
|
||||||
|
|
||||||
|
*-h*, *-help*::
|
||||||
|
Display a help message and exit.
|
||||||
|
|
||||||
|
*-version*::
|
||||||
|
Output version information and exit.
|
||||||
|
|
||||||
|
*-writedefaultcfg*::
|
||||||
|
Write a configuration file with defaults, show its path and exit.
|
||||||
|
+
|
||||||
|
The file will be appropriately commented.
|
||||||
|
|
||||||
|
Files
|
||||||
|
-----
|
||||||
|
*xS* follows the XDG Base Directory Specification.
|
||||||
|
|
||||||
|
_~/.config/xS/xS.conf_::
|
||||||
|
_/etc/xdg/xS/xS.conf_::
|
||||||
|
The daemon's configuration file. Use the *-writedefaultcfg* option
|
||||||
|
to create a new one for editing.
|
||||||
|
|
||||||
|
Reporting bugs
|
||||||
|
--------------
|
||||||
|
Use https://git.janouch.name/p/xK to report bugs, request features,
|
||||||
|
or submit pull requests.
|
||||||
|
|
||||||
|
See also
|
||||||
|
--------
|
||||||
|
*sd-daemon*(3)
|
||||||
168
xS/xS_test.go
Normal file
168
xS/xS_test.go
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) 2015 - 2018, Přemysl Eric Janouch <p@janouch.name>
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
// purpose with or without fee is hereby granted.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||||
|
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||||
|
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||||
|
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
//
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
"reflect"
|
||||||
|
"syscall"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSplitString(t *testing.T) {
|
||||||
|
var splitStringTests = []struct {
|
||||||
|
s, delims string
|
||||||
|
ignoreEmpty bool
|
||||||
|
result []string
|
||||||
|
}{
|
||||||
|
{",a,,bc", ",", false, []string{"", "a", "", "bc"}},
|
||||||
|
{",a,,bc", ",", true, []string{"a", "bc"}},
|
||||||
|
{"a,;bc,", ",;", false, []string{"a", "", "bc", ""}},
|
||||||
|
{"a,;bc,", ",;", true, []string{"a", "bc"}},
|
||||||
|
{"", ",", false, []string{""}},
|
||||||
|
{"", ",", true, nil},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, d := range splitStringTests {
|
||||||
|
got := splitString(d.s, d.delims, d.ignoreEmpty)
|
||||||
|
if !reflect.DeepEqual(got, d.result) {
|
||||||
|
t.Errorf("case %d: %v should be %v\n", i, got, d.result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func socketpair() (*os.File, *os.File, error) {
|
||||||
|
pair, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_STREAM, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// See go #24331, this makes 1.11 use the internal poller
|
||||||
|
// while there wasn't a way to achieve that before.
|
||||||
|
if err := syscall.SetNonblock(int(pair[0]), true); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
if err := syscall.SetNonblock(int(pair[1]), true); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
fa := os.NewFile(uintptr(pair[0]), "a")
|
||||||
|
if fa == nil {
|
||||||
|
return nil, nil, os.ErrInvalid
|
||||||
|
}
|
||||||
|
|
||||||
|
fb := os.NewFile(uintptr(pair[1]), "b")
|
||||||
|
if fb == nil {
|
||||||
|
fa.Close()
|
||||||
|
return nil, nil, os.ErrInvalid
|
||||||
|
}
|
||||||
|
|
||||||
|
return fa, fb, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDetectTLS(t *testing.T) {
|
||||||
|
detectTLSFromFunc := func(t *testing.T, writer func(net.Conn)) bool {
|
||||||
|
// net.Pipe doesn't use file descriptors, we need a socketpair.
|
||||||
|
sockA, sockB, err := socketpair()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer sockA.Close()
|
||||||
|
defer sockB.Close()
|
||||||
|
|
||||||
|
fcB, err := net.FileConn(sockB)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
go writer(fcB)
|
||||||
|
|
||||||
|
fcA, err := net.FileConn(sockA)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
sc, err := fcA.(syscall.Conn).SyscallConn()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return detectTLS(sc)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("SSL_2.0", func(t *testing.T) {
|
||||||
|
if !detectTLSFromFunc(t, func(fc net.Conn) {
|
||||||
|
// The obsolete, useless, unsupported SSL 2.0 record format.
|
||||||
|
_, _ = fc.Write([]byte{0x80, 0x01, 0x01})
|
||||||
|
}) {
|
||||||
|
t.Error("could not detect SSL")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("crypto_tls", func(t *testing.T) {
|
||||||
|
if !detectTLSFromFunc(t, func(fc net.Conn) {
|
||||||
|
conn := tls.Client(fc, &tls.Config{InsecureSkipVerify: true})
|
||||||
|
_ = conn.Handshake()
|
||||||
|
}) {
|
||||||
|
t.Error("could not detect TLS")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("text", func(t *testing.T) {
|
||||||
|
if detectTLSFromFunc(t, func(fc net.Conn) {
|
||||||
|
_, _ = fc.Write([]byte("ПРЕВЕД"))
|
||||||
|
}) {
|
||||||
|
t.Error("detected UTF-8 as TLS")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("EOF", func(t *testing.T) {
|
||||||
|
type connCloseWriter interface {
|
||||||
|
net.Conn
|
||||||
|
CloseWrite() error
|
||||||
|
}
|
||||||
|
if detectTLSFromFunc(t, func(fc net.Conn) {
|
||||||
|
_ = fc.(connCloseWriter).CloseWrite()
|
||||||
|
}) {
|
||||||
|
t.Error("detected EOF as TLS")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIRC(t *testing.T) {
|
||||||
|
msg := ircParseMessage(
|
||||||
|
`@first=a\:\s\r\n\\;2nd :srv hi there :good m8 :how are you?`)
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(msg.tags, map[string]string{
|
||||||
|
"first": "a; \r\n\\",
|
||||||
|
"2nd": "",
|
||||||
|
}) {
|
||||||
|
t.Error("tags parsed incorrectly")
|
||||||
|
}
|
||||||
|
|
||||||
|
if msg.nick != "srv" || msg.user != "" || msg.host != "" {
|
||||||
|
t.Error("server name parsed incorrectly")
|
||||||
|
}
|
||||||
|
if msg.command != "hi" {
|
||||||
|
t.Error("command name parsed incorrectly")
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(msg.params,
|
||||||
|
[]string{"there", "good m8 :how are you?"}) {
|
||||||
|
t.Error("params parsed incorrectly")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !ircEqual("[fag]^", "{FAG}~") {
|
||||||
|
t.Error("string case comparison not according to RFC 2812")
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: More tests.
|
||||||
|
}
|
||||||
11
xW/.clang-format
Normal file
11
xW/.clang-format
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
BasedOnStyle: LLVM
|
||||||
|
ColumnLimit: 80
|
||||||
|
IndentWidth: 4
|
||||||
|
TabWidth: 4
|
||||||
|
UseTab: ForContinuationAndIndentation
|
||||||
|
AlwaysBreakAfterReturnType: AllDefinitions
|
||||||
|
BreakBeforeBraces: Linux
|
||||||
|
SpaceAfterCStyleCast: true
|
||||||
|
AlignAfterOpenBracket: DontAlign
|
||||||
|
AlignOperands: DontAlign
|
||||||
|
SpacesBeforeTrailingComments: 2
|
||||||
85
xW/CMakeLists.txt
Normal file
85
xW/CMakeLists.txt
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
# The last version with Windows XP support is 3.13, we want to keep that
|
||||||
|
cmake_minimum_required (VERSION 3.10)
|
||||||
|
|
||||||
|
file (READ ../xK-version project_version)
|
||||||
|
configure_file (../xK-version xK-version.tag COPYONLY)
|
||||||
|
string (STRIP "${project_version}" project_version)
|
||||||
|
|
||||||
|
# This is an entirely separate CMake project--the main executables only build
|
||||||
|
# on Windows within Cygwin, and this Windows executable only builds on Linux
|
||||||
|
# cross-compiled, so you'd want to build them independently anyway.
|
||||||
|
project (xW VERSION "${project_version}"
|
||||||
|
DESCRIPTION "Win32 frontend for xC" LANGUAGES CXX)
|
||||||
|
|
||||||
|
set (CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
|
add_definitions (-DUNICODE -D_UNICODE)
|
||||||
|
add_compile_options ("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
|
||||||
|
add_compile_options ("$<$<CXX_COMPILER_ID:GNU>:-Wall;-Wextra>")
|
||||||
|
add_compile_options ("$<$<CXX_COMPILER_ID:Clang>:-Wall;-Wextra>")
|
||||||
|
add_link_options ("$<$<CXX_COMPILER_ID:GNU>:-static;-municode>")
|
||||||
|
add_link_options ("$<$<CXX_COMPILER_ID:Clang>:-static;-municode>")
|
||||||
|
|
||||||
|
set (project_config ${PROJECT_BINARY_DIR}/config.h)
|
||||||
|
configure_file (${PROJECT_SOURCE_DIR}/config.h.in ${project_config})
|
||||||
|
include_directories (${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})
|
||||||
|
|
||||||
|
# Produce a beep sample
|
||||||
|
if (NOT ${CMAKE_VERSION} VERSION_LESS 3.18.0)
|
||||||
|
set (find_program_REQUIRE REQUIRED)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
find_program (sox_EXECUTABLE sox ${find_program_REQUIRE})
|
||||||
|
add_custom_command (OUTPUT beep.wav
|
||||||
|
COMMAND ${sox_EXECUTABLE} -b 16 -Dr 44100 -n beep.wav
|
||||||
|
synth 0.1 0 25 triangle 800 vol 0.5 fade t 0 -0 0.005 pad 0 0.05
|
||||||
|
COMMENT "Generating a beep sample" VERBATIM)
|
||||||
|
|
||||||
|
# Rasterize SVG icons
|
||||||
|
set (root "${PROJECT_SOURCE_DIR}/..")
|
||||||
|
set (CMAKE_MODULE_PATH ${root}/liberty/cmake)
|
||||||
|
include (IconUtils)
|
||||||
|
|
||||||
|
set (icon_ico_list)
|
||||||
|
foreach (icon xW xW-highlighted)
|
||||||
|
set (icon_png_list)
|
||||||
|
foreach (icon_size 16 32 48)
|
||||||
|
icon_to_png (${icon} ${PROJECT_SOURCE_DIR}/${icon}.svg
|
||||||
|
${icon_size} ${PROJECT_BINARY_DIR}/icons icon_png)
|
||||||
|
list (APPEND icon_png_list ${icon_png})
|
||||||
|
endforeach ()
|
||||||
|
icon_to_png (${icon} ${PROJECT_SOURCE_DIR}/${icon}.svg
|
||||||
|
256 ${PROJECT_BINARY_DIR}/icons icon_png)
|
||||||
|
|
||||||
|
set (icon_ico ${PROJECT_BINARY_DIR}/${icon}.ico)
|
||||||
|
icon_for_win32 (${icon_ico} "${icon_png_list}" "${icon_png}")
|
||||||
|
list (APPEND icon_ico_list ${icon_ico})
|
||||||
|
endforeach ()
|
||||||
|
|
||||||
|
set_property (SOURCE xW.rc
|
||||||
|
APPEND PROPERTY OBJECT_DEPENDS ${icon_ico_list} beep.wav)
|
||||||
|
|
||||||
|
# Build the main executable and link it
|
||||||
|
find_program (awk_EXECUTABLE awk ${find_program_REQUIRE})
|
||||||
|
add_custom_command (OUTPUT xC-proto.cpp
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E env LC_ALL=C ${awk_EXECUTABLE}
|
||||||
|
-f ${root}/liberty/tools/lxdrgen.awk
|
||||||
|
-f ${root}/liberty/tools/lxdrgen-cpp.awk
|
||||||
|
-v PrefixCamel=Relay
|
||||||
|
${root}/xC.lxdr > xC-proto.cpp
|
||||||
|
DEPENDS
|
||||||
|
${root}/liberty/tools/lxdrgen.awk
|
||||||
|
${root}/liberty/tools/lxdrgen-cpp.awk
|
||||||
|
${root}/xC.lxdr
|
||||||
|
COMMENT "Generating xC relay protocol code" VERBATIM)
|
||||||
|
add_custom_target (xC-proto DEPENDS ${PROJECT_BINARY_DIR}/xC-proto.cpp)
|
||||||
|
|
||||||
|
add_executable (xW WIN32 xW.cpp xW.rc xW.manifest ${project_config}
|
||||||
|
${root}/liberty/tools/lxdrgen-cpp-win32.cpp)
|
||||||
|
target_link_libraries (xW comctl32 ws2_32 winmm)
|
||||||
|
add_dependencies (xW xC-proto)
|
||||||
|
|
||||||
|
# At least with MinGW, this is a fully independent portable executable
|
||||||
|
install (TARGETS xW DESTINATION .)
|
||||||
|
set (CPACK_GENERATOR ZIP)
|
||||||
|
include (CPack)
|
||||||
14
xW/config.h.in
Normal file
14
xW/config.h.in
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef CONFIG_H
|
||||||
|
#define CONFIG_H
|
||||||
|
|
||||||
|
#define PROJECT_NAME "${PROJECT_NAME}"
|
||||||
|
#define PROJECT_VERSION "${project_version}"
|
||||||
|
#define PROJECT_DESCRIPTION "${PROJECT_DESCRIPTION}"
|
||||||
|
#define PROJECT_AUTHOR "Přemysl Eric Janouch"
|
||||||
|
|
||||||
|
#define PROJECT_MAJOR (${PROJECT_VERSION_MAJOR}-0)
|
||||||
|
#define PROJECT_MINOR (${PROJECT_VERSION_MINOR}-0)
|
||||||
|
#define PROJECT_PATCH (${PROJECT_VERSION_PATCH}-0)
|
||||||
|
#define PROJECT_TWEAK (${PROJECT_VERSION_TWEAK}-0)
|
||||||
|
|
||||||
|
#endif // ! CONFIG_H
|
||||||
24
xW/xW-highlighted.svg
Normal file
24
xW/xW-highlighted.svg
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg version="1.1" width="48" height="48" viewBox="0 0 48 48"
|
||||||
|
xmlns="http://www.w3.org/2000/svg">
|
||||||
|
|
||||||
|
<defs>
|
||||||
|
<clipPath id="outer">
|
||||||
|
<rect x="-1" y="-0.15" width="5" height="3.30" />
|
||||||
|
</clipPath>
|
||||||
|
<clipPath id="inner">
|
||||||
|
<rect x="-1" y="0" width="5" height="3" />
|
||||||
|
</clipPath>
|
||||||
|
</defs>
|
||||||
|
|
||||||
|
<g transform="translate(6, 6) scale(12)" stroke-linecap="square">
|
||||||
|
<g clip-path="url(#outer)">
|
||||||
|
<path stroke="#ffffff" stroke-width="1.5" d="M 0.5,0 2.5,3" />
|
||||||
|
<path stroke="#ffffff" stroke-width="1.5" d="M 0.5,3 2.5,0" />
|
||||||
|
</g>
|
||||||
|
<g clip-path="url(#inner)">
|
||||||
|
<path stroke="#ff0000" stroke-width="0.9" d="M 0.5,0 2.5,3" />
|
||||||
|
<path stroke="#ff0000" stroke-width="0.9" d="M 0.5,3 2.5,0" />
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 806 B |
18
xW/xW-resources.h
Normal file
18
xW/xW-resources.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#define IDI_ICON 1
|
||||||
|
#define IDI_HIGHLIGHTED 2
|
||||||
|
#define IDR_BEEP 3
|
||||||
|
#define IDA_ACCELERATORS 10
|
||||||
|
|
||||||
|
// Named after input_add_functions() in xC.
|
||||||
|
#define ID_PREVIOUS_BUFFER 11
|
||||||
|
#define ID_NEXT_BUFFER 12
|
||||||
|
#define ID_SWITCH_BUFFER 13
|
||||||
|
#define ID_GOTO_HIGHLIGHT 14
|
||||||
|
#define ID_GOTO_ACTIVITY 15
|
||||||
|
#define ID_TOGGLE_UNIMPORTANT 16
|
||||||
|
#define ID_DISPLAY_FULL_LOG 17
|
||||||
|
|
||||||
|
#define IDD_CONNECT 20
|
||||||
|
#define IDC_STATIC 21
|
||||||
|
#define IDC_HOST 22
|
||||||
|
#define IDC_PORT 23
|
||||||
25
xW/xW.manifest
Normal file
25
xW/xW.manifest
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||||
|
<assemblyIdentity name="xW" version="1.0.0.0" type="win32" />
|
||||||
|
<dependency>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="Microsoft.Windows.Common-Controls"
|
||||||
|
version="6.0.0.0" type="win32" processorArchitecture="*"
|
||||||
|
publicKeyToken="6595b64144ccf1df" language="*" />
|
||||||
|
</dependentAssembly>
|
||||||
|
</dependency>
|
||||||
|
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||||
|
<application>
|
||||||
|
<!-- Windows 10 -->
|
||||||
|
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
|
||||||
|
<!-- Windows 8.1 -->
|
||||||
|
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
|
||||||
|
<!-- Windows 8 -->
|
||||||
|
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
|
||||||
|
<!-- Windows 7 -->
|
||||||
|
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
|
||||||
|
<!-- Windows Vista -->
|
||||||
|
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />
|
||||||
|
</application>
|
||||||
|
</compatibility>
|
||||||
|
</assembly>
|
||||||
80
xW/xW.rc
Normal file
80
xW/xW.rc
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
#include <windows.h>
|
||||||
|
#include "xW-resources.h"
|
||||||
|
|
||||||
|
// https://devblogs.microsoft.com/oldnewthing/20190607-00/?p=102569
|
||||||
|
// For UTF-8 literals to work in both MinGW and Microsoft resource compilers,
|
||||||
|
// the pragma needs to be in this file, and before they're included.
|
||||||
|
#pragma code_page(65001)
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
// Beware of this madness https://gitlab.kitware.com/cmake/cmake/-/issues/23066
|
||||||
|
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "xW.manifest"
|
||||||
|
|
||||||
|
IDI_ICON ICON "xW.ico"
|
||||||
|
IDI_HIGHLIGHTED ICON "xW-highlighted.ico"
|
||||||
|
IDR_BEEP WAVE "beep.wav"
|
||||||
|
|
||||||
|
IDA_ACCELERATORS ACCELERATORS
|
||||||
|
BEGIN
|
||||||
|
"^p", ID_PREVIOUS_BUFFER
|
||||||
|
"^n", ID_NEXT_BUFFER
|
||||||
|
VK_F5, ID_PREVIOUS_BUFFER, VIRTKEY
|
||||||
|
VK_F6, ID_NEXT_BUFFER, VIRTKEY
|
||||||
|
VK_PRIOR, ID_PREVIOUS_BUFFER, CONTROL, VIRTKEY
|
||||||
|
VK_NEXT, ID_NEXT_BUFFER, CONTROL, VIRTKEY
|
||||||
|
VK_TAB, ID_SWITCH_BUFFER, CONTROL, VIRTKEY
|
||||||
|
// These are proper, but llvm-rc won't accept them (GitHub #64002).
|
||||||
|
#ifndef __clang__
|
||||||
|
"!", ID_GOTO_HIGHLIGHT, ALT
|
||||||
|
"a", ID_GOTO_ACTIVITY, ALT
|
||||||
|
"H", ID_TOGGLE_UNIMPORTANT, ALT
|
||||||
|
"h", ID_DISPLAY_FULL_LOG, ALT
|
||||||
|
#endif
|
||||||
|
END
|
||||||
|
|
||||||
|
// https://devblogs.microsoft.com/oldnewthing/20050204-00/?p=36523
|
||||||
|
// https://devblogs.microsoft.com/oldnewthing/20050207-00/?p=36513
|
||||||
|
//
|
||||||
|
// Note that this is still not the right font to use in newest Windows,
|
||||||
|
// that would be 9pt Segoe UI, as described in:
|
||||||
|
// https://learn.microsoft.com/en-us/windows/win32/uxguide/vis-fonts
|
||||||
|
// or even better yet, NONCLIENTMETRICS::lfMessageFont.
|
||||||
|
IDD_CONNECT DIALOGEX 0, 0, 150, 64
|
||||||
|
STYLE DS_SHELLFONT | DS_MODALFRAME | DS_CENTER \
|
||||||
|
| WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||||
|
CAPTION "Connect to Relay"
|
||||||
|
FONT 8, "MS Shell Dlg", 400 /*FW_NORMAL*/, 0 /*FALSE*/, 0x1 /*DEFAULT_CHARSET*/
|
||||||
|
BEGIN
|
||||||
|
LTEXT "&Host:", IDC_STATIC, 7, 10, 18, 8
|
||||||
|
EDITTEXT IDC_HOST, 39, 7, 104, 14, ES_AUTOHSCROLL
|
||||||
|
LTEXT "&Port:", IDC_STATIC, 7, 28, 18, 8
|
||||||
|
EDITTEXT IDC_PORT, 39, 25, 104, 14, ES_AUTOHSCROLL
|
||||||
|
DEFPUSHBUTTON "&Connect", IDOK, 39, 43, 50, 14
|
||||||
|
PUSHBUTTON "E&xit", IDCANCEL, 93, 43, 50, 14
|
||||||
|
END
|
||||||
|
|
||||||
|
VS_VERSION_INFO VERSIONINFO
|
||||||
|
FILEVERSION PROJECT_MAJOR, PROJECT_MINOR, PROJECT_PATCH, PROJECT_TWEAK
|
||||||
|
PRODUCTVERSION PROJECT_MAJOR, PROJECT_MINOR, PROJECT_PATCH, PROJECT_TWEAK
|
||||||
|
FILETYPE VFT_APP
|
||||||
|
BEGIN
|
||||||
|
BLOCK "StringFileInfo"
|
||||||
|
BEGIN
|
||||||
|
BLOCK "040904B0"
|
||||||
|
BEGIN
|
||||||
|
VALUE "CompanyName", PROJECT_AUTHOR
|
||||||
|
VALUE "FileDescription", PROJECT_DESCRIPTION
|
||||||
|
VALUE "FileVersion", PROJECT_VERSION
|
||||||
|
VALUE "InternalName", PROJECT_NAME
|
||||||
|
VALUE "LegalCopyright", PROJECT_AUTHOR
|
||||||
|
VALUE "OriginalFilename", PROJECT_NAME ".exe"
|
||||||
|
VALUE "ProductName", PROJECT_NAME
|
||||||
|
VALUE "ProductVersion", PROJECT_VERSION
|
||||||
|
END
|
||||||
|
END
|
||||||
|
|
||||||
|
BLOCK "VarFileInfo"
|
||||||
|
BEGIN
|
||||||
|
VALUE "Translation", 0x409, 1200
|
||||||
|
END
|
||||||
|
END
|
||||||
24
xW/xW.svg
Normal file
24
xW/xW.svg
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg version="1.1" width="48" height="48" viewBox="0 0 48 48"
|
||||||
|
xmlns="http://www.w3.org/2000/svg">
|
||||||
|
|
||||||
|
<defs>
|
||||||
|
<clipPath id="outer">
|
||||||
|
<rect x="-1" y="-0.15" width="5" height="3.30" />
|
||||||
|
</clipPath>
|
||||||
|
<clipPath id="inner">
|
||||||
|
<rect x="-1" y="0" width="5" height="3" />
|
||||||
|
</clipPath>
|
||||||
|
</defs>
|
||||||
|
|
||||||
|
<g transform="translate(6, 6) scale(12)" stroke-linecap="square">
|
||||||
|
<g clip-path="url(#outer)">
|
||||||
|
<path stroke="#ffffff" stroke-width="1.5" d="M 0.5,0 2.5,3" />
|
||||||
|
<path stroke="#ffffff" stroke-width="1.5" d="M 0.5,3 2.5,0" />
|
||||||
|
</g>
|
||||||
|
<g clip-path="url(#inner)">
|
||||||
|
<path stroke="#000000" stroke-width="0.2" d="M 0,0 2,3 M 1,0 3,3" />
|
||||||
|
<path stroke="#ff6600" stroke-width="0.3" d="M 0,3 2,0 M 1,3 3,0" />
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 818 B |
Reference in New Issue
Block a user