Esempio n. 1
0
QIcon* get( NamedSymbol* ns )
{
  Parameter* opts = get_options( ns );
  Locator* l = get_locator( ns );
  int gt = get_grist_type( ns );

  opts = find_by_hash( opts, hashlittle( "cts" ) );
  opts = find_child_by_hash( opts, hashlittle( "icon" ) );
  if( opts && !safe_to_convert( opts, E_VART_STRING ) )
    opts = 0x0;

  QIcon* icon = 0x0;

  if( opts )
  {
    QFileInfo fi( l->m_Buffer );
    QDir parent_dir( fi.absoluteDir() );
    QString qstr = parent_dir.absoluteFilePath( QString( as_string( *opts )->m_Raw ) );
    std::string stdstr( qstr.toStdString() );
    icon = get( stdstr.c_str() );
  }

  if( !icon )
    icon = get( g_NodeSVGResourcePaths[gt] );

  return icon;
}
Esempio n. 2
0
/** Examine the query and return hash and source of netblock. */
static void examine_query(query_type* query, uint32_t* hash, uint64_t* source,
	uint16_t* flags, uint32_t* lm)
{
	/* compile a binary string representing the query */
	uint16_t c, c2;
	/* size with 16 bytes to spare */
	uint8_t buf[MAXDOMAINLEN + sizeof(*source) + sizeof(c) + 16];
	const uint8_t* dname = NULL; size_t dname_len;
	uint32_t r = 0x267fcd16;

	*source = rrl_get_source(query, &c2);
	c = rrl_classify(query, &dname, &dname_len);
	if(query->zone && query->zone->opts && 
		(query->zone->opts->rrl_whitelist & c))
		*lm = rrl_whitelist_ratelimit;
	if(*lm == 0) return;
	c |= c2;
	*flags = c;
	memmove(buf, source, sizeof(*source));
	memmove(buf+sizeof(*source), &c, sizeof(c));

	DEBUG(DEBUG_QUERY, 1, (LOG_INFO, "rrl_examine type %s name %s", rrltype2str(c), dname?wiredname2str(dname):"NULL"));

	/* and hash it */
	if(dname && dname_len <= MAXDOMAINLEN) {
		memmove(buf+sizeof(*source)+sizeof(c), dname, dname_len);
		*hash = hashlittle(buf, sizeof(*source)+sizeof(c)+dname_len, r);
	} else
		*hash = hashlittle(buf, sizeof(*source)+sizeof(c), r);
}
Esempio n. 3
0
unsigned int hash(const cstring& ci, const cstring& cs)
{
    unsigned int h=0;

    h = hashlittle(ci.s,ci.len,h);
    h = hashlittle(cs.s,cs.len,h);

    return h;
}
Esempio n. 4
0
unsigned int hash(const cstring& ci, const cstring& cs)
{
    unsigned int h=0;

    h = hashlittle(ci.s,ci.len,h);
    h = hashlittle(cs.s,cs.len,h);

    return h & (H_TABLE_ENTRIES-1);
}
Esempio n. 5
0
hashvalue_t 
query_info_hash(struct query_info *q)
{
	hashvalue_t h = 0xab;
	h = hashlittle(&q->qtype, sizeof(q->qtype), h);
	h = hashlittle(&q->qclass, sizeof(q->qclass), h);
	h = dname_query_hash(q->qname, h);
	return h;
}
Esempio n. 6
0
hashvalue_t 
query_info_hash(struct query_info *q, uint16_t flags)
{
	hashvalue_t h = 0xab;
	h = hashlittle(&q->qtype, sizeof(q->qtype), h);
	if(q->qtype == LDNS_RR_TYPE_AAAA && (flags&BIT_CD))
		h++;
	h = hashlittle(&q->qclass, sizeof(q->qclass), h);
	h = dname_query_hash(q->qname, h);
	return h;
}
Esempio n. 7
0
/** create a rrset hash from a partial dname hash */
static hashvalue_t
pkt_hash_rrset_rest(hashvalue_t dname_h, uint16_t type, uint16_t dclass, 
	uint32_t rrset_flags)
{
	/* works together with pkt_hash_rrset_first */
	/* note this MUST be identical to rrset_key_hash in packed_rrset.c */
	hashvalue_t h;
	h = hashlittle(&type, sizeof(type), dname_h);	/* host order */
	h = hashlittle(&dclass, sizeof(dclass), h);	/* netw order */
	h = hashlittle(&rrset_flags, sizeof(uint32_t), h);
	return h;
}
Esempio n. 8
0
hashvalue_t
pkt_hash_rrset(sldns_buffer* pkt, uint8_t* dname, uint16_t type, 
	uint16_t dclass, uint32_t rrset_flags)
{
	/* note this MUST be identical to rrset_key_hash in packed_rrset.c */
	/* this routine handles compressed names */
	hashvalue_t h = 0xab;
	h = dname_pkt_hash(pkt, dname, h);
	h = hashlittle(&type, sizeof(type), h);		/* host order */
	h = hashlittle(&dclass, sizeof(dclass), h);	/* netw order */
	h = hashlittle(&rrset_flags, sizeof(uint32_t), h);
	return h;
}
Esempio n. 9
0
hashvalue_t 
rrset_key_hash(struct packed_rrset_key* key)
{
	/* type is hashed in host order */
	uint16_t t = ntohs(key->type);
	/* Note this MUST be identical to pkt_hash_rrset in msgparse.c */
	/* this routine does not have a compressed name */
	hashvalue_t h = 0xab;
	h = dname_query_hash(key->dname, h);
	h = hashlittle(&t, sizeof(t), h);
	h = hashlittle(&key->rrset_class, sizeof(uint16_t), h);
	h = hashlittle(&key->flags, sizeof(uint32_t), h);
	return h;
}
Esempio n. 10
0
bool AmB2BSession::saveSessionDescription(const AmMimeBody& body) {

  const AmMimeBody* sdp_body = body.hasContentType(SIP_APPLICATION_SDP);
  if(!sdp_body)
    return false;

  DBG("saving session description (%s, %.*s...)\n",
      sdp_body->getCTStr().c_str(), 50, sdp_body->getPayload());

  established_body = *sdp_body;

  const char* cmp_body_begin = (const char*)sdp_body->getPayload();
  size_t cmp_body_length = sdp_body->getLen();

#define skip_line						\
    while (cmp_body_length && *cmp_body_begin != '\n') {	\
      cmp_body_begin++;						\
      cmp_body_length--;					\
    }								\
    if (cmp_body_length) {					\
      cmp_body_begin++;						\
      cmp_body_length--;					\
    }

  if (cmp_body_length) {
  // for SDP, skip v and o line
  // (o might change even if SDP unchanged)
  skip_line;
  skip_line;
  }

  body_hash = hashlittle(cmp_body_begin, cmp_body_length, 0);
  return true;
}
Esempio n. 11
0
void cheap_tcam_insert(cheap_tcam_t *tcam,
		       uint8_t *mask,
		       uint8_t *key,
		       cheap_tcam_node *node,
		       void *data) {
  tommy_list *hashmaps = &tcam->hashmaps;
  tcam_hashmap_t *tcam_hashmap;
  uint32_t hash = hashlittle(key, tcam->key_size, 0);
  tommy_node* elem = tommy_list_head(hashmaps);
  
  while(elem) {
    tcam_hashmap = (tcam_hashmap_t *) elem->data;
    if(!memcmp(mask, tcam_hashmap->mask, tcam->key_size)) {
      tommy_hashlin_insert(&tcam_hashmap->hashmap, node, data, hash);
      return;
    }
    elem = elem->next;
  }

  tcam_hashmap = malloc(sizeof(tcam_hashmap_t));
  tommy_hashlin_init(&tcam_hashmap->hashmap);
  tcam_hashmap->mask = malloc(tcam->key_size);
  memcpy(tcam_hashmap->mask, mask, tcam->key_size);
  tommy_list_insert_head(hashmaps, &tcam_hashmap->node, tcam_hashmap);
  tommy_hashlin_insert(&tcam_hashmap->hashmap, node, data, hash);
}
Esempio n. 12
0
bool AmB2BSession::updateSessionDescription(const AmMimeBody& body) {

  const AmMimeBody* sdp_body = body.hasContentType(SIP_APPLICATION_SDP);
  if(!sdp_body)
    return false;

  const char* cmp_body_begin = (const char*)sdp_body->getPayload();
  size_t cmp_body_length = sdp_body->getLen();
  if (cmp_body_length) {
    // for SDP, skip v and o line
    // (o might change even if SDP unchanged)
    skip_line;
    skip_line;
  }

#undef skip_line

  uint32_t new_body_hash = hashlittle(cmp_body_begin, cmp_body_length, 0);

  if (body_hash != new_body_hash) {
    DBG("session description changed - saving (%s, %.*s...)\n",
	sdp_body->getCTStr().c_str(), 50, sdp_body->getPayload());
    body_hash = new_body_hash;
    established_body = body;
    return true;
  }

  return false;
}
Esempio n. 13
0
 inline uint32_t lookup3(const Container &container, const uint32_t &init)
 {
     return hashlittle(
         &*std::begin(container),
         sizeof(typename Container::value_type) * (std::end(container) - std::begin(container)),
         init);
 }
Esempio n. 14
0
void Atom_registerStaticAddress(const char * staticAtom) {
	unsigned int bucketIndex, entryIndex;
	uint32_t hash;
	
	hash = hashlittle(staticAtom, strlen(staticAtom), 0);
	bucketIndex = hash % ATOM_HASH_TABLE_SIZE;
	
	for (entryIndex = 0; entryIndex < atomBuckets[bucketIndex].count; entryIndex++) {
		if (atomBuckets[bucketIndex].entries[entryIndex].hash == hash && !strcmp(atomBuckets[bucketIndex].entries[entryIndex].atom, staticAtom)) {
			fprintf(stderr, "ERROR: Atom_registerStaticAddress called with string \"%s\" at address %p, which is already registered at address %p\n", staticAtom, staticAtom, atomBuckets[bucketIndex].entries[entryIndex].atom);
			abort();
		}
	}
	
	if (atomBuckets[bucketIndex].count >= atomBuckets[bucketIndex].allocatedSize) {
		if (atomBuckets[bucketIndex].allocatedSize == 0) {
			atomBuckets[bucketIndex].allocatedSize = 1;
		} else {
			atomBuckets[bucketIndex].allocatedSize *= 2;
		}
		atomBuckets[bucketIndex].entries = realloc(atomBuckets[bucketIndex].entries, sizeof(struct AtomEntry) * atomBuckets[bucketIndex].allocatedSize);
	}
	
	atomBuckets[bucketIndex].entries[atomBuckets[bucketIndex].count].atom = staticAtom;
	atomBuckets[bucketIndex].entries[atomBuckets[bucketIndex].count].hash = hash;
	atomBuckets[bucketIndex].count++;
}
Esempio n. 15
0
/* 0: inserted
   1: not enough space in cache
*/
int tcam_cache_insert(tcam_cache_t *cache, uint8_t *key, void *data) {
  pthread_mutex_lock(&cache->lock);
  if(cache->nb_entries == cache->size) {
    pthread_mutex_unlock(&cache->lock);
    return 1;
  }
  int i;
  cache_entry_t *entry = NULL;
  int trailing_ones;
  for(i = 0; i < cache->bitmap_size; i++) {
    trailing_ones = __builtin_ctzl(~cache->bitmap_used[i]);
    if(trailing_ones != sizeof(unsigned long)) {
      entry = &cache->entries[sizeof(unsigned long) * i + trailing_ones];
      cache->bitmap_used[i] |= (1 << trailing_ones); 
      break;
    }
  }
  
  entry->last_access = time(NULL);
  entry->key = key;
  entry->key_size = cache->key_size;
  entry->data = data;
  uint32_t hash = hashlittle(key, cache->key_size, 0);
  tommy_hashtable_insert(&cache->hashtable, &entry->node, entry, hash);
  cache->nb_entries++;
  pthread_mutex_unlock(&cache->lock);
  return 0;
}
Esempio n. 16
0
 inline uint32_t lookup3(InputIt first, InputIt last, const uint32_t &init)
 {
     return hashlittle(
         &*first,
         sizeof(typename std::iterator_traits<InputIt>::value_type) * (last - first),
         init);
 }
Esempio n. 17
0
hashvalue_t
dname_pkt_hash(sldns_buffer* pkt, uint8_t* dname, hashvalue_t h)
{
    uint8_t labuf[LDNS_MAX_LABELLEN+1];
    uint8_t lablen;
    int i;

    /* preserve case of query, make hash label by label */
    lablen = *dname++;
    while(lablen) {
        if(LABEL_IS_PTR(lablen)) {
            /* follow pointer */
            dname = sldns_buffer_at(pkt, PTR_OFFSET(lablen, *dname));
            lablen = *dname++;
            continue;
        }
        log_assert(lablen <= LDNS_MAX_LABELLEN);
        labuf[0] = lablen;
        i=0;
        while(lablen--)
            labuf[++i] = (uint8_t)tolower((int)*dname++);
        h = hashlittle(labuf, labuf[0] + 1, h);
        lablen = *dname++;
    }

    return h;
}
Esempio n. 18
0
void _tr_blacklist::remove(const sockaddr_storage* addr)
{
  blacklist_bucket* bucket = get_bucket(hashlittle(addr, SA_len(addr), 0)
					& BLACKLIST_HT_MASK);
  bucket->lock();
  bucket->remove(*(const bl_addr*)addr);
  bucket->unlock();
}
Esempio n. 19
0
int print_header( FILE* f, const char* file_name, BehaviorTreeContext ctx )
{
  Parameter* opts = get_options( ctx );

  unsigned int header_hash = hashlittle( "ctc_h_header" );
  unsigned int footer_hash = hashlittle( "ctc_h_footer" );
  unsigned int symbol_hash = hashlittle( "ctc_h_symbol_prefix" );
  unsigned int id_hash     = hashlittle( "id" );

  const char* header = get_string_from_parameter_list( opts, header_hash );
  const char* footer = get_string_from_parameter_list( opts, footer_hash );
  const char* symbol = get_string_from_parameter_list( opts, symbol_hash );
  fprintf( f, "/*\n * This file is auto generated by ctc from %s.\n * Manual edits will be lost when regenerated.\n */\n\n", file_name );


  if( header )
    fprintf( f, "%s\n\n", header );

  int count;
  NamedSymbol* ns = access_symbols( ctx, &count );
  for( int i = 0; i < count; ++i )
  {
    if( ns[i].m_Type == E_ST_ACTION )
    {
      Parameter* p = find_by_hash( ns[i].m_Symbol.m_Action->m_Options, id_hash );
      if( p && safe_to_convert( p, E_VART_INTEGER ) )
        print_header_entry( f, symbol, ns[i].m_Symbol.m_Action->m_Id.m_Text, as_integer( *p ) );
      else
        print_header_entry( f, symbol, ns[i].m_Symbol.m_Action->m_Id.m_Text, ns[i].m_Symbol.m_Action->m_Id.m_Hash );
    }
    else if( ns[i].m_Type == E_ST_DECORATOR )
    {
      Parameter* p = find_by_hash( ns[i].m_Symbol.m_Decorator->m_Options, id_hash );
      if( p && safe_to_convert( p, E_VART_INTEGER ) )
        print_header_entry( f, symbol, ns[i].m_Symbol.m_Decorator->m_Id.m_Text, as_integer( *p ) );
      else
        print_header_entry( f, symbol, ns[i].m_Symbol.m_Decorator->m_Id.m_Text, ns[i].m_Symbol.m_Action->m_Id.m_Hash );
    }
  }

  if( footer )
    fprintf( f, "\n%s\n", footer );

  return 0;
}
Esempio n. 20
0
static int _get_entry_index(int type, void *entry, unsigned int size)
{
    struct entry_hash_node  *h;
    tommy_hash_t hash=hashlittle(entry, size, type);
     h = tommy_hashdyn_search(&entry_hash, entry_hash_cmp, entry, hash);
    if(h)
        return h->entry_handle;
	return -1;
}
Esempio n. 21
0
uint32_t h_index(htable_t *ht, void *key, int key_len)
{
  uint32_t idx;
  assert(ht != NULL);
  idx = hashmask(ht->index_bits) & hashlittle(key, key_len, HASH_INIT_VAL);
  //printf("h_index: (%llx): %p (key: '%s', key_len=%d)\n", (long long)ht, idx, (char *)key, key_len);
  //debug(0,0, "h_index: (%llx): %p (key: '%s', key_len=%d)\n", (long long)ht, idx, (char *)key, key_len);
  //debug_dump(0,0, key, key_len);
  return idx;
}
Esempio n. 22
0
int _del_entry_index(int type, void *entry, unsigned int size)
{
    tommy_hash_t hash=hashlittle(entry, size, type);
    void *p = tommy_hashdyn_remove (&entry_hash, entry_hash_cmp, entry, hash);
    if(p) {
        free(p);
        return 0;
    }
    return -1;
}
Esempio n. 23
0
bool _tr_blacklist::exist(const sockaddr_storage* addr)
{
  bool res;
  blacklist_bucket* bucket = get_bucket(hashlittle(addr, SA_len(addr), 0)
					& BLACKLIST_HT_MASK);
  bucket->lock();
  res = bucket->exist(*(const bl_addr*)addr);
  bucket->unlock();

  return res;
}
Esempio n. 24
0
bool is_btree_keyword( const char* str )
{
  hash_t t = hashlittle( str );
  int s = sizeof( g_keyword_hash_values ) / sizeof( hash_t );
  for( int i = 0; i < s; ++i )
  {
    if( g_keyword_hash_values[i] == t )
      return true;
  }
  return false;
}
Esempio n. 25
0
uint32_t lookup(uint8_t *k,  uint32_t length,  uint32_t initval)
{
#ifdef HAVE_SFHASH
  return SuperFastHash((const char*)k, length, initval);
#elif HAVE_LOOKUP3
#if LITTLE_ENDIAN
  return hashlittle(k, length, initval);
#elif BIG_ENDIAN
  return hashbig(k, length, initval);
#endif
#endif
}
Esempio n. 26
0
        inline uint32_t lookup3(std::ifstream &stream, uint32_t length, const uint32_t &init)
        {
            auto hash = init;
            std::vector<char> buffer(length);

            auto pos = stream.tellg();

            stream.read(buffer.data(), length);
            hash = hashlittle(buffer.data(), length, hash);

            stream.seekg(pos);

            return hash;
        }
Esempio n. 27
0
void _tr_blacklist::insert(const sockaddr_storage* addr, unsigned int duration,
			   const char* reason)
{
  if(!duration)
    return;

  blacklist_bucket* bucket = get_bucket(hashlittle(addr, SA_len(addr), 0)
					& BLACKLIST_HT_MASK);
  bucket->lock();
  if(!bucket->exist(*(const bl_addr*)addr)) {
    bucket->insert(*(const bl_addr*)addr,duration,reason);
  }
  bucket->unlock();
}
Esempio n. 28
0
Atom Atom_fromString(const char * string) {
	unsigned int bucketIndex, entryIndex;
	char * newAtom;
	size_t length;
	uint32_t hash;
	
	if (string == NULL) {
		return NULL;
	}
	
	length = strlen(string);
	hash = hashlittle(string, length, 0);
	bucketIndex = hash % ATOM_HASH_TABLE_SIZE;
	
	if (mutex != NULL) {
		lockMutex(mutex);
	}
	
	for (entryIndex = 0; entryIndex < atomBuckets[bucketIndex].count; entryIndex++) {
		if (atomBuckets[bucketIndex].entries[entryIndex].hash == hash && !strcmp(atomBuckets[bucketIndex].entries[entryIndex].atom, string)) {
			if (mutex != NULL) {
				unlockMutex(mutex);
			}
			return atomBuckets[bucketIndex].entries[entryIndex].atom;
		}
	}
	
	if (atomBuckets[bucketIndex].count >= atomBuckets[bucketIndex].allocatedSize) {
		if (atomBuckets[bucketIndex].allocatedSize == 0) {
			atomBuckets[bucketIndex].allocatedSize = 1;
		} else {
			atomBuckets[bucketIndex].allocatedSize *= 2;
		}
		atomBuckets[bucketIndex].entries = realloc(atomBuckets[bucketIndex].entries, sizeof(struct AtomEntry) * atomBuckets[bucketIndex].allocatedSize);
	}
	
	newAtom = strdup(string);
	atomBuckets[bucketIndex].entries[atomBuckets[bucketIndex].count].atom = newAtom;
	atomBuckets[bucketIndex].entries[atomBuckets[bucketIndex].count].hash = hash;
	atomBuckets[bucketIndex].count++;
	
	if (mutex != NULL) {
		unlockMutex(mutex);
	}
	return newAtom;
}
Esempio n. 29
0
void ZLFastDict::add(const void* pIndex, size_t len, void* pData)
{
	uint32_t uIndex = hashlittle(pIndex, len, 0x23);
	uIndex = (uIndex & hashmask(this->uHashBits));

	/* collision test 
	uIndex = 100; */

	if (this->pBuckets[uIndex] == NULL)
	{
		this->pBuckets[uIndex] = (_Bucket_t*)this->pDictHeap->alloc(sizeof(_Bucket_t));
		this->pBuckets[uIndex]->pIndex  = pIndex;
		this->pBuckets[uIndex]->sLength = len;
		this->pBuckets[uIndex]->pData   = pData;
		this->pBuckets[uIndex]->pNext   = NULL;
	}
	else
	{
		_Bucket_t* pBucket = this->pBuckets[uIndex];
		while (pBucket != NULL)
		{
			if (eq(pBucket->pIndex, pBucket->sLength, pIndex, len))
			{
				pBucket->pData = pData;
				break;
			}
			else
			{
				if (pBucket->pNext == NULL)
				{
					/* create new bucket */
					_Bucket_t* pNewBucket = (_Bucket_t*)this->pDictHeap->alloc(sizeof(_Bucket_t));
					pNewBucket->pIndex  = pIndex;
					pNewBucket->sLength = len;
					pNewBucket->pData   = pData;
					pNewBucket->pNext   = NULL;
					pBucket->pNext = pNewBucket;
					pBucket = pNewBucket;
				}
				pBucket = pBucket->pNext;
			}
		}
	}
}
Esempio n. 30
0
atom_t
stringtable_lookup(unsigned char *cs, int len)
{
//        static FILE *file = NULL;
//        if(!file)
//                file = fopen("atom.lookup","w");
//        fprintf(file,"stringtable_lookup(");
//        print_quoted(file,cs,len);
//        fprintf(file,")\n");
        pthread_mutex_lock(&mutex_hash);
        assert(len >= 0);
        assert(len < MAX_ENTRY_SIZE);
        hash_t h[CUCKOO_HASHES];
        for(uint32_t i = 0; i < CUCKOO_HASHES; i++) {
                h[i] = hashlittle(cs,len,i);
                //int e = HASH_INDEX(i,h[i]);
                for(int j = 0; j < CUCKOO_BUCKETS; j++) {
                        //struct hentry *b = &htable[(e + i) & HASHJMASK ];
                        //struct hentry *b = &htable[HASH_BUCKET(e,j)];
                        struct hentry *b = &htable[HASH_INDEX(i,h[i] + j)];
#if KEEP_HASH
                        if (ATOM_VALID(b->atom) && h[i] == b->hashes[i] && len == ATOM_LEN(b->atom) &&  !memcmp(ATOM_PTR(b->atom),cs,len)) {
                            pthread_mutex_unlock(&mutex_hash);
                            return b->atom;
                        }
#else
                        if (ATOM_VALID(b->atom) && len == ATOM_LEN(b->atom) && !memcmp(ATOM_PTR(b->atom),cs,len)) {
                            pthread_mutex_unlock(&mutex_hash);
                            return b->atom;
                        }
#endif
                }
        }
        atom_t na = add_string(cs,len);
        struct hentry hb;
        hb.atom = na;
#if KEEP_HASH
        memcpy(hb.hashes,h,sizeof hb.hashes);
#endif
        hash_insert(hb);
        pthread_mutex_unlock(&mutex_hash);
        return na;
}