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

Function ng_path_parse

freebsd/netgraph/ng_base.c:1654–1717  ·  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

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

Callers 1

ng_path2noderefFunction · 0.70

Calls 1

strcmpFunction · 0.85

Tested by

no test coverage detected