Esempio n. 1
0
void feeFEEDExpFree(feeFEEDExp feed)
{
	feedInst *finst = (feedInst *) feed;

	free_key(finst->plus);
	free_key(finst->minus);
	freeGiant(finst->xc);
	clearGiant(finst->xp); freeGiant(finst->xp);
	clearGiant(finst->xq); freeGiant(finst->xq);
	freeGiant(finst->xm);
	clearGiant(finst->xaux); freeGiant(finst->xaux);
	if(finst->gPriv) {
		clearGiant(finst->gPriv);
		freeGiant(finst->gPriv);
	}
	if(finst->rand) {
		feeRandFree(finst->rand);
	}
	if(finst->randData) {
		ffree(finst->randData);
	}
	if(finst->cp) {
		freeCurveParams(finst->cp);
	}
	ffree(finst);
}
Esempio n. 2
0
/**
 * u2fs_free_reg_res:
 * @result: a registration result as generated by u2fs_registration_verify()
 *
 * Deallocate resources associated with @result.
 */
void u2fs_free_reg_res(u2fs_reg_res_t * result)
{
  if (result != NULL) {
    if (result->keyHandle) {
      free(result->keyHandle);
      result->keyHandle = NULL;
    }
    if (result->publicKey) {
      free(result->publicKey);
      result->publicKey = NULL;
    }
    if (result->attestation_certificate_PEM) {
      free(result->attestation_certificate_PEM);
      result->attestation_certificate_PEM = NULL;
    }
    if (result->user_public_key) {
      free_key(result->user_public_key);
      result->user_public_key = NULL;
    }
    if (result->attestation_certificate) {
      free_cert(result->attestation_certificate);
      result->attestation_certificate = NULL;
    }
    free(result);
  }
}
Esempio n. 3
0
/* Recursively free all the splaynodes */
static inline int free_splaynode(splaynode_t * splaynode, void (*free_key)()) {

  /* Ok if this happens, a recursive base case */
  if (splaynode == NULL)
    return SUCCESS;

  /* Free left node */
  free_splaynode(splaynode->left, free_key);
  
  /* Free right node */
  free_splaynode(splaynode->right, free_key);
  
  /* Free this node's key */
  free_key(splaynode->key);
  
  /* Note that the data pointers are not freed here.
     Should be freed with a splay traversal function */
  
  /* Free the splaynode structure itself */
  free(splaynode);
 
  /* Finished, return success */
  return SUCCESS;

}
Esempio n. 4
0
static void free_item(genhash_t *h, struct genhash_entry_t *i)
{
    cb_assert(i);
    free_key(h, i->key);
    free_value(h, i->value);
    free(i);
}
Esempio n. 5
0
BL_ShapeDeformer::~BL_ShapeDeformer()
{
	if (m_key && m_bmesh->key)
	{
		free_key(m_bmesh->key);
		m_bmesh->key = m_key;
	}
};
Esempio n. 6
0
void _free_keys(GdkDisplay* gdisplay,
		GdkWindow* groot,
		HotkeyEntry* hotkeys,
		guint num_hotkeys)
{
    guint i;

    for (i = 0; i < num_hotkeys; ++i)
	free_key(gdisplay, groot, hotkeys + i);
}
Esempio n. 7
0
void
free_keys (vector vec)
{
	int i;
	struct key * kw;

	vector_foreach_slot (vec, kw, i)
		free_key(kw);

	vector_free(vec);
}
static void pubKeyInstFree(pubKeyInst *pkinst)
{
	if(pkinst->minus) {
		free_key(pkinst->minus);
	}
	if(pkinst->plus) {
		free_key(pkinst->plus);
	}
	if(pkinst->cp) {
		freeCurveParams(pkinst->cp);
	}
	if(pkinst->privGiant) {
		/*
		 * Zero out the private data...
		 */
		clearGiant(pkinst->privGiant);
		freeGiant(pkinst->privGiant);
	}
	ffree(pkinst);
}
Esempio n. 9
0
void free_keys(struct cgfs_files **keys)
{
	int i;

	if (!keys)
		return;
	for (i = 0; keys[i]; i++) {
		free_key(keys[i]);
	}
	free(keys);
}
Esempio n. 10
0
int
remove_key (KeyType_t type, EventType_t event_type, KeySym keysym, KeyCode keycode,
	    unsigned int button, unsigned int modifier)
{
  int i, found_index = -1;
  Keys_t *keys_bis = NULL;

  if (keys == NULL)
    {
      return (-1);
    }
  
  modifier &= ~(numlock_mask | capslock_mask | scrolllock_mask);

  for (i = 0; i < nb_keys; i++)
    {
      if (keys[i].type == type &&
	  keys[i].event_type == event_type &&
	  keys[i].modifier == modifier &&
	  ((type == SYM && keys[i].key.sym == keysym) ||
	   (type == CODE && keys[i].key.code == keycode) ||
	   (type == BUTTON && keys[i].key.button == button)))
	found_index = i;
    }

  if (found_index != -1)
    {
      if (verbose)
	printf ("Removing key index %d\n", found_index);
  
      /* make new array keys_bis */
      keys_bis = (Keys_t *) g_malloc ((nb_keys - 1) * sizeof (Keys_t));
      if (keys_bis == NULL)
	return (-1);

      for (i = 0; i < found_index; i++)
	keys_bis[i] = keys[i];
      
      for (i = found_index + 1; i < nb_keys; i++)
	keys_bis[i - 1] = keys[i];

      free_key (&keys[found_index]);
      g_free (keys);

      /* make keys_bis as keys */
      keys = keys_bis;

      nb_keys -= 1;
    }

  return (0);
}
void load_key(void){
	uint8_t r;
	if(keys_allocated){
		cli_putstr_P(PSTR("\r\nDBG: freeing old keys"));
		free_key();
	}
	keys_allocated = 1;
	r = read_key_crt();
	if(r){
		cli_putstr_P(PSTR("\r\nERROR: read_key_crt returned 0x"));
		cli_hexdump_byte(r);
	}
}
Esempio n. 12
0
OM_uint32
gss_krb5_free_lucid_sec_context(OM_uint32 *minor_status, void *c)
{
    gss_krb5_lucid_context_v1_t *ctx = c;

    if (ctx->version != 1) {
	if (minor_status)
	    *minor_status = 0;
	return GSS_S_FAILURE;
    }

    if (ctx->protocol == 0) {
	free_key(&ctx->rfc1964_kd.ctx_key);
    } else if (ctx->protocol == 1) {
	free_key(&ctx->cfx_kd.ctx_key);
	if (ctx->cfx_kd.have_acceptor_subkey)
	    free_key(&ctx->cfx_kd.acceptor_subkey);
    }
    free(ctx);
    if (minor_status)
	*minor_status = 0;
    return GSS_S_COMPLETE;
}
Esempio n. 13
0
/**
 * u2fs_done:
 * @ctx: a context handle, from u2fs_init()
 *
 * Deallocate resources associated with context @ctx.
 */
void u2fs_done(u2fs_ctx_t * ctx)
{
  if (ctx == NULL)
    return;

  free(ctx->keyHandle);
  ctx->keyHandle = NULL;
  free_key(ctx->key);
  ctx->key = NULL;
  free(ctx->origin);
  ctx->origin = NULL;
  free(ctx->appid);
  ctx->appid = NULL;
  free(ctx);
}
Esempio n. 14
0
void
close_keys (void)
{
  int i;

  for (i = 0; i < nb_keys; i++)
    free_key (&keys[i]);

  if (keys != NULL)
    {
      g_free (keys);
      keys = NULL;
    }

  nb_keys = 0;
}
Esempio n. 15
0
/**
 * u2fs_set_publicKey:
 * @ctx: a context handle, from u2fs_init()
 * @publicKey: a 65-byte raw EC public key as returned from registration.
 *
 * Decode @publicKey and store within @ctx. If a value is already
 * present, it is cleared and the memory is released.
 *
 * Returns: On success %U2FS_OK (integer 0) is returned, and on errors
 * a #u2fs_rc error code.
 */
u2fs_rc
u2fs_set_publicKey(u2fs_ctx_t * ctx, const unsigned char *publicKey)
{
  u2fs_EC_KEY_t *user_key;
  u2fs_rc rc;

  if (ctx == NULL || publicKey == NULL)
    return U2FS_MEMORY_ERROR;

  rc = decode_user_key(publicKey, &user_key);
  if (rc != U2FS_OK)
    return rc;

  if (ctx->key != NULL)
    free_key(ctx->key);

  ctx->key = user_key;

  return U2FS_OK;
}
Esempio n. 16
0
void
_ojc_val_destroy(ojcVal val, List freed, MList freed_bstrs) {
    free_key(val, freed_bstrs);
    if (OJC_STRING == val->type || OJC_NUMBER == val->type) {
	switch (val->str_type) {
	case STR_PTR:
	    free(val->str.str);
	    break;
	case STR_BLOCK:
	    if (0 == freed_bstrs->head) {
		freed_bstrs->head = val->str.bstr;
	    } else {
		freed_bstrs->tail->next = val->str.bstr;
	    }
	    val->str.bstr->next = 0;
	    freed_bstrs->tail = val->str.bstr;
	    break;
	default:
	    break;
	}
    }
    if (OJC_ARRAY == val->type || OJC_OBJECT == val->type) {
	ojcVal	m;
	ojcVal	next;

	for (m = val->members.head; 0 != m; m = next) {
	    next = m->next;
	    _ojc_val_destroy(m, freed, freed_bstrs);
	}
    }
    if (0 == freed->head) {
	freed->head = val;
    } else {
	freed->tail->next = val;
    }
    val->next = 0;
    val->type = OJC_NULL;
    val->str_type = STR_NONE;
    val->key_type = STR_NONE;
    freed->tail = val;
}
Esempio n. 17
0
void
hash_table_free(struct hash_table *hash_table, void (*free_key)(void *), void (*free_data)(void *))
{
	int i;

	for (i = 0; i < hash_table->nbuckets; i++) {
		struct hash_table_entry *p, *n;

		for (p = hash_table->buckets[i]; p; p = n) {
			n = p->next;

			if (free_key)
				free_key(p->key);

			if (free_data)
				free_data(p->value);

			free(p);
		}
	}
}
void load_fix_rsa(void){
	if(keys_allocated){
		free_key();
	}
	keys_allocated = 1;

	if(pre_alloc_key_crt()){
		cli_putstr_P(PSTR("\r\nOOM!\r\n"));
		return;
	}

	load_bigint_from_os(&pub_key.modulus, MODULUS, sizeof(MODULUS));
	memcpy(&priv_key.modulus, &pub_key.modulus, sizeof(bigint_t));
	load_bigint_from_os(&pub_key.exponent, PUB_EXPONENT, sizeof(PUB_EXPONENT));
	priv_key.n = 5;
	load_bigint_from_os(&(priv_key.components[0]), P, sizeof(P));
	load_bigint_from_os(&(priv_key.components[1]), Q, sizeof(Q));
	load_bigint_from_os(&(priv_key.components[2]), DP, sizeof(DP));
	load_bigint_from_os(&(priv_key.components[3]), DQ, sizeof(DQ));
	load_bigint_from_os(&(priv_key.components[4]), QINV, sizeof(QINV));
}
Esempio n. 19
0
File: parse.c Progetto: Ri0n/libotr
/* Parse a D-H Key Message into a newly-allocated KeyMsg structure */
KeyMsg parse_key(const char *msg)
{
    KeyMsg kmsg = NULL;
    size_t lenp;
    unsigned char *raw = decode(msg, &lenp);
    unsigned char *bufp = raw;
    if (!raw) goto inv;

    kmsg = calloc(1, sizeof(struct s_KeyMsg));
    if (!kmsg) {
	free(raw);
	goto inv;
    }

    kmsg->raw = raw;

    require_len(3);

    kmsg->version = bufp[1];

    if (!memcmp(bufp, "\x00\x03\x0a", 3)) {
	bufp += 3; lenp -= 3;
	read_int(kmsg->sender_instance);
	read_int(kmsg->receiver_instance);
    } else if (!memcmp(bufp, "\x00\x02\x0a", 3)) {
	bufp += 3; lenp -= 3;
	kmsg->sender_instance = 0;
	kmsg->receiver_instance = 0;
    } else goto inv;

    read_mpi(kmsg->y);

    if (lenp != 0) goto inv;

    return kmsg;
inv:
    free_key(kmsg);
    return NULL;
}
Esempio n. 20
0
File: hash.c Progetto: kosmix/ferret
void h_clear(Hash *self)
{
    int i;
    HashEntry *he;
    free_ft free_key   = self->free_key_i;
    free_ft free_value = self->free_value_i;

    /* Clear all the hash values and keys as necessary */
    if (free_key != dummy_free || free_value != dummy_free) {
        for (i = 0; i <= self->mask; i++) {
            he = &self->table[i];
            if (he->key != NULL && he->key != dummy_key) {
                free_value(he->value);
                free_key(he->key);
            }
            he->key = NULL;
        }
    }
    ZEROSET_N(self->table, HashEntry, self->mask + 1);
    self->size = 0;
    self->fill = 0;
}
Esempio n. 21
0
void
_ojc_set_key(ojcVal val, const char *key, int klen) {
    struct _MList	freed_bstrs = { 0, 0 };

    free_key(val, &freed_bstrs);
    while (atomic_flag_test_and_set(&free_bstrs.busy)) {
    }
    if (0 != freed_bstrs.head) {
	if (0 == free_bstrs.head) {
	    free_bstrs.head = freed_bstrs.head;
	} else {
	    free_bstrs.tail->next = freed_bstrs.head;
	}
	free_bstrs.tail = freed_bstrs.tail;
    }
    atomic_flag_clear(&free_bstrs.busy);

    if (0 != key) {
	if (0 >= klen) {
	    klen = strlen(key);
	}
	if ((int)sizeof(union _Bstr) <= klen) {
	    val->key_type = STR_PTR;
	    val->key.str = strndup(key, klen);
	    val->key.str[klen] = '\0';
	} else if ((int)sizeof(val->key.ca) <= klen) {
	    val->key_type = STR_BLOCK;
	    val->key.bstr = _ojc_bstr_create();
	    memcpy(val->key.bstr->ca, key, klen);
	    val->key.bstr->ca[klen] = '\0';
	} else {
	    val->key_type = STR_ARRAY;
	    memcpy(val->key.ca, key, klen);
	    val->key.ca[klen] = '\0';
	}
    }
}
Esempio n. 22
0
int main(int argc, char *argv[])
{
    int retval = EXIT_FAILURE;
    int long_opt_index = 0, display_info = 0, display_public_cert = 0, update_db = 0, quiet = 0;
    char c = 0;
    char *pcap_filter = NULL, *pcap_file = NULL, *pcap_interface = NULL, *update_db_outfile = NULL;
    struct keymaster certinfo = { 0 };
    struct option long_options[] = {
        { "fingerprint", required_argument, NULL, 'f' },
        { "pem", required_argument, NULL, 'p'  },
        { "host", required_argument, NULL, 'r' },
        { "pcap", required_argument, NULL, 'c' },
        { "interface", required_argument, NULL, 'i' },
        { "search", required_argument, NULL, 's' },
        { "filter", required_argument, NULL, 'l' },
        { "keypair", no_argument, NULL, 'k' },
        { "info", no_argument, NULL, 'v' },
        { "quiet", no_argument, NULL, 'q' },
        { "update", optional_argument, NULL, 'u' },
        { "help", no_argument, NULL, 'h' },
        { 0,    0,    0,    0   }
    };
    char *short_options = "f:p:r:c:i:s:l:u::kvqh";

    if(argc < MIN_ARGS)
    {
        usage(argv[0]);
        goto end;
    }

    while((c = getopt_long(argc,argv,short_options, long_options, &long_opt_index)) != -1)
    {
        switch(c)
        {
        case 'c':
            if(optarg) pcap_file = strdup(optarg);
            break;
        case 'f':
            if(optarg) certinfo.fingerprint = strdup(optarg);
            break;
        case 'p':
            if(optarg) certinfo.fingerprint = fingerprint_pem_file(optarg);
            break;
        case 'r':
            if(optarg) certinfo.fingerprint = fingerprint_host(optarg);
            break;
        case 'i':
            if(optarg) pcap_interface = strdup(optarg);
            break;
        case 'l':
            if(optarg) pcap_filter = strdup(optarg);
            break;
        case 's':
            if(optarg) print_search_results(optarg);
            break;
        case 'u':
            update_db = 1;
            if(optarg) update_db_outfile = strdup(optarg);
            else update_db_outfile = strdup(DB_NAME);
            break;
        case 'k':
            display_public_cert = 1;
            break;
        case 'v':
            display_info = 1;
            break;
        case 'q':
            quiet = 1;
            break;
        default:
            usage(argv[0]);
            goto end;
        }
    }

    /* Update the certificate database */
    if(update_db)
    {
        fprintf(stderr, "Updating %s from %s...", update_db_outfile, DB_UPDATE_URL);
        if(!update_database(DB_UPDATE_URL, update_db_outfile))
        {
            fprintf(stderr, "update failed!\n");
            goto end;
        } else {
            fprintf(stderr, "done.\n");
            goto success;
        }
    }

    /* If no filter was specified, use the default */
    if(pcap_filter == NULL)
    {
        pcap_filter = strdup(DEFAULT_FILTER);
    }

    /* Do raw traffic capture if specified */
    if(pcap_file != NULL)
    {
        certinfo.fingerprint = sniff(pcap_file, pcap_filter, PFILE);
    } else if(pcap_interface != NULL) {
        certinfo.fingerprint = sniff(pcap_interface, pcap_filter, IFACE);
    }

    /* Make sure we have a fingerprint */
    if(!certinfo.fingerprint)
    {
        fprintf(stderr, "No suitable certificate fingerprint provided!\n");
        goto end;
    }

    /* Try to lookup the private key that corresponds to this certificate */
    if(!lookup_key(&certinfo) || certinfo.key == NULL)
    {
        fprintf(stderr, "ERROR: Failed to locate a matching private certificate for fingerprint: %s\n", certinfo.fingerprint);
        goto end;
    }

    /* Display private key */
    if(!quiet)
    {
        printf("%s\n", certinfo.key);
    }

    /* Display public key */
    if(display_public_cert)
    {
        printf("%s\n", certinfo.certificate);
    }

    /* Show all certificate info for this cert */
    if(display_info)
    {
        print_all_cert_info(&certinfo);
    }

success:
    retval = EXIT_SUCCESS;
end:
    free_key(&certinfo);
    if(update_db_outfile) free(update_db_outfile);
    if(pcap_file) free(pcap_file);
    if(pcap_interface) free(pcap_interface);
    if(pcap_filter) free(pcap_filter);
    return retval;
}
Esempio n. 23
0
/*
 * Free an entire 'struct conf_entry' and its dynamic data.
 */
static void free_entry(struct conf_entry *entry)
{
    free_key(&entry->key);
    free_value(&entry->value, valuetypes[entry->key.primary]);
    sfree(entry);
}
Esempio n. 24
0
int join_mesh_exec(bContext *C, wmOperator *op)
{
	Main *bmain= CTX_data_main(C);
	Scene *scene= CTX_data_scene(C);
	Object *ob= CTX_data_active_object(C);
	Material **matar, *ma;
	Mesh *me;
	MVert *mvert, *mv;
	MEdge *medge = NULL;
	MFace *mface = NULL;
	Key *key, *nkey=NULL;
	KeyBlock *kb, *okb, *kbn;
	float imat[4][4], cmat[4][4], *fp1, *fp2, curpos;
	int a, b, totcol, totmat=0, totedge=0, totvert=0, totface=0, ok=0;
	int vertofs, *matmap=NULL;
	int	i, j, index, haskey=0, edgeofs, faceofs;
	bDeformGroup *dg, *odg;
	MDeformVert *dvert;
	CustomData vdata, edata, fdata;

	if(scene->obedit) {
		BKE_report(op->reports, RPT_WARNING, "Cant join while in editmode");
		return OPERATOR_CANCELLED;
	}
	
	/* ob is the object we are adding geometry to */
	if(!ob || ob->type!=OB_MESH) {
		BKE_report(op->reports, RPT_WARNING, "Active object is not a mesh");
		return OPERATOR_CANCELLED;
	}
	
	/* count & check */
	CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
		if(base->object->type==OB_MESH) {
			me= base->object->data;
			
			totvert+= me->totvert;
			totedge+= me->totedge;
			totface+= me->totface;
			totmat+= base->object->totcol;
			
			if(base->object == ob)
				ok= 1;
			
			/* check for shapekeys */
			if(me->key)
				haskey++;
		}
	}
	CTX_DATA_END;
	
	/* that way the active object is always selected */ 
	if(ok==0) {
		BKE_report(op->reports, RPT_WARNING, "Active object is not a selected mesh");
		return OPERATOR_CANCELLED;
	}
	
	/* only join meshes if there are verts to join, there aren't too many, and we only had one mesh selected */
	me= (Mesh *)ob->data;
	key= me->key;

	if(totvert==0 || totvert==me->totvert) {
		BKE_report(op->reports, RPT_WARNING, "No mesh data to join");
		return OPERATOR_CANCELLED;
	}
	
	if(totvert > MESH_MAX_VERTS) {
		BKE_reportf(op->reports, RPT_WARNING, "Joining results in %d vertices, limit is " STRINGIFY(MESH_MAX_VERTS), totvert);
		return OPERATOR_CANCELLED;		
	}

	/* new material indices and material array */
	matar= MEM_callocN(sizeof(void*)*totmat, "join_mesh matar");
	if (totmat) matmap= MEM_callocN(sizeof(int)*totmat, "join_mesh matmap");
	totcol= ob->totcol;
	
	/* obact materials in new main array, is nicer start! */
	for(a=0; a<ob->totcol; a++) {
		matar[a]= give_current_material(ob, a+1);
		id_us_plus((ID *)matar[a]);
		/* increase id->us : will be lowered later */
	}
	
	/* - if destination mesh had shapekeys, move them somewhere safe, and set up placeholders
	 * 	with arrays that are large enough to hold shapekey data for all meshes
	 * -	if destination mesh didn't have shapekeys, but we encountered some in the meshes we're 
	 *	joining, set up a new keyblock and assign to the mesh
	 */
	if(key) {
		/* make a duplicate copy that will only be used here... (must remember to free it!) */
		nkey= copy_key(key);
		
		/* for all keys in old block, clear data-arrays */
		for(kb= key->block.first; kb; kb= kb->next) {
			if(kb->data) MEM_freeN(kb->data);
			kb->data= MEM_callocN(sizeof(float)*3*totvert, "join_shapekey");
			kb->totelem= totvert;
			kb->weights= NULL;
		}
	}
	else if(haskey) {
		/* add a new key-block and add to the mesh */
		key= me->key= add_key((ID *)me);
		key->type = KEY_RELATIVE;
	}
	
	/* first pass over objects - copying materials and vertexgroups across */
	CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
		/* only act if a mesh, and not the one we're joining to */
		if((ob!=base->object) && (base->object->type==OB_MESH)) {
			me= base->object->data;
			
			/* Join this object's vertex groups to the base one's */
			for(dg=base->object->defbase.first; dg; dg=dg->next) {
				/* See if this group exists in the object (if it doesn't, add it to the end) */
				if(!defgroup_find_name(ob, dg->name)) {
					odg = MEM_callocN(sizeof(bDeformGroup), "join deformGroup");
					memcpy(odg, dg, sizeof(bDeformGroup));
					BLI_addtail(&ob->defbase, odg);
				}
			}
			if(ob->defbase.first && ob->actdef==0)
				ob->actdef=1;
			
			
			if(me->totvert) {
				/* Add this object's materials to the base one's if they don't exist already (but only if limits not exceeded yet) */
				if(totcol < MAXMAT) {
					for(a=1; a<=base->object->totcol; a++) {
						ma= give_current_material(base->object, a);

						for(b=0; b<totcol; b++) {
							if(ma == matar[b]) break;
						}
						if(b==totcol) {
							matar[b]= ma;
							if(ma) {
								id_us_plus(&ma->id);
							}
							totcol++;
						}
						if(totcol >= MAXMAT)
							break;
					}
				}
				
				/* if this mesh has shapekeys, check if destination mesh already has matching entries too */
				if(me->key && key) {
					for(kb= me->key->block.first; kb; kb= kb->next) {
						/* if key doesn't exist in destination mesh, add it */
						if(key_get_named_keyblock(key, kb->name) == NULL) {
							/* copy this existing one over to the new shapekey block */
							kbn= MEM_dupallocN(kb);
							kbn->prev= kbn->next= NULL;
							
							/* adjust adrcode and other settings to fit (allocate a new data-array) */
							kbn->data= MEM_callocN(sizeof(float)*3*totvert, "joined_shapekey");
							kbn->totelem= totvert;
							kbn->weights= NULL;
							
							okb= key->block.last;
							curpos= (okb) ? okb->pos : -0.1f;
							if(key->type == KEY_RELATIVE)
								kbn->pos= curpos + 0.1f;
							else
								kbn->pos= curpos;
							
							BLI_addtail(&key->block, kbn);
							kbn->adrcode= key->totkey;
							key->totkey++;
							if(key->totkey==1) key->refkey= kbn;
							
							// XXX 2.5 Animato
#if 0
							/* also, copy corresponding ipo-curve to ipo-block if applicable */
							if(me->key->ipo && key->ipo) {
								// FIXME... this is a luxury item!
								puts("FIXME: ignoring IPO's when joining shapekeys on Meshes for now...");
							}
#endif
						}
					}
				}
			}
		}
	}
	CTX_DATA_END;
	
	/* setup new data for destination mesh */
	memset(&vdata, 0, sizeof(vdata));
	memset(&edata, 0, sizeof(edata));
	memset(&fdata, 0, sizeof(fdata));
	
	mvert= CustomData_add_layer(&vdata, CD_MVERT, CD_CALLOC, NULL, totvert);
	medge= CustomData_add_layer(&edata, CD_MEDGE, CD_CALLOC, NULL, totedge);
	mface= CustomData_add_layer(&fdata, CD_MFACE, CD_CALLOC, NULL, totface);

	vertofs= 0;
	edgeofs= 0;
	faceofs= 0;
	
	/* inverse transform for all selected meshes in this object */
	invert_m4_m4(imat, ob->obmat);
	
	CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
		/* only join if this is a mesh */
		if(base->object->type==OB_MESH) {
			me= base->object->data;
			
			if(me->totvert) {
				/* standard data */
				CustomData_merge(&me->vdata, &vdata, CD_MASK_MESH, CD_DEFAULT, totvert);
				CustomData_copy_data(&me->vdata, &vdata, 0, vertofs, me->totvert);
				
				/* vertex groups */
				dvert= CustomData_get(&vdata, vertofs, CD_MDEFORMVERT);
				
				/* NB: vertex groups here are new version */
				if(dvert) {
					for(i=0; i<me->totvert; i++) {
						for(j=0; j<dvert[i].totweight; j++) {
							/*	Find the old vertex group */
							odg = BLI_findlink(&base->object->defbase, dvert[i].dw[j].def_nr);
							if(odg) {
								/*	Search for a match in the new object, and set new index */
								for(dg=ob->defbase.first, index=0; dg; dg=dg->next, index++) {
									if(!strcmp(dg->name, odg->name)) {
										dvert[i].dw[j].def_nr = index;
										break;
									}
								}
							}
						}
					}
				}
				
				/* if this is the object we're merging into, no need to do anything */
				if(base->object != ob) {
					/* watch this: switch matmul order really goes wrong */
					mul_m4_m4m4(cmat, base->object->obmat, imat);
					
					/* transform vertex coordinates into new space */
					for(a=0, mv=mvert; a < me->totvert; a++, mv++) {
						mul_m4_v3(cmat, mv->co);
					}
					
					/* for each shapekey in destination mesh:
					 *	- if there's a matching one, copy it across (will need to transform vertices into new space...)
					 *	- otherwise, just copy own coordinates of mesh (no need to transform vertex coordinates into new space)
					 */
					if(key) {
						/* if this mesh has any shapekeys, check first, otherwise just copy coordinates */
						for(kb= key->block.first; kb; kb= kb->next) {
							/* get pointer to where to write data for this mesh in shapekey's data array */
							fp1= ((float *)kb->data) + (vertofs*3);	
							
							/* check if this mesh has such a shapekey */
							okb= key_get_named_keyblock(me->key, kb->name);
							if(okb) {
								/* copy this mesh's shapekey to the destination shapekey (need to transform first) */
								fp2= ((float *)(okb->data));
								for(a=0; a < me->totvert; a++, fp1+=3, fp2+=3) {
									VECCOPY(fp1, fp2);
									mul_m4_v3(cmat, fp1);
								}
							}
							else {
								/* copy this mesh's vertex coordinates to the destination shapekey */
								mv= mvert;
								for(a=0; a < me->totvert; a++, fp1+=3, mv++) {
									VECCOPY(fp1, mv->co);
								}
							}
						}
					}
				}
				else {
					/* for each shapekey in destination mesh:
					 *	- if it was an 'original', copy the appropriate data from nkey
					 *	- otherwise, copy across plain coordinates (no need to transform coordinates)
					 */
					if(key) {
						for(kb= key->block.first; kb; kb= kb->next) {
							/* get pointer to where to write data for this mesh in shapekey's data array */
							fp1= ((float *)kb->data) + (vertofs*3);	
							
							/* check if this was one of the original shapekeys */
							okb= key_get_named_keyblock(nkey, kb->name);
							if(okb) {
								/* copy this mesh's shapekey to the destination shapekey */
								fp2= ((float *)(okb->data));
								for(a=0; a < me->totvert; a++, fp1+=3, fp2+=3) {
									VECCOPY(fp1, fp2);
								}
							}
							else {
								/* copy base-coordinates to the destination shapekey */
								mv= mvert;
								for(a=0; a < me->totvert; a++, fp1+=3, mv++) {
									VECCOPY(fp1, mv->co);
								}
							}
						}
					}
				}
				
				/* advance mvert pointer to end of base mesh's data */
				mvert+= me->totvert;
			}
			
			if(me->totface) {
				/* make mapping for materials */
				for(a=1; a<=base->object->totcol; a++) {
					ma= give_current_material(base->object, a);

					for(b=0; b<totcol; b++) {
						if(ma == matar[b]) {
							matmap[a-1]= b;
							break;
						}
					}
				}
				
				if(base->object!=ob)
					multiresModifier_prepare_join(scene, base->object, ob);

				CustomData_merge(&me->fdata, &fdata, CD_MASK_MESH, CD_DEFAULT, totface);
				CustomData_copy_data(&me->fdata, &fdata, 0, faceofs, me->totface);
				
				for(a=0; a<me->totface; a++, mface++) {
					mface->v1+= vertofs;
					mface->v2+= vertofs;
					mface->v3+= vertofs;
					if(mface->v4) mface->v4+= vertofs;
					
					if (matmap)
						mface->mat_nr= matmap[(int)mface->mat_nr];
					else 
						mface->mat_nr= 0;
				}
				
				faceofs += me->totface;
			}
			
			if(me->totedge) {
				CustomData_merge(&me->edata, &edata, CD_MASK_MESH, CD_DEFAULT, totedge);
				CustomData_copy_data(&me->edata, &edata, 0, edgeofs, me->totedge);
				
				for(a=0; a<me->totedge; a++, medge++) {
					medge->v1+= vertofs;
					medge->v2+= vertofs;
				}
				
				edgeofs += me->totedge;
			}
			
			/* vertofs is used to help newly added verts be reattached to their edge/face 
			 * (cannot be set earlier, or else reattaching goes wrong)
			 */
			vertofs += me->totvert;
			
			/* free base, now that data is merged */
			if(base->object != ob)
				ED_base_object_free_and_unlink(bmain, scene, base);
		}
	}
	CTX_DATA_END;
	
	/* return to mesh we're merging to */
	me= ob->data;
	
	CustomData_free(&me->vdata, me->totvert);
	CustomData_free(&me->edata, me->totedge);
	CustomData_free(&me->fdata, me->totface);

	me->totvert= totvert;
	me->totedge= totedge;
	me->totface= totface;
	
	me->vdata= vdata;
	me->edata= edata;
	me->fdata= fdata;

	mesh_update_customdata_pointers(me);
	
	/* old material array */
	for(a=1; a<=ob->totcol; a++) {
		ma= ob->mat[a-1];
		if(ma) ma->id.us--;
	}
	for(a=1; a<=me->totcol; a++) {
		ma= me->mat[a-1];
		if(ma) ma->id.us--;
	}
	if(ob->mat) MEM_freeN(ob->mat);
	if(ob->matbits) MEM_freeN(ob->matbits);
	if(me->mat) MEM_freeN(me->mat);
	ob->mat= me->mat= NULL;
	ob->matbits= NULL;
	
	if(totcol) {
		me->mat= matar;
		ob->mat= MEM_callocN(sizeof(void *)*totcol, "join obmatar");
		ob->matbits= MEM_callocN(sizeof(char)*totcol, "join obmatbits");
	}
	else
		MEM_freeN(matar);
	
	ob->totcol= me->totcol= totcol;
	ob->colbits= 0;

	if (matmap) MEM_freeN(matmap);
	
	/* other mesh users */
	test_object_materials((ID *)me);
	
	/* free temp copy of destination shapekeys (if applicable) */
	if(nkey) {
		// XXX 2.5 Animato
#if 0
		/* free it's ipo too - both are not actually freed from memory yet as ID-blocks */
		if(nkey->ipo) {
			free_ipo(nkey->ipo);
			BLI_remlink(&bmain->ipo, nkey->ipo);
			MEM_freeN(nkey->ipo);
		}
#endif
		
		free_key(nkey);
		BLI_remlink(&bmain->key, nkey);
		MEM_freeN(nkey);
	}
	
	DAG_scene_sort(bmain, scene);	// removed objects, need to rebuild dag before editmode call

#if 0
	ED_object_enter_editmode(C, EM_WAITCURSOR);
	ED_object_exit_editmode(C, EM_FREEDATA|EM_WAITCURSOR|EM_DO_UNDO);
#else
	/* toggle editmode using lower level functions so this can be called from python */
	make_editMesh(scene, ob);
	load_editMesh(scene, ob);
	free_editMesh(me->edit_mesh);
	MEM_freeN(me->edit_mesh);
	me->edit_mesh= NULL;
	DAG_id_tag_update(&ob->id, OB_RECALC_OB|OB_RECALC_DATA);
#endif
	WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);

	return OPERATOR_FINISHED;
}
Esempio n. 25
0
/**
 * u2fs_registration_verify:
 * @ctx: a context handle, from u2fs_init().
 * @response: a U2F registration response message Base64 encoded.
 * @output: pointer to output structure containing the relevant data for a well formed request. Memory should be free'd.
 *
 * Get a U2F registration response and check its validity.
 *
 * Returns: On success %U2FS_OK (integer 0) is returned and @output is filled up with the user public key, the key handle and the attestation certificate. On errors
 * a #u2fs_rc error code.
 */
u2fs_rc u2fs_registration_verify(u2fs_ctx_t * ctx, const char *response,
                                 u2fs_reg_res_t ** output)
{
  char *registrationData;
  char *clientData;
  char *clientData_decoded;
  unsigned char *user_public_key;
  size_t keyHandle_len;
  char *keyHandle;
  char *origin;
  char *challenge;
  char buf[_B64_BUFSIZE];
  unsigned char c = 0;
  u2fs_X509_t *attestation_certificate;
  u2fs_ECDSA_t *signature;
  u2fs_EC_KEY_t *key;
  u2fs_rc rc;

  if (ctx == NULL || response == NULL || output == NULL)
    return U2FS_MEMORY_ERROR;

  key = NULL;
  clientData_decoded = NULL;
  challenge = NULL;
  origin = NULL;
  attestation_certificate = NULL;
  user_public_key = NULL;
  signature = NULL;
  registrationData = NULL;
  clientData = NULL;
  keyHandle = NULL;
  *output = NULL;

  rc = parse_registration_response(response, &registrationData,
                                   &clientData);
  if (rc != U2FS_OK)
    goto failure;

  if (debug) {
    fprintf(stderr, "registrationData: %s\n", registrationData);
    fprintf(stderr, "clientData: %s\n", clientData);
  }

  rc = parse_registrationData(registrationData, &user_public_key,
                              &keyHandle_len, &keyHandle,
                              &attestation_certificate, &signature);
  if (rc != U2FS_OK)
    goto failure;

  rc = extract_EC_KEY_from_X509(attestation_certificate, &key);

  if (rc != U2FS_OK)
    goto failure;

  //TODO Add certificate validation

  rc = decode_clientData(clientData, &clientData_decoded);

  if (rc != U2FS_OK)
    goto failure;

  rc = parse_clientData(clientData_decoded, &challenge, &origin);

  if (rc != U2FS_OK)
    goto failure;

  if (strcmp(ctx->challenge, challenge) != 0) {
    rc = U2FS_CHALLENGE_ERROR;
    goto failure;
  }

  if (strcmp(ctx->origin, origin) != 0) {
    rc = U2FS_ORIGIN_ERROR;
    goto failure;
  }

  struct sha256_state sha_ctx;
  char challenge_parameter[U2FS_HASH_LEN],
      application_parameter[U2FS_HASH_LEN];

  sha256_init(&sha_ctx);
  sha256_process(&sha_ctx, (unsigned char *) ctx->appid,
                 strlen(ctx->appid));
  sha256_done(&sha_ctx, (unsigned char *) application_parameter);

  sha256_init(&sha_ctx);
  sha256_process(&sha_ctx, (unsigned char *) clientData_decoded,
                 strlen(clientData_decoded));
  sha256_done(&sha_ctx, (unsigned char *) challenge_parameter);

  unsigned char dgst[U2FS_HASH_LEN];
  sha256_init(&sha_ctx);
  sha256_process(&sha_ctx, &c, 1);
  sha256_process(&sha_ctx, (unsigned char *) application_parameter,
                 U2FS_HASH_LEN);
  sha256_process(&sha_ctx, (unsigned char *) challenge_parameter,
                 U2FS_HASH_LEN);
  sha256_process(&sha_ctx, (unsigned char *) keyHandle, keyHandle_len);
  sha256_process(&sha_ctx, user_public_key, U2FS_PUBLIC_KEY_LEN);
  sha256_done(&sha_ctx, dgst);

  rc = verify_ECDSA(dgst, U2FS_HASH_LEN, signature, key);

  if (rc != U2FS_OK)
    goto failure;

  free_sig(signature);
  signature = NULL;

  *output = calloc(1, sizeof(**output));
  if (*output == NULL) {
    rc = U2FS_MEMORY_ERROR;
    goto failure;
  }

  rc = encode_b64u(keyHandle, keyHandle_len, buf);
  if (rc != U2FS_OK)
    goto failure;

  u2fs_EC_KEY_t *key_ptr;
  (*output)->keyHandle = strndup(buf, strlen(buf));

  rc = decode_user_key(user_public_key, &key_ptr);
  if (rc != U2FS_OK)
    goto failure;

  (*output)->attestation_certificate = dup_cert(attestation_certificate);

  rc = dump_user_key(key_ptr, &(*output)->publicKey);
  if (rc != U2FS_OK)
    goto failure;

  rc = dump_X509_cert(attestation_certificate, &(*output)->attestation_certificate_PEM);
  if (rc != U2FS_OK)
    goto failure;

  if ((*output)->keyHandle == NULL
      || (*output)->publicKey == NULL
      || (*output)->attestation_certificate == NULL) {
    rc = U2FS_MEMORY_ERROR;
    goto failure;
  }

  free_key(key);
  key = NULL;

  free_cert(attestation_certificate);
  attestation_certificate = NULL;

  free(clientData_decoded);
  clientData_decoded = NULL;

  free(challenge);
  challenge = NULL;

  free(origin);
  origin = NULL;

  free(user_public_key);
  user_public_key = NULL;

  free(registrationData);
  registrationData = NULL;

  free(clientData);
  clientData = NULL;

  free(keyHandle);
  keyHandle = NULL;

  return U2FS_OK;

failure:
  if (key) {
    free_key(key);
    key = NULL;
  }

  if (clientData_decoded) {
    free(clientData_decoded);
    clientData_decoded = NULL;
  }

  if (challenge) {
    free(challenge);
    challenge = NULL;
  }

  if (origin) {
    free(origin);
    origin = NULL;
  }

  if (attestation_certificate) {
    free_cert(attestation_certificate);
    attestation_certificate = NULL;
  }

  if (user_public_key) {
    free(user_public_key);
    user_public_key = NULL;
  }

  if (signature) {
    free_sig(signature);
    signature = NULL;
  }

  if (registrationData) {
    free(registrationData);
    registrationData = NULL;
  }

  if (clientData) {
    free(clientData);
    clientData = NULL;
  }

  if (keyHandle) {
    free(keyHandle);
    keyHandle = NULL;
  }

  return rc;
}
Esempio n. 26
0
/* used in headerbuttons.c image.c mesh.c screen.c sound.c and library.c */
void free_libblock(ListBase *lb, void *idv)
{
	ID *id= idv;

#ifdef WITH_PYTHON
	BPY_id_release(id);
#endif

	switch( GS(id->name) ) {	/* GetShort from util.h */
		case ID_SCE:
			free_scene((Scene *)id);
			break;
		case ID_LI:
			free_library((Library *)id);
			break;
		case ID_OB:
			free_object((Object *)id);
			break;
		case ID_ME:
			free_mesh((Mesh *)id);
			break;
		case ID_CU:
			free_curve((Curve *)id);
			break;
		case ID_MB:
			free_mball((MetaBall *)id);
			break;
		case ID_MA:
			free_material((Material *)id);
			break;
		case ID_TE:
			free_texture((Tex *)id);
			break;
		case ID_IM:
			free_image((Image *)id);
			break;
		case ID_LT:
			free_lattice((Lattice *)id);
			break;
		case ID_LA:
			free_lamp((Lamp *)id);
			break;
		case ID_CA:
			free_camera((Camera*) id);
			break;
		case ID_IP:
			free_ipo((Ipo *)id);
			break;
		case ID_KE:
			free_key((Key *)id);
			break;
		case ID_WO:
			free_world((World *)id);
			break;
		case ID_SCR:
			free_screen((bScreen *)id);
			break;
		case ID_VF:
			free_vfont((VFont *)id);
			break;
		case ID_TXT:
			free_text((Text *)id);
			break;
		case ID_SCRIPT:
			//XXX free_script((Script *)id);
			break;
		case ID_SPK:
			free_speaker((Speaker *)id);
			break;
		case ID_SO:
			sound_free((bSound*)id);
			break;
		case ID_GR:
			free_group_objects((Group *)id);
			break;
		case ID_AR:
			free_armature((bArmature *)id);
			break;
		case ID_AC:
			free_action((bAction *)id);
			break;
		case ID_NT:
			ntreeFreeTree((bNodeTree *)id);
			break;
		case ID_BR:
			free_brush((Brush *)id);
			break;
		case ID_PA:
			psys_free_settings((ParticleSettings *)id);
			break;
		case ID_WM:
			if(free_windowmanager_cb)
				free_windowmanager_cb(NULL, (wmWindowManager *)id);
			break;
		case ID_GD:
			free_gpencil_data((bGPdata *)id);
			break;
	}

	if (id->properties) {
		IDP_FreeProperty(id->properties);
		MEM_freeN(id->properties);
	}

	BLI_remlink(lb, id);

	/* this ID may be a driver target! */
	BKE_animdata_main_cb(G.main, animdata_dtar_clear_cb, (void *)id);

	MEM_freeN(id);
}
Esempio n. 27
0
void mexFunction( int nlhs, mxArray *plhs[],
		  int nrhs, const mxArray *prhs[] )
{
	int mrows, ncols;
	int        i, j, k;
	double 	*volume;
	double	*matrix;
    extern rational *pivotrow;
    extern T_LassInt *All_index;
    extern T_LassInt *Pivot;
    extern int **p2c;
    extern rational *A;
    extern rational  * planescopy;
    extern T_Tree  *tree_volumes;
    extern T_Key key;

	/* Check for proper number of arguments. */
	if (nrhs != 1)
	{
		mexErrMsgTxt("One input required.");
	} else if (nlhs > 1)
	{
		mexErrMsgTxt("Too many output arguments");
	}

	/* the input must be a non complex m by 4 matrix */
	mrows = mxGetM(prhs[0]);
	ncols = mxGetN(prhs[0]);
	if (ncols != 4 || !mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]))
	{
		mexErrMsgTxt("Input must be a noncomplex m by 4 double matrix");
	}

	/* Set up the return argument matrix */
	plhs[0] = mxCreateDoubleMatrix(1,1, mxREAL);

	/* The output goes in *volume */
	volume = mxGetPr(plhs[0]);

	/* Get pointer to the right hand side */
	matrix = mxGetPr(prhs[0]);

	/* Set global variables */
	G_m = mrows;
	G_d = ncols - 1;
	create_hyperplanes (); /* allocates space for hyperplanes */

	/* needs to be changed to read data from the array, or use the array(better) */
	k=0;
	for (i = 0; i < G_m; i++)
    {
		G_Hyperplanes [i] [G_d] = matrix[k++];
	}
	for (i=0; i < G_m; i++)
	{
		G_Hyperplanes [i] [0] = -matrix[k++];
	}
	for (i=0; i < G_m; i++)
	{
		G_Hyperplanes [i] [1] = -matrix[k++];
	}
	for (i=0; i < G_m; i++)
	{
		G_Hyperplanes [i] [2] = -matrix[k++];
	}

	if (G_Storage > G_d - 3)
	  G_Storage = G_d - 3;
	  /* necessary to prevent memory waste because in the tree arrays of length */
	  /* G_Storage + 2 are allocated                                          */

	pivotrow = (rational *) my_malloc ((G_d + 1) * sizeof (rational));
	All_index = (T_LassInt *) my_malloc ((G_m + 1) * sizeof (T_LassInt));
	Pivot = (T_LassInt *) my_malloc ((G_d + 1) * sizeof (T_LassInt));
	p2c = (int **) my_malloc (G_d * sizeof (int *));
	for (i=0; i<G_d; i++){
	   p2c[i] = (int *) my_malloc (2 * sizeof (int));
	}
	A=compact();
	planescopy=compact();
	tree_volumes = NULL;
	create_key (&key, KEY_PLANES_VAR);
	key.hypervar.hyperplanes [0] = G_m + 1;
	key.hypervar.variables [0] = G_d + 1;
	All_index[0]=G_m+2;  /* initialization (end mark) */
	Pivot[0]=G_m+2;	/* initialization (end mark) */
	*volume = lass (A, G_m-1, G_d);

	/* Deallocate memory (didn't work?)*/
	free_key (key, KEY_PLANES_VAR);
	my_free(planescopy, G_m*(G_d+1)*sizeof(rational));
	my_free(A, G_m*(G_d+1)*sizeof(rational));
	for (i=0; i<G_d; i++){
		my_free(p2c[i], 2 * sizeof (int));
	}
	my_free(p2c, G_d * sizeof (int *));
	my_free(Pivot, (G_d + 1) * sizeof (T_LassInt));
	my_free(All_index,(G_m + 1) * sizeof (T_LassInt));
	my_free(pivotrow, (G_d + 1) * sizeof (rational));
	free_hyperplanes ();
}