kplugin_parse.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <stdint.h>
  4. #include <string.h>
  5. #include <assert.h>
  6. #include <dlfcn.h>
  7. #include <faux/str.h>
  8. #include <faux/list.h>
  9. #include <faux/conv.h>
  10. #include <faux/error.h>
  11. #include <klish/khelper.h>
  12. #include <klish/iplugin.h>
  13. #include <klish/kplugin.h>
  14. #include <klish/ksym.h>
  15. #define TAG "PLUGIN"
  16. bool_t kplugin_parse(kplugin_t *plugin, const iplugin_t *info, faux_error_t *error)
  17. {
  18. bool_t retcode = BOOL_TRUE;
  19. // ID
  20. if (!faux_str_is_empty(info->id)) {
  21. if (!kplugin_set_id(plugin, info->id)) {
  22. faux_error_add(error, TAG": Illegal 'id' attribute");
  23. retcode = BOOL_FALSE;
  24. }
  25. }
  26. // File
  27. if (!faux_str_is_empty(info->file)) {
  28. if (!kplugin_set_file(plugin, info->file)) {
  29. faux_error_add(error, TAG": Illegal 'file' attribute");
  30. retcode = BOOL_FALSE;
  31. }
  32. }
  33. // Global
  34. if (!faux_str_is_empty(info->global)) {
  35. bool_t b = BOOL_FALSE;
  36. if (!faux_conv_str2bool(info->global, &b) ||
  37. !kplugin_set_global(plugin, b)) {
  38. faux_error_add(error, TAG": Illegal 'global' attribute");
  39. retcode = BOOL_FALSE;
  40. }
  41. }
  42. // Conf
  43. if (!faux_str_is_empty(info->conf)) {
  44. if (!kplugin_set_conf(plugin, info->conf)) {
  45. faux_error_add(error, TAG": Illegal 'conf' attribute");
  46. retcode = BOOL_FALSE;
  47. }
  48. }
  49. return retcode;
  50. }
  51. kplugin_t *kplugin_from_iplugin(iplugin_t *iplugin, faux_error_t *error)
  52. {
  53. kplugin_t *kplugin = NULL;
  54. // Name [mandatory]
  55. if (faux_str_is_empty(iplugin->name))
  56. return NULL;
  57. kplugin = kplugin_new(iplugin->name);
  58. if (!kplugin) {
  59. faux_error_sprintf(error, TAG" \"%s\": Can't create object",
  60. iplugin->name);
  61. return NULL;
  62. }
  63. if (!kplugin_parse(kplugin, iplugin, error)) {
  64. kplugin_free(kplugin);
  65. return NULL;
  66. }
  67. return kplugin;
  68. }