22 #include "opensync_internals.h" 36 osync_assert_msg(table,
"You have to pass a valid hashtable to the call!");
37 osync_assert_msg(table->dbhandle,
"Hashtable not loaded yet. You have to load the hashtable first using osync_hashtable_load!");
97 table->used_entries = g_hash_table_new(g_str_hash, g_str_equal);
109 g_hash_table_destroy(table->used_entries);
126 g_hash_table_destroy(table->used_entries);
127 table->used_entries = g_hash_table_new(g_str_hash, g_str_equal);
140 return osync_db_open_hashtable(table, member, error);
152 osync_hashtable_assert_loaded(table);
155 osync_db_close(table->dbhandle);
166 osync_hashtable_assert_loaded(table);
168 return osync_db_count(table->dbhandle,
"SELECT count(*) FROM tbl_hash");
184 osync_hashtable_assert_loaded(table);
186 sqlite3 *sdb = table->dbhandle->db;
188 sqlite3_stmt *ppStmt = NULL;
189 char *query = g_strdup_printf(
"SELECT uid, hash FROM tbl_hash LIMIT 1 OFFSET %i", i);
190 sqlite3_prepare(sdb, query, -1, &ppStmt, NULL);
191 sqlite3_step(ppStmt);
192 *uid = g_strdup((gchar*)sqlite3_column_text(ppStmt, 0));
193 *hash = g_strdup((gchar*)sqlite3_column_text(ppStmt, 1));
194 sqlite3_finalize(ppStmt);
211 osync_hashtable_assert_loaded(table);
212 osync_assert_msg(change,
"Change was NULL. Bug in a plugin");
213 osync_assert_msg(change->
uid,
"No uid was set on change. Bug in a plugin");
221 osync_db_save_hash(table, change->
uid, change->
hash,
225 osync_db_delete_hash(table, change->
uid);
228 g_assert_not_reached();
247 osync_hashtable_assert_loaded(table);
249 g_hash_table_insert(table->used_entries, g_strdup(uid), GINT_TO_POINTER(1));
264 osync_hashtable_assert_loaded(table);
266 char **uidarr = osync_db_get_deleted_hash(table, objtype);
268 for (i = 0; uidarr[i]; i++) {
269 char *uid = uidarr[i];
274 osync_context_report_change(context, change);
293 osync_hashtable_assert_loaded(table);
295 char **retarr = osync_db_get_deleted_hash(table, objtype);
305 char *orighash = NULL;
326 osync_hashtable_assert_loaded(table);
329 char *orighash = NULL;
330 osync_db_get_hash(table, uid, objtype, &orighash);
334 if (strcmp(hash, orighash) == 0)
357 osync_bool retval = FALSE;
363 g_hash_table_insert(table->used_entries, g_strdup(change->
uid), GINT_TO_POINTER(1));
375 osync_hashtable_assert_loaded(table);
377 osync_db_reset_hash(table, objtype);
OSyncChangeType osync_change_get_changetype(OSyncChange *change)
Gets the changetype of a change.
void osync_hashtable_get_hash(OSyncHashTable *table, OSyncChange *chg)
Get the hash value from the hash table.
void osync_hashtable_free(OSyncHashTable *table)
Frees a hashtable.
void osync_change_set_uid(OSyncChange *change, const char *uid)
Sets the uid of a change.
void osync_hashtable_report_deleted(OSyncHashTable *table, OSyncContext *context, const char *objtype)
Report all deleted items.
osync_bool osync_hashtable_nth_entry(OSyncHashTable *table, int i, char **uid, char **hash)
Gets the nth entry from the table.
osync_bool osync_hashtable_load(OSyncHashTable *table, OSyncMember *member, OSyncError **error)
Loads a hashtable from disk.
OSyncChange * osync_change_new(void)
Spawns a new change object.
void osync_hashtable_update_hash(OSyncHashTable *table, OSyncChange *change)
Update the hash for a entry.
OSyncChangeType osync_hashtable_get_changetype(OSyncHashTable *table, const char *uid, const char *objtype, const char *hash)
Gets the changetype for a given uid and hash.
A member of a group which represent a single device.
OSyncHashTable * osync_hashtable_new(void)
Creates a new hashtable.
void osync_hashtable_forget(OSyncHashTable *table)
Makes a hashtable forget.
char ** osync_hashtable_get_deleted(OSyncHashTable *table, const char *objtype)
Get the uid of all deleted items.
osync_bool osync_hashtable_detect_change(OSyncHashTable *table, OSyncChange *change)
Gets the changetype of an object and sets it directly.
void osync_hashtable_close(OSyncHashTable *table)
Closes a previously loaded table.
void osync_hashtable_set_slow_sync(OSyncHashTable *table, const char *objtype)
Resets the hashtable for a given object type.
void osync_change_set_hash(OSyncChange *change, const char *hash)
Sets the hash of a change that is used to decide wether a change is new, modifed etc.
void osync_trace(OSyncTraceType type, const char *message,...)
Used for tracing the application.
const char * osync_objtype_get_name(OSyncObjType *type)
Returns the name of a object type.
OSyncObjType * osync_change_get_objtype(OSyncChange *change)
Gets the object type of a change.
void osync_hashtable_report(OSyncHashTable *table, const char *uid)
Report a item.
int osync_hashtable_num_entries(OSyncHashTable *table)
Returns the number of entries in this hashtable.
void osync_change_set_objtype_string(OSyncChange *change, const char *name)
Sets the object type of a change from the name.
OSyncChangeType
The changetypes of a change object.
Represent a hashtable which can be used to check if changes have been modifed or deleted.
OSyncChangeType changetype