poomserver2client.cpp

来自「funambol window mobile客户端源代码」· C++ 代码 · 共 547 行 · 第 1/2 页

CPP
547
字号
/*
 * Funambol is a mobile platform developed by Funambol, Inc.
 * Copyright (C) 2003 - 2007 Funambol, Inc.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License version 3 as published by
 * the Free Software Foundation with the addition of the following permission
 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
 * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program; if not, see http://www.gnu.org/licenses or write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301 USA.
 *
 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
 *
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 *
 * In accordance with Section 7(b) of the GNU Affero General Public License
 * version 3, these Appropriate Legal Notices must retain the display of the
 * "Powered by Funambol" logo. If the display of the logo is not reasonably
 * feasible for technical reasons, the Appropriate Legal Notices must display
 * the words "Powered by Funambol".
 */

#include <windows.h>
#include "pimstore.h"
#include <stdio.h>

#include "base/Log.h"
#include "base/util/utils.h"
#include "spds/spdsutils.h"
#include "spds/Constants.h"

#include "pim/Utils.h"
#include "pim/maincpp.h"
#include "pim/ContactBuilder.h"
#include "pim/AppointmentBuilder.h"
#include "pim/TaskBuilder.h"
#include "pim/UtilsRecurrence.h"
#include "pim/POOMServer2Client.h"
#include "pim/POOMFileManagement.h"
#include "pim/MAPIUtils.h"

#include "vocl/VConverter.h"

#include <vector>
#include <list>
#include <map>
using namespace std;


/**
 * Create a WinContact that could be a WinConctact or WinContactSIF
 */
WinItem* createWinItem(const int dataType, bool isSif, const wstring& ptrData, const wchar_t **fields) {

    WinItem* item = NULL;

    if (dataType == olFolderCalendar) {
        if (isSif)  item = new WinEventSIF(ptrData, fields, (const wchar_t**)recurrenceFields);
        else        item = new WinEvent(ptrData);
    }
    else if (dataType == olFolderContacts) {
        if (isSif)  item = new WinContactSIF(ptrData, fields);
        else        item = new WinContact(ptrData);
    }
    else if (dataType == olFolderTasks) {
        if (isSif)  item = new WinTaskSIF(ptrData, fields, (const wchar_t**)recurrenceFields);
        else        item = new WinTask(ptrData);
    }
    else {
        LOG.error("Internal error. createWinItem: dataType %d not supported", dataType);
    }
    return item;
}

/*
* Function return the code for the get_Oid function. Using PPC-WM5 the oid could have
* a value < 0. So it the value of OID is
*/

long manageNewItems(SyncItem* item, int dataType, long *oid, wchar_t* path, bool isSIF, map<long,long> &currentOidHash) {

    LOG.debug("Enter in manageNewItemsPOOM ...");
    IP_OUTLOOK_APP* polApp = getOutlookApp();
    if (polApp == NULL)
        return -1;

    HRESULT hr = -1;

    long oidNew = 0;
    int size = 0;
    wchar_t * ptrData = NULL;
    wchar_t* t = NULL;
    char* data = NULL;

    IFolder *pFolder = NULL;
    IPOutlookItemCollection *pItems = NULL;

    size = item->getDataSize();
    data = new char[size + 1];
    memset(data, 0, size + 1);
    memcpy(data, item->getData(), size);

    ptrData = toWideChar(data);
    delete [] data; data = NULL;

    wstring ptrDataString = ptrData;
    if (ptrData) {
        delete [] ptrData; ptrData = NULL;
    }
    ptrData = (wchar_t*)ptrDataString.data();


    // to create contacts
    if (dataType == olFolderContacts) {

        WinItem* winItem = createWinItem(dataType, isSIF, ptrDataString, contactFields);

        IItem* ppItem     = NULL;
        IDispatch *pDisp  = NULL;
        hr = polApp->CreateItem(olContactItem, &pDisp);

        // Get the IItem interface the newly created item.
        hr = pDisp->QueryInterface(IID_IItem, (LPVOID*)&ppItem);

        if (winItem) {
            WinContact* winC = (WinContact*)winItem;
            hr = winContactToContact(*winC, ppItem);
            if (SUCCEEDED(hr)) {
                oidNew = getIItemOid(ppItem);

                // calculate the new winC with all the fields to get the right crc
                delete winItem;
                winItem = contactToWinContact(ppItem, isSIF);
                long hash = winItem->getCRC();
                currentOidHash[oidNew] = hash;
            }
            delete winItem;
        }
        ppItem->Release();
        pDisp->Release();
    }

    else if (dataType == olFolderCalendar) {

        WinItem* winItem = createWinItem(dataType, isSIF, ptrDataString, appointmentFields);

        IItem* ppItem     = NULL;
        IDispatch *pDisp  = NULL;
        hr = polApp->CreateItem(olAppointmentItem, &pDisp);

        // Get the IItem interface the newly created item.
        hr = pDisp->QueryInterface(IID_IItem, (LPVOID*)&ppItem);

        if (winItem) {
            WinEvent* winE = (WinEvent*)winItem;
            hr = winEventToAppointment(*winE, ppItem, path, 0);
            if (SUCCEEDED(hr)) {
                oidNew = getIItemOid(ppItem);

                // calculate the new winE with all the fields to get the right crc
                delete winItem;
                winItem = appointmentToWinEvent(ppItem, isSIF);

                long hash = winItem->getCRC();
                LOG.debug("hash = %ld", hash);
                currentOidHash[oidNew] = hash;
            }
            delete winItem;
        }
        ppItem->Release();
        pDisp->Release();
    }

    else if (dataType == olFolderTasks) {

        WinItem* winItem = createWinItem(dataType, isSIF, ptrDataString, taskFields);

        IItem* ppItem     = NULL;
        IDispatch *pDisp  = NULL;
        hr = polApp->CreateItem(olTaskItem, &pDisp);

        // Get the IItem interface the newly created item.
        hr = pDisp->QueryInterface(IID_IItem, (LPVOID*)&ppItem);

        if (winItem) {
            WinTask* winT = (WinTask*)winItem;
            hr = winTaskToTask(*winT, ppItem, path, 0);
            if (SUCCEEDED(hr)) {
                oidNew = getIItemOid(ppItem);

                // calculate the new winE with all the fields to get the right crc
                delete winItem;
                winItem = taskToWinTask(ppItem, isSIF);

                long hash = winItem->getCRC();
                LOG.debug("hash = %ld", hash);
                currentOidHash[oidNew] = hash;
            }
            delete winItem;
        }
        ppItem->Release();
        pDisp->Release();
    }

    if (pItems) { pItems->Release (); }
    if (pFolder) { pFolder->Release ();}

    releaseOutlookApp(polApp);
    LOG.debug("Exiting manageNewItemsPOOM... ");

    if (hr == S_OK)
        *oid = oidNew;

    return hr;
}


long manageUpdatedItems(SyncItem* item, int dataType, wchar_t* path, bool isSIF, map<long,long> &currentOidHash) {

    LOG.debug("Enter in managerUpdatedItemsPOOM... ");

    int size = item->getDataSize();
    if (size <= 0){
        LOG.info("Empty data from server.");
        return 500;
    }

    IP_OUTLOOK_APP* polApp = getOutlookApp();
    if (polApp == NULL)
        return -1;

    wchar_t* dummy      = NULL;
    wchar_t* dummyEvent = NULL;
    HRESULT hr          = NULL;
    wchar_t * ptrData   = NULL;
    wchar_t* t = NULL;
    char* data = NULL;

    long oidToUpdate = 0;

    oidToUpdate = wcstol(item->getKey(), &dummy, 0);

    data = new char[size + 1];
    memset(data, 0, size + 1);
    memcpy(data, item->getData(), size);

    ptrData = toWideChar(data);
    delete [] data; data = NULL;

    wstring ptrDataString = ptrData;
    if (ptrData) {
        delete [] ptrData; ptrData = NULL;
    }
    ptrData = (wchar_t*)ptrDataString.data();


    //
    // we start to use the IPOutlookApp2 to use the IItem object
    //
    if (dataType == olFolderContacts) {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?