yumapro  20.10-12
YumaPro SDK
yang_patch.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 - 2021, YumaWorks, Inc., All Rights Reserved.
3  *
4  * Unless required by applicable law or agreed to in writing,
5  * software distributed under the License is distributed on an
6  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
7  * KIND, either express or implied. See the License for the
8  * specific language governing permissions and limitations
9  * under the License.
10  */
11 #ifndef _H_yang_patch
12 #define _H_yang_patch
13 
14 /* FILE: yang_patch.h
15 *********************************************************************
16 * *
17 * P U R P O S E *
18 * *
19 *********************************************************************/
20 
29 /*********************************************************************
30 * *
31 * C H A N G E H I S T O R Y *
32 * *
33 *********************************************************************
34 
35 date init comment
36 ----------------------------------------------------------------------
37 16-nov-14 abb Begun
38 
39 */
40 
41 #include <xmlstring.h>
42 
43 #ifndef _H_dlq
44 #include "dlq.h"
45 #endif
46 
47 #ifndef _H_obj
48 #include "obj.h"
49 #endif
50 
51 #ifndef _H_op
52 #include "op.h"
53 #endif
54 
55 #ifndef _H_status
56 #include "status.h"
57 #endif
58 
59 #ifndef _H_val
60 #include "val.h"
61 #endif
62 
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66 
67 
68 #define YANG_PATCH_DEF_SKIP_SIL TRUE
69 
70 
71 /********************************************************************
72 * *
73 * T Y P E S *
74 * *
75 *********************************************************************/
76 
87 typedef enum yang_patch_op_t_ {
96 } yang_patch_op_t;
97 
98 
104 } yang_patch_edit_type_t;
105 
106 
108 typedef enum yang_patch_where_t_ {
114 } yang_patch_where_t;
115 
116 
118 typedef struct yang_patch_edit_t_ {
120  dlq_hdr_t qhdr;
121 
123  xmlChar *edit_id;
124 
126  yang_patch_op_t operation;
127 
129  xmlChar *target;
130 
132  xmlChar *point;
133 
135  yang_patch_where_t insert_where;
136 
138  val_value_t *value;
139 
143  val_value_t *configval;
144 
146  val_value_t *targval;
147 
149  boolean lastedit;
150 
151 } yang_patch_edit_t;
152 
153 
155 typedef struct yang_patch_cb_t_ {
157  dlq_hdr_t qhdr;
158 
160  xmlChar *patch_id;
161 
163  yang_patch_edit_type_t edit_type;
164 
166  boolean skip_sil;
167 
169  xmlChar *comment;
170 
178  xmlChar *target;
179 
181  dlq_hdr_t editQ;
182 } yang_patch_cb_t;
183 
184 
185 
186 /********************************************************************
187 * *
188 * F U N C T I O N S *
189 * *
190 *********************************************************************/
191 
192 
198 extern status_t
199  yang_patch_init (void);
200 
201 
206 extern void
207  yang_patch_cleanup (void);
208 
209 
219 extern yang_patch_cb_t *
220  yang_patch_new_cb (const xmlChar *patch_id,
221  const xmlChar *the_comment,
222  const xmlChar *target);
223 
224 
230 extern void
231  yang_patch_free_cb (yang_patch_cb_t *pcb);
232 
233 
239 extern void
240  yang_patch_free_edit (yang_patch_edit_t *edit);
241 
242 
256 extern yang_patch_edit_t *
257  yang_patch_new_edit (const xmlChar *edit_id,
258  yang_patch_op_t operation,
259  const xmlChar *target,
260  const xmlChar *point,
261  yang_patch_where_t insert_where,
262  val_value_t *value);
263 
264 
280 extern yang_patch_edit_t *
281  yang_patch_new_edit2 (const xmlChar *edit_id,
282  yang_patch_op_t operation,
283  const xmlChar *target,
284  const xmlChar *point,
285  yang_patch_where_t insert_where,
286  val_value_t *value,
287  boolean plain_clone);
288 
289 
296 extern void
297  yang_patch_add_edit (yang_patch_cb_t *pcb,
298  yang_patch_edit_t *edit);
299 
300 
308 extern yang_patch_edit_t *
309  yang_patch_find_edit (yang_patch_cb_t *pcb,
310  const xmlChar *edit_id);
311 
312 
319 extern uint32
320  yang_patch_edit_count (yang_patch_cb_t *pcb);
321 
322 
330 extern yang_patch_op_t
331  yang_patch_str_to_op (const xmlChar *opstr);
332 
333 
341 extern const xmlChar *
342  yang_patch_op_to_str (yang_patch_op_t op);
343 
344 
352 extern yang_patch_edit_type_t
353  yang_patch_str_to_edit_type (const xmlChar *str);
354 
355 
363 extern const xmlChar *
364  yang_patch_edit_type_to_str (yang_patch_edit_type_t typ);
365 
366 
374 extern yang_patch_where_t
375  yang_patch_str_to_where (const xmlChar *wherestr);
376 
377 
385 extern const xmlChar *
386  yang_patch_where_to_str (yang_patch_where_t wh);
387 
388 
399 extern val_value_t *
400  yang_patch_edit_to_value (obj_template_t *edit_obj,
401  yang_patch_edit_t *edit,
402  status_t *res);
403 
404 
415 extern val_value_t *
416  yang_patch_to_value (obj_template_t *patch_obj,
417  yang_patch_cb_t *pcb,
418  status_t *res);
419 
420 
434 extern yang_patch_edit_t *
435  yang_patch_value_to_edit (val_value_t *edit_val,
436  boolean preserve_editval,
437  status_t *res);
438 
439 
454 extern yang_patch_cb_t *
455  yang_patch_value_to_patch (val_value_t *patch_val,
456  const xmlChar *target,
457  boolean preserve_patchval,
458  status_t *res);
459 
460 
471 extern op_editop_t
472  yang_patch_op_to_editop (yang_patch_op_t op,
473  boolean *is_insert);
474 
475 
485 extern yang_patch_op_t
486  yang_patch_editop_to_op (op_editop_t edit_op);
487 
488 
496 extern void
497  yang_patch_dump_pcb (yang_patch_cb_t *pcb);
498 
499 
503 #ifdef __cplusplus
504 } /* end extern 'C' */
505 #endif
506 
507 #endif /* _H_yang_patch */
yang_patch_where_t_
yang_patch_where_t_
YANG Patch insert location.
Definition: yang_patch.h:108
xml_strlen
uint32 xml_strlen(const xmlChar *str)
Get the String len for xmlChar.
Definition: xml_util.c:1406
yang_patch_edit_t_::value
val_value_t * value
edit value from request (not provided for delete)
Definition: yang_patch.h:138
yang_patch_edit_t_::qhdr
dlq_hdr_t qhdr
queue header
Definition: yang_patch.h:120
yang_patch_edit_t_::configval
val_value_t * configval
the 'root' value struct that represents the tree of changes to apply to the target
Definition: yang_patch.h:143
OP_EDITOP_CREATE
@ OP_EDITOP_CREATE
edit op is create
Definition: op.h:126
OP_EDITOP_REPLACE
@ OP_EDITOP_REPLACE
edit op is replace
Definition: op.h:125
YANG_PATCH_OP_CREATE
@ YANG_PATCH_OP_CREATE
create
Definition: yang_patch.h:89
OP_EDITOP_NONE
@ OP_EDITOP_NONE
not set
Definition: op.h:123
xml_strdup
xmlChar * xml_strdup(const xmlChar *copyFrom)
String duplicate for xmlChar.
Definition: xml_util.c:1553
val_set_name
void val_set_name(val_value_t *val, const xmlChar *name, uint32 namelen)
Set (or reset) the name of a value struct.
Definition: val.c:2875
val_find_child
val_value_t * val_find_child(const val_value_t *parent, const xmlChar *modname, const xmlChar *childname)
Find the first instance of the specified child node.
Definition: val.c:8560
yang_patch_add_edit
void yang_patch_add_edit(yang_patch_cb_t *pcb, yang_patch_edit_t *edit)
Malloc and add new YANG Patch edit control block.
Definition: yang_patch.c:393
YANG_PATCH_WHERE_AFTER
@ YANG_PATCH_WHERE_AFTER
insert after foo
Definition: yang_patch.h:111
val_change_nsid
void val_change_nsid(val_value_t *val, xmlns_id_t nsid)
Change the namespace ID for a value node and all its descendants.
Definition: val.c:12303
yang_patch_free_cb
void yang_patch_free_cb(yang_patch_cb_t *pcb)
Free a YANG Patch control block.
Definition: yang_patch.c:214
log_error
void log_error(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_ERROR log entry.
val.h
Value Node Basic Support.
xml_util.h
XML Utilities.
val_make_simval_obj
val_value_t * val_make_simval_obj(obj_template_t *obj, const xmlChar *valstr, status_t *res)
Create and set a val_value_t as a simple type from an object template instead of individual fields Ca...
Definition: val_util.c:4389
NCX_BT_INTERN
@ NCX_BT_INTERN
not a real type, string buffer for contents
Definition: ncxtypes.h:231
YANG_PATCH_OP_MERGE
@ YANG_PATCH_OP_MERGE
merge
Definition: yang_patch.h:92
YANG_PATCH_WHERE_NONE
@ YANG_PATCH_WHERE_NONE
not set
Definition: yang_patch.h:109
YANG_PATCH_EDIT_TYPE_NONE
@ YANG_PATCH_EDIT_TYPE_NONE
not set
Definition: yang_patch.h:101
yang_patch_init
status_t yang_patch_init(void)
Load the ietf-yang-patch module.
Definition: yang_patch.c:120
yang_patch_op_to_str
const xmlChar * yang_patch_op_to_str(yang_patch_op_t op)
Convert a YANG Patch operation enum to the operation string for the enumeration.
Definition: yang_patch.c:515
op.h
NETCONF protocol operations.
YANG_PATCH_EDIT_TYPE_SYSTEM
@ YANG_PATCH_EDIT_TYPE_SYSTEM
edit by system
Definition: yang_patch.h:103
ncxmod.h
NCX Module Load Manager.
YANG_PATCH_OP_DELETE
@ YANG_PATCH_OP_DELETE
delete
Definition: yang_patch.h:90
YANG_PATCH_WHERE_LAST
@ YANG_PATCH_WHERE_LAST
insert lsat (default)
Definition: yang_patch.h:113
yang_patch_edit_type_to_str
const xmlChar * yang_patch_edit_type_to_str(yang_patch_edit_type_t typ)
Convert a YANG Patch edit type enum to the string for the enumeration.
Definition: yang_patch.c:583
OP_EDITOP_MERGE
@ OP_EDITOP_MERGE
edit op is merge
Definition: op.h:124
val_find_next_child
val_value_t * val_find_next_child(const val_value_t *parent, const xmlChar *modname, const xmlChar *childname, const val_value_t *curchild)
Find the next instance of the specified child node.
Definition: val.c:8748
VAL_ENUM_NAME
#define VAL_ENUM_NAME(V)
Access the enum name in the value ONLY if BCX_NT_ENUM This is the macro used to check values in SIL c...
Definition: val.h:434
val_remove_child
void val_remove_child(val_value_t *child)
Remove a child value node from its parent value node.
Definition: val.c:8316
yang_patch_edit_to_value
val_value_t * yang_patch_edit_to_value(obj_template_t *edit_obj, yang_patch_edit_t *edit, status_t *res)
Convert a YANG Patch edit to a val_value_t tree.
Definition: yang_patch.c:680
NO_ERR
@ NO_ERR
000
Definition: status_enum.h:188
val_add_child
void val_add_child(val_value_t *child, val_value_t *parent)
Add a child (deprecated: use val_child_add instead)
Definition: val.c:8231
val_dump_value
void val_dump_value(val_value_t *val, int32 startindent, log_debug_t lvl)
Printf the specified val_value_t struct to the logfile, or stdout if none set Uses conf file format (...
Definition: val.c:5688
yang_patch_str_to_op
yang_patch_op_t yang_patch_str_to_op(const xmlChar *opstr)
Convert a YANG Patch operation string to the operation enumeration for the string.
Definition: yang_patch.c:465
val_get_nsid
xmlns_id_t val_get_nsid(const val_value_t *val)
Get the namespace ID for the specified value node.
Definition: val.c:12277
ERR_NCX_OPERATION_FAILED
@ ERR_NCX_OPERATION_FAILED
274
Definition: status_enum.h:315
yang_patch_edit_t_::point
xmlChar * point
point parameter for insert from request
Definition: yang_patch.h:132
val_gen_index_chain
status_t val_gen_index_chain(const obj_template_t *obj, val_value_t *val)
Create an index chain for the just-parsed table or container struct.
Definition: val_util.c:2632
OP_EDITOP_DELETE
@ OP_EDITOP_DELETE
edit op is delete
Definition: op.h:127
dlq_createSQue
void dlq_createSQue(dlq_hdrT *queAddr)
create a static queue header
Definition: dlq.c:177
ERR_INTERNAL_VAL
@ ERR_INTERNAL_VAL
004
Definition: status_enum.h:194
yang_patch_value_to_edit
yang_patch_edit_t * yang_patch_value_to_edit(val_value_t *edit_val, boolean preserve_editval, status_t *res)
Convert a val_value_t tree to a YANG Patch edit.
Definition: yang_patch.c:934
val_child_add
status_t val_child_add(val_value_t *child, val_value_t *parent)
Add a child value node to a parent value node.
Definition: val_child.c:1542
yang_patch_cleanup
void yang_patch_cleanup(void)
Cleanup the yang_patch module.
Definition: yang_patch.c:141
val_util.h
Value Node Utilities.
yang_patch_edit_type_t_
yang_patch_edit_type_t_
Internal edit type for access control and DB-API support.
Definition: yang_patch.h:100
yang_patch_op_to_editop
op_editop_t yang_patch_op_to_editop(yang_patch_op_t op, boolean *is_insert)
Convert a YANG Patch operation enum to the corresponding edit operation.
Definition: yang_patch.c:1149
YANG_PATCH_OP_REMOVE
@ YANG_PATCH_OP_REMOVE
remove
Definition: yang_patch.h:95
yang_patch_new_edit2
yang_patch_edit_t * yang_patch_new_edit2(const xmlChar *edit_id, yang_patch_op_t operation, const xmlChar *target, const xmlChar *point, yang_patch_where_t insert_where, val_value_t *value, boolean plain_clone)
Malloc a new YANG Patch edit control block Any of the fields can be NULL to add later or not use.
Definition: yang_patch.c:293
yang_patch_free_edit
void yang_patch_free_edit(yang_patch_edit_t *edit)
Free a YANG Patch edit control block.
Definition: yang_patch.c:367
yang_patch_edit_t_::target
xmlChar * target
data path target from request
Definition: yang_patch.h:129
log_debug_append
void void void void void void void void log_debug_append(const char *fstr,...) __attribute__((format(printf
Append to a LOG_DEBUG_DEBUG log entry.
ERR_INTERNAL_MEM
@ ERR_INTERNAL_MEM
003
Definition: status_enum.h:193
val_clone
val_value_t * val_clone(const val_value_t *val)
Clone a specified val_value_t struct and sub-trees.
Definition: val.c:7836
val_child.h
Value Node Child Access Support.
get_error_string
const char * get_error_string(status_t res)
Get the error message for a specific internal error.
Definition: status.c:239
YANG_PATCH_OP_INSERT
@ YANG_PATCH_OP_INSERT
insert
Definition: yang_patch.h:91
log_debug
void void void void void void void log_debug(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_DEBUG log entry.
typ.h
Parameter Type Handler.
dlq_count
unsigned int dlq_count(const dlq_hdrT *listP)
get the number of queue entries in the listP queue list
Definition: dlq.c:994
yangconst.h
Contains YANG constants separated to prevent H file include loops.
OP_EDITOP_COMMIT
@ OP_EDITOP_COMMIT
commit, internal enum
Definition: op.h:129
yang_patch_edit_t_::targval
val_value_t * targval
REAL target value for the current EDIT.
Definition: yang_patch.h:146
yang_patch.h
YANG Patch Media Type.
dlq_nextEntry
#define dlq_nextEntry(nodeP)
get the next queue entry after the current entry
Definition: dlq.h:265
OP_EDITOP_DELETE_ALL
@ OP_EDITOP_DELETE_ALL
delete-all, yumapro only
Definition: op.h:131
yang_patch_str_to_where
yang_patch_where_t yang_patch_str_to_where(const xmlChar *wherestr)
Convert a YANG Patch where string to the where enumeration for the string.
Definition: yang_patch.c:611
YANG_PATCH_OP_MOVE
@ YANG_PATCH_OP_MOVE
move
Definition: yang_patch.h:93
ERR_NCX_NOT_FOUND
@ ERR_NCX_NOT_FOUND
225
Definition: status_enum.h:264
yang_patch_to_value
val_value_t * yang_patch_to_value(obj_template_t *patch_obj, yang_patch_cb_t *pcb, status_t *res)
Convert a YANG Patch control block to a val_value_t tree.
Definition: yang_patch.c:846
yang_patch_edit_t_::edit_id
xmlChar * edit_id
edit identifier string from request
Definition: yang_patch.h:123
yang_patch_editop_to_op
yang_patch_op_t yang_patch_editop_to_op(op_editop_t edit_op)
Convert an edit operation enum to a YANG Patch operation enum.
Definition: yang_patch.c:1195
yang_patch_new_cb
yang_patch_cb_t * yang_patch_new_cb(const xmlChar *patch_id, const xmlChar *the_comment, const xmlChar *target)
Malloc a new YANG Patch control block.
Definition: yang_patch.c:162
YANG_PATCH_OP_REPLACE
@ YANG_PATCH_OP_REPLACE
replace
Definition: yang_patch.h:94
YANG_PATCH_WHERE_BEFORE
@ YANG_PATCH_WHERE_BEFORE
insert before foo
Definition: yang_patch.h:110
yang_patch_op_t_
yang_patch_op_t_
YANG Patch operation type.
Definition: yang_patch.h:87
YANG_PATCH_WHERE_FIRST
@ YANG_PATCH_WHERE_FIRST
insert first
Definition: yang_patch.h:112
obj_find_child
obj_template_t * obj_find_child(obj_template_t *obj, const xmlChar *modname, const xmlChar *objname)
Find a child object with the specified Qname.
Definition: obj.c:6116
yang_patch_edit_t_::lastedit
boolean lastedit
flag for last edit
Definition: yang_patch.h:149
xml_strcmp
int xml_strcmp(const xmlChar *s1, const xmlChar *s2)
String compare for xmlChar.
Definition: xml_util.c:1746
OP_EDITOP_LOAD
@ OP_EDITOP_LOAD
load, internal enum
Definition: op.h:128
ncxmod_load_module
status_t ncxmod_load_module(const xmlChar *modname, const xmlChar *revision, dlq_hdr_t *savedevQ, ncx_module_t **retmod)
Determine the location of the specified module and then load it into the system, if not already loade...
Definition: ncxmod.c:4342
yang_patch_edit_count
uint32 yang_patch_edit_count(yang_patch_cb_t *pcb)
Get the number of edits in the PCB.
Definition: yang_patch.c:443
log.h
NCX System Logging Manager.
ncxtypes.h
YANG module data structures Many internal representations of YANG module constructs.
yang_patch_edit_t_
Represents one YANG Patch edit entry.
Definition: yang_patch.h:118
YANG_PATCH_OP_NONE
@ YANG_PATCH_OP_NONE
not set
Definition: yang_patch.h:88
LOGDEBUG
#define LOGDEBUG
Check if at least log-level=debug.
Definition: log.h:287
yang_patch_cb_t_::edit_type
yang_patch_edit_type_t edit_type
edit type (user or system)
Definition: yang_patch.h:163
OP_EDITOP_REMOVE
@ OP_EDITOP_REMOVE
remove, base:1.1 only
Definition: op.h:130
val_clone_config_save
val_value_t * val_clone_config_save(const val_value_t *val, status_t *res)
Clone a specified val_value_t struct and sub-trees filter for config only for saving to NVRAM.
Definition: val.c:7941
yang_patch_cb_t_::editQ
dlq_hdr_t editQ
Parsed edits: Q of yang_patch_edit_t.
Definition: yang_patch.h:181
dlq_deque
void * dlq_deque(dlq_hdrT *listP)
remove the first queue node from the queue list
Definition: dlq.c:286
dlq_empty
#define dlq_empty(listP)
check if queue list is empty
Definition: dlq.h:367
VAL_BTYPE
#define VAL_BTYPE(V)
Access the base type : same as VAL_TYPE.
Definition: val.h:548
dlq_firstEntry
#define dlq_firstEntry(listP)
get the first entry in the queue list
Definition: dlq.h:337
val_new_value
val_value_t * val_new_value(void)
Malloc and initialize the fields in a val_value_t.
Definition: val.c:2697
ncx.h
YANG module utility functions.
yang_patch_cb_t_::skip_sil
boolean skip_sil
skip SIL callback; used by DB-API to control edit in main server
Definition: yang_patch.h:166
yang_patch_edit_t_::operation
yang_patch_op_t operation
edit operation from request
Definition: yang_patch.h:126
OP_EDITOP_REMOVE_ALL
@ OP_EDITOP_REMOVE_ALL
remove-all, yumapro only
Definition: op.h:132
obj.h
Data Object Support.
yang_patch_cb_t_::comment
xmlChar * comment
comment provided for this patch
Definition: yang_patch.h:169
yang_patch_cb_t_
One YANG Patch Request.
Definition: yang_patch.h:155
val_init_from_template
void val_init_from_template(val_value_t *val, struct obj_template_t_ *obj)
Initialize a value node from its object template.
dlq_enque
void dlq_enque(REG void *newP, REG dlq_hdrT *listP)
add a queue node to the end of a queue list Add newP to listP
Definition: dlq.c:246
yang_patch_dump_pcb
void yang_patch_dump_pcb(yang_patch_cb_t *pcb)
Dump the current Patch Control block with all the edits.
Definition: yang_patch.c:1240
yang_patch_new_edit
yang_patch_edit_t * yang_patch_new_edit(const xmlChar *edit_id, yang_patch_op_t operation, const xmlChar *target, const xmlChar *point, yang_patch_where_t insert_where, val_value_t *value)
Malloc a new YANG Patch edit control block Any of the fields can be NULL to add later or not use.
Definition: yang_patch.c:255
VAL_STR
#define VAL_STR(V)
Access the value as a string ONLY if typ_is_string() is true.
Definition: val.h:464
SET_ERROR
#define SET_ERROR(E)
macro SET_ERROR
Definition: status_enum.h:103
yang_patch_cb_t_::qhdr
dlq_hdr_t qhdr
in case used in Queue of patches
Definition: yang_patch.h:157
yang_patch_edit_t_::insert_where
yang_patch_where_t insert_where
insert where parameter for insert from request
Definition: yang_patch.h:135
yang_patch_find_edit
yang_patch_edit_t * yang_patch_find_edit(yang_patch_cb_t *pcb, const xmlChar *edit_id)
Find an edit by its edit_id in the YANG Patch.
Definition: yang_patch.c:414
yang_patch_str_to_edit_type
yang_patch_edit_type_t yang_patch_str_to_edit_type(const xmlChar *str)
Convert a YANG Patch edit-type string to the edit_type enumeration for the string.
Definition: yang_patch.c:553
yang_patch_value_to_patch
yang_patch_cb_t * yang_patch_value_to_patch(val_value_t *patch_val, const xmlChar *target, boolean preserve_patchval, status_t *res)
Convert a val_value tree to a YANG Patch control block.
Definition: yang_patch.c:1055
val_free_value
void val_free_value(val_value_t *val)
Scrub the memory in a val_value_t by freeing all the sub-fields and then freeing the entire struct it...
Definition: val.c:2842
status.h
Global error messages for status code enumerations.
YANG_PATCH_EDIT_TYPE_USER
@ YANG_PATCH_EDIT_TYPE_USER
edit by user
Definition: yang_patch.h:102
dlq.h
dlq provides general double-linked list and queue support:
yang_patch_cb_t_::patch_id
xmlChar * patch_id
patch ID is usually the transaction-id
Definition: yang_patch.h:160
yang_patch_where_to_str
const xmlChar * yang_patch_where_to_str(yang_patch_where_t wh)
Convert a YANG Patch where enum to the where string for the enumeration.
Definition: yang_patch.c:645
yang_patch_cb_t_::target
xmlChar * target
In case of HA and NETCONF this 'target' uses the datastore root '/' as the target resource and use th...
Definition: yang_patch.h:178