private.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * private.h
  3. */
  4. #ifndef _pligin_sysrepo_private_h
  5. #define _plugin_sysrepo_private_h
  6. #include <sysrepo.h>
  7. #include <faux/faux.h>
  8. #include <faux/argv.h>
  9. #include <klish/kcontext_base.h>
  10. #include "pline.h"
  11. // Plugin's user-data structure
  12. typedef struct {
  13. faux_argv_t *path; // Current data hierarchy path ('edit' operation)
  14. pline_opts_t opts; // Settings
  15. sr_conn_ctx_t *sr_conn; // Sysrepo connection
  16. sr_session_ctx_t *sr_sess; // Sysrepo session
  17. sr_subscription_ctx_t *nacm_sub;
  18. } srp_udata_t;
  19. // Repository to edit with srp commands
  20. #define SRP_REPO_EDIT SR_DS_CANDIDATE
  21. C_DECL_BEGIN
  22. // Types
  23. int srp_PLINE_SET(kcontext_t *context);
  24. int srp_PLINE_DEL(kcontext_t *context);
  25. int srp_PLINE_EDIT(kcontext_t *context);
  26. int srp_PLINE_INSERT_FROM(kcontext_t *context);
  27. int srp_PLINE_INSERT_TO(kcontext_t *context);
  28. // Completion/Help/Prompt
  29. int srp_compl(kcontext_t *context);
  30. int srp_help(kcontext_t *context);
  31. int srp_compl_set(kcontext_t *context);
  32. int srp_help_set(kcontext_t *context);
  33. int srp_compl_del(kcontext_t *context);
  34. int srp_help_del(kcontext_t *context);
  35. int srp_compl_edit(kcontext_t *context);
  36. int srp_help_edit(kcontext_t *context);
  37. int srp_compl_insert(kcontext_t *context);
  38. int srp_help_insert(kcontext_t *context);
  39. int srp_compl_insert_to(kcontext_t *context);
  40. int srp_help_insert_to(kcontext_t *context);
  41. int srp_prompt_edit_path(kcontext_t *context);
  42. int srp_compl_xpath(kcontext_t *context);
  43. // Operations
  44. int srp_set(kcontext_t *context);
  45. int srp_del(kcontext_t *context);
  46. int srp_edit(kcontext_t *context);
  47. int srp_top(kcontext_t *context);
  48. int srp_up(kcontext_t *context);
  49. int srp_insert(kcontext_t *context);
  50. int srp_verify(kcontext_t *context);
  51. int srp_commit(kcontext_t *context);
  52. int srp_reset(kcontext_t *context);
  53. int srp_show(kcontext_t *context);
  54. int srp_show_cur_path(kcontext_t *context);
  55. int srp_diff(kcontext_t *context);
  56. int srp_deactivate(kcontext_t *context);
  57. // Plugin's user-data service functions
  58. pline_opts_t *srp_udata_opts(kcontext_t *context);
  59. faux_argv_t *srp_udata_path(kcontext_t *context);
  60. void srp_udata_set_path(kcontext_t *context, faux_argv_t *path);
  61. sr_session_ctx_t *srp_udata_sr_sess(kcontext_t *context);
  62. // Private
  63. enum diff_op {
  64. DIFF_OP_CREATE,
  65. DIFF_OP_DELETE,
  66. DIFF_OP_REPLACE,
  67. DIFF_OP_NONE,
  68. };
  69. bool_t show_xpath(sr_session_ctx_t *sess, const char *xpath, pline_opts_t *opts);
  70. void show_subtree(const struct lyd_node *nodes_list, size_t level,
  71. enum diff_op op, pline_opts_t *opts, bool_t parent_is_oneliner);
  72. // kly helper library
  73. typedef struct {
  74. const struct lysc_node *node;
  75. const char *value;
  76. const char *dflt;
  77. } klysc_key_t;
  78. int klysc_key_compare(const void *first, const void *second);
  79. int klysc_key_kcompare(const void *key, const void *list_item);
  80. bool_t klysc_node_ext(const struct lysc_node *node,
  81. const char *module, const char *name, const char **argument);
  82. bool_t klysc_node_ext_is_password(const struct lysc_node *node);
  83. const char *klysc_node_ext_completion(const struct lysc_node *node);
  84. const char *klysc_node_ext_default(const struct lysc_node *node);
  85. char *klyd_node_value(const struct lyd_node *node);
  86. const struct lysc_node *klysc_find_child(const struct lysc_node *node,
  87. const char *name);
  88. char *klysc_leafref_xpath(const struct lysc_node *node,
  89. const struct lysc_type *type, const char *node_path);
  90. const char *klysc_identityref_prefix(struct lysc_type_identityref *type,
  91. const char *name);
  92. size_t klyd_visible_child_num(const struct lyd_node *node);
  93. bool_t kly_str2ds(const char *str, size_t len, sr_datastore_t *ds);
  94. bool_t kly_parse_ext_xpath(const char *xpath, const char **raw_xpath,
  95. sr_datastore_t *ds);
  96. C_DECL_END
  97. #endif // _plugin_sysrepo_private_h