2 * File: RemoteDataStore.cpp
4 * Author: Lukas Zeller (luz@synthesis.ch)
7 * Abstraction of remote data store for SyncML Server
8 * Buffers and forwards incoming remote data store commands for
9 * processing by sync engine.
11 * Copyright (c) 2001-2009 by Synthesis AG (www.synthesis.ch)
13 * 2001-06-12 : luz : created
18 #include "prefix_file.h"
20 #include "syncagent.h"
21 #include "remotedatastore.h"
24 using namespace sysync;
28 * Implementation of TRemoteDataStore
31 void TRemoteDataStore::init(void)
34 } // TSyncDataStore::init
37 void TRemoteDataStore::InternalResetDataStore(void)
39 // for server, get default GUID size (in case remote devInf does not send one)
42 fMaxGUIDSize = static_cast<TAgentConfig *>(getSession()->getSessionConfig())->fMaxGUIDSizeSent;
45 } // TRemoteDataStore::InternalResetDataStore
48 TRemoteDataStore::TRemoteDataStore(TSyncSession *aSessionP) :
49 TSyncDataStore(aSessionP)
52 } // TSyncDataStore::TSyncDataStore
55 TRemoteDataStore::TRemoteDataStore(
56 TSyncSession *aSessionP, const char *aName,
57 uInt32 aCommonSyncCapMask
59 TSyncDataStore(aSessionP, aName, aCommonSyncCapMask)
61 // assume full name same as real name, but could be updated at <alert> or <sync>
63 } // TSyncDataStore::TSyncDataStore
67 TRemoteDataStore::~TRemoteDataStore()
69 InternalResetDataStore();
71 } // TRemoteDataStore::~TRemoteDataStore
74 // - return pure relative (item) URI (removes absolute part or ./ prefix)
75 const char *TRemoteDataStore::DatastoreRelativeURI(const char *aURI)
77 return relativeURI(aURI,fSessionP->getRemoteURI());
78 } // TRemoteDataStore::DatastoreRelativeURI
81 // check if this remote datastore is accessible with given URI
82 // NOTE: URI might include path elements or CGI params that are
83 // access options to the database.
84 // Remote datastores however only represent devinf, so
85 // it counts as name match if start of specified URI matches
86 // name and then continues with "/" or "?" (subpaths and CGI ignored)
87 uInt16 TRemoteDataStore::isDatastore(const char *aDatastoreURI)
89 // - make pure relative paths
90 const char *nam=DatastoreRelativeURI(fName.c_str());
92 const char *uri=DatastoreRelativeURI(aDatastoreURI);
93 // - compare up to end of local name
94 if (strucmp(nam,uri,n,n)==0) {
96 char c=uri[n]; // terminating char
97 // match if full match, or uri continues with '/' or '?'
98 // Note: return number of chars matched, to allow search for best match
99 return (c==0 || c=='/' || c=='?') ? n : 0;
102 return 0; // no match
103 } // TRemoteDataStore::isDatastore
107 // SYNC command bracket start (check credentials if needed)
108 bool TRemoteDataStore::remoteProcessSyncCmd(
109 SmlSyncPtr_t aSyncP, // the Sync element
110 TStatusCommand &aStatusCommand, // status that might be modified
111 bool &aQueueForLater // will be set if command must be queued for later (re-)execution
114 // adjust name of datastore (may include subpath or CGI)
115 fFullName = smlSrcTargLocURIToCharP(aSyncP->source);
116 // read meta of Sync Command for remote datastore
117 // NOTE: this will overwrite Max values eventually read from DevInf
118 // as meta is more accurate (actual free bytes/ids, not total)
119 SmlMetInfMetInfPtr_t metaP = smlPCDataToMetInfP(aSyncP->meta);
123 if (metaP->mem->free)
124 if (!StrToLongLong(smlPCDataToCharP(metaP->mem->free),fFreeMemory))
127 if (metaP->mem->freeid)
128 if (!StrToLongLong(smlPCDataToCharP(metaP->mem->freeid),fFreeID))
131 PDEBUGPRINTFX(DBG_REMOTEINFO,("Sync Meta provides memory constraints: FreeMem=" PRINTF_LLD ", FreeID=" PRINTF_LLD,PRINTF_LLD_ARG(fFreeMemory),PRINTF_LLD_ARG(fFreeID)));
134 } // TRemoteDataStore::remoteProcessSyncCmd
137 // SYNC command bracket end (but another might follow in next message)
138 bool TRemoteDataStore::remoteProcessSyncCmdEnd(void)
140 // %%% nop for now, %%% eventually obsolete
142 } // TRemoteDataStore::remoteProcessSyncCmdEnd
145 // end of all sync commands from client
146 bool TRemoteDataStore::endOfClientSyncCmds(void)
148 // %%% nop for now, %%% eventually obsolete
150 } // TRemoteDataStore::endOfClientSyncCmds
153 // set description structure of datastore
154 bool TRemoteDataStore::setDatastoreDevInf(
155 SmlDevInfDatastorePtr_t aDataStoreDevInfP, // the datastore DevInf
156 TSyncItemTypePContainer &aLocalItemTypes, // list to look up local types (for reference)
157 TSyncItemTypePContainer &aNewItemTypes // list to add analyzed types if not already there
160 // get important info out of the structure
162 // - name (sourceRef)
163 fName=smlPCDataToCharP(aDataStoreDevInfP->sourceref);
166 fDisplayName=smlPCDataToCharP(aDataStoreDevInfP->displayname);
169 if (aDataStoreDevInfP->maxguidsize) {
170 if (!StrToLong(smlPCDataToCharP(aDataStoreDevInfP->maxguidsize),fMaxGUIDSize))
174 PDEBUGPRINTFX(DBG_REMOTEINFO,("Datastore DevInf does not specify MaxGUIDSize -> using default"));
176 PDEBUGPRINTFX(DBG_REMOTEINFO+DBG_HOT,(
177 "Remote Datastore Name='%s', DisplayName='%s', MaxGUIDSize=%ld",
182 PDEBUGPRINTFX(DBG_REMOTEINFO,(
183 "Preferred Rx='%s' version '%s', preferred Tx='%s' version '%s'",
184 smlPCDataToCharP(aDataStoreDevInfP->rxpref->cttype),
185 smlPCDataToCharP(aDataStoreDevInfP->rxpref->verct),
186 smlPCDataToCharP(aDataStoreDevInfP->txpref->cttype),
187 smlPCDataToCharP(aDataStoreDevInfP->txpref->verct)
189 // - analyze DS 1.2 style datastore local CTCap
190 if (getSession()->getSyncMLVersion()>=syncml_vers_1_2) {
191 // analyze CTCaps (content type capabilities)
192 SmlDevInfCtcapListPtr_t ctlP = aDataStoreDevInfP->ctcap;
194 PDEBUGBLOCKDESC("RemoteTypes", "Analyzing remote types listed in datastore level CTCap");
195 if (getSession()->fIgnoreCTCap) {
198 PDEBUGPRINTFX(DBG_REMOTEINFO+DBG_HOT,("Remote rule prevents looking at CTCap"));
204 // create appropriate remote data itemtypes
205 if (TSyncItemType::analyzeCTCapAndCreateItemTypes(
207 this, // this is the DS1.2 style where CTCap is related to this datastore
209 aLocalItemTypes, // look up in local types for specialized classes
210 aNewItemTypes // add new item types here
212 // we have CTCap info of at least one remote type
213 getSession()->fRemoteDataTypesKnown=true;
222 PDEBUGENDBLOCK("RemoteTypes");
224 // - analyze supported rx types
225 TSyncDataStore *relDsP = getSession()->getSyncMLVersion()>=syncml_vers_1_2 ? this : NULL;
226 fRxPrefItemTypeP=TSyncItemType::registerType(fSessionP,aDataStoreDevInfP->rxpref,aLocalItemTypes,aNewItemTypes,relDsP);
227 fRxItemTypes.push_back(fRxPrefItemTypeP);
228 registerTypes(fRxItemTypes,aDataStoreDevInfP->rx,aLocalItemTypes,aNewItemTypes,relDsP);
229 // - analyze supported tx types
230 fTxPrefItemTypeP=TSyncItemType::registerType(fSessionP,aDataStoreDevInfP->txpref,aLocalItemTypes,aNewItemTypes,relDsP);
231 fTxItemTypes.push_back(fTxPrefItemTypeP);
232 registerTypes(fTxItemTypes,aDataStoreDevInfP->tx,aLocalItemTypes,aNewItemTypes,relDsP);
233 // - Datastore Memory
234 if (aDataStoreDevInfP->dsmem) {
235 // datastore provides memory information
236 // Note: <Sync> command meta could override these with actual free info
238 if (aDataStoreDevInfP->dsmem->maxmem) {
239 if (!StrToLongLong(smlPCDataToCharP(aDataStoreDevInfP->dsmem->maxmem),fMaxMemory))
242 fFreeMemory=fMaxMemory; // default for free = max (sync meta might correct this)
245 if (aDataStoreDevInfP->dsmem->maxid) {
246 if (!StrToLongLong(smlPCDataToCharP(aDataStoreDevInfP->dsmem->maxid),fMaxID))
249 fFreeID=fMaxID; // default for free = max (sync meta might correct this)
251 PDEBUGPRINTFX(DBG_REMOTEINFO,("DevInf provides DSMem: MaxMem=" PRINTF_LLD ", MaxID=" PRINTF_LLD,PRINTF_LLD_ARG(fFreeMemory),PRINTF_LLD_ARG(fMaxID)));
255 DEBUGPRINTFX(DBG_ERROR,("******** setDatastoreDevInf caused exception"));
259 } // TRemoteDataStore::setDatastoreDevInf
262 /* end of TRemoteDataStore implementation */