Changeset 153

Show
Ignore:
Timestamp:
01/17/08 23:13:03 (11 months ago)
Author:
cyrusdaboo
Message:

Fix crash when no address book exists in CardDAV. Enable component level synchronization
with CardDAV.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Mulberry/branches/v4.1d1/Sources_Common/Mail/Protocols/CAdbkProtocol.cp

    r149 r153  
    4545 
    4646#include "CVCardAddressBook.h" 
     47#include "CVCardMapper.h" 
    4748#include "CVCardSync.h" 
     49#include "CVCardVCard.h" 
    4850 
    4951#include "cdfstream.h" 
     
    679681                                        break; 
    680682                                case CINETAccount::eCardDAVAdbk: 
    681                                         for(CAddressBookList::const_iterator niter = mStoreRoot.GetChildren()->begin(); 
    682                                                 niter != mStoreRoot.GetChildren()->end(); niter++) 
     683                                        if (mStoreRoot.GetChildren() != NULL) 
    683684                                        { 
    684                                                 if ((*niter)->IsAdbk()) 
     685                                                for(CAddressBookList::const_iterator niter = mStoreRoot.GetChildren()->begin(); 
     686                                                        niter != mStoreRoot.GetChildren()->end(); niter++) 
    685687                                                { 
    686                                                         if (adbk) 
     688                                                        if ((*niter)->IsAdbk()) 
    687689                                                        { 
    688                                                                 adbk = NULL; 
    689                                                                 break; 
     690                                                                if (adbk) 
     691                                                                { 
     692                                                                        adbk = NULL; 
     693                                                                        break; 
     694                                                                } 
     695                                                                else 
     696                                                                        adbk = *niter; 
    690697                                                        } 
    691                                                         else 
    692                                                                 adbk = *niter; 
    693698                                                } 
    694699                                        } 
     
    10871092void CAdbkProtocol::SyncComponentsFromServer(CAddressBook* adbk) 
    10881093{ 
    1089 #if 0 
    10901094        // We need to do this as a proper transaction with locking 
    10911095        try 
     
    10981102                //  2.1 Add new components to server and cache info 
    10991103                //  2.2 Remove deleted components from server and cached server info if still present on server 
    1100                 //  2.3 Cache info for changed items for later sync (or change them immediately if the server has not changed 
     1104                //  2.3 Cache info for changed items for later sync (or change them immediately if the server has not changed) 
    11011105                // 
    11021106                // 3. Scan list of local components 
     
    11181122 
    11191123                // Step 1 
     1124                vCard::CVCardAddressBook* vadbk = adbk->GetVCardAdbk(); 
     1125                CCardDAVVCardClient* cardclient = static_cast<CCardDAVVCardClient*>(mClient); 
    11201126                cdstrmap comps; 
    11211127                bool server_changed = mClient->_AdbkChanged(adbk); 
    11221128                if (server_changed) 
    1123                         mClient->_GetComponentInfo(adbk, vadbk, comps); 
     1129                        cardclient->_GetComponentInfo(adbk, *vadbk, comps); 
    11241130                else 
    11251131                { 
     
    11301136                cdstrmap cache_added; 
    11311137                cdstrmap cache_changed; 
    1132                 for(vcard::CVCardComponentRecordDB::const_iterator iter = adbk->GetRecording().begin(); iter != adbk->GetRecording().end(); iter++) 
     1138                for(vCard::CVCardComponentRecordDB::const_iterator iter = vadbk->GetRecording().begin(); iter != vadbk->GetRecording().end(); iter++) 
    11331139                { 
    11341140                        // Step 2.1 
    1135                         if ((*iter).second.GetAction() == vcard::CVCardComponentRecord::eAdded) 
     1141                        if ((*iter).second.GetAction() == vCard::CVCardComponentRecord::eAdded) 
    11361142                        { 
    11371143                                // Add component to server 
    1138                                 const iCal::CICalendarComponent* comp = cal.GetComponentByKey((*iter).first); 
     1144                                const vCard::CVCardVCard* comp = vadbk->GetCardByKey((*iter).first); 
    11391145                                if (comp != NULL) 
    11401146                                { 
    11411147                                        // Add component to server 
    1142                                         mClient->_AddComponent(node, cal, *comp); 
     1148                                        cardclient->_AddComponent(adbk, *vadbk, *comp); 
    11431149 
    11441150                                        // Add to added cache 
     
    11481154                         
    11491155                        // Step 2.2 
    1150                         else if ((*iter).second.GetAction() == iCal::CICalendarComponentRecord::eRemoved) 
     1156                        else if ((*iter).second.GetAction() == vCard::CVCardComponentRecord::eRemoved) 
    11511157                        { 
    11521158                                // Is it still present on the server 
     
    11541160                                { 
    11551161                                        // Remove component from server 
    1156                                         mClient->_RemoveComponent(node, cal, (*iter).second.GetRURL()); 
     1162                                        cardclient->_RemoveComponent(adbk, *vadbk, (*iter).second.GetRURL()); 
    11571163                                         
    11581164                                        // Remove from server component info 
     
    11621168 
    11631169                        // Step 2.3 
    1164                         else if ((*iter).second.GetAction() == iCal::CICalendarComponentRecord::eChanged) 
     1170                        else if ((*iter).second.GetAction() == vCard::CVCardComponentRecord::eChanged) 
    11651171                        { 
    11661172                                if (server_changed) 
     
    11691175                                { 
    11701176                                        // Change it on the server 
    1171                                         const iCal::CICalendarComponent* comp = cal.GetComponentByKey((*iter).first); 
    1172                                         mClient->_ChangeComponent(node, cal, *comp); 
     1177                                        const vCard::CVCardVCard* comp = vadbk->GetCardByKey((*iter).first); 
     1178                                        cardclient->_ChangeComponent(adbk, *vadbk, *comp); 
    11731179                                        cache_changed.insert(cdstrmap::value_type((*iter).second.GetRURL(), (*iter).second.GetETag())); 
    11741180                                } 
     
    11811187                { 
    11821188                        // Get component info from cache 
    1183                         iCal::CICalendarComponentDBList dbs; 
    1184                         cal.GetAllDBs(dbs); 
    11851189                        cdstrvect component_keys; 
    1186                         for(iCal::CICalendarComponentDBList::const_iterator iter1 = dbs.begin(); iter1 != dbs.end(); iter1++) 
     1190                        for(vCard::CVCardComponentDB::const_iterator iter = vadbk->GetVCards().begin(); iter != vadbk->GetVCards().end(); iter++) 
    11871191                        { 
    1188                                 for(iCal::CICalendarComponentDB::const_iterator iter2 = (*iter1)->begin(); iter2 != (*iter1)->end(); iter2++) 
    1189                                 { 
    1190                                         component_keys.push_back((*iter2).second->GetMapKey()); 
    1191                                 } 
     1192                                component_keys.push_back((*iter).second->GetMapKey()); 
    11921193                        } 
    11931194                         
     
    11961197                        for(cdstrvect::const_iterator iter = component_keys.begin(); iter != component_keys.end(); iter++) 
    11971198                        { 
    1198                                 iCal::CICalendarComponent* cache_comp = cal.GetComponentByKey(*iter); 
     1199                                vCard::CVCardVCard* cache_comp = vadbk->GetCardByKey(*iter); 
    11991200                                if (cache_comp == NULL) 
    12001201                                        continue; 
     
    12251226                                        { 
    12261227                                                // Write changed cache component to server 
    1227                                                 mClient->_ChangeComponent(node, cal, *cache_comp); 
     1228                                                cardclient->_ChangeComponent(adbk, *vadbk, *cache_comp); 
    12281229                                        } 
    12291230                                         
     
    12331234                                                // Do iCal SEQ etc comparison 
    12341235                                                 
    1235                                                 // First read in component from server into temp calendar 
    1236                                                 iCal::CICalendar tempcal; 
    1237                                                 iCal::CICalendarComponent* server_comp = mClient->_ReadComponent(node, tempcal, server_rurl); 
     1236                                                // First read in component from server into temp addressbook 
     1237                                                vCard::CVCardAddressBook tempvcard; 
     1238                                                vCard::CVCardVCard* server_comp = cardclient->_ReadComponent(adbk, tempvcard, server_rurl); 
    12381239                                                if (server_comp != NULL) 
    12391240                                                { 
    1240                                                         int result = iCal::CICalendarSync::CompareComponentVersions(server_comp, cache_comp); 
     1241                                                        int result = -1; //iCal::CICalendarSync::CompareComponentVersions(server_comp, cache_comp); 
    12411242                                                         
    12421243                                                        if (result == 1) 
    12431244                                                        { 
    12441245                                                                // Cache is newer than server - cache overwrites to server 
    1245                                                                 mClient->_ChangeComponent(node, cal, *cache_comp); 
     1246                                                                cardclient->_ChangeComponent(adbk, *vadbk, *cache_comp); 
    12461247                                                        } 
    12471248                                                        else if (result == -1) 
     
    12501251 
    12511252                                                                // Remove the cached component first 
    1252                                                                 cal.RemoveComponentByKey(cache_comp->GetMapKey()); 
     1253                                                                vadbk->RemoveCardByKey(cache_comp->GetMapKey()); 
    12531254                                                                cache_comp = NULL; 
    12541255                                                                 
    12551256                                                                // Copy component from server into local cache effectively replacing old one 
    1256                                                                 iCal::CICalendarComponent* new_comp = server_comp->clone(); 
    1257                                                                 new_comp->SetCalendar(cal.GetRef()); 
    1258                                                                 cal.AddComponent(new_comp); 
     1257                                                                vCard::CVCardComponent* new_comp = server_comp->clone(); 
     1258                                                                new_comp->SetAddressBook(vadbk->GetRef()); 
     1259                                                                vadbk->AddCard(new_comp); 
    12591260                                                        } 
    12601261                                                } 
     
    12711272                                                 
    12721273                                                // Remove the cached component first 
    1273                                                 cal.RemoveComponentByKey(cache_comp->GetMapKey()); 
     1274                                                vadbk->RemoveCardByKey(cache_comp->GetMapKey()); 
    12741275                                                cache_comp = NULL; 
    12751276                                                 
    12761277                                                // Read component from server into local cache effectively replacing old one 
    1277                                                 mClient->_ReadComponent(node, cal, server_rurl); 
     1278                                                cardclient->_ReadComponent(adbk, *vadbk, server_rurl); 
    12781279                                        } 
    12791280                                } 
     
    12831284                                { 
    12841285                                        // comp is deleted in this call 
    1285                                         cal.RemoveComponentByKey(cache_comp->GetMapKey()); 
     1286                                        vadbk->RemoveCardByKey(cache_comp->GetMapKey()); 
    12861287                                        cache_comp = NULL; 
    12871288                                } 
     
    13031304                        // Read components from server into local cache as its a new one on the server 
    13041305                        if (rurls.size() != 0) 
    1305                                 mClient->_ReadComponents(node, cal, rurls); 
     1306                                cardclient->_ReadComponents(adbk, *vadbk, rurls); 
    13061307                } 
    13071308 
    13081309                // Clear out cache recording 
    1309                 cal.ClearRecording(); 
     1310                vadbk->ClearRecording(); 
    13101311                 
    13111312                // Get the current server sync token 
    1312                 mClient->_UpdateSyncToken(node, cal); 
     1313                cardclient->_UpdateSyncToken(adbk); 
    13131314 
    13141315                // Now write back cache 
    1315                 if (!mCacheClient->_TouchCalendar(node)) 
    1316                         DumpCalendars(); 
    1317                 mCacheClient->_WriteFullCalendar(node, cal); 
     1316                if (!mCacheClient->_TouchAdbk(adbk)) 
     1317                        DumpAddressBooks(); 
     1318                mCacheClient->_WriteFullAddressBook(adbk); 
     1319         
     1320                // Now map VCards into internal addresses 
     1321                vcardstore::MapFromVCards(adbk); 
    13181322        } 
    13191323        catch(...) 
     
    13241328                throw; 
    13251329        } 
    1326 #endif 
    13271330} 
    13281331