00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "data_sync_common.h"
00022 #include "libsyncml/syncml_internals.h"
00023 #include "libsyncml/sml_error_internals.h"
00024
00025 #include "data_sync_devinf.h"
00026
00027 SmlBool smlDataSyncIsTimestamp(const char *anchor, SmlBool timestampDefault)
00028 {
00029 smlTrace(TRACE_ENTRY, "%s(%s, %d)", __func__, VA_STRING(anchor), timestampDefault);
00030 if (anchor == NULL || strlen(anchor) < 1)
00031 {
00032
00033 smlTrace(TRACE_EXIT, "%s - default", __func__);
00034 return timestampDefault;
00035 } else {
00036
00037 if (strstr(anchor, "Z")) {
00038
00039 smlTrace(TRACE_EXIT, "%s - TRUE", __func__);
00040 return TRUE;
00041 } else {
00042
00043 smlTrace(TRACE_EXIT, "%s - FALSE", __func__);
00044 return FALSE;
00045 }
00046 }
00047 }
00048
00049 char *smlDataSyncGetNextAnchor(
00050 SmlDataSyncDatastore *datastore,
00051 const char *last,
00052 SmlError **error)
00053 {
00054 smlTrace(TRACE_ENTRY, "%s(%s)", __func__, VA_STRING(last));
00055 CHECK_ERROR_REF
00056 SmlBool use_timestamp = TRUE;
00057 char *next = NULL;
00058
00059 use_timestamp = smlDataSyncIsTimestamp(last,
00060 datastore->dsObject->useTimestampAnchor);
00061 smlTrace(TRACE_INTERNAL, "%s: use timestamp is %d", __func__, use_timestamp);
00062
00063 if (use_timestamp)
00064 {
00065
00066 smlTrace(TRACE_INTERNAL,
00067 "%s: session %p, localtime %d, remoteDevInf %p",
00068 __func__,
00069 datastore->dsObject->session,
00070 datastore->dsObject->onlyLocaltime,
00071 datastore->dsObject->remoteDevInf);
00072 if (datastore->dsObject->session &&
00073 !datastore->dsObject->onlyLocaltime &&
00074 !datastore->dsObject->remoteDevInf &&
00075 !smlDataSyncManageDevInf(datastore->dsObject, FALSE, error))
00076 {
00077 goto error;
00078 }
00079 next = smlTryMalloc0(sizeof(char)*17, error);
00080 if (!next)
00081 goto error;
00082 time_t htime = time(NULL);
00083 if (datastore->dsObject->onlyLocaltime) {
00084 smlTrace(TRACE_INTERNAL, "%s: use localtime", __func__);
00085 strftime(next, 17, "%Y%m%dT%H%M%SZ", localtime(&htime));
00086 } else {
00087 smlTrace(TRACE_INTERNAL, "%s: use UTC", __func__);
00088 strftime(next, 17, "%Y%m%dT%H%M%SZ", gmtime(&htime));
00089 }
00090 } else {
00091 if (last == NULL)
00092 {
00093 next = g_strdup("1");
00094 } else {
00095 unsigned long count = strtoul(last, NULL, 10);
00096 count++;
00097 next = g_strdup_printf("%lu", count);
00098 }
00099 }
00100 smlTrace(TRACE_EXIT, "%s(%s)", __func__, VA_STRING(next));
00101 return next;
00102 error:
00103 smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error));
00104 return NULL;
00105 }