pline.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  1. /** @file pline.c
  2. */
  3. #include <stdlib.h>
  4. #include <stdint.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <assert.h>
  8. #include <syslog.h>
  9. #include <limits.h>
  10. #include <faux/faux.h>
  11. #include <faux/str.h>
  12. #include <faux/list.h>
  13. #include <faux/argv.h>
  14. #include <sysrepo.h>
  15. #include <sysrepo/xpath.h>
  16. #include <sysrepo/values.h>
  17. #include <libyang/tree_edit.h>
  18. #include "private.h"
  19. #include "pline.h"
  20. static int sr_ly_module_is_internal(const struct lys_module *ly_mod)
  21. {
  22. if (!ly_mod->revision) {
  23. return 0;
  24. }
  25. if (!strcmp(ly_mod->name, "ietf-yang-metadata")
  26. && !strcmp(ly_mod->revision, "2016-08-05")) {
  27. return 1;
  28. } else if (!strcmp(ly_mod->name, "yang")
  29. && !strcmp(ly_mod->revision, "2021-04-07")) {
  30. return 1;
  31. } else if (!strcmp(ly_mod->name, "ietf-inet-types")
  32. && !strcmp(ly_mod->revision, "2013-07-15")) {
  33. return 1;
  34. } else if (!strcmp(ly_mod->name, "ietf-yang-types")
  35. && !strcmp(ly_mod->revision, "2013-07-15")) {
  36. return 1;
  37. }
  38. return 0;
  39. }
  40. static int sr_module_is_internal(const struct lys_module *ly_mod, bool_t enable_nacm)
  41. {
  42. if (!ly_mod->revision) {
  43. return 0;
  44. }
  45. if (sr_ly_module_is_internal(ly_mod)) {
  46. return 1;
  47. }
  48. if (!strcmp(ly_mod->name, "ietf-datastores")
  49. && !strcmp(ly_mod->revision, "2018-02-14")) {
  50. return 1;
  51. } else if (!strcmp(ly_mod->name, "ietf-yang-schema-mount")) {
  52. return 1;
  53. } else if (!strcmp(ly_mod->name, "ietf-yang-library")) {
  54. return 1;
  55. } else if (!strcmp(ly_mod->name, "ietf-netconf")) {
  56. return 1;
  57. } else if (!strcmp(ly_mod->name, "ietf-netconf-with-defaults")
  58. && !strcmp(ly_mod->revision, "2011-06-01")) {
  59. return 1;
  60. } else if (!strcmp(ly_mod->name, "ietf-origin")
  61. && !strcmp(ly_mod->revision, "2018-02-14")) {
  62. return 1;
  63. } else if (!strcmp(ly_mod->name, "ietf-netconf-notifications")
  64. && !strcmp(ly_mod->revision, "2012-02-06")) {
  65. return 1;
  66. } else if (!strcmp(ly_mod->name, "sysrepo")) {
  67. return 1;
  68. } else if (!strcmp(ly_mod->name, "sysrepo-monitoring")) {
  69. return 1;
  70. } else if (!strcmp(ly_mod->name, "sysrepo-plugind")) {
  71. return 1;
  72. } else if (!strcmp(ly_mod->name, "ietf-netconf-acm") && !enable_nacm) {
  73. return 1;
  74. }
  75. return 0;
  76. }
  77. static pexpr_t *pexpr_new(void)
  78. {
  79. pexpr_t *pexpr = NULL;
  80. pexpr = faux_zmalloc(sizeof(*pexpr));
  81. assert(pexpr);
  82. if (!pexpr)
  83. return NULL;
  84. // Initialize
  85. pexpr->xpath = NULL;
  86. pexpr->value = NULL;
  87. pexpr->active = BOOL_FALSE;
  88. pexpr->pat = PAT_NONE;
  89. pexpr->args_num = 0;
  90. pexpr->list_pos = 0;
  91. pexpr->last_keys = NULL;
  92. return pexpr;
  93. }
  94. static void pexpr_free(pexpr_t *pexpr)
  95. {
  96. if (!pexpr)
  97. return;
  98. faux_str_free(pexpr->xpath);
  99. faux_str_free(pexpr->value);
  100. faux_str_free(pexpr->last_keys);
  101. free(pexpr);
  102. }
  103. static pcompl_t *pcompl_new(void)
  104. {
  105. pcompl_t *pcompl = NULL;
  106. pcompl = faux_zmalloc(sizeof(*pcompl));
  107. assert(pcompl);
  108. if (!pcompl)
  109. return NULL;
  110. // Initialize
  111. pcompl->type = PCOMPL_NODE;
  112. pcompl->node = NULL;
  113. pcompl->xpath = NULL;
  114. pcompl->xpath_ds = SRP_REPO_EDIT;
  115. pcompl->pat = PAT_NONE;
  116. return pcompl;
  117. }
  118. static void pcompl_free(pcompl_t *pcompl)
  119. {
  120. if (!pcompl)
  121. return;
  122. faux_str_free(pcompl->xpath);
  123. free(pcompl);
  124. }
  125. pline_t *pline_new(sr_session_ctx_t *sess)
  126. {
  127. pline_t *pline = NULL;
  128. pline = faux_zmalloc(sizeof(*pline));
  129. assert(pline);
  130. if (!pline)
  131. return NULL;
  132. // Init
  133. pline->sess = sess;
  134. pline->invalid = BOOL_FALSE;
  135. pline->exprs = faux_list_new(FAUX_LIST_UNSORTED, FAUX_LIST_NONUNIQUE,
  136. NULL, NULL, (faux_list_free_fn)pexpr_free);
  137. pline->compls = faux_list_new(FAUX_LIST_UNSORTED, FAUX_LIST_NONUNIQUE,
  138. NULL, NULL, (faux_list_free_fn)pcompl_free);
  139. return pline;
  140. }
  141. void pline_free(pline_t *pline)
  142. {
  143. if (!pline)
  144. return;
  145. faux_list_free(pline->exprs);
  146. faux_list_free(pline->compls);
  147. faux_free(pline);
  148. }
  149. static pexpr_t *pline_add_expr(pline_t *pline, const char *xpath,
  150. size_t args_num, size_t list_pos)
  151. {
  152. pexpr_t *pexpr = NULL;
  153. assert(pline);
  154. pexpr = pexpr_new();
  155. if (xpath)
  156. pexpr->xpath = faux_str_dup(xpath);
  157. pexpr->args_num = args_num;
  158. pexpr->list_pos = list_pos;
  159. faux_list_add(pline->exprs, pexpr);
  160. return pexpr;
  161. }
  162. pexpr_t *pline_current_expr(pline_t *pline)
  163. {
  164. assert(pline);
  165. if (faux_list_len(pline->exprs) == 0)
  166. pline_add_expr(pline, NULL, 0, 0);
  167. return (pexpr_t *)faux_list_data(faux_list_tail(pline->exprs));
  168. }
  169. static void pline_add_compl(pline_t *pline,
  170. pcompl_type_e type, const struct lysc_node *node,
  171. const char *xpath, sr_datastore_t ds, pat_e pat)
  172. {
  173. pcompl_t *pcompl = NULL;
  174. assert(pline);
  175. pcompl = pcompl_new();
  176. pcompl->type = type;
  177. pcompl->node = node;
  178. pcompl->pat = pat;
  179. if (xpath) {
  180. pcompl->xpath = faux_str_dup(xpath);
  181. pcompl->xpath_ds = ds;
  182. }
  183. faux_list_add(pline->compls, pcompl);
  184. }
  185. static void pline_add_compl_subtree(pline_t *pline, const struct lys_module *module,
  186. const struct lysc_node *node)
  187. {
  188. const struct lysc_node *subtree = NULL;
  189. const struct lysc_node *iter = NULL;
  190. assert(pline);
  191. assert(module);
  192. if (node)
  193. subtree = lysc_node_child(node);
  194. else
  195. subtree = module->compiled->data;
  196. LY_LIST_FOR(subtree, iter) {
  197. pat_e pat = PAT_NONE;
  198. if (!(iter->nodetype & SRP_NODETYPE_CONF))
  199. continue;
  200. if (!(iter->flags & LYS_CONFIG_W))
  201. continue;
  202. if ((iter->nodetype & LYS_LEAF) && (iter->flags & LYS_KEY))
  203. continue;
  204. if (iter->nodetype & (LYS_CHOICE | LYS_CASE)) {
  205. pline_add_compl_subtree(pline, module, iter);
  206. continue;
  207. }
  208. switch(iter->nodetype) {
  209. case LYS_CONTAINER:
  210. pat = PAT_CONTAINER;
  211. break;
  212. case LYS_LEAF:
  213. pat = PAT_LEAF;
  214. break;
  215. case LYS_LEAFLIST:
  216. pat = PAT_LEAFLIST;
  217. break;
  218. case LYS_LIST:
  219. pat = PAT_LIST;
  220. break;
  221. default:
  222. continue;
  223. break;
  224. }
  225. pline_add_compl(pline, PCOMPL_NODE, iter, NULL, SRP_REPO_EDIT, pat);
  226. }
  227. }
  228. static const char *pat2str(pat_e pat)
  229. {
  230. const char *str = NULL;
  231. switch (pat) {
  232. case PAT_NONE:
  233. str = "NONE";
  234. break;
  235. case PAT_CONTAINER:
  236. str = "CONTAINER";
  237. break;
  238. case PAT_LIST:
  239. str = "LIST";
  240. break;
  241. case PAT_LIST_KEY:
  242. str = "LIST_KEY";
  243. break;
  244. case PAT_LIST_KEY_INCOMPLETED:
  245. str = "LIST_KEY_INCOMPLETED";
  246. break;
  247. case PAT_LEAF:
  248. str = "LEAF";
  249. break;
  250. case PAT_LEAF_VALUE:
  251. str = "LEAF_VALUE";
  252. break;
  253. case PAT_LEAF_EMPTY:
  254. str = "LEAF_EMPTY";
  255. break;
  256. case PAT_LEAFLIST:
  257. str = "LEAFLIST";
  258. break;
  259. case PAT_LEAFLIST_VALUE:
  260. str = "LEAFLIST_VALUE";
  261. break;
  262. default:
  263. str = "UNKNOWN";
  264. break;
  265. }
  266. return str;
  267. }
  268. void pline_debug(pline_t *pline)
  269. {
  270. faux_list_node_t *iter = NULL;
  271. pexpr_t *pexpr = NULL;
  272. pcompl_t *pcompl = NULL;
  273. syslog(LOG_ERR, "====== Pline:");
  274. syslog(LOG_ERR, "invalid = %s", pline->invalid ? "true" : "false");
  275. syslog(LOG_ERR, "=== Expressions:");
  276. iter = faux_list_head(pline->exprs);
  277. while ((pexpr = (pexpr_t *)faux_list_each(&iter))) {
  278. syslog(LOG_ERR, "pexpr.xpath = %s", pexpr->xpath ? pexpr->xpath : "NULL");
  279. syslog(LOG_ERR, "pexpr.value = %s", pexpr->value ? pexpr->value : "NULL");
  280. syslog(LOG_ERR, "pexpr.active = %s", pexpr->active ? "true" : "false");
  281. syslog(LOG_ERR, "pexpr.pat = %s", pat2str(pexpr->pat));
  282. syslog(LOG_ERR, "pexpr.args_num = %lu", pexpr->args_num);
  283. syslog(LOG_ERR, "pexpr.list_pos = %lu", pexpr->list_pos);
  284. syslog(LOG_ERR, "pexpr.last_keys = %s", pexpr->last_keys ? pexpr->last_keys : "NULL");
  285. syslog(LOG_ERR, "---");
  286. }
  287. syslog(LOG_ERR, "=== Completions:");
  288. iter = faux_list_head(pline->compls);
  289. while ((pcompl = (pcompl_t *)faux_list_each(&iter))) {
  290. syslog(LOG_ERR, "pcompl.type = %s", (pcompl->type == PCOMPL_NODE) ?
  291. "PCOMPL_NODE" : "PCOMPL_TYPE");
  292. syslog(LOG_ERR, "pcompl.node = %s", pcompl->node ? pcompl->node->name : "NULL");
  293. syslog(LOG_ERR, "pcompl.xpath = %s", pcompl->xpath ? pcompl->xpath : "NULL");
  294. syslog(LOG_ERR, "pcompl.pat = %s", pat2str(pcompl->pat));
  295. syslog(LOG_ERR, "---");
  296. }
  297. }
  298. static bool_t pexpr_xpath_add_node(pexpr_t *pexpr,
  299. const char *prefix, const char *name)
  300. {
  301. char *tmp = NULL;
  302. assert(pexpr);
  303. assert(prefix);
  304. assert(name);
  305. tmp = faux_str_sprintf("/%s:%s", prefix, name);
  306. faux_str_cat(&pexpr->xpath, tmp);
  307. faux_str_free(tmp);
  308. pexpr->args_num++;
  309. // Activate current expression. Because it really has
  310. // new component
  311. pexpr->active = BOOL_TRUE;
  312. return BOOL_TRUE;
  313. }
  314. static bool_t pexpr_xpath_add_list_key(pexpr_t *pexpr,
  315. const char *key, const char *value, bool_t inc_args_num)
  316. {
  317. char *tmp = NULL;
  318. char *escaped = NULL;
  319. assert(pexpr);
  320. assert(key);
  321. assert(value);
  322. escaped = faux_str_c_esc(value);
  323. tmp = faux_str_sprintf("[%s=\"%s\"]", key, escaped);
  324. faux_str_free(escaped);
  325. faux_str_cat(&pexpr->xpath, tmp);
  326. faux_str_cat(&pexpr->last_keys, tmp);
  327. faux_str_free(tmp);
  328. if (inc_args_num)
  329. pexpr->args_num++;
  330. return BOOL_TRUE;
  331. }
  332. static bool_t pexpr_xpath_add_leaflist_key(pexpr_t *pexpr,
  333. const char *prefix, const char *value)
  334. {
  335. char *tmp = NULL;
  336. assert(pexpr);
  337. assert(value);
  338. tmp = faux_str_sprintf("[.='%s%s%s']",
  339. prefix ? prefix : "", prefix ? ":" : "", value);
  340. faux_str_cat(&pexpr->xpath, tmp);
  341. faux_str_cat(&pexpr->last_keys, value);
  342. faux_str_free(tmp);
  343. pexpr->args_num++;
  344. return BOOL_TRUE;
  345. }
  346. static void pline_add_compl_leafref(pline_t *pline, const struct lysc_node *node,
  347. const struct lysc_type *type, const char *xpath, pat_e pat)
  348. {
  349. if (!type)
  350. return;
  351. if (!node)
  352. return;
  353. if (!(node->nodetype & (LYS_LEAF | LYS_LEAFLIST)))
  354. return;
  355. switch (type->basetype) {
  356. case LY_TYPE_UNION: {
  357. struct lysc_type_union *t =
  358. (struct lysc_type_union *)type;
  359. LY_ARRAY_COUNT_TYPE u = 0;
  360. LY_ARRAY_FOR(t->types, u) {
  361. pline_add_compl_leafref(pline, node, t->types[u], xpath, pat);
  362. }
  363. break;
  364. }
  365. case LY_TYPE_LEAFREF: {
  366. char *compl_xpath = klysc_leafref_xpath(node, type, xpath);
  367. pline_add_compl(pline, PCOMPL_TYPE, NULL, compl_xpath, SRP_REPO_EDIT, pat);
  368. faux_str_free(compl_xpath);
  369. break;
  370. }
  371. default:
  372. break;
  373. }
  374. }
  375. static bool_t parse_ext_xpath(const char *xpath, const char **raw_xpath,
  376. sr_datastore_t *ds)
  377. {
  378. char *space = NULL;
  379. size_t len = 0;
  380. space = strchr(xpath, ' ');
  381. if (space) {
  382. *raw_xpath = space + 1;
  383. len = space - xpath;
  384. if (faux_str_cmpn(xpath, "candidate", len) == 0)
  385. *ds = SR_DS_CANDIDATE;
  386. else if (faux_str_cmpn(xpath, "running", len) == 0)
  387. *ds = SR_DS_RUNNING;
  388. else if (faux_str_cmpn(xpath, "operational", len) == 0)
  389. *ds = SR_DS_OPERATIONAL;
  390. else if (faux_str_cmpn(xpath, "startup", len) == 0)
  391. *ds = SR_DS_STARTUP;
  392. else if (faux_str_cmpn(xpath, "factory-default", len) == 0)
  393. *ds = SR_DS_FACTORY_DEFAULT;
  394. else
  395. return BOOL_FALSE;
  396. } else {
  397. *ds = SRP_REPO_EDIT;
  398. *raw_xpath = xpath;
  399. }
  400. return BOOL_TRUE;
  401. }
  402. static void pline_add_compl_leaf(pline_t *pline, const struct lysc_node *node,
  403. const char *xpath, pat_e pat)
  404. {
  405. struct lysc_type *type = NULL;
  406. const char *ext_xpath = NULL;
  407. assert(pline);
  408. if (!pline)
  409. return;
  410. assert(node);
  411. if (!node)
  412. return;
  413. switch (node->nodetype) {
  414. case LYS_LEAF:
  415. type = ((struct lysc_node_leaf *)node)->type;
  416. break;
  417. case LYS_LEAFLIST:
  418. type = ((struct lysc_node_leaflist *)node)->type;
  419. break;
  420. default:
  421. return;
  422. }
  423. ext_xpath = klysc_node_ext_completion(node);
  424. if (ext_xpath) {
  425. const char *raw_xpath = NULL;
  426. sr_datastore_t ds = SRP_REPO_EDIT;
  427. if (parse_ext_xpath(ext_xpath, &raw_xpath, &ds))
  428. pline_add_compl(pline, PCOMPL_TYPE, NULL, raw_xpath, ds, pat);
  429. }
  430. pline_add_compl(pline, PCOMPL_TYPE, node, xpath, SRP_REPO_EDIT, pat);
  431. pline_add_compl_leafref(pline, node, type, xpath, pat);
  432. }
  433. static bool_t pline_parse_module(const struct lys_module *module, faux_argv_t *argv,
  434. pline_t *pline, pline_opts_t *opts)
  435. {
  436. faux_argv_node_t *arg = faux_argv_iter(argv);
  437. const struct lysc_node *node = NULL;
  438. char *rollback_xpath = NULL;
  439. size_t rollback_args_num = 0;
  440. size_t rollback_list_pos = 0;
  441. // Rollback is a mechanism to roll to previous node while
  442. // oneliners parsing
  443. bool_t rollback = BOOL_FALSE;
  444. pexpr_t *first_pexpr = NULL;
  445. // It's necessary because upper function can use the same pline object
  446. // for another modules before. It uses the same object to collect
  447. // possible completions. But pline is really invalid only when all
  448. // modules don't recognize argument.
  449. pline->invalid = BOOL_FALSE;
  450. do {
  451. pexpr_t *pexpr = pline_current_expr(pline);
  452. const char *str = (const char *)faux_argv_current(arg);
  453. bool_t is_rollback = rollback;
  454. bool_t next_arg = BOOL_TRUE;
  455. rollback = BOOL_FALSE;
  456. if (node && !is_rollback) {
  457. // Save rollback Xpath (for oneliners) before leaf node
  458. // Only leaf and leaf-list node allows to "rollback"
  459. // the path and add additional statements
  460. if (node->nodetype & (LYS_LEAF | LYS_LEAFLIST)) {
  461. faux_str_free(rollback_xpath);
  462. rollback_xpath = faux_str_dup(pexpr->xpath);
  463. rollback_args_num = pexpr->args_num;
  464. rollback_list_pos = pexpr->list_pos;
  465. }
  466. // Add current node to Xpath
  467. pexpr_xpath_add_node(pexpr,
  468. node->module->name, node->name);
  469. }
  470. // Root of the module
  471. if (!node) {
  472. // Completion
  473. if (!str) {
  474. pline_add_compl_subtree(pline, module, node);
  475. break;
  476. }
  477. // Next element
  478. node = klysc_find_child(module->compiled->data, str);
  479. if (!node)
  480. break;
  481. // Container
  482. } else if (node->nodetype & LYS_CONTAINER) {
  483. pexpr->pat = PAT_CONTAINER;
  484. // Completion
  485. if (!str) {
  486. pline_add_compl_subtree(pline, module, node);
  487. break;
  488. }
  489. // Next element
  490. node = klysc_find_child(lysc_node_child(node), str);
  491. // List
  492. } else if (node->nodetype & LYS_LIST) {
  493. const struct lysc_node *iter = NULL;
  494. pexpr->pat = PAT_LIST;
  495. pexpr->list_pos = pexpr->args_num;
  496. faux_str_free(pexpr->last_keys);
  497. pexpr->last_keys = NULL;
  498. // Next element
  499. if (!is_rollback) {
  500. bool_t break_upper_loop = BOOL_FALSE;
  501. // Keys without statement. Positional parameters.
  502. if (!opts->keys_w_stmt) {
  503. LY_LIST_FOR(lysc_node_child(node), iter) {
  504. struct lysc_node_leaf *leaf =
  505. (struct lysc_node_leaf *)iter;
  506. if (!(iter->nodetype & LYS_LEAF))
  507. continue;
  508. if (!(iter->flags & LYS_KEY))
  509. continue;
  510. assert (leaf->type->basetype != LY_TYPE_EMPTY);
  511. // Completion
  512. if (!str) {
  513. char *tmp = faux_str_sprintf("%s/%s",
  514. pexpr->xpath, leaf->name);
  515. pline_add_compl_leaf(pline, iter,
  516. tmp, PAT_LIST_KEY);
  517. faux_str_free(tmp);
  518. break_upper_loop = BOOL_TRUE;
  519. break;
  520. }
  521. pexpr_xpath_add_list_key(pexpr,
  522. leaf->name, str, BOOL_TRUE);
  523. faux_argv_each(&arg);
  524. str = (const char *)faux_argv_current(arg);
  525. pexpr->pat = PAT_LIST_KEY_INCOMPLETED;
  526. }
  527. // Keys with statements. Arbitrary order of keys.
  528. } else {
  529. faux_list_t *keys = NULL;
  530. unsigned int specified_keys_num = 0;
  531. klysc_key_t *cur_key = NULL;
  532. bool_t first_key = BOOL_TRUE;
  533. bool_t first_key_is_optional = BOOL_FALSE;
  534. faux_list_node_t *key_iter = NULL;
  535. // List keys
  536. keys = faux_list_new(FAUX_LIST_UNSORTED,
  537. FAUX_LIST_UNIQUE,
  538. klysc_key_compare,
  539. klysc_key_kcompare,
  540. (faux_list_free_fn)faux_free);
  541. LY_LIST_FOR(lysc_node_child(node), iter) {
  542. struct lysc_node_leaf *leaf =
  543. (struct lysc_node_leaf *)iter;
  544. klysc_key_t *key = NULL;
  545. if (!(iter->nodetype & LYS_LEAF))
  546. continue;
  547. if (!(iter->flags & LYS_KEY))
  548. continue;
  549. assert (leaf->type->basetype != LY_TYPE_EMPTY);
  550. key = faux_zmalloc(sizeof(*key));
  551. assert(key);
  552. key->node = iter;
  553. if (opts->default_keys &&
  554. (key->dflt = klysc_node_ext_default(iter))) {
  555. if (first_key)
  556. first_key_is_optional = BOOL_TRUE;
  557. }
  558. faux_list_add(keys, key);
  559. first_key = BOOL_FALSE;
  560. }
  561. while (specified_keys_num < faux_list_len(keys)) {
  562. // First key without statement. Must be mandatory.
  563. if ((0 == specified_keys_num) &&
  564. !opts->first_key_w_stmt &&
  565. !first_key_is_optional) {
  566. cur_key = (klysc_key_t *)faux_list_data(faux_list_head(keys));
  567. } else {
  568. if (!str)
  569. break;
  570. cur_key = faux_list_kfind(keys, str);
  571. if (!cur_key || cur_key->value)
  572. break;
  573. pexpr->args_num++;
  574. faux_argv_each(&arg);
  575. str = (const char *)faux_argv_current(arg);
  576. }
  577. pexpr->pat = PAT_LIST_KEY_INCOMPLETED;
  578. // Completion
  579. if (!str) {
  580. char *tmp = faux_str_sprintf("%s/%s",
  581. pexpr->xpath,
  582. cur_key->node->name);
  583. pline_add_compl_leaf(pline, cur_key->node,
  584. tmp, PAT_LIST_KEY);
  585. faux_str_free(tmp);
  586. break_upper_loop = BOOL_TRUE;
  587. break;
  588. }
  589. pexpr_xpath_add_list_key(pexpr,
  590. cur_key->node->name, str, BOOL_TRUE);
  591. cur_key->value = str;
  592. specified_keys_num++;
  593. faux_argv_each(&arg);
  594. str = (const char *)faux_argv_current(arg);
  595. pexpr->pat = PAT_LIST_KEY_INCOMPLETED;
  596. }
  597. if (break_upper_loop) {
  598. faux_list_free(keys);
  599. break;
  600. }
  601. key_iter = faux_list_head(keys);
  602. while((cur_key = (klysc_key_t *)faux_list_each(&key_iter))) {
  603. if (cur_key->value)
  604. continue;
  605. // Completion
  606. if (!str)
  607. pline_add_compl(pline, PCOMPL_NODE,
  608. cur_key->node, NULL,
  609. SRP_REPO_EDIT, PAT_LIST_KEY);
  610. if (opts->default_keys && cur_key->dflt) {
  611. pexpr_xpath_add_list_key(pexpr,
  612. cur_key->node->name,
  613. cur_key->dflt, BOOL_FALSE);
  614. pexpr->pat = PAT_LIST_KEY_INCOMPLETED;
  615. } else { // Mandatory key is not specified
  616. break_upper_loop = BOOL_TRUE;
  617. }
  618. }
  619. faux_list_free(keys);
  620. }
  621. if (break_upper_loop)
  622. break;
  623. }
  624. pexpr->pat = PAT_LIST_KEY;
  625. // Completion
  626. if (!str) {
  627. pline_add_compl_subtree(pline, module, node);
  628. break;
  629. }
  630. // Next element
  631. node = klysc_find_child(lysc_node_child(node), str);
  632. // Leaf
  633. } else if (node->nodetype & LYS_LEAF) {
  634. struct lysc_node_leaf *leaf =
  635. (struct lysc_node_leaf *)node;
  636. // Next element
  637. if (LY_TYPE_EMPTY == leaf->type->basetype) {
  638. pexpr->pat = PAT_LEAF_EMPTY;
  639. // Completion
  640. if (!str) {
  641. pline_add_compl_subtree(pline,
  642. module, node->parent);
  643. break;
  644. }
  645. // Don't get next argument when argument is not
  646. // really consumed
  647. next_arg = BOOL_FALSE;
  648. } else {
  649. pexpr->pat = PAT_LEAF;
  650. // Completion
  651. if (!str) {
  652. pline_add_compl_leaf(pline, node,
  653. pexpr->xpath, PAT_LEAF_VALUE);
  654. break;
  655. }
  656. pexpr->pat = PAT_LEAF_VALUE;
  657. // Idenity must have prefix
  658. if (LY_TYPE_IDENT == leaf->type->basetype) {
  659. const char *prefix = NULL;
  660. prefix = klysc_identityref_prefix(
  661. (struct lysc_type_identityref *)
  662. leaf->type, str);
  663. if (prefix)
  664. pexpr->value = faux_str_sprintf(
  665. "%s:", prefix);
  666. }
  667. faux_str_cat(&pexpr->value, str);
  668. }
  669. // Expression was completed
  670. // So rollback (for oneliners)
  671. node = node->parent;
  672. pline_add_expr(pline, rollback_xpath,
  673. rollback_args_num, rollback_list_pos);
  674. rollback = BOOL_TRUE;
  675. // Leaf-list
  676. } else if (node->nodetype & LYS_LEAFLIST) {
  677. const char *prefix = NULL;
  678. struct lysc_node_leaflist *leaflist =
  679. (struct lysc_node_leaflist *)node;
  680. pexpr->pat = PAT_LEAFLIST;
  681. pexpr->list_pos = pexpr->args_num;
  682. faux_str_free(pexpr->last_keys);
  683. pexpr->last_keys = NULL;
  684. // Completion
  685. if (!str) {
  686. pline_add_compl_leaf(pline, node,
  687. pexpr->xpath, PAT_LEAFLIST_VALUE);
  688. break;
  689. }
  690. pexpr->pat = PAT_LEAFLIST_VALUE;
  691. // Idenity must have prefix
  692. if (LY_TYPE_IDENT == leaflist->type->basetype) {
  693. prefix = klysc_identityref_prefix(
  694. (struct lysc_type_identityref *)
  695. leaflist->type, str);
  696. }
  697. pexpr_xpath_add_leaflist_key(pexpr, prefix, str);
  698. // Expression was completed
  699. // So rollback (for oneliners)
  700. node = node->parent;
  701. pline_add_expr(pline, rollback_xpath,
  702. rollback_args_num, rollback_list_pos);
  703. rollback = BOOL_TRUE;
  704. // LYS_CHOICE and LYS_CASE can appear while rollback only
  705. } else if (node->nodetype & (LYS_CHOICE | LYS_CASE)) {
  706. // Don't set pexpr->pat because CHOICE and CASE can't
  707. // appear within data tree (schema only)
  708. // Completion
  709. if (!str) {
  710. pline_add_compl_subtree(pline, module, node);
  711. break;
  712. }
  713. // Next element
  714. node = klysc_find_child(lysc_node_child(node), str);
  715. } else {
  716. break;
  717. }
  718. // Current argument was not consumed.
  719. // Break before getting next arg.
  720. if (!node && !rollback)
  721. break;
  722. if (next_arg)
  723. faux_argv_each(&arg);
  724. } while (BOOL_TRUE);
  725. // There is not-consumed argument so whole pline is invalid
  726. if (faux_argv_current(arg))
  727. pline->invalid = BOOL_TRUE;
  728. faux_str_free(rollback_xpath);
  729. first_pexpr = (pexpr_t *)faux_list_data(faux_list_head(pline->exprs));
  730. if (!first_pexpr || !first_pexpr->xpath)
  731. return BOOL_FALSE; // Not found
  732. return BOOL_TRUE;
  733. }
  734. pline_t *pline_parse(sr_session_ctx_t *sess, faux_argv_t *argv, pline_opts_t *opts)
  735. {
  736. const struct ly_ctx *ctx = NULL;
  737. struct lys_module *module = NULL;
  738. pline_t *pline = NULL;
  739. uint32_t i = 0;
  740. faux_list_node_t *last_expr_node = NULL;
  741. assert(sess);
  742. if (!sess)
  743. return NULL;
  744. pline = pline_new(sess);
  745. if (!pline)
  746. return NULL;
  747. ctx = sr_session_acquire_context(pline->sess);
  748. if (!ctx)
  749. return NULL;
  750. // Iterate all modules
  751. i = 0;
  752. while ((module = ly_ctx_get_module_iter(ctx, &i))) {
  753. if (sr_module_is_internal(module, opts->enable_nacm))
  754. continue;
  755. if (!module->compiled)
  756. continue;
  757. if (!module->implemented)
  758. continue;
  759. if (!module->compiled->data)
  760. continue;
  761. if (pline_parse_module(module, argv, pline, opts))
  762. break; // Found
  763. }
  764. sr_session_release_context(pline->sess);
  765. // Last parsed expression can be inactive so remove it from list
  766. last_expr_node = faux_list_tail(pline->exprs);
  767. if (last_expr_node) {
  768. pexpr_t *expr = (pexpr_t *)faux_list_data(last_expr_node);
  769. if (!expr->active)
  770. faux_list_del(pline->exprs, last_expr_node);
  771. }
  772. return pline;
  773. }
  774. static void identityref_compl(struct lysc_ident *ident)
  775. {
  776. LY_ARRAY_COUNT_TYPE u = 0;
  777. if (!ident)
  778. return;
  779. if (!ident->derived) {
  780. printf("%s\n", ident->name);
  781. return;
  782. }
  783. LY_ARRAY_FOR(ident->derived, u) {
  784. identityref_compl(ident->derived[u]);
  785. }
  786. }
  787. static void identityref_help(struct lysc_ident *ident)
  788. {
  789. LY_ARRAY_COUNT_TYPE u = 0;
  790. if (!ident)
  791. return;
  792. if (!ident->derived) {
  793. if (ident->dsc) {
  794. char *dsc = faux_str_getline(ident->dsc, NULL);
  795. printf("%s\n%s\n", ident->name, dsc);
  796. faux_str_free(dsc);
  797. } else {
  798. printf("%s\n%s\n", ident->name, ident->name);
  799. }
  800. return;
  801. }
  802. LY_ARRAY_FOR(ident->derived, u) {
  803. identityref_help(ident->derived[u]);
  804. }
  805. }
  806. static void pline_print_type_completions(const struct lysc_type *type)
  807. {
  808. assert(type);
  809. switch (type->basetype) {
  810. case LY_TYPE_BOOL: {
  811. printf("true\nfalse\n");
  812. break;
  813. }
  814. case LY_TYPE_ENUM: {
  815. const struct lysc_type_enum *t =
  816. (const struct lysc_type_enum *)type;
  817. LY_ARRAY_COUNT_TYPE u = 0;
  818. LY_ARRAY_FOR(t->enums, u) {
  819. printf("%s\n",t->enums[u].name);
  820. }
  821. break;
  822. }
  823. case LY_TYPE_IDENT: {
  824. struct lysc_type_identityref *t =
  825. (struct lysc_type_identityref *)type;
  826. LY_ARRAY_COUNT_TYPE u = 0;
  827. LY_ARRAY_FOR(t->bases, u) {
  828. identityref_compl(t->bases[u]);
  829. }
  830. break;
  831. }
  832. case LY_TYPE_UNION: {
  833. struct lysc_type_union *t =
  834. (struct lysc_type_union *)type;
  835. LY_ARRAY_COUNT_TYPE u = 0;
  836. LY_ARRAY_FOR(t->types, u) {
  837. pline_print_type_completions(t->types[u]);
  838. }
  839. break;
  840. }
  841. case LY_TYPE_LEAFREF: {
  842. struct lysc_type_leafref *t =
  843. (struct lysc_type_leafref *)type;
  844. pline_print_type_completions(t->realtype);
  845. break;
  846. }
  847. default:
  848. break;
  849. }
  850. }
  851. static void uint_range(const struct lysc_type *type, uint64_t def_min, uint64_t def_max)
  852. {
  853. struct lysc_range *range = NULL;
  854. LY_ARRAY_COUNT_TYPE u = 0;
  855. char *r = NULL;
  856. assert(type);
  857. range = ((struct lysc_type_num *)type)->range;
  858. // Show defaults
  859. if (!range) {
  860. printf("[%" PRIu64 "..%" PRIu64 "]\n", def_min, def_max);
  861. return;
  862. }
  863. // Range
  864. faux_str_cat(&r, "[");
  865. LY_ARRAY_FOR(range->parts, u) {
  866. char *t = NULL;
  867. if (u != 0)
  868. faux_str_cat(&r, "|");
  869. t = faux_str_sprintf("%" PRIu64 "..%" PRIu64,
  870. range->parts[u].min_u64, range->parts[u].max_u64);
  871. faux_str_cat(&r, t);
  872. faux_str_free(t);
  873. }
  874. faux_str_cat(&r, "]\n");
  875. printf("%s", r);
  876. faux_free(r);
  877. }
  878. static void int_range(const struct lysc_type *type, int64_t def_min, int64_t def_max)
  879. {
  880. struct lysc_range *range = NULL;
  881. LY_ARRAY_COUNT_TYPE u = 0;
  882. char *r = NULL;
  883. assert(type);
  884. range = ((struct lysc_type_num *)type)->range;
  885. // Show defaults
  886. if (!range) {
  887. printf("[%" PRId64 "..%" PRId64 "]\n", def_min, def_max);
  888. return;
  889. }
  890. // Range
  891. faux_str_cat(&r, "[");
  892. LY_ARRAY_FOR(range->parts, u) {
  893. char *t = NULL;
  894. if (u != 0)
  895. faux_str_cat(&r, "|");
  896. t = faux_str_sprintf("%" PRId64 "..%" PRId64,
  897. range->parts[u].min_64, range->parts[u].max_64);
  898. faux_str_cat(&r, t);
  899. faux_str_free(t);
  900. }
  901. faux_str_cat(&r, "]\n");
  902. printf("%s", r);
  903. faux_free(r);
  904. }
  905. static void dec_range(const struct lysc_type *type, int64_t def_min, int64_t def_max)
  906. {
  907. struct lysc_range *range = NULL;
  908. uint8_t fraction_digits = 0;
  909. LY_ARRAY_COUNT_TYPE u = 0;
  910. char *r = NULL;
  911. int64_t div = 1;
  912. uint8_t i = 0;
  913. assert(type);
  914. range = ((struct lysc_type_dec *)type)->range;
  915. fraction_digits = ((struct lysc_type_dec *)type)->fraction_digits;
  916. for (i = 0; i < fraction_digits; i++)
  917. div = div * 10;
  918. // Show defaults
  919. if (!range) {
  920. printf("[%.*f..%.*f]\n",
  921. fraction_digits, (double)def_min / div,
  922. fraction_digits, (double)def_max / div);
  923. return;
  924. }
  925. // Range
  926. faux_str_cat(&r, "[");
  927. LY_ARRAY_FOR(range->parts, u) {
  928. char *t = NULL;
  929. if (u != 0)
  930. faux_str_cat(&r, "|");
  931. t = faux_str_sprintf("%.*f..%.*f",
  932. fraction_digits, (double)range->parts[u].min_64 / div,
  933. fraction_digits, (double)range->parts[u].max_64 / div);
  934. faux_str_cat(&r, t);
  935. faux_str_free(t);
  936. }
  937. faux_str_cat(&r, "]\n");
  938. printf("%s", r);
  939. faux_free(r);
  940. }
  941. static void str_range(const struct lysc_type *type)
  942. {
  943. struct lysc_range *range = NULL;
  944. LY_ARRAY_COUNT_TYPE u = 0;
  945. char *r = NULL;
  946. assert(type);
  947. range = ((struct lysc_type_str *)type)->length;
  948. // Show defaults
  949. if (!range) {
  950. printf("<string>\n");
  951. return;
  952. }
  953. // Range
  954. faux_str_cat(&r, "<string[");
  955. LY_ARRAY_FOR(range->parts, u) {
  956. char *t = NULL;
  957. if (u != 0)
  958. faux_str_cat(&r, "|");
  959. t = faux_str_sprintf("%" PRIu64 "..%" PRIu64,
  960. range->parts[u].min_u64, range->parts[u].max_u64);
  961. faux_str_cat(&r, t);
  962. faux_str_free(t);
  963. }
  964. faux_str_cat(&r, "]>\n");
  965. printf("%s", r);
  966. faux_free(r);
  967. }
  968. static void pline_print_type_help(const struct lysc_node *node,
  969. const struct lysc_type *type)
  970. {
  971. const char *units = NULL;
  972. assert(type);
  973. assert(node);
  974. if (node->nodetype & LYS_LEAF)
  975. units = ((struct lysc_node_leaf *)node)->units;
  976. else if (node->nodetype & LYS_LEAFLIST)
  977. units = ((struct lysc_node_leaflist *)node)->units;
  978. else
  979. return;
  980. if (units) {
  981. printf("%s\n", units);
  982. } else {
  983. switch (type->basetype) {
  984. case LY_TYPE_UINT8:
  985. uint_range(type, 0, UCHAR_MAX);
  986. break;
  987. case LY_TYPE_UINT16:
  988. uint_range(type, 0, USHRT_MAX);
  989. break;
  990. case LY_TYPE_UINT32:
  991. uint_range(type, 0, UINT_MAX);
  992. break;
  993. case LY_TYPE_UINT64:
  994. uint_range(type, 0, ULLONG_MAX);
  995. break;
  996. case LY_TYPE_INT8:
  997. int_range(type, CHAR_MIN, CHAR_MAX);
  998. break;
  999. case LY_TYPE_INT16:
  1000. int_range(type, SHRT_MIN, SHRT_MAX);
  1001. break;
  1002. case LY_TYPE_INT32:
  1003. int_range(type, INT_MIN, INT_MAX);
  1004. break;
  1005. case LY_TYPE_INT64:
  1006. int_range(type, LLONG_MIN, LLONG_MAX);
  1007. break;
  1008. case LY_TYPE_DEC64:
  1009. dec_range(type, LLONG_MIN, LLONG_MAX);
  1010. break;
  1011. case LY_TYPE_STRING:
  1012. str_range(type);
  1013. break;
  1014. case LY_TYPE_BOOL:
  1015. printf("<true/false>\n");
  1016. break;
  1017. case LY_TYPE_LEAFREF: {
  1018. const struct lysc_type_leafref *t =
  1019. (const struct lysc_type_leafref *)type;
  1020. const struct lysc_node *ref_node = NULL;
  1021. const struct lysc_type *ref_type = NULL;
  1022. char *node_path = lysc_path(node, LYSC_PATH_LOG, NULL, 0);
  1023. char *path = klysc_leafref_xpath(node, type, node_path);
  1024. faux_str_free(node_path);
  1025. ref_node = lys_find_path(NULL, node, path, 0);
  1026. faux_str_free(path);
  1027. if (!ref_node) {
  1028. pline_print_type_help(node, t->realtype);
  1029. return; // Because it prints whole info itself
  1030. }
  1031. if (ref_node->nodetype & LYS_LEAF)
  1032. ref_type = ((struct lysc_node_leaf *)ref_node)->type;
  1033. else
  1034. ref_type = ((struct lysc_node_leaflist *)ref_node)->type;
  1035. pline_print_type_help(ref_node, ref_type);
  1036. return; // Because it prints whole info itself
  1037. }
  1038. case LY_TYPE_UNION: {
  1039. const struct lysc_type_union *t =
  1040. (const struct lysc_type_union *)type;
  1041. LY_ARRAY_COUNT_TYPE u = 0;
  1042. LY_ARRAY_FOR(t->types, u)
  1043. pline_print_type_help(node, t->types[u]);
  1044. return; // Because it prints whole info itself
  1045. }
  1046. case LY_TYPE_ENUM: {
  1047. const struct lysc_type_enum *t =
  1048. (const struct lysc_type_enum *)type;
  1049. LY_ARRAY_COUNT_TYPE u = 0;
  1050. LY_ARRAY_FOR(t->enums, u)
  1051. if (t->enums[u].dsc) {
  1052. char *dsc = faux_str_getline(
  1053. t->enums[u].dsc, NULL);
  1054. printf("%s\n%s\n",
  1055. t->enums[u].name, dsc);
  1056. faux_str_free(dsc);
  1057. } else {
  1058. printf("%s\n%s\n",
  1059. t->enums[u].name,
  1060. t->enums[u].name);
  1061. }
  1062. return; // Because it prints whole info itself
  1063. }
  1064. case LY_TYPE_IDENT: {
  1065. struct lysc_type_identityref *t =
  1066. (struct lysc_type_identityref *)type;
  1067. LY_ARRAY_COUNT_TYPE u = 0;
  1068. LY_ARRAY_FOR(t->bases, u)
  1069. identityref_help(t->bases[u]);
  1070. return; // Because it prints whole info itself
  1071. }
  1072. default:
  1073. printf("<unknown>\n");
  1074. break;
  1075. }
  1076. }
  1077. if (node->dsc) {
  1078. char *dsc = faux_str_getline(node->dsc, NULL);
  1079. printf("%s\n", dsc);
  1080. faux_str_free(dsc);
  1081. } else {
  1082. printf("%s\n", node->name);
  1083. }
  1084. }
  1085. void pline_print_completions(const pline_t *pline, bool_t help, pt_e enabled_types)
  1086. {
  1087. faux_list_node_t *iter = NULL;
  1088. pcompl_t *pcompl = NULL;
  1089. sr_datastore_t current_ds = SRP_REPO_EDIT;
  1090. iter = faux_list_head(pline->compls);
  1091. while ((pcompl = (pcompl_t *)faux_list_each(&iter))) {
  1092. struct lysc_type *type = NULL;
  1093. const struct lysc_node *node = pcompl->node;
  1094. if (!(pcompl->pat & enabled_types))
  1095. continue;
  1096. if (pcompl->xpath && !help) {
  1097. sr_val_t *vals = NULL;
  1098. size_t val_num = 0;
  1099. size_t i = 0;
  1100. //printf("%s\n", pcompl->xpath);
  1101. // Switch to necessary DS
  1102. if (current_ds != pcompl->xpath_ds) {
  1103. sr_session_switch_ds(pline->sess, pcompl->xpath_ds);
  1104. current_ds = pcompl->xpath_ds;
  1105. }
  1106. sr_get_items(pline->sess, pcompl->xpath,
  1107. 0, 0, &vals, &val_num);
  1108. for (i = 0; i < val_num; i++) {
  1109. char *tmp = sr_val_to_str(&vals[i]);
  1110. if (!tmp)
  1111. continue;
  1112. printf("%s\n", tmp);
  1113. free(tmp);
  1114. }
  1115. sr_free_values(vals, val_num);
  1116. }
  1117. if (!node)
  1118. continue;
  1119. // Node
  1120. if (PCOMPL_NODE == pcompl->type) {
  1121. printf("%s\n", node->name);
  1122. if (help) {
  1123. if (!node->dsc) {
  1124. printf("%s\n", node->name);
  1125. } else {
  1126. char *dsc = faux_str_getline(node->dsc,
  1127. NULL);
  1128. printf("%s\n", dsc);
  1129. faux_str_free(dsc);
  1130. }
  1131. }
  1132. continue;
  1133. }
  1134. // Type
  1135. if (node->nodetype & LYS_LEAF)
  1136. type = ((struct lysc_node_leaf *)node)->type;
  1137. else if (node->nodetype & LYS_LEAFLIST)
  1138. type = ((struct lysc_node_leaflist *)node)->type;
  1139. else
  1140. continue;
  1141. if (help)
  1142. pline_print_type_help(node, type);
  1143. else
  1144. pline_print_type_completions(type);
  1145. }
  1146. // Restore default DS
  1147. if (current_ds != SRP_REPO_EDIT)
  1148. sr_session_switch_ds(pline->sess, SRP_REPO_EDIT);
  1149. }