00001 /* 00002 * Copyright (C) 2007-2008 Patrick Ohly 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 */ 00018 00019 #ifndef INCL_FILESYNCSOURCE 00020 #define INCL_FILESYNCSOURCE 00021 00022 #include "TrackingSyncSource.h" 00023 00024 #ifdef ENABLE_FILE 00025 00026 #include <memory> 00027 #include <boost/noncopyable.hpp> 00028 00029 /** 00030 * Stores each SyncML item as a separate file in a directory. The 00031 * directory has to be specified via the database name, using 00032 * [file://]<path> as format. The file:// prefix is optional, but the 00033 * directory is only created if it is used. 00034 * EvolutionSyncSource::getDatabaseID() gives us the database name. 00035 * 00036 * Change tracking is done via the file systems modification time 00037 * stamp: editing a file treats it as modified and then sends it to 00038 * the server in the next sync. Removing and adding files also works. 00039 * 00040 * The local unique identifier for each item is its name in the 00041 * directory. New files are created using a running count which 00042 * initialized based on the initial content of the directory to 00043 * "highest existing number + 1" and incremented to avoid collisions. 00044 * 00045 * Although this sync source itself does not care about the content of 00046 * each item/file, the server needs to know what each item sent to it 00047 * contains and what items the source is able to receive. Therefore 00048 * the "type" property for this source must contain a data format 00049 * specified, including a version for it. Here are some examples: 00050 * - type=file:text/vcard:3.0 00051 * - type=file:text/plain:1.0 00052 */ 00053 class FileSyncSource : public TrackingSyncSource, private boost::noncopyable 00054 { 00055 public: 00056 FileSyncSource(const EvolutionSyncSourceParams ¶ms, 00057 const string &dataformat); 00058 00059 00060 protected: 00061 /* implementation of EvolutionSyncSource interface */ 00062 virtual void open(); 00063 virtual void close(); 00064 virtual Databases getDatabases(); 00065 virtual SyncItem *createItem(const string &uid); 00066 virtual string fileSuffix() const; 00067 virtual const char *getMimeType() const; 00068 virtual const char *getMimeVersion() const; 00069 virtual const char *getSupportedTypes() const; 00070 virtual void logItem(const string &uid, const string &info, bool debug = false); 00071 virtual void logItem(const SyncItem &item, const string &info, bool debug = false); 00072 00073 /* implementation of TrackingSyncSource interface */ 00074 virtual void listAllItems(RevisionMap_t &revisions); 00075 virtual InsertItemResult insertItem(const string &uid, const SyncItem &item); 00076 virtual void deleteItem(const string &uid); 00077 00078 private: 00079 /** 00080 * @name values obtained from the source's type property 00081 * 00082 * Other sync sources only support one hard-coded type and 00083 * don't need such variables. 00084 */ 00085 /**@{*/ 00086 string m_mimeType; 00087 string m_mimeVersion; 00088 string m_supportedTypes; 00089 /**@}*/ 00090 00091 /** directory selected via the database name in open(), reset in close() */ 00092 string m_basedir; 00093 /** a counter which is used to name new files */ 00094 long m_entryCounter; 00095 00096 /** 00097 * get access time for file, formatted as revision string 00098 * @param filename absolute path or path relative to current directory 00099 */ 00100 string getATimeString(const string &filename); 00101 00102 /** 00103 * create full filename from basedir and entry name 00104 */ 00105 string createFilename(const string &entry); 00106 }; 00107 00108 #endif // ENABLE_FILE 00109 #endif // INCL_FILESYNCSOURCE