Start of a C provisioning system, and some initial porting of
authorbradh <bradh@71d39326-ef09-db11-b2a4-00e04c779ad1>
Sat, 1 Jan 2011 06:13:09 +0000 (06:13 +0000)
committerbradh <bradh@71d39326-ef09-db11-b2a4-00e04c779ad1>
Sat, 1 Jan 2011 06:13:09 +0000 (06:13 +0000)
the emsmdb server to mapistore_v2.

git-svn-id: https://svn.openchange.org/openchange@2463 71d39326-ef09-db11-b2a4-00e04c779ad1

13 files changed:
branches/mapistore_v2/Makefile
branches/mapistore_v2/mapiproxy/libmapistore/database/mapistoredb.c
branches/mapistore_v2/mapiproxy/libmapistore/mapistore.h
branches/mapistore_v2/mapiproxy/libmapistore/mapistore_interface.c
branches/mapistore_v2/mapiproxy/libmapistore/tests/mapistore_provision.c [new file with mode: 0644]
branches/mapistore_v2/mapiproxy/libmapistore/tests/mapistore_test.c
branches/mapistore_v2/mapiproxy/servers/default/emsmdb/dcesrv_exchange_emsmdb.c
branches/mapistore_v2/mapiproxy/servers/default/emsmdb/dcesrv_exchange_emsmdb.h
branches/mapistore_v2/mapiproxy/servers/default/emsmdb/emsmdbp.c
branches/mapistore_v2/mapiproxy/servers/default/emsmdb/oxcstor.c
branches/mapistore_v2/pyopenchange/pymapistore.h
branches/mapistore_v2/pyopenchange/pymapistoredb.c
branches/mapistore_v2/pyopenchange/tests/mapistoredb_test.py

index 24f41bdf06bf272fafbb34a3030e4bd961074e17..7165404e22927cf0a68473f835c01f665321a8b7 100644 (file)
@@ -990,18 +990,24 @@ mapiproxy/libmapistore/backends/mapistore_mstoredb.$(SHLIBEXT): mapiproxy/libmap
 # mapistore test tools
 #######################
 
-mapistore_test: bin/mapistore_test
+mapistore_test: bin/mapistore_test bin/mapistore_provision
 
 bin/mapistore_test:    mapiproxy/libmapistore/tests/mapistore_test.o           \
                        mapiproxy/libmapistore.$(SHLIBEXT).$(PACKAGE_VERSION)
        @echo "Linking $@"
        @$(CC) -o $@ $^ $(LDFLAGS) $(LIBS) -lpopt -L. libmapi.$(SHLIBEXT).$(PACKAGE_VERSION)
 
+bin/mapistore_provision:       mapiproxy/libmapistore/tests/mapistore_provision.o           \
+                               mapiproxy/libmapistore.$(SHLIBEXT).$(PACKAGE_VERSION)
+       @echo "Linking $@"
+       @$(CC) -o $@ $^ $(LDFLAGS) $(LIBS) -lpopt -L. libmapi.$(SHLIBEXT).$(PACKAGE_VERSION)
+
 mapistoretest_clean:
        rm -f mapiproxy/libmapistore/tests/*.o
        rm -f mapiproxy/libmapistore/tests/*.gcno
        rm -f mapiproxy/libmapistore/tests/*.gcda
        rm -f bin/mapistore_test
+       rm -f bin/mapistore_provision
 
 clean:: mapistoretest_clean
 
index c7de3a6a3eabfaba4de7dd92248af86a27ecd66e..a8a0d196c60a2683b59b3df54b8a72d0b1157dab 100644 (file)
@@ -404,7 +404,7 @@ enum MAPISTORE_ERROR mapistoredb_new_mailbox(struct mapistoredb_context *mdb_ctx
        return MAPISTORE_SUCCESS;
 }
 
-
+#if 0
 /**
    \details Add a root folder to user mailbox
    
@@ -509,3 +509,4 @@ enum MAPISTORE_ERROR mapistoredb_add_mailbox_folder(struct mapistoredb_context *
 
        return MAPISTORE_SUCCESS;
 }
+#endif
index e58fed18ca7229ce10de0b3a775512a4828d9314..f43dcb2b41d0fe5063b851455cb37e3e956fa064 100644 (file)
@@ -163,6 +163,7 @@ struct indexing_folders_list {
 #define        MDB_JUNK_EMAIL          27
 #define        MDB_RSS_FEEDS           28
 #define        MDB_CONVERSATION_ACT    29
+#define MDB_LAST_SPECIALFOLDER MDB_CONVERSATION_ACT
 #define        MDB_CUSTOM              999
 
 struct mailbox_special_folder {
@@ -223,7 +224,7 @@ enum MAPISTORE_ERROR                mapistore_del_context(struct mapistore_context *, uint32_t
 enum MAPISTORE_ERROR           mapistore_release_record(struct mapistore_context *, uint32_t, uint64_t, uint8_t);
 enum MAPISTORE_ERROR           mapistore_search_context_by_uri(struct mapistore_context *, const char *, uint32_t *);
 const char*                    mapistore_errstr(enum MAPISTORE_ERROR);
-enum MAPISTORE_ERROR           mapistore_root_mkdir(struct mapistore_context *, uint32_t, uint32_t, const char *, const char *);
+enum MAPISTORE_ERROR           mapistore_root_mkdir(struct mapistore_context *, uint32_t, uint32_t, uint64_t, const char *, const char *);
 enum MAPISTORE_ERROR           mapistore_create_mapistoreURI(struct mapistore_context *, const char *, uint64_t *, char **);
 enum MAPISTORE_ERROR           mapistore_get_context_fid(struct mapistore_context *, uint32_t, uint64_t *);
 /* enum MAPISTORE_ERROR        mapistore_add_context_indexing(struct mapistore_context *, const char *, uint32_t); */
@@ -245,6 +246,7 @@ enum MAPISTORE_ERROR                mapistore_setprops(struct mapistore_context *, uint32_t, u
 enum MAPISTORE_ERROR           mapistore_get_child_fids(struct mapistore_context *, uint32_t, uint64_t, uint64_t **, uint32_t *);
 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_SystemFolderID(struct mapistore_context *mstore_ctx, char *recipient, uint32_t SystemIdx, uint64_t *FolderId);
 
 /* definitions from mapistore_processing.c */
 enum MAPISTORE_ERROR           mapistore_set_mapping_path(const char *);
@@ -273,8 +275,10 @@ enum MAPISTORE_ERROR               mapistoredb_provision_publicfolders(struct mapistoredb_con
 enum MAPISTORE_ERROR           mapistoredb_new_mailbox(struct mapistoredb_context *, const char *, uint32_t *);
 enum MAPISTORE_ERROR           mapistoredb_add_mailbox_default_folder(struct mapistoredb_context *, uint32_t,
                                                                       uint32_t, const char *, const char *);
+#if 0
 enum MAPISTORE_ERROR           mapistoredb_add_mailbox_folder(struct mapistoredb_context *, uint32_t, uint32_t,
                                                               const char *, const char *);
+#endif
 
 /* definitions from mapistoredb_conf.c */
 void                           mapistoredb_dump_conf(struct mapistoredb_context *);
index a18b7f89d83e53c72e8b630ed7fad321986388be..6deb58252be77c40b63f7ee7e2264b85cd2020cc 100644 (file)
@@ -580,6 +580,8 @@ static const char * mapistore_folder_name_from_index(const uint32_t index)
    \param context_id the context identifier referencing the backend
    where the root directory will be created
    \param index the indexing referencing this system/special folder
+   \param parent_fid parent Folder ID for the new folder. Pass 0 to add below
+   the root of the context.
    \param name optional name to be used instead of the default one
    \param uri the optional mapistore uri to use for this folder
 
@@ -588,13 +590,13 @@ static const char * mapistore_folder_name_from_index(const uint32_t index)
 _PUBLIC_ enum MAPISTORE_ERROR mapistore_root_mkdir(struct mapistore_context *mstore_ctx,
                                                   uint32_t context_id,
                                                   uint32_t index,
+                                                  uint64_t parent_fid,
                                                   const char *name,
                                                   const char *mapistore_uri)
 {
        struct backend_context  *backend_ctx;
        enum MAPISTORE_ERROR    ret;
        uint64_t                fid;
-       uint64_t                parent_fid;
 
        /* Sanity checks */
        MAPISTORE_SANITY_CHECKS(mstore_ctx, NULL);
@@ -604,11 +606,13 @@ _PUBLIC_ enum MAPISTORE_ERROR mapistore_root_mkdir(struct mapistore_context *mst
        MAPISTORE_RETVAL_IF(!backend_ctx, MAPISTORE_ERR_INVALID_PARAMETER, NULL);
        DEBUG(8, ("[%s] backend_ctx is %s (%s)\n", __FUNCTION__, backend_ctx->uri, backend_ctx->username));
 
-       /* Retrieve the parent fid matching the context */
-       mapistore_get_context_fid(mstore_ctx, context_id, &parent_fid);
-       DEBUG(4, ("[%s] context FID: 0x%016"PRIx64"\n", __FUNCTION__, parent_fid));
+       if (parent_fid == 0) {
+               /* Retrieve the parent fid matching the context */
+               mapistore_get_context_fid(mstore_ctx, context_id, &parent_fid);
+               DEBUG(4, ("[%s] context FID: 0x%016"PRIx64"\n", __FUNCTION__, parent_fid));
+       }
 
-       /* Generate a fid for this folder */
+       /* Generate a new fid for this folder */
        mapistore_get_next_fmid(mstore_ctx, &fid);
 
        /* Fill in the name if not provided */
@@ -1240,3 +1244,24 @@ finish:
        talloc_free(mem_ctx);
        return ret;
 }
+
+/**
+   \details Retrieve the mailbox FolderID for given recipient from
+   mapistore database
+
+   \param mstore_ctx pointer to the mapistore context
+   \param recipient the mailbox username
+   \param SystemIdx the system folder index
+   \param FolderId pointer to the folder identifier that the function returns
+
+   \return MAPI_E_SUCCESS on success, otherwise MAPI error
+ */
+_PUBLIC_ enum MAPISTORE_ERROR mapistore_get_SystemFolderID(struct mapistore_context *mstore_ctx,
+                                                          char *recipient, uint32_t SystemIdx,
+                                                          uint64_t *FolderId)
+{
+       // TODO: this is just a stub implementation.
+       *FolderId = 0xDEADBEEF;
+
+       return MAPI_E_SUCCESS;
+}
diff --git a/branches/mapistore_v2/mapiproxy/libmapistore/tests/mapistore_provision.c b/branches/mapistore_v2/mapiproxy/libmapistore/tests/mapistore_provision.c
new file mode 100644 (file)
index 0000000..4a7af7e
--- /dev/null
@@ -0,0 +1,327 @@
+/*
+   OpenChange Storage Abstraction Layer library test tool
+
+   OpenChange Project
+
+   Copyright (C) Julien Kerihuel 2009
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "mapiproxy/libmapistore/mapistore.h"
+/* TODO: we shouldn't need to do this... */
+#include "mapiproxy/libmapistore/mapistore_private.h"
+#include <talloc.h>
+#include <core/ntstatus.h>
+#include <samba/popt.h>
+#include <param.h>
+#include <util/debug.h>
+
+/**
+   \file mapistore_provision.c
+
+   \brief Demo mapistore provisioning
+ */
+
+/* TODO: the path probably should be a parameter */
+static int do_initialisation(TALLOC_CTX *mem_ctx)
+{
+       struct mapistoredb_context      *mstoredb_ctx;
+       enum MAPISTORE_ERROR            retval;
+
+       // TODO: perhaps we should init() in the main() function
+       // TODO: probably need to mkdir if it doesn't already exist
+       mstoredb_ctx = mapistoredb_init(mem_ctx, "/usr/local/samba/private/mapistore");
+       if (mstoredb_ctx == NULL) {
+               DEBUG(0, ("mapistoredb_init returned NULL\n"));
+               return -1;
+       }
+
+       retval = mapistoredb_provision(mstoredb_ctx);
+       if (retval != MAPISTORE_SUCCESS) {
+               DEBUG(0, ("mapistoredb_provision() returned %i (%s)\n", retval, mapistore_errstr(retval)));
+               return -2;
+       }
+
+       mapistoredb_release(mstoredb_ctx);
+       
+       return 0;
+}
+
+static void add_special_folders(struct mapistore_context *mstore_ctx, uint32_t context_id, uint64_t root_fid)
+{
+       int                     i = 0;
+       enum MAPISTORE_ERROR    retval;
+       uint64_t                index_to_fid_map[MDB_LAST_SPECIALFOLDER + 1];
+
+       for (i = 0; mailbox_special_folders[i].name != NULL; ++i) {
+               if (mailbox_special_folders[i].parent_specialindex == MDB_ROOT_FOLDER) {
+                       retval = mapistore_root_mkdir(mstore_ctx, context_id, mailbox_special_folders[i].index, root_fid, NULL, NULL);
+                       if (retval != MAPISTORE_SUCCESS) {
+                               DEBUG(0, ("mapistore_root_mkdir() for %s returned %i (%s)\n", mailbox_special_folders[i].name, retval, mapistore_errstr(retval)));
+                               return;
+                       }
+                       mapistore_get_fid_by_name(mstore_ctx, context_id, root_fid, mailbox_special_folders[i].name,
+                                                       &(index_to_fid_map[mailbox_special_folders[i].index]));
+                       if (retval != MAPISTORE_SUCCESS) {
+                               DEBUG(0, ("mapistore_get_fid_by_name for %s returned %i (%s)\n", mailbox_special_folders[i].name, retval, mapistore_errstr(retval)));
+                               return;
+                       }
+               } else {
+                       retval = mapistore_root_mkdir(mstore_ctx, context_id, mailbox_special_folders[i].index,
+                                                     index_to_fid_map[mailbox_special_folders[i].parent_specialindex],
+                                                     NULL, NULL);
+                       if (retval != MAPISTORE_SUCCESS) {
+                               DEBUG(0, ("mapistore_root_mkdir() for %s returned %i (%s)\n", mailbox_special_folders[i].name, retval, mapistore_errstr(retval)));
+                               return;
+                       }
+                       mapistore_get_fid_by_name(mstore_ctx, context_id, index_to_fid_map[mailbox_special_folders[i].parent_specialindex],
+                                                 mailbox_special_folders[i].name, &(index_to_fid_map[mailbox_special_folders[i].index]));
+                       if (retval != MAPISTORE_SUCCESS) {
+                               DEBUG(0, ("mapistore_get_fid_by_name for %s returned %i (%s)\n", mailbox_special_folders[i].name, retval, mapistore_errstr(retval)));
+                               return;
+                       }
+               }
+       }
+}
+
+static int do_user_mailbox(TALLOC_CTX *mem_ctx, const char *username)
+{
+       struct mapistoredb_context      *mstoredb_ctx;
+       enum MAPISTORE_ERROR            retval;
+       uint32_t                        mailbox_context_id = 0;
+       uint64_t                        mailbox_root_fid = 0;
+
+       mstoredb_ctx = mapistoredb_init(mem_ctx, "/usr/local/samba/private/mapistore");
+       if (mstoredb_ctx == NULL) {
+               DEBUG(0, ("mapistoredb_init returned NULL\n"));
+               return -1;
+       }
+
+       retval = mapistoredb_new_mailbox(mstoredb_ctx, username, &mailbox_context_id);
+       if (retval != MAPISTORE_SUCCESS) {
+               DEBUG(0, ("mapistoredb_new_mailbox() returned %i (%s)\n", retval, mapistore_errstr(retval)));
+               return -2;
+       }
+       DEBUG(3, ("%s context ID: 0x%x\n", username, mailbox_context_id));
+
+       retval = mapistore_get_fid_by_name(mstoredb_ctx->mstore_ctx, mailbox_context_id, 0, username, &mailbox_root_fid); 
+       if (retval != MAPISTORE_SUCCESS) {
+               DEBUG(0, ("mapistore_get_fid_by_name() on %s root folder returned %i (%s)\n", username, retval, mapistore_errstr(retval)));
+               return -3;
+       }
+       DEBUG(3, ("%s root folder has fid: 0x%016"PRIx64"\n", username, mailbox_root_fid));
+
+       add_special_folders(mstoredb_ctx->mstore_ctx, mailbox_context_id, mailbox_root_fid);
+
+       mapistoredb_release(mstoredb_ctx);
+
+       return 0;
+
+}
+
+int main(int argc, const char *argv[])
+{
+       TALLOC_CTX                      *mem_ctx;
+       struct loadparm_context         *lp_ctx;
+       poptContext                     pc;
+       int                             opt;
+       const char                      *opt_debug = NULL;
+       bool                            opt_init = false;
+       const char                      *opt_mailbox = NULL;
+#if 0
+       uint32_t                        mailbox2_context_id = 0;
+       uint64_t                        testuser2_fid = 0;
+       uint64_t                        jk_fid = 0;
+       uint32_t                        testuser2_folder_count = 0;
+       uint32_t                        jk_folder_count = 0;
+       uint64_t                        planning_subfolder_fid = 0;
+       struct SRow                     planning_subfolder_props;
+#endif
+       enum { OPT_DEBUG=1000, OPT_INIT, OPT_MAILBOX };
+
+       struct poptOption long_options[] = {
+               POPT_AUTOHELP
+               { "init", 'i', POPT_ARG_NONE, NULL, OPT_INIT, "initialise the database", NULL },
+               { "mailbox", 'm', POPT_ARG_STRING, NULL, OPT_MAILBOX, "create a user mailbox", NULL },
+               { "debuglevel", 'd', POPT_ARG_STRING, NULL, OPT_DEBUG,  "set the debug level", NULL },
+               { NULL, 0, 0, NULL, 0, NULL, NULL }
+       };
+
+       /* TODO : chase down the leaks reported by this */
+       // talloc_enable_leak_report_full();
+       mem_ctx = talloc_named(NULL, 0, "mapistore_test");
+       lp_ctx = loadparm_init(mem_ctx);
+       lpcfg_load_default(lp_ctx);
+       setup_logging(NULL, DEBUG_STDOUT);
+       
+       pc = poptGetContext("mapistore_test", argc, argv, long_options, 0);
+       while ((opt = poptGetNextOpt(pc)) != -1) {
+               switch (opt) {
+               case OPT_DEBUG:
+                       opt_debug = poptGetOptArg(pc);
+                       break;
+               case OPT_INIT:
+                       opt_init = true;
+                       break;
+               case OPT_MAILBOX:
+                       opt_mailbox = poptGetOptArg(pc);
+                       break;
+               }
+       }
+
+       poptFreeContext(pc);
+
+       if (opt_debug) {
+               lpcfg_set_cmdline(lp_ctx, "log level", opt_debug);
+       }
+
+       if (opt_init) {
+               do_initialisation(mem_ctx);
+       }
+       
+       if (opt_mailbox) {
+               do_user_mailbox(mem_ctx, opt_mailbox);
+       }
+
+#if 0
+       // TODO: more features we could add....
+
+       retval = mapistoredb_set_netbiosname(mstoredb_ctx, "nbname");
+       if (retval != MAPISTORE_SUCCESS) {
+               DEBUG(0, ("mapistoredb_set_netbiosname() returned %i (%s)\n", retval, mapistore_errstr(retval)));
+               exit(1);
+       }
+
+
+
+       retval = mapistoredb_provision_publicfolders(mstoredb_ctx);
+       if (retval != MAPISTORE_SUCCESS) {
+               DEBUG(0, ("mapistoredb_provision_publicfolders() returned %i (%s)\n", retval, mapistore_errstr(retval)));
+               exit(1);
+       }
+
+       retval = mapistoredb_new_mailbox(mstoredb_ctx, "testuser1", &mailbox1_context_id);
+       if (retval != MAPISTORE_SUCCESS) {
+               DEBUG(0, ("mapistoredb_new_mailbox() returned %i (%s)\n", retval, mapistore_errstr(retval)));
+               exit(1);
+       }
+       DEBUG(2, ("testuser1 context ID: 0x%x\n", mailbox1_context_id));
+
+       retval = mapistoredb_new_mailbox(mstoredb_ctx, "testuser2", &mailbox2_context_id);
+       if (retval != MAPISTORE_SUCCESS) {
+               DEBUG(0, ("mapistoredb_new_mailbox() returned %i (%s)\n", retval, mapistore_errstr(retval)));
+               exit(1);
+       }
+       DEBUG(2, ("testuser2 context ID: 0x%x\n", mailbox2_context_id));
+
+       /* try adding the default Outbox folder */
+       retval = mapistore_root_mkdir(mstoredb_ctx->mstore_ctx, mailbox2_context_id, MDB_OUTBOX, NULL, NULL);
+       if (retval != MAPISTORE_SUCCESS) {
+               DEBUG(0, ("mapistore_root_mkdir() returned %i (%s)\n", retval, mapistore_errstr(retval)));
+               exit(1);
+       }
+
+       /* try adding the Journal folder with a non-standard name*/
+       retval = mapistore_root_mkdir(mstoredb_ctx->mstore_ctx, mailbox2_context_id, MDB_JOURNAL, "MyJournal", NULL);
+       if (retval != MAPISTORE_SUCCESS) {
+               DEBUG(0, ("mapistore_root_mkdir() returned %i (%s)\n", retval, mapistore_errstr(retval)));
+               exit(1);
+       }
+
+       /* try an adding a folder with the fsocpf backend */
+       retval = mapistore_root_mkdir(mstoredb_ctx->mstore_ctx, mailbox2_context_id, MDB_IPM_SUBTREE, "MyMessages", "fsocpf://tmp/testuser2/mymessages");
+       if (retval != MAPISTORE_SUCCESS) {
+               DEBUG(0, ("mapistore_root_mkdir() returned %i (%s)\n", retval, mapistore_errstr(retval)));
+               exit(1);
+       }
+
+       /* try adding a generic folder */
+       retval = mapistore_root_mkdir(mstoredb_ctx->mstore_ctx, mailbox2_context_id, MDB_CUSTOM, "From Julien", NULL);
+       if (retval != MAPISTORE_SUCCESS) {
+               DEBUG(0, ("mapistore_root_mkdir() for generic folder returned %i (%s)\n", retval, mapistore_errstr(retval)));
+               exit(1);
+       }
+
+       /* try opening the testuser2 root folder */
+       /* TODO consider whether we really want a hack like fid == 0 means open root folder for this context */
+       retval = mapistore_opendir(mstoredb_ctx->mstore_ctx, mailbox2_context_id, 0, 0); 
+       if (retval != MAPISTORE_SUCCESS) {
+               DEBUG(0, ("mapistore_opendir() on root folder returned %i (%s)\n", retval, mapistore_errstr(retval)));
+               exit(1);
+       }
+
+       retval = mapistore_get_fid_by_name(mstoredb_ctx->mstore_ctx, mailbox2_context_id, 0, "testuser2", &testuser2_fid); 
+       if (retval != MAPISTORE_SUCCESS) {
+               DEBUG(0, ("mapistore_get_fid_by_name() on testuser2 root folder returned %i (%s)\n", retval, mapistore_errstr(retval)));
+               exit(1);
+       }
+       DEBUG(0, ("testuser2 root folder has fid: 0x%016"PRIx64"\n", jk_fid));
+
+       retval = mapistore_get_fid_by_name(mstoredb_ctx->mstore_ctx, mailbox2_context_id, testuser2_fid, "From Julien", &jk_fid); 
+       if (retval != MAPISTORE_SUCCESS) {
+               DEBUG(0, ("mapistore_opendir() on root folder returned %i (%s)\n", retval, mapistore_errstr(retval)));
+               exit(1);
+       }
+       DEBUG(0, ("\"From Julien\" folder has fid: 0x%016"PRIx64"\n", jk_fid));
+
+       retval = mapistore_get_folder_count(mstoredb_ctx->mstore_ctx, mailbox2_context_id, testuser2_fid, &testuser2_folder_count);
+       if (retval != MAPISTORE_SUCCESS) {
+               DEBUG(0, ("mapistore_get_folder_count() on root folder returned %i (%s)\n", retval, mapistore_errstr(retval)));
+               exit(1);
+       }
+       DEBUG(0, ("testuser2 root folder has %i subfolders\n", testuser2_folder_count));
+
+       retval = mapistore_get_folder_count(mstoredb_ctx->mstore_ctx, mailbox2_context_id, jk_fid, &jk_folder_count);
+       if (retval != MAPISTORE_SUCCESS) {
+               DEBUG(0, ("mapistore_get_folder_count() on \"From Julien\" folder returned %i (%s)\n", retval, mapistore_errstr(retval)));
+               exit(1);
+       }
+       DEBUG(0, ("\"From Julien\" folder has %i subfolder(s)\n", jk_folder_count));
+
+       retval = mapistore_get_next_fmid(mstoredb_ctx->mstore_ctx, &planning_subfolder_fid);
+       if (retval != MAPISTORE_SUCCESS) {
+               DEBUG(0, ("mapistore_get_next_fmid() returned %i (%s)\n", retval, mapistore_errstr(retval)));
+               exit(1);
+       }
+       DEBUG(0, ("\"Planning January 2011\" subfolder will use FID: 0x%016"PRIx64"\n", planning_subfolder_fid));
+
+       planning_subfolder_props.cValues = 1;
+       planning_subfolder_props.lpProps = talloc_zero_array(mem_ctx, struct SPropValue, planning_subfolder_props.cValues);
+       planning_subfolder_props.lpProps[0].ulPropTag = PR_DISPLAY_NAME;
+       planning_subfolder_props.lpProps[0].value.lpszA = "Planning January 2011";
+
+       retval = mapistore_mkdir(mstoredb_ctx->mstore_ctx, mailbox2_context_id, jk_fid, planning_subfolder_fid, &planning_subfolder_props);
+       if (retval != MAPISTORE_SUCCESS) {
+               DEBUG(0, ("mapistore_mkdir() on planning subfolder returned %i (%s)\n", retval, mapistore_errstr(retval)));
+               exit(1);
+       }
+       DEBUG(0, ("Created \"Planning January 2011\" subfolder under \"From Julien\" subfolder\n"));
+
+       retval = mapistore_get_folder_count(mstoredb_ctx->mstore_ctx, mailbox2_context_id, jk_fid, &jk_folder_count);
+       if (retval != MAPISTORE_SUCCESS) {
+               DEBUG(0, ("mapistore_get_folder_count() on \"From Julien\" folder returned %i (%s)\n", retval, mapistore_errstr(retval)));
+               exit(1);
+       }
+       DEBUG(0, ("\"From Julien\" folder now has %i subfolder(s)\n", jk_folder_count));
+       
+       /* TODO: clean up mailbox contexts */
+
+#endif
+
+       talloc_free(lp_ctx);
+       talloc_report(mem_ctx, stdout);
+       talloc_free(mem_ctx);
+       return 0;
+}
index a505c283c723d3edb6fa06bb5539b94c19f4899b..63e82d95ae0934418af93f62d3719b2c85ad9cee 100644 (file)
@@ -122,28 +122,28 @@ int main(int argc, const char *argv[])
        DEBUG(2, ("testuser2 context ID: 0x%x\n", mailbox2_context_id));
 
        /* try adding the default Outbox folder */
-       retval = mapistore_root_mkdir(mstoredb_ctx->mstore_ctx, mailbox2_context_id, MDB_OUTBOX, NULL, NULL);
+       retval = mapistore_root_mkdir(mstoredb_ctx->mstore_ctx, mailbox2_context_id, MDB_OUTBOX, 0, NULL, NULL);
        if (retval != MAPISTORE_SUCCESS) {
                DEBUG(0, ("mapistore_root_mkdir() returned %i (%s)\n", retval, mapistore_errstr(retval)));
                exit(1);
        }
 
        /* try adding the Journal folder with a non-standard name*/
-       retval = mapistore_root_mkdir(mstoredb_ctx->mstore_ctx, mailbox2_context_id, MDB_JOURNAL, "MyJournal", NULL);
+       retval = mapistore_root_mkdir(mstoredb_ctx->mstore_ctx, mailbox2_context_id, MDB_JOURNAL, 0, "MyJournal", NULL);
        if (retval != MAPISTORE_SUCCESS) {
                DEBUG(0, ("mapistore_root_mkdir() returned %i (%s)\n", retval, mapistore_errstr(retval)));
                exit(1);
        }
 
        /* try an adding a folder with the fsocpf backend */
-       retval = mapistore_root_mkdir(mstoredb_ctx->mstore_ctx, mailbox2_context_id, MDB_IPM_SUBTREE, "MyMessages", "fsocpf://tmp/testuser2/mymessages");
+       retval = mapistore_root_mkdir(mstoredb_ctx->mstore_ctx, mailbox2_context_id, MDB_IPM_SUBTREE, 0, "MyMessages", "fsocpf://tmp/testuser2/mymessages");
        if (retval != MAPISTORE_SUCCESS) {
                DEBUG(0, ("mapistore_root_mkdir() returned %i (%s)\n", retval, mapistore_errstr(retval)));
                exit(1);
        }
 
        /* try adding a generic folder */
-       retval = mapistore_root_mkdir(mstoredb_ctx->mstore_ctx, mailbox2_context_id, MDB_CUSTOM, "From Julien", NULL);
+       retval = mapistore_root_mkdir(mstoredb_ctx->mstore_ctx, mailbox2_context_id, MDB_CUSTOM, 0, "From Julien", NULL);
        if (retval != MAPISTORE_SUCCESS) {
                DEBUG(0, ("mapistore_root_mkdir() for generic folder returned %i (%s)\n", retval, mapistore_errstr(retval)));
                exit(1);
index e5b3d7d71808deb5f03c31dd5ba43d2b87a81761..b96659a46313976b77d2acb6322417a1dd187107 100644 (file)
@@ -92,7 +92,7 @@ static enum MAPISTATUS dcesrv_EcDoConnect(struct dcesrv_call_state *dce_call,
        /* Step 1. Initialize the emsmdbp context */
        emsmdbp_ctx = emsmdbp_init(dce_call->conn->dce_ctx->lp_ctx, 
                                   dce_call->context->conn->auth_state.session_info->server_info->account_name,
-                                  openchange_ldb_ctx);
+                                  0);
        if (!emsmdbp_ctx) {
                smb_panic("unable to initialize emsmdbp context");
                OPENCHANGE_RETVAL_IF(!emsmdbp_ctx, MAPI_E_FAILONEPROVIDER, NULL);
@@ -1126,13 +1126,13 @@ static NTSTATUS dcesrv_exchange_emsmdb_init(struct dcesrv_context *dce_ctx)
        emsmdb_session = talloc_zero(dce_ctx, struct exchange_emsmdb_session);
        if (!emsmdb_session) return NT_STATUS_NO_MEMORY;
        emsmdb_session->session = NULL;
-
+#if 0
        /* Open read/write context on OpenChange dispatcher database */
        openchange_ldb_ctx = emsmdbp_openchange_ldb_init(dce_ctx->lp_ctx);
        if (!openchange_ldb_ctx) {
                smb_panic("unable to initialize 'openchange.ldb' context");
        }
-
+#endif
        return NT_STATUS_OK;
 }
 
index 99e493a40194ef7707d2f414e75c1753bbb1a758..328e14ab3b7eb0a98730648d43b848cbcb3e4af5 100644 (file)
@@ -42,6 +42,7 @@
 #endif
 #endif
 
+/* TODO: remove the oc_ctx */
 struct emsmdbp_context {
        char                            *szUserDN;
        char                            *szDisplayName;
index 850a778e860054a334af33cba4873302298832f4..eb0634ba174654f107599ca451b40b1810707875 100644 (file)
@@ -77,6 +77,7 @@ static int emsmdbp_mapi_handles_destructor(void *data)
    \return Allocated emsmdbp_context pointer on success, otherwise
    NULL
  */
+/* TODO: remove ldb context argument */
 _PUBLIC_ struct emsmdbp_context *emsmdbp_init(struct loadparm_context *lp_ctx,
                                              const char *username,
                                              void *ldb_ctx)
index fda37f827f9f81da85ed51b68a8f0398d07c5783..50226a59dc6a767551c8024842d9c0ddfe2548ee 100644 (file)
@@ -49,7 +49,7 @@ static enum MAPISTATUS RopLogon_Mailbox(TALLOC_CTX *mem_ctx,
                                        struct EcDoRpc_MAPI_REQ *mapi_req,
                                        struct EcDoRpc_MAPI_REPL *mapi_repl)
 {
-       enum MAPISTATUS         retval;
+       // enum MAPISTATUS              retval;
        char                    *recipient;
        struct Logon_req        request;
        struct Logon_repl       response;
@@ -75,30 +75,34 @@ static enum MAPISTATUS RopLogon_Mailbox(TALLOC_CTX *mem_ctx,
        response.LogonFlags = request.LogonFlags;
 
        /* Step 3. Build FolderIds list */
-       retval = openchangedb_get_SystemFolderID(emsmdbp_ctx->oc_ctx, recipient, EMSMDBP_MAILBOX_ROOT, &response.LogonType.store_mailbox.FolderIds[0]);
-       retval = openchangedb_get_SystemFolderID(emsmdbp_ctx->oc_ctx, recipient, EMSMDBP_DEFERRED_ACTIONS, &response.LogonType.store_mailbox.FolderIds[1]);
-       retval = openchangedb_get_SystemFolderID(emsmdbp_ctx->oc_ctx, recipient, EMSMDBP_SPOOLER_QUEUE, &response.LogonType.store_mailbox.FolderIds[2]);
-       retval = openchangedb_get_SystemFolderID(emsmdbp_ctx->oc_ctx, recipient, EMSMDBP_TOP_INFORMATION_STORE, &response.LogonType.store_mailbox.FolderIds[3]);
-       retval = openchangedb_get_SystemFolderID(emsmdbp_ctx->oc_ctx, recipient, EMSMDBP_INBOX, &response.LogonType.store_mailbox.FolderIds[4]);
-       retval = openchangedb_get_SystemFolderID(emsmdbp_ctx->oc_ctx, recipient, EMSMDBP_OUTBOX, &response.LogonType.store_mailbox.FolderIds[5]);
-       retval = openchangedb_get_SystemFolderID(emsmdbp_ctx->oc_ctx, recipient, EMSMDBP_SENT_ITEMS, &response.LogonType.store_mailbox.FolderIds[6]);
-       retval = openchangedb_get_SystemFolderID(emsmdbp_ctx->oc_ctx, recipient, EMSMDBP_DELETED_ITEMS, &response.LogonType.store_mailbox.FolderIds[7]);
-       retval = openchangedb_get_SystemFolderID(emsmdbp_ctx->oc_ctx, recipient, EMSMDBP_COMMON_VIEWS, &response.LogonType.store_mailbox.FolderIds[8]);
-       retval = openchangedb_get_SystemFolderID(emsmdbp_ctx->oc_ctx, recipient, EMSMDBP_SCHEDULE, &response.LogonType.store_mailbox.FolderIds[9]);
-       retval = openchangedb_get_SystemFolderID(emsmdbp_ctx->oc_ctx, recipient, EMSMDBP_SEARCH, &response.LogonType.store_mailbox.FolderIds[10]);
-       retval = openchangedb_get_SystemFolderID(emsmdbp_ctx->oc_ctx, recipient, EMSMDBP_VIEWS, &response.LogonType.store_mailbox.FolderIds[11]);
-       retval = openchangedb_get_SystemFolderID(emsmdbp_ctx->oc_ctx, recipient, EMSMDBP_SHORTCUTS, &response.LogonType.store_mailbox.FolderIds[12]);
-
+       mapistore_get_SystemFolderID(emsmdbp_ctx->mstore_ctx, recipient, MDB_ROOT_FOLDER, &response.LogonType.store_mailbox.FolderIds[0]);
+       mapistore_get_SystemFolderID(emsmdbp_ctx->mstore_ctx, recipient, MDB_DEFERRED_ACTIONS, &response.LogonType.store_mailbox.FolderIds[1]);
+       mapistore_get_SystemFolderID(emsmdbp_ctx->mstore_ctx, recipient, MDB_SPOOLER_QUEUE, &response.LogonType.store_mailbox.FolderIds[2]);
+       mapistore_get_SystemFolderID(emsmdbp_ctx->mstore_ctx, recipient, MDB_IPM_SUBTREE, &response.LogonType.store_mailbox.FolderIds[3]);
+       mapistore_get_SystemFolderID(emsmdbp_ctx->mstore_ctx, recipient, MDB_INBOX, &response.LogonType.store_mailbox.FolderIds[4]);
+       mapistore_get_SystemFolderID(emsmdbp_ctx->mstore_ctx, recipient, MDB_OUTBOX, &response.LogonType.store_mailbox.FolderIds[5]);
+       mapistore_get_SystemFolderID(emsmdbp_ctx->mstore_ctx, recipient, MDB_SENT_ITEMS, &response.LogonType.store_mailbox.FolderIds[6]);
+       mapistore_get_SystemFolderID(emsmdbp_ctx->mstore_ctx, recipient, MDB_DELETED_ITEMS, &response.LogonType.store_mailbox.FolderIds[7]);
+       mapistore_get_SystemFolderID(emsmdbp_ctx->mstore_ctx, recipient, MDB_COMMON_VIEWS, &response.LogonType.store_mailbox.FolderIds[8]);
+       mapistore_get_SystemFolderID(emsmdbp_ctx->mstore_ctx, recipient, MDB_SCHEDULE, &response.LogonType.store_mailbox.FolderIds[9]);
+       mapistore_get_SystemFolderID(emsmdbp_ctx->mstore_ctx, recipient, MDB_SEARCH, &response.LogonType.store_mailbox.FolderIds[10]);
+       mapistore_get_SystemFolderID(emsmdbp_ctx->mstore_ctx, recipient, MDB_VIEWS, &response.LogonType.store_mailbox.FolderIds[11]);
+       mapistore_get_SystemFolderID(emsmdbp_ctx->mstore_ctx, recipient, MDB_SHORTCUTS, &response.LogonType.store_mailbox.FolderIds[12]);
+
+       DEBUG(0, ("[%s] Finished with system folder ids: 0x%016"PRIx64"\n", __FUNCTION__, response.LogonType.store_mailbox.FolderIds[0]));
        /* Step 4. Set ResponseFlags */
        response.LogonType.store_mailbox.ResponseFlags = ResponseFlags_Reserved | ResponseFlags_OwnerRight | ResponseFlags_SendAsRight;
 
+#if 0
+       /* TODO */
        /* Step 5. Retrieve MailboxGuid */
-       retval = openchangedb_get_MailboxGuid(emsmdbp_ctx->oc_ctx, recipient, &response.LogonType.store_mailbox.MailboxGuid);
+       mapistore_get_MailboxGuid(emsmdbp_ctx->mstore_ctx, recipient, &response.LogonType.store_mailbox.MailboxGuid);
 
        /* Step 6. Retrieve mailbox replication information */
-       retval = openchangedb_get_MailboxReplica(emsmdbp_ctx->oc_ctx, recipient,
+       mapistore_get_MailboxReplica(emsmdbp_ctx->mstore_ctx, recipient,
                                                 &response.LogonType.store_mailbox.ReplId,
                                                 &response.LogonType.store_mailbox.ReplGUID);
+#endif
 
        /* Step 7. Set LogonTime both in openchange dispatcher database and reply */
        t = time(NULL);
index ef370e8db18b1ed63714f5f61d31bc2246f86297..648bb6e31a30e0ece672a131466030e4203abee5 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <Python.h>
 #include "mapiproxy/libmapistore/mapistore.h"
+#include "mapiproxy/libmapistore/mapistore_private.h"
 
 typedef struct {
        PyObject_HEAD
index 3de5b24c9af0b095f57d6c26fd52a60098c1ec88..074c3872950ed3a58c1ae82cff5b3d4e1cc137b7 100644 (file)
@@ -112,8 +112,7 @@ static PyObject *py_MAPIStoreDB_newdefaultfolder(PyMAPIStoreDBObject *self, PyOb
        DEBUG(0, ("[py_MAPIStoreDB_newdefaultdolder] name = %s\n", name));
        DEBUG(0, ("[py_MAPIStoreDB_newdefaultdolder] mapistore_uri = %s\n", mapistore_uri));
 
-       return PyInt_FromLong(mapistoredb_add_mailbox_folder(self->mdb_ctx, contextID, index,
-                                                            name, mapistore_uri));
+       return PyInt_FromLong(mapistore_root_mkdir(self->mdb_ctx->mstore_ctx, contextID, index, 0, name, mapistore_uri));
 }
 
 static int PyMAPIStoreDB_setParameter(PyObject *_self, PyObject *value, void *data)
index 7c04303eeedbbf2aa8a989a6fba677c02df09d38..9b5ce34662d4321427d7888a6c7133eee7e065e0 100755 (executable)
@@ -8,6 +8,8 @@ sys.path.append("python")
 import os
 import openchange
 import openchange.mapistoredb as mapistoredb
+import openchange.mapistore as mapistore
+from openchange import mapi
 
 os.mkdir("/tmp/mapistoredb");
 
@@ -75,3 +77,17 @@ print ""
 print "D. Create a new system/special default folder"
 print "---------------------------------------------"
 MAPIStoreDB.newdefaultfolder(contextID, mapistoredb.IPM_SUBTREE, "test", "mstoredb://")
+
+print "[Step 7]. Testing mapistore tie-in"
+print "=================================="
+
+print "A. Testing mkdir"
+MAPIStore = mapistore.mapistore()
+mapistore.set_mapping_path("/tmp/mapistore")
+ctx_id = MAPIStore.add_context("openchange", "mstoredb://CN=openchange2,CN=OpenChange Development Unit,CN=OpenChange Project,CN=server,CN=kubuntu1010")
+SPropValue = mapi.SPropValue()
+SPropValue.add(mapi.PR_PARENT_FID, 0x0000000000035001)
+SPropValue.add(mapi.PR_DISPLAY_NAME, "test")
+SPropValue.add(mapi.PR_COMMENT, "test folder")
+SPropValue.add(mapi.PR_FOLDER_TYPE, 1)
+MAPIStore.mkdir(contextID2, 0x0000000000035001, 0x0000000000036001, SPropValue)