* 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. */
| 906 | * there. |
| 907 | */ |
| 908 | node_p |
| 909 | ng_name2noderef(node_p here, const char *name) |
| 910 | { |
| 911 | node_p node; |
| 912 | ng_ID_t temp; |
| 913 | int hash; |
| 914 | |
| 915 | /* "." means "this node" */ |
| 916 | if (strcmp(name, ".") == 0) { |
| 917 | NG_NODE_REF(here); |
| 918 | return(here); |
| 919 | } |
| 920 | |
| 921 | /* Check for name-by-ID */ |
| 922 | if ((temp = ng_decodeidname(name)) != 0) { |
| 923 | return (ng_ID2noderef(temp)); |
| 924 | } |
| 925 | |
| 926 | /* Find node by name. */ |
| 927 | hash = hash32_str(name, HASHINIT) & V_ng_name_hmask; |
| 928 | NAMEHASH_RLOCK(); |
| 929 | LIST_FOREACH(node, &V_ng_name_hash[hash], nd_nodes) |
| 930 | if (NG_NODE_IS_VALID(node) && |
| 931 | (strcmp(NG_NODE_NAME(node), name) == 0)) { |
| 932 | NG_NODE_REF(node); |
| 933 | break; |
| 934 | } |
| 935 | NAMEHASH_RUNLOCK(); |
| 936 | |
| 937 | return (node); |
| 938 | } |
| 939 | |
| 940 | /* |
| 941 | * Decode an ID name, eg. "[f03034de]". Returns 0 if the |
no test coverage detected