Config vars can have multiple names ("--large-channels|--wumbo"), but first * is preferred. * wrap_object means we wrap json in an object of that name, otherwise outputs * raw fields. */
| 127 | * raw fields. |
| 128 | */ |
| 129 | static void json_add_config(struct lightningd *ld, |
| 130 | struct json_stream *response, |
| 131 | bool always_include, |
| 132 | bool wrap_object, |
| 133 | const struct opt_table *ot, |
| 134 | const char **names) |
| 135 | { |
| 136 | char buf[CONFIG_SHOW_BUFSIZE + sizeof("...")]; |
| 137 | const char *val; |
| 138 | struct configvar *cv; |
| 139 | |
| 140 | /* This tells us if they actually set the option */ |
| 141 | cv = configvar_first(ld->configvars, names); |
| 142 | |
| 143 | /* Ignore dev/hidden options (deprecated) unless they actually used it */ |
| 144 | if (!cv |
| 145 | && (ot->desc == opt_hidden || (ot->type & OPT_DEV)) |
| 146 | && !always_include) { |
| 147 | return; |
| 148 | } |
| 149 | |
| 150 | /* Ignore options which simply exit */ |
| 151 | if (ot->type & OPT_EXITS) |
| 152 | return; |
| 153 | |
| 154 | if (ot->type & OPT_NOARG) { |
| 155 | if (wrap_object) |
| 156 | json_object_start(response, names[0]); |
| 157 | json_add_bool(response, "set", cv != NULL); |
| 158 | json_add_source(response, "source", cv); |
| 159 | json_add_config_plugin(response, ld->plugins, "plugin", ot); |
| 160 | if (ot->type & OPT_DYNAMIC) |
| 161 | json_add_bool(response, "dynamic", true); |
| 162 | if (wrap_object) |
| 163 | json_object_end(response); |
| 164 | return; |
| 165 | } |
| 166 | |
| 167 | assert(ot->type & OPT_HASARG); |
| 168 | if (ot->type & OPT_MULTI) { |
| 169 | if (wrap_object) |
| 170 | json_object_start(response, names[0]); |
| 171 | json_array_start(response, configval_fieldname(ot)); |
| 172 | while (cv) { |
| 173 | val = get_opt_val(ot, buf, cv); |
| 174 | json_add_configval(response, NULL, ot, val); |
| 175 | cv = configvar_next(ld->configvars, cv, names); |
| 176 | } |
| 177 | json_array_end(response); |
| 178 | |
| 179 | /* Iterate again, for sources */ |
| 180 | json_array_start(response, "sources"); |
| 181 | for (cv = configvar_first(ld->configvars, names); |
| 182 | cv; |
| 183 | cv = configvar_next(ld->configvars, cv, names)) { |
| 184 | json_add_source(response, NULL, cv); |
| 185 | } |
| 186 | json_array_end(response); |
no test coverage detected