Back to index

lightning-sunbird  0.9+nobinonly
MozABConduitRecord.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 
00046 #include "MozABConduitRecord.h"
00047 #include "MozABPCManager.h"
00048 #include "MozABConduitSync.h"
00049 
00050 #define  STR_CRETURN  "\r" 
00051 #define  STR_NEWLINE  "\n" 
00052 
00053 #define  CH_CRETURN  0x0D 
00054 #define  CH_NEWLINE  0x0A 
00055 
00056 
00057 // constructor
00058 CMozABConduitRecord::CMozABConduitRecord(void)
00059 {
00060     Reset();
00061 }
00062 
00063 // construct using Palm record
00064 CMozABConduitRecord::CMozABConduitRecord(CPalmRecord &rec)
00065 {
00066     ConvertFromGeneric(rec);
00067 }
00068 
00069 // construct using Mozilla record
00070 CMozABConduitRecord::CMozABConduitRecord(nsABCOMCardStruct &rec)
00071 {
00072     Reset();
00073 
00074     memcpy(&m_nsCard, &rec, sizeof(nsABCOMCardStruct));
00075 
00076     m_dwRecordID = m_nsCard.dwRecordId;
00077     m_dwStatus = m_nsCard.dwStatus;
00078     m_dwCategoryID = m_nsCard.dwCategoryId;
00079 
00080     m_dwPhone1LabelID = PHONE_LABEL_WORK;
00081     m_dwPhone2LabelID = PHONE_LABEL_HOME;
00082     m_dwPhone3LabelID = PHONE_LABEL_FAX;
00083     m_dwPhone4LabelID = PHONE_LABEL_MOBILE;
00084     m_dwPhone5LabelID = PHONE_LABEL_EMAIL;
00085     
00086     m_csName = rec.lastName;
00087     m_csFirst = rec.firstName;
00088     m_csTitle = rec.jobTitle;
00089     m_csCompany = rec.company;
00090 
00091     m_csPhone1 = rec.workPhone;
00092     m_csPhone2 = rec.homePhone;
00093     m_csPhone3 = rec.faxNumber;
00094     m_csPhone4 = rec.cellularNumber;
00095     m_csPhone5 = rec.primaryEmail;
00096 
00097     m_csAddress = (MozABPCManager::gUseHomeAddress)
00098                     ? rec.homeAddress : rec.workAddress;
00099 
00100     m_csCity = (MozABPCManager::gUseHomeAddress) ? rec.homeCity : rec.workCity;
00101     m_csState = (MozABPCManager::gUseHomeAddress) ? rec.homeState : rec.workState;
00102     m_csZipCode = (MozABPCManager::gUseHomeAddress) ? rec.homeZipCode : rec.workZipCode;
00103     m_csCountry = (MozABPCManager::gUseHomeAddress) ? rec.homeCountry : rec.workCountry;
00104 //    CONDUIT_LOG3(gFD, "\nCMozABConduitRecord::CMozABConduitRecord(nsABCOMCardStruct &rec) gUseHomeAddress = %s card home address = %s card work address = %s\n", 
00105 //      (MozABPCManager::gUseHomeAddress) ? "true" : "false", (char *) rec.homeAddress, (char *) rec.workAddress);
00106     m_dwDisplayPhone = rec.preferredPhoneNum;
00107 
00108     m_csNote = rec.notes;
00109 
00110     m_csCustom1 = rec.custom1;
00111     m_csCustom2 = rec.custom2;
00112     m_csCustom3 = rec.custom3;
00113     m_csCustom4 = rec.custom4;
00114 }
00115 
00116 // destructor
00117 CMozABConduitRecord::~CMozABConduitRecord()
00118 {
00119 
00120 }
00121 
00122 // reset the internal data members
00123 void CMozABConduitRecord::Reset(void)
00124 {
00125     memset(&m_nsCard, 0, sizeof(nsABCOMCardStruct));
00126 
00127     m_dwRecordID = 0;
00128     m_dwStatus = 0;
00129     m_dwPosition = 0;
00130     m_dwPhone1LabelID = 0;
00131     m_dwPhone2LabelID = 0;
00132     m_dwPhone3LabelID = 0;
00133     m_dwPhone4LabelID = 0;
00134     m_dwPhone5LabelID = 0;
00135     m_dwPrivate = 0;
00136     m_dwCategoryID = 0;
00137     m_dwDisplayPhone = 1; // work 
00138     m_csName.Empty();
00139     m_csFirst.Empty();
00140     m_csTitle.Empty();
00141     m_csCompany.Empty();
00142     m_csPhone1.Empty();
00143     m_csPhone2.Empty();
00144     m_csPhone3.Empty();
00145     m_csPhone4.Empty();
00146     m_csCustom1.Empty();
00147     m_csCustom2.Empty();
00148     m_csCustom3.Empty();
00149     m_csCustom4.Empty();
00150     m_csPhone5.Empty();
00151     m_csAddress.Empty();
00152     m_csCity.Empty();
00153     m_csState.Empty();
00154     m_csZipCode.Empty();
00155     m_csCountry.Empty();
00156     m_csNote.Empty();
00157 }
00158 
00159 // this method compares this object with another MozAB Conduit record
00160 eRecCompare CMozABConduitRecord::Compare(const CMozABConduitRecord &rec)
00161 {
00162     if ( (m_dwPhone1LabelID != rec.m_dwPhone1LabelID) ||
00163          (m_dwPhone2LabelID != rec.m_dwPhone2LabelID) ||
00164          (m_dwPhone3LabelID != rec.m_dwPhone3LabelID ) ||
00165          (m_dwPhone4LabelID != rec.m_dwPhone4LabelID ) ||
00166          (m_dwPhone5LabelID != rec.m_dwPhone5LabelID ) ||
00167          // comment this out until we can match 4.x's displayPhone algorithm
00168 //         (m_dwDisplayPhone !=  rec.m_dwDisplayPhone ) ||
00169          (m_csName !=  rec.m_csName ) ||
00170          (m_csFirst !=  rec.m_csFirst ) ||
00171          (m_csTitle !=  rec.m_csTitle ) ||
00172          (m_csCompany !=  rec.m_csCompany ) ||
00173          (m_csPhone1 !=  rec.m_csPhone1 ) ||
00174          (m_csPhone2 !=  rec.m_csPhone2 ) ||
00175          (m_csPhone3 !=  rec.m_csPhone3 ) ||
00176          (m_csPhone4 !=  rec.m_csPhone4 ) ||
00177          (m_csCustom1 !=  rec.m_csCustom1 ) ||
00178          (m_csCustom2 !=  rec.m_csCustom2 ) ||
00179          (m_csCustom3 !=  rec.m_csCustom3 ) ||
00180          (m_csCustom4 !=  rec.m_csCustom4 ) ||
00181          (m_csPhone5 !=  rec.m_csPhone5 ) ||
00182          (m_csAddress !=  rec.m_csAddress ) ||
00183          (m_csCity !=  rec.m_csCity ) ||
00184          (m_csState !=  rec.m_csState ) ||
00185          (m_csZipCode !=  rec.m_csZipCode ) ||
00186          (m_csCountry !=  rec.m_csCountry ) ||
00187          (m_csNote !=  rec.m_csNote ))
00188          return eData;
00189     if (m_dwPrivate != rec.m_dwPrivate ) 
00190         return ePrivateFlag;
00191     if (m_dwCategoryID != rec.m_dwCategoryID ) 
00192         return eCategory;
00193 
00194     return eEqual;
00195 }
00196 
00197 #define COPY_FROM_GENERIC(m, d)  {  iLen = _tcslen((char *)pBuff);  \
00198                                     CopyFromHHBuffer((char *)pBuff, m.GetBuffer(iLen * 2), iLen); \
00199                                     m.ReleaseBuffer();              \
00200                                     d = m.GetBuffer(0);             \
00201                                     pBuff += iLen + 1;              \
00202                                  }                                  \
00203 
00204 #define COPY_PHONE_FROM_GENERIC(m, d){  iLen = _tcslen((char *)pBuff);              \
00205                                         CopyFromHHBuffer((char *)pBuff, m.GetBuffer(iLen * 2), iLen); \
00206                                         m.ReleaseBuffer();                          \
00207                                         AssignPhoneToMozData(d, m.GetBuffer(0));    \
00208                                         pBuff += iLen + 1;                          \
00209                                      }                                              \
00210 
00211 
00212 // this method converts CPalmRecord to MozAB Conduit record 
00213 long CMozABConduitRecord::ConvertFromGeneric(CPalmRecord &rec)
00214 {
00215     long                retval = 0;
00216     BYTE                *pBuff;
00217     AddrDBRecordFlags   flags;
00218     AddrOptionsType     options;
00219     int iLen;
00220 
00221     Reset();
00222 
00223     if (rec.GetRawDataSize() == (sizeof(DWORD) + sizeof(DWORD) + sizeof(unsigned char))){
00224         // then this is a deleted record because it has no data
00225         return GEN_ERR_EMPTY_RECORD;
00226     }
00227 
00228     // palm specific data
00229     m_dwRecordID = rec.GetID();
00230     m_dwCategoryID = rec.GetCategory();
00231     m_dwPrivate    = rec.IsPrivate();
00232     m_dwStatus = rec.GetStatus();
00233 
00234     m_nsCard.dwRecordId = m_dwRecordID;
00235     m_nsCard.dwCategoryId = m_dwCategoryID;
00236     m_nsCard.dwStatus = m_dwStatus;
00237 
00238     // clear all values in the Address Record
00239     m_dwPhone1LabelID = PHONE_LABEL_WORK;
00240     m_dwPhone2LabelID = PHONE_LABEL_HOME;
00241     m_dwPhone3LabelID = PHONE_LABEL_FAX;
00242     m_dwPhone4LabelID = PHONE_LABEL_MOBILE;
00243     m_dwPhone5LabelID = PHONE_LABEL_EMAIL;
00244     m_dwDisplayPhone = m_nsCard.preferredPhoneNum;
00245 
00246     DWORD dwRawSize = rec.GetRawDataSize();
00247     if (!dwRawSize) {
00248         // invalid record
00249         return 0;
00250     }
00251 
00252     // get the data for moz card
00253     pBuff = rec.GetRawData();
00254 
00255     // AddrOptionsType
00256     *(DWORD *)&options = CPalmRecord::SwapDWordToIntel(*((DWORD*)pBuff));
00257     m_dwDisplayPhone  = (long)options.displayPhone + 1;
00258     m_dwPhone1LabelID = (DWORD)options.phone1;
00259     m_dwPhone2LabelID = (DWORD)options.phone2;
00260     m_dwPhone3LabelID = (DWORD)options.phone3;
00261     m_dwPhone4LabelID = (DWORD)options.phone4;
00262     m_dwPhone5LabelID = (DWORD)options.phone5;
00263 
00264     pBuff += sizeof(DWORD);
00265 
00266     // The flag bits are used to indicate which fields exist
00267     *(DWORD *)&flags = CPalmRecord::SwapDWordToIntel(*((DWORD*)pBuff));
00268     pBuff += sizeof(DWORD) + sizeof(unsigned char);
00269 
00270     // Name
00271     if (flags.name) COPY_FROM_GENERIC(m_csName, m_nsCard.lastName)
00272     // FirstName
00273     if (flags.firstName) COPY_FROM_GENERIC(m_csFirst, m_nsCard.firstName)
00274     // DisplayName
00275     m_csDisplayName = m_nsCard.firstName;
00276     m_csDisplayName += " ";
00277     m_csDisplayName += m_nsCard.lastName;
00278     m_nsCard.displayName = m_csDisplayName.GetBuffer(0);
00279     // Company
00280     if (flags.company) COPY_FROM_GENERIC(m_csCompany, m_nsCard.company)
00281     // Phones
00282     if (flags.phone1) COPY_PHONE_FROM_GENERIC(m_csPhone1, m_dwPhone1LabelID)
00283     if (flags.phone2) COPY_PHONE_FROM_GENERIC(m_csPhone2, m_dwPhone2LabelID)
00284     if (flags.phone3) COPY_PHONE_FROM_GENERIC(m_csPhone3, m_dwPhone3LabelID)
00285     if (flags.phone4) COPY_PHONE_FROM_GENERIC(m_csPhone4, m_dwPhone4LabelID)
00286     if (flags.phone5) COPY_PHONE_FROM_GENERIC(m_csPhone5, m_dwPhone5LabelID)
00287     // Address
00288     if (flags.address) 
00289     {
00290       if (MozABPCManager::gUseHomeAddress)
00291         COPY_FROM_GENERIC(m_csAddress, m_nsCard.homeAddress)
00292       else
00293          COPY_FROM_GENERIC(m_csAddress, m_nsCard.workAddress)
00294 
00295 //      CONDUIT_LOG4(gFD, "\nConvertFromGeneric gUseHomeAddress = %s card home address = %s card work address = %s result = %s\n", 
00296 //        (MozABPCManager::gUseHomeAddress) ? "true" : "false", (char *) m_nsCard.homeAddress, (char *) m_nsCard.workAddress, (char *) m_csAddress);
00297     }
00298     // City
00299     if (flags.city) 
00300     {
00301       if (MozABPCManager::gUseHomeAddress)
00302         COPY_FROM_GENERIC(m_csCity, m_nsCard.homeCity)
00303       else
00304         COPY_FROM_GENERIC(m_csCity, m_nsCard.workCity)
00305     }
00306     // State
00307     if (flags.state) 
00308     {
00309       if (MozABPCManager::gUseHomeAddress)
00310         COPY_FROM_GENERIC(m_csState, m_nsCard.homeState)
00311       else
00312         COPY_FROM_GENERIC(m_csState, m_nsCard.workState)
00313     }
00314     // ZipCode
00315     if (flags.zipCode) 
00316     {
00317       if (MozABPCManager::gUseHomeAddress)
00318         COPY_FROM_GENERIC(m_csZipCode, m_nsCard.homeZipCode)
00319       else
00320         COPY_FROM_GENERIC(m_csZipCode, m_nsCard.workZipCode)
00321     }
00322     // Country
00323     if (flags.country)
00324     {
00325       if (MozABPCManager::gUseHomeAddress)
00326         COPY_FROM_GENERIC(m_csCountry, m_nsCard.homeCountry)
00327       else
00328         COPY_FROM_GENERIC(m_csCountry, m_nsCard.workCountry)
00329     }
00330     // Title
00331     if (flags.title) COPY_FROM_GENERIC(m_csTitle, m_nsCard.jobTitle)
00332     // Customs
00333     if (flags.custom1) COPY_FROM_GENERIC(m_csCustom1, m_nsCard.custom1)
00334     if (flags.custom2) COPY_FROM_GENERIC(m_csCustom2, m_nsCard.custom2)
00335     if (flags.custom3) COPY_FROM_GENERIC(m_csCustom3, m_nsCard.custom3)
00336     if (flags.custom4) COPY_FROM_GENERIC(m_csCustom4, m_nsCard.custom4)
00337     // Note
00338     if (flags.note) COPY_FROM_GENERIC(m_csNote, m_nsCard.notes)
00339 
00340     return retval;
00341 }
00342 
00343 // this method assigns the phone #s to the Moz card data from Palm Record Phone buffer
00344 void CMozABConduitRecord::AssignPhoneToMozData(DWORD labelID, LPTSTR buf)
00345 {
00346     switch(labelID) {
00347     case PHONE_LABEL_WORK:
00348         m_nsCard.workPhone = buf;
00349         break;
00350     case PHONE_LABEL_HOME:
00351         m_nsCard.homePhone = buf;
00352         break;
00353     case PHONE_LABEL_FAX:
00354         m_nsCard.faxNumber = buf;
00355         break;
00356     case PHONE_LABEL_OTHER:
00357         break;
00358     case PHONE_LABEL_EMAIL:
00359         m_nsCard.primaryEmail = buf;
00360         break;
00361     case PHONE_LABEL_MAIN:
00362         break;
00363     case PHONE_LABEL_PAGER:
00364         m_nsCard.pagerNumber = buf;
00365         break;
00366     case PHONE_LABEL_MOBILE:
00367         m_nsCard.cellularNumber = buf;
00368         break;
00369     }
00370 }
00371 
00372 
00373 #define COPY_TO_GENERIC(m, f)      iLen = m.length();           \
00374                                    if (iLen != 0)               \
00375                                    {                            \
00376                                         f = 1;                  \
00377                                         destLen = StripCRs(pBuff, m.c_str(), iLen);  \
00378                                         pBuff += destLen;       \
00379                                         dwRecSize += destLen;   \
00380                                     }                           \
00381 
00382 
00383 // This method converts records from the Moz type to the CPalmRecord record type.
00384 long CMozABConduitRecord::ConvertToGeneric(CPalmRecord &rec)
00385 {
00386     long                retval = 0;
00387     char                *pBuff, *pFlags, *pCompany, *pFirst;
00388     AddrDBRecordFlags   flags;
00389     AddrOptionsType     options;
00390     int                 destLen;
00391     BYTE                szRawData[MAX_RECORD_SIZE];
00392     DWORD               dwRecSize = 0;
00393     int                 iLen=0;
00394 
00395 
00396     rec.SetID(m_dwRecordID);
00397 
00398     rec.SetCategory(m_dwCategoryID);
00399 
00400     rec.SetPrivate(m_dwPrivate);
00401 
00402        rec.SetAttribs(m_dwStatus);
00403 
00404     pBuff = (char*)szRawData;
00405 
00406     // AddrOptionsType
00407     *(DWORD *)&options = 0;
00408     options.displayPhone = m_dwDisplayPhone - 1;
00409     options.phone1 = LOWORD(m_dwPhone1LabelID);
00410     options.phone2 = LOWORD(m_dwPhone2LabelID);
00411     options.phone3 = LOWORD(m_dwPhone3LabelID);
00412     options.phone4 = LOWORD(m_dwPhone4LabelID);
00413     options.phone5 = LOWORD(m_dwPhone5LabelID);
00414     *((DWORD *)pBuff) = CPalmRecord::SwapDWordToMotor(*(DWORD *)&options);
00415 
00416     pBuff += sizeof(DWORD);
00417     dwRecSize += sizeof(DWORD);
00418 
00419     // The flag bits are used to indicate which fields exist
00420     pFlags = pBuff;
00421     *(DWORD *)&flags = 0;
00422     pBuff += sizeof(DWORD);
00423     dwRecSize += sizeof(DWORD);
00424     
00425     // Company Field Offset - Initialize to zero
00426     pCompany = pBuff;
00427     *((unsigned char *)pCompany) = 0;
00428     pBuff += sizeof(unsigned char);
00429     dwRecSize += sizeof(unsigned char);
00430     
00431     // First Field
00432     pFirst = pBuff;
00433 
00434     // Name
00435     COPY_TO_GENERIC(m_csName, flags.name)
00436     // FirstName
00437     COPY_TO_GENERIC(m_csFirst, flags.firstName)
00438     // Company
00439     COPY_TO_GENERIC(m_csCompany, flags.company)
00440     // Phone1
00441     COPY_TO_GENERIC(m_csPhone1, flags.phone1)
00442     // Phone2
00443     COPY_TO_GENERIC(m_csPhone2, flags.phone2)
00444     // Phone3
00445     COPY_TO_GENERIC(m_csPhone3, flags.phone3)
00446     // Phone4
00447     COPY_TO_GENERIC(m_csPhone4, flags.phone4)
00448     // Phone5
00449     COPY_TO_GENERIC(m_csPhone5, flags.phone5)
00450     // Address
00451     COPY_TO_GENERIC(m_csAddress, flags.address)
00452     // City
00453     COPY_TO_GENERIC(m_csCity, flags.city)
00454     // State
00455     COPY_TO_GENERIC(m_csState, flags.state)
00456     // ZipCode
00457     COPY_TO_GENERIC(m_csZipCode, flags.zipCode)
00458     // Country
00459     COPY_TO_GENERIC(m_csCountry, flags.country)
00460     // Title
00461     COPY_TO_GENERIC(m_csTitle, flags.title)
00462     // Custom1
00463     COPY_TO_GENERIC(m_csCustom1, flags.custom1)
00464     // Custom2
00465     COPY_TO_GENERIC(m_csCustom2, flags.custom2)
00466     // Custom3
00467     COPY_TO_GENERIC(m_csCustom3, flags.custom3)
00468     // Custom4
00469     COPY_TO_GENERIC(m_csCustom4, flags.custom4)
00470     // Note
00471     COPY_TO_GENERIC(m_csNote, flags.note)
00472 
00473     // Store the AddrDBRecordFlags
00474     *((DWORD *)pFlags) = CPalmRecord::SwapDWordToMotor(*(DWORD *)&flags);
00475 
00476     
00477     if (dwRecSize == (sizeof(DWORD) + sizeof(DWORD) + sizeof(unsigned char))){
00478         // then this is a deleted record because it has no data
00479         rec.SetDeleted();
00480     }
00481 
00482     retval = rec.SetRawData(dwRecSize, szRawData);
00483 
00484     return(retval);
00485 }
00486 
00487 // this function copies data from the handheld into the passed destination,
00488 // and optionally adds carriage returns to handheld data
00489 long CMozABConduitRecord::CopyFromHHBuffer(TCHAR* pSrc, TCHAR* pDest, int len)
00490 {
00491     long retval = GEN_ERR_INVALID_POINTER;
00492     int off=0;
00493 
00494     TCHAR* pCurr;
00495 
00496     if (pDest) {
00497 
00498         // Only add Cr's if newlines are present..
00499         pCurr = _tcspbrk(pSrc, STR_NEWLINE);
00500         if(pCurr) 
00501         {
00502             while (off < len && *pSrc)
00503             {
00504                 if (*pSrc == CH_NEWLINE)
00505                 {
00506                     *pDest = CH_CRETURN;
00507                     pDest++;
00508                 }
00509                 *pDest = *pSrc;
00510 
00511                 pDest++ ; pSrc++;
00512                 off++;
00513             }
00514             *pDest = 0;
00515         }
00516         else 
00517         {
00518             strncpy(pDest, pSrc, len);
00519             pDest[len] = 0;
00520         }
00521         retval = 0;
00522     }
00523     return(retval);
00524 }
00525 
00526 // this function strips extra carraige returns from PC data
00527 int CMozABConduitRecord::StripCRs(TCHAR* pDest, const TCHAR* pSrc, int len)
00528 {
00529     int  retval = 0;
00530     int  off    = 0;
00531     TCHAR* pCurr; 
00532     TCHAR* pStart = pDest;
00533 
00534     // See if any cr's are present in the first place.
00535     pCurr = _tcspbrk(pSrc, STR_CRETURN);
00536     if (pCurr)
00537     {
00538         while (off < len && *pSrc)
00539         {
00540             if (*pSrc == CH_CRETURN)
00541                 pSrc++;
00542 
00543             *pDest = *pSrc;
00544 
00545             off++;
00546             pDest++ ; pSrc++;
00547         }
00548         *pDest = 0;
00549 
00550         retval = strlen(pStart) + 1;
00551     }
00552     else
00553     {
00554         strncpy(pDest, pSrc, len);
00555         *(pDest + len) = '\0';
00556         retval = len + 1;
00557     }    
00558 
00559     return(retval);
00560 }
00561 
00562 void CMozABConduitRecord::CleanUpABCOMCardStruct(nsABCOMCardStruct * card)
00563 {
00564     if(!card)
00565         return;
00566 
00567     CoTaskMemFree(card->firstName);
00568     CoTaskMemFree(card->lastName);
00569     CoTaskMemFree(card->displayName);
00570     CoTaskMemFree(card->nickName);
00571     CoTaskMemFree(card->primaryEmail);
00572     CoTaskMemFree(card->secondEmail);
00573     CoTaskMemFree(card->workPhone);
00574     CoTaskMemFree(card->homePhone);
00575     CoTaskMemFree(card->faxNumber);
00576     CoTaskMemFree(card->pagerNumber);
00577     CoTaskMemFree(card->cellularNumber);
00578     CoTaskMemFree(card->homeAddress);
00579     CoTaskMemFree(card->homeAddress2);
00580     CoTaskMemFree(card->homeCity);
00581     CoTaskMemFree(card->homeState);
00582     CoTaskMemFree(card->homeZipCode);
00583     CoTaskMemFree(card->homeCountry);
00584     CoTaskMemFree(card->workAddress);
00585     CoTaskMemFree(card->workAddress2);
00586     CoTaskMemFree(card->workCity);
00587     CoTaskMemFree(card->workState);
00588     CoTaskMemFree(card->workZipCode);
00589     CoTaskMemFree(card->workCountry);
00590     CoTaskMemFree(card->jobTitle);
00591     CoTaskMemFree(card->department);
00592     CoTaskMemFree(card->company);
00593     CoTaskMemFree(card->webPage1);
00594     CoTaskMemFree(card->webPage2);
00595     CoTaskMemFree(card->birthYear);
00596     CoTaskMemFree(card->birthMonth);
00597     CoTaskMemFree(card->birthDay);
00598     CoTaskMemFree(card->custom1);
00599     CoTaskMemFree(card->custom2);
00600     CoTaskMemFree(card->custom3);
00601     CoTaskMemFree(card->custom4);
00602     CoTaskMemFree(card->notes);
00603     CoTaskMemFree(card->mailListURI);
00604 }