2009-02-17 12:18:15 +01:00
|
|
|
/*
|
2009-03-25 15:21:04 +01:00
|
|
|
* Copyright (C) 2009 Patrick Ohly <patrick.ohly@gmx.de>
|
|
|
|
* Copyright (C) 2009 Intel Corporation
|
2009-02-17 12:18:15 +01:00
|
|
|
*
|
2009-04-30 18:35:56 +02:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) version 3.
|
2009-02-17 12:18:15 +01:00
|
|
|
*
|
2009-04-30 18:35:56 +02:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2009-02-17 12:18:15 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2009-04-30 18:35:56 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2009-02-17 12:18:15 +01:00
|
|
|
*
|
2009-04-30 18:35:56 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301 USA
|
2009-02-17 12:18:15 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCL_SYNCML
|
|
|
|
#define INCL_SYNCML
|
|
|
|
|
|
|
|
#include <string>
|
2009-02-19 14:53:55 +01:00
|
|
|
#include <map>
|
|
|
|
#include <ostream>
|
2009-02-25 15:33:10 +01:00
|
|
|
#include <string.h>
|
2009-02-17 12:18:15 +01:00
|
|
|
|
2009-10-05 14:49:32 +02:00
|
|
|
#include <syncevo/declarations.h>
|
2009-10-02 17:23:53 +02:00
|
|
|
SE_BEGIN_CXX
|
|
|
|
|
2009-09-24 12:51:43 +02:00
|
|
|
/** alert Codes used at the synchronization initialization */
|
2009-02-17 12:18:15 +01:00
|
|
|
enum SyncMode {
|
2009-09-24 12:51:43 +02:00
|
|
|
/** unset or disabled */
|
2009-02-17 12:18:15 +01:00
|
|
|
SYNC_NONE,
|
2009-09-24 12:51:43 +02:00
|
|
|
|
|
|
|
SYNC_FIRST = 200,
|
|
|
|
SYNC_TWO_WAY = 200,
|
|
|
|
SYNC_SLOW = 201,
|
|
|
|
SYNC_ONE_WAY_FROM_CLIENT = 202,
|
|
|
|
SYNC_REFRESH_FROM_CLIENT = 203,
|
|
|
|
SYNC_ONE_WAY_FROM_SERVER = 204,
|
|
|
|
SYNC_REFRESH_FROM_SERVER = 205,
|
|
|
|
|
2009-11-13 05:31:06 +01:00
|
|
|
/** used by Server Alerted Sync **/
|
|
|
|
SA_SYNC_TWO_WAY = 206,
|
|
|
|
SA_SYNC_ONE_WAY_FROM_CLIENT = 207,
|
|
|
|
SA_SYNC_REFRESH_FROM_CLIENT = 208,
|
|
|
|
SA_SYNC_ONE_WAY_FROM_SERVER = 209,
|
|
|
|
SA_SYNC_REFRESH_FROM_SERVER = 210,
|
2009-12-22 09:47:31 +01:00
|
|
|
|
|
|
|
// used by restore backend with backup data, a pseudo mode
|
|
|
|
SYNC_RESTORE_FROM_BACKUP = 211,
|
|
|
|
|
2009-11-13 05:31:06 +01:00
|
|
|
SYNC_LAST = 220,
|
2009-09-24 12:51:43 +02:00
|
|
|
/** error situation (in contrast to SYNC_NONE) */
|
|
|
|
SYNC_INVALID = 255
|
2009-02-17 12:18:15 +01:00
|
|
|
};
|
|
|
|
|
2009-11-18 07:22:33 +01:00
|
|
|
/* According to OMNA WSP Content Type Numbers*/
|
|
|
|
enum ContentType {
|
|
|
|
WSPCTC_TEXT_PLAIN = 0x03,
|
|
|
|
WSPCTC_XVCALENDAR = 0x06,
|
|
|
|
WSPCTC_XVCARD = 0x07,
|
|
|
|
WSPCTC_ICALENDAR = 0x0305,
|
|
|
|
WSPCTC_VCARD = 0x0309,
|
|
|
|
WSPCTC_UNKNOWN =0xFFFFFF
|
|
|
|
};
|
|
|
|
|
2009-02-19 10:52:35 +01:00
|
|
|
/**
|
|
|
|
* Return string for sync mode. User-visible strings are the ones used
|
|
|
|
* in a sync source config ("two-way", "refresh-from-server", etc.).
|
|
|
|
* Otherwise the constants above are returned ("SYNC_NONE").
|
|
|
|
*/
|
|
|
|
std::string PrettyPrintSyncMode(SyncMode mode, bool userVisible = true);
|
|
|
|
|
2009-04-16 12:07:49 +02:00
|
|
|
/**
|
|
|
|
* Parse user-visible mode names.
|
|
|
|
*/
|
2009-11-13 05:31:06 +01:00
|
|
|
SyncMode StringToSyncMode(const std::string &str, bool serverAlerted = false);
|
2009-04-16 12:07:49 +02:00
|
|
|
|
2009-11-18 07:22:33 +01:00
|
|
|
/*
|
|
|
|
* Parse string based content type to WSPCTC encoded binary code
|
2009-12-15 10:06:45 +01:00
|
|
|
* Always use older type unless forceType is true.
|
2009-11-18 07:22:33 +01:00
|
|
|
*/
|
2009-12-15 10:06:45 +01:00
|
|
|
ContentType StringToContentType (const std::string &str, bool forceType);
|
2009-11-18 07:22:33 +01:00
|
|
|
|
2009-02-17 12:18:15 +01:00
|
|
|
/**
|
|
|
|
* result of SyncML operations, same codes as in HTTP and the Synthesis engine
|
|
|
|
*/
|
|
|
|
enum SyncMLStatus {
|
|
|
|
/** ok */
|
|
|
|
STATUS_OK = 0,
|
|
|
|
|
2009-05-08 09:57:28 +02:00
|
|
|
/** more explicit ok status in cases where 0 might mean "unknown" (SyncReport) */
|
|
|
|
STATUS_HTTP_OK = 200,
|
|
|
|
|
2009-02-17 12:18:15 +01:00
|
|
|
/** no content / end of file / end of iteration / empty/NULL value */
|
|
|
|
STATUS_NO_CONTENT = 204,
|
|
|
|
/** external data has been merged */
|
|
|
|
STATUS_DATA_MERGED = 207,
|
|
|
|
|
|
|
|
/** forbidden / access denied */
|
|
|
|
STATUS_FORBIDDEN = 403,
|
|
|
|
/** object not found / unassigned field */
|
|
|
|
STATUS_NOT_FOUND = 404,
|
|
|
|
/** command not allowed */
|
|
|
|
STATUS_COMMAND_NOT_ALLOWED = 405,
|
|
|
|
/** command failed / fatal DB error */
|
|
|
|
STATUS_FATAL = 500,
|
|
|
|
/** general DB error */
|
|
|
|
STATUS_DATASTORE_FAILURE = 510,
|
|
|
|
/** database / memory full error */
|
|
|
|
STATUS_FULL = 420,
|
|
|
|
|
|
|
|
STATUS_MAX = 0x7FFFFFF
|
|
|
|
};
|
|
|
|
|
2009-04-22 17:53:04 +02:00
|
|
|
/**
|
|
|
|
* Information about a database dump.
|
|
|
|
* Currently only records the number of items.
|
|
|
|
* A negative number of items means no backup
|
|
|
|
* available.
|
|
|
|
*/
|
|
|
|
class BackupReport {
|
|
|
|
public:
|
|
|
|
BackupReport() {
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isAvailable() const { return m_numItems >= 0; }
|
|
|
|
long getNumItems() const { return m_numItems; }
|
|
|
|
void setNumItems(long numItems) { m_numItems = numItems; }
|
|
|
|
|
|
|
|
void clear() {
|
|
|
|
m_numItems = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
long m_numItems;
|
|
|
|
};
|
|
|
|
|
2009-02-19 14:53:55 +01:00
|
|
|
class SyncSourceReport {
|
|
|
|
public:
|
|
|
|
SyncSourceReport() {
|
|
|
|
memset(m_stat, 0, sizeof(m_stat));
|
2009-02-19 16:00:26 +01:00
|
|
|
m_first =
|
|
|
|
m_resume = false;
|
|
|
|
m_mode = SYNC_NONE;
|
|
|
|
m_status = STATUS_OK;
|
2009-02-19 14:53:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
enum ItemLocation {
|
|
|
|
ITEM_LOCAL,
|
|
|
|
ITEM_REMOTE,
|
|
|
|
ITEM_LOCATION_MAX
|
|
|
|
};
|
2009-04-16 12:07:49 +02:00
|
|
|
static std::string LocationToString(ItemLocation location);
|
|
|
|
static ItemLocation StringToLocation(const std::string &location);
|
2009-02-19 14:53:55 +01:00
|
|
|
enum ItemState {
|
|
|
|
ITEM_ADDED,
|
|
|
|
ITEM_UPDATED,
|
|
|
|
ITEM_REMOVED,
|
|
|
|
ITEM_ANY,
|
|
|
|
ITEM_STATE_MAX
|
|
|
|
};
|
2009-04-16 12:07:49 +02:00
|
|
|
static std::string StateToString(ItemState state);
|
|
|
|
static ItemState StringToState(const std::string &state);
|
2009-02-19 14:53:55 +01:00
|
|
|
enum ItemResult {
|
|
|
|
ITEM_TOTAL, /**< total number ADDED/UPDATED/REMOVED */
|
|
|
|
ITEM_REJECT, /**< number of rejected items, ANY state */
|
|
|
|
ITEM_MATCH, /**< number of matched items, ANY state, REMOTE */
|
|
|
|
ITEM_CONFLICT_SERVER_WON, /**< conflicts resolved by using server item, ANY state, REMOTE */
|
|
|
|
ITEM_CONFLICT_CLIENT_WON, /**< conflicts resolved by using client item, ANY state, REMOTE */
|
|
|
|
ITEM_CONFLICT_DUPLICATED, /**< conflicts resolved by duplicating item, ANY state, REMOTE */
|
|
|
|
ITEM_SENT_BYTES, /**< number of sent bytes, ANY, LOCAL */
|
|
|
|
ITEM_RECEIVED_BYTES, /**< number of received bytes, ANY, LOCAL */
|
|
|
|
ITEM_RESULT_MAX
|
|
|
|
};
|
2009-04-16 12:07:49 +02:00
|
|
|
static std::string ResultToString(ItemResult result);
|
|
|
|
static ItemResult StringToResult(const std::string &result);
|
|
|
|
|
|
|
|
static std::string StatTupleToString(ItemLocation location, ItemState state, ItemResult result);
|
|
|
|
static void StringToStatTuple(const std::string &str, ItemLocation &location, ItemState &state, ItemResult &result);
|
2009-02-19 14:53:55 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get item statistics
|
|
|
|
*
|
|
|
|
* @param location either local or remote
|
|
|
|
* @param state added, updated or removed
|
|
|
|
* @param success either okay or failed
|
|
|
|
*/
|
|
|
|
int getItemStat(ItemLocation location,
|
|
|
|
ItemState state,
|
|
|
|
ItemResult success) const {
|
|
|
|
return m_stat[location][state][success];
|
|
|
|
}
|
|
|
|
void setItemStat(ItemLocation location,
|
|
|
|
ItemState state,
|
|
|
|
ItemResult success,
|
|
|
|
int count) {
|
|
|
|
m_stat[location][state][success] = count;
|
|
|
|
}
|
2009-04-23 16:47:07 +02:00
|
|
|
void incrementItemStat(ItemLocation location,
|
|
|
|
ItemState state,
|
|
|
|
ItemResult success) {
|
|
|
|
m_stat[location][state][success]++;
|
|
|
|
}
|
2009-02-19 14:53:55 +01:00
|
|
|
|
2009-02-19 16:00:26 +01:00
|
|
|
void recordFinalSyncMode(SyncMode mode) { m_mode = mode; }
|
|
|
|
SyncMode getFinalSyncMode() const { return m_mode; }
|
|
|
|
|
|
|
|
void recordFirstSync(bool isFirstSync) { m_first = isFirstSync; }
|
|
|
|
bool isFirstSync() const { return m_first; }
|
|
|
|
|
|
|
|
void recordResumeSync(bool isResumeSync) { m_resume = isResumeSync; }
|
|
|
|
bool isResumeSync() const { return m_resume; }
|
|
|
|
|
|
|
|
void recordStatus(SyncMLStatus status ) { m_status = status; }
|
|
|
|
SyncMLStatus getStatus() const { return m_status; }
|
|
|
|
|
2009-04-22 17:53:04 +02:00
|
|
|
/** information about database dump before and after session */
|
|
|
|
BackupReport m_backupBefore, m_backupAfter;
|
|
|
|
|
2009-02-19 14:53:55 +01:00
|
|
|
private:
|
2009-04-16 12:07:49 +02:00
|
|
|
/** storage for getItemStat(): allow access with _MAX as index */
|
|
|
|
int m_stat[ITEM_LOCATION_MAX + 1][ITEM_STATE_MAX + 1][ITEM_RESULT_MAX + 1];
|
2009-02-19 16:00:26 +01:00
|
|
|
|
|
|
|
SyncMode m_mode;
|
|
|
|
bool m_first;
|
|
|
|
bool m_resume;
|
|
|
|
SyncMLStatus m_status;
|
2009-02-19 14:53:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class SyncReport : public std::map<std::string, SyncSourceReport> {
|
2009-04-15 21:03:26 +02:00
|
|
|
time_t m_start, m_end;
|
2009-05-08 09:57:28 +02:00
|
|
|
SyncMLStatus m_status;
|
2009-12-04 16:43:33 +01:00
|
|
|
std::string m_error;
|
2009-04-15 21:03:26 +02:00
|
|
|
|
2009-02-19 14:53:55 +01:00
|
|
|
public:
|
2009-04-15 21:03:26 +02:00
|
|
|
SyncReport() :
|
|
|
|
m_start(0),
|
2009-05-08 09:57:28 +02:00
|
|
|
m_end(0),
|
|
|
|
m_status(STATUS_OK)
|
2009-04-15 21:03:26 +02:00
|
|
|
{}
|
|
|
|
|
2009-02-19 14:53:55 +01:00
|
|
|
void addSyncSourceReport(const std::string &name,
|
|
|
|
const SyncSourceReport &report) {
|
|
|
|
(*this)[name] = report;
|
|
|
|
}
|
2009-04-16 12:07:49 +02:00
|
|
|
SyncSourceReport &getSyncSourceReport(const std::string &name) {
|
2009-02-19 14:53:55 +01:00
|
|
|
return (*this)[name];
|
|
|
|
}
|
2009-04-15 21:03:26 +02:00
|
|
|
|
|
|
|
/** start time of sync, 0 if unknown */
|
|
|
|
time_t getStart() const { return m_start; }
|
|
|
|
void setStart(time_t start) { m_start = start; }
|
|
|
|
/** end time of sync, 0 if unknown (indicates a crash) */
|
|
|
|
time_t getEnd() const { return m_end; }
|
|
|
|
void setEnd(time_t end) { m_end = end; }
|
|
|
|
|
2009-05-08 09:57:28 +02:00
|
|
|
/**
|
|
|
|
* overall sync result
|
|
|
|
*
|
|
|
|
* STATUS_OK = 0 means unknown status (might have aborted prematurely),
|
|
|
|
* STATUS_HTTP_OK = 200 means successful completion
|
|
|
|
*/
|
|
|
|
SyncMLStatus getStatus() const { return m_status; }
|
|
|
|
void setStatus(SyncMLStatus status) { m_status = status; }
|
|
|
|
|
2009-12-04 16:43:33 +01:00
|
|
|
/**
|
|
|
|
* Initial ERROR description as seen by SyncEvolution,
|
|
|
|
* typically via the logging infrastructure. Not localized.
|
|
|
|
*/
|
|
|
|
std::string getError() const { return m_error; }
|
|
|
|
void setError(const std::string &error) { m_error = error; }
|
|
|
|
|
2009-04-15 21:03:26 +02:00
|
|
|
void clear() {
|
|
|
|
std::map<std::string, SyncSourceReport>::clear();
|
|
|
|
m_start = m_end = 0;
|
2009-12-04 16:43:33 +01:00
|
|
|
m_error = "";
|
|
|
|
m_status = STATUS_OK;
|
2009-04-15 21:03:26 +02:00
|
|
|
}
|
2009-04-16 09:26:14 +02:00
|
|
|
|
|
|
|
/** generate short string representing start and duration of sync */
|
|
|
|
std::string formatSyncTimes() const;
|
2009-04-29 16:55:31 +02:00
|
|
|
|
|
|
|
/** pretty-print with options */
|
|
|
|
void prettyPrint(std::ostream &out, int flags) const;
|
|
|
|
enum {
|
|
|
|
WITHOUT_CLIENT = 1 << 1,
|
|
|
|
WITHOUT_SERVER = 1 << 2,
|
|
|
|
WITHOUT_CONFLICTS = 1 << 3,
|
|
|
|
WITHOUT_REJECTS = 1 << 4,
|
|
|
|
WITH_TOTAL = 1 << 5
|
|
|
|
};
|
2009-02-19 14:53:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/** pretty-print the report as an ASCII table */
|
|
|
|
std::ostream &operator << (std::ostream &out, const SyncReport &report);
|
|
|
|
|
2009-04-29 11:45:11 +02:00
|
|
|
class ConfigNode;
|
|
|
|
|
|
|
|
/** write report into a ConfigNode */
|
|
|
|
ConfigNode &operator << (ConfigNode &node, const SyncReport &report);
|
|
|
|
|
|
|
|
/** read report from a ConfigNode */
|
|
|
|
ConfigNode &operator >> (ConfigNode &node, SyncReport &report);
|
2009-02-19 14:53:55 +01:00
|
|
|
|
2009-10-02 17:23:53 +02:00
|
|
|
|
|
|
|
SE_END_CXX
|
2009-02-17 12:18:15 +01:00
|
|
|
#endif // INCL_SYNCML
|