SyncItem* WebOsCalendarSyncSource::getNextDeletedItem()
{
	LOG.info("=========== GET NEXT DELETED ITEM CALLED ==================");
	if(!mGetChangesCalled)
	{
		getChanges();
	}

	std::vector<WString> result = BlockingServiceCall("getDeletedEvent",TEXT(""));
	if(result.empty())
	{
		LOG.error("GetDeleted failed.");
	}
	else
	{
		if(result.front() != "finished")
		{
			SyncItem* item = new SyncItem();
			item->setDataType(TEXT("text/calendar"));
			//item->setData(e.second.c_str(),e.second.length()); no data for deleted items..
			item->setKey(result.front().c_str());
			LOG.debug("Added %s as deleted.",result.front().c_str());
			return item;
		}
	}

	return NULL;
}
SyncItem* WebOsCalendarSyncSource::getNextItem()
{
	LOG.info("========== GET NEXT ITEM CALLED ===========");
	if(mEvents.empty())
	{
		//no items anymore, need to get more. If that doesn't work, there are no more items.
		getMoreItems();
		if(mEvents.empty())
		{
			LOG.info("======= NO MORE ELEMENTS ==========");
			return NULL;
		}
	}

	if(!mEvents.empty())
	{
		//take first event and convert into item of correct type.
		std::pair<WString,WString>& e = mEvents.front();
		SyncItem* item = new SyncItem();
		item->setDataType(TEXT("text/calendar"));
		item->setData(e.second.c_str(),e.second.length());
		item->setKey(e.first.c_str());
		LOG.debug("Received %s from JS with key %s.",e.second.c_str(),e.first.c_str());
		mEvents.pop_front();
		return item;
	}
	else
		return NULL;
}
SyncItem* WebOsCalendarSyncSource::getNextUpdatedItem()
{
	LOG.info("=========== GET NEXT UPDATED ITEM CALLED ==================");
	if(!mGetChangesCalled)
	{
		getChanges();
	}

	if(!mEvents.empty())
	{
		//take first event and convert into item of correct type.
		std::pair<WString,WString>& e = mEvents.front();
		SyncItem* item = new SyncItem();
		item->setDataType(TEXT("text/calendar"));
		item->setData(e.second.c_str(),e.second.length());
		item->setKey(e.first.c_str());
		LOG.debug("Received %s from JS.",e.second.c_str());
		mEvents.pop_front();
		return item;
	}
	else
		return NULL;


	return NULL;
}
示例#4
0
SyncItem* LOSyncSource::getNextNewItem() {
    
    if (getUseAdd() == false) {
        return NULL;
    }
    if (count == 2) {
        return NULL;
    }
    
    StringBuffer name = getSyncItemName();
    WCHAR key[256];
    wsprintf(key, TEXT(WCHAR_PRINTF_STRING), name.c_str());
    wcscat(key, getName());    

    SyncItem* item = new SyncItem(key);    
    if (getUseDataEncoding()) {
        // just to test that the api works properly with custom encoding
        item->setDataEncoding("bin");
    }


    char* data = getNewCard(true);
    item->setData(data, (long)strlen(data));
    
    delete [] data;
    return item;

}
示例#5
0
int LOSyncSource::addItem(SyncItem& item) {

    WCHAR luid[128];
    wsprintf(luid, TEXT("%s-luid"), item.getKey());
    item.setKey(luid);
    return 200;
}
int WebOsCalendarSyncSource::deleteItem(SyncItem &item)
{
	int ret = STC_COMMAND_FAILED;
	LOG.info("deleteItem called with %s data. And Type %s.",item.getKey(),item.getDataType());

	LOG.info("Calling deleteEvent.");
	std::vector<WString> result = BlockingServiceCall("deleteEvent",item.getKey());
	if(result.empty())
	{
		LOG.error("delete event %s did not work.",item.getKey());
		ret = STC_COMMAND_FAILED;
	}
	else
	{
		LOG.error("delete event was successful, received: %s.",result[0].c_str());
		ret = STC_OK;
	}

	if (isErrorCode(ret))
	{
		report->setLastErrorCode(ERR_ITEM_ERROR);
	    report->setLastErrorMsg(ERRMSG_ITEM_ERROR);
	    report->setState(SOURCE_ERROR);
	    LOG.debug("Error deleting item: %", item.getKey());
	}

	return ret;
}
END_TEST

/**
* Removed the STATUS from the winevent parser
*/
BEGIN_TEST(WinEventNoSTATUS)
{
    int ret = 0;
    SyncItem* item = NULL;
    WCHAR* internalKey = NULL;
    wstring propValue; 

    WindowsSyncSource* ss = createAppointmentWindowsSyncSource();   
    WIN_ASSERT_NOT_NULL(ss, TEXT("The syncSource is null."));

    StringBuffer VCal;
    VCal.append("BEGIN:VCALENDAR\r\n");
    VCal.append("VERSION:1.0\r\n");
    VCal.append("BEGIN:VEVENT\r\n");
    VCal.append("X-FUNAMBOL-FOLDER:DEFAULT_FOLDER\r\n");
    VCal.append("X-FUNAMBOL-ALLDAY:1\r\n");
    VCal.append("DTSTART:20110407\r\n");
    VCal.append("DTEND:20110408\r\n");
    VCal.append("X-MICROSOFT-CDO-BUSYSTATUS:FREE\r\n");
    VCal.append("CATEGORIES:\r\n");
    VCal.append("DESCRIPTION:\r\n");
    VCal.append("LOCATION:Roma\r\n");
    VCal.append("PRIORITY:1\r\n");
    VCal.append("STATUS:NEED ACTION\r\n");
    VCal.append("X-MICROSOFT-CDO-REPLYTIME:\r\n");
    VCal.append("SUMMARY;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:Da test\r\n");
    VCal.append("CLASS:PUBLIC\r\n");
    VCal.append("AALARM:20110406T060000Z;;0;\r\n");
    VCal.append("RRULE:\r\n");
    VCal.append("X-FUNAMBOL-BILLINGINFO:\r\n");
    VCal.append("X-FUNAMBOL-COMPANIES:\r\n");
    VCal.append("X-FUNAMBOL-MILEAGE:\r\n");
    VCal.append("X-FUNAMBOL-NOAGING:0 \r\n");
    VCal.append("END:VEVENT\r\n");
    VCal.append("END:VCALENDAR");

    item = new SyncItem(TEXT("GUID"));
    item->setData(VCal.c_str(), VCal.length());
    
    WCHAR* tt = toWideChar(VCal.c_str());

    WinEvent d(tt);
    printf("%S", d.toString().c_str());        

    // insert test item
    ret = ss->addItem(*item);
    WIN_ASSERT_EQUAL(ret, 201, TEXT("Adding item is not correct"));    
    internalKey = (WCHAR*)item->getKey();        
    
    delete item;
    delete ss;
}
int AbstractSyncSource::updateItem(SyncItem& item)
{
    QByteArray data((char *)item.getData());
    QUniqueId id(QString((char *)item.getKey()));
    //qDebug() << "AbstractSyncSource::updateItem()" << toString(item) << "Id:" << id.toString();
    if (m_model->updateRecord(id, data, m_type))
        return 200; //ok, the SyncML command completed successfully
    else
        return 500; //failed, the recipient encountered an error
}
示例#9
0
    void testFillSyncItem(){
        StringBuffer inFile = getTestFileFullPath(TEST_INPUT_DIR, TEST_FILE_NAME1);
        SyncItem* si = fmss->fakeFillSyncItem(&inFile, true);

        StringBuffer* data = new StringBuffer((char*)si->getData());

        CPPUNIT_ASSERT(si != NULL);
        CPPUNIT_ASSERT(data != NULL);
      
        CPPUNIT_ASSERT(data->find("body") == StringBuffer::npos);
        CPPUNIT_ASSERT(data->find("size") != StringBuffer::npos);
    }
int AbstractSyncSource::addItem(SyncItem& item)
{
    QByteArray data((char *)item.getData());
    QUniqueId id = m_model->addRecord(data, QPimSource(), m_type);
    item.setKey(id.toString().toAscii().data());
    m_model->updateRecord(id, data, m_type);
    //qDebug() << "AbstractSyncSource::addItem() " << toString(item) << "Id:" << id.toString();
    if (!id.isNull())
        return 201;    //ok, the requested item was added
    else
        return 500;    //failed, the recipient encountered an error
}
    //test te getFirstItem. We pass all the values into the properties ArrayList
    //and we get the first one
    void testAllItems() {
        ArrayList properties;
        ConfigSyncSource source(TEXT("config"), APPLICATIONURI, s);
        
        StringBuffer emailaddress("./Email/Address");
        
        properties.add(emailaddress);
        source.setConfigProperties(properties);

        Enumeration* val = source.getAllItemList();
        SyncItem* value = source.getFirstItem();
        StringBuffer valuedata((const char*)value->getData(),value->getDataSize());
        CPPUNIT_ASSERT(valuedata == VALUE);
	delete val;
	delete value;
    }
示例#12
0
int TestSyncSource::updateItem(SyncItem& item) {
    char* val = toMultibyte( item.getKey() );
    LOG.info("updated item: %s", val);
    if(val){
        delete [] val;
        val = 0;
    }

    char *data = new char [item.getDataSize()];
    memcpy(data, item.getData(), item.getDataSize());
    data[item.getDataSize()] = 0;
    LOG.info("Data: %s", data);
    delete [] data;

    return 200;
}
示例#13
0
int setAllItems() {

    SyncItem item;
    WCHAR name[64];
    char data[128];

    for (int i = 0; i < 4; ++i) {

        wsprintf(name, TEXT("%s%d"), TEXT("item"), i);
        sprintf(data, "This is item %d", i);

        item.setKey(name);
        item.setData(data  , (strlen(data))*sizeof(char));
        items.add(item);
    }
    return 0;
}
示例#14
0
bool StorageHandler::startLargeObjectReplace( StoragePlugin& aPlugin,
                                              const QString& aLocalKey,
                                              const SyncItemKey& aParentKey,
                                              const QString& aType,
                                              const QString& aFormat,
                                              const QString& aVersion,
                                              qint64 aSize )
{
    FUNCTION_CALL_TRACE;

    if( iLargeObject ) {
        LOG_CRITICAL( "Already processing large object, aborting" );
        return false;
    }

    SyncItem* item = NULL;

    // If local key is empty, this Replace should be handled as Add (this is allowed by the protocol)

    if( !aLocalKey.isEmpty() ) {
        item = aPlugin.getSyncItem( aLocalKey );
    }

    if( !item ) {
        LOG_CRITICAL( "Could not find item, processing as Add" );
        return startLargeObjectAdd( aPlugin, aLocalKey, aParentKey, aType, aFormat, aVersion, aSize );
    }

    item->setParentKey( aParentKey );
    item->setType( aType );
    item->setFormat( aFormat );
    item->setVersion( aVersion );

    iLargeObject = item;
    iLargeObjectSize = aSize;
    iLargeObjectKey = aLocalKey;
    if( !iLargeObject->resize(0) )
    {
        LOG_DEBUG( "Large object created for replace couldn't be resized" );
    }

    LOG_DEBUG( "Large object created for replace" );

    return true;
}
示例#15
0
SyncItem* MappingTestSyncSource::getNextNewItem() {

    if (count == 3) {
        return NULL;
    }
    
    WCHAR key[256];
    wsprintf(key, TEXT("%i-%lu"), count, this->getConfig().getLast());
    wcscat(key, getName());    

    SyncItem* item = new SyncItem(key);
    
    StringBuffer data = getNewCard();
    item->setData(data, data.length());
    
    return item;

}
示例#16
0
int CacheSyncSource::addItem(SyncItem& item) {
    int ret = insertItem(item);
    switch (ret) {        
        case 200:
        case 201:
        case 418: {
            LOG.info("[%s] Successful add of item with key %s - code %d", getName(), item.getKey(), ret);
            KeyValuePair k;
            getKeyAndSignature(item, k);
            insertInCache(k);
        }
        break;
        default:
            LOG.error("[%s] Failed add of item with key %s - code %d", getName(), item.getKey(), ret);
        break;
    }
    return ret;
}
示例#17
0
int TestSyncSource::deleteItem(SyncItem& item) {
    char* val = toMultibyte( item.getKey() );
    LOG.info("deleted item: %s", val);
    if(val){
        delete [] val;
        val = 0;
    }
    return 200;
}
int AbstractSyncSource::deleteItem(SyncItem& item)
{
    QUniqueId id(QString((char *)item.getKey()));
    //qDebug() << "AbstractSyncSource::deleteItem()" << toString(item) << "Id:" << id.toString();
    if (m_model->removeRecord(id))
        return 200; //ok, the SyncML command completed successfully
    else
        return 211; //failed, the recipient encountered an error
}
示例#19
0
void CacheSyncSource::getKeyAndSignature(SyncItem& item, KeyValuePair& kvp) {
    
    char* t = toMultibyte(item.getKey());
    StringBuffer s(t);
    StringBuffer sign = getItemSignature(s);
    kvp.setKey(t);
    kvp.setValue(sign);
    delete [] t;
    
}
示例#20
0
int CacheSyncSource::deleteItem(SyncItem& item) {
    int ret = removeItem(item);
    switch (ret) {        
        case 200:
        case 201:
        case 418: {
            LOG.info("[%s] Successful delete of item with key %s - code %d", getName(), item.getKey(), ret);  
            char* t = toMultibyte(item.getKey());
            KeyValuePair k (t, "");
            removeFromCache(k);
            delete [] t;
        }
        break;
        default:
            LOG.error("[%s] Failed delete of item with key %s - code %d", getName(), item.getKey(), ret);
        break;
    }
    
    return ret;
} 
END_TEST


WinContact* updateOutlookItem(WindowsSyncSource* ss, SyncItem* item) {
    
    int ret = ss->updateItem(*item);
    WIN_ASSERT_EQUAL(ret, 200, TEXT("Update item is not correct"));
    wstring keyModified = item->getKey();

    SyncItem* itemTmp = ss->getItemFromId(keyModified.c_str());
    WIN_ASSERT_NOT_NULL(item, TEXT("The item retrieved from the backend is null."));

    WCHAR* wcon = toWideChar((const char*)itemTmp->getData());
    wstring wcontact(wcon);
    delete [] wcon;
   
    WinContact* winC = new WinContact(wcontact);
    return winC;

}
示例#22
0
    void testSetItemStatus(){
        StringBuffer inFile = getTestFileFullPath(TEST_INPUT_DIR, TEST_FILE_NAME1);
        SyncItem* si = fmss->fakeFillSyncItem(&inFile, true);

        const WCHAR* wKey = si->getKey();
        const char* key = toMultibyte(wKey);
        fmss->setItemStatus(wKey, 200, "Add");
        ArrayList luidToSend = fmss->getLUIDArray();

        bool luidPresent = false;
        for (int i = 0; i < luidToSend.size(); i++){
            if( strcmp( ((StringBuffer*)luidToSend.get(i))->c_str(), key) == 0 ){
                luidPresent = true;
            }
        }
        CPPUNIT_ASSERT(luidPresent);

        int ret = fmss->endSync();
        CPPUNIT_ASSERT( ret == 0 );
    
        StringBuffer propval = fmss->fakeReadCachePropertyValue(inFile.c_str());
        CPPUNIT_ASSERT( !propval.empty() );
    }
示例#23
0
SyncItem* LOSyncSource::getNextUpdatedItem() { 
    
    if (getUseUpdate() == false) {
        return NULL;
    }
    if (count == 2) {
        return NULL;
    }
    
    StringBuffer name = getSyncItemName();
    WCHAR key[256];
    wsprintf(key, TEXT(WCHAR_PRINTF_STRING), name.c_str());
    wcscat(key, getName());    

    SyncItem* item = new SyncItem(key);
    
    char* data = getNewCard(false);
    item->setData(data, (long)strlen(data));
    
    delete [] data;
    return item;

}
示例#24
0
SyncItem* CacheSyncSource::fillSyncItem(StringBuffer* key) {
    
    SyncItem* syncItem  = NULL;    
    size_t size         = 0;
    void* content       = NULL;
    
    if (!key) {
        return NULL;
    }
    
    LOG.debug("[%s] Filling item with key %s", getName(), key->c_str());
    
    content = getItemContent((*key), &size);
    
    WCHAR* wkey = toWideChar(key->c_str());
    syncItem = new SyncItem(wkey);
    syncItem->setData(content, size);
    
    if (wkey) { delete [] wkey; wkey = NULL; }
    if (content) { delete [] (char*)content; content = NULL; }

    return syncItem;

}
示例#25
0
int TestSyncSource::addItem(SyncItem& item) {
    char* val = toMultibyte( item.getKey() );
    LOG.info("added item: %s", val);
    if(val){
        delete [] val;
        val = 0;
    }
    char *data = new char [item.getDataSize()];
    memcpy(data, item.getData(), item.getDataSize());
    data[item.getDataSize()] = 0;
    LOG.info("Data: %s", data);
    delete [] data;

    WCHAR *luid = new WCHAR[wcslen(item.getKey())+10];
    wsprintf(luid, TEXT("%s-luid"), item.getKey());
    item.setKey(luid);

    return 200;
}
示例#26
0
int setModifiedItems() {

    SyncItem item;
                StringBuffer val; 
                for (int ii = 0; ii<1; ii++){
                    val.append("This is the updated item one");
                }

    for (int i = 0; i < 4; ++i) {

        switch (i) {

            case 0:
                item.setKey(TEXT("item5"));
                item.setData(val.c_str()  , (val.length())*sizeof(char));
                newItems.add(item);
                break;

            case 1:
                item.setKey(TEXT("item1"));
                item.setData(val.c_str()  , (val.length())*sizeof(char));
                updatedItems.add(item);
                break;

            case 2:
                item.setKey(TEXT("item3"));
                item.setData(val.c_str()  , (val.length())*sizeof(char));
                updatedItems.add(item);
                break;

            case 3:

                item.setKey(TEXT("item4"));
                deletedItems.add(item);
                break;

        }
    }

    return 0;
}
示例#27
0
bool StorageHandler::addItem( const ItemId& aItemId,
                              StoragePlugin& aPlugin,
                              const SyncItemKey& aLocalKey,
                              const SyncItemKey& aParentKey,
                              const QString& aType,
                              const QString& aFormat,
                              const QString& aVersion,
                              const QString& aData )
{
    FUNCTION_CALL_TRACE;

    LOG_DEBUG( "Processing item for add:" << aItemId.iCmdId <<"/" << aItemId.iItemIndex );

    if( iLargeObject ) {
        LOG_CRITICAL( "Already processing large object, aborting" );
        return false;
    }

    SyncItem* newItem = aPlugin.newItem();

    if( !newItem ) {
        LOG_CRITICAL( "Could not create new item" );
        return false;
    }

    //Setting empty string as we dont have any local key for it.
    newItem->setKey( aLocalKey );
    newItem->setParentKey( aParentKey );
    newItem->setType( aType );
    newItem->setFormat( aFormat );
    newItem->setVersion( aVersion );

    if( !newItem->write( 0, aData.toUtf8() ) ) {
        delete newItem;
        LOG_CRITICAL( "Could not write to item" );
        return false;
    }

    iAddList.insert( aItemId, newItem );
    LOG_DEBUG( "Item queued for addition" );

    return true;
}
QString AbstractSyncSource::toString(SyncItem& item)
{
    QByteArray data((char *)item.getData());
    QString ret("Key: ");
    ret += item.getKey();
    ret += " Mod.Time: ";
    ret += QString::number(item.getModificationTime());
    ret += " Encoding: ";
    ret += item.getDataEncoding();
    ret += " Size: ";
    ret += QString::number(item.getDataSize());
    ret += " Type: ";
    ret += item.getDataType();
    ret += " State: ";
    ret += QString::number(item.getState());
    ret += " Data:\n";
    ret += data;
    return ret;
}
SyncItem *AbstractSyncSource::createSyncItem(const QUniqueId &id, bool wantData, SyncState state) const
{
    //qDebug() << "AbstractSyncSource::createSyncItem(" << id.toString() << "," << wantData << "," << state << ")";
    QByteArray record = m_model->record(id, m_type);
    SyncItem *item = new SyncItem();
    QString key = id.toString();
    item->setKey(key.toAscii().data());
    item->setModificationTime(m_lastSync.toTime_t());
    item->setState(state);
    if (wantData) {
        item->setData(record.data(), record.size() - 1); // have to omit '\0'
        item->setDataType(getConfig().getType());
    }
    //qDebug() << "AbstractSyncSource::createSyncItem()" << toString(*item);
    return item;
}
示例#30
0
bool StorageHandler::replaceItem( const ItemId& aItemId,
                                  StoragePlugin& aPlugin,
                                  const QString& aLocalKey,
                                  const SyncItemKey& aParentKey,
                                  const QString& aType,
                                  const QString& aFormat,
                                  const QString& aVersion,
                                  const QString& aData )
{
    FUNCTION_CALL_TRACE;

    LOG_DEBUG( "Processing item for replace:" << aItemId.iCmdId <<"/" << aItemId.iItemIndex );

    if( iLargeObject ) {
        LOG_CRITICAL( "Already processing large object, aborting" );
        return false;
    }

    SyncItem* item = NULL;

    // If local key is empty, this Replace should be handled as Add (this is allowed by the protocol)

    if( !aLocalKey.isEmpty() ) {
        item = aPlugin.getSyncItem( aLocalKey );
    }

    if( !item ) {
        LOG_DEBUG( "Could not find item, processing as Add" );
        return addItem( aItemId, aPlugin, aLocalKey, aParentKey, aType, aFormat, aVersion, aData );
    }

    item->setParentKey( aParentKey );
    item->setType( aType );
    item->setFormat( aFormat );
    item->setVersion( aVersion );

    if( !item->write( 0, aData.toUtf8() ) ) {
        delete item;
        LOG_CRITICAL( "Could not write to item" );
        return false;
    }

    iReplaceList.insert( aItemId, item );
    LOG_DEBUG( "Item queued for replace" );

    return true;
}