MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ng_path_parse

Function ng_path_parse

lib/ff_ng_base.c:1660–1723  ·  view source on GitHub ↗

* Parse and verify a string of the form: * * Such a string can refer to a specific node or a specific hook * on a specific node, depending on how you look at it. In the * latter case, the PATH component must not end in a dot. * * Both and are optional. The is a string * of hook names separated by dots. This breaks out the original * string, setting *nod

Source from the content-addressed store, hash-verified

1658 * This returns -1 if the path is malformed. The char ** are optional.
1659 ***********************************************************************/
1660int
1661ng_path_parse(char *addr, char **nodep, char **pathp, char **hookp)
1662{
1663 char *node, *path, *hook;
1664 int k;
1665
1666 /*
1667 * Extract absolute NODE, if any
1668 */
1669 for (path = addr; *path && *path != ':'; path++);
1670 if (*path) {
1671 node = addr; /* Here's the NODE */
1672 *path++ = '\0'; /* Here's the PATH */
1673
1674 /* Node name must not be empty */
1675 if (!*node)
1676 return -1;
1677
1678 /* A name of "." is OK; otherwise '.' not allowed */
1679 if (strcmp(node, ".") != 0) {
1680 for (k = 0; node[k]; k++)
1681 if (node[k] == '.')
1682 return -1;
1683 }
1684 } else {
1685 node = NULL; /* No absolute NODE */
1686 path = addr; /* Here's the PATH */
1687 }
1688
1689 /* Snoop for illegal characters in PATH */
1690 for (k = 0; path[k]; k++)
1691 if (path[k] == ':')
1692 return -1;
1693
1694 /* Check for no repeated dots in PATH */
1695 for (k = 0; path[k]; k++)
1696 if (path[k] == '.' && path[k + 1] == '.')
1697 return -1;
1698
1699 /* Remove extra (degenerate) dots from beginning or end of PATH */
1700 if (path[0] == '.')
1701 path++;
1702 if (*path && path[strlen(path) - 1] == '.')
1703 path[strlen(path) - 1] = 0;
1704
1705 /* If PATH has a dot, then we're not talking about a hook */
1706 if (*path) {
1707 for (hook = path, k = 0; path[k]; k++)
1708 if (path[k] == '.') {
1709 hook = NULL;
1710 break;
1711 }
1712 } else
1713 path = hook = NULL;
1714
1715 /* Done */
1716 if (nodep)
1717 *nodep = node;

Callers 1

ng_path2noderefFunction · 0.70

Calls 1

strcmpFunction · 0.85

Tested by

no test coverage detected