Compare commits

...

169 Commits

Author SHA1 Message Date
74fcb06828 Bump version, update NEWS
All checks were successful
Alpine 3.20 Success
Arch Linux AUR Success
OpenBSD 7.5 Success
2024-12-24 10:43:59 +01:00
8cf1abf135 Bump liberty 2024-12-23 23:08:50 +01:00
b87fbc93a6 Support musl libc
All checks were successful
Alpine 3.20 Success
Arch Linux AUR Success
OpenBSD 7.5 Success
2024-09-11 04:55:59 +02:00
ac1a21eac8 Bump liberty, fix calloc argument order
All checks were successful
Alpine 3.20 Success
Arch Linux AUR Success
OpenBSD 7.5 Success
2024-08-08 09:08:33 +02:00
6934550068 CMakeLists.txt: declare compatibility with 3.27
All checks were successful
Arch Linux AUR Success
Alpine 3.19 Success
OpenBSD 7.3 Success
Sadly, the 3.5 deprecation warning doesn't go away after this.
2023-08-01 03:14:48 +02:00
cda7e1b1f3 Try harder to find ncursesw 2023-07-24 09:01:54 +02:00
14c6d285fc CMakeLists.txt: fix OpenBSD build
Note that we still don't use link_directories() as often as we should.
2023-07-04 07:45:57 +02:00
ab5941aaef CMakeLists.txt: fix build on macOS 2023-07-04 02:50:00 +02:00
84d6c658e8 README.adoc: update package information 2023-07-01 22:01:16 +02:00
a89fadf860 Bump liberty, improve fallback manual page output 2022-10-09 01:05:35 +02:00
4023155b67 Improve link detection suppression in man page 2022-09-30 14:49:51 +02:00
4ed58dd89a Bump liberty, make use of its new asciiman.awk 2022-09-25 21:24:18 +02:00
022668fb23 Update README
libedit (editline) seems to work just fine now,
except for not being fully asynchronous.
2022-09-04 17:07:38 +02:00
ba5a6374b6 json-rpc-test-server: add a "wait" method
Considering the server's nature, the global lock-up it causes
shouldn't constitute a major problem.
2022-09-04 15:25:27 +02:00
67008963cf Update NEWS 2022-09-04 15:22:46 +02:00
c1b6918db3 Fix libedit history behaviour 2022-09-04 15:22:46 +02:00
3cf3c0215e Build with AsciiDoc as well as Asciidoctor 2022-08-24 01:09:30 +02:00
a2a72c8b92 Update .gitignore 2021-10-30 03:34:23 +02:00
57f89eba07 Add clang-format configuration 2021-10-30 02:59:33 +02:00
4795ee851d FindLibEV.cmake: synchronise 2021-10-30 01:56:48 +02:00
87a644cc59 Fix newer libedit (2021-08-29) 2021-10-28 08:30:41 +02:00
990cf5a1d4 Reflect the sibling project's new name
Better keep all schizophreny in my own head, rather than all projects.
2021-08-06 19:26:04 +02:00
4a5c818ba1 json-rpc-shell: respect the NO_COLOR env. variable 2021-07-07 19:16:00 +02:00
af5929a383 CMakeLists.txt: fix copy-pasted variable name 2020-10-30 16:48:02 +01:00
9f5845fc51 json-rpc-shell.adoc: minor improvements
Documented envvars and added a note about XDG paths.
2020-10-30 04:21:17 +01:00
3daf254b41 CMakeLists.txt: make this build in OpenBSD 2020-10-30 04:21:16 +01:00
c533fa2fd7 CMakeLists.txt: omit end{if,foreach} expressions
Their usefulness was almost negative.
2020-10-30 04:21:16 +01:00
2fe2d6bc03 Bump minimum CMake version to 3.0
A nice, round number.  This allows us to remove some boilerplate.
2020-10-30 04:21:16 +01:00
df93937789 CMakeLists.txt: fix an outdated comment 2020-10-30 04:21:15 +01:00
ae447065f7 Bump liberty 2020-10-30 04:21:15 +01:00
f9e157293c json-rpc-test-server: only return regular files
They can be symlinked.
2020-10-17 23:30:22 +02:00
42d1ff064f json-rpc-test-server: comment on some CGI details
There are some unresolved issues in the CGI clients
that needed a more precise description.
2020-10-17 23:09:29 +02:00
710f8e0b2d json-rpc-test-server: fix function names
Very obviously copied and pasted from the shell.
2020-10-16 23:55:15 +02:00
4938ee43bd json-rpc-test-server: try to send a 408
Also send "Connection: close" when we're closing the connection.

With HTTP/1.1 there come some responsibilities.

Surprisingly enough, the forward declaration is desirable
and the invocation a clean-up.
2020-10-15 04:59:01 +02:00
6927d022fb WebSocket: send a User-Agent header 2020-10-15 04:30:48 +02:00
75b2094cdd json-rpc-test-server: add a simple co-process mode
A disgusting copy-paste but it will have to do for now.

Closes #6
2020-10-15 03:20:20 +02:00
b3c377afdb json-rpc-test-server: WS: fix failures to upgrade
Similar to ad1aba9, only here we return 426 to the client.
2020-10-15 00:39:27 +02:00
4236a4943a WebSocket: adapt to common "await" infrastructure 2020-10-14 13:37:10 +02:00
23c728e535 Add a backend for co-processes
Targets language servers.

In this first stage, we don't need to support bi-directionality,
although it's a requirement for finishing this task.

Updates #4
2020-10-14 13:37:08 +02:00
dfe814316f This software is no longer simple 2020-10-14 13:36:35 +02:00
efc663a178 WebSocket: some clean-up 2020-10-14 12:25:22 +02:00
2b8f52ac72 Split out a http-parser wrapper 2020-10-14 12:25:22 +02:00
bb7ffe1da2 Simplify the FAIL macro 2020-10-14 12:25:21 +02:00
ad1aba9d22 WebSocket: fix upgrade processing
When http-parser sets the upgrade field, it checks for status code 101
and even resolves our TODO about checking the entire Connection header.
2020-10-14 09:44:46 +02:00
0107d09abc json-rpc-shell.adoc: document the M-Enter binding 2020-10-14 02:37:50 +02:00
01767198f2 WebSockets -> WebSocket
This is the correct name of the protocol, usage of the word
"WebSockets" should be limited.
2020-10-14 00:03:34 +02:00
5854ed1b32 Support reading OpenRPC documents from a file
Bump liberty, it generated incorrect help messages.
2020-10-13 21:48:24 +02:00
63c8a79479 Factor out init_backend()
The main() function is still way too long.
2020-10-13 21:07:40 +02:00
d489362a28 json-rpc-test-server: implement rpc.discover 2020-10-13 20:54:27 +02:00
c87869bef7 Cleanup
Prevent the last fuck-up from happening again.
2020-10-13 20:30:33 +02:00
fcf65f8377 Add libedit autocompletion back in
I've mistakenly removed it in the M-Enter change.
2020-10-13 20:19:19 +02:00
d820bc2f23 Bump version, update NEWS 2020-10-13 16:03:19 +02:00
b458fc1f99 libedit: bind M-Enter to newline-insert as well 2020-10-13 15:55:37 +02:00
0771c142fe json-rpc-test-server: fix reading the request URI 2020-10-13 04:46:08 +02:00
742632a931 Bump http-parser
Apparently it's reached maturity and there won't be any changes
anytime soon, making this the perfect time for an upgrade.
2020-10-13 04:35:42 +02:00
2221828763 OpenRPC: avoid eating HTTP/transport errors 2020-10-13 04:35:32 +02:00
c2a00511c0 Document OpenRPC tab completion support
Now that it's functional in both frontends, we can flaunt it.

I still don't want to make it the default.

Closes #1
2020-10-13 04:23:28 +02:00
2b18ebf314 Implement tab completion under libedit
I haven't tested it with real wide characters but it will have to do.
I wasn't even sure if this piece of crap could be coerced into doing
this at first, so it's a win for me.

It uses a variation of the code in degesch where we /don't/ want to
print the list of candidates on partial failure.

Updates #1
2020-10-13 03:58:26 +02:00
5d2cd01db0 json-rpc-test-server: fix a potential memory leak 2020-10-13 02:08:53 +02:00
ee79249d23 json-rpc-shell.adoc: update WebSocket notes
https://github.com/open-rpc/client-js also uses WebSockets,
although they don't seem to support notifications (in general).
2020-10-10 05:20:31 +02:00
160d23018a Bump liberty
resolve_relative_runtime_unique_filename() used to have a bug.
2020-10-10 05:09:11 +02:00
fed2892ee1 Readline: add trivial OpenRPC support
So far hidden under a switch and only for this frontend.
2020-10-10 05:09:10 +02:00
667b01cb73 Reorder help message entries a bit
Should be both more useful and more alphabetic this way.
2020-10-10 02:57:14 +02:00
20c8578084 Fix use of possibly uninitialised memory 2020-10-10 02:57:14 +02:00
57a3b4e990 Split make_json_rpc_call() in half 2020-10-10 02:57:13 +02:00
e4d1529b4d Slightly refactor make_json_rpc_call() 2020-10-10 02:57:13 +02:00
897a263ee7 Readline: make M-Enter insert a newline
Before, it was only possible with C-v C-j but it's too useful
to require such an awkward method.

There is a precedent in, e.g., zsh and fish for the new binding.
2020-10-09 20:41:37 +02:00
84702fa47d Fix handling terminal resizes while the terminal is suspended
GNU Readline has a misfeature.
2020-10-09 20:21:52 +02:00
b315892249 Readline: fix a dormant bug in prompt changes
For details, see a similar change in degesch from uirc3.
2020-10-09 20:17:17 +02:00
710f5f197f Make a release, create NEWS 2020-09-05 20:42:02 +02:00
ba68585d14 Streamline the manual page a bit
I have consulted `man 7 man-pages` but overall it's a huge mess.
2020-09-05 06:34:00 +02:00
984e5b4e7f Use saner defaults
So that most of the time users won't need to use any switches.

--pretty-print has been inverted into jq's --compact-output,
and --auto-id has been replaced with barely, if-at-all useful
--null-as-id.
2020-09-05 06:07:45 +02:00
d57a8bd3c7 Improve AsciiDoc compatibility
I need two renderers to work: hswg/libasciidoc and asciidoctor
in man page mode (and ideally in HTML as well).  That should be
covered now.

The triple-plus thing was the first thing that showed good results,
after trying backslashes, single-plus quoting and [] after ://.

The change of the source code block kind could be considered as
unification.  I'm combining tabs with spaces within one document
though, and I should get rid of the tabs in the rest of it then...
2020-09-05 04:36:43 +02:00
2962a644da Write a nice new man page in AsciiDoc
Taking some preliminary steps for inclusion in Linux distributions.

The help message has been slightly improved and the README extended,
with part of it now residing in the man page.

One less GNU dependency, for what it's worth.
2020-09-05 03:51:36 +02:00
6f5ef30293 Move "connecting..." messages to the debug mode
So that the --verbose option does only one thing.
2020-09-05 03:50:14 +02:00
b7b1198be7 Fix libedit a bit more and discourage from using it 2020-09-02 01:08:09 +02:00
633f7007d1 json-rpc-test-server: add a "date" method 2020-09-01 23:41:20 +02:00
f4d178b3f6 Update copyright years 2020-09-01 21:03:53 +02:00
ee5317f865 json-rpc-test-server: reject non-null params in "ping" 2020-09-01 20:56:03 +02:00
20558ecd2b json-rpc-test-server: make sure to set the id in responses 2020-09-01 20:55:22 +02:00
f6225ac6cc Warn on unexpected "id" fields 2020-09-01 20:54:23 +02:00
16ec8261dc Make the verbose mode also show the raw input
To make it more useful for debugging.  We might also tie this
to the --debug option, though that would be a bit chaotic.
2020-09-01 20:37:08 +02:00
e49ff84b74 Strip trailing newlines from editor output 2020-09-01 19:26:37 +02:00
b7c9bfd9f5 Fix libedit crash
Again, I have no idea why it started to happen, it just occured
to me to try to change the call, and it turns out out it works.
2020-09-01 19:02:41 +02:00
f6165164ee Fix prompt attributes under libedit
I can only guess why this works, and I'm not sure I want to /know/.
2020-09-01 19:02:41 +02:00
3a445c2db2 Name change 2020-09-01 19:02:41 +02:00
45d023147a Bump liberty 2020-09-01 19:02:40 +02:00
90b5364b29 Fix running helper programs
A bug was introduced in 5c38087.
2019-09-23 23:07:04 +02:00
1840ac795e json-rpc-test-server: fix some outstanding issues 2018-10-19 01:15:12 +02:00
df38bcf775 Merge in a JSON-RPC 2.0 test server 2018-10-18 07:49:36 +02:00
1c52f9e37e demo-json-rpc-server -> json-rpc-test-server 2018-10-18 07:27:55 +02:00
6e152ae37c More debugging information for static file serving 2018-10-18 07:17:06 +02:00
8d66435568 Remember to set the server context in SCGI requests 2018-10-18 06:41:12 +02:00
d883f4cc71 Finish the FastCGI backend
Bump liberty, also fixing SCGI.
2018-10-18 06:35:29 +02:00
62945cceb3 Finish the WebSocket backend
Of course, everything so far hasn't been tested much.
2018-10-18 04:44:40 +02:00
580f0a0c59 Synthesize EOF events in SCGI 2018-10-18 04:44:39 +02:00
253e35e1e4 Wrap request::write_cb in a function 2018-10-17 23:34:59 +02:00
cf56921c4e Allow WebSockets to micromanage shutdowns
They have their reasons, mostly event-related.
2018-10-17 23:26:54 +02:00
a3ec0942f8 Implement basic connection teardown
I finally understand the codebase again.  It's rather complicated.
2018-10-17 22:59:40 +02:00
efd500ca3c Accelerated daemon quitting 2018-10-17 06:08:11 +02:00
13892fcd0e Clean up client de/allocation 2018-10-17 05:16:17 +02:00
1d638c9170 Say "finalize" instead of "destroy" where appropriate
- _make() returns a struct directly
 - _init() initializes over a pointer
 - _free() deinitializes over a pointer
 - _new() is like _init() but also allocates
 - _destroy() is like _free() but also deallocates

Finalization is a matching concept in garbage-collected languages.
2018-10-17 03:53:07 +02:00
83363e6383 FastCGI: make it work at least in theory 2018-10-17 03:50:39 +02:00
272145ace2 Clarify EOF behaviour 2018-10-17 02:21:19 +02:00
4c54bc42b9 Clean up and better document client_vtable 2018-10-16 04:45:36 +02:00
7d922352ea Rename client_vtable::destroy to finalize
Matches a similar concept from garbage-collected languages.
2018-10-16 04:34:00 +02:00
7f6db9d39f Improve WebSocket shutdown 2018-10-16 04:33:59 +02:00
7cefdd496f Cleanup 2018-10-16 04:05:42 +02:00
e9530f450e Call ws_handler_start() 2018-10-16 01:47:51 +02:00
dda22c2cd5 Eliminate unnecessary user_data pointers
The CONTAINER_OF macro can find the parent structure just as well.
2018-10-16 01:47:50 +02:00
7aff9c3475 Improve documentation 2018-10-16 01:47:50 +02:00
a14edb72e9 Make Doxygen a bit more useful 2018-10-15 05:07:57 +02:00
267a9a561b Eliminate some warnings 2018-10-15 03:28:09 +02:00
441c89f654 Handle FastCGI null request IDs better 2018-10-15 03:04:39 +02:00
14ded260a0 Clarify and degrade FastCGI multiplexing
No need to support more than 255 concurrent requests on one connection.
2018-10-15 03:02:49 +02:00
8b334e9c91 Fix fcgi_muxer_send()
Outgoing records were missing padding and the reserved field.
2018-10-13 04:08:43 +02:00
fd17b4e504 Update code comments 2018-10-13 04:07:45 +02:00
d182bcef3b More transient errors 2018-10-12 20:02:42 +02:00
329fc9b88f Bump liberty
Eliminates some fall-through warnings.
2018-10-11 21:03:34 +02:00
711d73f481 Fix text message UTF-8 validation 2018-06-24 06:12:16 +02:00
df340c13ed Add the missing Date header 2018-06-24 06:12:16 +02:00
8e986a6040 Remove .travis.yml
We don't depend on any proprietary services no longer.  I'll have to
make my own replacements with blackjack and hookers.  Until then,
the file stays in the commit log as an example.
2018-06-24 06:12:16 +02:00
131debe985 Bump liberty 2018-06-24 06:12:16 +02:00
b312c022ae Update README 2018-06-24 00:42:59 +02:00
4078c8845c Relicense to 0BSD, update mail address
I've come to the conclusion that copyright mostly just stands in the way
of software development.  In my jurisdiction I cannot give up my own
copyright and 0BSD seems to be the closest thing to public domain.

The updated mail address, also used in my author/committer lines,
is shorter and looks nicer.  People rarely interact anyway.
2018-06-24 00:21:10 +02:00
333efdc70f CMakeLists.txt: fix variable name 2018-06-24 00:15:53 +02:00
5e88608286 Bump liberty and http-parser 2017-06-20 14:04:40 +02:00
ca90e9df83 Fix teardown 2017-06-20 14:01:23 +02:00
419147beec Update README 2017-06-20 14:01:10 +02:00
b85d1d74a4 Don't respond to notifications 2017-02-06 20:48:14 +01:00
d35e733c6e Bump liberty
Fixing a bug in the WebSocket frame parser.
2017-02-06 19:47:24 +01:00
e6f9e53229 Fix segfault in WebSocket parsing 2017-02-06 18:51:52 +01:00
2986f6cda0 Fix segfault on client destruction etc. 2017-02-06 18:30:02 +01:00
c4ebf2ccd5 Fix segfault on missing Sec-WebSocket-Key 2017-02-06 18:28:53 +01:00
a785dc9670 WebSocket: fix header parsing 2017-02-06 18:28:40 +01:00
2b7d455471 Fix quitting 2017-02-06 17:18:24 +01:00
0ec0685714 Bump liberty 2017-02-05 22:44:01 +01:00
733451cf2a Fix and update LICENSE 2017-02-03 22:43:09 +01:00
369f94f5ab Travis CI: brevify notifications 2017-02-03 22:38:56 +01:00
7b94a03e8c Update IRC server address 2016-03-14 21:18:27 +01:00
8b66a3f074 Bump liberty 2016-01-17 04:48:17 +01:00
f273151447 Overall revision after a year
Use something closer to inheritance for clients
2016-01-17 04:48:00 +01:00
a95867dbee Fix daemonization 2016-01-16 22:33:57 +01:00
5298d802bb Fix compiler warning 2016-01-16 22:16:01 +01:00
af3cb3aaba Bump liberty 2016-01-16 06:41:31 +01:00
0f62ef26f5 Fix FindLibMagic.cmake 2016-01-16 06:37:56 +01:00
3c7b57bba9 Convert README to AsciiDoc 2015-09-27 02:11:38 +02:00
98bbea72d2 Fix README 2015-09-27 02:10:19 +02:00
df5b7ad71a Update README 2015-05-07 20:28:24 +02:00
6785d3a9ed Implement shutdown 2015-04-10 02:44:13 +02:00
1944f9f17d Travis CI: Change IRC notification address 2015-04-10 01:46:05 +02:00
4dbdc849d9 Steady progress
On the WebSocket service.

It's not too far from being finished now.  I just have to make some
sense of the code again and make sure it's correct.

Now that json-rpc-shell should be able to run against this, I can
also finally test if both of them work as they should.
2015-04-10 01:42:41 +02:00
db6dff4216 Move a lot of stuff to liberty 2015-03-29 03:14:20 +02:00
8aa232d32e Add and fix some preliminary tests 2015-03-23 20:12:53 +01:00
6e9109df4c Don't allow whitespace in base64 2015-03-23 20:12:02 +01:00
987eae5661 Steady progress
Renamed some constants, added basic UTF-8 validation.
2015-03-23 16:47:21 +01:00
9b7dd630e3 WebSockets improvements
- validate more HTTP stuff, use the newer RFC
 - validate the base64 key
2015-03-22 22:35:58 +01:00
c87d684154 Steady progress
Started parsing Content-Type properly after studying the HTTP RFC
for a significant period of time.

Some further WebSockets stuff.
2015-03-15 04:32:04 +01:00
23eb4cca38 Steady progress
Still in a state of total chaos, it appears.
2015-03-14 19:37:00 +01:00
4337038819 Try to lock a PID file 2015-03-11 23:57:25 +01:00
012a57b357 Steady progress
Some further refactoring, added a few comments, etc.

It's not about adding huge chunks of code anymore, and I'm slowly
moving towards getting the details right.

There's still a ton of TODO items, though.
2015-03-11 00:25:46 +01:00
3c0e48a429 Refactoring 2015-03-10 20:48:25 +01:00
5885d1aa69 Some intial WebSockets code 2015-03-09 23:32:01 +01:00
931fc441f6 Steady progress
Added static content serving with sane content type detection.

Started working on WebSockets (meanwhile neither SCGI or FastCGI is
finished and almost nothing has been tested).
2015-03-08 09:41:10 +01:00
9e0c9dd6d8 Steady progress
Still trying to figure out FastCGI.

At least I've finally implemented the JSON-RPC handler.
2015-03-08 05:51:51 +01:00
2733ead30f Figuring out how to close the connection 2015-03-06 19:49:33 +01:00
0b0d64124b Steady progress 2015-03-05 08:47:20 +01:00
a54230bddb Steady progress
I'm trying to figure out everything at once, i.e. the entire structure
of the application from top to bottom, trying to converge on a workable
design while refactoring still doesn't hurt as much as it would once
it's established.
2015-03-02 23:11:29 +01:00
8a3241d5c4 Initial commit
Not even the demo is able to compile yet.

I'm just tracking my progress.
2015-03-02 19:14:37 +01:00
14 changed files with 4774 additions and 563 deletions

33
.clang-format Normal file
View File

@@ -0,0 +1,33 @@
# clang-format is fairly limited, and these rules are approximate:
# - array initializers can get terribly mangled with clang-format 12.0,
# - sometimes it still aligns with space characters,
# - EV_DEFAULT_ and EV_A_ are always taken as identifiers,
# - struct name NL { NL ... NL } NL name; is unachievable.
BasedOnStyle: GNU
ColumnLimit: 80
IndentWidth: 4
TabWidth: 4
UseTab: ForContinuationAndIndentation
BreakBeforeBraces: Allman
SpaceAfterCStyleCast: true
AlignAfterOpenBracket: DontAlign
AlignOperands: DontAlign
AlignConsecutiveMacros: Consecutive
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
IndentGotoLabels: false
# IncludeCategories has some potential, but it may also break the build.
# Note that the documentation says the value should be "Never".
SortIncludes: false
# This is a compromise, it generally works out aesthetically better.
BinPackArguments: false
# Unfortunately, this can't be told to align to column 40 or so.
SpacesBeforeTrailingComments: 2
# liberty-specific macro body wrappers.
MacroBlockBegin: "BLOCK_START"
MacroBlockEnd: "BLOCK_END"
ForEachMacros: ["LIST_FOR_EACH"]

2
.gitignore vendored
View File

@@ -7,3 +7,5 @@
/json-rpc-shell.files
/json-rpc-shell.creator*
/json-rpc-shell.includes
/json-rpc-shell.cflags
/json-rpc-shell.cxxflags

View File

@@ -1,5 +1,5 @@
project (json-rpc-shell C)
cmake_minimum_required (VERSION 2.8.5)
cmake_minimum_required (VERSION 3.0...3.27)
project (json-rpc-shell VERSION 1.2.0 LANGUAGES C)
# Options
option (WANT_READLINE "Use GNU Readline for the UI (better)" ON)
@@ -10,54 +10,73 @@ if ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUCC)
# -Wunused-function is pretty annoying here, as everything is static
set (CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra -Wno-unused-function")
endif ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUCC)
# Version
set (project_VERSION_MAJOR "0")
set (project_VERSION_MINOR "1")
set (project_VERSION_PATCH "0")
set (project_VERSION "${project_VERSION_MAJOR}")
set (project_VERSION "${project_VERSION}.${project_VERSION_MINOR}")
set (project_VERSION "${project_VERSION}.${project_VERSION_PATCH}")
endif ()
# For custom modules
set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
set (CMAKE_MODULE_PATH
"${PROJECT_SOURCE_DIR}/cmake;${PROJECT_SOURCE_DIR}/liberty/cmake")
# Dependencies
find_package (Curses)
find_package (Ncursesw)
find_package (PkgConfig REQUIRED)
pkg_check_modules (dependencies REQUIRED libcurl jansson)
# Note that cURL can link to a different version of libssl than we do,
# in which case the results are undefined
pkg_check_modules (libssl REQUIRED libssl libcrypto)
pkg_check_modules (dependencies REQUIRED libcurl jansson libssl libcrypto)
find_package (LibEV REQUIRED)
pkg_check_modules (ncursesw ncursesw)
set (project_libraries ${dependencies_LIBRARIES}
${libssl_LIBRARIES} ${LIBEV_LIBRARIES})
include_directories (${dependencies_INCLUDE_DIRS}
${libssl_INCLUDE_DIRS} ${LIBEV_INCLUDE_DIRS})
set (project_libraries ${dependencies_LIBRARIES} ${LibEV_LIBRARIES})
include_directories (${dependencies_INCLUDE_DIRS} ${LibEV_INCLUDE_DIRS})
link_directories (${dependencies_LIBRARY_DIRS})
if (ncursesw_FOUND)
list (APPEND project_libraries ${ncursesw_LIBRARIES})
include_directories (${ncursesw_INCLUDE_DIRS})
if ("${CMAKE_SYSTEM_NAME}" MATCHES "BSD")
# Need this for SIGWINCH in FreeBSD and OpenBSD respectively;
# our POSIX version macros make it undefined
add_definitions (-D__BSD_VISIBLE=1 -D_BSD_SOURCE=1)
elseif (APPLE)
add_definitions (-D_DARWIN_C_SOURCE)
endif ()
# -liconv may or may not be a part of libc
find_library (iconv_LIBRARIES iconv)
if (iconv_LIBRARIES)
list (APPEND project_libraries ${iconv_LIBRARIES})
endif ()
include (CheckCSourceRuns)
set (CMAKE_REQUIRED_LIBRARIES ${project_libraries})
get_property (CMAKE_REQUIRED_INCLUDES
DIRECTORY "${PROJECT_SOURCE_DIR}" PROPERTY INCLUDE_DIRECTORIES)
CHECK_C_SOURCE_RUNS ("#include <iconv.h>
int main () { return iconv_open (\"UTF-8//TRANSLIT\", \"ISO-8859-1\")
== (iconv_t) -1; }" ICONV_ACCEPTS_TRANSLIT)
if (Ncursesw_FOUND)
list (APPEND project_libraries ${Ncursesw_LIBRARIES})
include_directories (${Ncursesw_INCLUDE_DIRS})
link_directories (${Ncursesw_LIBRARY_DIRS})
elseif (CURSES_FOUND)
list (APPEND project_libraries ${CURSES_LIBRARY})
include_directories (${CURSES_INCLUDE_DIR})
else (CURSES_FOUND)
else ()
message (SEND_ERROR "Curses not found")
endif (ncursesw_FOUND)
endif ()
if ((WANT_READLINE AND WANT_LIBEDIT) OR (NOT WANT_READLINE AND NOT WANT_LIBEDIT))
message (SEND_ERROR "You have to choose either GNU Readline or libedit")
elseif (WANT_READLINE)
list (APPEND project_libraries readline)
# OpenBSD's default readline is too old
if ("${CMAKE_SYSTEM_NAME}" MATCHES "OpenBSD")
include_directories (${OPENBSD_LOCALBASE}/include/ereadline)
list (APPEND project_libraries ereadline)
else ()
list (APPEND project_libraries readline)
endif ()
elseif (WANT_LIBEDIT)
pkg_check_modules (libedit REQUIRED libedit)
list (APPEND project_libraries ${libedit_LIBRARIES})
include_directories (${libedit_INCLUDE_DIRS})
endif ((WANT_READLINE AND WANT_LIBEDIT) OR (NOT WANT_READLINE AND NOT WANT_LIBEDIT))
endif ()
# Generate a configuration file
set (HAVE_READLINE "${WANT_READLINE}")
@@ -70,27 +89,59 @@ include_directories (${PROJECT_BINARY_DIR})
add_executable (${PROJECT_NAME} ${PROJECT_NAME}.c http-parser/http_parser.c)
target_link_libraries (${PROJECT_NAME} ${project_libraries})
# Development tools
find_package (LibMagic)
if (LIBMAGIC_FOUND)
include_directories (${LIBMAGIC_INCLUDE_DIRS})
add_executable (json-rpc-test-server
json-rpc-test-server.c http-parser/http_parser.c)
target_link_libraries (json-rpc-test-server
${project_libraries} ${LIBMAGIC_LIBRARIES})
endif ()
# The files to be installed
include (GNUInstallDirs)
install (TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
install (PROGRAMS json-format.pl DESTINATION ${CMAKE_INSTALL_BINDIR})
install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
# Generate documentation from program help
find_program (HELP2MAN_EXECUTABLE help2man)
if (NOT HELP2MAN_EXECUTABLE)
message (FATAL_ERROR "help2man not found")
endif (NOT HELP2MAN_EXECUTABLE)
# Generate documentation from text markup
find_program (ASCIIDOCTOR_EXECUTABLE asciidoctor)
find_program (A2X_EXECUTABLE a2x)
if (NOT ASCIIDOCTOR_EXECUTABLE AND NOT A2X_EXECUTABLE)
message (WARNING "Neither asciidoctor nor a2x were found, "
"falling back to a substandard manual page generator")
endif ()
foreach (page ${PROJECT_NAME})
set (page_output "${PROJECT_BINARY_DIR}/${page}.1")
list (APPEND project_MAN_PAGES "${page_output}")
add_custom_command (OUTPUT ${page_output}
COMMAND ${HELP2MAN_EXECUTABLE} -N
"${PROJECT_BINARY_DIR}/${page}" -o ${page_output}
DEPENDS ${page}
COMMENT "Generating man page for ${page}" VERBATIM)
endforeach (page)
if (ASCIIDOCTOR_EXECUTABLE)
add_custom_command (OUTPUT ${page_output}
COMMAND ${ASCIIDOCTOR_EXECUTABLE} -b manpage
-a release-version=${PROJECT_VERSION}
-o "${page_output}"
"${PROJECT_SOURCE_DIR}/${page}.adoc"
DEPENDS ${page}.adoc
COMMENT "Generating man page for ${page}" VERBATIM)
elseif (A2X_EXECUTABLE)
add_custom_command (OUTPUT ${page_output}
COMMAND ${A2X_EXECUTABLE} --doctype manpage --format manpage
-a release-version=${PROJECT_VERSION}
-D "${PROJECT_BINARY_DIR}"
"${PROJECT_SOURCE_DIR}/${page}.adoc"
DEPENDS ${page}.adoc
COMMENT "Generating man page for ${page}" VERBATIM)
else ()
set (ASCIIMAN ${PROJECT_SOURCE_DIR}/liberty/tools/asciiman.awk)
add_custom_command (OUTPUT ${page_output}
COMMAND env LC_ALL=C asciidoc-release-version=${PROJECT_VERSION}
awk -f ${ASCIIMAN} "${PROJECT_SOURCE_DIR}/${page}.adoc"
> ${page_output}
DEPENDS ${page}.adoc ${ASCIIMAN}
COMMENT "Generating man page for ${page}" VERBATIM)
endif ()
endforeach ()
add_custom_target (docs ALL DEPENDS ${project_MAN_PAGES})
@@ -98,22 +149,19 @@ foreach (page ${project_MAN_PAGES})
string (REGEX MATCH "\\.([0-9])$" manpage_suffix "${page}")
install (FILES "${page}"
DESTINATION "${CMAKE_INSTALL_MANDIR}/man${CMAKE_MATCH_1}")
endforeach (page)
endforeach ()
# CPack
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Shell for running JSON-RPC 2.0 queries")
set (CPACK_PACKAGE_VENDOR "Premysl Janouch")
set (CPACK_PACKAGE_CONTACT "Přemysl Janouch <p@janouch.name>")
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "A shell for JSON-RPC 2.0")
set (CPACK_PACKAGE_VENDOR "Premysl Eric Janouch")
set (CPACK_PACKAGE_CONTACT "Přemysl Eric Janouch <p@janouch.name>")
set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
set (CPACK_PACKAGE_VERSION_MAJOR ${project_VERSION_MAJOR})
set (CPACK_PACKAGE_VERSION_MINOR ${project_VERSION_MINOR})
set (CPACK_PACKAGE_VERSION_PATCH ${project_VERSION_PATCH})
set (CPACK_GENERATOR "TGZ;ZIP")
set (CPACK_PACKAGE_FILE_NAME
"${PROJECT_NAME}-${project_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
set (CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}-${project_VERSION}")
"${PROJECT_NAME}-${PROJECT_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
set (CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}-${PROJECT_VERSION}")
set (CPACK_SOURCE_GENERATOR "TGZ;ZIP")
set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git;/build;/CMakeLists.txt.user")
set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${project_VERSION}")
set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}")
include (CPack)

View File

@@ -1,4 +1,4 @@
Copyright (c) 2014 - 2016, Přemysl Janouch <p@janouch.name>
Copyright (c) 2014 - 2022, 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.

34
NEWS Normal file
View File

@@ -0,0 +1,34 @@
1.2.0 (2024-12-24)
* Add a backend for co-processes, such as language servers
* Support reading OpenRPC documents from a file
* Respect the NO_COLOR environment variable
* Miscellaneous libedit (editline) fixes
* Miscellaneous portability improvements
* json-rpc-test-server: implement OpenRPC discovery
* json-rpc-test-server: only serve regular files
* json-rpc-test-server: miscellaneous WebSocket fixes
1.1.0 (2020-10-13)
* Add method name tab completion using OpenRPC information
* Bind M-Enter to insert a newline into the command line
* json-rpc-test-server: fix a memory leak and request URI parsing
* Miscellaneous bug fixes
1.0.0 (2020-09-05)
* Initial release

View File

@@ -2,50 +2,44 @@ json-rpc-shell
==============
:compact-option:
'json-rpc-shell' is a simple shell for running JSON-RPC 2.0 queries.
'json-rpc-shell' is a shell for running JSON-RPC 2.0 queries.
This software has been created as a replacement for the following shell, which
is written in Java: http://software.dzhuvinov.com/json-rpc-2.0-shell.html
This software was originally created as a replacement for
http://software.dzhuvinov.com/json-rpc-2.0-shell.html[a different shell] made by
Vladimir Dzhuvinov, in order to avoid Java, but has evolved since.
Features
--------
In addition to most of the features provided by Vladimir Dzhuvinov's shell
you get the following niceties:
In addition to most of the features provided by its predecessor, you will get
the following niceties:
- configurable JSON syntax highlight, which with prettyprinting turned on
helps you make sense of the results significantly
- ability to pipe output through a shell command, so that you can view the
results in your favourite editor or redirect them to a file
- ability to edit the input line in your favourite editor as well with Alt+E
- WebSocket (RFC 6455) can also be used as a transport rather than HTTP
- even Language Server Protocol servers may be launched as a slave command
- support for method name tab completion using OpenRPC discovery or file input
Supported transports
--------------------
- HTTP
- HTTPS
- WebSocket
- WebSocket over TLS
WebSockets
~~~~~~~~~~
The JSON-RPC 2.0 spec doesn't say almost anything about underlying transports.
The way it's implemented here is that every request is sent as a single text
message. If it has an "id" field, i.e. it's not just a notification, the
client waits for a message from the server in response.
There's no support so far for any protocol extensions, nor for specifying
the higher-level protocol (the "Sec-Ws-Protocol" HTTP field).
Documentation
-------------
See the link:json-rpc-shell.adoc[man page] for information about usage.
The rest of this README will concern itself with externalities.
Packages
--------
Regular releases are sporadic. git master should be stable enough. You can get
a package with the latest development version from Archlinux's AUR.
Regular releases are sporadic. git master should be stable enough.
You can get a package with the latest development version using Arch Linux's
https://aur.archlinux.org/packages/json-rpc-shell-git[AUR],
or as a https://git.janouch.name/p/nixexprs[Nix derivation].
Building and Usage
------------------
Build dependencies: CMake, pkg-config, help2man,
liberty (included), http-parser (included) +
Runtime dependencies: libev, Jansson, cURL, openssl,
readline or libedit >= 2013-07-12,
Building
--------
Build dependencies: CMake, pkg-config, liberty (included),
http-parser (included), asciidoctor or asciidoc (recommended but optional) +
Runtime dependencies:
libev, Jansson, cURL, openssl, readline or libedit >= 2013-07-12
$ git clone --recursive https://git.janouch.name/p/json-rpc-shell.git
$ mkdir json-rpc-shell/build
@@ -62,10 +56,12 @@ Or you can try telling CMake to make a package for you. For Debian it is:
$ cpack -G DEB
# dpkg -i json-rpc-shell-*.deb
Note that for versions of CMake before 2.8.9, you need to prefix `cpack` with
`fakeroot` or file ownership will end up wrong.
Run the program with `--help` to obtain usage information.
Test server
-----------
If you install development packages for libmagic, an included test server will
be built but not installed which provides a trivial JSON-RPC 2.0 service with
FastCGI, SCGI, WebSocket and LSP-like co-process interfaces. It responds to
`ping` and `date`, supports OpenRPC discovery and it can serve static files.
Contributing and Support
------------------------

View File

@@ -5,14 +5,16 @@
# Some distributions do add it, though
find_package (PkgConfig REQUIRED)
pkg_check_modules (LIBEV QUIET libev)
pkg_check_modules (LibEV QUIET libev)
if (NOT LIBEV_FOUND)
find_path (LIBEV_INCLUDE_DIRS ev.h)
find_library (LIBEV_LIBRARIES NAMES ev)
set (required_vars LibEV_LIBRARIES)
if (NOT LibEV_FOUND)
find_path (LibEV_INCLUDE_DIRS ev.h)
find_library (LibEV_LIBRARIES NAMES ev)
list (APPEND required_vars LibEV_INCLUDE_DIRS)
endif ()
if (LIBEV_INCLUDE_DIRS AND LIBEV_LIBRARIES)
set (LIBEV_FOUND TRUE)
endif (LIBEV_INCLUDE_DIRS AND LIBEV_LIBRARIES)
endif (NOT LIBEV_FOUND)
include (FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS (LibEV DEFAULT_MSG ${required_vars})
mark_as_advanced (LibEV_LIBRARIES LibEV_INCLUDE_DIRS)

10
cmake/FindLibMagic.cmake Normal file
View File

@@ -0,0 +1,10 @@
# Public Domain
find_library (LIBMAGIC_LIBRARIES magic)
find_path (LIBMAGIC_INCLUDE_DIRS magic.h)
include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (LibMagic DEFAULT_MSG
LIBMAGIC_LIBRARIES LIBMAGIC_INCLUDE_DIRS)
mark_as_advanced (LIBMAGIC_LIBRARIES LIBMAGIC_INCLUDE_DIRS)

View File

@@ -2,10 +2,12 @@
#define CONFIG_H
#define PROGRAM_NAME "${PROJECT_NAME}"
#define PROGRAM_VERSION "${project_VERSION}"
#define PROGRAM_VERSION "${PROJECT_VERSION}"
#cmakedefine HAVE_READLINE
#cmakedefine HAVE_EDITLINE
#cmakedefine01 ICONV_ACCEPTS_TRANSLIT
#endif // ! CONFIG_H

196
json-rpc-shell.adoc Normal file
View File

@@ -0,0 +1,196 @@
json-rpc-shell(1)
=================
:doctype: manpage
:manmanual: json-rpc-shell Manual
:mansource: json-rpc-shell {release-version}
Name
----
json-rpc-shell - a shell for JSON-RPC 2.0
Synopsis
--------
*json-rpc-shell* [_OPTION_]... { _ENDPOINT_ | _COMMAND_ [_ARG_]... }
Description
-----------
:colon: :
The _ENDPOINT_ must be either an HTTP or a WebSocket URL, with or without TLS
(i.e. one of the _http{colon}//_, _https{colon}//_, _ws://_, _wss://_ schemas).
*json-rpc-shell* will use it to send any JSON-RPC 2.0 requests you enter on its
command line. The server's response will be parsed and validated, stripping it
of the protocol's noisy envelope. At your option, it can then also be
pretty-printed, rendered with adjustable syntax highlighting, or even piped
through another program such as the *less*(1) pager or the *jq*(1) JSON
processor.
Usage
~~~~~
Three things may appear on the internal command line, in a sequence. The first
one is always the name of the JSON-RPC method to call, as a bare word, separated
from the rest by white space. Following that, you may enter three kinds of JSON
values. If it is an object or an array, it constitutes the method parameters.
If it is a string or a number, it is taken as the "id" to use for the request,
which would be chosen for you automatically if left unspecified. Finally,
a null value indicates that the request should be sent as a notification,
lacking the ID completely. Booleans cannot be used for anything.
The response to the method call may be piped through external commands, the same
way you would do it in a Unix shell.
Exit the program by pressing C-c or C-d. No special keywords are reserved for
this action as they might conflict with method names.
Options
-------
Controlling output
~~~~~~~~~~~~~~~~~~
*-c*, *--compact-output*::
Do not pretty-print responses. Normally, spaces and newlines are added
where appropriate to improve readability.
*--color*=_WHEN_::
By default, when the output of the program is a terminal, JSON responses
are syntax-highlighted. This corresponds to the _auto_ setting. You may
also set this to _always_ or _never_. In either case, color is never
applied when piping to another program.
*-v*, *--verbose*::
Print raw requests and responses, including the JSON-RPC 2.0 envelope.
*-d*, *--debug*::
Print even more information to help debug various issues.
Protocol
~~~~~~~~
*-n*, *--null-as-id*::
Normally, entering a null JSON value on the command line causes
a notification to be sent. With this option, it is sent as the "id"
field of a normal request, which is discouraged by the specification.
*-t*, *--trust-all*::
Trust all SSL/TLS certificates. Useful in case that the certificate is
self-signed, or when the CA isn't in your CA store. Beware that this option
is about as good as using plain unencrypted HTTP.
*-o* _ORIGIN_, *--origin*=_ORIGIN_::
Set the HTTP Origin header to _ORIGIN_. Some servers may need this.
*-O*[__PATH__], *--openrpc*[**=**__PATH__]::
Call "rpc.discover" upon start-up in order to pull in OpenRPC data for
tab completion of method names. If a path is given, it is read from a file.
*-e*, *--execute*::
Rather than an _ENDPOINT_, accept a command line to execute and communicate
with using the JSON-RPC 2.0 protocol variation used in the Language Server
Protocol.
Program information
~~~~~~~~~~~~~~~~~~~
*-h*, *--help*::
Display a help message and exit.
*-V*, *--version*::
Output version information and exit.
*--write-default-cfg*[**=**__PATH__]::
Write a default configuration file, show its path and exit.
Environment
-----------
*VISUAL*, *EDITOR*::
The editor program to be launched by the M-e key binding.
If neither variable is set, it defaults to *vi*(1).
Files
-----
*json-rpc-shell* follows the XDG Base Directory Specification.
_~/.config/json-rpc-shell/json-rpc-shell.conf_::
The configuration file, in which you can configure color output and
CA certificate paths. Use the *--write-default-cfg* option to create
a new one for editing.
_~/.local/share/json-rpc-shell/history_::
All your past method invocations are stored here upon exit and loaded back
on start-up.
Notes
-----
Editing
~~~~~~~
While single-line editing on the command line may be satisfactory for simple
requests, it is often convenient or even necessary to run a full text editor
in order to construct complex objects or arrays, and may even be used to import
data from elsewhere. You can launch an editor for the current request using
the M-e key combination. Both *readline*(3) and *editline*(7) also support
multiline editing natively, press either M-Enter or C-v C-j in order to insert
newlines.
WebSocket
~~~~~~~~~
The JSON-RPC 2.0 specification doesn't say almost anything about underlying
transports. The way it's implemented here is that every request is sent as
a single text message. If it has an "id" field, i.e., it's not just
a notification, the client waits for a message from the server in response.
Should any message arrive unexpectedly, you will receive a warning.
There is no support so far for any protocol extensions, nor for specifying
the higher-level protocol (the "Sec-Ws-Protocol" HTTP field).
Bugs
----
The editline (libedit) frontend may exhibit some unexpected behaviour.
Examples
--------
Running some queries against json-rpc-test-server, included in the source
distribution of this program (public services are hard to find):
Methods without parameters
~~~~~~~~~~~~~~~~~~~~~~~~~~
$ json-rpc-shell ws://localhost:1234
json-rpc> ping
"pong"
json-rpc> date
{
"year": 2020,
"month": 9,
"day": 5,
"hours": 2,
"minutes": 23,
"seconds": 51
}
Notification with a parameter
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Notifications never produce a response, not even when the method is not known
to the server:
$ json-rpc-shell ws://localhost:1234
json-rpc> notify {"events": ["conquest", "war", "famine", "death"]} null
[Notification]
Piping in and out
~~~~~~~~~~~~~~~~~
GNU Readline always repeats the prompt, which makes this a bit less useful
for invoking from other programs:
$ echo 'ping | jq ascii_upcase' | json-rpc-shell ws://localhost:1234
json-rpc> ping | jq ascii_upcase
"PONG"
Reporting bugs
--------------
Use https://git.janouch.name/p/json-rpc-shell to report bugs, request features,
or submit pull requests.
See also
--------
*jq*(1), *readline*(3) or *editline*(7)
Specifications
~~~~~~~~~~~~~~
https://www.jsonrpc.org/specification +
https://www.json.org

File diff suppressed because it is too large Load Diff

3231
json-rpc-test-server.c Normal file

File diff suppressed because it is too large Load Diff

Submodule liberty updated: bb30c7d86e...1930f138d4