コード例 #1
0
ファイル: librsgt_read.c プロジェクト: Altiscale/rsyslog
/* TODO: think about merging this with the writer. The
 * same applies to the other computation algos.
 */
static int
verifySigblkFinish(gtfile gf, GTDataHash **pRoot)
{
	GTDataHash *root, *rootDel;
	int8_t j;
	int r;

	if(gf->nRecords == 0)
		goto done;

	root = NULL;
	for(j = 0 ; j < gf->nRoots ; ++j) {
		if(root == NULL) {
			root = gf->roots_valid[j] ? gf->roots_hash[j] : NULL;
			gf->roots_valid[j] = 0; /* guess this is redundant with init, maybe del */
		} else if(gf->roots_valid[j]) {
			rootDel = root;
			hash_node(gf, &root, gf->roots_hash[j], root, j+2);
			gf->roots_valid[j] = 0; /* guess this is redundant with init, maybe del */
			GTDataHash_free(rootDel);
		}
	}

	free(gf->blkStrtHash);
	gf->blkStrtHash = NULL;
	*pRoot = root;
	r = 0;
done:
	gf->bInBlk = 0;
	return r;
}
コード例 #2
0
 server_node * find_node(int32_t node_id)
 {
     node_set_type::iterator it = node_set.find(node_id, hash_node(), equal_node());
     if (it == node_set.end())
         return NULL;
     return &(*it);
 }
コード例 #3
0
ファイル: node_graph.cpp プロジェクト: mrotondo/SuperCollider
void node_graph::synth_reassign_id(int32_t node_id)
{
    node_set_type::iterator it = node_set.find(node_id, hash_node(), equal_node());
    if (it == node_set.end())
        throw std::runtime_error("node id not found");
    server_node * node = &(*it);

    if (!node->is_synth())
        return;

    boost::hash<int32_t> hasher;

    int32_t hidden_id = -std::abs(node_id);

    while (!node_id_available(hidden_id))
        hidden_id = -std::abs<int32_t>(hasher(node_id));

    assert(hidden_id < 0);
    node_set.erase(*node);
    node->reset_id(hidden_id);
    node_set.insert(*node);
}
コード例 #4
0
 bool node_id_available(int32_t node_id)
 {
     node_set_type::iterator it = node_set.find(node_id, hash_node(), equal_node());
     return (it == node_set.end());
 }
コード例 #5
0
ファイル: librsgt_read.c プロジェクト: Altiscale/rsyslog
int
rsgt_vrfy_nextRec(block_sig_t *bs, gtfile gf, FILE *sigfp, FILE *nsigfp,
	          unsigned char *rec, size_t len, gterrctx_t *ectx)
{
	int r = 0;
	GTDataHash *x; /* current hash */
	GTDataHash *m, *recHash = NULL, *t, *t_del;
	uint8_t j;

	hash_m(gf, &m);
	hash_r(gf, &recHash, rec, len);
	if(gf->bKeepRecordHashes) {
		r = rsgt_vrfy_chkRecHash(gf, sigfp, nsigfp, recHash, ectx);
		if(r != 0) goto done;
	}
	hash_node(gf, &x, m, recHash, 1); /* hash leaf */
	if(gf->bKeepTreeHashes) {
		ectx->treeLevel = 0;
		ectx->lefthash = m;
		ectx->righthash = recHash;
		r = rsgt_vrfy_chkTreeHash(gf, sigfp, nsigfp, x, ectx);
		if(r != 0) goto done;
	}
	rsgtimprintDel(gf->x_prev);
	gf->x_prev = rsgtImprintFromGTDataHash(x);
	/* add x to the forest as new leaf, update roots list */
	t = x;
	for(j = 0 ; j < gf->nRoots ; ++j) {
		if(gf->roots_valid[j] == 0) {
			gf->roots_hash[j] = t;
			gf->roots_valid[j] = 1;
			t = NULL;
			break;
		} else if(t != NULL) {
			/* hash interim node */
			ectx->treeLevel = j+1;
			ectx->righthash = t;
			t_del = t;
			hash_node(gf, &t, gf->roots_hash[j], t_del, j+2);
			gf->roots_valid[j] = 0;
			if(gf->bKeepTreeHashes) {
				ectx->lefthash = gf->roots_hash[j];
				r = rsgt_vrfy_chkTreeHash(gf, sigfp, nsigfp, t, ectx);
				if(r != 0) goto done; /* mem leak ok, we terminate! */
			}
			GTDataHash_free(gf->roots_hash[j]);
			GTDataHash_free(t_del);
		}
	}
	if(t != NULL) {
		/* new level, append "at the top" */
		gf->roots_hash[gf->nRoots] = t;
		gf->roots_valid[gf->nRoots] = 1;
		++gf->nRoots;
		assert(gf->nRoots < MAX_ROOTS);
		t = NULL;
	}
	++gf->nRecords;

	/* cleanup */
	GTDataHash_free(m);
done:
	if(recHash != NULL)
		GTDataHash_free(recHash);
	return r;
}