blob: 6274a84792330a8c6bbed94065108dbc1dd687ea [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 Vasko05532772021-06-03 12:12:38 +0200110 ERR(NULL, "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])) {
Michal Vasko05532772021-06-03 12:12:38 +0200148 ERR(NULL, "<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 Vasko05532772021-06-03 12:12:38 +0200188 ERR(NULL, "<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 Vasko05532772021-06-03 12:12:38 +0200295 ERR(NULL, "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 Vasko05532772021-06-03 12:12:38 +0200418 ERR(NULL, "<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 Vasko05532772021-06-03 12:12:38 +0200484 ERR(NULL, "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])) {
Michal Vasko05532772021-06-03 12:12:38 +0200529 ERR(NULL, "Filter is neither an XML subtree nor an XPath expression (invalid first char '%c').", filter[0]);
Michal Vaskoc1171a42019-11-05 12:06:46 +0100530 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])) {
Michal Vasko05532772021-06-03 12:12:38 +0200603 ERR(NULL, "<edit-data> content is neither a URL nor an XML config (invalid first char '%c').", edit_content[0]);
Michal Vaskoc1171a42019-11-05 12:06:46 +0100604 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])) {
Michal Vasko05532772021-06-03 12:12:38 +0200642 ERR(NULL, "Filter is not an XML subtree, an XPath expression, not a filter reference (invalid first char '%c').",
643 filter[0]);
Michal Vasko96f247a2021-03-15 13:32:10 +0100644 return NULL;
645 }
646
647 rpc = malloc(sizeof *rpc);
648 if (!rpc) {
649 ERRMEM;
650 return NULL;
651 }
652
653 rpc->type = NC_RPC_ESTABLISHSUB;
654 if (filter && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
655 rpc->filter = strdup(filter);
656 } else {
657 rpc->filter = (char *)filter;
658 }
659 if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
660 rpc->stream = strdup(stream_name);
661 } else {
662 rpc->stream = (char *)stream_name;
663 }
664 if (start_time && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
665 rpc->start = strdup(start_time);
666 } else {
667 rpc->start = (char *)start_time;
668 }
669 if (stop_time && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
670 rpc->stop = strdup(stop_time);
671 } else {
672 rpc->stop = (char *)stop_time;
673 }
674 if (encoding && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
675 rpc->encoding = strdup(encoding);
676 } else {
677 rpc->encoding = (char *)encoding;
678 }
679 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
680
681 return (struct nc_rpc *)rpc;
682}
683
684API struct nc_rpc *
685nc_rpc_modifysub(uint32_t id, const char *filter, const char *stop_time, NC_PARAMTYPE paramtype)
686{
687 struct nc_rpc_modifysub *rpc;
688
689 if (!id) {
690 ERRARG("id");
691 return NULL;
692 }
693
694 if (filter && filter[0] && (filter[0] != '<') && (filter[0] != '/') && !isalpha(filter[0])) {
Michal Vasko05532772021-06-03 12:12:38 +0200695 ERR(NULL, "Filter is not an XML subtree, an XPath expression, not a filter reference (invalid first char '%c').",
696 filter[0]);
Michal Vasko96f247a2021-03-15 13:32:10 +0100697 return NULL;
698 }
699
700 rpc = malloc(sizeof *rpc);
701 if (!rpc) {
702 ERRMEM;
703 return NULL;
704 }
705
706 rpc->type = NC_RPC_MODIFYSUB;
707 rpc->id = id;
708 if (filter && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
709 rpc->filter = strdup(filter);
710 } else {
711 rpc->filter = (char *)filter;
712 }
713 if (stop_time && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
714 rpc->stop = strdup(stop_time);
715 } else {
716 rpc->stop = (char *)stop_time;
717 }
718 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
719
720 return (struct nc_rpc *)rpc;
721}
722
723API struct nc_rpc *
724nc_rpc_deletesub(uint32_t id)
725{
726 struct nc_rpc_deletesub *rpc;
727
728 if (!id) {
729 ERRARG("id");
730 return NULL;
731 }
732
733 rpc = malloc(sizeof *rpc);
734 if (!rpc) {
735 ERRMEM;
736 return NULL;
737 }
738
739 rpc->type = NC_RPC_DELETESUB;
740 rpc->id = id;
741
742 return (struct nc_rpc *)rpc;
743}
744
745API struct nc_rpc *
746nc_rpc_killsub(uint32_t id)
747{
748 struct nc_rpc_killsub *rpc;
749
750 if (!id) {
751 ERRARG("id");
752 return NULL;
753 }
754
755 rpc = malloc(sizeof *rpc);
756 if (!rpc) {
757 ERRMEM;
758 return NULL;
759 }
760
761 rpc->type = NC_RPC_KILLSUB;
762 rpc->id = id;
763
764 return (struct nc_rpc *)rpc;
765}
766
Michal Vasko305faca2021-03-25 09:16:02 +0100767API struct nc_rpc *
768nc_rpc_establishpush_periodic(const char *datastore, const char *filter, const char *stop_time, const char *encoding,
769 uint32_t period, const char *anchor_time, NC_PARAMTYPE paramtype)
770{
771 struct nc_rpc_establishpush *rpc;
772
773 if (!datastore) {
774 ERRARG("datastore");
775 return NULL;
776 } else if (!period) {
777 ERRARG("period");
778 return NULL;
779 }
780
781 if (filter && filter[0] && (filter[0] != '<') && (filter[0] != '/') && !isalpha(filter[0])) {
Michal Vasko05532772021-06-03 12:12:38 +0200782 ERR(NULL, "Filter is not an XML subtree, an XPath expression, not a filter reference (invalid first char '%c').",
783 filter[0]);
Michal Vasko305faca2021-03-25 09:16:02 +0100784 return NULL;
785 }
786
787 rpc = malloc(sizeof *rpc);
788 if (!rpc) {
789 ERRMEM;
790 return NULL;
791 }
792
793 rpc->type = NC_RPC_ESTABLISHPUSH;
794 if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
795 rpc->datastore = strdup(datastore);
796 } else {
797 rpc->datastore = (char *)datastore;
798 }
799 if (filter && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
800 rpc->filter = strdup(filter);
801 } else {
802 rpc->filter = (char *)filter;
803 }
804 if (stop_time && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
805 rpc->stop = strdup(stop_time);
806 } else {
807 rpc->stop = (char *)stop_time;
808 }
809 if (encoding && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
810 rpc->encoding = strdup(encoding);
811 } else {
812 rpc->encoding = (char *)encoding;
813 }
814 rpc->periodic = 1;
815 rpc->period = period;
816 if (anchor_time && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
817 rpc->anchor_time = strdup(anchor_time);
818 } else {
819 rpc->anchor_time = (char *)anchor_time;
820 }
821 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
822
823 return (struct nc_rpc *)rpc;
824}
825
826API struct nc_rpc *
827nc_rpc_establishpush_onchange(const char *datastore, const char *filter, const char *stop_time, const char *encoding,
828 uint32_t dampening_period, int sync_on_start, const char **excluded_change, NC_PARAMTYPE paramtype)
829{
830 struct nc_rpc_establishpush *rpc;
831 uint32_t i;
832
833 if (!datastore) {
834 ERRARG("datastore");
835 return NULL;
836 }
837
838 if (filter && filter[0] && (filter[0] != '<') && (filter[0] != '/') && !isalpha(filter[0])) {
Michal Vasko05532772021-06-03 12:12:38 +0200839 ERR(NULL, "Filter is not an XML subtree, an XPath expression, not a filter reference (invalid first char '%c').",
840 filter[0]);
Michal Vasko305faca2021-03-25 09:16:02 +0100841 return NULL;
842 }
843
844 rpc = malloc(sizeof *rpc);
845 if (!rpc) {
846 ERRMEM;
847 return NULL;
848 }
849
850 rpc->type = NC_RPC_ESTABLISHPUSH;
851 if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
852 rpc->datastore = strdup(datastore);
853 } else {
854 rpc->datastore = (char *)datastore;
855 }
856 if (filter && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
857 rpc->filter = strdup(filter);
858 } else {
859 rpc->filter = (char *)filter;
860 }
861 if (stop_time && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
862 rpc->stop = strdup(stop_time);
863 } else {
864 rpc->stop = (char *)stop_time;
865 }
866 if (encoding && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
867 rpc->encoding = strdup(encoding);
868 } else {
869 rpc->encoding = (char *)encoding;
870 }
871 rpc->periodic = 0;
872 rpc->dampening_period = dampening_period;
873 rpc->sync_on_start = sync_on_start;
874 if (excluded_change && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
875 rpc->excluded_change = NULL;
876 for (i = 0; excluded_change[i]; ++i) {
877 rpc->excluded_change = realloc(rpc->excluded_change, (i + 2) * sizeof *rpc->excluded_change);
878 rpc->excluded_change[i] = strdup(excluded_change[i]);
879 rpc->excluded_change[i + 1] = NULL;
880 }
881 } else {
882 rpc->excluded_change = (char **)excluded_change;
883 }
884 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
885
886 return (struct nc_rpc *)rpc;
887}
888
889API struct nc_rpc *
890nc_rpc_modifypush_periodic(uint32_t id, const char *datastore, const char *filter, const char *stop_time, uint32_t period,
891 const char *anchor_time, NC_PARAMTYPE paramtype)
892{
893 struct nc_rpc_modifypush *rpc;
894
895 if (!id) {
896 ERRARG("id");
897 return NULL;
898 } else if (!datastore) {
899 ERRARG("datastore");
900 return NULL;
901 }
902
903 if (filter && filter[0] && (filter[0] != '<') && (filter[0] != '/') && !isalpha(filter[0])) {
Michal Vasko05532772021-06-03 12:12:38 +0200904 ERR(NULL, "Filter is not an XML subtree, an XPath expression, not a filter reference (invalid first char '%c').",
905 filter[0]);
Michal Vasko305faca2021-03-25 09:16:02 +0100906 return NULL;
907 }
908
909 rpc = malloc(sizeof *rpc);
910 if (!rpc) {
911 ERRMEM;
912 return NULL;
913 }
914
915 rpc->type = NC_RPC_MODIFYPUSH;
916 rpc->id = id;
917 if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
918 rpc->datastore = strdup(datastore);
919 } else {
920 rpc->datastore = (char *)datastore;
921 }
922 if (filter && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
923 rpc->filter = strdup(filter);
924 } else {
925 rpc->filter = (char *)filter;
926 }
927 if (stop_time && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
928 rpc->stop = strdup(stop_time);
929 } else {
930 rpc->stop = (char *)stop_time;
931 }
932 rpc->periodic = 1;
933 rpc->period = period;
934 if (anchor_time && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
935 rpc->anchor_time = strdup(anchor_time);
936 } else {
937 rpc->anchor_time = (char *)anchor_time;
938 }
939 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
940
941 return (struct nc_rpc *)rpc;
942}
943
944API struct nc_rpc *
945nc_rpc_modifypush_onchange(uint32_t id, const char *datastore, const char *filter, const char *stop_time,
946 uint32_t dampening_period, NC_PARAMTYPE paramtype)
947{
948 struct nc_rpc_modifypush *rpc;
949
950 if (!id) {
951 ERRARG("id");
952 return NULL;
953 } else if (!datastore) {
954 ERRARG("datastore");
955 return NULL;
956 }
957
958 if (filter && filter[0] && (filter[0] != '<') && (filter[0] != '/') && !isalpha(filter[0])) {
Michal Vasko05532772021-06-03 12:12:38 +0200959 ERR(NULL, "Filter is not an XML subtree, an XPath expression, not a filter reference (invalid first char '%c').",
960 filter[0]);
Michal Vasko305faca2021-03-25 09:16:02 +0100961 return NULL;
962 }
963
964 rpc = malloc(sizeof *rpc);
965 if (!rpc) {
966 ERRMEM;
967 return NULL;
968 }
969
970 rpc->type = NC_RPC_MODIFYPUSH;
971 rpc->id = id;
972 if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
973 rpc->datastore = strdup(datastore);
974 } else {
975 rpc->datastore = (char *)datastore;
976 }
977 if (filter && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
978 rpc->filter = strdup(filter);
979 } else {
980 rpc->filter = (char *)filter;
981 }
982 if (stop_time && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
983 rpc->stop = strdup(stop_time);
984 } else {
985 rpc->stop = (char *)stop_time;
986 }
987 rpc->periodic = 0;
988 rpc->dampening_period = dampening_period;
989 rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
990
991 return (struct nc_rpc *)rpc;
992}
993
994API struct nc_rpc *
995nc_rpc_resyncsub(uint32_t id)
996{
997 struct nc_rpc_resyncsub *rpc;
998
999 if (!id) {
1000 ERRARG("id");
1001 return NULL;
1002 }
1003
1004 rpc = malloc(sizeof *rpc);
1005 if (!rpc) {
1006 ERRMEM;
1007 return NULL;
1008 }
1009
1010 rpc->type = NC_RPC_RESYNCSUB;
1011 rpc->id = id;
1012
1013 return (struct nc_rpc *)rpc;
1014}
1015
Michal Vasko7bcb48e2016-01-15 10:28:54 +01001016API void
1017nc_rpc_free(struct nc_rpc *rpc)
1018{
Michal Vasko90e8e692016-07-13 12:27:57 +02001019 struct nc_rpc_act_generic *rpc_generic;
Michal Vasko7bcb48e2016-01-15 10:28:54 +01001020 struct nc_rpc_getconfig *rpc_getconfig;
1021 struct nc_rpc_edit *rpc_edit;
1022 struct nc_rpc_copy *rpc_copy;
1023 struct nc_rpc_delete *rpc_delete;
1024 struct nc_rpc_get *rpc_get;
1025 struct nc_rpc_commit *rpc_commit;
1026 struct nc_rpc_cancel *rpc_cancel;
1027 struct nc_rpc_validate *rpc_validate;
1028 struct nc_rpc_getschema *rpc_getschema;
1029 struct nc_rpc_subscribe *rpc_subscribe;
Michal Vaskoc1171a42019-11-05 12:06:46 +01001030 struct nc_rpc_getdata *rpc_getdata;
1031 struct nc_rpc_editdata *rpc_editdata;
Michal Vasko96f247a2021-03-15 13:32:10 +01001032 struct nc_rpc_establishsub *rpc_establishsub;
1033 struct nc_rpc_modifysub *rpc_modifysub;
Michal Vasko305faca2021-03-25 09:16:02 +01001034 struct nc_rpc_establishpush *rpc_establishpush;
1035 struct nc_rpc_modifypush *rpc_modifypush;
Michal Vaskoc1171a42019-11-05 12:06:46 +01001036 int i;
Michal Vasko7bcb48e2016-01-15 10:28:54 +01001037
1038 if (!rpc) {
1039 return;
1040 }
1041
1042 switch (rpc->type) {
Michal Vasko90e8e692016-07-13 12:27:57 +02001043 case NC_RPC_ACT_GENERIC:
1044 rpc_generic = (struct nc_rpc_act_generic *)rpc;
Michal Vasko7bcb48e2016-01-15 10:28:54 +01001045 if (rpc_generic->free) {
1046 if (rpc_generic->has_data) {
Michal Vasko77367452021-02-16 16:32:18 +01001047 lyd_free_tree(rpc_generic->content.data);
Michal Vasko7bcb48e2016-01-15 10:28:54 +01001048 } else {
1049 free(rpc_generic->content.xml_str);
1050 }
1051 }
1052 break;
1053 case NC_RPC_GETCONFIG:
1054 rpc_getconfig = (struct nc_rpc_getconfig *)rpc;
1055 if (rpc_getconfig->free) {
1056 free(rpc_getconfig->filter);
1057 }
1058 break;
1059 case NC_RPC_EDIT:
1060 rpc_edit = (struct nc_rpc_edit *)rpc;
1061 if (rpc_edit->free) {
1062 free(rpc_edit->edit_cont);
1063 }
1064 break;
1065 case NC_RPC_COPY:
1066 rpc_copy = (struct nc_rpc_copy *)rpc;
1067 if (rpc_copy->free) {
1068 free(rpc_copy->url_config_src);
David Sedlák35419a32018-10-07 23:23:33 +02001069 free(rpc_copy->url_trg);
Michal Vasko7bcb48e2016-01-15 10:28:54 +01001070 }
1071 break;
1072 case NC_RPC_DELETE:
1073 rpc_delete = (struct nc_rpc_delete *)rpc;
1074 if (rpc_delete->free) {
1075 free(rpc_delete->url);
1076 }
1077 break;
1078 case NC_RPC_GET:
1079 rpc_get = (struct nc_rpc_get *)rpc;
1080 if (rpc_get->free) {
1081 free(rpc_get->filter);
1082 }
1083 break;
1084 case NC_RPC_COMMIT:
1085 rpc_commit = (struct nc_rpc_commit *)rpc;
1086 if (rpc_commit->free) {
1087 free(rpc_commit->persist);
1088 free(rpc_commit->persist_id);
1089 }
1090 break;
1091 case NC_RPC_CANCEL:
1092 rpc_cancel = (struct nc_rpc_cancel *)rpc;
1093 if (rpc_cancel->free) {
1094 free(rpc_cancel->persist_id);
1095 }
1096 break;
1097 case NC_RPC_VALIDATE:
1098 rpc_validate = (struct nc_rpc_validate *)rpc;
1099 if (rpc_validate->free) {
1100 free(rpc_validate->url_config_src);
1101 }
1102 break;
1103 case NC_RPC_GETSCHEMA:
1104 rpc_getschema = (struct nc_rpc_getschema *)rpc;
1105 if (rpc_getschema->free) {
1106 free(rpc_getschema->identifier);
1107 free(rpc_getschema->version);
1108 free(rpc_getschema->format);
1109 }
1110 break;
1111 case NC_RPC_SUBSCRIBE:
1112 rpc_subscribe = (struct nc_rpc_subscribe *)rpc;
1113 if (rpc_subscribe->free) {
1114 free(rpc_subscribe->stream);
1115 free(rpc_subscribe->filter);
1116 free(rpc_subscribe->start);
1117 free(rpc_subscribe->stop);
1118 }
1119 break;
Michal Vaskoc1171a42019-11-05 12:06:46 +01001120 case NC_RPC_GETDATA:
1121 rpc_getdata = (struct nc_rpc_getdata *)rpc;
1122 if (rpc_getdata->free) {
1123 free(rpc_getdata->datastore);
1124 free(rpc_getdata->filter);
1125 free(rpc_getdata->config_filter);
1126 for (i = 0; i < rpc_getdata->origin_filter_count; ++i) {
1127 free(rpc_getdata->origin_filter[i]);
1128 }
1129 free(rpc_getdata->origin_filter);
1130 }
1131 break;
1132 case NC_RPC_EDITDATA:
1133 rpc_editdata = (struct nc_rpc_editdata *)rpc;
1134 if (rpc_editdata->free) {
1135 free(rpc_editdata->datastore);
1136 free(rpc_editdata->edit_cont);
1137 }
1138 break;
Michal Vasko96f247a2021-03-15 13:32:10 +01001139 case NC_RPC_ESTABLISHSUB:
1140 rpc_establishsub = (struct nc_rpc_establishsub *)rpc;
1141 if (rpc_establishsub->free) {
1142 free(rpc_establishsub->filter);
1143 free(rpc_establishsub->stream);
1144 free(rpc_establishsub->start);
1145 free(rpc_establishsub->stop);
1146 free(rpc_establishsub->encoding);
1147 }
1148 break;
1149 case NC_RPC_MODIFYSUB:
1150 rpc_modifysub = (struct nc_rpc_modifysub *)rpc;
1151 if (rpc_modifysub->free) {
1152 free(rpc_modifysub->filter);
1153 free(rpc_modifysub->stop);
1154 }
1155 break;
Michal Vasko305faca2021-03-25 09:16:02 +01001156 case NC_RPC_ESTABLISHPUSH:
1157 rpc_establishpush = (struct nc_rpc_establishpush *)rpc;
1158 if (rpc_establishpush->free) {
1159 free(rpc_establishpush->datastore);
1160 free(rpc_establishpush->filter);
1161 free(rpc_establishpush->stop);
1162 free(rpc_establishpush->encoding);
1163 if (rpc_establishpush->periodic) {
1164 free(rpc_establishpush->anchor_time);
1165 } else {
1166 if (rpc_establishpush->excluded_change) {
1167 for (i = 0; rpc_establishpush->excluded_change[i]; ++i) {
1168 free(rpc_establishpush->excluded_change[i]);
1169 }
1170 free(rpc_establishpush->excluded_change);
1171 }
1172 }
1173 }
1174 break;
1175 case NC_RPC_MODIFYPUSH:
1176 rpc_modifypush = (struct nc_rpc_modifypush *)rpc;
1177 if (rpc_modifypush->free) {
1178 free(rpc_modifypush->datastore);
1179 free(rpc_modifypush->filter);
1180 free(rpc_modifypush->stop);
1181 if (rpc_modifypush->periodic) {
1182 free(rpc_modifypush->anchor_time);
1183 }
1184 }
1185 break;
Michal Vasko96f247a2021-03-15 13:32:10 +01001186 case NC_RPC_UNKNOWN:
1187 case NC_RPC_LOCK:
1188 case NC_RPC_UNLOCK:
1189 case NC_RPC_KILL:
1190 case NC_RPC_DISCARD:
1191 case NC_RPC_DELETESUB:
1192 case NC_RPC_KILLSUB:
Michal Vasko305faca2021-03-25 09:16:02 +01001193 case NC_RPC_RESYNCSUB:
Michal Vasko7bcb48e2016-01-15 10:28:54 +01001194 /* nothing special needed */
1195 break;
1196 }
1197
1198 free(rpc);
1199}
1200
1201API void
Radek Krejci36d2ee42017-10-13 13:55:59 +02001202nc_client_err_clean(struct nc_err *err, struct ly_ctx *ctx)
1203{
1204 int i;
1205
1206 assert(ctx);
1207
1208 if (!err) {
1209 return;
1210 }
1211
1212 lydict_remove(ctx, err->type);
1213 lydict_remove(ctx, err->tag);
1214 lydict_remove(ctx, err->severity);
1215 lydict_remove(ctx, err->apptag);
1216 lydict_remove(ctx, err->path);
1217 lydict_remove(ctx, err->message);
1218 lydict_remove(ctx, err->message_lang);
1219 lydict_remove(ctx, err->sid);
1220 for (i = 0; i < err->attr_count; ++i) {
1221 lydict_remove(ctx, err->attr[i]);
1222 }
1223 free(err->attr);
1224 for (i = 0; i < err->elem_count; ++i) {
1225 lydict_remove(ctx, err->elem[i]);
1226 }
1227 free(err->elem);
1228 for (i = 0; i < err->ns_count; ++i) {
1229 lydict_remove(ctx, err->ns[i]);
1230 }
1231 free(err->ns);
Michal Vasko77367452021-02-16 16:32:18 +01001232 lyd_free_siblings(err->other);
Radek Krejci36d2ee42017-10-13 13:55:59 +02001233 free(err->other);
1234}