Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
    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;
    }
Ejemplo n.º 3
0
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;
	}
}