MCPcopy Create free account
hub / github.com/ElementsProject/lightning / json_add_opt_plugins_array

Function json_add_opt_plugins_array

lightningd/plugin.c:1944–1998  ·  view source on GitHub ↗

json_add_opt_plugins_array * * @brief add a named array of plugins to the given response, * depending on whether it is important or not important. * * @param response - the `json_stream` to write into. * @param name - the field name of the array. * @param plugins - the plugins object to query. * @param important - match the `important` setting of the * plugins to be added. */

Source from the content-addressed store, hash-verified

1942 * plugins to be added.
1943 */
1944static
1945void json_add_opt_plugins_array(struct json_stream *response,
1946 const char *name,
1947 const struct plugins *plugins,
1948 bool important)
1949{
1950 struct plugin *p;
1951 struct plugin_opt *opt;
1952 const char *opt_name;
1953
1954 /* we output 'plugins' and their options as an array of substructures */
1955 json_array_start(response, name);
1956 list_for_each(&plugins->plugins, p, list) {
1957 /* Skip if not matching. */
1958 if (p->important != important)
1959 continue;
1960
1961 json_object_start(response, NULL);
1962 json_add_string(response, "path", p->cmd);
1963
1964 /* FIXME: use executables basename until plugins can define their names */
1965 json_add_string(response, "name", p->shortname);
1966
1967 if (!list_empty(&p->plugin_opts)) {
1968 json_object_start(response, "options");
1969 list_for_each(&p->plugin_opts, opt, list) {
1970 if (!deprecated_apis && opt->deprecated)
1971 continue;
1972
1973 /* Trim the `--` that we added before */
1974 opt_name = opt->name + 2;
1975 if (opt->multi) {
1976 json_array_start(response, opt_name);
1977 for (size_t i = 0; i < tal_count(opt->values); i++)
1978 json_add_plugin_opt(response,
1979 NULL,
1980 opt->type,
1981 opt->values[i]);
1982 json_array_end(response);
1983 } else if (tal_count(opt->values)) {
1984 json_add_plugin_opt(response,
1985 opt_name,
1986 opt->type,
1987 opt->values[0]);
1988 } else {
1989 if (deprecated_apis)
1990 json_add_null(response, opt_name);
1991 }
1992 }
1993 json_object_end(response);
1994 }
1995 json_object_end(response);
1996 }
1997 json_array_end(response);
1998}
1999
2000void json_add_opt_plugins(struct json_stream *response,
2001 const struct plugins *plugins)

Callers 1

json_add_opt_pluginsFunction · 0.85

Calls 7

json_add_plugin_optFunction · 0.85
json_add_nullFunction · 0.85
json_array_startFunction · 0.50
json_object_startFunction · 0.50
json_add_stringFunction · 0.50
json_array_endFunction · 0.50
json_object_endFunction · 0.50

Tested by

no test coverage detected