Implement lookup of mailbox GUID and replica information in mapistore.
authorbradh <bradh@71d39326-ef09-db11-b2a4-00e04c779ad1>
Wed, 5 Jan 2011 02:48:45 +0000 (02:48 +0000)
committerbradh <bradh@71d39326-ef09-db11-b2a4-00e04c779ad1>
Wed, 5 Jan 2011 02:48:45 +0000 (02:48 +0000)
git-svn-id: https://svn.openchange.org/openchange@2472 71d39326-ef09-db11-b2a4-00e04c779ad1

branches/mapistore_v2/libmapi/conf/mapi-properties
branches/mapistore_v2/mapiproxy/libmapistore/backends/mapistore_mstoredb.c
branches/mapistore_v2/mapiproxy/libmapistore/mapistore.h
branches/mapistore_v2/mapiproxy/libmapistore/mapistore_interface.c
branches/mapistore_v2/mapiproxy/libmapistore/mapistore_private.h
branches/mapistore_v2/mapiproxy/servers/default/emsmdb/oxcstor.c

index 1b24111855fe44a40fb5b96051ae66b1b365962a..141644723848ca56d91b082daf41457448a86698 100644 (file)
 0xd00b0014  openchange_private_SEARCH_FID
 0xd00c0014  openchange_private_VIEWS_FID
 0xd00d0014  openchange_private_SHORTCUTS_FID
+0xd00e0048  openchange_private_MailboxGUID
+0xd00f0002  openchange_private_ReplicaID
+0xd0100048  openchange_private_ReplicaGUID
 0xf000000d  PR_EMS_AB_OTHER_RECIPS
 0xfff8101e  PR_EMS_AB_CHILD_RDNS
 0xfff9001e  PR_EMS_AB_HIERARCHY_PATH
index 878a3e772067ce3b90c2c4dc5ea45bd8eb713502..8cd4f010aca985f8712d99d9b49647af08af9e56 100644 (file)
@@ -23,6 +23,7 @@
 #include "mapistore_mstoredb.h"
 
 #include <string.h>
+#include <assert.h>
 
 /**
    \details Initialize mstoredb mapistore backend
@@ -436,7 +437,6 @@ static enum MAPISTORE_ERROR mstoredb_op_getprops(void *private_data, uint64_t fm
        const char * const              folder_attrs[] = { "*", NULL };
        int                             ret;
        int                             i = 0;
-       struct SPropValue               prop;
 
        DEBUG(5, ("[%s:%d]\n", __FUNCTION__, __LINE__));
 
@@ -475,10 +475,30 @@ static enum MAPISTORE_ERROR mstoredb_op_getprops(void *private_data, uint64_t fm
        }
 
        /* extract results and return them */
-       /* TODO: this is a special hack for PT_I8, and is not general */
+       /* TODO: this needs to be completed */
        for (i = 0; i < proptags->cValues; ++i) {
+               struct SPropValue               prop;
                prop.ulPropTag = proptags->aulPropTag[i];
-               prop.value.d = ldb_msg_find_attr_as_uint64(res->msgs[0], get_proptag_name(proptags->aulPropTag[i]), 0);
+               switch(proptags->aulPropTag[i] & 0xFFFF) {
+               case PT_SHORT:
+                       prop.value.i = ldb_msg_find_attr_as_uint(res->msgs[0], get_proptag_name(proptags->aulPropTag[i]), 0);
+                       break;
+               case PT_I8:
+                       prop.value.d = ldb_msg_find_attr_as_uint64(res->msgs[0], get_proptag_name(proptags->aulPropTag[i]), 0);
+                       break;
+               case PT_CLSID:
+               {
+                       const char *guid_str = ldb_msg_find_attr_as_string(res->msgs[0], get_proptag_name(proptags->aulPropTag[i]), "");
+                       DEBUG(7, ("[%s] guid_str: %s\n", __FUNCTION__, guid_str));
+                       prop.value.lpguid = talloc(props, struct FlatUID_r);
+                       GUID_from_string(guid_str, (struct GUID*)prop.value.lpguid);
+                       break;
+               }
+               default:
+                       /* if you hit this, you need to implement the missing property type */
+                       DEBUG(0, ("[%s] unhandled property type: 0x%04x\n", __FUNCTION__, (proptags->aulPropTag[i] & 0xFFFF)));
+                       assert(0);
+               }
                SRow_addprop(props, prop);
        }
 
index d6a506674f0f210f1f771828f83eea96abb973f1..15fcfb49c7775613d42c5e166def20400c9d79c7 100644 (file)
@@ -251,6 +251,8 @@ enum MAPISTORE_ERROR                mapistore_get_child_fids(struct mapistore_context *, uint3
 enum MAPISTORE_ERROR           mapistore_deletemessage(struct mapistore_context *, uint32_t, uint64_t, uint8_t);
 enum MAPISTORE_ERROR           mapistore_get_next_fmid(struct mapistore_context *mstore_ctx, uint64_t *fmid);
 enum MAPISTORE_ERROR           mapistore_get_SystemFolderIDs(struct mapistore_context *mstore_ctx, const uint32_t context_id, uint64_t (*FolderId)[13]);
+enum MAPISTORE_ERROR           mapistore_get_MailboxGuid(struct mapistore_context *mstore_ctx, const uint32_t context_id, struct GUID *MailboxGUID);
+enum MAPISTORE_ERROR           mapistore_get_MailboxReplica(struct mapistore_context *mstore_ctx, const uint32_t context_id, uint16_t *ReplId, struct GUID *ReplGUID);
 
 /* definitions from mapistore_processing.c */
 enum MAPISTORE_ERROR           mapistore_set_mapping_path(const char *);
index ea890a701e0cafe7b7c94c806a7e1a256b8bda12..8d5350b209070e278c6ec0287a965f0e369efa2c 100644 (file)
@@ -1311,3 +1311,83 @@ _PUBLIC_ enum MAPISTORE_ERROR mapistore_get_SystemFolderIDs(struct mapistore_con
        talloc_free(mem_ctx);
        return MAPISTORE_SUCCESS;
 }
+
+_PUBLIC_ enum MAPISTORE_ERROR mapistore_get_MailboxGuid(struct mapistore_context *mstore_ctx,
+                                                       const uint32_t context_id,
+                                                       struct GUID *MailboxGUID)
+{
+       struct SPropTagArray    props;
+       struct SRow             *propvalues;
+       TALLOC_CTX              *mem_ctx = 0;
+       uint64_t                mailbox_fid = 0;
+       enum MAPISTORE_ERROR    retval;
+
+       mem_ctx = talloc_init(NULL);
+
+       props.cValues = 1;
+       props.aulPropTag = talloc_zero_array(mem_ctx, enum MAPITAGS, props.cValues);
+       props.aulPropTag[0]  = openchange_private_MailboxGUID;
+
+       propvalues = talloc_zero(mem_ctx, struct SRow);
+        propvalues->cValues = 0;
+
+       retval = mapistore_get_context_fid(mstore_ctx, context_id, &mailbox_fid);
+       if (retval != MAPISTORE_SUCCESS) {
+               return MAPISTORE_ERR_CORRUPTED;
+       }
+
+       retval = mapistore_getprops(mstore_ctx, context_id, mailbox_fid, MAPISTORE_FOLDER, &props, propvalues);
+       if ((retval != MAPISTORE_SUCCESS) || (propvalues->cValues != 1)) {
+               DEBUG(0, ("[%s] retval: %i (%s)\n", __FUNCTION__, retval, mapistore_errstr(retval)));
+               if (retval == MAPISTORE_SUCCESS) {
+                       DEBUG(0, ("[%s] number of values: %i\n", __FUNCTION__, propvalues->cValues));
+               }
+               talloc_free(mem_ctx);
+               return MAPISTORE_ERR_CORRUPTED;
+       }
+
+       memcpy(MailboxGUID, propvalues->lpProps[0].value.lpguid, sizeof(struct GUID));
+
+       return MAPISTORE_SUCCESS;
+}
+
+_PUBLIC_ enum MAPISTORE_ERROR mapistore_get_MailboxReplica(struct mapistore_context *mstore_ctx,
+                                                          const uint32_t context_id,
+                                                          uint16_t *ReplId, struct GUID *ReplGUID)
+{
+       struct SPropTagArray    props;
+       struct SRow             *propvalues;
+       TALLOC_CTX              *mem_ctx = 0;
+       uint64_t                mailbox_fid = 0;
+       enum MAPISTORE_ERROR    retval;
+
+       mem_ctx = talloc_init(NULL);
+
+       props.cValues = 2;
+       props.aulPropTag = talloc_zero_array(mem_ctx, enum MAPITAGS, props.cValues);
+       props.aulPropTag[0] = openchange_private_ReplicaID;
+       props.aulPropTag[1] = openchange_private_ReplicaGUID;
+
+       propvalues = talloc_zero(mem_ctx, struct SRow);
+        propvalues->cValues = 0;
+
+       retval = mapistore_get_context_fid(mstore_ctx, context_id, &mailbox_fid);
+       if (retval != MAPISTORE_SUCCESS) {
+               return MAPISTORE_ERR_CORRUPTED;
+       }
+
+       retval = mapistore_getprops(mstore_ctx, context_id, mailbox_fid, MAPISTORE_FOLDER, &props, propvalues);
+       if ((retval != MAPISTORE_SUCCESS) || (propvalues->cValues != 2)) {
+               DEBUG(0, ("[%s] retval: %i (%s)\n", __FUNCTION__, retval, mapistore_errstr(retval)));
+               if (retval == MAPISTORE_SUCCESS) {
+                       DEBUG(0, ("[%s] number of values: %i\n", __FUNCTION__, propvalues->cValues));
+               }
+               talloc_free(mem_ctx);
+               return MAPISTORE_ERR_CORRUPTED;
+       }
+
+       *ReplId = propvalues->lpProps[0].value.i;
+       memcpy(ReplGUID, propvalues->lpProps[1].value.lpguid, sizeof(struct GUID));
+
+       return MAPISTORE_SUCCESS;
+}
index 3139809e6c80694be9a663427445e24e6c4c022f..cf53241425a41c08e7068f07afd66256dbfd00a4 100644 (file)
@@ -177,9 +177,9 @@ struct mapistoredb_context {
        "PidTagParentFolderId: 0x0000000000000000\n"    \
        "PidTagFolderId: 0x%.16"PRIx64"\n"              \
        "cn: %s\n"                                      \
-       "MailboxGUID: %s\n"                             \
-       "ReplicaID: %s\n"                               \
-       "ReplicaGUID: %s\n"                             \
+       "openchange_private_MailboxGUID: %s\n"          \
+       "openchange_private_ReplicaID: %s\n"            \
+       "openchange_private_ReplicaGUID: %s\n"          \
        "mapistore_uri: mstoredb://CN=%s,%s\n\n"
 
 #define        MDB_MAILBOX_TMPL_URI    "mstoredb://CN=%s,%s"
index 45b8cc36b9dda6a974697bfd2fd0f4c64c3f909e..ec1e3a5232bbf3935e735f2c94a7f0f8114d3223 100644 (file)
@@ -128,16 +128,13 @@ static enum MAPISTATUS RopLogon_Mailbox(TALLOC_CTX *mem_ctx,
        /* Set ResponseFlags */
        response.LogonType.store_mailbox.ResponseFlags = ResponseFlags_Reserved | ResponseFlags_OwnerRight | ResponseFlags_SendAsRight;
 
-#if 0
-       /* TODO */
        /* Retrieve MailboxGuid */
-       mapistore_get_MailboxGuid(emsmdbp_ctx->mstore_ctx, recipient, &response.LogonType.store_mailbox.MailboxGuid);
+       mapistore_get_MailboxGuid(emsmdbp_ctx->mstore_ctx, context_id, &response.LogonType.store_mailbox.MailboxGuid);
 
        /* Retrieve mailbox replication information */
-       mapistore_get_MailboxReplica(emsmdbp_ctx->mstore_ctx, recipient,
+       mapistore_get_MailboxReplica(emsmdbp_ctx->mstore_ctx, context_id,
                                                 &response.LogonType.store_mailbox.ReplId,
                                                 &response.LogonType.store_mailbox.ReplGUID);
-#endif
 
        /* Set LogonTime both in openchange dispatcher database and reply */
        t = time(NULL);