From 8fb4411dd608181d03c581df1ce1963809b9d1e8 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Sun, 4 Sep 2011 16:25:32 +0000 Subject: [PATCH] See ChangeLog Monotone-Parent: 34186beb96b4e03796e53fcc658539fd1c3dbb8a Monotone-Revision: 8027e57cbf5cbb4ab2ee6bf9509fe2f571f150c1 Monotone-Author: ludovic@Sophos.ca Monotone-Date: 2011-09-04T16:25:32 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 11 ++++ OpenChange/MAPIStoreContext.m | 2 + OpenChange/MAPIStoreMapping.m | 33 +++++++++--- OpenChange/MAPIStoreSOGo.m | 94 ++++++++++++++--------------------- 4 files changed, 76 insertions(+), 64 deletions(-) diff --git a/ChangeLog b/ChangeLog index a49c9f952..20e8b8481 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2011-09-04 Ludovic Marcotte + + * OpenChange/MAPIStoreMapping.m: (MAPIStoreMappingTDBTraverse()) + Fixed a major issue regarding the use of strtoll. It was overflowing + keys as they are unsigned long long int. We now make use of strtoull + which fixes the problem and avoids major cache corruption of the + indexing.tdb database (per user). + + * OpenChange/MAPIStoreSOGo.m: Some cleanups to ease current and + future debugging + 2011-08-18 Francis Lachapelle * UI/WebServerResources/UIxContactEditor.js diff --git a/OpenChange/MAPIStoreContext.m b/OpenChange/MAPIStoreContext.m index ad848918b..fa9f86788 100644 --- a/OpenChange/MAPIStoreContext.m +++ b/OpenChange/MAPIStoreContext.m @@ -410,6 +410,8 @@ _prepareContextClass (Class contextClass, openchangedb_get_new_folderID (connInfo->oc_ctx, &mappingId); [mapping registerURL: childURL withID: mappingId]; contextId = 0; + + // FIXME: + 7 to skip the BOM or what? mapistore_search_context_by_uri (mstoreCtx, [folderURL UTF8String] + 7, &contextId, &rootObject); mapistore_indexing_record_add_mid (mstoreCtx, contextId, mappingId); diff --git a/OpenChange/MAPIStoreMapping.m b/OpenChange/MAPIStoreMapping.m index 63ae6f83a..fa1415d6b 100644 --- a/OpenChange/MAPIStoreMapping.m +++ b/OpenChange/MAPIStoreMapping.m @@ -55,21 +55,36 @@ MAPIStoreMappingTDBTraverse (TDB_CONTEXT *ctx, TDB_DATA data1, TDB_DATA data2, NSNumber *idNbr; NSString *uri; char *idStr, *uriStr; - uint64_t idVal; + long long unsigned int idVal; + // get the key + // key examples : key(18) = "0x6900000000000001" + // key(31) = "SOFT_DELETED:0xb100020000000001" + // idStr = (char *) data1.dptr; - idVal = strtoll (idStr, NULL, 16); - idNbr = [NSNumber numberWithUnsignedLongLong: idVal]; + idNbr = nil; - uriStr = strndup ((const char *) data2.dptr, data2.dsize); - *(uriStr+(data2.dsize)) = 0; + if (strncmp(idStr, "SOFT_DELETED:", 13) != 0) + { + // It's very important here to use strtoull and NOT strtoll as + // the latter will overflow a long long with typical key values. + idVal = strtoull(idStr, NULL, 0); + idNbr = [NSNumber numberWithUnsignedLongLong: idVal]; + } + + // get the value and null-terminate it + uriStr = (char *)malloc(sizeof(char *) * data2.dsize+1); + memset(uriStr, 0, data2.dsize+1); + memcpy(uriStr, (const char *) data2.dptr, data2.dsize); uri = [NSString stringWithUTF8String: uriStr]; free (uriStr); mapping = data; - [mapping setObject: uri forKey: idNbr]; - // NSLog (@"preregistered url '%@' for id '%@'", uri, idNbr); + if (uri && idNbr) + { + [mapping setObject: uri forKey: idNbr]; + } return 0; } @@ -142,9 +157,11 @@ MAPIStoreMappingTDBTraverse (TDB_CONTEXT *ctx, TDB_DATA data1, TDB_DATA data2, { idNbr = [keys objectAtIndex: count]; uri = [mapping objectForKey: idNbr]; - // [self logWithFormat: @"preregistered id '%@' for url '%@'", idNbr, uri]; + //[self logWithFormat: @"preregistered id '%@' for url '%@'", idNbr, uri]; [reverseMapping setObject: idNbr forKey: uri]; } + + //[self logWithFormat: @"Complete mapping: %@ \nComplete reverse mapping: %@", mapping, reverseMapping]; } return self; diff --git a/OpenChange/MAPIStoreSOGo.m b/OpenChange/MAPIStoreSOGo.m index b54cdc872..9b5758f21 100644 --- a/OpenChange/MAPIStoreSOGo.m +++ b/OpenChange/MAPIStoreSOGo.m @@ -48,6 +48,13 @@ #include #include +static int +sogo_backend_unexpected_error() +{ + NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO OBJECT"); + return MAPISTORE_SUCCESS; +} + /** \details Initialize sogo mapistore backend @@ -169,8 +176,7 @@ sogo_context_get_path(void *backend_object, TALLOC_CTX *mem_ctx, } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO OBJECT"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -200,8 +206,7 @@ sogo_context_get_root_folder(void *backend_object, TALLOC_CTX *mem_ctx, } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO OBJECT"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -239,8 +244,7 @@ sogo_folder_open_folder(void *folder_object, TALLOC_CTX *mem_ctx, uint64_t fid, } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO OBJECT"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -277,8 +281,7 @@ sogo_folder_create_folder(void *folder_object, TALLOC_CTX *mem_ctx, } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO OBJECT"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -313,8 +316,7 @@ sogo_folder_delete_folder(void *folder_object, uint64_t fid) } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO OBJECT"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -340,8 +342,7 @@ sogo_folder_get_child_count(void *folder_object, uint8_t table_type, uint32_t *c } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO OBJECT"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -374,8 +375,7 @@ sogo_folder_open_message(void *folder_object, } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO OBJECT"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -409,8 +409,7 @@ sogo_folder_create_message(void *folder_object, } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO OBJECT"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -436,8 +435,7 @@ sogo_folder_delete_message(void *folder_object, uint64_t mid, uint8_t flags) } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO OBJECT"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -469,8 +467,7 @@ sogo_folder_get_deleted_fmids(void *folder_object, TALLOC_CTX *mem_ctx, } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO OBJECT"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -504,8 +501,7 @@ sogo_folder_open_table(void *folder_object, TALLOC_CTX *mem_ctx, } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO OBJECT"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -535,8 +531,7 @@ sogo_message_create_attachment (void *message_object, TALLOC_CTX *mem_ctx, void } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO OBJECT"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -567,8 +562,7 @@ sogo_message_open_attachment (void *message_object, TALLOC_CTX *mem_ctx, } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO OBJECT"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -599,8 +593,7 @@ sogo_message_get_attachment_table (void *message_object, TALLOC_CTX *mem_ctx, vo } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO OBJECT"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -629,8 +622,7 @@ sogo_message_modify_recipients (void *message_object, } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO OBJECT"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -657,8 +649,7 @@ sogo_message_save (void *message_object) } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO OBJECT"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -685,8 +676,7 @@ sogo_message_submit (void *message_object, enum SubmitFlags flags) } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO OBJECT"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -724,8 +714,7 @@ sogo_message_attachment_open_embedded_message } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO CONTEXT"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -751,8 +740,7 @@ static int sogo_table_get_available_properties(void *table_object, } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO DATA"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -779,8 +767,7 @@ sogo_table_set_columns (void *table_object, uint16_t count, enum MAPITAGS *prope } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO DATA"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -809,8 +796,7 @@ sogo_table_set_restrictions (void *table_object, struct mapi_SRestriction *restr } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO DATA"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -839,8 +825,7 @@ sogo_table_set_sort_order (void *table_object, struct SSortOrderSet *sort_order, } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO DATA"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -869,8 +854,7 @@ sogo_table_get_row (void *table_object, TALLOC_CTX *mem_ctx, } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO DATA"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -899,8 +883,7 @@ sogo_table_get_row_count (void *table_object, } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO DATA"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -912,6 +895,7 @@ sogo_table_handle_destructor (void *table_object, uint32_t handle_id) struct MAPIStoreTallocWrapper *wrapper; NSAutoreleasePool *pool; MAPIStoreTable *table; + int rc; DEBUG (5, ("[SOGo: %s:%d]\n", __FUNCTION__, __LINE__)); @@ -922,13 +906,14 @@ sogo_table_handle_destructor (void *table_object, uint32_t handle_id) pool = [NSAutoreleasePool new]; [table destroyHandle: handle_id]; [pool release]; + rc = MAPISTORE_SUCCESS; } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO DATA"); + rc = sogo_backend_unexpected_error(); } - return MAPISTORE_SUCCESS; + return rc; } static int sogo_properties_get_available_properties(void *object, @@ -952,8 +937,7 @@ static int sogo_properties_get_available_properties(void *object, } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO DATA"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -984,8 +968,7 @@ sogo_properties_get_properties (void *object, } else { - NSLog (@" UNEXPECTED WEIRDNESS: RECEIVED NO DATA"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc; @@ -1011,8 +994,7 @@ sogo_properties_set_properties (void *object, struct SRow *aRow) } else { - NSLog (@" bad object pointer"); - rc = MAPISTORE_SUCCESS; + rc = sogo_backend_unexpected_error(); } return rc;