void ldap2rdfInit (RDFT rdf) { if (!ldap2rdfInitedp) { ldap2rdfHash = PR_NewHashTable(500, idenHash, idenEqual, idenEqual, null, null); invldap2rdfHash = PR_NewHashTable(500, idenHash, idenEqual, idenEqual, null, null); gRDFDB = rdf; ldap2rdfInitedp = 1; } }
NSAPI_PUBLIC void ACL_AttrGetterRegisterInit() { ACLAttrGetterHash = PR_NewHashTable(256, ACLPR_HashCaseString, ACLPR_CompareCaseStrings, PR_CompareValues, &ACLPermAllocOps, NULL); NS_ASSERT(ACLAttrGetterHash); }
JSBool js_InitAtomState(JSContext *cx, JSAtomState *state) { uintN i; state->number = 0; state->table = PR_NewHashTable(JS_ATOM_HASH_SIZE, js_hash_atom_key, js_compare_atom_keys, js_compare_stub, &atomAllocOps, state); if (!state->table) { JS_ReportOutOfMemory(cx); return JS_FALSE; } #define FROB(lval,str) { \ if (!(state->lval = js_Atomize(cx, str, strlen(str), 0))) { \ js_FreeAtomState(cx, state); \ return JS_FALSE; \ } \ } PR_ASSERT(sizeof js_type_str / sizeof js_type_str[0] == JSTYPE_LIMIT); for (i = 0; i < JSTYPE_LIMIT; i++) FROB(typeAtoms[i], js_type_str[i]); FROB(booleanAtoms[0], js_false_str); FROB(booleanAtoms[1], js_true_str); FROB(nullAtom, js_null_str); FROB(ArrayAtom, js_Array_str); FROB(ObjectAtom, js_Object_str); FROB(anonymousAtom, js_anonymous_str); FROB(assignAtom, js_assign_str); FROB(classPrototypeAtom, js_class_prototype_str); FROB(constructorAtom, js_constructor_str); FROB(countAtom, js_count_str); FROB(indexAtom, js_index_str); FROB(inputAtom, js_input_str); FROB(lengthAtom, js_length_str); FROB(parentAtom, js_parent_str); FROB(protoAtom, js_proto_str); FROB(toStringAtom, js_toString_str); FROB(valueOfAtom, js_valueOf_str); #undef FROB return JS_TRUE; }
PRHashEntry * js_EnterSharpObject(JSContext *cx, JSObject *obj, jschar **sp) { JSSharpObjectMap *map; PRHashTable *table; PRHashNumber hash; PRHashEntry *he; jsatomid sharpid; char buf[20]; size_t len; map = &cx->sharpObjectMap; table = map->table; if (!table) { table = PR_NewHashTable(8, js_hash_object, PR_CompareValues, PR_CompareValues, NULL, NULL); if (!table) { JS_ReportOutOfMemory(cx); return NULL; } map->table = table; } if (map->depth == 0) { he = MarkSharpObjects(cx, obj); if (!he) return NULL; } else { hash = js_hash_object(obj); he = *PR_HashTableRawLookup(table, hash, obj); PR_ASSERT(he); } sharpid = (jsatomid) he->value; if (sharpid == 0) { *sp = NULL; } else { len = PR_snprintf(buf, sizeof buf, "#%u%c", sharpid >> 1, (sharpid & SHARP_BIT) ? '#' : '='); *sp = js_InflateString(cx, buf, len); if (!*sp) return NULL; } if ((sharpid & SHARP_BIT) == 0) map->depth++; return he; }
/* LASDNSBuild * Builds a hash table of all the hostnames provided (plus their aliases * if aliasflg is true). Wildcards are only permitted in the leftmost * field. They're represented in the hash table by a leading period. * E.g. ".mcom.com". * * RETURNS Zero on success, else LAS_EVAL_INVALID */ int LASDnsBuild(NSErr_t *errp, char *attr_pattern, LASDnsContext_t *context, int aliasflg) { size_t delimiter; /* length of valid tokeni */ char token[256]; /* max length dns name */ int i; char **p; pool_handle_t *pool; PRStatus error=PR_SUCCESS; char buffer[PR_NETDB_BUF_SIZE]; #ifdef UTEST struct hostent *he, host; #else PRHostEnt *he, host; #endif char *end_attr_pattern; if (attr_pattern == NULL) { nserrGenerate(errp, ACLERRINVAL, ACLERR4770, ACL_Program, 1, XP_GetAdminStr(DBT_lasdnsbuildInvalidAttributePattern_)); return LAS_EVAL_INVALID; } context->Table = PR_NewHashTable(0, PR_HashCaseString, PR_CompareCaseStrings, PR_CompareValues, &ACLPermAllocOps, NULL); pool = pool_create(); context->pool = pool; if ((!context->Table) || (!context->pool)) { nserrGenerate(errp, ACLERRNOMEM, ACLERR4700, ACL_Program, 1, XP_GetAdminStr(DBT_lasdnsbuildUnableToAllocateHashT_)); return LAS_EVAL_INVALID; } end_attr_pattern = attr_pattern + strlen(attr_pattern); do { size_t maxsize = sizeof(token); /* Get a single hostname from the pattern string */ delimiter = strcspn(attr_pattern, ", \t"); if (delimiter >= maxsize) { delimiter = maxsize-1; } PL_strncpyz(token, attr_pattern, delimiter + 1); token[delimiter] = '\0'; /* Skip any white space after the token */ attr_pattern += delimiter; if (attr_pattern < end_attr_pattern) { attr_pattern += strspn(attr_pattern, ", \t"); } /* If there's a wildcard, strip it off but leave the "." * Can't have aliases for a wildcard pattern. * Treat "*" as a special case. If so, go ahead and hash it. */ if (token[0] == '*') { if (token[1] != '\0') { if (!PR_HashTableAdd(context->Table, pool_strdup(pool, &token[1]), (void *)-1)) { nserrGenerate(errp, ACLERRFAIL, ACLERR4710, ACL_Program, 2, XP_GetAdminStr(DBT_lasdnsbuildUnableToAddKeySN_), token); return LAS_EVAL_INVALID; } } else { if (!PR_HashTableAdd(context->Table, pool_strdup(pool, token), (void *)-1)) { nserrGenerate(errp, ACLERRFAIL, ACLERR4720, ACL_Program, 2, XP_GetAdminStr(DBT_lasdnsbuildUnableToAddKeySN_), token); return LAS_EVAL_INVALID; } } } else { /* This is a single hostname add it to the hash table */ if (!PR_HashTableAdd(context->Table, pool_strdup(pool, &token[0]), (void *)-1)) { nserrGenerate(errp, ACLERRFAIL, ACLERR4730, ACL_Program, 2, XP_GetAdminStr(DBT_lasdnsbuildUnableToAddKeySN_), token); return LAS_EVAL_INVALID; } if (aliasflg) { void *iter = NULL; int addrcnt = 0; PRNetAddr *netaddr = (PRNetAddr *)PERM_CALLOC(sizeof(PRNetAddr)); PRAddrInfo *infop = PR_GetAddrInfoByName(token, PR_AF_UNSPEC, (PR_AI_ADDRCONFIG|PR_AI_NOCANONNAME)); if (!netaddr) { if (infop) { PR_FreeAddrInfo(infop); } return LAS_EVAL_NEED_MORE_INFO; /* hostname not known to dns? */ } if (!infop) { if (netaddr) { PERM_FREE(netaddr); } return LAS_EVAL_NEED_MORE_INFO; /* hostname not known to dns? */ } /* need to count the address, first */ while ((iter = PR_EnumerateAddrInfo(iter, infop, 0, netaddr))) { addrcnt++; } if (0 == addrcnt) { PERM_FREE(netaddr); PR_FreeAddrInfo(infop); return LAS_EVAL_NEED_MORE_INFO; /* hostname not known to dns? */ } iter = NULL; /* from the beginning */ memset(netaddr, 0, sizeof(PRNetAddr)); for (i = 0; i < addrcnt; i++) { iter = PR_EnumerateAddrInfo( iter, infop, 0, netaddr ); if (NULL == iter) { break; } error = PR_GetHostByAddr(netaddr, buffer, PR_NETDB_BUF_SIZE, &host); if (error == PR_SUCCESS) { he = &host; } else { continue; } if (he->h_name) { /* Add it to the hash table */ if (!PR_HashTableAdd(context->Table, pool_strdup(pool, he->h_name), (void *)-1)) { nserrGenerate(errp, ACLERRFAIL, ACLERR4750, ACL_Program, 2, XP_GetAdminStr(DBT_lasdnsbuildUnableToAddKeySN_), he->h_name); PERM_FREE(netaddr); PR_FreeAddrInfo(infop); return LAS_EVAL_INVALID; } } if (he->h_aliases && he->h_aliases[0]) { for (p = he->h_aliases; *p; ++p) { /* Add it to the hash table */ if (!PR_HashTableAdd(context->Table, pool_strdup(pool, *p), (void *)-1)) { nserrGenerate(errp, ACLERRFAIL, ACLERR4760, ACL_Program, 2, XP_GetAdminStr(DBT_lasdnsbuildUnableToAddKeySN_), *p); PERM_FREE(netaddr); PR_FreeAddrInfo(infop); return LAS_EVAL_INVALID; } } } } /* for (i = 0; i < addrcnt; i++) */ PERM_FREE(netaddr); PR_FreeAddrInfo(infop); } /* if aliasflg */ } /* else - single hostname */ } while ((attr_pattern != NULL) && (attr_pattern[0] != '\0') && (delimiter != 0)); return 0; }
static JSDContext* _newJSDContext(JSTaskState* jstaskstate, JSD_UserCallbacks* callbacks, void* user) { JSDContext* jsdc = NULL; if( ! jstaskstate ) return NULL; if( ! _validateUserCallbacks(callbacks) ) return NULL; jsdc = (JSDContext*) calloc(1, sizeof(JSDContext)); if( ! jsdc ) goto label_newJSDContext_failure; if( ! JSD_INIT_LOCKS(jsdc) ) goto label_newJSDContext_failure; PR_INIT_CLIST(&jsdc->links); jsdc->jstaskstate = jstaskstate; if( callbacks ) memcpy(&jsdc->userCallbacks, callbacks, callbacks->size); jsdc->user = user; #ifdef JSD_HAS_DANGEROUS_THREAD jsdc->dangerousThread = _dangerousThread; #endif PR_INIT_CLIST(&jsdc->threadsStates); PR_INIT_CLIST(&jsdc->scripts); PR_INIT_CLIST(&jsdc->sources); PR_INIT_CLIST(&jsdc->removedSources); jsdc->sourceAlterCount = 1; jsdc->jscontexts = PR_NewHashTable(256, _hash_root, PR_CompareValues, PR_CompareValues, NULL, NULL); if( ! jsdc->jscontexts ) goto label_newJSDContext_failure; jsdc->dumbContext = JS_NewContext(jsdc->jstaskstate, 256); if( ! jsdc->dumbContext ) goto label_newJSDContext_failure; jsdc->glob = JS_NewObject(jsdc->dumbContext, &global_class, NULL, NULL); if( ! jsdc->glob ) goto label_newJSDContext_failure; if( ! JS_InitStandardClasses(jsdc->dumbContext, jsdc->glob) ) goto label_newJSDContext_failure; jsdc->inited = JS_TRUE; JSD_LOCK(); PR_INSERT_LINK(&jsdc->links, &_jsd_context_list); JSD_UNLOCK(); return jsdc; label_newJSDContext_failure: if( jsdc ) free(jsdc); return NULL; }