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

Function ng_path2noderef

lib/ff_ng_base.c:1729–1851  ·  view source on GitHub ↗

* Given a path, which may be absolute or relative, and a starting node, * return the destination node. */

Source from the content-addressed store, hash-verified

1727 * return the destination node.
1728 */
1729int
1730ng_path2noderef(node_p here, const char *address, node_p *destp,
1731 hook_p *lasthook)
1732{
1733 char fullpath[NG_PATHSIZ];
1734 char *nodename, *path;
1735 node_p node, oldnode;
1736
1737 /* Initialize */
1738 if (destp == NULL) {
1739 TRAP_ERROR();
1740 return EINVAL;
1741 }
1742 *destp = NULL;
1743
1744 /* Make a writable copy of address for ng_path_parse() */
1745 strncpy(fullpath, address, sizeof(fullpath) - 1);
1746 fullpath[sizeof(fullpath) - 1] = '\0';
1747
1748 /* Parse out node and sequence of hooks */
1749 if (ng_path_parse(fullpath, &nodename, &path, NULL) < 0) {
1750 TRAP_ERROR();
1751 return EINVAL;
1752 }
1753
1754 /*
1755 * For an absolute address, jump to the starting node.
1756 * Note that this holds a reference on the node for us.
1757 * Don't forget to drop the reference if we don't need it.
1758 */
1759 if (nodename) {
1760 node = ng_name2noderef(here, nodename);
1761 if (node == NULL) {
1762 TRAP_ERROR();
1763 return (ENOENT);
1764 }
1765 } else {
1766 if (here == NULL) {
1767 TRAP_ERROR();
1768 return (EINVAL);
1769 }
1770 node = here;
1771 NG_NODE_REF(node);
1772 }
1773
1774 if (path == NULL) {
1775 if (lasthook != NULL)
1776 *lasthook = NULL;
1777 *destp = node;
1778 return (0);
1779 }
1780
1781 /*
1782 * Now follow the sequence of hooks
1783 *
1784 * XXXGL: The path may demolish as we go the sequence, but if
1785 * we hold the topology mutex at critical places, then, I hope,
1786 * we would always have valid pointers in hand, although the

Callers 2

ng_generic_msgFunction · 0.70
ng_address_pathFunction · 0.70

Calls 4

strncpyFunction · 0.85
ng_path_parseFunction · 0.70
ng_name2noderefFunction · 0.70
ng_findhookFunction · 0.70

Tested by

no test coverage detected