/*! Retrieves the block \a blockNumber from the hash table, if it's already there, or reads it from the disk. \param _allocated tells you whether or not a new block has been allocated to satisfy your request. \param readBlock if \c false, the block will not be read in case it was not already in the cache. The block you retrieve may contain random data. */ static cached_block* get_cached_block(block_cache* cache, fssh_off_t blockNumber, bool* _allocated, bool readBlock = true) { if (blockNumber < 0 || blockNumber >= cache->max_blocks) { fssh_panic("get_cached_block: invalid block number %" FSSH_B_PRIdOFF " (max %" FSSH_B_PRIdOFF ")", blockNumber, cache->max_blocks - 1); return NULL; } cached_block* block = (cached_block*)hash_lookup(cache->hash, &blockNumber); *_allocated = false; if (block == NULL) { // read block into cache block = cache->NewBlock(blockNumber); if (block == NULL) return NULL; hash_insert(cache->hash, block); *_allocated = true; } if (*_allocated && readBlock) { int32_t blockSize = cache->block_size; if (fssh_read_pos(cache->fd, blockNumber * blockSize, block->current_data, blockSize) < blockSize) { cache->RemoveBlock(block); FATAL(("could not read block %" FSSH_B_PRIdOFF "\n", blockNumber)); return NULL; } } if (block->unused) { //TRACE(("remove block %Ld from unused\n", blockNumber)); block->unused = false; cache->unused_blocks.Remove(block); } block->ref_count++; block->accessed++; return block; }
/******************************************************************* * * Description: Retrieve a copy of a string value * * Modified args: None * * Return value: 0 if key exists, negative if not. * *******************************************************************/ int hash_get_str(HASH_TABLE *ptbl, char *key, char *data) { struct hash_table_datum *entry; HASH_DATUM key_datum; key_datum.size = strlen(key) + 1; key_datum.data = key; if ((entry = hash_lookup(ptbl, &key_datum)) == NULL) { return -1; } memcpy(data, entry->data, entry->data_length); return 0; }
NEOERR* member_car_data_mod(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses) { mevent_t *evt = hash_lookup(evth, "member"); char *mname; NEOERR *err; MCS_NOT_NULLB(cgi->hdf, evt); MEMBER_CHECK_LOGIN(); hdf_set_value(evt->hdfsnd, "mname", mname); hdf_copy(evt->hdfsnd, NULL, hdf_get_obj(cgi->hdf, PRE_QUERY)); MEVENT_TRIGGER(evt, mname, REQ_CMD_CAR_UP, FLAGS_NONE); return STATUS_OK; }
void * mem_reallocate( void * ptr, unsigned int size, unsigned int line, const char * file ) { hashnode_t * h; void * ret; if( (h = hash_lookup( ptr )) == NULL ) { OS_Error( 1, "mem_realloc() with unallocated pointer" ); } ret = mem_allocate( size, line, file ); memcpy( ret, ptr, size <= h->size ? size : h->size ); mem_free( ptr ); return( ret ); }
NEOERR* oms_secy_data_mod(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses) { mevent_t *evt = (mevent_t*)hash_lookup(evth, "aic"); char *aname, *uname; NEOERR *err; HDF_GET_STR(cgi->hdf, PRE_QUERY".aname", uname); APP_CHECK_ADMIN_OTHER(uname); hdf_set_value(evt->hdfsnd, "pname", aname); hdf_set_value(evt->hdfsnd, "aname", uname); MEVENT_TRIGGER(evt, aname, REQ_CMD_APP_SETSECY, FLAGS_NONE); return STATUS_OK; }
/******************************************************************* * * Description: Get a unsigned value copy from the table. * * Modified args: None * * Return value: 0 if key exists, negative if not. * *******************************************************************/ int hash_get_ul(HASH_TABLE *ptbl, char *key, unsigned long *pdata) { struct hash_table_datum *entry; HASH_DATUM key_datum; key_datum.size = strlen(key) + 1; key_datum.data = key; if ((entry = hash_lookup(ptbl, &key_datum)) == NULL) { return -1; } *pdata = *((unsigned long *)entry->data); return 0; }
NEOERR* city_s_data_get(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses) { mevent_t *evt = hash_lookup(evth, "city"); char *s; if (!cgi || !cgi->hdf || !evt) return nerr_raise(NERR_ASSERT, "paramter null"); HDF_GET_STR(cgi->hdf, PRE_QUERY".c", s); hdf_set_value(evt->hdfsnd, "c", s); MEVENT_TRIGGER(evt, NULL, REQ_CMD_CITY_BY_S, FLAGS_SYNC); hdf_copy(cgi->hdf, PRE_OUTPUT, evt->hdfrcv); return STATUS_OK; }
NEOERR* city_id_data_get(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses) { mevent_t *evt = hash_lookup(evth, "city"); char *id; MCS_NOT_NULLB(cgi->hdf, evt); HDF_GET_STR(cgi->hdf, PRE_QUERY".id", id); hdf_set_value(evt->hdfsnd, "id", id); MEVENT_TRIGGER(evt, NULL, REQ_CMD_CITY_BY_ID, FLAGS_SYNC); hdf_copy(cgi->hdf, PRE_OUTPUT, evt->hdfrcv); return STATUS_OK; }
NEOERR* inbox_data_del(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses) { mevent_t *evt = hash_lookup(evth, "aux"); char *mname; NEOERR *err; MCS_NOT_NULLB(cgi->hdf, evt); MEMBER_CHECK_LOGIN(); hdf_copy(evt->hdfsnd, NULL, hdf_get_obj(cgi->hdf, PRE_QUERY)); hdf_set_value(evt->hdfsnd, "mname", mname); MEVENT_TRIGGER(evt, NULL, REQ_CMD_AUX_INBOX_DEL, FLAGS_NONE); return STATUS_OK; }
int thread_new ( struct thread * thread, L4_SpaceId_t space, L4_ThreadId_t scheduler, L4_ThreadId_t pager, L4_ThreadId_t exception ) { int rv; int fpu = 0; #if defined(ARCH_IA32) /* Always allocate FPU resources to every thread iguana creates on IA32 * (bug 2836) */ fpu = 0x80000001; #endif rv = L4_ThreadControl ( thread->id, space, scheduler, pager, exception, fpu, (void *)thread->utcb ); if (rv == 1) { L4_Word_t handle; L4_StoreMR(0, &handle); thread->handle.raw = handle; assert(hash_lookup(l4tid_to_thread, handle) == NULL); /* Guaranteed to work because hash_lookup was just performed */ hash_insert(l4tid_to_thread, handle, thread); L4_Set_Priority(thread->id, 100); } else { /* Initialise the handle to an invalid valid. */ thread->handle = L4_nilthread; } return rv; }
static Entry* cache_get (Cache* cache, const char* key, bool* hit) { #if CACHE_FIXED_SIZE size_t const h = String_Hash (key); size_t const idx = h % cache->size; Entry* const ce = cache->table + idx; bool const same_key = (ce->key && ce->hash == h && strcmp (ce->key, key) == 0); if (same_key) { *hit = true; } else { *hit = false; if (ce->key) { Log_Printf (LOG_DEBUG, "CACHE_COLLIDE (old='%s', new='%s')", ce->key, key); cache->nr_collide++; talloc_free (ce->key); } else { cache->nr_entries++; } ce->key = talloc_strdup (cache->table, key); if (ce->key == NULL) return NULL; // ----------> ce->hash = h; } #else Entry const searched = { .key = key }; Entry* ce = hash_lookup (cache->table, &searched); if (ce) { *hit = true; } else { *hit = false; ce = talloc (cache, Entry); if (ce) { ce->key = talloc_strdup (ce, key); if (ce->key == NULL) return NULL; // ----------> ce = hash_insert (cache->table, ce); } } #endif return ce; }
static errno_t get_autofs_map(struct autofs_ctx *actx, char *mapname, struct autofs_map_ctx **map) { hash_key_t key; hash_value_t value; int hret; key.type = HASH_KEY_STRING; key.str = mapname; hret = hash_lookup(actx->maps, &key, &value); if (hret == HASH_SUCCESS) { *map = talloc_get_type(value.ptr, struct autofs_map_ctx); return EOK; } else if (hret == HASH_ERROR_KEY_NOT_FOUND) {
static int send_tcp(struct dns_query *q) { const struct sa *srv; struct tcpconn *tc; int err = 0; if (!q) return EINVAL; while (q->ntx < *q->srvc) { srv = &q->srvv[q->ntx++]; DEBUG_NOTICE("trying tcp server#%u: %J\n", q->ntx-1, srv); tc = list_ledata(hash_lookup(q->dnsc->ht_tcpconn, sa_hash(srv, SA_ALL), tcpconn_cmp_handler, (void *)srv)); if (!tc) { err = tcpconn_alloc(&tc, q->dnsc, srv); if (err) continue; } if (tc->connected) { q->mb.pos = 0; err = tcp_send(tc->conn, &q->mb); if (err) { tcpconn_close(tc, err); continue; } tmr_start(&tc->tmr, tc->dnsc->conf.idle_timeout, tcpconn_timeout_handler, tc); DEBUG_NOTICE("tcp send %J\n", srv); } list_append(&tc->ql, &q->le_tc, q); q->tc = mem_ref(tc); break; } return err; }
value arc_hash_insert(arc *c, value hash, value key, value val) { unsigned int hv, index, i; value e; index = 0; /* First of all, look for the key if a binding already exists for it */ e = hash_lookup(c, hash, key, &index); if (BOUND_P(e)) { /* if we are already bound, overwrite the old value */ e = VINDEX(HASH_TABLE(hash), index); BVALUE(e) = val; return(val); } /* Not yet bound. Look for a slot where we can put it */ if (HASH_NENTRIES(hash)+1 > HASH_LLIMIT(hash)) hashtable_expand(c, hash); SET_NENTRIES(hash, HASH_NENTRIES(hash)+1); hv = arc_hash(c, key); index = hv & TABLEMASK(hash); for (i=0;; i++) { e = VINDEX(HASH_TABLE(hash), index); /* If we see an empty bucket in our search, or if we see a bucket whose key is the same as the key specified, we have found the place where the element should go. This second case should never happen, based on what we did above, but hey, belt and suspenders. */ if (EMPTYP(e) || arc_is2(c, BKEY(e), key) == CTRUE) break; /* We found a bucket, but it is occupied by some other key. Continue probing. */ index = (index + PROBE(i)) & TABLEMASK(hash); } if (EMPTYP(e)) { /* No such key in the hash table yet. Create a bucket and assign it to the table. */ e = mkhashbucket(c, key, val, index, hash, INT2FIX(hv)); SVINDEX(HASH_TABLE(hash), index, e); } else { /* The key already exists. Use the current bucket but change the value to the value specified. */ BVALUE(e) = val; } return(val); }
SessionGetter::SessionGetter(team_id team, Session **_session) { RecursiveLocker locker(&sLock); if (sMainSession != NULL) fSession = sMainSession; else fSession = (Session *)hash_lookup(sTeamHash, &team); if (fSession != NULL) { if (!fSession->IsClosing()) fSession->Lock(); else fSession = NULL; } *_session = fSession; }
NEOERR* inbox_system_data_get(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses) { mevent_t *evt = hash_lookup(evth, "aux"); char *mname; NEOERR *err; MCS_NOT_NULLB(cgi->hdf, evt); MEMBER_CHECK_LOGIN(); SET_DASHBOARD_ACTION(cgi->hdf); hdf_copy(evt->hdfsnd, NULL, hdf_get_obj(cgi->hdf, PRE_QUERY)); hdf_set_value(evt->hdfsnd, "mname", mname); MEVENT_TRIGGER(evt, mname, REQ_CMD_AUX_INBOX_GET, FLAGS_SYNC); hdf_copy(cgi->hdf, PRE_OUTPUT, evt->hdfrcv); return STATUS_OK; }
/* * inval_buf() * Clear out (without sync'ing) some buffer data * * This routine will handle multiple buffer entries, but "d" must * point to an aligned beginning of such an entry. */ void inval_buf(daddr_t d, uint len) { struct buf *b; for (;;) { b = hash_lookup(bufpool, d); if (b) { get(b); free_buf(b); } if (len <= EXTSIZ) { break; } d += EXTSIZ; len -= EXTSIZ; } }
NEOERR* bore_op_data_get(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses) { mevent_t *evt = hash_lookup(evth, "aux"); char *mname; NEOERR *err; MEMBER_CHECK_ADMIN(); SET_ADMIN_ACTION(cgi->hdf); hdf_copy(evt->hdfsnd, NULL, hdf_get_obj(cgi->hdf, PRE_QUERY)); MEVENT_TRIGGER(evt, NULL, REQ_CMD_MEMORY_GET, FLAGS_SYNC); hdf_copy(cgi->hdf, PRE_OUTPUT".memory", evt->hdfrcv); return STATUS_OK; }
static auth_user_t * authDigestUserFindUsername(const char *username) { auth_user_hash_pointer *usernamehash; auth_user_t *auth_user; debug(29, 9) ("authDigestUserFindUsername: Looking for user '%s'\n", username); if (username && (usernamehash = hash_lookup(proxy_auth_username_cache, username))) { while ((usernamehash->auth_user->auth_type != AUTH_DIGEST) && (usernamehash->next)) usernamehash = usernamehash->next; auth_user = NULL; if (usernamehash->auth_user->auth_type == AUTH_DIGEST) { auth_user = usernamehash->auth_user; } return auth_user; } return NULL; }
void mx_pop_handler(mx_connection_t *conn, mx_token_t *tokens, int tokens_count) { mx_queue_t *queue; mx_queue_item_t *item; if (hash_lookup(mx_daemon->table, tokens[1].value, (void **)&queue) == -1) { mx_send_reply_return(conn, MX_QUEUE_NOTFOUND); } if (!mx_queue_fetch_head(queue, (void **)&item)) { mx_send_reply_return(conn, MX_QUEUE_EMPTY); } mx_send_item(conn, item); mx_queue_delete_head(queue); mx_dirty_update(); return; }
NEOERR* city_ip_data_get(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses) { mevent_t *evt = hash_lookup(evth, "city"); char *ip; if (!cgi || !cgi->hdf || !evt) return nerr_raise(NERR_ASSERT, "paramter null"); ip = hdf_get_value(cgi->hdf, PRE_QUERY".ip", NULL); if (!ip) ip = hdf_get_value(cgi->hdf, PRE_REQ_IP, "0.0.0.0"); hdf_set_value(evt->hdfsnd, "ip", ip); MEVENT_TRIGGER(evt, NULL, REQ_CMD_CITY_BY_IP, FLAGS_SYNC); hdf_copy(cgi->hdf, PRE_OUTPUT, evt->hdfrcv); return STATUS_OK; }
static void hash_slist_insert (Hash *hash, const gchar *key, gpointer value) { GSList *list; list = hash_lookup (hash, key); if (list) { list->next = g_slist_prepend (list->next, value); } else { list = g_slist_prepend (NULL, value); list = g_slist_prepend (list, NULL); if (key == NULL) hash->null = list; else g_hash_table_insert (hash->hash, g_strdup (key), list); } }
void muscle_insert (const char *key, char *value) { muscle_entry probe; muscle_entry *entry; probe.key = key; entry = hash_lookup (muscle_table, &probe); if (!entry) { /* First insertion in the hash. */ entry = xmalloc (sizeof *entry); entry->key = key; hash_insert (muscle_table, entry); } entry->value = value; }
string get_remote_file(const_string filename) { string *lookup = NULL; string localname = NULL; boolean ret; if ((remote_db = hash_exists_p(hashtable_remote)) == NULL) { remote_db = hash_create (1007, hashtable_remote); } lookup = hash_lookup(remote_db, filename); /* Either the file has already been downloaded */ if (lookup && *lookup) { return *lookup; } /* Or it is a new one */ /* Get some local name */ localname =_tempnam(getenv("TMP"), "kpse"); if (localname == NULL) return localname; index = strlen(filename); log_buffer = xmalloc(index + 24); strcpy(log_buffer, filename); ret = (get_url_to_file(filename, localname, 0, DoDownloadLog, DoDownloadProgress, NULL, /* AfxGetInstanceHandle() */ NetIOIE5, /*g_uiNetMethod */ NULL, /* _proxy_address */ 80 /* g_uiProxyPort */ ) == 0); if (ret) hash_insert(remote_db, filename, localname); else localname = NULL; puts("\n"); free(log_buffer); return localname; }
static bool response_handler(const struct sip_msg *msg, void *arg) { struct sip_ctrans *ct; struct sip *sip = arg; ct = list_ledata(hash_lookup(sip->ht_ctrans, hash_joaat_pl(&msg->via.branch), cmp_handler, (void *)msg)); if (!ct) return false; if (ct->invite) { invite_response(ct, msg); return true; } switch (ct->state) { case TRYING: case PROCEEDING: if (msg->scode < 200) { ct->state = PROCEEDING; ct->resph(0, msg, ct->arg); } else { ct->state = COMPLETED; ct->resph(0, msg, ct->arg); if (sip_transp_reliable(ct->tp)) { mem_deref(ct); break; } tmr_start(&ct->tmr, SIP_T4, tmr_handler, ct); tmr_cancel(&ct->tmre); } break; default: break; } return true; }
static void cacheQueryPeer(Cache * cache, const cache_key * key) { const int peer_has_it = hash_lookup(cache->peer->hash, key) != NULL; const int we_think_we_have_it = cacheDigestTest(cache->digest, key); cache->qstats.query_count++; if (peer_has_it) { if (we_think_we_have_it) cache->qstats.true_hit_count++; else cache->qstats.false_miss_count++; } else { if (we_think_we_have_it) cache->qstats.false_hit_count++; else cache->qstats.true_miss_count++; } }
NEOERR* email_add(HDF *datanode, HASH *evth, char *emailtype, char *mname) { mevent_t *evt; NEOERR *err; MCS_NOT_NULLC(datanode, evth, mname); evt = hash_lookup(evth, "aux"); MCS_NOT_NULLA(evt); err = mtpl_InConfigRend_get(evt->hdfsnd, datanode, "email", emailtype, g_datah); if (err != STATUS_OK) return nerr_pass(err); hdf_set_value(evt->hdfsnd, "to", mname); MEVENT_TRIGGER(evt, NULL, REQ_CMD_AUX_EMAIL_ADD, FLAGS_NONE); return STATUS_OK; }
/** * The caller owns the key, and this function will duplicate it * if needed. This function owns the value and will destroy it * if there's an error. */ void Request_set(Request *req, bstring key, bstring val, int replace) { hnode_t *n = hash_lookup(req->headers, key); struct bstrList *val_list = NULL; int rc = 0; int i = 0; if(n == NULL) { // make a new bstring list to use as our storage val_list = bstrListCreate(); rc = bstrListAlloc(val_list, MAX_DUPE_HEADERS); check(rc == BSTR_OK, "Couldn't allocate space for header values."); val_list->entry[0] = val; val_list->qty = 1; hash_alloc_insert(req->headers, bstrcpy(key), val_list); } else { val_list = hnode_get(n); check(val_list != NULL, "Malformed request, missing bstrlist in node. Tell Zed: %s=%s", bdata(key), bdata(val)); if(replace) { // destroy ALL old ones and put this in their place for(i = 0; i < val_list->qty; i++) { bdestroy(val_list->entry[i]); } val_list->entry[0] = val; val_list->qty = 1; } else { check(val_list->qty < MAX_DUPE_HEADERS, "Header %s duplicated more than %d times allowed.", bdata(key), MAX_DUPE_HEADERS); val_list->entry[val_list->qty++] = val; } } return; error: bdestroy(val); return; }
NEOERR* pos_data_mod(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses) { STRING str; string_init(&str); mdb_conn *db = hash_lookup(dbh, "city"); NEOERR *err; if (!cgi || !cgi->hdf || !db) return nerr_raise(NERR_ASSERT, "paramter null"); int id = hdf_get_int_value(cgi->hdf, PRE_QUERY".id", 0); err = mdb_build_upcol(hdf_get_obj(cgi->hdf, PRE_QUERY), hdf_get_obj(g_cfg, "Db.UpdateCol.city"), &str); if (err != STATUS_OK) return nerr_pass(err); MDB_EXEC(db, NULL, "UPDATE city SET %s WHERE id=%d;", NULL, str.buf, id); return STATUS_OK; }
NEOERR* ldml_render(char *filename, char *keyname, HDF *datanode, HDF *outnode) { HASH *datah; HDF *confignode; MCS_NOT_NULLC(filename, keyname, outnode); datah = hash_lookup(g_datah, "runtime_dml"); MCS_NOT_NULLA(datah); confignode = hash_lookupf(datah, "%s.hdf", filename); if (!confignode) return nerr_raise(NERR_ASSERT, "data file %s nexist", filename); confignode = hdf_get_obj(confignode, keyname); if (!confignode) return nerr_raise(NERR_ASSERT, "%s.hdf %s nexist", filename, keyname); return nerr_pass(mcs_data_rend(confignode, datanode, outnode)); }