respondd.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. Copyright (c) 2016, Matthias Schiffer <mschiffer@universe-factory.net>
  3. Copyright (c) 2016, Karsten Böddeker <freifunk@kb-light.de>
  4. All rights reserved.
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions are met:
  7. 1. Redistributions of source code must retain the above copyright notice,
  8. this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright notice,
  10. this list of conditions and the following disclaimer in the documentation
  11. and/or other materials provided with the distribution.
  12. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  13. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  14. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  15. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  16. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  17. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  18. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  19. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  20. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  21. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. */
  23. #include <respondd.h>
  24. #include <json-c/json.h>
  25. #include <uci.h>
  26. #include <string.h>
  27. static struct json_object * get_autoupdater_wifi_fallback(void) {
  28. struct uci_context *ctx = uci_alloc_context();
  29. ctx->flags &= ~UCI_FLAG_STRICT;
  30. struct uci_package *p;
  31. if (uci_load(ctx, "autoupdater-wifi-fallback", &p))
  32. goto error;
  33. struct uci_section *s = uci_lookup_section(ctx, p, "settings");
  34. if (!s)
  35. goto error;
  36. struct json_object *ret = json_object_new_object();
  37. const char *enabled = uci_lookup_option_string(ctx, s, "enabled");
  38. json_object_object_add(ret, "wifi-fallback", json_object_new_boolean(enabled && !strcmp(enabled, "1")));
  39. uci_free_context(ctx);
  40. return ret;
  41. error:
  42. uci_free_context(ctx);
  43. return NULL;
  44. }
  45. static struct json_object * respondd_provider_nodeinfo(void) {
  46. struct json_object *ret = json_object_new_object();
  47. struct json_object *software = json_object_new_object();
  48. json_object_object_add(software, "autoupdater", get_autoupdater_wifi_fallback());
  49. json_object_object_add(ret, "software", software);
  50. return ret;
  51. }
  52. const struct respondd_provider_info respondd_providers[] = {
  53. {"nodeinfo", respondd_provider_nodeinfo},
  54. {}
  55. };