config: sanitize maxMsgSize and maxObjSize while reading from config

Unusually small values were ignored during syncing. Doing this in the config
access methods instead of the sync session setup ensures that all components
in SyncEvolution use the same value.
This commit is contained in:
Patrick Ohly 2014-09-08 01:52:00 -07:00
parent 9ea6379f98
commit 345a58abe4
2 changed files with 21 additions and 4 deletions

View File

@ -2291,9 +2291,26 @@ void SyncConfig::setSyncURL(const vector<string> &value, bool temporarily) {
}
InitStateString SyncConfig::getClientAuthType() const { return syncPropClientAuthType.getProperty(*getNode(syncPropClientAuthType)); }
void SyncConfig::setClientAuthType(const string &value, bool temporarily) { syncPropClientAuthType.setProperty(*getNode(syncPropClientAuthType), value, temporarily); }
InitState<unsigned long > SyncConfig::getMaxMsgSize() const { return syncPropMaxMsgSize.getPropertyValue(*getNode(syncPropMaxMsgSize)); }
template<class T> InitState<T> EnsureMinSize(const InitState<T> &current, T min)
{
if (current >= min) {
return current;
} else {
return InitState<T>(min);
}
}
InitState<unsigned long > SyncConfig::getMaxMsgSize() const {
// Sanitize value: don't run with buffer sizes smaller than 10KB.
return EnsureMinSize(syncPropMaxMsgSize.getPropertyValue(*getNode(syncPropMaxMsgSize)),
10 * 1024ul);
}
void SyncConfig::setMaxMsgSize(unsigned long value, bool temporarily) { syncPropMaxMsgSize.setProperty(*getNode(syncPropMaxMsgSize), value, temporarily); }
InitState<unsigned int > SyncConfig::getMaxObjSize() const { return syncPropMaxObjSize.getPropertyValue(*getNode(syncPropMaxObjSize)); }
InitState<unsigned int > SyncConfig::getMaxObjSize() const {
return EnsureMinSize(syncPropMaxObjSize.getPropertyValue(*getNode(syncPropMaxObjSize)),
1024u);
}
void SyncConfig::setMaxObjSize(unsigned int value, bool temporarily) { syncPropMaxObjSize.setProperty(*getNode(syncPropMaxObjSize), value, temporarily); }
InitStateString SyncConfig::getDevID() const { return syncPropDevID.getProperty(*getNode(syncPropDevID)); }
void SyncConfig::setDevID(const string &value, bool temporarily) { syncPropDevID.setProperty(*getNode(syncPropDevID), value, temporarily); }

View File

@ -2945,8 +2945,8 @@ void SyncContext::getConfigXML(bool isSync, string &xml, string &configname)
// abuse (?) the firmware version to store the SyncEvolution version number
substTag(xml, "firmwareversion", getSwv());
substTag(xml, "devicetype", getDevType());
substTag(xml, "maxmsgsize", std::max(getMaxMsgSize().get(), 10000ul));
substTag(xml, "maxobjsize", std::max(getMaxObjSize().get(), 1024u));
substTag(xml, "maxmsgsize", getMaxMsgSize().get());
substTag(xml, "maxobjsize", getMaxObjSize().get());
if (m_serverMode) {
UserIdentity id = getSyncUser();
Credentials cred = IdentityProviderCredentials(id, getSyncPassword());