void httpd_www_noproxies_msg(int fd) { char *retval; retval = hashtable_lookup(cfg, "http-analyzer"); if (!retval || !strcmp(retval, "off")) { hashtable_insert(cfg, "http-analyzer", "on"); hashtable_insert(cfg, "http-admin-mode", "on"); hashtable_insert(cfg, "http-admin-url", "http://ghost/"); } else { retval = hashtable_lookup(cfg, "http-admin-mode"); if (!retval || !strcmp(retval, "off")) { hashtable_insert(cfg, "http-admin-mode", "on"); hashtable_insert(cfg, "http-admin-url", "http://ghost/"); } } httpd_msg_page(fd, "Out of Proxies!", -1, NULL, "There are currectly no proxies or no working proxies in the database.<BR>\n \ Please click <A HREF=\"%sproxies.html\"><U>here</U></A> to access the database<BR> \n", hashtable_lookup(cfg, "http-admin-url")); return ; }
/* updateIndex - Updates the structure containing the index by * inserting a new WordNode if not already in the index * and updating the DocumentNode if word is already * in the index. * If word is not in the index, procedure allocates * a new WordNode and adds to the hashtable * * @word: string containing the word * @docID: identifier of the document * @index: InvertedIndex hashtable * * Returns 1 if successful * Returns 0 otherwise */ int updateIndex(char* word, int docID, HashTable* index) { //WordNode* wNode = initWNode(word, docID); WordNode* wNode = calloc(1, sizeof(WordNode)); if (!hashtable_get(index, word, wNode)) { assert(!hashtable_lookup(index, word)); initWNode(word, docID, wNode); hashtable_insert(index, word, wNode); } else { // Word in table, so update its list of DocumentNode assert(hashtable_lookup(index, word)); DocumentNode* dNode = NULL; if (!list_get(wNode->page, (element_t)&docID, (element_t)&dNode)) { // No matching document, so insert a new one assert(dNode == NULL); dNode = calloc(1, sizeof(DocumentNode)); dNode->document_id = docID; dNode->page_word_frequency = 1; list_append(wNode->page, dNode); } else { assert(dNode != NULL); assert(dNode->document_id == docID); dNode->page_word_frequency++; } } return 1; }
static int map_image_pixels_from_median_box( Pixel *pixelData, uint32_t nPixels, Pixel *paletteData, uint32_t nPaletteEntries, HashTable *medianBoxHash, uint32_t *avgDist, uint32_t **avgDistSortKey, uint32_t *pixelArray) { uint32_t *aD,**aDSK; uint32_t idx; uint32_t i,j; uint32_t bestdist,bestmatch,dist; uint32_t initialdist; HashTable *h2; uint32_t pixelVal; h2=hashtable_new(unshifted_pixel_hash,unshifted_pixel_cmp); for (i=0;i<nPixels;i++) { if (hashtable_lookup(h2,pixelData[i],&pixelVal)) { pixelArray[i]=pixelVal; continue; } if (!hashtable_lookup(medianBoxHash,pixelData[i],&pixelVal)) { #ifndef NO_OUTPUT printf ("pixel lookup failed\n"); #endif return 0; } initialdist=_DISTSQR(paletteData+pixelVal,pixelData+i); bestdist=initialdist; bestmatch=pixelVal; initialdist<<=2; aDSK=avgDistSortKey+pixelVal*nPaletteEntries; aD=avgDist+pixelVal*nPaletteEntries; for (j=0;j<nPaletteEntries;j++) { idx=aDSK[j]-aD; if (*(aDSK[j])<=initialdist) { dist=_DISTSQR(paletteData+idx,pixelData+i); if (dist<bestdist) { bestdist=dist; bestmatch=idx; } } else { break; } } pixelArray[i]=bestmatch; hashtable_insert(h2,pixelData[i],bestmatch); } hashtable_free(h2); return 1; }
static dr_emit_flags_t event_analyze_bb(void *drcontext, void *tag, instrlist_t *bb, bool for_trace, bool translating, void **user_data) { instr_t *instr; trace_head_entry_t *e = NULL; if (translating) return DR_EMIT_DEFAULT; for (instr = instrlist_first_app(bb); instr != NULL; instr = instr_get_next_app(instr)) { /* Blocks containing calls are trace heads. */ if (instr_is_call(instr)) { dr_mark_trace_head(drcontext, tag); hashtable_lock(&head_table); e = hashtable_lookup(&head_table, tag); if (e == NULL) { e = create_trace_head_entry(tag); if (!hashtable_add(&head_table, tag, (void *)e)) DR_ASSERT(false); } else e->refcount++; e->is_trace_head = true; hashtable_unlock(&head_table); #ifdef VERBOSE dr_log(drcontext, DR_LOG_ALL, 3, "inline: marking bb "PFX" as call trace head\n", tag); #endif /* Doesn't matter what's in rest of the bb. */ return DR_EMIT_DEFAULT; } else if (instr_is_return(instr)) { hashtable_lock(&head_table); e = hashtable_lookup(&head_table, tag); if (e == NULL) { e = create_trace_head_entry(tag); if (!hashtable_add(&head_table, tag, (void *)e)) DR_ASSERT(false); } else e->refcount++; e->has_ret = true; hashtable_unlock(&head_table); #ifdef VERBOSE dr_log(drcontext, DR_LOG_ALL, 3, "inline: marking bb "PFX" as return trace head\n", tag); #endif } } return DR_EMIT_DEFAULT; }
static void txdb_sign_tx_inputs(struct txdb *txdb, btc_msg_tx *tx) { int i; for (i = 0; i < tx->in_count; i++) { struct btc_msg_tx_in *txi = tx->tx_in + i; struct btc_msg_tx_out *txoFrom; struct tx_entry *txe; int res; bool s; s = hashtable_lookup(txdb->hash_tx, &txi->prevTxHash, sizeof txi->prevTxHash, (void *)&txe); ASSERT(s); ASSERT(txi->prevTxOutIdx < txe->tx.out_count); txoFrom = txe->tx.tx_out + txi->prevTxOutIdx; Warning(LGPFX" -- signing input #%u\n", i); res = script_sign(btc->wallet, txoFrom, tx, i, SIGHASH_ALL); ASSERT(res == 0); } }
int log_open(void) { /* CRITICAL SECTION */ pthread_mutex_lock(&log_mutex); if (!logfile) { logfile = hashtable_lookup(cfg, "daemon-logfile"); } if (!log_fp) { log_fp = fopen(logfile, "a+"); if (!log_fp) { perror(logfile); pthread_mutex_unlock(&log_mutex); return 0; } } pthread_mutex_unlock(&log_mutex); /* CRITICAL SECTION */ return 1; }
int blockstore_get_block_height(struct blockstore *bs, const uint256 *hash) { struct blockentry *be; int height; bool s; if (uint256_iszero(hash)) { return 0; } mutex_lock(bs->lock); s = hashtable_lookup(bs->hash_blk, hash, sizeof *hash, (void *)&be); if (s == 0) { char hashStr[80]; uint256_snprintf_reverse(hashStr, sizeof hashStr, hash); Panic(LGPFX " block %s not found.\n", hashStr); } height = be->height; mutex_unlock(bs->lock); return height; }
DR_EXPORT drmf_status_t drfuzz_unfuzz_target(generic_func_t func_pc) { drmf_status_t res = DRMF_SUCCESS; fuzz_pass_context_t *fp = drfuzz_get_fuzzcxt(); pass_target_t *live_target = lookup_live_target(fp, (app_pc) func_pc); fuzz_target_t *target = hashtable_lookup(&fuzz_target_htable, func_pc); if (target == NULL) return DRMF_ERROR_INVALID_PARAMETER; if (live_target != NULL) { /* XXX i#1734: ideally we would check all threads, or flag the target as live */ DRFUZZ_ERROR("Attempt to unfuzz a live fuzz target\n"); return DRMF_ERROR; /* cannot unfuzz the target in this state */ } if (!hashtable_remove(&fuzz_target_htable, func_pc)) { DRFUZZ_ERROR("failed to remove "PIFX" from the fuzz target hashtable\n", func_pc); res = DRMF_ERROR; /* Missing entry does not prevent unfuzzing, */ free_fuzz_target(target); /* but at least free it. */ } if (!drwrap_unwrap((app_pc) func_pc, pre_fuzz_handler, post_fuzz_handler)) { DRFUZZ_ERROR("failed to unwrap the fuzz target "PIFX" via drwrap_unwrap\n", func_pc); res = DRMF_ERROR; } return res; }
int ribs_queue_waitpid(pid_t pid) { uint32_t loc = hashtable_lookup(&ht_pid_to_ctx, &pid, sizeof(pid)); if (loc) return LOGGER_ERROR("pid is already in signal to ctx table"), -1; hashtable_insert(&ht_pid_to_ctx, &pid, sizeof(pid), ¤t_ctx, sizeof(current_ctx)); return 0; }
void blockstore_get_next_hashes(struct blockstore *bs, const uint256 *start, uint256 **hash, int *n) { struct blockentry *be; uint256 *table; int num; bool s; int i; i = 0; table = NULL; s = hashtable_lookup(bs->hash_blk, start, sizeof *start, (void*)&be); if (s == 0 || be->next == NULL) { goto exit; } be = be->next; num = 1000; table = safe_malloc(num * sizeof *table); while (be && i < num) { hash256_calc(&be->header, sizeof be->header, table + i); i++; be = be->next; } exit: *n = i; *hash = table; }
void it_read_instruction(Word word, char line[], Instruction *ins, char ***ids, int index, Queue *strs, Queue *ins_indices) { InsEntry *entry = (InsEntry *) hashtable_lookup(global_it.ins_ht, word.word); NULL_CHECK(entry, "Attempted to read instruction name, but was not registered.") ins->op = entry->op; char *str; switch (entry->type) { case I_VAL: str = get_value(ins, &word, line); if (STRING_INS == ins->type) { ins->op = PUSHM; queue_add_front(strs, str); queue_add_front(ins_indices, (int *) index); } break; case I_ADR: get_address(&word, line, ins, ids, index); break; case I_ID: get_id(&word, line, ins->id); break; case I_NONE: default: break; } }
int mysql_pool_get(struct mysql_login_info *info, struct mysql_pool_entry **mysql) { if (0 > make_ht_key(&misc, info)) return -1; char *ht_key = vmbuf_data(&misc); size_t key_len = vmbuf_wlocpos(&misc); uint32_t ofs = hashtable_lookup(&ht_idle_connections, ht_key, key_len); if (0 == ofs) { struct list *l = (struct list *)calloc(1, sizeof(struct list)); list_init(l); ofs = hashtable_insert(&ht_idle_connections, ht_key, key_len, &l, sizeof(struct list *)); if (0 == ofs) // unable to insert return -1; // add one element since we know there isn't any if (0 > create_entry(l)) return -1; // get first free element if (0 > get_free_entry(info, l, mysql)) return -1; } struct list *l = *(struct list **)hashtable_get_val(&ht_idle_connections, ofs); if (list_empty(l)) { LOGGER_INFO("adding one more entry in the list"); if (0 > create_entry(l)) return -1; } if (0 > get_free_entry(info, l, mysql)) return -1; return 0; }
static int map_image_pixels_from_quantized_pixels( Pixel *pixelData, uint32_t nPixels, Pixel *paletteData, uint32_t nPaletteEntries, uint32_t *avgDist, uint32_t **avgDistSortKey, uint32_t *pixelArray, uint32_t *avg[3], uint32_t *count) { uint32_t *aD,**aDSK; uint32_t idx; uint32_t i,j; uint32_t bestdist,bestmatch,dist; uint32_t initialdist; HashTable *h2; int changes=0; h2=hashtable_new(unshifted_pixel_hash,unshifted_pixel_cmp); for (i=0;i<nPixels;i++) { if (!hashtable_lookup(h2,pixelData[i],&bestmatch)) { bestmatch=pixelArray[i]; initialdist=_DISTSQR(paletteData+bestmatch,pixelData+i); bestdist=initialdist; initialdist<<=2; aDSK=avgDistSortKey+bestmatch*nPaletteEntries; aD=avgDist+bestmatch*nPaletteEntries; for (j=0;j<nPaletteEntries;j++) { idx=aDSK[j]-aD; if (*(aDSK[j])<=initialdist) { dist=_DISTSQR(paletteData+idx,pixelData+i); if (dist<bestdist) { bestdist=dist; bestmatch=idx; } } else { break; } } hashtable_insert(h2,pixelData[i],bestmatch); } if (pixelArray[i]!=bestmatch) { changes++; avg[0][bestmatch]+=pixelData[i].c.r; avg[1][bestmatch]+=pixelData[i].c.g; avg[2][bestmatch]+=pixelData[i].c.b; avg[0][pixelArray[i]]-=pixelData[i].c.r; avg[1][pixelArray[i]]-=pixelData[i].c.g; avg[2][pixelArray[i]]-=pixelData[i].c.b; count[bestmatch]++; count[pixelArray[i]]--; pixelArray[i]=bestmatch; } } hashtable_free(h2); return changes; }
bool hashtable_present(hashtable* table, const void* key) { hashlink** linkref = hashtable_lookup(table, key); hashlink* link = *linkref; return link != NULL; }
static struct blockentry * blockstore_lookup(const struct blockstore *bs, const uint256 *hash) { struct blockentry *be; bool s; s = hashtable_lookup(bs->hash_orphans, hash, sizeof *hash, (void *)&be); if (s) { return be; } s = hashtable_lookup(bs->hash_blk, hash, sizeof *hash, (void *)&be); if (s) { return be; } return NULL; }
GLuint sgGetProgram(const char *key) { SGshaderinfo *tmp = hashtable_lookup(shaderKeyMap, key); if (tmp) return tmp->ident; else ooLogWarn("no such shader '%s'", key); return 0; }
static char * read_module_list(char *buf, void ***tables, uint *num_mods) { char path[MAXIMUM_PATH]; uint i; uint version; PRINT(3, "Reading module table...\n"); /* versione number */ PRINT(4, "Reading version number"); if (dr_sscanf(buf, "DRCOV VERSION: %u\n", &version) != 1 && version != DRCOV_VERSION) { WARN(2, "Failed to read version number"); return NULL; } buf = move_to_next_line(buf); /* module table header */ PRINT(4, "Reading Module Table Header\n"); if (dr_sscanf(buf, "Module Table: %d\n", num_mods) != 1) { WARN(2, "Failed to read module table"); return NULL; } buf = move_to_next_line(buf); /* module lists */ PRINT(4, "Reading Module Lists\n"); *tables = calloc(*num_mods, sizeof(*tables)); for (i = 0; i < *num_mods; i++) { uint mod_id; uint64 mod_size; void *bb_table; /* assuming the string is something like: "0, 2207744, /bin/ls" */ /* XXX: i#1143: we do not use dr_sscanf since it does not support %[] */ if (sscanf(buf, " %u, %"INT64_FORMAT"u, %[^\n\r]", &mod_id, &mod_size, path) != 3) ASSERT(false, "Failed to read module table"); buf = move_to_next_line(buf); PRINT(5, "Module: %u, "PFX", %s\n", mod_id, (ptr_uint_t)mod_size, path); bb_table = hashtable_lookup(&module_htable, path); if (bb_table == NULL) { if (mod_size >= UINT_MAX) ASSERT(false, "module size is too large"); if (strstr(path, "<unknown>") != NULL || (mod_filter != NULL && strstr(path, mod_filter) == NULL)) bb_table = BB_TABLE_IGNORE; else bb_table = bb_table_create((uint)mod_size); PRINT(4, "Create bb table "PFX" for module %s\n", (ptr_uint_t)bb_table, path); num_module_htable_entries++; if (!hashtable_add(&module_htable, path, bb_table)) ASSERT(false, "Failed to add new module"); } (*tables)[i] = bb_table; } return buf; }
int compare_physical_offsets (const void *a, const void *b) { const char *left = *(const char **) a; const char *right = *(const char **) b; uint64_t *left_offset_p = hashtable_lookup (physical_offsets, left, strlen (left)); uint64_t *right_offset_p = hashtable_lookup (physical_offsets, right, strlen (right)); uint64_t left_offset = left_offset_p ? *left_offset_p : UINT64_MAX; uint64_t right_offset = right_offset_p ? *right_offset_p : UINT64_MAX; if (left_offset < right_offset) return -1; else if (left_offset > right_offset) return 1; else return 0; }
bool blockstore_has_header(const struct blockstore *bs, const uint256 *hash) { bool s; mutex_lock(bs->lock); s = hashtable_lookup(bs->hash_blk, hash, sizeof *hash, NULL); mutex_unlock(bs->lock); return s; }
bool blockstore_is_orphan(const struct blockstore *bs, const uint256 *hash) { bool s; mutex_lock(bs->lock); s = hashtable_lookup(bs->hash_orphans, hash, sizeof *hash, NULL); mutex_unlock(bs->lock); return s; }
DR_EXPORT drmf_status_t drfuzz_get_target_user_data(IN generic_func_t target_pc, OUT void **user_data) { fuzz_target_t *target = hashtable_lookup(&fuzz_target_htable, target_pc); if (target == NULL) return DRMF_ERROR_INVALID_PARAMETER; *user_data = target->user_data; return DRMF_SUCCESS; }
static struct blockentry *blockstore_lookup(const struct blockstore *bs, const uint256 *hash) { struct blockentry *be; bool s; be = NULL; mutex_lock(bs->lock); s = hashtable_lookup(bs->hash_orphans, hash, sizeof *hash, (void *)&be); if (s) { goto done; } s = hashtable_lookup(bs->hash_blk, hash, sizeof *hash, (void *)&be); if (s) { goto done; } done: mutex_unlock(bs->lock); return be; }
static struct grp_membership * grpobj_get_membership(obj_t grp_obj, obj_id_t member_oid) { struct grp_desc *grp_desc; struct grp_membership *membership; grp_desc = GRP_DESC(grp_obj); membership = hashtable_lookup(&grp_desc->members, &member_oid); return membership; }
/** Finds information associated with given tag. */ struct tag_info_t* find_tag_or_die(void* tag) { struct tag_info_t* tag_info; dr_mutex_lock(tags_lock); tag_info = hashtable_lookup(&tags, tag); dr_mutex_unlock(tags_lock); if(tag_info == NULL) { dr_fprintf(STDERR, "fatal: could not locate tag %p\n", tag); dr_exit_process(1); } return tag_info; }
message_channel_t *message_channel_lookup(const void *key, channel_hashfn_t hashfn) { hashelm_t *e; e = hashtable_lookup(&channel_table, key, hashfn); if (!e) return NULL; return container_of(e, struct message_channel, he); }
int httpd_www_log(int fd, char *raw, char *cgi) { httpd_start_hmenu(fd, log_menu); httpd_end_hmenu(fd); httpd_www_label(fd, hashtable_lookup(cfg, "daemon-logfile"), 80); wprintf(fd, "<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" WIDTH=\"45%\" ALIGN=\"CENTER\" VALIGN=\"MIDDLE\">\n"); wprintf(fd, "\t<TR>\n"); wprintf(fd, "\t\t<TD>\n"); wprintf(fd, "\t\t\t<PRE>\n"); httpd_playfile(fd, hashtable_lookup(cfg, "daemon-logfile")); wprintf(fd, "\t\t\t</PRE>\n"); wprintf(fd, "\t\t</TD>\n"); wprintf(fd, "\t</TR>\n"); wprintf(fd, "</TABLE>\r\n"); httpd_www_label(fd, "EOF", 80); return 1; }
static bool grpmgr_obj_is_member(obj_t grp_obj, obj_id_t member_oid) { struct grp_desc *grp_desc; struct grp_membership *membership; grp_desc = GRP_DESC(grp_obj); membership = hashtable_lookup(&grp_desc->members, &member_oid); if (membership && !membership->removed) { return true; } return false; }
bool wallet_is_pubkey_spendable(const struct wallet *wallet, const uint160 *pub_key) { struct wallet_key *wkey; bool s; s = hashtable_lookup(wallet->hash_keys, pub_key, sizeof *pub_key, (void *)&wkey); ASSERT(s); return wkey->spendable; }
static void * lookup_or_load(const char *modpath) { void *mod = hashtable_lookup(&modtable, (void*)modpath); if (mod == NULL) { mod = drsym_unix_load(modpath); if (mod != NULL) { hashtable_add(&modtable, (void*)modpath, mod); } } return mod; }
void script_closure_pred_equivalence_classes() { closure_operator *clop = clop_alloc_straightforward(); pred *ess_preds; size_t ess_sz; get_essential_predicates(2, &ess_preds, &ess_sz); /** We use a hash table to store a mapping between clones (equivalence * classes) and predicates that generate those clones (closure-equivalent * predicates). */ hashtable *ht = hashtable_alloc(512, clone_hash, (int (*)(const void *, const void *))clone_eq); /* construct the closure of all essential predicates */ for(pred *p = ess_preds; p < ess_preds + ess_sz; ++p) { clone *closure = aligned_alloc(32, sizeof(clone)); assert(closure); closure_one_pred(clop, p, closure); /* lookup equivalence class corresponding to `p` */ clone *equiv_preds = hashtable_lookup(ht, closure); if(equiv_preds == NULL) { equiv_preds = malloc(sizeof(clone)); assert(equiv_preds); clone_init(equiv_preds); hashtable_insert(ht, closure, equiv_preds); } else { free(closure); } clone_insert_pred(equiv_preds, p); } /* print the equivalence classes */ int idx = 1; for(hashtable_iterator it = hashtable_iterator_begin(ht); !hashtable_iterator_end(&it); hashtable_iterator_next(&it)) { hash_elem *elem = hashtable_iterator_deref(&it); printf("====== class %u ====================================\n", idx); for(clone_iterator itc = clone_iterator_begin((clone *)elem->value); !clone_iterator_end((clone *)elem->value, &itc); clone_iterator_next(&itc)) { pred p = clone_iterator_deref(&itc); printf("%s\t%s\n", pred_print_fingerprint(&p), pred_print_extensional_ex(&p)); } printf("\n"); free(elem->key); free(elem->value); ++idx; } hashtable_free(ht); free(ess_preds); clop_free(clop); }