void run() { AkonadiSource *source = appSource->getSyncSource(); AppSyncSourceConfig* sourceConfig = appSource->getConfig(); source->setCollectionId(sourceConfig->getCollectionId()); SyncSourceConfig *srcConfig = KFunSyncConfig::getInstance()->getSyncSourceConfig(source->getName()); if (srcConfig != NULL) { source->setConfig(srcConfig); } const char* remoteUri = sourceConfig->getRemoteUri(); if (remoteUri == NULL || strlen(remoteUri) == 0) { sourceConfig->setRemoteUri(srcConfig->getURI()); sourceConfig->save(); } else { srcConfig->setURI(remoteUri); } SyncSource* ssArray[] = { source, NULL } ; if (client->sync(*KFunSyncConfig::getInstance(), ssArray)) { LOG.error("Error during sync.\n"); } // Save the anchors KFunSyncConfig::getInstance()->save(); manager->emitSourceEnded(appSource, client->getSyncReport()); }
void setUp() { // Create the output dir outputDir = getTestDirFullPath(TEST_INPUT_DIR); createFolder(outputDir.c_str()); MediaSyncSourceParams params_; params_.setUrl(HTTPUPLOADER_URL); SyncSourceConfig* fssc = new SyncSourceConfig(); fssc->setURI("testMss"); // Create the FileSyncSource fmss = new FakeMediaSource(TEXT("testMss"), fssc, outputDir, params_); ssr = new SyncSourceReport("testMss"); fmss->setReport(ssr); }
void CPicturesSettings::loadSyncModesBox(const char* sourceName) { OutlookConfig* config = getConfig(); SyncSourceConfig* ssconf = config->getSyncSourceConfig(sourceName); if (!ssconf) return; // TODO: use a switch on sourceName when refactoring int editBoxResourceID = IDC_PICTURES_EDIT_SYNCTYPE; int comboBoxResourceID = IDC_PICTURES_COMBO_SYNCTYPE; CEdit* editbox = (CEdit*)GetDlgItem(editBoxResourceID); CComboBox* combobox = (CComboBox*)GetDlgItem(comboBoxResourceID); if (!combobox || !editbox) return; // // Load the syncmodes in the editbox/dropdown // CString s1 = ""; StringBuffer syncModes(ssconf->getSyncModes()); if (syncModes.find(SYNC_MODE_TWO_WAY) != StringBuffer::npos) { s1.LoadString(IDS_SYNCTYPE1); combobox->AddString(s1); } if (syncModes.find(SYNC_MODE_ONE_WAY_FROM_SERVER) != StringBuffer::npos || syncModes.find(SYNC_MODE_SMART_ONE_WAY_FROM_SERVER) != StringBuffer::npos) { s1.LoadString(IDS_SYNCTYPE2); combobox->AddString(s1); } if (syncModes.find(SYNC_MODE_ONE_WAY_FROM_CLIENT) != StringBuffer::npos || syncModes.find(SYNC_MODE_SMART_ONE_WAY_FROM_CLIENT) != StringBuffer::npos) { s1.LoadString(IDS_SYNCTYPE3); combobox->AddString(s1); } if (combobox->GetCount() > 1) { // More than 1 syncmode available: use the dropdown box editbox->ShowWindow(SW_HIDE); combobox->ShowWindow(SW_SHOW); } else { // Only 1 syncmode available: use the editbox editbox->ShowWindow(SW_SHOW); combobox->ShowWindow(SW_HIDE); SetDlgItemText(editBoxResourceID, s1); } }
WindowsSyncSource* createAppointmentWindowsSyncSource() { OutlookConfig* config = getConfig(); config->getServerConfig().setNoFieldLevelReplace("event"); WIN_ASSERT_NOT_NULL(config, TEXT("The config is null. Please verify the an Outlook client is already installed")); SyncSourceConfig* sc = config->getSyncSourceConfig(APPOINTMENT_); WindowsSyncSource* ss = new WindowsSyncSource(APPOINTMENT, sc); int ret = ss->beginSync(); WIN_ASSERT_ZERO(ret, TEXT("beginSync is not 0")); SyncSourceReport* ssReport = new SyncSourceReport(); ssReport->setSourceName(sc->getName()); ssReport->setState(SOURCE_ACTIVE); ss->setReport(ssReport); return ss; }
virtual int sync( const int *activeSources, SyncMode syncMode, const CheckSyncReport &checkReport, long maxMsgSize, long maxObjSize, bool loSupport, const char *encoding = 0) { SyncSource **syncSources = new SyncSource *[sources.size() + 1]; int index, numsources = 0; memset(syncSources, 0, sizeof(syncSources[0]) * (sources.size() + 1)); for (index = 0; activeSources[index] >= 0 && index < (int)sources.size(); index++) { // rewrite configuration as needed for test SyncSourceConfig *sourceConfig = config->getSyncSourceConfig(sources[activeSources[index]].c_str()); CPPUNIT_ASSERT(sourceConfig); sourceConfig->setSync(syncModeKeyword(syncMode)); sourceConfig->setEncoding(encoding); config->getAccessConfig().setMaxMsgSize(maxMsgSize); config->getDeviceConfig().setMaxObjSize(maxObjSize); config->getDeviceConfig().setLoSupport(loSupport); // create sync source using the third change tracking for syncs syncSources[numsources++] = createSource(activeSources[index], "S"); } SyncClient client; int res = client.sync(*config, syncSources); CPPUNIT_ASSERT(client.getSyncReport()); for (int source = 0; syncSources[source]; source++) { delete syncSources[source]; } checkReport.check(res, *client.getSyncReport()); return res; }
bool SyncManagerConfig::setSyncSourceConfig(SyncSourceConfig& sc) { unsigned int i=0; for (i=0; i<sourceConfigsCount; ++i) { if (strcmp(sc.getName(), sourceConfigs[i].getName()) == 0) { break; } } if (i >= sourceConfigsCount) { // // Not found! -> add the SyncSourceConfig. // return addSyncSourceConfig(sc); } if ( strcmp( sc.getName(), "mail") == 0 ){ ((MailSyncSourceConfig&)(sourceConfigs[i])).assign(((MailSyncSourceConfig&)(sourceConfigs[i]))); }else{ sourceConfigs[i].assign(sc); } //dirty |= DIRTY_SYNC_SOURCE; return true; }
/* * Add the passed SyncSourceConfig (the object is copied). * If SyncSourceConfig name is already present (match name) the * config is replaced with the given one. * Otherwise it is added in the sourceConfig array. */ bool SyncManagerConfig::addSyncSourceConfig(SyncSourceConfig& sc) { unsigned int i = 0; SyncSourceConfig* s = NULL; // copy array in a tmp buffer if (sourceConfigsCount > 0) { s = new SyncSourceConfig[sourceConfigsCount]; for (i=0; i<sourceConfigsCount; i++) { if (strcmp(sourceConfigs[i].getName(), "mail") == 0) { ((MailSyncSourceConfig&)s[i]).assign(((MailSyncSourceConfig&)(sourceConfigs[i]))); } else { s[i].assign(sourceConfigs[i]); } } } // delete old one, create new (+1 element) if (sourceConfigs) { delete [] sourceConfigs; } sourceConfigs = new SyncSourceConfig[sourceConfigsCount + 1]; // copy back. for (i = 0; i < sourceConfigsCount; i++) { if (strcmp(s[i].getName(), "mail") == 0) { ((MailSyncSourceConfig &)sourceConfigs[i]).assign(((MailSyncSourceConfig&)(s[i]))); } else { sourceConfigs[i].assign(s[i]); } } sourceConfigsCount++; if (strcmp(sc.getName(), "mail") == 0) { ((MailSyncSourceConfig&)(sourceConfigs[i])).assign(((MailSyncSourceConfig&)(sc))); } else { sourceConfigs[i].assign(sc); } if (s) { delete [] s; } return true; }
void doSync() { using namespace Funambol; std::stringstream log; log << "Syncing: " << user << ":" << password << "@" << server << ". Calendar: " << doCalendar << ", Contacts: " << doContacts << "."; LOG.info(log.str().c_str()); //create config object. StringMap env; env.put("HOME_FOLDER","/media/internal/.webOsSyncML"); env.put("CONFIG_FOLDER","/media/internal/.webOsSyncML/config"); PlatformAdapter::init("mobo/webOsSyncML",env); DMTClientConfig config; SyncSource* ssArray[3]; int ssIndex = 0; ssArray[0] = ssArray[1] = ssArray[2] = NULL; //fill some config values if(!config.read()) { PDL_GetDeviceName(buffer,BUFFERLEN); std::string id = "";//"webOsSyncML"; id.append(buffer); PDL_GetUniqueID(buffer,BUFFERLEN); id.append(buffer); //config.getDeviceConfig().setDevType("smartphone"); config.getDeviceConfig().setDevID(id.c_str()); config.getAccessConfig().setClientAuthType(AUTH_TYPE_MD5); } //fill access values: config.getAccessConfig().setSyncURL(server.c_str()); config.getAccessConfig().setUsername(user.c_str()); config.getAccessConfig().setPassword(password.c_str()); WebOsCalendarSyncSource* calendar; WebOsContactsSyncSource* contacts; if(doCalendar) { SyncSourceConfig* calConfig = config.getSyncSourceConfig("calendar"); if(!calConfig) { calConfig = DefaultConfigFactory::getSyncSourceConfig("calendar"); } calConfig->setSyncModes("slow,two-way,refresh-from-server,refresh-from-client,one-way-from-server,one-way-from-client"); calConfig->setSync(calendarMethod.c_str()); calConfig->setURI(calendarDataStore.c_str()); calConfig->setSupportedTypes("text/calendar"); calConfig->setType("text/calendar"); config.setSyncSourceConfig(*calConfig); calendar = new WebOsCalendarSyncSource(TEXT("calendar"),calConfig); ssArray[ssIndex] = calendar; ssIndex++; } if(doContacts) { SyncSourceConfig* conConfig = config.getSyncSourceConfig("contact"); if(!conConfig) { conConfig = DefaultConfigFactory::getSyncSourceConfig("contact"); } conConfig->setSyncModes("slow,two-way,refresh-from-server,refresh-from-client,one-way-from-server,one-way-from-client"); conConfig->setSync(contactsMethod.c_str()); conConfig->setSupportedTypes("text/x-vcard"); conConfig->setType("text/x-vcard"); conConfig->setURI(contactsDataStore.c_str()); config.setSyncSourceConfig(*conConfig); contacts = new WebOsContactsSyncSource(TEXT("contact"),conConfig); ssArray[ssIndex] = contacts; ssIndex++; } //start sync process: SyncClient client; client.sync(config, ssArray); //save config options, includes configuration for next sync process: config.getAccessConfig().setPassword(""); config.save(); StringBuffer report; client.getSyncReport()->toString(report,true); LOG.info("Report: %s.",report.c_str()); const char* params[2]; if(doCalendar) { LOG.info("Cal_Error: %s (%d)",calendar->getReport()->getLastErrorMsg(),calendar->getReport()->getLastErrorCode()); if(calendar->getReport()->getLastErrorCode() != 0) params[0] = "fail"; else params[0] = "ok"; } else params[0] = "ok"; if(doContacts && contacts->getReport()->getLastErrorCode() != 0) params[1] = "fail"; else params[1] = "ok"; PDL_CallJS("finished",params,2); for(int i = 0; i < ssIndex; i++) { delete ssArray[i]; ssArray[i] = NULL; } }
SyncSourceConfig* DefaultConfigFactory::getSyncSourceConfig(const char* name) { SyncSourceConfig* sc = new SyncSourceConfig(); sc->setName (name); sc->setSyncModes ("slow,two-way"); sc->setSync ("two-way"); sc->setEncoding ("b64"); sc->setLast (0); sc->setSupportedTypes (""); sc->setVersion (""); sc->setEncryption (""); if (!strcmp(name, "contact")){ sc->setURI ("scard"); sc->setType ("text/x-s4j-sifc"); } else if (!strcmp(name, "calendar")){ sc->setURI ("scal"); sc->setType ("text/x-s4j-sife"); } else if (!strcmp(name, "task")){ sc->setURI ("stask"); sc->setType ("text/x-s4j-sift"); } else if (!strcmp(name, "note")){ sc->setURI ("snote"); sc->setType ("text/x-s4j-sifn"); } // *** TBD *** //sc->setCtCap return sc; }
TestFileSource(const std::string &id) : ClientTest(getenv("CLIENT_TEST_DELAY") ? atoi(getenv("CLIENT_TEST_DELAY")) : 0, getenv("CLIENT_TEST_LOG") ? getenv("CLIENT_TEST_LOG") : ""), clientID(id) { const char *sourcelist = getenv("CLIENT_TEST_SOURCES"); const char *server = getenv("CLIENT_TEST_SERVER"); /* set up source list */ if (!sourcelist) { sourcelist = ""; } const char *eostr = strchr(sourcelist, ','); const char *start = sourcelist; while (eostr) { sources.push_back(std::string(start, 0, eostr - start)); start = eostr + 1; eostr = strchr(start, ','); } if (start[0]) { sources.push_back(start); } /* check server */ if (!server) { server = "funambol"; } // get configuration and set obligatory fields LOG.setLevel(LOG_LEVEL_DEBUG); std::string root = std::string("client-test/") + server + "_" + id; config.reset(new DMTClientConfig(root.c_str())); config->read(); DeviceConfig &dc(config->getDeviceConfig()); if (!strlen(dc.getDevID())) { // no configuration yet config->setClientDefaults(); dc.setDevID(id == "A" ? "sc-api-nat" : "sc-pim-ppc"); } for (int source = 0; source < (int)sources.size(); source++) { ClientTest::Config testconfig; getSourceConfig(source, testconfig); CPPUNIT_ASSERT(testconfig.type); SyncSourceConfig* sc = config->getSyncSourceConfig(sources[source].c_str()); if (!sc) { // no configuration yet config->setSourceDefaults(sources[source].c_str()); sc = config->getSyncSourceConfig(sources[source].c_str()); sc->setURI(testconfig.uri); CPPUNIT_ASSERT(sc); } sc->setType(testconfig.type); } config->save(); config->open(); if (id == "A") { /* we are the primary client, create a second one */ clientB.reset(new TestFileSource("B")); } }
void SyncSourceConfig::assign(const SyncSourceConfig& sc) { if (&sc == this) { return; } setName (sc.getName ()); setURI (sc.getURI ()); setSyncModes (sc.getSyncModes ()); setType (sc.getType ()); setSync (sc.getSync ()); setLast (sc.getLast ()); setEncoding (sc.getEncoding ()); setVersion (sc.getVersion ()); setSupportedTypes(sc.getSupportedTypes()); setSyncMode (sc.getSyncMode ()); setIsAllowed (sc.isAllowed ()); // setCtCap (sc.getCtCap ()); setEncryption (sc.getEncryption ()); setLastSourceError(sc.getLastSourceError()); setLastSyncServerTime(sc.AbstractSyncSourceConfig::getLastSyncServerTime()); extraProps = sc.getExtraProps(); }