- Move named properties database provisioning out of mapistore_init()
authorJulien Kerihuel <j.kerihuel@openchange.org>
Thu, 3 Feb 2011 16:36:44 +0000 (16:36 +0000)
committerJulien Kerihuel <j.kerihuel@openchange.org>
Thu, 3 Feb 2011 16:36:44 +0000 (16:36 +0000)
- Only create it through mapistoredb at provisioning time

- Add an interface in libmapistore/database to provision named
  properties and add associated python bindings and working code
  example within pyopenchange/tests/provision.py

- Remove deprecated code from mparse.pl for known and named property tags

- Add a convenient function in mapistore_processing.c to provision a
  LDB database using a LDIF file

- Add database schema and ROOTDSE to mapi_named_properties.ldb
  database

- Add MAPISTORE_ERR_NOT_IMPLEMENTED error code to the MAPISTORE_ERROR
  enum

- Replace some existing DEBUG macros with MSTORE_DEBUG_ equivalent

14 files changed:
Makefile
config.mk.in
libmapi/conf/build.sh
libmapi/conf/mparse.pl
mapiproxy/libmapistore/database/mapistoredb.c
mapiproxy/libmapistore/database/mapistoredb_namedprops.c [new file with mode: 0644]
mapiproxy/libmapistore/mapistore.h
mapiproxy/libmapistore/mapistore_errors.h
mapiproxy/libmapistore/mapistore_interface.c
mapiproxy/libmapistore/mapistore_namedprops.c
mapiproxy/libmapistore/mapistore_private.h
mapiproxy/libmapistore/mapistore_processing.c
pyopenchange/pymapistoredb.c
pyopenchange/tests/provision.py

index e5a38be9e91996090fd094dff3632a99ee6b67d9..fc48f7657b8800a71cf61d054046359592aa5fed 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -878,6 +878,7 @@ mapiproxy/libmapistore.$(SHLIBEXT).$(PACKAGE_VERSION):      mapiproxy/libmapistore/i
                                                        mapiproxy/libmapistore/mapistore_backend_public.po                      \
                                                        mapiproxy/libmapistore/database/mapistoredb.po                          \
                                                        mapiproxy/libmapistore/database/mapistoredb_conf.po                     \
+                                                       mapiproxy/libmapistore/database/mapistoredb_namedprops.po               \
                                                        libmapi.$(SHLIBEXT).$(PACKAGE_VERSION)
        @echo "Linking $@"
        @$(CC) -o $@ $(DSOOPT) $^ -L. $(LDFLAGS) $(LIBS) $(TDB_LIBS) $(DL_LIBS) -Wl,-soname,libmapistore.$(SHLIBEXT).$(LIBMAPISTORE_SO_VERSION)
index a0e86c32c44476632cae8a206710c289bca2990a..863378db320fcac7301fcd56dc625050759807ee 100644 (file)
@@ -29,13 +29,14 @@ pythondir=@pythondir@
 sambaprefix=@sambaprefix@
 
 DSOOPT=-shared -fPIC
-CFLAGS=@CFLAGS@ @COMPILER_OPTIONS_C@ @ASSERT_DEFINITION@ @SUBUNIT_CFLAGS@ \
-       -DDEFAULT_LDIF=\"$(datadir)/setup/profiles\"                                            \
-       -DMAPISTORE_LDIF=\"$(datadir)/setup/mapistore\"                                         \
-       -DMAPISTORE_BACKEND_INSTALLDIR=\"$(libdir)/mapistore_backends\"                         \
-       -DMAPISTORE_MAPPING_PATH=\"$(prefix)/private/mapistore\"                                        \
-       -DMAPISTORE_DBPATH=\"$(prefix)/private/mapistore/mapistore.ldb\"                                \
-       -DLZXPRESS_DATADIR=\"$(datadir)/mapitest/lzxpress\"                                     \
+CFLAGS=@CFLAGS@ @COMPILER_OPTIONS_C@ @ASSERT_DEFINITION@ @SUBUNIT_CFLAGS@                              \
+       -DDEFAULT_LDIF=\"$(datadir)/setup/profiles\"                                                    \
+       -DMAPISTORE_LDIF=\"$(datadir)/setup/mapistore\"                                                 \
+       -DMAPISTORE_BACKEND_INSTALLDIR=\"$(libdir)/mapistore_backends\"                                 \
+       -DMAPISTORE_MAPPING_PATH=\"$(prefix)/private/mapistore\"                                                \
+       -DMAPISTORE_DBPATH=\"$(prefix)/private/mapistore/mapistore.ldb\"                                        \
+       -DMAPISTORE_DB_NAMEDPROPS_PATH=\"$(prefix)/private/mapistore/mapistore_named_properties.ldb\"   \
+       -DLZXPRESS_DATADIR=\"$(datadir)/mapitest/lzxpress\"                                             \
        -DLZFU_DATADIR=\"$(datadir)/mapitest/lzfu\"
 
 # This value should be determined by configure at some point
index f422322f6874ff51ecf09075f1b23f55cf0bab8d..c452fc171b1bbc79098fc71bccef346756c4b5ab 100755 (executable)
@@ -2,5 +2,4 @@
 
 ./libmapi/conf/mparse.pl --parser=mapicodes --outputdir=libmapi/ libmapi/conf/mapi-codes
 ./libmapi/conf/mparse.pl --parser=codepage_lcid --outputdir=libmapi/ libmapi/conf/codepage-lcid
-./libmapi/conf/mparse.pl --parser=mapistore_namedprops --outputdir=setup/mapistore/ libmapi/conf/mapi-named-properties
 ./libmapi/conf/mparse.pl --parser=pymapi_properties --outputdir=pyopenchange/ libmapi/conf/mapi-properties
\ No newline at end of file
index f2a97ede190d8e317b3ff8ac48330fca551d34b1..3011378fd32aa1777fb7c862420702e71b9bdd92 100755 (executable)
@@ -153,319 +153,6 @@ sub FileSave($$)
     close(FILE);
 }
 
-#####################################################################
-# generate mapitags.h file
-sub mapitags_header($)
-{
-    my $contents = shift;
-    my $line;
-    my @lines;
-    my @prop;
-    my $prop_type;
-    my $prop_value;
-
-    mparse "/* parser auto-generated by mparse */";
-    mparse "#ifndef __MAPITAGS_H__";
-    mparse "#define __MAPITAGS_H__";
-    mparse "";
-
-    @lines = split(/\n/, $contents);
-    foreach $line (@lines) {
-       $line =~ s/^\#+.*$//;
-       if ($line) {
-           @prop = split(/\s+/, $line);
-           $prop_type = hex $prop[0];
-           $prop_type &= 0xFFFF;
-           $prop_value = hex $prop[0];
-           $prop_value = ($prop_value >> 16) & 0xFFFF;
-
-           mparse sprintf "#define %-51s PROP_TAG(%-13s, 0x%.04x) /* %s */", $prop[1], $prop_types{$prop_type}, $prop_value, $prop[0] if ($prop_types{$prop_type});
-           if (($prop_type == 0x1e) || ($prop_type == 0x101e)){
-               $prop_type++;
-               $prop[0] = sprintf "0x%.8x", ((hex $prop[0]) & 0xFFFF0000) + $prop_type;
-               mparse sprintf "#define %-51s PROP_TAG(%-13s, 0x%.04x) /* %s */", "$prop[1]_UNICODE", $prop_types{$prop_type}, $prop_value, $prop[0] if ($prop_types{$prop_type});
-           }
-           $prop_type = 0xa;
-           $prop[0] = sprintf "0x%.8x", ((hex $prop[0]) & 0xFFFF0000) + $prop_type;
-           mparse sprintf "#define %-51s PROP_TAG(%-13s, 0x%.04x) /* %s */", "$prop[1]_ERROR", $prop_types{$prop_type}, $prop_value, $prop[0] if ($prop_types{$prop_type});
-       }
-    }
-    mparse "";
-    mparse "#endif /* !__MAPITAGS_H__ */";
-
-    return $ret;
-    
-}
-
-
-#####################################################################
-# generate mapitags.c file
-sub mapitags_interface($)
-{
-    my $contents = shift;
-    my $line;
-    my @lines;
-    my @prop;
-    my $prop_type;
-    my $prop_value;
-
-    mparse "/* parser auto-generated by mparse */";
-    mparse "#include \"libmapi/libmapi.h\"";
-    mparse "#include \"libmapi/libmapi_private.h\"";
-    mparse "#include \"gen_ndr/ndr_exchange.h\"";
-    mparse "#include \"libmapi/mapitags.h\"";
-    mparse "";
-    mparse "struct mapi_proptags";
-    mparse "{";
-    indent;
-    mparse "uint32_t   proptag;";
-    mparse "uint32_t   proptype;";
-    mparse "const char *propname;";
-    deindent;
-    mparse "};";
-    mparse "";
-    mparse "static struct mapi_proptags mapitags[] = {";
-    indent;
-    
-    @lines = split(/\n/, $contents);
-    foreach $line (@lines) {
-       $line =~ s/^\#+.*$//;
-       if ($line) {
-           @prop = split(/\s+/, $line);
-           $prop_type = hex $prop[0];
-           $prop_type &= 0xFFFF;
-           $prop_value = hex $prop[0];
-           $prop_value = ($prop_value >> 16) & 0xFFFF;
-           if ($prop_types{$prop_type}) {
-               mparse sprintf "{ %-51s, %-13s, \"%s\" },", $prop[1], $prop_types{$prop_type}, $prop[1];
-               if (($prop_type == 0x1e) || ($prop_type == 0x101e)) {
-                   $prop_type++;
-                   mparse sprintf "{ %-51s, %-13s, \"%s\" },", "$prop[1]_UNICODE", $prop_types{$prop_type}, "$prop[1]_UNICODE";
-               }
-               $prop_type = 0xa;
-               mparse sprintf "{ %-51s, %-13s, \"%s\" },", "$prop[1]_ERROR", $prop_types{$prop_type}, $prop[1];
-           }
-       }
-    }
-
-    mparse sprintf "{ %-51s, %-13d, \"NULL\"}", 0, 0;
-    deindent;
-    mparse "};";
-    mparse "";
-    mparse "_PUBLIC_ const char *get_proptag_name(uint32_t proptag)";
-    mparse "{";
-    indent;
-    mparse "uint32_t idx;";
-    mparse "";
-    mparse "for (idx = 0; mapitags[idx].proptag; idx++) {";
-    indent;
-    mparse "if (mapitags[idx].proptag == proptag) { ";
-    indent;
-    mparse "return mapitags[idx].propname;";
-    deindent;
-    mparse "}";
-    deindent;
-    mparse "}";
-    mparse "";
-    mparse "return NULL;";
-    deindent;
-    mparse "}";
-    mparse "";
-    mparse "_PUBLIC_ uint32_t get_proptag_value(const char *propname)";
-    mparse "{";
-    indent;
-    mparse "uint32_t idx;";
-    mparse "";
-    mparse "for (idx = 0; mapitags[idx].proptag; idx++) {";
-    indent;
-    mparse "if (!strcmp(mapitags[idx].propname, propname)) { ";
-    indent;
-    mparse "return mapitags[idx].proptag;";
-    deindent;
-    mparse "}";
-    deindent;
-    mparse "}";
-    mparse "";
-    mparse "return 0;";
-    deindent;
-    mparse "}";
-    mparse "";
-
-    return $ret;
-    
-}
-
-#####################################################################
-# generate mapitags_enum.idl file
-sub mapitags_enum($)
-{
-    my $contents = shift;
-    my $line;
-    my @lines;
-    my @prop;
-    my $prop_type;
-    my %hash;
-
-    mparse "/* parser auto-generated by mparse */";
-    mparse "";
-
-    mparse "typedef [v1_enum, flag(NDR_PAHEX)] enum {";
-    indent;
-    
-    @lines = split(/\n/, $contents);
-    foreach $line (@lines) {
-       $line =~ s/^\#+.*$//;
-       if ($line) {
-           @prop = split(/\s+/, $line);
-           $prop_type = hex $prop[0];
-           $prop_type &= 0xFFFF;
-
-           mparse sprintf "%-51s = %s,", $prop[1], $prop[0];
-
-           if (($prop_type == 0x1e) || ($prop_type == 0x101e)) {
-               $prop_type = hex $prop[0];
-               $prop_type++;
-               mparse sprintf "%-51s = 0x%.8x,", "$prop[1]_UNICODE", $prop_type;
-           }
-           if (!exists($hash{((hex $prop[0]) & 0xFFFF0000)})) {
-               $prop_type = 0xa;
-               $prop_type += ((hex $prop[0]) & 0xFFFF0000);
-               mparse sprintf "%-51s = 0x%.8x,", "$prop[1]_ERROR", $prop_type;
-               $hash{((hex $prop[0]) & 0xFFFF0000)} = 1;
-           }
-       }
-    }
-    mparse sprintf "%-51s = %s", "MAPI_PROP_RESERVED", "0xFFFFFFFF";
-    deindent;
-    mparse "} MAPITAGS;";    
-    mparse "";
-    
-    return $ret;
-}
-
-
-#####################################################################
-# generate mapi_nameid_private.h file
-sub mapi_nameid_private_header($)
-{
-    my $contents = shift;
-    my $line;
-    my @lines;
-    my @prop;
-    my $prop_OOM;
-    my $prop_ID;
-    my $prop_Type;
-    my $prop_name;
-    my $prop_Kind;
-    my $prop_OLEGUID;
-
-    mparse "/* parser auto-generated by mparse */";
-    mparse "#ifndef __MAPI_NAMEID_PRIVATE_H__";
-    mparse "#define __MAPI_NAMEID_PRIVATE_H__";
-    mparse "";
-    mparse "static struct mapi_nameid_tags mapi_nameid_tags[] = {";
-    indent;
-    
-    @lines = split(/\n/, $contents);
-    foreach $line (@lines) {
-       $line =~ s/^\#+.*$//;
-       if ($line) {
-           @prop = split(/\s+/, $line);
-
-           if ($prop[1] ne "NULL") {
-               $prop[1] = sprintf "\"%s\"", $prop[1];
-           }
-           if ($prop[3] ne "NULL") {
-               $prop[3] = sprintf "\"%s\"", $prop[3]
-           }
-           if ($prop[0] eq "NULL") {
-               $prop[0] = "0x00000000";
-           }
-           mparse sprintf "{ %-51s, %-40s, %-15s, %-30s, %-30s, %-15s, %-20s, 0x0 },", 
-           $prop[0], $prop[1], $prop[2], $prop[3], $prop[4], $prop[5], $prop[6];
-       }
-    }
-
-    mparse sprintf "{ 0x00000000, NULL, 0x0, NULL, PT_UNSPECIFIED, 0x0, NULL, 0x0 }";
-    deindent;
-    mparse "};";
-    mparse "";
-    mparse "#endif /* !MAPI_NAMEID_PRIVATE_H__ */";
-
-    return $ret;
-}
-
-#####################################################################
-# generate mapi_nameid.h file
-sub mapi_nameid_header($)
-{
-    my $contents = shift;
-    my $line;
-    my @lines;
-    my @prop;
-    my $propID;
-    my $proptype;
-    my $property;
-    my $counter = 0;
-
-    mparse "/* parser auto-generated by mparse */";
-    mparse "#ifndef __MAPI_NAMEID_H__";
-    mparse "#define __MAPI_NAMEID_H__";
-    mparse "";
-
-    mparse "/* NOTE TO DEVELOPERS: If this is a MNID_STRING named property,";
-    mparse " * then we use the arbitrary 0xa000-0afff property ID range for";
-    mparse " * internal mapping purpose only.";
-    mparse " */";
-
-    mparse "";
-    mparse "struct mapi_nameid_tags {";
-    indent;
-    mparse "uint32_t                   proptag;";
-    mparse "const char                 *OOM;";
-    mparse "uint16_t                   lid;";
-    mparse "const char                 *Name;";
-    mparse "uint32_t                   propType;";
-    mparse "uint8_t                            ulKind;";
-    mparse "const char                 *OLEGUID;";
-    mparse "uint32_t                   position;";
-    deindent;
-    mparse "};";
-    mparse "";
-    mparse "struct mapi_nameid {";
-    indent;
-    mparse "struct MAPINAMEID          *nameid;";
-    mparse "uint16_t                   count;";
-    mparse "struct mapi_nameid_tags            *entries;";
-    deindent;
-    mparse "};";
-    mparse "";
-
-    @lines = split(/\n/, $contents);
-    foreach $line (@lines) {
-       $line =~ s/^\#+.*$//;
-       if ($line) {
-           @prop = split(/\s+/, $line);
-           if ($prop[0] ne "NULL") {
-               $proptype = $prop_names{$prop[4]};
-               $propID = hex $prop[2];
-               if ($propID == 0) {
-                   # 40960 == 0xa000
-                   $propID = 40960 + $counter;
-                   $counter++;
-               }
-               $property = sprintf "0x%.8x", ($propID << 16) | $proptype;
-               mparse sprintf "#define %-51s %s", $prop[0], $property; 
-           }
-       }
-    }
-
-    mparse "";
-    mparse "#endif /* !MAPI_NAMEID_H__ */";
-
-    return $ret;
-}
-
 #####################################################################
 # generate mapicode.c file
 
@@ -1163,72 +850,6 @@ sub pymapi_properties($)
     mparse "}";
 }
 
-
-#####################################################################
-# generate mapistore_namedprops.ldif file
-sub mapistore_namedprops($)
-{
-    my $contents = shift;
-    my $line;
-    my @lines;
-    my @prop;
-
-    mparse "# LDIF file auto-generated by mparse ";
-    mparse "";
-
-    mparse sprintf "dn: CN=default";
-    mparse sprintf "objectClass: top";
-    mparse sprintf "cn: default";
-    mparse sprintf "";
-
-    mparse sprintf "dn: CN=custom";
-    mparse sprintf "objectClass: top";
-    mparse sprintf "cn: custom";
-    mparse sprintf "";
-
-    for my $key ( keys %oleguid ) {
-       my $value = $oleguid{$key};
-       
-       mparse sprintf "dn: CN=%s,CN=default", $value;
-       mparse sprintf "cn: %s", $value;
-       mparse sprintf "name: %s", $key;
-       mparse sprintf "oleguid: %s", $value;
-       mparse "";
-    }
-
-    @lines = split(/\n/, $contents);
-    foreach $line (@lines) {
-       $line =~ s/^\#+.*$//;
-       if ($line) {
-           @prop = split(/\s+/, $line);
-           if ($prop[5] eq "MNID_ID" && $prop[7]) {
-               mparse sprintf "dn: CN=%s,CN=%s,CN=default", $prop[2], $oleguid{$prop[6]};
-               mparse sprintf "objectClass: %s", $prop[5];
-               mparse sprintf "cn: %s", $prop[2];
-               mparse sprintf "canonical: %s", $prop[0];
-               mparse sprintf "oleguid: %s", $oleguid{$prop[6]};
-               mparse sprintf "mapped_id: %s", $prop[7];
-               mparse sprintf "prop_id: %s", $prop[2];
-               mparse sprintf "prop_type: %s", $prop_names{$prop[4]};
-               mparse sprintf "oom: %s", $prop[1];
-               mparse sprintf "";
-           } elsif ($prop[5] eq "MNID_STRING" && $prop[7]) {
-               mparse sprintf "dn: CN=%s,CN=%s,CN=default", $prop[3], $oleguid{$prop[6]};
-               mparse sprintf "objectClass: %s", $prop[5];
-               mparse sprintf "cn: %s", $prop[3];
-               mparse sprintf "canonical: %s", $prop[0];
-               mparse sprintf "oleguid: %s", $oleguid{$prop[6]};
-               mparse sprintf "mapped_id: %s", $prop[7];
-               mparse sprintf "prop_id: 0x0";
-               mparse sprintf "prop_type: %s", $prop[4];
-               mparse sprintf "prop_name: %s", $prop[3];
-               mparse sprintf "";
-           }
-       }
-    }
-    return $ret;
-}
-
 sub process_file($)
 {
     my $mapi_file = shift;
@@ -1238,23 +859,6 @@ sub process_file($)
     my $contents = FileLoad($mapi_file);
     defined $contents || return undef;
 
-    
-    if ($opt_parser eq "mapitags") {
-       print "Generating $outputdir" . "mapitags.h\n";
-       my $parser = ("$outputdir/mapitags.h");
-       FileSave($parser, mapitags_header($contents));
-       
-       print "Generating $outputdir" . "mapitags.c\n";
-       $ret = '';
-       my $code_parser = ("$outputdir/mapitags.c");
-       FileSave($code_parser, mapitags_interface($contents));
-       
-       print "Generating mapitags_enum.h\n";
-       $ret = '';
-       my $enum_parser = ("mapitags_enum.h");
-       FileSave($enum_parser, mapitags_enum($contents));
-    }
-
     if ($opt_parser eq "mapicodes") {
        print "Generating $outputdir" . "mapicode.c\n";
        $ret = '';
@@ -1267,18 +871,6 @@ sub process_file($)
        FileSave($enum_parser, mapicodes_enum($contents));
     }
 
-    if ($opt_parser eq "mapi_nameid") {
-       print "Generating $outputdir" . "mapi_nameid_private.h\n";
-       $ret = '';
-       my $parser = ("$outputdir/mapi_nameid_private.h");
-       FileSave($parser, mapi_nameid_private_header($contents));
-
-       print "Generating $outputdir" . "mapi_nameid.h\n";
-       $ret = '';
-       my $nameid_parser = ("$outputdir/mapi_nameid.h");
-       FileSave($nameid_parser, mapi_nameid_header($contents));
-    }
-
     if ($opt_parser eq "codepage_lcid") {
        print "Generating $outputdir" . "codepage_lcid.c\n";
        $ret = '';
@@ -1292,12 +884,6 @@ sub process_file($)
        FileSave($openchangedb_parser, openchangedb_property($contents));
     }
 
-    if ($opt_parser eq "mapistore_namedprops") {
-       print "Generating $outputdir" . "mapistore_namedprops.ldif\n";
-       my $mapistore_parser = ("$outputdir/mapistore_namedprops.ldif");
-       FileSave($mapistore_parser, mapistore_namedprops($contents));
-    }
-
     if ($opt_parser eq "pymapi_properties") {
        print "Generating $outputdir" . "pymapi_properties.c\n";
        my $pymapi_parser = ("$outputdir/pymapi_properties.c");
index 0c37556485481cf0f9b2ba27d9f155937120b59b..e815a9b9ab4ebf9b5d65881ca02418ee80697ed3 100644 (file)
@@ -123,6 +123,7 @@ struct mapistoredb_context *mapistoredb_init(TALLOC_CTX *mem_ctx,
 
        mapistore_set_database_path(mdb_ctx->param->db_path);
        mapistore_set_mapping_path(mdb_ctx->param->mstore_path);
+       mapistore_set_named_properties_database_path(mdb_ctx->param->db_named_path);
        mdb_ctx->mstore_ctx = mapistore_init(mdb_ctx, NULL);
        if (!mdb_ctx->mstore_ctx) {
                DEBUG(5, ("! [%s:%d][%s]: Failed to initialize mapistore context\n", __FILE__, __LINE__, __FUNCTION__));
diff --git a/mapiproxy/libmapistore/database/mapistoredb_namedprops.c b/mapiproxy/libmapistore/database/mapistoredb_namedprops.c
new file mode 100644 (file)
index 0000000..a0af5ea
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+   OpenChange Storage Abstraction Layer library
+
+   OpenChange Project
+
+   Copyright (C) Julien Kerihuel 2011
+
+   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_errors.h"
+#include "mapiproxy/libmapistore/mapistore.h"
+#include "mapiproxy/libmapistore/mapistore_private.h"
+#include "mapiproxy/libmapistore/mapistore_common.h"
+
+/**
+   \file mapistoredb_namedprops.c
+
+   \brief MAPIStore named properties database provisioning interface
+ */
+
+static const char *mapistoredb_namedprops_get_ldif_path(void)
+{
+       return MAPISTORE_LDIF;
+}
+
+
+/**
+   \details Provision the default named properties database for mapistore
+
+   \param mdb_ctx pointer to the mapistore database context
+
+   \return MAPISTORE_SUCCESS on success, otherwise MAPISTORE error
+ */
+enum MAPISTORE_ERROR mapistoredb_namedprops_provision(struct mapistoredb_context *mdb_ctx)
+{
+       enum MAPISTORE_ERROR    retval;
+       TALLOC_CTX              *mem_ctx;
+       int                     ret;
+       struct stat             sb;
+       char                    *ldif;
+
+       /* Sanity checks */
+       MAPISTORE_RETVAL_IF(!mdb_ctx, MAPISTORE_ERR_NOT_INITIALIZED, NULL);
+       MAPISTORE_RETVAL_IF(!mdb_ctx->mstore_ctx, MAPISTORE_ERR_NOT_INITIALIZED, NULL);
+       MAPISTORE_RETVAL_IF(!mdb_ctx->mstore_ctx->mapistore_nprops_ctx, MAPISTORE_ERR_NOT_INITIALIZED, NULL);
+
+       ret = stat(mapistore_get_named_properties_database_path(), &sb);
+       MAPISTORE_RETVAL_IF(ret == -1, MAPISTORE_ERR_DATABASE_INIT, NULL);
+
+       mem_ctx = talloc_named(NULL, 0, "mapistoredb_namedprops_provision");
+       MAPISTORE_RETVAL_IF(!mem_ctx, MAPISTORE_ERR_NO_MEMORY, NULL);
+
+       /* Step 1. Retrieve the path to the LDIF file */
+       ldif = talloc_asprintf(mem_ctx, "%s/%s", mapistoredb_namedprops_get_ldif_path(), MAPISTORE_DB_NAMED_V2_LDIF);
+       ret = stat(ldif, &sb);
+       MAPISTORE_RETVAL_IF(ret == -1, MAPISTORE_ERR_DATABASE_INIT, mem_ctx);
+
+       /* Step 2. Add database schema */
+       retval = mapistore_ldb_write_ldif_string_to_store(mdb_ctx->mstore_ctx->mapistore_nprops_ctx, 
+                                                         MDB_NPROPS_INIT_LDIF_TMPL);
+       MAPISTORE_RETVAL_IF(retval, retval, mem_ctx);
+
+       /* Step 3. Add RootDSE schema */
+       retval = mapistore_ldb_write_ldif_string_to_store(mdb_ctx->mstore_ctx->mapistore_nprops_ctx,
+                                                         MDB_NPROPS_ROOTDSE_LDIF_TMPL);
+       MAPISTORE_RETVAL_IF(retval, retval, mem_ctx);
+
+       /* Step 2. Commit the database structure and default set of named properties */
+       retval = mapistore_ldb_write_ldif_file_to_store(mdb_ctx->mstore_ctx->mapistore_nprops_ctx, ldif);
+       MAPISTORE_RETVAL_IF(retval, retval, mem_ctx);
+
+       talloc_free(ldif);
+       talloc_free(mem_ctx);
+
+       return MAPISTORE_SUCCESS;
+}
+
+/**
+   Add an entry for the user within the named properties database
+
+   \param mdb_ctx pointer to the mapistore database context
+   \param username pointer to the username entry to create
+
+   \return MAPISTORE_SUCCESS on success, otherwise MAPISTORE error
+ */
+enum MAPISTORE_ERROR mapistoredb_namedprops_provision_user(struct mapistoredb_context *mdb_ctx,
+                                                          const char *username)
+{
+       return MAPISTORE_SUCCESS;
+}
+
+enum MAPISTORE_ERROR mapistoredb_namedprops_register_application(struct mapistoredb_context *mdb_ctx,
+                                                                const char *username,
+                                                                const char *app_name,
+                                                                const char *app_GUID,
+                                                                const char *ldif)
+{
+       return MAPISTORE_SUCCESS;
+}
+
+enum MAPISTORE_ERROR mapistoredb_namedprops_unregister_application(struct mapistoredb_context *mdb_ctx,
+                                                                  const char *username,
+                                                                  const char *app_name,
+                                                                  const char *app_GUID,
+                                                                  const char *ldif)
+{
+       return MAPISTORE_SUCCESS;
+}
index c85e27690ac6f304505c1515ad99f687213c5071..85844c3f37303e23350f8c042683e8f8a9a27251 100644 (file)
@@ -98,6 +98,7 @@ struct mapistore_context {
 
        /* MAPISTORE_v2 */
        struct mapistore_indexing_context_list  *mapistore_indexing_list;
+       struct ldb_context                      *mapistore_nprops_ctx;
        /* !MAPISTORE_v2 */
 
        void                                    *nprops_ctx;
@@ -185,6 +186,14 @@ const char*                        mapistoredb_get_netbiosname(struct mapistoredb_context *);
 const char*                    mapistoredb_get_firstorg(struct mapistoredb_context *);
 const char*                    mapistoredb_get_firstou(struct mapistoredb_context *);
 
+/* definitions from mapistoredb_namedprops.c */
+enum MAPISTORE_ERROR           mapistoredb_namedprops_provision(struct mapistoredb_context *);
+enum MAPISTORE_ERROR           mapistoredb_namedprops_provision_user(struct mapistoredb_context *, const char *);
+enum MAPISTORE_ERROR           mapistoredb_namedprops_register_application(struct mapistoredb_context *, const char *,
+                                                                           const char *, const char *, const char *);
+enum MAPISTORE_ERROR           mapistoredb_namedprops_unregister_application(struct mapistoredb_context *, const char *,
+                                                                             const char *, const char *, const char *);
+
 /* definitions from mapistore_indexing.c */
 
 /* MAPISTORE_v1 */
index a7a52a1f386214f500d0468c4fc1e211c159a999..f23e9195116155d6a59acdf6b294e1399988c19f 100644 (file)
@@ -73,6 +73,7 @@ enum MAPISTORE_ERROR {
        MAPISTORE_ERR_INVALID_OBJECT = 17, /*!< The specified object is invalid */
        MAPISTORE_ERR_INVALID_CONTEXT = 18, /*!< The specified context is invalid */
        MAPISTORE_ERR_INVALID_URI = 19, /*!< The specified URI is invalid */
+       MAPISTORE_ERR_NOT_IMPLEMENTED = 20, /*!< The function is not implemented */
 };
 
 #endif /* ! __MAPISTORE_ERRORS_H */
index a1b33ad146c5f61c0a8456e5767cb955baab459f..be7cd1f160e7e60f561a49feb17fc82b4a9a8156 100644 (file)
@@ -35,6 +35,7 @@
 #include "mapistore.h"
 #include "mapistore_private.h"
 #include "mapistore_backend.h"
+#include "mapistore_common.h"
 #include <dlinklist.h>
 #include "libmapi/libmapi_private.h"
 
@@ -62,14 +63,15 @@ _PUBLIC_ struct mapistore_context *mapistore_init(TALLOC_CTX *mem_ctx, const cha
 
        retval = mapistore_init_mapping_context(mstore_ctx->processing_ctx);
        if (retval != MAPISTORE_SUCCESS) {
-               DEBUG(5, ("[%s:%d]: %s\n", __FUNCTION__, __LINE__, mapistore_errstr(retval)));
+               MSTORE_DEBUG_ERROR(MSTORE_LEVEL_CRITICAL, "mapistore mapping context init failed: %s\n",
+                                  mapistore_errstr(retval));
                talloc_free(mstore_ctx);
                return NULL;
        }
 
        retval = mapistore_backend_init(mstore_ctx, path);
        if (retval != MAPISTORE_SUCCESS) {
-               DEBUG(5, ("[%s:%d]: %s\n", __FUNCTION__, __LINE__, mapistore_errstr(retval)));
+               MSTORE_DEBUG_ERROR(MSTORE_LEVEL_CRITICAL, "mapistore backend init failed: %s\n", mapistore_errstr(retval));
                talloc_free(mstore_ctx);
                return NULL;
        }
@@ -82,10 +84,20 @@ _PUBLIC_ struct mapistore_context *mapistore_init(TALLOC_CTX *mem_ctx, const cha
 
        /* MAPISTORE_v2 */
        mstore_ctx->mapistore_indexing_list = talloc_zero(mstore_ctx, struct mapistore_indexing_context_list);
+
+       mstore_ctx->mapistore_nprops_ctx = NULL;
+       retval = mapistore_namedprops_init(mstore_ctx, &(mstore_ctx->mapistore_nprops_ctx));
+       if (retval != MAPISTORE_SUCCESS) {
+               MSTORE_DEBUG_ERROR(MSTORE_LEVEL_CRITICAL, 
+                                  "mapistore named properties database init failed: %s\n", 
+                                  mapistore_errstr(retval));
+               talloc_free(mstore_ctx);
+               return NULL;
+       }
        /* MAPISTORE_v2 */
 
-       mstore_ctx->nprops_ctx = NULL;
-       retval = mapistore_namedprops_init(mstore_ctx, &(mstore_ctx->nprops_ctx));
+       /* mstore_ctx->nprops_ctx = NULL; */
+       /* retval = mapistore_namedprops_init(mstore_ctx, &(mstore_ctx->nprops_ctx)); */
 
        return mstore_ctx;
 }
@@ -571,6 +583,8 @@ _PUBLIC_ const char *mapistore_errstr(enum MAPISTORE_ERROR mapistore_err)
                return "Invalid mapistore context";
        case MAPISTORE_ERR_INVALID_URI:
                return "Invalid mapistore URI";
+       case MAPISTORE_ERR_NOT_IMPLEMENTED:
+               return "Not implemented";
        }
 
        return "Unknown error";
index 61254d66b21adc063b95517eea6b5eb2c06b98f8..18b26cebe5ab5870c4869f7737fba31376bf6b50 100644 (file)
 
 #include <sys/stat.h>
 
-static const char *mapistore_namedprops_get_ldif_path(void)
-{
-       return MAPISTORE_LDIF;
-}
-
 /**
    \details Initialize the named properties database or return pointer
    to the existing one if already initialized/opened.
@@ -43,14 +38,10 @@ static const char *mapistore_namedprops_get_ldif_path(void)
 
    \return MAPISTORE_SUCCESS on success, otherwise MAPISTORE error
  */
-enum MAPISTORE_ERROR mapistore_namedprops_init(TALLOC_CTX *mem_ctx, void **_ldb_ctx)
+enum MAPISTORE_ERROR mapistore_namedprops_init(TALLOC_CTX *mem_ctx, struct ldb_context **_ldb_ctx)
 {
-       int                     ret;
        struct stat             sb;
        struct ldb_context      *ldb_ctx = NULL;
-       struct ldb_ldif         *ldif;
-       char                    *filename;
-       FILE                    *f;
        struct tevent_context   *ev;
        char                    *database;
 
@@ -61,40 +52,13 @@ enum MAPISTORE_ERROR mapistore_namedprops_init(TALLOC_CTX *mem_ctx, void **_ldb_
        ev = tevent_context_init(mem_ctx);
        MAPISTORE_RETVAL_IF(!ev, MAPISTORE_ERR_NO_MEMORY, NULL);
 
-       database = talloc_asprintf(mem_ctx, "%s/%s", mapistore_get_mapping_path(), MAPISTORE_DB_NAMED);
-       DEBUG(0, ("database = %s\n", database));
-
-       /* Step 1. Stat the database and populate it if it doesn't exist */
-       if (stat(database, &sb) == -1) {
-               ldb_ctx = mapistore_ldb_wrap_connect(ldb_ctx, ev, database, 0);
-               talloc_free(database);
-               MAPISTORE_RETVAL_IF(!ldb_ctx, MAPISTORE_ERR_DATABASE_INIT, NULL);
-
-               filename = talloc_asprintf(mem_ctx, "%s/mapistore_namedprops.ldif", 
-                                          mapistore_namedprops_get_ldif_path());
-               f = fopen(filename, "r");
-               talloc_free(filename);
-               MAPISTORE_RETVAL_IF(!f, MAPISTORE_ERROR, NULL);
-
-               while ((ldif = ldb_ldif_read_file(ldb_ctx, f))) {
-                       struct ldb_message *normalized_msg;
-                       ret = ldb_msg_normalize(ldb_ctx, mem_ctx, ldif->msg, &normalized_msg);
-                       MAPISTORE_RETVAL_IF(ret, MAPISTORE_ERR_DATABASE_INIT, NULL);
-                       ret = ldb_add(ldb_ctx, normalized_msg);
-                       talloc_free(normalized_msg);
-                       if (ret != LDB_SUCCESS) {
-                               fclose(f);
-                               MAPISTORE_RETVAL_IF(ret, MAPISTORE_ERR_DATABASE_INIT, NULL);
-                       }
-                       ldb_ldif_read_free(ldb_ctx, ldif);
-               }
-               fclose(f);
-
-       } else {
-               ldb_ctx = mapistore_ldb_wrap_connect(ldb_ctx, ev, database, 0);
-               talloc_free(database);
-               MAPISTORE_RETVAL_IF(!ldb_ctx, MAPISTORE_ERR_DATABASE_INIT, NULL);
-       }
+       database = talloc_strdup(mem_ctx, mapistore_get_named_properties_database_path());
+       MSTORE_DEBUG_INFO(MSTORE_LEVEL_DEBUG, "Full path to mapistore named properties database is: %s\n",
+                         database);
+
+       ldb_ctx = mapistore_ldb_wrap_connect(ldb_ctx, ev, database, 0);
+       talloc_free(database);
+       MAPISTORE_RETVAL_IF(!ldb_ctx, MAPISTORE_ERR_DATABASE_INIT, NULL);
 
        *_ldb_ctx = ldb_ctx;
 
index 68830d5409dcb45e52854731c4ac5fffe4001f80..f14e2ee7018388dbc5aae409c1c5935b5d6b5a77 100644 (file)
@@ -163,6 +163,25 @@ struct mapistoredb_context {
        "mapistore_uri: %s\n"           \
        "distinguishedName: %s\n"
 
+/** Named properties database ldif */
+#define        MDB_NPROPS_INIT_LDIF_TMPL               \
+       "dn: @OPTIONS\n"                        \
+       "checkBaseOnSearch: TRUE\n\n"           \
+       "dn: @INDEXLIST\n"                      \
+       "@IDXATTR: cn\n"                        \
+       "@IDXATTR: objectClass\n"               \
+       "@IDXATTR: mapped_id\n\n"               \
+       "dn: @ATTRIBUTES@\n"                    \
+       "cn: CASE_INSENSITIVE\n"                \
+       "dn: CASE_INSENSITIVE\n\n"
+
+#define        MDB_NPROPS_ROOTDSE_LDIF_TMPL                                    \
+       "dn: @ROOTDSE\n"                                                \
+       "defaultNamingContext: DC=server\n"                             \
+       "rootDomainNamingContext: DC=server\n"                          \
+       "vendorName: OpenChange Project (http://www.openchange.org)\n\n"
+
+
 /**
    Identifier mapping context.
 
@@ -236,6 +255,7 @@ struct mapistore_indexing_context_list {
 #define        MAPISTORE_DB_NAMED              "named_properties.ldb"
 
 #define        MAPISTORE_DB_NAMED_V2           "mapistore_named_properties.ldb"
+#define        MAPISTORE_DB_NAMED_V2_LDIF      "mapistore_namedprops_v2.ldif"
 
 #define        MAPISTORE_DB_INDEXING           "indexing.tdb"
 #define        MAPISTORE_SOFT_DELETED_TAG      "SOFT_DELETED:"
@@ -269,6 +289,7 @@ enum MAPISTORE_ERROR mapistore_free_context_id(struct processing_context *, uint
 /* mapistore_v2 */
 enum MAPISTORE_ERROR mapistore_ldb_write_ldif_string_to_store(struct ldb_context *, const char *);
 enum MAPISTORE_ERROR mapistore_write_ldif_string_to_store(struct processing_context *, const char *);
+enum MAPISTORE_ERROR mapistore_ldb_write_ldif_file_to_store(struct ldb_context *, const char *);
 enum MAPISTORE_ERROR mapistore_get_new_fmid(struct processing_context *, const char *, uint64_t *);
 enum MAPISTORE_ERROR mapistore_get_new_allocation_range(struct processing_context *, const char *, uint64_t, uint64_t *, uint64_t *);
 enum MAPISTORE_ERROR mapistore_get_mailbox_uri(struct processing_context *, const char *, char **);
@@ -324,7 +345,7 @@ enum MAPISTORE_ERROR mapistore_indexing_context_add_ref(struct mapistore_context
 /* !MAPISTORE_v2 */
 
 /* definitions from mapistore_namedprops.c */
-enum MAPISTORE_ERROR mapistore_namedprops_init(TALLOC_CTX *, void **);
+enum MAPISTORE_ERROR mapistore_namedprops_init(TALLOC_CTX *, struct ldb_context **);
 
 __END_DECLS
 
index 9b1a947ae852e1c443a7cedbcd230caeed41ba47..1aabcfbd2a3a49fdaa363fba056a4387492d8e7b 100644 (file)
@@ -187,7 +187,7 @@ enum MAPISTORE_ERROR mapistore_set_named_properties_database_path(const char *db
  */
 const char *mapistore_get_named_properties_database_path(void)
 {
-       return (!mapistore_nprops_dbpath) ? NULL : mapistore_nprops_dbpath;
+       return (!mapistore_nprops_dbpath) ? MAPISTORE_DB_NAMEDPROPS_PATH : mapistore_nprops_dbpath;
 }
 
 
@@ -361,6 +361,43 @@ enum MAPISTORE_ERROR mapistore_write_ldif_string_to_store(struct processing_cont
 }
 
 
+enum MAPISTORE_ERROR mapistore_ldb_write_ldif_file_to_store(struct ldb_context *ldb_ctx, const char *ldif_path)
+{
+       int                     ret;
+       FILE                    *f;
+       struct ldb_ldif         *ldif;
+       TALLOC_CTX              *mem_ctx;
+
+       /* Sanity checks */
+       MAPISTORE_RETVAL_IF(!ldb_ctx, MAPISTORE_ERR_NOT_INITIALIZED, NULL);
+       MAPISTORE_RETVAL_IF(!ldif_path, MAPISTORE_ERR_INVALID_PARAMETER, NULL);
+
+       f = fopen(ldif_path, "r");
+       MAPISTORE_RETVAL_IF(!f, MAPISTORE_ERR_DATABASE_INIT, NULL);
+
+       mem_ctx = talloc_named(NULL, 0, "mapistore_ldb_write_ldif_file_to_store");
+
+       while ((ldif = ldb_ldif_read_file(ldb_ctx, f))) {
+               struct ldb_message      *normalized_msg;
+
+               ret = ldb_msg_normalize(ldb_ctx, mem_ctx, ldif->msg, &normalized_msg);
+               MAPISTORE_RETVAL_IF(ret != LDB_SUCCESS, MAPISTORE_ERR_DATABASE_OPS, mem_ctx);
+               ret = ldb_add(ldb_ctx, normalized_msg);
+               if (ret != LDB_SUCCESS) {
+                       fclose(f);
+                       MAPISTORE_RETVAL_IF(ret != LDB_SUCCESS, MAPISTORE_ERR_DATABASE_OPS, mem_ctx);
+               }
+               ldb_ldif_read_free(ldb_ctx, ldif);
+               talloc_free(normalized_msg);
+       }
+
+       fclose(f);
+       talloc_free(mem_ctx);
+
+       return MAPISTORE_SUCCESS;
+}
+
+
 /**
    \details Retrieve the next available folder or message identifier
 
index d265871e938f71b476873f75413e66bc9576b633..3da3ccf98b53ebb582297245f9f59d9417c0b824 100644 (file)
@@ -87,6 +87,10 @@ static PyObject *py_MAPIStoreDB_provision(PyMAPIStoreDBObject *self, PyObject *a
        return PyInt_FromLong(mapistoredb_provision(self->mdb_ctx));
 }
 
+static PyObject *py_MAPIStoreDB_provision_named_properties(PyMAPIStoreDBObject *self, PyObject *args)
+{
+       return PyInt_FromLong(mapistoredb_namedprops_provision(self->mdb_ctx));
+}
 
 static PyObject *py_MAPIStoreDB_get_mapistore_uri(PyObject *module, PyObject *args, PyObject *kwargs)
 {
@@ -215,6 +219,7 @@ static PyObject *PyMAPIStoreDB_getParameter(PyObject *_self, void *data)
 static PyMethodDef mapistoredb_methods[] = {
        { "dump_configuration", (PyCFunction)py_MAPIStoreDB_dump_configuration, METH_VARARGS },
        { "provision", (PyCFunction)py_MAPIStoreDB_provision, METH_KEYWORDS },
+       { "provision_named_properties", (PyCFunction)py_MAPIStoreDB_provision_named_properties, METH_VARARGS },
        { "get_mapistore_uri", (PyCFunction)py_MAPIStoreDB_get_mapistore_uri, METH_KEYWORDS },
        { "get_new_fid", (PyCFunction)py_MAPIStoreDB_get_new_fid, METH_VARARGS },
        { "get_new_allocation_range", (PyCFunction)py_MAPIStoreDB_get_new_allocation_range, METH_VARARGS },
index 2383ba43ea8ba95c5a61739cecf87d4c39f8ebe1..a28f416f445e389000adc9644f81be911d908bb4 100755 (executable)
@@ -12,13 +12,17 @@ import string
 
 username = "jkerihuel"
 indent = 1
+title_nb = 1
 
 os.mkdir("/tmp/mapistoredb");
 
 def newTitle(title, separator):
+    global title_nb
+    ftitle = "[Step %d]. %s" % (title_nb, title)
     print ""
-    print "%s" % title
-    print separator * len(title)
+    print ftitle
+    print separator * len(ftitle)
+    title_nb += 1
 
 def TreeRoot(name):
     print ""
@@ -43,26 +47,33 @@ def TreeDeIndent():
     indent -= 1
 
 def start():
-    newTitle("[Step 1]. Initializing mapistore database", '=')
+    newTitle("Initializing mapistore database", '=')
     MAPIStoreDB = mapistoredb.mapistoredb("/tmp/mapistoredb")
 
-    newTitle("[Step 2]. Provisioning mapistore database", '=')
+    newTitle("Provisioning mapistore database", '=')
     ret = MAPIStoreDB.provision(netbiosname = "server",
                                 firstorg = "OpenChange Project",
                                 firstou = "OpenChange Development Unit")
     if (ret == 0):
         print "\t* Provisioning: SUCCESS"
     else:
-        print "\t* Provisioning: FAILURE"
+        print "\t* Provisioning: FAILURE (ret = %d)" % ret
 
-    newTitle("[Step 3]. Create a new mailbox", '=')
+    newTitle("Create mapistore named properties database", '=')
+    ret = MAPIStoreDB.provision_named_properties()
+    if (ret == 0):
+        print "\t* Provisioning: SUCCESS"
+    else:
+        print "\t* Provisioning: FAILURE (ret = %d)" % ret
+
+    newTitle("Create a new mailbox", '=')
     mailbox_root = MAPIStoreDB.get_mapistore_uri(folder=mapistoredb.MDB_ROOT_FOLDER,
                                                  username=username, 
                                                  namespace="mstoredb://")
     retval = MAPIStoreDB.new_mailbox(username, mailbox_root)
     print "\t* Mailbox Root: %s" % mailbox_root
     
-    newTitle("[Step 4]. Get and Set a new allocation range to the mailbox", '=')
+    newTitle("Get and Set a new allocation range to the mailbox", '=')
     (retval, rstart,rend) = MAPIStoreDB.get_new_allocation_range(username,
                                                                  0x1000);
     if retval == 0:
@@ -76,18 +87,18 @@ def start():
         else:
             print "\t * Error while setting allocation range to the mailbox"
             
-    newTitle("[Step 5]. Uninitializing mapistore database context", '=')
+    newTitle("Uninitializing mapistore database context", '=')
     MAPIStoreDB.release()
                 
-    newTitle("[Step 6]. Initializing mapistore context", '=')
+    newTitle("Initializing mapistore context", '=')
     mapistore.set_mapping_path("/tmp/mapistoredb/mapistore")
     MAPIStore = mapistore.mapistore()
     
-    newTitle("[Step 7]. Adding a context over Mailbox Root Folder", '=')
+    newTitle("Adding a context over Mailbox Root Folder", '=')
     context_id = MAPIStore.add_context(username, mailbox_root)
     print "\t* context_id = %s" % context_id
 
-    newTitle("[Step 8]. Create the mailbox hierarchy", '=')
+    newTitle("Create the mailbox hierarchy", '=')
     
     TreeRoot("Mailbox Root Folder")
     
@@ -229,7 +240,7 @@ def start():
                                   folder_name="")
     TreeLeafStatus("Reminders", retval)
 
-    newTitle("[Step 9]. Setting mailbox folders to fsocpf", '=')
+    newTitle("Setting mailbox folders to fsocpf", '=')
     new_uri = MAPIStore.get_mapistore_uri(mapistoredb.MDB_INBOX,
                                           username, 
                                           "fsocpf://")