handler.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * netifd - network interface daemon
  3. * Copyright (C) 2012-2013 Felix Fietkau <nbd@openwrt.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #ifndef __NETIFD_HANDLER_H
  15. #define __NETIFD_HANDLER_H
  16. #include <libubox/blobmsg_json.h>
  17. #include <json-c/json.h>
  18. #include "config.h"
  19. typedef void (*script_dump_cb)(const char *script, const char *name, json_object *obj);
  20. static inline json_object *
  21. json_check_type(json_object *obj, json_type type)
  22. {
  23. if (!obj)
  24. return NULL;
  25. if (json_object_get_type(obj) != type)
  26. return NULL;
  27. return obj;
  28. }
  29. static inline json_object *
  30. json_get_field(json_object *obj, const char *name, json_type type)
  31. {
  32. return json_object_object_get_ex(obj, name, &obj) ?
  33. json_check_type(obj, type) : NULL;
  34. }
  35. int netifd_open_subdir(const char *name);
  36. void netifd_init_script_handlers(int dir_fd, script_dump_cb cb);
  37. char *netifd_handler_parse_config(struct uci_blob_param_list *config, json_object *obj);
  38. #endif