| 2107 | } |
| 2108 | |
| 2109 | static void json_add_plugin_options(struct json_stream *stream, |
| 2110 | const char *fieldname, |
| 2111 | struct plugin *plugin, |
| 2112 | bool include_deprecated) |
| 2113 | { |
| 2114 | /* We don't allow multiple option names in plugins */ |
| 2115 | struct lightningd *ld = plugin->plugins->ld; |
| 2116 | const char **namesarr = tal_arr(tmpctx, const char *, 1); |
| 2117 | struct plugin_opt *popt; |
| 2118 | |
| 2119 | json_object_start(stream, fieldname); |
| 2120 | list_for_each(&plugin->plugin_opts, popt, list) { |
| 2121 | struct configvar *cv; |
| 2122 | const struct opt_table *ot; |
| 2123 | |
| 2124 | if (!include_deprecated && !plugin_opt_deprecated_out_ok(popt)) |
| 2125 | continue; |
| 2126 | |
| 2127 | namesarr[0] = popt->name + 2; |
| 2128 | cv = configvar_first(ld->configvars, namesarr); |
| 2129 | if (!cv && !popt->def) |
| 2130 | continue; |
| 2131 | |
| 2132 | ot = opt_find_long(namesarr[0], NULL); |
| 2133 | if (ot->type & OPT_MULTI) { |
| 2134 | json_array_start(stream, namesarr[0]); |
| 2135 | if (!cv) { |
| 2136 | json_add_plugin_val(stream, ot, NULL, |
| 2137 | popt->def); |
| 2138 | } else { |
| 2139 | while (cv) { |
| 2140 | json_add_plugin_val(stream, |
| 2141 | ot, NULL, |
| 2142 | cv->optarg); |
| 2143 | cv = configvar_next(ld->configvars, |
| 2144 | cv, namesarr); |
| 2145 | } |
| 2146 | } |
| 2147 | json_array_end(stream); |
| 2148 | } else { |
| 2149 | if (!cv) { |
| 2150 | json_add_plugin_val(stream, ot, |
| 2151 | namesarr[0], |
| 2152 | popt->def); |
| 2153 | } else if (cv->optarg) { |
| 2154 | json_add_plugin_val(stream, |
| 2155 | ot, |
| 2156 | namesarr[0], |
| 2157 | cv->optarg); |
| 2158 | } else { |
| 2159 | /* We specify non-arg options as 'true' */ |
| 2160 | json_add_bool(stream, namesarr[0], true); |
| 2161 | } |
| 2162 | } |
| 2163 | } |
| 2164 | json_object_end(stream); |
| 2165 | } |
| 2166 |
no test coverage detected