OpenSync
0.22
|
00001 /* 00002 * libopensync - A synchronization framework 00003 * Copyright (C) 2004-2005 Armin Bauer <armin.bauer@opensync.org> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 * 00019 */ 00020 00021 #include <opensync.h> 00022 #include "opensync_internals.h" 00023 00024 osync_bool osync_anchor_compare(OSyncMember *member, const char *objtype, const char *new_anchor) 00025 { 00026 osync_trace(TRACE_ENTRY, "%s(%p, %s, %s)", __func__, member, objtype, new_anchor); 00027 g_assert(member); 00028 00029 OSyncError *error = NULL; 00030 OSyncDB *db = NULL; 00031 if (!(db = osync_db_open_anchor(member, &error))) 00032 goto error; 00033 00034 osync_bool retval = FALSE; 00035 00036 char *old_anchor = NULL; 00037 osync_db_get_anchor(db, objtype, &old_anchor); 00038 00039 if (old_anchor) { 00040 if (!strcmp(old_anchor, new_anchor)) { 00041 retval = TRUE; 00042 } else { 00043 osync_trace(TRACE_INTERNAL, "Anchor mismatch"); 00044 retval = FALSE; 00045 } 00046 } else { 00047 osync_trace(TRACE_INTERNAL, "No previous anchor"); 00048 retval = FALSE; 00049 } 00050 00051 osync_db_close_anchor(db); 00052 00053 osync_trace(TRACE_EXIT, "%s: %i", __func__, retval); 00054 return retval; 00055 00056 error: 00057 osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); 00058 osync_error_free(&error); 00059 return FALSE; 00060 } 00061 00062 void osync_anchor_update(OSyncMember *member, const char *objtype, const char *new_anchor) 00063 { 00064 osync_trace(TRACE_ENTRY, "%s(%p, %s, %s)", __func__, member, objtype, new_anchor); 00065 g_assert(member); 00066 00067 OSyncError *error = NULL; 00068 OSyncDB *db = NULL; 00069 if (!(db = osync_db_open_anchor(member, &error))) 00070 goto error; 00071 00072 osync_db_put_anchor(db, objtype, new_anchor); 00073 osync_db_close_anchor(db); 00074 00075 osync_trace(TRACE_EXIT, "%s", __func__); 00076 return; 00077 00078 error: 00079 osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); 00080 osync_error_free(&error); 00081 return; 00082 } 00083 00084 char *osync_anchor_retrieve(OSyncMember *member, const char *objtype) 00085 { 00086 osync_trace(TRACE_ENTRY, "%s(%p, %s)", __func__, member, objtype); 00087 g_assert(member); 00088 00089 OSyncError *error = NULL; 00090 OSyncDB *db = NULL; 00091 if (!(db = osync_db_open_anchor(member, &error))) 00092 goto error; 00093 00094 char *anchor = NULL; 00095 osync_db_get_anchor(db, objtype, &anchor); 00096 osync_db_close_anchor(db); 00097 00098 osync_trace(TRACE_EXIT, "%s: %s", __func__, anchor); 00099 return anchor; 00100 00101 error: 00102 osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); 00103 osync_error_free(&error); 00104 return NULL; 00105 }