Back to index

lightning-sunbird  0.9+nobinonly
MozABHHManager.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is mozilla.org code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation
00018  *
00019  * Portions created by the Initial Developer are Copyright (C) 2002
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *       Rajiv Dayal <rdayal@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include <windows.h>
00040 #include <string.h>
00041 #include <stdio.h>
00042 #include <memory.h>
00043 #include <sys/stat.h>
00044 #include <TCHAR.H>
00045 #include <malloc.h>
00046 #include <syncmgr.h>
00047 #include <Pgenerr.h>
00048 
00049 #include "MozABHHManager.h"
00050 
00051 MozABHHManager::MozABHHManager(DWORD dwGenericFlags, 
00052                char *pName, 
00053                DWORD dwCreator, 
00054                DWORD dwType, 
00055                WORD dbFlags, 
00056                WORD dbVersion, 
00057                         int  iCardNum,
00058                eSyncTypes syncType)
00059 {
00060     m_hhDB = 0;
00061     
00062     m_rInfo.m_pBytes = NULL;
00063     m_rInfo.m_TotalBytes = 0;
00064 
00065     m_dwMaxRecordCount = 0;
00066     m_pCatMgr = NULL;
00067     // since we are dealing with AB which is a Record DB in Palm
00068     m_bRecordDB = TRUE;
00069 
00070     m_szName[0] = '\0';
00071     SetName( pName);
00072     m_dwCreator = dwCreator;
00073     m_dwType    = dwType;
00074     m_wFlags    = dbFlags;
00075     m_wVersion  = dbVersion;
00076     m_CardNum = iCardNum;
00077 
00078     memset(&m_appInfo, 0, sizeof(CDbGenInfo));
00079 }
00080 
00081 MozABHHManager::~MozABHHManager()
00082 {
00083     if (m_rInfo.m_pBytes != NULL) {
00084         delete m_rInfo.m_pBytes;
00085     }
00086     m_rInfo.m_pBytes = NULL;
00087     m_rInfo.m_TotalBytes = 0;
00088 
00089     if (m_appInfo.m_pBytes) {
00090         delete m_appInfo.m_pBytes;
00091         m_appInfo.m_pBytes = NULL;
00092     }
00093 
00094     if (m_pCatMgr) {
00095         delete m_pCatMgr;
00096         m_pCatMgr = NULL;
00097     }
00098 
00099     CloseDB(TRUE);
00100 }
00101 
00102 
00103 long MozABHHManager::AllocateDBInfo(CDbGenInfo &info, BOOL bClearData)
00104 {
00105     BOOL bNew = FALSE;
00106 
00107     if (!info.m_pBytes) {
00108         info.m_pBytes = (BYTE *) new char[MAX_RECORD_SIZE];  // deleted in d'ctor or by caller
00109         if (!info.m_pBytes)
00110             return GEN_ERR_LOW_MEMORY;
00111         info.m_TotalBytes = MAX_RECORD_SIZE;
00112         bNew = TRUE;
00113     } 
00114 
00115     if ((bClearData) || (bNew)) {
00116         memset(info.m_pBytes, 0, info.m_TotalBytes);
00117     }
00118     return 0;
00119 }
00120 
00121 long MozABHHManager::GetInfoBlock(CDbGenInfo &info, BOOL bSortInfo)
00122 {
00123     long  retval=0;
00124 
00125     // Allocate storage for app/sort info blocks
00126     retval = AllocateDBInfo(info);
00127     if (retval)
00128         return retval;
00129 
00130     _tcsncpy((char*)info.m_FileName, m_szName, sizeof(info.m_FileName)-1);
00131     info.m_FileName[sizeof(info.m_FileName)-1] = '\0';
00132     memset(info.m_pBytes, 0, info.m_TotalBytes);
00133 
00134     if (!bSortInfo) {
00135         // Read the AppInfo block
00136         retval = SyncReadDBAppInfoBlock(m_hhDB, info);
00137     } else {
00138         // Read the SortInfo block
00139         retval = SyncReadDBSortInfoBlock(m_hhDB, info);
00140     }
00141     if (retval) {// if error then clean up
00142         delete info.m_pBytes;
00143         info.m_pBytes = NULL;
00144         info.m_TotalBytes = 0;
00145     }
00146 
00147     return retval;
00148 }
00149 
00150 
00151 long MozABHHManager::GetAppInfo(CDbGenInfo &rInfo)
00152 {
00153     long retval = 0;
00154     BYTE *pBuffer;
00155 
00156     pBuffer = rInfo.m_pBytes; 
00157     WORD wTotalBytes = rInfo.m_TotalBytes;
00158     memset(&rInfo, 0, sizeof(CDbGenInfo));
00159     if ((wTotalBytes > 0) && (pBuffer)) {
00160         memset(pBuffer, 0, wTotalBytes);
00161         rInfo.m_pBytes       = pBuffer; 
00162         rInfo.m_TotalBytes   = wTotalBytes;
00163     }
00164 
00165     retval = GetInfoBlock(rInfo);
00166 
00167     if (retval) { // if error cleanup
00168         if (rInfo.m_pBytes) {
00169             delete rInfo.m_pBytes;
00170             rInfo.m_pBytes = NULL;
00171             rInfo.m_TotalBytes   = 0;
00172         }
00173     }
00174 
00175     return retval;
00176 }
00177 
00178 long MozABHHManager::SetName( char *pName)
00179 {
00180     if (m_hhDB)
00181         return GEN_ERR_DB_ALREADY_OPEN;
00182 
00183     WORD wLen;
00184     if (!pName){
00185         *m_szName = '\0';
00186         return 0;
00187     } 
00188     wLen = (WORD)strlen(pName);
00189     if (!wLen) {
00190         *m_szName = '\0';
00191         return 0;
00192     }
00193     if (wLen >= sizeof(m_szName))
00194         return GEN_ERR_DATA_TOO_LARGE;
00195 
00196     strncpy(m_szName, pName, sizeof(m_szName)-1);
00197     m_szName[sizeof(m_szName)-1] = '\0';
00198     return 0;
00199 }
00200 
00201 long MozABHHManager::LoadCategories(void)
00202 {
00203     long retval=0;
00204 
00205     if (m_pCatMgr) {  // remove existing manager
00206         delete m_pCatMgr;
00207         m_pCatMgr = NULL;
00208     }
00209 
00210     if (m_appInfo.m_BytesRead == 0){
00211         retval = GetAppInfo(m_appInfo);
00212         if (retval)
00213             return retval;
00214     }
00215 
00216     if ((m_appInfo.m_BytesRead > 0) && (m_appInfo.m_pBytes)){
00217         m_pCatMgr = new CPCategoryMgr(m_appInfo.m_pBytes, m_appInfo.m_BytesRead); // deleted in d'ctor
00218         if (!m_pCatMgr)
00219             return GEN_ERR_LOW_MEMORY;
00220     } else {
00221         retval = GEN_ERR_NO_CATEGORIES;
00222     }
00223     return retval;
00224 }
00225 
00226 long MozABHHManager::AddCategory(CPCategory & cat)
00227 {
00228     long retval=0;
00229 
00230     if(!m_pCatMgr)
00231         retval = LoadCategories();
00232 
00233     // generate a new ID and Add the category
00234     if(!retval) {
00235         for(int id=0; id<=MAX_CATEGORIES; id++)
00236             if(!m_pCatMgr->FindID(id))
00237                 break;
00238         // if ID doesnot already exist
00239         if(id<MAX_CATEGORIES) {
00240             cat.SetID(MAKELONG(id, 0));
00241             retval = m_pCatMgr->Add(cat);
00242         }
00243         else
00244             retval = CAT_NO_ID;
00245     }
00246 
00247     if(!retval)
00248         m_pCatMgr->SetChanged();
00249 
00250     return retval;    
00251 }
00252 
00253 long MozABHHManager::DeleteCategory(DWORD dwCategory, BOOL bMoveToUnfiled)
00254 {
00255     long retval=0;
00256 
00257     if ((dwCategory < 0) || (dwCategory >= MAX_CATEGORIES))
00258         return CAT_ERR_INDEX_OUT_OF_RANGE;
00259 
00260     BYTE sCategory = LOBYTE(LOWORD(dwCategory));
00261 
00262     if (!bMoveToUnfiled)
00263     {
00264         retval = SyncPurgeAllRecsInCategory(m_hhDB, sCategory);
00265         m_pCatMgr->DeleteByIndex(dwCategory); // delete category itself
00266     }
00267     else 
00268         retval = SyncChangeCategory(m_hhDB, sCategory, 0);
00269     return retval;
00270 }
00271 
00272 long MozABHHManager::ChangeCategory(DWORD dwOldCatIndex, DWORD dwNewCatIndex)
00273 {
00274     long retval=0;
00275 
00276     if ((dwOldCatIndex < 0) || (dwOldCatIndex >= MAX_CATEGORIES))
00277         return CAT_ERR_INDEX_OUT_OF_RANGE;
00278 
00279     BYTE sCategory = LOBYTE(LOWORD(dwOldCatIndex));
00280 
00281     if ((dwNewCatIndex < 0) || (dwNewCatIndex >= MAX_CATEGORIES))
00282         return CAT_ERR_INDEX_OUT_OF_RANGE;
00283 
00284     BYTE sNewCategory = LOBYTE(LOWORD(dwNewCatIndex));
00285 
00286     retval = SyncChangeCategory(m_hhDB, sCategory, sNewCategory);
00287     return retval;
00288 }
00289 
00290 long MozABHHManager::CompactCategoriesToHH()
00291 {
00292     long retval = 0;
00293 
00294     if ((!m_pCatMgr) || (!m_pCatMgr->IsChanged()))
00295         return 0;
00296 
00297     retval = AllocateDBInfo(m_appInfo);
00298     if (retval)
00299         return retval;
00300 
00301     DWORD dwRecSize;
00302 
00303     dwRecSize = m_appInfo.m_TotalBytes;
00304 
00305     retval = m_pCatMgr->Compact(m_appInfo.m_pBytes, &dwRecSize);
00306     if (!retval) {
00307         // more than just the categories may be stored in the app info structure
00308         // This code only replaces the category area.
00309         if (!m_appInfo.m_BytesRead)
00310             m_appInfo.m_BytesRead = LOWORD(dwRecSize);
00311     }
00312 
00313     if(!retval)
00314         retval = SyncWriteDBAppInfoBlock(m_hhDB, m_appInfo);
00315 
00316     return retval;
00317 }
00318 
00319 long MozABHHManager::OpenDB(BOOL bCreate)
00320 {
00321     long retval=0;
00322 
00323     if (bCreate) {
00324        CDbCreateDB  createInfo;
00325 
00326         // Delete any existing DB with the same name
00327         SyncDeleteDB(m_szName, m_CardNum);
00328 
00329         memset(&createInfo, 0, sizeof(CDbCreateDB));
00330 
00331         createInfo.m_Creator     = m_dwCreator; 
00332         createInfo.m_Type        = m_dwType; 
00333         createInfo.m_Flags       = (eDbFlags) m_wFlags;
00334         createInfo.m_CardNo     = m_CardNum;  
00335         strncpy(createInfo.m_Name, m_szName, sizeof(createInfo.m_Name)-1);
00336         createInfo.m_Name[sizeof(createInfo.m_Name)-1] = '\0';
00337         createInfo.m_Version    = m_wVersion;
00338 
00339         if ((retval = SyncCreateDB(createInfo)) == SYNCERR_NONE)
00340             m_hhDB = createInfo.m_FileHandle;
00341     }
00342     else 
00343     {
00344         retval = SyncOpenDB(m_szName, 
00345                             m_CardNum, 
00346                             m_hhDB,
00347                             eDbRead | eDbWrite);
00348         if ((retval) && (retval == SYNCERR_NOT_FOUND))
00349             retval = GEN_ERR_NO_HH_DB;
00350     } 
00351 
00352     return retval;
00353 }
00354 
00355 long MozABHHManager::CloseDB(BOOL bDontUpdate)
00356 {
00357     long retval = 0;
00358     long retval2 = 0;
00359 
00360     if (m_hhDB == NULL) 
00361         return GEN_ERR_DB_NOT_OPEN;
00362 
00363     if (!bDontUpdate) {
00364         retval = SyncResetSyncFlags(m_hhDB);
00365     }
00366     retval2 = SyncCloseDB(m_hhDB);
00367     if (!retval)
00368         retval = retval2;
00369     m_hhDB = NULL;
00370     return retval;
00371 }
00372 
00373 long MozABHHManager::LoadAllUpdatedRecords(CPalmRecord ***ppRecordList, DWORD * pListSize)
00374 {
00375     return LoadUpdatedRecords(0, ppRecordList, pListSize);
00376 }
00377 
00378 long MozABHHManager::LoadUpdatedRecordsInCategory(DWORD catIndex, CPalmRecord ***ppRecordList, DWORD * pListSize)
00379 {
00380     return LoadUpdatedRecords(catIndex, ppRecordList, pListSize);
00381 }
00382 
00383 // this function allocates the list as well as the records, caller should free list and delete records
00384 long MozABHHManager::LoadUpdatedRecords(DWORD catIndex, CPalmRecord ***ppRecordList, DWORD * pListSize)
00385 {
00386     long retval=0;
00387     WORD dwRecCount=0;
00388 
00389     retval = SyncGetDBRecordCount(m_hhDB, dwRecCount);
00390     if (retval)
00391         return retval;
00392 
00393     // resset the iteration index
00394     retval = SyncResetRecordIndex(m_hhDB);
00395     if (retval)
00396         return retval;
00397 
00398     // allocate buffer initially for the total record size and adjust after getting records
00399     CPalmRecord ** palmRecordList = (CPalmRecord **) malloc(sizeof(CPalmRecord *) * dwRecCount);
00400     if (!palmRecordList)
00401         return GEN_ERR_LOW_MEMORY;
00402     memset(palmRecordList, 0, sizeof(CPalmRecord *) * dwRecCount);
00403     *ppRecordList = palmRecordList;
00404 
00405     // SyncReadNextModifiedRecInCategory() does not seem to be returning
00406     // deleted palm records, so SyncReadNextModifiedRec() is used instead.
00407     CPalmRecord *pPalmRec;
00408     *pListSize = 0;
00409     while ((!retval) && (*pListSize < dwRecCount))  {
00410         retval = AllocateRawRecord();
00411         if(retval)
00412             break;
00413         m_rInfo.m_RecIndex = 0;
00414         retval = SyncReadNextModifiedRec(m_rInfo);
00415         // Does it belong to the category we care about?
00416         if (!retval && m_rInfo.m_CatId == catIndex)
00417         {
00418             pPalmRec = new CPalmRecord(m_rInfo);
00419             if (pPalmRec) {
00420                 *palmRecordList = pPalmRec;
00421                 palmRecordList++;
00422                 (*pListSize)++;
00423             } else {
00424                 retval = GEN_ERR_LOW_MEMORY;
00425             }
00426         } 
00427     }
00428 
00429     // reallocate to the correct size
00430     if((*pListSize) != dwRecCount)
00431         *ppRecordList=(CPalmRecord **) realloc(*ppRecordList, sizeof(CPalmRecord *) * (*pListSize));
00432 
00433     if (retval == SYNCERR_FILE_NOT_FOUND) // if there are no more records
00434         retval = 0;
00435 
00436     return retval;
00437 }
00438 
00439 long MozABHHManager::AllocateRawRecord(void)
00440 {
00441     if (m_rInfo.m_pBytes != NULL) {
00442         BYTE *pBytes;
00443 
00444         pBytes = m_rInfo.m_pBytes;
00445         memset(&m_rInfo, 0, sizeof(CRawRecordInfo));
00446         memset(pBytes, 0, MAX_RECORD_SIZE);
00447 
00448         m_rInfo.m_pBytes        = pBytes;
00449         m_rInfo.m_TotalBytes    = MAX_RECORD_SIZE;
00450         m_rInfo.m_FileHandle    = m_hhDB;
00451         return 0;
00452     }
00453     
00454     memset(&m_rInfo, 0, sizeof(CRawRecordInfo));
00455     m_rInfo.m_pBytes        = (BYTE *) new char[MAX_RECORD_SIZE];
00456     if (!m_rInfo.m_pBytes)
00457         return GEN_ERR_LOW_MEMORY;
00458 
00459     memset(m_rInfo.m_pBytes, 0, MAX_RECORD_SIZE);
00460     m_rInfo.m_TotalBytes    = MAX_RECORD_SIZE;
00461     m_rInfo.m_FileHandle    = m_hhDB;
00462     return 0;
00463 }
00464 
00465 // this function allocates the list as well as the records, caller should free list and delete records
00466 long MozABHHManager::LoadAllRecords(CPalmRecord ***ppRecordList, DWORD * pListSize)
00467 {
00468     long retval=0;
00469     WORD dwRecCount, dwIndex;
00470 
00471     retval = SyncGetDBRecordCount(m_hhDB, dwRecCount);
00472     if (!retval)
00473         return retval;
00474     *pListSize = dwRecCount;
00475 
00476     *ppRecordList = (CPalmRecord **) malloc(sizeof(CPalmRecord *) * dwRecCount);
00477     if (!*ppRecordList)
00478         return GEN_ERR_LOW_MEMORY;
00479     memset(*ppRecordList, 0, sizeof(CPalmRecord *) * dwRecCount);
00480 
00481     CPalmRecord *pPalmRec;
00482     for (dwIndex = 0; (dwIndex < dwRecCount) && (!retval); dwIndex++){
00483         retval = AllocateRawRecord();
00484         if(retval)
00485             break;
00486 
00487         m_rInfo.m_RecIndex = LOWORD(dwIndex);
00488 
00489         retval = SyncReadRecordByIndex(m_rInfo);
00490         if (!retval) {
00491             pPalmRec = new CPalmRecord(m_rInfo);
00492             if (pPalmRec) {
00493                 *ppRecordList[dwIndex] = pPalmRec;
00494             } else {
00495                 retval = GEN_ERR_LOW_MEMORY;
00496             }
00497         } else if (retval != SYNCERR_FILE_NOT_FOUND) {
00498             pPalmRec = new CPalmRecord(m_rInfo);
00499             pPalmRec->Initialize();
00500             pPalmRec->SetIndex(dwIndex);
00501             *ppRecordList[dwIndex] = pPalmRec;
00502         }
00503     }
00504     m_dwMaxRecordCount = dwIndex + 1;
00505 
00506     if (retval == SYNCERR_FILE_NOT_FOUND) // if there are no more records
00507         retval = 0;
00508 
00509     return retval;
00510 }
00511 
00512 // this function allocates the list as well as the records, caller should free list and delete records
00513 long MozABHHManager::LoadAllRecordsInCategory(DWORD catIndex, CPalmRecord ***ppRecordList, DWORD * pListSize)
00514 {
00515     long retval=0;
00516     WORD dwRecCount=0;
00517 
00518     retval = SyncGetDBRecordCount(m_hhDB, dwRecCount);
00519     if (retval)
00520         return retval;
00521 
00522     // resset the iteration index
00523     retval = SyncResetRecordIndex(m_hhDB);
00524     if (retval)
00525         return retval;
00526 
00527     // allocate buffer initially for the total record size and adjust after getting records
00528     CPalmRecord ** palmRecordList = (CPalmRecord **) malloc(sizeof(CPalmRecord *) * dwRecCount);
00529     if (!palmRecordList)
00530         return GEN_ERR_LOW_MEMORY;
00531     memset(palmRecordList, 0, sizeof(CPalmRecord *) * dwRecCount);
00532     *ppRecordList = palmRecordList;
00533 
00534     CPalmRecord *pPalmRec;
00535 
00536     *pListSize = 0;
00537     while ((!retval) && (*pListSize < dwRecCount))  {
00538         retval = AllocateRawRecord();
00539         if (retval) 
00540             break;
00541         m_rInfo.m_RecIndex = 0;
00542         m_rInfo.m_CatId = catIndex;
00543         retval = SyncReadNextRecInCategory(m_rInfo);
00544         if (!retval) {
00545             pPalmRec = new CPalmRecord(m_rInfo);
00546             if (pPalmRec) {
00547                 *palmRecordList = pPalmRec;
00548                 palmRecordList++;
00549                 (*pListSize)++;
00550             } else {
00551                 retval = GEN_ERR_LOW_MEMORY;
00552             }
00553         } 
00554     }
00555 
00556     // reallocate to the correct size
00557     if((*pListSize) != dwRecCount)
00558         *ppRecordList=(CPalmRecord **) realloc(*ppRecordList, sizeof(CPalmRecord *) * (*pListSize));
00559 
00560     if (retval == SYNCERR_FILE_NOT_FOUND) // if there are no more records
00561         retval = 0;
00562 
00563     return retval;
00564 }
00565 
00566 long MozABHHManager::AddRecords(CPalmRecord **pRecordList, DWORD pCount)
00567 {
00568     long retval=0;
00569 
00570     for (unsigned long i=0; i < pCount; i++)
00571     {
00572         CPalmRecord palmRec = *pRecordList[i];
00573 
00574         palmRec.ResetAttribs();
00575 
00576         retval = AllocateRawRecord();
00577         if (retval) 
00578             return retval;
00579 
00580         retval = palmRec.ConvertToHH(m_rInfo);
00581         if (!retval) {
00582             m_rInfo.m_FileHandle = m_hhDB;
00583             m_rInfo.m_RecId = 0;
00584             if (m_bRecordDB)
00585                 retval = SyncWriteRec(m_rInfo);
00586             else 
00587                 retval = SyncWriteResourceRec(m_rInfo);
00588             if (!retval) {
00589                 palmRec.SetIndex(m_rInfo.m_RecIndex);
00590                 palmRec.SetID(m_rInfo.m_RecId);
00591             }
00592         }
00593         else
00594             return retval;
00595     }
00596 
00597     return retval;
00598 }
00599 
00600 long MozABHHManager::UpdateRecords(CPalmRecord **pRecordList, DWORD pCount)
00601 {
00602     long retval=0;
00603 
00604     for (unsigned long i=0; i < pCount; i++)
00605     {
00606         CPalmRecord palmRec = *pRecordList[i];
00607 
00608         retval = AllocateRawRecord();
00609         if (retval) 
00610             return retval;
00611 
00612         retval = palmRec.ConvertToHH(m_rInfo);
00613         if (!retval) {
00614             m_rInfo.m_FileHandle = m_hhDB;
00615             if (m_bRecordDB)
00616                 retval = SyncWriteRec(m_rInfo);
00617             else 
00618                 retval = SyncWriteResourceRec(m_rInfo);
00619             if (!retval) {
00620                 palmRec.SetIndex(m_rInfo.m_RecIndex);
00621                 palmRec.SetID(m_rInfo.m_RecId);
00622             }
00623         }
00624         else
00625             return retval;
00626     }
00627 
00628     return retval;
00629 }
00630 
00631 long MozABHHManager::DeleteRecords(CPalmRecord **pRecordList, DWORD pCount)
00632 {
00633     long retval=0;
00634 
00635     for (unsigned long i=0; i < pCount; i++)
00636     {
00637         CPalmRecord palmRec = *pRecordList[i];
00638 
00639         retval = AllocateRawRecord();
00640         if (retval) 
00641             return retval;
00642 
00643         retval = palmRec.ConvertToHH(m_rInfo);
00644         if (!retval) {
00645             m_rInfo.m_FileHandle = m_hhDB;
00646             if (m_bRecordDB)
00647                 retval = SyncDeleteRec(m_rInfo);
00648             else 
00649                 retval = SyncDeleteResourceRec(m_rInfo);
00650         }
00651         else
00652             return retval;
00653     }
00654 
00655     return retval;
00656 }
00657 
00658 
00659 long MozABHHManager::AddARecord(CPalmRecord & palmRec)
00660 {
00661     long retval=0;
00662 
00663     palmRec.ResetAttribs();
00664 
00665     retval = AllocateRawRecord();
00666     if (retval) 
00667         return retval;
00668 
00669     retval = palmRec.ConvertToHH(m_rInfo);
00670     if (!retval) {
00671         m_rInfo.m_FileHandle = m_hhDB;
00672         m_rInfo.m_RecId = 0;
00673         if (m_bRecordDB)
00674             retval = SyncWriteRec(m_rInfo);
00675         else 
00676             retval = SyncWriteResourceRec(m_rInfo);
00677         if (!retval) {
00678             palmRec.SetIndex(m_rInfo.m_RecIndex);
00679             palmRec.SetID(m_rInfo.m_RecId);
00680         }
00681     }
00682 
00683     return retval;
00684 }
00685 
00686 long MozABHHManager::UpdateARecord(CPalmRecord & palmRec)
00687 {
00688     long retval=0;
00689 
00690     retval = AllocateRawRecord();
00691     if (retval) 
00692         return retval;
00693 
00694     retval = palmRec.ConvertToHH(m_rInfo);
00695     if (!retval) {
00696         m_rInfo.m_FileHandle = m_hhDB;
00697         m_rInfo.m_Attribs = eRecAttrDirty;
00698         if (m_bRecordDB)
00699             retval = SyncWriteRec(m_rInfo);
00700         else 
00701             retval = SyncWriteResourceRec(m_rInfo);
00702         if (!retval) {
00703             palmRec.SetIndex(m_rInfo.m_RecIndex);
00704             palmRec.SetID(m_rInfo.m_RecId);
00705         }
00706     }
00707 
00708     return retval;
00709 }
00710 
00711 long MozABHHManager::DeleteARecord(CPalmRecord & palmRec)
00712 {
00713     long retval=0;
00714 
00715     retval = AllocateRawRecord();
00716     if (retval) 
00717         return retval;
00718 
00719     retval = palmRec.ConvertToHH(m_rInfo);
00720     if (!retval) {
00721         m_rInfo.m_FileHandle = m_hhDB;
00722         if (m_bRecordDB)
00723             retval = SyncDeleteRec(m_rInfo);
00724         else 
00725             retval = SyncDeleteResourceRec(m_rInfo);
00726     }
00727 
00728     return retval;
00729 }
00730 
00731 long MozABHHManager::PurgeDeletedRecs(void)
00732 {
00733     return (SyncPurgeDeletedRecs(m_hhDB));
00734 }