Calls itself repeatedly: first time, result is NULL */
| 113 | |
| 114 | /* Calls itself repeatedly: first time, result is NULL */ |
| 115 | static struct command_result *send_response(struct command *cmd, |
| 116 | const char *method UNUSED, |
| 117 | const char *buf UNUSED, |
| 118 | const jsmntok_t *result, |
| 119 | struct reply *reply) |
| 120 | { |
| 121 | size_t msglen = reply->len - reply->off; |
| 122 | u8 *cmd_msg; |
| 123 | enum commando_msgtype msgtype; |
| 124 | struct out_req *req; |
| 125 | |
| 126 | /* Limit is 64k, but there's a little overhead */ |
| 127 | if (msglen > 65000) { |
| 128 | msglen = 65000; |
| 129 | msgtype = COMMANDO_MSG_REPLY_CONTINUES; |
| 130 | } else { |
| 131 | if (msglen == 0) { |
| 132 | tal_free(reply); |
| 133 | return command_hook_success(cmd); |
| 134 | } |
| 135 | msgtype = COMMANDO_MSG_REPLY_TERM; |
| 136 | } |
| 137 | |
| 138 | cmd_msg = tal_arr(NULL, u8, 0); |
| 139 | towire_u16(&cmd_msg, msgtype); |
| 140 | towire_u64(&cmd_msg, reply->incoming->id); |
| 141 | towire(&cmd_msg, reply->buf + reply->off, msglen); |
| 142 | reply->off += msglen; |
| 143 | |
| 144 | req = jsonrpc_request_start(cmd, "sendcustommsg", |
| 145 | send_response, send_response, |
| 146 | reply); |
| 147 | json_add_node_id(req->js, "node_id", &reply->incoming->peer); |
| 148 | json_add_hex_talarr(req->js, "msg", cmd_msg); |
| 149 | tal_free(cmd_msg); |
| 150 | send_outreq(req); |
| 151 | |
| 152 | return command_still_pending(cmd); |
| 153 | } |
| 154 | |
| 155 | static struct command_result *cmd_done(struct command *command, |
| 156 | const char *method, |
no test coverage detected