示例#1
0
文件: fptree.c 项目: nionjo/dm
static void _all_children(int n, FPTREE * fpt, HashTable * id_count_dict){
    int stack[LINE_LEN], i = -1, pitem = -1, pop = 0, psupp = 0, id_count = 0;
    do{
        int ci = fpt->nodelist[n].ci;
        if (ci != 0 && pop == 0){
            pitem = fpt->nodelist[ci].item;
            psupp = fpt->nodelist[ci].supp;
            id_count = 0;
            if (EXISTS == hash_exists(id_count_dict,pitem)){
                hash_find(id_count_dict,pitem,&id_count);
            }
            id_count += psupp;
            hash_add(id_count_dict,pitem,id_count);

            stack[++i] = ci;
            n = ci;
            pop = 0;
        }
        else if (i >= 0){
            n = stack[i--];
            pop = 1;
            int si = fpt->nodelist[n].si;
            if (si != 0){
                pitem = fpt->nodelist[si].item;
                psupp = fpt->nodelist[si].supp;
                id_count = 0;
                if (EXISTS == hash_exists(id_count_dict,pitem)){
                    hash_find(id_count_dict,pitem,&id_count);
                }
                id_count += psupp;
                hash_add(id_count_dict,pitem,id_count);

                stack[++i] = si;
                n = si;
                pop = 0;
            }
        }
    }while(i >= 0);
}
示例#2
0
void *hash_find_or_create(struct hash_header *ht, int key)
{
  void	*rval;

if (DEBUG>10) log("hash_find_or_create");
  rval = hash_find(ht, key);
  if (rval)
    return rval;

  rval = (void*)malloc(ht->rec_size);
  _hash_enter(ht,key,rval);
  return rval;
}
示例#3
0
文件: track.c 项目: blanciq/bq-killer
void *hash_find_or_create( HASH_HEADER *ht, int key )
{
	void *rval;

	rval = hash_find( ht, key );
	if ( rval )
	return rval;

	rval = (void *) malloc( ht->rec_size );
	_hash_enter( ht, key, rval );

	return rval;
}
示例#4
0
OBJECT * macro_header_get( OBJECT * macro_name )
{
    HEADER_MACRO * v;
    if ( header_macros_hash && ( v = (HEADER_MACRO *)hash_find(
        header_macros_hash, macro_name ) ) )
    {
        if ( DEBUG_HEADER )
            printf( "### macro '%s' evaluated to '%s'\n", object_str( macro_name
                ), object_str( v->filename ) );
        return v->filename;
    }
    return 0;
}
示例#5
0
static tdesc_t *
tdesc_lookup(dwarf_t *dw, int tid)
{
	tdesc_t tmpl;
	void *tdp;

	tmpl.t_id = tid;

	if (hash_find(dw->dw_tidhash, &tmpl, &tdp))
		return (tdp);
	else
		return (NULL);
}
示例#6
0
LIST * var_get_and_clear_raw( module_t * module, OBJECT * symbol )
{
    LIST * result = L0;
    VARIABLE * v;

    if ( module->variables && ( v = (VARIABLE *)hash_find( module->variables, symbol ) ) )
    {
        result = v->value;
        v->value = L0;
    }

    return result;
}
示例#7
0
void *hash_get(hash_t ht, hash_key_t key)
{
	if (ht) {
		struct hash_element *entry = NULL;

		entry = hash_find(ht, key, 0);
		if (entry) {
			return entry->value;
		}
	}

	return NULL;
}
示例#8
0
LIST * var_get( struct module_t * module, OBJECT * symbol )
{
    LIST * result = L0;
#ifdef OPT_AT_FILES
    /* Some "fixed" variables... */
    if ( object_equal( symbol, constant_TMPDIR ) )
    {
        list_free( saved_var );
        result = saved_var = list_new( object_new( path_tmpdir() ) );
    }
    else if ( object_equal( symbol, constant_TMPNAME ) )
    {
        list_free( saved_var );
        result = saved_var = list_new( path_tmpnam() );
    }
    else if ( object_equal( symbol, constant_TMPFILE ) )
    {
        list_free( saved_var );
        result = saved_var = list_new( path_tmpfile() );
    }
    else if ( object_equal( symbol, constant_STDOUT ) )
    {
        list_free( saved_var );
        result = saved_var = list_new( object_copy( constant_STDOUT ) );
    }
    else if ( object_equal( symbol, constant_STDERR ) )
    {
        list_free( saved_var );
        result = saved_var = list_new( object_copy( constant_STDERR ) );
    }
    else
#endif
    {
        VARIABLE * v;
        int n;

        if ( ( n = module_get_fixed_var( module, symbol ) ) != -1 )
        {
            if ( DEBUG_VARGET )
                var_dump( symbol, module->fixed_variables[ n ], "get" );
            result = module->fixed_variables[ n ];
        }
        else if ( module->variables && ( v = (VARIABLE *)hash_find( module->variables, symbol ) ) )
        {
            if ( DEBUG_VARGET )
                var_dump( v->symbol, v->value, "get" );
            result = v->value;
        }
    }
    return result;
}
示例#9
0
/* Update router table */
void
router_update(struct iphdr *ip_header)
{
    void                   *fd;
    uint32_t                size_ip;
    uint64_t                key;
    msg_server_t            msg;
    struct tcphdr          *tcp_header;
#if (TCPCOPY_MYSQL_ADVANCED) 
    uint32_t                size_tcp, cont_len, tot_len;
    unsigned char          *payload;
#endif

    if (ip_header->protocol != IPPROTO_TCP) {
        tc_log_info(LOG_INFO, 0, "this is not a tcp packet");
        return;
    }

    size_ip = ip_header->ihl << 2;
    tcp_header = (struct tcphdr*)((char *)ip_header + size_ip);

    memset(&msg, 0, sizeof(struct msg_server_s));
    memcpy((void *) &(msg.ip_header),  ip_header,  sizeof(struct iphdr));
    memcpy((void *) &(msg.tcp_header), tcp_header, sizeof(struct tcphdr));

#if (TCPCOPY_MYSQL_ADVANCED) 
    tot_len  = ntohs(ip_header->tot_len);
    size_tcp = tcp_header->doff << 2;
    cont_len = tot_len - size_ip - size_tcp;
    if (cont_len > 0) {
        payload = (unsigned char*)((char*)tcp_header + size_tcp);
        if (cont_len <= MAX_PAYLOAD_LEN) {
            /*
             * Only transfer payload if content length is less
             * than MAX_PAYLOAD_LEN
             */
            memcpy((void *) &(msg.payload), payload, cont_len);
        }
    }
#endif

    key = get_key(ip_header->daddr, tcp_header->dest);
    fd  = hash_find(table, key);
    if ( NULL == fd ) {
        tc_log_debug0(LOG_DEBUG, 0, "fd is null");
        delay_table_add(key, &msg);
        return ;
    }

    tc_socket_send((int) (long) fd, (char *) &msg, MSG_SERVER_SIZE);
}
示例#10
0
void
change_cond(char *label, char *newcond)
{
    CondNode *condnode = (CondNode *) hash_find(gWindow->fCondHashTable, label);

    if (condnode == NULL) {
        fprintf(stderr, "Error: Tried to set an uncreated cond %s\n", label);
    }
    else {
        free(condnode->cond);
        condnode->cond = halloc(strlen(newcond) + 1, "Condnode->cond");
        strcpy(condnode->cond, newcond);
    }
}
示例#11
0
pilot_t new_pilot(const char* p_name, void*init_data) {
	/* seek for entry in htab */
	pilot_cache_elem_t pce = (pilot_cache_elem_t) hash_find(pilot_mgr.cache, (hash_key)p_name);
//	printf("new_pilot init_data=%p\n",init_data);
	if(!pce) {
		pce = new_pilot_cache_elem(p_name);
		hash_addelem(pilot_mgr.cache,(hash_key)pce->name,pce);
	}
	if(pce) {
		return new_pilot_from(pce,init_data);
	} else {
		return NULL;
	}
}
void hna_local_remove(uint8_t *addr, char *message)
{
	struct hna_local_entry *hna_local_entry;
	unsigned long flags;

	spin_lock_irqsave(&hna_local_hash_lock, flags);

	hna_local_entry = (struct hna_local_entry *)
		hash_find(hna_local_hash, addr);
	if (hna_local_entry)
		hna_local_del(hna_local_entry, message);

	spin_unlock_irqrestore(&hna_local_hash_lock, flags);
}
示例#13
0
void hash_iterate(struct hash_header *ht, void (*func)(), void *cdata)
{
    int	i;
    for (i=0; i<ht->klistlen; i++) {
        void	*temp;
        register int key;

        key = ht->keylist[i];
        temp = hash_find(ht, key);
        (*func)(key, temp, cdata);
        if (ht->keylist[i]!=key) /* They must have deleted this room */
            i--;	/* Hit this slot again. */
    }
}
示例#14
0
static void check_defined( LIST * class_names )
{
    LISTITER iter = list_begin( class_names );
    LISTITER const end = list_end( class_names );
    for ( ; iter != end; iter = list_next( iter ) )
    {
        if ( !hash_find( classes, list_item( iter ) ) )
        {
            out_printf( "Class %s is not defined\n", object_str( list_item( iter ) )
                );
            abort();
        }
    }
}
示例#15
0
int
check_condition(TextNode *node)
{
    CondNode *cond;
    InputBox *box;
    int ret_val;

    /* checks the condition presented and returns a 1 or a 0 */
    switch (node->type) {
      case openaxiom_Cond_token:
        cond = (CondNode *) hash_find(gWindow->fCondHashTable, node->data.text);
        if (!strcmp("0", cond->cond))
            return 0;
        else
            return 1;
      case openaxiom_Boxcond_token:
        box = (InputBox *) hash_find(gWindow->page->box_hash, node->data.text);
        return (box->picked);
      case openaxiom_Haslisp_token:
        if (spad_socket != NULL) {
            ret_val = send_int(spad_socket, TestLine);
            return (ret_val + 1);
        }
        else
            return 0;
      case openaxiom_Hasup_token:
        return need_up_button;
      case openaxiom_Hasreturn_token:
        return gWindow->fMemoStackIndex;
      case openaxiom_Hasreturnto_token:
        return (check_memostack(node));
      case openaxiom_Lastwindow_token:
        return (gSessionHashTable.num_entries == 1 || gParentWindow == gWindow);
      default:
        return 0;
    }
}
示例#16
0
文件: labels.c 项目: zoro0312/Liux
/*
 * Internal routine: finds the `union label' corresponding to the
 * given label name. Creates a new one, if it isn't found, and if
 * `create' is true.
 */
static union label *find_label(char *label, int create)
{
    char *prev;
    int prevlen, len;
    union label *lptr, **lpp;
    char label_str[IDLEN_MAX];
    struct hash_insert ip;

    if (islocal(label)) {
        prev = prevlabel;
        prevlen = strlen(prev);
        len = strlen(label);
        if (prevlen + len >= IDLEN_MAX) {
            nasm_error(ERR_NONFATAL, "identifier length exceed %i bytes",
                       IDLEN_MAX);
            return NULL;
        }
        memcpy(label_str, prev, prevlen);
        memcpy(label_str+prevlen, label, len+1);
        label = label_str;
    } else {
        prev = "";
        prevlen = 0;
    }

    lpp = (union label **) hash_find(&ltab, label, &ip);
    lptr = lpp ? *lpp : NULL;

    if (lptr || !create)
        return lptr;

    /* Create a new label... */
    if (lfree->admin.movingon == END_BLOCK) {
        /*
         * must allocate a new block
         */
        lfree->admin.next = (union label *)nasm_malloc(LBLK_SIZE);
        lfree = lfree->admin.next;
        init_block(lfree);
    }

    lfree->admin.movingon = BOGUS_VALUE;
    lfree->defn.label = perm_copy(label);
    lfree->defn.special = NULL;
    lfree->defn.is_global = NOT_DEFINED_YET;

    hash_add(&ip, lfree->defn.label, lfree);
    return lfree++;
}
/*
 * Returns 1 when image is signed and authorized.
 * Returns 0 when image is unauthorized.
 * Expects a pointer to the start of image and pointer to start of sig
 */
int
image_verify(unsigned char *image_ptr,
	     unsigned char *signature_ptr,
	     unsigned int image_size, unsigned hash_type)
{

	int ret = -1;
	int auth = 0;
	unsigned char *plain_text = NULL;
	unsigned int digest[8];
	unsigned int hash_size;

	plain_text = (unsigned char *)calloc(sizeof(char), SIGNATURE_SIZE);
	if (plain_text == NULL) {
		dprintf(CRITICAL, "ERROR: Calloc failed during verification\n");
		goto cleanup;
	}

	ret = image_decrypt_signature(signature_ptr, plain_text);
	if (ret == -1) {
		dprintf(CRITICAL, "ERROR: Image Invalid! Decryption failed!\n");
		goto cleanup;
	}

	/*
	 * Calculate hash of image for comparison
	 */
	hash_size =
	    (hash_type == CRYPTO_AUTH_ALG_SHA256) ? SHA256_SIZE : SHA1_SIZE;
	hash_find(image_ptr, image_size, (unsigned char *)&digest, hash_type);
	if (memcmp(plain_text, digest, hash_size) != 0) {
		dprintf(CRITICAL,
			"ERROR: Image Invalid! Please use another image!\n");
		ret = -1;
		goto cleanup;
	} else {
		/* Authorized image */
		auth = 1;
	}

	/* Cleanup after complete usage of openssl - cached data and objects */
 cleanup:
	if (plain_text != NULL)
		free(plain_text);
	EVP_cleanup();
	CRYPTO_cleanup_all_ex_data();
	ERR_remove_thread_state(NULL);
	return auth;
}
示例#18
0
int hash_delete(hcfg_t *cfg, const char *key)
{
    keyval_t *entry;

    entry = hash_find(cfg, key);
    if (entry == NULL || entry->key == NULL)
        return -1;

    free(entry->key);
    free(entry->val);
    entry->key = NULL;
    entry->val = NULL;
    --cfg->count;
    return 0;
}
示例#19
0
文件: libs.c 项目: clarkok/cript
static Value
_lib_to_string(VMState *vm, Value value)
{
    Hash *args = value_to_ptr(value);
    Value query_val = hash_find(args, 1);

    if (value_is_int(query_val)) {
        char buffer[30];
        sprintf(buffer, "%d", value_to_int(query_val));
        return cvm_get_cstring_value(vm, buffer);
    }
    else {
        return _lib_typeof(vm, value);
    }
}
示例#20
0
void *hash_put(hash_t ht, hash_key_t key, void *value)
{
	if (ht && (ht->count < ht->size)) {
		struct hash_element *entry = NULL;

		entry = hash_find(ht, key, 0);
		if (NULL == entry) {
			entry = hash_find(ht, key, 1);
		}
		if (entry) {
			if (ht->free && entry->value) {
				ht->free(entry->value);
			}
			if (entry->key == HASH_KEY_INVALID) {
				ht->count++;
			}
			entry->key = key;
			entry->value = value;
			return value;
		}
	}

	return NULL;
}
示例#21
0
struct orig_node *transtable_search(struct bat_priv *bat_priv, uint8_t *addr)
{
	struct hna_global_entry *hna_global_entry;
	unsigned long flags;

	spin_lock_irqsave(&bat_priv->hna_ghash_lock, flags);
	hna_global_entry = (struct hna_global_entry *)
				hash_find(bat_priv->hna_global_hash, addr);
	spin_unlock_irqrestore(&bat_priv->hna_ghash_lock, flags);

	if (!hna_global_entry)
		return NULL;

	return hna_global_entry->orig_node;
}
示例#22
0
文件: parse.c 项目: thors/ircd-ratbox
/* mod_add_cmd
 *
 * inputs	- command name
 *		- pointer to struct Message
 * output	- none
 * side effects - load this one command name
 *		  msg->count msg->bytes is modified in place, in
 *		  modules address space. Might not want to do that...
 */
void
mod_add_cmd(struct Message *msg)
{
	s_assert(msg != NULL);
	if(msg == NULL)
		return;

	if(hash_find(HASH_COMMAND, msg->cmd) != NULL)
		return;
	
	hash_add(HASH_COMMAND, msg->cmd, msg);
	msg->count = 0;
	msg->rcount = 0;
	msg->bytes = 0;
}
struct orig_node *transtable_search(uint8_t *addr)
{
	struct hna_global_entry *hna_global_entry;
	unsigned long flags;

	spin_lock_irqsave(&hna_global_hash_lock, flags);
	hna_global_entry = (struct hna_global_entry *)
		hash_find(hna_global_hash, addr);
	spin_unlock_irqrestore(&hna_global_hash_lock, flags);

	if (hna_global_entry == NULL)
		return NULL;

	return hna_global_entry->orig_node;
}
示例#24
0
static void
printsigns(const unsigned char *key,void *data)
{
  static int sign_count = 0;
  int ipct = 0;
  sign_count = *(int*)(hash_find(data,(const unsigned char *)"#count"));
#if 1
  ipct = pct(sign_count,signiary->key_count);
#else
  ipct = pct(sign_count,total_sign_instances);
#endif
  printf("%s\t%d\t%d\t",key,sign_count,ipct);
  hash_exec_user_key_data(data, printvals, &sign_count);
  printf("\n");
}
示例#25
0
文件: macro.c 项目: ajinkya93/OpenBSD
int
check_macro (const char *line, sb *expand,
	     const char **error, macro_entry **info)
{
  const char *s;
  char *copy, *cs;
  macro_entry *macro;
  sb line_sb;

  if (! ISALPHA (*line)
      && *line != '_'
      && *line != '$'
      && (! macro_mri || *line != '.'))
    return 0;

  s = line + 1;
  while (ISALNUM (*s)
	 || *s == '_'
	 || *s == '$')
    ++s;

  copy = (char *) alloca (s - line + 1);
  memcpy (copy, line, s - line);
  copy[s - line] = '\0';
  for (cs = copy; *cs != '\0'; cs++)
    *cs = TOLOWER (*cs);

  macro = (macro_entry *) hash_find (macro_hash, copy);

  if (macro == NULL)
    return 0;

  /* Wrap the line up in an sb.  */
  sb_new (&line_sb);
  while (*s != '\0' && *s != '\n' && *s != '\r')
    sb_add_char (&line_sb, *s++);

  sb_new (expand);
  *error = macro_expand (0, &line_sb, macro, expand);

  sb_kill (&line_sb);

  /* Export the macro information if requested.  */
  if (info)
    *info = macro;

  return 1;
}
示例#26
0
void
sH_index_step(const char *step, struct nsa_step *curr_step, int overt_star)
{
  const unsigned char **step_bits = split_step(step, overt_star);
  Hash_table *curr_hash = context->step_index;
  int i;
  for (i = 0; step_bits[i]; ++i)
    {
      struct nsa_hash_data *d;
      if ((d = hash_find(curr_hash,step_bits[i])))
	{
	  if (step_bits[i+1]) /* non-terminal */
	    {
	      struct nsa_hash_data *newd = new_hash_data();
	      newd->cands = NULL;
	      newd->continuations = NULL;
	      if (!d->continuations)
		d->continuations = hash_create(1);
	      hash_add(d->continuations,step_bits[i],newd);
	      curr_hash = d->continuations;
	    }
	  else  /* terminal */
	    {
	      if (!d->cands)
		d->cands = list_create(LIST_DOUBLE);
	      list_add(d->cands, curr_step);
	    }
	}
      else
	{
	  d = new_hash_data();
	  hash_add(curr_hash,step_bits[i],d);
	  if (step_bits[i+1])
	    {
	      d->cands = NULL;
	      d->continuations = hash_create(1);
	      curr_hash = d->continuations;
	    }
	  else
	    {
	      d->continuations = NULL;
	      d->cands = list_create(LIST_DOUBLE);
	      list_add(d->cands, curr_step);
	    }
	}
    }
  free(step_bits);
}
示例#27
0
int32_t texcache_loadoffsets(void)
{
    int32_t foffset, fsize, i;
    char *fname;

    scriptfile *script;

    Bstrcpy(ptempbuf,TEXCACHEFILE);
    Bstrcat(ptempbuf,".cache");
    script = scriptfile_fromfile(ptempbuf);

    if (!script) return -1;

    while (!scriptfile_eof(script))
    {
        if (scriptfile_getstring(script, &fname)) break;	// hashed filename
        if (scriptfile_getnumber(script, &foffset)) break;	// offset in cache
        if (scriptfile_getnumber(script, &fsize)) break;	// size

        i = hash_find(&texcache.hashes,fname);
        if (i > -1)
        {
            // update an existing entry
            texcacheindex *t = texcache.iptrs[i];
            t->offset = foffset;
            t->len = fsize;
            /*initprintf("%s %d got a match for %s offset %d\n",__FILE__, __LINE__, fname,foffset);*/
        }
        else
        {
            Bstrncpyz(texcache.currentindex->name, fname, BMAX_PATH);
            texcache.currentindex->offset = foffset;
            texcache.currentindex->len = fsize;
            texcache.currentindex->next = (texcacheindex *)Xcalloc(1, sizeof(texcacheindex));
            hash_add(&texcache.hashes, fname, texcache.numentries, 1);
            if (++texcache.numentries > texcache.iptrcnt)
            {
                texcache.iptrcnt += 512;
                texcache.iptrs = (texcacheindex **) Xrealloc(texcache.iptrs, sizeof(intptr_t) * texcache.iptrcnt);
            }
            texcache.iptrs[texcache.numentries-1] = texcache.currentindex;
            texcache.currentindex = texcache.currentindex->next;
        }
    }

    scriptfile_close(script);
    return 0;
}
示例#28
0
static struct line_subseg *
get_line_subseg (segT seg, subsegT subseg)
{
  static segT last_seg;
  static subsegT last_subseg;
  static struct line_subseg *last_line_subseg;

  struct line_seg *s;
  struct line_subseg **pss, *lss;

  if (seg == last_seg && subseg == last_subseg)
    return last_line_subseg;

  s = (struct line_seg *) hash_find (all_segs_hash, seg->name);
  if (s == NULL)
    {
      s = (struct line_seg *) xmalloc (sizeof (*s));
      s->next = NULL;
      s->seg = seg;
      s->head = NULL;
      *last_seg_ptr = s;
      last_seg_ptr = &s->next;
      hash_insert (all_segs_hash, seg->name, s);
    }
  gas_assert (seg == s->seg);

  for (pss = &s->head; (lss = *pss) != NULL ; pss = &lss->next)
    {
      if (lss->subseg == subseg)
	goto found_subseg;
      if (lss->subseg > subseg)
	break;
    }

  lss = (struct line_subseg *) xmalloc (sizeof (*lss));
  lss->next = *pss;
  lss->subseg = subseg;
  lss->head = NULL;
  lss->ptail = &lss->head;
  *pss = lss;

 found_subseg:
  last_seg = seg;
  last_subseg = subseg;
  last_line_subseg = lss;

  return lss;
}
示例#29
0
void *
wrap_hash_find(WRAPPERS_ARGS, hash_t h, const void *key)
{
  void *rv;

  assert(file && function);

  if (!h || !key)
    WRAPPERS_ERR_INVALID_PARAMETERS("hash_find");

  rv = hash_find(h, key);
  if (!rv && errno != 0)
    WRAPPERS_ERR_ERRNO("hash_find");

  return rv;
}
示例#30
0
文件: search.c 项目: bert/pcb-rnd
int layout_search_free(const char *search_ID)
{
	layout_search_t *s;

	if (layout_searches == NULL)
		return 1;

	s = (layout_search_t *)hash_find(layout_searches, search_ID);
	if (s != NULL) {
		hash_del_key(layout_searches, search_ID);
		free(s->objects);
		free(s);
		return 0;
	}
	return 2;
}