Compare commits

..

No commits in common. "0771c142fe8257aac22db7c02ca473b5fb4b13a1" and "2b18ebf3143f9be072260f2c69c9b39b8658f0fb" have entirely different histories.

5 changed files with 17 additions and 29 deletions

View File

@ -18,7 +18,6 @@ you get the following niceties:
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
- WebSockets (RFC 6455) can also be used as a transport rather than HTTP
- support for method name tab completion using OpenRPC discovery
Documentation
-------------

@ -1 +1 @@
Subproject commit ec8b5ee63f0e51191ea43bb0c6eac7bfbff3141d
Subproject commit 5d414fcb4b2ccc1ce9d6063292f9c63c9ec67b04

View File

@ -76,10 +76,6 @@ Protocol
*-o* _ORIGIN_, *--origin*=_ORIGIN_::
Set the HTTP Origin header to _ORIGIN_. Some servers may need this.
*-O*, *--openrpc*::
Call "rpc.discover" upon start-up in order to pull in OpenRPC data for
tab completion of method names.
Program information
~~~~~~~~~~~~~~~~~~~
*-h*, *--help*::

View File

@ -3225,16 +3225,24 @@ fail:
// --- OpenRPC information extraction ------------------------------------------
static void
parse_rpc_discover (struct app_context *ctx, struct str *buf, struct error **e)
init_openrpc (struct app_context *ctx)
{
if (!ctx->openrpc)
return;
json_t *id = json_integer (ctx->next_id++);
struct str buf = str_make ();
struct error *e = json_rpc_call_raw (ctx, "rpc.discover", id, NULL, &buf);
json_decref (id);
// Just optimistically punch through, I don't have time for this shit
json_error_t error;
json_t *response = NULL, *result = NULL, *value = NULL;
if (!(response = json_loadb (buf->str, buf->len, 0, &error)))
error_set (e, "parse failure: %s", error.text);
if (!e && !(response = json_loadb (buf.str, buf.len, 0, &error)))
error_set (&e, "parse failure: %s", error.text);
else if (!(result = json_object_get (response, "result"))
|| !(result = json_object_get (result, "methods")))
error_set (e, "unsupported");
error_set (&e, "unsupported");
else
{
const char *name = NULL;
@ -3244,25 +3252,10 @@ parse_rpc_discover (struct app_context *ctx, struct str *buf, struct error **e)
str_map_set (&ctx->methods, name, (void *) 1);
}
json_decref (response);
}
static void
init_openrpc (struct app_context *ctx)
{
if (!ctx->openrpc)
return;
json_t *id = json_integer (ctx->next_id++);
struct str buf = str_make ();
struct error *error;
if (!(error = json_rpc_call_raw (ctx, "rpc.discover", id, NULL, &buf)))
parse_rpc_discover (ctx, &buf, &error);
json_decref (id);
if (error)
if (e)
{
print_error ("OpenRPC: %s", error->message);
error_free (error);
print_error ("OpenRPC: %s", e->message);
error_free (e);
}
str_free (&buf);
}

View File

@ -1014,7 +1014,7 @@ static int
ws_handler_on_url (http_parser *parser, const char *at, size_t len)
{
struct ws_handler *self = parser->data;
str_append_data (&self->url, at, len);
str_append_data (&self->value, at, len);
return 0;
}