#include "mapistore_mstoredb.h"
#include <string.h>
+#include <assert.h>
/**
\details Initialize mstoredb mapistore backend
const char * const folder_attrs[] = { "*", NULL };
int ret;
int i = 0;
- struct SPropValue prop;
DEBUG(5, ("[%s:%d]\n", __FUNCTION__, __LINE__));
}
/* 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);
}
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;
+}
/* 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);