blob: 27812d2d0e2fd6a2bc8cb2f0d9d101fdea702743 [file] [log] [blame]
Michal Vasko7bcb48e2016-01-15 10:28:54 +01001/**
2 * \file messages.c
3 * \author Radek Krejci <rkrejci@cesnet.cz>
4 * \brief libnetconf2 - NETCONF messages functions
5 *
Michal Vasko96f247a2021-03-15 13:32:10 +01006 * Copyright (c) 2015 - 2021 CESNET, z.s.p.o.
Michal Vasko7bcb48e2016-01-15 10:28:54 +01007 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +01008 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
Michal Vaskoafd416b2016-02-25 14:51:46 +010011 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +010012 * https://opensource.org/licenses/BSD-3-Clause
Michal Vasko7bcb48e2016-01-15 10:28:54 +010013 */
14
Radek Krejci36d2ee42017-10-13 13:55:59 +020015#include <assert.h>
Michal Vasko7bcb48e2016-01-15 10:28:54 +010016#include <ctype.h>
Michal Vaskob83a3fa2021-05-26 09:53:42 +020017#include <stdarg.h>
Michal Vasko7bcb48e2016-01-15 10:28:54 +010018#include <stdlib.h>
19#include <string.h>
Michal Vasko7bcb48e2016-01-15 10:28:54 +010020
21#include <libyang/libyang.h>
22
23#include "libnetconf.h"
Michal Vasko7bcb48e2016-01-15 10:28:54 +010024
25const char *rpcedit_dfltop2str[] = {NULL, "merge", "replace", "none"};
26const char *rpcedit_testopt2str[] = {NULL, "test-then-set", "set", "test-only"};
27const char *rpcedit_erropt2str[] = {NULL, "stop-on-error", "continue-on-error", "rollback-on-error"};
28
29API NC_RPC_TYPE
30nc_rpc_get_type(const struct nc_rpc *rpc)
31{
Michal Vasko7f1c78b2016-01-19 09:52:14 +010032 if (!rpc) {
Michal Vasko45e53ae2016-04-07 11:46:03 +020033 ERRARG("rpc");
Michal Vasko7f1c78b2016-01-19 09:52:14 +010034 return 0;
35 }
36
Michal Vasko7bcb48e2016-01-15 10:28:54 +010037 return rpc->type;
38}
39
40API struct nc_rpc *
Michal Vasko90e8e692016-07-13 12:27:57 +020041nc_rpc_act_generic(const struct lyd_node *data, NC_PARAMTYPE paramtype)
Michal Vasko7bcb48e2016-01-15 10:28:54 +010042{
Michal Vasko90e8e692016-07-13 12:27:57 +020043 struct nc_rpc_act_generic *rpc;
Michal Vasko7bcb48e2016-01-15 10:28:54 +010044
Michal Vasko90e8e692016-07-13 12:27:57 +020045 if (!data || data->next || (data->prev != data)) {
Michal Vasko45e53ae2016-04-07 11:46:03 +020046 ERRARG("data");
Michal Vasko7f1c78b2016-01-19 09:52:14 +010047 return NULL;
48 }
49
Michal Vasko7bcb48e2016-01-15 10:28:54 +010050 rpc = malloc(sizeof *rpc);
51 if (!rpc) {
52 ERRMEM;
53 return NULL;
54 }
55
Michal Vasko90e8e692016-07-13 12:27:57 +020056 rpc->type = NC_RPC_ACT_GENERIC;
Michal Vasko7bcb48e2016-01-15 10:28:54 +010057 rpc->has_data = 1;
58 if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
Michal Vasko77367452021-02-16 16:32:18 +010059 if (lyd_dup_single(data, NULL, LYD_DUP_RECURSIVE, &rpc->content.data)) {
60 free(rpc);
61 return NULL;
62 }
Michal Vasko7bcb48e2016-01-15 10:28:54 +010063 } else {
64 rpc->content.data = (struct lyd_node *)data;
65 }
66 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
67
68 return (struct nc_rpc *)rpc;
69}
70
71API struct nc_rpc *
Michal Vasko90e8e692016-07-13 12:27:57 +020072nc_rpc_act_generic_xml(const char *xml_str, NC_PARAMTYPE paramtype)
Michal Vasko7bcb48e2016-01-15 10:28:54 +010073{
Michal Vasko90e8e692016-07-13 12:27:57 +020074 struct nc_rpc_act_generic *rpc;
Michal Vasko7bcb48e2016-01-15 10:28:54 +010075
Michal Vasko7f1c78b2016-01-19 09:52:14 +010076 if (!xml_str) {
Michal Vasko45e53ae2016-04-07 11:46:03 +020077 ERRARG("xml_str");
Michal Vasko7f1c78b2016-01-19 09:52:14 +010078 return NULL;
79 }
80
Michal Vasko7bcb48e2016-01-15 10:28:54 +010081 rpc = malloc(sizeof *rpc);
82 if (!rpc) {
83 ERRMEM;
84 return NULL;
85 }
86
Michal Vasko90e8e692016-07-13 12:27:57 +020087 rpc->type = NC_RPC_ACT_GENERIC;
Michal Vasko7bcb48e2016-01-15 10:28:54 +010088 rpc->has_data = 0;
89 if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
90 rpc->content.xml_str = strdup(xml_str);
91 } else {
92 rpc->content.xml_str = (char *)xml_str;
93 }
94 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
95
96 return (struct nc_rpc *)rpc;
97}
98
99API struct nc_rpc *
100nc_rpc_getconfig(NC_DATASTORE source, const char *filter, NC_WD_MODE wd_mode, NC_PARAMTYPE paramtype)
101{
102 struct nc_rpc_getconfig *rpc;
103
Michal Vasko7f1c78b2016-01-19 09:52:14 +0100104 if (!source) {
Michal Vasko45e53ae2016-04-07 11:46:03 +0200105 ERRARG("source");
Michal Vasko7f1c78b2016-01-19 09:52:14 +0100106 return NULL;
107 }
108
Michal Vaskof3c647b2016-03-08 12:17:33 +0100109 if (filter && filter[0] && (filter[0] != '<') && (filter[0] != '/') && !isalpha(filter[0])) {
Michal Vasko7793bc62016-09-16 11:58:41 +0200110 ERR("Filter is neither an XML subtree nor an XPath expression (invalid first char '%c').", filter[0]);
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100111 return NULL;
112 }
113
114 rpc = malloc(sizeof *rpc);
115 if (!rpc) {
116 ERRMEM;
117 return NULL;
118 }
119
120 rpc->type = NC_RPC_GETCONFIG;
121 rpc->source = source;
122 if (filter && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
123 rpc->filter = strdup(filter);
124 } else {
125 rpc->filter = (char *)filter;
126 }
127 rpc->wd_mode = wd_mode;
128 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
129
130 return (struct nc_rpc *)rpc;
131}
132
133API struct nc_rpc *
134nc_rpc_edit(NC_DATASTORE target, NC_RPC_EDIT_DFLTOP default_op, NC_RPC_EDIT_TESTOPT test_opt,
Michal Vasko96f247a2021-03-15 13:32:10 +0100135 NC_RPC_EDIT_ERROPT error_opt, const char *edit_content, NC_PARAMTYPE paramtype)
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100136{
137 struct nc_rpc_edit *rpc;
138
Michal Vasko45e53ae2016-04-07 11:46:03 +0200139 if (!target) {
140 ERRARG("target");
141 return NULL;
142 } else if (!edit_content) {
143 ERRARG("edit_content");
Michal Vasko7f1c78b2016-01-19 09:52:14 +0100144 return NULL;
145 }
146
Michal Vasko7793bc62016-09-16 11:58:41 +0200147 if (edit_content[0] && (edit_content[0] != '<') && !isalpha(edit_content[0])) {
148 ERR("<edit-config> content is neither a URL nor an XML config (invalid first char '%c').", edit_content[0]);
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100149 return NULL;
150 }
151
152 rpc = malloc(sizeof *rpc);
153 if (!rpc) {
154 ERRMEM;
155 return NULL;
156 }
157
158 rpc->type = NC_RPC_EDIT;
159 rpc->target = target;
160 rpc->default_op = default_op;
161 rpc->test_opt = test_opt;
162 rpc->error_opt = error_opt;
163 if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
164 rpc->edit_cont = strdup(edit_content);
165 } else {
166 rpc->edit_cont = (char *)edit_content;
167 }
168 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
169
170 return (struct nc_rpc *)rpc;
171}
172
173API struct nc_rpc *
174nc_rpc_copy(NC_DATASTORE target, const char *url_trg, NC_DATASTORE source, const char *url_or_config_src,
Michal Vasko96f247a2021-03-15 13:32:10 +0100175 NC_WD_MODE wd_mode, NC_PARAMTYPE paramtype)
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100176{
177 struct nc_rpc_copy *rpc;
178
Michal Vasko45e53ae2016-04-07 11:46:03 +0200179 if (!target) {
180 ERRARG("target");
181 return NULL;
182 } else if (!source) {
183 ERRARG("source");
Michal Vasko7f1c78b2016-01-19 09:52:14 +0100184 return NULL;
185 }
186
Michal Vasko7793bc62016-09-16 11:58:41 +0200187 if (url_or_config_src && url_or_config_src[0] && (url_or_config_src[0] != '<') && !isalpha(url_or_config_src[0])) {
Michal Vasko45e53ae2016-04-07 11:46:03 +0200188 ERR("<copy-config> source is neither a URL nor an XML config (invalid first char '%c').", url_or_config_src[0]);
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100189 return NULL;
190 }
191
192 rpc = malloc(sizeof *rpc);
193 if (!rpc) {
194 ERRMEM;
195 return NULL;
196 }
197
198 rpc->type = NC_RPC_COPY;
199 rpc->target = target;
200 if (url_trg && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
201 rpc->url_trg = strdup(url_trg);
202 } else {
203 rpc->url_trg = (char *)url_trg;
204 }
205 rpc->source = source;
206 if (url_or_config_src && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
207 rpc->url_config_src = strdup(url_or_config_src);
208 } else {
209 rpc->url_config_src = (char *)url_or_config_src;
210 }
211 rpc->wd_mode = wd_mode;
212 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
213
214 return (struct nc_rpc *)rpc;
215}
216
217API struct nc_rpc *
218nc_rpc_delete(NC_DATASTORE target, const char *url, NC_PARAMTYPE paramtype)
219{
220 struct nc_rpc_delete *rpc;
221
Michal Vasko7f1c78b2016-01-19 09:52:14 +0100222 if (!target) {
Michal Vasko45e53ae2016-04-07 11:46:03 +0200223 ERRARG("target");
Michal Vasko7f1c78b2016-01-19 09:52:14 +0100224 return NULL;
225 }
226
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100227 rpc = malloc(sizeof *rpc);
228 if (!rpc) {
229 ERRMEM;
230 return NULL;
231 }
232
233 rpc->type = NC_RPC_DELETE;
234 rpc->target = target;
235 if (url && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
236 rpc->url = strdup(url);
237 } else {
238 rpc->url = (char *)url;
239 }
240 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
241
242 return (struct nc_rpc *)rpc;
243}
244
245API struct nc_rpc *
246nc_rpc_lock(NC_DATASTORE target)
247{
248 struct nc_rpc_lock *rpc;
249
Michal Vasko7f1c78b2016-01-19 09:52:14 +0100250 if (!target) {
Michal Vasko45e53ae2016-04-07 11:46:03 +0200251 ERRARG("target");
Michal Vasko7f1c78b2016-01-19 09:52:14 +0100252 return NULL;
253 }
254
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100255 rpc = malloc(sizeof *rpc);
256 if (!rpc) {
257 ERRMEM;
258 return NULL;
259 }
260
261 rpc->type = NC_RPC_LOCK;
262 rpc->target = target;
263
264 return (struct nc_rpc *)rpc;
265}
266
267API struct nc_rpc *
268nc_rpc_unlock(NC_DATASTORE target)
269{
270 struct nc_rpc_lock *rpc;
271
Michal Vasko7f1c78b2016-01-19 09:52:14 +0100272 if (!target) {
Michal Vasko45e53ae2016-04-07 11:46:03 +0200273 ERRARG("target");
Michal Vasko7f1c78b2016-01-19 09:52:14 +0100274 return NULL;
275 }
276
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100277 rpc = malloc(sizeof *rpc);
278 if (!rpc) {
279 ERRMEM;
280 return NULL;
281 }
282
283 rpc->type = NC_RPC_UNLOCK;
284 rpc->target = target;
285
286 return (struct nc_rpc *)rpc;
287}
288
289API struct nc_rpc *
290nc_rpc_get(const char *filter, NC_WD_MODE wd_mode, NC_PARAMTYPE paramtype)
291{
292 struct nc_rpc_get *rpc;
293
Michal Vaskof3c647b2016-03-08 12:17:33 +0100294 if (filter && filter[0] && (filter[0] != '<') && (filter[0] != '/') && !isalpha(filter[0])) {
Michal Vasko7793bc62016-09-16 11:58:41 +0200295 ERR("Filter is neither an XML subtree nor an XPath expression (invalid first char '%c').", filter[0]);
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100296 return NULL;
297 }
298
299 rpc = malloc(sizeof *rpc);
300 if (!rpc) {
301 ERRMEM;
302 return NULL;
303 }
304
305 rpc->type = NC_RPC_GET;
306 if (filter && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
307 rpc->filter = strdup(filter);
308 } else {
309 rpc->filter = (char *)filter;
310 }
311 rpc->wd_mode = wd_mode;
312 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
313
314 return (struct nc_rpc *)rpc;
315}
316
317API struct nc_rpc *
318nc_rpc_kill(uint32_t session_id)
319{
320 struct nc_rpc_kill *rpc;
321
Michal Vasko7f1c78b2016-01-19 09:52:14 +0100322 if (!session_id) {
Michal Vasko45e53ae2016-04-07 11:46:03 +0200323 ERRARG("session_id");
Michal Vasko7f1c78b2016-01-19 09:52:14 +0100324 return NULL;
325 }
326
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100327 rpc = malloc(sizeof *rpc);
328 if (!rpc) {
329 ERRMEM;
330 return NULL;
331 }
332
333 rpc->type = NC_RPC_KILL;
334 rpc->sid = session_id;
335
336 return (struct nc_rpc *)rpc;
337}
338
339API struct nc_rpc *
340nc_rpc_commit(int confirmed, uint32_t confirm_timeout, const char *persist, const char *persist_id,
Michal Vasko96f247a2021-03-15 13:32:10 +0100341 NC_PARAMTYPE paramtype)
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100342{
343 struct nc_rpc_commit *rpc;
344
345 rpc = malloc(sizeof *rpc);
346 if (!rpc) {
347 ERRMEM;
348 return NULL;
349 }
350
351 rpc->type = NC_RPC_COMMIT;
352 rpc->confirmed = confirmed;
353 rpc->confirm_timeout = confirm_timeout;
354 if (persist && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
355 rpc->persist = strdup(persist);
356 } else {
357 rpc->persist = (char *)persist;
358 }
359 if (persist_id && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
360 rpc->persist_id = strdup(persist_id);
361 } else {
362 rpc->persist_id = (char *)persist_id;
363 }
364 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
365
366 return (struct nc_rpc *)rpc;
367}
368
369API struct nc_rpc *
370nc_rpc_discard(void)
371{
372 struct nc_rpc *rpc;
373
374 rpc = malloc(sizeof *rpc);
375 if (!rpc) {
376 ERRMEM;
377 return NULL;
378 }
379
380 rpc->type = NC_RPC_DISCARD;
381
382 return rpc;
383}
384
385API struct nc_rpc *
386nc_rpc_cancel(const char *persist_id, NC_PARAMTYPE paramtype)
387{
388 struct nc_rpc_cancel *rpc;
389
390 rpc = malloc(sizeof *rpc);
391 if (!rpc) {
392 ERRMEM;
393 return NULL;
394 }
395
396 rpc->type = NC_RPC_CANCEL;
397 if (persist_id && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
398 rpc->persist_id = strdup(persist_id);
399 } else {
400 rpc->persist_id = (char *)persist_id;
401 }
402 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
403
404 return (struct nc_rpc *)rpc;
405}
406
407API struct nc_rpc *
408nc_rpc_validate(NC_DATASTORE source, const char *url_or_config, NC_PARAMTYPE paramtype)
409{
410 struct nc_rpc_validate *rpc;
411
Michal Vasko7f1c78b2016-01-19 09:52:14 +0100412 if (!source) {
Michal Vasko45e53ae2016-04-07 11:46:03 +0200413 ERRARG("source");
Michal Vasko7f1c78b2016-01-19 09:52:14 +0100414 return NULL;
415 }
416
Michal Vasko7793bc62016-09-16 11:58:41 +0200417 if (url_or_config && url_or_config[0] && (url_or_config[0] != '<') && !isalpha(url_or_config[0])) {
Michal Vasko45e53ae2016-04-07 11:46:03 +0200418 ERR("<validate> source is neither a URL nor an XML config (invalid first char '%c').", url_or_config[0]);
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100419 return NULL;
420 }
421
422 rpc = malloc(sizeof *rpc);
423 if (!rpc) {
424 ERRMEM;
425 return NULL;
426 }
427
428 rpc->type = NC_RPC_VALIDATE;
429 rpc->source = source;
430 if (url_or_config && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
431 rpc->url_config_src = strdup(url_or_config);
432 } else {
433 rpc->url_config_src = (char *)url_or_config;
434 }
435 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
436
437 return (struct nc_rpc *)rpc;
438}
439
440API struct nc_rpc *
441nc_rpc_getschema(const char *identifier, const char *version, const char *format, NC_PARAMTYPE paramtype)
442{
443 struct nc_rpc_getschema *rpc;
444
Michal Vasko7f1c78b2016-01-19 09:52:14 +0100445 if (!identifier) {
Michal Vasko45e53ae2016-04-07 11:46:03 +0200446 ERRARG("identifier");
Michal Vasko7f1c78b2016-01-19 09:52:14 +0100447 return NULL;
448 }
449
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100450 rpc = malloc(sizeof *rpc);
451 if (!rpc) {
452 ERRMEM;
453 return NULL;
454 }
455
456 rpc->type = NC_RPC_GETSCHEMA;
457 if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
458 rpc->identifier = strdup(identifier);
459 } else {
460 rpc->identifier = (char *)identifier;
461 }
462 if (version && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
463 rpc->version = strdup(version);
464 } else {
465 rpc->version = (char *)version;
466 }
467 if (format && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
468 rpc->format = strdup(format);
469 } else {
470 rpc->format = (char *)format;
471 }
472 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
473
474 return (struct nc_rpc *)rpc;
475}
476
477API struct nc_rpc *
478nc_rpc_subscribe(const char *stream_name, const char *filter, const char *start_time, const char *stop_time,
Michal Vasko96f247a2021-03-15 13:32:10 +0100479 NC_PARAMTYPE paramtype)
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100480{
481 struct nc_rpc_subscribe *rpc;
482
Michal Vaskof3c647b2016-03-08 12:17:33 +0100483 if (filter && filter[0] && (filter[0] != '<') && (filter[0] != '/') && !isalpha(filter[0])) {
Michal Vasko7793bc62016-09-16 11:58:41 +0200484 ERR("Filter is neither an XML subtree nor an XPath expression (invalid first char '%c').", filter[0]);
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100485 return NULL;
486 }
487
488 rpc = malloc(sizeof *rpc);
489 if (!rpc) {
490 ERRMEM;
491 return NULL;
492 }
493
494 rpc->type = NC_RPC_SUBSCRIBE;
495 if (stream_name && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
496 rpc->stream = strdup(stream_name);
497 } else {
498 rpc->stream = (char *)stream_name;
499 }
500 if (filter && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
501 rpc->filter = strdup(filter);
502 } else {
503 rpc->filter = (char *)filter;
504 }
505 if (start_time && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
506 rpc->start = strdup(start_time);
507 } else {
508 rpc->start = (char *)start_time;
509 }
510 if (stop_time && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
511 rpc->stop = strdup(stop_time);
512 } else {
513 rpc->stop = (char *)stop_time;
514 }
515 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
516
517 return (struct nc_rpc *)rpc;
518}
519
Michal Vaskoc1171a42019-11-05 12:06:46 +0100520API struct nc_rpc *
521nc_rpc_getdata(const char *datastore, const char *filter, const char *config_filter, char **origin_filter,
Michal Vasko96f247a2021-03-15 13:32:10 +0100522 int origin_filter_count, int negated_origin_filter, uint16_t max_depth, int with_origin, NC_WD_MODE wd_mode,
523 NC_PARAMTYPE paramtype)
Michal Vaskoc1171a42019-11-05 12:06:46 +0100524{
525 struct nc_rpc_getdata *rpc = NULL;
526 int i;
527
528 if (filter && filter[0] && (filter[0] != '<') && (filter[0] != '/') && !isalpha(filter[0])) {
529 ERR("Filter is neither an XML subtree nor an XPath expression (invalid first char '%c').", filter[0]);
530 return NULL;
531 } else if (!datastore) {
532 ERRARG("datastore");
533 return NULL;
534 }
535
536 rpc = calloc(1, sizeof *rpc);
537 if (!rpc) {
538 ERRMEM;
539 return NULL;
540 }
541 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
542
543 rpc->type = NC_RPC_GETDATA;
544 if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
545 rpc->datastore = strdup(datastore);
546 } else {
547 rpc->datastore = (char *)datastore;
548 }
549 if (filter && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
550 rpc->filter = strdup(filter);
551 } else {
552 rpc->filter = (char *)filter;
553 }
554 if (config_filter && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
555 rpc->config_filter = strdup(config_filter);
556 } else {
557 rpc->config_filter = (char *)config_filter;
558 }
559 if (origin_filter && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
560 rpc->origin_filter = malloc(origin_filter_count * sizeof *rpc->origin_filter);
561 if (!rpc->origin_filter) {
562 ERRMEM;
563 goto error;
564 }
565 for (i = 0; i < origin_filter_count; ++i) {
566 rpc->origin_filter[i] = strdup(origin_filter[i]);
567 if (!rpc->origin_filter[i]) {
568 ERRMEM;
569 goto error;
570 }
571 ++rpc->origin_filter_count;
572 }
573 } else {
574 rpc->origin_filter = origin_filter;
575 rpc->origin_filter_count = origin_filter_count;
576 }
577 rpc->negated_origin_filter = negated_origin_filter;
578 rpc->max_depth = max_depth;
579 rpc->with_origin = with_origin;
580 rpc->wd_mode = wd_mode;
581
582 return (struct nc_rpc *)rpc;
583
584error:
585 nc_rpc_free((struct nc_rpc *)rpc);
586 return NULL;
587}
588
589API struct nc_rpc *
590nc_rpc_editdata(const char *datastore, NC_RPC_EDIT_DFLTOP default_op, const char *edit_content, NC_PARAMTYPE paramtype)
591{
592 struct nc_rpc_editdata *rpc;
593
594 if (!datastore) {
595 ERRARG("datastore");
596 return NULL;
597 } else if (!edit_content) {
598 ERRARG("edit_content");
599 return NULL;
600 }
601
602 if (edit_content[0] && (edit_content[0] != '<') && !isalpha(edit_content[0])) {
603 ERR("<edit-data> content is neither a URL nor an XML config (invalid first char '%c').", edit_content[0]);
604 return NULL;
605 }
606
607 rpc = malloc(sizeof *rpc);
608 if (!rpc) {
609 ERRMEM;
610 return NULL;
611 }
612
613 rpc->type = NC_RPC_EDITDATA;
614 if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
615 rpc->datastore = strdup(datastore);
616 } else {
617 rpc->datastore = (char *)datastore;
618 }
619 rpc->default_op = default_op;
620 if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
621 rpc->edit_cont = strdup(edit_content);
622 } else {
623 rpc->edit_cont = (char *)edit_content;
624 }
625 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
626
627 return (struct nc_rpc *)rpc;
628}
629
Michal Vasko96f247a2021-03-15 13:32:10 +0100630API struct nc_rpc *
631nc_rpc_establishsub(const char *filter, const char *stream_name, const char *start_time,
632 const char *stop_time, const char *encoding, NC_PARAMTYPE paramtype)
633{
634 struct nc_rpc_establishsub *rpc;
635
636 if (!stream_name) {
637 ERRARG("stream_name");
638 return NULL;
639 }
640
641 if (filter && filter[0] && (filter[0] != '<') && (filter[0] != '/') && !isalpha(filter[0])) {
642 ERR("Filter is not an XML subtree, an XPath expression, not a filter reference (invalid first char '%c').", filter[0]);
643 return NULL;
644 }
645
646 rpc = malloc(sizeof *rpc);
647 if (!rpc) {
648 ERRMEM;
649 return NULL;
650 }
651
652 rpc->type = NC_RPC_ESTABLISHSUB;
653 if (filter && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
654 rpc->filter = strdup(filter);
655 } else {
656 rpc->filter = (char *)filter;
657 }
658 if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
659 rpc->stream = strdup(stream_name);
660 } else {
661 rpc->stream = (char *)stream_name;
662 }
663 if (start_time && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
664 rpc->start = strdup(start_time);
665 } else {
666 rpc->start = (char *)start_time;
667 }
668 if (stop_time && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
669 rpc->stop = strdup(stop_time);
670 } else {
671 rpc->stop = (char *)stop_time;
672 }
673 if (encoding && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
674 rpc->encoding = strdup(encoding);
675 } else {
676 rpc->encoding = (char *)encoding;
677 }
678 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
679
680 return (struct nc_rpc *)rpc;
681}
682
683API struct nc_rpc *
684nc_rpc_modifysub(uint32_t id, const char *filter, const char *stop_time, NC_PARAMTYPE paramtype)
685{
686 struct nc_rpc_modifysub *rpc;
687
688 if (!id) {
689 ERRARG("id");
690 return NULL;
691 }
692
693 if (filter && filter[0] && (filter[0] != '<') && (filter[0] != '/') && !isalpha(filter[0])) {
694 ERR("Filter is not an XML subtree, an XPath expression, not a filter reference (invalid first char '%c').", filter[0]);
695 return NULL;
696 }
697
698 rpc = malloc(sizeof *rpc);
699 if (!rpc) {
700 ERRMEM;
701 return NULL;
702 }
703
704 rpc->type = NC_RPC_MODIFYSUB;
705 rpc->id = id;
706 if (filter && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
707 rpc->filter = strdup(filter);
708 } else {
709 rpc->filter = (char *)filter;
710 }
711 if (stop_time && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
712 rpc->stop = strdup(stop_time);
713 } else {
714 rpc->stop = (char *)stop_time;
715 }
716 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
717
718 return (struct nc_rpc *)rpc;
719}
720
721API struct nc_rpc *
722nc_rpc_deletesub(uint32_t id)
723{
724 struct nc_rpc_deletesub *rpc;
725
726 if (!id) {
727 ERRARG("id");
728 return NULL;
729 }
730
731 rpc = malloc(sizeof *rpc);
732 if (!rpc) {
733 ERRMEM;
734 return NULL;
735 }
736
737 rpc->type = NC_RPC_DELETESUB;
738 rpc->id = id;
739
740 return (struct nc_rpc *)rpc;
741}
742
743API struct nc_rpc *
744nc_rpc_killsub(uint32_t id)
745{
746 struct nc_rpc_killsub *rpc;
747
748 if (!id) {
749 ERRARG("id");
750 return NULL;
751 }
752
753 rpc = malloc(sizeof *rpc);
754 if (!rpc) {
755 ERRMEM;
756 return NULL;
757 }
758
759 rpc->type = NC_RPC_KILLSUB;
760 rpc->id = id;
761
762 return (struct nc_rpc *)rpc;
763}
764
Michal Vasko305faca2021-03-25 09:16:02 +0100765API struct nc_rpc *
766nc_rpc_establishpush_periodic(const char *datastore, const char *filter, const char *stop_time, const char *encoding,
767 uint32_t period, const char *anchor_time, NC_PARAMTYPE paramtype)
768{
769 struct nc_rpc_establishpush *rpc;
770
771 if (!datastore) {
772 ERRARG("datastore");
773 return NULL;
774 } else if (!period) {
775 ERRARG("period");
776 return NULL;
777 }
778
779 if (filter && filter[0] && (filter[0] != '<') && (filter[0] != '/') && !isalpha(filter[0])) {
780 ERR("Filter is not an XML subtree, an XPath expression, not a filter reference (invalid first char '%c').", filter[0]);
781 return NULL;
782 }
783
784 rpc = malloc(sizeof *rpc);
785 if (!rpc) {
786 ERRMEM;
787 return NULL;
788 }
789
790 rpc->type = NC_RPC_ESTABLISHPUSH;
791 if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
792 rpc->datastore = strdup(datastore);
793 } else {
794 rpc->datastore = (char *)datastore;
795 }
796 if (filter && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
797 rpc->filter = strdup(filter);
798 } else {
799 rpc->filter = (char *)filter;
800 }
801 if (stop_time && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
802 rpc->stop = strdup(stop_time);
803 } else {
804 rpc->stop = (char *)stop_time;
805 }
806 if (encoding && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
807 rpc->encoding = strdup(encoding);
808 } else {
809 rpc->encoding = (char *)encoding;
810 }
811 rpc->periodic = 1;
812 rpc->period = period;
813 if (anchor_time && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
814 rpc->anchor_time = strdup(anchor_time);
815 } else {
816 rpc->anchor_time = (char *)anchor_time;
817 }
818 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
819
820 return (struct nc_rpc *)rpc;
821}
822
823API struct nc_rpc *
824nc_rpc_establishpush_onchange(const char *datastore, const char *filter, const char *stop_time, const char *encoding,
825 uint32_t dampening_period, int sync_on_start, const char **excluded_change, NC_PARAMTYPE paramtype)
826{
827 struct nc_rpc_establishpush *rpc;
828 uint32_t i;
829
830 if (!datastore) {
831 ERRARG("datastore");
832 return NULL;
833 }
834
835 if (filter && filter[0] && (filter[0] != '<') && (filter[0] != '/') && !isalpha(filter[0])) {
836 ERR("Filter is not an XML subtree, an XPath expression, not a filter reference (invalid first char '%c').", filter[0]);
837 return NULL;
838 }
839
840 rpc = malloc(sizeof *rpc);
841 if (!rpc) {
842 ERRMEM;
843 return NULL;
844 }
845
846 rpc->type = NC_RPC_ESTABLISHPUSH;
847 if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
848 rpc->datastore = strdup(datastore);
849 } else {
850 rpc->datastore = (char *)datastore;
851 }
852 if (filter && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
853 rpc->filter = strdup(filter);
854 } else {
855 rpc->filter = (char *)filter;
856 }
857 if (stop_time && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
858 rpc->stop = strdup(stop_time);
859 } else {
860 rpc->stop = (char *)stop_time;
861 }
862 if (encoding && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
863 rpc->encoding = strdup(encoding);
864 } else {
865 rpc->encoding = (char *)encoding;
866 }
867 rpc->periodic = 0;
868 rpc->dampening_period = dampening_period;
869 rpc->sync_on_start = sync_on_start;
870 if (excluded_change && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
871 rpc->excluded_change = NULL;
872 for (i = 0; excluded_change[i]; ++i) {
873 rpc->excluded_change = realloc(rpc->excluded_change, (i + 2) * sizeof *rpc->excluded_change);
874 rpc->excluded_change[i] = strdup(excluded_change[i]);
875 rpc->excluded_change[i + 1] = NULL;
876 }
877 } else {
878 rpc->excluded_change = (char **)excluded_change;
879 }
880 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
881
882 return (struct nc_rpc *)rpc;
883}
884
885API struct nc_rpc *
886nc_rpc_modifypush_periodic(uint32_t id, const char *datastore, const char *filter, const char *stop_time, uint32_t period,
887 const char *anchor_time, NC_PARAMTYPE paramtype)
888{
889 struct nc_rpc_modifypush *rpc;
890
891 if (!id) {
892 ERRARG("id");
893 return NULL;
894 } else if (!datastore) {
895 ERRARG("datastore");
896 return NULL;
897 }
898
899 if (filter && filter[0] && (filter[0] != '<') && (filter[0] != '/') && !isalpha(filter[0])) {
900 ERR("Filter is not an XML subtree, an XPath expression, not a filter reference (invalid first char '%c').", filter[0]);
901 return NULL;
902 }
903
904 rpc = malloc(sizeof *rpc);
905 if (!rpc) {
906 ERRMEM;
907 return NULL;
908 }
909
910 rpc->type = NC_RPC_MODIFYPUSH;
911 rpc->id = id;
912 if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
913 rpc->datastore = strdup(datastore);
914 } else {
915 rpc->datastore = (char *)datastore;
916 }
917 if (filter && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
918 rpc->filter = strdup(filter);
919 } else {
920 rpc->filter = (char *)filter;
921 }
922 if (stop_time && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
923 rpc->stop = strdup(stop_time);
924 } else {
925 rpc->stop = (char *)stop_time;
926 }
927 rpc->periodic = 1;
928 rpc->period = period;
929 if (anchor_time && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
930 rpc->anchor_time = strdup(anchor_time);
931 } else {
932 rpc->anchor_time = (char *)anchor_time;
933 }
934 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
935
936 return (struct nc_rpc *)rpc;
937}
938
939API struct nc_rpc *
940nc_rpc_modifypush_onchange(uint32_t id, const char *datastore, const char *filter, const char *stop_time,
941 uint32_t dampening_period, NC_PARAMTYPE paramtype)
942{
943 struct nc_rpc_modifypush *rpc;
944
945 if (!id) {
946 ERRARG("id");
947 return NULL;
948 } else if (!datastore) {
949 ERRARG("datastore");
950 return NULL;
951 }
952
953 if (filter && filter[0] && (filter[0] != '<') && (filter[0] != '/') && !isalpha(filter[0])) {
954 ERR("Filter is not an XML subtree, an XPath expression, not a filter reference (invalid first char '%c').", filter[0]);
955 return NULL;
956 }
957
958 rpc = malloc(sizeof *rpc);
959 if (!rpc) {
960 ERRMEM;
961 return NULL;
962 }
963
964 rpc->type = NC_RPC_MODIFYPUSH;
965 rpc->id = id;
966 if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
967 rpc->datastore = strdup(datastore);
968 } else {
969 rpc->datastore = (char *)datastore;
970 }
971 if (filter && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
972 rpc->filter = strdup(filter);
973 } else {
974 rpc->filter = (char *)filter;
975 }
976 if (stop_time && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
977 rpc->stop = strdup(stop_time);
978 } else {
979 rpc->stop = (char *)stop_time;
980 }
981 rpc->periodic = 0;
982 rpc->dampening_period = dampening_period;
983 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
984
985 return (struct nc_rpc *)rpc;
986}
987
988API struct nc_rpc *
989nc_rpc_resyncsub(uint32_t id)
990{
991 struct nc_rpc_resyncsub *rpc;
992
993 if (!id) {
994 ERRARG("id");
995 return NULL;
996 }
997
998 rpc = malloc(sizeof *rpc);
999 if (!rpc) {
1000 ERRMEM;
1001 return NULL;
1002 }
1003
1004 rpc->type = NC_RPC_RESYNCSUB;
1005 rpc->id = id;
1006
1007 return (struct nc_rpc *)rpc;
1008}
1009
Michal Vasko7bcb48e2016-01-15 10:28:54 +01001010API void
1011nc_rpc_free(struct nc_rpc *rpc)
1012{
Michal Vasko90e8e692016-07-13 12:27:57 +02001013 struct nc_rpc_act_generic *rpc_generic;
Michal Vasko7bcb48e2016-01-15 10:28:54 +01001014 struct nc_rpc_getconfig *rpc_getconfig;
1015 struct nc_rpc_edit *rpc_edit;
1016 struct nc_rpc_copy *rpc_copy;
1017 struct nc_rpc_delete *rpc_delete;
1018 struct nc_rpc_get *rpc_get;
1019 struct nc_rpc_commit *rpc_commit;
1020 struct nc_rpc_cancel *rpc_cancel;
1021 struct nc_rpc_validate *rpc_validate;
1022 struct nc_rpc_getschema *rpc_getschema;
1023 struct nc_rpc_subscribe *rpc_subscribe;
Michal Vaskoc1171a42019-11-05 12:06:46 +01001024 struct nc_rpc_getdata *rpc_getdata;
1025 struct nc_rpc_editdata *rpc_editdata;
Michal Vasko96f247a2021-03-15 13:32:10 +01001026 struct nc_rpc_establishsub *rpc_establishsub;
1027 struct nc_rpc_modifysub *rpc_modifysub;
Michal Vasko305faca2021-03-25 09:16:02 +01001028 struct nc_rpc_establishpush *rpc_establishpush;
1029 struct nc_rpc_modifypush *rpc_modifypush;
Michal Vaskoc1171a42019-11-05 12:06:46 +01001030 int i;
Michal Vasko7bcb48e2016-01-15 10:28:54 +01001031
1032 if (!rpc) {
1033 return;
1034 }
1035
1036 switch (rpc->type) {
Michal Vasko90e8e692016-07-13 12:27:57 +02001037 case NC_RPC_ACT_GENERIC:
1038 rpc_generic = (struct nc_rpc_act_generic *)rpc;
Michal Vasko7bcb48e2016-01-15 10:28:54 +01001039 if (rpc_generic->free) {
1040 if (rpc_generic->has_data) {
Michal Vasko77367452021-02-16 16:32:18 +01001041 lyd_free_tree(rpc_generic->content.data);
Michal Vasko7bcb48e2016-01-15 10:28:54 +01001042 } else {
1043 free(rpc_generic->content.xml_str);
1044 }
1045 }
1046 break;
1047 case NC_RPC_GETCONFIG:
1048 rpc_getconfig = (struct nc_rpc_getconfig *)rpc;
1049 if (rpc_getconfig->free) {
1050 free(rpc_getconfig->filter);
1051 }
1052 break;
1053 case NC_RPC_EDIT:
1054 rpc_edit = (struct nc_rpc_edit *)rpc;
1055 if (rpc_edit->free) {
1056 free(rpc_edit->edit_cont);
1057 }
1058 break;
1059 case NC_RPC_COPY:
1060 rpc_copy = (struct nc_rpc_copy *)rpc;
1061 if (rpc_copy->free) {
1062 free(rpc_copy->url_config_src);
David Sedlák35419a32018-10-07 23:23:33 +02001063 free(rpc_copy->url_trg);
Michal Vasko7bcb48e2016-01-15 10:28:54 +01001064 }
1065 break;
1066 case NC_RPC_DELETE:
1067 rpc_delete = (struct nc_rpc_delete *)rpc;
1068 if (rpc_delete->free) {
1069 free(rpc_delete->url);
1070 }
1071 break;
1072 case NC_RPC_GET:
1073 rpc_get = (struct nc_rpc_get *)rpc;
1074 if (rpc_get->free) {
1075 free(rpc_get->filter);
1076 }
1077 break;
1078 case NC_RPC_COMMIT:
1079 rpc_commit = (struct nc_rpc_commit *)rpc;
1080 if (rpc_commit->free) {
1081 free(rpc_commit->persist);
1082 free(rpc_commit->persist_id);
1083 }
1084 break;
1085 case NC_RPC_CANCEL:
1086 rpc_cancel = (struct nc_rpc_cancel *)rpc;
1087 if (rpc_cancel->free) {
1088 free(rpc_cancel->persist_id);
1089 }
1090 break;
1091 case NC_RPC_VALIDATE:
1092 rpc_validate = (struct nc_rpc_validate *)rpc;
1093 if (rpc_validate->free) {
1094 free(rpc_validate->url_config_src);
1095 }
1096 break;
1097 case NC_RPC_GETSCHEMA:
1098 rpc_getschema = (struct nc_rpc_getschema *)rpc;
1099 if (rpc_getschema->free) {
1100 free(rpc_getschema->identifier);
1101 free(rpc_getschema->version);
1102 free(rpc_getschema->format);
1103 }
1104 break;
1105 case NC_RPC_SUBSCRIBE:
1106 rpc_subscribe = (struct nc_rpc_subscribe *)rpc;
1107 if (rpc_subscribe->free) {
1108 free(rpc_subscribe->stream);
1109 free(rpc_subscribe->filter);
1110 free(rpc_subscribe->start);
1111 free(rpc_subscribe->stop);
1112 }
1113 break;
Michal Vaskoc1171a42019-11-05 12:06:46 +01001114 case NC_RPC_GETDATA:
1115 rpc_getdata = (struct nc_rpc_getdata *)rpc;
1116 if (rpc_getdata->free) {
1117 free(rpc_getdata->datastore);
1118 free(rpc_getdata->filter);
1119 free(rpc_getdata->config_filter);
1120 for (i = 0; i < rpc_getdata->origin_filter_count; ++i) {
1121 free(rpc_getdata->origin_filter[i]);
1122 }
1123 free(rpc_getdata->origin_filter);
1124 }
1125 break;
1126 case NC_RPC_EDITDATA:
1127 rpc_editdata = (struct nc_rpc_editdata *)rpc;
1128 if (rpc_editdata->free) {
1129 free(rpc_editdata->datastore);
1130 free(rpc_editdata->edit_cont);
1131 }
1132 break;
Michal Vasko96f247a2021-03-15 13:32:10 +01001133 case NC_RPC_ESTABLISHSUB:
1134 rpc_establishsub = (struct nc_rpc_establishsub *)rpc;
1135 if (rpc_establishsub->free) {
1136 free(rpc_establishsub->filter);
1137 free(rpc_establishsub->stream);
1138 free(rpc_establishsub->start);
1139 free(rpc_establishsub->stop);
1140 free(rpc_establishsub->encoding);
1141 }
1142 break;
1143 case NC_RPC_MODIFYSUB:
1144 rpc_modifysub = (struct nc_rpc_modifysub *)rpc;
1145 if (rpc_modifysub->free) {
1146 free(rpc_modifysub->filter);
1147 free(rpc_modifysub->stop);
1148 }
1149 break;
Michal Vasko305faca2021-03-25 09:16:02 +01001150 case NC_RPC_ESTABLISHPUSH:
1151 rpc_establishpush = (struct nc_rpc_establishpush *)rpc;
1152 if (rpc_establishpush->free) {
1153 free(rpc_establishpush->datastore);
1154 free(rpc_establishpush->filter);
1155 free(rpc_establishpush->stop);
1156 free(rpc_establishpush->encoding);
1157 if (rpc_establishpush->periodic) {
1158 free(rpc_establishpush->anchor_time);
1159 } else {
1160 if (rpc_establishpush->excluded_change) {
1161 for (i = 0; rpc_establishpush->excluded_change[i]; ++i) {
1162 free(rpc_establishpush->excluded_change[i]);
1163 }
1164 free(rpc_establishpush->excluded_change);
1165 }
1166 }
1167 }
1168 break;
1169 case NC_RPC_MODIFYPUSH:
1170 rpc_modifypush = (struct nc_rpc_modifypush *)rpc;
1171 if (rpc_modifypush->free) {
1172 free(rpc_modifypush->datastore);
1173 free(rpc_modifypush->filter);
1174 free(rpc_modifypush->stop);
1175 if (rpc_modifypush->periodic) {
1176 free(rpc_modifypush->anchor_time);
1177 }
1178 }
1179 break;
Michal Vasko96f247a2021-03-15 13:32:10 +01001180 case NC_RPC_UNKNOWN:
1181 case NC_RPC_LOCK:
1182 case NC_RPC_UNLOCK:
1183 case NC_RPC_KILL:
1184 case NC_RPC_DISCARD:
1185 case NC_RPC_DELETESUB:
1186 case NC_RPC_KILLSUB:
Michal Vasko305faca2021-03-25 09:16:02 +01001187 case NC_RPC_RESYNCSUB:
Michal Vasko7bcb48e2016-01-15 10:28:54 +01001188 /* nothing special needed */
1189 break;
1190 }
1191
1192 free(rpc);
1193}
1194
1195API void
Radek Krejci36d2ee42017-10-13 13:55:59 +02001196nc_client_err_clean(struct nc_err *err, struct ly_ctx *ctx)
1197{
1198 int i;
1199
1200 assert(ctx);
1201
1202 if (!err) {
1203 return;
1204 }
1205
1206 lydict_remove(ctx, err->type);
1207 lydict_remove(ctx, err->tag);
1208 lydict_remove(ctx, err->severity);
1209 lydict_remove(ctx, err->apptag);
1210 lydict_remove(ctx, err->path);
1211 lydict_remove(ctx, err->message);
1212 lydict_remove(ctx, err->message_lang);
1213 lydict_remove(ctx, err->sid);
1214 for (i = 0; i < err->attr_count; ++i) {
1215 lydict_remove(ctx, err->attr[i]);
1216 }
1217 free(err->attr);
1218 for (i = 0; i < err->elem_count; ++i) {
1219 lydict_remove(ctx, err->elem[i]);
1220 }
1221 free(err->elem);
1222 for (i = 0; i < err->ns_count; ++i) {
1223 lydict_remove(ctx, err->ns[i]);
1224 }
1225 free(err->ns);
Michal Vasko77367452021-02-16 16:32:18 +01001226 lyd_free_siblings(err->other);
Radek Krejci36d2ee42017-10-13 13:55:59 +02001227 free(err->other);
1228}