void mbl_mw_ibeacon_set_minor_signal(MblMwMetaWearBoard *board, const MblMwDataSignal* minor) { EventDataParameter signal_data_token= {minor->length(), minor->offset, 0}; set_data_token(board, &signal_data_token); mbl_mw_ibeacon_set_minor(board, 0); clear_data_token(board); }
/** * Stores the information of token contained in spam message. */ int store_spam(void *dbp, void *token){ /* If the token is the empty word or count token it can't be stored.*/ if(strcmp(token,INIT_TOKEN) && strcmp((char *)token,COUNT_TOKEN)){ //printf("STORE_SPAM %s\n",(char *)token); char *hashkey=get_hash(token); if (hashkey==NULL){ wblprintf(LOG_CRITICAL,"LEARN_BAYES","Could not compute message digest\n"); return MAP_MISSING; } else{ //printf("STORE_SPAM 2\n"); DBT key, data; memset(&key,0,sizeof(DBT)); memset(&data,0,sizeof(DBT)); key.data = hashkey; key.size = sizeof(char)*strlen(hashkey)+1; //printf("STORE_SPAM 3\n"); if(((DB *)dbp)->get((DB *)dbp,NULL,&key,&data,0)==DB_NOTFOUND){ tokendata *dat=NULL;//malloc(sizeof(tokendata)); /* Stores the token and initializes to one its number of spam messages and to zero the number of ham messages*/ set_data_token(&dat,0,1); data.data=dat; data.size=sizeof(tokendata); ((DB *)dbp)->put((DB* )dbp, NULL, &key, &data, DB_NOOVERWRITE); free(dat); } else{ //printf("STORE_SPAM 4 - SI ESTA BD\n"); /* Increases by one the number of spam messages.*/ ((tokendata *)data.data)->spam_count+=1; ((DB *)dbp)->del((DB *)dbp,NULL,&key,0); ((DB *)dbp)->put((DB *)dbp,NULL,&key,&data,DB_NOOVERWRITE); wblprintf(LOG_DEBUG,"LEARN_BAYES","Word (%s) update\n",(char *)key.data); } free(hashkey); } } return MAP_OK; }
/** * Stores a struct with the number of spam and ham messages in a database. */ void store_magic_token(DB * dbp, int type){ char *hashkey=get_hash(MAGIC_TOKEN); if (hashkey==NULL){ wblprintf(LOG_CRITICAL,"LEARN_BAYES","Could not compute message digest\n"); exit(1); } else{ DBT key, data; memset(&key,0,sizeof(DBT)); memset(&data,0,sizeof(DBT)); /* The key is the hash of the empty word.*/ key.data = hashkey; key.size = sizeof(char)*strlen(hashkey)+1; if(dbp->get(dbp,NULL,&key,&data,0)==DB_NOTFOUND){ tokendata *dat=NULL;//malloc(sizeof(tokendata)); (type==OPT_SPAM)?(set_data_token(&dat,0,1)):(set_data_token(&dat,1,0)); data.data=dat; data.size=sizeof(tokendata); dbp->put(dbp, NULL, &key, &data, DB_NOOVERWRITE); free(dat); } else{ (type==OPT_HAM)?(((tokendata *)data.data)->ham_count+=1):(((tokendata *)data.data)->spam_count+=1); dbp->del((DB *)dbp,NULL,&key,0); dbp->put((DB *)dbp,NULL,&key,&data,DB_NOOVERWRITE); } } free(hashkey); }