Ejemplo n.º 1
0
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 ;
}
Ejemplo n.º 2
0
void hash() {
    printf(">> HASH\n");
    hashtable_t hash;

    test_hash_t a = { "Hello" };
    test_hash_t b = { "Intrusive" };
    test_hash_t c = { "World" };

    hashtable_init(&hash, 10, &hash_func);

    hashtable_insert(&hash, &a.node, "a", 2);
    hashtable_insert(&hash, &b.node, "b", 2);
    hashtable_insert(&hash, &c.node, "c", 2);

    hashnode_t *ga = hashtable_search(&hash, "a", 2);
    hashnode_t *gb = hashtable_search(&hash, "b", 2);
    hashnode_t *gc = hashtable_search(&hash, "c", 2);

    test_hash_t *aa = hashtable_ref(ga, test_hash_t, node);
    test_hash_t *bb = hashtable_ref(gb, test_hash_t, node);
    test_hash_t *cc = hashtable_ref(gc, test_hash_t, node);

    printf("%s\n", aa->message);
    printf("%s\n", bb->message);
    printf("%s\n", cc->message);
}
Ejemplo n.º 3
0
static void add_to_set(struct hashtable* h, key* k, val* v) {
	int rv;
	key* new_key;
	flat_key_val* new_value;
	
	new_value = hashtable_search(h, k);
	if (new_value == NULL) {
		new_key = key_new(k->data, k->size);
		new_value = malloc(sizeof(flat_key_val) + k->size + v->size);
		assert(new_value != NULL);
		rv = hashtable_insert(h, new_key, new_value);
		assert(rv != 0);
	} else {
		if ((k->size + v->size) != (new_value->ksize + new_value->vsize)) {
			new_key = key_new(k->data, k->size);
			new_value = hashtable_remove(h, k);
			free(new_value);
			new_value = malloc(sizeof(flat_key_val) + k->size + v->size);
			assert(new_value != NULL);
			rv = hashtable_insert(h, new_key, new_value);
			assert(rv != 0);
		}
	}
	
	new_value->ksize = k->size;
	new_value->vsize = v->size;
	memcpy(new_value->data, k->data, k->size);
	memcpy(&new_value->data[k->size], v->data, v->size);
}
Ejemplo n.º 4
0
static int
verify_object(struct conf *conf, struct manifest *mf, struct object *obj,
              struct hashtable *stated_files, struct hashtable *hashed_files)
{
	for (uint32_t i = 0; i < obj->n_file_info_indexes; i++) {
		struct file_info *fi = &mf->file_infos[obj->file_info_indexes[i]];
		char *path = mf->files[fi->index];
		struct file_stats *st = hashtable_search(stated_files, path);
		if (!st) {
			struct stat file_stat;
			if (x_stat(path, &file_stat) != 0) {
				return 0;
			}
			st = x_malloc(sizeof(*st));
			st->size = file_stat.st_size;
			st->mtime = file_stat.st_mtime;
			st->ctime = file_stat.st_ctime;
			hashtable_insert(stated_files, x_strdup(path), st);
		}

		if (fi->size != st->size) {
			return 0;
		}

		if (conf->sloppiness & SLOPPY_FILE_STAT_MATCHES) {
			if (fi->mtime == st->mtime && fi->ctime == st->ctime) {
				cc_log("mtime/ctime hit for %s", path);
				continue;
			} else {
				cc_log("mtime/ctime miss for %s", path);
			}
		}

		struct file_hash *actual = hashtable_search(hashed_files, path);
		if (!actual) {
			struct mdfour hash;
			hash_start(&hash);
			int result = hash_source_code_file(conf, &hash, path);
			if (result & HASH_SOURCE_CODE_ERROR) {
				cc_log("Failed hashing %s", path);
				return 0;
			}
			if (result & HASH_SOURCE_CODE_FOUND_TIME) {
				return 0;
			}
			actual = x_malloc(sizeof(*actual));
			hash_result_as_bytes(&hash, actual->hash);
			actual->size = hash.totalN;
			hashtable_insert(hashed_files, x_strdup(path), actual);
		}
		if (memcmp(fi->hash, actual->hash, mf->hash_size) != 0
		    || fi->size != actual->size) {
			return 0;
		}
	}

	return 1;
}
Ejemplo n.º 5
0
static int
blockstore_set_chain_links(struct blockstore *bs,
                           struct blockentry *be)
{
   struct blockentry *prev;
   char hashStr[80];
   uint256 hash;
   bool s;

   hash256_calc(&be->header, sizeof be->header, &hash);
   uint256_snprintf_reverse(hashStr, sizeof hashStr, &hash);

   if (be->height >= 0) {
      struct blockentry *li;
      /*
       * We've reached the junction with the current/old best chain. All the
       * entries from now on need to be made orphans.
       */

      Log(LGPFX" Reached block %s\n", hashStr);

      li = be->next;
      while (li) {
         hash256_calc(&li->header, sizeof li->header, &hash);
         uint256_snprintf_reverse(hashStr, sizeof hashStr, &hash);
         Log(LGPFX" moving #%d %s from blk -> orphan\n", li->height, hashStr);
         s = hashtable_remove(bs->hash_blk, &hash, sizeof hash);
         ASSERT(s);
         li->height = -1;
         s = hashtable_insert(bs->hash_orphans, &hash, sizeof hash, li);
         ASSERT(s);
         li = li->next;
      }

      return be->height;
   }

   ASSERT(be->height == -1); // orphan

   prev = blockstore_lookup(bs, &be->header.prevBlock);
   ASSERT(prev);

   be->height = 1 + blockstore_set_chain_links(bs, prev);

   Log(LGPFX" moving #%d %s from orphan -> blk\n", be->height, hashStr);

   prev->next = be;
   be->prev = prev;

   s = hashtable_remove(bs->hash_orphans, &hash, sizeof hash);
   ASSERT(s);
   s = hashtable_insert(bs->hash_blk, &hash, sizeof hash, be);
   ASSERT(s);

   return be->height;
}
Ejemplo n.º 6
0
static void
blockstore_add_entry(struct blockstore *bs,
                     struct blockentry *be,
                     const uint256 *hash)
{
   bool s;

   if (bs->best_chain == NULL) {

      s = hashtable_insert(bs->hash_blk, hash, sizeof *hash, be);

      ASSERT(s);
      ASSERT(uint256_issame(hash, &bs->genesis_hash));
      ASSERT(be->prev == NULL);
      ASSERT(bs->height);

      bs->best_chain = be;
      bs->genesis = be;
      bs->height  = 0;
      be->height  = 0;

      memcpy(&bs->best_hash, hash, sizeof *hash);
   } else if (uint256_issame(&be->header.prevBlock, &bs->best_hash)) {

      s = hashtable_insert(bs->hash_blk, hash, sizeof *hash, be);
      ASSERT(s);

      bs->height++;
      be->height = bs->height;

      bs->best_chain->next = be;
      be->prev = bs->best_chain;
      bs->best_chain = be;

      memcpy(&bs->best_hash, hash, sizeof *hash);
   } else {
      char hashStr[80];
      uint32 count;

      be->height = -1;
      count = hashtable_getnumentries(bs->hash_orphans);

      uint256_snprintf_reverse(hashStr, sizeof hashStr, hash);
      Log(LGPFX" block %s orphaned. %u orphan%s total.\n",
          hashStr, count, count > 1 ? "s" : "");

      s = hashtable_insert(bs->hash_orphans, hash, sizeof *hash, be);
      ASSERT(s);

      blockstore_set_best_chain(bs, be, hash);
   }
}
Ejemplo n.º 7
0
void
pc_schema_set_dimension(PCSCHEMA *s, PCDIMENSION *d)
{
	s->dims[d->position] = d;
	hashtable_insert(s->namehash, d->name, d);
	pc_schema_calculate_byteoffsets(s);
}
Ejemplo n.º 8
0
static void open_exsited_queue_db(DB_TXN *txnp, char *queue_name, qstats_t *qsp){
    int ret;
    
    char *k = strdup(queue_name);
    assert(k != NULL);
    queue_t *q = (queue_t *)calloc(1, sizeof(queue_t));
    assert(q != NULL);

    /* init hash_key and hash_value */
    q->dbp = NULL;
    q->set_hits = q->old_set_hits = qsp->set_hits;
    q->get_hits = q->old_get_hits = qsp->get_hits;
    pthread_mutex_init(&(q->lock), NULL);
    
    ret = db_create(&(q->dbp), envp, 0);
    CHECK_DB_RET(ret);    
    ret = q->dbp->open(q->dbp, txnp, queue_name, NULL, DB_QUEUE, DB_CREATE, 0664);         
    CHECK_DB_RET(ret);
    
    int result = hashtable_insert(qlist_htp, (void *)k, (void *)q);
    assert(result != 0);
    return;
    
dberr:
    fprintf(stderr, "open_exsited_queue_db: %s\n", db_strerror(ret));
    exit(EXIT_FAILURE);
}
Ejemplo n.º 9
0
struct reformat *reopen_cache(int lotNr, size_t structsize, char file[], char subname[], int flags) {
	char lotfile[PATH_MAX];
	struct reformat *re;

	sprintf(lotfile, "%s\x10%s\x10%d", subname, file, lotNr);
	if (lots_cache == NULL) {
		lots_cache = create_hashtable(3, ht_stringhash, ht_stringcmp);
		if (lots_cache == NULL)
			err(1, "hashtable_create(reopen_cache)");
	} else {
		re = hashtable_search(lots_cache, lotfile);
		#ifdef DEBUG
		printf("has cahce for %s:%s lot %d. pointer %p\n", subname, file, lotNr, re);
		#endif
		if (re != NULL)
			return re;
	}
	#ifdef DEBUG
	printf("reopen_cache: Cache miss for %s:%s lot %d\n", subname, file, lotNr);
	#endif

	re = reopen(lotNr, structsize, file, subname, flags);
	//Runarb 11 feb 2009:
	//vi må nesten cache at filen ikke fantes, for bakoverkompetabilitet. Når vi siden gjør om dette på preopning til å ikke
	//reåpne etter hver crawl, må vi gjøre om
	if (re == NULL) {
		return NULL;
	}
	hashtable_insert(lots_cache, strdup(lotfile), re);


	return re;
}
Ejemplo n.º 10
0
/* 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;
}
Ejemplo n.º 11
0
addEntry(struct sockaddr_storage *const addr, dnscache_entry_t **const pEtry)
{
	int r;
	dnscache_entry_t *etry = NULL;
	DEFiRet;

	/* entry still does not exist, so add it */
	struct sockaddr_storage *const keybuf =  malloc(sizeof(struct sockaddr_storage));
	CHKmalloc(keybuf);
	CHKmalloc(etry = malloc(sizeof(dnscache_entry_t)));
	resolveAddr(addr, etry);
	assert(etry != NULL);
	memcpy(&etry->addr, addr, SALEN((struct sockaddr*) addr));
	etry->nUsed = 0;
	if(dnscacheEnableTTL) {
		etry->validUntil = time(NULL) + dnscacheDefaultTTL;
	}

	memcpy(keybuf, addr, sizeof(struct sockaddr_storage));

	r = hashtable_insert(dnsCache.ht, keybuf, etry);
	if(r == 0) {
		DBGPRINTF("dnscache: inserting element failed\n");
	}
	*pEtry = etry;

finalize_it:
	if(iRet != RS_RET_OK) {
		free(keybuf);
	}
	RETiRet;
}
Ejemplo n.º 12
0
static void update_patch_function_lookup_for_module(NativePatch* module)
{
    World* world = module->world;
    caValue* everyPatchedFunction = &world->nativePatchWorld->everyPatchedFunction;

    caValue* targetName = &module->targetName;

    // Look at every function that this module patches.
    std::map<std::string, EvaluateFunc>::const_iterator it;

    for (it = module->patches.begin(); it != module->patches.end(); it++) {

        Value functionName;
        set_string(&functionName, it->first.c_str());

        // Construct a global name for this function, using the block's global name.

        Value globalName;
        copy(targetName, &globalName);
        string_append_qualified_name(&globalName, &functionName);

        // Save this line.
        caValue* entry = hashtable_insert(everyPatchedFunction, &globalName);
        set_list(entry, 2);
        copy(&module->targetName, list_get(entry, 0));
        copy(&functionName, list_get(entry, 1));
    }
}
Ejemplo n.º 13
0
Archivo: txdb.c Proyecto: haraldh/bitc
static int
txdb_add_to_hashtable(struct txdb      *txdb,
                      const void       *buf,
                      size_t            len,
                      const uint256    *txHash,
                      const uint256    *blkHash,
                      uint64            timestamp,
                      struct tx_entry **txePtr)
{
    struct tx_entry *txe;
    struct buff b;
    int res;
    bool s;

    buff_init(&b, (char *)buf, len);

    txe = safe_malloc(sizeof *txe);
    if (blkHash) {
        memcpy(&txe->blkHash, blkHash, sizeof *blkHash);
    } else {
        memset(&txe->blkHash, 0, sizeof txe->blkHash);
    }
    txe->relevant = 0; /* for now */
    txe->timestamp = timestamp; // only really useful for 'relevant' ones.

    res = deserialize_tx(&b, &txe->tx);
    ASSERT(res == 0);

    s = hashtable_insert(txdb->hash_tx, txHash, sizeof *txHash, txe);
    ASSERT(s);

    *txePtr = txe;

    return 0;
}
Ejemplo n.º 14
0
void migrate_value(Value* value, Migration* migration)
{
    if (is_ref(value)) {
        set_term_ref(value, migrate_term_pointer(as_term_ref(value), migration));
        
    } else if (is_block(value)) {
        set_block(value, migrate_block_pointer(as_block(value), migration));
    } else if (is_list_based(value)) {
        migrate_list_value(value, migration);

    } else if (is_hashtable(value)) {
        Value oldHashtable;
        move(value, &oldHashtable);

        set_hashtable(value);
        Value* hashtable = value;

        for (int i=0; i < hashtable_slot_count(&oldHashtable); i++) {
            Value* oldKey = hashtable_key_by_index(&oldHashtable, i);
            if (oldKey == NULL || is_null(oldKey))
                continue;

            Value* oldValue = hashtable_value_by_index(&oldHashtable, i);

            Value key;
            copy(oldKey, &key);
            migrate_value(&key, migration);
            Value* newValue = hashtable_insert(hashtable, &key);
            copy(oldValue, newValue);
            migrate_value(newValue, migration);
        }
    }
}
Ejemplo n.º 15
0
static inline rsRetVal
addEntry(struct sockaddr_storage *addr, dnscache_entry_t **pEtry)
{
    int r;
    struct sockaddr_storage *keybuf;
    dnscache_entry_t *etry = NULL;
    DEFiRet;

    CHKmalloc(etry = MALLOC(sizeof(dnscache_entry_t)));
    CHKiRet(resolveAddr(addr, etry));
    memcpy(&etry->addr, addr, SALEN((struct sockaddr*) addr));
    etry->nUsed = 0;
    *pEtry = etry;

    CHKmalloc(keybuf = malloc(sizeof(struct sockaddr_storage)));
    memcpy(keybuf, addr, sizeof(struct sockaddr_storage));

    pthread_rwlock_unlock(&dnsCache.rwlock); /* release read lock */
    pthread_rwlock_wrlock(&dnsCache.rwlock); /* and re-aquire for writing */
    r = hashtable_insert(dnsCache.ht, keybuf, *pEtry);
    if(r == 0) {
        DBGPRINTF("dnscache: inserting element failed\n");
    }
    pthread_rwlock_unlock(&dnsCache.rwlock);
    pthread_rwlock_rdlock(&dnsCache.rwlock); /* we need this again */

finalize_it:
    if(iRet != RS_RET_OK && etry != NULL) {
        /* Note: sub-fields cannot be populated in this case */
        free(etry);
    }
    RETiRet;
}
Ejemplo n.º 16
0
static int pagetable_post(pagetable *pages, int posttype, char *path, postitem *pi)
{
  /*   wserror(ws, MESSAGE, "Adding a path to server: %s\n", path); */
  webpage_table_item toinsert = {0};
  toinsert.postitem_type = posttype;
  toinsert.key = path;
  toinsert.value = *pi;
  toinsert.mime = NULL;

  /* if it is a file, then i should auto-determine the mime here, if it is a buffer,
     then it will be assumed that it is text/plain */
  /*   if(posttype == POSTITEM_BUFFER) { */
  /*     toinsert.mime = mime_lookup("txt"); */
  /*   } else if(posttype == POSTITEM_FILE) { */
  /*     toinsert.mime = mime_auto(pi->file_path); */
  /* /\*     printf("determined that the mime for %s was %s\n", pi->file_path, toinsert.mime); *\/ */
  /*   } */
  toinsert.mime = "text/plain";

  if(pagetable_find(pages, path) != NULL) {
    /*     wserror(ws, MESSAGE, "webshare: collission detected on %s, already present in share?\n", path); */
    return -1;
  }
  
  return hashtable_insert((hashtable*)pages, &toinsert) == NULL ? -1 : 0;
}
Ejemplo n.º 17
0
void dllhashtable_insert(struct DLLHASHTABLE* dllhashtable_ptr,
	void* key, void* value)
{
	struct DLL* dll_ptr;
	struct HASHTABLE* hashtable_ptr;
	struct DLLHASHTABLE_DLLITEM* dllitem_ptr;
	struct DLLHASHTABLE_HASHTABLEVALUE* hashtablevalue_ptr;
	struct HASHITEM* hashitem_ptr;

	dll_ptr = dllhashtable_ptr->dll_ptr;
	hashtable_ptr = dllhashtable_ptr->hashtable_ptr;

	hashtablevalue_ptr = (struct DLLHASHTABLE_HASHTABLEVALUE*)
		malloc(sizeof(struct DLLHASHTABLE_HASHTABLEVALUE));
	hashtablevalue_ptr->value = value;
	hashtablevalue_ptr->dllitem_ptr = NULL;	
	hashtablevalue_ptr->delvaluefunc = 
		dllhashtable_ptr->hashtable_delvaluefunc;
	
	hashitem_ptr = hashtable_insert(hashtable_ptr, key, 
		hashtablevalue_ptr);
	// printf("hashitem_ptr = %p\n", hashitem_ptr);
	// printf("hashtablevalue_ptr = %p\n", hashtablevalue_ptr);
	
	dllitem_ptr = (struct DLLHASHTABLE_DLLITEM*)
		dll_insert(dll_ptr, hashitem_ptr);
	// printf("dllitem_ptr = %p\n", dllitem_ptr);

	hashtablevalue_ptr->dllitem_ptr = dllitem_ptr;
}
Ejemplo n.º 18
0
hashtable_rc_t hashtable_resize(hash_table_t * const hashtblP, const hash_size_t sizeP)
{
    hash_table_t       newtbl;
    hash_size_t        n;
    hash_node_t       *node,*next;

    if (hashtblP == NULL) {
        return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
    }

    newtbl.size     = sizeP;
    newtbl.hashfunc = hashtblP->hashfunc;

    if(!(newtbl.nodes=calloc(sizeP, sizeof(hash_node_t*)))) return -1;

    for(n=0; n<hashtblP->size; ++n) {
        for(node=hashtblP->nodes[n]; node; node=next) {
            next = node->next;
            hashtable_insert(&newtbl, node->key, node->data);
            // Lionel GAUTHIER: BAD CODE TO BE REWRITTEN
            hashtable_remove(hashtblP, node->key);

        }
    }

    free(hashtblP->nodes);
    hashtblP->size=newtbl.size;
    hashtblP->nodes=newtbl.nodes;

    return HASH_TABLE_OK;
}
Ejemplo n.º 19
0
sp_image *osfy_image_create(sp_session *session, const byte image_id[20]) {
    sp_image *image;

    image = (sp_image *)hashtable_find(session->hashtable_images, image_id);
    if(image) {
        {
            char buf[41];
            hex_bytes_to_ascii(image->id, buf, 20);
            DSFYDEBUG("Returning existing image '%s'\n", buf);
        }

        return image;
    }

    image = malloc(sizeof(sp_image));

    memcpy(image->id, image_id, sizeof(image->id));
    image->format = SP_IMAGE_FORMAT_UNKNOWN;
    image->data = NULL;

    image->error = SP_ERROR_RESOURCE_NOT_LOADED;

    image->callback = NULL;
    image->userdata = NULL;

    image->is_loaded = 0;
    image->ref_count = 0;

    image->hashtable = session->hashtable_images;
    hashtable_insert(image->hashtable, image->id, image);

    return image;
}
Ejemplo n.º 20
0
static int
annotate_hash_table(BoxNode *n,HashTable *h,uint32_t *box)
{
   PixelList *p;
   PixelHashData *d=(PixelHashData *)hashtable_get_user_data(h);
   Pixel q;
   if (n->l&&n->r) {
      return annotate_hash_table(n->l,h,box) && annotate_hash_table(n->r,h,box);
   }
   if (n->l||n->r) {
#ifndef NO_OUTPUT
      printf ("box tree is dead\n");
#endif
      return 0;
   }
   for (p=n->head[0];p;p=p->next[0]) {
      PIXEL_UNSCALE(&(p->p),&q,d->scale);
      if (!hashtable_insert(h,q,*box)) {
#ifndef NO_OUTPUT
         printf ("hashtable insert failed\n");
#endif
         return 0;
      }
   }
   if (n->head[0]) (*box)++;
   return 1;
}
Ejemplo n.º 21
0
void parse_libextractor_output(struct hashtable *dst, const char *output, char **whitelist) {
	char **lines;
	int n_lines = split(output, "\n", &lines);
	char key[MAX_ATTRIB_LEN];
	char val[MAX_ATTRIB_LEN];

	printf("parse_libextractor_output: n_lines %i\n",n_lines);
	
	int i, j;
	for (i = 0; i < n_lines; i++) {
		char *line = lines[i];
		char *remain = strchr(line, '-');
		const char *ret;
		if (remain == NULL)
			continue;
		int keylen = remain - line;
		remain += 2; // skip '- '
		
		keylen = keylen > MAX_ATTRIB_LEN ? MAX_ATTRIB_LEN : keylen;
		strlcpy(key, line, keylen);
		strlcpy(val, remain, sizeof val);

		if ((ret=in_list(key, whitelist)) == NULL) {
			//warnx("ignoring attr %s - %s\n", key, val);
			continue;
		}

		hashtable_insert(dst, strdup(ret), strdup(val));
		//warnx("inserted attr %s - %s\n", key, val);
	}
	FreeSplitList(lines);
	printf("parse_libextractor_output: done\n");
}
Ejemplo n.º 22
0
void set_mount_status(char *p,char *val) {

    if (util_starts_with(p,NETWORK_SHARE)) {
        p += strlen(NETWORK_SHARE);
    }

    char *current = hashtable_search(mount_points,p);
    if (current == NULL) {
        HTML_LOG(0,"Adding mount point [%s] = %s",p,val);
        hashtable_insert(mount_points,STRDUP(p),val);
    } else if ( STRCMP(current,val) != 0) {
        hashtable_remove(mount_points,p,1);
        HTML_LOG(0,"mount point [%s] status changed from [%s] to [%s]",p,current,val);
        hashtable_insert(mount_points,STRDUP(p),val);
    }
}
Ejemplo n.º 23
0
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), &current_ctx, sizeof(current_ctx));
    return 0;
}
Ejemplo n.º 24
0
void set_symbol_from_string(caValue* val, caValue* str)
{
    // Find this name as an existing builtin symbol.
    int foundBuiltin = builtin_symbol_from_string(as_cstring(str));
    if (foundBuiltin != -1) {
        set_symbol(val, foundBuiltin);
        return;
    }

    // Find this name as an existing runtime symbol.
    caValue* foundRuntime = hashtable_get(g_runtimeSymbolMap, str);
    if (foundRuntime != NULL) {
        copy(foundRuntime, val);
        return;
    }

    // Create a new runtime symbol.
    caValue* newRuntime = hashtable_insert(g_runtimeSymbolMap, str);
    int index = g_nextRuntimeSymbol++;
    set_symbol(newRuntime, index);
    set_symbol(val, index);

    list_resize(g_runtimeSymbolTable, index+1);
    set_value(list_get(g_runtimeSymbolTable, index), str);
}
Ejemplo n.º 25
0
Variable* Mote::getVariable(char* name) {
  char* typeStr = "";
  int isArray;
  Variable* var;
  
  var = (Variable*)hashtable_search(varTable, name);
  if (var == NULL) {
    // Could hash this for greater efficiency,
    // but that would either require transformation
    // in Tossim class or a more complex typemap.
    if (app != NULL) {
      for (int i = 0; i < app->numVariables; i++) {
	if(strcmp(name, app->variableNames[i]) == 0) {
	  typeStr = app->variableTypes[i];
	  isArray = app->variableArray[i];
	  break;
	}
      }
    }
    //  printf("Getting variable %s of type %s %s\n", name, typeStr, isArray? "[]" : "");
    var = new Variable(name, typeStr, isArray, nodeID);
    hashtable_insert(varTable, name, var);
  }
  return var;
}
Ejemplo n.º 26
0
void list_names_that_must_be_looped(Block* contents, Value* names)
{
    // Find all names within 'contents' that must be looped. A name must be looped when
    // a term inside the loop binds a name that was already used outside the loop.

    Value namesMap;
    set_hashtable(&namesMap);

    for (BlockIteratorFlat it(contents); it; ++it) {
        Term* term = it.current();

        if (has_empty_name(term))
            continue;

        Value termVal;
        termVal.set_term(contents->owningTerm);
        Term* outsideName = find_name_at(&termVal, term_name(term));

        // Don't look at names outside the major block.
        if (outsideName != NULL && !is_under_same_major_block(term, outsideName))
            outsideName = NULL;

        if (outsideName != NULL)
            set_bool(hashtable_insert(&namesMap, term_name(term)), true);
    }

    hashtable_get_keys(&namesMap, names);
    list_sort(names, NULL, NULL);
}
//-----------------------------------------------------------------------------
mme_sgw_tunnel_t                       *
sgw_lite_cm_create_s11_tunnel (
  Teid_t remote_teid,
  Teid_t local_teid)
//-----------------------------------------------------------------------------
{
  mme_sgw_tunnel_t                       *new_tunnel;

  new_tunnel = malloc (sizeof (mme_sgw_tunnel_t));

  if (new_tunnel == NULL) {
    /*
     * Malloc failed, may be ENOMEM error
     */
    SPGW_APP_ERROR ("Failed to create tunnel for remote_teid %u\n", remote_teid);
    return NULL;
  }

  new_tunnel->remote_teid = remote_teid;
  new_tunnel->local_teid = local_teid;
  /*
   * Trying to insert the new tunnel into the tree.
   * * * * If collision_p is not NULL (0), it means tunnel is already present.
   */
  hashtable_insert (sgw_app.s11teid2mme_hashtable, local_teid, new_tunnel);
  return new_tunnel;
}
Ejemplo n.º 28
0
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;
}
Ejemplo n.º 29
0
static void on_accept(int fd, short ev, void *arg) {
	int rv, *k;
	tcp_client* c;
	unsigned int addr_len;
	is_socket_init = 1;
	
	c = tcp_client_new();
	k = malloc(sizeof(int));
	*k = c->id;
	rv = hashtable_insert(clients, k, c);
	
	addr_len = sizeof(c->addr);
	c->fd = accept(fd, (struct sockaddr*)&c->addr, &addr_len);
	if (c->fd < 0) {
		// TODO free client
		return;
	}
	
	setnonblock(c->fd); // TODO check return value
	
	c->buffer_ev = bufferevent_socket_new(tapioca_get_event_base(), c->fd,
		BEV_OPT_CLOSE_ON_FREE);
	bufferevent_setcb(c->buffer_ev, on_read, on_write, on_error, c);
	bufferevent_enable(c->buffer_ev, EV_READ);
	c->write_count = 0;
}
static int gtpv1u_create_s1u_tunnel(Gtpv1uCreateTunnelReq *create_tunnel_reqP)
{
  /* Create a new nw-gtpv1-u stack req using API */
  NwGtpv1uUlpApiT          stack_req;
  NwGtpv1uRcT              rc;
  /* Local tunnel end-point identifier */
  uint32_t                 s1u_teid             = 0;
  gtpv1u_teid2enb_info_t  *gtpv1u_teid2enb_info = NULL;
  MessageDef              *message_p            = NULL;
  hashtable_rc_t           hash_rc;

  GTPU_DEBUG("Rx GTPV1U_CREATE_TUNNEL_REQ Context %d\n", create_tunnel_reqP->context_teid);
  memset(&stack_req, 0, sizeof(NwGtpv1uUlpApiT));

  stack_req.apiType = NW_GTPV1U_ULP_API_CREATE_TUNNEL_ENDPOINT;

  do {
    s1u_teid = gtpv1u_new_teid();
    GTPU_DEBUG("gtpv1u_create_s1u_tunnel() %u\n", s1u_teid);
    stack_req.apiInfo.createTunnelEndPointInfo.teid          = s1u_teid;
    stack_req.apiInfo.createTunnelEndPointInfo.hUlpSession   = 0;
    stack_req.apiInfo.createTunnelEndPointInfo.hStackSession = 0;

    rc = nwGtpv1uProcessUlpReq(gtpv1u_sgw_data.gtpv1u_stack, &stack_req);
    GTPU_DEBUG(".\n");
  } while (rc != NW_GTPV1U_OK);

  gtpv1u_teid2enb_info = malloc (sizeof(gtpv1u_teid2enb_info_t));
  memset(gtpv1u_teid2enb_info, 0, sizeof(gtpv1u_teid2enb_info_t));
  gtpv1u_teid2enb_info->state       = BEARER_IN_CONFIG;

  //#warning !!! hack because missing modify session request, so force enb address
  //    gtpv1u_teid2enb_info->enb_ip_addr.pdn_type = IPv4;
  //    gtpv1u_teid2enb_info->enb_ip_addr.address.ipv4_address[0] = 192;
  //    gtpv1u_teid2enb_info->enb_ip_addr.address.ipv4_address[1] = 168;
  //    gtpv1u_teid2enb_info->enb_ip_addr.address.ipv4_address[2] = 1;
  //    gtpv1u_teid2enb_info->enb_ip_addr.address.ipv4_address[3] = 2;


  message_p = itti_alloc_new_message(TASK_GTPV1_U, GTPV1U_CREATE_TUNNEL_RESP);
  message_p->ittiMsg.gtpv1uCreateTunnelResp.S1u_teid      = s1u_teid;
  message_p->ittiMsg.gtpv1uCreateTunnelResp.context_teid  = create_tunnel_reqP->context_teid;
  message_p->ittiMsg.gtpv1uCreateTunnelResp.eps_bearer_id = create_tunnel_reqP->eps_bearer_id;

  hash_rc = hashtable_is_key_exists(gtpv1u_sgw_data.S1U_mapping, s1u_teid);

  if (hash_rc == HASH_TABLE_KEY_NOT_EXISTS) {
    hash_rc = hashtable_insert(gtpv1u_sgw_data.S1U_mapping, s1u_teid, gtpv1u_teid2enb_info);
    message_p->ittiMsg.gtpv1uCreateTunnelResp.status       = 0;
  } else {
    message_p->ittiMsg.gtpv1uCreateTunnelResp.status       = 0xFF;
  }

  GTPU_DEBUG("Tx GTPV1U_CREATE_TUNNEL_RESP Context %u teid %u eps bearer id %u status %d\n",
             message_p->ittiMsg.gtpv1uCreateTunnelResp.context_teid,
             message_p->ittiMsg.gtpv1uCreateTunnelResp.S1u_teid,
             message_p->ittiMsg.gtpv1uCreateTunnelResp.eps_bearer_id,
             message_p->ittiMsg.gtpv1uCreateTunnelResp.status);
  return itti_send_msg_to_task(TASK_SPGW_APP, INSTANCE_DEFAULT, message_p);
}