int borrow_key(Bnode *p, int index)
{
    int from, to;
    Bnode *p1, *p2;
    if (index == p->n)
    {   /* right most */
        from = index-1;
        to = index;
    }
    else
    {
        from = index+1;
        to = index;
    }
    p1 = p->ptr[from];
    p2 = p->ptr[to];
    if (p1->n <= M) return 0;
    if (from > to)
    {
        insert_key(p2, p->key[to], p2->ptr[p2->n], p1->ptr[0]);
        p->key[to] = p1->key[0];
        delete_key(p1, 0);
    }
    else
    {
        insert_key(p2, p->key[from], p1->ptr[p1->n], p2->ptr[0]);
        p->key[from] = p1->key[p1->n - 1];
        delete_key(p1, p1->n - 1);
    }
    return 1;
}
Exemple #2
0
static int detect_signtrust(
	sc_pkcs15_card_t *p15card
){
	if(insert_cert(p15card,"8000DF01C000", 0x45, 1, "Signatur Zertifikat")) return 1;
	p15card->tokeninfo->manufacturer_id = strdup("Deutsche Post");
	p15card->tokeninfo->label = strdup("SignTrust Card");

	insert_cert(p15card,"800082008220", 0x46, 1, "Verschluesselungs Zertifikat");
	insert_cert(p15card,"800083008320", 0x47, 1, "Authentifizierungs Zertifikat");

	insert_key(p15card,"8000DF015331", 0x45, 0x80, 1024, 1, "Signatur Schluessel");
	insert_key(p15card,"800082008210", 0x46, 0x80, 1024, 2, "Verschluesselungs Schluessel");
	insert_key(p15card,"800083008310", 0x47, 0x80, 1024, 3, "Authentifizierungs Schluessel");

	insert_pin(p15card,"8000DF010000", 1, 0, 0x81, 6, "Signatur PIN",
		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
		SC_PKCS15_PIN_FLAG_INITIALIZED
	);
	insert_pin(p15card,"800082000040", 2, 0, 0x81, 6, "Verschluesselungs PIN",
		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
		SC_PKCS15_PIN_FLAG_INITIALIZED
	);
	insert_pin(p15card,"800083000040", 3, 0, 0x81, 6, "Authentifizierungs PIN",
		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
		SC_PKCS15_PIN_FLAG_INITIALIZED
	);

	return 0;
}
Exemple #3
0
treenode* insert_key(char* s,int val,treenode* node)
{
  int i;
  
  if(strlen(s)==1) { // reached last character
    if(node->size>0){
      for(i=0;i<node->size;i++){
         if(s[0]==node->next[i]->letter) { node->next[i]->val=val; return(node);}
      }
    }
    //either node size==0 or new key letter
    node = new_branch(node);
    node->next[node->size-1]=new_lasttreenode(s[0],val); 
    return(node); 
  }
  else { // not the last character
    if(node->size>0){
      for(i=0;i<node->size;i++){
         if(s[0]==node->next[i]->letter) {  node->next[i] = insert_key(s+1,val,node->next[i]); return(node); }
      }
    }
    //either node size==0 or new key letter
    node = new_branch(node); 
    node->next[node->size-1]=new_treenode(s[0]);  
    node->next[node->size-1]=insert_key(s+1,val,node->next[node->size-1]);
    return(node);  
  }
}
Exemple #4
0
int		process_copypaste(char *key, int *pos, char **line)
{
	static char	*clip;
	int			x;

	if (key[0] == 11)
	{
		if (clip)
			free(clip);
		clip = ft_strdup(*line + term_line_index(pos, line));
		ft_strclr(*line + term_line_index(pos, line));
		tputs(tgetstr("sc", NULL), 0, ft_outc);
		x = ft_strlen(clip);
		while (x--)
			ft_putstr(" ");
		tputs(tgetstr("rc", NULL), 0, ft_outc);
	}
	else if (key[0] == 25)
	{
		x = -1;
		while (++x < (int)ft_strlen(clip))
			insert_key(clip + x, line, pos);
	}
	return (0);
}
Bnode *Btree_insert(int key, Bnode *base, int *num)
{
    Bnode *t, *parent;
    int i;
    parent = base;
    t = base->ptr[0];
    if (t == NULL)
    {
        if ((t = (Bnode*)malloc(sizeof(Bnode))) == NULL) return NULL;
        t->n = 0;
        t->ptr[0] = NULL;
        base->ptr[0] = t;
    }
    while (t != NULL)
    {
        if (in_Bnode(key, t) >= 0) return NULL;  /* equal key */
        if (t->n == MM)
        {
            t = split(key, parent, base);
            if (t == NULL) return NULL;
        }
        parent = t;
        for (i = 0; i < t->n && key >= t->key[i]; i++);
        t = t->ptr[i];
    }
    insert_key(parent, key, NULL, NULL);
    (*num)++;
    return parent;
}
Exemple #6
0
int					event(int key_to_insrt, t_line *stline, t_history **history)
{
	int					i;
	int					ret;
	t_key_fct			*tbl_keys;

	tbl_keys = tbl_key_fill();
	i = -1;
	ret = 0;
	tputs(tgetstr("vi", NULL), 1, my_outc);
	while (++i < 18)
	{
		if (tbl_keys[i].key == key_to_insrt)
		{
			ret = (tbl_keys[i].fct((stline->hrd.nb > 0 ? &(stline->hrd.line)
					: &(stline->line)), (stline->hrd.nb > 0 ? &(stline->hrd.pos)
					: &(stline->pos)), stline, history));
			tputs(tgetstr("ve", NULL), 1, my_outc);
			return (ret);
		}
	}
	insert_key(key_to_insrt, stline);
	tputs(tgetstr("ve", NULL), 1, my_outc);
	return (TRUE);
}
Bnode *split(int key, Bnode *pivot, Bnode *base)
{
    Bnode *left, *right;
    Bnode *child;
    int i;
    if ((right = (Bnode*)malloc(sizeof(Bnode))) == NULL) return NULL;
    if (pivot == base)
    {
        child = pivot->ptr[0];
        if ((left = (Bnode*)malloc(sizeof(Bnode))) == NULL) return NULL;
        for (i = 0; i < M; i++)   /* left node create */
        {
            left->key[i] = child->key[i];
            left->ptr[i] = child->ptr[i];
        }
        left->ptr[i] = child->ptr[i];
        left->n = M;
        for (i = M+1; i < MM; i++)  /* right node create */
        {
            right->key[i-M-1] = child->key[i];
            right->ptr[i-M-1] = child->ptr[i];
        }
        right->ptr[i-M-1] = child->ptr[i];
        right->n = M;

        child->n = 0;   /* root node create */
        insert_key(child, child->key[M], left, right);
    }
    else
    {
        for (i = 0; i < pivot->n && key >= pivot->key[i]; i++);
        left = pivot->ptr[i];
        left->n = M;  /* left already created */
        for (i = M+1; i < MM; i++)  /* right node create */
        {
            right->key[i-M-1] = left->key[i];
            right->ptr[i-M-1] = left->ptr[i];
        }
        right->ptr[i-M-1] = left->ptr[i];
        right->n = M;

        insert_key(pivot, left->key[M], left, right);  /* pivot update */
        child = pivot;
    }
    return child;
}
Exemple #8
0
static int detect_datev(
	sc_pkcs15_card_t *p15card
){
	if(insert_cert(p15card,"3000C500", 0x45, 0, "Signatur Zertifikat")) return 1;
	p15card->tokeninfo->manufacturer_id = strdup("DATEV");
	p15card->tokeninfo->label = strdup("DATEV Classic");

	insert_cert(p15card,"DF02C200", 0x46, 0, "Verschluesselungs Zertifikat");
	insert_cert(p15card,"DF02C500", 0x47, 0, "Authentifizierungs Zertifikat");

	insert_key(p15card,"30005371", 0x45, 0x82, 1024, 1, "Signatur Schluessel");
	insert_key(p15card,"DF0253B1", 0x46, 0x81, 1024, 1, "Verschluesselungs Schluessel");
	insert_key(p15card,"DF025371", 0x47, 0x82, 1024, 1, "Authentifizierungs Schluessel");

	insert_pin(p15card,"5001", 1, 0, 0x01, 6, "PIN",
		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_INITIALIZED
	);

	return 0;
}
Exemple #9
0
cDict *dict_new(cList *keys, cList *values)
{
    cDict *cnew;
    Int i, j, size;

    if (generic_empty_dict && list_length(keys) == 0)
        return dict_dup(generic_empty_dict);

    /* Construct a new dictionary. */
    cnew = tmalloc(sizeof(cDict));

    cnew->keys   = list_dup(keys);
    cnew->values = list_dup(values);

    /* Calculate initial size of chain and hash table. */
    cnew->hashtab_size = HASHTAB_STARTING_SIZE;
    while (cnew->hashtab_size < keys->len) {
        if (cnew->hashtab_size > 4096)
            cnew->hashtab_size += 4096;
        else
            cnew->hashtab_size = cnew->hashtab_size * 2 + MALLOC_DELTA;
    }

    /* Initialize chain entries and hash table. */
    size = sizeof(Int) * cnew->hashtab_size;
    cnew->links   = tmalloc(size);
    cnew->hashtab = tmalloc(size);
    memset(cnew->links,   -1, size);
    memset(cnew->hashtab, -1, size);

    /* Insert the keys into the hash table, eliminating duplicates. */
    i = j = 0;
    while (i < cnew->keys->len) {
        if (i != j) {
            cnew->keys->el[j] = cnew->keys->el[i];
            cnew->values->el[j] = cnew->values->el[i];
        }
        if (search(cnew, &keys->el[i]) == F_FAILURE) {
            insert_key(cnew, j++);
        } else {
            data_discard(&cnew->keys->el[i]);
            data_discard(&cnew->values->el[i]);
        }
        i++;
    }
    cnew->keys->len = cnew->values->len = j;

    cnew->refs = 1;

    if (!generic_empty_dict && list_length(keys) == 0)
        generic_empty_dict = dict_dup(cnew);

    return cnew;
}
Exemple #10
0
static int detect_unicard(
	sc_pkcs15_card_t *p15card
){
	if(!insert_cert(p15card,"41004352", 0x45, 1, "Zertifikat 1")){
		p15card->tokeninfo->manufacturer_id = strdup("JLU Giessen");
		p15card->tokeninfo->label = strdup("JLU Giessen Card");

		insert_cert(p15card,"41004353", 0x46, 1, "Zertifikat 2");
		insert_cert(p15card,"41004354", 0x47, 1, "Zertifikat 3");
		insert_key(p15card,"41005103", 0x45, 0x83, 1024, 1, "Schluessel 1");
		insert_key(p15card,"41005104", 0x46, 0x84, 1024, 1, "Schluessel 2");
		insert_key(p15card,"41005105", 0x47, 0x85, 1024, 1, "Schluessel 3");

	} else if(!insert_cert(p15card,"41014352", 0x45, 1, "Zertifikat 1")){
		p15card->tokeninfo->manufacturer_id = strdup("TU Darmstadt");
		p15card->tokeninfo->label = strdup("TUD Card");

		insert_cert(p15card,"41014353", 0x46, 1, "Zertifikat 2");
		insert_cert(p15card,"41014354", 0x47, 1, "Zertifikat 3");
		insert_key(p15card,"41015103", 0x45, 0x83, 1024, 1, "Schluessel 1");
		insert_key(p15card,"41015104", 0x46, 0x84, 1024, 1, "Schluessel 2");
		insert_key(p15card,"41015105", 0x47, 0x85, 1024, 1, "Schluessel 3");

	} else return 1;

	insert_pin(p15card,"5000", 1, 2, 0x00, 6, "PIN",
		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_INITIALIZED
	);
	insert_pin(p15card,"5008", 2, 0, 0x01, 8, "PUK",
		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_INITIALIZED |
		SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN
	);

	return 0;
}
Exemple #11
0
AvlIndex AvlNode::insert_key(AvlIndex tree, AvlKey key, AvlValue value)
{
    if (!tree)
    {
        tree = new_node(key, value);
        return tree;
    }

    if (key < AVLNODE(tree)->key)
    {
        AVLNODE(tree)->left = insert_key(AVLNODE(tree)->left, key, value);
        tree = balance(tree);
    }
    else if (key > AVLNODE(tree)->key)
    {
        AVLNODE(tree)->right = insert_key(AVLNODE(tree)->right, key, value);
        tree = balance(tree);
    }
    
    // tree already has key
    return tree;
}
Exemple #12
0
INTERNAL void double_hashtab_size(Hash * hash)
{
    Int i;

    hash->hashtab_size = hash->hashtab_size * 2 + MALLOC_DELTA;
    hash->links = EREALLOC(hash->links, Int, hash->hashtab_size);
    hash->hashtab = EREALLOC(hash->hashtab, Int, hash->hashtab_size);
    for (i = 0; i < hash->hashtab_size; i++) {
        hash->links[i] = -1;
        hash->hashtab[i] = -1;
    }
    for (i = 0; i < hash->keys->len; i++)
        insert_key(hash, i);
}
Exemple #13
0
static void increase_hashtab_size(cDict *dict)
{
    Int i, newsize, oldsize = sizeof(Int) * dict->hashtab_size;

    if (dict->hashtab_size > 4096)
        dict->hashtab_size += 4096;
    else
        dict->hashtab_size = dict->hashtab_size * 2 + MALLOC_DELTA;

    newsize = sizeof(Int) * dict->hashtab_size;
    dict->links   = trealloc(dict->links,   oldsize, newsize);
    dict->hashtab = trealloc(dict->hashtab, oldsize, newsize);
    memset(dict->links,   -1, newsize);
    memset(dict->hashtab, -1, newsize);
    for (i = 0; i < dict->keys->len; i++)
        insert_key(dict, i);
}
Exemple #14
0
/* WARNING: This will discard both arguments! */
cDict *dict_union (cDict *d1, cDict *d2) {
    int i, pos;
    Bool swap;

    if (d2->keys->len > d1->keys->len) {
        cDict *t;
        t=d2; d2=d1; d1=t;
        swap = NO;
    } else {
        swap = YES;
    }

    d1=dict_prep(d1);

    for (i=0; i<d2->keys->len; i++) {
        cData *key=&d2->keys->el[i], *value=&d2->values->el[i];

        pos = search(d1, key);

        /* forget the add if it's already there */
        if (pos != F_FAILURE) {
            /* ... but if the args are in the wrong order, we
               want to overwrite the key */
            if (swap)
                d1->values = list_replace(d1->values, pos, value);
            continue;
        }

        /* Add the key and value to the list. */
        d1->keys = list_add(d1->keys, key);
        d1->values = list_add(d1->values, value);

        /* Check if we should resize the hash table. */
        if (d1->keys->len > d1->hashtab_size)
            increase_hashtab_size(d1);
        else
            insert_key(d1, d1->keys->len - 1);
    }
    dict_discard(d2);
    return d1;
}
Exemple #15
0
Hash *hash_add(Hash * hash, cData * key)
{
    Int pos;

#if 0
    hash = hash_prep(hash);
#endif

    pos = hash_find(hash, key);
    if (pos != F_FAILURE)
        return hash;

    /* Add the key */
    hash->keys = list_add(hash->keys, key);

    /* Check if we should resize the hash table. */
    if (hash->keys->len > hash->hashtab_size)
        double_hashtab_size(hash);
    else
        insert_key(hash, hash->keys->len - 1);
    return hash;
}
Exemple #16
0
Hash *hash_new_with(cList * keys)
{
    Hash *cnew;
    Int i, j;

    /* Construct a new hash */
    cnew = EMALLOC(Hash, 1);
    cnew->keys = list_dup(keys);

    /* Calculate initial size of chain and hash table. */
    cnew->hashtab_size = HASHTAB_STARTING_SIZE;
    while (cnew->hashtab_size < keys->len)
        cnew->hashtab_size = cnew->hashtab_size * 2 + MALLOC_DELTA;

    /* Initialize chain entries and hash table. */
    cnew->links = EMALLOC(Int, cnew->hashtab_size);
    cnew->hashtab = EMALLOC(Int, cnew->hashtab_size);
    for (i = 0; i < cnew->hashtab_size; i++) {
        cnew->links[i] = -1;
        cnew->hashtab[i] = -1;
    }

    /* Insert the keys into the hash table, eliminating duplicates. */
    i = j = 0;
    while (i < cnew->keys->len) {
        if (i != j)
            cnew->keys->el[j] = cnew->keys->el[i];
        if (hash_find(cnew, &keys->el[i]) == F_FAILURE)
            insert_key(cnew, j++);
        else
            data_discard(&cnew->keys->el[i]);
        i++;
    }
    cnew->keys->len = j;

    cnew->refs = 1;
    return cnew;
}
Exemple #17
0
void insert_key( node_t* node, key_type key ){
        node_t** child;

        if( comp_key( key, node->key ) == 0 ){
                printf("Node already exist!\n");
                return;
        }
        
        if( comp_key( key, node->key ) == -1 )
                child = &(node->left);
        else
                child = &(node->right);
        
        if( *child != NULL )
                insert_key( *child, key );
        else{
                *child = malloc(sizeof(node_t));
                copy_key( &( (*child)->key ), key);
                (*child)->left = NULL;
                (*child)->right = NULL;
                (*child)->parent = node;
                return;
        }
}
Exemple #18
0
cDict *dict_add(cDict *dict, cData *key, cData *value)
{
    Int pos;

    dict = dict_prep(dict);

    /* Just replace the value for the key if it already exists. */
    pos = search(dict, key);
    if (pos != F_FAILURE) {
        dict->values = list_replace(dict->values, pos, value);
        return dict;
    }

    /* Add the key and value to the list. */
    dict->keys = list_add(dict->keys, key);
    dict->values = list_add(dict->values, value);

    /* Check if we should resize the hash table. */
    if (dict->keys->len > dict->hashtab_size)
        increase_hashtab_size(dict);
    else
        insert_key(dict, dict->keys->len - 1);
    return dict;
}
Exemple #19
0
Fichier : file.c Projet : ejrh/ejrh
static int get_file_data_block_callback(FS *fs, BLOCK *block, KEY *key, EFFECT *effect, void *data)
{
    struct get_file_data_block_baton *baton = (struct get_file_data_block_baton *) data;
    char extent_prefix[MAX_INTERNAL_NAME+1];
    unsigned long int start = -1, stop = -1;
    BLOCK *b;

    sprintf(extent_prefix, "%ld/X", baton->fh->label);

    if (key->type != K_INVALID && strncmp(key->name, extent_prefix, strlen(extent_prefix)) == 0)
    {
        sscanf(key->name + strlen(extent_prefix), "%ld-%ld", &start, &stop);
        if (start <= baton->block_num && baton->block_num <= stop)
        {
            baton->location = key->pointer + (baton->block_num - start);
            return 1;
        }
    }
    
    b = allocate_block(fs, B_DATA, baton->predecessor);

    if (key->type != K_INVALID && strncmp(key->name, extent_prefix, strlen(extent_prefix)) == 0
            && stop == baton->block_num - 1 && key->pointer + (stop - start) == b->location - 1)
    {
        sprintf(extent_prefix, "%ld/X%08ld-%08ld", baton->fh->label, start, baton->block_num);
        replace_key(fs, block, key->name, extent_prefix, K_ATTRIBUTE, key->pointer, effect);
    }
    else
    {
        sprintf(extent_prefix, "%ld/X%08ld-%08ld", baton->fh->label, baton->block_num, baton->block_num);
        insert_key(fs, block, extent_prefix, K_ATTRIBUTE, b->location, effect);
    }
    
    baton->location = b->location;
    return 1;
}
Exemple #20
0
static int detect_idkey(
	sc_pkcs15_card_t *p15card
){
	sc_card_t *card=p15card->card;
	sc_path_t p;

	/* TCKEY-Applikation ? */
	memset(&p, 0, sizeof(sc_path_t));
	p.type=SC_PATH_TYPE_DF_NAME;
	memcpy(p.value, "\xD2\x76\x00\x00\x03\x0C\x01", p.len=7);
	if (sc_select_file(card,&p,NULL)!=SC_SUCCESS) return 1;

	p15card->tokeninfo->manufacturer_id = strdup("TeleSec GmbH");
	p15card->tokeninfo->label = strdup("IDKey Card");

	insert_cert(p15card, "DF074331", 0x45, 1, "Signatur Zertifikat 1");
	insert_cert(p15card, "DF074332", 0x45, 1, "Signatur Zertifikat 2");
	insert_cert(p15card, "DF074333", 0x45, 1, "Signatur Zertifikat 3");

	insert_key(p15card, "DF074E03", 0x45, 0x84, 2048, 1, "IDKey1");
	insert_key(p15card, "DF074E04", 0x46, 0x85, 2048, 1, "IDKey2");
	insert_key(p15card, "DF074E05", 0x47, 0x86, 2048, 1, "IDKey3");
	insert_key(p15card, "DF074E06", 0x48, 0x87, 2048, 1, "IDKey4");
	insert_key(p15card, "DF074E07", 0x49, 0x88, 2048, 1, "IDKey5");
	insert_key(p15card, "DF074E08", 0x4A, 0x89, 2048, 1, "IDKey6");

	insert_pin(p15card, "5000", 1, 2, 0x00, 6, "PIN",
		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_INITIALIZED
	);
	insert_pin(p15card, "5001", 2, 0, 0x01, 8, "PUK",
		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_INITIALIZED |
		SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN
	);

	return 0;
}
Exemple #21
0
struct ini_doc *create_ini_doc(char * file_name) {
	char buffer[256];

	FILE * file = fopen(file_name, "r");

	if (file == NULL)
		return 0;

	struct ini_doc* pIniDoc = malloc(sizeof(struct ini_doc));
	if (pIniDoc == NULL)
		return NULL;

	pIniDoc->sectionNum = 0;
	pIniDoc->sections = NULL;

	struct ini_section * pSection = NULL;

	while (1) {
		char* line = fgets(buffer, sizeof(buffer), file);
		int length = 0;
		int index = -1;
		char * name = NULL;
		char *value = NULL;
		if (line == NULL)
			break;

		line = trim_string(line, &length);
		if (line == NULL)
			continue;
		if (line[0] == ';')
			continue;
		if (line[0] == '[') {
			index = find_index(line, 1, ']');
			if (index > 2) //find a new section
					{
				line[index] = '\0';
				name = (char*) malloc(index);
				strcpy(name, line + 1);
				name[index - 1] = '\0';
				if (pSection != NULL) {
					insert_section(pIniDoc, pSection);
				}
				pSection = (struct ini_section*) malloc(
						sizeof(struct ini_section));
				pSection->next = NULL;
				pSection->name = name;

			}
		} else if (pSection != NULL) {
			index = find_index(line, 0,'=');
			if (index >= 1 && index < length - 1) //find a new key-value
					{
				line[index] = '\0';
				struct ini_key *pKey = (struct ini_key *) malloc(
						sizeof(struct ini_key));
				pKey->next = NULL;
				name = (char*) malloc(index + 1);
				strcpy(name, line);
				name[index] = '\0';
				pKey->key = name;

				value = (char*) malloc(length - index);
				strcpy(value,line+index+1);
				value[length-index-1]='\0';
				pKey->value = value;

				insert_key(pSection,pKey);

			}

		}
	}

	if (pSection != NULL) {
		insert_section(pIniDoc, pSection);
	}
	fclose(file);

	return pIniDoc;
}
Exemple #22
0
static PurpleDesktopItem *
ditem_load (FILE *df,
	    gboolean no_translations,
	    const char *uri)
{
	int state;
	char CharBuffer [1024];
	char *next = CharBuffer;
	int c;
	Encoding encoding;
	PurpleDesktopItem *item;
	Section *cur_section = NULL;
	char *key = NULL;
	gboolean old_kde = FALSE;

	encoding = get_encoding (df);
	if (encoding == ENCODING_UNKNOWN) {
		fclose(df);
		/* spec says, don't read this file */
		printf ("Unknown encoding of .desktop file");

		return NULL;
	}

	/* Rewind since get_encoding goes through the file */
	if (fseek(df, 0L, SEEK_SET)) {
		fclose(df);
		/* spec says, don't read this file */
		printf ("fseek() error on .desktop file");
		return NULL;
	}

	item = _purple_desktop_item_new ();
	item->modified = FALSE;

	/* Note: location and mtime are filled in by the new_from_file
	 * function since it has those values */

#define PURPLE_DESKTOP_ITEM_OVERFLOW (next == &CharBuffer [sizeof(CharBuffer)-1])

	state = FirstBrace;
	while ((c = getc (df)) != EOF) {
		if (c == '\r')		/* Ignore Carriage Return */
			continue;
		
		switch (state) {

		case OnSecHeader:
			if (c == ']' || PURPLE_DESKTOP_ITEM_OVERFLOW) {
				*next = '\0';
				next = CharBuffer;

				/* keys were inserted in reverse */
				if (cur_section != NULL &&
				    cur_section->keys != NULL) {
					cur_section->keys = g_list_reverse
						(cur_section->keys);
				}
				if (strcmp (CharBuffer,
					    "KDE Desktop Entry") == 0) {
					/* Main section */
					cur_section = NULL;
					old_kde = TRUE;
				} else if (strcmp (CharBuffer,
						   "Desktop Entry") == 0) {
					/* Main section */
					cur_section = NULL;
				} else {
					cur_section = g_new0 (Section, 1);
					cur_section->name =
						g_strdup (CharBuffer);
					cur_section->keys = NULL;
					item->sections = g_list_prepend
						(item->sections, cur_section);
				}
				state = IgnoreToEOL;
			} else if (c == '[') {
				/* FIXME: probably error out instead of ignoring this */
			} else {
				*next++ = c;
			}
			break;

		case IgnoreToEOL:
		case IgnoreToEOLFirst:
			if (c == '\n'){
				if (state == IgnoreToEOLFirst)
					state = FirstBrace;
				else
					state = KeyDef;
				next = CharBuffer;
			}
			break;

		case FirstBrace:
		case KeyDef:
		case KeyDefOnKey:
			if (c == '#') {
				if (state == FirstBrace)
					state = IgnoreToEOLFirst;
				else
					state = IgnoreToEOL;
				break;
			}

			if (c == '[' && state != KeyDefOnKey){
				state = OnSecHeader;
				next = CharBuffer;
				g_free (key);
				key = NULL;
				break;
			}
			/* On first pass, don't allow dangling keys */
			if (state == FirstBrace)
				break;
	    
			if ((c == ' ' && state != KeyDefOnKey) || c == '\t')
				break;
	    
			if (c == '\n' || PURPLE_DESKTOP_ITEM_OVERFLOW) { /* Abort Definition */
				next = CharBuffer;
				state = KeyDef;
				break;
			}
	    
			if (c == '=' || PURPLE_DESKTOP_ITEM_OVERFLOW){
				*next = '\0';

				g_free (key);
				key = g_strdup (CharBuffer);
				state = KeyValue;
				next = CharBuffer;
			} else {
				*next++ = c;
				state = KeyDefOnKey;
			}
			break;

		case KeyValue:
			if (PURPLE_DESKTOP_ITEM_OVERFLOW || c == '\n'){
				*next = '\0';

				insert_key (item, cur_section, encoding,
					    key, CharBuffer, old_kde,
					    no_translations);

				g_free (key);
				key = NULL;

				state = (c == '\n') ? KeyDef : IgnoreToEOL;
				next = CharBuffer;
			} else {
				*next++ = c;
			}
			break;

		} /* switch */
	
	} /* while ((c = getc_unlocked (f)) != EOF) */
	if (c == EOF && state == KeyValue) {
		*next = '\0';

		insert_key (item, cur_section, encoding,
			    key, CharBuffer, old_kde,
			    no_translations);

		g_free (key);
		key = NULL;
	}

#undef PURPLE_DESKTOP_ITEM_OVERFLOW

	/* keys were inserted in reverse */
	if (cur_section != NULL &&
	    cur_section->keys != NULL) {
		cur_section->keys = g_list_reverse (cur_section->keys);
	}
	/* keys were inserted in reverse */
	item->keys = g_list_reverse (item->keys);
	/* sections were inserted in reverse */
	item->sections = g_list_reverse (item->sections);

	/* sanitize some things */
	sanitize (item, uri);

	/* make sure that we set up the type */
	setup_type (item, uri);

	fclose (df);

	return item;
}
Exemple #23
0
static int detect_netkey(
	sc_pkcs15_card_t *p15card
){
	sc_card_t *card=p15card->card;
	sc_path_t p;
	sc_file_t *f;
	int keylen;
	char dir[10];
	const char *c_auth;

	/* NKS-Applikation ? */
	memset(&p, 0, sizeof(sc_path_t));
	p.type=SC_PATH_TYPE_DF_NAME;
	memcpy(p.value, "\xD2\x76\x00\x00\x03\x01\x02", p.len=7);
	if (sc_select_file(card,&p,&f)!=SC_SUCCESS) return 1;
	sprintf(dir,"%04X", f->id);
	sc_file_free(f);

	p15card->tokeninfo->manufacturer_id = strdup("TeleSec GmbH");
	p15card->tokeninfo->label = strdup(card->type==SC_CARD_TYPE_TCOS_V3 ? "NetKey V3 Card" : "NetKey Card");
	keylen= card->type==SC_CARD_TYPE_TCOS_V3 ? 2048 : 1024;
	c_auth= card->type==SC_CARD_TYPE_TCOS_V3 ? "C500" : "C100";

	insert_cert(p15card, dirpath(dir,"4331"), 0x45, 1, "Signatur Zertifikat 1");
	insert_cert(p15card, dirpath(dir,"4332"), 0x45, 1, "Signatur Zertifikat 2");
	insert_cert(p15card, dirpath(dir,"C000"), 0x45, 0, "Telesec Signatur Zertifikat");
	insert_cert(p15card, dirpath(dir,"43B1"), 0x46, 1, "Verschluesselungs Zertifikat 1");
	insert_cert(p15card, dirpath(dir,"43B2"), 0x46, 1, "Verschluesselungs Zertifikat 2");
	insert_cert(p15card, dirpath(dir,"C200"), 0x46, 0, "Telesec Verschluesselungs Zertifikat");
	insert_cert(p15card, dirpath(dir,"4371"), 0x47, 1, "Authentifizierungs Zertifikat 1");
	insert_cert(p15card, dirpath(dir,"4372"), 0x47, 1, "Authentifizierungs Zertifikat 2");
	insert_cert(p15card, dirpath(dir,c_auth), 0x47, 0, "Telesec Authentifizierungs Zertifikat");
	insert_cert(p15card, dirpath(dir,"C201"), 0x48, 0, "Telesec 1024bit Zertifikat");

	insert_key(p15card, dirpath(dir,"5331"), 0x45, 0x80, keylen, 4, "Signatur Schluessel");
	insert_key(p15card, dirpath(dir,"53B1"), 0x46, 0x81, keylen, 3, "Verschluesselungs Schluessel");
	insert_key(p15card, dirpath(dir,"5371"), 0x47, 0x82, keylen, 3, "Authentifizierungs Schluessel");
	insert_key(p15card, dirpath(dir,"0000"), 0x48, 0x83, 1024,   3, "1024bit Schluessel");

	insert_pin(p15card, "5000", 1, 2, 0x00, 6, "PIN",
		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_INITIALIZED
	);
	insert_pin(p15card, "5001", 2, 0, 0x01, 8, "PUK",
		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_INITIALIZED |
		SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN
	);
	if(card->type==SC_CARD_TYPE_TCOS_V3){
		insert_pin(p15card, dirpath(dir,"0000"), 3, 1, 0x83, 6, "NetKey PIN2",
			SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
			SC_PKCS15_PIN_FLAG_INITIALIZED
		);
	} else {
		insert_pin(p15card, dirpath(dir,"5080"), 3, 1, 0x80, 6, "NetKey PIN0",
			SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
			SC_PKCS15_PIN_FLAG_INITIALIZED
		);
	}
	insert_pin(p15card, dirpath(dir,"5081"), 4, 1, 0x81, 6, "NetKey PIN1",
		SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
		SC_PKCS15_PIN_FLAG_INITIALIZED
	);

	/* SigG-Applikation */
	p.len=7; p.type=SC_PATH_TYPE_DF_NAME;
	memcpy(p.value, "\xD2\x76\x00\x00\x66\x01", p.len=6);
	if (sc_select_file(card,&p,&f)==SC_SUCCESS){
		sprintf(dir,"%04X", f->id);
		sc_file_free(f);

		insert_cert(p15card, dirpath(dir,"C000"), 0x49, 1, "SigG Zertifikat 1");
		insert_cert(p15card, dirpath(dir,"4331"), 0x49, 1, "SigG Zertifikat 2");
		insert_cert(p15card, dirpath(dir,"4332"), 0x49, 1, "SigG Zertifikat 3");
		
		if(card->type==SC_CARD_TYPE_TCOS_V3){
			insert_key(p15card, dirpath(dir,"0000"), 0x49, 0x84, 2048, 5, "SigG Schluessel");
		} else {
			insert_key(p15card, dirpath(dir,"5331"), 0x49, 0x80, 1024, 5, "SigG Schluessel");
		}

		insert_pin(p15card, dirpath(dir,"5081"), 5, 0, 0x81, 6, "SigG PIN",
			SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
			SC_PKCS15_PIN_FLAG_INITIALIZED
		);
		if(card->type==SC_CARD_TYPE_TCOS_V3){
			insert_pin(p15card, dirpath(dir,"0000"), 6, 0, 0x83, 8, "SigG PIN2",
				SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | SC_PKCS15_PIN_FLAG_LOCAL |
				SC_PKCS15_PIN_FLAG_INITIALIZED
			);
		}
	}

	return 0;
}
Exemple #24
0
int	insert_key(BTREE *bt, long page, KEY *key, ITEM *u, KEY **hkey)
{
PAGE_ADDRESS *p, *b;
KEY *pk, *pkk, *vkey;
long	nx;
int	k, l, r, n;
ITEM	v;

   *hkey = NULL;
   if (page == BTREE_NULL)
   {
	u->next = page;
	u->child = 0;
	*hkey = (KEY *) malloc(bt->keysize);
	memcpy(*hkey, key, bt->realkeysize);
        return 0;
   }

   p = (PAGE_ADDRESS *) get_page(bt, page);
   pk = (KEY *) (p + 1);

   l = 0; r = p->nkeys-1;
   do {
	k = (l + r) / 2;
	pkk = nth_key(bt, p, k);

	if (bt->compare_key((void *) key, pkk) < 0) r = k - 1;
	else

	if (bt->compare_key((void *) key, pkk) > 0) l = k + 1;
	else
	   break;
   } while (r >= l);

   if (r >= l)
   {
	if (p->s[k].size < 0) /* chave foi deletada */
	{
	   p->s[k].size = u->size;
	   p->s[k].address = u->address;
	   memcpy(nth_key(bt, p, k), key, bt->realkeysize);
	   return 0;
	} 
	btree_errno = DUP_KEY;
	return -1;	/* chave jah existe */
   }

   if (r < 0)
      	nx = p->next0;
   else
	nx = p->s[r].next;

   v = *u;
   if ((k = insert_key(bt, nx, key, &v, &vkey)) < 0)
	return k;

   if (vkey == NULL)
   {
     if ( r < 0)
     {
	p->child0 += v.child;
     }
     else
     {
	p->s[r].child += v.child;
     }
     *u = v;
     write_page(bt, p);
     return 0;
   }	

   p->s[r].child -= v.child;

   if (p->nkeys < bt->order)
   {
	for (k = p->nkeys; k > r+1; k--)
	{
	   p->s[k] = p->s[k-1];
	   pkk = nth_key(bt, p, k);
	   pk = nth_key(bt, p, k-1);
	   memcpy(pkk, pk, bt->realkeysize);
	}
	memcpy(nth_key(bt, p, k), vkey, bt->realkeysize);
	p->s[k] = v;
	p->nkeys++;
	u->child = 1;
	free(vkey);
	write_page(bt, p);
	return 0;
   }

   b = (PAGE_ADDRESS *) new_page(bt);
   b->label = BTREE_LABEL;
   n = bt->order / 2 - 1;
   if (r <= n)
   {
	if (r != n)
	{
	   *u = p->s[n];
	   *hkey = (KEY *) malloc(bt->keysize);
	   memcpy(*hkey, nth_key(bt, p, n), bt->realkeysize);
	   for (k = n ; k > r+1; k--)
	   {
	   	p->s[k] = p->s[k-1];
	   	pkk = nth_key(bt, p, k);
	   	pk = nth_key(bt, p, k-1);
	   	memcpy(pkk, pk, bt->realkeysize);
	   }
	   memcpy(nth_key(bt, p, k), vkey, bt->realkeysize);
	   p->s[k] = v;
	   free(vkey);
	}
	else
	{
	   *u = v;
	   *hkey = vkey;
	}
	n++;
	
	for (k = 0; k < n; k++)
	{
	   b->s[k] = p->s[k+n];
	   memcpy(nth_key(bt, b, k), nth_key(bt, p, k+n), bt->realkeysize);
	}
   }
   else
   {
	r = r - n - 1;
	*u = p->s[n+1];
	*hkey = (KEY *) malloc(bt->keysize);
	memcpy(*hkey, nth_key(bt, p, n+1), bt->realkeysize);
	for (k = 0; k < r; k++)
	{
	   
	   b->s[k] = p->s[k+n+2];
	   memcpy(nth_key(bt, b, k), nth_key(bt, p, k+n+2), bt->realkeysize);
	}
	memcpy(nth_key(bt, b, k), vkey, bt->realkeysize);
	b->s[k] = v;
	free(vkey);
	n++;
	for (k = r+1; k < n; k++)
	{
	   
	   b->s[k] = p->s[k+n];
	   memcpy(nth_key(bt, b, k), nth_key(bt, p, k+n), bt->realkeysize);
	}
   }
   p->nkeys = b->nkeys = n;
   b->next0 = u->next;
   b->child0 = u->child;
   u->next = address_of(bt, b);
   u->child = n + b->child0;
   for (k = 0; k < n; k++)
      u->child += b->s[k].child;
   write_page(bt, p);
   write_page(bt, b); 
   return 0;
}
Exemple #25
0
void
run_test(enum test_type t_type, uint8_t use_hashes)
{
        uint64_t i;
        uint64_t is_member_count;
        uint64_t rnd_nbr;
        char *type;
        uint64_t set_bits;
        struct timeval tval_before, tval_after, tval_result;

        /* insertion */
        create_filter(filter_size, use_hashes);

        gettimeofday(&tval_before, NULL);
        switch (t_type) {
                case EVEN_UNEVEN:
                        type = "un/even";
                        for (i = 1; i < insert_size << 1; i += 2) {
                                insert_key((char *)&i, 8);
                        }
                        break;
                case RANDOM:
                        type = "random";
                        for (i = 0; i < insert_size; i++) {
                                rnd_nbr = arc4random();
                                rnd_nbr = rnd_nbr << 32;
                                rnd_nbr = rnd_nbr | arc4random();
                                insert_key((char *)&rnd_nbr, 8);
                        }
                        break;
                case COUNTING:
                        type = "counting";
                        for (i = 0; i < insert_size; i++) {
                                insert_key((char *)&i, 8);
                        }
                        break;
                default:
                        /* not reached */
                        type = "";
                        break;
        }
        gettimeofday(&tval_after, NULL);
        timersub(&tval_after, &tval_before, &tval_result);

        /* testing */
        is_member_count = 0;
        switch (t_type) {
                case EVEN_UNEVEN:
                        for (i = 0; i < insert_size << 1; i += 2) {
                                if (is_member((char *)&i, 8)) {
                                        is_member_count++;
                                }
                        }
                        break;
                case RANDOM:
                        for (i = 0; i < insert_size; i++) {
                                rnd_nbr = arc4random();
                                rnd_nbr = rnd_nbr << 32;
                                rnd_nbr = rnd_nbr | arc4random();
                                if (is_member((char *)&rnd_nbr, 8)) {
                                        is_member_count++;
                                }
                        }
                        break;
                case COUNTING:
                        for (i = insert_size; i < insert_size << 1; i++) {
                                if (is_member((char *)&i, 8)) {
                                        is_member_count++;
                                }
                        }
                        break;
                default:
                        /* not reached */
                        break;
        }

        set_bits = estimate_cardinality();

        /* print info */
        printf("%-8s: ins time: %2ld.%-6ld false pos: %6.2f%% (%10lu) fill factor: %6.2f%% (%10lu) err rate: %6.2f%% (%10lu)\n",
            type,
            (long int)tval_result.tv_sec,
            (long int)tval_result.tv_usec,
            (double)is_member_count / (double)insert_size * 100.0,
            is_member_count,
            (double)set_bits / (double)filter_size * 100.0,
            set_bits,
            (double)(insert_size * K - set_bits) / (double)(insert_size * K) * 100.0,
            insert_size * K - set_bits);
}
Exemple #26
0
int main(int argc, char *argv[]){
	char buffer[64];
	char *c;

#if DEBUG
	printf("[DEBUG MODE]\n");
	printf("Compile: %s %s\n", __DATE__, __TIME__);
#endif

	printf("Version: %d.%d.%d\n", VER_REL, VER_MAJOR, VER_MINOR);
	printf("Database> ");
	dbfile_t *mdb = open_dbfile(get_input(buffer, 32, TRUE));
	commit_db(mdb);

	for(;;){
		printf("valca> ");

		c = get_input(buffer, 64, TRUE);
		if(!strcmp("quit", c)||!strcmp("exit", c)||!strcmp("\\q", c)){
			break;
		}
		if(!strcmp("help", c)){
			printf("COMMANDS:\n");
			printf("COMMIT        Commit file to disk\n");
			printf("COUNT         Show row count\n");
			printf("TRUNCATE      Delete all keys\n");
			printf("UPDATE        Update key value\n");
			printf("INSERT        Insert key\n");
			printf("DELETE \\\n");
			printf("  COLUMN      Delete column\n");
			printf("  ROW         Delete row\n");
			printf("ALTER \\\n");
			printf("  NAME        Change column name\n");
			printf("  LEFT        Shift column left\n");
			printf("  RIGHT       Shift column right\n");
			printf("SELECT        Select value from\n");
			printf("ADD \\\n");
			printf("  COLUMN      Add column\n");
			printf("SHOW \\\n");
			printf("  COLUMNS     Show all columns\n");
			printf("  TREE        Show storage tree\n");
			printf("  STATUS      Show database info\n");
			printf("  TABLE       Show dataset as table\n");
			printf("FREE \\\n");
			printf("  COLUMNS     Columns freelist\n");
			printf("  NODE        Node freelist\n");
			printf("  DATAFIELDS  Payload freelist\n");
			printf("EXIT          Quit the shell\n");
		}
		if(!strcmp("commit", c)){
			commit_db(mdb);
		}
		if(!strcmp("count", c)){
			printf("Total rows: %d\n", mdb->k_cnt);
		}
		if(!strcmp("truncate", c)){
			truncate_root(mdb);
		}
		if(!strcmp("update", c)){
			char tmp[32];
			printf(">psid: ");
			c = get_input(tmp, 32, FALSE);
			int key = atoi(tmp);
			char tmpcolname[32];
			printf(">column: ");
			c = get_input(tmpcolname, 32, FALSE);
			int idx = get_column_idx(mdb, tmpcolname);
			printf(">value: ");
			c = get_input(tmp, 32, FALSE);
			change(mdb, key, (void*)tmp, idx);
		}
		if(!strcmp("insert", c)){
			if(!mdb->c_cnt){
				printf("Cannot insert without column\n");
			}else{
				char tmp[32];
				printf(">psid[%d]: ", mdb->seq_cnt);
				c = get_input(tmp, 32, FALSE);
				int key;
				if(!strlen(tmp)){
					key = mdb->seq_cnt++;
				}else{
					key = atoi(tmp);
				}
				column_t col;
				read_column(mdb, mdb->data.c_root, &col);
				printf(">%s<%s(%d)>: ", col.name, get_datatype_name(col.d_type), col.maxsize);
				c = get_input(tmp, 32, FALSE);
				if(get_datatype(col.d_type).size == -1) tmp[col.maxsize] = '\0';
				if(col.usign) printf("<> %d\n", atoi(tmp));
					//if(atoi())
				if(insert_key(mdb, key, (void*)tmp) == SUCCESS){
					result_t rs = search_key(mdb, key);
					if(rs.rstat == SUCCESS){
						char tmp[32];
						int i = 1;
						while(col.c_next != EMPTY){
							read_column(mdb, col.c_next, &col);
							printf(">%s<%s(%d)>: ", col.name, get_datatype_name(col.d_type), col.maxsize);
							c = get_input(tmp, 32, FALSE);
							add_field(mdb, rs.fpos, rs.idx, (void*)tmp, i);
							i++;
						}
					}
				}
			}
		}
		if(!strcmp("delete", c)){
			printf(">");
			c = get_input(buffer, 64, TRUE);
			if(!strcmp("column", c)){
				char tmpcolname[32];
				printf(">column: ");
				c = get_input(tmpcolname, 32, FALSE);
				int idx = get_column_idx(mdb, tmpcolname);
				delete_column(mdb, idx);
			}
			if(!strcmp("row", c)){
				char tmp[32];
				printf(">psid: ");
				c = get_input(tmp, 32, FALSE);
				int key = atoi(tmp);
				result_t rs = search_key(mdb, key);
				if(rs.rstat == SUCCESS){
					int i;
					for(i=mdb->c_cnt; i>1; i--){
						delete_field(mdb, rs.fpos, rs.idx, (i-1));
					}
					delete_key(mdb, key);
				}
			}
		}
		if(!strcmp("alter", c)){
			printf(">");
			c = get_input(buffer, 64, TRUE);
			if(!strcmp("name", c)){
				printf(">column: ");
				char tmpcolname[32];
				c = get_input(tmpcolname, 32, FALSE);
				int idx = get_column_idx(mdb, tmpcolname);
				printf(">new name: ");
				c = get_input(tmpcolname, 32, FALSE);
				rename_column(mdb, tmpcolname, idx);
			}
			if(!strcmp("left", c)){
				char tmpcolname[32];
				printf(">column: ");
				c = get_input(tmpcolname, 32, FALSE);
				int idx = get_column_idx(mdb, tmpcolname);
				shift_column_left(mdb, idx);
			}
			if(!strcmp("right", c)){
				char tmpcolname[32];
				printf(">column: ");
				c = get_input(tmpcolname, 32, FALSE);
				int idx = get_column_idx(mdb, tmpcolname);
				shift_column_right(mdb, idx);
			}
		}
		if(!strcmp("select", c)){
			printf(">");
			char tmp[16];
			printf(">psid: ");
			c = get_input(tmp, 32, FALSE);
			int key = atoi(tmp);
			result_t rs = search_key(mdb, key);
			if(rs.rstat == SUCCESS){
				found(mdb, rs.fpos, rs.idx);
			}
		}
		if(!strcmp("add", c)){
			printf(">");
			c = get_input(buffer, 64, TRUE);
			if(!strcmp("column", c)){
				char colname[32];
				DTYPE type;
				int size;
				bool usign = FALSE;
				int idx;
				printf(">name: ");
				c = get_input(colname, 32, FALSE);
				printf(">type: ");
				char tmptype[32];
				c = get_input(tmptype, 32, FALSE);
				type = get_datatype_idx(tmptype);
				if(type == EMPTY){
					printf("Unkown datatype\n");
					continue;
				}
				size = get_datatype(type).size;
				if(size == EMPTY){
					printf(">size: ");
					char tmpsize[16];
					c = get_input(tmpsize, 16, FALSE);
					size = atoi(tmpsize);
				}
				if(get_datatype(type).signness){
					printf(">unsigned: ");
					char tmpsign[4];
					c = get_input(tmpsign, 4, FALSE);
					if(!strcmp("y", tmpsign)){
						usign = TRUE;
					}
				}
				printf(">before: ");
				char tmpcolname[32];
				c = get_input(tmpcolname, 32, FALSE);
				idx = get_column_idx(mdb, tmpcolname);
				add_column(mdb, colname, size, type, usign, idx);
			}
		}
		if(!strcmp("show", c)){
			printf(">");
			c = get_input(buffer, 64, TRUE);
			if(!strcmp("columns", c)){
				printf("Idx   Offset   Psid         Columnname  Size      Type    Unsigned    Next\n");
				printf("--------------------------------------------------------------------------\n");
				print_column(mdb, mdb->data.c_root, 0);
			}
			if(!strcmp("tree", c)){
				print_tree(mdb, mdb->data.n_root, 0);
			}
			if(!strcmp("status", c)){
				print_status(mdb);
			}
			if(!strcmp("table", c)){
				print_table(mdb);
			}
		}
		if(!strcmp("free", c)){
			printf(">");
			c = get_input(buffer, 64, TRUE);
			if(!strcmp("columns", c)){
				printf("Idx   Offset   Psid         Columnname  Size      Type    Unsigned    Next\n");
				printf("--------------------------------------------------------------------------\n");
				print_column(mdb, mdb->data.c_free, 0);
			}
			if(!strcmp("node", c)){
				print_tree(mdb, mdb->data.n_free, 0);
			}
			if(!strcmp("datafields", c)){
				print_datafield(mdb, mdb->data.d_free);
			}
		}
	}

	commit_db(mdb);
	close_dbfile(mdb->vfp);
	close_db(mdb);

	return 0;
}
Exemple #27
0
int main(){
  KeyType * keytype = new KeyType;
  keytype->numAttrs = 3;
  keytype->attrTypes[0] = intType;
  keytype->attrTypes[1] = stringType;
  keytype->attrTypes[2] = intType;
  keytype->attrLen[0] = INTSIZE;
  keytype->attrLen[1] = 8; // 8 character string
  keytype->attrLen[2] = INTSIZE;
  int payloadLen = 2;
  Index * foo = new Index("foo",keytype, payloadLen);
  int keylen = keyLength(keytype);

  if(DEBUG){
    cout << "MAXKEYS: " << foo->maxKeys << endl;
  }

  byte * key = new byte[keylen];
  char str[] = "awesom0";
  insert_key(key, 4, 12, str);
  char pay[] = "a";

  byte * key1 = new byte[keylen];
  char str1[] = "awesom1";
  insert_key(key1, 4, 12, str1);
  char pay1[] = "b";

  byte * key2 = new byte[keylen];
  char str2[] = "awesom2";
  insert_key(key2, 4, 22, str2);
  char pay2[] = "c";

  byte * key3 = new byte[keylen];
  char str3[] = "awesom3";
  insert_key(key3, 4, 32, str3);
  char pay3[] = "d";

  byte * key4 = new byte[keylen];
  char str4[] = "awesom4";
  insert_key(key4, 4, 42, str4);
  char pay4[] = "e";

  byte * key5 = new byte[keylen];
  char str5[] = "awesom5";
  insert_key(key5, 4, 52, str5);
  char pay5[] = "f";

  /*All database insertions*/ 
  foo->insert(key,pay);
  foo->insert(key3,pay3);
  foo->insert(key1,pay1);
  foo->insert(key5,pay5);
  foo->insert(key2,pay2);
  foo->insert(key4,pay4);
  

/*  cout << "main: " << *(int *)key1 << ","<< *(int *)key <<","<< (char *)(key1 + 4) <<","<<(char *)(key + 4) << ","<<*(int *)(key1 + 12)\
    << "," << *(int *)(key + 12) << endl; */
  // cout << "Comparing in Test :" << compareKeys(key2,key3,keytype) << endl;
  // cout << (char *)(key1 + 4) << " "<< (char *)(key + 4) << endl;
/*
  byte * res= new byte;
  foo->lookup(key3,res);
  cout << res[0] << endl;

  foo->lookup(key,res);
  cout << res[0] << endl;

  foo->lookup(key5,res);
  cout << res[0] << endl;
*/
  foo->closeIndex();
  return 0;
}