int main(int argc, char *argv[]) { Database *db; LinkedList *ll; db = db_create("project_seven"); //CREATE DATABASE project_seven; tbl_delete(db, "animals"); //DROP TABLE IF EXISTS animals; func_delete(db, "num_animals"); //DROP FUNCTION IF EXISTS num_animals; tbl_create(db, "animals"); //CREATE TABLE animals /* Capabilities of this function changed to make implementation easier. The purpose of this function is to demonstrate memory management */ func_create(db, "num_animals", num_animals); //CREATE FUNCTION num_animals() /*Creates rows in table*/ ll = ll_create(); ll_append(ll, "Cow"); tbl_insert(db, "animals", ll); //INSERT INTO animals (animal) VALUES ("Cow"); ll = ll_create(); ll_append(ll, "Dog"); tbl_insert(db, "animals", ll); //INSERT INTO animals (animal) VALUES ("Dog"); /*Printing tables, and rows created*/ db_print(db); //SHOW TABLES; tbl_print(db, "animals"); //SELECT * FROM animals; /*Deallocating memory*/ tbl_clear(db, "animals"); //DELETE FROM animals; tbl_print(db, "animals"); //SELECT * FROM animals; /*Allocating so that we can deallocate again*/ ll = ll_create(); ll_append(ll, "Pig"); tbl_insert(db, "animals", ll); //INSERT INTO animals (animal) VALUES ("Pig"); ll = ll_create(); ll_append(ll, "Cat"); tbl_insert(db, "animals", ll); //INSERT INTO animals (animal) VALUES ("Cat"); tbl_print(db, "animals"); //SELECT * FROM animals; /*Deallocating memory*/ tbl_clear(db, "animals"); //TRUNCATE TABLE animals; tbl_print(db, "animals"); //SELECT * FROM animals; tbl_delete(db, "animals"); //DROP TABLE IF EXISTS animals; func_delete(db, "num_animals"); //DROP FUNCTION IF EXISTS num_animals; db_print(db); //SHOW TABLES; db_delete(db); //DROP DATABASE IF EXISTS project_seven; return 0; }
int main() { //struct DBC dbc = {128*1024*1024, 2046, 16*1024*1024}; //struct DB *dbn = dbcreate("mydb", &dbc); //struct DB db = *dbn; struct DB db; db_init(&db, "mydb", 2048, 128*1024*1024, 16*1024*1024); cache_print(db.pool->cache); db_print(&db); db_insert(&db, "1234", "Hello, world1", 13); db_insert(&db, "1235", "Hello, world2", 13); db_insert(&db, "1236", "Hello, world3", 13); db_insert(&db, "1237", "Hello, world4", 13); db_insert(&db, "1238", "Hello, world5", 13); cache_print(db.pool->cache); db_insert(&db, "1232", "Hello, world6", 13); db_insert(&db, "1231", "Hello, world7", 13); db_insert(&db, "1240", "Hello, world8", 13); db_insert(&db, "1232", "Hello, world6", 13); db_insert(&db, "1251", "Hello, world7", 13); db_insert(&db, "1252", "Hello, world8", 13); db_insert(&db, "1253", "Hello, world6", 13); db_insert(&db, "1254", "Hello, world7", 13); cache_print(db.pool->cache); db_insert(&db, "1255", "Hello, world8", 13); db_insert(&db, "1253", "Hello, world6", 13); db_insert(&db, "1254", "Hello, world7", 13); db_insert(&db, "1255", "Hello, world8", 13); db_insert(&db, "1256", "Hello, world8", 13); db_insert(&db, "1257", "Hello, world7", 13); db_insert(&db, "1258", "Hello, world8", 13); db_insert(&db, "1259", "Hello, world6", 13); cache_print(db.pool->cache); db_insert(&db, "1260", "Hello, world8", 13); db_insert(&db, "1210", "Hello, world7", 13); db_insert(&db, "1209", "Hello, world8", 13); db_insert(&db, "1208", "Hello, world6", 13); db_insert(&db, "1207", "Hello, world8", 13); db_insert(&db, "1206", "Hello, world6", 13); db_insert(&db, "1205", "Hello, world8", 13); cache_print(db.pool->cache); db_insert(&db, "1204", "Hello, world7", 13); db_insert(&db, "1203", "Hello, world8", 13); db_insert(&db, "1202", "Hello, world6", 13); db_insert(&db, "1208", "Hello, world8", 13); db_insert(&db, "1209", "Hello, world6", 13); db_insert(&db, "121000", "Hello, world8", 13); /*db_delete(&db, "121000");*/ db_print(&db); cache_print(db.pool->cache); char *data = NULL; size_t val = 0; db_search(&db, "1231", (void **)&data, &val); printf("\n%13s\n", data); db_free(&db); return 0; }
int main(void) { struct db_context *ctx=db_prop_new(PROTO_ISAKMP, 0, 0); db_trans_add(ctx, KEY_IKE); db_attr_add_values(ctx, OAKLEY_ENCRYPTION_ALGORITHM, OAKLEY_DES_CBC); db_attr_add_values(ctx, OAKLEY_HASH_ALGORITHM, OAKLEY_MD5); db_attr_add_values(ctx, OAKLEY_AUTHENTICATION_METHOD, OAKLEY_RSA_SIG); db_attr_add_values(ctx, OAKLEY_GROUP_DESCRIPTION, OAKLEY_GROUP_MODP1024); db_trans_add(ctx, KEY_IKE); db_attr_add_values(ctx, OAKLEY_ENCRYPTION_ALGORITHM, OAKLEY_3DES_CBC); db_attr_add_values(ctx, OAKLEY_HASH_ALGORITHM, OAKLEY_MD5); db_attr_add_values(ctx, OAKLEY_AUTHENTICATION_METHOD, OAKLEY_RSA_SIG); db_attr_add_values(ctx, OAKLEY_GROUP_DESCRIPTION, OAKLEY_GROUP_MODP1024); db_trans_add(ctx, KEY_IKE); db_attr_add_values(ctx, OAKLEY_ENCRYPTION_ALGORITHM, OAKLEY_AES_CBC); db_attr_add_values(ctx, OAKLEY_HASH_ALGORITHM, OAKLEY_MD5); db_attr_add_values(ctx, OAKLEY_AUTHENTICATION_METHOD, OAKLEY_PRESHARED_KEY); db_attr_add_values(ctx, OAKLEY_GROUP_DESCRIPTION, OAKLEY_GROUP_MODP1536); db_trans_add(ctx, ESP_3DES); db_attr_add_values(ctx, AUTH_ALGORITHM, AUTH_ALGORITHM_HMAC_SHA1); db_trans_add(ctx, ESP_DES); db_attr_add_values(ctx, AUTH_ALGORITHM, AUTH_ALGORITHM_HMAC_SHA1); db_print(ctx); db_destroy(ctx); return 0; }
// update an entire record // int DB_BASE::update() { char vals[MAX_QUERY_LEN], query[MAX_QUERY_LEN]; db_print(vals); sprintf(query, "update %s set %s where id=%u", table_name, vals, get_id()); int retval = db->do_query(query); if (retval) return retval; if (db->affected_rows() != 1) return ERR_DB_NOT_FOUND; return 0; }
void * db_thread (void * parameters) { struct square_t *square = (struct square_t *)parameters; for(;;) { int i; for(i=0;i<MAX_SQUARES;i++) db_print(i,square[i]); sleep(5); } }
int DB_BASE::insert() { char vals[MAX_QUERY_LEN*2], query[MAX_QUERY_LEN*2]; db_print(vals); sprintf(query, "insert into %s set %s", table_name, vals); return db->do_query(query); }
int main( int argc, char *argv[] ) { dl_head_typ *pusr; /* A list of slv_clt_typ structures, * which contain client information, * and channels for communications. */ slv_db_typ *pdb; /* The variable list, which contains * data, the sizes, and a list trigger * clients for each variable. */ comm_clt_typ *psvc_clt; /* Client calls are received here. */ comm_clt_typ *pdb_clt; /* This points to the current client.*/ db_data_typ recv_buff; /* The buffer of information from the * client. */ char *pservname; /* The service name to be supported.*/ int option; int priority; int name_id; void *name_struct; int xport = COMM_PSX_XPORT; // transport mechanism int handle = COMM_WILD_HANDLE; // for COMM_QNX_XPORT, receive all /* Set to invalid values to facilitate error exits. */ pdb = NULL; psvc_clt = NULL; pusr = NULL; name_id = ERROR; name_struct = NULL; verbose_flag = FALSE; pservname = DEFAULT_SERVICE; while( (option = getopt( argc, argv, "S:P:qQv?" )) != EOF ) { switch( option ) { case 'v': verbose_flag = TRUE; break; case 'P': priority = atoi( optarg ); if( setprio( 0, priority ) == ERROR ) { fprintf(stderr, "Can't change priority to %d\n", priority ); exit( EXIT_FAILURE ); } break; case 'S': pservname = optarg; break; case 'q': xport = COMM_QNX_XPORT; break; case 'Q': xport = COMM_QNX6_XPORT; break; case '?': default: usage( argv[0] ); exit( EXIT_FAILURE ); break; } } if (verbose_flag) { printf("Starting PATH DB data server\n"); fflush(stdout); } if ( !slv_db_publish_name (xport, pservname, &name_id, &name_struct) ) { fprintf( stderr, "Can't publish service %s\n", pservname); slv_done( pdb, pusr, psvc_clt, name_id, pservname, name_struct); exit( EXIT_FAILURE ); } /* Beware that name_id is now the channel id in QNX 6, so * don't want to pass in COMM_WILD_HANDLE. But code for QNX 4 * assumes COMM_WILD_HANDLE, so must special case this */ if ( COMM_QNX6_XPORT == xport ) { handle = comm_get_handle( xport, pservname, name_id ); } else { handle = comm_get_handle( xport, pservname, COMM_WILD_HANDLE ); } if( (pdb = slv_db_create()) == NULL ) { fprintf( stderr, "%s: Can't create database\n", argv[0] ); slv_done( pdb, pusr, psvc_clt, name_id, pservname, name_struct ); exit( EXIT_FAILURE ); } else if( (psvc_clt = comm_init( xport, handle )) == NULL ) { fprintf( stderr, "%s: Can't create server communications\n", argv[0] ); slv_done( pdb, pusr, psvc_clt, name_id, pservname, name_struct ); exit( EXIT_FAILURE ); } else if( (pusr = dl_create()) == NULL ) { fprintf( stderr, "%s: Can't create usr list\n", argv[0] ); slv_done( pdb, pusr, psvc_clt, name_id, pservname, name_struct ); exit( EXIT_FAILURE ); } else if( setjmp( exit_env ) != 0 ) { slv_done( pdb, pusr, psvc_clt, name_id, pservname, name_struct ); exit( EXIT_SUCCESS ); } else sig_ign( sig_list, sig_hand ); if (verbose_flag) { printf("db slv: pdb 0x%x pusr 0x%x\n", (unsigned int) pdb, (unsigned int) pusr); } while( (pdb_clt = comm_sync_recv( psvc_clt, &recv_buff, DB_COMM_SIZE )) != NULL ) { if( verbose_flag == TRUE ) db_print( &recv_buff ); if( (slv_cmd( pdb, pusr, pdb_clt, &recv_buff ) == FALSE) && (verbose_flag == TRUE) ) { printf( "%s: processing failed.\n", argv[0] ); db_print( &recv_buff ); } } longjmp( exit_env, EXIT_FAILURE ); }
int main(int argc, char **argv) { int ret; setlocale(LC_ALL, ""); if (argc != 3) { wprintf(L"Usage: psafe file.psafe3 passphrase"); exit(EXIT_FAILURE); } init_crypto(64*1024); size_t sz; uint8_t *ptr; ptr = mapfile_ro(argv[1], &sz); if (ptr == NULL) err(1, "%s", argv[1]); struct psafe3_pro *pro; pro = (struct psafe3_pro *)(ptr + 4); struct safe_sec *sec; sec = gcry_malloc_secure(sizeof(*sec)); ret = stretch_and_check_pass(argv[2], strlen(argv[2]), pro, sec); if (ret != 0) { gcry_free(sec); wprintf(L"Invalid password.\n"); exit(1); } uint8_t *safe; size_t safe_size; safe_size = sz - (4 + sizeof(*pro) + 48); assert(safe_size > 0); assert(safe_size % TWOF_BLKSIZE == 0); safe = gcry_malloc_secure(safe_size); assert(safe != NULL); gcry_error_t gerr; struct decrypt_ctx ctx; if (init_decrypt_ctx(&ctx, pro, sec) < 0) gcrypt_fatal(ctx.gerr); size_t bcnt; bcnt = safe_size / TWOF_BLKSIZE; assert(bcnt > 0); uint8_t *encp; uint8_t *safep; encp = ptr + 4 + sizeof(*pro); safep = safe; while (bcnt--) { gerr = gcry_cipher_decrypt(ctx.cipher, safep, TWOF_BLKSIZE, encp, TWOF_BLKSIZE); if (gerr != GPG_ERR_NO_ERROR) gcrypt_fatal(gerr); safep += TWOF_BLKSIZE; encp += TWOF_BLKSIZE; } enum { HDR, DB }; int state = HDR; safep = safe; while (safep < safe + safe_size) { struct field *fld; fld = (struct field *)safep; wprintf(L"len=%-3u type=%02x ", fld->len, fld->type); if (state == DB) db_print(stdout, fld); else hd_print(stdout, fld); if (fld->type == 0xff) state = DB; putwc('\n', stdout); if (fld->len) gcry_md_write(ctx.hmac, safep + sizeof(*fld), fld->len); safep += ((fld->len + 5 + 15) / TWOF_BLKSIZE) * TWOF_BLKSIZE; } assert(memcmp(ptr + (sz - 48), "PWS3-EOFPWS3-EOF", TWOF_BLKSIZE) == 0); #define EOL() putwc('\n', stdout) EOL(); print_prologue(stdout, pro); wprintf(L"KEY "); printhex(stdout, sec->pprime, 32); EOL(); wprintf(L"H(KEY) "); printhex(stdout, pro->h_pprime, 32); EOL(); gcry_md_final(ctx.hmac); wprintf(L"HMAC' "); uint8_t hmac[32]; memmove(hmac, gcry_md_read(ctx.hmac, GCRY_MD_SHA256), 32); printhex(stdout, hmac, 32); EOL(); wprintf(L"HMAC "); printhex(stdout, ptr + (sz - 32), 32); EOL(); #undef EOL gcry_free(safe); gcry_free(sec); unmapfile(ptr, sz); term_decrypt_ctx(&ctx); exit(0); }
/* Prints the current database. Really just invokes the DB's print method. * * filepath: the path of the db file. DB will open it. */ void cmd_print(char *filepath) { db_print(filepath); }