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

Function ng_name2noderef

lib/ff_ng_base.c:914–944  ·  view source on GitHub ↗

* Find a node by absolute name. The name should NOT end with ':' * The name "." means "this node" and "[xxx]" means "the node * with ID (ie, at address) xxx". * * Returns the node if found, else NULL. * Eventually should add something faster than a sequential search. * Note it acquires a reference on the node so you can be sure it's still * there. */

Source from the content-addressed store, hash-verified

912 * there.
913 */
914node_p
915ng_name2noderef(node_p here, const char *name)
916{
917 node_p node;
918 ng_ID_t temp;
919 int hash;
920
921 /* "." means "this node" */
922 if (strcmp(name, ".") == 0) {
923 NG_NODE_REF(here);
924 return(here);
925 }
926
927 /* Check for name-by-ID */
928 if ((temp = ng_decodeidname(name)) != 0) {
929 return (ng_ID2noderef(temp));
930 }
931
932 /* Find node by name. */
933 hash = hash32_str(name, HASHINIT) & V_ng_name_hmask;
934 NAMEHASH_RLOCK();
935 LIST_FOREACH(node, &V_ng_name_hash[hash], nd_nodes)
936 if (NG_NODE_IS_VALID(node) &&
937 (strcmp(NG_NODE_NAME(node), name) == 0)) {
938 NG_NODE_REF(node);
939 break;
940 }
941 NAMEHASH_RUNLOCK();
942
943 return (node);
944}
945
946/*
947 * Decode an ID name, eg. "[f03034de]". Returns 0 if the

Callers 1

ng_path2noderefFunction · 0.70

Calls 4

strcmpFunction · 0.85
hash32_strFunction · 0.85
ng_decodeidnameFunction · 0.70
ng_ID2noderefFunction · 0.70

Tested by

no test coverage detected