libamxd  6.4.1
Data Model Manager
amxd_path.c
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** SPDX-License-Identifier: BSD-2-Clause-Patent
4 **
5 ** SPDX-FileCopyrightText: Copyright (c) 2023 SoftAtHome
6 **
7 ** Redistribution and use in source and binary forms, with or without modification,
8 ** are permitted provided that the following conditions are met:
9 **
10 ** 1. Redistributions of source code must retain the above copyright notice,
11 ** this list of conditions and the following disclaimer.
12 **
13 ** 2. Redistributions in binary form must reproduce the above copyright notice,
14 ** this list of conditions and the following disclaimer in the documentation
15 ** and/or other materials provided with the distribution.
16 **
17 ** Subject to the terms and conditions of this license, each copyright holder
18 ** and contributor hereby grants to those receiving rights under this license
19 ** a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable
20 ** (except for failure to satisfy the conditions of this license) patent license
21 ** to make, have made, use, offer to sell, sell, import, and otherwise transfer
22 ** this software, where such license applies only to those patent claims, already
23 ** acquired or hereafter acquired, licensable by such copyright holder or contributor
24 ** that are necessarily infringed by:
25 **
26 ** (a) their Contribution(s) (the licensed copyrights of copyright holders and
27 ** non-copyrightable additions of contributors, in source or binary form) alone;
28 ** or
29 **
30 ** (b) combination of their Contribution(s) with the work of authorship to which
31 ** such Contribution(s) was added by such copyright holder or contributor, if,
32 ** at the time the Contribution is added, such addition causes such combination
33 ** to be necessarily infringed. The patent license shall not apply to any other
34 ** combinations which include the Contribution.
35 **
36 ** Except as expressly stated above, no rights or licenses from any copyright
37 ** holder or contributor is granted under this license, whether expressly, by
38 ** implication, estoppel or otherwise.
39 **
40 ** DISCLAIMER
41 **
42 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
46 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
48 ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
49 ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50 ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
51 ** USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 **
53 ****************************************************************************/
54 
55 #include <string.h>
56 #include <stdlib.h>
57 #include <stdio.h>
58 #include <ctype.h>
59 #include <limits.h>
60 #include <errno.h>
61 
62 #include <amxc/amxc.h>
63 #include <amxp/amxp.h>
64 
65 #include <amxd/amxd_object.h>
66 #include <amxd/amxd_path.h>
67 
68 #include "amxd_priv.h"
69 #include "amxd_object_priv.h"
70 #include "amxd_assert.h"
71 
72 static bool amxd_build_path_common(amxc_string_t* path_part, amxc_var_t* path_parts,
73  const char* token, bool* quotes, bool* sb, bool* cb) {
74  bool dot = false;
75  switch(token[0]) {
76  case '"':
77  case '\'':
78  amxc_string_appendf(path_part, "%s", token);
79  (*quotes) = !(*quotes);
80  break;
81  case '*':
82  amxc_string_appendf(path_part, "%s", token);
83  if(!(*quotes)) {
84  amxc_var_add(cstring_t, path_parts, amxc_string_get(path_part, 0));
85  amxc_string_reset(path_part);
86  }
87  break;
88  case '[':
89  if(!(*quotes)) {
90  *sb = true;
91  }
92  amxc_string_appendf(path_part, "%s", token);
93  break;
94  case ']':
95  amxc_string_appendf(path_part, "%s", token);
96  if(!(*quotes)) {
97  amxc_var_add(cstring_t, path_parts, amxc_string_get(path_part, 0));
98  amxc_string_reset(path_part);
99  *sb = false;
100  }
101  break;
102  case '{':
103  *cb = true;
104  amxc_string_appendf(path_part, "%s", token);
105  break;
106  case '}':
107  amxc_string_appendf(path_part, "%s", token);
108  amxc_var_add(cstring_t, path_parts, amxc_string_get(path_part, 0));
109  amxc_string_reset(path_part);
110  *cb = false;
111  break;
112  case '.':
113  amxc_string_appendf(path_part, "%s", token);
114  dot = !(*quotes) && !(*sb);
115  break;
116  case '+':
117  case '#':
118  if(!(*quotes) && !(*sb)) {
119  amxc_var_add(cstring_t, path_parts, amxc_string_get(path_part, 0));
120  amxc_string_reset(path_part);
121  amxc_string_appendf(path_part, "%s", token);
122  dot = !(*quotes) && !(*sb);
123  }
124  break;
125  default:
126  amxc_string_appendf(path_part, "%s", token);
127  break;
128  }
129  return dot;
130 }
131 
132 static amxc_string_split_status_t amxd_build_path_parts(amxc_llist_t* all,
133  amxc_var_t* path_parts) {
134  bool quotes = false;
135  bool sb = false;
136  bool cb = false;
137  amxc_string_t path_part;
138 
139  amxc_var_set_type(path_parts, AMXC_VAR_ID_LIST);
140 
141  amxc_string_init(&path_part, 0);
142  amxc_llist_for_each(it, all) {
143  amxc_string_t* part = amxc_string_from_llist_it(it);
144  const char* txt_part = amxc_string_get(part, 0);
145  if(amxc_string_text_length(part) == 1) {
146  if(amxd_build_path_common(&path_part, path_parts, txt_part, &quotes, &sb, &cb)) {
147  amxc_var_add(cstring_t, path_parts, amxc_string_get(&path_part, 0));
148  amxc_string_reset(&path_part);
149  }
150  } else {
151  amxc_string_appendf(&path_part, "%s", txt_part);
152  }
153  }
154  if(amxc_string_text_length(&path_part) > 0) {
155  amxc_var_add(cstring_t, path_parts, amxc_string_get(&path_part, 0));
156  }
157  amxc_string_clean(&path_part);
158  return AMXC_STRING_SPLIT_OK;
159 }
160 
162  bool has_supported = false;
163  bool has_search = false;
164  bool has_ref_index = false;
166 
167  path->ref_index = 1;
168 
169  amxc_var_for_each(part, (&path->parts)) {
170  const char* path_str = amxc_var_constcast(cstring_t, part);
171  if(has_ref_index) {
172  char* endptr = NULL;
173  path->ref_index = labs(strtol(path_str, &endptr, 0));
174  when_true_status(((errno == ERANGE) && ((path->ref_index == 0) || (path->ref_index == ULONG_MAX))) ||
175  ((errno != 0) && (path->ref_index == 0)),
176  exit,
177  type = amxd_path_invalid);
178  when_true_status((endptr == path_str) || (*endptr != '\0'),
179  exit,
180  type = amxd_path_invalid);
181  has_ref_index = false;
182  continue;
183  }
184  switch(path_str[0]) {
185  case '{':
186  if(strncmp(path_str, "{i}", 3) != 0) {
187  type = amxd_path_invalid;
188  goto exit;
189  }
190  has_supported = true;
191  break;
192  case '*':
193  case '[':
194  has_search = true;
195  break;
196  case '"':
197  case '\'':
198  type = amxd_path_invalid;
199  goto exit;
200  break;
201  case '+':
202  type = amxd_path_reference;
203  goto exit;
204  break;
205  case '#':
206  has_ref_index = true;
207  break;
208  }
209  }
210 
211  if(path->param != NULL) {
212  if((path->param[0] == '{') && has_search) {
213  type = amxd_path_invalid;
214  goto exit;
215  }
216  }
217 
218  if(has_supported && !has_search) {
219  type = amxd_path_supported;
220  } else if(!has_supported && has_search) {
221  type = amxd_path_search;
222  } else if(has_supported && has_search) {
223  type = amxd_path_invalid;
224  }
225 
226  path->ref_index = (type != amxd_path_reference)? 0:path->ref_index;
227 
228 exit:
229  return type;
230 }
231 
234  amxc_llist_it_t* last = amxc_llist_get_last(&path->parts.data.vl);
235  amxc_var_t* last_part = amxc_var_from_llist_it(last);
236  const char* name = amxc_var_constcast(cstring_t, last_part);
237  int length = 0;
238 
239  when_str_empty(name, exit);
240  length = strlen(name);
241 
242  if(name[length - 1] != '.') {
243  path->param = amxc_var_take(cstring_t, last_part);
244 
245  if(path->param[0] == '[') {
247  amxc_var_push(cstring_t, last_part, path->param);
248  path->param = NULL;
249  goto exit;
250  }
251 
252  amxc_llist_it_take(last);
253 
254  if(amxc_llist_is_empty(&path->parts.data.vl)) {
255  amxc_var_set(cstring_t, last_part, ".");
256  amxc_llist_append(&path->parts.data.vl, last);
257  } else {
258  amxc_var_delete(&last_part);
259  }
260 
261  amxc_string_reset(&path->path);
262  amxc_string_join_var(&path->path, &path->parts, "");
263  }
264 
265 exit:
266  return status;
267 }
268 
270  amxc_string_split_builder_t fn) {
272 
273  amxc_var_set_type(&path->parts, AMXC_VAR_ID_LIST);
274  when_true_status(amxc_string_is_empty(&path->path),
275  exit,
277 
278  if(fn == NULL) {
280  }
281 
282  if(amxc_string_split(&path->path,
283  &path->parts,
284  fn,
285  &path->reason) != AMXC_STRING_SPLIT_OK) {
287  amxc_var_clean(&path->parts);
288  goto exit;
289  }
291 
292 exit:
293  return status;
294 }
295 
296 static int isdot(int c) {
297  return (c == '.') ? 1 : 0;
298 }
299 
300 static void amxd_path_add_dot(amxd_path_t* path, bool add_dot) {
301  if(!amxc_string_is_empty(&path->path) && add_dot) {
302  if(path->path.buffer[path->path.last_used - 1] != '.') {
303  amxc_string_append(&path->path, ".", 1);
304  }
305  }
306 }
307 
310  if((path->path.last_used > 0) &&
311  ( path->path.buffer[path->path.last_used - 1] == '*')) {
312  path->type = amxd_path_invalid;
314  goto exit;
315  }
316  status = amxd_path_split(path, NULL);
317  if(status != amxd_status_ok) {
318  path->type = amxd_path_invalid;
319  } else {
320  path->type = amxd_path_is(path);
322  }
323 
324 exit:
325  return status;
326 }
327 
329  const char* object_path) {
331 
332  when_null(path, exit);
333 
334  amxc_var_init(&path->parts);
335  amxc_var_set_type(&path->parts, AMXC_VAR_ID_LIST);
336 
337  amxc_string_init(&path->path, 0);
338  path->reason = NULL;
339  path->param = NULL;
340 
341  if(object_path != NULL) {
342  when_failed(amxc_string_setf(&path->path, "%s", object_path), exit);
343  }
344 
345  status = amxd_path_validate(path);
346 
347 exit:
348  return status;
349 }
350 
352  when_null(path, exit);
353 
354  amxc_var_clean(&path->parts);
355  amxc_string_clean(&path->path);
356  path->reason = NULL;
357  free(path->param);
358  path->param = NULL;
359  path->type = amxd_path_invalid;
360 
361 exit:
362  return;
363 }
364 
366  const char* object_path) {
368 
369  when_null(path, exit);
370  *path = (amxd_path_t*) calloc(1, sizeof(amxd_path_t));
371 
372  status = amxd_path_init((*path), object_path);
373 
374 exit:
375  return status;
376 }
377 
379  when_null(path, exit);
380  amxd_path_clean(*path);
381 
382  free(*path);
383  *path = NULL;
384 
385 exit:
386  return;
387 }
388 
390  when_null(path, exit);
391 
392  amxc_string_reset(&path->path);
393  amxc_var_clean(&path->parts);
394  path->type = amxd_path_invalid;
395  path->reason = NULL;
396  free(path->param);
397  path->param = NULL;
398 
399 exit:
400  return;
401 }
402 
404  bool add_dot,
405  const char* obj_path,
406  va_list args) {
408 
409  when_null(path, exit);
410  when_str_empty(obj_path, exit);
411 
412  amxd_path_reset(path);
413 
414  amxc_string_vsetf(&path->path, obj_path, args);
415 
416  amxd_path_add_dot(path, add_dot);
417 
418  status = amxd_path_validate(path);
419 
420 exit:
421  return status;
422 }
423 
425  bool add_dot,
426  const char* obj_path, ...) {
428  va_list args;
429 
430  when_null(path, exit);
431  when_str_empty(obj_path, exit);
432 
433  va_start(args, obj_path);
434  status = amxd_path_vsetf(path, add_dot, obj_path, args);
435  va_end(args);
436 
437 exit:
438  return status;
439 }
440 
441 amxd_status_t amxd_path_append(amxd_path_t* path, const char* extension, bool add_dot) {
443 
444  when_null(path, exit);
445  when_str_empty(extension, exit);
446 
447  amxc_string_appendf(&path->path, "%s", extension);
448  amxd_path_add_dot(path, add_dot);
449 
450  status = amxd_path_validate(path);
451 
452 exit:
453  return status;
454 }
455 
456 amxd_status_t amxd_path_prepend(amxd_path_t* path, const char* extension) {
458 
459  when_null(path, exit);
460  when_str_empty(extension, exit);
461 
462  amxc_string_prependf(&path->path, "%s", extension);
463 
464  status = amxd_path_validate(path);
465 
466 exit:
467  return status;
468 }
469 
470 const char* amxd_path_get(amxd_path_t* path, int flags) {
471  size_t length = 0;
472  const char* obj_path = NULL;
473 
474  when_null(path, exit)
475  when_true(amxc_string_is_empty(&path->path), exit);
476 
477  length = amxc_string_text_length(&path->path);
478  obj_path = amxc_string_get(&path->path, 0);
479 
480  if(flags & AMXD_OBJECT_TERMINATE) {
481  if(obj_path[length - 1] != '.') {
482  amxc_string_append(&path->path, ".", 1);
483  }
484  } else {
485  amxc_string_trimr(&path->path, isdot);
486  }
487 
488  obj_path = amxc_string_get(&path->path, 0);
489 
490 exit:
491  if(obj_path == NULL) {
492  obj_path = "";
493  }
494  return obj_path;
495 }
496 
497 const char* amxd_path_get_param(amxd_path_t* path) {
498  return path == NULL ? NULL : path->param;
499 }
500 
501 char* amxd_path_get_first(amxd_path_t* path, bool remove) {
502  amxc_string_t first_part;
503  char* first = NULL;
504  amxc_var_t* path_part = NULL;
505  int length = 0;
506  const char* path_str = NULL;
507  amxc_string_init(&first_part, 0);
508 
509  when_null(path, exit);
510  when_true(amxc_llist_is_empty(&path->parts.data.vl), exit);
511 
512  path_part = amxc_var_from_llist_it(amxc_llist_get_first(&path->parts.data.vl));
513  path_str = amxc_var_constcast(cstring_t, path_part);
514  length = strlen(path_str);
515  amxc_string_append(&first_part, path_str, length);
516  if(remove) {
517  amxc_var_delete(&path_part);
518  }
519 
520  if(remove) {
521  amxc_string_reset(&path->path);
522  amxc_string_join_var(&path->path, &path->parts, "");
523  }
524 
525 exit:
526  first = amxc_string_take_buffer(&first_part);
527  amxc_string_clean(&first_part);
528  return first;
529 }
530 
531 char* amxd_path_get_last(amxd_path_t* path, bool remove) {
532  amxc_string_t last_part;
533  char* last = NULL;
534  amxc_var_t* path_part = NULL;
535  int length = 0;
536  const char* path_str = NULL;
537  amxc_string_init(&last_part, 0);
538 
539  when_null(path, exit);
540  when_true(amxc_llist_is_empty(&path->parts.data.vl), exit);
541 
542  path_part = amxc_var_from_llist_it(amxc_llist_get_last(&path->parts.data.vl));
543  path_str = amxc_var_constcast(cstring_t, path_part);
544  length = strlen(path_str);
545  amxc_string_prepend(&last_part, path_str, length);
546 
547  if(path_str[0] == '.') {
548  amxc_llist_it_t* prev = NULL;
549  if(remove) {
550  amxc_var_delete(&path_part);
551  prev = amxc_llist_get_last(&path->parts.data.vl);
552  } else {
553  prev = amxc_llist_it_get_previous(amxc_llist_get_last(&path->parts.data.vl));
554  }
555  if(prev != NULL) {
556  path_part = amxc_var_from_llist_it(prev);
557  path_str = amxc_var_constcast(cstring_t, path_part);
558  length = strlen(path_str);
559  amxc_string_prepend(&last_part, path_str, length);
560  }
561  }
562 
563  if(remove) {
564  amxc_var_delete(&path_part);
565  amxc_string_reset(&path->path);
566  amxc_string_join_var(&path->path, &path->parts, "");
567  }
568  path->type = amxd_path_is(path);
569 
570 exit:
571  last = amxc_string_take_buffer(&last_part);
572  amxc_string_clean(&last_part);
573  return last;
574 }
575 
576 char* amxd_path_get_fixed_part(amxd_path_t* path, bool remove) {
577  amxc_string_t fixed_part;
578  char* fixed = NULL;
579  amxc_string_init(&fixed_part, 0);
580 
581  when_null(path, exit);
582 
583  amxc_var_for_each(path_part, (&path->parts)) {
584  int length = 0;
585  const char* path_str = amxc_var_constcast(cstring_t, path_part);
586  if((path_str[0] == '*') ||
587  (path_str[0] == '[') ||
588  (path_str[0] == '{') ||
589  (path_str[0] == '+') ||
590  (path_str[0] == '#')) {
591  break;
592  }
593  length = strlen(path_str);
594  amxc_string_append(&fixed_part, path_str, length);
595  if(remove) {
596  amxc_var_delete(&path_part);
597  }
598  }
599 
600  if(remove) {
601  amxc_string_reset(&path->path);
602  amxc_string_join_var(&path->path, &path->parts, "");
603  }
604 
605 exit:
606  fixed = amxc_string_take_buffer(&fixed_part);
607  amxc_string_clean(&fixed_part);
608  return fixed;
609 }
610 
612  amxc_string_t sup_path;
613  char* supported = NULL;
614  amxc_string_init(&sup_path, 0);
615 
616  when_null(path, exit);
617 
618  amxc_var_for_each(path_part, (&path->parts)) {
619  int length = 0;
620  const char* path_str = amxc_var_constcast(cstring_t, path_part);
621  if(path_str[0] == '{') {
622  continue;
623  }
624  if(isdigit(path_str[0])) {
625  continue;
626  }
627  length = strlen(path_str);
628  if((path_str[0] == '.') && (length == 1)) {
629  continue;
630  }
631  amxc_string_append(&sup_path, path_str, strlen(path_str));
632  }
633 
634 exit:
635  supported = amxc_string_take_buffer(&sup_path);
636  amxc_string_clean(&sup_path);
637  return supported;
638 }
639 
640 char* amxd_path_get_reference_part(amxd_path_t* path, bool remove) {
641  amxc_string_t ref_part;
642  char* ref = NULL;
643  bool has_ref_index = false;
644  amxc_string_init(&ref_part, 0);
645 
646  when_null(path, exit);
647 
648  amxc_var_for_each(path_part, (&path->parts)) {
649  int length = 0;
650  const char* path_str = amxc_var_constcast(cstring_t, path_part);
651  if(has_ref_index) {
652  if(remove) {
653  amxc_var_delete(&path_part);
654  }
655  has_ref_index = false;
656  continue;
657  }
658  if(path_str[0] == '+') {
659  if(remove) {
660  amxc_var_delete(&path_part);
661  }
662  break;
663  }
664  if(path_str[0] == '#') {
665  if(remove) {
666  amxc_var_delete(&path_part);
667  }
668  has_ref_index = true;
669  continue;
670  }
671  length = strlen(path_str);
672  amxc_string_append(&ref_part, path_str, length);
673  if(remove) {
674  amxc_var_delete(&path_part);
675  }
676  }
677 
678  if(remove) {
679  amxc_string_reset(&path->path);
680  amxc_string_join_var(&path->path, &path->parts, "");
681  }
682 
683 exit:
684  ref = amxc_string_take_buffer(&ref_part);
685  amxc_string_clean(&ref_part);
686  return ref;
687 }
688 
690  uint32_t index = 0;
691  when_null(path, exit);
692 
693  index = path->ref_index;
694 
695 exit:
696  return index;
697 }
698 
700  amxc_string_t sup_path;
701  char* supported = NULL;
702  char* endptr = NULL;
703 
704  amxc_string_init(&sup_path, 0);
705  when_null(path, exit);
706 
707  amxc_var_for_each(path_part, (&path->parts)) {
708  int length = 0;
709  const char* path_str = amxc_var_constcast(cstring_t, path_part);
710  if((path_str[0] == '*') || (path_str[0] == '[')) {
711  amxc_string_append(&sup_path, "{i}.", 4);
712  continue;
713  }
714  length = strlen(path_str);
715  if((path_str[0] == '.') && (length == 1)) {
716  continue;
717  }
718 
719  strtoll(path_str, &endptr, 0);
720  if((endptr == path_str) || (*endptr != '.')) {
721  amxc_string_append(&sup_path, path_str, strlen(path_str));
722  } else {
723  amxc_string_append(&sup_path, "{i}.", 4);
724  }
725  }
726 
727 exit:
728  supported = amxc_string_take_buffer(&sup_path);
729  amxc_string_clean(&sup_path);
730  return supported;
731 }
732 
733 uint32_t amxd_path_get_depth(const amxd_path_t* const path) {
734  uint32_t level = 0;
735 
736  when_null(path, exit);
737  when_true(amxc_var_type_of(&path->parts) != AMXC_VAR_ID_LIST, exit);
738 
739  amxc_var_for_each(path_part, (&path->parts)) {
740  int length = 0;
741  const char* path_str = amxc_var_constcast(cstring_t, path_part);
742  length = strlen(path_str);
743  if((path_str[0] == '.') && (length == 1)) {
744  continue;
745  }
746  level++;
747  }
748 
749 exit:
750  return level;
751 }
752 
753 bool amxd_path_is_instance_path(const amxd_path_t* const path) {
754  bool is_instance = false;
755  const amxc_llist_t* parts = NULL;
756  amxc_llist_it_t* part_it = NULL;
757  const char* part_txt = NULL;
758  char* endptr = NULL;
759 
760  when_null(path, exit);
761  when_true(amxc_var_type_of(&path->parts) != AMXC_VAR_ID_LIST, exit);
762 
763  parts = amxc_var_constcast(amxc_llist_t, &path->parts);
764  part_it = amxc_llist_get_last(parts);
765  when_null(part_it, exit);
766 
767  part_txt = amxc_var_constcast(cstring_t, amxc_var_from_llist_it(part_it));
768  if((part_txt != NULL) && (*part_txt == '.')) {
769  part_it = amxc_llist_it_get_previous(part_it);
770  when_null(part_it, exit);
771  part_txt = amxc_var_constcast(cstring_t, amxc_var_from_llist_it(part_it));
772  }
773  when_null(part_txt, exit);
774 
775  strtoll(part_txt, &endptr, 0);
776  if((endptr == NULL) || (*endptr == '.')) {
777  is_instance = true;
778  }
779  if((part_txt[0] == '[') || (part_txt[0] == '*')) {
780  is_instance = true;
781  }
782 
783 exit:
784  return is_instance;
785 }
786 
788  char* result = NULL;
789  amxc_string_t param_path;
790 
791  amxc_string_init(&param_path, 0);
792 
793  when_null(path, exit);
794  when_true(amxc_string_is_empty(&path->path), exit);
795  when_str_empty(path->param, exit);
796 
797  amxc_string_setf(&param_path, "%s%s", amxc_string_get(&path->path, 0), path->param);
798  result = amxc_string_take_buffer(&param_path);
799 
800 exit:
801  amxc_string_clean(&param_path);
802  return result;
803 }
Ambiorix Data Model API header file.
static amxd_status_t amxd_path_validate(amxd_path_t *path)
Definition: amxd_path.c:308
static void amxd_path_add_dot(amxd_path_t *path, bool add_dot)
Definition: amxd_path.c:300
amxd_status_t amxd_path_setf(amxd_path_t *path, bool add_dot, const char *obj_path,...)
Definition: amxd_path.c:424
static amxd_path_type_t amxd_path_is(amxd_path_t *path)
Definition: amxd_path.c:161
static int isdot(int c)
Definition: amxd_path.c:296
static amxc_string_split_status_t amxd_build_path_parts(amxc_llist_t *all, amxc_var_t *path_parts)
Definition: amxd_path.c:132
static amxd_status_t amxd_path_take_param(amxd_path_t *path)
Definition: amxd_path.c:232
static amxd_status_t amxd_path_split(amxd_path_t *path, amxc_string_split_builder_t fn)
Definition: amxd_path.c:269
static bool amxd_build_path_common(amxc_string_t *path_part, amxc_var_t *path_parts, const char *token, bool *quotes, bool *sb, bool *cb)
Definition: amxd_path.c:72
Ambiorix path API header file.
enum _amxd_path_type amxd_path_type_t
enum _amxd_status amxd_status_t
@ amxd_path_invalid
Definition: amxd_types.h:399
@ amxd_path_reference
Definition: amxd_types.h:403
@ amxd_path_supported
Definition: amxd_types.h:402
@ amxd_path_search
Definition: amxd_types.h:401
@ amxd_path_object
Definition: amxd_types.h:400
@ amxd_status_invalid_path
Definition: amxd_types.h:99
@ amxd_status_ok
Definition: amxd_types.h:78
@ amxd_status_unknown_error
Definition: amxd_types.h:79
#define AMXD_OBJECT_TERMINATE
Path format flag - when set the object path is terminated with a dot.
Definition: amxd_object.h:214
void amxd_path_delete(amxd_path_t **path)
Frees an allocated amxd_path_t structure.
Definition: amxd_path.c:378
amxd_status_t amxd_path_init(amxd_path_t *path, const char *object_path)
Initializes an amxd_path_t structure.
Definition: amxd_path.c:328
char * amxd_path_build_supported_path(amxd_path_t *path)
Creates the supported path representation of the given path.
Definition: amxd_path.c:699
const char * amxd_path_get_param(amxd_path_t *path)
Gets the parameter name.
Definition: amxd_path.c:497
uint32_t amxd_path_get_depth(const amxd_path_t *const path)
Calculates the depth of the path.
Definition: amxd_path.c:733
char * amxd_path_get_first(amxd_path_t *path, bool remove)
Gets the first part of the path.
Definition: amxd_path.c:501
char * amxd_path_get_last(amxd_path_t *path, bool remove)
Gets the last part of the path.
Definition: amxd_path.c:531
char * amxd_path_get_reference_part(amxd_path_t *path, bool remove)
Returns the reference path.
Definition: amxd_path.c:640
bool amxd_path_is_instance_path(const amxd_path_t *const path)
Checks if the path is in the instantiated data model.
Definition: amxd_path.c:753
amxd_status_t amxd_path_append(amxd_path_t *path, const char *extension, bool add_dot)
Appends a parameter name or object name/index to the path.
Definition: amxd_path.c:441
amxd_status_t amxd_path_new(amxd_path_t **path, const char *object_path)
Allocates and initializes an amxd_path_t structure.
Definition: amxd_path.c:365
const char * amxd_path_get(amxd_path_t *path, int flags)
Returns the path stored in the amxd_path_t structure.
Definition: amxd_path.c:470
char * amxd_path_get_supported_path(amxd_path_t *path)
Translates the path into a path that can be used to fetch the object definition.
Definition: amxd_path.c:611
amxd_status_t amxd_path_prepend(amxd_path_t *path, const char *extension)
Prepends an object name/index to the path.
Definition: amxd_path.c:456
char * amxd_path_get_param_path(amxd_path_t *path)
Get the full parameter path from the provided amxd_path_t struct.
Definition: amxd_path.c:787
void amxd_path_clean(amxd_path_t *path)
Cleans an amxd_path_t structure.
Definition: amxd_path.c:351
uint32_t amxd_path_get_reference_index(amxd_path_t *path)
Returns the reference path index.
Definition: amxd_path.c:689
amxd_status_t amxd_path_vsetf(amxd_path_t *path, bool add_dot, const char *obj_path, va_list args)
Sets or replaces the path contained in the amxd_path_t structure.
Definition: amxd_path.c:403
void amxd_path_reset(amxd_path_t *path)
Resets the amxd_path_t structure.
Definition: amxd_path.c:389
char * amxd_path_get_fixed_part(amxd_path_t *path, bool remove)
Gets the fixed part of the path.
Definition: amxd_path.c:576
amxd_path_type_t type
Definition: amxd_types.h:410
char * param
Definition: amxd_types.h:408
const char * reason
Definition: amxd_types.h:411
amxc_string_t path
Definition: amxd_types.h:407
amxc_var_t parts
Definition: amxd_types.h:409
uint64_t ref_index
Definition: amxd_types.h:412
static amxd_status_t status