static void nick_2_cont (void *cls, int32_t success, const char *emsg) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Nick added : %s\n", (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); GNUNET_asprintf(&s_name_1, "dummy1"); s_rd_1 = create_record(1); GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_1, 1, s_rd_1, &put_cont, NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); GNUNET_asprintf(&s_name_2, "dummy2"); s_rd_2 = create_record(1); GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_2, 1, s_rd_2, &put_cont, NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n"); /* name in different zone */ GNUNET_asprintf(&s_name_3, "dummy3"); s_rd_3 = create_record(1); GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3, 1, s_rd_3, &put_cont, NULL); }
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) { char *hostkey_file; struct GNUNET_TIME_Absolute et; endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,&endbadly, NULL); GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); privkey = GNUNET_CRYPTO_rsa_key_create_from_file(hostkey_file); GNUNET_free (hostkey_file); GNUNET_assert (privkey != NULL); GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey); GNUNET_CRYPTO_hash(&pubkey, sizeof (pubkey), &zone); GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); privkey2 = GNUNET_CRYPTO_rsa_key_create_from_file(hostkey_file); GNUNET_free (hostkey_file); GNUNET_assert (privkey2 != NULL); GNUNET_CRYPTO_rsa_key_get_public(privkey2, &pubkey2); GNUNET_CRYPTO_hash(&pubkey2, sizeof (pubkey), &zone2); nsh = GNUNET_NAMESTORE_connect (cfg); GNUNET_break (NULL != nsh); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); GNUNET_asprintf(&s_name_1, "dummy1"); s_rd_1 = create_record(1); et.abs_value = s_rd_1[0].expiration_time; sig_1 = GNUNET_NAMESTORE_create_signature(privkey, et, s_name_1, s_rd_1, 1); GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_1, s_rd_1, &put_cont, NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); GNUNET_asprintf(&s_name_2, "dummy2"); s_rd_2 = create_record(1); et.abs_value = s_rd_2[0].expiration_time; sig_2 = GNUNET_NAMESTORE_create_signature(privkey, et, s_name_2, s_rd_2, 1); GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_2, s_rd_2, &put_cont, NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n"); /* name in different zone */ GNUNET_asprintf(&s_name_3, "dummy3"); s_rd_3 = create_record(1); et.abs_value = s_rd_3[0].expiration_time; sig_3 = GNUNET_NAMESTORE_create_signature(privkey2, et, s_name_3, s_rd_3, 1); GNUNET_NAMESTORE_record_put (nsh, &pubkey2, s_name_3, GNUNET_TIME_UNIT_FOREVER_ABS, 1, s_rd_3, sig_3, &put_cont, NULL); }
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_GNSRECORD_Block *block; struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; /* load privat key */ char *hostkey_file; GNUNET_asprintf(&hostkey_file, "zonefiles%s%s", DIR_SEPARATOR_STR, "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s'\n", hostkey_file); privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); GNUNET_free (hostkey_file); GNUNET_assert (privkey != NULL); struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get(); /* get public key */ GNUNET_CRYPTO_ecdsa_key_get_public(privkey, &pubkey); /* create record */ s_name = "DUMMY.dummy.gnunet"; s_rd = create_record (RECORDS); /* Create block */ GNUNET_assert (NULL != (block = GNUNET_GNSRECORD_block_create (privkey, expire,s_name, s_rd, RECORDS))); GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_verify (block)); GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt (block, &pubkey, s_name, &rd_decrypt_cb, s_name)); GNUNET_free (block); }
static struct a2dp_sep *a2dp_add_sep(DBusConnection *conn, uint8_t type, uint8_t codec) { struct a2dp_sep *sep; GSList **l; sdp_record_t *(*create_record)(void); uint32_t *record_id; sdp_record_t *record; struct avdtp_sep_ind *ind; sep = g_new0(struct a2dp_sep, 1); ind = (codec == A2DP_CODEC_MPEG12) ? &mpeg_ind : &sbc_ind; sep->sep = avdtp_register_sep(type, AVDTP_MEDIA_TYPE_AUDIO, codec, ind, &cfm, sep); if (sep->sep == NULL) { g_free(sep); return NULL; } sep->codec = codec; sep->type = type; if (type == AVDTP_SEP_TYPE_SOURCE) { l = &sources; create_record = a2dp_source_record; record_id = &source_record_id; } else { l = &sinks; create_record = a2dp_sink_record; record_id = &sink_record_id; } if (*record_id != 0) goto add; record = create_record(); if (!record) { error("Unable to allocate new service record"); avdtp_unregister_sep(sep->sep); g_free(sep); return NULL; } if (add_record_to_server(BDADDR_ANY, record) < 0) { error("Unable to register A2DP service record");\ sdp_record_free(record); avdtp_unregister_sep(sep->sep); g_free(sep); return NULL; } *record_id = record->handle; add: *l = g_slist_append(*l, sep); return sep; }
bool GqRecordALSA::start_record() { create_record(); snd_pcm_hw_params_free(m_hw_params); int err = -1; if ((err = snd_pcm_prepare(m_pcapture_handle)) < 0) { fprintf(stderr, "cannot prepare audio interface for use (%s)\n", snd_strerror(err)); exit(1); } pthread_create(&m_ptd_record, NULL, fn_record, this); return true; }
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { delete_existing_db(cfg); endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); size_t rd_ser_len; /* load privat key from file not included in zonekey dir */ privkey = GNUNET_CRYPTO_rsa_key_create_from_file("test_hostkey"); GNUNET_assert (privkey != NULL); /* get public key */ GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey); /* create record */ s_name = "dummy.dummy.gnunet"; s_rd = create_record (RECORDS); rd_ser_len = GNUNET_NAMESTORE_records_get_size(RECORDS, s_rd); char rd_ser[rd_ser_len]; GNUNET_NAMESTORE_records_serialize(RECORDS, s_rd, rd_ser_len, rd_ser); /* sign */ s_signature = GNUNET_NAMESTORE_create_signature(privkey, s_rd[0].expiration, s_name, s_rd, RECORDS); /* create random zone hash */ GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone); start_arm (cfgfile); GNUNET_assert (arm != NULL); nsh = GNUNET_NAMESTORE_connect (cfg); GNUNET_break (NULL != nsh); GNUNET_break (s_rd != NULL); GNUNET_break (s_name != NULL); GNUNET_NAMESTORE_record_put (nsh, &pubkey, s_name, GNUNET_TIME_UNIT_FOREVER_ABS, RECORDS, s_rd, s_signature, put_cont, s_name); }
/* void add_mime_media_record(stru_message *message, char *mimeType, unsigned char *payload) { unsigned char payloadBytes[strlen(payload) + 1]; memcpy(payloadBytes, payload,strlen(payload)); stru_record *record = create_record(); set_tnf(record, TNF_MIME_MEDIA); unsigned char type[strlen(mimeType) + 1]; memcpy(type, mimeType, strlen(mimeType)); set_type(record, type, strlen(mimeType)); set_payload(record, payloadBytes, strlen(payload)); add_record(message, record); } */ void add_text_record(stru_message *message, char *text) { stru_record *record = create_record(); set_tnf(record, TNF_WELL_KNOWN); unsigned char RTD_TEXT[1] = { 0x54 }; // this should be a constant or preprocessor set_type(record, RTD_TEXT, sizeof(RTD_TEXT)); // X is a placeholder for encoding length // is it more efficient to build w/o string concatenation? unsigned char payload[strlen(text) + 4]; payload[strlen(text) + 3] = '\0'; memcpy(payload, "Xen", 3); memcpy(payload + 3, text, strlen(text)); // replace X with the real encoding length payload[0] = 2; set_payload(record, payload, strlen(text) + 3); add_record(message, record); }
/** * Callback called from the zone iterator when we iterate over * the empty zone. Check that we got no records and then * start the actual tests by filling the zone. */ static void empty_zone_proc (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd) { char *hostkey_file; GNUNET_assert (nsh == cls); if (NULL != zone) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Expected empty zone but received zone private key\n")); GNUNET_break (0); if (endbadly_task != NULL) GNUNET_SCHEDULER_cancel (endbadly_task); endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); return; } if ((NULL != label) || (NULL != rd) || (0 != rd_count)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Expected no zone content but received data\n")); GNUNET_break (0); if (endbadly_task != NULL) GNUNET_SCHEDULER_cancel (endbadly_task); endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); return; } zi = NULL; GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); GNUNET_free (hostkey_file); GNUNET_assert (privkey != NULL); GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); GNUNET_free (hostkey_file); GNUNET_assert (privkey2 != NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); GNUNET_asprintf(&s_name_1, "dummy1"); s_rd_1 = create_record(1); GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1, 1, s_rd_1, &put_cont, NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); GNUNET_asprintf(&s_name_2, "dummy2"); s_rd_2 = create_record(1); GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2, 1, s_rd_2, &put_cont, NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n"); /* name in different zone */ GNUNET_asprintf(&s_name_3, "dummy3"); s_rd_3 = create_record(1); GNUNET_NAMESTORE_records_store(nsh, privkey2, s_name_3, 1, s_rd_3, &put_cont, NULL); }
int main(int argc, char *argv[]) { MI_INFO *file; int i,j; MY_INIT(argv[0]); get_options(argc,argv); bzero((char*)recinfo,sizeof(recinfo)); /* First define 2 columns */ recinfo[0].type=FIELD_SKIP_ENDSPACE; recinfo[0].length=docid_length; recinfo[1].type=FIELD_BLOB; recinfo[1].length= 4+portable_sizeof_char_ptr; /* Define a key over the first column */ keyinfo[0].seg=keyseg; keyinfo[0].keysegs=1; keyinfo[0].block_length= 0; /* Default block length */ keyinfo[0].seg[0].type= HA_KEYTYPE_TEXT; keyinfo[0].seg[0].flag= HA_BLOB_PART; keyinfo[0].seg[0].start=recinfo[0].length; keyinfo[0].seg[0].length=key_length; keyinfo[0].seg[0].null_bit=0; keyinfo[0].seg[0].null_pos=0; keyinfo[0].seg[0].bit_start=4; keyinfo[0].seg[0].language=MY_CHARSET_CURRENT; keyinfo[0].flag = HA_FULLTEXT; if (!silent) printf("- Creating isam-file\n"); if (mi_create(filename,1,keyinfo,2,recinfo,0,NULL,(MI_CREATE_INFO*) 0,0)) goto err; if (!(file=mi_open(filename,2,0))) goto err; if (!silent) printf("Initializing stopwords\n"); ft_init_stopwords(stopwordlist); if (!silent) printf("- Writing key:s\n"); my_errno=0; i=0; while (create_record(record,df)) { error=mi_write(file,record); if (error) printf("I= %2d mi_write: %d errno: %d\n",i,error,my_errno); i++; } fclose(df); if (mi_close(file)) goto err; if (!silent) printf("- Reopening file\n"); if (!(file=mi_open(filename,2,0))) goto err; if (!silent) printf("- Reading rows with key\n"); for (i=1;create_record(record,qf);i++) { FT_DOCLIST *result; double w; int t, err; result=ft_nlq_init_search(file,0,blob_record,(uint) strlen(blob_record),1); if (!result) { printf("Query %d failed with errno %3d\n",i,my_errno); goto err; } if (!silent) printf("Query %d. Found: %d.\n",i,result->ndocs); for (j=0;(err=ft_nlq_read_next(result, read_record))==0;j++) { t=uint2korr(read_record); w=ft_nlq_get_relevance(result); printf("%d %.*s %f\n",i,t,read_record+2,w); } if (err != HA_ERR_END_OF_FILE) { printf("ft_read_next %d failed with errno %3d\n",j,my_errno); goto err; } ft_nlq_close_search(result); } if (mi_close(file)) goto err; my_end(MY_CHECK_ERROR); return (0); err: printf("got error: %3d when using myisam-database\n",my_errno); return 1; /* skip warning */ }
ERRORCODE Database::new_record(DB_RECORD_TYPE type, VOIDPTR creation_data, DatabaseRecordPtr far *record) { ERRORCODE error; DB_RECORD_NUMBER number; // Always want to be exclusive. storage_manager.SetExclusive(TRUE); /* The record should start out as NULL as an additional check. */ *record = NULL; /* Allocate a new entry. */ if ((error = table_manager.allocate_entry(&number, type)) == ERRORCODE_None) { RECORD_FILE_ENTRY far *fentry; RECORD_MEMORY_ENTRY far *mentry; /* Lock the entry. */ if ((error = table_manager.lock_entry(number, &fentry, &mentry)) == ERRORCODE_None) { if ((error = create_record(type, number, creation_data, &fentry->position, record)) == ERRORCODE_None) { /* Remember this for later. */ // TRACE("new_record allocated entry %ld (%d)\n", (*record)->Id(), (*record)->type()); mentry->data = *record; /* Start us off right. */ if (storage_manager.IsSharing()) { error = mentry->data->write(); } if (error == ERRORCODE_None) { mentry->data->ModifyLock(); mentry->data->ElementModified(); } else { /* Unable to write. */ delete mentry->data; mentry->data = *record = NULL; } } if (error != ERRORCODE_None) { /* Error clean up. */ table_manager.unlock_entry(number); table_manager.deallocate_entry(number); } } } storage_manager.SetExclusive(FALSE); #ifdef DATABASE_STATISTICS if (error == ERRORCODE_None) { if( type < RECORD_TYPE_ProjectPreview || type > RECORD_TYPE_Component ) { m_lCreateRecord[0]++; } else { m_lCreateRecord[type]++; } } #endif return error; }
stru_message *create_message_b(const unsigned char* data, const int numBytes) { stru_message *message = &message_buffer; //message = (stru_message *)malloc(sizeof(stru_message)); int index = 0; message->recordCount = 0; while(index <= numBytes) { // decode tnf - first byte is tnf with bit flags // see the NFDEF spec for more info unsigned char tnf_byte = data[index]; bool mb = (tnf_byte & 0x80) != 0; bool me = (tnf_byte & 0x40) != 0; bool cf = (tnf_byte & 0x20) != 0; bool sr = (tnf_byte & 0x10) != 0; bool il = (tnf_byte & 0x8) != 0; unsigned char tnf = (tnf_byte & 0x7); stru_record *record = create_record(); set_tnf(record, tnf); index++; int typeLength = data[index]; int payloadLength = 0; if(sr) { index++; payloadLength = data[index]; } else { payloadLength =((0xFF & data[++index]) << 24) | ((0xFF & data[++index]) << 16) | ((0xFF & data[++index]) << 8) | (0xFF & data[++index]); } int idLength = 0; if(il) { index++; idLength = data[index]; } index++; set_type(record, &data[index], typeLength); index += typeLength; if(il) { set_id(record, &data[index], idLength); index += idLength; } set_payload(record, &data[index], payloadLength); index += payloadLength; add_record(message, record); if(me)break; // last message } return message; }
/* void add_uri_record(stru_message *message, char *uri) { stru_record *record = create_record(); set_tnf(record, TNF_WELL_KNOWN); unsigned char RTD_URI[1] = { 0x55 }; // this should be a constant or preprocessor set_type(record, RTD_URI, sizeof(RTD_URI)); // X is a placeholder for identifier code unsigned char payload[strlen(uri) + 2]; memcpy(payload, "X", 1); memcpy(payload + 1, uri, strlen(uri)); // add identifier code 0x0, meaning no prefix substitution payload[0] = 0x0; set_payload(record, payload, strlen(uri) + 1); add_record(message, record); } */ void add_empty_record(stru_message *message) { stru_record *record = create_record(); set_tnf(record, TNF_EMPTY); add_record(message, record); }
static int run_test(const char *filename) { MARIA_HA *file; int i,j= 0,error,deleted,rec_length,uniques=0; uint offset_to_key; ha_rows found,row_count; uchar record[MAX_REC_LENGTH],key[MAX_REC_LENGTH],read_record[MAX_REC_LENGTH]; MARIA_UNIQUEDEF uniquedef; MARIA_CREATE_INFO create_info; if (die_in_middle_of_transaction) null_fields= 1; bzero((char*) recinfo,sizeof(recinfo)); bzero((char*) &create_info,sizeof(create_info)); /* First define 2 columns */ create_info.null_bytes= 1; recinfo[0].type= key_field; recinfo[0].length= (key_field == FIELD_BLOB ? 4+portable_sizeof_char_ptr : key_length); if (key_field == FIELD_VARCHAR) recinfo[0].length+= HA_VARCHAR_PACKLENGTH(key_length); recinfo[1].type=extra_field; recinfo[1].length= (extra_field == FIELD_BLOB ? 4 + portable_sizeof_char_ptr : 24); if (extra_field == FIELD_VARCHAR) recinfo[1].length+= HA_VARCHAR_PACKLENGTH(recinfo[1].length); recinfo[1].null_bit= null_fields ? 2 : 0; if (opt_unique) { recinfo[2].type=FIELD_CHECK; recinfo[2].length=MARIA_UNIQUE_HASH_LENGTH; } rec_length= recinfo[0].length + recinfo[1].length + recinfo[2].length + create_info.null_bytes; if (key_type == HA_KEYTYPE_VARTEXT1 && key_length > 255) key_type= HA_KEYTYPE_VARTEXT2; /* Define a key over the first column */ keyinfo[0].seg=keyseg; keyinfo[0].keysegs=1; keyinfo[0].block_length= 0; /* Default block length */ keyinfo[0].key_alg=HA_KEY_ALG_BTREE; keyinfo[0].seg[0].type= key_type; keyinfo[0].seg[0].flag= pack_seg; keyinfo[0].seg[0].start=1; keyinfo[0].seg[0].length=key_length; keyinfo[0].seg[0].null_bit= null_fields ? 2 : 0; keyinfo[0].seg[0].null_pos=0; keyinfo[0].seg[0].language= default_charset_info->number; if (pack_seg & HA_BLOB_PART) { keyinfo[0].seg[0].bit_start=4; /* Length of blob length */ } keyinfo[0].flag = (uint8) (pack_keys | unique_key); bzero((uchar*) flags,sizeof(flags)); if (opt_unique) { uint start; uniques=1; bzero((char*) &uniquedef,sizeof(uniquedef)); bzero((char*) uniqueseg,sizeof(uniqueseg)); uniquedef.seg=uniqueseg; uniquedef.keysegs=2; /* Make a unique over all columns (except first NULL fields) */ for (i=0, start=1 ; i < 2 ; i++) { uniqueseg[i].start=start; start+=recinfo[i].length; uniqueseg[i].length=recinfo[i].length; uniqueseg[i].language= default_charset_info->number; } uniqueseg[0].type= key_type; uniqueseg[0].null_bit= null_fields ? 2 : 0; uniqueseg[1].type= HA_KEYTYPE_TEXT; if (extra_field == FIELD_BLOB) { uniqueseg[1].length=0; /* The whole blob */ uniqueseg[1].bit_start=4; /* long blob */ uniqueseg[1].flag|= HA_BLOB_PART; } else if (extra_field == FIELD_VARCHAR) { uniqueseg[1].flag|= HA_VAR_LENGTH_PART; uniqueseg[1].type= (HA_VARCHAR_PACKLENGTH(recinfo[1].length-1) == 1 ? HA_KEYTYPE_VARTEXT1 : HA_KEYTYPE_VARTEXT2); } } else uniques=0; offset_to_key= MY_TEST(null_fields); if (key_field == FIELD_BLOB || key_field == FIELD_VARCHAR) offset_to_key+= 2; if (!silent) printf("- Creating maria file\n"); create_info.max_rows=(ulong) (rec_pointer_size ? (1L << (rec_pointer_size*8))/40 : 0); create_info.transactional= transactional; if (maria_create(filename, record_type, 1, keyinfo,2+opt_unique,recinfo, uniques, &uniquedef, &create_info, create_flag)) goto err; if (!(file=maria_open(filename,2,HA_OPEN_ABORT_IF_LOCKED))) goto err; if (!silent) printf("- Writing key:s\n"); if (maria_begin(file)) goto err; if (opt_versioning) maria_versioning(file, 1); my_errno=0; row_count=deleted=0; for (i=49 ; i>=1 ; i-=2 ) { if (insert_count-- == 0) { if (testflag) break; maria_close(file); exit(0); } j=i%25 +1; create_record(record,j); error=maria_write(file,record); if (!error) row_count++; flags[j]=1; if (verbose || error) printf("J= %2d maria_write: %d errno: %d\n", j,error,my_errno); } if (maria_commit(file) || maria_begin(file)) goto err; if (checkpoint == 1 && ma_checkpoint_execute(CHECKPOINT_MEDIUM, FALSE)) goto err; if (testflag == 1) goto end; /* Insert 2 rows with null values */ if (null_fields) { create_record(record,0); error=maria_write(file,record); if (!error) row_count++; if (verbose || error) printf("J= NULL maria_write: %d errno: %d\n", error,my_errno); error=maria_write(file,record); if (!error) row_count++; if (verbose || error) printf("J= NULL maria_write: %d errno: %d\n", error,my_errno); flags[0]=2; } if (checkpoint == 2 && ma_checkpoint_execute(CHECKPOINT_MEDIUM, FALSE)) goto err; if (testflag == 2) { printf("Terminating after inserts\n"); goto end; } if (maria_commit(file) || maria_begin(file)) goto err; if (!skip_update) { if (opt_unique) { if (!silent) printf("- Checking unique constraint\n"); create_record(record,j); /* Check last created row */ if (!maria_write(file,record) || my_errno != HA_ERR_FOUND_DUPP_UNIQUE) { printf("unique check failed\n"); } } if (!silent) printf("- Updating rows\n"); /* Update first last row to force extend of file */ if (maria_rsame(file,read_record,-1)) { printf("Can't find last row with maria_rsame\n"); } else { memcpy(record,read_record,rec_length); update_record(record); if (maria_update(file,read_record,record)) { printf("Can't update last row: %.*s\n", keyinfo[0].seg[0].length,read_record+1); } } /* Read through all rows and update them */ maria_scan_init(file); found=0; while ((error= maria_scan(file,read_record)) == 0) { if (--update_count == 0) { maria_close(file); exit(0) ; } memcpy(record,read_record,rec_length); update_record(record); if (maria_update(file,read_record,record)) { printf("Can't update row: %.*s, error: %d\n", keyinfo[0].seg[0].length,record+1,my_errno); } found++; } if (found != row_count) printf("Found %ld of %ld rows\n", (ulong) found, (ulong) row_count); maria_scan_end(file); } if (checkpoint == 3 && ma_checkpoint_execute(CHECKPOINT_MEDIUM, FALSE)) goto err; if (testflag == 3) { printf("Terminating after updates\n"); goto end; } if (!silent) printf("- Reopening file\n"); if (maria_commit(file)) goto err; if (maria_close(file)) goto err; if (!(file=maria_open(filename,2,HA_OPEN_ABORT_IF_LOCKED))) goto err; if (maria_begin(file)) goto err; if (opt_versioning) maria_versioning(file, 1); if (!skip_delete) { if (!silent) printf("- Removing keys\n"); for (i=0 ; i <= 10 ; i++) { /* If you want to debug the problem in ma_test_recovery with BLOBs (see @todo there), you can break out of the loop after just one delete, it is enough, like this: if (i==1) break; */ /* testing */ if (remove_count-- == 0) { fprintf(stderr, "delete-rows number of rows deleted; Going down hard!\n"); goto end; } j=i*2; if (!flags[j]) continue; create_key(key,j); my_errno=0; if ((error = maria_rkey(file, read_record, 0, key, HA_WHOLE_KEY, HA_READ_KEY_EXACT))) { if (verbose || (flags[j] >= 1 || (error && my_errno != HA_ERR_KEY_NOT_FOUND))) printf("key: '%.*s' maria_rkey: %3d errno: %3d\n", (int) key_length,key+offset_to_key,error,my_errno); } else { error=maria_delete(file,read_record); if (verbose || error) printf("key: '%.*s' maria_delete: %3d errno: %3d\n", (int) key_length, key+offset_to_key, error, my_errno); if (! error) { deleted++; flags[j]--; } } } } if (checkpoint == 4 && ma_checkpoint_execute(CHECKPOINT_MEDIUM, FALSE)) goto err; if (testflag == 4) { printf("Terminating after deletes\n"); goto end; } if (!silent) printf("- Reading rows with key\n"); record[1]= 0; /* For nicer printf */ if (record_type == NO_RECORD) maria_extra(file, HA_EXTRA_KEYREAD, 0); for (i=0 ; i <= 25 ; i++) { create_key(key,i); my_errno=0; error=maria_rkey(file,read_record,0,key,HA_WHOLE_KEY,HA_READ_KEY_EXACT); if (verbose || (error == 0 && flags[i] == 0 && unique_key) || (error && (flags[i] != 0 || my_errno != HA_ERR_KEY_NOT_FOUND))) { printf("key: '%.*s' maria_rkey: %3d errno: %3d record: %s\n", (int) key_length,key+offset_to_key,error,my_errno,record+1); } } if (record_type == NO_RECORD) { maria_extra(file, HA_EXTRA_NO_KEYREAD, 0); goto end; } if (!silent) printf("- Reading rows with position\n"); if (maria_scan_init(file)) { fprintf(stderr, "maria_scan_init failed\n"); goto err; } for (i=1,found=0 ; i <= 30 ; i++) { my_errno=0; if ((error= maria_scan(file, read_record)) == HA_ERR_END_OF_FILE) { if (found != row_count-deleted) printf("Found only %ld of %ld rows\n", (ulong) found, (ulong) (row_count - deleted)); break; } if (!error) found++; if (verbose || (error != 0 && error != HA_ERR_RECORD_DELETED && error != HA_ERR_END_OF_FILE)) { printf("pos: %2d maria_rrnd: %3d errno: %3d record: %s\n", i-1,error,my_errno,read_record+1); } } maria_scan_end(file); end: if (die_in_middle_of_transaction) { /* As commit record is not done, UNDO entries needs to be rolled back */ switch (die_in_middle_of_transaction) { case 1: /* Flush changed pages go to disk. That will also flush log. Recovery will skip REDOs and apply UNDOs. */ _ma_flush_table_files(file, MARIA_FLUSH_DATA | MARIA_FLUSH_INDEX, FLUSH_RELEASE, FLUSH_RELEASE); break; case 2: /* Just flush log. Pages are likely to not be on disk. Recovery will then execute REDOs and UNDOs. */ if (translog_flush(file->trn->undo_lsn)) goto err; break; case 3: /* Flush nothing. Pages and log are likely to not be on disk. Recovery will then do nothing. */ break; case 4: /* Flush changed data pages go to disk. Changed index pages are not flushed. Recovery will skip some REDOs and apply UNDOs. */ _ma_flush_table_files(file, MARIA_FLUSH_DATA, FLUSH_RELEASE, FLUSH_RELEASE); /* We have to flush log separately as the redo for the last key page may not be flushed */ if (translog_flush(file->trn->undo_lsn)) goto err; break; } printf("Dying on request without maria_commit()/maria_close()\n"); sf_leaking_memory= 1; exit(0); } if (maria_commit(file)) goto err; if (maria_close(file)) goto err; maria_end(); my_uuid_end(); my_end(MY_CHECK_ERROR); return (0); err: printf("got error: %3d when using maria-database\n",my_errno); return 1; /* skip warning */ }
DatabaseRecordPtr Database::get_record(DB_RECORD_NUMBER number, LPERRORCODE e, DB_RECORD_TYPE type, BOOL read_only) { RECORD_FILE_ENTRY far *fentry; RECORD_MEMORY_ENTRY far *mentry; ERRORCODE error; DatabaseRecordPtr record = NULL; // Always want to be exclusive. storage_manager.SetExclusive(TRUE); // TRACE("get_record: %ld, %d, %d\n", number, type, read_only); /* Lock the entry. */ if ((error = table_manager.lock_entry(number, &fentry, &mentry, read_only)) == ERRORCODE_None) { /* Do some type checking. */ if (type != DB_ANY_TYPE && type != fentry->type) { table_manager.unlock_entry(number, read_only, FALSE); error = ERRORCODE_TypeMismatch; } else { /* // Make sure we have the record in memory. */ if (mentry->data == NULL) { DatabaseRecordPtr new_record; /* Create the new record and read it into memory. */ if ((error = create_record(fentry->type, number, NULL, &fentry->position, &new_record)) == ERRORCODE_None) { /* Read the record from its position. */ if ((error = new_record->read()) == ERRORCODE_None) { /* Success! Use this record now. */ mentry->data = new_record; } else { /* We failed to read the record. Unlock and delete it. */ delete new_record; } } } /* Handle the lock if successful. */ if ((record = mentry->data) != NULL) { if (read_only) { error = record->ReadLock(); } else { error = record->ModifyLock(); } } if (error != ERRORCODE_None) { record = NULL; table_manager.unlock_entry(number, read_only, FALSE); } } } if (e != NULL) { *e = error; } storage_manager.SetExclusive(FALSE); #ifdef DATABASE_STATISTICS if (record != NULL) { if (read_only) { if( type == DB_ANY_TYPE ) { m_lGetRORecord[fentry->type]++; } else if( type < RECORD_TYPE_ProjectPreview || type > RECORD_TYPE_Component ) { m_lGetRORecord[0]++; } else { m_lGetRORecord[type]++; } } else { if( type == DB_ANY_TYPE ) { m_lGetRecord[fentry->type]++; } else if( type < RECORD_TYPE_ProjectPreview || type > RECORD_TYPE_Component ) { m_lGetRecord[0]++; } else { m_lGetRecord[type]++; } } } #endif return record; }
void UpdateState(Matrix * m_matrix, char * dest ,int begin, int end) { //300/128 + 1 =3, 3*300=900 unsigned size_sse_row = m_matrix->width/128 + 1; //3 unsigned size_sse_ar=size_sse_row * (end - begin); __m128i X[906], A[900], B[900], C[900]; char * mas = m_matrix->data; for( unsigned i=0; i<size_sse_ar; ++i) { A[i].m128i_u32[0]=0;A[i].m128i_u32[1]=0;A[i].m128i_u32[2]=0;A[i].m128i_u32[3]=0; B[i].m128i_u32[0]=0;B[i].m128i_u32[1]=0;B[i].m128i_u32[2]=0;B[i].m128i_u32[3]=0; C[i].m128i_u32[0]=0;C[i].m128i_u32[1]=0;C[i].m128i_u32[2]=0;C[i].m128i_u32[3]=0; } for( unsigned i=0; i<size_sse_ar+6; ++i) { X[i].m128i_u32[0]=0;X[i].m128i_u32[1]=0;X[i].m128i_u32[2]=0;X[i].m128i_u32[3]=0; } // create X[] with bounds unsigned height = end - begin; unsigned width = m_matrix->width; for( unsigned b = 0 ; b < height; ++b ) { char* src = &mas[(b + begin)*width]; unsigned* dst = (unsigned*)&X[(b+1)*size_sse_row]; create_record(src, dst, width); } // create high row in X[] char * src; if(begin == 0) { src = &mas[(m_matrix->height-1)*width]; } else { src = &mas[(begin-1)*width]; } unsigned* dst = (unsigned*)X; create_record(src, dst, width); //create lower row in X[] if(end == m_matrix->height ) { src = mas; } else { src = &mas[end*width]; } dst = (unsigned*)&X[(height+1)*size_sse_row]; create_record(src, dst, width); //sum( C, B, A, X+offset_for_upwards ); high-left friend sum_offset(X,A,B,C,size_sse_ar, 0); //sum( C, B, A, X+offset_for_no_vertical_shift ); sum_offset(X,A,B,C,size_sse_ar, size_sse_row); //sum( C, B, A, X+offset_for_downwards ); sum_offset(X,A,B,C,size_sse_ar, 2*size_sse_row); //shift_left( X ); (when view 2D) in our logic it is in right height = end - begin + 2; shift_left2D( X, height, size_sse_row); //sum( C, B, A, X+offset_for_upwards ); high-left friend sum_offset(X,A,B,C,size_sse_ar, 0); //sum( C, B, A, X+offset_for_downwards ); sum_offset(X,A,B,C,size_sse_ar, 2*size_sse_row); //shift_left( X ); (view in 2D) in our logic it is right shift height = end - begin + 2; shift_left2D( X, height, size_sse_row); //sum( C, B, A, X+offset_for_upwards ); high-right friend sum_offset(X,A,B,C,size_sse_ar, 0); //sum( C, B, A, X+offset_for_no_vertical_shift ); right friend sum_offset(X,A,B,C,size_sse_ar, size_sse_row); //sum( C, B, A, X+offset_for_downwards ); right down friend sum_offset(X,A,B,C,size_sse_ar, 2*size_sse_row); //shift_right( X ); (when view in 2D) in our case it left shift. height = end - begin + 2; shift_right2D( X, height, size_sse_row); //X = (X|A)&B&~C (done bitwise over the arrays) unsigned shift = size_sse_row; for(unsigned i=0; i<size_sse_ar; ++i) { C[i].m128i_u32[0] = ~C[i].m128i_u32[0]; C[i].m128i_u32[1] = ~C[i].m128i_u32[1]; C[i].m128i_u32[2] = ~C[i].m128i_u32[2]; C[i].m128i_u32[3] = ~C[i].m128i_u32[3]; X[shift + i] = _mm_and_si128(_mm_and_si128(_mm_or_si128(X[shift + i], A[i]),B[i]),C[i]); } height = end - begin; width=m_matrix->width; for( unsigned b=0; b<height; ++b ) { char* dst = &dest[(b+begin)*width]; unsigned* src = (unsigned*)&X[(b+1)*size_sse_row]; for( unsigned a=0; a<width; ++a ) { unsigned c = src[a/32u] & 1<<(a%32u); dst[a] = c>>(a%32u); } } }
int run_test(const char *filename) { MI_INFO *file; int i , j, error, deleted, rec_length, uniques = 0; ha_rows found , row_count; my_off_t pos; char record [MAX_REC_LENGTH], key[MAX_REC_LENGTH], read_record[MAX_REC_LENGTH]; MI_UNIQUEDEF uniquedef; MI_CREATE_INFO create_info; bzero((char *)recinfo, sizeof(recinfo)); /* First define 2 columns */ recinfo[0].type = FIELD_NORMAL; recinfo[0].length = 1; /* For NULL bits */ recinfo[1].type = key_field; recinfo[1].length = (key_field == FIELD_BLOB ? 4 + mi_portable_sizeof_char_ptr : key_length); if (key_field == FIELD_VARCHAR) recinfo[1].length += 2; recinfo[2].type = extra_field; recinfo[2].length = (extra_field == FIELD_BLOB ? 4 + mi_portable_sizeof_char_ptr : 24); if (extra_field == FIELD_VARCHAR) recinfo[2].length += 2; if (opt_unique) { recinfo[3].type = FIELD_CHECK; recinfo[3].length = MI_UNIQUE_HASH_LENGTH; } rec_length = recinfo[0].length + recinfo[1].length + recinfo[2].length + recinfo[3].length; /* Define a key over the first column */ keyinfo[0].seg = keyseg; keyinfo[0].keysegs = 1; keyinfo[0].seg[0].type = key_type; keyinfo[0].seg[0].flag = pack_seg; keyinfo[0].seg[0].start = 1; keyinfo[0].seg[0].length = key_length; keyinfo[0].seg[0].null_bit = null_fields ? 2 : 0; keyinfo[0].seg[0].null_pos = 0; keyinfo[0].seg[0].language = MY_CHARSET_CURRENT; if (pack_seg & HA_BLOB_PART) { keyinfo[0].seg[0].bit_start = 4; /* Length of blob length */ } keyinfo[0].flag = (uint8) (pack_keys | unique_key); bzero((byte *) flags, sizeof(flags)); if (opt_unique) { uint start; uniques = 1; bzero((char *)&uniquedef, sizeof(uniquedef)); bzero((char *)uniqueseg, sizeof(uniqueseg)); uniquedef.seg = uniqueseg; uniquedef.keysegs = 2; /* Make a unique over all columns (except first NULL fields) */ for (i = 0, start = 1; i < 2; i++) { uniqueseg[i].start = start; start += recinfo[i + 1].length; uniqueseg[i].length = recinfo[i + 1].length; uniqueseg[i].language = MY_CHARSET_CURRENT; } uniqueseg[0].type = key_type; uniqueseg[0].null_bit = null_fields ? 2 : 0; uniqueseg[1].type = HA_KEYTYPE_TEXT; if (extra_field == FIELD_BLOB) { uniqueseg[1].length = 0; /* The whole blob */ uniqueseg[1].bit_start = 4; /* long blob */ uniqueseg[1].flag |= HA_BLOB_PART; } else if (extra_field == FIELD_VARCHAR) uniqueseg[1].flag |= HA_VAR_LENGTH; } else uniques = 0; if (!silent) printf("- Creating isam-file\n"); bzero((char *)&create_info, sizeof(create_info)); create_info.max_rows = (ulong) (rec_pointer_size ? (1L << (rec_pointer_size * 8)) / 40 : 0); if (mi_create(filename, 1, keyinfo, 3 + opt_unique, recinfo, uniques, &uniquedef, &create_info, create_flag)) goto err; if (!(file = mi_open(filename, 2, HA_OPEN_ABORT_IF_LOCKED))) goto err; if (!silent) printf("- Writing key:s\n"); my_errno = 0; row_count = deleted = 0; for (i = 49; i >= 1; i -= 2) { if (insert_count-- == 0) { VOID(mi_close(file)); exit(0); } j = i % 25 + 1; create_record(record, j); error = mi_write(file, record); if (!error) row_count++; flags[j] = 1; if (verbose || error) printf("J= %2d mi_write: %d errno: %d\n", j, error, my_errno); } /* Insert 2 rows with null values */ if (null_fields) { create_record(record, 0); error = mi_write(file, record); if (!error) row_count++; if (verbose || error) printf("J= NULL mi_write: %d errno: %d\n", error, my_errno); error = mi_write(file, record); if (!error) row_count++; if (verbose || error) printf("J= NULL mi_write: %d errno: %d\n", error, my_errno); flags[0] = 2; } if (!skip_update) { if (opt_unique) { if (!silent) printf("- Checking unique constraint\n"); create_record(record, j); if (!mi_write(file, record) || my_errno != HA_ERR_FOUND_DUPP_UNIQUE) { printf("unique check failed\n"); } } if (!silent) printf("- Updating rows\n"); /* Update first last row to force extend of file */ if (mi_rsame(file, read_record, -1)) { printf("Can't find last row with mi_rsame\n"); } else { memcpy(record, read_record, rec_length); update_record(record); if (mi_update(file, read_record, record)) { printf("Can't update last row: %.*s\n", keyinfo[0].seg[0].length, read_record + 1); } } /* Read through all rows and update them */ pos = (my_off_t) 0; found = 0; while ((error = mi_rrnd(file, read_record, pos)) == 0) { if (update_count-- == 0) { VOID(mi_close(file)); exit(0); } memcpy(record, read_record, rec_length); update_record(record); if (mi_update(file, read_record, record)) { printf("Can't update row: %.*s, error: %d\n", keyinfo[0].seg[0].length, record + 1, my_errno); } found++; pos = HA_OFFSET_ERROR; } if (found != row_count) printf("Found %ld of %ld rows\n", found, row_count); } if (!silent) printf("- Reopening file\n"); if (mi_close(file)) goto err; if (!(file = mi_open(filename, 2, HA_OPEN_ABORT_IF_LOCKED))) goto err; if (!skip_update) { if (!silent) printf("- Removing keys\n"); for (i = 0; i <= 10; i++) { /* testing */ if (remove_count-- == 0) { VOID(mi_close(file)); exit(0); } j = i * 2; if (!flags[j]) continue; create_key(key, j); my_errno = 0; if ((error = mi_rkey(file, read_record, 0, key, 0, HA_READ_KEY_EXACT))) { if (verbose || (flags[j] >= 1 || (error && my_errno != HA_ERR_KEY_NOT_FOUND))) printf("key: '%.*s' mi_rkey: %3d errno: %3d\n", (int)key_length, key + test(null_fields), error, my_errno); } else { error = mi_delete(file, read_record); if (verbose || error) printf("key: '%.*s' mi_delete: %3d errno: %3d\n", (int)key_length, key + test(null_fields), error, my_errno); if (!error) { deleted++; flags[j]--; } } } } if (!silent) printf("- Reading rows with key\n"); for (i = 0; i <= 25; i++) { create_key(key, i); my_errno = 0; error = mi_rkey(file, read_record, 0, key, 0, HA_READ_KEY_EXACT); if (verbose || (error == 0 && flags[i] == 0 && unique_key) || (error && (flags[i] != 0 || my_errno != HA_ERR_KEY_NOT_FOUND))) { printf("key: '%.*s' mi_rkey: %3d errno: %3d record: %s\n", (int)key_length, key + test(null_fields), error, my_errno, record + 1); } } if (!silent) printf("- Reading rows with position\n"); for (i = 1, found = 0; i <= 30; i++) { my_errno = 0; if ((error = mi_rrnd(file, read_record, i == 1 ? 0L : HA_OFFSET_ERROR)) == -1) { if (found != row_count - deleted) printf("Found only %ld of %ld rows\n", found, row_count - deleted); break; } if (!error) found++; if (verbose || (error != 0 && error != HA_ERR_RECORD_DELETED && error != HA_ERR_END_OF_FILE)) { printf("pos: %2d mi_rrnd: %3d errno: %3d record: %s\n", i - 1, error, my_errno, read_record + 1); } } if (mi_close(file)) goto err; my_end(MY_CHECK_ERROR); return (0); err: printf("got error: %3d when using myisam-database\n", my_errno); return 1; /* skipp warning */ }
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, struct GNUNET_TESTING_Peer *peer) { char *hostkey_file; directory = NULL; GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(mycfg, "PATHS", "GNUNET_TEST_HOME", &directory)); GNUNET_DISK_directory_remove (directory); res = 1; GNUNET_asprintf(&hostkey_file, "zonefiles%s%s", DIR_SEPARATOR_STR, "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); GNUNET_free (hostkey_file); GNUNET_assert (privkey != NULL); cfg = mycfg; endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); /* Connect to namestore */ nsh = GNUNET_NAMESTORE_connect (cfg); if (NULL == nsh) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connect to namestore\n"); GNUNET_break (0); endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); return; } GNUNET_asprintf(&hostkey_file,"zonefiles%s%s", DIR_SEPARATOR_STR, "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); GNUNET_free (hostkey_file); GNUNET_assert (privkey2 != NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n"); /* name in different zone */ GNUNET_asprintf(&s_name_3, "dummy3"); s_rd_3 = create_record(1); GNUNET_assert (NULL != (ns_ops[2] = GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3, 1, s_rd_3, &put_cont, s_name_3))); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); GNUNET_asprintf(&s_name_1, "dummy1"); s_rd_1 = create_record(1); GNUNET_assert (NULL != (ns_ops[0] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1, 1, s_rd_1, &put_cont, s_name_1))); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); GNUNET_asprintf(&s_name_2, "dummy2"); s_rd_2 = create_record(1); GNUNET_assert (NULL != (ns_ops[1] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2, 1, s_rd_2, &put_cont, s_name_2))); }