syms.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  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. assert(context);
  725. sess = srp_udata_sr_sess(context);
  726. if (ds != SRP_REPO_EDIT)
  727. sr_session_switch_ds(sess, ds);
  728. if (use_cur_path)
  729. cur_path = (faux_argv_t *)srp_udata_path(context);
  730. if (kpargv_find(kcontext_pargv(context), path_var) || cur_path) {
  731. args = param2argv(cur_path, kcontext_pargv(context), path_var);
  732. pline = pline_parse(sess, args, srp_udata_opts(context));
  733. faux_argv_free(args);
  734. if (pline->invalid) {
  735. fprintf(stderr, ERRORMSG "Invalid 'show' request\n");
  736. goto err;
  737. }
  738. if (faux_list_len(pline->exprs) > 1) {
  739. fprintf(stderr, ERRORMSG "Can't process more than one object\n");
  740. goto err;
  741. }
  742. if (!(expr = (pexpr_t *)faux_list_data(faux_list_head(pline->exprs)))) {
  743. fprintf(stderr, ERRORMSG "Can't get expression\n");
  744. goto err;
  745. }
  746. if (!(expr->pat & PT_SHOW)) {
  747. fprintf(stderr, ERRORMSG "Illegal expression for 'show' operation\n");
  748. goto err;
  749. }
  750. if (!expr->xpath) {
  751. fprintf(stderr, ERRORMSG "Empty expression for 'show' operation\n");
  752. goto err;
  753. }
  754. xpath = expr->xpath;
  755. }
  756. show_xpath(sess, xpath, srp_udata_opts(context));
  757. ret = 0;
  758. err:
  759. pline_free(pline);
  760. if (ds != SRP_REPO_EDIT)
  761. sr_session_switch_ds(sess, SRP_REPO_EDIT);
  762. return ret;
  763. }
  764. static int show_path(kcontext_t *context, bool_t use_cur_path)
  765. {
  766. sr_datastore_t ds = SRP_REPO_EDIT;
  767. const char *script = NULL;
  768. assert(context);
  769. script = kcontext_script(context);
  770. if (!faux_str_is_empty(script))
  771. if (!kly_str2ds(script, strlen(script), &ds))
  772. ds = SRP_REPO_EDIT;
  773. return show(context, ds, ARG_PATH, use_cur_path);
  774. }
  775. int srp_show_abs(kcontext_t *context)
  776. {
  777. return show_path(context, BOOL_FALSE);
  778. }
  779. int srp_show(kcontext_t *context)
  780. {
  781. return show_path(context, BOOL_TRUE);
  782. }
  783. int srp_deactivate(kcontext_t *context)
  784. {
  785. int ret = -1;
  786. faux_argv_t *args = NULL;
  787. pline_t *pline = NULL;
  788. sr_session_ctx_t *sess = NULL;
  789. pexpr_t *expr = NULL;
  790. faux_argv_t *cur_path = NULL;
  791. sr_data_t *data = NULL;
  792. assert(context);
  793. sess = srp_udata_sr_sess(context);
  794. cur_path = (faux_argv_t *)srp_udata_path(context);
  795. args = param2argv(cur_path, kcontext_pargv(context), ARG_PATH);
  796. pline = pline_parse(sess, args, srp_udata_opts(context));
  797. faux_argv_free(args);
  798. if (pline->invalid) {
  799. fprintf(stderr, ERRORMSG "Invalid 'show' request\n");
  800. goto err;
  801. }
  802. if (faux_list_len(pline->exprs) > 1) {
  803. fprintf(stderr, ERRORMSG "Can't process more than one object\n");
  804. goto err;
  805. }
  806. expr = (pexpr_t *)faux_list_data(faux_list_head(pline->exprs));
  807. if (!(expr->pat & PT_DEL)) {
  808. fprintf(stderr, ERRORMSG "Illegal expression for 'show' operation\n");
  809. goto err;
  810. }
  811. if (sr_get_subtree(sess, expr->xpath, 0, &data) != SR_ERR_OK) {
  812. srp_error(sess, ERRORMSG "Can't get specified subtree\n");
  813. goto err;
  814. }
  815. if (!data) // Not found
  816. goto err;
  817. if (lyd_new_meta(LYD_CTX(data->tree), data->tree, NULL,
  818. "junos-configuration-metadata:active", "false", 0, NULL)) {
  819. fprintf(stderr, ERRORMSG "Can't deactivate\n");
  820. goto err;
  821. }
  822. struct lyd_meta *meta = lyd_find_meta(data->tree->meta, NULL, "junos-configuration-metadata:active");
  823. if (meta)
  824. printf("META\n");
  825. if (sr_has_changes(sess))
  826. fprintf(stderr, ERRORMSG "Has changes\n");
  827. if (sr_apply_changes(sess, 0) != SR_ERR_OK) {
  828. sr_discard_changes(sess);
  829. srp_error(sess, ERRORMSG "Can't apply changes\n");
  830. }
  831. sr_release_data(data);
  832. if (sr_get_subtree(sess, expr->xpath, 0, &data) != SR_ERR_OK) {
  833. srp_error(sess, ERRORMSG "Can't get specified subtree\n");
  834. goto err;
  835. }
  836. if (!data) // Not found
  837. goto err;
  838. struct ly_out *out = NULL;
  839. ly_out_new_file(stdout, &out);
  840. lyd_print_tree(out, data->tree, LYD_XML, 0);
  841. ly_out_free(out, NULL, 0);
  842. sr_release_data(data);
  843. ret = 0;
  844. err:
  845. pline_free(pline);
  846. return ret;
  847. }
  848. int srp_diff(kcontext_t *context)
  849. {
  850. int ret = -1;
  851. pline_t *pline = NULL;
  852. sr_session_ctx_t *sess = NULL;
  853. sr_data_t *data1 = NULL;
  854. sr_data_t *data2 = NULL;
  855. faux_argv_t *cur_path = NULL;
  856. const char *xpath = NULL;
  857. struct lyd_node *diff = NULL;
  858. pline_opts_t masked_opts = {};
  859. assert(context);
  860. sess = srp_udata_sr_sess(context);
  861. cur_path = (faux_argv_t *)srp_udata_path(context);
  862. if (kpargv_find(kcontext_pargv(context), ARG_PATH) || cur_path) {
  863. faux_argv_t *args = NULL;
  864. pexpr_t *expr = NULL;
  865. args = param2argv(cur_path, kcontext_pargv(context), ARG_PATH);
  866. pline = pline_parse(sess, args, srp_udata_opts(context));
  867. faux_argv_free(args);
  868. if (pline->invalid) {
  869. fprintf(stderr, ERRORMSG "Invalid 'show' request\n");
  870. goto err;
  871. }
  872. if (faux_list_len(pline->exprs) > 1) {
  873. fprintf(stderr, ERRORMSG "Can't process more than one object\n");
  874. goto err;
  875. }
  876. if (!(expr = (pexpr_t *)faux_list_data(faux_list_head(pline->exprs)))) {
  877. fprintf(stderr, ERRORMSG "Can't get expression\n");
  878. goto err;
  879. }
  880. if (!(expr->pat & PT_EDIT)) {
  881. fprintf(stderr, ERRORMSG "Illegal expression for 'show' operation\n");
  882. goto err;
  883. }
  884. if (!expr->xpath) {
  885. fprintf(stderr, ERRORMSG "Empty expression for 'show' operation\n");
  886. goto err;
  887. }
  888. xpath = expr->xpath;
  889. }
  890. if (!xpath)
  891. xpath = "/*";
  892. if (sr_get_data(sess, xpath, 0, 0, 0, &data2) != SR_ERR_OK) {
  893. srp_error(sess, ERRORMSG "Can't get specified subtree\n");
  894. goto err;
  895. }
  896. // Running config
  897. sr_session_switch_ds(sess, SR_DS_RUNNING);
  898. if (sr_get_data(sess, xpath, 0, 0, 0, &data1) != SR_ERR_OK) {
  899. srp_error(sess, ERRORMSG "Can't get specified subtree\n");
  900. goto err;
  901. }
  902. if (lyd_diff_siblings(data1 ? data1->tree : NULL, data2 ? data2->tree : NULL,
  903. 0, &diff) != LY_SUCCESS) {
  904. srp_error(sess, ERRORMSG "Can't generate diff\n");
  905. goto err;
  906. }
  907. // Hack to don't show oneliners within diff. Mask oneliners flag
  908. masked_opts = *srp_udata_opts(context);
  909. masked_opts.oneliners = BOOL_FALSE;
  910. show_subtree(diff, 0, DIFF_OP_NONE, &masked_opts, BOOL_FALSE);
  911. lyd_free_siblings(diff);
  912. ret = 0;
  913. err:
  914. if (data1)
  915. sr_release_data(data1);
  916. if (data2)
  917. sr_release_data(data2);
  918. pline_free(pline);
  919. sr_session_switch_ds(sess, SRP_REPO_EDIT);
  920. return ret;
  921. }
  922. int srp_compl_xpath(kcontext_t *context)
  923. {
  924. sr_session_ctx_t *sess = NULL;
  925. sr_val_t *vals = NULL;
  926. size_t val_num = 0;
  927. size_t i = 0;
  928. const char *script = NULL;
  929. const char *raw_xpath = NULL;
  930. sr_datastore_t ds = SRP_REPO_EDIT;
  931. assert(context);
  932. script = kcontext_script(context);
  933. if (faux_str_is_empty(script))
  934. return -1;
  935. if (!kly_parse_ext_xpath(script, &raw_xpath, &ds))
  936. return -1;
  937. sess = srp_udata_sr_sess(context);
  938. if (ds != SRP_REPO_EDIT)
  939. sr_session_switch_ds(sess, ds);
  940. sr_get_items(sess, raw_xpath, 0, 0, &vals, &val_num);
  941. for (i = 0; i < val_num; i++) {
  942. char *tmp = sr_val_to_str(&vals[i]);
  943. if (!tmp)
  944. continue;
  945. printf("%s\n", tmp);
  946. free(tmp);
  947. }
  948. sr_free_values(vals, val_num);
  949. if (ds != SRP_REPO_EDIT)
  950. sr_session_switch_ds(sess, SRP_REPO_EDIT);
  951. return 0;
  952. }
  953. // Function for mass operations.
  954. int srp_mass_op(char op, int fd, sr_datastore_t ds, const faux_argv_t *cur_path,
  955. const pline_opts_t *opts, const char *user, bool_t stop_on_error)
  956. {
  957. int ret = -1;
  958. int err = SR_ERR_OK;
  959. sr_conn_ctx_t *conn = NULL;
  960. sr_session_ctx_t *sess = NULL;
  961. faux_file_t *file = NULL;
  962. char *line = NULL;
  963. size_t err_num = 0;
  964. sr_subscription_ctx_t *nacm_sub = NULL;
  965. err = sr_connect(SR_CONN_DEFAULT, &conn);
  966. if (err) {
  967. fprintf(stderr, "Error: Can't connect to sysrepo\n");
  968. goto out;
  969. }
  970. err = sr_session_start(conn, ds, &sess);
  971. if (err) {
  972. fprintf(stderr, "Error: Can't start session\n");
  973. goto out;
  974. }
  975. sr_session_set_orig_name(sess, user);
  976. // Init NACM session
  977. if (opts->enable_nacm) {
  978. if (sr_nacm_init(sess, 0, &nacm_sub) != SR_ERR_OK) {
  979. fprintf(stderr, "Error: Can't init NACM\n");
  980. goto out;
  981. }
  982. sr_nacm_set_user(sess, user);
  983. }
  984. file = faux_file_fdopen(fd);
  985. if (!file) {
  986. fprintf(stderr, "Error: Can't open input stream\n");
  987. goto out;
  988. }
  989. while ((line = faux_file_getline(file))) {
  990. pline_t *pline = NULL;
  991. faux_argv_t *args = NULL;
  992. // Don't process empty strings and strings with only spaces
  993. if (!faux_str_has_content(line)) {
  994. faux_str_free(line);
  995. continue;
  996. }
  997. // Add current sysrepo path
  998. if (cur_path)
  999. args = faux_argv_dup(cur_path);
  1000. else
  1001. args = faux_argv_new();
  1002. faux_argv_parse(args, line);
  1003. pline = pline_parse(sess, args, opts);
  1004. faux_argv_free(args);
  1005. if (!pline || pline->invalid) {
  1006. err_num++;
  1007. fprintf(stderr, "Error: Illegal: %s\n", line);
  1008. } else {
  1009. faux_list_node_t *iter = NULL;
  1010. pexpr_t *expr = NULL;
  1011. iter = faux_list_head(pline->exprs);
  1012. while ((expr = (pexpr_t *)faux_list_each(&iter))) {
  1013. // Set
  1014. if (op == 's') {
  1015. if (!(expr->pat & PT_SET)) {
  1016. err_num++;
  1017. fprintf(stderr, "Error: Illegal expression"
  1018. " for set operation\n");
  1019. break;
  1020. }
  1021. if (sr_set_item_str(sess, expr->xpath,
  1022. expr->value, NULL, 0) != SR_ERR_OK) {
  1023. err_num++;
  1024. fprintf(stderr, "Error: Can't set data\n");
  1025. break;
  1026. }
  1027. // Del
  1028. } else if (op == 'd') {
  1029. if (!(expr->pat & PT_DEL)) {
  1030. err_num++;
  1031. fprintf(stderr, "Error: Illegal expression"
  1032. " for del operation\n");
  1033. break;
  1034. }
  1035. if (sr_delete_item(sess, expr->xpath, 0) !=
  1036. SR_ERR_OK) {
  1037. err_num++;
  1038. fprintf(stderr, "Error: Can't del data\n");
  1039. break;
  1040. }
  1041. } else {
  1042. err_num++;
  1043. fprintf(stderr, "Error: Illegal operation '%c'\n",
  1044. op);
  1045. break;
  1046. }
  1047. }
  1048. }
  1049. if (stop_on_error && (err_num > 0)) {
  1050. sr_discard_changes(sess);
  1051. goto out;
  1052. }
  1053. pline_free(pline);
  1054. faux_str_free(line);
  1055. }
  1056. if (sr_has_changes(sess)) {
  1057. if (sr_apply_changes(sess, 0) != SR_ERR_OK) {
  1058. sr_discard_changes(sess);
  1059. fprintf(stderr, "Error: Can't apply changes\n");
  1060. goto out;
  1061. }
  1062. }
  1063. ret = 0;
  1064. out:
  1065. faux_file_close(file);
  1066. if (opts->enable_nacm) {
  1067. sr_unsubscribe(nacm_sub);
  1068. sr_nacm_destroy();
  1069. }
  1070. sr_disconnect(conn);
  1071. return ret;
  1072. }
  1073. // Function for mass config strings load. It can load stream of KPath strings
  1074. // (without "set" command, only path and value). Function doesn't use
  1075. // pre-connected session because it can be executed within FILTER or utility.
  1076. int srp_mass_set(int fd, sr_datastore_t ds, const faux_argv_t *cur_path,
  1077. const pline_opts_t *opts, const char *user, bool_t stop_on_error)
  1078. {
  1079. return srp_mass_op('s', fd, ds, cur_path, opts, user, stop_on_error);
  1080. }
  1081. // Function for mass config strings deletion. It can get stream of KPath strings
  1082. // (without "del" command, only path). Function doesn't use
  1083. // pre-connected session because it can be executed within FILTER or utility.
  1084. int srp_mass_del(int fd, sr_datastore_t ds, const faux_argv_t *cur_path,
  1085. const pline_opts_t *opts, const char *user, bool_t stop_on_error)
  1086. {
  1087. return srp_mass_op('d', fd, ds, cur_path, opts, user, stop_on_error);
  1088. }