ytree.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. //#include <libyang/libyang.h>
  4. //#include <libyang/tree_schema.h>
  5. #include <sysrepo.h>
  6. #include <sysrepo/xpath.h>
  7. #include <faux/faux.h>
  8. #include <faux/argv.h>
  9. #include "pline.h"
  10. static int
  11. sr_ly_module_is_internal(const struct lys_module *ly_mod)
  12. {
  13. if (!ly_mod->revision) {
  14. return 0;
  15. }
  16. if (!strcmp(ly_mod->name, "ietf-yang-metadata") && !strcmp(ly_mod->revision, "2016-08-05")) {
  17. return 1;
  18. } else if (!strcmp(ly_mod->name, "yang") && !strcmp(ly_mod->revision, "2021-04-07")) {
  19. return 1;
  20. } else if (!strcmp(ly_mod->name, "ietf-inet-types") && !strcmp(ly_mod->revision, "2013-07-15")) {
  21. return 1;
  22. } else if (!strcmp(ly_mod->name, "ietf-yang-types") && !strcmp(ly_mod->revision, "2013-07-15")) {
  23. return 1;
  24. }
  25. return 0;
  26. }
  27. int
  28. sr_module_is_internal(const struct lys_module *ly_mod)
  29. {
  30. if (!ly_mod->revision) {
  31. return 0;
  32. }
  33. if (sr_ly_module_is_internal(ly_mod)) {
  34. return 1;
  35. }
  36. if (!strcmp(ly_mod->name, "ietf-datastores") && !strcmp(ly_mod->revision, "2018-02-14")) {
  37. return 1;
  38. } else if (!strcmp(ly_mod->name, "ietf-yang-schema-mount")) {
  39. return 1;
  40. } else if (!strcmp(ly_mod->name, "ietf-yang-library")) {
  41. return 1;
  42. } else if (!strcmp(ly_mod->name, "ietf-netconf")) {
  43. return 1;
  44. } else if (!strcmp(ly_mod->name, "ietf-netconf-with-defaults") && !strcmp(ly_mod->revision, "2011-06-01")) {
  45. return 1;
  46. } else if (!strcmp(ly_mod->name, "ietf-origin") && !strcmp(ly_mod->revision, "2018-02-14")) {
  47. return 1;
  48. } else if (!strcmp(ly_mod->name, "ietf-netconf-notifications") && !strcmp(ly_mod->revision, "2012-02-06")) {
  49. return 1;
  50. } else if (!strcmp(ly_mod->name, "sysrepo")) {
  51. return 1;
  52. } else if (!strcmp(ly_mod->name, "sysrepo-monitoring")) {
  53. return 1;
  54. } else if (!strcmp(ly_mod->name, "sysrepo-plugind")) {
  55. return 1;
  56. } else if (!strcmp(ly_mod->name, "ietf-netconf-acm")) {
  57. return 1;
  58. }
  59. return 0;
  60. }
  61. int main(int argc, char **argv)
  62. {
  63. int ret = -1;
  64. int err = SR_ERR_OK;
  65. sr_conn_ctx_t *conn = NULL;
  66. sr_session_ctx_t *sess = NULL;
  67. faux_argv_t *args = faux_argv_new();
  68. pline_t *pline = NULL;
  69. err = sr_connect(SR_CONN_DEFAULT, &conn);
  70. if (err) {
  71. printf("Error\n");
  72. goto out;
  73. }
  74. err = sr_session_start(conn, SR_DS_RUNNING, &sess);
  75. if (err) {
  76. printf("Error2\n");
  77. goto out;
  78. }
  79. faux_argv_parse(args, argv[1]);
  80. faux_argv_del_continuable(args);
  81. pline = pline_parse(sess, args, 0);
  82. faux_argv_free(args);
  83. // pline_debug(pline);
  84. pline_print_completions(pline, BOOL_TRUE);
  85. pline_free(pline);
  86. ret = 0;
  87. out:
  88. sr_disconnect(conn);
  89. return 0;
  90. }