syms.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. #include <syslog.h>
  6. #include <faux/faux.h>
  7. #include <faux/str.h>
  8. #include <faux/argv.h>
  9. #include <faux/list.h>
  10. #include <faux/error.h>
  11. #include <faux/file.h>
  12. #include <klish/khelper.h>
  13. #include <klish/kplugin.h>
  14. #include <klish/kentry.h>
  15. #include <klish/kscheme.h>
  16. #include <klish/kcontext.h>
  17. #include <klish/kpargv.h>
  18. #include <sysrepo.h>
  19. #include <sysrepo/xpath.h>
  20. #include <sysrepo/values.h>
  21. #include <sysrepo/netconf_acm.h>
  22. #include "klish_plugin_sysrepo.h"
  23. #define ERRORMSG "Error: "
  24. #define ARG_PATH "path"
  25. #define ARG_FROM_PATH "from_path"
  26. #define ARG_TO_PATH "to_path"
  27. // Print sysrepo session errors
  28. static void srp_print_errors(sr_session_ctx_t *session)
  29. {
  30. const sr_error_info_t *err_info = NULL;
  31. int rc = 0;
  32. unsigned int i = 0;
  33. if (!session)
  34. return;
  35. rc = sr_session_get_error(session, &err_info);
  36. if ((rc != SR_ERR_OK) || !err_info)
  37. return;
  38. // Show the first error only. Because probably next errors are
  39. // originated from internal sysrepo code but is not from subscribers.
  40. // for (i = 0; i < err_info->err_count; i++)
  41. for (i = 0; i < (err_info->err_count < 1 ? err_info->err_count : 1); i++)
  42. fprintf(stderr, ERRORMSG "%s\n", err_info->err[i].message);
  43. }
  44. // Print sysrepo session errors and then specified error
  45. static void srp_error(sr_session_ctx_t *session, const char *fmt, ...)
  46. {
  47. srp_print_errors(session);
  48. if (fmt) {
  49. va_list argptr;
  50. va_start(argptr, fmt);
  51. vfprintf(stderr, fmt, argptr);
  52. va_end(argptr);
  53. }
  54. }
  55. static faux_argv_t *param2argv(const faux_argv_t *cur_path,
  56. const kpargv_t *pargv, const char *entry_name)
  57. {
  58. faux_list_node_t *iter = NULL;
  59. faux_list_t *pargs = NULL;
  60. faux_argv_t *args = NULL;
  61. kparg_t *parg = NULL;
  62. assert(pargv);
  63. if (!pargv)
  64. return NULL;
  65. pargs = kpargv_find_multi(pargv, entry_name);
  66. if (cur_path)
  67. args = faux_argv_dup(cur_path);
  68. else
  69. args = faux_argv_new();
  70. iter = faux_list_head(pargs);
  71. while ((parg = (kparg_t *)faux_list_each(&iter))) {
  72. faux_argv_add(args, kparg_value(parg));
  73. }
  74. faux_list_free(pargs);
  75. return args;
  76. }
  77. // Candidate from pargv contains possible begin of current word (that must be
  78. // completed). kpargv's list don't contain candidate but only already parsed
  79. // words.
  80. static int srp_compl_or_help(kcontext_t *context, bool_t help,
  81. pt_e enabled_ptypes, bool_t use_cur_path, bool_t existing_nodes_only)
  82. {
  83. faux_argv_t *args = NULL;
  84. pline_t *pline = NULL;
  85. sr_session_ctx_t *sess = NULL;
  86. const char *entry_name = NULL;
  87. faux_argv_t *cur_path = NULL;
  88. assert(context);
  89. sess = srp_udata_sr_sess(context);
  90. if (use_cur_path)
  91. cur_path = (faux_argv_t *)srp_udata_path(context);
  92. entry_name = kentry_name(kcontext_candidate_entry(context));
  93. args = param2argv(cur_path, kcontext_parent_pargv(context), entry_name);
  94. pline = pline_parse(sess, args, srp_udata_opts(context));
  95. faux_argv_free(args);
  96. pline_print_completions(pline, help, enabled_ptypes, existing_nodes_only);
  97. pline_free(pline);
  98. return 0;
  99. }
  100. int srp_compl(kcontext_t *context)
  101. {
  102. return srp_compl_or_help(context, BOOL_FALSE, PT_COMPL_ALL, BOOL_TRUE, BOOL_FALSE);
  103. }
  104. int srp_help(kcontext_t *context)
  105. {
  106. return srp_compl_or_help(context, BOOL_TRUE, PT_COMPL_ALL, BOOL_TRUE, BOOL_FALSE);
  107. }
  108. int srp_compl_set(kcontext_t *context)
  109. {
  110. return srp_compl_or_help(context, BOOL_FALSE, PT_COMPL_SET, BOOL_TRUE, BOOL_FALSE);
  111. }
  112. int srp_help_set(kcontext_t *context)
  113. {
  114. return srp_compl_or_help(context, BOOL_TRUE, PT_COMPL_SET, BOOL_TRUE, BOOL_FALSE);
  115. }
  116. int srp_compl_del(kcontext_t *context)
  117. {
  118. return srp_compl_or_help(context, BOOL_FALSE, PT_COMPL_DEL, BOOL_TRUE, BOOL_TRUE);
  119. }
  120. int srp_help_del(kcontext_t *context)
  121. {
  122. return srp_compl_or_help(context, BOOL_TRUE, PT_COMPL_DEL, BOOL_TRUE, BOOL_TRUE);
  123. }
  124. int srp_compl_edit(kcontext_t *context)
  125. {
  126. return srp_compl_or_help(context, BOOL_FALSE, PT_COMPL_EDIT, BOOL_TRUE, BOOL_FALSE);
  127. }
  128. int srp_compl_edit_abs(kcontext_t *context)
  129. {
  130. return srp_compl_or_help(context, BOOL_FALSE, PT_COMPL_EDIT, BOOL_FALSE, BOOL_FALSE);
  131. }
  132. int srp_help_edit(kcontext_t *context)
  133. {
  134. return srp_compl_or_help(context, BOOL_TRUE, PT_COMPL_EDIT, BOOL_TRUE, BOOL_FALSE);
  135. }
  136. int srp_help_edit_abs(kcontext_t *context)
  137. {
  138. return srp_compl_or_help(context, BOOL_TRUE, PT_COMPL_EDIT, BOOL_FALSE, BOOL_FALSE);
  139. }
  140. int srp_compl_insert(kcontext_t *context)
  141. {
  142. return srp_compl_or_help(context, BOOL_FALSE, PT_COMPL_INSERT, BOOL_TRUE, BOOL_TRUE);
  143. }
  144. int srp_help_insert(kcontext_t *context)
  145. {
  146. return srp_compl_or_help(context, BOOL_TRUE, PT_COMPL_INSERT, BOOL_TRUE, BOOL_TRUE);
  147. }
  148. int srp_compl_show(kcontext_t *context)
  149. {
  150. return srp_compl_or_help(context, BOOL_FALSE, PT_COMPL_SHOW, BOOL_TRUE, BOOL_TRUE);
  151. }
  152. int srp_compl_show_abs(kcontext_t *context)
  153. {
  154. return srp_compl_or_help(context, BOOL_FALSE, PT_COMPL_SHOW, BOOL_FALSE, BOOL_TRUE);
  155. }
  156. int srp_help_show(kcontext_t *context)
  157. {
  158. return srp_compl_or_help(context, BOOL_TRUE, PT_COMPL_SHOW, BOOL_TRUE, BOOL_TRUE);
  159. }
  160. int srp_help_show_abs(kcontext_t *context)
  161. {
  162. return srp_compl_or_help(context, BOOL_TRUE, PT_COMPL_SHOW, BOOL_FALSE, BOOL_TRUE);
  163. }
  164. int srp_prompt_edit_path(kcontext_t *context)
  165. {
  166. faux_argv_t *cur_path = NULL;
  167. char *path = NULL;
  168. assert(context);
  169. cur_path = (faux_argv_t *)srp_udata_path(context);
  170. if (cur_path)
  171. path = faux_argv_line(cur_path);
  172. kcontext_printf(context, "[edit%s%s]\n",
  173. path ? " " : "", path ? path : "");
  174. faux_str_free(path);
  175. return 0;
  176. }
  177. static int srp_check_type(kcontext_t *context,
  178. pt_e not_accepted_nodes, size_t max_expr_num, bool_t use_cur_path)
  179. {
  180. int ret = -1;
  181. faux_argv_t *args = NULL;
  182. pline_t *pline = NULL;
  183. sr_session_ctx_t *sess = NULL;
  184. const char *entry_name = NULL;
  185. const char *value = NULL;
  186. pexpr_t *expr = NULL;
  187. size_t expr_num = 0;
  188. faux_argv_t *cur_path = NULL;
  189. assert(context);
  190. sess = srp_udata_sr_sess(context);
  191. if (use_cur_path)
  192. cur_path = (faux_argv_t *)srp_udata_path(context);
  193. entry_name = kentry_name(kcontext_candidate_entry(context));
  194. value = kcontext_candidate_value(context);
  195. args = param2argv(cur_path, kcontext_parent_pargv(context), entry_name);
  196. if (value)
  197. faux_argv_add(args, value);
  198. pline = pline_parse(sess, args, srp_udata_opts(context));
  199. faux_argv_free(args);
  200. if (pline->invalid)
  201. goto err;
  202. expr_num = faux_list_len(pline->exprs);
  203. if (expr_num < 1)
  204. goto err;
  205. if ((max_expr_num > 0) && // '0' means unlimited
  206. (expr_num > max_expr_num))
  207. goto err;
  208. expr = pline_current_expr(pline);
  209. if (expr->pat & not_accepted_nodes)
  210. goto err;
  211. ret = 0;
  212. err:
  213. pline_free(pline);
  214. return ret;
  215. }
  216. int srp_PLINE_SET(kcontext_t *context)
  217. {
  218. return srp_check_type(context, PT_NOT_SET, 0, BOOL_TRUE);
  219. }
  220. int srp_PLINE_DEL(kcontext_t *context)
  221. {
  222. return srp_check_type(context, PT_NOT_DEL, 1, BOOL_TRUE);
  223. }
  224. int srp_PLINE_EDIT(kcontext_t *context)
  225. {
  226. return srp_check_type(context, PT_NOT_EDIT, 1, BOOL_TRUE);
  227. }
  228. int srp_PLINE_EDIT_ABS(kcontext_t *context)
  229. {
  230. return srp_check_type(context, PT_NOT_EDIT, 1, BOOL_FALSE);
  231. }
  232. int srp_PLINE_INSERT_FROM(kcontext_t *context)
  233. {
  234. return srp_check_type(context, PT_NOT_INSERT, 1, BOOL_TRUE);
  235. }
  236. int srp_PLINE_SHOW(kcontext_t *context)
  237. {
  238. return srp_check_type(context, PT_NOT_SHOW, 1, BOOL_TRUE);
  239. }
  240. int srp_PLINE_SHOW_ABS(kcontext_t *context)
  241. {
  242. return srp_check_type(context, PT_NOT_SHOW, 1, BOOL_FALSE);
  243. }
  244. static faux_argv_t *assemble_insert_to(sr_session_ctx_t *sess, const kpargv_t *pargv,
  245. faux_argv_t *cur_path, const char *candidate_value, pline_opts_t *opts)
  246. {
  247. faux_argv_t *args = NULL;
  248. faux_argv_t *insert_to = NULL;
  249. pline_t *pline = NULL;
  250. pexpr_t *expr = NULL;
  251. size_t i = 0;
  252. assert(sess);
  253. args = param2argv(cur_path, pargv, ARG_FROM_PATH);
  254. pline = pline_parse(sess, args, opts);
  255. expr = pline_current_expr(pline);
  256. for (i = 0; i < (expr->args_num - expr->list_pos); i++) {
  257. faux_argv_node_t *iter = faux_argv_iterr(args);
  258. faux_argv_del(args, iter);
  259. }
  260. insert_to = param2argv(args, pargv, ARG_TO_PATH);
  261. faux_argv_free(args);
  262. if (candidate_value)
  263. faux_argv_add(insert_to, candidate_value);
  264. pline_free(pline);
  265. return insert_to;
  266. }
  267. int srp_PLINE_INSERT_TO(kcontext_t *context)
  268. {
  269. int ret = -1;
  270. faux_argv_t *args = NULL;
  271. pline_t *pline = NULL;
  272. sr_session_ctx_t *sess = NULL;
  273. const char *value = NULL;
  274. pexpr_t *expr = NULL;
  275. size_t expr_num = 0;
  276. faux_argv_t *cur_path = NULL;
  277. assert(context);
  278. sess = srp_udata_sr_sess(context);
  279. cur_path = (faux_argv_t *)srp_udata_path(context);
  280. value = kcontext_candidate_value(context);
  281. args = assemble_insert_to(sess, kcontext_parent_pargv(context),
  282. cur_path, value, srp_udata_opts(context));
  283. pline = pline_parse(sess, args, srp_udata_opts(context));
  284. faux_argv_free(args);
  285. if (pline->invalid)
  286. goto err;
  287. expr_num = faux_list_len(pline->exprs);
  288. if (expr_num != 1)
  289. goto err;
  290. expr = pline_current_expr(pline);
  291. if (expr->pat & PT_NOT_INSERT)
  292. goto err;
  293. ret = 0;
  294. err:
  295. pline_free(pline);
  296. return ret;
  297. }
  298. static int srp_compl_or_help_insert_to(kcontext_t *context, bool_t help)
  299. {
  300. faux_argv_t *args = NULL;
  301. pline_t *pline = NULL;
  302. sr_session_ctx_t *sess = NULL;
  303. faux_argv_t *cur_path = NULL;
  304. assert(context);
  305. sess = srp_udata_sr_sess(context);
  306. cur_path = (faux_argv_t *)srp_udata_path(context);
  307. args = assemble_insert_to(sess, kcontext_parent_pargv(context),
  308. cur_path, NULL, srp_udata_opts(context));
  309. pline = pline_parse(sess, args, srp_udata_opts(context));
  310. faux_argv_free(args);
  311. pline_print_completions(pline, help, PT_COMPL_INSERT, BOOL_TRUE);
  312. pline_free(pline);
  313. return 0;
  314. }
  315. int srp_compl_insert_to(kcontext_t *context)
  316. {
  317. return srp_compl_or_help_insert_to(context, BOOL_FALSE);
  318. }
  319. int srp_help_insert_to(kcontext_t *context)
  320. {
  321. return srp_compl_or_help_insert_to(context, BOOL_TRUE);
  322. }
  323. int srp_set(kcontext_t *context)
  324. {
  325. int ret = 0;
  326. faux_argv_t *args = NULL;
  327. pline_t *pline = NULL;
  328. sr_session_ctx_t *sess = NULL;
  329. faux_list_node_t *iter = NULL;
  330. pexpr_t *expr = NULL;
  331. size_t err_num = 0;
  332. faux_argv_t *cur_path = NULL;
  333. assert(context);
  334. sess = srp_udata_sr_sess(context);
  335. cur_path = (faux_argv_t *)srp_udata_path(context);
  336. args = param2argv(cur_path, kcontext_pargv(context), ARG_PATH);
  337. pline = pline_parse(sess, args, srp_udata_opts(context));
  338. faux_argv_free(args);
  339. if (pline->invalid) {
  340. fprintf(stderr, ERRORMSG "Invalid set request\n");
  341. ret = -1;
  342. goto cleanup;
  343. }
  344. iter = faux_list_head(pline->exprs);
  345. while ((expr = (pexpr_t *)faux_list_each(&iter))) {
  346. if (!(expr->pat & PT_SET)) {
  347. err_num++;
  348. fprintf(stderr, ERRORMSG "Illegal expression for set operation\n");
  349. break;
  350. }
  351. if (sr_set_item_str(sess, expr->xpath, expr->value, NULL, 0) !=
  352. SR_ERR_OK) {
  353. err_num++;
  354. srp_error(sess, ERRORMSG "Can't set data\n");
  355. break;
  356. }
  357. }
  358. if (err_num > 0)
  359. ret = -1;
  360. if (!sr_has_changes(sess))
  361. goto cleanup;
  362. if (err_num > 0) {
  363. sr_discard_changes(sess);
  364. goto cleanup;
  365. }
  366. if (sr_apply_changes(sess, 0) != SR_ERR_OK) {
  367. sr_discard_changes(sess);
  368. srp_error(sess, ERRORMSG "Can't apply changes\n");
  369. goto cleanup;
  370. }
  371. cleanup:
  372. pline_free(pline);
  373. return ret;
  374. }
  375. int srp_del(kcontext_t *context)
  376. {
  377. int ret = -1;
  378. faux_argv_t *args = NULL;
  379. pline_t *pline = NULL;
  380. sr_session_ctx_t *sess = NULL;
  381. pexpr_t *expr = NULL;
  382. faux_argv_t *cur_path = NULL;
  383. assert(context);
  384. sess = srp_udata_sr_sess(context);
  385. cur_path = (faux_argv_t *)srp_udata_path(context);
  386. args = param2argv(cur_path, kcontext_pargv(context), ARG_PATH);
  387. pline = pline_parse(sess, args, srp_udata_opts(context));
  388. faux_argv_free(args);
  389. if (pline->invalid) {
  390. fprintf(stderr, ERRORMSG "Invalid 'del' request\n");
  391. goto err;
  392. }
  393. if (faux_list_len(pline->exprs) > 1) {
  394. fprintf(stderr, ERRORMSG "Can't delete more than one object\n");
  395. goto err;
  396. }
  397. expr = (pexpr_t *)faux_list_data(faux_list_head(pline->exprs));
  398. if (!(expr->pat & PT_DEL)) {
  399. fprintf(stderr, ERRORMSG "Illegal expression for 'del' operation\n");
  400. goto err;
  401. }
  402. if (sr_delete_item(sess, expr->xpath, 0) != SR_ERR_OK) {
  403. srp_error(sess, ERRORMSG "Can't delete data\n");
  404. goto err;
  405. }
  406. if (sr_apply_changes(sess, 0) != SR_ERR_OK) {
  407. sr_discard_changes(sess);
  408. srp_error(sess, ERRORMSG "Can't apply changes\n");
  409. goto err;
  410. }
  411. ret = 0;
  412. err:
  413. pline_free(pline);
  414. return ret;
  415. }
  416. int srp_edit(kcontext_t *context)
  417. {
  418. int ret = -1;
  419. faux_argv_t *args = NULL;
  420. pline_t *pline = NULL;
  421. sr_session_ctx_t *sess = NULL;
  422. pexpr_t *expr = NULL;
  423. faux_argv_t *cur_path = NULL;
  424. assert(context);
  425. sess = srp_udata_sr_sess(context);
  426. cur_path = (faux_argv_t *)srp_udata_path(context);
  427. args = param2argv(cur_path, kcontext_pargv(context), ARG_PATH);
  428. pline = pline_parse(sess, args, srp_udata_opts(context));
  429. if (pline->invalid) {
  430. fprintf(stderr, ERRORMSG "Invalid 'edit' request\n");
  431. goto err;
  432. }
  433. if (faux_list_len(pline->exprs) > 1) {
  434. fprintf(stderr, ERRORMSG "Can't process more than one object\n");
  435. goto err;
  436. }
  437. expr = (pexpr_t *)faux_list_data(faux_list_head(pline->exprs));
  438. if (!(expr->pat & PT_EDIT)) {
  439. fprintf(stderr, ERRORMSG "Illegal expression for 'edit' operation\n");
  440. goto err;
  441. }
  442. if (sr_set_item_str(sess, expr->xpath, NULL, NULL, 0) != SR_ERR_OK) {
  443. srp_error(sess, ERRORMSG "Can't set editing data\n");
  444. goto err;
  445. }
  446. if (sr_apply_changes(sess, 0) != SR_ERR_OK) {
  447. sr_discard_changes(sess);
  448. srp_error(sess, ERRORMSG "Can't apply changes\n");
  449. goto err;
  450. }
  451. // Set new current path
  452. srp_udata_set_path(context, args);
  453. ret = 0;
  454. err:
  455. if (ret < 0)
  456. faux_argv_free(args);
  457. pline_free(pline);
  458. return ret;
  459. }
  460. int srp_top(kcontext_t *context)
  461. {
  462. assert(context);
  463. srp_udata_set_path(context, NULL);
  464. return 0;
  465. }
  466. int srp_up(kcontext_t *context)
  467. {
  468. sr_session_ctx_t *sess = NULL;
  469. faux_argv_t *cur_path = NULL;
  470. faux_argv_node_t *iter = NULL;
  471. assert(context);
  472. sess = srp_udata_sr_sess(context);
  473. cur_path = (faux_argv_t *)srp_udata_path(context);
  474. if (!cur_path)
  475. return -1; // It's top level and can't level up
  476. // Remove last arguments one by one and wait for legal edit-like pline
  477. while (faux_argv_len(cur_path) > 0) {
  478. pline_t *pline = NULL;
  479. pexpr_t *expr = NULL;
  480. size_t len = 0;
  481. iter = faux_argv_iterr(cur_path);
  482. faux_argv_del(cur_path, iter);
  483. pline = pline_parse(sess, cur_path, srp_udata_opts(context));
  484. if (pline->invalid) {
  485. pline_free(pline);
  486. continue;
  487. }
  488. len = faux_list_len(pline->exprs);
  489. if (len != 1) {
  490. pline_free(pline);
  491. continue;
  492. }
  493. expr = (pexpr_t *)faux_list_data(faux_list_head(pline->exprs));
  494. if (!(expr->pat & PT_EDIT)) {
  495. pline_free(pline);
  496. continue;
  497. }
  498. // Here new path is ok
  499. pline_free(pline);
  500. break;
  501. }
  502. // Don't store empty path
  503. if (faux_argv_len(cur_path) == 0)
  504. srp_udata_set_path(context, NULL);
  505. return 0;
  506. }
  507. int srp_insert(kcontext_t *context)
  508. {
  509. int ret = -1;
  510. pline_t *pline = NULL;
  511. pline_t *pline_to = NULL;
  512. sr_session_ctx_t *sess = NULL;
  513. pexpr_t *expr = NULL;
  514. pexpr_t *expr_to = NULL;
  515. faux_argv_t *cur_path = NULL;
  516. faux_argv_t *insert_from = NULL;
  517. faux_argv_t *insert_to = NULL;
  518. sr_move_position_t position = SR_MOVE_LAST;
  519. kpargv_t *pargv = NULL;
  520. const char *list_keys = NULL;
  521. const char *leaflist_value = NULL;
  522. assert(context);
  523. sess = srp_udata_sr_sess(context);
  524. cur_path = (faux_argv_t *)srp_udata_path(context);
  525. pargv = kcontext_pargv(context);
  526. // 'from' argument
  527. insert_from = param2argv(cur_path, pargv, ARG_FROM_PATH);
  528. pline = pline_parse(sess, insert_from, srp_udata_opts(context));
  529. faux_argv_free(insert_from);
  530. if (pline->invalid) {
  531. fprintf(stderr, ERRORMSG "Invalid 'from' expression\n");
  532. goto err;
  533. }
  534. if (faux_list_len(pline->exprs) > 1) {
  535. fprintf(stderr, ERRORMSG "Can't process more than one object\n");
  536. goto err;
  537. }
  538. expr = (pexpr_t *)faux_list_data(faux_list_head(pline->exprs));
  539. if (!(expr->pat & PT_INSERT)) {
  540. fprintf(stderr, ERRORMSG "Illegal 'from' expression for 'insert' operation\n");
  541. goto err;
  542. }
  543. // Position
  544. if (kpargv_find(pargv, "first"))
  545. position = SR_MOVE_FIRST;
  546. else if (kpargv_find(pargv, "last"))
  547. position = SR_MOVE_LAST;
  548. else if (kpargv_find(pargv, "before"))
  549. position = SR_MOVE_BEFORE;
  550. else if (kpargv_find(pargv, "after"))
  551. position = SR_MOVE_AFTER;
  552. else {
  553. fprintf(stderr, ERRORMSG "Illegal 'position' argument\n");
  554. goto err;
  555. }
  556. // 'to' argument
  557. if ((SR_MOVE_BEFORE == position) || (SR_MOVE_AFTER == position)) {
  558. insert_to = assemble_insert_to(sess, pargv, cur_path,
  559. NULL, srp_udata_opts(context));
  560. pline_to = pline_parse(sess, insert_to, srp_udata_opts(context));
  561. faux_argv_free(insert_to);
  562. if (pline_to->invalid) {
  563. fprintf(stderr, ERRORMSG "Invalid 'to' expression\n");
  564. goto err;
  565. }
  566. if (faux_list_len(pline_to->exprs) > 1) {
  567. fprintf(stderr, ERRORMSG "Can't process more than one object\n");
  568. goto err;
  569. }
  570. expr_to = (pexpr_t *)faux_list_data(faux_list_head(pline_to->exprs));
  571. if (!(expr_to->pat & PT_INSERT)) {
  572. fprintf(stderr, ERRORMSG "Illegal 'to' expression for 'insert' operation\n");
  573. goto err;
  574. }
  575. if (PAT_LIST_KEY == expr_to->pat)
  576. list_keys = expr_to->last_keys;
  577. else // PATH_LEAFLIST_VALUE
  578. leaflist_value = expr_to->last_keys;
  579. }
  580. if (sr_move_item(sess, expr->xpath, position,
  581. list_keys, leaflist_value, NULL, 0) != SR_ERR_OK) {
  582. srp_error(sess, ERRORMSG "Can't move element\n");
  583. goto err;
  584. }
  585. if (sr_apply_changes(sess, 0) != SR_ERR_OK) {
  586. sr_discard_changes(sess);
  587. srp_error(sess, ERRORMSG "Can't apply changes\n");
  588. goto err;
  589. }
  590. ret = 0;
  591. err:
  592. pline_free(pline);
  593. pline_free(pline_to);
  594. return ret;
  595. }
  596. int srp_verify(kcontext_t *context)
  597. {
  598. int ret = -1;
  599. sr_session_ctx_t *sess = NULL;
  600. assert(context);
  601. sess = srp_udata_sr_sess(context);
  602. // Validate candidate config
  603. if (sr_validate(sess, NULL, 0) != SR_ERR_OK) {
  604. srp_error(sess, ERRORMSG "Invalid candidate configuration\n");
  605. goto err;
  606. }
  607. ret = 0;
  608. err:
  609. return ret;
  610. }
  611. int srp_commit(kcontext_t *context)
  612. {
  613. int ret = -1;
  614. sr_session_ctx_t *sess = NULL;
  615. assert(context);
  616. sess = srp_udata_sr_sess(context);
  617. // Validate candidate config. The copy operation is not enough to fully
  618. // verify candidate config. It verifies only the part of it. So verify
  619. // before commit
  620. if (sr_validate(sess, NULL, 0) != SR_ERR_OK) {
  621. srp_error(sess, ERRORMSG "Invalid candidate configuration\n");
  622. goto err;
  623. }
  624. // Copy candidate to running-config
  625. if (sr_session_switch_ds(sess, SR_DS_RUNNING)) {
  626. srp_error(sess, ERRORMSG "Can't connect to running-config data store\n");
  627. goto err;
  628. }
  629. if (sr_copy_config(sess, NULL, SRP_REPO_EDIT, 0) != SR_ERR_OK) {
  630. srp_error(sess, ERRORMSG "Can't commit to running-config\n");
  631. goto err;
  632. }
  633. // Copy running-config to startup-config
  634. if (sr_session_switch_ds(sess, SR_DS_STARTUP)) {
  635. srp_error(sess, ERRORMSG "Can't connect to startup-config data store\n");
  636. goto err;
  637. }
  638. if (sr_copy_config(sess, NULL, SR_DS_RUNNING, 0) != SR_ERR_OK) {
  639. srp_error(sess, ERRORMSG "Can't store data to startup-config\n");
  640. goto err;
  641. }
  642. ret = 0;
  643. err:
  644. sr_session_switch_ds(sess, SRP_REPO_EDIT);
  645. return ret;
  646. }
  647. int srp_reset(kcontext_t *context)
  648. {
  649. int ret = -1;
  650. sr_session_ctx_t *sess = NULL;
  651. assert(context);
  652. sess = srp_udata_sr_sess(context);
  653. // Copy running-config to candidate config
  654. if (sr_copy_config(sess, NULL, SR_DS_RUNNING, 0) != SR_ERR_OK) {
  655. srp_error(sess, ERRORMSG "Can't reset to running-config\n");
  656. goto err;
  657. }
  658. ret = 0;
  659. err:
  660. return ret;
  661. }
  662. int srp_show_xml(kcontext_t *context)
  663. {
  664. int ret = -1;
  665. faux_argv_t *args = NULL;
  666. pline_t *pline = NULL;
  667. sr_session_ctx_t *sess = NULL;
  668. pexpr_t *expr = NULL;
  669. faux_argv_t *cur_path = NULL;
  670. sr_data_t *data = NULL;
  671. struct ly_out *out = NULL;
  672. assert(context);
  673. sess = srp_udata_sr_sess(context);
  674. cur_path = (faux_argv_t *)srp_udata_path(context);
  675. args = param2argv(cur_path, kcontext_pargv(context), ARG_PATH);
  676. pline = pline_parse(sess, args, srp_udata_opts(context));
  677. faux_argv_free(args);
  678. if (pline->invalid) {
  679. fprintf(stderr, ERRORMSG "Invalid 'show' request\n");
  680. goto err;
  681. }
  682. if (faux_list_len(pline->exprs) > 1) {
  683. fprintf(stderr, ERRORMSG "Can't process more than one object\n");
  684. goto err;
  685. }
  686. expr = (pexpr_t *)faux_list_data(faux_list_head(pline->exprs));
  687. if (!(expr->pat & PT_EDIT)) {
  688. fprintf(stderr, ERRORMSG "Illegal expression for 'show' operation\n");
  689. goto err;
  690. }
  691. if (sr_get_subtree(sess, expr->xpath, 0, &data) != SR_ERR_OK) {
  692. srp_error(sess, ERRORMSG "Can't get specified subtree\n");
  693. goto err;
  694. }
  695. if (!data) // Not found
  696. goto err;
  697. ly_out_new_file(stdout, &out);
  698. lyd_print_tree(out, data->tree, LYD_XML, 0);
  699. ly_out_free(out, NULL, 0);
  700. // child = lyd_child(data->tree);
  701. // if (child) {
  702. // ly_out_new_file(stdout, &out);
  703. // lyd_print_all(out, child, LYD_XML, 0);
  704. // }
  705. struct lyd_meta *meta = lyd_find_meta(data->tree->meta, NULL, "junos-configuration-metadata:active");
  706. if (meta)
  707. printf("META\n");
  708. sr_release_data(data);
  709. ret = 0;
  710. err:
  711. pline_free(pline);
  712. return ret;
  713. }
  714. static int show(kcontext_t *context, sr_datastore_t ds,
  715. const char *path_var, bool_t use_cur_path)
  716. {
  717. int ret = -1;
  718. faux_argv_t *args = NULL;
  719. pline_t *pline = NULL;
  720. sr_session_ctx_t *sess = NULL;
  721. pexpr_t *expr = NULL;
  722. faux_argv_t *cur_path = NULL;
  723. char *xpath = NULL;
  724. size_t xpath_depth = 0;
  725. assert(context);
  726. sess = srp_udata_sr_sess(context);
  727. if (ds != SRP_REPO_EDIT)
  728. sr_session_switch_ds(sess, ds);
  729. if (use_cur_path)
  730. cur_path = (faux_argv_t *)srp_udata_path(context);
  731. if (kpargv_find(kcontext_pargv(context), path_var) || cur_path) {
  732. args = param2argv(cur_path, kcontext_pargv(context), path_var);
  733. pline = pline_parse(sess, args, srp_udata_opts(context));
  734. faux_argv_free(args);
  735. if (pline->invalid) {
  736. fprintf(stderr, ERRORMSG "Invalid 'show' request\n");
  737. goto err;
  738. }
  739. if (faux_list_len(pline->exprs) > 1) {
  740. fprintf(stderr, ERRORMSG "Can't process more than one object\n");
  741. goto err;
  742. }
  743. if (!(expr = (pexpr_t *)faux_list_data(faux_list_head(pline->exprs)))) {
  744. fprintf(stderr, ERRORMSG "Can't get expression\n");
  745. goto err;
  746. }
  747. if (!(expr->pat & PT_SHOW)) {
  748. fprintf(stderr, ERRORMSG "Illegal expression for 'show' operation\n");
  749. goto err;
  750. }
  751. if (!expr->xpath) {
  752. fprintf(stderr, ERRORMSG "Empty expression for 'show' operation\n");
  753. goto err;
  754. }
  755. xpath = expr->xpath;
  756. xpath_depth = expr->tree_depth;
  757. }
  758. show_xpath(sess, xpath, xpath_depth, srp_udata_opts(context));
  759. ret = 0;
  760. err:
  761. pline_free(pline);
  762. if (ds != SRP_REPO_EDIT)
  763. sr_session_switch_ds(sess, SRP_REPO_EDIT);
  764. return ret;
  765. }
  766. static int show_path(kcontext_t *context, bool_t use_cur_path)
  767. {
  768. sr_datastore_t ds = SRP_REPO_EDIT;
  769. const char *script = NULL;
  770. assert(context);
  771. script = kcontext_script(context);
  772. if (!faux_str_is_empty(script))
  773. if (!kly_str2ds(script, strlen(script), &ds))
  774. ds = SRP_REPO_EDIT;
  775. return show(context, ds, ARG_PATH, use_cur_path);
  776. }
  777. int srp_show_abs(kcontext_t *context)
  778. {
  779. return show_path(context, BOOL_FALSE);
  780. }
  781. int srp_show(kcontext_t *context)
  782. {
  783. return show_path(context, BOOL_TRUE);
  784. }
  785. int srp_deactivate(kcontext_t *context)
  786. {
  787. int ret = -1;
  788. faux_argv_t *args = NULL;
  789. pline_t *pline = NULL;
  790. sr_session_ctx_t *sess = NULL;
  791. pexpr_t *expr = NULL;
  792. faux_argv_t *cur_path = NULL;
  793. sr_data_t *data = NULL;
  794. assert(context);
  795. sess = srp_udata_sr_sess(context);
  796. cur_path = (faux_argv_t *)srp_udata_path(context);
  797. args = param2argv(cur_path, kcontext_pargv(context), ARG_PATH);
  798. pline = pline_parse(sess, args, srp_udata_opts(context));
  799. faux_argv_free(args);
  800. if (pline->invalid) {
  801. fprintf(stderr, ERRORMSG "Invalid 'show' request\n");
  802. goto err;
  803. }
  804. if (faux_list_len(pline->exprs) > 1) {
  805. fprintf(stderr, ERRORMSG "Can't process more than one object\n");
  806. goto err;
  807. }
  808. expr = (pexpr_t *)faux_list_data(faux_list_head(pline->exprs));
  809. if (!(expr->pat & PT_DEL)) {
  810. fprintf(stderr, ERRORMSG "Illegal expression for 'show' operation\n");
  811. goto err;
  812. }
  813. if (sr_get_subtree(sess, expr->xpath, 0, &data) != SR_ERR_OK) {
  814. srp_error(sess, ERRORMSG "Can't get specified subtree\n");
  815. goto err;
  816. }
  817. if (!data) // Not found
  818. goto err;
  819. if (lyd_new_meta(LYD_CTX(data->tree), data->tree, NULL,
  820. "junos-configuration-metadata:active", "false", 0, NULL)) {
  821. fprintf(stderr, ERRORMSG "Can't deactivate\n");
  822. goto err;
  823. }
  824. struct lyd_meta *meta = lyd_find_meta(data->tree->meta, NULL, "junos-configuration-metadata:active");
  825. if (meta)
  826. printf("META\n");
  827. if (sr_has_changes(sess))
  828. fprintf(stderr, ERRORMSG "Has changes\n");
  829. if (sr_apply_changes(sess, 0) != SR_ERR_OK) {
  830. sr_discard_changes(sess);
  831. srp_error(sess, ERRORMSG "Can't apply changes\n");
  832. }
  833. sr_release_data(data);
  834. if (sr_get_subtree(sess, expr->xpath, 0, &data) != SR_ERR_OK) {
  835. srp_error(sess, ERRORMSG "Can't get specified subtree\n");
  836. goto err;
  837. }
  838. if (!data) // Not found
  839. goto err;
  840. struct ly_out *out = NULL;
  841. ly_out_new_file(stdout, &out);
  842. lyd_print_tree(out, data->tree, LYD_XML, 0);
  843. ly_out_free(out, NULL, 0);
  844. sr_release_data(data);
  845. ret = 0;
  846. err:
  847. pline_free(pline);
  848. return ret;
  849. }
  850. int srp_diff(kcontext_t *context)
  851. {
  852. int ret = -1;
  853. pline_t *pline = NULL;
  854. sr_session_ctx_t *sess = NULL;
  855. sr_data_t *data1 = NULL;
  856. sr_data_t *data2 = NULL;
  857. faux_argv_t *cur_path = NULL;
  858. const char *xpath = NULL;
  859. struct lyd_node *diff = NULL;
  860. pline_opts_t masked_opts = {};
  861. assert(context);
  862. sess = srp_udata_sr_sess(context);
  863. cur_path = (faux_argv_t *)srp_udata_path(context);
  864. if (kpargv_find(kcontext_pargv(context), ARG_PATH) || cur_path) {
  865. faux_argv_t *args = NULL;
  866. pexpr_t *expr = NULL;
  867. args = param2argv(cur_path, kcontext_pargv(context), ARG_PATH);
  868. pline = pline_parse(sess, args, srp_udata_opts(context));
  869. faux_argv_free(args);
  870. if (pline->invalid) {
  871. fprintf(stderr, ERRORMSG "Invalid 'show' request\n");
  872. goto err;
  873. }
  874. if (faux_list_len(pline->exprs) > 1) {
  875. fprintf(stderr, ERRORMSG "Can't process more than one object\n");
  876. goto err;
  877. }
  878. if (!(expr = (pexpr_t *)faux_list_data(faux_list_head(pline->exprs)))) {
  879. fprintf(stderr, ERRORMSG "Can't get expression\n");
  880. goto err;
  881. }
  882. if (!(expr->pat & PT_EDIT)) {
  883. fprintf(stderr, ERRORMSG "Illegal expression for 'show' operation\n");
  884. goto err;
  885. }
  886. if (!expr->xpath) {
  887. fprintf(stderr, ERRORMSG "Empty expression for 'show' operation\n");
  888. goto err;
  889. }
  890. xpath = expr->xpath;
  891. }
  892. if (!xpath)
  893. xpath = "/*";
  894. if (sr_get_data(sess, xpath, 0, 0, 0, &data2) != SR_ERR_OK) {
  895. srp_error(sess, ERRORMSG "Can't get specified subtree\n");
  896. goto err;
  897. }
  898. // Running config
  899. sr_session_switch_ds(sess, SR_DS_RUNNING);
  900. if (sr_get_data(sess, xpath, 0, 0, 0, &data1) != SR_ERR_OK) {
  901. srp_error(sess, ERRORMSG "Can't get specified subtree\n");
  902. goto err;
  903. }
  904. if (lyd_diff_siblings(data1 ? data1->tree : NULL, data2 ? data2->tree : NULL,
  905. 0, &diff) != LY_SUCCESS) {
  906. srp_error(sess, ERRORMSG "Can't generate diff\n");
  907. goto err;
  908. }
  909. // Hack to don't show oneliners within diff. Mask oneliners flag
  910. masked_opts = *srp_udata_opts(context);
  911. masked_opts.oneliners = BOOL_FALSE;
  912. show_subtree(diff, 0, DIFF_OP_NONE, &masked_opts, BOOL_FALSE);
  913. lyd_free_siblings(diff);
  914. ret = 0;
  915. err:
  916. if (data1)
  917. sr_release_data(data1);
  918. if (data2)
  919. sr_release_data(data2);
  920. pline_free(pline);
  921. sr_session_switch_ds(sess, SRP_REPO_EDIT);
  922. return ret;
  923. }
  924. int srp_compl_xpath(kcontext_t *context)
  925. {
  926. sr_session_ctx_t *sess = NULL;
  927. sr_val_t *vals = NULL;
  928. size_t val_num = 0;
  929. size_t i = 0;
  930. const char *script = NULL;
  931. const char *raw_xpath = NULL;
  932. sr_datastore_t ds = SRP_REPO_EDIT;
  933. assert(context);
  934. script = kcontext_script(context);
  935. if (faux_str_is_empty(script))
  936. return -1;
  937. if (!kly_parse_ext_xpath(script, &raw_xpath, &ds))
  938. return -1;
  939. sess = srp_udata_sr_sess(context);
  940. if (ds != SRP_REPO_EDIT)
  941. sr_session_switch_ds(sess, ds);
  942. sr_get_items(sess, raw_xpath, 0, 0, &vals, &val_num);
  943. for (i = 0; i < val_num; i++) {
  944. char *tmp = sr_val_to_str(&vals[i]);
  945. if (!tmp)
  946. continue;
  947. printf("%s\n", tmp);
  948. free(tmp);
  949. }
  950. sr_free_values(vals, val_num);
  951. if (ds != SRP_REPO_EDIT)
  952. sr_session_switch_ds(sess, SRP_REPO_EDIT);
  953. return 0;
  954. }
  955. // Function for mass operations.
  956. int srp_mass_op(char op, int fd, sr_datastore_t ds, const faux_argv_t *cur_path,
  957. const pline_opts_t *opts, const char *user, bool_t stop_on_error)
  958. {
  959. int ret = -1;
  960. int err = SR_ERR_OK;
  961. sr_conn_ctx_t *conn = NULL;
  962. sr_session_ctx_t *sess = NULL;
  963. faux_file_t *file = NULL;
  964. char *line = NULL;
  965. size_t err_num = 0;
  966. sr_subscription_ctx_t *nacm_sub = NULL;
  967. err = sr_connect(SR_CONN_DEFAULT, &conn);
  968. if (err) {
  969. fprintf(stderr, "Error: Can't connect to sysrepo\n");
  970. goto out;
  971. }
  972. err = sr_session_start(conn, ds, &sess);
  973. if (err) {
  974. fprintf(stderr, "Error: Can't start session\n");
  975. goto out;
  976. }
  977. sr_session_set_orig_name(sess, user);
  978. // Init NACM session
  979. if (opts->enable_nacm) {
  980. if (sr_nacm_init(sess, 0, &nacm_sub) != SR_ERR_OK) {
  981. fprintf(stderr, "Error: Can't init NACM\n");
  982. goto out;
  983. }
  984. sr_nacm_set_user(sess, user);
  985. }
  986. file = faux_file_fdopen(fd);
  987. if (!file) {
  988. fprintf(stderr, "Error: Can't open input stream\n");
  989. goto out;
  990. }
  991. while ((line = faux_file_getline(file))) {
  992. pline_t *pline = NULL;
  993. faux_argv_t *args = NULL;
  994. // Don't process empty strings and strings with only spaces
  995. if (!faux_str_has_content(line)) {
  996. faux_str_free(line);
  997. continue;
  998. }
  999. // Add current sysrepo path
  1000. if (cur_path)
  1001. args = faux_argv_dup(cur_path);
  1002. else
  1003. args = faux_argv_new();
  1004. faux_argv_parse(args, line);
  1005. pline = pline_parse(sess, args, opts);
  1006. faux_argv_free(args);
  1007. if (!pline || pline->invalid) {
  1008. err_num++;
  1009. fprintf(stderr, "Error: Illegal: %s\n", line);
  1010. } else {
  1011. faux_list_node_t *iter = NULL;
  1012. pexpr_t *expr = NULL;
  1013. iter = faux_list_head(pline->exprs);
  1014. while ((expr = (pexpr_t *)faux_list_each(&iter))) {
  1015. // Set
  1016. if (op == 's') {
  1017. if (!(expr->pat & PT_SET)) {
  1018. err_num++;
  1019. fprintf(stderr, "Error: Illegal expression"
  1020. " for set operation\n");
  1021. break;
  1022. }
  1023. if (sr_set_item_str(sess, expr->xpath,
  1024. expr->value, NULL, 0) != SR_ERR_OK) {
  1025. err_num++;
  1026. fprintf(stderr, "Error: Can't set data\n");
  1027. break;
  1028. }
  1029. // Del
  1030. } else if (op == 'd') {
  1031. if (!(expr->pat & PT_DEL)) {
  1032. err_num++;
  1033. fprintf(stderr, "Error: Illegal expression"
  1034. " for del operation\n");
  1035. break;
  1036. }
  1037. if (sr_delete_item(sess, expr->xpath, 0) !=
  1038. SR_ERR_OK) {
  1039. err_num++;
  1040. fprintf(stderr, "Error: Can't del data\n");
  1041. break;
  1042. }
  1043. } else {
  1044. err_num++;
  1045. fprintf(stderr, "Error: Illegal operation '%c'\n",
  1046. op);
  1047. break;
  1048. }
  1049. }
  1050. }
  1051. if (stop_on_error && (err_num > 0)) {
  1052. sr_discard_changes(sess);
  1053. goto out;
  1054. }
  1055. pline_free(pline);
  1056. faux_str_free(line);
  1057. }
  1058. if (sr_has_changes(sess)) {
  1059. if (sr_apply_changes(sess, 0) != SR_ERR_OK) {
  1060. sr_discard_changes(sess);
  1061. fprintf(stderr, "Error: Can't apply changes\n");
  1062. goto out;
  1063. }
  1064. }
  1065. ret = 0;
  1066. out:
  1067. faux_file_close(file);
  1068. if (opts->enable_nacm) {
  1069. sr_unsubscribe(nacm_sub);
  1070. sr_nacm_destroy();
  1071. }
  1072. sr_disconnect(conn);
  1073. return ret;
  1074. }
  1075. // Function for mass config strings load. It can load stream of KPath strings
  1076. // (without "set" command, only path and value). Function doesn't use
  1077. // pre-connected session because it can be executed within FILTER or utility.
  1078. int srp_mass_set(int fd, sr_datastore_t ds, const faux_argv_t *cur_path,
  1079. const pline_opts_t *opts, const char *user, bool_t stop_on_error)
  1080. {
  1081. return srp_mass_op('s', fd, ds, cur_path, opts, user, stop_on_error);
  1082. }
  1083. // Function for mass config strings deletion. It can get stream of KPath strings
  1084. // (without "del" command, only path). Function doesn't use
  1085. // pre-connected session because it can be executed within FILTER or utility.
  1086. int srp_mass_del(int fd, sr_datastore_t ds, const faux_argv_t *cur_path,
  1087. const pline_opts_t *opts, const char *user, bool_t stop_on_error)
  1088. {
  1089. return srp_mass_op('d', fd, ds, cur_path, opts, user, stop_on_error);
  1090. }