libamxd  6.4.1
Data Model Manager
data model path API

Data model path helper functions. More...

Functions

amxd_status_t amxd_path_init (amxd_path_t *path, const char *object_path)
 Initializes an amxd_path_t structure. More...
 
void amxd_path_clean (amxd_path_t *path)
 Cleans an amxd_path_t structure. More...
 
amxd_status_t amxd_path_new (amxd_path_t **path, const char *object_path)
 Allocates and initializes an amxd_path_t structure. More...
 
void amxd_path_delete (amxd_path_t **path)
 Frees an allocated amxd_path_t structure. More...
 
void amxd_path_reset (amxd_path_t *path)
 Resets the amxd_path_t structure. More...
 
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. More...
 
amxd_status_t amxd_path_setf (amxd_path_t *path, bool add_dot, const char *obj_path,...) __attribute__((format(printf
 Sets or replaces the path contained in the amxd_path_t structure. More...
 
amxd_status_t 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. More...
 
amxd_status_t amxd_path_prepend (amxd_path_t *path, const char *extension)
 Prepends an object name/index to the path. More...
 
const char * amxd_path_get (amxd_path_t *path, int flags)
 Returns the path stored in the amxd_path_t structure. More...
 
const char * amxd_path_get_param (amxd_path_t *path)
 Gets the parameter name. More...
 
char * amxd_path_get_first (amxd_path_t *path, bool remove)
 Gets the first part of the path. More...
 
char * amxd_path_get_last (amxd_path_t *path, bool remove)
 Gets the last part of the path. More...
 
char * amxd_path_get_fixed_part (amxd_path_t *path, bool remove)
 Gets the fixed part of the path. More...
 
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. More...
 
char * amxd_path_get_reference_part (amxd_path_t *path, bool remove)
 Returns the reference path. More...
 
uint32_t amxd_path_get_reference_index (amxd_path_t *path)
 Returns the reference path index. More...
 
char * amxd_path_build_supported_path (amxd_path_t *path)
 Creates the supported path representation of the given path. More...
 
uint32_t amxd_path_get_depth (const amxd_path_t *const path)
 Calculates the depth of the path. More...
 
static amxd_path_type_t amxd_path_get_type (amxd_path_t *path)
 Returns the path type. More...
 
static bool amxd_path_is_valid (amxd_path_t *path)
 Checks if the path is valid path. More...
 
static bool amxd_path_is_search_path (amxd_path_t *path)
 Checks if the path is a search path. More...
 
static bool amxd_path_is_supported_path (amxd_path_t *path)
 Checks if the path is in the supported data model. More...
 
static bool amxd_path_is_object_path (amxd_path_t *path)
 Checks if the path is an object path. More...
 
bool amxd_path_is_instance_path (const amxd_path_t *const path)
 Checks if the path is in the instantiated data model. More...
 
char * amxd_path_get_param_path (amxd_path_t *path)
 Get the full parameter path from the provided amxd_path_t struct. More...
 

Detailed Description

Data model path helper functions.

These functions help in parsing data model paths.

Path Names are represented by a hierarchy of Objects (“parents”) and Sub-Objects (“children”), separated by the dot “.” character, ending with a Parameter if referencing a Parameter Path. There are six different types of Path Names used to address the data model:

Reference following.

The data model can contain parameters that contains reference paths to other objects in the data model. The Reference Following mechanism allows references to Objects (not Parameters) to be followed from inside a single Path Name. Reference Following is indicated by a “+” character after the Parameter Path, referencing the Object followed by a “.”, optionally followed by a Relative Object or Parameter Path that are children of the Referenced Object.

For example, "Device.NAT.PortMapping.{i}.Interface" references an IP Interface Object (Device.IP.Interface.{i}.) and that Object has a Parameter called “Name”. With Reference Following, a Path Name of "Device.NAT.PortMapping.1.Interface+.Name" references the “Name” Parameter of the Interface Object that the PortMapping is associated with (i.e. it is the equivalent of using Device.IP.Interface.1.Name as the Path Name).

Function Documentation

◆ amxd_path_append()

amxd_status_t 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.

Adds a parameter name or object name, instance index, wildcard, search expression to the path contained in the amxd_path_t structure.

When add_dot is set to true, a dot is added if the extension doesn't end with a dot.

Parameters
pathamxd_path_t struct containing a path
extensionthe string that must be added to the path
add_dotmake sure the path ends with a dot, even if the extension doesn't contain a dot.
Returns
amxd_status_invalid_path when the result is an invalid path, amxd_status_ok otherwise.

Definition at line 441 of file amxd_path.c.

441  {
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 }
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
enum _amxd_status amxd_status_t
@ amxd_status_unknown_error
Definition: amxd_types.h:79
amxc_string_t path
Definition: amxd_types.h:407
static amxd_status_t status

◆ amxd_path_build_supported_path()

char* amxd_path_build_supported_path ( amxd_path_t path)

Creates the supported path representation of the given path.

Replaces each index, wildcard or search string into '{i}' placeholder.

Note
The returned string must be freed when not needed anymore.
Parameters
pathamxd_path_t struct containing a path
Returns
The supported path representation.

Definition at line 699 of file amxd_path.c.

699  {
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 }
amxc_var_t parts
Definition: amxd_types.h:409

◆ amxd_path_clean()

void amxd_path_clean ( amxd_path_t path)

Cleans an amxd_path_t structure.

Frees all allocated memory and resets the amxd_path_t structure.

Parameters
pathamxd_path_t struct containing a path

Definition at line 351 of file amxd_path.c.

351  {
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 }
@ amxd_path_invalid
Definition: amxd_types.h:399
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

◆ amxd_path_delete()

void amxd_path_delete ( amxd_path_t **  path)

Frees an allocated amxd_path_t structure.

After freeing the allocated memory, resets the amxd_path_t pointer to NULL.

Note
The allocated amxd_path_t structures must be allocated using amxd_path_new
Parameters
pathamxd_path_t struct containing a path

Definition at line 378 of file amxd_path.c.

378  {
379  when_null(path, exit);
380  amxd_path_clean(*path);
381 
382  free(*path);
383  *path = NULL;
384 
385 exit:
386  return;
387 }
void amxd_path_clean(amxd_path_t *path)
Cleans an amxd_path_t structure.
Definition: amxd_path.c:351

◆ amxd_path_get()

const char* amxd_path_get ( amxd_path_t path,
int  flags 
)

Returns the path stored in the amxd_path_t structure.

Returns the object path as a string that is stored in the amxd_path_t structure.

When the amxd_path_t structure contains a parameter path, this function will only return the object path without the parameter name.

When the full parameter path is needed use amxd_path_get_param_path

Parameters
pathamxd_path_t struct containing a path
flagsbitmap of flags. Currently only AMXD_OBJECT_TERMINATE is supported.
Returns
the path stored in the structure

Definition at line 470 of file amxd_path.c.

470  {
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 }
static int isdot(int c)
Definition: amxd_path.c:296
#define AMXD_OBJECT_TERMINATE
Path format flag - when set the object path is terminated with a dot.
Definition: amxd_object.h:214

◆ amxd_path_get_depth()

uint32_t amxd_path_get_depth ( const amxd_path_t *const  path)

Calculates the depth of the path.

Calculates the depth of the path. This is the depth of the hierarchy of the path in the data model. Each object in the hierarchy increases the depth, parameters are not counted as a depth.

Parameters
pathamxd_path_t struct containing a path
Returns
The depth of the path

Definition at line 733 of file amxd_path.c.

733  {
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 }

◆ amxd_path_get_first()

char* amxd_path_get_first ( amxd_path_t path,
bool  remove 
)

Gets the first part of the path.

Gets the first part of the path, that is until the first dot encountered.

When remove is set to true, it is removed from the path contained in the amxd_path_t structure.

Note
The returned string must be freed when not needed anymore.
Parameters
pathamxd_path_t struct containing a path
removewhen set to true it is removed from the path contained in the structure.
Returns
The first part of the path or NULL when the path is empty.

Definition at line 501 of file amxd_path.c.

501  {
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 }

◆ amxd_path_get_fixed_part()

char* amxd_path_get_fixed_part ( amxd_path_t path,
bool  remove 
)

Gets the fixed part of the path.

The fixed part of a path is the path starting from the beginning until a wildcard or seearch expression.

If the path doesn't contain a wildcard or search expression the full path is returned.

When remove is set to true, the fixed part is removed from the path.

Note
The returned string must be freed when not needed anymore.
Parameters
pathamxd_path_t struct containing a path
removewhen set to true it is removed from the path contained in the structure.
Returns
The fixed part of the path.

Definition at line 576 of file amxd_path.c.

576  {
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 }

◆ amxd_path_get_last()

char* amxd_path_get_last ( amxd_path_t path,
bool  remove 
)

Gets the last part of the path.

Gets the last part of the path, that is the part in front of the last dot.

When remove is set to true, it is removed from the path contained in the amxd_path_t structure.

Parameter names are not returned by this function, use amxd_path_get_param to get the parameter name.

Note
The returned string must be freed when not needed anymore.
Parameters
pathamxd_path_t struct containing a path
removewhen set to true it is removed from the path contained in the structure.
Returns
The last part of the path or NULL if the path is empty.

Definition at line 531 of file amxd_path.c.

531  {
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 }
static amxd_path_type_t amxd_path_is(amxd_path_t *path)
Definition: amxd_path.c:161

◆ amxd_path_get_param()

const char* amxd_path_get_param ( amxd_path_t path)

Gets the parameter name.

Gets the parameter name if the path is a parameter path. This function returns NULL if the path contained in the amxd_path_t structure is not a parameter path.

Parameters
pathamxd_path_t struct containing a path
Returns
The parameter name or NULL if the path is not a parameter path.

Definition at line 497 of file amxd_path.c.

497  {
498  return path == NULL ? NULL : path->param;
499 }

◆ amxd_path_get_param_path()

char* amxd_path_get_param_path ( amxd_path_t path)

Get the full parameter path from the provided amxd_path_t struct.

Note
If the provided path does not contain a parameter, the function will return NULL.
Parameters
pathamxd_path_t struct containing a parameter path
Returns
Full parameter path in case of success, NULL otherwise

Definition at line 787 of file amxd_path.c.

787  {
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 }

◆ amxd_path_get_reference_index()

uint32_t amxd_path_get_reference_index ( amxd_path_t path)

Returns the reference path index.

When the given path has reference following decorations, this function will return the index of the reference.

When the parameter that contains the reference is a comma separated list of references, the index is used to specify which item in the list must be used. The index starts with 1 for the first item in the list.

If no index is provided in the reference following decoration, the index returned is 1.

Example: When the path is "Device.NAT.PortMapping.1.Interface+#2.Name" this function returns 2

Parameters
pathamxd_path_t struct containing a path
Returns
The reference index.

Definition at line 689 of file amxd_path.c.

689  {
690  uint32_t index = 0;
691  when_null(path, exit);
692 
693  index = path->ref_index;
694 
695 exit:
696  return index;
697 }
uint64_t ref_index
Definition: amxd_types.h:412

◆ amxd_path_get_reference_part()

char* amxd_path_get_reference_part ( amxd_path_t path,
bool  remove 
)

Returns the reference path.

When the given path has reference following decorations, this function will return the reference path.

Example: When the path is "Device.NAT.PortMapping.1.Interface+.Name" this function returns the string "Device.NAT.PortMapping.1.Interface."

When remove is set to true the reference path is removed from the path contained in the amxd_path_t structure.

Note
The returned string must be freed when not needed anymore.
Parameters
pathamxd_path_t struct containing a path
removewhen set to true it is removed from the path contained in the structure.
Returns
The reference path.

Definition at line 640 of file amxd_path.c.

640  {
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 }

◆ amxd_path_get_supported_path()

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.

This function will remove the '{i}' placeholders or indices from the path contained in the amxd_path_t structure. This will result in an ambiorix data model object definition path.

The resulting path can be used to fetch the object definition.

Note
The provided path must not contain search expressions or wildcards.
The returned string must be freed when not needed anymore.
Parameters
pathamxd_path_t struct containing a path
Returns
The ambiorix data model object definition path.

Definition at line 611 of file amxd_path.c.

611  {
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 }

◆ amxd_path_get_type()

static amxd_path_type_t amxd_path_get_type ( amxd_path_t path)
inlinestatic

Returns the path type.

See amxd_path_type_t for the supported path types.

Parameters
pathamxd_path_t struct containing a path
Returns
The path type.

Definition at line 507 of file amxd_path.h.

507  {
508  return path == NULL ? amxd_path_invalid : path->type;
509 }

◆ amxd_path_init()

amxd_status_t amxd_path_init ( amxd_path_t path,
const char *  object_path 
)

Initializes an amxd_path_t structure.

Initializes an amxd_path_t structure and sets the path.

If the given object path is invalid the structure will be initialized but an error is returned

Parameters
pathamxd_path_t struct containing a path
object_pathNULL or a valid path string
Returns
amxd_status_ok when the structure is initialized and a valid path was given, otherwise an error code is returned.

Definition at line 328 of file amxd_path.c.

329  {
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 }

◆ amxd_path_is_instance_path()

bool amxd_path_is_instance_path ( const amxd_path_t *const  path)

Checks if the path is in the instantiated data model.

A path is in the instantiated data model if the path ends with an instance index, a wildcard or a search expression.

Parameters
pathamxd_path_t struct containing a path
Returns
true when the path is in the instantiated data model, false otherwise

Definition at line 753 of file amxd_path.c.

753  {
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 }

◆ amxd_path_is_object_path()

static bool amxd_path_is_object_path ( amxd_path_t path)
inlinestatic

Checks if the path is an object path.

An object path is a path pointing to a singleton object or an instance object.

Parameters
pathamxd_path_t struct containing a path
Returns
true when the path is an object path, false otherwise

Definition at line 579 of file amxd_path.h.

579  {
580  return path == NULL ? false : (path->type == amxd_path_object);
581 }
@ amxd_path_object
Definition: amxd_types.h:400

◆ amxd_path_is_search_path()

static bool amxd_path_is_search_path ( amxd_path_t path)
inlinestatic

Checks if the path is a search path.

A search path is an object path containing a wildcard character ('*') or it contains search expressions (between '[' and ']')

Parameters
pathamxd_path_t struct containing a path
Returns
true when the path is a search path, false otherwise

Definition at line 544 of file amxd_path.h.

544  {
545  return path == NULL ? false : (path->type == amxd_path_search);
546 }
@ amxd_path_search
Definition: amxd_types.h:401

◆ amxd_path_is_supported_path()

static bool amxd_path_is_supported_path ( amxd_path_t path)
inlinestatic

Checks if the path is in the supported data model.

A path is an supported path if it contains '{i}' or it is pointing to a an object under a template object (not an instance of the template object).

Parameters
pathamxd_path_t struct containing a path
Returns
true when the path is in the supported datamodel, false otherwise

Definition at line 562 of file amxd_path.h.

562  {
563  return path == NULL ? false : (path->type == amxd_path_supported);
564 }
@ amxd_path_supported
Definition: amxd_types.h:402

◆ amxd_path_is_valid()

static bool amxd_path_is_valid ( amxd_path_t path)
inlinestatic

Checks if the path is valid path.

Examples of invalid paths:

  • "Device.WiFi.AccessPoint.{some_id}.AssociatedDevice."
  • "Device.WiFi.AccessPoint.*.AssociatedDevice.{i}."
Parameters
pathamxd_path_t struct containing a path
Returns
true when the path is valid, false otherwise

Definition at line 526 of file amxd_path.h.

526  {
527  return path == NULL ? false : (path->type != amxd_path_invalid);
528 }

◆ amxd_path_new()

amxd_status_t amxd_path_new ( amxd_path_t **  path,
const char *  object_path 
)

Allocates and initializes an amxd_path_t structure.

Allocates memory on the heap for the amxd_path_t structure and initializes it.

Note
The allocated amxd_path_t structures must be freed when not needed anymore using amxd_path_delete
Parameters
pathamxd_path_t struct containing a path
object_pathNULL or a valid path string
Returns
amxd_status_ok when the structure is allocated initialized and a valid path was given, otherwise an error code is returned.

Definition at line 365 of file amxd_path.c.

366  {
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 }
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

◆ amxd_path_prepend()

amxd_status_t amxd_path_prepend ( amxd_path_t path,
const char *  extension 
)

Prepends an object name/index to the path.

Prepends the current path with an object name, instance index, wildcard, search expression to the path contained in the amxd_path_t structure.

The extension can not be a parameter name in this case, as a parameter name can only be added to the end of the path.

Parameters
pathamxd_path_t struct containing a path
extensionthe string that must be prepended to the path
Returns
amxd_status_invalid_path when the result is an invalid path, amxd_status_ok otherwise.

Definition at line 456 of file amxd_path.c.

456  {
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 }

◆ amxd_path_reset()

void amxd_path_reset ( amxd_path_t path)

Resets the amxd_path_t structure.

Parameters
pathamxd_path_t struct containing a path

Definition at line 389 of file amxd_path.c.

389  {
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 }

◆ amxd_path_setf()

amxd_status_t amxd_path_setf ( amxd_path_t path,
bool  add_dot,
const char *  obj_path,
  ... 
)

Sets or replaces the path contained in the amxd_path_t structure.

This function supports printf notations in the object path.

When the add_dot argument is set to true, a dot will be added to the end, if no dot at the end was present.

If the given path ends with a dot it will be an object path or an instance path. If the given path doesn't end with a dot it is a parameter path and the last part is the name of the parameter.

When an invalid object path is given, the function will return amxd_invalid_path and the type of the amxd_path_t will be set to amxd_path_invalid.

Parameters
pathamxd_path_t struct containing a path
add_dotmakes sure the path is ended with a dot when set to true
obj_paththe object path that must be set in the amxd_path_t structure. printf like format string is supported.
Returns
amxd_status_invalid_path when the given path is invalid, otherwise amxd_status_ok.

◆ amxd_path_vsetf()

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.

This function does exactly the same as amxd_path_setf, but takes a va_list of values.

Parameters
pathamxd_path_t struct containing a path
add_dotmakes sure the path is ended with a dot when set to true
obj_paththe object path that must be set in the amxd_path_t structure. printf like format string is supported.
argsa va_list, containing the values for the printf formatting
Returns
amxd_status_invalid_path when the given path is invalid, otherwise amxd_status_ok.

Definition at line 403 of file amxd_path.c.

406  {
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 }
void amxd_path_reset(amxd_path_t *path)
Resets the amxd_path_t structure.
Definition: amxd_path.c:389