зеркало из https://github.com/mozilla/pjs.git
Files for implementation of PalmSync Conduit, NOT YET PART OF BUILD The Conduit would be built as separate Windows Dll loaded by the HotSync Manager r=cavin, sr=mscott
This commit is contained in:
Родитель
a6065e7319
Коммит
dcf98d7652
|
@ -0,0 +1,268 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* EXPORTED FUNCTIONS Generic Conduit Entry Points Source File
|
||||
*
|
||||
* THIS FILE IS GENERATED BY PALM CDK
|
||||
*
|
||||
****************************************************************************/
|
||||
#define STRICT 1
|
||||
#define ASSERT(f) ((void)0)
|
||||
#define TRACE0(sz)
|
||||
#define TRACE(sz)
|
||||
|
||||
#include <windows.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#ifdef METROWERKS_WIN
|
||||
#include <wmem.h>
|
||||
#else
|
||||
#include <memory.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
#include <TCHAR.H>
|
||||
#include <COMMCTRL.H>
|
||||
|
||||
#include <syncmgr.h>
|
||||
#include "MozABConduitGenCond.h"
|
||||
|
||||
#include <logstrng.h>
|
||||
|
||||
// TODO - Include custom sync header
|
||||
|
||||
#include <PALM_CMN.H>
|
||||
#define CONDUIT_NAME "MozABConduit"
|
||||
#include "MozABConduitSync.h"
|
||||
|
||||
HANDLE hLangInstance;
|
||||
HANDLE hAppInstance;
|
||||
extern HANDLE hLangInstance;
|
||||
extern HANDLE hAppInstance;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Function: DllMain()
|
||||
//
|
||||
// Description: main entry point to the MozABConduitProto component
|
||||
//
|
||||
// Parameters: hInstance - instance handle of the DLL
|
||||
// dwReason - why the entry point was called
|
||||
// lpReserved - reserved
|
||||
//
|
||||
// Returns: 1 if okay
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef _68K_
|
||||
|
||||
static int iTerminationCount = 0;
|
||||
|
||||
DWORD tId = 0;
|
||||
|
||||
extern "C" int APIENTRY
|
||||
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
|
||||
{
|
||||
|
||||
if (dwReason == DLL_PROCESS_ATTACH)
|
||||
{
|
||||
TRACE0("EXPORTED FUNCTIONS Initializing!\n");
|
||||
|
||||
if (!iTerminationCount ) {
|
||||
hAppInstance = hInstance;
|
||||
// use PalmLoadLanguage here to load different languages
|
||||
hLangInstance = hInstance;
|
||||
}
|
||||
++iTerminationCount;
|
||||
|
||||
tId = TlsAlloc();
|
||||
if (tId == 0xFFFFFFFF)
|
||||
return FALSE;
|
||||
}
|
||||
else if (dwReason == DLL_PROCESS_DETACH)
|
||||
{
|
||||
TRACE0("EXPORTED FUNCTIONS Terminating!\n");
|
||||
|
||||
--iTerminationCount;
|
||||
if (!iTerminationCount ) {
|
||||
// use PalmFreeLanguage here to unload different languages
|
||||
}
|
||||
TlsFree(tId);
|
||||
}
|
||||
return 1; // ok
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Function: OpenConduit()
|
||||
//
|
||||
// Description: Extern "C" entry point into this conduit which starts the
|
||||
// process of synchronizing the local database table with
|
||||
// a remote conterpart residing on the remote view device.
|
||||
//
|
||||
// Parameters: Pointer to a callback function used to report progress.
|
||||
//
|
||||
//
|
||||
//
|
||||
// Returns:
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
ExportFunc long OpenConduit(PROGRESSFN pFn, CSyncProperties& rProps)
|
||||
{
|
||||
long retval = -1;
|
||||
if (pFn)
|
||||
{
|
||||
CMozABConduitSync * pABSync = new CMozABConduitSync(rProps);
|
||||
if (pABSync){
|
||||
retval = pABSync->Perform();
|
||||
delete pABSync;
|
||||
}
|
||||
}
|
||||
return(retval);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Function: GetConduitName()
|
||||
//
|
||||
// Description: Extern "C" entry point into this conduit which returns
|
||||
// the name to be used when display messages regarding
|
||||
// this conduit.
|
||||
//
|
||||
// Parameters: pszName - buffer in which to place the name
|
||||
// nLen - maximum number of bytes of buffer
|
||||
//
|
||||
//
|
||||
//
|
||||
// Returns: -1 indicates erros
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
ExportFunc long GetConduitName(char* pszName,WORD nLen)
|
||||
{
|
||||
pszName = CONDUIT_NAME;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Function: GetConduitVersion()
|
||||
//
|
||||
// Description: Extern "C" entry point into this conduit which returns
|
||||
// the conduits version
|
||||
//
|
||||
// Parameters: none
|
||||
//
|
||||
// Returns: DWORD indicating major and minor version number
|
||||
// HIWORD - reserved
|
||||
// HIBYTE(LOWORD) - major number
|
||||
// LOBYTE(LOWORD) - minor number
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
ExportFunc DWORD GetConduitVersion()
|
||||
{
|
||||
return GENERIC_CONDUIT_VERSION;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Function: ConfigureConduit
|
||||
//
|
||||
// Description: Extern "C" entry point into this conduit which returns
|
||||
// should display the UI necessary to configure this
|
||||
// conduit.
|
||||
//
|
||||
// Parameters: none
|
||||
//
|
||||
// Returns: 0 - success, !0 - failure
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
ExportFunc long ConfigureConduit(CSyncPreference& pref)
|
||||
{
|
||||
|
||||
long nRtn = -1;
|
||||
return nRtn;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Method: GetConduitInfo
|
||||
//
|
||||
// Description: This function provides a way for a Conduit to provide info
|
||||
// to the caller.
|
||||
// In this version of the call, MFC Version, Conduit Name, and
|
||||
// Default sync action are the types of information this call
|
||||
// will return.
|
||||
//
|
||||
// Parameters: ConduitInfoEnum infoType - enum specifying what info is being
|
||||
// requested.
|
||||
// void *pInArgs - This parameter may be null, except for the Conduit
|
||||
// name enum, this value will be a ConduitRequestInfoType structure.
|
||||
// This following to parameters vary depending upon the info being requested.
|
||||
// For enum eConduitName
|
||||
// void *pOut - will be a pointer to a character buffer
|
||||
// DWORD *pdwOutSize - will be a pointer to a DWORD specifying the size of the character buffer.
|
||||
//
|
||||
// For enum eMfcVersion
|
||||
// void *pOut - will be a pointer to a DWORD
|
||||
// DWORD *pdwOutSize - will be a pointer to a DWORD specifying the size of pOut.
|
||||
//
|
||||
// For enum eDefaultAction
|
||||
// void *pOut - will be a pointer to a eSyncType variable
|
||||
// DWORD *pdwOutSize - will be a pointer to a DWORD specifying the size of pOut.
|
||||
//
|
||||
// Returns: 0 - Success.
|
||||
// !0 - error code.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
ExportFunc long GetConduitInfo(ConduitInfoEnum infoType, void *pInArgs, void *pOut, DWORD *pdwOutSize)
|
||||
{
|
||||
if (!pOut)
|
||||
return CONDERR_INVALID_PTR;
|
||||
if (!pdwOutSize)
|
||||
return CONDERR_INVALID_OUTSIZE_PTR;
|
||||
|
||||
switch (infoType) {
|
||||
case eConduitName:
|
||||
|
||||
// This code is for example. This conduit does not use this code
|
||||
|
||||
if (!pInArgs)
|
||||
return CONDERR_INVALID_INARGS_PTR;
|
||||
ConduitRequestInfoType *pInfo;
|
||||
pInfo = (ConduitRequestInfoType *)pInArgs;
|
||||
if ((pInfo->dwVersion != CONDUITREQUESTINFO_VERSION_1) ||
|
||||
(pInfo->dwSize != SZ_CONDUITREQUESTINFO))
|
||||
return CONDERR_INVALID_INARGS_STRUCT;
|
||||
|
||||
pOut = CONDUIT_NAME;
|
||||
return CONDERR_CONDUIT_RESOURCE_FAILURE;
|
||||
break;
|
||||
case eDefaultAction:
|
||||
if (*pdwOutSize != sizeof(eSyncTypes))
|
||||
return CONDERR_INVALID_BUFFER_SIZE;
|
||||
(*(eSyncTypes*)pOut) = eFast;
|
||||
break;
|
||||
case eMfcVersion:
|
||||
if (*pdwOutSize != sizeof(DWORD))
|
||||
return CONDERR_INVALID_BUFFER_SIZE;
|
||||
(*(DWORD*)pOut) = MFC_NOT_USED;
|
||||
break;
|
||||
default:
|
||||
return CONDERR_UNSUPPORTED_CONDUITINFO_ENUM;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* Generic Conduit Export Functions Header File
|
||||
*
|
||||
* THIS FILE IS GENERATED BY PALM CDK
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifndef __GENERIC_MAIN_CONDUIT__
|
||||
#define __GENERIC_MAIN_CONDUIT__
|
||||
#include <condapi.h>
|
||||
|
||||
#define GENERIC_CONDUIT_VERSION 0x00000102
|
||||
|
||||
#ifndef ExportFunc
|
||||
#ifdef _68K_
|
||||
#define ExportFunc
|
||||
#else
|
||||
#define ExportFunc __declspec( dllexport )
|
||||
#endif
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
|
||||
typedef long (*PROGRESSFN) (char*);
|
||||
ExportFunc long OpenConduit(PROGRESSFN, CSyncProperties&);
|
||||
ExportFunc long GetConduitName(char*,WORD);
|
||||
ExportFunc DWORD GetConduitVersion();
|
||||
ExportFunc long ConfigureConduit(CSyncPreference& pref);
|
||||
ExportFunc long GetConduitInfo(ConduitInfoEnum infoType, void *pInArgs, void *pOut, DWORD *dwOutSize);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,515 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Rajiv Dayal <rdayal@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <windows.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
#include <sys/stat.h>
|
||||
#include <TCHAR.H>
|
||||
|
||||
#include "MozABConduitRecord.h"
|
||||
|
||||
#define STR_CRETURN "\r"
|
||||
#define STR_NEWLINE "\n"
|
||||
|
||||
#define CH_CRETURN 0x0D
|
||||
#define CH_NEWLINE 0x0A
|
||||
|
||||
// constructor
|
||||
CMozABConduitRecord::CMozABConduitRecord(void)
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
// construct using Palm record
|
||||
CMozABConduitRecord::CMozABConduitRecord(CPalmRecord &rec)
|
||||
{
|
||||
ConvertFromGeneric(rec);
|
||||
}
|
||||
|
||||
// construct using Mozilla record
|
||||
CMozABConduitRecord::CMozABConduitRecord(nsABCOMCardStruct &rec)
|
||||
{
|
||||
Reset();
|
||||
|
||||
memcpy(&m_nsCard, &rec, sizeof(nsABCOMCardStruct));
|
||||
|
||||
m_dwRecordID = m_nsCard.dwRecordId;
|
||||
m_dwStatus = m_nsCard.dwStatus;
|
||||
m_dwCategoryID = m_nsCard.dwCategoryId;
|
||||
|
||||
m_dwPhone1LabelID = PHONE_LABEL_WORK;
|
||||
m_dwPhone2LabelID = PHONE_LABEL_HOME;
|
||||
m_dwPhone3LabelID = PHONE_LABEL_FAX;
|
||||
m_dwPhone4LabelID = PHONE_LABEL_MOBILE;
|
||||
m_dwPhone5LabelID = PHONE_LABEL_EMAIL;
|
||||
|
||||
m_csName = rec.lastName;
|
||||
m_csFirst = rec.firstName;
|
||||
m_csTitle = rec.jobTitle;
|
||||
m_csCompany = rec.company;
|
||||
|
||||
m_csPhone1 = rec.workPhone;
|
||||
m_csPhone2 = rec.homePhone;
|
||||
m_csPhone3 = rec.faxNumber;
|
||||
m_csPhone4 = rec.cellularNumber;
|
||||
m_csPhone5 = rec.primaryEmail;
|
||||
|
||||
m_csAddress = rec.homeAddress;
|
||||
m_csCity = rec.homeCity;
|
||||
m_csState = rec.homeState;
|
||||
m_csCountry = rec.homeCountry;
|
||||
|
||||
m_csNote = rec.notes;
|
||||
|
||||
m_csCustom1 = rec.custom1;
|
||||
m_csCustom2 = rec.custom2;
|
||||
m_csCustom3 = rec.custom3;
|
||||
m_csCustom4 = rec.custom4;
|
||||
}
|
||||
|
||||
// destructor
|
||||
CMozABConduitRecord::~CMozABConduitRecord()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// reset the internal data members
|
||||
void CMozABConduitRecord::Reset(void)
|
||||
{
|
||||
memset(&m_nsCard, 0, sizeof(nsABCOMCardStruct));
|
||||
|
||||
m_dwRecordID = 0;
|
||||
m_dwStatus = 0;
|
||||
m_dwPosition = 0;
|
||||
m_dwPhone1LabelID = 0;
|
||||
m_dwPhone2LabelID = 0;
|
||||
m_dwPhone3LabelID = 0;
|
||||
m_dwPhone4LabelID = 0;
|
||||
m_dwPhone5LabelID = 0;
|
||||
m_dwPrivate = 0;
|
||||
m_dwCategoryID = 0;
|
||||
m_dwDisplayPhone = 0;
|
||||
m_csName.Empty();
|
||||
m_csFirst.Empty();
|
||||
m_csTitle.Empty();
|
||||
m_csCompany.Empty();
|
||||
m_csPhone1.Empty();
|
||||
m_csPhone2.Empty();
|
||||
m_csPhone3.Empty();
|
||||
m_csPhone4.Empty();
|
||||
m_csCustom1.Empty();
|
||||
m_csCustom2.Empty();
|
||||
m_csCustom3.Empty();
|
||||
m_csCustom4.Empty();
|
||||
m_csPhone5.Empty();
|
||||
m_csAddress.Empty();
|
||||
m_csCity.Empty();
|
||||
m_csState.Empty();
|
||||
m_csZipCode.Empty();
|
||||
m_csCountry.Empty();
|
||||
m_csNote.Empty();
|
||||
}
|
||||
|
||||
// this method compares this object with another MozAB Conduit record
|
||||
eRecCompare CMozABConduitRecord::Compare(const CMozABConduitRecord &rec)
|
||||
{
|
||||
if ( (m_dwPhone1LabelID != rec.m_dwPhone1LabelID) ||
|
||||
(m_dwPhone2LabelID != rec.m_dwPhone2LabelID) ||
|
||||
(m_dwPhone3LabelID != rec.m_dwPhone3LabelID ) ||
|
||||
(m_dwPhone4LabelID != rec.m_dwPhone4LabelID ) ||
|
||||
(m_dwPhone5LabelID != rec.m_dwPhone5LabelID ) ||
|
||||
(m_dwDisplayPhone != rec.m_dwDisplayPhone ) ||
|
||||
(m_csName != rec.m_csName ) ||
|
||||
(m_csFirst != rec.m_csFirst ) ||
|
||||
(m_csTitle != rec.m_csTitle ) ||
|
||||
(m_csCompany != rec.m_csCompany ) ||
|
||||
(m_csPhone1 != rec.m_csPhone1 ) ||
|
||||
(m_csPhone2 != rec.m_csPhone2 ) ||
|
||||
(m_csPhone3 != rec.m_csPhone3 ) ||
|
||||
(m_csPhone4 != rec.m_csPhone4 ) ||
|
||||
(m_csCustom1 != rec.m_csCustom1 ) ||
|
||||
(m_csCustom2 != rec.m_csCustom2 ) ||
|
||||
(m_csCustom3 != rec.m_csCustom3 ) ||
|
||||
(m_csCustom4 != rec.m_csCustom4 ) ||
|
||||
(m_csPhone5 != rec.m_csPhone5 ) ||
|
||||
(m_csAddress != rec.m_csAddress ) ||
|
||||
(m_csCity != rec.m_csCity ) ||
|
||||
(m_csState != rec.m_csState ) ||
|
||||
(m_csZipCode != rec.m_csZipCode ) ||
|
||||
(m_csCountry != rec.m_csCountry ) ||
|
||||
(m_csNote != rec.m_csNote ))
|
||||
return eData;
|
||||
if (m_dwPrivate != rec.m_dwPrivate )
|
||||
return ePrivateFlag;
|
||||
if (m_dwCategoryID != rec.m_dwCategoryID )
|
||||
return eCategory;
|
||||
|
||||
return eEqual;
|
||||
}
|
||||
|
||||
#define COPY_FROM_GENERIC(m, d) { iLen = _tcslen((char *)pBuff); \
|
||||
AddCRs((char *)pBuff, m.GetBuffer(iLen * 2), iLen); \
|
||||
m.ReleaseBuffer(); \
|
||||
d = m.GetBuffer(0); \
|
||||
pBuff += iLen + 1; \
|
||||
} \
|
||||
|
||||
#define COPY_PHONE_FROM_GENERIC(m, d){ iLen = _tcslen((char *)pBuff); \
|
||||
AddCRs((char *)pBuff, m.GetBuffer(iLen * 2), iLen); \
|
||||
m.ReleaseBuffer(); \
|
||||
AssignPhoneToMozData(d, m.GetBuffer(0)); \
|
||||
pBuff += iLen + 1; \
|
||||
} \
|
||||
|
||||
|
||||
// this method converts CPalmRecord to MozAB Conduit record
|
||||
long CMozABConduitRecord::ConvertFromGeneric(CPalmRecord &rec)
|
||||
{
|
||||
long retval = 0;
|
||||
BYTE *pBuff;
|
||||
AddrDBRecordFlags flags;
|
||||
AddrOptionsType options;
|
||||
int iLen;
|
||||
|
||||
Reset();
|
||||
|
||||
if (rec.GetRawDataSize() == (sizeof(DWORD) + sizeof(DWORD) + sizeof(unsigned char))){
|
||||
// then this is a deleted record because it has no data
|
||||
return GEN_ERR_EMPTY_RECORD;
|
||||
}
|
||||
|
||||
// palm specific data
|
||||
m_dwRecordID = rec.GetID();
|
||||
m_dwCategoryID = rec.GetCategory();
|
||||
m_dwPrivate = rec.IsPrivate();
|
||||
m_dwStatus = rec.GetStatus();
|
||||
|
||||
m_nsCard.dwRecordId = m_dwRecordID;
|
||||
m_nsCard.dwCategoryId = m_dwCategoryID;
|
||||
m_nsCard.dwStatus = m_dwStatus;
|
||||
|
||||
// clear all values in the Address Record
|
||||
m_dwPhone1LabelID = PHONE_LABEL_WORK;
|
||||
m_dwPhone2LabelID = PHONE_LABEL_HOME;
|
||||
m_dwPhone3LabelID = PHONE_LABEL_FAX;
|
||||
m_dwPhone4LabelID = PHONE_LABEL_MOBILE;
|
||||
m_dwPhone5LabelID = PHONE_LABEL_EMAIL;
|
||||
m_dwDisplayPhone = 0;
|
||||
|
||||
DWORD dwRawSize = rec.GetRawDataSize();
|
||||
if (!dwRawSize) {
|
||||
// invalid record
|
||||
return 0;
|
||||
}
|
||||
|
||||
// get the data for moz card
|
||||
pBuff = rec.GetRawData();
|
||||
|
||||
// AddrOptionsType
|
||||
*(DWORD *)&options = CPalmRecord::SwapDWordToIntel(*((DWORD*)pBuff));
|
||||
m_dwDisplayPhone = (long)options.displayPhone + 1;
|
||||
m_dwPhone1LabelID = (DWORD)options.phone1;
|
||||
m_dwPhone2LabelID = (DWORD)options.phone2;
|
||||
m_dwPhone3LabelID = (DWORD)options.phone3;
|
||||
m_dwPhone4LabelID = (DWORD)options.phone4;
|
||||
m_dwPhone5LabelID = (DWORD)options.phone5;
|
||||
|
||||
pBuff += sizeof(DWORD);
|
||||
|
||||
// The flag bits are used to indicate which fields exist
|
||||
*(DWORD *)&flags = CPalmRecord::SwapDWordToIntel(*((DWORD*)pBuff));
|
||||
pBuff += sizeof(DWORD) + sizeof(unsigned char);
|
||||
|
||||
// Name
|
||||
if (flags.name) COPY_FROM_GENERIC(m_csName, m_nsCard.lastName)
|
||||
// FirstName
|
||||
if (flags.firstName) COPY_FROM_GENERIC(m_csFirst, m_nsCard.firstName)
|
||||
// DisplayName
|
||||
m_csDisplayName = m_nsCard.firstName;
|
||||
m_csDisplayName += " ";
|
||||
m_csDisplayName += m_nsCard.lastName;
|
||||
m_nsCard.displayName = m_csDisplayName.GetBuffer(0);
|
||||
// Company
|
||||
if (flags.company) COPY_FROM_GENERIC(m_csCompany, m_nsCard.company)
|
||||
// Phones
|
||||
if (flags.phone1) COPY_PHONE_FROM_GENERIC(m_csPhone1, m_dwPhone1LabelID)
|
||||
if (flags.phone2) COPY_PHONE_FROM_GENERIC(m_csPhone2, m_dwPhone2LabelID)
|
||||
if (flags.phone3) COPY_PHONE_FROM_GENERIC(m_csPhone3, m_dwPhone3LabelID)
|
||||
if (flags.phone4) COPY_PHONE_FROM_GENERIC(m_csPhone4, m_dwPhone4LabelID)
|
||||
if (flags.phone5) COPY_PHONE_FROM_GENERIC(m_csPhone5, m_dwPhone5LabelID)
|
||||
// Address
|
||||
if (flags.address) COPY_FROM_GENERIC(m_csAddress, m_nsCard.homeAddress)
|
||||
// City
|
||||
if (flags.city) COPY_FROM_GENERIC(m_csCity, m_nsCard.homeCity)
|
||||
// State
|
||||
if (flags.state) COPY_FROM_GENERIC(m_csState, m_nsCard.homeState)
|
||||
// ZipCode
|
||||
if (flags.zipCode) COPY_FROM_GENERIC(m_csZipCode, m_nsCard.homeZipCode)
|
||||
// Country
|
||||
if (flags.country) COPY_FROM_GENERIC(m_csCountry, m_nsCard.homeCountry)
|
||||
// Title
|
||||
if (flags.title) COPY_FROM_GENERIC(m_csTitle, m_nsCard.jobTitle)
|
||||
// Customs
|
||||
if (flags.custom1) COPY_FROM_GENERIC(m_csCustom1, m_nsCard.custom1)
|
||||
if (flags.custom2) COPY_FROM_GENERIC(m_csCustom2, m_nsCard.custom2)
|
||||
if (flags.custom3) COPY_FROM_GENERIC(m_csCustom3, m_nsCard.custom3)
|
||||
if (flags.custom4) COPY_FROM_GENERIC(m_csCustom4, m_nsCard.custom4)
|
||||
// Note
|
||||
if (flags.note) COPY_FROM_GENERIC(m_csNote, m_nsCard.notes)
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
// this method assigns the phone #s to the Moz card data from Palm Record Phone buffer
|
||||
void CMozABConduitRecord::AssignPhoneToMozData(DWORD labelID, LPTSTR buf)
|
||||
{
|
||||
switch(labelID) {
|
||||
case PHONE_LABEL_WORK:
|
||||
m_nsCard.workPhone = buf;
|
||||
break;
|
||||
case PHONE_LABEL_HOME:
|
||||
m_nsCard.homePhone = buf;
|
||||
break;
|
||||
case PHONE_LABEL_FAX:
|
||||
m_nsCard.faxNumber = buf;
|
||||
break;
|
||||
case PHONE_LABEL_OTHER:
|
||||
break;
|
||||
case PHONE_LABEL_EMAIL:
|
||||
m_nsCard.primaryEmail = buf;
|
||||
break;
|
||||
case PHONE_LABEL_MAIN:
|
||||
break;
|
||||
case PHONE_LABEL_PAGER:
|
||||
m_nsCard.pagerNumber = buf;
|
||||
break;
|
||||
case PHONE_LABEL_MOBILE:
|
||||
m_nsCard.cellularNumber = buf;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define COPY_TO_GENERIC(m, f) iLen = m.length(); \
|
||||
if (iLen != 0) \
|
||||
{ \
|
||||
f = 1; \
|
||||
destLen = StripCRs(pBuff, m.c_str(), iLen); \
|
||||
pBuff += destLen; \
|
||||
dwRecSize += destLen; \
|
||||
} \
|
||||
|
||||
|
||||
// This method converts records from the Moz type to the CPalmRecord record type.
|
||||
long CMozABConduitRecord::ConvertToGeneric(CPalmRecord &rec)
|
||||
{
|
||||
long retval = 0;
|
||||
char *pBuff, *pFlags, *pCompany, *pFirst;
|
||||
AddrDBRecordFlags flags;
|
||||
AddrOptionsType options;
|
||||
int destLen;
|
||||
BYTE szRawData[MAX_RECORD_SIZE];
|
||||
DWORD dwRecSize = 0;
|
||||
int iLen=0;
|
||||
|
||||
|
||||
rec.SetID(m_dwRecordID);
|
||||
|
||||
rec.SetCategory(m_dwCategoryID);
|
||||
|
||||
if (m_dwPrivate)
|
||||
rec.SetPrivate(TRUE);
|
||||
else
|
||||
rec.SetPrivate(FALSE);
|
||||
|
||||
rec.SetAttribs(m_dwStatus);
|
||||
|
||||
pBuff = (char*)szRawData;
|
||||
|
||||
// AddrOptionsType
|
||||
*(DWORD *)&options = 0;
|
||||
options.displayPhone = m_dwDisplayPhone - 1;
|
||||
options.phone1 = LOWORD(m_dwPhone1LabelID);
|
||||
options.phone2 = LOWORD(m_dwPhone2LabelID);
|
||||
options.phone3 = LOWORD(m_dwPhone3LabelID);
|
||||
options.phone4 = LOWORD(m_dwPhone4LabelID);
|
||||
options.phone5 = LOWORD(m_dwPhone5LabelID);
|
||||
*((DWORD *)pBuff) = CPalmRecord::SwapDWordToMotor(*(DWORD *)&options);
|
||||
|
||||
pBuff += sizeof(DWORD);
|
||||
dwRecSize += sizeof(DWORD);
|
||||
|
||||
// The flag bits are used to indicate which fields exist
|
||||
pFlags = pBuff;
|
||||
*(DWORD *)&flags = 0;
|
||||
pBuff += sizeof(DWORD);
|
||||
dwRecSize += sizeof(DWORD);
|
||||
|
||||
// Company Field Offset - Initialize to zero
|
||||
pCompany = pBuff;
|
||||
*((unsigned char *)pCompany) = 0;
|
||||
pBuff += sizeof(unsigned char);
|
||||
dwRecSize += sizeof(unsigned char);
|
||||
|
||||
// First Field
|
||||
pFirst = pBuff;
|
||||
|
||||
// Name
|
||||
COPY_TO_GENERIC(m_csName, flags.name)
|
||||
// FirstName
|
||||
COPY_TO_GENERIC(m_csFirst, flags.firstName)
|
||||
// Company
|
||||
COPY_TO_GENERIC(m_csCompany, flags.company)
|
||||
// Phone1
|
||||
COPY_TO_GENERIC(m_csPhone1, flags.phone1)
|
||||
// Phone2
|
||||
COPY_TO_GENERIC(m_csPhone2, flags.phone2)
|
||||
// Phone3
|
||||
COPY_TO_GENERIC(m_csPhone3, flags.phone3)
|
||||
// Phone4
|
||||
COPY_TO_GENERIC(m_csPhone4, flags.phone4)
|
||||
// Phone5
|
||||
COPY_TO_GENERIC(m_csPhone5, flags.phone5)
|
||||
// Address
|
||||
COPY_TO_GENERIC(m_csAddress, flags.address)
|
||||
// City
|
||||
COPY_TO_GENERIC(m_csCity, flags.city)
|
||||
// State
|
||||
COPY_TO_GENERIC(m_csState, flags.state)
|
||||
// ZipCode
|
||||
COPY_TO_GENERIC(m_csZipCode, flags.zipCode)
|
||||
// Country
|
||||
COPY_TO_GENERIC(m_csCountry, flags.country)
|
||||
// Title
|
||||
COPY_TO_GENERIC(m_csTitle, flags.title)
|
||||
// Custom1
|
||||
COPY_TO_GENERIC(m_csCustom1, flags.custom1)
|
||||
// Custom2
|
||||
COPY_TO_GENERIC(m_csCustom2, flags.custom2)
|
||||
// Custom3
|
||||
COPY_TO_GENERIC(m_csCustom3, flags.custom3)
|
||||
// Custom4
|
||||
COPY_TO_GENERIC(m_csCustom4, flags.custom4)
|
||||
// Note
|
||||
COPY_TO_GENERIC(m_csNote, flags.note)
|
||||
|
||||
// Store the AddrDBRecordFlags
|
||||
*((DWORD *)pFlags) = CPalmRecord::SwapDWordToMotor(*(DWORD *)&flags);
|
||||
|
||||
|
||||
if (dwRecSize == (sizeof(DWORD) + sizeof(DWORD) + sizeof(unsigned char))){
|
||||
// then this is a deleted record because it has no data
|
||||
rec.SetDeleted();
|
||||
}
|
||||
|
||||
retval = rec.SetRawData(dwRecSize, szRawData);
|
||||
|
||||
return(retval);
|
||||
}
|
||||
|
||||
// this function adds carraige returns to handheld data
|
||||
long CMozABConduitRecord::AddCRs(TCHAR* pSrc, TCHAR* pDest, int len)
|
||||
{
|
||||
long retval = GEN_ERR_INVALID_POINTER;
|
||||
int off=0;
|
||||
|
||||
TCHAR* pCurr;
|
||||
|
||||
if (pDest) {
|
||||
|
||||
// Only add Cr's if newlines are present..
|
||||
pCurr = _tcspbrk(pSrc, STR_NEWLINE);
|
||||
if(pCurr)
|
||||
{
|
||||
while (off < len && *pSrc) {
|
||||
if (*pSrc == CH_NEWLINE){
|
||||
*pDest = CH_CRETURN;
|
||||
pDest++;
|
||||
}
|
||||
*pDest = *pSrc;
|
||||
|
||||
pDest++ ; pSrc++;
|
||||
off++;
|
||||
}
|
||||
*pDest = 0;
|
||||
} else {
|
||||
strncpy(pDest, pSrc, len);
|
||||
pDest[len] = 0;
|
||||
}
|
||||
retval = 0;
|
||||
}
|
||||
return(retval);
|
||||
}
|
||||
|
||||
// this function strips extra carraige returns from PC data
|
||||
int CMozABConduitRecord::StripCRs(TCHAR* pDest, const TCHAR* pSrc, int len)
|
||||
{
|
||||
int retval = 0;
|
||||
int off = 0;
|
||||
TCHAR* pCurr;
|
||||
TCHAR* pStart = pDest;
|
||||
|
||||
// See if any cr's are present in the first place.
|
||||
pCurr = _tcspbrk(pSrc, STR_CRETURN);
|
||||
if (pCurr)
|
||||
{
|
||||
while (off < len && *pSrc)
|
||||
{
|
||||
if (*pSrc == CH_CRETURN)
|
||||
pSrc++;
|
||||
|
||||
*pDest = *pSrc;
|
||||
|
||||
off++;
|
||||
pDest++ ; pSrc++;
|
||||
}
|
||||
*pDest = 0;
|
||||
|
||||
retval = strlen(pStart) + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(pDest, pSrc, len);
|
||||
*(pDest + len) = '\0';
|
||||
retval = len + 1;
|
||||
}
|
||||
|
||||
return(retval);
|
||||
}
|
|
@ -0,0 +1,164 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Rajiv Dayal <rdayal@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __MOZABCONDUIT_RECORD_H_
|
||||
#define __MOZABCONDUIT_RECORD_H_
|
||||
|
||||
#include <syncmgr.h>
|
||||
#include "CPString.h"
|
||||
#include "CPalmRec.h"
|
||||
#include <PGenErr.h>
|
||||
#include <tables.h>
|
||||
|
||||
#include "IPalmSync.h"
|
||||
|
||||
// these identify the types of phone numbers in Palm record
|
||||
#define PHONE_LABEL_WORK 0
|
||||
#define PHONE_LABEL_HOME 1
|
||||
#define PHONE_LABEL_FAX 2
|
||||
#define PHONE_LABEL_OTHER 3
|
||||
#define PHONE_LABEL_EMAIL 4
|
||||
#define PHONE_LABEL_MAIN 5
|
||||
#define PHONE_LABEL_PAGER 6
|
||||
#define PHONE_LABEL_MOBILE 7
|
||||
|
||||
// these are flags which says if a field in Palm record exist or not
|
||||
struct AddrDBRecordFlags {
|
||||
unsigned name :1;
|
||||
unsigned firstName :1;
|
||||
unsigned company :1;
|
||||
unsigned phone1 :1;
|
||||
unsigned phone2 :1;
|
||||
unsigned phone3 :1;
|
||||
unsigned phone4 :1;
|
||||
unsigned phone5 :1;
|
||||
unsigned address :1;
|
||||
unsigned city :1;
|
||||
unsigned state :1;
|
||||
unsigned zipCode :1;
|
||||
unsigned country :1;
|
||||
unsigned title :1;
|
||||
unsigned custom1 :1;
|
||||
unsigned custom2 :1;
|
||||
unsigned custom3 :1;
|
||||
unsigned custom4 :1;
|
||||
unsigned note :1;
|
||||
unsigned reserved :13;
|
||||
};
|
||||
|
||||
// these are the flag that identify the type of phone #s in Palm record
|
||||
struct AddrOptionsType {
|
||||
unsigned phone1 :4;
|
||||
unsigned phone2 :4;
|
||||
unsigned phone3 :4;
|
||||
unsigned phone4 :4;
|
||||
unsigned phone5 :4;
|
||||
unsigned displayPhone :4;
|
||||
unsigned reserved :8;
|
||||
};
|
||||
|
||||
// class implementation that represents the Mozilla AB Record type
|
||||
// used along with Palm record type
|
||||
class CMozABConduitRecord {
|
||||
|
||||
public:
|
||||
CMozABConduitRecord(void);
|
||||
CMozABConduitRecord(CPalmRecord &rec);
|
||||
CMozABConduitRecord(nsABCOMCardStruct &rec);
|
||||
virtual ~CMozABConduitRecord();
|
||||
|
||||
public:
|
||||
// Mozilla AB card data structure member
|
||||
nsABCOMCardStruct m_nsCard;
|
||||
|
||||
// the following data members are for Palm Record
|
||||
DWORD m_dwRecordID;
|
||||
DWORD m_dwStatus;
|
||||
DWORD m_dwPosition;
|
||||
CPString m_csName;
|
||||
CPString m_csFirst;
|
||||
CPString m_csDisplayName;
|
||||
CPString m_csTitle;
|
||||
CPString m_csCompany;
|
||||
DWORD m_dwPhone1LabelID;
|
||||
CPString m_csPhone1;
|
||||
DWORD m_dwPhone2LabelID;
|
||||
CPString m_csPhone2;
|
||||
DWORD m_dwPhone3LabelID;
|
||||
CPString m_csPhone3;
|
||||
DWORD m_dwPhone4LabelID;
|
||||
CPString m_csPhone4;
|
||||
DWORD m_dwPhone5LabelID;
|
||||
CPString m_csPhone5;
|
||||
CPString m_csAddress;
|
||||
CPString m_csCity;
|
||||
CPString m_csState;
|
||||
CPString m_csZipCode;
|
||||
CPString m_csCountry;
|
||||
CPString m_csNote;
|
||||
DWORD m_dwPrivate;
|
||||
DWORD m_dwCategoryID;
|
||||
CPString m_csCustom1;
|
||||
CPString m_csCustom2;
|
||||
CPString m_csCustom3;
|
||||
CPString m_csCustom4;
|
||||
DWORD m_dwDisplayPhone;
|
||||
|
||||
protected:
|
||||
|
||||
// internal utility functions
|
||||
long AddCRs(TCHAR* pSrc, TCHAR* pDest, int len, int iBufSize);
|
||||
long AddCRs(TCHAR* pSrc, TCHAR* pDest, int len);
|
||||
int StripCRs(TCHAR* pDest, const TCHAR* pSrc, int len);
|
||||
|
||||
void AssignPhoneToMozData(DWORD labelID, LPTSTR buf);
|
||||
|
||||
public:
|
||||
// rests the data in this record object
|
||||
void Reset(void);
|
||||
// compares with another record object
|
||||
eRecCompare Compare(const CMozABConduitRecord &rec);
|
||||
|
||||
// converts from Palm record type to self(Mozilla AB) type
|
||||
long ConvertFromGeneric(CPalmRecord &rec);
|
||||
// converts from self(Mozilla AB) type to Palm record type
|
||||
long ConvertToGeneric(CPalmRecord &rec);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,429 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Rajiv Dayal <rdayal@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <windows.h>
|
||||
#include "syncmgr.h"
|
||||
#include <tchar.h>
|
||||
|
||||
#include "MozABConduitSync.h"
|
||||
#include "MozABConduitRecord.h"
|
||||
|
||||
|
||||
#define MAX_PROD_ID_TEXT 255
|
||||
#define PERSONAL "Personal"
|
||||
|
||||
CMozABConduitSync::CMozABConduitSync(CSyncProperties& rProps)
|
||||
{
|
||||
m_dbHH = NULL;
|
||||
m_dbPC = NULL;
|
||||
m_remoteDB = NULL;
|
||||
m_TotRemoteDBs = rProps.m_nRemoteCount; // Fixed 3/25/99 KRM
|
||||
m_ConduitHandle = (CONDHANDLE)0;
|
||||
memcpy(&m_rSyncProperties, &rProps, sizeof(m_rSyncProperties));
|
||||
memset(&m_SystemInfo, 0, sizeof(m_SystemInfo));
|
||||
}
|
||||
|
||||
CMozABConduitSync::~CMozABConduitSync()
|
||||
{
|
||||
long retval;
|
||||
|
||||
if (m_SystemInfo.m_ProductIdText) {
|
||||
delete m_SystemInfo.m_ProductIdText;
|
||||
m_SystemInfo.m_ProductIdText = NULL;
|
||||
m_SystemInfo.m_AllocedLen = 0;
|
||||
}
|
||||
if ((!m_rSyncProperties.m_RemoteDbList) && (m_remoteDB)) {
|
||||
delete m_remoteDB;
|
||||
m_remoteDB = NULL;
|
||||
}
|
||||
if (m_ConduitHandle) {
|
||||
retval = SyncUnRegisterConduit(m_ConduitHandle);
|
||||
m_ConduitHandle = 0;
|
||||
}
|
||||
}
|
||||
|
||||
long CMozABConduitSync::Perform(void)
|
||||
{
|
||||
long retval = 0;
|
||||
|
||||
if (m_rSyncProperties.m_SyncType > eProfileInstall)
|
||||
return GEN_ERR_BAD_SYNC_TYPE;
|
||||
|
||||
if (m_rSyncProperties.m_SyncType == eDoNothing) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Obtain System Information
|
||||
m_SystemInfo.m_ProductIdText = (BYTE*) new char [MAX_PROD_ID_TEXT]; //deleted in d'ctor
|
||||
if (!m_SystemInfo.m_ProductIdText)
|
||||
return GEN_ERR_LOW_MEMORY;
|
||||
|
||||
m_SystemInfo.m_AllocedLen = (BYTE) MAX_PROD_ID_TEXT;
|
||||
retval = SyncReadSystemInfo(m_SystemInfo);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
// Register this conduit with SyncMgr.DLL for communication to HH
|
||||
retval = SyncRegisterConduit(m_ConduitHandle);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
for (int iCount=0; iCount < m_TotRemoteDBs && !retval; iCount++) {
|
||||
retval = GetRemoteDBInfo(iCount);
|
||||
if (retval) {
|
||||
retval = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
m_dbHH = new MozABHHManager(GENERIC_FLAG_APPINFO_SUPPORTED | GENERIC_FLAG_CATEGORY_SUPPORTED,
|
||||
m_remoteDB->m_Name,
|
||||
m_remoteDB->m_Creator,
|
||||
m_remoteDB->m_DbType,
|
||||
m_remoteDB->m_DbFlags,
|
||||
0,
|
||||
m_remoteDB->m_CardNum,
|
||||
m_rSyncProperties.m_SyncType);
|
||||
if(!m_dbHH)
|
||||
return GEN_ERR_LOW_MEMORY;
|
||||
|
||||
m_dbPC = new MozABPCManager();
|
||||
if(!m_dbPC) {
|
||||
if (m_dbHH)
|
||||
delete m_dbHH;
|
||||
m_dbHH = NULL;
|
||||
return GEN_ERR_LOW_MEMORY;
|
||||
}
|
||||
|
||||
switch (m_rSyncProperties.m_SyncType) {
|
||||
case eFast:
|
||||
retval = PerformFastSync();
|
||||
if ((retval) && (retval == GEN_ERR_CHANGE_SYNC_MODE)){
|
||||
if (m_rSyncProperties.m_SyncType == eHHtoPC)
|
||||
retval = CopyHHtoPC();
|
||||
else if (m_rSyncProperties.m_SyncType == ePCtoHH)
|
||||
retval = CopyPCtoHH();
|
||||
}
|
||||
break;
|
||||
case eSlow:
|
||||
retval = PerformSlowSync();
|
||||
if ((retval) && (retval == GEN_ERR_CHANGE_SYNC_MODE)){
|
||||
if (m_rSyncProperties.m_SyncType == eHHtoPC)
|
||||
retval = CopyHHtoPC();
|
||||
else if (m_rSyncProperties.m_SyncType == ePCtoHH)
|
||||
retval = CopyPCtoHH();
|
||||
}
|
||||
break;
|
||||
case eHHtoPC:
|
||||
case eBackup:
|
||||
retval = CopyHHtoPC();
|
||||
break;
|
||||
case eInstall:
|
||||
case ePCtoHH:
|
||||
case eProfileInstall:
|
||||
retval = CopyPCtoHH();
|
||||
break;
|
||||
case eDoNothing:
|
||||
break;
|
||||
default:
|
||||
retval = GEN_ERR_SYNC_TYPE_NOT_SUPPORTED;
|
||||
break;
|
||||
}
|
||||
|
||||
// remove the handheld and PC manager
|
||||
if (m_dbHH)
|
||||
delete m_dbHH;
|
||||
m_dbHH = NULL;
|
||||
if (m_dbPC)
|
||||
delete m_dbPC;
|
||||
m_dbPC = NULL;
|
||||
}
|
||||
|
||||
// Unregister the conduit
|
||||
long retval2 = 0;
|
||||
if (m_ConduitHandle) {
|
||||
retval2 = SyncUnRegisterConduit(m_ConduitHandle);
|
||||
m_ConduitHandle = 0;
|
||||
}
|
||||
|
||||
if (!retval)
|
||||
return retval2;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
long CMozABConduitSync::GetRemoteDBInfo(int iIndex)
|
||||
{
|
||||
long retval = 0;
|
||||
if (m_rSyncProperties.m_RemoteDbList) {
|
||||
m_remoteDB = m_rSyncProperties.m_RemoteDbList[iIndex];
|
||||
} else {
|
||||
if (m_remoteDB)
|
||||
delete m_remoteDB;
|
||||
|
||||
m_remoteDB = new CDbList; // deleted in d'ctor
|
||||
if (m_remoteDB) {
|
||||
m_remoteDB->m_Creator = m_rSyncProperties.m_Creator;
|
||||
m_remoteDB->m_DbFlags = eRecord; // todo
|
||||
m_remoteDB->m_DbType = m_rSyncProperties.m_DbType;
|
||||
strcpy(m_remoteDB->m_Name, m_rSyncProperties.m_RemoteName[iIndex]);
|
||||
m_remoteDB->m_Version = 0;
|
||||
m_remoteDB->m_CardNum = 0;
|
||||
m_remoteDB->m_ModNumber = 0;
|
||||
m_remoteDB->m_CreateDate= 0;
|
||||
m_remoteDB->m_ModDate = 0;
|
||||
m_remoteDB->m_BackupDate= 0;
|
||||
} else {
|
||||
retval = GEN_ERR_LOW_MEMORY;
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
// this is done in separate thread since the main thread in this DLL
|
||||
// needs to call SyncYieldCycles(1) atleast once every 7 seconds
|
||||
DWORD WINAPI DoFastSync(LPVOID lpParameter)
|
||||
{
|
||||
long retval=0;
|
||||
BOOL success = FALSE;
|
||||
|
||||
CMozABConduitSync * sync = (CMozABConduitSync * ) lpParameter;
|
||||
if(!sync)
|
||||
return retval;
|
||||
|
||||
if(sync->m_dbHH) {
|
||||
DWORD mozABCount=0;
|
||||
DWORD * mozCatIDList = NULL; // freed by MSCOM/Mozilla
|
||||
CPString ** mozABNameList = NULL; // freed by MSCOM/Mozilla
|
||||
BOOL * mozIsFirstSyncList = NULL; // freed by MSCOM/Mozilla
|
||||
|
||||
retval = sync->m_dbHH->OpenDB(FALSE);
|
||||
if (!retval)
|
||||
retval = sync->m_dbHH->LoadCategories();
|
||||
|
||||
if(!retval)
|
||||
retval = sync->m_dbPC->GetPCABList(&mozABCount, &mozCatIDList, &mozABNameList, &mozIsFirstSyncList);
|
||||
|
||||
// for each category synchronize
|
||||
if (!retval) {
|
||||
CPCategory * pCategory = sync->m_dbHH->GetFirstCategory();
|
||||
while (pCategory) {
|
||||
CPalmRecord ** recordListHH = NULL;
|
||||
DWORD recordCountHH=0;
|
||||
|
||||
DWORD catID = pCategory->GetID();
|
||||
DWORD catIndex = pCategory->GetIndex();
|
||||
CPString catName(pCategory->GetName());
|
||||
|
||||
DWORD mozABIndex=0;
|
||||
BOOL foundInABList=FALSE;
|
||||
for(mozABIndex=0; mozABIndex<mozABCount; mozABIndex++) {
|
||||
// if this category has been synchronized before
|
||||
if(catID == mozCatIDList[mozABIndex]) {
|
||||
retval = sync->m_dbHH->LoadUpdatedRecordsInCategory(catIndex, &recordListHH, &recordCountHH);
|
||||
foundInABList = TRUE;
|
||||
break;
|
||||
}
|
||||
// if corresponding category exists but not synchronized before
|
||||
if(!catName.CompareNoCase(mozABNameList[mozABIndex]->GetBuffer(0))) {
|
||||
retval = sync->m_dbHH->LoadAllRecordsInCategory(catIndex, &recordListHH, &recordCountHH);
|
||||
foundInABList = TRUE;
|
||||
break;
|
||||
}
|
||||
// if it is PAB, called 'Personal' on Palm and 'Personal Address Book' in Mozilla/Netscape
|
||||
CPString personal(PERSONAL);
|
||||
if( (catName.Find(personal) != -1) &&
|
||||
(mozABNameList[mozABIndex]->Find(personal) != -1) ) {
|
||||
retval = sync->m_dbHH->LoadAllRecordsInCategory(catIndex, &recordListHH, &recordCountHH);
|
||||
foundInABList = TRUE;
|
||||
break;
|
||||
}
|
||||
} // end of for
|
||||
|
||||
if(!retval && foundInABList) {
|
||||
CPalmRecord ** recordListPC=NULL;
|
||||
DWORD recordCountPC=0;
|
||||
DWORD newRecAddedCount = 0;
|
||||
DWORD * newRecIDList=NULL;
|
||||
retval = sync->m_dbPC->SynchronizePCAB(catID, catName,
|
||||
recordCountHH, recordListHH,
|
||||
&recordCountPC, &recordListPC);
|
||||
if (!retval) {
|
||||
newRecIDList = (DWORD *) calloc(recordCountPC, sizeof(DWORD));
|
||||
for (unsigned long i=0; i < recordCountPC; i++) {
|
||||
if(!recordListPC[i])
|
||||
continue;
|
||||
CPalmRecord palmRec = *recordListPC[i];
|
||||
palmRec.SetCategory(catIndex);
|
||||
if(palmRec.GetAttribs() == ATTR_DELETED)
|
||||
retval = sync->m_dbHH->DeleteARecord(palmRec);
|
||||
else if(palmRec.GetAttribs() == ATTR_MODIFIED)
|
||||
retval = sync->m_dbHH->UpdateARecord(palmRec);
|
||||
else if(palmRec.GetAttribs() == ATTR_NEW) {
|
||||
retval = sync->m_dbHH->AddARecord(palmRec); // should we check existing recs?
|
||||
if(!retval && (newRecAddedCount < recordCountPC)) {
|
||||
newRecIDList[newRecAddedCount] = palmRec.GetID();
|
||||
newRecAddedCount++;
|
||||
}
|
||||
}
|
||||
delete recordListPC[i]; // once done with PC record, delete
|
||||
}
|
||||
}
|
||||
// the MozAB is now synchronized
|
||||
if(!retval)
|
||||
mozIsFirstSyncList[mozABIndex] = FALSE;
|
||||
// delete the PC recordList now that palm is updated
|
||||
if(recordListPC)
|
||||
free(recordListPC);
|
||||
// notify Mozilla that sync is done so that memory can be freed
|
||||
if(!retval)
|
||||
success = TRUE;
|
||||
|
||||
if(newRecAddedCount) {
|
||||
if(newRecAddedCount != recordCountPC)
|
||||
newRecIDList = (DWORD *) realloc(newRecIDList, newRecAddedCount);
|
||||
retval = sync->m_dbPC->NotifySyncDone(success, catID, newRecAddedCount, newRecIDList);
|
||||
}
|
||||
else
|
||||
retval = sync->m_dbPC->NotifySyncDone(success);
|
||||
|
||||
if(newRecIDList)
|
||||
free(newRecIDList);
|
||||
}
|
||||
|
||||
if(!retval && !foundInABList) {
|
||||
retval = sync->m_dbHH->LoadAllRecordsInCategory(catIndex, &recordListHH, &recordCountHH);
|
||||
if(!retval && recordCountHH)
|
||||
retval = sync->m_dbPC->AddRecords(catID, catName, recordCountHH, recordListHH);
|
||||
}
|
||||
// delete and free HH records and recordList once synced
|
||||
if(recordListHH) {
|
||||
CPalmRecord ** tempRecordListHH = recordListHH;
|
||||
for(DWORD i=0; i < recordCountHH; i++) {
|
||||
if(*tempRecordListHH)
|
||||
delete *tempRecordListHH;
|
||||
tempRecordListHH++;
|
||||
}
|
||||
free(recordListHH);
|
||||
}
|
||||
|
||||
pCategory = sync->m_dbHH->GetNextCategory();
|
||||
} // end of while
|
||||
|
||||
// deal with any Moz AB not existing in Palm, ones not sync'ed above
|
||||
for(DWORD mozABIndex=0; mozABIndex<mozABCount; mozABIndex++) {
|
||||
if(mozIsFirstSyncList[mozABIndex]) {
|
||||
CPalmRecord ** recordListPC=NULL;
|
||||
DWORD recordCountPC=0;
|
||||
DWORD * newRecIDList=NULL;
|
||||
CPCategory cat;
|
||||
retval = sync->m_dbPC->LoadAllRecords(*mozABNameList[mozABIndex],
|
||||
&recordCountPC, &recordListPC);
|
||||
if(!retval && recordCountPC) {
|
||||
cat.SetName(mozABNameList[mozABIndex]->GetBuffer(0));
|
||||
retval = sync->m_dbHH->AddCategory(cat);
|
||||
}
|
||||
|
||||
if(!retval) {
|
||||
newRecIDList = (DWORD *) calloc(recordCountPC, sizeof(DWORD));
|
||||
for (unsigned long i=0; i < recordCountPC; i++) {
|
||||
if(!recordListPC[i])
|
||||
continue;
|
||||
CPalmRecord palmRec = *recordListPC[i];
|
||||
palmRec.SetCategory(cat.GetIndex());
|
||||
retval = sync->m_dbHH->AddARecord(palmRec); // should we check existing recs?
|
||||
newRecIDList[i] = palmRec.GetID();
|
||||
delete recordListPC[i]; // delete the record now that it is used
|
||||
}
|
||||
}
|
||||
// the MozAB is now synchronized
|
||||
if(!retval)
|
||||
mozIsFirstSyncList[mozABIndex] = FALSE;
|
||||
// delete the recordList now that palm is updated
|
||||
if(recordListPC)
|
||||
free(recordListPC);
|
||||
// notify Mozilla that sync is done so that memory can be freed
|
||||
if(!retval)
|
||||
success = TRUE;
|
||||
else
|
||||
recordCountPC=0;
|
||||
retval = sync->m_dbPC->NotifySyncDone(success, cat.GetID(), recordCountPC, newRecIDList);
|
||||
if(newRecIDList)
|
||||
free(newRecIDList);
|
||||
}
|
||||
} // end of mozAB for loop
|
||||
}
|
||||
|
||||
// update category info in HH
|
||||
sync->m_dbHH->CompactCategoriesToHH();
|
||||
|
||||
// close the HH DB once synced
|
||||
retval = sync->m_dbHH->CloseDB(FALSE);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
long CMozABConduitSync::PerformFastSync()
|
||||
{
|
||||
DWORD ThreadId;
|
||||
HANDLE hThread = CreateThread(NULL, 0, DoFastSync, this, 0, &ThreadId);
|
||||
while (WaitForSingleObject(hThread, 1000) == WAIT_TIMEOUT) {
|
||||
SyncYieldCycles(1); // every sec call this for feedback & keep Palm connection alive
|
||||
continue;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
long CMozABConduitSync::PerformSlowSync()
|
||||
{
|
||||
// we take care of fist time sync in fast sync in an optimized way
|
||||
return PerformFastSync();
|
||||
}
|
||||
|
||||
long CMozABConduitSync::CopyHHtoPC()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
long CMozABConduitSync::CopyPCtoHH()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Rajiv Dayal <rdayal@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef _MOZABCONDUIT_SYNC_H_
|
||||
#define _MOZABCONDUIT_SYNC_H_
|
||||
|
||||
#include <Cpalmrec.h>
|
||||
#include <Pgenerr.h>
|
||||
|
||||
#include "MozABHHManager.h"
|
||||
#include "MozABPCManager.h"
|
||||
|
||||
class CMozABConduitSync
|
||||
{
|
||||
public:
|
||||
// OpenConduit creates a new object using this constructor
|
||||
CMozABConduitSync(CSyncProperties& rProps);
|
||||
// destructor
|
||||
~CMozABConduitSync();
|
||||
|
||||
// OpenConduit calls this function to begin the sync process
|
||||
long Perform();
|
||||
|
||||
friend DWORD WINAPI DoFastSync(LPVOID lpParameter);
|
||||
|
||||
protected:
|
||||
// default constructor
|
||||
CMozABConduitSync();
|
||||
|
||||
// initialization method
|
||||
long GetRemoteDBInfo(int iIndex);
|
||||
|
||||
// synchronization methods
|
||||
long PerformFastSync();
|
||||
long PerformSlowSync();
|
||||
long CopyHHtoPC();
|
||||
long CopyPCtoHH();
|
||||
|
||||
private:
|
||||
CSyncProperties m_rSyncProperties;
|
||||
|
||||
MozABHHManager *m_dbHH;
|
||||
MozABPCManager *m_dbPC;
|
||||
CDbList *m_remoteDB;
|
||||
short m_TotRemoteDBs;
|
||||
CSystemInfo m_SystemInfo;
|
||||
CONDHANDLE m_ConduitHandle;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,724 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Rajiv Dayal <rdayal@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <windows.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
#include <sys/stat.h>
|
||||
#include <TCHAR.H>
|
||||
|
||||
#include <syncmgr.h>
|
||||
#include <Pgenerr.h>
|
||||
|
||||
#include "MozABHHManager.h"
|
||||
|
||||
MozABHHManager::MozABHHManager(DWORD dwGenericFlags,
|
||||
char *pName,
|
||||
DWORD dwCreator,
|
||||
DWORD dwType,
|
||||
WORD dbFlags,
|
||||
WORD dbVersion,
|
||||
int iCardNum,
|
||||
eSyncTypes syncType)
|
||||
{
|
||||
m_hhDB = 0;
|
||||
|
||||
m_rInfo.m_pBytes = NULL;
|
||||
m_rInfo.m_TotalBytes = 0;
|
||||
|
||||
m_dwMaxRecordCount = 0;
|
||||
m_pCatMgr = NULL;
|
||||
|
||||
|
||||
m_szName[0] = '\0';
|
||||
SetName( pName);
|
||||
m_dwCreator = dwCreator;
|
||||
m_dwType = dwType;
|
||||
m_wFlags = dbFlags;
|
||||
m_wVersion = dbVersion;
|
||||
m_CardNum = iCardNum;
|
||||
|
||||
memset(&m_appInfo, 0, sizeof(CDbGenInfo));
|
||||
}
|
||||
|
||||
MozABHHManager::~MozABHHManager()
|
||||
{
|
||||
if (m_rInfo.m_pBytes != NULL) {
|
||||
delete m_rInfo.m_pBytes;
|
||||
}
|
||||
m_rInfo.m_pBytes = NULL;
|
||||
m_rInfo.m_TotalBytes = 0;
|
||||
|
||||
if (m_appInfo.m_pBytes) {
|
||||
delete m_appInfo.m_pBytes;
|
||||
m_appInfo.m_pBytes = NULL;
|
||||
}
|
||||
|
||||
if (m_pCatMgr) {
|
||||
delete m_pCatMgr;
|
||||
m_pCatMgr = NULL;
|
||||
}
|
||||
|
||||
CloseDB(TRUE);
|
||||
}
|
||||
|
||||
|
||||
long MozABHHManager::AllocateDBInfo(CDbGenInfo &info, BOOL bClearData)
|
||||
{
|
||||
BOOL bNew = FALSE;
|
||||
|
||||
if (!info.m_pBytes) {
|
||||
info.m_pBytes = (BYTE *) new char[MAX_RECORD_SIZE]; // deleted in d'ctor or by caller
|
||||
if (!info.m_pBytes)
|
||||
return GEN_ERR_LOW_MEMORY;
|
||||
info.m_TotalBytes = MAX_RECORD_SIZE;
|
||||
bNew = TRUE;
|
||||
}
|
||||
|
||||
if ((bClearData) || (bNew)) {
|
||||
memset(info.m_pBytes, 0, info.m_TotalBytes);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
long MozABHHManager::GetInfoBlock(CDbGenInfo &info, BOOL bSortInfo)
|
||||
{
|
||||
long retval=0;
|
||||
|
||||
// Allocate storage for app/sort info blocks
|
||||
retval = AllocateDBInfo(info);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
_tcscpy((char*)info.m_FileName, m_szName);
|
||||
memset(info.m_pBytes, 0, info.m_TotalBytes);
|
||||
|
||||
if (!bSortInfo) {
|
||||
// Read the AppInfo block
|
||||
retval = SyncReadDBAppInfoBlock(m_hhDB, info);
|
||||
} else {
|
||||
// Read the SortInfo block
|
||||
retval = SyncReadDBSortInfoBlock(m_hhDB, info);
|
||||
}
|
||||
if (retval) {// if error then clean up
|
||||
delete info.m_pBytes;
|
||||
info.m_pBytes = NULL;
|
||||
info.m_TotalBytes = 0;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
long MozABHHManager::GetAppInfo(CDbGenInfo &rInfo)
|
||||
{
|
||||
long retval = 0;
|
||||
BYTE *pBuffer;
|
||||
|
||||
pBuffer = rInfo.m_pBytes;
|
||||
WORD wTotalBytes = rInfo.m_TotalBytes;
|
||||
memset(&rInfo, 0, sizeof(CDbGenInfo));
|
||||
if ((wTotalBytes > 0) && (pBuffer)) {
|
||||
memset(pBuffer, 0, wTotalBytes);
|
||||
rInfo.m_pBytes = pBuffer;
|
||||
rInfo.m_TotalBytes = wTotalBytes;
|
||||
}
|
||||
|
||||
retval = GetInfoBlock(rInfo);
|
||||
|
||||
if (retval) { // if error cleanup
|
||||
if (rInfo.m_pBytes) {
|
||||
delete rInfo.m_pBytes;
|
||||
rInfo.m_pBytes = NULL;
|
||||
rInfo.m_TotalBytes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
long MozABHHManager::SetName( char *pName)
|
||||
{
|
||||
if (m_hhDB)
|
||||
return GEN_ERR_DB_ALREADY_OPEN;
|
||||
|
||||
WORD wLen;
|
||||
if (!pName){
|
||||
*m_szName = '\0';
|
||||
return 0;
|
||||
}
|
||||
wLen = (WORD)strlen(pName);
|
||||
if (!wLen) {
|
||||
*m_szName = '\0';
|
||||
return 0;
|
||||
}
|
||||
if (wLen >= sizeof(m_szName))
|
||||
return GEN_ERR_DATA_TOO_LARGE;
|
||||
|
||||
strcpy(m_szName, pName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
long MozABHHManager::LoadCategories(void)
|
||||
{
|
||||
long retval=0;
|
||||
|
||||
if (m_pCatMgr) { // remove existing manager
|
||||
delete m_pCatMgr;
|
||||
m_pCatMgr = NULL;
|
||||
}
|
||||
|
||||
if (m_appInfo.m_BytesRead == 0){
|
||||
retval = GetAppInfo(m_appInfo);
|
||||
if (retval)
|
||||
return retval;
|
||||
}
|
||||
|
||||
if ((m_appInfo.m_BytesRead > 0) && (m_appInfo.m_pBytes)){
|
||||
m_pCatMgr = new CPCategoryMgr(m_appInfo.m_pBytes, m_appInfo.m_BytesRead); // deleted in d'ctor
|
||||
if (!m_pCatMgr)
|
||||
return GEN_ERR_LOW_MEMORY;
|
||||
} else {
|
||||
retval = GEN_ERR_NO_CATEGORIES;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
long MozABHHManager::AddCategory(CPCategory & cat)
|
||||
{
|
||||
long retval=0;
|
||||
|
||||
if(!m_pCatMgr)
|
||||
retval = LoadCategories();
|
||||
|
||||
// generate a new ID and Add the category
|
||||
if(!retval) {
|
||||
for(int id=0; id<=MAX_CATEGORIES; id++)
|
||||
if(!m_pCatMgr->FindID(id))
|
||||
break;
|
||||
// if ID doesnot already exist
|
||||
if(id<MAX_CATEGORIES) {
|
||||
cat.SetID(MAKELONG(id, 0));
|
||||
retval = m_pCatMgr->Add(cat);
|
||||
}
|
||||
else
|
||||
retval = CAT_NO_ID;
|
||||
}
|
||||
|
||||
if(!retval)
|
||||
m_pCatMgr->SetChanged();
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
long MozABHHManager::DeleteCategory(DWORD dwCategory, BOOL bMoveToUnfiled)
|
||||
{
|
||||
long retval=0;
|
||||
|
||||
if ((dwCategory < 0) || (dwCategory >= MAX_CATEGORIES))
|
||||
return CAT_ERR_INDEX_OUT_OF_RANGE;
|
||||
|
||||
BYTE sCategory = LOBYTE(LOWORD(dwCategory));
|
||||
|
||||
if (!bMoveToUnfiled)
|
||||
retval = SyncPurgeAllRecsInCategory(m_hhDB, sCategory);
|
||||
else
|
||||
retval = SyncChangeCategory(m_hhDB, sCategory, 0);
|
||||
return retval;
|
||||
}
|
||||
|
||||
long MozABHHManager::ChangeCategory(DWORD dwOldCatIndex, DWORD dwNewCatIndex)
|
||||
{
|
||||
long retval=0;
|
||||
|
||||
if ((dwOldCatIndex < 0) || (dwOldCatIndex >= MAX_CATEGORIES))
|
||||
return CAT_ERR_INDEX_OUT_OF_RANGE;
|
||||
|
||||
BYTE sCategory = LOBYTE(LOWORD(dwOldCatIndex));
|
||||
|
||||
if ((dwNewCatIndex < 0) || (dwNewCatIndex >= MAX_CATEGORIES))
|
||||
return CAT_ERR_INDEX_OUT_OF_RANGE;
|
||||
|
||||
BYTE sNewCategory = LOBYTE(LOWORD(dwNewCatIndex));
|
||||
|
||||
retval = SyncChangeCategory(m_hhDB, sCategory, sNewCategory);
|
||||
return retval;
|
||||
}
|
||||
|
||||
long MozABHHManager::CompactCategoriesToHH()
|
||||
{
|
||||
long retval = 0;
|
||||
|
||||
if ((!m_pCatMgr) || (!m_pCatMgr->IsChanged()))
|
||||
return 0;
|
||||
|
||||
retval = AllocateDBInfo(m_appInfo);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
DWORD dwRecSize;
|
||||
|
||||
dwRecSize = m_appInfo.m_TotalBytes;
|
||||
|
||||
retval = m_pCatMgr->Compact(m_appInfo.m_pBytes, &dwRecSize);
|
||||
if (!retval) {
|
||||
// more than just the categories may be stored in the app info structure
|
||||
// This code only replaces the category area.
|
||||
if (!m_appInfo.m_BytesRead)
|
||||
m_appInfo.m_BytesRead = LOWORD(dwRecSize);
|
||||
}
|
||||
|
||||
if(!retval)
|
||||
retval = SyncWriteDBAppInfoBlock(m_hhDB, m_appInfo);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
long MozABHHManager::OpenDB(BOOL bCreate)
|
||||
{
|
||||
long retval=0;
|
||||
|
||||
if (bCreate) {
|
||||
CDbCreateDB createInfo;
|
||||
|
||||
// Delete any existing DB with the same name
|
||||
SyncDeleteDB(m_szName, m_CardNum);
|
||||
|
||||
memset(&createInfo, 0, sizeof(CDbCreateDB));
|
||||
|
||||
createInfo.m_Creator = m_dwCreator;
|
||||
createInfo.m_Type = m_dwType;
|
||||
createInfo.m_Flags = (eDbFlags) m_wFlags;
|
||||
createInfo.m_CardNo = m_CardNum;
|
||||
strcpy(createInfo.m_Name, m_szName);
|
||||
createInfo.m_Version = m_wVersion;
|
||||
|
||||
if ((retval = SyncCreateDB(createInfo)) == SYNCERR_NONE)
|
||||
m_hhDB = createInfo.m_FileHandle;
|
||||
}
|
||||
else
|
||||
{
|
||||
retval = SyncOpenDB(m_szName,
|
||||
m_CardNum,
|
||||
m_hhDB,
|
||||
eDbRead | eDbWrite);
|
||||
if ((retval) && (retval == SYNCERR_NOT_FOUND))
|
||||
retval = GEN_ERR_NO_HH_DB;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
long MozABHHManager::CloseDB(BOOL bDontUpdate)
|
||||
{
|
||||
long retval = 0;
|
||||
long retval2 = 0;
|
||||
|
||||
if (m_hhDB == NULL)
|
||||
return GEN_ERR_DB_NOT_OPEN;
|
||||
|
||||
if (!bDontUpdate) {
|
||||
retval = SyncResetSyncFlags(m_hhDB);
|
||||
}
|
||||
retval2 = SyncCloseDB(m_hhDB);
|
||||
if (!retval)
|
||||
retval = retval2;
|
||||
m_hhDB = NULL;
|
||||
return retval;
|
||||
}
|
||||
|
||||
long MozABHHManager::LoadAllUpdatedRecords(CPalmRecord ***ppRecordList, DWORD * pListSize)
|
||||
{
|
||||
return LoadUpdatedRecords(0, ppRecordList, pListSize);
|
||||
}
|
||||
|
||||
long MozABHHManager::LoadUpdatedRecordsInCategory(DWORD catIndex, CPalmRecord ***ppRecordList, DWORD * pListSize)
|
||||
{
|
||||
return LoadUpdatedRecords(catIndex, ppRecordList, pListSize);
|
||||
}
|
||||
|
||||
// this function allocates the list as well as the records, caller should free list and delete records
|
||||
long MozABHHManager::LoadUpdatedRecords(DWORD catIndex, CPalmRecord ***ppRecordList, DWORD * pListSize)
|
||||
{
|
||||
long retval=0;
|
||||
WORD dwRecCount=0;
|
||||
|
||||
retval = SyncGetDBRecordCount(m_hhDB, dwRecCount);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
// resset the iteration index
|
||||
retval = SyncResetRecordIndex(m_hhDB);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
// allocate buffer initially for the total record size and adjust after getting records
|
||||
CPalmRecord ** palmRecordList = (CPalmRecord **) malloc(sizeof(CPalmRecord *) * dwRecCount);
|
||||
if (!palmRecordList)
|
||||
return GEN_ERR_LOW_MEMORY;
|
||||
memset(palmRecordList, 0, sizeof(CPalmRecord *) * dwRecCount);
|
||||
*ppRecordList = palmRecordList;
|
||||
|
||||
CPalmRecord *pPalmRec;
|
||||
*pListSize = 0;
|
||||
while ((!retval) && (*pListSize < dwRecCount)) {
|
||||
retval = AllocateRawRecord();
|
||||
if(retval)
|
||||
break;
|
||||
m_rInfo.m_RecIndex = 0;
|
||||
if(catIndex >= 0) {
|
||||
m_rInfo.m_CatId = catIndex;
|
||||
retval = SyncReadNextModifiedRecInCategory(m_rInfo);
|
||||
}
|
||||
else
|
||||
retval = SyncReadNextModifiedRec(m_rInfo);
|
||||
if (!retval) {
|
||||
pPalmRec = new CPalmRecord(m_rInfo);
|
||||
if (pPalmRec) {
|
||||
*palmRecordList = pPalmRec;
|
||||
palmRecordList++;
|
||||
(*pListSize)++;
|
||||
} else {
|
||||
retval = GEN_ERR_LOW_MEMORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// reallocate to the correct size
|
||||
if((*pListSize) != dwRecCount)
|
||||
*ppRecordList=(CPalmRecord **) realloc(*ppRecordList, sizeof(CPalmRecord *) * (*pListSize));
|
||||
|
||||
if (retval == SYNCERR_FILE_NOT_FOUND) // if there are no more records
|
||||
retval = 0;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
long MozABHHManager::AllocateRawRecord(void)
|
||||
{
|
||||
if (m_rInfo.m_pBytes != NULL) {
|
||||
BYTE *pBytes;
|
||||
|
||||
pBytes = m_rInfo.m_pBytes;
|
||||
memset(&m_rInfo, 0, sizeof(CRawRecordInfo));
|
||||
memset(pBytes, 0, MAX_RECORD_SIZE);
|
||||
|
||||
m_rInfo.m_pBytes = pBytes;
|
||||
m_rInfo.m_TotalBytes = MAX_RECORD_SIZE;
|
||||
m_rInfo.m_FileHandle = m_hhDB;
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(&m_rInfo, 0, sizeof(CRawRecordInfo));
|
||||
m_rInfo.m_pBytes = (BYTE *) new char[MAX_RECORD_SIZE];
|
||||
if (!m_rInfo.m_pBytes)
|
||||
return GEN_ERR_LOW_MEMORY;
|
||||
|
||||
memset(m_rInfo.m_pBytes, 0, MAX_RECORD_SIZE);
|
||||
m_rInfo.m_TotalBytes = MAX_RECORD_SIZE;
|
||||
m_rInfo.m_FileHandle = m_hhDB;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// this function allocates the list as well as the records, caller should free list and delete records
|
||||
long MozABHHManager::LoadAllRecords(CPalmRecord ***ppRecordList, DWORD * pListSize)
|
||||
{
|
||||
long retval=0;
|
||||
WORD dwRecCount, dwIndex;
|
||||
|
||||
retval = SyncGetDBRecordCount(m_hhDB, dwRecCount);
|
||||
if (!retval)
|
||||
return retval;
|
||||
*pListSize = dwRecCount;
|
||||
|
||||
*ppRecordList = (CPalmRecord **) malloc(sizeof(CPalmRecord *) * dwRecCount);
|
||||
if (!*ppRecordList)
|
||||
return GEN_ERR_LOW_MEMORY;
|
||||
memset(*ppRecordList, 0, sizeof(CPalmRecord *) * dwRecCount);
|
||||
|
||||
CPalmRecord *pPalmRec;
|
||||
for (dwIndex = 0; (dwIndex < dwRecCount) && (!retval); dwIndex++){
|
||||
retval = AllocateRawRecord();
|
||||
if(retval)
|
||||
break;
|
||||
|
||||
m_rInfo.m_RecIndex = LOWORD(dwIndex);
|
||||
|
||||
retval = SyncReadRecordByIndex(m_rInfo);
|
||||
if (!retval) {
|
||||
pPalmRec = new CPalmRecord(m_rInfo);
|
||||
if (pPalmRec) {
|
||||
*ppRecordList[dwIndex] = pPalmRec;
|
||||
} else {
|
||||
retval = GEN_ERR_LOW_MEMORY;
|
||||
}
|
||||
} else if (retval != SYNCERR_FILE_NOT_FOUND) {
|
||||
pPalmRec = new CPalmRecord(m_rInfo);
|
||||
pPalmRec->Initialize();
|
||||
pPalmRec->SetIndex(dwIndex);
|
||||
*ppRecordList[dwIndex] = pPalmRec;
|
||||
}
|
||||
}
|
||||
m_dwMaxRecordCount = dwIndex + 1;
|
||||
|
||||
if (retval == SYNCERR_FILE_NOT_FOUND) // if there are no more records
|
||||
retval = 0;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
// this function allocates the list as well as the records, caller should free list and delete records
|
||||
long MozABHHManager::LoadAllRecordsInCategory(DWORD catIndex, CPalmRecord ***ppRecordList, DWORD * pListSize)
|
||||
{
|
||||
long retval=0;
|
||||
WORD dwRecCount=0;
|
||||
|
||||
retval = SyncGetDBRecordCount(m_hhDB, dwRecCount);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
// resset the iteration index
|
||||
retval = SyncResetRecordIndex(m_hhDB);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
// allocate buffer initially for the total record size and adjust after getting records
|
||||
CPalmRecord ** palmRecordList = (CPalmRecord **) malloc(sizeof(CPalmRecord *) * dwRecCount);
|
||||
if (!palmRecordList)
|
||||
return GEN_ERR_LOW_MEMORY;
|
||||
memset(palmRecordList, 0, sizeof(CPalmRecord *) * dwRecCount);
|
||||
*ppRecordList = palmRecordList;
|
||||
|
||||
CPalmRecord *pPalmRec;
|
||||
|
||||
*pListSize = 0;
|
||||
while ((!retval) && (*pListSize < dwRecCount)) {
|
||||
retval = AllocateRawRecord();
|
||||
if (retval)
|
||||
break;
|
||||
m_rInfo.m_RecIndex = 0;
|
||||
m_rInfo.m_CatId = catIndex;
|
||||
retval = SyncReadNextRecInCategory(m_rInfo);
|
||||
if (!retval) {
|
||||
pPalmRec = new CPalmRecord(m_rInfo);
|
||||
if (pPalmRec) {
|
||||
*palmRecordList = pPalmRec;
|
||||
palmRecordList++;
|
||||
(*pListSize)++;
|
||||
} else {
|
||||
retval = GEN_ERR_LOW_MEMORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// reallocate to the correct size
|
||||
if((*pListSize) != dwRecCount)
|
||||
*ppRecordList=(CPalmRecord **) realloc(*ppRecordList, sizeof(CPalmRecord *) * (*pListSize));
|
||||
|
||||
if (retval == SYNCERR_FILE_NOT_FOUND) // if there are no more records
|
||||
retval = 0;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
long MozABHHManager::AddRecords(CPalmRecord **pRecordList, DWORD pCount)
|
||||
{
|
||||
long retval=0;
|
||||
|
||||
for (unsigned long i=0; i < pCount; i++)
|
||||
{
|
||||
CPalmRecord palmRec = *pRecordList[i];
|
||||
|
||||
palmRec.ResetAttribs();
|
||||
|
||||
retval = AllocateRawRecord();
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
retval = palmRec.ConvertToHH(m_rInfo);
|
||||
if (!retval) {
|
||||
m_rInfo.m_FileHandle = m_hhDB;
|
||||
m_rInfo.m_RecId = 0;
|
||||
if (m_bRecordDB)
|
||||
retval = SyncWriteRec(m_rInfo);
|
||||
else
|
||||
retval = SyncWriteResourceRec(m_rInfo);
|
||||
if (!retval) {
|
||||
palmRec.SetIndex(m_rInfo.m_RecIndex);
|
||||
palmRec.SetID(m_rInfo.m_RecId);
|
||||
}
|
||||
}
|
||||
else
|
||||
return retval;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
long MozABHHManager::UpdateRecords(CPalmRecord **pRecordList, DWORD pCount)
|
||||
{
|
||||
long retval=0;
|
||||
|
||||
for (unsigned long i=0; i < pCount; i++)
|
||||
{
|
||||
CPalmRecord palmRec = *pRecordList[i];
|
||||
|
||||
retval = AllocateRawRecord();
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
retval = palmRec.ConvertToHH(m_rInfo);
|
||||
if (!retval) {
|
||||
m_rInfo.m_FileHandle = m_hhDB;
|
||||
if (m_bRecordDB)
|
||||
retval = SyncWriteRec(m_rInfo);
|
||||
else
|
||||
retval = SyncWriteResourceRec(m_rInfo);
|
||||
if (!retval) {
|
||||
palmRec.SetIndex(m_rInfo.m_RecIndex);
|
||||
palmRec.SetID(m_rInfo.m_RecId);
|
||||
}
|
||||
}
|
||||
else
|
||||
return retval;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
long MozABHHManager::DeleteRecords(CPalmRecord **pRecordList, DWORD pCount)
|
||||
{
|
||||
long retval=0;
|
||||
|
||||
for (unsigned long i=0; i < pCount; i++)
|
||||
{
|
||||
CPalmRecord palmRec = *pRecordList[i];
|
||||
|
||||
retval = AllocateRawRecord();
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
retval = palmRec.ConvertToHH(m_rInfo);
|
||||
if (!retval) {
|
||||
m_rInfo.m_FileHandle = m_hhDB;
|
||||
if (m_bRecordDB)
|
||||
retval = SyncDeleteRec(m_rInfo);
|
||||
else
|
||||
retval = SyncDeleteResourceRec(m_rInfo);
|
||||
}
|
||||
else
|
||||
return retval;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
long MozABHHManager::AddARecord(CPalmRecord & palmRec)
|
||||
{
|
||||
long retval=0;
|
||||
|
||||
palmRec.ResetAttribs();
|
||||
|
||||
retval = AllocateRawRecord();
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
retval = palmRec.ConvertToHH(m_rInfo);
|
||||
if (!retval) {
|
||||
m_rInfo.m_FileHandle = m_hhDB;
|
||||
m_rInfo.m_RecId = 0;
|
||||
if (m_bRecordDB)
|
||||
retval = SyncWriteRec(m_rInfo);
|
||||
else
|
||||
retval = SyncWriteResourceRec(m_rInfo);
|
||||
if (!retval) {
|
||||
palmRec.SetIndex(m_rInfo.m_RecIndex);
|
||||
palmRec.SetID(m_rInfo.m_RecId);
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
long MozABHHManager::UpdateARecord(CPalmRecord & palmRec)
|
||||
{
|
||||
long retval=0;
|
||||
|
||||
retval = AllocateRawRecord();
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
retval = palmRec.ConvertToHH(m_rInfo);
|
||||
if (!retval) {
|
||||
m_rInfo.m_FileHandle = m_hhDB;
|
||||
m_rInfo.m_Attribs = eRecAttrDirty;
|
||||
if (m_bRecordDB)
|
||||
retval = SyncWriteRec(m_rInfo);
|
||||
else
|
||||
retval = SyncWriteResourceRec(m_rInfo);
|
||||
if (!retval) {
|
||||
palmRec.SetIndex(m_rInfo.m_RecIndex);
|
||||
palmRec.SetID(m_rInfo.m_RecId);
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
long MozABHHManager::DeleteARecord(CPalmRecord & palmRec)
|
||||
{
|
||||
long retval=0;
|
||||
|
||||
retval = AllocateRawRecord();
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
retval = palmRec.ConvertToHH(m_rInfo);
|
||||
if (!retval) {
|
||||
m_rInfo.m_FileHandle = m_hhDB;
|
||||
if (m_bRecordDB)
|
||||
retval = SyncDeleteRec(m_rInfo);
|
||||
else
|
||||
retval = SyncDeleteResourceRec(m_rInfo);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Rajiv Dayal <rdayal@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef _MOZAB_HHMANAGER_H_
|
||||
#define _MOZAB_HHMANAGERT_H_
|
||||
|
||||
#include <CPDbBMgr.h>
|
||||
|
||||
class MozABHHManager
|
||||
{
|
||||
public:
|
||||
MozABHHManager(DWORD dwGenericFlags,
|
||||
char *pName,
|
||||
DWORD dwCreator,
|
||||
DWORD dwType,
|
||||
WORD dbFlags,
|
||||
WORD dbVersion,
|
||||
int iCardNum,
|
||||
eSyncTypes syncType);
|
||||
~MozABHHManager();
|
||||
|
||||
long OpenDB(BOOL bCreate);
|
||||
long CloseDB(BOOL bDontUpdate);
|
||||
|
||||
// this will load categories in m_pCatMgr member
|
||||
long LoadCategories();
|
||||
CPCategory * GetFirstCategory() { return m_pCatMgr->FindFirst(); }
|
||||
CPCategory * GetNextCategory() { return m_pCatMgr->FindNext(); }
|
||||
long DeleteCategory(DWORD dwCategory, BOOL bMoveToUnfiled);
|
||||
long ChangeCategory(DWORD dwOldCatIndex, DWORD dwNewCatIndex);
|
||||
long AddCategory(CPCategory & cat);
|
||||
long CompactCategoriesToHH();
|
||||
|
||||
long LoadAllRecords(CPalmRecord ***ppRecordList, DWORD * pListSize);
|
||||
long LoadAllRecordsInCategory(DWORD catIndex, CPalmRecord ***ppRecordList, DWORD * pListSize);
|
||||
long LoadAllUpdatedRecords(CPalmRecord ***ppRecordList, DWORD * pListSize);
|
||||
long LoadUpdatedRecordsInCategory(DWORD catIndex, CPalmRecord ***ppRecordList, DWORD * pListSize);
|
||||
|
||||
long AddRecords(CPalmRecord **m_pRecordList, DWORD pCount);
|
||||
long DeleteRecords(CPalmRecord **m_pRecordList, DWORD pCount);
|
||||
long UpdateRecords(CPalmRecord **m_pRecordList, DWORD pCount);
|
||||
|
||||
long AddARecord(CPalmRecord & palmRec);
|
||||
long DeleteARecord(CPalmRecord & palmRec);
|
||||
long UpdateARecord(CPalmRecord & palmRec);
|
||||
|
||||
protected:
|
||||
char m_szName[SYNC_DB_NAMELEN];
|
||||
DWORD m_dwCreator;
|
||||
DWORD m_dwType;
|
||||
WORD m_wFlags;
|
||||
WORD m_wVersion;
|
||||
int m_CardNum;
|
||||
BOOL m_bRecordDB;
|
||||
|
||||
DWORD m_dwMaxRecordCount;
|
||||
|
||||
CRawRecordInfo m_rInfo;
|
||||
CPCategoryMgr * m_pCatMgr;
|
||||
|
||||
BYTE m_hhDB;
|
||||
CDbGenInfo m_appInfo;
|
||||
|
||||
long AllocateRawRecord();
|
||||
long AllocateDBInfo(CDbGenInfo &info, BOOL bClearData=FALSE);
|
||||
long GetInfoBlock(CDbGenInfo &info, BOOL bSortInfo=FALSE);
|
||||
long GetAppInfo(CDbGenInfo &rInfo);
|
||||
long SetName( char *pName);
|
||||
long LoadUpdatedRecords(DWORD catIndex, CPalmRecord ***ppRecordList, DWORD * pListSize);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,297 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Rajiv Dayal <rdayal@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <windows.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
#include <sys/stat.h>
|
||||
#include <TCHAR.H>
|
||||
|
||||
#include <syncmgr.h>
|
||||
#include <Pgenerr.h>
|
||||
|
||||
#include "MozABConduitRecord.h"
|
||||
#include "MozABPCManager.h"
|
||||
|
||||
const IID IID_IPalmSync = {0xC8CE6FC1,0xCCF1,0x11d6,{0xB8,0xA5,0x00,0x00,0x64,0x65,0x73,0x74}};
|
||||
const CLSID CLSID_CPalmSyncImp = { 0xb20b4521, 0xccf8, 0x11d6, { 0xb8, 0xa5, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } };
|
||||
|
||||
extern DWORD tId;
|
||||
|
||||
BOOL MozABPCManager::InitMozPalmSyncInstance(IPalmSync **aRetValue)
|
||||
{
|
||||
// Check wehther this thread has a valid Interface
|
||||
// by looking into thread-specific-data variable
|
||||
|
||||
*aRetValue = (IPalmSync *)TlsGetValue(tId);
|
||||
|
||||
// Check whether the pointer actually resolves to
|
||||
// a valid method call; otherwise mozilla is not running
|
||||
|
||||
if ((*aRetValue) && (*aRetValue)->IsValid() == S_OK)
|
||||
return TRUE;
|
||||
|
||||
HRESULT hRes = ::CoInitialize(NULL) ;
|
||||
|
||||
hRes = ::CoCreateInstance(CLSID_CPalmSyncImp, NULL, CLSCTX_LOCAL_SERVER,
|
||||
IID_IPalmSync, (LPVOID *)aRetValue);
|
||||
|
||||
if (hRes == S_OK)
|
||||
if (TlsSetValue(tId, (LPVOID)(*aRetValue)))
|
||||
return TRUE;
|
||||
|
||||
// Either CoCreate or TlsSetValue failed; so return FALSE
|
||||
|
||||
if ((*aRetValue))
|
||||
(*aRetValue)->Release();
|
||||
|
||||
::CoUninitialize();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// this function allocates the list as well as the strings, caller should free list and delete strings
|
||||
long MozABPCManager::GetPCABList(DWORD * pCategoryCount, DWORD ** pCategoryIdList, CPString *** pCategoryNameList, BOOL ** pIsFirstTimeSyncList)
|
||||
{
|
||||
lpnsMozABDesc mozABNameList=NULL;
|
||||
|
||||
short dwMozABCount=0;
|
||||
long retval = 0;
|
||||
IPalmSync *pNsPalmSync = NULL;
|
||||
|
||||
// get the interface
|
||||
if (!InitMozPalmSyncInstance(&pNsPalmSync))
|
||||
return GEN_ERR_NOT_SUPPORTED;
|
||||
|
||||
// get the ABList
|
||||
HRESULT hres = pNsPalmSync->nsGetABList(FALSE, &dwMozABCount,
|
||||
&mozABNameList, (long**) pCategoryIdList, pIsFirstTimeSyncList);
|
||||
if (hres != S_OK) {
|
||||
retval = (long) hres;
|
||||
return retval;
|
||||
}
|
||||
|
||||
*pCategoryCount = dwMozABCount;
|
||||
|
||||
CPString ** abNameList = (CPString **) malloc(sizeof(CPString *) * dwMozABCount);
|
||||
if (!abNameList) {
|
||||
free(mozABNameList);
|
||||
return GEN_ERR_LOW_MEMORY;
|
||||
}
|
||||
memset(abNameList, 0, sizeof(CPString *) * dwMozABCount);
|
||||
*pCategoryNameList = abNameList;
|
||||
|
||||
for (int i=0; i < dwMozABCount; i++) {
|
||||
CPString * pABName = new CPString((LPCTSTR) mozABNameList[i].lpszABDesc);
|
||||
if (pABName) {
|
||||
*abNameList = pABName;
|
||||
abNameList++;
|
||||
}
|
||||
else {
|
||||
return GEN_ERR_LOW_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
// free(mozABNameList); // we donot free this, allocated on another heap (COM), COM takes care of it.
|
||||
return retval;
|
||||
}
|
||||
|
||||
// this function allocates the mozlist as well as the mozRecs, caller should free list and delete recs
|
||||
long MozABPCManager::SynchronizePCAB(DWORD categoryId, CPString & categoryName,
|
||||
DWORD updatedPalmRecCount, CPalmRecord ** updatedPalmRecList,
|
||||
DWORD * pUpdatedPCRecListCount, CPalmRecord *** updatedPCRecList)
|
||||
{
|
||||
lpnsABCOMCardStruct mozCardList=NULL; // freed by MSCOM/Mozilla.
|
||||
int dwMozCardCount=0;
|
||||
long retval = 0;
|
||||
IPalmSync *pNsPalmSync = NULL;
|
||||
|
||||
// get the interface
|
||||
if (!InitMozPalmSyncInstance(&pNsPalmSync))
|
||||
return GEN_ERR_NOT_SUPPORTED;
|
||||
|
||||
CMozABConduitRecord ** tempMozABConduitRecList = new CMozABConduitRecord*[updatedPalmRecCount];
|
||||
nsABCOMCardStruct * palmCardList = new nsABCOMCardStruct[updatedPalmRecCount];
|
||||
if(palmCardList) {
|
||||
for(DWORD i=0; i<updatedPalmRecCount; i++) {
|
||||
if(*updatedPalmRecList) {
|
||||
CMozABConduitRecord * pConduitRecord = new CMozABConduitRecord(**updatedPalmRecList);
|
||||
memcpy(&palmCardList[i], &pConduitRecord->m_nsCard, sizeof(nsABCOMCardStruct));
|
||||
tempMozABConduitRecList[i]=pConduitRecord;
|
||||
}
|
||||
updatedPalmRecList++;
|
||||
}
|
||||
// synchronize and get the updated cards in MozAB
|
||||
HRESULT hres = pNsPalmSync->nsSynchronizeAB(FALSE, categoryId, categoryName.GetBuffer(0),
|
||||
updatedPalmRecCount, palmCardList,
|
||||
&dwMozCardCount, &mozCardList);
|
||||
if(hres == S_OK) {
|
||||
*pUpdatedPCRecListCount = dwMozCardCount;
|
||||
CPalmRecord ** mozRecordList = (CPalmRecord **) malloc(sizeof(CPalmRecord *) * dwMozCardCount);
|
||||
*updatedPCRecList = mozRecordList;
|
||||
if (mozRecordList) {
|
||||
memset(mozRecordList, 0, sizeof(CPalmRecord *) * dwMozCardCount);
|
||||
int i=0;
|
||||
for (i=0; i < dwMozCardCount; i++) {
|
||||
CMozABConduitRecord * pConduitRecord = new CMozABConduitRecord(mozCardList[i]);
|
||||
CPalmRecord * pMozRecord = new CPalmRecord;
|
||||
pConduitRecord->ConvertToGeneric(*pMozRecord);
|
||||
*mozRecordList = pMozRecord;
|
||||
mozRecordList++;
|
||||
delete pConduitRecord;
|
||||
}
|
||||
}
|
||||
else
|
||||
retval = GEN_ERR_LOW_MEMORY;
|
||||
}
|
||||
else
|
||||
retval = (long) hres;
|
||||
}
|
||||
else
|
||||
retval = GEN_ERR_LOW_MEMORY;
|
||||
|
||||
|
||||
if(palmCardList)
|
||||
delete palmCardList;
|
||||
if(tempMozABConduitRecList) {
|
||||
for(DWORD j=0; j<updatedPalmRecCount; j++)
|
||||
delete tempMozABConduitRecList[j];
|
||||
delete tempMozABConduitRecList;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
// this will add all records in a Palm category into a new Mozilla AB
|
||||
long MozABPCManager::AddRecords(DWORD categoryId, CPString & categoryName,
|
||||
DWORD updatedPalmRecCount, CPalmRecord ** updatedPalmRecList)
|
||||
{
|
||||
long retval = 0;
|
||||
IPalmSync *pNsPalmSync = NULL;
|
||||
|
||||
// get the interface
|
||||
if (!InitMozPalmSyncInstance(&pNsPalmSync))
|
||||
return GEN_ERR_NOT_SUPPORTED;
|
||||
|
||||
CMozABConduitRecord ** tempMozABConduitRecList = new CMozABConduitRecord*[updatedPalmRecCount];
|
||||
nsABCOMCardStruct * palmCardList = new nsABCOMCardStruct[updatedPalmRecCount];
|
||||
if(palmCardList) {
|
||||
for(DWORD i=0; i<updatedPalmRecCount; i++) {
|
||||
if(*updatedPalmRecList) {
|
||||
CMozABConduitRecord * pConduitRecord = new CMozABConduitRecord(**updatedPalmRecList);
|
||||
memcpy(&palmCardList[i], &pConduitRecord->m_nsCard, sizeof(nsABCOMCardStruct));
|
||||
tempMozABConduitRecList[i]=pConduitRecord;
|
||||
}
|
||||
updatedPalmRecList++;
|
||||
}
|
||||
// get the ABList
|
||||
HRESULT hres = pNsPalmSync->nsAddAllABRecords(FALSE, categoryId, categoryName.GetBuffer(0),
|
||||
updatedPalmRecCount, palmCardList);
|
||||
if (hres != S_OK)
|
||||
retval = (long) hres;
|
||||
}
|
||||
else
|
||||
retval = GEN_ERR_LOW_MEMORY;
|
||||
|
||||
if(palmCardList)
|
||||
delete palmCardList;
|
||||
if(tempMozABConduitRecList) {
|
||||
for(DWORD i=0; i<updatedPalmRecCount; i++)
|
||||
delete tempMozABConduitRecList[i];
|
||||
delete tempMozABConduitRecList;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
// this load all records in an Moz AB
|
||||
// this function allocates the mozlist as well as the mozRecs, caller should free list and delete recs
|
||||
long MozABPCManager::LoadAllRecords(CPString & ABName, DWORD * pPCRecListCount, CPalmRecord *** pPCRecList)
|
||||
{
|
||||
lpnsABCOMCardStruct mozCardList=NULL; // freed by MSCOM/Mozilla.
|
||||
int dwMozCardCount=0;
|
||||
long retval = 0;
|
||||
IPalmSync *pNsPalmSync = NULL;
|
||||
|
||||
// get the interface
|
||||
if (!InitMozPalmSyncInstance(&pNsPalmSync))
|
||||
return GEN_ERR_NOT_SUPPORTED;
|
||||
|
||||
// get the ABList
|
||||
HRESULT hres = pNsPalmSync->nsGetAllABCards(FALSE, -1, ABName.GetBuffer(0),
|
||||
&dwMozCardCount, &mozCardList);
|
||||
if (hres == S_OK) {
|
||||
*pPCRecListCount = dwMozCardCount;
|
||||
CPalmRecord ** mozRecordList = (CPalmRecord **) malloc(sizeof(CPalmRecord *) * dwMozCardCount);
|
||||
*pPCRecList = mozRecordList;
|
||||
if (mozRecordList) {
|
||||
memset(mozRecordList, 0, sizeof(CPalmRecord *) * dwMozCardCount);
|
||||
for (int i=0; i < dwMozCardCount; i++) {
|
||||
CMozABConduitRecord * pConduitRecord = new CMozABConduitRecord(mozCardList[i]);
|
||||
CPalmRecord * pMozRecord = new CPalmRecord;
|
||||
pConduitRecord->ConvertToGeneric(*pMozRecord);
|
||||
*mozRecordList = pMozRecord;
|
||||
mozRecordList++;
|
||||
delete pConduitRecord;
|
||||
}
|
||||
}
|
||||
else
|
||||
retval = GEN_ERR_LOW_MEMORY;
|
||||
}
|
||||
else
|
||||
retval = (long) hres;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
long MozABPCManager::NotifySyncDone(BOOL success, DWORD catID, DWORD newRecCount, DWORD * newRecIDList)
|
||||
{
|
||||
IPalmSync *pNsPalmSync = NULL;
|
||||
// get the interface
|
||||
if (!InitMozPalmSyncInstance(&pNsPalmSync))
|
||||
return GEN_ERR_NOT_SUPPORTED;
|
||||
|
||||
// MS COM Proxy stub Dll will not accept NULL for this address
|
||||
if(!newRecIDList)
|
||||
newRecIDList = &catID;
|
||||
|
||||
HRESULT hres = pNsPalmSync->nsAckSyncDone(success, catID, newRecCount, newRecIDList);
|
||||
long retval = (long) hres;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Rajiv Dayal <rdayal@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef _MOZAB_PCMANAGER_H_
|
||||
#define _MOZAB_PCMANAGER_H_
|
||||
|
||||
#include <CPString.h>
|
||||
#include <CPDbBMgr.h>
|
||||
|
||||
#include "IPalmSync.h"
|
||||
|
||||
class MozABPCManager
|
||||
{
|
||||
public:
|
||||
MozABPCManager() { }
|
||||
~MozABPCManager() { }
|
||||
|
||||
// this will return the list of ABs in Mozilla and if they were synced before
|
||||
long GetPCABList(DWORD * pCategoryCount, DWORD ** pCategoryIdList,
|
||||
CPString *** pCategoryNameList, BOOL ** pIsFirstTimeSyncList);
|
||||
// this will update a Mozilla AB with updated Palm records and
|
||||
// return updated records in a Mozilla AB after the last sync
|
||||
// this will take care of first time sync also in which case
|
||||
// updatedPalmRecList is the list of all palm records and
|
||||
// updatedPCRecList is the list of unique Moz AB cards / records.
|
||||
long SynchronizePCAB(DWORD categoryId, CPString & categoryName,
|
||||
DWORD updatedPalmRecCount, CPalmRecord ** updatedPalmRecList,
|
||||
DWORD * pUpdatedPCRecList, CPalmRecord *** updatedPCRecList);
|
||||
// this will add all records in a Palm category into a new Mozilla AB
|
||||
long AddRecords(DWORD categoryId, CPString & categoryName,
|
||||
DWORD updatedPalmRecCount, CPalmRecord ** updatedPalmRecList);
|
||||
// this load all records in an Moz AB
|
||||
long LoadAllRecords(CPString & ABName, DWORD * pPCRecListCount, CPalmRecord *** pPCRecList);
|
||||
|
||||
long NotifySyncDone(BOOL success, DWORD catID=-1, DWORD newRecCount=0, DWORD * newRecIDList=NULL);
|
||||
|
||||
private:
|
||||
// this will initiate the communication with Mozilla
|
||||
BOOL InitMozPalmSyncInstance(IPalmSync **aRetValue);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Загрузка…
Ссылка в новой задаче