@@ -392,6 +392,27 @@ static void destroy_out_req(struct out_req *out_req, struct plugin *plugin)
392
392
strmap_del (& plugin -> out_reqs , out_req -> id , NULL );
393
393
}
394
394
395
+ void forward_notified (struct command * cmd ,
396
+ const char * method ,
397
+ const char * buf ,
398
+ const jsmntok_t * params ,
399
+ void * arg )
400
+ {
401
+ const jsmntok_t * msgtok ;
402
+ struct json_stream * js ;
403
+
404
+ /* FIXME: There are also progress indicators, how to forward them? */
405
+ msgtok = json_get_member (buf , params , "message" );
406
+ if (!msgtok )
407
+ return ;
408
+
409
+ js = plugin_notify_start (cmd , "message" );
410
+ json_add_tok (js , "level" , json_get_member (buf , params , "level" ), buf );
411
+ json_add_str_fmt (js , "message" , "%s: %s" ,
412
+ method , json_strdup (tmpctx , buf , msgtok ));
413
+ plugin_notify_end (cmd , js );
414
+ }
415
+
395
416
/* FIXME: Move lightningd/jsonrpc to common/ ? */
396
417
397
418
struct out_req *
@@ -409,6 +430,11 @@ jsonrpc_request_start_(struct command *cmd,
409
430
const char * buf ,
410
431
const jsmntok_t * result ,
411
432
void * arg ),
433
+ void (* notified )(struct command * command ,
434
+ const char * method ,
435
+ const char * buf ,
436
+ const jsmntok_t * params ,
437
+ void * arg ),
412
438
void * arg )
413
439
{
414
440
struct out_req * out ;
@@ -420,6 +446,7 @@ jsonrpc_request_start_(struct command *cmd,
420
446
out -> cmd = cmd ;
421
447
out -> cb = cb ;
422
448
out -> errcb = errcb ;
449
+ out -> notified = notified ;
423
450
out -> arg = arg ;
424
451
strmap_add (& cmd -> plugin -> out_reqs , out -> id , out );
425
452
tal_add_destructor2 (out , destroy_out_req , cmd -> plugin );
@@ -1085,9 +1112,19 @@ static void handle_rpc_reply(struct plugin *plugin, const char *buf, const jsmnt
1085
1112
bool cmd_freed ;
1086
1113
1087
1114
idtok = json_get_member (buf , toks , "id" );
1088
- if (!idtok )
1089
- /* FIXME: Don't simply ignore notifications! */
1115
+ if (!idtok ) {
1116
+ const jsmntok_t * paramstok ;
1117
+ /* It's a notification about a command! */
1118
+ paramstok = json_get_member (buf , toks , "params" );
1119
+ idtok = json_get_member (buf , paramstok , "id" );
1120
+ out = strmap_getn (& plugin -> out_reqs ,
1121
+ json_tok_full (buf , idtok ),
1122
+ json_tok_full_len (idtok ));
1123
+ if (!out || !out -> notified )
1124
+ return ;
1125
+ out -> notified (out -> cmd , out -> method , buf , paramstok , out -> arg );
1090
1126
return ;
1127
+ }
1091
1128
1092
1129
out = strmap_getn (& plugin -> out_reqs ,
1093
1130
json_tok_full (buf , idtok ),
@@ -1654,6 +1691,13 @@ static struct command_result *handle_init(struct command *cmd,
1654
1691
struct command * aux_cmd = aux_command (cmd );
1655
1692
1656
1693
io_new_conn (p , p -> rpc_conn -> fd , rpc_conn_init , p );
1694
+
1695
+ /* Enable notifications on all commands */
1696
+ req = jsonrpc_request_start (aux_cmd , "notifications" ,
1697
+ ignore_and_complete , plugin_broken_cb , NULL );
1698
+ json_add_bool (req -> js , "enable" , true);
1699
+ send_outreq (req );
1700
+
1657
1701
/* In case they intercept rpc_command, we can't do this sync. */
1658
1702
req = jsonrpc_request_start (aux_cmd , "listconfigs" ,
1659
1703
get_beglist , plugin_broken_cb , NULL );
0 commit comments