dyncfg-inline.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "dyncfg.h"
  3. static DICTIONARY *dyncfg_nodes = NULL;
  4. static int dyncfg_inline_callback(struct rrd_function_execute *rfe, void *data __maybe_unused) {
  5. char tr[UUID_COMPACT_STR_LEN];
  6. uuid_unparse_lower_compact(*rfe->transaction, tr);
  7. bool cancelled = rfe->is_cancelled.cb ? rfe->is_cancelled.cb(rfe->is_cancelled.data) : false;
  8. int code;
  9. if(cancelled)
  10. code = HTTP_RESP_CLIENT_CLOSED_REQUEST;
  11. else
  12. code = dyncfg_node_find_and_call(dyncfg_nodes, tr, rfe->function, rfe->stop_monotonic_ut, &cancelled, rfe->payload, rfe->source, rfe->result.wb);
  13. if(code == HTTP_RESP_CLIENT_CLOSED_REQUEST || (rfe->is_cancelled.cb && rfe->is_cancelled.cb(rfe->is_cancelled.data))) {
  14. buffer_flush(rfe->result.wb);
  15. code = HTTP_RESP_CLIENT_CLOSED_REQUEST;
  16. }
  17. if(rfe->result.cb)
  18. rfe->result.cb(rfe->result.wb, code, rfe->result.data);
  19. return code;
  20. }
  21. bool dyncfg_add(RRDHOST *host, const char *id, const char *path, DYNCFG_STATUS status, DYNCFG_TYPE type, DYNCFG_SOURCE_TYPE source_type, const char *source, DYNCFG_CMDS cmds, dyncfg_cb_t cb, void *data) {
  22. if(dyncfg_add_low_level(host, id, path, status, type, source_type, source, cmds,
  23. 0, 0, true,
  24. dyncfg_inline_callback, NULL)) {
  25. struct dyncfg_node tmp = {
  26. .cmds = cmds,
  27. .type = type,
  28. .cb = cb,
  29. .data = data,
  30. };
  31. dictionary_set(dyncfg_nodes, id, &tmp, sizeof(tmp));
  32. return true;
  33. }
  34. return false;
  35. }
  36. void dyncfg_del(RRDHOST *host, const char *id) {
  37. dictionary_del(dyncfg_nodes, id);
  38. dyncfg_del_low_level(host, id);
  39. }
  40. void dyncfg_status(RRDHOST *host, const char *id, DYNCFG_STATUS status) {
  41. dyncfg_status_low_level(host, id, status);
  42. }
  43. void dyncfg_init(bool load_saved) {
  44. dyncfg_nodes = dyncfg_nodes_dictionary_create();
  45. dyncfg_init_low_level(load_saved);
  46. }