示例#1
0
文件: spki.c 项目: macssh/macssh
static int
subject_match_hash(struct spki_subject *self,
		   int method,
		   const struct lsh_string *h1)
{
  struct lsh_string *h2;

  switch (method)
    {
    case ATOM_SHA1:
      if (self->sha1)
	h2 = self->sha1;
#if 0
      else if (self->key)
	h2 = self->sha1
	  = hash_string(&sha1_algorithm,
			sexp_format(self->key, SEXP_CANONICAL, 0), 1);
#endif
      else
	return 0;
      break;

    case ATOM_MD5:
      if (self->md5)
	h2 = self->md5;
#if 0
      else if (self->key)
	h2 = self->md5
	  = hash_string(&md5_algorithm,
			sexp_format(self->key, SEXP_CANONICAL, 0), 1);
#endif
      else
	return 0;
      break;

    default:
      return 0;
    }
  return lsh_string_eq(h1, h2);
}
示例#2
0
static NEOERR* aic_cmd_appousers(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    unsigned char *val = NULL; size_t vsize = 0;
    int count, offset;
    int pid;
    char *pname, *aname;
    NEOERR *err;

    REQ_GET_PARAM_STR(q->hdfrcv, "pname", pname);
    pid = hash_string(pname);
    
    mmisc_pagediv(q->hdfrcv, NULL, &count, &offset, NULL, q->hdfsnd);
    
    if (cache_getf(cd, &val, &vsize, PREFIX_APPOUSER"%d_%d", pid, offset)) {
        unpack_hdf(val, vsize, &q->hdfsnd);
    } else {
        MMISC_PAGEDIV_SET_N(q->hdfsnd, db, "appinfo", "pid=%d OR aid=%d",
                            NULL, pid, pid);
        MDB_QUERY_RAW(db, "appinfo", APPINFO_COL,
                      "pid=%d OR aid=%d ORDER BY uptime DESC LIMIT %d OFFSET %d",
                      NULL, pid, pid, count, offset);
        err = mdb_set_rows(q->hdfsnd, db, APPINFO_COL, "users", "1");
        if (err != STATUS_OK) return nerr_pass(err);
        HDF *node = hdf_get_child(q->hdfsnd, "users");
        while (node) {
            /* numcamer */
            aname = hdf_get_value(node, "aname", NULL);
            if (aname) {
                MDB_QUERY_RAW(db, "userinfo", " COUNT(*) AS numcamer ",
                              "aid=%d", NULL, hash_string(aname));
                err = mdb_set_row(node, db, " numcamer ", NULL);
                if (err != STATUS_OK) return nerr_pass(err);
            }
            node = hdf_obj_next(node);
        }
        CACHE_HDF(q->hdfsnd, AIC_CC_SEC, PREFIX_APPOUSER"%d_%d", pid, offset);
    }
    
    return STATUS_OK;
}
示例#3
0
文件: ref.cpp 项目: att/uwin
void reference::compute_hash_code()
{
  if (!rid.is_null())
    h = rid.hash();
  else {
    h = 0;
    for (int i = 0; i < nfields; i++)
      if (field[i].length() > 0) {
	h <<= 4;
	h ^= hash_string(field[i].contents(), field[i].length());
      }
  }
}
示例#4
0
文件: symtab.c 项目: freecores/marca
void push_sym(const char *symbol, uint8_t type, uint32_t addr)
{
  uint32_t pos;
  struct sym_info *sym;

  pos = hash_string(symbol) % SYMTAB_SIZE;
  sym = xmalloc(sizeof(struct sym_info));
  sym->symbol = symbol;
  sym->type = type;
  sym->addr = addr;
  sym->next = symtab[pos];
  symtab[pos] = sym;  
}
示例#5
0
/*************************************************************************
*       dict_search: look for entries in the dictionary
*
*       dict - pointer to dictionary to search
*       s - string to search for
*       number - pointer to long to return string number
*
*       Returns: pointer to string entry
*               NULL - entry not found
*               non-NULL - pointer to string entry
*************************************************************************/
STRING_ENTRY *dict_search(const DICTIONARY *dict, const char *s,
        long *number)
{
        unsigned long   hash_value;
        long    hash_index;
        long    string_index = -1;
        long    he;

        /* have to point to something */
        if (dict == NULL)
                return NULL;

        /* check value has to be OK */
        if (dict->check_value != DICT_VALIDATE)
                return NULL;

        /* must have a string */
        if (s == NULL) {
                *number = -1;
                return NULL;
        }

        /* must be non-NULL */
        if (s[0] == '\0') {
                *number = -1;
                return FALSE;
        }

        /* figure out which chain it should be in */
        hash_value = hash_string(s);
        hash_index = hash_value & dict->hash_mask;

        /* look for the entry in the chain */
        for (he = dict->chains[hash_index]; he != DICT_ENTRY_NONE;
                        he = dict->string_table[he].next) {
                char    *sa = (char*)(&dict->string_array[dict->string_table[he].string_offset]);

                /* compare hash_value and then string, in that order, for speed */
                if (dict->string_table[he].hash_value == hash_value && !strcmp(s, sa)) {
                        string_index = he;
                        break;
                }
        }
        if (string_index < 0) {
                *number = -1;
                return NULL;
        }

        *number = string_index;
        return dict->string_table+string_index;
}
示例#6
0
文件: uppg6.c 项目: h4xxel/algdat
struct PERSON *db_add_person(char *first_name, char *last_name) {
	char *string=malloc(strlen(first_name)+strlen(last_name)+3);
	unsigned int hash;
	struct PERSON **person;
	sprintf(string, "%s, %s", last_name, first_name);
	hash=hash_string(string);
	free(string);
	for(person=&people[hash%PEOPLE_TABLE]; *person; person=&(*person)->next);
	*person=calloc(sizeof(struct PERSON), 1);
	*((char **) &((*person)->name.first))=first_name;
	*((char **) &((*person)->name.last))=last_name;
	*((int *) &((*person)->hash))=hash;
	return *person;
}
示例#7
0
文件: uppg6.c 项目: h4xxel/algdat
void db_remove_info(struct PERSON *person, char *key) {
	unsigned int hash=hash_string(key);
	struct INFO **info, *tmp;
	for(info=&person->info[hash%INFO_TABLE]; *info; info=&(*info)->next) {
		if(strcasecmp(key, (*info)->key))
			continue;
		tmp=*info;
		*info=tmp->next;
		free((void *) tmp->key);
		free(tmp->value);
		free(tmp);
		return;
	}
}
示例#8
0
std::size_t UnivariatePolynomial::__hash__() const
{
    std::hash<std::string> hash_string;
    std::size_t seed = UNIVARIATEPOLYNOMIAL;

    seed += hash_string(this->var_->get_name());
    for (const auto &it : this->dict_) {
        std::size_t temp = UNIVARIATEPOLYNOMIAL;
        hash_combine<unsigned int>(temp, it.first);
        hash_combine<Basic>(temp, *(it.second.get_basic()));
        seed += temp;
    }
    return seed;
}
示例#9
0
struct rtpp_session *
session_findfirst(struct cfg *cf, const char *call_id)
{
    uint8_t hash;
    struct rtpp_session *sp;

    hash = hash_string(&cf->stable, call_id, NULL);
    for (sp = cf->hash_table[hash]; sp != NULL; sp = sp->next) {
	if (strcmp(sp->call_id, call_id) == 0) {
	    break;
	}
    }
    return (sp);
}
示例#10
0
static NEOERR* aic_cmd_appuserout(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    char *uname, *aname;
    int aid;
    NEOERR *err;

    REQ_GET_PARAM_STR(q->hdfrcv, "uname", uname);
    REQ_GET_PARAM_STR(q->hdfrcv, "aname", aname);
    aid = hash_string(aname);

    err = aic_cmd_appusers(q, cd, db);
    if (err != STATUS_OK) return nerr_pass(err);

    if (!hdf_get_valuef(q->hdfsnd, "userlist.%s.uname", uname))
        return nerr_raise(REP_ERR_NOTJOIN, "%s not join %s", uname, aname);

    MDB_EXEC(db, NULL, "DELETE FROM userinfo WHERE uid=%d AND aid=%d;",
             NULL, hash_string(uname), aid);

    cache_delf(cd, PREFIX_USERLIST"%d", aid);

    return STATUS_OK;
}
示例#11
0
/**
 * lookup the given string in the table.  Return an index
 * to the place it is, or the place where it should be.
 */
static unsigned int find_place(const char * str, String_id *ss)
{
	unsigned int h, s;
	h = hash_string(str, ss);

	if ((ss->table[h].str == NULL) || (strcmp(ss->table[h].str, str) == 0)) return h;
	s = stride_hash_string(str, ss);
	while (true)
	{
		h = h + s;
		if (h >= ss->size) h %= ss->size;
		if ((ss->table[h].str == NULL) || (strcmp(ss->table[h].str, str) == 0)) return h;
	}
}
示例#12
0
文件: model.c 项目: Tayyib/uludag
int
model_lookup_notify(const char *path)
{
	struct node *n;
	int val;

	val = hash_string(path, strlen(path)) % TABLE_SIZE;
	for (n = node_table[val]; n; n = n->next) {
		if (N_NOTIFY == n->type && strcmp(n->path, path) == 0) {
			return n->no;
		}
	}
	return -1;
}
示例#13
0
文件: proc.c 项目: mycoboco/beluga
/*
 *  accepts #if, #ifdef or #ifndef (a start of conditionals);
 *  ASSUMPTION: no signed zero on the host
 */
static lex_t *dif(const lmap_t *pos, int kind, int ign)
{
    lex_t *t;
    expr_t *c;
    const char *s;

    assert(pos);

    cond_push(kind, pos);
    t = lst_nexti();    /* skips if/ifdef/ifndef */
    if (ign) {
        cond_list->f.ignore = 2;    /* inside ignoring section */
        SKIPNL(t);
        return t;
    }
    SKIPSP(t);
    switch(kind) {
        case COND_KIF:
            if (t->id == LEX_NEWLINE)
                err_dpos(lmap_after(pos), ERR_PP_NOIFEXPR, "#if");
            else {
                c = expr_start(&t, "#if");
                cond_list->f.once = !(cond_list->f.ignore = xe(c->u.u, xO));
            }
            break;
        case COND_KIFNDEF:
            if (mg_state == MG_SINIT && state == SIDIREC)
                mg_state = MG_SIFNDEF;
        case COND_KIFDEF:
            if (t->id != LEX_ID) {
                err_dmpos(lmap_after(pos), ERR_PP_NOIFID, pos, NULL, kind);
                SKIPNL(t);
                return t;
            }
            if (mg_state == MG_SIFNDEF) {
                mg_name = hash_string(LEX_SPELL(t));
                mg_state = MG_SMACRO;
            }
            cond_list->f.once = !(cond_list->f.ignore =
                                      mcr_redef(s = LEX_SPELL(t)) ^ (kind == COND_KIFDEF));
            MCR_IDVAARGS(s, t);
            t = lst_nexti();
            break;
        default:
            assert(!"invalid conditional kind -- should never reach here");
            break;
    }

    return t;
}
示例#14
0
/*
 * input : aname(STR) asn(STR) masn(STR) email(STR) state(INT)
 * return: NORMAL REP_ERR_ALREADYREGIST
 * reply : NULL
 */
static NEOERR* aic_cmd_appnew(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    char *aname, *pname, *asn, *masn, *email;
    int aid, pid = 0, state;
    NEOERR *err;

    REQ_GET_PARAM_INT(q->hdfrcv, "state", state);
    REQ_GET_PARAM_STR(q->hdfrcv, "aname", aname);
    REQ_GET_PARAM_STR(q->hdfrcv, "asn", asn);
    REQ_GET_PARAM_STR(q->hdfrcv, "masn", masn);
    REQ_GET_PARAM_STR(q->hdfrcv, "email", email);

    REQ_FETCH_PARAM_STR(q->hdfrcv, "pname", pname);

    aid = hash_string(aname);
    if (pname) pid = hash_string(pname);

    err = aic_cmd_appinfo(q, cd, db);
    nerr_handle(&err, REP_ERR_NREGIST);
    if (err != STATUS_OK) return nerr_pass(err);

    if (hdf_get_obj(q->hdfsnd, "state"))
        return nerr_raise(REP_ERR_ALREADYREGIST, "%s already regist", aname);

    MDB_EXEC(db, NULL, "INSERT INTO appinfo (aid, aname, "
             " pid, asn, masn, email, state) "
             " VALUES ($1, $2::varchar(256), $3, $4::varchar(256), "
             " $5::varchar(256), $6::varchar(256), $7);",
             "isisssi", aid, aname, pid, asn, masn, email, state);
    
    cache_delf(cd, PREFIX_APPINFO"%d", aid);
    if (pid > 0) {
        cache_delf(cd, PREFIX_APPOUSER"%d_0", pid);
    }

    return STATUS_OK;
}
示例#15
0
文件: symtab.c 项目: freecores/marca
struct sym_info *get_sym(const char *symbol)
{
  uint32_t pos;
  struct sym_info *sym;

  pos = hash_string(symbol) % SYMTAB_SIZE;
  sym = symtab[pos];

  while ((sym != NULL) && (strcmp(sym->symbol, symbol) != 0))
    {
      sym = sym->next;
    }

  return sym;
}
示例#16
0
int smap_get_extended(smap *map, char *key, int *success) {
    if (!map) {
	*success = 0;
	return -1;
    }
    size_t hash = hash_string(key) % map->num_buckets;
    bucket buck = map->buckets[hash];
    for (size_t i = 0; i < buck.num_pairs; i += 1) {
	if (!strcmp(key, buck.pairs[i].key)) {
	    return buck.pairs[i].val;
	}
    }
    *success = 0;
    return -1;
}
示例#17
0
void *key_binary_get(dword *ary,char *key,dword size)
{
    if(!*ary)return 0;

    array *m = (array *)*ary;

    dword tmp = hash_string(key)%buffer;

    while(m[tmp].key)
    {
        if(!strncmp(key,(char*)m[tmp].key,size))break;
        ++tmp;
    }
    return (void *)m[tmp].value;
}
示例#18
0
struct file_entry * get_file_entry( struct archive *arc, const char *filename )
{
	ar_uint index;
	ar_uint64 key;

	if(arc->file_table == NULL)
		return NULL;

	key = hash_string(filename);
	index = get_file_index(arc, key);
	if(index >= arc->file_table_size)
		return NULL;

	return arc->file_table + index;
}
示例#19
0
/* Inserts S, which must be a malloc'd string, into SET, transferring ownership
   of S to SET.  Returns true if successful, false if SET is unchanged because
   it already contained a copy of S.  (In the latter case, S is freed.) */
bool
string_set_insert_nocopy (struct string_set *set, char *s)
{
  unsigned int hash = hash_string (s, 0);
  if (!string_set_find_node__ (set, s, hash))
    {
      string_set_insert__ (set, s, hash);
      return true;
    }
  else
    {
      free (s);
      return false;
    }
}
示例#20
0
void *key_string_get(dword *ary,char *key)
{
    if(!*ary)return 0;

    array *m = (array *)*ary;

    dword tmp = hash_string(key)%buffer;
    tmp+=(m[0].value/buffer)*buffer;
    ++tmp;
    while(m[tmp].key)
    {
        if(!strcmp(key,(char*)m[tmp].key))break;
        ++tmp;
    }
    return (void *)m[tmp].value;
}
示例#21
0
文件: trace.c 项目: 274914765/C
static int show_dev_hash(unsigned int value)
{
    int match = 0;
    struct list_head * entry = dpm_active.prev;

    while (entry != &dpm_active) {
        struct device * dev = to_device(entry);
        unsigned int hash = hash_string(DEVSEED, dev->bus_id, DEVHASH);
        if (hash == value) {
            printk("  hash matches device %s\n", dev->bus_id);
            match++;
        }
        entry = entry->prev;
    }
    return match;
}
示例#22
0
void add_command(const char *key, void *callback)
{
    struct builtin_command *cmd = (struct builtin_command*)malloc(sizeof(struct builtin_command));
    cmd->key = hash_string(key);
    cmd->interpret = callback;
    cmd->next = NULL;
    struct builtin_command *i = cmd_list;
    if(i) {
        while(i->next) {
            i = i->next;
        }
        i->next = cmd;
    } else {
        cmd_list = cmd;
    }
}
示例#23
0
文件: uppg6.c 项目: h4xxel/algdat
struct PERSON *db_find_person(const char *first_name, const char *last_name) {
	char *string=malloc(strlen(first_name)+strlen(last_name)+3);
	unsigned int hash;
	struct PERSON *person;
	sprintf(string, "%s, %s", last_name, first_name);
	hash=hash_string(string);
	free(string);
	for(person=people[hash%PEOPLE_TABLE]; person; person=person->next) {
		if(strcasecmp(first_name, person->name.first))
			continue;
		if(strcasecmp(last_name, person->name.last))
			continue;
		return person;
	}
	return NULL;
}
示例#24
0
文件: line.c 项目: mingpen/OpenNT
/* return the hashcode for this line */
DWORD
line_gethashcode(LINE line)
{
        if (line == NULL) {
                return(0);
        }

        if (! (line->flags & LF_HASHVALID)) {


                /* hashcode needs to be recalced */
                line->hash = hash_string(line->text, ignore_blanks);
                line->flags |= LF_HASHVALID;
        }
        return (line->hash);
}
示例#25
0
const token_info *lookup_token(const char *start, const char *end)
{
  unsigned n = hash_string(start, end - start) % TOKEN_TABLE_SIZE;
  for (;;) {
    if (token_table[n].tok == 0)
      break;
    if (strlen(token_table[n].tok) == size_t(end - start)
	&& memcmp(token_table[n].tok, start, end - start) == 0)
      return &(token_table[n].ti);
    if (n == 0)
      n = TOKEN_TABLE_SIZE - 1;
    else
      --n;
  }
  return &default_token_info;
}
示例#26
0
文件: clx.c 项目: mycoboco/beluga
/*
 *  recognizes keywords and identifiers
 */
static int id(lex_t *t)
{
    unsigned h;
    const struct tab *p;

    assert(t);

    clx_tok = hash_string(LEX_SPELL(t));
    h = hashkey(clx_tok, NELEM(tab));
    for (p = tab[h]; p; p = p->link)
        if (p->key == clx_tok)
            return p->code;

    clx_sym = sym_lookup(clx_tok, sym_ident);
    return LEX_ID;
}
示例#27
0
/* Return the value associated with the given key in the hashtable.
   Returns NULL if there is no association for that key.
 */
void *
hashtable_get(struct hashtable *table, char *key)
{
  int hash;
  struct hashtable_bucket *bucket;

  if (table == NULL || key == NULL) {
    return NULL;
  }
  hash = hash_string(key);
  bucket = hashtable_find_bucket(table->buckets, table->size, hash, key);
  if (bucket->key == NULL) {
    return NULL;
  }
  return bucket->value;
}
示例#28
0
static int show_file_hash(unsigned int value)
{
	int match;
	char *tracedata;

	match = 0;
	for (tracedata = &__tracedata_start ; tracedata < &__tracedata_end ;
			tracedata += 2 + sizeof(unsigned long)) {
		unsigned short lineno = *(unsigned short *)tracedata;
		const char *file = *(const char **)(tracedata + 2);
		unsigned int hash = hash_string(lineno, file, FILEHASH);
		if (hash != value)
			continue;
<<<<<<< HEAD
		pr_info("  hash matches %s:%u\n", file, lineno);
=======
示例#29
0
文件: translate.c 项目: jff/mathspad
void set_translation8(char *orig,  Uchar *transl)
{
  int i;
  Translation *tl;
  if (!currentlang) currentlang=new_language();
  i=hash_string(orig);
  tl = malloc(sizeof(Translation));
  tl->hashvalue=i;
  tl->original=orig;
  tl->translate=transl;
  tl->autoconv=0;
  tl->next=currentlang->translist[i%currentlang->hashsize];
  currentlang->translist[i%currentlang->hashsize]=tl;
  currentlang->entries++;
  rehash_translang(currentlang);
}
示例#30
0
static int show_dev_hash(unsigned int value)
{
	int match = 0;
	struct list_head *entry = dpm_list.prev;

	while (entry != &dpm_list) {
		struct device * dev = to_device(entry);
		unsigned int hash = hash_string(DEVSEED, dev_name(dev), DEVHASH);
		if (hash == value) {
			dev_info(dev, "hash matches\n");
			match++;
		}
		entry = entry->prev;
	}
	return match;
}