]>
git.proxmox.com Git - mirror_edk2.git/blob - RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c
2 This file is cloned from DMTF libredfish library tag v1.0.0 and maintained
5 //----------------------------------------------------------------------------
7 // Copyright 2017 Distributed Management Task Force, Inc. All rights reserved.
8 // License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libredfish/LICENSE.md
9 //----------------------------------------------------------------------------
11 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
12 (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
14 SPDX-License-Identifier: BSD-2-Clause-Patent
35 const char *terminator
,
49 if (!path
|| (strlen (path
) == 0)) {
53 node
= (redPathNode
*)calloc (1, sizeof (redPathNode
));
61 node
->version
= getVersion (path
+1, &curPath
);
62 if (curPath
== NULL
) {
66 if (curPath
[0] == '/') {
70 node
->next
= parseRedPath (curPath
);
72 node
->next
= parseRedPath (path
+1);
79 curPath
= getStringTill (path
, "/", &end
);
81 parseNode (curPath
, node
, &endNode
);
84 endNode
->next
= parseRedPath (end
+1);
99 cleanupRedPath (node
->next
);
102 free (node
->version
);
105 if (node
->nodeName
) {
106 free (node
->nodeName
);
113 if (node
->propName
) {
114 free (node
->propName
);
130 return getStringTill (path
, "/", end
);
143 char *nodeName
= getStringTill (path
, "[", &indexStart
);
147 node
->nodeName
= nodeName
;
148 if (indexStart
== NULL
) {
153 node
->next
= (redPathNode
*)calloc (1, sizeof (redPathNode
));
161 index
= getStringTill (indexStart
, "]", NULL
);
162 tmpIndex
= (size_t)strtoull (index
, &indexEnd
, 0);
163 if (indexEnd
!= index
) {
165 node
->next
->index
= tmpIndex
;
166 node
->next
->isIndex
= true;
170 opChars
= strpbrk (index
, "<>=~");
171 if (opChars
== NULL
) {
172 // TODO handle last() and position()
173 node
->next
->op
= strdup ("exists");
174 node
->next
->propName
= index
;
178 node
->next
->propName
= (char *)malloc ((opChars
- index
)+1);
179 memcpy (node
->next
->propName
, index
, (opChars
- index
));
180 node
->next
->propName
[(opChars
- index
)] = 0;
184 if ((opChars
[tmpIndex
] == '=') || (opChars
[tmpIndex
] == '<') || (opChars
[tmpIndex
] == '>') || (opChars
[tmpIndex
] == '~')) {
192 node
->next
->op
= (char *)malloc (tmpIndex
+1);
193 memcpy (node
->next
->op
, opChars
, tmpIndex
);
194 node
->next
->op
[tmpIndex
] = 0;
196 node
->next
->value
= strdup (opChars
+tmpIndex
);
203 const char *terminator
,
210 end
= strstr ((char *)string
, terminator
);
217 return strdup (string
);
220 ret
= (char *)malloc ((end
-string
)+1);
221 memcpy (ret
, string
, (end
-string
));
222 ret
[(end
-string
)] = 0;