| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #include "api_v1_calls.h" |
| 4 | |
| 5 | int api_v1_function(RRDHOST *host, struct web_client *w, char *url) { |
| 6 | if (!netdata_ready_load()) |
| 7 | return HTTP_RESP_SERVICE_UNAVAILABLE; |
| 8 | |
| 9 | int timeout = 0; |
| 10 | const char *function = NULL; |
| 11 | |
| 12 | while (url) { |
| 13 | char *value = strsep_skip_consecutive_separators(&url, "&"); |
| 14 | if (!value || !*value) |
| 15 | continue; |
| 16 | |
| 17 | char *name = strsep_skip_consecutive_separators(&value, "="); |
| 18 | if (!name || !*name) |
| 19 | continue; |
| 20 | |
| 21 | if (!strcmp(name, "function")) |
| 22 | function = value; |
| 23 | |
| 24 | else if (!strcmp(name, "timeout")) |
| 25 | timeout = (int) strtoul(value, NULL, 0); |
| 26 | } |
| 27 | |
| 28 | BUFFER *wb = w->response.data; |
| 29 | buffer_flush(wb); |
| 30 | wb->content_type = CT_APPLICATION_JSON; |
| 31 | buffer_no_cacheable(wb); |
| 32 | |
| 33 | char transaction[UUID_COMPACT_STR_LEN]; |
| 34 | uuid_unparse_lower_compact(w->transaction, transaction); |
| 35 | |
| 36 | CLEAN_BUFFER *source = buffer_create(100, NULL); |
| 37 | user_auth_to_source_buffer(&w->user_auth, source); |
| 38 | |
| 39 | return rrd_function_run(host, wb, timeout, w->user_auth.access, function, true, transaction, |
| 40 | NULL, NULL, |
| 41 | web_client_progress_functions_update, NULL, |
| 42 | web_client_interrupt_callback, w, w->payload, |
| 43 | buffer_tostring(source), false); |
| 44 | } |