| 1689 | } |
| 1690 | |
| 1691 | static struct command_result *json_listconfigs(struct command *cmd, |
| 1692 | const char *buffer, |
| 1693 | const jsmntok_t *obj UNNEEDED, |
| 1694 | const jsmntok_t *params) |
| 1695 | { |
| 1696 | size_t i; |
| 1697 | struct json_stream *response = NULL; |
| 1698 | const char *configname; |
| 1699 | |
| 1700 | if (!param(cmd, buffer, params, |
| 1701 | p_opt("config", param_string, &configname), |
| 1702 | NULL)) |
| 1703 | return command_param_failed(); |
| 1704 | |
| 1705 | if (!configname) { |
| 1706 | response = json_stream_success(cmd); |
| 1707 | json_add_string(response, "# version", version()); |
| 1708 | } |
| 1709 | |
| 1710 | for (i = 0; i < opt_count; i++) { |
| 1711 | unsigned int len; |
| 1712 | const char *name; |
| 1713 | |
| 1714 | /* FIXME: Print out comment somehow? */ |
| 1715 | if (opt_table[i].type == OPT_SUBTABLE) |
| 1716 | continue; |
| 1717 | |
| 1718 | for (name = first_name(opt_table[i].names, &len); |
| 1719 | name; |
| 1720 | name = next_name(name, &len)) { |
| 1721 | /* Skips over first -, so just need to look for one */ |
| 1722 | if (name[0] != '-') |
| 1723 | continue; |
| 1724 | |
| 1725 | if (configname |
| 1726 | && !memeq(configname, strlen(configname), |
| 1727 | name + 1, len - 1)) |
| 1728 | continue; |
| 1729 | |
| 1730 | if (!response) |
| 1731 | response = json_stream_success(cmd); |
| 1732 | add_config(cmd->ld, response, &opt_table[i], |
| 1733 | name+1, len-1); |
| 1734 | /* If we have more than one long name, first |
| 1735 | * is preferred */ |
| 1736 | break; |
| 1737 | } |
| 1738 | } |
| 1739 | |
| 1740 | if (configname && !response) { |
| 1741 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1742 | "Unknown config option %s", |
| 1743 | configname); |
| 1744 | } |
| 1745 | return command_success(cmd, response); |
| 1746 | } |
| 1747 | |
| 1748 | static const struct json_command listconfigs_command = { |
nothing calls this directly
no test coverage detected