Lines Matching +full:vc +full:- +full:win32

11  * - Redistributions of source code must retain the above copyright
14 * - Redistributions in binary form must reproduce the above copyright
39 * - tables -- multiple attribute/value tables in one DB
40 * - locking
41 * - transactions (i.e., allow any heim_object_t as key or value)
42 * - transcoding of values
49 * memory-based rollback log is used).
58 #ifdef WIN32
93 "db-object",
160 heim_release(plug->name); in plugin_dealloc()
196 if ((plugin->beginf != NULL && plugin->commitf == NULL) || in heim_db_register()
197 (plugin->beginf != NULL && plugin->rollbackf == NULL) || in heim_db_register()
198 (plugin->lockf != NULL && plugin->unlockf == NULL) || in heim_db_register()
199 plugin->copyf == NULL) in heim_db_register()
220 plug->name = heim_retain(s); in heim_db_register()
221 plug->openf = plugin->openf; in heim_db_register()
222 plug->clonef = plugin->clonef; in heim_db_register()
223 plug->closef = plugin->closef; in heim_db_register()
224 plug->lockf = plugin->lockf; in heim_db_register()
225 plug->unlockf = plugin->unlockf; in heim_db_register()
226 plug->syncf = plugin->syncf; in heim_db_register()
227 plug->beginf = plugin->beginf; in heim_db_register()
228 plug->commitf = plugin->commitf; in heim_db_register()
229 plug->rollbackf = plugin->rollbackf; in heim_db_register()
230 plug->copyf = plugin->copyf; in heim_db_register()
231 plug->setf = plugin->setf; in heim_db_register()
232 plug->delf = plugin->delf; in heim_db_register()
233 plug->iterf = plugin->iterf; in heim_db_register()
234 plug->data = data; in heim_db_register()
251 heim_assert(!db->in_transaction, in db_dealloc()
253 if (db->db_data) in db_dealloc()
254 (void) db->plug->closef(db->db_data, NULL); in db_dealloc()
255 heim_release(db->to_release); in db_dealloc()
256 heim_release(db->dbtype); in db_dealloc()
257 heim_release(db->dbname); in db_dealloc()
258 heim_release(db->options); in db_dealloc()
259 heim_release(db->set_keys); in db_dealloc()
260 heim_release(db->del_keys); in db_dealloc()
261 heim_release(db->error); in db_dealloc()
282 if (iter_ctx->db != NULL) in dbtype_iter2create_f()
284 iter_ctx->db = heim_db_create(heim_string_get_utf8(dbtype), in dbtype_iter2create_f()
285 iter_ctx->dbname, iter_ctx->options, in dbtype_iter2create_f()
286 iter_ctx->error); in dbtype_iter2create_f()
292 * Database type names can be composed of one or more pseudo-DB types
300 * - "create", with any value (create if DB doesn't exist)
301 * - "exclusive", with any value (exclusive create)
302 * - "truncate", with any value (truncate the DB)
303 * - "read-only", with any value (disallow writes)
304 * - "sync", with any value (make transactions durable)
305 * - "journal-name", with a string value naming a journal file name
355 * Allow for dbtypes that are composed from pseudo-dbtypes chained in heim_db_create()
356 * to a real DB type with '+'. For example a pseudo-dbtype might in heim_db_create()
361 s = heim_string_create_with_bytes(dbtype, p - dbtype); in heim_db_create()
388 db->in_transaction = 0; in heim_db_create()
389 db->ro_tx = 0; in heim_db_create()
390 db->set_keys = NULL; in heim_db_create()
391 db->del_keys = NULL; in heim_db_create()
392 db->plug = plug; in heim_db_create()
393 db->options = options; in heim_db_create()
395 ret = plug->openf(plug->data, dbtype, dbname, options, &db->db_data, error); in heim_db_create()
411 if (plug->clonef == NULL) { in heim_db_create()
412 db->dbtype = heim_string_create(dbtype); in heim_db_create()
413 db->dbname = heim_string_create(dbname); in heim_db_create()
415 if (!db->dbtype || ! db->dbname) { in heim_db_create()
429 * This is useful for multi-threaded applications. Applications must
449 if (db->in_transaction) in heim_db_clone()
452 if (db->plug->clonef == NULL) { in heim_db_clone()
453 return heim_db_create(heim_string_get_utf8(db->dbtype), in heim_db_clone()
454 heim_string_get_utf8(db->dbname), in heim_db_clone()
455 db->options, error); in heim_db_clone()
465 result->set_keys = NULL; in heim_db_clone()
466 result->del_keys = NULL; in heim_db_clone()
467 ret = db->plug->clonef(db->db_data, &result->db_data, error); in heim_db_clone()
472 N_("Could not re-open DB while cloning", "")); in heim_db_clone()
475 db->db_data = NULL; in heim_db_clone()
497 if (db->in_transaction && (read_only || !db->ro_tx || (!read_only && !db->ro_tx))) in heim_db_begin()
500 if (db->plug->setf == NULL || db->plug->delf == NULL) in heim_db_begin()
503 if (db->plug->beginf) { in heim_db_begin()
504 ret = db->plug->beginf(db->db_data, read_only, error); in heim_db_begin()
507 } else if (!db->in_transaction) { in heim_db_begin()
510 if (db->plug->lockf == NULL) in heim_db_begin()
511 return EINVAL; /* can't lock? -> no transactions */ in heim_db_begin()
514 ret = db->plug->lockf(db->db_data, read_only, error); in heim_db_begin()
520 ret = db->plug->unlockf(db->db_data, error); in heim_db_begin()
524 db->set_keys = heim_dict_create(11); in heim_db_begin()
525 if (db->set_keys == NULL) in heim_db_begin()
527 db->del_keys = heim_dict_create(11); in heim_db_begin()
528 if (db->del_keys == NULL) { in heim_db_begin()
529 heim_release(db->set_keys); in heim_db_begin()
530 db->set_keys = NULL; in heim_db_begin()
535 ret = db->plug->lockf(db->db_data, 0, error); in heim_db_begin()
539 db->in_transaction = 1; in heim_db_begin()
540 db->ro_tx = !!read_only; in heim_db_begin()
562 if (!db->in_transaction) in heim_db_commit()
564 if (db->plug->commitf == NULL && db->plug->lockf == NULL) in heim_db_commit()
567 if (db->plug->commitf != NULL) { in heim_db_commit()
568 ret = db->plug->commitf(db->db_data, error); in heim_db_commit()
570 (void) db->plug->rollbackf(db->db_data, error); in heim_db_commit()
572 db->in_transaction = 0; in heim_db_commit()
573 db->ro_tx = 0; in heim_db_commit()
577 if (db->ro_tx) { in heim_db_commit()
582 if (db->options == NULL) in heim_db_commit()
583 journal_fname = heim_dict_get_value(db->options, HSTR("journal-filename")); in heim_db_commit()
596 ret = heim_array_append_value(a, db->set_keys); in heim_db_commit()
601 ret = heim_array_append_value(a, db->del_keys); in heim_db_commit()
639 if (db->plug->syncf != NULL) { in heim_db_commit()
641 ret = db->plug->syncf(db->db_data, error); in heim_db_commit()
660 heim_release(db->set_keys); in heim_db_commit()
661 heim_release(db->del_keys); in heim_db_commit()
662 db->set_keys = NULL; in heim_db_commit()
663 db->del_keys = NULL; in heim_db_commit()
664 db->in_transaction = 0; in heim_db_commit()
665 db->ro_tx = 0; in heim_db_commit()
667 ret2 = db->plug->unlockf(db->db_data, error); in heim_db_commit()
696 if (!db->in_transaction) in heim_db_rollback()
699 if (db->plug->rollbackf != NULL) in heim_db_rollback()
700 ret = db->plug->rollbackf(db->db_data, error); in heim_db_rollback()
701 else if (db->plug->unlockf != NULL) in heim_db_rollback()
702 ret = db->plug->unlockf(db->db_data, error); in heim_db_rollback()
704 heim_release(db->set_keys); in heim_db_rollback()
705 heim_release(db->del_keys); in heim_db_rollback()
706 db->set_keys = NULL; in heim_db_rollback()
707 db->del_keys = NULL; in heim_db_rollback()
708 db->in_transaction = 0; in heim_db_rollback()
709 db->ro_tx = 0; in heim_db_rollback()
729 heim_release(db->to_release); in _heim_db_get_value()
730 db->to_release = heim_db_copy_value(db, table, key, error); in _heim_db_get_value()
731 return db->to_release; in _heim_db_get_value()
737 * Returns 0 on success, -1 if the key does not exist in the DB, or a
764 if (db->in_transaction) { in heim_db_copy_value()
774 v = heim_path_copy(db->set_keys, error, table, key64, NULL); in heim_db_copy_value()
779 v = heim_path_copy(db->del_keys, error, table, key64, NULL); /* can't be NULL */ in heim_db_copy_value()
785 result = db->plug->copyf(db->db_data, table, key, error); in heim_db_copy_value()
826 if (db->plug->setf == NULL) in heim_db_set_value()
829 if (!db->in_transaction) { in heim_db_set_value()
833 heim_assert(db->in_transaction, "Internal error"); in heim_db_set_value()
843 heim_assert(db->set_keys != NULL, "Internal error"); in heim_db_set_value()
848 if (db->ro_tx) { in heim_db_set_value()
853 ret = heim_path_create(db->set_keys, 29, value, error, table, key64, NULL); in heim_db_set_value()
856 heim_path_delete(db->del_keys, error, table, key64, NULL); in heim_db_set_value()
896 if (db->plug->delf == NULL) in heim_db_delete_key()
899 if (!db->in_transaction) { in heim_db_delete_key()
903 heim_assert(db->in_transaction, "Internal error"); in heim_db_delete_key()
913 heim_assert(db->set_keys != NULL, "Internal error"); in heim_db_delete_key()
917 if (db->ro_tx) { in heim_db_delete_key()
922 ret = heim_path_create(db->del_keys, 29, heim_number_create(1), error, table, key64, NULL); in heim_db_delete_key()
925 heim_path_delete(db->set_keys, error, table, key64, NULL); in heim_db_delete_key()
942 * @param iter_f Callback function, called once per-key/value pair
957 if (!db->in_transaction) in heim_db_iterate_f()
958 db->plug->iterf(db->db_data, table, iter_data, iter_f, error); in heim_db_iterate_f()
968 if (db->ret) in db_replay_log_table_set_keys_iter()
971 k = from_base64((heim_string_t)key, &db->error); in db_replay_log_table_set_keys_iter()
973 db->ret = ENOMEM; in db_replay_log_table_set_keys_iter()
978 db->ret = db->plug->setf(db->db_data, db->current_table, k, v, &db->error); in db_replay_log_table_set_keys_iter()
989 if (db->ret) { in db_replay_log_table_del_keys_iter()
990 db->ret = ENOMEM; in db_replay_log_table_del_keys_iter()
994 k = from_base64((heim_string_t)key, &db->error); in db_replay_log_table_del_keys_iter()
998 db->ret = db->plug->delf(db->db_data, db->current_table, k, &db->error); in db_replay_log_table_del_keys_iter()
1008 if (db->ret) in db_replay_log_set_keys_iter()
1011 db->current_table = table; in db_replay_log_set_keys_iter()
1021 if (db->ret) in db_replay_log_del_keys_iter()
1024 db->current_table = table; in db_replay_log_del_keys_iter()
1036 db->ret = 0; in db_do_log_actions()
1037 db->error = NULL; in db_do_log_actions()
1038 if (db->set_keys != NULL) in db_do_log_actions()
1039 heim_dict_iterate_f(db->set_keys, db, db_replay_log_set_keys_iter); in db_do_log_actions()
1040 if (db->del_keys != NULL) in db_do_log_actions()
1041 heim_dict_iterate_f(db->del_keys, db, db_replay_log_del_keys_iter); in db_do_log_actions()
1043 ret = db->ret; in db_do_log_actions()
1044 db->ret = 0; in db_do_log_actions()
1045 if (error && db->error) { in db_do_log_actions()
1046 *error = db->error; in db_do_log_actions()
1047 db->error = NULL; in db_do_log_actions()
1049 heim_release(db->error); in db_do_log_actions()
1050 db->error = NULL; in db_do_log_actions()
1063 heim_assert(!db->in_transaction, "DB transaction not open"); in db_replay_log()
1064 heim_assert(db->set_keys == NULL && db->set_keys == NULL, "DB transaction not open"); in db_replay_log()
1069 if (db->options == NULL) in db_replay_log()
1072 journal_fname = heim_dict_get_value(db->options, HSTR("journal-filename")); in db_replay_log()
1100 db->set_keys = heim_array_get_value(journal, 0); in db_replay_log()
1102 db->del_keys = heim_array_get_value(journal, 1); in db_replay_log()
1114 heim_release(db->set_keys); in db_replay_log()
1115 heim_release(db->del_keys); in db_replay_log()
1116 db->set_keys = NULL; in db_replay_log()
1117 db->del_keys = NULL; in db_replay_log()
1131 ret = rk_base64_encode(d->data, d->length, &b64); in to_base64()
1174 #ifdef WIN32 in open_file()
1179 *fd_out = -1; in open_file()
1224 *fd_out = -1; in open_file()
1245 if (ret == -1) { in open_file()
1265 int fd = -1; in read_json()
1274 if (ret == -1) { in read_json()
1346 heim_object_t vc, ve, vt; in json_db_open() local
1348 vc = heim_dict_get_value(options, HSTR("create")); in json_db_open()
1351 if (vc && vt) { in json_db_open()
1355 } else if (vc || ve || vt) { in json_db_open()
1422 jsondb->last_read_time = time(NULL); in json_db_open()
1423 jsondb->fd = -1; in json_db_open()
1424 jsondb->dbname = dbname_s; in json_db_open()
1425 jsondb->bkpname = bkpname_s; in json_db_open()
1426 jsondb->read_only = 0; in json_db_open()
1429 jsondb->dict = contents; in json_db_open()
1431 jsondb->dict = heim_dict_create(29); in json_db_open()
1432 if (jsondb->dict == NULL) { in json_db_open()
1449 if (jsondb->fd > -1) in json_db_close()
1450 (void) close(jsondb->fd); in json_db_close()
1451 jsondb->fd = -1; in json_db_close()
1452 heim_release(jsondb->dbname); in json_db_close()
1453 heim_release(jsondb->bkpname); in json_db_close()
1454 heim_release(jsondb->dict); in json_db_close()
1465 heim_assert(jsondb->fd == -1 || (jsondb->read_only && !read_only), in json_db_lock()
1468 jsondb->read_only = read_only ? 1 : 0; in json_db_lock()
1469 if (jsondb->fd > -1) in json_db_lock()
1472 ret = open_file(heim_string_get_utf8(jsondb->bkpname), 1, 1, &jsondb->fd, error); in json_db_lock()
1474 jsondb->locked_needs_unlink = 1; in json_db_lock()
1475 jsondb->locked = 1; in json_db_lock()
1486 heim_assert(jsondb->locked, "DB not locked when unlock attempted"); in json_db_unlock()
1487 if (jsondb->fd > -1) in json_db_unlock()
1488 ret = close(jsondb->fd); in json_db_unlock()
1489 jsondb->fd = -1; in json_db_unlock()
1490 jsondb->read_only = 0; in json_db_unlock()
1491 jsondb->locked = 0; in json_db_unlock()
1492 if (jsondb->locked_needs_unlink) in json_db_unlock()
1493 unlink(heim_string_get_utf8(jsondb->bkpname)); in json_db_unlock()
1494 jsondb->locked_needs_unlink = 0; in json_db_unlock()
1507 int fd = -1; in json_db_sync()
1508 #ifdef WIN32 in json_db_sync()
1512 heim_assert(jsondb->fd > -1, "DB not locked when sync attempted"); in json_db_sync()
1514 json = heim_json_copy_serialize(jsondb->dict, 0, &e); in json_db_sync()
1527 #ifdef WIN32 in json_db_sync()
1528 while (tries--) { in json_db_sync()
1529 ret = open_file(heim_string_get_utf8(jsondb->dbname), 1, 0, &fd, error); in json_db_sync()
1539 fd = jsondb->fd; in json_db_sync()
1540 #endif /* WIN32 */ in json_db_sync()
1550 #ifdef WIN32 in json_db_sync()
1555 ret = rename(heim_string_get_utf8(jsondb->bkpname), heim_string_get_utf8(jsondb->dbname)); in json_db_sync()
1557 jsondb->locked_needs_unlink = 0; in json_db_sync()
1560 #endif /* WIN32 */ in json_db_sync()
1578 if (strnlen(key_data->data, key_data->length) != key_data->length) { in json_db_copy_value()
1585 if (stat(heim_string_get_utf8(jsondb->dbname), &st) == -1) { in json_db_copy_value()
1591 if (st.st_mtime > jsondb->last_read_time || in json_db_copy_value()
1592 st.st_ctime > jsondb->last_read_time) { in json_db_copy_value()
1597 ret = read_json(heim_string_get_utf8(jsondb->dbname), in json_db_copy_value()
1603 heim_release(jsondb->dict); in json_db_copy_value()
1604 jsondb->dict = contents; in json_db_copy_value()
1605 jsondb->last_read_time = time(NULL); in json_db_copy_value()
1608 key_string = heim_string_create_with_bytes(key_data->data, in json_db_copy_value()
1609 key_data->length); in json_db_copy_value()
1615 result = heim_path_copy(jsondb->dict, error, table, key_string, NULL); in json_db_copy_value()
1632 if (strnlen(key_data->data, key_data->length) != key_data->length) in json_db_set_value()
1638 key_string = heim_string_create_with_bytes(key_data->data, in json_db_set_value()
1639 key_data->length); in json_db_set_value()
1646 ret = heim_path_create(jsondb->dict, 29, value, error, table, key_string, NULL); in json_db_set_value()
1662 if (strnlen(key_data->data, key_data->length) != key_data->length) in json_db_del_key()
1668 key_string = heim_string_create_with_bytes(key_data->data, in json_db_del_key()
1669 key_data->length); in json_db_del_key()
1676 heim_path_delete(jsondb->dict, error, table, key_string, NULL); in json_db_del_key()
1694 ctx->iter_f(key_data, (heim_object_t)value, ctx->iter_ctx); in json_db_iter_f()
1712 table_dict = heim_dict_get_value(jsondb->dict, table); in json_db_iter()