@@ -5185,6 +5185,78 @@ lys_data_path(const struct lys_node *node)
5185
5185
return result ;
5186
5186
}
5187
5187
5188
+ API char *
5189
+ lys_data_path_pattern (const struct lys_node * node , const char * placeholder )
5190
+ {
5191
+ FUN_IN ;
5192
+
5193
+ const struct lys_module * prev_mod , * mod ;
5194
+ char * result = NULL , keys [512 ], buf [2048 ];
5195
+ const char * name , * separator ;
5196
+ struct ly_set * set ;
5197
+ size_t x ;
5198
+ int i ;
5199
+
5200
+ if (!node || !placeholder ) {
5201
+ LOGARG ;
5202
+ return NULL ;
5203
+ }
5204
+
5205
+ buf [0 ] = '\0' ;
5206
+ set = ly_set_new ();
5207
+ LY_CHECK_ERR_GOTO (!set , LOGMEM (node -> module -> ctx ), cleanup );
5208
+
5209
+ /* collect all schema nodes that can be instantiated into a set */
5210
+ while (node ) {
5211
+ ly_set_add (set , (void * )node , 0 );
5212
+ do {
5213
+ node = lys_parent (node );
5214
+ } while (node && (node -> nodetype & (LYS_USES | LYS_CHOICE | LYS_CASE | LYS_INPUT | LYS_OUTPUT )));
5215
+ }
5216
+
5217
+ x = 0 ;
5218
+ prev_mod = NULL ;
5219
+
5220
+ /* build path for all the collected nodes */
5221
+ for (i = set -> number - 1 ; i > -1 ; -- i ) {
5222
+ size_t k = 0 ;
5223
+ keys [0 ] = '\0' ;
5224
+ node = set -> set .s [i ];
5225
+ if (node -> nodetype == LYS_EXT ) {
5226
+ if (strcmp (((struct lys_ext_instance * )node )-> def -> name , "yang-data" )) {
5227
+ continue ;
5228
+ }
5229
+ name = ((struct lys_ext_instance * )node )-> arg_value ;
5230
+ separator = ":#" ;
5231
+ } else {
5232
+ name = node -> name ;
5233
+ separator = ":" ;
5234
+ }
5235
+ if (node -> nodetype == LYS_LIST ) {
5236
+ /* add specific key values (placeholders) for list */
5237
+ const struct lys_node_list * list ;
5238
+ list = (const struct lys_node_list * )node ;
5239
+ for (uint8_t j = 0 ; j < list -> keys_size ; j ++ ) {
5240
+ k += sprintf (keys + k , "[%s=%s]" , list -> keys [j ]-> name , placeholder );
5241
+ }
5242
+ }
5243
+ mod = lys_node_module (node );
5244
+ if (mod && mod != prev_mod ) {
5245
+ prev_mod = mod ;
5246
+ x += sprintf (buf + x , "/%s%s%s%s" , mod -> name , separator , name , keys );
5247
+ } else {
5248
+ x += sprintf (buf + x , "/%s%s" , name , keys );
5249
+ }
5250
+ }
5251
+
5252
+ result = strdup (buf );
5253
+ LY_CHECK_ERR_GOTO (!result , LOGMEM (node -> module -> ctx ), cleanup );
5254
+
5255
+ cleanup :
5256
+ ly_set_free (set );
5257
+ return result ;
5258
+ }
5259
+
5188
5260
struct lys_node_augment *
5189
5261
lys_getnext_target_aug (struct lys_node_augment * last , const struct lys_module * mod , const struct lys_node * aug_target )
5190
5262
{
0 commit comments